Skip to content

Commit 5b38279

Browse files
justinledfordgroeck
authored andcommitted
hwmon: (max31790) add fanN_enable
The MAX31790 has a tach input enable bit in each fan's configuration register. This is only enabled by the driver if RPM mode is selected, but the driver doesn't provide a way to independently enable tachometer input regardless of the regulator mode. By adding the fanN_enable sysfs files, we can decouple the tach input from the regulator mode. Also update the documentation. Signed-off-by: Justin Ledford <justinledford@google.com> Link: https://lore.kernel.org/r/20220829195930.2521755-1-justinledford@google.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent b5ae0ad commit 5b38279

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

Documentation/hwmon/max31790.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Sysfs entries
3838
fan[1-12]_input RO fan tachometer speed in RPM
3939
fan[1-12]_fault RO fan experienced fault
4040
fan[1-6]_target RW desired fan speed in RPM
41+
fan[1-6]_enable RW enable or disable the tachometer input
4142
pwm[1-6]_enable RW regulator mode, 0=disabled (duty cycle=0%), 1=manual mode, 2=rpm mode
4243
pwm[1-6] RW read: current pwm duty cycle,
4344
write: target pwm duty cycle (0-255)

drivers/hwmon/max31790.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ static int max31790_read_fan(struct device *dev, u32 attr, int channel,
202202
}
203203
mutex_unlock(&data->update_lock);
204204
return 0;
205+
case hwmon_fan_enable:
206+
*val = !!(data->fan_config[channel] & MAX31790_FAN_CFG_TACH_INPUT_EN);
207+
return 0;
205208
default:
206209
return -EOPNOTSUPP;
207210
}
@@ -214,7 +217,7 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
214217
struct i2c_client *client = data->client;
215218
int target_count;
216219
int err = 0;
217-
u8 bits;
220+
u8 bits, fan_config;
218221
int sr;
219222

220223
mutex_lock(&data->update_lock);
@@ -243,6 +246,23 @@ static int max31790_write_fan(struct device *dev, u32 attr, int channel,
243246
MAX31790_REG_TARGET_COUNT(channel),
244247
data->target_count[channel]);
245248
break;
249+
case hwmon_fan_enable:
250+
fan_config = data->fan_config[channel];
251+
if (val == 0) {
252+
fan_config &= ~MAX31790_FAN_CFG_TACH_INPUT_EN;
253+
} else if (val == 1) {
254+
fan_config |= MAX31790_FAN_CFG_TACH_INPUT_EN;
255+
} else {
256+
err = -EINVAL;
257+
break;
258+
}
259+
if (fan_config != data->fan_config[channel]) {
260+
err = i2c_smbus_write_byte_data(client, MAX31790_REG_FAN_CONFIG(channel),
261+
fan_config);
262+
if (!err)
263+
data->fan_config[channel] = fan_config;
264+
}
265+
break;
246266
default:
247267
err = -EOPNOTSUPP;
248268
break;
@@ -270,6 +290,10 @@ static umode_t max31790_fan_is_visible(const void *_data, u32 attr, int channel)
270290
!(fan_config & MAX31790_FAN_CFG_TACH_INPUT))
271291
return 0644;
272292
return 0;
293+
case hwmon_fan_enable:
294+
if (channel < NR_CHANNEL)
295+
return 0644;
296+
return 0;
273297
default:
274298
return 0;
275299
}
@@ -423,12 +447,12 @@ static umode_t max31790_is_visible(const void *data,
423447

424448
static const struct hwmon_channel_info *max31790_info[] = {
425449
HWMON_CHANNEL_INFO(fan,
426-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
427-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
428-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
429-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
430-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
431-
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT,
450+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
451+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
452+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
453+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
454+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
455+
HWMON_F_INPUT | HWMON_F_TARGET | HWMON_F_FAULT | HWMON_F_ENABLE,
432456
HWMON_F_INPUT | HWMON_F_FAULT,
433457
HWMON_F_INPUT | HWMON_F_FAULT,
434458
HWMON_F_INPUT | HWMON_F_FAULT,

0 commit comments

Comments
 (0)