aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTim Shimmin <tes@chook.melbourne.sgi.com>2006-09-29 02:45:43 -0400
committerTim Shimmin <tes@chook.melbourne.sgi.com>2006-09-29 02:45:43 -0400
commit1b06e7926694178e146ff708b2c15a6da64c9765 (patch)
tree30602fa4a854d6956f478212937726ca75ea13ce /drivers
parent65e8697a12e356cd7a6ecafa1149f5c5c6a71593 (diff)
parentc972398b7871d9fb58c6a317786065a7cc6ca4be (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/Kconfig51
-rw-r--r--drivers/hwmon/Makefile2
-rw-r--r--drivers/hwmon/abituguru.c30
-rw-r--r--drivers/hwmon/adm1021.c31
-rw-r--r--drivers/hwmon/adm1025.c94
-rw-r--r--drivers/hwmon/adm1026.c286
-rw-r--r--drivers/hwmon/adm1031.c114
-rw-r--r--drivers/hwmon/adm9240.c105
-rw-r--r--drivers/hwmon/asb100.c122
-rw-r--r--drivers/hwmon/atxp1.c28
-rw-r--r--drivers/hwmon/ds1621.c28
-rw-r--r--drivers/hwmon/f71805f.c336
-rw-r--r--drivers/hwmon/fscher.c106
-rw-r--r--drivers/hwmon/fscpos.c75
-rw-r--r--drivers/hwmon/gl518sm.c74
-rw-r--r--drivers/hwmon/gl520sm.c128
-rw-r--r--drivers/hwmon/hdaps.c6
-rw-r--r--drivers/hwmon/it87.c469
-rw-r--r--drivers/hwmon/k8temp.c294
-rw-r--r--drivers/hwmon/lm63.c96
-rw-r--r--drivers/hwmon/lm75.c24
-rw-r--r--drivers/hwmon/lm77.c33
-rw-r--r--drivers/hwmon/lm78.c88
-rw-r--r--drivers/hwmon/lm80.c85
-rw-r--r--drivers/hwmon/lm83.c128
-rw-r--r--drivers/hwmon/lm85.c173
-rw-r--r--drivers/hwmon/lm87.c191
-rw-r--r--drivers/hwmon/lm90.c90
-rw-r--r--drivers/hwmon/lm92.c34
-rw-r--r--drivers/hwmon/max1619.c33
-rw-r--r--drivers/hwmon/pc87360.c230
-rw-r--r--drivers/hwmon/sis5595.c101
-rw-r--r--drivers/hwmon/smsc47b397.c39
-rw-r--r--drivers/hwmon/smsc47m1.c81
-rw-r--r--drivers/hwmon/smsc47m192.c150
-rw-r--r--drivers/hwmon/via686a.c83
-rw-r--r--drivers/hwmon/vt1211.c1355
-rw-r--r--drivers/hwmon/vt8231.c186
-rw-r--r--drivers/hwmon/w83627ehf.c485
-rw-r--r--drivers/hwmon/w83627hf.c232
-rw-r--r--drivers/hwmon/w83781d.c277
-rw-r--r--drivers/hwmon/w83791d.c7
-rw-r--r--drivers/hwmon/w83792d.c554
-rw-r--r--drivers/hwmon/w83l785ts.c28
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c16
-rw-r--r--drivers/mmc/at91_mci.c5
-rw-r--r--drivers/mmc/imxmmc.c2
-rw-r--r--drivers/mmc/mmc.c1
-rw-r--r--drivers/mmc/mmc_block.c66
-rw-r--r--drivers/mmc/mmci.c13
-rw-r--r--drivers/mmc/omap.c7
-rw-r--r--drivers/mmc/sdhci.c2
-rw-r--r--drivers/mmc/wbsd.c2
-rw-r--r--drivers/net/arm/at91_ether.c2
-rw-r--r--drivers/s390/block/dasd_diag.c34
-rw-r--r--drivers/s390/block/xpram.c54
-rw-r--r--drivers/s390/char/fs3270.c1
-rw-r--r--drivers/s390/char/sclp.c31
-rw-r--r--drivers/s390/char/tty3270.c1
-rw-r--r--drivers/s390/char/vmwatchdog.c52
-rw-r--r--drivers/s390/cio/device_id.c38
-rw-r--r--drivers/s390/cio/ioasm.h220
-rw-r--r--drivers/s390/cio/qdio.h192
-rw-r--r--drivers/s390/net/iucv.c39
-rw-r--r--drivers/s390/s390mach.c93
-rw-r--r--drivers/serial/at91_serial.c2
-rw-r--r--drivers/usb/core/driver.c65
-rw-r--r--drivers/usb/core/hcd.c6
-rw-r--r--drivers/usb/core/hub.c4
-rw-r--r--drivers/usb/core/usb.c46
-rw-r--r--drivers/usb/core/usb.h19
-rw-r--r--drivers/usb/gadget/at91_udc.c6
-rw-r--r--drivers/usb/gadget/dummy_hcd.c33
-rw-r--r--drivers/usb/gadget/file_storage.c35
-rw-r--r--drivers/usb/host/ohci-hcd.c18
-rw-r--r--drivers/usb/host/ohci-hub.c265
-rw-r--r--drivers/usb/host/ohci-pci.c3
-rw-r--r--drivers/usb/host/ohci.h1
-rw-r--r--drivers/usb/image/microtek.c18
-rw-r--r--drivers/usb/image/microtek.h4
-rw-r--r--drivers/usb/input/hid-core.c4
-rw-r--r--drivers/usb/misc/phidgetkit.c56
-rw-r--r--drivers/usb/net/asix.c4
-rw-r--r--drivers/usb/net/kaweth.c1
-rw-r--r--drivers/usb/net/pegasus.c18
-rw-r--r--drivers/usb/serial/cyberjack.c6
-rw-r--r--drivers/usb/serial/ftdi_sio.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.h10
-rw-r--r--drivers/usb/serial/generic.c6
-rw-r--r--drivers/usb/serial/ipaq.c1
-rw-r--r--drivers/usb/serial/ipw.c6
-rw-r--r--drivers/usb/serial/ir-usb.c6
-rw-r--r--drivers/usb/serial/keyspan_pda.c6
-rw-r--r--drivers/usb/serial/omninet.c6
-rw-r--r--drivers/usb/serial/pl2303.c1
-rw-r--r--drivers/usb/serial/pl2303.h4
-rw-r--r--drivers/usb/serial/safe_serial.c6
-rw-r--r--drivers/usb/storage/unusual_devs.h14
-rw-r--r--drivers/video/backlight/locomolcd.c30
100 files changed, 6071 insertions, 2678 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 0e31a0c496e8..9b88b25b6edb 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -53,7 +53,7 @@ config SENSORS_ADM1021
53 53
54config SENSORS_ADM1025 54config SENSORS_ADM1025
55 tristate "Analog Devices ADM1025 and compatibles" 55 tristate "Analog Devices ADM1025 and compatibles"
56 depends on HWMON && I2C && EXPERIMENTAL 56 depends on HWMON && I2C
57 select HWMON_VID 57 select HWMON_VID
58 help 58 help
59 If you say yes here you get support for Analog Devices ADM1025 59 If you say yes here you get support for Analog Devices ADM1025
@@ -94,6 +94,16 @@ config SENSORS_ADM9240
94 This driver can also be built as a module. If so, the module 94 This driver can also be built as a module. If so, the module
95 will be called adm9240. 95 will be called adm9240.
96 96
97config SENSORS_K8TEMP
98 tristate "AMD K8 processor sensor"
99 depends on HWMON && X86 && PCI && EXPERIMENTAL
100 help
101 If you say yes here you get support for the temperature
102 sensor(s) inside your AMD K8 CPU.
103
104 This driver can also be built as a module. If so, the module
105 will be called k8temp.
106
97config SENSORS_ASB100 107config SENSORS_ASB100
98 tristate "Asus ASB100 Bach" 108 tristate "Asus ASB100 Bach"
99 depends on HWMON && I2C && EXPERIMENTAL 109 depends on HWMON && I2C && EXPERIMENTAL
@@ -121,7 +131,7 @@ config SENSORS_ATXP1
121 131
122config SENSORS_DS1621 132config SENSORS_DS1621
123 tristate "Dallas Semiconductor DS1621 and DS1625" 133 tristate "Dallas Semiconductor DS1621 and DS1625"
124 depends on HWMON && I2C && EXPERIMENTAL 134 depends on HWMON && I2C
125 help 135 help
126 If you say yes here you get support for Dallas Semiconductor 136 If you say yes here you get support for Dallas Semiconductor
127 DS1621 and DS1625 sensor chips. 137 DS1621 and DS1625 sensor chips.
@@ -141,7 +151,7 @@ config SENSORS_F71805F
141 151
142config SENSORS_FSCHER 152config SENSORS_FSCHER
143 tristate "FSC Hermes" 153 tristate "FSC Hermes"
144 depends on HWMON && I2C && EXPERIMENTAL 154 depends on HWMON && I2C
145 help 155 help
146 If you say yes here you get support for Fujitsu Siemens 156 If you say yes here you get support for Fujitsu Siemens
147 Computers Hermes sensor chips. 157 Computers Hermes sensor chips.
@@ -151,7 +161,7 @@ config SENSORS_FSCHER
151 161
152config SENSORS_FSCPOS 162config SENSORS_FSCPOS
153 tristate "FSC Poseidon" 163 tristate "FSC Poseidon"
154 depends on HWMON && I2C && EXPERIMENTAL 164 depends on HWMON && I2C
155 help 165 help
156 If you say yes here you get support for Fujitsu Siemens 166 If you say yes here you get support for Fujitsu Siemens
157 Computers Poseidon sensor chips. 167 Computers Poseidon sensor chips.
@@ -171,7 +181,7 @@ config SENSORS_GL518SM
171 181
172config SENSORS_GL520SM 182config SENSORS_GL520SM
173 tristate "Genesys Logic GL520SM" 183 tristate "Genesys Logic GL520SM"
174 depends on HWMON && I2C && EXPERIMENTAL 184 depends on HWMON && I2C
175 select HWMON_VID 185 select HWMON_VID
176 help 186 help
177 If you say yes here you get support for Genesys Logic GL520SM 187 If you say yes here you get support for Genesys Logic GL520SM
@@ -186,15 +196,15 @@ config SENSORS_IT87
186 select I2C_ISA 196 select I2C_ISA
187 select HWMON_VID 197 select HWMON_VID
188 help 198 help
189 If you say yes here you get support for ITE IT87xx sensor chips 199 If you say yes here you get support for ITE IT8705F, IT8712F,
190 and clones: SiS960. 200 IT8716F and IT8718F sensor chips, and the SiS960 clone.
191 201
192 This driver can also be built as a module. If so, the module 202 This driver can also be built as a module. If so, the module
193 will be called it87. 203 will be called it87.
194 204
195config SENSORS_LM63 205config SENSORS_LM63
196 tristate "National Semiconductor LM63" 206 tristate "National Semiconductor LM63"
197 depends on HWMON && I2C && EXPERIMENTAL 207 depends on HWMON && I2C
198 help 208 help
199 If you say yes here you get support for the National Semiconductor 209 If you say yes here you get support for the National Semiconductor
200 LM63 remote diode digital temperature sensor with integrated fan 210 LM63 remote diode digital temperature sensor with integrated fan
@@ -231,7 +241,7 @@ config SENSORS_LM75
231 241
232config SENSORS_LM77 242config SENSORS_LM77
233 tristate "National Semiconductor LM77" 243 tristate "National Semiconductor LM77"
234 depends on HWMON && I2C && EXPERIMENTAL 244 depends on HWMON && I2C
235 help 245 help
236 If you say yes here you get support for National Semiconductor LM77 246 If you say yes here you get support for National Semiconductor LM77
237 sensor chips. 247 sensor chips.
@@ -241,7 +251,7 @@ config SENSORS_LM77
241 251
242config SENSORS_LM78 252config SENSORS_LM78
243 tristate "National Semiconductor LM78 and compatibles" 253 tristate "National Semiconductor LM78 and compatibles"
244 depends on HWMON && I2C && EXPERIMENTAL 254 depends on HWMON && I2C
245 select I2C_ISA 255 select I2C_ISA
246 select HWMON_VID 256 select HWMON_VID
247 help 257 help
@@ -284,7 +294,7 @@ config SENSORS_LM85
284 294
285config SENSORS_LM87 295config SENSORS_LM87
286 tristate "National Semiconductor LM87" 296 tristate "National Semiconductor LM87"
287 depends on HWMON && I2C && EXPERIMENTAL 297 depends on HWMON && I2C
288 select HWMON_VID 298 select HWMON_VID
289 help 299 help
290 If you say yes here you get support for National Semiconductor LM87 300 If you say yes here you get support for National Semiconductor LM87
@@ -309,7 +319,7 @@ config SENSORS_LM90
309 319
310config SENSORS_LM92 320config SENSORS_LM92
311 tristate "National Semiconductor LM92 and compatibles" 321 tristate "National Semiconductor LM92 and compatibles"
312 depends on HWMON && I2C && EXPERIMENTAL 322 depends on HWMON && I2C
313 help 323 help
314 If you say yes here you get support for National Semiconductor LM92 324 If you say yes here you get support for National Semiconductor LM92
315 and Maxim MAX6635 sensor chips. 325 and Maxim MAX6635 sensor chips.
@@ -319,7 +329,7 @@ config SENSORS_LM92
319 329
320config SENSORS_MAX1619 330config SENSORS_MAX1619
321 tristate "Maxim MAX1619 sensor chip" 331 tristate "Maxim MAX1619 sensor chip"
322 depends on HWMON && I2C && EXPERIMENTAL 332 depends on HWMON && I2C
323 help 333 help
324 If you say yes here you get support for MAX1619 sensor chip. 334 If you say yes here you get support for MAX1619 sensor chip.
325 335
@@ -354,7 +364,7 @@ config SENSORS_SIS5595
354 364
355config SENSORS_SMSC47M1 365config SENSORS_SMSC47M1
356 tristate "SMSC LPC47M10x and compatibles" 366 tristate "SMSC LPC47M10x and compatibles"
357 depends on HWMON && I2C && EXPERIMENTAL 367 depends on HWMON && I2C
358 select I2C_ISA 368 select I2C_ISA
359 help 369 help
360 If you say yes here you get support for the integrated fan 370 If you say yes here you get support for the integrated fan
@@ -407,8 +417,19 @@ config SENSORS_VIA686A
407 This driver can also be built as a module. If so, the module 417 This driver can also be built as a module. If so, the module
408 will be called via686a. 418 will be called via686a.
409 419
420config SENSORS_VT1211
421 tristate "VIA VT1211"
422 depends on HWMON && EXPERIMENTAL
423 select HWMON_VID
424 help
425 If you say yes here then you get support for hardware monitoring
426 features of the VIA VT1211 Super-I/O chip.
427
428 This driver can also be built as a module. If so, the module
429 will be called vt1211.
430
410config SENSORS_VT8231 431config SENSORS_VT8231
411 tristate "VT8231" 432 tristate "VIA VT8231"
412 depends on HWMON && I2C && PCI && EXPERIMENTAL 433 depends on HWMON && I2C && PCI && EXPERIMENTAL
413 select HWMON_VID 434 select HWMON_VID
414 select I2C_ISA 435 select I2C_ISA
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 31415843a91a..af01cc64f7d2 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
27obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o 27obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
28obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o 28obj-$(CONFIG_SENSORS_HDAPS) += hdaps.o
29obj-$(CONFIG_SENSORS_IT87) += it87.o 29obj-$(CONFIG_SENSORS_IT87) += it87.o
30obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
30obj-$(CONFIG_SENSORS_LM63) += lm63.o 31obj-$(CONFIG_SENSORS_LM63) += lm63.o
31obj-$(CONFIG_SENSORS_LM70) += lm70.o 32obj-$(CONFIG_SENSORS_LM70) += lm70.o
32obj-$(CONFIG_SENSORS_LM75) += lm75.o 33obj-$(CONFIG_SENSORS_LM75) += lm75.o
@@ -45,6 +46,7 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
45obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o 46obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
46obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o 47obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
47obj-$(CONFIG_SENSORS_VIA686A) += via686a.o 48obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
49obj-$(CONFIG_SENSORS_VT1211) += vt1211.o
48obj-$(CONFIG_SENSORS_VT8231) += vt8231.o 50obj-$(CONFIG_SENSORS_VT8231) += vt8231.o
49obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o 51obj-$(CONFIG_SENSORS_W83627EHF) += w83627ehf.o
50obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o 52obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index 35ad1b032726..e5cb0fdab9b1 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -1354,13 +1354,39 @@ LEAVE_UPDATE:
1354 return NULL; 1354 return NULL;
1355} 1355}
1356 1356
1357#ifdef CONFIG_PM
1358static int abituguru_suspend(struct platform_device *pdev, pm_message_t state)
1359{
1360 struct abituguru_data *data = platform_get_drvdata(pdev);
1361 /* make sure all communications with the uguru are done and no new
1362 ones are started */
1363 mutex_lock(&data->update_lock);
1364 return 0;
1365}
1366
1367static int abituguru_resume(struct platform_device *pdev)
1368{
1369 struct abituguru_data *data = platform_get_drvdata(pdev);
1370 /* See if the uGuru is still ready */
1371 if (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT)
1372 data->uguru_ready = 0;
1373 mutex_unlock(&data->update_lock);
1374 return 0;
1375}
1376#else
1377#define abituguru_suspend NULL
1378#define abituguru_resume NULL
1379#endif /* CONFIG_PM */
1380
1357static struct platform_driver abituguru_driver = { 1381static struct platform_driver abituguru_driver = {
1358 .driver = { 1382 .driver = {
1359 .owner = THIS_MODULE, 1383 .owner = THIS_MODULE,
1360 .name = ABIT_UGURU_NAME, 1384 .name = ABIT_UGURU_NAME,
1361 }, 1385 },
1362 .probe = abituguru_probe, 1386 .probe = abituguru_probe,
1363 .remove = __devexit_p(abituguru_remove), 1387 .remove = __devexit_p(abituguru_remove),
1388 .suspend = abituguru_suspend,
1389 .resume = abituguru_resume,
1364}; 1390};
1365 1391
1366static int __init abituguru_detect(void) 1392static int __init abituguru_detect(void)
diff --git a/drivers/hwmon/adm1021.c b/drivers/hwmon/adm1021.c
index 2b6e74dd4a82..c466329b2ef4 100644
--- a/drivers/hwmon/adm1021.c
+++ b/drivers/hwmon/adm1021.c
@@ -190,6 +190,21 @@ static int adm1021_attach_adapter(struct i2c_adapter *adapter)
190 return i2c_probe(adapter, &addr_data, adm1021_detect); 190 return i2c_probe(adapter, &addr_data, adm1021_detect);
191} 191}
192 192
193static struct attribute *adm1021_attributes[] = {
194 &dev_attr_temp1_max.attr,
195 &dev_attr_temp1_min.attr,
196 &dev_attr_temp1_input.attr,
197 &dev_attr_temp2_max.attr,
198 &dev_attr_temp2_min.attr,
199 &dev_attr_temp2_input.attr,
200 &dev_attr_alarms.attr,
201 NULL
202};
203
204static const struct attribute_group adm1021_group = {
205 .attrs = adm1021_attributes,
206};
207
193static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind) 208static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
194{ 209{
195 int i; 210 int i;
@@ -287,22 +302,19 @@ static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
287 adm1021_init_client(new_client); 302 adm1021_init_client(new_client);
288 303
289 /* Register sysfs hooks */ 304 /* Register sysfs hooks */
305 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1021_group)))
306 goto error2;
307
290 data->class_dev = hwmon_device_register(&new_client->dev); 308 data->class_dev = hwmon_device_register(&new_client->dev);
291 if (IS_ERR(data->class_dev)) { 309 if (IS_ERR(data->class_dev)) {
292 err = PTR_ERR(data->class_dev); 310 err = PTR_ERR(data->class_dev);
293 goto error2; 311 goto error3;
294 } 312 }
295 313
296 device_create_file(&new_client->dev, &dev_attr_temp1_max);
297 device_create_file(&new_client->dev, &dev_attr_temp1_min);
298 device_create_file(&new_client->dev, &dev_attr_temp1_input);
299 device_create_file(&new_client->dev, &dev_attr_temp2_max);
300 device_create_file(&new_client->dev, &dev_attr_temp2_min);
301 device_create_file(&new_client->dev, &dev_attr_temp2_input);
302 device_create_file(&new_client->dev, &dev_attr_alarms);
303
304 return 0; 314 return 0;
305 315
316error3:
317 sysfs_remove_group(&new_client->dev.kobj, &adm1021_group);
306error2: 318error2:
307 i2c_detach_client(new_client); 319 i2c_detach_client(new_client);
308error1: 320error1:
@@ -326,6 +338,7 @@ static int adm1021_detach_client(struct i2c_client *client)
326 int err; 338 int err;
327 339
328 hwmon_device_unregister(data->class_dev); 340 hwmon_device_unregister(data->class_dev);
341 sysfs_remove_group(&client->dev.kobj, &adm1021_group);
329 342
330 if ((err = i2c_detach_client(client))) 343 if ((err = i2c_detach_client(client)))
331 return err; 344 return err;
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index a4c859c9fbf8..8c562885b54b 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -315,6 +315,49 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
315 return i2c_probe(adapter, &addr_data, adm1025_detect); 315 return i2c_probe(adapter, &addr_data, adm1025_detect);
316} 316}
317 317
318static struct attribute *adm1025_attributes[] = {
319 &dev_attr_in0_input.attr,
320 &dev_attr_in1_input.attr,
321 &dev_attr_in2_input.attr,
322 &dev_attr_in3_input.attr,
323 &dev_attr_in5_input.attr,
324 &dev_attr_in0_min.attr,
325 &dev_attr_in1_min.attr,
326 &dev_attr_in2_min.attr,
327 &dev_attr_in3_min.attr,
328 &dev_attr_in5_min.attr,
329 &dev_attr_in0_max.attr,
330 &dev_attr_in1_max.attr,
331 &dev_attr_in2_max.attr,
332 &dev_attr_in3_max.attr,
333 &dev_attr_in5_max.attr,
334 &dev_attr_temp1_input.attr,
335 &dev_attr_temp2_input.attr,
336 &dev_attr_temp1_min.attr,
337 &dev_attr_temp2_min.attr,
338 &dev_attr_temp1_max.attr,
339 &dev_attr_temp2_max.attr,
340 &dev_attr_alarms.attr,
341 &dev_attr_cpu0_vid.attr,
342 &dev_attr_vrm.attr,
343 NULL
344};
345
346static const struct attribute_group adm1025_group = {
347 .attrs = adm1025_attributes,
348};
349
350static struct attribute *adm1025_attributes_opt[] = {
351 &dev_attr_in4_input.attr,
352 &dev_attr_in4_min.attr,
353 &dev_attr_in4_max.attr,
354 NULL
355};
356
357static const struct attribute_group adm1025_group_opt = {
358 .attrs = adm1025_attributes_opt,
359};
360
318/* 361/*
319 * The following function does more than just detection. If detection 362 * The following function does more than just detection. If detection
320 * succeeds, it also registers the new chip. 363 * succeeds, it also registers the new chip.
@@ -415,46 +458,31 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
415 adm1025_init_client(new_client); 458 adm1025_init_client(new_client);
416 459
417 /* Register sysfs hooks */ 460 /* Register sysfs hooks */
418 data->class_dev = hwmon_device_register(&new_client->dev); 461 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group)))
419 if (IS_ERR(data->class_dev)) {
420 err = PTR_ERR(data->class_dev);
421 goto exit_detach; 462 goto exit_detach;
422 }
423
424 device_create_file(&new_client->dev, &dev_attr_in0_input);
425 device_create_file(&new_client->dev, &dev_attr_in1_input);
426 device_create_file(&new_client->dev, &dev_attr_in2_input);
427 device_create_file(&new_client->dev, &dev_attr_in3_input);
428 device_create_file(&new_client->dev, &dev_attr_in5_input);
429 device_create_file(&new_client->dev, &dev_attr_in0_min);
430 device_create_file(&new_client->dev, &dev_attr_in1_min);
431 device_create_file(&new_client->dev, &dev_attr_in2_min);
432 device_create_file(&new_client->dev, &dev_attr_in3_min);
433 device_create_file(&new_client->dev, &dev_attr_in5_min);
434 device_create_file(&new_client->dev, &dev_attr_in0_max);
435 device_create_file(&new_client->dev, &dev_attr_in1_max);
436 device_create_file(&new_client->dev, &dev_attr_in2_max);
437 device_create_file(&new_client->dev, &dev_attr_in3_max);
438 device_create_file(&new_client->dev, &dev_attr_in5_max);
439 device_create_file(&new_client->dev, &dev_attr_temp1_input);
440 device_create_file(&new_client->dev, &dev_attr_temp2_input);
441 device_create_file(&new_client->dev, &dev_attr_temp1_min);
442 device_create_file(&new_client->dev, &dev_attr_temp2_min);
443 device_create_file(&new_client->dev, &dev_attr_temp1_max);
444 device_create_file(&new_client->dev, &dev_attr_temp2_max);
445 device_create_file(&new_client->dev, &dev_attr_alarms);
446 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
447 device_create_file(&new_client->dev, &dev_attr_vrm);
448 463
449 /* Pin 11 is either in4 (+12V) or VID4 */ 464 /* Pin 11 is either in4 (+12V) or VID4 */
450 if (!(config & 0x20)) { 465 if (!(config & 0x20)) {
451 device_create_file(&new_client->dev, &dev_attr_in4_input); 466 if ((err = device_create_file(&new_client->dev,
452 device_create_file(&new_client->dev, &dev_attr_in4_min); 467 &dev_attr_in4_input))
453 device_create_file(&new_client->dev, &dev_attr_in4_max); 468 || (err = device_create_file(&new_client->dev,
469 &dev_attr_in4_min))
470 || (err = device_create_file(&new_client->dev,
471 &dev_attr_in4_max)))
472 goto exit_remove;
473 }
474
475 data->class_dev = hwmon_device_register(&new_client->dev);
476 if (IS_ERR(data->class_dev)) {
477 err = PTR_ERR(data->class_dev);
478 goto exit_remove;
454 } 479 }
455 480
456 return 0; 481 return 0;
457 482
483exit_remove:
484 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group);
485 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt);
458exit_detach: 486exit_detach:
459 i2c_detach_client(new_client); 487 i2c_detach_client(new_client);
460exit_free: 488exit_free:
@@ -511,6 +539,8 @@ static int adm1025_detach_client(struct i2c_client *client)
511 int err; 539 int err;
512 540
513 hwmon_device_unregister(data->class_dev); 541 hwmon_device_unregister(data->class_dev);
542 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
543 sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt);
514 544
515 if ((err = i2c_detach_client(client))) 545 if ((err = i2c_detach_client(client)))
516 return err; 546 return err;
diff --git a/drivers/hwmon/adm1026.c b/drivers/hwmon/adm1026.c
index 6d4f8b8d358e..b4618b2705f7 100644
--- a/drivers/hwmon/adm1026.c
+++ b/drivers/hwmon/adm1026.c
@@ -323,15 +323,6 @@ static int adm1026_attach_adapter(struct i2c_adapter *adapter)
323 return i2c_probe(adapter, &addr_data, adm1026_detect); 323 return i2c_probe(adapter, &addr_data, adm1026_detect);
324} 324}
325 325
326static int adm1026_detach_client(struct i2c_client *client)
327{
328 struct adm1026_data *data = i2c_get_clientdata(client);
329 hwmon_device_unregister(data->class_dev);
330 i2c_detach_client(client);
331 kfree(data);
332 return 0;
333}
334
335static int adm1026_read_value(struct i2c_client *client, u8 reg) 326static int adm1026_read_value(struct i2c_client *client, u8 reg)
336{ 327{
337 int res; 328 int res;
@@ -1450,6 +1441,135 @@ static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1450static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1441static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1451static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL); 1442static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1452 1443
1444static struct attribute *adm1026_attributes[] = {
1445 &sensor_dev_attr_in0_input.dev_attr.attr,
1446 &sensor_dev_attr_in0_max.dev_attr.attr,
1447 &sensor_dev_attr_in0_min.dev_attr.attr,
1448 &sensor_dev_attr_in1_input.dev_attr.attr,
1449 &sensor_dev_attr_in1_max.dev_attr.attr,
1450 &sensor_dev_attr_in1_min.dev_attr.attr,
1451 &sensor_dev_attr_in2_input.dev_attr.attr,
1452 &sensor_dev_attr_in2_max.dev_attr.attr,
1453 &sensor_dev_attr_in2_min.dev_attr.attr,
1454 &sensor_dev_attr_in3_input.dev_attr.attr,
1455 &sensor_dev_attr_in3_max.dev_attr.attr,
1456 &sensor_dev_attr_in3_min.dev_attr.attr,
1457 &sensor_dev_attr_in4_input.dev_attr.attr,
1458 &sensor_dev_attr_in4_max.dev_attr.attr,
1459 &sensor_dev_attr_in4_min.dev_attr.attr,
1460 &sensor_dev_attr_in5_input.dev_attr.attr,
1461 &sensor_dev_attr_in5_max.dev_attr.attr,
1462 &sensor_dev_attr_in5_min.dev_attr.attr,
1463 &sensor_dev_attr_in6_input.dev_attr.attr,
1464 &sensor_dev_attr_in6_max.dev_attr.attr,
1465 &sensor_dev_attr_in6_min.dev_attr.attr,
1466 &sensor_dev_attr_in7_input.dev_attr.attr,
1467 &sensor_dev_attr_in7_max.dev_attr.attr,
1468 &sensor_dev_attr_in7_min.dev_attr.attr,
1469 &sensor_dev_attr_in8_input.dev_attr.attr,
1470 &sensor_dev_attr_in8_max.dev_attr.attr,
1471 &sensor_dev_attr_in8_min.dev_attr.attr,
1472 &sensor_dev_attr_in9_input.dev_attr.attr,
1473 &sensor_dev_attr_in9_max.dev_attr.attr,
1474 &sensor_dev_attr_in9_min.dev_attr.attr,
1475 &sensor_dev_attr_in10_input.dev_attr.attr,
1476 &sensor_dev_attr_in10_max.dev_attr.attr,
1477 &sensor_dev_attr_in10_min.dev_attr.attr,
1478 &sensor_dev_attr_in11_input.dev_attr.attr,
1479 &sensor_dev_attr_in11_max.dev_attr.attr,
1480 &sensor_dev_attr_in11_min.dev_attr.attr,
1481 &sensor_dev_attr_in12_input.dev_attr.attr,
1482 &sensor_dev_attr_in12_max.dev_attr.attr,
1483 &sensor_dev_attr_in12_min.dev_attr.attr,
1484 &sensor_dev_attr_in13_input.dev_attr.attr,
1485 &sensor_dev_attr_in13_max.dev_attr.attr,
1486 &sensor_dev_attr_in13_min.dev_attr.attr,
1487 &sensor_dev_attr_in14_input.dev_attr.attr,
1488 &sensor_dev_attr_in14_max.dev_attr.attr,
1489 &sensor_dev_attr_in14_min.dev_attr.attr,
1490 &sensor_dev_attr_in15_input.dev_attr.attr,
1491 &sensor_dev_attr_in15_max.dev_attr.attr,
1492 &sensor_dev_attr_in15_min.dev_attr.attr,
1493 &sensor_dev_attr_in16_input.dev_attr.attr,
1494 &sensor_dev_attr_in16_max.dev_attr.attr,
1495 &sensor_dev_attr_in16_min.dev_attr.attr,
1496 &sensor_dev_attr_fan1_input.dev_attr.attr,
1497 &sensor_dev_attr_fan1_div.dev_attr.attr,
1498 &sensor_dev_attr_fan1_min.dev_attr.attr,
1499 &sensor_dev_attr_fan2_input.dev_attr.attr,
1500 &sensor_dev_attr_fan2_div.dev_attr.attr,
1501 &sensor_dev_attr_fan2_min.dev_attr.attr,
1502 &sensor_dev_attr_fan3_input.dev_attr.attr,
1503 &sensor_dev_attr_fan3_div.dev_attr.attr,
1504 &sensor_dev_attr_fan3_min.dev_attr.attr,
1505 &sensor_dev_attr_fan4_input.dev_attr.attr,
1506 &sensor_dev_attr_fan4_div.dev_attr.attr,
1507 &sensor_dev_attr_fan4_min.dev_attr.attr,
1508 &sensor_dev_attr_fan5_input.dev_attr.attr,
1509 &sensor_dev_attr_fan5_div.dev_attr.attr,
1510 &sensor_dev_attr_fan5_min.dev_attr.attr,
1511 &sensor_dev_attr_fan6_input.dev_attr.attr,
1512 &sensor_dev_attr_fan6_div.dev_attr.attr,
1513 &sensor_dev_attr_fan6_min.dev_attr.attr,
1514 &sensor_dev_attr_fan7_input.dev_attr.attr,
1515 &sensor_dev_attr_fan7_div.dev_attr.attr,
1516 &sensor_dev_attr_fan7_min.dev_attr.attr,
1517 &sensor_dev_attr_fan8_input.dev_attr.attr,
1518 &sensor_dev_attr_fan8_div.dev_attr.attr,
1519 &sensor_dev_attr_fan8_min.dev_attr.attr,
1520 &sensor_dev_attr_temp1_input.dev_attr.attr,
1521 &sensor_dev_attr_temp1_max.dev_attr.attr,
1522 &sensor_dev_attr_temp1_min.dev_attr.attr,
1523 &sensor_dev_attr_temp2_input.dev_attr.attr,
1524 &sensor_dev_attr_temp2_max.dev_attr.attr,
1525 &sensor_dev_attr_temp2_min.dev_attr.attr,
1526 &sensor_dev_attr_temp3_input.dev_attr.attr,
1527 &sensor_dev_attr_temp3_max.dev_attr.attr,
1528 &sensor_dev_attr_temp3_min.dev_attr.attr,
1529 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1530 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1531 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1532 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
1533 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
1534 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
1535 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
1536 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
1537 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
1538 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
1539 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
1540 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
1541 &sensor_dev_attr_temp1_crit.dev_attr.attr,
1542 &sensor_dev_attr_temp2_crit.dev_attr.attr,
1543 &sensor_dev_attr_temp3_crit.dev_attr.attr,
1544 &dev_attr_temp1_crit_enable.attr,
1545 &dev_attr_temp2_crit_enable.attr,
1546 &dev_attr_temp3_crit_enable.attr,
1547 &dev_attr_cpu0_vid.attr,
1548 &dev_attr_vrm.attr,
1549 &dev_attr_alarms.attr,
1550 &dev_attr_alarm_mask.attr,
1551 &dev_attr_gpio.attr,
1552 &dev_attr_gpio_mask.attr,
1553 &dev_attr_pwm1.attr,
1554 &dev_attr_pwm2.attr,
1555 &dev_attr_pwm3.attr,
1556 &dev_attr_pwm1_enable.attr,
1557 &dev_attr_pwm2_enable.attr,
1558 &dev_attr_pwm3_enable.attr,
1559 &dev_attr_temp1_auto_point1_pwm.attr,
1560 &dev_attr_temp2_auto_point1_pwm.attr,
1561 &dev_attr_temp3_auto_point1_pwm.attr,
1562 &dev_attr_temp1_auto_point2_pwm.attr,
1563 &dev_attr_temp2_auto_point2_pwm.attr,
1564 &dev_attr_temp3_auto_point2_pwm.attr,
1565 &dev_attr_analog_out.attr,
1566 NULL
1567};
1568
1569static const struct attribute_group adm1026_group = {
1570 .attrs = adm1026_attributes,
1571};
1572
1453static int adm1026_detect(struct i2c_adapter *adapter, int address, 1573static int adm1026_detect(struct i2c_adapter *adapter, int address,
1454 int kind) 1574 int kind)
1455{ 1575{
@@ -1554,145 +1674,20 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
1554 adm1026_init_client(new_client); 1674 adm1026_init_client(new_client);
1555 1675
1556 /* Register sysfs hooks */ 1676 /* Register sysfs hooks */
1677 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1026_group)))
1678 goto exitdetach;
1679
1557 data->class_dev = hwmon_device_register(&new_client->dev); 1680 data->class_dev = hwmon_device_register(&new_client->dev);
1558 if (IS_ERR(data->class_dev)) { 1681 if (IS_ERR(data->class_dev)) {
1559 err = PTR_ERR(data->class_dev); 1682 err = PTR_ERR(data->class_dev);
1560 goto exitdetach; 1683 goto exitremove;
1561 } 1684 }
1562 1685
1563 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
1564 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
1565 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
1566 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
1567 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
1568 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
1569 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
1570 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
1571 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
1572 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
1573 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
1574 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
1575 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
1576 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
1577 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
1578 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
1579 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
1580 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
1581 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
1582 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
1583 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
1584 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
1585 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
1586 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
1587 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
1588 device_create_file(&new_client->dev, &sensor_dev_attr_in8_max.dev_attr);
1589 device_create_file(&new_client->dev, &sensor_dev_attr_in8_min.dev_attr);
1590 device_create_file(&new_client->dev, &sensor_dev_attr_in9_input.dev_attr);
1591 device_create_file(&new_client->dev, &sensor_dev_attr_in9_max.dev_attr);
1592 device_create_file(&new_client->dev, &sensor_dev_attr_in9_min.dev_attr);
1593 device_create_file(&new_client->dev, &sensor_dev_attr_in10_input.dev_attr);
1594 device_create_file(&new_client->dev, &sensor_dev_attr_in10_max.dev_attr);
1595 device_create_file(&new_client->dev, &sensor_dev_attr_in10_min.dev_attr);
1596 device_create_file(&new_client->dev, &sensor_dev_attr_in11_input.dev_attr);
1597 device_create_file(&new_client->dev, &sensor_dev_attr_in11_max.dev_attr);
1598 device_create_file(&new_client->dev, &sensor_dev_attr_in11_min.dev_attr);
1599 device_create_file(&new_client->dev, &sensor_dev_attr_in12_input.dev_attr);
1600 device_create_file(&new_client->dev, &sensor_dev_attr_in12_max.dev_attr);
1601 device_create_file(&new_client->dev, &sensor_dev_attr_in12_min.dev_attr);
1602 device_create_file(&new_client->dev, &sensor_dev_attr_in13_input.dev_attr);
1603 device_create_file(&new_client->dev, &sensor_dev_attr_in13_max.dev_attr);
1604 device_create_file(&new_client->dev, &sensor_dev_attr_in13_min.dev_attr);
1605 device_create_file(&new_client->dev, &sensor_dev_attr_in14_input.dev_attr);
1606 device_create_file(&new_client->dev, &sensor_dev_attr_in14_max.dev_attr);
1607 device_create_file(&new_client->dev, &sensor_dev_attr_in14_min.dev_attr);
1608 device_create_file(&new_client->dev, &sensor_dev_attr_in15_input.dev_attr);
1609 device_create_file(&new_client->dev, &sensor_dev_attr_in15_max.dev_attr);
1610 device_create_file(&new_client->dev, &sensor_dev_attr_in15_min.dev_attr);
1611 device_create_file(&new_client->dev, &sensor_dev_attr_in16_input.dev_attr);
1612 device_create_file(&new_client->dev, &sensor_dev_attr_in16_max.dev_attr);
1613 device_create_file(&new_client->dev, &sensor_dev_attr_in16_min.dev_attr);
1614 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
1615 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
1616 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
1617 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
1618 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
1619 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
1620 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
1621 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
1622 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
1623 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_input.dev_attr);
1624 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_div.dev_attr);
1625 device_create_file(&new_client->dev, &sensor_dev_attr_fan4_min.dev_attr);
1626 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_input.dev_attr);
1627 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_div.dev_attr);
1628 device_create_file(&new_client->dev, &sensor_dev_attr_fan5_min.dev_attr);
1629 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_input.dev_attr);
1630 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_div.dev_attr);
1631 device_create_file(&new_client->dev, &sensor_dev_attr_fan6_min.dev_attr);
1632 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_input.dev_attr);
1633 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_div.dev_attr);
1634 device_create_file(&new_client->dev, &sensor_dev_attr_fan7_min.dev_attr);
1635 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_input.dev_attr);
1636 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_div.dev_attr);
1637 device_create_file(&new_client->dev, &sensor_dev_attr_fan8_min.dev_attr);
1638 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
1639 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
1640 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
1641 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
1642 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
1643 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
1644 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
1645 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
1646 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
1647 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_offset.dev_attr);
1648 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_offset.dev_attr);
1649 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_offset.dev_attr);
1650 device_create_file(&new_client->dev,
1651 &sensor_dev_attr_temp1_auto_point1_temp.dev_attr);
1652 device_create_file(&new_client->dev,
1653 &sensor_dev_attr_temp2_auto_point1_temp.dev_attr);
1654 device_create_file(&new_client->dev,
1655 &sensor_dev_attr_temp3_auto_point1_temp.dev_attr);
1656 device_create_file(&new_client->dev,
1657 &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr);
1658 device_create_file(&new_client->dev,
1659 &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr);
1660 device_create_file(&new_client->dev,
1661 &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr);
1662 device_create_file(&new_client->dev,
1663 &sensor_dev_attr_temp1_auto_point2_temp.dev_attr);
1664 device_create_file(&new_client->dev,
1665 &sensor_dev_attr_temp2_auto_point2_temp.dev_attr);
1666 device_create_file(&new_client->dev,
1667 &sensor_dev_attr_temp3_auto_point2_temp.dev_attr);
1668 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_crit.dev_attr);
1669 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_crit.dev_attr);
1670 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_crit.dev_attr);
1671 device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
1672 device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
1673 device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
1674 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
1675 device_create_file(&new_client->dev, &dev_attr_vrm);
1676 device_create_file(&new_client->dev, &dev_attr_alarms);
1677 device_create_file(&new_client->dev, &dev_attr_alarm_mask);
1678 device_create_file(&new_client->dev, &dev_attr_gpio);
1679 device_create_file(&new_client->dev, &dev_attr_gpio_mask);
1680 device_create_file(&new_client->dev, &dev_attr_pwm1);
1681 device_create_file(&new_client->dev, &dev_attr_pwm2);
1682 device_create_file(&new_client->dev, &dev_attr_pwm3);
1683 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1684 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1685 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1686 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
1687 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
1688 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
1689 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
1690 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
1691 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
1692 device_create_file(&new_client->dev, &dev_attr_analog_out);
1693 return 0; 1686 return 0;
1694 1687
1695 /* Error out and cleanup code */ 1688 /* Error out and cleanup code */
1689exitremove:
1690 sysfs_remove_group(&new_client->dev.kobj, &adm1026_group);
1696exitdetach: 1691exitdetach:
1697 i2c_detach_client(new_client); 1692 i2c_detach_client(new_client);
1698exitfree: 1693exitfree:
@@ -1700,6 +1695,17 @@ exitfree:
1700exit: 1695exit:
1701 return err; 1696 return err;
1702} 1697}
1698
1699static int adm1026_detach_client(struct i2c_client *client)
1700{
1701 struct adm1026_data *data = i2c_get_clientdata(client);
1702 hwmon_device_unregister(data->class_dev);
1703 sysfs_remove_group(&client->dev.kobj, &adm1026_group);
1704 i2c_detach_client(client);
1705 kfree(data);
1706 return 0;
1707}
1708
1703static int __init sm_adm1026_init(void) 1709static int __init sm_adm1026_init(void)
1704{ 1710{
1705 return i2c_add_driver(&adm1026_driver); 1711 return i2c_add_driver(&adm1026_driver);
diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c
index 3bf2da621aed..122683fc91d0 100644
--- a/drivers/hwmon/adm1031.c
+++ b/drivers/hwmon/adm1031.c
@@ -730,6 +730,61 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
730 return i2c_probe(adapter, &addr_data, adm1031_detect); 730 return i2c_probe(adapter, &addr_data, adm1031_detect);
731} 731}
732 732
733static struct attribute *adm1031_attributes[] = {
734 &dev_attr_fan1_input.attr,
735 &dev_attr_fan1_div.attr,
736 &dev_attr_fan1_min.attr,
737 &dev_attr_pwm1.attr,
738 &dev_attr_auto_fan1_channel.attr,
739 &dev_attr_temp1_input.attr,
740 &dev_attr_temp1_min.attr,
741 &dev_attr_temp1_max.attr,
742 &dev_attr_temp1_crit.attr,
743 &dev_attr_temp2_input.attr,
744 &dev_attr_temp2_min.attr,
745 &dev_attr_temp2_max.attr,
746 &dev_attr_temp2_crit.attr,
747
748 &dev_attr_auto_temp1_off.attr,
749 &dev_attr_auto_temp1_min.attr,
750 &dev_attr_auto_temp1_max.attr,
751
752 &dev_attr_auto_temp2_off.attr,
753 &dev_attr_auto_temp2_min.attr,
754 &dev_attr_auto_temp2_max.attr,
755
756 &dev_attr_auto_fan1_min_pwm.attr,
757
758 &dev_attr_alarms.attr,
759
760 NULL
761};
762
763static const struct attribute_group adm1031_group = {
764 .attrs = adm1031_attributes,
765};
766
767static struct attribute *adm1031_attributes_opt[] = {
768 &dev_attr_fan2_input.attr,
769 &dev_attr_fan2_div.attr,
770 &dev_attr_fan2_min.attr,
771 &dev_attr_pwm2.attr,
772 &dev_attr_auto_fan2_channel.attr,
773 &dev_attr_temp3_input.attr,
774 &dev_attr_temp3_min.attr,
775 &dev_attr_temp3_max.attr,
776 &dev_attr_temp3_crit.attr,
777 &dev_attr_auto_temp3_off.attr,
778 &dev_attr_auto_temp3_min.attr,
779 &dev_attr_auto_temp3_max.attr,
780 &dev_attr_auto_fan2_min_pwm.attr,
781 NULL
782};
783
784static const struct attribute_group adm1031_group_opt = {
785 .attrs = adm1031_attributes_opt,
786};
787
733/* This function is called by i2c_probe */ 788/* This function is called by i2c_probe */
734static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 789static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
735{ 790{
@@ -789,57 +844,26 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
789 adm1031_init_client(new_client); 844 adm1031_init_client(new_client);
790 845
791 /* Register sysfs hooks */ 846 /* Register sysfs hooks */
792 data->class_dev = hwmon_device_register(&new_client->dev); 847 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group)))
793 if (IS_ERR(data->class_dev)) {
794 err = PTR_ERR(data->class_dev);
795 goto exit_detach; 848 goto exit_detach;
796 }
797
798 device_create_file(&new_client->dev, &dev_attr_fan1_input);
799 device_create_file(&new_client->dev, &dev_attr_fan1_div);
800 device_create_file(&new_client->dev, &dev_attr_fan1_min);
801 device_create_file(&new_client->dev, &dev_attr_pwm1);
802 device_create_file(&new_client->dev, &dev_attr_auto_fan1_channel);
803 device_create_file(&new_client->dev, &dev_attr_temp1_input);
804 device_create_file(&new_client->dev, &dev_attr_temp1_min);
805 device_create_file(&new_client->dev, &dev_attr_temp1_max);
806 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
807 device_create_file(&new_client->dev, &dev_attr_temp2_input);
808 device_create_file(&new_client->dev, &dev_attr_temp2_min);
809 device_create_file(&new_client->dev, &dev_attr_temp2_max);
810 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
811
812 device_create_file(&new_client->dev, &dev_attr_auto_temp1_off);
813 device_create_file(&new_client->dev, &dev_attr_auto_temp1_min);
814 device_create_file(&new_client->dev, &dev_attr_auto_temp1_max);
815
816 device_create_file(&new_client->dev, &dev_attr_auto_temp2_off);
817 device_create_file(&new_client->dev, &dev_attr_auto_temp2_min);
818 device_create_file(&new_client->dev, &dev_attr_auto_temp2_max);
819
820 device_create_file(&new_client->dev, &dev_attr_auto_fan1_min_pwm);
821
822 device_create_file(&new_client->dev, &dev_attr_alarms);
823 849
824 if (kind == adm1031) { 850 if (kind == adm1031) {
825 device_create_file(&new_client->dev, &dev_attr_fan2_input); 851 if ((err = sysfs_create_group(&new_client->dev.kobj,
826 device_create_file(&new_client->dev, &dev_attr_fan2_div); 852 &adm1031_group_opt)))
827 device_create_file(&new_client->dev, &dev_attr_fan2_min); 853 goto exit_remove;
828 device_create_file(&new_client->dev, &dev_attr_pwm2); 854 }
829 device_create_file(&new_client->dev, 855
830 &dev_attr_auto_fan2_channel); 856 data->class_dev = hwmon_device_register(&new_client->dev);
831 device_create_file(&new_client->dev, &dev_attr_temp3_input); 857 if (IS_ERR(data->class_dev)) {
832 device_create_file(&new_client->dev, &dev_attr_temp3_min); 858 err = PTR_ERR(data->class_dev);
833 device_create_file(&new_client->dev, &dev_attr_temp3_max); 859 goto exit_remove;
834 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
835 device_create_file(&new_client->dev, &dev_attr_auto_temp3_off);
836 device_create_file(&new_client->dev, &dev_attr_auto_temp3_min);
837 device_create_file(&new_client->dev, &dev_attr_auto_temp3_max);
838 device_create_file(&new_client->dev, &dev_attr_auto_fan2_min_pwm);
839 } 860 }
840 861
841 return 0; 862 return 0;
842 863
864exit_remove:
865 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group);
866 sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt);
843exit_detach: 867exit_detach:
844 i2c_detach_client(new_client); 868 i2c_detach_client(new_client);
845exit_free: 869exit_free:
@@ -854,6 +878,8 @@ static int adm1031_detach_client(struct i2c_client *client)
854 int ret; 878 int ret;
855 879
856 hwmon_device_unregister(data->class_dev); 880 hwmon_device_unregister(data->class_dev);
881 sysfs_remove_group(&client->dev.kobj, &adm1031_group);
882 sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
857 if ((ret = i2c_detach_client(client)) != 0) { 883 if ((ret = i2c_detach_client(client)) != 0) {
858 return ret; 884 return ret;
859 } 885 }
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 43f6991b588c..377961c4a41e 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -465,6 +465,45 @@ static ssize_t chassis_clear(struct device *dev,
465} 465}
466static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear); 466static DEVICE_ATTR(chassis_clear, S_IWUSR, NULL, chassis_clear);
467 467
468static struct attribute *adm9240_attributes[] = {
469 &sensor_dev_attr_in0_input.dev_attr.attr,
470 &sensor_dev_attr_in0_min.dev_attr.attr,
471 &sensor_dev_attr_in0_max.dev_attr.attr,
472 &sensor_dev_attr_in1_input.dev_attr.attr,
473 &sensor_dev_attr_in1_min.dev_attr.attr,
474 &sensor_dev_attr_in1_max.dev_attr.attr,
475 &sensor_dev_attr_in2_input.dev_attr.attr,
476 &sensor_dev_attr_in2_min.dev_attr.attr,
477 &sensor_dev_attr_in2_max.dev_attr.attr,
478 &sensor_dev_attr_in3_input.dev_attr.attr,
479 &sensor_dev_attr_in3_min.dev_attr.attr,
480 &sensor_dev_attr_in3_max.dev_attr.attr,
481 &sensor_dev_attr_in4_input.dev_attr.attr,
482 &sensor_dev_attr_in4_min.dev_attr.attr,
483 &sensor_dev_attr_in4_max.dev_attr.attr,
484 &sensor_dev_attr_in5_input.dev_attr.attr,
485 &sensor_dev_attr_in5_min.dev_attr.attr,
486 &sensor_dev_attr_in5_max.dev_attr.attr,
487 &dev_attr_temp1_input.attr,
488 &sensor_dev_attr_temp1_max.dev_attr.attr,
489 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
490 &sensor_dev_attr_fan1_input.dev_attr.attr,
491 &sensor_dev_attr_fan1_div.dev_attr.attr,
492 &sensor_dev_attr_fan1_min.dev_attr.attr,
493 &sensor_dev_attr_fan2_input.dev_attr.attr,
494 &sensor_dev_attr_fan2_div.dev_attr.attr,
495 &sensor_dev_attr_fan2_min.dev_attr.attr,
496 &dev_attr_alarms.attr,
497 &dev_attr_aout_output.attr,
498 &dev_attr_chassis_clear.attr,
499 &dev_attr_cpu0_vid.attr,
500 NULL
501};
502
503static const struct attribute_group adm9240_group = {
504 .attrs = adm9240_attributes,
505};
506
468 507
469/*** sensor chip detect and driver install ***/ 508/*** sensor chip detect and driver install ***/
470 509
@@ -548,72 +587,19 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind)
548 adm9240_init_client(new_client); 587 adm9240_init_client(new_client);
549 588
550 /* populate sysfs filesystem */ 589 /* populate sysfs filesystem */
590 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm9240_group)))
591 goto exit_detach;
592
551 data->class_dev = hwmon_device_register(&new_client->dev); 593 data->class_dev = hwmon_device_register(&new_client->dev);
552 if (IS_ERR(data->class_dev)) { 594 if (IS_ERR(data->class_dev)) {
553 err = PTR_ERR(data->class_dev); 595 err = PTR_ERR(data->class_dev);
554 goto exit_detach; 596 goto exit_remove;
555 } 597 }
556 598
557 device_create_file(&new_client->dev,
558 &sensor_dev_attr_in0_input.dev_attr);
559 device_create_file(&new_client->dev,
560 &sensor_dev_attr_in0_min.dev_attr);
561 device_create_file(&new_client->dev,
562 &sensor_dev_attr_in0_max.dev_attr);
563 device_create_file(&new_client->dev,
564 &sensor_dev_attr_in1_input.dev_attr);
565 device_create_file(&new_client->dev,
566 &sensor_dev_attr_in1_min.dev_attr);
567 device_create_file(&new_client->dev,
568 &sensor_dev_attr_in1_max.dev_attr);
569 device_create_file(&new_client->dev,
570 &sensor_dev_attr_in2_input.dev_attr);
571 device_create_file(&new_client->dev,
572 &sensor_dev_attr_in2_min.dev_attr);
573 device_create_file(&new_client->dev,
574 &sensor_dev_attr_in2_max.dev_attr);
575 device_create_file(&new_client->dev,
576 &sensor_dev_attr_in3_input.dev_attr);
577 device_create_file(&new_client->dev,
578 &sensor_dev_attr_in3_min.dev_attr);
579 device_create_file(&new_client->dev,
580 &sensor_dev_attr_in3_max.dev_attr);
581 device_create_file(&new_client->dev,
582 &sensor_dev_attr_in4_input.dev_attr);
583 device_create_file(&new_client->dev,
584 &sensor_dev_attr_in4_min.dev_attr);
585 device_create_file(&new_client->dev,
586 &sensor_dev_attr_in4_max.dev_attr);
587 device_create_file(&new_client->dev,
588 &sensor_dev_attr_in5_input.dev_attr);
589 device_create_file(&new_client->dev,
590 &sensor_dev_attr_in5_min.dev_attr);
591 device_create_file(&new_client->dev,
592 &sensor_dev_attr_in5_max.dev_attr);
593 device_create_file(&new_client->dev, &dev_attr_temp1_input);
594 device_create_file(&new_client->dev,
595 &sensor_dev_attr_temp1_max.dev_attr);
596 device_create_file(&new_client->dev,
597 &sensor_dev_attr_temp1_max_hyst.dev_attr);
598 device_create_file(&new_client->dev,
599 &sensor_dev_attr_fan1_input.dev_attr);
600 device_create_file(&new_client->dev,
601 &sensor_dev_attr_fan1_div.dev_attr);
602 device_create_file(&new_client->dev,
603 &sensor_dev_attr_fan1_min.dev_attr);
604 device_create_file(&new_client->dev,
605 &sensor_dev_attr_fan2_input.dev_attr);
606 device_create_file(&new_client->dev,
607 &sensor_dev_attr_fan2_div.dev_attr);
608 device_create_file(&new_client->dev,
609 &sensor_dev_attr_fan2_min.dev_attr);
610 device_create_file(&new_client->dev, &dev_attr_alarms);
611 device_create_file(&new_client->dev, &dev_attr_aout_output);
612 device_create_file(&new_client->dev, &dev_attr_chassis_clear);
613 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
614
615 return 0; 599 return 0;
616 600
601exit_remove:
602 sysfs_remove_group(&new_client->dev.kobj, &adm9240_group);
617exit_detach: 603exit_detach:
618 i2c_detach_client(new_client); 604 i2c_detach_client(new_client);
619exit_free: 605exit_free:
@@ -635,6 +621,7 @@ static int adm9240_detach_client(struct i2c_client *client)
635 int err; 621 int err;
636 622
637 hwmon_device_unregister(data->class_dev); 623 hwmon_device_unregister(data->class_dev);
624 sysfs_remove_group(&client->dev.kobj, &adm9240_group);
638 625
639 if ((err = i2c_detach_client(client))) 626 if ((err = i2c_detach_client(client)))
640 return err; 627 return err;
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index facc1ccb8338..57b1c7b7ac3f 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -298,12 +298,6 @@ sysfs_in(4);
298sysfs_in(5); 298sysfs_in(5);
299sysfs_in(6); 299sysfs_in(6);
300 300
301#define device_create_file_in(client, offset) do { \
302 device_create_file(&client->dev, &dev_attr_in##offset##_input); \
303 device_create_file(&client->dev, &dev_attr_in##offset##_min); \
304 device_create_file(&client->dev, &dev_attr_in##offset##_max); \
305} while (0)
306
307/* 3 Fans */ 301/* 3 Fans */
308static ssize_t show_fan(struct device *dev, char *buf, int nr) 302static ssize_t show_fan(struct device *dev, char *buf, int nr)
309{ 303{
@@ -421,12 +415,6 @@ sysfs_fan(1);
421sysfs_fan(2); 415sysfs_fan(2);
422sysfs_fan(3); 416sysfs_fan(3);
423 417
424#define device_create_file_fan(client, offset) do { \
425 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
426 device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
427 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
428} while (0)
429
430/* 4 Temp. Sensors */ 418/* 4 Temp. Sensors */
431static int sprintf_temp_from_reg(u16 reg, char *buf, int nr) 419static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
432{ 420{
@@ -515,12 +503,6 @@ sysfs_temp(3);
515sysfs_temp(4); 503sysfs_temp(4);
516 504
517/* VID */ 505/* VID */
518#define device_create_file_temp(client, num) do { \
519 device_create_file(&client->dev, &dev_attr_temp##num##_input); \
520 device_create_file(&client->dev, &dev_attr_temp##num##_max); \
521 device_create_file(&client->dev, &dev_attr_temp##num##_max_hyst); \
522} while (0)
523
524static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 506static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
525{ 507{
526 struct asb100_data *data = asb100_update_device(dev); 508 struct asb100_data *data = asb100_update_device(dev);
@@ -528,8 +510,6 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
528} 510}
529 511
530static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 512static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
531#define device_create_file_vid(client) \
532device_create_file(&client->dev, &dev_attr_cpu0_vid)
533 513
534/* VRM */ 514/* VRM */
535static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 515static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
@@ -549,8 +529,6 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const
549 529
550/* Alarms */ 530/* Alarms */
551static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm); 531static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
552#define device_create_file_vrm(client) \
553device_create_file(&client->dev, &dev_attr_vrm);
554 532
555static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 533static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
556{ 534{
@@ -559,8 +537,6 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
559} 537}
560 538
561static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 539static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
562#define device_create_file_alarms(client) \
563device_create_file(&client->dev, &dev_attr_alarms)
564 540
565/* 1 PWM */ 541/* 1 PWM */
566static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf) 542static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
@@ -607,10 +583,65 @@ static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr
607static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1); 583static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
608static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, 584static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
609 show_pwm_enable1, set_pwm_enable1); 585 show_pwm_enable1, set_pwm_enable1);
610#define device_create_file_pwm1(client) do { \ 586
611 device_create_file(&new_client->dev, &dev_attr_pwm1); \ 587static struct attribute *asb100_attributes[] = {
612 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \ 588 &dev_attr_in0_input.attr,
613} while (0) 589 &dev_attr_in0_min.attr,
590 &dev_attr_in0_max.attr,
591 &dev_attr_in1_input.attr,
592 &dev_attr_in1_min.attr,
593 &dev_attr_in1_max.attr,
594 &dev_attr_in2_input.attr,
595 &dev_attr_in2_min.attr,
596 &dev_attr_in2_max.attr,
597 &dev_attr_in3_input.attr,
598 &dev_attr_in3_min.attr,
599 &dev_attr_in3_max.attr,
600 &dev_attr_in4_input.attr,
601 &dev_attr_in4_min.attr,
602 &dev_attr_in4_max.attr,
603 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr,
606 &dev_attr_in6_input.attr,
607 &dev_attr_in6_min.attr,
608 &dev_attr_in6_max.attr,
609
610 &dev_attr_fan1_input.attr,
611 &dev_attr_fan1_min.attr,
612 &dev_attr_fan1_div.attr,
613 &dev_attr_fan2_input.attr,
614 &dev_attr_fan2_min.attr,
615 &dev_attr_fan2_div.attr,
616 &dev_attr_fan3_input.attr,
617 &dev_attr_fan3_min.attr,
618 &dev_attr_fan3_div.attr,
619
620 &dev_attr_temp1_input.attr,
621 &dev_attr_temp1_max.attr,
622 &dev_attr_temp1_max_hyst.attr,
623 &dev_attr_temp2_input.attr,
624 &dev_attr_temp2_max.attr,
625 &dev_attr_temp2_max_hyst.attr,
626 &dev_attr_temp3_input.attr,
627 &dev_attr_temp3_max.attr,
628 &dev_attr_temp3_max_hyst.attr,
629 &dev_attr_temp4_input.attr,
630 &dev_attr_temp4_max.attr,
631 &dev_attr_temp4_max_hyst.attr,
632
633 &dev_attr_cpu0_vid.attr,
634 &dev_attr_vrm.attr,
635 &dev_attr_alarms.attr,
636 &dev_attr_pwm1.attr,
637 &dev_attr_pwm1_enable.attr,
638
639 NULL
640};
641
642static const struct attribute_group asb100_group = {
643 .attrs = asb100_attributes,
644};
614 645
615/* This function is called when: 646/* This function is called when:
616 asb100_driver is inserted (when this module is loaded), for each 647 asb100_driver is inserted (when this module is loaded), for each
@@ -810,38 +841,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
810 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2)); 841 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
811 842
812 /* Register sysfs hooks */ 843 /* Register sysfs hooks */
844 if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
845 goto ERROR3;
846
813 data->class_dev = hwmon_device_register(&new_client->dev); 847 data->class_dev = hwmon_device_register(&new_client->dev);
814 if (IS_ERR(data->class_dev)) { 848 if (IS_ERR(data->class_dev)) {
815 err = PTR_ERR(data->class_dev); 849 err = PTR_ERR(data->class_dev);
816 goto ERROR3; 850 goto ERROR4;
817 } 851 }
818 852
819 device_create_file_in(new_client, 0);
820 device_create_file_in(new_client, 1);
821 device_create_file_in(new_client, 2);
822 device_create_file_in(new_client, 3);
823 device_create_file_in(new_client, 4);
824 device_create_file_in(new_client, 5);
825 device_create_file_in(new_client, 6);
826
827 device_create_file_fan(new_client, 1);
828 device_create_file_fan(new_client, 2);
829 device_create_file_fan(new_client, 3);
830
831 device_create_file_temp(new_client, 1);
832 device_create_file_temp(new_client, 2);
833 device_create_file_temp(new_client, 3);
834 device_create_file_temp(new_client, 4);
835
836 device_create_file_vid(new_client);
837 device_create_file_vrm(new_client);
838
839 device_create_file_alarms(new_client);
840
841 device_create_file_pwm1(new_client);
842
843 return 0; 853 return 0;
844 854
855ERROR4:
856 sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
845ERROR3: 857ERROR3:
846 i2c_detach_client(data->lm75[1]); 858 i2c_detach_client(data->lm75[1]);
847 i2c_detach_client(data->lm75[0]); 859 i2c_detach_client(data->lm75[0]);
@@ -861,8 +873,10 @@ static int asb100_detach_client(struct i2c_client *client)
861 int err; 873 int err;
862 874
863 /* main client */ 875 /* main client */
864 if (data) 876 if (data) {
865 hwmon_device_unregister(data->class_dev); 877 hwmon_device_unregister(data->class_dev);
878 sysfs_remove_group(&client->dev.kobj, &asb100_group);
879 }
866 880
867 if ((err = i2c_detach_client(client))) 881 if ((err = i2c_detach_client(client)))
868 return err; 882 return err;
diff --git a/drivers/hwmon/atxp1.c b/drivers/hwmon/atxp1.c
index 728a1e8b9190..0ccdd0750c44 100644
--- a/drivers/hwmon/atxp1.c
+++ b/drivers/hwmon/atxp1.c
@@ -27,6 +27,7 @@
27#include <linux/hwmon-vid.h> 27#include <linux/hwmon-vid.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/sysfs.h>
30 31
31MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
32MODULE_DESCRIPTION("System voltages control via Attansic ATXP1"); 33MODULE_DESCRIPTION("System voltages control via Attansic ATXP1");
@@ -116,8 +117,7 @@ static ssize_t atxp1_storevcore(struct device *dev, struct device_attribute *att
116{ 117{
117 struct atxp1_data *data; 118 struct atxp1_data *data;
118 struct i2c_client *client; 119 struct i2c_client *client;
119 char vid; 120 int vid, cvid;
120 char cvid;
121 unsigned int vcore; 121 unsigned int vcore;
122 122
123 client = to_i2c_client(dev); 123 client = to_i2c_client(dev);
@@ -251,6 +251,17 @@ static ssize_t atxp1_storegpio2(struct device *dev, struct device_attribute *att
251*/ 251*/
252static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2); 252static DEVICE_ATTR(gpio2, S_IRUGO | S_IWUSR, atxp1_showgpio2, atxp1_storegpio2);
253 253
254static struct attribute *atxp1_attributes[] = {
255 &dev_attr_gpio1.attr,
256 &dev_attr_gpio2.attr,
257 &dev_attr_cpu0_vid.attr,
258 NULL
259};
260
261static const struct attribute_group atxp1_group = {
262 .attrs = atxp1_attributes,
263};
264
254 265
255static int atxp1_attach_adapter(struct i2c_adapter *adapter) 266static int atxp1_attach_adapter(struct i2c_adapter *adapter)
256{ 267{
@@ -320,21 +331,23 @@ static int atxp1_detect(struct i2c_adapter *adapter, int address, int kind)
320 goto exit_free; 331 goto exit_free;
321 } 332 }
322 333
334 /* Register sysfs hooks */
335 if ((err = sysfs_create_group(&new_client->dev.kobj, &atxp1_group)))
336 goto exit_detach;
337
323 data->class_dev = hwmon_device_register(&new_client->dev); 338 data->class_dev = hwmon_device_register(&new_client->dev);
324 if (IS_ERR(data->class_dev)) { 339 if (IS_ERR(data->class_dev)) {
325 err = PTR_ERR(data->class_dev); 340 err = PTR_ERR(data->class_dev);
326 goto exit_detach; 341 goto exit_remove_files;
327 } 342 }
328 343
329 device_create_file(&new_client->dev, &dev_attr_gpio1);
330 device_create_file(&new_client->dev, &dev_attr_gpio2);
331 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
332
333 dev_info(&new_client->dev, "Using VRM: %d.%d\n", 344 dev_info(&new_client->dev, "Using VRM: %d.%d\n",
334 data->vrm / 10, data->vrm % 10); 345 data->vrm / 10, data->vrm % 10);
335 346
336 return 0; 347 return 0;
337 348
349exit_remove_files:
350 sysfs_remove_group(&new_client->dev.kobj, &atxp1_group);
338exit_detach: 351exit_detach:
339 i2c_detach_client(new_client); 352 i2c_detach_client(new_client);
340exit_free: 353exit_free:
@@ -349,6 +362,7 @@ static int atxp1_detach_client(struct i2c_client * client)
349 int err; 362 int err;
350 363
351 hwmon_device_unregister(data->class_dev); 364 hwmon_device_unregister(data->class_dev);
365 sysfs_remove_group(&client->dev.kobj, &atxp1_group);
352 366
353 err = i2c_detach_client(client); 367 err = i2c_detach_client(client);
354 368
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index 478eb4bb8570..c849c0c6ee9c 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -29,6 +29,7 @@
29#include <linux/hwmon.h> 29#include <linux/hwmon.h>
30#include <linux/err.h> 30#include <linux/err.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/sysfs.h>
32#include "lm75.h" 33#include "lm75.h"
33 34
34/* Addresses to scan */ 35/* Addresses to scan */
@@ -178,6 +179,18 @@ static DEVICE_ATTR(temp1_input, S_IRUGO , show_temp, NULL);
178static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min); 179static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min);
179static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); 180static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
180 181
182static struct attribute *ds1621_attributes[] = {
183 &dev_attr_temp1_input.attr,
184 &dev_attr_temp1_min.attr,
185 &dev_attr_temp1_max.attr,
186 &dev_attr_alarms.attr,
187 NULL
188};
189
190static const struct attribute_group ds1621_group = {
191 .attrs = ds1621_attributes,
192};
193
181 194
182static int ds1621_attach_adapter(struct i2c_adapter *adapter) 195static int ds1621_attach_adapter(struct i2c_adapter *adapter)
183{ 196{
@@ -253,21 +266,19 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
253 ds1621_init_client(new_client); 266 ds1621_init_client(new_client);
254 267
255 /* Register sysfs hooks */ 268 /* Register sysfs hooks */
269 if ((err = sysfs_create_group(&new_client->dev.kobj, &ds1621_group)))
270 goto exit_detach;
271
256 data->class_dev = hwmon_device_register(&new_client->dev); 272 data->class_dev = hwmon_device_register(&new_client->dev);
257 if (IS_ERR(data->class_dev)) { 273 if (IS_ERR(data->class_dev)) {
258 err = PTR_ERR(data->class_dev); 274 err = PTR_ERR(data->class_dev);
259 goto exit_detach; 275 goto exit_remove_files;
260 } 276 }
261 277
262 device_create_file(&new_client->dev, &dev_attr_alarms);
263 device_create_file(&new_client->dev, &dev_attr_temp1_input);
264 device_create_file(&new_client->dev, &dev_attr_temp1_min);
265 device_create_file(&new_client->dev, &dev_attr_temp1_max);
266
267 return 0; 278 return 0;
268 279
269/* OK, this is not exactly good programming practice, usually. But it is 280 exit_remove_files:
270 very code-efficient in this case. */ 281 sysfs_remove_group(&new_client->dev.kobj, &ds1621_group);
271 exit_detach: 282 exit_detach:
272 i2c_detach_client(new_client); 283 i2c_detach_client(new_client);
273 exit_free: 284 exit_free:
@@ -282,6 +293,7 @@ static int ds1621_detach_client(struct i2c_client *client)
282 int err; 293 int err;
283 294
284 hwmon_device_unregister(data->class_dev); 295 hwmon_device_unregister(data->class_dev);
296 sysfs_remove_group(&client->dev.kobj, &ds1621_group);
285 297
286 if ((err = i2c_detach_client(client))) 298 if ((err = i2c_detach_client(client)))
287 return err; 299 return err;
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index fd72440faf76..de17a72149d9 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated 2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated
3 * hardware monitoring features 3 * hardware monitoring features
4 * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates 6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates
7 * complete hardware monitoring features: voltage, fan and temperature 7 * complete hardware monitoring features: voltage, fan and temperature
@@ -31,6 +31,7 @@
31#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/sysfs.h>
34#include <asm/io.h> 35#include <asm/io.h>
35 36
36static struct platform_device *pdev; 37static struct platform_device *pdev;
@@ -147,7 +148,7 @@ struct f71805f_data {
147 u8 temp_high[3]; 148 u8 temp_high[3];
148 u8 temp_hyst[3]; 149 u8 temp_hyst[3];
149 u8 temp_mode; 150 u8 temp_mode;
150 u8 alarms[3]; 151 unsigned long alarms;
151}; 152};
152 153
153static inline long in_from_reg(u8 reg) 154static inline long in_from_reg(u8 reg)
@@ -311,10 +312,9 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
311 data->temp[nr] = f71805f_read8(data, 312 data->temp[nr] = f71805f_read8(data,
312 F71805F_REG_TEMP(nr)); 313 F71805F_REG_TEMP(nr));
313 } 314 }
314 for (nr = 0; nr < 3; nr++) { 315 data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0))
315 data->alarms[nr] = f71805f_read8(data, 316 + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8)
316 F71805F_REG_STATUS(nr)); 317 + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16);
317 }
318 318
319 data->last_updated = jiffies; 319 data->last_updated = jiffies;
320 data->valid = 1; 320 data->valid = 1;
@@ -557,8 +557,7 @@ static ssize_t show_alarms_in(struct device *dev, struct device_attribute
557{ 557{
558 struct f71805f_data *data = f71805f_update_device(dev); 558 struct f71805f_data *data = f71805f_update_device(dev);
559 559
560 return sprintf(buf, "%d\n", data->alarms[0] | 560 return sprintf(buf, "%lu\n", data->alarms & 0x1ff);
561 ((data->alarms[1] & 0x01) << 8));
562} 561}
563 562
564static ssize_t show_alarms_fan(struct device *dev, struct device_attribute 563static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
@@ -566,7 +565,7 @@ static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
566{ 565{
567 struct f71805f_data *data = f71805f_update_device(dev); 566 struct f71805f_data *data = f71805f_update_device(dev);
568 567
569 return sprintf(buf, "%d\n", data->alarms[2] & 0x07); 568 return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07);
570} 569}
571 570
572static ssize_t show_alarms_temp(struct device *dev, struct device_attribute 571static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
@@ -574,7 +573,17 @@ static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
574{ 573{
575 struct f71805f_data *data = f71805f_update_device(dev); 574 struct f71805f_data *data = f71805f_update_device(dev);
576 575
577 return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); 576 return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07);
577}
578
579static ssize_t show_alarm(struct device *dev, struct device_attribute
580 *devattr, char *buf)
581{
582 struct f71805f_data *data = f71805f_update_device(dev);
583 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
584 int bitnr = attr->index;
585
586 return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1);
578} 587}
579 588
580static ssize_t show_name(struct device *dev, struct device_attribute 589static ssize_t show_name(struct device *dev, struct device_attribute
@@ -585,88 +594,189 @@ static ssize_t show_name(struct device *dev, struct device_attribute
585 return sprintf(buf, "%s\n", data->name); 594 return sprintf(buf, "%s\n", data->name);
586} 595}
587 596
588static struct device_attribute f71805f_dev_attr[] = { 597static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL);
589 __ATTR(in0_input, S_IRUGO, show_in0, NULL), 598static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max);
590 __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max), 599static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min);
591 __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min), 600static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
592 __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL), 601static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
593 __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL), 602 show_in_max, set_in_max, 1);
594 __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL), 603static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
595 __ATTR(name, S_IRUGO, show_name, NULL), 604 show_in_min, set_in_min, 1);
605static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
606static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
607 show_in_max, set_in_max, 2);
608static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
609 show_in_min, set_in_min, 2);
610static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
611static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
612 show_in_max, set_in_max, 3);
613static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
614 show_in_min, set_in_min, 3);
615static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
616static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
617 show_in_max, set_in_max, 4);
618static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
619 show_in_min, set_in_min, 4);
620static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
621static SENSOR_DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR,
622 show_in_max, set_in_max, 5);
623static SENSOR_DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR,
624 show_in_min, set_in_min, 5);
625static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
626static SENSOR_DEVICE_ATTR(in6_max, S_IRUGO | S_IWUSR,
627 show_in_max, set_in_max, 6);
628static SENSOR_DEVICE_ATTR(in6_min, S_IRUGO | S_IWUSR,
629 show_in_min, set_in_min, 6);
630static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
631static SENSOR_DEVICE_ATTR(in7_max, S_IRUGO | S_IWUSR,
632 show_in_max, set_in_max, 7);
633static SENSOR_DEVICE_ATTR(in7_min, S_IRUGO | S_IWUSR,
634 show_in_min, set_in_min, 7);
635static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
636static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR,
637 show_in_max, set_in_max, 8);
638static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR,
639 show_in_min, set_in_min, 8);
640
641static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
642static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
643 show_fan_min, set_fan_min, 0);
644static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
645static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
646 show_fan_min, set_fan_min, 1);
647static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
648static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
649 show_fan_min, set_fan_min, 2);
650
651static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
652static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
653 show_temp_max, set_temp_max, 0);
654static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
655 show_temp_hyst, set_temp_hyst, 0);
656static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0);
657static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
658static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
659 show_temp_max, set_temp_max, 1);
660static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
661 show_temp_hyst, set_temp_hyst, 1);
662static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1);
663static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
664static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR,
665 show_temp_max, set_temp_max, 2);
666static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
667 show_temp_hyst, set_temp_hyst, 2);
668static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
669
670static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
671static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
672static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
673static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
674static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
675static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
676static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
677static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
678static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8);
679static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11);
680static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12);
681static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
682static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
683static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
684static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
685static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL);
686static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL);
687static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL);
688
689static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
690
691static struct attribute *f71805f_attributes[] = {
692 &dev_attr_in0_input.attr,
693 &dev_attr_in0_max.attr,
694 &dev_attr_in0_min.attr,
695 &sensor_dev_attr_in1_input.dev_attr.attr,
696 &sensor_dev_attr_in1_max.dev_attr.attr,
697 &sensor_dev_attr_in1_min.dev_attr.attr,
698 &sensor_dev_attr_in2_input.dev_attr.attr,
699 &sensor_dev_attr_in2_max.dev_attr.attr,
700 &sensor_dev_attr_in2_min.dev_attr.attr,
701 &sensor_dev_attr_in3_input.dev_attr.attr,
702 &sensor_dev_attr_in3_max.dev_attr.attr,
703 &sensor_dev_attr_in3_min.dev_attr.attr,
704 &sensor_dev_attr_in4_input.dev_attr.attr,
705 &sensor_dev_attr_in4_max.dev_attr.attr,
706 &sensor_dev_attr_in4_min.dev_attr.attr,
707 &sensor_dev_attr_in5_input.dev_attr.attr,
708 &sensor_dev_attr_in5_max.dev_attr.attr,
709 &sensor_dev_attr_in5_min.dev_attr.attr,
710 &sensor_dev_attr_in6_input.dev_attr.attr,
711 &sensor_dev_attr_in6_max.dev_attr.attr,
712 &sensor_dev_attr_in6_min.dev_attr.attr,
713 &sensor_dev_attr_in7_input.dev_attr.attr,
714 &sensor_dev_attr_in7_max.dev_attr.attr,
715 &sensor_dev_attr_in7_min.dev_attr.attr,
716 &sensor_dev_attr_in8_input.dev_attr.attr,
717 &sensor_dev_attr_in8_max.dev_attr.attr,
718 &sensor_dev_attr_in8_min.dev_attr.attr,
719
720 &sensor_dev_attr_temp1_input.dev_attr.attr,
721 &sensor_dev_attr_temp1_max.dev_attr.attr,
722 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
723 &sensor_dev_attr_temp1_type.dev_attr.attr,
724 &sensor_dev_attr_temp2_input.dev_attr.attr,
725 &sensor_dev_attr_temp2_max.dev_attr.attr,
726 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
727 &sensor_dev_attr_temp2_type.dev_attr.attr,
728 &sensor_dev_attr_temp3_input.dev_attr.attr,
729 &sensor_dev_attr_temp3_max.dev_attr.attr,
730 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
731 &sensor_dev_attr_temp3_type.dev_attr.attr,
732
733 &sensor_dev_attr_in0_alarm.dev_attr.attr,
734 &sensor_dev_attr_in1_alarm.dev_attr.attr,
735 &sensor_dev_attr_in2_alarm.dev_attr.attr,
736 &sensor_dev_attr_in3_alarm.dev_attr.attr,
737 &sensor_dev_attr_in4_alarm.dev_attr.attr,
738 &sensor_dev_attr_in5_alarm.dev_attr.attr,
739 &sensor_dev_attr_in6_alarm.dev_attr.attr,
740 &sensor_dev_attr_in7_alarm.dev_attr.attr,
741 &sensor_dev_attr_in8_alarm.dev_attr.attr,
742 &dev_attr_alarms_in.attr,
743 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
744 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
745 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
746 &dev_attr_alarms_temp.attr,
747 &dev_attr_alarms_fan.attr,
748
749 &dev_attr_name.attr,
750 NULL
596}; 751};
597 752
598static struct sensor_device_attribute f71805f_sensor_attr[] = { 753static const struct attribute_group f71805f_group = {
599 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), 754 .attrs = f71805f_attributes,
600 SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
601 show_in_max, set_in_max, 1),
602 SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
603 show_in_min, set_in_min, 1),
604 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
605 SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
606 show_in_max, set_in_max, 2),
607 SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
608 show_in_min, set_in_min, 2),
609 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
610 SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
611 show_in_max, set_in_max, 3),
612 SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
613 show_in_min, set_in_min, 3),
614 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
615 SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
616 show_in_max, set_in_max, 4),
617 SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
618 show_in_min, set_in_min, 4),
619 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
620 SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
621 show_in_max, set_in_max, 5),
622 SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
623 show_in_min, set_in_min, 5),
624 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
625 SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
626 show_in_max, set_in_max, 6),
627 SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
628 show_in_min, set_in_min, 6),
629 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
630 SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
631 show_in_max, set_in_max, 7),
632 SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
633 show_in_min, set_in_min, 7),
634 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
635 SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
636 show_in_max, set_in_max, 8),
637 SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
638 show_in_min, set_in_min, 8),
639
640 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
641 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
642 show_temp_max, set_temp_max, 0),
643 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
644 show_temp_hyst, set_temp_hyst, 0),
645 SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
646 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
647 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
648 show_temp_max, set_temp_max, 1),
649 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
650 show_temp_hyst, set_temp_hyst, 1),
651 SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
652 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
653 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
654 show_temp_max, set_temp_max, 2),
655 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
656 show_temp_hyst, set_temp_hyst, 2),
657 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
658}; 755};
659 756
660static struct sensor_device_attribute f71805f_fan_attr[] = { 757static struct attribute *f71805f_attributes_fan[3][4] = {
661 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), 758 {
662 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR, 759 &sensor_dev_attr_fan1_input.dev_attr.attr,
663 show_fan_min, set_fan_min, 0), 760 &sensor_dev_attr_fan1_min.dev_attr.attr,
664 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 761 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
665 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR, 762 NULL
666 show_fan_min, set_fan_min, 1), 763 }, {
667 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 764 &sensor_dev_attr_fan2_input.dev_attr.attr,
668 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR, 765 &sensor_dev_attr_fan2_min.dev_attr.attr,
669 show_fan_min, set_fan_min, 2), 766 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
767 NULL
768 }, {
769 &sensor_dev_attr_fan3_input.dev_attr.attr,
770 &sensor_dev_attr_fan3_min.dev_attr.attr,
771 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
772 NULL
773 }
774};
775
776static const struct attribute_group f71805f_group_fan[3] = {
777 { .attrs = f71805f_attributes_fan[0] },
778 { .attrs = f71805f_attributes_fan[1] },
779 { .attrs = f71805f_attributes_fan[2] },
670}; 780};
671 781
672/* 782/*
@@ -714,43 +824,35 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
714 824
715 platform_set_drvdata(pdev, data); 825 platform_set_drvdata(pdev, data);
716 826
717 data->class_dev = hwmon_device_register(&pdev->dev);
718 if (IS_ERR(data->class_dev)) {
719 err = PTR_ERR(data->class_dev);
720 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
721 goto exit_free;
722 }
723
724 /* Initialize the F71805F chip */ 827 /* Initialize the F71805F chip */
725 f71805f_init_device(data); 828 f71805f_init_device(data);
726 829
727 /* Register sysfs interface files */ 830 /* Register sysfs interface files */
728 for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) { 831 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group)))
729 err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]); 832 goto exit_free;
730 if (err) 833 for (i = 0; i < 3; i++) {
731 goto exit_class; 834 if (!(data->fan_enabled & (1 << i)))
732 }
733 for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
734 err = device_create_file(&pdev->dev,
735 &f71805f_sensor_attr[i].dev_attr);
736 if (err)
737 goto exit_class;
738 }
739 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
740 if (!(data->fan_enabled & (1 << (i / 2))))
741 continue; 835 continue;
742 err = device_create_file(&pdev->dev, 836 if ((err = sysfs_create_group(&pdev->dev.kobj,
743 &f71805f_fan_attr[i].dev_attr); 837 &f71805f_group_fan[i])))
744 if (err) 838 goto exit_remove_files;
745 goto exit_class; 839 }
840
841 data->class_dev = hwmon_device_register(&pdev->dev);
842 if (IS_ERR(data->class_dev)) {
843 err = PTR_ERR(data->class_dev);
844 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
845 goto exit_remove_files;
746 } 846 }
747 847
748 return 0; 848 return 0;
749 849
750exit_class: 850exit_remove_files:
751 dev_err(&pdev->dev, "Sysfs interface creation failed\n"); 851 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
752 hwmon_device_unregister(data->class_dev); 852 for (i = 0; i < 3; i++)
853 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
753exit_free: 854exit_free:
855 platform_set_drvdata(pdev, NULL);
754 kfree(data); 856 kfree(data);
755exit: 857exit:
756 return err; 858 return err;
@@ -759,9 +861,13 @@ exit:
759static int __devexit f71805f_remove(struct platform_device *pdev) 861static int __devexit f71805f_remove(struct platform_device *pdev)
760{ 862{
761 struct f71805f_data *data = platform_get_drvdata(pdev); 863 struct f71805f_data *data = platform_get_drvdata(pdev);
864 int i;
762 865
763 platform_set_drvdata(pdev, NULL); 866 platform_set_drvdata(pdev, NULL);
764 hwmon_device_unregister(data->class_dev); 867 hwmon_device_unregister(data->class_dev);
868 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
869 for (i = 0; i < 3; i++)
870 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
765 kfree(data); 871 kfree(data);
766 872
767 return 0; 873 return 0;
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index 6bc76b407636..19717752cfca 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38/* 39/*
39 * Addresses to scan 40 * Addresses to scan
@@ -240,47 +241,45 @@ sysfs_alarms(FSCHER_REG_EVENTS)
240sysfs_control(FSCHER_REG_CONTROL) 241sysfs_control(FSCHER_REG_CONTROL)
241sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET) 242sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
242 243
243#define device_create_file_fan(client, offset) \ 244static struct attribute *fscher_attributes[] = {
244do { \ 245 &dev_attr_revision.attr,
245 device_create_file(&client->dev, &dev_attr_fan##offset##_status); \ 246 &dev_attr_alarms.attr,
246 device_create_file(&client->dev, &dev_attr_pwm##offset); \ 247 &dev_attr_control.attr,
247 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ 248
248 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \ 249 &dev_attr_watchdog_status.attr,
249} while (0) 250 &dev_attr_watchdog_control.attr,
250 251 &dev_attr_watchdog_preset.attr,
251#define device_create_file_temp(client, offset) \ 252
252do { \ 253 &dev_attr_in0_input.attr,
253 device_create_file(&client->dev, &dev_attr_temp##offset##_status); \ 254 &dev_attr_in1_input.attr,
254 device_create_file(&client->dev, &dev_attr_temp##offset##_input); \ 255 &dev_attr_in2_input.attr,
255} while (0) 256
256 257 &dev_attr_fan1_status.attr,
257#define device_create_file_in(client, offset) \ 258 &dev_attr_fan1_div.attr,
258do { \ 259 &dev_attr_fan1_input.attr,
259 device_create_file(&client->dev, &dev_attr_in##offset##_input); \ 260 &dev_attr_pwm1.attr,
260} while (0) 261 &dev_attr_fan2_status.attr,
261 262 &dev_attr_fan2_div.attr,
262#define device_create_file_revision(client) \ 263 &dev_attr_fan2_input.attr,
263do { \ 264 &dev_attr_pwm2.attr,
264 device_create_file(&client->dev, &dev_attr_revision); \ 265 &dev_attr_fan3_status.attr,
265} while (0) 266 &dev_attr_fan3_div.attr,
266 267 &dev_attr_fan3_input.attr,
267#define device_create_file_alarms(client) \ 268 &dev_attr_pwm3.attr,
268do { \ 269
269 device_create_file(&client->dev, &dev_attr_alarms); \ 270 &dev_attr_temp1_status.attr,
270} while (0) 271 &dev_attr_temp1_input.attr,
271 272 &dev_attr_temp2_status.attr,
272#define device_create_file_control(client) \ 273 &dev_attr_temp2_input.attr,
273do { \ 274 &dev_attr_temp3_status.attr,
274 device_create_file(&client->dev, &dev_attr_control); \ 275 &dev_attr_temp3_input.attr,
275} while (0) 276 NULL
276 277};
277#define device_create_file_watchdog(client) \ 278
278do { \ 279static const struct attribute_group fscher_group = {
279 device_create_file(&client->dev, &dev_attr_watchdog_status); \ 280 .attrs = fscher_attributes,
280 device_create_file(&client->dev, &dev_attr_watchdog_control); \ 281};
281 device_create_file(&client->dev, &dev_attr_watchdog_preset); \ 282
282} while (0)
283
284/* 283/*
285 * Real code 284 * Real code
286 */ 285 */
@@ -342,31 +341,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
342 fscher_init_client(new_client); 341 fscher_init_client(new_client);
343 342
344 /* Register sysfs hooks */ 343 /* Register sysfs hooks */
344 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
345 goto exit_detach;
346
345 data->class_dev = hwmon_device_register(&new_client->dev); 347 data->class_dev = hwmon_device_register(&new_client->dev);
346 if (IS_ERR(data->class_dev)) { 348 if (IS_ERR(data->class_dev)) {
347 err = PTR_ERR(data->class_dev); 349 err = PTR_ERR(data->class_dev);
348 goto exit_detach; 350 goto exit_remove_files;
349 } 351 }
350 352
351 device_create_file_revision(new_client);
352 device_create_file_alarms(new_client);
353 device_create_file_control(new_client);
354 device_create_file_watchdog(new_client);
355
356 device_create_file_in(new_client, 0);
357 device_create_file_in(new_client, 1);
358 device_create_file_in(new_client, 2);
359
360 device_create_file_fan(new_client, 1);
361 device_create_file_fan(new_client, 2);
362 device_create_file_fan(new_client, 3);
363
364 device_create_file_temp(new_client, 1);
365 device_create_file_temp(new_client, 2);
366 device_create_file_temp(new_client, 3);
367
368 return 0; 353 return 0;
369 354
355exit_remove_files:
356 sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
370exit_detach: 357exit_detach:
371 i2c_detach_client(new_client); 358 i2c_detach_client(new_client);
372exit_free: 359exit_free:
@@ -381,6 +368,7 @@ static int fscher_detach_client(struct i2c_client *client)
381 int err; 368 int err;
382 369
383 hwmon_device_unregister(data->class_dev); 370 hwmon_device_unregister(data->class_dev);
371 sysfs_remove_group(&client->dev.kobj, &fscher_group);
384 372
385 if ((err = i2c_detach_client(client))) 373 if ((err = i2c_detach_client(client)))
386 return err; 374 return err;
diff --git a/drivers/hwmon/fscpos.c b/drivers/hwmon/fscpos.c
index 6dc4846b9eeb..ea506a77f9c9 100644
--- a/drivers/hwmon/fscpos.c
+++ b/drivers/hwmon/fscpos.c
@@ -38,6 +38,7 @@
38#include <linux/hwmon.h> 38#include <linux/hwmon.h>
39#include <linux/err.h> 39#include <linux/err.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/sysfs.h>
41 42
42/* 43/*
43 * Addresses to scan 44 * Addresses to scan
@@ -432,6 +433,44 @@ static DEVICE_ATTR(in0_input, S_IRUGO, show_volt_12, NULL);
432static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL); 433static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL);
433static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL); 434static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL);
434 435
436static struct attribute *fscpos_attributes[] = {
437 &dev_attr_event.attr,
438 &dev_attr_in0_input.attr,
439 &dev_attr_in1_input.attr,
440 &dev_attr_in2_input.attr,
441
442 &dev_attr_wdog_control.attr,
443 &dev_attr_wdog_preset.attr,
444 &dev_attr_wdog_state.attr,
445
446 &dev_attr_temp1_input.attr,
447 &dev_attr_temp1_status.attr,
448 &dev_attr_temp1_reset.attr,
449 &dev_attr_temp2_input.attr,
450 &dev_attr_temp2_status.attr,
451 &dev_attr_temp2_reset.attr,
452 &dev_attr_temp3_input.attr,
453 &dev_attr_temp3_status.attr,
454 &dev_attr_temp3_reset.attr,
455
456 &dev_attr_fan1_input.attr,
457 &dev_attr_fan1_status.attr,
458 &dev_attr_fan1_ripple.attr,
459 &dev_attr_pwm1.attr,
460 &dev_attr_fan2_input.attr,
461 &dev_attr_fan2_status.attr,
462 &dev_attr_fan2_ripple.attr,
463 &dev_attr_pwm2.attr,
464 &dev_attr_fan3_input.attr,
465 &dev_attr_fan3_status.attr,
466 &dev_attr_fan3_ripple.attr,
467 NULL
468};
469
470static const struct attribute_group fscpos_group = {
471 .attrs = fscpos_attributes,
472};
473
435static int fscpos_attach_adapter(struct i2c_adapter *adapter) 474static int fscpos_attach_adapter(struct i2c_adapter *adapter)
436{ 475{
437 if (!(adapter->class & I2C_CLASS_HWMON)) 476 if (!(adapter->class & I2C_CLASS_HWMON))
@@ -497,42 +536,19 @@ static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
497 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision); 536 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
498 537
499 /* Register sysfs hooks */ 538 /* Register sysfs hooks */
539 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscpos_group)))
540 goto exit_detach;
541
500 data->class_dev = hwmon_device_register(&new_client->dev); 542 data->class_dev = hwmon_device_register(&new_client->dev);
501 if (IS_ERR(data->class_dev)) { 543 if (IS_ERR(data->class_dev)) {
502 err = PTR_ERR(data->class_dev); 544 err = PTR_ERR(data->class_dev);
503 goto exit_detach; 545 goto exit_remove_files;
504 } 546 }
505 547
506 device_create_file(&new_client->dev, &dev_attr_event);
507 device_create_file(&new_client->dev, &dev_attr_in0_input);
508 device_create_file(&new_client->dev, &dev_attr_in1_input);
509 device_create_file(&new_client->dev, &dev_attr_in2_input);
510 device_create_file(&new_client->dev, &dev_attr_wdog_control);
511 device_create_file(&new_client->dev, &dev_attr_wdog_preset);
512 device_create_file(&new_client->dev, &dev_attr_wdog_state);
513 device_create_file(&new_client->dev, &dev_attr_temp1_input);
514 device_create_file(&new_client->dev, &dev_attr_temp1_status);
515 device_create_file(&new_client->dev, &dev_attr_temp1_reset);
516 device_create_file(&new_client->dev, &dev_attr_temp2_input);
517 device_create_file(&new_client->dev, &dev_attr_temp2_status);
518 device_create_file(&new_client->dev, &dev_attr_temp2_reset);
519 device_create_file(&new_client->dev, &dev_attr_temp3_input);
520 device_create_file(&new_client->dev, &dev_attr_temp3_status);
521 device_create_file(&new_client->dev, &dev_attr_temp3_reset);
522 device_create_file(&new_client->dev, &dev_attr_fan1_input);
523 device_create_file(&new_client->dev, &dev_attr_fan1_status);
524 device_create_file(&new_client->dev, &dev_attr_fan1_ripple);
525 device_create_file(&new_client->dev, &dev_attr_pwm1);
526 device_create_file(&new_client->dev, &dev_attr_fan2_input);
527 device_create_file(&new_client->dev, &dev_attr_fan2_status);
528 device_create_file(&new_client->dev, &dev_attr_fan2_ripple);
529 device_create_file(&new_client->dev, &dev_attr_pwm2);
530 device_create_file(&new_client->dev, &dev_attr_fan3_input);
531 device_create_file(&new_client->dev, &dev_attr_fan3_status);
532 device_create_file(&new_client->dev, &dev_attr_fan3_ripple);
533
534 return 0; 548 return 0;
535 549
550exit_remove_files:
551 sysfs_remove_group(&new_client->dev.kobj, &fscpos_group);
536exit_detach: 552exit_detach:
537 i2c_detach_client(new_client); 553 i2c_detach_client(new_client);
538exit_free: 554exit_free:
@@ -547,6 +563,7 @@ static int fscpos_detach_client(struct i2c_client *client)
547 int err; 563 int err;
548 564
549 hwmon_device_unregister(data->class_dev); 565 hwmon_device_unregister(data->class_dev);
566 sysfs_remove_group(&client->dev.kobj, &fscpos_group);
550 567
551 if ((err = i2c_detach_client(client))) 568 if ((err = i2c_detach_client(client)))
552 return err; 569 return err;
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index 6606aabdb49d..c103640455a3 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -44,6 +44,7 @@
44#include <linux/hwmon.h> 44#include <linux/hwmon.h>
45#include <linux/err.h> 45#include <linux/err.h>
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/sysfs.h>
47 48
48/* Addresses to scan */ 49/* Addresses to scan */
49static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 50static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -340,6 +341,42 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
340static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO, 341static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
341 show_beep_mask, set_beep_mask); 342 show_beep_mask, set_beep_mask);
342 343
344static struct attribute *gl518_attributes[] = {
345 &dev_attr_in0_input.attr,
346 &dev_attr_in1_input.attr,
347 &dev_attr_in2_input.attr,
348 &dev_attr_in3_input.attr,
349 &dev_attr_in0_min.attr,
350 &dev_attr_in1_min.attr,
351 &dev_attr_in2_min.attr,
352 &dev_attr_in3_min.attr,
353 &dev_attr_in0_max.attr,
354 &dev_attr_in1_max.attr,
355 &dev_attr_in2_max.attr,
356 &dev_attr_in3_max.attr,
357
358 &dev_attr_fan1_auto.attr,
359 &dev_attr_fan1_input.attr,
360 &dev_attr_fan2_input.attr,
361 &dev_attr_fan1_min.attr,
362 &dev_attr_fan2_min.attr,
363 &dev_attr_fan1_div.attr,
364 &dev_attr_fan2_div.attr,
365
366 &dev_attr_temp1_input.attr,
367 &dev_attr_temp1_max.attr,
368 &dev_attr_temp1_max_hyst.attr,
369
370 &dev_attr_alarms.attr,
371 &dev_attr_beep_enable.attr,
372 &dev_attr_beep_mask.attr,
373 NULL
374};
375
376static const struct attribute_group gl518_group = {
377 .attrs = gl518_attributes,
378};
379
343/* 380/*
344 * Real code 381 * Real code
345 */ 382 */
@@ -420,43 +457,19 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
420 gl518_init_client((struct i2c_client *) new_client); 457 gl518_init_client((struct i2c_client *) new_client);
421 458
422 /* Register sysfs hooks */ 459 /* Register sysfs hooks */
460 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group)))
461 goto exit_detach;
462
423 data->class_dev = hwmon_device_register(&new_client->dev); 463 data->class_dev = hwmon_device_register(&new_client->dev);
424 if (IS_ERR(data->class_dev)) { 464 if (IS_ERR(data->class_dev)) {
425 err = PTR_ERR(data->class_dev); 465 err = PTR_ERR(data->class_dev);
426 goto exit_detach; 466 goto exit_remove_files;
427 } 467 }
428 468
429 device_create_file(&new_client->dev, &dev_attr_in0_input);
430 device_create_file(&new_client->dev, &dev_attr_in1_input);
431 device_create_file(&new_client->dev, &dev_attr_in2_input);
432 device_create_file(&new_client->dev, &dev_attr_in3_input);
433 device_create_file(&new_client->dev, &dev_attr_in0_min);
434 device_create_file(&new_client->dev, &dev_attr_in1_min);
435 device_create_file(&new_client->dev, &dev_attr_in2_min);
436 device_create_file(&new_client->dev, &dev_attr_in3_min);
437 device_create_file(&new_client->dev, &dev_attr_in0_max);
438 device_create_file(&new_client->dev, &dev_attr_in1_max);
439 device_create_file(&new_client->dev, &dev_attr_in2_max);
440 device_create_file(&new_client->dev, &dev_attr_in3_max);
441 device_create_file(&new_client->dev, &dev_attr_fan1_auto);
442 device_create_file(&new_client->dev, &dev_attr_fan1_input);
443 device_create_file(&new_client->dev, &dev_attr_fan2_input);
444 device_create_file(&new_client->dev, &dev_attr_fan1_min);
445 device_create_file(&new_client->dev, &dev_attr_fan2_min);
446 device_create_file(&new_client->dev, &dev_attr_fan1_div);
447 device_create_file(&new_client->dev, &dev_attr_fan2_div);
448 device_create_file(&new_client->dev, &dev_attr_temp1_input);
449 device_create_file(&new_client->dev, &dev_attr_temp1_max);
450 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
451 device_create_file(&new_client->dev, &dev_attr_alarms);
452 device_create_file(&new_client->dev, &dev_attr_beep_enable);
453 device_create_file(&new_client->dev, &dev_attr_beep_mask);
454
455 return 0; 469 return 0;
456 470
457/* OK, this is not exactly good programming practice, usually. But it is 471exit_remove_files:
458 very code-efficient in this case. */ 472 sysfs_remove_group(&new_client->dev.kobj, &gl518_group);
459
460exit_detach: 473exit_detach:
461 i2c_detach_client(new_client); 474 i2c_detach_client(new_client);
462exit_free: 475exit_free:
@@ -490,6 +503,7 @@ static int gl518_detach_client(struct i2c_client *client)
490 int err; 503 int err;
491 504
492 hwmon_device_unregister(data->class_dev); 505 hwmon_device_unregister(data->class_dev);
506 sysfs_remove_group(&client->dev.kobj, &gl518_group);
493 507
494 if ((err = i2c_detach_client(client))) 508 if ((err = i2c_detach_client(client)))
495 return err; 509 return err;
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 14e810f3c2c0..ebe7b9aaa916 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/sysfs.h>
33 34
34/* Type of the extra sensor */ 35/* Type of the extra sensor */
35static unsigned short extra_sensor_type; 36static unsigned short extra_sensor_type;
@@ -190,55 +191,29 @@ static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
190#define sysfs_vid(n) \ 191#define sysfs_vid(n) \
191sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT) 192sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
192 193
193#define device_create_file_vid(client, n) \
194device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
195
196#define sysfs_in(n) \ 194#define sysfs_in(n) \
197sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \ 195sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
198sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \ 196sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
199sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \ 197sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
200 198
201#define device_create_file_in(client, n) \
202({device_create_file(&client->dev, &dev_attr_in##n##_input); \
203device_create_file(&client->dev, &dev_attr_in##n##_min); \
204device_create_file(&client->dev, &dev_attr_in##n##_max);})
205
206#define sysfs_fan(n) \ 199#define sysfs_fan(n) \
207sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \ 200sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
208sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \ 201sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
209sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV) 202sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
210 203
211#define device_create_file_fan(client, n) \
212({device_create_file(&client->dev, &dev_attr_fan##n##_input); \
213device_create_file(&client->dev, &dev_attr_fan##n##_min); \
214device_create_file(&client->dev, &dev_attr_fan##n##_div);})
215
216#define sysfs_fan_off(n) \ 204#define sysfs_fan_off(n) \
217sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \ 205sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
218 206
219#define device_create_file_fan_off(client, n) \
220device_create_file(&client->dev, &dev_attr_fan##n##_off)
221
222#define sysfs_temp(n) \ 207#define sysfs_temp(n) \
223sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \ 208sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
224sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \ 209sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
225sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST) 210sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
226 211
227#define device_create_file_temp(client, n) \
228({device_create_file(&client->dev, &dev_attr_temp##n##_input); \
229device_create_file(&client->dev, &dev_attr_temp##n##_max); \
230device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
231
232#define sysfs_alarms() \ 212#define sysfs_alarms() \
233sysfs_ro(alarms, , GL520_REG_ALARMS) \ 213sysfs_ro(alarms, , GL520_REG_ALARMS) \
234sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \ 214sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
235sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK) 215sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
236 216
237#define device_create_file_alarms(client) \
238({device_create_file(&client->dev, &dev_attr_alarms); \
239device_create_file(&client->dev, &dev_attr_beep_enable); \
240device_create_file(&client->dev, &dev_attr_beep_mask);})
241
242 217
243sysfs_vid(0) 218sysfs_vid(0)
244 219
@@ -511,6 +486,59 @@ static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data,
511 return count; 486 return count;
512} 487}
513 488
489static struct attribute *gl520_attributes[] = {
490 &dev_attr_cpu0_vid.attr,
491
492 &dev_attr_in0_input.attr,
493 &dev_attr_in0_min.attr,
494 &dev_attr_in0_max.attr,
495 &dev_attr_in1_input.attr,
496 &dev_attr_in1_min.attr,
497 &dev_attr_in1_max.attr,
498 &dev_attr_in2_input.attr,
499 &dev_attr_in2_min.attr,
500 &dev_attr_in2_max.attr,
501 &dev_attr_in3_input.attr,
502 &dev_attr_in3_min.attr,
503 &dev_attr_in3_max.attr,
504
505 &dev_attr_fan1_input.attr,
506 &dev_attr_fan1_min.attr,
507 &dev_attr_fan1_div.attr,
508 &dev_attr_fan1_off.attr,
509 &dev_attr_fan2_input.attr,
510 &dev_attr_fan2_min.attr,
511 &dev_attr_fan2_div.attr,
512
513 &dev_attr_temp1_input.attr,
514 &dev_attr_temp1_max.attr,
515 &dev_attr_temp1_max_hyst.attr,
516
517 &dev_attr_alarms.attr,
518 &dev_attr_beep_enable.attr,
519 &dev_attr_beep_mask.attr,
520 NULL
521};
522
523static const struct attribute_group gl520_group = {
524 .attrs = gl520_attributes,
525};
526
527static struct attribute *gl520_attributes_opt[] = {
528 &dev_attr_in4_input.attr,
529 &dev_attr_in4_min.attr,
530 &dev_attr_in4_max.attr,
531
532 &dev_attr_temp2_input.attr,
533 &dev_attr_temp2_max.attr,
534 &dev_attr_temp2_max_hyst.attr,
535 NULL
536};
537
538static const struct attribute_group gl520_group_opt = {
539 .attrs = gl520_attributes_opt,
540};
541
514 542
515/* 543/*
516 * Real code 544 * Real code
@@ -572,33 +600,39 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
572 gl520_init_client(new_client); 600 gl520_init_client(new_client);
573 601
574 /* Register sysfs hooks */ 602 /* Register sysfs hooks */
575 data->class_dev = hwmon_device_register(&new_client->dev); 603 if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group)))
576 if (IS_ERR(data->class_dev)) {
577 err = PTR_ERR(data->class_dev);
578 goto exit_detach; 604 goto exit_detach;
579 }
580
581 device_create_file_vid(new_client, 0);
582 605
583 device_create_file_in(new_client, 0); 606 if (data->two_temps) {
584 device_create_file_in(new_client, 1); 607 if ((err = device_create_file(&new_client->dev,
585 device_create_file_in(new_client, 2); 608 &dev_attr_temp2_input))
586 device_create_file_in(new_client, 3); 609 || (err = device_create_file(&new_client->dev,
587 if (!data->two_temps) 610 &dev_attr_temp2_max))
588 device_create_file_in(new_client, 4); 611 || (err = device_create_file(&new_client->dev,
589 612 &dev_attr_temp2_max_hyst)))
590 device_create_file_fan(new_client, 1); 613 goto exit_remove_files;
591 device_create_file_fan(new_client, 2); 614 } else {
592 device_create_file_fan_off(new_client, 1); 615 if ((err = device_create_file(&new_client->dev,
616 &dev_attr_in4_input))
617 || (err = device_create_file(&new_client->dev,
618 &dev_attr_in4_min))
619 || (err = device_create_file(&new_client->dev,
620 &dev_attr_in4_max)))
621 goto exit_remove_files;
622 }
593 623
594 device_create_file_temp(new_client, 1);
595 if (data->two_temps)
596 device_create_file_temp(new_client, 2);
597 624
598 device_create_file_alarms(new_client); 625 data->class_dev = hwmon_device_register(&new_client->dev);
626 if (IS_ERR(data->class_dev)) {
627 err = PTR_ERR(data->class_dev);
628 goto exit_remove_files;
629 }
599 630
600 return 0; 631 return 0;
601 632
633exit_remove_files:
634 sysfs_remove_group(&new_client->dev.kobj, &gl520_group);
635 sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt);
602exit_detach: 636exit_detach:
603 i2c_detach_client(new_client); 637 i2c_detach_client(new_client);
604exit_free: 638exit_free:
@@ -652,6 +686,8 @@ static int gl520_detach_client(struct i2c_client *client)
652 int err; 686 int err;
653 687
654 hwmon_device_unregister(data->class_dev); 688 hwmon_device_unregister(data->class_dev);
689 sysfs_remove_group(&client->dev.kobj, &gl520_group);
690 sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
655 691
656 if ((err = i2c_detach_client(client))) 692 if ((err = i2c_detach_client(client)))
657 return err; 693 return err;
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index 42b632889dd8..8e7b5607f5a1 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -587,7 +587,9 @@ static int __init hdaps_init(void)
587 input_set_abs_params(hdaps_idev, ABS_Y, 587 input_set_abs_params(hdaps_idev, ABS_Y,
588 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); 588 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
589 589
590 input_register_device(hdaps_idev); 590 ret = input_register_device(hdaps_idev);
591 if (ret)
592 goto out_idev;
591 593
592 /* start up our timer for the input device */ 594 /* start up our timer for the input device */
593 init_timer(&hdaps_timer); 595 init_timer(&hdaps_timer);
@@ -598,6 +600,8 @@ static int __init hdaps_init(void)
598 printk(KERN_INFO "hdaps: driver successfully loaded.\n"); 600 printk(KERN_INFO "hdaps: driver successfully loaded.\n");
599 return 0; 601 return 0;
600 602
603out_idev:
604 input_free_device(hdaps_idev);
601out_group: 605out_group:
602 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group); 606 sysfs_remove_group(&pdev->dev.kobj, &hdaps_attribute_group);
603out_device: 607out_device:
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index b0ee57492228..323ef06719c1 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -4,10 +4,12 @@
4 4
5 Supports: IT8705F Super I/O chip w/LPC interface 5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMBus 6 IT8712F Super I/O chip w/LPC interface & SMBus
7 IT8716F Super I/O chip w/LPC interface
8 IT8718F Super I/O chip w/LPC interface
7 Sis950 A clone of the IT8705F 9 Sis950 A clone of the IT8705F
8 10
9 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 11 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
10 Largely inspired by lm78.c of the same package 12 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
11 13
12 This program is free software; you can redistribute it and/or modify 14 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 15 it under the terms of the GNU General Public License as published by
@@ -24,13 +26,6 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/ 27*/
26 28
27/*
28 djg@pdp8.net David Gesswein 7/18/01
29 Modified to fix bug with not all alarms enabled.
30 Added ability to read battery voltage and select temperature sensor
31 type at module load time.
32*/
33
34#include <linux/module.h> 29#include <linux/module.h>
35#include <linux/init.h> 30#include <linux/init.h>
36#include <linux/slab.h> 31#include <linux/slab.h>
@@ -42,6 +37,7 @@
42#include <linux/hwmon-vid.h> 37#include <linux/hwmon-vid.h>
43#include <linux/err.h> 38#include <linux/err.h>
44#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/sysfs.h>
45#include <asm/io.h> 41#include <asm/io.h>
46 42
47 43
@@ -50,12 +46,13 @@ static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
50static unsigned short isa_address; 46static unsigned short isa_address;
51 47
52/* Insmod parameters */ 48/* Insmod parameters */
53I2C_CLIENT_INSMOD_2(it87, it8712); 49I2C_CLIENT_INSMOD_4(it87, it8712, it8716, it8718);
54 50
55#define REG 0x2e /* The register to read/write */ 51#define REG 0x2e /* The register to read/write */
56#define DEV 0x07 /* Register: Logical device select */ 52#define DEV 0x07 /* Register: Logical device select */
57#define VAL 0x2f /* The value to read/write */ 53#define VAL 0x2f /* The value to read/write */
58#define PME 0x04 /* The device with the fan registers in it */ 54#define PME 0x04 /* The device with the fan registers in it */
55#define GPIO 0x07 /* The device with the IT8718F VID value in it */
59#define DEVID 0x20 /* Register: Device ID */ 56#define DEVID 0x20 /* Register: Device ID */
60#define DEVREV 0x22 /* Register: Device Revision */ 57#define DEVREV 0x22 /* Register: Device Revision */
61 58
@@ -77,10 +74,10 @@ static int superio_inw(int reg)
77} 74}
78 75
79static inline void 76static inline void
80superio_select(void) 77superio_select(int ldn)
81{ 78{
82 outb(DEV, REG); 79 outb(DEV, REG);
83 outb(PME, VAL); 80 outb(ldn, VAL);
84} 81}
85 82
86static inline void 83static inline void
@@ -99,20 +96,27 @@ superio_exit(void)
99 outb(0x02, VAL); 96 outb(0x02, VAL);
100} 97}
101 98
99/* Logical device 4 registers */
102#define IT8712F_DEVID 0x8712 100#define IT8712F_DEVID 0x8712
103#define IT8705F_DEVID 0x8705 101#define IT8705F_DEVID 0x8705
102#define IT8716F_DEVID 0x8716
103#define IT8718F_DEVID 0x8718
104#define IT87_ACT_REG 0x30 104#define IT87_ACT_REG 0x30
105#define IT87_BASE_REG 0x60 105#define IT87_BASE_REG 0x60
106 106
107/* Logical device 7 registers (IT8712F and later) */
108#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
109#define IT87_SIO_VID_REG 0xfc /* VID value */
110
107/* Update battery voltage after every reading if true */ 111/* Update battery voltage after every reading if true */
108static int update_vbat; 112static int update_vbat;
109 113
110/* Not all BIOSes properly configure the PWM registers */ 114/* Not all BIOSes properly configure the PWM registers */
111static int fix_pwm_polarity; 115static int fix_pwm_polarity;
112 116
113/* Chip Type */ 117/* Values read from Super-I/O config space */
114
115static u16 chip_type; 118static u16 chip_type;
119static u8 vid_value;
116 120
117/* Many IT87 constants specified below */ 121/* Many IT87 constants specified below */
118 122
@@ -131,13 +135,21 @@ static u16 chip_type;
131#define IT87_REG_ALARM2 0x02 135#define IT87_REG_ALARM2 0x02
132#define IT87_REG_ALARM3 0x03 136#define IT87_REG_ALARM3 0x03
133 137
138/* The IT8718F has the VID value in a different register, in Super-I/O
139 configuration space. */
134#define IT87_REG_VID 0x0a 140#define IT87_REG_VID 0x0a
141/* Warning: register 0x0b is used for something completely different in
142 new chips/revisions. I suspect only 16-bit tachometer mode will work
143 for these. */
135#define IT87_REG_FAN_DIV 0x0b 144#define IT87_REG_FAN_DIV 0x0b
145#define IT87_REG_FAN_16BIT 0x0c
136 146
137/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ 147/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
138 148
139#define IT87_REG_FAN(nr) (0x0d + (nr)) 149#define IT87_REG_FAN(nr) (0x0d + (nr))
140#define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) 150#define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
151#define IT87_REG_FANX(nr) (0x18 + (nr))
152#define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
141#define IT87_REG_FAN_MAIN_CTRL 0x13 153#define IT87_REG_FAN_MAIN_CTRL 0x13
142#define IT87_REG_FAN_CTL 0x14 154#define IT87_REG_FAN_CTL 0x14
143#define IT87_REG_PWM(nr) (0x15 + (nr)) 155#define IT87_REG_PWM(nr) (0x15 + (nr))
@@ -169,7 +181,16 @@ static inline u8 FAN_TO_REG(long rpm, int div)
169 254); 181 254);
170} 182}
171 183
184static inline u16 FAN16_TO_REG(long rpm)
185{
186 if (rpm == 0)
187 return 0xffff;
188 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
189}
190
172#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 191#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
192/* The divider is fixed to 2 in 16-bit mode */
193#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
173 194
174#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ 195#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
175 ((val)+500)/1000),-128,127)) 196 ((val)+500)/1000),-128,127))
@@ -181,7 +202,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
181static int DIV_TO_REG(int val) 202static int DIV_TO_REG(int val)
182{ 203{
183 int answer = 0; 204 int answer = 0;
184 while ((val >>= 1) != 0) 205 while (answer < 7 && (val >>= 1))
185 answer++; 206 answer++;
186 return answer; 207 return answer;
187} 208}
@@ -203,10 +224,11 @@ struct it87_data {
203 unsigned long last_updated; /* In jiffies */ 224 unsigned long last_updated; /* In jiffies */
204 225
205 u8 in[9]; /* Register value */ 226 u8 in[9]; /* Register value */
206 u8 in_max[9]; /* Register value */ 227 u8 in_max[8]; /* Register value */
207 u8 in_min[9]; /* Register value */ 228 u8 in_min[8]; /* Register value */
208 u8 fan[3]; /* Register value */ 229 u8 has_fan; /* Bitfield, fans enabled */
209 u8 fan_min[3]; /* Register value */ 230 u16 fan[3]; /* Register values, possibly combined */
231 u16 fan_min[3]; /* Register values, possibly combined */
210 u8 temp[3]; /* Register value */ 232 u8 temp[3]; /* Register value */
211 u8 temp_high[3]; /* Register value */ 233 u8 temp_high[3]; /* Register value */
212 u8 temp_low[3]; /* Register value */ 234 u8 temp_low[3]; /* Register value */
@@ -545,15 +567,15 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
545 567
546 struct i2c_client *client = to_i2c_client(dev); 568 struct i2c_client *client = to_i2c_client(dev);
547 struct it87_data *data = i2c_get_clientdata(client); 569 struct it87_data *data = i2c_get_clientdata(client);
548 int val = simple_strtol(buf, NULL, 10); 570 unsigned long val = simple_strtoul(buf, NULL, 10);
549 int i, min[3]; 571 int min;
550 u8 old; 572 u8 old;
551 573
552 mutex_lock(&data->update_lock); 574 mutex_lock(&data->update_lock);
553 old = it87_read_value(client, IT87_REG_FAN_DIV); 575 old = it87_read_value(client, IT87_REG_FAN_DIV);
554 576
555 for (i = 0; i < 3; i++) 577 /* Save fan min limit */
556 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); 578 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
557 579
558 switch (nr) { 580 switch (nr) {
559 case 0: 581 case 0:
@@ -573,10 +595,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
573 val |= 0x1 << 6; 595 val |= 0x1 << 6;
574 it87_write_value(client, IT87_REG_FAN_DIV, val); 596 it87_write_value(client, IT87_REG_FAN_DIV, val);
575 597
576 for (i = 0; i < 3; i++) { 598 /* Restore fan min limit */
577 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); 599 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
578 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); 600 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
579 } 601
580 mutex_unlock(&data->update_lock); 602 mutex_unlock(&data->update_lock);
581 return count; 603 return count;
582} 604}
@@ -657,6 +679,59 @@ show_pwm_offset(1);
657show_pwm_offset(2); 679show_pwm_offset(2);
658show_pwm_offset(3); 680show_pwm_offset(3);
659 681
682/* A different set of callbacks for 16-bit fans */
683static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
684 char *buf)
685{
686 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
687 int nr = sensor_attr->index;
688 struct it87_data *data = it87_update_device(dev);
689 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
690}
691
692static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
693 char *buf)
694{
695 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
696 int nr = sensor_attr->index;
697 struct it87_data *data = it87_update_device(dev);
698 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
699}
700
701static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
702 const char *buf, size_t count)
703{
704 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
705 int nr = sensor_attr->index;
706 struct i2c_client *client = to_i2c_client(dev);
707 struct it87_data *data = i2c_get_clientdata(client);
708 int val = simple_strtol(buf, NULL, 10);
709
710 mutex_lock(&data->update_lock);
711 data->fan_min[nr] = FAN16_TO_REG(val);
712 it87_write_value(client, IT87_REG_FAN_MIN(nr),
713 data->fan_min[nr] & 0xff);
714 it87_write_value(client, IT87_REG_FANX_MIN(nr),
715 data->fan_min[nr] >> 8);
716 mutex_unlock(&data->update_lock);
717 return count;
718}
719
720/* We want to use the same sysfs file names as 8-bit fans, but we need
721 different variable names, so we have to use SENSOR_ATTR instead of
722 SENSOR_DEVICE_ATTR. */
723#define show_fan16_offset(offset) \
724static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
725 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
726 show_fan16, NULL, offset - 1); \
727static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
728 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
729 show_fan16_min, set_fan16_min, offset - 1)
730
731show_fan16_offset(1);
732show_fan16_offset(2);
733show_fan16_offset(3);
734
660/* Alarms */ 735/* Alarms */
661static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 736static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
662{ 737{
@@ -684,8 +759,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
684 return count; 759 return count;
685} 760}
686static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 761static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
687#define device_create_file_vrm(client) \
688device_create_file(&client->dev, &dev_attr_vrm)
689 762
690static ssize_t 763static ssize_t
691show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 764show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -694,8 +767,88 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
694 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 767 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
695} 768}
696static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 769static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
697#define device_create_file_vid(client) \ 770
698device_create_file(&client->dev, &dev_attr_cpu0_vid) 771static struct attribute *it87_attributes[] = {
772 &sensor_dev_attr_in0_input.dev_attr.attr,
773 &sensor_dev_attr_in1_input.dev_attr.attr,
774 &sensor_dev_attr_in2_input.dev_attr.attr,
775 &sensor_dev_attr_in3_input.dev_attr.attr,
776 &sensor_dev_attr_in4_input.dev_attr.attr,
777 &sensor_dev_attr_in5_input.dev_attr.attr,
778 &sensor_dev_attr_in6_input.dev_attr.attr,
779 &sensor_dev_attr_in7_input.dev_attr.attr,
780 &sensor_dev_attr_in8_input.dev_attr.attr,
781 &sensor_dev_attr_in0_min.dev_attr.attr,
782 &sensor_dev_attr_in1_min.dev_attr.attr,
783 &sensor_dev_attr_in2_min.dev_attr.attr,
784 &sensor_dev_attr_in3_min.dev_attr.attr,
785 &sensor_dev_attr_in4_min.dev_attr.attr,
786 &sensor_dev_attr_in5_min.dev_attr.attr,
787 &sensor_dev_attr_in6_min.dev_attr.attr,
788 &sensor_dev_attr_in7_min.dev_attr.attr,
789 &sensor_dev_attr_in0_max.dev_attr.attr,
790 &sensor_dev_attr_in1_max.dev_attr.attr,
791 &sensor_dev_attr_in2_max.dev_attr.attr,
792 &sensor_dev_attr_in3_max.dev_attr.attr,
793 &sensor_dev_attr_in4_max.dev_attr.attr,
794 &sensor_dev_attr_in5_max.dev_attr.attr,
795 &sensor_dev_attr_in6_max.dev_attr.attr,
796 &sensor_dev_attr_in7_max.dev_attr.attr,
797
798 &sensor_dev_attr_temp1_input.dev_attr.attr,
799 &sensor_dev_attr_temp2_input.dev_attr.attr,
800 &sensor_dev_attr_temp3_input.dev_attr.attr,
801 &sensor_dev_attr_temp1_max.dev_attr.attr,
802 &sensor_dev_attr_temp2_max.dev_attr.attr,
803 &sensor_dev_attr_temp3_max.dev_attr.attr,
804 &sensor_dev_attr_temp1_min.dev_attr.attr,
805 &sensor_dev_attr_temp2_min.dev_attr.attr,
806 &sensor_dev_attr_temp3_min.dev_attr.attr,
807 &sensor_dev_attr_temp1_type.dev_attr.attr,
808 &sensor_dev_attr_temp2_type.dev_attr.attr,
809 &sensor_dev_attr_temp3_type.dev_attr.attr,
810
811 &dev_attr_alarms.attr,
812 NULL
813};
814
815static const struct attribute_group it87_group = {
816 .attrs = it87_attributes,
817};
818
819static struct attribute *it87_attributes_opt[] = {
820 &sensor_dev_attr_fan1_input16.dev_attr.attr,
821 &sensor_dev_attr_fan1_min16.dev_attr.attr,
822 &sensor_dev_attr_fan2_input16.dev_attr.attr,
823 &sensor_dev_attr_fan2_min16.dev_attr.attr,
824 &sensor_dev_attr_fan3_input16.dev_attr.attr,
825 &sensor_dev_attr_fan3_min16.dev_attr.attr,
826
827 &sensor_dev_attr_fan1_input.dev_attr.attr,
828 &sensor_dev_attr_fan1_min.dev_attr.attr,
829 &sensor_dev_attr_fan1_div.dev_attr.attr,
830 &sensor_dev_attr_fan2_input.dev_attr.attr,
831 &sensor_dev_attr_fan2_min.dev_attr.attr,
832 &sensor_dev_attr_fan2_div.dev_attr.attr,
833 &sensor_dev_attr_fan3_input.dev_attr.attr,
834 &sensor_dev_attr_fan3_min.dev_attr.attr,
835 &sensor_dev_attr_fan3_div.dev_attr.attr,
836
837 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
838 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
839 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
840 &sensor_dev_attr_pwm1.dev_attr.attr,
841 &sensor_dev_attr_pwm2.dev_attr.attr,
842 &sensor_dev_attr_pwm3.dev_attr.attr,
843
844 &dev_attr_vrm.attr,
845 &dev_attr_cpu0_vid.attr,
846 NULL
847};
848
849static const struct attribute_group it87_group_opt = {
850 .attrs = it87_attributes_opt,
851};
699 852
700/* This function is called when: 853/* This function is called when:
701 * it87_driver is inserted (when this module is loaded), for each 854 * it87_driver is inserted (when this module is loaded), for each
@@ -721,10 +874,12 @@ static int __init it87_find(unsigned short *address)
721 superio_enter(); 874 superio_enter();
722 chip_type = superio_inw(DEVID); 875 chip_type = superio_inw(DEVID);
723 if (chip_type != IT8712F_DEVID 876 if (chip_type != IT8712F_DEVID
877 && chip_type != IT8716F_DEVID
878 && chip_type != IT8718F_DEVID
724 && chip_type != IT8705F_DEVID) 879 && chip_type != IT8705F_DEVID)
725 goto exit; 880 goto exit;
726 881
727 superio_select(); 882 superio_select(PME);
728 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 883 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
729 pr_info("it87: Device not activated, skipping\n"); 884 pr_info("it87: Device not activated, skipping\n");
730 goto exit; 885 goto exit;
@@ -740,6 +895,21 @@ static int __init it87_find(unsigned short *address)
740 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 895 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
741 chip_type, *address, superio_inb(DEVREV) & 0x0f); 896 chip_type, *address, superio_inb(DEVREV) & 0x0f);
742 897
898 /* Read GPIO config and VID value from LDN 7 (GPIO) */
899 if (chip_type != IT8705F_DEVID) {
900 int reg;
901
902 superio_select(GPIO);
903 if (chip_type == it8718)
904 vid_value = superio_inb(IT87_SIO_VID_REG);
905
906 reg = superio_inb(IT87_SIO_PINX2_REG);
907 if (reg & (1 << 0))
908 pr_info("it87: in3 is VCC (+5V)\n");
909 if (reg & (1 << 1))
910 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
911 }
912
743exit: 913exit:
744 superio_exit(); 914 superio_exit();
745 return err; 915 return err;
@@ -800,8 +970,19 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
800 i = it87_read_value(new_client, IT87_REG_CHIPID); 970 i = it87_read_value(new_client, IT87_REG_CHIPID);
801 if (i == 0x90) { 971 if (i == 0x90) {
802 kind = it87; 972 kind = it87;
803 if ((is_isa) && (chip_type == IT8712F_DEVID)) 973 if (is_isa) {
804 kind = it8712; 974 switch (chip_type) {
975 case IT8712F_DEVID:
976 kind = it8712;
977 break;
978 case IT8716F_DEVID:
979 kind = it8716;
980 break;
981 case IT8718F_DEVID:
982 kind = it8718;
983 break;
984 }
985 }
805 } 986 }
806 else { 987 else {
807 if (kind == 0) 988 if (kind == 0)
@@ -818,6 +999,10 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
818 name = "it87"; 999 name = "it87";
819 } else if (kind == it8712) { 1000 } else if (kind == it8712) {
820 name = "it8712"; 1001 name = "it8712";
1002 } else if (kind == it8716) {
1003 name = "it8716";
1004 } else if (kind == it8718) {
1005 name = "it8718";
821 } 1006 }
822 1007
823 /* Fill in the remaining client fields and put it into the global list */ 1008 /* Fill in the remaining client fields and put it into the global list */
@@ -842,76 +1027,103 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
842 it87_init_client(new_client, data); 1027 it87_init_client(new_client, data);
843 1028
844 /* Register sysfs hooks */ 1029 /* Register sysfs hooks */
845 data->class_dev = hwmon_device_register(&new_client->dev); 1030 if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group)))
846 if (IS_ERR(data->class_dev)) {
847 err = PTR_ERR(data->class_dev);
848 goto ERROR3; 1031 goto ERROR3;
1032
1033 /* Do not create fan files for disabled fans */
1034 if (data->type == it8716 || data->type == it8718) {
1035 /* 16-bit tachometers */
1036 if (data->has_fan & (1 << 0)) {
1037 if ((err = device_create_file(&new_client->dev,
1038 &sensor_dev_attr_fan1_input16.dev_attr))
1039 || (err = device_create_file(&new_client->dev,
1040 &sensor_dev_attr_fan1_min16.dev_attr)))
1041 goto ERROR4;
1042 }
1043 if (data->has_fan & (1 << 1)) {
1044 if ((err = device_create_file(&new_client->dev,
1045 &sensor_dev_attr_fan2_input16.dev_attr))
1046 || (err = device_create_file(&new_client->dev,
1047 &sensor_dev_attr_fan2_min16.dev_attr)))
1048 goto ERROR4;
1049 }
1050 if (data->has_fan & (1 << 2)) {
1051 if ((err = device_create_file(&new_client->dev,
1052 &sensor_dev_attr_fan3_input16.dev_attr))
1053 || (err = device_create_file(&new_client->dev,
1054 &sensor_dev_attr_fan3_min16.dev_attr)))
1055 goto ERROR4;
1056 }
1057 } else {
1058 /* 8-bit tachometers with clock divider */
1059 if (data->has_fan & (1 << 0)) {
1060 if ((err = device_create_file(&new_client->dev,
1061 &sensor_dev_attr_fan1_input.dev_attr))
1062 || (err = device_create_file(&new_client->dev,
1063 &sensor_dev_attr_fan1_min.dev_attr))
1064 || (err = device_create_file(&new_client->dev,
1065 &sensor_dev_attr_fan1_div.dev_attr)))
1066 goto ERROR4;
1067 }
1068 if (data->has_fan & (1 << 1)) {
1069 if ((err = device_create_file(&new_client->dev,
1070 &sensor_dev_attr_fan2_input.dev_attr))
1071 || (err = device_create_file(&new_client->dev,
1072 &sensor_dev_attr_fan2_min.dev_attr))
1073 || (err = device_create_file(&new_client->dev,
1074 &sensor_dev_attr_fan2_div.dev_attr)))
1075 goto ERROR4;
1076 }
1077 if (data->has_fan & (1 << 2)) {
1078 if ((err = device_create_file(&new_client->dev,
1079 &sensor_dev_attr_fan3_input.dev_attr))
1080 || (err = device_create_file(&new_client->dev,
1081 &sensor_dev_attr_fan3_min.dev_attr))
1082 || (err = device_create_file(&new_client->dev,
1083 &sensor_dev_attr_fan3_div.dev_attr)))
1084 goto ERROR4;
1085 }
849 } 1086 }
850 1087
851 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
852 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
853 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
854 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
855 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
856 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
857 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
858 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
859 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
860 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
861 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
862 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
863 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
864 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
865 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
866 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
867 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
868 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
869 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
870 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
871 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
872 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
873 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
874 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
875 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
876 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
877 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
878 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
879 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
880 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
881 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
882 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
883 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
884 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
885 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
886 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
887 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
888 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
889 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
890 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
891 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
892 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
893 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
894 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
895 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
896 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
897 device_create_file(&new_client->dev, &dev_attr_alarms);
898 if (enable_pwm_interface) { 1088 if (enable_pwm_interface) {
899 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); 1089 if ((err = device_create_file(&new_client->dev,
900 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); 1090 &sensor_dev_attr_pwm1_enable.dev_attr))
901 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); 1091 || (err = device_create_file(&new_client->dev,
902 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); 1092 &sensor_dev_attr_pwm2_enable.dev_attr))
903 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); 1093 || (err = device_create_file(&new_client->dev,
904 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); 1094 &sensor_dev_attr_pwm3_enable.dev_attr))
1095 || (err = device_create_file(&new_client->dev,
1096 &sensor_dev_attr_pwm1.dev_attr))
1097 || (err = device_create_file(&new_client->dev,
1098 &sensor_dev_attr_pwm2.dev_attr))
1099 || (err = device_create_file(&new_client->dev,
1100 &sensor_dev_attr_pwm3.dev_attr)))
1101 goto ERROR4;
905 } 1102 }
906 1103
907 if (data->type == it8712) { 1104 if (data->type == it8712 || data->type == it8716
1105 || data->type == it8718) {
908 data->vrm = vid_which_vrm(); 1106 data->vrm = vid_which_vrm();
909 device_create_file_vrm(new_client); 1107 /* VID reading from Super-I/O config space if available */
910 device_create_file_vid(new_client); 1108 data->vid = vid_value;
1109 if ((err = device_create_file(&new_client->dev,
1110 &dev_attr_vrm))
1111 || (err = device_create_file(&new_client->dev,
1112 &dev_attr_cpu0_vid)))
1113 goto ERROR4;
1114 }
1115
1116 data->class_dev = hwmon_device_register(&new_client->dev);
1117 if (IS_ERR(data->class_dev)) {
1118 err = PTR_ERR(data->class_dev);
1119 goto ERROR4;
911 } 1120 }
912 1121
913 return 0; 1122 return 0;
914 1123
1124ERROR4:
1125 sysfs_remove_group(&new_client->dev.kobj, &it87_group);
1126 sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt);
915ERROR3: 1127ERROR3:
916 i2c_detach_client(new_client); 1128 i2c_detach_client(new_client);
917ERROR2: 1129ERROR2:
@@ -929,6 +1141,8 @@ static int it87_detach_client(struct i2c_client *client)
929 int err; 1141 int err;
930 1142
931 hwmon_device_unregister(data->class_dev); 1143 hwmon_device_unregister(data->class_dev);
1144 sysfs_remove_group(&client->dev.kobj, &it87_group);
1145 sysfs_remove_group(&client->dev.kobj, &it87_group_opt);
932 1146
933 if ((err = i2c_detach_client(client))) 1147 if ((err = i2c_detach_client(client)))
934 return err; 1148 return err;
@@ -1045,6 +1259,22 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1045 data->manual_pwm_ctl[i] = 0xff; 1259 data->manual_pwm_ctl[i] = 0xff;
1046 } 1260 }
1047 1261
1262 /* Some chips seem to have default value 0xff for all limit
1263 * registers. For low voltage limits it makes no sense and triggers
1264 * alarms, so change to 0 instead. For high temperature limits, it
1265 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1266 * but is still confusing, so change to 127 degrees C. */
1267 for (i = 0; i < 8; i++) {
1268 tmp = it87_read_value(client, IT87_REG_VIN_MIN(i));
1269 if (tmp == 0xff)
1270 it87_write_value(client, IT87_REG_VIN_MIN(i), 0);
1271 }
1272 for (i = 0; i < 3; i++) {
1273 tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1274 if (tmp == 0xff)
1275 it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127);
1276 }
1277
1048 /* Check if temperature channnels are reset manually or by some reason */ 1278 /* Check if temperature channnels are reset manually or by some reason */
1049 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1279 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1050 if ((tmp & 0x3f) == 0) { 1280 if ((tmp & 0x3f) == 0) {
@@ -1068,6 +1298,18 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1068 data->fan_main_ctrl |= 0x70; 1298 data->fan_main_ctrl |= 0x70;
1069 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1299 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1070 } 1300 }
1301 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1302
1303 /* Set tachometers to 16-bit mode if needed */
1304 if (data->type == it8716 || data->type == it8718) {
1305 tmp = it87_read_value(client, IT87_REG_FAN_16BIT);
1306 if (~tmp & 0x07 & data->has_fan) {
1307 dev_dbg(&client->dev,
1308 "Setting fan1-3 to 16-bit mode\n");
1309 it87_write_value(client, IT87_REG_FAN_16BIT,
1310 tmp | 0x07);
1311 }
1312 }
1071 1313
1072 /* Set current fan mode registers and the default settings for the 1314 /* Set current fan mode registers and the default settings for the
1073 * other mode registers */ 1315 * other mode registers */
@@ -1118,18 +1360,26 @@ static struct it87_data *it87_update_device(struct device *dev)
1118 data->in_max[i] = 1360 data->in_max[i] =
1119 it87_read_value(client, IT87_REG_VIN_MAX(i)); 1361 it87_read_value(client, IT87_REG_VIN_MAX(i));
1120 } 1362 }
1363 /* in8 (battery) has no limit registers */
1121 data->in[8] = 1364 data->in[8] =
1122 it87_read_value(client, IT87_REG_VIN(8)); 1365 it87_read_value(client, IT87_REG_VIN(8));
1123 /* Temperature sensor doesn't have limit registers, set
1124 to min and max value */
1125 data->in_min[8] = 0;
1126 data->in_max[8] = 255;
1127 1366
1128 for (i = 0; i < 3; i++) { 1367 for (i = 0; i < 3; i++) {
1129 data->fan[i] = 1368 /* Skip disabled fans */
1130 it87_read_value(client, IT87_REG_FAN(i)); 1369 if (!(data->has_fan & (1 << i)))
1370 continue;
1371
1131 data->fan_min[i] = 1372 data->fan_min[i] =
1132 it87_read_value(client, IT87_REG_FAN_MIN(i)); 1373 it87_read_value(client, IT87_REG_FAN_MIN(i));
1374 data->fan[i] = it87_read_value(client,
1375 IT87_REG_FAN(i));
1376 /* Add high byte if in 16-bit mode */
1377 if (data->type == it8716 || data->type == it8718) {
1378 data->fan[i] |= it87_read_value(client,
1379 IT87_REG_FANX(i)) << 8;
1380 data->fan_min[i] |= it87_read_value(client,
1381 IT87_REG_FANX_MIN(i)) << 8;
1382 }
1133 } 1383 }
1134 for (i = 0; i < 3; i++) { 1384 for (i = 0; i < 3; i++) {
1135 data->temp[i] = 1385 data->temp[i] =
@@ -1140,10 +1390,14 @@ static struct it87_data *it87_update_device(struct device *dev)
1140 it87_read_value(client, IT87_REG_TEMP_LOW(i)); 1390 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1141 } 1391 }
1142 1392
1143 i = it87_read_value(client, IT87_REG_FAN_DIV); 1393 /* Newer chips don't have clock dividers */
1144 data->fan_div[0] = i & 0x07; 1394 if ((data->has_fan & 0x07) && data->type != it8716
1145 data->fan_div[1] = (i >> 3) & 0x07; 1395 && data->type != it8718) {
1146 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1396 i = it87_read_value(client, IT87_REG_FAN_DIV);
1397 data->fan_div[0] = i & 0x07;
1398 data->fan_div[1] = (i >> 3) & 0x07;
1399 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1400 }
1147 1401
1148 data->alarms = 1402 data->alarms =
1149 it87_read_value(client, IT87_REG_ALARM1) | 1403 it87_read_value(client, IT87_REG_ALARM1) |
@@ -1153,9 +1407,11 @@ static struct it87_data *it87_update_device(struct device *dev)
1153 1407
1154 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1408 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1155 /* The 8705 does not have VID capability */ 1409 /* The 8705 does not have VID capability */
1156 if (data->type == it8712) { 1410 if (data->type == it8712 || data->type == it8716) {
1157 data->vid = it87_read_value(client, IT87_REG_VID); 1411 data->vid = it87_read_value(client, IT87_REG_VID);
1158 data->vid &= 0x1f; 1412 /* The older IT8712F revisions had only 5 VID pins,
1413 but we assume it is always safe to read 6 bits. */
1414 data->vid &= 0x3f;
1159 } 1415 }
1160 data->last_updated = jiffies; 1416 data->last_updated = jiffies;
1161 data->valid = 1; 1417 data->valid = 1;
@@ -1193,8 +1449,9 @@ static void __exit sm_it87_exit(void)
1193} 1449}
1194 1450
1195 1451
1196MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); 1452MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1197MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); 1453 "Jean Delvare <khali@linux-fr.org>");
1454MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver");
1198module_param(update_vbat, bool, 0); 1455module_param(update_vbat, bool, 0);
1199MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1456MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1200module_param(fix_pwm_polarity, bool, 0); 1457module_param(fix_pwm_polarity, bool, 0);
diff --git a/drivers/hwmon/k8temp.c b/drivers/hwmon/k8temp.c
new file mode 100644
index 000000000000..f58b64ed09e3
--- /dev/null
+++ b/drivers/hwmon/k8temp.c
@@ -0,0 +1,294 @@
1/*
2 * k8temp.c - Linux kernel module for hardware monitoring
3 *
4 * Copyright (C) 2006 Rudolf Marek <r.marek@sh.cvut.cz>
5 *
6 * Inspired from the w83785 and amd756 drivers.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301 USA.
22 */
23
24#include <linux/module.h>
25#include <linux/delay.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/jiffies.h>
29#include <linux/pci.h>
30#include <linux/hwmon.h>
31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34
35#define TEMP_FROM_REG(val) (((((val) >> 16) & 0xff) - 49) * 1000)
36#define REG_TEMP 0xe4
37#define SEL_PLACE 0x40
38#define SEL_CORE 0x04
39
40struct k8temp_data {
41 struct class_device *class_dev;
42 struct mutex update_lock;
43 const char *name;
44 char valid; /* zero until following fields are valid */
45 unsigned long last_updated; /* in jiffies */
46
47 /* registers values */
48 u8 sensorsp; /* sensor presence bits - SEL_CORE & SEL_PLACE */
49 u32 temp[2][2]; /* core, place */
50};
51
52static struct k8temp_data *k8temp_update_device(struct device *dev)
53{
54 struct k8temp_data *data = dev_get_drvdata(dev);
55 struct pci_dev *pdev = to_pci_dev(dev);
56 u8 tmp;
57
58 mutex_lock(&data->update_lock);
59
60 if (!data->valid
61 || time_after(jiffies, data->last_updated + HZ)) {
62 pci_read_config_byte(pdev, REG_TEMP, &tmp);
63 tmp &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
64 pci_write_config_byte(pdev, REG_TEMP, tmp);
65 pci_read_config_dword(pdev, REG_TEMP, &data->temp[0][0]);
66
67 if (data->sensorsp & SEL_PLACE) {
68 tmp |= SEL_PLACE; /* Select sensor 1, core0 */
69 pci_write_config_byte(pdev, REG_TEMP, tmp);
70 pci_read_config_dword(pdev, REG_TEMP,
71 &data->temp[0][1]);
72 }
73
74 if (data->sensorsp & SEL_CORE) {
75 tmp &= ~SEL_PLACE; /* Select sensor 0, core1 */
76 tmp |= SEL_CORE;
77 pci_write_config_byte(pdev, REG_TEMP, tmp);
78 pci_read_config_dword(pdev, REG_TEMP,
79 &data->temp[1][0]);
80
81 if (data->sensorsp & SEL_PLACE) {
82 tmp |= SEL_PLACE; /* Select sensor 1, core1 */
83 pci_write_config_byte(pdev, REG_TEMP, tmp);
84 pci_read_config_dword(pdev, REG_TEMP,
85 &data->temp[1][1]);
86 }
87 }
88
89 data->last_updated = jiffies;
90 data->valid = 1;
91 }
92
93 mutex_unlock(&data->update_lock);
94 return data;
95}
96
97/*
98 * Sysfs stuff
99 */
100
101static ssize_t show_name(struct device *dev, struct device_attribute
102 *devattr, char *buf)
103{
104 struct k8temp_data *data = dev_get_drvdata(dev);
105
106 return sprintf(buf, "%s\n", data->name);
107}
108
109
110static ssize_t show_temp(struct device *dev,
111 struct device_attribute *devattr, char *buf)
112{
113 struct sensor_device_attribute_2 *attr =
114 to_sensor_dev_attr_2(devattr);
115 int core = attr->nr;
116 int place = attr->index;
117 struct k8temp_data *data = k8temp_update_device(dev);
118
119 return sprintf(buf, "%d\n",
120 TEMP_FROM_REG(data->temp[core][place]));
121}
122
123/* core, place */
124
125static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
126static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1);
127static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 1, 0);
128static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 1, 1);
129static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
130
131static struct pci_device_id k8temp_ids[] = {
132 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
133 { 0 },
134};
135
136MODULE_DEVICE_TABLE(pci, k8temp_ids);
137
138static int __devinit k8temp_probe(struct pci_dev *pdev,
139 const struct pci_device_id *id)
140{
141 int err;
142 u8 scfg;
143 u32 temp;
144 struct k8temp_data *data;
145 u32 cpuid = cpuid_eax(1);
146
147 /* this feature should be available since SH-C0 core */
148 if ((cpuid == 0xf40) || (cpuid == 0xf50) || (cpuid == 0xf51)) {
149 err = -ENODEV;
150 goto exit;
151 }
152
153 if (!(data = kzalloc(sizeof(struct k8temp_data), GFP_KERNEL))) {
154 err = -ENOMEM;
155 goto exit;
156 }
157
158 pci_read_config_byte(pdev, REG_TEMP, &scfg);
159 scfg &= ~(SEL_PLACE | SEL_CORE); /* Select sensor 0, core0 */
160 pci_write_config_byte(pdev, REG_TEMP, scfg);
161 pci_read_config_byte(pdev, REG_TEMP, &scfg);
162
163 if (scfg & (SEL_PLACE | SEL_CORE)) {
164 dev_err(&pdev->dev, "Configuration bit(s) stuck at 1!\n");
165 err = -ENODEV;
166 goto exit_free;
167 }
168
169 scfg |= (SEL_PLACE | SEL_CORE);
170 pci_write_config_byte(pdev, REG_TEMP, scfg);
171
172 /* now we know if we can change core and/or sensor */
173 pci_read_config_byte(pdev, REG_TEMP, &data->sensorsp);
174
175 if (data->sensorsp & SEL_PLACE) {
176 scfg &= ~SEL_CORE; /* Select sensor 1, core0 */
177 pci_write_config_byte(pdev, REG_TEMP, scfg);
178 pci_read_config_dword(pdev, REG_TEMP, &temp);
179 scfg |= SEL_CORE; /* prepare for next selection */
180 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */
181 data->sensorsp &= ~SEL_PLACE;
182 }
183
184 if (data->sensorsp & SEL_CORE) {
185 scfg &= ~SEL_PLACE; /* Select sensor 0, core1 */
186 pci_write_config_byte(pdev, REG_TEMP, scfg);
187 pci_read_config_dword(pdev, REG_TEMP, &temp);
188 if (!((temp >> 16) & 0xff)) /* if temp is 0 -49C is not likely */
189 data->sensorsp &= ~SEL_CORE;
190 }
191
192 data->name = "k8temp";
193 mutex_init(&data->update_lock);
194 dev_set_drvdata(&pdev->dev, data);
195
196 /* Register sysfs hooks */
197 err = device_create_file(&pdev->dev,
198 &sensor_dev_attr_temp1_input.dev_attr);
199 if (err)
200 goto exit_remove;
201
202 /* sensor can be changed and reports something */
203 if (data->sensorsp & SEL_PLACE) {
204 err = device_create_file(&pdev->dev,
205 &sensor_dev_attr_temp2_input.dev_attr);
206 if (err)
207 goto exit_remove;
208 }
209
210 /* core can be changed and reports something */
211 if (data->sensorsp & SEL_CORE) {
212 err = device_create_file(&pdev->dev,
213 &sensor_dev_attr_temp3_input.dev_attr);
214 if (err)
215 goto exit_remove;
216 if (data->sensorsp & SEL_PLACE)
217 err = device_create_file(&pdev->dev,
218 &sensor_dev_attr_temp4_input.
219 dev_attr);
220 if (err)
221 goto exit_remove;
222 }
223
224 err = device_create_file(&pdev->dev, &dev_attr_name);
225 if (err)
226 goto exit_remove;
227
228 data->class_dev = hwmon_device_register(&pdev->dev);
229
230 if (IS_ERR(data->class_dev)) {
231 err = PTR_ERR(data->class_dev);
232 goto exit_remove;
233 }
234
235 return 0;
236
237exit_remove:
238 device_remove_file(&pdev->dev,
239 &sensor_dev_attr_temp1_input.dev_attr);
240 device_remove_file(&pdev->dev,
241 &sensor_dev_attr_temp2_input.dev_attr);
242 device_remove_file(&pdev->dev,
243 &sensor_dev_attr_temp3_input.dev_attr);
244 device_remove_file(&pdev->dev,
245 &sensor_dev_attr_temp4_input.dev_attr);
246 device_remove_file(&pdev->dev, &dev_attr_name);
247exit_free:
248 dev_set_drvdata(&pdev->dev, NULL);
249 kfree(data);
250exit:
251 return err;
252}
253
254static void __devexit k8temp_remove(struct pci_dev *pdev)
255{
256 struct k8temp_data *data = dev_get_drvdata(&pdev->dev);
257
258 hwmon_device_unregister(data->class_dev);
259 device_remove_file(&pdev->dev,
260 &sensor_dev_attr_temp1_input.dev_attr);
261 device_remove_file(&pdev->dev,
262 &sensor_dev_attr_temp2_input.dev_attr);
263 device_remove_file(&pdev->dev,
264 &sensor_dev_attr_temp3_input.dev_attr);
265 device_remove_file(&pdev->dev,
266 &sensor_dev_attr_temp4_input.dev_attr);
267 device_remove_file(&pdev->dev, &dev_attr_name);
268 dev_set_drvdata(&pdev->dev, NULL);
269 kfree(data);
270}
271
272static struct pci_driver k8temp_driver = {
273 .name = "k8temp",
274 .id_table = k8temp_ids,
275 .probe = k8temp_probe,
276 .remove = __devexit_p(k8temp_remove),
277};
278
279static int __init k8temp_init(void)
280{
281 return pci_register_driver(&k8temp_driver);
282}
283
284static void __exit k8temp_exit(void)
285{
286 pci_unregister_driver(&k8temp_driver);
287}
288
289MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>");
290MODULE_DESCRIPTION("AMD K8 core temperature monitor");
291MODULE_LICENSE("GPL");
292
293module_init(k8temp_init)
294module_exit(k8temp_exit)
diff --git a/drivers/hwmon/lm63.c b/drivers/hwmon/lm63.c
index 071f0fc6adec..d69f3cf07122 100644
--- a/drivers/hwmon/lm63.c
+++ b/drivers/hwmon/lm63.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor 2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control 3 * with integrated fan control
4 * Copyright (C) 2004-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2004-2006 Jean Delvare <khali@linux-fr.org>
5 * Based on the lm90 driver. 5 * Based on the lm90 driver.
6 * 6 *
7 * The LM63 is a sensor chip made by National Semiconductor. It measures 7 * The LM63 is a sensor chip made by National Semiconductor. It measures
@@ -46,6 +46,7 @@
46#include <linux/hwmon.h> 46#include <linux/hwmon.h>
47#include <linux/err.h> 47#include <linux/err.h>
48#include <linux/mutex.h> 48#include <linux/mutex.h>
49#include <linux/sysfs.h>
49 50
50/* 51/*
51 * Addresses to scan 52 * Addresses to scan
@@ -330,6 +331,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
330 return sprintf(buf, "%u\n", data->alarms); 331 return sprintf(buf, "%u\n", data->alarms);
331} 332}
332 333
334static ssize_t show_alarm(struct device *dev, struct device_attribute *devattr,
335 char *buf)
336{
337 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
338 struct lm63_data *data = lm63_update_device(dev);
339 int bitnr = attr->index;
340
341 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
342}
343
333static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0); 344static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
334static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan, 345static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan,
335 set_fan, 1); 346 set_fan, 1);
@@ -350,8 +361,52 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp8, NULL, 2);
350static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst, 361static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
351 set_temp2_crit_hyst); 362 set_temp2_crit_hyst);
352 363
364/* Individual alarm files */
365static SENSOR_DEVICE_ATTR(fan1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
366static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
367static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
368static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
369static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
370static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
371/* Raw alarm file for compatibility */
353static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 372static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
354 373
374static struct attribute *lm63_attributes[] = {
375 &dev_attr_pwm1.attr,
376 &dev_attr_pwm1_enable.attr,
377 &sensor_dev_attr_temp1_input.dev_attr.attr,
378 &sensor_dev_attr_temp2_input.dev_attr.attr,
379 &sensor_dev_attr_temp2_min.dev_attr.attr,
380 &sensor_dev_attr_temp1_max.dev_attr.attr,
381 &sensor_dev_attr_temp2_max.dev_attr.attr,
382 &sensor_dev_attr_temp2_crit.dev_attr.attr,
383 &dev_attr_temp2_crit_hyst.attr,
384
385 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
386 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
387 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
388 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
389 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
390 &dev_attr_alarms.attr,
391 NULL
392};
393
394static const struct attribute_group lm63_group = {
395 .attrs = lm63_attributes,
396};
397
398static struct attribute *lm63_attributes_fan1[] = {
399 &sensor_dev_attr_fan1_input.dev_attr.attr,
400 &sensor_dev_attr_fan1_min.dev_attr.attr,
401
402 &sensor_dev_attr_fan1_min_alarm.dev_attr.attr,
403 NULL
404};
405
406static const struct attribute_group lm63_group_fan1 = {
407 .attrs = lm63_attributes_fan1,
408};
409
355/* 410/*
356 * Real code 411 * Real code
357 */ 412 */
@@ -438,37 +493,26 @@ static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
438 lm63_init_client(new_client); 493 lm63_init_client(new_client);
439 494
440 /* Register sysfs hooks */ 495 /* Register sysfs hooks */
441 data->class_dev = hwmon_device_register(&new_client->dev); 496 if ((err = sysfs_create_group(&new_client->dev.kobj,
442 if (IS_ERR(data->class_dev)) { 497 &lm63_group)))
443 err = PTR_ERR(data->class_dev);
444 goto exit_detach; 498 goto exit_detach;
499 if (data->config & 0x04) { /* tachometer enabled */
500 if ((err = sysfs_create_group(&new_client->dev.kobj,
501 &lm63_group_fan1)))
502 goto exit_remove_files;
445 } 503 }
446 504
447 if (data->config & 0x04) { /* tachometer enabled */ 505 data->class_dev = hwmon_device_register(&new_client->dev);
448 device_create_file(&new_client->dev, 506 if (IS_ERR(data->class_dev)) {
449 &sensor_dev_attr_fan1_input.dev_attr); 507 err = PTR_ERR(data->class_dev);
450 device_create_file(&new_client->dev, 508 goto exit_remove_files;
451 &sensor_dev_attr_fan1_min.dev_attr);
452 } 509 }
453 device_create_file(&new_client->dev, &dev_attr_pwm1);
454 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
455 device_create_file(&new_client->dev,
456 &sensor_dev_attr_temp1_input.dev_attr);
457 device_create_file(&new_client->dev,
458 &sensor_dev_attr_temp2_input.dev_attr);
459 device_create_file(&new_client->dev,
460 &sensor_dev_attr_temp2_min.dev_attr);
461 device_create_file(&new_client->dev,
462 &sensor_dev_attr_temp1_max.dev_attr);
463 device_create_file(&new_client->dev,
464 &sensor_dev_attr_temp2_max.dev_attr);
465 device_create_file(&new_client->dev,
466 &sensor_dev_attr_temp2_crit.dev_attr);
467 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
468 device_create_file(&new_client->dev, &dev_attr_alarms);
469 510
470 return 0; 511 return 0;
471 512
513exit_remove_files:
514 sysfs_remove_group(&new_client->dev.kobj, &lm63_group);
515 sysfs_remove_group(&new_client->dev.kobj, &lm63_group_fan1);
472exit_detach: 516exit_detach:
473 i2c_detach_client(new_client); 517 i2c_detach_client(new_client);
474exit_free: 518exit_free:
@@ -518,6 +562,8 @@ static int lm63_detach_client(struct i2c_client *client)
518 int err; 562 int err;
519 563
520 hwmon_device_unregister(data->class_dev); 564 hwmon_device_unregister(data->class_dev);
565 sysfs_remove_group(&client->dev.kobj, &lm63_group);
566 sysfs_remove_group(&client->dev.kobj, &lm63_group_fan1);
521 567
522 if ((err = i2c_detach_client(client))) 568 if ((err = i2c_detach_client(client)))
523 return err; 569 return err;
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index fc25b90ec24a..7c65b8bb6d72 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -112,6 +112,18 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter)
112 return i2c_probe(adapter, &addr_data, lm75_detect); 112 return i2c_probe(adapter, &addr_data, lm75_detect);
113} 113}
114 114
115static struct attribute *lm75_attributes[] = {
116 &dev_attr_temp1_input.attr,
117 &dev_attr_temp1_max.attr,
118 &dev_attr_temp1_max_hyst.attr,
119
120 NULL
121};
122
123static const struct attribute_group lm75_group = {
124 .attrs = lm75_attributes,
125};
126
115/* This function is called by i2c_probe */ 127/* This function is called by i2c_probe */
116static int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 128static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
117{ 129{
@@ -199,18 +211,19 @@ static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
199 lm75_init_client(new_client); 211 lm75_init_client(new_client);
200 212
201 /* Register sysfs hooks */ 213 /* Register sysfs hooks */
214 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm75_group)))
215 goto exit_detach;
216
202 data->class_dev = hwmon_device_register(&new_client->dev); 217 data->class_dev = hwmon_device_register(&new_client->dev);
203 if (IS_ERR(data->class_dev)) { 218 if (IS_ERR(data->class_dev)) {
204 err = PTR_ERR(data->class_dev); 219 err = PTR_ERR(data->class_dev);
205 goto exit_detach; 220 goto exit_remove;
206 } 221 }
207 222
208 device_create_file(&new_client->dev, &dev_attr_temp1_max);
209 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
210 device_create_file(&new_client->dev, &dev_attr_temp1_input);
211
212 return 0; 223 return 0;
213 224
225exit_remove:
226 sysfs_remove_group(&new_client->dev.kobj, &lm75_group);
214exit_detach: 227exit_detach:
215 i2c_detach_client(new_client); 228 i2c_detach_client(new_client);
216exit_free: 229exit_free:
@@ -223,6 +236,7 @@ static int lm75_detach_client(struct i2c_client *client)
223{ 236{
224 struct lm75_data *data = i2c_get_clientdata(client); 237 struct lm75_data *data = i2c_get_clientdata(client);
225 hwmon_device_unregister(data->class_dev); 238 hwmon_device_unregister(data->class_dev);
239 sysfs_remove_group(&client->dev.kobj, &lm75_group);
226 i2c_detach_client(client); 240 i2c_detach_client(client);
227 kfree(data); 241 kfree(data);
228 return 0; 242 return 0;
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 459cc977380a..dd969f1e8415 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -212,6 +212,23 @@ static int lm77_attach_adapter(struct i2c_adapter *adapter)
212 return i2c_probe(adapter, &addr_data, lm77_detect); 212 return i2c_probe(adapter, &addr_data, lm77_detect);
213} 213}
214 214
215static struct attribute *lm77_attributes[] = {
216 &dev_attr_temp1_input.attr,
217 &dev_attr_temp1_crit.attr,
218 &dev_attr_temp1_min.attr,
219 &dev_attr_temp1_max.attr,
220 &dev_attr_temp1_crit_hyst.attr,
221 &dev_attr_temp1_min_hyst.attr,
222 &dev_attr_temp1_max_hyst.attr,
223 &dev_attr_alarms.attr,
224
225 NULL
226};
227
228static const struct attribute_group lm77_group = {
229 .attrs = lm77_attributes,
230};
231
215/* This function is called by i2c_probe */ 232/* This function is called by i2c_probe */
216static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) 233static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
217{ 234{
@@ -317,22 +334,19 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
317 lm77_init_client(new_client); 334 lm77_init_client(new_client);
318 335
319 /* Register sysfs hooks */ 336 /* Register sysfs hooks */
337 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group)))
338 goto exit_detach;
339
320 data->class_dev = hwmon_device_register(&new_client->dev); 340 data->class_dev = hwmon_device_register(&new_client->dev);
321 if (IS_ERR(data->class_dev)) { 341 if (IS_ERR(data->class_dev)) {
322 err = PTR_ERR(data->class_dev); 342 err = PTR_ERR(data->class_dev);
323 goto exit_detach; 343 goto exit_remove;
324 } 344 }
325 345
326 device_create_file(&new_client->dev, &dev_attr_temp1_input);
327 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
328 device_create_file(&new_client->dev, &dev_attr_temp1_min);
329 device_create_file(&new_client->dev, &dev_attr_temp1_max);
330 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
331 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
332 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
333 device_create_file(&new_client->dev, &dev_attr_alarms);
334 return 0; 346 return 0;
335 347
348exit_remove:
349 sysfs_remove_group(&new_client->dev.kobj, &lm77_group);
336exit_detach: 350exit_detach:
337 i2c_detach_client(new_client); 351 i2c_detach_client(new_client);
338exit_free: 352exit_free:
@@ -345,6 +359,7 @@ static int lm77_detach_client(struct i2c_client *client)
345{ 359{
346 struct lm77_data *data = i2c_get_clientdata(client); 360 struct lm77_data *data = i2c_get_clientdata(client);
347 hwmon_device_unregister(data->class_dev); 361 hwmon_device_unregister(data->class_dev);
362 sysfs_remove_group(&client->dev.kobj, &lm77_group);
348 i2c_detach_client(client); 363 i2c_detach_client(client);
349 kfree(data); 364 kfree(data);
350 return 0; 365 return 0;
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index fa1715b9a996..ac1b746df6d0 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -482,6 +482,50 @@ static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
482 return lm78_detect(adapter, isa_address, -1); 482 return lm78_detect(adapter, isa_address, -1);
483} 483}
484 484
485static struct attribute *lm78_attributes[] = {
486 &dev_attr_in0_input.attr,
487 &dev_attr_in0_min.attr,
488 &dev_attr_in0_max.attr,
489 &dev_attr_in1_input.attr,
490 &dev_attr_in1_min.attr,
491 &dev_attr_in1_max.attr,
492 &dev_attr_in2_input.attr,
493 &dev_attr_in2_min.attr,
494 &dev_attr_in2_max.attr,
495 &dev_attr_in3_input.attr,
496 &dev_attr_in3_min.attr,
497 &dev_attr_in3_max.attr,
498 &dev_attr_in4_input.attr,
499 &dev_attr_in4_min.attr,
500 &dev_attr_in4_max.attr,
501 &dev_attr_in5_input.attr,
502 &dev_attr_in5_min.attr,
503 &dev_attr_in5_max.attr,
504 &dev_attr_in6_input.attr,
505 &dev_attr_in6_min.attr,
506 &dev_attr_in6_max.attr,
507 &dev_attr_temp1_input.attr,
508 &dev_attr_temp1_max.attr,
509 &dev_attr_temp1_max_hyst.attr,
510 &dev_attr_fan1_input.attr,
511 &dev_attr_fan1_min.attr,
512 &dev_attr_fan1_div.attr,
513 &dev_attr_fan2_input.attr,
514 &dev_attr_fan2_min.attr,
515 &dev_attr_fan2_div.attr,
516 &dev_attr_fan3_input.attr,
517 &dev_attr_fan3_min.attr,
518 &dev_attr_fan3_div.attr,
519 &dev_attr_alarms.attr,
520 &dev_attr_cpu0_vid.attr,
521
522 NULL
523};
524
525static const struct attribute_group lm78_group = {
526 .attrs = lm78_attributes,
527};
528
485/* This function is called by i2c_probe */ 529/* This function is called by i2c_probe */
486static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 530static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
487{ 531{
@@ -616,50 +660,19 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
616 } 660 }
617 661
618 /* Register sysfs hooks */ 662 /* Register sysfs hooks */
663 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group)))
664 goto ERROR3;
665
619 data->class_dev = hwmon_device_register(&new_client->dev); 666 data->class_dev = hwmon_device_register(&new_client->dev);
620 if (IS_ERR(data->class_dev)) { 667 if (IS_ERR(data->class_dev)) {
621 err = PTR_ERR(data->class_dev); 668 err = PTR_ERR(data->class_dev);
622 goto ERROR3; 669 goto ERROR4;
623 } 670 }
624 671
625 device_create_file(&new_client->dev, &dev_attr_in0_input);
626 device_create_file(&new_client->dev, &dev_attr_in0_min);
627 device_create_file(&new_client->dev, &dev_attr_in0_max);
628 device_create_file(&new_client->dev, &dev_attr_in1_input);
629 device_create_file(&new_client->dev, &dev_attr_in1_min);
630 device_create_file(&new_client->dev, &dev_attr_in1_max);
631 device_create_file(&new_client->dev, &dev_attr_in2_input);
632 device_create_file(&new_client->dev, &dev_attr_in2_min);
633 device_create_file(&new_client->dev, &dev_attr_in2_max);
634 device_create_file(&new_client->dev, &dev_attr_in3_input);
635 device_create_file(&new_client->dev, &dev_attr_in3_min);
636 device_create_file(&new_client->dev, &dev_attr_in3_max);
637 device_create_file(&new_client->dev, &dev_attr_in4_input);
638 device_create_file(&new_client->dev, &dev_attr_in4_min);
639 device_create_file(&new_client->dev, &dev_attr_in4_max);
640 device_create_file(&new_client->dev, &dev_attr_in5_input);
641 device_create_file(&new_client->dev, &dev_attr_in5_min);
642 device_create_file(&new_client->dev, &dev_attr_in5_max);
643 device_create_file(&new_client->dev, &dev_attr_in6_input);
644 device_create_file(&new_client->dev, &dev_attr_in6_min);
645 device_create_file(&new_client->dev, &dev_attr_in6_max);
646 device_create_file(&new_client->dev, &dev_attr_temp1_input);
647 device_create_file(&new_client->dev, &dev_attr_temp1_max);
648 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
649 device_create_file(&new_client->dev, &dev_attr_fan1_input);
650 device_create_file(&new_client->dev, &dev_attr_fan1_min);
651 device_create_file(&new_client->dev, &dev_attr_fan1_div);
652 device_create_file(&new_client->dev, &dev_attr_fan2_input);
653 device_create_file(&new_client->dev, &dev_attr_fan2_min);
654 device_create_file(&new_client->dev, &dev_attr_fan2_div);
655 device_create_file(&new_client->dev, &dev_attr_fan3_input);
656 device_create_file(&new_client->dev, &dev_attr_fan3_min);
657 device_create_file(&new_client->dev, &dev_attr_fan3_div);
658 device_create_file(&new_client->dev, &dev_attr_alarms);
659 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
660
661 return 0; 672 return 0;
662 673
674ERROR4:
675 sysfs_remove_group(&new_client->dev.kobj, &lm78_group);
663ERROR3: 676ERROR3:
664 i2c_detach_client(new_client); 677 i2c_detach_client(new_client);
665ERROR2: 678ERROR2:
@@ -677,6 +690,7 @@ static int lm78_detach_client(struct i2c_client *client)
677 int err; 690 int err;
678 691
679 hwmon_device_unregister(data->class_dev); 692 hwmon_device_unregister(data->class_dev);
693 sysfs_remove_group(&client->dev.kobj, &lm78_group);
680 694
681 if ((err = i2c_detach_client(client))) 695 if ((err = i2c_detach_client(client)))
682 return err; 696 return err;
diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c
index b4ccdfc01203..064516d824ad 100644
--- a/drivers/hwmon/lm80.c
+++ b/drivers/hwmon/lm80.c
@@ -394,6 +394,48 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
394 return i2c_probe(adapter, &addr_data, lm80_detect); 394 return i2c_probe(adapter, &addr_data, lm80_detect);
395} 395}
396 396
397static struct attribute *lm80_attributes[] = {
398 &dev_attr_in0_min.attr,
399 &dev_attr_in1_min.attr,
400 &dev_attr_in2_min.attr,
401 &dev_attr_in3_min.attr,
402 &dev_attr_in4_min.attr,
403 &dev_attr_in5_min.attr,
404 &dev_attr_in6_min.attr,
405 &dev_attr_in0_max.attr,
406 &dev_attr_in1_max.attr,
407 &dev_attr_in2_max.attr,
408 &dev_attr_in3_max.attr,
409 &dev_attr_in4_max.attr,
410 &dev_attr_in5_max.attr,
411 &dev_attr_in6_max.attr,
412 &dev_attr_in0_input.attr,
413 &dev_attr_in1_input.attr,
414 &dev_attr_in2_input.attr,
415 &dev_attr_in3_input.attr,
416 &dev_attr_in4_input.attr,
417 &dev_attr_in5_input.attr,
418 &dev_attr_in6_input.attr,
419 &dev_attr_fan1_min.attr,
420 &dev_attr_fan2_min.attr,
421 &dev_attr_fan1_input.attr,
422 &dev_attr_fan2_input.attr,
423 &dev_attr_fan1_div.attr,
424 &dev_attr_fan2_div.attr,
425 &dev_attr_temp1_input.attr,
426 &dev_attr_temp1_max.attr,
427 &dev_attr_temp1_max_hyst.attr,
428 &dev_attr_temp1_crit.attr,
429 &dev_attr_temp1_crit_hyst.attr,
430 &dev_attr_alarms.attr,
431
432 NULL
433};
434
435static const struct attribute_group lm80_group = {
436 .attrs = lm80_attributes,
437};
438
397static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) 439static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
398{ 440{
399 int i, cur; 441 int i, cur;
@@ -452,48 +494,19 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
452 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2)); 494 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
453 495
454 /* Register sysfs hooks */ 496 /* Register sysfs hooks */
497 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm80_group)))
498 goto error_detach;
499
455 data->class_dev = hwmon_device_register(&new_client->dev); 500 data->class_dev = hwmon_device_register(&new_client->dev);
456 if (IS_ERR(data->class_dev)) { 501 if (IS_ERR(data->class_dev)) {
457 err = PTR_ERR(data->class_dev); 502 err = PTR_ERR(data->class_dev);
458 goto error_detach; 503 goto error_remove;
459 } 504 }
460 505
461 device_create_file(&new_client->dev, &dev_attr_in0_min);
462 device_create_file(&new_client->dev, &dev_attr_in1_min);
463 device_create_file(&new_client->dev, &dev_attr_in2_min);
464 device_create_file(&new_client->dev, &dev_attr_in3_min);
465 device_create_file(&new_client->dev, &dev_attr_in4_min);
466 device_create_file(&new_client->dev, &dev_attr_in5_min);
467 device_create_file(&new_client->dev, &dev_attr_in6_min);
468 device_create_file(&new_client->dev, &dev_attr_in0_max);
469 device_create_file(&new_client->dev, &dev_attr_in1_max);
470 device_create_file(&new_client->dev, &dev_attr_in2_max);
471 device_create_file(&new_client->dev, &dev_attr_in3_max);
472 device_create_file(&new_client->dev, &dev_attr_in4_max);
473 device_create_file(&new_client->dev, &dev_attr_in5_max);
474 device_create_file(&new_client->dev, &dev_attr_in6_max);
475 device_create_file(&new_client->dev, &dev_attr_in0_input);
476 device_create_file(&new_client->dev, &dev_attr_in1_input);
477 device_create_file(&new_client->dev, &dev_attr_in2_input);
478 device_create_file(&new_client->dev, &dev_attr_in3_input);
479 device_create_file(&new_client->dev, &dev_attr_in4_input);
480 device_create_file(&new_client->dev, &dev_attr_in5_input);
481 device_create_file(&new_client->dev, &dev_attr_in6_input);
482 device_create_file(&new_client->dev, &dev_attr_fan1_min);
483 device_create_file(&new_client->dev, &dev_attr_fan2_min);
484 device_create_file(&new_client->dev, &dev_attr_fan1_input);
485 device_create_file(&new_client->dev, &dev_attr_fan2_input);
486 device_create_file(&new_client->dev, &dev_attr_fan1_div);
487 device_create_file(&new_client->dev, &dev_attr_fan2_div);
488 device_create_file(&new_client->dev, &dev_attr_temp1_input);
489 device_create_file(&new_client->dev, &dev_attr_temp1_max);
490 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
491 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
492 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
493 device_create_file(&new_client->dev, &dev_attr_alarms);
494
495 return 0; 506 return 0;
496 507
508error_remove:
509 sysfs_remove_group(&new_client->dev.kobj, &lm80_group);
497error_detach: 510error_detach:
498 i2c_detach_client(new_client); 511 i2c_detach_client(new_client);
499error_free: 512error_free:
@@ -508,7 +521,7 @@ static int lm80_detach_client(struct i2c_client *client)
508 int err; 521 int err;
509 522
510 hwmon_device_unregister(data->class_dev); 523 hwmon_device_unregister(data->class_dev);
511 524 sysfs_remove_group(&client->dev.kobj, &lm80_group);
512 if ((err = i2c_detach_client(client))) 525 if ((err = i2c_detach_client(client)))
513 return err; 526 return err;
514 527
diff --git a/drivers/hwmon/lm83.c b/drivers/hwmon/lm83.c
index 2137d7879df6..feb87b41e986 100644
--- a/drivers/hwmon/lm83.c
+++ b/drivers/hwmon/lm83.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is 6 * Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
7 * a sensor chip made by National Semiconductor. It reports up to four 7 * a sensor chip made by National Semiconductor. It reports up to four
@@ -40,6 +40,7 @@
40#include <linux/hwmon.h> 40#include <linux/hwmon.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/sysfs.h>
43 44
44/* 45/*
45 * Addresses to scan 46 * Addresses to scan
@@ -191,6 +192,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
191 return sprintf(buf, "%d\n", data->alarms); 192 return sprintf(buf, "%d\n", data->alarms);
192} 193}
193 194
195static ssize_t show_alarm(struct device *dev, struct device_attribute
196 *devattr, char *buf)
197{
198 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
199 struct lm83_data *data = lm83_update_device(dev);
200 int bitnr = attr->index;
201
202 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
203}
204
194static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); 205static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
195static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); 206static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
196static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); 207static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
@@ -208,8 +219,64 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp, NULL, 8);
208static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp, 219static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp,
209 set_temp, 8); 220 set_temp, 8);
210static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8); 221static SENSOR_DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp, NULL, 8);
222
223/* Individual alarm files */
224static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
225static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
226static SENSOR_DEVICE_ATTR(temp3_input_fault, S_IRUGO, show_alarm, NULL, 2);
227static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 4);
228static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
229static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8);
230static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
231static SENSOR_DEVICE_ATTR(temp4_input_fault, S_IRUGO, show_alarm, NULL, 10);
232static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 12);
233static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 13);
234static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 15);
235/* Raw alarm file for compatibility */
211static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 236static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
212 237
238static struct attribute *lm83_attributes[] = {
239 &sensor_dev_attr_temp1_input.dev_attr.attr,
240 &sensor_dev_attr_temp3_input.dev_attr.attr,
241 &sensor_dev_attr_temp1_max.dev_attr.attr,
242 &sensor_dev_attr_temp3_max.dev_attr.attr,
243 &sensor_dev_attr_temp1_crit.dev_attr.attr,
244 &sensor_dev_attr_temp3_crit.dev_attr.attr,
245
246 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
247 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
248 &sensor_dev_attr_temp3_input_fault.dev_attr.attr,
249 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
250 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
251 &dev_attr_alarms.attr,
252 NULL
253};
254
255static const struct attribute_group lm83_group = {
256 .attrs = lm83_attributes,
257};
258
259static struct attribute *lm83_attributes_opt[] = {
260 &sensor_dev_attr_temp2_input.dev_attr.attr,
261 &sensor_dev_attr_temp4_input.dev_attr.attr,
262 &sensor_dev_attr_temp2_max.dev_attr.attr,
263 &sensor_dev_attr_temp4_max.dev_attr.attr,
264 &sensor_dev_attr_temp2_crit.dev_attr.attr,
265 &sensor_dev_attr_temp4_crit.dev_attr.attr,
266
267 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
268 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
269 &sensor_dev_attr_temp4_input_fault.dev_attr.attr,
270 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
271 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
272 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
273 NULL
274};
275
276static const struct attribute_group lm83_group_opt = {
277 .attrs = lm83_attributes_opt,
278};
279
213/* 280/*
214 * Real code 281 * Real code
215 */ 282 */
@@ -318,59 +385,32 @@ static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
318 goto exit_free; 385 goto exit_free;
319 386
320 /* 387 /*
321 * Initialize the LM83 chip 388 * Register sysfs hooks
322 * (Nothing to do for this one.)
323 */
324
325 /* Register sysfs hooks */
326 data->class_dev = hwmon_device_register(&new_client->dev);
327 if (IS_ERR(data->class_dev)) {
328 err = PTR_ERR(data->class_dev);
329 goto exit_detach;
330 }
331
332 /*
333 * The LM82 can only monitor one external diode which is 389 * The LM82 can only monitor one external diode which is
334 * at the same register as the LM83 temp3 entry - so we 390 * at the same register as the LM83 temp3 entry - so we
335 * declare 1 and 3 common, and then 2 and 4 only for the LM83. 391 * declare 1 and 3 common, and then 2 and 4 only for the LM83.
336 */ 392 */
337 393
338 device_create_file(&new_client->dev, 394 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm83_group)))
339 &sensor_dev_attr_temp1_input.dev_attr); 395 goto exit_detach;
340 device_create_file(&new_client->dev,
341 &sensor_dev_attr_temp3_input.dev_attr);
342
343 device_create_file(&new_client->dev,
344 &sensor_dev_attr_temp1_max.dev_attr);
345 device_create_file(&new_client->dev,
346 &sensor_dev_attr_temp3_max.dev_attr);
347
348 device_create_file(&new_client->dev,
349 &sensor_dev_attr_temp1_crit.dev_attr);
350 device_create_file(&new_client->dev,
351 &sensor_dev_attr_temp3_crit.dev_attr);
352
353 device_create_file(&new_client->dev, &dev_attr_alarms);
354 396
355 if (kind == lm83) { 397 if (kind == lm83) {
356 device_create_file(&new_client->dev, 398 if ((err = sysfs_create_group(&new_client->dev.kobj,
357 &sensor_dev_attr_temp2_input.dev_attr); 399 &lm83_group_opt)))
358 device_create_file(&new_client->dev, 400 goto exit_remove_files;
359 &sensor_dev_attr_temp4_input.dev_attr); 401 }
360 402
361 device_create_file(&new_client->dev, 403 data->class_dev = hwmon_device_register(&new_client->dev);
362 &sensor_dev_attr_temp2_max.dev_attr); 404 if (IS_ERR(data->class_dev)) {
363 device_create_file(&new_client->dev, 405 err = PTR_ERR(data->class_dev);
364 &sensor_dev_attr_temp4_max.dev_attr); 406 goto exit_remove_files;
365
366 device_create_file(&new_client->dev,
367 &sensor_dev_attr_temp2_crit.dev_attr);
368 device_create_file(&new_client->dev,
369 &sensor_dev_attr_temp4_crit.dev_attr);
370 } 407 }
371 408
372 return 0; 409 return 0;
373 410
411exit_remove_files:
412 sysfs_remove_group(&new_client->dev.kobj, &lm83_group);
413 sysfs_remove_group(&new_client->dev.kobj, &lm83_group_opt);
374exit_detach: 414exit_detach:
375 i2c_detach_client(new_client); 415 i2c_detach_client(new_client);
376exit_free: 416exit_free:
@@ -385,6 +425,8 @@ static int lm83_detach_client(struct i2c_client *client)
385 int err; 425 int err;
386 426
387 hwmon_device_unregister(data->class_dev); 427 hwmon_device_unregister(data->class_dev);
428 sysfs_remove_group(&client->dev.kobj, &lm83_group);
429 sysfs_remove_group(&client->dev.kobj, &lm83_group_opt);
388 430
389 if ((err = i2c_detach_client(client))) 431 if ((err = i2c_detach_client(client)))
390 return err; 432 return err;
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index 342e9663119d..2c3293cf69d1 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -1025,6 +1025,89 @@ static int lm85_attach_adapter(struct i2c_adapter *adapter)
1025 return i2c_probe(adapter, &addr_data, lm85_detect); 1025 return i2c_probe(adapter, &addr_data, lm85_detect);
1026} 1026}
1027 1027
1028static struct attribute *lm85_attributes[] = {
1029 &dev_attr_fan1_input.attr,
1030 &dev_attr_fan2_input.attr,
1031 &dev_attr_fan3_input.attr,
1032 &dev_attr_fan4_input.attr,
1033 &dev_attr_fan1_min.attr,
1034 &dev_attr_fan2_min.attr,
1035 &dev_attr_fan3_min.attr,
1036 &dev_attr_fan4_min.attr,
1037 &dev_attr_pwm1.attr,
1038 &dev_attr_pwm2.attr,
1039 &dev_attr_pwm3.attr,
1040 &dev_attr_pwm1_enable.attr,
1041 &dev_attr_pwm2_enable.attr,
1042 &dev_attr_pwm3_enable.attr,
1043 &dev_attr_in0_input.attr,
1044 &dev_attr_in1_input.attr,
1045 &dev_attr_in2_input.attr,
1046 &dev_attr_in3_input.attr,
1047 &dev_attr_in0_min.attr,
1048 &dev_attr_in1_min.attr,
1049 &dev_attr_in2_min.attr,
1050 &dev_attr_in3_min.attr,
1051 &dev_attr_in0_max.attr,
1052 &dev_attr_in1_max.attr,
1053 &dev_attr_in2_max.attr,
1054 &dev_attr_in3_max.attr,
1055 &dev_attr_temp1_input.attr,
1056 &dev_attr_temp2_input.attr,
1057 &dev_attr_temp3_input.attr,
1058 &dev_attr_temp1_min.attr,
1059 &dev_attr_temp2_min.attr,
1060 &dev_attr_temp3_min.attr,
1061 &dev_attr_temp1_max.attr,
1062 &dev_attr_temp2_max.attr,
1063 &dev_attr_temp3_max.attr,
1064 &dev_attr_vrm.attr,
1065 &dev_attr_cpu0_vid.attr,
1066 &dev_attr_alarms.attr,
1067 &dev_attr_pwm1_auto_channels.attr,
1068 &dev_attr_pwm2_auto_channels.attr,
1069 &dev_attr_pwm3_auto_channels.attr,
1070 &dev_attr_pwm1_auto_pwm_min.attr,
1071 &dev_attr_pwm2_auto_pwm_min.attr,
1072 &dev_attr_pwm3_auto_pwm_min.attr,
1073 &dev_attr_pwm1_auto_pwm_minctl.attr,
1074 &dev_attr_pwm2_auto_pwm_minctl.attr,
1075 &dev_attr_pwm3_auto_pwm_minctl.attr,
1076 &dev_attr_pwm1_auto_pwm_freq.attr,
1077 &dev_attr_pwm2_auto_pwm_freq.attr,
1078 &dev_attr_pwm3_auto_pwm_freq.attr,
1079 &dev_attr_temp1_auto_temp_off.attr,
1080 &dev_attr_temp2_auto_temp_off.attr,
1081 &dev_attr_temp3_auto_temp_off.attr,
1082 &dev_attr_temp1_auto_temp_min.attr,
1083 &dev_attr_temp2_auto_temp_min.attr,
1084 &dev_attr_temp3_auto_temp_min.attr,
1085 &dev_attr_temp1_auto_temp_max.attr,
1086 &dev_attr_temp2_auto_temp_max.attr,
1087 &dev_attr_temp3_auto_temp_max.attr,
1088 &dev_attr_temp1_auto_temp_crit.attr,
1089 &dev_attr_temp2_auto_temp_crit.attr,
1090 &dev_attr_temp3_auto_temp_crit.attr,
1091
1092 NULL
1093};
1094
1095static const struct attribute_group lm85_group = {
1096 .attrs = lm85_attributes,
1097};
1098
1099static struct attribute *lm85_attributes_opt[] = {
1100 &dev_attr_in4_input.attr,
1101 &dev_attr_in4_min.attr,
1102 &dev_attr_in4_max.attr,
1103
1104 NULL
1105};
1106
1107static const struct attribute_group lm85_group_opt = {
1108 .attrs = lm85_attributes_opt,
1109};
1110
1028static int lm85_detect(struct i2c_adapter *adapter, int address, 1111static int lm85_detect(struct i2c_adapter *adapter, int address,
1029 int kind) 1112 int kind)
1030{ 1113{
@@ -1163,87 +1246,33 @@ static int lm85_detect(struct i2c_adapter *adapter, int address,
1163 lm85_init_client(new_client); 1246 lm85_init_client(new_client);
1164 1247
1165 /* Register sysfs hooks */ 1248 /* Register sysfs hooks */
1166 data->class_dev = hwmon_device_register(&new_client->dev); 1249 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm85_group)))
1167 if (IS_ERR(data->class_dev)) {
1168 err = PTR_ERR(data->class_dev);
1169 goto ERROR2; 1250 goto ERROR2;
1170 }
1171
1172 device_create_file(&new_client->dev, &dev_attr_fan1_input);
1173 device_create_file(&new_client->dev, &dev_attr_fan2_input);
1174 device_create_file(&new_client->dev, &dev_attr_fan3_input);
1175 device_create_file(&new_client->dev, &dev_attr_fan4_input);
1176 device_create_file(&new_client->dev, &dev_attr_fan1_min);
1177 device_create_file(&new_client->dev, &dev_attr_fan2_min);
1178 device_create_file(&new_client->dev, &dev_attr_fan3_min);
1179 device_create_file(&new_client->dev, &dev_attr_fan4_min);
1180 device_create_file(&new_client->dev, &dev_attr_pwm1);
1181 device_create_file(&new_client->dev, &dev_attr_pwm2);
1182 device_create_file(&new_client->dev, &dev_attr_pwm3);
1183 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1184 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1185 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1186 device_create_file(&new_client->dev, &dev_attr_in0_input);
1187 device_create_file(&new_client->dev, &dev_attr_in1_input);
1188 device_create_file(&new_client->dev, &dev_attr_in2_input);
1189 device_create_file(&new_client->dev, &dev_attr_in3_input);
1190 device_create_file(&new_client->dev, &dev_attr_in0_min);
1191 device_create_file(&new_client->dev, &dev_attr_in1_min);
1192 device_create_file(&new_client->dev, &dev_attr_in2_min);
1193 device_create_file(&new_client->dev, &dev_attr_in3_min);
1194 device_create_file(&new_client->dev, &dev_attr_in0_max);
1195 device_create_file(&new_client->dev, &dev_attr_in1_max);
1196 device_create_file(&new_client->dev, &dev_attr_in2_max);
1197 device_create_file(&new_client->dev, &dev_attr_in3_max);
1198 device_create_file(&new_client->dev, &dev_attr_temp1_input);
1199 device_create_file(&new_client->dev, &dev_attr_temp2_input);
1200 device_create_file(&new_client->dev, &dev_attr_temp3_input);
1201 device_create_file(&new_client->dev, &dev_attr_temp1_min);
1202 device_create_file(&new_client->dev, &dev_attr_temp2_min);
1203 device_create_file(&new_client->dev, &dev_attr_temp3_min);
1204 device_create_file(&new_client->dev, &dev_attr_temp1_max);
1205 device_create_file(&new_client->dev, &dev_attr_temp2_max);
1206 device_create_file(&new_client->dev, &dev_attr_temp3_max);
1207 device_create_file(&new_client->dev, &dev_attr_vrm);
1208 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
1209 device_create_file(&new_client->dev, &dev_attr_alarms);
1210 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_channels);
1211 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_channels);
1212 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_channels);
1213 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
1214 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_min);
1215 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_min);
1216 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_minctl);
1217 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_minctl);
1218 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_minctl);
1219 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_freq);
1220 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_freq);
1221 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_freq);
1222 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_off);
1223 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_off);
1224 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_off);
1225 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_min);
1226 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_min);
1227 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_min);
1228 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_max);
1229 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_max);
1230 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_max);
1231 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_crit);
1232 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_crit);
1233 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_crit);
1234 1251
1235 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used 1252 /* The ADT7463 has an optional VRM 10 mode where pin 21 is used
1236 as a sixth digital VID input rather than an analog input. */ 1253 as a sixth digital VID input rather than an analog input. */
1237 data->vid = lm85_read_value(new_client, LM85_REG_VID); 1254 data->vid = lm85_read_value(new_client, LM85_REG_VID);
1238 if (!(kind == adt7463 && (data->vid & 0x80))) { 1255 if (!(kind == adt7463 && (data->vid & 0x80)))
1239 device_create_file(&new_client->dev, &dev_attr_in4_input); 1256 if ((err = device_create_file(&new_client->dev,
1240 device_create_file(&new_client->dev, &dev_attr_in4_min); 1257 &dev_attr_in4_input))
1241 device_create_file(&new_client->dev, &dev_attr_in4_max); 1258 || (err = device_create_file(&new_client->dev,
1259 &dev_attr_in4_min))
1260 || (err = device_create_file(&new_client->dev,
1261 &dev_attr_in4_max)))
1262 goto ERROR3;
1263
1264 data->class_dev = hwmon_device_register(&new_client->dev);
1265 if (IS_ERR(data->class_dev)) {
1266 err = PTR_ERR(data->class_dev);
1267 goto ERROR3;
1242 } 1268 }
1243 1269
1244 return 0; 1270 return 0;
1245 1271
1246 /* Error out and cleanup code */ 1272 /* Error out and cleanup code */
1273 ERROR3:
1274 sysfs_remove_group(&new_client->dev.kobj, &lm85_group);
1275 sysfs_remove_group(&new_client->dev.kobj, &lm85_group_opt);
1247 ERROR2: 1276 ERROR2:
1248 i2c_detach_client(new_client); 1277 i2c_detach_client(new_client);
1249 ERROR1: 1278 ERROR1:
@@ -1256,6 +1285,8 @@ static int lm85_detach_client(struct i2c_client *client)
1256{ 1285{
1257 struct lm85_data *data = i2c_get_clientdata(client); 1286 struct lm85_data *data = i2c_get_clientdata(client);
1258 hwmon_device_unregister(data->class_dev); 1287 hwmon_device_unregister(data->class_dev);
1288 sysfs_remove_group(&client->dev.kobj, &lm85_group);
1289 sysfs_remove_group(&client->dev.kobj, &lm85_group_opt);
1259 i2c_detach_client(client); 1290 i2c_detach_client(client);
1260 kfree(data); 1291 kfree(data);
1261 return 0; 1292 return 0;
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index e6c1b638c971..3ce825489e34 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -542,6 +542,78 @@ static int lm87_attach_adapter(struct i2c_adapter *adapter)
542 return i2c_probe(adapter, &addr_data, lm87_detect); 542 return i2c_probe(adapter, &addr_data, lm87_detect);
543} 543}
544 544
545static struct attribute *lm87_attributes[] = {
546 &dev_attr_in1_input.attr,
547 &dev_attr_in1_min.attr,
548 &dev_attr_in1_max.attr,
549 &dev_attr_in2_input.attr,
550 &dev_attr_in2_min.attr,
551 &dev_attr_in2_max.attr,
552 &dev_attr_in3_input.attr,
553 &dev_attr_in3_min.attr,
554 &dev_attr_in3_max.attr,
555 &dev_attr_in4_input.attr,
556 &dev_attr_in4_min.attr,
557 &dev_attr_in4_max.attr,
558
559 &dev_attr_temp1_input.attr,
560 &dev_attr_temp1_max.attr,
561 &dev_attr_temp1_min.attr,
562 &dev_attr_temp1_crit.attr,
563 &dev_attr_temp2_input.attr,
564 &dev_attr_temp2_max.attr,
565 &dev_attr_temp2_min.attr,
566 &dev_attr_temp2_crit.attr,
567
568 &dev_attr_alarms.attr,
569 &dev_attr_aout_output.attr,
570
571 NULL
572};
573
574static const struct attribute_group lm87_group = {
575 .attrs = lm87_attributes,
576};
577
578static struct attribute *lm87_attributes_opt[] = {
579 &dev_attr_in6_input.attr,
580 &dev_attr_in6_min.attr,
581 &dev_attr_in6_max.attr,
582
583 &dev_attr_fan1_input.attr,
584 &dev_attr_fan1_min.attr,
585 &dev_attr_fan1_div.attr,
586
587 &dev_attr_in7_input.attr,
588 &dev_attr_in7_min.attr,
589 &dev_attr_in7_max.attr,
590
591 &dev_attr_fan2_input.attr,
592 &dev_attr_fan2_min.attr,
593 &dev_attr_fan2_div.attr,
594
595 &dev_attr_temp3_input.attr,
596 &dev_attr_temp3_max.attr,
597 &dev_attr_temp3_min.attr,
598 &dev_attr_temp3_crit.attr,
599
600 &dev_attr_in0_input.attr,
601 &dev_attr_in0_min.attr,
602 &dev_attr_in0_max.attr,
603 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr,
606
607 &dev_attr_cpu0_vid.attr,
608 &dev_attr_vrm.attr,
609
610 NULL
611};
612
613static const struct attribute_group lm87_group_opt = {
614 .attrs = lm87_attributes_opt,
615};
616
545/* 617/*
546 * The following function does more than just detection. If detection 618 * The following function does more than just detection. If detection
547 * succeeds, it also registers the new chip. 619 * succeeds, it also registers the new chip.
@@ -609,77 +681,90 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
609 data->in_scale[7] = 1875; 681 data->in_scale[7] = 1875;
610 682
611 /* Register sysfs hooks */ 683 /* Register sysfs hooks */
612 data->class_dev = hwmon_device_register(&new_client->dev); 684 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm87_group)))
613 if (IS_ERR(data->class_dev)) {
614 err = PTR_ERR(data->class_dev);
615 goto exit_detach; 685 goto exit_detach;
616 }
617
618 device_create_file(&new_client->dev, &dev_attr_in1_input);
619 device_create_file(&new_client->dev, &dev_attr_in1_min);
620 device_create_file(&new_client->dev, &dev_attr_in1_max);
621 device_create_file(&new_client->dev, &dev_attr_in2_input);
622 device_create_file(&new_client->dev, &dev_attr_in2_min);
623 device_create_file(&new_client->dev, &dev_attr_in2_max);
624 device_create_file(&new_client->dev, &dev_attr_in3_input);
625 device_create_file(&new_client->dev, &dev_attr_in3_min);
626 device_create_file(&new_client->dev, &dev_attr_in3_max);
627 device_create_file(&new_client->dev, &dev_attr_in4_input);
628 device_create_file(&new_client->dev, &dev_attr_in4_min);
629 device_create_file(&new_client->dev, &dev_attr_in4_max);
630 686
631 if (data->channel & CHAN_NO_FAN(0)) { 687 if (data->channel & CHAN_NO_FAN(0)) {
632 device_create_file(&new_client->dev, &dev_attr_in6_input); 688 if ((err = device_create_file(&new_client->dev,
633 device_create_file(&new_client->dev, &dev_attr_in6_min); 689 &dev_attr_in6_input))
634 device_create_file(&new_client->dev, &dev_attr_in6_max); 690 || (err = device_create_file(&new_client->dev,
691 &dev_attr_in6_min))
692 || (err = device_create_file(&new_client->dev,
693 &dev_attr_in6_max)))
694 goto exit_remove;
635 } else { 695 } else {
636 device_create_file(&new_client->dev, &dev_attr_fan1_input); 696 if ((err = device_create_file(&new_client->dev,
637 device_create_file(&new_client->dev, &dev_attr_fan1_min); 697 &dev_attr_fan1_input))
638 device_create_file(&new_client->dev, &dev_attr_fan1_div); 698 || (err = device_create_file(&new_client->dev,
699 &dev_attr_fan1_min))
700 || (err = device_create_file(&new_client->dev,
701 &dev_attr_fan1_div)))
702 goto exit_remove;
639 } 703 }
704
640 if (data->channel & CHAN_NO_FAN(1)) { 705 if (data->channel & CHAN_NO_FAN(1)) {
641 device_create_file(&new_client->dev, &dev_attr_in7_input); 706 if ((err = device_create_file(&new_client->dev,
642 device_create_file(&new_client->dev, &dev_attr_in7_min); 707 &dev_attr_in7_input))
643 device_create_file(&new_client->dev, &dev_attr_in7_max); 708 || (err = device_create_file(&new_client->dev,
709 &dev_attr_in7_min))
710 || (err = device_create_file(&new_client->dev,
711 &dev_attr_in7_max)))
712 goto exit_remove;
644 } else { 713 } else {
645 device_create_file(&new_client->dev, &dev_attr_fan2_input); 714 if ((err = device_create_file(&new_client->dev,
646 device_create_file(&new_client->dev, &dev_attr_fan2_min); 715 &dev_attr_fan2_input))
647 device_create_file(&new_client->dev, &dev_attr_fan2_div); 716 || (err = device_create_file(&new_client->dev,
717 &dev_attr_fan2_min))
718 || (err = device_create_file(&new_client->dev,
719 &dev_attr_fan2_div)))
720 goto exit_remove;
648 } 721 }
649 722
650 device_create_file(&new_client->dev, &dev_attr_temp1_input);
651 device_create_file(&new_client->dev, &dev_attr_temp1_max);
652 device_create_file(&new_client->dev, &dev_attr_temp1_min);
653 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
654 device_create_file(&new_client->dev, &dev_attr_temp2_input);
655 device_create_file(&new_client->dev, &dev_attr_temp2_max);
656 device_create_file(&new_client->dev, &dev_attr_temp2_min);
657 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
658
659 if (data->channel & CHAN_TEMP3) { 723 if (data->channel & CHAN_TEMP3) {
660 device_create_file(&new_client->dev, &dev_attr_temp3_input); 724 if ((err = device_create_file(&new_client->dev,
661 device_create_file(&new_client->dev, &dev_attr_temp3_max); 725 &dev_attr_temp3_input))
662 device_create_file(&new_client->dev, &dev_attr_temp3_min); 726 || (err = device_create_file(&new_client->dev,
663 device_create_file(&new_client->dev, &dev_attr_temp3_crit); 727 &dev_attr_temp3_max))
728 || (err = device_create_file(&new_client->dev,
729 &dev_attr_temp3_min))
730 || (err = device_create_file(&new_client->dev,
731 &dev_attr_temp3_crit)))
732 goto exit_remove;
664 } else { 733 } else {
665 device_create_file(&new_client->dev, &dev_attr_in0_input); 734 if ((err = device_create_file(&new_client->dev,
666 device_create_file(&new_client->dev, &dev_attr_in0_min); 735 &dev_attr_in0_input))
667 device_create_file(&new_client->dev, &dev_attr_in0_max); 736 || (err = device_create_file(&new_client->dev,
668 device_create_file(&new_client->dev, &dev_attr_in5_input); 737 &dev_attr_in0_min))
669 device_create_file(&new_client->dev, &dev_attr_in5_min); 738 || (err = device_create_file(&new_client->dev,
670 device_create_file(&new_client->dev, &dev_attr_in5_max); 739 &dev_attr_in0_max))
740 || (err = device_create_file(&new_client->dev,
741 &dev_attr_in5_input))
742 || (err = device_create_file(&new_client->dev,
743 &dev_attr_in5_min))
744 || (err = device_create_file(&new_client->dev,
745 &dev_attr_in5_max)))
746 goto exit_remove;
671 } 747 }
672 748
673 if (!(data->channel & CHAN_NO_VID)) { 749 if (!(data->channel & CHAN_NO_VID)) {
674 device_create_file(&new_client->dev, &dev_attr_cpu0_vid); 750 if ((err = device_create_file(&new_client->dev,
675 device_create_file(&new_client->dev, &dev_attr_vrm); 751 &dev_attr_cpu0_vid))
752 || (err = device_create_file(&new_client->dev,
753 &dev_attr_vrm)))
754 goto exit_remove;
676 } 755 }
677 756
678 device_create_file(&new_client->dev, &dev_attr_alarms); 757 data->class_dev = hwmon_device_register(&new_client->dev);
679 device_create_file(&new_client->dev, &dev_attr_aout_output); 758 if (IS_ERR(data->class_dev)) {
759 err = PTR_ERR(data->class_dev);
760 goto exit_remove;
761 }
680 762
681 return 0; 763 return 0;
682 764
765exit_remove:
766 sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
767 sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
683exit_detach: 768exit_detach:
684 i2c_detach_client(new_client); 769 i2c_detach_client(new_client);
685exit_free: 770exit_free:
@@ -732,6 +817,8 @@ static int lm87_detach_client(struct i2c_client *client)
732 int err; 817 int err;
733 818
734 hwmon_device_unregister(data->class_dev); 819 hwmon_device_unregister(data->class_dev);
820 sysfs_remove_group(&client->dev.kobj, &lm87_group);
821 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
735 822
736 if ((err = i2c_detach_client(client))) 823 if ((err = i2c_detach_client(client)))
737 return err; 824 return err;
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index d9eeaf7585bd..6882ce75feee 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware 2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring 3 * monitoring
4 * Copyright (C) 2003-2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2003-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * Based on the lm83 driver. The LM90 is a sensor chip made by National 6 * Based on the lm83 driver. The LM90 is a sensor chip made by National
7 * Semiconductor. It reports up to two temperatures (its own plus up to 7 * Semiconductor. It reports up to two temperatures (its own plus up to
@@ -79,6 +79,7 @@
79#include <linux/hwmon.h> 79#include <linux/hwmon.h>
80#include <linux/err.h> 80#include <linux/err.h>
81#include <linux/mutex.h> 81#include <linux/mutex.h>
82#include <linux/sysfs.h>
82 83
83/* 84/*
84 * Addresses to scan 85 * Addresses to scan
@@ -327,6 +328,16 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *dummy,
327 return sprintf(buf, "%d\n", data->alarms); 328 return sprintf(buf, "%d\n", data->alarms);
328} 329}
329 330
331static ssize_t show_alarm(struct device *dev, struct device_attribute
332 *devattr, char *buf)
333{
334 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
335 struct lm90_data *data = lm90_update_device(dev);
336 int bitnr = attr->index;
337
338 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
339}
340
330static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0); 341static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp8, NULL, 0);
331static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0); 342static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp11, NULL, 0);
332static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, 343static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
@@ -344,8 +355,45 @@ static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
344static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, 355static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
345 set_temphyst, 3); 356 set_temphyst, 3);
346static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4); 357static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 4);
358
359/* Individual alarm files */
360static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
361static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 1);
362static SENSOR_DEVICE_ATTR(temp2_input_fault, S_IRUGO, show_alarm, NULL, 2);
363static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
364static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 4);
365static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 5);
366static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
367/* Raw alarm file for compatibility */
347static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 368static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
348 369
370static struct attribute *lm90_attributes[] = {
371 &sensor_dev_attr_temp1_input.dev_attr.attr,
372 &sensor_dev_attr_temp2_input.dev_attr.attr,
373 &sensor_dev_attr_temp1_min.dev_attr.attr,
374 &sensor_dev_attr_temp2_min.dev_attr.attr,
375 &sensor_dev_attr_temp1_max.dev_attr.attr,
376 &sensor_dev_attr_temp2_max.dev_attr.attr,
377 &sensor_dev_attr_temp1_crit.dev_attr.attr,
378 &sensor_dev_attr_temp2_crit.dev_attr.attr,
379 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
380 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
381
382 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
383 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
384 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
385 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
386 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
387 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
388 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
389 &dev_attr_alarms.attr,
390 NULL
391};
392
393static const struct attribute_group lm90_group = {
394 .attrs = lm90_attributes,
395};
396
349/* pec used for ADM1032 only */ 397/* pec used for ADM1032 only */
350static ssize_t show_pec(struct device *dev, struct device_attribute *dummy, 398static ssize_t show_pec(struct device *dev, struct device_attribute *dummy,
351 char *buf) 399 char *buf)
@@ -569,39 +617,25 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
569 lm90_init_client(new_client); 617 lm90_init_client(new_client);
570 618
571 /* Register sysfs hooks */ 619 /* Register sysfs hooks */
620 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm90_group)))
621 goto exit_detach;
622 if (new_client->flags & I2C_CLIENT_PEC) {
623 if ((err = device_create_file(&new_client->dev,
624 &dev_attr_pec)))
625 goto exit_remove_files;
626 }
627
572 data->class_dev = hwmon_device_register(&new_client->dev); 628 data->class_dev = hwmon_device_register(&new_client->dev);
573 if (IS_ERR(data->class_dev)) { 629 if (IS_ERR(data->class_dev)) {
574 err = PTR_ERR(data->class_dev); 630 err = PTR_ERR(data->class_dev);
575 goto exit_detach; 631 goto exit_remove_files;
576 } 632 }
577 633
578 device_create_file(&new_client->dev,
579 &sensor_dev_attr_temp1_input.dev_attr);
580 device_create_file(&new_client->dev,
581 &sensor_dev_attr_temp2_input.dev_attr);
582 device_create_file(&new_client->dev,
583 &sensor_dev_attr_temp1_min.dev_attr);
584 device_create_file(&new_client->dev,
585 &sensor_dev_attr_temp2_min.dev_attr);
586 device_create_file(&new_client->dev,
587 &sensor_dev_attr_temp1_max.dev_attr);
588 device_create_file(&new_client->dev,
589 &sensor_dev_attr_temp2_max.dev_attr);
590 device_create_file(&new_client->dev,
591 &sensor_dev_attr_temp1_crit.dev_attr);
592 device_create_file(&new_client->dev,
593 &sensor_dev_attr_temp2_crit.dev_attr);
594 device_create_file(&new_client->dev,
595 &sensor_dev_attr_temp1_crit_hyst.dev_attr);
596 device_create_file(&new_client->dev,
597 &sensor_dev_attr_temp2_crit_hyst.dev_attr);
598 device_create_file(&new_client->dev, &dev_attr_alarms);
599
600 if (new_client->flags & I2C_CLIENT_PEC)
601 device_create_file(&new_client->dev, &dev_attr_pec);
602
603 return 0; 634 return 0;
604 635
636exit_remove_files:
637 sysfs_remove_group(&new_client->dev.kobj, &lm90_group);
638 device_remove_file(&new_client->dev, &dev_attr_pec);
605exit_detach: 639exit_detach:
606 i2c_detach_client(new_client); 640 i2c_detach_client(new_client);
607exit_free: 641exit_free:
@@ -634,6 +668,8 @@ static int lm90_detach_client(struct i2c_client *client)
634 int err; 668 int err;
635 669
636 hwmon_device_unregister(data->class_dev); 670 hwmon_device_unregister(data->class_dev);
671 sysfs_remove_group(&client->dev.kobj, &lm90_group);
672 device_remove_file(&client->dev, &dev_attr_pec);
637 673
638 if ((err = i2c_detach_client(client))) 674 if ((err = i2c_detach_client(client)))
639 return err; 675 return err;
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 197f77226dc4..30b536333f14 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -288,6 +288,23 @@ static int max6635_check(struct i2c_client *client)
288 return 1; 288 return 1;
289} 289}
290 290
291static struct attribute *lm92_attributes[] = {
292 &dev_attr_temp1_input.attr,
293 &dev_attr_temp1_crit.attr,
294 &dev_attr_temp1_crit_hyst.attr,
295 &dev_attr_temp1_min.attr,
296 &dev_attr_temp1_min_hyst.attr,
297 &dev_attr_temp1_max.attr,
298 &dev_attr_temp1_max_hyst.attr,
299 &dev_attr_alarms.attr,
300
301 NULL
302};
303
304static const struct attribute_group lm92_group = {
305 .attrs = lm92_attributes,
306};
307
291/* The following function does more than just detection. If detection 308/* The following function does more than just detection. If detection
292 succeeds, it also registers the new chip. */ 309 succeeds, it also registers the new chip. */
293static int lm92_detect(struct i2c_adapter *adapter, int address, int kind) 310static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -359,23 +376,19 @@ static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
359 lm92_init_client(new_client); 376 lm92_init_client(new_client);
360 377
361 /* Register sysfs hooks */ 378 /* Register sysfs hooks */
379 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm92_group)))
380 goto exit_detach;
381
362 data->class_dev = hwmon_device_register(&new_client->dev); 382 data->class_dev = hwmon_device_register(&new_client->dev);
363 if (IS_ERR(data->class_dev)) { 383 if (IS_ERR(data->class_dev)) {
364 err = PTR_ERR(data->class_dev); 384 err = PTR_ERR(data->class_dev);
365 goto exit_detach; 385 goto exit_remove;
366 } 386 }
367 387
368 device_create_file(&new_client->dev, &dev_attr_temp1_input);
369 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
370 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
371 device_create_file(&new_client->dev, &dev_attr_temp1_min);
372 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
373 device_create_file(&new_client->dev, &dev_attr_temp1_max);
374 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
375 device_create_file(&new_client->dev, &dev_attr_alarms);
376
377 return 0; 388 return 0;
378 389
390exit_remove:
391 sysfs_remove_group(&new_client->dev.kobj, &lm92_group);
379exit_detach: 392exit_detach:
380 i2c_detach_client(new_client); 393 i2c_detach_client(new_client);
381exit_free: 394exit_free:
@@ -397,6 +410,7 @@ static int lm92_detach_client(struct i2c_client *client)
397 int err; 410 int err;
398 411
399 hwmon_device_unregister(data->class_dev); 412 hwmon_device_unregister(data->class_dev);
413 sysfs_remove_group(&client->dev.kobj, &lm92_group);
400 414
401 if ((err = i2c_detach_client(client))) 415 if ((err = i2c_detach_client(client)))
402 return err; 416 return err;
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c
index b4135b5971f4..2f58f651f03a 100644
--- a/drivers/hwmon/max1619.c
+++ b/drivers/hwmon/max1619.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a, 39static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
39 0x29, 0x2a, 0x2b, 40 0x29, 0x2a, 0x2b,
@@ -172,6 +173,22 @@ static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst2,
172 set_temp_hyst2); 173 set_temp_hyst2);
173static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 174static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
174 175
176static struct attribute *max1619_attributes[] = {
177 &dev_attr_temp1_input.attr,
178 &dev_attr_temp2_input.attr,
179 &dev_attr_temp2_min.attr,
180 &dev_attr_temp2_max.attr,
181 &dev_attr_temp2_crit.attr,
182 &dev_attr_temp2_crit_hyst.attr,
183
184 &dev_attr_alarms.attr,
185 NULL
186};
187
188static const struct attribute_group max1619_group = {
189 .attrs = max1619_attributes,
190};
191
175/* 192/*
176 * Real code 193 * Real code
177 */ 194 */
@@ -273,22 +290,19 @@ static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
273 max1619_init_client(new_client); 290 max1619_init_client(new_client);
274 291
275 /* Register sysfs hooks */ 292 /* Register sysfs hooks */
293 if ((err = sysfs_create_group(&new_client->dev.kobj, &max1619_group)))
294 goto exit_detach;
295
276 data->class_dev = hwmon_device_register(&new_client->dev); 296 data->class_dev = hwmon_device_register(&new_client->dev);
277 if (IS_ERR(data->class_dev)) { 297 if (IS_ERR(data->class_dev)) {
278 err = PTR_ERR(data->class_dev); 298 err = PTR_ERR(data->class_dev);
279 goto exit_detach; 299 goto exit_remove_files;
280 } 300 }
281 301
282 device_create_file(&new_client->dev, &dev_attr_temp1_input);
283 device_create_file(&new_client->dev, &dev_attr_temp2_input);
284 device_create_file(&new_client->dev, &dev_attr_temp2_min);
285 device_create_file(&new_client->dev, &dev_attr_temp2_max);
286 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
287 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
288 device_create_file(&new_client->dev, &dev_attr_alarms);
289
290 return 0; 302 return 0;
291 303
304exit_remove_files:
305 sysfs_remove_group(&new_client->dev.kobj, &max1619_group);
292exit_detach: 306exit_detach:
293 i2c_detach_client(new_client); 307 i2c_detach_client(new_client);
294exit_free: 308exit_free:
@@ -318,6 +332,7 @@ static int max1619_detach_client(struct i2c_client *client)
318 int err; 332 int err;
319 333
320 hwmon_device_unregister(data->class_dev); 334 hwmon_device_unregister(data->class_dev);
335 sysfs_remove_group(&client->dev.kobj, &max1619_group);
321 336
322 if ((err = i2c_detach_client(client))) 337 if ((err = i2c_detach_client(client)))
323 return err; 338 return err;
diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c
index 236f9f29c624..3b8b81984ad4 100644
--- a/drivers/hwmon/pc87360.c
+++ b/drivers/hwmon/pc87360.c
@@ -328,6 +328,12 @@ static struct sensor_device_attribute fan_min[] = {
328 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2), 328 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
329}; 329};
330 330
331#define FAN_UNIT_ATTRS(X) \
332 &fan_input[X].dev_attr.attr, \
333 &fan_status[X].dev_attr.attr, \
334 &fan_div[X].dev_attr.attr, \
335 &fan_min[X].dev_attr.attr
336
331static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) 337static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
332{ 338{
333 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 339 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -360,6 +366,19 @@ static struct sensor_device_attribute pwm[] = {
360 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2), 366 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
361}; 367};
362 368
369static struct attribute * pc8736x_fan_attr_array[] = {
370 FAN_UNIT_ATTRS(0),
371 FAN_UNIT_ATTRS(1),
372 FAN_UNIT_ATTRS(2),
373 &pwm[0].dev_attr.attr,
374 &pwm[1].dev_attr.attr,
375 &pwm[2].dev_attr.attr,
376 NULL
377};
378static const struct attribute_group pc8736x_fan_group = {
379 .attrs = pc8736x_fan_attr_array,
380};
381
363static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) 382static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
364{ 383{
365 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 384 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -472,6 +491,61 @@ static struct sensor_device_attribute in_max[] = {
472 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10), 491 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10),
473}; 492};
474 493
494#define VIN_UNIT_ATTRS(X) \
495 &in_input[X].dev_attr.attr, \
496 &in_status[X].dev_attr.attr, \
497 &in_min[X].dev_attr.attr, \
498 &in_max[X].dev_attr.attr
499
500static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
501{
502 struct pc87360_data *data = pc87360_update_device(dev);
503 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
504}
505static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
506
507static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
508{
509 struct pc87360_data *data = pc87360_update_device(dev);
510 return sprintf(buf, "%u\n", data->vrm);
511}
512static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
513{
514 struct i2c_client *client = to_i2c_client(dev);
515 struct pc87360_data *data = i2c_get_clientdata(client);
516 data->vrm = simple_strtoul(buf, NULL, 10);
517 return count;
518}
519static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
520
521static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf)
522{
523 struct pc87360_data *data = pc87360_update_device(dev);
524 return sprintf(buf, "%u\n", data->in_alarms);
525}
526static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
527
528static struct attribute *pc8736x_vin_attr_array[] = {
529 VIN_UNIT_ATTRS(0),
530 VIN_UNIT_ATTRS(1),
531 VIN_UNIT_ATTRS(2),
532 VIN_UNIT_ATTRS(3),
533 VIN_UNIT_ATTRS(4),
534 VIN_UNIT_ATTRS(5),
535 VIN_UNIT_ATTRS(6),
536 VIN_UNIT_ATTRS(7),
537 VIN_UNIT_ATTRS(8),
538 VIN_UNIT_ATTRS(9),
539 VIN_UNIT_ATTRS(10),
540 &dev_attr_cpu0_vid.attr,
541 &dev_attr_vrm.attr,
542 &dev_attr_alarms_in.attr,
543 NULL
544};
545static const struct attribute_group pc8736x_vin_group = {
546 .attrs = pc8736x_vin_attr_array,
547};
548
475static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf) 549static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
476{ 550{
477 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 551 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
@@ -590,33 +664,22 @@ static struct sensor_device_attribute therm_crit[] = {
590 show_therm_crit, set_therm_crit, 2+11), 664 show_therm_crit, set_therm_crit, 2+11),
591}; 665};
592 666
593static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 667#define THERM_UNIT_ATTRS(X) \
594{ 668 &therm_input[X].dev_attr.attr, \
595 struct pc87360_data *data = pc87360_update_device(dev); 669 &therm_status[X].dev_attr.attr, \
596 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 670 &therm_min[X].dev_attr.attr, \
597} 671 &therm_max[X].dev_attr.attr, \
598static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 672 &therm_crit[X].dev_attr.attr
599 673
600static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 674static struct attribute * pc8736x_therm_attr_array[] = {
601{ 675 THERM_UNIT_ATTRS(0),
602 struct pc87360_data *data = pc87360_update_device(dev); 676 THERM_UNIT_ATTRS(1),
603 return sprintf(buf, "%u\n", data->vrm); 677 THERM_UNIT_ATTRS(2),
604} 678 NULL
605static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 679};
606{ 680static const struct attribute_group pc8736x_therm_group = {
607 struct i2c_client *client = to_i2c_client(dev); 681 .attrs = pc8736x_therm_attr_array,
608 struct pc87360_data *data = i2c_get_clientdata(client); 682};
609 data->vrm = simple_strtoul(buf, NULL, 10);
610 return count;
611}
612static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
613
614static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf)
615{
616 struct pc87360_data *data = pc87360_update_device(dev);
617 return sprintf(buf, "%u\n", data->in_alarms);
618}
619static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
620 683
621static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf) 684static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf)
622{ 685{
@@ -736,6 +799,25 @@ static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *att
736} 799}
737static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL); 800static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
738 801
802#define TEMP_UNIT_ATTRS(X) \
803 &temp_input[X].dev_attr.attr, \
804 &temp_status[X].dev_attr.attr, \
805 &temp_min[X].dev_attr.attr, \
806 &temp_max[X].dev_attr.attr, \
807 &temp_crit[X].dev_attr.attr
808
809static struct attribute * pc8736x_temp_attr_array[] = {
810 TEMP_UNIT_ATTRS(0),
811 TEMP_UNIT_ATTRS(1),
812 TEMP_UNIT_ATTRS(2),
813 /* include the few miscellaneous atts here */
814 &dev_attr_alarms_temp.attr,
815 NULL
816};
817static const struct attribute_group pc8736x_temp_group = {
818 .attrs = pc8736x_temp_attr_array,
819};
820
739/* 821/*
740 * Device detection, registration and update 822 * Device detection, registration and update
741 */ 823 */
@@ -936,60 +1018,69 @@ static int pc87360_detect(struct i2c_adapter *adapter)
936 pc87360_init_client(client, use_thermistors); 1018 pc87360_init_client(client, use_thermistors);
937 } 1019 }
938 1020
939 /* Register sysfs hooks */ 1021 /* Register all-or-nothing sysfs groups */
940 data->class_dev = hwmon_device_register(&client->dev); 1022
941 if (IS_ERR(data->class_dev)) { 1023 if (data->innr &&
942 err = PTR_ERR(data->class_dev); 1024 (err = sysfs_create_group(&client->dev.kobj,
1025 &pc8736x_vin_group)))
943 goto ERROR3; 1026 goto ERROR3;
944 }
945 1027
946 if (data->innr) { 1028 if (data->innr == 14 &&
947 for (i = 0; i < 11; i++) { 1029 (err = sysfs_create_group(&client->dev.kobj,
948 device_create_file(dev, &in_input[i].dev_attr); 1030 &pc8736x_therm_group)))
949 device_create_file(dev, &in_min[i].dev_attr); 1031 goto ERROR3;
950 device_create_file(dev, &in_max[i].dev_attr); 1032
951 device_create_file(dev, &in_status[i].dev_attr); 1033 /* create device attr-files for varying sysfs groups */
952 }
953 device_create_file(dev, &dev_attr_cpu0_vid);
954 device_create_file(dev, &dev_attr_vrm);
955 device_create_file(dev, &dev_attr_alarms_in);
956 }
957 1034
958 if (data->tempnr) { 1035 if (data->tempnr) {
959 for (i = 0; i < data->tempnr; i++) { 1036 for (i = 0; i < data->tempnr; i++) {
960 device_create_file(dev, &temp_input[i].dev_attr); 1037 if ((err = device_create_file(dev,
961 device_create_file(dev, &temp_min[i].dev_attr); 1038 &temp_input[i].dev_attr))
962 device_create_file(dev, &temp_max[i].dev_attr); 1039 || (err = device_create_file(dev,
963 device_create_file(dev, &temp_crit[i].dev_attr); 1040 &temp_min[i].dev_attr))
964 device_create_file(dev, &temp_status[i].dev_attr); 1041 || (err = device_create_file(dev,
965 } 1042 &temp_max[i].dev_attr))
966 device_create_file(dev, &dev_attr_alarms_temp); 1043 || (err = device_create_file(dev,
967 } 1044 &temp_crit[i].dev_attr))
968 1045 || (err = device_create_file(dev,
969 if (data->innr == 14) { 1046 &temp_status[i].dev_attr)))
970 for (i = 0; i < 3; i++) { 1047 goto ERROR3;
971 device_create_file(dev, &therm_input[i].dev_attr);
972 device_create_file(dev, &therm_min[i].dev_attr);
973 device_create_file(dev, &therm_max[i].dev_attr);
974 device_create_file(dev, &therm_crit[i].dev_attr);
975 device_create_file(dev, &therm_status[i].dev_attr);
976 } 1048 }
1049 if ((err = device_create_file(dev, &dev_attr_alarms_temp)))
1050 goto ERROR3;
977 } 1051 }
978 1052
979 for (i = 0; i < data->fannr; i++) { 1053 for (i = 0; i < data->fannr; i++) {
980 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) { 1054 if (FAN_CONFIG_MONITOR(data->fan_conf, i)
981 device_create_file(dev, &fan_input[i].dev_attr); 1055 && ((err = device_create_file(dev,
982 device_create_file(dev, &fan_min[i].dev_attr); 1056 &fan_input[i].dev_attr))
983 device_create_file(dev, &fan_div[i].dev_attr); 1057 || (err = device_create_file(dev,
984 device_create_file(dev, &fan_status[i].dev_attr); 1058 &fan_min[i].dev_attr))
985 } 1059 || (err = device_create_file(dev,
986 if (FAN_CONFIG_CONTROL(data->fan_conf, i)) 1060 &fan_div[i].dev_attr))
987 device_create_file(dev, &pwm[i].dev_attr); 1061 || (err = device_create_file(dev,
1062 &fan_status[i].dev_attr))))
1063 goto ERROR3;
1064
1065 if (FAN_CONFIG_CONTROL(data->fan_conf, i)
1066 && (err = device_create_file(dev, &pwm[i].dev_attr)))
1067 goto ERROR3;
988 } 1068 }
989 1069
1070 data->class_dev = hwmon_device_register(&client->dev);
1071 if (IS_ERR(data->class_dev)) {
1072 err = PTR_ERR(data->class_dev);
1073 goto ERROR3;
1074 }
990 return 0; 1075 return 0;
991 1076
992ERROR3: 1077ERROR3:
1078 /* can still remove groups whose members were added individually */
1079 sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group);
1080 sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group);
1081 sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group);
1082 sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group);
1083
993 i2c_detach_client(client); 1084 i2c_detach_client(client);
994ERROR2: 1085ERROR2:
995 for (i = 0; i < 3; i++) { 1086 for (i = 0; i < 3; i++) {
@@ -1009,6 +1100,11 @@ static int pc87360_detach_client(struct i2c_client *client)
1009 1100
1010 hwmon_device_unregister(data->class_dev); 1101 hwmon_device_unregister(data->class_dev);
1011 1102
1103 sysfs_remove_group(&client->dev.kobj, &pc8736x_temp_group);
1104 sysfs_remove_group(&client->dev.kobj, &pc8736x_fan_group);
1105 sysfs_remove_group(&client->dev.kobj, &pc8736x_therm_group);
1106 sysfs_remove_group(&client->dev.kobj, &pc8736x_vin_group);
1107
1012 if ((i = i2c_detach_client(client))) 1108 if ((i = i2c_detach_client(client)))
1013 return i; 1109 return i;
1014 1110
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 3783af4195bd..95a4b5d9eaf2 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -61,6 +61,7 @@
61#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/jiffies.h> 62#include <linux/jiffies.h>
63#include <linux/mutex.h> 63#include <linux/mutex.h>
64#include <linux/sysfs.h>
64#include <asm/io.h> 65#include <asm/io.h>
65 66
66 67
@@ -473,6 +474,50 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
473 return sprintf(buf, "%d\n", data->alarms); 474 return sprintf(buf, "%d\n", data->alarms);
474} 475}
475static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 476static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
477
478static struct attribute *sis5595_attributes[] = {
479 &dev_attr_in0_input.attr,
480 &dev_attr_in0_min.attr,
481 &dev_attr_in0_max.attr,
482 &dev_attr_in1_input.attr,
483 &dev_attr_in1_min.attr,
484 &dev_attr_in1_max.attr,
485 &dev_attr_in2_input.attr,
486 &dev_attr_in2_min.attr,
487 &dev_attr_in2_max.attr,
488 &dev_attr_in3_input.attr,
489 &dev_attr_in3_min.attr,
490 &dev_attr_in3_max.attr,
491
492 &dev_attr_fan1_input.attr,
493 &dev_attr_fan1_min.attr,
494 &dev_attr_fan1_div.attr,
495 &dev_attr_fan2_input.attr,
496 &dev_attr_fan2_min.attr,
497 &dev_attr_fan2_div.attr,
498
499 &dev_attr_alarms.attr,
500 NULL
501};
502
503static const struct attribute_group sis5595_group = {
504 .attrs = sis5595_attributes,
505};
506
507static struct attribute *sis5595_attributes_opt[] = {
508 &dev_attr_in4_input.attr,
509 &dev_attr_in4_min.attr,
510 &dev_attr_in4_max.attr,
511
512 &dev_attr_temp1_input.attr,
513 &dev_attr_temp1_max.attr,
514 &dev_attr_temp1_max_hyst.attr,
515 NULL
516};
517
518static const struct attribute_group sis5595_group_opt = {
519 .attrs = sis5595_attributes_opt,
520};
476 521
477/* This is called when the module is loaded */ 522/* This is called when the module is loaded */
478static int sis5595_detect(struct i2c_adapter *adapter) 523static int sis5595_detect(struct i2c_adapter *adapter)
@@ -566,43 +611,37 @@ static int sis5595_detect(struct i2c_adapter *adapter)
566 } 611 }
567 612
568 /* Register sysfs hooks */ 613 /* Register sysfs hooks */
614 if ((err = sysfs_create_group(&new_client->dev.kobj, &sis5595_group)))
615 goto exit_detach;
616 if (data->maxins == 4) {
617 if ((err = device_create_file(&new_client->dev,
618 &dev_attr_in4_input))
619 || (err = device_create_file(&new_client->dev,
620 &dev_attr_in4_min))
621 || (err = device_create_file(&new_client->dev,
622 &dev_attr_in4_max)))
623 goto exit_remove_files;
624 } else {
625 if ((err = device_create_file(&new_client->dev,
626 &dev_attr_temp1_input))
627 || (err = device_create_file(&new_client->dev,
628 &dev_attr_temp1_max))
629 || (err = device_create_file(&new_client->dev,
630 &dev_attr_temp1_max_hyst)))
631 goto exit_remove_files;
632 }
633
569 data->class_dev = hwmon_device_register(&new_client->dev); 634 data->class_dev = hwmon_device_register(&new_client->dev);
570 if (IS_ERR(data->class_dev)) { 635 if (IS_ERR(data->class_dev)) {
571 err = PTR_ERR(data->class_dev); 636 err = PTR_ERR(data->class_dev);
572 goto exit_detach; 637 goto exit_remove_files;
573 } 638 }
574 639
575 device_create_file(&new_client->dev, &dev_attr_in0_input);
576 device_create_file(&new_client->dev, &dev_attr_in0_min);
577 device_create_file(&new_client->dev, &dev_attr_in0_max);
578 device_create_file(&new_client->dev, &dev_attr_in1_input);
579 device_create_file(&new_client->dev, &dev_attr_in1_min);
580 device_create_file(&new_client->dev, &dev_attr_in1_max);
581 device_create_file(&new_client->dev, &dev_attr_in2_input);
582 device_create_file(&new_client->dev, &dev_attr_in2_min);
583 device_create_file(&new_client->dev, &dev_attr_in2_max);
584 device_create_file(&new_client->dev, &dev_attr_in3_input);
585 device_create_file(&new_client->dev, &dev_attr_in3_min);
586 device_create_file(&new_client->dev, &dev_attr_in3_max);
587 if (data->maxins == 4) {
588 device_create_file(&new_client->dev, &dev_attr_in4_input);
589 device_create_file(&new_client->dev, &dev_attr_in4_min);
590 device_create_file(&new_client->dev, &dev_attr_in4_max);
591 }
592 device_create_file(&new_client->dev, &dev_attr_fan1_input);
593 device_create_file(&new_client->dev, &dev_attr_fan1_min);
594 device_create_file(&new_client->dev, &dev_attr_fan1_div);
595 device_create_file(&new_client->dev, &dev_attr_fan2_input);
596 device_create_file(&new_client->dev, &dev_attr_fan2_min);
597 device_create_file(&new_client->dev, &dev_attr_fan2_div);
598 device_create_file(&new_client->dev, &dev_attr_alarms);
599 if (data->maxins == 3) {
600 device_create_file(&new_client->dev, &dev_attr_temp1_input);
601 device_create_file(&new_client->dev, &dev_attr_temp1_max);
602 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
603 }
604 return 0; 640 return 0;
605 641
642exit_remove_files:
643 sysfs_remove_group(&new_client->dev.kobj, &sis5595_group);
644 sysfs_remove_group(&new_client->dev.kobj, &sis5595_group_opt);
606exit_detach: 645exit_detach:
607 i2c_detach_client(new_client); 646 i2c_detach_client(new_client);
608exit_free: 647exit_free:
@@ -619,6 +658,8 @@ static int sis5595_detach_client(struct i2c_client *client)
619 int err; 658 int err;
620 659
621 hwmon_device_unregister(data->class_dev); 660 hwmon_device_unregister(data->class_dev);
661 sysfs_remove_group(&client->dev.kobj, &sis5595_group);
662 sysfs_remove_group(&client->dev.kobj, &sis5595_group_opt);
622 663
623 if ((err = i2c_detach_client(client))) 664 if ((err = i2c_detach_client(client)))
624 return err; 665 return err;
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index a85869393bab..72b0e2d8650c 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -176,9 +176,6 @@ sysfs_temp(2);
176sysfs_temp(3); 176sysfs_temp(3);
177sysfs_temp(4); 177sysfs_temp(4);
178 178
179#define device_create_file_temp(client, num) \
180 device_create_file(&client->dev, &dev_attr_temp##num##_input)
181
182/* FAN: 1 RPM/bit 179/* FAN: 1 RPM/bit
183 REG: count of 90kHz pulses / revolution */ 180 REG: count of 90kHz pulses / revolution */
184static int fan_from_reg(u16 reg) 181static int fan_from_reg(u16 reg)
@@ -205,8 +202,22 @@ sysfs_fan(2);
205sysfs_fan(3); 202sysfs_fan(3);
206sysfs_fan(4); 203sysfs_fan(4);
207 204
208#define device_create_file_fan(client, num) \ 205static struct attribute *smsc47b397_attributes[] = {
209 device_create_file(&client->dev, &dev_attr_fan##num##_input) 206 &dev_attr_temp1_input.attr,
207 &dev_attr_temp2_input.attr,
208 &dev_attr_temp3_input.attr,
209 &dev_attr_temp4_input.attr,
210 &dev_attr_fan1_input.attr,
211 &dev_attr_fan2_input.attr,
212 &dev_attr_fan3_input.attr,
213 &dev_attr_fan4_input.attr,
214
215 NULL
216};
217
218static const struct attribute_group smsc47b397_group = {
219 .attrs = smsc47b397_attributes,
220};
210 221
211static int smsc47b397_detach_client(struct i2c_client *client) 222static int smsc47b397_detach_client(struct i2c_client *client)
212{ 223{
@@ -214,6 +225,7 @@ static int smsc47b397_detach_client(struct i2c_client *client)
214 int err; 225 int err;
215 226
216 hwmon_device_unregister(data->class_dev); 227 hwmon_device_unregister(data->class_dev);
228 sysfs_remove_group(&client->dev.kobj, &smsc47b397_group);
217 229
218 if ((err = i2c_detach_client(client))) 230 if ((err = i2c_detach_client(client)))
219 return err; 231 return err;
@@ -268,24 +280,19 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
268 if ((err = i2c_attach_client(new_client))) 280 if ((err = i2c_attach_client(new_client)))
269 goto error_free; 281 goto error_free;
270 282
283 if ((err = sysfs_create_group(&new_client->dev.kobj, &smsc47b397_group)))
284 goto error_detach;
285
271 data->class_dev = hwmon_device_register(&new_client->dev); 286 data->class_dev = hwmon_device_register(&new_client->dev);
272 if (IS_ERR(data->class_dev)) { 287 if (IS_ERR(data->class_dev)) {
273 err = PTR_ERR(data->class_dev); 288 err = PTR_ERR(data->class_dev);
274 goto error_detach; 289 goto error_remove;
275 } 290 }
276 291
277 device_create_file_temp(new_client, 1);
278 device_create_file_temp(new_client, 2);
279 device_create_file_temp(new_client, 3);
280 device_create_file_temp(new_client, 4);
281
282 device_create_file_fan(new_client, 1);
283 device_create_file_fan(new_client, 2);
284 device_create_file_fan(new_client, 3);
285 device_create_file_fan(new_client, 4);
286
287 return 0; 292 return 0;
288 293
294error_remove:
295 sysfs_remove_group(&new_client->dev.kobj, &smsc47b397_group);
289error_detach: 296error_detach:
290 i2c_detach_client(new_client); 297 i2c_detach_client(new_client);
291error_free: 298error_free:
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index 6c81b843d831..47132fd26b1b 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/mutex.h> 37#include <linux/mutex.h>
38#include <linux/sysfs.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40/* Address is autodetected, there is no default value */ 41/* Address is autodetected, there is no default value */
@@ -347,6 +348,30 @@ fan_present(2);
347 348
348static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); 349static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
349 350
351/* Almost all sysfs files may or may not be created depending on the chip
352 setup so we create them individually. It is still convenient to define a
353 group to remove them all at once. */
354static struct attribute *smsc47m1_attributes[] = {
355 &dev_attr_fan1_input.attr,
356 &dev_attr_fan1_min.attr,
357 &dev_attr_fan1_div.attr,
358 &dev_attr_fan2_input.attr,
359 &dev_attr_fan2_min.attr,
360 &dev_attr_fan2_div.attr,
361
362 &dev_attr_pwm1.attr,
363 &dev_attr_pwm1_enable.attr,
364 &dev_attr_pwm2.attr,
365 &dev_attr_pwm2_enable.attr,
366
367 &dev_attr_alarms.attr,
368 NULL
369};
370
371static const struct attribute_group smsc47m1_group = {
372 .attrs = smsc47m1_attributes,
373};
374
350static int __init smsc47m1_find(unsigned short *addr) 375static int __init smsc47m1_find(unsigned short *addr)
351{ 376{
352 u8 val; 377 u8 val;
@@ -429,7 +454,8 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
429 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05) 454 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05)
430 == 0x04; 455 == 0x04;
431 if (!(fan1 || fan2 || pwm1 || pwm2)) { 456 if (!(fan1 || fan2 || pwm1 || pwm2)) {
432 dev_warn(&new_client->dev, "Device is not configured, will not use\n"); 457 dev_warn(&adapter->dev, "Device at 0x%x is not configured, "
458 "will not use\n", new_client->addr);
433 err = -ENODEV; 459 err = -ENODEV;
434 goto error_free; 460 goto error_free;
435 } 461 }
@@ -446,46 +472,62 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
446 smsc47m1_update_device(&new_client->dev, 1); 472 smsc47m1_update_device(&new_client->dev, 1);
447 473
448 /* Register sysfs hooks */ 474 /* Register sysfs hooks */
449 data->class_dev = hwmon_device_register(&new_client->dev);
450 if (IS_ERR(data->class_dev)) {
451 err = PTR_ERR(data->class_dev);
452 goto error_detach;
453 }
454
455 if (fan1) { 475 if (fan1) {
456 device_create_file(&new_client->dev, &dev_attr_fan1_input); 476 if ((err = device_create_file(&new_client->dev,
457 device_create_file(&new_client->dev, &dev_attr_fan1_min); 477 &dev_attr_fan1_input))
458 device_create_file(&new_client->dev, &dev_attr_fan1_div); 478 || (err = device_create_file(&new_client->dev,
479 &dev_attr_fan1_min))
480 || (err = device_create_file(&new_client->dev,
481 &dev_attr_fan1_div)))
482 goto error_remove_files;
459 } else 483 } else
460 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, " 484 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, "
461 "skipping\n"); 485 "skipping\n");
462 486
463 if (fan2) { 487 if (fan2) {
464 device_create_file(&new_client->dev, &dev_attr_fan2_input); 488 if ((err = device_create_file(&new_client->dev,
465 device_create_file(&new_client->dev, &dev_attr_fan2_min); 489 &dev_attr_fan2_input))
466 device_create_file(&new_client->dev, &dev_attr_fan2_div); 490 || (err = device_create_file(&new_client->dev,
491 &dev_attr_fan2_min))
492 || (err = device_create_file(&new_client->dev,
493 &dev_attr_fan2_div)))
494 goto error_remove_files;
467 } else 495 } else
468 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, " 496 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, "
469 "skipping\n"); 497 "skipping\n");
470 498
471 if (pwm1) { 499 if (pwm1) {
472 device_create_file(&new_client->dev, &dev_attr_pwm1); 500 if ((err = device_create_file(&new_client->dev,
473 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); 501 &dev_attr_pwm1))
502 || (err = device_create_file(&new_client->dev,
503 &dev_attr_pwm1_enable)))
504 goto error_remove_files;
474 } else 505 } else
475 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, " 506 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, "
476 "skipping\n"); 507 "skipping\n");
477 if (pwm2) { 508 if (pwm2) {
478 device_create_file(&new_client->dev, &dev_attr_pwm2); 509 if ((err = device_create_file(&new_client->dev,
479 device_create_file(&new_client->dev, &dev_attr_pwm2_enable); 510 &dev_attr_pwm2))
511 || (err = device_create_file(&new_client->dev,
512 &dev_attr_pwm2_enable)))
513 goto error_remove_files;
480 } else 514 } else
481 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, " 515 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, "
482 "skipping\n"); 516 "skipping\n");
483 517
484 device_create_file(&new_client->dev, &dev_attr_alarms); 518 if ((err = device_create_file(&new_client->dev, &dev_attr_alarms)))
519 goto error_remove_files;
520
521 data->class_dev = hwmon_device_register(&new_client->dev);
522 if (IS_ERR(data->class_dev)) {
523 err = PTR_ERR(data->class_dev);
524 goto error_remove_files;
525 }
485 526
486 return 0; 527 return 0;
487 528
488error_detach: 529error_remove_files:
530 sysfs_remove_group(&new_client->dev.kobj, &smsc47m1_group);
489 i2c_detach_client(new_client); 531 i2c_detach_client(new_client);
490error_free: 532error_free:
491 kfree(data); 533 kfree(data);
@@ -500,6 +542,7 @@ static int smsc47m1_detach_client(struct i2c_client *client)
500 int err; 542 int err;
501 543
502 hwmon_device_unregister(data->class_dev); 544 hwmon_device_unregister(data->class_dev);
545 sysfs_remove_group(&client->dev.kobj, &smsc47m1_group);
503 546
504 if ((err = i2c_detach_client(client))) 547 if ((err = i2c_detach_client(client)))
505 return err; 548 return err;
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index bdc4570acf9a..a6833f437395 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -30,6 +30,7 @@
30#include <linux/hwmon-sysfs.h> 30#include <linux/hwmon-sysfs.h>
31#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/sysfs.h>
33 34
34/* Addresses to scan */ 35/* Addresses to scan */
35static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; 36static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
@@ -370,6 +371,75 @@ static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 0x0200);
370static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400); 371static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 0x0400);
371static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800); 372static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 0x0800);
372 373
374static struct attribute *smsc47m192_attributes[] = {
375 &sensor_dev_attr_in0_input.dev_attr.attr,
376 &sensor_dev_attr_in0_min.dev_attr.attr,
377 &sensor_dev_attr_in0_max.dev_attr.attr,
378 &sensor_dev_attr_in0_alarm.dev_attr.attr,
379 &sensor_dev_attr_in1_input.dev_attr.attr,
380 &sensor_dev_attr_in1_min.dev_attr.attr,
381 &sensor_dev_attr_in1_max.dev_attr.attr,
382 &sensor_dev_attr_in1_alarm.dev_attr.attr,
383 &sensor_dev_attr_in2_input.dev_attr.attr,
384 &sensor_dev_attr_in2_min.dev_attr.attr,
385 &sensor_dev_attr_in2_max.dev_attr.attr,
386 &sensor_dev_attr_in2_alarm.dev_attr.attr,
387 &sensor_dev_attr_in3_input.dev_attr.attr,
388 &sensor_dev_attr_in3_min.dev_attr.attr,
389 &sensor_dev_attr_in3_max.dev_attr.attr,
390 &sensor_dev_attr_in3_alarm.dev_attr.attr,
391 &sensor_dev_attr_in5_input.dev_attr.attr,
392 &sensor_dev_attr_in5_min.dev_attr.attr,
393 &sensor_dev_attr_in5_max.dev_attr.attr,
394 &sensor_dev_attr_in5_alarm.dev_attr.attr,
395 &sensor_dev_attr_in6_input.dev_attr.attr,
396 &sensor_dev_attr_in6_min.dev_attr.attr,
397 &sensor_dev_attr_in6_max.dev_attr.attr,
398 &sensor_dev_attr_in6_alarm.dev_attr.attr,
399 &sensor_dev_attr_in7_input.dev_attr.attr,
400 &sensor_dev_attr_in7_min.dev_attr.attr,
401 &sensor_dev_attr_in7_max.dev_attr.attr,
402 &sensor_dev_attr_in7_alarm.dev_attr.attr,
403
404 &sensor_dev_attr_temp1_input.dev_attr.attr,
405 &sensor_dev_attr_temp1_max.dev_attr.attr,
406 &sensor_dev_attr_temp1_min.dev_attr.attr,
407 &sensor_dev_attr_temp1_offset.dev_attr.attr,
408 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
409 &sensor_dev_attr_temp2_input.dev_attr.attr,
410 &sensor_dev_attr_temp2_max.dev_attr.attr,
411 &sensor_dev_attr_temp2_min.dev_attr.attr,
412 &sensor_dev_attr_temp2_offset.dev_attr.attr,
413 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
414 &sensor_dev_attr_temp2_input_fault.dev_attr.attr,
415 &sensor_dev_attr_temp3_input.dev_attr.attr,
416 &sensor_dev_attr_temp3_max.dev_attr.attr,
417 &sensor_dev_attr_temp3_min.dev_attr.attr,
418 &sensor_dev_attr_temp3_offset.dev_attr.attr,
419 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
420 &sensor_dev_attr_temp3_input_fault.dev_attr.attr,
421
422 &dev_attr_cpu0_vid.attr,
423 &dev_attr_vrm.attr,
424 NULL
425};
426
427static const struct attribute_group smsc47m192_group = {
428 .attrs = smsc47m192_attributes,
429};
430
431static struct attribute *smsc47m192_attributes_in4[] = {
432 &sensor_dev_attr_in4_input.dev_attr.attr,
433 &sensor_dev_attr_in4_min.dev_attr.attr,
434 &sensor_dev_attr_in4_max.dev_attr.attr,
435 &sensor_dev_attr_in4_alarm.dev_attr.attr,
436 NULL
437};
438
439static const struct attribute_group smsc47m192_group_in4 = {
440 .attrs = smsc47m192_attributes_in4,
441};
442
373/* This function is called when: 443/* This function is called when:
374 * smsc47m192_driver is inserted (when this module is loaded), for each 444 * smsc47m192_driver is inserted (when this module is loaded), for each
375 available adapter 445 available adapter
@@ -471,80 +541,28 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
471 smsc47m192_init_client(client); 541 smsc47m192_init_client(client);
472 542
473 /* Register sysfs hooks */ 543 /* Register sysfs hooks */
474 data->class_dev = hwmon_device_register(&client->dev); 544 if ((err = sysfs_create_group(&client->dev.kobj, &smsc47m192_group)))
475 if (IS_ERR(data->class_dev)) {
476 err = PTR_ERR(data->class_dev);
477 goto exit_detach; 545 goto exit_detach;
478 }
479
480 device_create_file(&client->dev, &sensor_dev_attr_in0_input.dev_attr);
481 device_create_file(&client->dev, &sensor_dev_attr_in0_min.dev_attr);
482 device_create_file(&client->dev, &sensor_dev_attr_in0_max.dev_attr);
483 device_create_file(&client->dev, &sensor_dev_attr_in0_alarm.dev_attr);
484 device_create_file(&client->dev, &sensor_dev_attr_in1_input.dev_attr);
485 device_create_file(&client->dev, &sensor_dev_attr_in1_min.dev_attr);
486 device_create_file(&client->dev, &sensor_dev_attr_in1_max.dev_attr);
487 device_create_file(&client->dev, &sensor_dev_attr_in1_alarm.dev_attr);
488 device_create_file(&client->dev, &sensor_dev_attr_in2_input.dev_attr);
489 device_create_file(&client->dev, &sensor_dev_attr_in2_min.dev_attr);
490 device_create_file(&client->dev, &sensor_dev_attr_in2_max.dev_attr);
491 device_create_file(&client->dev, &sensor_dev_attr_in2_alarm.dev_attr);
492 device_create_file(&client->dev, &sensor_dev_attr_in3_input.dev_attr);
493 device_create_file(&client->dev, &sensor_dev_attr_in3_min.dev_attr);
494 device_create_file(&client->dev, &sensor_dev_attr_in3_max.dev_attr);
495 device_create_file(&client->dev, &sensor_dev_attr_in3_alarm.dev_attr);
496 546
497 /* Pin 110 is either in4 (+12V) or VID4 */ 547 /* Pin 110 is either in4 (+12V) or VID4 */
498 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG); 548 config = i2c_smbus_read_byte_data(client, SMSC47M192_REG_CONFIG);
499 if (!(config & 0x20)) { 549 if (!(config & 0x20)) {
500 device_create_file(&client->dev, 550 if ((err = sysfs_create_group(&client->dev.kobj,
501 &sensor_dev_attr_in4_input.dev_attr); 551 &smsc47m192_group_in4)))
502 device_create_file(&client->dev, 552 goto exit_remove_files;
503 &sensor_dev_attr_in4_min.dev_attr); 553 }
504 device_create_file(&client->dev, 554
505 &sensor_dev_attr_in4_max.dev_attr); 555 data->class_dev = hwmon_device_register(&client->dev);
506 device_create_file(&client->dev, 556 if (IS_ERR(data->class_dev)) {
507 &sensor_dev_attr_in4_alarm.dev_attr); 557 err = PTR_ERR(data->class_dev);
558 goto exit_remove_files;
508 } 559 }
509 device_create_file(&client->dev, &sensor_dev_attr_in5_input.dev_attr);
510 device_create_file(&client->dev, &sensor_dev_attr_in5_min.dev_attr);
511 device_create_file(&client->dev, &sensor_dev_attr_in5_max.dev_attr);
512 device_create_file(&client->dev, &sensor_dev_attr_in5_alarm.dev_attr);
513 device_create_file(&client->dev, &sensor_dev_attr_in6_input.dev_attr);
514 device_create_file(&client->dev, &sensor_dev_attr_in6_min.dev_attr);
515 device_create_file(&client->dev, &sensor_dev_attr_in6_max.dev_attr);
516 device_create_file(&client->dev, &sensor_dev_attr_in6_alarm.dev_attr);
517 device_create_file(&client->dev, &sensor_dev_attr_in7_input.dev_attr);
518 device_create_file(&client->dev, &sensor_dev_attr_in7_min.dev_attr);
519 device_create_file(&client->dev, &sensor_dev_attr_in7_max.dev_attr);
520 device_create_file(&client->dev, &sensor_dev_attr_in7_alarm.dev_attr);
521 device_create_file(&client->dev, &sensor_dev_attr_temp1_input.dev_attr);
522 device_create_file(&client->dev, &sensor_dev_attr_temp1_max.dev_attr);
523 device_create_file(&client->dev, &sensor_dev_attr_temp1_min.dev_attr);
524 device_create_file(&client->dev,
525 &sensor_dev_attr_temp1_offset.dev_attr);
526 device_create_file(&client->dev, &sensor_dev_attr_temp1_alarm.dev_attr);
527 device_create_file(&client->dev, &sensor_dev_attr_temp2_input.dev_attr);
528 device_create_file(&client->dev, &sensor_dev_attr_temp2_max.dev_attr);
529 device_create_file(&client->dev, &sensor_dev_attr_temp2_min.dev_attr);
530 device_create_file(&client->dev,
531 &sensor_dev_attr_temp2_offset.dev_attr);
532 device_create_file(&client->dev, &sensor_dev_attr_temp2_alarm.dev_attr);
533 device_create_file(&client->dev,
534 &sensor_dev_attr_temp2_input_fault.dev_attr);
535 device_create_file(&client->dev, &sensor_dev_attr_temp3_input.dev_attr);
536 device_create_file(&client->dev, &sensor_dev_attr_temp3_max.dev_attr);
537 device_create_file(&client->dev, &sensor_dev_attr_temp3_min.dev_attr);
538 device_create_file(&client->dev,
539 &sensor_dev_attr_temp3_offset.dev_attr);
540 device_create_file(&client->dev, &sensor_dev_attr_temp3_alarm.dev_attr);
541 device_create_file(&client->dev,
542 &sensor_dev_attr_temp3_input_fault.dev_attr);
543 device_create_file(&client->dev, &dev_attr_cpu0_vid);
544 device_create_file(&client->dev, &dev_attr_vrm);
545 560
546 return 0; 561 return 0;
547 562
563exit_remove_files:
564 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group);
565 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4);
548exit_detach: 566exit_detach:
549 i2c_detach_client(client); 567 i2c_detach_client(client);
550exit_free: 568exit_free:
@@ -559,6 +577,8 @@ static int smsc47m192_detach_client(struct i2c_client *client)
559 int err; 577 int err;
560 578
561 hwmon_device_unregister(data->class_dev); 579 hwmon_device_unregister(data->class_dev);
580 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group);
581 sysfs_remove_group(&client->dev.kobj, &smsc47m192_group_in4);
562 582
563 if ((err = i2c_detach_client(client))) 583 if ((err = i2c_detach_client(client)))
564 return err; 584 return err;
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c
index 95ae056e5a94..f8acada0537a 100644
--- a/drivers/hwmon/via686a.c
+++ b/drivers/hwmon/via686a.c
@@ -40,6 +40,7 @@
40#include <linux/err.h> 40#include <linux/err.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/sysfs.h>
43#include <asm/io.h> 44#include <asm/io.h>
44 45
45 46
@@ -570,6 +571,48 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
570} 571}
571static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 572static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
572 573
574static struct attribute *via686a_attributes[] = {
575 &dev_attr_in0_input.attr,
576 &dev_attr_in1_input.attr,
577 &dev_attr_in2_input.attr,
578 &dev_attr_in3_input.attr,
579 &dev_attr_in4_input.attr,
580 &dev_attr_in0_min.attr,
581 &dev_attr_in1_min.attr,
582 &dev_attr_in2_min.attr,
583 &dev_attr_in3_min.attr,
584 &dev_attr_in4_min.attr,
585 &dev_attr_in0_max.attr,
586 &dev_attr_in1_max.attr,
587 &dev_attr_in2_max.attr,
588 &dev_attr_in3_max.attr,
589 &dev_attr_in4_max.attr,
590
591 &dev_attr_temp1_input.attr,
592 &dev_attr_temp2_input.attr,
593 &dev_attr_temp3_input.attr,
594 &dev_attr_temp1_max.attr,
595 &dev_attr_temp2_max.attr,
596 &dev_attr_temp3_max.attr,
597 &dev_attr_temp1_max_hyst.attr,
598 &dev_attr_temp2_max_hyst.attr,
599 &dev_attr_temp3_max_hyst.attr,
600
601 &dev_attr_fan1_input.attr,
602 &dev_attr_fan2_input.attr,
603 &dev_attr_fan1_min.attr,
604 &dev_attr_fan2_min.attr,
605 &dev_attr_fan1_div.attr,
606 &dev_attr_fan2_div.attr,
607
608 &dev_attr_alarms.attr,
609 NULL
610};
611
612static const struct attribute_group via686a_group = {
613 .attrs = via686a_attributes,
614};
615
573/* The driver. I choose to use type i2c_driver, as at is identical to both 616/* The driver. I choose to use type i2c_driver, as at is identical to both
574 smbus_driver and isa_driver, and clients could be of either kind */ 617 smbus_driver and isa_driver, and clients could be of either kind */
575static struct i2c_driver via686a_driver = { 618static struct i2c_driver via686a_driver = {
@@ -650,46 +693,19 @@ static int via686a_detect(struct i2c_adapter *adapter)
650 via686a_init_client(new_client); 693 via686a_init_client(new_client);
651 694
652 /* Register sysfs hooks */ 695 /* Register sysfs hooks */
696 if ((err = sysfs_create_group(&new_client->dev.kobj, &via686a_group)))
697 goto exit_detach;
698
653 data->class_dev = hwmon_device_register(&new_client->dev); 699 data->class_dev = hwmon_device_register(&new_client->dev);
654 if (IS_ERR(data->class_dev)) { 700 if (IS_ERR(data->class_dev)) {
655 err = PTR_ERR(data->class_dev); 701 err = PTR_ERR(data->class_dev);
656 goto exit_detach; 702 goto exit_remove_files;
657 } 703 }
658 704
659 device_create_file(&new_client->dev, &dev_attr_in0_input);
660 device_create_file(&new_client->dev, &dev_attr_in1_input);
661 device_create_file(&new_client->dev, &dev_attr_in2_input);
662 device_create_file(&new_client->dev, &dev_attr_in3_input);
663 device_create_file(&new_client->dev, &dev_attr_in4_input);
664 device_create_file(&new_client->dev, &dev_attr_in0_min);
665 device_create_file(&new_client->dev, &dev_attr_in1_min);
666 device_create_file(&new_client->dev, &dev_attr_in2_min);
667 device_create_file(&new_client->dev, &dev_attr_in3_min);
668 device_create_file(&new_client->dev, &dev_attr_in4_min);
669 device_create_file(&new_client->dev, &dev_attr_in0_max);
670 device_create_file(&new_client->dev, &dev_attr_in1_max);
671 device_create_file(&new_client->dev, &dev_attr_in2_max);
672 device_create_file(&new_client->dev, &dev_attr_in3_max);
673 device_create_file(&new_client->dev, &dev_attr_in4_max);
674 device_create_file(&new_client->dev, &dev_attr_temp1_input);
675 device_create_file(&new_client->dev, &dev_attr_temp2_input);
676 device_create_file(&new_client->dev, &dev_attr_temp3_input);
677 device_create_file(&new_client->dev, &dev_attr_temp1_max);
678 device_create_file(&new_client->dev, &dev_attr_temp2_max);
679 device_create_file(&new_client->dev, &dev_attr_temp3_max);
680 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
681 device_create_file(&new_client->dev, &dev_attr_temp2_max_hyst);
682 device_create_file(&new_client->dev, &dev_attr_temp3_max_hyst);
683 device_create_file(&new_client->dev, &dev_attr_fan1_input);
684 device_create_file(&new_client->dev, &dev_attr_fan2_input);
685 device_create_file(&new_client->dev, &dev_attr_fan1_min);
686 device_create_file(&new_client->dev, &dev_attr_fan2_min);
687 device_create_file(&new_client->dev, &dev_attr_fan1_div);
688 device_create_file(&new_client->dev, &dev_attr_fan2_div);
689 device_create_file(&new_client->dev, &dev_attr_alarms);
690
691 return 0; 705 return 0;
692 706
707exit_remove_files:
708 sysfs_remove_group(&new_client->dev.kobj, &via686a_group);
693exit_detach: 709exit_detach:
694 i2c_detach_client(new_client); 710 i2c_detach_client(new_client);
695exit_free: 711exit_free:
@@ -705,6 +721,7 @@ static int via686a_detach_client(struct i2c_client *client)
705 int err; 721 int err;
706 722
707 hwmon_device_unregister(data->class_dev); 723 hwmon_device_unregister(data->class_dev);
724 sysfs_remove_group(&client->dev.kobj, &via686a_group);
708 725
709 if ((err = i2c_detach_client(client))) 726 if ((err = i2c_detach_client(client)))
710 return err; 727 return err;
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
new file mode 100644
index 000000000000..25cc56003d7a
--- /dev/null
+++ b/drivers/hwmon/vt1211.c
@@ -0,0 +1,1355 @@
1/*
2 * vt1211.c - driver for the VIA VT1211 Super-I/O chip integrated hardware
3 * monitoring features
4 * Copyright (C) 2006 Juerg Haefliger <juergh@gmail.com>
5 *
6 * This driver is based on the driver for kernel 2.4 by Mark D. Studebaker
7 * and its port to kernel 2.6 by Lars Ekman.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/jiffies.h>
28#include <linux/platform_device.h>
29#include <linux/hwmon.h>
30#include <linux/hwmon-sysfs.h>
31#include <linux/hwmon-vid.h>
32#include <linux/err.h>
33#include <linux/mutex.h>
34#include <asm/io.h>
35
36static int uch_config = -1;
37module_param(uch_config, int, 0);
38MODULE_PARM_DESC(uch_config, "Initialize the universal channel configuration");
39
40static int int_mode = -1;
41module_param(int_mode, int, 0);
42MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode");
43
44static struct platform_device *pdev;
45
46#define DRVNAME "vt1211"
47
48/* ---------------------------------------------------------------------
49 * Registers
50 *
51 * The sensors are defined as follows.
52 *
53 * Sensor Voltage Mode Temp Mode Notes (from the datasheet)
54 * -------- ------------ --------- --------------------------
55 * Reading 1 temp1 Intel thermal diode
56 * Reading 3 temp2 Internal thermal diode
57 * UCH1/Reading2 in0 temp3 NTC type thermistor
58 * UCH2 in1 temp4 +2.5V
59 * UCH3 in2 temp5 VccP
60 * UCH4 in3 temp6 +5V
61 * UCH5 in4 temp7 +12V
62 * 3.3V in5 Internal VDD (+3.3V)
63 *
64 * --------------------------------------------------------------------- */
65
66/* Voltages (in) numbered 0-5 (ix) */
67#define VT1211_REG_IN(ix) (0x21 + (ix))
68#define VT1211_REG_IN_MIN(ix) ((ix) == 0 ? 0x3e : 0x2a + 2 * (ix))
69#define VT1211_REG_IN_MAX(ix) ((ix) == 0 ? 0x3d : 0x29 + 2 * (ix))
70
71/* Temperatures (temp) numbered 0-6 (ix) */
72static u8 regtemp[] = {0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25};
73static u8 regtempmax[] = {0x39, 0x1d, 0x3d, 0x2b, 0x2d, 0x2f, 0x31};
74static u8 regtemphyst[] = {0x3a, 0x1e, 0x3e, 0x2c, 0x2e, 0x30, 0x32};
75
76/* Fans numbered 0-1 (ix) */
77#define VT1211_REG_FAN(ix) (0x29 + (ix))
78#define VT1211_REG_FAN_MIN(ix) (0x3b + (ix))
79#define VT1211_REG_FAN_DIV 0x47
80
81/* PWMs numbered 0-1 (ix) */
82/* Auto points numbered 0-3 (ap) */
83#define VT1211_REG_PWM(ix) (0x60 + (ix))
84#define VT1211_REG_PWM_CLK 0x50
85#define VT1211_REG_PWM_CTL 0x51
86#define VT1211_REG_PWM_AUTO_TEMP(ap) (0x55 - (ap))
87#define VT1211_REG_PWM_AUTO_PWM(ix, ap) (0x58 + 2 * (ix) - (ap))
88
89/* Miscellaneous registers */
90#define VT1211_REG_CONFIG 0x40
91#define VT1211_REG_ALARM1 0x41
92#define VT1211_REG_ALARM2 0x42
93#define VT1211_REG_VID 0x45
94#define VT1211_REG_UCH_CONFIG 0x4a
95#define VT1211_REG_TEMP1_CONFIG 0x4b
96#define VT1211_REG_TEMP2_CONFIG 0x4c
97
98/* In, temp & fan alarm bits */
99static const u8 bitalarmin[] = {11, 0, 1, 3, 8, 2, 9};
100static const u8 bitalarmtemp[] = {4, 15, 11, 0, 1, 3, 8};
101static const u8 bitalarmfan[] = {6, 7};
102
103/* ---------------------------------------------------------------------
104 * Data structures and manipulation thereof
105 * --------------------------------------------------------------------- */
106
107struct vt1211_data {
108 unsigned short addr;
109 const char *name;
110 struct class_device *class_dev;
111
112 struct mutex update_lock;
113 char valid; /* !=0 if following fields are valid */
114 unsigned long last_updated; /* In jiffies */
115
116 /* Register values */
117 u8 in[6];
118 u8 in_max[6];
119 u8 in_min[6];
120 u8 temp[7];
121 u8 temp_max[7];
122 u8 temp_hyst[7];
123 u8 fan[2];
124 u8 fan_min[2];
125 u8 fan_div[2];
126 u8 fan_ctl;
127 u8 pwm[2];
128 u8 pwm_ctl[2];
129 u8 pwm_clk;
130 u8 pwm_auto_temp[4];
131 u8 pwm_auto_pwm[2][4];
132 u8 vid; /* Read once at init time */
133 u8 vrm;
134 u8 uch_config; /* Read once at init time */
135 u16 alarms;
136};
137
138/* ix = [0-5] */
139#define ISVOLT(ix, uch_config) ((ix) > 4 ? 1 : \
140 !(((uch_config) >> ((ix) + 2)) & 1))
141
142/* ix = [0-6] */
143#define ISTEMP(ix, uch_config) ((ix) < 2 ? 1 : \
144 ((uch_config) >> (ix)) & 1)
145
146/* in5 (ix = 5) is special. It's the internal 3.3V so it's scaled in the
147 driver according to the VT1211 BIOS porting guide */
148#define IN_FROM_REG(ix, reg) ((reg) < 3 ? 0 : (ix) == 5 ? \
149 (((reg) - 3) * 15882 + 479) / 958 : \
150 (((reg) - 3) * 10000 + 479) / 958)
151#define IN_TO_REG(ix, val) (SENSORS_LIMIT((ix) == 5 ? \
152 ((val) * 958 + 7941) / 15882 + 3 : \
153 ((val) * 958 + 5000) / 10000 + 3, 0, 255))
154
155/* temp1 (ix = 0) is an intel thermal diode which is scaled in user space.
156 temp2 (ix = 1) is the internal temp diode so it's scaled in the driver
157 according to some measurements that I took on an EPIA M10000.
158 temp3-7 are thermistor based so the driver returns the voltage measured at
159 the pin (range 0V - 2.2V). */
160#define TEMP_FROM_REG(ix, reg) ((ix) == 0 ? (reg) * 1000 : \
161 (ix) == 1 ? (reg) < 51 ? 0 : \
162 ((reg) - 51) * 1000 : \
163 ((253 - (reg)) * 2200 + 105) / 210)
164#define TEMP_TO_REG(ix, val) SENSORS_LIMIT( \
165 ((ix) == 0 ? ((val) + 500) / 1000 : \
166 (ix) == 1 ? ((val) + 500) / 1000 + 51 : \
167 253 - ((val) * 210 + 1100) / 2200), 0, 255)
168
169#define DIV_FROM_REG(reg) (1 << (reg))
170
171#define RPM_FROM_REG(reg, div) (((reg) == 0) || ((reg) == 255) ? 0 : \
172 1310720 / (reg) / DIV_FROM_REG(div))
173#define RPM_TO_REG(val, div) ((val) == 0 ? 255 : \
174 SENSORS_LIMIT((1310720 / (val) / \
175 DIV_FROM_REG(div)), 1, 254))
176
177/* ---------------------------------------------------------------------
178 * Super-I/O constants and functions
179 * --------------------------------------------------------------------- */
180
181/* Configuration & data index port registers */
182#define SIO_REG_CIP 0x2e
183#define SIO_REG_DIP 0x2f
184
185/* Configuration registers */
186#define SIO_VT1211_LDN 0x07 /* logical device number */
187#define SIO_VT1211_DEVID 0x20 /* device ID */
188#define SIO_VT1211_DEVREV 0x21 /* device revision */
189#define SIO_VT1211_ACTIVE 0x30 /* HW monitor active */
190#define SIO_VT1211_BADDR 0x60 /* base I/O address */
191#define SIO_VT1211_ID 0x3c /* VT1211 device ID */
192
193/* VT1211 logical device numbers */
194#define SIO_VT1211_LDN_HWMON 0x0b /* HW monitor */
195
196static inline void superio_outb(int reg, int val)
197{
198 outb(reg, SIO_REG_CIP);
199 outb(val, SIO_REG_DIP);
200}
201
202static inline int superio_inb(int reg)
203{
204 outb(reg, SIO_REG_CIP);
205 return inb(SIO_REG_DIP);
206}
207
208static inline void superio_select(int ldn)
209{
210 outb(SIO_VT1211_LDN, SIO_REG_CIP);
211 outb(ldn, SIO_REG_DIP);
212}
213
214static inline void superio_enter(void)
215{
216 outb(0x87, SIO_REG_CIP);
217 outb(0x87, SIO_REG_CIP);
218}
219
220static inline void superio_exit(void)
221{
222 outb(0xaa, SIO_REG_CIP);
223}
224
225/* ---------------------------------------------------------------------
226 * Device I/O access
227 * --------------------------------------------------------------------- */
228
229static inline u8 vt1211_read8(struct vt1211_data *data, u8 reg)
230{
231 return inb(data->addr + reg);
232}
233
234static inline void vt1211_write8(struct vt1211_data *data, u8 reg, u8 val)
235{
236 outb(val, data->addr + reg);
237}
238
239static struct vt1211_data *vt1211_update_device(struct device *dev)
240{
241 struct vt1211_data *data = dev_get_drvdata(dev);
242 int ix, val;
243
244 mutex_lock(&data->update_lock);
245
246 /* registers cache is refreshed after 1 second */
247 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
248 /* read VID */
249 data->vid = vt1211_read8(data, VT1211_REG_VID) & 0x1f;
250
251 /* voltage (in) registers */
252 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
253 if (ISVOLT(ix, data->uch_config)) {
254 data->in[ix] = vt1211_read8(data,
255 VT1211_REG_IN(ix));
256 data->in_min[ix] = vt1211_read8(data,
257 VT1211_REG_IN_MIN(ix));
258 data->in_max[ix] = vt1211_read8(data,
259 VT1211_REG_IN_MAX(ix));
260 }
261 }
262
263 /* temp registers */
264 for (ix = 0; ix < ARRAY_SIZE(data->temp); ix++) {
265 if (ISTEMP(ix, data->uch_config)) {
266 data->temp[ix] = vt1211_read8(data,
267 regtemp[ix]);
268 data->temp_max[ix] = vt1211_read8(data,
269 regtempmax[ix]);
270 data->temp_hyst[ix] = vt1211_read8(data,
271 regtemphyst[ix]);
272 }
273 }
274
275 /* fan & pwm registers */
276 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) {
277 data->fan[ix] = vt1211_read8(data,
278 VT1211_REG_FAN(ix));
279 data->fan_min[ix] = vt1211_read8(data,
280 VT1211_REG_FAN_MIN(ix));
281 data->pwm[ix] = vt1211_read8(data,
282 VT1211_REG_PWM(ix));
283 }
284 val = vt1211_read8(data, VT1211_REG_FAN_DIV);
285 data->fan_div[0] = (val >> 4) & 3;
286 data->fan_div[1] = (val >> 6) & 3;
287 data->fan_ctl = val & 0xf;
288
289 val = vt1211_read8(data, VT1211_REG_PWM_CTL);
290 data->pwm_ctl[0] = val & 0xf;
291 data->pwm_ctl[1] = (val >> 4) & 0xf;
292
293 data->pwm_clk = vt1211_read8(data, VT1211_REG_PWM_CLK);
294
295 /* pwm & temp auto point registers */
296 data->pwm_auto_pwm[0][1] = vt1211_read8(data,
297 VT1211_REG_PWM_AUTO_PWM(0, 1));
298 data->pwm_auto_pwm[0][2] = vt1211_read8(data,
299 VT1211_REG_PWM_AUTO_PWM(0, 2));
300 data->pwm_auto_pwm[1][1] = vt1211_read8(data,
301 VT1211_REG_PWM_AUTO_PWM(1, 1));
302 data->pwm_auto_pwm[1][2] = vt1211_read8(data,
303 VT1211_REG_PWM_AUTO_PWM(1, 2));
304 for (ix = 0; ix < ARRAY_SIZE(data->pwm_auto_temp); ix++) {
305 data->pwm_auto_temp[ix] = vt1211_read8(data,
306 VT1211_REG_PWM_AUTO_TEMP(ix));
307 }
308
309 /* alarm registers */
310 data->alarms = (vt1211_read8(data, VT1211_REG_ALARM2) << 8) |
311 vt1211_read8(data, VT1211_REG_ALARM1);
312
313 data->last_updated = jiffies;
314 data->valid = 1;
315 }
316
317 mutex_unlock(&data->update_lock);
318
319 return data;
320}
321
322/* ---------------------------------------------------------------------
323 * Voltage sysfs interfaces
324 * ix = [0-5]
325 * --------------------------------------------------------------------- */
326
327#define SHOW_IN_INPUT 0
328#define SHOW_SET_IN_MIN 1
329#define SHOW_SET_IN_MAX 2
330#define SHOW_IN_ALARM 3
331
332static ssize_t show_in(struct device *dev, struct device_attribute *attr,
333 char *buf)
334{
335 struct vt1211_data *data = vt1211_update_device(dev);
336 struct sensor_device_attribute_2 *sensor_attr_2 =
337 to_sensor_dev_attr_2(attr);
338 int ix = sensor_attr_2->index;
339 int fn = sensor_attr_2->nr;
340 int res;
341
342 switch (fn) {
343 case SHOW_IN_INPUT:
344 res = IN_FROM_REG(ix, data->in[ix]);
345 break;
346 case SHOW_SET_IN_MIN:
347 res = IN_FROM_REG(ix, data->in_min[ix]);
348 break;
349 case SHOW_SET_IN_MAX:
350 res = IN_FROM_REG(ix, data->in_max[ix]);
351 break;
352 case SHOW_IN_ALARM:
353 res = (data->alarms >> bitalarmin[ix]) & 1;
354 break;
355 default:
356 res = 0;
357 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
358 }
359
360 return sprintf(buf, "%d\n", res);
361}
362
363static ssize_t set_in(struct device *dev, struct device_attribute *attr,
364 const char *buf, size_t count)
365{
366 struct vt1211_data *data = dev_get_drvdata(dev);
367 struct sensor_device_attribute_2 *sensor_attr_2 =
368 to_sensor_dev_attr_2(attr);
369 int ix = sensor_attr_2->index;
370 int fn = sensor_attr_2->nr;
371 long val = simple_strtol(buf, NULL, 10);
372
373 mutex_lock(&data->update_lock);
374 switch (fn) {
375 case SHOW_SET_IN_MIN:
376 data->in_min[ix] = IN_TO_REG(ix, val);
377 vt1211_write8(data, VT1211_REG_IN_MIN(ix), data->in_min[ix]);
378 break;
379 case SHOW_SET_IN_MAX:
380 data->in_max[ix] = IN_TO_REG(ix, val);
381 vt1211_write8(data, VT1211_REG_IN_MAX(ix), data->in_max[ix]);
382 break;
383 default:
384 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
385 }
386 mutex_unlock(&data->update_lock);
387
388 return count;
389}
390
391/* ---------------------------------------------------------------------
392 * Temperature sysfs interfaces
393 * ix = [0-6]
394 * --------------------------------------------------------------------- */
395
396#define SHOW_TEMP_INPUT 0
397#define SHOW_SET_TEMP_MAX 1
398#define SHOW_SET_TEMP_MAX_HYST 2
399#define SHOW_TEMP_ALARM 3
400
401static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
402 char *buf)
403{
404 struct vt1211_data *data = vt1211_update_device(dev);
405 struct sensor_device_attribute_2 *sensor_attr_2 =
406 to_sensor_dev_attr_2(attr);
407 int ix = sensor_attr_2->index;
408 int fn = sensor_attr_2->nr;
409 int res;
410
411 switch (fn) {
412 case SHOW_TEMP_INPUT:
413 res = TEMP_FROM_REG(ix, data->temp[ix]);
414 break;
415 case SHOW_SET_TEMP_MAX:
416 res = TEMP_FROM_REG(ix, data->temp_max[ix]);
417 break;
418 case SHOW_SET_TEMP_MAX_HYST:
419 res = TEMP_FROM_REG(ix, data->temp_hyst[ix]);
420 break;
421 case SHOW_TEMP_ALARM:
422 res = (data->alarms >> bitalarmtemp[ix]) & 1;
423 break;
424 default:
425 res = 0;
426 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
427 }
428
429 return sprintf(buf, "%d\n", res);
430}
431
432static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
433 const char *buf, size_t count)
434{
435 struct vt1211_data *data = dev_get_drvdata(dev);
436 struct sensor_device_attribute_2 *sensor_attr_2 =
437 to_sensor_dev_attr_2(attr);
438 int ix = sensor_attr_2->index;
439 int fn = sensor_attr_2->nr;
440 long val = simple_strtol(buf, NULL, 10);
441
442 mutex_lock(&data->update_lock);
443 switch (fn) {
444 case SHOW_SET_TEMP_MAX:
445 data->temp_max[ix] = TEMP_TO_REG(ix, val);
446 vt1211_write8(data, regtempmax[ix],
447 data->temp_max[ix]);
448 break;
449 case SHOW_SET_TEMP_MAX_HYST:
450 data->temp_hyst[ix] = TEMP_TO_REG(ix, val);
451 vt1211_write8(data, regtemphyst[ix],
452 data->temp_hyst[ix]);
453 break;
454 default:
455 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
456 }
457 mutex_unlock(&data->update_lock);
458
459 return count;
460}
461
462/* ---------------------------------------------------------------------
463 * Fan sysfs interfaces
464 * ix = [0-1]
465 * --------------------------------------------------------------------- */
466
467#define SHOW_FAN_INPUT 0
468#define SHOW_SET_FAN_MIN 1
469#define SHOW_SET_FAN_DIV 2
470#define SHOW_FAN_ALARM 3
471
472static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
473 char *buf)
474{
475 struct vt1211_data *data = vt1211_update_device(dev);
476 struct sensor_device_attribute_2 *sensor_attr_2 =
477 to_sensor_dev_attr_2(attr);
478 int ix = sensor_attr_2->index;
479 int fn = sensor_attr_2->nr;
480 int res;
481
482 switch (fn) {
483 case SHOW_FAN_INPUT:
484 res = RPM_FROM_REG(data->fan[ix], data->fan_div[ix]);
485 break;
486 case SHOW_SET_FAN_MIN:
487 res = RPM_FROM_REG(data->fan_min[ix], data->fan_div[ix]);
488 break;
489 case SHOW_SET_FAN_DIV:
490 res = DIV_FROM_REG(data->fan_div[ix]);
491 break;
492 case SHOW_FAN_ALARM:
493 res = (data->alarms >> bitalarmfan[ix]) & 1;
494 break;
495 default:
496 res = 0;
497 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
498 }
499
500 return sprintf(buf, "%d\n", res);
501}
502
503static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
504 const char *buf, size_t count)
505{
506 struct vt1211_data *data = dev_get_drvdata(dev);
507 struct sensor_device_attribute_2 *sensor_attr_2 =
508 to_sensor_dev_attr_2(attr);
509 int ix = sensor_attr_2->index;
510 int fn = sensor_attr_2->nr;
511 long val = simple_strtol(buf, NULL, 10);
512 int reg;
513
514 mutex_lock(&data->update_lock);
515
516 /* sync the data cache */
517 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
518 data->fan_div[0] = (reg >> 4) & 3;
519 data->fan_div[1] = (reg >> 6) & 3;
520 data->fan_ctl = reg & 0xf;
521
522 switch (fn) {
523 case SHOW_SET_FAN_MIN:
524 data->fan_min[ix] = RPM_TO_REG(val, data->fan_div[ix]);
525 vt1211_write8(data, VT1211_REG_FAN_MIN(ix),
526 data->fan_min[ix]);
527 break;
528 case SHOW_SET_FAN_DIV:
529 switch (val) {
530 case 1: data->fan_div[ix] = 0; break;
531 case 2: data->fan_div[ix] = 1; break;
532 case 4: data->fan_div[ix] = 2; break;
533 case 8: data->fan_div[ix] = 3; break;
534 default:
535 count = -EINVAL;
536 dev_warn(dev, "fan div value %ld not "
537 "supported. Choose one of 1, 2, "
538 "4, or 8.\n", val);
539 goto EXIT;
540 }
541 vt1211_write8(data, VT1211_REG_FAN_DIV,
542 ((data->fan_div[1] << 6) |
543 (data->fan_div[0] << 4) |
544 data->fan_ctl));
545 break;
546 default:
547 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
548 }
549
550EXIT:
551 mutex_unlock(&data->update_lock);
552 return count;
553}
554
555/* ---------------------------------------------------------------------
556 * PWM sysfs interfaces
557 * ix = [0-1]
558 * --------------------------------------------------------------------- */
559
560#define SHOW_PWM 0
561#define SHOW_SET_PWM_ENABLE 1
562#define SHOW_SET_PWM_FREQ 2
563#define SHOW_SET_PWM_AUTO_CHANNELS_TEMP 3
564
565static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
566 char *buf)
567{
568 struct vt1211_data *data = vt1211_update_device(dev);
569 struct sensor_device_attribute_2 *sensor_attr_2 =
570 to_sensor_dev_attr_2(attr);
571 int ix = sensor_attr_2->index;
572 int fn = sensor_attr_2->nr;
573 int res;
574
575 switch (fn) {
576 case SHOW_PWM:
577 res = data->pwm[ix];
578 break;
579 case SHOW_SET_PWM_ENABLE:
580 res = ((data->pwm_ctl[ix] >> 3) & 1) ? 2 : 0;
581 break;
582 case SHOW_SET_PWM_FREQ:
583 res = 90000 >> (data->pwm_clk & 7);
584 break;
585 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
586 res = (data->pwm_ctl[ix] & 7) + 1;
587 break;
588 default:
589 res = 0;
590 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
591 }
592
593 return sprintf(buf, "%d\n", res);
594}
595
596static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
597 const char *buf, size_t count)
598{
599 struct vt1211_data *data = dev_get_drvdata(dev);
600 struct sensor_device_attribute_2 *sensor_attr_2 =
601 to_sensor_dev_attr_2(attr);
602 int ix = sensor_attr_2->index;
603 int fn = sensor_attr_2->nr;
604 long val = simple_strtol(buf, NULL, 10);
605 int tmp, reg;
606
607 mutex_lock(&data->update_lock);
608
609 switch (fn) {
610 case SHOW_SET_PWM_ENABLE:
611 /* sync the data cache */
612 reg = vt1211_read8(data, VT1211_REG_FAN_DIV);
613 data->fan_div[0] = (reg >> 4) & 3;
614 data->fan_div[1] = (reg >> 6) & 3;
615 data->fan_ctl = reg & 0xf;
616 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
617 data->pwm_ctl[0] = reg & 0xf;
618 data->pwm_ctl[1] = (reg >> 4) & 0xf;
619 switch (val) {
620 case 0:
621 data->pwm_ctl[ix] &= 7;
622 /* disable SmartGuardian if both PWM outputs are
623 * disabled */
624 if ((data->pwm_ctl[ix ^ 1] & 1) == 0) {
625 data->fan_ctl &= 0xe;
626 }
627 break;
628 case 2:
629 data->pwm_ctl[ix] |= 8;
630 data->fan_ctl |= 1;
631 break;
632 default:
633 count = -EINVAL;
634 dev_warn(dev, "pwm mode %ld not supported. "
635 "Choose one of 0 or 2.\n", val);
636 goto EXIT;
637 }
638 vt1211_write8(data, VT1211_REG_PWM_CTL,
639 ((data->pwm_ctl[1] << 4) |
640 data->pwm_ctl[0]));
641 vt1211_write8(data, VT1211_REG_FAN_DIV,
642 ((data->fan_div[1] << 6) |
643 (data->fan_div[0] << 4) |
644 data->fan_ctl));
645 break;
646 case SHOW_SET_PWM_FREQ:
647 val = 135000 / SENSORS_LIMIT(val, 135000 >> 7, 135000);
648 /* calculate tmp = log2(val) */
649 tmp = 0;
650 for (val >>= 1; val > 0; val >>= 1) {
651 tmp++;
652 }
653 /* sync the data cache */
654 reg = vt1211_read8(data, VT1211_REG_PWM_CLK);
655 data->pwm_clk = (reg & 0xf8) | tmp;
656 vt1211_write8(data, VT1211_REG_PWM_CLK, data->pwm_clk);
657 break;
658 case SHOW_SET_PWM_AUTO_CHANNELS_TEMP:
659 if ((val < 1) || (val > 7)) {
660 count = -EINVAL;
661 dev_warn(dev, "temp channel %ld not supported. "
662 "Choose a value between 1 and 7.\n", val);
663 goto EXIT;
664 }
665 if (!ISTEMP(val - 1, data->uch_config)) {
666 count = -EINVAL;
667 dev_warn(dev, "temp channel %ld is not available.\n",
668 val);
669 goto EXIT;
670 }
671 /* sync the data cache */
672 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
673 data->pwm_ctl[0] = reg & 0xf;
674 data->pwm_ctl[1] = (reg >> 4) & 0xf;
675 data->pwm_ctl[ix] = (data->pwm_ctl[ix] & 8) | (val - 1);
676 vt1211_write8(data, VT1211_REG_PWM_CTL,
677 ((data->pwm_ctl[1] << 4) | data->pwm_ctl[0]));
678 break;
679 default:
680 dev_dbg(dev, "Unknown attr fetch (%d)\n", fn);
681 }
682
683EXIT:
684 mutex_unlock(&data->update_lock);
685 return count;
686}
687
688/* ---------------------------------------------------------------------
689 * PWM auto point definitions
690 * ix = [0-1]
691 * ap = [0-3]
692 * --------------------------------------------------------------------- */
693
694/*
695 * pwm[ix+1]_auto_point[ap+1]_temp mapping table:
696 * Note that there is only a single set of temp auto points that controls both
697 * PWM controllers. We still create 2 sets of sysfs files to make it look
698 * more consistent even though they map to the same registers.
699 *
700 * ix ap : description
701 * -------------------
702 * 0 0 : pwm1/2 off temperature (pwm_auto_temp[0])
703 * 0 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
704 * 0 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
705 * 0 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
706 * 1 0 : pwm1/2 off temperature (pwm_auto_temp[0])
707 * 1 1 : pwm1/2 low speed temperature (pwm_auto_temp[1])
708 * 1 2 : pwm1/2 high speed temperature (pwm_auto_temp[2])
709 * 1 3 : pwm1/2 full speed temperature (pwm_auto_temp[3])
710 */
711
712static ssize_t show_pwm_auto_point_temp(struct device *dev,
713 struct device_attribute *attr,
714 char *buf)
715{
716 struct vt1211_data *data = vt1211_update_device(dev);
717 struct sensor_device_attribute_2 *sensor_attr_2 =
718 to_sensor_dev_attr_2(attr);
719 int ix = sensor_attr_2->index;
720 int ap = sensor_attr_2->nr;
721
722 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->pwm_ctl[ix] & 7,
723 data->pwm_auto_temp[ap]));
724}
725
726static ssize_t set_pwm_auto_point_temp(struct device *dev,
727 struct device_attribute *attr,
728 const char *buf, size_t count)
729{
730 struct vt1211_data *data = dev_get_drvdata(dev);
731 struct sensor_device_attribute_2 *sensor_attr_2 =
732 to_sensor_dev_attr_2(attr);
733 int ix = sensor_attr_2->index;
734 int ap = sensor_attr_2->nr;
735 long val = simple_strtol(buf, NULL, 10);
736 int reg;
737
738 mutex_lock(&data->update_lock);
739
740 /* sync the data cache */
741 reg = vt1211_read8(data, VT1211_REG_PWM_CTL);
742 data->pwm_ctl[0] = reg & 0xf;
743 data->pwm_ctl[1] = (reg >> 4) & 0xf;
744
745 data->pwm_auto_temp[ap] = TEMP_TO_REG(data->pwm_ctl[ix] & 7, val);
746 vt1211_write8(data, VT1211_REG_PWM_AUTO_TEMP(ap),
747 data->pwm_auto_temp[ap]);
748 mutex_unlock(&data->update_lock);
749
750 return count;
751}
752
753/*
754 * pwm[ix+1]_auto_point[ap+1]_pwm mapping table:
755 * Note that the PWM auto points 0 & 3 are hard-wired in the VT1211 and can't
756 * be changed.
757 *
758 * ix ap : description
759 * -------------------
760 * 0 0 : pwm1 off (pwm_auto_pwm[0][0], hard-wired to 0)
761 * 0 1 : pwm1 low speed duty cycle (pwm_auto_pwm[0][1])
762 * 0 2 : pwm1 high speed duty cycle (pwm_auto_pwm[0][2])
763 * 0 3 : pwm1 full speed (pwm_auto_pwm[0][3], hard-wired to 255)
764 * 1 0 : pwm2 off (pwm_auto_pwm[1][0], hard-wired to 0)
765 * 1 1 : pwm2 low speed duty cycle (pwm_auto_pwm[1][1])
766 * 1 2 : pwm2 high speed duty cycle (pwm_auto_pwm[1][2])
767 * 1 3 : pwm2 full speed (pwm_auto_pwm[1][3], hard-wired to 255)
768*/
769
770static ssize_t show_pwm_auto_point_pwm(struct device *dev,
771 struct device_attribute *attr,
772 char *buf)
773{
774 struct vt1211_data *data = vt1211_update_device(dev);
775 struct sensor_device_attribute_2 *sensor_attr_2 =
776 to_sensor_dev_attr_2(attr);
777 int ix = sensor_attr_2->index;
778 int ap = sensor_attr_2->nr;
779
780 return sprintf(buf, "%d\n", data->pwm_auto_pwm[ix][ap]);
781}
782
783static ssize_t set_pwm_auto_point_pwm(struct device *dev,
784 struct device_attribute *attr,
785 const char *buf, size_t count)
786{
787 struct vt1211_data *data = dev_get_drvdata(dev);
788 struct sensor_device_attribute_2 *sensor_attr_2 =
789 to_sensor_dev_attr_2(attr);
790 int ix = sensor_attr_2->index;
791 int ap = sensor_attr_2->nr;
792 long val = simple_strtol(buf, NULL, 10);
793
794 if ((val < 0) || (val > 255)) {
795 dev_err(dev, "pwm value %ld is out of range. "
796 "Choose a value between 0 and 255." , val);
797 return -EINVAL;
798 }
799
800 mutex_lock(&data->update_lock);
801 data->pwm_auto_pwm[ix][ap] = val;
802 vt1211_write8(data, VT1211_REG_PWM_AUTO_PWM(ix, ap),
803 data->pwm_auto_pwm[ix][ap]);
804 mutex_unlock(&data->update_lock);
805
806 return count;
807}
808
809/* ---------------------------------------------------------------------
810 * Miscellaneous sysfs interfaces (VRM, VID, name, and (legacy) alarms)
811 * --------------------------------------------------------------------- */
812
813static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
814 char *buf)
815{
816 struct vt1211_data *data = dev_get_drvdata(dev);
817
818 return sprintf(buf, "%d\n", data->vrm);
819}
820
821static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
822 const char *buf, size_t count)
823{
824 struct vt1211_data *data = dev_get_drvdata(dev);
825 long val = simple_strtol(buf, NULL, 10);
826
827 data->vrm = val;
828
829 return count;
830}
831
832static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
833 char *buf)
834{
835 struct vt1211_data *data = dev_get_drvdata(dev);
836
837 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
838}
839
840static ssize_t show_name(struct device *dev,
841 struct device_attribute *attr, char *buf)
842{
843 struct vt1211_data *data = dev_get_drvdata(dev);
844
845 return sprintf(buf, "%s\n", data->name);
846}
847
848static ssize_t show_alarms(struct device *dev,
849 struct device_attribute *attr, char *buf)
850{
851 struct vt1211_data *data = vt1211_update_device(dev);
852
853 return sprintf(buf, "%d\n", data->alarms);
854}
855
856/* ---------------------------------------------------------------------
857 * Device attribute structs
858 * --------------------------------------------------------------------- */
859
860#define SENSOR_ATTR_IN_INPUT(ix) \
861 SENSOR_ATTR_2(in##ix##_input, S_IRUGO, \
862 show_in, NULL, SHOW_IN_INPUT, ix)
863
864static struct sensor_device_attribute_2 vt1211_sysfs_in_input[] = {
865 SENSOR_ATTR_IN_INPUT(0),
866 SENSOR_ATTR_IN_INPUT(1),
867 SENSOR_ATTR_IN_INPUT(2),
868 SENSOR_ATTR_IN_INPUT(3),
869 SENSOR_ATTR_IN_INPUT(4),
870 SENSOR_ATTR_IN_INPUT(5),
871};
872
873#define SENSOR_ATTR_IN_MIN(ix) \
874 SENSOR_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \
875 show_in, set_in, SHOW_SET_IN_MIN, ix)
876
877static struct sensor_device_attribute_2 vt1211_sysfs_in_min[] = {
878 SENSOR_ATTR_IN_MIN(0),
879 SENSOR_ATTR_IN_MIN(1),
880 SENSOR_ATTR_IN_MIN(2),
881 SENSOR_ATTR_IN_MIN(3),
882 SENSOR_ATTR_IN_MIN(4),
883 SENSOR_ATTR_IN_MIN(5),
884};
885
886#define SENSOR_ATTR_IN_MAX(ix) \
887 SENSOR_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \
888 show_in, set_in, SHOW_SET_IN_MAX, ix)
889
890static struct sensor_device_attribute_2 vt1211_sysfs_in_max[] = {
891 SENSOR_ATTR_IN_MAX(0),
892 SENSOR_ATTR_IN_MAX(1),
893 SENSOR_ATTR_IN_MAX(2),
894 SENSOR_ATTR_IN_MAX(3),
895 SENSOR_ATTR_IN_MAX(4),
896 SENSOR_ATTR_IN_MAX(5),
897};
898
899#define SENSOR_ATTR_IN_ALARM(ix) \
900 SENSOR_ATTR_2(in##ix##_alarm, S_IRUGO, \
901 show_in, NULL, SHOW_IN_ALARM, ix)
902
903static struct sensor_device_attribute_2 vt1211_sysfs_in_alarm[] = {
904 SENSOR_ATTR_IN_ALARM(0),
905 SENSOR_ATTR_IN_ALARM(1),
906 SENSOR_ATTR_IN_ALARM(2),
907 SENSOR_ATTR_IN_ALARM(3),
908 SENSOR_ATTR_IN_ALARM(4),
909 SENSOR_ATTR_IN_ALARM(5),
910};
911
912#define SENSOR_ATTR_TEMP_INPUT(ix) \
913 SENSOR_ATTR_2(temp##ix##_input, S_IRUGO, \
914 show_temp, NULL, SHOW_TEMP_INPUT, ix-1)
915
916static struct sensor_device_attribute_2 vt1211_sysfs_temp_input[] = {
917 SENSOR_ATTR_TEMP_INPUT(1),
918 SENSOR_ATTR_TEMP_INPUT(2),
919 SENSOR_ATTR_TEMP_INPUT(3),
920 SENSOR_ATTR_TEMP_INPUT(4),
921 SENSOR_ATTR_TEMP_INPUT(5),
922 SENSOR_ATTR_TEMP_INPUT(6),
923 SENSOR_ATTR_TEMP_INPUT(7),
924};
925
926#define SENSOR_ATTR_TEMP_MAX(ix) \
927 SENSOR_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \
928 show_temp, set_temp, SHOW_SET_TEMP_MAX, ix-1)
929
930static struct sensor_device_attribute_2 vt1211_sysfs_temp_max[] = {
931 SENSOR_ATTR_TEMP_MAX(1),
932 SENSOR_ATTR_TEMP_MAX(2),
933 SENSOR_ATTR_TEMP_MAX(3),
934 SENSOR_ATTR_TEMP_MAX(4),
935 SENSOR_ATTR_TEMP_MAX(5),
936 SENSOR_ATTR_TEMP_MAX(6),
937 SENSOR_ATTR_TEMP_MAX(7),
938};
939
940#define SENSOR_ATTR_TEMP_MAX_HYST(ix) \
941 SENSOR_ATTR_2(temp##ix##_max_hyst, S_IRUGO | S_IWUSR, \
942 show_temp, set_temp, SHOW_SET_TEMP_MAX_HYST, ix-1)
943
944static struct sensor_device_attribute_2 vt1211_sysfs_temp_max_hyst[] = {
945 SENSOR_ATTR_TEMP_MAX_HYST(1),
946 SENSOR_ATTR_TEMP_MAX_HYST(2),
947 SENSOR_ATTR_TEMP_MAX_HYST(3),
948 SENSOR_ATTR_TEMP_MAX_HYST(4),
949 SENSOR_ATTR_TEMP_MAX_HYST(5),
950 SENSOR_ATTR_TEMP_MAX_HYST(6),
951 SENSOR_ATTR_TEMP_MAX_HYST(7),
952};
953
954#define SENSOR_ATTR_TEMP_ALARM(ix) \
955 SENSOR_ATTR_2(temp##ix##_alarm, S_IRUGO, \
956 show_temp, NULL, SHOW_TEMP_ALARM, ix-1)
957
958static struct sensor_device_attribute_2 vt1211_sysfs_temp_alarm[] = {
959 SENSOR_ATTR_TEMP_ALARM(1),
960 SENSOR_ATTR_TEMP_ALARM(2),
961 SENSOR_ATTR_TEMP_ALARM(3),
962 SENSOR_ATTR_TEMP_ALARM(4),
963 SENSOR_ATTR_TEMP_ALARM(5),
964 SENSOR_ATTR_TEMP_ALARM(6),
965 SENSOR_ATTR_TEMP_ALARM(7),
966};
967
968#define SENSOR_ATTR_FAN(ix) \
969 SENSOR_ATTR_2(fan##ix##_input, S_IRUGO, \
970 show_fan, NULL, SHOW_FAN_INPUT, ix-1), \
971 SENSOR_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \
972 show_fan, set_fan, SHOW_SET_FAN_MIN, ix-1), \
973 SENSOR_ATTR_2(fan##ix##_div, S_IRUGO | S_IWUSR, \
974 show_fan, set_fan, SHOW_SET_FAN_DIV, ix-1), \
975 SENSOR_ATTR_2(fan##ix##_alarm, S_IRUGO, \
976 show_fan, NULL, SHOW_FAN_ALARM, ix-1)
977
978#define SENSOR_ATTR_PWM(ix) \
979 SENSOR_ATTR_2(pwm##ix, S_IRUGO, \
980 show_pwm, NULL, SHOW_PWM, ix-1), \
981 SENSOR_ATTR_2(pwm##ix##_enable, S_IRUGO | S_IWUSR, \
982 show_pwm, set_pwm, SHOW_SET_PWM_ENABLE, ix-1), \
983 SENSOR_ATTR_2(pwm##ix##_auto_channels_temp, S_IRUGO | S_IWUSR, \
984 show_pwm, set_pwm, SHOW_SET_PWM_AUTO_CHANNELS_TEMP, ix-1)
985
986#define SENSOR_ATTR_PWM_FREQ(ix) \
987 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \
988 show_pwm, set_pwm, SHOW_SET_PWM_FREQ, ix-1)
989
990#define SENSOR_ATTR_PWM_FREQ_RO(ix) \
991 SENSOR_ATTR_2(pwm##ix##_freq, S_IRUGO, \
992 show_pwm, NULL, SHOW_SET_PWM_FREQ, ix-1)
993
994#define SENSOR_ATTR_PWM_AUTO_POINT_TEMP(ix, ap) \
995 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO | S_IWUSR, \
996 show_pwm_auto_point_temp, set_pwm_auto_point_temp, \
997 ap-1, ix-1)
998
999#define SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(ix, ap) \
1000 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_temp, S_IRUGO, \
1001 show_pwm_auto_point_temp, NULL, \
1002 ap-1, ix-1)
1003
1004#define SENSOR_ATTR_PWM_AUTO_POINT_PWM(ix, ap) \
1005 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO | S_IWUSR, \
1006 show_pwm_auto_point_pwm, set_pwm_auto_point_pwm, \
1007 ap-1, ix-1)
1008
1009#define SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(ix, ap) \
1010 SENSOR_ATTR_2(pwm##ix##_auto_point##ap##_pwm, S_IRUGO, \
1011 show_pwm_auto_point_pwm, NULL, \
1012 ap-1, ix-1)
1013
1014static struct sensor_device_attribute_2 vt1211_sysfs_fan_pwm[] = {
1015 SENSOR_ATTR_FAN(1),
1016 SENSOR_ATTR_FAN(2),
1017 SENSOR_ATTR_PWM(1),
1018 SENSOR_ATTR_PWM(2),
1019 SENSOR_ATTR_PWM_FREQ(1),
1020 SENSOR_ATTR_PWM_FREQ_RO(2),
1021 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 1),
1022 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 2),
1023 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 3),
1024 SENSOR_ATTR_PWM_AUTO_POINT_TEMP(1, 4),
1025 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 1),
1026 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 2),
1027 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 3),
1028 SENSOR_ATTR_PWM_AUTO_POINT_TEMP_RO(2, 4),
1029 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 1),
1030 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 2),
1031 SENSOR_ATTR_PWM_AUTO_POINT_PWM(1, 3),
1032 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(1, 4),
1033 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 1),
1034 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 2),
1035 SENSOR_ATTR_PWM_AUTO_POINT_PWM(2, 3),
1036 SENSOR_ATTR_PWM_AUTO_POINT_PWM_RO(2, 4),
1037};
1038
1039static struct device_attribute vt1211_sysfs_misc[] = {
1040 __ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm),
1041 __ATTR(cpu0_vid, S_IRUGO, show_vid, NULL),
1042 __ATTR(name, S_IRUGO, show_name, NULL),
1043 __ATTR(alarms, S_IRUGO, show_alarms, NULL),
1044};
1045
1046/* ---------------------------------------------------------------------
1047 * Device registration and initialization
1048 * --------------------------------------------------------------------- */
1049
1050static void __devinit vt1211_init_device(struct vt1211_data *data)
1051{
1052 /* set VRM */
1053 data->vrm = vid_which_vrm();
1054
1055 /* Read (and initialize) UCH config */
1056 data->uch_config = vt1211_read8(data, VT1211_REG_UCH_CONFIG);
1057 if (uch_config > -1) {
1058 data->uch_config = (data->uch_config & 0x83) |
1059 (uch_config << 2);
1060 vt1211_write8(data, VT1211_REG_UCH_CONFIG, data->uch_config);
1061 }
1062
1063 /* Initialize the interrupt mode (if request at module load time).
1064 * The VT1211 implements 3 different modes for clearing interrupts:
1065 * 0: Clear INT when status register is read. Regenerate INT as long
1066 * as temp stays above hysteresis limit.
1067 * 1: Clear INT when status register is read. DON'T regenerate INT
1068 * until temp falls below hysteresis limit and exceeds hot limit
1069 * again.
1070 * 2: Clear INT when temp falls below max limit.
1071 *
1072 * The driver only allows to force mode 0 since that's the only one
1073 * that makes sense for 'sensors' */
1074 if (int_mode == 0) {
1075 vt1211_write8(data, VT1211_REG_TEMP1_CONFIG, 0);
1076 vt1211_write8(data, VT1211_REG_TEMP2_CONFIG, 0);
1077 }
1078
1079 /* Fill in some hard wired values into our data struct */
1080 data->pwm_auto_pwm[0][3] = 255;
1081 data->pwm_auto_pwm[1][3] = 255;
1082}
1083
1084static void vt1211_remove_sysfs(struct platform_device *pdev)
1085{
1086 struct device *dev = &pdev->dev;
1087 int i;
1088
1089 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1090 device_remove_file(dev,
1091 &vt1211_sysfs_in_input[i].dev_attr);
1092 device_remove_file(dev,
1093 &vt1211_sysfs_in_min[i].dev_attr);
1094 device_remove_file(dev,
1095 &vt1211_sysfs_in_max[i].dev_attr);
1096 device_remove_file(dev,
1097 &vt1211_sysfs_in_alarm[i].dev_attr);
1098 }
1099 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1100 device_remove_file(dev,
1101 &vt1211_sysfs_temp_input[i].dev_attr);
1102 device_remove_file(dev,
1103 &vt1211_sysfs_temp_max[i].dev_attr);
1104 device_remove_file(dev,
1105 &vt1211_sysfs_temp_max_hyst[i].dev_attr);
1106 device_remove_file(dev,
1107 &vt1211_sysfs_temp_alarm[i].dev_attr);
1108 }
1109 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1110 device_remove_file(dev,
1111 &vt1211_sysfs_fan_pwm[i].dev_attr);
1112 }
1113 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1114 device_remove_file(dev, &vt1211_sysfs_misc[i]);
1115 }
1116}
1117
1118static int __devinit vt1211_probe(struct platform_device *pdev)
1119{
1120 struct device *dev = &pdev->dev;
1121 struct vt1211_data *data;
1122 struct resource *res;
1123 int i, err;
1124
1125 if (!(data = kzalloc(sizeof(struct vt1211_data), GFP_KERNEL))) {
1126 err = -ENOMEM;
1127 dev_err(dev, "Out of memory\n");
1128 goto EXIT;
1129 }
1130
1131 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1132 data->addr = res->start;
1133 data->name = DRVNAME;
1134 mutex_init(&data->update_lock);
1135
1136 platform_set_drvdata(pdev, data);
1137
1138 /* Initialize the VT1211 chip */
1139 vt1211_init_device(data);
1140
1141 /* Create sysfs interface files */
1142 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_in_input); i++) {
1143 if (ISVOLT(i, data->uch_config)) {
1144 if ((err = device_create_file(dev,
1145 &vt1211_sysfs_in_input[i].dev_attr)) ||
1146 (err = device_create_file(dev,
1147 &vt1211_sysfs_in_min[i].dev_attr)) ||
1148 (err = device_create_file(dev,
1149 &vt1211_sysfs_in_max[i].dev_attr)) ||
1150 (err = device_create_file(dev,
1151 &vt1211_sysfs_in_alarm[i].dev_attr))) {
1152 goto EXIT_DEV_REMOVE;
1153 }
1154 }
1155 }
1156 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_temp_input); i++) {
1157 if (ISTEMP(i, data->uch_config)) {
1158 if ((err = device_create_file(dev,
1159 &vt1211_sysfs_temp_input[i].dev_attr)) ||
1160 (err = device_create_file(dev,
1161 &vt1211_sysfs_temp_max[i].dev_attr)) ||
1162 (err = device_create_file(dev,
1163 &vt1211_sysfs_temp_max_hyst[i].dev_attr)) ||
1164 (err = device_create_file(dev,
1165 &vt1211_sysfs_temp_alarm[i].dev_attr))) {
1166 goto EXIT_DEV_REMOVE;
1167 }
1168 }
1169 }
1170 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_fan_pwm); i++) {
1171 err = device_create_file(dev,
1172 &vt1211_sysfs_fan_pwm[i].dev_attr);
1173 if (err) {
1174 goto EXIT_DEV_REMOVE;
1175 }
1176 }
1177 for (i = 0; i < ARRAY_SIZE(vt1211_sysfs_misc); i++) {
1178 err = device_create_file(dev,
1179 &vt1211_sysfs_misc[i]);
1180 if (err) {
1181 goto EXIT_DEV_REMOVE;
1182 }
1183 }
1184
1185 /* Register device */
1186 data->class_dev = hwmon_device_register(dev);
1187 if (IS_ERR(data->class_dev)) {
1188 err = PTR_ERR(data->class_dev);
1189 dev_err(dev, "Class registration failed (%d)\n", err);
1190 goto EXIT_DEV_REMOVE_SILENT;
1191 }
1192
1193 return 0;
1194
1195EXIT_DEV_REMOVE:
1196 dev_err(dev, "Sysfs interface creation failed (%d)\n", err);
1197EXIT_DEV_REMOVE_SILENT:
1198 vt1211_remove_sysfs(pdev);
1199 platform_set_drvdata(pdev, NULL);
1200 kfree(data);
1201EXIT:
1202 return err;
1203}
1204
1205static int __devexit vt1211_remove(struct platform_device *pdev)
1206{
1207 struct vt1211_data *data = platform_get_drvdata(pdev);
1208
1209 hwmon_device_unregister(data->class_dev);
1210 vt1211_remove_sysfs(pdev);
1211 platform_set_drvdata(pdev, NULL);
1212 kfree(data);
1213
1214 return 0;
1215}
1216
1217static struct platform_driver vt1211_driver = {
1218 .driver = {
1219 .owner = THIS_MODULE,
1220 .name = DRVNAME,
1221 },
1222 .probe = vt1211_probe,
1223 .remove = __devexit_p(vt1211_remove),
1224};
1225
1226static int __init vt1211_device_add(unsigned short address)
1227{
1228 struct resource res = {
1229 .start = address,
1230 .end = address + 0x7f,
1231 .flags = IORESOURCE_IO,
1232 };
1233 int err;
1234
1235 pdev = platform_device_alloc(DRVNAME, address);
1236 if (!pdev) {
1237 err = -ENOMEM;
1238 printk(KERN_ERR DRVNAME ": Device allocation failed (%d)\n",
1239 err);
1240 goto EXIT;
1241 }
1242
1243 res.name = pdev->name;
1244 err = platform_device_add_resources(pdev, &res, 1);
1245 if (err) {
1246 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1247 "(%d)\n", err);
1248 goto EXIT_DEV_PUT;
1249 }
1250
1251 err = platform_device_add(pdev);
1252 if (err) {
1253 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1254 err);
1255 goto EXIT_DEV_PUT;
1256 }
1257
1258 return 0;
1259
1260EXIT_DEV_PUT:
1261 platform_device_put(pdev);
1262EXIT:
1263 return err;
1264}
1265
1266static int __init vt1211_find(unsigned short *address)
1267{
1268 int err = -ENODEV;
1269
1270 superio_enter();
1271
1272 if (superio_inb(SIO_VT1211_DEVID) != SIO_VT1211_ID) {
1273 goto EXIT;
1274 }
1275
1276 superio_select(SIO_VT1211_LDN_HWMON);
1277
1278 if ((superio_inb(SIO_VT1211_ACTIVE) & 1) == 0) {
1279 printk(KERN_WARNING DRVNAME ": HW monitor is disabled, "
1280 "skipping\n");
1281 goto EXIT;
1282 }
1283
1284 *address = ((superio_inb(SIO_VT1211_BADDR) << 8) |
1285 (superio_inb(SIO_VT1211_BADDR + 1))) & 0xff00;
1286 if (*address == 0) {
1287 printk(KERN_WARNING DRVNAME ": Base address is not set, "
1288 "skipping\n");
1289 goto EXIT;
1290 }
1291
1292 err = 0;
1293 printk(KERN_INFO DRVNAME ": Found VT1211 chip at 0x%04x, "
1294 "revision %u\n", *address, superio_inb(SIO_VT1211_DEVREV));
1295
1296EXIT:
1297 superio_exit();
1298 return err;
1299}
1300
1301static int __init vt1211_init(void)
1302{
1303 int err;
1304 unsigned short address = 0;
1305
1306 err = vt1211_find(&address);
1307 if (err) {
1308 goto EXIT;
1309 }
1310
1311 if ((uch_config < -1) || (uch_config > 31)) {
1312 err = -EINVAL;
1313 printk(KERN_WARNING DRVNAME ": Invalid UCH configuration %d. "
1314 "Choose a value between 0 and 31.\n", uch_config);
1315 goto EXIT;
1316 }
1317
1318 if ((int_mode < -1) || (int_mode > 0)) {
1319 err = -EINVAL;
1320 printk(KERN_WARNING DRVNAME ": Invalid interrupt mode %d. "
1321 "Only mode 0 is supported.\n", int_mode);
1322 goto EXIT;
1323 }
1324
1325 err = platform_driver_register(&vt1211_driver);
1326 if (err) {
1327 goto EXIT;
1328 }
1329
1330 /* Sets global pdev as a side effect */
1331 err = vt1211_device_add(address);
1332 if (err) {
1333 goto EXIT_DRV_UNREGISTER;
1334 }
1335
1336 return 0;
1337
1338EXIT_DRV_UNREGISTER:
1339 platform_driver_unregister(&vt1211_driver);
1340EXIT:
1341 return err;
1342}
1343
1344static void __exit vt1211_exit(void)
1345{
1346 platform_device_unregister(pdev);
1347 platform_driver_unregister(&vt1211_driver);
1348}
1349
1350MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");
1351MODULE_DESCRIPTION("VT1211 sensors");
1352MODULE_LICENSE("GPL");
1353
1354module_init(vt1211_init);
1355module_exit(vt1211_exit);
diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 236ccf0e915d..93f93d4fb8ae 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -451,37 +451,6 @@ define_temperature_sysfs(4);
451define_temperature_sysfs(5); 451define_temperature_sysfs(5);
452define_temperature_sysfs(6); 452define_temperature_sysfs(6);
453 453
454#define CFG_INFO_TEMP(id) { &sensor_dev_attr_temp##id##_input.dev_attr, \
455 &sensor_dev_attr_temp##id##_max_hyst.dev_attr, \
456 &sensor_dev_attr_temp##id##_max.dev_attr }
457#define CFG_INFO_VOLT(id) { &sensor_dev_attr_in##id##_input.dev_attr, \
458 &sensor_dev_attr_in##id##_min.dev_attr, \
459 &sensor_dev_attr_in##id##_max.dev_attr }
460
461struct str_device_attr_table {
462 struct device_attribute *input;
463 struct device_attribute *min;
464 struct device_attribute *max;
465};
466
467static struct str_device_attr_table cfg_info_temp[] = {
468 { &dev_attr_temp1_input, &dev_attr_temp1_max_hyst, &dev_attr_temp1_max },
469 CFG_INFO_TEMP(2),
470 CFG_INFO_TEMP(3),
471 CFG_INFO_TEMP(4),
472 CFG_INFO_TEMP(5),
473 CFG_INFO_TEMP(6)
474};
475
476static struct str_device_attr_table cfg_info_volt[] = {
477 CFG_INFO_VOLT(0),
478 CFG_INFO_VOLT(1),
479 CFG_INFO_VOLT(2),
480 CFG_INFO_VOLT(3),
481 CFG_INFO_VOLT(4),
482 { &dev_attr_in5_input, &dev_attr_in5_min, &dev_attr_in5_max }
483};
484
485/* Fans */ 454/* Fans */
486static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 455static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
487 char *buf) 456 char *buf)
@@ -585,6 +554,107 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
585 554
586static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); 555static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
587 556
557static struct attribute *vt8231_attributes_temps[6][4] = {
558 {
559 &dev_attr_temp1_input.attr,
560 &dev_attr_temp1_max_hyst.attr,
561 &dev_attr_temp1_max.attr,
562 NULL
563 }, {
564 &sensor_dev_attr_temp2_input.dev_attr.attr,
565 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
566 &sensor_dev_attr_temp2_max.dev_attr.attr,
567 NULL
568 }, {
569 &sensor_dev_attr_temp3_input.dev_attr.attr,
570 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
571 &sensor_dev_attr_temp3_max.dev_attr.attr,
572 NULL
573 }, {
574 &sensor_dev_attr_temp4_input.dev_attr.attr,
575 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
576 &sensor_dev_attr_temp4_max.dev_attr.attr,
577 NULL
578 }, {
579 &sensor_dev_attr_temp5_input.dev_attr.attr,
580 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
581 &sensor_dev_attr_temp5_max.dev_attr.attr,
582 NULL
583 }, {
584 &sensor_dev_attr_temp6_input.dev_attr.attr,
585 &sensor_dev_attr_temp6_max_hyst.dev_attr.attr,
586 &sensor_dev_attr_temp6_max.dev_attr.attr,
587 NULL
588 }
589};
590
591static const struct attribute_group vt8231_group_temps[6] = {
592 { .attrs = vt8231_attributes_temps[0] },
593 { .attrs = vt8231_attributes_temps[1] },
594 { .attrs = vt8231_attributes_temps[2] },
595 { .attrs = vt8231_attributes_temps[3] },
596 { .attrs = vt8231_attributes_temps[4] },
597 { .attrs = vt8231_attributes_temps[5] },
598};
599
600static struct attribute *vt8231_attributes_volts[6][4] = {
601 {
602 &sensor_dev_attr_in0_input.dev_attr.attr,
603 &sensor_dev_attr_in0_min.dev_attr.attr,
604 &sensor_dev_attr_in0_max.dev_attr.attr,
605 NULL
606 }, {
607 &sensor_dev_attr_in1_input.dev_attr.attr,
608 &sensor_dev_attr_in1_min.dev_attr.attr,
609 &sensor_dev_attr_in1_max.dev_attr.attr,
610 NULL
611 }, {
612 &sensor_dev_attr_in2_input.dev_attr.attr,
613 &sensor_dev_attr_in2_min.dev_attr.attr,
614 &sensor_dev_attr_in2_max.dev_attr.attr,
615 NULL
616 }, {
617 &sensor_dev_attr_in3_input.dev_attr.attr,
618 &sensor_dev_attr_in3_min.dev_attr.attr,
619 &sensor_dev_attr_in3_max.dev_attr.attr,
620 NULL
621 }, {
622 &sensor_dev_attr_in4_input.dev_attr.attr,
623 &sensor_dev_attr_in4_min.dev_attr.attr,
624 &sensor_dev_attr_in4_max.dev_attr.attr,
625 NULL
626 }, {
627 &dev_attr_in5_input.attr,
628 &dev_attr_in5_min.attr,
629 &dev_attr_in5_max.attr,
630 NULL
631 }
632};
633
634static const struct attribute_group vt8231_group_volts[6] = {
635 { .attrs = vt8231_attributes_volts[0] },
636 { .attrs = vt8231_attributes_volts[1] },
637 { .attrs = vt8231_attributes_volts[2] },
638 { .attrs = vt8231_attributes_volts[3] },
639 { .attrs = vt8231_attributes_volts[4] },
640 { .attrs = vt8231_attributes_volts[5] },
641};
642
643static struct attribute *vt8231_attributes[] = {
644 &sensor_dev_attr_fan1_input.dev_attr.attr,
645 &sensor_dev_attr_fan2_input.dev_attr.attr,
646 &sensor_dev_attr_fan1_min.dev_attr.attr,
647 &sensor_dev_attr_fan2_min.dev_attr.attr,
648 &sensor_dev_attr_fan1_div.dev_attr.attr,
649 &sensor_dev_attr_fan2_div.dev_attr.attr,
650 &dev_attr_alarms.attr,
651 NULL
652};
653
654static const struct attribute_group vt8231_group = {
655 .attrs = vt8231_attributes,
656};
657
588static struct i2c_driver vt8231_driver = { 658static struct i2c_driver vt8231_driver = {
589 .driver = { 659 .driver = {
590 .owner = THIS_MODULE, 660 .owner = THIS_MODULE,
@@ -671,43 +741,43 @@ int vt8231_detect(struct i2c_adapter *adapter)
671 vt8231_init_client(client); 741 vt8231_init_client(client);
672 742
673 /* Register sysfs hooks */ 743 /* Register sysfs hooks */
674 data->class_dev = hwmon_device_register(&client->dev); 744 if ((err = sysfs_create_group(&client->dev.kobj, &vt8231_group)))
675 if (IS_ERR(data->class_dev)) {
676 err = PTR_ERR(data->class_dev);
677 goto exit_detach; 745 goto exit_detach;
678 }
679 746
680 /* Must update device information to find out the config field */ 747 /* Must update device information to find out the config field */
681 data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG); 748 data->uch_config = vt8231_read_value(client, VT8231_REG_UCH_CONFIG);
682 749
683 for (i = 0; i < ARRAY_SIZE(cfg_info_temp); i++) { 750 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) {
684 if (ISTEMP(i, data->uch_config)) { 751 if (ISTEMP(i, data->uch_config)) {
685 device_create_file(&client->dev, 752 if ((err = sysfs_create_group(&client->dev.kobj,
686 cfg_info_temp[i].input); 753 &vt8231_group_temps[i])))
687 device_create_file(&client->dev, cfg_info_temp[i].max); 754 goto exit_remove_files;
688 device_create_file(&client->dev, cfg_info_temp[i].min);
689 } 755 }
690 } 756 }
691 757
692 for (i = 0; i < ARRAY_SIZE(cfg_info_volt); i++) { 758 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) {
693 if (ISVOLT(i, data->uch_config)) { 759 if (ISVOLT(i, data->uch_config)) {
694 device_create_file(&client->dev, 760 if ((err = sysfs_create_group(&client->dev.kobj,
695 cfg_info_volt[i].input); 761 &vt8231_group_volts[i])))
696 device_create_file(&client->dev, cfg_info_volt[i].max); 762 goto exit_remove_files;
697 device_create_file(&client->dev, cfg_info_volt[i].min);
698 } 763 }
699 } 764 }
700 765
701 device_create_file(&client->dev, &sensor_dev_attr_fan1_input.dev_attr); 766 data->class_dev = hwmon_device_register(&client->dev);
702 device_create_file(&client->dev, &sensor_dev_attr_fan2_input.dev_attr); 767 if (IS_ERR(data->class_dev)) {
703 device_create_file(&client->dev, &sensor_dev_attr_fan1_min.dev_attr); 768 err = PTR_ERR(data->class_dev);
704 device_create_file(&client->dev, &sensor_dev_attr_fan2_min.dev_attr); 769 goto exit_remove_files;
705 device_create_file(&client->dev, &sensor_dev_attr_fan1_div.dev_attr); 770 }
706 device_create_file(&client->dev, &sensor_dev_attr_fan2_div.dev_attr);
707
708 device_create_file(&client->dev, &dev_attr_alarms);
709 return 0; 771 return 0;
710 772
773exit_remove_files:
774 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
775 sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]);
776
777 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
778 sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]);
779
780 sysfs_remove_group(&client->dev.kobj, &vt8231_group);
711exit_detach: 781exit_detach:
712 i2c_detach_client(client); 782 i2c_detach_client(client);
713exit_free: 783exit_free:
@@ -720,10 +790,18 @@ exit_release:
720static int vt8231_detach_client(struct i2c_client *client) 790static int vt8231_detach_client(struct i2c_client *client)
721{ 791{
722 struct vt8231_data *data = i2c_get_clientdata(client); 792 struct vt8231_data *data = i2c_get_clientdata(client);
723 int err; 793 int err, i;
724 794
725 hwmon_device_unregister(data->class_dev); 795 hwmon_device_unregister(data->class_dev);
726 796
797 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
798 sysfs_remove_group(&client->dev.kobj, &vt8231_group_volts[i]);
799
800 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
801 sysfs_remove_group(&client->dev.kobj, &vt8231_group_temps[i]);
802
803 sysfs_remove_group(&client->dev.kobj, &vt8231_group);
804
727 if ((err = i2c_detach_client(client))) { 805 if ((err = i2c_detach_client(client))) {
728 return err; 806 return err;
729 } 807 }
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index b21d6b9d7eac..833faa275ffa 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -2,6 +2,9 @@
2 w83627ehf - Driver for the hardware monitoring functionality of 2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip 3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
5 Copyright (C) 2006 Yuan Mu (Winbond),
6 Rudolf Marek <r.marek@sh.cvut.cz>
7 David Hubbard <david.c.hubbard@gmail.com>
5 8
6 Shamelessly ripped from the w83627hf driver 9 Shamelessly ripped from the w83627hf driver
7 Copyright (C) 2003 Mark Studebaker 10 Copyright (C) 2003 Mark Studebaker
@@ -29,8 +32,8 @@
29 32
30 Supports the following chips: 33 Supports the following chips:
31 34
32 Chip #vin #fan #pwm #temp chip_id man_id 35 Chip #vin #fan #pwm #temp chip_id man_id
33 w83627ehf 10 5 - 3 0x88 0x5ca3 36 w83627ehf 10 5 4 3 0x88,0xa1 0x5ca3
34*/ 37*/
35 38
36#include <linux/module.h> 39#include <linux/module.h>
@@ -145,10 +148,44 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0x152, 0x252 };
145#define W83627EHF_REG_ALARM2 0x45A 148#define W83627EHF_REG_ALARM2 0x45A
146#define W83627EHF_REG_ALARM3 0x45B 149#define W83627EHF_REG_ALARM3 0x45B
147 150
151/* SmartFan registers */
152/* DC or PWM output fan configuration */
153static const u8 W83627EHF_REG_PWM_ENABLE[] = {
154 0x04, /* SYS FAN0 output mode and PWM mode */
155 0x04, /* CPU FAN0 output mode and PWM mode */
156 0x12, /* AUX FAN mode */
157 0x62, /* CPU fan1 mode */
158};
159
160static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 };
161static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 };
162
163/* FAN Duty Cycle, be used to control */
164static const u8 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 };
165static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 };
166static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 };
167
168
169/* Advanced Fan control, some values are common for all fans */
170static const u8 W83627EHF_REG_FAN_MIN_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 };
171static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0C, 0x0D, 0x17, 0x66 };
172
148/* 173/*
149 * Conversions 174 * Conversions
150 */ 175 */
151 176
177/* 1 is PWM mode, output in ms */
178static inline unsigned int step_time_from_reg(u8 reg, u8 mode)
179{
180 return mode ? 100 * reg : 400 * reg;
181}
182
183static inline u8 step_time_to_reg(unsigned int msec, u8 mode)
184{
185 return SENSORS_LIMIT((mode ? (msec + 50) / 100 :
186 (msec + 200) / 400), 1, 255);
187}
188
152static inline unsigned int 189static inline unsigned int
153fan_from_reg(u8 reg, unsigned int div) 190fan_from_reg(u8 reg, unsigned int div)
154{ 191{
@@ -170,12 +207,12 @@ temp1_from_reg(s8 reg)
170} 207}
171 208
172static inline s8 209static inline s8
173temp1_to_reg(int temp) 210temp1_to_reg(int temp, int min, int max)
174{ 211{
175 if (temp <= -128000) 212 if (temp <= min)
176 return -128; 213 return min / 1000;
177 if (temp >= 127000) 214 if (temp >= max)
178 return 127; 215 return max / 1000;
179 if (temp < 0) 216 if (temp < 0)
180 return (temp - 500) / 1000; 217 return (temp - 500) / 1000;
181 return (temp + 500) / 1000; 218 return (temp + 500) / 1000;
@@ -223,6 +260,16 @@ struct w83627ehf_data {
223 s16 temp_max[2]; 260 s16 temp_max[2];
224 s16 temp_max_hyst[2]; 261 s16 temp_max_hyst[2];
225 u32 alarms; 262 u32 alarms;
263
264 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
265 u8 pwm_enable[4]; /* 1->manual
266 2->thermal cruise (also called SmartFan I) */
267 u8 pwm[4];
268 u8 target_temp[4];
269 u8 tolerance[4];
270
271 u8 fan_min_output[4]; /* minimum fan speed */
272 u8 fan_stop_time[4];
226}; 273};
227 274
228static inline int is_word_sized(u16 reg) 275static inline int is_word_sized(u16 reg)
@@ -349,6 +396,7 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
349{ 396{
350 struct i2c_client *client = to_i2c_client(dev); 397 struct i2c_client *client = to_i2c_client(dev);
351 struct w83627ehf_data *data = i2c_get_clientdata(client); 398 struct w83627ehf_data *data = i2c_get_clientdata(client);
399 int pwmcfg = 0, tolerance = 0; /* shut up the compiler */
352 int i; 400 int i;
353 401
354 mutex_lock(&data->update_lock); 402 mutex_lock(&data->update_lock);
@@ -416,6 +464,34 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
416 } 464 }
417 } 465 }
418 466
467 for (i = 0; i < 4; i++) {
468 /* pwmcfg, tolarance mapped for i=0, i=1 to same reg */
469 if (i != 1) {
470 pwmcfg = w83627ehf_read_value(client,
471 W83627EHF_REG_PWM_ENABLE[i]);
472 tolerance = w83627ehf_read_value(client,
473 W83627EHF_REG_TOLERANCE[i]);
474 }
475 data->pwm_mode[i] =
476 ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1)
477 ? 0 : 1;
478 data->pwm_enable[i] =
479 ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i])
480 & 3) + 1;
481 data->pwm[i] = w83627ehf_read_value(client,
482 W83627EHF_REG_PWM[i]);
483 data->fan_min_output[i] = w83627ehf_read_value(client,
484 W83627EHF_REG_FAN_MIN_OUTPUT[i]);
485 data->fan_stop_time[i] = w83627ehf_read_value(client,
486 W83627EHF_REG_FAN_STOP_TIME[i]);
487 data->target_temp[i] =
488 w83627ehf_read_value(client,
489 W83627EHF_REG_TARGET[i]) &
490 (data->pwm_mode[i] == 1 ? 0x7f : 0xff);
491 data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0))
492 & 0x0f;
493 }
494
419 /* Measured temperatures and limits */ 495 /* Measured temperatures and limits */
420 data->temp1 = w83627ehf_read_value(client, 496 data->temp1 = w83627ehf_read_value(client,
421 W83627EHF_REG_TEMP1); 497 W83627EHF_REG_TEMP1);
@@ -546,14 +622,6 @@ static struct sensor_device_attribute sda_in_max[] = {
546 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), 622 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
547}; 623};
548 624
549static void device_create_file_in(struct device *dev, int i)
550{
551 device_create_file(dev, &sda_in_input[i].dev_attr);
552 device_create_file(dev, &sda_in_alarm[i].dev_attr);
553 device_create_file(dev, &sda_in_min[i].dev_attr);
554 device_create_file(dev, &sda_in_max[i].dev_attr);
555}
556
557#define show_fan_reg(reg) \ 625#define show_fan_reg(reg) \
558static ssize_t \ 626static ssize_t \
559show_##reg(struct device *dev, struct device_attribute *attr, \ 627show_##reg(struct device *dev, struct device_attribute *attr, \
@@ -681,14 +749,6 @@ static struct sensor_device_attribute sda_fan_div[] = {
681 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4), 749 SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4),
682}; 750};
683 751
684static void device_create_file_fan(struct device *dev, int i)
685{
686 device_create_file(dev, &sda_fan_input[i].dev_attr);
687 device_create_file(dev, &sda_fan_alarm[i].dev_attr);
688 device_create_file(dev, &sda_fan_div[i].dev_attr);
689 device_create_file(dev, &sda_fan_min[i].dev_attr);
690}
691
692#define show_temp1_reg(reg) \ 752#define show_temp1_reg(reg) \
693static ssize_t \ 753static ssize_t \
694show_##reg(struct device *dev, struct device_attribute *attr, \ 754show_##reg(struct device *dev, struct device_attribute *attr, \
@@ -711,7 +771,7 @@ store_temp1_##reg(struct device *dev, struct device_attribute *attr, \
711 u32 val = simple_strtoul(buf, NULL, 10); \ 771 u32 val = simple_strtoul(buf, NULL, 10); \
712 \ 772 \
713 mutex_lock(&data->update_lock); \ 773 mutex_lock(&data->update_lock); \
714 data->temp1_##reg = temp1_to_reg(val); \ 774 data->temp1_##reg = temp1_to_reg(val, -128000, 127000); \
715 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \ 775 w83627ehf_write_value(client, W83627EHF_REG_TEMP1_##REG, \
716 data->temp1_##reg); \ 776 data->temp1_##reg); \
717 mutex_unlock(&data->update_lock); \ 777 mutex_unlock(&data->update_lock); \
@@ -777,10 +837,309 @@ static struct sensor_device_attribute sda_temp[] = {
777 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), 837 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
778}; 838};
779 839
840#define show_pwm_reg(reg) \
841static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
842 char *buf) \
843{ \
844 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
845 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
846 int nr = sensor_attr->index; \
847 return sprintf(buf, "%d\n", data->reg[nr]); \
848}
849
850show_pwm_reg(pwm_mode)
851show_pwm_reg(pwm_enable)
852show_pwm_reg(pwm)
853
854static ssize_t
855store_pwm_mode(struct device *dev, struct device_attribute *attr,
856 const char *buf, size_t count)
857{
858 struct i2c_client *client = to_i2c_client(dev);
859 struct w83627ehf_data *data = i2c_get_clientdata(client);
860 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
861 int nr = sensor_attr->index;
862 u32 val = simple_strtoul(buf, NULL, 10);
863 u16 reg;
864
865 if (val > 1)
866 return -EINVAL;
867 mutex_lock(&data->update_lock);
868 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
869 data->pwm_mode[nr] = val;
870 reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]);
871 if (!val)
872 reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr];
873 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
874 mutex_unlock(&data->update_lock);
875 return count;
876}
877
878static ssize_t
879store_pwm(struct device *dev, struct device_attribute *attr,
880 const char *buf, size_t count)
881{
882 struct i2c_client *client = to_i2c_client(dev);
883 struct w83627ehf_data *data = i2c_get_clientdata(client);
884 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
885 int nr = sensor_attr->index;
886 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255);
887
888 mutex_lock(&data->update_lock);
889 data->pwm[nr] = val;
890 w83627ehf_write_value(client, W83627EHF_REG_PWM[nr], val);
891 mutex_unlock(&data->update_lock);
892 return count;
893}
894
895static ssize_t
896store_pwm_enable(struct device *dev, struct device_attribute *attr,
897 const char *buf, size_t count)
898{
899 struct i2c_client *client = to_i2c_client(dev);
900 struct w83627ehf_data *data = i2c_get_clientdata(client);
901 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
902 int nr = sensor_attr->index;
903 u32 val = simple_strtoul(buf, NULL, 10);
904 u16 reg;
905
906 if (!val || (val > 2)) /* only modes 1 and 2 are supported */
907 return -EINVAL;
908 mutex_lock(&data->update_lock);
909 reg = w83627ehf_read_value(client, W83627EHF_REG_PWM_ENABLE[nr]);
910 data->pwm_enable[nr] = val;
911 reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]);
912 reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr];
913 w83627ehf_write_value(client, W83627EHF_REG_PWM_ENABLE[nr], reg);
914 mutex_unlock(&data->update_lock);
915 return count;
916}
917
918
919#define show_tol_temp(reg) \
920static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
921 char *buf) \
922{ \
923 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
924 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
925 int nr = sensor_attr->index; \
926 return sprintf(buf, "%d\n", temp1_from_reg(data->reg[nr])); \
927}
928
929show_tol_temp(tolerance)
930show_tol_temp(target_temp)
931
932static ssize_t
933store_target_temp(struct device *dev, struct device_attribute *attr,
934 const char *buf, size_t count)
935{
936 struct i2c_client *client = to_i2c_client(dev);
937 struct w83627ehf_data *data = i2c_get_clientdata(client);
938 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
939 int nr = sensor_attr->index;
940 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 127000);
941
942 mutex_lock(&data->update_lock);
943 data->target_temp[nr] = val;
944 w83627ehf_write_value(client, W83627EHF_REG_TARGET[nr], val);
945 mutex_unlock(&data->update_lock);
946 return count;
947}
948
949static ssize_t
950store_tolerance(struct device *dev, struct device_attribute *attr,
951 const char *buf, size_t count)
952{
953 struct i2c_client *client = to_i2c_client(dev);
954 struct w83627ehf_data *data = i2c_get_clientdata(client);
955 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
956 int nr = sensor_attr->index;
957 u16 reg;
958 /* Limit the temp to 0C - 15C */
959 u8 val = temp1_to_reg(simple_strtoul(buf, NULL, 10), 0, 15000);
960
961 mutex_lock(&data->update_lock);
962 reg = w83627ehf_read_value(client, W83627EHF_REG_TOLERANCE[nr]);
963 data->tolerance[nr] = val;
964 if (nr == 1)
965 reg = (reg & 0x0f) | (val << 4);
966 else
967 reg = (reg & 0xf0) | val;
968 w83627ehf_write_value(client, W83627EHF_REG_TOLERANCE[nr], reg);
969 mutex_unlock(&data->update_lock);
970 return count;
971}
972
973static struct sensor_device_attribute sda_pwm[] = {
974 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
975 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
976 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
977 SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3),
978};
979
980static struct sensor_device_attribute sda_pwm_mode[] = {
981 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
982 store_pwm_mode, 0),
983 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
984 store_pwm_mode, 1),
985 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
986 store_pwm_mode, 2),
987 SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
988 store_pwm_mode, 3),
989};
990
991static struct sensor_device_attribute sda_pwm_enable[] = {
992 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
993 store_pwm_enable, 0),
994 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
995 store_pwm_enable, 1),
996 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
997 store_pwm_enable, 2),
998 SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
999 store_pwm_enable, 3),
1000};
1001
1002static struct sensor_device_attribute sda_target_temp[] = {
1003 SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp,
1004 store_target_temp, 0),
1005 SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp,
1006 store_target_temp, 1),
1007 SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp,
1008 store_target_temp, 2),
1009 SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp,
1010 store_target_temp, 3),
1011};
1012
1013static struct sensor_device_attribute sda_tolerance[] = {
1014 SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1015 store_tolerance, 0),
1016 SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1017 store_tolerance, 1),
1018 SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1019 store_tolerance, 2),
1020 SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance,
1021 store_tolerance, 3),
1022};
1023
1024/* Smart Fan registers */
1025
1026#define fan_functions(reg, REG) \
1027static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1028 char *buf) \
1029{ \
1030 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1031 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1032 int nr = sensor_attr->index; \
1033 return sprintf(buf, "%d\n", data->reg[nr]); \
1034}\
1035static ssize_t \
1036store_##reg(struct device *dev, struct device_attribute *attr, \
1037 const char *buf, size_t count) \
1038{\
1039 struct i2c_client *client = to_i2c_client(dev); \
1040 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1041 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1042 int nr = sensor_attr->index; \
1043 u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 1, 255); \
1044 mutex_lock(&data->update_lock); \
1045 data->reg[nr] = val; \
1046 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1047 mutex_unlock(&data->update_lock); \
1048 return count; \
1049}
1050
1051fan_functions(fan_min_output, FAN_MIN_OUTPUT)
1052
1053#define fan_time_functions(reg, REG) \
1054static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
1055 char *buf) \
1056{ \
1057 struct w83627ehf_data *data = w83627ehf_update_device(dev); \
1058 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1059 int nr = sensor_attr->index; \
1060 return sprintf(buf, "%d\n", \
1061 step_time_from_reg(data->reg[nr], data->pwm_mode[nr])); \
1062} \
1063\
1064static ssize_t \
1065store_##reg(struct device *dev, struct device_attribute *attr, \
1066 const char *buf, size_t count) \
1067{ \
1068 struct i2c_client *client = to_i2c_client(dev); \
1069 struct w83627ehf_data *data = i2c_get_clientdata(client); \
1070 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \
1071 int nr = sensor_attr->index; \
1072 u8 val = step_time_to_reg(simple_strtoul(buf, NULL, 10), \
1073 data->pwm_mode[nr]); \
1074 mutex_lock(&data->update_lock); \
1075 data->reg[nr] = val; \
1076 w83627ehf_write_value(client, W83627EHF_REG_##REG[nr], val); \
1077 mutex_unlock(&data->update_lock); \
1078 return count; \
1079} \
1080
1081fan_time_functions(fan_stop_time, FAN_STOP_TIME)
1082
1083
1084static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
1085 SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1086 store_fan_stop_time, 3),
1087 SENSOR_ATTR(pwm4_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1088 store_fan_min_output, 3),
1089};
1090
1091static struct sensor_device_attribute sda_sf3_arrays[] = {
1092 SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1093 store_fan_stop_time, 0),
1094 SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1095 store_fan_stop_time, 1),
1096 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1097 store_fan_stop_time, 2),
1098 SENSOR_ATTR(pwm1_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1099 store_fan_min_output, 0),
1100 SENSOR_ATTR(pwm2_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1101 store_fan_min_output, 1),
1102 SENSOR_ATTR(pwm3_min_output, S_IWUSR | S_IRUGO, show_fan_min_output,
1103 store_fan_min_output, 2),
1104};
1105
780/* 1106/*
781 * Driver and client management 1107 * Driver and client management
782 */ 1108 */
783 1109
1110static void w83627ehf_device_remove_files(struct device *dev)
1111{
1112 /* some entries in the following arrays may not have been used in
1113 * device_create_file(), but device_remove_file() will ignore them */
1114 int i;
1115
1116 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
1117 device_remove_file(dev, &sda_sf3_arrays[i].dev_attr);
1118 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1119 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1120 for (i = 0; i < 10; i++) {
1121 device_remove_file(dev, &sda_in_input[i].dev_attr);
1122 device_remove_file(dev, &sda_in_alarm[i].dev_attr);
1123 device_remove_file(dev, &sda_in_min[i].dev_attr);
1124 device_remove_file(dev, &sda_in_max[i].dev_attr);
1125 }
1126 for (i = 0; i < 5; i++) {
1127 device_remove_file(dev, &sda_fan_input[i].dev_attr);
1128 device_remove_file(dev, &sda_fan_alarm[i].dev_attr);
1129 device_remove_file(dev, &sda_fan_div[i].dev_attr);
1130 device_remove_file(dev, &sda_fan_min[i].dev_attr);
1131 }
1132 for (i = 0; i < 4; i++) {
1133 device_remove_file(dev, &sda_pwm[i].dev_attr);
1134 device_remove_file(dev, &sda_pwm_mode[i].dev_attr);
1135 device_remove_file(dev, &sda_pwm_enable[i].dev_attr);
1136 device_remove_file(dev, &sda_target_temp[i].dev_attr);
1137 device_remove_file(dev, &sda_tolerance[i].dev_attr);
1138 }
1139 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
1140 device_remove_file(dev, &sda_temp[i].dev_attr);
1141}
1142
784static struct i2c_driver w83627ehf_driver; 1143static struct i2c_driver w83627ehf_driver;
785 1144
786static void w83627ehf_init_client(struct i2c_client *client) 1145static void w83627ehf_init_client(struct i2c_client *client)
@@ -810,6 +1169,7 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
810 struct i2c_client *client; 1169 struct i2c_client *client;
811 struct w83627ehf_data *data; 1170 struct w83627ehf_data *data;
812 struct device *dev; 1171 struct device *dev;
1172 u8 fan4pin, fan5pin;
813 int i, err = 0; 1173 int i, err = 0;
814 1174
815 if (!request_region(address + REGION_OFFSET, REGION_LENGTH, 1175 if (!request_region(address + REGION_OFFSET, REGION_LENGTH,
@@ -848,35 +1208,87 @@ static int w83627ehf_detect(struct i2c_adapter *adapter)
848 data->fan_min[i] = w83627ehf_read_value(client, 1208 data->fan_min[i] = w83627ehf_read_value(client,
849 W83627EHF_REG_FAN_MIN[i]); 1209 W83627EHF_REG_FAN_MIN[i]);
850 1210
1211 /* fan4 and fan5 share some pins with the GPIO and serial flash */
1212
1213 superio_enter();
1214 fan5pin = superio_inb(0x24) & 0x2;
1215 fan4pin = superio_inb(0x29) & 0x6;
1216 superio_exit();
1217
851 /* It looks like fan4 and fan5 pins can be alternatively used 1218 /* It looks like fan4 and fan5 pins can be alternatively used
852 as fan on/off switches */ 1219 as fan on/off switches */
1220
853 data->has_fan = 0x07; /* fan1, fan2 and fan3 */ 1221 data->has_fan = 0x07; /* fan1, fan2 and fan3 */
854 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1); 1222 i = w83627ehf_read_value(client, W83627EHF_REG_FANDIV1);
855 if (i & (1 << 2)) 1223 if ((i & (1 << 2)) && (!fan4pin))
856 data->has_fan |= (1 << 3); 1224 data->has_fan |= (1 << 3);
857 if (i & (1 << 0)) 1225 if ((i & (1 << 0)) && (!fan5pin))
858 data->has_fan |= (1 << 4); 1226 data->has_fan |= (1 << 4);
859 1227
860 /* Register sysfs hooks */ 1228 /* Register sysfs hooks */
861 data->class_dev = hwmon_device_register(dev); 1229 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++)
862 if (IS_ERR(data->class_dev)) { 1230 if ((err = device_create_file(dev,
863 err = PTR_ERR(data->class_dev); 1231 &sda_sf3_arrays[i].dev_attr)))
864 goto exit_detach; 1232 goto exit_remove;
865 } 1233
1234 /* if fan4 is enabled create the sf3 files for it */
1235 if (data->has_fan & (1 << 3))
1236 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
1237 if ((err = device_create_file(dev,
1238 &sda_sf3_arrays_fan4[i].dev_attr)))
1239 goto exit_remove;
1240 }
866 1241
867 for (i = 0; i < 10; i++) 1242 for (i = 0; i < 10; i++)
868 device_create_file_in(dev, i); 1243 if ((err = device_create_file(dev, &sda_in_input[i].dev_attr))
1244 || (err = device_create_file(dev,
1245 &sda_in_alarm[i].dev_attr))
1246 || (err = device_create_file(dev,
1247 &sda_in_min[i].dev_attr))
1248 || (err = device_create_file(dev,
1249 &sda_in_max[i].dev_attr)))
1250 goto exit_remove;
869 1251
870 for (i = 0; i < 5; i++) { 1252 for (i = 0; i < 5; i++) {
871 if (data->has_fan & (1 << i)) 1253 if (data->has_fan & (1 << i)) {
872 device_create_file_fan(dev, i); 1254 if ((err = device_create_file(dev,
1255 &sda_fan_input[i].dev_attr))
1256 || (err = device_create_file(dev,
1257 &sda_fan_alarm[i].dev_attr))
1258 || (err = device_create_file(dev,
1259 &sda_fan_div[i].dev_attr))
1260 || (err = device_create_file(dev,
1261 &sda_fan_min[i].dev_attr)))
1262 goto exit_remove;
1263 if (i < 4 && /* w83627ehf only has 4 pwm */
1264 ((err = device_create_file(dev,
1265 &sda_pwm[i].dev_attr))
1266 || (err = device_create_file(dev,
1267 &sda_pwm_mode[i].dev_attr))
1268 || (err = device_create_file(dev,
1269 &sda_pwm_enable[i].dev_attr))
1270 || (err = device_create_file(dev,
1271 &sda_target_temp[i].dev_attr))
1272 || (err = device_create_file(dev,
1273 &sda_tolerance[i].dev_attr))))
1274 goto exit_remove;
1275 }
873 } 1276 }
1277
874 for (i = 0; i < ARRAY_SIZE(sda_temp); i++) 1278 for (i = 0; i < ARRAY_SIZE(sda_temp); i++)
875 device_create_file(dev, &sda_temp[i].dev_attr); 1279 if ((err = device_create_file(dev, &sda_temp[i].dev_attr)))
1280 goto exit_remove;
1281
1282 data->class_dev = hwmon_device_register(dev);
1283 if (IS_ERR(data->class_dev)) {
1284 err = PTR_ERR(data->class_dev);
1285 goto exit_remove;
1286 }
876 1287
877 return 0; 1288 return 0;
878 1289
879exit_detach: 1290exit_remove:
1291 w83627ehf_device_remove_files(dev);
880 i2c_detach_client(client); 1292 i2c_detach_client(client);
881exit_free: 1293exit_free:
882 kfree(data); 1294 kfree(data);
@@ -892,6 +1304,7 @@ static int w83627ehf_detach_client(struct i2c_client *client)
892 int err; 1304 int err;
893 1305
894 hwmon_device_unregister(data->class_dev); 1306 hwmon_device_unregister(data->class_dev);
1307 w83627ehf_device_remove_files(&client->dev);
895 1308
896 if ((err = i2c_detach_client(client))) 1309 if ((err = i2c_detach_client(client)))
897 return err; 1310 return err;
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 30295028ea99..dfdc29c77123 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -512,13 +512,6 @@ static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, 512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
513 show_regs_in_max0, store_regs_in_max0); 513 show_regs_in_max0, store_regs_in_max0);
514 514
515#define device_create_file_in(client, offset) \
516do { \
517device_create_file(&client->dev, &dev_attr_in##offset##_input); \
518device_create_file(&client->dev, &dev_attr_in##offset##_min); \
519device_create_file(&client->dev, &dev_attr_in##offset##_max); \
520} while (0)
521
522#define show_fan_reg(reg) \ 515#define show_fan_reg(reg) \
523static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 516static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
524{ \ 517{ \
@@ -576,12 +569,6 @@ sysfs_fan_min_offset(2);
576sysfs_fan_offset(3); 569sysfs_fan_offset(3);
577sysfs_fan_min_offset(3); 570sysfs_fan_min_offset(3);
578 571
579#define device_create_file_fan(client, offset) \
580do { \
581device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
582device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
583} while (0)
584
585#define show_temp_reg(reg) \ 572#define show_temp_reg(reg) \
586static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 573static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
587{ \ 574{ \
@@ -656,13 +643,6 @@ sysfs_temp_offsets(1);
656sysfs_temp_offsets(2); 643sysfs_temp_offsets(2);
657sysfs_temp_offsets(3); 644sysfs_temp_offsets(3);
658 645
659#define device_create_file_temp(client, offset) \
660do { \
661device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
662device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
663device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
664} while (0)
665
666static ssize_t 646static ssize_t
667show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 647show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
668{ 648{
@@ -670,8 +650,6 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
670 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 650 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
671} 651}
672static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 652static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
673#define device_create_file_vid(client) \
674device_create_file(&client->dev, &dev_attr_cpu0_vid)
675 653
676static ssize_t 654static ssize_t
677show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 655show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -692,8 +670,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
692 return count; 670 return count;
693} 671}
694static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 672static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
695#define device_create_file_vrm(client) \
696device_create_file(&client->dev, &dev_attr_vrm)
697 673
698static ssize_t 674static ssize_t
699show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 675show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -702,8 +678,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
702 return sprintf(buf, "%ld\n", (long) data->alarms); 678 return sprintf(buf, "%ld\n", (long) data->alarms);
703} 679}
704static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 680static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
705#define device_create_file_alarms(client) \
706device_create_file(&client->dev, &dev_attr_alarms)
707 681
708#define show_beep_reg(REG, reg) \ 682#define show_beep_reg(REG, reg) \
709static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 683static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
@@ -766,12 +740,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
766sysfs_beep(ENABLE, enable); 740sysfs_beep(ENABLE, enable);
767sysfs_beep(MASK, mask); 741sysfs_beep(MASK, mask);
768 742
769#define device_create_file_beep(client) \
770do { \
771device_create_file(&client->dev, &dev_attr_beep_enable); \
772device_create_file(&client->dev, &dev_attr_beep_mask); \
773} while (0)
774
775static ssize_t 743static ssize_t
776show_fan_div_reg(struct device *dev, char *buf, int nr) 744show_fan_div_reg(struct device *dev, char *buf, int nr)
777{ 745{
@@ -837,11 +805,6 @@ sysfs_fan_div(1);
837sysfs_fan_div(2); 805sysfs_fan_div(2);
838sysfs_fan_div(3); 806sysfs_fan_div(3);
839 807
840#define device_create_file_fan_div(client, offset) \
841do { \
842device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
843} while (0)
844
845static ssize_t 808static ssize_t
846show_pwm_reg(struct device *dev, char *buf, int nr) 809show_pwm_reg(struct device *dev, char *buf, int nr)
847{ 810{
@@ -896,11 +859,6 @@ sysfs_pwm(1);
896sysfs_pwm(2); 859sysfs_pwm(2);
897sysfs_pwm(3); 860sysfs_pwm(3);
898 861
899#define device_create_file_pwm(client, offset) \
900do { \
901device_create_file(&client->dev, &dev_attr_pwm##offset); \
902} while (0)
903
904static ssize_t 862static ssize_t
905show_sensor_reg(struct device *dev, char *buf, int nr) 863show_sensor_reg(struct device *dev, char *buf, int nr)
906{ 864{
@@ -972,12 +930,6 @@ sysfs_sensor(1);
972sysfs_sensor(2); 930sysfs_sensor(2);
973sysfs_sensor(3); 931sysfs_sensor(3);
974 932
975#define device_create_file_sensor(client, offset) \
976do { \
977device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
978} while (0)
979
980
981static int __init w83627hf_find(int sioaddr, unsigned short *addr) 933static int __init w83627hf_find(int sioaddr, unsigned short *addr)
982{ 934{
983 u16 val; 935 u16 val;
@@ -1009,6 +961,85 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
1009 return 0; 961 return 0;
1010} 962}
1011 963
964static struct attribute *w83627hf_attributes[] = {
965 &dev_attr_in0_input.attr,
966 &dev_attr_in0_min.attr,
967 &dev_attr_in0_max.attr,
968 &dev_attr_in2_input.attr,
969 &dev_attr_in2_min.attr,
970 &dev_attr_in2_max.attr,
971 &dev_attr_in3_input.attr,
972 &dev_attr_in3_min.attr,
973 &dev_attr_in3_max.attr,
974 &dev_attr_in4_input.attr,
975 &dev_attr_in4_min.attr,
976 &dev_attr_in4_max.attr,
977 &dev_attr_in7_input.attr,
978 &dev_attr_in7_min.attr,
979 &dev_attr_in7_max.attr,
980 &dev_attr_in8_input.attr,
981 &dev_attr_in8_min.attr,
982 &dev_attr_in8_max.attr,
983
984 &dev_attr_fan1_input.attr,
985 &dev_attr_fan1_min.attr,
986 &dev_attr_fan1_div.attr,
987 &dev_attr_fan2_input.attr,
988 &dev_attr_fan2_min.attr,
989 &dev_attr_fan2_div.attr,
990
991 &dev_attr_temp1_input.attr,
992 &dev_attr_temp1_max.attr,
993 &dev_attr_temp1_max_hyst.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_input.attr,
996 &dev_attr_temp2_max.attr,
997 &dev_attr_temp2_max_hyst.attr,
998 &dev_attr_temp2_type.attr,
999
1000 &dev_attr_alarms.attr,
1001 &dev_attr_beep_enable.attr,
1002 &dev_attr_beep_mask.attr,
1003
1004 &dev_attr_pwm1.attr,
1005 &dev_attr_pwm2.attr,
1006
1007 NULL
1008};
1009
1010static const struct attribute_group w83627hf_group = {
1011 .attrs = w83627hf_attributes,
1012};
1013
1014static struct attribute *w83627hf_attributes_opt[] = {
1015 &dev_attr_in1_input.attr,
1016 &dev_attr_in1_min.attr,
1017 &dev_attr_in1_max.attr,
1018 &dev_attr_in5_input.attr,
1019 &dev_attr_in5_min.attr,
1020 &dev_attr_in5_max.attr,
1021 &dev_attr_in6_input.attr,
1022 &dev_attr_in6_min.attr,
1023 &dev_attr_in6_max.attr,
1024
1025 &dev_attr_fan3_input.attr,
1026 &dev_attr_fan3_min.attr,
1027 &dev_attr_fan3_div.attr,
1028
1029 &dev_attr_temp3_input.attr,
1030 &dev_attr_temp3_max.attr,
1031 &dev_attr_temp3_max_hyst.attr,
1032 &dev_attr_temp3_type.attr,
1033
1034 &dev_attr_pwm3.attr,
1035
1036 NULL
1037};
1038
1039static const struct attribute_group w83627hf_group_opt = {
1040 .attrs = w83627hf_attributes_opt,
1041};
1042
1012static int w83627hf_detect(struct i2c_adapter *adapter) 1043static int w83627hf_detect(struct i2c_adapter *adapter)
1013{ 1044{
1014 int val, kind; 1045 int val, kind;
@@ -1108,62 +1139,72 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1108 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); 1139 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
1109 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1140 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1110 1141
1111 /* Register sysfs hooks */ 1142 /* Register common device attributes */
1112 data->class_dev = hwmon_device_register(&new_client->dev); 1143 if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group)))
1113 if (IS_ERR(data->class_dev)) {
1114 err = PTR_ERR(data->class_dev);
1115 goto ERROR3; 1144 goto ERROR3;
1116 }
1117
1118 device_create_file_in(new_client, 0);
1119 if (kind != w83697hf)
1120 device_create_file_in(new_client, 1);
1121 device_create_file_in(new_client, 2);
1122 device_create_file_in(new_client, 3);
1123 device_create_file_in(new_client, 4);
1124 if (kind == w83627hf || kind == w83697hf) {
1125 device_create_file_in(new_client, 5);
1126 device_create_file_in(new_client, 6);
1127 }
1128 device_create_file_in(new_client, 7);
1129 device_create_file_in(new_client, 8);
1130
1131 device_create_file_fan(new_client, 1);
1132 device_create_file_fan(new_client, 2);
1133 if (kind != w83697hf)
1134 device_create_file_fan(new_client, 3);
1135
1136 device_create_file_temp(new_client, 1);
1137 device_create_file_temp(new_client, 2);
1138 if (kind != w83697hf)
1139 device_create_file_temp(new_client, 3);
1140 1145
1141 if (kind != w83697hf && data->vid != 0xff) { 1146 /* Register chip-specific device attributes */
1142 device_create_file_vid(new_client); 1147 if (kind == w83627hf || kind == w83697hf)
1143 device_create_file_vrm(new_client); 1148 if ((err = device_create_file(&new_client->dev,
1144 } 1149 &dev_attr_in5_input))
1150 || (err = device_create_file(&new_client->dev,
1151 &dev_attr_in5_min))
1152 || (err = device_create_file(&new_client->dev,
1153 &dev_attr_in5_max))
1154 || (err = device_create_file(&new_client->dev,
1155 &dev_attr_in6_input))
1156 || (err = device_create_file(&new_client->dev,
1157 &dev_attr_in6_min))
1158 || (err = device_create_file(&new_client->dev,
1159 &dev_attr_in6_max)))
1160 goto ERROR4;
1145 1161
1146 device_create_file_fan_div(new_client, 1);
1147 device_create_file_fan_div(new_client, 2);
1148 if (kind != w83697hf) 1162 if (kind != w83697hf)
1149 device_create_file_fan_div(new_client, 3); 1163 if ((err = device_create_file(&new_client->dev,
1150 1164 &dev_attr_in1_input))
1151 device_create_file_alarms(new_client); 1165 || (err = device_create_file(&new_client->dev,
1152 1166 &dev_attr_in1_min))
1153 device_create_file_beep(new_client); 1167 || (err = device_create_file(&new_client->dev,
1168 &dev_attr_in1_max))
1169 || (err = device_create_file(&new_client->dev,
1170 &dev_attr_fan3_input))
1171 || (err = device_create_file(&new_client->dev,
1172 &dev_attr_fan3_min))
1173 || (err = device_create_file(&new_client->dev,
1174 &dev_attr_fan3_div))
1175 || (err = device_create_file(&new_client->dev,
1176 &dev_attr_temp3_input))
1177 || (err = device_create_file(&new_client->dev,
1178 &dev_attr_temp3_max))
1179 || (err = device_create_file(&new_client->dev,
1180 &dev_attr_temp3_max_hyst))
1181 || (err = device_create_file(&new_client->dev,
1182 &dev_attr_temp3_type)))
1183 goto ERROR4;
1184
1185 if (kind != w83697hf && data->vid != 0xff)
1186 if ((err = device_create_file(&new_client->dev,
1187 &dev_attr_cpu0_vid))
1188 || (err = device_create_file(&new_client->dev,
1189 &dev_attr_vrm)))
1190 goto ERROR4;
1154 1191
1155 device_create_file_pwm(new_client, 1);
1156 device_create_file_pwm(new_client, 2);
1157 if (kind == w83627thf || kind == w83637hf || kind == w83687thf) 1192 if (kind == w83627thf || kind == w83637hf || kind == w83687thf)
1158 device_create_file_pwm(new_client, 3); 1193 if ((err = device_create_file(&new_client->dev,
1194 &dev_attr_pwm3)))
1195 goto ERROR4;
1159 1196
1160 device_create_file_sensor(new_client, 1); 1197 data->class_dev = hwmon_device_register(&new_client->dev);
1161 device_create_file_sensor(new_client, 2); 1198 if (IS_ERR(data->class_dev)) {
1162 if (kind != w83697hf) 1199 err = PTR_ERR(data->class_dev);
1163 device_create_file_sensor(new_client, 3); 1200 goto ERROR4;
1201 }
1164 1202
1165 return 0; 1203 return 0;
1166 1204
1205 ERROR4:
1206 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group);
1207 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt);
1167 ERROR3: 1208 ERROR3:
1168 i2c_detach_client(new_client); 1209 i2c_detach_client(new_client);
1169 ERROR2: 1210 ERROR2:
@@ -1181,6 +1222,9 @@ static int w83627hf_detach_client(struct i2c_client *client)
1181 1222
1182 hwmon_device_unregister(data->class_dev); 1223 hwmon_device_unregister(data->class_dev);
1183 1224
1225 sysfs_remove_group(&client->dev.kobj, &w83627hf_group);
1226 sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt);
1227
1184 if ((err = i2c_detach_client(client))) 1228 if ((err = i2c_detach_client(client)))
1185 return err; 1229 return err;
1186 1230
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index 95221b14e13a..a4584ec69842 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -41,6 +41,7 @@
41#include <linux/i2c-isa.h> 41#include <linux/i2c-isa.h>
42#include <linux/hwmon.h> 42#include <linux/hwmon.h>
43#include <linux/hwmon-vid.h> 43#include <linux/hwmon-vid.h>
44#include <linux/sysfs.h>
44#include <linux/err.h> 45#include <linux/err.h>
45#include <linux/mutex.h> 46#include <linux/mutex.h>
46#include <asm/io.h> 47#include <asm/io.h>
@@ -360,13 +361,6 @@ sysfs_in_offsets(6);
360sysfs_in_offsets(7); 361sysfs_in_offsets(7);
361sysfs_in_offsets(8); 362sysfs_in_offsets(8);
362 363
363#define device_create_file_in(client, offset) \
364do { \
365device_create_file(&client->dev, &dev_attr_in##offset##_input); \
366device_create_file(&client->dev, &dev_attr_in##offset##_min); \
367device_create_file(&client->dev, &dev_attr_in##offset##_max); \
368} while (0)
369
370#define show_fan_reg(reg) \ 364#define show_fan_reg(reg) \
371static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 365static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
372{ \ 366{ \
@@ -421,12 +415,6 @@ sysfs_fan_min_offset(2);
421sysfs_fan_offset(3); 415sysfs_fan_offset(3);
422sysfs_fan_min_offset(3); 416sysfs_fan_min_offset(3);
423 417
424#define device_create_file_fan(client, offset) \
425do { \
426device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
427device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
428} while (0)
429
430#define show_temp_reg(reg) \ 418#define show_temp_reg(reg) \
431static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 419static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
432{ \ 420{ \
@@ -497,13 +485,6 @@ sysfs_temp_offsets(1);
497sysfs_temp_offsets(2); 485sysfs_temp_offsets(2);
498sysfs_temp_offsets(3); 486sysfs_temp_offsets(3);
499 487
500#define device_create_file_temp(client, offset) \
501do { \
502device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
503device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
504device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
505} while (0)
506
507static ssize_t 488static ssize_t
508show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 489show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
509{ 490{
@@ -511,10 +492,8 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
511 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 492 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
512} 493}
513 494
514static 495static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
515DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 496
516#define device_create_file_vid(client) \
517device_create_file(&client->dev, &dev_attr_cpu0_vid);
518static ssize_t 497static ssize_t
519show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 498show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
520{ 499{
@@ -535,10 +514,8 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
535 return count; 514 return count;
536} 515}
537 516
538static 517static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
539DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 518
540#define device_create_file_vrm(client) \
541device_create_file(&client->dev, &dev_attr_vrm);
542static ssize_t 519static ssize_t
543show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 520show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
544{ 521{
@@ -546,10 +523,8 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
546 return sprintf(buf, "%u\n", data->alarms); 523 return sprintf(buf, "%u\n", data->alarms);
547} 524}
548 525
549static 526static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
550DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 527
551#define device_create_file_alarms(client) \
552device_create_file(&client->dev, &dev_attr_alarms);
553static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf) 528static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
554{ 529{
555 struct w83781d_data *data = w83781d_update_device(dev); 530 struct w83781d_data *data = w83781d_update_device(dev);
@@ -615,12 +590,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, show_regs_beep_##reg, store_re
615sysfs_beep(ENABLE, enable); 590sysfs_beep(ENABLE, enable);
616sysfs_beep(MASK, mask); 591sysfs_beep(MASK, mask);
617 592
618#define device_create_file_beep(client) \
619do { \
620device_create_file(&client->dev, &dev_attr_beep_enable); \
621device_create_file(&client->dev, &dev_attr_beep_mask); \
622} while (0)
623
624static ssize_t 593static ssize_t
625show_fan_div_reg(struct device *dev, char *buf, int nr) 594show_fan_div_reg(struct device *dev, char *buf, int nr)
626{ 595{
@@ -686,11 +655,6 @@ sysfs_fan_div(1);
686sysfs_fan_div(2); 655sysfs_fan_div(2);
687sysfs_fan_div(3); 656sysfs_fan_div(3);
688 657
689#define device_create_file_fan_div(client, offset) \
690do { \
691device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
692} while (0)
693
694static ssize_t 658static ssize_t
695show_pwm_reg(struct device *dev, char *buf, int nr) 659show_pwm_reg(struct device *dev, char *buf, int nr)
696{ 660{
@@ -787,16 +751,6 @@ sysfs_pwmenable(2); /* only PWM2 can be enabled/disabled */
787sysfs_pwm(3); 751sysfs_pwm(3);
788sysfs_pwm(4); 752sysfs_pwm(4);
789 753
790#define device_create_file_pwm(client, offset) \
791do { \
792device_create_file(&client->dev, &dev_attr_pwm##offset); \
793} while (0)
794
795#define device_create_file_pwmenable(client, offset) \
796do { \
797device_create_file(&client->dev, &dev_attr_pwm##offset##_enable); \
798} while (0)
799
800static ssize_t 754static ssize_t
801show_sensor_reg(struct device *dev, char *buf, int nr) 755show_sensor_reg(struct device *dev, char *buf, int nr)
802{ 756{
@@ -865,11 +819,6 @@ sysfs_sensor(1);
865sysfs_sensor(2); 819sysfs_sensor(2);
866sysfs_sensor(3); 820sysfs_sensor(3);
867 821
868#define device_create_file_sensor(client, offset) \
869do { \
870device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
871} while (0)
872
873/* This function is called when: 822/* This function is called when:
874 * w83781d_driver is inserted (when this module is loaded), for each 823 * w83781d_driver is inserted (when this module is loaded), for each
875 available adapter 824 available adapter
@@ -994,11 +943,69 @@ ERROR_SC_0:
994 return err; 943 return err;
995} 944}
996 945
946#define IN_UNIT_ATTRS(X) \
947 &dev_attr_in##X##_input.attr, \
948 &dev_attr_in##X##_min.attr, \
949 &dev_attr_in##X##_max.attr
950
951#define FAN_UNIT_ATTRS(X) \
952 &dev_attr_fan##X##_input.attr, \
953 &dev_attr_fan##X##_min.attr, \
954 &dev_attr_fan##X##_div.attr
955
956#define TEMP_UNIT_ATTRS(X) \
957 &dev_attr_temp##X##_input.attr, \
958 &dev_attr_temp##X##_max.attr, \
959 &dev_attr_temp##X##_max_hyst.attr
960
961static struct attribute* w83781d_attributes[] = {
962 IN_UNIT_ATTRS(0),
963 IN_UNIT_ATTRS(2),
964 IN_UNIT_ATTRS(3),
965 IN_UNIT_ATTRS(4),
966 IN_UNIT_ATTRS(5),
967 IN_UNIT_ATTRS(6),
968 FAN_UNIT_ATTRS(1),
969 FAN_UNIT_ATTRS(2),
970 FAN_UNIT_ATTRS(3),
971 TEMP_UNIT_ATTRS(1),
972 TEMP_UNIT_ATTRS(2),
973 &dev_attr_cpu0_vid.attr,
974 &dev_attr_vrm.attr,
975 &dev_attr_alarms.attr,
976 &dev_attr_beep_mask.attr,
977 &dev_attr_beep_enable.attr,
978 NULL
979};
980static const struct attribute_group w83781d_group = {
981 .attrs = w83781d_attributes,
982};
983
984static struct attribute *w83781d_attributes_opt[] = {
985 IN_UNIT_ATTRS(1),
986 IN_UNIT_ATTRS(7),
987 IN_UNIT_ATTRS(8),
988 TEMP_UNIT_ATTRS(3),
989 &dev_attr_pwm1.attr,
990 &dev_attr_pwm2.attr,
991 &dev_attr_pwm2_enable.attr,
992 &dev_attr_pwm3.attr,
993 &dev_attr_pwm4.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_type.attr,
996 &dev_attr_temp3_type.attr,
997 NULL
998};
999static const struct attribute_group w83781d_group_opt = {
1000 .attrs = w83781d_attributes_opt,
1001};
1002
997static int 1003static int
998w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 1004w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
999{ 1005{
1000 int i = 0, val1 = 0, val2; 1006 int i = 0, val1 = 0, val2;
1001 struct i2c_client *new_client; 1007 struct i2c_client *client;
1008 struct device *dev;
1002 struct w83781d_data *data; 1009 struct w83781d_data *data;
1003 int err; 1010 int err;
1004 const char *client_name = ""; 1011 const char *client_name = "";
@@ -1075,13 +1082,14 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1075 goto ERROR1; 1082 goto ERROR1;
1076 } 1083 }
1077 1084
1078 new_client = &data->client; 1085 client = &data->client;
1079 i2c_set_clientdata(new_client, data); 1086 i2c_set_clientdata(client, data);
1080 new_client->addr = address; 1087 client->addr = address;
1081 mutex_init(&data->lock); 1088 mutex_init(&data->lock);
1082 new_client->adapter = adapter; 1089 client->adapter = adapter;
1083 new_client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; 1090 client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver;
1084 new_client->flags = 0; 1091 client->flags = 0;
1092 dev = &client->dev;
1085 1093
1086 /* Now, we do the remaining detection. */ 1094 /* Now, we do the remaining detection. */
1087 1095
@@ -1090,20 +1098,18 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1090 force_*=... parameter, and the Winbond will be reset to the right 1098 force_*=... parameter, and the Winbond will be reset to the right
1091 bank. */ 1099 bank. */
1092 if (kind < 0) { 1100 if (kind < 0) {
1093 if (w83781d_read_value(new_client, W83781D_REG_CONFIG) & 0x80) { 1101 if (w83781d_read_value(client, W83781D_REG_CONFIG) & 0x80) {
1094 dev_dbg(&new_client->dev, "Detection failed at step " 1102 dev_dbg(dev, "Detection failed at step 3\n");
1095 "3\n");
1096 err = -ENODEV; 1103 err = -ENODEV;
1097 goto ERROR2; 1104 goto ERROR2;
1098 } 1105 }
1099 val1 = w83781d_read_value(new_client, W83781D_REG_BANK); 1106 val1 = w83781d_read_value(client, W83781D_REG_BANK);
1100 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); 1107 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN);
1101 /* Check for Winbond or Asus ID if in bank 0 */ 1108 /* Check for Winbond or Asus ID if in bank 0 */
1102 if ((!(val1 & 0x07)) && 1109 if ((!(val1 & 0x07)) &&
1103 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1110 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1104 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) { 1111 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
1105 dev_dbg(&new_client->dev, "Detection failed at step " 1112 dev_dbg(dev, "Detection failed at step 4\n");
1106 "4\n");
1107 err = -ENODEV; 1113 err = -ENODEV;
1108 goto ERROR2; 1114 goto ERROR2;
1109 } 1115 }
@@ -1112,9 +1118,8 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1112 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) || 1118 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) ||
1113 ((val1 & 0x80) && (val2 == 0x5c)))) { 1119 ((val1 & 0x80) && (val2 == 0x5c)))) {
1114 if (w83781d_read_value 1120 if (w83781d_read_value
1115 (new_client, W83781D_REG_I2C_ADDR) != address) { 1121 (client, W83781D_REG_I2C_ADDR) != address) {
1116 dev_dbg(&new_client->dev, "Detection failed " 1122 dev_dbg(dev, "Detection failed at step 5\n");
1117 "at step 5\n");
1118 err = -ENODEV; 1123 err = -ENODEV;
1119 goto ERROR2; 1124 goto ERROR2;
1120 } 1125 }
@@ -1123,27 +1128,26 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1123 1128
1124 /* We have either had a force parameter, or we have already detected the 1129 /* We have either had a force parameter, or we have already detected the
1125 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1130 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1126 w83781d_write_value(new_client, W83781D_REG_BANK, 1131 w83781d_write_value(client, W83781D_REG_BANK,
1127 (w83781d_read_value(new_client, 1132 (w83781d_read_value(client, W83781D_REG_BANK)
1128 W83781D_REG_BANK) & 0x78) | 1133 & 0x78) | 0x80);
1129 0x80);
1130 1134
1131 /* Determine the chip type. */ 1135 /* Determine the chip type. */
1132 if (kind <= 0) { 1136 if (kind <= 0) {
1133 /* get vendor ID */ 1137 /* get vendor ID */
1134 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); 1138 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN);
1135 if (val2 == 0x5c) 1139 if (val2 == 0x5c)
1136 vendid = winbond; 1140 vendid = winbond;
1137 else if (val2 == 0x12) 1141 else if (val2 == 0x12)
1138 vendid = asus; 1142 vendid = asus;
1139 else { 1143 else {
1140 dev_dbg(&new_client->dev, "Chip was made by neither " 1144 dev_dbg(dev, "Chip was made by neither "
1141 "Winbond nor Asus?\n"); 1145 "Winbond nor Asus?\n");
1142 err = -ENODEV; 1146 err = -ENODEV;
1143 goto ERROR2; 1147 goto ERROR2;
1144 } 1148 }
1145 1149
1146 val1 = w83781d_read_value(new_client, W83781D_REG_WCHIPID); 1150 val1 = w83781d_read_value(client, W83781D_REG_WCHIPID);
1147 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond) 1151 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1148 kind = w83781d; 1152 kind = w83781d;
1149 else if (val1 == 0x30 && vendid == winbond) 1153 else if (val1 == 0x30 && vendid == winbond)
@@ -1157,7 +1161,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1157 kind = as99127f; 1161 kind = as99127f;
1158 else { 1162 else {
1159 if (kind == 0) 1163 if (kind == 0)
1160 dev_warn(&new_client->dev, "Ignoring 'force' " 1164 dev_warn(dev, "Ignoring 'force' "
1161 "parameter for unknown chip at " 1165 "parameter for unknown chip at "
1162 "adapter %d, address 0x%02x\n", 1166 "adapter %d, address 0x%02x\n",
1163 i2c_adapter_id(adapter), address); 1167 i2c_adapter_id(adapter), address);
@@ -1179,20 +1183,20 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1179 } 1183 }
1180 1184
1181 /* Fill in the remaining client fields and put into the global list */ 1185 /* Fill in the remaining client fields and put into the global list */
1182 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 1186 strlcpy(client->name, client_name, I2C_NAME_SIZE);
1183 data->type = kind; 1187 data->type = kind;
1184 1188
1185 data->valid = 0; 1189 data->valid = 0;
1186 mutex_init(&data->update_lock); 1190 mutex_init(&data->update_lock);
1187 1191
1188 /* Tell the I2C layer a new client has arrived */ 1192 /* Tell the I2C layer a new client has arrived */
1189 if ((err = i2c_attach_client(new_client))) 1193 if ((err = i2c_attach_client(client)))
1190 goto ERROR2; 1194 goto ERROR2;
1191 1195
1192 /* attach secondary i2c lm75-like clients */ 1196 /* attach secondary i2c lm75-like clients */
1193 if (!is_isa) { 1197 if (!is_isa) {
1194 if ((err = w83781d_detect_subclients(adapter, address, 1198 if ((err = w83781d_detect_subclients(adapter, address,
1195 kind, new_client))) 1199 kind, client)))
1196 goto ERROR3; 1200 goto ERROR3;
1197 } else { 1201 } else {
1198 data->lm75[0] = NULL; 1202 data->lm75[0] = NULL;
@@ -1200,11 +1204,11 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1200 } 1204 }
1201 1205
1202 /* Initialize the chip */ 1206 /* Initialize the chip */
1203 w83781d_init_client(new_client); 1207 w83781d_init_client(client);
1204 1208
1205 /* A few vars need to be filled upon startup */ 1209 /* A few vars need to be filled upon startup */
1206 for (i = 1; i <= 3; i++) { 1210 for (i = 1; i <= 3; i++) {
1207 data->fan_min[i - 1] = w83781d_read_value(new_client, 1211 data->fan_min[i - 1] = w83781d_read_value(client,
1208 W83781D_REG_FAN_MIN(i)); 1212 W83781D_REG_FAN_MIN(i));
1209 } 1213 }
1210 if (kind != w83781d && kind != as99127f) 1214 if (kind != w83781d && kind != as99127f)
@@ -1212,65 +1216,68 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1212 data->pwmenable[i] = 1; 1216 data->pwmenable[i] = 1;
1213 1217
1214 /* Register sysfs hooks */ 1218 /* Register sysfs hooks */
1215 data->class_dev = hwmon_device_register(&new_client->dev); 1219 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group)))
1216 if (IS_ERR(data->class_dev)) {
1217 err = PTR_ERR(data->class_dev);
1218 goto ERROR4; 1220 goto ERROR4;
1219 }
1220 1221
1221 device_create_file_in(new_client, 0); 1222 if (kind != w83783s) {
1222 if (kind != w83783s) 1223 if ((err = device_create_file(dev, &dev_attr_in1_input))
1223 device_create_file_in(new_client, 1); 1224 || (err = device_create_file(dev, &dev_attr_in1_min))
1224 device_create_file_in(new_client, 2); 1225 || (err = device_create_file(dev, &dev_attr_in1_max)))
1225 device_create_file_in(new_client, 3); 1226 goto ERROR4;
1226 device_create_file_in(new_client, 4); 1227 }
1227 device_create_file_in(new_client, 5);
1228 device_create_file_in(new_client, 6);
1229 if (kind != as99127f && kind != w83781d && kind != w83783s) { 1228 if (kind != as99127f && kind != w83781d && kind != w83783s) {
1230 device_create_file_in(new_client, 7); 1229 if ((err = device_create_file(dev, &dev_attr_in7_input))
1231 device_create_file_in(new_client, 8); 1230 || (err = device_create_file(dev, &dev_attr_in7_min))
1231 || (err = device_create_file(dev, &dev_attr_in7_max))
1232 || (err = device_create_file(dev, &dev_attr_in8_input))
1233 || (err = device_create_file(dev, &dev_attr_in8_min))
1234 || (err = device_create_file(dev, &dev_attr_in8_max)))
1235 goto ERROR4;
1236 }
1237 if (kind != w83783s) {
1238 if ((err = device_create_file(dev, &dev_attr_temp3_input))
1239 || (err = device_create_file(dev, &dev_attr_temp3_max))
1240 || (err = device_create_file(dev,
1241 &dev_attr_temp3_max_hyst)))
1242 goto ERROR4;
1232 } 1243 }
1233
1234 device_create_file_fan(new_client, 1);
1235 device_create_file_fan(new_client, 2);
1236 device_create_file_fan(new_client, 3);
1237
1238 device_create_file_temp(new_client, 1);
1239 device_create_file_temp(new_client, 2);
1240 if (kind != w83783s)
1241 device_create_file_temp(new_client, 3);
1242
1243 device_create_file_vid(new_client);
1244 device_create_file_vrm(new_client);
1245
1246 device_create_file_fan_div(new_client, 1);
1247 device_create_file_fan_div(new_client, 2);
1248 device_create_file_fan_div(new_client, 3);
1249
1250 device_create_file_alarms(new_client);
1251
1252 device_create_file_beep(new_client);
1253 1244
1254 if (kind != w83781d && kind != as99127f) { 1245 if (kind != w83781d && kind != as99127f) {
1255 device_create_file_pwm(new_client, 1); 1246 if ((err = device_create_file(dev, &dev_attr_pwm1))
1256 device_create_file_pwm(new_client, 2); 1247 || (err = device_create_file(dev, &dev_attr_pwm2))
1257 device_create_file_pwmenable(new_client, 2); 1248 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1249 goto ERROR4;
1258 } 1250 }
1259 if (kind == w83782d && !is_isa) { 1251 if (kind == w83782d && !is_isa) {
1260 device_create_file_pwm(new_client, 3); 1252 if ((err = device_create_file(dev, &dev_attr_pwm3))
1261 device_create_file_pwm(new_client, 4); 1253 || (err = device_create_file(dev, &dev_attr_pwm4)))
1254 goto ERROR4;
1262 } 1255 }
1263 1256
1264 if (kind != as99127f && kind != w83781d) { 1257 if (kind != as99127f && kind != w83781d) {
1265 device_create_file_sensor(new_client, 1); 1258 if ((err = device_create_file(dev, &dev_attr_temp1_type))
1266 device_create_file_sensor(new_client, 2); 1259 || (err = device_create_file(dev,
1267 if (kind != w83783s) 1260 &dev_attr_temp2_type)))
1268 device_create_file_sensor(new_client, 3); 1261 goto ERROR4;
1262 if (kind != w83783s) {
1263 if ((err = device_create_file(dev,
1264 &dev_attr_temp3_type)))
1265 goto ERROR4;
1266 }
1267 }
1268
1269 data->class_dev = hwmon_device_register(dev);
1270 if (IS_ERR(data->class_dev)) {
1271 err = PTR_ERR(data->class_dev);
1272 goto ERROR4;
1269 } 1273 }
1270 1274
1271 return 0; 1275 return 0;
1272 1276
1273ERROR4: 1277ERROR4:
1278 sysfs_remove_group(&dev->kobj, &w83781d_group);
1279 sysfs_remove_group(&dev->kobj, &w83781d_group_opt);
1280
1274 if (data->lm75[1]) { 1281 if (data->lm75[1]) {
1275 i2c_detach_client(data->lm75[1]); 1282 i2c_detach_client(data->lm75[1]);
1276 kfree(data->lm75[1]); 1283 kfree(data->lm75[1]);
@@ -1280,7 +1287,7 @@ ERROR4:
1280 kfree(data->lm75[0]); 1287 kfree(data->lm75[0]);
1281 } 1288 }
1282ERROR3: 1289ERROR3:
1283 i2c_detach_client(new_client); 1290 i2c_detach_client(client);
1284ERROR2: 1291ERROR2:
1285 kfree(data); 1292 kfree(data);
1286ERROR1: 1293ERROR1:
@@ -1297,9 +1304,11 @@ w83781d_detach_client(struct i2c_client *client)
1297 int err; 1304 int err;
1298 1305
1299 /* main client */ 1306 /* main client */
1300 if (data) 1307 if (data) {
1301 hwmon_device_unregister(data->class_dev); 1308 hwmon_device_unregister(data->class_dev);
1302 1309 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1310 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1311 }
1303 if (i2c_is_isa_client(client)) 1312 if (i2c_is_isa_client(client))
1304 release_region(client->addr, W83781D_EXTENT); 1313 release_region(client->addr, W83781D_EXTENT);
1305 1314
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index eec43abd57fb..d965d074cd61 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -27,9 +27,9 @@
27 27
28 The w83791d chip appears to be part way between the 83781d and the 28 The w83791d chip appears to be part way between the 83781d and the
29 83792d. Thus, this file is derived from both the w83792d.c and 29 83792d. Thus, this file is derived from both the w83792d.c and
30 w83781d.c files, but its output is more along the lines of the 30 w83781d.c files.
31 83781d (which means there are no changes to the user-mode sensors 31
32 program which treats the 83791d as an 83781d). 32 The w83791g chip is the same as the w83791d but lead-free.
33*/ 33*/
34 34
35#include <linux/config.h> 35#include <linux/config.h>
@@ -1172,6 +1172,7 @@ static struct w83791d_data *w83791d_update_device(struct device *dev)
1172 (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) + 1172 (w83791d_read(client, W83791D_REG_BEEP_CTRL[1]) << 8) +
1173 (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16); 1173 (w83791d_read(client, W83791D_REG_BEEP_CTRL[2]) << 16);
1174 1174
1175 /* Extract global beep enable flag */
1175 data->beep_enable = 1176 data->beep_enable =
1176 (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01; 1177 (data->beep_mask >> GLOBAL_BEEP_ENABLE_SHIFT) & 0x01;
1177 1178
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 7576ec9426a3..4e108262576f 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -43,6 +43,7 @@
43#include <linux/hwmon-sysfs.h> 43#include <linux/hwmon-sysfs.h>
44#include <linux/err.h> 44#include <linux/err.h>
45#include <linux/mutex.h> 45#include <linux/mutex.h>
46#include <linux/sysfs.h>
46 47
47/* Addresses to scan */ 48/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; 49static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
@@ -381,41 +382,6 @@ static ssize_t store_in_##reg (struct device *dev, \
381store_in_reg(MIN, min); 382store_in_reg(MIN, min);
382store_in_reg(MAX, max); 383store_in_reg(MAX, max);
383 384
384static struct sensor_device_attribute sda_in_input[] = {
385 SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
386 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
387 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
388 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
389 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
390 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
391 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
392 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
393 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
394};
395static struct sensor_device_attribute sda_in_min[] = {
396 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
397 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
398 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
399 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3),
400 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4),
401 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5),
402 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6),
403 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7),
404 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8),
405};
406static struct sensor_device_attribute sda_in_max[] = {
407 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
408 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
409 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
410 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3),
411 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4),
412 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5),
413 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6),
414 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7),
415 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8),
416};
417
418
419#define show_fan_reg(reg) \ 385#define show_fan_reg(reg) \
420static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ 386static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
421 char *buf) \ 387 char *buf) \
@@ -499,35 +465,6 @@ store_fan_div(struct device *dev, struct device_attribute *attr,
499 return count; 465 return count;
500} 466}
501 467
502static struct sensor_device_attribute sda_fan_input[] = {
503 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1),
504 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2),
505 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3),
506 SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4),
507 SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5),
508 SENSOR_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6),
509 SENSOR_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7),
510};
511static struct sensor_device_attribute sda_fan_min[] = {
512 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 1),
513 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 2),
514 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 3),
515 SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 4),
516 SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 5),
517 SENSOR_ATTR(fan6_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 6),
518 SENSOR_ATTR(fan7_min, S_IWUSR | S_IRUGO, show_fan_min, store_fan_min, 7),
519};
520static struct sensor_device_attribute sda_fan_div[] = {
521 SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 1),
522 SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 2),
523 SENSOR_ATTR(fan3_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 3),
524 SENSOR_ATTR(fan4_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 4),
525 SENSOR_ATTR(fan5_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 5),
526 SENSOR_ATTR(fan6_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 6),
527 SENSOR_ATTR(fan7_div, S_IWUSR | S_IRUGO, show_fan_div, store_fan_div, 7),
528};
529
530
531/* read/write the temperature1, includes measured value and limits */ 468/* read/write the temperature1, includes measured value and limits */
532 469
533static ssize_t show_temp1(struct device *dev, struct device_attribute *attr, 470static ssize_t show_temp1(struct device *dev, struct device_attribute *attr,
@@ -595,24 +532,6 @@ static ssize_t store_temp23(struct device *dev, struct device_attribute *attr,
595 return count; 532 return count;
596} 533}
597 534
598static struct sensor_device_attribute_2 sda_temp_input[] = {
599 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0),
600 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0),
601 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0),
602};
603
604static struct sensor_device_attribute_2 sda_temp_max[] = {
605 SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 1),
606 SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 2),
607 SENSOR_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 2),
608};
609
610static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
611 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp1, store_temp1, 0, 2),
612 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 0, 4),
613 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp23, store_temp23, 1, 4),
614};
615
616/* get reatime status of all sensors items: voltage, temp, fan */ 535/* get reatime status of all sensors items: voltage, temp, fan */
617static ssize_t 536static ssize_t
618show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 537show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -621,9 +540,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
621 return sprintf(buf, "%d\n", data->alarms); 540 return sprintf(buf, "%d\n", data->alarms);
622} 541}
623 542
624static
625DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
626
627static ssize_t 543static ssize_t
628show_pwm(struct device *dev, struct device_attribute *attr, 544show_pwm(struct device *dev, struct device_attribute *attr,
629 char *buf) 545 char *buf)
@@ -715,21 +631,6 @@ store_pwmenable(struct device *dev, struct device_attribute *attr,
715 return count; 631 return count;
716} 632}
717 633
718static struct sensor_device_attribute sda_pwm[] = {
719 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
720 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
721 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2),
722};
723static struct sensor_device_attribute sda_pwm_enable[] = {
724 SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
725 show_pwmenable, store_pwmenable, 1),
726 SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
727 show_pwmenable, store_pwmenable, 2),
728 SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
729 show_pwmenable, store_pwmenable, 3),
730};
731
732
733static ssize_t 634static ssize_t
734show_pwm_mode(struct device *dev, struct device_attribute *attr, 635show_pwm_mode(struct device *dev, struct device_attribute *attr,
735 char *buf) 636 char *buf)
@@ -767,16 +668,6 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr,
767 return count; 668 return count;
768} 669}
769 670
770static struct sensor_device_attribute sda_pwm_mode[] = {
771 SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
772 show_pwm_mode, store_pwm_mode, 0),
773 SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
774 show_pwm_mode, store_pwm_mode, 1),
775 SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
776 show_pwm_mode, store_pwm_mode, 2),
777};
778
779
780static ssize_t 671static ssize_t
781show_regs_chassis(struct device *dev, struct device_attribute *attr, 672show_regs_chassis(struct device *dev, struct device_attribute *attr,
782 char *buf) 673 char *buf)
@@ -785,8 +676,6 @@ show_regs_chassis(struct device *dev, struct device_attribute *attr,
785 return sprintf(buf, "%d\n", data->chassis); 676 return sprintf(buf, "%d\n", data->chassis);
786} 677}
787 678
788static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
789
790static ssize_t 679static ssize_t
791show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf) 680show_chassis_clear(struct device *dev, struct device_attribute *attr, char *buf)
792{ 681{
@@ -815,9 +704,6 @@ store_chassis_clear(struct device *dev, struct device_attribute *attr,
815 return count; 704 return count;
816} 705}
817 706
818static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
819 show_chassis_clear, store_chassis_clear);
820
821/* For Smart Fan I / Thermal Cruise */ 707/* For Smart Fan I / Thermal Cruise */
822static ssize_t 708static ssize_t
823show_thermal_cruise(struct device *dev, struct device_attribute *attr, 709show_thermal_cruise(struct device *dev, struct device_attribute *attr,
@@ -853,15 +739,6 @@ store_thermal_cruise(struct device *dev, struct device_attribute *attr,
853 return count; 739 return count;
854} 740}
855 741
856static struct sensor_device_attribute sda_thermal_cruise[] = {
857 SENSOR_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
858 show_thermal_cruise, store_thermal_cruise, 1),
859 SENSOR_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
860 show_thermal_cruise, store_thermal_cruise, 2),
861 SENSOR_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
862 show_thermal_cruise, store_thermal_cruise, 3),
863};
864
865/* For Smart Fan I/Thermal Cruise and Smart Fan II */ 742/* For Smart Fan I/Thermal Cruise and Smart Fan II */
866static ssize_t 743static ssize_t
867show_tolerance(struct device *dev, struct device_attribute *attr, 744show_tolerance(struct device *dev, struct device_attribute *attr,
@@ -901,15 +778,6 @@ store_tolerance(struct device *dev, struct device_attribute *attr,
901 return count; 778 return count;
902} 779}
903 780
904static struct sensor_device_attribute sda_tolerance[] = {
905 SENSOR_ATTR(tolerance1, S_IWUSR | S_IRUGO,
906 show_tolerance, store_tolerance, 1),
907 SENSOR_ATTR(tolerance2, S_IWUSR | S_IRUGO,
908 show_tolerance, store_tolerance, 2),
909 SENSOR_ATTR(tolerance3, S_IWUSR | S_IRUGO,
910 show_tolerance, store_tolerance, 3),
911};
912
913/* For Smart Fan II */ 781/* For Smart Fan II */
914static ssize_t 782static ssize_t
915show_sf2_point(struct device *dev, struct device_attribute *attr, 783show_sf2_point(struct device *dev, struct device_attribute *attr,
@@ -946,36 +814,6 @@ store_sf2_point(struct device *dev, struct device_attribute *attr,
946 return count; 814 return count;
947} 815}
948 816
949static struct sensor_device_attribute_2 sda_sf2_point[] = {
950 SENSOR_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
951 show_sf2_point, store_sf2_point, 1, 1),
952 SENSOR_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
953 show_sf2_point, store_sf2_point, 2, 1),
954 SENSOR_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
955 show_sf2_point, store_sf2_point, 3, 1),
956 SENSOR_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
957 show_sf2_point, store_sf2_point, 4, 1),
958
959 SENSOR_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
960 show_sf2_point, store_sf2_point, 1, 2),
961 SENSOR_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
962 show_sf2_point, store_sf2_point, 2, 2),
963 SENSOR_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
964 show_sf2_point, store_sf2_point, 3, 2),
965 SENSOR_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
966 show_sf2_point, store_sf2_point, 4, 2),
967
968 SENSOR_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
969 show_sf2_point, store_sf2_point, 1, 3),
970 SENSOR_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
971 show_sf2_point, store_sf2_point, 2, 3),
972 SENSOR_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
973 show_sf2_point, store_sf2_point, 3, 3),
974 SENSOR_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
975 show_sf2_point, store_sf2_point, 4, 3),
976};
977
978
979static ssize_t 817static ssize_t
980show_sf2_level(struct device *dev, struct device_attribute *attr, 818show_sf2_level(struct device *dev, struct device_attribute *attr,
981 char *buf) 819 char *buf)
@@ -1016,29 +854,6 @@ store_sf2_level(struct device *dev, struct device_attribute *attr,
1016 return count; 854 return count;
1017} 855}
1018 856
1019static struct sensor_device_attribute_2 sda_sf2_level[] = {
1020 SENSOR_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1021 show_sf2_level, store_sf2_level, 1, 1),
1022 SENSOR_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1023 show_sf2_level, store_sf2_level, 2, 1),
1024 SENSOR_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1025 show_sf2_level, store_sf2_level, 3, 1),
1026
1027 SENSOR_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1028 show_sf2_level, store_sf2_level, 1, 2),
1029 SENSOR_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1030 show_sf2_level, store_sf2_level, 2, 2),
1031 SENSOR_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1032 show_sf2_level, store_sf2_level, 3, 2),
1033
1034 SENSOR_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1035 show_sf2_level, store_sf2_level, 1, 3),
1036 SENSOR_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1037 show_sf2_level, store_sf2_level, 2, 3),
1038 SENSOR_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1039 show_sf2_level, store_sf2_level, 3, 3),
1040};
1041
1042/* This function is called when: 857/* This function is called when:
1043 * w83792d_driver is inserted (when this module is loaded), for each 858 * w83792d_driver is inserted (when this module is loaded), for each
1044 available adapter 859 available adapter
@@ -1139,12 +954,297 @@ ERROR_SC_0:
1139 return err; 954 return err;
1140} 955}
1141 956
1142static void device_create_file_fan(struct device *dev, int i) 957static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in, NULL, 0);
1143{ 958static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
1144 device_create_file(dev, &sda_fan_input[i].dev_attr); 959static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
1145 device_create_file(dev, &sda_fan_div[i].dev_attr); 960static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
1146 device_create_file(dev, &sda_fan_min[i].dev_attr); 961static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
1147} 962static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
963static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
964static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
965static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
966static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
967 show_in_min, store_in_min, 0);
968static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
969 show_in_min, store_in_min, 1);
970static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
971 show_in_min, store_in_min, 2);
972static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
973 show_in_min, store_in_min, 3);
974static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
975 show_in_min, store_in_min, 4);
976static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
977 show_in_min, store_in_min, 5);
978static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
979 show_in_min, store_in_min, 6);
980static SENSOR_DEVICE_ATTR(in7_min, S_IWUSR | S_IRUGO,
981 show_in_min, store_in_min, 7);
982static SENSOR_DEVICE_ATTR(in8_min, S_IWUSR | S_IRUGO,
983 show_in_min, store_in_min, 8);
984static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
985 show_in_max, store_in_max, 0);
986static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
987 show_in_max, store_in_max, 1);
988static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
989 show_in_max, store_in_max, 2);
990static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
991 show_in_max, store_in_max, 3);
992static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
993 show_in_max, store_in_max, 4);
994static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
995 show_in_max, store_in_max, 5);
996static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
997 show_in_max, store_in_max, 6);
998static SENSOR_DEVICE_ATTR(in7_max, S_IWUSR | S_IRUGO,
999 show_in_max, store_in_max, 7);
1000static SENSOR_DEVICE_ATTR(in8_max, S_IWUSR | S_IRUGO,
1001 show_in_max, store_in_max, 8);
1002static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp1, NULL, 0, 0);
1003static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp23, NULL, 0, 0);
1004static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp23, NULL, 1, 0);
1005static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
1006 show_temp1, store_temp1, 0, 1);
1007static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp23,
1008 store_temp23, 0, 2);
1009static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp23,
1010 store_temp23, 1, 2);
1011static SENSOR_DEVICE_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
1012 show_temp1, store_temp1, 0, 2);
1013static SENSOR_DEVICE_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
1014 show_temp23, store_temp23, 0, 4);
1015static SENSOR_DEVICE_ATTR_2(temp3_max_hyst, S_IRUGO | S_IWUSR,
1016 show_temp23, store_temp23, 1, 4);
1017static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1018static DEVICE_ATTR(chassis, S_IRUGO, show_regs_chassis, NULL);
1019static DEVICE_ATTR(chassis_clear, S_IRUGO | S_IWUSR,
1020 show_chassis_clear, store_chassis_clear);
1021static SENSOR_DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0);
1022static SENSOR_DEVICE_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1);
1023static SENSOR_DEVICE_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2);
1024static SENSOR_DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO,
1025 show_pwmenable, store_pwmenable, 1);
1026static SENSOR_DEVICE_ATTR(pwm2_enable, S_IWUSR | S_IRUGO,
1027 show_pwmenable, store_pwmenable, 2);
1028static SENSOR_DEVICE_ATTR(pwm3_enable, S_IWUSR | S_IRUGO,
1029 show_pwmenable, store_pwmenable, 3);
1030static SENSOR_DEVICE_ATTR(pwm1_mode, S_IWUSR | S_IRUGO,
1031 show_pwm_mode, store_pwm_mode, 0);
1032static SENSOR_DEVICE_ATTR(pwm2_mode, S_IWUSR | S_IRUGO,
1033 show_pwm_mode, store_pwm_mode, 1);
1034static SENSOR_DEVICE_ATTR(pwm3_mode, S_IWUSR | S_IRUGO,
1035 show_pwm_mode, store_pwm_mode, 2);
1036static SENSOR_DEVICE_ATTR(tolerance1, S_IWUSR | S_IRUGO,
1037 show_tolerance, store_tolerance, 1);
1038static SENSOR_DEVICE_ATTR(tolerance2, S_IWUSR | S_IRUGO,
1039 show_tolerance, store_tolerance, 2);
1040static SENSOR_DEVICE_ATTR(tolerance3, S_IWUSR | S_IRUGO,
1041 show_tolerance, store_tolerance, 3);
1042static SENSOR_DEVICE_ATTR(thermal_cruise1, S_IWUSR | S_IRUGO,
1043 show_thermal_cruise, store_thermal_cruise, 1);
1044static SENSOR_DEVICE_ATTR(thermal_cruise2, S_IWUSR | S_IRUGO,
1045 show_thermal_cruise, store_thermal_cruise, 2);
1046static SENSOR_DEVICE_ATTR(thermal_cruise3, S_IWUSR | S_IRUGO,
1047 show_thermal_cruise, store_thermal_cruise, 3);
1048static SENSOR_DEVICE_ATTR_2(sf2_point1_fan1, S_IRUGO | S_IWUSR,
1049 show_sf2_point, store_sf2_point, 1, 1);
1050static SENSOR_DEVICE_ATTR_2(sf2_point2_fan1, S_IRUGO | S_IWUSR,
1051 show_sf2_point, store_sf2_point, 2, 1);
1052static SENSOR_DEVICE_ATTR_2(sf2_point3_fan1, S_IRUGO | S_IWUSR,
1053 show_sf2_point, store_sf2_point, 3, 1);
1054static SENSOR_DEVICE_ATTR_2(sf2_point4_fan1, S_IRUGO | S_IWUSR,
1055 show_sf2_point, store_sf2_point, 4, 1);
1056static SENSOR_DEVICE_ATTR_2(sf2_point1_fan2, S_IRUGO | S_IWUSR,
1057 show_sf2_point, store_sf2_point, 1, 2);
1058static SENSOR_DEVICE_ATTR_2(sf2_point2_fan2, S_IRUGO | S_IWUSR,
1059 show_sf2_point, store_sf2_point, 2, 2);
1060static SENSOR_DEVICE_ATTR_2(sf2_point3_fan2, S_IRUGO | S_IWUSR,
1061 show_sf2_point, store_sf2_point, 3, 2);
1062static SENSOR_DEVICE_ATTR_2(sf2_point4_fan2, S_IRUGO | S_IWUSR,
1063 show_sf2_point, store_sf2_point, 4, 2);
1064static SENSOR_DEVICE_ATTR_2(sf2_point1_fan3, S_IRUGO | S_IWUSR,
1065 show_sf2_point, store_sf2_point, 1, 3);
1066static SENSOR_DEVICE_ATTR_2(sf2_point2_fan3, S_IRUGO | S_IWUSR,
1067 show_sf2_point, store_sf2_point, 2, 3);
1068static SENSOR_DEVICE_ATTR_2(sf2_point3_fan3, S_IRUGO | S_IWUSR,
1069 show_sf2_point, store_sf2_point, 3, 3);
1070static SENSOR_DEVICE_ATTR_2(sf2_point4_fan3, S_IRUGO | S_IWUSR,
1071 show_sf2_point, store_sf2_point, 4, 3);
1072static SENSOR_DEVICE_ATTR_2(sf2_level1_fan1, S_IRUGO | S_IWUSR,
1073 show_sf2_level, store_sf2_level, 1, 1);
1074static SENSOR_DEVICE_ATTR_2(sf2_level2_fan1, S_IRUGO | S_IWUSR,
1075 show_sf2_level, store_sf2_level, 2, 1);
1076static SENSOR_DEVICE_ATTR_2(sf2_level3_fan1, S_IRUGO | S_IWUSR,
1077 show_sf2_level, store_sf2_level, 3, 1);
1078static SENSOR_DEVICE_ATTR_2(sf2_level1_fan2, S_IRUGO | S_IWUSR,
1079 show_sf2_level, store_sf2_level, 1, 2);
1080static SENSOR_DEVICE_ATTR_2(sf2_level2_fan2, S_IRUGO | S_IWUSR,
1081 show_sf2_level, store_sf2_level, 2, 2);
1082static SENSOR_DEVICE_ATTR_2(sf2_level3_fan2, S_IRUGO | S_IWUSR,
1083 show_sf2_level, store_sf2_level, 3, 2);
1084static SENSOR_DEVICE_ATTR_2(sf2_level1_fan3, S_IRUGO | S_IWUSR,
1085 show_sf2_level, store_sf2_level, 1, 3);
1086static SENSOR_DEVICE_ATTR_2(sf2_level2_fan3, S_IRUGO | S_IWUSR,
1087 show_sf2_level, store_sf2_level, 2, 3);
1088static SENSOR_DEVICE_ATTR_2(sf2_level3_fan3, S_IRUGO | S_IWUSR,
1089 show_sf2_level, store_sf2_level, 3, 3);
1090static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 1);
1091static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 2);
1092static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 3);
1093static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 4);
1094static SENSOR_DEVICE_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 5);
1095static SENSOR_DEVICE_ATTR(fan6_input, S_IRUGO, show_fan, NULL, 6);
1096static SENSOR_DEVICE_ATTR(fan7_input, S_IRUGO, show_fan, NULL, 7);
1097static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
1098 show_fan_min, store_fan_min, 1);
1099static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
1100 show_fan_min, store_fan_min, 2);
1101static SENSOR_DEVICE_ATTR(fan3_min, S_IWUSR | S_IRUGO,
1102 show_fan_min, store_fan_min, 3);
1103static SENSOR_DEVICE_ATTR(fan4_min, S_IWUSR | S_IRUGO,
1104 show_fan_min, store_fan_min, 4);
1105static SENSOR_DEVICE_ATTR(fan5_min, S_IWUSR | S_IRUGO,
1106 show_fan_min, store_fan_min, 5);
1107static SENSOR_DEVICE_ATTR(fan6_min, S_IWUSR | S_IRUGO,
1108 show_fan_min, store_fan_min, 6);
1109static SENSOR_DEVICE_ATTR(fan7_min, S_IWUSR | S_IRUGO,
1110 show_fan_min, store_fan_min, 7);
1111static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
1112 show_fan_div, store_fan_div, 1);
1113static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
1114 show_fan_div, store_fan_div, 2);
1115static SENSOR_DEVICE_ATTR(fan3_div, S_IWUSR | S_IRUGO,
1116 show_fan_div, store_fan_div, 3);
1117static SENSOR_DEVICE_ATTR(fan4_div, S_IWUSR | S_IRUGO,
1118 show_fan_div, store_fan_div, 4);
1119static SENSOR_DEVICE_ATTR(fan5_div, S_IWUSR | S_IRUGO,
1120 show_fan_div, store_fan_div, 5);
1121static SENSOR_DEVICE_ATTR(fan6_div, S_IWUSR | S_IRUGO,
1122 show_fan_div, store_fan_div, 6);
1123static SENSOR_DEVICE_ATTR(fan7_div, S_IWUSR | S_IRUGO,
1124 show_fan_div, store_fan_div, 7);
1125
1126static struct attribute *w83792d_attributes_fan[4][4] = {
1127 {
1128 &sensor_dev_attr_fan4_input.dev_attr.attr,
1129 &sensor_dev_attr_fan4_min.dev_attr.attr,
1130 &sensor_dev_attr_fan4_div.dev_attr.attr,
1131 NULL
1132 }, {
1133 &sensor_dev_attr_fan5_input.dev_attr.attr,
1134 &sensor_dev_attr_fan5_min.dev_attr.attr,
1135 &sensor_dev_attr_fan5_div.dev_attr.attr,
1136 NULL
1137 }, {
1138 &sensor_dev_attr_fan6_input.dev_attr.attr,
1139 &sensor_dev_attr_fan6_min.dev_attr.attr,
1140 &sensor_dev_attr_fan6_div.dev_attr.attr,
1141 NULL
1142 }, {
1143 &sensor_dev_attr_fan7_input.dev_attr.attr,
1144 &sensor_dev_attr_fan7_min.dev_attr.attr,
1145 &sensor_dev_attr_fan7_div.dev_attr.attr,
1146 NULL
1147 }
1148};
1149
1150static const struct attribute_group w83792d_group_fan[4] = {
1151 { .attrs = w83792d_attributes_fan[0] },
1152 { .attrs = w83792d_attributes_fan[1] },
1153 { .attrs = w83792d_attributes_fan[2] },
1154 { .attrs = w83792d_attributes_fan[3] },
1155};
1156
1157static struct attribute *w83792d_attributes[] = {
1158 &sensor_dev_attr_in0_input.dev_attr.attr,
1159 &sensor_dev_attr_in0_max.dev_attr.attr,
1160 &sensor_dev_attr_in0_min.dev_attr.attr,
1161 &sensor_dev_attr_in1_input.dev_attr.attr,
1162 &sensor_dev_attr_in1_max.dev_attr.attr,
1163 &sensor_dev_attr_in1_min.dev_attr.attr,
1164 &sensor_dev_attr_in2_input.dev_attr.attr,
1165 &sensor_dev_attr_in2_max.dev_attr.attr,
1166 &sensor_dev_attr_in2_min.dev_attr.attr,
1167 &sensor_dev_attr_in3_input.dev_attr.attr,
1168 &sensor_dev_attr_in3_max.dev_attr.attr,
1169 &sensor_dev_attr_in3_min.dev_attr.attr,
1170 &sensor_dev_attr_in4_input.dev_attr.attr,
1171 &sensor_dev_attr_in4_max.dev_attr.attr,
1172 &sensor_dev_attr_in4_min.dev_attr.attr,
1173 &sensor_dev_attr_in5_input.dev_attr.attr,
1174 &sensor_dev_attr_in5_max.dev_attr.attr,
1175 &sensor_dev_attr_in5_min.dev_attr.attr,
1176 &sensor_dev_attr_in6_input.dev_attr.attr,
1177 &sensor_dev_attr_in6_max.dev_attr.attr,
1178 &sensor_dev_attr_in6_min.dev_attr.attr,
1179 &sensor_dev_attr_in7_input.dev_attr.attr,
1180 &sensor_dev_attr_in7_max.dev_attr.attr,
1181 &sensor_dev_attr_in7_min.dev_attr.attr,
1182 &sensor_dev_attr_in8_input.dev_attr.attr,
1183 &sensor_dev_attr_in8_max.dev_attr.attr,
1184 &sensor_dev_attr_in8_min.dev_attr.attr,
1185 &sensor_dev_attr_temp1_input.dev_attr.attr,
1186 &sensor_dev_attr_temp1_max.dev_attr.attr,
1187 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
1188 &sensor_dev_attr_temp2_input.dev_attr.attr,
1189 &sensor_dev_attr_temp2_max.dev_attr.attr,
1190 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
1191 &sensor_dev_attr_temp3_input.dev_attr.attr,
1192 &sensor_dev_attr_temp3_max.dev_attr.attr,
1193 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
1194 &sensor_dev_attr_pwm1.dev_attr.attr,
1195 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
1196 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
1197 &sensor_dev_attr_pwm2.dev_attr.attr,
1198 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
1199 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1200 &sensor_dev_attr_pwm3.dev_attr.attr,
1201 &sensor_dev_attr_pwm3_mode.dev_attr.attr,
1202 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1203 &dev_attr_alarms.attr,
1204 &dev_attr_chassis.attr,
1205 &dev_attr_chassis_clear.attr,
1206 &sensor_dev_attr_tolerance1.dev_attr.attr,
1207 &sensor_dev_attr_thermal_cruise1.dev_attr.attr,
1208 &sensor_dev_attr_tolerance2.dev_attr.attr,
1209 &sensor_dev_attr_thermal_cruise2.dev_attr.attr,
1210 &sensor_dev_attr_tolerance3.dev_attr.attr,
1211 &sensor_dev_attr_thermal_cruise3.dev_attr.attr,
1212 &sensor_dev_attr_sf2_point1_fan1.dev_attr.attr,
1213 &sensor_dev_attr_sf2_point2_fan1.dev_attr.attr,
1214 &sensor_dev_attr_sf2_point3_fan1.dev_attr.attr,
1215 &sensor_dev_attr_sf2_point4_fan1.dev_attr.attr,
1216 &sensor_dev_attr_sf2_point1_fan2.dev_attr.attr,
1217 &sensor_dev_attr_sf2_point2_fan2.dev_attr.attr,
1218 &sensor_dev_attr_sf2_point3_fan2.dev_attr.attr,
1219 &sensor_dev_attr_sf2_point4_fan2.dev_attr.attr,
1220 &sensor_dev_attr_sf2_point1_fan3.dev_attr.attr,
1221 &sensor_dev_attr_sf2_point2_fan3.dev_attr.attr,
1222 &sensor_dev_attr_sf2_point3_fan3.dev_attr.attr,
1223 &sensor_dev_attr_sf2_point4_fan3.dev_attr.attr,
1224 &sensor_dev_attr_sf2_level1_fan1.dev_attr.attr,
1225 &sensor_dev_attr_sf2_level2_fan1.dev_attr.attr,
1226 &sensor_dev_attr_sf2_level3_fan1.dev_attr.attr,
1227 &sensor_dev_attr_sf2_level1_fan2.dev_attr.attr,
1228 &sensor_dev_attr_sf2_level2_fan2.dev_attr.attr,
1229 &sensor_dev_attr_sf2_level3_fan2.dev_attr.attr,
1230 &sensor_dev_attr_sf2_level1_fan3.dev_attr.attr,
1231 &sensor_dev_attr_sf2_level2_fan3.dev_attr.attr,
1232 &sensor_dev_attr_sf2_level3_fan3.dev_attr.attr,
1233 &sensor_dev_attr_fan1_input.dev_attr.attr,
1234 &sensor_dev_attr_fan1_min.dev_attr.attr,
1235 &sensor_dev_attr_fan1_div.dev_attr.attr,
1236 &sensor_dev_attr_fan2_input.dev_attr.attr,
1237 &sensor_dev_attr_fan2_min.dev_attr.attr,
1238 &sensor_dev_attr_fan2_div.dev_attr.attr,
1239 &sensor_dev_attr_fan3_input.dev_attr.attr,
1240 &sensor_dev_attr_fan3_min.dev_attr.attr,
1241 &sensor_dev_attr_fan3_div.dev_attr.attr,
1242 NULL
1243};
1244
1245static const struct attribute_group w83792d_group = {
1246 .attrs = w83792d_attributes,
1247};
1148 1248
1149static int 1249static int
1150w83792d_detect(struct i2c_adapter *adapter, int address, int kind) 1250w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
@@ -1268,59 +1368,46 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1268 } 1368 }
1269 1369
1270 /* Register sysfs hooks */ 1370 /* Register sysfs hooks */
1271 data->class_dev = hwmon_device_register(dev); 1371 if ((err = sysfs_create_group(&dev->kobj, &w83792d_group)))
1272 if (IS_ERR(data->class_dev)) {
1273 err = PTR_ERR(data->class_dev);
1274 goto ERROR3; 1372 goto ERROR3;
1275 }
1276 for (i = 0; i < 9; i++) {
1277 device_create_file(dev, &sda_in_input[i].dev_attr);
1278 device_create_file(dev, &sda_in_max[i].dev_attr);
1279 device_create_file(dev, &sda_in_min[i].dev_attr);
1280 }
1281 for (i = 0; i < 3; i++)
1282 device_create_file_fan(dev, i);
1283 1373
1284 /* Read GPIO enable register to check if pins for fan 4,5 are used as 1374 /* Read GPIO enable register to check if pins for fan 4,5 are used as
1285 GPIO */ 1375 GPIO */
1286 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN); 1376 val1 = w83792d_read_value(client, W83792D_REG_GPIO_EN);
1377
1287 if (!(val1 & 0x40)) 1378 if (!(val1 & 0x40))
1288 device_create_file_fan(dev, 3); 1379 if ((err = sysfs_create_group(&dev->kobj,
1380 &w83792d_group_fan[0])))
1381 goto exit_remove_files;
1382
1289 if (!(val1 & 0x20)) 1383 if (!(val1 & 0x20))
1290 device_create_file_fan(dev, 4); 1384 if ((err = sysfs_create_group(&dev->kobj,
1385 &w83792d_group_fan[1])))
1386 goto exit_remove_files;
1291 1387
1292 val1 = w83792d_read_value(client, W83792D_REG_PIN); 1388 val1 = w83792d_read_value(client, W83792D_REG_PIN);
1293 if (val1 & 0x40) 1389 if (val1 & 0x40)
1294 device_create_file_fan(dev, 5); 1390 if ((err = sysfs_create_group(&dev->kobj,
1391 &w83792d_group_fan[2])))
1392 goto exit_remove_files;
1393
1295 if (val1 & 0x04) 1394 if (val1 & 0x04)
1296 device_create_file_fan(dev, 6); 1395 if ((err = sysfs_create_group(&dev->kobj,
1297 1396 &w83792d_group_fan[3])))
1298 for (i = 0; i < 3; i++) { 1397 goto exit_remove_files;
1299 device_create_file(dev, &sda_temp_input[i].dev_attr);
1300 device_create_file(dev, &sda_temp_max[i].dev_attr);
1301 device_create_file(dev, &sda_temp_max_hyst[i].dev_attr);
1302 device_create_file(dev, &sda_thermal_cruise[i].dev_attr);
1303 device_create_file(dev, &sda_tolerance[i].dev_attr);
1304 }
1305 1398
1306 for (i = 0; i < ARRAY_SIZE(sda_pwm); i++) { 1399 data->class_dev = hwmon_device_register(dev);
1307 device_create_file(dev, &sda_pwm[i].dev_attr); 1400 if (IS_ERR(data->class_dev)) {
1308 device_create_file(dev, &sda_pwm_enable[i].dev_attr); 1401 err = PTR_ERR(data->class_dev);
1309 device_create_file(dev, &sda_pwm_mode[i].dev_attr); 1402 goto exit_remove_files;
1310 } 1403 }
1311 1404
1312 device_create_file(dev, &dev_attr_alarms);
1313 device_create_file(dev, &dev_attr_chassis);
1314 device_create_file(dev, &dev_attr_chassis_clear);
1315
1316 for (i = 0; i < ARRAY_SIZE(sda_sf2_point); i++)
1317 device_create_file(dev, &sda_sf2_point[i].dev_attr);
1318
1319 for (i = 0; i < ARRAY_SIZE(sda_sf2_level); i++)
1320 device_create_file(dev, &sda_sf2_level[i].dev_attr);
1321
1322 return 0; 1405 return 0;
1323 1406
1407exit_remove_files:
1408 sysfs_remove_group(&dev->kobj, &w83792d_group);
1409 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1410 sysfs_remove_group(&dev->kobj, &w83792d_group_fan[i]);
1324ERROR3: 1411ERROR3:
1325 if (data->lm75[0] != NULL) { 1412 if (data->lm75[0] != NULL) {
1326 i2c_detach_client(data->lm75[0]); 1413 i2c_detach_client(data->lm75[0]);
@@ -1342,11 +1429,16 @@ static int
1342w83792d_detach_client(struct i2c_client *client) 1429w83792d_detach_client(struct i2c_client *client)
1343{ 1430{
1344 struct w83792d_data *data = i2c_get_clientdata(client); 1431 struct w83792d_data *data = i2c_get_clientdata(client);
1345 int err; 1432 int err, i;
1346 1433
1347 /* main client */ 1434 /* main client */
1348 if (data) 1435 if (data) {
1349 hwmon_device_unregister(data->class_dev); 1436 hwmon_device_unregister(data->class_dev);
1437 sysfs_remove_group(&client->dev.kobj, &w83792d_group);
1438 for (i = 0; i < ARRAY_SIZE(w83792d_group_fan); i++)
1439 sysfs_remove_group(&client->dev.kobj,
1440 &w83792d_group_fan[i]);
1441 }
1350 1442
1351 if ((err = i2c_detach_client(client))) 1443 if ((err = i2c_detach_client(client)))
1352 return err; 1444 return err;
diff --git a/drivers/hwmon/w83l785ts.c b/drivers/hwmon/w83l785ts.c
index 3f2bac125fb1..a3fcace412f0 100644
--- a/drivers/hwmon/w83l785ts.c
+++ b/drivers/hwmon/w83l785ts.c
@@ -236,21 +236,30 @@ static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
236 * Nothing yet, assume it is already started. 236 * Nothing yet, assume it is already started.
237 */ 237 */
238 238
239 err = device_create_file(&new_client->dev,
240 &sensor_dev_attr_temp1_input.dev_attr);
241 if (err)
242 goto exit_remove;
243
244 err = device_create_file(&new_client->dev,
245 &sensor_dev_attr_temp1_max.dev_attr);
246 if (err)
247 goto exit_remove;
248
239 /* Register sysfs hooks */ 249 /* Register sysfs hooks */
240 data->class_dev = hwmon_device_register(&new_client->dev); 250 data->class_dev = hwmon_device_register(&new_client->dev);
241 if (IS_ERR(data->class_dev)) { 251 if (IS_ERR(data->class_dev)) {
242 err = PTR_ERR(data->class_dev); 252 err = PTR_ERR(data->class_dev);
243 goto exit_detach; 253 goto exit_remove;
244 } 254 }
245 255
246 device_create_file(&new_client->dev,
247 &sensor_dev_attr_temp1_input.dev_attr);
248 device_create_file(&new_client->dev,
249 &sensor_dev_attr_temp1_max.dev_attr);
250
251 return 0; 256 return 0;
252 257
253exit_detach: 258exit_remove:
259 device_remove_file(&new_client->dev,
260 &sensor_dev_attr_temp1_input.dev_attr);
261 device_remove_file(&new_client->dev,
262 &sensor_dev_attr_temp1_max.dev_attr);
254 i2c_detach_client(new_client); 263 i2c_detach_client(new_client);
255exit_free: 264exit_free:
256 kfree(data); 265 kfree(data);
@@ -264,7 +273,10 @@ static int w83l785ts_detach_client(struct i2c_client *client)
264 int err; 273 int err;
265 274
266 hwmon_device_unregister(data->class_dev); 275 hwmon_device_unregister(data->class_dev);
267 276 device_remove_file(&client->dev,
277 &sensor_dev_attr_temp1_input.dev_attr);
278 device_remove_file(&client->dev,
279 &sensor_dev_attr_temp1_max.dev_attr);
268 if ((err = i2c_detach_client(client))) 280 if ((err = i2c_detach_client(client)))
269 return err; 281 return err;
270 282
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 9e56c3989d68..0d9667921f61 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -196,7 +196,7 @@ config I2C_IBM_IIC
196 196
197config I2C_IOP3XX 197config I2C_IOP3XX
198 tristate "Intel IOP3xx and IXP4xx on-chip I2C interface" 198 tristate "Intel IOP3xx and IXP4xx on-chip I2C interface"
199 depends on (ARCH_IOP3XX || ARCH_IXP4XX) && I2C 199 depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX) && I2C
200 help 200 help
201 Say Y here if you want to use the IIC bus controller on 201 Say Y here if you want to use the IIC bus controller on
202 the Intel IOP3xx I/O Processors or IXP4xx Network Processors. 202 the Intel IOP3xx I/O Processors or IXP4xx Network Processors.
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 8e413150af37..4436c89be58e 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -82,14 +82,16 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
82 82
83 /* 83 /*
84 * Every time unit enable is asserted, GPOD needs to be cleared 84 * Every time unit enable is asserted, GPOD needs to be cleared
85 * on IOP321 to avoid data corruption on the bus. 85 * on IOP3XX to avoid data corruption on the bus.
86 */ 86 */
87#ifdef CONFIG_ARCH_IOP321 87#ifdef CONFIG_PLAT_IOP
88#define IOP321_GPOD_I2C0 0x00c0 /* clear these bits to enable ch0 */ 88 if (iop3xx_adap->id == 0) {
89#define IOP321_GPOD_I2C1 0x0030 /* clear these bits to enable ch1 */ 89 gpio_line_set(IOP3XX_GPIO_LINE(7), GPIO_LOW);
90 90 gpio_line_set(IOP3XX_GPIO_LINE(6), GPIO_LOW);
91 *IOP321_GPOD &= (iop3xx_adap->id == 0) ? ~IOP321_GPOD_I2C0 : 91 } else {
92 ~IOP321_GPOD_I2C1; 92 gpio_line_set(IOP3XX_GPIO_LINE(5), GPIO_LOW);
93 gpio_line_set(IOP3XX_GPIO_LINE(4), GPIO_LOW);
94 }
93#endif 95#endif
94 /* NB SR bits not same position as CR IE bits :-( */ 96 /* NB SR bits not same position as CR IE bits :-( */
95 iop3xx_adap->SR_enabled = 97 iop3xx_adap->SR_enabled =
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 6b7638b84290..cb142a66098c 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -822,6 +822,7 @@ static int at91_mci_probe(struct platform_device *pdev)
822 mmc->f_min = 375000; 822 mmc->f_min = 375000;
823 mmc->f_max = 25000000; 823 mmc->f_max = 25000000;
824 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 824 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
825 mmc->caps = MMC_CAP_BYTEBLOCK;
825 826
826 host = mmc_priv(mmc); 827 host = mmc_priv(mmc);
827 host->mmc = mmc; 828 host->mmc = mmc;
@@ -850,7 +851,7 @@ static int at91_mci_probe(struct platform_device *pdev)
850 /* 851 /*
851 * Allocate the MCI interrupt 852 * Allocate the MCI interrupt
852 */ 853 */
853 ret = request_irq(AT91_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host); 854 ret = request_irq(AT91RM9200_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host);
854 if (ret) { 855 if (ret) {
855 printk(KERN_ERR "Failed to request MCI interrupt\n"); 856 printk(KERN_ERR "Failed to request MCI interrupt\n");
856 clk_disable(mci_clk); 857 clk_disable(mci_clk);
@@ -906,7 +907,7 @@ static int at91_mci_remove(struct platform_device *pdev)
906 907
907 mmc_remove_host(mmc); 908 mmc_remove_host(mmc);
908 at91_mci_disable(); 909 at91_mci_disable();
909 free_irq(AT91_ID_MCI, host); 910 free_irq(AT91RM9200_ID_MCI, host);
910 mmc_free_host(mmc); 911 mmc_free_host(mmc);
911 912
912 clk_disable(mci_clk); /* Disable the peripheral clock */ 913 clk_disable(mci_clk); /* Disable the peripheral clock */
diff --git a/drivers/mmc/imxmmc.c b/drivers/mmc/imxmmc.c
index fb6565b98f32..1b79dd271aae 100644
--- a/drivers/mmc/imxmmc.c
+++ b/drivers/mmc/imxmmc.c
@@ -956,7 +956,7 @@ static int imxmci_probe(struct platform_device *pdev)
956 mmc->f_min = 150000; 956 mmc->f_min = 150000;
957 mmc->f_max = CLK_RATE/2; 957 mmc->f_max = CLK_RATE/2;
958 mmc->ocr_avail = MMC_VDD_32_33; 958 mmc->ocr_avail = MMC_VDD_32_33;
959 mmc->caps |= MMC_CAP_4_BIT_DATA; 959 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_BYTEBLOCK;
960 960
961 /* MMC core transfer sizes tunable parameters */ 961 /* MMC core transfer sizes tunable parameters */
962 mmc->max_hw_segs = 64; 962 mmc->max_hw_segs = 64;
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 74eaaee66de0..5b9caa7978d3 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -996,7 +996,6 @@ static void mmc_read_scrs(struct mmc_host *host)
996 996
997 mmc_set_data_timeout(&data, card, 0); 997 mmc_set_data_timeout(&data, card, 0);
998 998
999 data.blksz_bits = 3;
1000 data.blksz = 1 << 3; 999 data.blksz = 1 << 3;
1001 data.blocks = 1; 1000 data.blocks = 1;
1002 data.flags = MMC_DATA_READ; 1001 data.flags = MMC_DATA_READ;
diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c
index a0e0dad1b419..db0e8ad439a5 100644
--- a/drivers/mmc/mmc_block.c
+++ b/drivers/mmc/mmc_block.c
@@ -32,6 +32,7 @@
32#include <linux/mmc/card.h> 32#include <linux/mmc/card.h>
33#include <linux/mmc/host.h> 33#include <linux/mmc/host.h>
34#include <linux/mmc/protocol.h> 34#include <linux/mmc/protocol.h>
35#include <linux/mmc/host.h>
35 36
36#include <asm/system.h> 37#include <asm/system.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
@@ -165,6 +166,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
165 do { 166 do {
166 struct mmc_blk_request brq; 167 struct mmc_blk_request brq;
167 struct mmc_command cmd; 168 struct mmc_command cmd;
169 u32 readcmd, writecmd;
168 170
169 memset(&brq, 0, sizeof(struct mmc_blk_request)); 171 memset(&brq, 0, sizeof(struct mmc_blk_request));
170 brq.mrq.cmd = &brq.cmd; 172 brq.mrq.cmd = &brq.cmd;
@@ -172,7 +174,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
172 174
173 brq.cmd.arg = req->sector << 9; 175 brq.cmd.arg = req->sector << 9;
174 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 176 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
175 brq.data.blksz_bits = md->block_bits;
176 brq.data.blksz = 1 << md->block_bits; 177 brq.data.blksz = 1 << md->block_bits;
177 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 178 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
178 brq.stop.opcode = MMC_STOP_TRANSMISSION; 179 brq.stop.opcode = MMC_STOP_TRANSMISSION;
@@ -181,20 +182,31 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
181 182
182 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ); 183 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
183 184
184 if (rq_data_dir(req) == READ) { 185 /*
185 brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; 186 * If the host doesn't support multiple block writes, force
186 brq.data.flags |= MMC_DATA_READ; 187 * block writes to single block.
187 } else { 188 */
188 brq.cmd.opcode = MMC_WRITE_BLOCK; 189 if (rq_data_dir(req) != READ &&
189 brq.data.flags |= MMC_DATA_WRITE; 190 !(card->host->caps & MMC_CAP_MULTIWRITE))
190 brq.data.blocks = 1; 191 brq.data.blocks = 1;
191 }
192 192
193 if (brq.data.blocks > 1) { 193 if (brq.data.blocks > 1) {
194 brq.data.flags |= MMC_DATA_MULTI; 194 brq.data.flags |= MMC_DATA_MULTI;
195 brq.mrq.stop = &brq.stop; 195 brq.mrq.stop = &brq.stop;
196 readcmd = MMC_READ_MULTIPLE_BLOCK;
197 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
196 } else { 198 } else {
197 brq.mrq.stop = NULL; 199 brq.mrq.stop = NULL;
200 readcmd = MMC_READ_SINGLE_BLOCK;
201 writecmd = MMC_WRITE_BLOCK;
202 }
203
204 if (rq_data_dir(req) == READ) {
205 brq.cmd.opcode = readcmd;
206 brq.data.flags |= MMC_DATA_READ;
207 } else {
208 brq.cmd.opcode = writecmd;
209 brq.data.flags |= MMC_DATA_WRITE;
198 } 210 }
199 211
200 brq.data.sg = mq->sg; 212 brq.data.sg = mq->sg;
@@ -219,27 +231,29 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
219 goto cmd_err; 231 goto cmd_err;
220 } 232 }
221 233
222 do { 234 if (rq_data_dir(req) != READ) {
223 int err; 235 do {
224 236 int err;
225 cmd.opcode = MMC_SEND_STATUS; 237
226 cmd.arg = card->rca << 16; 238 cmd.opcode = MMC_SEND_STATUS;
227 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 239 cmd.arg = card->rca << 16;
228 err = mmc_wait_for_cmd(card->host, &cmd, 5); 240 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
229 if (err) { 241 err = mmc_wait_for_cmd(card->host, &cmd, 5);
230 printk(KERN_ERR "%s: error %d requesting status\n", 242 if (err) {
231 req->rq_disk->disk_name, err); 243 printk(KERN_ERR "%s: error %d requesting status\n",
232 goto cmd_err; 244 req->rq_disk->disk_name, err);
233 } 245 goto cmd_err;
234 } while (!(cmd.resp[0] & R1_READY_FOR_DATA)); 246 }
247 } while (!(cmd.resp[0] & R1_READY_FOR_DATA));
235 248
236#if 0 249#if 0
237 if (cmd.resp[0] & ~0x00000900) 250 if (cmd.resp[0] & ~0x00000900)
238 printk(KERN_ERR "%s: status = %08x\n", 251 printk(KERN_ERR "%s: status = %08x\n",
239 req->rq_disk->disk_name, cmd.resp[0]); 252 req->rq_disk->disk_name, cmd.resp[0]);
240 if (mmc_decode_status(cmd.resp)) 253 if (mmc_decode_status(cmd.resp))
241 goto cmd_err; 254 goto cmd_err;
242#endif 255#endif
256 }
243 257
244 /* 258 /*
245 * A block was successfully transferred. 259 * A block was successfully transferred.
diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c
index 1886562abdd4..2b5a0cc9ea56 100644
--- a/drivers/mmc/mmci.c
+++ b/drivers/mmc/mmci.c
@@ -69,12 +69,13 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
69 unsigned int datactrl, timeout, irqmask; 69 unsigned int datactrl, timeout, irqmask;
70 unsigned long long clks; 70 unsigned long long clks;
71 void __iomem *base; 71 void __iomem *base;
72 int blksz_bits;
72 73
73 DBG(host, "blksz %04x blks %04x flags %08x\n", 74 DBG(host, "blksz %04x blks %04x flags %08x\n",
74 1 << data->blksz_bits, data->blocks, data->flags); 75 data->blksz, data->blocks, data->flags);
75 76
76 host->data = data; 77 host->data = data;
77 host->size = data->blocks << data->blksz_bits; 78 host->size = data->blksz;
78 host->data_xfered = 0; 79 host->data_xfered = 0;
79 80
80 mmci_init_sg(host, data); 81 mmci_init_sg(host, data);
@@ -88,7 +89,10 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
88 writel(timeout, base + MMCIDATATIMER); 89 writel(timeout, base + MMCIDATATIMER);
89 writel(host->size, base + MMCIDATALENGTH); 90 writel(host->size, base + MMCIDATALENGTH);
90 91
91 datactrl = MCI_DPSM_ENABLE | data->blksz_bits << 4; 92 blksz_bits = ffs(data->blksz) - 1;
93 BUG_ON(1 << blksz_bits != data->blksz);
94
95 datactrl = MCI_DPSM_ENABLE | blksz_bits << 4;
92 if (data->flags & MMC_DATA_READ) { 96 if (data->flags & MMC_DATA_READ) {
93 datactrl |= MCI_DPSM_DIRECTION; 97 datactrl |= MCI_DPSM_DIRECTION;
94 irqmask = MCI_RXFIFOHALFFULLMASK; 98 irqmask = MCI_RXFIFOHALFFULLMASK;
@@ -145,7 +149,7 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
145 unsigned int status) 149 unsigned int status)
146{ 150{
147 if (status & MCI_DATABLOCKEND) { 151 if (status & MCI_DATABLOCKEND) {
148 host->data_xfered += 1 << data->blksz_bits; 152 host->data_xfered += data->blksz;
149 } 153 }
150 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) { 154 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
151 if (status & MCI_DATACRCFAIL) 155 if (status & MCI_DATACRCFAIL)
@@ -505,6 +509,7 @@ static int mmci_probe(struct amba_device *dev, void *id)
505 mmc->f_min = (host->mclk + 511) / 512; 509 mmc->f_min = (host->mclk + 511) / 512;
506 mmc->f_max = min(host->mclk, fmax); 510 mmc->f_max = min(host->mclk, fmax);
507 mmc->ocr_avail = plat->ocr_mask; 511 mmc->ocr_avail = plat->ocr_mask;
512 mmc->caps = MMC_CAP_MULTIWRITE;
508 513
509 /* 514 /*
510 * We can do SGIO 515 * We can do SGIO
diff --git a/drivers/mmc/omap.c b/drivers/mmc/omap.c
index ddf06b32c159..52c9e52e6b78 100644
--- a/drivers/mmc/omap.c
+++ b/drivers/mmc/omap.c
@@ -1034,13 +1034,14 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
1034 host->irq = pdev->resource[1].start; 1034 host->irq = pdev->resource[1].start;
1035 host->base = (void __iomem*)IO_ADDRESS(r->start); 1035 host->base = (void __iomem*)IO_ADDRESS(r->start);
1036 1036
1037 if (minfo->wire4)
1038 mmc->caps |= MMC_CAP_4_BIT_DATA;
1039
1040 mmc->ops = &mmc_omap_ops; 1037 mmc->ops = &mmc_omap_ops;
1041 mmc->f_min = 400000; 1038 mmc->f_min = 400000;
1042 mmc->f_max = 24000000; 1039 mmc->f_max = 24000000;
1043 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34; 1040 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1041 mmc->caps = MMC_CAP_BYTEBLOCK;
1042
1043 if (minfo->wire4)
1044 mmc->caps |= MMC_CAP_4_BIT_DATA;
1044 1045
1045 /* Use scatterlist DMA to reduce per-transfer costs. 1046 /* Use scatterlist DMA to reduce per-transfer costs.
1046 * NOTE max_seg_size assumption that small blocks aren't 1047 * NOTE max_seg_size assumption that small blocks aren't
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 4e21b3b9d330..fdfc3838dd79 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -1262,7 +1262,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1262 mmc->ops = &sdhci_ops; 1262 mmc->ops = &sdhci_ops;
1263 mmc->f_min = host->max_clk / 256; 1263 mmc->f_min = host->max_clk / 256;
1264 mmc->f_max = host->max_clk; 1264 mmc->f_max = host->max_clk;
1265 mmc->caps = MMC_CAP_4_BIT_DATA; 1265 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
1266 1266
1267 mmc->ocr_avail = 0; 1267 mmc->ocr_avail = 0;
1268 if (caps & SDHCI_CAN_VDD_330) 1268 if (caps & SDHCI_CAN_VDD_330)
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index c351c6d1a18a..6435a6822ad3 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -1323,7 +1323,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
1323 mmc->f_min = 375000; 1323 mmc->f_min = 375000;
1324 mmc->f_max = 24000000; 1324 mmc->f_max = 24000000;
1325 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1325 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1326 mmc->caps = MMC_CAP_4_BIT_DATA; 1326 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK;
1327 1327
1328 spin_lock_init(&host->lock); 1328 spin_lock_init(&host->lock);
1329 1329
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 95b28aa01f4f..3ecf2cc53a7c 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -947,7 +947,7 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
947 return -ENOMEM; 947 return -ENOMEM;
948 948
949 dev->base_addr = AT91_VA_BASE_EMAC; 949 dev->base_addr = AT91_VA_BASE_EMAC;
950 dev->irq = AT91_ID_EMAC; 950 dev->irq = AT91RM9200_ID_EMAC;
951 SET_MODULE_OWNER(dev); 951 SET_MODULE_OWNER(dev);
952 952
953 /* Install the interrupt handler */ 953 /* Install the interrupt handler */
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 23fa0b289173..9d051e5687ea 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -63,44 +63,26 @@ static const u8 DASD_DIAG_CMS1[] = { 0xc3, 0xd4, 0xe2, 0xf1 };/* EBCDIC CMS1 */
63 * and function code cmd. 63 * and function code cmd.
64 * In case of an exception return 3. Otherwise return result of bitwise OR of 64 * In case of an exception return 3. Otherwise return result of bitwise OR of
65 * resulting condition code and DIAG return code. */ 65 * resulting condition code and DIAG return code. */
66static __inline__ int 66static inline int dia250(void *iob, int cmd)
67dia250(void *iob, int cmd)
68{ 67{
68 register unsigned long reg0 asm ("0") = (unsigned long) iob;
69 typedef union { 69 typedef union {
70 struct dasd_diag_init_io init_io; 70 struct dasd_diag_init_io init_io;
71 struct dasd_diag_rw_io rw_io; 71 struct dasd_diag_rw_io rw_io;
72 } addr_type; 72 } addr_type;
73 int rc; 73 int rc;
74 74
75 __asm__ __volatile__( 75 rc = 3;
76#ifdef CONFIG_64BIT 76 asm volatile(
77 " lghi %0,3\n"
78 " lgr 0,%3\n"
79 " diag 0,%2,0x250\n"
80 "0: ipm %0\n"
81 " srl %0,28\n"
82 " or %0,1\n"
83 "1:\n"
84 ".section __ex_table,\"a\"\n"
85 " .align 8\n"
86 " .quad 0b,1b\n"
87 ".previous\n"
88#else
89 " lhi %0,3\n"
90 " lr 0,%3\n"
91 " diag 0,%2,0x250\n" 77 " diag 0,%2,0x250\n"
92 "0: ipm %0\n" 78 "0: ipm %0\n"
93 " srl %0,28\n" 79 " srl %0,28\n"
94 " or %0,1\n" 80 " or %0,1\n"
95 "1:\n" 81 "1:\n"
96 ".section __ex_table,\"a\"\n" 82 EX_TABLE(0b,1b)
97 " .align 4\n" 83 : "+d" (rc), "=m" (*(addr_type *) iob)
98 " .long 0b,1b\n" 84 : "d" (cmd), "d" (reg0), "m" (*(addr_type *) iob)
99 ".previous\n" 85 : "1", "cc");
100#endif
101 : "=&d" (rc), "=m" (*(addr_type *) iob)
102 : "d" (cmd), "d" (iob), "m" (*(addr_type *) iob)
103 : "0", "1", "cc");
104 return rc; 86 return rc;
105} 87}
106 88
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index cab2c736683a..a04d9120cef0 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -89,28 +89,15 @@ MODULE_LICENSE("GPL");
89 */ 89 */
90static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index) 90static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
91{ 91{
92 int cc; 92 int cc = 2; /* return unused cc 2 if pgin traps */
93 93
94 __asm__ __volatile__ ( 94 asm volatile(
95 " lhi %0,2\n" /* return unused cc 2 if pgin traps */ 95 " .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */
96 " .insn rre,0xb22e0000,%1,%2\n" /* pgin %1,%2 */ 96 "0: ipm %0\n"
97 "0: ipm %0\n" 97 " srl %0,28\n"
98 " srl %0,28\n"
99 "1:\n" 98 "1:\n"
100#ifndef CONFIG_64BIT 99 EX_TABLE(0b,1b)
101 ".section __ex_table,\"a\"\n" 100 : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
102 " .align 4\n"
103 " .long 0b,1b\n"
104 ".previous"
105#else
106 ".section __ex_table,\"a\"\n"
107 " .align 8\n"
108 " .quad 0b,1b\n"
109 ".previous"
110#endif
111 : "=&d" (cc)
112 : "a" (__pa(page_addr)), "a" (xpage_index)
113 : "cc" );
114 if (cc == 3) 101 if (cc == 3)
115 return -ENXIO; 102 return -ENXIO;
116 if (cc == 2) { 103 if (cc == 2) {
@@ -137,28 +124,15 @@ static int xpram_page_in (unsigned long page_addr, unsigned int xpage_index)
137 */ 124 */
138static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index) 125static long xpram_page_out (unsigned long page_addr, unsigned int xpage_index)
139{ 126{
140 int cc; 127 int cc = 2; /* return unused cc 2 if pgin traps */
141 128
142 __asm__ __volatile__ ( 129 asm volatile(
143 " lhi %0,2\n" /* return unused cc 2 if pgout traps */ 130 " .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */
144 " .insn rre,0xb22f0000,%1,%2\n" /* pgout %1,%2 */ 131 "0: ipm %0\n"
145 "0: ipm %0\n" 132 " srl %0,28\n"
146 " srl %0,28\n"
147 "1:\n" 133 "1:\n"
148#ifndef CONFIG_64BIT 134 EX_TABLE(0b,1b)
149 ".section __ex_table,\"a\"\n" 135 : "+d" (cc) : "a" (__pa(page_addr)), "d" (xpage_index) : "cc");
150 " .align 4\n"
151 " .long 0b,1b\n"
152 ".previous"
153#else
154 ".section __ex_table,\"a\"\n"
155 " .align 8\n"
156 " .quad 0b,1b\n"
157 ".previous"
158#endif
159 : "=&d" (cc)
160 : "a" (__pa(page_addr)), "a" (xpage_index)
161 : "cc" );
162 if (cc == 3) 136 if (cc == 3)
163 return -ENXIO; 137 return -ENXIO;
164 if (cc == 2) { 138 if (cc == 2) {
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index ef004d089712..b4557fa30858 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -17,7 +17,6 @@
17 17
18#include <asm/ccwdev.h> 18#include <asm/ccwdev.h>
19#include <asm/cio.h> 19#include <asm/cio.h>
20#include <asm/cpcmd.h>
21#include <asm/ebcdic.h> 20#include <asm/ebcdic.h>
22#include <asm/idals.h> 21#include <asm/idals.h>
23 22
diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
index 985d1613baaa..31e335751d6d 100644
--- a/drivers/s390/char/sclp.c
+++ b/drivers/s390/char/sclp.c
@@ -100,13 +100,12 @@ service_call(sclp_cmdw_t command, void *sccb)
100{ 100{
101 int cc; 101 int cc;
102 102
103 __asm__ __volatile__( 103 asm volatile(
104 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ 104 " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */
105 " ipm %0\n" 105 " ipm %0\n"
106 " srl %0,28" 106 " srl %0,28"
107 : "=&d" (cc) 107 : "=&d" (cc) : "d" (command), "a" (__pa(sccb))
108 : "d" (command), "a" (__pa(sccb)) 108 : "cc", "memory");
109 : "cc", "memory" );
110 if (cc == 3) 109 if (cc == 3)
111 return -EIO; 110 return -EIO;
112 if (cc == 2) 111 if (cc == 2)
@@ -360,16 +359,6 @@ sclp_interrupt_handler(struct pt_regs *regs, __u16 code)
360 sclp_process_queue(); 359 sclp_process_queue();
361} 360}
362 361
363/* Return current Time-Of-Day clock. */
364static inline u64
365sclp_get_clock(void)
366{
367 u64 result;
368
369 asm volatile ("STCK 0(%1)" : "=m" (result) : "a" (&(result)) : "cc");
370 return result;
371}
372
373/* Convert interval in jiffies to TOD ticks. */ 362/* Convert interval in jiffies to TOD ticks. */
374static inline u64 363static inline u64
375sclp_tod_from_jiffies(unsigned long jiffies) 364sclp_tod_from_jiffies(unsigned long jiffies)
@@ -382,7 +371,6 @@ sclp_tod_from_jiffies(unsigned long jiffies)
382void 371void
383sclp_sync_wait(void) 372sclp_sync_wait(void)
384{ 373{
385 unsigned long psw_mask;
386 unsigned long flags; 374 unsigned long flags;
387 unsigned long cr0, cr0_sync; 375 unsigned long cr0, cr0_sync;
388 u64 timeout; 376 u64 timeout;
@@ -392,7 +380,7 @@ sclp_sync_wait(void)
392 timeout = 0; 380 timeout = 0;
393 if (timer_pending(&sclp_request_timer)) { 381 if (timer_pending(&sclp_request_timer)) {
394 /* Get timeout TOD value */ 382 /* Get timeout TOD value */
395 timeout = sclp_get_clock() + 383 timeout = get_clock() +
396 sclp_tod_from_jiffies(sclp_request_timer.expires - 384 sclp_tod_from_jiffies(sclp_request_timer.expires -
397 jiffies); 385 jiffies);
398 } 386 }
@@ -406,13 +394,12 @@ sclp_sync_wait(void)
406 cr0_sync |= 0x00000200; 394 cr0_sync |= 0x00000200;
407 cr0_sync &= 0xFFFFF3AC; 395 cr0_sync &= 0xFFFFF3AC;
408 __ctl_load(cr0_sync, 0, 0); 396 __ctl_load(cr0_sync, 0, 0);
409 asm volatile ("STOSM 0(%1),0x01" 397 __raw_local_irq_stosm(0x01);
410 : "=m" (psw_mask) : "a" (&psw_mask) : "memory");
411 /* Loop until driver state indicates finished request */ 398 /* Loop until driver state indicates finished request */
412 while (sclp_running_state != sclp_running_state_idle) { 399 while (sclp_running_state != sclp_running_state_idle) {
413 /* Check for expired request timer */ 400 /* Check for expired request timer */
414 if (timer_pending(&sclp_request_timer) && 401 if (timer_pending(&sclp_request_timer) &&
415 sclp_get_clock() > timeout && 402 get_clock() > timeout &&
416 del_timer(&sclp_request_timer)) 403 del_timer(&sclp_request_timer))
417 sclp_request_timer.function(sclp_request_timer.data); 404 sclp_request_timer.function(sclp_request_timer.data);
418 barrier(); 405 barrier();
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 29718042c6c9..06e2eeec8473 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -698,7 +698,6 @@ tty3270_alloc_view(void)
698 if (!tp->freemem_pages) 698 if (!tp->freemem_pages)
699 goto out_tp; 699 goto out_tp;
700 INIT_LIST_HEAD(&tp->freemem); 700 INIT_LIST_HEAD(&tp->freemem);
701 init_timer(&tp->timer);
702 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) { 701 for (pages = 0; pages < TTY3270_STRING_PAGES; pages++) {
703 tp->freemem_pages[pages] = (void *) 702 tp->freemem_pages[pages] = (void *)
704 __get_free_pages(GFP_KERNEL|GFP_DMA, 0); 703 __get_free_pages(GFP_KERNEL|GFP_DMA, 0);
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index 807320a41fa4..4b868f72fe89 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -54,48 +54,20 @@ enum vmwdt_func {
54static int __diag288(enum vmwdt_func func, unsigned int timeout, 54static int __diag288(enum vmwdt_func func, unsigned int timeout,
55 char *cmd, size_t len) 55 char *cmd, size_t len)
56{ 56{
57 register unsigned long __func asm("2"); 57 register unsigned long __func asm("2") = func;
58 register unsigned long __timeout asm("3"); 58 register unsigned long __timeout asm("3") = timeout;
59 register unsigned long __cmdp asm("4"); 59 register unsigned long __cmdp asm("4") = virt_to_phys(cmd);
60 register unsigned long __cmdl asm("5"); 60 register unsigned long __cmdl asm("5") = len;
61 int err; 61 int err;
62 62
63 __func = func; 63 err = -EINVAL;
64 __timeout = timeout; 64 asm volatile(
65 __cmdp = virt_to_phys(cmd); 65 " diag %1,%3,0x288\n"
66 __cmdl = len; 66 "0: la %0,0\n"
67 err = 0; 67 "1:\n"
68 asm volatile ( 68 EX_TABLE(0b,1b)
69#ifdef CONFIG_64BIT 69 : "=d" (err) : "d"(__func), "d"(__timeout),
70 "diag %2,%4,0x288\n" 70 "d"(__cmdp), "d"(__cmdl), "0" (-EINVAL) : "1", "cc");
71 "1: \n"
72 ".section .fixup,\"ax\"\n"
73 "2: lghi %0,%1\n"
74 " jg 1b\n"
75 ".previous\n"
76 ".section __ex_table,\"a\"\n"
77 " .align 8\n"
78 " .quad 1b,2b\n"
79 ".previous\n"
80#else
81 "diag %2,%4,0x288\n"
82 "1: \n"
83 ".section .fixup,\"ax\"\n"
84 "2: lhi %0,%1\n"
85 " bras 1,3f\n"
86 " .long 1b\n"
87 "3: l 1,0(1)\n"
88 " br 1\n"
89 ".previous\n"
90 ".section __ex_table,\"a\"\n"
91 " .align 4\n"
92 " .long 1b,2b\n"
93 ".previous\n"
94#endif
95 : "+&d"(err)
96 : "i"(-EINVAL), "d"(__func), "d"(__timeout),
97 "d"(__cmdp), "d"(__cmdl)
98 : "1", "cc");
99 return err; 71 return err;
100} 72}
101 73
diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index 438db483035d..1398367b5f68 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -42,18 +42,15 @@ diag210(struct diag210 * addr)
42 spin_lock_irqsave(&diag210_lock, flags); 42 spin_lock_irqsave(&diag210_lock, flags);
43 diag210_tmp = *addr; 43 diag210_tmp = *addr;
44 44
45 asm volatile ( 45 asm volatile(
46 " lhi %0,-1\n" 46 " lhi %0,-1\n"
47 " sam31\n" 47 " sam31\n"
48 " diag %1,0,0x210\n" 48 " diag %1,0,0x210\n"
49 "0: ipm %0\n" 49 "0: ipm %0\n"
50 " srl %0,28\n" 50 " srl %0,28\n"
51 "1: sam64\n" 51 "1: sam64\n"
52 ".section __ex_table,\"a\"\n" 52 EX_TABLE(0b,1b)
53 " .align 8\n" 53 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory");
54 " .quad 0b,1b\n"
55 ".previous"
56 : "=&d" (ccode) : "a" (__pa(&diag210_tmp)) : "cc", "memory" );
57 54
58 *addr = diag210_tmp; 55 *addr = diag210_tmp;
59 spin_unlock_irqrestore(&diag210_lock, flags); 56 spin_unlock_irqrestore(&diag210_lock, flags);
@@ -66,17 +63,14 @@ diag210(struct diag210 * addr)
66{ 63{
67 int ccode; 64 int ccode;
68 65
69 asm volatile ( 66 asm volatile(
70 " lhi %0,-1\n" 67 " lhi %0,-1\n"
71 " diag %1,0,0x210\n" 68 " diag %1,0,0x210\n"
72 "0: ipm %0\n" 69 "0: ipm %0\n"
73 " srl %0,28\n" 70 " srl %0,28\n"
74 "1:\n" 71 "1:\n"
75 ".section __ex_table,\"a\"\n" 72 EX_TABLE(0b,1b)
76 " .align 4\n" 73 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory");
77 " .long 0b,1b\n"
78 ".previous"
79 : "=&d" (ccode) : "a" (__pa(addr)) : "cc", "memory" );
80 74
81 return ccode; 75 return ccode;
82} 76}
diff --git a/drivers/s390/cio/ioasm.h b/drivers/s390/cio/ioasm.h
index 95a9462f9a91..ad6d82940069 100644
--- a/drivers/s390/cio/ioasm.h
+++ b/drivers/s390/cio/ioasm.h
@@ -25,106 +25,74 @@ struct tpi_info {
25static inline int stsch(struct subchannel_id schid, 25static inline int stsch(struct subchannel_id schid,
26 volatile struct schib *addr) 26 volatile struct schib *addr)
27{ 27{
28 register struct subchannel_id reg1 asm ("1") = schid;
28 int ccode; 29 int ccode;
29 30
30 __asm__ __volatile__( 31 asm volatile(
31 " lr 1,%1\n" 32 " stsch 0(%2)\n"
32 " stsch 0(%2)\n" 33 " ipm %0\n"
33 " ipm %0\n" 34 " srl %0,28"
34 " srl %0,28" 35 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
35 : "=d" (ccode)
36 : "d" (schid), "a" (addr), "m" (*addr)
37 : "cc", "1" );
38 return ccode; 36 return ccode;
39} 37}
40 38
41static inline int stsch_err(struct subchannel_id schid, 39static inline int stsch_err(struct subchannel_id schid,
42 volatile struct schib *addr) 40 volatile struct schib *addr)
43{ 41{
44 int ccode; 42 register struct subchannel_id reg1 asm ("1") = schid;
43 int ccode = -EIO;
45 44
46 __asm__ __volatile__( 45 asm volatile(
47 " lhi %0,%3\n" 46 " stsch 0(%2)\n"
48 " lr 1,%1\n" 47 "0: ipm %0\n"
49 " stsch 0(%2)\n" 48 " srl %0,28\n"
50 "0: ipm %0\n"
51 " srl %0,28\n"
52 "1:\n" 49 "1:\n"
53#ifdef CONFIG_64BIT 50 EX_TABLE(0b,1b)
54 ".section __ex_table,\"a\"\n" 51 : "+d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
55 " .align 8\n"
56 " .quad 0b,1b\n"
57 ".previous"
58#else
59 ".section __ex_table,\"a\"\n"
60 " .align 4\n"
61 " .long 0b,1b\n"
62 ".previous"
63#endif
64 : "=&d" (ccode)
65 : "d" (schid), "a" (addr), "K" (-EIO), "m" (*addr)
66 : "cc", "1" );
67 return ccode; 52 return ccode;
68} 53}
69 54
70static inline int msch(struct subchannel_id schid, 55static inline int msch(struct subchannel_id schid,
71 volatile struct schib *addr) 56 volatile struct schib *addr)
72{ 57{
58 register struct subchannel_id reg1 asm ("1") = schid;
73 int ccode; 59 int ccode;
74 60
75 __asm__ __volatile__( 61 asm volatile(
76 " lr 1,%1\n" 62 " msch 0(%2)\n"
77 " msch 0(%2)\n" 63 " ipm %0\n"
78 " ipm %0\n" 64 " srl %0,28"
79 " srl %0,28" 65 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
80 : "=d" (ccode)
81 : "d" (schid), "a" (addr), "m" (*addr)
82 : "cc", "1" );
83 return ccode; 66 return ccode;
84} 67}
85 68
86static inline int msch_err(struct subchannel_id schid, 69static inline int msch_err(struct subchannel_id schid,
87 volatile struct schib *addr) 70 volatile struct schib *addr)
88{ 71{
89 int ccode; 72 register struct subchannel_id reg1 asm ("1") = schid;
73 int ccode = -EIO;
90 74
91 __asm__ __volatile__( 75 asm volatile(
92 " lhi %0,%3\n" 76 " msch 0(%2)\n"
93 " lr 1,%1\n" 77 "0: ipm %0\n"
94 " msch 0(%2)\n" 78 " srl %0,28\n"
95 "0: ipm %0\n"
96 " srl %0,28\n"
97 "1:\n" 79 "1:\n"
98#ifdef CONFIG_64BIT 80 EX_TABLE(0b,1b)
99 ".section __ex_table,\"a\"\n" 81 : "+d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
100 " .align 8\n"
101 " .quad 0b,1b\n"
102 ".previous"
103#else
104 ".section __ex_table,\"a\"\n"
105 " .align 4\n"
106 " .long 0b,1b\n"
107 ".previous"
108#endif
109 : "=&d" (ccode)
110 : "d" (schid), "a" (addr), "K" (-EIO), "m" (*addr)
111 : "cc", "1" );
112 return ccode; 82 return ccode;
113} 83}
114 84
115static inline int tsch(struct subchannel_id schid, 85static inline int tsch(struct subchannel_id schid,
116 volatile struct irb *addr) 86 volatile struct irb *addr)
117{ 87{
88 register struct subchannel_id reg1 asm ("1") = schid;
118 int ccode; 89 int ccode;
119 90
120 __asm__ __volatile__( 91 asm volatile(
121 " lr 1,%1\n" 92 " tsch 0(%2)\n"
122 " tsch 0(%2)\n" 93 " ipm %0\n"
123 " ipm %0\n" 94 " srl %0,28"
124 " srl %0,28" 95 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
125 : "=d" (ccode)
126 : "d" (schid), "a" (addr), "m" (*addr)
127 : "cc", "1" );
128 return ccode; 96 return ccode;
129} 97}
130 98
@@ -132,89 +100,77 @@ static inline int tpi( volatile struct tpi_info *addr)
132{ 100{
133 int ccode; 101 int ccode;
134 102
135 __asm__ __volatile__( 103 asm volatile(
136 " tpi 0(%1)\n" 104 " tpi 0(%1)\n"
137 " ipm %0\n" 105 " ipm %0\n"
138 " srl %0,28" 106 " srl %0,28"
139 : "=d" (ccode) 107 : "=d" (ccode) : "a" (addr), "m" (*addr) : "cc");
140 : "a" (addr), "m" (*addr)
141 : "cc", "1" );
142 return ccode; 108 return ccode;
143} 109}
144 110
145static inline int ssch(struct subchannel_id schid, 111static inline int ssch(struct subchannel_id schid,
146 volatile struct orb *addr) 112 volatile struct orb *addr)
147{ 113{
114 register struct subchannel_id reg1 asm ("1") = schid;
148 int ccode; 115 int ccode;
149 116
150 __asm__ __volatile__( 117 asm volatile(
151 " lr 1,%1\n" 118 " ssch 0(%2)\n"
152 " ssch 0(%2)\n" 119 " ipm %0\n"
153 " ipm %0\n" 120 " srl %0,28"
154 " srl %0,28" 121 : "=d" (ccode) : "d" (reg1), "a" (addr), "m" (*addr) : "cc");
155 : "=d" (ccode)
156 : "d" (schid), "a" (addr), "m" (*addr)
157 : "cc", "1" );
158 return ccode; 122 return ccode;
159} 123}
160 124
161static inline int rsch(struct subchannel_id schid) 125static inline int rsch(struct subchannel_id schid)
162{ 126{
127 register struct subchannel_id reg1 asm ("1") = schid;
163 int ccode; 128 int ccode;
164 129
165 __asm__ __volatile__( 130 asm volatile(
166 " lr 1,%1\n" 131 " rsch\n"
167 " rsch\n" 132 " ipm %0\n"
168 " ipm %0\n" 133 " srl %0,28"
169 " srl %0,28" 134 : "=d" (ccode) : "d" (reg1) : "cc");
170 : "=d" (ccode)
171 : "d" (schid)
172 : "cc", "1" );
173 return ccode; 135 return ccode;
174} 136}
175 137
176static inline int csch(struct subchannel_id schid) 138static inline int csch(struct subchannel_id schid)
177{ 139{
140 register struct subchannel_id reg1 asm ("1") = schid;
178 int ccode; 141 int ccode;
179 142
180 __asm__ __volatile__( 143 asm volatile(
181 " lr 1,%1\n" 144 " csch\n"
182 " csch\n" 145 " ipm %0\n"
183 " ipm %0\n" 146 " srl %0,28"
184 " srl %0,28" 147 : "=d" (ccode) : "d" (reg1) : "cc");
185 : "=d" (ccode)
186 : "d" (schid)
187 : "cc", "1" );
188 return ccode; 148 return ccode;
189} 149}
190 150
191static inline int hsch(struct subchannel_id schid) 151static inline int hsch(struct subchannel_id schid)
192{ 152{
153 register struct subchannel_id reg1 asm ("1") = schid;
193 int ccode; 154 int ccode;
194 155
195 __asm__ __volatile__( 156 asm volatile(
196 " lr 1,%1\n" 157 " hsch\n"
197 " hsch\n" 158 " ipm %0\n"
198 " ipm %0\n" 159 " srl %0,28"
199 " srl %0,28" 160 : "=d" (ccode) : "d" (reg1) : "cc");
200 : "=d" (ccode)
201 : "d" (schid)
202 : "cc", "1" );
203 return ccode; 161 return ccode;
204} 162}
205 163
206static inline int xsch(struct subchannel_id schid) 164static inline int xsch(struct subchannel_id schid)
207{ 165{
166 register struct subchannel_id reg1 asm ("1") = schid;
208 int ccode; 167 int ccode;
209 168
210 __asm__ __volatile__( 169 asm volatile(
211 " lr 1,%1\n" 170 " .insn rre,0xb2760000,%1,0\n"
212 " .insn rre,0xb2760000,%1,0\n" 171 " ipm %0\n"
213 " ipm %0\n" 172 " srl %0,28"
214 " srl %0,28" 173 : "=d" (ccode) : "d" (reg1) : "cc");
215 : "=d" (ccode)
216 : "d" (schid)
217 : "cc", "1" );
218 return ccode; 174 return ccode;
219} 175}
220 176
@@ -223,41 +179,27 @@ static inline int chsc(void *chsc_area)
223 typedef struct { char _[4096]; } addr_type; 179 typedef struct { char _[4096]; } addr_type;
224 int cc; 180 int cc;
225 181
226 __asm__ __volatile__ ( 182 asm volatile(
227 ".insn rre,0xb25f0000,%2,0 \n\t" 183 " .insn rre,0xb25f0000,%2,0\n"
228 "ipm %0 \n\t" 184 " ipm %0\n"
229 "srl %0,28 \n\t" 185 " srl %0,28\n"
230 : "=d" (cc), "=m" (*(addr_type *) chsc_area) 186 : "=d" (cc), "=m" (*(addr_type *) chsc_area)
231 : "d" (chsc_area), "m" (*(addr_type *) chsc_area) 187 : "d" (chsc_area), "m" (*(addr_type *) chsc_area)
232 : "cc" ); 188 : "cc");
233
234 return cc; 189 return cc;
235} 190}
236 191
237static inline int iac( void)
238{
239 int ccode;
240
241 __asm__ __volatile__(
242 " iac 1\n"
243 " ipm %0\n"
244 " srl %0,28"
245 : "=d" (ccode) : : "cc", "1" );
246 return ccode;
247}
248
249static inline int rchp(int chpid) 192static inline int rchp(int chpid)
250{ 193{
194 register unsigned int reg1 asm ("1") = chpid;
251 int ccode; 195 int ccode;
252 196
253 __asm__ __volatile__( 197 asm volatile(
254 " lr 1,%1\n" 198 " lr 1,%1\n"
255 " rchp\n" 199 " rchp\n"
256 " ipm %0\n" 200 " ipm %0\n"
257 " srl %0,28" 201 " srl %0,28"
258 : "=d" (ccode) 202 : "=d" (ccode) : "d" (reg1) : "cc");
259 : "d" (chpid)
260 : "cc", "1" );
261 return ccode; 203 return ccode;
262} 204}
263 205
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 124569362f02..49bb9e371c32 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -274,12 +274,11 @@ do_sqbs(unsigned long sch, unsigned char state, int queue,
274 register unsigned long _sch asm ("1") = sch; 274 register unsigned long _sch asm ("1") = sch;
275 unsigned long _queuestart = ((unsigned long)queue << 32) | *start; 275 unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
276 276
277 asm volatile ( 277 asm volatile(
278 " .insn rsy,0xeb000000008A,%1,0,0(%2)\n\t" 278 " .insn rsy,0xeb000000008A,%1,0,0(%2)"
279 : "+d" (_ccq), "+d" (_queuestart) 279 : "+d" (_ccq), "+d" (_queuestart)
280 : "d" ((unsigned long)state), "d" (_sch) 280 : "d" ((unsigned long)state), "d" (_sch)
281 : "memory", "cc" 281 : "memory", "cc");
282 );
283 *count = _ccq & 0xff; 282 *count = _ccq & 0xff;
284 *start = _queuestart & 0xff; 283 *start = _queuestart & 0xff;
285 284
@@ -299,12 +298,11 @@ do_eqbs(unsigned long sch, unsigned char *state, int queue,
299 unsigned long _queuestart = ((unsigned long)queue << 32) | *start; 298 unsigned long _queuestart = ((unsigned long)queue << 32) | *start;
300 unsigned long _state = 0; 299 unsigned long _state = 0;
301 300
302 asm volatile ( 301 asm volatile(
303 " .insn rrf,0xB99c0000,%1,%2,0,0 \n\t" 302 " .insn rrf,0xB99c0000,%1,%2,0,0"
304 : "+d" (_ccq), "+d" (_queuestart), "+d" (_state) 303 : "+d" (_ccq), "+d" (_queuestart), "+d" (_state)
305 : "d" (_sch) 304 : "d" (_sch)
306 : "memory", "cc" 305 : "memory", "cc" );
307 );
308 *count = _ccq & 0xff; 306 *count = _ccq & 0xff;
309 *start = _queuestart & 0xff; 307 *start = _queuestart & 0xff;
310 *state = _state & 0xff; 308 *state = _state & 0xff;
@@ -319,69 +317,35 @@ do_eqbs(unsigned long sch, unsigned char *state, int queue,
319static inline int 317static inline int
320do_siga_sync(struct subchannel_id schid, unsigned int mask1, unsigned int mask2) 318do_siga_sync(struct subchannel_id schid, unsigned int mask1, unsigned int mask2)
321{ 319{
320 register unsigned long reg0 asm ("0") = 2;
321 register struct subchannel_id reg1 asm ("1") = schid;
322 register unsigned long reg2 asm ("2") = mask1;
323 register unsigned long reg3 asm ("3") = mask2;
322 int cc; 324 int cc;
323 325
324#ifndef CONFIG_64BIT 326 asm volatile(
325 asm volatile ( 327 " siga 0\n"
326 "lhi 0,2 \n\t" 328 " ipm %0\n"
327 "lr 1,%1 \n\t" 329 " srl %0,28\n"
328 "lr 2,%2 \n\t"
329 "lr 3,%3 \n\t"
330 "siga 0 \n\t"
331 "ipm %0 \n\t"
332 "srl %0,28 \n\t"
333 : "=d" (cc) 330 : "=d" (cc)
334 : "d" (schid), "d" (mask1), "d" (mask2) 331 : "d" (reg0), "d" (reg1), "d" (reg2), "d" (reg3) : "cc");
335 : "cc", "0", "1", "2", "3"
336 );
337#else /* CONFIG_64BIT */
338 asm volatile (
339 "lghi 0,2 \n\t"
340 "llgfr 1,%1 \n\t"
341 "llgfr 2,%2 \n\t"
342 "llgfr 3,%3 \n\t"
343 "siga 0 \n\t"
344 "ipm %0 \n\t"
345 "srl %0,28 \n\t"
346 : "=d" (cc)
347 : "d" (schid), "d" (mask1), "d" (mask2)
348 : "cc", "0", "1", "2", "3"
349 );
350#endif /* CONFIG_64BIT */
351 return cc; 332 return cc;
352} 333}
353 334
354static inline int 335static inline int
355do_siga_input(struct subchannel_id schid, unsigned int mask) 336do_siga_input(struct subchannel_id schid, unsigned int mask)
356{ 337{
338 register unsigned long reg0 asm ("0") = 1;
339 register struct subchannel_id reg1 asm ("1") = schid;
340 register unsigned long reg2 asm ("2") = mask;
357 int cc; 341 int cc;
358 342
359#ifndef CONFIG_64BIT 343 asm volatile(
360 asm volatile ( 344 " siga 0\n"
361 "lhi 0,1 \n\t" 345 " ipm %0\n"
362 "lr 1,%1 \n\t" 346 " srl %0,28\n"
363 "lr 2,%2 \n\t"
364 "siga 0 \n\t"
365 "ipm %0 \n\t"
366 "srl %0,28 \n\t"
367 : "=d" (cc)
368 : "d" (schid), "d" (mask)
369 : "cc", "0", "1", "2", "memory"
370 );
371#else /* CONFIG_64BIT */
372 asm volatile (
373 "lghi 0,1 \n\t"
374 "llgfr 1,%1 \n\t"
375 "llgfr 2,%2 \n\t"
376 "siga 0 \n\t"
377 "ipm %0 \n\t"
378 "srl %0,28 \n\t"
379 : "=d" (cc) 347 : "=d" (cc)
380 : "d" (schid), "d" (mask) 348 : "d" (reg0), "d" (reg1), "d" (reg2) : "cc", "memory");
381 : "cc", "0", "1", "2", "memory"
382 );
383#endif /* CONFIG_64BIT */
384
385 return cc; 349 return cc;
386} 350}
387 351
@@ -389,93 +353,35 @@ static inline int
389do_siga_output(unsigned long schid, unsigned long mask, __u32 *bb, 353do_siga_output(unsigned long schid, unsigned long mask, __u32 *bb,
390 unsigned int fc) 354 unsigned int fc)
391{ 355{
356 register unsigned long __fc asm("0") = fc;
357 register unsigned long __schid asm("1") = schid;
358 register unsigned long __mask asm("2") = mask;
392 int cc; 359 int cc;
393 __u32 busy_bit; 360
394 361 asm volatile(
395#ifndef CONFIG_64BIT 362 " siga 0\n"
396 asm volatile ( 363 "0: ipm %0\n"
397 "lhi 0,0 \n\t" 364 " srl %0,28\n"
398 "lr 1,%2 \n\t" 365 "1:\n"
399 "lr 2,%3 \n\t" 366 EX_TABLE(0b,1b)
400 "siga 0 \n\t" 367 : "=d" (cc), "+d" (__fc), "+d" (__schid), "+d" (__mask)
401 "0:" 368 : "0" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION)
402 "ipm %0 \n\t" 369 : "cc", "memory");
403 "srl %0,28 \n\t" 370 (*bb) = ((unsigned int) __fc) >> 31;
404 "srl 0,31 \n\t"
405 "lr %1,0 \n\t"
406 "1: \n\t"
407 ".section .fixup,\"ax\"\n\t"
408 "2: \n\t"
409 "lhi %0,%4 \n\t"
410 "bras 1,3f \n\t"
411 ".long 1b \n\t"
412 "3: \n\t"
413 "l 1,0(1) \n\t"
414 "br 1 \n\t"
415 ".previous \n\t"
416 ".section __ex_table,\"a\"\n\t"
417 ".align 4 \n\t"
418 ".long 0b,2b \n\t"
419 ".previous \n\t"
420 : "=d" (cc), "=d" (busy_bit)
421 : "d" (schid), "d" (mask),
422 "i" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION)
423 : "cc", "0", "1", "2", "memory"
424 );
425#else /* CONFIG_64BIT */
426 asm volatile (
427 "llgfr 0,%5 \n\t"
428 "lgr 1,%2 \n\t"
429 "llgfr 2,%3 \n\t"
430 "siga 0 \n\t"
431 "0:"
432 "ipm %0 \n\t"
433 "srl %0,28 \n\t"
434 "srl 0,31 \n\t"
435 "llgfr %1,0 \n\t"
436 "1: \n\t"
437 ".section .fixup,\"ax\"\n\t"
438 "lghi %0,%4 \n\t"
439 "jg 1b \n\t"
440 ".previous\n\t"
441 ".section __ex_table,\"a\"\n\t"
442 ".align 8 \n\t"
443 ".quad 0b,1b \n\t"
444 ".previous \n\t"
445 : "=d" (cc), "=d" (busy_bit)
446 : "d" (schid), "d" (mask),
447 "i" (QDIO_SIGA_ERROR_ACCESS_EXCEPTION), "d" (fc)
448 : "cc", "0", "1", "2", "memory"
449 );
450#endif /* CONFIG_64BIT */
451
452 (*bb) = busy_bit;
453 return cc; 371 return cc;
454} 372}
455 373
456static inline unsigned long 374static inline unsigned long
457do_clear_global_summary(void) 375do_clear_global_summary(void)
458{ 376{
459 377 register unsigned long __fn asm("1") = 3;
460 unsigned long time; 378 register unsigned long __tmp asm("2");
461 379 register unsigned long __time asm("3");
462#ifndef CONFIG_64BIT 380
463 asm volatile ( 381 asm volatile(
464 "lhi 1,3 \n\t" 382 " .insn rre,0xb2650000,2,0"
465 ".insn rre,0xb2650000,2,0 \n\t" 383 : "+d" (__fn), "=d" (__tmp), "=d" (__time));
466 "lr %0,3 \n\t" 384 return __time;
467 : "=d" (time) : : "cc", "1", "2", "3"
468 );
469#else /* CONFIG_64BIT */
470 asm volatile (
471 "lghi 1,3 \n\t"
472 ".insn rre,0xb2650000,2,0 \n\t"
473 "lgr %0,3 \n\t"
474 : "=d" (time) : : "cc", "1", "2", "3"
475 );
476#endif /* CONFIG_64BIT */
477
478 return time;
479} 385}
480 386
481/* 387/*
diff --git a/drivers/s390/net/iucv.c b/drivers/s390/net/iucv.c
index 821dde86e240..809dd8d7f47a 100644
--- a/drivers/s390/net/iucv.c
+++ b/drivers/s390/net/iucv.c
@@ -534,19 +534,15 @@ iucv_add_handler (handler *new)
534 * 534 *
535 * Returns: return code from CP's IUCV call 535 * Returns: return code from CP's IUCV call
536 */ 536 */
537static __inline__ ulong 537static inline ulong b2f0(__u32 code, void *parm)
538b2f0(__u32 code, void *parm)
539{ 538{
539 register unsigned long reg0 asm ("0");
540 register unsigned long reg1 asm ("1");
540 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param)); 541 iucv_dumpit("iparml before b2f0 call:", parm, sizeof(iucv_param));
541 542
542 asm volatile ( 543 reg0 = code;
543 "LRA 1,0(%1)\n\t" 544 reg1 = virt_to_phys(parm);
544 "LR 0,%0\n\t" 545 asm volatile(".long 0xb2f01000" : : "d" (reg0), "a" (reg1));
545 ".long 0xb2f01000"
546 :
547 : "d" (code), "a" (parm)
548 : "0", "1"
549 );
550 546
551 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param)); 547 iucv_dumpit("iparml after b2f0 call:", parm, sizeof(iucv_param));
552 548
@@ -1248,6 +1244,8 @@ iucv_purge (__u16 pathid, __u32 msgid, __u32 srccls, __u32 *audit)
1248static int 1244static int
1249iucv_query_generic(int want_maxconn) 1245iucv_query_generic(int want_maxconn)
1250{ 1246{
1247 register unsigned long reg0 asm ("0");
1248 register unsigned long reg1 asm ("1");
1251 iparml_purge *parm = (iparml_purge *)grab_param(); 1249 iparml_purge *parm = (iparml_purge *)grab_param();
1252 int bufsize, maxconn; 1250 int bufsize, maxconn;
1253 int ccode; 1251 int ccode;
@@ -1256,18 +1254,15 @@ iucv_query_generic(int want_maxconn)
1256 * Call b2f0 and store R0 (max buffer size), 1254 * Call b2f0 and store R0 (max buffer size),
1257 * R1 (max connections) and CC. 1255 * R1 (max connections) and CC.
1258 */ 1256 */
1259 asm volatile ( 1257 reg0 = QUERY;
1260 "LRA 1,0(%4)\n\t" 1258 reg1 = virt_to_phys(parm);
1261 "LR 0,%3\n\t" 1259 asm volatile(
1262 ".long 0xb2f01000\n\t" 1260 " .long 0xb2f01000\n"
1263 "IPM %0\n\t" 1261 " ipm %0\n"
1264 "SRL %0,28\n\t" 1262 " srl %0,28\n"
1265 "ST 0,%1\n\t" 1263 : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
1266 "ST 1,%2\n\t" 1264 bufsize = reg0;
1267 : "=d" (ccode), "=m" (bufsize), "=m" (maxconn) 1265 maxconn = reg1;
1268 : "d" (QUERY), "a" (parm)
1269 : "0", "1", "cc"
1270 );
1271 release_param(parm); 1266 release_param(parm);
1272 1267
1273 if (ccode) 1268 if (ccode)
diff --git a/drivers/s390/s390mach.c b/drivers/s390/s390mach.c
index a914129a4da9..479364d0332a 100644
--- a/drivers/s390/s390mach.c
+++ b/drivers/s390/s390mach.c
@@ -253,11 +253,12 @@ s390_revalidate_registers(struct mci *mci)
253 kill_task = 1; 253 kill_task = 1;
254 254
255#ifndef CONFIG_64BIT 255#ifndef CONFIG_64BIT
256 asm volatile("ld 0,0(%0)\n" 256 asm volatile(
257 "ld 2,8(%0)\n" 257 " ld 0,0(%0)\n"
258 "ld 4,16(%0)\n" 258 " ld 2,8(%0)\n"
259 "ld 6,24(%0)" 259 " ld 4,16(%0)\n"
260 : : "a" (&S390_lowcore.floating_pt_save_area)); 260 " ld 6,24(%0)"
261 : : "a" (&S390_lowcore.floating_pt_save_area));
261#endif 262#endif
262 263
263 if (MACHINE_HAS_IEEE) { 264 if (MACHINE_HAS_IEEE) {
@@ -274,37 +275,36 @@ s390_revalidate_registers(struct mci *mci)
274 * Floating point control register can't be restored. 275 * Floating point control register can't be restored.
275 * Task will be terminated. 276 * Task will be terminated.
276 */ 277 */
277 asm volatile ("lfpc 0(%0)" : : "a" (&zero), "m" (zero)); 278 asm volatile("lfpc 0(%0)" : : "a" (&zero), "m" (zero));
278 kill_task = 1; 279 kill_task = 1;
279 280
280 } 281 } else
281 else 282 asm volatile("lfpc 0(%0)" : : "a" (fpt_creg_save_area));
282 asm volatile ( 283
283 "lfpc 0(%0)" 284 asm volatile(
284 : : "a" (fpt_creg_save_area)); 285 " ld 0,0(%0)\n"
285 286 " ld 1,8(%0)\n"
286 asm volatile("ld 0,0(%0)\n" 287 " ld 2,16(%0)\n"
287 "ld 1,8(%0)\n" 288 " ld 3,24(%0)\n"
288 "ld 2,16(%0)\n" 289 " ld 4,32(%0)\n"
289 "ld 3,24(%0)\n" 290 " ld 5,40(%0)\n"
290 "ld 4,32(%0)\n" 291 " ld 6,48(%0)\n"
291 "ld 5,40(%0)\n" 292 " ld 7,56(%0)\n"
292 "ld 6,48(%0)\n" 293 " ld 8,64(%0)\n"
293 "ld 7,56(%0)\n" 294 " ld 9,72(%0)\n"
294 "ld 8,64(%0)\n" 295 " ld 10,80(%0)\n"
295 "ld 9,72(%0)\n" 296 " ld 11,88(%0)\n"
296 "ld 10,80(%0)\n" 297 " ld 12,96(%0)\n"
297 "ld 11,88(%0)\n" 298 " ld 13,104(%0)\n"
298 "ld 12,96(%0)\n" 299 " ld 14,112(%0)\n"
299 "ld 13,104(%0)\n" 300 " ld 15,120(%0)\n"
300 "ld 14,112(%0)\n" 301 : : "a" (fpt_save_area));
301 "ld 15,120(%0)\n"
302 : : "a" (fpt_save_area));
303 } 302 }
304 303
305 /* Revalidate access registers */ 304 /* Revalidate access registers */
306 asm volatile("lam 0,15,0(%0)" 305 asm volatile(
307 : : "a" (&S390_lowcore.access_regs_save_area)); 306 " lam 0,15,0(%0)"
307 : : "a" (&S390_lowcore.access_regs_save_area));
308 if (!mci->ar) 308 if (!mci->ar)
309 /* 309 /*
310 * Access registers have unknown contents. 310 * Access registers have unknown contents.
@@ -321,11 +321,13 @@ s390_revalidate_registers(struct mci *mci)
321 s390_handle_damage("invalid control registers."); 321 s390_handle_damage("invalid control registers.");
322 else 322 else
323#ifdef CONFIG_64BIT 323#ifdef CONFIG_64BIT
324 asm volatile("lctlg 0,15,0(%0)" 324 asm volatile(
325 : : "a" (&S390_lowcore.cregs_save_area)); 325 " lctlg 0,15,0(%0)"
326 : : "a" (&S390_lowcore.cregs_save_area));
326#else 327#else
327 asm volatile("lctl 0,15,0(%0)" 328 asm volatile(
328 : : "a" (&S390_lowcore.cregs_save_area)); 329 " lctl 0,15,0(%0)"
330 : : "a" (&S390_lowcore.cregs_save_area));
329#endif 331#endif
330 332
331 /* 333 /*
@@ -339,20 +341,23 @@ s390_revalidate_registers(struct mci *mci)
339 * old contents (should be zero) otherwise set it to zero. 341 * old contents (should be zero) otherwise set it to zero.
340 */ 342 */
341 if (!mci->pr) 343 if (!mci->pr)
342 asm volatile("sr 0,0\n" 344 asm volatile(
343 "sckpf" 345 " sr 0,0\n"
344 : : : "0", "cc"); 346 " sckpf"
347 : : : "0", "cc");
345 else 348 else
346 asm volatile( 349 asm volatile(
347 "l 0,0(%0)\n" 350 " l 0,0(%0)\n"
348 "sckpf" 351 " sckpf"
349 : : "a" (&S390_lowcore.tod_progreg_save_area) : "0", "cc"); 352 : : "a" (&S390_lowcore.tod_progreg_save_area)
353 : "0", "cc");
350#endif 354#endif
351 355
352 /* Revalidate clock comparator register */ 356 /* Revalidate clock comparator register */
353 asm volatile ("stck 0(%1)\n" 357 asm volatile(
354 "sckc 0(%1)" 358 " stck 0(%1)\n"
355 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory"); 359 " sckc 0(%1)"
360 : "=m" (tmpclock) : "a" (&(tmpclock)) : "cc", "memory");
356 361
357 /* Check if old PSW is valid */ 362 /* Check if old PSW is valid */
358 if (!mci->wp) 363 if (!mci->wp)
diff --git a/drivers/serial/at91_serial.c b/drivers/serial/at91_serial.c
index 54c6b2adf7b7..bf4bf103e5a0 100644
--- a/drivers/serial/at91_serial.c
+++ b/drivers/serial/at91_serial.c
@@ -139,7 +139,7 @@ static void at91_set_mctrl(struct uart_port *port, u_int mctrl)
139 * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21. 139 * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
140 * We need to drive the pin manually. 140 * We need to drive the pin manually.
141 */ 141 */
142 if (port->mapbase == AT91_BASE_US0) { 142 if (port->mapbase == AT91RM9200_BASE_US0) {
143 if (mctrl & TIOCM_RTS) 143 if (mctrl & TIOCM_RTS)
144 at91_set_gpio_value(AT91_PIN_PA21, 0); 144 at91_set_gpio_value(AT91_PIN_PA21, 0);
145 else 145 else
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index b10463244413..113e484c763e 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/workqueue.h>
27#include "hcd.h" 28#include "hcd.h"
28#include "usb.h" 29#include "usb.h"
29 30
@@ -302,11 +303,11 @@ int usb_driver_claim_interface(struct usb_driver *driver,
302 dev->driver = &driver->drvwrap.driver; 303 dev->driver = &driver->drvwrap.driver;
303 usb_set_intfdata(iface, priv); 304 usb_set_intfdata(iface, priv);
304 305
305 mutex_lock_nested(&udev->pm_mutex, udev->level); 306 usb_pm_lock(udev);
306 iface->condition = USB_INTERFACE_BOUND; 307 iface->condition = USB_INTERFACE_BOUND;
307 mark_active(iface); 308 mark_active(iface);
308 iface->pm_usage_cnt = !(driver->supports_autosuspend); 309 iface->pm_usage_cnt = !(driver->supports_autosuspend);
309 mutex_unlock(&udev->pm_mutex); 310 usb_pm_unlock(udev);
310 311
311 /* if interface was already added, bind now; else let 312 /* if interface was already added, bind now; else let
312 * the future device_add() bind it, bypassing probe() 313 * the future device_add() bind it, bypassing probe()
@@ -355,11 +356,11 @@ void usb_driver_release_interface(struct usb_driver *driver,
355 dev->driver = NULL; 356 dev->driver = NULL;
356 usb_set_intfdata(iface, NULL); 357 usb_set_intfdata(iface, NULL);
357 358
358 mutex_lock_nested(&udev->pm_mutex, udev->level); 359 usb_pm_lock(udev);
359 iface->condition = USB_INTERFACE_UNBOUND; 360 iface->condition = USB_INTERFACE_UNBOUND;
360 mark_quiesced(iface); 361 mark_quiesced(iface);
361 iface->needs_remote_wakeup = 0; 362 iface->needs_remote_wakeup = 0;
362 mutex_unlock(&udev->pm_mutex); 363 usb_pm_unlock(udev);
363} 364}
364EXPORT_SYMBOL(usb_driver_release_interface); 365EXPORT_SYMBOL(usb_driver_release_interface);
365 366
@@ -788,7 +789,7 @@ EXPORT_SYMBOL_GPL_FUTURE(usb_deregister);
788 789
789#ifdef CONFIG_PM 790#ifdef CONFIG_PM
790 791
791/* Caller has locked udev->pm_mutex */ 792/* Caller has locked udev's pm_mutex */
792static int suspend_device(struct usb_device *udev, pm_message_t msg) 793static int suspend_device(struct usb_device *udev, pm_message_t msg)
793{ 794{
794 struct usb_device_driver *udriver; 795 struct usb_device_driver *udriver;
@@ -815,7 +816,7 @@ done:
815 return status; 816 return status;
816} 817}
817 818
818/* Caller has locked udev->pm_mutex */ 819/* Caller has locked udev's pm_mutex */
819static int resume_device(struct usb_device *udev) 820static int resume_device(struct usb_device *udev)
820{ 821{
821 struct usb_device_driver *udriver; 822 struct usb_device_driver *udriver;
@@ -841,7 +842,7 @@ done:
841 return status; 842 return status;
842} 843}
843 844
844/* Caller has locked intf's usb_device's pm_mutex */ 845/* Caller has locked intf's usb_device's pm mutex */
845static int suspend_interface(struct usb_interface *intf, pm_message_t msg) 846static int suspend_interface(struct usb_interface *intf, pm_message_t msg)
846{ 847{
847 struct usb_driver *driver; 848 struct usb_driver *driver;
@@ -1063,7 +1064,7 @@ int usb_resume_both(struct usb_device *udev)
1063 /* Propagate the resume up the tree, if necessary */ 1064 /* Propagate the resume up the tree, if necessary */
1064 if (udev->state == USB_STATE_SUSPENDED) { 1065 if (udev->state == USB_STATE_SUSPENDED) {
1065 if (parent) { 1066 if (parent) {
1066 mutex_lock_nested(&parent->pm_mutex, parent->level); 1067 usb_pm_lock(parent);
1067 parent->auto_pm = 1; 1068 parent->auto_pm = 1;
1068 status = usb_resume_both(parent); 1069 status = usb_resume_both(parent);
1069 } else { 1070 } else {
@@ -1078,7 +1079,7 @@ int usb_resume_both(struct usb_device *udev)
1078 if (status == 0) 1079 if (status == 0)
1079 status = resume_device(udev); 1080 status = resume_device(udev);
1080 if (parent) 1081 if (parent)
1081 mutex_unlock(&parent->pm_mutex); 1082 usb_pm_unlock(parent);
1082 } else { 1083 } else {
1083 1084
1084 /* Needed only for setting udev->dev.power.power_state.event 1085 /* Needed only for setting udev->dev.power.power_state.event
@@ -1103,8 +1104,8 @@ int usb_resume_both(struct usb_device *udev)
1103 1104
1104/** 1105/**
1105 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces 1106 * usb_autosuspend_device - delayed autosuspend of a USB device and its interfaces
1106 * @udev - the usb_device to autosuspend 1107 * @udev: the usb_device to autosuspend
1107 * @dec_usage_cnt - flag to decrement @udev's PM-usage counter 1108 * @dec_usage_cnt: flag to decrement @udev's PM-usage counter
1108 * 1109 *
1109 * This routine should be called when a core subsystem is finished using 1110 * This routine should be called when a core subsystem is finished using
1110 * @udev and wants to allow it to autosuspend. Examples would be when 1111 * @udev and wants to allow it to autosuspend. Examples would be when
@@ -1128,20 +1129,20 @@ int usb_resume_both(struct usb_device *udev)
1128 */ 1129 */
1129void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt) 1130void usb_autosuspend_device(struct usb_device *udev, int dec_usage_cnt)
1130{ 1131{
1131 mutex_lock_nested(&udev->pm_mutex, udev->level); 1132 usb_pm_lock(udev);
1132 udev->pm_usage_cnt -= dec_usage_cnt; 1133 udev->pm_usage_cnt -= dec_usage_cnt;
1133 if (udev->pm_usage_cnt <= 0) 1134 if (udev->pm_usage_cnt <= 0)
1134 schedule_delayed_work(&udev->autosuspend, 1135 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1135 USB_AUTOSUSPEND_DELAY); 1136 USB_AUTOSUSPEND_DELAY);
1136 mutex_unlock(&udev->pm_mutex); 1137 usb_pm_unlock(udev);
1137 // dev_dbg(&udev->dev, "%s: cnt %d\n", 1138 // dev_dbg(&udev->dev, "%s: cnt %d\n",
1138 // __FUNCTION__, udev->pm_usage_cnt); 1139 // __FUNCTION__, udev->pm_usage_cnt);
1139} 1140}
1140 1141
1141/** 1142/**
1142 * usb_autoresume_device - immediately autoresume a USB device and its interfaces 1143 * usb_autoresume_device - immediately autoresume a USB device and its interfaces
1143 * @udev - the usb_device to autoresume 1144 * @udev: the usb_device to autoresume
1144 * @inc_usage_cnt - flag to increment @udev's PM-usage counter 1145 * @inc_usage_cnt: flag to increment @udev's PM-usage counter
1145 * 1146 *
1146 * This routine should be called when a core subsystem wants to use @udev 1147 * This routine should be called when a core subsystem wants to use @udev
1147 * and needs to guarantee that it is not suspended. In addition, the 1148 * and needs to guarantee that it is not suspended. In addition, the
@@ -1167,13 +1168,13 @@ int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt)
1167{ 1168{
1168 int status; 1169 int status;
1169 1170
1170 mutex_lock_nested(&udev->pm_mutex, udev->level); 1171 usb_pm_lock(udev);
1171 udev->pm_usage_cnt += inc_usage_cnt; 1172 udev->pm_usage_cnt += inc_usage_cnt;
1172 udev->auto_pm = 1; 1173 udev->auto_pm = 1;
1173 status = usb_resume_both(udev); 1174 status = usb_resume_both(udev);
1174 if (status != 0) 1175 if (status != 0)
1175 udev->pm_usage_cnt -= inc_usage_cnt; 1176 udev->pm_usage_cnt -= inc_usage_cnt;
1176 mutex_unlock(&udev->pm_mutex); 1177 usb_pm_unlock(udev);
1177 // dev_dbg(&udev->dev, "%s: status %d cnt %d\n", 1178 // dev_dbg(&udev->dev, "%s: status %d cnt %d\n",
1178 // __FUNCTION__, status, udev->pm_usage_cnt); 1179 // __FUNCTION__, status, udev->pm_usage_cnt);
1179 return status; 1180 return status;
@@ -1181,7 +1182,7 @@ int usb_autoresume_device(struct usb_device *udev, int inc_usage_cnt)
1181 1182
1182/** 1183/**
1183 * usb_autopm_put_interface - decrement a USB interface's PM-usage counter 1184 * usb_autopm_put_interface - decrement a USB interface's PM-usage counter
1184 * @intf - the usb_interface whose counter should be decremented 1185 * @intf: the usb_interface whose counter should be decremented
1185 * 1186 *
1186 * This routine should be called by an interface driver when it is 1187 * This routine should be called by an interface driver when it is
1187 * finished using @intf and wants to allow it to autosuspend. A typical 1188 * finished using @intf and wants to allow it to autosuspend. A typical
@@ -1214,13 +1215,13 @@ void usb_autopm_put_interface(struct usb_interface *intf)
1214{ 1215{
1215 struct usb_device *udev = interface_to_usbdev(intf); 1216 struct usb_device *udev = interface_to_usbdev(intf);
1216 1217
1217 mutex_lock_nested(&udev->pm_mutex, udev->level); 1218 usb_pm_lock(udev);
1218 if (intf->condition != USB_INTERFACE_UNBOUND) { 1219 if (intf->condition != USB_INTERFACE_UNBOUND &&
1219 if (--intf->pm_usage_cnt <= 0) 1220 --intf->pm_usage_cnt <= 0) {
1220 schedule_delayed_work(&udev->autosuspend, 1221 queue_delayed_work(ksuspend_usb_wq, &udev->autosuspend,
1221 USB_AUTOSUSPEND_DELAY); 1222 USB_AUTOSUSPEND_DELAY);
1222 } 1223 }
1223 mutex_unlock(&udev->pm_mutex); 1224 usb_pm_unlock(udev);
1224 // dev_dbg(&intf->dev, "%s: cnt %d\n", 1225 // dev_dbg(&intf->dev, "%s: cnt %d\n",
1225 // __FUNCTION__, intf->pm_usage_cnt); 1226 // __FUNCTION__, intf->pm_usage_cnt);
1226} 1227}
@@ -1228,7 +1229,7 @@ EXPORT_SYMBOL_GPL(usb_autopm_put_interface);
1228 1229
1229/** 1230/**
1230 * usb_autopm_get_interface - increment a USB interface's PM-usage counter 1231 * usb_autopm_get_interface - increment a USB interface's PM-usage counter
1231 * @intf - the usb_interface whose counter should be incremented 1232 * @intf: the usb_interface whose counter should be incremented
1232 * 1233 *
1233 * This routine should be called by an interface driver when it wants to 1234 * This routine should be called by an interface driver when it wants to
1234 * use @intf and needs to guarantee that it is not suspended. In addition, 1235 * use @intf and needs to guarantee that it is not suspended. In addition,
@@ -1262,7 +1263,7 @@ int usb_autopm_get_interface(struct usb_interface *intf)
1262 struct usb_device *udev = interface_to_usbdev(intf); 1263 struct usb_device *udev = interface_to_usbdev(intf);
1263 int status; 1264 int status;
1264 1265
1265 mutex_lock_nested(&udev->pm_mutex, udev->level); 1266 usb_pm_lock(udev);
1266 if (intf->condition == USB_INTERFACE_UNBOUND) 1267 if (intf->condition == USB_INTERFACE_UNBOUND)
1267 status = -ENODEV; 1268 status = -ENODEV;
1268 else { 1269 else {
@@ -1272,7 +1273,7 @@ int usb_autopm_get_interface(struct usb_interface *intf)
1272 if (status != 0) 1273 if (status != 0)
1273 --intf->pm_usage_cnt; 1274 --intf->pm_usage_cnt;
1274 } 1275 }
1275 mutex_unlock(&udev->pm_mutex); 1276 usb_pm_unlock(udev);
1276 // dev_dbg(&intf->dev, "%s: status %d cnt %d\n", 1277 // dev_dbg(&intf->dev, "%s: status %d cnt %d\n",
1277 // __FUNCTION__, status, intf->pm_usage_cnt); 1278 // __FUNCTION__, status, intf->pm_usage_cnt);
1278 return status; 1279 return status;
@@ -1288,10 +1289,10 @@ static int usb_suspend(struct device *dev, pm_message_t message)
1288 if (is_usb_device(dev)) { 1289 if (is_usb_device(dev)) {
1289 struct usb_device *udev = to_usb_device(dev); 1290 struct usb_device *udev = to_usb_device(dev);
1290 1291
1291 mutex_lock_nested(&udev->pm_mutex, udev->level); 1292 usb_pm_lock(udev);
1292 udev->auto_pm = 0; 1293 udev->auto_pm = 0;
1293 status = usb_suspend_both(udev, message); 1294 status = usb_suspend_both(udev, message);
1294 mutex_unlock(&udev->pm_mutex); 1295 usb_pm_unlock(udev);
1295 } else 1296 } else
1296 status = 0; 1297 status = 0;
1297 return status; 1298 return status;
@@ -1304,10 +1305,10 @@ static int usb_resume(struct device *dev)
1304 if (is_usb_device(dev)) { 1305 if (is_usb_device(dev)) {
1305 struct usb_device *udev = to_usb_device(dev); 1306 struct usb_device *udev = to_usb_device(dev);
1306 1307
1307 mutex_lock_nested(&udev->pm_mutex, udev->level); 1308 usb_pm_lock(udev);
1308 udev->auto_pm = 0; 1309 udev->auto_pm = 0;
1309 status = usb_resume_both(udev); 1310 status = usb_resume_both(udev);
1310 mutex_unlock(&udev->pm_mutex); 1311 usb_pm_unlock(udev);
1311 1312
1312 /* Rebind drivers that had no suspend method? */ 1313 /* Rebind drivers that had no suspend method? */
1313 } else 1314 } else
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index e86f62957085..37f9f5e7425d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -345,7 +345,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
345 struct usb_ctrlrequest *cmd; 345 struct usb_ctrlrequest *cmd;
346 u16 typeReq, wValue, wIndex, wLength; 346 u16 typeReq, wValue, wIndex, wLength;
347 u8 *ubuf = urb->transfer_buffer; 347 u8 *ubuf = urb->transfer_buffer;
348 u8 tbuf [sizeof (struct usb_hub_descriptor)]; 348 u8 tbuf [sizeof (struct usb_hub_descriptor)]
349 __attribute__((aligned(4)));
349 const u8 *bufp = tbuf; 350 const u8 *bufp = tbuf;
350 int len = 0; 351 int len = 0;
351 int patch_wakeup = 0; 352 int patch_wakeup = 0;
@@ -835,8 +836,7 @@ void usb_enable_root_hub_irq (struct usb_bus *bus)
835 struct usb_hcd *hcd; 836 struct usb_hcd *hcd;
836 837
837 hcd = container_of (bus, struct usb_hcd, self); 838 hcd = container_of (bus, struct usb_hcd, self);
838 if (hcd->driver->hub_irq_enable && !hcd->poll_rh && 839 if (hcd->driver->hub_irq_enable && hcd->state != HC_STATE_HALT)
839 hcd->state != HC_STATE_HALT)
840 hcd->driver->hub_irq_enable (hcd); 840 hcd->driver->hub_irq_enable (hcd);
841} 841}
842 842
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2a8cb3c2b19c..7676690a0386 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1779,7 +1779,7 @@ static int remote_wakeup(struct usb_device *udev)
1779 * to the parent hub! */ 1779 * to the parent hub! */
1780 1780
1781 usb_lock_device(udev); 1781 usb_lock_device(udev);
1782 mutex_lock_nested(&udev->pm_mutex, udev->level); 1782 usb_pm_lock(udev);
1783 if (udev->state == USB_STATE_SUSPENDED) { 1783 if (udev->state == USB_STATE_SUSPENDED) {
1784 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-"); 1784 dev_dbg(&udev->dev, "usb %sresume\n", "wakeup-");
1785 /* TRSMRCY = 10 msec */ 1785 /* TRSMRCY = 10 msec */
@@ -1788,7 +1788,7 @@ static int remote_wakeup(struct usb_device *udev)
1788 if (status == 0) 1788 if (status == 0)
1789 udev->dev.power.power_state.event = PM_EVENT_ON; 1789 udev->dev.power.power_state.event = PM_EVENT_ON;
1790 } 1790 }
1791 mutex_unlock(&udev->pm_mutex); 1791 usb_pm_unlock(udev);
1792 1792
1793 if (status == 0) 1793 if (status == 0)
1794 usb_autoresume_device(udev, 0); 1794 usb_autoresume_device(udev, 0);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 60ef4ef0101a..e4df9edf1bc0 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -33,6 +33,7 @@
33#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include <linux/mutex.h> 35#include <linux/mutex.h>
36#include <linux/workqueue.h>
36 37
37#include <asm/io.h> 38#include <asm/io.h>
38#include <asm/scatterlist.h> 39#include <asm/scatterlist.h>
@@ -47,6 +48,8 @@ const char *usbcore_name = "usbcore";
47 48
48static int nousb; /* Disable USB when built into kernel image */ 49static int nousb; /* Disable USB when built into kernel image */
49 50
51struct workqueue_struct *ksuspend_usb_wq; /* For autosuspend */
52
50 53
51/** 54/**
52 * usb_ifnum_to_if - get the interface object with a given interface number 55 * usb_ifnum_to_if - get the interface object with a given interface number
@@ -170,9 +173,9 @@ static void usb_release_dev(struct device *dev)
170 173
171 udev = to_usb_device(dev); 174 udev = to_usb_device(dev);
172 175
173#ifdef CONFIG_PM 176#ifdef CONFIG_USB_SUSPEND
174 cancel_delayed_work(&udev->autosuspend); 177 cancel_delayed_work(&udev->autosuspend);
175 flush_scheduled_work(); 178 flush_workqueue(ksuspend_usb_wq);
176#endif 179#endif
177 usb_destroy_configuration(udev); 180 usb_destroy_configuration(udev);
178 usb_put_hcd(bus_to_hcd(udev->bus)); 181 usb_put_hcd(bus_to_hcd(udev->bus));
@@ -184,17 +187,44 @@ static void usb_release_dev(struct device *dev)
184 187
185#ifdef CONFIG_PM 188#ifdef CONFIG_PM
186 189
190static int ksuspend_usb_init(void)
191{
192 ksuspend_usb_wq = create_singlethread_workqueue("ksuspend_usbd");
193 if (!ksuspend_usb_wq)
194 return -ENOMEM;
195 return 0;
196}
197
198static void ksuspend_usb_cleanup(void)
199{
200 destroy_workqueue(ksuspend_usb_wq);
201}
202
203#else
204
205#define ksuspend_usb_init() 0
206#define ksuspend_usb_cleanup() do {} while (0)
207
208#endif
209
210#ifdef CONFIG_USB_SUSPEND
211
187/* usb_autosuspend_work - callback routine to autosuspend a USB device */ 212/* usb_autosuspend_work - callback routine to autosuspend a USB device */
188static void usb_autosuspend_work(void *_udev) 213static void usb_autosuspend_work(void *_udev)
189{ 214{
190 struct usb_device *udev = _udev; 215 struct usb_device *udev = _udev;
191 216
192 mutex_lock_nested(&udev->pm_mutex, udev->level); 217 usb_pm_lock(udev);
193 udev->auto_pm = 1; 218 udev->auto_pm = 1;
194 usb_suspend_both(udev, PMSG_SUSPEND); 219 usb_suspend_both(udev, PMSG_SUSPEND);
195 mutex_unlock(&udev->pm_mutex); 220 usb_pm_unlock(udev);
196} 221}
197 222
223#else
224
225static void usb_autosuspend_work(void *_udev)
226{}
227
198#endif 228#endif
199 229
200/** 230/**
@@ -976,9 +1006,12 @@ static int __init usb_init(void)
976 return 0; 1006 return 0;
977 } 1007 }
978 1008
1009 retval = ksuspend_usb_init();
1010 if (retval)
1011 goto out;
979 retval = bus_register(&usb_bus_type); 1012 retval = bus_register(&usb_bus_type);
980 if (retval) 1013 if (retval)
981 goto out; 1014 goto bus_register_failed;
982 retval = usb_host_init(); 1015 retval = usb_host_init();
983 if (retval) 1016 if (retval)
984 goto host_init_failed; 1017 goto host_init_failed;
@@ -1014,6 +1047,8 @@ major_init_failed:
1014 usb_host_cleanup(); 1047 usb_host_cleanup();
1015host_init_failed: 1048host_init_failed:
1016 bus_unregister(&usb_bus_type); 1049 bus_unregister(&usb_bus_type);
1050bus_register_failed:
1051 ksuspend_usb_cleanup();
1017out: 1052out:
1018 return retval; 1053 return retval;
1019} 1054}
@@ -1035,6 +1070,7 @@ static void __exit usb_exit(void)
1035 usb_hub_cleanup(); 1070 usb_hub_cleanup();
1036 usb_host_cleanup(); 1071 usb_host_cleanup();
1037 bus_unregister(&usb_bus_type); 1072 bus_unregister(&usb_bus_type);
1073 ksuspend_usb_cleanup();
1038} 1074}
1039 1075
1040subsys_initcall(usb_init); 1076subsys_initcall(usb_init);
diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
index 0c09ecced6e1..f69df137ec0e 100644
--- a/drivers/usb/core/usb.h
+++ b/drivers/usb/core/usb.h
@@ -36,6 +36,16 @@ extern int usb_resume_both(struct usb_device *udev);
36extern int usb_port_suspend(struct usb_device *dev); 36extern int usb_port_suspend(struct usb_device *dev);
37extern int usb_port_resume(struct usb_device *dev); 37extern int usb_port_resume(struct usb_device *dev);
38 38
39static inline void usb_pm_lock(struct usb_device *udev)
40{
41 mutex_lock_nested(&udev->pm_mutex, udev->level);
42}
43
44static inline void usb_pm_unlock(struct usb_device *udev)
45{
46 mutex_unlock(&udev->pm_mutex);
47}
48
39#else 49#else
40 50
41#define usb_suspend_both(udev, msg) 0 51#define usb_suspend_both(udev, msg) 0
@@ -45,6 +55,8 @@ static inline int usb_resume_both(struct usb_device *udev)
45} 55}
46#define usb_port_suspend(dev) 0 56#define usb_port_suspend(dev) 0
47#define usb_port_resume(dev) 0 57#define usb_port_resume(dev) 0
58static inline void usb_pm_lock(struct usb_device *udev) {}
59static inline void usb_pm_unlock(struct usb_device *udev) {}
48 60
49#endif 61#endif
50 62
@@ -58,10 +70,15 @@ extern int usb_autoresume_device(struct usb_device *udev, int inc_busy_cnt);
58#else 70#else
59 71
60#define usb_autosuspend_device(udev, dec_busy_cnt) do {} while (0) 72#define usb_autosuspend_device(udev, dec_busy_cnt) do {} while (0)
61#define usb_autoresume_device(udev, inc_busy_cnt) 0 73static inline int usb_autoresume_device(struct usb_device *udev,
74 int inc_busy_cnt)
75{
76 return 0;
77}
62 78
63#endif 79#endif
64 80
81extern struct workqueue_struct *ksuspend_usb_wq;
65extern struct bus_type usb_bus_type; 82extern struct bus_type usb_bus_type;
66extern struct usb_device_driver usb_generic_driver; 83extern struct usb_device_driver usb_generic_driver;
67 84
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index d00958a01cfb..77beba485a84 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -1658,7 +1658,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1658 return -ENODEV; 1658 return -ENODEV;
1659 } 1659 }
1660 1660
1661 if (!request_mem_region(AT91_BASE_UDP, SZ_16K, driver_name)) { 1661 if (!request_mem_region(AT91RM9200_BASE_UDP, SZ_16K, driver_name)) {
1662 DBG("someone's using UDC memory\n"); 1662 DBG("someone's using UDC memory\n");
1663 return -EBUSY; 1663 return -EBUSY;
1664 } 1664 }
@@ -1720,7 +1720,7 @@ static int __devinit at91udc_probe(struct platform_device *pdev)
1720fail1: 1720fail1:
1721 device_unregister(&udc->gadget.dev); 1721 device_unregister(&udc->gadget.dev);
1722fail0: 1722fail0:
1723 release_mem_region(AT91_BASE_UDP, SZ_16K); 1723 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K);
1724 DBG("%s probe failed, %d\n", driver_name, retval); 1724 DBG("%s probe failed, %d\n", driver_name, retval);
1725 return retval; 1725 return retval;
1726} 1726}
@@ -1742,7 +1742,7 @@ static int __devexit at91udc_remove(struct platform_device *pdev)
1742 free_irq(udc->board.vbus_pin, udc); 1742 free_irq(udc->board.vbus_pin, udc);
1743 free_irq(udc->udp_irq, udc); 1743 free_irq(udc->udp_irq, udc);
1744 device_unregister(&udc->gadget.dev); 1744 device_unregister(&udc->gadget.dev);
1745 release_mem_region(AT91_BASE_UDP, SZ_16K); 1745 release_mem_region(AT91RM9200_BASE_UDP, SZ_16K);
1746 1746
1747 clk_put(udc->iclk); 1747 clk_put(udc->iclk);
1748 clk_put(udc->fclk); 1748 clk_put(udc->fclk);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index fdab97a27c08..4d2946e540cf 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -816,15 +816,14 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
816 dum->gadget.dev.driver = &driver->driver; 816 dum->gadget.dev.driver = &driver->driver;
817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n", 817 dev_dbg (udc_dev(dum), "binding gadget driver '%s'\n",
818 driver->driver.name); 818 driver->driver.name);
819 if ((retval = driver->bind (&dum->gadget)) != 0) { 819 if ((retval = driver->bind (&dum->gadget)) != 0)
820 dum->driver = NULL; 820 goto err_bind_gadget;
821 dum->gadget.dev.driver = NULL;
822 return retval;
823 }
824 821
825 driver->driver.bus = dum->gadget.dev.parent->bus; 822 driver->driver.bus = dum->gadget.dev.parent->bus;
826 driver_register (&driver->driver); 823 if ((retval = driver_register (&driver->driver)) != 0)
827 device_bind_driver (&dum->gadget.dev); 824 goto err_register;
825 if ((retval = device_bind_driver (&dum->gadget.dev)) != 0)
826 goto err_bind_driver;
828 827
829 /* khubd will enumerate this in a while */ 828 /* khubd will enumerate this in a while */
830 spin_lock_irq (&dum->lock); 829 spin_lock_irq (&dum->lock);
@@ -834,6 +833,19 @@ usb_gadget_register_driver (struct usb_gadget_driver *driver)
834 833
835 usb_hcd_poll_rh_status (dummy_to_hcd (dum)); 834 usb_hcd_poll_rh_status (dummy_to_hcd (dum));
836 return 0; 835 return 0;
836
837err_bind_driver:
838 driver_unregister (&driver->driver);
839err_register:
840 driver->unbind (&dum->gadget);
841 spin_lock_irq (&dum->lock);
842 dum->pullup = 0;
843 set_link_state (dum);
844 spin_unlock_irq (&dum->lock);
845err_bind_gadget:
846 dum->driver = NULL;
847 dum->gadget.dev.driver = NULL;
848 return retval;
837} 849}
838EXPORT_SYMBOL (usb_gadget_register_driver); 850EXPORT_SYMBOL (usb_gadget_register_driver);
839 851
@@ -916,7 +928,9 @@ static int dummy_udc_probe (struct platform_device *pdev)
916 usb_get_hcd (dummy_to_hcd (dum)); 928 usb_get_hcd (dummy_to_hcd (dum));
917 929
918 platform_set_drvdata (pdev, dum); 930 platform_set_drvdata (pdev, dum);
919 device_create_file (&dum->gadget.dev, &dev_attr_function); 931 rc = device_create_file (&dum->gadget.dev, &dev_attr_function);
932 if (rc < 0)
933 device_unregister (&dum->gadget.dev);
920 return rc; 934 return rc;
921} 935}
922 936
@@ -1864,8 +1878,7 @@ static int dummy_start (struct usb_hcd *hcd)
1864#endif 1878#endif
1865 1879
1866 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */ 1880 /* FIXME 'urbs' should be a per-device thing, maybe in usbcore */
1867 device_create_file (dummy_dev(dum), &dev_attr_urbs); 1881 return device_create_file (dummy_dev(dum), &dev_attr_urbs);
1868 return 0;
1869} 1882}
1870 1883
1871static void dummy_stop (struct usb_hcd *hcd) 1884static void dummy_stop (struct usb_hcd *hcd)
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 8d7f1e84cd7b..c83d3b6c68f2 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -567,6 +567,7 @@ struct lun {
567 unsigned int ro : 1; 567 unsigned int ro : 1;
568 unsigned int prevent_medium_removal : 1; 568 unsigned int prevent_medium_removal : 1;
569 unsigned int registered : 1; 569 unsigned int registered : 1;
570 unsigned int info_valid : 1;
570 571
571 u32 sense_data; 572 u32 sense_data;
572 u32 sense_data_info; 573 u32 sense_data_info;
@@ -1656,6 +1657,7 @@ static int do_read(struct fsg_dev *fsg)
1656 curlun->sense_data = 1657 curlun->sense_data =
1657 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1658 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1658 curlun->sense_data_info = file_offset >> 9; 1659 curlun->sense_data_info = file_offset >> 9;
1660 curlun->info_valid = 1;
1659 bh->inreq->length = 0; 1661 bh->inreq->length = 0;
1660 bh->state = BUF_STATE_FULL; 1662 bh->state = BUF_STATE_FULL;
1661 break; 1663 break;
@@ -1691,6 +1693,7 @@ static int do_read(struct fsg_dev *fsg)
1691 if (nread < amount) { 1693 if (nread < amount) {
1692 curlun->sense_data = SS_UNRECOVERED_READ_ERROR; 1694 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
1693 curlun->sense_data_info = file_offset >> 9; 1695 curlun->sense_data_info = file_offset >> 9;
1696 curlun->info_valid = 1;
1694 break; 1697 break;
1695 } 1698 }
1696 1699
@@ -1785,6 +1788,7 @@ static int do_write(struct fsg_dev *fsg)
1785 curlun->sense_data = 1788 curlun->sense_data =
1786 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 1789 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
1787 curlun->sense_data_info = usb_offset >> 9; 1790 curlun->sense_data_info = usb_offset >> 9;
1791 curlun->info_valid = 1;
1788 continue; 1792 continue;
1789 } 1793 }
1790 amount -= (amount & 511); 1794 amount -= (amount & 511);
@@ -1827,6 +1831,7 @@ static int do_write(struct fsg_dev *fsg)
1827 if (bh->outreq->status != 0) { 1831 if (bh->outreq->status != 0) {
1828 curlun->sense_data = SS_COMMUNICATION_FAILURE; 1832 curlun->sense_data = SS_COMMUNICATION_FAILURE;
1829 curlun->sense_data_info = file_offset >> 9; 1833 curlun->sense_data_info = file_offset >> 9;
1834 curlun->info_valid = 1;
1830 break; 1835 break;
1831 } 1836 }
1832 1837
@@ -1868,6 +1873,7 @@ static int do_write(struct fsg_dev *fsg)
1868 if (nwritten < amount) { 1873 if (nwritten < amount) {
1869 curlun->sense_data = SS_WRITE_ERROR; 1874 curlun->sense_data = SS_WRITE_ERROR;
1870 curlun->sense_data_info = file_offset >> 9; 1875 curlun->sense_data_info = file_offset >> 9;
1876 curlun->info_valid = 1;
1871 break; 1877 break;
1872 } 1878 }
1873 1879
@@ -2010,6 +2016,7 @@ static int do_verify(struct fsg_dev *fsg)
2010 curlun->sense_data = 2016 curlun->sense_data =
2011 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE; 2017 SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
2012 curlun->sense_data_info = file_offset >> 9; 2018 curlun->sense_data_info = file_offset >> 9;
2019 curlun->info_valid = 1;
2013 break; 2020 break;
2014 } 2021 }
2015 2022
@@ -2036,6 +2043,7 @@ static int do_verify(struct fsg_dev *fsg)
2036 if (nread == 0) { 2043 if (nread == 0) {
2037 curlun->sense_data = SS_UNRECOVERED_READ_ERROR; 2044 curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
2038 curlun->sense_data_info = file_offset >> 9; 2045 curlun->sense_data_info = file_offset >> 9;
2046 curlun->info_valid = 1;
2039 break; 2047 break;
2040 } 2048 }
2041 file_offset += nread; 2049 file_offset += nread;
@@ -2079,6 +2087,7 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2079 struct lun *curlun = fsg->curlun; 2087 struct lun *curlun = fsg->curlun;
2080 u8 *buf = (u8 *) bh->buf; 2088 u8 *buf = (u8 *) bh->buf;
2081 u32 sd, sdinfo; 2089 u32 sd, sdinfo;
2090 int valid;
2082 2091
2083 /* 2092 /*
2084 * From the SCSI-2 spec., section 7.9 (Unit attention condition): 2093 * From the SCSI-2 spec., section 7.9 (Unit attention condition):
@@ -2106,15 +2115,18 @@ static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
2106 fsg->bad_lun_okay = 1; 2115 fsg->bad_lun_okay = 1;
2107 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED; 2116 sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
2108 sdinfo = 0; 2117 sdinfo = 0;
2118 valid = 0;
2109 } else { 2119 } else {
2110 sd = curlun->sense_data; 2120 sd = curlun->sense_data;
2111 sdinfo = curlun->sense_data_info; 2121 sdinfo = curlun->sense_data_info;
2122 valid = curlun->info_valid << 7;
2112 curlun->sense_data = SS_NO_SENSE; 2123 curlun->sense_data = SS_NO_SENSE;
2113 curlun->sense_data_info = 0; 2124 curlun->sense_data_info = 0;
2125 curlun->info_valid = 0;
2114 } 2126 }
2115 2127
2116 memset(buf, 0, 18); 2128 memset(buf, 0, 18);
2117 buf[0] = 0x80 | 0x70; // Valid, current error 2129 buf[0] = valid | 0x70; // Valid, current error
2118 buf[2] = SK(sd); 2130 buf[2] = SK(sd);
2119 put_be32(&buf[3], sdinfo); // Sense information 2131 put_be32(&buf[3], sdinfo); // Sense information
2120 buf[7] = 18 - 8; // Additional sense length 2132 buf[7] = 18 - 8; // Additional sense length
@@ -2703,6 +2715,7 @@ static int check_command(struct fsg_dev *fsg, int cmnd_size,
2703 if (fsg->cmnd[0] != SC_REQUEST_SENSE) { 2715 if (fsg->cmnd[0] != SC_REQUEST_SENSE) {
2704 curlun->sense_data = SS_NO_SENSE; 2716 curlun->sense_data = SS_NO_SENSE;
2705 curlun->sense_data_info = 0; 2717 curlun->sense_data_info = 0;
2718 curlun->info_valid = 0;
2706 } 2719 }
2707 } else { 2720 } else {
2708 fsg->curlun = curlun = NULL; 2721 fsg->curlun = curlun = NULL;
@@ -3332,6 +3345,7 @@ static void handle_exception(struct fsg_dev *fsg)
3332 curlun->sense_data = curlun->unit_attention_data = 3345 curlun->sense_data = curlun->unit_attention_data =
3333 SS_NO_SENSE; 3346 SS_NO_SENSE;
3334 curlun->sense_data_info = 0; 3347 curlun->sense_data_info = 0;
3348 curlun->info_valid = 0;
3335 } 3349 }
3336 fsg->state = FSG_STATE_IDLE; 3350 fsg->state = FSG_STATE_IDLE;
3337 } 3351 }
@@ -3873,21 +3887,26 @@ static int __init fsg_bind(struct usb_gadget *gadget)
3873 for (i = 0; i < fsg->nluns; ++i) { 3887 for (i = 0; i < fsg->nluns; ++i) {
3874 curlun = &fsg->luns[i]; 3888 curlun = &fsg->luns[i];
3875 curlun->ro = mod_data.ro[i]; 3889 curlun->ro = mod_data.ro[i];
3890 curlun->dev.release = lun_release;
3876 curlun->dev.parent = &gadget->dev; 3891 curlun->dev.parent = &gadget->dev;
3877 curlun->dev.driver = &fsg_driver.driver; 3892 curlun->dev.driver = &fsg_driver.driver;
3878 dev_set_drvdata(&curlun->dev, fsg); 3893 dev_set_drvdata(&curlun->dev, fsg);
3879 snprintf(curlun->dev.bus_id, BUS_ID_SIZE, 3894 snprintf(curlun->dev.bus_id, BUS_ID_SIZE,
3880 "%s-lun%d", gadget->dev.bus_id, i); 3895 "%s-lun%d", gadget->dev.bus_id, i);
3881 3896
3882 if ((rc = device_register(&curlun->dev)) != 0) 3897 if ((rc = device_register(&curlun->dev)) != 0) {
3883 INFO(fsg, "failed to register LUN%d: %d\n", i, rc); 3898 INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
3884 else { 3899 goto out;
3885 curlun->registered = 1; 3900 }
3886 curlun->dev.release = lun_release; 3901 if ((rc = device_create_file(&curlun->dev,
3887 device_create_file(&curlun->dev, &dev_attr_ro); 3902 &dev_attr_ro)) != 0 ||
3888 device_create_file(&curlun->dev, &dev_attr_file); 3903 (rc = device_create_file(&curlun->dev,
3889 kref_get(&fsg->ref); 3904 &dev_attr_file)) != 0) {
3905 device_unregister(&curlun->dev);
3906 goto out;
3890 } 3907 }
3908 curlun->registered = 1;
3909 kref_get(&fsg->ref);
3891 3910
3892 if (mod_data.file[i] && *mod_data.file[i]) { 3911 if (mod_data.file[i] && *mod_data.file[i]) {
3893 if ((rc = open_backing_file(curlun, 3912 if ((rc = open_backing_file(curlun,
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 1027aa04583d..d1d68c402251 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -715,17 +715,8 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
715 return IRQ_NOTMINE; 715 return IRQ_NOTMINE;
716 } 716 }
717 717
718 /* NOTE: vendors didn't always make the same implementation
719 * choices for RHSC. Sometimes it triggers on an edge (like
720 * setting and maybe clearing a port status change bit); and
721 * it's level-triggered on other silicon, active until khubd
722 * clears all active port status change bits. Poll by timer
723 * til it's fully debounced and the difference won't matter.
724 */
725 if (ints & OHCI_INTR_RHSC) { 718 if (ints & OHCI_INTR_RHSC) {
726 ohci_vdbg (ohci, "rhsc\n"); 719 ohci_vdbg (ohci, "rhsc\n");
727 ohci_writel (ohci, OHCI_INTR_RHSC, &regs->intrdisable);
728 hcd->poll_rh = 1;
729 ohci->next_statechange = jiffies + STATECHANGE_DELAY; 720 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
730 ohci_writel (ohci, OHCI_INTR_RHSC, &regs->intrstatus); 721 ohci_writel (ohci, OHCI_INTR_RHSC, &regs->intrstatus);
731 usb_hcd_poll_rh_status(hcd); 722 usb_hcd_poll_rh_status(hcd);
@@ -743,13 +734,18 @@ static irqreturn_t ohci_irq (struct usb_hcd *hcd, struct pt_regs *ptregs)
743 if (ints & OHCI_INTR_RD) { 734 if (ints & OHCI_INTR_RD) {
744 ohci_vdbg (ohci, "resume detect\n"); 735 ohci_vdbg (ohci, "resume detect\n");
745 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus); 736 ohci_writel (ohci, OHCI_INTR_RD, &regs->intrstatus);
746 if (hcd->state != HC_STATE_QUIESCING) 737 hcd->poll_rh = 1;
738 if (ohci->autostop) {
739 spin_lock (&ohci->lock);
740 ohci_rh_resume (ohci);
741 spin_unlock (&ohci->lock);
742 } else
747 usb_hcd_resume_root_hub(hcd); 743 usb_hcd_resume_root_hub(hcd);
748 } 744 }
749 745
750 if (ints & OHCI_INTR_WDH) { 746 if (ints & OHCI_INTR_WDH) {
751 if (HC_IS_RUNNING(hcd->state)) 747 if (HC_IS_RUNNING(hcd->state))
752 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable); 748 ohci_writel (ohci, OHCI_INTR_WDH, &regs->intrdisable);
753 spin_lock (&ohci->lock); 749 spin_lock (&ohci->lock);
754 dl_done_list (ohci, ptregs); 750 dl_done_list (ohci, ptregs);
755 spin_unlock (&ohci->lock); 751 spin_unlock (&ohci->lock);
diff --git a/drivers/usb/host/ohci-hub.c b/drivers/usb/host/ohci-hub.c
index 0b899339cac8..ec75774abeac 100644
--- a/drivers/usb/host/ohci-hub.c
+++ b/drivers/usb/host/ohci-hub.c
@@ -44,27 +44,17 @@ static void ohci_rhsc_enable (struct usb_hcd *hcd)
44 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable); 44 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrenable);
45} 45}
46 46
47#ifdef CONFIG_PM
48
49#define OHCI_SCHED_ENABLES \ 47#define OHCI_SCHED_ENABLES \
50 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE) 48 (OHCI_CTRL_CLE|OHCI_CTRL_BLE|OHCI_CTRL_PLE|OHCI_CTRL_IE)
51 49
52static void dl_done_list (struct ohci_hcd *, struct pt_regs *); 50static void dl_done_list (struct ohci_hcd *, struct pt_regs *);
53static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *); 51static void finish_unlinks (struct ohci_hcd *, u16 , struct pt_regs *);
54static int ohci_restart (struct ohci_hcd *ohci);
55 52
56static int ohci_bus_suspend (struct usb_hcd *hcd) 53static int ohci_rh_suspend (struct ohci_hcd *ohci, int autostop)
54__releases(ohci->lock)
55__acquires(ohci->lock)
57{ 56{
58 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
59 int status = 0; 57 int status = 0;
60 unsigned long flags;
61
62 spin_lock_irqsave (&ohci->lock, flags);
63
64 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
65 spin_unlock_irqrestore (&ohci->lock, flags);
66 return -ESHUTDOWN;
67 }
68 58
69 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 59 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
70 switch (ohci->hc_control & OHCI_CTRL_HCFS) { 60 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
@@ -80,15 +70,16 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
80 ohci_dbg (ohci, "needs reinit!\n"); 70 ohci_dbg (ohci, "needs reinit!\n");
81 goto done; 71 goto done;
82 case OHCI_USB_SUSPEND: 72 case OHCI_USB_SUSPEND:
83 ohci_dbg (ohci, "already suspended\n"); 73 if (!ohci->autostop) {
84 goto done; 74 ohci_dbg (ohci, "already suspended\n");
75 goto done;
76 }
85 } 77 }
86 ohci_dbg (ohci, "suspend root hub\n"); 78 ohci_dbg (ohci, "%s root hub\n",
79 autostop ? "auto-stop" : "suspend");
87 80
88 /* First stop any processing */ 81 /* First stop any processing */
89 if (ohci->hc_control & OHCI_SCHED_ENABLES) { 82 if (!autostop && (ohci->hc_control & OHCI_SCHED_ENABLES)) {
90 int limit;
91
92 ohci->hc_control &= ~OHCI_SCHED_ENABLES; 83 ohci->hc_control &= ~OHCI_SCHED_ENABLES;
93 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 84 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
94 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 85 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
@@ -98,27 +89,22 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
98 * then the last WDH could take 6+ msec 89 * then the last WDH could take 6+ msec
99 */ 90 */
100 ohci_dbg (ohci, "stopping schedules ...\n"); 91 ohci_dbg (ohci, "stopping schedules ...\n");
101 limit = 2000; 92 ohci->autostop = 0;
102 while (limit > 0) { 93 spin_unlock_irq (&ohci->lock);
103 udelay (250); 94 msleep (8);
104 limit =- 250; 95 spin_lock_irq (&ohci->lock);
105 if (ohci_readl (ohci, &ohci->regs->intrstatus)
106 & OHCI_INTR_SF)
107 break;
108 }
109 dl_done_list (ohci, NULL);
110 mdelay (7);
111 } 96 }
112 dl_done_list (ohci, NULL); 97 dl_done_list (ohci, NULL);
113 finish_unlinks (ohci, ohci_frame_no(ohci), NULL); 98 finish_unlinks (ohci, ohci_frame_no(ohci), NULL);
114 ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
115 &ohci->regs->intrstatus);
116 99
117 /* maybe resume can wake root hub */ 100 /* maybe resume can wake root hub */
118 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev)) 101 if (device_may_wakeup(&ohci_to_hcd(ohci)->self.root_hub->dev) ||
102 autostop)
119 ohci->hc_control |= OHCI_CTRL_RWE; 103 ohci->hc_control |= OHCI_CTRL_RWE;
120 else 104 else {
105 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
121 ohci->hc_control &= ~OHCI_CTRL_RWE; 106 ohci->hc_control &= ~OHCI_CTRL_RWE;
107 }
122 108
123 /* Suspend hub ... this is the "global (to this bus) suspend" mode, 109 /* Suspend hub ... this is the "global (to this bus) suspend" mode,
124 * which doesn't imply ports will first be individually suspended. 110 * which doesn't imply ports will first be individually suspended.
@@ -129,13 +115,12 @@ static int ohci_bus_suspend (struct usb_hcd *hcd)
129 (void) ohci_readl (ohci, &ohci->regs->control); 115 (void) ohci_readl (ohci, &ohci->regs->control);
130 116
131 /* no resumes until devices finish suspending */ 117 /* no resumes until devices finish suspending */
132 ohci->next_statechange = jiffies + msecs_to_jiffies (5); 118 if (!autostop) {
133 119 ohci->next_statechange = jiffies + msecs_to_jiffies (5);
134 /* no timer polling */ 120 ohci->autostop = 0;
135 hcd->poll_rh = 0; 121 }
136 122
137done: 123done:
138 spin_unlock_irqrestore (&ohci->lock, flags);
139 return status; 124 return status;
140} 125}
141 126
@@ -147,25 +132,19 @@ static inline struct ed *find_head (struct ed *ed)
147 return ed; 132 return ed;
148} 133}
149 134
135static int ohci_restart (struct ohci_hcd *ohci);
136
150/* caller has locked the root hub */ 137/* caller has locked the root hub */
151static int ohci_bus_resume (struct usb_hcd *hcd) 138static int ohci_rh_resume (struct ohci_hcd *ohci)
139__releases(ohci->lock)
140__acquires(ohci->lock)
152{ 141{
153 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 142 struct usb_hcd *hcd = ohci_to_hcd (ohci);
154 u32 temp, enables; 143 u32 temp, enables;
155 int status = -EINPROGRESS; 144 int status = -EINPROGRESS;
156 unsigned long flags; 145 int autostopped = ohci->autostop;
157
158 if (time_before (jiffies, ohci->next_statechange))
159 msleep(5);
160
161 spin_lock_irqsave (&ohci->lock, flags);
162
163 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))) {
164 spin_unlock_irqrestore (&ohci->lock, flags);
165 return -ESHUTDOWN;
166 }
167
168 146
147 ohci->autostop = 0;
169 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control); 148 ohci->hc_control = ohci_readl (ohci, &ohci->regs->control);
170 149
171 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) { 150 if (ohci->hc_control & (OHCI_CTRL_IR | OHCI_SCHED_ENABLES)) {
@@ -185,7 +164,8 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
185 ohci->hc_control |= OHCI_USB_RESUME; 164 ohci->hc_control |= OHCI_USB_RESUME;
186 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); 165 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
187 (void) ohci_readl (ohci, &ohci->regs->control); 166 (void) ohci_readl (ohci, &ohci->regs->control);
188 ohci_dbg (ohci, "resume root hub\n"); 167 ohci_dbg (ohci, "%s root hub\n",
168 autostopped ? "auto-start" : "resume");
189 break; 169 break;
190 case OHCI_USB_RESUME: 170 case OHCI_USB_RESUME:
191 /* HCFS changes sometime after INTR_RD */ 171 /* HCFS changes sometime after INTR_RD */
@@ -200,16 +180,24 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
200 ohci_dbg (ohci, "lost power\n"); 180 ohci_dbg (ohci, "lost power\n");
201 status = -EBUSY; 181 status = -EBUSY;
202 } 182 }
203 spin_unlock_irqrestore (&ohci->lock, flags); 183#ifdef CONFIG_PM
204 if (status == -EBUSY) { 184 if (status == -EBUSY) {
205 (void) ohci_init (ohci); 185 if (!autostopped) {
206 return ohci_restart (ohci); 186 spin_unlock_irq (&ohci->lock);
187 (void) ohci_init (ohci);
188 status = ohci_restart (ohci);
189 spin_lock_irq (&ohci->lock);
190 }
191 return status;
207 } 192 }
193#endif
208 if (status != -EINPROGRESS) 194 if (status != -EINPROGRESS)
209 return status; 195 return status;
196 if (autostopped)
197 goto skip_resume;
198 spin_unlock_irq (&ohci->lock);
210 199
211 temp = ohci->num_ports; 200 temp = ohci->num_ports;
212 enables = 0;
213 while (temp--) { 201 while (temp--) {
214 u32 stat = ohci_readl (ohci, 202 u32 stat = ohci_readl (ohci,
215 &ohci->regs->roothub.portstatus [temp]); 203 &ohci->regs->roothub.portstatus [temp]);
@@ -242,17 +230,21 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
242 /* Sometimes PCI D3 suspend trashes frame timings ... */ 230 /* Sometimes PCI D3 suspend trashes frame timings ... */
243 periodic_reinit (ohci); 231 periodic_reinit (ohci);
244 232
233 /* the following code is executed with ohci->lock held and
234 * irqs disabled if and only if autostopped is true
235 */
236
237skip_resume:
245 /* interrupts might have been disabled */ 238 /* interrupts might have been disabled */
246 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable); 239 ohci_writel (ohci, OHCI_INTR_INIT, &ohci->regs->intrenable);
247 if (ohci->ed_rm_list) 240 if (ohci->ed_rm_list)
248 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); 241 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
249 ohci_writel (ohci, ohci_readl (ohci, &ohci->regs->intrstatus),
250 &ohci->regs->intrstatus);
251 242
252 /* Then re-enable operations */ 243 /* Then re-enable operations */
253 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control); 244 ohci_writel (ohci, OHCI_USB_OPER, &ohci->regs->control);
254 (void) ohci_readl (ohci, &ohci->regs->control); 245 (void) ohci_readl (ohci, &ohci->regs->control);
255 msleep (3); 246 if (!autostopped)
247 msleep (3);
256 248
257 temp = ohci->hc_control; 249 temp = ohci->hc_control;
258 temp &= OHCI_CTRL_RWC; 250 temp &= OHCI_CTRL_RWC;
@@ -262,7 +254,11 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
262 (void) ohci_readl (ohci, &ohci->regs->control); 254 (void) ohci_readl (ohci, &ohci->regs->control);
263 255
264 /* TRSMRCY */ 256 /* TRSMRCY */
265 msleep (10); 257 if (!autostopped) {
258 msleep (10);
259 spin_lock_irq (&ohci->lock);
260 }
261 /* now ohci->lock is always held and irqs are always disabled */
266 262
267 /* keep it alive for more than ~5x suspend + resume costs */ 263 /* keep it alive for more than ~5x suspend + resume costs */
268 ohci->next_statechange = jiffies + STATECHANGE_DELAY; 264 ohci->next_statechange = jiffies + STATECHANGE_DELAY;
@@ -299,6 +295,45 @@ static int ohci_bus_resume (struct usb_hcd *hcd)
299 return 0; 295 return 0;
300} 296}
301 297
298#ifdef CONFIG_PM
299
300static int ohci_bus_suspend (struct usb_hcd *hcd)
301{
302 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
303 int rc;
304
305 spin_lock_irq (&ohci->lock);
306
307 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
308 rc = -ESHUTDOWN;
309 else
310 rc = ohci_rh_suspend (ohci, 0);
311 spin_unlock_irq (&ohci->lock);
312 return rc;
313}
314
315static int ohci_bus_resume (struct usb_hcd *hcd)
316{
317 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
318 int rc;
319
320 if (time_before (jiffies, ohci->next_statechange))
321 msleep(5);
322
323 spin_lock_irq (&ohci->lock);
324
325 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
326 rc = -ESHUTDOWN;
327 else
328 rc = ohci_rh_resume (ohci);
329 spin_unlock_irq (&ohci->lock);
330
331 /* poll until we know a device is connected or we autostop */
332 if (rc == 0)
333 usb_hcd_poll_rh_status(hcd);
334 return rc;
335}
336
302#endif /* CONFIG_PM */ 337#endif /* CONFIG_PM */
303 338
304/*-------------------------------------------------------------------------*/ 339/*-------------------------------------------------------------------------*/
@@ -310,21 +345,11 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
310{ 345{
311 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 346 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
312 int i, changed = 0, length = 1; 347 int i, changed = 0, length = 1;
313 int can_suspend; 348 int any_connected = 0, rhsc_enabled = 1;
314 unsigned long flags; 349 unsigned long flags;
315 350
316 can_suspend = device_may_wakeup(&hcd->self.root_hub->dev);
317 spin_lock_irqsave (&ohci->lock, flags); 351 spin_lock_irqsave (&ohci->lock, flags);
318 352
319 /* handle autosuspended root: finish resuming before
320 * letting khubd or root hub timer see state changes.
321 */
322 if (unlikely((ohci->hc_control & OHCI_CTRL_HCFS) != OHCI_USB_OPER
323 || !HC_IS_RUNNING(hcd->state))) {
324 can_suspend = 0;
325 goto done;
326 }
327
328 /* undocumented erratum seen on at least rev D */ 353 /* undocumented erratum seen on at least rev D */
329 if ((ohci->flags & OHCI_QUIRK_AMD756) 354 if ((ohci->flags & OHCI_QUIRK_AMD756)
330 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) { 355 && (roothub_a (ohci) & RH_A_NDP) > MAX_ROOT_PORTS) {
@@ -348,9 +373,8 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
348 for (i = 0; i < ohci->num_ports; i++) { 373 for (i = 0; i < ohci->num_ports; i++) {
349 u32 status = roothub_portstatus (ohci, i); 374 u32 status = roothub_portstatus (ohci, i);
350 375
351 /* can't autosuspend with active ports */ 376 /* can't autostop if ports are connected */
352 if ((status & RH_PS_PES) && !(status & RH_PS_PSS)) 377 any_connected |= (status & RH_PS_CCS);
353 can_suspend = 0;
354 378
355 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC 379 if (status & (RH_PS_CSC | RH_PS_PESC | RH_PS_PSSC
356 | RH_PS_OCIC | RH_PS_PRSC)) { 380 | RH_PS_OCIC | RH_PS_PRSC)) {
@@ -359,49 +383,73 @@ ohci_hub_status_data (struct usb_hcd *hcd, char *buf)
359 buf [0] |= 1 << (i + 1); 383 buf [0] |= 1 << (i + 1);
360 else 384 else
361 buf [1] |= 1 << (i - 7); 385 buf [1] |= 1 << (i - 7);
362 continue;
363 } 386 }
364 } 387 }
365 388
366 /* after root hub changes, stop polling after debouncing 389 /* NOTE: vendors didn't always make the same implementation
367 * for a while and maybe kicking in autosuspend 390 * choices for RHSC. Sometimes it triggers on an edge (like
391 * setting and maybe clearing a port status change bit); and
392 * it's level-triggered on other silicon, active until khubd
393 * clears all active port status change bits. If it's still
394 * set (level-triggered) we must disable it and rely on
395 * polling until khubd re-enables it.
368 */ 396 */
369 if (changed) { 397 if (ohci_readl (ohci, &ohci->regs->intrstatus) & OHCI_INTR_RHSC) {
370 ohci->next_statechange = jiffies + STATECHANGE_DELAY; 398 ohci_writel (ohci, OHCI_INTR_RHSC, &ohci->regs->intrdisable);
371 can_suspend = 0; 399 (void) ohci_readl (ohci, &ohci->regs->intrdisable);
372 } else if (time_before (jiffies, ohci->next_statechange)) { 400 rhsc_enabled = 0;
373 can_suspend = 0; 401 }
374 } else { 402 hcd->poll_rh = 1;
375#ifdef CONFIG_PM 403
376 can_suspend = can_suspend 404 /* carry out appropriate state changes */
377 && !ohci->ed_rm_list 405 switch (ohci->hc_control & OHCI_CTRL_HCFS) {
378 && ((OHCI_CTRL_HCFS | OHCI_SCHED_ENABLES) 406
379 & ohci->hc_control) 407 case OHCI_USB_OPER:
380 == OHCI_USB_OPER; 408 /* keep on polling until we know a device is connected
381#endif 409 * and RHSC is enabled */
382 if (hcd->uses_new_polling) { 410 if (!ohci->autostop) {
411 if (any_connected) {
412 if (rhsc_enabled)
413 hcd->poll_rh = 0;
414 } else {
415 ohci->autostop = 1;
416 ohci->next_statechange = jiffies + HZ;
417 }
418
419 /* if no devices have been attached for one second, autostop */
420 } else {
421 if (changed || any_connected) {
422 ohci->autostop = 0;
423 ohci->next_statechange = jiffies +
424 STATECHANGE_DELAY;
425 } else if (time_after_eq (jiffies,
426 ohci->next_statechange)
427 && !ohci->ed_rm_list
428 && !(ohci->hc_control &
429 OHCI_SCHED_ENABLES)) {
430 ohci_rh_suspend (ohci, 1);
431 }
432 }
433 break;
434
435 /* if there is a port change, autostart or ask to be resumed */
436 case OHCI_USB_SUSPEND:
437 case OHCI_USB_RESUME:
438 if (changed) {
439 if (ohci->autostop)
440 ohci_rh_resume (ohci);
441 else
442 usb_hcd_resume_root_hub (hcd);
443 } else {
444 /* everything is idle, no need for polling */
383 hcd->poll_rh = 0; 445 hcd->poll_rh = 0;
384 /* use INTR_RHSC iff INTR_RD won't apply */
385 if (!can_suspend)
386 ohci_writel (ohci, OHCI_INTR_RHSC,
387 &ohci->regs->intrenable);
388 } 446 }
447 break;
389 } 448 }
390 449
391done: 450done:
392 spin_unlock_irqrestore (&ohci->lock, flags); 451 spin_unlock_irqrestore (&ohci->lock, flags);
393 452
394#ifdef CONFIG_PM
395 /* save power by autosuspending idle root hubs;
396 * INTR_RD wakes us when there's work
397 */
398 if (can_suspend && usb_trylock_device (hcd->self.root_hub) == 0) {
399 ohci_vdbg (ohci, "autosuspend\n");
400 (void) ohci_bus_suspend (hcd);
401 usb_unlock_device (hcd->self.root_hub);
402 }
403#endif
404
405 return changed ? length : 0; 453 return changed ? length : 0;
406} 454}
407 455
@@ -572,9 +620,6 @@ static int ohci_hub_control (
572 break; 620 break;
573 case USB_PORT_FEAT_SUSPEND: 621 case USB_PORT_FEAT_SUSPEND:
574 temp = RH_PS_POCI; 622 temp = RH_PS_POCI;
575 if ((ohci->hc_control & OHCI_CTRL_HCFS)
576 != OHCI_USB_OPER)
577 usb_hcd_resume_root_hub(hcd);
578 break; 623 break;
579 case USB_PORT_FEAT_C_SUSPEND: 624 case USB_PORT_FEAT_C_SUSPEND:
580 temp = RH_PS_PSSC; 625 temp = RH_PS_PSSC;
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c
index 3732db7d68eb..874418552789 100644
--- a/drivers/usb/host/ohci-pci.c
+++ b/drivers/usb/host/ohci-pci.c
@@ -73,13 +73,14 @@ ohci_pci_start (struct usb_hcd *hcd)
73 else if (pdev->vendor == PCI_VENDOR_ID_NS) { 73 else if (pdev->vendor == PCI_VENDOR_ID_NS) {
74 struct pci_dev *b; 74 struct pci_dev *b;
75 75
76 b = pci_find_slot (pdev->bus->number, 76 b = pci_get_slot (pdev->bus,
77 PCI_DEVFN (PCI_SLOT (pdev->devfn), 1)); 77 PCI_DEVFN (PCI_SLOT (pdev->devfn), 1));
78 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO 78 if (b && b->device == PCI_DEVICE_ID_NS_87560_LIO
79 && b->vendor == PCI_VENDOR_ID_NS) { 79 && b->vendor == PCI_VENDOR_ID_NS) {
80 ohci->flags |= OHCI_QUIRK_SUPERIO; 80 ohci->flags |= OHCI_QUIRK_SUPERIO;
81 ohci_dbg (ohci, "Using NSC SuperIO setup\n"); 81 ohci_dbg (ohci, "Using NSC SuperIO setup\n");
82 } 82 }
83 pci_dev_put(b);
83 } 84 }
84 85
85 /* Check for Compaq's ZFMicro chipset, which needs short 86 /* Check for Compaq's ZFMicro chipset, which needs short
diff --git a/drivers/usb/host/ohci.h b/drivers/usb/host/ohci.h
index 93fdc3c35341..a2f42a2f47c6 100644
--- a/drivers/usb/host/ohci.h
+++ b/drivers/usb/host/ohci.h
@@ -388,6 +388,7 @@ struct ohci_hcd {
388 u32 hc_control; /* copy of hc control reg */ 388 u32 hc_control; /* copy of hc control reg */
389 unsigned long next_statechange; /* suspend/resume */ 389 unsigned long next_statechange; /* suspend/resume */
390 u32 fminterval; /* saved register */ 390 u32 fminterval; /* saved register */
391 unsigned autostop:1; /* rh auto stopping/stopped */
391 392
392 unsigned long flags; /* for HC bugs */ 393 unsigned long flags; /* for HC bugs */
393#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */ 394#define OHCI_QUIRK_AMD756 0x01 /* erratum #4 */
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index b2bafc37c414..5f861331932a 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -225,7 +225,7 @@ static inline void mts_debug_dump(struct mts_desc* desc) {
225} 225}
226 226
227 227
228static inline void mts_show_command(Scsi_Cmnd *srb) 228static inline void mts_show_command(struct scsi_cmnd *srb)
229{ 229{
230 char *what = NULL; 230 char *what = NULL;
231 231
@@ -309,7 +309,7 @@ static inline void mts_show_command(Scsi_Cmnd *srb)
309 309
310#else 310#else
311 311
312static inline void mts_show_command(Scsi_Cmnd * dummy) 312static inline void mts_show_command(struct scsi_cmnd * dummy)
313{ 313{
314} 314}
315 315
@@ -338,7 +338,7 @@ static int mts_slave_configure (struct scsi_device *s)
338 return 0; 338 return 0;
339} 339}
340 340
341static int mts_scsi_abort (Scsi_Cmnd *srb) 341static int mts_scsi_abort(struct scsi_cmnd *srb)
342{ 342{
343 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 343 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
344 344
@@ -349,7 +349,7 @@ static int mts_scsi_abort (Scsi_Cmnd *srb)
349 return FAILED; 349 return FAILED;
350} 350}
351 351
352static int mts_scsi_host_reset (Scsi_Cmnd *srb) 352static int mts_scsi_host_reset(struct scsi_cmnd *srb)
353{ 353{
354 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 354 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
355 int result, rc; 355 int result, rc;
@@ -366,8 +366,8 @@ static int mts_scsi_host_reset (Scsi_Cmnd *srb)
366 return result ? FAILED : SUCCESS; 366 return result ? FAILED : SUCCESS;
367} 367}
368 368
369static 369static int
370int mts_scsi_queuecommand (Scsi_Cmnd *srb, mts_scsi_cmnd_callback callback ); 370mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback);
371 371
372static void mts_transfer_cleanup( struct urb *transfer ); 372static void mts_transfer_cleanup( struct urb *transfer );
373static void mts_do_sg(struct urb * transfer, struct pt_regs *regs); 373static void mts_do_sg(struct urb * transfer, struct pt_regs *regs);
@@ -537,7 +537,7 @@ static const unsigned char mts_direction[256/8] = {
537#define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1) 537#define MTS_DIRECTION_IS_IN(x) ((mts_direction[x>>3] >> (x & 7)) & 1)
538 538
539static void 539static void
540mts_build_transfer_context( Scsi_Cmnd *srb, struct mts_desc* desc ) 540mts_build_transfer_context(struct scsi_cmnd *srb, struct mts_desc* desc)
541{ 541{
542 int pipe; 542 int pipe;
543 struct scatterlist * sg; 543 struct scatterlist * sg;
@@ -588,8 +588,8 @@ mts_build_transfer_context( Scsi_Cmnd *srb, struct mts_desc* desc )
588} 588}
589 589
590 590
591static 591static int
592int mts_scsi_queuecommand( Scsi_Cmnd *srb, mts_scsi_cmnd_callback callback ) 592mts_scsi_queuecommand(struct scsi_cmnd *srb, mts_scsi_cmnd_callback callback)
593{ 593{
594 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]); 594 struct mts_desc* desc = (struct mts_desc*)(srb->device->host->hostdata[0]);
595 int err = 0; 595 int err = 0;
diff --git a/drivers/usb/image/microtek.h b/drivers/usb/image/microtek.h
index 926d4bdc6746..d5d62a939058 100644
--- a/drivers/usb/image/microtek.h
+++ b/drivers/usb/image/microtek.h
@@ -8,14 +8,14 @@
8 * 8 *
9 */ 9 */
10 10
11typedef void (*mts_scsi_cmnd_callback)(Scsi_Cmnd *); 11typedef void (*mts_scsi_cmnd_callback)(struct scsi_cmnd *);
12 12
13 13
14struct mts_transfer_context 14struct mts_transfer_context
15{ 15{
16 struct mts_desc* instance; 16 struct mts_desc* instance;
17 mts_scsi_cmnd_callback final_callback; 17 mts_scsi_cmnd_callback final_callback;
18 Scsi_Cmnd *srb; 18 struct scsi_cmnd *srb;
19 19
20 void* data; 20 void* data;
21 unsigned data_length; 21 unsigned data_length;
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 2a3e9e9b4b3d..81b1ea01a172 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -1600,6 +1600,9 @@ void hid_init_reports(struct hid_device *hid)
1600#define USB_VENDOR_ID_ALCOR 0x058f 1600#define USB_VENDOR_ID_ALCOR 0x058f
1601#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720 1601#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
1602 1602
1603#define USB_VENDOR_ID_SUN 0x0430
1604#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
1605
1603/* 1606/*
1604 * Alphabetically sorted blacklist by quirk type. 1607 * Alphabetically sorted blacklist by quirk type.
1605 */ 1608 */
@@ -1729,6 +1732,7 @@ static const struct hid_blacklist {
1729 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 1732 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
1730 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 1733 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
1731 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 1734 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
1735 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
1732 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1736 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1733 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 1737 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
1734 1738
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index 9a8d137d39f9..78e419904abf 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -44,20 +44,25 @@ struct driver_interfacekit {
44 int inputs; 44 int inputs;
45 int outputs; 45 int outputs;
46 int has_lcd; 46 int has_lcd;
47 int amnesiac;
47}; 48};
48#define ifkit(_sensors, _inputs, _outputs, _lcd) \ 49
49static struct driver_interfacekit ph_##_sensors##_inputs##_outputs = { \ 50#define ifkit(_sensors, _inputs, _outputs, _lcd, _amnesiac) \
51{ \
50 .sensors = _sensors, \ 52 .sensors = _sensors, \
51 .inputs = _inputs, \ 53 .inputs = _inputs, \
52 .outputs = _outputs, \ 54 .outputs = _outputs, \
53 .has_lcd = _lcd, \ 55 .has_lcd = _lcd, \
56 .amnesiac = _amnesiac \
54}; 57};
55ifkit(0, 0, 4, 0); 58
56ifkit(8, 8, 8, 0); 59static const struct driver_interfacekit ph_004 = ifkit(0, 0, 4, 0, 0);
57ifkit(0, 4, 7, 1); 60static const struct driver_interfacekit ph_888n = ifkit(8, 8, 8, 0, 1);
58ifkit(8, 8, 4, 0); 61static const struct driver_interfacekit ph_888o = ifkit(8, 8, 8, 0, 0);
59ifkit(0, 8, 8, 1); 62static const struct driver_interfacekit ph_047 = ifkit(0, 4, 7, 1, 0);
60ifkit(0, 16, 16, 0); 63static const struct driver_interfacekit ph_884 = ifkit(8, 8, 4, 0, 0);
64static const struct driver_interfacekit ph_088 = ifkit(0, 8, 8, 1, 0);
65static const struct driver_interfacekit ph_01616 = ifkit(0, 16, 16, 0, 0);
61 66
62static unsigned long device_no; 67static unsigned long device_no;
63 68
@@ -77,6 +82,7 @@ struct interfacekit {
77 dma_addr_t data_dma; 82 dma_addr_t data_dma;
78 83
79 struct work_struct do_notify; 84 struct work_struct do_notify;
85 struct work_struct do_resubmit;
80 unsigned long input_events; 86 unsigned long input_events;
81 unsigned long sensor_events; 87 unsigned long sensor_events;
82}; 88};
@@ -84,8 +90,10 @@ struct interfacekit {
84static struct usb_device_id id_table[] = { 90static struct usb_device_id id_table[] = {
85 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004), 91 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004),
86 .driver_info = (kernel_ulong_t)&ph_004}, 92 .driver_info = (kernel_ulong_t)&ph_004},
87 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888), 93 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0, 0x814),
88 .driver_info = (kernel_ulong_t)&ph_888}, 94 .driver_info = (kernel_ulong_t)&ph_888o},
95 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0x0815, 0xffff),
96 .driver_info = (kernel_ulong_t)&ph_888n},
89 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047), 97 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047),
90 .driver_info = (kernel_ulong_t)&ph_047}, 98 .driver_info = (kernel_ulong_t)&ph_047},
91 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088), 99 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088),
@@ -98,16 +106,11 @@ static struct usb_device_id id_table[] = {
98}; 106};
99MODULE_DEVICE_TABLE(usb, id_table); 107MODULE_DEVICE_TABLE(usb, id_table);
100 108
101static int change_outputs(struct interfacekit *kit, int output_num, int enable) 109static int set_outputs(struct interfacekit *kit)
102{ 110{
103 u8 *buffer; 111 u8 *buffer;
104 int retval; 112 int retval;
105 113
106 if (enable)
107 set_bit(output_num, &kit->outputs);
108 else
109 clear_bit(output_num, &kit->outputs);
110
111 buffer = kzalloc(4, GFP_KERNEL); 114 buffer = kzalloc(4, GFP_KERNEL);
112 if (!buffer) { 115 if (!buffer) {
113 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__); 116 dev_err(&kit->udev->dev, "%s - out of memory\n", __FUNCTION__);
@@ -127,6 +130,9 @@ static int change_outputs(struct interfacekit *kit, int output_num, int enable)
127 retval); 130 retval);
128 kfree(buffer); 131 kfree(buffer);
129 132
133 if (kit->ifkit->amnesiac)
134 schedule_delayed_work(&kit->do_resubmit, HZ / 2);
135
130 return retval < 0 ? retval : 0; 136 return retval < 0 ? retval : 0;
131} 137}
132 138
@@ -399,19 +405,29 @@ static void do_notify(void *data)
399 } 405 }
400} 406}
401 407
408static void do_resubmit(void *data)
409{
410 set_outputs(data);
411}
412
402#define show_set_output(value) \ 413#define show_set_output(value) \
403static ssize_t set_output##value(struct device *dev, \ 414static ssize_t set_output##value(struct device *dev, \
404 struct device_attribute *attr, \ 415 struct device_attribute *attr, \
405 const char *buf, size_t count) \ 416 const char *buf, size_t count) \
406{ \ 417{ \
407 struct interfacekit *kit = dev_get_drvdata(dev); \ 418 struct interfacekit *kit = dev_get_drvdata(dev); \
408 int enabled; \ 419 int enable; \
409 int retval; \ 420 int retval; \
410 \ 421 \
411 if (sscanf(buf, "%d", &enabled) < 1) \ 422 if (sscanf(buf, "%d", &enable) < 1) \
412 return -EINVAL; \ 423 return -EINVAL; \
413 \ 424 \
414 retval = change_outputs(kit, value - 1, enabled); \ 425 if (enable) \
426 set_bit(value - 1, &kit->outputs); \
427 else \
428 clear_bit(value - 1, &kit->outputs); \
429 \
430 retval = set_outputs(kit); \
415 \ 431 \
416 return retval ? retval : count; \ 432 return retval ? retval : count; \
417} \ 433} \
@@ -560,6 +576,7 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
560 kit->udev = usb_get_dev(dev); 576 kit->udev = usb_get_dev(dev);
561 kit->intf = intf; 577 kit->intf = intf;
562 INIT_WORK(&kit->do_notify, do_notify, kit); 578 INIT_WORK(&kit->do_notify, do_notify, kit);
579 INIT_WORK(&kit->do_resubmit, do_resubmit, kit);
563 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data, 580 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data,
564 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp, 581 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
565 interfacekit_irq, kit, endpoint->bInterval); 582 interfacekit_irq, kit, endpoint->bInterval);
@@ -663,6 +680,7 @@ static void interfacekit_disconnect(struct usb_interface *interface)
663 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma); 680 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma);
664 681
665 cancel_delayed_work(&kit->do_notify); 682 cancel_delayed_work(&kit->do_notify);
683 cancel_delayed_work(&kit->do_resubmit);
666 684
667 for (i=0; i<kit->ifkit->outputs; i++) 685 for (i=0; i<kit->ifkit->outputs; i++)
668 device_remove_file(kit->dev, &dev_output_attrs[i]); 686 device_remove_file(kit->dev, &dev_output_attrs[i]);
diff --git a/drivers/usb/net/asix.c b/drivers/usb/net/asix.c
index 9b97aa6384c7..9c0eacf7055c 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/usb/net/asix.c
@@ -1456,6 +1456,10 @@ static const struct usb_device_id products [] = {
1456 USB_DEVICE (0x07d1, 0x3c05), 1456 USB_DEVICE (0x07d1, 0x3c05),
1457 .driver_info = (unsigned long) &ax88772_info, 1457 .driver_info = (unsigned long) &ax88772_info,
1458}, { 1458}, {
1459 // DLink DUB-E100 H/W Ver B1 Alternate
1460 USB_DEVICE (0x2001, 0x3c05),
1461 .driver_info = (unsigned long) &ax88772_info,
1462}, {
1459 // Linksys USB1000 1463 // Linksys USB1000
1460 USB_DEVICE (0x1737, 0x0039), 1464 USB_DEVICE (0x1737, 0x0039),
1461 .driver_info = (unsigned long) &ax88178_info, 1465 .driver_info = (unsigned long) &ax88178_info,
diff --git a/drivers/usb/net/kaweth.c b/drivers/usb/net/kaweth.c
index def3bb8e2290..544d41fe9b92 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/usb/net/kaweth.c
@@ -165,6 +165,7 @@ static struct usb_device_id usb_klsi_table[] = {
165 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */ 165 { USB_DEVICE(0x1645, 0x0005) }, /* Entrega E45 */
166 { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */ 166 { USB_DEVICE(0x1645, 0x0008) }, /* Entrega USB Ethernet Adapter */
167 { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */ 167 { USB_DEVICE(0x1645, 0x8005) }, /* PortGear Ethernet Adapter */
168 { USB_DEVICE(0x1668, 0x0323) }, /* Actiontec USB Ethernet */
168 { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */ 169 { USB_DEVICE(0x2001, 0x4000) }, /* D-link DSB-650C */
169 {} /* Null terminator */ 170 {} /* Null terminator */
170}; 171};
diff --git a/drivers/usb/net/pegasus.c b/drivers/usb/net/pegasus.c
index b8e25af13f02..918cf5a77c08 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/usb/net/pegasus.c
@@ -45,7 +45,7 @@
45/* 45/*
46 * Version Information 46 * Version Information
47 */ 47 */
48#define DRIVER_VERSION "v0.6.13 (2005/11/13)" 48#define DRIVER_VERSION "v0.6.14 (2006/09/27)"
49#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>" 49#define DRIVER_AUTHOR "Petko Manolov <petkan@users.sourceforge.net>"
50#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver" 50#define DRIVER_DESC "Pegasus/Pegasus II USB Ethernet driver"
51 51
@@ -339,7 +339,7 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
339 } 339 }
340fail: 340fail:
341 if (netif_msg_drv(pegasus)) 341 if (netif_msg_drv(pegasus))
342 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 342 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
343 343
344 return ret; 344 return ret;
345} 345}
@@ -376,7 +376,7 @@ static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
376 376
377fail: 377fail:
378 if (netif_msg_drv(pegasus)) 378 if (netif_msg_drv(pegasus))
379 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 379 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
380 return -ETIMEDOUT; 380 return -ETIMEDOUT;
381} 381}
382 382
@@ -413,7 +413,7 @@ static int read_eprom_word(pegasus_t * pegasus, __u8 index, __u16 * retdata)
413 413
414fail: 414fail:
415 if (netif_msg_drv(pegasus)) 415 if (netif_msg_drv(pegasus))
416 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 416 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
417 return -ETIMEDOUT; 417 return -ETIMEDOUT;
418} 418}
419 419
@@ -461,7 +461,7 @@ static int write_eprom_word(pegasus_t * pegasus, __u8 index, __u16 data)
461 return ret; 461 return ret;
462fail: 462fail:
463 if (netif_msg_drv(pegasus)) 463 if (netif_msg_drv(pegasus))
464 dev_warn(&pegasus->intf->dev, "fail %s\n", __FUNCTION__); 464 dev_warn(&pegasus->intf->dev, "%s failed\n", __FUNCTION__);
465 return -ETIMEDOUT; 465 return -ETIMEDOUT;
466} 466}
467#endif /* PEGASUS_WRITE_EEPROM */ 467#endif /* PEGASUS_WRITE_EEPROM */
@@ -481,8 +481,12 @@ static void set_ethernet_addr(pegasus_t * pegasus)
481{ 481{
482 __u8 node_id[6]; 482 __u8 node_id[6];
483 483
484 get_node_id(pegasus, node_id); 484 if (pegasus->features & PEGASUS_II) {
485 set_registers(pegasus, EthID, sizeof (node_id), node_id); 485 get_registers(pegasus, 0x10, sizeof(node_id), node_id);
486 } else {
487 get_node_id(pegasus, node_id);
488 set_registers(pegasus, EthID, sizeof (node_id), node_id);
489 }
486 memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id)); 490 memcpy(pegasus->net->dev_addr, node_id, sizeof (node_id));
487} 491}
488 492
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index 6286aba86fae..d954ec34b018 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -214,14 +214,14 @@ static int cyberjack_write (struct usb_serial_port *port, const unsigned char *b
214 return (0); 214 return (0);
215 } 215 }
216 216
217 spin_lock(&port->lock); 217 spin_lock_bh(&port->lock);
218 if (port->write_urb_busy) { 218 if (port->write_urb_busy) {
219 spin_unlock(&port->lock); 219 spin_unlock_bh(&port->lock);
220 dbg("%s - already writing", __FUNCTION__); 220 dbg("%s - already writing", __FUNCTION__);
221 return 0; 221 return 0;
222 } 222 }
223 port->write_urb_busy = 1; 223 port->write_urb_busy = 1;
224 spin_unlock(&port->lock); 224 spin_unlock_bh(&port->lock);
225 225
226 spin_lock_irqsave(&priv->lock, flags); 226 spin_lock_irqsave(&priv->lock, flags);
227 227
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 1f7b72553f37..e774a27c6c98 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -344,6 +344,7 @@ static struct usb_device_id id_table_combined [] = {
344 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) }, 344 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2102_PID) },
345 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) }, 345 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2103_PID) },
346 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) }, 346 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2104_PID) },
347 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2106_PID) },
347 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) }, 348 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_1_PID) },
348 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) }, 349 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2201_2_PID) },
349 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) }, 350 { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2202_1_PID) },
@@ -507,6 +508,9 @@ static struct usb_device_id id_table_combined [] = {
507 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) }, 508 { USB_DEVICE(FTDI_VID, FTDI_THORLABS_PID) },
508 { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) }, 509 { USB_DEVICE(TESTO_VID, TESTO_USB_INTERFACE_PID) },
509 { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) }, 510 { USB_DEVICE(FTDI_VID, FTDI_GAMMA_SCOUT_PID) },
511 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13M_PID) },
512 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13S_PID) },
513 { USB_DEVICE(FTDI_VID, FTDI_TACTRIX_OPENPORT_13U_PID) },
510 { }, /* Optional parameter entry */ 514 { }, /* Optional parameter entry */
511 { } /* Terminating entry */ 515 { } /* Terminating entry */
512}; 516};
diff --git a/drivers/usb/serial/ftdi_sio.h b/drivers/usb/serial/ftdi_sio.h
index 77299996f7ee..f0edb87d2dd5 100644
--- a/drivers/usb/serial/ftdi_sio.h
+++ b/drivers/usb/serial/ftdi_sio.h
@@ -111,6 +111,7 @@
111#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */ 111#define SEALEVEL_2102_PID 0x2102 /* SeaLINK+485 (2102) */
112#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */ 112#define SEALEVEL_2103_PID 0x2103 /* SeaLINK+232I (2103) */
113#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */ 113#define SEALEVEL_2104_PID 0x2104 /* SeaLINK+485I (2104) */
114#define SEALEVEL_2106_PID 0x9020 /* SeaLINK+422 (2106) */
114#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */ 115#define SEALEVEL_2201_1_PID 0x2211 /* SeaPORT+2/232 (2201) Port 1 */
115#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */ 116#define SEALEVEL_2201_2_PID 0x2221 /* SeaPORT+2/232 (2201) Port 2 */
116#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */ 117#define SEALEVEL_2202_1_PID 0x2212 /* SeaPORT+2/485 (2202) Port 1 */
@@ -472,6 +473,15 @@
472 */ 473 */
473#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */ 474#define FTDI_GAMMA_SCOUT_PID 0xD678 /* Gamma Scout online */
474 475
476/*
477 * Tactrix OpenPort (ECU) devices.
478 * OpenPort 1.3M submitted by Donour Sizemore.
479 * OpenPort 1.3S and 1.3U submitted by Ian Abbott.
480 */
481#define FTDI_TACTRIX_OPENPORT_13M_PID 0xCC48 /* OpenPort 1.3 Mitsubishi */
482#define FTDI_TACTRIX_OPENPORT_13S_PID 0xCC49 /* OpenPort 1.3 Subaru */
483#define FTDI_TACTRIX_OPENPORT_13U_PID 0xCC4A /* OpenPort 1.3 Universal */
484
475/* Commands */ 485/* Commands */
476#define FTDI_SIO_RESET 0 /* Reset the port */ 486#define FTDI_SIO_RESET 0 /* Reset the port */
477#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */ 487#define FTDI_SIO_MODEM_CTRL 1 /* Set the modem control register */
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 172713556393..21cbaa0fb96b 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -175,14 +175,14 @@ int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *
175 175
176 /* only do something if we have a bulk out endpoint */ 176 /* only do something if we have a bulk out endpoint */
177 if (serial->num_bulk_out) { 177 if (serial->num_bulk_out) {
178 spin_lock(&port->lock); 178 spin_lock_bh(&port->lock);
179 if (port->write_urb_busy) { 179 if (port->write_urb_busy) {
180 spin_unlock(&port->lock); 180 spin_unlock_bh(&port->lock);
181 dbg("%s - already writing", __FUNCTION__); 181 dbg("%s - already writing", __FUNCTION__);
182 return 0; 182 return 0;
183 } 183 }
184 port->write_urb_busy = 1; 184 port->write_urb_busy = 1;
185 spin_unlock(&port->lock); 185 spin_unlock_bh(&port->lock);
186 186
187 count = (count > port->bulk_out_size) ? port->bulk_out_size : count; 187 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
188 188
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index bfc6998cd16f..cbc725a6c58e 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -479,6 +479,7 @@ static struct usb_device_id ipaq_id_table [] = {
479 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */ 479 { USB_DEVICE(0x0BB4, 0x0A9D) }, /* SmartPhone USB Sync */
480 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */ 480 { USB_DEVICE(0x0BB4, 0x0A9E) }, /* SmartPhone USB Sync */
481 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */ 481 { USB_DEVICE(0x0BB4, 0x0A9F) }, /* SmartPhone USB Sync */
482 { USB_DEVICE(0x0BB4, 0x0BCE) }, /* "High Tech Computer Corp" */
482 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */ 483 { USB_DEVICE(0x0BF8, 0x1001) }, /* Fujitsu Siemens Computers USB Sync */
483 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */ 484 { USB_DEVICE(0x0C44, 0x03A2) }, /* Motorola iDEN Smartphone */
484 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */ 485 { USB_DEVICE(0x0C8E, 0x6000) }, /* Cesscom Luxian Series */
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index 87306cb6f9f5..812bc213a963 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -394,14 +394,14 @@ static int ipw_write(struct usb_serial_port *port, const unsigned char *buf, int
394 return 0; 394 return 0;
395 } 395 }
396 396
397 spin_lock(&port->lock); 397 spin_lock_bh(&port->lock);
398 if (port->write_urb_busy) { 398 if (port->write_urb_busy) {
399 spin_unlock(&port->lock); 399 spin_unlock_bh(&port->lock);
400 dbg("%s - already writing", __FUNCTION__); 400 dbg("%s - already writing", __FUNCTION__);
401 return 0; 401 return 0;
402 } 402 }
403 port->write_urb_busy = 1; 403 port->write_urb_busy = 1;
404 spin_unlock(&port->lock); 404 spin_unlock_bh(&port->lock);
405 405
406 count = min(count, port->bulk_out_size); 406 count = min(count, port->bulk_out_size);
407 memcpy(port->bulk_out_buffer, buf, count); 407 memcpy(port->bulk_out_buffer, buf, count);
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 1738b0b6a376..1b348df388ed 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -342,14 +342,14 @@ static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int
342 if (count == 0) 342 if (count == 0)
343 return 0; 343 return 0;
344 344
345 spin_lock(&port->lock); 345 spin_lock_bh(&port->lock);
346 if (port->write_urb_busy) { 346 if (port->write_urb_busy) {
347 spin_unlock(&port->lock); 347 spin_unlock_bh(&port->lock);
348 dbg("%s - already writing", __FUNCTION__); 348 dbg("%s - already writing", __FUNCTION__);
349 return 0; 349 return 0;
350 } 350 }
351 port->write_urb_busy = 1; 351 port->write_urb_busy = 1;
352 spin_unlock(&port->lock); 352 spin_unlock_bh(&port->lock);
353 353
354 transfer_buffer = port->write_urb->transfer_buffer; 354 transfer_buffer = port->write_urb->transfer_buffer;
355 transfer_size = min(count, port->bulk_out_size - 1); 355 transfer_size = min(count, port->bulk_out_size - 1);
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 49b8dc039d1f..59e777f1e8fd 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -518,13 +518,13 @@ static int keyspan_pda_write(struct usb_serial_port *port,
518 the TX urb is in-flight (wait until it completes) 518 the TX urb is in-flight (wait until it completes)
519 the device is full (wait until it says there is room) 519 the device is full (wait until it says there is room)
520 */ 520 */
521 spin_lock(&port->lock); 521 spin_lock_bh(&port->lock);
522 if (port->write_urb_busy || priv->tx_throttled) { 522 if (port->write_urb_busy || priv->tx_throttled) {
523 spin_unlock(&port->lock); 523 spin_unlock_bh(&port->lock);
524 return 0; 524 return 0;
525 } 525 }
526 port->write_urb_busy = 1; 526 port->write_urb_busy = 1;
527 spin_unlock(&port->lock); 527 spin_unlock_bh(&port->lock);
528 528
529 /* At this point the URB is in our control, nobody else can submit it 529 /* At this point the URB is in our control, nobody else can submit it
530 again (the only sudden transition was the one from EINPROGRESS to 530 again (the only sudden transition was the one from EINPROGRESS to
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index e49f40913c27..a764ff4e326c 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -256,14 +256,14 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
256 return (0); 256 return (0);
257 } 257 }
258 258
259 spin_lock(&wport->lock); 259 spin_lock_bh(&wport->lock);
260 if (wport->write_urb_busy) { 260 if (wport->write_urb_busy) {
261 spin_unlock(&wport->lock); 261 spin_unlock_bh(&wport->lock);
262 dbg("%s - already writing", __FUNCTION__); 262 dbg("%s - already writing", __FUNCTION__);
263 return 0; 263 return 0;
264 } 264 }
265 wport->write_urb_busy = 1; 265 wport->write_urb_busy = 1;
266 spin_unlock(&wport->lock); 266 spin_unlock_bh(&wport->lock);
267 267
268 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 268 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
269 269
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 1036d436ed23..9c18173e33fb 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -82,6 +82,7 @@ static struct usb_device_id id_table [] = {
82 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, 82 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) },
83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 83 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) },
84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 84 { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) },
85 { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ID) },
85 { } /* Terminating entry */ 86 { } /* Terminating entry */
86}; 87};
87 88
diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h
index 762cc290ef58..65a5039665e7 100644
--- a/drivers/usb/serial/pl2303.h
+++ b/drivers/usb/serial/pl2303.h
@@ -93,3 +93,7 @@
93/* Alcor Micro Corp. USB 2.0 TO RS-232 */ 93/* Alcor Micro Corp. USB 2.0 TO RS-232 */
94#define ALCOR_VENDOR_ID 0x058F 94#define ALCOR_VENDOR_ID 0x058F
95#define ALCOR_PRODUCT_ID 0x9720 95#define ALCOR_PRODUCT_ID 0x9720
96
97/* Huawei E620 UMTS/HSDPA card (ID: 12d1:1001) */
98#define HUAWEI_VENDOR_ID 0x12d1
99#define HUAWEI_PRODUCT_ID 0x1001
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 789771ecdb11..1e07dfad6853 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -298,14 +298,14 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
298 dbg ("%s - write request of 0 bytes", __FUNCTION__); 298 dbg ("%s - write request of 0 bytes", __FUNCTION__);
299 return (0); 299 return (0);
300 } 300 }
301 spin_lock(&port->lock); 301 spin_lock_bh(&port->lock);
302 if (port->write_urb_busy) { 302 if (port->write_urb_busy) {
303 spin_unlock(&port->lock); 303 spin_unlock_bh(&port->lock);
304 dbg("%s - already writing", __FUNCTION__); 304 dbg("%s - already writing", __FUNCTION__);
305 return 0; 305 return 0;
306 } 306 }
307 port->write_urb_busy = 1; 307 port->write_urb_busy = 1;
308 spin_unlock(&port->lock); 308 spin_unlock_bh(&port->lock);
309 309
310 packet_length = port->bulk_out_size; // get max packetsize 310 packet_length = port->bulk_out_size; // get max packetsize
311 311
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index 40bf159f7d54..c9a8d50106d1 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -152,6 +152,13 @@ UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
152 US_SC_DEVICE, US_PR_DEVICE, NULL, 152 US_SC_DEVICE, US_PR_DEVICE, NULL,
153 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ), 153 US_FL_IGNORE_RESIDUE | US_FL_FIX_CAPACITY ),
154 154
155/* Reported by Jon Hart <Jon.Hart@web.de> */
156UNUSUAL_DEV( 0x0421, 0x0434, 0x0100, 0x0100,
157 "Nokia",
158 "E60",
159 US_SC_DEVICE, US_PR_DEVICE, NULL,
160 US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
161
155/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and 162/* Reported by Sumedha Swamy <sumedhaswamy@gmail.com> and
156 * Einar Th. Einarsson <einarthered@gmail.com> */ 163 * Einar Th. Einarsson <einarthered@gmail.com> */
157UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100, 164UNUSUAL_DEV( 0x0421, 0x0444, 0x0100, 0x0100,
@@ -1277,6 +1284,13 @@ UNUSUAL_DEV( 0x0fce, 0xe031, 0x0000, 0x0000,
1277 US_SC_DEVICE, US_PR_DEVICE, NULL, 1284 US_SC_DEVICE, US_PR_DEVICE, NULL,
1278 US_FL_FIX_CAPACITY ), 1285 US_FL_FIX_CAPACITY ),
1279 1286
1287/* Reported by Jan Mate <mate@fiit.stuba.sk> */
1288UNUSUAL_DEV( 0x0fce, 0xe030, 0x0000, 0x0000,
1289 "Sony Ericsson",
1290 "P990i",
1291 US_SC_DEVICE, US_PR_DEVICE, NULL,
1292 US_FL_FIX_CAPACITY ),
1293
1280/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu> 1294/* Reported by Kevin Cernekee <kpc-usbdev@gelato.uiuc.edu>
1281 * Tested on hardware version 1.10. 1295 * Tested on hardware version 1.10.
1282 * Entry is needed only for the initializer function override. 1296 * Entry is needed only for the initializer function override.
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index caf1eca199b0..628571c63bac 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -33,19 +33,19 @@ static unsigned long locomolcd_flags;
33 33
34static void locomolcd_on(int comadj) 34static void locomolcd_on(int comadj)
35{ 35{
36 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0); 36 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
37 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 1); 37 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 1);
38 mdelay(2); 38 mdelay(2);
39 39
40 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0); 40 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
41 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 1); 41 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 1);
42 mdelay(2); 42 mdelay(2);
43 43
44 locomo_m62332_senddata(locomolcd_dev, comadj, 0); 44 locomo_m62332_senddata(locomolcd_dev, comadj, 0);
45 mdelay(5); 45 mdelay(5);
46 46
47 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0); 47 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
48 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 1); 48 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 1);
49 mdelay(10); 49 mdelay(10);
50 50
51 /* TFTCRST | CPSOUT=0 | CPSEN */ 51 /* TFTCRST | CPSOUT=0 | CPSEN */
@@ -58,8 +58,8 @@ static void locomolcd_on(int comadj)
58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC); 58 locomo_writel((0x04 | 0x01), locomolcd_dev->mapbase + LOCOMO_TC);
59 mdelay(10); 59 mdelay(10);
60 60
61 locomo_gpio_set_dir(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0); 61 locomo_gpio_set_dir(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
62 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 1); 62 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 1);
63} 63}
64 64
65static void locomolcd_off(int comadj) 65static void locomolcd_off(int comadj)
@@ -68,16 +68,16 @@ static void locomolcd_off(int comadj)
68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC); 68 locomo_writel(0x06, locomolcd_dev->mapbase + LOCOMO_TC);
69 mdelay(1); 69 mdelay(1);
70 70
71 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHA_ON, 0); 71 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHA_ON, 0);
72 mdelay(110); 72 mdelay(110);
73 73
74 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VEE_ON, 0); 74 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VEE_ON, 0);
75 mdelay(700); 75 mdelay(700);
76 76
77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */ 77 /* TFTCRST=0 | CPSOUT=0 | CPSEN = 0 */
78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC); 78 locomo_writel(0, locomolcd_dev->mapbase + LOCOMO_TC);
79 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_MOD, 0); 79 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_MOD, 0);
80 locomo_gpio_write(locomolcd_dev, LOCOMO_GPIO_LCD_VSHD_ON, 0); 80 locomo_gpio_write(locomolcd_dev->dev.parent, LOCOMO_GPIO_LCD_VSHD_ON, 0);
81} 81}
82 82
83void locomolcd_power(int on) 83void locomolcd_power(int on)
@@ -167,14 +167,14 @@ static int locomolcd_resume(struct locomo_dev *dev)
167#define locomolcd_resume NULL 167#define locomolcd_resume NULL
168#endif 168#endif
169 169
170static int locomolcd_probe(struct locomo_dev *dev) 170static int locomolcd_probe(struct locomo_dev *ldev)
171{ 171{
172 unsigned long flags; 172 unsigned long flags;
173 173
174 local_irq_save(flags); 174 local_irq_save(flags);
175 locomolcd_dev = dev; 175 locomolcd_dev = ldev;
176 176
177 locomo_gpio_set_dir(dev, LOCOMO_GPIO_FL_VR, 0); 177 locomo_gpio_set_dir(ldev->dev.parent, LOCOMO_GPIO_FL_VR, 0);
178 178
179 /* the poodle_lcd_power function is called for the first time 179 /* the poodle_lcd_power function is called for the first time
180 * from fs_initcall, which is before locomo is activated. 180 * from fs_initcall, which is before locomo is activated.