Add G762/G763 PWM fan controller
Subsystems (3)
v3 cover Add G762/G763 PWM fan controller
Hi,
This series adds support for GMT G762/G763. This work is based on a basic version for 2.6.31 kernel developed Olivier Mouchet for LaCie NAS. Updates have been performed to run on recent kernels. Support has been completed and additional features added: ability to configure various characteristics from .dts file, better initialization, alarms and error reporting support, gear mode, polarity, fan pulse per revolution, fan startup voltage control. The following detailed datasheet has been used as a basis for this work:
http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf
The patch was developed for and tested against the GMT G762 fan controller used in a Netgear ReadyNAS Duo v2 (kirkwood 88F6282-based NAS). This is the main reason for the device tree bindings provided in first patch. The driver also support init via board file. The patches are against current ARM tree; tell me if you need me to rebase it against something else. Patch 2 and 3 provides documentation for the driver and DT bindings, respectively.
As discussed in a previous email:
- A macro is defined to pass values of platform data structure in board setup files. If one has a better approach ...
- This v3 still has support for pwm1 sysfs entry in closed-loop mode. Guenter, if you still think it is a bad idea, I will change that in v4.
note: this should not be an issue but this v3 is based on
jcooper/mvebu/fixes branch.
Comments welcome,
Cheers,
a+
Changes since v2:
set ref_clk value to 32768 if not overloaded
fixed multi-line comment format in g762.h
add spaces between operators when missing
check return value of i2c_smbus_{read,write}_byte_data()
{ } is not needed in single-statement conditionals introduced G762_ATTR_VAL() to allow sparse init of platform_data struct changed reference to linear mode for DC mode in doc
Changes since v1
Changed author
removed bad tabs
Provide datasheet link w/o fud in g762 documentation
removed documentation for removed fan_gear_mode sysfs entry removed tested-by from patch
removed FSF address in header file
removed useless include of <linux/slab.h>
removed useless parenthesis against HZ in define
use spaces around binary operators
use i2c_smbus_{read,write}_byte_data() instead of g762_{read,write}_value() use return value of i2c_smbus_write_byte_data()
use true for initializing boolean
removed useless blank lines
do not enforce single return point rule where less readable use dev_err() and dev_dbg() instead of dev_info() when it makes sense remove leading '&' for function passed as pointers
allow passing parameter via platform_data struct for non-DT enabled boards set data->valid to false when config is modified
s/linear/DC/ for mode (g762 datasheet uses linear)
more tests on rpm_from_cnt() and cnt_from_rpm() formula
dont overload
Changes since v0
removed forward declaration
use bool for valid field instead of bit field.
protect macro args
fixed typo in subject line
Added mention for G763 support in Kconfig
fixed typo in driver name in Kconfig
do not use DRVNAME in i2c_device_id g762_id[]
Following discussions, kept DEVICE_ATTR (i.e. no switch to SENSOR_DEVICE_ATTR) removed useless casts when flipping bit values
Sanity check user input value (e.g. to prevent 256 to silenty become 0) Added extra lines for multi line comments when needed
removed various testing knobs
make removed knobs available via DT
passed checkpatch script on the patch
removed useless lock protection againt clk setting
moved all setter at the beginning of the file
removed bad (u16) casts in g762_write_value() calls
Arnaud Ebalard (3):
Add support for GMT G762/G763 PWM fan controller Add documentation for g762 driver
Add DT bindings documentation for g762 driver
Documentation/devicetree/bindings/hwmon/g762.txt | 58 ++ Documentation/hwmon/g762 | 64 ++ drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/g762.c | 1179 ++++++++++++++++++++++ include/linux/platform_data/g762.h | 51 + 6 files changed, 1363 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/g762.txt create mode 100644 Documentation/hwmon/g762 create mode 100644 drivers/hwmon/g762.c create mode 100644 include/linux/platform_data/g762.h
Signature · 1 line
1.7.10.4
PATCH v3 1/3 Add support for GMT G762/G763 PWM fan controller
--- drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/g762.c | 1179 ++++++++++++++++++++++++++++++++++++ include/linux/platform_data/g762.h | 51 ++ 4 files changed, 1241 insertions(+) create mode 100644 drivers/hwmon/g762.c create mode 100644 include/linux/platform_data/g762.h
drivers/hwmon/Kconfig +10 -0
@@ -456,6 +456,16 @@ config SENSORS_G760A This driver can also be built as a module. If so, the module will be called g760a. +config SENSORS_G762 + tristate "GMT G762 and G763" + depends on I2C + help + If you say yes here you get support for Global Mixed-mode + Technology Inc G762 and G763 fan speed PWM controller chips. + + This driver can also be built as a module. If so, the module + will be called g762. + config SENSORS_GL518SM tristate "Genesys Logic GL518SM" depends on I2C
drivers/hwmon/Makefile +1 -0
@@ -60,6 +60,7 @@ obj-$(CONFIG_SENSORS_F75375S) += f75375s.o obj-$(CONFIG_SENSORS_FAM15H_POWER) += fam15h_power.o obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o obj-$(CONFIG_SENSORS_G760A) += g760a.o +obj-$(CONFIG_SENSORS_G762) += g762.o obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o obj-$(CONFIG_SENSORS_GPIO_FAN) += gpio-fan.o
drivers/hwmon/g762.c new file +1179 -0
1,179 lines not on this page · raw message
include/linux/platform_data/g762.h new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v3 2/3 Add documentation for g762 driver
In reply to Arnaud Ebalard--- Documentation/hwmon/g762 | 64 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Documentation/hwmon/g762
Documentation/hwmon/g762 new file +64 -0
@@ -0,0 +1,64 @@ +Kernel driver g762 +================== + +The GMT G762 Fan Speed PWM Controller is connected directly to a fan +and performs closed-loop or open-loop control of the fan speed. Two +modes - PWM or DC - are supported by the device. + +For additional information, a detailed datasheet is available at +http://natisbad.org/NAS/ref/GMT_EDS-762_763-080710-0.2.pdf. sysfs +bindings are described in Documentation/hwmon/sysfs-interface. + +The following entries are available to the user in a subdirectory of +/sys/bus/i2c/drivers/g762/ to control the operation of the device. +This can be done manually using the following entries but is usually +done via a userland daemon like fancontrol. + +Note that those entries do not provide ways to setup the specific +hardware characteristics of the system (reference clock, pulses per +fan revolution, ...); Those can be modified via devicetree bindings +documented in Documentation/devicetree/bindings/hwmon/g762.txt. + + + fan1_target: set desired fan speed. This only makes sense in closed-loop + fan speed control (i.e. when pwm1_enable is set to 2). + + fan1_input: provide current fan rotation value in RPM as reported by + the fan to the device. + + fan1_div: fan clock divisor. Supported value are 1, 2, 4 and 8. + + fan1_fault: reports fan failure, i.e. no transition on fan gear pin for + about 0.7s (if the fan is not voluntarily set off). + + fan1_alarm: in closed-loop control mode, if fan RPM value is 25% out + of the programmed value for over 6 seconds 'fan1_alarm' is + set to 1. + + pwm1_enable: set current fan speed control mode i.e. 1 for manual fan + speed control (open-loop) via pwm1 described below, 2 for + automatic fan speed control (closed-loop) via fan1_target + above (pwm1 is also usable). + + pwm1_mode: set or get fan driving mode: 1 for PWM mode, 0 for DC mode. + + pwm1: get or set PWM fan control value. This is an integer value + between 0 and 255. 0 stops the fan, 255 makes it run at + full speed. Note that the fan speed control mode (open vs + closed-loop) must be set prior via pwm1_enable prior to + passing a value via pwm1. + + +Both in PWM mode ('pwm1_mode' set to 1) and DC mode ('pwm1_mode' set to 0), +when current fan speed control mode is open-loop ('pwm1_enable' set to 1), +the fan speed is programmed by setting a value between 0 and 255 via 'pwm1' +entry (0 stops the fan, 255 makes it run at full speed). In closed-loop mode +('pwm1_enable' set to 2), the expected rotation speed in RPM can be passed to +the chip via 'fan1_target'. In closed-loop mode, the target speed is compared +with current speed (available via 'fan1_input') by the device and a feedback +is performed to match that target value. The fan speed value is computed +based on the parameters associated with the physical characteristics of the +system: a reference clock source frequency, a number of pulses per fan +revolution, etc. + +Note that the driver will update its values at most once per second.
Signature · 1 line
1.7.10.4
PATCH v3 3/3 Add DT bindings documentation for g762 driver
In reply to Arnaud Ebalard--- Documentation/devicetree/bindings/hwmon/g762.txt | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/g762.txt
Documentation/devicetree/bindings/hwmon/g762.txt new file +58 -0
@@ -0,0 +1,58 @@ +GMT G762/G763 PWM Fan controller + +Required node properties: + + - "compatible": must be either "gmt,g762" or "gmt,g763" + - "reg": I2C bus address of the device + +Optional properties: + + - "pwm_mode": fan driving mode. 1 for PWM mode, 0 for DC mode. + + - "pwm_enable": fan speed control. 1 for open-loop, 2 for closed-loop. + + - "pwm_freq": reference clock frequency for PWM mode in Hz. If not set, + default value is 32768. + + - "fan_pulses": number of pulses per fan revolution. Supported values + are 2 and 4. + + - "fan_div": fan clock frequency divisor value. Supported values are 1, + 2, 4 and 8. Default is 1. + + - "fan_target": initial target fan speed in RPM. Only works in closed-loop + fan speed control, i.e. when pwm_enable has already been set + to 2. + + - "fan_startv": fan startup voltage. Accepted values are 0, 1, 2 and 3. + The higher the more. + + - "pwm_polarity": pwm polarity. Accepted values are 0 (positive duty) + and 1 (negative duty). + + - "fan_gear_mode": fan gear mode. Supported values are 0, 1 and 2. + +If an optional property is not set in .dts file, then current value is kept +unmodified (e.g. u-boot installed value). + + +Additional information on operational parameters for the device is available +in Documentation/hwmon/g762. A detailed datasheet for the device is available +at http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf. + +Example g762 node: + + g762: g762 at 3e { + compatible = "gmt,g762"; + reg = <0x3e>; + pwm_mode = <1>; /* closed-loop control */ + pwm_enable = <2>; /* PWM mode */ + pwm_freq = <8192>; /* PWM reference clock freq */ + fan_pulses = <2>; /* 2 pulses per rev */ + fan_div = <2>; /* fan clock divisor */ + fan_target = <2000>; /* target fan speed at 2000 RPM */ + fan_gear_mode = <0>; /* chip default */ + fan_startv = <1>; /* chip default */ + pwm_polarity = <0>; /* chip default */ + }; +
Signature · 1 line
1.7.10.4
Guenter Roeck
maintainerv3 cover Add G762/G763 PWM fan controller
In reply to Arnaud EbalardQuoted 21 lines · Arnaud Ebalard
Hi,
This series adds support for GMT G762/G763. This work is based on a basic version for 2.6.31 kernel developed Olivier Mouchet for LaCie NAS. Updates have been performed to run on recent kernels. Support has been completed and additional features added: ability to configure various characteristics from .dts file, better initialization, alarms and error reporting support, gear mode, polarity, fan pulse per revolution, fan startup voltage control. The following detailed datasheet has been used as a basis for this work:
http://natisbad.org/NAS/refs/GMT_EDS-762_763-080710-0.2.pdf
The patch was developed for and tested against the GMT G762 fan controller used in a Netgear ReadyNAS Duo v2 (kirkwood 88F6282-based NAS). This is the main reason for the device tree bindings provided in first patch. The driver also support init via board file. The patches are against current ARM tree; tell me if you need me to rebase it against something else. Patch 2 and 3 provides documentation for the driver and DT bindings, respectively.
Quoted 8 lines
As discussed in a previous email:
- A macro is defined to pass values of platform data structure in board setup files. If one has a better approach ...
- This v3 still has support for pwm1 sysfs entry in closed-loop mode. Guenter, if you still think it is a bad idea, I will change that in v4.
If you want me to accept your code, I would suggest to change it such that pwm1 sets the FAN_SET_OUT register, and fan1_target sets the SET_CNT register, both unconditionally. Redefining the pwm1 attribute to set the fan target speed instead of a pwm / voltage value is not acceptable.
Quoted 3 lines
note: this should not be an issue but this v3 is based on
jcooper/mvebu/fixes branch.
I don't know about this branch/repository. If there are hwmon fixes in it, they should be submitted to the lm-sensors mailing list.
Thanks,
Guenter
Guenter Roeck
maintainerPATCH v3 1/3 Add support for GMT G762/G763 PWM fan controller
In reply to Arnaud EbalardQuoted 11 lines · Arnaud Ebalard
Signed-off-by Arnaud Ebalard <[email protected]>--- drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/g762.c | 1179 ++++++++++++++++++++++++++++++++++++ include/linux/platform_data/g762.h | 51 ++ 4 files changed, 1241 insertions(+) create mode 100644 drivers/hwmon/g762.c create mode 100644 include/linux/platform_data/g762.h
[ ... ]
drivers/hwmon/g762.c line 220
Quoted 9 lines
drivers/hwmon/g762.c new file +9
-0+static inline int g762_read_byte (const struct i2c_client *client,u8 reg, +u8 *dest) +{ +int ret; + + ret =i2c_smbus_read_byte_data (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"failed to read reg %x02x, err %d\n" , + (int )reg, ret);
I would suggest to write a piece of test code for the above statement and observe its output. "printf("%x02x\n", 0x1234);" should do.
Is the error message really needed ? If there is a persistent error, it will clog the log.
Thanks,
Guenter
v3 cover Add G762/G763 PWM fan controller
In reply to Guenter RoeckQuoted 1 line · Guenter Roeck
On Sun, Jun 02, 2013 at 10:14:05PM +0200, Arnaud Ebalard wrote:
...
Quoted 5 lines
Quoted 3 lines
note: this should not be an issue but this v3 is based on
jcooper/mvebu/fixes branch.I don't know about this branch/repository. If there are hwmon fixes in it, they should be submitted to the lm-sensors mailing list.
Yes, please, unless you *need* a patch to build/boot that isn't in mainline yet, always base off of one of Linus' tags, eg v3.10-rc4. Then, if asked, rebase as needed.
thx,
Jason.
PATCH v3 1/3 Add support for GMT G762/G763 PWM fan controller
In reply to Guenter RoeckHi,
Quoted 14 lines · Guenter Roeck
Quoted 11 lines · Arnaud Ebalard
Signed-off-by Arnaud Ebalard <[email protected]>--- drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/g762.c | 1179 ++++++++++++++++++++++++++++++++++++ include/linux/platform_data/g762.h | 51 ++ 4 files changed, 1241 insertions(+) create mode 100644 drivers/hwmon/g762.c create mode 100644 include/linux/platform_data/g762.h[ ... ]
Quoted 12 lines
drivers/hwmon/g762.c line 220
Quoted 9 lines
drivers/hwmon/g762.c new file +9
-0+static inline int g762_read_byte (const struct i2c_client *client,u8 reg, +u8 *dest) +{ +int ret; + + ret =i2c_smbus_read_byte_data (client, reg); +if (ret <0 ) { +dev_err (&client->dev,"failed to read reg %x02x, err %d\n" , + (int )reg, ret);I would suggest to write a piece of test code for the above statement and observe its output. "
printf("%x02x\n", 0x1234);" should do.
good catch. s/%x02x/0x%02x/.
Quoted 2 lines
Is the error message really needed ? If there is a persistent error, it will clog the log.
I removed it in v4 to come.
Cheers,
a+