Lines Matching +full:pwm +full:- +full:outputs
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()
43 return ERR_PTR(-ENOMEM); in lp3943_pwm_request_map()
45 pwm_map->output = pdata->pwms[hwpwm]->output; in lp3943_pwm_request_map()
46 pwm_map->num_outputs = pdata->pwms[hwpwm]->num_outputs; in lp3943_pwm_request_map()
48 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_request_map()
49 offset = pwm_map->output[i]; in lp3943_pwm_request_map()
52 if (test_and_set_bit(offset, &lp3943->pin_used)) { in lp3943_pwm_request_map()
54 return ERR_PTR(-EBUSY); in lp3943_pwm_request_map()
61 static int lp3943_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_request() argument
66 pwm_map = lp3943_pwm_request_map(lp3943_pwm, pwm->hwpwm); in lp3943_pwm_request()
70 return pwm_set_chip_data(pwm, pwm_map); in lp3943_pwm_request()
76 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_free_map()
79 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_free_map()
80 offset = pwm_map->output[i]; in lp3943_pwm_free_map()
81 clear_bit(offset, &lp3943->pin_used); in lp3943_pwm_free_map()
87 static void lp3943_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_free() argument
90 struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); in lp3943_pwm_free()
95 static int lp3943_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, in lp3943_pwm_config() argument
99 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_config()
107 * 2) Prescale = period / 6250 -1 in lp3943_pwm_config()
113 if (pwm->hwpwm == 0) { in lp3943_pwm_config()
122 val = (u8)(period_ns / LP3943_MIN_PERIOD - 1); in lp3943_pwm_config()
137 struct lp3943 *lp3943 = lp3943_pwm->lp3943; in lp3943_pwm_set_mode()
138 const struct lp3943_reg_cfg *mux = lp3943->mux_cfg; in lp3943_pwm_set_mode()
141 for (i = 0; i < pwm_map->num_outputs; i++) { in lp3943_pwm_set_mode()
142 index = pwm_map->output[i]; in lp3943_pwm_set_mode()
153 static int lp3943_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_enable() argument
156 struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); in lp3943_pwm_enable()
159 if (pwm->hwpwm == 0) in lp3943_pwm_enable()
165 * Each PWM generator is set to control any of outputs of LP3943. in lp3943_pwm_enable()
166 * To enable/disable the PWM, these output pins should be configured. in lp3943_pwm_enable()
172 static void lp3943_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) in lp3943_pwm_disable() argument
175 struct lp3943_pwm_map *pwm_map = pwm_get_chip_data(pwm); in lp3943_pwm_disable()
178 * LP3943 outputs are open-drain, so the pin should be configured in lp3943_pwm_disable()
179 * when the PWM is disabled. in lp3943_pwm_disable()
198 struct device_node *node = dev->of_node; in lp3943_pwm_parse_dt()
206 return -EINVAL; in lp3943_pwm_parse_dt()
210 return -ENOMEM; in lp3943_pwm_parse_dt()
214 * Each of the two PWM generators can drive zero or more outputs. in lp3943_pwm_parse_dt()
228 return -ENOMEM; in lp3943_pwm_parse_dt()
237 return -ENOMEM; in lp3943_pwm_parse_dt()
239 pwm_map->output = output; in lp3943_pwm_parse_dt()
240 pwm_map->num_outputs = num_outputs; in lp3943_pwm_parse_dt()
241 pdata->pwms[i] = pwm_map; in lp3943_pwm_parse_dt()
247 return -ENODATA; in lp3943_pwm_parse_dt()
249 lp3943_pwm->pdata = pdata; in lp3943_pwm_parse_dt()
255 struct lp3943 *lp3943 = dev_get_drvdata(pdev->dev.parent); in lp3943_pwm_probe()
259 lp3943_pwm = devm_kzalloc(&pdev->dev, sizeof(*lp3943_pwm), GFP_KERNEL); in lp3943_pwm_probe()
261 return -ENOMEM; in lp3943_pwm_probe()
263 lp3943_pwm->pdata = lp3943->pdata; in lp3943_pwm_probe()
264 if (!lp3943_pwm->pdata) { in lp3943_pwm_probe()
266 ret = lp3943_pwm_parse_dt(&pdev->dev, lp3943_pwm); in lp3943_pwm_probe()
268 ret = -ENODEV; in lp3943_pwm_probe()
274 lp3943_pwm->lp3943 = lp3943; in lp3943_pwm_probe()
275 lp3943_pwm->chip.dev = &pdev->dev; in lp3943_pwm_probe()
276 lp3943_pwm->chip.ops = &lp3943_pwm_ops; in lp3943_pwm_probe()
277 lp3943_pwm->chip.npwm = LP3943_NUM_PWMS; in lp3943_pwm_probe()
281 return pwmchip_add(&lp3943_pwm->chip); in lp3943_pwm_probe()
288 return pwmchip_remove(&lp3943_pwm->chip); in lp3943_pwm_remove()
293 { .compatible = "ti,lp3943-pwm", },
303 .name = "lp3943-pwm",
309 MODULE_DESCRIPTION("LP3943 PWM driver");
310 MODULE_ALIAS("platform:lp3943-pwm");