Lines Matching +full:pwm +full:- +full:offset
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI/National Semiconductor LP3943 PWM driver
15 #include <linux/pwm.h>
36 struct lp3943_platform_data *pdata = lp3943_pwm->pdata; in lp3943_pwm_request_map()
37 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_request_map()
38 struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[hwpwm]; in lp3943_pwm_request_map()
39 int i, offset; in lp3943_pwm_request_map() local
41 pwm_map->output = pdata->pwms[hwpwm]->output; in lp3943_pwm_request_map()
42 pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs; in lp3943_pwm_request_map()
44 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_request_map()
45 offset = pwm_map->output[i]; in lp3943_pwm_request_map()
48 if (test_and_set_bit(offset, &lp3943->pin_used)) in lp3943_pwm_request_map()
49 return ERR_PTR(-EBUSY); in lp3943_pwm_request_map()
55 static int lp3943_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_request() argument
60 pwm_map = lp3943_pwm_request_map(lp3943_pwm, pwm->hwpwm); in lp3943_pwm_request()
70 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_free_map()
71 int i, offset; in lp3943_pwm_free_map() local
73 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_free_map()
74 offset = pwm_map->output[i]; in lp3943_pwm_free_map()
75 clear_bit(offset, &lp3943->pin_used); in lp3943_pwm_free_map()
79 static void lp3943_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_free() argument
82 struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; in lp3943_pwm_free()
87 static int lp3943_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in lp3943_pwm_config() argument
91 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_config()
99 * 2) Prescale = period / 6250 -1 in lp3943_pwm_config()
105 if (pwm->hwpwm == 0) { in lp3943_pwm_config()
119 val = (u8)((int)period_ns / LP3943_MIN_PERIOD - 1); in lp3943_pwm_config()
135 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_set_mode()
136 const struct lp3943_reg_cfg *mux = lp3943->mux_cfg; in lp3943_pwm_set_mode()
139 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_set_mode()
140 index = pwm_map->output[i]; in lp3943_pwm_set_mode()
151 static int lp3943_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_enable() argument
154 struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; in lp3943_pwm_enable()
157 if (pwm->hwpwm == 0) in lp3943_pwm_enable()
163 * Each PWM generator is set to control any of outputs of LP3943. in lp3943_pwm_enable()
164 * To enable/disable the PWM, these output pins should be configured. in lp3943_pwm_enable()
170 static void lp3943_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_disable() argument
173 struct lp3943_pwm_map *pwm_map = &lp3943_pwm->pwm_map[pwm->hwpwm]; in lp3943_pwm_disable()
176 * LP3943 outputs are open-drain, so the pin should be configured in lp3943_pwm_disable()
177 * when the PWM is disabled. in lp3943_pwm_disable()
183 static int lp3943_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, in lp3943_pwm_apply() argument
188 if (state->polarity != PWM_POLARITY_NORMAL) in lp3943_pwm_apply()
189 return -EINVAL; in lp3943_pwm_apply()
191 if (!state->enabled) { in lp3943_pwm_apply()
192 if (pwm->state.enabled) in lp3943_pwm_apply()
193 lp3943_pwm_disable(chip, pwm); in lp3943_pwm_apply()
197 err = lp3943_pwm_config(chip, pwm, state->duty_cycle, state->period); in lp3943_pwm_apply()
201 if (!pwm->state.enabled) in lp3943_pwm_apply()
202 err = lp3943_pwm_enable(chip, pwm); in lp3943_pwm_apply()
217 struct device_node *node = dev->of_node; in lp3943_pwm_parse_dt()
224 return -EINVAL; in lp3943_pwm_parse_dt()
228 return -ENOMEM; in lp3943_pwm_parse_dt()
232 * Each of the two PWM generators can drive zero or more outputs. in lp3943_pwm_parse_dt()
243 return -ENOMEM; in lp3943_pwm_parse_dt()
252 return -ENOMEM; in lp3943_pwm_parse_dt()
254 pwm_map->output = output; in lp3943_pwm_parse_dt()
255 pwm_map->num_outputs = num_outputs; in lp3943_pwm_parse_dt()
256 pdata->pwms[i] = pwm_map; in lp3943_pwm_parse_dt()
262 return -ENODATA; in lp3943_pwm_parse_dt()
264 lp3943_pwm->pdata = pdata; in lp3943_pwm_parse_dt()
270 struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent); in lp3943_pwm_probe()
275 chip = devm_pwmchip_alloc(&pdev->dev, LP3943_NUM_PWMS, sizeof(*lp3943_pwm)); in lp3943_pwm_probe()
280 lp3943_pwm->pdata = lp3943->pdata; in lp3943_pwm_probe()
281 if (!lp3943_pwm->pdata) { in lp3943_pwm_probe()
283 ret = lp3943_pwm_parse_dt(&pdev->dev, lp3943_pwm); in lp3943_pwm_probe()
285 ret = -ENODEV; in lp3943_pwm_probe()
291 lp3943_pwm->lp3943 = lp3943; in lp3943_pwm_probe()
292 chip->ops = &lp3943_pwm_ops; in lp3943_pwm_probe()
294 return devm_pwmchip_add(&pdev->dev, chip); in lp3943_pwm_probe()
299 { .compatible = "ti,lp3943-pwm", },
308 .name = "lp3943-pwm",
314 MODULE_DESCRIPTION("LP3943 PWM driver");
315 MODULE_ALIAS("platform:lp3943-pwm");