Skip to contentSkip to conversation

hwmon: (it87) Manage device specific features with table

PATCH Jean Delvare 2 participants 4 messages Oct 30, 2012

lore
Share & tools
lore
#0 lore raw

Hi Guenter,

Quoted 36 lines · Guenter Roeck

This simplifies the code, improves runtime performance, reduces code size (about 280 bytes on x86_64), and makes it easier to add support for new devices.

---
v3: s/define^I/define /
Handle new conditional FEAT_TEMP_OFFSET
const char * const name -> const char *name
define "features" flag consistently as u16
v2: Don't introduce new chip type for IT8726F. Doing that would break backward
compatibility.
Since we dropped the has_16bit_fans flag from patch 5/8, changing the code back to use has_16bit_fans() is no longer needed.

 drivers/hwmon/it87.c |  152 ++++++++++++++++++++++++++------------------------
 1 file changed, 80 insertions(+), 72 deletions(-)
drivers/hwmon/it87.c +10 -0
index 2c027ae..96759c3 100644
@@ -228,6 +228,63 @@ static const u8 IT87_REG_TEMP_OFFSET[]	= { 0x56, 0x57, 0x59 };
 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
 #define IT87_REG_AUTO_PWM(nr, i)  (0x65 + (nr) * 8 + (i))
 
+struct it87_devices {
+	const char *name;
+	u16 features;
+};
+
+#define FEAT_12MV_ADC		(1 << 0)
+#define FEAT_NEWER_AUTOPWM	(1 << 1)
+#define FEAT_OLD_AUTOPWM	(1 << 2)
+#define FEAT_16BIT_FANS		(1 << 3)
+#define FEAT_TEMP_OFFSET	(1 << 4)

drivers/hwmon/it87.c static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 }; · line 250

Quoted 10 lines
drivers/hwmon/it87.c +10 -0
+
+static const struct it87_devices it87_devices[] = {
+	[it87] = {
+		.name = "it87",
+		.features = FEAT_OLD_AUTOPWM,	/* may need to override */
+	},
+	[it8712] = {
+		.name = "it8712",
+		.features = FEAT_OLD_AUTOPWM,	/* may need to overwrite */
+	},

You were supposed to harmonize the wording, weren't you?

Quoted 20 lines
drivers/hwmon/it87.c +13 -2
+	[it8716] = {
+		.name = "it8716",
+		.features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
+	},
(...)
@@ -1980,8 +1968,28 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
 	data->addr = res->start;
 	data->type = sio_data->type;
-	data->revision = sio_data->revision;
-	data->name = names[sio_data->type];
+	data->features = it87_devices[sio_data->type].features;
+	data->name = it87_devices[sio_data->type].name;
+	/*
+	 * IT8705F Datasheet 0.4.1, 3h = Version G.
+	 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h = Version J.
+	 * These are the first revisions with 16-bit tachometer support.
+	 */
+	switch (data->type) {
+	case it87:

drivers/hwmon/it87.c static int __devinit it87_probe(struct platform_device *pdev) · line 1989

Quoted 10 lines
drivers/hwmon/it87.c +10 -0
+		if (sio_data->revision >= 0x03) {
+			data->features &= ~FEAT_OLD_AUTOPWM;
+			data->features |= FEAT_16BIT_FANS;
+		}
+		break;
+	case it8712:
+		if (sio_data->revision >= 0x08) {
+			data->features &= ~FEAT_OLD_AUTOPWM;
+			data->features |= FEAT_16BIT_FANS;
+		}

The missing break here is an invitation for future bugs. It was there before... I'm adding it back.

drivers/hwmon/it87.c static int __devinit it87_probe(struct platform_device *pdev) · line 1995

Quoted 6 lines
drivers/hwmon/it87.c +3 -0
+	default:
+		break;
+	}
 
 	/* Now, we do the remaining detection. */
 	if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)

I fixed it all myself, no need to resend.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 43 lines · Jean Delvare

Hi Guenter,

Quoted 40 lines · Guenter Roeck

This simplifies the code, improves runtime performance, reduces code size (about 280 bytes on x86_64), and makes it easier to add support for new devices.

