Skip to contentSkip to conversation

PATCH: hwmon-fschmd-use-dmi-tables.patch

lm-sensors Hans de Goede 3 participants 6 messages Dec 17, 2007 – Jan 28, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

Hi All,

This patch adds support to the fschmd driver for reading the voltage scaling factors from BIOS DMI tables, as specified in the Siemens datasheet.

Notice that this patch depends on the patch to the in kernel DMI parser titled:
"dmi: Let drivers walk the DMI table" by Jean Delvare:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-November/021864.html

Regards,

Hans

This patch adds support to the fschmd driver for reading the voltage scaling factors from BIOS DMI tables, as specified in the Siemens datasheet.

Notice that this patch depends on the patch to the in kernel DMI parser titled:
"dmi: Let drivers walk the DMI table" by Jean Delvare:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-November/021864.html

drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +88 -2
diff -up vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c.orig vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c
@@ -41,6 +41,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/dmi.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
@@ -210,6 +211,13 @@ struct fschmd_data {
 	u8 fan_ripple[6];	/* divider for rps */
 };
 
+/* Global variables to hold information read from special DMI tables, which are
+   available on FSC machines with an fscher or later chip. */
+static int dmi_mult[3] = { 49, 20, 10 };
+static int dmi_offset[3] = { 0, 0, 0 };
+static int dmi_vref = -1;
+
+
 /*
  * Sysfs attr show / store functions
  */
@@ -221,8 +229,13 @@ static ssize_t show_in_value(struct devi
 	int index = to_sensor_dev_attr(devattr)->index;
 	struct fschmd_data *data = fschmd_update_device(dev);
 
-	return sprintf(buf, "%d\n", (data->volt[index] *
-		max_reading[index] + 128) / 255);
+	/* fscher / fschrc - 1 as data->kind is an array index, not a chips */
+	if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
+		return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
+			dmi_mult[index] * 10) / 255 + dmi_offset[index] * 10);
+	else
+		return sprintf(buf, "%d\n", (data->volt[index] *
+			max_reading[index] + 128) / 255);
 }
 
 
@@ -524,6 +537,68 @@ static struct sensor_device_attribute fs
 /*
  * Real code
  */
