New driver to support GMT G762/G763 pwm fan controllers

Add support for DS1631, DS1721, and DS1731 to ds1621 driver
 Remove detect function from ds1621 driver as unreliable
 Bug fixes in nct6775, iio_hwmon, and adm1021 drivers
 Remove redundant platform_set_drvdata in various drivers
 Add device tree support to ina2xx driver
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.12 (GNU/Linux)
 
 iQIcBAABAgAGBQJR0I8LAAoJEMsfJm/On5mBPp8P+wedtxZpljmca+YnuBnZnnZN
 7HLFdGvbwOA+ThfYx7UhpyRgJ+D4ggB0jTiVCPHGUJzmwYjEVk5e9qZkIX/1fBIB
 Iun9TZdJPG+fYFkr8H91dnJcaeELog76yOvx3VRU1QYO11L1wx56oJ2b3a+lnIb5
 UNyovFhvJuZ4jDpzQNUGY5/CMScj2rtPiRPT5NC/3HoSmkXFuV1uw4nhn3C79ycR
 NoZFyjFi7J1hCTB7ExoHHSQBGdLFDXQiEZqNaQS4WXnW1jmiTsQl0rRLoP5KqUDU
 3NovVA557nOfOHAjB98nQrBM7Syn2jKYeZP+M5OR1iKIXxv5uUs/Ajmpnk5x2t1d
 Wf5uHW99SEDTn19U8icgOO4zLvNX0lSXHs+FC6hzKTpLp/FLVjP2uOYj9TcxtPzn
 pLAYsE5UIySH4ybJ0Jdf2pKA+8D2eAOVo1joFhaoz8qFjMNdSxBlf8/xOUsBaJoi
 dAQ/SmWc9z0Tk03Hxn1b/XVKHLbb3AIpPTe1PCK9bUBzLQyZp2UmBmSPHIVxdjO/
 zyRABp64pkoVMqomJPzujEgT2NaqSfr+wwLyUOPBtmaMM8N6aOUlRjrJyOHrSrmB
 3CTT23h8xp8lEgjezQ0jYlhNQPgpGmlu/yuFfL2GyqRw00clAkUem0BrstZg0EOD
 lepSJCaSpyqr3jfhIBwN
 =OdGw
 -----END PGP SIGNATURE-----

Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

Pull hwmon updates from Guenter Roeck:
 - new driver to support GMT G762/G763 pwm fan controllers
 - add support for DS1631, DS1721, and DS1731 to ds1621 driver
 - remove detect function from ds1621 driver as unreliable
 - bug fixes in nct6775, iio_hwmon, and adm1021 drivers
 - remove redundant platform_set_drvdata in various drivers
 - add device tree support to ina2xx driver

* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging:
  hwmon: (ds1621) Fix temperature rounding operations
  hwmon: (nct6775) Drop unsupported fan alarm attributes for NCT6775
  hwmon: (nct6775) Fix temperature alarm attributes
  Add support for GMT G762/G763 PWM fan controllers
  hwmon: (ina2xx) Add device tree support to pass the shunt resistor
  hwmon: (ds1621) Update documentation
  hwmon: (ds1621) Add DS1731 chip support to ds1621 driver
  hwmon: (iio_hwmon) add alias table
  hwmon: (adm1021) Do not create min sysfs attributes for LM84
  hwmon: (ds1621) Remove detect function
  hwmon: (ds1621) Add ds1631 chip support to ds1621 driver and documentation
  hwmon: (ds1621) Add ds1721 update interval sysfs attribute
  hwmon: (ds1621) Add ds1721 chip support
  hwmon: (w83627ehf) Remove redundant platform_set_drvdata()
  hwmon: (ntc_thermistor) Remove redundant platform_set_drvdata()
  hwmon: (i5k_amb) Remove redundant platform_set_drvdata()
  hwmon: (coretemp) Remove redundant platform_set_drvdata()
  hwmon: (abituguru3) Remove redundant platform_set_drvdata()
This commit is contained in:
Linus Torvalds 2013-07-03 19:56:35 -07:00
commit ddcf6600b1
19 changed files with 1743 additions and 111 deletions

View File

@ -0,0 +1,47 @@
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
- "clocks": a fixed clock providing input clock frequency
on CLK pin of the chip.
Optional properties:
- "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:
clocks {
#address-cells = <1>;
#size-cells = <0>;
g762_clk: fixedclk {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <8192>;
}
}
g762: g762@3e {
compatible = "gmt,g762";
reg = <0x3e>;
clocks = <&g762_clk>
fan_gear_mode = <0>; /* chip default */
fan_startv = <1>; /* chip default */
pwm_polarity = <0>; /* chip default */
};

