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
45 static int raspberrypi_pwm_set_property(struct rpi_firmware *firmware, in raspberrypi_pwm_set_property() argument
54 ret = rpi_firmware_property(firmware, RPI_FIRMWARE_SET_POE_HAT_VAL, in raspberrypi_pwm_set_property()
59 return -EIO; in raspberrypi_pwm_set_property()
64 static int raspberrypi_pwm_get_property(struct rpi_firmware *firmware, in raspberrypi_pwm_get_property() argument
72 ret = rpi_firmware_property(firmware, RPI_FIRMWARE_GET_POE_HAT_VAL, in raspberrypi_pwm_get_property()
77 return -EIO; in raspberrypi_pwm_get_property()
85 struct pwm_device *pwm, in raspberrypi_pwm_get_state() argument
90 state->period = RPI_PWM_PERIOD_NS; in raspberrypi_pwm_get_state()
91 state->duty_cycle = DIV_ROUND_UP(rpipwm->duty_cycle * RPI_PWM_PERIOD_NS, in raspberrypi_pwm_get_state()
93 state->enabled = !!(rpipwm->duty_cycle); in raspberrypi_pwm_get_state()
94 state->polarity = PWM_POLARITY_NORMAL; in raspberrypi_pwm_get_state()
99 static int raspberrypi_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in raspberrypi_pwm_apply() argument
106 if (state->period < RPI_PWM_PERIOD_NS || in raspberrypi_pwm_apply()
107 state->polarity != PWM_POLARITY_NORMAL) in raspberrypi_pwm_apply()
108 return -EINVAL; in raspberrypi_pwm_apply()
110 if (!state->enabled) in raspberrypi_pwm_apply()
112 else if (state->duty_cycle < RPI_PWM_PERIOD_NS) in raspberrypi_pwm_apply()
113 duty_cycle = DIV_ROUND_DOWN_ULL(state->duty_cycle * RPI_PWM_MAX_DUTY, in raspberrypi_pwm_apply()
118 if (duty_cycle == rpipwm->duty_cycle) in raspberrypi_pwm_apply()
121 ret = raspberrypi_pwm_set_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, in raspberrypi_pwm_apply()
129 rpipwm->duty_cycle = duty_cycle; in raspberrypi_pwm_apply()
142 struct device *dev = &pdev->dev; in raspberrypi_pwm_probe()
143 struct rpi_firmware *firmware; in raspberrypi_pwm_probe() local
148 firmware_node = of_get_parent(dev->of_node); in raspberrypi_pwm_probe()
150 dev_err(dev, "Missing firmware node\n"); in raspberrypi_pwm_probe()
151 return -ENOENT; in raspberrypi_pwm_probe()
154 firmware = devm_rpi_firmware_get(&pdev->dev, firmware_node); in raspberrypi_pwm_probe()
156 if (!firmware) in raspberrypi_pwm_probe()
157 return dev_err_probe(dev, -EPROBE_DEFER, in raspberrypi_pwm_probe()
158 "Failed to get firmware handle\n"); in raspberrypi_pwm_probe()
160 chip = devm_pwmchip_alloc(&pdev->dev, RASPBERRYPI_FIRMWARE_PWM_NUM, in raspberrypi_pwm_probe()
166 rpipwm->firmware = firmware; in raspberrypi_pwm_probe()
167 chip->ops = &raspberrypi_pwm_ops; in raspberrypi_pwm_probe()
169 ret = raspberrypi_pwm_get_property(rpipwm->firmware, RPI_PWM_CUR_DUTY_REG, in raspberrypi_pwm_probe()
170 &rpipwm->duty_cycle); in raspberrypi_pwm_probe()
180 { .compatible = "raspberrypi,firmware-poe-pwm", },
187 .name = "raspberrypi-poe-pwm",
195 MODULE_DESCRIPTION("Raspberry Pi Firmware Based PWM Bus Driver");