---
v3: s/define^I/define /
Handle new conditional FEAT_TEMP_OFFSET
const char * const name -> const char *name
define "features" flag consistently as u16
v2: Don't introduce new chip type for IT8726F. Doing that would break backward
compatibility.
Since we dropped the has_16bit_fans flag from patch 5/8, changing the code back to use has_16bit_fans() is no longer needed.

 drivers/hwmon/it87.c |  152 ++++++++++++++++++++++++++------------------------
 1 file changed, 80 insertions(+), 72 deletions(-)
drivers/hwmon/it87.c +14 -0
index 2c027ae..96759c3 100644
@@ -228,6 +228,63 @@ static const u8 IT87_REG_TEMP_OFFSET[]	= { 0x56, 0x57, 0x59 };
 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
 #define IT87_REG_AUTO_PWM(nr, i)  (0x65 + (nr) * 8 + (i))
 
+struct it87_devices {
+	const char *name;
+	u16 features;
+};
+
+#define FEAT_12MV_ADC		(1 << 0)
+#define FEAT_NEWER_AUTOPWM	(1 << 1)
+#define FEAT_OLD_AUTOPWM	(1 << 2)
+#define FEAT_16BIT_FANS		(1 << 3)
+#define FEAT_TEMP_OFFSET	(1 << 4)
+
+static const struct it87_devices it87_devices[] = {
+	[it87] = {
+		.name = "it87",
Quoted 9 lines

drivers/hwmon/it87.c static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 }; · line 250

Quoted 6 lines
drivers/hwmon/it87.c +6 -0
+		.features = FEAT_OLD_AUTOPWM,	/* may need to override */
+	},
+	[it8712] = {
+		.name = "it8712",
+		.features = FEAT_OLD_AUTOPWM,	/* may need to overwrite */
+	},

You were supposed to harmonize the wording, weren't you?

Thought I did :(

Quoted 25 lines
Quoted 25 lines
drivers/hwmon/it87.c +18 -2
+	[it8716] = {
+		.name = "it8716",
+		.features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET,
+	},
(...)
@@ -1980,8 +1968,28 @@ static int __devinit it87_probe(struct platform_device *pdev)
 
 	data->addr = res->start;
 	data->type = sio_data->type;
-	data->revision = sio_data->revision;
-	data->name = names[sio_data->type];
+	data->features = it87_devices[sio_data->type].features;
+	data->name = it87_devices[sio_data->type].name;
+	/*
+	 * IT8705F Datasheet 0.4.1, 3h = Version G.
+	 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h = Version J.
+	 * These are the first revisions with 16-bit tachometer support.
+	 */
+	switch (data->type) {
+	case it87:
+		if (sio_data->revision >= 0x03) {
+			data->features &= ~FEAT_OLD_AUTOPWM;
+			data->features |= FEAT_16BIT_FANS;
+		}
+		break;
Quoted 9 lines

drivers/hwmon/it87.c static int __devinit it87_probe(struct platform_device *pdev) · line 1989

Quoted 5 lines
drivers/hwmon/it87.c +5 -0
+	case it8712:
+		if (sio_data->revision >= 0x08) {
+			data->features &= ~FEAT_OLD_AUTOPWM;
+			data->features |= FEAT_16BIT_FANS;
+		}

The missing break here is an invitation for future bugs. It was there before... I'm adding it back.

Accidential.

Quoted 9 lines

drivers/hwmon/it87.c static int __devinit it87_probe(struct platform_device *pdev) · line 1995

Quoted 6 lines
drivers/hwmon/it87.c +3 -0
+	default:
+		break;
+	}
 
 	/* Now, we do the remaining detection. */
 	if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)

I fixed it all myself, no need to resend.

Ok. This will conflict with 4/9, though, for the has_temp_offset() function. Did you fix those as well or should I resend both ?

Thanks,
Guenter

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

#2 lore raw
In reply to Jean Delvare
Quoted 2 lines · Guenter Roeck

Ok. This will conflict with 4/9, though, for the has_temp_offset() function. Did you fix those as well or should I resend both ?

Whatever is easier for you.

Signature · 6 lines
Jean Delvare

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