mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 04:18:39 +08:00
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:
parent
c3492db288
commit
f20fb5c858
@ -27,13 +27,12 @@
|
||||
|
||||
struct stmpe_pwm {
|
||||
struct stmpe *stmpe;
|
||||
struct pwm_chip chip;
|
||||
u8 last_duty;
|
||||
};
|
||||
|
||||
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)
|
||||
@ -292,33 +291,36 @@ static const struct pwm_ops stmpe_24xx_pwm_ops = {
|
||||
static int __init stmpe_pwm_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct stmpe *stmpe = dev_get_drvdata(pdev->dev.parent);
|
||||
struct pwm_chip *chip;
|
||||
struct stmpe_pwm *stmpe_pwm;
|
||||
int ret;
|
||||
|
||||
stmpe_pwm = devm_kzalloc(&pdev->dev, sizeof(*stmpe_pwm), GFP_KERNEL);
|
||||
if (!stmpe_pwm)
|
||||
return -ENOMEM;
|
||||
switch (stmpe->partnum) {
|
||||
case STMPE2401:
|
||||
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->chip.dev = &pdev->dev;
|
||||
|
||||
if (stmpe->partnum == STMPE2401 || stmpe->partnum == STMPE2403) {
|
||||
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;
|
||||
}
|
||||
chip->ops = &stmpe_24xx_pwm_ops;
|
||||
|
||||
ret = stmpe_enable(stmpe, STMPE_BLOCK_PWM);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = pwmchip_add(&stmpe_pwm->chip);
|
||||
ret = pwmchip_add(chip);
|
||||
if (ret) {
|
||||
stmpe_disable(stmpe, STMPE_BLOCK_PWM);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user