View File

@ -0,0 +1,22 @@
ina2xx properties
Required properties:
- compatible: Must be one of the following:
- "ti,ina219" for ina219
- "ti,ina220" for ina220
- "ti,ina226" for ina226
- "ti,ina230" for ina230
- reg: I2C address
Optional properties:
- shunt-resistor
Shunt resistor value in micro-Ohm
Example:
ina220@44 {
compatible = "ti,ina220";
reg = <0x44>;
shunt-resistor = <1000>;
};

View File

@ -2,16 +2,30 @@ Kernel driver ds1621
====================
Supported chips:
* Dallas Semiconductor DS1621
* Dallas Semiconductor / Maxim Integrated DS1621
Prefix: 'ds1621'
Addresses scanned: I2C 0x48 - 0x4f
Datasheet: Publicly available at the Dallas Semiconductor website
http://www.dalsemi.com/
Addresses scanned: none
Datasheet: Publicly available from www.maximintegrated.com
* Dallas Semiconductor DS1625
Prefix: 'ds1621'
Addresses scanned: I2C 0x48 - 0x4f
Datasheet: Publicly available at the Dallas Semiconductor website
http://www.dalsemi.com/
Prefix: 'ds1625'
Addresses scanned: none
Datasheet: Publicly available from www.datasheetarchive.com
* Maxim Integrated DS1631
Prefix: 'ds1631'
Addresses scanned: none
Datasheet: Publicly available from www.maximintegrated.com
* Maxim Integrated DS1721
Prefix: 'ds1721'
Addresses scanned: none
Datasheet: Publicly available from www.maximintegrated.com
* Maxim Integrated DS1731
Prefix: 'ds1731'
Addresses scanned: none
Datasheet: Publicly available from www.maximintegrated.com
Authors:
Christian W. Zuckschwerdt <zany@triq.net>
@ -59,5 +73,115 @@ any of the limits have ever been met or exceeded since last power-up or
reset. Be aware: When testing, it showed that the status of Tout can change
with neither of the alarms set.
Temperature conversion of the DS1621 takes up to 1000ms; internal access to
non-volatile registers may last for 10ms or below.
Since there is no version or vendor identification register, there is
no unique identification for these devices. Therefore, explicit device
instantiation is required for correct device identification and functionality
(one device per address in this address range: 0x48..0x4f).
The DS1625 is pin compatible and functionally equivalent with the DS1621,
but the DS1621 is meant to replace it. The DS1631, DS1721, and DS1731 are
also pin compatible with the DS1621 and provide multi-resolution support.
Additionally, the DS1721 data sheet says the temperature flags (THF and TLF)
are used internally, however, these flags do get set and cleared as the actual
temperature crosses the min or max settings (which by default are set to 75
and 80 degrees respectively).
Temperature Conversion:
-----------------------
DS1621 - 750ms (older devices may take up to 1000ms)
DS1625 - 500ms
DS1631 - 93ms..750ms for 9..12 bits resolution, respectively.
DS1721 - 93ms..750ms for 9..12 bits resolution, respectively.
DS1731 - 93ms..750ms for 9..12 bits resolution, respectively.
Note:
On the DS1621, internal access to non-volatile registers may last for 10ms
or less (unverified on the other devices).
Temperature Accuracy:
---------------------
DS1621: +/- 0.5 degree Celsius (from 0 to +70 degrees)
DS1625: +/- 0.5 degree Celsius (from 0 to +70 degrees)
DS1631: +/- 0.5 degree Celsius (from 0 to +70 degrees)
DS1721: +/- 1.0 degree Celsius (from -10 to +85 degrees)
DS1731: +/- 1.0 degree Celsius (from -10 to +85 degrees)
Note:
Please refer to the device datasheets for accuracy at other temperatures.
Temperature Resolution:
-----------------------
As mentioned above, the DS1631, DS1721, and DS1731 provide multi-resolution
support, which is achieved via the R0 and R1 config register bits, where:
R0..R1
------
0 0 => 9 bits, 0.5 degrees Celcius
1 0 => 10 bits, 0.25 degrees Celcius
0 1 => 11 bits, 0.125 degrees Celcius
1 1 => 12 bits, 0.0625 degrees Celcius
Note:
At initial device power-on, the default resolution is set to 12-bits.
The resolution mode for the DS1631, DS1721, or DS1731 can be changed from
userspace, via the device 'update_interval' sysfs attribute. This attribute
will normalize the range of input values to the device maximum resolution
values defined in the datasheet as follows:
Resolution Conversion Time Input Range
(C/LSB) (msec) (msec)
------------------------------------------------
0.5 93.75 0....94
0.25 187.5 95...187
0.125 375 188..375
0.0625 750 376..infinity
------------------------------------------------
The following examples show how the 'update_interval' attribute can be
used to change the conversion time:
$ cat update_interval
750
$ cat temp1_input
22062
$
$ echo 300 > update_interval
$ cat update_interval
375
$ cat temp1_input
22125
$
$ echo 150 > update_interval
$ cat update_interval
188
$ cat temp1_input
22250
$
$ echo 1 > update_interval
$ cat update_interval
94
$ cat temp1_input
22000
$
$ echo 1000 > update_interval
$ cat update_interval
750
$ cat temp1_input
22062
$
As shown, the ds1621 driver automatically adjusts the 'update_interval'
user input, via a step function. Reading back the 'update_interval' value
after a write operation provides the conversion time used by the device.
Mathematically, the resolution can be derived from the conversion time
via the following function:
g(x) = 0.5 * [minimum_conversion_time/x]
where:
-> 'x' = the output from 'update_interval'
-> 'g(x)' = the resolution in degrees C per LSB.
-> 93.75ms = minimum conversion time

