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
51 struct iqs62x_core *iqs62x = iqs620_pwm->iqs62x; in iqs620_pwm_init()
55 return regmap_clear_bits(iqs62x->regmap, IQS620_PWR_SETTINGS, in iqs620_pwm_init()
58 ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, in iqs620_pwm_init()
59 duty_scale - 1); in iqs620_pwm_init()
63 return regmap_set_bits(iqs62x->regmap, IQS620_PWR_SETTINGS, in iqs620_pwm_init()
75 if (state->polarity != PWM_POLARITY_NORMAL) in iqs620_pwm_apply()
76 return -EINVAL; in iqs620_pwm_apply()
78 if (state->period < IQS620_PWM_PERIOD_NS) in iqs620_pwm_apply()
79 return -EINVAL; in iqs620_pwm_apply()
84 * The duty cycle generated by the device is calculated as follows: in iqs620_pwm_apply()
89 * (inclusive). Therefore the lowest duty cycle the device can generate in iqs620_pwm_apply()
92 * For lower duty cycles (e.g. 0), the PWM output is simply disabled to in iqs620_pwm_apply()
93 * allow an external pull-down resistor to hold the GPIO3/LTX pin low. in iqs620_pwm_apply()
95 duty_cycle = min_t(u64, state->duty_cycle, IQS620_PWM_PERIOD_NS); in iqs620_pwm_apply()
98 if (!state->enabled) in iqs620_pwm_apply()
101 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_apply()
105 iqs620_pwm->duty_scale = duty_scale; in iqs620_pwm_apply()
107 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_apply()
119 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_get_state()
122 * Since the device cannot generate a 0% duty cycle, requests to do so in iqs620_pwm_get_state()
127 state->enabled = iqs620_pwm->duty_scale > 0; in iqs620_pwm_get_state()
128 state->duty_cycle = DIV_ROUND_UP(iqs620_pwm->duty_scale * in iqs620_pwm_get_state()
131 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_get_state()
133 state->period = IQS620_PWM_PERIOD_NS; in iqs620_pwm_get_state()
134 state->polarity = PWM_POLARITY_NORMAL; in iqs620_pwm_get_state()
151 mutex_lock(&iqs620_pwm->lock); in iqs620_pwm_notifier()
158 ret = iqs620_pwm_init(iqs620_pwm, iqs620_pwm->duty_scale); in iqs620_pwm_notifier()
160 mutex_unlock(&iqs620_pwm->lock); in iqs620_pwm_notifier()
163 dev_err(iqs620_pwm->dev, in iqs620_pwm_notifier()
164 "Failed to re-initialize device: %d\n", ret); in iqs620_pwm_notifier()
181 ret = blocking_notifier_chain_unregister(&iqs620_pwm->iqs62x->nh, in iqs620_pwm_notifier_unregister()
182 &iqs620_pwm->notifier); in iqs620_pwm_notifier_unregister()
184 dev_err(iqs620_pwm->dev, in iqs620_pwm_notifier_unregister()
190 struct iqs62x_core *iqs62x = dev_get_drvdata(pdev->dev.parent); in iqs620_pwm_probe()
196 chip = devm_pwmchip_alloc(&pdev->dev, 1, sizeof(*iqs620_pwm)); in iqs620_pwm_probe()
201 iqs620_pwm->dev = &pdev->dev; in iqs620_pwm_probe()
202 iqs620_pwm->iqs62x = iqs62x; in iqs620_pwm_probe()
204 ret = regmap_read(iqs62x->regmap, IQS620_PWR_SETTINGS, &val); in iqs620_pwm_probe()
209 ret = regmap_read(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE, &val); in iqs620_pwm_probe()
213 iqs620_pwm->duty_scale = val + 1; in iqs620_pwm_probe()
216 chip->ops = &iqs620_pwm_ops; in iqs620_pwm_probe()
218 mutex_init(&iqs620_pwm->lock); in iqs620_pwm_probe()
220 iqs620_pwm->notifier.notifier_call = iqs620_pwm_notifier; in iqs620_pwm_probe()
221 ret = blocking_notifier_chain_register(&iqs620_pwm->iqs62x->nh, in iqs620_pwm_probe()
222 &iqs620_pwm->notifier); in iqs620_pwm_probe()
224 dev_err(&pdev->dev, "Failed to register notifier: %d\n", ret); in iqs620_pwm_probe()
228 ret = devm_add_action_or_reset(&pdev->dev, in iqs620_pwm_probe()
234 ret = devm_pwmchip_add(&pdev->dev, chip); in iqs620_pwm_probe()
236 dev_err(&pdev->dev, "Failed to add device: %d\n", ret); in iqs620_pwm_probe()
243 .name = "iqs620a-pwm",
252 MODULE_ALIAS("platform:iqs620a-pwm");