aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig42
-rw-r--r--drivers/hwmon/Makefile3
-rw-r--r--drivers/hwmon/abituguru.c3
-rw-r--r--drivers/hwmon/abituguru3.c13
-rw-r--r--drivers/hwmon/acpi_power_meter.c1023
-rw-r--r--drivers/hwmon/adcxx.c16
-rw-r--r--drivers/hwmon/emc6w201.c539
-rw-r--r--drivers/hwmon/f71882fg.c115
-rw-r--r--drivers/hwmon/fam15h_power.c229
-rw-r--r--drivers/hwmon/ibmaem.c10
-rw-r--r--drivers/hwmon/it87.c31
-rw-r--r--drivers/hwmon/jc42.c2
-rw-r--r--drivers/hwmon/k10temp.c11
-rw-r--r--drivers/hwmon/k8temp.c8
-rw-r--r--drivers/hwmon/lm70.c10
-rw-r--r--drivers/hwmon/max6650.c78
-rw-r--r--drivers/hwmon/sch5627.c46
-rw-r--r--drivers/hwmon/ultra45_env.c4
18 files changed, 2054 insertions, 129 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 43221beb9e97..16db83c83c8b 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -41,7 +41,7 @@ comment "Native drivers"
41 41
42config SENSORS_ABITUGURU 42config SENSORS_ABITUGURU
43 tristate "Abit uGuru (rev 1 & 2)" 43 tristate "Abit uGuru (rev 1 & 2)"
44 depends on X86 && EXPERIMENTAL 44 depends on X86 && DMI && EXPERIMENTAL
45 help 45 help
46 If you say yes here you get support for the sensor part of the first 46 If you say yes here you get support for the sensor part of the first
47 and second revision of the Abit uGuru chip. The voltage and frequency 47 and second revision of the Abit uGuru chip. The voltage and frequency
@@ -56,7 +56,7 @@ config SENSORS_ABITUGURU
56 56
57config SENSORS_ABITUGURU3 57config SENSORS_ABITUGURU3
58 tristate "Abit uGuru (rev 3)" 58 tristate "Abit uGuru (rev 3)"
59 depends on X86 && EXPERIMENTAL 59 depends on X86 && DMI && EXPERIMENTAL
60 help 60 help
61 If you say yes here you get support for the sensor part of the 61 If you say yes here you get support for the sensor part of the
62 third revision of the Abit uGuru chip. Only reading the sensors 62 third revision of the Abit uGuru chip. Only reading the sensors
@@ -213,7 +213,7 @@ config SENSORS_ADT7475
213 213
214config SENSORS_ASC7621 214config SENSORS_ASC7621
215 tristate "Andigilog aSC7621" 215 tristate "Andigilog aSC7621"
216 depends on HWMON && I2C 216 depends on I2C
217 help 217 help
218 If you say yes here you get support for the aSC7621 218 If you say yes here you get support for the aSC7621
219 family of SMBus sensors chip found on most Intel X38, X48, X58, 219 family of SMBus sensors chip found on most Intel X38, X48, X58,
@@ -237,17 +237,27 @@ config SENSORS_K8TEMP
237 will be called k8temp. 237 will be called k8temp.
238 238
239config SENSORS_K10TEMP 239config SENSORS_K10TEMP
240 tristate "AMD Family 10h/11h/12h/14h temperature sensor" 240 tristate "AMD Family 10h+ temperature sensor"
241 depends on X86 && PCI 241 depends on X86 && PCI
242 help 242 help
243 If you say yes here you get support for the temperature 243 If you say yes here you get support for the temperature
244 sensor(s) inside your CPU. Supported are later revisions of 244 sensor(s) inside your CPU. Supported are later revisions of
245 the AMD Family 10h and all revisions of the AMD Family 11h, 245 the AMD Family 10h and all revisions of the AMD Family 11h,
246 12h (Llano), and 14h (Brazos) microarchitectures. 246 12h (Llano), 14h (Brazos) and 15h (Bulldozer) microarchitectures.
247 247
248 This driver can also be built as a module. If so, the module 248 This driver can also be built as a module. If so, the module
249 will be called k10temp. 249 will be called k10temp.
250 250
251config SENSORS_FAM15H_POWER
252 tristate "AMD Family 15h processor power"
253 depends on X86 && PCI
254 help
255 If you say yes here you get support for processor power
256 information of your AMD family 15h CPU.
257
258 This driver can also be built as a module. If so, the module
259 will be called fam15h_power.
260
251config SENSORS_ASB100 261config SENSORS_ASB100
252 tristate "Asus ASB100 Bach" 262 tristate "Asus ASB100 Bach"
253 depends on X86 && I2C && EXPERIMENTAL 263 depends on X86 && I2C && EXPERIMENTAL
@@ -319,7 +329,7 @@ config SENSORS_F71882FG
319 If you say yes here you get support for hardware monitoring 329 If you say yes here you get support for hardware monitoring
320 features of many Fintek Super-I/O (LPC) chips. The currently 330 features of many Fintek Super-I/O (LPC) chips. The currently
321 supported chips are: 331 supported chips are:
322 F71808E 332 F71808E/A
323 F71858FG 333 F71858FG
324 F71862FG 334 F71862FG
325 F71863FG 335 F71863FG
@@ -978,6 +988,16 @@ config SENSORS_EMC2103
978 This driver can also be built as a module. If so, the module 988 This driver can also be built as a module. If so, the module
979 will be called emc2103. 989 will be called emc2103.
980 990
991config SENSORS_EMC6W201
992 tristate "SMSC EMC6W201"
993 depends on I2C
994 help
995 If you say yes here you get support for the SMSC EMC6W201
996 hardware monitoring chip.
997
998 This driver can also be built as a module. If so, the module
999 will be called emc6w201.
1000
981config SENSORS_SMSC47M1 1001config SENSORS_SMSC47M1
982 tristate "SMSC LPC47M10x and compatibles" 1002 tristate "SMSC LPC47M10x and compatibles"
983 help 1003 help
@@ -1341,6 +1361,16 @@ if ACPI
1341 1361
1342comment "ACPI drivers" 1362comment "ACPI drivers"
1343 1363
1364config SENSORS_ACPI_POWER
1365 tristate "ACPI 4.0 power meter"
1366 help
1367 This driver exposes ACPI 4.0 power meters as hardware monitoring
1368 devices. Say Y (or M) if you have a computer with ACPI 4.0 firmware
1369 and a power meter.
1370
1371 To compile this driver as a module, choose M here:
1372 the module will be called acpi_power_meter.
1373
1344config SENSORS_ATK0110 1374config SENSORS_ATK0110
1345 tristate "ASUS ATK0110" 1375 tristate "ASUS ATK0110"
1346 depends on X86 && EXPERIMENTAL 1376 depends on X86 && EXPERIMENTAL
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 28e8d52f6379..28061cfa0cdb 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_HWMON) += hwmon.o
6obj-$(CONFIG_HWMON_VID) += hwmon-vid.o 6obj-$(CONFIG_HWMON_VID) += hwmon-vid.o
7 7
8# APCI drivers 8# APCI drivers
9obj-$(CONFIG_SENSORS_ACPI_POWER) += acpi_power_meter.o
9obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o 10obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o
10 11
11# Native drivers 12# Native drivers
@@ -45,9 +46,11 @@ obj-$(CONFIG_SENSORS_DS620) += ds620.o
45obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 46obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
46obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o 47obj-$(CONFIG_SENSORS_EMC1403) += emc1403.o
47obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o 48obj-$(CONFIG_SENSORS_EMC2103) += emc2103.o
49obj-$(CONFIG_SENSORS_EMC6W201) += emc6w201.o
48obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 50obj-$(CONFIG_SENSORS_F71805F) += f71805f.o
49obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o 51obj-$(CONFIG_SENSORS_F71882FG) += f71882fg.o
50obj-$(CONFIG_SENSORS_F75375S) += f75375s.o 52obj-$(CONFIG_SENSORS_F75375S) += f75375s.o
53obj-$(CONFIG_SENSORS_FAM15H_POWER) += fam15h_power.o
51obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o 54obj-$(CONFIG_SENSORS_FSCHMD) += fschmd.o
52obj-$(CONFIG_SENSORS_G760A) += g760a.o 55obj-$(CONFIG_SENSORS_G760A) += g760a.o
53obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o 56obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index e7d4c4687f02..65a35cf5b3c5 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1448,15 +1448,12 @@ static int __init abituguru_init(void)
1448{ 1448{
1449 int address, err; 1449 int address, err;
1450 struct resource res = { .flags = IORESOURCE_IO }; 1450 struct resource res = { .flags = IORESOURCE_IO };
1451
1452#ifdef CONFIG_DMI
1453 const char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); 1451 const char *board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1454 1452
1455 /* safety check, refuse to load on non Abit motherboards */ 1453 /* safety check, refuse to load on non Abit motherboards */
1456 if (!force && (!board_vendor || 1454 if (!force && (!board_vendor ||
1457 strcmp(board_vendor, "http://www.abit.com.tw/"))) 1455 strcmp(board_vendor, "http://www.abit.com.tw/")))
1458 return -ENODEV; 1456 return -ENODEV;
1459#endif
1460 1457
1461 address = abituguru_detect(); 1458 address = abituguru_detect();
1462 if (address < 0) 1459 if (address < 0)
diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
index e89d572e3320..d30855a75786 100644
--- a/drivers/hwmon/abituguru3.c
+++ b/drivers/hwmon/abituguru3.c
@@ -1119,8 +1119,6 @@ static struct platform_driver abituguru3_driver = {
1119 .resume = abituguru3_resume 1119 .resume = abituguru3_resume
1120}; 1120};
1121 1121
1122#ifdef CONFIG_DMI
1123
1124static int __init abituguru3_dmi_detect(void) 1122static int __init abituguru3_dmi_detect(void)
1125{ 1123{
1126 const char *board_vendor, *board_name; 1124 const char *board_vendor, *board_name;
@@ -1159,15 +1157,6 @@ static int __init abituguru3_dmi_detect(void)
1159 return 1; 1157 return 1;
1160} 1158}
1161 1159
1162#else /* !CONFIG_DMI */
1163
1164static inline int abituguru3_dmi_detect(void)
1165{
1166 return 1;
1167}
1168
1169#endif /* CONFIG_DMI */
1170
1171/* FIXME: Manual detection should die eventually; we need to collect stable 1160/* FIXME: Manual detection should die eventually; we need to collect stable
1172 * DMI model names first before we can rely entirely on CONFIG_DMI. 1161 * DMI model names first before we can rely entirely on CONFIG_DMI.
1173 */ 1162 */
@@ -1216,10 +1205,8 @@ static int __init abituguru3_init(void)
1216 if (err) 1205 if (err)
1217 return err; 1206 return err;
1218 1207
1219#ifdef CONFIG_DMI
1220 pr_warn("this motherboard was not detected using DMI. " 1208 pr_warn("this motherboard was not detected using DMI. "
1221 "Please send the output of \"dmidecode\" to the abituguru3 maintainer (see MAINTAINERS)\n"); 1209 "Please send the output of \"dmidecode\" to the abituguru3 maintainer (see MAINTAINERS)\n");
1222#endif
1223 } 1210 }
1224 1211
1225 err = platform_driver_register(&abituguru3_driver); 1212 err = platform_driver_register(&abituguru3_driver);
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
new file mode 100644
index 000000000000..66f67293341e
--- /dev/null
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -0,0 +1,1023 @@
1/*
2 * A hwmon driver for ACPI 4.0 power meters
3 * Copyright (C) 2009 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/hwmon.h>
24#include <linux/hwmon-sysfs.h>
25#include <linux/jiffies.h>
26#include <linux/mutex.h>
27#include <linux/dmi.h>
28#include <linux/slab.h>
29#include <linux/kdev_t.h>
30#include <linux/sched.h>
31#include <linux/time.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34
35#define ACPI_POWER_METER_NAME "power_meter"
36ACPI_MODULE_NAME(ACPI_POWER_METER_NAME);
37#define ACPI_POWER_METER_DEVICE_NAME "Power Meter"
38#define ACPI_POWER_METER_CLASS "pwr_meter_resource"
39
40#define NUM_SENSORS 17
41
42#define POWER_METER_CAN_MEASURE (1 << 0)
43#define POWER_METER_CAN_TRIP (1 << 1)
44#define POWER_METER_CAN_CAP (1 << 2)
45#define POWER_METER_CAN_NOTIFY (1 << 3)
46#define POWER_METER_IS_BATTERY (1 << 8)
47#define UNKNOWN_HYSTERESIS 0xFFFFFFFF
48
49#define METER_NOTIFY_CONFIG 0x80
50#define METER_NOTIFY_TRIP 0x81
51#define METER_NOTIFY_CAP 0x82
52#define METER_NOTIFY_CAPPING 0x83
53#define METER_NOTIFY_INTERVAL 0x84
54
55#define POWER_AVERAGE_NAME "power1_average"
56#define POWER_CAP_NAME "power1_cap"
57#define POWER_AVG_INTERVAL_NAME "power1_average_interval"
58#define POWER_ALARM_NAME "power1_alarm"
59
60static int cap_in_hardware;
61static int force_cap_on;
62
63static int can_cap_in_hardware(void)
64{
65 return force_cap_on || cap_in_hardware;
66}
67
68static const struct acpi_device_id power_meter_ids[] = {
69 {"ACPI000D", 0},
70 {"", 0},
71};
72MODULE_DEVICE_TABLE(acpi, power_meter_ids);
73
74struct acpi_power_meter_capabilities {
75 u64 flags;
76 u64 units;
77 u64 type;
78 u64 accuracy;
79 u64 sampling_time;
80 u64 min_avg_interval;
81 u64 max_avg_interval;
82 u64 hysteresis;
83 u64 configurable_cap;
84 u64 min_cap;
85 u64 max_cap;
86};
87
88struct acpi_power_meter_resource {
89 struct acpi_device *acpi_dev;
90 acpi_bus_id name;
91 struct mutex lock;
92 struct device *hwmon_dev;
93 struct acpi_power_meter_capabilities caps;
94 acpi_string model_number;
95 acpi_string serial_number;
96 acpi_string oem_info;
97 u64 power;
98 u64 cap;
99 u64 avg_interval;
100 int sensors_valid;
101 unsigned long sensors_last_updated;
102 struct sensor_device_attribute sensors[NUM_SENSORS];
103 int num_sensors;
104 int trip[2];
105 int num_domain_devices;
106 struct acpi_device **domain_devices;
107 struct kobject *holders_dir;
108};
109
110struct ro_sensor_template {
111 char *label;
112 ssize_t (*show)(struct device *dev,
113 struct device_attribute *devattr,
114 char *buf);
115 int index;
116};
117
118struct rw_sensor_template {
119 char *label;
120 ssize_t (*show)(struct device *dev,
121 struct device_attribute *devattr,
122 char *buf);
123 ssize_t (*set)(struct device *dev,
124 struct device_attribute *devattr,
125 const char *buf, size_t count);
126 int index;
127};
128
129/* Averaging interval */
130static int update_avg_interval(struct acpi_power_meter_resource *resource)
131{
132 unsigned long long data;
133 acpi_status status;
134
135 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GAI",
136 NULL, &data);
137 if (ACPI_FAILURE(status)) {
138 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _GAI"));
139 return -ENODEV;
140 }
141
142 resource->avg_interval = data;
143 return 0;
144}
145
146static ssize_t show_avg_interval(struct device *dev,
147 struct device_attribute *devattr,
148 char *buf)
149{
150 struct acpi_device *acpi_dev = to_acpi_device(dev);
151 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
152
153 mutex_lock(&resource->lock);
154 update_avg_interval(resource);
155 mutex_unlock(&resource->lock);
156
157 return sprintf(buf, "%llu\n", resource->avg_interval);
158}
159
160static ssize_t set_avg_interval(struct device *dev,
161 struct device_attribute *devattr,
162 const char *buf, size_t count)
163{
164 struct acpi_device *acpi_dev = to_acpi_device(dev);
165 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
166 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
167 struct acpi_object_list args = { 1, &arg0 };
168 int res;
169 unsigned long temp;
170 unsigned long long data;
171 acpi_status status;
172
173 res = strict_strtoul(buf, 10, &temp);
174 if (res)
175 return res;
176
177 if (temp > resource->caps.max_avg_interval ||
178 temp < resource->caps.min_avg_interval)
179 return -EINVAL;
180 arg0.integer.value = temp;
181
182 mutex_lock(&resource->lock);
183 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PAI",
184 &args, &data);
185 if (!ACPI_FAILURE(status))
186 resource->avg_interval = temp;
187 mutex_unlock(&resource->lock);
188
189 if (ACPI_FAILURE(status)) {
190 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PAI"));
191 return -EINVAL;
192 }
193
194 /* _PAI returns 0 on success, nonzero otherwise */
195 if (data)
196 return -EINVAL;
197
198 return count;
199}
200
201/* Cap functions */
202static int update_cap(struct acpi_power_meter_resource *resource)
203{
204 unsigned long long data;
205 acpi_status status;
206
207 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_GHL",
208 NULL, &data);
209 if (ACPI_FAILURE(status)) {
210 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _GHL"));
211 return -ENODEV;
212 }
213
214 resource->cap = data;
215 return 0;
216}
217
218static ssize_t show_cap(struct device *dev,
219 struct device_attribute *devattr,
220 char *buf)
221{
222 struct acpi_device *acpi_dev = to_acpi_device(dev);
223 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
224
225 mutex_lock(&resource->lock);
226 update_cap(resource);
227 mutex_unlock(&resource->lock);
228
229 return sprintf(buf, "%llu\n", resource->cap * 1000);
230}
231
232static ssize_t set_cap(struct device *dev, struct device_attribute *devattr,
233 const char *buf, size_t count)
234{
235 struct acpi_device *acpi_dev = to_acpi_device(dev);
236 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
237 union acpi_object arg0 = { ACPI_TYPE_INTEGER };
238 struct acpi_object_list args = { 1, &arg0 };
239 int res;
240 unsigned long temp;
241 unsigned long long data;
242 acpi_status status;
243
244 res = strict_strtoul(buf, 10, &temp);
245 if (res)
246 return res;
247
248 temp /= 1000;
249 if (temp > resource->caps.max_cap || temp < resource->caps.min_cap)
250 return -EINVAL;
251 arg0.integer.value = temp;
252
253 mutex_lock(&resource->lock);
254 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_SHL",
255 &args, &data);
256 if (!ACPI_FAILURE(status))
257 resource->cap = temp;
258 mutex_unlock(&resource->lock);
259
260 if (ACPI_FAILURE(status)) {
261 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SHL"));
262 return -EINVAL;
263 }
264
265 /* _SHL returns 0 on success, nonzero otherwise */
266 if (data)
267 return -EINVAL;
268
269 return count;
270}
271
272/* Power meter trip points */
273static int set_acpi_trip(struct acpi_power_meter_resource *resource)
274{
275 union acpi_object arg_objs[] = {
276 {ACPI_TYPE_INTEGER},
277 {ACPI_TYPE_INTEGER}
278 };
279 struct acpi_object_list args = { 2, arg_objs };
280 unsigned long long data;
281 acpi_status status;
282
283 /* Both trip levels must be set */
284 if (resource->trip[0] < 0 || resource->trip[1] < 0)
285 return 0;
286
287 /* This driver stores min, max; ACPI wants max, min. */
288 arg_objs[0].integer.value = resource->trip[1];
289 arg_objs[1].integer.value = resource->trip[0];
290
291 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PTP",
292 &args, &data);
293 if (ACPI_FAILURE(status)) {
294 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTP"));
295 return -EINVAL;
296 }
297
298 /* _PTP returns 0 on success, nonzero otherwise */
299 if (data)
300 return -EINVAL;
301
302 return 0;
303}
304
305static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
306 const char *buf, size_t count)
307{
308 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
309 struct acpi_device *acpi_dev = to_acpi_device(dev);
310 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
311 int res;
312 unsigned long temp;
313
314 res = strict_strtoul(buf, 10, &temp);
315 if (res)
316 return res;
317
318 temp /= 1000;
319 if (temp < 0)
320 return -EINVAL;
321
322 mutex_lock(&resource->lock);
323 resource->trip[attr->index - 7] = temp;
324 res = set_acpi_trip(resource);
325 mutex_unlock(&resource->lock);
326
327 if (res)
328 return res;
329
330 return count;
331}
332
333/* Power meter */
334static int update_meter(struct acpi_power_meter_resource *resource)
335{
336 unsigned long long data;
337 acpi_status status;
338 unsigned long local_jiffies = jiffies;
339
340 if (time_before(local_jiffies, resource->sensors_last_updated +
341 msecs_to_jiffies(resource->caps.sampling_time)) &&
342 resource->sensors_valid)
343 return 0;
344
345 status = acpi_evaluate_integer(resource->acpi_dev->handle, "_PMM",
346 NULL, &data);
347 if (ACPI_FAILURE(status)) {
348 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PMM"));
349 return -ENODEV;
350 }
351
352 resource->power = data;
353 resource->sensors_valid = 1;
354 resource->sensors_last_updated = jiffies;
355 return 0;
356}
357
358static ssize_t show_power(struct device *dev,
359 struct device_attribute *devattr,
360 char *buf)
361{
362 struct acpi_device *acpi_dev = to_acpi_device(dev);
363 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
364
365 mutex_lock(&resource->lock);
366 update_meter(resource);
367 mutex_unlock(&resource->lock);
368
369 return sprintf(buf, "%llu\n", resource->power * 1000);
370}
371
372/* Miscellaneous */
373static ssize_t show_str(struct device *dev,
374 struct device_attribute *devattr,
375 char *buf)
376{
377 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
378 struct acpi_device *acpi_dev = to_acpi_device(dev);
379 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
380 acpi_string val;
381
382 switch (attr->index) {
383 case 0:
384 val = resource->model_number;
385 break;
386 case 1:
387 val = resource->serial_number;
388 break;
389 case 2:
390 val = resource->oem_info;
391 break;
392 default:
393 BUG();
394 }
395
396 return sprintf(buf, "%s\n", val);
397}
398
399static ssize_t show_val(struct device *dev,
400 struct device_attribute *devattr,
401 char *buf)
402{
403 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
404 struct acpi_device *acpi_dev = to_acpi_device(dev);
405 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
406 u64 val = 0;
407
408 switch (attr->index) {
409 case 0:
410 val = resource->caps.min_avg_interval;
411 break;
412 case 1:
413 val = resource->caps.max_avg_interval;
414 break;
415 case 2:
416 val = resource->caps.min_cap * 1000;
417 break;
418 case 3:
419 val = resource->caps.max_cap * 1000;
420 break;
421 case 4:
422 if (resource->caps.hysteresis == UNKNOWN_HYSTERESIS)
423 return sprintf(buf, "unknown\n");
424
425 val = resource->caps.hysteresis * 1000;
426 break;
427 case 5:
428 if (resource->caps.flags & POWER_METER_IS_BATTERY)
429 val = 1;
430 else
431 val = 0;
432 break;
433 case 6:
434 if (resource->power > resource->cap)
435 val = 1;
436 else
437 val = 0;
438 break;
439 case 7:
440 case 8:
441 if (resource->trip[attr->index - 7] < 0)
442 return sprintf(buf, "unknown\n");
443
444 val = resource->trip[attr->index - 7] * 1000;
445 break;
446 default:
447 BUG();
448 }
449
450 return sprintf(buf, "%llu\n", val);
451}
452
453static ssize_t show_accuracy(struct device *dev,
454 struct device_attribute *devattr,
455 char *buf)
456{
457 struct acpi_device *acpi_dev = to_acpi_device(dev);
458 struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
459 unsigned int acc = resource->caps.accuracy;
460
461 return sprintf(buf, "%u.%u%%\n", acc / 1000, acc % 1000);
462}
463
464static ssize_t show_name(struct device *dev,
465 struct device_attribute *devattr,
466 char *buf)
467{
468 return sprintf(buf, "%s\n", ACPI_POWER_METER_NAME);
469}
470
471/* Sensor descriptions. If you add a sensor, update NUM_SENSORS above! */
472static struct ro_sensor_template meter_ro_attrs[] = {
473{POWER_AVERAGE_NAME, show_power, 0},
474{"power1_accuracy", show_accuracy, 0},
475{"power1_average_interval_min", show_val, 0},
476{"power1_average_interval_max", show_val, 1},
477{"power1_is_battery", show_val, 5},
478{NULL, NULL, 0},
479};
480
481static struct rw_sensor_template meter_rw_attrs[] = {
482{POWER_AVG_INTERVAL_NAME, show_avg_interval, set_avg_interval, 0},
483{NULL, NULL, NULL, 0},
484};
485
486static struct ro_sensor_template misc_cap_attrs[] = {
487{"power1_cap_min", show_val, 2},
488{"power1_cap_max", show_val, 3},
489{"power1_cap_hyst", show_val, 4},
490{POWER_ALARM_NAME, show_val, 6},
491{NULL, NULL, 0},
492};
493
494static struct ro_sensor_template ro_cap_attrs[] = {
495{POWER_CAP_NAME, show_cap, 0},
496{NULL, NULL, 0},
497};
498
499static struct rw_sensor_template rw_cap_attrs[] = {
500{POWER_CAP_NAME, show_cap, set_cap, 0},
501{NULL, NULL, NULL, 0},
502};
503
504static struct rw_sensor_template trip_attrs[] = {
505{"power1_average_min", show_val, set_trip, 7},
506{"power1_average_max", show_val, set_trip, 8},
507{NULL, NULL, NULL, 0},
508};
509
510static struct ro_sensor_template misc_attrs[] = {
511{"name", show_name, 0},
512{"power1_model_number", show_str, 0},
513{"power1_oem_info", show_str, 2},
514{"power1_serial_number", show_str, 1},
515{NULL, NULL, 0},
516};
517
518/* Read power domain data */
519static void remove_domain_devices(struct acpi_power_meter_resource *resource)
520{
521 int i;
522
523 if (!resource->num_domain_devices)
524 return;
525
526 for (i = 0; i < resource->num_domain_devices; i++) {
527 struct acpi_device *obj = resource->domain_devices[i];
528 if (!obj)
529 continue;
530
531 sysfs_remove_link(resource->holders_dir,
532 kobject_name(&obj->dev.kobj));
533 put_device(&obj->dev);
534 }
535
536 kfree(resource->domain_devices);
537 kobject_put(resource->holders_dir);
538 resource->num_domain_devices = 0;
539}
540
541static int read_domain_devices(struct acpi_power_meter_resource *resource)
542{
543 int res = 0;
544 int i;
545 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
546 union acpi_object *pss;
547 acpi_status status;
548
549 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMD", NULL,
550 &buffer);
551 if (ACPI_FAILURE(status)) {
552 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PMD"));
553 return -ENODEV;
554 }
555
556 pss = buffer.pointer;
557 if (!pss ||
558 pss->type != ACPI_TYPE_PACKAGE) {
559 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
560 "Invalid _PMD data\n");
561 res = -EFAULT;
562 goto end;
563 }
564
565 if (!pss->package.count)
566 goto end;
567
568 resource->domain_devices = kzalloc(sizeof(struct acpi_device *) *
569 pss->package.count, GFP_KERNEL);
570 if (!resource->domain_devices) {
571 res = -ENOMEM;
572 goto end;
573 }
574
575 resource->holders_dir = kobject_create_and_add("measures",
576 &resource->acpi_dev->dev.kobj);
577 if (!resource->holders_dir) {
578 res = -ENOMEM;
579 goto exit_free;
580 }
581
582 resource->num_domain_devices = pss->package.count;
583
584 for (i = 0; i < pss->package.count; i++) {
585 struct acpi_device *obj;
586 union acpi_object *element = &(pss->package.elements[i]);
587
588 /* Refuse non-references */
589 if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
590 continue;
591
592 /* Create a symlink to domain objects */
593 resource->domain_devices[i] = NULL;
594 status = acpi_bus_get_device(element->reference.handle,
595 &resource->domain_devices[i]);
596 if (ACPI_FAILURE(status))
597 continue;
598
599 obj = resource->domain_devices[i];
600 get_device(&obj->dev);
601
602 res = sysfs_create_link(resource->holders_dir, &obj->dev.kobj,
603 kobject_name(&obj->dev.kobj));
604 if (res) {
605 put_device(&obj->dev);
606 resource->domain_devices[i] = NULL;
607 }
608 }
609
610 res = 0;
611 goto end;
612
613exit_free:
614 kfree(resource->domain_devices);
615end:
616 kfree(buffer.pointer);
617 return res;
618}
619
620/* Registration and deregistration */
621static int register_ro_attrs(struct acpi_power_meter_resource *resource,
622 struct ro_sensor_template *ro)
623{
624 struct device *dev = &resource->acpi_dev->dev;
625 struct sensor_device_attribute *sensors =
626 &resource->sensors[resource->num_sensors];
627 int res = 0;
628
629 while (ro->label) {
630 sensors->dev_attr.attr.name = ro->label;
631 sensors->dev_attr.attr.mode = S_IRUGO;
632 sensors->dev_attr.show = ro->show;
633 sensors->index = ro->index;
634
635 res = device_create_file(dev, &sensors->dev_attr);
636 if (res) {
637 sensors->dev_attr.attr.name = NULL;
638 goto error;
639 }
640 sensors++;
641 resource->num_sensors++;
642 ro++;
643 }
644
645error:
646 return res;
647}
648
649static int register_rw_attrs(struct acpi_power_meter_resource *resource,
650 struct rw_sensor_template *rw)
651{
652 struct device *dev = &resource->acpi_dev->dev;
653 struct sensor_device_attribute *sensors =
654 &resource->sensors[resource->num_sensors];
655 int res = 0;
656
657 while (rw->label) {
658 sensors->dev_attr.attr.name = rw->label;
659 sensors->dev_attr.attr.mode = S_IRUGO | S_IWUSR;
660 sensors->dev_attr.show = rw->show;
661 sensors->dev_attr.store = rw->set;
662 sensors->index = rw->index;
663
664 res = device_create_file(dev, &sensors->dev_attr);
665 if (res) {
666 sensors->dev_attr.attr.name = NULL;
667 goto error;
668 }
669 sensors++;
670 resource->num_sensors++;
671 rw++;
672 }
673
674error:
675 return res;
676}
677
678static void remove_attrs(struct acpi_power_meter_resource *resource)
679{
680 int i;
681
682 for (i = 0; i < resource->num_sensors; i++) {
683 if (!resource->sensors[i].dev_attr.attr.name)
684 continue;
685 device_remove_file(&resource->acpi_dev->dev,
686 &resource->sensors[i].dev_attr);
687 }
688
689 remove_domain_devices(resource);
690
691 resource->num_sensors = 0;
692}
693
694static int setup_attrs(struct acpi_power_meter_resource *resource)
695{
696 int res = 0;
697
698 res = read_domain_devices(resource);
699 if (res)
700 return res;
701
702 if (resource->caps.flags & POWER_METER_CAN_MEASURE) {
703 res = register_ro_attrs(resource, meter_ro_attrs);
704 if (res)
705 goto error;
706 res = register_rw_attrs(resource, meter_rw_attrs);
707 if (res)
708 goto error;
709 }
710
711 if (resource->caps.flags & POWER_METER_CAN_CAP) {
712 if (!can_cap_in_hardware()) {
713 dev_err(&resource->acpi_dev->dev,
714 "Ignoring unsafe software power cap!\n");
715 goto skip_unsafe_cap;
716 }
717
718 if (resource->caps.configurable_cap) {
719 res = register_rw_attrs(resource, rw_cap_attrs);
720 if (res)
721 goto error;
722 } else {
723 res = register_ro_attrs(resource, ro_cap_attrs);
724 if (res)
725 goto error;
726 }
727 res = register_ro_attrs(resource, misc_cap_attrs);
728 if (res)
729 goto error;
730 }
731skip_unsafe_cap:
732
733 if (resource->caps.flags & POWER_METER_CAN_TRIP) {
734 res = register_rw_attrs(resource, trip_attrs);
735 if (res)
736 goto error;
737 }
738
739 res = register_ro_attrs(resource, misc_attrs);
740 if (res)
741 goto error;
742
743 return res;
744error:
745 remove_attrs(resource);
746 return res;
747}
748
749static void free_capabilities(struct acpi_power_meter_resource *resource)
750{
751 acpi_string *str;
752 int i;
753
754 str = &resource->model_number;
755 for (i = 0; i < 3; i++, str++)
756 kfree(*str);
757}
758
759static int read_capabilities(struct acpi_power_meter_resource *resource)
760{
761 int res = 0;
762 int i;
763 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
764 struct acpi_buffer state = { 0, NULL };
765 struct acpi_buffer format = { sizeof("NNNNNNNNNNN"), "NNNNNNNNNNN" };
766 union acpi_object *pss;
767 acpi_string *str;
768 acpi_status status;
769
770 status = acpi_evaluate_object(resource->acpi_dev->handle, "_PMC", NULL,
771 &buffer);
772 if (ACPI_FAILURE(status)) {
773 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PMC"));
774 return -ENODEV;
775 }
776
777 pss = buffer.pointer;
778 if (!pss ||
779 pss->type != ACPI_TYPE_PACKAGE ||
780 pss->package.count != 14) {
781 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
782 "Invalid _PMC data\n");
783 res = -EFAULT;
784 goto end;
785 }
786
787 /* Grab all the integer data at once */
788 state.length = sizeof(struct acpi_power_meter_capabilities);
789 state.pointer = &resource->caps;
790
791 status = acpi_extract_package(pss, &format, &state);
792 if (ACPI_FAILURE(status)) {
793 ACPI_EXCEPTION((AE_INFO, status, "Invalid data"));
794 res = -EFAULT;
795 goto end;
796 }
797
798 if (resource->caps.units) {
799 dev_err(&resource->acpi_dev->dev, ACPI_POWER_METER_NAME
800 "Unknown units %llu.\n",
801 resource->caps.units);
802 res = -EINVAL;
803 goto end;
804 }
805
806 /* Grab the string data */
807 str = &resource->model_number;
808
809 for (i = 11; i < 14; i++) {
810 union acpi_object *element = &(pss->package.elements[i]);
811
812 if (element->type != ACPI_TYPE_STRING) {
813 res = -EINVAL;
814 goto error;
815 }
816
817 *str = kzalloc(sizeof(u8) * (element->string.length + 1),
818 GFP_KERNEL);
819 if (!*str) {
820 res = -ENOMEM;
821 goto error;
822 }
823
824 strncpy(*str, element->string.pointer, element->string.length);
825 str++;
826 }
827
828 dev_info(&resource->acpi_dev->dev, "Found ACPI power meter.\n");
829 goto end;
830error:
831 str = &resource->model_number;
832 for (i = 0; i < 3; i++, str++)
833 kfree(*str);
834end:
835 kfree(buffer.pointer);
836 return res;
837}
838
839/* Handle ACPI event notifications */
840static void acpi_power_meter_notify(struct acpi_device *device, u32 event)
841{
842 struct acpi_power_meter_resource *resource;
843 int res;
844
845 if (!device || !acpi_driver_data(device))
846 return;
847
848 resource = acpi_driver_data(device);
849
850 mutex_lock(&resource->lock);
851 switch (event) {
852 case METER_NOTIFY_CONFIG:
853 free_capabilities(resource);
854 res = read_capabilities(resource);
855 if (res)
856 break;
857
858 remove_attrs(resource);
859 setup_attrs(resource);
860 break;
861 case METER_NOTIFY_TRIP:
862 sysfs_notify(&device->dev.kobj, NULL, POWER_AVERAGE_NAME);
863 update_meter(resource);
864 break;
865 case METER_NOTIFY_CAP:
866 sysfs_notify(&device->dev.kobj, NULL, POWER_CAP_NAME);
867 update_cap(resource);
868 break;
869 case METER_NOTIFY_INTERVAL:
870 sysfs_notify(&device->dev.kobj, NULL, POWER_AVG_INTERVAL_NAME);
871 update_avg_interval(resource);
872 break;
873 case METER_NOTIFY_CAPPING:
874 sysfs_notify(&device->dev.kobj, NULL, POWER_ALARM_NAME);
875 dev_info(&device->dev, "Capping in progress.\n");
876 break;
877 default:
878 BUG();
879 }
880 mutex_unlock(&resource->lock);
881
882 acpi_bus_generate_netlink_event(ACPI_POWER_METER_CLASS,
883 dev_name(&device->dev), event, 0);
884}
885
886static int acpi_power_meter_add(struct acpi_device *device)
887{
888 int res;
889 struct acpi_power_meter_resource *resource;
890
891 if (!device)
892 return -EINVAL;
893
894 resource = kzalloc(sizeof(struct acpi_power_meter_resource),
895 GFP_KERNEL);
896 if (!resource)
897 return -ENOMEM;
898
899 resource->sensors_valid = 0;
900 resource->acpi_dev = device;
901 mutex_init(&resource->lock);
902 strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
903 strcpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
904 device->driver_data = resource;
905
906 free_capabilities(resource);
907 res = read_capabilities(resource);
908 if (res)
909 goto exit_free;
910
911 resource->trip[0] = resource->trip[1] = -1;
912
913 res = setup_attrs(resource);
914 if (res)
915 goto exit_free;
916
917 resource->hwmon_dev = hwmon_device_register(&device->dev);
918 if (IS_ERR(resource->hwmon_dev)) {
919 res = PTR_ERR(resource->hwmon_dev);
920 goto exit_remove;
921 }
922
923 res = 0;
924 goto exit;
925
926exit_remove:
927 remove_attrs(resource);
928exit_free:
929 kfree(resource);
930exit:
931 return res;
932}
933
934static int acpi_power_meter_remove(struct acpi_device *device, int type)
935{
936 struct acpi_power_meter_resource *resource;
937
938 if (!device || !acpi_driver_data(device))
939 return -EINVAL;
940
941 resource = acpi_driver_data(device);
942 hwmon_device_unregister(resource->hwmon_dev);
943
944 free_capabilities(resource);
945 remove_attrs(resource);
946
947 kfree(resource);
948 return 0;
949}
950
951static int acpi_power_meter_resume(struct acpi_device *device)
952{
953 struct acpi_power_meter_resource *resource;
954
955 if (!device || !acpi_driver_data(device))
956 return -EINVAL;
957
958 resource = acpi_driver_data(device);
959 free_capabilities(resource);
960 read_capabilities(resource);
961
962 return 0;
963}
964
965static struct acpi_driver acpi_power_meter_driver = {
966 .name = "power_meter",
967 .class = ACPI_POWER_METER_CLASS,
968 .ids = power_meter_ids,
969 .ops = {
970 .add = acpi_power_meter_add,
971 .remove = acpi_power_meter_remove,
972 .resume = acpi_power_meter_resume,
973 .notify = acpi_power_meter_notify,
974 },
975};
976
977/* Module init/exit routines */
978static int __init enable_cap_knobs(const struct dmi_system_id *d)
979{
980 cap_in_hardware = 1;
981 return 0;
982}
983
984static struct dmi_system_id __initdata pm_dmi_table[] = {
985 {
986 enable_cap_knobs, "IBM Active Energy Manager",
987 {
988 DMI_MATCH(DMI_SYS_VENDOR, "IBM")
989 },
990 },
991 {}
992};
993
994static int __init acpi_power_meter_init(void)
995{
996 int result;
997
998 if (acpi_disabled)
999 return -ENODEV;
1000
1001 dmi_check_system(pm_dmi_table);
1002
1003 result = acpi_bus_register_driver(&acpi_power_meter_driver);
1004 if (result < 0)
1005 return -ENODEV;
1006
1007 return 0;
1008}
1009
1010static void __exit acpi_power_meter_exit(void)
1011{
1012 acpi_bus_unregister_driver(&acpi_power_meter_driver);
1013}
1014
1015MODULE_AUTHOR("Darrick J. Wong <djwong@us.ibm.com>");
1016MODULE_DESCRIPTION("ACPI 4.0 power meter driver");
1017MODULE_LICENSE("GPL");
1018
1019module_param(force_cap_on, bool, 0644);
1020MODULE_PARM_DESC(force_cap_on, "Enable power cap even it is unsafe to do so.");
1021
1022module_init(acpi_power_meter_init);
1023module_exit(acpi_power_meter_exit);
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index fbdc7655303b..b2cacbe707a8 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -62,7 +62,7 @@ static ssize_t adcxx_read(struct device *dev,
62{ 62{
63 struct spi_device *spi = to_spi_device(dev); 63 struct spi_device *spi = to_spi_device(dev);
64 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 64 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
65 struct adcxx *adc = dev_get_drvdata(&spi->dev); 65 struct adcxx *adc = spi_get_drvdata(spi);
66 u8 tx_buf[2]; 66 u8 tx_buf[2];
67 u8 rx_buf[2]; 67 u8 rx_buf[2];
68 int status; 68 int status;
@@ -105,7 +105,7 @@ static ssize_t adcxx_show_max(struct device *dev,
105 struct device_attribute *devattr, char *buf) 105 struct device_attribute *devattr, char *buf)
106{ 106{
107 struct spi_device *spi = to_spi_device(dev); 107 struct spi_device *spi = to_spi_device(dev);
108 struct adcxx *adc = dev_get_drvdata(&spi->dev); 108 struct adcxx *adc = spi_get_drvdata(spi);
109 u32 reference; 109 u32 reference;
110 110
111 if (mutex_lock_interruptible(&adc->lock)) 111 if (mutex_lock_interruptible(&adc->lock))
@@ -122,7 +122,7 @@ static ssize_t adcxx_set_max(struct device *dev,
122 struct device_attribute *devattr, const char *buf, size_t count) 122 struct device_attribute *devattr, const char *buf, size_t count)
123{ 123{
124 struct spi_device *spi = to_spi_device(dev); 124 struct spi_device *spi = to_spi_device(dev);
125 struct adcxx *adc = dev_get_drvdata(&spi->dev); 125 struct adcxx *adc = spi_get_drvdata(spi);
126 unsigned long value; 126 unsigned long value;
127 127
128 if (strict_strtoul(buf, 10, &value)) 128 if (strict_strtoul(buf, 10, &value))
@@ -142,7 +142,7 @@ static ssize_t adcxx_show_name(struct device *dev, struct device_attribute
142 *devattr, char *buf) 142 *devattr, char *buf)
143{ 143{
144 struct spi_device *spi = to_spi_device(dev); 144 struct spi_device *spi = to_spi_device(dev);
145 struct adcxx *adc = dev_get_drvdata(&spi->dev); 145 struct adcxx *adc = spi_get_drvdata(spi);
146 146
147 return sprintf(buf, "adcxx%ds\n", adc->channels); 147 return sprintf(buf, "adcxx%ds\n", adc->channels);
148} 148}
@@ -182,7 +182,7 @@ static int __devinit adcxx_probe(struct spi_device *spi)
182 182
183 mutex_lock(&adc->lock); 183 mutex_lock(&adc->lock);
184 184
185 dev_set_drvdata(&spi->dev, adc); 185 spi_set_drvdata(spi, adc);
186 186
187 for (i = 0; i < 3 + adc->channels; i++) { 187 for (i = 0; i < 3 + adc->channels; i++) {
188 status = device_create_file(&spi->dev, &ad_input[i].dev_attr); 188 status = device_create_file(&spi->dev, &ad_input[i].dev_attr);
@@ -206,7 +206,7 @@ out_err:
206 for (i--; i >= 0; i--) 206 for (i--; i >= 0; i--)
207 device_remove_file(&spi->dev, &ad_input[i].dev_attr); 207 device_remove_file(&spi->dev, &ad_input[i].dev_attr);
208 208
209 dev_set_drvdata(&spi->dev, NULL); 209 spi_set_drvdata(spi, NULL);
210 mutex_unlock(&adc->lock); 210 mutex_unlock(&adc->lock);
211 kfree(adc); 211 kfree(adc);
212 return status; 212 return status;
@@ -214,7 +214,7 @@ out_err:
214 214
215static int __devexit adcxx_remove(struct spi_device *spi) 215static int __devexit adcxx_remove(struct spi_device *spi)
216{ 216{
217 struct adcxx *adc = dev_get_drvdata(&spi->dev); 217 struct adcxx *adc = spi_get_drvdata(spi);
218 int i; 218 int i;
219 219
220 mutex_lock(&adc->lock); 220 mutex_lock(&adc->lock);
@@ -222,7 +222,7 @@ static int __devexit adcxx_remove(struct spi_device *spi)
222 for (i = 0; i < 3 + adc->channels; i++) 222 for (i = 0; i < 3 + adc->channels; i++)
223 device_remove_file(&spi->dev, &ad_input[i].dev_attr); 223 device_remove_file(&spi->dev, &ad_input[i].dev_attr);
224 224
225 dev_set_drvdata(&spi->dev, NULL); 225 spi_set_drvdata(spi, NULL);
226 mutex_unlock(&adc->lock); 226 mutex_unlock(&adc->lock);
227 kfree(adc); 227 kfree(adc);
228 228
diff --git a/drivers/hwmon/emc6w201.c b/drivers/hwmon/emc6w201.c
new file mode 100644
index 000000000000..e0ef32378ac6
--- /dev/null
+++ b/drivers/hwmon/emc6w201.c
@@ -0,0 +1,539 @@
1/*
2 * emc6w201.c - Hardware monitoring driver for the SMSC EMC6W201
3 * Copyright (C) 2011 Jean Delvare <khali@linux-fr.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20#include <linux/module.h>
21#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/jiffies.h>
25#include <linux/i2c.h>
26#include <linux/hwmon.h>
27#include <linux/hwmon-sysfs.h>
28#include <linux/err.h>
29#include <linux/mutex.h>
30
31/*
32 * Addresses to scan
33 */
34
35static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
36
37/*
38 * The EMC6W201 registers
39 */
40
41#define EMC6W201_REG_IN(nr) (0x20 + (nr))
42#define EMC6W201_REG_TEMP(nr) (0x26 + (nr))
43#define EMC6W201_REG_FAN(nr) (0x2C + (nr) * 2)
44#define EMC6W201_REG_COMPANY 0x3E
45#define EMC6W201_REG_VERSTEP 0x3F
46#define EMC6W201_REG_CONFIG 0x40
47#define EMC6W201_REG_IN_LOW(nr) (0x4A + (nr) * 2)
48#define EMC6W201_REG_IN_HIGH(nr) (0x4B + (nr) * 2)
49#define EMC6W201_REG_TEMP_LOW(nr) (0x56 + (nr) * 2)
50#define EMC6W201_REG_TEMP_HIGH(nr) (0x57 + (nr) * 2)
51#define EMC6W201_REG_FAN_MIN(nr) (0x62 + (nr) * 2)
52
53enum { input, min, max } subfeature;
54
55/*
56 * Per-device data
57 */
58
59struct emc6w201_data {
60 struct device *hwmon_dev;
61 struct mutex update_lock;
62 char valid; /* zero until following fields are valid */
63 unsigned long last_updated; /* in jiffies */
64
65 /* registers values */
66 u8 in[3][6];
67 s8 temp[3][6];
68 u16 fan[2][5];
69};
70
71/*
72 * Combine LSB and MSB registers in a single value
73 * Locking: must be called with data->update_lock held
74 */
75static u16 emc6w201_read16(struct i2c_client *client, u8 reg)
76{
77 int lsb, msb;
78
79 lsb = i2c_smbus_read_byte_data(client, reg);
80 msb = i2c_smbus_read_byte_data(client, reg + 1);
81 if (lsb < 0 || msb < 0) {
82 dev_err(&client->dev, "16-bit read failed at 0x%02x\n", reg);
83 return 0xFFFF; /* Arbitrary value */
84 }
85
86 return (msb << 8) | lsb;
87}
88
89/*
90 * Write 16-bit value to LSB and MSB registers
91 * Locking: must be called with data->update_lock held
92 */
93static int emc6w201_write16(struct i2c_client *client, u8 reg, u16 val)
94{
95 int err;
96
97 err = i2c_smbus_write_byte_data(client, reg, val & 0xff);
98 if (!err)
99 err = i2c_smbus_write_byte_data(client, reg + 1, val >> 8);
100 if (err < 0)
101 dev_err(&client->dev, "16-bit write failed at 0x%02x\n", reg);
102
103 return err;
104}
105
106static struct emc6w201_data *emc6w201_update_device(struct device *dev)
107{
108 struct i2c_client *client = to_i2c_client(dev);
109 struct emc6w201_data *data = i2c_get_clientdata(client);
110 int nr;
111
112 mutex_lock(&data->update_lock);
113
114 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
115 for (nr = 0; nr < 6; nr++) {
116 data->in[input][nr] =
117 i2c_smbus_read_byte_data(client,
118 EMC6W201_REG_IN(nr));
119 data->in[min][nr] =
120 i2c_smbus_read_byte_data(client,
121 EMC6W201_REG_IN_LOW(nr));
122 data->in[max][nr] =
123 i2c_smbus_read_byte_data(client,
124 EMC6W201_REG_IN_HIGH(nr));
125 }
126
127 for (nr = 0; nr < 6; nr++) {
128 data->temp[input][nr] =
129 i2c_smbus_read_byte_data(client,
130 EMC6W201_REG_TEMP(nr));
131 data->temp[min][nr] =
132 i2c_smbus_read_byte_data(client,
133 EMC6W201_REG_TEMP_LOW(nr));
134 data->temp[max][nr] =
135 i2c_smbus_read_byte_data(client,
136 EMC6W201_REG_TEMP_HIGH(nr));
137 }
138
139 for (nr = 0; nr < 5; nr++) {
140 data->fan[input][nr] =
141 emc6w201_read16(client,
142 EMC6W201_REG_FAN(nr));
143 data->fan[min][nr] =
144 emc6w201_read16(client,
145 EMC6W201_REG_FAN_MIN(nr));
146 }
147
148 data->last_updated = jiffies;
149 data->valid = 1;
150 }
151
152 mutex_unlock(&data->update_lock);
153
154 return data;
155}
156
157/*
158 * Sysfs callback functions
159 */
160
161static const u16 nominal_mv[6] = { 2500, 1500, 3300, 5000, 1500, 1500 };
162
163static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
164 char *buf)
165{
166 struct emc6w201_data *data = emc6w201_update_device(dev);
167 int sf = to_sensor_dev_attr_2(devattr)->index;
168 int nr = to_sensor_dev_attr_2(devattr)->nr;
169
170 return sprintf(buf, "%u\n",
171 (unsigned)data->in[sf][nr] * nominal_mv[nr] / 0xC0);
172}
173
174static ssize_t set_in(struct device *dev, struct device_attribute *devattr,
175 const char *buf, size_t count)
176{
177 struct i2c_client *client = to_i2c_client(dev);
178 struct emc6w201_data *data = i2c_get_clientdata(client);
179 int sf = to_sensor_dev_attr_2(devattr)->index;
180 int nr = to_sensor_dev_attr_2(devattr)->nr;
181 int err;
182 long val;
183 u8 reg;
184
185 err = strict_strtol(buf, 10, &val);
186 if (err < 0)
187 return err;
188
189 val = DIV_ROUND_CLOSEST(val * 0xC0, nominal_mv[nr]);
190 reg = (sf == min) ? EMC6W201_REG_IN_LOW(nr)
191 : EMC6W201_REG_IN_HIGH(nr);
192
193 mutex_lock(&data->update_lock);
194 data->in[sf][nr] = SENSORS_LIMIT(val, 0, 255);
195 err = i2c_smbus_write_byte_data(client, reg, data->in[sf][nr]);
196 mutex_unlock(&data->update_lock);
197
198 return err < 0 ? err : count;
199}
200
201static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
202 char *buf)
203{
204 struct emc6w201_data *data = emc6w201_update_device(dev);
205 int sf = to_sensor_dev_attr_2(devattr)->index;
206 int nr = to_sensor_dev_attr_2(devattr)->nr;
207
208 return sprintf(buf, "%d\n", (int)data->temp[sf][nr] * 1000);
209}
210
211static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
212 const char *buf, size_t count)
213{
214 struct i2c_client *client = to_i2c_client(dev);
215 struct emc6w201_data *data = i2c_get_clientdata(client);
216 int sf = to_sensor_dev_attr_2(devattr)->index;
217 int nr = to_sensor_dev_attr_2(devattr)->nr;
218 int err;
219 long val;
220 u8 reg;
221
222 err = strict_strtol(buf, 10, &val);
223 if (err < 0)
224 return err;
225
226 val /= 1000;
227 reg = (sf == min) ? EMC6W201_REG_TEMP_LOW(nr)
228 : EMC6W201_REG_TEMP_HIGH(nr);
229
230 mutex_lock(&data->update_lock);
231 data->temp[sf][nr] = SENSORS_LIMIT(val, -127, 128);
232 err = i2c_smbus_write_byte_data(client, reg, data->temp[sf][nr]);
233 mutex_unlock(&data->update_lock);
234
235 return err < 0 ? err : count;
236}
237
238static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
239 char *buf)
240{
241 struct emc6w201_data *data = emc6w201_update_device(dev);
242 int sf = to_sensor_dev_attr_2(devattr)->index;
243 int nr = to_sensor_dev_attr_2(devattr)->nr;
244 unsigned rpm;
245
246 if (data->fan[sf][nr] == 0 || data->fan[sf][nr] == 0xFFFF)
247 rpm = 0;
248 else
249 rpm = 5400000U / data->fan[sf][nr];
250
251 return sprintf(buf, "%u\n", rpm);
252}
253
254static ssize_t set_fan(struct device *dev, struct device_attribute *devattr,
255 const char *buf, size_t count)
256{
257 struct i2c_client *client = to_i2c_client(dev);
258 struct emc6w201_data *data = i2c_get_clientdata(client);
259 int sf = to_sensor_dev_attr_2(devattr)->index;
260 int nr = to_sensor_dev_attr_2(devattr)->nr;
261 int err;
262 unsigned long val;
263
264 err = strict_strtoul(buf, 10, &val);
265 if (err < 0)
266 return err;
267
268 if (val == 0) {
269 val = 0xFFFF;
270 } else {
271 val = DIV_ROUND_CLOSEST(5400000U, val);
272 val = SENSORS_LIMIT(val, 0, 0xFFFE);
273 }
274
275 mutex_lock(&data->update_lock);
276 data->fan[sf][nr] = val;
277 err = emc6w201_write16(client, EMC6W201_REG_FAN_MIN(nr),
278 data->fan[sf][nr]);
279 mutex_unlock(&data->update_lock);
280
281 return err < 0 ? err : count;
282}
283
284static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, input);
285static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
286 0, min);
287static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
288 0, max);
289static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, input);
290static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
291 1, min);
292static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
293 1, max);
294static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, input);
295static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
296 2, min);
297static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
298 2, max);
299static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, input);
300static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
301 3, min);
302static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
303 3, max);
304static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, input);
305static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
306 4, min);
307static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
308 4, max);
309static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, input);
310static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
311 5, min);
312static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
313 5, max);
314
315static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, input);
316static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
317 0, min);
318static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
319 0, max);
320static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, input);
321static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
322 1, min);
323static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
324 1, max);
325static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, input);
326static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
327 2, min);
328static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
329 2, max);
330static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, input);
331static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
332 3, min);
333static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
334 3, max);
335static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, input);
336static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
337 4, min);
338static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
339 4, max);
340static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, input);
341static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
342 5, min);
343static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
344 5, max);
345
346static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, input);
347static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
348 0, min);
349static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, input);
350static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
351 1, min);
352static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, input);
353static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
354 2, min);
355static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, input);
356static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
357 3, min);
358static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, input);
359static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
360 4, min);
361
362static struct attribute *emc6w201_attributes[] = {
363 &sensor_dev_attr_in0_input.dev_attr.attr,
364 &sensor_dev_attr_in0_min.dev_attr.attr,
365 &sensor_dev_attr_in0_max.dev_attr.attr,
366 &sensor_dev_attr_in1_input.dev_attr.attr,
367 &sensor_dev_attr_in1_min.dev_attr.attr,
368 &sensor_dev_attr_in1_max.dev_attr.attr,
369 &sensor_dev_attr_in2_input.dev_attr.attr,
370 &sensor_dev_attr_in2_min.dev_attr.attr,
371 &sensor_dev_attr_in2_max.dev_attr.attr,
372 &sensor_dev_attr_in3_input.dev_attr.attr,
373 &sensor_dev_attr_in3_min.dev_attr.attr,
374 &sensor_dev_attr_in3_max.dev_attr.attr,
375 &sensor_dev_attr_in4_input.dev_attr.attr,
376 &sensor_dev_attr_in4_min.dev_attr.attr,
377 &sensor_dev_attr_in4_max.dev_attr.attr,
378 &sensor_dev_attr_in5_input.dev_attr.attr,
379 &sensor_dev_attr_in5_min.dev_attr.attr,
380 &sensor_dev_attr_in5_max.dev_attr.attr,
381
382 &sensor_dev_attr_temp1_input.dev_attr.attr,
383 &sensor_dev_attr_temp1_min.dev_attr.attr,
384 &sensor_dev_attr_temp1_max.dev_attr.attr,
385 &sensor_dev_attr_temp2_input.dev_attr.attr,
386 &sensor_dev_attr_temp2_min.dev_attr.attr,
387 &sensor_dev_attr_temp2_max.dev_attr.attr,
388 &sensor_dev_attr_temp3_input.dev_attr.attr,
389 &sensor_dev_attr_temp3_min.dev_attr.attr,
390 &sensor_dev_attr_temp3_max.dev_attr.attr,
391 &sensor_dev_attr_temp4_input.dev_attr.attr,
392 &sensor_dev_attr_temp4_min.dev_attr.attr,
393 &sensor_dev_attr_temp4_max.dev_attr.attr,
394 &sensor_dev_attr_temp5_input.dev_attr.attr,
395 &sensor_dev_attr_temp5_min.dev_attr.attr,
396 &sensor_dev_attr_temp5_max.dev_attr.attr,
397 &sensor_dev_attr_temp6_input.dev_attr.attr,
398 &sensor_dev_attr_temp6_min.dev_attr.attr,
399 &sensor_dev_attr_temp6_max.dev_attr.attr,
400
401 &sensor_dev_attr_fan1_input.dev_attr.attr,
402 &sensor_dev_attr_fan1_min.dev_attr.attr,
403 &sensor_dev_attr_fan2_input.dev_attr.attr,
404 &sensor_dev_attr_fan2_min.dev_attr.attr,
405 &sensor_dev_attr_fan3_input.dev_attr.attr,
406 &sensor_dev_attr_fan3_min.dev_attr.attr,
407 &sensor_dev_attr_fan4_input.dev_attr.attr,
408 &sensor_dev_attr_fan4_min.dev_attr.attr,
409 &sensor_dev_attr_fan5_input.dev_attr.attr,
410 &sensor_dev_attr_fan5_min.dev_attr.attr,
411 NULL
412};
413
414static const struct attribute_group emc6w201_group = {
415 .attrs = emc6w201_attributes,
416};
417
418/*
419 * Driver interface
420 */
421
422/* Return 0 if detection is successful, -ENODEV otherwise */
423static int emc6w201_detect(struct i2c_client *client,
424 struct i2c_board_info *info)
425{
426 struct i2c_adapter *adapter = client->adapter;
427 int company, verstep, config;
428
429 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
430 return -ENODEV;
431
432 /* Identification */
433 company = i2c_smbus_read_byte_data(client, EMC6W201_REG_COMPANY);
434 if (company != 0x5C)
435 return -ENODEV;
436 verstep = i2c_smbus_read_byte_data(client, EMC6W201_REG_VERSTEP);
437 if (verstep < 0 || (verstep & 0xF0) != 0xB0)
438 return -ENODEV;
439 if ((verstep & 0x0F) > 2) {
440 dev_dbg(&client->dev, "Unknwown EMC6W201 stepping %d\n",
441 verstep & 0x0F);
442 return -ENODEV;
443 }
444
445 /* Check configuration */
446 config = i2c_smbus_read_byte_data(client, EMC6W201_REG_CONFIG);
447 if ((config & 0xF4) != 0x04)
448 return -ENODEV;
449 if (!(config & 0x01)) {
450 dev_err(&client->dev, "Monitoring not enabled\n");
451 return -ENODEV;
452 }
453
454 strlcpy(info->type, "emc6w201", I2C_NAME_SIZE);
455
456 return 0;
457}
458
459static int emc6w201_probe(struct i2c_client *client,
460 const struct i2c_device_id *id)
461{
462 struct emc6w201_data *data;
463 int err;
464
465 data = kzalloc(sizeof(struct emc6w201_data), GFP_KERNEL);
466 if (!data) {
467 err = -ENOMEM;
468 goto exit;
469 }
470
471 i2c_set_clientdata(client, data);
472 mutex_init(&data->update_lock);
473
474 /* Create sysfs attribute */
475 err = sysfs_create_group(&client->dev.kobj, &emc6w201_group);
476 if (err)
477 goto exit_free;
478
479 /* Expose as a hwmon device */
480 data->hwmon_dev = hwmon_device_register(&client->dev);
481 if (IS_ERR(data->hwmon_dev)) {
482 err = PTR_ERR(data->hwmon_dev);
483 goto exit_remove;
484 }
485
486 return 0;
487
488 exit_remove:
489 sysfs_remove_group(&client->dev.kobj, &emc6w201_group);
490 exit_free:
491 kfree(data);
492 exit:
493 return err;
494}
495
496static int emc6w201_remove(struct i2c_client *client)
497{
498 struct emc6w201_data *data = i2c_get_clientdata(client);
499
500 hwmon_device_unregister(data->hwmon_dev);
501 sysfs_remove_group(&client->dev.kobj, &emc6w201_group);
502 kfree(data);
503
504 return 0;
505}
506
507static const struct i2c_device_id emc6w201_id[] = {
508 { "emc6w201", 0 },
509 { }
510};
511MODULE_DEVICE_TABLE(i2c, emc6w201_id);
512
513static struct i2c_driver emc6w201_driver = {
514 .class = I2C_CLASS_HWMON,
515 .driver = {
516 .name = "emc6w201",
517 },
518 .probe = emc6w201_probe,
519 .remove = emc6w201_remove,
520 .id_table = emc6w201_id,
521 .detect = emc6w201_detect,
522 .address_list = normal_i2c,
523};
524
525static int __init sensors_emc6w201_init(void)
526{
527 return i2c_add_driver(&emc6w201_driver);
528}
529module_init(sensors_emc6w201_init);
530
531static void __exit sensors_emc6w201_exit(void)
532{
533 i2c_del_driver(&emc6w201_driver);
534}
535module_exit(sensors_emc6w201_exit);
536
537MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
538MODULE_DESCRIPTION("SMSC EMC6W201 hardware monitoring driver");
539MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index ca07a32447c2..a4a94a096c90 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -48,6 +48,7 @@
48 48
49#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */ 49#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
50#define SIO_F71808E_ID 0x0901 /* Chipset ID */ 50#define SIO_F71808E_ID 0x0901 /* Chipset ID */
51#define SIO_F71808A_ID 0x1001 /* Chipset ID */
51#define SIO_F71858_ID 0x0507 /* Chipset ID */ 52#define SIO_F71858_ID 0x0507 /* Chipset ID */
52#define SIO_F71862_ID 0x0601 /* Chipset ID */ 53#define SIO_F71862_ID 0x0601 /* Chipset ID */
53#define SIO_F71869_ID 0x0814 /* Chipset ID */ 54#define SIO_F71869_ID 0x0814 /* Chipset ID */
@@ -107,11 +108,12 @@ static unsigned short force_id;
107module_param(force_id, ushort, 0); 108module_param(force_id, ushort, 0);
108MODULE_PARM_DESC(force_id, "Override the detected device ID"); 109MODULE_PARM_DESC(force_id, "Override the detected device ID");
109 110
110enum chips { f71808e, f71858fg, f71862fg, f71869, f71882fg, f71889fg, 111enum chips { f71808e, f71808a, f71858fg, f71862fg, f71869, f71882fg, f71889fg,
111 f71889ed, f71889a, f8000, f81865f }; 112 f71889ed, f71889a, f8000, f81865f };
112 113
113static const char *f71882fg_names[] = { 114static const char *f71882fg_names[] = {
114 "f71808e", 115 "f71808e",
116 "f71808a",
115 "f71858fg", 117 "f71858fg",
116 "f71862fg", 118 "f71862fg",
117 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */ 119 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
@@ -125,6 +127,7 @@ static const char *f71882fg_names[] = {
125 127
126static const char f71882fg_has_in[][F71882FG_MAX_INS] = { 128static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
127 [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 }, 129 [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
130 [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 },
128 [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, 131 [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
129 [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 132 [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
130 [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, 133 [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
@@ -138,6 +141,7 @@ static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
138 141
139static const char f71882fg_has_in1_alarm[] = { 142static const char f71882fg_has_in1_alarm[] = {
140 [f71808e] = 0, 143 [f71808e] = 0,
144 [f71808a] = 0,
141 [f71858fg] = 0, 145 [f71858fg] = 0,
142 [f71862fg] = 0, 146 [f71862fg] = 0,
143 [f71869] = 0, 147 [f71869] = 0,
@@ -149,8 +153,9 @@ static const char f71882fg_has_in1_alarm[] = {
149 [f81865f] = 1, 153 [f81865f] = 1,
150}; 154};
151 155
152static const char f71882fg_has_beep[] = { 156static const char f71882fg_fan_has_beep[] = {
153 [f71808e] = 0, 157 [f71808e] = 0,
158 [f71808a] = 0,
154 [f71858fg] = 0, 159 [f71858fg] = 0,
155 [f71862fg] = 1, 160 [f71862fg] = 1,
156 [f71869] = 1, 161 [f71869] = 1,
@@ -164,6 +169,7 @@ static const char f71882fg_has_beep[] = {
164 169
165static const char f71882fg_nr_fans[] = { 170static const char f71882fg_nr_fans[] = {
166 [f71808e] = 3, 171 [f71808e] = 3,
172 [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
167 [f71858fg] = 3, 173 [f71858fg] = 3,
168 [f71862fg] = 3, 174 [f71862fg] = 3,
169 [f71869] = 3, 175 [f71869] = 3,
@@ -171,12 +177,27 @@ static const char f71882fg_nr_fans[] = {
171 [f71889fg] = 3, 177 [f71889fg] = 3,
172 [f71889ed] = 3, 178 [f71889ed] = 3,
173 [f71889a] = 3, 179 [f71889a] = 3,
174 [f8000] = 3, 180 [f8000] = 3, /* +1 fan which is monitor only */
175 [f81865f] = 2, 181 [f81865f] = 2,
176}; 182};
177 183
184static const char f71882fg_temp_has_beep[] = {
185 [f71808e] = 0,
186 [f71808a] = 1,
187 [f71858fg] = 0,
188 [f71862fg] = 1,
189 [f71869] = 1,
190 [f71882fg] = 1,
191 [f71889fg] = 1,
192 [f71889ed] = 1,
193 [f71889a] = 1,
194 [f8000] = 0,
195 [f81865f] = 1,
196};
197
178static const char f71882fg_nr_temps[] = { 198static const char f71882fg_nr_temps[] = {
179 [f71808e] = 2, 199 [f71808e] = 2,
200 [f71808a] = 2,
180 [f71858fg] = 3, 201 [f71858fg] = 3,
181 [f71862fg] = 3, 202 [f71862fg] = 3,
182 [f71869] = 3, 203 [f71869] = 3,
@@ -301,6 +322,10 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
301 char *buf); 322 char *buf);
302static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr, 323static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
303 const char *buf, size_t count); 324 const char *buf, size_t count);
325static ssize_t show_simple_pwm(struct device *dev,
326 struct device_attribute *devattr, char *buf);
327static ssize_t store_simple_pwm(struct device *dev,
328 struct device_attribute *devattr, const char *buf, size_t count);
304static ssize_t show_pwm_enable(struct device *dev, 329static ssize_t show_pwm_enable(struct device *dev,
305 struct device_attribute *devattr, char *buf); 330 struct device_attribute *devattr, char *buf);
306static ssize_t store_pwm_enable(struct device *dev, 331static ssize_t store_pwm_enable(struct device *dev,
@@ -550,6 +575,14 @@ static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
550 show_pwm_interpolate, store_pwm_interpolate, 0, 3), 575 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
551} }; 576} };
552 577
578/* Attr for the third fan of the f71808a, which only has manual pwm */
579static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
580 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
581 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
582 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
583 show_simple_pwm, store_simple_pwm, 0, 2),
584};
585
553/* Attr for models which can beep on Fan alarm */ 586/* Attr for models which can beep on Fan alarm */
554static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = { 587static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
555 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep, 588 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
@@ -1146,12 +1179,13 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
1146 data->temp_type[3] = (reg & 0x08) ? 2 : 4; 1179 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
1147 } 1180 }
1148 1181
1149 if (f71882fg_has_beep[data->type]) { 1182 if (f71882fg_fan_has_beep[data->type])
1150 data->fan_beep = f71882fg_read8(data, 1183 data->fan_beep = f71882fg_read8(data,
1151 F71882FG_REG_FAN_BEEP); 1184 F71882FG_REG_FAN_BEEP);
1185
1186 if (f71882fg_temp_has_beep[data->type])
1152 data->temp_beep = f71882fg_read8(data, 1187 data->temp_beep = f71882fg_read8(data,
1153 F71882FG_REG_TEMP_BEEP); 1188 F71882FG_REG_TEMP_BEEP);
1154 }
1155 1189
1156 data->pwm_enable = f71882fg_read8(data, 1190 data->pwm_enable = f71882fg_read8(data,
1157 F71882FG_REG_PWM_ENABLE); 1191 F71882FG_REG_PWM_ENABLE);
@@ -1232,7 +1266,13 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
1232 data->pwm[nr] = 1266 data->pwm[nr] =
1233 f71882fg_read8(data, F71882FG_REG_PWM(nr)); 1267 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1234 } 1268 }
1235 /* The f8000 can monitor 1 more fan, but has no pwm for it */ 1269 /* Some models have 1 more fan with limited capabilities */
1270 if (data->type == f71808a) {
1271 data->fan[2] = f71882fg_read16(data,
1272 F71882FG_REG_FAN(2));
1273 data->pwm[2] = f71882fg_read8(data,
1274 F71882FG_REG_PWM(2));
1275 }
1236 if (data->type == f8000) 1276 if (data->type == f8000)
1237 data->fan[3] = f71882fg_read16(data, 1277 data->fan[3] = f71882fg_read16(data,
1238 F71882FG_REG_FAN(3)); 1278 F71882FG_REG_FAN(3));
@@ -1722,6 +1762,38 @@ leave:
1722 return count; 1762 return count;
1723} 1763}
1724 1764
1765static ssize_t show_simple_pwm(struct device *dev,
1766 struct device_attribute *devattr, char *buf)
1767{
1768 struct f71882fg_data *data = f71882fg_update_device(dev);
1769 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1770
1771 val = data->pwm[nr];
1772 return sprintf(buf, "%d\n", val);
1773}
1774
1775static ssize_t store_simple_pwm(struct device *dev,
1776 struct device_attribute *devattr,
1777 const char *buf, size_t count)
1778{
1779 struct f71882fg_data *data = dev_get_drvdata(dev);
1780 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1781 long val;
1782
1783 err = strict_strtol(buf, 10, &val);
1784 if (err)
1785 return err;
1786
1787 val = SENSORS_LIMIT(val, 0, 255);
1788
1789 mutex_lock(&data->update_lock);
1790 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1791 data->pwm[nr] = val;
1792 mutex_unlock(&data->update_lock);
1793
1794 return count;
1795}
1796
1725static ssize_t show_pwm_enable(struct device *dev, 1797static ssize_t show_pwm_enable(struct device *dev,
1726 struct device_attribute *devattr, char *buf) 1798 struct device_attribute *devattr, char *buf)
1727{ 1799{
@@ -2140,7 +2212,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2140 if (err) 2212 if (err)
2141 goto exit_unregister_sysfs; 2213 goto exit_unregister_sysfs;
2142 2214
2143 if (f71882fg_has_beep[data->type]) { 2215 if (f71882fg_temp_has_beep[data->type]) {
2144 err = f71882fg_create_sysfs_files(pdev, 2216 err = f71882fg_create_sysfs_files(pdev,
2145 &fxxxx_temp_beep_attr[0][0], 2217 &fxxxx_temp_beep_attr[0][0],
2146 ARRAY_SIZE(fxxxx_temp_beep_attr[0]) 2218 ARRAY_SIZE(fxxxx_temp_beep_attr[0])
@@ -2169,6 +2241,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2169 if (start_reg & 0x02) { 2241 if (start_reg & 0x02) {
2170 switch (data->type) { 2242 switch (data->type) {
2171 case f71808e: 2243 case f71808e:
2244 case f71808a:
2172 case f71869: 2245 case f71869:
2173 /* These always have signed auto point temps */ 2246 /* These always have signed auto point temps */
2174 data->auto_point_temp_signed = 1; 2247 data->auto_point_temp_signed = 1;
@@ -2221,7 +2294,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2221 if (err) 2294 if (err)
2222 goto exit_unregister_sysfs; 2295 goto exit_unregister_sysfs;
2223 2296
2224 if (f71882fg_has_beep[data->type]) { 2297 if (f71882fg_fan_has_beep[data->type]) {
2225 err = f71882fg_create_sysfs_files(pdev, 2298 err = f71882fg_create_sysfs_files(pdev,
2226 fxxxx_fan_beep_attr, nr_fans); 2299 fxxxx_fan_beep_attr, nr_fans);
2227 if (err) 2300 if (err)
@@ -2230,6 +2303,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2230 2303
2231 switch (data->type) { 2304 switch (data->type) {
2232 case f71808e: 2305 case f71808e:
2306 case f71808a:
2233 case f71869: 2307 case f71869:
2234 case f71889fg: 2308 case f71889fg:
2235 case f71889ed: 2309 case f71889ed:
@@ -2255,6 +2329,16 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
2255 } 2329 }
2256 2330
2257 switch (data->type) { 2331 switch (data->type) {
2332 case f71808a:
2333 err = f71882fg_create_sysfs_files(pdev,
2334 &fxxxx_auto_pwm_attr[0][0],
2335 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2336 if (err)
2337 goto exit_unregister_sysfs;
2338 err = f71882fg_create_sysfs_files(pdev,
2339 f71808a_fan3_attr,
2340 ARRAY_SIZE(f71808a_fan3_attr));
2341 break;
2258 case f71862fg: 2342 case f71862fg:
2259 err = f71882fg_create_sysfs_files(pdev, 2343 err = f71882fg_create_sysfs_files(pdev,
2260 f71862fg_auto_pwm_attr, 2344 f71862fg_auto_pwm_attr,
@@ -2343,7 +2427,7 @@ static int f71882fg_remove(struct platform_device *pdev)
2343 &fxxxx_temp_attr[0][0], 2427 &fxxxx_temp_attr[0][0],
2344 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps); 2428 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
2345 } 2429 }
2346 if (f71882fg_has_beep[data->type]) { 2430 if (f71882fg_temp_has_beep[data->type]) {
2347 f71882fg_remove_sysfs_files(pdev, 2431 f71882fg_remove_sysfs_files(pdev,
2348 &fxxxx_temp_beep_attr[0][0], 2432 &fxxxx_temp_beep_attr[0][0],
2349 ARRAY_SIZE(fxxxx_temp_beep_attr[0]) * nr_temps); 2433 ARRAY_SIZE(fxxxx_temp_beep_attr[0]) * nr_temps);
@@ -2366,12 +2450,20 @@ static int f71882fg_remove(struct platform_device *pdev)
2366 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0], 2450 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2367 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans); 2451 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2368 2452
2369 if (f71882fg_has_beep[data->type]) { 2453 if (f71882fg_fan_has_beep[data->type]) {
2370 f71882fg_remove_sysfs_files(pdev, 2454 f71882fg_remove_sysfs_files(pdev,
2371 fxxxx_fan_beep_attr, nr_fans); 2455 fxxxx_fan_beep_attr, nr_fans);
2372 } 2456 }
2373 2457
2374 switch (data->type) { 2458 switch (data->type) {
2459 case f71808a:
2460 f71882fg_remove_sysfs_files(pdev,
2461 &fxxxx_auto_pwm_attr[0][0],
2462 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2463 f71882fg_remove_sysfs_files(pdev,
2464 f71808a_fan3_attr,
2465 ARRAY_SIZE(f71808a_fan3_attr));
2466 break;
2375 case f71862fg: 2467 case f71862fg:
2376 f71882fg_remove_sysfs_files(pdev, 2468 f71882fg_remove_sysfs_files(pdev,
2377 f71862fg_auto_pwm_attr, 2469 f71862fg_auto_pwm_attr,
@@ -2424,6 +2516,9 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
2424 case SIO_F71808E_ID: 2516 case SIO_F71808E_ID:
2425 sio_data->type = f71808e; 2517 sio_data->type = f71808e;
2426 break; 2518 break;
2519 case SIO_F71808A_ID:
2520 sio_data->type = f71808a;
2521 break;
2427 case SIO_F71858_ID: 2522 case SIO_F71858_ID:
2428 sio_data->type = f71858fg; 2523 sio_data->type = f71858fg;
2429 break; 2524 break;
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
new file mode 100644
index 000000000000..523f8fb9e7d9
--- /dev/null
+++ b/drivers/hwmon/fam15h_power.c
@@ -0,0 +1,229 @@
1/*
2 * fam15h_power.c - AMD Family 15h processor power monitoring
3 *
4 * Copyright (c) 2011 Advanced Micro Devices, Inc.
5 * Author: Andreas Herrmann <andreas.herrmann3@amd.com>
6 *
7 *
8 * This driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This driver 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.
15 * See the 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 driver; if not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/err.h>
22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/pci.h>
27#include <linux/bitops.h>
28#include <asm/processor.h>
29
30MODULE_DESCRIPTION("AMD Family 15h CPU processor power monitor");
31MODULE_AUTHOR("Andreas Herrmann <andreas.herrmann3@amd.com>");
32MODULE_LICENSE("GPL");
33
34/* D18F3 */
35#define REG_NORTHBRIDGE_CAP 0xe8
36
37/* D18F4 */
38#define REG_PROCESSOR_TDP 0x1b8
39
40/* D18F5 */
41#define REG_TDP_RUNNING_AVERAGE 0xe0
42#define REG_TDP_LIMIT3 0xe8
43
44struct fam15h_power_data {
45 struct device *hwmon_dev;
46 unsigned int tdp_to_watts;
47 unsigned int base_tdp;
48 unsigned int processor_pwr_watts;
49};
50
51static ssize_t show_power(struct device *dev,
52 struct device_attribute *attr, char *buf)
53{
54 u32 val, tdp_limit, running_avg_range;
55 s32 running_avg_capture;
56 u64 curr_pwr_watts;
57 struct pci_dev *f4 = to_pci_dev(dev);
58 struct fam15h_power_data *data = dev_get_drvdata(dev);
59
60 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
61 REG_TDP_RUNNING_AVERAGE, &val);
62 running_avg_capture = (val >> 4) & 0x3fffff;
63 running_avg_capture = sign_extend32(running_avg_capture, 22);
64 running_avg_range = val & 0xf;
65
66 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
67 REG_TDP_LIMIT3, &val);
68
69 tdp_limit = val >> 16;
70 curr_pwr_watts = tdp_limit + data->base_tdp -
71 (s32)(running_avg_capture >> (running_avg_range + 1));
72 curr_pwr_watts *= data->tdp_to_watts;
73
74 /*
75 * Convert to microWatt
76 *
77 * power is in Watt provided as fixed point integer with
78 * scaling factor 1/(2^16). For conversion we use
79 * (10^6)/(2^16) = 15625/(2^10)
80 */
81 curr_pwr_watts = (curr_pwr_watts * 15625) >> 10;
82 return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts);
83}
84static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL);
85
86static ssize_t show_power_crit(struct device *dev,
87 struct device_attribute *attr, char *buf)
88{
89 struct fam15h_power_data *data = dev_get_drvdata(dev);
90
91 return sprintf(buf, "%u\n", data->processor_pwr_watts);
92}
93static DEVICE_ATTR(power1_crit, S_IRUGO, show_power_crit, NULL);
94
95static ssize_t show_name(struct device *dev,
96 struct device_attribute *attr, char *buf)
97{
98 return sprintf(buf, "fam15h_power\n");
99}
100static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
101
102static struct attribute *fam15h_power_attrs[] = {
103 &dev_attr_power1_input.attr,
104 &dev_attr_power1_crit.attr,
105 &dev_attr_name.attr,
106 NULL
107};
108
109static const struct attribute_group fam15h_power_attr_group = {
110 .attrs = fam15h_power_attrs,
111};
112
113static bool __devinit fam15h_power_is_internal_node0(struct pci_dev *f4)
114{
115 u32 val;
116
117 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 3),
118 REG_NORTHBRIDGE_CAP, &val);
119 if ((val & BIT(29)) && ((val >> 30) & 3))
120 return false;
121
122 return true;
123}
124
125static void __devinit fam15h_power_init_data(struct pci_dev *f4,
126 struct fam15h_power_data *data)
127{
128 u32 val;
129 u64 tmp;
130
131 pci_read_config_dword(f4, REG_PROCESSOR_TDP, &val);
132 data->base_tdp = val >> 16;
133 tmp = val & 0xffff;
134
135 pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
136 REG_TDP_LIMIT3, &val);
137
138 data->tdp_to_watts = ((val & 0x3ff) << 6) | ((val >> 10) & 0x3f);
139 tmp *= data->tdp_to_watts;
140
141 /* result not allowed to be >= 256W */
142 if ((tmp >> 16) >= 256)
143 dev_warn(&f4->dev, "Bogus value for ProcessorPwrWatts "
144 "(processor_pwr_watts>=%u)\n",
145 (unsigned int) (tmp >> 16));
146
147 /* convert to microWatt */
148 data->processor_pwr_watts = (tmp * 15625) >> 10;
149}
150
151static int __devinit fam15h_power_probe(struct pci_dev *pdev,
152 const struct pci_device_id *id)
153{
154 struct fam15h_power_data *data;
155 struct device *dev;
156 int err;
157
158 if (!fam15h_power_is_internal_node0(pdev)) {
159 err = -ENODEV;
160 goto exit;
161 }
162
163 data = kzalloc(sizeof(struct fam15h_power_data), GFP_KERNEL);
164 if (!data) {
165 err = -ENOMEM;
166 goto exit;
167 }
168 fam15h_power_init_data(pdev, data);
169 dev = &pdev->dev;
170
171 dev_set_drvdata(dev, data);
172 err = sysfs_create_group(&dev->kobj, &fam15h_power_attr_group);
173 if (err)
174 goto exit_free_data;
175
176 data->hwmon_dev = hwmon_device_register(dev);
177 if (IS_ERR(data->hwmon_dev)) {
178 err = PTR_ERR(data->hwmon_dev);
179 goto exit_remove_group;
180 }
181
182 return 0;
183
184exit_remove_group:
185 sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group);
186exit_free_data:
187 kfree(data);
188exit:
189 return err;
190}
191
192static void __devexit fam15h_power_remove(struct pci_dev *pdev)
193{
194 struct device *dev;
195 struct fam15h_power_data *data;
196
197 dev = &pdev->dev;
198 data = dev_get_drvdata(dev);
199 hwmon_device_unregister(data->hwmon_dev);
200 sysfs_remove_group(&dev->kobj, &fam15h_power_attr_group);
201 dev_set_drvdata(dev, NULL);
202 kfree(data);
203}
204
205static DEFINE_PCI_DEVICE_TABLE(fam15h_power_id_table) = {
206 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
207 {}
208};
209MODULE_DEVICE_TABLE(pci, fam15h_power_id_table);
210
211static struct pci_driver fam15h_power_driver = {
212 .name = "fam15h_power",
213 .id_table = fam15h_power_id_table,
214 .probe = fam15h_power_probe,
215 .remove = __devexit_p(fam15h_power_remove),
216};
217
218static int __init fam15h_power_init(void)
219{
220 return pci_register_driver(&fam15h_power_driver);
221}
222
223static void __exit fam15h_power_exit(void)
224{
225 pci_unregister_driver(&fam15h_power_driver);
226}
227
228module_init(fam15h_power_init)
229module_exit(fam15h_power_exit)
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index bc6e2ab3a361..537409d07ee7 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -523,7 +523,7 @@ static void aem_delete(struct aem_data *data)
523 aem_remove_sensors(data); 523 aem_remove_sensors(data);
524 hwmon_device_unregister(data->hwmon_dev); 524 hwmon_device_unregister(data->hwmon_dev);
525 ipmi_destroy_user(data->ipmi.user); 525 ipmi_destroy_user(data->ipmi.user);
526 dev_set_drvdata(&data->pdev->dev, NULL); 526 platform_set_drvdata(data->pdev, NULL);
527 platform_device_unregister(data->pdev); 527 platform_device_unregister(data->pdev);
528 aem_idr_put(data->id); 528 aem_idr_put(data->id);
529 kfree(data); 529 kfree(data);
@@ -594,7 +594,7 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
594 if (res) 594 if (res)
595 goto ipmi_err; 595 goto ipmi_err;
596 596
597 dev_set_drvdata(&data->pdev->dev, data); 597 platform_set_drvdata(data->pdev, data);
598 598
599 /* Set up IPMI interface */ 599 /* Set up IPMI interface */
600 if (aem_init_ipmi_data(&data->ipmi, probe->interface, 600 if (aem_init_ipmi_data(&data->ipmi, probe->interface,
@@ -630,7 +630,7 @@ sensor_err:
630hwmon_reg_err: 630hwmon_reg_err:
631 ipmi_destroy_user(data->ipmi.user); 631 ipmi_destroy_user(data->ipmi.user);
632ipmi_err: 632ipmi_err:
633 dev_set_drvdata(&data->pdev->dev, NULL); 633 platform_set_drvdata(data->pdev, NULL);
634 platform_device_unregister(data->pdev); 634 platform_device_unregister(data->pdev);
635dev_err: 635dev_err:
636 aem_idr_put(data->id); 636 aem_idr_put(data->id);
@@ -727,7 +727,7 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
727 if (res) 727 if (res)
728 goto ipmi_err; 728 goto ipmi_err;
729 729
730 dev_set_drvdata(&data->pdev->dev, data); 730 platform_set_drvdata(data->pdev, data);
731 731
732 /* Set up IPMI interface */ 732 /* Set up IPMI interface */
733 if (aem_init_ipmi_data(&data->ipmi, probe->interface, 733 if (aem_init_ipmi_data(&data->ipmi, probe->interface,
@@ -763,7 +763,7 @@ sensor_err:
763hwmon_reg_err: 763hwmon_reg_err:
764 ipmi_destroy_user(data->ipmi.user); 764 ipmi_destroy_user(data->ipmi.user);
765ipmi_err: 765ipmi_err:
766 dev_set_drvdata(&data->pdev->dev, NULL); 766 platform_set_drvdata(data->pdev, NULL);
767 platform_device_unregister(data->pdev); 767 platform_device_unregister(data->pdev);
768dev_err: 768dev_err:
769 aem_idr_put(data->id); 769 aem_idr_put(data->id);
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 316b64823f7b..bb6405b92007 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -77,15 +77,13 @@ static struct platform_device *pdev;
77#define DEVID 0x20 /* Register: Device ID */ 77#define DEVID 0x20 /* Register: Device ID */
78#define DEVREV 0x22 /* Register: Device Revision */ 78#define DEVREV 0x22 /* Register: Device Revision */
79 79
80static inline int 80static inline int superio_inb(int reg)
81superio_inb(int reg)
82{ 81{
83 outb(reg, REG); 82 outb(reg, REG);
84 return inb(VAL); 83 return inb(VAL);
85} 84}
86 85
87static inline void 86static inline void superio_outb(int reg, int val)
88superio_outb(int reg, int val)
89{ 87{
90 outb(reg, REG); 88 outb(reg, REG);
91 outb(val, VAL); 89 outb(val, VAL);
@@ -101,27 +99,32 @@ static int superio_inw(int reg)
101 return val; 99 return val;
102} 100}
103 101
104static inline void 102static inline void superio_select(int ldn)
105superio_select(int ldn)
106{ 103{
107 outb(DEV, REG); 104 outb(DEV, REG);
108 outb(ldn, VAL); 105 outb(ldn, VAL);
109} 106}
110 107
111static inline void 108static inline int superio_enter(void)
112superio_enter(void)
113{ 109{
110 /*
111 * Try to reserve REG and REG + 1 for exclusive access.
112 */
113 if (!request_muxed_region(REG, 2, DRVNAME))
114 return -EBUSY;
115
114 outb(0x87, REG); 116 outb(0x87, REG);
115 outb(0x01, REG); 117 outb(0x01, REG);
116 outb(0x55, REG); 118 outb(0x55, REG);
117 outb(0x55, REG); 119 outb(0x55, REG);
120 return 0;
118} 121}
119 122
120static inline void 123static inline void superio_exit(void)
121superio_exit(void)
122{ 124{
123 outb(0x02, REG); 125 outb(0x02, REG);
124 outb(0x02, VAL); 126 outb(0x02, VAL);
127 release_region(REG, 2);
125} 128}
126 129
127/* Logical device 4 registers */ 130/* Logical device 4 registers */
@@ -1542,11 +1545,15 @@ static const struct attribute_group it87_group_label = {
1542static int __init it87_find(unsigned short *address, 1545static int __init it87_find(unsigned short *address,
1543 struct it87_sio_data *sio_data) 1546 struct it87_sio_data *sio_data)
1544{ 1547{
1545 int err = -ENODEV; 1548 int err;
1546 u16 chip_type; 1549 u16 chip_type;
1547 const char *board_vendor, *board_name; 1550 const char *board_vendor, *board_name;
1548 1551
1549 superio_enter(); 1552 err = superio_enter();
1553 if (err)
1554 return err;
1555
1556 err = -ENODEV;
1550 chip_type = force_id ? force_id : superio_inw(DEVID); 1557 chip_type = force_id ? force_id : superio_inw(DEVID);
1551 1558
1552 switch (chip_type) { 1559 switch (chip_type) {
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index 934991237061..02cebb74e206 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -213,7 +213,7 @@ static const struct dev_pm_ops jc42_dev_pm_ops = {
213 213
214/* This is the driver that will be inserted */ 214/* This is the driver that will be inserted */
215static struct i2c_driver jc42_driver = { 215static struct i2c_driver jc42_driver = {
216 .class = I2C_CLASS_HWMON, 216 .class = I2C_CLASS_SPD,
217 .driver = { 217 .driver = {
218 .name = "jc42", 218 .name = "jc42",
219 .pm = JC42_DEV_PM_OPS, 219 .pm = JC42_DEV_PM_OPS,
diff --git a/drivers/hwmon/k10temp.c b/drivers/hwmon/k10temp.c
index 82bf65aa2968..41aa6a319870 100644
--- a/drivers/hwmon/k10temp.c
+++ b/drivers/hwmon/k10temp.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * k10temp.c - AMD Family 10h/11h/12h/14h processor hardware monitoring 2 * k10temp.c - AMD Family 10h/11h/12h/14h/15h processor hardware monitoring
3 * 3 *
4 * Copyright (c) 2009 Clemens Ladisch <clemens@ladisch.de> 4 * Copyright (c) 2009 Clemens Ladisch <clemens@ladisch.de>
5 * 5 *
@@ -25,7 +25,7 @@
25#include <linux/pci.h> 25#include <linux/pci.h>
26#include <asm/processor.h> 26#include <asm/processor.h>
27 27
28MODULE_DESCRIPTION("AMD Family 10h/11h/12h/14h CPU core temperature monitor"); 28MODULE_DESCRIPTION("AMD Family 10h+ CPU core temperature monitor");
29MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 29MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
31 31
@@ -173,7 +173,7 @@ static int __devinit k10temp_probe(struct pci_dev *pdev,
173 err = PTR_ERR(hwmon_dev); 173 err = PTR_ERR(hwmon_dev);
174 goto exit_remove; 174 goto exit_remove;
175 } 175 }
176 dev_set_drvdata(&pdev->dev, hwmon_dev); 176 pci_set_drvdata(pdev, hwmon_dev);
177 177
178 if (unreliable && force) 178 if (unreliable && force)
179 dev_warn(&pdev->dev, 179 dev_warn(&pdev->dev,
@@ -194,7 +194,7 @@ exit:
194 194
195static void __devexit k10temp_remove(struct pci_dev *pdev) 195static void __devexit k10temp_remove(struct pci_dev *pdev)
196{ 196{
197 hwmon_device_unregister(dev_get_drvdata(&pdev->dev)); 197 hwmon_device_unregister(pci_get_drvdata(pdev));
198 device_remove_file(&pdev->dev, &dev_attr_name); 198 device_remove_file(&pdev->dev, &dev_attr_name);
199 device_remove_file(&pdev->dev, &dev_attr_temp1_input); 199 device_remove_file(&pdev->dev, &dev_attr_temp1_input);
200 device_remove_file(&pdev->dev, &dev_attr_temp1_max); 200 device_remove_file(&pdev->dev, &dev_attr_temp1_max);
@@ -202,13 +202,14 @@ static void __devexit k10temp_remove(struct pci_dev *pdev)
202 &sensor_dev_attr_temp1_crit.dev_attr); 202 &sensor_dev_attr_temp1_crit.dev_attr);
203 device_remove_file(&pdev->dev, 203 device_remove_file(&pdev->dev,
204 &sensor_dev_attr_temp1_crit_hyst.dev_attr); 204 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
205 dev_set_drvdata(&pdev->dev, NULL); 205 pci_set_drvdata(pdev, NULL);
206} 206}
207 207
208static const struct pci_device_id k10temp_id_table[] = { 208static const struct pci_device_id k10temp_id_table[] = {
209 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) }, 209 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) },
210 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) }, 210 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_11H_NB_MISC) },
211 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) }, 211 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_CNB17H_F3) },
212 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
212 {} 213 {}
213}; 214};
214MODULE_DEVICE_TABLE(pci, k10temp_id_table); 215MODULE_DEVICE_TABLE(pci, k10temp_id_table);
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
index 418496f13020..b923bc2307ad 100644
--- a/drivers/hwmon/k8temp.c
+++ b/drivers/hwmon/k8temp.c
@@ -252,7 +252,7 @@ static int __devinit k8temp_probe(struct pci_dev *pdev,
252 252
253 data->name = "k8temp"; 253 data->name = "k8temp";
254 mutex_init(&data->update_lock); 254 mutex_init(&data->update_lock);
255 dev_set_drvdata(&pdev->dev, data); 255 pci_set_drvdata(pdev, data);
256 256
257 /* Register sysfs hooks */ 257 /* Register sysfs hooks */
258 err = device_create_file(&pdev->dev, 258 err = device_create_file(&pdev->dev,
@@ -307,7 +307,7 @@ exit_remove:
307 &sensor_dev_attr_temp4_input.dev_attr); 307 &sensor_dev_attr_temp4_input.dev_attr);
308 device_remove_file(&pdev->dev, &dev_attr_name); 308 device_remove_file(&pdev->dev, &dev_attr_name);
309exit_free: 309exit_free:
310 dev_set_drvdata(&pdev->dev, NULL); 310 pci_set_drvdata(pdev, NULL);
311 kfree(data); 311 kfree(data);
312exit: 312exit:
313 return err; 313 return err;
@@ -315,7 +315,7 @@ exit:
315 315
316static void __devexit k8temp_remove(struct pci_dev *pdev) 316static void __devexit k8temp_remove(struct pci_dev *pdev)
317{ 317{
318 struct k8temp_data *data = dev_get_drvdata(&pdev->dev); 318 struct k8temp_data *data = pci_get_drvdata(pdev);
319 319
320 hwmon_device_unregister(data->hwmon_dev); 320 hwmon_device_unregister(data->hwmon_dev);
321 device_remove_file(&pdev->dev, 321 device_remove_file(&pdev->dev,
@@ -327,7 +327,7 @@ static void __devexit k8temp_remove(struct pci_dev *pdev)
327 device_remove_file(&pdev->dev, 327 device_remove_file(&pdev->dev,
328 &sensor_dev_attr_temp4_input.dev_attr); 328 &sensor_dev_attr_temp4_input.dev_attr);
329 device_remove_file(&pdev->dev, &dev_attr_name); 329 device_remove_file(&pdev->dev, &dev_attr_name);
330 dev_set_drvdata(&pdev->dev, NULL); 330 pci_set_drvdata(pdev, NULL);
331 kfree(data); 331 kfree(data);
332} 332}
333 333
diff --git a/drivers/hwmon/lm70.c b/drivers/hwmon/lm70.c
index 3b84fb503053..c274ea25d899 100644
--- a/drivers/hwmon/lm70.c
+++ b/drivers/hwmon/lm70.c
@@ -58,7 +58,7 @@ static ssize_t lm70_sense_temp(struct device *dev,
58 int status, val = 0; 58 int status, val = 0;
59 u8 rxbuf[2]; 59 u8 rxbuf[2];
60 s16 raw=0; 60 s16 raw=0;
61 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 61 struct lm70 *p_lm70 = spi_get_drvdata(spi);
62 62
63 if (mutex_lock_interruptible(&p_lm70->lock)) 63 if (mutex_lock_interruptible(&p_lm70->lock))
64 return -ERESTARTSYS; 64 return -ERESTARTSYS;
@@ -163,7 +163,7 @@ static int __devinit lm70_probe(struct spi_device *spi)
163 status = PTR_ERR(p_lm70->hwmon_dev); 163 status = PTR_ERR(p_lm70->hwmon_dev);
164 goto out_dev_reg_failed; 164 goto out_dev_reg_failed;
165 } 165 }
166 dev_set_drvdata(&spi->dev, p_lm70); 166 spi_set_drvdata(spi, p_lm70);
167 167
168 if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input)) 168 if ((status = device_create_file(&spi->dev, &dev_attr_temp1_input))
169 || (status = device_create_file(&spi->dev, &dev_attr_name))) { 169 || (status = device_create_file(&spi->dev, &dev_attr_name))) {
@@ -177,19 +177,19 @@ out_dev_create_file_failed:
177 device_remove_file(&spi->dev, &dev_attr_temp1_input); 177 device_remove_file(&spi->dev, &dev_attr_temp1_input);
178 hwmon_device_unregister(p_lm70->hwmon_dev); 178 hwmon_device_unregister(p_lm70->hwmon_dev);
179out_dev_reg_failed: 179out_dev_reg_failed:
180 dev_set_drvdata(&spi->dev, NULL); 180 spi_set_drvdata(spi, NULL);
181 kfree(p_lm70); 181 kfree(p_lm70);
182 return status; 182 return status;
183} 183}
184 184
185static int __devexit lm70_remove(struct spi_device *spi) 185static int __devexit lm70_remove(struct spi_device *spi)
186{ 186{
187 struct lm70 *p_lm70 = dev_get_drvdata(&spi->dev); 187 struct lm70 *p_lm70 = spi_get_drvdata(spi);
188 188
189 device_remove_file(&spi->dev, &dev_attr_temp1_input); 189 device_remove_file(&spi->dev, &dev_attr_temp1_input);
190 device_remove_file(&spi->dev, &dev_attr_name); 190 device_remove_file(&spi->dev, &dev_attr_name);
191 hwmon_device_unregister(p_lm70->hwmon_dev); 191 hwmon_device_unregister(p_lm70->hwmon_dev);
192 dev_set_drvdata(&spi->dev, NULL); 192 spi_set_drvdata(spi, NULL);
193 kfree(p_lm70); 193 kfree(p_lm70);
194 194
195 return 0; 195 return 0;
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 9a11532ecae8..ece3aafa54b3 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -41,13 +41,6 @@
41#include <linux/err.h> 41#include <linux/err.h>
42 42
43/* 43/*
44 * Addresses to scan. There are four disjoint possibilities, by pin config.
45 */
46
47static const unsigned short normal_i2c[] = {0x1b, 0x1f, 0x48, 0x4b,
48 I2C_CLIENT_END};
49
50/*
51 * Insmod parameters 44 * Insmod parameters
52 */ 45 */
53 46
@@ -114,8 +107,6 @@ module_param(clock, int, S_IRUGO);
114 107
115static int max6650_probe(struct i2c_client *client, 108static int max6650_probe(struct i2c_client *client,
116 const struct i2c_device_id *id); 109 const struct i2c_device_id *id);
117static int max6650_detect(struct i2c_client *client,
118 struct i2c_board_info *info);
119static int max6650_init_client(struct i2c_client *client); 110static int max6650_init_client(struct i2c_client *client);
120static int max6650_remove(struct i2c_client *client); 111static int max6650_remove(struct i2c_client *client);
121static struct max6650_data *max6650_update_device(struct device *dev); 112static struct max6650_data *max6650_update_device(struct device *dev);
@@ -125,21 +116,19 @@ static struct max6650_data *max6650_update_device(struct device *dev);
125 */ 116 */
126 117
127static const struct i2c_device_id max6650_id[] = { 118static const struct i2c_device_id max6650_id[] = {
128 { "max6650", 0 }, 119 { "max6650", 1 },
120 { "max6651", 4 },
129 { } 121 { }
130}; 122};
131MODULE_DEVICE_TABLE(i2c, max6650_id); 123MODULE_DEVICE_TABLE(i2c, max6650_id);
132 124
133static struct i2c_driver max6650_driver = { 125static struct i2c_driver max6650_driver = {
134 .class = I2C_CLASS_HWMON,
135 .driver = { 126 .driver = {
136 .name = "max6650", 127 .name = "max6650",
137 }, 128 },
138 .probe = max6650_probe, 129 .probe = max6650_probe,
139 .remove = max6650_remove, 130 .remove = max6650_remove,
140 .id_table = max6650_id, 131 .id_table = max6650_id,
141 .detect = max6650_detect,
142 .address_list = normal_i2c,
143}; 132};
144 133
145/* 134/*
@@ -150,6 +139,7 @@ struct max6650_data
150{ 139{
151 struct device *hwmon_dev; 140 struct device *hwmon_dev;
152 struct mutex update_lock; 141 struct mutex update_lock;
142 int nr_fans;
153 char valid; /* zero until following fields are valid */ 143 char valid; /* zero until following fields are valid */
154 unsigned long last_updated; /* in jiffies */ 144 unsigned long last_updated; /* in jiffies */
155 145
@@ -501,9 +491,6 @@ static mode_t max6650_attrs_visible(struct kobject *kobj, struct attribute *a,
501 491
502static struct attribute *max6650_attrs[] = { 492static struct attribute *max6650_attrs[] = {
503 &sensor_dev_attr_fan1_input.dev_attr.attr, 493 &sensor_dev_attr_fan1_input.dev_attr.attr,
504 &sensor_dev_attr_fan2_input.dev_attr.attr,
505 &sensor_dev_attr_fan3_input.dev_attr.attr,
506 &sensor_dev_attr_fan4_input.dev_attr.attr,
507 &dev_attr_fan1_target.attr, 494 &dev_attr_fan1_target.attr,
508 &dev_attr_fan1_div.attr, 495 &dev_attr_fan1_div.attr,
509 &dev_attr_pwm1_enable.attr, 496 &dev_attr_pwm1_enable.attr,
@@ -521,42 +508,21 @@ static struct attribute_group max6650_attr_grp = {
521 .is_visible = max6650_attrs_visible, 508 .is_visible = max6650_attrs_visible,
522}; 509};
523 510
511static struct attribute *max6651_attrs[] = {
512 &sensor_dev_attr_fan2_input.dev_attr.attr,
513 &sensor_dev_attr_fan3_input.dev_attr.attr,
514 &sensor_dev_attr_fan4_input.dev_attr.attr,
515 NULL
516};
517
518static const struct attribute_group max6651_attr_grp = {
519 .attrs = max6651_attrs,
520};
521
524/* 522/*
525 * Real code 523 * Real code
526 */ 524 */
527 525
528/* Return 0 if detection is successful, -ENODEV otherwise */
529static int max6650_detect(struct i2c_client *client,
530 struct i2c_board_info *info)
531{
532 struct i2c_adapter *adapter = client->adapter;
533 int address = client->addr;
534
535 dev_dbg(&adapter->dev, "max6650_detect called\n");
536
537 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
538 dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support "
539 "byte read mode, skipping.\n");
540 return -ENODEV;
541 }
542
543 if (((i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
544 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0)
545 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0)
546 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0)
547 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) {
548 dev_dbg(&adapter->dev,
549 "max6650: detection failed at 0x%02x.\n", address);
550 return -ENODEV;
551 }
552
553 dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address);
554
555 strlcpy(info->type, "max6650", I2C_NAME_SIZE);
556
557 return 0;
558}
559
560static int max6650_probe(struct i2c_client *client, 526static int max6650_probe(struct i2c_client *client,
561 const struct i2c_device_id *id) 527 const struct i2c_device_id *id)
562{ 528{
@@ -570,6 +536,7 @@ static int max6650_probe(struct i2c_client *client,
570 536
571 i2c_set_clientdata(client, data); 537 i2c_set_clientdata(client, data);
572 mutex_init(&data->update_lock); 538 mutex_init(&data->update_lock);
539 data->nr_fans = id->driver_data;
573 540
574 /* 541 /*
575 * Initialize the max6650 chip 542 * Initialize the max6650 chip
@@ -581,6 +548,12 @@ static int max6650_probe(struct i2c_client *client,
581 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp); 548 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp);
582 if (err) 549 if (err)
583 goto err_free; 550 goto err_free;
551 /* 3 additional fan inputs for the MAX6651 */
552 if (data->nr_fans == 4) {
553 err = sysfs_create_group(&client->dev.kobj, &max6651_attr_grp);
554 if (err)
555 goto err_remove;
556 }
584 557
585 data->hwmon_dev = hwmon_device_register(&client->dev); 558 data->hwmon_dev = hwmon_device_register(&client->dev);
586 if (!IS_ERR(data->hwmon_dev)) 559 if (!IS_ERR(data->hwmon_dev))
@@ -588,6 +561,9 @@ static int max6650_probe(struct i2c_client *client,
588 561
589 err = PTR_ERR(data->hwmon_dev); 562 err = PTR_ERR(data->hwmon_dev);
590 dev_err(&client->dev, "error registering hwmon device.\n"); 563 dev_err(&client->dev, "error registering hwmon device.\n");
564 if (data->nr_fans == 4)
565 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
566err_remove:
591 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp); 567 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
592err_free: 568err_free:
593 kfree(data); 569 kfree(data);
@@ -598,8 +574,10 @@ static int max6650_remove(struct i2c_client *client)
598{ 574{
599 struct max6650_data *data = i2c_get_clientdata(client); 575 struct max6650_data *data = i2c_get_clientdata(client);
600 576
601 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
602 hwmon_device_unregister(data->hwmon_dev); 577 hwmon_device_unregister(data->hwmon_dev);
578 if (data->nr_fans == 4)
579 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
580 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
603 kfree(data); 581 kfree(data);
604 return 0; 582 return 0;
605} 583}
@@ -712,7 +690,7 @@ static struct max6650_data *max6650_update_device(struct device *dev)
712 MAX6650_REG_SPEED); 690 MAX6650_REG_SPEED);
713 data->config = i2c_smbus_read_byte_data(client, 691 data->config = i2c_smbus_read_byte_data(client,
714 MAX6650_REG_CONFIG); 692 MAX6650_REG_CONFIG);
715 for (i = 0; i < 4; i++) { 693 for (i = 0; i < data->nr_fans; i++) {
716 data->tach[i] = i2c_smbus_read_byte_data(client, 694 data->tach[i] = i2c_smbus_read_byte_data(client,
717 tach_reg[i]); 695 tach_reg[i]);
718 } 696 }
diff --git a/drivers/hwmon/sch5627.c b/drivers/hwmon/sch5627.c
index 9a51dcca9b0d..020c87273ea1 100644
--- a/drivers/hwmon/sch5627.c
+++ b/drivers/hwmon/sch5627.c
@@ -52,6 +52,9 @@
52#define SCH5627_COMPANY_ID 0x5c 52#define SCH5627_COMPANY_ID 0x5c
53#define SCH5627_PRIMARY_ID 0xa0 53#define SCH5627_PRIMARY_ID 0xa0
54 54
55#define SCH5627_CMD_READ 0x02
56#define SCH5627_CMD_WRITE 0x03
57
55#define SCH5627_REG_BUILD_CODE 0x39 58#define SCH5627_REG_BUILD_CODE 0x39
56#define SCH5627_REG_BUILD_ID 0x3a 59#define SCH5627_REG_BUILD_ID 0x3a
57#define SCH5627_REG_HWMON_ID 0x3c 60#define SCH5627_REG_HWMON_ID 0x3c
@@ -94,11 +97,13 @@ static const char * const SCH5627_IN_LABELS[SCH5627_NO_IN] = {
94struct sch5627_data { 97struct sch5627_data {
95 unsigned short addr; 98 unsigned short addr;
96 struct device *hwmon_dev; 99 struct device *hwmon_dev;
100 u8 control;
97 u8 temp_max[SCH5627_NO_TEMPS]; 101 u8 temp_max[SCH5627_NO_TEMPS];
98 u8 temp_crit[SCH5627_NO_TEMPS]; 102 u8 temp_crit[SCH5627_NO_TEMPS];
99 u16 fan_min[SCH5627_NO_FANS]; 103 u16 fan_min[SCH5627_NO_FANS];
100 104
101 struct mutex update_lock; 105 struct mutex update_lock;
106 unsigned long last_battery; /* In jiffies */
102 char valid; /* !=0 if following fields are valid */ 107 char valid; /* !=0 if following fields are valid */
103 unsigned long last_updated; /* In jiffies */ 108 unsigned long last_updated; /* In jiffies */
104 u16 temp[SCH5627_NO_TEMPS]; 109 u16 temp[SCH5627_NO_TEMPS];
@@ -140,7 +145,7 @@ static inline void superio_exit(int base)
140 release_region(base, 2); 145 release_region(base, 2);
141} 146}
142 147
143static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg) 148static int sch5627_send_cmd(struct sch5627_data *data, u8 cmd, u16 reg, u8 v)
144{ 149{
145 u8 val; 150 u8 val;
146 int i; 151 int i;
@@ -163,10 +168,14 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
163 outb(0x80, data->addr + 3); 168 outb(0x80, data->addr + 3);
164 169
165 /* Write Request Packet Header */ 170 /* Write Request Packet Header */
166 outb(0x02, data->addr + 4); /* Access Type: VREG read */ 171 outb(cmd, data->addr + 4); /* VREG Access Type read:0x02 write:0x03 */
167 outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */ 172 outb(0x01, data->addr + 5); /* # of Entries: 1 Byte (8-bit) */
168 outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */ 173 outb(0x04, data->addr + 2); /* Mailbox AP to first data entry loc. */
169 174
175 /* Write Value field */
176 if (cmd == SCH5627_CMD_WRITE)
177 outb(v, data->addr + 4);
178
170 /* Write Address field */ 179 /* Write Address field */
171 outb(reg & 0xff, data->addr + 6); 180 outb(reg & 0xff, data->addr + 6);
172 outb(reg >> 8, data->addr + 7); 181 outb(reg >> 8, data->addr + 7);
@@ -224,8 +233,22 @@ static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
224 * But if we do that things don't work, so let's not. 233 * But if we do that things don't work, so let's not.
225 */ 234 */
226 235
227 /* Read Data from Mailbox */ 236 /* Read Value field */
228 return inb(data->addr + 4); 237 if (cmd == SCH5627_CMD_READ)
238 return inb(data->addr + 4);
239
240 return 0;
241}
242
243static int sch5627_read_virtual_reg(struct sch5627_data *data, u16 reg)
244{
245 return sch5627_send_cmd(data, SCH5627_CMD_READ, reg, 0);
246}
247
248static int sch5627_write_virtual_reg(struct sch5627_data *data,
249 u16 reg, u8 val)
250{
251 return sch5627_send_cmd(data, SCH5627_CMD_WRITE, reg, val);
229} 252}
230 253
231static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg) 254static int sch5627_read_virtual_reg16(struct sch5627_data *data, u16 reg)
@@ -272,6 +295,13 @@ static struct sch5627_data *sch5627_update_device(struct device *dev)
272 295
273 mutex_lock(&data->update_lock); 296 mutex_lock(&data->update_lock);
274 297
298 /* Trigger a Vbat voltage measurement every 5 minutes */
299 if (time_after(jiffies, data->last_battery + 300 * HZ)) {
300 sch5627_write_virtual_reg(data, SCH5627_REG_CTRL,
301 data->control | 0x10);
302 data->last_battery = jiffies;
303 }
304
275 /* Cache the values for 1 second */ 305 /* Cache the values for 1 second */
276 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 306 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
277 for (i = 0; i < SCH5627_NO_TEMPS; i++) { 307 for (i = 0; i < SCH5627_NO_TEMPS; i++) {
@@ -696,11 +726,17 @@ static int __devinit sch5627_probe(struct platform_device *pdev)
696 err = val; 726 err = val;
697 goto error; 727 goto error;
698 } 728 }
699 if (!(val & 0x01)) { 729 data->control = val;
730 if (!(data->control & 0x01)) {
700 pr_err("hardware monitoring not enabled\n"); 731 pr_err("hardware monitoring not enabled\n");
701 err = -ENODEV; 732 err = -ENODEV;
702 goto error; 733 goto error;
703 } 734 }
735 /* Trigger a Vbat voltage measurement, so that we get a valid reading
736 the first time we read Vbat */
737 sch5627_write_virtual_reg(data, SCH5627_REG_CTRL,
738 data->control | 0x10);
739 data->last_battery = jiffies;
704 740
705 /* 741 /*
706 * Read limits, we do this only once as reading a register on 742 * Read limits, we do this only once as reading a register on
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 1f36c635d933..27a62711e0a6 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -258,7 +258,7 @@ static int __devinit env_probe(struct platform_device *op)
258 goto out_sysfs_remove_group; 258 goto out_sysfs_remove_group;
259 } 259 }
260 260
261 dev_set_drvdata(&op->dev, p); 261 platform_set_drvdata(op, p);
262 err = 0; 262 err = 0;
263 263
264out: 264out:
@@ -277,7 +277,7 @@ out_free:
277 277
278static int __devexit env_remove(struct platform_device *op) 278static int __devexit env_remove(struct platform_device *op)
279{ 279{
280 struct env *p = dev_get_drvdata(&op->dev); 280 struct env *p = platform_get_drvdata(op);
281 281
282 if (p) { 282 if (p) {
283 sysfs_remove_group(&op->dev.kobj, &env_group); 283 sysfs_remove_group(&op->dev.kobj, &env_group);