65
Documentation/hwmon/g762 Normal file
View File

@ -0,0 +1,65 @@
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 or
using a specific platform_data structure in board initialization
file (see include/linux/platform_data/g762.h).
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_pulses: number of pulses per fan revolution. Supported values
are 2 and 4.
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_mode: set or get fan driving mode: 1 for PWM mode, 0 for DC mode.
pwm1: get or set PWM fan control value in open-loop mode. This is an
integer value between 0 and 255. 0 stops the fan, 255 makes
it run at full speed.
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.

View File

@ -44,4 +44,6 @@ The INA226 monitors both a shunt voltage drop and bus supply voltage.
The INA230 is a high or low side current shunt and power monitor with an I2C
interface. The INA230 monitors both a shunt voltage drop and bus supply voltage.
The shunt value in micro-ohms can be set via platform data.
The shunt value in micro-ohms can be set via platform data or device tree.
Please refer to the Documentation/devicetree/bindings/i2c/ina2xx.txt for bindings
if the device tree is used.

View File

@ -348,11 +348,16 @@ config SENSORS_DS620
will be called ds620.
config SENSORS_DS1621
tristate "Dallas Semiconductor DS1621 and DS1625"
tristate "Dallas Semiconductor DS1621 and compatibles"
depends on I2C
help
If you say yes here you get support for Dallas Semiconductor
DS1621 and DS1625 sensor chips.
If you say yes here you get support for Dallas Semiconductor/Maxim
Integrated DS1621 sensor chips and compatible models including:
- Dallas Semiconductor DS1625
- Maxim Integrated DS1631
- Maxim Integrated DS1721
- Maxim Integrated DS1731
This driver can also be built as a module. If so, the module
will be called ds1621.
@ -456,6 +461,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

View File

@ -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

View File

@ -1079,7 +1079,6 @@ static int abituguru3_remove(struct platform_device *pdev)
int i;
struct abituguru3_data *data = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
hwmon_device_unregister(data->hwmon_dev);
for (i = 0; data->sysfs_attr[i].dev_attr.attr.name; i++)
device_remove_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);

View File

