Skip to contentSkip to conversation

hwmon: (it87) Add support for 6th fan of IT8620E

PATCH In review Guenter Roeck 2 participants 3 messages Mar 30, 2015 – Apr 1, 2015

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 7/15 hwmon: (it87) Add support for 6th fan of IT8620E

IT8620E supports up to 6 fan tachometers.

---
 drivers/hwmon/it87.c | 51 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 15 deletions(-)
drivers/hwmon/it87.c +36 -15
index ee6d30960fce..24e9369f1b74 100644
@@ -215,11 +215,11 @@ static bool fix_pwm_polarity;
 
 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
 
-static const u8 IT87_REG_FAN[]		= { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
-static const u8 IT87_REG_FAN_MIN[]	= { 0x10, 0x11, 0x12, 0x84, 0x86 };
-static const u8 IT87_REG_FANX[]		= { 0x18, 0x19, 0x1a, 0x81, 0x83 };
-static const u8 IT87_REG_FANX_MIN[]	= { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
-static const u8 IT87_REG_TEMP_OFFSET[]	= { 0x56, 0x57, 0x59 };
+static const u8 IT87_REG_FAN[]		= {0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c};
+static const u8 IT87_REG_FAN_MIN[]	= {0x10, 0x11, 0x12, 0x84, 0x86, 0x4e};
+static const u8 IT87_REG_FANX[]		= {0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d};
+static const u8 IT87_REG_FANX_MIN[]	= {0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f};
+static const u8 IT87_REG_TEMP_OFFSET[]	= {0x56, 0x57, 0x59};
 
 #define IT87_REG_FAN_MAIN_CTRL 0x13
 #define IT87_REG_FAN_CTL       0x14
@@ -263,6 +263,7 @@ struct it87_devices {
 #define FEAT_FIVE_FANS		(1 << 8)	/* Supports five fans */
 #define FEAT_VID		(1 << 9)	/* Set if chip supports VID */
 #define FEAT_IN7_INTERNAL	(1 << 10)	/* Set if in7 is internal */
+#define FEAT_SIX_FANS		(1 << 11)	/* Supports six fans */
 
 static const struct it87_devices it87_devices[] = {
 	[it87] = {
@@ -380,7 +381,7 @@ static const struct it87_devices it87_devices[] = {
 	[it8620] = {
 		.name = "it8620",
 		.features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
-		  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
+		  | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_SIX_FANS
 		  | FEAT_IN7_INTERNAL,
 		.peci_mask = 0x07,
 		.suffix = "E",
@@ -398,9 +399,11 @@ static const struct it87_devices it87_devices[] = {
 				(((data)->features & FEAT_TEMP_OLD_PECI) && \
 				 ((data)->old_peci_mask & (1 << nr)))
 #define has_fan16_config(data)	((data)->features & FEAT_FAN16_CONFIG)
-#define has_five_fans(data)	((data)->features & FEAT_FIVE_FANS)
+#define has_five_fans(data)	((data)->features & (FEAT_FIVE_FANS | \
+						     FEAT_SIX_FANS))
 #define has_vid(data)		((data)->features & FEAT_VID)
 #define has_in7_internal(data)	((data)->features & FEAT_IN7_INTERNAL)
+#define has_six_fans(data)	((data)->features & FEAT_SIX_FANS)
 
 struct it87_sio_data {
 	enum chips type;
@@ -437,7 +440,7 @@ struct it87_data {
 	u16 in_scaled;		/* Internal voltage sensors are scaled */
 	u8 in[10][3];		/* [nr][0]=in, [1]=min, [2]=max */
 	u8 has_fan;		/* Bitfield, fans enabled */
-	u16 fan[5][2];		/* Register values, [nr][0]ún, [1]=min */
+	u16 fan[6][2];		/* Register values, [nr][0]ún, [1]=min */
 	u8 has_temp;		/* Bitfield, temp sensors enabled */
 	s8 temp[3][4];		/* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
 	u8 sensor;		/* Register value (IT87_REG_TEMP_ENABLE) */
@@ -1276,6 +1279,10 @@ static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
 static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
 			    4, 1);
 
+static SENSOR_DEVICE_ATTR_2(fan6_input, S_IRUGO, show_fan, NULL, 5, 0);
+static SENSOR_DEVICE_ATTR_2(fan6_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
+			    5, 1);
+
 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
 			  show_pwm_enable, set_pwm_enable, 0);
 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
@@ -1406,6 +1413,7 @@ static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
 static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
 static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
 static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7);
 static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
 static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
 static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
@@ -1456,6 +1464,7 @@ static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
 static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
 static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
 static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
+static SENSOR_DEVICE_ATTR(fan6_beep, S_IRUGO, show_beep, set_beep, 0);
 static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
 			  show_beep, set_beep, 2);
 static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
@@ -1659,7 +1668,7 @@ static struct attribute *it87_attributes_temp_beep[] = {
 	&sensor_dev_attr_temp3_beep.dev_attr.attr,
 };
 
-static struct attribute *it87_attributes_fan[5][3+1] = { {
+static struct attribute *it87_attributes_fan[6][3+1] = { {
 	&sensor_dev_attr_fan1_input.dev_attr.attr,
 	&sensor_dev_attr_fan1_min.dev_attr.attr,
 	&sensor_dev_attr_fan1_alarm.dev_attr.attr,
@@ -1684,14 +1693,20 @@ static struct attribute *it87_attributes_fan[5][3+1] = { {
 	&sensor_dev_attr_fan5_min.dev_attr.attr,
 	&sensor_dev_attr_fan5_alarm.dev_attr.attr,
 	NULL
+}, {
+	&sensor_dev_attr_fan6_input.dev_attr.attr,
+	&sensor_dev_attr_fan6_min.dev_attr.attr,
+	&sensor_dev_attr_fan6_alarm.dev_attr.attr,
+	NULL
 } };
 
-static const struct attribute_group it87_group_fan[5] = {
+static const struct attribute_group it87_group_fan[6] = {
 	{ .attrs = it87_attributes_fan[0] },
 	{ .attrs = it87_attributes_fan[1] },
 	{ .attrs = it87_attributes_fan[2] },
 	{ .attrs = it87_attributes_fan[3] },
 	{ .attrs = it87_attributes_fan[4] },
+	{ .attrs = it87_attributes_fan[5] },
 };
 
 static const struct attribute *it87_attributes_fan_div[] = {
@@ -1773,6 +1788,7 @@ static struct attribute *it87_attributes_fan_beep[] = {
 	&sensor_dev_attr_fan3_beep.dev_attr.attr,
 	&sensor_dev_attr_fan4_beep.dev_attr.attr,
 	&sensor_dev_attr_fan5_beep.dev_attr.attr,
+	&sensor_dev_attr_fan6_beep.dev_attr.attr,
 };
 
 static struct attribute *it87_attributes_vid[] = {
@@ -2154,7 +2170,7 @@ static void it87_remove_files(struct device *dev)
 			sysfs_remove_file(&dev->kobj,
 					  it87_attributes_temp_beep[i]);
 	}
-	for (i = 0; i < 5; i++) {
+	for (i = 0; i < 6; i++) {
 		if (!(data->has_fan & (1 << i)))
 			continue;
 		sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
@@ -2311,7 +2327,7 @@ static int it87_probe(struct platform_device *pdev)
 
 	/* Do not create fan files for disabled fans */
 	fan_beep_need_rw = 1;
-	for (i = 0; i < 5; i++) {
+	for (i = 0; i < 6; i++) {
 		if (!(data->has_fan & (1 << i)))
 			continue;
 		err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
@@ -2556,9 +2572,10 @@ static void it87_init_device(struct platform_device *pdev)
 	}
 	data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
 
+	tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
+
 	/* Set tachometers to 16-bit mode if needed */
 	if (has_fan16_config(data)) {
-		tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
 		if (~tmp & 0x07 & data->has_fan) {
 			dev_dbg(&pdev->dev,
 				"Setting fan1-3 to 16-bit mode\n");
@@ -2569,13 +2586,17 @@ static void it87_init_device(struct platform_device *pdev)
 
 	/* Check for additional fans */
 	if (has_five_fans(data)) {
-		tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
 		if (tmp & (1 << 4))
 			data->has_fan |= (1 << 3); /* fan4 enabled */
 		if (tmp & (1 << 5))
 			data->has_fan |= (1 << 4); /* fan5 enabled */
 	}
 
+	if (has_six_fans(data)) {
+		if (tmp & (1 << 2))
+			data->has_fan |= (1 << 5); /* fan6 enabled */
+	}
+
 	/* Fan input pins may be used for alternative functions */
 	data->has_fan &= ~sio_data->skip_fan;
 
@@ -2641,7 +2662,7 @@ static struct it87_data *it87_update_device(struct device *dev)
 		if (data->type = it8603)
 			data->in[9][0] = it87_read_value(data, 0x2f);
 
-		for (i = 0; i < 5; i++) {
+		for (i = 0; i < 6; i++) {
 			/* Skip disabled fans */
 			if (!(data->has_fan & (1 << i)))
 				continue;
Signature · 7 lines
2.1.0


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Reviewed-by on v1 7/15
#1 lore raw

Hi Guenter,

Quoted 12 lines · Guenter Roeck

IT8620E supports up to 6 fan tachometers.

---
 drivers/hwmon/it87.c | 51 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 36 insertions(+), 15 deletions(-)
drivers/hwmon/it87.c +0 -0
index ee6d30960fce..24e9369f1b74 100644

drivers/hwmon/it87.c static bool fix_pwm_polarity; · line 216

Quoted 2 lines
drivers/hwmon/it87.c +0 -0
@@ -215,11 +215,11 @@ static bool fix_pwm_polarity;
 
 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */

The comment above it out of date, BTW.

drivers/hwmon/it87.c static bool fix_pwm_polarity; · line 222

Quoted 11 lines
drivers/hwmon/it87.c +5 -5
-static const u8 IT87_REG_FAN[]		= { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
-static const u8 IT87_REG_FAN_MIN[]	= { 0x10, 0x11, 0x12, 0x84, 0x86 };
-static const u8 IT87_REG_FANX[]		= { 0x18, 0x19, 0x1a, 0x81, 0x83 };
-static const u8 IT87_REG_FANX_MIN[]	= { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
-static const u8 IT87_REG_TEMP_OFFSET[]	= { 0x56, 0x57, 0x59 };
+static const u8 IT87_REG_FAN[]		= {0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c};
+static const u8 IT87_REG_FAN_MIN[]	= {0x10, 0x11, 0x12, 0x84, 0x86, 0x4e};
+static const u8 IT87_REG_FANX[]		= {0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d};
+static const u8 IT87_REG_FANX_MIN[]	= {0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f};
+static const u8 IT87_REG_TEMP_OFFSET[]	= {0x56, 0x57, 0x59};

I see why you removed the spaces inside the curly braces, but that's inconsistent with enum chips and the style used in the vast majority of other hwmon drivers. I would rather align with spaces instead of tabs so that you can move everything by a few columns to the left and everything fits again. (Until the next chip that will support 7 fans, that is ^^.)

(That's typically the kind of comment you're free to ignore if you prefer the way you did.)

Quoted 10 lines
drivers/hwmon/it87.c +0 -1
 #define IT87_REG_FAN_MAIN_CTRL 0x13
 #define IT87_REG_FAN_CTL       0x14
(...)
@@ -2569,13 +2586,17 @@ static void it87_init_device(struct platform_device *pdev)
 
 	/* Check for additional fans */
 	if (has_five_fans(data)) {
-		tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
 		if (tmp & (1 << 4))

drivers/hwmon/it87.c static void it87_init_device(struct platform_device *pdev) · line 2599

Quoted 10 lines
drivers/hwmon/it87.c +5 -0
 			data->has_fan |= (1 << 3); /* fan4 enabled */
 		if (tmp & (1 << 5))
 			data->has_fan |= (1 << 4); /* fan5 enabled */
 	}
 
+	if (has_six_fans(data)) {
+		if (tmp & (1 << 2))
+			data->has_fan |= (1 << 5); /* fan6 enabled */
+	}
+

May I suggest the following optimization?

	/* Check for additional fans */
	if (has_five_fans(data)) {
		if (tmp & (1 << 4))
			data->has_fan |= (1 << 3); /* fan4 enabled */
		if (tmp & (1 << 5))
			data->has_fan |= (1 << 4); /* fan5 enabled */
		if (has_six_fans(data) && (tmp & (1 << 2)))
			data->has_fan |= (1 << 5); /* fan6 enabled */
	}

This fits in fewer lines and saves a test for 3-fan chips.

Looks good otherwise:

Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#2 lore raw
In reply to Guenter Roeck

Hi Jean,

Quoted 16 lines · Jean Delvare

Hi Guenter,

Quoted 13 lines · Guenter Roeck

IT8620E supports up to 6 fan tachometers.

---
  drivers/hwmon/it87.c | 51 ++++++++++++++++++++++++++++++++++++---------------
  1 file changed, 36 insertions(+), 15 deletions(-)
drivers/hwmon/it87.c +0 -0
index ee6d30960fce..24e9369f1b74 100644
@@ -215,11 +215,11 @@ static bool fix_pwm_polarity;
 
Quoted 4 lines

drivers/hwmon/it87.c static bool fix_pwm_polarity; · line 216

Quoted 1 line
drivers/hwmon/it87.c +0 -0
  /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */

The comment above it out of date, BTW.

Yes, I noticed earlier today. I'll address that later, when I add VIN7..9 and TEMP4..6.

Quoted 19 lines

drivers/hwmon/it87.c static bool fix_pwm_polarity; · line 222

Quoted 11 lines
drivers/hwmon/it87.c +5 -5
-static const u8 IT87_REG_FAN[]		= { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
-static const u8 IT87_REG_FAN_MIN[]	= { 0x10, 0x11, 0x12, 0x84, 0x86 };
-static const u8 IT87_REG_FANX[]		= { 0x18, 0x19, 0x1a, 0x81, 0x83 };
-static const u8 IT87_REG_FANX_MIN[]	= { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
-static const u8 IT87_REG_TEMP_OFFSET[]	= { 0x56, 0x57, 0x59 };
+static const u8 IT87_REG_FAN[]		= {0x0d, 0x0e, 0x0f, 0x80, 0x82, 0x4c};
+static const u8 IT87_REG_FAN_MIN[]	= {0x10, 0x11, 0x12, 0x84, 0x86, 0x4e};
+static const u8 IT87_REG_FANX[]		= {0x18, 0x19, 0x1a, 0x81, 0x83, 0x4d};
+static const u8 IT87_REG_FANX_MIN[]	= {0x1b, 0x1c, 0x1d, 0x85, 0x87, 0x4f};
+static const u8 IT87_REG_TEMP_OFFSET[]	= {0x56, 0x57, 0x59};

I see why you removed the spaces inside the curly braces, but that's inconsistent with enum chips and the style used in the vast majority of other hwmon drivers. I would rather align with spaces instead of tabs so that you can move everything by a few columns to the left and everything fits again. (Until the next chip that will support 7 fans, that is ^^.)

Quoted 3 lines

(That's typically the kind of comment you're free to ignore if you prefer the way you did.)

You are right, that is better. Done.

Quoted 33 lines
Quoted 10 lines
drivers/hwmon/it87.c +0 -1
  #define IT87_REG_FAN_MAIN_CTRL 0x13
  #define IT87_REG_FAN_CTL       0x14
(...)
@@ -2569,13 +2586,17 @@ static void it87_init_device(struct platform_device *pdev)
 
  	/* Check for additional fans */
  	if (has_five_fans(data)) {
-		tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
  		if (tmp & (1 << 4))

drivers/hwmon/it87.c static void it87_init_device(struct platform_device *pdev) · line 2599

Quoted 10 lines
drivers/hwmon/it87.c +5 -0
  			data->has_fan |= (1 << 3); /* fan4 enabled */
  		if (tmp & (1 << 5))
  			data->has_fan |= (1 << 4); /* fan5 enabled */
  	}
 
+	if (has_six_fans(data)) {
+		if (tmp & (1 << 2))
+			data->has_fan |= (1 << 5); /* fan6 enabled */
+	}
+

May I suggest the following optimization?

	/* Check for additional fans */
	if (has_five_fans(data)) {
		if (tmp & (1 << 4))
			data->has_fan |= (1 << 3); /* fan4 enabled */
		if (tmp & (1 << 5))
			data->has_fan |= (1 << 4); /* fan5 enabled */
		if (has_six_fans(data) && (tmp & (1 << 2)))
			data->has_fan |= (1 << 5); /* fan6 enabled */
	}
Quoted 2 lines

This fits in fewer lines and saves a test for 3-fan chips.

Excellent idea. Done.

Quoted 4 lines

Looks good otherwise:

Thanks a lot!

Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors