Lines Matching +full:chip +full:- +full:relative

1 // SPDX-License-Identifier: GPL-2.0-only
8 * This driver is a complete rewrite of the former pwm-twl6030.c authorded by:
15 * - The twl6030 hardware only supports two period lengths (128 clock ticks and
17 * - The hardware doesn't support ON = 0, so the active part of a period doesn't
19 * - The hardware could support inverted polarity (with a similar limitation as
21 * - The hardware emits a constant low output when disabled.
22 * - A request for .duty_cycle = 0 results in an output wave with one active
24 * - The driver only implements setting the relative duty cycle.
25 * - The driver doesn't implement .get_state().
38 * - LEDA uses PWMA
39 * - LEDB uses PWMB
64 static inline struct twl_pwmled_chip *to_twl(struct pwm_chip *chip) in to_twl() argument
66 return pwmchip_get_drvdata(chip); in to_twl()
69 static int twl4030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm, in twl4030_pwmled_config() argument
78 * On-cycle is set to 1 (the minimum allowed value) in twl4030_pwmled_config()
80 * 0 -> off cycle = 2, in twl4030_pwmled_config()
81 * 1 -> off cycle = 2, in twl4030_pwmled_config()
82 * 2 -> off cycle = 3, in twl4030_pwmled_config()
83 * 126 - > off cycle 127, in twl4030_pwmled_config()
84 * 127 - > off cycle 1 in twl4030_pwmled_config()
92 base = pwm->hwpwm * 2 + TWL4030_PWMA_REG; in twl4030_pwmled_config()
98 dev_err(pwmchip_parent(chip), "%s: Failed to configure PWM\n", pwm->label); in twl4030_pwmled_config()
103 static int twl4030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwmled_enable() argument
110 dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label); in twl4030_pwmled_enable()
114 val |= TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS); in twl4030_pwmled_enable()
118 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl4030_pwmled_enable()
123 static void twl4030_pwmled_disable(struct pwm_chip *chip, in twl4030_pwmled_disable() argument
131 dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label); in twl4030_pwmled_disable()
135 val &= ~TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS); in twl4030_pwmled_disable()
139 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl4030_pwmled_disable()
142 static int twl4030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl4030_pwmled_apply() argument
147 if (state->polarity != PWM_POLARITY_NORMAL) in twl4030_pwmled_apply()
148 return -EINVAL; in twl4030_pwmled_apply()
150 if (!state->enabled) { in twl4030_pwmled_apply()
151 if (pwm->state.enabled) in twl4030_pwmled_apply()
152 twl4030_pwmled_disable(chip, pwm); in twl4030_pwmled_apply()
158 * We cannot skip calling ->config even if state->period == in twl4030_pwmled_apply()
159 * pwm->state.period && state->duty_cycle == pwm->state.duty_cycle in twl4030_pwmled_apply()
161 * pwm_apply_might_sleep because of !state->enabled and so the two values in in twl4030_pwmled_apply()
162 * pwm->state might not be configured in hardware. in twl4030_pwmled_apply()
164 ret = twl4030_pwmled_config(chip, pwm, in twl4030_pwmled_apply()
165 state->duty_cycle, state->period); in twl4030_pwmled_apply()
169 if (!pwm->state.enabled) in twl4030_pwmled_apply()
170 ret = twl4030_pwmled_enable(chip, pwm); in twl4030_pwmled_apply()
180 static int twl6030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm, in twl6030_pwmled_config() argument
192 dev_err(pwmchip_parent(chip), "%s: Failed to configure PWM\n", pwm->label); in twl6030_pwmled_config()
197 static int twl6030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_enable() argument
204 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_enable()
205 pwm->label); in twl6030_pwmled_enable()
214 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl6030_pwmled_enable()
219 static void twl6030_pwmled_disable(struct pwm_chip *chip, in twl6030_pwmled_disable() argument
227 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_disable()
228 pwm->label); in twl6030_pwmled_disable()
237 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl6030_pwmled_disable()
240 static int twl6030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl6030_pwmled_apply() argument
245 if (state->polarity != pwm->state.polarity) in twl6030_pwmled_apply()
246 return -EINVAL; in twl6030_pwmled_apply()
248 if (!state->enabled) { in twl6030_pwmled_apply()
249 if (pwm->state.enabled) in twl6030_pwmled_apply()
250 twl6030_pwmled_disable(chip, pwm); in twl6030_pwmled_apply()
255 err = twl6030_pwmled_config(chip, pwm, in twl6030_pwmled_apply()
256 state->duty_cycle, state->period); in twl6030_pwmled_apply()
260 if (!pwm->state.enabled) in twl6030_pwmled_apply()
261 err = twl6030_pwmled_enable(chip, pwm); in twl6030_pwmled_apply()
266 static int twl6030_pwmled_request(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_request() argument
273 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_request()
274 pwm->label); in twl6030_pwmled_request()
283 dev_err(pwmchip_parent(chip), "%s: Failed to request PWM\n", pwm->label); in twl6030_pwmled_request()
288 static void twl6030_pwmled_free(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_free() argument
295 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_free()
296 pwm->label); in twl6030_pwmled_free()
305 dev_err(pwmchip_parent(chip), "%s: Failed to free PWM\n", pwm->label); in twl6030_pwmled_free()
316 struct pwm_chip *chip; in twl_pwmled_probe() local
328 chip = devm_pwmchip_alloc(&pdev->dev, npwm, 0); in twl_pwmled_probe()
329 if (IS_ERR(chip)) in twl_pwmled_probe()
330 return PTR_ERR(chip); in twl_pwmled_probe()
332 chip->ops = ops; in twl_pwmled_probe()
334 return devm_pwmchip_add(&pdev->dev, chip); in twl_pwmled_probe()
339 { .compatible = "ti,twl4030-pwmled" },
340 { .compatible = "ti,twl6030-pwmled" },
348 .name = "twl-pwmled",
357 MODULE_ALIAS("platform:twl-pwmled");