summaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorUwe Kleine-König <uwe@kleine-koenig.org>2021-03-21 15:24:12 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2021-03-25 11:14:08 -0700
commit8f50743feedd9a4d322322ef1d91426401e98e10 (patch)
treeffdcd3136783ade3f686d8fd65aff39805dfa294 /drivers/input
parent8b488ef295f206885dbe48de09346059df620dfa (diff)
Input: max8997 - simplify open coding of a division using up to 64 divisions
The for loop is just a complicate way to express a division. Replace it by the actual division which is both simpler to understand for a human and more efficient for a CPU to calculate. Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org> Link: https://lore.kernel.org/r/20210316212233.50765-1-uwe@kleine-koenig.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/misc/max8997_haptic.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/drivers/input/misc/max8997_haptic.c b/drivers/input/misc/max8997_haptic.c
index 20ff087b8a44..cd5e99ec1d3c 100644
--- a/drivers/input/misc/max8997_haptic.c
+++ b/drivers/input/misc/max8997_haptic.c
@@ -61,15 +61,10 @@ static int max8997_haptic_set_duty_cycle(struct max8997_haptic *chip)
unsigned int duty = chip->pwm_period * chip->level / 100;
ret = pwm_config(chip->pwm, duty, chip->pwm_period);
} else {
- int i;
u8 duty_index = 0;
- for (i = 0; i <= 64; i++) {
- if (chip->level <= i * 100 / 64) {
- duty_index = i;
- break;
- }
- }
+ duty_index = DIV_ROUND_UP(chip->level * 64, 100);
+
switch (chip->internal_mode_pattern) {
case 0:
max8997_write_reg(chip->client,