Lines Matching +full:off +full:- +full:chip

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
68 static inline struct twl_pwmled_chip *to_twl(struct pwm_chip *chip) in to_twl() argument
70 return pwmchip_get_drvdata(chip); in to_twl()
73 static int twl4030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm, in twl4030_pwmled_config() argument
82 * On-cycle is set to 1 (the minimum allowed value) in twl4030_pwmled_config()
83 * The off time of 0 is not configurable, so the mapping is: in twl4030_pwmled_config()
84 * 0 -> off cycle = 2, in twl4030_pwmled_config()
85 * 1 -> off cycle = 2, in twl4030_pwmled_config()
86 * 2 -> off cycle = 3, in twl4030_pwmled_config()
87 * 126 - > off cycle 127, in twl4030_pwmled_config()
88 * 127 - > off cycle 1 in twl4030_pwmled_config()
89 * When on cycle == off cycle the PWM will be always on in twl4030_pwmled_config()
96 base = pwm->hwpwm * 2 + TWL4030_PWMA_REG; in twl4030_pwmled_config()
102 dev_err(pwmchip_parent(chip), "%s: Failed to configure PWM\n", pwm->label); in twl4030_pwmled_config()
107 static int twl4030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwmled_enable() argument
109 struct twl_pwmled_chip *twl = to_twl(chip); in twl4030_pwmled_enable()
113 mutex_lock(&twl->mutex); in twl4030_pwmled_enable()
116 dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label); in twl4030_pwmled_enable()
120 val |= TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS); in twl4030_pwmled_enable()
124 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl4030_pwmled_enable()
127 mutex_unlock(&twl->mutex); in twl4030_pwmled_enable()
131 static void twl4030_pwmled_disable(struct pwm_chip *chip, in twl4030_pwmled_disable() argument
134 struct twl_pwmled_chip *twl = to_twl(chip); in twl4030_pwmled_disable()
138 mutex_lock(&twl->mutex); in twl4030_pwmled_disable()
141 dev_err(pwmchip_parent(chip), "%s: Failed to read LEDEN\n", pwm->label); in twl4030_pwmled_disable()
145 val &= ~TWL4030_LED_TOGGLE(pwm->hwpwm, TWL4030_LED_PINS); in twl4030_pwmled_disable()
149 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl4030_pwmled_disable()
152 mutex_unlock(&twl->mutex); in twl4030_pwmled_disable()
155 static int twl4030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl4030_pwmled_apply() argument
160 if (state->polarity != PWM_POLARITY_NORMAL) in twl4030_pwmled_apply()
161 return -EINVAL; in twl4030_pwmled_apply()
163 if (!state->enabled) { in twl4030_pwmled_apply()
164 if (pwm->state.enabled) in twl4030_pwmled_apply()
165 twl4030_pwmled_disable(chip, pwm); in twl4030_pwmled_apply()
171 * We cannot skip calling ->config even if state->period == in twl4030_pwmled_apply()
172 * pwm->state.period && state->duty_cycle == pwm->state.duty_cycle in twl4030_pwmled_apply()
174 * pwm_apply_might_sleep because of !state->enabled and so the two values in in twl4030_pwmled_apply()
175 * pwm->state might not be configured in hardware. in twl4030_pwmled_apply()
177 ret = twl4030_pwmled_config(chip, pwm, in twl4030_pwmled_apply()
178 state->duty_cycle, state->period); in twl4030_pwmled_apply()
182 if (!pwm->state.enabled) in twl4030_pwmled_apply()
183 ret = twl4030_pwmled_enable(chip, pwm); in twl4030_pwmled_apply()
193 static int twl6030_pwmled_config(struct pwm_chip *chip, struct pwm_device *pwm, in twl6030_pwmled_config() argument
205 dev_err(pwmchip_parent(chip), "%s: Failed to configure PWM\n", pwm->label); in twl6030_pwmled_config()
210 static int twl6030_pwmled_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_enable() argument
212 struct twl_pwmled_chip *twl = to_twl(chip); in twl6030_pwmled_enable()
216 mutex_lock(&twl->mutex); in twl6030_pwmled_enable()
219 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_enable()
220 pwm->label); in twl6030_pwmled_enable()
229 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl6030_pwmled_enable()
232 mutex_unlock(&twl->mutex); in twl6030_pwmled_enable()
236 static void twl6030_pwmled_disable(struct pwm_chip *chip, in twl6030_pwmled_disable() argument
239 struct twl_pwmled_chip *twl = to_twl(chip); in twl6030_pwmled_disable()
243 mutex_lock(&twl->mutex); in twl6030_pwmled_disable()
246 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_disable()
247 pwm->label); in twl6030_pwmled_disable()
256 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl6030_pwmled_disable()
259 mutex_unlock(&twl->mutex); in twl6030_pwmled_disable()
262 static int twl6030_pwmled_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl6030_pwmled_apply() argument
267 if (state->polarity != pwm->state.polarity) in twl6030_pwmled_apply()
268 return -EINVAL; in twl6030_pwmled_apply()
270 if (!state->enabled) { in twl6030_pwmled_apply()
271 if (pwm->state.enabled) in twl6030_pwmled_apply()
272 twl6030_pwmled_disable(chip, pwm); in twl6030_pwmled_apply()
277 err = twl6030_pwmled_config(chip, pwm, in twl6030_pwmled_apply()
278 state->duty_cycle, state->period); in twl6030_pwmled_apply()
282 if (!pwm->state.enabled) in twl6030_pwmled_apply()
283 err = twl6030_pwmled_enable(chip, pwm); in twl6030_pwmled_apply()
288 static int twl6030_pwmled_request(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_request() argument
290 struct twl_pwmled_chip *twl = to_twl(chip); in twl6030_pwmled_request()
294 mutex_lock(&twl->mutex); in twl6030_pwmled_request()
297 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_request()
298 pwm->label); in twl6030_pwmled_request()
307 dev_err(pwmchip_parent(chip), "%s: Failed to request PWM\n", pwm->label); in twl6030_pwmled_request()
310 mutex_unlock(&twl->mutex); in twl6030_pwmled_request()
314 static void twl6030_pwmled_free(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwmled_free() argument
316 struct twl_pwmled_chip *twl = to_twl(chip); in twl6030_pwmled_free()
320 mutex_lock(&twl->mutex); in twl6030_pwmled_free()
323 dev_err(pwmchip_parent(chip), "%s: Failed to read PWM_CTRL2\n", in twl6030_pwmled_free()
324 pwm->label); in twl6030_pwmled_free()
333 dev_err(pwmchip_parent(chip), "%s: Failed to free PWM\n", pwm->label); in twl6030_pwmled_free()
336 mutex_unlock(&twl->mutex); in twl6030_pwmled_free()
347 struct pwm_chip *chip; in twl_pwmled_probe() local
360 chip = devm_pwmchip_alloc(&pdev->dev, npwm, sizeof(*twl)); in twl_pwmled_probe()
361 if (IS_ERR(chip)) in twl_pwmled_probe()
362 return PTR_ERR(chip); in twl_pwmled_probe()
363 twl = to_twl(chip); in twl_pwmled_probe()
365 chip->ops = ops; in twl_pwmled_probe()
367 mutex_init(&twl->mutex); in twl_pwmled_probe()
369 return devm_pwmchip_add(&pdev->dev, chip); in twl_pwmled_probe()
374 { .compatible = "ti,twl4030-pwmled" },
375 { .compatible = "ti,twl6030-pwmled" },
383 .name = "twl-pwmled",
392 MODULE_ALIAS("platform:twl-pwmled");