GL520SM driver
Hello,
I ported the driver for the GL520SM chip to linux 2.6 . It is only tested on my hardware; maybe some others could also test it? For me, it seems to work fine. Also, some changes to the lm_sensors library chips.c were needed for makeing it find its way through the sysfs interface (included in the patch).
Note that i also had to apply another patch (see m7101.patch) to un-hide the Ali M7101 PMU to which the GL520SM is connected. In the lm_sensors package is included a module for linux 2.4 to "hotplug" this device if it is hidden. This patch patches drivers/pci/quirks.c, as it is really a bug in the BIOS. Maybe it should be integrated into the kernel or at least be included in the lm_sensors package? I found it on the linux kernel mailing list. This chip can be configured to read either a second temperature sensor or a fourth voltage sensor. The user can configure this through the two_temps file. If it contains "1" the temp2_* files are valid and if it contains "0" the in4_* files are valid. I think it would make sense to remove the irrelevant files from the directory instead of leaving dummy files, but i think the library needs some changes therefor.
Maarten Deprez
-------------- next part --------------
drivers/i2c/chips/Kconfig renamed from drivers/i2c/chips/Kconfig.orig +11 -0
@@ -95,6 +95,17 @@ This driver can also be built as a module. If so, the module will be called gl518sm. +config SENSORS_GL520SM + tristate "Genesys Logic GL520SM" + depends on I2C && EXPERIMENTAL + select I2C_SENSOR + help + If you say yes here you get support for Genesys Logic GL520SM + sensor chips. + + This driver can also be built as a module. If so, the module + will be called gl520sm. + config SENSORS_IT87 tristate "ITE IT87xx and compatibles" depends on I2C && EXPERIMENTAL
drivers/i2c/chips/Makefile renamed from drivers/i2c/chips/Makefile.orig +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o obj-$(CONFIG_SENSORS_FSCHER) += fscher.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o +obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_LM63) += lm63.o obj-$(CONFIG_SENSORS_LM75) += lm75.o
drivers/i2c/chips/gl520sm.c new file +605 -4
626 lines not on this page · raw message
-------------- next part --------------
pci/quirks.c renamed from pci/quirks.c.old +72 -0
84 lines not on this page · raw message
Hi Maarten,
Quoted 3 lines
It wasn't me, but as that was a while ago and i couldn't find his code, i ported this from 2.4 looking how the gl518sm driver was ported.
Wow, that's odd. I have a very bad memory, maybe I don't remember correctly. Anyway, as long as we end up with a valid driver, alright. We just try to avoid concurrent ports. We already lack resources to port the drivers and review the new code, so let's not do it twice for each driver if possible.
Quoted 5 lines
Yes, i think it is automatically configured right. Still, i find strange that if i set
two_tempsto one, the temp sensor was switching between two values, and if i set it to zero, the voltage sensors switched between at least three values. Is there any clarification for this?
This isn't surprising. Voltage measurement doesn't work as temperature measurement (and there are also different ways to measure the temperature). When you change the configuation bit, I expect the chip to switch to a different circuitery, and this explains why you get a different number of values (one series of which is additionally wrong, obviously).
Thanks,
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Hello Maarten,
Quoted 3 lines
I ported the driver for the GL520SM chip to linux 2.6 . It is only tested on my hardware; maybe some others could also test it? For me, it seems to work fine.
Some times ago I met someone on IRC (#linux-sensors) who told he was working on a port of the gl520sm driver to Linux 2.6. Was it you?
This chip isn't much used, I don't think that any of us has one to test your driver, unfortunately.
Quoted 3 lines
Also, some changes to the
lm_sensorslibrarychips.cwere needed for makeing it find its way through the sysfs interface (included in the patch).
Looks fine to me, will apply this evening.
Quoted 5 lines
Note that i also had to apply another patch (see m7101.patch) to un-hide the Ali M7101 PMU to which the GL520SM is connected. In the
lm_sensorspackage is included a module for linux 2.4 to "hotplug" this device if it is hidden. This patch patchesdrivers/pci/quirks.c, as it is really a bug in the BIOS.
You are right, this is the correct location for such a BIOS workaround. The trick to unhide the P4B and other Asus boards SMBus is already there.
Quoted 2 lines
Maybe it should be integrated into the kernel or at least be included in the
lm_sensorspackage? I found it on the linux kernel mailing list.
You're right, it should be included in the kernel. There is no room for this in the lm_sensors project since this project only covers the 2.4 kernels (let alone user-space tools).
Comments about the m7101 patch:
* It is way too verbose.
* It doesn't respect the kernel coding style.
* I am surprised that you need to include "pci.h". There are a lot of other entried in this file doing the same kind of operations. If they don't need it, I guess there is a reason and possibly your code could do without it.
Please note however that I am not qualified to review the details of this patch, nor to push it upstreams. You will have to find someone else who is (but please address the verbosity and coding style issues before you do).
Quoted 6 lines
This chip can be configured to read either a second temperature sensor or a fourth voltage sensor. The user can configure this through the
two_tempsfile. If it contains "1" the temp2_* files are valid and if it contains "0" the in4_* files are valid. I think it would make sense to remove the irrelevant files from the directory instead of leaving dummy files, but i think the library needs some changes therefor.
I do not think that this is the correct approach. The correct chip configuration depends on the way the chip was wired, and the BIOS should hopefully have configured it properly before the driver is loaded. Is it the case for you? If it is, you can get rid of this "two_temps" file, and simply trust the original chip configuration. As you suggested, you should then not create the files that make no sense in the current configuration.
The libsensors library won't have to be modified, but the sensors program will. It is a straightforward change however (simply discard error messages when an optional file isn't found) and has already been done for several other drivers. Just send us a patch.
My comments on the code itself now:
+#include <linux/config.h>
You don't really need this, do you?
+#define GL520_REG_CHIP_ID 0x00
+#define GL520_REG_REVISION 0x01
+#define GL520_REG_VID 0x02
(...)
Would be way more readable if you would align all values (using tabs!).
+/* Conversions. Rounding and limit checking is only done on the TO_REG
+ variants. Note that you should be a bit careful with which arguments + these macros are called: arguments may be evaluated more than once. + Fixing this is just not worth it. */
That old comment sucks, just kill it.
+#define DIV_TO_REG(val) ((val)=4?2:(val)=2?1:(val)=1?0:3)
Instead of defaulting to an arbitrary value, we now return an error when one tries to set an unsupported value. This means that this macro is replaced by real code in the set_fan_div function. See the fscher driver (in Linux 2.6) for an example.
+static inline u8 FAN_TO_REG(long rpm, int div)
+{
+ if (rpm = 0)
+ return 0;
+ div = DIV_FROM_REG(div);
+ rpm = SENSORS_LIMIT(rpm, 1, 1920000) * div;
+ return SENSORS_LIMIT((960000 + rpm / 2) / rpm, 1, 255);
+}
You should be able to have only one call to SENSORS_LIMIT if you return 0 on rpm <= 0 (instead of only = 0).
+#define VID_FROM_REG(val) ((val)=0x1f?0:(val)>=0x10?5100-(val)*100:2050-(val)*50)
This only works for one VRM version. I know that the GL520SM is old and used one very few systems, but you should still consider using the standard functions in i2c-vid.h and i2c-sensor-vid.c to handle VID in your driver. Take a look at the way other drivers do.
+#define ALARMS_FROM_REG(val) val
Useless macro, get rid of it.
+#define BEEP_MASK_TO_REG(val) (val & data->alarm_mask)
Missing parentheses around val.
+#define BEEP_MASK_FROM_REG(val) (val)
Useless too, get rid of it.
+struct gl520_data {
+ struct i2c_client client;
+ enum chips type;
You never use "type" in the code, which is quite logical since the driver supports a single chip type. Kill it.
+ u8 fan_off; /* Boolean */
What is this?
+/*
+ * Internal variables
+ */
+
+static int gl520_id = 0;
+
This is gone in kernel 2.6.11-rc2.
+#define get_if(name, value, cond) \
+static ssize_t get_##name(struct device *dev, char *buf) \
+{ \
+ struct gl520_data *data = gl520_update_device(dev); \
+ return sprintf(buf, "%d\n", (cond) ? value : 0); \
+}
Useless. You will only create the file if it matches the chip configuration.
Your "set" macros aren't exactly readable. They make the code compact, right, but I am not certain it is worth it. I wouldn't want to have to track a bug down in there.
+ /* Determine the chip type. */
+ if (gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) {
+ dev_info(&adapter->dev,
+ "Ignoring 'force' parameter for unknown " + "chip at adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address);
+ goto exit_free;
+ } else {
+ kind = gl520sm;
+ }
The message isn't correct, as it may be displayed even if the force parameter wasn't used. And actually this code doesn't honor the force parameter. This parameter should allow one to skip the detection of the chip. This should look like:
if (kind < 0) {
if (gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) {
dev_dbg(&new_client->dev, "Unsupported chip id 0x%02x,
skipping\n");
goto exit_free;
}
}Don't bother setting kind = gl520sm, you never use it after that.
Also, this detection is rather weak. Are there no other registers we can use to improve the detection? The sensors-detect script suggests that bit 7 of register 0x03 (configuration) should always be cleared. It also mentions revision register at 0x01 being possibly always equal to 0. Do you confirm this is the case for you?
I would appreciate a dump of your chip for my collection, BTW.
+ new_client->id = gl520_id++;
+ data->type = kind;
Kill these ones.
+/* OK, this is not exactly good programming practice, usually. But it is
+ very code-efficient in this case. */
Kill that old comment too.
+/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
+ GL520 uses a high-byte first convention, which is exactly opposite to
+ the usual practice. */
Please remove the "which is exactly opposite to the usual practice". All chips actually do it that way.
Rest of the code is fine with me. Feel free to remove the other names in MODULE_AUTHOR.
Thanks,
--
Jean Delvare
Jean,
I rewrote the code, patches to linux and lm_sensors2 (cvs) attached. The two_temps file is now implemented as a module parameter (default is autodetect, so: what the BIOS thinks). For the autodetection: the revision register isn't zero for me, so that cannot be used.
The driver reports that my fan1 is at 8000 RPM while BIOS setup monitor utility says 4000 RPM, i don't know which is right (could be useful to know that this fan is cooling a 667MHz pentium 3 cpu)? Maybe fan_div is interpreted wrong by the driver? I don't know what fan1_off is, at least it doesn't turn off my fan.
Dump (in word mode because some registers are words) attached.
Maybe we should also send this to the one who was writing a driver so he can check and test it?
Should i send the linux patches (m7101 unhideing and gl520sm driver) for inclusion in the kernel?
Maarten
-------------- next part --------------
0,8 1,9 2,a 3,b 4,c 5,d 6,e 7,f
00: 0020 0080 0000 0040 00a5 00b4 0000 003d 08: f0f0 a8b3 8aa3 6f79 cadb 005b 00a5 0050 10: 0000 0000 00d8 009e 00b2 00d9 0000 00b4 18: 0000 0000 0000 0000 0000 0000 0000 0000 20: 0000 0000 0000 0000 0000 0000 0000 0000 28: 0000 0000 0000 0000 0000 0000 0000 0000 30: 0000 0000 0000 0000 0000 0000 0000 0000 38: 0000 0000 0000 0000 0000 0000 0000 0000 40: 0000 0000 0000 0000 0000 0000 0000 0000 48: 0000 0000 0000 0000 0000 0000 0000 0000 50: 0000 0000 0000 0000 0000 0000 0000 0000 58: 0000 0000 0000 0000 0000 0000 0000 0000 60: 0000 0000 0000 0000 0000 0000 0000 0000 68: 0000 0000 0000 0000 0000 0000 0000 0000 70: 0000 0000 0000 0000 0000 0000 0000 0000 78: 0000 0000 0000 0000 0000 0000 0000 0000 80: 0000 0000 0000 0000 0000 0000 0000 0000 88: 0000 0000 0000 0000 0000 0000 0000 0000 90: 0000 0000 0000 0000 0000 0000 0000 0000 98: 0000 0000 0000 0000 0000 0000 0000 0000
a0: 0000 0000 0000 0000 0000 0000 0000 0000
a8: 0000 0000 0000 0000 0000 0000 0000 0000
b0: 0000 0000 0000 0000 0000 0000 0000 0000
b8: 0000 0000 0000 0000 0000 0000 0000 0000
c0: 0000 0000 0000 0000 0000 0000 0000 0000
c8: 0000 0000 0000 0000 0000 0000 0000 0000
d0: 0000 0000 0000 0000 0000 0000 0000 0000
d8: 0000 0000 0000 0000 0000 0000 0000 0000
e0: 0000 0000 0000 0000 0000 0000 0000 0000
e8: 0000 0000 0000 0000 0000 0000 0000 0000
f0: 0000 0000 0000 0000 0000 0000 0000 0000
f8: 0000 0000 0000 0000 0000 0000 0000 0000 -------------- next part --------------
drivers/i2c/chips/Kconfig renamed from drivers/i2c/chips/Kconfig.orig +11 -0
@@ -106,6 +106,17 @@ This driver can also be built as a module. If so, the module will be called gl518sm. +config SENSORS_GL520SM + tristate "Genesys Logic GL520SM" + depends on I2C && EXPERIMENTAL + select I2C_SENSOR + help + If you say yes here you get support for Genesys Logic GL520SM + sensor chips. + + This driver can also be built as a module. If so, the module + will be called gl520sm. + config SENSORS_IT87 tristate "ITE IT87xx and compatibles" depends on I2C && EXPERIMENTAL
drivers/i2c/chips/Makefile renamed from drivers/i2c/chips/Makefile.orig +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SENSORS_FSCHER) += fscher.o obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o +obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_LM63) += lm63.o obj-$(CONFIG_SENSORS_LM75) += lm75.o
drivers/i2c/chips/gl520sm.c renamed from drivers/i2c/chips/gl520sm.c.orig +749 -0
749 lines not on this page · raw message
-------------- next part --------------
prog/sensors/chips.c renamed from prog/sensors/chips.c.orig +175 -0
181 lines not on this page · raw message
prog/sensors/chips.h renamed from prog/sensors/chips.h.orig +1 -0
@@ -37,6 +37,7 @@extern void print_sis5595 (const sensors_chip_name *name);extern void print_via686a (const sensors_chip_name *name);extern void print_gl518 (const sensors_chip_name *name); +extern void print_gl520 (const sensors_chip_name *name);extern void print_lm80 (const sensors_chip_name *name);extern void print_lm85 (const sensors_chip_name *name);extern void print_w83781d (const sensors_chip_name *name);
prog/sensors/main.c renamed from prog/sensors/main.c.orig +1 -0
@@ -349,6 +349,7 @@ { "emc6d100", print_lm85 }, { "lm87", print_lm87 }, { "gl518sm", print_gl518 }, + { "gl520sm", print_gl520 }, { "adm1025", print_adm1025 }, { "ne1619", print_adm1025 }, { "adm1024", print_adm1024 },
Hi Maarten,
Quoted 3 lines
I rewrote the code, patches to linux and
lm_sensors2(cvs) attached. Thetwo_tempsfile is now implemented as a module parameter (default is autodetect, so: what the BIOS thinks).
Code looks really great to me, with the minor following comments.
For the kernel driver:
Quoted 1 line
+static unsigned short
extra_sensor_type= 0;
0 is the default value, omit it.
Review
Quoted 2 lines
(quoted diff) +2
-0+#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT +#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT
Why define these (and others) and never use them?
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) + goto exit;
Cut the long line, and kill the extra spaces before the goto.
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (extra_sensor_type) { + if (extra_sensor_type = 1) + conf &= ~0x10; + else if (extra_sensor_type = 2) + conf |= 0x10; + }
The first test looks useless.
Review
Quoted 3 lines
(quoted diff) +3
-0+ if (n < 4) { + gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r); + }
Kill the useless curly braces (twice).
And finally I'd like you to move all sysfs callback functions in a single place, instead of having definitions at the top and implementations at the end.
For the sensors program:
First of all I have to say I am very surprised to see that there were no code for the gl520sm at all so far! This certainly proves that this chip doesn't have many users.
Quoted 1 line
+
printf("ERROR: Can't get TEMP1 or VIN4 data!\n");
That would be TEMP2?
Quoted 2 lines
For the autodetection: the revision register isn't zero for me, so that cannot be used.
Well, what is it for you? We can use that with some mask.
Quoted 3 lines
The driver reports that my fan1 is at 8000 RPM while BIOS setup monitor utility says 4000 RPM, i don't know which is right (could be useful to know that this fan is cooling a 667MHz pentium 3 cpu)?
8000RPM seems very high, I would bet that 4000RPM is correct.
Quoted 1 line
Maybe
fan_divis interpreted wrong by the driver?
Don't misunderstand fan_div. It stands for fan clock divider and doesn't divide the speed value but an internal clock used to measure it. What fan clock dividers change is the range and accuracy of the measure, not its value.
Just took a look at the datasheet and it seems clear that the formula found in the driver doesn't take in account the fact that most fans emit two pulses per revolution. Thus you would need to change the 960000 into 480000, and then the driver should agree with your BIOS.
Quoted 1 line
I don't know what
fan1_offis, at least it doesn't turn off my fan.
Maybe that output isn't wired on your board.
Quoted 1 line
Dump (in word mode because some registers are words) attached.
Care to provide a byte mode dump for ceompleteness?
Quoted 2 lines
Maybe we should also send this to the one who was writing a driver so he can check and test it?
No news for quite some times, unfortunately.
Quoted 2 lines
Should i send the linux patches (m7101 unhideing and gl520sm driver) for inclusion in the kernel?
Sure. For the m7101 unhiding I'm not too sure who to send it to. For the gl520sm driver, send it to Greg KH. You should make sure that it properly applies on top of 2.6.11-rc2-mm2 so that Greg can apply it easily.
Thanks,
--
Jean Delvare