@ -284,15 +284,11 @@ static DEVICE_ATTR(low_power, S_IWUSR | S_IRUGO, show_low_power, set_low_power);
static struct attribute *adm1021_attributes[] = {
&sensor_dev_attr_temp1_max.dev_attr.attr,
&sensor_dev_attr_temp1_min.dev_attr.attr,
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp2_max.dev_attr.attr,
&sensor_dev_attr_temp2_min.dev_attr.attr,
&sensor_dev_attr_temp2_input.dev_attr.attr,
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_fault.dev_attr.attr,
&dev_attr_alarms.attr,
&dev_attr_low_power.attr,
@ -303,6 +299,18 @@ static const struct attribute_group adm1021_group = {
.attrs = adm1021_attributes,
};
static struct attribute *adm1021_min_attributes[] = {
&sensor_dev_attr_temp1_min.dev_attr.attr,
&sensor_dev_attr_temp2_min.dev_attr.attr,
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
NULL
};
static const struct attribute_group adm1021_min_group = {
.attrs = adm1021_min_attributes,
};
/* Return 0 if detection is successful, -ENODEV otherwise */
static int adm1021_detect(struct i2c_client *client,
struct i2c_board_info *info)
@ -425,6 +433,12 @@ static int adm1021_probe(struct i2c_client *client,
if (err)
return err;
if (data->type != lm84) {
err = sysfs_create_group(&client->dev.kobj, &adm1021_min_group);
if (err)
goto error;
}
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
@ -434,6 +448,7 @@ static int adm1021_probe(struct i2c_client *client,
return 0;
error:
sysfs_remove_group(&client->dev.kobj, &adm1021_min_group);
sysfs_remove_group(&client->dev.kobj, &adm1021_group);
return err;
}
@ -452,6 +467,7 @@ static int adm1021_remove(struct i2c_client *client)
struct adm1021_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &adm1021_min_group);
sysfs_remove_group(&client->dev.kobj, &adm1021_group);
return 0;
@ -477,9 +493,11 @@ static struct adm1021_data *adm1021_update_device(struct device *dev)
data->temp_max[i] = 1000 *
(s8) i2c_smbus_read_byte_data(
client, ADM1021_REG_TOS_R(i));
if (data->type != lm84) {
data->temp_min[i] = 1000 *
(s8) i2c_smbus_read_byte_data(
client, ADM1021_REG_THYST_R(i));
(s8) i2c_smbus_read_byte_data(client,
ADM1021_REG_THYST_R(i));
}
}
data->alarms = i2c_smbus_read_byte_data(client,
ADM1021_REG_STATUS) & 0x7c;

View File

@ -578,7 +578,6 @@ static int coretemp_probe(struct platform_device *pdev)
exit_name:
device_remove_file(&pdev->dev, &pdata->name_attr);
platform_set_drvdata(pdev, NULL);
exit_free:
kfree(pdata);
return err;
@ -595,7 +594,6 @@ static int coretemp_remove(struct platform_device *pdev)
device_remove_file(&pdev->dev, &pdata->name_attr);
hwmon_device_unregister(pdata->hwmon_dev);
platform_set_drvdata(pdev, NULL);
kfree(pdata);
return 0;
}

View File

