pwm: stmpe: Make use of devm_pwmchip_alloc() function

This prepares the pwm-stmpe driver to further changes of the pwm core
outlined in the commit introducing devm_pwmchip_alloc(). There is no
intended semantical change and the driver should behave as before.

Link: https://lore.kernel.org/r/7e3dbf3b70126038c0ba16331ca8c07cab575bd3.1707900770.git.u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This commit is contained in:
Uwe Kleine-König 2024-02-14 10:32:50 +01:00
parent c3492db288
commit f20fb5c858

View File

@ -27,13 +27,12 @@
struct stmpe_pwm { struct stmpe_pwm {
struct stmpe *stmpe; struct stmpe *stmpe;
struct pwm_chip chip;
u8 last_duty; u8 last_duty;
}; };
static inline struct stmpe_pwm *to_stmpe_pwm(struct pwm_chip *chip) static inline struct stmpe_pwm *to_stmpe_pwm(struct pwm_chip *chip)
{ {
return container_of(chip, struct stmpe_pwm, chip); return pwmchip_get_drvdata(chip);
} }
static int stmpe_24xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) static int stmpe_24xx_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
@ -292,33 +291,36 @@ static const struct pwm_ops stmpe_24xx_pwm_ops = {
static int __init stmpe_pwm_probe(struct platform_device *pdev) static int __init stmpe_pwm_probe(struct platform_device *pdev)
{ {
struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent); struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
struct pwm_chip *chip;
struct stmpe_pwm *stmpe_pwm; struct stmpe_pwm *stmpe_pwm;
int ret; int ret;
stmpe_pwm = devm_kzalloc(&pdev->dev, sizeof(*stmpe_pwm), GFP_KERNEL); switch (stmpe->partnum) {
if (!stmpe_pwm) case STMPE2401:
return -ENOMEM; case STMPE2403:
break;
case STMPE1601:
return dev_err_probe(&pdev->dev, -ENODEV,
"STMPE1601 not yet supported\n");
default:
return dev_err_probe(&pdev->dev, -ENODEV,
"Unknown STMPE PWM\n");
}
chip = devm_pwmchip_alloc(&pdev->dev, 3, sizeof(*stmpe_pwm));
if (IS_ERR(chip))
return PTR_ERR(chip);
stmpe_pwm = to_stmpe_pwm(chip);
stmpe_pwm->stmpe = stmpe; stmpe_pwm->stmpe = stmpe;
stmpe_pwm->chip.dev = &pdev->dev;
if (stmpe->partnum == STMPE2401 || stmpe->partnum == STMPE2403) { chip->ops = &stmpe_24xx_pwm_ops;
stmpe_pwm->chip.ops = &stmpe_24xx_pwm_ops;
stmpe_pwm->chip.npwm = 3;
} else {
if (stmpe->partnum == STMPE1601)
dev_err(&pdev->dev, "STMPE1601 not yet supported\n");
else
dev_err(&pdev->dev, "Unknown STMPE PWM\n");
return -ENODEV;
}
ret = stmpe_enable(stmpe, STMPE_BLOCK_PWM); ret = stmpe_enable(stmpe, STMPE_BLOCK_PWM);
if (ret) if (ret)
return ret; return ret;
ret = pwmchip_add(&stmpe_pwm->chip); ret = pwmchip_add(chip);
if (ret) { if (ret) {
stmpe_disable(stmpe, STMPE_BLOCK_PWM); stmpe_disable(stmpe, STMPE_BLOCK_PWM);
return ret; return ret;