Skip to content

Commit e5335b5

Browse files
chnguyen-amperethangqn-ampere
authored andcommitted
hwmon: (max31790): Add new FAN mode control
Add the new mode (called as mode#3) to monitor speed and control the PWM. Initialize mode #3 by default (fan tach input enable and PWM mode enable). We can reconfigure again by the pwm_enale setting. Signed-off-by: Chanh Nguyen <[email protected]>
1 parent 8d80760 commit e5335b5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/hwmon/max31790.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
320320
*val = 0;
321321
else if (fan_config & MAX31790_FAN_CFG_RPM_MODE)
322322
*val = 2;
323+
else if (fan_config & MAX31790_FAN_CFG_TACH_INPUT_EN)
324+
*val = 3;
323325
else
324326
*val = 1;
325327
return 0;
@@ -369,6 +371,9 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel,
369371
* value in the cache.
370372
*/
371373
fan_config |= (MAX31790_FAN_CFG_RPM_MODE | MAX31790_FAN_CFG_TACH_INPUT_EN);
374+
} else if (val == 3) {
375+
fan_config &= ~(MAX31790_FAN_CFG_CTRL_MON | MAX31790_FAN_CFG_RPM_MODE);
376+
fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN;
372377
} else {
373378
err = -EINVAL;
374379
break;
@@ -484,20 +489,34 @@ static const struct hwmon_chip_info max31790_chip_info = {
484489
static int max31790_init_client(struct i2c_client *client,
485490
struct max31790_data *data)
486491
{
487-
int i, rv;
492+
int i, rv, pre_config;
488493

489494
for (i = 0; i < NR_CHANNEL; i++) {
490495
rv = i2c_smbus_read_byte_data(client,
491496
MAX31790_REG_FAN_CONFIG(i));
492497
if (rv < 0)
493498
return rv;
494499

500+
/*
501+
* Initialize mode 3 (Monitor speed and control PWM) by default
502+
*/
503+
pre_config = rv;
504+
505+
rv &= ~(MAX31790_FAN_CFG_CTRL_MON | MAX31790_FAN_CFG_RPM_MODE);
506+
rv |= MAX31790_FAN_CFG_TACH_INPUT_EN;
507+
495508
if (data->mode[i]) {
496509
rv |= MAX31790_FAN_CFG_TACH_INPUT;
497510
} else {
498511
rv &= ~(MAX31790_FAN_CFG_TACH_INPUT);
499512
}
500513

514+
if (rv != pre_config) {
515+
if (i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(i),
516+
rv))
517+
return rv;
518+
}
519+
501520
data->fan_config[i] = rv;
502521

503522
rv = i2c_smbus_read_byte_data(client,

0 commit comments

Comments
 (0)