Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (max31790) revise the scale to write pwm

Since the value for PWMOUT Target Duty Cycle register is a 9 bit
left-justified value that ranges from 0 to 511 and is contained in 2
bytes.

There is an issue that the PWM signal recorded by oscilloscope would
not be on consistently if we set PWM to 100% to the driver.

It is because the LSB of the 9 bit would always be zero if it just
left shift 8 bit for the value that write to PWMOUT Target Duty
Cycle register.

Therefore, revise the scale of the value that was written to pwm input
from 255 to 511 and modify the value to left-justified value.

Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Link: https://lore.kernel.org/r/20240416022211.859483-1-Delphine_CC_Chiu@wiwynn.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Delphine CC Chiu and committed by
Guenter Roeck
801fec8d 8ec8d6c5

+7 -1
+7 -1
drivers/hwmon/max31790.c
··· 49 49 50 50 #define NR_CHANNEL 6 51 51 52 + #define PWM_INPUT_SCALE 255 53 + #define MAX31790_REG_PWMOUT_SCALE 511 54 + 52 55 /* 53 56 * Client data (each client gets its own) 54 57 */ ··· 346 343 err = -EINVAL; 347 344 break; 348 345 } 346 + 347 + val = DIV_ROUND_CLOSEST(val * MAX31790_REG_PWMOUT_SCALE, 348 + PWM_INPUT_SCALE); 349 349 data->valid = false; 350 350 err = i2c_smbus_write_word_swapped(client, 351 351 MAX31790_REG_PWMOUT(channel), 352 - val << 8); 352 + val << 7); 353 353 break; 354 354 case hwmon_pwm_enable: 355 355 fan_config = data->fan_config[channel];