Skip to contentSkip to conversation

hwmon: max31790: revise the scale to write pwm

PATCH Applied Delphine CC Chiu 2 participants 2 messages Apr 16, 2024 – Apr 28, 2024 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
 drivers/hwmon/max31790.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/hwmon/max31790.c +7 -1
index 3dc95196b229..7aa1aa63bf1b 100644
@@ -49,6 +49,9 @@
 
 #define NR_CHANNEL			6
 
+#define PWM_INPUT_SCALE	255
+#define MAX31790_REG_PWMOUT_SCALE	511
+
 /*
  * Client data (each client gets its own)
  */
@@ -343,10 +346,13 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel,
 			err = -EINVAL;
 			break;
 		}
+
+		val = DIV_ROUND_CLOSEST(val * MAX31790_REG_PWMOUT_SCALE,
+					PWM_INPUT_SCALE);
 		data->valid = false;
 		err = i2c_smbus_write_word_swapped(client,
 						   MAX31790_REG_PWMOUT(channel),
-						   val << 8);
+						   val << 7);
 		break;
 	case hwmon_pwm_enable:
 		fan_config = data->fan_config[channel];
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Delphine CC Chiu

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.

Quoted 8 lines

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.

Applied.

Thanks,
Guenter