Skip to content

Commit becbd16

Browse files
committed
hwmon: (amc6821) Add support for fan1_target and pwm1_enable mode 4
After setting fan1_target and setting pwm1_enable to 4, the fan controller tries to achieve the requested fan speed. Reviewed-by: Quentin Schulz <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 154a0c2 commit becbd16

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

Documentation/hwmon/amc6821.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ fan1_min rw "
4848
fan1_max rw "
4949
fan1_fault ro "
5050
fan1_pulses rw Pulses per revolution can be either 2 or 4.
51+
fan1_target rw Target fan speed, to be used with pwm1_enable
52+
mode 4.
5153

5254
pwm1 rw pwm1
5355
pwm1_enable rw regulator mode, 1=open loop, 2=fan controlled
5456
by remote temperature, 3=fan controlled by
5557
combination of the on-chip temperature and
5658
remote-sensor temperature,
59+
4=fan controlled by target rpm set with
60+
fan1_target attribute.
5761
pwm1_auto_channels_temp ro 1 if pwm_enable==2, 3 if pwm_enable==3
5862
pwm1_auto_point1_pwm ro Hardwired to 0, shared for both
5963
temperature channels.

drivers/hwmon/amc6821.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ enum chips { amc6821 };
6666
#define AMC6821_REG_TACH_LLIMITH 0x11
6767
#define AMC6821_REG_TACH_HLIMITL 0x12
6868
#define AMC6821_REG_TACH_HLIMITH 0x13
69+
#define AMC6821_REG_TACH_SETTINGL 0x1e
70+
#define AMC6821_REG_TACH_SETTINGH 0x1f
6971

7072
#define AMC6821_CONF1_START 0x01
7173
#define AMC6821_CONF1_FAN_INT_EN 0x02
@@ -122,17 +124,18 @@ static const u8 temp_reg[] = {AMC6821_REG_LTEMP_HI,
122124
AMC6821_REG_RTEMP_LIMIT_MAX,
123125
AMC6821_REG_RTEMP_CRIT, };
124126

125-
enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX,
127+
enum {IDX_FAN1_INPUT = 0, IDX_FAN1_MIN, IDX_FAN1_MAX, IDX_FAN1_TARGET,
126128
FAN1_IDX_LEN, };
127129

128130
static const u8 fan_reg_low[] = {AMC6821_REG_TDATA_LOW,
129131
AMC6821_REG_TACH_LLIMITL,
130-
AMC6821_REG_TACH_HLIMITL, };
131-
132+
AMC6821_REG_TACH_HLIMITL,
133+
AMC6821_REG_TACH_SETTINGL, };
132134

133135
static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI,
134136
AMC6821_REG_TACH_LLIMITH,
135-
AMC6821_REG_TACH_HLIMITH, };
137+
AMC6821_REG_TACH_HLIMITH,
138+
AMC6821_REG_TACH_SETTINGH, };
136139

137140
/*
138141
* Client data (each client gets its own)
@@ -250,10 +253,10 @@ static struct amc6821_data *amc6821_update_device(struct device *dev)
250253
break;
251254
case 1: /*
252255
* semi-open loop: software sets rpm, chip controls
253-
* pwm1, currently not implemented
256+
* pwm1
254257
*/
255258
data->pwm1_auto_channels_temp = 0;
256-
data->pwm1_enable = 0;
259+
data->pwm1_enable = 4;
257260
break;
258261
}
259262

@@ -407,6 +410,10 @@ static ssize_t pwm1_enable_store(struct device *dev,
407410
config |= AMC6821_CONF1_FDRC0;
408411
config |= AMC6821_CONF1_FDRC1;
409412
break;
413+
case 4:
414+
config |= AMC6821_CONF1_FDRC0;
415+
config &= ~AMC6821_CONF1_FDRC1;
416+
break;
410417
default:
411418
count = -EINVAL;
412419
goto unlock;
@@ -622,8 +629,8 @@ static ssize_t fan_store(struct device *dev, struct device_attribute *attr,
622629
if (ret)
623630
return ret;
624631

625-
/* The minimum fan speed must not be unlimited (0) */
626-
if (ix == IDX_FAN1_MIN && !val)
632+
/* Minimum and target fan speed must not be unlimited (0) */
633+
if ((ix == IDX_FAN1_MIN || ix == IDX_FAN1_TARGET) && !val)
627634
return -EINVAL;
628635

629636
val = val > 0 ? 6000000 / clamp_val(val, 1, 6000000) : 0;
@@ -713,6 +720,7 @@ static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, temp_alarm, IDX_TEMP2_CRIT);
713720
static SENSOR_DEVICE_ATTR_RO(fan1_input, fan, IDX_FAN1_INPUT);
714721
static SENSOR_DEVICE_ATTR_RW(fan1_min, fan, IDX_FAN1_MIN);
715722
static SENSOR_DEVICE_ATTR_RW(fan1_max, fan, IDX_FAN1_MAX);
723+
static SENSOR_DEVICE_ATTR_RW(fan1_target, fan, IDX_FAN1_TARGET);
716724
static SENSOR_DEVICE_ATTR_RO(fan1_fault, fan1_fault, 0);
717725
static SENSOR_DEVICE_ATTR_RW(fan1_pulses, fan1_pulses, 0);
718726

@@ -756,6 +764,7 @@ static struct attribute *amc6821_attrs[] = {
756764
&sensor_dev_attr_fan1_input.dev_attr.attr,
757765
&sensor_dev_attr_fan1_min.dev_attr.attr,
758766
&sensor_dev_attr_fan1_max.dev_attr.attr,
767+
&sensor_dev_attr_fan1_target.dev_attr.attr,
759768
&sensor_dev_attr_fan1_fault.dev_attr.attr,
760769
&sensor_dev_attr_fan1_pulses.dev_attr.attr,
761770
&sensor_dev_attr_pwm1.dev_attr.attr,

0 commit comments

Comments
 (0)