Skip to content

Commit 85984cd

Browse files
chnguyen-amperethangqn-ampere
authored andcommitted
hwmon: (max31790): Support config PWM output becomes TACH
Support the "pwm-to-tach" property to config the PWM outputs to serve as tachometer inputs. Signed-off-by: Chanh Nguyen <[email protected]>
1 parent e6df290 commit 85984cd

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Bindings for the Maxim MAX31790 Fan Controller
2+
==========================================================
3+
4+
Reference:
5+
6+
https://datasheets.maximintegrated.com/en/ds/MAX31790.pdf
7+
8+
The MAX31790 controls the speeds of up to six fans
9+
using six independent PWM outputs. The desired fan
10+
speeds (or PWM duty cycles) are written through the I2C
11+
interface.
12+
13+
Required properties:
14+
- compatible : Must be "maxim,max31790"
15+
- reg : I2C slave address
16+
- pwm-to-tach : An array of six integers respond to six pwm channels for
17+
configuring the pwm to tach mode.
18+
19+
When set to 0, the associated PWMOUT produces a PWM waveform
20+
for control of fan speed. When set to 1, PWMOUT becomes a TACH input
21+
22+
Without the "pwm-to-tach" properties, by default "pwm-to-tach" is <0 0 0 0 0 0>
23+
24+
Example: Set PWM channel 5-6 become TACH input mode
25+
26+
fans@20 {
27+
compatible = "maxim,max31790";
28+
reg = <0x20>;
29+
pwm-to-tach = <0 0 0 0 1 1>;
30+
};

drivers/hwmon/max31790.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/jiffies.h>
1414
#include <linux/module.h>
1515
#include <linux/slab.h>
16+
#include <linux/property.h>
1617

1718
/* MAX31790 registers */
1819
#define MAX31790_REG_GLOBAL_CONFIG 0x00
@@ -65,6 +66,7 @@ struct max31790_data {
6566
u16 tach[NR_CHANNEL * 2];
6667
u16 pwm[NR_CHANNEL];
6768
u16 target_count[NR_CHANNEL];
69+
u32 mode[NR_CHANNEL];
6870
};
6971

7072
static struct max31790_data *max31790_update_device(struct device *dev)
@@ -96,7 +98,6 @@ static struct max31790_data *max31790_update_device(struct device *dev)
9698
if (rv < 0)
9799
goto abort;
98100
data->tach[i] = rv;
99-
100101
if (data->fan_config[i]
101102
& MAX31790_FAN_CFG_TACH_INPUT) {
102103
rv = i2c_smbus_read_word_swapped(client,
@@ -490,6 +491,13 @@ static int max31790_init_client(struct i2c_client *client,
490491
MAX31790_REG_FAN_CONFIG(i));
491492
if (rv < 0)
492493
return rv;
494+
495+
if (data->mode[i]) {
496+
rv |= MAX31790_FAN_CFG_TACH_INPUT;
497+
} else {
498+
rv &= ~(MAX31790_FAN_CFG_TACH_INPUT);
499+
}
500+
493501
data->fan_config[i] = rv;
494502

495503
rv = i2c_smbus_read_byte_data(client,
@@ -509,6 +517,7 @@ static int max31790_probe(struct i2c_client *client)
509517
struct max31790_data *data;
510518
struct device *hwmon_dev;
511519
int err;
520+
int i;
512521

513522
if (!i2c_check_functionality(adapter,
514523
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
@@ -521,6 +530,16 @@ static int max31790_probe(struct i2c_client *client)
521530
data->client = client;
522531
mutex_init(&data->update_lock);
523532

533+
if (device_property_present(dev,"pwm-to-tach")) {
534+
err = device_property_read_u32_array(dev,"pwm-to-tach",data->mode,NR_CHANNEL);
535+
if (err < 0)
536+
return err;
537+
} else {
538+
for (i = 0; i < NR_CHANNEL; i++) {
539+
data->mode[i]=0;
540+
}
541+
}
542+
524543
/*
525544
* Initialize the max31790 chip
526545
*/

0 commit comments

Comments
 (0)