Lines Matching +full:firmware +full:- +full:poe +full:- +full:pwm

1 // SPDX-License-Identifier: GPL-2.0
4 * For more information on Raspberry Pi's PoE hat see:
5 * https://www.raspberrypi.org/products/poe-hat/
8 * - No disable bit, so a disabled PWM is simulated by duty_cycle 0
9 * - Only normal polarity
10 * - Fixed 12.5 kHz period
18 #include <linux/pwm.h>
20 #include <soc/bcm2835/raspberrypi-firmware.h>
21 #include <dt-bindings/pwm/raspberrypi,firmware-poe-pwm.h>
29 struct rpi_firmware *firmware; member
46 static int raspberrypi_pwm_set_property(struct rpi_firmware *firmware, in raspberrypi_pwm_set_property() argument
55 ret = rpi_firmware_property(firmware, RPI_FIRMWARE_SET_POE_HAT_VAL, in raspberrypi_pwm_set_property()
60 return -EIO; in raspberrypi_pwm_set_property()
65 static int raspberrypi_pwm_get_property(struct rpi_firmware *firmware, in raspberrypi_pwm_get_property() argument
73 ret = rpi_firmware_property(firmware, RPI_FIRMWARE_GET_POE_HAT_VAL, in raspberrypi_pwm_get_property()
78 return -EIO; in raspberrypi_pwm_get_property()
86 struct pwm_device *pwm, in raspberrypi_pwm_get_state() argument
91 state->period = RPI_PWM_PERIOD_NS; in raspberrypi_pwm_get_state()
92 state->duty_cycle = DIV_ROUND_UP(rpipwm->duty_cycle * RPI_PWM_PERIOD_NS, in raspberrypi_pwm_get_state()
94 state->enabled = !!(rpipwm->duty_cycle); in raspberrypi_pwm_get_state()
95 state->polarity = PWM_POLARITY_NORMAL; in raspberrypi_pwm_get_state()
100 static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in raspberrypi_pwm_apply() argument
107 if (state->period < RPI_PWM_PERIOD_NS || in raspberrypi_pwm_apply()
108 state->polarity != PWM_POLARITY_NORMAL) in raspberrypi_pwm_apply()
109 return -EINVAL; in raspberrypi_pwm_apply()
111 if (!state->enabled) in raspberrypi_pwm_apply()
113 else if (state->duty_cycle < RPI_PWM_PERIOD_NS) in raspberrypi_pwm_apply()
114 duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY, in raspberrypi_pwm_apply()
119 if (duty_cycle == rpipwm->duty_cycle) in raspberrypi_pwm_apply()
122 ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, in raspberrypi_pwm_apply()
125 dev_err(chip->dev, "Failed to set duty cycle: %pe\n", in raspberrypi_pwm_apply()
130 rpipwm->duty_cycle = duty_cycle; in raspberrypi_pwm_apply()
144 struct device *dev = &pdev->dev; in raspberrypi_pwm_probe()
145 struct rpi_firmware *firmware; in raspberrypi_pwm_probe() local
149 firmware_node = of_get_parent(dev->of_node); in raspberrypi_pwm_probe()
151 dev_err(dev, "Missing firmware node\n"); in raspberrypi_pwm_probe()
152 return -ENOENT; in raspberrypi_pwm_probe()
155 firmware = devm_rpi_firmware_get(&pdev->dev, firmware_node); in raspberrypi_pwm_probe()
157 if (!firmware) in raspberrypi_pwm_probe()
158 return dev_err_probe(dev, -EPROBE_DEFER, in raspberrypi_pwm_probe()
159 "Failed to get firmware handle\n"); in raspberrypi_pwm_probe()
161 rpipwm = devm_kzalloc(&pdev->dev, sizeof(*rpipwm), GFP_KERNEL); in raspberrypi_pwm_probe()
163 return -ENOMEM; in raspberrypi_pwm_probe()
165 rpipwm->firmware = firmware; in raspberrypi_pwm_probe()
166 rpipwm->chip.dev = dev; in raspberrypi_pwm_probe()
167 rpipwm->chip.ops = &raspberrypi_pwm_ops; in raspberrypi_pwm_probe()
168 rpipwm->chip.npwm = RASPBERRYPI_FIRMWARE_PWM_NUM; in raspberrypi_pwm_probe()
170 ret = raspberrypi_pwm_get_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, in raspberrypi_pwm_probe()
171 &rpipwm->duty_cycle); in raspberrypi_pwm_probe()
177 return devm_pwmchip_add(dev, &rpipwm->chip); in raspberrypi_pwm_probe()
181 { .compatible = "raspberrypi,firmware-poe-pwm", },
188 .name = "raspberrypi-poe-pwm",
196 MODULE_DESCRIPTION("Raspberry Pi Firmware Based PWM Bus Driver");