Skip to content

Commit 5bc5d99

Browse files
committed
pwm: iqs620a: Use 64-bit division
The PWM framework is going to change the PWM period and duty cycles to be 64-bit unsigned integers. To avoid build errors on platforms that do not natively support 64-bit division, use explicity 64-bit division. Acked-by: Uwe Kleine-König <[email protected]> Acked-by: Lee Jones <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 1689dcd commit 5bc5d99

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/pwm/pwm-iqs620a.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4646
{
4747
struct iqs620_pwm_private *iqs620_pwm;
4848
struct iqs62x_core *iqs62x;
49-
int duty_scale, ret;
49+
u64 duty_scale;
50+
int ret;
5051

5152
if (state->polarity != PWM_POLARITY_NORMAL)
5253
return -ENOTSUPP;
@@ -69,7 +70,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
6970
* For lower duty cycles (e.g. 0), the PWM output is simply disabled to
7071
* allow an external pull-down resistor to hold the GPIO3/LTX pin low.
7172
*/
72-
duty_scale = state->duty_cycle * 256 / IQS620_PWM_PERIOD_NS;
73+
duty_scale = div_u64(state->duty_cycle * 256, IQS620_PWM_PERIOD_NS);
7374

7475
mutex_lock(&iqs620_pwm->lock);
7576

@@ -81,7 +82,7 @@ static int iqs620_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
8182
}
8283

8384
if (duty_scale) {
84-
u8 duty_val = min(duty_scale - 1, 0xFF);
85+
u8 duty_val = min_t(u64, duty_scale - 1, 0xff);
8586

8687
ret = regmap_write(iqs62x->regmap, IQS620_PWM_DUTY_CYCLE,
8788
duty_val);

0 commit comments

Comments
 (0)