Skip to content

Commit 5f62383

Browse files
author
Uwe Kleine-König
committed
pwm: sti: Fix capture for st,pwm-num-chan < st,capture-num-chan
The driver only used the number of pwm channels to set the pwm_chip's npwm member. The result is that if there are more capture channels than PWM channels specified in the device tree, only a part of the capture channel is usable. Fix that by passing the bigger channel count to the pwm framework. This makes it possible that the .apply() callback is called with .hwpwm >= pwm_num_devs, catch that case and return an error code. Fixes: c97267a ("pwm: sti: Add PWM capture callback") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent e25ac87 commit 5f62383

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/pwm/pwm-sti.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,17 @@ static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
395395
static int sti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
396396
const struct pwm_state *state)
397397
{
398+
struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
399+
struct sti_pwm_compat_data *cdata = pc->cdata;
400+
struct device *dev = pc->dev;
398401
int err;
399402

403+
if (pwm->hwpwm >= cdata->pwm_num_devs) {
404+
dev_err(dev, "device %u is not valid for pwm mode\n",
405+
pwm->hwpwm);
406+
return -EINVAL;
407+
}
408+
400409
if (state->polarity != PWM_POLARITY_NORMAL)
401410
return -EINVAL;
402411

@@ -646,7 +655,7 @@ static int sti_pwm_probe(struct platform_device *pdev)
646655

647656
pc->chip.dev = dev;
648657
pc->chip.ops = &sti_pwm_ops;
649-
pc->chip.npwm = pc->cdata->pwm_num_devs;
658+
pc->chip.npwm = max(cdata->pwm_num_devs, cdata->cpt_num_devs);
650659

651660
for (i = 0; i < cdata->cpt_num_devs; i++) {
652661
struct sti_cpt_ddata *ddata = &cdata->ddata[i];

0 commit comments

Comments
 (0)