diff options
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/Kconfig | 29 | ||||
-rw-r--r-- | drivers/hwmon/Makefile | 2 | ||||
-rw-r--r-- | drivers/hwmon/adt7462.c | 2002 | ||||
-rw-r--r-- | drivers/hwmon/adt7470.c | 75 | ||||
-rw-r--r-- | drivers/hwmon/adt7473.c | 89 | ||||
-rw-r--r-- | drivers/hwmon/applesmc.c | 6 | ||||
-rw-r--r-- | drivers/hwmon/ibmaem.c | 18 | ||||
-rw-r--r-- | drivers/hwmon/lis3lv02d.c | 581 | ||||
-rw-r--r-- | drivers/hwmon/lis3lv02d.h | 149 | ||||
-rw-r--r-- | drivers/hwmon/lm85.c | 52 |
10 files changed, 2960 insertions, 43 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 6de1e0ffd391..c709e821f04b 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -159,6 +159,16 @@ config SENSORS_ADM9240 | |||
159 | This driver can also be built as a module. If so, the module | 159 | This driver can also be built as a module. If so, the module |
160 | will be called adm9240. | 160 | will be called adm9240. |
161 | 161 | ||
162 | config SENSORS_ADT7462 | ||
163 | tristate "Analog Devices ADT7462" | ||
164 | depends on I2C && EXPERIMENTAL | ||
165 | help | ||
166 | If you say yes here you get support for the Analog Devices | ||
167 | ADT7462 temperature monitoring chips. | ||
168 | |||
169 | This driver can also be built as a module. If so, the module | ||
170 | will be called adt7462. | ||
171 | |||
162 | config SENSORS_ADT7470 | 172 | config SENSORS_ADT7470 |
163 | tristate "Analog Devices ADT7470" | 173 | tristate "Analog Devices ADT7470" |
164 | depends on I2C && EXPERIMENTAL | 174 | depends on I2C && EXPERIMENTAL |
@@ -825,6 +835,25 @@ config SENSORS_HDAPS | |||
825 | Say Y here if you have an applicable laptop and want to experience | 835 | Say Y here if you have an applicable laptop and want to experience |
826 | the awesome power of hdaps. | 836 | the awesome power of hdaps. |
827 | 837 | ||
838 | config SENSORS_LIS3LV02D | ||
839 | tristate "STMicroeletronics LIS3LV02Dx three-axis digital accelerometer" | ||
840 | depends on ACPI && INPUT | ||
841 | default n | ||
842 | help | ||
843 | This driver provides support for the LIS3LV02Dx accelerometer. In | ||
844 | particular, it can be found in a number of HP laptops, which have the | ||
845 | "Mobile Data Protection System 3D" or "3D DriveGuard" feature. On such | ||
846 | systems the driver should load automatically (via ACPI). The | ||
847 | accelerometer might also be found in other systems, connected via SPI | ||
848 | or I2C. The accelerometer data is readable via | ||
849 | /sys/devices/platform/lis3lv02d. | ||
850 | |||
851 | This driver also provides an absolute input class device, allowing | ||
852 | the laptop to act as a pinball machine-esque joystick. | ||
853 | |||
854 | This driver can also be built as a module. If so, the module | ||
855 | will be called lis3lv02d. | ||
856 | |||
828 | config SENSORS_APPLESMC | 857 | config SENSORS_APPLESMC |
829 | tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" | 858 | tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)" |
830 | depends on INPUT && X86 | 859 | depends on INPUT && X86 |
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index 042d5a78622e..58fc5be5355d 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile | |||
@@ -25,6 +25,7 @@ obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o | |||
25 | obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o | 25 | obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o |
26 | obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o | 26 | obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o |
27 | obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o | 27 | obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o |
28 | obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o | ||
28 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o | 29 | obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o |
29 | obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o | 30 | obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o |
30 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o | 31 | obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o |
@@ -48,6 +49,7 @@ obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o | |||
48 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o | 49 | obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o |
49 | obj-$(CONFIG_SENSORS_IT87) += it87.o | 50 | obj-$(CONFIG_SENSORS_IT87) += it87.o |
50 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o | 51 | obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o |
52 | obj-$(CONFIG_SENSORS_LIS3LV02D) += lis3lv02d.o | ||
51 | obj-$(CONFIG_SENSORS_LM63) += lm63.o | 53 | obj-$(CONFIG_SENSORS_LM63) += lm63.o |
52 | obj-$(CONFIG_SENSORS_LM70) += lm70.o | 54 | obj-$(CONFIG_SENSORS_LM70) += lm70.o |
53 | obj-$(CONFIG_SENSORS_LM75) += lm75.o | 55 | obj-$(CONFIG_SENSORS_LM75) += lm75.o |
diff --git a/drivers/hwmon/adt7462.c b/drivers/hwmon/adt7462.c new file mode 100644 index 000000000000..66107b4dc12a --- /dev/null +++ b/drivers/hwmon/adt7462.c | |||
@@ -0,0 +1,2002 @@ | |||
1 | /* | ||
2 | * A hwmon driver for the Analog Devices ADT7462 | ||
3 | * Copyright (C) 2008 IBM | ||
4 | * | ||
5 | * Author: Darrick J. Wong <djwong@us.ibm.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/jiffies.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/hwmon.h> | ||
26 | #include <linux/hwmon-sysfs.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/mutex.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/log2.h> | ||
31 | |||
32 | /* Addresses to scan */ | ||
33 | static const unsigned short normal_i2c[] = { 0x58, 0x5C, I2C_CLIENT_END }; | ||
34 | |||
35 | /* Insmod parameters */ | ||
36 | I2C_CLIENT_INSMOD_1(adt7462); | ||
37 | |||
38 | /* ADT7462 registers */ | ||
39 | #define ADT7462_REG_DEVICE 0x3D | ||
40 | #define ADT7462_REG_VENDOR 0x3E | ||
41 | #define ADT7462_REG_REVISION 0x3F | ||
42 | |||
43 | #define ADT7462_REG_MIN_TEMP_BASE_ADDR 0x44 | ||
44 | #define ADT7462_REG_MIN_TEMP_MAX_ADDR 0x47 | ||
45 | #define ADT7462_REG_MAX_TEMP_BASE_ADDR 0x48 | ||
46 | #define ADT7462_REG_MAX_TEMP_MAX_ADDR 0x4B | ||
47 | #define ADT7462_REG_TEMP_BASE_ADDR 0x88 | ||
48 | #define ADT7462_REG_TEMP_MAX_ADDR 0x8F | ||
49 | |||
50 | #define ADT7462_REG_FAN_BASE_ADDR 0x98 | ||
51 | #define ADT7462_REG_FAN_MAX_ADDR 0x9F | ||
52 | #define ADT7462_REG_FAN2_BASE_ADDR 0xA2 | ||
53 | #define ADT7462_REG_FAN2_MAX_ADDR 0xA9 | ||
54 | #define ADT7462_REG_FAN_ENABLE 0x07 | ||
55 | #define ADT7462_REG_FAN_MIN_BASE_ADDR 0x78 | ||
56 | #define ADT7462_REG_FAN_MIN_MAX_ADDR 0x7F | ||
57 | |||
58 | #define ADT7462_REG_CFG2 0x02 | ||
59 | #define ADT7462_FSPD_MASK 0x20 | ||
60 | |||
61 | #define ADT7462_REG_PWM_BASE_ADDR 0xAA | ||
62 | #define ADT7462_REG_PWM_MAX_ADDR 0xAD | ||
63 | #define ADT7462_REG_PWM_MIN_BASE_ADDR 0x28 | ||
64 | #define ADT7462_REG_PWM_MIN_MAX_ADDR 0x2B | ||
65 | #define ADT7462_REG_PWM_MAX 0x2C | ||
66 | #define ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR 0x5C | ||
67 | #define ADT7462_REG_PWM_TEMP_MIN_MAX_ADDR 0x5F | ||
68 | #define ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR 0x60 | ||
69 | #define ADT7462_REG_PWM_TEMP_RANGE_MAX_ADDR 0x63 | ||
70 | #define ADT7462_PWM_HYST_MASK 0x0F | ||
71 | #define ADT7462_PWM_RANGE_MASK 0xF0 | ||
72 | #define ADT7462_PWM_RANGE_SHIFT 4 | ||
73 | #define ADT7462_REG_PWM_CFG_BASE_ADDR 0x21 | ||
74 | #define ADT7462_REG_PWM_CFG_MAX_ADDR 0x24 | ||
75 | #define ADT7462_PWM_CHANNEL_MASK 0xE0 | ||
76 | #define ADT7462_PWM_CHANNEL_SHIFT 5 | ||
77 | |||
78 | #define ADT7462_REG_PIN_CFG_BASE_ADDR 0x10 | ||
79 | #define ADT7462_REG_PIN_CFG_MAX_ADDR 0x13 | ||
80 | #define ADT7462_PIN7_INPUT 0x01 /* cfg0 */ | ||
81 | #define ADT7462_DIODE3_INPUT 0x20 | ||
82 | #define ADT7462_DIODE1_INPUT 0x40 | ||
83 | #define ADT7462_VID_INPUT 0x80 | ||
84 | #define ADT7462_PIN22_INPUT 0x04 /* cfg1 */ | ||
85 | #define ADT7462_PIN21_INPUT 0x08 | ||
86 | #define ADT7462_PIN19_INPUT 0x10 | ||
87 | #define ADT7462_PIN15_INPUT 0x20 | ||
88 | #define ADT7462_PIN13_INPUT 0x40 | ||
89 | #define ADT7462_PIN8_INPUT 0x80 | ||
90 | #define ADT7462_PIN23_MASK 0x03 | ||
91 | #define ADT7462_PIN23_SHIFT 0 | ||
92 | #define ADT7462_PIN26_MASK 0x0C /* cfg2 */ | ||
93 | #define ADT7462_PIN26_SHIFT 2 | ||
94 | #define ADT7462_PIN25_MASK 0x30 | ||
95 | #define ADT7462_PIN25_SHIFT 4 | ||
96 | #define ADT7462_PIN24_MASK 0xC0 | ||
97 | #define ADT7462_PIN24_SHIFT 6 | ||
98 | #define ADT7462_PIN26_VOLT_INPUT 0x08 | ||
99 | #define ADT7462_PIN25_VOLT_INPUT 0x20 | ||
100 | #define ADT7462_PIN28_SHIFT 6 /* cfg3 */ | ||
101 | #define ADT7462_PIN28_VOLT 0x5 | ||
102 | |||
103 | #define ADT7462_REG_ALARM1 0xB8 | ||
104 | #define ADT7462_LT_ALARM 0x02 | ||
105 | #define ADT7462_R1T_ALARM 0x04 | ||
106 | #define ADT7462_R2T_ALARM 0x08 | ||
107 | #define ADT7462_R3T_ALARM 0x10 | ||
108 | #define ADT7462_REG_ALARM2 0xBB | ||
109 | #define ADT7462_V0_ALARM 0x01 | ||
110 | #define ADT7462_V1_ALARM 0x02 | ||
111 | #define ADT7462_V2_ALARM 0x04 | ||
112 | #define ADT7462_V3_ALARM 0x08 | ||
113 | #define ADT7462_V4_ALARM 0x10 | ||
114 | #define ADT7462_V5_ALARM 0x20 | ||
115 | #define ADT7462_V6_ALARM 0x40 | ||
116 | #define ADT7462_V7_ALARM 0x80 | ||
117 | #define ADT7462_REG_ALARM3 0xBC | ||
118 | #define ADT7462_V8_ALARM 0x08 | ||
119 | #define ADT7462_V9_ALARM 0x10 | ||
120 | #define ADT7462_V10_ALARM 0x20 | ||
121 | #define ADT7462_V11_ALARM 0x40 | ||
122 | #define ADT7462_V12_ALARM 0x80 | ||
123 | #define ADT7462_REG_ALARM4 0xBD | ||
124 | #define ADT7462_F0_ALARM 0x01 | ||
125 | #define ADT7462_F1_ALARM 0x02 | ||
126 | #define ADT7462_F2_ALARM 0x04 | ||
127 | #define ADT7462_F3_ALARM 0x08 | ||
128 | #define ADT7462_F4_ALARM 0x10 | ||
129 | #define ADT7462_F5_ALARM 0x20 | ||
130 | #define ADT7462_F6_ALARM 0x40 | ||
131 | #define ADT7462_F7_ALARM 0x80 | ||
132 | #define ADT7462_ALARM1 0x0000 | ||
133 | #define ADT7462_ALARM2 0x0100 | ||
134 | #define ADT7462_ALARM3 0x0200 | ||
135 | #define ADT7462_ALARM4 0x0300 | ||
136 | #define ADT7462_ALARM_REG_SHIFT 8 | ||
137 | #define ADT7462_ALARM_FLAG_MASK 0x0F | ||
138 | |||
139 | #define ADT7462_TEMP_COUNT 4 | ||
140 | #define ADT7462_TEMP_REG(x) (ADT7462_REG_TEMP_BASE_ADDR + (x * 2)) | ||
141 | #define ADT7462_TEMP_MIN_REG(x) (ADT7462_REG_MIN_TEMP_BASE_ADDR + (x)) | ||
142 | #define ADT7462_TEMP_MAX_REG(x) (ADT7462_REG_MAX_TEMP_BASE_ADDR + (x)) | ||
143 | #define TEMP_FRAC_OFFSET 6 | ||
144 | |||
145 | #define ADT7462_FAN_COUNT 8 | ||
146 | #define ADT7462_REG_FAN_MIN(x) (ADT7462_REG_FAN_MIN_BASE_ADDR + (x)) | ||
147 | |||
148 | #define ADT7462_PWM_COUNT 4 | ||
149 | #define ADT7462_REG_PWM(x) (ADT7462_REG_PWM_BASE_ADDR + (x)) | ||
150 | #define ADT7462_REG_PWM_MIN(x) (ADT7462_REG_PWM_MIN_BASE_ADDR + (x)) | ||
151 | #define ADT7462_REG_PWM_TMIN(x) \ | ||
152 | (ADT7462_REG_PWM_TEMP_MIN_BASE_ADDR + (x)) | ||
153 | #define ADT7462_REG_PWM_TRANGE(x) \ | ||
154 | (ADT7462_REG_PWM_TEMP_RANGE_BASE_ADDR + (x)) | ||
155 | |||
156 | #define ADT7462_PIN_CFG_REG_COUNT 4 | ||
157 | #define ADT7462_REG_PIN_CFG(x) (ADT7462_REG_PIN_CFG_BASE_ADDR + (x)) | ||
158 | #define ADT7462_REG_PWM_CFG(x) (ADT7462_REG_PWM_CFG_BASE_ADDR + (x)) | ||
159 | |||
160 | #define ADT7462_ALARM_REG_COUNT 4 | ||
161 | |||
162 | /* | ||
163 | * The chip can measure 13 different voltage sources: | ||
164 | * | ||
165 | * 1. +12V1 (pin 7) | ||
166 | * 2. Vccp1/+2.5V/+1.8V/+1.5V (pin 23) | ||
167 | * 3. +12V3 (pin 22) | ||
168 | * 4. +5V (pin 21) | ||
169 | * 5. +1.25V/+0.9V (pin 19) | ||
170 | * 6. +2.5V/+1.8V (pin 15) | ||
171 | * 7. +3.3v (pin 13) | ||
172 | * 8. +12V2 (pin 8) | ||
173 | * 9. Vbatt/FSB_Vtt (pin 26) | ||
174 | * A. +3.3V/+1.2V1 (pin 25) | ||
175 | * B. Vccp2/+2.5V/+1.8V/+1.5V (pin 24) | ||
176 | * C. +1.5V ICH (only if BOTH pin 28/29 are set to +1.5V) | ||
177 | * D. +1.5V 3GPIO (only if BOTH pin 28/29 are set to +1.5V) | ||
178 | * | ||
179 | * Each of these 13 has a factor to convert raw to voltage. Even better, | ||
180 | * the pins can be connected to other sensors (tach/gpio/hot/etc), which | ||
181 | * makes the bookkeeping tricky. | ||
182 | * | ||
183 | * Some, but not all, of these voltages have low/high limits. | ||
184 | */ | ||
185 | #define ADT7462_VOLT_COUNT 12 | ||
186 | |||
187 | #define ADT7462_VENDOR 0x41 | ||
188 | #define ADT7462_DEVICE 0x62 | ||
189 | /* datasheet only mentions a revision 4 */ | ||
190 | #define ADT7462_REVISION 0x04 | ||
191 | |||
192 | /* How often do we reread sensors values? (In jiffies) */ | ||
193 | #define SENSOR_REFRESH_INTERVAL (2 * HZ) | ||
194 | |||
195 | /* How often do we reread sensor limit values? (In jiffies) */ | ||
196 | #define LIMIT_REFRESH_INTERVAL (60 * HZ) | ||
197 | |||
198 | /* datasheet says to divide this number by the fan reading to get fan rpm */ | ||
199 | #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x)) | ||
200 | #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM | ||
201 | #define FAN_PERIOD_INVALID 65535 | ||
202 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | ||
203 | |||
204 | #define MASK_AND_SHIFT(value, prefix) \ | ||
205 | (((value) & prefix##_MASK) >> prefix##_SHIFT) | ||
206 | |||
207 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
208 | |||
209 | struct adt7462_data { | ||
210 | struct device *hwmon_dev; | ||
211 | struct attribute_group attrs; | ||
212 | struct mutex lock; | ||
213 | char sensors_valid; | ||
214 | char limits_valid; | ||
215 | unsigned long sensors_last_updated; /* In jiffies */ | ||
216 | unsigned long limits_last_updated; /* In jiffies */ | ||
217 | |||
218 | u8 temp[ADT7462_TEMP_COUNT]; | ||
219 | /* bits 6-7 are quarter pieces of temp */ | ||
220 | u8 temp_frac[ADT7462_TEMP_COUNT]; | ||
221 | u8 temp_min[ADT7462_TEMP_COUNT]; | ||
222 | u8 temp_max[ADT7462_TEMP_COUNT]; | ||
223 | u16 fan[ADT7462_FAN_COUNT]; | ||
224 | u8 fan_enabled; | ||
225 | u8 fan_min[ADT7462_FAN_COUNT]; | ||
226 | u8 cfg2; | ||
227 | u8 pwm[ADT7462_PWM_COUNT]; | ||
228 | u8 pin_cfg[ADT7462_PIN_CFG_REG_COUNT]; | ||
229 | u8 voltages[ADT7462_VOLT_COUNT]; | ||
230 | u8 volt_max[ADT7462_VOLT_COUNT]; | ||
231 | u8 volt_min[ADT7462_VOLT_COUNT]; | ||
232 | u8 pwm_min[ADT7462_PWM_COUNT]; | ||
233 | u8 pwm_tmin[ADT7462_PWM_COUNT]; | ||
234 | u8 pwm_trange[ADT7462_PWM_COUNT]; | ||
235 | u8 pwm_max; /* only one per chip */ | ||
236 | u8 pwm_cfg[ADT7462_PWM_COUNT]; | ||
237 | u8 alarms[ADT7462_ALARM_REG_COUNT]; | ||
238 | }; | ||
239 | |||
240 | static int adt7462_probe(struct i2c_client *client, | ||
241 | const struct i2c_device_id *id); | ||
242 | static int adt7462_detect(struct i2c_client *client, int kind, | ||
243 | struct i2c_board_info *info); | ||
244 | static int adt7462_remove(struct i2c_client *client); | ||
245 | |||
246 | static const struct i2c_device_id adt7462_id[] = { | ||
247 | { "adt7462", adt7462 }, | ||
248 | { } | ||
249 | }; | ||
250 | MODULE_DEVICE_TABLE(i2c, adt7462_id); | ||
251 | |||
252 | static struct i2c_driver adt7462_driver = { | ||
253 | .class = I2C_CLASS_HWMON, | ||
254 | .driver = { | ||
255 | .name = "adt7462", | ||
256 | }, | ||
257 | .probe = adt7462_probe, | ||
258 | .remove = adt7462_remove, | ||
259 | .id_table = adt7462_id, | ||
260 | .detect = adt7462_detect, | ||
261 | .address_data = &addr_data, | ||
262 | }; | ||
263 | |||
264 | /* | ||
265 | * 16-bit registers on the ADT7462 are low-byte first. The data sheet says | ||
266 | * that the low byte must be read before the high byte. | ||
267 | */ | ||
268 | static inline int adt7462_read_word_data(struct i2c_client *client, u8 reg) | ||
269 | { | ||
270 | u16 foo; | ||
271 | foo = i2c_smbus_read_byte_data(client, reg); | ||
272 | foo |= ((u16)i2c_smbus_read_byte_data(client, reg + 1) << 8); | ||
273 | return foo; | ||
274 | } | ||
275 | |||
276 | /* For some reason these registers are not contiguous. */ | ||
277 | static int ADT7462_REG_FAN(int fan) | ||
278 | { | ||
279 | if (fan < 4) | ||
280 | return ADT7462_REG_FAN_BASE_ADDR + (2 * fan); | ||
281 | return ADT7462_REG_FAN2_BASE_ADDR + (2 * (fan - 4)); | ||
282 | } | ||
283 | |||
284 | /* Voltage registers are scattered everywhere */ | ||
285 | static int ADT7462_REG_VOLT_MAX(struct adt7462_data *data, int which) | ||
286 | { | ||
287 | switch (which) { | ||
288 | case 0: | ||
289 | if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) | ||
290 | return 0x7C; | ||
291 | break; | ||
292 | case 1: | ||
293 | return 0x69; | ||
294 | case 2: | ||
295 | if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) | ||
296 | return 0x7F; | ||
297 | break; | ||
298 | case 3: | ||
299 | if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) | ||
300 | return 0x7E; | ||
301 | break; | ||
302 | case 4: | ||
303 | if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) | ||
304 | return 0x4B; | ||
305 | break; | ||
306 | case 5: | ||
307 | if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) | ||
308 | return 0x49; | ||
309 | break; | ||
310 | case 6: | ||
311 | if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) | ||
312 | return 0x68; | ||
313 | break; | ||
314 | case 7: | ||
315 | if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) | ||
316 | return 0x7D; | ||
317 | break; | ||
318 | case 8: | ||
319 | if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) | ||
320 | return 0x6C; | ||
321 | break; | ||
322 | case 9: | ||
323 | if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) | ||
324 | return 0x6B; | ||
325 | break; | ||
326 | case 10: | ||
327 | return 0x6A; | ||
328 | case 11: | ||
329 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
330 | ADT7462_PIN28_VOLT && | ||
331 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
332 | return 0x50; | ||
333 | break; | ||
334 | case 12: | ||
335 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
336 | ADT7462_PIN28_VOLT && | ||
337 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
338 | return 0x4C; | ||
339 | break; | ||
340 | } | ||
341 | return -ENODEV; | ||
342 | } | ||
343 | |||
344 | static int ADT7462_REG_VOLT_MIN(struct adt7462_data *data, int which) | ||
345 | { | ||
346 | switch (which) { | ||
347 | case 0: | ||
348 | if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) | ||
349 | return 0x6D; | ||
350 | break; | ||
351 | case 1: | ||
352 | return 0x72; | ||
353 | case 2: | ||
354 | if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) | ||
355 | return 0x6F; | ||
356 | break; | ||
357 | case 3: | ||
358 | if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) | ||
359 | return 0x71; | ||
360 | break; | ||
361 | case 4: | ||
362 | if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) | ||
363 | return 0x47; | ||
364 | break; | ||
365 | case 5: | ||
366 | if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) | ||
367 | return 0x45; | ||
368 | break; | ||
369 | case 6: | ||
370 | if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) | ||
371 | return 0x70; | ||
372 | break; | ||
373 | case 7: | ||
374 | if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) | ||
375 | return 0x6E; | ||
376 | break; | ||
377 | case 8: | ||
378 | if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) | ||
379 | return 0x75; | ||
380 | break; | ||
381 | case 9: | ||
382 | if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) | ||
383 | return 0x74; | ||
384 | break; | ||
385 | case 10: | ||
386 | return 0x73; | ||
387 | case 11: | ||
388 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
389 | ADT7462_PIN28_VOLT && | ||
390 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
391 | return 0x76; | ||
392 | break; | ||
393 | case 12: | ||
394 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
395 | ADT7462_PIN28_VOLT && | ||
396 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
397 | return 0x77; | ||
398 | break; | ||
399 | } | ||
400 | return -ENODEV; | ||
401 | } | ||
402 | |||
403 | static int ADT7462_REG_VOLT(struct adt7462_data *data, int which) | ||
404 | { | ||
405 | switch (which) { | ||
406 | case 0: | ||
407 | if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) | ||
408 | return 0xA3; | ||
409 | break; | ||
410 | case 1: | ||
411 | return 0x90; | ||
412 | case 2: | ||
413 | if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) | ||
414 | return 0xA9; | ||
415 | break; | ||
416 | case 3: | ||
417 | if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) | ||
418 | return 0xA7; | ||
419 | break; | ||
420 | case 4: | ||
421 | if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) | ||
422 | return 0x8F; | ||
423 | break; | ||
424 | case 5: | ||
425 | if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) | ||
426 | return 0x8B; | ||
427 | break; | ||
428 | case 6: | ||
429 | if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) | ||
430 | return 0x96; | ||
431 | break; | ||
432 | case 7: | ||
433 | if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) | ||
434 | return 0xA5; | ||
435 | break; | ||
436 | case 8: | ||
437 | if (!(data->pin_cfg[2] & ADT7462_PIN26_VOLT_INPUT)) | ||
438 | return 0x93; | ||
439 | break; | ||
440 | case 9: | ||
441 | if (!(data->pin_cfg[2] & ADT7462_PIN25_VOLT_INPUT)) | ||
442 | return 0x92; | ||
443 | break; | ||
444 | case 10: | ||
445 | return 0x91; | ||
446 | case 11: | ||
447 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
448 | ADT7462_PIN28_VOLT && | ||
449 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
450 | return 0x94; | ||
451 | break; | ||
452 | case 12: | ||
453 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
454 | ADT7462_PIN28_VOLT && | ||
455 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
456 | return 0x95; | ||
457 | break; | ||
458 | } | ||
459 | return -ENODEV; | ||
460 | } | ||
461 | |||
462 | /* Provide labels for sysfs */ | ||
463 | static const char *voltage_label(struct adt7462_data *data, int which) | ||
464 | { | ||
465 | switch (which) { | ||
466 | case 0: | ||
467 | if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) | ||
468 | return "+12V1"; | ||
469 | break; | ||
470 | case 1: | ||
471 | switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) { | ||
472 | case 0: | ||
473 | return "Vccp1"; | ||
474 | case 1: | ||
475 | return "+2.5V"; | ||
476 | case 2: | ||
477 | return "+1.8V"; | ||
478 | case 3: | ||
479 | return "+1.5V"; | ||
480 | } | ||
481 | case 2: | ||
482 | if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) | ||
483 | return "+12V3"; | ||
484 | break; | ||
485 | case 3: | ||
486 | if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) | ||
487 | return "+5V"; | ||
488 | break; | ||
489 | case 4: | ||
490 | if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) { | ||
491 | if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) | ||
492 | return "+0.9V"; | ||
493 | return "+1.25V"; | ||
494 | } | ||
495 | break; | ||
496 | case 5: | ||
497 | if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) { | ||
498 | if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) | ||
499 | return "+1.8V"; | ||
500 | return "+2.5V"; | ||
501 | } | ||
502 | break; | ||
503 | case 6: | ||
504 | if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) | ||
505 | return "+3.3V"; | ||
506 | break; | ||
507 | case 7: | ||
508 | if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) | ||
509 | return "+12V2"; | ||
510 | break; | ||
511 | case 8: | ||
512 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) { | ||
513 | case 0: | ||
514 | return "Vbatt"; | ||
515 | case 1: | ||
516 | return "FSB_Vtt"; | ||
517 | } | ||
518 | break; | ||
519 | case 9: | ||
520 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) { | ||
521 | case 0: | ||
522 | return "+3.3V"; | ||
523 | case 1: | ||
524 | return "+1.2V1"; | ||
525 | } | ||
526 | break; | ||
527 | case 10: | ||
528 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) { | ||
529 | case 0: | ||
530 | return "Vccp2"; | ||
531 | case 1: | ||
532 | return "+2.5V"; | ||
533 | case 2: | ||
534 | return "+1.8V"; | ||
535 | case 3: | ||
536 | return "+1.5"; | ||
537 | } | ||
538 | case 11: | ||
539 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
540 | ADT7462_PIN28_VOLT && | ||
541 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
542 | return "+1.5V ICH"; | ||
543 | break; | ||
544 | case 12: | ||
545 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
546 | ADT7462_PIN28_VOLT && | ||
547 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
548 | return "+1.5V 3GPIO"; | ||
549 | break; | ||
550 | } | ||
551 | return "N/A"; | ||
552 | } | ||
553 | |||
554 | /* Multipliers are actually in uV, not mV. */ | ||
555 | static int voltage_multiplier(struct adt7462_data *data, int which) | ||
556 | { | ||
557 | switch (which) { | ||
558 | case 0: | ||
559 | if (!(data->pin_cfg[0] & ADT7462_PIN7_INPUT)) | ||
560 | return 62500; | ||
561 | break; | ||
562 | case 1: | ||
563 | switch (MASK_AND_SHIFT(data->pin_cfg[1], ADT7462_PIN23)) { | ||
564 | case 0: | ||
565 | if (data->pin_cfg[0] & ADT7462_VID_INPUT) | ||
566 | return 12500; | ||
567 | return 6250; | ||
568 | case 1: | ||
569 | return 13000; | ||
570 | case 2: | ||
571 | return 9400; | ||
572 | case 3: | ||
573 | return 7800; | ||
574 | } | ||
575 | case 2: | ||
576 | if (!(data->pin_cfg[1] & ADT7462_PIN22_INPUT)) | ||
577 | return 62500; | ||
578 | break; | ||
579 | case 3: | ||
580 | if (!(data->pin_cfg[1] & ADT7462_PIN21_INPUT)) | ||
581 | return 26000; | ||
582 | break; | ||
583 | case 4: | ||
584 | if (!(data->pin_cfg[0] & ADT7462_DIODE3_INPUT)) { | ||
585 | if (data->pin_cfg[1] & ADT7462_PIN19_INPUT) | ||
586 | return 4690; | ||
587 | return 6500; | ||
588 | } | ||
589 | break; | ||
590 | case 5: | ||
591 | if (!(data->pin_cfg[0] & ADT7462_DIODE1_INPUT)) { | ||
592 | if (data->pin_cfg[1] & ADT7462_PIN15_INPUT) | ||
593 | return 9400; | ||
594 | return 13000; | ||
595 | } | ||
596 | break; | ||
597 | case 6: | ||
598 | if (!(data->pin_cfg[1] & ADT7462_PIN13_INPUT)) | ||
599 | return 17200; | ||
600 | break; | ||
601 | case 7: | ||
602 | if (!(data->pin_cfg[1] & ADT7462_PIN8_INPUT)) | ||
603 | return 62500; | ||
604 | break; | ||
605 | case 8: | ||
606 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN26)) { | ||
607 | case 0: | ||
608 | return 15600; | ||
609 | case 1: | ||
610 | return 6250; | ||
611 | } | ||
612 | break; | ||
613 | case 9: | ||
614 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN25)) { | ||
615 | case 0: | ||
616 | return 17200; | ||
617 | case 1: | ||
618 | return 6250; | ||
619 | } | ||
620 | break; | ||
621 | case 10: | ||
622 | switch (MASK_AND_SHIFT(data->pin_cfg[2], ADT7462_PIN24)) { | ||
623 | case 0: | ||
624 | return 6250; | ||
625 | case 1: | ||
626 | return 13000; | ||
627 | case 2: | ||
628 | return 9400; | ||
629 | case 3: | ||
630 | return 7800; | ||
631 | } | ||
632 | case 11: | ||
633 | case 12: | ||
634 | if (data->pin_cfg[3] >> ADT7462_PIN28_SHIFT == | ||
635 | ADT7462_PIN28_VOLT && | ||
636 | !(data->pin_cfg[0] & ADT7462_VID_INPUT)) | ||
637 | return 7800; | ||
638 | } | ||
639 | return 0; | ||
640 | } | ||
641 | |||
642 | static int temp_enabled(struct adt7462_data *data, int which) | ||
643 | { | ||
644 | switch (which) { | ||
645 | case 0: | ||
646 | case 2: | ||
647 | return 1; | ||
648 | case 1: | ||
649 | if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT) | ||
650 | return 1; | ||
651 | break; | ||
652 | case 3: | ||
653 | if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT) | ||
654 | return 1; | ||
655 | break; | ||
656 | } | ||
657 | return 0; | ||
658 | } | ||
659 | |||
660 | static const char *temp_label(struct adt7462_data *data, int which) | ||
661 | { | ||
662 | switch (which) { | ||
663 | case 0: | ||
664 | return "local"; | ||
665 | case 1: | ||
666 | if (data->pin_cfg[0] & ADT7462_DIODE1_INPUT) | ||
667 | return "remote1"; | ||
668 | break; | ||
669 | case 2: | ||
670 | return "remote2"; | ||
671 | case 3: | ||
672 | if (data->pin_cfg[0] & ADT7462_DIODE3_INPUT) | ||
673 | return "remote3"; | ||
674 | break; | ||
675 | } | ||
676 | return "N/A"; | ||
677 | } | ||
678 | |||
679 | /* Map Trange register values to mC */ | ||
680 | #define NUM_TRANGE_VALUES 16 | ||
681 | static const int trange_values[NUM_TRANGE_VALUES] = { | ||
682 | 2000, | ||
683 | 2500, | ||
684 | 3300, | ||
685 | 4000, | ||
686 | 5000, | ||
687 | 6700, | ||
688 | 8000, | ||
689 | 10000, | ||
690 | 13300, | ||
691 | 16000, | ||
692 | 20000, | ||
693 | 26700, | ||
694 | 32000, | ||
695 | 40000, | ||
696 | 53300, | ||
697 | 80000 | ||
698 | }; | ||
699 | |||
700 | static int find_trange_value(int trange) | ||
701 | { | ||
702 | int i; | ||
703 | |||
704 | for (i = 0; i < NUM_TRANGE_VALUES; i++) | ||
705 | if (trange_values[i] == trange) | ||
706 | return i; | ||
707 | |||
708 | return -ENODEV; | ||
709 | } | ||
710 | |||
711 | static struct adt7462_data *adt7462_update_device(struct device *dev) | ||
712 | { | ||
713 | struct i2c_client *client = to_i2c_client(dev); | ||
714 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
715 | unsigned long local_jiffies = jiffies; | ||
716 | int i; | ||
717 | |||
718 | mutex_lock(&data->lock); | ||
719 | if (time_before(local_jiffies, data->sensors_last_updated + | ||
720 | SENSOR_REFRESH_INTERVAL) | ||
721 | && data->sensors_valid) | ||
722 | goto no_sensor_update; | ||
723 | |||
724 | for (i = 0; i < ADT7462_TEMP_COUNT; i++) { | ||
725 | /* | ||
726 | * Reading the fractional register locks the integral | ||
727 | * register until both have been read. | ||
728 | */ | ||
729 | data->temp_frac[i] = i2c_smbus_read_byte_data(client, | ||
730 | ADT7462_TEMP_REG(i)); | ||
731 | data->temp[i] = i2c_smbus_read_byte_data(client, | ||
732 | ADT7462_TEMP_REG(i) + 1); | ||
733 | } | ||
734 | |||
735 | for (i = 0; i < ADT7462_FAN_COUNT; i++) | ||
736 | data->fan[i] = adt7462_read_word_data(client, | ||
737 | ADT7462_REG_FAN(i)); | ||
738 | |||
739 | data->fan_enabled = i2c_smbus_read_byte_data(client, | ||
740 | ADT7462_REG_FAN_ENABLE); | ||
741 | |||
742 | for (i = 0; i < ADT7462_PWM_COUNT; i++) | ||
743 | data->pwm[i] = i2c_smbus_read_byte_data(client, | ||
744 | ADT7462_REG_PWM(i)); | ||
745 | |||
746 | for (i = 0; i < ADT7462_PIN_CFG_REG_COUNT; i++) | ||
747 | data->pin_cfg[i] = i2c_smbus_read_byte_data(client, | ||
748 | ADT7462_REG_PIN_CFG(i)); | ||
749 | |||
750 | for (i = 0; i < ADT7462_VOLT_COUNT; i++) { | ||
751 | int reg = ADT7462_REG_VOLT(data, i); | ||
752 | if (!reg) | ||
753 | data->voltages[i] = 0; | ||
754 | else | ||
755 | data->voltages[i] = i2c_smbus_read_byte_data(client, | ||
756 | reg); | ||
757 | } | ||
758 | |||
759 | data->alarms[0] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM1); | ||
760 | data->alarms[1] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM2); | ||
761 | data->alarms[2] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM3); | ||
762 | data->alarms[3] = i2c_smbus_read_byte_data(client, ADT7462_REG_ALARM4); | ||
763 | |||
764 | data->sensors_last_updated = local_jiffies; | ||
765 | data->sensors_valid = 1; | ||
766 | |||
767 | no_sensor_update: | ||
768 | if (time_before(local_jiffies, data->limits_last_updated + | ||
769 | LIMIT_REFRESH_INTERVAL) | ||
770 | && data->limits_valid) | ||
771 | goto out; | ||
772 | |||
773 | for (i = 0; i < ADT7462_TEMP_COUNT; i++) { | ||
774 | data->temp_min[i] = i2c_smbus_read_byte_data(client, | ||
775 | ADT7462_TEMP_MIN_REG(i)); | ||
776 | data->temp_max[i] = i2c_smbus_read_byte_data(client, | ||
777 | ADT7462_TEMP_MAX_REG(i)); | ||
778 | } | ||
779 | |||
780 | for (i = 0; i < ADT7462_FAN_COUNT; i++) | ||
781 | data->fan_min[i] = i2c_smbus_read_byte_data(client, | ||
782 | ADT7462_REG_FAN_MIN(i)); | ||
783 | |||
784 | for (i = 0; i < ADT7462_VOLT_COUNT; i++) { | ||
785 | int reg = ADT7462_REG_VOLT_MAX(data, i); | ||
786 | data->volt_max[i] = | ||
787 | (reg ? i2c_smbus_read_byte_data(client, reg) : 0); | ||
788 | |||
789 | reg = ADT7462_REG_VOLT_MIN(data, i); | ||
790 | data->volt_min[i] = | ||
791 | (reg ? i2c_smbus_read_byte_data(client, reg) : 0); | ||
792 | } | ||
793 | |||
794 | for (i = 0; i < ADT7462_PWM_COUNT; i++) { | ||
795 | data->pwm_min[i] = i2c_smbus_read_byte_data(client, | ||
796 | ADT7462_REG_PWM_MIN(i)); | ||
797 | data->pwm_tmin[i] = i2c_smbus_read_byte_data(client, | ||
798 | ADT7462_REG_PWM_TMIN(i)); | ||
799 | data->pwm_trange[i] = i2c_smbus_read_byte_data(client, | ||
800 | ADT7462_REG_PWM_TRANGE(i)); | ||
801 | data->pwm_cfg[i] = i2c_smbus_read_byte_data(client, | ||
802 | ADT7462_REG_PWM_CFG(i)); | ||
803 | } | ||
804 | |||
805 | data->pwm_max = i2c_smbus_read_byte_data(client, ADT7462_REG_PWM_MAX); | ||
806 | |||
807 | data->cfg2 = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2); | ||
808 | |||
809 | data->limits_last_updated = local_jiffies; | ||
810 | data->limits_valid = 1; | ||
811 | |||
812 | out: | ||
813 | mutex_unlock(&data->lock); | ||
814 | return data; | ||
815 | } | ||
816 | |||
817 | static ssize_t show_temp_min(struct device *dev, | ||
818 | struct device_attribute *devattr, | ||
819 | char *buf) | ||
820 | { | ||
821 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
822 | struct adt7462_data *data = adt7462_update_device(dev); | ||
823 | |||
824 | if (!temp_enabled(data, attr->index)) | ||
825 | return sprintf(buf, "0\n"); | ||
826 | |||
827 | return sprintf(buf, "%d\n", 1000 * (data->temp_min[attr->index] - 64)); | ||
828 | } | ||
829 | |||
830 | static ssize_t set_temp_min(struct device *dev, | ||
831 | struct device_attribute *devattr, | ||
832 | const char *buf, | ||
833 | size_t count) | ||
834 | { | ||
835 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
836 | struct i2c_client *client = to_i2c_client(dev); | ||
837 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
838 | long temp; | ||
839 | |||
840 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | ||
841 | return -EINVAL; | ||
842 | |||
843 | temp = ROUND_DIV(temp, 1000) + 64; | ||
844 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
845 | |||
846 | mutex_lock(&data->lock); | ||
847 | data->temp_min[attr->index] = temp; | ||
848 | i2c_smbus_write_byte_data(client, ADT7462_TEMP_MIN_REG(attr->index), | ||
849 | temp); | ||
850 | mutex_unlock(&data->lock); | ||
851 | |||
852 | return count; | ||
853 | } | ||
854 | |||
855 | static ssize_t show_temp_max(struct device *dev, | ||
856 | struct device_attribute *devattr, | ||
857 | char *buf) | ||
858 | { | ||
859 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
860 | struct adt7462_data *data = adt7462_update_device(dev); | ||
861 | |||
862 | if (!temp_enabled(data, attr->index)) | ||
863 | return sprintf(buf, "0\n"); | ||
864 | |||
865 | return sprintf(buf, "%d\n", 1000 * (data->temp_max[attr->index] - 64)); | ||
866 | } | ||
867 | |||
868 | static ssize_t set_temp_max(struct device *dev, | ||
869 | struct device_attribute *devattr, | ||
870 | const char *buf, | ||
871 | size_t count) | ||
872 | { | ||
873 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
874 | struct i2c_client *client = to_i2c_client(dev); | ||
875 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
876 | long temp; | ||
877 | |||
878 | if (strict_strtol(buf, 10, &temp) || !temp_enabled(data, attr->index)) | ||
879 | return -EINVAL; | ||
880 | |||
881 | temp = ROUND_DIV(temp, 1000) + 64; | ||
882 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
883 | |||
884 | mutex_lock(&data->lock); | ||
885 | data->temp_max[attr->index] = temp; | ||
886 | i2c_smbus_write_byte_data(client, ADT7462_TEMP_MAX_REG(attr->index), | ||
887 | temp); | ||
888 | mutex_unlock(&data->lock); | ||
889 | |||
890 | return count; | ||
891 | } | ||
892 | |||
893 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, | ||
894 | char *buf) | ||
895 | { | ||
896 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
897 | struct adt7462_data *data = adt7462_update_device(dev); | ||
898 | u8 frac = data->temp_frac[attr->index] >> TEMP_FRAC_OFFSET; | ||
899 | |||
900 | if (!temp_enabled(data, attr->index)) | ||
901 | return sprintf(buf, "0\n"); | ||
902 | |||
903 | return sprintf(buf, "%d\n", 1000 * (data->temp[attr->index] - 64) + | ||
904 | 250 * frac); | ||
905 | } | ||
906 | |||
907 | static ssize_t show_temp_label(struct device *dev, | ||
908 | struct device_attribute *devattr, | ||
909 | char *buf) | ||
910 | { | ||
911 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
912 | struct adt7462_data *data = adt7462_update_device(dev); | ||
913 | |||
914 | return sprintf(buf, "%s\n", temp_label(data, attr->index)); | ||
915 | } | ||
916 | |||
917 | static ssize_t show_volt_max(struct device *dev, | ||
918 | struct device_attribute *devattr, | ||
919 | char *buf) | ||
920 | { | ||
921 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
922 | struct adt7462_data *data = adt7462_update_device(dev); | ||
923 | int x = voltage_multiplier(data, attr->index); | ||
924 | |||
925 | x *= data->volt_max[attr->index]; | ||
926 | x /= 1000; /* convert from uV to mV */ | ||
927 | |||
928 | return sprintf(buf, "%d\n", x); | ||
929 | } | ||
930 | |||
931 | static ssize_t set_volt_max(struct device *dev, | ||
932 | struct device_attribute *devattr, | ||
933 | const char *buf, | ||
934 | size_t count) | ||
935 | { | ||
936 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
937 | struct i2c_client *client = to_i2c_client(dev); | ||
938 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
939 | int x = voltage_multiplier(data, attr->index); | ||
940 | long temp; | ||
941 | |||
942 | if (strict_strtol(buf, 10, &temp) || !x) | ||
943 | return -EINVAL; | ||
944 | |||
945 | temp *= 1000; /* convert mV to uV */ | ||
946 | temp = ROUND_DIV(temp, x); | ||
947 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
948 | |||
949 | mutex_lock(&data->lock); | ||
950 | data->volt_max[attr->index] = temp; | ||
951 | i2c_smbus_write_byte_data(client, | ||
952 | ADT7462_REG_VOLT_MAX(data, attr->index), | ||
953 | temp); | ||
954 | mutex_unlock(&data->lock); | ||
955 | |||
956 | return count; | ||
957 | } | ||
958 | |||
959 | static ssize_t show_volt_min(struct device *dev, | ||
960 | struct device_attribute *devattr, | ||
961 | char *buf) | ||
962 | { | ||
963 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
964 | struct adt7462_data *data = adt7462_update_device(dev); | ||
965 | int x = voltage_multiplier(data, attr->index); | ||
966 | |||
967 | x *= data->volt_min[attr->index]; | ||
968 | x /= 1000; /* convert from uV to mV */ | ||
969 | |||
970 | return sprintf(buf, "%d\n", x); | ||
971 | } | ||
972 | |||
973 | static ssize_t set_volt_min(struct device *dev, | ||
974 | struct device_attribute *devattr, | ||
975 | const char *buf, | ||
976 | size_t count) | ||
977 | { | ||
978 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
979 | struct i2c_client *client = to_i2c_client(dev); | ||
980 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
981 | int x = voltage_multiplier(data, attr->index); | ||
982 | long temp; | ||
983 | |||
984 | if (strict_strtol(buf, 10, &temp) || !x) | ||
985 | return -EINVAL; | ||
986 | |||
987 | temp *= 1000; /* convert mV to uV */ | ||
988 | temp = ROUND_DIV(temp, x); | ||
989 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
990 | |||
991 | mutex_lock(&data->lock); | ||
992 | data->volt_min[attr->index] = temp; | ||
993 | i2c_smbus_write_byte_data(client, | ||
994 | ADT7462_REG_VOLT_MIN(data, attr->index), | ||
995 | temp); | ||
996 | mutex_unlock(&data->lock); | ||
997 | |||
998 | return count; | ||
999 | } | ||
1000 | |||
1001 | static ssize_t show_voltage(struct device *dev, | ||
1002 | struct device_attribute *devattr, | ||
1003 | char *buf) | ||
1004 | { | ||
1005 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1006 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1007 | int x = voltage_multiplier(data, attr->index); | ||
1008 | |||
1009 | x *= data->voltages[attr->index]; | ||
1010 | x /= 1000; /* convert from uV to mV */ | ||
1011 | |||
1012 | return sprintf(buf, "%d\n", x); | ||
1013 | } | ||
1014 | |||
1015 | static ssize_t show_voltage_label(struct device *dev, | ||
1016 | struct device_attribute *devattr, | ||
1017 | char *buf) | ||
1018 | { | ||
1019 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1020 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1021 | |||
1022 | return sprintf(buf, "%s\n", voltage_label(data, attr->index)); | ||
1023 | } | ||
1024 | |||
1025 | static ssize_t show_alarm(struct device *dev, | ||
1026 | struct device_attribute *devattr, | ||
1027 | char *buf) | ||
1028 | { | ||
1029 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1030 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1031 | int reg = attr->index >> ADT7462_ALARM_REG_SHIFT; | ||
1032 | int mask = attr->index & ADT7462_ALARM_FLAG_MASK; | ||
1033 | |||
1034 | if (data->alarms[reg] & mask) | ||
1035 | return sprintf(buf, "1\n"); | ||
1036 | else | ||
1037 | return sprintf(buf, "0\n"); | ||
1038 | } | ||
1039 | |||
1040 | static int fan_enabled(struct adt7462_data *data, int fan) | ||
1041 | { | ||
1042 | return data->fan_enabled & (1 << fan); | ||
1043 | } | ||
1044 | |||
1045 | static ssize_t show_fan_min(struct device *dev, | ||
1046 | struct device_attribute *devattr, | ||
1047 | char *buf) | ||
1048 | { | ||
1049 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1050 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1051 | u16 temp; | ||
1052 | |||
1053 | /* Only the MSB of the min fan period is stored... */ | ||
1054 | temp = data->fan_min[attr->index]; | ||
1055 | temp <<= 8; | ||
1056 | |||
1057 | if (!fan_enabled(data, attr->index) || | ||
1058 | !FAN_DATA_VALID(temp)) | ||
1059 | return sprintf(buf, "0\n"); | ||
1060 | |||
1061 | return sprintf(buf, "%d\n", FAN_PERIOD_TO_RPM(temp)); | ||
1062 | } | ||
1063 | |||
1064 | static ssize_t set_fan_min(struct device *dev, | ||
1065 | struct device_attribute *devattr, | ||
1066 | const char *buf, size_t count) | ||
1067 | { | ||
1068 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1069 | struct i2c_client *client = to_i2c_client(dev); | ||
1070 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1071 | long temp; | ||
1072 | |||
1073 | if (strict_strtol(buf, 10, &temp) || !temp || | ||
1074 | !fan_enabled(data, attr->index)) | ||
1075 | return -EINVAL; | ||
1076 | |||
1077 | temp = FAN_RPM_TO_PERIOD(temp); | ||
1078 | temp >>= 8; | ||
1079 | temp = SENSORS_LIMIT(temp, 1, 255); | ||
1080 | |||
1081 | mutex_lock(&data->lock); | ||
1082 | data->fan_min[attr->index] = temp; | ||
1083 | i2c_smbus_write_byte_data(client, ADT7462_REG_FAN_MIN(attr->index), | ||
1084 | temp); | ||
1085 | mutex_unlock(&data->lock); | ||
1086 | |||
1087 | return count; | ||
1088 | } | ||
1089 | |||
1090 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, | ||
1091 | char *buf) | ||
1092 | { | ||
1093 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1094 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1095 | |||
1096 | if (!fan_enabled(data, attr->index) || | ||
1097 | !FAN_DATA_VALID(data->fan[attr->index])) | ||
1098 | return sprintf(buf, "0\n"); | ||
1099 | |||
1100 | return sprintf(buf, "%d\n", | ||
1101 | FAN_PERIOD_TO_RPM(data->fan[attr->index])); | ||
1102 | } | ||
1103 | |||
1104 | static ssize_t show_force_pwm_max(struct device *dev, | ||
1105 | struct device_attribute *devattr, | ||
1106 | char *buf) | ||
1107 | { | ||
1108 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1109 | return sprintf(buf, "%d\n", (data->cfg2 & ADT7462_FSPD_MASK ? 1 : 0)); | ||
1110 | } | ||
1111 | |||
1112 | static ssize_t set_force_pwm_max(struct device *dev, | ||
1113 | struct device_attribute *devattr, | ||
1114 | const char *buf, | ||
1115 | size_t count) | ||
1116 | { | ||
1117 | struct i2c_client *client = to_i2c_client(dev); | ||
1118 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1119 | long temp; | ||
1120 | u8 reg; | ||
1121 | |||
1122 | if (strict_strtol(buf, 10, &temp)) | ||
1123 | return -EINVAL; | ||
1124 | |||
1125 | mutex_lock(&data->lock); | ||
1126 | reg = i2c_smbus_read_byte_data(client, ADT7462_REG_CFG2); | ||
1127 | if (temp) | ||
1128 | reg |= ADT7462_FSPD_MASK; | ||
1129 | else | ||
1130 | reg &= ~ADT7462_FSPD_MASK; | ||
1131 | data->cfg2 = reg; | ||
1132 | i2c_smbus_write_byte_data(client, ADT7462_REG_CFG2, reg); | ||
1133 | mutex_unlock(&data->lock); | ||
1134 | |||
1135 | return count; | ||
1136 | } | ||
1137 | |||
1138 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, | ||
1139 | char *buf) | ||
1140 | { | ||
1141 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1142 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1143 | return sprintf(buf, "%d\n", data->pwm[attr->index]); | ||
1144 | } | ||
1145 | |||
1146 | static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | ||
1147 | const char *buf, size_t count) | ||
1148 | { | ||
1149 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1150 | struct i2c_client *client = to_i2c_client(dev); | ||
1151 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1152 | long temp; | ||
1153 | |||
1154 | if (strict_strtol(buf, 10, &temp)) | ||
1155 | return -EINVAL; | ||
1156 | |||
1157 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
1158 | |||
1159 | mutex_lock(&data->lock); | ||
1160 | data->pwm[attr->index] = temp; | ||
1161 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM(attr->index), temp); | ||
1162 | mutex_unlock(&data->lock); | ||
1163 | |||
1164 | return count; | ||
1165 | } | ||
1166 | |||
1167 | static ssize_t show_pwm_max(struct device *dev, | ||
1168 | struct device_attribute *devattr, | ||
1169 | char *buf) | ||
1170 | { | ||
1171 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1172 | return sprintf(buf, "%d\n", data->pwm_max); | ||
1173 | } | ||
1174 | |||
1175 | static ssize_t set_pwm_max(struct device *dev, | ||
1176 | struct device_attribute *devattr, | ||
1177 | const char *buf, | ||
1178 | size_t count) | ||
1179 | { | ||
1180 | struct i2c_client *client = to_i2c_client(dev); | ||
1181 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1182 | long temp; | ||
1183 | |||
1184 | if (strict_strtol(buf, 10, &temp)) | ||
1185 | return -EINVAL; | ||
1186 | |||
1187 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
1188 | |||
1189 | mutex_lock(&data->lock); | ||
1190 | data->pwm_max = temp; | ||
1191 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MAX, temp); | ||
1192 | mutex_unlock(&data->lock); | ||
1193 | |||
1194 | return count; | ||
1195 | } | ||
1196 | |||
1197 | static ssize_t show_pwm_min(struct device *dev, | ||
1198 | struct device_attribute *devattr, | ||
1199 | char *buf) | ||
1200 | { | ||
1201 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1202 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1203 | return sprintf(buf, "%d\n", data->pwm_min[attr->index]); | ||
1204 | } | ||
1205 | |||
1206 | static ssize_t set_pwm_min(struct device *dev, | ||
1207 | struct device_attribute *devattr, | ||
1208 | const char *buf, | ||
1209 | size_t count) | ||
1210 | { | ||
1211 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1212 | struct i2c_client *client = to_i2c_client(dev); | ||
1213 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1214 | long temp; | ||
1215 | |||
1216 | if (strict_strtol(buf, 10, &temp)) | ||
1217 | return -EINVAL; | ||
1218 | |||
1219 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
1220 | |||
1221 | mutex_lock(&data->lock); | ||
1222 | data->pwm_min[attr->index] = temp; | ||
1223 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_MIN(attr->index), | ||
1224 | temp); | ||
1225 | mutex_unlock(&data->lock); | ||
1226 | |||
1227 | return count; | ||
1228 | } | ||
1229 | |||
1230 | static ssize_t show_pwm_hyst(struct device *dev, | ||
1231 | struct device_attribute *devattr, | ||
1232 | char *buf) | ||
1233 | { | ||
1234 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1235 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1236 | return sprintf(buf, "%d\n", 1000 * | ||
1237 | (data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK)); | ||
1238 | } | ||
1239 | |||
1240 | static ssize_t set_pwm_hyst(struct device *dev, | ||
1241 | struct device_attribute *devattr, | ||
1242 | const char *buf, | ||
1243 | size_t count) | ||
1244 | { | ||
1245 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1246 | struct i2c_client *client = to_i2c_client(dev); | ||
1247 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1248 | long temp; | ||
1249 | |||
1250 | if (strict_strtol(buf, 10, &temp)) | ||
1251 | return -EINVAL; | ||
1252 | |||
1253 | temp = ROUND_DIV(temp, 1000); | ||
1254 | temp = SENSORS_LIMIT(temp, 0, 15); | ||
1255 | |||
1256 | /* package things up */ | ||
1257 | temp &= ADT7462_PWM_HYST_MASK; | ||
1258 | temp |= data->pwm_trange[attr->index] & ADT7462_PWM_RANGE_MASK; | ||
1259 | |||
1260 | mutex_lock(&data->lock); | ||
1261 | data->pwm_trange[attr->index] = temp; | ||
1262 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index), | ||
1263 | temp); | ||
1264 | mutex_unlock(&data->lock); | ||
1265 | |||
1266 | return count; | ||
1267 | } | ||
1268 | |||
1269 | static ssize_t show_pwm_tmax(struct device *dev, | ||
1270 | struct device_attribute *devattr, | ||
1271 | char *buf) | ||
1272 | { | ||
1273 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1274 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1275 | |||
1276 | /* tmax = tmin + trange */ | ||
1277 | int trange = trange_values[data->pwm_trange[attr->index] >> | ||
1278 | ADT7462_PWM_RANGE_SHIFT]; | ||
1279 | int tmin = (data->pwm_tmin[attr->index] - 64) * 1000; | ||
1280 | |||
1281 | return sprintf(buf, "%d\n", tmin + trange); | ||
1282 | } | ||
1283 | |||
1284 | static ssize_t set_pwm_tmax(struct device *dev, | ||
1285 | struct device_attribute *devattr, | ||
1286 | const char *buf, | ||
1287 | size_t count) | ||
1288 | { | ||
1289 | int temp; | ||
1290 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1291 | struct i2c_client *client = to_i2c_client(dev); | ||
1292 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1293 | int tmin, trange_value; | ||
1294 | long trange; | ||
1295 | |||
1296 | if (strict_strtol(buf, 10, &trange)) | ||
1297 | return -EINVAL; | ||
1298 | |||
1299 | /* trange = tmax - tmin */ | ||
1300 | tmin = (data->pwm_tmin[attr->index] - 64) * 1000; | ||
1301 | trange_value = find_trange_value(trange - tmin); | ||
1302 | |||
1303 | if (trange_value < 0) | ||
1304 | return -EINVAL; | ||
1305 | |||
1306 | temp = trange_value << ADT7462_PWM_RANGE_SHIFT; | ||
1307 | temp |= data->pwm_trange[attr->index] & ADT7462_PWM_HYST_MASK; | ||
1308 | |||
1309 | mutex_lock(&data->lock); | ||
1310 | data->pwm_trange[attr->index] = temp; | ||
1311 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TRANGE(attr->index), | ||
1312 | temp); | ||
1313 | mutex_unlock(&data->lock); | ||
1314 | |||
1315 | return count; | ||
1316 | } | ||
1317 | |||
1318 | static ssize_t show_pwm_tmin(struct device *dev, | ||
1319 | struct device_attribute *devattr, | ||
1320 | char *buf) | ||
1321 | { | ||
1322 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1323 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1324 | return sprintf(buf, "%d\n", 1000 * (data->pwm_tmin[attr->index] - 64)); | ||
1325 | } | ||
1326 | |||
1327 | static ssize_t set_pwm_tmin(struct device *dev, | ||
1328 | struct device_attribute *devattr, | ||
1329 | const char *buf, | ||
1330 | size_t count) | ||
1331 | { | ||
1332 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1333 | struct i2c_client *client = to_i2c_client(dev); | ||
1334 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1335 | long temp; | ||
1336 | |||
1337 | if (strict_strtol(buf, 10, &temp)) | ||
1338 | return -EINVAL; | ||
1339 | |||
1340 | temp = ROUND_DIV(temp, 1000) + 64; | ||
1341 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
1342 | |||
1343 | mutex_lock(&data->lock); | ||
1344 | data->pwm_tmin[attr->index] = temp; | ||
1345 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_TMIN(attr->index), | ||
1346 | temp); | ||
1347 | mutex_unlock(&data->lock); | ||
1348 | |||
1349 | return count; | ||
1350 | } | ||
1351 | |||
1352 | static ssize_t show_pwm_auto(struct device *dev, | ||
1353 | struct device_attribute *devattr, | ||
1354 | char *buf) | ||
1355 | { | ||
1356 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1357 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1358 | int cfg = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT; | ||
1359 | |||
1360 | switch (cfg) { | ||
1361 | case 4: /* off */ | ||
1362 | return sprintf(buf, "0\n"); | ||
1363 | case 7: /* manual */ | ||
1364 | return sprintf(buf, "1\n"); | ||
1365 | default: /* automatic */ | ||
1366 | return sprintf(buf, "2\n"); | ||
1367 | } | ||
1368 | } | ||
1369 | |||
1370 | static void set_pwm_channel(struct i2c_client *client, | ||
1371 | struct adt7462_data *data, | ||
1372 | int which, | ||
1373 | int value) | ||
1374 | { | ||
1375 | int temp = data->pwm_cfg[which] & ~ADT7462_PWM_CHANNEL_MASK; | ||
1376 | temp |= value << ADT7462_PWM_CHANNEL_SHIFT; | ||
1377 | |||
1378 | mutex_lock(&data->lock); | ||
1379 | data->pwm_cfg[which] = temp; | ||
1380 | i2c_smbus_write_byte_data(client, ADT7462_REG_PWM_CFG(which), temp); | ||
1381 | mutex_unlock(&data->lock); | ||
1382 | } | ||
1383 | |||
1384 | static ssize_t set_pwm_auto(struct device *dev, | ||
1385 | struct device_attribute *devattr, | ||
1386 | const char *buf, | ||
1387 | size_t count) | ||
1388 | { | ||
1389 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1390 | struct i2c_client *client = to_i2c_client(dev); | ||
1391 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1392 | long temp; | ||
1393 | |||
1394 | if (strict_strtol(buf, 10, &temp)) | ||
1395 | return -EINVAL; | ||
1396 | |||
1397 | switch (temp) { | ||
1398 | case 0: /* off */ | ||
1399 | set_pwm_channel(client, data, attr->index, 4); | ||
1400 | return count; | ||
1401 | case 1: /* manual */ | ||
1402 | set_pwm_channel(client, data, attr->index, 7); | ||
1403 | return count; | ||
1404 | default: | ||
1405 | return -EINVAL; | ||
1406 | } | ||
1407 | } | ||
1408 | |||
1409 | static ssize_t show_pwm_auto_temp(struct device *dev, | ||
1410 | struct device_attribute *devattr, | ||
1411 | char *buf) | ||
1412 | { | ||
1413 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1414 | struct adt7462_data *data = adt7462_update_device(dev); | ||
1415 | int channel = data->pwm_cfg[attr->index] >> ADT7462_PWM_CHANNEL_SHIFT; | ||
1416 | |||
1417 | switch (channel) { | ||
1418 | case 0: /* temp[1234] only */ | ||
1419 | case 1: | ||
1420 | case 2: | ||
1421 | case 3: | ||
1422 | return sprintf(buf, "%d\n", (1 << channel)); | ||
1423 | case 5: /* temp1 & temp4 */ | ||
1424 | return sprintf(buf, "9\n"); | ||
1425 | case 6: | ||
1426 | return sprintf(buf, "15\n"); | ||
1427 | default: | ||
1428 | return sprintf(buf, "0\n"); | ||
1429 | } | ||
1430 | } | ||
1431 | |||
1432 | static int cvt_auto_temp(int input) | ||
1433 | { | ||
1434 | if (input == 0xF) | ||
1435 | return 6; | ||
1436 | if (input == 0x9) | ||
1437 | return 5; | ||
1438 | if (input < 1 || !is_power_of_2(input)) | ||
1439 | return -EINVAL; | ||
1440 | return ilog2(input); | ||
1441 | } | ||
1442 | |||
1443 | static ssize_t set_pwm_auto_temp(struct device *dev, | ||
1444 | struct device_attribute *devattr, | ||
1445 | const char *buf, | ||
1446 | size_t count) | ||
1447 | { | ||
1448 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
1449 | struct i2c_client *client = to_i2c_client(dev); | ||
1450 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1451 | long temp; | ||
1452 | |||
1453 | if (strict_strtol(buf, 10, &temp)) | ||
1454 | return -EINVAL; | ||
1455 | |||
1456 | temp = cvt_auto_temp(temp); | ||
1457 | if (temp < 0) | ||
1458 | return temp; | ||
1459 | |||
1460 | set_pwm_channel(client, data, attr->index, temp); | ||
1461 | |||
1462 | return count; | ||
1463 | } | ||
1464 | |||
1465 | static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
1466 | set_temp_max, 0); | ||
1467 | static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
1468 | set_temp_max, 1); | ||
1469 | static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
1470 | set_temp_max, 2); | ||
1471 | static SENSOR_DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_max, | ||
1472 | set_temp_max, 3); | ||
1473 | |||
1474 | static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
1475 | set_temp_min, 0); | ||
1476 | static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
1477 | set_temp_min, 1); | ||
1478 | static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
1479 | set_temp_min, 2); | ||
1480 | static SENSOR_DEVICE_ATTR(temp4_min, S_IWUSR | S_IRUGO, show_temp_min, | ||
1481 | set_temp_min, 3); | ||
1482 | |||
1483 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); | ||
1484 | static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); | ||
1485 | static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); | ||
1486 | static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3); | ||
1487 | |||
1488 | static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0); | ||
1489 | static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1); | ||
1490 | static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2); | ||
1491 | static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3); | ||
1492 | |||
1493 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, | ||
1494 | ADT7462_ALARM1 | ADT7462_LT_ALARM); | ||
1495 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, | ||
1496 | ADT7462_ALARM1 | ADT7462_R1T_ALARM); | ||
1497 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, | ||
1498 | ADT7462_ALARM1 | ADT7462_R2T_ALARM); | ||
1499 | static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, | ||
1500 | ADT7462_ALARM1 | ADT7462_R3T_ALARM); | ||
1501 | |||
1502 | static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1503 | set_volt_max, 0); | ||
1504 | static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1505 | set_volt_max, 1); | ||
1506 | static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1507 | set_volt_max, 2); | ||
1508 | static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1509 | set_volt_max, 3); | ||
1510 | static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1511 | set_volt_max, 4); | ||
1512 | static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1513 | set_volt_max, 5); | ||
1514 | static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1515 | set_volt_max, 6); | ||
1516 | static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1517 | set_volt_max, 7); | ||
1518 | static SENSOR_DEVICE_ATTR(in9_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1519 | set_volt_max, 8); | ||
1520 | static SENSOR_DEVICE_ATTR(in10_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1521 | set_volt_max, 9); | ||
1522 | static SENSOR_DEVICE_ATTR(in11_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1523 | set_volt_max, 10); | ||
1524 | static SENSOR_DEVICE_ATTR(in12_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1525 | set_volt_max, 11); | ||
1526 | static SENSOR_DEVICE_ATTR(in13_max, S_IWUSR | S_IRUGO, show_volt_max, | ||
1527 | set_volt_max, 12); | ||
1528 | |||
1529 | static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1530 | set_volt_min, 0); | ||
1531 | static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1532 | set_volt_min, 1); | ||
1533 | static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1534 | set_volt_min, 2); | ||
1535 | static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1536 | set_volt_min, 3); | ||
1537 | static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1538 | set_volt_min, 4); | ||
1539 | static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1540 | set_volt_min, 5); | ||
1541 | static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1542 | set_volt_min, 6); | ||
1543 | static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1544 | set_volt_min, 7); | ||
1545 | static SENSOR_DEVICE_ATTR(in9_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1546 | set_volt_min, 8); | ||
1547 | static SENSOR_DEVICE_ATTR(in10_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1548 | set_volt_min, 9); | ||
1549 | static SENSOR_DEVICE_ATTR(in11_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1550 | set_volt_min, 10); | ||
1551 | static SENSOR_DEVICE_ATTR(in12_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1552 | set_volt_min, 11); | ||
1553 | static SENSOR_DEVICE_ATTR(in13_min, S_IWUSR | S_IRUGO, show_volt_min, | ||
1554 | set_volt_min, 12); | ||
1555 | |||
1556 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 0); | ||
1557 | static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 1); | ||
1558 | static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 2); | ||
1559 | static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 3); | ||
1560 | static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 4); | ||
1561 | static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 5); | ||
1562 | static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 6); | ||
1563 | static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_voltage, NULL, 7); | ||
1564 | static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_voltage, NULL, 8); | ||
1565 | static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_voltage, NULL, 9); | ||
1566 | static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_voltage, NULL, 10); | ||
1567 | static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_voltage, NULL, 11); | ||
1568 | static SENSOR_DEVICE_ATTR(in13_input, S_IRUGO, show_voltage, NULL, 12); | ||
1569 | |||
1570 | static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, show_voltage_label, NULL, 0); | ||
1571 | static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, show_voltage_label, NULL, 1); | ||
1572 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_voltage_label, NULL, 2); | ||
1573 | static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_voltage_label, NULL, 3); | ||
1574 | static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_voltage_label, NULL, 4); | ||
1575 | static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_voltage_label, NULL, 5); | ||
1576 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_voltage_label, NULL, 6); | ||
1577 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_voltage_label, NULL, 7); | ||
1578 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_voltage_label, NULL, 8); | ||
1579 | static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, show_voltage_label, NULL, 9); | ||
1580 | static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, show_voltage_label, NULL, 10); | ||
1581 | static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, show_voltage_label, NULL, 11); | ||
1582 | static SENSOR_DEVICE_ATTR(in13_label, S_IRUGO, show_voltage_label, NULL, 12); | ||
1583 | |||
1584 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, | ||
1585 | ADT7462_ALARM2 | ADT7462_V0_ALARM); | ||
1586 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, | ||
1587 | ADT7462_ALARM2 | ADT7462_V7_ALARM); | ||
1588 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, | ||
1589 | ADT7462_ALARM2 | ADT7462_V2_ALARM); | ||
1590 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, | ||
1591 | ADT7462_ALARM2 | ADT7462_V6_ALARM); | ||
1592 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, | ||
1593 | ADT7462_ALARM2 | ADT7462_V5_ALARM); | ||
1594 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, | ||
1595 | ADT7462_ALARM2 | ADT7462_V4_ALARM); | ||
1596 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, | ||
1597 | ADT7462_ALARM2 | ADT7462_V3_ALARM); | ||
1598 | static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, | ||
1599 | ADT7462_ALARM2 | ADT7462_V1_ALARM); | ||
1600 | static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, | ||
1601 | ADT7462_ALARM3 | ADT7462_V10_ALARM); | ||
1602 | static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, | ||
1603 | ADT7462_ALARM3 | ADT7462_V9_ALARM); | ||
1604 | static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, | ||
1605 | ADT7462_ALARM3 | ADT7462_V8_ALARM); | ||
1606 | static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, | ||
1607 | ADT7462_ALARM3 | ADT7462_V11_ALARM); | ||
1608 | static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, | ||
1609 | ADT7462_ALARM3 | ADT7462_V12_ALARM); | ||
1610 | |||
1611 | static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1612 | set_fan_min, 0); | ||
1613 | static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1614 | set_fan_min, 1); | ||
1615 | static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1616 | set_fan_min, 2); | ||
1617 | static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1618 | set_fan_min, 3); | ||
1619 | static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1620 | set_fan_min, 4); | ||
1621 | static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1622 | set_fan_min, 5); | ||
1623 | static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1624 | set_fan_min, 6); | ||
1625 | static SENSOR_DEVICE_ATTR(fan8_min, S_IWUSR | S_IRUGO, show_fan_min, | ||
1626 | set_fan_min, 7); | ||
1627 | |||
1628 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); | ||
1629 | static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1); | ||
1630 | static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); | ||
1631 | static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); | ||
1632 | static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4); | ||
1633 | static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 5); | ||
1634 | static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 6); | ||
1635 | static SENSOR_DEVICE_ATTR(fan8_input, S_IRUGO, show_fan, NULL, 7); | ||
1636 | |||
1637 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, | ||
1638 | ADT7462_ALARM4 | ADT7462_F0_ALARM); | ||
1639 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, | ||
1640 | ADT7462_ALARM4 | ADT7462_F1_ALARM); | ||
1641 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, | ||
1642 | ADT7462_ALARM4 | ADT7462_F2_ALARM); | ||
1643 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, | ||
1644 | ADT7462_ALARM4 | ADT7462_F3_ALARM); | ||
1645 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, | ||
1646 | ADT7462_ALARM4 | ADT7462_F4_ALARM); | ||
1647 | static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, | ||
1648 | ADT7462_ALARM4 | ADT7462_F5_ALARM); | ||
1649 | static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, | ||
1650 | ADT7462_ALARM4 | ADT7462_F6_ALARM); | ||
1651 | static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL, | ||
1652 | ADT7462_ALARM4 | ADT7462_F7_ALARM); | ||
1653 | |||
1654 | static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO, | ||
1655 | show_force_pwm_max, set_force_pwm_max, 0); | ||
1656 | |||
1657 | static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0); | ||
1658 | static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1); | ||
1659 | static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2); | ||
1660 | static SENSOR_DEVICE_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 3); | ||
1661 | |||
1662 | static SENSOR_DEVICE_ATTR(pwm1_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
1663 | show_pwm_min, set_pwm_min, 0); | ||
1664 | static SENSOR_DEVICE_ATTR(pwm2_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
1665 | show_pwm_min, set_pwm_min, 1); | ||
1666 | static SENSOR_DEVICE_ATTR(pwm3_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
1667 | show_pwm_min, set_pwm_min, 2); | ||
1668 | static SENSOR_DEVICE_ATTR(pwm4_auto_point1_pwm, S_IWUSR | S_IRUGO, | ||
1669 | show_pwm_min, set_pwm_min, 3); | ||
1670 | |||
1671 | static SENSOR_DEVICE_ATTR(pwm1_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
1672 | show_pwm_max, set_pwm_max, 0); | ||
1673 | static SENSOR_DEVICE_ATTR(pwm2_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
1674 | show_pwm_max, set_pwm_max, 1); | ||
1675 | static SENSOR_DEVICE_ATTR(pwm3_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
1676 | show_pwm_max, set_pwm_max, 2); | ||
1677 | static SENSOR_DEVICE_ATTR(pwm4_auto_point2_pwm, S_IWUSR | S_IRUGO, | ||
1678 | show_pwm_max, set_pwm_max, 3); | ||
1679 | |||
1680 | static SENSOR_DEVICE_ATTR(temp1_auto_point1_hyst, S_IWUSR | S_IRUGO, | ||
1681 | show_pwm_hyst, set_pwm_hyst, 0); | ||
1682 | static SENSOR_DEVICE_ATTR(temp2_auto_point1_hyst, S_IWUSR | S_IRUGO, | ||
1683 | show_pwm_hyst, set_pwm_hyst, 1); | ||
1684 | static SENSOR_DEVICE_ATTR(temp3_auto_point1_hyst, S_IWUSR | S_IRUGO, | ||
1685 | show_pwm_hyst, set_pwm_hyst, 2); | ||
1686 | static SENSOR_DEVICE_ATTR(temp4_auto_point1_hyst, S_IWUSR | S_IRUGO, | ||
1687 | show_pwm_hyst, set_pwm_hyst, 3); | ||
1688 | |||
1689 | static SENSOR_DEVICE_ATTR(temp1_auto_point2_hyst, S_IWUSR | S_IRUGO, | ||
1690 | show_pwm_hyst, set_pwm_hyst, 0); | ||
1691 | static SENSOR_DEVICE_ATTR(temp2_auto_point2_hyst, S_IWUSR | S_IRUGO, | ||
1692 | show_pwm_hyst, set_pwm_hyst, 1); | ||
1693 | static SENSOR_DEVICE_ATTR(temp3_auto_point2_hyst, S_IWUSR | S_IRUGO, | ||
1694 | show_pwm_hyst, set_pwm_hyst, 2); | ||
1695 | static SENSOR_DEVICE_ATTR(temp4_auto_point2_hyst, S_IWUSR | S_IRUGO, | ||
1696 | show_pwm_hyst, set_pwm_hyst, 3); | ||
1697 | |||
1698 | static SENSOR_DEVICE_ATTR(temp1_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
1699 | show_pwm_tmin, set_pwm_tmin, 0); | ||
1700 | static SENSOR_DEVICE_ATTR(temp2_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
1701 | show_pwm_tmin, set_pwm_tmin, 1); | ||
1702 | static SENSOR_DEVICE_ATTR(temp3_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
1703 | show_pwm_tmin, set_pwm_tmin, 2); | ||
1704 | static SENSOR_DEVICE_ATTR(temp4_auto_point1_temp, S_IWUSR | S_IRUGO, | ||
1705 | show_pwm_tmin, set_pwm_tmin, 3); | ||
1706 | |||
1707 | static SENSOR_DEVICE_ATTR(temp1_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1708 | show_pwm_tmax, set_pwm_tmax, 0); | ||
1709 | static SENSOR_DEVICE_ATTR(temp2_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1710 | show_pwm_tmax, set_pwm_tmax, 1); | ||
1711 | static SENSOR_DEVICE_ATTR(temp3_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1712 | show_pwm_tmax, set_pwm_tmax, 2); | ||
1713 | static SENSOR_DEVICE_ATTR(temp4_auto_point2_temp, S_IWUSR | S_IRUGO, | ||
1714 | show_pwm_tmax, set_pwm_tmax, 3); | ||
1715 | |||
1716 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_auto, | ||
1717 | set_pwm_auto, 0); | ||
1718 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_auto, | ||
1719 | set_pwm_auto, 1); | ||
1720 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_auto, | ||
1721 | set_pwm_auto, 2); | ||
1722 | static SENSOR_DEVICE_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_auto, | ||
1723 | set_pwm_auto, 3); | ||
1724 | |||
1725 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1726 | show_pwm_auto_temp, set_pwm_auto_temp, 0); | ||
1727 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1728 | show_pwm_auto_temp, set_pwm_auto_temp, 1); | ||
1729 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1730 | show_pwm_auto_temp, set_pwm_auto_temp, 2); | ||
1731 | static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO, | ||
1732 | show_pwm_auto_temp, set_pwm_auto_temp, 3); | ||
1733 | |||
1734 | static struct attribute *adt7462_attr[] = | ||
1735 | { | ||
1736 | &sensor_dev_attr_temp1_max.dev_attr.attr, | ||
1737 | &sensor_dev_attr_temp2_max.dev_attr.attr, | ||
1738 | &sensor_dev_attr_temp3_max.dev_attr.attr, | ||
1739 | &sensor_dev_attr_temp4_max.dev_attr.attr, | ||
1740 | |||
1741 | &sensor_dev_attr_temp1_min.dev_attr.attr, | ||
1742 | &sensor_dev_attr_temp2_min.dev_attr.attr, | ||
1743 | &sensor_dev_attr_temp3_min.dev_attr.attr, | ||
1744 | &sensor_dev_attr_temp4_min.dev_attr.attr, | ||
1745 | |||
1746 | &sensor_dev_attr_temp1_input.dev_attr.attr, | ||
1747 | &sensor_dev_attr_temp2_input.dev_attr.attr, | ||
1748 | &sensor_dev_attr_temp3_input.dev_attr.attr, | ||
1749 | &sensor_dev_attr_temp4_input.dev_attr.attr, | ||
1750 | |||
1751 | &sensor_dev_attr_temp1_label.dev_attr.attr, | ||
1752 | &sensor_dev_attr_temp2_label.dev_attr.attr, | ||
1753 | &sensor_dev_attr_temp3_label.dev_attr.attr, | ||
1754 | &sensor_dev_attr_temp4_label.dev_attr.attr, | ||
1755 | |||
1756 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, | ||
1757 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, | ||
1758 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, | ||
1759 | &sensor_dev_attr_temp4_alarm.dev_attr.attr, | ||
1760 | |||
1761 | &sensor_dev_attr_in1_max.dev_attr.attr, | ||
1762 | &sensor_dev_attr_in2_max.dev_attr.attr, | ||
1763 | &sensor_dev_attr_in3_max.dev_attr.attr, | ||
1764 | &sensor_dev_attr_in4_max.dev_attr.attr, | ||
1765 | &sensor_dev_attr_in5_max.dev_attr.attr, | ||
1766 | &sensor_dev_attr_in6_max.dev_attr.attr, | ||
1767 | &sensor_dev_attr_in7_max.dev_attr.attr, | ||
1768 | &sensor_dev_attr_in8_max.dev_attr.attr, | ||
1769 | &sensor_dev_attr_in9_max.dev_attr.attr, | ||
1770 | &sensor_dev_attr_in10_max.dev_attr.attr, | ||
1771 | &sensor_dev_attr_in11_max.dev_attr.attr, | ||
1772 | &sensor_dev_attr_in12_max.dev_attr.attr, | ||
1773 | &sensor_dev_attr_in13_max.dev_attr.attr, | ||
1774 | |||
1775 | &sensor_dev_attr_in1_min.dev_attr.attr, | ||
1776 | &sensor_dev_attr_in2_min.dev_attr.attr, | ||
1777 | &sensor_dev_attr_in3_min.dev_attr.attr, | ||
1778 | &sensor_dev_attr_in4_min.dev_attr.attr, | ||
1779 | &sensor_dev_attr_in5_min.dev_attr.attr, | ||
1780 | &sensor_dev_attr_in6_min.dev_attr.attr, | ||
1781 | &sensor_dev_attr_in7_min.dev_attr.attr, | ||
1782 | &sensor_dev_attr_in8_min.dev_attr.attr, | ||
1783 | &sensor_dev_attr_in9_min.dev_attr.attr, | ||
1784 | &sensor_dev_attr_in10_min.dev_attr.attr, | ||
1785 | &sensor_dev_attr_in11_min.dev_attr.attr, | ||
1786 | &sensor_dev_attr_in12_min.dev_attr.attr, | ||
1787 | &sensor_dev_attr_in13_min.dev_attr.attr, | ||
1788 | |||
1789 | &sensor_dev_attr_in1_input.dev_attr.attr, | ||
1790 | &sensor_dev_attr_in2_input.dev_attr.attr, | ||
1791 | &sensor_dev_attr_in3_input.dev_attr.attr, | ||
1792 | &sensor_dev_attr_in4_input.dev_attr.attr, | ||
1793 | &sensor_dev_attr_in5_input.dev_attr.attr, | ||
1794 | &sensor_dev_attr_in6_input.dev_attr.attr, | ||
1795 | &sensor_dev_attr_in7_input.dev_attr.attr, | ||
1796 | &sensor_dev_attr_in8_input.dev_attr.attr, | ||
1797 | &sensor_dev_attr_in9_input.dev_attr.attr, | ||
1798 | &sensor_dev_attr_in10_input.dev_attr.attr, | ||
1799 | &sensor_dev_attr_in11_input.dev_attr.attr, | ||
1800 | &sensor_dev_attr_in12_input.dev_attr.attr, | ||
1801 | &sensor_dev_attr_in13_input.dev_attr.attr, | ||
1802 | |||
1803 | &sensor_dev_attr_in1_label.dev_attr.attr, | ||
1804 | &sensor_dev_attr_in2_label.dev_attr.attr, | ||
1805 | &sensor_dev_attr_in3_label.dev_attr.attr, | ||
1806 | &sensor_dev_attr_in4_label.dev_attr.attr, | ||
1807 | &sensor_dev_attr_in5_label.dev_attr.attr, | ||
1808 | &sensor_dev_attr_in6_label.dev_attr.attr, | ||
1809 | &sensor_dev_attr_in7_label.dev_attr.attr, | ||
1810 | &sensor_dev_attr_in8_label.dev_attr.attr, | ||
1811 | &sensor_dev_attr_in9_label.dev_attr.attr, | ||
1812 | &sensor_dev_attr_in10_label.dev_attr.attr, | ||
1813 | &sensor_dev_attr_in11_label.dev_attr.attr, | ||
1814 | &sensor_dev_attr_in12_label.dev_attr.attr, | ||
1815 | &sensor_dev_attr_in13_label.dev_attr.attr, | ||
1816 | |||
1817 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | ||
1818 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | ||
1819 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | ||
1820 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | ||
1821 | &sensor_dev_attr_in5_alarm.dev_attr.attr, | ||
1822 | &sensor_dev_attr_in6_alarm.dev_attr.attr, | ||
1823 | &sensor_dev_attr_in7_alarm.dev_attr.attr, | ||
1824 | &sensor_dev_attr_in8_alarm.dev_attr.attr, | ||
1825 | &sensor_dev_attr_in9_alarm.dev_attr.attr, | ||
1826 | &sensor_dev_attr_in10_alarm.dev_attr.attr, | ||
1827 | &sensor_dev_attr_in11_alarm.dev_attr.attr, | ||
1828 | &sensor_dev_attr_in12_alarm.dev_attr.attr, | ||
1829 | &sensor_dev_attr_in13_alarm.dev_attr.attr, | ||
1830 | |||
1831 | &sensor_dev_attr_fan1_min.dev_attr.attr, | ||
1832 | &sensor_dev_attr_fan2_min.dev_attr.attr, | ||
1833 | &sensor_dev_attr_fan3_min.dev_attr.attr, | ||
1834 | &sensor_dev_attr_fan4_min.dev_attr.attr, | ||
1835 | &sensor_dev_attr_fan5_min.dev_attr.attr, | ||
1836 | &sensor_dev_attr_fan6_min.dev_attr.attr, | ||
1837 | &sensor_dev_attr_fan7_min.dev_attr.attr, | ||
1838 | &sensor_dev_attr_fan8_min.dev_attr.attr, | ||
1839 | |||
1840 | &sensor_dev_attr_fan1_input.dev_attr.attr, | ||
1841 | &sensor_dev_attr_fan2_input.dev_attr.attr, | ||
1842 | &sensor_dev_attr_fan3_input.dev_attr.attr, | ||
1843 | &sensor_dev_attr_fan4_input.dev_attr.attr, | ||
1844 | &sensor_dev_attr_fan5_input.dev_attr.attr, | ||
1845 | &sensor_dev_attr_fan6_input.dev_attr.attr, | ||
1846 | &sensor_dev_attr_fan7_input.dev_attr.attr, | ||
1847 | &sensor_dev_attr_fan8_input.dev_attr.attr, | ||
1848 | |||
1849 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, | ||
1850 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, | ||
1851 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, | ||
1852 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, | ||
1853 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, | ||
1854 | &sensor_dev_attr_fan6_alarm.dev_attr.attr, | ||
1855 | &sensor_dev_attr_fan7_alarm.dev_attr.attr, | ||
1856 | &sensor_dev_attr_fan8_alarm.dev_attr.attr, | ||
1857 | |||
1858 | &sensor_dev_attr_force_pwm_max.dev_attr.attr, | ||
1859 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
1860 | &sensor_dev_attr_pwm2.dev_attr.attr, | ||
1861 | &sensor_dev_attr_pwm3.dev_attr.attr, | ||
1862 | &sensor_dev_attr_pwm4.dev_attr.attr, | ||
1863 | |||
1864 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, | ||
1865 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, | ||
1866 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, | ||
1867 | &sensor_dev_attr_pwm4_auto_point1_pwm.dev_attr.attr, | ||
1868 | |||
1869 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, | ||
1870 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, | ||
1871 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, | ||
1872 | &sensor_dev_attr_pwm4_auto_point2_pwm.dev_attr.attr, | ||
1873 | |||
1874 | &sensor_dev_attr_temp1_auto_point1_hyst.dev_attr.attr, | ||
1875 | &sensor_dev_attr_temp2_auto_point1_hyst.dev_attr.attr, | ||
1876 | &sensor_dev_attr_temp3_auto_point1_hyst.dev_attr.attr, | ||
1877 | &sensor_dev_attr_temp4_auto_point1_hyst.dev_attr.attr, | ||
1878 | |||
1879 | &sensor_dev_attr_temp1_auto_point2_hyst.dev_attr.attr, | ||
1880 | &sensor_dev_attr_temp2_auto_point2_hyst.dev_attr.attr, | ||
1881 | &sensor_dev_attr_temp3_auto_point2_hyst.dev_attr.attr, | ||
1882 | &sensor_dev_attr_temp4_auto_point2_hyst.dev_attr.attr, | ||
1883 | |||
1884 | &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr, | ||
1885 | &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr, | ||
1886 | &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr, | ||
1887 | &sensor_dev_attr_temp4_auto_point1_temp.dev_attr.attr, | ||
1888 | |||
1889 | &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr, | ||
1890 | &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr, | ||
1891 | &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr, | ||
1892 | &sensor_dev_attr_temp4_auto_point2_temp.dev_attr.attr, | ||
1893 | |||
1894 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | ||
1895 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | ||
1896 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | ||
1897 | &sensor_dev_attr_pwm4_enable.dev_attr.attr, | ||
1898 | |||
1899 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, | ||
1900 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, | ||
1901 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, | ||
1902 | &sensor_dev_attr_pwm4_auto_channels_temp.dev_attr.attr, | ||
1903 | NULL | ||
1904 | }; | ||
1905 | |||
1906 | /* Return 0 if detection is successful, -ENODEV otherwise */ | ||
1907 | static int adt7462_detect(struct i2c_client *client, int kind, | ||
1908 | struct i2c_board_info *info) | ||
1909 | { | ||
1910 | struct i2c_adapter *adapter = client->adapter; | ||
1911 | |||
1912 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
1913 | return -ENODEV; | ||
1914 | |||
1915 | if (kind <= 0) { | ||
1916 | int vendor, device, revision; | ||
1917 | |||
1918 | vendor = i2c_smbus_read_byte_data(client, ADT7462_REG_VENDOR); | ||
1919 | if (vendor != ADT7462_VENDOR) | ||
1920 | return -ENODEV; | ||
1921 | |||
1922 | device = i2c_smbus_read_byte_data(client, ADT7462_REG_DEVICE); | ||
1923 | if (device != ADT7462_DEVICE) | ||
1924 | return -ENODEV; | ||
1925 | |||
1926 | revision = i2c_smbus_read_byte_data(client, | ||
1927 | ADT7462_REG_REVISION); | ||
1928 | if (revision != ADT7462_REVISION) | ||
1929 | return -ENODEV; | ||
1930 | } else | ||
1931 | dev_dbg(&adapter->dev, "detection forced\n"); | ||
1932 | |||
1933 | strlcpy(info->type, "adt7462", I2C_NAME_SIZE); | ||
1934 | |||
1935 | return 0; | ||
1936 | } | ||
1937 | |||
1938 | static int adt7462_probe(struct i2c_client *client, | ||
1939 | const struct i2c_device_id *id) | ||
1940 | { | ||
1941 | struct adt7462_data *data; | ||
1942 | int err; | ||
1943 | |||
1944 | data = kzalloc(sizeof(struct adt7462_data), GFP_KERNEL); | ||
1945 | if (!data) { | ||
1946 | err = -ENOMEM; | ||
1947 | goto exit; | ||
1948 | } | ||
1949 | |||
1950 | i2c_set_clientdata(client, data); | ||
1951 | mutex_init(&data->lock); | ||
1952 | |||
1953 | dev_info(&client->dev, "%s chip found\n", client->name); | ||
1954 | |||
1955 | /* Register sysfs hooks */ | ||
1956 | data->attrs.attrs = adt7462_attr; | ||
1957 | err = sysfs_create_group(&client->dev.kobj, &data->attrs); | ||
1958 | if (err) | ||
1959 | goto exit_free; | ||
1960 | |||
1961 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
1962 | if (IS_ERR(data->hwmon_dev)) { | ||
1963 | err = PTR_ERR(data->hwmon_dev); | ||
1964 | goto exit_remove; | ||
1965 | } | ||
1966 | |||
1967 | return 0; | ||
1968 | |||
1969 | exit_remove: | ||
1970 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1971 | exit_free: | ||
1972 | kfree(data); | ||
1973 | exit: | ||
1974 | return err; | ||
1975 | } | ||
1976 | |||
1977 | static int adt7462_remove(struct i2c_client *client) | ||
1978 | { | ||
1979 | struct adt7462_data *data = i2c_get_clientdata(client); | ||
1980 | |||
1981 | hwmon_device_unregister(data->hwmon_dev); | ||
1982 | sysfs_remove_group(&client->dev.kobj, &data->attrs); | ||
1983 | kfree(data); | ||
1984 | return 0; | ||
1985 | } | ||
1986 | |||
1987 | static int __init adt7462_init(void) | ||
1988 | { | ||
1989 | return i2c_add_driver(&adt7462_driver); | ||
1990 | } | ||
1991 | |||
1992 | static void __exit adt7462_exit(void) | ||
1993 | { | ||
1994 | i2c_del_driver(&adt7462_driver); | ||
1995 | } | ||
1996 | |||
1997 | MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>"); | ||
1998 | MODULE_DESCRIPTION("ADT7462 driver"); | ||
1999 | MODULE_LICENSE("GPL"); | ||
2000 | |||
2001 | module_init(adt7462_init); | ||
2002 | module_exit(adt7462_exit); | ||
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index d368d8f845e1..1311a595147e 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c | |||
@@ -137,6 +137,8 @@ I2C_CLIENT_INSMOD_1(adt7470); | |||
137 | #define FAN_PERIOD_INVALID 65535 | 137 | #define FAN_PERIOD_INVALID 65535 |
138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 138 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
139 | 139 | ||
140 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
141 | |||
140 | struct adt7470_data { | 142 | struct adt7470_data { |
141 | struct device *hwmon_dev; | 143 | struct device *hwmon_dev; |
142 | struct attribute_group attrs; | 144 | struct attribute_group attrs; |
@@ -353,7 +355,13 @@ static ssize_t set_temp_min(struct device *dev, | |||
353 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 355 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
354 | struct i2c_client *client = to_i2c_client(dev); | 356 | struct i2c_client *client = to_i2c_client(dev); |
355 | struct adt7470_data *data = i2c_get_clientdata(client); | 357 | struct adt7470_data *data = i2c_get_clientdata(client); |
356 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 358 | long temp; |
359 | |||
360 | if (strict_strtol(buf, 10, &temp)) | ||
361 | return -EINVAL; | ||
362 | |||
363 | temp = ROUND_DIV(temp, 1000); | ||
364 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
357 | 365 | ||
358 | mutex_lock(&data->lock); | 366 | mutex_lock(&data->lock); |
359 | data->temp_min[attr->index] = temp; | 367 | data->temp_min[attr->index] = temp; |
@@ -381,7 +389,13 @@ static ssize_t set_temp_max(struct device *dev, | |||
381 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 389 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
382 | struct i2c_client *client = to_i2c_client(dev); | 390 | struct i2c_client *client = to_i2c_client(dev); |
383 | struct adt7470_data *data = i2c_get_clientdata(client); | 391 | struct adt7470_data *data = i2c_get_clientdata(client); |
384 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 392 | long temp; |
393 | |||
394 | if (strict_strtol(buf, 10, &temp)) | ||
395 | return -EINVAL; | ||
396 | |||
397 | temp = ROUND_DIV(temp, 1000); | ||
398 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
385 | 399 | ||
386 | mutex_lock(&data->lock); | 400 | mutex_lock(&data->lock); |
387 | data->temp_max[attr->index] = temp; | 401 | data->temp_max[attr->index] = temp; |
@@ -430,11 +444,13 @@ static ssize_t set_fan_max(struct device *dev, | |||
430 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 444 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
431 | struct i2c_client *client = to_i2c_client(dev); | 445 | struct i2c_client *client = to_i2c_client(dev); |
432 | struct adt7470_data *data = i2c_get_clientdata(client); | 446 | struct adt7470_data *data = i2c_get_clientdata(client); |
433 | int temp = simple_strtol(buf, NULL, 10); | 447 | long temp; |
434 | 448 | ||
435 | if (!temp) | 449 | if (strict_strtol(buf, 10, &temp) || !temp) |
436 | return -EINVAL; | 450 | return -EINVAL; |
451 | |||
437 | temp = FAN_RPM_TO_PERIOD(temp); | 452 | temp = FAN_RPM_TO_PERIOD(temp); |
453 | temp = SENSORS_LIMIT(temp, 1, 65534); | ||
438 | 454 | ||
439 | mutex_lock(&data->lock); | 455 | mutex_lock(&data->lock); |
440 | data->fan_max[attr->index] = temp; | 456 | data->fan_max[attr->index] = temp; |
@@ -465,11 +481,13 @@ static ssize_t set_fan_min(struct device *dev, | |||
465 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 481 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
466 | struct i2c_client *client = to_i2c_client(dev); | 482 | struct i2c_client *client = to_i2c_client(dev); |
467 | struct adt7470_data *data = i2c_get_clientdata(client); | 483 | struct adt7470_data *data = i2c_get_clientdata(client); |
468 | int temp = simple_strtol(buf, NULL, 10); | 484 | long temp; |
469 | 485 | ||
470 | if (!temp) | 486 | if (strict_strtol(buf, 10, &temp) || !temp) |
471 | return -EINVAL; | 487 | return -EINVAL; |
488 | |||
472 | temp = FAN_RPM_TO_PERIOD(temp); | 489 | temp = FAN_RPM_TO_PERIOD(temp); |
490 | temp = SENSORS_LIMIT(temp, 1, 65534); | ||
473 | 491 | ||
474 | mutex_lock(&data->lock); | 492 | mutex_lock(&data->lock); |
475 | data->fan_min[attr->index] = temp; | 493 | data->fan_min[attr->index] = temp; |
@@ -507,9 +525,12 @@ static ssize_t set_force_pwm_max(struct device *dev, | |||
507 | { | 525 | { |
508 | struct i2c_client *client = to_i2c_client(dev); | 526 | struct i2c_client *client = to_i2c_client(dev); |
509 | struct adt7470_data *data = i2c_get_clientdata(client); | 527 | struct adt7470_data *data = i2c_get_clientdata(client); |
510 | int temp = simple_strtol(buf, NULL, 10); | 528 | long temp; |
511 | u8 reg; | 529 | u8 reg; |
512 | 530 | ||
531 | if (strict_strtol(buf, 10, &temp)) | ||
532 | return -EINVAL; | ||
533 | |||
513 | mutex_lock(&data->lock); | 534 | mutex_lock(&data->lock); |
514 | data->force_pwm_max = temp; | 535 | data->force_pwm_max = temp; |
515 | reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); | 536 | reg = i2c_smbus_read_byte_data(client, ADT7470_REG_CFG); |
@@ -537,7 +558,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
537 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 558 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
538 | struct i2c_client *client = to_i2c_client(dev); | 559 | struct i2c_client *client = to_i2c_client(dev); |
539 | struct adt7470_data *data = i2c_get_clientdata(client); | 560 | struct adt7470_data *data = i2c_get_clientdata(client); |
540 | int temp = simple_strtol(buf, NULL, 10); | 561 | long temp; |
562 | |||
563 | if (strict_strtol(buf, 10, &temp)) | ||
564 | return -EINVAL; | ||
565 | |||
566 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
541 | 567 | ||
542 | mutex_lock(&data->lock); | 568 | mutex_lock(&data->lock); |
543 | data->pwm[attr->index] = temp; | 569 | data->pwm[attr->index] = temp; |
@@ -564,7 +590,12 @@ static ssize_t set_pwm_max(struct device *dev, | |||
564 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 590 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
565 | struct i2c_client *client = to_i2c_client(dev); | 591 | struct i2c_client *client = to_i2c_client(dev); |
566 | struct adt7470_data *data = i2c_get_clientdata(client); | 592 | struct adt7470_data *data = i2c_get_clientdata(client); |
567 | int temp = simple_strtol(buf, NULL, 10); | 593 | long temp; |
594 | |||
595 | if (strict_strtol(buf, 10, &temp)) | ||
596 | return -EINVAL; | ||
597 | |||
598 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
568 | 599 | ||
569 | mutex_lock(&data->lock); | 600 | mutex_lock(&data->lock); |
570 | data->pwm_max[attr->index] = temp; | 601 | data->pwm_max[attr->index] = temp; |
@@ -592,7 +623,12 @@ static ssize_t set_pwm_min(struct device *dev, | |||
592 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 623 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
593 | struct i2c_client *client = to_i2c_client(dev); | 624 | struct i2c_client *client = to_i2c_client(dev); |
594 | struct adt7470_data *data = i2c_get_clientdata(client); | 625 | struct adt7470_data *data = i2c_get_clientdata(client); |
595 | int temp = simple_strtol(buf, NULL, 10); | 626 | long temp; |
627 | |||
628 | if (strict_strtol(buf, 10, &temp)) | ||
629 | return -EINVAL; | ||
630 | |||
631 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
596 | 632 | ||
597 | mutex_lock(&data->lock); | 633 | mutex_lock(&data->lock); |
598 | data->pwm_min[attr->index] = temp; | 634 | data->pwm_min[attr->index] = temp; |
@@ -630,7 +666,13 @@ static ssize_t set_pwm_tmin(struct device *dev, | |||
630 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 666 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
631 | struct i2c_client *client = to_i2c_client(dev); | 667 | struct i2c_client *client = to_i2c_client(dev); |
632 | struct adt7470_data *data = i2c_get_clientdata(client); | 668 | struct adt7470_data *data = i2c_get_clientdata(client); |
633 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 669 | long temp; |
670 | |||
671 | if (strict_strtol(buf, 10, &temp)) | ||
672 | return -EINVAL; | ||
673 | |||
674 | temp = ROUND_DIV(temp, 1000); | ||
675 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
634 | 676 | ||
635 | mutex_lock(&data->lock); | 677 | mutex_lock(&data->lock); |
636 | data->pwm_tmin[attr->index] = temp; | 678 | data->pwm_tmin[attr->index] = temp; |
@@ -658,11 +700,14 @@ static ssize_t set_pwm_auto(struct device *dev, | |||
658 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 700 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
659 | struct i2c_client *client = to_i2c_client(dev); | 701 | struct i2c_client *client = to_i2c_client(dev); |
660 | struct adt7470_data *data = i2c_get_clientdata(client); | 702 | struct adt7470_data *data = i2c_get_clientdata(client); |
661 | int temp = simple_strtol(buf, NULL, 10); | ||
662 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); | 703 | int pwm_auto_reg = ADT7470_REG_PWM_CFG(attr->index); |
663 | int pwm_auto_reg_mask; | 704 | int pwm_auto_reg_mask; |
705 | long temp; | ||
664 | u8 reg; | 706 | u8 reg; |
665 | 707 | ||
708 | if (strict_strtol(buf, 10, &temp)) | ||
709 | return -EINVAL; | ||
710 | |||
666 | if (attr->index % 2) | 711 | if (attr->index % 2) |
667 | pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK; | 712 | pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK; |
668 | else | 713 | else |
@@ -716,10 +761,14 @@ static ssize_t set_pwm_auto_temp(struct device *dev, | |||
716 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 761 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
717 | struct i2c_client *client = to_i2c_client(dev); | 762 | struct i2c_client *client = to_i2c_client(dev); |
718 | struct adt7470_data *data = i2c_get_clientdata(client); | 763 | struct adt7470_data *data = i2c_get_clientdata(client); |
719 | int temp = cvt_auto_temp(simple_strtol(buf, NULL, 10)); | ||
720 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); | 764 | int pwm_auto_reg = ADT7470_REG_PWM_AUTO_TEMP(attr->index); |
765 | long temp; | ||
721 | u8 reg; | 766 | u8 reg; |
722 | 767 | ||
768 | if (strict_strtol(buf, 10, &temp)) | ||
769 | return -EINVAL; | ||
770 | |||
771 | temp = cvt_auto_temp(temp); | ||
723 | if (temp < 0) | 772 | if (temp < 0) |
724 | return temp; | 773 | return temp; |
725 | 774 | ||
diff --git a/drivers/hwmon/adt7473.c b/drivers/hwmon/adt7473.c index b9a8ea30c99c..18aa30866a6c 100644 --- a/drivers/hwmon/adt7473.c +++ b/drivers/hwmon/adt7473.c | |||
@@ -129,6 +129,8 @@ I2C_CLIENT_INSMOD_1(adt7473); | |||
129 | #define FAN_PERIOD_INVALID 65535 | 129 | #define FAN_PERIOD_INVALID 65535 |
130 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) | 130 | #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID) |
131 | 131 | ||
132 | #define ROUND_DIV(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) | ||
133 | |||
132 | struct adt7473_data { | 134 | struct adt7473_data { |
133 | struct device *hwmon_dev; | 135 | struct device *hwmon_dev; |
134 | struct attribute_group attrs; | 136 | struct attribute_group attrs; |
@@ -357,7 +359,12 @@ static ssize_t set_volt_min(struct device *dev, | |||
357 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 359 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
358 | struct i2c_client *client = to_i2c_client(dev); | 360 | struct i2c_client *client = to_i2c_client(dev); |
359 | struct adt7473_data *data = i2c_get_clientdata(client); | 361 | struct adt7473_data *data = i2c_get_clientdata(client); |
360 | int volt = encode_volt(attr->index, simple_strtol(buf, NULL, 10)); | 362 | long volt; |
363 | |||
364 | if (strict_strtol(buf, 10, &volt)) | ||
365 | return -EINVAL; | ||
366 | |||
367 | volt = encode_volt(attr->index, volt); | ||
361 | 368 | ||
362 | mutex_lock(&data->lock); | 369 | mutex_lock(&data->lock); |
363 | data->volt_min[attr->index] = volt; | 370 | data->volt_min[attr->index] = volt; |
@@ -386,7 +393,12 @@ static ssize_t set_volt_max(struct device *dev, | |||
386 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 393 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
387 | struct i2c_client *client = to_i2c_client(dev); | 394 | struct i2c_client *client = to_i2c_client(dev); |
388 | struct adt7473_data *data = i2c_get_clientdata(client); | 395 | struct adt7473_data *data = i2c_get_clientdata(client); |
389 | int volt = encode_volt(attr->index, simple_strtol(buf, NULL, 10)); | 396 | long volt; |
397 | |||
398 | if (strict_strtol(buf, 10, &volt)) | ||
399 | return -EINVAL; | ||
400 | |||
401 | volt = encode_volt(attr->index, volt); | ||
390 | 402 | ||
391 | mutex_lock(&data->lock); | 403 | mutex_lock(&data->lock); |
392 | data->volt_max[attr->index] = volt; | 404 | data->volt_max[attr->index] = volt; |
@@ -419,7 +431,8 @@ static int decode_temp(u8 twos_complement, u8 raw) | |||
419 | 431 | ||
420 | static u8 encode_temp(u8 twos_complement, int cooked) | 432 | static u8 encode_temp(u8 twos_complement, int cooked) |
421 | { | 433 | { |
422 | return twos_complement ? cooked & 0xFF : cooked + 64; | 434 | u8 ret = twos_complement ? cooked & 0xFF : cooked + 64; |
435 | return SENSORS_LIMIT(ret, 0, 255); | ||
423 | } | 436 | } |
424 | 437 | ||
425 | static ssize_t show_temp_min(struct device *dev, | 438 | static ssize_t show_temp_min(struct device *dev, |
@@ -441,7 +454,12 @@ static ssize_t set_temp_min(struct device *dev, | |||
441 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 454 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
442 | struct i2c_client *client = to_i2c_client(dev); | 455 | struct i2c_client *client = to_i2c_client(dev); |
443 | struct adt7473_data *data = i2c_get_clientdata(client); | 456 | struct adt7473_data *data = i2c_get_clientdata(client); |
444 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 457 | long temp; |
458 | |||
459 | if (strict_strtol(buf, 10, &temp)) | ||
460 | return -EINVAL; | ||
461 | |||
462 | temp = ROUND_DIV(temp, 1000); | ||
445 | temp = encode_temp(data->temp_twos_complement, temp); | 463 | temp = encode_temp(data->temp_twos_complement, temp); |
446 | 464 | ||
447 | mutex_lock(&data->lock); | 465 | mutex_lock(&data->lock); |
@@ -472,7 +490,12 @@ static ssize_t set_temp_max(struct device *dev, | |||
472 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 490 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
473 | struct i2c_client *client = to_i2c_client(dev); | 491 | struct i2c_client *client = to_i2c_client(dev); |
474 | struct adt7473_data *data = i2c_get_clientdata(client); | 492 | struct adt7473_data *data = i2c_get_clientdata(client); |
475 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 493 | long temp; |
494 | |||
495 | if (strict_strtol(buf, 10, &temp)) | ||
496 | return -EINVAL; | ||
497 | |||
498 | temp = ROUND_DIV(temp, 1000); | ||
476 | temp = encode_temp(data->temp_twos_complement, temp); | 499 | temp = encode_temp(data->temp_twos_complement, temp); |
477 | 500 | ||
478 | mutex_lock(&data->lock); | 501 | mutex_lock(&data->lock); |
@@ -515,11 +538,13 @@ static ssize_t set_fan_min(struct device *dev, | |||
515 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 538 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
516 | struct i2c_client *client = to_i2c_client(dev); | 539 | struct i2c_client *client = to_i2c_client(dev); |
517 | struct adt7473_data *data = i2c_get_clientdata(client); | 540 | struct adt7473_data *data = i2c_get_clientdata(client); |
518 | int temp = simple_strtol(buf, NULL, 10); | 541 | long temp; |
519 | 542 | ||
520 | if (!temp) | 543 | if (strict_strtol(buf, 10, &temp) || !temp) |
521 | return -EINVAL; | 544 | return -EINVAL; |
545 | |||
522 | temp = FAN_RPM_TO_PERIOD(temp); | 546 | temp = FAN_RPM_TO_PERIOD(temp); |
547 | temp = SENSORS_LIMIT(temp, 1, 65534); | ||
523 | 548 | ||
524 | mutex_lock(&data->lock); | 549 | mutex_lock(&data->lock); |
525 | data->fan_min[attr->index] = temp; | 550 | data->fan_min[attr->index] = temp; |
@@ -558,7 +583,10 @@ static ssize_t set_max_duty_at_crit(struct device *dev, | |||
558 | u8 reg; | 583 | u8 reg; |
559 | struct i2c_client *client = to_i2c_client(dev); | 584 | struct i2c_client *client = to_i2c_client(dev); |
560 | struct adt7473_data *data = i2c_get_clientdata(client); | 585 | struct adt7473_data *data = i2c_get_clientdata(client); |
561 | int temp = simple_strtol(buf, NULL, 10); | 586 | long temp; |
587 | |||
588 | if (strict_strtol(buf, 10, &temp)) | ||
589 | return -EINVAL; | ||
562 | 590 | ||
563 | mutex_lock(&data->lock); | 591 | mutex_lock(&data->lock); |
564 | data->max_duty_at_overheat = !!temp; | 592 | data->max_duty_at_overheat = !!temp; |
@@ -587,7 +615,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, | |||
587 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 615 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
588 | struct i2c_client *client = to_i2c_client(dev); | 616 | struct i2c_client *client = to_i2c_client(dev); |
589 | struct adt7473_data *data = i2c_get_clientdata(client); | 617 | struct adt7473_data *data = i2c_get_clientdata(client); |
590 | int temp = simple_strtol(buf, NULL, 10); | 618 | long temp; |
619 | |||
620 | if (strict_strtol(buf, 10, &temp)) | ||
621 | return -EINVAL; | ||
622 | |||
623 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
591 | 624 | ||
592 | mutex_lock(&data->lock); | 625 | mutex_lock(&data->lock); |
593 | data->pwm[attr->index] = temp; | 626 | data->pwm[attr->index] = temp; |
@@ -614,7 +647,12 @@ static ssize_t set_pwm_max(struct device *dev, | |||
614 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 647 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
615 | struct i2c_client *client = to_i2c_client(dev); | 648 | struct i2c_client *client = to_i2c_client(dev); |
616 | struct adt7473_data *data = i2c_get_clientdata(client); | 649 | struct adt7473_data *data = i2c_get_clientdata(client); |
617 | int temp = simple_strtol(buf, NULL, 10); | 650 | long temp; |
651 | |||
652 | if (strict_strtol(buf, 10, &temp)) | ||
653 | return -EINVAL; | ||
654 | |||
655 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
618 | 656 | ||
619 | mutex_lock(&data->lock); | 657 | mutex_lock(&data->lock); |
620 | data->pwm_max[attr->index] = temp; | 658 | data->pwm_max[attr->index] = temp; |
@@ -642,7 +680,12 @@ static ssize_t set_pwm_min(struct device *dev, | |||
642 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 680 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
643 | struct i2c_client *client = to_i2c_client(dev); | 681 | struct i2c_client *client = to_i2c_client(dev); |
644 | struct adt7473_data *data = i2c_get_clientdata(client); | 682 | struct adt7473_data *data = i2c_get_clientdata(client); |
645 | int temp = simple_strtol(buf, NULL, 10); | 683 | long temp; |
684 | |||
685 | if (strict_strtol(buf, 10, &temp)) | ||
686 | return -EINVAL; | ||
687 | |||
688 | temp = SENSORS_LIMIT(temp, 0, 255); | ||
646 | 689 | ||
647 | mutex_lock(&data->lock); | 690 | mutex_lock(&data->lock); |
648 | data->pwm_min[attr->index] = temp; | 691 | data->pwm_min[attr->index] = temp; |
@@ -672,7 +715,12 @@ static ssize_t set_temp_tmax(struct device *dev, | |||
672 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 715 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
673 | struct i2c_client *client = to_i2c_client(dev); | 716 | struct i2c_client *client = to_i2c_client(dev); |
674 | struct adt7473_data *data = i2c_get_clientdata(client); | 717 | struct adt7473_data *data = i2c_get_clientdata(client); |
675 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 718 | long temp; |
719 | |||
720 | if (strict_strtol(buf, 10, &temp)) | ||
721 | return -EINVAL; | ||
722 | |||
723 | temp = ROUND_DIV(temp, 1000); | ||
676 | temp = encode_temp(data->temp_twos_complement, temp); | 724 | temp = encode_temp(data->temp_twos_complement, temp); |
677 | 725 | ||
678 | mutex_lock(&data->lock); | 726 | mutex_lock(&data->lock); |
@@ -703,7 +751,12 @@ static ssize_t set_temp_tmin(struct device *dev, | |||
703 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 751 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
704 | struct i2c_client *client = to_i2c_client(dev); | 752 | struct i2c_client *client = to_i2c_client(dev); |
705 | struct adt7473_data *data = i2c_get_clientdata(client); | 753 | struct adt7473_data *data = i2c_get_clientdata(client); |
706 | int temp = simple_strtol(buf, NULL, 10) / 1000; | 754 | long temp; |
755 | |||
756 | if (strict_strtol(buf, 10, &temp)) | ||
757 | return -EINVAL; | ||
758 | |||
759 | temp = ROUND_DIV(temp, 1000); | ||
707 | temp = encode_temp(data->temp_twos_complement, temp); | 760 | temp = encode_temp(data->temp_twos_complement, temp); |
708 | 761 | ||
709 | mutex_lock(&data->lock); | 762 | mutex_lock(&data->lock); |
@@ -741,7 +794,10 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
741 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 794 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
742 | struct i2c_client *client = to_i2c_client(dev); | 795 | struct i2c_client *client = to_i2c_client(dev); |
743 | struct adt7473_data *data = i2c_get_clientdata(client); | 796 | struct adt7473_data *data = i2c_get_clientdata(client); |
744 | int temp = simple_strtol(buf, NULL, 10); | 797 | long temp; |
798 | |||
799 | if (strict_strtol(buf, 10, &temp)) | ||
800 | return -EINVAL; | ||
745 | 801 | ||
746 | switch (temp) { | 802 | switch (temp) { |
747 | case 0: | 803 | case 0: |
@@ -805,7 +861,10 @@ static ssize_t set_pwm_auto_temp(struct device *dev, | |||
805 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | 861 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
806 | struct i2c_client *client = to_i2c_client(dev); | 862 | struct i2c_client *client = to_i2c_client(dev); |
807 | struct adt7473_data *data = i2c_get_clientdata(client); | 863 | struct adt7473_data *data = i2c_get_clientdata(client); |
808 | int temp = simple_strtol(buf, NULL, 10); | 864 | long temp; |
865 | |||
866 | if (strict_strtol(buf, 10, &temp)) | ||
867 | return -EINVAL; | ||
809 | 868 | ||
810 | switch (temp) { | 869 | switch (temp) { |
811 | case 1: | 870 | case 1: |
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index be3285912cb7..488e45cd43d7 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c | |||
@@ -1280,7 +1280,7 @@ static __initdata struct dmi_match_data applesmc_dmi_data[] = { | |||
1280 | { .accelerometer = 0, .light = 0, .temperature_set = 4 }, | 1280 | { .accelerometer = 0, .light = 0, .temperature_set = 4 }, |
1281 | /* iMac: temperature set 5 */ | 1281 | /* iMac: temperature set 5 */ |
1282 | { .accelerometer = 0, .light = 0, .temperature_set = 5 }, | 1282 | { .accelerometer = 0, .light = 0, .temperature_set = 5 }, |
1283 | /* MacBook3: accelerometer and temperature set 6 */ | 1283 | /* MacBook3, MacBook4: accelerometer and temperature set 6 */ |
1284 | { .accelerometer = 1, .light = 0, .temperature_set = 6 }, | 1284 | { .accelerometer = 1, .light = 0, .temperature_set = 6 }, |
1285 | /* MacBook Air: accelerometer, backlight and temperature set 7 */ | 1285 | /* MacBook Air: accelerometer, backlight and temperature set 7 */ |
1286 | { .accelerometer = 1, .light = 1, .temperature_set = 7 }, | 1286 | { .accelerometer = 1, .light = 1, .temperature_set = 7 }, |
@@ -1329,6 +1329,10 @@ static __initdata struct dmi_system_id applesmc_whitelist[] = { | |||
1329 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), | 1329 | DMI_MATCH(DMI_BOARD_VENDOR,"Apple"), |
1330 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, | 1330 | DMI_MATCH(DMI_PRODUCT_NAME,"MacBook3") }, |
1331 | &applesmc_dmi_data[6]}, | 1331 | &applesmc_dmi_data[6]}, |
1332 | { applesmc_dmi_match, "Apple MacBook 4", { | ||
1333 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | ||
1334 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook4") }, | ||
1335 | &applesmc_dmi_data[6]}, | ||
1332 | { applesmc_dmi_match, "Apple MacBook 5", { | 1336 | { applesmc_dmi_match, "Apple MacBook 5", { |
1333 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), | 1337 | DMI_MATCH(DMI_BOARD_VENDOR, "Apple"), |
1334 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") }, | 1338 | DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5") }, |
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c index 7b0ed5dea399..fe74609a7feb 100644 --- a/drivers/hwmon/ibmaem.c +++ b/drivers/hwmon/ibmaem.c | |||
@@ -88,9 +88,11 @@ | |||
88 | static DEFINE_IDR(aem_idr); | 88 | static DEFINE_IDR(aem_idr); |
89 | static DEFINE_SPINLOCK(aem_idr_lock); | 89 | static DEFINE_SPINLOCK(aem_idr_lock); |
90 | 90 | ||
91 | static struct device_driver aem_driver = { | 91 | static struct platform_driver aem_driver = { |
92 | .name = DRVNAME, | 92 | .driver = { |
93 | .bus = &platform_bus_type, | 93 | .name = DRVNAME, |
94 | .bus = &platform_bus_type, | ||
95 | } | ||
94 | }; | 96 | }; |
95 | 97 | ||
96 | struct aem_ipmi_data { | 98 | struct aem_ipmi_data { |
@@ -583,7 +585,7 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle) | |||
583 | data->pdev = platform_device_alloc(DRVNAME, data->id); | 585 | data->pdev = platform_device_alloc(DRVNAME, data->id); |
584 | if (!data->pdev) | 586 | if (!data->pdev) |
585 | goto dev_err; | 587 | goto dev_err; |
586 | data->pdev->dev.driver = &aem_driver; | 588 | data->pdev->dev.driver = &aem_driver.driver; |
587 | 589 | ||
588 | res = platform_device_add(data->pdev); | 590 | res = platform_device_add(data->pdev); |
589 | if (res) | 591 | if (res) |
@@ -716,7 +718,7 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe, | |||
716 | data->pdev = platform_device_alloc(DRVNAME, data->id); | 718 | data->pdev = platform_device_alloc(DRVNAME, data->id); |
717 | if (!data->pdev) | 719 | if (!data->pdev) |
718 | goto dev_err; | 720 | goto dev_err; |
719 | data->pdev->dev.driver = &aem_driver; | 721 | data->pdev->dev.driver = &aem_driver.driver; |
720 | 722 | ||
721 | res = platform_device_add(data->pdev); | 723 | res = platform_device_add(data->pdev); |
722 | if (res) | 724 | if (res) |
@@ -1085,7 +1087,7 @@ static int __init aem_init(void) | |||
1085 | { | 1087 | { |
1086 | int res; | 1088 | int res; |
1087 | 1089 | ||
1088 | res = driver_register(&aem_driver); | 1090 | res = driver_register(&aem_driver.driver); |
1089 | if (res) { | 1091 | if (res) { |
1090 | printk(KERN_ERR "Can't register aem driver\n"); | 1092 | printk(KERN_ERR "Can't register aem driver\n"); |
1091 | return res; | 1093 | return res; |
@@ -1097,7 +1099,7 @@ static int __init aem_init(void) | |||
1097 | return 0; | 1099 | return 0; |
1098 | 1100 | ||
1099 | ipmi_reg_err: | 1101 | ipmi_reg_err: |
1100 | driver_unregister(&aem_driver); | 1102 | driver_unregister(&aem_driver.driver); |
1101 | return res; | 1103 | return res; |
1102 | 1104 | ||
1103 | } | 1105 | } |
@@ -1107,7 +1109,7 @@ static void __exit aem_exit(void) | |||
1107 | struct aem_data *p1, *next1; | 1109 | struct aem_data *p1, *next1; |
1108 | 1110 | ||
1109 | ipmi_smi_watcher_unregister(&driver_data.bmc_events); | 1111 | ipmi_smi_watcher_unregister(&driver_data.bmc_events); |
1110 | driver_unregister(&aem_driver); | 1112 | driver_unregister(&aem_driver.driver); |
1111 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) | 1113 | list_for_each_entry_safe(p1, next1, &driver_data.aem_devices, list) |
1112 | aem_delete(p1); | 1114 | aem_delete(p1); |
1113 | } | 1115 | } |
diff --git a/drivers/hwmon/lis3lv02d.c b/drivers/hwmon/lis3lv02d.c new file mode 100644 index 000000000000..c002144c76bc --- /dev/null +++ b/drivers/hwmon/lis3lv02d.c | |||
@@ -0,0 +1,581 @@ | |||
1 | /* | ||
2 | * lis3lv02d.c - ST LIS3LV02DL accelerometer driver | ||
3 | * | ||
4 | * Copyright (C) 2007-2008 Yan Burman | ||
5 | * Copyright (C) 2008 Eric Piel | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/dmi.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/types.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/interrupt.h> | ||
29 | #include <linux/input.h> | ||
30 | #include <linux/kthread.h> | ||
31 | #include <linux/semaphore.h> | ||
32 | #include <linux/delay.h> | ||
33 | #include <linux/wait.h> | ||
34 | #include <linux/poll.h> | ||
35 | #include <linux/freezer.h> | ||
36 | #include <linux/uaccess.h> | ||
37 | #include <acpi/acpi_drivers.h> | ||
38 | #include <asm/atomic.h> | ||
39 | #include "lis3lv02d.h" | ||
40 | |||
41 | #define DRIVER_NAME "lis3lv02d" | ||
42 | #define ACPI_MDPS_CLASS "accelerometer" | ||
43 | |||
44 | /* joystick device poll interval in milliseconds */ | ||
45 | #define MDPS_POLL_INTERVAL 50 | ||
46 | /* | ||
47 | * The sensor can also generate interrupts (DRDY) but it's pretty pointless | ||
48 | * because their are generated even if the data do not change. So it's better | ||
49 | * to keep the interrupt for the free-fall event. The values are updated at | ||
50 | * 40Hz (at the lowest frequency), but as it can be pretty time consuming on | ||
51 | * some low processor, we poll the sensor only at 20Hz... enough for the | ||
52 | * joystick. | ||
53 | */ | ||
54 | |||
55 | /* Maximum value our axis may get for the input device (signed 12 bits) */ | ||
56 | #define MDPS_MAX_VAL 2048 | ||
57 | |||
58 | struct axis_conversion { | ||
59 | s8 x; | ||
60 | s8 y; | ||
61 | s8 z; | ||
62 | }; | ||
63 | |||
64 | struct acpi_lis3lv02d { | ||
65 | struct acpi_device *device; /* The ACPI device */ | ||
66 | struct input_dev *idev; /* input device */ | ||
67 | struct task_struct *kthread; /* kthread for input */ | ||
68 | struct mutex lock; | ||
69 | struct platform_device *pdev; /* platform device */ | ||
70 | atomic_t count; /* interrupt count after last read */ | ||
71 | int xcalib; /* calibrated null value for x */ | ||
72 | int ycalib; /* calibrated null value for y */ | ||
73 | int zcalib; /* calibrated null value for z */ | ||
74 | unsigned char is_on; /* whether the device is on or off */ | ||
75 | unsigned char usage; /* usage counter */ | ||
76 | struct axis_conversion ac; /* hw -> logical axis */ | ||
77 | }; | ||
78 | |||
79 | static struct acpi_lis3lv02d adev; | ||
80 | |||
81 | static int lis3lv02d_remove_fs(void); | ||
82 | static int lis3lv02d_add_fs(struct acpi_device *device); | ||
83 | |||
84 | /* For automatic insertion of the module */ | ||
85 | static struct acpi_device_id lis3lv02d_device_ids[] = { | ||
86 | {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */ | ||
87 | {"", 0}, | ||
88 | }; | ||
89 | MODULE_DEVICE_TABLE(acpi, lis3lv02d_device_ids); | ||
90 | |||
91 | /** | ||
92 | * lis3lv02d_acpi_init - ACPI _INI method: initialize the device. | ||
93 | * @handle: the handle of the device | ||
94 | * | ||
95 | * Returns AE_OK on success. | ||
96 | */ | ||
97 | static inline acpi_status lis3lv02d_acpi_init(acpi_handle handle) | ||
98 | { | ||
99 | return acpi_evaluate_object(handle, METHOD_NAME__INI, NULL, NULL); | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * lis3lv02d_acpi_read - ACPI ALRD method: read a register | ||
104 | * @handle: the handle of the device | ||
105 | * @reg: the register to read | ||
106 | * @ret: result of the operation | ||
107 | * | ||
108 | * Returns AE_OK on success. | ||
109 | */ | ||
110 | static acpi_status lis3lv02d_acpi_read(acpi_handle handle, int reg, u8 *ret) | ||
111 | { | ||
112 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | ||
113 | struct acpi_object_list args = { 1, &arg0 }; | ||
114 | unsigned long long lret; | ||
115 | acpi_status status; | ||
116 | |||
117 | arg0.integer.value = reg; | ||
118 | |||
119 | status = acpi_evaluate_integer(handle, "ALRD", &args, &lret); | ||
120 | *ret = lret; | ||
121 | return status; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * lis3lv02d_acpi_write - ACPI ALWR method: write to a register | ||
126 | * @handle: the handle of the device | ||
127 | * @reg: the register to write to | ||
128 | * @val: the value to write | ||
129 | * | ||
130 | * Returns AE_OK on success. | ||
131 | */ | ||
132 | static acpi_status lis3lv02d_acpi_write(acpi_handle handle, int reg, u8 val) | ||
133 | { | ||
134 | unsigned long long ret; /* Not used when writting */ | ||
135 | union acpi_object in_obj[2]; | ||
136 | struct acpi_object_list args = { 2, in_obj }; | ||
137 | |||
138 | in_obj[0].type = ACPI_TYPE_INTEGER; | ||
139 | in_obj[0].integer.value = reg; | ||
140 | in_obj[1].type = ACPI_TYPE_INTEGER; | ||
141 | in_obj[1].integer.value = val; | ||
142 | |||
143 | return acpi_evaluate_integer(handle, "ALWR", &args, &ret); | ||
144 | } | ||
145 | |||
146 | static s16 lis3lv02d_read_16(acpi_handle handle, int reg) | ||
147 | { | ||
148 | u8 lo, hi; | ||
149 | |||
150 | lis3lv02d_acpi_read(handle, reg, &lo); | ||
151 | lis3lv02d_acpi_read(handle, reg + 1, &hi); | ||
152 | /* In "12 bit right justified" mode, bit 6, bit 7, bit 8 = bit 5 */ | ||
153 | return (s16)((hi << 8) | lo); | ||
154 | } | ||
155 | |||
156 | /** | ||
157 | * lis3lv02d_get_axis - For the given axis, give the value converted | ||
158 | * @axis: 1,2,3 - can also be negative | ||
159 | * @hw_values: raw values returned by the hardware | ||
160 | * | ||
161 | * Returns the converted value. | ||
162 | */ | ||
163 | static inline int lis3lv02d_get_axis(s8 axis, int hw_values[3]) | ||
164 | { | ||
165 | if (axis > 0) | ||
166 | return hw_values[axis - 1]; | ||
167 | else | ||
168 | return -hw_values[-axis - 1]; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * lis3lv02d_get_xyz - Get X, Y and Z axis values from the accelerometer | ||
173 | * @handle: the handle to the device | ||
174 | * @x: where to store the X axis value | ||
175 | * @y: where to store the Y axis value | ||
176 | * @z: where to store the Z axis value | ||
177 | * | ||
178 | * Note that 40Hz input device can eat up about 10% CPU at 800MHZ | ||
179 | */ | ||
180 | static void lis3lv02d_get_xyz(acpi_handle handle, int *x, int *y, int *z) | ||
181 | { | ||
182 | int position[3]; | ||
183 | |||
184 | position[0] = lis3lv02d_read_16(handle, OUTX_L); | ||
185 | position[1] = lis3lv02d_read_16(handle, OUTY_L); | ||
186 | position[2] = lis3lv02d_read_16(handle, OUTZ_L); | ||
187 | |||
188 | *x = lis3lv02d_get_axis(adev.ac.x, position); | ||
189 | *y = lis3lv02d_get_axis(adev.ac.y, position); | ||
190 | *z = lis3lv02d_get_axis(adev.ac.z, position); | ||
191 | } | ||
192 | |||
193 | static inline void lis3lv02d_poweroff(acpi_handle handle) | ||
194 | { | ||
195 | adev.is_on = 0; | ||
196 | /* disable X,Y,Z axis and power down */ | ||
197 | lis3lv02d_acpi_write(handle, CTRL_REG1, 0x00); | ||
198 | } | ||
199 | |||
200 | static void lis3lv02d_poweron(acpi_handle handle) | ||
201 | { | ||
202 | u8 val; | ||
203 | |||
204 | adev.is_on = 1; | ||
205 | lis3lv02d_acpi_init(handle); | ||
206 | lis3lv02d_acpi_write(handle, FF_WU_CFG, 0); | ||
207 | /* | ||
208 | * BDU: LSB and MSB values are not updated until both have been read. | ||
209 | * So the value read will always be correct. | ||
210 | * IEN: Interrupt for free-fall and DD, not for data-ready. | ||
211 | */ | ||
212 | lis3lv02d_acpi_read(handle, CTRL_REG2, &val); | ||
213 | val |= CTRL2_BDU | CTRL2_IEN; | ||
214 | lis3lv02d_acpi_write(handle, CTRL_REG2, val); | ||
215 | } | ||
216 | |||
217 | #ifdef CONFIG_PM | ||
218 | static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state) | ||
219 | { | ||
220 | /* make sure the device is off when we suspend */ | ||
221 | lis3lv02d_poweroff(device->handle); | ||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int lis3lv02d_resume(struct acpi_device *device) | ||
226 | { | ||
227 | /* put back the device in the right state (ACPI might turn it on) */ | ||
228 | mutex_lock(&adev.lock); | ||
229 | if (adev.usage > 0) | ||
230 | lis3lv02d_poweron(device->handle); | ||
231 | else | ||
232 | lis3lv02d_poweroff(device->handle); | ||
233 | mutex_unlock(&adev.lock); | ||
234 | return 0; | ||
235 | } | ||
236 | #else | ||
237 | #define lis3lv02d_suspend NULL | ||
238 | #define lis3lv02d_resume NULL | ||
239 | #endif | ||
240 | |||
241 | |||
242 | /* | ||
243 | * To be called before starting to use the device. It makes sure that the | ||
244 | * device will always be on until a call to lis3lv02d_decrease_use(). Not to be | ||
245 | * used from interrupt context. | ||
246 | */ | ||
247 | static void lis3lv02d_increase_use(struct acpi_lis3lv02d *dev) | ||
248 | { | ||
249 | mutex_lock(&dev->lock); | ||
250 | dev->usage++; | ||
251 | if (dev->usage == 1) { | ||
252 | if (!dev->is_on) | ||
253 | lis3lv02d_poweron(dev->device->handle); | ||
254 | } | ||
255 | mutex_unlock(&dev->lock); | ||
256 | } | ||
257 | |||
258 | /* | ||
259 | * To be called whenever a usage of the device is stopped. | ||
260 | * It will make sure to turn off the device when there is not usage. | ||
261 | */ | ||
262 | static void lis3lv02d_decrease_use(struct acpi_lis3lv02d *dev) | ||
263 | { | ||
264 | mutex_lock(&dev->lock); | ||
265 | dev->usage--; | ||
266 | if (dev->usage == 0) | ||
267 | lis3lv02d_poweroff(dev->device->handle); | ||
268 | mutex_unlock(&dev->lock); | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * lis3lv02d_joystick_kthread - Kthread polling function | ||
273 | * @data: unused - here to conform to threadfn prototype | ||
274 | */ | ||
275 | static int lis3lv02d_joystick_kthread(void *data) | ||
276 | { | ||
277 | int x, y, z; | ||
278 | |||
279 | while (!kthread_should_stop()) { | ||
280 | lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z); | ||
281 | input_report_abs(adev.idev, ABS_X, x - adev.xcalib); | ||
282 | input_report_abs(adev.idev, ABS_Y, y - adev.ycalib); | ||
283 | input_report_abs(adev.idev, ABS_Z, z - adev.zcalib); | ||
284 | |||
285 | input_sync(adev.idev); | ||
286 | |||
287 | try_to_freeze(); | ||
288 | msleep_interruptible(MDPS_POLL_INTERVAL); | ||
289 | } | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | static int lis3lv02d_joystick_open(struct input_dev *input) | ||
295 | { | ||
296 | lis3lv02d_increase_use(&adev); | ||
297 | adev.kthread = kthread_run(lis3lv02d_joystick_kthread, NULL, "klis3lv02d"); | ||
298 | if (IS_ERR(adev.kthread)) { | ||
299 | lis3lv02d_decrease_use(&adev); | ||
300 | return PTR_ERR(adev.kthread); | ||
301 | } | ||
302 | |||
303 | return 0; | ||
304 | } | ||
305 | |||
306 | static void lis3lv02d_joystick_close(struct input_dev *input) | ||
307 | { | ||
308 | kthread_stop(adev.kthread); | ||
309 | lis3lv02d_decrease_use(&adev); | ||
310 | } | ||
311 | |||
312 | |||
313 | static inline void lis3lv02d_calibrate_joystick(void) | ||
314 | { | ||
315 | lis3lv02d_get_xyz(adev.device->handle, &adev.xcalib, &adev.ycalib, &adev.zcalib); | ||
316 | } | ||
317 | |||
318 | static int lis3lv02d_joystick_enable(void) | ||
319 | { | ||
320 | int err; | ||
321 | |||
322 | if (adev.idev) | ||
323 | return -EINVAL; | ||
324 | |||
325 | adev.idev = input_allocate_device(); | ||
326 | if (!adev.idev) | ||
327 | return -ENOMEM; | ||
328 | |||
329 | lis3lv02d_calibrate_joystick(); | ||
330 | |||
331 | adev.idev->name = "ST LIS3LV02DL Accelerometer"; | ||
332 | adev.idev->phys = DRIVER_NAME "/input0"; | ||
333 | adev.idev->id.bustype = BUS_HOST; | ||
334 | adev.idev->id.vendor = 0; | ||
335 | adev.idev->dev.parent = &adev.pdev->dev; | ||
336 | adev.idev->open = lis3lv02d_joystick_open; | ||
337 | adev.idev->close = lis3lv02d_joystick_close; | ||
338 | |||
339 | set_bit(EV_ABS, adev.idev->evbit); | ||
340 | input_set_abs_params(adev.idev, ABS_X, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3); | ||
341 | input_set_abs_params(adev.idev, ABS_Y, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3); | ||
342 | input_set_abs_params(adev.idev, ABS_Z, -MDPS_MAX_VAL, MDPS_MAX_VAL, 3, 3); | ||
343 | |||
344 | err = input_register_device(adev.idev); | ||
345 | if (err) { | ||
346 | input_free_device(adev.idev); | ||
347 | adev.idev = NULL; | ||
348 | } | ||
349 | |||
350 | return err; | ||
351 | } | ||
352 | |||
353 | static void lis3lv02d_joystick_disable(void) | ||
354 | { | ||
355 | if (!adev.idev) | ||
356 | return; | ||
357 | |||
358 | input_unregister_device(adev.idev); | ||
359 | adev.idev = NULL; | ||
360 | } | ||
361 | |||
362 | |||
363 | /* | ||
364 | * Initialise the accelerometer and the various subsystems. | ||
365 | * Should be rather independant of the bus system. | ||
366 | */ | ||
367 | static int lis3lv02d_init_device(struct acpi_lis3lv02d *dev) | ||
368 | { | ||
369 | mutex_init(&dev->lock); | ||
370 | lis3lv02d_add_fs(dev->device); | ||
371 | lis3lv02d_increase_use(dev); | ||
372 | |||
373 | if (lis3lv02d_joystick_enable()) | ||
374 | printk(KERN_ERR DRIVER_NAME ": joystick initialization failed\n"); | ||
375 | |||
376 | lis3lv02d_decrease_use(dev); | ||
377 | return 0; | ||
378 | } | ||
379 | |||
380 | static int lis3lv02d_dmi_matched(const struct dmi_system_id *dmi) | ||
381 | { | ||
382 | adev.ac = *((struct axis_conversion *)dmi->driver_data); | ||
383 | printk(KERN_INFO DRIVER_NAME ": hardware type %s found.\n", dmi->ident); | ||
384 | |||
385 | return 1; | ||
386 | } | ||
387 | |||
388 | /* Represents, for each axis seen by userspace, the corresponding hw axis (+1). | ||
389 | * If the value is negative, the opposite of the hw value is used. */ | ||
390 | static struct axis_conversion lis3lv02d_axis_normal = {1, 2, 3}; | ||
391 | static struct axis_conversion lis3lv02d_axis_y_inverted = {1, -2, 3}; | ||
392 | static struct axis_conversion lis3lv02d_axis_x_inverted = {-1, 2, 3}; | ||
393 | static struct axis_conversion lis3lv02d_axis_z_inverted = {1, 2, -3}; | ||
394 | static struct axis_conversion lis3lv02d_axis_xy_rotated_left = {-2, 1, 3}; | ||
395 | static struct axis_conversion lis3lv02d_axis_xy_swap_inverted = {-2, -1, 3}; | ||
396 | |||
397 | #define AXIS_DMI_MATCH(_ident, _name, _axis) { \ | ||
398 | .ident = _ident, \ | ||
399 | .callback = lis3lv02d_dmi_matched, \ | ||
400 | .matches = { \ | ||
401 | DMI_MATCH(DMI_PRODUCT_NAME, _name) \ | ||
402 | }, \ | ||
403 | .driver_data = &lis3lv02d_axis_##_axis \ | ||
404 | } | ||
405 | static struct dmi_system_id lis3lv02d_dmi_ids[] = { | ||
406 | /* product names are truncated to match all kinds of a same model */ | ||
407 | AXIS_DMI_MATCH("NC64x0", "HP Compaq nc64", x_inverted), | ||
408 | AXIS_DMI_MATCH("NC84x0", "HP Compaq nc84", z_inverted), | ||
409 | AXIS_DMI_MATCH("NX9420", "HP Compaq nx9420", x_inverted), | ||
410 | AXIS_DMI_MATCH("NW9440", "HP Compaq nw9440", x_inverted), | ||
411 | AXIS_DMI_MATCH("NC2510", "HP Compaq 2510", y_inverted), | ||
412 | AXIS_DMI_MATCH("NC8510", "HP Compaq 8510", xy_swap_inverted), | ||
413 | AXIS_DMI_MATCH("HP2133", "HP 2133", xy_rotated_left), | ||
414 | { NULL, } | ||
415 | /* Laptop models without axis info (yet): | ||
416 | * "NC651xx" "HP Compaq 651" | ||
417 | * "NC671xx" "HP Compaq 671" | ||
418 | * "NC6910" "HP Compaq 6910" | ||
419 | * HP Compaq 8710x Notebook PC / Mobile Workstation | ||
420 | * "NC2400" "HP Compaq nc2400" | ||
421 | * "NX74x0" "HP Compaq nx74" | ||
422 | * "NX6325" "HP Compaq nx6325" | ||
423 | * "NC4400" "HP Compaq nc4400" | ||
424 | */ | ||
425 | }; | ||
426 | |||
427 | static int lis3lv02d_add(struct acpi_device *device) | ||
428 | { | ||
429 | u8 val; | ||
430 | |||
431 | if (!device) | ||
432 | return -EINVAL; | ||
433 | |||
434 | adev.device = device; | ||
435 | strcpy(acpi_device_name(device), DRIVER_NAME); | ||
436 | strcpy(acpi_device_class(device), ACPI_MDPS_CLASS); | ||
437 | device->driver_data = &adev; | ||
438 | |||
439 | lis3lv02d_acpi_read(device->handle, WHO_AM_I, &val); | ||
440 | if ((val != LIS3LV02DL_ID) && (val != LIS302DL_ID)) { | ||
441 | printk(KERN_ERR DRIVER_NAME | ||
442 | ": Accelerometer chip not LIS3LV02D{L,Q}\n"); | ||
443 | } | ||
444 | |||
445 | /* If possible use a "standard" axes order */ | ||
446 | if (dmi_check_system(lis3lv02d_dmi_ids) == 0) { | ||
447 | printk(KERN_INFO DRIVER_NAME ": laptop model unknown, " | ||
448 | "using default axes configuration\n"); | ||
449 | adev.ac = lis3lv02d_axis_normal; | ||
450 | } | ||
451 | |||
452 | return lis3lv02d_init_device(&adev); | ||
453 | } | ||
454 | |||
455 | static int lis3lv02d_remove(struct acpi_device *device, int type) | ||
456 | { | ||
457 | if (!device) | ||
458 | return -EINVAL; | ||
459 | |||
460 | lis3lv02d_joystick_disable(); | ||
461 | lis3lv02d_poweroff(device->handle); | ||
462 | |||
463 | return lis3lv02d_remove_fs(); | ||
464 | } | ||
465 | |||
466 | |||
467 | /* Sysfs stuff */ | ||
468 | static ssize_t lis3lv02d_position_show(struct device *dev, | ||
469 | struct device_attribute *attr, char *buf) | ||
470 | { | ||
471 | int x, y, z; | ||
472 | |||
473 | lis3lv02d_increase_use(&adev); | ||
474 | lis3lv02d_get_xyz(adev.device->handle, &x, &y, &z); | ||
475 | lis3lv02d_decrease_use(&adev); | ||
476 | return sprintf(buf, "(%d,%d,%d)\n", x, y, z); | ||
477 | } | ||
478 | |||
479 | static ssize_t lis3lv02d_calibrate_show(struct device *dev, | ||
480 | struct device_attribute *attr, char *buf) | ||
481 | { | ||
482 | return sprintf(buf, "(%d,%d,%d)\n", adev.xcalib, adev.ycalib, adev.zcalib); | ||
483 | } | ||
484 | |||
485 | static ssize_t lis3lv02d_calibrate_store(struct device *dev, | ||
486 | struct device_attribute *attr, | ||
487 | const char *buf, size_t count) | ||
488 | { | ||
489 | lis3lv02d_increase_use(&adev); | ||
490 | lis3lv02d_calibrate_joystick(); | ||
491 | lis3lv02d_decrease_use(&adev); | ||
492 | return count; | ||
493 | } | ||
494 | |||
495 | /* conversion btw sampling rate and the register values */ | ||
496 | static int lis3lv02dl_df_val[4] = {40, 160, 640, 2560}; | ||
497 | static ssize_t lis3lv02d_rate_show(struct device *dev, | ||
498 | struct device_attribute *attr, char *buf) | ||
499 | { | ||
500 | u8 ctrl; | ||
501 | int val; | ||
502 | |||
503 | lis3lv02d_increase_use(&adev); | ||
504 | lis3lv02d_acpi_read(adev.device->handle, CTRL_REG1, &ctrl); | ||
505 | lis3lv02d_decrease_use(&adev); | ||
506 | val = (ctrl & (CTRL1_DF0 | CTRL1_DF1)) >> 4; | ||
507 | return sprintf(buf, "%d\n", lis3lv02dl_df_val[val]); | ||
508 | } | ||
509 | |||
510 | static DEVICE_ATTR(position, S_IRUGO, lis3lv02d_position_show, NULL); | ||
511 | static DEVICE_ATTR(calibrate, S_IRUGO|S_IWUSR, lis3lv02d_calibrate_show, | ||
512 | lis3lv02d_calibrate_store); | ||
513 | static DEVICE_ATTR(rate, S_IRUGO, lis3lv02d_rate_show, NULL); | ||
514 | |||
515 | static struct attribute *lis3lv02d_attributes[] = { | ||
516 | &dev_attr_position.attr, | ||
517 | &dev_attr_calibrate.attr, | ||
518 | &dev_attr_rate.attr, | ||
519 | NULL | ||
520 | }; | ||
521 | |||
522 | static struct attribute_group lis3lv02d_attribute_group = { | ||
523 | .attrs = lis3lv02d_attributes | ||
524 | }; | ||
525 | |||
526 | static int lis3lv02d_add_fs(struct acpi_device *device) | ||
527 | { | ||
528 | adev.pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); | ||
529 | if (IS_ERR(adev.pdev)) | ||
530 | return PTR_ERR(adev.pdev); | ||
531 | |||
532 | return sysfs_create_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group); | ||
533 | } | ||
534 | |||
535 | static int lis3lv02d_remove_fs(void) | ||
536 | { | ||
537 | sysfs_remove_group(&adev.pdev->dev.kobj, &lis3lv02d_attribute_group); | ||
538 | platform_device_unregister(adev.pdev); | ||
539 | return 0; | ||
540 | } | ||
541 | |||
542 | /* For the HP MDPS aka 3D Driveguard */ | ||
543 | static struct acpi_driver lis3lv02d_driver = { | ||
544 | .name = DRIVER_NAME, | ||
545 | .class = ACPI_MDPS_CLASS, | ||
546 | .ids = lis3lv02d_device_ids, | ||
547 | .ops = { | ||
548 | .add = lis3lv02d_add, | ||
549 | .remove = lis3lv02d_remove, | ||
550 | .suspend = lis3lv02d_suspend, | ||
551 | .resume = lis3lv02d_resume, | ||
552 | } | ||
553 | }; | ||
554 | |||
555 | static int __init lis3lv02d_init_module(void) | ||
556 | { | ||
557 | int ret; | ||
558 | |||
559 | if (acpi_disabled) | ||
560 | return -ENODEV; | ||
561 | |||
562 | ret = acpi_bus_register_driver(&lis3lv02d_driver); | ||
563 | if (ret < 0) | ||
564 | return ret; | ||
565 | |||
566 | printk(KERN_INFO DRIVER_NAME " driver loaded.\n"); | ||
567 | |||
568 | return 0; | ||
569 | } | ||
570 | |||
571 | static void __exit lis3lv02d_exit_module(void) | ||
572 | { | ||
573 | acpi_bus_unregister_driver(&lis3lv02d_driver); | ||
574 | } | ||
575 | |||
576 | MODULE_DESCRIPTION("ST LIS3LV02Dx three-axis digital accelerometer driver"); | ||
577 | MODULE_AUTHOR("Yan Burman and Eric Piel"); | ||
578 | MODULE_LICENSE("GPL"); | ||
579 | |||
580 | module_init(lis3lv02d_init_module); | ||
581 | module_exit(lis3lv02d_exit_module); | ||
diff --git a/drivers/hwmon/lis3lv02d.h b/drivers/hwmon/lis3lv02d.h new file mode 100644 index 000000000000..330cfc60e948 --- /dev/null +++ b/drivers/hwmon/lis3lv02d.h | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * lis3lv02d.h - ST LIS3LV02DL accelerometer driver | ||
3 | * | ||
4 | * Copyright (C) 2007-2008 Yan Burman | ||
5 | * Copyright (C) 2008 Eric Piel | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | /* | ||
23 | * The actual chip is STMicroelectronics LIS3LV02DL or LIS3LV02DQ that seems to | ||
24 | * be connected via SPI. There exists also several similar chips (such as LIS302DL or | ||
25 | * LIS3L02DQ) but not in the HP laptops and they have slightly different registers. | ||
26 | * They can also be connected via I²C. | ||
27 | */ | ||
28 | |||
29 | #define LIS3LV02DL_ID 0x3A /* Also the LIS3LV02DQ */ | ||
30 | #define LIS302DL_ID 0x3B /* Also the LIS202DL! */ | ||
31 | |||
32 | enum lis3lv02d_reg { | ||
33 | WHO_AM_I = 0x0F, | ||
34 | OFFSET_X = 0x16, | ||
35 | OFFSET_Y = 0x17, | ||
36 | OFFSET_Z = 0x18, | ||
37 | GAIN_X = 0x19, | ||
38 | GAIN_Y = 0x1A, | ||
39 | GAIN_Z = 0x1B, | ||
40 | CTRL_REG1 = 0x20, | ||
41 | CTRL_REG2 = 0x21, | ||
42 | CTRL_REG3 = 0x22, | ||
43 | HP_FILTER_RESET = 0x23, | ||
44 | STATUS_REG = 0x27, | ||
45 | OUTX_L = 0x28, | ||
46 | OUTX_H = 0x29, | ||
47 | OUTY_L = 0x2A, | ||
48 | OUTY_H = 0x2B, | ||
49 | OUTZ_L = 0x2C, | ||
50 | OUTZ_H = 0x2D, | ||
51 | FF_WU_CFG = 0x30, | ||
52 | FF_WU_SRC = 0x31, | ||
53 | FF_WU_ACK = 0x32, | ||
54 | FF_WU_THS_L = 0x34, | ||
55 | FF_WU_THS_H = 0x35, | ||
56 | FF_WU_DURATION = 0x36, | ||
57 | DD_CFG = 0x38, | ||
58 | DD_SRC = 0x39, | ||
59 | DD_ACK = 0x3A, | ||
60 | DD_THSI_L = 0x3C, | ||
61 | DD_THSI_H = 0x3D, | ||
62 | DD_THSE_L = 0x3E, | ||
63 | DD_THSE_H = 0x3F, | ||
64 | }; | ||
65 | |||
66 | enum lis3lv02d_ctrl1 { | ||
67 | CTRL1_Xen = 0x01, | ||
68 | CTRL1_Yen = 0x02, | ||
69 | CTRL1_Zen = 0x04, | ||
70 | CTRL1_ST = 0x08, | ||
71 | CTRL1_DF0 = 0x10, | ||
72 | CTRL1_DF1 = 0x20, | ||
73 | CTRL1_PD0 = 0x40, | ||
74 | CTRL1_PD1 = 0x80, | ||
75 | }; | ||
76 | enum lis3lv02d_ctrl2 { | ||
77 | CTRL2_DAS = 0x01, | ||
78 | CTRL2_SIM = 0x02, | ||
79 | CTRL2_DRDY = 0x04, | ||
80 | CTRL2_IEN = 0x08, | ||
81 | CTRL2_BOOT = 0x10, | ||
82 | CTRL2_BLE = 0x20, | ||
83 | CTRL2_BDU = 0x40, /* Block Data Update */ | ||
84 | CTRL2_FS = 0x80, /* Full Scale selection */ | ||
85 | }; | ||
86 | |||
87 | |||
88 | enum lis3lv02d_ctrl3 { | ||
89 | CTRL3_CFS0 = 0x01, | ||
90 | CTRL3_CFS1 = 0x02, | ||
91 | CTRL3_FDS = 0x10, | ||
92 | CTRL3_HPFF = 0x20, | ||
93 | CTRL3_HPDD = 0x40, | ||
94 | CTRL3_ECK = 0x80, | ||
95 | }; | ||
96 | |||
97 | enum lis3lv02d_status_reg { | ||
98 | STATUS_XDA = 0x01, | ||
99 | STATUS_YDA = 0x02, | ||
100 | STATUS_ZDA = 0x04, | ||
101 | STATUS_XYZDA = 0x08, | ||
102 | STATUS_XOR = 0x10, | ||
103 | STATUS_YOR = 0x20, | ||
104 | STATUS_ZOR = 0x40, | ||
105 | STATUS_XYZOR = 0x80, | ||
106 | }; | ||
107 | |||
108 | enum lis3lv02d_ff_wu_cfg { | ||
109 | FF_WU_CFG_XLIE = 0x01, | ||
110 | FF_WU_CFG_XHIE = 0x02, | ||
111 | FF_WU_CFG_YLIE = 0x04, | ||
112 | FF_WU_CFG_YHIE = 0x08, | ||
113 | FF_WU_CFG_ZLIE = 0x10, | ||
114 | FF_WU_CFG_ZHIE = 0x20, | ||
115 | FF_WU_CFG_LIR = 0x40, | ||
116 | FF_WU_CFG_AOI = 0x80, | ||
117 | }; | ||
118 | |||
119 | enum lis3lv02d_ff_wu_src { | ||
120 | FF_WU_SRC_XL = 0x01, | ||
121 | FF_WU_SRC_XH = 0x02, | ||
122 | FF_WU_SRC_YL = 0x04, | ||
123 | FF_WU_SRC_YH = 0x08, | ||
124 | FF_WU_SRC_ZL = 0x10, | ||
125 | FF_WU_SRC_ZH = 0x20, | ||
126 | FF_WU_SRC_IA = 0x40, | ||
127 | }; | ||
128 | |||
129 | enum lis3lv02d_dd_cfg { | ||
130 | DD_CFG_XLIE = 0x01, | ||
131 | DD_CFG_XHIE = 0x02, | ||
132 | DD_CFG_YLIE = 0x04, | ||
133 | DD_CFG_YHIE = 0x08, | ||
134 | DD_CFG_ZLIE = 0x10, | ||
135 | DD_CFG_ZHIE = 0x20, | ||
136 | DD_CFG_LIR = 0x40, | ||
137 | DD_CFG_IEND = 0x80, | ||
138 | }; | ||
139 | |||
140 | enum lis3lv02d_dd_src { | ||
141 | DD_SRC_XL = 0x01, | ||
142 | DD_SRC_XH = 0x02, | ||
143 | DD_SRC_YL = 0x04, | ||
144 | DD_SRC_YH = 0x08, | ||
145 | DD_SRC_ZL = 0x10, | ||
146 | DD_SRC_ZH = 0x20, | ||
147 | DD_SRC_IA = 0x40, | ||
148 | }; | ||
149 | |||
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 3ff0285396fa..cfc1ee90f5a3 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -39,7 +39,8 @@ | |||
39 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; | 39 | static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; |
40 | 40 | ||
41 | /* Insmod parameters */ | 41 | /* Insmod parameters */ |
42 | I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); | 42 | I2C_CLIENT_INSMOD_7(lm85b, lm85c, adm1027, adt7463, adt7468, emc6d100, |
43 | emc6d102); | ||
43 | 44 | ||
44 | /* The LM85 registers */ | 45 | /* The LM85 registers */ |
45 | 46 | ||
@@ -59,6 +60,12 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); | |||
59 | 60 | ||
60 | #define LM85_REG_COMPANY 0x3e | 61 | #define LM85_REG_COMPANY 0x3e |
61 | #define LM85_REG_VERSTEP 0x3f | 62 | #define LM85_REG_VERSTEP 0x3f |
63 | |||
64 | #define ADT7468_REG_CFG5 0x7c | ||
65 | #define ADT7468_OFF64 0x01 | ||
66 | #define IS_ADT7468_OFF64(data) \ | ||
67 | ((data)->type == adt7468 && !((data)->cfg5 & ADT7468_OFF64)) | ||
68 | |||
62 | /* These are the recognized values for the above regs */ | 69 | /* These are the recognized values for the above regs */ |
63 | #define LM85_COMPANY_NATIONAL 0x01 | 70 | #define LM85_COMPANY_NATIONAL 0x01 |
64 | #define LM85_COMPANY_ANALOG_DEV 0x41 | 71 | #define LM85_COMPANY_ANALOG_DEV 0x41 |
@@ -70,6 +77,8 @@ I2C_CLIENT_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102); | |||
70 | #define LM85_VERSTEP_ADM1027 0x60 | 77 | #define LM85_VERSTEP_ADM1027 0x60 |
71 | #define LM85_VERSTEP_ADT7463 0x62 | 78 | #define LM85_VERSTEP_ADT7463 0x62 |
72 | #define LM85_VERSTEP_ADT7463C 0x6A | 79 | #define LM85_VERSTEP_ADT7463C 0x6A |
80 | #define LM85_VERSTEP_ADT7468_1 0x71 | ||
81 | #define LM85_VERSTEP_ADT7468_2 0x72 | ||
73 | #define LM85_VERSTEP_EMC6D100_A0 0x60 | 82 | #define LM85_VERSTEP_EMC6D100_A0 0x60 |
74 | #define LM85_VERSTEP_EMC6D100_A1 0x61 | 83 | #define LM85_VERSTEP_EMC6D100_A1 0x61 |
75 | #define LM85_VERSTEP_EMC6D102 0x65 | 84 | #define LM85_VERSTEP_EMC6D102 0x65 |
@@ -306,6 +315,7 @@ struct lm85_data { | |||
306 | u8 vid; /* Register value */ | 315 | u8 vid; /* Register value */ |
307 | u8 vrm; /* VRM version */ | 316 | u8 vrm; /* VRM version */ |
308 | u32 alarms; /* Register encoding, combined */ | 317 | u32 alarms; /* Register encoding, combined */ |
318 | u8 cfg5; /* Config Register 5 on ADT7468 */ | ||
309 | struct lm85_autofan autofan[3]; | 319 | struct lm85_autofan autofan[3]; |
310 | struct lm85_zone zone[3]; | 320 | struct lm85_zone zone[3]; |
311 | }; | 321 | }; |
@@ -685,6 +695,9 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | |||
685 | struct lm85_data *data = i2c_get_clientdata(client); | 695 | struct lm85_data *data = i2c_get_clientdata(client); |
686 | long val = simple_strtol(buf, NULL, 10); | 696 | long val = simple_strtol(buf, NULL, 10); |
687 | 697 | ||
698 | if (IS_ADT7468_OFF64(data)) | ||
699 | val += 64; | ||
700 | |||
688 | mutex_lock(&data->update_lock); | 701 | mutex_lock(&data->update_lock); |
689 | data->temp_min[nr] = TEMP_TO_REG(val); | 702 | data->temp_min[nr] = TEMP_TO_REG(val); |
690 | lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); | 703 | lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); |
@@ -708,6 +721,9 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | |||
708 | struct lm85_data *data = i2c_get_clientdata(client); | 721 | struct lm85_data *data = i2c_get_clientdata(client); |
709 | long val = simple_strtol(buf, NULL, 10); | 722 | long val = simple_strtol(buf, NULL, 10); |
710 | 723 | ||
724 | if (IS_ADT7468_OFF64(data)) | ||
725 | val += 64; | ||
726 | |||
711 | mutex_lock(&data->update_lock); | 727 | mutex_lock(&data->update_lock); |
712 | data->temp_max[nr] = TEMP_TO_REG(val); | 728 | data->temp_max[nr] = TEMP_TO_REG(val); |
713 | lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); | 729 | lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); |
@@ -1163,6 +1179,10 @@ static int lm85_detect(struct i2c_client *client, int kind, | |||
1163 | case LM85_VERSTEP_ADT7463C: | 1179 | case LM85_VERSTEP_ADT7463C: |
1164 | kind = adt7463; | 1180 | kind = adt7463; |
1165 | break; | 1181 | break; |
1182 | case LM85_VERSTEP_ADT7468_1: | ||
1183 | case LM85_VERSTEP_ADT7468_2: | ||
1184 | kind = adt7468; | ||
1185 | break; | ||
1166 | } | 1186 | } |
1167 | } else if (company == LM85_COMPANY_SMSC) { | 1187 | } else if (company == LM85_COMPANY_SMSC) { |
1168 | switch (verstep) { | 1188 | switch (verstep) { |
@@ -1195,6 +1215,9 @@ static int lm85_detect(struct i2c_client *client, int kind, | |||
1195 | case adt7463: | 1215 | case adt7463: |
1196 | type_name = "adt7463"; | 1216 | type_name = "adt7463"; |
1197 | break; | 1217 | break; |
1218 | case adt7468: | ||
1219 | type_name = "adt7468"; | ||
1220 | break; | ||
1198 | case emc6d100: | 1221 | case emc6d100: |
1199 | type_name = "emc6d100"; | 1222 | type_name = "emc6d100"; |
1200 | break; | 1223 | break; |
@@ -1246,10 +1269,11 @@ static int lm85_probe(struct i2c_client *client, | |||
1246 | if (err) | 1269 | if (err) |
1247 | goto err_kfree; | 1270 | goto err_kfree; |
1248 | 1271 | ||
1249 | /* The ADT7463 has an optional VRM 10 mode where pin 21 is used | 1272 | /* The ADT7463/68 have an optional VRM 10 mode where pin 21 is used |
1250 | as a sixth digital VID input rather than an analog input. */ | 1273 | as a sixth digital VID input rather than an analog input. */ |
1251 | data->vid = lm85_read_value(client, LM85_REG_VID); | 1274 | data->vid = lm85_read_value(client, LM85_REG_VID); |
1252 | if (!(data->type == adt7463 && (data->vid & 0x80))) | 1275 | if (!((data->type == adt7463 || data->type == adt7468) && |
1276 | (data->vid & 0x80))) | ||
1253 | if ((err = sysfs_create_group(&client->dev.kobj, | 1277 | if ((err = sysfs_create_group(&client->dev.kobj, |
1254 | &lm85_group_in4))) | 1278 | &lm85_group_in4))) |
1255 | goto err_remove_files; | 1279 | goto err_remove_files; |
@@ -1357,7 +1381,8 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1357 | * There are 2 additional resolution bits per channel and we | 1381 | * There are 2 additional resolution bits per channel and we |
1358 | * have room for 4, so we shift them to the left. | 1382 | * have room for 4, so we shift them to the left. |
1359 | */ | 1383 | */ |
1360 | if (data->type == adm1027 || data->type == adt7463) { | 1384 | if (data->type == adm1027 || data->type == adt7463 || |
1385 | data->type == adt7468) { | ||
1361 | int ext1 = lm85_read_value(client, | 1386 | int ext1 = lm85_read_value(client, |
1362 | ADM1027_REG_EXTEND_ADC1); | 1387 | ADM1027_REG_EXTEND_ADC1); |
1363 | int ext2 = lm85_read_value(client, | 1388 | int ext2 = lm85_read_value(client, |
@@ -1382,16 +1407,23 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1382 | lm85_read_value(client, LM85_REG_FAN(i)); | 1407 | lm85_read_value(client, LM85_REG_FAN(i)); |
1383 | } | 1408 | } |
1384 | 1409 | ||
1385 | if (!(data->type == adt7463 && (data->vid & 0x80))) { | 1410 | if (!((data->type == adt7463 || data->type == adt7468) && |
1411 | (data->vid & 0x80))) { | ||
1386 | data->in[4] = lm85_read_value(client, | 1412 | data->in[4] = lm85_read_value(client, |
1387 | LM85_REG_IN(4)); | 1413 | LM85_REG_IN(4)); |
1388 | } | 1414 | } |
1389 | 1415 | ||
1416 | if (data->type == adt7468) | ||
1417 | data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5); | ||
1418 | |||
1390 | for (i = 0; i <= 2; ++i) { | 1419 | for (i = 0; i <= 2; ++i) { |
1391 | data->temp[i] = | 1420 | data->temp[i] = |
1392 | lm85_read_value(client, LM85_REG_TEMP(i)); | 1421 | lm85_read_value(client, LM85_REG_TEMP(i)); |
1393 | data->pwm[i] = | 1422 | data->pwm[i] = |
1394 | lm85_read_value(client, LM85_REG_PWM(i)); | 1423 | lm85_read_value(client, LM85_REG_PWM(i)); |
1424 | |||
1425 | if (IS_ADT7468_OFF64(data)) | ||
1426 | data->temp[i] -= 64; | ||
1395 | } | 1427 | } |
1396 | 1428 | ||
1397 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); | 1429 | data->alarms = lm85_read_value(client, LM85_REG_ALARM1); |
@@ -1446,7 +1478,8 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1446 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); | 1478 | lm85_read_value(client, LM85_REG_FAN_MIN(i)); |
1447 | } | 1479 | } |
1448 | 1480 | ||
1449 | if (!(data->type == adt7463 && (data->vid & 0x80))) { | 1481 | if (!((data->type == adt7463 || data->type == adt7468) && |
1482 | (data->vid & 0x80))) { | ||
1450 | data->in_min[4] = lm85_read_value(client, | 1483 | data->in_min[4] = lm85_read_value(client, |
1451 | LM85_REG_IN_MIN(4)); | 1484 | LM85_REG_IN_MIN(4)); |
1452 | data->in_max[4] = lm85_read_value(client, | 1485 | data->in_max[4] = lm85_read_value(client, |
@@ -1481,6 +1514,13 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1481 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); | 1514 | lm85_read_value(client, LM85_REG_AFAN_LIMIT(i)); |
1482 | data->zone[i].critical = | 1515 | data->zone[i].critical = |
1483 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); | 1516 | lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i)); |
1517 | |||
1518 | if (IS_ADT7468_OFF64(data)) { | ||
1519 | data->temp_min[i] -= 64; | ||
1520 | data->temp_max[i] -= 64; | ||
1521 | data->zone[i].limit -= 64; | ||
1522 | data->zone[i].critical -= 64; | ||
1523 | } | ||
1484 | } | 1524 | } |
1485 | 1525 | ||
1486 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); | 1526 | i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1); |