Skip to content

Commit

Permalink
pwm: sti: Fix capture for st,pwm-num-chan < st,capture-num-chan
Browse files Browse the repository at this point in the history
[ Upstream commit 5f62383 ]

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]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Uwe Kleine-König authored and Sasha Levin committed Mar 26, 2024
1 parent d73b916 commit 23f96f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/pwm/pwm-sti.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,17 @@ static int sti_pwm_capture(struct pwm_chip *chip, struct pwm_device *pwm,
static int sti_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
const struct pwm_state *state)
{
struct sti_pwm_chip *pc = to_sti_pwmchip(chip);
struct sti_pwm_compat_data *cdata = pc->cdata;
struct device *dev = pc->dev;
int err;

if (pwm->hwpwm >= cdata->pwm_num_devs) {
dev_err(dev, "device %u is not valid for pwm mode\n",
pwm->hwpwm);
return -EINVAL;
}

if (state->polarity != PWM_POLARITY_NORMAL)
return -EINVAL;

Expand Down Expand Up @@ -647,7 +656,7 @@ static int sti_pwm_probe(struct platform_device *pdev)

pc->chip.dev = dev;
pc->chip.ops = &sti_pwm_ops;
pc->chip.npwm = pc->cdata->pwm_num_devs;
pc->chip.npwm = max(cdata->pwm_num_devs, cdata->cpt_num_devs);

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

0 comments on commit 23f96f8

Please sign in to comment.