@ -6,6 +6,19 @@
* Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
* the help of Jean Delvare <khali@linux-fr.org>
*
* The DS1621 device is a digital temperature/thermometer with 9-bit
* resolution, a thermal alarm output (Tout), and user-defined minimum
* and maximum temperature thresholds (TH and TL).
*
* The DS1625, DS1631, DS1721, and DS1731 are pin compatible with the DS1621
* and similar in operation, with slight variations as noted in the device
* datasheets (please refer to www.maximintegrated.com for specific
* device information).
*
* Since the DS1621 was the first chipset supported by this driver,
* most comments will refer to this chipset, but are actually general
* and concern all supported chipsets, unless mentioned otherwise.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@ -31,27 +44,62 @@
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
#include "lm75.h"
#include <linux/kernel.h>
/* Addresses to scan */
static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
/* Supported devices */
enum chips { ds1621, ds1625, ds1631, ds1721, ds1731 };
/* Insmod parameters */
static int polarity = -1;
module_param(polarity, int, 0);
MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
/* Many DS1621 constants specified below */
/* Config register used for detection */
/* 7 6 5 4 3 2 1 0 */
/* |Done|THF |TLF |NVB | X | X |POL |1SHOT| */
/*
* The Configuration/Status register
*
* - DS1621:
* 7 6 5 4 3 2 1 0
* |Done|THF |TLF |NVB | X | X |POL |1SHOT|
*
* - DS1625:
* 7 6 5 4 3 2 1 0
* |Done|THF |TLF |NVB | 1 | 0 |POL |1SHOT|
*
* - DS1631, DS1731:
* 7 6 5 4 3 2 1 0
* |Done|THF |TLF |NVB | R1 | R0 |POL |1SHOT|
*
* - DS1721:
* 7 6 5 4 3 2 1 0
* |Done| X | X | U | R1 | R0 |POL |1SHOT|
*
* Where:
* - 'X' is Reserved
* - 'U' is Undefined
*/
#define DS1621_REG_CONFIG_NVB 0x10
#define DS1621_REG_CONFIG_RESOL 0x0C
#define DS1621_REG_CONFIG_POLARITY 0x02
#define DS1621_REG_CONFIG_1SHOT 0x01
#define DS1621_REG_CONFIG_DONE 0x80
/* The DS1621 registers */
#define DS1621_REG_CONFIG_RESOL_SHIFT 2
/* ds1721 conversion rates: {C/LSB, time(ms), resolution bit setting} */
static const unsigned short ds1721_convrates[] = {
94, /* 9-bits (0.5, 93.75, RES[0..1] = 0 */
188, /* 10-bits (0.25, 187.5, RES[0..1] = 1 */
375, /* 11-bits (0.125, 375, RES[0..1] = 2 */
750, /* 12-bits (0.0625, 750, RES[0..1] = 3 */
};
#define DS1621_CONVERSION_MAX 750
#define DS1625_CONVERSION_MAX 500
#define DS1621_TEMP_MAX 125000
#define DS1621_TEMP_MIN (-55000)
/* The DS1621 temperature registers */
static const u8 DS1621_REG_TEMP[3] = {
0xAA, /* input, word, RO */
0xA2, /* min, word, RW */
@ -59,6 +107,7 @@ static const u8 DS1621_REG_TEMP[3] = {
};
#define DS1621_REG_CONF 0xAC /* byte, RW */
#define DS1621_COM_START 0xEE /* no data */
#define DS1721_COM_START 0x51 /* no data */
#define DS1621_COM_STOP 0x22 /* no data */
/* The DS1621 configuration register */
@ -75,14 +124,37 @@ struct ds1621_data {
struct mutex update_lock;
char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */
enum chips kind; /* device type */
u16 temp[3]; /* Register values, word */
u8 conf; /* Register encoding, combined */
u8 zbits; /* Resolution encoded as number of
* zero bits */
u16 update_interval; /* Conversion rate in milliseconds */
};
static inline int DS1621_TEMP_FROM_REG(u16 reg)
{
return DIV_ROUND_CLOSEST(((s16)reg / 16) * 625, 10);
}
/*
* TEMP: 0.001C/bit (-55C to +125C)
* REG:
* - 1621, 1625: 0.5C/bit, 7 zero-bits
* - 1631, 1721, 1731: 0.0625C/bit, 4 zero-bits
*/
static inline u16 DS1621_TEMP_TO_REG(long temp, u8 zbits)
{
temp = clamp_val(temp, DS1621_TEMP_MIN, DS1621_TEMP_MAX);
temp = DIV_ROUND_CLOSEST(temp * (1 << (8 - zbits)), 1000) << zbits;
return temp;
}
static void ds1621_init_client(struct i2c_client *client)
{
u8 conf, new_conf;
u8 conf, new_conf, sreg, resol;
struct ds1621_data *data = i2c_get_clientdata(client);
new_conf = conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
/* switch to continuous conversion mode */
@ -97,8 +169,30 @@ static void ds1621_init_client(struct i2c_client *client)
if (conf != new_conf)
i2c_smbus_write_byte_data(client, DS1621_REG_CONF, new_conf);
switch (data->kind) {
case ds1625:
data->update_interval = DS1625_CONVERSION_MAX;
data->zbits = 7;
sreg = DS1621_COM_START;
break;
case ds1631:
case ds1721:
case ds1731:
resol = (new_conf & DS1621_REG_CONFIG_RESOL) >>
DS1621_REG_CONFIG_RESOL_SHIFT;
data->update_interval = ds1721_convrates[resol];
data->zbits = 7 - resol;
sreg = DS1721_COM_START;
break;
default:
data->update_interval = DS1621_CONVERSION_MAX;
data->zbits = 7;
sreg = DS1621_COM_START;
break;
}
/* start conversion */
i2c_smbus_write_byte(client, DS1621_COM_START);
i2c_smbus_write_byte(client, sreg);
}
static struct ds1621_data *ds1621_update_client(struct device *dev)
@ -109,8 +203,8 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
mutex_lock(&data->update_lock);
if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
|| !data->valid) {
if (time_after(jiffies, data->last_updated + data->update_interval) ||
!data->valid) {
int i;
dev_dbg(&client->dev, "Starting ds1621 update\n");
@ -146,7 +240,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
struct ds1621_data *data = ds1621_update_client(dev);
return sprintf(buf, "%d\n",
LM75_TEMP_FROM_REG(data->temp[attr->index]));
DS1621_TEMP_FROM_REG(data->temp[attr->index]));
}
static ssize_t set_temp(struct device *dev, struct device_attribute *da,
@ -163,7 +257,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
return err;
mutex_lock(&data->update_lock);
data->temp[attr->index] = LM75_TEMP_TO_REG(val);
data->temp[attr->index] = DS1621_TEMP_TO_REG(val, data->zbits);
i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
data->temp[attr->index]);
mutex_unlock(&data->update_lock);
@ -185,7 +279,47 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
return sprintf(buf, "%d\n", !!(data->conf & attr->index));
}
static ssize_t show_convrate(struct device *dev, struct device_attribute *da,
char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
return scnprintf(buf, PAGE_SIZE, "%hu\n", data->update_interval);
}
static ssize_t set_convrate(struct device *dev, struct device_attribute *da,
const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
unsigned long convrate;
s32 err;
int resol = 0;
err = kstrtoul(buf, 10, &convrate);
if (err)
return err;
/* Convert rate into resolution bits */
while (resol < (ARRAY_SIZE(ds1721_convrates) - 1) &&
convrate > ds1721_convrates[resol])
resol++;
mutex_lock(&data->update_lock);
data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
data->conf &= ~DS1621_REG_CONFIG_RESOL;
data->conf |= (resol << DS1621_REG_CONFIG_RESOL_SHIFT);
i2c_smbus_write_byte_data(client, DS1621_REG_CONF, data->conf);
data->update_interval = ds1721_convrates[resol];
mutex_unlock(&data->update_lock);
return count;
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_convrate,
set_convrate);
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp, set_temp, 1);
static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp, set_temp, 2);
@ -201,48 +335,29 @@ static struct attribute *ds1621_attributes[] = {
&sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
&sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
&dev_attr_alarms.attr,
&dev_attr_update_interval.attr,
NULL
};
static umode_t ds1621_attribute_visible(struct kobject *kobj,
struct attribute *attr, int index)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct i2c_client *client = to_i2c_client(dev);
struct ds1621_data *data = i2c_get_clientdata(client);
if (attr == &dev_attr_update_interval.attr)
if (data->kind == ds1621 || data->kind == ds1625)
/* shhh, we're hiding update_interval */
return 0;
return attr->mode;
}
static const struct attribute_group ds1621_group = {
.attrs = ds1621_attributes,
.is_visible = ds1621_attribute_visible
};
/* Return 0 if detection is successful, -ENODEV otherwise */
static int ds1621_detect(struct i2c_client *client,
struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
int conf, temp;
int i;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
| I2C_FUNC_SMBUS_WORD_DATA
| I2C_FUNC_SMBUS_WRITE_BYTE))
return -ENODEV;
/*
* Now, we do the remaining detection. It is lousy.
*
* The NVB bit should be low if no EEPROM write has been requested
* during the latest 10ms, which is highly improbable in our case.
*/
conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
if (conf < 0 || conf & DS1621_REG_CONFIG_NVB)
return -ENODEV;
/* The 7 lowest bits of a temperature should always be 0. */
for (i = 0; i < ARRAY_SIZE(DS1621_REG_TEMP); i++) {
temp = i2c_smbus_read_word_data(client, DS1621_REG_TEMP[i]);
if (temp < 0 || (temp & 0x7f00))
return -ENODEV;
}
strlcpy(info->type, "ds1621", I2C_NAME_SIZE);
return 0;
}
static int ds1621_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@ -257,6 +372,8 @@ static int ds1621_probe(struct i2c_client *client,
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);
data->kind = id->driver_data;
/* Initialize the DS1621 chip */
ds1621_init_client(client);
@ -289,8 +406,11 @@ static int ds1621_remove(struct i2c_client *client)
}
static const struct i2c_device_id ds1621_id[] = {
{ "ds1621", 0 },
{ "ds1625", 0 },
{ "ds1621", ds1621 },
{ "ds1625", ds1625 },
{ "ds1631", ds1631 },
{ "ds1721", ds1721 },
{ "ds1731", ds1731 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ds1621_id);
@ -304,8 +424,6 @@ static struct i2c_driver ds1621_driver = {
.probe = ds1621_probe,
.remove = ds1621_remove,
.id_table = ds1621_id,
.detect = ds1621_detect,
.address_list = normal_i2c,
};
module_i2c_driver(ds1621_driver);

1149
drivers/hwmon/g762.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -556,7 +556,6 @@ static int i5k_amb_probe(struct platform_device *pdev)
err_init_failed:
iounmap(data->amb_mmio);
platform_set_drvdata(pdev, NULL);
err_map_failed:
release_mem_region(data->amb_base, data->amb_len);
err:
@ -576,7 +575,6 @@ static int i5k_amb_remove(struct platform_device *pdev)
kfree(data->attrs);
iounmap(data->amb_mmio);
release_mem_region(data->amb_base, data->amb_len);
platform_set_drvdata(pdev, NULL);
kfree(data);
return 0;
}

