Lines Matching +full:duty +full:- +full:cycle
1 // SPDX-License-Identifier: GPL-2.0+
8 * - The period is fixed to 1 ms and is generated continuously despite changes
9 * to the duty cycle or enable/disable state.
10 * - Changes to the duty cycle or enable/disable state take effect immediately
12 * - The device cannot generate a 0% duty cycle. For duty cycles below 1 / 256
13 * ms, the output is disabled and relies upon an external pull-down resistor
46 struct iqs62x_core *iqs62x = iqs620_pwm->iqs62x; in iqs620_pwm_init()
50 return regmap_clear_bits(iqs62x->regmap, IQS620_PWR_SETTINGS, in iqs620_pwm_init()
53 ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, in iqs620_pwm_init()
54 duty_scale - 1); in iqs620_pwm_init()
58 return regmap_set_bits(iqs62x->regmap, IQS620_PWR_SETTINGS, in iqs620_pwm_init()
70 if (state->polarity != PWM_POLARITY_NORMAL) in iqs620_pwm_apply()
71 return -EINVAL; in iqs620_pwm_apply()
73 if (state->period < IQS620_PWM_PERIOD_NS) in iqs620_pwm_apply()
74 return -EINVAL; in iqs620_pwm_apply()
79 * The duty cycle generated by the device is calculated as follows: in iqs620_pwm_apply()
84 * (inclusive). Therefore the lowest duty cycle the device can generate in iqs620_pwm_apply()
87 * For lower duty cycles (e.g. 0), the PWM output is simply disabled to in iqs620_pwm_apply()
88 * allow an external pull-down resistor to hold the GPIO3/LTX pin low. in iqs620_pwm_apply()
90 duty_cycle = min_t(u64, state->duty_cycle, IQS620_PWM_PERIOD_NS); in iqs620_pwm_apply()
93 if (!state->enabled) in iqs620_pwm_apply()
96 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_apply()
100 iqs620_pwm->duty_scale = duty_scale; in iqs620_pwm_apply()
102 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_apply()
114 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_get_state()
117 * Since the device cannot generate a 0% duty cycle, requests to do so in iqs620_pwm_get_state()
122 state->enabled = iqs620_pwm->duty_scale > 0; in iqs620_pwm_get_state()
123 state->duty_cycle = DIV_ROUND_UP(iqs620_pwm->duty_scale * in iqs620_pwm_get_state()
126 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_get_state()
128 state->period = IQS620_PWM_PERIOD_NS; in iqs620_pwm_get_state()
129 state->polarity = PWM_POLARITY_NORMAL; in iqs620_pwm_get_state()
146 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_notifier()
153 ret = iqs620_pwm_init(iqs620_pwm, iqs620_pwm->duty_scale); in iqs620_pwm_notifier()
155 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_notifier()
158 dev_err(iqs620_pwm->chip.dev, in iqs620_pwm_notifier()
159 "Failed to re-initialize device: %d\n", ret); in iqs620_pwm_notifier()
177 ret = blocking_notifier_chain_unregister(&iqs620_pwm->iqs62x->nh, in iqs620_pwm_notifier_unregister()
178 &iqs620_pwm->notifier); in iqs620_pwm_notifier_unregister()
180 dev_err(iqs620_pwm->chip.dev, in iqs620_pwm_notifier_unregister()
186 struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent); in iqs620_pwm_probe()
191 iqs620_pwm = devm_kzalloc(&pdev->dev, sizeof(*iqs620_pwm), GFP_KERNEL); in iqs620_pwm_probe()
193 return -ENOMEM; in iqs620_pwm_probe()
195 iqs620_pwm->iqs62x = iqs62x; in iqs620_pwm_probe()
197 ret = regmap_read(iqs62x->regmap, IQS620_PWR_SETTINGS, &val); in iqs620_pwm_probe()
202 ret = regmap_read(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, &val); in iqs620_pwm_probe()
206 iqs620_pwm->duty_scale = val + 1; in iqs620_pwm_probe()
209 iqs620_pwm->chip.dev = &pdev->dev; in iqs620_pwm_probe()
210 iqs620_pwm->chip.ops = &iqs620_pwm_ops; in iqs620_pwm_probe()
211 iqs620_pwm->chip.npwm = 1; in iqs620_pwm_probe()
213 mutex_init(&iqs620_pwm->lock); in iqs620_pwm_probe()
215 iqs620_pwm->notifier.notifier_call = iqs620_pwm_notifier; in iqs620_pwm_probe()
216 ret = blocking_notifier_chain_register(&iqs620_pwm->iqs62x->nh, in iqs620_pwm_probe()
217 &iqs620_pwm->notifier); in iqs620_pwm_probe()
219 dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret); in iqs620_pwm_probe()
223 ret = devm_add_action_or_reset(&pdev->dev, in iqs620_pwm_probe()
229 ret = devm_pwmchip_add(&pdev->dev, &iqs620_pwm->chip); in iqs620_pwm_probe()
231 dev_err(&pdev->dev, "Failed to add device: %d\n", ret); in iqs620_pwm_probe()
238 .name = "iqs620a-pwm",
247 MODULE_ALIAS("platform:iqs620a-pwm");