Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89d1b9df authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Greg Kroah-Hartman
Browse files

pwm: lp3943: Fix duty calculation in case period was clamped



[ Upstream commit 5e3b07ca5cc78cd4a987e78446849e41288d87cb ]

The hardware only supports periods <= 1.6 ms and if a bigger period is
requested it is clamped to 1.6 ms. In this case duty_cycle might be bigger
than 1.6 ms and then the duty cycle register is written with a value
bigger than LP3943_MAX_DUTY. So clamp duty_cycle accordingly.

Fixes: af66b3c0 ("pwm: Add LP3943 PWM driver")
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: default avatarThierry Reding <thierry.reding@gmail.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 8e9f3f50
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ static int lp3943_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
	if (err)
		return err;

	duty_ns = min(duty_ns, period_ns);
	val = (u8)(duty_ns * LP3943_MAX_DUTY / period_ns);

	return lp3943_write_byte(lp3943, reg_duty, val);