+ 
+/* DMI decode routine to read voltage scaling factors from special DMI tables,
+   which are available on FSC machines with an fscher or later chip. */
+static void fschmd_dmi_decode(const struct dmi_header *header)
+{
+	int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
+
+	/* dmi code ugliness, we get passed the address of the contents of
+	   a complete DMI handle, but in the form of a dmi_header pointer, in
+	   reality this address holds header->length bytes of which the header
+	   are the first 4 bytes */
+	u8 *dmi_data = (u8 *)header;
+
+	/* We are looking for OEM-specific type 185 */
+	if (header->type != 185)
+		return;
+
+	/* we are looking for what Siemens calls "subtype" 19, the subtype
+	   is stored in byte 5 of the dmi block */
+	if (header->length < 5 || dmi_data[4] != 19)
+		return;
+
+	/* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
+	   consisting of what Siemens calls an "Entity" number, followed by
+	   2 16 bit words in LSB first order */
+	for (i = 6; (i + 4) < header->length; i += 5) {
+		/* entity 1 - 3 voltage multiplier and offset */
+		if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
+			/* Our in sensors order and the DMI order differ */
+			const int shuffle[3] = { 1, 0, 2 };
+			int in = shuffle[dmi_data[i] - 1];
+
+			/* Check for twice the same entity */
+			if (found & (1 << in))
+				return;
+
+			mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+			offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
+
+			found |= 1 << in;
+		}
+
+		/* entity 7 reference voltage */
+		if (dmi_data[i] == 7) {
+			/* Check for twice the same entity */
+			if (found & 0x08)
+				return;
+
+			vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+
+			found |= 0x08;
+		}
+	}
+
+	if (found == 0x0F) {
+		for (i = 0; i < 3; i++) {
+			dmi_mult[i] = mult[i];
+			dmi_offset[i] = offset[i];
+		}
+		dmi_vref = vref;
+	}
+}
 
 static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
 {
@@ -585,6 +660,17 @@ static int fschmd_detect(struct i2c_adap
 		data->temp_max[1] = 50 + 128;
 		data->temp_max[2] = 50 + 128;
 	}
+	
+	/* Read the special DMI table for fscher and newer chips */
+	if (kind == fscher || kind >= fschrc) {
+		dmi_walk(fschmd_dmi_decode);
+		if (dmi_vref == -1) {
+			printk(KERN_WARNING FSCHMD_NAME
+				": couldn't get voltage scaling factors from "
+				"BIOS DMI table using builtin defaults\n");
+			dmi_vref = 33;
+		}
+	}
 
 	/* i2c kind goes from 1-5, we want from 0-4 to address arrays */
 	data->kind = kind - 1;

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

#1 lore raw

Hi Hans,

Quoted 8 lines · Hans de Goede

This patch adds support to the fschmd driver for reading the voltage scaling factors from BIOS DMI tables, as specified in the Siemens datasheet.

Notice that this patch depends on the patch to the in kernel DMI parser titled:
"dmi: Let drivers walk the DMI table" by Jean Delvare:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-November/021864.html

Looks good to me, I have mainly cosmetic comments:

Quoted 26 lines

diff -up vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c.orig vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c

drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +8 -0
@@ -41,6 +41,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/dmi.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
@@ -210,6 +211,13 @@ struct fschmd_data {
 	u8 fan_ripple[6];	/* divider for rps */
 };
 
+/* Global variables to hold information read from special DMI tables, which are
+   available on FSC machines with an fscher or later chip. */
+static int dmi_mult[3] = { 49, 20, 10 };
+static int dmi_offset[3] = { 0, 0, 0 };
+static int dmi_vref = -1;
+
+
 /*
  * Sysfs attr show / store functions
  */

drivers/hwmon/fschmd.c static ssize_t show_in_value(struct devi · line 235

Quoted 9 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +4 -2
@@ -221,8 +229,13 @@ static ssize_t show_in_value(struct devi
 	int index = to_sensor_dev_attr(devattr)->index;
 	struct fschmd_data *data = fschmd_update_device(dev);
 
-	return sprintf(buf, "%d\n", (data->volt[index] *
-		max_reading[index] + 128) / 255);
+	/* fscher / fschrc - 1 as data->kind is an array index, not a chips */
+	if (data->kind = (fscher - 1) || data->kind >= (fschrc - 1))
+		return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
+			dmi_mult[index] * 10) / 255 + dmi_offset[index] * 10);

For slightly faster code, you could multiply dmi_vref and the 3 dmi_offset values by 10 at initialization time so that you don't have to do it again on every call.

Quoted 9 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +3 -0
+	else
+		return sprintf(buf, "%d\n", (data->volt[index] *
+			max_reading[index] + 128) / 255);
 }
 
 
@@ -524,6 +537,68 @@ static struct sensor_device_attribute fs
 /*
  * Real code

drivers/hwmon/fschmd.c static struct sensor_device_attribute fs · line 548

Quoted 10 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +9 -0
  */
