Lines Matching +full:- +full:pwm

1 // SPDX-License-Identifier: GPL-2.0-only
12 #include <linux/pwm.h>
32 #define TWL4030_PWM_TOGGLE(pwm, x) ((x) << (pwm)) argument
46 #define TWL6030_PWM_TOGGLE(pwm, x) ((x) << (pwm * 3)) argument
59 static int twl_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in twl_pwm_config() argument
68 * On-cycle is set to 1 (the minimum allowed value) in twl_pwm_config()
70 * 0 -> off cycle = 2, in twl_pwm_config()
71 * 1 -> off cycle = 2, in twl_pwm_config()
72 * 2 -> off cycle = 3, in twl_pwm_config()
73 * 126 - > off cycle 127, in twl_pwm_config()
74 * 127 - > off cycle 1 in twl_pwm_config()
75 * When on cycle == off cycle the PWM will be always on in twl_pwm_config()
82 base = pwm->hwpwm * 3; in twl_pwm_config()
88 dev_err(pwmchip_parent(chip), "%s: Failed to configure PWM\n", pwm->label); in twl_pwm_config()
93 static int twl4030_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwm_enable() argument
99 mutex_lock(&twl->mutex); in twl4030_pwm_enable()
102 dev_err(pwmchip_parent(chip), "%s: Failed to read GPBR1\n", pwm->label); in twl4030_pwm_enable()
106 val |= TWL4030_PWM_TOGGLE(pwm->hwpwm, TWL4030_PWMXCLK_ENABLE); in twl4030_pwm_enable()
110 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl4030_pwm_enable()
112 val |= TWL4030_PWM_TOGGLE(pwm->hwpwm, TWL4030_PWMX_ENABLE); in twl4030_pwm_enable()
116 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl4030_pwm_enable()
119 mutex_unlock(&twl->mutex); in twl4030_pwm_enable()
123 static void twl4030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwm_disable() argument
129 mutex_lock(&twl->mutex); in twl4030_pwm_disable()
132 dev_err(pwmchip_parent(chip), "%s: Failed to read GPBR1\n", pwm->label); in twl4030_pwm_disable()
136 val &= ~TWL4030_PWM_TOGGLE(pwm->hwpwm, TWL4030_PWMX_ENABLE); in twl4030_pwm_disable()
140 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl4030_pwm_disable()
142 val &= ~TWL4030_PWM_TOGGLE(pwm->hwpwm, TWL4030_PWMXCLK_ENABLE); in twl4030_pwm_disable()
146 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl4030_pwm_disable()
149 mutex_unlock(&twl->mutex); in twl4030_pwm_disable()
152 static int twl4030_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwm_request() argument
158 if (pwm->hwpwm == 1) { in twl4030_pwm_request()
166 mutex_lock(&twl->mutex); in twl4030_pwm_request()
169 dev_err(pwmchip_parent(chip), "%s: Failed to read PMBR1\n", pwm->label); in twl4030_pwm_request()
173 /* Save the current MUX configuration for the PWM */ in twl4030_pwm_request()
174 twl->twl4030_pwm_mux &= ~mask; in twl4030_pwm_request()
175 twl->twl4030_pwm_mux |= (val & mask); in twl4030_pwm_request()
177 /* Select PWM functionality */ in twl4030_pwm_request()
183 dev_err(pwmchip_parent(chip), "%s: Failed to request PWM\n", pwm->label); in twl4030_pwm_request()
186 mutex_unlock(&twl->mutex); in twl4030_pwm_request()
190 static void twl4030_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) in twl4030_pwm_free() argument
196 if (pwm->hwpwm == 1) in twl4030_pwm_free()
201 mutex_lock(&twl->mutex); in twl4030_pwm_free()
204 dev_err(pwmchip_parent(chip), "%s: Failed to read PMBR1\n", pwm->label); in twl4030_pwm_free()
208 /* Restore the MUX configuration for the PWM */ in twl4030_pwm_free()
210 val |= (twl->twl4030_pwm_mux & mask); in twl4030_pwm_free()
214 dev_err(pwmchip_parent(chip), "%s: Failed to free PWM\n", pwm->label); in twl4030_pwm_free()
217 mutex_unlock(&twl->mutex); in twl4030_pwm_free()
220 static int twl6030_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwm_enable() argument
226 mutex_lock(&twl->mutex); in twl6030_pwm_enable()
227 val = twl->twl6030_toggle3; in twl6030_pwm_enable()
228 val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXS | TWL6030_PWMXEN); in twl6030_pwm_enable()
229 val &= ~TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXR); in twl6030_pwm_enable()
233 dev_err(pwmchip_parent(chip), "%s: Failed to enable PWM\n", pwm->label); in twl6030_pwm_enable()
237 twl->twl6030_toggle3 = val; in twl6030_pwm_enable()
239 mutex_unlock(&twl->mutex); in twl6030_pwm_enable()
243 static void twl6030_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in twl6030_pwm_disable() argument
249 mutex_lock(&twl->mutex); in twl6030_pwm_disable()
250 val = twl->twl6030_toggle3; in twl6030_pwm_disable()
251 val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXR); in twl6030_pwm_disable()
252 val &= ~TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXS | TWL6030_PWMXEN); in twl6030_pwm_disable()
256 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl6030_pwm_disable()
260 val |= TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXEN); in twl6030_pwm_disable()
264 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl6030_pwm_disable()
268 val &= ~TWL6030_PWM_TOGGLE(pwm->hwpwm, TWL6030_PWMXEN); in twl6030_pwm_disable()
272 dev_err(pwmchip_parent(chip), "%s: Failed to disable PWM\n", pwm->label); in twl6030_pwm_disable()
276 twl->twl6030_toggle3 = val; in twl6030_pwm_disable()
278 mutex_unlock(&twl->mutex); in twl6030_pwm_disable()
281 static int twl4030_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl4030_pwm_apply() argument
286 if (state->polarity != PWM_POLARITY_NORMAL) in twl4030_pwm_apply()
287 return -EINVAL; in twl4030_pwm_apply()
289 if (!state->enabled) { in twl4030_pwm_apply()
290 if (pwm->state.enabled) in twl4030_pwm_apply()
291 twl4030_pwm_disable(chip, pwm); in twl4030_pwm_apply()
296 err = twl_pwm_config(chip, pwm, state->duty_cycle, state->period); in twl4030_pwm_apply()
300 if (!pwm->state.enabled) in twl4030_pwm_apply()
301 err = twl4030_pwm_enable(chip, pwm); in twl4030_pwm_apply()
306 static int twl6030_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in twl6030_pwm_apply() argument
311 if (state->polarity != PWM_POLARITY_NORMAL) in twl6030_pwm_apply()
312 return -EINVAL; in twl6030_pwm_apply()
314 if (!state->enabled) { in twl6030_pwm_apply()
315 if (pwm->state.enabled) in twl6030_pwm_apply()
316 twl6030_pwm_disable(chip, pwm); in twl6030_pwm_apply()
321 err = twl_pwm_config(chip, pwm, state->duty_cycle, state->period); in twl6030_pwm_apply()
325 if (!pwm->state.enabled) in twl6030_pwm_apply()
326 err = twl6030_pwm_enable(chip, pwm); in twl6030_pwm_apply()
346 chip = devm_pwmchip_alloc(&pdev->dev, 2, sizeof(*twl)); in twl_pwm_probe()
352 chip->ops = &twl4030_pwm_ops; in twl_pwm_probe()
354 chip->ops = &twl6030_pwm_ops; in twl_pwm_probe()
356 mutex_init(&twl->mutex); in twl_pwm_probe()
358 return devm_pwmchip_add(&pdev->dev, chip); in twl_pwm_probe()
363 { .compatible = "ti,twl4030-pwm" },
364 { .compatible = "ti,twl6030-pwm" },
372 .name = "twl-pwm",
380 MODULE_DESCRIPTION("PWM driver for TWL4030 and TWL6030");
381 MODULE_ALIAS("platform:twl-pwm");