View File

@ -180,6 +180,7 @@ static struct of_device_id iio_hwmon_of_match[] = {
{ .compatible = "iio-hwmon", },
{ }
};
MODULE_DEVICE_TABLE(of, iio_hwmon_of_match);
static struct platform_driver __refdata iio_hwmon_driver = {
.driver = {

View File

@ -34,6 +34,7 @@
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/jiffies.h>
#include <linux/of.h>
#include <linux/platform_data/ina2xx.h>
@ -221,6 +222,7 @@ static int ina2xx_probe(struct i2c_client *client,
struct ina2xx_data *data;
struct ina2xx_platform_data *pdata;
int ret;
u32 val;
long shunt = 10000; /* default shunt value 10mOhms */
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
@ -234,6 +236,9 @@ static int ina2xx_probe(struct i2c_client *client,
pdata =
(struct ina2xx_platform_data *)client->dev.platform_data;
shunt = pdata->shunt_uohms;
} else if (!of_property_read_u32(client->dev.of_node,
"shunt-resistor", &val)) {
shunt = val;
}
if (shunt <= 0)

View File

@ -199,7 +199,7 @@ static const s8 NCT6775_ALARM_BITS[] = {
0, 1, 2, 3, 8, 21, 20, 16, /* in0.. in7 */
17, -1, -1, -1, -1, -1, -1, /* in8..in14 */
-1, /* unused */
6, 7, 11, 10, 23, /* fan1..fan5 */
6, 7, 11, -1, -1, /* fan1..fan5 */
-1, -1, -1, /* unused */
4, 5, 13, -1, -1, -1, /* temp1..temp6 */
12, -1 }; /* intrusion0, intrusion1 */
@ -625,6 +625,7 @@ struct nct6775_data {
u8 has_fan_min; /* some fans don't have min register */
bool has_fan_div;
u8 num_temp_alarms; /* 2 or 3 */
u8 temp_fixed_num; /* 3 or 6 */
u8 temp_type[NUM_TEMP_FIXED];
s8 temp_offset[NUM_TEMP_FIXED];
@ -1193,6 +1194,42 @@ show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
(unsigned int)((data->alarms >> nr) & 0x01));
}
static int find_temp_source(struct nct6775_data *data, int index, int count)
{
int source = data->temp_src[index];
int nr;
for (nr = 0; nr < count; nr++) {
int src;
src = nct6775_read_value(data,
data->REG_TEMP_SOURCE[nr]) & 0x1f;
if (src == source)
return nr;
}
return -1;
}
static ssize_t
show_temp_alarm(struct device *dev, struct device_attribute *attr, char *buf)
{
struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
struct nct6775_data *data = nct6775_update_device(dev);
unsigned int alarm = 0;
int nr;
/*
* For temperatures, there is no fixed mapping from registers to alarm
* bits. Alarm bits are determined by the temperature source mapping.
*/
nr = find_temp_source(data, sattr->index, data->num_temp_alarms);
if (nr >= 0) {
int bit = data->ALARM_BITS[nr + TEMP_ALARM_BASE];
alarm = (data->alarms >> bit) & 0x01;
}
return sprintf(buf, "%u\n", alarm);
}
static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in_reg, NULL, 0, 0);
static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in_reg, NULL, 1, 0);
static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in_reg, NULL, 2, 0);
@ -1874,22 +1911,18 @@ static struct sensor_device_attribute sda_temp_type[] = {
};
static struct sensor_device_attribute sda_temp_alarm[] = {
SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE),
SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE + 1),
SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE + 2),
SENSOR_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE + 3),
SENSOR_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE + 4),
SENSOR_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
TEMP_ALARM_BASE + 5),
SENSOR_ATTR(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0),
SENSOR_ATTR(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 1),
SENSOR_ATTR(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 2),
SENSOR_ATTR(temp4_alarm, S_IRUGO, show_temp_alarm, NULL, 3),
SENSOR_ATTR(temp5_alarm, S_IRUGO, show_temp_alarm, NULL, 4),
SENSOR_ATTR(temp6_alarm, S_IRUGO, show_temp_alarm, NULL, 5),
SENSOR_ATTR(temp7_alarm, S_IRUGO, show_temp_alarm, NULL, 6),
SENSOR_ATTR(temp8_alarm, S_IRUGO, show_temp_alarm, NULL, 7),
SENSOR_ATTR(temp9_alarm, S_IRUGO, show_temp_alarm, NULL, 8),
SENSOR_ATTR(temp10_alarm, S_IRUGO, show_temp_alarm, NULL, 9),
};
#define NUM_TEMP_ALARM ARRAY_SIZE(sda_temp_alarm)
static ssize_t
show_pwm_mode(struct device *dev, struct device_attribute *attr, char *buf)
{
@ -3215,13 +3248,11 @@ static void nct6775_device_remove_files(struct device *dev)
device_remove_file(dev, &sda_temp_max[i].dev_attr);
device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
device_remove_file(dev, &sda_temp_crit[i].dev_attr);
device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
if (!(data->have_temp_fixed & (1 << i)))
continue;
device_remove_file(dev, &sda_temp_type[i].dev_attr);
device_remove_file(dev, &sda_temp_offset[i].dev_attr);
if (i >= NUM_TEMP_ALARM)
continue;
device_remove_file(dev, &sda_temp_alarm[i].dev_attr);
}
device_remove_file(dev, &sda_caseopen[0].dev_attr);
@ -3419,6 +3450,7 @@ static int nct6775_probe(struct platform_device *pdev)
data->auto_pwm_num = 6;
data->has_fan_div = true;
data->temp_fixed_num = 3;
data->num_temp_alarms = 3;
data->ALARM_BITS = NCT6775_ALARM_BITS;
@ -3483,6 +3515,7 @@ static int nct6775_probe(struct platform_device *pdev)
data->auto_pwm_num = 4;
data->has_fan_div = false;
data->temp_fixed_num = 3;
data->num_temp_alarms = 3;
data->ALARM_BITS = NCT6776_ALARM_BITS;
@ -3547,6 +3580,7 @@ static int nct6775_probe(struct platform_device *pdev)
data->auto_pwm_num = 4;
data->has_fan_div = false;
data->temp_fixed_num = 6;
data->num_temp_alarms = 2;
data->ALARM_BITS = NCT6779_ALARM_BITS;
@ -3843,10 +3877,12 @@ static int nct6775_probe(struct platform_device *pdev)
&sda_fan_input[i].dev_attr);
if (err)
goto exit_remove;
if (data->ALARM_BITS[FAN_ALARM_BASE + i] >= 0) {
err = device_create_file(dev,
&sda_fan_alarm[i].dev_attr);
if (err)
goto exit_remove;
}
if (data->kind != nct6776 &&
data->kind != nct6779) {
err = device_create_file(dev,
@ -3897,6 +3933,12 @@ static int nct6775_probe(struct platform_device *pdev)
if (err)
goto exit_remove;
}
if (find_temp_source(data, i, data->num_temp_alarms) >= 0) {
err = device_create_file(dev,
&sda_temp_alarm[i].dev_attr);
if (err)
goto exit_remove;
}
if (!(data->have_temp_fixed & (1 << i)))
continue;
err = device_create_file(dev, &sda_temp_type[i].dev_attr);
@ -3905,12 +3947,6 @@ static int nct6775_probe(struct platform_device *pdev)
err = device_create_file(dev, &sda_temp_offset[i].dev_attr);
if (err)
goto exit_remove;
if (i >= NUM_TEMP_ALARM ||
data->ALARM_BITS[TEMP_ALARM_BASE + i] < 0)
continue;
err = device_create_file(dev, &sda_temp_alarm[i].dev_attr);
if (err)
goto exit_remove;
}
for (i = 0; i < ARRAY_SIZE(sda_caseopen); i++) {

View File

@ -514,7 +514,6 @@ static int ntc_thermistor_remove(struct platform_device *pdev)
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&data->dev->kobj, &ntc_attr_group);
ntc_iio_channel_release(pdata);
platform_set_drvdata(pdev, NULL);
return 0;
}