+ 
+/* DMI decode routine to read voltage scaling factors from special DMI tables,
+   which are available on FSC machines with an fscher or later chip. */
+static void fschmd_dmi_decode(const struct dmi_header *header)
+{
+	int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
+
+	/* dmi code ugliness, we get passed the address of the contents of
+	   a complete DMI handle, but in the form of a dmi_header pointer, in

A complete DMI record or entry. The "handle" is just its reference number.

Quoted 6 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +6 -0
+	   reality this address holds header->length bytes of which the header
+	   are the first 4 bytes */
+	u8 *dmi_data = (u8 *)header;
+
+	/* We are looking for OEM-specific type 185 */
+	if (header->type != 185)

drivers/hwmon/fschmd.c static struct sensor_device_attribute fs · line 564

Quoted 10 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +10 -0
+		return;
+
+	/* we are looking for what Siemens calls "subtype" 19, the subtype
+	   is stored in byte 5 of the dmi block */
+	if (header->length < 5 || dmi_data[4] != 19)
+		return;
+
+	/* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
+	   consisting of what Siemens calls an "Entity" number, followed by
+	   2 16 bit words in LSB first order */

16-bit

drivers/hwmon/fschmd.c static struct sensor_device_attribute fs · line 566

Quoted 2 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +2 -0
+	for (i = 6; (i + 4) < header->length; i += 5) {
+		/* entity 1 - 3 voltage multiplier and offset */

I'd suggest adding ":" after "3"...

Quoted 6 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +6 -0
+		if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
+			/* Our in sensors order and the DMI order differ */
+			const int shuffle[3] = { 1, 0, 2 };
+			int in = shuffle[dmi_data[i] - 1];
+
+			/* Check for twice the same entity */

drivers/hwmon/fschmd.c static struct sensor_device_attribute fs · line 582

Quoted 10 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +10 -0
+			if (found & (1 << in))
+				return;
+
+			mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+			offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
+
+			found |= 1 << in;
+		}
+
+		/* entity 7 reference voltage */

... and after "7" here.

Quoted 23 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +19 -0
+		if (dmi_data[i] = 7) {
+			/* Check for twice the same entity */
+			if (found & 0x08)
+				return;
+
+			vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+
+			found |= 0x08;
+		}
+	}
+
+	if (found = 0x0F) {
+		for (i = 0; i < 3; i++) {
+			dmi_mult[i] = mult[i];
+			dmi_offset[i] = offset[i];
+		}
+		dmi_vref = vref;
+	}
+}
 
 static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
 {

drivers/hwmon/fschmd.c static int fschmd_detect(struct i2c_adap · line 669

Quoted 10 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +7 -0
@@ -585,6 +660,17 @@ static int fschmd_detect(struct i2c_adap
 		data->temp_max[1] = 50 + 128;
 		data->temp_max[2] = 50 + 128;
 	}
+	
+	/* Read the special DMI table for fscher and newer chips */
+	if (kind = fscher || kind >= fschrc) {
+		dmi_walk(fschmd_dmi_decode);
+		if (dmi_vref = -1) {
+			printk(KERN_WARNING FSCHMD_NAME
+				": couldn't get voltage scaling factors from "

Suggesting capital "C" for consistency.

drivers/hwmon/fschmd.c static int fschmd_detect(struct i2c_adap · line 670

Quoted 1 line
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +1 -0
+				"BIOS DMI table using builtin defaults\n");

Missing comma after "table".

drivers/hwmon/fschmd.c static int fschmd_detect(struct i2c_adap · line 676

Quoted 6 lines
drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +3 -0
+			dmi_vref = 33;
+		}
+	}
 
 	/* i2c kind goes from 1-5, we want from 0-4 to address arrays */
 	data->kind = kind - 1;

And two lines with trailing space...

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Hans de Goede
Quoted 6 lines · Jean Delvare

Hi Hans,

Quoted 3 lines · Hans de Goede

This patch adds support to the fschmd driver for reading the voltage scaling factors from BIOS DMI tables, as specified in the Siemens datasheet.

Quoted 8 lines
Quoted 5 lines

Notice that this patch depends on the patch to the in kernel DMI parser titled:
"dmi: Let drivers walk the DMI table" by Jean Delvare:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-November/021864.html

Looks good to me, I have mainly cosmetic comments:

Thanks,

All fixed, new version attached.

Regards,

Hans

This patch adds support to the fschmd driver for reading the voltage scaling factors from BIOS DMI tables, as specified in the Siemens datasheet.

This is the second version featuring several small cleanups as a result of the review by Jean Delvare.

Notice that this patch depends on the patch to the in kernel DMI parser titled:
"dmi: Let drivers walk the DMI table" by Jean Delvare:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-November/021864.html

drivers/hwmon/fschmd.c renamed from drivers/hwmon/fschmd.c.orig +88 -2
diff -up vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c.orig vanilla-2.6.24-rc5-git3/drivers/hwmon/fschmd.c
@@ -41,6 +41,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/dmi.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
@@ -210,6 +211,13 @@ struct fschmd_data {
 	u8 fan_ripple[6];	/* divider for rps */
 };
 
+/* Global variables to hold information read from special DMI tables, which are
+   available on FSC machines with an fscher or later chip. */
+static int dmi_mult[3] = { 490, 200, 100 };
+static int dmi_offset[3] = { 0, 0, 0 };
+static int dmi_vref = -1;
+
+
 /*
  * Sysfs attr show / store functions
  */
@@ -221,8 +229,13 @@ static ssize_t show_in_value(struct devi
 	int index = to_sensor_dev_attr(devattr)->index;
 	struct fschmd_data *data = fschmd_update_device(dev);
 
-	return sprintf(buf, "%d\n", (data->volt[index] *
-		max_reading[index] + 128) / 255);
+	/* fscher / fschrc - 1 as data->kind is an array index, not a chips */
+	if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
+		return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
+			dmi_mult[index]) / 255 + dmi_offset[index]);
+	else
+		return sprintf(buf, "%d\n", (data->volt[index] *
+			max_reading[index] + 128) / 255);
 }
 
 
@@ -525,6 +538,68 @@ static struct sensor_device_attribute fs
  * Real code
  */
 
+/* DMI decode routine to read voltage scaling factors from special DMI tables,
+   which are available on FSC machines with an fscher or later chip. */
+static void fschmd_dmi_decode(const struct dmi_header *header)
+{
+	int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
+
+	/* dmi code ugliness, we get passed the address of the contents of
+	   a complete DMI record, but in the form of a dmi_header pointer, in
+	   reality this address holds header->length bytes of which the header
+	   are the first 4 bytes */
+	u8 *dmi_data = (u8 *)header;
+
+	/* We are looking for OEM-specific type 185 */
+	if (header->type != 185)
+		return;
+
+	/* we are looking for what Siemens calls "subtype" 19, the subtype
+	   is stored in byte 5 of the dmi block */
+	if (header->length < 5 || dmi_data[4] != 19)
+		return;
+
+	/* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
+	   consisting of what Siemens calls an "Entity" number, followed by
+	   2 16-bit words in LSB first order */
+	for (i = 6; (i + 4) < header->length; i += 5) {
+		/* entity 1 - 3: voltage multiplier and offset */
+		if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
+			/* Our in sensors order and the DMI order differ */
+			const int shuffle[3] = { 1, 0, 2 };
+			int in = shuffle[dmi_data[i] - 1];
+
+			/* Check for twice the same entity */
+			if (found & (1 << in))
+				return;
+
+			mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+			offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
+
+			found |= 1 << in;
+		}
+
+		/* entity 7: reference voltage */
+		if (dmi_data[i] == 7) {
+			/* Check for twice the same entity */
+			if (found & 0x08)
+				return;
+
+			vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+
+			found |= 0x08;
+		}
+	}
+
+	if (found == 0x0F) {
+		for (i = 0; i < 3; i++) {
+			dmi_mult[i] = mult[i] * 10;
+			dmi_offset[i] = offset[i] * 10;
+		}
+		dmi_vref = vref;
+	}
+}
+
 static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
 {
 	struct i2c_client *client;
@@ -586,6 +661,17 @@ static int fschmd_detect(struct i2c_adap
 		data->temp_max[2] = 50 + 128;
 	}
 
+	/* Read the special DMI table for fscher and newer chips */
+	if (kind == fscher || kind >= fschrc) {
+		dmi_walk(fschmd_dmi_decode);
+		if (dmi_vref == -1) {
+			printk(KERN_WARNING FSCHMD_NAME
+				": Couldn't get voltage scaling factors from "
+				"BIOS DMI table, using builtin defaults\n");
+			dmi_vref = 33;
+		}
+	}
+
 	/* i2c kind goes from 1-5, we want from 0-4 to address arrays */
 	data->kind = kind - 1;
 	strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE);

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

#4 lore raw
In reply to Hans de Goede

Hi Jean, Hans:

Quoted 9 lines · Jean Delvare

Hi Hans,

Quoted 1 line · Hans de Goede

All fixed, new version attached.

Looks alright.

I've applied both patches (dmi-walk and fschmd) to hwmon-2.6.git/testing, thanks. FYI: the dmi-walk patch took some trivial merge conflict fixes.

Regards,

Signature · 8 lines
Mark M. Hoffman
[email protected]


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#5 lore raw
In reply to Hans de Goede
Quoted 7 lines · Mark M. Hoffman

Hi Jean, Hans:

Quoted 4 lines · Jean Delvare

Hi Hans,

Le 20/12/2007, "Hans de Goede" <[email protected]> a écrit:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

All fixed, new version attached.

Looks alright.

I've applied both patches (dmi-walk and fschmd) to hwmon-2.6.git/testing, thanks. FYI: the dmi-walk patch took some trivial merge conflict fixes.

I had updated the patch already and posted it to LKML [1], but forgot to Cc you, sorry about that.

[1] http://marc.info/?l=linux-kernel&m0129379115786&w=2

Signature · 6 lines
Jean Delvare

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