GMT G760A fan speed PWM controller
Subsystems (2)
Herbert Valerio Riedel originally submitted a driver for the GMT G760A fan speed PWM controller in December 2007:
http://lists.lm-sensors.org/pipermail/lm-sensors/2007-December/022161.html
Jean Delvare kindly reviewed the driver and provided some comments:
http://lists.lm-sensors.org/pipermail/lm-sensors/2008-January/022291.html
Unfortunately, Herbert became busy and never got the time to finish the driver.
Matt Palmer later made some modifications to Herbert's patch and came up with the attached patch, but he also doesn't have the time to push for mainline inclusion.
The GMT G760A is used on the D-Link DNS-323, which is a pretty popular NAS device: http://wiki.dns323.info/ Even though there is a reasonable community around Linux on the DNS-323, it seems that there's nobody with the time and knowledge to finish this driver for mainline inclusion.
I'd therefore like to ask the lm-sensors community for help to get this driver into the mainline. I'd be happy to test the driver on my DNS-323.
The current version of the patch (from Matt Palmer) is attached below. Note that it doesn't seem to work for me - the g760a module doesn't get loaded, even though the DNS-323 board code loads it. (The lm75 module, which is also loaded from the DNS-323 board code, is properly loaded, though, so I suspect it's a problem with the g760a patch.)
Signature · 2 lines
Martin Michlmayr http://www.cyrius.com/
From: Herbert Valerio Riedel <hvr at gnu.org>
Subject: hwmon: add support for GMT G760A fan speed PWM controller
This controller can be found on the D-Link DNS-323 for instance, where it is to be configured via static i2c_board_info in the board-specific mach-orion/dns323-setup.c; this driver supports only the new-style driver model.
Documentation/hwmon/g760a +37 -0
@@ -0,0 +1,37 @@ +Kernel driver g760a +=================== + +Supported chips: + * Global Mixed-mode Technology Inc. G760A + Prefix: 'g760a' + Datasheet: Publicly available at the GMT website + http://www.gmt.com.tw/datasheet/g760a.pdf + +Author: Herbert Valerio Riedel <hvr at gnu.org> + +Description +----------- + +The GMT G760A Fan Speed PWM Controller is connected directly to a fan +and performs closed-loop control of the fan speed. + +The fan speed is programmed by setting the period via 'pwm1' of two +consecutive speed pulses. The period is defined in terms of clock +cycle counts of an assumed 32kHz clock source. + +Setting a period of 0 stops the fan; setting the period to 255 sets +fan to maximum speed. + +The measured fan rotation speed returned via 'fan1_input' is derived +from the measured speed pulse period by assuming again a 32kHz clock +source and a 2 pulse-per-revolution fan. + +The 'alarms' file provides access to the two alarm bits provided by +the G760A chip's status register: Bit 0 is set when the actual fan +speed differs more than 20% with respect to the programmed fan speed; +bit 1 is set when fan speed is below 1920 rpm. + +The g760a driver will not update its values more frequently than every +other second; reading them more often will do no harm, but will return +'old' values. +
drivers/hwmon/g760a.c +271 -0
271 lines not on this page · raw message
drivers/hwmon/Kconfig +10 -0
@@ -301,6 +301,16 @@ This driver can also be built as a module. If so, the module will be called fschmd. +config SENSORS_G760A + tristate "GMT G760A" + depends on I2C + help + If you say yes here you get support for Global Mixed-mode + Technology Inc G760A fan speed pwm controller chips. + + This driver can also be built as a module. If so, the module + will be called g760a. + config SENSORS_GL518SM tristate "Genesys Logic GL518SM" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_SENSORS_FSCHER) += fscher.o obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o +obj-$(CONFIG_SENSORS_G760A) += g760a.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Martin Michlmayr
Tested-byQuoted 2 lines · Martin Michlmayr
Note that it doesn't seem to work for me - the g760a module doesn't get loaded, even though the DNS-323 board code loads it.
Laurie Bradshaw pointed out in private that I didn't have the latest version of the patch. He has a version that correctly loads. I just tested this patch and it works for me.
It seems to me that the new version of the patch is very close to being ready. Jean, do you think you could review it?
Thanks.
Signature · 2 lines
Martin Michlmayr http://www.cyrius.com/
From: Herbert Valerio Riedel <[email protected]>
Subject: hwmon: add support for GMT G760A fan speed PWM controller
This controller can be found on the D-Link DNS-323 for instance, where it is to be configured via static i2c_board_info in the board-specific mach-orion/dns323-setup.c; this driver supports only the new-style driver model.
Documentation/hwmon/g760a new file +36 -0
@@ -0,0 +1,36 @@ +Kernel driver g760a +=================== + +Supported chips: + * Global Mixed-mode Technology Inc. G760A + Prefix: 'g760a' + Datasheet: Publicly available at the GMT website + http://www.gmt.com.tw/datasheet/g760a.pdf + +Author: Herbert Valerio Riedel <[email protected]> + +Description +----------- + +The GMT G760A Fan Speed PWM Controller is connected directly to a fan +and performs closed-loop control of the fan speed. + +The fan speed is programmed by setting the period via 'pwm1' of two +consecutive speed pulses. The period is defined in terms of clock +cycle counts of an assumed 32kHz clock source. + +Setting a period of 0 stops the fan; setting the period to 255 sets +fan to maximum speed. + +The measured fan rotation speed returned via 'fan1_input' is derived +from the measured speed pulse period by assuming again a 32kHz clock +source and a 2 pulse-per-revolution fan. + +The 'alarms' file provides access to the two alarm bits provided by +the G760A chip's status register: Bit 0 is set when the actual fan +speed differs more than 20% with respect to the programmed fan speed; +bit 1 is set when fan speed is below 1920 rpm. + +The g760a driver will not update its values more frequently than every +other second; reading them more often will do no harm, but will return +'old' values.
drivers/hwmon/g760a.c new file +268 -0
268 lines not on this page · raw message
drivers/hwmon/Kconfig +10 -0
@@ -357,6 +357,16 @@ config SENSORS_FSCHMD This driver can also be built as a module. If so, the module will be called fschmd. +config SENSORS_G760A + tristate "GMT G760A" + depends on I2C + help + If you say yes here you get support for Global Mixed-mode + Technology Inc G760A fan speed PWM controller chips. + + This driver can also be built as a module. If so, the module + will be called g760a. + config SENSORS_GL518SM tristate "Genesys Logic GL518SM" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_SENSORS_F75375S) += f75375s.o obj-$(CONFIG_SENSORS_FSCHER) += fscher.o obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o +obj-$(CONFIG_SENSORS_G760A) += g760a.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 2 lines · Martin Michlmayr
It seems to me that the new version of the patch is very close to being ready. Jean, do you think you could review it?
I just wanted to add that there are at least two volunteers now who are interested in fixing the driver for mainline inclusion in case there are some issues left, so a review would be apprecited.
Thanks,
Signature · 7 lines
Martin Michlmayr http://www.cyrius.com/ _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 12 lines · On Tue, 10 Mar 2009 19:05:53 +0100 Martin Michlmayr <[email protected]> wrote:
From: Herbert Valerio Riedel <[email protected]>
Subject: hwmon: add support for GMT G760A fan speed PWM controllerThis controller can be found on the D-Link DNS-323 for instance, where it is to be configured via static
i2c_board_infoin the board-specificmach-orion/dns323-setup.c; this driver supports only the new-style driver model....
drivers/hwmon/g760a.c +1
-0+struct g760a_data {
drivers/hwmon/g760a.c line 49
Quoted 10 lines
drivers/hwmon/g760a.c +10
-0+struct i2c_client *client; +struct device *hwmon_dev; +struct mutex update_lock; + +/* board specific parameters */ +u32 clk;/* default 32kHz */ +u16 fan_div;/* default P=2 */ + +/* g760a register cache */ + int valid:1;
I think sparse gets upset about signed single-bit bit fields. Because the sole bit is also the sign bit, so does it have a value of 1, or of -1???
So it should be converted to unsigned.
Quoted 4 lines
drivers/hwmon/g760a.c +4
-0+unsigned long last_updated;/* In jiffies */ + +u8 set_cnt;/* PWM (period) count number; 0xff stops fan */ +u8 act_cnt;/* formula: cnt = (CLK * 30)/(rpm * P) */
drivers/hwmon/g760a.c
Quoted 10 lines
drivers/hwmon/g760a.c +10
-0+u8 fan_sta;/* bit 0: set when actual fan speed more than 20% +* outside requested fan speed +* bit 1: set when fan speed below 1920 rpm */ +}; + +#define G760A_DEFAULT_CLK 32768 +#define G760A_DEFAULT_FAN_DIV 2 + +#define RPM_FROM_CNT (val, clk, div) \ + ((0x00 = (val)) ? 0 : (((clk)*30)/((val)*(div))))
The macro evaluates its arguments multiple times hence is slow or buggy if passed an expression with side effects.
Please convert it to a plain old lower-case C function.
drivers/hwmon/g760a.c line 124
Quoted 11 lines
drivers/hwmon/g760a.c +8
-0+#define PWM_FROM_CNT (cnt) (0xff-(cnt)) +#define PWM_TO_CNT (pwm) (0xff-(pwm)) + +static ssize_t show_fan (struct device *dev,struct device_attribute *da, +char *buf) +{ +struct g760a_data *data =g760a_update_client (dev); +int rpm =0 ;
An unsigned type would be more appropriate here.
Quoted 8 lines
drivers/hwmon/g760a.c +8
-0+mutex_lock (&data->update_lock); +if (!(data->fan_sta &G760A_REG_FAN_STA_RPM_LOW )) + rpm =RPM_FROM_CNT (data->act_cnt, data->clk, data->fan_div); +mutex_unlock (&data->update_lock); + +return sprintf (buf,"%d\n" , rpm); +} +
drivers/hwmon/g760a.c line 158
Quoted 10 lines
drivers/hwmon/g760a.c +7
-0+static ssize_t set_pwm (struct device *dev,struct device_attribute *da, +const char *buf,size_t count) +{ +struct i2c_client *client =to_i2c_client (dev); +struct g760a_data *data =g760a_update_client (dev); + +const long val =simple_strtol (buf,NULL ,10 );
strict_strtoul()?
drivers/hwmon/g760a.c
Quoted 11 lines
drivers/hwmon/g760a.c +8
-0+mutex_lock (&data->update_lock); + data->set_cnt =PWM_TO_CNT (SENSORS_LIMIT (val,0 ,255 )); +g760a_write_value (client,G760A_REG_SET_CNT , data->set_cnt); +mutex_unlock (&data->update_lock); + +return count; +} +
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Martin Michlmayr
Tested-byQuoted 1 line · Andrew Morton
I think sparse gets upset about signed single-bit bit fields. Because the
...
Thanks for the review. I made those changes, ran the patch through checkpatch.pl again, and tested it. Here's the new version:
From: Herbert Valerio Riedel <[email protected]>
Subject: hwmon: add support for GMT G760A fan speed PWM controller
This controller can be found on the D-Link DNS-323 for instance, where it is to be configured via static i2c_board_info in the board-specific mach-orion/dns323-setup.c; this driver supports only the new-style driver model.
drivers/hwmon/Kconfig +10 -0
@@ -357,6 +357,16 @@ config SENSORS_FSCHMD This driver can also be built as a module. If so, the module will be called fschmd. +config SENSORS_G760A + tristate "GMT G760A" + depends on I2C + help + If you say yes here you get support for Global Mixed-mode + Technology Inc G760A fan speed PWM controller chips. + + This driver can also be built as a module. If so, the module + will be called g760a. + config SENSORS_GL518SM tristate "Genesys Logic GL518SM" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_SENSORS_F75375S) += f75375s.o obj-$(CONFIG_SENSORS_FSCHER) += fscher.o obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o +obj-$(CONFIG_SENSORS_G760A) += g760a.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_ULTRA45) += ultra45_env.o
Documentation/hwmon/g760a new file +35 -0
@@ -0,0 +1,36 @@ +Kernel driver g760a +=========+ +Supported chips: + * Global Mixed-mode Technology Inc. G760A + Prefix: 'g760a' + Datasheet: Publicly available at the GMT website + http://www.gmt.com.tw/datasheet/g760a.pdf + +Author: Herbert Valerio Riedel <[email protected]> + +Description +----------- + +The GMT G760A Fan Speed PWM Controller is connected directly to a fan +and performs closed-loop control of the fan speed. + +The fan speed is programmed by setting the period via 'pwm1' of two +consecutive speed pulses. The period is defined in terms of clock +cycle counts of an assumed 32kHz clock source. + +Setting a period of 0 stops the fan; setting the period to 255 sets +fan to maximum speed. + +The measured fan rotation speed returned via 'fan1_input' is derived +from the measured speed pulse period by assuming again a 32kHz clock +source and a 2 pulse-per-revolution fan. + +The 'alarms' file provides access to the two alarm bits provided by +the G760A chip's status register: Bit 0 is set when the actual fan +speed differs more than 20% with respect to the programmed fan speed; +bit 1 is set when fan speed is below 1920 RPM. + +The g760a driver will not update its values more frequently than every +other second; reading them more often will do no harm, but will return +'old' values.
drivers/hwmon/g760a.c new file +272 -0
272 lines not on this page · raw message
Signature · 7 lines
Martin Michlmayr http://www.cyrius.com/ _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors