Lines Matching +full:sl28cpld +full:- +full:gpio

1 // SPDX-License-Identifier: GPL-2.0-only
3 * sl28cpld PWM driver
8 * enough to be briefly explained. It consists of one 8-bit counter. The PWM
15 * +-----------+--------+--------------+-----------+---------------+
17 * +-----------+--------+--------------+-----------+---------------+
22 * +-----------+--------+--------------+-----------+---------------+
25 * - The hardware cannot generate a 100% duty cycle if the prescaler is 0.
26 * - The hardware cannot atomically set the prescaler and the counter value,
28 * - The counter is not reset if you switch the prescaler which leads
30 * - The duty cycle will switch immediately and not after a complete cycle.
31 * - Depending on the actual implementation, disabling the PWM might have
32 * side effects. For example, if the output pin is shared with a GPIO pin
33 * it will automatically switch back to GPIO mode.
55 #define SL28CPLD_PWM_MAX_DUTY_CYCLE(prescaler) (1 << (7 - (prescaler)))
64 * max_period_ns = 1 << (7 - prescaler) / SL28CPLD_PWM_CLK * NSEC_PER_SEC
65 * max_duty_cycle = 1 << (7 - prescaler)
79 regmap_read((priv)->regmap, (priv)->offset + (reg), (val))
81 regmap_write((priv)->regmap, (priv)->offset + (reg), (val))
104 state->enabled = reg & SL28CPLD_PWM_CTRL_ENABLE; in sl28cpld_pwm_get_state()
107 state->period = SL28CPLD_PWM_PERIOD(prescaler); in sl28cpld_pwm_get_state()
110 state->duty_cycle = SL28CPLD_PWM_TO_DUTY_CYCLE(reg); in sl28cpld_pwm_get_state()
111 state->polarity = PWM_POLARITY_NORMAL; in sl28cpld_pwm_get_state()
121 state->duty_cycle = min(state->duty_cycle, state->period); in sl28cpld_pwm_get_state()
136 if (state->polarity != PWM_POLARITY_NORMAL) in sl28cpld_pwm_apply()
137 return -EINVAL; in sl28cpld_pwm_apply()
143 prescaler = DIV_ROUND_UP_ULL(SL28CPLD_PWM_PERIOD(0), state->period); in sl28cpld_pwm_apply()
147 return -ERANGE; in sl28cpld_pwm_apply()
150 if (state->enabled) in sl28cpld_pwm_apply()
153 cycle = SL28CPLD_PWM_FROM_DUTY_CYCLE(state->duty_cycle); in sl28cpld_pwm_apply()
159 * care about the frequency because its "all-one" in either case. in sl28cpld_pwm_apply()
179 write_duty_cycle_first = pwm->state.period > state->period; in sl28cpld_pwm_apply()
212 if (!pdev->dev.parent) { in sl28cpld_pwm_probe()
213 dev_err(&pdev->dev, "no parent device\n"); in sl28cpld_pwm_probe()
214 return -ENODEV; in sl28cpld_pwm_probe()
217 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in sl28cpld_pwm_probe()
219 return -ENOMEM; in sl28cpld_pwm_probe()
221 priv->regmap = dev_get_regmap(pdev->dev.parent, NULL); in sl28cpld_pwm_probe()
222 if (!priv->regmap) { in sl28cpld_pwm_probe()
223 dev_err(&pdev->dev, "could not get parent regmap\n"); in sl28cpld_pwm_probe()
224 return -ENODEV; in sl28cpld_pwm_probe()
227 ret = device_property_read_u32(&pdev->dev, "reg", &priv->offset); in sl28cpld_pwm_probe()
229 dev_err(&pdev->dev, "no 'reg' property found (%pe)\n", in sl28cpld_pwm_probe()
231 return -EINVAL; in sl28cpld_pwm_probe()
235 chip = &priv->chip; in sl28cpld_pwm_probe()
236 chip->dev = &pdev->dev; in sl28cpld_pwm_probe()
237 chip->ops = &sl28cpld_pwm_ops; in sl28cpld_pwm_probe()
238 chip->npwm = 1; in sl28cpld_pwm_probe()
240 ret = devm_pwmchip_add(&pdev->dev, chip); in sl28cpld_pwm_probe()
242 dev_err(&pdev->dev, "failed to add PWM chip (%pe)", in sl28cpld_pwm_probe()
251 { .compatible = "kontron,sl28cpld-pwm" },
259 .name = "sl28cpld-pwm",
265 MODULE_DESCRIPTION("sl28cpld PWM Driver");