Skip to content

Commit

Permalink
hwmon: (max31790): Add new FAN mode control
Browse files Browse the repository at this point in the history
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 <chanh@os.amperecomputing.com>
  • Loading branch information
chnguyen-ampere authored and thangqn-ampere committed Dec 12, 2022
1 parent 7733487 commit b0ec988
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion drivers/hwmon/max31790.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ static int max31790_read_pwm(struct device *dev, u32 attr, int channel,
*val = 0;
else if (fan_config & MAX31790_FAN_CFG_RPM_MODE)
*val = 2;
else if (fan_config & MAX31790_FAN_CFG_TACH_INPUT_EN)
*val = 3;
else
*val = 1;
return 0;
Expand Down Expand Up @@ -345,6 +347,9 @@ static int max31790_write_pwm(struct device *dev, u32 attr, int channel,
* value in the cache.
*/
fan_config |= (MAX31790_FAN_CFG_RPM_MODE | MAX31790_FAN_CFG_TACH_INPUT_EN);
} else if (val == 3) {
fan_config &= ~(MAX31790_FAN_CFG_CTRL_MON | MAX31790_FAN_CFG_RPM_MODE);
fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN;
} else {
err = -EINVAL;
break;
Expand Down Expand Up @@ -460,20 +465,34 @@ static const struct hwmon_chip_info max31790_chip_info = {
static int max31790_init_client(struct i2c_client *client,
struct max31790_data *data)
{
int i, rv;
int i, rv, pre_config;

for (i = 0; i < NR_CHANNEL; i++) {
rv = i2c_smbus_read_byte_data(client,
MAX31790_REG_FAN_CONFIG(i));
if (rv < 0)
return rv;

/*
* Initialize mode 3 (Monitor speed and control PWM) by default
*/
pre_config = rv;

rv &= ~(MAX31790_FAN_CFG_CTRL_MON | MAX31790_FAN_CFG_RPM_MODE);
rv |= MAX31790_FAN_CFG_TACH_INPUT_EN;

if (data->mode[i]) {
rv |= MAX31790_FAN_CFG_TACH_INPUT;
} else {
rv &= ~(MAX31790_FAN_CFG_TACH_INPUT);
}

if (rv != pre_config) {
if (i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(i),
rv))
return rv;
}

data->fan_config[i] = rv;

rv = i2c_smbus_read_byte_data(client,
Expand Down

0 comments on commit b0ec988

Please sign in to comment.