View File

@ -2598,7 +2598,6 @@ static int w83627ehf_probe(struct platform_device *pdev)
exit_remove:
w83627ehf_device_remove_files(dev);
exit_release:
platform_set_drvdata(pdev, NULL);
release_region(res->start, IOREGION_LENGTH);
exit:
return err;
@ -2611,7 +2610,6 @@ static int w83627ehf_remove(struct platform_device *pdev)
hwmon_device_unregister(data->hwmon_dev);
w83627ehf_device_remove_files(&pdev->dev);
release_region(data->addr, IOREGION_LENGTH);
platform_set_drvdata(pdev, NULL);
return 0;
}

View File

@ -0,0 +1,37 @@
/*
* Platform data structure for g762 fan controller driver
*
* Copyright (C) 2013, Arnaud EBALARD <arno@natisbad.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LINUX_PLATFORM_DATA_G762_H__
#define __LINUX_PLATFORM_DATA_G762_H__
/*
* Following structure can be used to set g762 driver platform specific data
* during board init. Note that passing a sparse structure is possible but
* will result in non-specified attributes to be set to default value, hence
* overloading those installed during boot (e.g. by u-boot).
*/
struct g762_platform_data {
u32 fan_startv;
u32 fan_gear_mode;
u32 pwm_polarity;
u32 clk_freq;
};
#endif /* __LINUX_PLATFORM_DATA_G762_H__ */