aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Makefile4
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c12
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c24
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c5
-rw-r--r--drivers/i2c/busses/Kconfig42
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c3
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c3
-rw-r--r--drivers/i2c/busses/i2c-amd756.c3
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c3
-rw-r--r--drivers/i2c/busses/i2c-au1550.c3
-rw-r--r--drivers/i2c/busses/i2c-elektor.c1
-rw-r--r--drivers/i2c/busses/i2c-frodo.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c13
-rw-r--r--drivers/i2c/busses/i2c-i810.c1
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c6
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.h1
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c4
-rw-r--r--drivers/i2c/busses/i2c-isa.c162
-rw-r--r--drivers/i2c/busses/i2c-ite.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c8
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c5
-rw-r--r--drivers/i2c/busses/i2c-keywest.c23
-rw-r--r--drivers/i2c/busses/i2c-mpc.c122
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c12
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c34
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c1
-rw-r--r--drivers/i2c/busses/i2c-parport.c3
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c1
-rw-r--r--drivers/i2c/busses/i2c-piix4.c5
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c1
-rw-r--r--drivers/i2c/busses/i2c-rpx.c1
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c4
-rw-r--r--drivers/i2c/busses/i2c-savage4.c1
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c5
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c5
-rw-r--r--drivers/i2c/busses/i2c-sis630.c3
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c3
-rw-r--r--drivers/i2c/busses/i2c-stub.c3
-rw-r--r--drivers/i2c/busses/i2c-via.c1
-rw-r--r--drivers/i2c/busses/i2c-viapro.c3
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c1
-rw-r--r--drivers/i2c/busses/scx200_acb.c5
-rw-r--r--drivers/i2c/chips/Kconfig416
-rw-r--r--drivers/i2c/chips/Makefile38
-rw-r--r--drivers/i2c/chips/adm1021.c411
-rw-r--r--drivers/i2c/chips/adm1025.c574
-rw-r--r--drivers/i2c/chips/adm1026.c1754
-rw-r--r--drivers/i2c/chips/adm1031.c977
-rw-r--r--drivers/i2c/chips/asb100.c1066
-rw-r--r--drivers/i2c/chips/ds1337.c112
-rw-r--r--drivers/i2c/chips/ds1374.c259
-rw-r--r--drivers/i2c/chips/ds1621.c341
-rw-r--r--drivers/i2c/chips/eeprom.c19
-rw-r--r--drivers/i2c/chips/fscher.c692
-rw-r--r--drivers/i2c/chips/fscpos.c641
-rw-r--r--drivers/i2c/chips/gl518sm.c605
-rw-r--r--drivers/i2c/chips/gl520sm.c769
-rw-r--r--drivers/i2c/chips/isp1301_omap.c3
-rw-r--r--drivers/i2c/chips/it87.c1208
-rw-r--r--drivers/i2c/chips/lm63.c581
-rw-r--r--drivers/i2c/chips/lm75.c297
-rw-r--r--drivers/i2c/chips/lm75.h49
-rw-r--r--drivers/i2c/chips/lm77.c421
-rw-r--r--drivers/i2c/chips/lm78.c796
-rw-r--r--drivers/i2c/chips/lm80.c602
-rw-r--r--drivers/i2c/chips/lm83.c412
-rw-r--r--drivers/i2c/chips/lm85.c1578
-rw-r--r--drivers/i2c/chips/lm87.c829
-rw-r--r--drivers/i2c/chips/lm90.c626
-rw-r--r--drivers/i2c/chips/lm92.c429
-rw-r--r--drivers/i2c/chips/m41t00.c8
-rw-r--r--drivers/i2c/chips/max1619.c373
-rw-r--r--drivers/i2c/chips/max6875.c261
-rw-r--r--drivers/i2c/chips/pc87360.c1349
-rw-r--r--drivers/i2c/chips/pca9539.c188
-rw-r--r--drivers/i2c/chips/pcf8574.c25
-rw-r--r--drivers/i2c/chips/pcf8591.c23
-rw-r--r--drivers/i2c/chips/rtc8564.c5
-rw-r--r--drivers/i2c/chips/sis5595.c816
-rw-r--r--drivers/i2c/chips/smsc47b397.c352
-rw-r--r--drivers/i2c/chips/smsc47m1.c591
-rw-r--r--drivers/i2c/chips/tps65010.c1069
-rw-r--r--drivers/i2c/chips/via686a.c878
-rw-r--r--drivers/i2c/chips/w83627hf.c1511
-rw-r--r--drivers/i2c/chips/w83781d.c1664
-rw-r--r--drivers/i2c/chips/w83l785ts.c329
-rw-r--r--drivers/i2c/i2c-core.c383
-rw-r--r--drivers/i2c/i2c-dev.c8
-rw-r--r--drivers/i2c/i2c-sensor-detect.c145
-rw-r--r--drivers/i2c/i2c-sensor-vid.c98
94 files changed, 2298 insertions, 24840 deletions
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index cd170395a8c7..71c5a854ac5d 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -4,12 +4,8 @@
4 4
5obj-$(CONFIG_I2C) += i2c-core.o 5obj-$(CONFIG_I2C) += i2c-core.o
6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o 6obj-$(CONFIG_I2C_CHARDEV) += i2c-dev.o
7obj-$(CONFIG_I2C_SENSOR) += i2c-sensor.o
8obj-y += busses/ chips/ algos/ 7obj-y += busses/ chips/ algos/
9 8
10i2c-sensor-objs := i2c-sensor-detect.o i2c-sensor-vid.o
11
12
13ifeq ($(CONFIG_I2C_DEBUG_CORE),y) 9ifeq ($(CONFIG_I2C_DEBUG_CORE),y)
14EXTRA_CFLAGS += -DDEBUG 10EXTRA_CFLAGS += -DDEBUG
15endif 11endif
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index fb5b732238ed..df05df1a0ef6 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -519,8 +519,6 @@ static u32 bit_func(struct i2c_adapter *adap)
519/* -----exported algorithm data: ------------------------------------- */ 519/* -----exported algorithm data: ------------------------------------- */
520 520
521static struct i2c_algorithm i2c_bit_algo = { 521static struct i2c_algorithm i2c_bit_algo = {
522 .name = "Bit-shift algorithm",
523 .id = I2C_ALGO_BIT,
524 .master_xfer = bit_xfer, 522 .master_xfer = bit_xfer,
525 .functionality = bit_func, 523 .functionality = bit_func,
526}; 524};
@@ -541,8 +539,6 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
541 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); 539 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
542 540
543 /* register new adapter to i2c module... */ 541 /* register new adapter to i2c module... */
544
545 adap->id |= i2c_bit_algo.id;
546 adap->algo = &i2c_bit_algo; 542 adap->algo = &i2c_bit_algo;
547 543
548 adap->timeout = 100; /* default values, should */ 544 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
index 68e9e6832ca0..2db7bfc85225 100644
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ b/drivers/i2c/algos/i2c-algo-ite.c
@@ -208,7 +208,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
208 goto bailout; 208 goto bailout;
209 } 209 }
210 sdalo(adap); 210 sdalo(adap);
211 printk("test_bus:1 scl: %d sda: %d \n",getscl(adap), 211 printk("test_bus:1 scl: %d sda: %d\n", getscl(adap),
212 getsda(adap)); 212 getsda(adap));
213 if ( 0 != getsda(adap) ) { 213 if ( 0 != getsda(adap) ) {
214 printk("test_bus: %s SDA stuck high!\n",name); 214 printk("test_bus: %s SDA stuck high!\n",name);
@@ -221,7 +221,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
221 goto bailout; 221 goto bailout;
222 } 222 }
223 sdahi(adap); 223 sdahi(adap);
224 printk("test_bus:2 scl: %d sda: %d \n",getscl(adap), 224 printk("test_bus:2 scl: %d sda: %d\n", getscl(adap),
225 getsda(adap)); 225 getsda(adap));
226 if ( 0 == getsda(adap) ) { 226 if ( 0 == getsda(adap) ) {
227 printk("test_bus: %s SDA stuck low!\n",name); 227 printk("test_bus: %s SDA stuck low!\n",name);
@@ -234,7 +234,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
234 goto bailout; 234 goto bailout;
235 } 235 }
236 scllo(adap); 236 scllo(adap);
237 printk("test_bus:3 scl: %d sda: %d \n",getscl(adap), 237 printk("test_bus:3 scl: %d sda: %d\n", getscl(adap),
238 getsda(adap)); 238 getsda(adap));
239 if ( 0 != getscl(adap) ) { 239 if ( 0 != getscl(adap) ) {
240 240
@@ -247,7 +247,7 @@ static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
247 goto bailout; 247 goto bailout;
248 } 248 }
249 sclhi(adap); 249 sclhi(adap);
250 printk("test_bus:4 scl: %d sda: %d \n",getscl(adap), 250 printk("test_bus:4 scl: %d sda: %d\n", getscl(adap),
251 getsda(adap)); 251 getsda(adap));
252 if ( 0 == getscl(adap) ) { 252 if ( 0 == getscl(adap) ) {
253 printk("test_bus: %s SCL stuck low!\n",name); 253 printk("test_bus: %s SCL stuck low!\n",name);
@@ -713,8 +713,6 @@ static u32 iic_func(struct i2c_adapter *adap)
713/* -----exported algorithm data: ------------------------------------- */ 713/* -----exported algorithm data: ------------------------------------- */
714 714
715static struct i2c_algorithm iic_algo = { 715static struct i2c_algorithm iic_algo = {
716 .name = "ITE IIC algorithm",
717 .id = I2C_ALGO_IIC,
718 .master_xfer = iic_xfer, 716 .master_xfer = iic_xfer,
719 .algo_control = algo_control, /* ioctl */ 717 .algo_control = algo_control, /* ioctl */
720 .functionality = iic_func, 718 .functionality = iic_func,
@@ -738,8 +736,6 @@ int i2c_iic_add_bus(struct i2c_adapter *adap)
738 adap->name)); 736 adap->name));
739 737
740 /* register new adapter to i2c module... */ 738 /* register new adapter to i2c module... */
741
742 adap->id |= iic_algo.id;
743 adap->algo = &iic_algo; 739 adap->algo = &iic_algo;
744 740
745 adap->timeout = 100; /* default values, should */ 741 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index c3d912cbbbc3..beb10edfe9c1 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -49,7 +49,7 @@ static int i2c_debug=0;
49/* 49/*
50 * Generate a start condition on the i2c bus. 50 * Generate a start condition on the i2c bus.
51 * 51 *
52 * returns after the start condition has occured 52 * returns after the start condition has occurred
53 */ 53 */
54static void pca_start(struct i2c_algo_pca_data *adap) 54static void pca_start(struct i2c_algo_pca_data *adap)
55{ 55{
@@ -62,9 +62,9 @@ static void pca_start(struct i2c_algo_pca_data *adap)
62} 62}
63 63
64/* 64/*
65 * Generate a repeated start condition on the i2c bus 65 * Generate a repeated start condition on the i2c bus
66 * 66 *
67 * return after the repeated start condition has occured 67 * return after the repeated start condition has occurred
68 */ 68 */
69static void pca_repeated_start(struct i2c_algo_pca_data *adap) 69static void pca_repeated_start(struct i2c_algo_pca_data *adap)
70{ 70{
@@ -82,7 +82,7 @@ static void pca_repeated_start(struct i2c_algo_pca_data *adap)
82 * returns after the stop condition has been generated 82 * returns after the stop condition has been generated
83 * 83 *
84 * STOPs do not generate an interrupt or set the SI flag, since the 84 * STOPs do not generate an interrupt or set the SI flag, since the
85 * part returns the the idle state (0xf8). Hence we don't need to 85 * part returns the idle state (0xf8). Hence we don't need to
86 * pca_wait here. 86 * pca_wait here.
87 */ 87 */
88static void pca_stop(struct i2c_algo_pca_data *adap) 88static void pca_stop(struct i2c_algo_pca_data *adap)
@@ -187,12 +187,14 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
187 int numbytes = 0; 187 int numbytes = 0;
188 int state; 188 int state;
189 int ret; 189 int ret;
190 int timeout = 100;
190 191
191 state = pca_status(adap); 192 while ((state = pca_status(adap)) != 0xf8 && timeout--) {
192 if ( state != 0xF8 ) { 193 msleep(10);
193 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state ); 194 }
194 /* FIXME: what to do. Force stop ? */ 195 if (state != 0xf8) {
195 return -EREMOTEIO; 196 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state);
197 return -EIO;
196 } 198 }
197 199
198 DEB1("{{{ XFER %d messages\n", num); 200 DEB1("{{{ XFER %d messages\n", num);
@@ -354,8 +356,6 @@ static int pca_init(struct i2c_algo_pca_data *adap)
354} 356}
355 357
356static struct i2c_algorithm pca_algo = { 358static struct i2c_algorithm pca_algo = {
357 .name = "PCA9564 algorithm",
358 .id = I2C_ALGO_PCA,
359 .master_xfer = pca_xfer, 359 .master_xfer = pca_xfer,
360 .functionality = pca_func, 360 .functionality = pca_func,
361}; 361};
@@ -369,8 +369,6 @@ int i2c_pca_add_bus(struct i2c_adapter *adap)
369 int rval; 369 int rval;
370 370
371 /* register new adapter to i2c module... */ 371 /* register new adapter to i2c module... */
372
373 adap->id |= pca_algo.id;
374 adap->algo = &pca_algo; 372 adap->algo = &pca_algo;
375 373
376 adap->timeout = 100; /* default values, should */ 374 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 8d087dac32af..6e498df1f717 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -459,8 +459,6 @@ static u32 pcf_func(struct i2c_adapter *adap)
459/* -----exported algorithm data: ------------------------------------- */ 459/* -----exported algorithm data: ------------------------------------- */
460 460
461static struct i2c_algorithm pcf_algo = { 461static struct i2c_algorithm pcf_algo = {
462 .name = "PCF8584 algorithm",
463 .id = I2C_ALGO_PCF,
464 .master_xfer = pcf_xfer, 462 .master_xfer = pcf_xfer,
465 .functionality = pcf_func, 463 .functionality = pcf_func,
466}; 464};
@@ -476,8 +474,6 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
476 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); 474 DEB2(dev_dbg(&adap->dev, "hw routines registered.\n"));
477 475
478 /* register new adapter to i2c module... */ 476 /* register new adapter to i2c module... */
479
480 adap->id |= pcf_algo.id;
481 adap->algo = &pcf_algo; 477 adap->algo = &pcf_algo;
482 478
483 adap->timeout = 100; /* default values, should */ 479 adap->timeout = 100; /* default values, should */
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index 422721b241e5..932c4fa86c73 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -149,7 +149,7 @@ static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
149 err = i2c_write(adap, p->buf, p->len); 149 err = i2c_write(adap, p->buf, p->len);
150 } 150 }
151 151
152 return err; 152 return (err < 0) ? err : i;
153} 153}
154 154
155static u32 sgi_func(struct i2c_adapter *adap) 155static u32 sgi_func(struct i2c_adapter *adap)
@@ -158,8 +158,6 @@ static u32 sgi_func(struct i2c_adapter *adap)
158} 158}
159 159
160static struct i2c_algorithm sgi_algo = { 160static struct i2c_algorithm sgi_algo = {
161 .name = "SGI algorithm",
162 .id = I2C_ALGO_SGI,
163 .master_xfer = sgi_xfer, 161 .master_xfer = sgi_xfer,
164 .functionality = sgi_func, 162 .functionality = sgi_func,
165}; 163};
@@ -169,7 +167,6 @@ static struct i2c_algorithm sgi_algo = {
169 */ 167 */
170int i2c_sgi_add_bus(struct i2c_adapter *adap) 168int i2c_sgi_add_bus(struct i2c_adapter *adap)
171{ 169{
172 adap->id |= sgi_algo.id;
173 adap->algo = &sgi_algo; 170 adap->algo = &sgi_algo;
174 171
175 return i2c_add_adapter(adap); 172 return i2c_add_adapter(adap);
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
index 35789bb7126a..8ed5ad12552f 100644
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ b/drivers/i2c/algos/i2c-algo-sibyte.c
@@ -24,7 +24,6 @@
24 24
25/* Ported for SiByte SOCs by Broadcom Corporation. */ 25/* Ported for SiByte SOCs by Broadcom Corporation. */
26 26
27#include <linux/config.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/init.h> 29#include <linux/init.h>
@@ -136,8 +135,6 @@ static u32 bit_func(struct i2c_adapter *adap)
136/* -----exported algorithm data: ------------------------------------- */ 135/* -----exported algorithm data: ------------------------------------- */
137 136
138static struct i2c_algorithm i2c_sibyte_algo = { 137static struct i2c_algorithm i2c_sibyte_algo = {
139 .name = "SiByte algorithm",
140 .id = I2C_ALGO_SIBYTE,
141 .smbus_xfer = smbus_xfer, 138 .smbus_xfer = smbus_xfer,
142 .algo_control = algo_control, /* ioctl */ 139 .algo_control = algo_control, /* ioctl */
143 .functionality = bit_func, 140 .functionality = bit_func,
@@ -152,8 +149,6 @@ int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
152 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 149 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
153 150
154 /* register new adapter to i2c module... */ 151 /* register new adapter to i2c module... */
155
156 i2c_adap->id |= i2c_sibyte_algo.id;
157 i2c_adap->algo = &i2c_sibyte_algo; 152 i2c_adap->algo = &i2c_sibyte_algo;
158 153
159 /* Set the frequency to 100 kHz */ 154 /* Set the frequency to 100 kHz */
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index a3bec8d65cff..8334496a7e0a 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -7,7 +7,7 @@ menu "I2C Hardware Bus support"
7 7
8config I2C_ALI1535 8config I2C_ALI1535
9 tristate "ALI 1535" 9 tristate "ALI 1535"
10 depends on I2C && PCI && EXPERIMENTAL 10 depends on I2C && PCI
11 help 11 help
12 If you say yes to this option, support will be included for the SMB 12 If you say yes to this option, support will be included for the SMB
13 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB 13 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB
@@ -31,7 +31,7 @@ config I2C_ALI1563
31 31
32config I2C_ALI15X3 32config I2C_ALI15X3
33 tristate "ALI 15x3" 33 tristate "ALI 15x3"
34 depends on I2C && PCI && EXPERIMENTAL 34 depends on I2C && PCI
35 help 35 help
36 If you say yes to this option, support will be included for the 36 If you say yes to this option, support will be included for the
37 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. 37 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces.
@@ -41,7 +41,7 @@ config I2C_ALI15X3
41 41
42config I2C_AMD756 42config I2C_AMD756
43 tristate "AMD 756/766/768/8111 and nVidia nForce" 43 tristate "AMD 756/766/768/8111 and nVidia nForce"
44 depends on I2C && PCI && EXPERIMENTAL 44 depends on I2C && PCI
45 help 45 help
46 If you say yes to this option, support will be included for the AMD 46 If you say yes to this option, support will be included for the AMD
47 756/766/768 mainboard I2C interfaces. The driver also includes 47 756/766/768 mainboard I2C interfaces. The driver also includes
@@ -66,7 +66,7 @@ config I2C_AMD756_S4882
66 66
67config I2C_AMD8111 67config I2C_AMD8111
68 tristate "AMD 8111" 68 tristate "AMD 8111"
69 depends on I2C && PCI && EXPERIMENTAL 69 depends on I2C && PCI
70 help 70 help
71 If you say yes to this option, support will be included for the 71 If you say yes to this option, support will be included for the
72 second (SMBus 2.0) AMD 8111 mainboard I2C interface. 72 second (SMBus 2.0) AMD 8111 mainboard I2C interface.
@@ -109,7 +109,7 @@ config I2C_HYDRA
109 109
110config I2C_I801 110config I2C_I801
111 tristate "Intel 82801 (ICH)" 111 tristate "Intel 82801 (ICH)"
112 depends on I2C && PCI && EXPERIMENTAL 112 depends on I2C && PCI
113 help 113 help
114 If you say yes to this option, support will be included for the Intel 114 If you say yes to this option, support will be included for the Intel
115 801 family of mainboard I2C interfaces. Specifically, the following 115 801 family of mainboard I2C interfaces. Specifically, the following
@@ -130,7 +130,7 @@ config I2C_I801
130 130
131config I2C_I810 131config I2C_I810
132 tristate "Intel 810/815" 132 tristate "Intel 810/815"
133 depends on I2C && PCI && EXPERIMENTAL 133 depends on I2C && PCI
134 select I2C_ALGOBIT 134 select I2C_ALGOBIT
135 help 135 help
136 If you say yes to this option, support will be included for the Intel 136 If you say yes to this option, support will be included for the Intel
@@ -198,14 +198,8 @@ config I2C_IOP3XX
198 will be called i2c-iop3xx. 198 will be called i2c-iop3xx.
199 199
200config I2C_ISA 200config I2C_ISA
201 tristate "ISA Bus support" 201 tristate
202 depends on I2C && EXPERIMENTAL 202 depends on I2C
203 help
204 If you say yes to this option, support will be included for i2c
205 interfaces that are on the ISA bus.
206
207 This driver can also be built as a module. If so, the module
208 will be called i2c-isa.
209 203
210config I2C_ITE 204config I2C_ITE
211 tristate "ITE I2C Adapter" 205 tristate "ITE I2C Adapter"
@@ -264,12 +258,11 @@ config I2C_MPC
264 will be called i2c-mpc. 258 will be called i2c-mpc.
265 259
266config I2C_NFORCE2 260config I2C_NFORCE2
267 tristate "Nvidia Nforce2" 261 tristate "Nvidia nForce2, nForce3 and nForce4"
268 depends on I2C && PCI && EXPERIMENTAL 262 depends on I2C && PCI
269 help 263 help
270 If you say yes to this option, support will be included for the Nvidia 264 If you say yes to this option, support will be included for the Nvidia
271 Nforce2 family of mainboard I2C interfaces. 265 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces.
272 This driver also supports the nForce3 Pro 150 MCP.
273 266
274 This driver can also be built as a module. If so, the module 267 This driver can also be built as a module. If so, the module
275 will be called i2c-nforce2. 268 will be called i2c-nforce2.
@@ -321,7 +314,7 @@ config I2C_PARPORT_LIGHT
321 314
322config I2C_PROSAVAGE 315config I2C_PROSAVAGE
323 tristate "S3/VIA (Pro)Savage" 316 tristate "S3/VIA (Pro)Savage"
324 depends on I2C && PCI && EXPERIMENTAL 317 depends on I2C && PCI
325 select I2C_ALGOBIT 318 select I2C_ALGOBIT
326 help 319 help
327 If you say yes to this option, support will be included for the 320 If you say yes to this option, support will be included for the
@@ -404,7 +397,7 @@ config SCx200_ACB
404 397
405config I2C_SIS5595 398config I2C_SIS5595
406 tristate "SiS 5595" 399 tristate "SiS 5595"
407 depends on I2C && PCI && EXPERIMENTAL 400 depends on I2C && PCI
408 help 401 help
409 If you say yes to this option, support will be included for the 402 If you say yes to this option, support will be included for the
410 SiS5595 SMBus (a subset of I2C) interface. 403 SiS5595 SMBus (a subset of I2C) interface.
@@ -414,7 +407,7 @@ config I2C_SIS5595
414 407
415config I2C_SIS630 408config I2C_SIS630
416 tristate "SiS 630/730" 409 tristate "SiS 630/730"
417 depends on I2C && PCI && EXPERIMENTAL 410 depends on I2C && PCI
418 help 411 help
419 If you say yes to this option, support will be included for the 412 If you say yes to this option, support will be included for the
420 SiS630 and SiS730 SMBus (a subset of I2C) interface. 413 SiS630 and SiS730 SMBus (a subset of I2C) interface.
@@ -424,7 +417,7 @@ config I2C_SIS630
424 417
425config I2C_SIS96X 418config I2C_SIS96X
426 tristate "SiS 96x" 419 tristate "SiS 96x"
427 depends on I2C && PCI && EXPERIMENTAL 420 depends on I2C && PCI
428 help 421 help
429 If you say yes to this option, support will be included for the SiS 422 If you say yes to this option, support will be included for the SiS
430 96x SMBus (a subset of I2C) interfaces. Specifically, the following 423 96x SMBus (a subset of I2C) interfaces. Specifically, the following
@@ -435,6 +428,7 @@ config I2C_SIS96X
435 648/961 428 648/961
436 650/961 429 650/961
437 735 430 735
431 745
438 432
439 This driver can also be built as a module. If so, the module 433 This driver can also be built as a module. If so, the module
440 will be called i2c-sis96x. 434 will be called i2c-sis96x.
@@ -465,7 +459,7 @@ config I2C_VIA
465 459
466config I2C_VIAPRO 460config I2C_VIAPRO
467 tristate "VIA 82C596/82C686/823x" 461 tristate "VIA 82C596/82C686/823x"
468 depends on I2C && PCI && EXPERIMENTAL 462 depends on I2C && PCI
469 help 463 help
470 If you say yes to this option, support will be included for the VIA 464 If you say yes to this option, support will be included for the VIA
471 82C596/82C686/823x I2C interfaces. Specifically, the following 465 82C596/82C686/823x I2C interfaces. Specifically, the following
@@ -483,7 +477,7 @@ config I2C_VIAPRO
483 477
484config I2C_VOODOO3 478config I2C_VOODOO3
485 tristate "Voodoo 3" 479 tristate "Voodoo 3"
486 depends on I2C && PCI && EXPERIMENTAL 480 depends on I2C && PCI
487 select I2C_ALGOBIT 481 select I2C_ALGOBIT
488 help 482 help
489 If you say yes to this option, support will be included for the 483 If you say yes to this option, support will be included for the
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index b00cd4098221..f021acd2674e 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -53,7 +53,6 @@
53 53
54/* Note: we assume there can only be one ALI1535, with one SMBus interface */ 54/* Note: we assume there can only be one ALI1535, with one SMBus interface */
55 55
56#include <linux/config.h>
57#include <linux/module.h> 56#include <linux/module.h>
58#include <linux/pci.h> 57#include <linux/pci.h>
59#include <linux/kernel.h> 58#include <linux/kernel.h>
@@ -473,8 +472,6 @@ static u32 ali1535_func(struct i2c_adapter *adapter)
473} 472}
474 473
475static struct i2c_algorithm smbus_algorithm = { 474static struct i2c_algorithm smbus_algorithm = {
476 .name = "Non-i2c SMBus adapter",
477 .id = I2C_ALGO_SMBUS,
478 .smbus_xfer = ali1535_access, 475 .smbus_xfer = ali1535_access,
479 .functionality = ali1535_func, 476 .functionality = ali1535_func,
480}; 477};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index fdd881aee618..86947504aea1 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -366,8 +366,6 @@ static void ali1563_shutdown(struct pci_dev *dev)
366} 366}
367 367
368static struct i2c_algorithm ali1563_algorithm = { 368static struct i2c_algorithm ali1563_algorithm = {
369 .name = "Non-i2c SMBus adapter",
370 .id = I2C_ALGO_SMBUS,
371 .smbus_xfer = ali1563_access, 369 .smbus_xfer = ali1563_access,
372 .functionality = ali1563_func, 370 .functionality = ali1563_func,
373}; 371};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 5bd6a4a77c1e..b3f50bff39a0 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -60,7 +60,6 @@
60 60
61/* Note: we assume there can only be one ALI15X3, with one SMBus interface */ 61/* Note: we assume there can only be one ALI15X3, with one SMBus interface */
62 62
63#include <linux/config.h>
64#include <linux/module.h> 63#include <linux/module.h>
65#include <linux/pci.h> 64#include <linux/pci.h>
66#include <linux/kernel.h> 65#include <linux/kernel.h>
@@ -463,8 +462,6 @@ static u32 ali15x3_func(struct i2c_adapter *adapter)
463} 462}
464 463
465static struct i2c_algorithm smbus_algorithm = { 464static struct i2c_algorithm smbus_algorithm = {
466 .name = "Non-I2C SMBus adapter",
467 .id = I2C_ALGO_SMBUS,
468 .smbus_xfer = ali15x3_access, 465 .smbus_xfer = ali15x3_access,
469 .functionality = ali15x3_func, 466 .functionality = ali15x3_func,
470}; 467};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index eca5ed3738b8..6ad0603384b8 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -37,7 +37,6 @@
37 Note: we assume there can only be one device, with one SMBus interface. 37 Note: we assume there can only be one device, with one SMBus interface.
38*/ 38*/
39 39
40#include <linux/config.h>
41#include <linux/module.h> 40#include <linux/module.h>
42#include <linux/pci.h> 41#include <linux/pci.h>
43#include <linux/kernel.h> 42#include <linux/kernel.h>
@@ -296,8 +295,6 @@ static u32 amd756_func(struct i2c_adapter *adapter)
296} 295}
297 296
298static struct i2c_algorithm smbus_algorithm = { 297static struct i2c_algorithm smbus_algorithm = {
299 .name = "Non-I2C SMBus adapter",
300 .id = I2C_ALGO_SMBUS,
301 .smbus_xfer = amd756_access, 298 .smbus_xfer = amd756_access,
302 .functionality = amd756_func, 299 .functionality = amd756_func,
303}; 300};
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index af22b401a38b..45ea24ba14d5 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -8,7 +8,6 @@
8 * the Free Software Foundation version 2. 8 * the Free Software Foundation version 2.
9 */ 9 */
10 10
11#include <linux/config.h>
12#include <linux/module.h> 11#include <linux/module.h>
13#include <linux/pci.h> 12#include <linux/pci.h>
14#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -324,8 +323,6 @@ static u32 amd8111_func(struct i2c_adapter *adapter)
324} 323}
325 324
326static struct i2c_algorithm smbus_algorithm = { 325static struct i2c_algorithm smbus_algorithm = {
327 .name = "Non-I2C SMBus 2.0 adapter",
328 .id = I2C_ALGO_SMBUS,
329 .smbus_xfer = amd8111_access, 326 .smbus_xfer = amd8111_access,
330 .functionality = amd8111_func, 327 .functionality = amd8111_func,
331}; 328};
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 75831a20b0bd..d06edce03bf4 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -27,7 +27,6 @@
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 */ 28 */
29 29
30#include <linux/config.h>
31#include <linux/delay.h> 30#include <linux/delay.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/module.h> 32#include <linux/module.h>
@@ -284,8 +283,6 @@ au1550_func(struct i2c_adapter *adap)
284} 283}
285 284
286static struct i2c_algorithm au1550_algo = { 285static struct i2c_algorithm au1550_algo = {
287 .name = "Au1550 algorithm",
288 .id = I2C_ALGO_AU1550,
289 .master_xfer = au1550_xfer, 286 .master_xfer = au1550_xfer,
290 .functionality = au1550_func, 287 .functionality = au1550_func,
291}; 288};
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 0a7720000a0c..6930b660e508 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -25,7 +25,6 @@
25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of 25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of
26 for Alpha Processor Inc. UP-2000(+) boards */ 26 for Alpha Processor Inc. UP-2000(+) boards */
27 27
28#include <linux/config.h>
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/ioport.h> 29#include <linux/ioport.h>
31#include <linux/module.h> 30#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-frodo.c b/drivers/i2c/busses/i2c-frodo.c
index e093829a0bf7..b6f52f5a4138 100644
--- a/drivers/i2c/busses/i2c-frodo.c
+++ b/drivers/i2c/busses/i2c-frodo.c
@@ -12,7 +12,6 @@
12 * version 2 as published by the Free Software Foundation. 12 * version 2 as published by the Free Software Foundation.
13 */ 13 */
14 14
15#include <linux/config.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/kernel.h> 16#include <linux/kernel.h>
18#include <linux/init.h> 17#include <linux/init.h>
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 59c238c42e8c..709beab76609 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -41,7 +41,6 @@
41 41
42/* Note: we assume there can only be one I801, with one SMBus interface */ 42/* Note: we assume there can only be one I801, with one SMBus interface */
43 43
44#include <linux/config.h>
45#include <linux/module.h> 44#include <linux/module.h>
46#include <linux/pci.h> 45#include <linux/pci.h>
47#include <linux/kernel.h> 46#include <linux/kernel.h>
@@ -138,7 +137,7 @@ static int i801_setup(struct pci_dev *dev)
138 pci_read_config_word(I801_dev, SMBBA, &i801_smba); 137 pci_read_config_word(I801_dev, SMBBA, &i801_smba);
139 i801_smba &= 0xfff0; 138 i801_smba &= 0xfff0;
140 if(i801_smba == 0) { 139 if(i801_smba == 0) {
141 dev_err(&dev->dev, "SMB base address uninitialized" 140 dev_err(&dev->dev, "SMB base address uninitialized "
142 "- upgrade BIOS or use force_addr=0xaddr\n"); 141 "- upgrade BIOS or use force_addr=0xaddr\n");
143 return -ENODEV; 142 return -ENODEV;
144 } 143 }
@@ -187,7 +186,7 @@ static int i801_transaction(void)
187 int result = 0; 186 int result = 0;
188 int timeout = 0; 187 int timeout = 0;
189 188
190 dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x," 189 dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
191 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 190 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
192 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 191 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
193 inb_p(SMBHSTDAT1)); 192 inb_p(SMBHSTDAT1));
@@ -195,7 +194,7 @@ static int i801_transaction(void)
195 /* Make sure the SMBus host is ready to start transmitting */ 194 /* Make sure the SMBus host is ready to start transmitting */
196 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ 195 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
197 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 196 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
198 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting... \n", 197 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting...\n",
199 temp); 198 temp);
200 outb_p(temp, SMBHSTSTS); 199 outb_p(temp, SMBHSTSTS);
201 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 200 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
@@ -241,7 +240,7 @@ static int i801_transaction(void)
241 outb_p(inb(SMBHSTSTS), SMBHSTSTS); 240 outb_p(inb(SMBHSTSTS), SMBHSTSTS);
242 241
243 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 242 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
244 dev_dbg(&I801_dev->dev, "Failed reset at end of transaction" 243 dev_dbg(&I801_dev->dev, "Failed reset at end of transaction "
245 "(%02x)\n", temp); 244 "(%02x)\n", temp);
246 } 245 }
247 dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, " 246 dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, "
@@ -316,7 +315,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
316 } 315 }
317 if (temp & errmask) { 316 if (temp & errmask) {
318 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). " 317 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
319 "Resetting... \n", temp); 318 "Resetting...\n", temp);
320 outb_p(temp, SMBHSTSTS); 319 outb_p(temp, SMBHSTSTS);
321 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { 320 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
322 dev_err(&I801_dev->dev, 321 dev_err(&I801_dev->dev,
@@ -536,8 +535,6 @@ static u32 i801_func(struct i2c_adapter *adapter)
536} 535}
537 536
538static struct i2c_algorithm smbus_algorithm = { 537static struct i2c_algorithm smbus_algorithm = {
539 .name = "Non-I2C SMBus adapter",
540 .id = I2C_ALGO_SMBUS,
541 .smbus_xfer = i801_access, 538 .smbus_xfer = i801_access,
542 .functionality = i801_func, 539 .functionality = i801_func,
543}; 540};
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index ef358bd9c3da..0ff7016e0629 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -34,7 +34,6 @@
34 i815 1132 34 i815 1132
35*/ 35*/
36 36
37#include <linux/config.h>
38#include <linux/kernel.h> 37#include <linux/kernel.h>
39#include <linux/module.h> 38#include <linux/module.h>
40#include <linux/init.h> 39#include <linux/init.h>
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index bb885215c08d..a3ed9590f028 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -627,8 +627,6 @@ static u32 iic_func(struct i2c_adapter *adap)
627} 627}
628 628
629static struct i2c_algorithm iic_algo = { 629static struct i2c_algorithm iic_algo = {
630 .name = "IBM IIC algorithm",
631 .id = I2C_ALGO_OCP,
632 .master_xfer = iic_xfer, 630 .master_xfer = iic_xfer,
633 .functionality = iic_func 631 .functionality = iic_func
634}; 632};
@@ -695,7 +693,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
695 693
696 dev->irq = iic_force_poll ? -1 : ocp->def->irq; 694 dev->irq = iic_force_poll ? -1 : ocp->def->irq;
697 if (dev->irq >= 0){ 695 if (dev->irq >= 0){
698 /* Disable interrupts until we finish intialization, 696 /* Disable interrupts until we finish initialization,
699 assumes level-sensitive IRQ setup... 697 assumes level-sensitive IRQ setup...
700 */ 698 */
701 iic_interrupt_mode(dev, 0); 699 iic_interrupt_mode(dev, 0);
@@ -727,7 +725,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
727 adap = &dev->adap; 725 adap = &dev->adap;
728 strcpy(adap->name, "IBM IIC"); 726 strcpy(adap->name, "IBM IIC");
729 i2c_set_adapdata(adap, dev); 727 i2c_set_adapdata(adap, dev);
730 adap->id = I2C_HW_OCP | iic_algo.id; 728 adap->id = I2C_HW_OCP;
731 adap->algo = &iic_algo; 729 adap->algo = &iic_algo;
732 adap->client_register = NULL; 730 adap->client_register = NULL;
733 adap->client_unregister = NULL; 731 adap->client_unregister = NULL;
diff --git a/drivers/i2c/busses/i2c-ibm_iic.h b/drivers/i2c/busses/i2c-ibm_iic.h
index d819a955d890..2b3219d00e92 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.h
+++ b/drivers/i2c/busses/i2c-ibm_iic.h
@@ -22,7 +22,6 @@
22#ifndef __I2C_IBM_IIC_H_ 22#ifndef __I2C_IBM_IIC_H_
23#define __I2C_IBM_IIC_H_ 23#define __I2C_IBM_IIC_H_
24 24
25#include <linux/config.h>
26#include <linux/i2c.h> 25#include <linux/i2c.h>
27 26
28struct iic_regs { 27struct iic_regs {
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index c961ba4cfb32..7bd9102db701 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -85,7 +85,7 @@ iop3xx_i2c_enable(struct i2c_algo_iop3xx_data *iop3xx_adap)
85 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE; 85 u32 cr = IOP3XX_ICR_GCD | IOP3XX_ICR_SCLEN | IOP3XX_ICR_UE;
86 86
87 /* 87 /*
88 * Everytime unit enable is asserted, GPOD needs to be cleared 88 * Every time unit enable is asserted, GPOD needs to be cleared
89 * on IOP321 to avoid data corruption on the bus. 89 * on IOP321 to avoid data corruption on the bus.
90 */ 90 */
91#ifdef CONFIG_ARCH_IOP321 91#ifdef CONFIG_ARCH_IOP321
@@ -399,8 +399,6 @@ iop3xx_i2c_func(struct i2c_adapter *adap)
399} 399}
400 400
401static struct i2c_algorithm iop3xx_i2c_algo = { 401static struct i2c_algorithm iop3xx_i2c_algo = {
402 .name = "IOP3xx I2C algorithm",
403 .id = I2C_ALGO_IOP3XX,
404 .master_xfer = iop3xx_i2c_master_xfer, 402 .master_xfer = iop3xx_i2c_master_xfer,
405 .algo_control = iop3xx_i2c_algo_control, 403 .algo_control = iop3xx_i2c_algo_control,
406 .functionality = iop3xx_i2c_func, 404 .functionality = iop3xx_i2c_func,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 0f54a2a0afa5..bdc6806dafae 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -1,6 +1,8 @@
1/* 1/*
2 i2c-isa.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-isa.c - an i2c-core-like thing for ISA hardware monitoring chips
3 monitoring 3 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
4
5 Based on the i2c-isa pseudo-adapter from the lm_sensors project
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 6 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 7
6 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
@@ -18,31 +20,36 @@
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 21*/
20 22
21/* This implements an i2c algorithm/adapter for ISA bus. Not that this is 23/* This implements an i2c-core-like thing for ISA hardware monitoring
22 on first sight very useful; almost no functionality is preserved. 24 chips. Such chips are linked to the i2c subsystem for historical
23 Except that it makes writing drivers for chips which can be on both 25 reasons (because the early ISA hardware monitoring chips such as the
24 the SMBus and the ISA bus very much easier. See lm78.c for an example 26 LM78 had both an I2C and an ISA interface). They used to be
25 of this. */ 27 registered with the main i2c-core, but as a first step in the
28 direction of a clean separation between I2C and ISA chip drivers,
29 we now have this separate core for ISA ones. It is significantly
30 more simple than the real one, of course, because we don't have to
31 handle multiple busses: there is only one (fake) ISA adapter.
32 It is worth noting that we still rely on i2c-core for some things
33 at the moment - but hopefully this won't last. */
26 34
27#include <linux/config.h>
28#include <linux/init.h> 35#include <linux/init.h>
29#include <linux/module.h> 36#include <linux/module.h>
30#include <linux/kernel.h> 37#include <linux/kernel.h>
31#include <linux/errno.h> 38#include <linux/errno.h>
32#include <linux/i2c.h> 39#include <linux/i2c.h>
40#include <linux/i2c-isa.h>
33 41
34static u32 isa_func(struct i2c_adapter *adapter); 42static u32 isa_func(struct i2c_adapter *adapter);
35 43
36/* This is the actual algorithm we define */ 44/* This is the actual algorithm we define */
37static struct i2c_algorithm isa_algorithm = { 45static struct i2c_algorithm isa_algorithm = {
38 .name = "ISA bus algorithm",
39 .id = I2C_ALGO_ISA,
40 .functionality = isa_func, 46 .functionality = isa_func,
41}; 47};
42 48
43/* There can only be one... */ 49/* There can only be one... */
44static struct i2c_adapter isa_adapter = { 50static struct i2c_adapter isa_adapter = {
45 .owner = THIS_MODULE, 51 .owner = THIS_MODULE,
52 .id = I2C_HW_ISA,
46 .class = I2C_CLASS_HWMON, 53 .class = I2C_CLASS_HWMON,
47 .algo = &isa_algorithm, 54 .algo = &isa_algorithm,
48 .name = "ISA main adapter", 55 .name = "ISA main adapter",
@@ -54,17 +61,146 @@ static u32 isa_func(struct i2c_adapter *adapter)
54 return 0; 61 return 0;
55} 62}
56 63
64
65/* Copied from i2c-core */
66static ssize_t show_adapter_name(struct device *dev,
67 struct device_attribute *attr, char *buf)
68{
69 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
70 return sprintf(buf, "%s\n", adap->name);
71}
72static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
73
74static int i2c_isa_device_probe(struct device *dev)
75{
76 return -ENODEV;
77}
78
79static int i2c_isa_device_remove(struct device *dev)
80{
81 return 0;
82}
83
84
85/* We implement an interface which resembles i2c_{add,del}_driver,
86 but for i2c-isa drivers. We don't have to remember and handle lists
87 of drivers and adapters so this is much more simple, of course. */
88
89int i2c_isa_add_driver(struct i2c_driver *driver)
90{
91 int res;
92
93 /* Add the driver to the list of i2c drivers in the driver core */
94 driver->driver.name = driver->name;
95 driver->driver.bus = &i2c_bus_type;
96 driver->driver.probe = i2c_isa_device_probe;
97 driver->driver.remove = i2c_isa_device_remove;
98 res = driver_register(&driver->driver);
99 if (res)
100 return res;
101 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->name);
102
103 /* Now look for clients */
104 driver->attach_adapter(&isa_adapter);
105
106 return 0;
107}
108
109int i2c_isa_del_driver(struct i2c_driver *driver)
110{
111 struct list_head *item, *_n;
112 struct i2c_client *client;
113 int res;
114
115 /* Detach all clients belonging to this one driver */
116 list_for_each_safe(item, _n, &isa_adapter.clients) {
117 client = list_entry(item, struct i2c_client, list);
118 if (client->driver != driver)
119 continue;
120 dev_dbg(&isa_adapter.dev, "Detaching client %s at 0x%x\n",
121 client->name, client->addr);
122 if ((res = driver->detach_client(client))) {
123 dev_err(&isa_adapter.dev, "Failed, driver "
124 "%s not unregistered!\n",
125 driver->name);
126 return res;
127 }
128 }
129
130 /* Get the driver off the core list */
131 driver_unregister(&driver->driver);
132 dev_dbg(&isa_adapter.dev, "Driver %s unregistered\n", driver->name);
133
134 return 0;
135}
136
137
57static int __init i2c_isa_init(void) 138static int __init i2c_isa_init(void)
58{ 139{
59 return i2c_add_adapter(&isa_adapter); 140 init_MUTEX(&isa_adapter.clist_lock);
141 INIT_LIST_HEAD(&isa_adapter.clients);
142
143 isa_adapter.nr = ANY_I2C_ISA_BUS;
144 isa_adapter.dev.parent = &platform_bus;
145 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
146 isa_adapter.dev.driver = &i2c_adapter_driver;
147 isa_adapter.dev.release = &i2c_adapter_dev_release;
148 device_register(&isa_adapter.dev);
149 device_create_file(&isa_adapter.dev, &dev_attr_name);
150
151 /* Add this adapter to the i2c_adapter class */
152 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
153 isa_adapter.class_dev.dev = &isa_adapter.dev;
154 isa_adapter.class_dev.class = &i2c_adapter_class;
155 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
156 BUS_ID_SIZE);
157 class_device_register(&isa_adapter.class_dev);
158
159 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
160
161 return 0;
60} 162}
61 163
62static void __exit i2c_isa_exit(void) 164static void __exit i2c_isa_exit(void)
63{ 165{
64 i2c_del_adapter(&isa_adapter); 166#ifdef DEBUG
167 struct list_head *item, *_n;
168 struct i2c_client *client = NULL;
169#endif
170
171 /* There should be no more active client */
172#ifdef DEBUG
173 dev_dbg(&isa_adapter.dev, "Looking for clients\n");
174 list_for_each_safe(item, _n, &isa_adapter.clients) {
175 client = list_entry(item, struct i2c_client, list);
176 dev_err(&isa_adapter.dev, "Driver %s still has an active "
177 "ISA client at 0x%x\n", client->driver->name,
178 client->addr);
179 }
180 if (client != NULL)
181 return;
182#endif
183
184 /* Clean up the sysfs representation */
185 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
186 init_completion(&isa_adapter.dev_released);
187 init_completion(&isa_adapter.class_dev_released);
188 class_device_unregister(&isa_adapter.class_dev);
189 device_remove_file(&isa_adapter.dev, &dev_attr_name);
190 device_unregister(&isa_adapter.dev);
191
192 /* Wait for sysfs to drop all references */
193 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
194 wait_for_completion(&isa_adapter.dev_released);
195 wait_for_completion(&isa_adapter.class_dev_released);
196
197 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
65} 198}
66 199
67MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>"); 200EXPORT_SYMBOL(i2c_isa_add_driver);
201EXPORT_SYMBOL(i2c_isa_del_driver);
202
203MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
68MODULE_DESCRIPTION("ISA bus access through i2c"); 204MODULE_DESCRIPTION("ISA bus access through i2c");
69MODULE_LICENSE("GPL"); 205MODULE_LICENSE("GPL");
70 206
diff --git a/drivers/i2c/busses/i2c-ite.c b/drivers/i2c/busses/i2c-ite.c
index 702e3def1b81..5f5d2944808b 100644
--- a/drivers/i2c/busses/i2c-ite.c
+++ b/drivers/i2c/busses/i2c-ite.c
@@ -33,7 +33,6 @@
33/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 33/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
34 Frodo Looijaard <frodol@dds.nl> */ 34 Frodo Looijaard <frodol@dds.nl> */
35 35
36#include <linux/config.h>
37#include <linux/kernel.h> 36#include <linux/kernel.h>
38#include <linux/ioport.h> 37#include <linux/ioport.h>
39#include <linux/module.h> 38#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index 21cd54d02302..1956af382cd8 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -26,11 +26,6 @@
26 * 'enabled' to drive the GPIOs. 26 * 'enabled' to drive the GPIOs.
27 */ 27 */
28 28
29#include <linux/config.h>
30#ifdef CONFIG_I2C_DEBUG_BUS
31#define DEBUG 1
32#endif
33
34#include <linux/kernel.h> 29#include <linux/kernel.h>
35#include <linux/init.h> 30#include <linux/init.h>
36#include <linux/device.h> 31#include <linux/device.h>
@@ -38,7 +33,8 @@
38#include <linux/i2c.h> 33#include <linux/i2c.h>
39#include <linux/i2c-algo-bit.h> 34#include <linux/i2c-algo-bit.h>
40 35
41#include <asm/hardware.h> /* Pick up IXP42000-specific bits */ 36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */
37#include <asm/arch/gpio.h>
42 38
43static inline int ixp2000_scl_pin(void *data) 39static inline int ixp2000_scl_pin(void *data)
44{ 40{
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 8c55eafc3a09..f6f5ca31fdba 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -26,11 +26,6 @@
26 * that is passed as the platform_data to this driver. 26 * that is passed as the platform_data to this driver.
27 */ 27 */
28 28
29#include <linux/config.h>
30#ifdef CONFIG_I2C_DEBUG_BUS
31#define DEBUG 1
32#endif
33
34#include <linux/kernel.h> 29#include <linux/kernel.h>
35#include <linux/init.h> 30#include <linux/init.h>
36#include <linux/device.h> 31#include <linux/device.h>
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index 867d443e7133..37b49c2daf5f 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -46,7 +46,6 @@
46 sound driver to be happy 46 sound driver to be happy
47*/ 47*/
48 48
49#include <linux/config.h>
50#include <linux/module.h> 49#include <linux/module.h>
51#include <linux/kernel.h> 50#include <linux/kernel.h>
52#include <linux/ioport.h> 51#include <linux/ioport.h>
@@ -88,12 +87,9 @@ static const char *__kw_state_names[] = {
88}; 87};
89#endif /* DEBUG */ 88#endif /* DEBUG */
90 89
91static int probe;
92
93MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>"); 90MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
94MODULE_DESCRIPTION("I2C driver for Apple's Keywest"); 91MODULE_DESCRIPTION("I2C driver for Apple's Keywest");
95MODULE_LICENSE("GPL"); 92MODULE_LICENSE("GPL");
96module_param(probe, bool, 0);
97 93
98#ifdef POLLED_MODE 94#ifdef POLLED_MODE
99/* Don't schedule, the g5 fan controller is too 95/* Don't schedule, the g5 fan controller is too
@@ -499,8 +495,6 @@ keywest_func(struct i2c_adapter * adapter)
499 495
500/* For now, we only handle combined mode (smbus) */ 496/* For now, we only handle combined mode (smbus) */
501static struct i2c_algorithm keywest_algorithm = { 497static struct i2c_algorithm keywest_algorithm = {
502 .name = "Keywest i2c",
503 .id = I2C_ALGO_SMBUS,
504 .smbus_xfer = keywest_smbus_xfer, 498 .smbus_xfer = keywest_smbus_xfer,
505 .master_xfer = keywest_xfer, 499 .master_xfer = keywest_xfer,
506 .functionality = keywest_func, 500 .functionality = keywest_func,
@@ -622,7 +616,6 @@ create_iface(struct device_node *np, struct device *dev)
622 sprintf(chan->adapter.name, "%s %d", np->parent->name, i); 616 sprintf(chan->adapter.name, "%s %d", np->parent->name, i);
623 chan->iface = iface; 617 chan->iface = iface;
624 chan->chan_no = i; 618 chan->chan_no = i;
625 chan->adapter.id = I2C_ALGO_SMBUS;
626 chan->adapter.algo = &keywest_algorithm; 619 chan->adapter.algo = &keywest_algorithm;
627 chan->adapter.algo_data = NULL; 620 chan->adapter.algo_data = NULL;
628 chan->adapter.client_register = NULL; 621 chan->adapter.client_register = NULL;
@@ -636,15 +629,6 @@ create_iface(struct device_node *np, struct device *dev)
636 chan->adapter.name); 629 chan->adapter.name);
637 i2c_set_adapdata(&chan->adapter, NULL); 630 i2c_set_adapdata(&chan->adapter, NULL);
638 } 631 }
639 if (probe) {
640 printk("Probe: ");
641 for (addr = 0x00; addr <= 0x7f; addr++) {
642 if (i2c_smbus_xfer(&chan->adapter,addr,
643 0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)
644 printk("%02x ", addr);
645 }
646 printk("\n");
647 }
648 } 632 }
649 633
650 printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n", 634 printk(KERN_INFO "Found KeyWest i2c on \"%s\", %d channel%s, stepping: %d bits\n",
@@ -699,7 +683,7 @@ dispose_iface(struct device *dev)
699} 683}
700 684
701static int 685static int
702create_iface_macio(struct macio_dev* dev, const struct of_match *match) 686create_iface_macio(struct macio_dev* dev, const struct of_device_id *match)
703{ 687{
704 return create_iface(dev->ofdev.node, &dev->ofdev.dev); 688 return create_iface(dev->ofdev.node, &dev->ofdev.dev);
705} 689}
@@ -711,7 +695,7 @@ dispose_iface_macio(struct macio_dev* dev)
711} 695}
712 696
713static int 697static int
714create_iface_of_platform(struct of_device* dev, const struct of_match *match) 698create_iface_of_platform(struct of_device* dev, const struct of_device_id *match)
715{ 699{
716 return create_iface(dev->node, &dev->dev); 700 return create_iface(dev->node, &dev->dev);
717} 701}
@@ -722,10 +706,9 @@ dispose_iface_of_platform(struct of_device* dev)
722 return dispose_iface(&dev->dev); 706 return dispose_iface(&dev->dev);
723} 707}
724 708
725static struct of_match i2c_keywest_match[] = 709static struct of_device_id i2c_keywest_match[] =
726{ 710{
727 { 711 {
728 .name = OF_ANY_MATCH,
729 .type = "i2c", 712 .type = "i2c",
730 .compatible = "keywest" 713 .compatible = "keywest"
731 }, 714 },
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 6f33496d31c3..f065583ddcf1 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -20,13 +20,7 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <asm/io.h> 22#include <asm/io.h>
23#ifdef CONFIG_FSL_OCP
24#include <asm/ocp.h>
25#define FSL_I2C_DEV_SEPARATE_DFSRR FS_I2C_SEPARATE_DFSRR
26#define FSL_I2C_DEV_CLOCK_5200 FS_I2C_CLOCK_5200
27#else
28#include <linux/fsl_devices.h> 23#include <linux/fsl_devices.h>
29#endif
30#include <linux/i2c.h> 24#include <linux/i2c.h>
31#include <linux/interrupt.h> 25#include <linux/interrupt.h>
32#include <linux/delay.h> 26#include <linux/delay.h>
@@ -278,8 +272,6 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
278} 272}
279 273
280static struct i2c_algorithm mpc_algo = { 274static struct i2c_algorithm mpc_algo = {
281 .name = "MPC algorithm",
282 .id = I2C_ALGO_MPC107,
283 .master_xfer = mpc_xfer, 275 .master_xfer = mpc_xfer,
284 .functionality = mpc_functionality, 276 .functionality = mpc_functionality,
285}; 277};
@@ -287,114 +279,13 @@ static struct i2c_algorithm mpc_algo = {
287static struct i2c_adapter mpc_ops = { 279static struct i2c_adapter mpc_ops = {
288 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
289 .name = "MPC adapter", 281 .name = "MPC adapter",
290 .id = I2C_ALGO_MPC107 | I2C_HW_MPC107, 282 .id = I2C_HW_MPC107,
291 .algo = &mpc_algo, 283 .algo = &mpc_algo,
292 .class = I2C_CLASS_HWMON, 284 .class = I2C_CLASS_HWMON,
293 .timeout = 1, 285 .timeout = 1,
294 .retries = 1 286 .retries = 1
295}; 287};
296 288
297#ifdef CONFIG_FSL_OCP
298static int __devinit mpc_i2c_probe(struct ocp_device *ocp)
299{
300 int result = 0;
301 struct mpc_i2c *i2c;
302
303 if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) {
304 return -ENOMEM;
305 }
306 memset(i2c, 0, sizeof(*i2c));
307
308 i2c->irq = ocp->def->irq;
309 i2c->flags = ((struct ocp_fs_i2c_data *)ocp->def->additions)->flags;
310 init_waitqueue_head(&i2c->queue);
311
312 if (!request_mem_region(ocp->def->paddr, MPC_I2C_REGION, "i2c-mpc")) {
313 printk(KERN_ERR "i2c-mpc - resource unavailable\n");
314 return -ENODEV;
315 }
316
317 i2c->base = ioremap(ocp->def->paddr, MPC_I2C_REGION);
318
319 if (!i2c->base) {
320 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
321 result = -ENOMEM;
322 goto fail_map;
323 }
324
325 if (i2c->irq != OCP_IRQ_NA)
326 {
327 if ((result = request_irq(ocp->def->irq, mpc_i2c_isr,
328 0, "i2c-mpc", i2c)) < 0) {
329 printk(KERN_ERR
330 "i2c-mpc - failed to attach interrupt\n");
331 goto fail_irq;
332 }
333 } else
334 i2c->irq = 0;
335
336 i2c->adap = mpc_ops;
337 i2c_set_adapdata(&i2c->adap, i2c);
338
339 if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
340 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
341 goto fail_add;
342 }
343
344 mpc_i2c_setclock(i2c);
345 ocp_set_drvdata(ocp, i2c);
346 return result;
347
348 fail_add:
349 if (ocp->def->irq != OCP_IRQ_NA)
350 free_irq(ocp->def->irq, 0);
351 fail_irq:
352 iounmap(i2c->base);
353 fail_map:
354 release_mem_region(ocp->def->paddr, MPC_I2C_REGION);
355 kfree(i2c);
356 return result;
357}
358static void __devexit mpc_i2c_remove(struct ocp_device *ocp)
359{
360 struct mpc_i2c *i2c = ocp_get_drvdata(ocp);
361 ocp_set_drvdata(ocp, NULL);
362 i2c_del_adapter(&i2c->adap);
363
364 if (ocp->def->irq != OCP_IRQ_NA)
365 free_irq(i2c->irq, i2c);
366 iounmap(i2c->base);
367 release_mem_region(ocp->def->paddr, MPC_I2C_REGION);
368 kfree(i2c);
369}
370
371static struct ocp_device_id mpc_iic_ids[] __devinitdata = {
372 {.vendor = OCP_VENDOR_FREESCALE,.function = OCP_FUNC_IIC},
373 {.vendor = OCP_VENDOR_INVALID}
374};
375
376MODULE_DEVICE_TABLE(ocp, mpc_iic_ids);
377
378static struct ocp_driver mpc_iic_driver = {
379 .name = "iic",
380 .id_table = mpc_iic_ids,
381 .probe = mpc_i2c_probe,
382 .remove = __devexit_p(mpc_i2c_remove)
383};
384
385static int __init iic_init(void)
386{
387 return ocp_register_driver(&mpc_iic_driver);
388}
389
390static void __exit iic_exit(void)
391{
392 ocp_unregister_driver(&mpc_iic_driver);
393}
394
395module_init(iic_init);
396module_exit(iic_exit);
397#else
398static int fsl_i2c_probe(struct device *device) 289static int fsl_i2c_probe(struct device *device)
399{ 290{
400 int result = 0; 291 int result = 0;
@@ -424,12 +315,15 @@ static int fsl_i2c_probe(struct device *device)
424 315
425 if (i2c->irq != 0) 316 if (i2c->irq != 0)
426 if ((result = request_irq(i2c->irq, mpc_i2c_isr, 317 if ((result = request_irq(i2c->irq, mpc_i2c_isr,
427 0, "fsl-i2c", i2c)) < 0) { 318 SA_SHIRQ, "i2c-mpc", i2c)) < 0) {
428 printk(KERN_ERR 319 printk(KERN_ERR
429 "i2c-mpc - failed to attach interrupt\n"); 320 "i2c-mpc - failed to attach interrupt\n");
430 goto fail_irq; 321 goto fail_irq;
431 } 322 }
432 323
324 mpc_i2c_setclock(i2c);
325 dev_set_drvdata(device, i2c);
326
433 i2c->adap = mpc_ops; 327 i2c->adap = mpc_ops;
434 i2c_set_adapdata(&i2c->adap, i2c); 328 i2c_set_adapdata(&i2c->adap, i2c);
435 i2c->adap.dev.parent = &pdev->dev; 329 i2c->adap.dev.parent = &pdev->dev;
@@ -438,8 +332,6 @@ static int fsl_i2c_probe(struct device *device)
438 goto fail_add; 332 goto fail_add;
439 } 333 }
440 334
441 mpc_i2c_setclock(i2c);
442 dev_set_drvdata(device, i2c);
443 return result; 335 return result;
444 336
445 fail_add: 337 fail_add:
@@ -456,8 +348,8 @@ static int fsl_i2c_remove(struct device *device)
456{ 348{
457 struct mpc_i2c *i2c = dev_get_drvdata(device); 349 struct mpc_i2c *i2c = dev_get_drvdata(device);
458 350
459 dev_set_drvdata(device, NULL);
460 i2c_del_adapter(&i2c->adap); 351 i2c_del_adapter(&i2c->adap);
352 dev_set_drvdata(device, NULL);
461 353
462 if (i2c->irq != 0) 354 if (i2c->irq != 0)
463 free_irq(i2c->irq, i2c); 355 free_irq(i2c->irq, i2c);
@@ -488,8 +380,6 @@ static void __exit fsl_i2c_exit(void)
488module_init(fsl_i2c_init); 380module_init(fsl_i2c_init);
489module_exit(fsl_i2c_exit); 381module_exit(fsl_i2c_exit);
490 382
491#endif /* CONFIG_FSL_OCP */
492
493MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>"); 383MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
494MODULE_DESCRIPTION 384MODULE_DESCRIPTION
495 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors"); 385 ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors");
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 5b852782d2f5..99abca45fece 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -423,18 +423,16 @@ static int
423mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) 423mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
424{ 424{
425 struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap); 425 struct mv64xxx_i2c_data *drv_data = i2c_get_adapdata(adap);
426 int i, rc = 0; 426 int i, rc;
427 427
428 for (i=0; i<num; i++) 428 for (i=0; i<num; i++)
429 if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) != 0) 429 if ((rc = mv64xxx_i2c_execute_msg(drv_data, &msgs[i])) < 0)
430 break; 430 return rc;
431 431
432 return rc; 432 return num;
433} 433}
434 434
435static struct i2c_algorithm mv64xxx_i2c_algo = { 435static struct i2c_algorithm mv64xxx_i2c_algo = {
436 .name = MV64XXX_I2C_CTLR_NAME " algorithm",
437 .id = I2C_ALGO_MV64XXX,
438 .master_xfer = mv64xxx_i2c_xfer, 436 .master_xfer = mv64xxx_i2c_xfer,
439 .functionality = mv64xxx_i2c_functionality, 437 .functionality = mv64xxx_i2c_functionality,
440}; 438};
@@ -523,7 +521,7 @@ mv64xxx_i2c_probe(struct device *dev)
523 drv_data->freq_m = pdata->freq_m; 521 drv_data->freq_m = pdata->freq_m;
524 drv_data->freq_n = pdata->freq_n; 522 drv_data->freq_n = pdata->freq_n;
525 drv_data->irq = platform_get_irq(pd, 0); 523 drv_data->irq = platform_get_irq(pd, 0);
526 drv_data->adapter.id = I2C_ALGO_MV64XXX | I2C_HW_MV64XXX; 524 drv_data->adapter.id = I2C_HW_MV64XXX;
527 drv_data->adapter.algo = &mv64xxx_i2c_algo; 525 drv_data->adapter.algo = &mv64xxx_i2c_algo;
528 drv_data->adapter.owner = THIS_MODULE; 526 drv_data->adapter.owner = THIS_MODULE;
529 drv_data->adapter.class = I2C_CLASS_HWMON; 527 drv_data->adapter.class = I2C_CLASS_HWMON;
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 6d13127c8c4e..e0b7a913431e 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -37,7 +37,6 @@
37 37
38/* Note: we assume there can only be one nForce2, with two SMBus interfaces */ 38/* Note: we assume there can only be one nForce2, with two SMBus interfaces */
39 39
40#include <linux/config.h>
41#include <linux/module.h> 40#include <linux/module.h>
42#include <linux/pci.h> 41#include <linux/pci.h>
43#include <linux/kernel.h> 42#include <linux/kernel.h>
@@ -111,8 +110,6 @@ static u32 nforce2_func(struct i2c_adapter *adapter);
111 110
112 111
113static struct i2c_algorithm smbus_algorithm = { 112static struct i2c_algorithm smbus_algorithm = {
114 .name = "Non-I2C SMBus adapter",
115 .id = I2C_ALGO_SMBUS,
116 .smbus_xfer = nforce2_access, 113 .smbus_xfer = nforce2_access,
117 .functionality = nforce2_func, 114 .functionality = nforce2_func,
118}; 115};
@@ -132,7 +129,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
132 struct nforce2_smbus *smbus = adap->algo_data; 129 struct nforce2_smbus *smbus = adap->algo_data;
133 unsigned char protocol, pec, temp; 130 unsigned char protocol, pec, temp;
134 unsigned char len = 0; /* to keep the compiler quiet */ 131 unsigned char len = 0; /* to keep the compiler quiet */
135 int timeout = 0;
136 int i; 132 int i;
137 133
138 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 134 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
@@ -192,29 +188,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
192 case I2C_SMBUS_PROC_CALL: 188 case I2C_SMBUS_PROC_CALL:
193 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 189 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
194 return -1; 190 return -1;
195 /*
196 outb_p(command, NVIDIA_SMB_CMD);
197 outb_p(data->word, NVIDIA_SMB_DATA);
198 outb_p(data->word >> 8, NVIDIA_SMB_DATA + 1);
199 protocol = NVIDIA_SMB_PRTCL_PROC_CALL | pec;
200 read_write = I2C_SMBUS_READ;
201 break;
202 */
203 191
204 case I2C_SMBUS_BLOCK_PROC_CALL: 192 case I2C_SMBUS_BLOCK_PROC_CALL:
205 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); 193 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n");
206 return -1; 194 return -1;
207 /*
208 protocol |= pec;
209 len = min_t(u8, data->block[0], 31);
210 outb_p(command, NVIDIA_SMB_CMD);
211 outb_p(len, NVIDIA_SMB_BCNT);
212 for (i = 0; i < len; i++)
213 outb_p(data->block[i + 1], NVIDIA_SMB_DATA + i);
214 protocol = NVIDIA_SMB_PRTCL_BLOCK_PROC_CALL | pec;
215 read_write = I2C_SMBUS_READ;
216 break;
217 */
218 195
219 case I2C_SMBUS_WORD_DATA_PEC: 196 case I2C_SMBUS_WORD_DATA_PEC:
220 case I2C_SMBUS_BLOCK_DATA_PEC: 197 case I2C_SMBUS_BLOCK_DATA_PEC:
@@ -233,12 +210,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
233 210
234 temp = inb_p(NVIDIA_SMB_STS); 211 temp = inb_p(NVIDIA_SMB_STS);
235 212
236#if 0
237 do {
238 i2c_do_pause(1);
239 temp = inb_p(NVIDIA_SMB_STS);
240 } while (((temp & NVIDIA_SMB_STS_DONE) == 0) && (timeout++ < MAX_TIMEOUT));
241#endif
242 if (~temp & NVIDIA_SMB_STS_DONE) { 213 if (~temp & NVIDIA_SMB_STS_DONE) {
243 udelay(500); 214 udelay(500);
244 temp = inb_p(NVIDIA_SMB_STS); 215 temp = inb_p(NVIDIA_SMB_STS);
@@ -248,9 +219,10 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
248 temp = inb_p(NVIDIA_SMB_STS); 219 temp = inb_p(NVIDIA_SMB_STS);
249 } 220 }
250 221
251 if ((timeout >= MAX_TIMEOUT) || (~temp & NVIDIA_SMB_STS_DONE) 222 if ((~temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) {
252 || (temp & NVIDIA_SMB_STS_STATUS)) 223 dev_dbg(&adap->dev, "SMBus Timeout! (0x%02x)\n", temp);
253 return -1; 224 return -1;
225 }
254 226
255 if (read_write == I2C_SMBUS_WRITE) 227 if (read_write == I2C_SMBUS_WRITE)
256 return 0; 228 return 0;
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index cb5e722301d8..3e5eba9fcacb 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -24,7 +24,6 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ------------------------------------------------------------------------ */ 25 * ------------------------------------------------------------------------ */
26 26
27#include <linux/config.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/init.h> 29#include <linux/init.h>
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index e9560bab51c4..71a2502fe069 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -24,7 +24,6 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ------------------------------------------------------------------------ */ 25 * ------------------------------------------------------------------------ */
26 26
27#include <linux/config.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/init.h> 29#include <linux/init.h>
@@ -131,7 +130,7 @@ static int parport_getsda(void *data)
131/* Encapsulate the functions above in the correct structure. 130/* Encapsulate the functions above in the correct structure.
132 Note that this is only a template, from which the real structures are 131 Note that this is only a template, from which the real structures are
133 copied. The attaching code will set getscl to NULL for adapters that 132 copied. The attaching code will set getscl to NULL for adapters that
134 cannot read SCL back, and will also make the the data field point to 133 cannot read SCL back, and will also make the data field point to
135 the parallel port structure. */ 134 the parallel port structure. */
136static struct i2c_algo_bit_data parport_algo_data = { 135static struct i2c_algo_bit_data parport_algo_data = {
137 .setsda = parport_setsda, 136 .setsda = parport_setsda,
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 9c611134db9c..d9b4ddbad7e0 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -17,7 +17,6 @@
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 19
20#include <linux/config.h>
21#include <linux/kernel.h> 20#include <linux/kernel.h>
22#include <linux/ioport.h> 21#include <linux/ioport.h>
23#include <linux/module.h> 22#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 646381b6b3bf..6d48a4da7bed 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -28,7 +28,6 @@
28 Note: we assume there can only be one device, with one SMBus interface. 28 Note: we assume there can only be one device, with one SMBus interface.
29*/ 29*/
30 30
31#include <linux/config.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/moduleparam.h> 32#include <linux/moduleparam.h>
34#include <linux/pci.h> 33#include <linux/pci.h>
@@ -244,7 +243,7 @@ static int piix4_transaction(void)
244 /* Make sure the SMBus host is ready to start transmitting */ 243 /* Make sure the SMBus host is ready to start transmitting */
245 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 244 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
246 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). " 245 dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). "
247 "Resetting... \n", temp); 246 "Resetting...\n", temp);
248 outb_p(temp, SMBHSTSTS); 247 outb_p(temp, SMBHSTSTS);
249 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 248 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
250 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 249 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
@@ -400,8 +399,6 @@ static u32 piix4_func(struct i2c_adapter *adapter)
400} 399}
401 400
402static struct i2c_algorithm smbus_algorithm = { 401static struct i2c_algorithm smbus_algorithm = {
403 .name = "Non-I2C SMBus adapter",
404 .id = I2C_ALGO_SMBUS,
405 .smbus_xfer = piix4_access, 402 .smbus_xfer = piix4_access,
406 .functionality = piix4_func, 403 .functionality = piix4_func,
407}; 404};
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 13d66289933b..83fd16d61ce5 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -54,7 +54,6 @@
54 * (Additional documentation needed :( 54 * (Additional documentation needed :(
55 */ 55 */
56 56
57#include <linux/config.h>
58#include <linux/module.h> 57#include <linux/module.h>
59#include <linux/init.h> 58#include <linux/init.h>
60#include <linux/pci.h> 59#include <linux/pci.h>
diff --git a/drivers/i2c/busses/i2c-rpx.c b/drivers/i2c/busses/i2c-rpx.c
index 9497b1b6852f..0ebec3c1a54e 100644
--- a/drivers/i2c/busses/i2c-rpx.c
+++ b/drivers/i2c/busses/i2c-rpx.c
@@ -11,7 +11,6 @@
11 * changed to eliminate RPXLite references. 11 * changed to eliminate RPXLite references.
12 */ 12 */
13 13
14#include <linux/config.h>
15#include <linux/kernel.h> 14#include <linux/kernel.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/init.h> 16#include <linux/init.h>
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index fcfa51c1436b..73a092fb0e7e 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -20,6 +20,7 @@
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/ 21*/
22 22
23#include <linux/config.h>
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/module.h> 25#include <linux/module.h>
25 26
@@ -533,7 +534,7 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int
533/* s3c24xx_i2c_xfer 534/* s3c24xx_i2c_xfer
534 * 535 *
535 * first port of call from the i2c bus code when an message needs 536 * first port of call from the i2c bus code when an message needs
536 * transfering across the i2c bus. 537 * transferring across the i2c bus.
537*/ 538*/
538 539
539static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, 540static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
@@ -567,7 +568,6 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
567/* i2c bus registration info */ 568/* i2c bus registration info */
568 569
569static struct i2c_algorithm s3c24xx_i2c_algorithm = { 570static struct i2c_algorithm s3c24xx_i2c_algorithm = {
570 .name = "S3C2410-I2C-Algorithm",
571 .master_xfer = s3c24xx_i2c_xfer, 571 .master_xfer = s3c24xx_i2c_xfer,
572 .functionality = s3c24xx_i2c_func, 572 .functionality = s3c24xx_i2c_func,
573}; 573};
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 092d0323c6c6..0c8518298e4d 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -29,7 +29,6 @@
29 it easier to add later. 29 it easier to add later.
30*/ 30*/
31 31
32#include <linux/config.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/module.h> 33#include <linux/module.h>
35#include <linux/init.h> 34#include <linux/init.h>
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index e5dd90bdb04a..fa503ed9f86d 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -17,15 +17,14 @@
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */ 18 */
19 19
20#include <linux/config.h>
21#include <linux/module.h> 20#include <linux/module.h>
22#include <linux/i2c-algo-sibyte.h> 21#include <linux/i2c-algo-sibyte.h>
23#include <asm/sibyte/sb1250_regs.h> 22#include <asm/sibyte/sb1250_regs.h>
24#include <asm/sibyte/sb1250_smbus.h> 23#include <asm/sibyte/sb1250_smbus.h>
25 24
26static struct i2c_algo_sibyte_data sibyte_board_data[2] = { 25static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
27 { NULL, 0, (void *) (KSEG1+A_SMB_BASE(0)) }, 26 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) },
28 { NULL, 1, (void *) (KSEG1+A_SMB_BASE(1)) } 27 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) }
29}; 28};
30 29
31static struct i2c_adapter sibyte_board_adapter[2] = { 30static struct i2c_adapter sibyte_board_adapter[2] = {
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 425733b019b6..080318d6f54b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -55,7 +55,6 @@
55 * Add adapter resets 55 * Add adapter resets
56 */ 56 */
57 57
58#include <linux/config.h>
59#include <linux/kernel.h> 58#include <linux/kernel.h>
60#include <linux/module.h> 59#include <linux/module.h>
61#include <linux/delay.h> 60#include <linux/delay.h>
@@ -229,7 +228,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
229 /* Make sure the SMBus host is ready to start transmitting */ 228 /* Make sure the SMBus host is ready to start transmitting */
230 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); 229 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
231 if (temp != 0x00) { 230 if (temp != 0x00) {
232 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting... \n", temp); 231 dev_dbg(&adap->dev, "SMBus busy (%04x). Resetting...\n", temp);
233 sis5595_write(SMB_STS_LO, temp & 0xff); 232 sis5595_write(SMB_STS_LO, temp & 0xff);
234 sis5595_write(SMB_STS_HI, temp >> 8); 233 sis5595_write(SMB_STS_HI, temp >> 8);
235 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { 234 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
@@ -358,8 +357,6 @@ static u32 sis5595_func(struct i2c_adapter *adapter)
358} 357}
359 358
360static struct i2c_algorithm smbus_algorithm = { 359static struct i2c_algorithm smbus_algorithm = {
361 .name = "Non-I2C SMBus adapter",
362 .id = I2C_ALGO_SMBUS,
363 .smbus_xfer = sis5595_access, 360 .smbus_xfer = sis5595_access,
364 .functionality = sis5595_func, 361 .functionality = sis5595_func,
365}; 362};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 58df63df1540..86f0f448fa0b 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -48,7 +48,6 @@
48 Note: we assume there can only be one device, with one SMBus interface. 48 Note: we assume there can only be one device, with one SMBus interface.
49*/ 49*/
50 50
51#include <linux/config.h>
52#include <linux/kernel.h> 51#include <linux/kernel.h>
53#include <linux/module.h> 52#include <linux/module.h>
54#include <linux/delay.h> 53#include <linux/delay.h>
@@ -449,8 +448,6 @@ exit:
449 448
450 449
451static struct i2c_algorithm smbus_algorithm = { 450static struct i2c_algorithm smbus_algorithm = {
452 .name = "Non-I2C SMBus adapter",
453 .id = I2C_ALGO_SMBUS,
454 .smbus_xfer = sis630_access, 451 .smbus_xfer = sis630_access,
455 .functionality = sis630_func, 452 .functionality = sis630_func,
456}; 453};
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 3cac6d43bce5..ead2ff3cf60e 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -32,7 +32,6 @@
32 We assume there can only be one SiS96x with one SMBus interface. 32 We assume there can only be one SiS96x with one SMBus interface.
33*/ 33*/
34 34
35#include <linux/config.h>
36#include <linux/module.h> 35#include <linux/module.h>
37#include <linux/pci.h> 36#include <linux/pci.h>
38#include <linux/kernel.h> 37#include <linux/kernel.h>
@@ -250,8 +249,6 @@ static u32 sis96x_func(struct i2c_adapter *adapter)
250} 249}
251 250
252static struct i2c_algorithm smbus_algorithm = { 251static struct i2c_algorithm smbus_algorithm = {
253 .name = "Non-I2C SMBus adapter",
254 .id = I2C_ALGO_SMBUS,
255 .smbus_xfer = sis96x_access, 252 .smbus_xfer = sis96x_access,
256 .functionality = sis96x_func, 253 .functionality = sis96x_func,
257}; 254};
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 19c805ead4d8..73f481e93a36 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -21,7 +21,6 @@
21 21
22#define DEBUG 1 22#define DEBUG 1
23 23
24#include <linux/config.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/module.h> 25#include <linux/module.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -110,8 +109,6 @@ static u32 stub_func(struct i2c_adapter *adapter)
110} 109}
111 110
112static struct i2c_algorithm smbus_algorithm = { 111static struct i2c_algorithm smbus_algorithm = {
113 .name = "Non-I2C SMBus adapter",
114 .id = I2C_ALGO_SMBUS,
115 .functionality = stub_func, 112 .functionality = stub_func,
116 .smbus_xfer = stub_xfer, 113 .smbus_xfer = stub_xfer,
117}; 114};
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 2cbc4cd22366..040b8abeabba 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -21,7 +21,6 @@
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 22*/
23 23
24#include <linux/config.h>
25#include <linux/kernel.h> 24#include <linux/kernel.h>
26#include <linux/module.h> 25#include <linux/module.h>
27#include <linux/pci.h> 26#include <linux/pci.h>
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 0bb60a636e16..99d209e0485a 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -33,7 +33,6 @@
33 Note: we assume there can only be one device, with one SMBus interface. 33 Note: we assume there can only be one device, with one SMBus interface.
34*/ 34*/
35 35
36#include <linux/config.h>
37#include <linux/module.h> 36#include <linux/module.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/pci.h> 38#include <linux/pci.h>
@@ -287,8 +286,6 @@ static u32 vt596_func(struct i2c_adapter *adapter)
287} 286}
288 287
289static struct i2c_algorithm smbus_algorithm = { 288static struct i2c_algorithm smbus_algorithm = {
290 .name = "Non-I2C SMBus adapter",
291 .id = I2C_ALGO_SMBUS,
292 .smbus_xfer = vt596_access, 289 .smbus_xfer = vt596_access,
293 .functionality = vt596_func, 290 .functionality = vt596_func,
294}; 291};
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index 3edf0e34155e..b675773b0cc1 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -27,7 +27,6 @@
27/* This interfaces to the I2C bus of the Voodoo3 to gain access to 27/* This interfaces to the I2C bus of the Voodoo3 to gain access to
28 the BT869 and possibly other I2C devices. */ 28 the BT869 and possibly other I2C devices. */
29 29
30#include <linux/config.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/init.h> 32#include <linux/init.h>
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 1c4159a93623..a1d580e05361 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -24,7 +24,6 @@
24 24
25*/ 25*/
26 26
27#include <linux/config.h>
28#include <linux/module.h> 27#include <linux/module.h>
29#include <linux/errno.h> 28#include <linux/errno.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
@@ -396,8 +395,6 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
396 395
397/* For now, we only handle combined mode (smbus) */ 396/* For now, we only handle combined mode (smbus) */
398static struct i2c_algorithm scx200_acb_algorithm = { 397static struct i2c_algorithm scx200_acb_algorithm = {
399 .name = "NatSemi SCx200 ACCESS.bus",
400 .id = I2C_ALGO_SMBUS,
401 .smbus_xfer = scx200_acb_smbus_xfer, 398 .smbus_xfer = scx200_acb_smbus_xfer,
402 .functionality = scx200_acb_func, 399 .functionality = scx200_acb_func,
403}; 400};
@@ -457,7 +454,7 @@ static int __init scx200_acb_create(int base, int index)
457 i2c_set_adapdata(adapter, iface); 454 i2c_set_adapdata(adapter, iface);
458 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); 455 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index);
459 adapter->owner = THIS_MODULE; 456 adapter->owner = THIS_MODULE;
460 adapter->id = I2C_ALGO_SMBUS; 457 adapter->id = I2C_HW_SMBUS_SCX200;
461 adapter->algo = &scx200_acb_algorithm; 458 adapter->algo = &scx200_acb_algorithm;
462 adapter->class = I2C_CLASS_HWMON; 459 adapter->class = I2C_CLASS_HWMON;
463 460
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 74d23cfce2a3..6bd44a44cd28 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -1,385 +1,33 @@
1# 1#
2# I2C Sensor device configuration 2# Miscellaneous I2C chip drivers configuration
3# 3#
4 4
5menu "Hardware Sensors Chip support" 5menu "Miscellaneous I2C Chip support"
6 depends on I2C 6 depends on I2C
7 7
8config I2C_SENSOR 8config SENSORS_DS1337
9 tristate 9 tristate "Dallas Semiconductor DS1337 and DS1339 Real Time Clock"
10 default n
11
12config SENSORS_ADM1021
13 tristate "Analog Devices ADM1021 and compatibles"
14 depends on I2C && EXPERIMENTAL
15 select I2C_SENSOR
16 help
17 If you say yes here you get support for Analog Devices ADM1021
18 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
19 Genesys Logic GL523SM, National Semiconductor LM84, TI THMC10,
20 and the XEON processor built-in sensor.
21
22 This driver can also be built as a module. If so, the module
23 will be called adm1021.
24
25config SENSORS_ADM1025
26 tristate "Analog Devices ADM1025 and compatibles"
27 depends on I2C && EXPERIMENTAL
28 select I2C_SENSOR
29 help
30 If you say yes here you get support for Analog Devices ADM1025
31 and Philips NE1619 sensor chips.
32 This driver can also be built as a module. If so, the module
33 will be called adm1025.
34
35config SENSORS_ADM1026
36 tristate "Analog Devices ADM1026 and compatibles"
37 depends on I2C && EXPERIMENTAL
38 select I2C_SENSOR
39 help
40 If you say yes here you get support for Analog Devices ADM1026
41 This driver can also be built as a module. If so, the module
42 will be called adm1026.
43
44config SENSORS_ADM1031
45 tristate "Analog Devices ADM1031 and compatibles"
46 depends on I2C && EXPERIMENTAL
47 select I2C_SENSOR
48 help
49 If you say yes here you get support for Analog Devices ADM1031
50 and ADM1030 sensor chips.
51 This driver can also be built as a module. If so, the module
52 will be called adm1031.
53
54config SENSORS_ASB100
55 tristate "Asus ASB100 Bach"
56 depends on I2C && EXPERIMENTAL
57 select I2C_SENSOR
58 help
59 If you say yes here you get support for the ASB100 Bach sensor
60 chip found on some Asus mainboards.
61
62 This driver can also be built as a module. If so, the module
63 will be called asb100.
64
65config SENSORS_DS1621
66 tristate "Dallas Semiconductor DS1621 and DS1625"
67 depends on I2C && EXPERIMENTAL 10 depends on I2C && EXPERIMENTAL
68 select I2C_SENSOR
69 help 11 help
70 If you say yes here you get support for Dallas Semiconductor 12 If you say yes here you get support for Dallas Semiconductor
71 DS1621 and DS1625 sensor chips. 13 DS1337 and DS1339 real-time clock chips.
72
73 This driver can also be built as a module. If so, the module
74 will be called ds1621.
75
76config SENSORS_FSCHER
77 tristate "FSC Hermes"
78 depends on I2C && EXPERIMENTAL
79 select I2C_SENSOR
80 help
81 If you say yes here you get support for Fujitsu Siemens
82 Computers Hermes sensor chips.
83
84 This driver can also be built as a module. If so, the module
85 will be called fscher.
86
87config SENSORS_FSCPOS
88 tristate "FSC Poseidon"
89 depends on I2C && EXPERIMENTAL
90 select I2C_SENSOR
91 help
92 If you say yes here you get support for Fujitsu Siemens
93 Computers Poseidon sensor chips.
94
95 This driver can also be built as a module. If so, the module
96 will be called fscpos.
97
98config SENSORS_GL518SM
99 tristate "Genesys Logic GL518SM"
100 depends on I2C && EXPERIMENTAL
101 select I2C_SENSOR
102 help
103 If you say yes here you get support for Genesys Logic GL518SM
104 sensor chips.
105
106 This driver can also be built as a module. If so, the module
107 will be called gl518sm.
108
109config SENSORS_GL520SM
110 tristate "Genesys Logic GL520SM"
111 depends on I2C && EXPERIMENTAL
112 select I2C_SENSOR
113 help
114 If you say yes here you get support for Genesys Logic GL520SM
115 sensor chips.
116
117 This driver can also be built as a module. If so, the module
118 will be called gl520sm.
119
120config SENSORS_IT87
121 tristate "ITE IT87xx and compatibles"
122 depends on I2C && EXPERIMENTAL
123 select I2C_SENSOR
124 help
125 If you say yes here you get support for ITE IT87xx sensor chips
126 and clones: SiS960.
127
128 This driver can also be built as a module. If so, the module
129 will be called it87.
130
131config SENSORS_LM63
132 tristate "National Semiconductor LM63"
133 depends on I2C && EXPERIMENTAL
134 select I2C_SENSOR
135 help
136 If you say yes here you get support for the National Semiconductor
137 LM63 remote diode digital temperature sensor with integrated fan
138 control. Such chips are found on the Tyan S4882 (Thunder K8QS Pro)
139 motherboard, among others.
140
141 This driver can also be built as a module. If so, the module
142 will be called lm63.
143
144config SENSORS_LM75
145 tristate "National Semiconductor LM75 and compatibles"
146 depends on I2C && EXPERIMENTAL
147 select I2C_SENSOR
148 help
149 If you say yes here you get support for National Semiconductor LM75
150 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
151 9-bit precision mode), and TelCom (now Microchip) TCN75.
152
153 The DS75 and DS1775 in 10- to 12-bit precision modes will require
154 a force module parameter. The driver will not handle the extra
155 precision anyhow.
156
157 This driver can also be built as a module. If so, the module
158 will be called lm75.
159
160config SENSORS_LM77
161 tristate "National Semiconductor LM77"
162 depends on I2C && EXPERIMENTAL
163 select I2C_SENSOR
164 help
165 If you say yes here you get support for National Semiconductor LM77
166 sensor chips.
167 14
168 This driver can also be built as a module. If so, the module 15 This driver can also be built as a module. If so, the module
169 will be called lm77. 16 will be called ds1337.
170
171config SENSORS_LM78
172 tristate "National Semiconductor LM78 and compatibles"
173 depends on I2C && EXPERIMENTAL
174 select I2C_SENSOR
175 help
176 If you say yes here you get support for National Semiconductor LM78,
177 LM78-J and LM79. This can also be built as a module which can be
178 inserted and removed while the kernel is running.
179
180 This driver can also be built as a module. If so, the module
181 will be called lm78.
182
183config SENSORS_LM80
184 tristate "National Semiconductor LM80"
185 depends on I2C && EXPERIMENTAL
186 select I2C_SENSOR
187 help
188 If you say yes here you get support for National Semiconductor
189 LM80 sensor chips.
190
191 This driver can also be built as a module. If so, the module
192 will be called lm80.
193
194config SENSORS_LM83
195 tristate "National Semiconductor LM83"
196 depends on I2C
197 select I2C_SENSOR
198 help
199 If you say yes here you get support for National Semiconductor
200 LM83 sensor chips.
201
202 This driver can also be built as a module. If so, the module
203 will be called lm83.
204
205config SENSORS_LM85
206 tristate "National Semiconductor LM85 and compatibles"
207 depends on I2C && EXPERIMENTAL
208 select I2C_SENSOR
209 help
210 If you say yes here you get support for National Semiconductor LM85
211 sensor chips and clones: ADT7463 and ADM1027.
212
213 This driver can also be built as a module. If so, the module
214 will be called lm85.
215
216config SENSORS_LM87
217 tristate "National Semiconductor LM87"
218 depends on I2C && EXPERIMENTAL
219 select I2C_SENSOR
220 help
221 If you say yes here you get support for National Semiconductor LM87
222 sensor chips.
223
224 This driver can also be built as a module. If so, the module
225 will be called lm87.
226
227config SENSORS_LM90
228 tristate "National Semiconductor LM90 and compatibles"
229 depends on I2C
230 select I2C_SENSOR
231 help
232 If you say yes here you get support for National Semiconductor LM90,
233 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
234 MAX6658 sensor chips.
235
236 The Analog Devices ADT7461 sensor chip is also supported, but only
237 if found in ADM1032 compatibility mode.
238
239 This driver can also be built as a module. If so, the module
240 will be called lm90.
241
242config SENSORS_LM92
243 tristate "National Semiconductor LM92 and compatibles"
244 depends on I2C && EXPERIMENTAL
245 select I2C_SENSOR
246 help
247 If you say yes here you get support for National Semiconductor LM92
248 and Maxim MAX6635 sensor chips.
249
250 This driver can also be built as a module. If so, the module
251 will be called lm92.
252
253config SENSORS_MAX1619
254 tristate "Maxim MAX1619 sensor chip"
255 depends on I2C && EXPERIMENTAL
256 select I2C_SENSOR
257 help
258 If you say yes here you get support for MAX1619 sensor chip.
259
260 This driver can also be built as a module. If so, the module
261 will be called max1619.
262
263config SENSORS_PC87360
264 tristate "National Semiconductor PC87360 family"
265 depends on I2C && EXPERIMENTAL
266 select I2C_SENSOR
267 select I2C_ISA
268 help
269 If you say yes here you get access to the hardware monitoring
270 functions of the National Semiconductor PC8736x Super-I/O chips.
271 The PC87360, PC87363 and PC87364 only have fan monitoring and
272 control. The PC87365 and PC87366 additionally have voltage and
273 temperature monitoring.
274
275 This driver can also be built as a module. If so, the module
276 will be called pc87360.
277
278config SENSORS_SMSC47B397
279 tristate "SMSC LPC47B397-NC"
280 depends on I2C && EXPERIMENTAL
281 select I2C_SENSOR
282 select I2C_ISA
283 help
284 If you say yes here you get support for the SMSC LPC47B397-NC
285 sensor chip.
286
287 This driver can also be built as a module. If so, the module
288 will be called smsc47b397.
289
290config SENSORS_SIS5595
291 tristate "Silicon Integrated Systems Corp. SiS5595"
292 depends on I2C && PCI && EXPERIMENTAL
293 select I2C_SENSOR
294 select I2C_ISA
295 help
296 If you say yes here you get support for the integrated sensors in
297 SiS5595 South Bridges.
298
299 This driver can also be built as a module. If so, the module
300 will be called sis5595.
301
302config SENSORS_SMSC47M1
303 tristate "SMSC LPC47M10x and compatibles"
304 depends on I2C && EXPERIMENTAL
305 select I2C_SENSOR
306 select I2C_ISA
307 help
308 If you say yes here you get support for the integrated fan
309 monitoring and control capabilities of the SMSC LPC47B27x,
310 LPC47M10x, LPC47M13x and LPC47M14x chips.
311
312 This driver can also be built as a module. If so, the module
313 will be called smsc47m1.
314
315config SENSORS_VIA686A
316 tristate "VIA686A"
317 depends on I2C && PCI && EXPERIMENTAL
318 select I2C_SENSOR
319 select I2C_ISA
320 help
321 If you say yes here you get support for the integrated sensors in
322 Via 686A/B South Bridges.
323
324 This driver can also be built as a module. If so, the module
325 will be called via686a.
326
327config SENSORS_W83781D
328 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
329 depends on I2C && EXPERIMENTAL
330 select I2C_SENSOR
331 help
332 If you say yes here you get support for the Winbond W8378x series
333 of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
334 and the similar Asus AS99127F.
335
336 This driver can also be built as a module. If so, the module
337 will be called w83781d.
338
339config SENSORS_W83L785TS
340 tristate "Winbond W83L785TS-S"
341 depends on I2C && EXPERIMENTAL
342 select I2C_SENSOR
343 help
344 If you say yes here you get support for the Winbond W83L785TS-S
345 sensor chip, which is used on the Asus A7N8X, among other
346 motherboards.
347
348 This driver can also be built as a module. If so, the module
349 will be called w83l785ts.
350
351config SENSORS_W83627HF
352 tristate "Winbond W83627HF, W83627THF, W83637HF, W83697HF"
353 depends on I2C && EXPERIMENTAL
354 select I2C_SENSOR
355 select I2C_ISA
356 help
357 If you say yes here you get support for the Winbond W836X7 series
358 of sensor chips: the W83627HF, W83627THF, W83637HF, and the W83697HF
359
360 This driver can also be built as a module. If so, the module
361 will be called w83627hf.
362
363endmenu
364
365menu "Other I2C Chip support"
366 depends on I2C
367 17
368config SENSORS_DS1337 18config SENSORS_DS1374
369 tristate "Dallas Semiconductor DS1337 Real Time Clock" 19 tristate "Maxim/Dallas Semiconductor DS1374 Real Time Clock"
370 depends on I2C && EXPERIMENTAL 20 depends on I2C && EXPERIMENTAL
371 select I2C_SENSOR
372 help 21 help
373 If you say yes here you get support for Dallas Semiconductor 22 If you say yes here you get support for Dallas Semiconductor
374 DS1337 real-time clock chips. 23 DS1374 real-time clock chips.
375 24
376 This driver can also be built as a module. If so, the module 25 This driver can also be built as a module. If so, the module
377 will be called ds1337. 26 will be called ds1374.
378 27
379config SENSORS_EEPROM 28config SENSORS_EEPROM
380 tristate "EEPROM reader" 29 tristate "EEPROM reader"
381 depends on I2C && EXPERIMENTAL 30 depends on I2C && EXPERIMENTAL
382 select I2C_SENSOR
383 help 31 help
384 If you say yes here you get read-only access to the EEPROM data 32 If you say yes here you get read-only access to the EEPROM data
385 available on modern memory DIMMs and Sony Vaio laptops. Such 33 available on modern memory DIMMs and Sony Vaio laptops. Such
@@ -391,7 +39,6 @@ config SENSORS_EEPROM
391config SENSORS_PCF8574 39config SENSORS_PCF8574
392 tristate "Philips PCF8574 and PCF8574A" 40 tristate "Philips PCF8574 and PCF8574A"
393 depends on I2C && EXPERIMENTAL 41 depends on I2C && EXPERIMENTAL
394 select I2C_SENSOR
395 help 42 help
396 If you say yes here you get support for Philips PCF8574 and 43 If you say yes here you get support for Philips PCF8574 and
397 PCF8574A chips. 44 PCF8574A chips.
@@ -399,10 +46,19 @@ config SENSORS_PCF8574
399 This driver can also be built as a module. If so, the module 46 This driver can also be built as a module. If so, the module
400 will be called pcf8574. 47 will be called pcf8574.
401 48
49config SENSORS_PCA9539
50 tristate "Philips PCA9539 16-bit I/O port"
51 depends on I2C && EXPERIMENTAL
52 help
53 If you say yes here you get support for the Philips PCA9539
54 16-bit I/O port.
55
56 This driver can also be built as a module. If so, the module
57 will be called pca9539.
58
402config SENSORS_PCF8591 59config SENSORS_PCF8591
403 tristate "Philips PCF8591" 60 tristate "Philips PCF8591"
404 depends on I2C && EXPERIMENTAL 61 depends on I2C && EXPERIMENTAL
405 select I2C_SENSOR
406 help 62 help
407 If you say yes here you get support for Philips PCF8591 chips. 63 If you say yes here you get support for Philips PCF8591 chips.
408 64
@@ -412,7 +68,6 @@ config SENSORS_PCF8591
412config SENSORS_RTC8564 68config SENSORS_RTC8564
413 tristate "Epson 8564 RTC chip" 69 tristate "Epson 8564 RTC chip"
414 depends on I2C && EXPERIMENTAL 70 depends on I2C && EXPERIMENTAL
415 select I2C_SENSOR
416 help 71 help
417 If you say yes here you get support for the Epson 8564 RTC chip. 72 If you say yes here you get support for the Epson 8564 RTC chip.
418 73
@@ -431,6 +86,22 @@ config ISP1301_OMAP
431 This driver can also be built as a module. If so, the module 86 This driver can also be built as a module. If so, the module
432 will be called isp1301_omap. 87 will be called isp1301_omap.
433 88
89# NOTE: This isn't really OMAP-specific, except for the current
90# interface location in <include/asm-arm/arch-omap/tps65010.h>
91# and having mostly OMAP-specific board support
92config TPS65010
93 tristate "TPS6501x Power Management chips"
94 depends on I2C && ARCH_OMAP
95 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
96 help
97 If you say yes here you get support for the TPS6501x series of
98 Power Management chips. These include voltage regulators,
99 lithium ion/polymer battery charging, and other features that
100 are often used in portable devices like cell phones and cameras.
101
102 This driver can also be built as a module. If so, the module
103 will be called tps65010.
104
434config SENSORS_M41T00 105config SENSORS_M41T00
435 tristate "ST M41T00 RTC chip" 106 tristate "ST M41T00 RTC chip"
436 depends on I2C && PPC32 107 depends on I2C && PPC32
@@ -440,4 +111,19 @@ config SENSORS_M41T00
440 This driver can also be built as a module. If so, the module 111 This driver can also be built as a module. If so, the module
441 will be called m41t00. 112 will be called m41t00.
442 113
114config SENSORS_MAX6875
115 tristate "Maxim MAX6875 Power supply supervisor"
116 depends on I2C && EXPERIMENTAL
117 help
118 If you say yes here you get support for the Maxim MAX6875
119 EEPROM-programmable, quad power-supply sequencer/supervisor.
120
121 This provides an interface to program the EEPROM and reset the chip.
122
123 This driver also supports the Maxim MAX6874 hex power-supply
124 sequencer/supervisor if found at a compatible address.
125
126 This driver can also be built as a module. If so, the module
127 will be called max6875.
128
443endmenu 129endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 65599161a172..a876dd42b860 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -1,46 +1,18 @@
1# 1#
2# Makefile for the kernel hardware sensors chip drivers. 2# Makefile for miscellaneous I2C chip drivers.
3# 3#
4 4
5# asb100, then w83781d go first, as they can override other drivers' addresses.
6obj-$(CONFIG_SENSORS_ASB100) += asb100.o
7obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o
8obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
9
10obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
11obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
12obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
13obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
14obj-$(CONFIG_SENSORS_DS1337) += ds1337.o 5obj-$(CONFIG_SENSORS_DS1337) += ds1337.o
15obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 6obj-$(CONFIG_SENSORS_DS1374) += ds1374.o
16obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 7obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
17obj-$(CONFIG_SENSORS_FSCHER) += fscher.o 8obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
18obj-$(CONFIG_SENSORS_FSCPOS) += fscpos.o
19obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
20obj-$(CONFIG_SENSORS_GL520SM) += gl520sm.o
21obj-$(CONFIG_SENSORS_IT87) += it87.o
22obj-$(CONFIG_SENSORS_LM63) += lm63.o
23obj-$(CONFIG_SENSORS_LM75) += lm75.o
24obj-$(CONFIG_SENSORS_LM77) += lm77.o
25obj-$(CONFIG_SENSORS_LM78) += lm78.o
26obj-$(CONFIG_SENSORS_LM80) += lm80.o
27obj-$(CONFIG_SENSORS_LM83) += lm83.o
28obj-$(CONFIG_SENSORS_LM85) += lm85.o
29obj-$(CONFIG_SENSORS_LM87) += lm87.o
30obj-$(CONFIG_SENSORS_LM90) += lm90.o
31obj-$(CONFIG_SENSORS_LM92) += lm92.o
32obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
33obj-$(CONFIG_SENSORS_M41T00) += m41t00.o 9obj-$(CONFIG_SENSORS_M41T00) += m41t00.o
34obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 10obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
35obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o 11obj-$(CONFIG_SENSORS_PCF8574) += pcf8574.o
36obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o 12obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
37obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o 13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
38obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
39obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
40obj-$(CONFIG_SENSORS_SMSC47M1) += smsc47m1.o
41obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
42obj-$(CONFIG_SENSORS_W83L785TS) += w83l785ts.o
43obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
15obj-$(CONFIG_TPS65010) += tps65010.o
44 16
45ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 17ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
46EXTRA_CFLAGS += -DDEBUG 18EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/adm1021.c b/drivers/i2c/chips/adm1021.c
deleted file mode 100644
index 9c59a370b6d9..000000000000
--- a/drivers/i2c/chips/adm1021.c
+++ /dev/null
@@ -1,411 +0,0 @@
1/*
2 adm1021.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <linux/config.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/jiffies.h>
27#include <linux/i2c.h>
28#include <linux/i2c-sensor.h>
29
30
31/* Addresses to scan */
32static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
33 0x29, 0x2a, 0x2b,
34 0x4c, 0x4d, 0x4e,
35 I2C_CLIENT_END };
36static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
37
38/* Insmod parameters */
39SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1066);
40
41/* adm1021 constants specified below */
42
43/* The adm1021 registers */
44/* Read-only */
45#define ADM1021_REG_TEMP 0x00
46#define ADM1021_REG_REMOTE_TEMP 0x01
47#define ADM1021_REG_STATUS 0x02
48#define ADM1021_REG_MAN_ID 0x0FE /* 0x41 = AMD, 0x49 = TI, 0x4D = Maxim, 0x23 = Genesys , 0x54 = Onsemi*/
49#define ADM1021_REG_DEV_ID 0x0FF /* ADM1021 = 0x0X, ADM1023 = 0x3X */
50#define ADM1021_REG_DIE_CODE 0x0FF /* MAX1617A */
51/* These use different addresses for reading/writing */
52#define ADM1021_REG_CONFIG_R 0x03
53#define ADM1021_REG_CONFIG_W 0x09
54#define ADM1021_REG_CONV_RATE_R 0x04
55#define ADM1021_REG_CONV_RATE_W 0x0A
56/* These are for the ADM1023's additional precision on the remote temp sensor */
57#define ADM1021_REG_REM_TEMP_PREC 0x010
58#define ADM1021_REG_REM_OFFSET 0x011
59#define ADM1021_REG_REM_OFFSET_PREC 0x012
60#define ADM1021_REG_REM_TOS_PREC 0x013
61#define ADM1021_REG_REM_THYST_PREC 0x014
62/* limits */
63#define ADM1021_REG_TOS_R 0x05
64#define ADM1021_REG_TOS_W 0x0B
65#define ADM1021_REG_REMOTE_TOS_R 0x07
66#define ADM1021_REG_REMOTE_TOS_W 0x0D
67#define ADM1021_REG_THYST_R 0x06
68#define ADM1021_REG_THYST_W 0x0C
69#define ADM1021_REG_REMOTE_THYST_R 0x08
70#define ADM1021_REG_REMOTE_THYST_W 0x0E
71/* write-only */
72#define ADM1021_REG_ONESHOT 0x0F
73
74
75/* Conversions. Rounding and limit checking is only done on the TO_REG
76 variants. Note that you should be a bit careful with which arguments
77 these macros are called: arguments may be evaluated more than once.
78 Fixing this is just not worth it. */
79/* Conversions note: 1021 uses normal integer signed-byte format*/
80#define TEMP_FROM_REG(val) (val > 127 ? (val-256)*1000 : val*1000)
81#define TEMP_TO_REG(val) (SENSORS_LIMIT((val < 0 ? (val/1000)+256 : val/1000),0,255))
82
83/* Initial values */
84
85/* Note: Even though I left the low and high limits named os and hyst,
86they don't quite work like a thermostat the way the LM75 does. I.e.,
87a lower temp than THYST actually triggers an alarm instead of
88clearing it. Weird, ey? --Phil */
89
90/* Each client has this additional data */
91struct adm1021_data {
92 struct i2c_client client;
93 enum chips type;
94
95 struct semaphore update_lock;
96 char valid; /* !=0 if following fields are valid */
97 unsigned long last_updated; /* In jiffies */
98
99 u8 temp_max; /* Register values */
100 u8 temp_hyst;
101 u8 temp_input;
102 u8 remote_temp_max;
103 u8 remote_temp_hyst;
104 u8 remote_temp_input;
105 u8 alarms;
106 /* special values for ADM1021 only */
107 u8 die_code;
108 /* Special values for ADM1023 only */
109 u8 remote_temp_prec;
110 u8 remote_temp_os_prec;
111 u8 remote_temp_hyst_prec;
112 u8 remote_temp_offset;
113 u8 remote_temp_offset_prec;
114};
115
116static int adm1021_attach_adapter(struct i2c_adapter *adapter);
117static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind);
118static void adm1021_init_client(struct i2c_client *client);
119static int adm1021_detach_client(struct i2c_client *client);
120static int adm1021_read_value(struct i2c_client *client, u8 reg);
121static int adm1021_write_value(struct i2c_client *client, u8 reg,
122 u16 value);
123static struct adm1021_data *adm1021_update_device(struct device *dev);
124
125/* (amalysh) read only mode, otherwise any limit's writing confuse BIOS */
126static int read_only = 0;
127
128
129/* This is the driver that will be inserted */
130static struct i2c_driver adm1021_driver = {
131 .owner = THIS_MODULE,
132 .name = "adm1021",
133 .id = I2C_DRIVERID_ADM1021,
134 .flags = I2C_DF_NOTIFY,
135 .attach_adapter = adm1021_attach_adapter,
136 .detach_client = adm1021_detach_client,
137};
138
139#define show(value) \
140static ssize_t show_##value(struct device *dev, char *buf) \
141{ \
142 struct adm1021_data *data = adm1021_update_device(dev); \
143 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
144}
145show(temp_max);
146show(temp_hyst);
147show(temp_input);
148show(remote_temp_max);
149show(remote_temp_hyst);
150show(remote_temp_input);
151
152#define show2(value) \
153static ssize_t show_##value(struct device *dev, char *buf) \
154{ \
155 struct adm1021_data *data = adm1021_update_device(dev); \
156 return sprintf(buf, "%d\n", data->value); \
157}
158show2(alarms);
159show2(die_code);
160
161#define set(value, reg) \
162static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
163{ \
164 struct i2c_client *client = to_i2c_client(dev); \
165 struct adm1021_data *data = i2c_get_clientdata(client); \
166 int temp = simple_strtoul(buf, NULL, 10); \
167 \
168 down(&data->update_lock); \
169 data->value = TEMP_TO_REG(temp); \
170 adm1021_write_value(client, reg, data->value); \
171 up(&data->update_lock); \
172 return count; \
173}
174set(temp_max, ADM1021_REG_TOS_W);
175set(temp_hyst, ADM1021_REG_THYST_W);
176set(remote_temp_max, ADM1021_REG_REMOTE_TOS_W);
177set(remote_temp_hyst, ADM1021_REG_REMOTE_THYST_W);
178
179static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
180static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_hyst, set_temp_hyst);
181static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL);
182static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_remote_temp_max, set_remote_temp_max);
183static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_remote_temp_hyst, set_remote_temp_hyst);
184static DEVICE_ATTR(temp2_input, S_IRUGO, show_remote_temp_input, NULL);
185static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
186static DEVICE_ATTR(die_code, S_IRUGO, show_die_code, NULL);
187
188
189static int adm1021_attach_adapter(struct i2c_adapter *adapter)
190{
191 if (!(adapter->class & I2C_CLASS_HWMON))
192 return 0;
193 return i2c_detect(adapter, &addr_data, adm1021_detect);
194}
195
196static int adm1021_detect(struct i2c_adapter *adapter, int address, int kind)
197{
198 int i;
199 struct i2c_client *new_client;
200 struct adm1021_data *data;
201 int err = 0;
202 const char *type_name = "";
203
204 /* Make sure we aren't probing the ISA bus!! This is just a safety check
205 at this moment; i2c_detect really won't call us. */
206#ifdef DEBUG
207 if (i2c_is_isa_adapter(adapter)) {
208 dev_dbg(&adapter->dev, "adm1021_detect called for an ISA bus adapter?!?\n");
209 return 0;
210 }
211#endif
212
213 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
214 goto error0;
215
216 /* OK. For now, we presume we have a valid client. We now create the
217 client structure, even though we cannot fill it completely yet.
218 But it allows us to access adm1021_{read,write}_value. */
219
220 if (!(data = kmalloc(sizeof(struct adm1021_data), GFP_KERNEL))) {
221 err = -ENOMEM;
222 goto error0;
223 }
224 memset(data, 0, sizeof(struct adm1021_data));
225
226 new_client = &data->client;
227 i2c_set_clientdata(new_client, data);
228 new_client->addr = address;
229 new_client->adapter = adapter;
230 new_client->driver = &adm1021_driver;
231 new_client->flags = 0;
232
233 /* Now, we do the remaining detection. */
234 if (kind < 0) {
235 if ((adm1021_read_value(new_client, ADM1021_REG_STATUS) & 0x03) != 0x00
236 || (adm1021_read_value(new_client, ADM1021_REG_CONFIG_R) & 0x3F) != 0x00
237 || (adm1021_read_value(new_client, ADM1021_REG_CONV_RATE_R) & 0xF8) != 0x00) {
238 err = -ENODEV;
239 goto error1;
240 }
241 }
242
243 /* Determine the chip type. */
244 if (kind <= 0) {
245 i = adm1021_read_value(new_client, ADM1021_REG_MAN_ID);
246 if (i == 0x41)
247 if ((adm1021_read_value(new_client, ADM1021_REG_DEV_ID) & 0x0F0) == 0x030)
248 kind = adm1023;
249 else
250 kind = adm1021;
251 else if (i == 0x49)
252 kind = thmc10;
253 else if (i == 0x23)
254 kind = gl523sm;
255 else if ((i == 0x4d) &&
256 (adm1021_read_value(new_client, ADM1021_REG_DEV_ID) == 0x01))
257 kind = max1617a;
258 else if (i == 0x54)
259 kind = mc1066;
260 /* LM84 Mfr ID in a different place, and it has more unused bits */
261 else if (adm1021_read_value(new_client, ADM1021_REG_CONV_RATE_R) == 0x00
262 && (kind == 0 /* skip extra detection */
263 || ((adm1021_read_value(new_client, ADM1021_REG_CONFIG_R) & 0x7F) == 0x00
264 && (adm1021_read_value(new_client, ADM1021_REG_STATUS) & 0xAB) == 0x00)))
265 kind = lm84;
266 else
267 kind = max1617;
268 }
269
270 if (kind == max1617) {
271 type_name = "max1617";
272 } else if (kind == max1617a) {
273 type_name = "max1617a";
274 } else if (kind == adm1021) {
275 type_name = "adm1021";
276 } else if (kind == adm1023) {
277 type_name = "adm1023";
278 } else if (kind == thmc10) {
279 type_name = "thmc10";
280 } else if (kind == lm84) {
281 type_name = "lm84";
282 } else if (kind == gl523sm) {
283 type_name = "gl523sm";
284 } else if (kind == mc1066) {
285 type_name = "mc1066";
286 }
287
288 /* Fill in the remaining client fields and put it into the global list */
289 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
290 data->type = kind;
291 data->valid = 0;
292 init_MUTEX(&data->update_lock);
293
294 /* Tell the I2C layer a new client has arrived */
295 if ((err = i2c_attach_client(new_client)))
296 goto error1;
297
298 /* Initialize the ADM1021 chip */
299 if (kind != lm84)
300 adm1021_init_client(new_client);
301
302 /* Register sysfs hooks */
303 device_create_file(&new_client->dev, &dev_attr_temp1_max);
304 device_create_file(&new_client->dev, &dev_attr_temp1_min);
305 device_create_file(&new_client->dev, &dev_attr_temp1_input);
306 device_create_file(&new_client->dev, &dev_attr_temp2_max);
307 device_create_file(&new_client->dev, &dev_attr_temp2_min);
308 device_create_file(&new_client->dev, &dev_attr_temp2_input);
309 device_create_file(&new_client->dev, &dev_attr_alarms);
310 if (data->type == adm1021)
311 device_create_file(&new_client->dev, &dev_attr_die_code);
312
313 return 0;
314
315error1:
316 kfree(data);
317error0:
318 return err;
319}
320
321static void adm1021_init_client(struct i2c_client *client)
322{
323 /* Enable ADC and disable suspend mode */
324 adm1021_write_value(client, ADM1021_REG_CONFIG_W,
325 adm1021_read_value(client, ADM1021_REG_CONFIG_R) & 0xBF);
326 /* Set Conversion rate to 1/sec (this can be tinkered with) */
327 adm1021_write_value(client, ADM1021_REG_CONV_RATE_W, 0x04);
328}
329
330static int adm1021_detach_client(struct i2c_client *client)
331{
332 int err;
333
334 if ((err = i2c_detach_client(client))) {
335 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
336 return err;
337 }
338
339 kfree(i2c_get_clientdata(client));
340 return 0;
341}
342
343/* All registers are byte-sized */
344static int adm1021_read_value(struct i2c_client *client, u8 reg)
345{
346 return i2c_smbus_read_byte_data(client, reg);
347}
348
349static int adm1021_write_value(struct i2c_client *client, u8 reg, u16 value)
350{
351 if (!read_only)
352 return i2c_smbus_write_byte_data(client, reg, value);
353 return 0;
354}
355
356static struct adm1021_data *adm1021_update_device(struct device *dev)
357{
358 struct i2c_client *client = to_i2c_client(dev);
359 struct adm1021_data *data = i2c_get_clientdata(client);
360
361 down(&data->update_lock);
362
363 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
364 || !data->valid) {
365 dev_dbg(&client->dev, "Starting adm1021 update\n");
366
367 data->temp_input = adm1021_read_value(client, ADM1021_REG_TEMP);
368 data->temp_max = adm1021_read_value(client, ADM1021_REG_TOS_R);
369 data->temp_hyst = adm1021_read_value(client, ADM1021_REG_THYST_R);
370 data->remote_temp_input = adm1021_read_value(client, ADM1021_REG_REMOTE_TEMP);
371 data->remote_temp_max = adm1021_read_value(client, ADM1021_REG_REMOTE_TOS_R);
372 data->remote_temp_hyst = adm1021_read_value(client, ADM1021_REG_REMOTE_THYST_R);
373 data->alarms = adm1021_read_value(client, ADM1021_REG_STATUS) & 0x7c;
374 if (data->type == adm1021)
375 data->die_code = adm1021_read_value(client, ADM1021_REG_DIE_CODE);
376 if (data->type == adm1023) {
377 data->remote_temp_prec = adm1021_read_value(client, ADM1021_REG_REM_TEMP_PREC);
378 data->remote_temp_os_prec = adm1021_read_value(client, ADM1021_REG_REM_TOS_PREC);
379 data->remote_temp_hyst_prec = adm1021_read_value(client, ADM1021_REG_REM_THYST_PREC);
380 data->remote_temp_offset = adm1021_read_value(client, ADM1021_REG_REM_OFFSET);
381 data->remote_temp_offset_prec = adm1021_read_value(client, ADM1021_REG_REM_OFFSET_PREC);
382 }
383 data->last_updated = jiffies;
384 data->valid = 1;
385 }
386
387 up(&data->update_lock);
388
389 return data;
390}
391
392static int __init sensors_adm1021_init(void)
393{
394 return i2c_add_driver(&adm1021_driver);
395}
396
397static void __exit sensors_adm1021_exit(void)
398{
399 i2c_del_driver(&adm1021_driver);
400}
401
402MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl> and "
403 "Philip Edelbrock <phil@netroedge.com>");
404MODULE_DESCRIPTION("adm1021 driver");
405MODULE_LICENSE("GPL");
406
407module_param(read_only, bool, 0);
408MODULE_PARM_DESC(read_only, "Don't set any values, read only mode");
409
410module_init(sensors_adm1021_init)
411module_exit(sensors_adm1021_exit)
diff --git a/drivers/i2c/chips/adm1025.c b/drivers/i2c/chips/adm1025.c
deleted file mode 100644
index e0771a3d05c9..000000000000
--- a/drivers/i2c/chips/adm1025.c
+++ /dev/null
@@ -1,574 +0,0 @@
1/*
2 * adm1025.c
3 *
4 * Copyright (C) 2000 Chen-Yuan Wu <gwu@esoft.com>
5 * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org>
6 *
7 * The ADM1025 is a sensor chip made by Analog Devices. It reports up to 6
8 * voltages (including its own power source) and up to two temperatures
9 * (its own plus up to one external one). Voltages are scaled internally
10 * (which is not the common way) with ratios such that the nominal value
11 * of each voltage correspond to a register value of 192 (which means a
12 * resolution of about 0.5% of the nominal value). Temperature values are
13 * reported with a 1 deg resolution and a 3 deg accuracy. Complete
14 * datasheet can be obtained from Analog's website at:
15 * http://www.analog.com/Analog_Root/productPage/productHome/0,2121,ADM1025,00.html
16 *
17 * This driver also supports the ADM1025A, which differs from the ADM1025
18 * only in that it has "open-drain VID inputs while the ADM1025 has
19 * on-chip 100k pull-ups on the VID inputs". It doesn't make any
20 * difference for us.
21 *
22 * This driver also supports the NE1619, a sensor chip made by Philips.
23 * That chip is similar to the ADM1025A, with a few differences. The only
24 * difference that matters to us is that the NE1619 has only two possible
25 * addresses while the ADM1025A has a third one. Complete datasheet can be
26 * obtained from Philips's website at:
27 * http://www.semiconductors.philips.com/pip/NE1619DS.html
28 *
29 * Since the ADM1025 was the first chipset supported by this driver, most
30 * comments will refer to this chipset, but are actually general and
31 * concern all supported chipsets, unless mentioned otherwise.
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License
44 * along with this program; if not, write to the Free Software
45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
46 */
47
48#include <linux/config.h>
49#include <linux/module.h>
50#include <linux/init.h>
51#include <linux/slab.h>
52#include <linux/jiffies.h>
53#include <linux/i2c.h>
54#include <linux/i2c-sensor.h>
55#include <linux/i2c-vid.h>
56
57/*
58 * Addresses to scan
59 * ADM1025 and ADM1025A have three possible addresses: 0x2c, 0x2d and 0x2e.
60 * NE1619 has two possible addresses: 0x2c and 0x2d.
61 */
62
63static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
64static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
65
66/*
67 * Insmod parameters
68 */
69
70SENSORS_INSMOD_2(adm1025, ne1619);
71
72/*
73 * The ADM1025 registers
74 */
75
76#define ADM1025_REG_MAN_ID 0x3E
77#define ADM1025_REG_CHIP_ID 0x3F
78#define ADM1025_REG_CONFIG 0x40
79#define ADM1025_REG_STATUS1 0x41
80#define ADM1025_REG_STATUS2 0x42
81#define ADM1025_REG_IN(nr) (0x20 + (nr))
82#define ADM1025_REG_IN_MAX(nr) (0x2B + (nr) * 2)
83#define ADM1025_REG_IN_MIN(nr) (0x2C + (nr) * 2)
84#define ADM1025_REG_TEMP(nr) (0x26 + (nr))
85#define ADM1025_REG_TEMP_HIGH(nr) (0x37 + (nr) * 2)
86#define ADM1025_REG_TEMP_LOW(nr) (0x38 + (nr) * 2)
87#define ADM1025_REG_VID 0x47
88#define ADM1025_REG_VID4 0x49
89
90/*
91 * Conversions and various macros
92 * The ADM1025 uses signed 8-bit values for temperatures.
93 */
94
95static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
96
97#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
98#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
99 (val) * 192 >= (scale) * 255 ? 255 : \
100 ((val) * 192 + (scale)/2) / (scale))
101
102#define TEMP_FROM_REG(reg) ((reg) * 1000)
103#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
104 (val) >= 126500 ? 127 : \
105 (((val) < 0 ? (val)-500 : (val)+500) / 1000))
106
107/*
108 * Functions declaration
109 */
110
111static int adm1025_attach_adapter(struct i2c_adapter *adapter);
112static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind);
113static void adm1025_init_client(struct i2c_client *client);
114static int adm1025_detach_client(struct i2c_client *client);
115static struct adm1025_data *adm1025_update_device(struct device *dev);
116
117/*
118 * Driver data (common to all clients)
119 */
120
121static struct i2c_driver adm1025_driver = {
122 .owner = THIS_MODULE,
123 .name = "adm1025",
124 .id = I2C_DRIVERID_ADM1025,
125 .flags = I2C_DF_NOTIFY,
126 .attach_adapter = adm1025_attach_adapter,
127 .detach_client = adm1025_detach_client,
128};
129
130/*
131 * Client data (each client gets its own)
132 */
133
134struct adm1025_data {
135 struct i2c_client client;
136 struct semaphore update_lock;
137 char valid; /* zero until following fields are valid */
138 unsigned long last_updated; /* in jiffies */
139
140 u8 in[6]; /* register value */
141 u8 in_max[6]; /* register value */
142 u8 in_min[6]; /* register value */
143 s8 temp[2]; /* register value */
144 s8 temp_min[2]; /* register value */
145 s8 temp_max[2]; /* register value */
146 u16 alarms; /* register values, combined */
147 u8 vid; /* register values, combined */
148 u8 vrm;
149};
150
151/*
152 * Sysfs stuff
153 */
154
155#define show_in(offset) \
156static ssize_t show_in##offset(struct device *dev, char *buf) \
157{ \
158 struct adm1025_data *data = adm1025_update_device(dev); \
159 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
160 in_scale[offset])); \
161} \
162static ssize_t show_in##offset##_min(struct device *dev, char *buf) \
163{ \
164 struct adm1025_data *data = adm1025_update_device(dev); \
165 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
166 in_scale[offset])); \
167} \
168static ssize_t show_in##offset##_max(struct device *dev, char *buf) \
169{ \
170 struct adm1025_data *data = adm1025_update_device(dev); \
171 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
172 in_scale[offset])); \
173} \
174static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
175show_in(0);
176show_in(1);
177show_in(2);
178show_in(3);
179show_in(4);
180show_in(5);
181
182#define show_temp(offset) \
183static ssize_t show_temp##offset(struct device *dev, char *buf) \
184{ \
185 struct adm1025_data *data = adm1025_update_device(dev); \
186 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
187} \
188static ssize_t show_temp##offset##_min(struct device *dev, char *buf) \
189{ \
190 struct adm1025_data *data = adm1025_update_device(dev); \
191 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
192} \
193static ssize_t show_temp##offset##_max(struct device *dev, char *buf) \
194{ \
195 struct adm1025_data *data = adm1025_update_device(dev); \
196 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
197}\
198static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL);
199show_temp(1);
200show_temp(2);
201
202#define set_in(offset) \
203static ssize_t set_in##offset##_min(struct device *dev, const char *buf, \
204 size_t count) \
205{ \
206 struct i2c_client *client = to_i2c_client(dev); \
207 struct adm1025_data *data = i2c_get_clientdata(client); \
208 long val = simple_strtol(buf, NULL, 10); \
209 \
210 down(&data->update_lock); \
211 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
212 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
213 data->in_min[offset]); \
214 up(&data->update_lock); \
215 return count; \
216} \
217static ssize_t set_in##offset##_max(struct device *dev, const char *buf, \
218 size_t count) \
219{ \
220 struct i2c_client *client = to_i2c_client(dev); \
221 struct adm1025_data *data = i2c_get_clientdata(client); \
222 long val = simple_strtol(buf, NULL, 10); \
223 \
224 down(&data->update_lock); \
225 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
226 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
227 data->in_max[offset]); \
228 up(&data->update_lock); \
229 return count; \
230} \
231static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
232 show_in##offset##_min, set_in##offset##_min); \
233static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
234 show_in##offset##_max, set_in##offset##_max);
235set_in(0);
236set_in(1);
237set_in(2);
238set_in(3);
239set_in(4);
240set_in(5);
241
242#define set_temp(offset) \
243static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
244 size_t count) \
245{ \
246 struct i2c_client *client = to_i2c_client(dev); \
247 struct adm1025_data *data = i2c_get_clientdata(client); \
248 long val = simple_strtol(buf, NULL, 10); \
249 \
250 down(&data->update_lock); \
251 data->temp_min[offset-1] = TEMP_TO_REG(val); \
252 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
253 data->temp_min[offset-1]); \
254 up(&data->update_lock); \
255 return count; \
256} \
257static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
258 size_t count) \
259{ \
260 struct i2c_client *client = to_i2c_client(dev); \
261 struct adm1025_data *data = i2c_get_clientdata(client); \
262 long val = simple_strtol(buf, NULL, 10); \
263 \
264 down(&data->update_lock); \
265 data->temp_max[offset-1] = TEMP_TO_REG(val); \
266 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
267 data->temp_max[offset-1]); \
268 up(&data->update_lock); \
269 return count; \
270} \
271static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
272 show_temp##offset##_min, set_temp##offset##_min); \
273static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
274 show_temp##offset##_max, set_temp##offset##_max);
275set_temp(1);
276set_temp(2);
277
278static ssize_t show_alarms(struct device *dev, char *buf)
279{
280 struct adm1025_data *data = adm1025_update_device(dev);
281 return sprintf(buf, "%u\n", data->alarms);
282}
283static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
284
285static ssize_t show_vid(struct device *dev, char *buf)
286{
287 struct adm1025_data *data = adm1025_update_device(dev);
288 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
289}
290static DEVICE_ATTR(in1_ref, S_IRUGO, show_vid, NULL);
291
292static ssize_t show_vrm(struct device *dev, char *buf)
293{
294 struct adm1025_data *data = adm1025_update_device(dev);
295 return sprintf(buf, "%u\n", data->vrm);
296}
297static ssize_t set_vrm(struct device *dev, const char *buf, size_t count)
298{
299 struct i2c_client *client = to_i2c_client(dev);
300 struct adm1025_data *data = i2c_get_clientdata(client);
301 data->vrm = simple_strtoul(buf, NULL, 10);
302 return count;
303}
304static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
305
306/*
307 * Real code
308 */
309
310static int adm1025_attach_adapter(struct i2c_adapter *adapter)
311{
312 if (!(adapter->class & I2C_CLASS_HWMON))
313 return 0;
314 return i2c_detect(adapter, &addr_data, adm1025_detect);
315}
316
317/*
318 * The following function does more than just detection. If detection
319 * succeeds, it also registers the new chip.
320 */
321static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
322{
323 struct i2c_client *new_client;
324 struct adm1025_data *data;
325 int err = 0;
326 const char *name = "";
327 u8 config;
328
329 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
330 goto exit;
331
332 if (!(data = kmalloc(sizeof(struct adm1025_data), GFP_KERNEL))) {
333 err = -ENOMEM;
334 goto exit;
335 }
336 memset(data, 0, sizeof(struct adm1025_data));
337
338 /* The common I2C client data is placed right before the
339 ADM1025-specific data. */
340 new_client = &data->client;
341 i2c_set_clientdata(new_client, data);
342 new_client->addr = address;
343 new_client->adapter = adapter;
344 new_client->driver = &adm1025_driver;
345 new_client->flags = 0;
346
347 /*
348 * Now we do the remaining detection. A negative kind means that
349 * the driver was loaded with no force parameter (default), so we
350 * must both detect and identify the chip. A zero kind means that
351 * the driver was loaded with the force parameter, the detection
352 * step shall be skipped. A positive kind means that the driver
353 * was loaded with the force parameter and a given kind of chip is
354 * requested, so both the detection and the identification steps
355 * are skipped.
356 */
357 config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG);
358 if (kind < 0) { /* detection */
359 if ((config & 0x80) != 0x00
360 || (i2c_smbus_read_byte_data(new_client,
361 ADM1025_REG_STATUS1) & 0xC0) != 0x00
362 || (i2c_smbus_read_byte_data(new_client,
363 ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
364 dev_dbg(&adapter->dev,
365 "ADM1025 detection failed at 0x%02x.\n",
366 address);
367 goto exit_free;
368 }
369 }
370
371 if (kind <= 0) { /* identification */
372 u8 man_id, chip_id;
373
374 man_id = i2c_smbus_read_byte_data(new_client,
375 ADM1025_REG_MAN_ID);
376 chip_id = i2c_smbus_read_byte_data(new_client,
377 ADM1025_REG_CHIP_ID);
378
379 if (man_id == 0x41) { /* Analog Devices */
380 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
381 kind = adm1025;
382 }
383 } else
384 if (man_id == 0xA1) { /* Philips */
385 if (address != 0x2E
386 && (chip_id & 0xF0) == 0x20) { /* NE1619 */
387 kind = ne1619;
388 }
389 }
390
391 if (kind <= 0) { /* identification failed */
392 dev_info(&adapter->dev,
393 "Unsupported chip (man_id=0x%02X, "
394 "chip_id=0x%02X).\n", man_id, chip_id);
395 goto exit_free;
396 }
397 }
398
399 if (kind == adm1025) {
400 name = "adm1025";
401 } else if (kind == ne1619) {
402 name = "ne1619";
403 }
404
405 /* We can fill in the remaining client fields */
406 strlcpy(new_client->name, name, I2C_NAME_SIZE);
407 data->valid = 0;
408 init_MUTEX(&data->update_lock);
409
410 /* Tell the I2C layer a new client has arrived */
411 if ((err = i2c_attach_client(new_client)))
412 goto exit_free;
413
414 /* Initialize the ADM1025 chip */
415 adm1025_init_client(new_client);
416
417 /* Register sysfs hooks */
418 device_create_file(&new_client->dev, &dev_attr_in0_input);
419 device_create_file(&new_client->dev, &dev_attr_in1_input);
420 device_create_file(&new_client->dev, &dev_attr_in2_input);
421 device_create_file(&new_client->dev, &dev_attr_in3_input);
422 device_create_file(&new_client->dev, &dev_attr_in5_input);
423 device_create_file(&new_client->dev, &dev_attr_in0_min);
424 device_create_file(&new_client->dev, &dev_attr_in1_min);
425 device_create_file(&new_client->dev, &dev_attr_in2_min);
426 device_create_file(&new_client->dev, &dev_attr_in3_min);
427 device_create_file(&new_client->dev, &dev_attr_in5_min);
428 device_create_file(&new_client->dev, &dev_attr_in0_max);
429 device_create_file(&new_client->dev, &dev_attr_in1_max);
430 device_create_file(&new_client->dev, &dev_attr_in2_max);
431 device_create_file(&new_client->dev, &dev_attr_in3_max);
432 device_create_file(&new_client->dev, &dev_attr_in5_max);
433 device_create_file(&new_client->dev, &dev_attr_temp1_input);
434 device_create_file(&new_client->dev, &dev_attr_temp2_input);
435 device_create_file(&new_client->dev, &dev_attr_temp1_min);
436 device_create_file(&new_client->dev, &dev_attr_temp2_min);
437 device_create_file(&new_client->dev, &dev_attr_temp1_max);
438 device_create_file(&new_client->dev, &dev_attr_temp2_max);
439 device_create_file(&new_client->dev, &dev_attr_alarms);
440 device_create_file(&new_client->dev, &dev_attr_in1_ref);
441 device_create_file(&new_client->dev, &dev_attr_vrm);
442
443 /* Pin 11 is either in4 (+12V) or VID4 */
444 if (!(config & 0x20)) {
445 device_create_file(&new_client->dev, &dev_attr_in4_input);
446 device_create_file(&new_client->dev, &dev_attr_in4_min);
447 device_create_file(&new_client->dev, &dev_attr_in4_max);
448 }
449
450 return 0;
451
452exit_free:
453 kfree(data);
454exit:
455 return err;
456}
457
458static void adm1025_init_client(struct i2c_client *client)
459{
460 u8 reg;
461 struct adm1025_data *data = i2c_get_clientdata(client);
462 int i;
463
464 data->vrm = i2c_which_vrm();
465
466 /*
467 * Set high limits
468 * Usually we avoid setting limits on driver init, but it happens
469 * that the ADM1025 comes with stupid default limits (all registers
470 * set to 0). In case the chip has not gone through any limit
471 * setting yet, we better set the high limits to the max so that
472 * no alarm triggers.
473 */
474 for (i=0; i<6; i++) {
475 reg = i2c_smbus_read_byte_data(client,
476 ADM1025_REG_IN_MAX(i));
477 if (reg == 0)
478 i2c_smbus_write_byte_data(client,
479 ADM1025_REG_IN_MAX(i),
480 0xFF);
481 }
482 for (i=0; i<2; i++) {
483 reg = i2c_smbus_read_byte_data(client,
484 ADM1025_REG_TEMP_HIGH(i));
485 if (reg == 0)
486 i2c_smbus_write_byte_data(client,
487 ADM1025_REG_TEMP_HIGH(i),
488 0x7F);
489 }
490
491 /*
492 * Start the conversions
493 */
494 reg = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
495 if (!(reg & 0x01))
496 i2c_smbus_write_byte_data(client, ADM1025_REG_CONFIG,
497 (reg&0x7E)|0x01);
498}
499
500static int adm1025_detach_client(struct i2c_client *client)
501{
502 int err;
503
504 if ((err = i2c_detach_client(client))) {
505 dev_err(&client->dev, "Client deregistration failed, "
506 "client not detached.\n");
507 return err;
508 }
509
510 kfree(i2c_get_clientdata(client));
511 return 0;
512}
513
514static struct adm1025_data *adm1025_update_device(struct device *dev)
515{
516 struct i2c_client *client = to_i2c_client(dev);
517 struct adm1025_data *data = i2c_get_clientdata(client);
518
519 down(&data->update_lock);
520
521 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
522 int i;
523
524 dev_dbg(&client->dev, "Updating data.\n");
525 for (i=0; i<6; i++) {
526 data->in[i] = i2c_smbus_read_byte_data(client,
527 ADM1025_REG_IN(i));
528 data->in_min[i] = i2c_smbus_read_byte_data(client,
529 ADM1025_REG_IN_MIN(i));
530 data->in_max[i] = i2c_smbus_read_byte_data(client,
531 ADM1025_REG_IN_MAX(i));
532 }
533 for (i=0; i<2; i++) {
534 data->temp[i] = i2c_smbus_read_byte_data(client,
535 ADM1025_REG_TEMP(i));
536 data->temp_min[i] = i2c_smbus_read_byte_data(client,
537 ADM1025_REG_TEMP_LOW(i));
538 data->temp_max[i] = i2c_smbus_read_byte_data(client,
539 ADM1025_REG_TEMP_HIGH(i));
540 }
541 data->alarms = i2c_smbus_read_byte_data(client,
542 ADM1025_REG_STATUS1)
543 | (i2c_smbus_read_byte_data(client,
544 ADM1025_REG_STATUS2) << 8);
545 data->vid = (i2c_smbus_read_byte_data(client,
546 ADM1025_REG_VID) & 0x0f)
547 | ((i2c_smbus_read_byte_data(client,
548 ADM1025_REG_VID4) & 0x01) << 4);
549
550 data->last_updated = jiffies;
551 data->valid = 1;
552 }
553
554 up(&data->update_lock);
555
556 return data;
557}
558
559static int __init sensors_adm1025_init(void)
560{
561 return i2c_add_driver(&adm1025_driver);
562}
563
564static void __exit sensors_adm1025_exit(void)
565{
566 i2c_del_driver(&adm1025_driver);
567}
568
569MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
570MODULE_DESCRIPTION("ADM1025 driver");
571MODULE_LICENSE("GPL");
572
573module_init(sensors_adm1025_init);
574module_exit(sensors_adm1025_exit);
diff --git a/drivers/i2c/chips/adm1026.c b/drivers/i2c/chips/adm1026.c
deleted file mode 100644
index 39e2f4a900bf..000000000000
--- a/drivers/i2c/chips/adm1026.c
+++ /dev/null
@@ -1,1754 +0,0 @@
1/*
2 adm1026.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
5 Copyright (C) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
6
7 Chip details at:
8
9 <http://www.analog.com/UploadedFiles/Data_Sheets/779263102ADM1026_a.pdf>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26#include <linux/config.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/jiffies.h>
31#include <linux/i2c.h>
32#include <linux/i2c-sensor.h>
33#include <linux/i2c-vid.h>
34
35/* Addresses to scan */
36static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
37static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
38
39/* Insmod parameters */
40SENSORS_INSMOD_1(adm1026);
41
42static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
43 -1, -1, -1, -1, -1, -1, -1, -1 };
44static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
45 -1, -1, -1, -1, -1, -1, -1, -1 };
46static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
47 -1, -1, -1, -1, -1, -1, -1, -1 };
48static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
49 -1, -1, -1, -1, -1, -1, -1, -1 };
50static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
51module_param_array(gpio_input,int,NULL,0);
52MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
53module_param_array(gpio_output,int,NULL,0);
54MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
55 "outputs");
56module_param_array(gpio_inverted,int,NULL,0);
57MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
58 "inverted");
59module_param_array(gpio_normal,int,NULL,0);
60MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
61 "normal/non-inverted");
62module_param_array(gpio_fan,int,NULL,0);
63MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
64
65/* Many ADM1026 constants specified below */
66
67/* The ADM1026 registers */
68#define ADM1026_REG_CONFIG1 0x00
69#define CFG1_MONITOR 0x01
70#define CFG1_INT_ENABLE 0x02
71#define CFG1_INT_CLEAR 0x04
72#define CFG1_AIN8_9 0x08
73#define CFG1_THERM_HOT 0x10
74#define CFG1_DAC_AFC 0x20
75#define CFG1_PWM_AFC 0x40
76#define CFG1_RESET 0x80
77#define ADM1026_REG_CONFIG2 0x01
78/* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
79#define ADM1026_REG_CONFIG3 0x07
80#define CFG3_GPIO16_ENABLE 0x01
81#define CFG3_CI_CLEAR 0x02
82#define CFG3_VREF_250 0x04
83#define CFG3_GPIO16_DIR 0x40
84#define CFG3_GPIO16_POL 0x80
85#define ADM1026_REG_E2CONFIG 0x13
86#define E2CFG_READ 0x01
87#define E2CFG_WRITE 0x02
88#define E2CFG_ERASE 0x04
89#define E2CFG_ROM 0x08
90#define E2CFG_CLK_EXT 0x80
91
92/* There are 10 general analog inputs and 7 dedicated inputs
93 * They are:
94 * 0 - 9 = AIN0 - AIN9
95 * 10 = Vbat
96 * 11 = 3.3V Standby
97 * 12 = 3.3V Main
98 * 13 = +5V
99 * 14 = Vccp (CPU core voltage)
100 * 15 = +12V
101 * 16 = -12V
102 */
103static u16 ADM1026_REG_IN[] = {
104 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
105 0x36, 0x37, 0x27, 0x29, 0x26, 0x2a,
106 0x2b, 0x2c, 0x2d, 0x2e, 0x2f
107 };
108static u16 ADM1026_REG_IN_MIN[] = {
109 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d,
110 0x5e, 0x5f, 0x6d, 0x49, 0x6b, 0x4a,
111 0x4b, 0x4c, 0x4d, 0x4e, 0x4f
112 };
113static u16 ADM1026_REG_IN_MAX[] = {
114 0x50, 0x51, 0x52, 0x53, 0x54, 0x55,
115 0x56, 0x57, 0x6c, 0x41, 0x6a, 0x42,
116 0x43, 0x44, 0x45, 0x46, 0x47
117 };
118
119/* Temperatures are:
120 * 0 - Internal
121 * 1 - External 1
122 * 2 - External 2
123 */
124static u16 ADM1026_REG_TEMP[] = { 0x1f, 0x28, 0x29 };
125static u16 ADM1026_REG_TEMP_MIN[] = { 0x69, 0x48, 0x49 };
126static u16 ADM1026_REG_TEMP_MAX[] = { 0x68, 0x40, 0x41 };
127static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
128static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
129static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
130
131#define ADM1026_REG_FAN(nr) (0x38 + (nr))
132#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
133#define ADM1026_REG_FAN_DIV_0_3 0x02
134#define ADM1026_REG_FAN_DIV_4_7 0x03
135
136#define ADM1026_REG_DAC 0x04
137#define ADM1026_REG_PWM 0x05
138
139#define ADM1026_REG_GPIO_CFG_0_3 0x08
140#define ADM1026_REG_GPIO_CFG_4_7 0x09
141#define ADM1026_REG_GPIO_CFG_8_11 0x0a
142#define ADM1026_REG_GPIO_CFG_12_15 0x0b
143/* CFG_16 in REG_CFG3 */
144#define ADM1026_REG_GPIO_STATUS_0_7 0x24
145#define ADM1026_REG_GPIO_STATUS_8_15 0x25
146/* STATUS_16 in REG_STATUS4 */
147#define ADM1026_REG_GPIO_MASK_0_7 0x1c
148#define ADM1026_REG_GPIO_MASK_8_15 0x1d
149/* MASK_16 in REG_MASK4 */
150
151#define ADM1026_REG_COMPANY 0x16
152#define ADM1026_REG_VERSTEP 0x17
153/* These are the recognized values for the above regs */
154#define ADM1026_COMPANY_ANALOG_DEV 0x41
155#define ADM1026_VERSTEP_GENERIC 0x40
156#define ADM1026_VERSTEP_ADM1026 0x44
157
158#define ADM1026_REG_MASK1 0x18
159#define ADM1026_REG_MASK2 0x19
160#define ADM1026_REG_MASK3 0x1a
161#define ADM1026_REG_MASK4 0x1b
162
163#define ADM1026_REG_STATUS1 0x20
164#define ADM1026_REG_STATUS2 0x21
165#define ADM1026_REG_STATUS3 0x22
166#define ADM1026_REG_STATUS4 0x23
167
168#define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
169#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
170#define ADM1026_PWM_MAX 255
171
172/* Conversions. Rounding and limit checking is only done on the TO_REG
173 * variants. Note that you should be a bit careful with which arguments
174 * these macros are called: arguments may be evaluated more than once.
175 */
176
177/* IN are scaled acording to built-in resistors. These are the
178 * voltages corresponding to 3/4 of full scale (192 or 0xc0)
179 * NOTE: The -12V input needs an additional factor to account
180 * for the Vref pullup resistor.
181 * NEG12_OFFSET = SCALE * Vref / V-192 - Vref
182 * = 13875 * 2.50 / 1.875 - 2500
183 * = 16000
184 *
185 * The values in this table are based on Table II, page 15 of the
186 * datasheet.
187 */
188static int adm1026_scaling[] = { /* .001 Volts */
189 2250, 2250, 2250, 2250, 2250, 2250,
190 1875, 1875, 1875, 1875, 3000, 3330,
191 3330, 4995, 2250, 12000, 13875
192 };
193#define NEG12_OFFSET 16000
194#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
195#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
196 0,255))
197#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
198
199/* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
200 * and we assume a 2 pulse-per-rev fan tach signal
201 * 22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
202 */
203#define FAN_TO_REG(val,div) ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
204 (div)),1,254))
205#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
206 (div)))
207#define DIV_FROM_REG(val) (1<<(val))
208#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
209
210/* Temperature is reported in 1 degC increments */
211#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
212 -127,127))
213#define TEMP_FROM_REG(val) ((val) * 1000)
214#define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
215 -127,127))
216#define OFFSET_FROM_REG(val) ((val) * 1000)
217
218#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
219#define PWM_FROM_REG(val) (val)
220
221#define PWM_MIN_TO_REG(val) ((val) & 0xf0)
222#define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
223
224/* Analog output is a voltage, and scaled to millivolts. The datasheet
225 * indicates that the DAC could be used to drive the fans, but in our
226 * example board (Arima HDAMA) it isn't connected to the fans at all.
227 */
228#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255))
229#define DAC_FROM_REG(val) (((val)*2500)/255)
230
231/* Typically used with systems using a v9.1 VRM spec ? */
232#define ADM1026_INIT_VRM 91
233
234/* Chip sampling rates
235 *
236 * Some sensors are not updated more frequently than once per second
237 * so it doesn't make sense to read them more often than that.
238 * We cache the results and return the saved data if the driver
239 * is called again before a second has elapsed.
240 *
241 * Also, there is significant configuration data for this chip
242 * So, we keep the config data up to date in the cache
243 * when it is written and only sample it once every 5 *minutes*
244 */
245#define ADM1026_DATA_INTERVAL (1 * HZ)
246#define ADM1026_CONFIG_INTERVAL (5 * 60 * HZ)
247
248/* We allow for multiple chips in a single system.
249 *
250 * For each registered ADM1026, we need to keep state information
251 * at client->data. The adm1026_data structure is dynamically
252 * allocated, when a new client structure is allocated. */
253
254struct pwm_data {
255 u8 pwm;
256 u8 enable;
257 u8 auto_pwm_min;
258};
259
260struct adm1026_data {
261 struct i2c_client client;
262 struct semaphore lock;
263 enum chips type;
264
265 struct semaphore update_lock;
266 int valid; /* !=0 if following fields are valid */
267 unsigned long last_reading; /* In jiffies */
268 unsigned long last_config; /* In jiffies */
269
270 u8 in[17]; /* Register value */
271 u8 in_max[17]; /* Register value */
272 u8 in_min[17]; /* Register value */
273 s8 temp[3]; /* Register value */
274 s8 temp_min[3]; /* Register value */
275 s8 temp_max[3]; /* Register value */
276 s8 temp_tmin[3]; /* Register value */
277 s8 temp_crit[3]; /* Register value */
278 s8 temp_offset[3]; /* Register value */
279 u8 fan[8]; /* Register value */
280 u8 fan_min[8]; /* Register value */
281 u8 fan_div[8]; /* Decoded value */
282 struct pwm_data pwm1; /* Pwm control values */
283 int vid; /* Decoded value */
284 u8 vrm; /* VRM version */
285 u8 analog_out; /* Register value (DAC) */
286 long alarms; /* Register encoding, combined */
287 long alarm_mask; /* Register encoding, combined */
288 long gpio; /* Register encoding, combined */
289 long gpio_mask; /* Register encoding, combined */
290 u8 gpio_config[17]; /* Decoded value */
291 u8 config1; /* Register value */
292 u8 config2; /* Register value */
293 u8 config3; /* Register value */
294};
295
296static int adm1026_attach_adapter(struct i2c_adapter *adapter);
297static int adm1026_detect(struct i2c_adapter *adapter, int address,
298 int kind);
299static int adm1026_detach_client(struct i2c_client *client);
300static int adm1026_read_value(struct i2c_client *client, u8 register);
301static int adm1026_write_value(struct i2c_client *client, u8 register,
302 int value);
303static void adm1026_print_gpio(struct i2c_client *client);
304static void adm1026_fixup_gpio(struct i2c_client *client);
305static struct adm1026_data *adm1026_update_device(struct device *dev);
306static void adm1026_init_client(struct i2c_client *client);
307
308
309static struct i2c_driver adm1026_driver = {
310 .owner = THIS_MODULE,
311 .name = "adm1026",
312 .flags = I2C_DF_NOTIFY,
313 .attach_adapter = adm1026_attach_adapter,
314 .detach_client = adm1026_detach_client,
315};
316
317int adm1026_attach_adapter(struct i2c_adapter *adapter)
318{
319 if (!(adapter->class & I2C_CLASS_HWMON)) {
320 return 0;
321 }
322 return i2c_detect(adapter, &addr_data, adm1026_detect);
323}
324
325int adm1026_detach_client(struct i2c_client *client)
326{
327 i2c_detach_client(client);
328 kfree(client);
329 return 0;
330}
331
332int adm1026_read_value(struct i2c_client *client, u8 reg)
333{
334 int res;
335
336 if (reg < 0x80) {
337 /* "RAM" locations */
338 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
339 } else {
340 /* EEPROM, do nothing */
341 res = 0;
342 }
343 return res;
344}
345
346int adm1026_write_value(struct i2c_client *client, u8 reg, int value)
347{
348 int res;
349
350 if (reg < 0x80) {
351 /* "RAM" locations */
352 res = i2c_smbus_write_byte_data(client, reg, value);
353 } else {
354 /* EEPROM, do nothing */
355 res = 0;
356 }
357 return res;
358}
359
360void adm1026_init_client(struct i2c_client *client)
361{
362 int value, i;
363 struct adm1026_data *data = i2c_get_clientdata(client);
364
365 dev_dbg(&client->dev, "Initializing device\n");
366 /* Read chip config */
367 data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
368 data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
369 data->config3 = adm1026_read_value(client, ADM1026_REG_CONFIG3);
370
371 /* Inform user of chip config */
372 dev_dbg(&client->dev, "ADM1026_REG_CONFIG1 is: 0x%02x\n",
373 data->config1);
374 if ((data->config1 & CFG1_MONITOR) == 0) {
375 dev_dbg(&client->dev, "Monitoring not currently "
376 "enabled.\n");
377 }
378 if (data->config1 & CFG1_INT_ENABLE) {
379 dev_dbg(&client->dev, "SMBALERT interrupts are "
380 "enabled.\n");
381 }
382 if (data->config1 & CFG1_AIN8_9) {
383 dev_dbg(&client->dev, "in8 and in9 enabled. "
384 "temp3 disabled.\n");
385 } else {
386 dev_dbg(&client->dev, "temp3 enabled. in8 and "
387 "in9 disabled.\n");
388 }
389 if (data->config1 & CFG1_THERM_HOT) {
390 dev_dbg(&client->dev, "Automatic THERM, PWM, "
391 "and temp limits enabled.\n");
392 }
393
394 value = data->config3;
395 if (data->config3 & CFG3_GPIO16_ENABLE) {
396 dev_dbg(&client->dev, "GPIO16 enabled. THERM"
397 "pin disabled.\n");
398 } else {
399 dev_dbg(&client->dev, "THERM pin enabled. "
400 "GPIO16 disabled.\n");
401 }
402 if (data->config3 & CFG3_VREF_250) {
403 dev_dbg(&client->dev, "Vref is 2.50 Volts.\n");
404 } else {
405 dev_dbg(&client->dev, "Vref is 1.82 Volts.\n");
406 }
407 /* Read and pick apart the existing GPIO configuration */
408 value = 0;
409 for (i = 0;i <= 15;++i) {
410 if ((i & 0x03) == 0) {
411 value = adm1026_read_value(client,
412 ADM1026_REG_GPIO_CFG_0_3 + i/4);
413 }
414 data->gpio_config[i] = value & 0x03;
415 value >>= 2;
416 }
417 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
418
419 /* ... and then print it */
420 adm1026_print_gpio(client);
421
422 /* If the user asks us to reprogram the GPIO config, then
423 * do it now.
424 */
425 if (gpio_input[0] != -1 || gpio_output[0] != -1
426 || gpio_inverted[0] != -1 || gpio_normal[0] != -1
427 || gpio_fan[0] != -1) {
428 adm1026_fixup_gpio(client);
429 }
430
431 /* WE INTENTIONALLY make no changes to the limits,
432 * offsets, pwms, fans and zones. If they were
433 * configured, we don't want to mess with them.
434 * If they weren't, the default is 100% PWM, no
435 * control and will suffice until 'sensors -s'
436 * can be run by the user. We DO set the default
437 * value for pwm1.auto_pwm_min to its maximum
438 * so that enabling automatic pwm fan control
439 * without first setting a value for pwm1.auto_pwm_min
440 * will not result in potentially dangerous fan speed decrease.
441 */
442 data->pwm1.auto_pwm_min=255;
443 /* Start monitoring */
444 value = adm1026_read_value(client, ADM1026_REG_CONFIG1);
445 /* Set MONITOR, clear interrupt acknowledge and s/w reset */
446 value = (value | CFG1_MONITOR) & (~CFG1_INT_CLEAR & ~CFG1_RESET);
447 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
448 data->config1 = value;
449 adm1026_write_value(client, ADM1026_REG_CONFIG1, value);
450
451 /* initialize fan_div[] to hardware defaults */
452 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3) |
453 (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7) << 8);
454 for (i = 0;i <= 7;++i) {
455 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
456 value >>= 2;
457 }
458}
459
460void adm1026_print_gpio(struct i2c_client *client)
461{
462 struct adm1026_data *data = i2c_get_clientdata(client);
463 int i;
464
465 dev_dbg(&client->dev, "GPIO config is:");
466 for (i = 0;i <= 7;++i) {
467 if (data->config2 & (1 << i)) {
468 dev_dbg(&client->dev, "\t%sGP%s%d\n",
469 data->gpio_config[i] & 0x02 ? "" : "!",
470 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
471 i);
472 } else {
473 dev_dbg(&client->dev, "\tFAN%d\n", i);
474 }
475 }
476 for (i = 8;i <= 15;++i) {
477 dev_dbg(&client->dev, "\t%sGP%s%d\n",
478 data->gpio_config[i] & 0x02 ? "" : "!",
479 data->gpio_config[i] & 0x01 ? "OUT" : "IN",
480 i);
481 }
482 if (data->config3 & CFG3_GPIO16_ENABLE) {
483 dev_dbg(&client->dev, "\t%sGP%s16\n",
484 data->gpio_config[16] & 0x02 ? "" : "!",
485 data->gpio_config[16] & 0x01 ? "OUT" : "IN");
486 } else {
487 /* GPIO16 is THERM */
488 dev_dbg(&client->dev, "\tTHERM\n");
489 }
490}
491
492void adm1026_fixup_gpio(struct i2c_client *client)
493{
494 struct adm1026_data *data = i2c_get_clientdata(client);
495 int i;
496 int value;
497
498 /* Make the changes requested. */
499 /* We may need to unlock/stop monitoring or soft-reset the
500 * chip before we can make changes. This hasn't been
501 * tested much. FIXME
502 */
503
504 /* Make outputs */
505 for (i = 0;i <= 16;++i) {
506 if (gpio_output[i] >= 0 && gpio_output[i] <= 16) {
507 data->gpio_config[gpio_output[i]] |= 0x01;
508 }
509 /* if GPIO0-7 is output, it isn't a FAN tach */
510 if (gpio_output[i] >= 0 && gpio_output[i] <= 7) {
511 data->config2 |= 1 << gpio_output[i];
512 }
513 }
514
515 /* Input overrides output */
516 for (i = 0;i <= 16;++i) {
517 if (gpio_input[i] >= 0 && gpio_input[i] <= 16) {
518 data->gpio_config[gpio_input[i]] &= ~ 0x01;
519 }
520 /* if GPIO0-7 is input, it isn't a FAN tach */
521 if (gpio_input[i] >= 0 && gpio_input[i] <= 7) {
522 data->config2 |= 1 << gpio_input[i];
523 }
524 }
525
526 /* Inverted */
527 for (i = 0;i <= 16;++i) {
528 if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
529 data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
530 }
531 }
532
533 /* Normal overrides inverted */
534 for (i = 0;i <= 16;++i) {
535 if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
536 data->gpio_config[gpio_normal[i]] |= 0x02;
537 }
538 }
539
540 /* Fan overrides input and output */
541 for (i = 0;i <= 7;++i) {
542 if (gpio_fan[i] >= 0 && gpio_fan[i] <= 7) {
543 data->config2 &= ~(1 << gpio_fan[i]);
544 }
545 }
546
547 /* Write new configs to registers */
548 adm1026_write_value(client, ADM1026_REG_CONFIG2, data->config2);
549 data->config3 = (data->config3 & 0x3f)
550 | ((data->gpio_config[16] & 0x03) << 6);
551 adm1026_write_value(client, ADM1026_REG_CONFIG3, data->config3);
552 for (i = 15, value = 0;i >= 0;--i) {
553 value <<= 2;
554 value |= data->gpio_config[i] & 0x03;
555 if ((i & 0x03) == 0) {
556 adm1026_write_value(client,
557 ADM1026_REG_GPIO_CFG_0_3 + i/4,
558 value);
559 value = 0;
560 }
561 }
562
563 /* Print the new config */
564 adm1026_print_gpio(client);
565}
566
567
568static struct adm1026_data *adm1026_update_device(struct device *dev)
569{
570 struct i2c_client *client = to_i2c_client(dev);
571 struct adm1026_data *data = i2c_get_clientdata(client);
572 int i;
573 long value, alarms, gpio;
574
575 down(&data->update_lock);
576 if (!data->valid
577 || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
578 /* Things that change quickly */
579 dev_dbg(&client->dev,"Reading sensor values\n");
580 for (i = 0;i <= 16;++i) {
581 data->in[i] =
582 adm1026_read_value(client, ADM1026_REG_IN[i]);
583 }
584
585 for (i = 0;i <= 7;++i) {
586 data->fan[i] =
587 adm1026_read_value(client, ADM1026_REG_FAN(i));
588 }
589
590 for (i = 0;i <= 2;++i) {
591 /* NOTE: temp[] is s8 and we assume 2's complement
592 * "conversion" in the assignment */
593 data->temp[i] =
594 adm1026_read_value(client, ADM1026_REG_TEMP[i]);
595 }
596
597 data->pwm1.pwm = adm1026_read_value(client,
598 ADM1026_REG_PWM);
599 data->analog_out = adm1026_read_value(client,
600 ADM1026_REG_DAC);
601 /* GPIO16 is MSbit of alarms, move it to gpio */
602 alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
603 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
604 alarms &= 0x7f;
605 alarms <<= 8;
606 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
607 alarms <<= 8;
608 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS2);
609 alarms <<= 8;
610 alarms |= adm1026_read_value(client, ADM1026_REG_STATUS1);
611 data->alarms = alarms;
612
613 /* Read the GPIO values */
614 gpio |= adm1026_read_value(client,
615 ADM1026_REG_GPIO_STATUS_8_15);
616 gpio <<= 8;
617 gpio |= adm1026_read_value(client,
618 ADM1026_REG_GPIO_STATUS_0_7);
619 data->gpio = gpio;
620
621 data->last_reading = jiffies;
622 }; /* last_reading */
623
624 if (!data->valid ||
625 time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
626 /* Things that don't change often */
627 dev_dbg(&client->dev, "Reading config values\n");
628 for (i = 0;i <= 16;++i) {
629 data->in_min[i] = adm1026_read_value(client,
630 ADM1026_REG_IN_MIN[i]);
631 data->in_max[i] = adm1026_read_value(client,
632 ADM1026_REG_IN_MAX[i]);
633 }
634
635 value = adm1026_read_value(client, ADM1026_REG_FAN_DIV_0_3)
636 | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
637 << 8);
638 for (i = 0;i <= 7;++i) {
639 data->fan_min[i] = adm1026_read_value(client,
640 ADM1026_REG_FAN_MIN(i));
641 data->fan_div[i] = DIV_FROM_REG(value & 0x03);
642 value >>= 2;
643 }
644
645 for (i = 0; i <= 2; ++i) {
646 /* NOTE: temp_xxx[] are s8 and we assume 2's
647 * complement "conversion" in the assignment
648 */
649 data->temp_min[i] = adm1026_read_value(client,
650 ADM1026_REG_TEMP_MIN[i]);
651 data->temp_max[i] = adm1026_read_value(client,
652 ADM1026_REG_TEMP_MAX[i]);
653 data->temp_tmin[i] = adm1026_read_value(client,
654 ADM1026_REG_TEMP_TMIN[i]);
655 data->temp_crit[i] = adm1026_read_value(client,
656 ADM1026_REG_TEMP_THERM[i]);
657 data->temp_offset[i] = adm1026_read_value(client,
658 ADM1026_REG_TEMP_OFFSET[i]);
659 }
660
661 /* Read the STATUS/alarm masks */
662 alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
663 gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
664 alarms = (alarms & 0x7f) << 8;
665 alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
666 alarms <<= 8;
667 alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
668 alarms <<= 8;
669 alarms |= adm1026_read_value(client, ADM1026_REG_MASK1);
670 data->alarm_mask = alarms;
671
672 /* Read the GPIO values */
673 gpio |= adm1026_read_value(client,
674 ADM1026_REG_GPIO_MASK_8_15);
675 gpio <<= 8;
676 gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
677 data->gpio_mask = gpio;
678
679 /* Read various values from CONFIG1 */
680 data->config1 = adm1026_read_value(client,
681 ADM1026_REG_CONFIG1);
682 if (data->config1 & CFG1_PWM_AFC) {
683 data->pwm1.enable = 2;
684 data->pwm1.auto_pwm_min =
685 PWM_MIN_FROM_REG(data->pwm1.pwm);
686 }
687 /* Read the GPIO config */
688 data->config2 = adm1026_read_value(client,
689 ADM1026_REG_CONFIG2);
690 data->config3 = adm1026_read_value(client,
691 ADM1026_REG_CONFIG3);
692 data->gpio_config[16] = (data->config3 >> 6) & 0x03;
693
694 value = 0;
695 for (i = 0;i <= 15;++i) {
696 if ((i & 0x03) == 0) {
697 value = adm1026_read_value(client,
698 ADM1026_REG_GPIO_CFG_0_3 + i/4);
699 }
700 data->gpio_config[i] = value & 0x03;
701 value >>= 2;
702 }
703
704 data->last_config = jiffies;
705 }; /* last_config */
706
707 dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
708 data->vid = (data->gpio >> 11) & 0x1f;
709 data->valid = 1;
710 up(&data->update_lock);
711 return data;
712}
713
714static ssize_t show_in(struct device *dev, char *buf, int nr)
715{
716 struct adm1026_data *data = adm1026_update_device(dev);
717 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
718}
719static ssize_t show_in_min(struct device *dev, char *buf, int nr)
720{
721 struct adm1026_data *data = adm1026_update_device(dev);
722 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
723}
724static ssize_t set_in_min(struct device *dev, const char *buf,
725 size_t count, int nr)
726{
727 struct i2c_client *client = to_i2c_client(dev);
728 struct adm1026_data *data = i2c_get_clientdata(client);
729 int val = simple_strtol(buf, NULL, 10);
730
731 down(&data->update_lock);
732 data->in_min[nr] = INS_TO_REG(nr, val);
733 adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
734 up(&data->update_lock);
735 return count;
736}
737static ssize_t show_in_max(struct device *dev, char *buf, int nr)
738{
739 struct adm1026_data *data = adm1026_update_device(dev);
740 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
741}
742static ssize_t set_in_max(struct device *dev, const char *buf,
743 size_t count, int nr)
744{
745 struct i2c_client *client = to_i2c_client(dev);
746 struct adm1026_data *data = i2c_get_clientdata(client);
747 int val = simple_strtol(buf, NULL, 10);
748
749 down(&data->update_lock);
750 data->in_max[nr] = INS_TO_REG(nr, val);
751 adm1026_write_value(client, ADM1026_REG_IN_MAX[nr], data->in_max[nr]);
752 up(&data->update_lock);
753 return count;
754}
755
756#define in_reg(offset) \
757static ssize_t show_in##offset (struct device *dev, char *buf) \
758{ \
759 return show_in(dev, buf, offset); \
760} \
761static ssize_t show_in##offset##_min (struct device *dev, char *buf) \
762{ \
763 return show_in_min(dev, buf, offset); \
764} \
765static ssize_t set_in##offset##_min (struct device *dev, \
766 const char *buf, size_t count) \
767{ \
768 return set_in_min(dev, buf, count, offset); \
769} \
770static ssize_t show_in##offset##_max (struct device *dev, char *buf) \
771{ \
772 return show_in_max(dev, buf, offset); \
773} \
774static ssize_t set_in##offset##_max (struct device *dev, \
775 const char *buf, size_t count) \
776{ \
777 return set_in_max(dev, buf, count, offset); \
778} \
779static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); \
780static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
781 show_in##offset##_min, set_in##offset##_min); \
782static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
783 show_in##offset##_max, set_in##offset##_max);
784
785
786in_reg(0);
787in_reg(1);
788in_reg(2);
789in_reg(3);
790in_reg(4);
791in_reg(5);
792in_reg(6);
793in_reg(7);
794in_reg(8);
795in_reg(9);
796in_reg(10);
797in_reg(11);
798in_reg(12);
799in_reg(13);
800in_reg(14);
801in_reg(15);
802
803static ssize_t show_in16(struct device *dev, char *buf)
804{
805 struct adm1026_data *data = adm1026_update_device(dev);
806 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
807 NEG12_OFFSET);
808}
809static ssize_t show_in16_min(struct device *dev, char *buf)
810{
811 struct adm1026_data *data = adm1026_update_device(dev);
812 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
813 - NEG12_OFFSET);
814}
815static ssize_t set_in16_min(struct device *dev, const char *buf, size_t count)
816{
817 struct i2c_client *client = to_i2c_client(dev);
818 struct adm1026_data *data = i2c_get_clientdata(client);
819 int val = simple_strtol(buf, NULL, 10);
820
821 down(&data->update_lock);
822 data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
823 adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
824 up(&data->update_lock);
825 return count;
826}
827static ssize_t show_in16_max(struct device *dev, char *buf)
828{
829 struct adm1026_data *data = adm1026_update_device(dev);
830 return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
831 - NEG12_OFFSET);
832}
833static ssize_t set_in16_max(struct device *dev, const char *buf, size_t count)
834{
835 struct i2c_client *client = to_i2c_client(dev);
836 struct adm1026_data *data = i2c_get_clientdata(client);
837 int val = simple_strtol(buf, NULL, 10);
838
839 down(&data->update_lock);
840 data->in_max[16] = INS_TO_REG(16, val+NEG12_OFFSET);
841 adm1026_write_value(client, ADM1026_REG_IN_MAX[16], data->in_max[16]);
842 up(&data->update_lock);
843 return count;
844}
845
846static DEVICE_ATTR(in16_input, S_IRUGO, show_in16, NULL);
847static DEVICE_ATTR(in16_min, S_IRUGO | S_IWUSR, show_in16_min, set_in16_min);
848static DEVICE_ATTR(in16_max, S_IRUGO | S_IWUSR, show_in16_max, set_in16_max);
849
850
851
852
853/* Now add fan read/write functions */
854
855static ssize_t show_fan(struct device *dev, char *buf, int nr)
856{
857 struct adm1026_data *data = adm1026_update_device(dev);
858 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
859 data->fan_div[nr]));
860}
861static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
862{
863 struct adm1026_data *data = adm1026_update_device(dev);
864 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
865 data->fan_div[nr]));
866}
867static ssize_t set_fan_min(struct device *dev, const char *buf,
868 size_t count, int nr)
869{
870 struct i2c_client *client = to_i2c_client(dev);
871 struct adm1026_data *data = i2c_get_clientdata(client);
872 int val = simple_strtol(buf, NULL, 10);
873
874 down(&data->update_lock);
875 data->fan_min[nr] = FAN_TO_REG(val, data->fan_div[nr]);
876 adm1026_write_value(client, ADM1026_REG_FAN_MIN(nr),
877 data->fan_min[nr]);
878 up(&data->update_lock);
879 return count;
880}
881
882#define fan_offset(offset) \
883static ssize_t show_fan_##offset (struct device *dev, char *buf) \
884{ \
885 return show_fan(dev, buf, offset - 1); \
886} \
887static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
888{ \
889 return show_fan_min(dev, buf, offset - 1); \
890} \
891static ssize_t set_fan_##offset##_min (struct device *dev, \
892 const char *buf, size_t count) \
893{ \
894 return set_fan_min(dev, buf, count, offset - 1); \
895} \
896static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
897static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
898 show_fan_##offset##_min, set_fan_##offset##_min);
899
900fan_offset(1);
901fan_offset(2);
902fan_offset(3);
903fan_offset(4);
904fan_offset(5);
905fan_offset(6);
906fan_offset(7);
907fan_offset(8);
908
909/* Adjust fan_min to account for new fan divisor */
910static void fixup_fan_min(struct device *dev, int fan, int old_div)
911{
912 struct i2c_client *client = to_i2c_client(dev);
913 struct adm1026_data *data = i2c_get_clientdata(client);
914 int new_min;
915 int new_div = data->fan_div[fan];
916
917 /* 0 and 0xff are special. Don't adjust them */
918 if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
919 return;
920 }
921
922 new_min = data->fan_min[fan] * old_div / new_div;
923 new_min = SENSORS_LIMIT(new_min, 1, 254);
924 data->fan_min[fan] = new_min;
925 adm1026_write_value(client, ADM1026_REG_FAN_MIN(fan), new_min);
926}
927
928/* Now add fan_div read/write functions */
929static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
930{
931 struct adm1026_data *data = adm1026_update_device(dev);
932 return sprintf(buf,"%d\n", data->fan_div[nr]);
933}
934static ssize_t set_fan_div(struct device *dev, const char *buf,
935 size_t count, int nr)
936{
937 struct i2c_client *client = to_i2c_client(dev);
938 struct adm1026_data *data = i2c_get_clientdata(client);
939 int val,orig_div,new_div,shift;
940
941 val = simple_strtol(buf, NULL, 10);
942 new_div = DIV_TO_REG(val);
943 if (new_div == 0) {
944 return -EINVAL;
945 }
946 down(&data->update_lock);
947 orig_div = data->fan_div[nr];
948 data->fan_div[nr] = DIV_FROM_REG(new_div);
949
950 if (nr < 4) { /* 0 <= nr < 4 */
951 shift = 2 * nr;
952 adm1026_write_value(client, ADM1026_REG_FAN_DIV_0_3,
953 ((DIV_TO_REG(orig_div) & (~(0x03 << shift))) |
954 (new_div << shift)));
955 } else { /* 3 < nr < 8 */
956 shift = 2 * (nr - 4);
957 adm1026_write_value(client, ADM1026_REG_FAN_DIV_4_7,
958 ((DIV_TO_REG(orig_div) & (~(0x03 << (2 * shift)))) |
959 (new_div << shift)));
960 }
961
962 if (data->fan_div[nr] != orig_div) {
963 fixup_fan_min(dev,nr,orig_div);
964 }
965 up(&data->update_lock);
966 return count;
967}
968
969#define fan_offset_div(offset) \
970static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
971{ \
972 return show_fan_div(dev, buf, offset - 1); \
973} \
974static ssize_t set_fan_##offset##_div (struct device *dev, \
975 const char *buf, size_t count) \
976{ \
977 return set_fan_div(dev, buf, count, offset - 1); \
978} \
979static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
980 show_fan_##offset##_div, set_fan_##offset##_div);
981
982fan_offset_div(1);
983fan_offset_div(2);
984fan_offset_div(3);
985fan_offset_div(4);
986fan_offset_div(5);
987fan_offset_div(6);
988fan_offset_div(7);
989fan_offset_div(8);
990
991/* Temps */
992static ssize_t show_temp(struct device *dev, char *buf, int nr)
993{
994 struct adm1026_data *data = adm1026_update_device(dev);
995 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
996}
997static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
998{
999 struct adm1026_data *data = adm1026_update_device(dev);
1000 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
1001}
1002static ssize_t set_temp_min(struct device *dev, const char *buf,
1003 size_t count, int nr)
1004{
1005 struct i2c_client *client = to_i2c_client(dev);
1006 struct adm1026_data *data = i2c_get_clientdata(client);
1007 int val = simple_strtol(buf, NULL, 10);
1008
1009 down(&data->update_lock);
1010 data->temp_min[nr] = TEMP_TO_REG(val);
1011 adm1026_write_value(client, ADM1026_REG_TEMP_MIN[nr],
1012 data->temp_min[nr]);
1013 up(&data->update_lock);
1014 return count;
1015}
1016static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
1017{
1018 struct adm1026_data *data = adm1026_update_device(dev);
1019 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
1020}
1021static ssize_t set_temp_max(struct device *dev, const char *buf,
1022 size_t count, int nr)
1023{
1024 struct i2c_client *client = to_i2c_client(dev);
1025 struct adm1026_data *data = i2c_get_clientdata(client);
1026 int val = simple_strtol(buf, NULL, 10);
1027
1028 down(&data->update_lock);
1029 data->temp_max[nr] = TEMP_TO_REG(val);
1030 adm1026_write_value(client, ADM1026_REG_TEMP_MAX[nr],
1031 data->temp_max[nr]);
1032 up(&data->update_lock);
1033 return count;
1034}
1035#define temp_reg(offset) \
1036static ssize_t show_temp_##offset (struct device *dev, char *buf) \
1037{ \
1038 return show_temp(dev, buf, offset - 1); \
1039} \
1040static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
1041{ \
1042 return show_temp_min(dev, buf, offset - 1); \
1043} \
1044static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
1045{ \
1046 return show_temp_max(dev, buf, offset - 1); \
1047} \
1048static ssize_t set_temp_##offset##_min (struct device *dev, \
1049 const char *buf, size_t count) \
1050{ \
1051 return set_temp_min(dev, buf, count, offset - 1); \
1052} \
1053static ssize_t set_temp_##offset##_max (struct device *dev, \
1054 const char *buf, size_t count) \
1055{ \
1056 return set_temp_max(dev, buf, count, offset - 1); \
1057} \
1058static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
1059static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
1060 show_temp_##offset##_min, set_temp_##offset##_min); \
1061static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
1062 show_temp_##offset##_max, set_temp_##offset##_max);
1063
1064
1065temp_reg(1);
1066temp_reg(2);
1067temp_reg(3);
1068
1069static ssize_t show_temp_offset(struct device *dev, char *buf, int nr)
1070{
1071 struct adm1026_data *data = adm1026_update_device(dev);
1072 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
1073}
1074static ssize_t set_temp_offset(struct device *dev, const char *buf,
1075 size_t count, int nr)
1076{
1077 struct i2c_client *client = to_i2c_client(dev);
1078 struct adm1026_data *data = i2c_get_clientdata(client);
1079 int val = simple_strtol(buf, NULL, 10);
1080
1081 down(&data->update_lock);
1082 data->temp_offset[nr] = TEMP_TO_REG(val);
1083 adm1026_write_value(client, ADM1026_REG_TEMP_OFFSET[nr],
1084 data->temp_offset[nr]);
1085 up(&data->update_lock);
1086 return count;
1087}
1088
1089#define temp_offset_reg(offset) \
1090static ssize_t show_temp_##offset##_offset (struct device *dev, char *buf) \
1091{ \
1092 return show_temp_offset(dev, buf, offset - 1); \
1093} \
1094static ssize_t set_temp_##offset##_offset (struct device *dev, \
1095 const char *buf, size_t count) \
1096{ \
1097 return set_temp_offset(dev, buf, count, offset - 1); \
1098} \
1099static DEVICE_ATTR(temp##offset##_offset, S_IRUGO | S_IWUSR, \
1100 show_temp_##offset##_offset, set_temp_##offset##_offset);
1101
1102temp_offset_reg(1);
1103temp_offset_reg(2);
1104temp_offset_reg(3);
1105
1106static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev, char *buf,
1107 int nr)
1108{
1109 struct adm1026_data *data = adm1026_update_device(dev);
1110 return sprintf(buf,"%d\n", TEMP_FROM_REG(
1111 ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
1112}
1113static ssize_t show_temp_auto_point2_temp(struct device *dev, char *buf,
1114 int nr)
1115{
1116 struct adm1026_data *data = adm1026_update_device(dev);
1117 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
1118 ADM1026_FAN_CONTROL_TEMP_RANGE));
1119}
1120static ssize_t show_temp_auto_point1_temp(struct device *dev, char *buf,
1121 int nr)
1122{
1123 struct adm1026_data *data = adm1026_update_device(dev);
1124 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
1125}
1126static ssize_t set_temp_auto_point1_temp(struct device *dev, const char *buf,
1127 size_t count, int nr)
1128{
1129 struct i2c_client *client = to_i2c_client(dev);
1130 struct adm1026_data *data = i2c_get_clientdata(client);
1131 int val = simple_strtol(buf, NULL, 10);
1132
1133 down(&data->update_lock);
1134 data->temp_tmin[nr] = TEMP_TO_REG(val);
1135 adm1026_write_value(client, ADM1026_REG_TEMP_TMIN[nr],
1136 data->temp_tmin[nr]);
1137 up(&data->update_lock);
1138 return count;
1139}
1140
1141#define temp_auto_point(offset) \
1142static ssize_t show_temp##offset##_auto_point1_temp (struct device *dev, \
1143 char *buf) \
1144{ \
1145 return show_temp_auto_point1_temp(dev, buf, offset - 1); \
1146} \
1147static ssize_t set_temp##offset##_auto_point1_temp (struct device *dev, \
1148 const char *buf, size_t count) \
1149{ \
1150 return set_temp_auto_point1_temp(dev, buf, count, offset - 1); \
1151} \
1152static ssize_t show_temp##offset##_auto_point1_temp_hyst (struct device \
1153 *dev, char *buf) \
1154{ \
1155 return show_temp_auto_point1_temp_hyst(dev, buf, offset - 1); \
1156} \
1157static ssize_t show_temp##offset##_auto_point2_temp (struct device *dev, \
1158 char *buf) \
1159{ \
1160 return show_temp_auto_point2_temp(dev, buf, offset - 1); \
1161} \
1162static DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR, \
1163 show_temp##offset##_auto_point1_temp, \
1164 set_temp##offset##_auto_point1_temp); \
1165static DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO, \
1166 show_temp##offset##_auto_point1_temp_hyst, NULL); \
1167static DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO, \
1168 show_temp##offset##_auto_point2_temp, NULL);
1169
1170temp_auto_point(1);
1171temp_auto_point(2);
1172temp_auto_point(3);
1173
1174static ssize_t show_temp_crit_enable(struct device *dev, char *buf)
1175{
1176 struct adm1026_data *data = adm1026_update_device(dev);
1177 return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
1178}
1179static ssize_t set_temp_crit_enable(struct device *dev, const char *buf,
1180 size_t count)
1181{
1182 struct i2c_client *client = to_i2c_client(dev);
1183 struct adm1026_data *data = i2c_get_clientdata(client);
1184 int val = simple_strtol(buf, NULL, 10);
1185
1186 if ((val == 1) || (val==0)) {
1187 down(&data->update_lock);
1188 data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
1189 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1190 data->config1);
1191 up(&data->update_lock);
1192 }
1193 return count;
1194}
1195
1196static DEVICE_ATTR(temp1_crit_enable, S_IRUGO | S_IWUSR,
1197 show_temp_crit_enable, set_temp_crit_enable);
1198
1199static DEVICE_ATTR(temp2_crit_enable, S_IRUGO | S_IWUSR,
1200 show_temp_crit_enable, set_temp_crit_enable);
1201
1202static DEVICE_ATTR(temp3_crit_enable, S_IRUGO | S_IWUSR,
1203 show_temp_crit_enable, set_temp_crit_enable);
1204
1205
1206static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
1207{
1208 struct adm1026_data *data = adm1026_update_device(dev);
1209 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
1210}
1211static ssize_t set_temp_crit(struct device *dev, const char *buf,
1212 size_t count, int nr)
1213{
1214 struct i2c_client *client = to_i2c_client(dev);
1215 struct adm1026_data *data = i2c_get_clientdata(client);
1216 int val = simple_strtol(buf, NULL, 10);
1217
1218 down(&data->update_lock);
1219 data->temp_crit[nr] = TEMP_TO_REG(val);
1220 adm1026_write_value(client, ADM1026_REG_TEMP_THERM[nr],
1221 data->temp_crit[nr]);
1222 up(&data->update_lock);
1223 return count;
1224}
1225
1226#define temp_crit_reg(offset) \
1227static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
1228{ \
1229 return show_temp_crit(dev, buf, offset - 1); \
1230} \
1231static ssize_t set_temp_##offset##_crit (struct device *dev, \
1232 const char *buf, size_t count) \
1233{ \
1234 return set_temp_crit(dev, buf, count, offset - 1); \
1235} \
1236static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
1237 show_temp_##offset##_crit, set_temp_##offset##_crit);
1238
1239temp_crit_reg(1);
1240temp_crit_reg(2);
1241temp_crit_reg(3);
1242
1243static ssize_t show_analog_out_reg(struct device *dev, char *buf)
1244{
1245 struct adm1026_data *data = adm1026_update_device(dev);
1246 return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
1247}
1248static ssize_t set_analog_out_reg(struct device *dev, const char *buf,
1249 size_t count)
1250{
1251 struct i2c_client *client = to_i2c_client(dev);
1252 struct adm1026_data *data = i2c_get_clientdata(client);
1253 int val = simple_strtol(buf, NULL, 10);
1254
1255 down(&data->update_lock);
1256 data->analog_out = DAC_TO_REG(val);
1257 adm1026_write_value(client, ADM1026_REG_DAC, data->analog_out);
1258 up(&data->update_lock);
1259 return count;
1260}
1261
1262static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
1263 set_analog_out_reg);
1264
1265static ssize_t show_vid_reg(struct device *dev, char *buf)
1266{
1267 struct adm1026_data *data = adm1026_update_device(dev);
1268 return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
1269}
1270
1271static DEVICE_ATTR(vid, S_IRUGO, show_vid_reg, NULL);
1272
1273static ssize_t show_vrm_reg(struct device *dev, char *buf)
1274{
1275 struct adm1026_data *data = adm1026_update_device(dev);
1276 return sprintf(buf,"%d\n", data->vrm);
1277}
1278static ssize_t store_vrm_reg(struct device *dev, const char *buf,
1279 size_t count)
1280{
1281 struct i2c_client *client = to_i2c_client(dev);
1282 struct adm1026_data *data = i2c_get_clientdata(client);
1283
1284 data->vrm = simple_strtol(buf, NULL, 10);
1285 return count;
1286}
1287
1288static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
1289
1290static ssize_t show_alarms_reg(struct device *dev, char *buf)
1291{
1292 struct adm1026_data *data = adm1026_update_device(dev);
1293 return sprintf(buf, "%ld\n", (long) (data->alarms));
1294}
1295
1296static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
1297
1298static ssize_t show_alarm_mask(struct device *dev, char *buf)
1299{
1300 struct adm1026_data *data = adm1026_update_device(dev);
1301 return sprintf(buf,"%ld\n", data->alarm_mask);
1302}
1303static ssize_t set_alarm_mask(struct device *dev, const char *buf,
1304 size_t count)
1305{
1306 struct i2c_client *client = to_i2c_client(dev);
1307 struct adm1026_data *data = i2c_get_clientdata(client);
1308 int val = simple_strtol(buf, NULL, 10);
1309 unsigned long mask;
1310
1311 down(&data->update_lock);
1312 data->alarm_mask = val & 0x7fffffff;
1313 mask = data->alarm_mask
1314 | (data->gpio_mask & 0x10000 ? 0x80000000 : 0);
1315 adm1026_write_value(client, ADM1026_REG_MASK1,
1316 mask & 0xff);
1317 mask >>= 8;
1318 adm1026_write_value(client, ADM1026_REG_MASK2,
1319 mask & 0xff);
1320 mask >>= 8;
1321 adm1026_write_value(client, ADM1026_REG_MASK3,
1322 mask & 0xff);
1323 mask >>= 8;
1324 adm1026_write_value(client, ADM1026_REG_MASK4,
1325 mask & 0xff);
1326 up(&data->update_lock);
1327 return count;
1328}
1329
1330static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
1331 set_alarm_mask);
1332
1333
1334static ssize_t show_gpio(struct device *dev, char *buf)
1335{
1336 struct adm1026_data *data = adm1026_update_device(dev);
1337 return sprintf(buf,"%ld\n", data->gpio);
1338}
1339static ssize_t set_gpio(struct device *dev, const char *buf,
1340 size_t count)
1341{
1342 struct i2c_client *client = to_i2c_client(dev);
1343 struct adm1026_data *data = i2c_get_clientdata(client);
1344 int val = simple_strtol(buf, NULL, 10);
1345 long gpio;
1346
1347 down(&data->update_lock);
1348 data->gpio = val & 0x1ffff;
1349 gpio = data->gpio;
1350 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
1351 gpio >>= 8;
1352 adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
1353 gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
1354 adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
1355 up(&data->update_lock);
1356 return count;
1357}
1358
1359static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
1360
1361
1362static ssize_t show_gpio_mask(struct device *dev, char *buf)
1363{
1364 struct adm1026_data *data = adm1026_update_device(dev);
1365 return sprintf(buf,"%ld\n", data->gpio_mask);
1366}
1367static ssize_t set_gpio_mask(struct device *dev, const char *buf,
1368 size_t count)
1369{
1370 struct i2c_client *client = to_i2c_client(dev);
1371 struct adm1026_data *data = i2c_get_clientdata(client);
1372 int val = simple_strtol(buf, NULL, 10);
1373 long mask;
1374
1375 down(&data->update_lock);
1376 data->gpio_mask = val & 0x1ffff;
1377 mask = data->gpio_mask;
1378 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
1379 mask >>= 8;
1380 adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
1381 mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
1382 adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
1383 up(&data->update_lock);
1384 return count;
1385}
1386
1387static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
1388
1389static ssize_t show_pwm_reg(struct device *dev, char *buf)
1390{
1391 struct adm1026_data *data = adm1026_update_device(dev);
1392 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
1393}
1394static ssize_t set_pwm_reg(struct device *dev, const char *buf,
1395 size_t count)
1396{
1397 struct i2c_client *client = to_i2c_client(dev);
1398 struct adm1026_data *data = i2c_get_clientdata(client);
1399
1400 if (data->pwm1.enable == 1) {
1401 int val = simple_strtol(buf, NULL, 10);
1402
1403 down(&data->update_lock);
1404 data->pwm1.pwm = PWM_TO_REG(val);
1405 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1406 up(&data->update_lock);
1407 }
1408 return count;
1409}
1410static ssize_t show_auto_pwm_min(struct device *dev, char *buf)
1411{
1412 struct adm1026_data *data = adm1026_update_device(dev);
1413 return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
1414}
1415static ssize_t set_auto_pwm_min(struct device *dev, const char *buf,
1416 size_t count)
1417{
1418 struct i2c_client *client = to_i2c_client(dev);
1419 struct adm1026_data *data = i2c_get_clientdata(client);
1420 int val = simple_strtol(buf, NULL, 10);
1421
1422 down(&data->update_lock);
1423 data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
1424 if (data->pwm1.enable == 2) { /* apply immediately */
1425 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1426 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1427 adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
1428 }
1429 up(&data->update_lock);
1430 return count;
1431}
1432static ssize_t show_auto_pwm_max(struct device *dev, char *buf)
1433{
1434 return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
1435}
1436static ssize_t show_pwm_enable(struct device *dev, char *buf)
1437{
1438 struct adm1026_data *data = adm1026_update_device(dev);
1439 return sprintf(buf,"%d\n", data->pwm1.enable);
1440}
1441static ssize_t set_pwm_enable(struct device *dev, const char *buf,
1442 size_t count)
1443{
1444 struct i2c_client *client = to_i2c_client(dev);
1445 struct adm1026_data *data = i2c_get_clientdata(client);
1446 int val = simple_strtol(buf, NULL, 10);
1447 int old_enable;
1448
1449 if ((val >= 0) && (val < 3)) {
1450 down(&data->update_lock);
1451 old_enable = data->pwm1.enable;
1452 data->pwm1.enable = val;
1453 data->config1 = (data->config1 & ~CFG1_PWM_AFC)
1454 | ((val == 2) ? CFG1_PWM_AFC : 0);
1455 adm1026_write_value(client, ADM1026_REG_CONFIG1,
1456 data->config1);
1457 if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
1458 data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
1459 PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
1460 adm1026_write_value(client, ADM1026_REG_PWM,
1461 data->pwm1.pwm);
1462 } else if (!((old_enable == 1) && (val == 1))) {
1463 /* set pwm to safe value */
1464 data->pwm1.pwm = 255;
1465 adm1026_write_value(client, ADM1026_REG_PWM,
1466 data->pwm1.pwm);
1467 }
1468 up(&data->update_lock);
1469 }
1470 return count;
1471}
1472
1473/* enable PWM fan control */
1474static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1475static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1476static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
1477static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1478 set_pwm_enable);
1479static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1480 set_pwm_enable);
1481static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
1482 set_pwm_enable);
1483static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1484 show_auto_pwm_min, set_auto_pwm_min);
1485static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1486 show_auto_pwm_min, set_auto_pwm_min);
1487static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1488 show_auto_pwm_min, set_auto_pwm_min);
1489
1490static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1491static DEVICE_ATTR(temp2_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1492static DEVICE_ATTR(temp3_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
1493
1494int adm1026_detect(struct i2c_adapter *adapter, int address,
1495 int kind)
1496{
1497 int company, verstep;
1498 struct i2c_client *new_client;
1499 struct adm1026_data *data;
1500 int err = 0;
1501 const char *type_name = "";
1502
1503 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1504 /* We need to be able to do byte I/O */
1505 goto exit;
1506 };
1507
1508 /* OK. For now, we presume we have a valid client. We now create the
1509 client structure, even though we cannot fill it completely yet.
1510 But it allows us to access adm1026_{read,write}_value. */
1511
1512 if (!(data = kmalloc(sizeof(struct adm1026_data), GFP_KERNEL))) {
1513 err = -ENOMEM;
1514 goto exit;
1515 }
1516
1517 memset(data, 0, sizeof(struct adm1026_data));
1518
1519 new_client = &data->client;
1520 i2c_set_clientdata(new_client, data);
1521 new_client->addr = address;
1522 new_client->adapter = adapter;
1523 new_client->driver = &adm1026_driver;
1524 new_client->flags = 0;
1525
1526 /* Now, we do the remaining detection. */
1527
1528 company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
1529 verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
1530
1531 dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
1532 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1533 i2c_adapter_id(new_client->adapter), new_client->addr,
1534 company, verstep);
1535
1536 /* If auto-detecting, Determine the chip type. */
1537 if (kind <= 0) {
1538 dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
1539 "...\n", i2c_adapter_id(adapter), address);
1540 if (company == ADM1026_COMPANY_ANALOG_DEV
1541 && verstep == ADM1026_VERSTEP_ADM1026) {
1542 kind = adm1026;
1543 } else if (company == ADM1026_COMPANY_ANALOG_DEV
1544 && (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1545 dev_err(&adapter->dev, ": Unrecognized stepping "
1546 "0x%02x. Defaulting to ADM1026.\n", verstep);
1547 kind = adm1026;
1548 } else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
1549 dev_err(&adapter->dev, ": Found version/stepping "
1550 "0x%02x. Assuming generic ADM1026.\n",
1551 verstep);
1552 kind = any_chip;
1553 } else {
1554 dev_dbg(&new_client->dev, ": Autodetection "
1555 "failed\n");
1556 /* Not an ADM1026 ... */
1557 if (kind == 0) { /* User used force=x,y */
1558 dev_err(&adapter->dev, "Generic ADM1026 not "
1559 "found at %d,0x%02x. Try "
1560 "force_adm1026.\n",
1561 i2c_adapter_id(adapter), address);
1562 }
1563 err = 0;
1564 goto exitfree;
1565 }
1566 }
1567
1568 /* Fill in the chip specific driver values */
1569 switch (kind) {
1570 case any_chip :
1571 type_name = "adm1026";
1572 break;
1573 case adm1026 :
1574 type_name = "adm1026";
1575 break;
1576 default :
1577 dev_err(&adapter->dev, ": Internal error, invalid "
1578 "kind (%d)!", kind);
1579 err = -EFAULT;
1580 goto exitfree;
1581 }
1582 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
1583
1584 /* Fill in the remaining client fields */
1585 data->type = kind;
1586 data->valid = 0;
1587 init_MUTEX(&data->update_lock);
1588
1589 /* Tell the I2C layer a new client has arrived */
1590 if ((err = i2c_attach_client(new_client)))
1591 goto exitfree;
1592
1593 /* Set the VRM version */
1594 data->vrm = i2c_which_vrm();
1595
1596 /* Initialize the ADM1026 chip */
1597 adm1026_init_client(new_client);
1598
1599 /* Register sysfs hooks */
1600 device_create_file(&new_client->dev, &dev_attr_in0_input);
1601 device_create_file(&new_client->dev, &dev_attr_in0_max);
1602 device_create_file(&new_client->dev, &dev_attr_in0_min);
1603 device_create_file(&new_client->dev, &dev_attr_in1_input);
1604 device_create_file(&new_client->dev, &dev_attr_in1_max);
1605 device_create_file(&new_client->dev, &dev_attr_in1_min);
1606 device_create_file(&new_client->dev, &dev_attr_in2_input);
1607 device_create_file(&new_client->dev, &dev_attr_in2_max);
1608 device_create_file(&new_client->dev, &dev_attr_in2_min);
1609 device_create_file(&new_client->dev, &dev_attr_in3_input);
1610 device_create_file(&new_client->dev, &dev_attr_in3_max);
1611 device_create_file(&new_client->dev, &dev_attr_in3_min);
1612 device_create_file(&new_client->dev, &dev_attr_in4_input);
1613 device_create_file(&new_client->dev, &dev_attr_in4_max);
1614 device_create_file(&new_client->dev, &dev_attr_in4_min);
1615 device_create_file(&new_client->dev, &dev_attr_in5_input);
1616 device_create_file(&new_client->dev, &dev_attr_in5_max);
1617 device_create_file(&new_client->dev, &dev_attr_in5_min);
1618 device_create_file(&new_client->dev, &dev_attr_in6_input);
1619 device_create_file(&new_client->dev, &dev_attr_in6_max);
1620 device_create_file(&new_client->dev, &dev_attr_in6_min);
1621 device_create_file(&new_client->dev, &dev_attr_in7_input);
1622 device_create_file(&new_client->dev, &dev_attr_in7_max);
1623 device_create_file(&new_client->dev, &dev_attr_in7_min);
1624 device_create_file(&new_client->dev, &dev_attr_in8_input);
1625 device_create_file(&new_client->dev, &dev_attr_in8_max);
1626 device_create_file(&new_client->dev, &dev_attr_in8_min);
1627 device_create_file(&new_client->dev, &dev_attr_in9_input);
1628 device_create_file(&new_client->dev, &dev_attr_in9_max);
1629 device_create_file(&new_client->dev, &dev_attr_in9_min);
1630 device_create_file(&new_client->dev, &dev_attr_in10_input);
1631 device_create_file(&new_client->dev, &dev_attr_in10_max);
1632 device_create_file(&new_client->dev, &dev_attr_in10_min);
1633 device_create_file(&new_client->dev, &dev_attr_in11_input);
1634 device_create_file(&new_client->dev, &dev_attr_in11_max);
1635 device_create_file(&new_client->dev, &dev_attr_in11_min);
1636 device_create_file(&new_client->dev, &dev_attr_in12_input);
1637 device_create_file(&new_client->dev, &dev_attr_in12_max);
1638 device_create_file(&new_client->dev, &dev_attr_in12_min);
1639 device_create_file(&new_client->dev, &dev_attr_in13_input);
1640 device_create_file(&new_client->dev, &dev_attr_in13_max);
1641 device_create_file(&new_client->dev, &dev_attr_in13_min);
1642 device_create_file(&new_client->dev, &dev_attr_in14_input);
1643 device_create_file(&new_client->dev, &dev_attr_in14_max);
1644 device_create_file(&new_client->dev, &dev_attr_in14_min);
1645 device_create_file(&new_client->dev, &dev_attr_in15_input);
1646 device_create_file(&new_client->dev, &dev_attr_in15_max);
1647 device_create_file(&new_client->dev, &dev_attr_in15_min);
1648 device_create_file(&new_client->dev, &dev_attr_in16_input);
1649 device_create_file(&new_client->dev, &dev_attr_in16_max);
1650 device_create_file(&new_client->dev, &dev_attr_in16_min);
1651 device_create_file(&new_client->dev, &dev_attr_fan1_input);
1652 device_create_file(&new_client->dev, &dev_attr_fan1_div);
1653 device_create_file(&new_client->dev, &dev_attr_fan1_min);
1654 device_create_file(&new_client->dev, &dev_attr_fan2_input);
1655 device_create_file(&new_client->dev, &dev_attr_fan2_div);
1656 device_create_file(&new_client->dev, &dev_attr_fan2_min);
1657 device_create_file(&new_client->dev, &dev_attr_fan3_input);
1658 device_create_file(&new_client->dev, &dev_attr_fan3_div);
1659 device_create_file(&new_client->dev, &dev_attr_fan3_min);
1660 device_create_file(&new_client->dev, &dev_attr_fan4_input);
1661 device_create_file(&new_client->dev, &dev_attr_fan4_div);
1662 device_create_file(&new_client->dev, &dev_attr_fan4_min);
1663 device_create_file(&new_client->dev, &dev_attr_fan5_input);
1664 device_create_file(&new_client->dev, &dev_attr_fan5_div);
1665 device_create_file(&new_client->dev, &dev_attr_fan5_min);
1666 device_create_file(&new_client->dev, &dev_attr_fan6_input);
1667 device_create_file(&new_client->dev, &dev_attr_fan6_div);
1668 device_create_file(&new_client->dev, &dev_attr_fan6_min);
1669 device_create_file(&new_client->dev, &dev_attr_fan7_input);
1670 device_create_file(&new_client->dev, &dev_attr_fan7_div);
1671 device_create_file(&new_client->dev, &dev_attr_fan7_min);
1672 device_create_file(&new_client->dev, &dev_attr_fan8_input);
1673 device_create_file(&new_client->dev, &dev_attr_fan8_div);
1674 device_create_file(&new_client->dev, &dev_attr_fan8_min);
1675 device_create_file(&new_client->dev, &dev_attr_temp1_input);
1676 device_create_file(&new_client->dev, &dev_attr_temp1_max);
1677 device_create_file(&new_client->dev, &dev_attr_temp1_min);
1678 device_create_file(&new_client->dev, &dev_attr_temp2_input);
1679 device_create_file(&new_client->dev, &dev_attr_temp2_max);
1680 device_create_file(&new_client->dev, &dev_attr_temp2_min);
1681 device_create_file(&new_client->dev, &dev_attr_temp3_input);
1682 device_create_file(&new_client->dev, &dev_attr_temp3_max);
1683 device_create_file(&new_client->dev, &dev_attr_temp3_min);
1684 device_create_file(&new_client->dev, &dev_attr_temp1_offset);
1685 device_create_file(&new_client->dev, &dev_attr_temp2_offset);
1686 device_create_file(&new_client->dev, &dev_attr_temp3_offset);
1687 device_create_file(&new_client->dev,
1688 &dev_attr_temp1_auto_point1_temp);
1689 device_create_file(&new_client->dev,
1690 &dev_attr_temp2_auto_point1_temp);
1691 device_create_file(&new_client->dev,
1692 &dev_attr_temp3_auto_point1_temp);
1693 device_create_file(&new_client->dev,
1694 &dev_attr_temp1_auto_point1_temp_hyst);
1695 device_create_file(&new_client->dev,
1696 &dev_attr_temp2_auto_point1_temp_hyst);
1697 device_create_file(&new_client->dev,
1698 &dev_attr_temp3_auto_point1_temp_hyst);
1699 device_create_file(&new_client->dev,
1700 &dev_attr_temp1_auto_point2_temp);
1701 device_create_file(&new_client->dev,
1702 &dev_attr_temp2_auto_point2_temp);
1703 device_create_file(&new_client->dev,
1704 &dev_attr_temp3_auto_point2_temp);
1705 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
1706 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
1707 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
1708 device_create_file(&new_client->dev, &dev_attr_temp1_crit_enable);
1709 device_create_file(&new_client->dev, &dev_attr_temp2_crit_enable);
1710 device_create_file(&new_client->dev, &dev_attr_temp3_crit_enable);
1711 device_create_file(&new_client->dev, &dev_attr_vid);
1712 device_create_file(&new_client->dev, &dev_attr_vrm);
1713 device_create_file(&new_client->dev, &dev_attr_alarms);
1714 device_create_file(&new_client->dev, &dev_attr_alarm_mask);
1715 device_create_file(&new_client->dev, &dev_attr_gpio);
1716 device_create_file(&new_client->dev, &dev_attr_gpio_mask);
1717 device_create_file(&new_client->dev, &dev_attr_pwm1);
1718 device_create_file(&new_client->dev, &dev_attr_pwm2);
1719 device_create_file(&new_client->dev, &dev_attr_pwm3);
1720 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
1721 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
1722 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
1723 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point1_pwm);
1724 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point1_pwm);
1725 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point1_pwm);
1726 device_create_file(&new_client->dev, &dev_attr_temp1_auto_point2_pwm);
1727 device_create_file(&new_client->dev, &dev_attr_temp2_auto_point2_pwm);
1728 device_create_file(&new_client->dev, &dev_attr_temp3_auto_point2_pwm);
1729 device_create_file(&new_client->dev, &dev_attr_analog_out);
1730 return 0;
1731
1732 /* Error out and cleanup code */
1733exitfree:
1734 kfree(new_client);
1735exit:
1736 return err;
1737}
1738static int __init sm_adm1026_init(void)
1739{
1740 return i2c_add_driver(&adm1026_driver);
1741}
1742
1743static void __exit sm_adm1026_exit(void)
1744{
1745 i2c_del_driver(&adm1026_driver);
1746}
1747
1748MODULE_LICENSE("GPL");
1749MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
1750 "Justin Thiessen <jthiessen@penguincomputing.com>");
1751MODULE_DESCRIPTION("ADM1026 driver");
1752
1753module_init(sm_adm1026_init);
1754module_exit(sm_adm1026_exit);
diff --git a/drivers/i2c/chips/adm1031.c b/drivers/i2c/chips/adm1031.c
deleted file mode 100644
index d4385a23f79a..000000000000
--- a/drivers/i2c/chips/adm1031.c
+++ /dev/null
@@ -1,977 +0,0 @@
1/*
2 adm1031.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Based on lm75.c and lm85.c
5 Supports adm1030 / adm1031
6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
7 Reworked by Jean Delvare <khali@linux-fr.org>
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/i2c.h>
29#include <linux/i2c-sensor.h>
30
31/* Following macros takes channel parameter starting from 0 to 2 */
32#define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr))
33#define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr))
34#define ADM1031_REG_PWM (0x22)
35#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr))
36
37#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4*(nr))
38#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4*(nr))
39#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4*(nr))
40
41#define ADM1031_REG_TEMP(nr) (0xa + (nr))
42#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr))
43
44#define ADM1031_REG_STATUS(nr) (0x2 + (nr))
45
46#define ADM1031_REG_CONF1 0x0
47#define ADM1031_REG_CONF2 0x1
48#define ADM1031_REG_EXT_TEMP 0x6
49
50#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */
51#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */
52#define ADM1031_CONF1_AUTO_MODE 0x80 /* Auto FAN */
53
54#define ADM1031_CONF2_PWM1_ENABLE 0x01
55#define ADM1031_CONF2_PWM2_ENABLE 0x02
56#define ADM1031_CONF2_TACH1_ENABLE 0x04
57#define ADM1031_CONF2_TACH2_ENABLE 0x08
58#define ADM1031_CONF2_TEMP_ENABLE(chan) (0x10 << (chan))
59
60/* Addresses to scan */
61static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
62static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
63
64/* Insmod parameters */
65SENSORS_INSMOD_2(adm1030, adm1031);
66
67typedef u8 auto_chan_table_t[8][2];
68
69/* Each client has this additional data */
70struct adm1031_data {
71 struct i2c_client client;
72 struct semaphore update_lock;
73 int chip_type;
74 char valid; /* !=0 if following fields are valid */
75 unsigned long last_updated; /* In jiffies */
76 /* The chan_select_table contains the possible configurations for
77 * auto fan control.
78 */
79 auto_chan_table_t *chan_select_table;
80 u16 alarm;
81 u8 conf1;
82 u8 conf2;
83 u8 fan[2];
84 u8 fan_div[2];
85 u8 fan_min[2];
86 u8 pwm[2];
87 u8 old_pwm[2];
88 s8 temp[3];
89 u8 ext_temp[3];
90 u8 auto_temp[3];
91 u8 auto_temp_min[3];
92 u8 auto_temp_off[3];
93 u8 auto_temp_max[3];
94 s8 temp_min[3];
95 s8 temp_max[3];
96 s8 temp_crit[3];
97};
98
99static int adm1031_attach_adapter(struct i2c_adapter *adapter);
100static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind);
101static void adm1031_init_client(struct i2c_client *client);
102static int adm1031_detach_client(struct i2c_client *client);
103static struct adm1031_data *adm1031_update_device(struct device *dev);
104
105/* This is the driver that will be inserted */
106static struct i2c_driver adm1031_driver = {
107 .owner = THIS_MODULE,
108 .name = "adm1031",
109 .flags = I2C_DF_NOTIFY,
110 .attach_adapter = adm1031_attach_adapter,
111 .detach_client = adm1031_detach_client,
112};
113
114static inline u8 adm1031_read_value(struct i2c_client *client, u8 reg)
115{
116 return i2c_smbus_read_byte_data(client, reg);
117}
118
119static inline int
120adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value)
121{
122 return i2c_smbus_write_byte_data(client, reg, value);
123}
124
125
126#define TEMP_TO_REG(val) (((val) < 0 ? ((val - 500) / 1000) : \
127 ((val + 500) / 1000)))
128
129#define TEMP_FROM_REG(val) ((val) * 1000)
130
131#define TEMP_FROM_REG_EXT(val, ext) (TEMP_FROM_REG(val) + (ext) * 125)
132
133#define FAN_FROM_REG(reg, div) ((reg) ? (11250 * 60) / ((reg) * (div)) : 0)
134
135static int FAN_TO_REG(int reg, int div)
136{
137 int tmp;
138 tmp = FAN_FROM_REG(SENSORS_LIMIT(reg, 0, 65535), div);
139 return tmp > 255 ? 255 : tmp;
140}
141
142#define FAN_DIV_FROM_REG(reg) (1<<(((reg)&0xc0)>>6))
143
144#define PWM_TO_REG(val) (SENSORS_LIMIT((val), 0, 255) >> 4)
145#define PWM_FROM_REG(val) ((val) << 4)
146
147#define FAN_CHAN_FROM_REG(reg) (((reg) >> 5) & 7)
148#define FAN_CHAN_TO_REG(val, reg) \
149 (((reg) & 0x1F) | (((val) << 5) & 0xe0))
150
151#define AUTO_TEMP_MIN_TO_REG(val, reg) \
152 ((((val)/500) & 0xf8)|((reg) & 0x7))
153#define AUTO_TEMP_RANGE_FROM_REG(reg) (5000 * (1<< ((reg)&0x7)))
154#define AUTO_TEMP_MIN_FROM_REG(reg) (1000 * ((((reg) >> 3) & 0x1f) << 2))
155
156#define AUTO_TEMP_MIN_FROM_REG_DEG(reg) ((((reg) >> 3) & 0x1f) << 2)
157
158#define AUTO_TEMP_OFF_FROM_REG(reg) \
159 (AUTO_TEMP_MIN_FROM_REG(reg) - 5000)
160
161#define AUTO_TEMP_MAX_FROM_REG(reg) \
162 (AUTO_TEMP_RANGE_FROM_REG(reg) + \
163 AUTO_TEMP_MIN_FROM_REG(reg))
164
165static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
166{
167 int ret;
168 int range = val - AUTO_TEMP_MIN_FROM_REG(reg);
169
170 range = ((val - AUTO_TEMP_MIN_FROM_REG(reg))*10)/(16 - pwm);
171 ret = ((reg & 0xf8) |
172 (range < 10000 ? 0 :
173 range < 20000 ? 1 :
174 range < 40000 ? 2 : range < 80000 ? 3 : 4));
175 return ret;
176}
177
178/* FAN auto control */
179#define GET_FAN_AUTO_BITFIELD(data, idx) \
180 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2]
181
182/* The tables below contains the possible values for the auto fan
183 * control bitfields. the index in the table is the register value.
184 * MSb is the auto fan control enable bit, so the four first entries
185 * in the table disables auto fan control when both bitfields are zero.
186 */
187static auto_chan_table_t auto_channel_select_table_adm1031 = {
188 {0, 0}, {0, 0}, {0, 0}, {0, 0},
189 {2 /*0b010 */ , 4 /*0b100 */ },
190 {2 /*0b010 */ , 2 /*0b010 */ },
191 {4 /*0b100 */ , 4 /*0b100 */ },
192 {7 /*0b111 */ , 7 /*0b111 */ },
193};
194
195static auto_chan_table_t auto_channel_select_table_adm1030 = {
196 {0, 0}, {0, 0}, {0, 0}, {0, 0},
197 {2 /*0b10 */ , 0},
198 {0xff /*invalid */ , 0},
199 {0xff /*invalid */ , 0},
200 {3 /*0b11 */ , 0},
201};
202
203/* That function checks if a bitfield is valid and returns the other bitfield
204 * nearest match if no exact match where found.
205 */
206static int
207get_fan_auto_nearest(struct adm1031_data *data,
208 int chan, u8 val, u8 reg, u8 * new_reg)
209{
210 int i;
211 int first_match = -1, exact_match = -1;
212 u8 other_reg_val =
213 (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1];
214
215 if (val == 0) {
216 *new_reg = 0;
217 return 0;
218 }
219
220 for (i = 0; i < 8; i++) {
221 if ((val == (*data->chan_select_table)[i][chan]) &&
222 ((*data->chan_select_table)[i][chan ? 0 : 1] ==
223 other_reg_val)) {
224 /* We found an exact match */
225 exact_match = i;
226 break;
227 } else if (val == (*data->chan_select_table)[i][chan] &&
228 first_match == -1) {
229 /* Save the first match in case of an exact match has not been
230 * found
231 */
232 first_match = i;
233 }
234 }
235
236 if (exact_match >= 0) {
237 *new_reg = exact_match;
238 } else if (first_match >= 0) {
239 *new_reg = first_match;
240 } else {
241 return -EINVAL;
242 }
243 return 0;
244}
245
246static ssize_t show_fan_auto_channel(struct device *dev, char *buf, int nr)
247{
248 struct adm1031_data *data = adm1031_update_device(dev);
249 return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr));
250}
251
252static ssize_t
253set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
254{
255 struct i2c_client *client = to_i2c_client(dev);
256 struct adm1031_data *data = i2c_get_clientdata(client);
257 int val = simple_strtol(buf, NULL, 10);
258 u8 reg;
259 int ret;
260 u8 old_fan_mode;
261
262 old_fan_mode = data->conf1;
263
264 down(&data->update_lock);
265
266 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
267 up(&data->update_lock);
268 return ret;
269 }
270 if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^
271 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
272 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){
273 /* Switch to Auto Fan Mode
274 * Save PWM registers
275 * Set PWM registers to 33% Both */
276 data->old_pwm[0] = data->pwm[0];
277 data->old_pwm[1] = data->pwm[1];
278 adm1031_write_value(client, ADM1031_REG_PWM, 0x55);
279 } else {
280 /* Switch to Manual Mode */
281 data->pwm[0] = data->old_pwm[0];
282 data->pwm[1] = data->old_pwm[1];
283 /* Restore PWM registers */
284 adm1031_write_value(client, ADM1031_REG_PWM,
285 data->pwm[0] | (data->pwm[1] << 4));
286 }
287 }
288 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
289 adm1031_write_value(client, ADM1031_REG_CONF1, data->conf1);
290 up(&data->update_lock);
291 return count;
292}
293
294#define fan_auto_channel_offset(offset) \
295static ssize_t show_fan_auto_channel_##offset (struct device *dev, char *buf) \
296{ \
297 return show_fan_auto_channel(dev, buf, offset - 1); \
298} \
299static ssize_t set_fan_auto_channel_##offset (struct device *dev, \
300 const char *buf, size_t count) \
301{ \
302 return set_fan_auto_channel(dev, buf, count, offset - 1); \
303} \
304static DEVICE_ATTR(auto_fan##offset##_channel, S_IRUGO | S_IWUSR, \
305 show_fan_auto_channel_##offset, \
306 set_fan_auto_channel_##offset)
307
308fan_auto_channel_offset(1);
309fan_auto_channel_offset(2);
310
311/* Auto Temps */
312static ssize_t show_auto_temp_off(struct device *dev, char *buf, int nr)
313{
314 struct adm1031_data *data = adm1031_update_device(dev);
315 return sprintf(buf, "%d\n",
316 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr]));
317}
318static ssize_t show_auto_temp_min(struct device *dev, char *buf, int nr)
319{
320 struct adm1031_data *data = adm1031_update_device(dev);
321 return sprintf(buf, "%d\n",
322 AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr]));
323}
324static ssize_t
325set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
326{
327 struct i2c_client *client = to_i2c_client(dev);
328 struct adm1031_data *data = i2c_get_clientdata(client);
329 int val = simple_strtol(buf, NULL, 10);
330
331 down(&data->update_lock);
332 data->auto_temp[nr] = AUTO_TEMP_MIN_TO_REG(val, data->auto_temp[nr]);
333 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
334 data->auto_temp[nr]);
335 up(&data->update_lock);
336 return count;
337}
338static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr)
339{
340 struct adm1031_data *data = adm1031_update_device(dev);
341 return sprintf(buf, "%d\n",
342 AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr]));
343}
344static ssize_t
345set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
346{
347 struct i2c_client *client = to_i2c_client(dev);
348 struct adm1031_data *data = i2c_get_clientdata(client);
349 int val = simple_strtol(buf, NULL, 10);
350
351 down(&data->update_lock);
352 data->temp_max[nr] = AUTO_TEMP_MAX_TO_REG(val, data->auto_temp[nr], data->pwm[nr]);
353 adm1031_write_value(client, ADM1031_REG_AUTO_TEMP(nr),
354 data->temp_max[nr]);
355 up(&data->update_lock);
356 return count;
357}
358
359#define auto_temp_reg(offset) \
360static ssize_t show_auto_temp_##offset##_off (struct device *dev, char *buf) \
361{ \
362 return show_auto_temp_off(dev, buf, offset - 1); \
363} \
364static ssize_t show_auto_temp_##offset##_min (struct device *dev, char *buf) \
365{ \
366 return show_auto_temp_min(dev, buf, offset - 1); \
367} \
368static ssize_t show_auto_temp_##offset##_max (struct device *dev, char *buf) \
369{ \
370 return show_auto_temp_max(dev, buf, offset - 1); \
371} \
372static ssize_t set_auto_temp_##offset##_min (struct device *dev, \
373 const char *buf, size_t count) \
374{ \
375 return set_auto_temp_min(dev, buf, count, offset - 1); \
376} \
377static ssize_t set_auto_temp_##offset##_max (struct device *dev, \
378 const char *buf, size_t count) \
379{ \
380 return set_auto_temp_max(dev, buf, count, offset - 1); \
381} \
382static DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO, \
383 show_auto_temp_##offset##_off, NULL); \
384static DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR, \
385 show_auto_temp_##offset##_min, set_auto_temp_##offset##_min);\
386static DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR, \
387 show_auto_temp_##offset##_max, set_auto_temp_##offset##_max)
388
389auto_temp_reg(1);
390auto_temp_reg(2);
391auto_temp_reg(3);
392
393/* pwm */
394static ssize_t show_pwm(struct device *dev, char *buf, int nr)
395{
396 struct adm1031_data *data = adm1031_update_device(dev);
397 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
398}
399static ssize_t
400set_pwm(struct device *dev, const char *buf, size_t count, int nr)
401{
402 struct i2c_client *client = to_i2c_client(dev);
403 struct adm1031_data *data = i2c_get_clientdata(client);
404 int val = simple_strtol(buf, NULL, 10);
405 int reg;
406
407 down(&data->update_lock);
408 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
409 (((val>>4) & 0xf) != 5)) {
410 /* In automatic mode, the only PWM accepted is 33% */
411 up(&data->update_lock);
412 return -EINVAL;
413 }
414 data->pwm[nr] = PWM_TO_REG(val);
415 reg = adm1031_read_value(client, ADM1031_REG_PWM);
416 adm1031_write_value(client, ADM1031_REG_PWM,
417 nr ? ((data->pwm[nr] << 4) & 0xf0) | (reg & 0xf)
418 : (data->pwm[nr] & 0xf) | (reg & 0xf0));
419 up(&data->update_lock);
420 return count;
421}
422
423#define pwm_reg(offset) \
424static ssize_t show_pwm_##offset (struct device *dev, char *buf) \
425{ \
426 return show_pwm(dev, buf, offset - 1); \
427} \
428static ssize_t set_pwm_##offset (struct device *dev, \
429 const char *buf, size_t count) \
430{ \
431 return set_pwm(dev, buf, count, offset - 1); \
432} \
433static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
434 show_pwm_##offset, set_pwm_##offset)
435
436pwm_reg(1);
437pwm_reg(2);
438
439/* Fans */
440
441/*
442 * That function checks the cases where the fan reading is not
443 * relevent. It is used to provide 0 as fan reading when the fan is
444 * not supposed to run
445 */
446static int trust_fan_readings(struct adm1031_data *data, int chan)
447{
448 int res = 0;
449
450 if (data->conf1 & ADM1031_CONF1_AUTO_MODE) {
451 switch (data->conf1 & 0x60) {
452 case 0x00: /* remote temp1 controls fan1 remote temp2 controls fan2 */
453 res = data->temp[chan+1] >=
454 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[chan+1]);
455 break;
456 case 0x20: /* remote temp1 controls both fans */
457 res =
458 data->temp[1] >=
459 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]);
460 break;
461 case 0x40: /* remote temp2 controls both fans */
462 res =
463 data->temp[2] >=
464 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]);
465 break;
466 case 0x60: /* max controls both fans */
467 res =
468 data->temp[0] >=
469 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0])
470 || data->temp[1] >=
471 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1])
472 || (data->chip_type == adm1031
473 && data->temp[2] >=
474 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]));
475 break;
476 }
477 } else {
478 res = data->pwm[chan] > 0;
479 }
480 return res;
481}
482
483
484static ssize_t show_fan(struct device *dev, char *buf, int nr)
485{
486 struct adm1031_data *data = adm1031_update_device(dev);
487 int value;
488
489 value = trust_fan_readings(data, nr) ? FAN_FROM_REG(data->fan[nr],
490 FAN_DIV_FROM_REG(data->fan_div[nr])) : 0;
491 return sprintf(buf, "%d\n", value);
492}
493
494static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
495{
496 struct adm1031_data *data = adm1031_update_device(dev);
497 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr]));
498}
499static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
500{
501 struct adm1031_data *data = adm1031_update_device(dev);
502 return sprintf(buf, "%d\n",
503 FAN_FROM_REG(data->fan_min[nr],
504 FAN_DIV_FROM_REG(data->fan_div[nr])));
505}
506static ssize_t
507set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
508{
509 struct i2c_client *client = to_i2c_client(dev);
510 struct adm1031_data *data = i2c_get_clientdata(client);
511 int val = simple_strtol(buf, NULL, 10);
512
513 down(&data->update_lock);
514 if (val) {
515 data->fan_min[nr] =
516 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
517 } else {
518 data->fan_min[nr] = 0xff;
519 }
520 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), data->fan_min[nr]);
521 up(&data->update_lock);
522 return count;
523}
524static ssize_t
525set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
526{
527 struct i2c_client *client = to_i2c_client(dev);
528 struct adm1031_data *data = i2c_get_clientdata(client);
529 int val = simple_strtol(buf, NULL, 10);
530 u8 tmp;
531 int old_div;
532 int new_min;
533
534 tmp = val == 8 ? 0xc0 :
535 val == 4 ? 0x80 :
536 val == 2 ? 0x40 :
537 val == 1 ? 0x00 :
538 0xff;
539 if (tmp == 0xff)
540 return -EINVAL;
541
542 down(&data->update_lock);
543 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
544 data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
545 new_min = data->fan_min[nr] * old_div /
546 FAN_DIV_FROM_REG(data->fan_div[nr]);
547 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min;
548 data->fan[nr] = data->fan[nr] * old_div /
549 FAN_DIV_FROM_REG(data->fan_div[nr]);
550
551 adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr),
552 data->fan_div[nr]);
553 adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
554 data->fan_min[nr]);
555 up(&data->update_lock);
556 return count;
557}
558
559#define fan_offset(offset) \
560static ssize_t show_fan_##offset (struct device *dev, char *buf) \
561{ \
562 return show_fan(dev, buf, offset - 1); \
563} \
564static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
565{ \
566 return show_fan_min(dev, buf, offset - 1); \
567} \
568static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
569{ \
570 return show_fan_div(dev, buf, offset - 1); \
571} \
572static ssize_t set_fan_##offset##_min (struct device *dev, \
573 const char *buf, size_t count) \
574{ \
575 return set_fan_min(dev, buf, count, offset - 1); \
576} \
577static ssize_t set_fan_##offset##_div (struct device *dev, \
578 const char *buf, size_t count) \
579{ \
580 return set_fan_div(dev, buf, count, offset - 1); \
581} \
582static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
583 NULL); \
584static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
585 show_fan_##offset##_min, set_fan_##offset##_min); \
586static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
587 show_fan_##offset##_div, set_fan_##offset##_div); \
588static DEVICE_ATTR(auto_fan##offset##_min_pwm, S_IRUGO | S_IWUSR, \
589 show_pwm_##offset, set_pwm_##offset)
590
591fan_offset(1);
592fan_offset(2);
593
594
595/* Temps */
596static ssize_t show_temp(struct device *dev, char *buf, int nr)
597{
598 struct adm1031_data *data = adm1031_update_device(dev);
599 int ext;
600 ext = nr == 0 ?
601 ((data->ext_temp[nr] >> 6) & 0x3) * 2 :
602 (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7));
603 return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext));
604}
605static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
606{
607 struct adm1031_data *data = adm1031_update_device(dev);
608 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
609}
610static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
611{
612 struct adm1031_data *data = adm1031_update_device(dev);
613 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
614}
615static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
616{
617 struct adm1031_data *data = adm1031_update_device(dev);
618 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
619}
620static ssize_t
621set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
622{
623 struct i2c_client *client = to_i2c_client(dev);
624 struct adm1031_data *data = i2c_get_clientdata(client);
625 int val;
626
627 val = simple_strtol(buf, NULL, 10);
628 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
629 down(&data->update_lock);
630 data->temp_min[nr] = TEMP_TO_REG(val);
631 adm1031_write_value(client, ADM1031_REG_TEMP_MIN(nr),
632 data->temp_min[nr]);
633 up(&data->update_lock);
634 return count;
635}
636static ssize_t
637set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
638{
639 struct i2c_client *client = to_i2c_client(dev);
640 struct adm1031_data *data = i2c_get_clientdata(client);
641 int val;
642
643 val = simple_strtol(buf, NULL, 10);
644 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
645 down(&data->update_lock);
646 data->temp_max[nr] = TEMP_TO_REG(val);
647 adm1031_write_value(client, ADM1031_REG_TEMP_MAX(nr),
648 data->temp_max[nr]);
649 up(&data->update_lock);
650 return count;
651}
652static ssize_t
653set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
654{
655 struct i2c_client *client = to_i2c_client(dev);
656 struct adm1031_data *data = i2c_get_clientdata(client);
657 int val;
658
659 val = simple_strtol(buf, NULL, 10);
660 val = SENSORS_LIMIT(val, -55000, nr == 0 ? 127750 : 127875);
661 down(&data->update_lock);
662 data->temp_crit[nr] = TEMP_TO_REG(val);
663 adm1031_write_value(client, ADM1031_REG_TEMP_CRIT(nr),
664 data->temp_crit[nr]);
665 up(&data->update_lock);
666 return count;
667}
668
669#define temp_reg(offset) \
670static ssize_t show_temp_##offset (struct device *dev, char *buf) \
671{ \
672 return show_temp(dev, buf, offset - 1); \
673} \
674static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
675{ \
676 return show_temp_min(dev, buf, offset - 1); \
677} \
678static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
679{ \
680 return show_temp_max(dev, buf, offset - 1); \
681} \
682static ssize_t show_temp_##offset##_crit (struct device *dev, char *buf) \
683{ \
684 return show_temp_crit(dev, buf, offset - 1); \
685} \
686static ssize_t set_temp_##offset##_min (struct device *dev, \
687 const char *buf, size_t count) \
688{ \
689 return set_temp_min(dev, buf, count, offset - 1); \
690} \
691static ssize_t set_temp_##offset##_max (struct device *dev, \
692 const char *buf, size_t count) \
693{ \
694 return set_temp_max(dev, buf, count, offset - 1); \
695} \
696static ssize_t set_temp_##offset##_crit (struct device *dev, \
697 const char *buf, size_t count) \
698{ \
699 return set_temp_crit(dev, buf, count, offset - 1); \
700} \
701static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
702 NULL); \
703static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
704 show_temp_##offset##_min, set_temp_##offset##_min); \
705static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
706 show_temp_##offset##_max, set_temp_##offset##_max); \
707static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR, \
708 show_temp_##offset##_crit, set_temp_##offset##_crit)
709
710temp_reg(1);
711temp_reg(2);
712temp_reg(3);
713
714/* Alarms */
715static ssize_t show_alarms(struct device *dev, char *buf)
716{
717 struct adm1031_data *data = adm1031_update_device(dev);
718 return sprintf(buf, "%d\n", data->alarm);
719}
720
721static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
722
723
724static int adm1031_attach_adapter(struct i2c_adapter *adapter)
725{
726 if (!(adapter->class & I2C_CLASS_HWMON))
727 return 0;
728 return i2c_detect(adapter, &addr_data, adm1031_detect);
729}
730
731/* This function is called by i2c_detect */
732static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
733{
734 struct i2c_client *new_client;
735 struct adm1031_data *data;
736 int err = 0;
737 const char *name = "";
738
739 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
740 goto exit;
741
742 if (!(data = kmalloc(sizeof(struct adm1031_data), GFP_KERNEL))) {
743 err = -ENOMEM;
744 goto exit;
745 }
746 memset(data, 0, sizeof(struct adm1031_data));
747
748 new_client = &data->client;
749 i2c_set_clientdata(new_client, data);
750 new_client->addr = address;
751 new_client->adapter = adapter;
752 new_client->driver = &adm1031_driver;
753 new_client->flags = 0;
754
755 if (kind < 0) {
756 int id, co;
757 id = i2c_smbus_read_byte_data(new_client, 0x3d);
758 co = i2c_smbus_read_byte_data(new_client, 0x3e);
759
760 if (!((id == 0x31 || id == 0x30) && co == 0x41))
761 goto exit_free;
762 kind = (id == 0x30) ? adm1030 : adm1031;
763 }
764
765 if (kind <= 0)
766 kind = adm1031;
767
768 /* Given the detected chip type, set the chip name and the
769 * auto fan control helper table. */
770 if (kind == adm1030) {
771 name = "adm1030";
772 data->chan_select_table = &auto_channel_select_table_adm1030;
773 } else if (kind == adm1031) {
774 name = "adm1031";
775 data->chan_select_table = &auto_channel_select_table_adm1031;
776 }
777 data->chip_type = kind;
778
779 strlcpy(new_client->name, name, I2C_NAME_SIZE);
780 data->valid = 0;
781 init_MUTEX(&data->update_lock);
782
783 /* Tell the I2C layer a new client has arrived */
784 if ((err = i2c_attach_client(new_client)))
785 goto exit_free;
786
787 /* Initialize the ADM1031 chip */
788 adm1031_init_client(new_client);
789
790 /* Register sysfs hooks */
791 device_create_file(&new_client->dev, &dev_attr_fan1_input);
792 device_create_file(&new_client->dev, &dev_attr_fan1_div);
793 device_create_file(&new_client->dev, &dev_attr_fan1_min);
794 device_create_file(&new_client->dev, &dev_attr_pwm1);
795 device_create_file(&new_client->dev, &dev_attr_auto_fan1_channel);
796 device_create_file(&new_client->dev, &dev_attr_temp1_input);
797 device_create_file(&new_client->dev, &dev_attr_temp1_min);
798 device_create_file(&new_client->dev, &dev_attr_temp1_max);
799 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
800 device_create_file(&new_client->dev, &dev_attr_temp2_input);
801 device_create_file(&new_client->dev, &dev_attr_temp2_min);
802 device_create_file(&new_client->dev, &dev_attr_temp2_max);
803 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
804
805 device_create_file(&new_client->dev, &dev_attr_auto_temp1_off);
806 device_create_file(&new_client->dev, &dev_attr_auto_temp1_min);
807 device_create_file(&new_client->dev, &dev_attr_auto_temp1_max);
808
809 device_create_file(&new_client->dev, &dev_attr_auto_temp2_off);
810 device_create_file(&new_client->dev, &dev_attr_auto_temp2_min);
811 device_create_file(&new_client->dev, &dev_attr_auto_temp2_max);
812
813 device_create_file(&new_client->dev, &dev_attr_auto_fan1_min_pwm);
814
815 device_create_file(&new_client->dev, &dev_attr_alarms);
816
817 if (kind == adm1031) {
818 device_create_file(&new_client->dev, &dev_attr_fan2_input);
819 device_create_file(&new_client->dev, &dev_attr_fan2_div);
820 device_create_file(&new_client->dev, &dev_attr_fan2_min);
821 device_create_file(&new_client->dev, &dev_attr_pwm2);
822 device_create_file(&new_client->dev,
823 &dev_attr_auto_fan2_channel);
824 device_create_file(&new_client->dev, &dev_attr_temp3_input);
825 device_create_file(&new_client->dev, &dev_attr_temp3_min);
826 device_create_file(&new_client->dev, &dev_attr_temp3_max);
827 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
828 device_create_file(&new_client->dev, &dev_attr_auto_temp3_off);
829 device_create_file(&new_client->dev, &dev_attr_auto_temp3_min);
830 device_create_file(&new_client->dev, &dev_attr_auto_temp3_max);
831 device_create_file(&new_client->dev, &dev_attr_auto_fan2_min_pwm);
832 }
833
834 return 0;
835
836exit_free:
837 kfree(new_client);
838exit:
839 return err;
840}
841
842static int adm1031_detach_client(struct i2c_client *client)
843{
844 int ret;
845 if ((ret = i2c_detach_client(client)) != 0) {
846 return ret;
847 }
848 kfree(client);
849 return 0;
850}
851
852static void adm1031_init_client(struct i2c_client *client)
853{
854 unsigned int read_val;
855 unsigned int mask;
856 struct adm1031_data *data = i2c_get_clientdata(client);
857
858 mask = (ADM1031_CONF2_PWM1_ENABLE | ADM1031_CONF2_TACH1_ENABLE);
859 if (data->chip_type == adm1031) {
860 mask |= (ADM1031_CONF2_PWM2_ENABLE |
861 ADM1031_CONF2_TACH2_ENABLE);
862 }
863 /* Initialize the ADM1031 chip (enables fan speed reading ) */
864 read_val = adm1031_read_value(client, ADM1031_REG_CONF2);
865 if ((read_val | mask) != read_val) {
866 adm1031_write_value(client, ADM1031_REG_CONF2, read_val | mask);
867 }
868
869 read_val = adm1031_read_value(client, ADM1031_REG_CONF1);
870 if ((read_val | ADM1031_CONF1_MONITOR_ENABLE) != read_val) {
871 adm1031_write_value(client, ADM1031_REG_CONF1, read_val |
872 ADM1031_CONF1_MONITOR_ENABLE);
873 }
874
875}
876
877static struct adm1031_data *adm1031_update_device(struct device *dev)
878{
879 struct i2c_client *client = to_i2c_client(dev);
880 struct adm1031_data *data = i2c_get_clientdata(client);
881 int chan;
882
883 down(&data->update_lock);
884
885 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
886 || !data->valid) {
887
888 dev_dbg(&client->dev, "Starting adm1031 update\n");
889 for (chan = 0;
890 chan < ((data->chip_type == adm1031) ? 3 : 2); chan++) {
891 u8 oldh, newh;
892
893 oldh =
894 adm1031_read_value(client, ADM1031_REG_TEMP(chan));
895 data->ext_temp[chan] =
896 adm1031_read_value(client, ADM1031_REG_EXT_TEMP);
897 newh =
898 adm1031_read_value(client, ADM1031_REG_TEMP(chan));
899 if (newh != oldh) {
900 data->ext_temp[chan] =
901 adm1031_read_value(client,
902 ADM1031_REG_EXT_TEMP);
903#ifdef DEBUG
904 oldh =
905 adm1031_read_value(client,
906 ADM1031_REG_TEMP(chan));
907
908 /* oldh is actually newer */
909 if (newh != oldh)
910 dev_warn(&client->dev,
911 "Remote temperature may be "
912 "wrong.\n");
913#endif
914 }
915 data->temp[chan] = newh;
916
917 data->temp_min[chan] =
918 adm1031_read_value(client,
919 ADM1031_REG_TEMP_MIN(chan));
920 data->temp_max[chan] =
921 adm1031_read_value(client,
922 ADM1031_REG_TEMP_MAX(chan));
923 data->temp_crit[chan] =
924 adm1031_read_value(client,
925 ADM1031_REG_TEMP_CRIT(chan));
926 data->auto_temp[chan] =
927 adm1031_read_value(client,
928 ADM1031_REG_AUTO_TEMP(chan));
929
930 }
931
932 data->conf1 = adm1031_read_value(client, ADM1031_REG_CONF1);
933 data->conf2 = adm1031_read_value(client, ADM1031_REG_CONF2);
934
935 data->alarm = adm1031_read_value(client, ADM1031_REG_STATUS(0))
936 | (adm1031_read_value(client, ADM1031_REG_STATUS(1))
937 << 8);
938 if (data->chip_type == adm1030) {
939 data->alarm &= 0xc0ff;
940 }
941
942 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) {
943 data->fan_div[chan] =
944 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan));
945 data->fan_min[chan] =
946 adm1031_read_value(client, ADM1031_REG_FAN_MIN(chan));
947 data->fan[chan] =
948 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan));
949 data->pwm[chan] =
950 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >>
951 (4*chan));
952 }
953 data->last_updated = jiffies;
954 data->valid = 1;
955 }
956
957 up(&data->update_lock);
958
959 return data;
960}
961
962static int __init sensors_adm1031_init(void)
963{
964 return i2c_add_driver(&adm1031_driver);
965}
966
967static void __exit sensors_adm1031_exit(void)
968{
969 i2c_del_driver(&adm1031_driver);
970}
971
972MODULE_AUTHOR("Alexandre d'Alton <alex@alexdalton.org>");
973MODULE_DESCRIPTION("ADM1031/ADM1030 driver");
974MODULE_LICENSE("GPL");
975
976module_init(sensors_adm1031_init);
977module_exit(sensors_adm1031_exit);
diff --git a/drivers/i2c/chips/asb100.c b/drivers/i2c/chips/asb100.c
deleted file mode 100644
index 7f899002bc54..000000000000
--- a/drivers/i2c/chips/asb100.c
+++ /dev/null
@@ -1,1066 +0,0 @@
1/*
2 asb100.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (C) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
6
7 (derived from w83781d.c)
8
9 Copyright (C) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
10 Philip Edelbrock <phil@netroedge.com>, and
11 Mark Studebaker <mdsxyz123@yahoo.com>
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/
27
28/*
29 This driver supports the hardware sensor chips: Asus ASB100 and
30 ASB100-A "BACH".
31
32 ASB100-A supports pwm1, while plain ASB100 does not. There is no known
33 way for the driver to tell which one is there.
34
35 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
36 asb100 7 3 1 4 0x31 0x0694 yes no
37*/
38
39#include <linux/module.h>
40#include <linux/slab.h>
41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h>
43#include <linux/i2c-vid.h>
44#include <linux/init.h>
45#include "lm75.h"
46
47/*
48 HISTORY:
49 2003-12-29 1.0.0 Ported from lm_sensors project for kernel 2.6
50*/
51#define ASB100_VERSION "1.0.0"
52
53/* I2C addresses to scan */
54static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
55
56/* ISA addresses to scan (none) */
57static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
58
59/* Insmod parameters */
60SENSORS_INSMOD_1(asb100);
61I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
62 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
63
64/* Voltage IN registers 0-6 */
65#define ASB100_REG_IN(nr) (0x20 + (nr))
66#define ASB100_REG_IN_MAX(nr) (0x2b + (nr * 2))
67#define ASB100_REG_IN_MIN(nr) (0x2c + (nr * 2))
68
69/* FAN IN registers 1-3 */
70#define ASB100_REG_FAN(nr) (0x28 + (nr))
71#define ASB100_REG_FAN_MIN(nr) (0x3b + (nr))
72
73/* TEMPERATURE registers 1-4 */
74static const u16 asb100_reg_temp[] = {0, 0x27, 0x150, 0x250, 0x17};
75static const u16 asb100_reg_temp_max[] = {0, 0x39, 0x155, 0x255, 0x18};
76static const u16 asb100_reg_temp_hyst[] = {0, 0x3a, 0x153, 0x253, 0x19};
77
78#define ASB100_REG_TEMP(nr) (asb100_reg_temp[nr])
79#define ASB100_REG_TEMP_MAX(nr) (asb100_reg_temp_max[nr])
80#define ASB100_REG_TEMP_HYST(nr) (asb100_reg_temp_hyst[nr])
81
82#define ASB100_REG_TEMP2_CONFIG 0x0152
83#define ASB100_REG_TEMP3_CONFIG 0x0252
84
85
86#define ASB100_REG_CONFIG 0x40
87#define ASB100_REG_ALARM1 0x41
88#define ASB100_REG_ALARM2 0x42
89#define ASB100_REG_SMIM1 0x43
90#define ASB100_REG_SMIM2 0x44
91#define ASB100_REG_VID_FANDIV 0x47
92#define ASB100_REG_I2C_ADDR 0x48
93#define ASB100_REG_CHIPID 0x49
94#define ASB100_REG_I2C_SUBADDR 0x4a
95#define ASB100_REG_PIN 0x4b
96#define ASB100_REG_IRQ 0x4c
97#define ASB100_REG_BANK 0x4e
98#define ASB100_REG_CHIPMAN 0x4f
99
100#define ASB100_REG_WCHIPID 0x58
101
102/* bit 7 -> enable, bits 0-3 -> duty cycle */
103#define ASB100_REG_PWM1 0x59
104
105/* CONVERSIONS
106 Rounding and limit checking is only done on the TO_REG variants. */
107
108/* These constants are a guess, consistent w/ w83781d */
109#define ASB100_IN_MIN ( 0)
110#define ASB100_IN_MAX (4080)
111
112/* IN: 1/1000 V (0V to 4.08V)
113 REG: 16mV/bit */
114static u8 IN_TO_REG(unsigned val)
115{
116 unsigned nval = SENSORS_LIMIT(val, ASB100_IN_MIN, ASB100_IN_MAX);
117 return (nval + 8) / 16;
118}
119
120static unsigned IN_FROM_REG(u8 reg)
121{
122 return reg * 16;
123}
124
125static u8 FAN_TO_REG(long rpm, int div)
126{
127 if (rpm == -1)
128 return 0;
129 if (rpm == 0)
130 return 255;
131 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
132 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
133}
134
135static int FAN_FROM_REG(u8 val, int div)
136{
137 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
138}
139
140/* These constants are a guess, consistent w/ w83781d */
141#define ASB100_TEMP_MIN (-128000)
142#define ASB100_TEMP_MAX ( 127000)
143
144/* TEMP: 0.001C/bit (-128C to +127C)
145 REG: 1C/bit, two's complement */
146static u8 TEMP_TO_REG(int temp)
147{
148 int ntemp = SENSORS_LIMIT(temp, ASB100_TEMP_MIN, ASB100_TEMP_MAX);
149 ntemp += (ntemp<0 ? -500 : 500);
150 return (u8)(ntemp / 1000);
151}
152
153static int TEMP_FROM_REG(u8 reg)
154{
155 return (s8)reg * 1000;
156}
157
158/* PWM: 0 - 255 per sensors documentation
159 REG: (6.25% duty cycle per bit) */
160static u8 ASB100_PWM_TO_REG(int pwm)
161{
162 pwm = SENSORS_LIMIT(pwm, 0, 255);
163 return (u8)(pwm / 16);
164}
165
166static int ASB100_PWM_FROM_REG(u8 reg)
167{
168 return reg * 16;
169}
170
171#define ALARMS_FROM_REG(val) (val)
172
173#define DIV_FROM_REG(val) (1 << (val))
174
175/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
176 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
177static u8 DIV_TO_REG(long val)
178{
179 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
180}
181
182/* For each registered client, we need to keep some data in memory. That
183 data is pointed to by client->data. The structure itself is
184 dynamically allocated, at the same time the client itself is allocated. */
185struct asb100_data {
186 struct i2c_client client;
187 struct semaphore lock;
188 enum chips type;
189
190 struct semaphore update_lock;
191 unsigned long last_updated; /* In jiffies */
192
193 /* array of 2 pointers to subclients */
194 struct i2c_client *lm75[2];
195
196 char valid; /* !=0 if following fields are valid */
197 u8 in[7]; /* Register value */
198 u8 in_max[7]; /* Register value */
199 u8 in_min[7]; /* Register value */
200 u8 fan[3]; /* Register value */
201 u8 fan_min[3]; /* Register value */
202 u16 temp[4]; /* Register value (0 and 3 are u8 only) */
203 u16 temp_max[4]; /* Register value (0 and 3 are u8 only) */
204 u16 temp_hyst[4]; /* Register value (0 and 3 are u8 only) */
205 u8 fan_div[3]; /* Register encoding, right justified */
206 u8 pwm; /* Register encoding */
207 u8 vid; /* Register encoding, combined */
208 u32 alarms; /* Register encoding, combined */
209 u8 vrm;
210};
211
212static int asb100_read_value(struct i2c_client *client, u16 reg);
213static void asb100_write_value(struct i2c_client *client, u16 reg, u16 val);
214
215static int asb100_attach_adapter(struct i2c_adapter *adapter);
216static int asb100_detect(struct i2c_adapter *adapter, int address, int kind);
217static int asb100_detach_client(struct i2c_client *client);
218static struct asb100_data *asb100_update_device(struct device *dev);
219static void asb100_init_client(struct i2c_client *client);
220
221static struct i2c_driver asb100_driver = {
222 .owner = THIS_MODULE,
223 .name = "asb100",
224 .id = I2C_DRIVERID_ASB100,
225 .flags = I2C_DF_NOTIFY,
226 .attach_adapter = asb100_attach_adapter,
227 .detach_client = asb100_detach_client,
228};
229
230/* 7 Voltages */
231#define show_in_reg(reg) \
232static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
233{ \
234 struct asb100_data *data = asb100_update_device(dev); \
235 return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
236}
237
238show_in_reg(in)
239show_in_reg(in_min)
240show_in_reg(in_max)
241
242#define set_in_reg(REG, reg) \
243static ssize_t set_in_##reg(struct device *dev, const char *buf, \
244 size_t count, int nr) \
245{ \
246 struct i2c_client *client = to_i2c_client(dev); \
247 struct asb100_data *data = i2c_get_clientdata(client); \
248 unsigned long val = simple_strtoul(buf, NULL, 10); \
249 \
250 down(&data->update_lock); \
251 data->in_##reg[nr] = IN_TO_REG(val); \
252 asb100_write_value(client, ASB100_REG_IN_##REG(nr), \
253 data->in_##reg[nr]); \
254 up(&data->update_lock); \
255 return count; \
256}
257
258set_in_reg(MIN, min)
259set_in_reg(MAX, max)
260
261#define sysfs_in(offset) \
262static ssize_t \
263 show_in##offset (struct device *dev, char *buf) \
264{ \
265 return show_in(dev, buf, offset); \
266} \
267static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
268 show_in##offset, NULL); \
269static ssize_t \
270 show_in##offset##_min (struct device *dev, char *buf) \
271{ \
272 return show_in_min(dev, buf, offset); \
273} \
274static ssize_t \
275 show_in##offset##_max (struct device *dev, char *buf) \
276{ \
277 return show_in_max(dev, buf, offset); \
278} \
279static ssize_t set_in##offset##_min (struct device *dev, \
280 const char *buf, size_t count) \
281{ \
282 return set_in_min(dev, buf, count, offset); \
283} \
284static ssize_t set_in##offset##_max (struct device *dev, \
285 const char *buf, size_t count) \
286{ \
287 return set_in_max(dev, buf, count, offset); \
288} \
289static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
290 show_in##offset##_min, set_in##offset##_min); \
291static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
292 show_in##offset##_max, set_in##offset##_max);
293
294sysfs_in(0);
295sysfs_in(1);
296sysfs_in(2);
297sysfs_in(3);
298sysfs_in(4);
299sysfs_in(5);
300sysfs_in(6);
301
302#define device_create_file_in(client, offset) do { \
303 device_create_file(&client->dev, &dev_attr_in##offset##_input); \
304 device_create_file(&client->dev, &dev_attr_in##offset##_min); \
305 device_create_file(&client->dev, &dev_attr_in##offset##_max); \
306} while (0)
307
308/* 3 Fans */
309static ssize_t show_fan(struct device *dev, char *buf, int nr)
310{
311 struct asb100_data *data = asb100_update_device(dev);
312 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
313 DIV_FROM_REG(data->fan_div[nr])));
314}
315
316static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
317{
318 struct asb100_data *data = asb100_update_device(dev);
319 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
320 DIV_FROM_REG(data->fan_div[nr])));
321}
322
323static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
324{
325 struct asb100_data *data = asb100_update_device(dev);
326 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
327}
328
329static ssize_t set_fan_min(struct device *dev, const char *buf,
330 size_t count, int nr)
331{
332 struct i2c_client *client = to_i2c_client(dev);
333 struct asb100_data *data = i2c_get_clientdata(client);
334 u32 val = simple_strtoul(buf, NULL, 10);
335
336 down(&data->update_lock);
337 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
338 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
339 up(&data->update_lock);
340 return count;
341}
342
343/* Note: we save and restore the fan minimum here, because its value is
344 determined in part by the fan divisor. This follows the principle of
345 least suprise; the user doesn't expect the fan minimum to change just
346 because the divisor changed. */
347static ssize_t set_fan_div(struct device *dev, const char *buf,
348 size_t count, int nr)
349{
350 struct i2c_client *client = to_i2c_client(dev);
351 struct asb100_data *data = i2c_get_clientdata(client);
352 unsigned long min;
353 unsigned long val = simple_strtoul(buf, NULL, 10);
354 int reg;
355
356 down(&data->update_lock);
357
358 min = FAN_FROM_REG(data->fan_min[nr],
359 DIV_FROM_REG(data->fan_div[nr]));
360 data->fan_div[nr] = DIV_TO_REG(val);
361
362 switch(nr) {
363 case 0: /* fan 1 */
364 reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
365 reg = (reg & 0xcf) | (data->fan_div[0] << 4);
366 asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
367 break;
368
369 case 1: /* fan 2 */
370 reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
371 reg = (reg & 0x3f) | (data->fan_div[1] << 6);
372 asb100_write_value(client, ASB100_REG_VID_FANDIV, reg);
373 break;
374
375 case 2: /* fan 3 */
376 reg = asb100_read_value(client, ASB100_REG_PIN);
377 reg = (reg & 0x3f) | (data->fan_div[2] << 6);
378 asb100_write_value(client, ASB100_REG_PIN, reg);
379 break;
380 }
381
382 data->fan_min[nr] =
383 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
384 asb100_write_value(client, ASB100_REG_FAN_MIN(nr), data->fan_min[nr]);
385
386 up(&data->update_lock);
387
388 return count;
389}
390
391#define sysfs_fan(offset) \
392static ssize_t show_fan##offset(struct device *dev, char *buf) \
393{ \
394 return show_fan(dev, buf, offset - 1); \
395} \
396static ssize_t show_fan##offset##_min(struct device *dev, char *buf) \
397{ \
398 return show_fan_min(dev, buf, offset - 1); \
399} \
400static ssize_t show_fan##offset##_div(struct device *dev, char *buf) \
401{ \
402 return show_fan_div(dev, buf, offset - 1); \
403} \
404static ssize_t set_fan##offset##_min(struct device *dev, const char *buf, \
405 size_t count) \
406{ \
407 return set_fan_min(dev, buf, count, offset - 1); \
408} \
409static ssize_t set_fan##offset##_div(struct device *dev, const char *buf, \
410 size_t count) \
411{ \
412 return set_fan_div(dev, buf, count, offset - 1); \
413} \
414static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
415 show_fan##offset, NULL); \
416static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
417 show_fan##offset##_min, set_fan##offset##_min); \
418static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
419 show_fan##offset##_div, set_fan##offset##_div);
420
421sysfs_fan(1);
422sysfs_fan(2);
423sysfs_fan(3);
424
425#define device_create_file_fan(client, offset) do { \
426 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
427 device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
428 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
429} while (0)
430
431/* 4 Temp. Sensors */
432static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
433{
434 int ret = 0;
435
436 switch (nr) {
437 case 1: case 2:
438 ret = sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(reg));
439 break;
440 case 0: case 3: default:
441 ret = sprintf(buf, "%d\n", TEMP_FROM_REG(reg));
442 break;
443 }
444 return ret;
445}
446
447#define show_temp_reg(reg) \
448static ssize_t show_##reg(struct device *dev, char *buf, int nr) \
449{ \
450 struct asb100_data *data = asb100_update_device(dev); \
451 return sprintf_temp_from_reg(data->reg[nr], buf, nr); \
452}
453
454show_temp_reg(temp);
455show_temp_reg(temp_max);
456show_temp_reg(temp_hyst);
457
458#define set_temp_reg(REG, reg) \
459static ssize_t set_##reg(struct device *dev, const char *buf, \
460 size_t count, int nr) \
461{ \
462 struct i2c_client *client = to_i2c_client(dev); \
463 struct asb100_data *data = i2c_get_clientdata(client); \
464 unsigned long val = simple_strtoul(buf, NULL, 10); \
465 \
466 down(&data->update_lock); \
467 switch (nr) { \
468 case 1: case 2: \
469 data->reg[nr] = LM75_TEMP_TO_REG(val); \
470 break; \
471 case 0: case 3: default: \
472 data->reg[nr] = TEMP_TO_REG(val); \
473 break; \
474 } \
475 asb100_write_value(client, ASB100_REG_TEMP_##REG(nr+1), \
476 data->reg[nr]); \
477 up(&data->update_lock); \
478 return count; \
479}
480
481set_temp_reg(MAX, temp_max);
482set_temp_reg(HYST, temp_hyst);
483
484#define sysfs_temp(num) \
485static ssize_t show_temp##num(struct device *dev, char *buf) \
486{ \
487 return show_temp(dev, buf, num-1); \
488} \
489static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL); \
490static ssize_t show_temp_max##num(struct device *dev, char *buf) \
491{ \
492 return show_temp_max(dev, buf, num-1); \
493} \
494static ssize_t set_temp_max##num(struct device *dev, const char *buf, \
495 size_t count) \
496{ \
497 return set_temp_max(dev, buf, count, num-1); \
498} \
499static DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
500 show_temp_max##num, set_temp_max##num); \
501static ssize_t show_temp_hyst##num(struct device *dev, char *buf) \
502{ \
503 return show_temp_hyst(dev, buf, num-1); \
504} \
505static ssize_t set_temp_hyst##num(struct device *dev, const char *buf, \
506 size_t count) \
507{ \
508 return set_temp_hyst(dev, buf, count, num-1); \
509} \
510static DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
511 show_temp_hyst##num, set_temp_hyst##num);
512
513sysfs_temp(1);
514sysfs_temp(2);
515sysfs_temp(3);
516sysfs_temp(4);
517
518/* VID */
519#define device_create_file_temp(client, num) do { \
520 device_create_file(&client->dev, &dev_attr_temp##num##_input); \
521 device_create_file(&client->dev, &dev_attr_temp##num##_max); \
522 device_create_file(&client->dev, &dev_attr_temp##num##_max_hyst); \
523} while (0)
524
525static ssize_t show_vid(struct device *dev, char *buf)
526{
527 struct asb100_data *data = asb100_update_device(dev);
528 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
529}
530
531static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
532#define device_create_file_vid(client) \
533device_create_file(&client->dev, &dev_attr_cpu0_vid)
534
535/* VRM */
536static ssize_t show_vrm(struct device *dev, char *buf)
537{
538 struct asb100_data *data = asb100_update_device(dev);
539 return sprintf(buf, "%d\n", data->vrm);
540}
541
542static ssize_t set_vrm(struct device *dev, const char *buf, size_t count)
543{
544 struct i2c_client *client = to_i2c_client(dev);
545 struct asb100_data *data = i2c_get_clientdata(client);
546 unsigned long val = simple_strtoul(buf, NULL, 10);
547 data->vrm = val;
548 return count;
549}
550
551/* Alarms */
552static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
553#define device_create_file_vrm(client) \
554device_create_file(&client->dev, &dev_attr_vrm);
555
556static ssize_t show_alarms(struct device *dev, char *buf)
557{
558 struct asb100_data *data = asb100_update_device(dev);
559 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
560}
561
562static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
563#define device_create_file_alarms(client) \
564device_create_file(&client->dev, &dev_attr_alarms)
565
566/* 1 PWM */
567static ssize_t show_pwm1(struct device *dev, char *buf)
568{
569 struct asb100_data *data = asb100_update_device(dev);
570 return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
571}
572
573static ssize_t set_pwm1(struct device *dev, const char *buf, size_t count)
574{
575 struct i2c_client *client = to_i2c_client(dev);
576 struct asb100_data *data = i2c_get_clientdata(client);
577 unsigned long val = simple_strtoul(buf, NULL, 10);
578
579 down(&data->update_lock);
580 data->pwm &= 0x80; /* keep the enable bit */
581 data->pwm |= (0x0f & ASB100_PWM_TO_REG(val));
582 asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
583 up(&data->update_lock);
584 return count;
585}
586
587static ssize_t show_pwm_enable1(struct device *dev, char *buf)
588{
589 struct asb100_data *data = asb100_update_device(dev);
590 return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
591}
592
593static ssize_t set_pwm_enable1(struct device *dev, const char *buf,
594 size_t count)
595{
596 struct i2c_client *client = to_i2c_client(dev);
597 struct asb100_data *data = i2c_get_clientdata(client);
598 unsigned long val = simple_strtoul(buf, NULL, 10);
599
600 down(&data->update_lock);
601 data->pwm &= 0x0f; /* keep the duty cycle bits */
602 data->pwm |= (val ? 0x80 : 0x00);
603 asb100_write_value(client, ASB100_REG_PWM1, data->pwm);
604 up(&data->update_lock);
605 return count;
606}
607
608static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm1, set_pwm1);
609static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
610 show_pwm_enable1, set_pwm_enable1);
611#define device_create_file_pwm1(client) do { \
612 device_create_file(&new_client->dev, &dev_attr_pwm1); \
613 device_create_file(&new_client->dev, &dev_attr_pwm1_enable); \
614} while (0)
615
616/* This function is called when:
617 asb100_driver is inserted (when this module is loaded), for each
618 available adapter
619 when a new adapter is inserted (and asb100_driver is still present)
620 */
621static int asb100_attach_adapter(struct i2c_adapter *adapter)
622{
623 if (!(adapter->class & I2C_CLASS_HWMON))
624 return 0;
625 return i2c_detect(adapter, &addr_data, asb100_detect);
626}
627
628static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
629 int kind, struct i2c_client *new_client)
630{
631 int i, id, err;
632 struct asb100_data *data = i2c_get_clientdata(new_client);
633
634 data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
635 if (!(data->lm75[0])) {
636 err = -ENOMEM;
637 goto ERROR_SC_0;
638 }
639 memset(data->lm75[0], 0x00, sizeof(struct i2c_client));
640
641 data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
642 if (!(data->lm75[1])) {
643 err = -ENOMEM;
644 goto ERROR_SC_1;
645 }
646 memset(data->lm75[1], 0x00, sizeof(struct i2c_client));
647
648 id = i2c_adapter_id(adapter);
649
650 if (force_subclients[0] == id && force_subclients[1] == address) {
651 for (i = 2; i <= 3; i++) {
652 if (force_subclients[i] < 0x48 ||
653 force_subclients[i] > 0x4f) {
654 dev_err(&new_client->dev, "invalid subclient "
655 "address %d; must be 0x48-0x4f\n",
656 force_subclients[i]);
657 err = -ENODEV;
658 goto ERROR_SC_2;
659 }
660 }
661 asb100_write_value(new_client, ASB100_REG_I2C_SUBADDR,
662 (force_subclients[2] & 0x07) |
663 ((force_subclients[3] & 0x07) <<4));
664 data->lm75[0]->addr = force_subclients[2];
665 data->lm75[1]->addr = force_subclients[3];
666 } else {
667 int val = asb100_read_value(new_client, ASB100_REG_I2C_SUBADDR);
668 data->lm75[0]->addr = 0x48 + (val & 0x07);
669 data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
670 }
671
672 if(data->lm75[0]->addr == data->lm75[1]->addr) {
673 dev_err(&new_client->dev, "duplicate addresses 0x%x "
674 "for subclients\n", data->lm75[0]->addr);
675 err = -ENODEV;
676 goto ERROR_SC_2;
677 }
678
679 for (i = 0; i <= 1; i++) {
680 i2c_set_clientdata(data->lm75[i], NULL);
681 data->lm75[i]->adapter = adapter;
682 data->lm75[i]->driver = &asb100_driver;
683 data->lm75[i]->flags = 0;
684 strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
685 }
686
687 if ((err = i2c_attach_client(data->lm75[0]))) {
688 dev_err(&new_client->dev, "subclient %d registration "
689 "at address 0x%x failed.\n", i, data->lm75[0]->addr);
690 goto ERROR_SC_2;
691 }
692
693 if ((err = i2c_attach_client(data->lm75[1]))) {
694 dev_err(&new_client->dev, "subclient %d registration "
695 "at address 0x%x failed.\n", i, data->lm75[1]->addr);
696 goto ERROR_SC_3;
697 }
698
699 return 0;
700
701/* Undo inits in case of errors */
702ERROR_SC_3:
703 i2c_detach_client(data->lm75[0]);
704ERROR_SC_2:
705 kfree(data->lm75[1]);
706ERROR_SC_1:
707 kfree(data->lm75[0]);
708ERROR_SC_0:
709 return err;
710}
711
712static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
713{
714 int err;
715 struct i2c_client *new_client;
716 struct asb100_data *data;
717
718 /* asb100 is SMBus only */
719 if (i2c_is_isa_adapter(adapter)) {
720 pr_debug("asb100.o: detect failed, "
721 "cannot attach to legacy adapter!\n");
722 err = -ENODEV;
723 goto ERROR0;
724 }
725
726 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
727 pr_debug("asb100.o: detect failed, "
728 "smbus byte data not supported!\n");
729 err = -ENODEV;
730 goto ERROR0;
731 }
732
733 /* OK. For now, we presume we have a valid client. We now create the
734 client structure, even though we cannot fill it completely yet.
735 But it allows us to access asb100_{read,write}_value. */
736
737 if (!(data = kmalloc(sizeof(struct asb100_data), GFP_KERNEL))) {
738 pr_debug("asb100.o: detect failed, kmalloc failed!\n");
739 err = -ENOMEM;
740 goto ERROR0;
741 }
742 memset(data, 0, sizeof(struct asb100_data));
743
744 new_client = &data->client;
745 init_MUTEX(&data->lock);
746 i2c_set_clientdata(new_client, data);
747 new_client->addr = address;
748 new_client->adapter = adapter;
749 new_client->driver = &asb100_driver;
750 new_client->flags = 0;
751
752 /* Now, we do the remaining detection. */
753
754 /* The chip may be stuck in some other bank than bank 0. This may
755 make reading other information impossible. Specify a force=... or
756 force_*=... parameter, and the chip will be reset to the right
757 bank. */
758 if (kind < 0) {
759
760 int val1 = asb100_read_value(new_client, ASB100_REG_BANK);
761 int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
762
763 /* If we're in bank 0 */
764 if ( (!(val1 & 0x07)) &&
765 /* Check for ASB100 ID (low byte) */
766 ( ((!(val1 & 0x80)) && (val2 != 0x94)) ||
767 /* Check for ASB100 ID (high byte ) */
768 ((val1 & 0x80) && (val2 != 0x06)) ) ) {
769 pr_debug("asb100.o: detect failed, "
770 "bad chip id 0x%02x!\n", val2);
771 err = -ENODEV;
772 goto ERROR1;
773 }
774
775 } /* kind < 0 */
776
777 /* We have either had a force parameter, or we have already detected
778 Winbond. Put it now into bank 0 and Vendor ID High Byte */
779 asb100_write_value(new_client, ASB100_REG_BANK,
780 (asb100_read_value(new_client, ASB100_REG_BANK) & 0x78) | 0x80);
781
782 /* Determine the chip type. */
783 if (kind <= 0) {
784 int val1 = asb100_read_value(new_client, ASB100_REG_WCHIPID);
785 int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
786
787 if ((val1 == 0x31) && (val2 == 0x06))
788 kind = asb100;
789 else {
790 if (kind == 0)
791 dev_warn(&new_client->dev, "ignoring "
792 "'force' parameter for unknown chip "
793 "at adapter %d, address 0x%02x.\n",
794 i2c_adapter_id(adapter), address);
795 err = -ENODEV;
796 goto ERROR1;
797 }
798 }
799
800 /* Fill in remaining client fields and put it into the global list */
801 strlcpy(new_client->name, "asb100", I2C_NAME_SIZE);
802 data->type = kind;
803
804 data->valid = 0;
805 init_MUTEX(&data->update_lock);
806
807 /* Tell the I2C layer a new client has arrived */
808 if ((err = i2c_attach_client(new_client)))
809 goto ERROR1;
810
811 /* Attach secondary lm75 clients */
812 if ((err = asb100_detect_subclients(adapter, address, kind,
813 new_client)))
814 goto ERROR2;
815
816 /* Initialize the chip */
817 asb100_init_client(new_client);
818
819 /* A few vars need to be filled upon startup */
820 data->fan_min[0] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(0));
821 data->fan_min[1] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(1));
822 data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
823
824 /* Register sysfs hooks */
825 device_create_file_in(new_client, 0);
826 device_create_file_in(new_client, 1);
827 device_create_file_in(new_client, 2);
828 device_create_file_in(new_client, 3);
829 device_create_file_in(new_client, 4);
830 device_create_file_in(new_client, 5);
831 device_create_file_in(new_client, 6);
832
833 device_create_file_fan(new_client, 1);
834 device_create_file_fan(new_client, 2);
835 device_create_file_fan(new_client, 3);
836
837 device_create_file_temp(new_client, 1);
838 device_create_file_temp(new_client, 2);
839 device_create_file_temp(new_client, 3);
840 device_create_file_temp(new_client, 4);
841
842 device_create_file_vid(new_client);
843 device_create_file_vrm(new_client);
844
845 device_create_file_alarms(new_client);
846
847 device_create_file_pwm1(new_client);
848
849 return 0;
850
851ERROR2:
852 i2c_detach_client(new_client);
853ERROR1:
854 kfree(data);
855ERROR0:
856 return err;
857}
858
859static int asb100_detach_client(struct i2c_client *client)
860{
861 int err;
862
863 if ((err = i2c_detach_client(client))) {
864 dev_err(&client->dev, "client deregistration failed; "
865 "client not detached.\n");
866 return err;
867 }
868
869 if (i2c_get_clientdata(client)==NULL) {
870 /* subclients */
871 kfree(client);
872 } else {
873 /* main client */
874 kfree(i2c_get_clientdata(client));
875 }
876
877 return 0;
878}
879
880/* The SMBus locks itself, usually, but nothing may access the chip between
881 bank switches. */
882static int asb100_read_value(struct i2c_client *client, u16 reg)
883{
884 struct asb100_data *data = i2c_get_clientdata(client);
885 struct i2c_client *cl;
886 int res, bank;
887
888 down(&data->lock);
889
890 bank = (reg >> 8) & 0x0f;
891 if (bank > 2)
892 /* switch banks */
893 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);
894
895 if (bank == 0 || bank > 2) {
896 res = i2c_smbus_read_byte_data(client, reg & 0xff);
897 } else {
898 /* switch to subclient */
899 cl = data->lm75[bank - 1];
900
901 /* convert from ISA to LM75 I2C addresses */
902 switch (reg & 0xff) {
903 case 0x50: /* TEMP */
904 res = swab16(i2c_smbus_read_word_data (cl, 0));
905 break;
906 case 0x52: /* CONFIG */
907 res = i2c_smbus_read_byte_data(cl, 1);
908 break;
909 case 0x53: /* HYST */
910 res = swab16(i2c_smbus_read_word_data (cl, 2));
911 break;
912 case 0x55: /* MAX */
913 default:
914 res = swab16(i2c_smbus_read_word_data (cl, 3));
915 break;
916 }
917 }
918
919 if (bank > 2)
920 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
921
922 up(&data->lock);
923
924 return res;
925}
926
927static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
928{
929 struct asb100_data *data = i2c_get_clientdata(client);
930 struct i2c_client *cl;
931 int bank;
932
933 down(&data->lock);
934
935 bank = (reg >> 8) & 0x0f;
936 if (bank > 2)
937 /* switch banks */
938 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, bank);
939
940 if (bank == 0 || bank > 2) {
941 i2c_smbus_write_byte_data(client, reg & 0xff, value & 0xff);
942 } else {
943 /* switch to subclient */
944 cl = data->lm75[bank - 1];
945
946 /* convert from ISA to LM75 I2C addresses */
947 switch (reg & 0xff) {
948 case 0x52: /* CONFIG */
949 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
950 break;
951 case 0x53: /* HYST */
952 i2c_smbus_write_word_data(cl, 2, swab16(value));
953 break;
954 case 0x55: /* MAX */
955 i2c_smbus_write_word_data(cl, 3, swab16(value));
956 break;
957 }
958 }
959
960 if (bank > 2)
961 i2c_smbus_write_byte_data(client, ASB100_REG_BANK, 0);
962
963 up(&data->lock);
964}
965
966static void asb100_init_client(struct i2c_client *client)
967{
968 struct asb100_data *data = i2c_get_clientdata(client);
969 int vid = 0;
970
971 vid = asb100_read_value(client, ASB100_REG_VID_FANDIV) & 0x0f;
972 vid |= (asb100_read_value(client, ASB100_REG_CHIPID) & 0x01) << 4;
973 data->vrm = i2c_which_vrm();
974 vid = vid_from_reg(vid, data->vrm);
975
976 /* Start monitoring */
977 asb100_write_value(client, ASB100_REG_CONFIG,
978 (asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01);
979}
980
981static struct asb100_data *asb100_update_device(struct device *dev)
982{
983 struct i2c_client *client = to_i2c_client(dev);
984 struct asb100_data *data = i2c_get_clientdata(client);
985 int i;
986
987 down(&data->update_lock);
988
989 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
990 || !data->valid) {
991
992 dev_dbg(&client->dev, "starting device update...\n");
993
994 /* 7 voltage inputs */
995 for (i = 0; i < 7; i++) {
996 data->in[i] = asb100_read_value(client,
997 ASB100_REG_IN(i));
998 data->in_min[i] = asb100_read_value(client,
999 ASB100_REG_IN_MIN(i));
1000 data->in_max[i] = asb100_read_value(client,
1001 ASB100_REG_IN_MAX(i));
1002 }
1003
1004 /* 3 fan inputs */
1005 for (i = 0; i < 3; i++) {
1006 data->fan[i] = asb100_read_value(client,
1007 ASB100_REG_FAN(i));
1008 data->fan_min[i] = asb100_read_value(client,
1009 ASB100_REG_FAN_MIN(i));
1010 }
1011
1012 /* 4 temperature inputs */
1013 for (i = 1; i <= 4; i++) {
1014 data->temp[i-1] = asb100_read_value(client,
1015 ASB100_REG_TEMP(i));
1016 data->temp_max[i-1] = asb100_read_value(client,
1017 ASB100_REG_TEMP_MAX(i));
1018 data->temp_hyst[i-1] = asb100_read_value(client,
1019 ASB100_REG_TEMP_HYST(i));
1020 }
1021
1022 /* VID and fan divisors */
1023 i = asb100_read_value(client, ASB100_REG_VID_FANDIV);
1024 data->vid = i & 0x0f;
1025 data->vid |= (asb100_read_value(client,
1026 ASB100_REG_CHIPID) & 0x01) << 4;
1027 data->fan_div[0] = (i >> 4) & 0x03;
1028 data->fan_div[1] = (i >> 6) & 0x03;
1029 data->fan_div[2] = (asb100_read_value(client,
1030 ASB100_REG_PIN) >> 6) & 0x03;
1031
1032 /* PWM */
1033 data->pwm = asb100_read_value(client, ASB100_REG_PWM1);
1034
1035 /* alarms */
1036 data->alarms = asb100_read_value(client, ASB100_REG_ALARM1) +
1037 (asb100_read_value(client, ASB100_REG_ALARM2) << 8);
1038
1039 data->last_updated = jiffies;
1040 data->valid = 1;
1041
1042 dev_dbg(&client->dev, "... device update complete\n");
1043 }
1044
1045 up(&data->update_lock);
1046
1047 return data;
1048}
1049
1050static int __init asb100_init(void)
1051{
1052 return i2c_add_driver(&asb100_driver);
1053}
1054
1055static void __exit asb100_exit(void)
1056{
1057 i2c_del_driver(&asb100_driver);
1058}
1059
1060MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
1061MODULE_DESCRIPTION("ASB100 Bach driver");
1062MODULE_LICENSE("GPL");
1063
1064module_init(asb100_init);
1065module_exit(asb100_exit);
1066
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 07f16c3fb084..9d3175c03395 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -3,22 +3,20 @@
3 * 3 *
4 * Copyright (C) 2005 James Chapman <jchapman@katalix.com> 4 * Copyright (C) 2005 James Chapman <jchapman@katalix.com>
5 * 5 *
6 * based on linux/drivers/acron/char/pcf8583.c 6 * based on linux/drivers/acorn/char/pcf8583.c
7 * Copyright (C) 2000 Russell King 7 * Copyright (C) 2000 Russell King
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 * 12 *
13 * Driver for Dallas Semiconductor DS1337 real time clock chip 13 * Driver for Dallas Semiconductor DS1337 and DS1339 real time clock chip
14 */ 14 */
15 15
16#include <linux/config.h>
17#include <linux/module.h> 16#include <linux/module.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/i2c.h> 19#include <linux/i2c.h>
21#include <linux/i2c-sensor.h>
22#include <linux/string.h> 20#include <linux/string.h>
23#include <linux/rtc.h> /* get the user-level API */ 21#include <linux/rtc.h> /* get the user-level API */
24#include <linux/bcd.h> 22#include <linux/bcd.h>
@@ -40,9 +38,8 @@
40 * Functions declaration 38 * Functions declaration
41 */ 39 */
42static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END }; 40static unsigned short normal_i2c[] = { 0x68, I2C_CLIENT_END };
43static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
44 41
45SENSORS_INSMOD_1(ds1337); 42I2C_CLIENT_INSMOD_1(ds1337);
46 43
47static int ds1337_attach_adapter(struct i2c_adapter *adapter); 44static int ds1337_attach_adapter(struct i2c_adapter *adapter);
48static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind); 45static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind);
@@ -69,13 +66,11 @@ static struct i2c_driver ds1337_driver = {
69struct ds1337_data { 66struct ds1337_data {
70 struct i2c_client client; 67 struct i2c_client client;
71 struct list_head list; 68 struct list_head list;
72 int id;
73}; 69};
74 70
75/* 71/*
76 * Internal variables 72 * Internal variables
77 */ 73 */
78static int ds1337_id;
79static LIST_HEAD(ds1337_clients); 74static LIST_HEAD(ds1337_clients);
80 75
81static inline int ds1337_read(struct i2c_client *client, u8 reg, u8 *value) 76static inline int ds1337_read(struct i2c_client *client, u8 reg, u8 *value)
@@ -95,7 +90,6 @@ static inline int ds1337_read(struct i2c_client *client, u8 reg, u8 *value)
95 */ 90 */
96static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt) 91static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
97{ 92{
98 struct ds1337_data *data = i2c_get_clientdata(client);
99 int result; 93 int result;
100 u8 buf[7]; 94 u8 buf[7];
101 u8 val; 95 u8 val;
@@ -103,9 +97,7 @@ static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
103 u8 offs = 0; 97 u8 offs = 0;
104 98
105 if (!dt) { 99 if (!dt) {
106 dev_dbg(&client->adapter->dev, "%s: EINVAL: dt=NULL\n", 100 dev_dbg(&client->dev, "%s: EINVAL: dt=NULL\n", __FUNCTION__);
107 __FUNCTION__);
108
109 return -EINVAL; 101 return -EINVAL;
110 } 102 }
111 103
@@ -119,98 +111,86 @@ static int ds1337_get_datetime(struct i2c_client *client, struct rtc_time *dt)
119 msg[1].len = sizeof(buf); 111 msg[1].len = sizeof(buf);
120 msg[1].buf = &buf[0]; 112 msg[1].buf = &buf[0];
121 113
122 result = client->adapter->algo->master_xfer(client->adapter, 114 result = i2c_transfer(client->adapter, msg, 2);
123 &msg[0], 2);
124 115
125 dev_dbg(&client->adapter->dev, 116 dev_dbg(&client->dev, "%s: [%d] %02x %02x %02x %02x %02x %02x %02x\n",
126 "%s: [%d] %02x %02x %02x %02x %02x %02x %02x\n",
127 __FUNCTION__, result, buf[0], buf[1], buf[2], buf[3], 117 __FUNCTION__, result, buf[0], buf[1], buf[2], buf[3],
128 buf[4], buf[5], buf[6]); 118 buf[4], buf[5], buf[6]);
129 119
130 if (result >= 0) { 120 if (result == 2) {
131 dt->tm_sec = BCD_TO_BIN(buf[0]); 121 dt->tm_sec = BCD2BIN(buf[0]);
132 dt->tm_min = BCD_TO_BIN(buf[1]); 122 dt->tm_min = BCD2BIN(buf[1]);
133 val = buf[2] & 0x3f; 123 val = buf[2] & 0x3f;
134 dt->tm_hour = BCD_TO_BIN(val); 124 dt->tm_hour = BCD2BIN(val);
135 dt->tm_wday = BCD_TO_BIN(buf[3]) - 1; 125 dt->tm_wday = BCD2BIN(buf[3]) - 1;
136 dt->tm_mday = BCD_TO_BIN(buf[4]); 126 dt->tm_mday = BCD2BIN(buf[4]);
137 val = buf[5] & 0x7f; 127 val = buf[5] & 0x7f;
138 dt->tm_mon = BCD_TO_BIN(val); 128 dt->tm_mon = BCD2BIN(val) - 1;
139 dt->tm_year = 1900 + BCD_TO_BIN(buf[6]); 129 dt->tm_year = BCD2BIN(buf[6]);
140 if (buf[5] & 0x80) 130 if (buf[5] & 0x80)
141 dt->tm_year += 100; 131 dt->tm_year += 100;
142 132
143 dev_dbg(&client->adapter->dev, "%s: secs=%d, mins=%d, " 133 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, "
144 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n", 134 "hours=%d, mday=%d, mon=%d, year=%d, wday=%d\n",
145 __FUNCTION__, dt->tm_sec, dt->tm_min, 135 __FUNCTION__, dt->tm_sec, dt->tm_min,
146 dt->tm_hour, dt->tm_mday, 136 dt->tm_hour, dt->tm_mday,
147 dt->tm_mon, dt->tm_year, dt->tm_wday); 137 dt->tm_mon, dt->tm_year, dt->tm_wday);
148 } else { 138
149 dev_err(&client->adapter->dev, "ds1337[%d]: error reading " 139 return 0;
150 "data! %d\n", data->id, result);
151 result = -EIO;
152 } 140 }
153 141
154 return result; 142 dev_err(&client->dev, "error reading data! %d\n", result);
143 return -EIO;
155} 144}
156 145
157static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt) 146static int ds1337_set_datetime(struct i2c_client *client, struct rtc_time *dt)
158{ 147{
159 struct ds1337_data *data = i2c_get_clientdata(client);
160 int result; 148 int result;
161 u8 buf[8]; 149 u8 buf[8];
162 u8 val; 150 u8 val;
163 struct i2c_msg msg[1]; 151 struct i2c_msg msg[1];
164 152
165 if (!dt) { 153 if (!dt) {
166 dev_dbg(&client->adapter->dev, "%s: EINVAL: dt=NULL\n", 154 dev_dbg(&client->dev, "%s: EINVAL: dt=NULL\n", __FUNCTION__);
167 __FUNCTION__);
168
169 return -EINVAL; 155 return -EINVAL;
170 } 156 }
171 157
172 dev_dbg(&client->adapter->dev, "%s: secs=%d, mins=%d, hours=%d, " 158 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
173 "mday=%d, mon=%d, year=%d, wday=%d\n", __FUNCTION__, 159 "mday=%d, mon=%d, year=%d, wday=%d\n", __FUNCTION__,
174 dt->tm_sec, dt->tm_min, dt->tm_hour, 160 dt->tm_sec, dt->tm_min, dt->tm_hour,
175 dt->tm_mday, dt->tm_mon, dt->tm_year, dt->tm_wday); 161 dt->tm_mday, dt->tm_mon, dt->tm_year, dt->tm_wday);
176 162
177 buf[0] = 0; /* reg offset */ 163 buf[0] = 0; /* reg offset */
178 buf[1] = BIN_TO_BCD(dt->tm_sec); 164 buf[1] = BIN2BCD(dt->tm_sec);
179 buf[2] = BIN_TO_BCD(dt->tm_min); 165 buf[2] = BIN2BCD(dt->tm_min);
180 buf[3] = BIN_TO_BCD(dt->tm_hour) | (1 << 6); 166 buf[3] = BIN2BCD(dt->tm_hour);
181 buf[4] = BIN_TO_BCD(dt->tm_wday) + 1; 167 buf[4] = BIN2BCD(dt->tm_wday) + 1;
182 buf[5] = BIN_TO_BCD(dt->tm_mday); 168 buf[5] = BIN2BCD(dt->tm_mday);
183 buf[6] = BIN_TO_BCD(dt->tm_mon); 169 buf[6] = BIN2BCD(dt->tm_mon) + 1;
184 if (dt->tm_year >= 2000) { 170 val = dt->tm_year;
185 val = dt->tm_year - 2000; 171 if (val >= 100) {
172 val -= 100;
186 buf[6] |= (1 << 7); 173 buf[6] |= (1 << 7);
187 } else {
188 val = dt->tm_year - 1900;
189 } 174 }
190 buf[7] = BIN_TO_BCD(val); 175 buf[7] = BIN2BCD(val);
191 176
192 msg[0].addr = client->addr; 177 msg[0].addr = client->addr;
193 msg[0].flags = 0; 178 msg[0].flags = 0;
194 msg[0].len = sizeof(buf); 179 msg[0].len = sizeof(buf);
195 msg[0].buf = &buf[0]; 180 msg[0].buf = &buf[0];
196 181
197 result = client->adapter->algo->master_xfer(client->adapter, 182 result = i2c_transfer(client->adapter, msg, 1);
198 &msg[0], 1); 183 if (result == 1)
199 if (result < 0) { 184 return 0;
200 dev_err(&client->adapter->dev, "ds1337[%d]: error "
201 "writing data! %d\n", data->id, result);
202 result = -EIO;
203 } else {
204 result = 0;
205 }
206 185
207 return result; 186 dev_err(&client->dev, "error writing data! %d\n", result);
187 return -EIO;
208} 188}
209 189
210static int ds1337_command(struct i2c_client *client, unsigned int cmd, 190static int ds1337_command(struct i2c_client *client, unsigned int cmd,
211 void *arg) 191 void *arg)
212{ 192{
213 dev_dbg(&client->adapter->dev, "%s: cmd=%d\n", __FUNCTION__, cmd); 193 dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd);
214 194
215 switch (cmd) { 195 switch (cmd) {
216 case DS1337_GET_DATE: 196 case DS1337_GET_DATE:
@@ -228,7 +208,7 @@ static int ds1337_command(struct i2c_client *client, unsigned int cmd,
228 * Public API for access to specific device. Useful for low-level 208 * Public API for access to specific device. Useful for low-level
229 * RTC access from kernel code. 209 * RTC access from kernel code.
230 */ 210 */
231int ds1337_do_command(int id, int cmd, void *arg) 211int ds1337_do_command(int bus, int cmd, void *arg)
232{ 212{
233 struct list_head *walk; 213 struct list_head *walk;
234 struct list_head *tmp; 214 struct list_head *tmp;
@@ -236,7 +216,7 @@ int ds1337_do_command(int id, int cmd, void *arg)
236 216
237 list_for_each_safe(walk, tmp, &ds1337_clients) { 217 list_for_each_safe(walk, tmp, &ds1337_clients) {
238 data = list_entry(walk, struct ds1337_data, list); 218 data = list_entry(walk, struct ds1337_data, list);
239 if (data->id == id) 219 if (data->client.adapter->nr == bus)
240 return ds1337_command(&data->client, cmd, arg); 220 return ds1337_command(&data->client, cmd, arg);
241 } 221 }
242 222
@@ -245,7 +225,7 @@ int ds1337_do_command(int id, int cmd, void *arg)
245 225
246static int ds1337_attach_adapter(struct i2c_adapter *adapter) 226static int ds1337_attach_adapter(struct i2c_adapter *adapter)
247{ 227{
248 return i2c_detect(adapter, &addr_data, ds1337_detect); 228 return i2c_probe(adapter, &addr_data, ds1337_detect);
249} 229}
250 230
251/* 231/*
@@ -346,7 +326,6 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
346 ds1337_init_client(new_client); 326 ds1337_init_client(new_client);
347 327
348 /* Add client to local list */ 328 /* Add client to local list */
349 data->id = ds1337_id++;
350 list_add(&data->list, &ds1337_clients); 329 list_add(&data->list, &ds1337_clients);
351 330
352 return 0; 331 return 0;
@@ -363,9 +342,9 @@ static void ds1337_init_client(struct i2c_client *client)
363 342
364 /* Ensure that device is set in 24-hour mode */ 343 /* Ensure that device is set in 24-hour mode */
365 val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR); 344 val = i2c_smbus_read_byte_data(client, DS1337_REG_HOUR);
366 if ((val >= 0) && (val & (1 << 6)) == 0) 345 if ((val >= 0) && (val & (1 << 6)))
367 i2c_smbus_write_byte_data(client, DS1337_REG_HOUR, 346 i2c_smbus_write_byte_data(client, DS1337_REG_HOUR,
368 val | (1 << 6)); 347 val & 0x3f);
369} 348}
370 349
371static int ds1337_detach_client(struct i2c_client *client) 350static int ds1337_detach_client(struct i2c_client *client)
@@ -373,11 +352,8 @@ static int ds1337_detach_client(struct i2c_client *client)
373 int err; 352 int err;
374 struct ds1337_data *data = i2c_get_clientdata(client); 353 struct ds1337_data *data = i2c_get_clientdata(client);
375 354
376 if ((err = i2c_detach_client(client))) { 355 if ((err = i2c_detach_client(client)))
377 dev_err(&client->dev, "Client deregistration failed, "
378 "client not detached.\n");
379 return err; 356 return err;
380 }
381 357
382 list_del(&data->list); 358 list_del(&data->list);
383 kfree(data); 359 kfree(data);
@@ -398,5 +374,7 @@ MODULE_AUTHOR("James Chapman <jchapman@katalix.com>");
398MODULE_DESCRIPTION("DS1337 RTC driver"); 374MODULE_DESCRIPTION("DS1337 RTC driver");
399MODULE_LICENSE("GPL"); 375MODULE_LICENSE("GPL");
400 376
377EXPORT_SYMBOL_GPL(ds1337_do_command);
378
401module_init(ds1337_init); 379module_init(ds1337_init);
402module_exit(ds1337_exit); 380module_exit(ds1337_exit);
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
new file mode 100644
index 000000000000..0936327a946d
--- /dev/null
+++ b/drivers/i2c/chips/ds1374.c
@@ -0,0 +1,259 @@
1/*
2 * drivers/i2c/chips/ds1374.c
3 *
4 * I2C client/driver for the Maxim/Dallas DS1374 Real-Time Clock
5 *
6 * Author: Randy Vinson <rvinson@mvista.com>
7 *
8 * Based on the m41t00.c by Mark Greer <mgreer@mvista.com>
9 *
10 * 2005 (c) MontaVista Software, Inc. This file is licensed under
11 * the terms of the GNU General Public License version 2. This program
12 * is licensed "as is" without any warranty of any kind, whether express
13 * or implied.
14 */
15/*
16 * This i2c client/driver wedges between the drivers/char/genrtc.c RTC
17 * interface and the SMBus interface of the i2c subsystem.
18 * It would be more efficient to use i2c msgs/i2c_transfer directly but, as
19 * recommened in .../Documentation/i2c/writing-clients section
20 * "Sending and receiving", using SMBus level communication is preferred.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/interrupt.h>
26#include <linux/i2c.h>
27#include <linux/rtc.h>
28#include <linux/bcd.h>
29
30#define DS1374_REG_TOD0 0x00
31#define DS1374_REG_TOD1 0x01
32#define DS1374_REG_TOD2 0x02
33#define DS1374_REG_TOD3 0x03
34#define DS1374_REG_WDALM0 0x04
35#define DS1374_REG_WDALM1 0x05
36#define DS1374_REG_WDALM2 0x06
37#define DS1374_REG_CR 0x07
38#define DS1374_REG_SR 0x08
39#define DS1374_REG_SR_OSF 0x80
40#define DS1374_REG_TCR 0x09
41
42#define DS1374_DRV_NAME "ds1374"
43
44static DECLARE_MUTEX(ds1374_mutex);
45
46static struct i2c_driver ds1374_driver;
47static struct i2c_client *save_client;
48
49static unsigned short ignore[] = { I2C_CLIENT_END };
50static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END };
51
52static struct i2c_client_address_data addr_data = {
53 .normal_i2c = normal_addr,
54 .probe = ignore,
55 .ignore = ignore,
56};
57
58static ulong ds1374_read_rtc(void)
59{
60 ulong time = 0;
61 int reg = DS1374_REG_WDALM0;
62
63 while (reg--) {
64 s32 tmp;
65 if ((tmp = i2c_smbus_read_byte_data(save_client, reg)) < 0) {
66 dev_warn(&save_client->dev,
67 "can't read from rtc chip\n");
68 return 0;
69 }
70 time = (time << 8) | (tmp & 0xff);
71 }
72 return time;
73}
74
75static void ds1374_write_rtc(ulong time)
76{
77 int reg;
78
79 for (reg = DS1374_REG_TOD0; reg < DS1374_REG_WDALM0; reg++) {
80 if (i2c_smbus_write_byte_data(save_client, reg, time & 0xff)
81 < 0) {
82 dev_warn(&save_client->dev,
83 "can't write to rtc chip\n");
84 break;
85 }
86 time = time >> 8;
87 }
88}
89
90static void ds1374_check_rtc_status(void)
91{
92 s32 tmp;
93
94 tmp = i2c_smbus_read_byte_data(save_client, DS1374_REG_SR);
95 if (tmp < 0) {
96 dev_warn(&save_client->dev,
97 "can't read status from rtc chip\n");
98 return;
99 }
100 if (tmp & DS1374_REG_SR_OSF) {
101 dev_warn(&save_client->dev,
102 "oscillator discontinuity flagged, time unreliable\n");
103 tmp &= ~DS1374_REG_SR_OSF;
104 tmp = i2c_smbus_write_byte_data(save_client, DS1374_REG_SR,
105 tmp & 0xff);
106 if (tmp < 0)
107 dev_warn(&save_client->dev,
108 "can't clear discontinuity notification\n");
109 }
110}
111
112ulong ds1374_get_rtc_time(void)
113{
114 ulong t1, t2;
115 int limit = 10; /* arbitrary retry limit */
116
117 down(&ds1374_mutex);
118
119 /*
120 * Since the reads are being performed one byte at a time using
121 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
122 * carry will occur during the read. To detect this, 2 reads are
123 * performed and compared.
124 */
125 do {
126 t1 = ds1374_read_rtc();
127 t2 = ds1374_read_rtc();
128 } while (t1 != t2 && limit--);
129
130 up(&ds1374_mutex);
131
132 if (t1 != t2) {
133 dev_warn(&save_client->dev,
134 "can't get consistent time from rtc chip\n");
135 t1 = 0;
136 }
137
138 return t1;
139}
140
141static void ds1374_set_tlet(ulong arg)
142{
143 ulong t1, t2;
144 int limit = 10; /* arbitrary retry limit */
145
146 t1 = *(ulong *) arg;
147
148 down(&ds1374_mutex);
149
150 /*
151 * Since the writes are being performed one byte at a time using
152 * the SMBus vs a 4-byte i2c transfer, there is a chance that a
153 * carry will occur during the write. To detect this, the write
154 * value is read back and compared.
155 */
156 do {
157 ds1374_write_rtc(t1);
158 t2 = ds1374_read_rtc();
159 } while (t1 != t2 && limit--);
160
161 up(&ds1374_mutex);
162
163 if (t1 != t2)
164 dev_warn(&save_client->dev,
165 "can't confirm time set from rtc chip\n");
166}
167
168static ulong new_time;
169
170DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time);
171
172int ds1374_set_rtc_time(ulong nowtime)
173{
174 new_time = nowtime;
175
176 if (in_interrupt())
177 tasklet_schedule(&ds1374_tasklet);
178 else
179 ds1374_set_tlet((ulong) & new_time);
180
181 return 0;
182}
183
184/*
185 *****************************************************************************
186 *
187 * Driver Interface
188 *
189 *****************************************************************************
190 */
191static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
192{
193 struct i2c_client *client;
194 int rc;
195
196 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
197 if (!client)
198 return -ENOMEM;
199
200 memset(client, 0, sizeof(struct i2c_client));
201 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
202 client->flags = I2C_DF_NOTIFY;
203 client->addr = addr;
204 client->adapter = adap;
205 client->driver = &ds1374_driver;
206
207 if ((rc = i2c_attach_client(client)) != 0) {
208 kfree(client);
209 return rc;
210 }
211
212 save_client = client;
213
214 ds1374_check_rtc_status();
215
216 return 0;
217}
218
219static int ds1374_attach(struct i2c_adapter *adap)
220{
221 return i2c_probe(adap, &addr_data, ds1374_probe);
222}
223
224static int ds1374_detach(struct i2c_client *client)
225{
226 int rc;
227
228 if ((rc = i2c_detach_client(client)) == 0) {
229 kfree(i2c_get_clientdata(client));
230 tasklet_kill(&ds1374_tasklet);
231 }
232 return rc;
233}
234
235static struct i2c_driver ds1374_driver = {
236 .owner = THIS_MODULE,
237 .name = DS1374_DRV_NAME,
238 .id = I2C_DRIVERID_DS1374,
239 .flags = I2C_DF_NOTIFY,
240 .attach_adapter = ds1374_attach,
241 .detach_client = ds1374_detach,
242};
243
244static int __init ds1374_init(void)
245{
246 return i2c_add_driver(&ds1374_driver);
247}
248
249static void __exit ds1374_exit(void)
250{
251 i2c_del_driver(&ds1374_driver);
252}
253
254module_init(ds1374_init);
255module_exit(ds1374_exit);
256
257MODULE_AUTHOR("Randy Vinson <rvinson@mvista.com>");
258MODULE_DESCRIPTION("Maxim/Dallas DS1374 RTC I2C Client Driver");
259MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/ds1621.c b/drivers/i2c/chips/ds1621.c
deleted file mode 100644
index bb1fefb2162e..000000000000
--- a/drivers/i2c/chips/ds1621.c
+++ /dev/null
@@ -1,341 +0,0 @@
1/*
2 ds1621.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Christian W. Zuckschwerdt <zany@triq.net> 2000-11-23
5 based on lm75.c by Frodo Looijaard <frodol@dds.nl>
6 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
7 the help of Jean Delvare <khali@linux-fr.org>
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/i2c.h>
29#include <linux/i2c-sensor.h>
30#include "lm75.h"
31
32/* Addresses to scan */
33static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
34 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
35static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
36
37/* Insmod parameters */
38SENSORS_INSMOD_1(ds1621);
39static int polarity = -1;
40module_param(polarity, int, 0);
41MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low");
42
43/* Many DS1621 constants specified below */
44/* Config register used for detection */
45/* 7 6 5 4 3 2 1 0 */
46/* |Done|THF |TLF |NVB | X | X |POL |1SHOT| */
47#define DS1621_REG_CONFIG_NVB 0x10
48#define DS1621_REG_CONFIG_POLARITY 0x02
49#define DS1621_REG_CONFIG_1SHOT 0x01
50#define DS1621_REG_CONFIG_DONE 0x80
51
52/* The DS1621 registers */
53#define DS1621_REG_TEMP 0xAA /* word, RO */
54#define DS1621_REG_TEMP_MIN 0xA1 /* word, RW */
55#define DS1621_REG_TEMP_MAX 0xA2 /* word, RW */
56#define DS1621_REG_CONF 0xAC /* byte, RW */
57#define DS1621_COM_START 0xEE /* no data */
58#define DS1621_COM_STOP 0x22 /* no data */
59
60/* The DS1621 configuration register */
61#define DS1621_ALARM_TEMP_HIGH 0x40
62#define DS1621_ALARM_TEMP_LOW 0x20
63
64/* Conversions. Rounding and limit checking is only done on the TO_REG
65 variants. Note that you should be a bit careful with which arguments
66 these macros are called: arguments may be evaluated more than once.
67 Fixing this is just not worth it. */
68#define ALARMS_FROM_REG(val) ((val) & \
69 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW))
70
71/* Each client has this additional data */
72struct ds1621_data {
73 struct i2c_client client;
74 struct semaphore update_lock;
75 char valid; /* !=0 if following fields are valid */
76 unsigned long last_updated; /* In jiffies */
77
78 u16 temp, temp_min, temp_max; /* Register values, word */
79 u8 conf; /* Register encoding, combined */
80};
81
82static int ds1621_attach_adapter(struct i2c_adapter *adapter);
83static int ds1621_detect(struct i2c_adapter *adapter, int address,
84 int kind);
85static void ds1621_init_client(struct i2c_client *client);
86static int ds1621_detach_client(struct i2c_client *client);
87static struct ds1621_data *ds1621_update_client(struct device *dev);
88
89/* This is the driver that will be inserted */
90static struct i2c_driver ds1621_driver = {
91 .owner = THIS_MODULE,
92 .name = "ds1621",
93 .id = I2C_DRIVERID_DS1621,
94 .flags = I2C_DF_NOTIFY,
95 .attach_adapter = ds1621_attach_adapter,
96 .detach_client = ds1621_detach_client,
97};
98
99/* All registers are word-sized, except for the configuration register.
100 DS1621 uses a high-byte first convention, which is exactly opposite to
101 the usual practice. */
102static int ds1621_read_value(struct i2c_client *client, u8 reg)
103{
104 if (reg == DS1621_REG_CONF)
105 return i2c_smbus_read_byte_data(client, reg);
106 else
107 return swab16(i2c_smbus_read_word_data(client, reg));
108}
109
110/* All registers are word-sized, except for the configuration register.
111 DS1621 uses a high-byte first convention, which is exactly opposite to
112 the usual practice. */
113static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value)
114{
115 if (reg == DS1621_REG_CONF)
116 return i2c_smbus_write_byte_data(client, reg, value);
117 else
118 return i2c_smbus_write_word_data(client, reg, swab16(value));
119}
120
121static void ds1621_init_client(struct i2c_client *client)
122{
123 int reg = ds1621_read_value(client, DS1621_REG_CONF);
124 /* switch to continous conversion mode */
125 reg &= ~ DS1621_REG_CONFIG_1SHOT;
126
127 /* setup output polarity */
128 if (polarity == 0)
129 reg &= ~DS1621_REG_CONFIG_POLARITY;
130 else if (polarity == 1)
131 reg |= DS1621_REG_CONFIG_POLARITY;
132
133 ds1621_write_value(client, DS1621_REG_CONF, reg);
134
135 /* start conversion */
136 i2c_smbus_write_byte(client, DS1621_COM_START);
137}
138
139#define show(value) \
140static ssize_t show_##value(struct device *dev, char *buf) \
141{ \
142 struct ds1621_data *data = ds1621_update_client(dev); \
143 return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \
144}
145
146show(temp);
147show(temp_min);
148show(temp_max);
149
150#define set_temp(suffix, value, reg) \
151static ssize_t set_temp_##suffix(struct device *dev, const char *buf, \
152 size_t count) \
153{ \
154 struct i2c_client *client = to_i2c_client(dev); \
155 struct ds1621_data *data = ds1621_update_client(dev); \
156 u16 val = LM75_TEMP_TO_REG(simple_strtoul(buf, NULL, 10)); \
157 \
158 down(&data->update_lock); \
159 data->value = val; \
160 ds1621_write_value(client, reg, data->value); \
161 up(&data->update_lock); \
162 return count; \
163}
164
165set_temp(min, temp_min, DS1621_REG_TEMP_MIN);
166set_temp(max, temp_max, DS1621_REG_TEMP_MAX);
167
168static ssize_t show_alarms(struct device *dev, char *buf)
169{
170 struct ds1621_data *data = ds1621_update_client(dev);
171 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->conf));
172}
173
174static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
175static DEVICE_ATTR(temp1_input, S_IRUGO , show_temp, NULL);
176static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO , show_temp_min, set_temp_min);
177static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
178
179
180static int ds1621_attach_adapter(struct i2c_adapter *adapter)
181{
182 return i2c_detect(adapter, &addr_data, ds1621_detect);
183}
184
185/* This function is called by i2c_detect */
186int ds1621_detect(struct i2c_adapter *adapter, int address,
187 int kind)
188{
189 int conf, temp;
190 struct i2c_client *new_client;
191 struct ds1621_data *data;
192 int err = 0;
193
194 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
195 | I2C_FUNC_SMBUS_WORD_DATA
196 | I2C_FUNC_SMBUS_WRITE_BYTE))
197 goto exit;
198
199 /* OK. For now, we presume we have a valid client. We now create the
200 client structure, even though we cannot fill it completely yet.
201 But it allows us to access ds1621_{read,write}_value. */
202 if (!(data = kmalloc(sizeof(struct ds1621_data), GFP_KERNEL))) {
203 err = -ENOMEM;
204 goto exit;
205 }
206 memset(data, 0, sizeof(struct ds1621_data));
207
208 new_client = &data->client;
209 i2c_set_clientdata(new_client, data);
210 new_client->addr = address;
211 new_client->adapter = adapter;
212 new_client->driver = &ds1621_driver;
213 new_client->flags = 0;
214
215
216 /* Now, we do the remaining detection. It is lousy. */
217 if (kind < 0) {
218 /* The NVB bit should be low if no EEPROM write has been
219 requested during the latest 10ms, which is highly
220 improbable in our case. */
221 conf = ds1621_read_value(new_client, DS1621_REG_CONF);
222 if (conf & DS1621_REG_CONFIG_NVB)
223 goto exit_free;
224 /* The 7 lowest bits of a temperature should always be 0. */
225 temp = ds1621_read_value(new_client, DS1621_REG_TEMP);
226 if (temp & 0x007f)
227 goto exit_free;
228 temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MIN);
229 if (temp & 0x007f)
230 goto exit_free;
231 temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MAX);
232 if (temp & 0x007f)
233 goto exit_free;
234 }
235
236 /* Determine the chip type - only one kind supported! */
237 if (kind <= 0)
238 kind = ds1621;
239
240 /* Fill in remaining client fields and put it into the global list */
241 strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE);
242 data->valid = 0;
243 init_MUTEX(&data->update_lock);
244
245 /* Tell the I2C layer a new client has arrived */
246 if ((err = i2c_attach_client(new_client)))
247 goto exit_free;
248
249 /* Initialize the DS1621 chip */
250 ds1621_init_client(new_client);
251
252 /* Register sysfs hooks */
253 device_create_file(&new_client->dev, &dev_attr_alarms);
254 device_create_file(&new_client->dev, &dev_attr_temp1_input);
255 device_create_file(&new_client->dev, &dev_attr_temp1_min);
256 device_create_file(&new_client->dev, &dev_attr_temp1_max);
257
258 return 0;
259
260/* OK, this is not exactly good programming practice, usually. But it is
261 very code-efficient in this case. */
262 exit_free:
263 kfree(data);
264 exit:
265 return err;
266}
267
268static int ds1621_detach_client(struct i2c_client *client)
269{
270 int err;
271
272 if ((err = i2c_detach_client(client))) {
273 dev_err(&client->dev, "Client deregistration failed, "
274 "client not detached.\n");
275 return err;
276 }
277
278 kfree(i2c_get_clientdata(client));
279
280 return 0;
281}
282
283
284static struct ds1621_data *ds1621_update_client(struct device *dev)
285{
286 struct i2c_client *client = to_i2c_client(dev);
287 struct ds1621_data *data = i2c_get_clientdata(client);
288 u8 new_conf;
289
290 down(&data->update_lock);
291
292 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
293 || !data->valid) {
294
295 dev_dbg(&client->dev, "Starting ds1621 update\n");
296
297 data->conf = ds1621_read_value(client, DS1621_REG_CONF);
298
299 data->temp = ds1621_read_value(client, DS1621_REG_TEMP);
300
301 data->temp_min = ds1621_read_value(client,
302 DS1621_REG_TEMP_MIN);
303 data->temp_max = ds1621_read_value(client,
304 DS1621_REG_TEMP_MAX);
305
306 /* reset alarms if neccessary */
307 new_conf = data->conf;
308 if (data->temp < data->temp_min)
309 new_conf &= ~DS1621_ALARM_TEMP_LOW;
310 if (data->temp > data->temp_max)
311 new_conf &= ~DS1621_ALARM_TEMP_HIGH;
312 if (data->conf != new_conf)
313 ds1621_write_value(client, DS1621_REG_CONF,
314 new_conf);
315
316 data->last_updated = jiffies;
317 data->valid = 1;
318 }
319
320 up(&data->update_lock);
321
322 return data;
323}
324
325static int __init ds1621_init(void)
326{
327 return i2c_add_driver(&ds1621_driver);
328}
329
330static void __exit ds1621_exit(void)
331{
332 i2c_del_driver(&ds1621_driver);
333}
334
335
336MODULE_AUTHOR("Christian W. Zuckschwerdt <zany@triq.net>");
337MODULE_DESCRIPTION("DS1621 driver");
338MODULE_LICENSE("GPL");
339
340module_init(ds1621_init);
341module_exit(ds1621_exit);
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index cbdfa2db6f7c..d58403a47908 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -26,7 +26,6 @@
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/ 27*/
28 28
29#include <linux/config.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/module.h> 31#include <linux/module.h>
@@ -34,15 +33,13 @@
34#include <linux/sched.h> 33#include <linux/sched.h>
35#include <linux/jiffies.h> 34#include <linux/jiffies.h>
36#include <linux/i2c.h> 35#include <linux/i2c.h>
37#include <linux/i2c-sensor.h>
38 36
39/* Addresses to scan */ 37/* Addresses to scan */
40static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54, 38static unsigned short normal_i2c[] = { 0x50, 0x51, 0x52, 0x53, 0x54,
41 0x55, 0x56, 0x57, I2C_CLIENT_END }; 39 0x55, 0x56, 0x57, I2C_CLIENT_END };
42static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
43 40
44/* Insmod parameters */ 41/* Insmod parameters */
45SENSORS_INSMOD_1(eeprom); 42I2C_CLIENT_INSMOD_1(eeprom);
46 43
47 44
48/* Size of EEPROM in bytes */ 45/* Size of EEPROM in bytes */
@@ -154,10 +151,10 @@ static struct bin_attribute eeprom_attr = {
154 151
155static int eeprom_attach_adapter(struct i2c_adapter *adapter) 152static int eeprom_attach_adapter(struct i2c_adapter *adapter)
156{ 153{
157 return i2c_detect(adapter, &addr_data, eeprom_detect); 154 return i2c_probe(adapter, &addr_data, eeprom_detect);
158} 155}
159 156
160/* This function is called by i2c_detect */ 157/* This function is called by i2c_probe */
161int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 158int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
162{ 159{
163 struct i2c_client *new_client; 160 struct i2c_client *new_client;
@@ -174,9 +171,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
174 | I2C_FUNC_SMBUS_BYTE)) 171 | I2C_FUNC_SMBUS_BYTE))
175 goto exit; 172 goto exit;
176 173
177 /* OK. For now, we presume we have a valid client. We now create the
178 client structure, even though we cannot fill it completely yet.
179 But it allows us to access eeprom_{read,write}_value. */
180 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 174 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
181 err = -ENOMEM; 175 err = -ENOMEM;
182 goto exit; 176 goto exit;
@@ -191,9 +185,6 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
191 new_client->driver = &eeprom_driver; 185 new_client->driver = &eeprom_driver;
192 new_client->flags = 0; 186 new_client->flags = 0;
193 187
194 /* prevent 24RF08 corruption */
195 i2c_smbus_write_quick(new_client, 0);
196
197 /* Fill in the remaining client fields */ 188 /* Fill in the remaining client fields */
198 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE); 189 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE);
199 data->valid = 0; 190 data->valid = 0;
@@ -233,10 +224,8 @@ static int eeprom_detach_client(struct i2c_client *client)
233 int err; 224 int err;
234 225
235 err = i2c_detach_client(client); 226 err = i2c_detach_client(client);
236 if (err) { 227 if (err)
237 dev_err(&client->dev, "Client deregistration failed, client not detached.\n");
238 return err; 228 return err;
239 }
240 229
241 kfree(i2c_get_clientdata(client)); 230 kfree(i2c_get_clientdata(client));
242 231
diff --git a/drivers/i2c/chips/fscher.c b/drivers/i2c/chips/fscher.c
deleted file mode 100644
index 18e33ac59d0c..000000000000
--- a/drivers/i2c/chips/fscher.c
+++ /dev/null
@@ -1,692 +0,0 @@
1/*
2 * fscher.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2003, 2004 Reinhard Nissl <rnissl@gmx.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/*
22 * fujitsu siemens hermes chip,
23 * module based on fscpos.c
24 * Copyright (C) 2000 Hermann Jung <hej@odn.de>
25 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
26 * and Philip Edelbrock <phil@netroedge.com>
27 */
28
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/jiffies.h>
34#include <linux/i2c.h>
35#include <linux/i2c-sensor.h>
36
37/*
38 * Addresses to scan
39 */
40
41static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
42static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
43
44/*
45 * Insmod parameters
46 */
47
48SENSORS_INSMOD_1(fscher);
49
50/*
51 * The FSCHER registers
52 */
53
54/* chip identification */
55#define FSCHER_REG_IDENT_0 0x00
56#define FSCHER_REG_IDENT_1 0x01
57#define FSCHER_REG_IDENT_2 0x02
58#define FSCHER_REG_REVISION 0x03
59
60/* global control and status */
61#define FSCHER_REG_EVENT_STATE 0x04
62#define FSCHER_REG_CONTROL 0x05
63
64/* watchdog */
65#define FSCHER_REG_WDOG_PRESET 0x28
66#define FSCHER_REG_WDOG_STATE 0x23
67#define FSCHER_REG_WDOG_CONTROL 0x21
68
69/* fan 0 */
70#define FSCHER_REG_FAN0_MIN 0x55
71#define FSCHER_REG_FAN0_ACT 0x0e
72#define FSCHER_REG_FAN0_STATE 0x0d
73#define FSCHER_REG_FAN0_RIPPLE 0x0f
74
75/* fan 1 */
76#define FSCHER_REG_FAN1_MIN 0x65
77#define FSCHER_REG_FAN1_ACT 0x6b
78#define FSCHER_REG_FAN1_STATE 0x62
79#define FSCHER_REG_FAN1_RIPPLE 0x6f
80
81/* fan 2 */
82#define FSCHER_REG_FAN2_MIN 0xb5
83#define FSCHER_REG_FAN2_ACT 0xbb
84#define FSCHER_REG_FAN2_STATE 0xb2
85#define FSCHER_REG_FAN2_RIPPLE 0xbf
86
87/* voltage supervision */
88#define FSCHER_REG_VOLT_12 0x45
89#define FSCHER_REG_VOLT_5 0x42
90#define FSCHER_REG_VOLT_BATT 0x48
91
92/* temperature 0 */
93#define FSCHER_REG_TEMP0_ACT 0x64
94#define FSCHER_REG_TEMP0_STATE 0x71
95
96/* temperature 1 */
97#define FSCHER_REG_TEMP1_ACT 0x32
98#define FSCHER_REG_TEMP1_STATE 0x81
99
100/* temperature 2 */
101#define FSCHER_REG_TEMP2_ACT 0x35
102#define FSCHER_REG_TEMP2_STATE 0x91
103
104/*
105 * Functions declaration
106 */
107
108static int fscher_attach_adapter(struct i2c_adapter *adapter);
109static int fscher_detect(struct i2c_adapter *adapter, int address, int kind);
110static int fscher_detach_client(struct i2c_client *client);
111static struct fscher_data *fscher_update_device(struct device *dev);
112static void fscher_init_client(struct i2c_client *client);
113
114static int fscher_read_value(struct i2c_client *client, u8 reg);
115static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value);
116
117/*
118 * Driver data (common to all clients)
119 */
120
121static struct i2c_driver fscher_driver = {
122 .owner = THIS_MODULE,
123 .name = "fscher",
124 .id = I2C_DRIVERID_FSCHER,
125 .flags = I2C_DF_NOTIFY,
126 .attach_adapter = fscher_attach_adapter,
127 .detach_client = fscher_detach_client,
128};
129
130/*
131 * Client data (each client gets its own)
132 */
133
134struct fscher_data {
135 struct i2c_client client;
136 struct semaphore update_lock;
137 char valid; /* zero until following fields are valid */
138 unsigned long last_updated; /* in jiffies */
139
140 /* register values */
141 u8 revision; /* revision of chip */
142 u8 global_event; /* global event status */
143 u8 global_control; /* global control register */
144 u8 watchdog[3]; /* watchdog */
145 u8 volt[3]; /* 12, 5, battery voltage */
146 u8 temp_act[3]; /* temperature */
147 u8 temp_status[3]; /* status of sensor */
148 u8 fan_act[3]; /* fans revolutions per second */
149 u8 fan_status[3]; /* fan status */
150 u8 fan_min[3]; /* fan min value for rps */
151 u8 fan_ripple[3]; /* divider for rps */
152};
153
154/*
155 * Sysfs stuff
156 */
157
158#define sysfs_r(kind, sub, offset, reg) \
159static ssize_t show_##kind##sub (struct fscher_data *, char *, int); \
160static ssize_t show_##kind##offset##sub (struct device *, char *); \
161static ssize_t show_##kind##offset##sub (struct device *dev, char *buf) \
162{ \
163 struct fscher_data *data = fscher_update_device(dev); \
164 return show_##kind##sub(data, buf, (offset)); \
165}
166
167#define sysfs_w(kind, sub, offset, reg) \
168static ssize_t set_##kind##sub (struct i2c_client *, struct fscher_data *, const char *, size_t, int, int); \
169static ssize_t set_##kind##offset##sub (struct device *, const char *, size_t); \
170static ssize_t set_##kind##offset##sub (struct device *dev, const char *buf, size_t count) \
171{ \
172 struct i2c_client *client = to_i2c_client(dev); \
173 struct fscher_data *data = i2c_get_clientdata(client); \
174 return set_##kind##sub(client, data, buf, count, (offset), reg); \
175}
176
177#define sysfs_rw_n(kind, sub, offset, reg) \
178sysfs_r(kind, sub, offset, reg) \
179sysfs_w(kind, sub, offset, reg) \
180static DEVICE_ATTR(kind##offset##sub, S_IRUGO | S_IWUSR, show_##kind##offset##sub, set_##kind##offset##sub);
181
182#define sysfs_rw(kind, sub, reg) \
183sysfs_r(kind, sub, 0, reg) \
184sysfs_w(kind, sub, 0, reg) \
185static DEVICE_ATTR(kind##sub, S_IRUGO | S_IWUSR, show_##kind##0##sub, set_##kind##0##sub);
186
187#define sysfs_ro_n(kind, sub, offset, reg) \
188sysfs_r(kind, sub, offset, reg) \
189static DEVICE_ATTR(kind##offset##sub, S_IRUGO, show_##kind##offset##sub, NULL);
190
191#define sysfs_ro(kind, sub, reg) \
192sysfs_r(kind, sub, 0, reg) \
193static DEVICE_ATTR(kind, S_IRUGO, show_##kind##0##sub, NULL);
194
195#define sysfs_fan(offset, reg_status, reg_min, reg_ripple, reg_act) \
196sysfs_rw_n(pwm, , offset, reg_min) \
197sysfs_rw_n(fan, _status, offset, reg_status) \
198sysfs_rw_n(fan, _div , offset, reg_ripple) \
199sysfs_ro_n(fan, _input , offset, reg_act)
200
201#define sysfs_temp(offset, reg_status, reg_act) \
202sysfs_rw_n(temp, _status, offset, reg_status) \
203sysfs_ro_n(temp, _input , offset, reg_act)
204
205#define sysfs_in(offset, reg_act) \
206sysfs_ro_n(in, _input, offset, reg_act)
207
208#define sysfs_revision(reg_revision) \
209sysfs_ro(revision, , reg_revision)
210
211#define sysfs_alarms(reg_events) \
212sysfs_ro(alarms, , reg_events)
213
214#define sysfs_control(reg_control) \
215sysfs_rw(control, , reg_control)
216
217#define sysfs_watchdog(reg_control, reg_status, reg_preset) \
218sysfs_rw(watchdog, _control, reg_control) \
219sysfs_rw(watchdog, _status , reg_status) \
220sysfs_rw(watchdog, _preset , reg_preset)
221
222sysfs_fan(1, FSCHER_REG_FAN0_STATE, FSCHER_REG_FAN0_MIN,
223 FSCHER_REG_FAN0_RIPPLE, FSCHER_REG_FAN0_ACT)
224sysfs_fan(2, FSCHER_REG_FAN1_STATE, FSCHER_REG_FAN1_MIN,
225 FSCHER_REG_FAN1_RIPPLE, FSCHER_REG_FAN1_ACT)
226sysfs_fan(3, FSCHER_REG_FAN2_STATE, FSCHER_REG_FAN2_MIN,
227 FSCHER_REG_FAN2_RIPPLE, FSCHER_REG_FAN2_ACT)
228
229sysfs_temp(1, FSCHER_REG_TEMP0_STATE, FSCHER_REG_TEMP0_ACT)
230sysfs_temp(2, FSCHER_REG_TEMP1_STATE, FSCHER_REG_TEMP1_ACT)
231sysfs_temp(3, FSCHER_REG_TEMP2_STATE, FSCHER_REG_TEMP2_ACT)
232
233sysfs_in(0, FSCHER_REG_VOLT_12)
234sysfs_in(1, FSCHER_REG_VOLT_5)
235sysfs_in(2, FSCHER_REG_VOLT_BATT)
236
237sysfs_revision(FSCHER_REG_REVISION)
238sysfs_alarms(FSCHER_REG_EVENTS)
239sysfs_control(FSCHER_REG_CONTROL)
240sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
241
242#define device_create_file_fan(client, offset) \
243do { \
244 device_create_file(&client->dev, &dev_attr_fan##offset##_status); \
245 device_create_file(&client->dev, &dev_attr_pwm##offset); \
246 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
247 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
248} while (0)
249
250#define device_create_file_temp(client, offset) \
251do { \
252 device_create_file(&client->dev, &dev_attr_temp##offset##_status); \
253 device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
254} while (0)
255
256#define device_create_file_in(client, offset) \
257do { \
258 device_create_file(&client->dev, &dev_attr_in##offset##_input); \
259} while (0)
260
261#define device_create_file_revision(client) \
262do { \
263 device_create_file(&client->dev, &dev_attr_revision); \
264} while (0)
265
266#define device_create_file_alarms(client) \
267do { \
268 device_create_file(&client->dev, &dev_attr_alarms); \
269} while (0)
270
271#define device_create_file_control(client) \
272do { \
273 device_create_file(&client->dev, &dev_attr_control); \
274} while (0)
275
276#define device_create_file_watchdog(client) \
277do { \
278 device_create_file(&client->dev, &dev_attr_watchdog_status); \
279 device_create_file(&client->dev, &dev_attr_watchdog_control); \
280 device_create_file(&client->dev, &dev_attr_watchdog_preset); \
281} while (0)
282
283/*
284 * Real code
285 */
286
287static int fscher_attach_adapter(struct i2c_adapter *adapter)
288{
289 if (!(adapter->class & I2C_CLASS_HWMON))
290 return 0;
291 return i2c_detect(adapter, &addr_data, fscher_detect);
292}
293
294static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
295{
296 struct i2c_client *new_client;
297 struct fscher_data *data;
298 int err = 0;
299
300 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
301 goto exit;
302
303 /* OK. For now, we presume we have a valid client. We now create the
304 * client structure, even though we cannot fill it completely yet.
305 * But it allows us to access i2c_smbus_read_byte_data. */
306 if (!(data = kmalloc(sizeof(struct fscher_data), GFP_KERNEL))) {
307 err = -ENOMEM;
308 goto exit;
309 }
310 memset(data, 0, sizeof(struct fscher_data));
311
312 /* The common I2C client data is placed right before the
313 * Hermes-specific data. */
314 new_client = &data->client;
315 i2c_set_clientdata(new_client, data);
316 new_client->addr = address;
317 new_client->adapter = adapter;
318 new_client->driver = &fscher_driver;
319 new_client->flags = 0;
320
321 /* Do the remaining detection unless force or force_fscher parameter */
322 if (kind < 0) {
323 if ((i2c_smbus_read_byte_data(new_client,
324 FSCHER_REG_IDENT_0) != 0x48) /* 'H' */
325 || (i2c_smbus_read_byte_data(new_client,
326 FSCHER_REG_IDENT_1) != 0x45) /* 'E' */
327 || (i2c_smbus_read_byte_data(new_client,
328 FSCHER_REG_IDENT_2) != 0x52)) /* 'R' */
329 goto exit_free;
330 }
331
332 /* Fill in the remaining client fields and put it into the
333 * global list */
334 strlcpy(new_client->name, "fscher", I2C_NAME_SIZE);
335 data->valid = 0;
336 init_MUTEX(&data->update_lock);
337
338 /* Tell the I2C layer a new client has arrived */
339 if ((err = i2c_attach_client(new_client)))
340 goto exit_free;
341
342 fscher_init_client(new_client);
343
344 /* Register sysfs hooks */
345 device_create_file_revision(new_client);
346 device_create_file_alarms(new_client);
347 device_create_file_control(new_client);
348 device_create_file_watchdog(new_client);
349
350 device_create_file_in(new_client, 0);
351 device_create_file_in(new_client, 1);
352 device_create_file_in(new_client, 2);
353
354 device_create_file_fan(new_client, 1);
355 device_create_file_fan(new_client, 2);
356 device_create_file_fan(new_client, 3);
357
358 device_create_file_temp(new_client, 1);
359 device_create_file_temp(new_client, 2);
360 device_create_file_temp(new_client, 3);
361
362 return 0;
363
364exit_free:
365 kfree(data);
366exit:
367 return err;
368}
369
370static int fscher_detach_client(struct i2c_client *client)
371{
372 int err;
373
374 if ((err = i2c_detach_client(client))) {
375 dev_err(&client->dev, "Client deregistration failed, "
376 "client not detached.\n");
377 return err;
378 }
379
380 kfree(i2c_get_clientdata(client));
381 return 0;
382}
383
384static int fscher_read_value(struct i2c_client *client, u8 reg)
385{
386 dev_dbg(&client->dev, "read reg 0x%02x\n", reg);
387
388 return i2c_smbus_read_byte_data(client, reg);
389}
390
391static int fscher_write_value(struct i2c_client *client, u8 reg, u8 value)
392{
393 dev_dbg(&client->dev, "write reg 0x%02x, val 0x%02x\n",
394 reg, value);
395
396 return i2c_smbus_write_byte_data(client, reg, value);
397}
398
399/* Called when we have found a new FSC Hermes. */
400static void fscher_init_client(struct i2c_client *client)
401{
402 struct fscher_data *data = i2c_get_clientdata(client);
403
404 /* Read revision from chip */
405 data->revision = fscher_read_value(client, FSCHER_REG_REVISION);
406}
407
408static struct fscher_data *fscher_update_device(struct device *dev)
409{
410 struct i2c_client *client = to_i2c_client(dev);
411 struct fscher_data *data = i2c_get_clientdata(client);
412
413 down(&data->update_lock);
414
415 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
416
417 dev_dbg(&client->dev, "Starting fscher update\n");
418
419 data->temp_act[0] = fscher_read_value(client, FSCHER_REG_TEMP0_ACT);
420 data->temp_act[1] = fscher_read_value(client, FSCHER_REG_TEMP1_ACT);
421 data->temp_act[2] = fscher_read_value(client, FSCHER_REG_TEMP2_ACT);
422 data->temp_status[0] = fscher_read_value(client, FSCHER_REG_TEMP0_STATE);
423 data->temp_status[1] = fscher_read_value(client, FSCHER_REG_TEMP1_STATE);
424 data->temp_status[2] = fscher_read_value(client, FSCHER_REG_TEMP2_STATE);
425
426 data->volt[0] = fscher_read_value(client, FSCHER_REG_VOLT_12);
427 data->volt[1] = fscher_read_value(client, FSCHER_REG_VOLT_5);
428 data->volt[2] = fscher_read_value(client, FSCHER_REG_VOLT_BATT);
429
430 data->fan_act[0] = fscher_read_value(client, FSCHER_REG_FAN0_ACT);
431 data->fan_act[1] = fscher_read_value(client, FSCHER_REG_FAN1_ACT);
432 data->fan_act[2] = fscher_read_value(client, FSCHER_REG_FAN2_ACT);
433 data->fan_status[0] = fscher_read_value(client, FSCHER_REG_FAN0_STATE);
434 data->fan_status[1] = fscher_read_value(client, FSCHER_REG_FAN1_STATE);
435 data->fan_status[2] = fscher_read_value(client, FSCHER_REG_FAN2_STATE);
436 data->fan_min[0] = fscher_read_value(client, FSCHER_REG_FAN0_MIN);
437 data->fan_min[1] = fscher_read_value(client, FSCHER_REG_FAN1_MIN);
438 data->fan_min[2] = fscher_read_value(client, FSCHER_REG_FAN2_MIN);
439 data->fan_ripple[0] = fscher_read_value(client, FSCHER_REG_FAN0_RIPPLE);
440 data->fan_ripple[1] = fscher_read_value(client, FSCHER_REG_FAN1_RIPPLE);
441 data->fan_ripple[2] = fscher_read_value(client, FSCHER_REG_FAN2_RIPPLE);
442
443 data->watchdog[0] = fscher_read_value(client, FSCHER_REG_WDOG_PRESET);
444 data->watchdog[1] = fscher_read_value(client, FSCHER_REG_WDOG_STATE);
445 data->watchdog[2] = fscher_read_value(client, FSCHER_REG_WDOG_CONTROL);
446
447 data->global_event = fscher_read_value(client, FSCHER_REG_EVENT_STATE);
448
449 data->last_updated = jiffies;
450 data->valid = 1;
451 }
452
453 up(&data->update_lock);
454
455 return data;
456}
457
458
459
460#define FAN_INDEX_FROM_NUM(nr) ((nr) - 1)
461
462static ssize_t set_fan_status(struct i2c_client *client, struct fscher_data *data,
463 const char *buf, size_t count, int nr, int reg)
464{
465 /* bits 0..1, 3..7 reserved => mask with 0x04 */
466 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x04;
467
468 down(&data->update_lock);
469 data->fan_status[FAN_INDEX_FROM_NUM(nr)] &= ~v;
470 fscher_write_value(client, reg, v);
471 up(&data->update_lock);
472 return count;
473}
474
475static ssize_t show_fan_status(struct fscher_data *data, char *buf, int nr)
476{
477 /* bits 0..1, 3..7 reserved => mask with 0x04 */
478 return sprintf(buf, "%u\n", data->fan_status[FAN_INDEX_FROM_NUM(nr)] & 0x04);
479}
480
481static ssize_t set_pwm(struct i2c_client *client, struct fscher_data *data,
482 const char *buf, size_t count, int nr, int reg)
483{
484 unsigned long v = simple_strtoul(buf, NULL, 10);
485
486 down(&data->update_lock);
487 data->fan_min[FAN_INDEX_FROM_NUM(nr)] = v > 0xff ? 0xff : v;
488 fscher_write_value(client, reg, data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
489 up(&data->update_lock);
490 return count;
491}
492
493static ssize_t show_pwm(struct fscher_data *data, char *buf, int nr)
494{
495 return sprintf(buf, "%u\n", data->fan_min[FAN_INDEX_FROM_NUM(nr)]);
496}
497
498static ssize_t set_fan_div(struct i2c_client *client, struct fscher_data *data,
499 const char *buf, size_t count, int nr, int reg)
500{
501 /* supported values: 2, 4, 8 */
502 unsigned long v = simple_strtoul(buf, NULL, 10);
503
504 switch (v) {
505 case 2: v = 1; break;
506 case 4: v = 2; break;
507 case 8: v = 3; break;
508 default:
509 dev_err(&client->dev, "fan_div value %ld not "
510 "supported. Choose one of 2, 4 or 8!\n", v);
511 return -EINVAL;
512 }
513
514 down(&data->update_lock);
515
516 /* bits 2..7 reserved => mask with 0x03 */
517 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] &= ~0x03;
518 data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] |= v;
519
520 fscher_write_value(client, reg, data->fan_ripple[FAN_INDEX_FROM_NUM(nr)]);
521 up(&data->update_lock);
522 return count;
523}
524
525static ssize_t show_fan_div(struct fscher_data *data, char *buf, int nr)
526{
527 /* bits 2..7 reserved => mask with 0x03 */
528 return sprintf(buf, "%u\n", 1 << (data->fan_ripple[FAN_INDEX_FROM_NUM(nr)] & 0x03));
529}
530
531#define RPM_FROM_REG(val) (val*60)
532
533static ssize_t show_fan_input (struct fscher_data *data, char *buf, int nr)
534{
535 return sprintf(buf, "%u\n", RPM_FROM_REG(data->fan_act[FAN_INDEX_FROM_NUM(nr)]));
536}
537
538
539
540#define TEMP_INDEX_FROM_NUM(nr) ((nr) - 1)
541
542static ssize_t set_temp_status(struct i2c_client *client, struct fscher_data *data,
543 const char *buf, size_t count, int nr, int reg)
544{
545 /* bits 2..7 reserved, 0 read only => mask with 0x02 */
546 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
547
548 down(&data->update_lock);
549 data->temp_status[TEMP_INDEX_FROM_NUM(nr)] &= ~v;
550 fscher_write_value(client, reg, v);
551 up(&data->update_lock);
552 return count;
553}
554
555static ssize_t show_temp_status(struct fscher_data *data, char *buf, int nr)
556{
557 /* bits 2..7 reserved => mask with 0x03 */
558 return sprintf(buf, "%u\n", data->temp_status[TEMP_INDEX_FROM_NUM(nr)] & 0x03);
559}
560
561#define TEMP_FROM_REG(val) (((val) - 128) * 1000)
562
563static ssize_t show_temp_input(struct fscher_data *data, char *buf, int nr)
564{
565 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_act[TEMP_INDEX_FROM_NUM(nr)]));
566}
567
568/*
569 * The final conversion is specified in sensors.conf, as it depends on
570 * mainboard specific values. We export the registers contents as
571 * pseudo-hundredths-of-Volts (range 0V - 2.55V). Not that it makes much
572 * sense per se, but it minimizes the conversions count and keeps the
573 * values within a usual range.
574 */
575#define VOLT_FROM_REG(val) ((val) * 10)
576
577static ssize_t show_in_input(struct fscher_data *data, char *buf, int nr)
578{
579 return sprintf(buf, "%u\n", VOLT_FROM_REG(data->volt[nr]));
580}
581
582
583
584static ssize_t show_revision(struct fscher_data *data, char *buf, int nr)
585{
586 return sprintf(buf, "%u\n", data->revision);
587}
588
589
590
591static ssize_t show_alarms(struct fscher_data *data, char *buf, int nr)
592{
593 /* bits 2, 5..6 reserved => mask with 0x9b */
594 return sprintf(buf, "%u\n", data->global_event & 0x9b);
595}
596
597
598
599static ssize_t set_control(struct i2c_client *client, struct fscher_data *data,
600 const char *buf, size_t count, int nr, int reg)
601{
602 /* bits 1..7 reserved => mask with 0x01 */
603 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x01;
604
605 down(&data->update_lock);
606 data->global_control &= ~v;
607 fscher_write_value(client, reg, v);
608 up(&data->update_lock);
609 return count;
610}
611
612static ssize_t show_control(struct fscher_data *data, char *buf, int nr)
613{
614 /* bits 1..7 reserved => mask with 0x01 */
615 return sprintf(buf, "%u\n", data->global_control & 0x01);
616}
617
618
619
620static ssize_t set_watchdog_control(struct i2c_client *client, struct
621 fscher_data *data, const char *buf, size_t count,
622 int nr, int reg)
623{
624 /* bits 0..3 reserved => mask with 0xf0 */
625 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
626
627 down(&data->update_lock);
628 data->watchdog[2] &= ~0xf0;
629 data->watchdog[2] |= v;
630 fscher_write_value(client, reg, data->watchdog[2]);
631 up(&data->update_lock);
632 return count;
633}
634
635static ssize_t show_watchdog_control(struct fscher_data *data, char *buf, int nr)
636{
637 /* bits 0..3 reserved, bit 5 write only => mask with 0xd0 */
638 return sprintf(buf, "%u\n", data->watchdog[2] & 0xd0);
639}
640
641static ssize_t set_watchdog_status(struct i2c_client *client, struct fscher_data *data,
642 const char *buf, size_t count, int nr, int reg)
643{
644 /* bits 0, 2..7 reserved => mask with 0x02 */
645 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
646
647 down(&data->update_lock);
648 data->watchdog[1] &= ~v;
649 fscher_write_value(client, reg, v);
650 up(&data->update_lock);
651 return count;
652}
653
654static ssize_t show_watchdog_status(struct fscher_data *data, char *buf, int nr)
655{
656 /* bits 0, 2..7 reserved => mask with 0x02 */
657 return sprintf(buf, "%u\n", data->watchdog[1] & 0x02);
658}
659
660static ssize_t set_watchdog_preset(struct i2c_client *client, struct fscher_data *data,
661 const char *buf, size_t count, int nr, int reg)
662{
663 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
664
665 down(&data->update_lock);
666 data->watchdog[0] = v;
667 fscher_write_value(client, reg, data->watchdog[0]);
668 up(&data->update_lock);
669 return count;
670}
671
672static ssize_t show_watchdog_preset(struct fscher_data *data, char *buf, int nr)
673{
674 return sprintf(buf, "%u\n", data->watchdog[0]);
675}
676
677static int __init sensors_fscher_init(void)
678{
679 return i2c_add_driver(&fscher_driver);
680}
681
682static void __exit sensors_fscher_exit(void)
683{
684 i2c_del_driver(&fscher_driver);
685}
686
687MODULE_AUTHOR("Reinhard Nissl <rnissl@gmx.de>");
688MODULE_DESCRIPTION("FSC Hermes driver");
689MODULE_LICENSE("GPL");
690
691module_init(sensors_fscher_init);
692module_exit(sensors_fscher_exit);
diff --git a/drivers/i2c/chips/fscpos.c b/drivers/i2c/chips/fscpos.c
deleted file mode 100644
index 2cac79145c75..000000000000
--- a/drivers/i2c/chips/fscpos.c
+++ /dev/null
@@ -1,641 +0,0 @@
1/*
2 fscpos.c - Kernel module for hardware monitoring with FSC Poseidon chips
3 Copyright (C) 2004, 2005 Stefan Ott <stefan@desire.ch>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20/*
21 fujitsu siemens poseidon chip,
22 module based on the old fscpos module by Hermann Jung <hej@odn.de> and
23 the fscher module by Reinhard Nissl <rnissl@gmx.de>
24
25 original module based on lm80.c
26 Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
27 and Philip Edelbrock <phil@netroedge.com>
28
29 Thanks to Jean Delvare for reviewing my code and suggesting a lot of
30 improvements.
31*/
32
33#include <linux/module.h>
34#include <linux/slab.h>
35#include <linux/i2c.h>
36#include <linux/i2c-sensor.h>
37#include <linux/init.h>
38
39/*
40 * Addresses to scan
41 */
42static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
43static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
44
45/*
46 * Insmod parameters
47 */
48SENSORS_INSMOD_1(fscpos);
49
50/*
51 * The FSCPOS registers
52 */
53
54/* chip identification */
55#define FSCPOS_REG_IDENT_0 0x00
56#define FSCPOS_REG_IDENT_1 0x01
57#define FSCPOS_REG_IDENT_2 0x02
58#define FSCPOS_REG_REVISION 0x03
59
60/* global control and status */
61#define FSCPOS_REG_EVENT_STATE 0x04
62#define FSCPOS_REG_CONTROL 0x05
63
64/* watchdog */
65#define FSCPOS_REG_WDOG_PRESET 0x28
66#define FSCPOS_REG_WDOG_STATE 0x23
67#define FSCPOS_REG_WDOG_CONTROL 0x21
68
69/* voltages */
70#define FSCPOS_REG_VOLT_12 0x45
71#define FSCPOS_REG_VOLT_5 0x42
72#define FSCPOS_REG_VOLT_BATT 0x48
73
74/* fans - the chip does not support minimum speed for fan2 */
75static u8 FSCPOS_REG_PWM[] = { 0x55, 0x65 };
76static u8 FSCPOS_REG_FAN_ACT[] = { 0x0e, 0x6b, 0xab };
77static u8 FSCPOS_REG_FAN_STATE[] = { 0x0d, 0x62, 0xa2 };
78static u8 FSCPOS_REG_FAN_RIPPLE[] = { 0x0f, 0x6f, 0xaf };
79
80/* temperatures */
81static u8 FSCPOS_REG_TEMP_ACT[] = { 0x64, 0x32, 0x35 };
82static u8 FSCPOS_REG_TEMP_STATE[] = { 0x71, 0x81, 0x91 };
83
84/*
85 * Functions declaration
86 */
87static int fscpos_attach_adapter(struct i2c_adapter *adapter);
88static int fscpos_detect(struct i2c_adapter *adapter, int address, int kind);
89static int fscpos_detach_client(struct i2c_client *client);
90
91static int fscpos_read_value(struct i2c_client *client, u8 register);
92static int fscpos_write_value(struct i2c_client *client, u8 register, u8 value);
93static struct fscpos_data *fscpos_update_device(struct device *dev);
94static void fscpos_init_client(struct i2c_client *client);
95
96static void reset_fan_alarm(struct i2c_client *client, int nr);
97
98/*
99 * Driver data (common to all clients)
100 */
101static struct i2c_driver fscpos_driver = {
102 .owner = THIS_MODULE,
103 .name = "fscpos",
104 .id = I2C_DRIVERID_FSCPOS,
105 .flags = I2C_DF_NOTIFY,
106 .attach_adapter = fscpos_attach_adapter,
107 .detach_client = fscpos_detach_client,
108};
109
110/*
111 * Client data (each client gets its own)
112 */
113struct fscpos_data {
114 struct i2c_client client;
115 struct semaphore update_lock;
116 char valid; /* 0 until following fields are valid */
117 unsigned long last_updated; /* In jiffies */
118
119 /* register values */
120 u8 revision; /* revision of chip */
121 u8 global_event; /* global event status */
122 u8 global_control; /* global control register */
123 u8 wdog_control; /* watchdog control */
124 u8 wdog_state; /* watchdog status */
125 u8 wdog_preset; /* watchdog preset */
126 u8 volt[3]; /* 12, 5, battery current */
127 u8 temp_act[3]; /* temperature */
128 u8 temp_status[3]; /* status of sensor */
129 u8 fan_act[3]; /* fans revolutions per second */
130 u8 fan_status[3]; /* fan status */
131 u8 pwm[2]; /* fan min value for rps */
132 u8 fan_ripple[3]; /* divider for rps */
133};
134
135/* Temperature */
136#define TEMP_FROM_REG(val) (((val) - 128) * 1000)
137
138static ssize_t show_temp_input(struct fscpos_data *data, char *buf, int nr)
139{
140 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_act[nr - 1]));
141}
142
143static ssize_t show_temp_status(struct fscpos_data *data, char *buf, int nr)
144{
145 /* bits 2..7 reserved => mask with 0x03 */
146 return sprintf(buf, "%u\n", data->temp_status[nr - 1] & 0x03);
147}
148
149static ssize_t show_temp_reset(struct fscpos_data *data, char *buf, int nr)
150{
151 return sprintf(buf, "1\n");
152}
153
154static ssize_t set_temp_reset(struct i2c_client *client, struct fscpos_data
155 *data, const char *buf, size_t count, int nr, int reg)
156{
157 unsigned long v = simple_strtoul(buf, NULL, 10);
158 if (v != 1) {
159 dev_err(&client->dev, "temp_reset value %ld not supported. "
160 "Use 1 to reset the alarm!\n", v);
161 return -EINVAL;
162 }
163
164 dev_info(&client->dev, "You used the temp_reset feature which has not "
165 "been proplerly tested. Please report your "
166 "experience to the module author.\n");
167
168 /* Supported value: 2 (clears the status) */
169 fscpos_write_value(client, FSCPOS_REG_TEMP_STATE[nr], 2);
170 return count;
171}
172
173/* Fans */
174#define RPM_FROM_REG(val) ((val) * 60)
175
176static ssize_t show_fan_status(struct fscpos_data *data, char *buf, int nr)
177{
178 /* bits 0..1, 3..7 reserved => mask with 0x04 */
179 return sprintf(buf, "%u\n", data->fan_status[nr - 1] & 0x04);
180}
181
182static ssize_t show_fan_input(struct fscpos_data *data, char *buf, int nr)
183{
184 return sprintf(buf, "%u\n", RPM_FROM_REG(data->fan_act[nr - 1]));
185}
186
187static ssize_t show_fan_ripple(struct fscpos_data *data, char *buf, int nr)
188{
189 /* bits 2..7 reserved => mask with 0x03 */
190 return sprintf(buf, "%u\n", data->fan_ripple[nr - 1] & 0x03);
191}
192
193static ssize_t set_fan_ripple(struct i2c_client *client, struct fscpos_data
194 *data, const char *buf, size_t count, int nr, int reg)
195{
196 /* supported values: 2, 4, 8 */
197 unsigned long v = simple_strtoul(buf, NULL, 10);
198
199 switch (v) {
200 case 2: v = 1; break;
201 case 4: v = 2; break;
202 case 8: v = 3; break;
203 default:
204 dev_err(&client->dev, "fan_ripple value %ld not supported. "
205 "Must be one of 2, 4 or 8!\n", v);
206 return -EINVAL;
207 }
208
209 down(&data->update_lock);
210 /* bits 2..7 reserved => mask with 0x03 */
211 data->fan_ripple[nr - 1] &= ~0x03;
212 data->fan_ripple[nr - 1] |= v;
213
214 fscpos_write_value(client, reg, data->fan_ripple[nr - 1]);
215 up(&data->update_lock);
216 return count;
217}
218
219static ssize_t show_pwm(struct fscpos_data *data, char *buf, int nr)
220{
221 return sprintf(buf, "%u\n", data->pwm[nr - 1]);
222}
223
224static ssize_t set_pwm(struct i2c_client *client, struct fscpos_data *data,
225 const char *buf, size_t count, int nr, int reg)
226{
227 unsigned long v = simple_strtoul(buf, NULL, 10);
228
229 /* Range: 0..255 */
230 if (v < 0) v = 0;
231 if (v > 255) v = 255;
232
233 down(&data->update_lock);
234 data->pwm[nr - 1] = v;
235 fscpos_write_value(client, reg, data->pwm[nr - 1]);
236 up(&data->update_lock);
237 return count;
238}
239
240static void reset_fan_alarm(struct i2c_client *client, int nr)
241{
242 fscpos_write_value(client, FSCPOS_REG_FAN_STATE[nr], 4);
243}
244
245/* Volts */
246#define VOLT_FROM_REG(val, mult) ((val) * (mult) / 255)
247
248static ssize_t show_volt_12(struct device *dev, char *buf)
249{
250 struct fscpos_data *data = fscpos_update_device(dev);
251 return sprintf(buf, "%u\n", VOLT_FROM_REG(data->volt[0], 14200));
252}
253
254static ssize_t show_volt_5(struct device *dev, char *buf)
255{
256 struct fscpos_data *data = fscpos_update_device(dev);
257 return sprintf(buf, "%u\n", VOLT_FROM_REG(data->volt[1], 6600));
258}
259
260static ssize_t show_volt_batt(struct device *dev, char *buf)
261{
262 struct fscpos_data *data = fscpos_update_device(dev);
263 return sprintf(buf, "%u\n", VOLT_FROM_REG(data->volt[2], 3300));
264}
265
266/* Watchdog */
267static ssize_t show_wdog_control(struct fscpos_data *data, char *buf)
268{
269 /* bits 0..3 reserved, bit 6 write only => mask with 0xb0 */
270 return sprintf(buf, "%u\n", data->wdog_control & 0xb0);
271}
272
273static ssize_t set_wdog_control(struct i2c_client *client, struct fscpos_data
274 *data, const char *buf, size_t count, int reg)
275{
276 /* bits 0..3 reserved => mask with 0xf0 */
277 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xf0;
278
279 down(&data->update_lock);
280 data->wdog_control &= ~0xf0;
281 data->wdog_control |= v;
282 fscpos_write_value(client, reg, data->wdog_control);
283 up(&data->update_lock);
284 return count;
285}
286
287static ssize_t show_wdog_state(struct fscpos_data *data, char *buf)
288{
289 /* bits 0, 2..7 reserved => mask with 0x02 */
290 return sprintf(buf, "%u\n", data->wdog_state & 0x02);
291}
292
293static ssize_t set_wdog_state(struct i2c_client *client, struct fscpos_data
294 *data, const char *buf, size_t count, int reg)
295{
296 unsigned long v = simple_strtoul(buf, NULL, 10) & 0x02;
297
298 /* Valid values: 2 (clear) */
299 if (v != 2) {
300 dev_err(&client->dev, "wdog_state value %ld not supported. "
301 "Must be 2 to clear the state!\n", v);
302 return -EINVAL;
303 }
304
305 down(&data->update_lock);
306 data->wdog_state &= ~v;
307 fscpos_write_value(client, reg, v);
308 up(&data->update_lock);
309 return count;
310}
311
312static ssize_t show_wdog_preset(struct fscpos_data *data, char *buf)
313{
314 return sprintf(buf, "%u\n", data->wdog_preset);
315}
316
317static ssize_t set_wdog_preset(struct i2c_client *client, struct fscpos_data
318 *data, const char *buf, size_t count, int reg)
319{
320 unsigned long v = simple_strtoul(buf, NULL, 10) & 0xff;
321
322 down(&data->update_lock);
323 data->wdog_preset = v;
324 fscpos_write_value(client, reg, data->wdog_preset);
325 up(&data->update_lock);
326 return count;
327}
328
329/* Event */
330static ssize_t show_event(struct device *dev, char *buf)
331{
332 /* bits 5..7 reserved => mask with 0x1f */
333 struct fscpos_data *data = fscpos_update_device(dev);
334 return sprintf(buf, "%u\n", data->global_event & 0x9b);
335}
336
337/*
338 * Sysfs stuff
339 */
340#define create_getter(kind, sub) \
341 static ssize_t sysfs_show_##kind##sub(struct device *dev, char *buf) \
342 { \
343 struct fscpos_data *data = fscpos_update_device(dev); \
344 return show_##kind##sub(data, buf); \
345 }
346
347#define create_getter_n(kind, offset, sub) \
348 static ssize_t sysfs_show_##kind##offset##sub(struct device *dev, char\
349 *buf) \
350 { \
351 struct fscpos_data *data = fscpos_update_device(dev); \
352 return show_##kind##sub(data, buf, offset); \
353 }
354
355#define create_setter(kind, sub, reg) \
356 static ssize_t sysfs_set_##kind##sub (struct device *dev, const char \
357 *buf, size_t count) \
358 { \
359 struct i2c_client *client = to_i2c_client(dev); \
360 struct fscpos_data *data = i2c_get_clientdata(client); \
361 return set_##kind##sub(client, data, buf, count, reg); \
362 }
363
364#define create_setter_n(kind, offset, sub, reg) \
365 static ssize_t sysfs_set_##kind##offset##sub (struct device *dev, \
366 const char *buf, size_t count) \
367 { \
368 struct i2c_client *client = to_i2c_client(dev); \
369 struct fscpos_data *data = i2c_get_clientdata(client); \
370 return set_##kind##sub(client, data, buf, count, offset, reg);\
371 }
372
373#define create_sysfs_device_ro(kind, sub, offset) \
374 static DEVICE_ATTR(kind##offset##sub, S_IRUGO, \
375 sysfs_show_##kind##offset##sub, NULL);
376
377#define create_sysfs_device_rw(kind, sub, offset) \
378 static DEVICE_ATTR(kind##offset##sub, S_IRUGO | S_IWUSR, \
379 sysfs_show_##kind##offset##sub, sysfs_set_##kind##offset##sub);
380
381#define sysfs_ro_n(kind, sub, offset) \
382 create_getter_n(kind, offset, sub); \
383 create_sysfs_device_ro(kind, sub, offset);
384
385#define sysfs_rw_n(kind, sub, offset, reg) \
386 create_getter_n(kind, offset, sub); \
387 create_setter_n(kind, offset, sub, reg); \
388 create_sysfs_device_rw(kind, sub, offset);
389
390#define sysfs_rw(kind, sub, reg) \
391 create_getter(kind, sub); \
392 create_setter(kind, sub, reg); \
393 create_sysfs_device_rw(kind, sub,);
394
395#define sysfs_fan_with_min(offset, reg_status, reg_ripple, reg_min) \
396 sysfs_fan(offset, reg_status, reg_ripple); \
397 sysfs_rw_n(pwm,, offset, reg_min);
398
399#define sysfs_fan(offset, reg_status, reg_ripple) \
400 sysfs_ro_n(fan, _input, offset); \
401 sysfs_ro_n(fan, _status, offset); \
402 sysfs_rw_n(fan, _ripple, offset, reg_ripple);
403
404#define sysfs_temp(offset, reg_status) \
405 sysfs_ro_n(temp, _input, offset); \
406 sysfs_ro_n(temp, _status, offset); \
407 sysfs_rw_n(temp, _reset, offset, reg_status);
408
409#define sysfs_watchdog(reg_wdog_preset, reg_wdog_state, reg_wdog_control) \
410 sysfs_rw(wdog, _control, reg_wdog_control); \
411 sysfs_rw(wdog, _preset, reg_wdog_preset); \
412 sysfs_rw(wdog, _state, reg_wdog_state);
413
414sysfs_fan_with_min(1, FSCPOS_REG_FAN_STATE[0], FSCPOS_REG_FAN_RIPPLE[0],
415 FSCPOS_REG_PWM[0]);
416sysfs_fan_with_min(2, FSCPOS_REG_FAN_STATE[1], FSCPOS_REG_FAN_RIPPLE[1],
417 FSCPOS_REG_PWM[1]);
418sysfs_fan(3, FSCPOS_REG_FAN_STATE[2], FSCPOS_REG_FAN_RIPPLE[2]);
419
420sysfs_temp(1, FSCPOS_REG_TEMP_STATE[0]);
421sysfs_temp(2, FSCPOS_REG_TEMP_STATE[1]);
422sysfs_temp(3, FSCPOS_REG_TEMP_STATE[2]);
423
424sysfs_watchdog(FSCPOS_REG_WDOG_PRESET, FSCPOS_REG_WDOG_STATE,
425 FSCPOS_REG_WDOG_CONTROL);
426
427static DEVICE_ATTR(event, S_IRUGO, show_event, NULL);
428static DEVICE_ATTR(in0_input, S_IRUGO, show_volt_12, NULL);
429static DEVICE_ATTR(in1_input, S_IRUGO, show_volt_5, NULL);
430static DEVICE_ATTR(in2_input, S_IRUGO, show_volt_batt, NULL);
431
432static int fscpos_attach_adapter(struct i2c_adapter *adapter)
433{
434 if (!(adapter->class & I2C_CLASS_HWMON))
435 return 0;
436 return i2c_detect(adapter, &addr_data, fscpos_detect);
437}
438
439int fscpos_detect(struct i2c_adapter *adapter, int address, int kind)
440{
441 struct i2c_client *new_client;
442 struct fscpos_data *data;
443 int err = 0;
444
445 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
446 goto exit;
447
448 /*
449 * OK. For now, we presume we have a valid client. We now create the
450 * client structure, even though we cannot fill it completely yet.
451 * But it allows us to access fscpos_{read,write}_value.
452 */
453
454 if (!(data = kmalloc(sizeof(struct fscpos_data), GFP_KERNEL))) {
455 err = -ENOMEM;
456 goto exit;
457 }
458 memset(data, 0, sizeof(struct fscpos_data));
459
460 new_client = &data->client;
461 i2c_set_clientdata(new_client, data);
462 new_client->addr = address;
463 new_client->adapter = adapter;
464 new_client->driver = &fscpos_driver;
465 new_client->flags = 0;
466
467 /* Do the remaining detection unless force or force_fscpos parameter */
468 if (kind < 0) {
469 if ((fscpos_read_value(new_client, FSCPOS_REG_IDENT_0)
470 != 0x50) /* 'P' */
471 || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_1)
472 != 0x45) /* 'E' */
473 || (fscpos_read_value(new_client, FSCPOS_REG_IDENT_2)
474 != 0x47))/* 'G' */
475 {
476 dev_dbg(&new_client->dev, "fscpos detection failed\n");
477 goto exit_free;
478 }
479 }
480
481 /* Fill in the remaining client fields and put it in the global list */
482 strlcpy(new_client->name, "fscpos", I2C_NAME_SIZE);
483
484 data->valid = 0;
485 init_MUTEX(&data->update_lock);
486
487 /* Tell the I2C layer a new client has arrived */
488 if ((err = i2c_attach_client(new_client)))
489 goto exit_free;
490
491 /* Inizialize the fscpos chip */
492 fscpos_init_client(new_client);
493
494 /* Announce that the chip was found */
495 dev_info(&new_client->dev, "Found fscpos chip, rev %u\n", data->revision);
496
497 /* Register sysfs hooks */
498 device_create_file(&new_client->dev, &dev_attr_event);
499 device_create_file(&new_client->dev, &dev_attr_in0_input);
500 device_create_file(&new_client->dev, &dev_attr_in1_input);
501 device_create_file(&new_client->dev, &dev_attr_in2_input);
502 device_create_file(&new_client->dev, &dev_attr_wdog_control);
503 device_create_file(&new_client->dev, &dev_attr_wdog_preset);
504 device_create_file(&new_client->dev, &dev_attr_wdog_state);
505 device_create_file(&new_client->dev, &dev_attr_temp1_input);
506 device_create_file(&new_client->dev, &dev_attr_temp1_status);
507 device_create_file(&new_client->dev, &dev_attr_temp1_reset);
508 device_create_file(&new_client->dev, &dev_attr_temp2_input);
509 device_create_file(&new_client->dev, &dev_attr_temp2_status);
510 device_create_file(&new_client->dev, &dev_attr_temp2_reset);
511 device_create_file(&new_client->dev, &dev_attr_temp3_input);
512 device_create_file(&new_client->dev, &dev_attr_temp3_status);
513 device_create_file(&new_client->dev, &dev_attr_temp3_reset);
514 device_create_file(&new_client->dev, &dev_attr_fan1_input);
515 device_create_file(&new_client->dev, &dev_attr_fan1_status);
516 device_create_file(&new_client->dev, &dev_attr_fan1_ripple);
517 device_create_file(&new_client->dev, &dev_attr_pwm1);
518 device_create_file(&new_client->dev, &dev_attr_fan2_input);
519 device_create_file(&new_client->dev, &dev_attr_fan2_status);
520 device_create_file(&new_client->dev, &dev_attr_fan2_ripple);
521 device_create_file(&new_client->dev, &dev_attr_pwm2);
522 device_create_file(&new_client->dev, &dev_attr_fan3_input);
523 device_create_file(&new_client->dev, &dev_attr_fan3_status);
524 device_create_file(&new_client->dev, &dev_attr_fan3_ripple);
525
526 return 0;
527
528exit_free:
529 kfree(data);
530exit:
531 return err;
532}
533
534static int fscpos_detach_client(struct i2c_client *client)
535{
536 int err;
537
538 if ((err = i2c_detach_client(client))) {
539 dev_err(&client->dev, "Client deregistration failed, client"
540 " not detached.\n");
541 return err;
542 }
543 kfree(i2c_get_clientdata(client));
544 return 0;
545}
546
547static int fscpos_read_value(struct i2c_client *client, u8 reg)
548{
549 dev_dbg(&client->dev, "Read reg 0x%02x\n", reg);
550 return i2c_smbus_read_byte_data(client, reg);
551}
552
553static int fscpos_write_value(struct i2c_client *client, u8 reg, u8 value)
554{
555 dev_dbg(&client->dev, "Write reg 0x%02x, val 0x%02x\n", reg, value);
556 return i2c_smbus_write_byte_data(client, reg, value);
557}
558
559/* Called when we have found a new FSCPOS chip */
560static void fscpos_init_client(struct i2c_client *client)
561{
562 struct fscpos_data *data = i2c_get_clientdata(client);
563
564 /* read revision from chip */
565 data->revision = fscpos_read_value(client, FSCPOS_REG_REVISION);
566}
567
568static struct fscpos_data *fscpos_update_device(struct device *dev)
569{
570 struct i2c_client *client = to_i2c_client(dev);
571 struct fscpos_data *data = i2c_get_clientdata(client);
572
573 down(&data->update_lock);
574
575 if ((jiffies - data->last_updated > 2 * HZ) ||
576 (jiffies < data->last_updated) || !data->valid) {
577 int i;
578
579 dev_dbg(&client->dev, "Starting fscpos update\n");
580
581 for (i = 0; i < 3; i++) {
582 data->temp_act[i] = fscpos_read_value(client,
583 FSCPOS_REG_TEMP_ACT[i]);
584 data->temp_status[i] = fscpos_read_value(client,
585 FSCPOS_REG_TEMP_STATE[i]);
586 data->fan_act[i] = fscpos_read_value(client,
587 FSCPOS_REG_FAN_ACT[i]);
588 data->fan_status[i] = fscpos_read_value(client,
589 FSCPOS_REG_FAN_STATE[i]);
590 data->fan_ripple[i] = fscpos_read_value(client,
591 FSCPOS_REG_FAN_RIPPLE[i]);
592 if (i < 2) {
593 /* fan2_min is not supported by the chip */
594 data->pwm[i] = fscpos_read_value(client,
595 FSCPOS_REG_PWM[i]);
596 }
597 /* reset fan status if speed is back to > 0 */
598 if (data->fan_status[i] != 0 && data->fan_act[i] > 0) {
599 reset_fan_alarm(client, i);
600 }
601 }
602
603 data->volt[0] = fscpos_read_value(client, FSCPOS_REG_VOLT_12);
604 data->volt[1] = fscpos_read_value(client, FSCPOS_REG_VOLT_5);
605 data->volt[2] = fscpos_read_value(client, FSCPOS_REG_VOLT_BATT);
606
607 data->wdog_preset = fscpos_read_value(client,
608 FSCPOS_REG_WDOG_PRESET);
609 data->wdog_state = fscpos_read_value(client,
610 FSCPOS_REG_WDOG_STATE);
611 data->wdog_control = fscpos_read_value(client,
612 FSCPOS_REG_WDOG_CONTROL);
613
614 data->global_event = fscpos_read_value(client,
615 FSCPOS_REG_EVENT_STATE);
616
617 data->last_updated = jiffies;
618 data->valid = 1;
619 }
620 up(&data->update_lock);
621 return data;
622}
623
624static int __init sm_fscpos_init(void)
625{
626 return i2c_add_driver(&fscpos_driver);
627}
628
629static void __exit sm_fscpos_exit(void)
630{
631 i2c_del_driver(&fscpos_driver);
632}
633
634MODULE_AUTHOR("Stefan Ott <stefan@desire.ch> based on work from Hermann Jung "
635 "<hej@odn.de>, Frodo Looijaard <frodol@dds.nl>"
636 " and Philip Edelbrock <phil@netroedge.com>");
637MODULE_DESCRIPTION("fujitsu siemens poseidon chip driver");
638MODULE_LICENSE("GPL");
639
640module_init(sm_fscpos_init);
641module_exit(sm_fscpos_exit);
diff --git a/drivers/i2c/chips/gl518sm.c b/drivers/i2c/chips/gl518sm.c
deleted file mode 100644
index c82d6ce21205..000000000000
--- a/drivers/i2c/chips/gl518sm.c
+++ /dev/null
@@ -1,605 +0,0 @@
1/*
2 * gl518sm.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
5 * Kyosti Malkki <kmalkki@cc.hut.fi>
6 * Copyright (C) 2004 Hong-Gunn Chew <hglinux@gunnet.org> and
7 * Jean Delvare <khali@linux-fr.org>
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 * Ported to Linux 2.6 by Hong-Gunn Chew with the help of Jean Delvare
24 * and advice of Greg Kroah-Hartman.
25 *
26 * Notes about the port:
27 * Release 0x00 of the GL518SM chipset doesn't support reading of in0,
28 * in1 nor in2. The original driver had an ugly workaround to get them
29 * anyway (changing limits and watching alarms trigger and wear off).
30 * We did not keep that part of the original driver in the Linux 2.6
31 * version, since it was making the driver significantly more complex
32 * with no real benefit.
33 *
34 * History:
35 * 2004-01-28 Original port. (Hong-Gunn Chew)
36 * 2004-01-31 Code review and approval. (Jean Delvare)
37 */
38
39#include <linux/config.h>
40#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/jiffies.h>
44#include <linux/i2c.h>
45#include <linux/i2c-sensor.h>
46
47/* Addresses to scan */
48static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
49static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
50
51/* Insmod parameters */
52SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80);
53
54/* Many GL518 constants specified below */
55
56/* The GL518 registers */
57#define GL518_REG_CHIP_ID 0x00
58#define GL518_REG_REVISION 0x01
59#define GL518_REG_VENDOR_ID 0x02
60#define GL518_REG_CONF 0x03
61#define GL518_REG_TEMP_IN 0x04
62#define GL518_REG_TEMP_MAX 0x05
63#define GL518_REG_TEMP_HYST 0x06
64#define GL518_REG_FAN_COUNT 0x07
65#define GL518_REG_FAN_LIMIT 0x08
66#define GL518_REG_VIN1_LIMIT 0x09
67#define GL518_REG_VIN2_LIMIT 0x0a
68#define GL518_REG_VIN3_LIMIT 0x0b
69#define GL518_REG_VDD_LIMIT 0x0c
70#define GL518_REG_VIN3 0x0d
71#define GL518_REG_MISC 0x0f
72#define GL518_REG_ALARM 0x10
73#define GL518_REG_MASK 0x11
74#define GL518_REG_INT 0x12
75#define GL518_REG_VIN2 0x13
76#define GL518_REG_VIN1 0x14
77#define GL518_REG_VDD 0x15
78
79
80/*
81 * Conversions. Rounding and limit checking is only done on the TO_REG
82 * variants. Note that you should be a bit careful with which arguments
83 * these macros are called: arguments may be evaluated more than once.
84 * Fixing this is just not worth it.
85 */
86
87#define RAW_FROM_REG(val) val
88
89#define BOOL_FROM_REG(val) ((val)?0:1)
90#define BOOL_TO_REG(val) ((val)?0:1)
91
92#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0? \
93 (val)-500:(val)+500)/1000)+119),0,255))
94#define TEMP_FROM_REG(val) (((val) - 119) * 1000)
95
96static inline u8 FAN_TO_REG(long rpm, int div)
97{
98 long rpmdiv;
99 if (rpm == 0)
100 return 0;
101 rpmdiv = SENSORS_LIMIT(rpm, 1, 1920000) * div;
102 return SENSORS_LIMIT((960000 + rpmdiv / 2) / rpmdiv, 1, 255);
103}
104#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (960000/((val)*(div))))
105
106#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
107#define IN_FROM_REG(val) ((val)*19)
108
109#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
110#define VDD_FROM_REG(val) (((val)*95+2)/4)
111
112#define DIV_TO_REG(val) ((val)==4?2:(val)==2?1:(val)==1?0:3)
113#define DIV_FROM_REG(val) (1 << (val))
114
115#define BEEP_MASK_TO_REG(val) ((val) & 0x7f & data->alarm_mask)
116#define BEEP_MASK_FROM_REG(val) ((val) & 0x7f)
117
118/* Each client has this additional data */
119struct gl518_data {
120 struct i2c_client client;
121 enum chips type;
122
123 struct semaphore update_lock;
124 char valid; /* !=0 if following fields are valid */
125 unsigned long last_updated; /* In jiffies */
126
127 u8 voltage_in[4]; /* Register values; [0] = VDD */
128 u8 voltage_min[4]; /* Register values; [0] = VDD */
129 u8 voltage_max[4]; /* Register values; [0] = VDD */
130 u8 iter_voltage_in[4]; /* Register values; [0] = VDD */
131 u8 fan_in[2];
132 u8 fan_min[2];
133 u8 fan_div[2]; /* Register encoding, shifted right */
134 u8 fan_auto1; /* Boolean */
135 u8 temp_in; /* Register values */
136 u8 temp_max; /* Register values */
137 u8 temp_hyst; /* Register values */
138 u8 alarms; /* Register value */
139 u8 alarm_mask; /* Register value */
140 u8 beep_mask; /* Register value */
141 u8 beep_enable; /* Boolean */
142};
143
144static int gl518_attach_adapter(struct i2c_adapter *adapter);
145static int gl518_detect(struct i2c_adapter *adapter, int address, int kind);
146static void gl518_init_client(struct i2c_client *client);
147static int gl518_detach_client(struct i2c_client *client);
148static int gl518_read_value(struct i2c_client *client, u8 reg);
149static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value);
150static struct gl518_data *gl518_update_device(struct device *dev);
151
152/* This is the driver that will be inserted */
153static struct i2c_driver gl518_driver = {
154 .owner = THIS_MODULE,
155 .name = "gl518sm",
156 .id = I2C_DRIVERID_GL518,
157 .flags = I2C_DF_NOTIFY,
158 .attach_adapter = gl518_attach_adapter,
159 .detach_client = gl518_detach_client,
160};
161
162/*
163 * Sysfs stuff
164 */
165
166#define show(type, suffix, value) \
167static ssize_t show_##suffix(struct device *dev, char *buf) \
168{ \
169 struct gl518_data *data = gl518_update_device(dev); \
170 return sprintf(buf, "%d\n", type##_FROM_REG(data->value)); \
171}
172
173#define show_fan(suffix, value, index) \
174static ssize_t show_##suffix(struct device *dev, char *buf) \
175{ \
176 struct gl518_data *data = gl518_update_device(dev); \
177 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index], \
178 DIV_FROM_REG(data->fan_div[index]))); \
179}
180
181show(TEMP, temp_input1, temp_in);
182show(TEMP, temp_max1, temp_max);
183show(TEMP, temp_hyst1, temp_hyst);
184show(BOOL, fan_auto1, fan_auto1);
185show_fan(fan_input1, fan_in, 0);
186show_fan(fan_input2, fan_in, 1);
187show_fan(fan_min1, fan_min, 0);
188show_fan(fan_min2, fan_min, 1);
189show(DIV, fan_div1, fan_div[0]);
190show(DIV, fan_div2, fan_div[1]);
191show(VDD, in_input0, voltage_in[0]);
192show(IN, in_input1, voltage_in[1]);
193show(IN, in_input2, voltage_in[2]);
194show(IN, in_input3, voltage_in[3]);
195show(VDD, in_min0, voltage_min[0]);
196show(IN, in_min1, voltage_min[1]);
197show(IN, in_min2, voltage_min[2]);
198show(IN, in_min3, voltage_min[3]);
199show(VDD, in_max0, voltage_max[0]);
200show(IN, in_max1, voltage_max[1]);
201show(IN, in_max2, voltage_max[2]);
202show(IN, in_max3, voltage_max[3]);
203show(RAW, alarms, alarms);
204show(BOOL, beep_enable, beep_enable);
205show(BEEP_MASK, beep_mask, beep_mask);
206
207#define set(type, suffix, value, reg) \
208static ssize_t set_##suffix(struct device *dev, const char *buf, \
209 size_t count) \
210{ \
211 struct i2c_client *client = to_i2c_client(dev); \
212 struct gl518_data *data = i2c_get_clientdata(client); \
213 long val = simple_strtol(buf, NULL, 10); \
214 \
215 down(&data->update_lock); \
216 data->value = type##_TO_REG(val); \
217 gl518_write_value(client, reg, data->value); \
218 up(&data->update_lock); \
219 return count; \
220}
221
222#define set_bits(type, suffix, value, reg, mask, shift) \
223static ssize_t set_##suffix(struct device *dev, const char *buf, \
224 size_t count) \
225{ \
226 struct i2c_client *client = to_i2c_client(dev); \
227 struct gl518_data *data = i2c_get_clientdata(client); \
228 int regvalue; \
229 unsigned long val = simple_strtoul(buf, NULL, 10); \
230 \
231 down(&data->update_lock); \
232 regvalue = gl518_read_value(client, reg); \
233 data->value = type##_TO_REG(val); \
234 regvalue = (regvalue & ~mask) | (data->value << shift); \
235 gl518_write_value(client, reg, regvalue); \
236 up(&data->update_lock); \
237 return count; \
238}
239
240#define set_low(type, suffix, value, reg) \
241 set_bits(type, suffix, value, reg, 0x00ff, 0)
242#define set_high(type, suffix, value, reg) \
243 set_bits(type, suffix, value, reg, 0xff00, 8)
244
245set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
246set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
247set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
248set_bits(DIV, fan_div1, fan_div[0], GL518_REG_MISC, 0xc0, 6);
249set_bits(DIV, fan_div2, fan_div[1], GL518_REG_MISC, 0x30, 4);
250set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
251set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
252set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
253set_low(IN, in_min3, voltage_min[3], GL518_REG_VIN3_LIMIT);
254set_high(VDD, in_max0, voltage_max[0], GL518_REG_VDD_LIMIT);
255set_high(IN, in_max1, voltage_max[1], GL518_REG_VIN1_LIMIT);
256set_high(IN, in_max2, voltage_max[2], GL518_REG_VIN2_LIMIT);
257set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
258set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
259set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
260
261static ssize_t set_fan_min1(struct device *dev, const char *buf, size_t count)
262{
263 struct i2c_client *client = to_i2c_client(dev);
264 struct gl518_data *data = i2c_get_clientdata(client);
265 int regvalue;
266 unsigned long val = simple_strtoul(buf, NULL, 10);
267
268 down(&data->update_lock);
269 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
270 data->fan_min[0] = FAN_TO_REG(val,
271 DIV_FROM_REG(data->fan_div[0]));
272 regvalue = (regvalue & 0x00ff) | (data->fan_min[0] << 8);
273 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
274
275 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
276 if (data->fan_min[0] == 0)
277 data->alarm_mask &= ~0x20;
278 else
279 data->alarm_mask |= 0x20;
280 data->beep_mask &= data->alarm_mask;
281 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
282
283 up(&data->update_lock);
284 return count;
285}
286
287static ssize_t set_fan_min2(struct device *dev, const char *buf, size_t count)
288{
289 struct i2c_client *client = to_i2c_client(dev);
290 struct gl518_data *data = i2c_get_clientdata(client);
291 int regvalue;
292 unsigned long val = simple_strtoul(buf, NULL, 10);
293
294 down(&data->update_lock);
295 regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
296 data->fan_min[1] = FAN_TO_REG(val,
297 DIV_FROM_REG(data->fan_div[1]));
298 regvalue = (regvalue & 0xff00) | data->fan_min[1];
299 gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
300
301 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
302 if (data->fan_min[1] == 0)
303 data->alarm_mask &= ~0x40;
304 else
305 data->alarm_mask |= 0x40;
306 data->beep_mask &= data->alarm_mask;
307 gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
308
309 up(&data->update_lock);
310 return count;
311}
312
313static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
314static DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, show_temp_max1, set_temp_max1);
315static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO,
316 show_temp_hyst1, set_temp_hyst1);
317static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1);
318static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL);
319static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL);
320static DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, show_fan_min1, set_fan_min1);
321static DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, show_fan_min2, set_fan_min2);
322static DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, show_fan_div1, set_fan_div1);
323static DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, show_fan_div2, set_fan_div2);
324static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL);
325static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL);
326static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL);
327static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL);
328static DEVICE_ATTR(in0_min, S_IWUSR|S_IRUGO, show_in_min0, set_in_min0);
329static DEVICE_ATTR(in1_min, S_IWUSR|S_IRUGO, show_in_min1, set_in_min1);
330static DEVICE_ATTR(in2_min, S_IWUSR|S_IRUGO, show_in_min2, set_in_min2);
331static DEVICE_ATTR(in3_min, S_IWUSR|S_IRUGO, show_in_min3, set_in_min3);
332static DEVICE_ATTR(in0_max, S_IWUSR|S_IRUGO, show_in_max0, set_in_max0);
333static DEVICE_ATTR(in1_max, S_IWUSR|S_IRUGO, show_in_max1, set_in_max1);
334static DEVICE_ATTR(in2_max, S_IWUSR|S_IRUGO, show_in_max2, set_in_max2);
335static DEVICE_ATTR(in3_max, S_IWUSR|S_IRUGO, show_in_max3, set_in_max3);
336static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
337static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
338 show_beep_enable, set_beep_enable);
339static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
340 show_beep_mask, set_beep_mask);
341
342/*
343 * Real code
344 */
345
346static int gl518_attach_adapter(struct i2c_adapter *adapter)
347{
348 if (!(adapter->class & I2C_CLASS_HWMON))
349 return 0;
350 return i2c_detect(adapter, &addr_data, gl518_detect);
351}
352
353static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
354{
355 int i;
356 struct i2c_client *new_client;
357 struct gl518_data *data;
358 int err = 0;
359
360 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
361 I2C_FUNC_SMBUS_WORD_DATA))
362 goto exit;
363
364 /* OK. For now, we presume we have a valid client. We now create the
365 client structure, even though we cannot fill it completely yet.
366 But it allows us to access gl518_{read,write}_value. */
367
368 if (!(data = kmalloc(sizeof(struct gl518_data), GFP_KERNEL))) {
369 err = -ENOMEM;
370 goto exit;
371 }
372 memset(data, 0, sizeof(struct gl518_data));
373
374 new_client = &data->client;
375 i2c_set_clientdata(new_client, data);
376
377 new_client->addr = address;
378 new_client->adapter = adapter;
379 new_client->driver = &gl518_driver;
380 new_client->flags = 0;
381
382 /* Now, we do the remaining detection. */
383
384 if (kind < 0) {
385 if ((gl518_read_value(new_client, GL518_REG_CHIP_ID) != 0x80)
386 || (gl518_read_value(new_client, GL518_REG_CONF) & 0x80))
387 goto exit_free;
388 }
389
390 /* Determine the chip type. */
391 if (kind <= 0) {
392 i = gl518_read_value(new_client, GL518_REG_REVISION);
393 if (i == 0x00) {
394 kind = gl518sm_r00;
395 } else if (i == 0x80) {
396 kind = gl518sm_r80;
397 } else {
398 if (kind <= 0)
399 dev_info(&adapter->dev,
400 "Ignoring 'force' parameter for unknown "
401 "chip at adapter %d, address 0x%02x\n",
402 i2c_adapter_id(adapter), address);
403 goto exit_free;
404 }
405 }
406
407 /* Fill in the remaining client fields */
408 strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE);
409 data->type = kind;
410 data->valid = 0;
411 init_MUTEX(&data->update_lock);
412
413 /* Tell the I2C layer a new client has arrived */
414 if ((err = i2c_attach_client(new_client)))
415 goto exit_free;
416
417 /* Initialize the GL518SM chip */
418 data->alarm_mask = 0xff;
419 data->voltage_in[0]=data->voltage_in[1]=data->voltage_in[2]=0;
420 gl518_init_client((struct i2c_client *) new_client);
421
422 /* Register sysfs hooks */
423 device_create_file(&new_client->dev, &dev_attr_in0_input);
424 device_create_file(&new_client->dev, &dev_attr_in1_input);
425 device_create_file(&new_client->dev, &dev_attr_in2_input);
426 device_create_file(&new_client->dev, &dev_attr_in3_input);
427 device_create_file(&new_client->dev, &dev_attr_in0_min);
428 device_create_file(&new_client->dev, &dev_attr_in1_min);
429 device_create_file(&new_client->dev, &dev_attr_in2_min);
430 device_create_file(&new_client->dev, &dev_attr_in3_min);
431 device_create_file(&new_client->dev, &dev_attr_in0_max);
432 device_create_file(&new_client->dev, &dev_attr_in1_max);
433 device_create_file(&new_client->dev, &dev_attr_in2_max);
434 device_create_file(&new_client->dev, &dev_attr_in3_max);
435 device_create_file(&new_client->dev, &dev_attr_fan1_auto);
436 device_create_file(&new_client->dev, &dev_attr_fan1_input);
437 device_create_file(&new_client->dev, &dev_attr_fan2_input);
438 device_create_file(&new_client->dev, &dev_attr_fan1_min);
439 device_create_file(&new_client->dev, &dev_attr_fan2_min);
440 device_create_file(&new_client->dev, &dev_attr_fan1_div);
441 device_create_file(&new_client->dev, &dev_attr_fan2_div);
442 device_create_file(&new_client->dev, &dev_attr_temp1_input);
443 device_create_file(&new_client->dev, &dev_attr_temp1_max);
444 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
445 device_create_file(&new_client->dev, &dev_attr_alarms);
446 device_create_file(&new_client->dev, &dev_attr_beep_enable);
447 device_create_file(&new_client->dev, &dev_attr_beep_mask);
448
449 return 0;
450
451/* OK, this is not exactly good programming practice, usually. But it is
452 very code-efficient in this case. */
453
454exit_free:
455 kfree(data);
456exit:
457 return err;
458}
459
460
461/* Called when we have found a new GL518SM.
462 Note that we preserve D4:NoFan2 and D2:beep_enable. */
463static void gl518_init_client(struct i2c_client *client)
464{
465 /* Make sure we leave D7:Reset untouched */
466 u8 regvalue = gl518_read_value(client, GL518_REG_CONF) & 0x7f;
467
468 /* Comparator mode (D3=0), standby mode (D6=0) */
469 gl518_write_value(client, GL518_REG_CONF, (regvalue &= 0x37));
470
471 /* Never interrupts */
472 gl518_write_value(client, GL518_REG_MASK, 0x00);
473
474 /* Clear status register (D5=1), start (D6=1) */
475 gl518_write_value(client, GL518_REG_CONF, 0x20 | regvalue);
476 gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue);
477}
478
479static int gl518_detach_client(struct i2c_client *client)
480{
481 int err;
482
483 if ((err = i2c_detach_client(client))) {
484 dev_err(&client->dev, "Client deregistration failed, "
485 "client not detached.\n");
486 return err;
487 }
488
489 kfree(i2c_get_clientdata(client));
490
491 return 0;
492}
493
494/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
495 GL518 uses a high-byte first convention, which is exactly opposite to
496 the usual practice. */
497static int gl518_read_value(struct i2c_client *client, u8 reg)
498{
499 if ((reg >= 0x07) && (reg <= 0x0c))
500 return swab16(i2c_smbus_read_word_data(client, reg));
501 else
502 return i2c_smbus_read_byte_data(client, reg);
503}
504
505/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
506 GL518 uses a high-byte first convention, which is exactly opposite to
507 the usual practice. */
508static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
509{
510 if ((reg >= 0x07) && (reg <= 0x0c))
511 return i2c_smbus_write_word_data(client, reg, swab16(value));
512 else
513 return i2c_smbus_write_byte_data(client, reg, value);
514}
515
516static struct gl518_data *gl518_update_device(struct device *dev)
517{
518 struct i2c_client *client = to_i2c_client(dev);
519 struct gl518_data *data = i2c_get_clientdata(client);
520 int val;
521
522 down(&data->update_lock);
523
524 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
525 || !data->valid) {
526 dev_dbg(&client->dev, "Starting gl518 update\n");
527
528 data->alarms = gl518_read_value(client, GL518_REG_INT);
529 data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
530
531 val = gl518_read_value(client, GL518_REG_VDD_LIMIT);
532 data->voltage_min[0] = val & 0xff;
533 data->voltage_max[0] = (val >> 8) & 0xff;
534 val = gl518_read_value(client, GL518_REG_VIN1_LIMIT);
535 data->voltage_min[1] = val & 0xff;
536 data->voltage_max[1] = (val >> 8) & 0xff;
537 val = gl518_read_value(client, GL518_REG_VIN2_LIMIT);
538 data->voltage_min[2] = val & 0xff;
539 data->voltage_max[2] = (val >> 8) & 0xff;
540 val = gl518_read_value(client, GL518_REG_VIN3_LIMIT);
541 data->voltage_min[3] = val & 0xff;
542 data->voltage_max[3] = (val >> 8) & 0xff;
543
544 val = gl518_read_value(client, GL518_REG_FAN_COUNT);
545 data->fan_in[0] = (val >> 8) & 0xff;
546 data->fan_in[1] = val & 0xff;
547
548 val = gl518_read_value(client, GL518_REG_FAN_LIMIT);
549 data->fan_min[0] = (val >> 8) & 0xff;
550 data->fan_min[1] = val & 0xff;
551
552 data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN);
553 data->temp_max =
554 gl518_read_value(client, GL518_REG_TEMP_MAX);
555 data->temp_hyst =
556 gl518_read_value(client, GL518_REG_TEMP_HYST);
557
558 val = gl518_read_value(client, GL518_REG_MISC);
559 data->fan_div[0] = (val >> 6) & 0x03;
560 data->fan_div[1] = (val >> 4) & 0x03;
561 data->fan_auto1 = (val >> 3) & 0x01;
562
563 data->alarms &= data->alarm_mask;
564
565 val = gl518_read_value(client, GL518_REG_CONF);
566 data->beep_enable = (val >> 2) & 1;
567
568 if (data->type != gl518sm_r00) {
569 data->voltage_in[0] =
570 gl518_read_value(client, GL518_REG_VDD);
571 data->voltage_in[1] =
572 gl518_read_value(client, GL518_REG_VIN1);
573 data->voltage_in[2] =
574 gl518_read_value(client, GL518_REG_VIN2);
575 }
576 data->voltage_in[3] =
577 gl518_read_value(client, GL518_REG_VIN3);
578
579 data->last_updated = jiffies;
580 data->valid = 1;
581 }
582
583 up(&data->update_lock);
584
585 return data;
586}
587
588static int __init sensors_gl518sm_init(void)
589{
590 return i2c_add_driver(&gl518_driver);
591}
592
593static void __exit sensors_gl518sm_exit(void)
594{
595 i2c_del_driver(&gl518_driver);
596}
597
598MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
599 "Kyosti Malkki <kmalkki@cc.hut.fi> and "
600 "Hong-Gunn Chew <hglinux@gunnet.org>");
601MODULE_DESCRIPTION("GL518SM driver");
602MODULE_LICENSE("GPL");
603
604module_init(sensors_gl518sm_init);
605module_exit(sensors_gl518sm_exit);
diff --git a/drivers/i2c/chips/gl520sm.c b/drivers/i2c/chips/gl520sm.c
deleted file mode 100644
index 3fd17e46ffc6..000000000000
--- a/drivers/i2c/chips/gl520sm.c
+++ /dev/null
@@ -1,769 +0,0 @@
1/*
2 gl520sm.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
5 Kyösti Mälkki <kmalkki@cc.hut.fi>
6 Copyright (c) 2005 Maarten Deprez <maartendeprez@users.sourceforge.net>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22*/
23
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/i2c.h>
28#include <linux/i2c-sensor.h>
29#include <linux/i2c-vid.h>
30
31/* Type of the extra sensor */
32static unsigned short extra_sensor_type;
33module_param(extra_sensor_type, ushort, 0);
34MODULE_PARM_DESC(extra_sensor_type, "Type of extra sensor (0=autodetect, 1=temperature, 2=voltage)");
35
36/* Addresses to scan */
37static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
38static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
39
40/* Insmod parameters */
41SENSORS_INSMOD_1(gl520sm);
42
43/* Many GL520 constants specified below
44One of the inputs can be configured as either temp or voltage.
45That's why _TEMP2 and _IN4 access the same register
46*/
47
48/* The GL520 registers */
49#define GL520_REG_CHIP_ID 0x00
50#define GL520_REG_REVISION 0x01
51#define GL520_REG_CONF 0x03
52#define GL520_REG_MASK 0x11
53
54#define GL520_REG_VID_INPUT 0x02
55
56#define GL520_REG_IN0_INPUT 0x15
57#define GL520_REG_IN0_LIMIT 0x0c
58#define GL520_REG_IN0_MIN GL520_REG_IN0_LIMIT
59#define GL520_REG_IN0_MAX GL520_REG_IN0_LIMIT
60
61#define GL520_REG_IN1_INPUT 0x14
62#define GL520_REG_IN1_LIMIT 0x09
63#define GL520_REG_IN1_MIN GL520_REG_IN1_LIMIT
64#define GL520_REG_IN1_MAX GL520_REG_IN1_LIMIT
65
66#define GL520_REG_IN2_INPUT 0x13
67#define GL520_REG_IN2_LIMIT 0x0a
68#define GL520_REG_IN2_MIN GL520_REG_IN2_LIMIT
69#define GL520_REG_IN2_MAX GL520_REG_IN2_LIMIT
70
71#define GL520_REG_IN3_INPUT 0x0d
72#define GL520_REG_IN3_LIMIT 0x0b
73#define GL520_REG_IN3_MIN GL520_REG_IN3_LIMIT
74#define GL520_REG_IN3_MAX GL520_REG_IN3_LIMIT
75
76#define GL520_REG_IN4_INPUT 0x0e
77#define GL520_REG_IN4_MAX 0x17
78#define GL520_REG_IN4_MIN 0x18
79
80#define GL520_REG_TEMP1_INPUT 0x04
81#define GL520_REG_TEMP1_MAX 0x05
82#define GL520_REG_TEMP1_MAX_HYST 0x06
83
84#define GL520_REG_TEMP2_INPUT 0x0e
85#define GL520_REG_TEMP2_MAX 0x17
86#define GL520_REG_TEMP2_MAX_HYST 0x18
87
88#define GL520_REG_FAN_INPUT 0x07
89#define GL520_REG_FAN_MIN 0x08
90#define GL520_REG_FAN_DIV 0x0f
91#define GL520_REG_FAN_OFF GL520_REG_FAN_DIV
92
93#define GL520_REG_ALARMS 0x12
94#define GL520_REG_BEEP_MASK 0x10
95#define GL520_REG_BEEP_ENABLE GL520_REG_CONF
96
97/*
98 * Function declarations
99 */
100
101static int gl520_attach_adapter(struct i2c_adapter *adapter);
102static int gl520_detect(struct i2c_adapter *adapter, int address, int kind);
103static void gl520_init_client(struct i2c_client *client);
104static int gl520_detach_client(struct i2c_client *client);
105static int gl520_read_value(struct i2c_client *client, u8 reg);
106static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value);
107static struct gl520_data *gl520_update_device(struct device *dev);
108
109/* Driver data */
110static struct i2c_driver gl520_driver = {
111 .owner = THIS_MODULE,
112 .name = "gl520sm",
113 .id = I2C_DRIVERID_GL520,
114 .flags = I2C_DF_NOTIFY,
115 .attach_adapter = gl520_attach_adapter,
116 .detach_client = gl520_detach_client,
117};
118
119/* Client data */
120struct gl520_data {
121 struct i2c_client client;
122 struct semaphore update_lock;
123 char valid; /* zero until the following fields are valid */
124 unsigned long last_updated; /* in jiffies */
125
126 u8 vid;
127 u8 vrm;
128 u8 in_input[5]; /* [0] = VVD */
129 u8 in_min[5]; /* [0] = VDD */
130 u8 in_max[5]; /* [0] = VDD */
131 u8 fan_input[2];
132 u8 fan_min[2];
133 u8 fan_div[2];
134 u8 fan_off;
135 u8 temp_input[2];
136 u8 temp_max[2];
137 u8 temp_max_hyst[2];
138 u8 alarms;
139 u8 beep_enable;
140 u8 beep_mask;
141 u8 alarm_mask;
142 u8 two_temps;
143};
144
145/*
146 * Sysfs stuff
147 */
148
149#define sysfs_r(type, n, item, reg) \
150static ssize_t get_##type##item (struct gl520_data *, char *, int); \
151static ssize_t get_##type##n##item (struct device *, char *); \
152static ssize_t get_##type##n##item (struct device *dev, char *buf) \
153{ \
154 struct gl520_data *data = gl520_update_device(dev); \
155 return get_##type##item(data, buf, (n)); \
156}
157
158#define sysfs_w(type, n, item, reg) \
159static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
160static ssize_t set_##type##n##item (struct device *, const char *, size_t); \
161static ssize_t set_##type##n##item (struct device *dev, const char *buf, size_t count) \
162{ \
163 struct i2c_client *client = to_i2c_client(dev); \
164 struct gl520_data *data = i2c_get_clientdata(client); \
165 return set_##type##item(client, data, buf, count, (n), reg); \
166}
167
168#define sysfs_rw_n(type, n, item, reg) \
169sysfs_r(type, n, item, reg) \
170sysfs_w(type, n, item, reg) \
171static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
172
173#define sysfs_ro_n(type, n, item, reg) \
174sysfs_r(type, n, item, reg) \
175static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
176
177#define sysfs_rw(type, item, reg) \
178sysfs_r(type, 0, item, reg) \
179sysfs_w(type, 0, item, reg) \
180static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
181
182#define sysfs_ro(type, item, reg) \
183sysfs_r(type, 0, item, reg) \
184static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
185
186
187#define sysfs_vid(n) \
188sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
189
190#define device_create_file_vid(client, n) \
191device_create_file(&client->dev, &dev_attr_cpu##n##_vid)
192
193#define sysfs_in(n) \
194sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
195sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
196sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
197
198#define device_create_file_in(client, n) \
199({device_create_file(&client->dev, &dev_attr_in##n##_input); \
200device_create_file(&client->dev, &dev_attr_in##n##_min); \
201device_create_file(&client->dev, &dev_attr_in##n##_max);})
202
203#define sysfs_fan(n) \
204sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
205sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
206sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
207
208#define device_create_file_fan(client, n) \
209({device_create_file(&client->dev, &dev_attr_fan##n##_input); \
210device_create_file(&client->dev, &dev_attr_fan##n##_min); \
211device_create_file(&client->dev, &dev_attr_fan##n##_div);})
212
213#define sysfs_fan_off(n) \
214sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
215
216#define device_create_file_fan_off(client, n) \
217device_create_file(&client->dev, &dev_attr_fan##n##_off)
218
219#define sysfs_temp(n) \
220sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
221sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
222sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
223
224#define device_create_file_temp(client, n) \
225({device_create_file(&client->dev, &dev_attr_temp##n##_input); \
226device_create_file(&client->dev, &dev_attr_temp##n##_max); \
227device_create_file(&client->dev, &dev_attr_temp##n##_max_hyst);})
228
229#define sysfs_alarms() \
230sysfs_ro(alarms, , GL520_REG_ALARMS) \
231sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
232sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
233
234#define device_create_file_alarms(client) \
235({device_create_file(&client->dev, &dev_attr_alarms); \
236device_create_file(&client->dev, &dev_attr_beep_enable); \
237device_create_file(&client->dev, &dev_attr_beep_mask);})
238
239
240sysfs_vid(0)
241
242sysfs_in(0)
243sysfs_in(1)
244sysfs_in(2)
245sysfs_in(3)
246sysfs_in(4)
247
248sysfs_fan(1)
249sysfs_fan(2)
250sysfs_fan_off(1)
251
252sysfs_temp(1)
253sysfs_temp(2)
254
255sysfs_alarms()
256
257
258static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
259{
260 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
261}
262
263#define VDD_FROM_REG(val) (((val)*95+2)/4)
264#define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
265
266#define IN_FROM_REG(val) ((val)*19)
267#define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
268
269static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
270{
271 u8 r = data->in_input[n];
272
273 if (n == 0)
274 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
275 else
276 return sprintf(buf, "%d\n", IN_FROM_REG(r));
277}
278
279static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
280{
281 u8 r = data->in_min[n];
282
283 if (n == 0)
284 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
285 else
286 return sprintf(buf, "%d\n", IN_FROM_REG(r));
287}
288
289static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
290{
291 u8 r = data->in_max[n];
292
293 if (n == 0)
294 return sprintf(buf, "%d\n", VDD_FROM_REG(r));
295 else
296 return sprintf(buf, "%d\n", IN_FROM_REG(r));
297}
298
299static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
300{
301 long v = simple_strtol(buf, NULL, 10);
302 u8 r;
303
304 down(&data->update_lock);
305
306 if (n == 0)
307 r = VDD_TO_REG(v);
308 else
309 r = IN_TO_REG(v);
310
311 data->in_min[n] = r;
312
313 if (n < 4)
314 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
315 else
316 gl520_write_value(client, reg, r);
317
318 up(&data->update_lock);
319 return count;
320}
321
322static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
323{
324 long v = simple_strtol(buf, NULL, 10);
325 u8 r;
326
327 if (n == 0)
328 r = VDD_TO_REG(v);
329 else
330 r = IN_TO_REG(v);
331
332 down(&data->update_lock);
333
334 data->in_max[n] = r;
335
336 if (n < 4)
337 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
338 else
339 gl520_write_value(client, reg, r);
340
341 up(&data->update_lock);
342 return count;
343}
344
345#define DIV_FROM_REG(val) (1 << (val))
346#define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
347#define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
348
349static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n)
350{
351 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1]));
352}
353
354static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n)
355{
356 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1]));
357}
358
359static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n)
360{
361 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1]));
362}
363
364static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n)
365{
366 return sprintf(buf, "%d\n", data->fan_off);
367}
368
369static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
370{
371 unsigned long v = simple_strtoul(buf, NULL, 10);
372 u8 r;
373
374 down(&data->update_lock);
375 r = FAN_TO_REG(v, data->fan_div[n - 1]);
376 data->fan_min[n - 1] = r;
377
378 if (n == 1)
379 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
380 else
381 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
382
383 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
384 if (data->fan_min[n - 1] == 0)
385 data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40;
386 else
387 data->alarm_mask |= (n == 1) ? 0x20 : 0x40;
388 data->beep_mask &= data->alarm_mask;
389 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
390
391 up(&data->update_lock);
392 return count;
393}
394
395static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
396{
397 unsigned long v = simple_strtoul(buf, NULL, 10);
398 u8 r;
399
400 switch (v) {
401 case 1: r = 0; break;
402 case 2: r = 1; break;
403 case 4: r = 2; break;
404 case 8: r = 3; break;
405 default:
406 dev_err(&client->dev, "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n", v);
407 return -EINVAL;
408 }
409
410 down(&data->update_lock);
411 data->fan_div[n - 1] = r;
412
413 if (n == 1)
414 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6));
415 else
416 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
417
418 up(&data->update_lock);
419 return count;
420}
421
422static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
423{
424 u8 r = simple_strtoul(buf, NULL, 10)?1:0;
425
426 down(&data->update_lock);
427 data->fan_off = r;
428 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
429 up(&data->update_lock);
430 return count;
431}
432
433#define TEMP_FROM_REG(val) (((val) - 130) * 1000)
434#define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
435
436static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n)
437{
438 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1]));
439}
440
441static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n)
442{
443 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1]));
444}
445
446static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n)
447{
448 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1]));
449}
450
451static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
452{
453 long v = simple_strtol(buf, NULL, 10);
454
455 down(&data->update_lock);
456 data->temp_max[n - 1] = TEMP_TO_REG(v);;
457 gl520_write_value(client, reg, data->temp_max[n - 1]);
458 up(&data->update_lock);
459 return count;
460}
461
462static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
463{
464 long v = simple_strtol(buf, NULL, 10);
465
466 down(&data->update_lock);
467 data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
468 gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
469 up(&data->update_lock);
470 return count;
471}
472
473static ssize_t get_alarms(struct gl520_data *data, char *buf, int n)
474{
475 return sprintf(buf, "%d\n", data->alarms);
476}
477
478static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n)
479{
480 return sprintf(buf, "%d\n", data->beep_enable);
481}
482
483static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n)
484{
485 return sprintf(buf, "%d\n", data->beep_mask);
486}
487
488static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
489{
490 u8 r = simple_strtoul(buf, NULL, 10)?0:1;
491
492 down(&data->update_lock);
493 data->beep_enable = !r;
494 gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
495 up(&data->update_lock);
496 return count;
497}
498
499static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
500{
501 u8 r = simple_strtoul(buf, NULL, 10);
502
503 down(&data->update_lock);
504 r &= data->alarm_mask;
505 data->beep_mask = r;
506 gl520_write_value(client, reg, r);
507 up(&data->update_lock);
508 return count;
509}
510
511
512/*
513 * Real code
514 */
515
516static int gl520_attach_adapter(struct i2c_adapter *adapter)
517{
518 if (!(adapter->class & I2C_CLASS_HWMON))
519 return 0;
520 return i2c_detect(adapter, &addr_data, gl520_detect);
521}
522
523static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
524{
525 struct i2c_client *new_client;
526 struct gl520_data *data;
527 int err = 0;
528
529 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
530 I2C_FUNC_SMBUS_WORD_DATA))
531 goto exit;
532
533 /* OK. For now, we presume we have a valid client. We now create the
534 client structure, even though we cannot fill it completely yet.
535 But it allows us to access gl520_{read,write}_value. */
536
537 if (!(data = kmalloc(sizeof(struct gl520_data), GFP_KERNEL))) {
538 err = -ENOMEM;
539 goto exit;
540 }
541 memset(data, 0, sizeof(struct gl520_data));
542
543 new_client = &data->client;
544 i2c_set_clientdata(new_client, data);
545 new_client->addr = address;
546 new_client->adapter = adapter;
547 new_client->driver = &gl520_driver;
548 new_client->flags = 0;
549
550 /* Determine the chip type. */
551 if (kind < 0) {
552 if ((gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) ||
553 ((gl520_read_value(new_client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
554 ((gl520_read_value(new_client, GL520_REG_CONF) & 0x80) != 0x00)) {
555 dev_dbg(&new_client->dev, "Unknown chip type, skipping\n");
556 goto exit_free;
557 }
558 }
559
560 /* Fill in the remaining client fields */
561 strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE);
562 data->valid = 0;
563 init_MUTEX(&data->update_lock);
564
565 /* Tell the I2C layer a new client has arrived */
566 if ((err = i2c_attach_client(new_client)))
567 goto exit_free;
568
569 /* Initialize the GL520SM chip */
570 gl520_init_client(new_client);
571
572 /* Register sysfs hooks */
573 device_create_file_vid(new_client, 0);
574
575 device_create_file_in(new_client, 0);
576 device_create_file_in(new_client, 1);
577 device_create_file_in(new_client, 2);
578 device_create_file_in(new_client, 3);
579 if (!data->two_temps)
580 device_create_file_in(new_client, 4);
581
582 device_create_file_fan(new_client, 1);
583 device_create_file_fan(new_client, 2);
584 device_create_file_fan_off(new_client, 1);
585
586 device_create_file_temp(new_client, 1);
587 if (data->two_temps)
588 device_create_file_temp(new_client, 2);
589
590 device_create_file_alarms(new_client);
591
592 return 0;
593
594exit_free:
595 kfree(data);
596exit:
597 return err;
598}
599
600
601/* Called when we have found a new GL520SM. */
602static void gl520_init_client(struct i2c_client *client)
603{
604 struct gl520_data *data = i2c_get_clientdata(client);
605 u8 oldconf, conf;
606
607 conf = oldconf = gl520_read_value(client, GL520_REG_CONF);
608
609 data->alarm_mask = 0xff;
610 data->vrm = i2c_which_vrm();
611
612 if (extra_sensor_type == 1)
613 conf &= ~0x10;
614 else if (extra_sensor_type == 2)
615 conf |= 0x10;
616 data->two_temps = !(conf & 0x10);
617
618 /* If IRQ# is disabled, we can safely force comparator mode */
619 if (!(conf & 0x20))
620 conf &= 0xf7;
621
622 /* Enable monitoring if needed */
623 conf |= 0x40;
624
625 if (conf != oldconf)
626 gl520_write_value(client, GL520_REG_CONF, conf);
627
628 gl520_update_device(&(client->dev));
629
630 if (data->fan_min[0] == 0)
631 data->alarm_mask &= ~0x20;
632 if (data->fan_min[1] == 0)
633 data->alarm_mask &= ~0x40;
634
635 data->beep_mask &= data->alarm_mask;
636 gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
637}
638
639static int gl520_detach_client(struct i2c_client *client)
640{
641 int err;
642
643 if ((err = i2c_detach_client(client))) {
644 dev_err(&client->dev, "Client deregistration failed, "
645 "client not detached.\n");
646 return err;
647 }
648
649 kfree(i2c_get_clientdata(client));
650 return 0;
651}
652
653
654/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
655 GL520 uses a high-byte first convention */
656static int gl520_read_value(struct i2c_client *client, u8 reg)
657{
658 if ((reg >= 0x07) && (reg <= 0x0c))
659 return swab16(i2c_smbus_read_word_data(client, reg));
660 else
661 return i2c_smbus_read_byte_data(client, reg);
662}
663
664static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
665{
666 if ((reg >= 0x07) && (reg <= 0x0c))
667 return i2c_smbus_write_word_data(client, reg, swab16(value));
668 else
669 return i2c_smbus_write_byte_data(client, reg, value);
670}
671
672
673static struct gl520_data *gl520_update_device(struct device *dev)
674{
675 struct i2c_client *client = to_i2c_client(dev);
676 struct gl520_data *data = i2c_get_clientdata(client);
677 int val;
678
679 down(&data->update_lock);
680
681 if ((jiffies - data->last_updated > 2 * HZ) ||
682 (jiffies < data->last_updated) || !data->valid) {
683
684 dev_dbg(&client->dev, "Starting gl520sm update\n");
685
686 data->alarms = gl520_read_value(client, GL520_REG_ALARMS);
687 data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
688 data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
689
690 val = gl520_read_value(client, GL520_REG_IN0_LIMIT);
691 data->in_min[0] = val & 0xff;
692 data->in_max[0] = (val >> 8) & 0xff;
693 val = gl520_read_value(client, GL520_REG_IN1_LIMIT);
694 data->in_min[1] = val & 0xff;
695 data->in_max[1] = (val >> 8) & 0xff;
696 val = gl520_read_value(client, GL520_REG_IN2_LIMIT);
697 data->in_min[2] = val & 0xff;
698 data->in_max[2] = (val >> 8) & 0xff;
699 val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
700 data->in_min[3] = val & 0xff;
701 data->in_max[3] = (val >> 8) & 0xff;
702
703 val = gl520_read_value(client, GL520_REG_FAN_INPUT);
704 data->fan_input[0] = (val >> 8) & 0xff;
705 data->fan_input[1] = val & 0xff;
706
707 val = gl520_read_value(client, GL520_REG_FAN_MIN);
708 data->fan_min[0] = (val >> 8) & 0xff;
709 data->fan_min[1] = val & 0xff;
710
711 data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT);
712 data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX);
713 data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST);
714
715 val = gl520_read_value(client, GL520_REG_FAN_DIV);
716 data->fan_div[0] = (val >> 6) & 0x03;
717 data->fan_div[1] = (val >> 4) & 0x03;
718 data->fan_off = (val >> 2) & 0x01;
719
720 data->alarms &= data->alarm_mask;
721
722 val = gl520_read_value(client, GL520_REG_CONF);
723 data->beep_enable = !((val >> 2) & 1);
724
725 data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
726 data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
727 data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
728 data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
729
730 /* Temp1 and Vin4 are the same input */
731 if (data->two_temps) {
732 data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT);
733 data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX);
734 data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST);
735 } else {
736 data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT);
737 data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN);
738 data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX);
739 }
740
741 data->last_updated = jiffies;
742 data->valid = 1;
743 }
744
745 up(&data->update_lock);
746
747 return data;
748}
749
750
751static int __init sensors_gl520sm_init(void)
752{
753 return i2c_add_driver(&gl520_driver);
754}
755
756static void __exit sensors_gl520sm_exit(void)
757{
758 i2c_del_driver(&gl520_driver);
759}
760
761
762MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
763 "Kyösti Mälkki <kmalkki@cc.hut.fi>, "
764 "Maarten Deprez <maartendeprez@users.sourceforge.net>");
765MODULE_DESCRIPTION("GL520SM driver");
766MODULE_LICENSE("GPL");
767
768module_init(sensors_gl520sm_init);
769module_exit(sensors_gl520sm_exit);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 7f29a8aff165..8ee56d4b3891 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -145,7 +145,6 @@ static inline void notresponding(struct isp1301 *isp)
145static unsigned short normal_i2c[] = { 145static unsigned short normal_i2c[] = {
146 ISP_BASE, ISP_BASE + 1, 146 ISP_BASE, ISP_BASE + 1,
147 I2C_CLIENT_END }; 147 I2C_CLIENT_END };
148static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
149 148
150I2C_CLIENT_INSMOD; 149I2C_CLIENT_INSMOD;
151 150
@@ -1490,7 +1489,7 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1490 if (the_transceiver) 1489 if (the_transceiver)
1491 return 0; 1490 return 0;
1492 1491
1493 isp = kcalloc(1, sizeof *isp, GFP_KERNEL); 1492 isp = kzalloc(sizeof *isp, GFP_KERNEL);
1494 if (!isp) 1493 if (!isp)
1495 return 0; 1494 return 0;
1496 1495
diff --git a/drivers/i2c/chips/it87.c b/drivers/i2c/chips/it87.c
deleted file mode 100644
index cf7e6898754f..000000000000
--- a/drivers/i2c/chips/it87.c
+++ /dev/null
@@ -1,1208 +0,0 @@
1/*
2 it87.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring.
4
5 Supports: IT8705F Super I/O chip w/LPC interface & SMBus
6 IT8712F Super I/O chip w/LPC interface & SMBus
7 Sis950 A clone of the IT8705F
8
9 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
10 Largely inspired by lm78.c of the same package
11
12 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
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/
26
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/config.h>
35#include <linux/module.h>
36#include <linux/init.h>
37#include <linux/slab.h>
38#include <linux/jiffies.h>
39#include <linux/i2c.h>
40#include <linux/i2c-sensor.h>
41#include <linux/i2c-vid.h>
42#include <asm/io.h>
43
44
45/* Addresses to scan */
46static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
47 0x2e, 0x2f, I2C_CLIENT_END };
48static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
49
50/* Insmod parameters */
51SENSORS_INSMOD_2(it87, it8712);
52
53#define REG 0x2e /* The register to read/write */
54#define DEV 0x07 /* Register: Logical device select */
55#define VAL 0x2f /* The value to read/write */
56#define PME 0x04 /* The device with the fan registers in it */
57#define DEVID 0x20 /* Register: Device ID */
58#define DEVREV 0x22 /* Register: Device Revision */
59
60static inline int
61superio_inb(int reg)
62{
63 outb(reg, REG);
64 return inb(VAL);
65}
66
67static int superio_inw(int reg)
68{
69 int val;
70 outb(reg++, REG);
71 val = inb(VAL) << 8;
72 outb(reg, REG);
73 val |= inb(VAL);
74 return val;
75}
76
77static inline void
78superio_select(void)
79{
80 outb(DEV, REG);
81 outb(PME, VAL);
82}
83
84static inline void
85superio_enter(void)
86{
87 outb(0x87, REG);
88 outb(0x01, REG);
89 outb(0x55, REG);
90 outb(0x55, REG);
91}
92
93static inline void
94superio_exit(void)
95{
96 outb(0x02, REG);
97 outb(0x02, VAL);
98}
99
100#define IT8712F_DEVID 0x8712
101#define IT8705F_DEVID 0x8705
102#define IT87_ACT_REG 0x30
103#define IT87_BASE_REG 0x60
104
105/* Update battery voltage after every reading if true */
106static int update_vbat;
107
108/* Not all BIOSes properly configure the PWM registers */
109static int fix_pwm_polarity;
110
111/* Chip Type */
112
113static u16 chip_type;
114
115/* Many IT87 constants specified below */
116
117/* Length of ISA address segment */
118#define IT87_EXTENT 8
119
120/* Where are the ISA address/data registers relative to the base address */
121#define IT87_ADDR_REG_OFFSET 5
122#define IT87_DATA_REG_OFFSET 6
123
124/*----- The IT87 registers -----*/
125
126#define IT87_REG_CONFIG 0x00
127
128#define IT87_REG_ALARM1 0x01
129#define IT87_REG_ALARM2 0x02
130#define IT87_REG_ALARM3 0x03
131
132#define IT87_REG_VID 0x0a
133#define IT87_REG_FAN_DIV 0x0b
134
135/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
136
137#define IT87_REG_FAN(nr) (0x0d + (nr))
138#define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
139#define IT87_REG_FAN_MAIN_CTRL 0x13
140#define IT87_REG_FAN_CTL 0x14
141#define IT87_REG_PWM(nr) (0x15 + (nr))
142
143#define IT87_REG_VIN(nr) (0x20 + (nr))
144#define IT87_REG_TEMP(nr) (0x29 + (nr))
145
146#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
147#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
148#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
149#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
150
151#define IT87_REG_I2C_ADDR 0x48
152
153#define IT87_REG_VIN_ENABLE 0x50
154#define IT87_REG_TEMP_ENABLE 0x51
155
156#define IT87_REG_CHIPID 0x58
157
158#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
159#define IN_FROM_REG(val) ((val) * 16)
160
161static inline u8 FAN_TO_REG(long rpm, int div)
162{
163 if (rpm == 0)
164 return 255;
165 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
166 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
167 254);
168}
169
170#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
171
172#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
173 ((val)+500)/1000),-128,127))
174#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
175
176#define ALARMS_FROM_REG(val) (val)
177
178#define PWM_TO_REG(val) ((val) >> 1)
179#define PWM_FROM_REG(val) (((val)&0x7f) << 1)
180
181static int DIV_TO_REG(int val)
182{
183 int answer = 0;
184 while ((val >>= 1) != 0)
185 answer++;
186 return answer;
187}
188#define DIV_FROM_REG(val) (1 << (val))
189
190
191/* For each registered IT87, we need to keep some data in memory. That
192 data is pointed to by it87_list[NR]->data. The structure itself is
193 dynamically allocated, at the same time when a new it87 client is
194 allocated. */
195struct it87_data {
196 struct i2c_client client;
197 struct semaphore lock;
198 enum chips type;
199
200 struct semaphore update_lock;
201 char valid; /* !=0 if following fields are valid */
202 unsigned long last_updated; /* In jiffies */
203
204 u8 in[9]; /* Register value */
205 u8 in_max[9]; /* Register value */
206 u8 in_min[9]; /* Register value */
207 u8 fan[3]; /* Register value */
208 u8 fan_min[3]; /* Register value */
209 u8 temp[3]; /* Register value */
210 u8 temp_high[3]; /* Register value */
211 u8 temp_low[3]; /* Register value */
212 u8 sensor; /* Register value */
213 u8 fan_div[3]; /* Register encoding, shifted right */
214 u8 vid; /* Register encoding, combined */
215 int vrm;
216 u32 alarms; /* Register encoding, combined */
217 u8 fan_main_ctrl; /* Register value */
218 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
219};
220
221
222static int it87_attach_adapter(struct i2c_adapter *adapter);
223static int it87_find(int *address);
224static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
225static int it87_detach_client(struct i2c_client *client);
226
227static int it87_read_value(struct i2c_client *client, u8 register);
228static int it87_write_value(struct i2c_client *client, u8 register,
229 u8 value);
230static struct it87_data *it87_update_device(struct device *dev);
231static int it87_check_pwm(struct i2c_client *client);
232static void it87_init_client(struct i2c_client *client, struct it87_data *data);
233
234
235static struct i2c_driver it87_driver = {
236 .owner = THIS_MODULE,
237 .name = "it87",
238 .id = I2C_DRIVERID_IT87,
239 .flags = I2C_DF_NOTIFY,
240 .attach_adapter = it87_attach_adapter,
241 .detach_client = it87_detach_client,
242};
243
244static ssize_t show_in(struct device *dev, char *buf, int nr)
245{
246 struct it87_data *data = it87_update_device(dev);
247 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
248}
249
250static ssize_t show_in_min(struct device *dev, char *buf, int nr)
251{
252 struct it87_data *data = it87_update_device(dev);
253 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
254}
255
256static ssize_t show_in_max(struct device *dev, char *buf, int nr)
257{
258 struct it87_data *data = it87_update_device(dev);
259 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
260}
261
262static ssize_t set_in_min(struct device *dev, const char *buf,
263 size_t count, int nr)
264{
265 struct i2c_client *client = to_i2c_client(dev);
266 struct it87_data *data = i2c_get_clientdata(client);
267 unsigned long val = simple_strtoul(buf, NULL, 10);
268
269 down(&data->update_lock);
270 data->in_min[nr] = IN_TO_REG(val);
271 it87_write_value(client, IT87_REG_VIN_MIN(nr),
272 data->in_min[nr]);
273 up(&data->update_lock);
274 return count;
275}
276static ssize_t set_in_max(struct device *dev, const char *buf,
277 size_t count, int nr)
278{
279 struct i2c_client *client = to_i2c_client(dev);
280 struct it87_data *data = i2c_get_clientdata(client);
281 unsigned long val = simple_strtoul(buf, NULL, 10);
282
283 down(&data->update_lock);
284 data->in_max[nr] = IN_TO_REG(val);
285 it87_write_value(client, IT87_REG_VIN_MAX(nr),
286 data->in_max[nr]);
287 up(&data->update_lock);
288 return count;
289}
290
291#define show_in_offset(offset) \
292static ssize_t \
293 show_in##offset (struct device *dev, char *buf) \
294{ \
295 return show_in(dev, buf, offset); \
296} \
297static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
298
299#define limit_in_offset(offset) \
300static ssize_t \
301 show_in##offset##_min (struct device *dev, char *buf) \
302{ \
303 return show_in_min(dev, buf, offset); \
304} \
305static ssize_t \
306 show_in##offset##_max (struct device *dev, char *buf) \
307{ \
308 return show_in_max(dev, buf, offset); \
309} \
310static ssize_t set_in##offset##_min (struct device *dev, \
311 const char *buf, size_t count) \
312{ \
313 return set_in_min(dev, buf, count, offset); \
314} \
315static ssize_t set_in##offset##_max (struct device *dev, \
316 const char *buf, size_t count) \
317{ \
318 return set_in_max(dev, buf, count, offset); \
319} \
320static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
321 show_in##offset##_min, set_in##offset##_min); \
322static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
323 show_in##offset##_max, set_in##offset##_max);
324
325show_in_offset(0);
326limit_in_offset(0);
327show_in_offset(1);
328limit_in_offset(1);
329show_in_offset(2);
330limit_in_offset(2);
331show_in_offset(3);
332limit_in_offset(3);
333show_in_offset(4);
334limit_in_offset(4);
335show_in_offset(5);
336limit_in_offset(5);
337show_in_offset(6);
338limit_in_offset(6);
339show_in_offset(7);
340limit_in_offset(7);
341show_in_offset(8);
342
343/* 3 temperatures */
344static ssize_t show_temp(struct device *dev, char *buf, int nr)
345{
346 struct it87_data *data = it87_update_device(dev);
347 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
348}
349static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
350{
351 struct it87_data *data = it87_update_device(dev);
352 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
353}
354static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
355{
356 struct it87_data *data = it87_update_device(dev);
357 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
358}
359static ssize_t set_temp_max(struct device *dev, const char *buf,
360 size_t count, int nr)
361{
362 struct i2c_client *client = to_i2c_client(dev);
363 struct it87_data *data = i2c_get_clientdata(client);
364 int val = simple_strtol(buf, NULL, 10);
365
366 down(&data->update_lock);
367 data->temp_high[nr] = TEMP_TO_REG(val);
368 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
369 up(&data->update_lock);
370 return count;
371}
372static ssize_t set_temp_min(struct device *dev, const char *buf,
373 size_t count, int nr)
374{
375 struct i2c_client *client = to_i2c_client(dev);
376 struct it87_data *data = i2c_get_clientdata(client);
377 int val = simple_strtol(buf, NULL, 10);
378
379 down(&data->update_lock);
380 data->temp_low[nr] = TEMP_TO_REG(val);
381 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
382 up(&data->update_lock);
383 return count;
384}
385#define show_temp_offset(offset) \
386static ssize_t show_temp_##offset (struct device *dev, char *buf) \
387{ \
388 return show_temp(dev, buf, offset - 1); \
389} \
390static ssize_t \
391show_temp_##offset##_max (struct device *dev, char *buf) \
392{ \
393 return show_temp_max(dev, buf, offset - 1); \
394} \
395static ssize_t \
396show_temp_##offset##_min (struct device *dev, char *buf) \
397{ \
398 return show_temp_min(dev, buf, offset - 1); \
399} \
400static ssize_t set_temp_##offset##_max (struct device *dev, \
401 const char *buf, size_t count) \
402{ \
403 return set_temp_max(dev, buf, count, offset - 1); \
404} \
405static ssize_t set_temp_##offset##_min (struct device *dev, \
406 const char *buf, size_t count) \
407{ \
408 return set_temp_min(dev, buf, count, offset - 1); \
409} \
410static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL); \
411static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
412 show_temp_##offset##_max, set_temp_##offset##_max); \
413static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
414 show_temp_##offset##_min, set_temp_##offset##_min);
415
416show_temp_offset(1);
417show_temp_offset(2);
418show_temp_offset(3);
419
420static ssize_t show_sensor(struct device *dev, char *buf, int nr)
421{
422 struct it87_data *data = it87_update_device(dev);
423 u8 reg = data->sensor; /* In case the value is updated while we use it */
424
425 if (reg & (1 << nr))
426 return sprintf(buf, "3\n"); /* thermal diode */
427 if (reg & (8 << nr))
428 return sprintf(buf, "2\n"); /* thermistor */
429 return sprintf(buf, "0\n"); /* disabled */
430}
431static ssize_t set_sensor(struct device *dev, const char *buf,
432 size_t count, int nr)
433{
434 struct i2c_client *client = to_i2c_client(dev);
435 struct it87_data *data = i2c_get_clientdata(client);
436 int val = simple_strtol(buf, NULL, 10);
437
438 down(&data->update_lock);
439
440 data->sensor &= ~(1 << nr);
441 data->sensor &= ~(8 << nr);
442 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
443 if (val == 3)
444 data->sensor |= 1 << nr;
445 else if (val == 2)
446 data->sensor |= 8 << nr;
447 else if (val != 0) {
448 up(&data->update_lock);
449 return -EINVAL;
450 }
451 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
452 up(&data->update_lock);
453 return count;
454}
455#define show_sensor_offset(offset) \
456static ssize_t show_sensor_##offset (struct device *dev, char *buf) \
457{ \
458 return show_sensor(dev, buf, offset - 1); \
459} \
460static ssize_t set_sensor_##offset (struct device *dev, \
461 const char *buf, size_t count) \
462{ \
463 return set_sensor(dev, buf, count, offset - 1); \
464} \
465static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
466 show_sensor_##offset, set_sensor_##offset);
467
468show_sensor_offset(1);
469show_sensor_offset(2);
470show_sensor_offset(3);
471
472/* 3 Fans */
473static ssize_t show_fan(struct device *dev, char *buf, int nr)
474{
475 struct it87_data *data = it87_update_device(dev);
476 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
477 DIV_FROM_REG(data->fan_div[nr])));
478}
479static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
480{
481 struct it87_data *data = it87_update_device(dev);
482 return sprintf(buf,"%d\n",
483 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
484}
485static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
486{
487 struct it87_data *data = it87_update_device(dev);
488 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
489}
490static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
491{
492 struct it87_data *data = it87_update_device(dev);
493 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
494}
495static ssize_t show_pwm(struct device *dev, char *buf, int nr)
496{
497 struct it87_data *data = it87_update_device(dev);
498 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
499}
500static ssize_t set_fan_min(struct device *dev, const char *buf,
501 size_t count, int nr)
502{
503 struct i2c_client *client = to_i2c_client(dev);
504 struct it87_data *data = i2c_get_clientdata(client);
505 int val = simple_strtol(buf, NULL, 10);
506
507 down(&data->update_lock);
508 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
509 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
510 up(&data->update_lock);
511 return count;
512}
513static ssize_t set_fan_div(struct device *dev, const char *buf,
514 size_t count, int nr)
515{
516 struct i2c_client *client = to_i2c_client(dev);
517 struct it87_data *data = i2c_get_clientdata(client);
518 int val = simple_strtol(buf, NULL, 10);
519 int i, min[3];
520 u8 old;
521
522 down(&data->update_lock);
523 old = it87_read_value(client, IT87_REG_FAN_DIV);
524
525 for (i = 0; i < 3; i++)
526 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i]));
527
528 switch (nr) {
529 case 0:
530 case 1:
531 data->fan_div[nr] = DIV_TO_REG(val);
532 break;
533 case 2:
534 if (val < 8)
535 data->fan_div[nr] = 1;
536 else
537 data->fan_div[nr] = 3;
538 }
539 val = old & 0x80;
540 val |= (data->fan_div[0] & 0x07);
541 val |= (data->fan_div[1] & 0x07) << 3;
542 if (data->fan_div[2] == 3)
543 val |= 0x1 << 6;
544 it87_write_value(client, IT87_REG_FAN_DIV, val);
545
546 for (i = 0; i < 3; i++) {
547 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i]));
548 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
549 }
550 up(&data->update_lock);
551 return count;
552}
553static ssize_t set_pwm_enable(struct device *dev, const char *buf,
554 size_t count, int nr)
555{
556 struct i2c_client *client = to_i2c_client(dev);
557 struct it87_data *data = i2c_get_clientdata(client);
558 int val = simple_strtol(buf, NULL, 10);
559
560 down(&data->update_lock);
561
562 if (val == 0) {
563 int tmp;
564 /* make sure the fan is on when in on/off mode */
565 tmp = it87_read_value(client, IT87_REG_FAN_CTL);
566 it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr));
567 /* set on/off mode */
568 data->fan_main_ctrl &= ~(1 << nr);
569 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
570 } else if (val == 1) {
571 /* set SmartGuardian mode */
572 data->fan_main_ctrl |= (1 << nr);
573 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
574 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
575 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
576 } else {
577 up(&data->update_lock);
578 return -EINVAL;
579 }
580
581 up(&data->update_lock);
582 return count;
583}
584static ssize_t set_pwm(struct device *dev, const char *buf,
585 size_t count, int nr)
586{
587 struct i2c_client *client = to_i2c_client(dev);
588 struct it87_data *data = i2c_get_clientdata(client);
589 int val = simple_strtol(buf, NULL, 10);
590
591 if (val < 0 || val > 255)
592 return -EINVAL;
593
594 down(&data->update_lock);
595 data->manual_pwm_ctl[nr] = val;
596 if (data->fan_main_ctrl & (1 << nr))
597 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
598 up(&data->update_lock);
599 return count;
600}
601
602#define show_fan_offset(offset) \
603static ssize_t show_fan_##offset (struct device *dev, char *buf) \
604{ \
605 return show_fan(dev, buf, offset - 1); \
606} \
607static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
608{ \
609 return show_fan_min(dev, buf, offset - 1); \
610} \
611static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
612{ \
613 return show_fan_div(dev, buf, offset - 1); \
614} \
615static ssize_t set_fan_##offset##_min (struct device *dev, \
616 const char *buf, size_t count) \
617{ \
618 return set_fan_min(dev, buf, count, offset - 1); \
619} \
620static ssize_t set_fan_##offset##_div (struct device *dev, \
621 const char *buf, size_t count) \
622{ \
623 return set_fan_div(dev, buf, count, offset - 1); \
624} \
625static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL); \
626static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
627 show_fan_##offset##_min, set_fan_##offset##_min); \
628static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
629 show_fan_##offset##_div, set_fan_##offset##_div);
630
631show_fan_offset(1);
632show_fan_offset(2);
633show_fan_offset(3);
634
635#define show_pwm_offset(offset) \
636static ssize_t show_pwm##offset##_enable (struct device *dev, \
637 char *buf) \
638{ \
639 return show_pwm_enable(dev, buf, offset - 1); \
640} \
641static ssize_t show_pwm##offset (struct device *dev, char *buf) \
642{ \
643 return show_pwm(dev, buf, offset - 1); \
644} \
645static ssize_t set_pwm##offset##_enable (struct device *dev, \
646 const char *buf, size_t count) \
647{ \
648 return set_pwm_enable(dev, buf, count, offset - 1); \
649} \
650static ssize_t set_pwm##offset (struct device *dev, \
651 const char *buf, size_t count) \
652{ \
653 return set_pwm(dev, buf, count, offset - 1); \
654} \
655static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
656 show_pwm##offset##_enable, \
657 set_pwm##offset##_enable); \
658static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
659 show_pwm##offset , set_pwm##offset );
660
661show_pwm_offset(1);
662show_pwm_offset(2);
663show_pwm_offset(3);
664
665/* Alarms */
666static ssize_t show_alarms(struct device *dev, char *buf)
667{
668 struct it87_data *data = it87_update_device(dev);
669 return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms));
670}
671static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
672
673static ssize_t
674show_vrm_reg(struct device *dev, char *buf)
675{
676 struct it87_data *data = it87_update_device(dev);
677 return sprintf(buf, "%ld\n", (long) data->vrm);
678}
679static ssize_t
680store_vrm_reg(struct device *dev, const char *buf, size_t count)
681{
682 struct i2c_client *client = to_i2c_client(dev);
683 struct it87_data *data = i2c_get_clientdata(client);
684 u32 val;
685
686 val = simple_strtoul(buf, NULL, 10);
687 data->vrm = val;
688
689 return count;
690}
691static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
692#define device_create_file_vrm(client) \
693device_create_file(&client->dev, &dev_attr_vrm)
694
695static ssize_t
696show_vid_reg(struct device *dev, char *buf)
697{
698 struct it87_data *data = it87_update_device(dev);
699 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
700}
701static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
702#define device_create_file_vid(client) \
703device_create_file(&client->dev, &dev_attr_cpu0_vid)
704
705/* This function is called when:
706 * it87_driver is inserted (when this module is loaded), for each
707 available adapter
708 * when a new adapter is inserted (and it87_driver is still present) */
709static int it87_attach_adapter(struct i2c_adapter *adapter)
710{
711 if (!(adapter->class & I2C_CLASS_HWMON))
712 return 0;
713 return i2c_detect(adapter, &addr_data, it87_detect);
714}
715
716/* SuperIO detection - will change normal_isa[0] if a chip is found */
717static int it87_find(int *address)
718{
719 int err = -ENODEV;
720
721 superio_enter();
722 chip_type = superio_inw(DEVID);
723 if (chip_type != IT8712F_DEVID
724 && chip_type != IT8705F_DEVID)
725 goto exit;
726
727 superio_select();
728 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
729 pr_info("it87: Device not activated, skipping\n");
730 goto exit;
731 }
732
733 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
734 if (*address == 0) {
735 pr_info("it87: Base address not set, skipping\n");
736 goto exit;
737 }
738
739 err = 0;
740 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
741 chip_type, *address, superio_inb(DEVREV) & 0x0f);
742
743exit:
744 superio_exit();
745 return err;
746}
747
748/* This function is called by i2c_detect */
749int it87_detect(struct i2c_adapter *adapter, int address, int kind)
750{
751 int i;
752 struct i2c_client *new_client;
753 struct it87_data *data;
754 int err = 0;
755 const char *name = "";
756 int is_isa = i2c_is_isa_adapter(adapter);
757 int enable_pwm_interface;
758
759 if (!is_isa &&
760 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
761 goto ERROR0;
762
763 /* Reserve the ISA region */
764 if (is_isa)
765 if (!request_region(address, IT87_EXTENT, it87_driver.name))
766 goto ERROR0;
767
768 /* Probe whether there is anything available on this address. Already
769 done for SMBus and Super-I/O clients */
770 if (kind < 0) {
771 if (is_isa && !chip_type) {
772#define REALLY_SLOW_IO
773 /* We need the timeouts for at least some IT87-like chips. But only
774 if we read 'undefined' registers. */
775 i = inb_p(address + 1);
776 if (inb_p(address + 2) != i
777 || inb_p(address + 3) != i
778 || inb_p(address + 7) != i) {
779 err = -ENODEV;
780 goto ERROR1;
781 }
782#undef REALLY_SLOW_IO
783
784 /* Let's just hope nothing breaks here */
785 i = inb_p(address + 5) & 0x7f;
786 outb_p(~i & 0x7f, address + 5);
787 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
788 outb_p(i, address + 5);
789 err = -ENODEV;
790 goto ERROR1;
791 }
792 }
793 }
794
795 /* OK. For now, we presume we have a valid client. We now create the
796 client structure, even though we cannot fill it completely yet.
797 But it allows us to access it87_{read,write}_value. */
798
799 if (!(data = kmalloc(sizeof(struct it87_data), GFP_KERNEL))) {
800 err = -ENOMEM;
801 goto ERROR1;
802 }
803 memset(data, 0, sizeof(struct it87_data));
804
805 new_client = &data->client;
806 if (is_isa)
807 init_MUTEX(&data->lock);
808 i2c_set_clientdata(new_client, data);
809 new_client->addr = address;
810 new_client->adapter = adapter;
811 new_client->driver = &it87_driver;
812 new_client->flags = 0;
813
814 /* Now, we do the remaining detection. */
815
816 if (kind < 0) {
817 if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80)
818 || (!is_isa
819 && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) {
820 err = -ENODEV;
821 goto ERROR2;
822 }
823 }
824
825 /* Determine the chip type. */
826 if (kind <= 0) {
827 i = it87_read_value(new_client, IT87_REG_CHIPID);
828 if (i == 0x90) {
829 kind = it87;
830 if ((is_isa) && (chip_type == IT8712F_DEVID))
831 kind = it8712;
832 }
833 else {
834 if (kind == 0)
835 dev_info(&adapter->dev,
836 "Ignoring 'force' parameter for unknown chip at "
837 "adapter %d, address 0x%02x\n",
838 i2c_adapter_id(adapter), address);
839 err = -ENODEV;
840 goto ERROR2;
841 }
842 }
843
844 if (kind == it87) {
845 name = "it87";
846 } else if (kind == it8712) {
847 name = "it8712";
848 }
849
850 /* Fill in the remaining client fields and put it into the global list */
851 strlcpy(new_client->name, name, I2C_NAME_SIZE);
852 data->type = kind;
853 data->valid = 0;
854 init_MUTEX(&data->update_lock);
855
856 /* Tell the I2C layer a new client has arrived */
857 if ((err = i2c_attach_client(new_client)))
858 goto ERROR2;
859
860 /* Check PWM configuration */
861 enable_pwm_interface = it87_check_pwm(new_client);
862
863 /* Initialize the IT87 chip */
864 it87_init_client(new_client, data);
865
866 /* Register sysfs hooks */
867 device_create_file(&new_client->dev, &dev_attr_in0_input);
868 device_create_file(&new_client->dev, &dev_attr_in1_input);
869 device_create_file(&new_client->dev, &dev_attr_in2_input);
870 device_create_file(&new_client->dev, &dev_attr_in3_input);
871 device_create_file(&new_client->dev, &dev_attr_in4_input);
872 device_create_file(&new_client->dev, &dev_attr_in5_input);
873 device_create_file(&new_client->dev, &dev_attr_in6_input);
874 device_create_file(&new_client->dev, &dev_attr_in7_input);
875 device_create_file(&new_client->dev, &dev_attr_in8_input);
876 device_create_file(&new_client->dev, &dev_attr_in0_min);
877 device_create_file(&new_client->dev, &dev_attr_in1_min);
878 device_create_file(&new_client->dev, &dev_attr_in2_min);
879 device_create_file(&new_client->dev, &dev_attr_in3_min);
880 device_create_file(&new_client->dev, &dev_attr_in4_min);
881 device_create_file(&new_client->dev, &dev_attr_in5_min);
882 device_create_file(&new_client->dev, &dev_attr_in6_min);
883 device_create_file(&new_client->dev, &dev_attr_in7_min);
884 device_create_file(&new_client->dev, &dev_attr_in0_max);
885 device_create_file(&new_client->dev, &dev_attr_in1_max);
886 device_create_file(&new_client->dev, &dev_attr_in2_max);
887 device_create_file(&new_client->dev, &dev_attr_in3_max);
888 device_create_file(&new_client->dev, &dev_attr_in4_max);
889 device_create_file(&new_client->dev, &dev_attr_in5_max);
890 device_create_file(&new_client->dev, &dev_attr_in6_max);
891 device_create_file(&new_client->dev, &dev_attr_in7_max);
892 device_create_file(&new_client->dev, &dev_attr_temp1_input);
893 device_create_file(&new_client->dev, &dev_attr_temp2_input);
894 device_create_file(&new_client->dev, &dev_attr_temp3_input);
895 device_create_file(&new_client->dev, &dev_attr_temp1_max);
896 device_create_file(&new_client->dev, &dev_attr_temp2_max);
897 device_create_file(&new_client->dev, &dev_attr_temp3_max);
898 device_create_file(&new_client->dev, &dev_attr_temp1_min);
899 device_create_file(&new_client->dev, &dev_attr_temp2_min);
900 device_create_file(&new_client->dev, &dev_attr_temp3_min);
901 device_create_file(&new_client->dev, &dev_attr_temp1_type);
902 device_create_file(&new_client->dev, &dev_attr_temp2_type);
903 device_create_file(&new_client->dev, &dev_attr_temp3_type);
904 device_create_file(&new_client->dev, &dev_attr_fan1_input);
905 device_create_file(&new_client->dev, &dev_attr_fan2_input);
906 device_create_file(&new_client->dev, &dev_attr_fan3_input);
907 device_create_file(&new_client->dev, &dev_attr_fan1_min);
908 device_create_file(&new_client->dev, &dev_attr_fan2_min);
909 device_create_file(&new_client->dev, &dev_attr_fan3_min);
910 device_create_file(&new_client->dev, &dev_attr_fan1_div);
911 device_create_file(&new_client->dev, &dev_attr_fan2_div);
912 device_create_file(&new_client->dev, &dev_attr_fan3_div);
913 device_create_file(&new_client->dev, &dev_attr_alarms);
914 if (enable_pwm_interface) {
915 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
916 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
917 device_create_file(&new_client->dev, &dev_attr_pwm3_enable);
918 device_create_file(&new_client->dev, &dev_attr_pwm1);
919 device_create_file(&new_client->dev, &dev_attr_pwm2);
920 device_create_file(&new_client->dev, &dev_attr_pwm3);
921 }
922
923 if (data->type == it8712) {
924 data->vrm = i2c_which_vrm();
925 device_create_file_vrm(new_client);
926 device_create_file_vid(new_client);
927 }
928
929 return 0;
930
931ERROR2:
932 kfree(data);
933ERROR1:
934 if (is_isa)
935 release_region(address, IT87_EXTENT);
936ERROR0:
937 return err;
938}
939
940static int it87_detach_client(struct i2c_client *client)
941{
942 int err;
943
944 if ((err = i2c_detach_client(client))) {
945 dev_err(&client->dev,
946 "Client deregistration failed, client not detached.\n");
947 return err;
948 }
949
950 if(i2c_is_isa_client(client))
951 release_region(client->addr, IT87_EXTENT);
952 kfree(i2c_get_clientdata(client));
953
954 return 0;
955}
956
957/* The SMBus locks itself, but ISA access must be locked explicitely!
958 We don't want to lock the whole ISA bus, so we lock each client
959 separately.
960 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
961 would slow down the IT87 access and should not be necessary. */
962static int it87_read_value(struct i2c_client *client, u8 reg)
963{
964 struct it87_data *data = i2c_get_clientdata(client);
965
966 int res;
967 if (i2c_is_isa_client(client)) {
968 down(&data->lock);
969 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
970 res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
971 up(&data->lock);
972 return res;
973 } else
974 return i2c_smbus_read_byte_data(client, reg);
975}
976
977/* The SMBus locks itself, but ISA access muse be locked explicitely!
978 We don't want to lock the whole ISA bus, so we lock each client
979 separately.
980 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
981 would slow down the IT87 access and should not be necessary. */
982static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
983{
984 struct it87_data *data = i2c_get_clientdata(client);
985
986 if (i2c_is_isa_client(client)) {
987 down(&data->lock);
988 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
989 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
990 up(&data->lock);
991 return 0;
992 } else
993 return i2c_smbus_write_byte_data(client, reg, value);
994}
995
996/* Return 1 if and only if the PWM interface is safe to use */
997static int it87_check_pwm(struct i2c_client *client)
998{
999 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1000 * and polarity set to active low is sign that this is the case so we
1001 * disable pwm control to protect the user. */
1002 int tmp = it87_read_value(client, IT87_REG_FAN_CTL);
1003 if ((tmp & 0x87) == 0) {
1004 if (fix_pwm_polarity) {
1005 /* The user asks us to attempt a chip reconfiguration.
1006 * This means switching to active high polarity and
1007 * inverting all fan speed values. */
1008 int i;
1009 u8 pwm[3];
1010
1011 for (i = 0; i < 3; i++)
1012 pwm[i] = it87_read_value(client,
1013 IT87_REG_PWM(i));
1014
1015 /* If any fan is in automatic pwm mode, the polarity
1016 * might be correct, as suspicious as it seems, so we
1017 * better don't change anything (but still disable the
1018 * PWM interface). */
1019 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1020 dev_info(&client->dev, "Reconfiguring PWM to "
1021 "active high polarity\n");
1022 it87_write_value(client, IT87_REG_FAN_CTL,
1023 tmp | 0x87);
1024 for (i = 0; i < 3; i++)
1025 it87_write_value(client,
1026 IT87_REG_PWM(i),
1027 0x7f & ~pwm[i]);
1028 return 1;
1029 }
1030
1031 dev_info(&client->dev, "PWM configuration is "
1032 "too broken to be fixed\n");
1033 }
1034
1035 dev_info(&client->dev, "Detected broken BIOS "
1036 "defaults, disabling PWM interface\n");
1037 return 0;
1038 } else if (fix_pwm_polarity) {
1039 dev_info(&client->dev, "PWM configuration looks "
1040 "sane, won't touch\n");
1041 }
1042
1043 return 1;
1044}
1045
1046/* Called when we have found a new IT87. */
1047static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1048{
1049 int tmp, i;
1050
1051 /* initialize to sane defaults:
1052 * - if the chip is in manual pwm mode, this will be overwritten with
1053 * the actual settings on the chip (so in this case, initialization
1054 * is not needed)
1055 * - if in automatic or on/off mode, we could switch to manual mode,
1056 * read the registers and set manual_pwm_ctl accordingly, but currently
1057 * this is not implemented, so we initialize to something sane */
1058 for (i = 0; i < 3; i++) {
1059 data->manual_pwm_ctl[i] = 0xff;
1060 }
1061
1062 /* Check if temperature channnels are reset manually or by some reason */
1063 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1064 if ((tmp & 0x3f) == 0) {
1065 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1066 tmp = (tmp & 0xc0) | 0x2a;
1067 it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp);
1068 }
1069 data->sensor = tmp;
1070
1071 /* Check if voltage monitors are reset manually or by some reason */
1072 tmp = it87_read_value(client, IT87_REG_VIN_ENABLE);
1073 if ((tmp & 0xff) == 0) {
1074 /* Enable all voltage monitors */
1075 it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff);
1076 }
1077
1078 /* Check if tachometers are reset manually or by some reason */
1079 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1080 if ((data->fan_main_ctrl & 0x70) == 0) {
1081 /* Enable all fan tachometers */
1082 data->fan_main_ctrl |= 0x70;
1083 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1084 }
1085
1086 /* Set current fan mode registers and the default settings for the
1087 * other mode registers */
1088 for (i = 0; i < 3; i++) {
1089 if (data->fan_main_ctrl & (1 << i)) {
1090 /* pwm mode */
1091 tmp = it87_read_value(client, IT87_REG_PWM(i));
1092 if (tmp & 0x80) {
1093 /* automatic pwm - not yet implemented, but
1094 * leave the settings made by the BIOS alone
1095 * until a change is requested via the sysfs
1096 * interface */
1097 } else {
1098 /* manual pwm */
1099 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1100 }
1101 }
1102 }
1103
1104 /* Start monitoring */
1105 it87_write_value(client, IT87_REG_CONFIG,
1106 (it87_read_value(client, IT87_REG_CONFIG) & 0x36)
1107 | (update_vbat ? 0x41 : 0x01));
1108}
1109
1110static struct it87_data *it87_update_device(struct device *dev)
1111{
1112 struct i2c_client *client = to_i2c_client(dev);
1113 struct it87_data *data = i2c_get_clientdata(client);
1114 int i;
1115
1116 down(&data->update_lock);
1117
1118 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1119 || !data->valid) {
1120
1121 if (update_vbat) {
1122 /* Cleared after each update, so reenable. Value
1123 returned by this read will be previous value */
1124 it87_write_value(client, IT87_REG_CONFIG,
1125 it87_read_value(client, IT87_REG_CONFIG) | 0x40);
1126 }
1127 for (i = 0; i <= 7; i++) {
1128 data->in[i] =
1129 it87_read_value(client, IT87_REG_VIN(i));
1130 data->in_min[i] =
1131 it87_read_value(client, IT87_REG_VIN_MIN(i));
1132 data->in_max[i] =
1133 it87_read_value(client, IT87_REG_VIN_MAX(i));
1134 }
1135 data->in[8] =
1136 it87_read_value(client, IT87_REG_VIN(8));
1137 /* Temperature sensor doesn't have limit registers, set
1138 to min and max value */
1139 data->in_min[8] = 0;
1140 data->in_max[8] = 255;
1141
1142 for (i = 0; i < 3; i++) {
1143 data->fan[i] =
1144 it87_read_value(client, IT87_REG_FAN(i));
1145 data->fan_min[i] =
1146 it87_read_value(client, IT87_REG_FAN_MIN(i));
1147 }
1148 for (i = 0; i < 3; i++) {
1149 data->temp[i] =
1150 it87_read_value(client, IT87_REG_TEMP(i));
1151 data->temp_high[i] =
1152 it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1153 data->temp_low[i] =
1154 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1155 }
1156
1157 i = it87_read_value(client, IT87_REG_FAN_DIV);
1158 data->fan_div[0] = i & 0x07;
1159 data->fan_div[1] = (i >> 3) & 0x07;
1160 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1161
1162 data->alarms =
1163 it87_read_value(client, IT87_REG_ALARM1) |
1164 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
1165 (it87_read_value(client, IT87_REG_ALARM3) << 16);
1166 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1167
1168 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1169 /* The 8705 does not have VID capability */
1170 if (data->type == it8712) {
1171 data->vid = it87_read_value(client, IT87_REG_VID);
1172 data->vid &= 0x1f;
1173 }
1174 data->last_updated = jiffies;
1175 data->valid = 1;
1176 }
1177
1178 up(&data->update_lock);
1179
1180 return data;
1181}
1182
1183static int __init sm_it87_init(void)
1184{
1185 int addr;
1186
1187 if (!it87_find(&addr)) {
1188 normal_isa[0] = addr;
1189 }
1190 return i2c_add_driver(&it87_driver);
1191}
1192
1193static void __exit sm_it87_exit(void)
1194{
1195 i2c_del_driver(&it87_driver);
1196}
1197
1198
1199MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>");
1200MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver");
1201module_param(update_vbat, bool, 0);
1202MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1203module_param(fix_pwm_polarity, bool, 0);
1204MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1205MODULE_LICENSE("GPL");
1206
1207module_init(sm_it87_init);
1208module_exit(sm_it87_exit);
diff --git a/drivers/i2c/chips/lm63.c b/drivers/i2c/chips/lm63.c
deleted file mode 100644
index 14cc5af03739..000000000000
--- a/drivers/i2c/chips/lm63.c
+++ /dev/null
@@ -1,581 +0,0 @@
1/*
2 * lm63.c - driver for the National Semiconductor LM63 temperature sensor
3 * with integrated fan control
4 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
5 * Based on the lm90 driver.
6 *
7 * The LM63 is a sensor chip made by National Semiconductor. It measures
8 * two temperatures (its own and one external one) and the speed of one
9 * fan, those speed it can additionally control. Complete datasheet can be
10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM63.html
12 *
13 * The LM63 is basically an LM86 with fan speed monitoring and control
14 * capabilities added. It misses some of the LM86 features though:
15 * - No low limit for local temperature.
16 * - No critical limit for local temperature.
17 * - Critical limit for remote temperature can be changed only once. We
18 * will consider that the critical limit is read-only.
19 *
20 * The datasheet isn't very clear about what the tachometer reading is.
21 * I had a explanation from National Semiconductor though. The two lower
22 * bits of the read value have to be masked out. The value is still 16 bit
23 * in width.
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38 */
39
40#include <linux/config.h>
41#include <linux/module.h>
42#include <linux/init.h>
43#include <linux/slab.h>
44#include <linux/jiffies.h>
45#include <linux/i2c.h>
46#include <linux/i2c-sensor.h>
47
48/*
49 * Addresses to scan
50 * Address is fully defined internally and cannot be changed.
51 */
52
53static unsigned short normal_i2c[] = { 0x4c, I2C_CLIENT_END };
54static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
55
56/*
57 * Insmod parameters
58 */
59
60SENSORS_INSMOD_1(lm63);
61
62/*
63 * The LM63 registers
64 */
65
66#define LM63_REG_CONFIG1 0x03
67#define LM63_REG_CONFIG2 0xBF
68#define LM63_REG_CONFIG_FAN 0x4A
69
70#define LM63_REG_TACH_COUNT_MSB 0x47
71#define LM63_REG_TACH_COUNT_LSB 0x46
72#define LM63_REG_TACH_LIMIT_MSB 0x49
73#define LM63_REG_TACH_LIMIT_LSB 0x48
74
75#define LM63_REG_PWM_VALUE 0x4C
76#define LM63_REG_PWM_FREQ 0x4D
77
78#define LM63_REG_LOCAL_TEMP 0x00
79#define LM63_REG_LOCAL_HIGH 0x05
80
81#define LM63_REG_REMOTE_TEMP_MSB 0x01
82#define LM63_REG_REMOTE_TEMP_LSB 0x10
83#define LM63_REG_REMOTE_OFFSET_MSB 0x11
84#define LM63_REG_REMOTE_OFFSET_LSB 0x12
85#define LM63_REG_REMOTE_HIGH_MSB 0x07
86#define LM63_REG_REMOTE_HIGH_LSB 0x13
87#define LM63_REG_REMOTE_LOW_MSB 0x08
88#define LM63_REG_REMOTE_LOW_LSB 0x14
89#define LM63_REG_REMOTE_TCRIT 0x19
90#define LM63_REG_REMOTE_TCRIT_HYST 0x21
91
92#define LM63_REG_ALERT_STATUS 0x02
93#define LM63_REG_ALERT_MASK 0x16
94
95#define LM63_REG_MAN_ID 0xFE
96#define LM63_REG_CHIP_ID 0xFF
97
98/*
99 * Conversions and various macros
100 * For tachometer counts, the LM63 uses 16-bit values.
101 * For local temperature and high limit, remote critical limit and hysteresis
102 * value, it uses signed 8-bit values with LSB = 1 degree Celcius.
103 * For remote temperature, low and high limits, it uses signed 11-bit values
104 * with LSB = 0.125 degree Celcius, left-justified in 16-bit registers.
105 */
106
107#define FAN_FROM_REG(reg) ((reg) == 0xFFFC || (reg) == 0 ? 0 : \
108 5400000 / (reg))
109#define FAN_TO_REG(val) ((val) <= 82 ? 0xFFFC : \
110 (5400000 / (val)) & 0xFFFC)
111#define TEMP8_FROM_REG(reg) ((reg) * 1000)
112#define TEMP8_TO_REG(val) ((val) <= -128000 ? -128 : \
113 (val) >= 127000 ? 127 : \
114 (val) < 0 ? ((val) - 500) / 1000 : \
115 ((val) + 500) / 1000)
116#define TEMP11_FROM_REG(reg) ((reg) / 32 * 125)
117#define TEMP11_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
118 (val) >= 127875 ? 0x7FE0 : \
119 (val) < 0 ? ((val) - 62) / 125 * 32 : \
120 ((val) + 62) / 125 * 32)
121#define HYST_TO_REG(val) ((val) <= 0 ? 0 : \
122 (val) >= 127000 ? 127 : \
123 ((val) + 500) / 1000)
124
125/*
126 * Functions declaration
127 */
128
129static int lm63_attach_adapter(struct i2c_adapter *adapter);
130static int lm63_detach_client(struct i2c_client *client);
131
132static struct lm63_data *lm63_update_device(struct device *dev);
133
134static int lm63_detect(struct i2c_adapter *adapter, int address, int kind);
135static void lm63_init_client(struct i2c_client *client);
136
137/*
138 * Driver data (common to all clients)
139 */
140
141static struct i2c_driver lm63_driver = {
142 .owner = THIS_MODULE,
143 .name = "lm63",
144 .flags = I2C_DF_NOTIFY,
145 .attach_adapter = lm63_attach_adapter,
146 .detach_client = lm63_detach_client,
147};
148
149/*
150 * Client data (each client gets its own)
151 */
152
153struct lm63_data {
154 struct i2c_client client;
155 struct semaphore update_lock;
156 char valid; /* zero until following fields are valid */
157 unsigned long last_updated; /* in jiffies */
158
159 /* registers values */
160 u8 config, config_fan;
161 u16 fan1_input;
162 u16 fan1_low;
163 u8 pwm1_freq;
164 u8 pwm1_value;
165 s8 temp1_input;
166 s8 temp1_high;
167 s16 temp2_input;
168 s16 temp2_high;
169 s16 temp2_low;
170 s8 temp2_crit;
171 u8 temp2_crit_hyst;
172 u8 alarms;
173};
174
175/*
176 * Sysfs callback functions and files
177 */
178
179#define show_fan(value) \
180static ssize_t show_##value(struct device *dev, char *buf) \
181{ \
182 struct lm63_data *data = lm63_update_device(dev); \
183 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value)); \
184}
185show_fan(fan1_input);
186show_fan(fan1_low);
187
188static ssize_t set_fan1_low(struct device *dev, const char *buf,
189 size_t count)
190{
191 struct i2c_client *client = to_i2c_client(dev);
192 struct lm63_data *data = i2c_get_clientdata(client);
193 unsigned long val = simple_strtoul(buf, NULL, 10);
194
195 down(&data->update_lock);
196 data->fan1_low = FAN_TO_REG(val);
197 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_LSB,
198 data->fan1_low & 0xFF);
199 i2c_smbus_write_byte_data(client, LM63_REG_TACH_LIMIT_MSB,
200 data->fan1_low >> 8);
201 up(&data->update_lock);
202 return count;
203}
204
205static ssize_t show_pwm1(struct device *dev, char *buf)
206{
207 struct lm63_data *data = lm63_update_device(dev);
208 return sprintf(buf, "%d\n", data->pwm1_value >= 2 * data->pwm1_freq ?
209 255 : (data->pwm1_value * 255 + data->pwm1_freq) /
210 (2 * data->pwm1_freq));
211}
212
213static ssize_t set_pwm1(struct device *dev, const char *buf, size_t count)
214{
215 struct i2c_client *client = to_i2c_client(dev);
216 struct lm63_data *data = i2c_get_clientdata(client);
217 unsigned long val;
218
219 if (!(data->config_fan & 0x20)) /* register is read-only */
220 return -EPERM;
221
222 val = simple_strtoul(buf, NULL, 10);
223 down(&data->update_lock);
224 data->pwm1_value = val <= 0 ? 0 :
225 val >= 255 ? 2 * data->pwm1_freq :
226 (val * data->pwm1_freq * 2 + 127) / 255;
227 i2c_smbus_write_byte_data(client, LM63_REG_PWM_VALUE, data->pwm1_value);
228 up(&data->update_lock);
229 return count;
230}
231
232static ssize_t show_pwm1_enable(struct device *dev, char *buf)
233{
234 struct lm63_data *data = lm63_update_device(dev);
235 return sprintf(buf, "%d\n", data->config_fan & 0x20 ? 1 : 2);
236}
237
238#define show_temp8(value) \
239static ssize_t show_##value(struct device *dev, char *buf) \
240{ \
241 struct lm63_data *data = lm63_update_device(dev); \
242 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->value)); \
243}
244#define show_temp11(value) \
245static ssize_t show_##value(struct device *dev, char *buf) \
246{ \
247 struct lm63_data *data = lm63_update_device(dev); \
248 return sprintf(buf, "%d\n", TEMP11_FROM_REG(data->value)); \
249}
250show_temp8(temp1_input);
251show_temp8(temp1_high);
252show_temp11(temp2_input);
253show_temp11(temp2_high);
254show_temp11(temp2_low);
255show_temp8(temp2_crit);
256
257#define set_temp8(value, reg) \
258static ssize_t set_##value(struct device *dev, const char *buf, \
259 size_t count) \
260{ \
261 struct i2c_client *client = to_i2c_client(dev); \
262 struct lm63_data *data = i2c_get_clientdata(client); \
263 long val = simple_strtol(buf, NULL, 10); \
264 \
265 down(&data->update_lock); \
266 data->value = TEMP8_TO_REG(val); \
267 i2c_smbus_write_byte_data(client, reg, data->value); \
268 up(&data->update_lock); \
269 return count; \
270}
271#define set_temp11(value, reg_msb, reg_lsb) \
272static ssize_t set_##value(struct device *dev, const char *buf, \
273 size_t count) \
274{ \
275 struct i2c_client *client = to_i2c_client(dev); \
276 struct lm63_data *data = i2c_get_clientdata(client); \
277 long val = simple_strtol(buf, NULL, 10); \
278 \
279 down(&data->update_lock); \
280 data->value = TEMP11_TO_REG(val); \
281 i2c_smbus_write_byte_data(client, reg_msb, data->value >> 8); \
282 i2c_smbus_write_byte_data(client, reg_lsb, data->value & 0xff); \
283 up(&data->update_lock); \
284 return count; \
285}
286set_temp8(temp1_high, LM63_REG_LOCAL_HIGH);
287set_temp11(temp2_high, LM63_REG_REMOTE_HIGH_MSB, LM63_REG_REMOTE_HIGH_LSB);
288set_temp11(temp2_low, LM63_REG_REMOTE_LOW_MSB, LM63_REG_REMOTE_LOW_LSB);
289
290/* Hysteresis register holds a relative value, while we want to present
291 an absolute to user-space */
292static ssize_t show_temp2_crit_hyst(struct device *dev, char *buf)
293{
294 struct lm63_data *data = lm63_update_device(dev);
295 return sprintf(buf, "%d\n", TEMP8_FROM_REG(data->temp2_crit)
296 - TEMP8_FROM_REG(data->temp2_crit_hyst));
297}
298
299/* And now the other way around, user-space provides an absolute
300 hysteresis value and we have to store a relative one */
301static ssize_t set_temp2_crit_hyst(struct device *dev, const char *buf,
302 size_t count)
303{
304 struct i2c_client *client = to_i2c_client(dev);
305 struct lm63_data *data = i2c_get_clientdata(client);
306 long val = simple_strtol(buf, NULL, 10);
307 long hyst;
308
309 down(&data->update_lock);
310 hyst = TEMP8_FROM_REG(data->temp2_crit) - val;
311 i2c_smbus_write_byte_data(client, LM63_REG_REMOTE_TCRIT_HYST,
312 HYST_TO_REG(hyst));
313 up(&data->update_lock);
314 return count;
315}
316
317static ssize_t show_alarms(struct device *dev, char *buf)
318{
319 struct lm63_data *data = lm63_update_device(dev);
320 return sprintf(buf, "%u\n", data->alarms);
321}
322
323static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan1_input, NULL);
324static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan1_low,
325 set_fan1_low);
326
327static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm1, set_pwm1);
328static DEVICE_ATTR(pwm1_enable, S_IRUGO, show_pwm1_enable, NULL);
329
330static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1_input, NULL);
331static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp1_high,
332 set_temp1_high);
333
334static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp2_input, NULL);
335static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp2_low,
336 set_temp2_low);
337static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp2_high,
338 set_temp2_high);
339static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp2_crit, NULL);
340static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp2_crit_hyst,
341 set_temp2_crit_hyst);
342
343static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
344
345/*
346 * Real code
347 */
348
349static int lm63_attach_adapter(struct i2c_adapter *adapter)
350{
351 if (!(adapter->class & I2C_CLASS_HWMON))
352 return 0;
353 return i2c_detect(adapter, &addr_data, lm63_detect);
354}
355
356/*
357 * The following function does more than just detection. If detection
358 * succeeds, it also registers the new chip.
359 */
360static int lm63_detect(struct i2c_adapter *adapter, int address, int kind)
361{
362 struct i2c_client *new_client;
363 struct lm63_data *data;
364 int err = 0;
365
366 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
367 goto exit;
368
369 if (!(data = kmalloc(sizeof(struct lm63_data), GFP_KERNEL))) {
370 err = -ENOMEM;
371 goto exit;
372 }
373 memset(data, 0, sizeof(struct lm63_data));
374
375 /* The common I2C client data is placed right before the
376 LM63-specific data. */
377 new_client = &data->client;
378 i2c_set_clientdata(new_client, data);
379 new_client->addr = address;
380 new_client->adapter = adapter;
381 new_client->driver = &lm63_driver;
382 new_client->flags = 0;
383
384 /* Default to an LM63 if forced */
385 if (kind == 0)
386 kind = lm63;
387
388 if (kind < 0) { /* must identify */
389 u8 man_id, chip_id, reg_config1, reg_config2;
390 u8 reg_alert_status, reg_alert_mask;
391
392 man_id = i2c_smbus_read_byte_data(new_client,
393 LM63_REG_MAN_ID);
394 chip_id = i2c_smbus_read_byte_data(new_client,
395 LM63_REG_CHIP_ID);
396 reg_config1 = i2c_smbus_read_byte_data(new_client,
397 LM63_REG_CONFIG1);
398 reg_config2 = i2c_smbus_read_byte_data(new_client,
399 LM63_REG_CONFIG2);
400 reg_alert_status = i2c_smbus_read_byte_data(new_client,
401 LM63_REG_ALERT_STATUS);
402 reg_alert_mask = i2c_smbus_read_byte_data(new_client,
403 LM63_REG_ALERT_MASK);
404
405 if (man_id == 0x01 /* National Semiconductor */
406 && chip_id == 0x41 /* LM63 */
407 && (reg_config1 & 0x18) == 0x00
408 && (reg_config2 & 0xF8) == 0x00
409 && (reg_alert_status & 0x20) == 0x00
410 && (reg_alert_mask & 0xA4) == 0xA4) {
411 kind = lm63;
412 } else { /* failed */
413 dev_dbg(&adapter->dev, "Unsupported chip "
414 "(man_id=0x%02X, chip_id=0x%02X).\n",
415 man_id, chip_id);
416 goto exit_free;
417 }
418 }
419
420 strlcpy(new_client->name, "lm63", I2C_NAME_SIZE);
421 data->valid = 0;
422 init_MUTEX(&data->update_lock);
423
424 /* Tell the I2C layer a new client has arrived */
425 if ((err = i2c_attach_client(new_client)))
426 goto exit_free;
427
428 /* Initialize the LM63 chip */
429 lm63_init_client(new_client);
430
431 /* Register sysfs hooks */
432 if (data->config & 0x04) { /* tachometer enabled */
433 device_create_file(&new_client->dev, &dev_attr_fan1_input);
434 device_create_file(&new_client->dev, &dev_attr_fan1_min);
435 }
436 device_create_file(&new_client->dev, &dev_attr_pwm1);
437 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
438 device_create_file(&new_client->dev, &dev_attr_temp1_input);
439 device_create_file(&new_client->dev, &dev_attr_temp2_input);
440 device_create_file(&new_client->dev, &dev_attr_temp2_min);
441 device_create_file(&new_client->dev, &dev_attr_temp1_max);
442 device_create_file(&new_client->dev, &dev_attr_temp2_max);
443 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
444 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
445 device_create_file(&new_client->dev, &dev_attr_alarms);
446
447 return 0;
448
449exit_free:
450 kfree(data);
451exit:
452 return err;
453}
454
455/* Idealy we shouldn't have to initialize anything, since the BIOS
456 should have taken care of everything */
457static void lm63_init_client(struct i2c_client *client)
458{
459 struct lm63_data *data = i2c_get_clientdata(client);
460
461 data->config = i2c_smbus_read_byte_data(client, LM63_REG_CONFIG1);
462 data->config_fan = i2c_smbus_read_byte_data(client,
463 LM63_REG_CONFIG_FAN);
464
465 /* Start converting if needed */
466 if (data->config & 0x40) { /* standby */
467 dev_dbg(&client->dev, "Switching to operational mode");
468 data->config &= 0xA7;
469 i2c_smbus_write_byte_data(client, LM63_REG_CONFIG1,
470 data->config);
471 }
472
473 /* We may need pwm1_freq before ever updating the client data */
474 data->pwm1_freq = i2c_smbus_read_byte_data(client, LM63_REG_PWM_FREQ);
475 if (data->pwm1_freq == 0)
476 data->pwm1_freq = 1;
477
478 /* Show some debug info about the LM63 configuration */
479 dev_dbg(&client->dev, "Alert/tach pin configured for %s\n",
480 (data->config & 0x04) ? "tachometer input" :
481 "alert output");
482 dev_dbg(&client->dev, "PWM clock %s kHz, output frequency %u Hz\n",
483 (data->config_fan & 0x08) ? "1.4" : "360",
484 ((data->config_fan & 0x08) ? 700 : 180000) / data->pwm1_freq);
485 dev_dbg(&client->dev, "PWM output active %s, %s mode\n",
486 (data->config_fan & 0x10) ? "low" : "high",
487 (data->config_fan & 0x20) ? "manual" : "auto");
488}
489
490static int lm63_detach_client(struct i2c_client *client)
491{
492 int err;
493
494 if ((err = i2c_detach_client(client))) {
495 dev_err(&client->dev, "Client deregistration failed, "
496 "client not detached\n");
497 return err;
498 }
499
500 kfree(i2c_get_clientdata(client));
501 return 0;
502}
503
504static struct lm63_data *lm63_update_device(struct device *dev)
505{
506 struct i2c_client *client = to_i2c_client(dev);
507 struct lm63_data *data = i2c_get_clientdata(client);
508
509 down(&data->update_lock);
510
511 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
512 if (data->config & 0x04) { /* tachometer enabled */
513 /* order matters for fan1_input */
514 data->fan1_input = i2c_smbus_read_byte_data(client,
515 LM63_REG_TACH_COUNT_LSB) & 0xFC;
516 data->fan1_input |= i2c_smbus_read_byte_data(client,
517 LM63_REG_TACH_COUNT_MSB) << 8;
518 data->fan1_low = (i2c_smbus_read_byte_data(client,
519 LM63_REG_TACH_LIMIT_LSB) & 0xFC)
520 | (i2c_smbus_read_byte_data(client,
521 LM63_REG_TACH_LIMIT_MSB) << 8);
522 }
523
524 data->pwm1_freq = i2c_smbus_read_byte_data(client,
525 LM63_REG_PWM_FREQ);
526 if (data->pwm1_freq == 0)
527 data->pwm1_freq = 1;
528 data->pwm1_value = i2c_smbus_read_byte_data(client,
529 LM63_REG_PWM_VALUE);
530
531 data->temp1_input = i2c_smbus_read_byte_data(client,
532 LM63_REG_LOCAL_TEMP);
533 data->temp1_high = i2c_smbus_read_byte_data(client,
534 LM63_REG_LOCAL_HIGH);
535
536 /* order matters for temp2_input */
537 data->temp2_input = i2c_smbus_read_byte_data(client,
538 LM63_REG_REMOTE_TEMP_MSB) << 8;
539 data->temp2_input |= i2c_smbus_read_byte_data(client,
540 LM63_REG_REMOTE_TEMP_LSB);
541 data->temp2_high = (i2c_smbus_read_byte_data(client,
542 LM63_REG_REMOTE_HIGH_MSB) << 8)
543 | i2c_smbus_read_byte_data(client,
544 LM63_REG_REMOTE_HIGH_LSB);
545 data->temp2_low = (i2c_smbus_read_byte_data(client,
546 LM63_REG_REMOTE_LOW_MSB) << 8)
547 | i2c_smbus_read_byte_data(client,
548 LM63_REG_REMOTE_LOW_LSB);
549 data->temp2_crit = i2c_smbus_read_byte_data(client,
550 LM63_REG_REMOTE_TCRIT);
551 data->temp2_crit_hyst = i2c_smbus_read_byte_data(client,
552 LM63_REG_REMOTE_TCRIT_HYST);
553
554 data->alarms = i2c_smbus_read_byte_data(client,
555 LM63_REG_ALERT_STATUS) & 0x7F;
556
557 data->last_updated = jiffies;
558 data->valid = 1;
559 }
560
561 up(&data->update_lock);
562
563 return data;
564}
565
566static int __init sensors_lm63_init(void)
567{
568 return i2c_add_driver(&lm63_driver);
569}
570
571static void __exit sensors_lm63_exit(void)
572{
573 i2c_del_driver(&lm63_driver);
574}
575
576MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
577MODULE_DESCRIPTION("LM63 driver");
578MODULE_LICENSE("GPL");
579
580module_init(sensors_lm63_init);
581module_exit(sensors_lm63_exit);
diff --git a/drivers/i2c/chips/lm75.c b/drivers/i2c/chips/lm75.c
deleted file mode 100644
index 0e86cc893981..000000000000
--- a/drivers/i2c/chips/lm75.c
+++ /dev/null
@@ -1,297 +0,0 @@
1/*
2 lm75.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/jiffies.h>
26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h>
28#include "lm75.h"
29
30
31/* Addresses to scan */
32static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
33 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
34static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
35
36/* Insmod parameters */
37SENSORS_INSMOD_1(lm75);
38
39/* Many LM75 constants specified below */
40
41/* The LM75 registers */
42#define LM75_REG_TEMP 0x00
43#define LM75_REG_CONF 0x01
44#define LM75_REG_TEMP_HYST 0x02
45#define LM75_REG_TEMP_OS 0x03
46
47/* Each client has this additional data */
48struct lm75_data {
49 struct i2c_client client;
50 struct semaphore update_lock;
51 char valid; /* !=0 if following fields are valid */
52 unsigned long last_updated; /* In jiffies */
53 u16 temp_input; /* Register values */
54 u16 temp_max;
55 u16 temp_hyst;
56};
57
58static int lm75_attach_adapter(struct i2c_adapter *adapter);
59static int lm75_detect(struct i2c_adapter *adapter, int address, int kind);
60static void lm75_init_client(struct i2c_client *client);
61static int lm75_detach_client(struct i2c_client *client);
62static int lm75_read_value(struct i2c_client *client, u8 reg);
63static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value);
64static struct lm75_data *lm75_update_device(struct device *dev);
65
66
67/* This is the driver that will be inserted */
68static struct i2c_driver lm75_driver = {
69 .owner = THIS_MODULE,
70 .name = "lm75",
71 .id = I2C_DRIVERID_LM75,
72 .flags = I2C_DF_NOTIFY,
73 .attach_adapter = lm75_attach_adapter,
74 .detach_client = lm75_detach_client,
75};
76
77#define show(value) \
78static ssize_t show_##value(struct device *dev, char *buf) \
79{ \
80 struct lm75_data *data = lm75_update_device(dev); \
81 return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \
82}
83show(temp_max);
84show(temp_hyst);
85show(temp_input);
86
87#define set(value, reg) \
88static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
89{ \
90 struct i2c_client *client = to_i2c_client(dev); \
91 struct lm75_data *data = i2c_get_clientdata(client); \
92 int temp = simple_strtoul(buf, NULL, 10); \
93 \
94 down(&data->update_lock); \
95 data->value = LM75_TEMP_TO_REG(temp); \
96 lm75_write_value(client, reg, data->value); \
97 up(&data->update_lock); \
98 return count; \
99}
100set(temp_max, LM75_REG_TEMP_OS);
101set(temp_hyst, LM75_REG_TEMP_HYST);
102
103static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
104static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_temp_hyst, set_temp_hyst);
105static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL);
106
107static int lm75_attach_adapter(struct i2c_adapter *adapter)
108{
109 if (!(adapter->class & I2C_CLASS_HWMON))
110 return 0;
111 return i2c_detect(adapter, &addr_data, lm75_detect);
112}
113
114/* This function is called by i2c_detect */
115static int lm75_detect(struct i2c_adapter *adapter, int address, int kind)
116{
117 int i;
118 struct i2c_client *new_client;
119 struct lm75_data *data;
120 int err = 0;
121 const char *name = "";
122
123 /* Make sure we aren't probing the ISA bus!! This is just a safety check
124 at this moment; i2c_detect really won't call us. */
125#ifdef DEBUG
126 if (i2c_is_isa_adapter(adapter)) {
127 dev_dbg(&adapter->dev,
128 "lm75_detect called for an ISA bus adapter?!?\n");
129 goto exit;
130 }
131#endif
132
133 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
134 I2C_FUNC_SMBUS_WORD_DATA))
135 goto exit;
136
137 /* OK. For now, we presume we have a valid client. We now create the
138 client structure, even though we cannot fill it completely yet.
139 But it allows us to access lm75_{read,write}_value. */
140 if (!(data = kmalloc(sizeof(struct lm75_data), GFP_KERNEL))) {
141 err = -ENOMEM;
142 goto exit;
143 }
144 memset(data, 0, sizeof(struct lm75_data));
145
146 new_client = &data->client;
147 i2c_set_clientdata(new_client, data);
148 new_client->addr = address;
149 new_client->adapter = adapter;
150 new_client->driver = &lm75_driver;
151 new_client->flags = 0;
152
153 /* Now, we do the remaining detection. There is no identification-
154 dedicated register so we have to rely on several tricks:
155 unused bits, registers cycling over 8-address boundaries,
156 addresses 0x04-0x07 returning the last read value.
157 The cycling+unused addresses combination is not tested,
158 since it would significantly slow the detection down and would
159 hardly add any value. */
160 if (kind < 0) {
161 int cur, conf, hyst, os;
162
163 /* Unused addresses */
164 cur = i2c_smbus_read_word_data(new_client, 0);
165 conf = i2c_smbus_read_byte_data(new_client, 1);
166 hyst = i2c_smbus_read_word_data(new_client, 2);
167 if (i2c_smbus_read_word_data(new_client, 4) != hyst
168 || i2c_smbus_read_word_data(new_client, 5) != hyst
169 || i2c_smbus_read_word_data(new_client, 6) != hyst
170 || i2c_smbus_read_word_data(new_client, 7) != hyst)
171 goto exit_free;
172 os = i2c_smbus_read_word_data(new_client, 3);
173 if (i2c_smbus_read_word_data(new_client, 4) != os
174 || i2c_smbus_read_word_data(new_client, 5) != os
175 || i2c_smbus_read_word_data(new_client, 6) != os
176 || i2c_smbus_read_word_data(new_client, 7) != os)
177 goto exit_free;
178
179 /* Unused bits */
180 if (conf & 0xe0)
181 goto exit_free;
182
183 /* Addresses cycling */
184 for (i = 8; i < 0xff; i += 8)
185 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
186 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
187 || i2c_smbus_read_word_data(new_client, i + 3) != os)
188 goto exit_free;
189 }
190
191 /* Determine the chip type - only one kind supported! */
192 if (kind <= 0)
193 kind = lm75;
194
195 if (kind == lm75) {
196 name = "lm75";
197 }
198
199 /* Fill in the remaining client fields and put it into the global list */
200 strlcpy(new_client->name, name, I2C_NAME_SIZE);
201 data->valid = 0;
202 init_MUTEX(&data->update_lock);
203
204 /* Tell the I2C layer a new client has arrived */
205 if ((err = i2c_attach_client(new_client)))
206 goto exit_free;
207
208 /* Initialize the LM75 chip */
209 lm75_init_client(new_client);
210
211 /* Register sysfs hooks */
212 device_create_file(&new_client->dev, &dev_attr_temp1_max);
213 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
214 device_create_file(&new_client->dev, &dev_attr_temp1_input);
215
216 return 0;
217
218exit_free:
219 kfree(data);
220exit:
221 return err;
222}
223
224static int lm75_detach_client(struct i2c_client *client)
225{
226 i2c_detach_client(client);
227 kfree(i2c_get_clientdata(client));
228 return 0;
229}
230
231/* All registers are word-sized, except for the configuration register.
232 LM75 uses a high-byte first convention, which is exactly opposite to
233 the usual practice. */
234static int lm75_read_value(struct i2c_client *client, u8 reg)
235{
236 if (reg == LM75_REG_CONF)
237 return i2c_smbus_read_byte_data(client, reg);
238 else
239 return swab16(i2c_smbus_read_word_data(client, reg));
240}
241
242/* All registers are word-sized, except for the configuration register.
243 LM75 uses a high-byte first convention, which is exactly opposite to
244 the usual practice. */
245static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
246{
247 if (reg == LM75_REG_CONF)
248 return i2c_smbus_write_byte_data(client, reg, value);
249 else
250 return i2c_smbus_write_word_data(client, reg, swab16(value));
251}
252
253static void lm75_init_client(struct i2c_client *client)
254{
255 /* Initialize the LM75 chip */
256 lm75_write_value(client, LM75_REG_CONF, 0);
257}
258
259static struct lm75_data *lm75_update_device(struct device *dev)
260{
261 struct i2c_client *client = to_i2c_client(dev);
262 struct lm75_data *data = i2c_get_clientdata(client);
263
264 down(&data->update_lock);
265
266 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
267 || !data->valid) {
268 dev_dbg(&client->dev, "Starting lm75 update\n");
269
270 data->temp_input = lm75_read_value(client, LM75_REG_TEMP);
271 data->temp_max = lm75_read_value(client, LM75_REG_TEMP_OS);
272 data->temp_hyst = lm75_read_value(client, LM75_REG_TEMP_HYST);
273 data->last_updated = jiffies;
274 data->valid = 1;
275 }
276
277 up(&data->update_lock);
278
279 return data;
280}
281
282static int __init sensors_lm75_init(void)
283{
284 return i2c_add_driver(&lm75_driver);
285}
286
287static void __exit sensors_lm75_exit(void)
288{
289 i2c_del_driver(&lm75_driver);
290}
291
292MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
293MODULE_DESCRIPTION("LM75 driver");
294MODULE_LICENSE("GPL");
295
296module_init(sensors_lm75_init);
297module_exit(sensors_lm75_exit);
diff --git a/drivers/i2c/chips/lm75.h b/drivers/i2c/chips/lm75.h
deleted file mode 100644
index 63e3f2fb4c21..000000000000
--- a/drivers/i2c/chips/lm75.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 lm75.h - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21/*
22 This file contains common code for encoding/decoding LM75 type
23 temperature readings, which are emulated by many of the chips
24 we support. As the user is unlikely to load more than one driver
25 which contains this code, we don't worry about the wasted space.
26*/
27
28#include <linux/i2c-sensor.h>
29
30/* straight from the datasheet */
31#define LM75_TEMP_MIN (-55000)
32#define LM75_TEMP_MAX 125000
33
34/* TEMP: 0.001C/bit (-55C to +125C)
35 REG: (0.5C/bit, two's complement) << 7 */
36static inline u16 LM75_TEMP_TO_REG(int temp)
37{
38 int ntemp = SENSORS_LIMIT(temp, LM75_TEMP_MIN, LM75_TEMP_MAX);
39 ntemp += (ntemp<0 ? -250 : 250);
40 return (u16)((ntemp / 500) << 7);
41}
42
43static inline int LM75_TEMP_FROM_REG(u16 reg)
44{
45 /* use integer division instead of equivalent right shift to
46 guarantee arithmetic shift and preserve the sign */
47 return ((s16)reg / 128) * 500;
48}
49
diff --git a/drivers/i2c/chips/lm77.c b/drivers/i2c/chips/lm77.c
deleted file mode 100644
index f56b7a37de75..000000000000
--- a/drivers/i2c/chips/lm77.c
+++ /dev/null
@@ -1,421 +0,0 @@
1/*
2 lm77.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 2004 Andras BALI <drewie@freemail.hu>
6
7 Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77
8 is a temperature sensor and thermal window comparator with 0.5 deg
9 resolution made by National Semiconductor. Complete datasheet can be
10 obtained at their site:
11 http://www.national.com/pf/LM/LM77.html
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/
27
28#include <linux/config.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/slab.h>
32#include <linux/jiffies.h>
33#include <linux/i2c.h>
34#include <linux/i2c-sensor.h>
35
36
37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END };
39static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
40
41/* Insmod parameters */
42SENSORS_INSMOD_1(lm77);
43
44/* The LM77 registers */
45#define LM77_REG_TEMP 0x00
46#define LM77_REG_CONF 0x01
47#define LM77_REG_TEMP_HYST 0x02
48#define LM77_REG_TEMP_CRIT 0x03
49#define LM77_REG_TEMP_MIN 0x04
50#define LM77_REG_TEMP_MAX 0x05
51
52/* Each client has this additional data */
53struct lm77_data {
54 struct i2c_client client;
55 struct semaphore update_lock;
56 char valid;
57 unsigned long last_updated; /* In jiffies */
58 int temp_input; /* Temperatures */
59 int temp_crit;
60 int temp_min;
61 int temp_max;
62 int temp_hyst;
63 u8 alarms;
64};
65
66static int lm77_attach_adapter(struct i2c_adapter *adapter);
67static int lm77_detect(struct i2c_adapter *adapter, int address, int kind);
68static void lm77_init_client(struct i2c_client *client);
69static int lm77_detach_client(struct i2c_client *client);
70static u16 lm77_read_value(struct i2c_client *client, u8 reg);
71static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value);
72
73static struct lm77_data *lm77_update_device(struct device *dev);
74
75
76/* This is the driver that will be inserted */
77static struct i2c_driver lm77_driver = {
78 .owner = THIS_MODULE,
79 .name = "lm77",
80 .flags = I2C_DF_NOTIFY,
81 .attach_adapter = lm77_attach_adapter,
82 .detach_client = lm77_detach_client,
83};
84
85/* straight from the datasheet */
86#define LM77_TEMP_MIN (-55000)
87#define LM77_TEMP_MAX 125000
88
89/* In the temperature registers, the low 3 bits are not part of the
90 temperature values; they are the status bits. */
91static inline u16 LM77_TEMP_TO_REG(int temp)
92{
93 int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX);
94 return (u16)((ntemp / 500) * 8);
95}
96
97static inline int LM77_TEMP_FROM_REG(u16 reg)
98{
99 return ((int)reg / 8) * 500;
100}
101
102/* sysfs stuff */
103
104/* read routines for temperature limits */
105#define show(value) \
106static ssize_t show_##value(struct device *dev, char *buf) \
107{ \
108 struct lm77_data *data = lm77_update_device(dev); \
109 return sprintf(buf, "%d\n", data->value); \
110}
111
112show(temp_input);
113show(temp_crit);
114show(temp_min);
115show(temp_max);
116show(alarms);
117
118/* read routines for hysteresis values */
119static ssize_t show_temp_crit_hyst(struct device *dev, char *buf)
120{
121 struct lm77_data *data = lm77_update_device(dev);
122 return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst);
123}
124static ssize_t show_temp_min_hyst(struct device *dev, char *buf)
125{
126 struct lm77_data *data = lm77_update_device(dev);
127 return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst);
128}
129static ssize_t show_temp_max_hyst(struct device *dev, char *buf)
130{
131 struct lm77_data *data = lm77_update_device(dev);
132 return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst);
133}
134
135/* write routines */
136#define set(value, reg) \
137static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
138{ \
139 struct i2c_client *client = to_i2c_client(dev); \
140 struct lm77_data *data = i2c_get_clientdata(client); \
141 long val = simple_strtoul(buf, NULL, 10); \
142 \
143 down(&data->update_lock); \
144 data->value = val; \
145 lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
146 up(&data->update_lock); \
147 return count; \
148}
149
150set(temp_min, LM77_REG_TEMP_MIN);
151set(temp_max, LM77_REG_TEMP_MAX);
152
153/* hysteresis is stored as a relative value on the chip, so it has to be
154 converted first */
155static ssize_t set_temp_crit_hyst(struct device *dev, const char *buf, size_t count)
156{
157 struct i2c_client *client = to_i2c_client(dev);
158 struct lm77_data *data = i2c_get_clientdata(client);
159 unsigned long val = simple_strtoul(buf, NULL, 10);
160
161 down(&data->update_lock);
162 data->temp_hyst = data->temp_crit - val;
163 lm77_write_value(client, LM77_REG_TEMP_HYST,
164 LM77_TEMP_TO_REG(data->temp_hyst));
165 up(&data->update_lock);
166 return count;
167}
168
169/* preserve hysteresis when setting T_crit */
170static ssize_t set_temp_crit(struct device *dev, const char *buf, size_t count)
171{
172 struct i2c_client *client = to_i2c_client(dev);
173 struct lm77_data *data = i2c_get_clientdata(client);
174 long val = simple_strtoul(buf, NULL, 10);
175 int oldcrithyst;
176
177 down(&data->update_lock);
178 oldcrithyst = data->temp_crit - data->temp_hyst;
179 data->temp_crit = val;
180 data->temp_hyst = data->temp_crit - oldcrithyst;
181 lm77_write_value(client, LM77_REG_TEMP_CRIT,
182 LM77_TEMP_TO_REG(data->temp_crit));
183 lm77_write_value(client, LM77_REG_TEMP_HYST,
184 LM77_TEMP_TO_REG(data->temp_hyst));
185 up(&data->update_lock);
186 return count;
187}
188
189static DEVICE_ATTR(temp1_input, S_IRUGO,
190 show_temp_input, NULL);
191static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO,
192 show_temp_crit, set_temp_crit);
193static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO,
194 show_temp_min, set_temp_min);
195static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
196 show_temp_max, set_temp_max);
197
198static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO,
199 show_temp_crit_hyst, set_temp_crit_hyst);
200static DEVICE_ATTR(temp1_min_hyst, S_IRUGO,
201 show_temp_min_hyst, NULL);
202static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
203 show_temp_max_hyst, NULL);
204
205static DEVICE_ATTR(alarms, S_IRUGO,
206 show_alarms, NULL);
207
208static int lm77_attach_adapter(struct i2c_adapter *adapter)
209{
210 if (!(adapter->class & I2C_CLASS_HWMON))
211 return 0;
212 return i2c_detect(adapter, &addr_data, lm77_detect);
213}
214
215/* This function is called by i2c_detect */
216static int lm77_detect(struct i2c_adapter *adapter, int address, int kind)
217{
218 struct i2c_client *new_client;
219 struct lm77_data *data;
220 int err = 0;
221 const char *name = "";
222
223 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
224 I2C_FUNC_SMBUS_WORD_DATA))
225 goto exit;
226
227 /* OK. For now, we presume we have a valid client. We now create the
228 client structure, even though we cannot fill it completely yet.
229 But it allows us to access lm77_{read,write}_value. */
230 if (!(data = kmalloc(sizeof(struct lm77_data), GFP_KERNEL))) {
231 err = -ENOMEM;
232 goto exit;
233 }
234 memset(data, 0, sizeof(struct lm77_data));
235
236 new_client = &data->client;
237 i2c_set_clientdata(new_client, data);
238 new_client->addr = address;
239 new_client->adapter = adapter;
240 new_client->driver = &lm77_driver;
241 new_client->flags = 0;
242
243 /* Here comes the remaining detection. Since the LM77 has no
244 register dedicated to identification, we have to rely on the
245 following tricks:
246
247 1. the high 4 bits represent the sign and thus they should
248 always be the same
249 2. the high 3 bits are unused in the configuration register
250 3. addresses 0x06 and 0x07 return the last read value
251 4. registers cycling over 8-address boundaries
252
253 Word-sized registers are high-byte first. */
254 if (kind < 0) {
255 int i, cur, conf, hyst, crit, min, max;
256
257 /* addresses cycling */
258 cur = i2c_smbus_read_word_data(new_client, 0);
259 conf = i2c_smbus_read_byte_data(new_client, 1);
260 hyst = i2c_smbus_read_word_data(new_client, 2);
261 crit = i2c_smbus_read_word_data(new_client, 3);
262 min = i2c_smbus_read_word_data(new_client, 4);
263 max = i2c_smbus_read_word_data(new_client, 5);
264 for (i = 8; i <= 0xff; i += 8)
265 if (i2c_smbus_read_byte_data(new_client, i + 1) != conf
266 || i2c_smbus_read_word_data(new_client, i + 2) != hyst
267 || i2c_smbus_read_word_data(new_client, i + 3) != crit
268 || i2c_smbus_read_word_data(new_client, i + 4) != min
269 || i2c_smbus_read_word_data(new_client, i + 5) != max)
270 goto exit_free;
271
272 /* sign bits */
273 if (((cur & 0x00f0) != 0xf0 && (cur & 0x00f0) != 0x0)
274 || ((hyst & 0x00f0) != 0xf0 && (hyst & 0x00f0) != 0x0)
275 || ((crit & 0x00f0) != 0xf0 && (crit & 0x00f0) != 0x0)
276 || ((min & 0x00f0) != 0xf0 && (min & 0x00f0) != 0x0)
277 || ((max & 0x00f0) != 0xf0 && (max & 0x00f0) != 0x0))
278 goto exit_free;
279
280 /* unused bits */
281 if (conf & 0xe0)
282 goto exit_free;
283
284 /* 0x06 and 0x07 return the last read value */
285 cur = i2c_smbus_read_word_data(new_client, 0);
286 if (i2c_smbus_read_word_data(new_client, 6) != cur
287 || i2c_smbus_read_word_data(new_client, 7) != cur)
288 goto exit_free;
289 hyst = i2c_smbus_read_word_data(new_client, 2);
290 if (i2c_smbus_read_word_data(new_client, 6) != hyst
291 || i2c_smbus_read_word_data(new_client, 7) != hyst)
292 goto exit_free;
293 min = i2c_smbus_read_word_data(new_client, 4);
294 if (i2c_smbus_read_word_data(new_client, 6) != min
295 || i2c_smbus_read_word_data(new_client, 7) != min)
296 goto exit_free;
297
298 }
299
300 /* Determine the chip type - only one kind supported! */
301 if (kind <= 0)
302 kind = lm77;
303
304 if (kind == lm77) {
305 name = "lm77";
306 }
307
308 /* Fill in the remaining client fields and put it into the global list */
309 strlcpy(new_client->name, name, I2C_NAME_SIZE);
310 data->valid = 0;
311 init_MUTEX(&data->update_lock);
312
313 /* Tell the I2C layer a new client has arrived */
314 if ((err = i2c_attach_client(new_client)))
315 goto exit_free;
316
317 /* Initialize the LM77 chip */
318 lm77_init_client(new_client);
319
320 /* Register sysfs hooks */
321 device_create_file(&new_client->dev, &dev_attr_temp1_input);
322 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
323 device_create_file(&new_client->dev, &dev_attr_temp1_min);
324 device_create_file(&new_client->dev, &dev_attr_temp1_max);
325 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
326 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
327 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
328 device_create_file(&new_client->dev, &dev_attr_alarms);
329 return 0;
330
331exit_free:
332 kfree(data);
333exit:
334 return err;
335}
336
337static int lm77_detach_client(struct i2c_client *client)
338{
339 i2c_detach_client(client);
340 kfree(i2c_get_clientdata(client));
341 return 0;
342}
343
344/* All registers are word-sized, except for the configuration register.
345 The LM77 uses the high-byte first convention. */
346static u16 lm77_read_value(struct i2c_client *client, u8 reg)
347{
348 if (reg == LM77_REG_CONF)
349 return i2c_smbus_read_byte_data(client, reg);
350 else
351 return swab16(i2c_smbus_read_word_data(client, reg));
352}
353
354static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
355{
356 if (reg == LM77_REG_CONF)
357 return i2c_smbus_write_byte_data(client, reg, value);
358 else
359 return i2c_smbus_write_word_data(client, reg, swab16(value));
360}
361
362static void lm77_init_client(struct i2c_client *client)
363{
364 /* Initialize the LM77 chip - turn off shutdown mode */
365 int conf = lm77_read_value(client, LM77_REG_CONF);
366 if (conf & 1)
367 lm77_write_value(client, LM77_REG_CONF, conf & 0xfe);
368}
369
370static struct lm77_data *lm77_update_device(struct device *dev)
371{
372 struct i2c_client *client = to_i2c_client(dev);
373 struct lm77_data *data = i2c_get_clientdata(client);
374
375 down(&data->update_lock);
376
377 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
378 || !data->valid) {
379 dev_dbg(&client->dev, "Starting lm77 update\n");
380 data->temp_input =
381 LM77_TEMP_FROM_REG(lm77_read_value(client,
382 LM77_REG_TEMP));
383 data->temp_hyst =
384 LM77_TEMP_FROM_REG(lm77_read_value(client,
385 LM77_REG_TEMP_HYST));
386 data->temp_crit =
387 LM77_TEMP_FROM_REG(lm77_read_value(client,
388 LM77_REG_TEMP_CRIT));
389 data->temp_min =
390 LM77_TEMP_FROM_REG(lm77_read_value(client,
391 LM77_REG_TEMP_MIN));
392 data->temp_max =
393 LM77_TEMP_FROM_REG(lm77_read_value(client,
394 LM77_REG_TEMP_MAX));
395 data->alarms =
396 lm77_read_value(client, LM77_REG_TEMP) & 0x0007;
397 data->last_updated = jiffies;
398 data->valid = 1;
399 }
400
401 up(&data->update_lock);
402
403 return data;
404}
405
406static int __init sensors_lm77_init(void)
407{
408 return i2c_add_driver(&lm77_driver);
409}
410
411static void __exit sensors_lm77_exit(void)
412{
413 i2c_del_driver(&lm77_driver);
414}
415
416MODULE_AUTHOR("Andras BALI <drewie@freemail.hu>");
417MODULE_DESCRIPTION("LM77 driver");
418MODULE_LICENSE("GPL");
419
420module_init(sensors_lm77_init);
421module_exit(sensors_lm77_exit);
diff --git a/drivers/i2c/chips/lm78.c b/drivers/i2c/chips/lm78.c
deleted file mode 100644
index 6d52d14eb31c..000000000000
--- a/drivers/i2c/chips/lm78.c
+++ /dev/null
@@ -1,796 +0,0 @@
1/*
2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/jiffies.h>
26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h>
28#include <asm/io.h>
29
30/* Addresses to scan */
31static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
32 0x25, 0x26, 0x27, 0x28, 0x29,
33 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
34 0x2f, I2C_CLIENT_END };
35static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
36
37/* Insmod parameters */
38SENSORS_INSMOD_3(lm78, lm78j, lm79);
39
40/* Many LM78 constants specified below */
41
42/* Length of ISA address segment */
43#define LM78_EXTENT 8
44
45/* Where are the ISA address/data registers relative to the base address */
46#define LM78_ADDR_REG_OFFSET 5
47#define LM78_DATA_REG_OFFSET 6
48
49/* The LM78 registers */
50#define LM78_REG_IN_MAX(nr) (0x2b + (nr) * 2)
51#define LM78_REG_IN_MIN(nr) (0x2c + (nr) * 2)
52#define LM78_REG_IN(nr) (0x20 + (nr))
53
54#define LM78_REG_FAN_MIN(nr) (0x3b + (nr))
55#define LM78_REG_FAN(nr) (0x28 + (nr))
56
57#define LM78_REG_TEMP 0x27
58#define LM78_REG_TEMP_OVER 0x39
59#define LM78_REG_TEMP_HYST 0x3a
60
61#define LM78_REG_ALARM1 0x41
62#define LM78_REG_ALARM2 0x42
63
64#define LM78_REG_VID_FANDIV 0x47
65
66#define LM78_REG_CONFIG 0x40
67#define LM78_REG_CHIPID 0x49
68#define LM78_REG_I2C_ADDR 0x48
69
70
71/* Conversions. Rounding and limit checking is only done on the TO_REG
72 variants. */
73
74/* IN: mV, (0V to 4.08V)
75 REG: 16mV/bit */
76static inline u8 IN_TO_REG(unsigned long val)
77{
78 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
79 return (nval + 8) / 16;
80}
81#define IN_FROM_REG(val) ((val) * 16)
82
83static inline u8 FAN_TO_REG(long rpm, int div)
84{
85 if (rpm <= 0)
86 return 255;
87 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
88}
89
90static inline int FAN_FROM_REG(u8 val, int div)
91{
92 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
93}
94
95/* TEMP: mC (-128C to +127C)
96 REG: 1C/bit, two's complement */
97static inline s8 TEMP_TO_REG(int val)
98{
99 int nval = SENSORS_LIMIT(val, -128000, 127000) ;
100 return nval<0 ? (nval-500)/1000 : (nval+500)/1000;
101}
102
103static inline int TEMP_FROM_REG(s8 val)
104{
105 return val * 1000;
106}
107
108/* VID: mV
109 REG: (see doc/vid) */
110static inline int VID_FROM_REG(u8 val)
111{
112 return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
113}
114
115#define DIV_FROM_REG(val) (1 << (val))
116
117/* There are some complications in a module like this. First off, LM78 chips
118 may be both present on the SMBus and the ISA bus, and we have to handle
119 those cases separately at some places. Second, there might be several
120 LM78 chips available (well, actually, that is probably never done; but
121 it is a clean illustration of how to handle a case like that). Finally,
122 a specific chip may be attached to *both* ISA and SMBus, and we would
123 not like to detect it double. Fortunately, in the case of the LM78 at
124 least, a register tells us what SMBus address we are on, so that helps
125 a bit - except if there could be more than one SMBus. Groan. No solution
126 for this yet. */
127
128/* This module may seem overly long and complicated. In fact, it is not so
129 bad. Quite a lot of bookkeeping is done. A real driver can often cut
130 some corners. */
131
132/* For each registered LM78, we need to keep some data in memory. That
133 data is pointed to by lm78_list[NR]->data. The structure itself is
134 dynamically allocated, at the same time when a new lm78 client is
135 allocated. */
136struct lm78_data {
137 struct i2c_client client;
138 struct semaphore lock;
139 enum chips type;
140
141 struct semaphore update_lock;
142 char valid; /* !=0 if following fields are valid */
143 unsigned long last_updated; /* In jiffies */
144
145 u8 in[7]; /* Register value */
146 u8 in_max[7]; /* Register value */
147 u8 in_min[7]; /* Register value */
148 u8 fan[3]; /* Register value */
149 u8 fan_min[3]; /* Register value */
150 s8 temp; /* Register value */
151 s8 temp_over; /* Register value */
152 s8 temp_hyst; /* Register value */
153 u8 fan_div[3]; /* Register encoding, shifted right */
154 u8 vid; /* Register encoding, combined */
155 u16 alarms; /* Register encoding, combined */
156};
157
158
159static int lm78_attach_adapter(struct i2c_adapter *adapter);
160static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
161static int lm78_detach_client(struct i2c_client *client);
162
163static int lm78_read_value(struct i2c_client *client, u8 register);
164static int lm78_write_value(struct i2c_client *client, u8 register, u8 value);
165static struct lm78_data *lm78_update_device(struct device *dev);
166static void lm78_init_client(struct i2c_client *client);
167
168
169static struct i2c_driver lm78_driver = {
170 .owner = THIS_MODULE,
171 .name = "lm78",
172 .id = I2C_DRIVERID_LM78,
173 .flags = I2C_DF_NOTIFY,
174 .attach_adapter = lm78_attach_adapter,
175 .detach_client = lm78_detach_client,
176};
177
178/* 7 Voltages */
179static ssize_t show_in(struct device *dev, char *buf, int nr)
180{
181 struct lm78_data *data = lm78_update_device(dev);
182 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
183}
184
185static ssize_t show_in_min(struct device *dev, char *buf, int nr)
186{
187 struct lm78_data *data = lm78_update_device(dev);
188 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
189}
190
191static ssize_t show_in_max(struct device *dev, char *buf, int nr)
192{
193 struct lm78_data *data = lm78_update_device(dev);
194 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
195}
196
197static ssize_t set_in_min(struct device *dev, const char *buf,
198 size_t count, int nr)
199{
200 struct i2c_client *client = to_i2c_client(dev);
201 struct lm78_data *data = i2c_get_clientdata(client);
202 unsigned long val = simple_strtoul(buf, NULL, 10);
203
204 down(&data->update_lock);
205 data->in_min[nr] = IN_TO_REG(val);
206 lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]);
207 up(&data->update_lock);
208 return count;
209}
210
211static ssize_t set_in_max(struct device *dev, const char *buf,
212 size_t count, int nr)
213{
214 struct i2c_client *client = to_i2c_client(dev);
215 struct lm78_data *data = i2c_get_clientdata(client);
216 unsigned long val = simple_strtoul(buf, NULL, 10);
217
218 down(&data->update_lock);
219 data->in_max[nr] = IN_TO_REG(val);
220 lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]);
221 up(&data->update_lock);
222 return count;
223}
224
225#define show_in_offset(offset) \
226static ssize_t \
227 show_in##offset (struct device *dev, char *buf) \
228{ \
229 return show_in(dev, buf, offset); \
230} \
231static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
232 show_in##offset, NULL); \
233static ssize_t \
234 show_in##offset##_min (struct device *dev, char *buf) \
235{ \
236 return show_in_min(dev, buf, offset); \
237} \
238static ssize_t \
239 show_in##offset##_max (struct device *dev, char *buf) \
240{ \
241 return show_in_max(dev, buf, offset); \
242} \
243static ssize_t set_in##offset##_min (struct device *dev, \
244 const char *buf, size_t count) \
245{ \
246 return set_in_min(dev, buf, count, offset); \
247} \
248static ssize_t set_in##offset##_max (struct device *dev, \
249 const char *buf, size_t count) \
250{ \
251 return set_in_max(dev, buf, count, offset); \
252} \
253static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
254 show_in##offset##_min, set_in##offset##_min); \
255static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
256 show_in##offset##_max, set_in##offset##_max);
257
258show_in_offset(0);
259show_in_offset(1);
260show_in_offset(2);
261show_in_offset(3);
262show_in_offset(4);
263show_in_offset(5);
264show_in_offset(6);
265
266/* Temperature */
267static ssize_t show_temp(struct device *dev, char *buf)
268{
269 struct lm78_data *data = lm78_update_device(dev);
270 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
271}
272
273static ssize_t show_temp_over(struct device *dev, char *buf)
274{
275 struct lm78_data *data = lm78_update_device(dev);
276 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
277}
278
279static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count)
280{
281 struct i2c_client *client = to_i2c_client(dev);
282 struct lm78_data *data = i2c_get_clientdata(client);
283 long val = simple_strtol(buf, NULL, 10);
284
285 down(&data->update_lock);
286 data->temp_over = TEMP_TO_REG(val);
287 lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over);
288 up(&data->update_lock);
289 return count;
290}
291
292static ssize_t show_temp_hyst(struct device *dev, char *buf)
293{
294 struct lm78_data *data = lm78_update_device(dev);
295 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
296}
297
298static ssize_t set_temp_hyst(struct device *dev, const char *buf, size_t count)
299{
300 struct i2c_client *client = to_i2c_client(dev);
301 struct lm78_data *data = i2c_get_clientdata(client);
302 long val = simple_strtol(buf, NULL, 10);
303
304 down(&data->update_lock);
305 data->temp_hyst = TEMP_TO_REG(val);
306 lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst);
307 up(&data->update_lock);
308 return count;
309}
310
311static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
312static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
313 show_temp_over, set_temp_over);
314static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
315 show_temp_hyst, set_temp_hyst);
316
317/* 3 Fans */
318static ssize_t show_fan(struct device *dev, char *buf, int nr)
319{
320 struct lm78_data *data = lm78_update_device(dev);
321 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
322 DIV_FROM_REG(data->fan_div[nr])) );
323}
324
325static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
326{
327 struct lm78_data *data = lm78_update_device(dev);
328 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
329 DIV_FROM_REG(data->fan_div[nr])) );
330}
331
332static ssize_t set_fan_min(struct device *dev, const char *buf,
333 size_t count, int nr)
334{
335 struct i2c_client *client = to_i2c_client(dev);
336 struct lm78_data *data = i2c_get_clientdata(client);
337 unsigned long val = simple_strtoul(buf, NULL, 10);
338
339 down(&data->update_lock);
340 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
341 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
342 up(&data->update_lock);
343 return count;
344}
345
346static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
347{
348 struct lm78_data *data = lm78_update_device(dev);
349 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
350}
351
352/* Note: we save and restore the fan minimum here, because its value is
353 determined in part by the fan divisor. This follows the principle of
354 least suprise; the user doesn't expect the fan minimum to change just
355 because the divisor changed. */
356static ssize_t set_fan_div(struct device *dev, const char *buf,
357 size_t count, int nr)
358{
359 struct i2c_client *client = to_i2c_client(dev);
360 struct lm78_data *data = i2c_get_clientdata(client);
361 unsigned long val = simple_strtoul(buf, NULL, 10);
362 unsigned long min;
363 u8 reg;
364
365 down(&data->update_lock);
366 min = FAN_FROM_REG(data->fan_min[nr],
367 DIV_FROM_REG(data->fan_div[nr]));
368
369 switch (val) {
370 case 1: data->fan_div[nr] = 0; break;
371 case 2: data->fan_div[nr] = 1; break;
372 case 4: data->fan_div[nr] = 2; break;
373 case 8: data->fan_div[nr] = 3; break;
374 default:
375 dev_err(&client->dev, "fan_div value %ld not "
376 "supported. Choose one of 1, 2, 4 or 8!\n", val);
377 up(&data->update_lock);
378 return -EINVAL;
379 }
380
381 reg = lm78_read_value(client, LM78_REG_VID_FANDIV);
382 switch (nr) {
383 case 0:
384 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
385 break;
386 case 1:
387 reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
388 break;
389 }
390 lm78_write_value(client, LM78_REG_VID_FANDIV, reg);
391
392 data->fan_min[nr] =
393 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
394 lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
395 up(&data->update_lock);
396
397 return count;
398}
399
400#define show_fan_offset(offset) \
401static ssize_t show_fan_##offset (struct device *dev, char *buf) \
402{ \
403 return show_fan(dev, buf, offset - 1); \
404} \
405static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
406{ \
407 return show_fan_min(dev, buf, offset - 1); \
408} \
409static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
410{ \
411 return show_fan_div(dev, buf, offset - 1); \
412} \
413static ssize_t set_fan_##offset##_min (struct device *dev, \
414 const char *buf, size_t count) \
415{ \
416 return set_fan_min(dev, buf, count, offset - 1); \
417} \
418static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
419static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
420 show_fan_##offset##_min, set_fan_##offset##_min);
421
422static ssize_t set_fan_1_div(struct device *dev, const char *buf,
423 size_t count)
424{
425 return set_fan_div(dev, buf, count, 0) ;
426}
427
428static ssize_t set_fan_2_div(struct device *dev, const char *buf,
429 size_t count)
430{
431 return set_fan_div(dev, buf, count, 1) ;
432}
433
434show_fan_offset(1);
435show_fan_offset(2);
436show_fan_offset(3);
437
438/* Fan 3 divisor is locked in H/W */
439static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
440 show_fan_1_div, set_fan_1_div);
441static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
442 show_fan_2_div, set_fan_2_div);
443static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL);
444
445/* VID */
446static ssize_t show_vid(struct device *dev, char *buf)
447{
448 struct lm78_data *data = lm78_update_device(dev);
449 return sprintf(buf, "%d\n", VID_FROM_REG(data->vid));
450}
451static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
452
453/* Alarms */
454static ssize_t show_alarms(struct device *dev, char *buf)
455{
456 struct lm78_data *data = lm78_update_device(dev);
457 return sprintf(buf, "%u\n", data->alarms);
458}
459static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
460
461/* This function is called when:
462 * lm78_driver is inserted (when this module is loaded), for each
463 available adapter
464 * when a new adapter is inserted (and lm78_driver is still present) */
465static int lm78_attach_adapter(struct i2c_adapter *adapter)
466{
467 if (!(adapter->class & I2C_CLASS_HWMON))
468 return 0;
469 return i2c_detect(adapter, &addr_data, lm78_detect);
470}
471
472/* This function is called by i2c_detect */
473int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
474{
475 int i, err;
476 struct i2c_client *new_client;
477 struct lm78_data *data;
478 const char *client_name = "";
479 int is_isa = i2c_is_isa_adapter(adapter);
480
481 if (!is_isa &&
482 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
483 err = -ENODEV;
484 goto ERROR0;
485 }
486
487 /* Reserve the ISA region */
488 if (is_isa)
489 if (!request_region(address, LM78_EXTENT, lm78_driver.name)) {
490 err = -EBUSY;
491 goto ERROR0;
492 }
493
494 /* Probe whether there is anything available on this address. Already
495 done for SMBus clients */
496 if (kind < 0) {
497 if (is_isa) {
498
499#define REALLY_SLOW_IO
500 /* We need the timeouts for at least some LM78-like
501 chips. But only if we read 'undefined' registers. */
502 i = inb_p(address + 1);
503 if (inb_p(address + 2) != i) {
504 err = -ENODEV;
505 goto ERROR1;
506 }
507 if (inb_p(address + 3) != i) {
508 err = -ENODEV;
509 goto ERROR1;
510 }
511 if (inb_p(address + 7) != i) {
512 err = -ENODEV;
513 goto ERROR1;
514 }
515#undef REALLY_SLOW_IO
516
517 /* Let's just hope nothing breaks here */
518 i = inb_p(address + 5) & 0x7f;
519 outb_p(~i & 0x7f, address + 5);
520 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
521 outb_p(i, address + 5);
522 err = -ENODEV;
523 goto ERROR1;
524 }
525 }
526 }
527
528 /* OK. For now, we presume we have a valid client. We now create the
529 client structure, even though we cannot fill it completely yet.
530 But it allows us to access lm78_{read,write}_value. */
531
532 if (!(data = kmalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
533 err = -ENOMEM;
534 goto ERROR1;
535 }
536 memset(data, 0, sizeof(struct lm78_data));
537
538 new_client = &data->client;
539 if (is_isa)
540 init_MUTEX(&data->lock);
541 i2c_set_clientdata(new_client, data);
542 new_client->addr = address;
543 new_client->adapter = adapter;
544 new_client->driver = &lm78_driver;
545 new_client->flags = 0;
546
547 /* Now, we do the remaining detection. */
548 if (kind < 0) {
549 if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) {
550 err = -ENODEV;
551 goto ERROR2;
552 }
553 if (!is_isa && (lm78_read_value(
554 new_client, LM78_REG_I2C_ADDR) != address)) {
555 err = -ENODEV;
556 goto ERROR2;
557 }
558 }
559
560 /* Determine the chip type. */
561 if (kind <= 0) {
562 i = lm78_read_value(new_client, LM78_REG_CHIPID);
563 if (i == 0x00 || i == 0x20)
564 kind = lm78;
565 else if (i == 0x40)
566 kind = lm78j;
567 else if ((i & 0xfe) == 0xc0)
568 kind = lm79;
569 else {
570 if (kind == 0)
571 dev_warn(&adapter->dev, "Ignoring 'force' "
572 "parameter for unknown chip at "
573 "adapter %d, address 0x%02x\n",
574 i2c_adapter_id(adapter), address);
575 err = -ENODEV;
576 goto ERROR2;
577 }
578 }
579
580 if (kind == lm78) {
581 client_name = "lm78";
582 } else if (kind == lm78j) {
583 client_name = "lm78-j";
584 } else if (kind == lm79) {
585 client_name = "lm79";
586 }
587
588 /* Fill in the remaining client fields and put into the global list */
589 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
590 data->type = kind;
591
592 data->valid = 0;
593 init_MUTEX(&data->update_lock);
594
595 /* Tell the I2C layer a new client has arrived */
596 if ((err = i2c_attach_client(new_client)))
597 goto ERROR2;
598
599 /* Initialize the LM78 chip */
600 lm78_init_client(new_client);
601
602 /* A few vars need to be filled upon startup */
603 for (i = 0; i < 3; i++) {
604 data->fan_min[i] = lm78_read_value(new_client,
605 LM78_REG_FAN_MIN(i));
606 }
607
608 /* Register sysfs hooks */
609 device_create_file(&new_client->dev, &dev_attr_in0_input);
610 device_create_file(&new_client->dev, &dev_attr_in0_min);
611 device_create_file(&new_client->dev, &dev_attr_in0_max);
612 device_create_file(&new_client->dev, &dev_attr_in1_input);
613 device_create_file(&new_client->dev, &dev_attr_in1_min);
614 device_create_file(&new_client->dev, &dev_attr_in1_max);
615 device_create_file(&new_client->dev, &dev_attr_in2_input);
616 device_create_file(&new_client->dev, &dev_attr_in2_min);
617 device_create_file(&new_client->dev, &dev_attr_in2_max);
618 device_create_file(&new_client->dev, &dev_attr_in3_input);
619 device_create_file(&new_client->dev, &dev_attr_in3_min);
620 device_create_file(&new_client->dev, &dev_attr_in3_max);
621 device_create_file(&new_client->dev, &dev_attr_in4_input);
622 device_create_file(&new_client->dev, &dev_attr_in4_min);
623 device_create_file(&new_client->dev, &dev_attr_in4_max);
624 device_create_file(&new_client->dev, &dev_attr_in5_input);
625 device_create_file(&new_client->dev, &dev_attr_in5_min);
626 device_create_file(&new_client->dev, &dev_attr_in5_max);
627 device_create_file(&new_client->dev, &dev_attr_in6_input);
628 device_create_file(&new_client->dev, &dev_attr_in6_min);
629 device_create_file(&new_client->dev, &dev_attr_in6_max);
630 device_create_file(&new_client->dev, &dev_attr_temp1_input);
631 device_create_file(&new_client->dev, &dev_attr_temp1_max);
632 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
633 device_create_file(&new_client->dev, &dev_attr_fan1_input);
634 device_create_file(&new_client->dev, &dev_attr_fan1_min);
635 device_create_file(&new_client->dev, &dev_attr_fan1_div);
636 device_create_file(&new_client->dev, &dev_attr_fan2_input);
637 device_create_file(&new_client->dev, &dev_attr_fan2_min);
638 device_create_file(&new_client->dev, &dev_attr_fan2_div);
639 device_create_file(&new_client->dev, &dev_attr_fan3_input);
640 device_create_file(&new_client->dev, &dev_attr_fan3_min);
641 device_create_file(&new_client->dev, &dev_attr_fan3_div);
642 device_create_file(&new_client->dev, &dev_attr_alarms);
643 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
644
645 return 0;
646
647ERROR2:
648 kfree(data);
649ERROR1:
650 if (is_isa)
651 release_region(address, LM78_EXTENT);
652ERROR0:
653 return err;
654}
655
656static int lm78_detach_client(struct i2c_client *client)
657{
658 int err;
659
660 if ((err = i2c_detach_client(client))) {
661 dev_err(&client->dev,
662 "Client deregistration failed, client not detached.\n");
663 return err;
664 }
665
666 if(i2c_is_isa_client(client))
667 release_region(client->addr, LM78_EXTENT);
668
669 kfree(i2c_get_clientdata(client));
670
671 return 0;
672}
673
674/* The SMBus locks itself, but ISA access must be locked explicitely!
675 We don't want to lock the whole ISA bus, so we lock each client
676 separately.
677 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
678 would slow down the LM78 access and should not be necessary. */
679static int lm78_read_value(struct i2c_client *client, u8 reg)
680{
681 int res;
682 if (i2c_is_isa_client(client)) {
683 struct lm78_data *data = i2c_get_clientdata(client);
684 down(&data->lock);
685 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
686 res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
687 up(&data->lock);
688 return res;
689 } else
690 return i2c_smbus_read_byte_data(client, reg);
691}
692
693/* The SMBus locks itself, but ISA access muse be locked explicitely!
694 We don't want to lock the whole ISA bus, so we lock each client
695 separately.
696 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
697 would slow down the LM78 access and should not be necessary.
698 There are some ugly typecasts here, but the good new is - they should
699 nowhere else be necessary! */
700static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
701{
702 if (i2c_is_isa_client(client)) {
703 struct lm78_data *data = i2c_get_clientdata(client);
704 down(&data->lock);
705 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
706 outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
707 up(&data->lock);
708 return 0;
709 } else
710 return i2c_smbus_write_byte_data(client, reg, value);
711}
712
713/* Called when we have found a new LM78. It should set limits, etc. */
714static void lm78_init_client(struct i2c_client *client)
715{
716 u8 config = lm78_read_value(client, LM78_REG_CONFIG);
717
718 /* Start monitoring */
719 if (!(config & 0x01))
720 lm78_write_value(client, LM78_REG_CONFIG,
721 (config & 0xf7) | 0x01);
722}
723
724static struct lm78_data *lm78_update_device(struct device *dev)
725{
726 struct i2c_client *client = to_i2c_client(dev);
727 struct lm78_data *data = i2c_get_clientdata(client);
728 int i;
729
730 down(&data->update_lock);
731
732 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
733 || !data->valid) {
734
735 dev_dbg(&client->dev, "Starting lm78 update\n");
736
737 for (i = 0; i <= 6; i++) {
738 data->in[i] =
739 lm78_read_value(client, LM78_REG_IN(i));
740 data->in_min[i] =
741 lm78_read_value(client, LM78_REG_IN_MIN(i));
742 data->in_max[i] =
743 lm78_read_value(client, LM78_REG_IN_MAX(i));
744 }
745 for (i = 0; i < 3; i++) {
746 data->fan[i] =
747 lm78_read_value(client, LM78_REG_FAN(i));
748 data->fan_min[i] =
749 lm78_read_value(client, LM78_REG_FAN_MIN(i));
750 }
751 data->temp = lm78_read_value(client, LM78_REG_TEMP);
752 data->temp_over =
753 lm78_read_value(client, LM78_REG_TEMP_OVER);
754 data->temp_hyst =
755 lm78_read_value(client, LM78_REG_TEMP_HYST);
756 i = lm78_read_value(client, LM78_REG_VID_FANDIV);
757 data->vid = i & 0x0f;
758 if (data->type == lm79)
759 data->vid |=
760 (lm78_read_value(client, LM78_REG_CHIPID) &
761 0x01) << 4;
762 else
763 data->vid |= 0x10;
764 data->fan_div[0] = (i >> 4) & 0x03;
765 data->fan_div[1] = i >> 6;
766 data->alarms = lm78_read_value(client, LM78_REG_ALARM1) +
767 (lm78_read_value(client, LM78_REG_ALARM2) << 8);
768 data->last_updated = jiffies;
769 data->valid = 1;
770
771 data->fan_div[2] = 1;
772 }
773
774 up(&data->update_lock);
775
776 return data;
777}
778
779static int __init sm_lm78_init(void)
780{
781 return i2c_add_driver(&lm78_driver);
782}
783
784static void __exit sm_lm78_exit(void)
785{
786 i2c_del_driver(&lm78_driver);
787}
788
789
790
791MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
792MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver");
793MODULE_LICENSE("GPL");
794
795module_init(sm_lm78_init);
796module_exit(sm_lm78_exit);
diff --git a/drivers/i2c/chips/lm80.c b/drivers/i2c/chips/lm80.c
deleted file mode 100644
index a72f431971bb..000000000000
--- a/drivers/i2c/chips/lm80.c
+++ /dev/null
@@ -1,602 +0,0 @@
1/*
2 * lm80.c - From lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 * and Philip Edelbrock <phil@netroedge.com>
6 *
7 * Ported to Linux 2.6 by Tiago Sousa <mirage@kaotik.org>
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/config.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/jiffies.h>
29#include <linux/i2c.h>
30#include <linux/i2c-sensor.h>
31
32/* Addresses to scan */
33static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c,
34 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
35static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
36
37/* Insmod parameters */
38SENSORS_INSMOD_1(lm80);
39
40/* Many LM80 constants specified below */
41
42/* The LM80 registers */
43#define LM80_REG_IN_MAX(nr) (0x2a + (nr) * 2)
44#define LM80_REG_IN_MIN(nr) (0x2b + (nr) * 2)
45#define LM80_REG_IN(nr) (0x20 + (nr))
46
47#define LM80_REG_FAN1 0x28
48#define LM80_REG_FAN2 0x29
49#define LM80_REG_FAN_MIN(nr) (0x3b + (nr))
50
51#define LM80_REG_TEMP 0x27
52#define LM80_REG_TEMP_HOT_MAX 0x38
53#define LM80_REG_TEMP_HOT_HYST 0x39
54#define LM80_REG_TEMP_OS_MAX 0x3a
55#define LM80_REG_TEMP_OS_HYST 0x3b
56
57#define LM80_REG_CONFIG 0x00
58#define LM80_REG_ALARM1 0x01
59#define LM80_REG_ALARM2 0x02
60#define LM80_REG_MASK1 0x03
61#define LM80_REG_MASK2 0x04
62#define LM80_REG_FANDIV 0x05
63#define LM80_REG_RES 0x06
64
65
66/* Conversions. Rounding and limit checking is only done on the TO_REG
67 variants. Note that you should be a bit careful with which arguments
68 these macros are called: arguments may be evaluated more than once.
69 Fixing this is just not worth it. */
70
71#define IN_TO_REG(val) (SENSORS_LIMIT(((val)+5)/10,0,255))
72#define IN_FROM_REG(val) ((val)*10)
73
74static inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div)
75{
76 if (rpm == 0)
77 return 255;
78 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
79 return SENSORS_LIMIT((1350000 + rpm*div / 2) / (rpm*div), 1, 254);
80}
81
82#define FAN_FROM_REG(val,div) ((val)==0?-1:\
83 (val)==255?0:1350000/((div)*(val)))
84
85static inline long TEMP_FROM_REG(u16 temp)
86{
87 long res;
88
89 temp >>= 4;
90 if (temp < 0x0800)
91 res = 625 * (long) temp;
92 else
93 res = ((long) temp - 0x01000) * 625;
94
95 return res / 10;
96}
97
98#define TEMP_LIMIT_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
99
100#define TEMP_LIMIT_TO_REG(val) SENSORS_LIMIT((val)<0?\
101 ((val)-500)/1000:((val)+500)/1000,0,255)
102
103#define DIV_FROM_REG(val) (1 << (val))
104
105/*
106 * Client data (each client gets its own)
107 */
108
109struct lm80_data {
110 struct i2c_client client;
111 struct semaphore update_lock;
112 char valid; /* !=0 if following fields are valid */
113 unsigned long last_updated; /* In jiffies */
114
115 u8 in[7]; /* Register value */
116 u8 in_max[7]; /* Register value */
117 u8 in_min[7]; /* Register value */
118 u8 fan[2]; /* Register value */
119 u8 fan_min[2]; /* Register value */
120 u8 fan_div[2]; /* Register encoding, shifted right */
121 u16 temp; /* Register values, shifted right */
122 u8 temp_hot_max; /* Register value */
123 u8 temp_hot_hyst; /* Register value */
124 u8 temp_os_max; /* Register value */
125 u8 temp_os_hyst; /* Register value */
126 u16 alarms; /* Register encoding, combined */
127};
128
129/*
130 * Functions declaration
131 */
132
133static int lm80_attach_adapter(struct i2c_adapter *adapter);
134static int lm80_detect(struct i2c_adapter *adapter, int address, int kind);
135static void lm80_init_client(struct i2c_client *client);
136static int lm80_detach_client(struct i2c_client *client);
137static struct lm80_data *lm80_update_device(struct device *dev);
138static int lm80_read_value(struct i2c_client *client, u8 reg);
139static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value);
140
141/*
142 * Driver data (common to all clients)
143 */
144
145static struct i2c_driver lm80_driver = {
146 .owner = THIS_MODULE,
147 .name = "lm80",
148 .id = I2C_DRIVERID_LM80,
149 .flags = I2C_DF_NOTIFY,
150 .attach_adapter = lm80_attach_adapter,
151 .detach_client = lm80_detach_client,
152};
153
154/*
155 * Sysfs stuff
156 */
157
158#define show_in(suffix, value) \
159static ssize_t show_in_##suffix(struct device *dev, char *buf) \
160{ \
161 struct lm80_data *data = lm80_update_device(dev); \
162 return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \
163}
164show_in(min0, in_min[0]);
165show_in(min1, in_min[1]);
166show_in(min2, in_min[2]);
167show_in(min3, in_min[3]);
168show_in(min4, in_min[4]);
169show_in(min5, in_min[5]);
170show_in(min6, in_min[6]);
171show_in(max0, in_max[0]);
172show_in(max1, in_max[1]);
173show_in(max2, in_max[2]);
174show_in(max3, in_max[3]);
175show_in(max4, in_max[4]);
176show_in(max5, in_max[5]);
177show_in(max6, in_max[6]);
178show_in(input0, in[0]);
179show_in(input1, in[1]);
180show_in(input2, in[2]);
181show_in(input3, in[3]);
182show_in(input4, in[4]);
183show_in(input5, in[5]);
184show_in(input6, in[6]);
185
186#define set_in(suffix, value, reg) \
187static ssize_t set_in_##suffix(struct device *dev, const char *buf, \
188 size_t count) \
189{ \
190 struct i2c_client *client = to_i2c_client(dev); \
191 struct lm80_data *data = i2c_get_clientdata(client); \
192 long val = simple_strtol(buf, NULL, 10); \
193 \
194 down(&data->update_lock);\
195 data->value = IN_TO_REG(val); \
196 lm80_write_value(client, reg, data->value); \
197 up(&data->update_lock);\
198 return count; \
199}
200set_in(min0, in_min[0], LM80_REG_IN_MIN(0));
201set_in(min1, in_min[1], LM80_REG_IN_MIN(1));
202set_in(min2, in_min[2], LM80_REG_IN_MIN(2));
203set_in(min3, in_min[3], LM80_REG_IN_MIN(3));
204set_in(min4, in_min[4], LM80_REG_IN_MIN(4));
205set_in(min5, in_min[5], LM80_REG_IN_MIN(5));
206set_in(min6, in_min[6], LM80_REG_IN_MIN(6));
207set_in(max0, in_max[0], LM80_REG_IN_MAX(0));
208set_in(max1, in_max[1], LM80_REG_IN_MAX(1));
209set_in(max2, in_max[2], LM80_REG_IN_MAX(2));
210set_in(max3, in_max[3], LM80_REG_IN_MAX(3));
211set_in(max4, in_max[4], LM80_REG_IN_MAX(4));
212set_in(max5, in_max[5], LM80_REG_IN_MAX(5));
213set_in(max6, in_max[6], LM80_REG_IN_MAX(6));
214
215#define show_fan(suffix, value, div) \
216static ssize_t show_fan_##suffix(struct device *dev, char *buf) \
217{ \
218 struct lm80_data *data = lm80_update_device(dev); \
219 return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \
220 DIV_FROM_REG(data->div))); \
221}
222show_fan(min1, fan_min[0], fan_div[0]);
223show_fan(min2, fan_min[1], fan_div[1]);
224show_fan(input1, fan[0], fan_div[0]);
225show_fan(input2, fan[1], fan_div[1]);
226
227#define show_fan_div(suffix, value) \
228static ssize_t show_fan_div##suffix(struct device *dev, char *buf) \
229{ \
230 struct lm80_data *data = lm80_update_device(dev); \
231 return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \
232}
233show_fan_div(1, fan_div[0]);
234show_fan_div(2, fan_div[1]);
235
236#define set_fan(suffix, value, reg, div) \
237static ssize_t set_fan_##suffix(struct device *dev, const char *buf, \
238 size_t count) \
239{ \
240 struct i2c_client *client = to_i2c_client(dev); \
241 struct lm80_data *data = i2c_get_clientdata(client); \
242 long val = simple_strtoul(buf, NULL, 10); \
243 \
244 down(&data->update_lock);\
245 data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \
246 lm80_write_value(client, reg, data->value); \
247 up(&data->update_lock);\
248 return count; \
249}
250set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
251set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]);
252
253/* Note: we save and restore the fan minimum here, because its value is
254 determined in part by the fan divisor. This follows the principle of
255 least suprise; the user doesn't expect the fan minimum to change just
256 because the divisor changed. */
257static ssize_t set_fan_div(struct device *dev, const char *buf,
258 size_t count, int nr)
259{
260 struct i2c_client *client = to_i2c_client(dev);
261 struct lm80_data *data = i2c_get_clientdata(client);
262 unsigned long min, val = simple_strtoul(buf, NULL, 10);
263 u8 reg;
264
265 /* Save fan_min */
266 down(&data->update_lock);
267 min = FAN_FROM_REG(data->fan_min[nr],
268 DIV_FROM_REG(data->fan_div[nr]));
269
270 switch (val) {
271 case 1: data->fan_div[nr] = 0; break;
272 case 2: data->fan_div[nr] = 1; break;
273 case 4: data->fan_div[nr] = 2; break;
274 case 8: data->fan_div[nr] = 3; break;
275 default:
276 dev_err(&client->dev, "fan_div value %ld not "
277 "supported. Choose one of 1, 2, 4 or 8!\n", val);
278 up(&data->update_lock);
279 return -EINVAL;
280 }
281
282 reg = (lm80_read_value(client, LM80_REG_FANDIV) & ~(3 << (2 * (nr + 1))))
283 | (data->fan_div[nr] << (2 * (nr + 1)));
284 lm80_write_value(client, LM80_REG_FANDIV, reg);
285
286 /* Restore fan_min */
287 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
288 lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
289 up(&data->update_lock);
290
291 return count;
292}
293
294#define set_fan_div(number) \
295static ssize_t set_fan_div##number(struct device *dev, const char *buf, \
296 size_t count) \
297{ \
298 return set_fan_div(dev, buf, count, number - 1); \
299}
300set_fan_div(1);
301set_fan_div(2);
302
303static ssize_t show_temp_input1(struct device *dev, char *buf)
304{
305 struct lm80_data *data = lm80_update_device(dev);
306 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp));
307}
308
309#define show_temp(suffix, value) \
310static ssize_t show_temp_##suffix(struct device *dev, char *buf) \
311{ \
312 struct lm80_data *data = lm80_update_device(dev); \
313 return sprintf(buf, "%d\n", TEMP_LIMIT_FROM_REG(data->value)); \
314}
315show_temp(hot_max, temp_hot_max);
316show_temp(hot_hyst, temp_hot_hyst);
317show_temp(os_max, temp_os_max);
318show_temp(os_hyst, temp_os_hyst);
319
320#define set_temp(suffix, value, reg) \
321static ssize_t set_temp_##suffix(struct device *dev, const char *buf, \
322 size_t count) \
323{ \
324 struct i2c_client *client = to_i2c_client(dev); \
325 struct lm80_data *data = i2c_get_clientdata(client); \
326 long val = simple_strtoul(buf, NULL, 10); \
327 \
328 down(&data->update_lock); \
329 data->value = TEMP_LIMIT_TO_REG(val); \
330 lm80_write_value(client, reg, data->value); \
331 up(&data->update_lock); \
332 return count; \
333}
334set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX);
335set_temp(hot_hyst, temp_hot_hyst, LM80_REG_TEMP_HOT_HYST);
336set_temp(os_max, temp_os_max, LM80_REG_TEMP_OS_MAX);
337set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST);
338
339static ssize_t show_alarms(struct device *dev, char *buf)
340{
341 struct lm80_data *data = lm80_update_device(dev);
342 return sprintf(buf, "%u\n", data->alarms);
343}
344
345static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0);
346static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1);
347static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2);
348static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3);
349static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4);
350static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5);
351static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6);
352static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0);
353static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1);
354static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2);
355static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3);
356static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4);
357static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5);
358static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6);
359static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL);
360static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL);
361static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL);
362static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL);
363static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL);
364static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL);
365static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL);
366static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1,
367 set_fan_min1);
368static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2,
369 set_fan_min2);
370static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL);
371static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL);
372static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1);
373static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2);
374static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
375static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max,
376 set_temp_hot_max);
377static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_temp_hot_hyst,
378 set_temp_hot_hyst);
379static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_os_max,
380 set_temp_os_max);
381static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_os_hyst,
382 set_temp_os_hyst);
383static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
384
385/*
386 * Real code
387 */
388
389static int lm80_attach_adapter(struct i2c_adapter *adapter)
390{
391 if (!(adapter->class & I2C_CLASS_HWMON))
392 return 0;
393 return i2c_detect(adapter, &addr_data, lm80_detect);
394}
395
396int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
397{
398 int i, cur;
399 struct i2c_client *new_client;
400 struct lm80_data *data;
401 int err = 0;
402 const char *name;
403
404 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
405 goto exit;
406
407 /* OK. For now, we presume we have a valid client. We now create the
408 client structure, even though we cannot fill it completely yet.
409 But it allows us to access lm80_{read,write}_value. */
410 if (!(data = kmalloc(sizeof(struct lm80_data), GFP_KERNEL))) {
411 err = -ENOMEM;
412 goto exit;
413 }
414 memset(data, 0, sizeof(struct lm80_data));
415
416 new_client = &data->client;
417 i2c_set_clientdata(new_client, data);
418 new_client->addr = address;
419 new_client->adapter = adapter;
420 new_client->driver = &lm80_driver;
421 new_client->flags = 0;
422
423 /* Now, we do the remaining detection. It is lousy. */
424 if (lm80_read_value(new_client, LM80_REG_ALARM2) & 0xc0)
425 goto error_free;
426 for (i = 0x2a; i <= 0x3d; i++) {
427 cur = i2c_smbus_read_byte_data(new_client, i);
428 if ((i2c_smbus_read_byte_data(new_client, i + 0x40) != cur)
429 || (i2c_smbus_read_byte_data(new_client, i + 0x80) != cur)
430 || (i2c_smbus_read_byte_data(new_client, i + 0xc0) != cur))
431 goto error_free;
432 }
433
434 /* Determine the chip type - only one kind supported! */
435 kind = lm80;
436 name = "lm80";
437
438 /* Fill in the remaining client fields and put it into the global list */
439 strlcpy(new_client->name, name, I2C_NAME_SIZE);
440 data->valid = 0;
441 init_MUTEX(&data->update_lock);
442
443 /* Tell the I2C layer a new client has arrived */
444 if ((err = i2c_attach_client(new_client)))
445 goto error_free;
446
447 /* Initialize the LM80 chip */
448 lm80_init_client(new_client);
449
450 /* A few vars need to be filled upon startup */
451 data->fan_min[0] = lm80_read_value(new_client, LM80_REG_FAN_MIN(1));
452 data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
453
454 /* Register sysfs hooks */
455 device_create_file(&new_client->dev, &dev_attr_in0_min);
456 device_create_file(&new_client->dev, &dev_attr_in1_min);
457 device_create_file(&new_client->dev, &dev_attr_in2_min);
458 device_create_file(&new_client->dev, &dev_attr_in3_min);
459 device_create_file(&new_client->dev, &dev_attr_in4_min);
460 device_create_file(&new_client->dev, &dev_attr_in5_min);
461 device_create_file(&new_client->dev, &dev_attr_in6_min);
462 device_create_file(&new_client->dev, &dev_attr_in0_max);
463 device_create_file(&new_client->dev, &dev_attr_in1_max);
464 device_create_file(&new_client->dev, &dev_attr_in2_max);
465 device_create_file(&new_client->dev, &dev_attr_in3_max);
466 device_create_file(&new_client->dev, &dev_attr_in4_max);
467 device_create_file(&new_client->dev, &dev_attr_in5_max);
468 device_create_file(&new_client->dev, &dev_attr_in6_max);
469 device_create_file(&new_client->dev, &dev_attr_in0_input);
470 device_create_file(&new_client->dev, &dev_attr_in1_input);
471 device_create_file(&new_client->dev, &dev_attr_in2_input);
472 device_create_file(&new_client->dev, &dev_attr_in3_input);
473 device_create_file(&new_client->dev, &dev_attr_in4_input);
474 device_create_file(&new_client->dev, &dev_attr_in5_input);
475 device_create_file(&new_client->dev, &dev_attr_in6_input);
476 device_create_file(&new_client->dev, &dev_attr_fan1_min);
477 device_create_file(&new_client->dev, &dev_attr_fan2_min);
478 device_create_file(&new_client->dev, &dev_attr_fan1_input);
479 device_create_file(&new_client->dev, &dev_attr_fan2_input);
480 device_create_file(&new_client->dev, &dev_attr_fan1_div);
481 device_create_file(&new_client->dev, &dev_attr_fan2_div);
482 device_create_file(&new_client->dev, &dev_attr_temp1_input);
483 device_create_file(&new_client->dev, &dev_attr_temp1_max);
484 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
485 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
486 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
487 device_create_file(&new_client->dev, &dev_attr_alarms);
488
489 return 0;
490
491error_free:
492 kfree(data);
493exit:
494 return err;
495}
496
497static int lm80_detach_client(struct i2c_client *client)
498{
499 int err;
500
501 if ((err = i2c_detach_client(client))) {
502 dev_err(&client->dev, "Client deregistration failed, "
503 "client not detached.\n");
504 return err;
505 }
506
507 kfree(i2c_get_clientdata(client));
508 return 0;
509}
510
511static int lm80_read_value(struct i2c_client *client, u8 reg)
512{
513 return i2c_smbus_read_byte_data(client, reg);
514}
515
516static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value)
517{
518 return i2c_smbus_write_byte_data(client, reg, value);
519}
520
521/* Called when we have found a new LM80. */
522static void lm80_init_client(struct i2c_client *client)
523{
524 /* Reset all except Watchdog values and last conversion values
525 This sets fan-divs to 2, among others. This makes most other
526 initializations unnecessary */
527 lm80_write_value(client, LM80_REG_CONFIG, 0x80);
528 /* Set 11-bit temperature resolution */
529 lm80_write_value(client, LM80_REG_RES, 0x08);
530
531 /* Start monitoring */
532 lm80_write_value(client, LM80_REG_CONFIG, 0x01);
533}
534
535static struct lm80_data *lm80_update_device(struct device *dev)
536{
537 struct i2c_client *client = to_i2c_client(dev);
538 struct lm80_data *data = i2c_get_clientdata(client);
539 int i;
540
541 down(&data->update_lock);
542
543 if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) {
544 dev_dbg(&client->dev, "Starting lm80 update\n");
545 for (i = 0; i <= 6; i++) {
546 data->in[i] =
547 lm80_read_value(client, LM80_REG_IN(i));
548 data->in_min[i] =
549 lm80_read_value(client, LM80_REG_IN_MIN(i));
550 data->in_max[i] =
551 lm80_read_value(client, LM80_REG_IN_MAX(i));
552 }
553 data->fan[0] = lm80_read_value(client, LM80_REG_FAN1);
554 data->fan_min[0] =
555 lm80_read_value(client, LM80_REG_FAN_MIN(1));
556 data->fan[1] = lm80_read_value(client, LM80_REG_FAN2);
557 data->fan_min[1] =
558 lm80_read_value(client, LM80_REG_FAN_MIN(2));
559
560 data->temp =
561 (lm80_read_value(client, LM80_REG_TEMP) << 8) |
562 (lm80_read_value(client, LM80_REG_RES) & 0xf0);
563 data->temp_os_max =
564 lm80_read_value(client, LM80_REG_TEMP_OS_MAX);
565 data->temp_os_hyst =
566 lm80_read_value(client, LM80_REG_TEMP_OS_HYST);
567 data->temp_hot_max =
568 lm80_read_value(client, LM80_REG_TEMP_HOT_MAX);
569 data->temp_hot_hyst =
570 lm80_read_value(client, LM80_REG_TEMP_HOT_HYST);
571
572 i = lm80_read_value(client, LM80_REG_FANDIV);
573 data->fan_div[0] = (i >> 2) & 0x03;
574 data->fan_div[1] = (i >> 4) & 0x03;
575 data->alarms = lm80_read_value(client, LM80_REG_ALARM1) +
576 (lm80_read_value(client, LM80_REG_ALARM2) << 8);
577 data->last_updated = jiffies;
578 data->valid = 1;
579 }
580
581 up(&data->update_lock);
582
583 return data;
584}
585
586static int __init sensors_lm80_init(void)
587{
588 return i2c_add_driver(&lm80_driver);
589}
590
591static void __exit sensors_lm80_exit(void)
592{
593 i2c_del_driver(&lm80_driver);
594}
595
596MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and "
597 "Philip Edelbrock <phil@netroedge.com>");
598MODULE_DESCRIPTION("LM80 driver");
599MODULE_LICENSE("GPL");
600
601module_init(sensors_lm80_init);
602module_exit(sensors_lm80_exit);
diff --git a/drivers/i2c/chips/lm83.c b/drivers/i2c/chips/lm83.c
deleted file mode 100644
index 3dafe60766ad..000000000000
--- a/drivers/i2c/chips/lm83.c
+++ /dev/null
@@ -1,412 +0,0 @@
1/*
2 * lm83.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2003 Jean Delvare <khali@linux-fr.org>
5 *
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
8 * temperatures (its own plus up to three external ones) with a 1 deg
9 * resolution and a 3-4 deg accuracy. Complete datasheet can be obtained
10 * from National's website at:
11 * http://www.national.com/pf/LM/LM83.html
12 * Since the datasheet omits to give the chip stepping code, I give it
13 * here: 0x03 (at register 0xff).
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30#include <linux/config.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/slab.h>
34#include <linux/jiffies.h>
35#include <linux/i2c.h>
36#include <linux/i2c-sensor.h>
37
38/*
39 * Addresses to scan
40 * Address is selected using 2 three-level pins, resulting in 9 possible
41 * addresses.
42 */
43
44static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
45 0x29, 0x2a, 0x2b,
46 0x4c, 0x4d, 0x4e,
47 I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49
50/*
51 * Insmod parameters
52 */
53
54SENSORS_INSMOD_1(lm83);
55
56/*
57 * The LM83 registers
58 * Manufacturer ID is 0x01 for National Semiconductor.
59 */
60
61#define LM83_REG_R_MAN_ID 0xFE
62#define LM83_REG_R_CHIP_ID 0xFF
63#define LM83_REG_R_CONFIG 0x03
64#define LM83_REG_W_CONFIG 0x09
65#define LM83_REG_R_STATUS1 0x02
66#define LM83_REG_R_STATUS2 0x35
67#define LM83_REG_R_LOCAL_TEMP 0x00
68#define LM83_REG_R_LOCAL_HIGH 0x05
69#define LM83_REG_W_LOCAL_HIGH 0x0B
70#define LM83_REG_R_REMOTE1_TEMP 0x30
71#define LM83_REG_R_REMOTE1_HIGH 0x38
72#define LM83_REG_W_REMOTE1_HIGH 0x50
73#define LM83_REG_R_REMOTE2_TEMP 0x01
74#define LM83_REG_R_REMOTE2_HIGH 0x07
75#define LM83_REG_W_REMOTE2_HIGH 0x0D
76#define LM83_REG_R_REMOTE3_TEMP 0x31
77#define LM83_REG_R_REMOTE3_HIGH 0x3A
78#define LM83_REG_W_REMOTE3_HIGH 0x52
79#define LM83_REG_R_TCRIT 0x42
80#define LM83_REG_W_TCRIT 0x5A
81
82/*
83 * Conversions and various macros
84 * The LM83 uses signed 8-bit values with LSB = 1 degree Celcius.
85 */
86
87#define TEMP_FROM_REG(val) ((val) * 1000)
88#define TEMP_TO_REG(val) ((val) <= -128000 ? -128 : \
89 (val) >= 127000 ? 127 : \
90 (val) < 0 ? ((val) - 500) / 1000 : \
91 ((val) + 500) / 1000)
92
93static const u8 LM83_REG_R_TEMP[] = {
94 LM83_REG_R_LOCAL_TEMP,
95 LM83_REG_R_REMOTE1_TEMP,
96 LM83_REG_R_REMOTE2_TEMP,
97 LM83_REG_R_REMOTE3_TEMP
98};
99
100static const u8 LM83_REG_R_HIGH[] = {
101 LM83_REG_R_LOCAL_HIGH,
102 LM83_REG_R_REMOTE1_HIGH,
103 LM83_REG_R_REMOTE2_HIGH,
104 LM83_REG_R_REMOTE3_HIGH
105};
106
107static const u8 LM83_REG_W_HIGH[] = {
108 LM83_REG_W_LOCAL_HIGH,
109 LM83_REG_W_REMOTE1_HIGH,
110 LM83_REG_W_REMOTE2_HIGH,
111 LM83_REG_W_REMOTE3_HIGH
112};
113
114/*
115 * Functions declaration
116 */
117
118static int lm83_attach_adapter(struct i2c_adapter *adapter);
119static int lm83_detect(struct i2c_adapter *adapter, int address, int kind);
120static int lm83_detach_client(struct i2c_client *client);
121static struct lm83_data *lm83_update_device(struct device *dev);
122
123/*
124 * Driver data (common to all clients)
125 */
126
127static struct i2c_driver lm83_driver = {
128 .owner = THIS_MODULE,
129 .name = "lm83",
130 .id = I2C_DRIVERID_LM83,
131 .flags = I2C_DF_NOTIFY,
132 .attach_adapter = lm83_attach_adapter,
133 .detach_client = lm83_detach_client,
134};
135
136/*
137 * Client data (each client gets its own)
138 */
139
140struct lm83_data {
141 struct i2c_client client;
142 struct semaphore update_lock;
143 char valid; /* zero until following fields are valid */
144 unsigned long last_updated; /* in jiffies */
145
146 /* registers values */
147 s8 temp_input[4];
148 s8 temp_high[4];
149 s8 temp_crit;
150 u16 alarms; /* bitvector, combined */
151};
152
153/*
154 * Sysfs stuff
155 */
156
157#define show_temp(suffix, value) \
158static ssize_t show_temp_##suffix(struct device *dev, char *buf) \
159{ \
160 struct lm83_data *data = lm83_update_device(dev); \
161 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
162}
163show_temp(input1, temp_input[0]);
164show_temp(input2, temp_input[1]);
165show_temp(input3, temp_input[2]);
166show_temp(input4, temp_input[3]);
167show_temp(high1, temp_high[0]);
168show_temp(high2, temp_high[1]);
169show_temp(high3, temp_high[2]);
170show_temp(high4, temp_high[3]);
171show_temp(crit, temp_crit);
172
173#define set_temp(suffix, value, reg) \
174static ssize_t set_temp_##suffix(struct device *dev, const char *buf, \
175 size_t count) \
176{ \
177 struct i2c_client *client = to_i2c_client(dev); \
178 struct lm83_data *data = i2c_get_clientdata(client); \
179 long val = simple_strtol(buf, NULL, 10); \
180 \
181 down(&data->update_lock); \
182 data->value = TEMP_TO_REG(val); \
183 i2c_smbus_write_byte_data(client, reg, data->value); \
184 up(&data->update_lock); \
185 return count; \
186}
187set_temp(high1, temp_high[0], LM83_REG_W_LOCAL_HIGH);
188set_temp(high2, temp_high[1], LM83_REG_W_REMOTE1_HIGH);
189set_temp(high3, temp_high[2], LM83_REG_W_REMOTE2_HIGH);
190set_temp(high4, temp_high[3], LM83_REG_W_REMOTE3_HIGH);
191set_temp(crit, temp_crit, LM83_REG_W_TCRIT);
192
193static ssize_t show_alarms(struct device *dev, char *buf)
194{
195 struct lm83_data *data = lm83_update_device(dev);
196 return sprintf(buf, "%d\n", data->alarms);
197}
198
199static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
200static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input2, NULL);
201static DEVICE_ATTR(temp3_input, S_IRUGO, show_temp_input3, NULL);
202static DEVICE_ATTR(temp4_input, S_IRUGO, show_temp_input4, NULL);
203static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_high1,
204 set_temp_high1);
205static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_high2,
206 set_temp_high2);
207static DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_high3,
208 set_temp_high3);
209static DEVICE_ATTR(temp4_max, S_IWUSR | S_IRUGO, show_temp_high4,
210 set_temp_high4);
211static DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit, NULL);
212static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit, NULL);
213static DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp_crit,
214 set_temp_crit);
215static DEVICE_ATTR(temp4_crit, S_IRUGO, show_temp_crit, NULL);
216static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
217
218/*
219 * Real code
220 */
221
222static int lm83_attach_adapter(struct i2c_adapter *adapter)
223{
224 if (!(adapter->class & I2C_CLASS_HWMON))
225 return 0;
226 return i2c_detect(adapter, &addr_data, lm83_detect);
227}
228
229/*
230 * The following function does more than just detection. If detection
231 * succeeds, it also registers the new chip.
232 */
233static int lm83_detect(struct i2c_adapter *adapter, int address, int kind)
234{
235 struct i2c_client *new_client;
236 struct lm83_data *data;
237 int err = 0;
238 const char *name = "";
239
240 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
241 goto exit;
242
243 if (!(data = kmalloc(sizeof(struct lm83_data), GFP_KERNEL))) {
244 err = -ENOMEM;
245 goto exit;
246 }
247 memset(data, 0, sizeof(struct lm83_data));
248
249 /* The common I2C client data is placed right after the
250 * LM83-specific data. */
251 new_client = &data->client;
252 i2c_set_clientdata(new_client, data);
253 new_client->addr = address;
254 new_client->adapter = adapter;
255 new_client->driver = &lm83_driver;
256 new_client->flags = 0;
257
258 /* Now we do the detection and identification. A negative kind
259 * means that the driver was loaded with no force parameter
260 * (default), so we must both detect and identify the chip
261 * (actually there is only one possible kind of chip for now, LM83).
262 * A zero kind means that the driver was loaded with the force
263 * parameter, the detection step shall be skipped. A positive kind
264 * means that the driver was loaded with the force parameter and a
265 * given kind of chip is requested, so both the detection and the
266 * identification steps are skipped. */
267
268 /* Default to an LM83 if forced */
269 if (kind == 0)
270 kind = lm83;
271
272 if (kind < 0) { /* detection */
273 if (((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1)
274 & 0xA8) != 0x00) ||
275 ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2)
276 & 0x48) != 0x00) ||
277 ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG)
278 & 0x41) != 0x00)) {
279 dev_dbg(&adapter->dev,
280 "LM83 detection failed at 0x%02x.\n", address);
281 goto exit_free;
282 }
283 }
284
285 if (kind <= 0) { /* identification */
286 u8 man_id, chip_id;
287
288 man_id = i2c_smbus_read_byte_data(new_client,
289 LM83_REG_R_MAN_ID);
290 chip_id = i2c_smbus_read_byte_data(new_client,
291 LM83_REG_R_CHIP_ID);
292
293 if (man_id == 0x01) { /* National Semiconductor */
294 if (chip_id == 0x03) {
295 kind = lm83;
296 }
297 }
298
299 if (kind <= 0) { /* identification failed */
300 dev_info(&adapter->dev,
301 "Unsupported chip (man_id=0x%02X, "
302 "chip_id=0x%02X).\n", man_id, chip_id);
303 goto exit_free;
304 }
305 }
306
307 if (kind == lm83) {
308 name = "lm83";
309 }
310
311 /* We can fill in the remaining client fields */
312 strlcpy(new_client->name, name, I2C_NAME_SIZE);
313 data->valid = 0;
314 init_MUTEX(&data->update_lock);
315
316 /* Tell the I2C layer a new client has arrived */
317 if ((err = i2c_attach_client(new_client)))
318 goto exit_free;
319
320 /*
321 * Initialize the LM83 chip
322 * (Nothing to do for this one.)
323 */
324
325 /* Register sysfs hooks */
326 device_create_file(&new_client->dev, &dev_attr_temp1_input);
327 device_create_file(&new_client->dev, &dev_attr_temp2_input);
328 device_create_file(&new_client->dev, &dev_attr_temp3_input);
329 device_create_file(&new_client->dev, &dev_attr_temp4_input);
330 device_create_file(&new_client->dev, &dev_attr_temp1_max);
331 device_create_file(&new_client->dev, &dev_attr_temp2_max);
332 device_create_file(&new_client->dev, &dev_attr_temp3_max);
333 device_create_file(&new_client->dev, &dev_attr_temp4_max);
334 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
335 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
336 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
337 device_create_file(&new_client->dev, &dev_attr_temp4_crit);
338 device_create_file(&new_client->dev, &dev_attr_alarms);
339
340 return 0;
341
342exit_free:
343 kfree(data);
344exit:
345 return err;
346}
347
348static int lm83_detach_client(struct i2c_client *client)
349{
350 int err;
351
352 if ((err = i2c_detach_client(client))) {
353 dev_err(&client->dev,
354 "Client deregistration failed, client not detached.\n");
355 return err;
356 }
357
358 kfree(i2c_get_clientdata(client));
359 return 0;
360}
361
362static struct lm83_data *lm83_update_device(struct device *dev)
363{
364 struct i2c_client *client = to_i2c_client(dev);
365 struct lm83_data *data = i2c_get_clientdata(client);
366
367 down(&data->update_lock);
368
369 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
370 int nr;
371
372 dev_dbg(&client->dev, "Updating lm83 data.\n");
373 for (nr = 0; nr < 4 ; nr++) {
374 data->temp_input[nr] =
375 i2c_smbus_read_byte_data(client,
376 LM83_REG_R_TEMP[nr]);
377 data->temp_high[nr] =
378 i2c_smbus_read_byte_data(client,
379 LM83_REG_R_HIGH[nr]);
380 }
381 data->temp_crit =
382 i2c_smbus_read_byte_data(client, LM83_REG_R_TCRIT);
383 data->alarms =
384 i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS1)
385 + (i2c_smbus_read_byte_data(client, LM83_REG_R_STATUS2)
386 << 8);
387
388 data->last_updated = jiffies;
389 data->valid = 1;
390 }
391
392 up(&data->update_lock);
393
394 return data;
395}
396
397static int __init sensors_lm83_init(void)
398{
399 return i2c_add_driver(&lm83_driver);
400}
401
402static void __exit sensors_lm83_exit(void)
403{
404 i2c_del_driver(&lm83_driver);
405}
406
407MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
408MODULE_DESCRIPTION("LM83 driver");
409MODULE_LICENSE("GPL");
410
411module_init(sensors_lm83_init);
412module_exit(sensors_lm83_exit);
diff --git a/drivers/i2c/chips/lm85.c b/drivers/i2c/chips/lm85.c
deleted file mode 100644
index b1a0dc5f6b34..000000000000
--- a/drivers/i2c/chips/lm85.c
+++ /dev/null
@@ -1,1578 +0,0 @@
1/*
2 lm85.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2002, 2003 Philip Pokorny <ppokorny@penguincomputing.com>
6 Copyright (c) 2003 Margit Schubert-While <margitsw@t-online.de>
7 Copyright (c) 2004 Justin Thiessen <jthiessen@penguincomputing.com>
8
9 Chip details at <http://www.national.com/ds/LM/LM85.pdf>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26#include <linux/config.h>
27#include <linux/module.h>
28#include <linux/init.h>
29#include <linux/slab.h>
30#include <linux/jiffies.h>
31#include <linux/i2c.h>
32#include <linux/i2c-sensor.h>
33#include <linux/i2c-vid.h>
34
35/* Addresses to scan */
36static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
37static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
38
39/* Insmod parameters */
40SENSORS_INSMOD_6(lm85b, lm85c, adm1027, adt7463, emc6d100, emc6d102);
41
42/* The LM85 registers */
43
44#define LM85_REG_IN(nr) (0x20 + (nr))
45#define LM85_REG_IN_MIN(nr) (0x44 + (nr) * 2)
46#define LM85_REG_IN_MAX(nr) (0x45 + (nr) * 2)
47
48#define LM85_REG_TEMP(nr) (0x25 + (nr))
49#define LM85_REG_TEMP_MIN(nr) (0x4e + (nr) * 2)
50#define LM85_REG_TEMP_MAX(nr) (0x4f + (nr) * 2)
51
52/* Fan speeds are LSB, MSB (2 bytes) */
53#define LM85_REG_FAN(nr) (0x28 + (nr) *2)
54#define LM85_REG_FAN_MIN(nr) (0x54 + (nr) *2)
55
56#define LM85_REG_PWM(nr) (0x30 + (nr))
57
58#define ADT7463_REG_OPPOINT(nr) (0x33 + (nr))
59
60#define ADT7463_REG_TMIN_CTL1 0x36
61#define ADT7463_REG_TMIN_CTL2 0x37
62
63#define LM85_REG_DEVICE 0x3d
64#define LM85_REG_COMPANY 0x3e
65#define LM85_REG_VERSTEP 0x3f
66/* These are the recognized values for the above regs */
67#define LM85_DEVICE_ADX 0x27
68#define LM85_COMPANY_NATIONAL 0x01
69#define LM85_COMPANY_ANALOG_DEV 0x41
70#define LM85_COMPANY_SMSC 0x5c
71#define LM85_VERSTEP_VMASK 0xf0
72#define LM85_VERSTEP_GENERIC 0x60
73#define LM85_VERSTEP_LM85C 0x60
74#define LM85_VERSTEP_LM85B 0x62
75#define LM85_VERSTEP_ADM1027 0x60
76#define LM85_VERSTEP_ADT7463 0x62
77#define LM85_VERSTEP_ADT7463C 0x6A
78#define LM85_VERSTEP_EMC6D100_A0 0x60
79#define LM85_VERSTEP_EMC6D100_A1 0x61
80#define LM85_VERSTEP_EMC6D102 0x65
81
82#define LM85_REG_CONFIG 0x40
83
84#define LM85_REG_ALARM1 0x41
85#define LM85_REG_ALARM2 0x42
86
87#define LM85_REG_VID 0x43
88
89/* Automated FAN control */
90#define LM85_REG_AFAN_CONFIG(nr) (0x5c + (nr))
91#define LM85_REG_AFAN_RANGE(nr) (0x5f + (nr))
92#define LM85_REG_AFAN_SPIKE1 0x62
93#define LM85_REG_AFAN_SPIKE2 0x63
94#define LM85_REG_AFAN_MINPWM(nr) (0x64 + (nr))
95#define LM85_REG_AFAN_LIMIT(nr) (0x67 + (nr))
96#define LM85_REG_AFAN_CRITICAL(nr) (0x6a + (nr))
97#define LM85_REG_AFAN_HYST1 0x6d
98#define LM85_REG_AFAN_HYST2 0x6e
99
100#define LM85_REG_TACH_MODE 0x74
101#define LM85_REG_SPINUP_CTL 0x75
102
103#define ADM1027_REG_TEMP_OFFSET(nr) (0x70 + (nr))
104#define ADM1027_REG_CONFIG2 0x73
105#define ADM1027_REG_INTMASK1 0x74
106#define ADM1027_REG_INTMASK2 0x75
107#define ADM1027_REG_EXTEND_ADC1 0x76
108#define ADM1027_REG_EXTEND_ADC2 0x77
109#define ADM1027_REG_CONFIG3 0x78
110#define ADM1027_REG_FAN_PPR 0x7b
111
112#define ADT7463_REG_THERM 0x79
113#define ADT7463_REG_THERM_LIMIT 0x7A
114
115#define EMC6D100_REG_ALARM3 0x7d
116/* IN5, IN6 and IN7 */
117#define EMC6D100_REG_IN(nr) (0x70 + ((nr)-5))
118#define EMC6D100_REG_IN_MIN(nr) (0x73 + ((nr)-5) * 2)
119#define EMC6D100_REG_IN_MAX(nr) (0x74 + ((nr)-5) * 2)
120#define EMC6D102_REG_EXTEND_ADC1 0x85
121#define EMC6D102_REG_EXTEND_ADC2 0x86
122#define EMC6D102_REG_EXTEND_ADC3 0x87
123#define EMC6D102_REG_EXTEND_ADC4 0x88
124
125#define LM85_ALARM_IN0 0x0001
126#define LM85_ALARM_IN1 0x0002
127#define LM85_ALARM_IN2 0x0004
128#define LM85_ALARM_IN3 0x0008
129#define LM85_ALARM_TEMP1 0x0010
130#define LM85_ALARM_TEMP2 0x0020
131#define LM85_ALARM_TEMP3 0x0040
132#define LM85_ALARM_ALARM2 0x0080
133#define LM85_ALARM_IN4 0x0100
134#define LM85_ALARM_RESERVED 0x0200
135#define LM85_ALARM_FAN1 0x0400
136#define LM85_ALARM_FAN2 0x0800
137#define LM85_ALARM_FAN3 0x1000
138#define LM85_ALARM_FAN4 0x2000
139#define LM85_ALARM_TEMP1_FAULT 0x4000
140#define LM85_ALARM_TEMP3_FAULT 0x8000
141
142
143/* Conversions. Rounding and limit checking is only done on the TO_REG
144 variants. Note that you should be a bit careful with which arguments
145 these macros are called: arguments may be evaluated more than once.
146 */
147
148/* IN are scaled acording to built-in resistors */
149static int lm85_scaling[] = { /* .001 Volts */
150 2500, 2250, 3300, 5000, 12000,
151 3300, 1500, 1800 /*EMC6D100*/
152 };
153#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
154
155#define INS_TO_REG(n,val) \
156 SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)
157
158#define INSEXT_FROM_REG(n,val,ext,scale) \
159 SCALE((val)*(scale) + (ext),192*(scale),lm85_scaling[n])
160
161#define INS_FROM_REG(n,val) INSEXT_FROM_REG(n,val,0,1)
162
163/* FAN speed is measured using 90kHz clock */
164#define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534))
165#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val))
166
167/* Temperature is reported in .001 degC increments */
168#define TEMP_TO_REG(val) \
169 SENSORS_LIMIT(SCALE(val,1000,1),-127,127)
170#define TEMPEXT_FROM_REG(val,ext,scale) \
171 SCALE((val)*scale + (ext),scale,1000)
172#define TEMP_FROM_REG(val) \
173 TEMPEXT_FROM_REG(val,0,1)
174
175#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
176#define PWM_FROM_REG(val) (val)
177
178
179/* ZONEs have the following parameters:
180 * Limit (low) temp, 1. degC
181 * Hysteresis (below limit), 1. degC (0-15)
182 * Range of speed control, .1 degC (2-80)
183 * Critical (high) temp, 1. degC
184 *
185 * FAN PWMs have the following parameters:
186 * Reference Zone, 1, 2, 3, etc.
187 * Spinup time, .05 sec
188 * PWM value at limit/low temp, 1 count
189 * PWM Frequency, 1. Hz
190 * PWM is Min or OFF below limit, flag
191 * Invert PWM output, flag
192 *
193 * Some chips filter the temp, others the fan.
194 * Filter constant (or disabled) .1 seconds
195 */
196
197/* These are the zone temperature range encodings in .001 degree C */
198static int lm85_range_map[] = {
199 2000, 2500, 3300, 4000, 5000, 6600,
200 8000, 10000, 13300, 16000, 20000, 26600,
201 32000, 40000, 53300, 80000
202 };
203static int RANGE_TO_REG( int range )
204{
205 int i;
206
207 if ( range < lm85_range_map[0] ) {
208 return 0 ;
209 } else if ( range > lm85_range_map[15] ) {
210 return 15 ;
211 } else { /* find closest match */
212 for ( i = 14 ; i >= 0 ; --i ) {
213 if ( range > lm85_range_map[i] ) { /* range bracketed */
214 if ((lm85_range_map[i+1] - range) <
215 (range - lm85_range_map[i])) {
216 i++;
217 break;
218 }
219 break;
220 }
221 }
222 }
223 return( i & 0x0f );
224}
225#define RANGE_FROM_REG(val) (lm85_range_map[(val)&0x0f])
226
227/* These are the Acoustic Enhancement, or Temperature smoothing encodings
228 * NOTE: The enable/disable bit is INCLUDED in these encodings as the
229 * MSB (bit 3, value 8). If the enable bit is 0, the encoded value
230 * is ignored, or set to 0.
231 */
232/* These are the PWM frequency encodings */
233static int lm85_freq_map[] = { /* .1 Hz */
234 100, 150, 230, 300, 380, 470, 620, 940
235 };
236static int FREQ_TO_REG( int freq )
237{
238 int i;
239
240 if( freq >= lm85_freq_map[7] ) { return 7 ; }
241 for( i = 0 ; i < 7 ; ++i )
242 if( freq <= lm85_freq_map[i] )
243 break ;
244 return( i & 0x07 );
245}
246#define FREQ_FROM_REG(val) (lm85_freq_map[(val)&0x07])
247
248/* Since we can't use strings, I'm abusing these numbers
249 * to stand in for the following meanings:
250 * 1 -- PWM responds to Zone 1
251 * 2 -- PWM responds to Zone 2
252 * 3 -- PWM responds to Zone 3
253 * 23 -- PWM responds to the higher temp of Zone 2 or 3
254 * 123 -- PWM responds to highest of Zone 1, 2, or 3
255 * 0 -- PWM is always at 0% (ie, off)
256 * -1 -- PWM is always at 100%
257 * -2 -- PWM responds to manual control
258 */
259
260static int lm85_zone_map[] = { 1, 2, 3, -1, 0, 23, 123, -2 };
261#define ZONE_FROM_REG(val) (lm85_zone_map[((val)>>5)&0x07])
262
263static int ZONE_TO_REG( int zone )
264{
265 int i;
266
267 for( i = 0 ; i <= 7 ; ++i )
268 if( zone == lm85_zone_map[i] )
269 break ;
270 if( i > 7 ) /* Not found. */
271 i = 3; /* Always 100% */
272 return( (i & 0x07)<<5 );
273}
274
275#define HYST_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,0,15))
276#define HYST_FROM_REG(val) ((val)*1000)
277
278#define OFFSET_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127))
279#define OFFSET_FROM_REG(val) ((val)*25)
280
281#define PPR_MASK(fan) (0x03<<(fan *2))
282#define PPR_TO_REG(val,fan) (SENSORS_LIMIT((val)-1,0,3)<<(fan *2))
283#define PPR_FROM_REG(val,fan) ((((val)>>(fan * 2))&0x03)+1)
284
285/* i2c-vid.h defines vid_from_reg() */
286#define VID_FROM_REG(val,vrm) (vid_from_reg((val),(vrm)))
287
288#define ALARMS_FROM_REG(val) (val)
289
290/* Unlike some other drivers we DO NOT set initial limits. Use
291 * the config file to set limits. Some users have reported
292 * motherboards shutting down when we set limits in a previous
293 * version of the driver.
294 */
295
296/* Chip sampling rates
297 *
298 * Some sensors are not updated more frequently than once per second
299 * so it doesn't make sense to read them more often than that.
300 * We cache the results and return the saved data if the driver
301 * is called again before a second has elapsed.
302 *
303 * Also, there is significant configuration data for this chip
304 * given the automatic PWM fan control that is possible. There
305 * are about 47 bytes of config data to only 22 bytes of actual
306 * readings. So, we keep the config data up to date in the cache
307 * when it is written and only sample it once every 1 *minute*
308 */
309#define LM85_DATA_INTERVAL (HZ + HZ / 2)
310#define LM85_CONFIG_INTERVAL (1 * 60 * HZ)
311
312/* For each registered LM85, we need to keep some data in memory. That
313 data is pointed to by lm85_list[NR]->data. The structure itself is
314 dynamically allocated, at the same time when a new lm85 client is
315 allocated. */
316
317/* LM85 can automatically adjust fan speeds based on temperature
318 * This structure encapsulates an entire Zone config. There are
319 * three zones (one for each temperature input) on the lm85
320 */
321struct lm85_zone {
322 s8 limit; /* Low temp limit */
323 u8 hyst; /* Low limit hysteresis. (0-15) */
324 u8 range; /* Temp range, encoded */
325 s8 critical; /* "All fans ON" temp limit */
326 u8 off_desired; /* Actual "off" temperature specified. Preserved
327 * to prevent "drift" as other autofan control
328 * values change.
329 */
330 u8 max_desired; /* Actual "max" temperature specified. Preserved
331 * to prevent "drift" as other autofan control
332 * values change.
333 */
334};
335
336struct lm85_autofan {
337 u8 config; /* Register value */
338 u8 freq; /* PWM frequency, encoded */
339 u8 min_pwm; /* Minimum PWM value, encoded */
340 u8 min_off; /* Min PWM or OFF below "limit", flag */
341};
342
343struct lm85_data {
344 struct i2c_client client;
345 struct semaphore lock;
346 enum chips type;
347
348 struct semaphore update_lock;
349 int valid; /* !=0 if following fields are valid */
350 unsigned long last_reading; /* In jiffies */
351 unsigned long last_config; /* In jiffies */
352
353 u8 in[8]; /* Register value */
354 u8 in_max[8]; /* Register value */
355 u8 in_min[8]; /* Register value */
356 s8 temp[3]; /* Register value */
357 s8 temp_min[3]; /* Register value */
358 s8 temp_max[3]; /* Register value */
359 s8 temp_offset[3]; /* Register value */
360 u16 fan[4]; /* Register value */
361 u16 fan_min[4]; /* Register value */
362 u8 pwm[3]; /* Register value */
363 u8 spinup_ctl; /* Register encoding, combined */
364 u8 tach_mode; /* Register encoding, combined */
365 u8 temp_ext[3]; /* Decoded values */
366 u8 in_ext[8]; /* Decoded values */
367 u8 adc_scale; /* ADC Extended bits scaling factor */
368 u8 fan_ppr; /* Register value */
369 u8 smooth[3]; /* Register encoding */
370 u8 vid; /* Register value */
371 u8 vrm; /* VRM version */
372 u8 syncpwm3; /* Saved PWM3 for TACH 2,3,4 config */
373 u8 oppoint[3]; /* Register value */
374 u16 tmin_ctl; /* Register value */
375 unsigned long therm_total; /* Cummulative therm count */
376 u8 therm_limit; /* Register value */
377 u32 alarms; /* Register encoding, combined */
378 struct lm85_autofan autofan[3];
379 struct lm85_zone zone[3];
380};
381
382static int lm85_attach_adapter(struct i2c_adapter *adapter);
383static int lm85_detect(struct i2c_adapter *adapter, int address,
384 int kind);
385static int lm85_detach_client(struct i2c_client *client);
386
387static int lm85_read_value(struct i2c_client *client, u8 register);
388static int lm85_write_value(struct i2c_client *client, u8 register, int value);
389static struct lm85_data *lm85_update_device(struct device *dev);
390static void lm85_init_client(struct i2c_client *client);
391
392
393static struct i2c_driver lm85_driver = {
394 .owner = THIS_MODULE,
395 .name = "lm85",
396 .id = I2C_DRIVERID_LM85,
397 .flags = I2C_DF_NOTIFY,
398 .attach_adapter = lm85_attach_adapter,
399 .detach_client = lm85_detach_client,
400};
401
402
403/* 4 Fans */
404static ssize_t show_fan(struct device *dev, char *buf, int nr)
405{
406 struct lm85_data *data = lm85_update_device(dev);
407 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr]) );
408}
409static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
410{
411 struct lm85_data *data = lm85_update_device(dev);
412 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr]) );
413}
414static ssize_t set_fan_min(struct device *dev, const char *buf,
415 size_t count, int nr)
416{
417 struct i2c_client *client = to_i2c_client(dev);
418 struct lm85_data *data = i2c_get_clientdata(client);
419 long val = simple_strtol(buf, NULL, 10);
420
421 down(&data->update_lock);
422 data->fan_min[nr] = FAN_TO_REG(val);
423 lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
424 up(&data->update_lock);
425 return count;
426}
427
428#define show_fan_offset(offset) \
429static ssize_t show_fan_##offset (struct device *dev, char *buf) \
430{ \
431 return show_fan(dev, buf, offset - 1); \
432} \
433static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
434{ \
435 return show_fan_min(dev, buf, offset - 1); \
436} \
437static ssize_t set_fan_##offset##_min (struct device *dev, \
438 const char *buf, size_t count) \
439{ \
440 return set_fan_min(dev, buf, count, offset - 1); \
441} \
442static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, \
443 NULL); \
444static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
445 show_fan_##offset##_min, set_fan_##offset##_min);
446
447show_fan_offset(1);
448show_fan_offset(2);
449show_fan_offset(3);
450show_fan_offset(4);
451
452/* vid, vrm, alarms */
453
454static ssize_t show_vid_reg(struct device *dev, char *buf)
455{
456 struct lm85_data *data = lm85_update_device(dev);
457 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
458}
459
460static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
461
462static ssize_t show_vrm_reg(struct device *dev, char *buf)
463{
464 struct lm85_data *data = lm85_update_device(dev);
465 return sprintf(buf, "%ld\n", (long) data->vrm);
466}
467
468static ssize_t store_vrm_reg(struct device *dev, const char *buf, size_t count)
469{
470 struct i2c_client *client = to_i2c_client(dev);
471 struct lm85_data *data = i2c_get_clientdata(client);
472 u32 val;
473
474 val = simple_strtoul(buf, NULL, 10);
475 data->vrm = val;
476 return count;
477}
478
479static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
480
481static ssize_t show_alarms_reg(struct device *dev, char *buf)
482{
483 struct lm85_data *data = lm85_update_device(dev);
484 return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms));
485}
486
487static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
488
489/* pwm */
490
491static ssize_t show_pwm(struct device *dev, char *buf, int nr)
492{
493 struct lm85_data *data = lm85_update_device(dev);
494 return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm[nr]) );
495}
496static ssize_t set_pwm(struct device *dev, const char *buf,
497 size_t count, int nr)
498{
499 struct i2c_client *client = to_i2c_client(dev);
500 struct lm85_data *data = i2c_get_clientdata(client);
501 long val = simple_strtol(buf, NULL, 10);
502
503 down(&data->update_lock);
504 data->pwm[nr] = PWM_TO_REG(val);
505 lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
506 up(&data->update_lock);
507 return count;
508}
509static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
510{
511 struct lm85_data *data = lm85_update_device(dev);
512 int pwm_zone;
513
514 pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
515 return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) );
516}
517
518#define show_pwm_reg(offset) \
519static ssize_t show_pwm_##offset (struct device *dev, char *buf) \
520{ \
521 return show_pwm(dev, buf, offset - 1); \
522} \
523static ssize_t set_pwm_##offset (struct device *dev, \
524 const char *buf, size_t count) \
525{ \
526 return set_pwm(dev, buf, count, offset - 1); \
527} \
528static ssize_t show_pwm_enable##offset (struct device *dev, char *buf) \
529{ \
530 return show_pwm_enable(dev, buf, offset - 1); \
531} \
532static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
533 show_pwm_##offset, set_pwm_##offset); \
534static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \
535 show_pwm_enable##offset, NULL);
536
537show_pwm_reg(1);
538show_pwm_reg(2);
539show_pwm_reg(3);
540
541/* Voltages */
542
543static ssize_t show_in(struct device *dev, char *buf, int nr)
544{
545 struct lm85_data *data = lm85_update_device(dev);
546 return sprintf( buf, "%d\n", INSEXT_FROM_REG(nr,
547 data->in[nr],
548 data->in_ext[nr],
549 data->adc_scale) );
550}
551static ssize_t show_in_min(struct device *dev, char *buf, int nr)
552{
553 struct lm85_data *data = lm85_update_device(dev);
554 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]) );
555}
556static ssize_t set_in_min(struct device *dev, const char *buf,
557 size_t count, int nr)
558{
559 struct i2c_client *client = to_i2c_client(dev);
560 struct lm85_data *data = i2c_get_clientdata(client);
561 long val = simple_strtol(buf, NULL, 10);
562
563 down(&data->update_lock);
564 data->in_min[nr] = INS_TO_REG(nr, val);
565 lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
566 up(&data->update_lock);
567 return count;
568}
569static ssize_t show_in_max(struct device *dev, char *buf, int nr)
570{
571 struct lm85_data *data = lm85_update_device(dev);
572 return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]) );
573}
574static ssize_t set_in_max(struct device *dev, const char *buf,
575 size_t count, int nr)
576{
577 struct i2c_client *client = to_i2c_client(dev);
578 struct lm85_data *data = i2c_get_clientdata(client);
579 long val = simple_strtol(buf, NULL, 10);
580
581 down(&data->update_lock);
582 data->in_max[nr] = INS_TO_REG(nr, val);
583 lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
584 up(&data->update_lock);
585 return count;
586}
587#define show_in_reg(offset) \
588static ssize_t show_in_##offset (struct device *dev, char *buf) \
589{ \
590 return show_in(dev, buf, offset); \
591} \
592static ssize_t show_in_##offset##_min (struct device *dev, char *buf) \
593{ \
594 return show_in_min(dev, buf, offset); \
595} \
596static ssize_t show_in_##offset##_max (struct device *dev, char *buf) \
597{ \
598 return show_in_max(dev, buf, offset); \
599} \
600static ssize_t set_in_##offset##_min (struct device *dev, \
601 const char *buf, size_t count) \
602{ \
603 return set_in_min(dev, buf, count, offset); \
604} \
605static ssize_t set_in_##offset##_max (struct device *dev, \
606 const char *buf, size_t count) \
607{ \
608 return set_in_max(dev, buf, count, offset); \
609} \
610static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in_##offset, \
611 NULL); \
612static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
613 show_in_##offset##_min, set_in_##offset##_min); \
614static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
615 show_in_##offset##_max, set_in_##offset##_max);
616
617show_in_reg(0);
618show_in_reg(1);
619show_in_reg(2);
620show_in_reg(3);
621show_in_reg(4);
622
623/* Temps */
624
625static ssize_t show_temp(struct device *dev, char *buf, int nr)
626{
627 struct lm85_data *data = lm85_update_device(dev);
628 return sprintf(buf,"%d\n", TEMPEXT_FROM_REG(data->temp[nr],
629 data->temp_ext[nr],
630 data->adc_scale) );
631}
632static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
633{
634 struct lm85_data *data = lm85_update_device(dev);
635 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]) );
636}
637static ssize_t set_temp_min(struct device *dev, const char *buf,
638 size_t count, int nr)
639{
640 struct i2c_client *client = to_i2c_client(dev);
641 struct lm85_data *data = i2c_get_clientdata(client);
642 long val = simple_strtol(buf, NULL, 10);
643
644 down(&data->update_lock);
645 data->temp_min[nr] = TEMP_TO_REG(val);
646 lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
647 up(&data->update_lock);
648 return count;
649}
650static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
651{
652 struct lm85_data *data = lm85_update_device(dev);
653 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]) );
654}
655static ssize_t set_temp_max(struct device *dev, const char *buf,
656 size_t count, int nr)
657{
658 struct i2c_client *client = to_i2c_client(dev);
659 struct lm85_data *data = i2c_get_clientdata(client);
660 long val = simple_strtol(buf, NULL, 10);
661
662 down(&data->update_lock);
663 data->temp_max[nr] = TEMP_TO_REG(val);
664 lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
665 up(&data->update_lock);
666 return count;
667}
668#define show_temp_reg(offset) \
669static ssize_t show_temp_##offset (struct device *dev, char *buf) \
670{ \
671 return show_temp(dev, buf, offset - 1); \
672} \
673static ssize_t show_temp_##offset##_min (struct device *dev, char *buf) \
674{ \
675 return show_temp_min(dev, buf, offset - 1); \
676} \
677static ssize_t show_temp_##offset##_max (struct device *dev, char *buf) \
678{ \
679 return show_temp_max(dev, buf, offset - 1); \
680} \
681static ssize_t set_temp_##offset##_min (struct device *dev, \
682 const char *buf, size_t count) \
683{ \
684 return set_temp_min(dev, buf, count, offset - 1); \
685} \
686static ssize_t set_temp_##offset##_max (struct device *dev, \
687 const char *buf, size_t count) \
688{ \
689 return set_temp_max(dev, buf, count, offset - 1); \
690} \
691static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, \
692 NULL); \
693static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
694 show_temp_##offset##_min, set_temp_##offset##_min); \
695static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
696 show_temp_##offset##_max, set_temp_##offset##_max);
697
698show_temp_reg(1);
699show_temp_reg(2);
700show_temp_reg(3);
701
702
703/* Automatic PWM control */
704
705static ssize_t show_pwm_auto_channels(struct device *dev, char *buf, int nr)
706{
707 struct lm85_data *data = lm85_update_device(dev);
708 return sprintf(buf,"%d\n", ZONE_FROM_REG(data->autofan[nr].config));
709}
710static ssize_t set_pwm_auto_channels(struct device *dev, const char *buf,
711 size_t count, int nr)
712{
713 struct i2c_client *client = to_i2c_client(dev);
714 struct lm85_data *data = i2c_get_clientdata(client);
715 long val = simple_strtol(buf, NULL, 10);
716
717 down(&data->update_lock);
718 data->autofan[nr].config = (data->autofan[nr].config & (~0xe0))
719 | ZONE_TO_REG(val) ;
720 lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
721 data->autofan[nr].config);
722 up(&data->update_lock);
723 return count;
724}
725static ssize_t show_pwm_auto_pwm_min(struct device *dev, char *buf, int nr)
726{
727 struct lm85_data *data = lm85_update_device(dev);
728 return sprintf(buf,"%d\n", PWM_FROM_REG(data->autofan[nr].min_pwm));
729}
730static ssize_t set_pwm_auto_pwm_min(struct device *dev, const char *buf,
731 size_t count, int nr)
732{
733 struct i2c_client *client = to_i2c_client(dev);
734 struct lm85_data *data = i2c_get_clientdata(client);
735 long val = simple_strtol(buf, NULL, 10);
736
737 down(&data->update_lock);
738 data->autofan[nr].min_pwm = PWM_TO_REG(val);
739 lm85_write_value(client, LM85_REG_AFAN_MINPWM(nr),
740 data->autofan[nr].min_pwm);
741 up(&data->update_lock);
742 return count;
743}
744static ssize_t show_pwm_auto_pwm_minctl(struct device *dev, char *buf, int nr)
745{
746 struct lm85_data *data = lm85_update_device(dev);
747 return sprintf(buf,"%d\n", data->autofan[nr].min_off);
748}
749static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, const char *buf,
750 size_t count, int nr)
751{
752 struct i2c_client *client = to_i2c_client(dev);
753 struct lm85_data *data = i2c_get_clientdata(client);
754 long val = simple_strtol(buf, NULL, 10);
755
756 down(&data->update_lock);
757 data->autofan[nr].min_off = val;
758 lm85_write_value(client, LM85_REG_AFAN_SPIKE1, data->smooth[0]
759 | data->syncpwm3
760 | (data->autofan[0].min_off ? 0x20 : 0)
761 | (data->autofan[1].min_off ? 0x40 : 0)
762 | (data->autofan[2].min_off ? 0x80 : 0)
763 );
764 up(&data->update_lock);
765 return count;
766}
767static ssize_t show_pwm_auto_pwm_freq(struct device *dev, char *buf, int nr)
768{
769 struct lm85_data *data = lm85_update_device(dev);
770 return sprintf(buf,"%d\n", FREQ_FROM_REG(data->autofan[nr].freq));
771}
772static ssize_t set_pwm_auto_pwm_freq(struct device *dev, const char *buf,
773 size_t count, int nr)
774{
775 struct i2c_client *client = to_i2c_client(dev);
776 struct lm85_data *data = i2c_get_clientdata(client);
777 long val = simple_strtol(buf, NULL, 10);
778
779 down(&data->update_lock);
780 data->autofan[nr].freq = FREQ_TO_REG(val);
781 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
782 (data->zone[nr].range << 4)
783 | data->autofan[nr].freq
784 );
785 up(&data->update_lock);
786 return count;
787}
788#define pwm_auto(offset) \
789static ssize_t show_pwm##offset##_auto_channels (struct device *dev, \
790 char *buf) \
791{ \
792 return show_pwm_auto_channels(dev, buf, offset - 1); \
793} \
794static ssize_t set_pwm##offset##_auto_channels (struct device *dev, \
795 const char *buf, size_t count) \
796{ \
797 return set_pwm_auto_channels(dev, buf, count, offset - 1); \
798} \
799static ssize_t show_pwm##offset##_auto_pwm_min (struct device *dev, \
800 char *buf) \
801{ \
802 return show_pwm_auto_pwm_min(dev, buf, offset - 1); \
803} \
804static ssize_t set_pwm##offset##_auto_pwm_min (struct device *dev, \
805 const char *buf, size_t count) \
806{ \
807 return set_pwm_auto_pwm_min(dev, buf, count, offset - 1); \
808} \
809static ssize_t show_pwm##offset##_auto_pwm_minctl (struct device *dev, \
810 char *buf) \
811{ \
812 return show_pwm_auto_pwm_minctl(dev, buf, offset - 1); \
813} \
814static ssize_t set_pwm##offset##_auto_pwm_minctl (struct device *dev, \
815 const char *buf, size_t count) \
816{ \
817 return set_pwm_auto_pwm_minctl(dev, buf, count, offset - 1); \
818} \
819static ssize_t show_pwm##offset##_auto_pwm_freq (struct device *dev, \
820 char *buf) \
821{ \
822 return show_pwm_auto_pwm_freq(dev, buf, offset - 1); \
823} \
824static ssize_t set_pwm##offset##_auto_pwm_freq(struct device *dev, \
825 const char *buf, size_t count) \
826{ \
827 return set_pwm_auto_pwm_freq(dev, buf, count, offset - 1); \
828} \
829static DEVICE_ATTR(pwm##offset##_auto_channels, S_IRUGO | S_IWUSR, \
830 show_pwm##offset##_auto_channels, \
831 set_pwm##offset##_auto_channels); \
832static DEVICE_ATTR(pwm##offset##_auto_pwm_min, S_IRUGO | S_IWUSR, \
833 show_pwm##offset##_auto_pwm_min, \
834 set_pwm##offset##_auto_pwm_min); \
835static DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, S_IRUGO | S_IWUSR, \
836 show_pwm##offset##_auto_pwm_minctl, \
837 set_pwm##offset##_auto_pwm_minctl); \
838static DEVICE_ATTR(pwm##offset##_auto_pwm_freq, S_IRUGO | S_IWUSR, \
839 show_pwm##offset##_auto_pwm_freq, \
840 set_pwm##offset##_auto_pwm_freq);
841pwm_auto(1);
842pwm_auto(2);
843pwm_auto(3);
844
845/* Temperature settings for automatic PWM control */
846
847static ssize_t show_temp_auto_temp_off(struct device *dev, char *buf, int nr)
848{
849 struct lm85_data *data = lm85_update_device(dev);
850 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) -
851 HYST_FROM_REG(data->zone[nr].hyst));
852}
853static ssize_t set_temp_auto_temp_off(struct device *dev, const char *buf,
854 size_t count, int nr)
855{
856 struct i2c_client *client = to_i2c_client(dev);
857 struct lm85_data *data = i2c_get_clientdata(client);
858 int min;
859 long val = simple_strtol(buf, NULL, 10);
860
861 down(&data->update_lock);
862 min = TEMP_FROM_REG(data->zone[nr].limit);
863 data->zone[nr].off_desired = TEMP_TO_REG(val);
864 data->zone[nr].hyst = HYST_TO_REG(min - val);
865 if ( nr == 0 || nr == 1 ) {
866 lm85_write_value(client, LM85_REG_AFAN_HYST1,
867 (data->zone[0].hyst << 4)
868 | data->zone[1].hyst
869 );
870 } else {
871 lm85_write_value(client, LM85_REG_AFAN_HYST2,
872 (data->zone[2].hyst << 4)
873 );
874 }
875 up(&data->update_lock);
876 return count;
877}
878static ssize_t show_temp_auto_temp_min(struct device *dev, char *buf, int nr)
879{
880 struct lm85_data *data = lm85_update_device(dev);
881 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) );
882}
883static ssize_t set_temp_auto_temp_min(struct device *dev, const char *buf,
884 size_t count, int nr)
885{
886 struct i2c_client *client = to_i2c_client(dev);
887 struct lm85_data *data = i2c_get_clientdata(client);
888 long val = simple_strtol(buf, NULL, 10);
889
890 down(&data->update_lock);
891 data->zone[nr].limit = TEMP_TO_REG(val);
892 lm85_write_value(client, LM85_REG_AFAN_LIMIT(nr),
893 data->zone[nr].limit);
894
895/* Update temp_auto_max and temp_auto_range */
896 data->zone[nr].range = RANGE_TO_REG(
897 TEMP_FROM_REG(data->zone[nr].max_desired) -
898 TEMP_FROM_REG(data->zone[nr].limit));
899 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
900 ((data->zone[nr].range & 0x0f) << 4)
901 | (data->autofan[nr].freq & 0x07));
902
903/* Update temp_auto_hyst and temp_auto_off */
904 data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG(
905 data->zone[nr].limit) - TEMP_FROM_REG(
906 data->zone[nr].off_desired));
907 if ( nr == 0 || nr == 1 ) {
908 lm85_write_value(client, LM85_REG_AFAN_HYST1,
909 (data->zone[0].hyst << 4)
910 | data->zone[1].hyst
911 );
912 } else {
913 lm85_write_value(client, LM85_REG_AFAN_HYST2,
914 (data->zone[2].hyst << 4)
915 );
916 }
917 up(&data->update_lock);
918 return count;
919}
920static ssize_t show_temp_auto_temp_max(struct device *dev, char *buf, int nr)
921{
922 struct lm85_data *data = lm85_update_device(dev);
923 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].limit) +
924 RANGE_FROM_REG(data->zone[nr].range));
925}
926static ssize_t set_temp_auto_temp_max(struct device *dev, const char *buf,
927 size_t count, int nr)
928{
929 struct i2c_client *client = to_i2c_client(dev);
930 struct lm85_data *data = i2c_get_clientdata(client);
931 int min;
932 long val = simple_strtol(buf, NULL, 10);
933
934 down(&data->update_lock);
935 min = TEMP_FROM_REG(data->zone[nr].limit);
936 data->zone[nr].max_desired = TEMP_TO_REG(val);
937 data->zone[nr].range = RANGE_TO_REG(
938 val - min);
939 lm85_write_value(client, LM85_REG_AFAN_RANGE(nr),
940 ((data->zone[nr].range & 0x0f) << 4)
941 | (data->autofan[nr].freq & 0x07));
942 up(&data->update_lock);
943 return count;
944}
945static ssize_t show_temp_auto_temp_crit(struct device *dev, char *buf, int nr)
946{
947 struct lm85_data *data = lm85_update_device(dev);
948 return sprintf(buf,"%d\n", TEMP_FROM_REG(data->zone[nr].critical));
949}
950static ssize_t set_temp_auto_temp_crit(struct device *dev, const char *buf,
951 size_t count, int nr)
952{
953 struct i2c_client *client = to_i2c_client(dev);
954 struct lm85_data *data = i2c_get_clientdata(client);
955 long val = simple_strtol(buf, NULL, 10);
956
957 down(&data->update_lock);
958 data->zone[nr].critical = TEMP_TO_REG(val);
959 lm85_write_value(client, LM85_REG_AFAN_CRITICAL(nr),
960 data->zone[nr].critical);
961 up(&data->update_lock);
962 return count;
963}
964#define temp_auto(offset) \
965static ssize_t show_temp##offset##_auto_temp_off (struct device *dev, \
966 char *buf) \
967{ \
968 return show_temp_auto_temp_off(dev, buf, offset - 1); \
969} \
970static ssize_t set_temp##offset##_auto_temp_off (struct device *dev, \
971 const char *buf, size_t count) \
972{ \
973 return set_temp_auto_temp_off(dev, buf, count, offset - 1); \
974} \
975static ssize_t show_temp##offset##_auto_temp_min (struct device *dev, \
976 char *buf) \
977{ \
978 return show_temp_auto_temp_min(dev, buf, offset - 1); \
979} \
980static ssize_t set_temp##offset##_auto_temp_min (struct device *dev, \
981 const char *buf, size_t count) \
982{ \
983 return set_temp_auto_temp_min(dev, buf, count, offset - 1); \
984} \
985static ssize_t show_temp##offset##_auto_temp_max (struct device *dev, \
986 char *buf) \
987{ \
988 return show_temp_auto_temp_max(dev, buf, offset - 1); \
989} \
990static ssize_t set_temp##offset##_auto_temp_max (struct device *dev, \
991 const char *buf, size_t count) \
992{ \
993 return set_temp_auto_temp_max(dev, buf, count, offset - 1); \
994} \
995static ssize_t show_temp##offset##_auto_temp_crit (struct device *dev, \
996 char *buf) \
997{ \
998 return show_temp_auto_temp_crit(dev, buf, offset - 1); \
999} \
1000static ssize_t set_temp##offset##_auto_temp_crit (struct device *dev, \
1001 const char *buf, size_t count) \
1002{ \
1003 return set_temp_auto_temp_crit(dev, buf, count, offset - 1); \
1004} \
1005static DEVICE_ATTR(temp##offset##_auto_temp_off, S_IRUGO | S_IWUSR, \
1006 show_temp##offset##_auto_temp_off, \
1007 set_temp##offset##_auto_temp_off); \
1008static DEVICE_ATTR(temp##offset##_auto_temp_min, S_IRUGO | S_IWUSR, \
1009 show_temp##offset##_auto_temp_min, \
1010 set_temp##offset##_auto_temp_min); \
1011static DEVICE_ATTR(temp##offset##_auto_temp_max, S_IRUGO | S_IWUSR, \
1012 show_temp##offset##_auto_temp_max, \
1013 set_temp##offset##_auto_temp_max); \
1014static DEVICE_ATTR(temp##offset##_auto_temp_crit, S_IRUGO | S_IWUSR, \
1015 show_temp##offset##_auto_temp_crit, \
1016 set_temp##offset##_auto_temp_crit);
1017temp_auto(1);
1018temp_auto(2);
1019temp_auto(3);
1020
1021int lm85_attach_adapter(struct i2c_adapter *adapter)
1022{
1023 if (!(adapter->class & I2C_CLASS_HWMON))
1024 return 0;
1025 return i2c_detect(adapter, &addr_data, lm85_detect);
1026}
1027
1028int lm85_detect(struct i2c_adapter *adapter, int address,
1029 int kind)
1030{
1031 int company, verstep ;
1032 struct i2c_client *new_client = NULL;
1033 struct lm85_data *data;
1034 int err = 0;
1035 const char *type_name = "";
1036
1037 if (i2c_is_isa_adapter(adapter)) {
1038 /* This chip has no ISA interface */
1039 goto ERROR0 ;
1040 };
1041
1042 if (!i2c_check_functionality(adapter,
1043 I2C_FUNC_SMBUS_BYTE_DATA)) {
1044 /* We need to be able to do byte I/O */
1045 goto ERROR0 ;
1046 };
1047
1048 /* OK. For now, we presume we have a valid client. We now create the
1049 client structure, even though we cannot fill it completely yet.
1050 But it allows us to access lm85_{read,write}_value. */
1051
1052 if (!(data = kmalloc(sizeof(struct lm85_data), GFP_KERNEL))) {
1053 err = -ENOMEM;
1054 goto ERROR0;
1055 }
1056 memset(data, 0, sizeof(struct lm85_data));
1057
1058 new_client = &data->client;
1059 i2c_set_clientdata(new_client, data);
1060 new_client->addr = address;
1061 new_client->adapter = adapter;
1062 new_client->driver = &lm85_driver;
1063 new_client->flags = 0;
1064
1065 /* Now, we do the remaining detection. */
1066
1067 company = lm85_read_value(new_client, LM85_REG_COMPANY);
1068 verstep = lm85_read_value(new_client, LM85_REG_VERSTEP);
1069
1070 dev_dbg(&adapter->dev, "Detecting device at %d,0x%02x with"
1071 " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
1072 i2c_adapter_id(new_client->adapter), new_client->addr,
1073 company, verstep);
1074
1075 /* If auto-detecting, Determine the chip type. */
1076 if (kind <= 0) {
1077 dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x ...\n",
1078 i2c_adapter_id(adapter), address );
1079 if( company == LM85_COMPANY_NATIONAL
1080 && verstep == LM85_VERSTEP_LM85C ) {
1081 kind = lm85c ;
1082 } else if( company == LM85_COMPANY_NATIONAL
1083 && verstep == LM85_VERSTEP_LM85B ) {
1084 kind = lm85b ;
1085 } else if( company == LM85_COMPANY_NATIONAL
1086 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
1087 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1088 " Defaulting to LM85.\n", verstep);
1089 kind = any_chip ;
1090 } else if( company == LM85_COMPANY_ANALOG_DEV
1091 && verstep == LM85_VERSTEP_ADM1027 ) {
1092 kind = adm1027 ;
1093 } else if( company == LM85_COMPANY_ANALOG_DEV
1094 && (verstep == LM85_VERSTEP_ADT7463
1095 || verstep == LM85_VERSTEP_ADT7463C) ) {
1096 kind = adt7463 ;
1097 } else if( company == LM85_COMPANY_ANALOG_DEV
1098 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC ) {
1099 dev_err(&adapter->dev, "Unrecognized version/stepping 0x%02x"
1100 " Defaulting to Generic LM85.\n", verstep );
1101 kind = any_chip ;
1102 } else if( company == LM85_COMPANY_SMSC
1103 && (verstep == LM85_VERSTEP_EMC6D100_A0
1104 || verstep == LM85_VERSTEP_EMC6D100_A1) ) {
1105 /* Unfortunately, we can't tell a '100 from a '101
1106 * from the registers. Since a '101 is a '100
1107 * in a package with fewer pins and therefore no
1108 * 3.3V, 1.5V or 1.8V inputs, perhaps if those
1109 * inputs read 0, then it's a '101.
1110 */
1111 kind = emc6d100 ;
1112 } else if( company == LM85_COMPANY_SMSC
1113 && verstep == LM85_VERSTEP_EMC6D102) {
1114 kind = emc6d102 ;
1115 } else if( company == LM85_COMPANY_SMSC
1116 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1117 dev_err(&adapter->dev, "lm85: Detected SMSC chip\n");
1118 dev_err(&adapter->dev, "lm85: Unrecognized version/stepping 0x%02x"
1119 " Defaulting to Generic LM85.\n", verstep );
1120 kind = any_chip ;
1121 } else if( kind == any_chip
1122 && (verstep & LM85_VERSTEP_VMASK) == LM85_VERSTEP_GENERIC) {
1123 dev_err(&adapter->dev, "Generic LM85 Version 6 detected\n");
1124 /* Leave kind as "any_chip" */
1125 } else {
1126 dev_dbg(&adapter->dev, "Autodetection failed\n");
1127 /* Not an LM85 ... */
1128 if( kind == any_chip ) { /* User used force=x,y */
1129 dev_err(&adapter->dev, "Generic LM85 Version 6 not"
1130 " found at %d,0x%02x. Try force_lm85c.\n",
1131 i2c_adapter_id(adapter), address );
1132 }
1133 err = 0 ;
1134 goto ERROR1;
1135 }
1136 }
1137
1138 /* Fill in the chip specific driver values */
1139 if ( kind == any_chip ) {
1140 type_name = "lm85";
1141 } else if ( kind == lm85b ) {
1142 type_name = "lm85b";
1143 } else if ( kind == lm85c ) {
1144 type_name = "lm85c";
1145 } else if ( kind == adm1027 ) {
1146 type_name = "adm1027";
1147 } else if ( kind == adt7463 ) {
1148 type_name = "adt7463";
1149 } else if ( kind == emc6d100){
1150 type_name = "emc6d100";
1151 } else if ( kind == emc6d102 ) {
1152 type_name = "emc6d102";
1153 }
1154 strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
1155
1156 /* Fill in the remaining client fields */
1157 data->type = kind;
1158 data->valid = 0;
1159 init_MUTEX(&data->update_lock);
1160
1161 /* Tell the I2C layer a new client has arrived */
1162 if ((err = i2c_attach_client(new_client)))
1163 goto ERROR1;
1164
1165 /* Set the VRM version */
1166 data->vrm = i2c_which_vrm();
1167
1168 /* Initialize the LM85 chip */
1169 lm85_init_client(new_client);
1170
1171 /* Register sysfs hooks */
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_in4_input);
1191 device_create_file(&new_client->dev, &dev_attr_in0_min);
1192 device_create_file(&new_client->dev, &dev_attr_in1_min);
1193 device_create_file(&new_client->dev, &dev_attr_in2_min);
1194 device_create_file(&new_client->dev, &dev_attr_in3_min);
1195 device_create_file(&new_client->dev, &dev_attr_in4_min);
1196 device_create_file(&new_client->dev, &dev_attr_in0_max);
1197 device_create_file(&new_client->dev, &dev_attr_in1_max);
1198 device_create_file(&new_client->dev, &dev_attr_in2_max);
1199 device_create_file(&new_client->dev, &dev_attr_in3_max);
1200 device_create_file(&new_client->dev, &dev_attr_in4_max);
1201 device_create_file(&new_client->dev, &dev_attr_temp1_input);
1202 device_create_file(&new_client->dev, &dev_attr_temp2_input);
1203 device_create_file(&new_client->dev, &dev_attr_temp3_input);
1204 device_create_file(&new_client->dev, &dev_attr_temp1_min);
1205 device_create_file(&new_client->dev, &dev_attr_temp2_min);
1206 device_create_file(&new_client->dev, &dev_attr_temp3_min);
1207 device_create_file(&new_client->dev, &dev_attr_temp1_max);
1208 device_create_file(&new_client->dev, &dev_attr_temp2_max);
1209 device_create_file(&new_client->dev, &dev_attr_temp3_max);
1210 device_create_file(&new_client->dev, &dev_attr_vrm);
1211 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
1212 device_create_file(&new_client->dev, &dev_attr_alarms);
1213 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_channels);
1214 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_channels);
1215 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_channels);
1216 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_min);
1217 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_min);
1218 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_min);
1219 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_minctl);
1220 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_minctl);
1221 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_minctl);
1222 device_create_file(&new_client->dev, &dev_attr_pwm1_auto_pwm_freq);
1223 device_create_file(&new_client->dev, &dev_attr_pwm2_auto_pwm_freq);
1224 device_create_file(&new_client->dev, &dev_attr_pwm3_auto_pwm_freq);
1225 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_off);
1226 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_off);
1227 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_off);
1228 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_min);
1229 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_min);
1230 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_min);
1231 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_max);
1232 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_max);
1233 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_max);
1234 device_create_file(&new_client->dev, &dev_attr_temp1_auto_temp_crit);
1235 device_create_file(&new_client->dev, &dev_attr_temp2_auto_temp_crit);
1236 device_create_file(&new_client->dev, &dev_attr_temp3_auto_temp_crit);
1237
1238 return 0;
1239
1240 /* Error out and cleanup code */
1241 ERROR1:
1242 kfree(data);
1243 ERROR0:
1244 return err;
1245}
1246
1247int lm85_detach_client(struct i2c_client *client)
1248{
1249 i2c_detach_client(client);
1250 kfree(i2c_get_clientdata(client));
1251 return 0;
1252}
1253
1254
1255int lm85_read_value(struct i2c_client *client, u8 reg)
1256{
1257 int res;
1258
1259 /* What size location is it? */
1260 switch( reg ) {
1261 case LM85_REG_FAN(0) : /* Read WORD data */
1262 case LM85_REG_FAN(1) :
1263 case LM85_REG_FAN(2) :
1264 case LM85_REG_FAN(3) :
1265 case LM85_REG_FAN_MIN(0) :
1266 case LM85_REG_FAN_MIN(1) :
1267 case LM85_REG_FAN_MIN(2) :
1268 case LM85_REG_FAN_MIN(3) :
1269 case LM85_REG_ALARM1 : /* Read both bytes at once */
1270 res = i2c_smbus_read_byte_data(client, reg) & 0xff ;
1271 res |= i2c_smbus_read_byte_data(client, reg+1) << 8 ;
1272 break ;
1273 case ADT7463_REG_TMIN_CTL1 : /* Read WORD MSB, LSB */
1274 res = i2c_smbus_read_byte_data(client, reg) << 8 ;
1275 res |= i2c_smbus_read_byte_data(client, reg+1) & 0xff ;
1276 break ;
1277 default: /* Read BYTE data */
1278 res = i2c_smbus_read_byte_data(client, reg);
1279 break ;
1280 }
1281
1282 return res ;
1283}
1284
1285int lm85_write_value(struct i2c_client *client, u8 reg, int value)
1286{
1287 int res ;
1288
1289 switch( reg ) {
1290 case LM85_REG_FAN(0) : /* Write WORD data */
1291 case LM85_REG_FAN(1) :
1292 case LM85_REG_FAN(2) :
1293 case LM85_REG_FAN(3) :
1294 case LM85_REG_FAN_MIN(0) :
1295 case LM85_REG_FAN_MIN(1) :
1296 case LM85_REG_FAN_MIN(2) :
1297 case LM85_REG_FAN_MIN(3) :
1298 /* NOTE: ALARM is read only, so not included here */
1299 res = i2c_smbus_write_byte_data(client, reg, value & 0xff) ;
1300 res |= i2c_smbus_write_byte_data(client, reg+1, (value>>8) & 0xff) ;
1301 break ;
1302 case ADT7463_REG_TMIN_CTL1 : /* Write WORD MSB, LSB */
1303 res = i2c_smbus_write_byte_data(client, reg, (value>>8) & 0xff);
1304 res |= i2c_smbus_write_byte_data(client, reg+1, value & 0xff) ;
1305 break ;
1306 default: /* Write BYTE data */
1307 res = i2c_smbus_write_byte_data(client, reg, value);
1308 break ;
1309 }
1310
1311 return res ;
1312}
1313
1314void lm85_init_client(struct i2c_client *client)
1315{
1316 int value;
1317 struct lm85_data *data = i2c_get_clientdata(client);
1318
1319 dev_dbg(&client->dev, "Initializing device\n");
1320
1321 /* Warn if part was not "READY" */
1322 value = lm85_read_value(client, LM85_REG_CONFIG);
1323 dev_dbg(&client->dev, "LM85_REG_CONFIG is: 0x%02x\n", value);
1324 if( value & 0x02 ) {
1325 dev_err(&client->dev, "Client (%d,0x%02x) config is locked.\n",
1326 i2c_adapter_id(client->adapter), client->addr );
1327 };
1328 if( ! (value & 0x04) ) {
1329 dev_err(&client->dev, "Client (%d,0x%02x) is not ready.\n",
1330 i2c_adapter_id(client->adapter), client->addr );
1331 };
1332 if( value & 0x10
1333 && ( data->type == adm1027
1334 || data->type == adt7463 ) ) {
1335 dev_err(&client->dev, "Client (%d,0x%02x) VxI mode is set. "
1336 "Please report this to the lm85 maintainer.\n",
1337 i2c_adapter_id(client->adapter), client->addr );
1338 };
1339
1340 /* WE INTENTIONALLY make no changes to the limits,
1341 * offsets, pwms, fans and zones. If they were
1342 * configured, we don't want to mess with them.
1343 * If they weren't, the default is 100% PWM, no
1344 * control and will suffice until 'sensors -s'
1345 * can be run by the user.
1346 */
1347
1348 /* Start monitoring */
1349 value = lm85_read_value(client, LM85_REG_CONFIG);
1350 /* Try to clear LOCK, Set START, save everything else */
1351 value = (value & ~ 0x02) | 0x01 ;
1352 dev_dbg(&client->dev, "Setting CONFIG to: 0x%02x\n", value);
1353 lm85_write_value(client, LM85_REG_CONFIG, value);
1354}
1355
1356static struct lm85_data *lm85_update_device(struct device *dev)
1357{
1358 struct i2c_client *client = to_i2c_client(dev);
1359 struct lm85_data *data = i2c_get_clientdata(client);
1360 int i;
1361
1362 down(&data->update_lock);
1363
1364 if ( !data->valid ||
1365 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL) ) {
1366 /* Things that change quickly */
1367 dev_dbg(&client->dev, "Reading sensor values\n");
1368
1369 /* Have to read extended bits first to "freeze" the
1370 * more significant bits that are read later.
1371 */
1372 if ( (data->type == adm1027) || (data->type == adt7463) ) {
1373 int ext1 = lm85_read_value(client,
1374 ADM1027_REG_EXTEND_ADC1);
1375 int ext2 = lm85_read_value(client,
1376 ADM1027_REG_EXTEND_ADC2);
1377 int val = (ext1 << 8) + ext2;
1378
1379 for(i = 0; i <= 4; i++)
1380 data->in_ext[i] = (val>>(i * 2))&0x03;
1381
1382 for(i = 0; i <= 2; i++)
1383 data->temp_ext[i] = (val>>((i + 5) * 2))&0x03;
1384 }
1385
1386 /* adc_scale is 2^(number of LSBs). There are 4 extra bits in
1387 the emc6d102 and 2 in the adt7463 and adm1027. In all
1388 other chips ext is always 0 and the value of scale is
1389 irrelevant. So it is left in 4*/
1390 data->adc_scale = (data->type == emc6d102 ) ? 16 : 4;
1391
1392 for (i = 0; i <= 4; ++i) {
1393 data->in[i] =
1394 lm85_read_value(client, LM85_REG_IN(i));
1395 }
1396
1397 for (i = 0; i <= 3; ++i) {
1398 data->fan[i] =
1399 lm85_read_value(client, LM85_REG_FAN(i));
1400 }
1401
1402 for (i = 0; i <= 2; ++i) {
1403 data->temp[i] =
1404 lm85_read_value(client, LM85_REG_TEMP(i));
1405 }
1406
1407 for (i = 0; i <= 2; ++i) {
1408 data->pwm[i] =
1409 lm85_read_value(client, LM85_REG_PWM(i));
1410 }
1411
1412 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1413
1414 if ( data->type == adt7463 ) {
1415 if( data->therm_total < ULONG_MAX - 256 ) {
1416 data->therm_total +=
1417 lm85_read_value(client, ADT7463_REG_THERM );
1418 }
1419 } else if ( data->type == emc6d100 ) {
1420 /* Three more voltage sensors */
1421 for (i = 5; i <= 7; ++i) {
1422 data->in[i] =
1423 lm85_read_value(client, EMC6D100_REG_IN(i));
1424 }
1425 /* More alarm bits */
1426 data->alarms |=
1427 lm85_read_value(client, EMC6D100_REG_ALARM3) << 16;
1428 } else if (data->type == emc6d102 ) {
1429 /* Have to read LSB bits after the MSB ones because
1430 the reading of the MSB bits has frozen the
1431 LSBs (backward from the ADM1027).
1432 */
1433 int ext1 = lm85_read_value(client,
1434 EMC6D102_REG_EXTEND_ADC1);
1435 int ext2 = lm85_read_value(client,
1436 EMC6D102_REG_EXTEND_ADC2);
1437 int ext3 = lm85_read_value(client,
1438 EMC6D102_REG_EXTEND_ADC3);
1439 int ext4 = lm85_read_value(client,
1440 EMC6D102_REG_EXTEND_ADC4);
1441 data->in_ext[0] = ext3 & 0x0f;
1442 data->in_ext[1] = ext4 & 0x0f;
1443 data->in_ext[2] = (ext4 >> 4) & 0x0f;
1444 data->in_ext[3] = (ext3 >> 4) & 0x0f;
1445 data->in_ext[4] = (ext2 >> 4) & 0x0f;
1446
1447 data->temp_ext[0] = ext1 & 0x0f;
1448 data->temp_ext[1] = ext2 & 0x0f;
1449 data->temp_ext[2] = (ext1 >> 4) & 0x0f;
1450 }
1451
1452 data->last_reading = jiffies ;
1453 }; /* last_reading */
1454
1455 if ( !data->valid ||
1456 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL) ) {
1457 /* Things that don't change often */
1458 dev_dbg(&client->dev, "Reading config values\n");
1459
1460 for (i = 0; i <= 4; ++i) {
1461 data->in_min[i] =
1462 lm85_read_value(client, LM85_REG_IN_MIN(i));
1463 data->in_max[i] =
1464 lm85_read_value(client, LM85_REG_IN_MAX(i));
1465 }
1466
1467 if ( data->type == emc6d100 ) {
1468 for (i = 5; i <= 7; ++i) {
1469 data->in_min[i] =
1470 lm85_read_value(client, EMC6D100_REG_IN_MIN(i));
1471 data->in_max[i] =
1472 lm85_read_value(client, EMC6D100_REG_IN_MAX(i));
1473 }
1474 }
1475
1476 for (i = 0; i <= 3; ++i) {
1477 data->fan_min[i] =
1478 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1479 }
1480
1481 for (i = 0; i <= 2; ++i) {
1482 data->temp_min[i] =
1483 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1484 data->temp_max[i] =
1485 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
1486 }
1487
1488 data->vid = lm85_read_value(client, LM85_REG_VID);
1489
1490 for (i = 0; i <= 2; ++i) {
1491 int val ;
1492 data->autofan[i].config =
1493 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1494 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1495 data->autofan[i].freq = val & 0x07 ;
1496 data->zone[i].range = (val >> 4) & 0x0f ;
1497 data->autofan[i].min_pwm =
1498 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1499 data->zone[i].limit =
1500 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
1501 data->zone[i].critical =
1502 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
1503 }
1504
1505 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
1506 data->smooth[0] = i & 0x0f ;
1507 data->syncpwm3 = i & 0x10 ; /* Save PWM3 config */
1508 data->autofan[0].min_off = (i & 0x20) != 0 ;
1509 data->autofan[1].min_off = (i & 0x40) != 0 ;
1510 data->autofan[2].min_off = (i & 0x80) != 0 ;
1511 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE2);
1512 data->smooth[1] = (i>>4) & 0x0f ;
1513 data->smooth[2] = i & 0x0f ;
1514
1515 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
1516 data->zone[0].hyst = (i>>4) & 0x0f ;
1517 data->zone[1].hyst = i & 0x0f ;
1518
1519 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
1520 data->zone[2].hyst = (i>>4) & 0x0f ;
1521
1522 if ( (data->type == lm85b) || (data->type == lm85c) ) {
1523 data->tach_mode = lm85_read_value(client,
1524 LM85_REG_TACH_MODE );
1525 data->spinup_ctl = lm85_read_value(client,
1526 LM85_REG_SPINUP_CTL );
1527 } else if ( (data->type == adt7463) || (data->type == adm1027) ) {
1528 if ( data->type == adt7463 ) {
1529 for (i = 0; i <= 2; ++i) {
1530 data->oppoint[i] = lm85_read_value(client,
1531 ADT7463_REG_OPPOINT(i) );
1532 }
1533 data->tmin_ctl = lm85_read_value(client,
1534 ADT7463_REG_TMIN_CTL1 );
1535 data->therm_limit = lm85_read_value(client,
1536 ADT7463_REG_THERM_LIMIT );
1537 }
1538 for (i = 0; i <= 2; ++i) {
1539 data->temp_offset[i] = lm85_read_value(client,
1540 ADM1027_REG_TEMP_OFFSET(i) );
1541 }
1542 data->tach_mode = lm85_read_value(client,
1543 ADM1027_REG_CONFIG3 );
1544 data->fan_ppr = lm85_read_value(client,
1545 ADM1027_REG_FAN_PPR );
1546 }
1547
1548 data->last_config = jiffies;
1549 }; /* last_config */
1550
1551 data->valid = 1;
1552
1553 up(&data->update_lock);
1554
1555 return data;
1556}
1557
1558
1559static int __init sm_lm85_init(void)
1560{
1561 return i2c_add_driver(&lm85_driver);
1562}
1563
1564static void __exit sm_lm85_exit(void)
1565{
1566 i2c_del_driver(&lm85_driver);
1567}
1568
1569/* Thanks to Richard Barrington for adding the LM85 to sensors-detect.
1570 * Thanks to Margit Schubert-While <margitsw@t-online.de> for help with
1571 * post 2.7.0 CVS changes.
1572 */
1573MODULE_LICENSE("GPL");
1574MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, Margit Schubert-While <margitsw@t-online.de>, Justin Thiessen <jthiessen@penguincomputing.com");
1575MODULE_DESCRIPTION("LM85-B, LM85-C driver");
1576
1577module_init(sm_lm85_init);
1578module_exit(sm_lm85_exit);
diff --git a/drivers/i2c/chips/lm87.c b/drivers/i2c/chips/lm87.c
deleted file mode 100644
index 98cabd665063..000000000000
--- a/drivers/i2c/chips/lm87.c
+++ /dev/null
@@ -1,829 +0,0 @@
1/*
2 * lm87.c
3 *
4 * Copyright (C) 2000 Frodo Looijaard <frodol@dds.nl>
5 * Philip Edelbrock <phil@netroedge.com>
6 * Stephen Rousset <stephen.rousset@rocketlogix.com>
7 * Dan Eaton <dan.eaton@rocketlogix.com>
8 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
9 *
10 * Original port to Linux 2.6 by Jeff Oliver.
11 *
12 * The LM87 is a sensor chip made by National Semiconductor. It monitors up
13 * to 8 voltages (including its own power source), up to three temperatures
14 * (its own plus up to two external ones) and up to two fans. The default
15 * configuration is 6 voltages, two temperatures and two fans (see below).
16 * Voltages are scaled internally with ratios such that the nominal value of
17 * each voltage correspond to a register value of 192 (which means a
18 * resolution of about 0.5% of the nominal value). Temperature values are
19 * reported with a 1 deg resolution and a 3-4 deg accuracy. Complete
20 * datasheet can be obtained from National's website at:
21 * http://www.national.com/pf/LM/LM87.html
22 *
23 * Some functions share pins, so not all functions are available at the same
24 * time. Which are depends on the hardware setup. This driver assumes that
25 * the BIOS configured the chip correctly. In that respect, it differs from
26 * the original driver (from lm_sensors for Linux 2.4), which would force the
27 * LM87 to an arbitrary, compile-time chosen mode, regardless of the actual
28 * chipset wiring.
29 * For reference, here is the list of exclusive functions:
30 * - in0+in5 (default) or temp3
31 * - fan1 (default) or in6
32 * - fan2 (default) or in7
33 * - VID lines (default) or IRQ lines (not handled by this driver)
34 *
35 * The LM87 additionally features an analog output, supposedly usable to
36 * control the speed of a fan. All new chips use pulse width modulation
37 * instead. The LM87 is the only hardware monitoring chipset I know of
38 * which uses amplitude modulation. Be careful when using this feature.
39 *
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License as published by
42 * the Free Software Foundation; either version 2 of the License, or
43 * (at your option) any later version.
44 *
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
49 *
50 * You should have received a copy of the GNU General Public License
51 * along with this program; if not, write to the Free Software
52 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
53 */
54
55#include <linux/config.h>
56#include <linux/module.h>
57#include <linux/init.h>
58#include <linux/slab.h>
59#include <linux/jiffies.h>
60#include <linux/i2c.h>
61#include <linux/i2c-sensor.h>
62#include <linux/i2c-vid.h>
63
64/*
65 * Addresses to scan
66 * LM87 has three possible addresses: 0x2c, 0x2d and 0x2e.
67 */
68
69static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
70static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
71
72/*
73 * Insmod parameters
74 */
75
76SENSORS_INSMOD_1(lm87);
77
78/*
79 * The LM87 registers
80 */
81
82/* nr in 0..5 */
83#define LM87_REG_IN(nr) (0x20 + (nr))
84#define LM87_REG_IN_MAX(nr) (0x2B + (nr) * 2)
85#define LM87_REG_IN_MIN(nr) (0x2C + (nr) * 2)
86/* nr in 0..1 */
87#define LM87_REG_AIN(nr) (0x28 + (nr))
88#define LM87_REG_AIN_MIN(nr) (0x1A + (nr))
89#define LM87_REG_AIN_MAX(nr) (0x3B + (nr))
90
91static u8 LM87_REG_TEMP[3] = { 0x27, 0x26, 0x20 };
92static u8 LM87_REG_TEMP_HIGH[3] = { 0x39, 0x37, 0x2B };
93static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
94
95#define LM87_REG_TEMP_HW_INT_LOCK 0x13
96#define LM87_REG_TEMP_HW_EXT_LOCK 0x14
97#define LM87_REG_TEMP_HW_INT 0x17
98#define LM87_REG_TEMP_HW_EXT 0x18
99
100/* nr in 0..1 */
101#define LM87_REG_FAN(nr) (0x28 + (nr))
102#define LM87_REG_FAN_MIN(nr) (0x3B + (nr))
103#define LM87_REG_AOUT 0x19
104
105#define LM87_REG_CONFIG 0x40
106#define LM87_REG_CHANNEL_MODE 0x16
107#define LM87_REG_VID_FAN_DIV 0x47
108#define LM87_REG_VID4 0x49
109
110#define LM87_REG_ALARMS1 0x41
111#define LM87_REG_ALARMS2 0x42
112
113#define LM87_REG_COMPANY_ID 0x3E
114#define LM87_REG_REVISION 0x3F
115
116/*
117 * Conversions and various macros
118 * The LM87 uses signed 8-bit values for temperatures.
119 */
120
121#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
122#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
123 (val) * 192 >= (scale) * 255 ? 255 : \
124 ((val) * 192 + (scale)/2) / (scale))
125
126#define TEMP_FROM_REG(reg) ((reg) * 1000)
127#define TEMP_TO_REG(val) ((val) <= -127500 ? -128 : \
128 (val) >= 126500 ? 127 : \
129 (((val) < 0 ? (val)-500 : (val)+500) / 1000))
130
131#define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \
132 1350000 + (reg)*(div) / 2) / ((reg)*(div))
133#define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \
134 (1350000 + (val)*(div) / 2) / ((val)*(div)))
135
136#define FAN_DIV_FROM_REG(reg) (1 << (reg))
137
138/* analog out is 9.80mV/LSB */
139#define AOUT_FROM_REG(reg) (((reg) * 98 + 5) / 10)
140#define AOUT_TO_REG(val) ((val) <= 0 ? 0 : \
141 (val) >= 2500 ? 255 : \
142 ((val) * 10 + 49) / 98)
143
144/* nr in 0..1 */
145#define CHAN_NO_FAN(nr) (1 << (nr))
146#define CHAN_TEMP3 (1 << 2)
147#define CHAN_VCC_5V (1 << 3)
148#define CHAN_NO_VID (1 << 8)
149
150/*
151 * Functions declaration
152 */
153
154static int lm87_attach_adapter(struct i2c_adapter *adapter);
155static int lm87_detect(struct i2c_adapter *adapter, int address, int kind);
156static void lm87_init_client(struct i2c_client *client);
157static int lm87_detach_client(struct i2c_client *client);
158static struct lm87_data *lm87_update_device(struct device *dev);
159
160/*
161 * Driver data (common to all clients)
162 */
163
164static struct i2c_driver lm87_driver = {
165 .owner = THIS_MODULE,
166 .name = "lm87",
167 .id = I2C_DRIVERID_LM87,
168 .flags = I2C_DF_NOTIFY,
169 .attach_adapter = lm87_attach_adapter,
170 .detach_client = lm87_detach_client,
171};
172
173/*
174 * Client data (each client gets its own)
175 */
176
177struct lm87_data {
178 struct i2c_client client;
179 struct semaphore update_lock;
180 char valid; /* zero until following fields are valid */
181 unsigned long last_updated; /* In jiffies */
182
183 u8 channel; /* register value */
184
185 u8 in[8]; /* register value */
186 u8 in_max[8]; /* register value */
187 u8 in_min[8]; /* register value */
188 u16 in_scale[8];
189
190 s8 temp[3]; /* register value */
191 s8 temp_high[3]; /* register value */
192 s8 temp_low[3]; /* register value */
193 s8 temp_crit_int; /* min of two register values */
194 s8 temp_crit_ext; /* min of two register values */
195
196 u8 fan[2]; /* register value */
197 u8 fan_min[2]; /* register value */
198 u8 fan_div[2]; /* register value, shifted right */
199 u8 aout; /* register value */
200
201 u16 alarms; /* register values, combined */
202 u8 vid; /* register values, combined */
203 u8 vrm;
204};
205
206/*
207 * Sysfs stuff
208 */
209
210static inline int lm87_read_value(struct i2c_client *client, u8 reg)
211{
212 return i2c_smbus_read_byte_data(client, reg);
213}
214
215static inline int lm87_write_value(struct i2c_client *client, u8 reg, u8 value)
216{
217 return i2c_smbus_write_byte_data(client, reg, value);
218}
219
220#define show_in(offset) \
221static ssize_t show_in##offset##_input(struct device *dev, char *buf) \
222{ \
223 struct lm87_data *data = lm87_update_device(dev); \
224 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
225 data->in_scale[offset])); \
226} \
227static ssize_t show_in##offset##_min(struct device *dev, char *buf) \
228{ \
229 struct lm87_data *data = lm87_update_device(dev); \
230 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
231 data->in_scale[offset])); \
232} \
233static ssize_t show_in##offset##_max(struct device *dev, char *buf) \
234{ \
235 struct lm87_data *data = lm87_update_device(dev); \
236 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
237 data->in_scale[offset])); \
238} \
239static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
240 show_in##offset##_input, NULL);
241show_in(0);
242show_in(1);
243show_in(2);
244show_in(3);
245show_in(4);
246show_in(5);
247show_in(6);
248show_in(7);
249
250static void set_in_min(struct device *dev, const char *buf, int nr)
251{
252 struct i2c_client *client = to_i2c_client(dev);
253 struct lm87_data *data = i2c_get_clientdata(client);
254 long val = simple_strtol(buf, NULL, 10);
255
256 down(&data->update_lock);
257 data->in_min[nr] = IN_TO_REG(val, data->in_scale[nr]);
258 lm87_write_value(client, nr<6 ? LM87_REG_IN_MIN(nr) :
259 LM87_REG_AIN_MIN(nr-6), data->in_min[nr]);
260 up(&data->update_lock);
261}
262
263static void set_in_max(struct device *dev, const char *buf, int nr)
264{
265 struct i2c_client *client = to_i2c_client(dev);
266 struct lm87_data *data = i2c_get_clientdata(client);
267 long val = simple_strtol(buf, NULL, 10);
268
269 down(&data->update_lock);
270 data->in_max[nr] = IN_TO_REG(val, data->in_scale[nr]);
271 lm87_write_value(client, nr<6 ? LM87_REG_IN_MAX(nr) :
272 LM87_REG_AIN_MAX(nr-6), data->in_max[nr]);
273 up(&data->update_lock);
274}
275
276#define set_in(offset) \
277static ssize_t set_in##offset##_min(struct device *dev, \
278 const char *buf, size_t count) \
279{ \
280 set_in_min(dev, buf, offset); \
281 return count; \
282} \
283static ssize_t set_in##offset##_max(struct device *dev, \
284 const char *buf, size_t count) \
285{ \
286 set_in_max(dev, buf, offset); \
287 return count; \
288} \
289static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
290 show_in##offset##_min, set_in##offset##_min); \
291static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
292 show_in##offset##_max, set_in##offset##_max);
293set_in(0);
294set_in(1);
295set_in(2);
296set_in(3);
297set_in(4);
298set_in(5);
299set_in(6);
300set_in(7);
301
302#define show_temp(offset) \
303static ssize_t show_temp##offset##_input(struct device *dev, char *buf) \
304{ \
305 struct lm87_data *data = lm87_update_device(dev); \
306 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
307} \
308static ssize_t show_temp##offset##_low(struct device *dev, char *buf) \
309{ \
310 struct lm87_data *data = lm87_update_device(dev); \
311 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[offset-1])); \
312} \
313static ssize_t show_temp##offset##_high(struct device *dev, char *buf) \
314{ \
315 struct lm87_data *data = lm87_update_device(dev); \
316 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[offset-1])); \
317}\
318static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
319 show_temp##offset##_input, NULL);
320show_temp(1);
321show_temp(2);
322show_temp(3);
323
324static void set_temp_low(struct device *dev, const char *buf, int nr)
325{
326 struct i2c_client *client = to_i2c_client(dev);
327 struct lm87_data *data = i2c_get_clientdata(client);
328 long val = simple_strtol(buf, NULL, 10);
329
330 down(&data->update_lock);
331 data->temp_low[nr] = TEMP_TO_REG(val);
332 lm87_write_value(client, LM87_REG_TEMP_LOW[nr], data->temp_low[nr]);
333 up(&data->update_lock);
334}
335
336static void set_temp_high(struct device *dev, const char *buf, int nr)
337{
338 struct i2c_client *client = to_i2c_client(dev);
339 struct lm87_data *data = i2c_get_clientdata(client);
340 long val = simple_strtol(buf, NULL, 10);
341
342 down(&data->update_lock);
343 data->temp_high[nr] = TEMP_TO_REG(val);
344 lm87_write_value(client, LM87_REG_TEMP_HIGH[nr], data->temp_high[nr]);
345 up(&data->update_lock);
346}
347
348#define set_temp(offset) \
349static ssize_t set_temp##offset##_low(struct device *dev, \
350 const char *buf, size_t count) \
351{ \
352 set_temp_low(dev, buf, offset-1); \
353 return count; \
354} \
355static ssize_t set_temp##offset##_high(struct device *dev, \
356 const char *buf, size_t count) \
357{ \
358 set_temp_high(dev, buf, offset-1); \
359 return count; \
360} \
361static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
362 show_temp##offset##_high, set_temp##offset##_high); \
363static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
364 show_temp##offset##_low, set_temp##offset##_low);
365set_temp(1);
366set_temp(2);
367set_temp(3);
368
369static ssize_t show_temp_crit_int(struct device *dev, char *buf)
370{
371 struct lm87_data *data = lm87_update_device(dev);
372 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_int));
373}
374
375static ssize_t show_temp_crit_ext(struct device *dev, char *buf)
376{
377 struct lm87_data *data = lm87_update_device(dev);
378 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit_ext));
379}
380
381static DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp_crit_int, NULL);
382static DEVICE_ATTR(temp2_crit, S_IRUGO, show_temp_crit_ext, NULL);
383static DEVICE_ATTR(temp3_crit, S_IRUGO, show_temp_crit_ext, NULL);
384
385#define show_fan(offset) \
386static ssize_t show_fan##offset##_input(struct device *dev, char *buf) \
387{ \
388 struct lm87_data *data = lm87_update_device(dev); \
389 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[offset-1], \
390 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \
391} \
392static ssize_t show_fan##offset##_min(struct device *dev, char *buf) \
393{ \
394 struct lm87_data *data = lm87_update_device(dev); \
395 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[offset-1], \
396 FAN_DIV_FROM_REG(data->fan_div[offset-1]))); \
397} \
398static ssize_t show_fan##offset##_div(struct device *dev, char *buf) \
399{ \
400 struct lm87_data *data = lm87_update_device(dev); \
401 return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[offset-1])); \
402} \
403static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
404 show_fan##offset##_input, NULL);
405show_fan(1);
406show_fan(2);
407
408static void set_fan_min(struct device *dev, const char *buf, int nr)
409{
410 struct i2c_client *client = to_i2c_client(dev);
411 struct lm87_data *data = i2c_get_clientdata(client);
412 long val = simple_strtol(buf, NULL, 10);
413
414 down(&data->update_lock);
415 data->fan_min[nr] = FAN_TO_REG(val,
416 FAN_DIV_FROM_REG(data->fan_div[nr]));
417 lm87_write_value(client, LM87_REG_FAN_MIN(nr), data->fan_min[nr]);
418 up(&data->update_lock);
419}
420
421/* Note: we save and restore the fan minimum here, because its value is
422 determined in part by the fan clock divider. This follows the principle
423 of least suprise; the user doesn't expect the fan minimum to change just
424 because the divider changed. */
425static ssize_t set_fan_div(struct device *dev, const char *buf,
426 size_t count, int nr)
427{
428 struct i2c_client *client = to_i2c_client(dev);
429 struct lm87_data *data = i2c_get_clientdata(client);
430 long val = simple_strtol(buf, NULL, 10);
431 unsigned long min;
432 u8 reg;
433
434 down(&data->update_lock);
435 min = FAN_FROM_REG(data->fan_min[nr],
436 FAN_DIV_FROM_REG(data->fan_div[nr]));
437
438 switch (val) {
439 case 1: data->fan_div[nr] = 0; break;
440 case 2: data->fan_div[nr] = 1; break;
441 case 4: data->fan_div[nr] = 2; break;
442 case 8: data->fan_div[nr] = 3; break;
443 default:
444 up(&data->update_lock);
445 return -EINVAL;
446 }
447
448 reg = lm87_read_value(client, LM87_REG_VID_FAN_DIV);
449 switch (nr) {
450 case 0:
451 reg = (reg & 0xCF) | (data->fan_div[0] << 4);
452 break;
453 case 1:
454 reg = (reg & 0x3F) | (data->fan_div[1] << 6);
455 break;
456 }
457 lm87_write_value(client, LM87_REG_VID_FAN_DIV, reg);
458
459 data->fan_min[nr] = FAN_TO_REG(min, val);
460 lm87_write_value(client, LM87_REG_FAN_MIN(nr),
461 data->fan_min[nr]);
462 up(&data->update_lock);
463
464 return count;
465}
466
467#define set_fan(offset) \
468static ssize_t set_fan##offset##_min(struct device *dev, const char *buf, \
469 size_t count) \
470{ \
471 set_fan_min(dev, buf, offset-1); \
472 return count; \
473} \
474static ssize_t set_fan##offset##_div(struct device *dev, const char *buf, \
475 size_t count) \
476{ \
477 return set_fan_div(dev, buf, count, offset-1); \
478} \
479static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
480 show_fan##offset##_min, set_fan##offset##_min); \
481static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
482 show_fan##offset##_div, set_fan##offset##_div);
483set_fan(1);
484set_fan(2);
485
486static ssize_t show_alarms(struct device *dev, char *buf)
487{
488 struct lm87_data *data = lm87_update_device(dev);
489 return sprintf(buf, "%d\n", data->alarms);
490}
491static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
492
493static ssize_t show_vid(struct device *dev, char *buf)
494{
495 struct lm87_data *data = lm87_update_device(dev);
496 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
497}
498static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
499
500static ssize_t show_vrm(struct device *dev, char *buf)
501{
502 struct lm87_data *data = lm87_update_device(dev);
503 return sprintf(buf, "%d\n", data->vrm);
504}
505static ssize_t set_vrm(struct device *dev, const char *buf, size_t count)
506{
507 struct i2c_client *client = to_i2c_client(dev);
508 struct lm87_data *data = i2c_get_clientdata(client);
509 data->vrm = simple_strtoul(buf, NULL, 10);
510 return count;
511}
512static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
513
514static ssize_t show_aout(struct device *dev, char *buf)
515{
516 struct lm87_data *data = lm87_update_device(dev);
517 return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
518}
519static ssize_t set_aout(struct device *dev, const char *buf, size_t count)
520{
521 struct i2c_client *client = to_i2c_client(dev);
522 struct lm87_data *data = i2c_get_clientdata(client);
523 long val = simple_strtol(buf, NULL, 10);
524
525 down(&data->update_lock);
526 data->aout = AOUT_TO_REG(val);
527 lm87_write_value(client, LM87_REG_AOUT, data->aout);
528 up(&data->update_lock);
529 return count;
530}
531static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
532
533/*
534 * Real code
535 */
536
537static int lm87_attach_adapter(struct i2c_adapter *adapter)
538{
539 if (!(adapter->class & I2C_CLASS_HWMON))
540 return 0;
541 return i2c_detect(adapter, &addr_data, lm87_detect);
542}
543
544/*
545 * The following function does more than just detection. If detection
546 * succeeds, it also registers the new chip.
547 */
548static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
549{
550 struct i2c_client *new_client;
551 struct lm87_data *data;
552 int err = 0;
553
554 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
555 goto exit;
556
557 if (!(data = kmalloc(sizeof(struct lm87_data), GFP_KERNEL))) {
558 err = -ENOMEM;
559 goto exit;
560 }
561 memset(data, 0, sizeof(struct lm87_data));
562
563 /* The common I2C client data is placed right before the
564 LM87-specific data. */
565 new_client = &data->client;
566 i2c_set_clientdata(new_client, data);
567 new_client->addr = address;
568 new_client->adapter = adapter;
569 new_client->driver = &lm87_driver;
570 new_client->flags = 0;
571
572 /* Default to an LM87 if forced */
573 if (kind == 0)
574 kind = lm87;
575
576 /* Now, we do the remaining detection. */
577 if (kind < 0) {
578 u8 rev = lm87_read_value(new_client, LM87_REG_REVISION);
579
580 if (rev < 0x01 || rev > 0x08
581 || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)
582 || lm87_read_value(new_client, LM87_REG_COMPANY_ID) != 0x02) {
583 dev_dbg(&adapter->dev,
584 "LM87 detection failed at 0x%02x.\n",
585 address);
586 goto exit_free;
587 }
588 }
589
590 /* We can fill in the remaining client fields */
591 strlcpy(new_client->name, "lm87", I2C_NAME_SIZE);
592 data->valid = 0;
593 init_MUTEX(&data->update_lock);
594
595 /* Tell the I2C layer a new client has arrived */
596 if ((err = i2c_attach_client(new_client)))
597 goto exit_free;
598
599 /* Initialize the LM87 chip */
600 lm87_init_client(new_client);
601
602 data->in_scale[0] = 2500;
603 data->in_scale[1] = 2700;
604 data->in_scale[2] = (data->channel & CHAN_VCC_5V) ? 5000 : 3300;
605 data->in_scale[3] = 5000;
606 data->in_scale[4] = 12000;
607 data->in_scale[5] = 2700;
608 data->in_scale[6] = 1875;
609 data->in_scale[7] = 1875;
610
611 /* Register sysfs hooks */
612 device_create_file(&new_client->dev, &dev_attr_in1_input);
613 device_create_file(&new_client->dev, &dev_attr_in1_min);
614 device_create_file(&new_client->dev, &dev_attr_in1_max);
615 device_create_file(&new_client->dev, &dev_attr_in2_input);
616 device_create_file(&new_client->dev, &dev_attr_in2_min);
617 device_create_file(&new_client->dev, &dev_attr_in2_max);
618 device_create_file(&new_client->dev, &dev_attr_in3_input);
619 device_create_file(&new_client->dev, &dev_attr_in3_min);
620 device_create_file(&new_client->dev, &dev_attr_in3_max);
621 device_create_file(&new_client->dev, &dev_attr_in4_input);
622 device_create_file(&new_client->dev, &dev_attr_in4_min);
623 device_create_file(&new_client->dev, &dev_attr_in4_max);
624
625 if (data->channel & CHAN_NO_FAN(0)) {
626 device_create_file(&new_client->dev, &dev_attr_in6_input);
627 device_create_file(&new_client->dev, &dev_attr_in6_min);
628 device_create_file(&new_client->dev, &dev_attr_in6_max);
629 } else {
630 device_create_file(&new_client->dev, &dev_attr_fan1_input);
631 device_create_file(&new_client->dev, &dev_attr_fan1_min);
632 device_create_file(&new_client->dev, &dev_attr_fan1_div);
633 }
634 if (data->channel & CHAN_NO_FAN(1)) {
635 device_create_file(&new_client->dev, &dev_attr_in7_input);
636 device_create_file(&new_client->dev, &dev_attr_in7_min);
637 device_create_file(&new_client->dev, &dev_attr_in7_max);
638 } else {
639 device_create_file(&new_client->dev, &dev_attr_fan2_input);
640 device_create_file(&new_client->dev, &dev_attr_fan2_min);
641 device_create_file(&new_client->dev, &dev_attr_fan2_div);
642 }
643
644 device_create_file(&new_client->dev, &dev_attr_temp1_input);
645 device_create_file(&new_client->dev, &dev_attr_temp1_max);
646 device_create_file(&new_client->dev, &dev_attr_temp1_min);
647 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
648 device_create_file(&new_client->dev, &dev_attr_temp2_input);
649 device_create_file(&new_client->dev, &dev_attr_temp2_max);
650 device_create_file(&new_client->dev, &dev_attr_temp2_min);
651 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
652
653 if (data->channel & CHAN_TEMP3) {
654 device_create_file(&new_client->dev, &dev_attr_temp3_input);
655 device_create_file(&new_client->dev, &dev_attr_temp3_max);
656 device_create_file(&new_client->dev, &dev_attr_temp3_min);
657 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
658 } else {
659 device_create_file(&new_client->dev, &dev_attr_in0_input);
660 device_create_file(&new_client->dev, &dev_attr_in0_min);
661 device_create_file(&new_client->dev, &dev_attr_in0_max);
662 device_create_file(&new_client->dev, &dev_attr_in5_input);
663 device_create_file(&new_client->dev, &dev_attr_in5_min);
664 device_create_file(&new_client->dev, &dev_attr_in5_max);
665 }
666
667 if (!(data->channel & CHAN_NO_VID)) {
668 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
669 device_create_file(&new_client->dev, &dev_attr_vrm);
670 }
671
672 device_create_file(&new_client->dev, &dev_attr_alarms);
673 device_create_file(&new_client->dev, &dev_attr_aout_output);
674
675 return 0;
676
677exit_free:
678 kfree(data);
679exit:
680 return err;
681}
682
683static void lm87_init_client(struct i2c_client *client)
684{
685 struct lm87_data *data = i2c_get_clientdata(client);
686 u8 config;
687
688 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
689 data->vrm = i2c_which_vrm();
690
691 config = lm87_read_value(client, LM87_REG_CONFIG);
692 if (!(config & 0x01)) {
693 int i;
694
695 /* Limits are left uninitialized after power-up */
696 for (i = 1; i < 6; i++) {
697 lm87_write_value(client, LM87_REG_IN_MIN(i), 0x00);
698 lm87_write_value(client, LM87_REG_IN_MAX(i), 0xFF);
699 }
700 for (i = 0; i < 2; i++) {
701 lm87_write_value(client, LM87_REG_TEMP_HIGH[i], 0x7F);
702 lm87_write_value(client, LM87_REG_TEMP_LOW[i], 0x00);
703 lm87_write_value(client, LM87_REG_AIN_MIN(i), 0x00);
704 lm87_write_value(client, LM87_REG_AIN_MAX(i), 0xFF);
705 }
706 if (data->channel & CHAN_TEMP3) {
707 lm87_write_value(client, LM87_REG_TEMP_HIGH[2], 0x7F);
708 lm87_write_value(client, LM87_REG_TEMP_LOW[2], 0x00);
709 } else {
710 lm87_write_value(client, LM87_REG_IN_MIN(0), 0x00);
711 lm87_write_value(client, LM87_REG_IN_MAX(0), 0xFF);
712 }
713 }
714 if ((config & 0x81) != 0x01) {
715 /* Start monitoring */
716 lm87_write_value(client, LM87_REG_CONFIG,
717 (config & 0xF7) | 0x01);
718 }
719}
720
721static int lm87_detach_client(struct i2c_client *client)
722{
723 int err;
724
725 if ((err = i2c_detach_client(client))) {
726 dev_err(&client->dev, "Client deregistration failed, "
727 "client not detached.\n");
728 return err;
729 }
730
731 kfree(i2c_get_clientdata(client));
732 return 0;
733}
734
735static struct lm87_data *lm87_update_device(struct device *dev)
736{
737 struct i2c_client *client = to_i2c_client(dev);
738 struct lm87_data *data = i2c_get_clientdata(client);
739
740 down(&data->update_lock);
741
742 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
743 int i, j;
744
745 dev_dbg(&client->dev, "Updating data.\n");
746
747 i = (data->channel & CHAN_TEMP3) ? 1 : 0;
748 j = (data->channel & CHAN_TEMP3) ? 5 : 6;
749 for (; i < j; i++) {
750 data->in[i] = lm87_read_value(client,
751 LM87_REG_IN(i));
752 data->in_min[i] = lm87_read_value(client,
753 LM87_REG_IN_MIN(i));
754 data->in_max[i] = lm87_read_value(client,
755 LM87_REG_IN_MAX(i));
756 }
757
758 for (i = 0; i < 2; i++) {
759 if (data->channel & CHAN_NO_FAN(i)) {
760 data->in[6+i] = lm87_read_value(client,
761 LM87_REG_AIN(i));
762 data->in_max[6+i] = lm87_read_value(client,
763 LM87_REG_AIN_MAX(i));
764 data->in_min[6+i] = lm87_read_value(client,
765 LM87_REG_AIN_MIN(i));
766
767 } else {
768 data->fan[i] = lm87_read_value(client,
769 LM87_REG_FAN(i));
770 data->fan_min[i] = lm87_read_value(client,
771 LM87_REG_FAN_MIN(i));
772 }
773 }
774
775 j = (data->channel & CHAN_TEMP3) ? 3 : 2;
776 for (i = 0 ; i < j; i++) {
777 data->temp[i] = lm87_read_value(client,
778 LM87_REG_TEMP[i]);
779 data->temp_high[i] = lm87_read_value(client,
780 LM87_REG_TEMP_HIGH[i]);
781 data->temp_low[i] = lm87_read_value(client,
782 LM87_REG_TEMP_LOW[i]);
783 }
784
785 i = lm87_read_value(client, LM87_REG_TEMP_HW_INT_LOCK);
786 j = lm87_read_value(client, LM87_REG_TEMP_HW_INT);
787 data->temp_crit_int = min(i, j);
788
789 i = lm87_read_value(client, LM87_REG_TEMP_HW_EXT_LOCK);
790 j = lm87_read_value(client, LM87_REG_TEMP_HW_EXT);
791 data->temp_crit_ext = min(i, j);
792
793 i = lm87_read_value(client, LM87_REG_VID_FAN_DIV);
794 data->fan_div[0] = (i >> 4) & 0x03;
795 data->fan_div[1] = (i >> 6) & 0x03;
796 data->vid = (i & 0x0F)
797 | (lm87_read_value(client, LM87_REG_VID4) & 0x01)
798 << 4;
799
800 data->alarms = lm87_read_value(client, LM87_REG_ALARMS1)
801 | (lm87_read_value(client, LM87_REG_ALARMS2)
802 << 8);
803 data->aout = lm87_read_value(client, LM87_REG_AOUT);
804
805 data->last_updated = jiffies;
806 data->valid = 1;
807 }
808
809 up(&data->update_lock);
810
811 return data;
812}
813
814static int __init sensors_lm87_init(void)
815{
816 return i2c_add_driver(&lm87_driver);
817}
818
819static void __exit sensors_lm87_exit(void)
820{
821 i2c_del_driver(&lm87_driver);
822}
823
824MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org> and others");
825MODULE_DESCRIPTION("LM87 driver");
826MODULE_LICENSE("GPL");
827
828module_init(sensors_lm87_init);
829module_exit(sensors_lm87_exit);
diff --git a/drivers/i2c/chips/lm90.c b/drivers/i2c/chips/lm90.c
deleted file mode 100644
index 2c00ff83babc..000000000000
--- a/drivers/i2c/chips/lm90.c
+++ /dev/null
@@ -1,626 +0,0 @@
1/*
2 * lm90.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org>
5 *
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
8 * one external one) with a 0.125 deg resolution (1 deg for local
9 * temperature) and a 3-4 deg accuracy. Complete datasheet can be
10 * obtained from National's website at:
11 * http://www.national.com/pf/LM/LM90.html
12 *
13 * This driver also supports the LM89 and LM99, two other sensor chips
14 * made by National Semiconductor. Both have an increased remote
15 * temperature measurement accuracy (1 degree), and the LM99
16 * additionally shifts remote temperatures (measured and limits) by 16
17 * degrees, which allows for higher temperatures measurement. The
18 * driver doesn't handle it since it can be done easily in user-space.
19 * Complete datasheets can be obtained from National's website at:
20 * http://www.national.com/pf/LM/LM89.html
21 * http://www.national.com/pf/LM/LM99.html
22 * Note that there is no way to differenciate between both chips.
23 *
24 * This driver also supports the LM86, another sensor chip made by
25 * National Semiconductor. It is exactly similar to the LM90 except it
26 * has a higher accuracy.
27 * Complete datasheet can be obtained from National's website at:
28 * http://www.national.com/pf/LM/LM86.html
29 *
30 * This driver also supports the ADM1032, a sensor chip made by Analog
31 * Devices. That chip is similar to the LM90, with a few differences
32 * that are not handled by this driver. Complete datasheet can be
33 * obtained from Analog's website at:
34 * http://products.analog.com/products/info.asp?product=ADM1032
35 * Among others, it has a higher accuracy than the LM90, much like the
36 * LM86 does.
37 *
38 * This driver also supports the MAX6657, MAX6658 and MAX6659 sensor
39 * chips made by Maxim. These chips are similar to the LM86. Complete
40 * datasheet can be obtained at Maxim's website at:
41 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2578
42 * Note that there is no easy way to differenciate between the three
43 * variants. The extra address and features of the MAX6659 are not
44 * supported by this driver.
45 *
46 * This driver also supports the ADT7461 chip from Analog Devices but
47 * only in its "compatability mode". If an ADT7461 chip is found but
48 * is configured in non-compatible mode (where its temperature
49 * register values are decoded differently) it is ignored by this
50 * driver. Complete datasheet can be obtained from Analog's website
51 * at:
52 * http://products.analog.com/products/info.asp?product=ADT7461
53 *
54 * Since the LM90 was the first chipset supported by this driver, most
55 * comments will refer to this chipset, but are actually general and
56 * concern all supported chipsets, unless mentioned otherwise.
57 *
58 * This program is free software; you can redistribute it and/or modify
59 * it under the terms of the GNU General Public License as published by
60 * the Free Software Foundation; either version 2 of the License, or
61 * (at your option) any later version.
62 *
63 * This program is distributed in the hope that it will be useful,
64 * but WITHOUT ANY WARRANTY; without even the implied warranty of
65 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66 * GNU General Public License for more details.
67 *
68 * You should have received a copy of the GNU General Public License
69 * along with this program; if not, write to the Free Software
70 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
71 */
72
73#include <linux/config.h>
74#include <linux/module.h>
75#include <linux/init.h>
76#include <linux/slab.h>
77#include <linux/jiffies.h>
78#include <linux/i2c.h>
79#include <linux/i2c-sensor.h>
80
81/*
82 * Addresses to scan
83 * Address is fully defined internally and cannot be changed except for
84 * MAX6659.
85 * LM86, LM89, LM90, LM99, ADM1032, MAX6657 and MAX6658 have address 0x4c.
86 * LM89-1, and LM99-1 have address 0x4d.
87 * MAX6659 can have address 0x4c, 0x4d or 0x4e (unsupported).
88 * ADT7461 always has address 0x4c.
89 */
90
91static unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END };
92static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
93
94/*
95 * Insmod parameters
96 */
97
98SENSORS_INSMOD_6(lm90, adm1032, lm99, lm86, max6657, adt7461);
99
100/*
101 * The LM90 registers
102 */
103
104#define LM90_REG_R_MAN_ID 0xFE
105#define LM90_REG_R_CHIP_ID 0xFF
106#define LM90_REG_R_CONFIG1 0x03
107#define LM90_REG_W_CONFIG1 0x09
108#define LM90_REG_R_CONFIG2 0xBF
109#define LM90_REG_W_CONFIG2 0xBF
110#define LM90_REG_R_CONVRATE 0x04
111#define LM90_REG_W_CONVRATE 0x0A
112#define LM90_REG_R_STATUS 0x02
113#define LM90_REG_R_LOCAL_TEMP 0x00
114#define LM90_REG_R_LOCAL_HIGH 0x05
115#define LM90_REG_W_LOCAL_HIGH 0x0B
116#define LM90_REG_R_LOCAL_LOW 0x06
117#define LM90_REG_W_LOCAL_LOW 0x0C
118#define LM90_REG_R_LOCAL_CRIT 0x20
119#define LM90_REG_W_LOCAL_CRIT 0x20
120#define LM90_REG_R_REMOTE_TEMPH 0x01
121#define LM90_REG_R_REMOTE_TEMPL 0x10
122#define LM90_REG_R_REMOTE_OFFSH 0x11
123#define LM90_REG_W_REMOTE_OFFSH 0x11
124#define LM90_REG_R_REMOTE_OFFSL 0x12
125#define LM90_REG_W_REMOTE_OFFSL 0x12
126#define LM90_REG_R_REMOTE_HIGHH 0x07
127#define LM90_REG_W_REMOTE_HIGHH 0x0D
128#define LM90_REG_R_REMOTE_HIGHL 0x13
129#define LM90_REG_W_REMOTE_HIGHL 0x13
130#define LM90_REG_R_REMOTE_LOWH 0x08
131#define LM90_REG_W_REMOTE_LOWH 0x0E
132#define LM90_REG_R_REMOTE_LOWL 0x14
133#define LM90_REG_W_REMOTE_LOWL 0x14
134#define LM90_REG_R_REMOTE_CRIT 0x19
135#define LM90_REG_W_REMOTE_CRIT 0x19
136#define LM90_REG_R_TCRIT_HYST 0x21
137#define LM90_REG_W_TCRIT_HYST 0x21
138
139/*
140 * Conversions and various macros
141 * For local temperatures and limits, critical limits and the hysteresis
142 * value, the LM90 uses signed 8-bit values with LSB = 1 degree Celcius.
143 * For remote temperatures and limits, it uses signed 11-bit values with
144 * LSB = 0.125 degree Celcius, left-justified in 16-bit registers.
145 */
146
147#define TEMP1_FROM_REG(val) ((val) * 1000)
148#define TEMP1_TO_REG(val) ((val) <= -128000 ? -128 : \
149 (val) >= 127000 ? 127 : \
150 (val) < 0 ? ((val) - 500) / 1000 : \
151 ((val) + 500) / 1000)
152#define TEMP2_FROM_REG(val) ((val) / 32 * 125)
153#define TEMP2_TO_REG(val) ((val) <= -128000 ? 0x8000 : \
154 (val) >= 127875 ? 0x7FE0 : \
155 (val) < 0 ? ((val) - 62) / 125 * 32 : \
156 ((val) + 62) / 125 * 32)
157#define HYST_TO_REG(val) ((val) <= 0 ? 0 : (val) >= 30500 ? 31 : \
158 ((val) + 500) / 1000)
159
160/*
161 * ADT7461 is almost identical to LM90 except that attempts to write
162 * values that are outside the range 0 < temp < 127 are treated as
163 * the boundary value.
164 */
165
166#define TEMP1_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \
167 (val) >= 127000 ? 127 : \
168 ((val) + 500) / 1000)
169#define TEMP2_TO_REG_ADT7461(val) ((val) <= 0 ? 0 : \
170 (val) >= 127750 ? 0x7FC0 : \
171 ((val) + 125) / 250 * 64)
172
173/*
174 * Functions declaration
175 */
176
177static int lm90_attach_adapter(struct i2c_adapter *adapter);
178static int lm90_detect(struct i2c_adapter *adapter, int address,
179 int kind);
180static void lm90_init_client(struct i2c_client *client);
181static int lm90_detach_client(struct i2c_client *client);
182static struct lm90_data *lm90_update_device(struct device *dev);
183
184/*
185 * Driver data (common to all clients)
186 */
187
188static struct i2c_driver lm90_driver = {
189 .owner = THIS_MODULE,
190 .name = "lm90",
191 .id = I2C_DRIVERID_LM90,
192 .flags = I2C_DF_NOTIFY,
193 .attach_adapter = lm90_attach_adapter,
194 .detach_client = lm90_detach_client,
195};
196
197/*
198 * Client data (each client gets its own)
199 */
200
201struct lm90_data {
202 struct i2c_client client;
203 struct semaphore update_lock;
204 char valid; /* zero until following fields are valid */
205 unsigned long last_updated; /* in jiffies */
206 int kind;
207
208 /* registers values */
209 s8 temp_input1, temp_low1, temp_high1; /* local */
210 s16 temp_input2, temp_low2, temp_high2; /* remote, combined */
211 s8 temp_crit1, temp_crit2;
212 u8 temp_hyst;
213 u8 alarms; /* bitvector */
214};
215
216/*
217 * Sysfs stuff
218 */
219
220#define show_temp(value, converter) \
221static ssize_t show_##value(struct device *dev, char *buf) \
222{ \
223 struct lm90_data *data = lm90_update_device(dev); \
224 return sprintf(buf, "%d\n", converter(data->value)); \
225}
226show_temp(temp_input1, TEMP1_FROM_REG);
227show_temp(temp_input2, TEMP2_FROM_REG);
228show_temp(temp_low1, TEMP1_FROM_REG);
229show_temp(temp_low2, TEMP2_FROM_REG);
230show_temp(temp_high1, TEMP1_FROM_REG);
231show_temp(temp_high2, TEMP2_FROM_REG);
232show_temp(temp_crit1, TEMP1_FROM_REG);
233show_temp(temp_crit2, TEMP1_FROM_REG);
234
235#define set_temp1(value, reg) \
236static ssize_t set_##value(struct device *dev, const char *buf, \
237 size_t count) \
238{ \
239 struct i2c_client *client = to_i2c_client(dev); \
240 struct lm90_data *data = i2c_get_clientdata(client); \
241 long val = simple_strtol(buf, NULL, 10); \
242 \
243 down(&data->update_lock); \
244 if (data->kind == adt7461) \
245 data->value = TEMP1_TO_REG_ADT7461(val); \
246 else \
247 data->value = TEMP1_TO_REG(val); \
248 i2c_smbus_write_byte_data(client, reg, data->value); \
249 up(&data->update_lock); \
250 return count; \
251}
252#define set_temp2(value, regh, regl) \
253static ssize_t set_##value(struct device *dev, const char *buf, \
254 size_t count) \
255{ \
256 struct i2c_client *client = to_i2c_client(dev); \
257 struct lm90_data *data = i2c_get_clientdata(client); \
258 long val = simple_strtol(buf, NULL, 10); \
259 \
260 down(&data->update_lock); \
261 if (data->kind == adt7461) \
262 data->value = TEMP2_TO_REG_ADT7461(val); \
263 else \
264 data->value = TEMP2_TO_REG(val); \
265 i2c_smbus_write_byte_data(client, regh, data->value >> 8); \
266 i2c_smbus_write_byte_data(client, regl, data->value & 0xff); \
267 up(&data->update_lock); \
268 return count; \
269}
270set_temp1(temp_low1, LM90_REG_W_LOCAL_LOW);
271set_temp2(temp_low2, LM90_REG_W_REMOTE_LOWH, LM90_REG_W_REMOTE_LOWL);
272set_temp1(temp_high1, LM90_REG_W_LOCAL_HIGH);
273set_temp2(temp_high2, LM90_REG_W_REMOTE_HIGHH, LM90_REG_W_REMOTE_HIGHL);
274set_temp1(temp_crit1, LM90_REG_W_LOCAL_CRIT);
275set_temp1(temp_crit2, LM90_REG_W_REMOTE_CRIT);
276
277#define show_temp_hyst(value, basereg) \
278static ssize_t show_##value(struct device *dev, char *buf) \
279{ \
280 struct lm90_data *data = lm90_update_device(dev); \
281 return sprintf(buf, "%d\n", TEMP1_FROM_REG(data->basereg) \
282 - TEMP1_FROM_REG(data->temp_hyst)); \
283}
284show_temp_hyst(temp_hyst1, temp_crit1);
285show_temp_hyst(temp_hyst2, temp_crit2);
286
287static ssize_t set_temp_hyst1(struct device *dev, const char *buf,
288 size_t count)
289{
290 struct i2c_client *client = to_i2c_client(dev);
291 struct lm90_data *data = i2c_get_clientdata(client);
292 long val = simple_strtol(buf, NULL, 10);
293 long hyst;
294
295 down(&data->update_lock);
296 hyst = TEMP1_FROM_REG(data->temp_crit1) - val;
297 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
298 HYST_TO_REG(hyst));
299 up(&data->update_lock);
300 return count;
301}
302
303static ssize_t show_alarms(struct device *dev, char *buf)
304{
305 struct lm90_data *data = lm90_update_device(dev);
306 return sprintf(buf, "%d\n", data->alarms);
307}
308
309static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
310static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input2, NULL);
311static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_low1,
312 set_temp_low1);
313static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_low2,
314 set_temp_low2);
315static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_high1,
316 set_temp_high1);
317static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_high2,
318 set_temp_high2);
319static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_crit1,
320 set_temp_crit1);
321static DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit2,
322 set_temp_crit2);
323static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst1,
324 set_temp_hyst1);
325static DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temp_hyst2, NULL);
326static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
327
328/*
329 * Real code
330 */
331
332static int lm90_attach_adapter(struct i2c_adapter *adapter)
333{
334 if (!(adapter->class & I2C_CLASS_HWMON))
335 return 0;
336 return i2c_detect(adapter, &addr_data, lm90_detect);
337}
338
339/*
340 * The following function does more than just detection. If detection
341 * succeeds, it also registers the new chip.
342 */
343static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
344{
345 struct i2c_client *new_client;
346 struct lm90_data *data;
347 int err = 0;
348 const char *name = "";
349
350 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
351 goto exit;
352
353 if (!(data = kmalloc(sizeof(struct lm90_data), GFP_KERNEL))) {
354 err = -ENOMEM;
355 goto exit;
356 }
357 memset(data, 0, sizeof(struct lm90_data));
358
359 /* The common I2C client data is placed right before the
360 LM90-specific data. */
361 new_client = &data->client;
362 i2c_set_clientdata(new_client, data);
363 new_client->addr = address;
364 new_client->adapter = adapter;
365 new_client->driver = &lm90_driver;
366 new_client->flags = 0;
367
368 /*
369 * Now we do the remaining detection. A negative kind means that
370 * the driver was loaded with no force parameter (default), so we
371 * must both detect and identify the chip. A zero kind means that
372 * the driver was loaded with the force parameter, the detection
373 * step shall be skipped. A positive kind means that the driver
374 * was loaded with the force parameter and a given kind of chip is
375 * requested, so both the detection and the identification steps
376 * are skipped.
377 */
378
379 /* Default to an LM90 if forced */
380 if (kind == 0)
381 kind = lm90;
382
383 if (kind < 0) { /* detection and identification */
384 u8 man_id, chip_id, reg_config1, reg_convrate;
385
386 man_id = i2c_smbus_read_byte_data(new_client,
387 LM90_REG_R_MAN_ID);
388 chip_id = i2c_smbus_read_byte_data(new_client,
389 LM90_REG_R_CHIP_ID);
390 reg_config1 = i2c_smbus_read_byte_data(new_client,
391 LM90_REG_R_CONFIG1);
392 reg_convrate = i2c_smbus_read_byte_data(new_client,
393 LM90_REG_R_CONVRATE);
394
395 if (man_id == 0x01) { /* National Semiconductor */
396 u8 reg_config2;
397
398 reg_config2 = i2c_smbus_read_byte_data(new_client,
399 LM90_REG_R_CONFIG2);
400
401 if ((reg_config1 & 0x2A) == 0x00
402 && (reg_config2 & 0xF8) == 0x00
403 && reg_convrate <= 0x09) {
404 if (address == 0x4C
405 && (chip_id & 0xF0) == 0x20) { /* LM90 */
406 kind = lm90;
407 } else
408 if ((chip_id & 0xF0) == 0x30) { /* LM89/LM99 */
409 kind = lm99;
410 } else
411 if (address == 0x4C
412 && (chip_id & 0xF0) == 0x10) { /* LM86 */
413 kind = lm86;
414 }
415 }
416 } else
417 if (man_id == 0x41) { /* Analog Devices */
418 if (address == 0x4C
419 && (chip_id & 0xF0) == 0x40 /* ADM1032 */
420 && (reg_config1 & 0x3F) == 0x00
421 && reg_convrate <= 0x0A) {
422 kind = adm1032;
423 } else
424 if (address == 0x4c
425 && chip_id == 0x51 /* ADT7461 */
426 && (reg_config1 & 0x1F) == 0x00 /* check compat mode */
427 && reg_convrate <= 0x0A) {
428 kind = adt7461;
429 }
430 } else
431 if (man_id == 0x4D) { /* Maxim */
432 /*
433 * The Maxim variants do NOT have a chip_id register.
434 * Reading from that address will return the last read
435 * value, which in our case is those of the man_id
436 * register. Likewise, the config1 register seems to
437 * lack a low nibble, so the value will be those of the
438 * previous read, so in our case those of the man_id
439 * register.
440 */
441 if (chip_id == man_id
442 && (reg_config1 & 0x1F) == (man_id & 0x0F)
443 && reg_convrate <= 0x09) {
444 kind = max6657;
445 }
446 }
447
448 if (kind <= 0) { /* identification failed */
449 dev_info(&adapter->dev,
450 "Unsupported chip (man_id=0x%02X, "
451 "chip_id=0x%02X).\n", man_id, chip_id);
452 goto exit_free;
453 }
454 }
455
456 if (kind == lm90) {
457 name = "lm90";
458 } else if (kind == adm1032) {
459 name = "adm1032";
460 } else if (kind == lm99) {
461 name = "lm99";
462 } else if (kind == lm86) {
463 name = "lm86";
464 } else if (kind == max6657) {
465 name = "max6657";
466 } else if (kind == adt7461) {
467 name = "adt7461";
468 }
469
470 /* We can fill in the remaining client fields */
471 strlcpy(new_client->name, name, I2C_NAME_SIZE);
472 data->valid = 0;
473 data->kind = kind;
474 init_MUTEX(&data->update_lock);
475
476 /* Tell the I2C layer a new client has arrived */
477 if ((err = i2c_attach_client(new_client)))
478 goto exit_free;
479
480 /* Initialize the LM90 chip */
481 lm90_init_client(new_client);
482
483 /* Register sysfs hooks */
484 device_create_file(&new_client->dev, &dev_attr_temp1_input);
485 device_create_file(&new_client->dev, &dev_attr_temp2_input);
486 device_create_file(&new_client->dev, &dev_attr_temp1_min);
487 device_create_file(&new_client->dev, &dev_attr_temp2_min);
488 device_create_file(&new_client->dev, &dev_attr_temp1_max);
489 device_create_file(&new_client->dev, &dev_attr_temp2_max);
490 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
491 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
492 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
493 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
494 device_create_file(&new_client->dev, &dev_attr_alarms);
495
496 return 0;
497
498exit_free:
499 kfree(data);
500exit:
501 return err;
502}
503
504static void lm90_init_client(struct i2c_client *client)
505{
506 u8 config;
507
508 /*
509 * Start the conversions.
510 */
511 i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE,
512 5); /* 2 Hz */
513 config = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1);
514 if (config & 0x40)
515 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
516 config & 0xBF); /* run */
517}
518
519static int lm90_detach_client(struct i2c_client *client)
520{
521 int err;
522
523 if ((err = i2c_detach_client(client))) {
524 dev_err(&client->dev, "Client deregistration failed, "
525 "client not detached.\n");
526 return err;
527 }
528
529 kfree(i2c_get_clientdata(client));
530 return 0;
531}
532
533static struct lm90_data *lm90_update_device(struct device *dev)
534{
535 struct i2c_client *client = to_i2c_client(dev);
536 struct lm90_data *data = i2c_get_clientdata(client);
537
538 down(&data->update_lock);
539
540 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
541 u8 oldh, newh;
542
543 dev_dbg(&client->dev, "Updating lm90 data.\n");
544 data->temp_input1 = i2c_smbus_read_byte_data(client,
545 LM90_REG_R_LOCAL_TEMP);
546 data->temp_high1 = i2c_smbus_read_byte_data(client,
547 LM90_REG_R_LOCAL_HIGH);
548 data->temp_low1 = i2c_smbus_read_byte_data(client,
549 LM90_REG_R_LOCAL_LOW);
550 data->temp_crit1 = i2c_smbus_read_byte_data(client,
551 LM90_REG_R_LOCAL_CRIT);
552 data->temp_crit2 = i2c_smbus_read_byte_data(client,
553 LM90_REG_R_REMOTE_CRIT);
554 data->temp_hyst = i2c_smbus_read_byte_data(client,
555 LM90_REG_R_TCRIT_HYST);
556
557 /*
558 * There is a trick here. We have to read two registers to
559 * have the remote sensor temperature, but we have to beware
560 * a conversion could occur inbetween the readings. The
561 * datasheet says we should either use the one-shot
562 * conversion register, which we don't want to do (disables
563 * hardware monitoring) or monitor the busy bit, which is
564 * impossible (we can't read the values and monitor that bit
565 * at the exact same time). So the solution used here is to
566 * read the high byte once, then the low byte, then the high
567 * byte again. If the new high byte matches the old one,
568 * then we have a valid reading. Else we have to read the low
569 * byte again, and now we believe we have a correct reading.
570 */
571 oldh = i2c_smbus_read_byte_data(client,
572 LM90_REG_R_REMOTE_TEMPH);
573 data->temp_input2 = i2c_smbus_read_byte_data(client,
574 LM90_REG_R_REMOTE_TEMPL);
575 newh = i2c_smbus_read_byte_data(client,
576 LM90_REG_R_REMOTE_TEMPH);
577 if (newh != oldh) {
578 data->temp_input2 = i2c_smbus_read_byte_data(client,
579 LM90_REG_R_REMOTE_TEMPL);
580#ifdef DEBUG
581 oldh = i2c_smbus_read_byte_data(client,
582 LM90_REG_R_REMOTE_TEMPH);
583 /* oldh is actually newer */
584 if (newh != oldh)
585 dev_warn(&client->dev, "Remote temperature may be "
586 "wrong.\n");
587#endif
588 }
589 data->temp_input2 |= (newh << 8);
590
591 data->temp_high2 = (i2c_smbus_read_byte_data(client,
592 LM90_REG_R_REMOTE_HIGHH) << 8) +
593 i2c_smbus_read_byte_data(client,
594 LM90_REG_R_REMOTE_HIGHL);
595 data->temp_low2 = (i2c_smbus_read_byte_data(client,
596 LM90_REG_R_REMOTE_LOWH) << 8) +
597 i2c_smbus_read_byte_data(client,
598 LM90_REG_R_REMOTE_LOWL);
599 data->alarms = i2c_smbus_read_byte_data(client,
600 LM90_REG_R_STATUS);
601
602 data->last_updated = jiffies;
603 data->valid = 1;
604 }
605
606 up(&data->update_lock);
607
608 return data;
609}
610
611static int __init sensors_lm90_init(void)
612{
613 return i2c_add_driver(&lm90_driver);
614}
615
616static void __exit sensors_lm90_exit(void)
617{
618 i2c_del_driver(&lm90_driver);
619}
620
621MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
622MODULE_DESCRIPTION("LM90/ADM1032 driver");
623MODULE_LICENSE("GPL");
624
625module_init(sensors_lm90_init);
626module_exit(sensors_lm90_exit);
diff --git a/drivers/i2c/chips/lm92.c b/drivers/i2c/chips/lm92.c
deleted file mode 100644
index fe6e83d70a72..000000000000
--- a/drivers/i2c/chips/lm92.c
+++ /dev/null
@@ -1,429 +0,0 @@
1/*
2 * lm92 - Hardware monitoring driver
3 * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
4 *
5 * Based on the lm90 driver, with some ideas taken from the lm_sensors
6 * lm92 driver as well.
7 *
8 * The LM92 is a sensor chip made by National Semiconductor. It reports
9 * its own temperature with a 0.0625 deg resolution and a 0.33 deg
10 * accuracy. Complete datasheet can be obtained from National's website
11 * at:
12 * http://www.national.com/pf/LM/LM92.html
13 *
14 * This driver also supports the MAX6635 sensor chip made by Maxim.
15 * This chip is compatible with the LM92, but has a lesser accuracy
16 * (1.0 deg). Complete datasheet can be obtained from Maxim's website
17 * at:
18 * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3074
19 *
20 * Since the LM92 was the first chipset supported by this driver, most
21 * comments will refer to this chipset, but are actually general and
22 * concern all supported chipsets, unless mentioned otherwise.
23 *
24 * Support could easily be added for the National Semiconductor LM76
25 * and Maxim MAX6633 and MAX6634 chips, which are mostly compatible
26 * with the LM92.
27 *
28 * This program is free software; you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation; either version 2 of the License, or
31 * (at your option) any later version.
32 *
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
41 */
42
43#include <linux/module.h>
44#include <linux/init.h>
45#include <linux/slab.h>
46#include <linux/i2c.h>
47#include <linux/i2c-sensor.h>
48
49
50/* The LM92 and MAX6635 have 2 two-state pins for address selection,
51 resulting in 4 possible addresses. */
52static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
53 I2C_CLIENT_END };
54static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
55
56/* Insmod parameters */
57SENSORS_INSMOD_1(lm92);
58
59/* The LM92 registers */
60#define LM92_REG_CONFIG 0x01 /* 8-bit, RW */
61#define LM92_REG_TEMP 0x00 /* 16-bit, RO */
62#define LM92_REG_TEMP_HYST 0x02 /* 16-bit, RW */
63#define LM92_REG_TEMP_CRIT 0x03 /* 16-bit, RW */
64#define LM92_REG_TEMP_LOW 0x04 /* 16-bit, RW */
65#define LM92_REG_TEMP_HIGH 0x05 /* 16-bit, RW */
66#define LM92_REG_MAN_ID 0x07 /* 16-bit, RO, LM92 only */
67
68/* The LM92 uses signed 13-bit values with LSB = 0.0625 degree Celsius,
69 left-justified in 16-bit registers. No rounding is done, with such
70 a resolution it's just not worth it. Note that the MAX6635 doesn't
71 make use of the 4 lower bits for limits (i.e. effective resolution
72 for limits is 1 degree Celsius). */
73static inline int TEMP_FROM_REG(s16 reg)
74{
75 return reg / 8 * 625 / 10;
76}
77
78static inline s16 TEMP_TO_REG(int val)
79{
80 if (val <= -60000)
81 return -60000 * 10 / 625 * 8;
82 if (val >= 160000)
83 return 160000 * 10 / 625 * 8;
84 return val * 10 / 625 * 8;
85}
86
87/* Alarm flags are stored in the 3 LSB of the temperature register */
88static inline u8 ALARMS_FROM_REG(s16 reg)
89{
90 return reg & 0x0007;
91}
92
93/* Driver data (common to all clients) */
94static struct i2c_driver lm92_driver;
95
96/* Client data (each client gets its own) */
97struct lm92_data {
98 struct i2c_client client;
99 struct semaphore update_lock;
100 char valid; /* zero until following fields are valid */
101 unsigned long last_updated; /* in jiffies */
102
103 /* registers values */
104 s16 temp1_input, temp1_crit, temp1_min, temp1_max, temp1_hyst;
105};
106
107
108/*
109 * Sysfs attributes and callback functions
110 */
111
112static struct lm92_data *lm92_update_device(struct device *dev)
113{
114 struct i2c_client *client = to_i2c_client(dev);
115 struct lm92_data *data = i2c_get_clientdata(client);
116
117 down(&data->update_lock);
118
119 if (time_after(jiffies, data->last_updated + HZ)
120 || !data->valid) {
121 dev_dbg(&client->dev, "Updating lm92 data\n");
122 data->temp1_input = swab16(i2c_smbus_read_word_data(client,
123 LM92_REG_TEMP));
124 data->temp1_hyst = swab16(i2c_smbus_read_word_data(client,
125 LM92_REG_TEMP_HYST));
126 data->temp1_crit = swab16(i2c_smbus_read_word_data(client,
127 LM92_REG_TEMP_CRIT));
128 data->temp1_min = swab16(i2c_smbus_read_word_data(client,
129 LM92_REG_TEMP_LOW));
130 data->temp1_max = swab16(i2c_smbus_read_word_data(client,
131 LM92_REG_TEMP_HIGH));
132
133 data->last_updated = jiffies;
134 data->valid = 1;
135 }
136
137 up(&data->update_lock);
138
139 return data;
140}
141
142#define show_temp(value) \
143static ssize_t show_##value(struct device *dev, char *buf) \
144{ \
145 struct lm92_data *data = lm92_update_device(dev); \
146 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
147}
148show_temp(temp1_input);
149show_temp(temp1_crit);
150show_temp(temp1_min);
151show_temp(temp1_max);
152
153#define set_temp(value, reg) \
154static ssize_t set_##value(struct device *dev, const char *buf, \
155 size_t count) \
156{ \
157 struct i2c_client *client = to_i2c_client(dev); \
158 struct lm92_data *data = i2c_get_clientdata(client); \
159 long val = simple_strtol(buf, NULL, 10); \
160 \
161 down(&data->update_lock); \
162 data->value = TEMP_TO_REG(val); \
163 i2c_smbus_write_word_data(client, reg, swab16(data->value)); \
164 up(&data->update_lock); \
165 return count; \
166}
167set_temp(temp1_crit, LM92_REG_TEMP_CRIT);
168set_temp(temp1_min, LM92_REG_TEMP_LOW);
169set_temp(temp1_max, LM92_REG_TEMP_HIGH);
170
171static ssize_t show_temp1_crit_hyst(struct device *dev, char *buf)
172{
173 struct lm92_data *data = lm92_update_device(dev);
174 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_crit)
175 - TEMP_FROM_REG(data->temp1_hyst));
176}
177static ssize_t show_temp1_max_hyst(struct device *dev, char *buf)
178{
179 struct lm92_data *data = lm92_update_device(dev);
180 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_max)
181 - TEMP_FROM_REG(data->temp1_hyst));
182}
183static ssize_t show_temp1_min_hyst(struct device *dev, char *buf)
184{
185 struct lm92_data *data = lm92_update_device(dev);
186 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp1_min)
187 + TEMP_FROM_REG(data->temp1_hyst));
188}
189
190static ssize_t set_temp1_crit_hyst(struct device *dev, const char *buf,
191 size_t count)
192{
193 struct i2c_client *client = to_i2c_client(dev);
194 struct lm92_data *data = i2c_get_clientdata(client);
195 long val = simple_strtol(buf, NULL, 10);
196
197 down(&data->update_lock);
198 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
199 i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST,
200 swab16(TEMP_TO_REG(data->temp1_hyst)));
201 up(&data->update_lock);
202 return count;
203}
204
205static ssize_t show_alarms(struct device *dev, char *buf)
206{
207 struct lm92_data *data = lm92_update_device(dev);
208 return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->temp1_input));
209}
210
211static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp1_input, NULL);
212static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp1_crit,
213 set_temp1_crit);
214static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp1_crit_hyst,
215 set_temp1_crit_hyst);
216static DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp1_min,
217 set_temp1_min);
218static DEVICE_ATTR(temp1_min_hyst, S_IRUGO, show_temp1_min_hyst, NULL);
219static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp1_max,
220 set_temp1_max);
221static DEVICE_ATTR(temp1_max_hyst, S_IRUGO, show_temp1_max_hyst, NULL);
222static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
223
224
225/*
226 * Detection and registration
227 */
228
229static void lm92_init_client(struct i2c_client *client)
230{
231 u8 config;
232
233 /* Start the conversions if needed */
234 config = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG);
235 if (config & 0x01)
236 i2c_smbus_write_byte_data(client, LM92_REG_CONFIG,
237 config & 0xFE);
238}
239
240/* The MAX6635 has no identification register, so we have to use tricks
241 to identify it reliably. This is somewhat slow.
242 Note that we do NOT rely on the 2 MSB of the configuration register
243 always reading 0, as suggested by the datasheet, because it was once
244 reported not to be true. */
245static int max6635_check(struct i2c_client *client)
246{
247 u16 temp_low, temp_high, temp_hyst, temp_crit;
248 u8 conf;
249 int i;
250
251 /* No manufacturer ID register, so a read from this address will
252 always return the last read value. */
253 temp_low = i2c_smbus_read_word_data(client, LM92_REG_TEMP_LOW);
254 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_low)
255 return 0;
256 temp_high = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HIGH);
257 if (i2c_smbus_read_word_data(client, LM92_REG_MAN_ID) != temp_high)
258 return 0;
259
260 /* Limits are stored as integer values (signed, 9-bit). */
261 if ((temp_low & 0x7f00) || (temp_high & 0x7f00))
262 return 0;
263 temp_hyst = i2c_smbus_read_word_data(client, LM92_REG_TEMP_HYST);
264 temp_crit = i2c_smbus_read_word_data(client, LM92_REG_TEMP_CRIT);
265 if ((temp_hyst & 0x7f00) || (temp_crit & 0x7f00))
266 return 0;
267
268 /* Registers addresses were found to cycle over 16-byte boundaries.
269 We don't test all registers with all offsets so as to save some
270 reads and time, but this should still be sufficient to dismiss
271 non-MAX6635 chips. */
272 conf = i2c_smbus_read_byte_data(client, LM92_REG_CONFIG);
273 for (i=16; i<96; i*=2) {
274 if (temp_hyst != i2c_smbus_read_word_data(client,
275 LM92_REG_TEMP_HYST + i - 16)
276 || temp_crit != i2c_smbus_read_word_data(client,
277 LM92_REG_TEMP_CRIT + i)
278 || temp_low != i2c_smbus_read_word_data(client,
279 LM92_REG_TEMP_LOW + i + 16)
280 || temp_high != i2c_smbus_read_word_data(client,
281 LM92_REG_TEMP_HIGH + i + 32)
282 || conf != i2c_smbus_read_byte_data(client,
283 LM92_REG_CONFIG + i))
284 return 0;
285 }
286
287 return 1;
288}
289
290/* The following function does more than just detection. If detection
291 succeeds, it also registers the new chip. */
292static int lm92_detect(struct i2c_adapter *adapter, int address, int kind)
293{
294 struct i2c_client *new_client;
295 struct lm92_data *data;
296 int err = 0;
297 char *name;
298
299 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
300 | I2C_FUNC_SMBUS_WORD_DATA))
301 goto exit;
302
303 if (!(data = kmalloc(sizeof(struct lm92_data), GFP_KERNEL))) {
304 err = -ENOMEM;
305 goto exit;
306 }
307 memset(data, 0, sizeof(struct lm92_data));
308
309 /* Fill in enough client fields so that we can read from the chip,
310 which is required for identication */
311 new_client = &data->client;
312 i2c_set_clientdata(new_client, data);
313 new_client->addr = address;
314 new_client->adapter = adapter;
315 new_client->driver = &lm92_driver;
316 new_client->flags = 0;
317
318 /* A negative kind means that the driver was loaded with no force
319 parameter (default), so we must identify the chip. */
320 if (kind < 0) {
321 u8 config = i2c_smbus_read_byte_data(new_client,
322 LM92_REG_CONFIG);
323 u16 man_id = i2c_smbus_read_word_data(new_client,
324 LM92_REG_MAN_ID);
325
326 if ((config & 0xe0) == 0x00
327 && man_id == 0x0180) {
328 pr_info("lm92: Found National Semiconductor LM92 chip\n");
329 kind = lm92;
330 } else
331 if (max6635_check(new_client)) {
332 pr_info("lm92: Found Maxim MAX6635 chip\n");
333 kind = lm92; /* No separate prefix */
334 }
335 else
336 goto exit_free;
337 } else
338 if (kind == 0) /* Default to an LM92 if forced */
339 kind = lm92;
340
341 /* Give it the proper name */
342 if (kind == lm92) {
343 name = "lm92";
344 } else { /* Supposedly cannot happen */
345 dev_dbg(&new_client->dev, "Kind out of range?\n");
346 goto exit_free;
347 }
348
349 /* Fill in the remaining client fields */
350 strlcpy(new_client->name, name, I2C_NAME_SIZE);
351 data->valid = 0;
352 init_MUTEX(&data->update_lock);
353
354 /* Tell the i2c subsystem a new client has arrived */
355 if ((err = i2c_attach_client(new_client)))
356 goto exit_free;
357
358 /* Initialize the chipset */
359 lm92_init_client(new_client);
360
361 /* Register sysfs hooks */
362 device_create_file(&new_client->dev, &dev_attr_temp1_input);
363 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
364 device_create_file(&new_client->dev, &dev_attr_temp1_crit_hyst);
365 device_create_file(&new_client->dev, &dev_attr_temp1_min);
366 device_create_file(&new_client->dev, &dev_attr_temp1_min_hyst);
367 device_create_file(&new_client->dev, &dev_attr_temp1_max);
368 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
369 device_create_file(&new_client->dev, &dev_attr_alarms);
370
371 return 0;
372
373exit_free:
374 kfree(data);
375exit:
376 return err;
377}
378
379static int lm92_attach_adapter(struct i2c_adapter *adapter)
380{
381 if (!(adapter->class & I2C_CLASS_HWMON))
382 return 0;
383 return i2c_detect(adapter, &addr_data, lm92_detect);
384}
385
386static int lm92_detach_client(struct i2c_client *client)
387{
388 int err;
389
390 if ((err = i2c_detach_client(client))) {
391 dev_err(&client->dev, "Client deregistration failed, "
392 "client not detached.\n");
393 return err;
394 }
395
396 kfree(i2c_get_clientdata(client));
397 return 0;
398}
399
400
401/*
402 * Module and driver stuff
403 */
404
405static struct i2c_driver lm92_driver = {
406 .owner = THIS_MODULE,
407 .name = "lm92",
408 .id = I2C_DRIVERID_LM92,
409 .flags = I2C_DF_NOTIFY,
410 .attach_adapter = lm92_attach_adapter,
411 .detach_client = lm92_detach_client,
412};
413
414static int __init sensors_lm92_init(void)
415{
416 return i2c_add_driver(&lm92_driver);
417}
418
419static void __exit sensors_lm92_exit(void)
420{
421 i2c_del_driver(&lm92_driver);
422}
423
424MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
425MODULE_DESCRIPTION("LM92/MAX6635 driver");
426MODULE_LICENSE("GPL");
427
428module_init(sensors_lm92_init);
429module_exit(sensors_lm92_exit);
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index e771566dffa8..3f14528a52a9 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -40,12 +40,8 @@ static unsigned short normal_addr[] = { 0x68, I2C_CLIENT_END };
40 40
41static struct i2c_client_address_data addr_data = { 41static struct i2c_client_address_data addr_data = {
42 .normal_i2c = normal_addr, 42 .normal_i2c = normal_addr,
43 .normal_i2c_range = ignore,
44 .probe = ignore, 43 .probe = ignore,
45 .probe_range = ignore,
46 .ignore = ignore, 44 .ignore = ignore,
47 .ignore_range = ignore,
48 .force = ignore,
49}; 45};
50 46
51ulong 47ulong
@@ -148,7 +144,7 @@ m41t00_set_tlet(ulong arg)
148 return; 144 return;
149} 145}
150 146
151ulong new_time; 147static ulong new_time;
152 148
153DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time); 149DECLARE_TASKLET_DISABLED(m41t00_tasklet, m41t00_set_tlet, (ulong)&new_time);
154 150
@@ -210,7 +206,7 @@ m41t00_detach(struct i2c_client *client)
210 int rc; 206 int rc;
211 207
212 if ((rc = i2c_detach_client(client)) == 0) { 208 if ((rc = i2c_detach_client(client)) == 0) {
213 kfree(i2c_get_clientdata(client)); 209 kfree(client);
214 tasklet_kill(&m41t00_tasklet); 210 tasklet_kill(&m41t00_tasklet);
215 } 211 }
216 return rc; 212 return rc;
diff --git a/drivers/i2c/chips/max1619.c b/drivers/i2c/chips/max1619.c
deleted file mode 100644
index 5afa961a5e10..000000000000
--- a/drivers/i2c/chips/max1619.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/*
2 * max1619.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2003-2004 Alexey Fisher <fishor@mail.ru>
5 * Jean Delvare <khali@linux-fr.org>
6 *
7 * Based on the lm90 driver. The MAX1619 is a sensor chip made by Maxim.
8 * It reports up to two temperatures (its own plus up to
9 * one external one). Complete datasheet can be
10 * obtained from Maxim's website at:
11 * http://pdfserv.maxim-ic.com/en/ds/MAX1619.pdf
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28
29#include <linux/config.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/jiffies.h>
34#include <linux/i2c.h>
35#include <linux/i2c-sensor.h>
36
37
38static unsigned short normal_i2c[] = { 0x18, 0x19, 0x1a,
39 0x29, 0x2a, 0x2b,
40 0x4c, 0x4d, 0x4e,
41 I2C_CLIENT_END };
42static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
43
44/*
45 * Insmod parameters
46 */
47
48SENSORS_INSMOD_1(max1619);
49
50/*
51 * The MAX1619 registers
52 */
53
54#define MAX1619_REG_R_MAN_ID 0xFE
55#define MAX1619_REG_R_CHIP_ID 0xFF
56#define MAX1619_REG_R_CONFIG 0x03
57#define MAX1619_REG_W_CONFIG 0x09
58#define MAX1619_REG_R_CONVRATE 0x04
59#define MAX1619_REG_W_CONVRATE 0x0A
60#define MAX1619_REG_R_STATUS 0x02
61#define MAX1619_REG_R_LOCAL_TEMP 0x00
62#define MAX1619_REG_R_REMOTE_TEMP 0x01
63#define MAX1619_REG_R_REMOTE_HIGH 0x07
64#define MAX1619_REG_W_REMOTE_HIGH 0x0D
65#define MAX1619_REG_R_REMOTE_LOW 0x08
66#define MAX1619_REG_W_REMOTE_LOW 0x0E
67#define MAX1619_REG_R_REMOTE_CRIT 0x10
68#define MAX1619_REG_W_REMOTE_CRIT 0x12
69#define MAX1619_REG_R_TCRIT_HYST 0x11
70#define MAX1619_REG_W_TCRIT_HYST 0x13
71
72/*
73 * Conversions and various macros
74 */
75
76#define TEMP_FROM_REG(val) ((val & 0x80 ? val-0x100 : val) * 1000)
77#define TEMP_TO_REG(val) ((val < 0 ? val+0x100*1000 : val) / 1000)
78
79/*
80 * Functions declaration
81 */
82
83static int max1619_attach_adapter(struct i2c_adapter *adapter);
84static int max1619_detect(struct i2c_adapter *adapter, int address,
85 int kind);
86static void max1619_init_client(struct i2c_client *client);
87static int max1619_detach_client(struct i2c_client *client);
88static struct max1619_data *max1619_update_device(struct device *dev);
89
90/*
91 * Driver data (common to all clients)
92 */
93
94static struct i2c_driver max1619_driver = {
95 .owner = THIS_MODULE,
96 .name = "max1619",
97 .flags = I2C_DF_NOTIFY,
98 .attach_adapter = max1619_attach_adapter,
99 .detach_client = max1619_detach_client,
100};
101
102/*
103 * Client data (each client gets its own)
104 */
105
106struct max1619_data {
107 struct i2c_client client;
108 struct semaphore update_lock;
109 char valid; /* zero until following fields are valid */
110 unsigned long last_updated; /* in jiffies */
111
112 /* registers values */
113 u8 temp_input1; /* local */
114 u8 temp_input2, temp_low2, temp_high2; /* remote */
115 u8 temp_crit2;
116 u8 temp_hyst2;
117 u8 alarms;
118};
119
120/*
121 * Sysfs stuff
122 */
123
124#define show_temp(value) \
125static ssize_t show_##value(struct device *dev, char *buf) \
126{ \
127 struct max1619_data *data = max1619_update_device(dev); \
128 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->value)); \
129}
130show_temp(temp_input1);
131show_temp(temp_input2);
132show_temp(temp_low2);
133show_temp(temp_high2);
134show_temp(temp_crit2);
135show_temp(temp_hyst2);
136
137#define set_temp2(value, reg) \
138static ssize_t set_##value(struct device *dev, const char *buf, \
139 size_t count) \
140{ \
141 struct i2c_client *client = to_i2c_client(dev); \
142 struct max1619_data *data = i2c_get_clientdata(client); \
143 long val = simple_strtol(buf, NULL, 10); \
144 \
145 down(&data->update_lock); \
146 data->value = TEMP_TO_REG(val); \
147 i2c_smbus_write_byte_data(client, reg, data->value); \
148 up(&data->update_lock); \
149 return count; \
150}
151
152set_temp2(temp_low2, MAX1619_REG_W_REMOTE_LOW);
153set_temp2(temp_high2, MAX1619_REG_W_REMOTE_HIGH);
154set_temp2(temp_crit2, MAX1619_REG_W_REMOTE_CRIT);
155set_temp2(temp_hyst2, MAX1619_REG_W_TCRIT_HYST);
156
157static ssize_t show_alarms(struct device *dev, char *buf)
158{
159 struct max1619_data *data = max1619_update_device(dev);
160 return sprintf(buf, "%d\n", data->alarms);
161}
162
163static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
164static DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input2, NULL);
165static DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_low2,
166 set_temp_low2);
167static DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_high2,
168 set_temp_high2);
169static DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp_crit2,
170 set_temp_crit2);
171static DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_temp_hyst2,
172 set_temp_hyst2);
173static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
174
175/*
176 * Real code
177 */
178
179static int max1619_attach_adapter(struct i2c_adapter *adapter)
180{
181 if (!(adapter->class & I2C_CLASS_HWMON))
182 return 0;
183 return i2c_detect(adapter, &addr_data, max1619_detect);
184}
185
186/*
187 * The following function does more than just detection. If detection
188 * succeeds, it also registers the new chip.
189 */
190static int max1619_detect(struct i2c_adapter *adapter, int address, int kind)
191{
192 struct i2c_client *new_client;
193 struct max1619_data *data;
194 int err = 0;
195 const char *name = "";
196 u8 reg_config=0, reg_convrate=0, reg_status=0;
197 u8 man_id, chip_id;
198 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
199 goto exit;
200
201 if (!(data = kmalloc(sizeof(struct max1619_data), GFP_KERNEL))) {
202 err = -ENOMEM;
203 goto exit;
204 }
205 memset(data, 0, sizeof(struct max1619_data));
206
207 /* The common I2C client data is placed right before the
208 MAX1619-specific data. */
209 new_client = &data->client;
210 i2c_set_clientdata(new_client, data);
211 new_client->addr = address;
212 new_client->adapter = adapter;
213 new_client->driver = &max1619_driver;
214 new_client->flags = 0;
215
216 /*
217 * Now we do the remaining detection. A negative kind means that
218 * the driver was loaded with no force parameter (default), so we
219 * must both detect and identify the chip. A zero kind means that
220 * the driver was loaded with the force parameter, the detection
221 * step shall be skipped. A positive kind means that the driver
222 * was loaded with the force parameter and a given kind of chip is
223 * requested, so both the detection and the identification steps
224 * are skipped.
225 */
226 if (kind < 0) { /* detection */
227 reg_config = i2c_smbus_read_byte_data(new_client,
228 MAX1619_REG_R_CONFIG);
229 reg_convrate = i2c_smbus_read_byte_data(new_client,
230 MAX1619_REG_R_CONVRATE);
231 reg_status = i2c_smbus_read_byte_data(new_client,
232 MAX1619_REG_R_STATUS);
233 if ((reg_config & 0x03) != 0x00
234 || reg_convrate > 0x07 || (reg_status & 0x61 ) !=0x00) {
235 dev_dbg(&adapter->dev,
236 "MAX1619 detection failed at 0x%02x.\n",
237 address);
238 goto exit_free;
239 }
240 }
241
242 if (kind <= 0) { /* identification */
243
244 man_id = i2c_smbus_read_byte_data(new_client,
245 MAX1619_REG_R_MAN_ID);
246 chip_id = i2c_smbus_read_byte_data(new_client,
247 MAX1619_REG_R_CHIP_ID);
248
249 if ((man_id == 0x4D) && (chip_id == 0x04)){
250 kind = max1619;
251 }
252 }
253
254 if (kind <= 0) { /* identification failed */
255 dev_info(&adapter->dev,
256 "Unsupported chip (man_id=0x%02X, "
257 "chip_id=0x%02X).\n", man_id, chip_id);
258 goto exit_free;
259 }
260
261
262 if (kind == max1619){
263 name = "max1619";
264 }
265
266 /* We can fill in the remaining client fields */
267 strlcpy(new_client->name, name, I2C_NAME_SIZE);
268 data->valid = 0;
269 init_MUTEX(&data->update_lock);
270
271 /* Tell the I2C layer a new client has arrived */
272 if ((err = i2c_attach_client(new_client)))
273 goto exit_free;
274
275 /* Initialize the MAX1619 chip */
276 max1619_init_client(new_client);
277
278 /* Register sysfs hooks */
279 device_create_file(&new_client->dev, &dev_attr_temp1_input);
280 device_create_file(&new_client->dev, &dev_attr_temp2_input);
281 device_create_file(&new_client->dev, &dev_attr_temp2_min);
282 device_create_file(&new_client->dev, &dev_attr_temp2_max);
283 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
284 device_create_file(&new_client->dev, &dev_attr_temp2_crit_hyst);
285 device_create_file(&new_client->dev, &dev_attr_alarms);
286
287 return 0;
288
289exit_free:
290 kfree(data);
291exit:
292 return err;
293}
294
295static void max1619_init_client(struct i2c_client *client)
296{
297 u8 config;
298
299 /*
300 * Start the conversions.
301 */
302 i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONVRATE,
303 5); /* 2 Hz */
304 config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG);
305 if (config & 0x40)
306 i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONFIG,
307 config & 0xBF); /* run */
308}
309
310static int max1619_detach_client(struct i2c_client *client)
311{
312 int err;
313
314 if ((err = i2c_detach_client(client))) {
315 dev_err(&client->dev, "Client deregistration failed, "
316 "client not detached.\n");
317 return err;
318 }
319
320 kfree(i2c_get_clientdata(client));
321 return 0;
322}
323
324static struct max1619_data *max1619_update_device(struct device *dev)
325{
326 struct i2c_client *client = to_i2c_client(dev);
327 struct max1619_data *data = i2c_get_clientdata(client);
328
329 down(&data->update_lock);
330
331 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
332 dev_dbg(&client->dev, "Updating max1619 data.\n");
333 data->temp_input1 = i2c_smbus_read_byte_data(client,
334 MAX1619_REG_R_LOCAL_TEMP);
335 data->temp_input2 = i2c_smbus_read_byte_data(client,
336 MAX1619_REG_R_REMOTE_TEMP);
337 data->temp_high2 = i2c_smbus_read_byte_data(client,
338 MAX1619_REG_R_REMOTE_HIGH);
339 data->temp_low2 = i2c_smbus_read_byte_data(client,
340 MAX1619_REG_R_REMOTE_LOW);
341 data->temp_crit2 = i2c_smbus_read_byte_data(client,
342 MAX1619_REG_R_REMOTE_CRIT);
343 data->temp_hyst2 = i2c_smbus_read_byte_data(client,
344 MAX1619_REG_R_TCRIT_HYST);
345 data->alarms = i2c_smbus_read_byte_data(client,
346 MAX1619_REG_R_STATUS);
347
348 data->last_updated = jiffies;
349 data->valid = 1;
350 }
351
352 up(&data->update_lock);
353
354 return data;
355}
356
357static int __init sensors_max1619_init(void)
358{
359 return i2c_add_driver(&max1619_driver);
360}
361
362static void __exit sensors_max1619_exit(void)
363{
364 i2c_del_driver(&max1619_driver);
365}
366
367MODULE_AUTHOR("Alexey Fisher <fishor@mail.ru> and"
368 "Jean Delvare <khali@linux-fr.org>");
369MODULE_DESCRIPTION("MAX1619 sensor driver");
370MODULE_LICENSE("GPL");
371
372module_init(sensors_max1619_init);
373module_exit(sensors_max1619_exit);
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
new file mode 100644
index 000000000000..9e1aeb69abf9
--- /dev/null
+++ b/drivers/i2c/chips/max6875.c
@@ -0,0 +1,261 @@
1/*
2 max6875.c - driver for MAX6874/MAX6875
3
4 Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5
6 Based on i2c/chips/eeprom.c
7
8 The MAX6875 has a bank of registers and two banks of EEPROM.
9 Address ranges are defined as follows:
10 * 0x0000 - 0x0046 = configuration registers
11 * 0x8000 - 0x8046 = configuration EEPROM
12 * 0x8100 - 0x82FF = user EEPROM
13
14 This driver makes the user EEPROM available for read.
15
16 The registers & config EEPROM should be accessed via i2c-dev.
17
18 The MAX6875 ignores the lowest address bit, so each chip responds to
19 two addresses - 0x50/0x51 and 0x52/0x53.
20
21 Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
22 address, so this driver is destructive if loaded for the wrong EEPROM chip.
23
24 This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; version 2 of the License.
27*/
28
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33#include <linux/i2c.h>
34#include <asm/semaphore.h>
35
36/* Do not scan - the MAX6875 access method will write to some EEPROM chips */
37static unsigned short normal_i2c[] = {I2C_CLIENT_END};
38
39/* Insmod parameters */
40I2C_CLIENT_INSMOD_1(max6875);
41
42/* The MAX6875 can only read/write 16 bytes at a time */
43#define SLICE_SIZE 16
44#define SLICE_BITS 4
45
46/* USER EEPROM is at addresses 0x8100 - 0x82FF */
47#define USER_EEPROM_BASE 0x8100
48#define USER_EEPROM_SIZE 0x0200
49#define USER_EEPROM_SLICES 32
50
51/* MAX6875 commands */
52#define MAX6875_CMD_BLK_READ 0x84
53
54/* Each client has this additional data */
55struct max6875_data {
56 struct i2c_client client;
57 struct semaphore update_lock;
58
59 u32 valid;
60 u8 data[USER_EEPROM_SIZE];
61 unsigned long last_updated[USER_EEPROM_SLICES];
62};
63
64static int max6875_attach_adapter(struct i2c_adapter *adapter);
65static int max6875_detect(struct i2c_adapter *adapter, int address, int kind);
66static int max6875_detach_client(struct i2c_client *client);
67
68/* This is the driver that will be inserted */
69static struct i2c_driver max6875_driver = {
70 .owner = THIS_MODULE,
71 .name = "max6875",
72 .flags = I2C_DF_NOTIFY,
73 .attach_adapter = max6875_attach_adapter,
74 .detach_client = max6875_detach_client,
75};
76
77static void max6875_update_slice(struct i2c_client *client, int slice)
78{
79 struct max6875_data *data = i2c_get_clientdata(client);
80 int i, j, addr;
81 u8 *buf;
82
83 if (slice >= USER_EEPROM_SLICES)
84 return;
85
86 down(&data->update_lock);
87
88 buf = &data->data[slice << SLICE_BITS];
89
90 if (!(data->valid & (1 << slice)) ||
91 time_after(jiffies, data->last_updated[slice])) {
92
93 dev_dbg(&client->dev, "Starting update of slice %u\n", slice);
94
95 data->valid &= ~(1 << slice);
96
97 addr = USER_EEPROM_BASE + (slice << SLICE_BITS);
98
99 /* select the eeprom address */
100 if (i2c_smbus_write_byte_data(client, addr >> 8, addr & 0xFF)) {
101 dev_err(&client->dev, "address set failed\n");
102 goto exit_up;
103 }
104
105 if (i2c_check_functionality(client->adapter,
106 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
107 if (i2c_smbus_read_i2c_block_data(client,
108 MAX6875_CMD_BLK_READ,
109 buf) != SLICE_SIZE) {
110 goto exit_up;
111 }
112 } else {
113 for (i = 0; i < SLICE_SIZE; i++) {
114 j = i2c_smbus_read_byte(client);
115 if (j < 0) {
116 goto exit_up;
117 }
118 buf[i] = j;
119 }
120 }
121 data->last_updated[slice] = jiffies;
122 data->valid |= (1 << slice);
123 }
124exit_up:
125 up(&data->update_lock);
126}
127
128static ssize_t max6875_read(struct kobject *kobj, char *buf, loff_t off,
129 size_t count)
130{
131 struct i2c_client *client = kobj_to_i2c_client(kobj);
132 struct max6875_data *data = i2c_get_clientdata(client);
133 int slice, max_slice;
134
135 if (off > USER_EEPROM_SIZE)
136 return 0;
137
138 if (off + count > USER_EEPROM_SIZE)
139 count = USER_EEPROM_SIZE - off;
140
141 /* refresh slices which contain requested bytes */
142 max_slice = (off + count - 1) >> SLICE_BITS;
143 for (slice = (off >> SLICE_BITS); slice <= max_slice; slice++)
144 max6875_update_slice(client, slice);
145
146 memcpy(buf, &data->data[off], count);
147
148 return count;
149}
150
151static struct bin_attribute user_eeprom_attr = {
152 .attr = {
153 .name = "eeprom",
154 .mode = S_IRUGO,
155 .owner = THIS_MODULE,
156 },
157 .size = USER_EEPROM_SIZE,
158 .read = max6875_read,
159};
160
161static int max6875_attach_adapter(struct i2c_adapter *adapter)
162{
163 return i2c_probe(adapter, &addr_data, max6875_detect);
164}
165
166/* This function is called by i2c_probe */
167static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
168{
169 struct i2c_client *real_client;
170 struct i2c_client *fake_client;
171 struct max6875_data *data;
172 int err = 0;
173
174 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
175 | I2C_FUNC_SMBUS_READ_BYTE))
176 return 0;
177
178 /* Only check even addresses */
179 if (address & 1)
180 return 0;
181
182 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL)))
183 return -ENOMEM;
184 memset(data, 0, sizeof(struct max6875_data));
185
186 /* A fake client is created on the odd address */
187 if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
188 err = -ENOMEM;
189 goto exit_kfree1;
190 }
191 memset(fake_client, 0, sizeof(struct i2c_client));
192
193 /* Init real i2c_client */
194 real_client = &data->client;
195 i2c_set_clientdata(real_client, data);
196 real_client->addr = address;
197 real_client->adapter = adapter;
198 real_client->driver = &max6875_driver;
199 real_client->flags = 0;
200 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
201 init_MUTEX(&data->update_lock);
202
203 /* Init fake client data */
204 /* set the client data to the i2c_client so that it will get freed */
205 i2c_set_clientdata(fake_client, fake_client);
206 fake_client->addr = address | 1;
207 fake_client->adapter = adapter;
208 fake_client->driver = &max6875_driver;
209 fake_client->flags = 0;
210 strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
211
212 /* Prevent 24RF08 corruption (in case of user error) */
213 i2c_smbus_write_quick(real_client, 0);
214
215 if ((err = i2c_attach_client(real_client)) != 0)
216 goto exit_kfree2;
217
218 if ((err = i2c_attach_client(fake_client)) != 0)
219 goto exit_detach;
220
221 sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
222
223 return 0;
224
225exit_detach:
226 i2c_detach_client(real_client);
227exit_kfree2:
228 kfree(fake_client);
229exit_kfree1:
230 kfree(data);
231 return err;
232}
233
234static int max6875_detach_client(struct i2c_client *client)
235{
236 int err;
237
238 err = i2c_detach_client(client);
239 if (err)
240 return err;
241 kfree(i2c_get_clientdata(client));
242 return 0;
243}
244
245static int __init max6875_init(void)
246{
247 return i2c_add_driver(&max6875_driver);
248}
249
250static void __exit max6875_exit(void)
251{
252 i2c_del_driver(&max6875_driver);
253}
254
255
256MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
257MODULE_DESCRIPTION("MAX6875 driver");
258MODULE_LICENSE("GPL");
259
260module_init(max6875_init);
261module_exit(max6875_exit);
diff --git a/drivers/i2c/chips/pc87360.c b/drivers/i2c/chips/pc87360.c
deleted file mode 100644
index 6d94c36c9218..000000000000
--- a/drivers/i2c/chips/pc87360.c
+++ /dev/null
@@ -1,1349 +0,0 @@
1/*
2 * pc87360.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
4 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
5 *
6 * Copied from smsc47m1.c:
7 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
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 * Supports the following chips:
24 *
25 * Chip #vin #fan #pwm #temp devid
26 * PC87360 - 2 2 - 0xE1
27 * PC87363 - 2 2 - 0xE8
28 * PC87364 - 3 3 - 0xE4
29 * PC87365 11 3 3 2 0xE5
30 * PC87366 11 3 3 3-4 0xE9
31 *
32 * This driver assumes that no more than one chip is present, and one of
33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F).
34 */
35
36#include <linux/config.h>
37#include <linux/module.h>
38#include <linux/init.h>
39#include <linux/slab.h>
40#include <linux/jiffies.h>
41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h>
43#include <linux/i2c-vid.h>
44#include <asm/io.h>
45
46static unsigned short normal_i2c[] = { I2C_CLIENT_END };
47static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
48static struct i2c_force_data forces[] = {{ NULL }};
49static u8 devid;
50static unsigned int extra_isa[3];
51static u8 confreg[4];
52
53enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 };
54static struct i2c_address_data addr_data = {
55 .normal_i2c = normal_i2c,
56 .normal_isa = normal_isa,
57 .forces = forces,
58};
59
60static int init = 1;
61module_param(init, int, 0);
62MODULE_PARM_DESC(init,
63 "Chip initialization level:\n"
64 " 0: None\n"
65 "*1: Forcibly enable internal voltage and temperature channels, except in9\n"
66 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
67 " 3: Forcibly enable all voltage and temperature channels, including in9");
68
69/*
70 * Super-I/O registers and operations
71 */
72
73#define DEV 0x07 /* Register: Logical device select */
74#define DEVID 0x20 /* Register: Device ID */
75#define ACT 0x30 /* Register: Device activation */
76#define BASE 0x60 /* Register: Base address */
77
78#define FSCM 0x09 /* Logical device: fans */
79#define VLM 0x0d /* Logical device: voltages */
80#define TMS 0x0e /* Logical device: temperatures */
81static const u8 logdev[3] = { FSCM, VLM, TMS };
82
83#define LD_FAN 0
84#define LD_IN 1
85#define LD_TEMP 2
86
87static inline void superio_outb(int sioaddr, int reg, int val)
88{
89 outb(reg, sioaddr);
90 outb(val, sioaddr+1);
91}
92
93static inline int superio_inb(int sioaddr, int reg)
94{
95 outb(reg, sioaddr);
96 return inb(sioaddr+1);
97}
98
99static inline void superio_exit(int sioaddr)
100{
101 outb(0x02, sioaddr);
102 outb(0x02, sioaddr+1);
103}
104
105/*
106 * Logical devices
107 */
108
109#define PC87360_EXTENT 0x10
110#define PC87365_REG_BANK 0x09
111#define NO_BANK 0xff
112
113/*
114 * Fan registers and conversions
115 */
116
117/* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
118#define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
119#define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
120#define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
121#define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
122#define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
123
124#define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \
125 480000 / ((val)*(div)))
126#define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \
127 480000 / ((val)*(div)))
128#define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03))
129#define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
130
131#define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1)
132#define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1)
133#define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1)
134
135#define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val))
136static inline u8 PWM_TO_REG(int val, int inv)
137{
138 if (inv)
139 val = 255 - val;
140 if (val < 0)
141 return 0;
142 if (val > 255)
143 return 255;
144 return val;
145}
146
147/*
148 * Voltage registers and conversions
149 */
150
151#define PC87365_REG_IN_CONVRATE 0x07
152#define PC87365_REG_IN_CONFIG 0x08
153#define PC87365_REG_IN 0x0B
154#define PC87365_REG_IN_MIN 0x0D
155#define PC87365_REG_IN_MAX 0x0C
156#define PC87365_REG_IN_STATUS 0x0A
157#define PC87365_REG_IN_ALARMS1 0x00
158#define PC87365_REG_IN_ALARMS2 0x01
159#define PC87365_REG_VID 0x06
160
161#define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256)
162#define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \
163 (val)*256 >= (ref)*255 ? 255: \
164 ((val) * 256 + (ref)/2) / (ref))
165
166/*
167 * Temperature registers and conversions
168 */
169
170#define PC87365_REG_TEMP_CONFIG 0x08
171#define PC87365_REG_TEMP 0x0B
172#define PC87365_REG_TEMP_MIN 0x0D
173#define PC87365_REG_TEMP_MAX 0x0C
174#define PC87365_REG_TEMP_CRIT 0x0E
175#define PC87365_REG_TEMP_STATUS 0x0A
176#define PC87365_REG_TEMP_ALARMS 0x00
177
178#define TEMP_FROM_REG(val) ((val) * 1000)
179#define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
180 (val) > 127000 ? 127 : \
181 (val) < 0 ? ((val) - 500) / 1000 : \
182 ((val) + 500) / 1000)
183
184/*
185 * Client data (each client gets its own)
186 */
187
188struct pc87360_data {
189 struct i2c_client client;
190 struct semaphore lock;
191 struct semaphore update_lock;
192 char valid; /* !=0 if following fields are valid */
193 unsigned long last_updated; /* In jiffies */
194
195 int address[3];
196
197 u8 fannr, innr, tempnr;
198
199 u8 fan[3]; /* Register value */
200 u8 fan_min[3]; /* Register value */
201 u8 fan_status[3]; /* Register value */
202 u8 pwm[3]; /* Register value */
203 u16 fan_conf; /* Configuration register values, combined */
204
205 u16 in_vref; /* 1 mV/bit */
206 u8 in[14]; /* Register value */
207 u8 in_min[14]; /* Register value */
208 u8 in_max[14]; /* Register value */
209 u8 in_crit[3]; /* Register value */
210 u8 in_status[14]; /* Register value */
211 u16 in_alarms; /* Register values, combined, masked */
212 u8 vid_conf; /* Configuration register value */
213 u8 vrm;
214 u8 vid; /* Register value */
215
216 s8 temp[3]; /* Register value */
217 s8 temp_min[3]; /* Register value */
218 s8 temp_max[3]; /* Register value */
219 s8 temp_crit[3]; /* Register value */
220 u8 temp_status[3]; /* Register value */
221 u8 temp_alarms; /* Register value, masked */
222};
223
224/*
225 * Functions declaration
226 */
227
228static int pc87360_attach_adapter(struct i2c_adapter *adapter);
229static int pc87360_detect(struct i2c_adapter *adapter, int address, int kind);
230static int pc87360_detach_client(struct i2c_client *client);
231
232static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
233 u8 reg);
234static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
235 u8 reg, u8 value);
236static void pc87360_init_client(struct i2c_client *client, int use_thermistors);
237static struct pc87360_data *pc87360_update_device(struct device *dev);
238
239/*
240 * Driver data (common to all clients)
241 */
242
243static struct i2c_driver pc87360_driver = {
244 .owner = THIS_MODULE,
245 .name = "pc87360",
246 .flags = I2C_DF_NOTIFY,
247 .attach_adapter = pc87360_attach_adapter,
248 .detach_client = pc87360_detach_client,
249};
250
251/*
252 * Sysfs stuff
253 */
254
255static ssize_t set_fan_min(struct device *dev, const char *buf,
256 size_t count, int nr)
257{
258 struct i2c_client *client = to_i2c_client(dev);
259 struct pc87360_data *data = i2c_get_clientdata(client);
260 long fan_min = simple_strtol(buf, NULL, 10);
261
262 down(&data->update_lock);
263 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[nr]));
264
265 /* If it wouldn't fit, change clock divisor */
266 while (fan_min > 255
267 && (data->fan_status[nr] & 0x60) != 0x60) {
268 fan_min >>= 1;
269 data->fan[nr] >>= 1;
270 data->fan_status[nr] += 0x20;
271 }
272 data->fan_min[nr] = fan_min > 255 ? 255 : fan_min;
273 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(nr),
274 data->fan_min[nr]);
275
276 /* Write new divider, preserve alarm bits */
277 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(nr),
278 data->fan_status[nr] & 0xF9);
279 up(&data->update_lock);
280
281 return count;
282}
283
284#define show_and_set_fan(offset) \
285static ssize_t show_fan##offset##_input(struct device *dev, char *buf) \
286{ \
287 struct pc87360_data *data = pc87360_update_device(dev); \
288 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \
289 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
290} \
291static ssize_t show_fan##offset##_min(struct device *dev, char *buf) \
292{ \
293 struct pc87360_data *data = pc87360_update_device(dev); \
294 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \
295 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
296} \
297static ssize_t show_fan##offset##_div(struct device *dev, char *buf) \
298{ \
299 struct pc87360_data *data = pc87360_update_device(dev); \
300 return sprintf(buf, "%u\n", \
301 FAN_DIV_FROM_REG(data->fan_status[offset-1])); \
302} \
303static ssize_t show_fan##offset##_status(struct device *dev, char *buf) \
304{ \
305 struct pc87360_data *data = pc87360_update_device(dev); \
306 return sprintf(buf, "%u\n", \
307 FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \
308} \
309static ssize_t set_fan##offset##_min(struct device *dev, const char *buf, \
310 size_t count) \
311{ \
312 return set_fan_min(dev, buf, count, offset-1); \
313} \
314static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
315 show_fan##offset##_input, NULL); \
316static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
317 show_fan##offset##_min, set_fan##offset##_min); \
318static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
319 show_fan##offset##_div, NULL); \
320static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
321 show_fan##offset##_status, NULL);
322show_and_set_fan(1)
323show_and_set_fan(2)
324show_and_set_fan(3)
325
326#define show_and_set_pwm(offset) \
327static ssize_t show_pwm##offset(struct device *dev, char *buf) \
328{ \
329 struct pc87360_data *data = pc87360_update_device(dev); \
330 return sprintf(buf, "%u\n", \
331 PWM_FROM_REG(data->pwm[offset-1], \
332 FAN_CONFIG_INVERT(data->fan_conf, \
333 offset-1))); \
334} \
335static ssize_t set_pwm##offset(struct device *dev, const char *buf, \
336 size_t count) \
337{ \
338 struct i2c_client *client = to_i2c_client(dev); \
339 struct pc87360_data *data = i2c_get_clientdata(client); \
340 long val = simple_strtol(buf, NULL, 10); \
341 \
342 down(&data->update_lock); \
343 data->pwm[offset-1] = PWM_TO_REG(val, \
344 FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \
345 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \
346 data->pwm[offset-1]); \
347 up(&data->update_lock); \
348 return count; \
349} \
350static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
351 show_pwm##offset, set_pwm##offset);
352show_and_set_pwm(1)
353show_and_set_pwm(2)
354show_and_set_pwm(3)
355
356#define show_and_set_in(offset) \
357static ssize_t show_in##offset##_input(struct device *dev, char *buf) \
358{ \
359 struct pc87360_data *data = pc87360_update_device(dev); \
360 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
361 data->in_vref)); \
362} \
363static ssize_t show_in##offset##_min(struct device *dev, char *buf) \
364{ \
365 struct pc87360_data *data = pc87360_update_device(dev); \
366 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
367 data->in_vref)); \
368} \
369static ssize_t show_in##offset##_max(struct device *dev, char *buf) \
370{ \
371 struct pc87360_data *data = pc87360_update_device(dev); \
372 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
373 data->in_vref)); \
374} \
375static ssize_t show_in##offset##_status(struct device *dev, char *buf) \
376{ \
377 struct pc87360_data *data = pc87360_update_device(dev); \
378 return sprintf(buf, "%u\n", data->in_status[offset]); \
379} \
380static ssize_t set_in##offset##_min(struct device *dev, const char *buf, \
381 size_t count) \
382{ \
383 struct i2c_client *client = to_i2c_client(dev); \
384 struct pc87360_data *data = i2c_get_clientdata(client); \
385 long val = simple_strtol(buf, NULL, 10); \
386 \
387 down(&data->update_lock); \
388 data->in_min[offset] = IN_TO_REG(val, data->in_vref); \
389 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \
390 data->in_min[offset]); \
391 up(&data->update_lock); \
392 return count; \
393} \
394static ssize_t set_in##offset##_max(struct device *dev, const char *buf, \
395 size_t count) \
396{ \
397 struct i2c_client *client = to_i2c_client(dev); \
398 struct pc87360_data *data = i2c_get_clientdata(client); \
399 long val = simple_strtol(buf, NULL, 10); \
400 \
401 down(&data->update_lock); \
402 data->in_max[offset] = IN_TO_REG(val, \
403 data->in_vref); \
404 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \
405 data->in_max[offset]); \
406 up(&data->update_lock); \
407 return count; \
408} \
409static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
410 show_in##offset##_input, NULL); \
411static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
412 show_in##offset##_min, set_in##offset##_min); \
413static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
414 show_in##offset##_max, set_in##offset##_max); \
415static DEVICE_ATTR(in##offset##_status, S_IRUGO, \
416 show_in##offset##_status, NULL);
417show_and_set_in(0)
418show_and_set_in(1)
419show_and_set_in(2)
420show_and_set_in(3)
421show_and_set_in(4)
422show_and_set_in(5)
423show_and_set_in(6)
424show_and_set_in(7)
425show_and_set_in(8)
426show_and_set_in(9)
427show_and_set_in(10)
428
429#define show_and_set_therm(offset) \
430static ssize_t show_temp##offset##_input(struct device *dev, char *buf) \
431{ \
432 struct pc87360_data *data = pc87360_update_device(dev); \
433 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \
434 data->in_vref)); \
435} \
436static ssize_t show_temp##offset##_min(struct device *dev, char *buf) \
437{ \
438 struct pc87360_data *data = pc87360_update_device(dev); \
439 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \
440 data->in_vref)); \
441} \
442static ssize_t show_temp##offset##_max(struct device *dev, char *buf) \
443{ \
444 struct pc87360_data *data = pc87360_update_device(dev); \
445 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \
446 data->in_vref)); \
447} \
448static ssize_t show_temp##offset##_crit(struct device *dev, char *buf) \
449{ \
450 struct pc87360_data *data = pc87360_update_device(dev); \
451 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \
452 data->in_vref)); \
453} \
454static ssize_t show_temp##offset##_status(struct device *dev, char *buf) \
455{ \
456 struct pc87360_data *data = pc87360_update_device(dev); \
457 return sprintf(buf, "%u\n", data->in_status[offset+7]); \
458} \
459static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
460 size_t count) \
461{ \
462 struct i2c_client *client = to_i2c_client(dev); \
463 struct pc87360_data *data = i2c_get_clientdata(client); \
464 long val = simple_strtol(buf, NULL, 10); \
465 \
466 down(&data->update_lock); \
467 data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \
468 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \
469 data->in_min[offset+7]); \
470 up(&data->update_lock); \
471 return count; \
472} \
473static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
474 size_t count) \
475{ \
476 struct i2c_client *client = to_i2c_client(dev); \
477 struct pc87360_data *data = i2c_get_clientdata(client); \
478 long val = simple_strtol(buf, NULL, 10); \
479 \
480 down(&data->update_lock); \
481 data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \
482 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \
483 data->in_max[offset+7]); \
484 up(&data->update_lock); \
485 return count; \
486} \
487static ssize_t set_temp##offset##_crit(struct device *dev, const char *buf, \
488 size_t count) \
489{ \
490 struct i2c_client *client = to_i2c_client(dev); \
491 struct pc87360_data *data = i2c_get_clientdata(client); \
492 long val = simple_strtol(buf, NULL, 10); \
493 \
494 down(&data->update_lock); \
495 data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \
496 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \
497 data->in_crit[offset-4]); \
498 up(&data->update_lock); \
499 return count; \
500} \
501static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
502 show_temp##offset##_input, NULL); \
503static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
504 show_temp##offset##_min, set_temp##offset##_min); \
505static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
506 show_temp##offset##_max, set_temp##offset##_max); \
507static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
508 show_temp##offset##_crit, set_temp##offset##_crit); \
509static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
510 show_temp##offset##_status, NULL);
511show_and_set_therm(4)
512show_and_set_therm(5)
513show_and_set_therm(6)
514
515static ssize_t show_vid(struct device *dev, char *buf)
516{
517 struct pc87360_data *data = pc87360_update_device(dev);
518 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
519}
520static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
521
522static ssize_t show_vrm(struct device *dev, char *buf)
523{
524 struct pc87360_data *data = pc87360_update_device(dev);
525 return sprintf(buf, "%u\n", data->vrm);
526}
527static ssize_t set_vrm(struct device *dev, const char *buf, size_t count)
528{
529 struct i2c_client *client = to_i2c_client(dev);
530 struct pc87360_data *data = i2c_get_clientdata(client);
531 data->vrm = simple_strtoul(buf, NULL, 10);
532 return count;
533}
534static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
535
536static ssize_t show_in_alarms(struct device *dev, char *buf)
537{
538 struct pc87360_data *data = pc87360_update_device(dev);
539 return sprintf(buf, "%u\n", data->in_alarms);
540}
541static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
542
543#define show_and_set_temp(offset) \
544static ssize_t show_temp##offset##_input(struct device *dev, char *buf) \
545{ \
546 struct pc87360_data *data = pc87360_update_device(dev); \
547 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
548} \
549static ssize_t show_temp##offset##_min(struct device *dev, char *buf) \
550{ \
551 struct pc87360_data *data = pc87360_update_device(dev); \
552 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
553} \
554static ssize_t show_temp##offset##_max(struct device *dev, char *buf) \
555{ \
556 struct pc87360_data *data = pc87360_update_device(dev); \
557 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
558}\
559static ssize_t show_temp##offset##_crit(struct device *dev, char *buf) \
560{ \
561 struct pc87360_data *data = pc87360_update_device(dev); \
562 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \
563}\
564static ssize_t show_temp##offset##_status(struct device *dev, char *buf) \
565{ \
566 struct pc87360_data *data = pc87360_update_device(dev); \
567 return sprintf(buf, "%d\n", data->temp_status[offset-1]); \
568}\
569static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
570 size_t count) \
571{ \
572 struct i2c_client *client = to_i2c_client(dev); \
573 struct pc87360_data *data = i2c_get_clientdata(client); \
574 long val = simple_strtol(buf, NULL, 10); \
575 \
576 down(&data->update_lock); \
577 data->temp_min[offset-1] = TEMP_TO_REG(val); \
578 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \
579 data->temp_min[offset-1]); \
580 up(&data->update_lock); \
581 return count; \
582} \
583static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
584 size_t count) \
585{ \
586 struct i2c_client *client = to_i2c_client(dev); \
587 struct pc87360_data *data = i2c_get_clientdata(client); \
588 long val = simple_strtol(buf, NULL, 10); \
589 \
590 down(&data->update_lock); \
591 data->temp_max[offset-1] = TEMP_TO_REG(val); \
592 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \
593 data->temp_max[offset-1]); \
594 up(&data->update_lock); \
595 return count; \
596} \
597static ssize_t set_temp##offset##_crit(struct device *dev, const char *buf, \
598 size_t count) \
599{ \
600 struct i2c_client *client = to_i2c_client(dev); \
601 struct pc87360_data *data = i2c_get_clientdata(client); \
602 long val = simple_strtol(buf, NULL, 10); \
603 \
604 down(&data->update_lock); \
605 data->temp_crit[offset-1] = TEMP_TO_REG(val); \
606 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \
607 data->temp_crit[offset-1]); \
608 up(&data->update_lock); \
609 return count; \
610} \
611static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
612 show_temp##offset##_input, NULL); \
613static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
614 show_temp##offset##_min, set_temp##offset##_min); \
615static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
616 show_temp##offset##_max, set_temp##offset##_max); \
617static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
618 show_temp##offset##_crit, set_temp##offset##_crit); \
619static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
620 show_temp##offset##_status, NULL);
621show_and_set_temp(1)
622show_and_set_temp(2)
623show_and_set_temp(3)
624
625static ssize_t show_temp_alarms(struct device *dev, char *buf)
626{
627 struct pc87360_data *data = pc87360_update_device(dev);
628 return sprintf(buf, "%u\n", data->temp_alarms);
629}
630static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
631
632/*
633 * Device detection, registration and update
634 */
635
636static int pc87360_attach_adapter(struct i2c_adapter *adapter)
637{
638 return i2c_detect(adapter, &addr_data, pc87360_detect);
639}
640
641static int pc87360_find(int sioaddr, u8 *devid, int *address)
642{
643 u16 val;
644 int i;
645 int nrdev; /* logical device count */
646
647 /* No superio_enter */
648
649 /* Identify device */
650 val = superio_inb(sioaddr, DEVID);
651 switch (val) {
652 case 0xE1: /* PC87360 */
653 case 0xE8: /* PC87363 */
654 case 0xE4: /* PC87364 */
655 nrdev = 1;
656 break;
657 case 0xE5: /* PC87365 */
658 case 0xE9: /* PC87366 */
659 nrdev = 3;
660 break;
661 default:
662 superio_exit(sioaddr);
663 return -ENODEV;
664 }
665 /* Remember the device id */
666 *devid = val;
667
668 for (i = 0; i < nrdev; i++) {
669 /* select logical device */
670 superio_outb(sioaddr, DEV, logdev[i]);
671
672 val = superio_inb(sioaddr, ACT);
673 if (!(val & 0x01)) {
674 printk(KERN_INFO "pc87360: Device 0x%02x not "
675 "activated\n", logdev[i]);
676 continue;
677 }
678
679 val = (superio_inb(sioaddr, BASE) << 8)
680 | superio_inb(sioaddr, BASE + 1);
681 if (!val) {
682 printk(KERN_INFO "pc87360: Base address not set for "
683 "device 0x%02x\n", logdev[i]);
684 continue;
685 }
686
687 address[i] = val;
688
689 if (i==0) { /* Fans */
690 confreg[0] = superio_inb(sioaddr, 0xF0);
691 confreg[1] = superio_inb(sioaddr, 0xF1);
692
693#ifdef DEBUG
694 printk(KERN_DEBUG "pc87360: Fan 1: mon=%d "
695 "ctrl=%d inv=%d\n", (confreg[0]>>2)&1,
696 (confreg[0]>>3)&1, (confreg[0]>>4)&1);
697 printk(KERN_DEBUG "pc87360: Fan 2: mon=%d "
698 "ctrl=%d inv=%d\n", (confreg[0]>>5)&1,
699 (confreg[0]>>6)&1, (confreg[0]>>7)&1);
700 printk(KERN_DEBUG "pc87360: Fan 3: mon=%d "
701 "ctrl=%d inv=%d\n", confreg[1]&1,
702 (confreg[1]>>1)&1, (confreg[1]>>2)&1);
703#endif
704 } else if (i==1) { /* Voltages */
705 /* Are we using thermistors? */
706 if (*devid == 0xE9) { /* PC87366 */
707 /* These registers are not logical-device
708 specific, just that we won't need them if
709 we don't use the VLM device */
710 confreg[2] = superio_inb(sioaddr, 0x2B);
711 confreg[3] = superio_inb(sioaddr, 0x25);
712
713 if (confreg[2] & 0x40) {
714 printk(KERN_INFO "pc87360: Using "
715 "thermistors for temperature "
716 "monitoring\n");
717 }
718 if (confreg[3] & 0xE0) {
719 printk(KERN_INFO "pc87360: VID "
720 "inputs routed (mode %u)\n",
721 confreg[3] >> 5);
722 }
723 }
724 }
725 }
726
727 superio_exit(sioaddr);
728 return 0;
729}
730
731/* We don't really care about the address.
732 Read from extra_isa instead. */
733int pc87360_detect(struct i2c_adapter *adapter, int address, int kind)
734{
735 int i;
736 struct i2c_client *new_client;
737 struct pc87360_data *data;
738 int err = 0;
739 const char *name = "pc87360";
740 int use_thermistors = 0;
741
742 if (!i2c_is_isa_adapter(adapter))
743 return -ENODEV;
744
745 if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
746 return -ENOMEM;
747 memset(data, 0x00, sizeof(struct pc87360_data));
748
749 new_client = &data->client;
750 i2c_set_clientdata(new_client, data);
751 new_client->addr = address;
752 init_MUTEX(&data->lock);
753 new_client->adapter = adapter;
754 new_client->driver = &pc87360_driver;
755 new_client->flags = 0;
756
757 data->fannr = 2;
758 data->innr = 0;
759 data->tempnr = 0;
760
761 switch (devid) {
762 case 0xe8:
763 name = "pc87363";
764 break;
765 case 0xe4:
766 name = "pc87364";
767 data->fannr = 3;
768 break;
769 case 0xe5:
770 name = "pc87365";
771 data->fannr = extra_isa[0] ? 3 : 0;
772 data->innr = extra_isa[1] ? 11 : 0;
773 data->tempnr = extra_isa[2] ? 2 : 0;
774 break;
775 case 0xe9:
776 name = "pc87366";
777 data->fannr = extra_isa[0] ? 3 : 0;
778 data->innr = extra_isa[1] ? 14 : 0;
779 data->tempnr = extra_isa[2] ? 3 : 0;
780 break;
781 }
782
783 strcpy(new_client->name, name);
784 data->valid = 0;
785 init_MUTEX(&data->update_lock);
786
787 for (i = 0; i < 3; i++) {
788 if (((data->address[i] = extra_isa[i]))
789 && !request_region(extra_isa[i], PC87360_EXTENT,
790 pc87360_driver.name)) {
791 dev_err(&new_client->dev, "Region 0x%x-0x%x already "
792 "in use!\n", extra_isa[i],
793 extra_isa[i]+PC87360_EXTENT-1);
794 for (i--; i >= 0; i--)
795 release_region(extra_isa[i], PC87360_EXTENT);
796 err = -EBUSY;
797 goto ERROR1;
798 }
799 }
800
801 /* Retrieve the fans configuration from Super-I/O space */
802 if (data->fannr)
803 data->fan_conf = confreg[0] | (confreg[1] << 8);
804
805 if ((err = i2c_attach_client(new_client)))
806 goto ERROR2;
807
808 /* Use the correct reference voltage
809 Unless both the VLM and the TMS logical devices agree to
810 use an external Vref, the internal one is used. */
811 if (data->innr) {
812 i = pc87360_read_value(data, LD_IN, NO_BANK,
813 PC87365_REG_IN_CONFIG);
814 if (data->tempnr) {
815 i &= pc87360_read_value(data, LD_TEMP, NO_BANK,
816 PC87365_REG_TEMP_CONFIG);
817 }
818 data->in_vref = (i&0x02) ? 3025 : 2966;
819 dev_dbg(&new_client->dev, "Using %s reference voltage\n",
820 (i&0x02) ? "external" : "internal");
821
822 data->vid_conf = confreg[3];
823 data->vrm = 90;
824 }
825
826 /* Fan clock dividers may be needed before any data is read */
827 for (i = 0; i < data->fannr; i++) {
828 if (FAN_CONFIG_MONITOR(data->fan_conf, i))
829 data->fan_status[i] = pc87360_read_value(data,
830 LD_FAN, NO_BANK,
831 PC87360_REG_FAN_STATUS(i));
832 }
833
834 if (init > 0) {
835 if (devid == 0xe9 && data->address[1]) /* PC87366 */
836 use_thermistors = confreg[2] & 0x40;
837
838 pc87360_init_client(new_client, use_thermistors);
839 }
840
841 /* Register sysfs hooks */
842 if (data->innr) {
843 device_create_file(&new_client->dev, &dev_attr_in0_input);
844 device_create_file(&new_client->dev, &dev_attr_in1_input);
845 device_create_file(&new_client->dev, &dev_attr_in2_input);
846 device_create_file(&new_client->dev, &dev_attr_in3_input);
847 device_create_file(&new_client->dev, &dev_attr_in4_input);
848 device_create_file(&new_client->dev, &dev_attr_in5_input);
849 device_create_file(&new_client->dev, &dev_attr_in6_input);
850 device_create_file(&new_client->dev, &dev_attr_in7_input);
851 device_create_file(&new_client->dev, &dev_attr_in8_input);
852 device_create_file(&new_client->dev, &dev_attr_in9_input);
853 device_create_file(&new_client->dev, &dev_attr_in10_input);
854 device_create_file(&new_client->dev, &dev_attr_in0_min);
855 device_create_file(&new_client->dev, &dev_attr_in1_min);
856 device_create_file(&new_client->dev, &dev_attr_in2_min);
857 device_create_file(&new_client->dev, &dev_attr_in3_min);
858 device_create_file(&new_client->dev, &dev_attr_in4_min);
859 device_create_file(&new_client->dev, &dev_attr_in5_min);
860 device_create_file(&new_client->dev, &dev_attr_in6_min);
861 device_create_file(&new_client->dev, &dev_attr_in7_min);
862 device_create_file(&new_client->dev, &dev_attr_in8_min);
863 device_create_file(&new_client->dev, &dev_attr_in9_min);
864 device_create_file(&new_client->dev, &dev_attr_in10_min);
865 device_create_file(&new_client->dev, &dev_attr_in0_max);
866 device_create_file(&new_client->dev, &dev_attr_in1_max);
867 device_create_file(&new_client->dev, &dev_attr_in2_max);
868 device_create_file(&new_client->dev, &dev_attr_in3_max);
869 device_create_file(&new_client->dev, &dev_attr_in4_max);
870 device_create_file(&new_client->dev, &dev_attr_in5_max);
871 device_create_file(&new_client->dev, &dev_attr_in6_max);
872 device_create_file(&new_client->dev, &dev_attr_in7_max);
873 device_create_file(&new_client->dev, &dev_attr_in8_max);
874 device_create_file(&new_client->dev, &dev_attr_in9_max);
875 device_create_file(&new_client->dev, &dev_attr_in10_max);
876 device_create_file(&new_client->dev, &dev_attr_in0_status);
877 device_create_file(&new_client->dev, &dev_attr_in1_status);
878 device_create_file(&new_client->dev, &dev_attr_in2_status);
879 device_create_file(&new_client->dev, &dev_attr_in3_status);
880 device_create_file(&new_client->dev, &dev_attr_in4_status);
881 device_create_file(&new_client->dev, &dev_attr_in5_status);
882 device_create_file(&new_client->dev, &dev_attr_in6_status);
883 device_create_file(&new_client->dev, &dev_attr_in7_status);
884 device_create_file(&new_client->dev, &dev_attr_in8_status);
885 device_create_file(&new_client->dev, &dev_attr_in9_status);
886 device_create_file(&new_client->dev, &dev_attr_in10_status);
887
888 device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
889 device_create_file(&new_client->dev, &dev_attr_vrm);
890 device_create_file(&new_client->dev, &dev_attr_alarms_in);
891 }
892
893 if (data->tempnr) {
894 device_create_file(&new_client->dev, &dev_attr_temp1_input);
895 device_create_file(&new_client->dev, &dev_attr_temp2_input);
896 device_create_file(&new_client->dev, &dev_attr_temp1_min);
897 device_create_file(&new_client->dev, &dev_attr_temp2_min);
898 device_create_file(&new_client->dev, &dev_attr_temp1_max);
899 device_create_file(&new_client->dev, &dev_attr_temp2_max);
900 device_create_file(&new_client->dev, &dev_attr_temp1_crit);
901 device_create_file(&new_client->dev, &dev_attr_temp2_crit);
902 device_create_file(&new_client->dev, &dev_attr_temp1_status);
903 device_create_file(&new_client->dev, &dev_attr_temp2_status);
904
905 device_create_file(&new_client->dev, &dev_attr_alarms_temp);
906 }
907 if (data->tempnr == 3) {
908 device_create_file(&new_client->dev, &dev_attr_temp3_input);
909 device_create_file(&new_client->dev, &dev_attr_temp3_min);
910 device_create_file(&new_client->dev, &dev_attr_temp3_max);
911 device_create_file(&new_client->dev, &dev_attr_temp3_crit);
912 device_create_file(&new_client->dev, &dev_attr_temp3_status);
913 }
914 if (data->innr == 14) {
915 device_create_file(&new_client->dev, &dev_attr_temp4_input);
916 device_create_file(&new_client->dev, &dev_attr_temp5_input);
917 device_create_file(&new_client->dev, &dev_attr_temp6_input);
918 device_create_file(&new_client->dev, &dev_attr_temp4_min);
919 device_create_file(&new_client->dev, &dev_attr_temp5_min);
920 device_create_file(&new_client->dev, &dev_attr_temp6_min);
921 device_create_file(&new_client->dev, &dev_attr_temp4_max);
922 device_create_file(&new_client->dev, &dev_attr_temp5_max);
923 device_create_file(&new_client->dev, &dev_attr_temp6_max);
924 device_create_file(&new_client->dev, &dev_attr_temp4_crit);
925 device_create_file(&new_client->dev, &dev_attr_temp5_crit);
926 device_create_file(&new_client->dev, &dev_attr_temp6_crit);
927 device_create_file(&new_client->dev, &dev_attr_temp4_status);
928 device_create_file(&new_client->dev, &dev_attr_temp5_status);
929 device_create_file(&new_client->dev, &dev_attr_temp6_status);
930 }
931
932 if (data->fannr) {
933 if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) {
934 device_create_file(&new_client->dev,
935 &dev_attr_fan1_input);
936 device_create_file(&new_client->dev,
937 &dev_attr_fan1_min);
938 device_create_file(&new_client->dev,
939 &dev_attr_fan1_div);
940 device_create_file(&new_client->dev,
941 &dev_attr_fan1_status);
942 }
943
944 if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) {
945 device_create_file(&new_client->dev,
946 &dev_attr_fan2_input);
947 device_create_file(&new_client->dev,
948 &dev_attr_fan2_min);
949 device_create_file(&new_client->dev,
950 &dev_attr_fan2_div);
951 device_create_file(&new_client->dev,
952 &dev_attr_fan2_status);
953 }
954
955 if (FAN_CONFIG_CONTROL(data->fan_conf, 0))
956 device_create_file(&new_client->dev, &dev_attr_pwm1);
957 if (FAN_CONFIG_CONTROL(data->fan_conf, 1))
958 device_create_file(&new_client->dev, &dev_attr_pwm2);
959 }
960 if (data->fannr == 3) {
961 if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) {
962 device_create_file(&new_client->dev,
963 &dev_attr_fan3_input);
964 device_create_file(&new_client->dev,
965 &dev_attr_fan3_min);
966 device_create_file(&new_client->dev,
967 &dev_attr_fan3_div);
968 device_create_file(&new_client->dev,
969 &dev_attr_fan3_status);
970 }
971
972 if (FAN_CONFIG_CONTROL(data->fan_conf, 2))
973 device_create_file(&new_client->dev, &dev_attr_pwm3);
974 }
975
976 return 0;
977
978ERROR2:
979 for (i = 0; i < 3; i++) {
980 if (data->address[i]) {
981 release_region(data->address[i], PC87360_EXTENT);
982 }
983 }
984ERROR1:
985 kfree(data);
986 return err;
987}
988
989static int pc87360_detach_client(struct i2c_client *client)
990{
991 struct pc87360_data *data = i2c_get_clientdata(client);
992 int i;
993
994 if ((i = i2c_detach_client(client))) {
995 dev_err(&client->dev, "Client deregistration failed, "
996 "client not detached.\n");
997 return i;
998 }
999
1000 for (i = 0; i < 3; i++) {
1001 if (data->address[i]) {
1002 release_region(data->address[i], PC87360_EXTENT);
1003 }
1004 }
1005 kfree(data);
1006
1007 return 0;
1008}
1009
1010/* ldi is the logical device index
1011 bank is for voltages and temperatures only */
1012static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
1013 u8 reg)
1014{
1015 int res;
1016
1017 down(&(data->lock));
1018 if (bank != NO_BANK)
1019 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1020 res = inb_p(data->address[ldi] + reg);
1021 up(&(data->lock));
1022
1023 return res;
1024}
1025
1026static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
1027 u8 reg, u8 value)
1028{
1029 down(&(data->lock));
1030 if (bank != NO_BANK)
1031 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1032 outb_p(value, data->address[ldi] + reg);
1033 up(&(data->lock));
1034}
1035
1036static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
1037{
1038 struct pc87360_data *data = i2c_get_clientdata(client);
1039 int i, nr;
1040 const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1041 const u8 init_temp[3] = { 2, 2, 1 };
1042 u8 reg;
1043
1044 if (init >= 2 && data->innr) {
1045 reg = pc87360_read_value(data, LD_IN, NO_BANK,
1046 PC87365_REG_IN_CONVRATE);
1047 dev_info(&client->dev, "VLM conversion set to"
1048 "1s period, 160us delay\n");
1049 pc87360_write_value(data, LD_IN, NO_BANK,
1050 PC87365_REG_IN_CONVRATE,
1051 (reg & 0xC0) | 0x11);
1052 }
1053
1054 nr = data->innr < 11 ? data->innr : 11;
1055 for (i=0; i<nr; i++) {
1056 if (init >= init_in[i]) {
1057 /* Forcibly enable voltage channel */
1058 reg = pc87360_read_value(data, LD_IN, i,
1059 PC87365_REG_IN_STATUS);
1060 if (!(reg & 0x01)) {
1061 dev_dbg(&client->dev, "Forcibly "
1062 "enabling in%d\n", i);
1063 pc87360_write_value(data, LD_IN, i,
1064 PC87365_REG_IN_STATUS,
1065 (reg & 0x68) | 0x87);
1066 }
1067 }
1068 }
1069
1070 /* We can't blindly trust the Super-I/O space configuration bit,
1071 most BIOS won't set it properly */
1072 for (i=11; i<data->innr; i++) {
1073 reg = pc87360_read_value(data, LD_IN, i,
1074 PC87365_REG_TEMP_STATUS);
1075 use_thermistors = use_thermistors || (reg & 0x01);
1076 }
1077
1078 i = use_thermistors ? 2 : 0;
1079 for (; i<data->tempnr; i++) {
1080 if (init >= init_temp[i]) {
1081 /* Forcibly enable temperature channel */
1082 reg = pc87360_read_value(data, LD_TEMP, i,
1083 PC87365_REG_TEMP_STATUS);
1084 if (!(reg & 0x01)) {
1085 dev_dbg(&client->dev, "Forcibly "
1086 "enabling temp%d\n", i+1);
1087 pc87360_write_value(data, LD_TEMP, i,
1088 PC87365_REG_TEMP_STATUS,
1089 0xCF);
1090 }
1091 }
1092 }
1093
1094 if (use_thermistors) {
1095 for (i=11; i<data->innr; i++) {
1096 if (init >= init_in[i]) {
1097 /* The pin may already be used by thermal
1098 diodes */
1099 reg = pc87360_read_value(data, LD_TEMP,
1100 (i-11)/2, PC87365_REG_TEMP_STATUS);
1101 if (reg & 0x01) {
1102 dev_dbg(&client->dev, "Skipping "
1103 "temp%d, pin already in use "
1104 "by temp%d\n", i-7, (i-11)/2);
1105 continue;
1106 }
1107
1108 /* Forcibly enable thermistor channel */
1109 reg = pc87360_read_value(data, LD_IN, i,
1110 PC87365_REG_IN_STATUS);
1111 if (!(reg & 0x01)) {
1112 dev_dbg(&client->dev, "Forcibly "
1113 "enabling temp%d\n", i-7);
1114 pc87360_write_value(data, LD_IN, i,
1115 PC87365_REG_TEMP_STATUS,
1116 (reg & 0x60) | 0x8F);
1117 }
1118 }
1119 }
1120 }
1121
1122 if (data->innr) {
1123 reg = pc87360_read_value(data, LD_IN, NO_BANK,
1124 PC87365_REG_IN_CONFIG);
1125 if (reg & 0x01) {
1126 dev_dbg(&client->dev, "Forcibly "
1127 "enabling monitoring (VLM)\n");
1128 pc87360_write_value(data, LD_IN, NO_BANK,
1129 PC87365_REG_IN_CONFIG,
1130 reg & 0xFE);
1131 }
1132 }
1133
1134 if (data->tempnr) {
1135 reg = pc87360_read_value(data, LD_TEMP, NO_BANK,
1136 PC87365_REG_TEMP_CONFIG);
1137 if (reg & 0x01) {
1138 dev_dbg(&client->dev, "Forcibly enabling "
1139 "monitoring (TMS)\n");
1140 pc87360_write_value(data, LD_TEMP, NO_BANK,
1141 PC87365_REG_TEMP_CONFIG,
1142 reg & 0xFE);
1143 }
1144
1145 if (init >= 2) {
1146 /* Chip config as documented by National Semi. */
1147 pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08);
1148 /* We voluntarily omit the bank here, in case the
1149 sequence itself matters. It shouldn't be a problem,
1150 since nobody else is supposed to access the
1151 device at that point. */
1152 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04);
1153 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35);
1154 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05);
1155 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xE, 0x05);
1156 }
1157 }
1158}
1159
1160static void pc87360_autodiv(struct i2c_client *client, int nr)
1161{
1162 struct pc87360_data *data = i2c_get_clientdata(client);
1163 u8 old_min = data->fan_min[nr];
1164
1165 /* Increase clock divider if needed and possible */
1166 if ((data->fan_status[nr] & 0x04) /* overflow flag */
1167 || (data->fan[nr] >= 224)) { /* next to overflow */
1168 if ((data->fan_status[nr] & 0x60) != 0x60) {
1169 data->fan_status[nr] += 0x20;
1170 data->fan_min[nr] >>= 1;
1171 data->fan[nr] >>= 1;
1172 dev_dbg(&client->dev, "Increasing "
1173 "clock divider to %d for fan %d\n",
1174 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1);
1175 }
1176 } else {
1177 /* Decrease clock divider if possible */
1178 while (!(data->fan_min[nr] & 0x80) /* min "nails" divider */
1179 && data->fan[nr] < 85 /* bad accuracy */
1180 && (data->fan_status[nr] & 0x60) != 0x00) {
1181 data->fan_status[nr] -= 0x20;
1182 data->fan_min[nr] <<= 1;
1183 data->fan[nr] <<= 1;
1184 dev_dbg(&client->dev, "Decreasing "
1185 "clock divider to %d for fan %d\n",
1186 FAN_DIV_FROM_REG(data->fan_status[nr]),
1187 nr+1);
1188 }
1189 }
1190
1191 /* Write new fan min if it changed */
1192 if (old_min != data->fan_min[nr]) {
1193 pc87360_write_value(data, LD_FAN, NO_BANK,
1194 PC87360_REG_FAN_MIN(nr),
1195 data->fan_min[nr]);
1196 }
1197}
1198
1199static struct pc87360_data *pc87360_update_device(struct device *dev)
1200{
1201 struct i2c_client *client = to_i2c_client(dev);
1202 struct pc87360_data *data = i2c_get_clientdata(client);
1203 u8 i;
1204
1205 down(&data->update_lock);
1206
1207 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
1208 dev_dbg(&client->dev, "Data update\n");
1209
1210 /* Fans */
1211 for (i = 0; i < data->fannr; i++) {
1212 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) {
1213 data->fan_status[i] =
1214 pc87360_read_value(data, LD_FAN,
1215 NO_BANK, PC87360_REG_FAN_STATUS(i));
1216 data->fan[i] = pc87360_read_value(data, LD_FAN,
1217 NO_BANK, PC87360_REG_FAN(i));
1218 data->fan_min[i] = pc87360_read_value(data,
1219 LD_FAN, NO_BANK,
1220 PC87360_REG_FAN_MIN(i));
1221 /* Change clock divider if needed */
1222 pc87360_autodiv(client, i);
1223 /* Clear bits and write new divider */
1224 pc87360_write_value(data, LD_FAN, NO_BANK,
1225 PC87360_REG_FAN_STATUS(i),
1226 data->fan_status[i]);
1227 }
1228 if (FAN_CONFIG_CONTROL(data->fan_conf, i))
1229 data->pwm[i] = pc87360_read_value(data, LD_FAN,
1230 NO_BANK, PC87360_REG_PWM(i));
1231 }
1232
1233 /* Voltages */
1234 for (i = 0; i < data->innr; i++) {
1235 data->in_status[i] = pc87360_read_value(data, LD_IN, i,
1236 PC87365_REG_IN_STATUS);
1237 /* Clear bits */
1238 pc87360_write_value(data, LD_IN, i,
1239 PC87365_REG_IN_STATUS,
1240 data->in_status[i]);
1241 if ((data->in_status[i] & 0x81) == 0x81) {
1242 data->in[i] = pc87360_read_value(data, LD_IN,
1243 i, PC87365_REG_IN);
1244 }
1245 if (data->in_status[i] & 0x01) {
1246 data->in_min[i] = pc87360_read_value(data,
1247 LD_IN, i,
1248 PC87365_REG_IN_MIN);
1249 data->in_max[i] = pc87360_read_value(data,
1250 LD_IN, i,
1251 PC87365_REG_IN_MAX);
1252 if (i >= 11)
1253 data->in_crit[i-11] =
1254 pc87360_read_value(data, LD_IN,
1255 i, PC87365_REG_TEMP_CRIT);
1256 }
1257 }
1258 if (data->innr) {
1259 data->in_alarms = pc87360_read_value(data, LD_IN,
1260 NO_BANK, PC87365_REG_IN_ALARMS1)
1261 | ((pc87360_read_value(data, LD_IN,
1262 NO_BANK, PC87365_REG_IN_ALARMS2)
1263 & 0x07) << 8);
1264 data->vid = (data->vid_conf & 0xE0) ?
1265 pc87360_read_value(data, LD_IN,
1266 NO_BANK, PC87365_REG_VID) : 0x1F;
1267 }
1268
1269 /* Temperatures */
1270 for (i = 0; i < data->tempnr; i++) {
1271 data->temp_status[i] = pc87360_read_value(data,
1272 LD_TEMP, i,
1273 PC87365_REG_TEMP_STATUS);
1274 /* Clear bits */
1275 pc87360_write_value(data, LD_TEMP, i,
1276 PC87365_REG_TEMP_STATUS,
1277 data->temp_status[i]);
1278 if ((data->temp_status[i] & 0x81) == 0x81) {
1279 data->temp[i] = pc87360_read_value(data,
1280 LD_TEMP, i,
1281 PC87365_REG_TEMP);
1282 }
1283 if (data->temp_status[i] & 0x01) {
1284 data->temp_min[i] = pc87360_read_value(data,
1285 LD_TEMP, i,
1286 PC87365_REG_TEMP_MIN);
1287 data->temp_max[i] = pc87360_read_value(data,
1288 LD_TEMP, i,
1289 PC87365_REG_TEMP_MAX);
1290 data->temp_crit[i] = pc87360_read_value(data,
1291 LD_TEMP, i,
1292 PC87365_REG_TEMP_CRIT);
1293 }
1294 }
1295 if (data->tempnr) {
1296 data->temp_alarms = pc87360_read_value(data, LD_TEMP,
1297 NO_BANK, PC87365_REG_TEMP_ALARMS)
1298 & 0x3F;
1299 }
1300
1301 data->last_updated = jiffies;
1302 data->valid = 1;
1303 }
1304
1305 up(&data->update_lock);
1306
1307 return data;
1308}
1309
1310static int __init pc87360_init(void)
1311{
1312 int i;
1313
1314 if (pc87360_find(0x2e, &devid, extra_isa)
1315 && pc87360_find(0x4e, &devid, extra_isa)) {
1316 printk(KERN_WARNING "pc87360: PC8736x not detected, "
1317 "module not inserted.\n");
1318 return -ENODEV;
1319 }
1320
1321 /* Arbitrarily pick one of the addresses */
1322 for (i = 0; i < 3; i++) {
1323 if (extra_isa[i] != 0x0000) {
1324 normal_isa[0] = extra_isa[i];
1325 break;
1326 }
1327 }
1328
1329 if (normal_isa[0] == 0x0000) {
1330 printk(KERN_WARNING "pc87360: No active logical device, "
1331 "module not inserted.\n");
1332 return -ENODEV;
1333 }
1334
1335 return i2c_add_driver(&pc87360_driver);
1336}
1337
1338static void __exit pc87360_exit(void)
1339{
1340 i2c_del_driver(&pc87360_driver);
1341}
1342
1343
1344MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1345MODULE_DESCRIPTION("PC8736x hardware monitor");
1346MODULE_LICENSE("GPL");
1347
1348module_init(pc87360_init);
1349module_exit(pc87360_exit);
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
new file mode 100644
index 000000000000..225577fdda4d
--- /dev/null
+++ b/drivers/i2c/chips/pca9539.c
@@ -0,0 +1,188 @@
1/*
2 pca9539.c - 16-bit I/O port with interrupt and reset
3
4 Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9*/
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h>
16
17/* Addresses to scan */
18static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END};
19
20/* Insmod parameters */
21I2C_CLIENT_INSMOD_1(pca9539);
22
23enum pca9539_cmd
24{
25 PCA9539_INPUT_0 = 0,
26 PCA9539_INPUT_1 = 1,
27 PCA9539_OUTPUT_0 = 2,
28 PCA9539_OUTPUT_1 = 3,
29 PCA9539_INVERT_0 = 4,
30 PCA9539_INVERT_1 = 5,
31 PCA9539_DIRECTION_0 = 6,
32 PCA9539_DIRECTION_1 = 7,
33};
34
35static int pca9539_attach_adapter(struct i2c_adapter *adapter);
36static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind);
37static int pca9539_detach_client(struct i2c_client *client);
38
39/* This is the driver that will be inserted */
40static struct i2c_driver pca9539_driver = {
41 .owner = THIS_MODULE,
42 .name = "pca9539",
43 .flags = I2C_DF_NOTIFY,
44 .attach_adapter = pca9539_attach_adapter,
45 .detach_client = pca9539_detach_client,
46};
47
48struct pca9539_data {
49 struct i2c_client client;
50};
51
52/* following are the sysfs callback functions */
53static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr,
54 char *buf)
55{
56 struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
57 struct i2c_client *client = to_i2c_client(dev);
58 return sprintf(buf, "%d\n", i2c_smbus_read_byte_data(client,
59 psa->index));
60}
61
62static ssize_t pca9539_store(struct device *dev, struct device_attribute *attr,
63 const char *buf, size_t count)
64{
65 struct sensor_device_attribute *psa = to_sensor_dev_attr(attr);
66 struct i2c_client *client = to_i2c_client(dev);
67 unsigned long val = simple_strtoul(buf, NULL, 0);
68 if (val > 0xff)
69 return -EINVAL;
70 i2c_smbus_write_byte_data(client, psa->index, val);
71 return count;
72}
73
74/* Define the device attributes */
75
76#define PCA9539_ENTRY_RO(name, cmd_idx) \
77 static SENSOR_DEVICE_ATTR(name, S_IRUGO, pca9539_show, NULL, cmd_idx)
78
79#define PCA9539_ENTRY_RW(name, cmd_idx) \
80 static SENSOR_DEVICE_ATTR(name, S_IRUGO | S_IWUSR, pca9539_show, \
81 pca9539_store, cmd_idx)
82
83PCA9539_ENTRY_RO(input0, PCA9539_INPUT_0);
84PCA9539_ENTRY_RO(input1, PCA9539_INPUT_1);
85PCA9539_ENTRY_RW(output0, PCA9539_OUTPUT_0);
86PCA9539_ENTRY_RW(output1, PCA9539_OUTPUT_1);
87PCA9539_ENTRY_RW(invert0, PCA9539_INVERT_0);
88PCA9539_ENTRY_RW(invert1, PCA9539_INVERT_1);
89PCA9539_ENTRY_RW(direction0, PCA9539_DIRECTION_0);
90PCA9539_ENTRY_RW(direction1, PCA9539_DIRECTION_1);
91
92static struct attribute *pca9539_attributes[] = {
93 &sensor_dev_attr_input0.dev_attr.attr,
94 &sensor_dev_attr_input1.dev_attr.attr,
95 &sensor_dev_attr_output0.dev_attr.attr,
96 &sensor_dev_attr_output1.dev_attr.attr,
97 &sensor_dev_attr_invert0.dev_attr.attr,
98 &sensor_dev_attr_invert1.dev_attr.attr,
99 &sensor_dev_attr_direction0.dev_attr.attr,
100 &sensor_dev_attr_direction1.dev_attr.attr,
101 NULL
102};
103
104static struct attribute_group pca9539_defattr_group = {
105 .attrs = pca9539_attributes,
106};
107
108static int pca9539_attach_adapter(struct i2c_adapter *adapter)
109{
110 return i2c_probe(adapter, &addr_data, pca9539_detect);
111}
112
113/* This function is called by i2c_probe */
114static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
115{
116 struct i2c_client *new_client;
117 struct pca9539_data *data;
118 int err = 0;
119
120 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
121 goto exit;
122
123 /* OK. For now, we presume we have a valid client. We now create the
124 client structure, even though we cannot fill it completely yet. */
125 if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
126 err = -ENOMEM;
127 goto exit;
128 }
129 memset(data, 0, sizeof(struct pca9539_data));
130
131 new_client = &data->client;
132 i2c_set_clientdata(new_client, data);
133 new_client->addr = address;
134 new_client->adapter = adapter;
135 new_client->driver = &pca9539_driver;
136 new_client->flags = 0;
137
138 /* Detection: the pca9539 only has 8 registers (0-7).
139 A read of 7 should succeed, but a read of 8 should fail. */
140 if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
141 (i2c_smbus_read_byte_data(new_client, 8) >= 0))
142 goto exit_kfree;
143
144 strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE);
145
146 /* Tell the I2C layer a new client has arrived */
147 if ((err = i2c_attach_client(new_client)))
148 goto exit_kfree;
149
150 /* Register sysfs hooks (don't care about failure) */
151 sysfs_create_group(&new_client->dev.kobj, &pca9539_defattr_group);
152
153 return 0;
154
155exit_kfree:
156 kfree(data);
157exit:
158 return err;
159}
160
161static int pca9539_detach_client(struct i2c_client *client)
162{
163 int err;
164
165 if ((err = i2c_detach_client(client)))
166 return err;
167
168 kfree(i2c_get_clientdata(client));
169 return 0;
170}
171
172static int __init pca9539_init(void)
173{
174 return i2c_add_driver(&pca9539_driver);
175}
176
177static void __exit pca9539_exit(void)
178{
179 i2c_del_driver(&pca9539_driver);
180}
181
182MODULE_AUTHOR("Ben Gardner <bgardner@wabtec.com>");
183MODULE_DESCRIPTION("PCA9539 driver");
184MODULE_LICENSE("GPL");
185
186module_init(pca9539_init);
187module_exit(pca9539_exit);
188
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index 48b4e22eaffe..6525743ff9fd 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -39,16 +39,14 @@
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/i2c.h> 41#include <linux/i2c.h>
42#include <linux/i2c-sensor.h>
43 42
44/* Addresses to scan */ 43/* Addresses to scan */
45static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 44static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 45 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
47 I2C_CLIENT_END }; 46 I2C_CLIENT_END };
48static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
49 47
50/* Insmod parameters */ 48/* Insmod parameters */
51SENSORS_INSMOD_2(pcf8574, pcf8574a); 49I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
52 50
53/* Initial values */ 51/* Initial values */
54#define PCF8574_INIT 255 /* All outputs on (input mode) */ 52#define PCF8574_INIT 255 /* All outputs on (input mode) */
@@ -57,7 +55,7 @@ SENSORS_INSMOD_2(pcf8574, pcf8574a);
57struct pcf8574_data { 55struct pcf8574_data {
58 struct i2c_client client; 56 struct i2c_client client;
59 57
60 u8 read, write; /* Register values */ 58 u8 write; /* Remember last written value */
61}; 59};
62 60
63static int pcf8574_attach_adapter(struct i2c_adapter *adapter); 61static int pcf8574_attach_adapter(struct i2c_adapter *adapter);
@@ -76,23 +74,21 @@ static struct i2c_driver pcf8574_driver = {
76}; 74};
77 75
78/* following are the sysfs callback functions */ 76/* following are the sysfs callback functions */
79static ssize_t show_read(struct device *dev, char *buf) 77static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf)
80{ 78{
81 struct i2c_client *client = to_i2c_client(dev); 79 struct i2c_client *client = to_i2c_client(dev);
82 struct pcf8574_data *data = i2c_get_clientdata(client); 80 return sprintf(buf, "%u\n", i2c_smbus_read_byte(client));
83 data->read = i2c_smbus_read_byte(client);
84 return sprintf(buf, "%u\n", data->read);
85} 81}
86 82
87static DEVICE_ATTR(read, S_IRUGO, show_read, NULL); 83static DEVICE_ATTR(read, S_IRUGO, show_read, NULL);
88 84
89static ssize_t show_write(struct device *dev, char *buf) 85static ssize_t show_write(struct device *dev, struct device_attribute *attr, char *buf)
90{ 86{
91 struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev)); 87 struct pcf8574_data *data = i2c_get_clientdata(to_i2c_client(dev));
92 return sprintf(buf, "%u\n", data->write); 88 return sprintf(buf, "%u\n", data->write);
93} 89}
94 90
95static ssize_t set_write(struct device *dev, const char *buf, 91static ssize_t set_write(struct device *dev, struct device_attribute *attr, const char *buf,
96 size_t count) 92 size_t count)
97{ 93{
98 struct i2c_client *client = to_i2c_client(dev); 94 struct i2c_client *client = to_i2c_client(dev);
@@ -115,10 +111,10 @@ static DEVICE_ATTR(write, S_IWUSR | S_IRUGO, show_write, set_write);
115 111
116static int pcf8574_attach_adapter(struct i2c_adapter *adapter) 112static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
117{ 113{
118 return i2c_detect(adapter, &addr_data, pcf8574_detect); 114 return i2c_probe(adapter, &addr_data, pcf8574_detect);
119} 115}
120 116
121/* This function is called by i2c_detect */ 117/* This function is called by i2c_probe */
122int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) 118int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
123{ 119{
124 struct i2c_client *new_client; 120 struct i2c_client *new_client;
@@ -188,11 +184,8 @@ static int pcf8574_detach_client(struct i2c_client *client)
188{ 184{
189 int err; 185 int err;
190 186
191 if ((err = i2c_detach_client(client))) { 187 if ((err = i2c_detach_client(client)))
192 dev_err(&client->dev,
193 "Client deregistration failed, client not detached.\n");
194 return err; 188 return err;
195 }
196 189
197 kfree(i2c_get_clientdata(client)); 190 kfree(i2c_get_clientdata(client));
198 return 0; 191 return 0;
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index b6b927d8b372..80f1df9a4500 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -24,15 +24,13 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-sensor.h>
28 27
29/* Addresses to scan */ 28/* Addresses to scan */
30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 29static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
31 0x4d, 0x4e, 0x4f, I2C_CLIENT_END }; 30 0x4d, 0x4e, 0x4f, I2C_CLIENT_END };
32static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
33 31
34/* Insmod parameters */ 32/* Insmod parameters */
35SENSORS_INSMOD_1(pcf8591); 33I2C_CLIENT_INSMOD_1(pcf8591);
36 34
37static int input_mode; 35static int input_mode;
38module_param(input_mode, int, 0); 36module_param(input_mode, int, 0);
@@ -100,7 +98,7 @@ static struct i2c_driver pcf8591_driver = {
100 98
101/* following are the sysfs callback functions */ 99/* following are the sysfs callback functions */
102#define show_in_channel(channel) \ 100#define show_in_channel(channel) \
103static ssize_t show_in##channel##_input(struct device *dev, char *buf) \ 101static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \
104{ \ 102{ \
105 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\ 103 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
106} \ 104} \
@@ -112,13 +110,13 @@ show_in_channel(1);
112show_in_channel(2); 110show_in_channel(2);
113show_in_channel(3); 111show_in_channel(3);
114 112
115static ssize_t show_out0_ouput(struct device *dev, char *buf) 113static ssize_t show_out0_ouput(struct device *dev, struct device_attribute *attr, char *buf)
116{ 114{
117 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 115 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
118 return sprintf(buf, "%d\n", data->aout * 10); 116 return sprintf(buf, "%d\n", data->aout * 10);
119} 117}
120 118
121static ssize_t set_out0_output(struct device *dev, const char *buf, size_t count) 119static ssize_t set_out0_output(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
122{ 120{
123 unsigned int value; 121 unsigned int value;
124 struct i2c_client *client = to_i2c_client(dev); 122 struct i2c_client *client = to_i2c_client(dev);
@@ -134,13 +132,13 @@ static ssize_t set_out0_output(struct device *dev, const char *buf, size_t count
134static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO, 132static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO,
135 show_out0_ouput, set_out0_output); 133 show_out0_ouput, set_out0_output);
136 134
137static ssize_t show_out0_enable(struct device *dev, char *buf) 135static ssize_t show_out0_enable(struct device *dev, struct device_attribute *attr, char *buf)
138{ 136{
139 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev)); 137 struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
140 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); 138 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF)));
141} 139}
142 140
143static ssize_t set_out0_enable(struct device *dev, const char *buf, size_t count) 141static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
144{ 142{
145 struct i2c_client *client = to_i2c_client(dev); 143 struct i2c_client *client = to_i2c_client(dev);
146 struct pcf8591_data *data = i2c_get_clientdata(client); 144 struct pcf8591_data *data = i2c_get_clientdata(client);
@@ -164,10 +162,10 @@ static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
164 */ 162 */
165static int pcf8591_attach_adapter(struct i2c_adapter *adapter) 163static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
166{ 164{
167 return i2c_detect(adapter, &addr_data, pcf8591_detect); 165 return i2c_probe(adapter, &addr_data, pcf8591_detect);
168} 166}
169 167
170/* This function is called by i2c_detect */ 168/* This function is called by i2c_probe */
171int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 169int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
172{ 170{
173 struct i2c_client *new_client; 171 struct i2c_client *new_client;
@@ -241,11 +239,8 @@ static int pcf8591_detach_client(struct i2c_client *client)
241{ 239{
242 int err; 240 int err;
243 241
244 if ((err = i2c_detach_client(client))) { 242 if ((err = i2c_detach_client(client)))
245 dev_err(&client->dev,
246 "Client deregistration failed, client not detached.\n");
247 return err; 243 return err;
248 }
249 244
250 kfree(i2c_get_clientdata(client)); 245 kfree(i2c_get_clientdata(client));
251 return 0; 246 return 0;
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index 5a9deddb626b..0b5385c892b1 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -19,7 +19,6 @@
19#include <linux/string.h> 19#include <linux/string.h>
20#include <linux/rtc.h> /* get the user-level API */ 20#include <linux/rtc.h> /* get the user-level API */
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/init.h>
23 22
24#include "rtc8564.h" 23#include "rtc8564.h"
25 24
@@ -66,12 +65,8 @@ static unsigned short normal_addr[] = { 0x51, I2C_CLIENT_END };
66 65
67static struct i2c_client_address_data addr_data = { 66static struct i2c_client_address_data addr_data = {
68 .normal_i2c = normal_addr, 67 .normal_i2c = normal_addr,
69 .normal_i2c_range = ignore,
70 .probe = ignore, 68 .probe = ignore,
71 .probe_range = ignore,
72 .ignore = ignore, 69 .ignore = ignore,
73 .ignore_range = ignore,
74 .force = ignore,
75}; 70};
76 71
77static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem); 72static int rtc8564_read_mem(struct i2c_client *client, struct mem *mem);
diff --git a/drivers/i2c/chips/sis5595.c b/drivers/i2c/chips/sis5595.c
deleted file mode 100644
index 7ea84532df32..000000000000
--- a/drivers/i2c/chips/sis5595.c
+++ /dev/null
@@ -1,816 +0,0 @@
1/*
2 sis5595.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 Copyright (C) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>, and
7 Mark D. Studebaker <mdsxyz123@yahoo.com>
8 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
9 the help of Jean Delvare <khali@linux-fr.org>
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/
25
26/*
27 SiS southbridge has a LM78-like chip integrated on the same IC.
28 This driver is a customized copy of lm78.c
29
30 Supports following revisions:
31 Version PCI ID PCI Revision
32 1 1039/0008 AF or less
33 2 1039/0008 B0 or greater
34
35 Note: these chips contain a 0008 device which is incompatible with the
36 5595. We recognize these by the presence of the listed
37 "blacklist" PCI ID and refuse to load.
38
39 NOT SUPPORTED PCI ID BLACKLIST PCI ID
40 540 0008 0540
41 550 0008 0550
42 5513 0008 5511
43 5581 0008 5597
44 5582 0008 5597
45 5597 0008 5597
46 5598 0008 5597/5598
47 630 0008 0630
48 645 0008 0645
49 730 0008 0730
50 735 0008 0735
51*/
52
53#include <linux/module.h>
54#include <linux/slab.h>
55#include <linux/ioport.h>
56#include <linux/pci.h>
57#include <linux/i2c.h>
58#include <linux/i2c-sensor.h>
59#include <linux/init.h>
60#include <asm/io.h>
61
62
63/* If force_addr is set to anything different from 0, we forcibly enable
64 the device at the given address. */
65static u16 force_addr;
66module_param(force_addr, ushort, 0);
67MODULE_PARM_DESC(force_addr,
68 "Initialize the base address of the sensors");
69
70/* Addresses to scan.
71 Note that we can't determine the ISA address until we have initialized
72 our module */
73static unsigned short normal_i2c[] = { I2C_CLIENT_END };
74static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
75
76/* Insmod parameters */
77SENSORS_INSMOD_1(sis5595);
78
79/* Many SIS5595 constants specified below */
80
81/* Length of ISA address segment */
82#define SIS5595_EXTENT 8
83/* PCI Config Registers */
84#define SIS5595_REVISION_REG 0x08
85#define SIS5595_BASE_REG 0x68
86#define SIS5595_PIN_REG 0x7A
87#define SIS5595_ENABLE_REG 0x7B
88
89/* Where are the ISA address/data registers relative to the base address */
90#define SIS5595_ADDR_REG_OFFSET 5
91#define SIS5595_DATA_REG_OFFSET 6
92
93/* The SIS5595 registers */
94#define SIS5595_REG_IN_MAX(nr) (0x2b + (nr) * 2)
95#define SIS5595_REG_IN_MIN(nr) (0x2c + (nr) * 2)
96#define SIS5595_REG_IN(nr) (0x20 + (nr))
97
98#define SIS5595_REG_FAN_MIN(nr) (0x3b + (nr))
99#define SIS5595_REG_FAN(nr) (0x28 + (nr))
100
101/* On the first version of the chip, the temp registers are separate.
102 On the second version,
103 TEMP pin is shared with IN4, configured in PCI register 0x7A.
104 The registers are the same as well.
105 OVER and HYST are really MAX and MIN. */
106
107#define REV2MIN 0xb0
108#define SIS5595_REG_TEMP (( data->revision) >= REV2MIN) ? \
109 SIS5595_REG_IN(4) : 0x27
110#define SIS5595_REG_TEMP_OVER (( data->revision) >= REV2MIN) ? \
111 SIS5595_REG_IN_MAX(4) : 0x39
112#define SIS5595_REG_TEMP_HYST (( data->revision) >= REV2MIN) ? \
113 SIS5595_REG_IN_MIN(4) : 0x3a
114
115#define SIS5595_REG_CONFIG 0x40
116#define SIS5595_REG_ALARM1 0x41
117#define SIS5595_REG_ALARM2 0x42
118#define SIS5595_REG_FANDIV 0x47
119
120/* Conversions. Limit checking is only done on the TO_REG
121 variants. */
122
123/* IN: mV, (0V to 4.08V)
124 REG: 16mV/bit */
125static inline u8 IN_TO_REG(unsigned long val)
126{
127 unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
128 return (nval + 8) / 16;
129}
130#define IN_FROM_REG(val) ((val) * 16)
131
132static inline u8 FAN_TO_REG(long rpm, int div)
133{
134 if (rpm <= 0)
135 return 255;
136 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
137}
138
139static inline int FAN_FROM_REG(u8 val, int div)
140{
141 return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
142}
143
144/* TEMP: mC (-54.12C to +157.53C)
145 REG: 0.83C/bit + 52.12, two's complement */
146static inline int TEMP_FROM_REG(s8 val)
147{
148 return val * 830 + 52120;
149}
150static inline s8 TEMP_TO_REG(int val)
151{
152 int nval = SENSORS_LIMIT(val, -54120, 157530) ;
153 return nval<0 ? (nval-5212-415)/830 : (nval-5212+415)/830;
154}
155
156/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
157 REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
158static inline u8 DIV_TO_REG(int val)
159{
160 return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
161}
162#define DIV_FROM_REG(val) (1 << (val))
163
164/* For the SIS5595, we need to keep some data in memory. That
165 data is pointed to by sis5595_list[NR]->data. The structure itself is
166 dynamically allocated, at the time when the new sis5595 client is
167 allocated. */
168struct sis5595_data {
169 struct i2c_client client;
170 struct semaphore lock;
171
172 struct semaphore update_lock;
173 char valid; /* !=0 if following fields are valid */
174 unsigned long last_updated; /* In jiffies */
175 char maxins; /* == 3 if temp enabled, otherwise == 4 */
176 u8 revision; /* Reg. value */
177
178 u8 in[5]; /* Register value */
179 u8 in_max[5]; /* Register value */
180 u8 in_min[5]; /* Register value */
181 u8 fan[2]; /* Register value */
182 u8 fan_min[2]; /* Register value */
183 s8 temp; /* Register value */
184 s8 temp_over; /* Register value */
185 s8 temp_hyst; /* Register value */
186 u8 fan_div[2]; /* Register encoding, shifted right */
187 u16 alarms; /* Register encoding, combined */
188};
189
190static struct pci_dev *s_bridge; /* pointer to the (only) sis5595 */
191
192static int sis5595_attach_adapter(struct i2c_adapter *adapter);
193static int sis5595_detect(struct i2c_adapter *adapter, int address, int kind);
194static int sis5595_detach_client(struct i2c_client *client);
195
196static int sis5595_read_value(struct i2c_client *client, u8 register);
197static int sis5595_write_value(struct i2c_client *client, u8 register, u8 value);
198static struct sis5595_data *sis5595_update_device(struct device *dev);
199static void sis5595_init_client(struct i2c_client *client);
200
201static struct i2c_driver sis5595_driver = {
202 .owner = THIS_MODULE,
203 .name = "sis5595",
204 .id = I2C_DRIVERID_SIS5595,
205 .flags = I2C_DF_NOTIFY,
206 .attach_adapter = sis5595_attach_adapter,
207 .detach_client = sis5595_detach_client,
208};
209
210/* 4 Voltages */
211static ssize_t show_in(struct device *dev, char *buf, int nr)
212{
213 struct sis5595_data *data = sis5595_update_device(dev);
214 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
215}
216
217static ssize_t show_in_min(struct device *dev, char *buf, int nr)
218{
219 struct sis5595_data *data = sis5595_update_device(dev);
220 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
221}
222
223static ssize_t show_in_max(struct device *dev, char *buf, int nr)
224{
225 struct sis5595_data *data = sis5595_update_device(dev);
226 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
227}
228
229static ssize_t set_in_min(struct device *dev, const char *buf,
230 size_t count, int nr)
231{
232 struct i2c_client *client = to_i2c_client(dev);
233 struct sis5595_data *data = i2c_get_clientdata(client);
234 unsigned long val = simple_strtoul(buf, NULL, 10);
235
236 down(&data->update_lock);
237 data->in_min[nr] = IN_TO_REG(val);
238 sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), data->in_min[nr]);
239 up(&data->update_lock);
240 return count;
241}
242
243static ssize_t set_in_max(struct device *dev, const char *buf,
244 size_t count, int nr)
245{
246 struct i2c_client *client = to_i2c_client(dev);
247 struct sis5595_data *data = i2c_get_clientdata(client);
248 unsigned long val = simple_strtoul(buf, NULL, 10);
249
250 down(&data->update_lock);
251 data->in_max[nr] = IN_TO_REG(val);
252 sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), data->in_max[nr]);
253 up(&data->update_lock);
254 return count;
255}
256
257#define show_in_offset(offset) \
258static ssize_t \
259 show_in##offset (struct device *dev, char *buf) \
260{ \
261 return show_in(dev, buf, offset); \
262} \
263static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
264 show_in##offset, NULL); \
265static ssize_t \
266 show_in##offset##_min (struct device *dev, char *buf) \
267{ \
268 return show_in_min(dev, buf, offset); \
269} \
270static ssize_t \
271 show_in##offset##_max (struct device *dev, char *buf) \
272{ \
273 return show_in_max(dev, buf, offset); \
274} \
275static ssize_t set_in##offset##_min (struct device *dev, \
276 const char *buf, size_t count) \
277{ \
278 return set_in_min(dev, buf, count, offset); \
279} \
280static ssize_t set_in##offset##_max (struct device *dev, \
281 const char *buf, size_t count) \
282{ \
283 return set_in_max(dev, buf, count, offset); \
284} \
285static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
286 show_in##offset##_min, set_in##offset##_min); \
287static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
288 show_in##offset##_max, set_in##offset##_max);
289
290show_in_offset(0);
291show_in_offset(1);
292show_in_offset(2);
293show_in_offset(3);
294show_in_offset(4);
295
296/* Temperature */
297static ssize_t show_temp(struct device *dev, char *buf)
298{
299 struct sis5595_data *data = sis5595_update_device(dev);
300 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
301}
302
303static ssize_t show_temp_over(struct device *dev, char *buf)
304{
305 struct sis5595_data *data = sis5595_update_device(dev);
306 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
307}
308
309static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count)
310{
311 struct i2c_client *client = to_i2c_client(dev);
312 struct sis5595_data *data = i2c_get_clientdata(client);
313 long val = simple_strtol(buf, NULL, 10);
314
315 down(&data->update_lock);
316 data->temp_over = TEMP_TO_REG(val);
317 sis5595_write_value(client, SIS5595_REG_TEMP_OVER, data->temp_over);
318 up(&data->update_lock);
319 return count;
320}
321
322static ssize_t show_temp_hyst(struct device *dev, char *buf)
323{
324 struct sis5595_data *data = sis5595_update_device(dev);
325 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
326}
327
328static ssize_t set_temp_hyst(struct device *dev, const char *buf, size_t count)
329{
330 struct i2c_client *client = to_i2c_client(dev);
331 struct sis5595_data *data = i2c_get_clientdata(client);
332 long val = simple_strtol(buf, NULL, 10);
333
334 down(&data->update_lock);
335 data->temp_hyst = TEMP_TO_REG(val);
336 sis5595_write_value(client, SIS5595_REG_TEMP_HYST, data->temp_hyst);
337 up(&data->update_lock);
338 return count;
339}
340
341static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
342static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
343 show_temp_over, set_temp_over);
344static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
345 show_temp_hyst, set_temp_hyst);
346
347/* 2 Fans */
348static ssize_t show_fan(struct device *dev, char *buf, int nr)
349{
350 struct sis5595_data *data = sis5595_update_device(dev);
351 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
352 DIV_FROM_REG(data->fan_div[nr])) );
353}
354
355static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
356{
357 struct sis5595_data *data = sis5595_update_device(dev);
358 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
359 DIV_FROM_REG(data->fan_div[nr])) );
360}
361
362static ssize_t set_fan_min(struct device *dev, const char *buf,
363 size_t count, int nr)
364{
365 struct i2c_client *client = to_i2c_client(dev);
366 struct sis5595_data *data = i2c_get_clientdata(client);
367 unsigned long val = simple_strtoul(buf, NULL, 10);
368
369 down(&data->update_lock);
370 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
371 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
372 up(&data->update_lock);
373 return count;
374}
375
376static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
377{
378 struct sis5595_data *data = sis5595_update_device(dev);
379 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
380}
381
382/* Note: we save and restore the fan minimum here, because its value is
383 determined in part by the fan divisor. This follows the principle of
384 least suprise; the user doesn't expect the fan minimum to change just
385 because the divisor changed. */
386static ssize_t set_fan_div(struct device *dev, const char *buf,
387 size_t count, int nr)
388{
389 struct i2c_client *client = to_i2c_client(dev);
390 struct sis5595_data *data = i2c_get_clientdata(client);
391 unsigned long min;
392 unsigned long val = simple_strtoul(buf, NULL, 10);
393 int reg;
394
395 down(&data->update_lock);
396 min = FAN_FROM_REG(data->fan_min[nr],
397 DIV_FROM_REG(data->fan_div[nr]));
398 reg = sis5595_read_value(client, SIS5595_REG_FANDIV);
399
400 switch (val) {
401 case 1: data->fan_div[nr] = 0; break;
402 case 2: data->fan_div[nr] = 1; break;
403 case 4: data->fan_div[nr] = 2; break;
404 case 8: data->fan_div[nr] = 3; break;
405 default:
406 dev_err(&client->dev, "fan_div value %ld not "
407 "supported. Choose one of 1, 2, 4 or 8!\n", val);
408 up(&data->update_lock);
409 return -EINVAL;
410 }
411
412 switch (nr) {
413 case 0:
414 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
415 break;
416 case 1:
417 reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
418 break;
419 }
420 sis5595_write_value(client, SIS5595_REG_FANDIV, reg);
421 data->fan_min[nr] =
422 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
423 sis5595_write_value(client, SIS5595_REG_FAN_MIN(nr), data->fan_min[nr]);
424 up(&data->update_lock);
425 return count;
426}
427
428#define show_fan_offset(offset) \
429static ssize_t show_fan_##offset (struct device *dev, char *buf) \
430{ \
431 return show_fan(dev, buf, offset - 1); \
432} \
433static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
434{ \
435 return show_fan_min(dev, buf, offset - 1); \
436} \
437static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
438{ \
439 return show_fan_div(dev, buf, offset - 1); \
440} \
441static ssize_t set_fan_##offset##_min (struct device *dev, \
442 const char *buf, size_t count) \
443{ \
444 return set_fan_min(dev, buf, count, offset - 1); \
445} \
446static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
447static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
448 show_fan_##offset##_min, set_fan_##offset##_min);
449
450show_fan_offset(1);
451show_fan_offset(2);
452
453static ssize_t set_fan_1_div(struct device *dev, const char *buf,
454 size_t count)
455{
456 return set_fan_div(dev, buf, count, 0) ;
457}
458
459static ssize_t set_fan_2_div(struct device *dev, const char *buf,
460 size_t count)
461{
462 return set_fan_div(dev, buf, count, 1) ;
463}
464static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
465 show_fan_1_div, set_fan_1_div);
466static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
467 show_fan_2_div, set_fan_2_div);
468
469/* Alarms */
470static ssize_t show_alarms(struct device *dev, char *buf)
471{
472 struct sis5595_data *data = sis5595_update_device(dev);
473 return sprintf(buf, "%d\n", data->alarms);
474}
475static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
476
477/* This is called when the module is loaded */
478static int sis5595_attach_adapter(struct i2c_adapter *adapter)
479{
480 if (!(adapter->class & I2C_CLASS_HWMON))
481 return 0;
482 return i2c_detect(adapter, &addr_data, sis5595_detect);
483}
484
485int sis5595_detect(struct i2c_adapter *adapter, int address, int kind)
486{
487 int err = 0;
488 int i;
489 struct i2c_client *new_client;
490 struct sis5595_data *data;
491 char val;
492 u16 a;
493
494 /* Make sure we are probing the ISA bus!! */
495 if (!i2c_is_isa_adapter(adapter))
496 goto exit;
497
498 if (force_addr)
499 address = force_addr & ~(SIS5595_EXTENT - 1);
500 /* Reserve the ISA region */
501 if (!request_region(address, SIS5595_EXTENT, sis5595_driver.name)) {
502 err = -EBUSY;
503 goto exit;
504 }
505 if (force_addr) {
506 dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", address);
507 if (PCIBIOS_SUCCESSFUL !=
508 pci_write_config_word(s_bridge, SIS5595_BASE_REG, address))
509 goto exit_release;
510 if (PCIBIOS_SUCCESSFUL !=
511 pci_read_config_word(s_bridge, SIS5595_BASE_REG, &a))
512 goto exit_release;
513 if ((a & ~(SIS5595_EXTENT - 1)) != address)
514 /* doesn't work for some chips? */
515 goto exit_release;
516 }
517
518 if (PCIBIOS_SUCCESSFUL !=
519 pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val)) {
520 goto exit_release;
521 }
522 if ((val & 0x80) == 0) {
523 if (PCIBIOS_SUCCESSFUL !=
524 pci_write_config_byte(s_bridge, SIS5595_ENABLE_REG,
525 val | 0x80))
526 goto exit_release;
527 if (PCIBIOS_SUCCESSFUL !=
528 pci_read_config_byte(s_bridge, SIS5595_ENABLE_REG, &val))
529 goto exit_release;
530 if ((val & 0x80) == 0)
531 /* doesn't work for some chips! */
532 goto exit_release;
533 }
534
535 if (!(data = kmalloc(sizeof(struct sis5595_data), GFP_KERNEL))) {
536 err = -ENOMEM;
537 goto exit_release;
538 }
539 memset(data, 0, sizeof(struct sis5595_data));
540
541 new_client = &data->client;
542 new_client->addr = address;
543 init_MUTEX(&data->lock);
544 i2c_set_clientdata(new_client, data);
545 new_client->adapter = adapter;
546 new_client->driver = &sis5595_driver;
547 new_client->flags = 0;
548
549 /* Check revision and pin registers to determine whether 4 or 5 voltages */
550 pci_read_config_byte(s_bridge, SIS5595_REVISION_REG, &(data->revision));
551 /* 4 voltages, 1 temp */
552 data->maxins = 3;
553 if (data->revision >= REV2MIN) {
554 pci_read_config_byte(s_bridge, SIS5595_PIN_REG, &val);
555 if (!(val & 0x80))
556 /* 5 voltages, no temps */
557 data->maxins = 4;
558 }
559
560 /* Fill in the remaining client fields and put it into the global list */
561 strlcpy(new_client->name, "sis5595", I2C_NAME_SIZE);
562
563 data->valid = 0;
564 init_MUTEX(&data->update_lock);
565
566 /* Tell the I2C layer a new client has arrived */
567 if ((err = i2c_attach_client(new_client)))
568 goto exit_free;
569
570 /* Initialize the SIS5595 chip */
571 sis5595_init_client(new_client);
572
573 /* A few vars need to be filled upon startup */
574 for (i = 0; i < 2; i++) {
575 data->fan_min[i] = sis5595_read_value(new_client,
576 SIS5595_REG_FAN_MIN(i));
577 }
578
579 /* Register sysfs hooks */
580 device_create_file(&new_client->dev, &dev_attr_in0_input);
581 device_create_file(&new_client->dev, &dev_attr_in0_min);
582 device_create_file(&new_client->dev, &dev_attr_in0_max);
583 device_create_file(&new_client->dev, &dev_attr_in1_input);
584 device_create_file(&new_client->dev, &dev_attr_in1_min);
585 device_create_file(&new_client->dev, &dev_attr_in1_max);
586 device_create_file(&new_client->dev, &dev_attr_in2_input);
587 device_create_file(&new_client->dev, &dev_attr_in2_min);
588 device_create_file(&new_client->dev, &dev_attr_in2_max);
589 device_create_file(&new_client->dev, &dev_attr_in3_input);
590 device_create_file(&new_client->dev, &dev_attr_in3_min);
591 device_create_file(&new_client->dev, &dev_attr_in3_max);
592 if (data->maxins == 4) {
593 device_create_file(&new_client->dev, &dev_attr_in4_input);
594 device_create_file(&new_client->dev, &dev_attr_in4_min);
595 device_create_file(&new_client->dev, &dev_attr_in4_max);
596 }
597 device_create_file(&new_client->dev, &dev_attr_fan1_input);
598 device_create_file(&new_client->dev, &dev_attr_fan1_min);
599 device_create_file(&new_client->dev, &dev_attr_fan1_div);
600 device_create_file(&new_client->dev, &dev_attr_fan2_input);
601 device_create_file(&new_client->dev, &dev_attr_fan2_min);
602 device_create_file(&new_client->dev, &dev_attr_fan2_div);
603 device_create_file(&new_client->dev, &dev_attr_alarms);
604 if (data->maxins == 3) {
605 device_create_file(&new_client->dev, &dev_attr_temp1_input);
606 device_create_file(&new_client->dev, &dev_attr_temp1_max);
607 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
608 }
609 return 0;
610
611exit_free:
612 kfree(data);
613exit_release:
614 release_region(address, SIS5595_EXTENT);
615exit:
616 return err;
617}
618
619static int sis5595_detach_client(struct i2c_client *client)
620{
621 int err;
622
623 if ((err = i2c_detach_client(client))) {
624 dev_err(&client->dev,
625 "Client deregistration failed, client not detached.\n");
626 return err;
627 }
628
629 if (i2c_is_isa_client(client))
630 release_region(client->addr, SIS5595_EXTENT);
631
632 kfree(i2c_get_clientdata(client));
633
634 return 0;
635}
636
637
638/* ISA access must be locked explicitly. */
639static int sis5595_read_value(struct i2c_client *client, u8 reg)
640{
641 int res;
642
643 struct sis5595_data *data = i2c_get_clientdata(client);
644 down(&data->lock);
645 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
646 res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET);
647 up(&data->lock);
648 return res;
649}
650
651static int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value)
652{
653 struct sis5595_data *data = i2c_get_clientdata(client);
654 down(&data->lock);
655 outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET);
656 outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET);
657 up(&data->lock);
658 return 0;
659}
660
661/* Called when we have found a new SIS5595. */
662static void sis5595_init_client(struct i2c_client *client)
663{
664 u8 config = sis5595_read_value(client, SIS5595_REG_CONFIG);
665 if (!(config & 0x01))
666 sis5595_write_value(client, SIS5595_REG_CONFIG,
667 (config & 0xf7) | 0x01);
668}
669
670static struct sis5595_data *sis5595_update_device(struct device *dev)
671{
672 struct i2c_client *client = to_i2c_client(dev);
673 struct sis5595_data *data = i2c_get_clientdata(client);
674 int i;
675
676 down(&data->update_lock);
677
678 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
679 || !data->valid) {
680
681 for (i = 0; i <= data->maxins; i++) {
682 data->in[i] =
683 sis5595_read_value(client, SIS5595_REG_IN(i));
684 data->in_min[i] =
685 sis5595_read_value(client,
686 SIS5595_REG_IN_MIN(i));
687 data->in_max[i] =
688 sis5595_read_value(client,
689 SIS5595_REG_IN_MAX(i));
690 }
691 for (i = 0; i < 2; i++) {
692 data->fan[i] =
693 sis5595_read_value(client, SIS5595_REG_FAN(i));
694 data->fan_min[i] =
695 sis5595_read_value(client,
696 SIS5595_REG_FAN_MIN(i));
697 }
698 if (data->maxins == 3) {
699 data->temp =
700 sis5595_read_value(client, SIS5595_REG_TEMP);
701 data->temp_over =
702 sis5595_read_value(client, SIS5595_REG_TEMP_OVER);
703 data->temp_hyst =
704 sis5595_read_value(client, SIS5595_REG_TEMP_HYST);
705 }
706 i = sis5595_read_value(client, SIS5595_REG_FANDIV);
707 data->fan_div[0] = (i >> 4) & 0x03;
708 data->fan_div[1] = i >> 6;
709 data->alarms =
710 sis5595_read_value(client, SIS5595_REG_ALARM1) |
711 (sis5595_read_value(client, SIS5595_REG_ALARM2) << 8);
712 data->last_updated = jiffies;
713 data->valid = 1;
714 }
715
716 up(&data->update_lock);
717
718 return data;
719}
720
721static struct pci_device_id sis5595_pci_ids[] = {
722 { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
723 { 0, }
724};
725
726MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
727
728static int blacklist[] __devinitdata = {
729 PCI_DEVICE_ID_SI_540,
730 PCI_DEVICE_ID_SI_550,
731 PCI_DEVICE_ID_SI_630,
732 PCI_DEVICE_ID_SI_645,
733 PCI_DEVICE_ID_SI_730,
734 PCI_DEVICE_ID_SI_735,
735 PCI_DEVICE_ID_SI_5511, /* 5513 chip has the 0008 device but
736 that ID shows up in other chips so we
737 use the 5511 ID for recognition */
738 PCI_DEVICE_ID_SI_5597,
739 PCI_DEVICE_ID_SI_5598,
740 0 };
741
742static int __devinit sis5595_pci_probe(struct pci_dev *dev,
743 const struct pci_device_id *id)
744{
745 u16 val;
746 int *i;
747 int addr = 0;
748
749 for (i = blacklist; *i != 0; i++) {
750 struct pci_dev *dev;
751 dev = pci_get_device(PCI_VENDOR_ID_SI, *i, NULL);
752 if (dev) {
753 dev_err(&dev->dev, "Looked for SIS5595 but found unsupported device %.4x\n", *i);
754 pci_dev_put(dev);
755 return -ENODEV;
756 }
757 }
758
759 if (PCIBIOS_SUCCESSFUL !=
760 pci_read_config_word(dev, SIS5595_BASE_REG, &val))
761 return -ENODEV;
762
763 addr = val & ~(SIS5595_EXTENT - 1);
764 if (addr == 0 && force_addr == 0) {
765 dev_err(&dev->dev, "Base address not set - upgrade BIOS or use force_addr=0xaddr\n");
766 return -ENODEV;
767 }
768 if (force_addr)
769 addr = force_addr; /* so detect will get called */
770
771 if (!addr) {
772 dev_err(&dev->dev,"No SiS 5595 sensors found.\n");
773 return -ENODEV;
774 }
775 normal_isa[0] = addr;
776
777 s_bridge = pci_dev_get(dev);
778 if (i2c_add_driver(&sis5595_driver)) {
779 pci_dev_put(s_bridge);
780 s_bridge = NULL;
781 }
782
783 /* Always return failure here. This is to allow other drivers to bind
784 * to this pci device. We don't really want to have control over the
785 * pci device, we only wanted to read as few register values from it.
786 */
787 return -ENODEV;
788}
789
790static struct pci_driver sis5595_pci_driver = {
791 .name = "sis5595",
792 .id_table = sis5595_pci_ids,
793 .probe = sis5595_pci_probe,
794};
795
796static int __init sm_sis5595_init(void)
797{
798 return pci_register_driver(&sis5595_pci_driver);
799}
800
801static void __exit sm_sis5595_exit(void)
802{
803 pci_unregister_driver(&sis5595_pci_driver);
804 if (s_bridge != NULL) {
805 i2c_del_driver(&sis5595_driver);
806 pci_dev_put(s_bridge);
807 s_bridge = NULL;
808 }
809}
810
811MODULE_AUTHOR("Aurelien Jarno <aurelien@aurel32.net>");
812MODULE_DESCRIPTION("SiS 5595 Sensor device");
813MODULE_LICENSE("GPL");
814
815module_init(sm_sis5595_init);
816module_exit(sm_sis5595_exit);
diff --git a/drivers/i2c/chips/smsc47b397.c b/drivers/i2c/chips/smsc47b397.c
deleted file mode 100644
index 1119c76791d9..000000000000
--- a/drivers/i2c/chips/smsc47b397.c
+++ /dev/null
@@ -1,352 +0,0 @@
1/*
2 smsc47b397.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 Supports the SMSC LPC47B397-NC Super-I/O chip.
6
7 Author/Maintainer: Mark M. Hoffman <mhoffman@lightlink.com>
8 Copyright (C) 2004 Utilitek Systems, Inc.
9
10 derived in part from smsc47m1.c:
11 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
12 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/
28
29#include <linux/module.h>
30#include <linux/slab.h>
31#include <linux/ioport.h>
32#include <linux/jiffies.h>
33#include <linux/i2c.h>
34#include <linux/i2c-sensor.h>
35#include <linux/init.h>
36#include <asm/io.h>
37
38static unsigned short normal_i2c[] = { I2C_CLIENT_END };
39/* Address is autodetected, there is no default value */
40static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
41static struct i2c_force_data forces[] = {{NULL}};
42
43enum chips { any_chip, smsc47b397 };
44static struct i2c_address_data addr_data = {
45 .normal_i2c = normal_i2c,
46 .normal_isa = normal_isa,
47 .probe = normal_i2c, /* cheat */
48 .ignore = normal_i2c, /* cheat */
49 .forces = forces,
50};
51
52/* Super-I/0 registers and commands */
53
54#define REG 0x2e /* The register to read/write */
55#define VAL 0x2f /* The value to read/write */
56
57static inline void superio_outb(int reg, int val)
58{
59 outb(reg, REG);
60 outb(val, VAL);
61}
62
63static inline int superio_inb(int reg)
64{
65 outb(reg, REG);
66 return inb(VAL);
67}
68
69/* select superio logical device */
70static inline void superio_select(int ld)
71{
72 superio_outb(0x07, ld);
73}
74
75static inline void superio_enter(void)
76{
77 outb(0x55, REG);
78}
79
80static inline void superio_exit(void)
81{
82 outb(0xAA, REG);
83}
84
85#define SUPERIO_REG_DEVID 0x20
86#define SUPERIO_REG_DEVREV 0x21
87#define SUPERIO_REG_BASE_MSB 0x60
88#define SUPERIO_REG_BASE_LSB 0x61
89#define SUPERIO_REG_LD8 0x08
90
91#define SMSC_EXTENT 0x02
92
93/* 0 <= nr <= 3 */
94static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
95#define SMSC47B397_REG_TEMP(nr) (smsc47b397_reg_temp[(nr)])
96
97/* 0 <= nr <= 3 */
98#define SMSC47B397_REG_FAN_LSB(nr) (0x28 + 2 * (nr))
99#define SMSC47B397_REG_FAN_MSB(nr) (0x29 + 2 * (nr))
100
101struct smsc47b397_data {
102 struct i2c_client client;
103 struct semaphore lock;
104
105 struct semaphore update_lock;
106 unsigned long last_updated; /* in jiffies */
107 int valid;
108
109 /* register values */
110 u16 fan[4];
111 u8 temp[4];
112};
113
114static int smsc47b397_read_value(struct i2c_client *client, u8 reg)
115{
116 struct smsc47b397_data *data = i2c_get_clientdata(client);
117 int res;
118
119 down(&data->lock);
120 outb(reg, client->addr);
121 res = inb_p(client->addr + 1);
122 up(&data->lock);
123 return res;
124}
125
126static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
127{
128 struct i2c_client *client = to_i2c_client(dev);
129 struct smsc47b397_data *data = i2c_get_clientdata(client);
130 int i;
131
132 down(&data->update_lock);
133
134 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
135 dev_dbg(&client->dev, "starting device update...\n");
136
137 /* 4 temperature inputs, 4 fan inputs */
138 for (i = 0; i < 4; i++) {
139 data->temp[i] = smsc47b397_read_value(client,
140 SMSC47B397_REG_TEMP(i));
141
142 /* must read LSB first */
143 data->fan[i] = smsc47b397_read_value(client,
144 SMSC47B397_REG_FAN_LSB(i));
145 data->fan[i] |= smsc47b397_read_value(client,
146 SMSC47B397_REG_FAN_MSB(i)) << 8;
147 }
148
149 data->last_updated = jiffies;
150 data->valid = 1;
151
152 dev_dbg(&client->dev, "... device update complete\n");
153 }
154
155 up(&data->update_lock);
156
157 return data;
158}
159
160/* TEMP: 0.001C/bit (-128C to +127C)
161 REG: 1C/bit, two's complement */
162static int temp_from_reg(u8 reg)
163{
164 return (s8)reg * 1000;
165}
166
167/* 0 <= nr <= 3 */
168static ssize_t show_temp(struct device *dev, char *buf, int nr)
169{
170 struct smsc47b397_data *data = smsc47b397_update_device(dev);
171 return sprintf(buf, "%d\n", temp_from_reg(data->temp[nr]));
172}
173
174#define sysfs_temp(num) \
175static ssize_t show_temp##num(struct device *dev, char *buf) \
176{ \
177 return show_temp(dev, buf, num-1); \
178} \
179static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL)
180
181sysfs_temp(1);
182sysfs_temp(2);
183sysfs_temp(3);
184sysfs_temp(4);
185
186#define device_create_file_temp(client, num) \
187 device_create_file(&client->dev, &dev_attr_temp##num##_input)
188
189/* FAN: 1 RPM/bit
190 REG: count of 90kHz pulses / revolution */
191static int fan_from_reg(u16 reg)
192{
193 return 90000 * 60 / reg;
194}
195
196/* 0 <= nr <= 3 */
197static ssize_t show_fan(struct device *dev, char *buf, int nr)
198{
199 struct smsc47b397_data *data = smsc47b397_update_device(dev);
200 return sprintf(buf, "%d\n", fan_from_reg(data->fan[nr]));
201}
202
203#define sysfs_fan(num) \
204static ssize_t show_fan##num(struct device *dev, char *buf) \
205{ \
206 return show_fan(dev, buf, num-1); \
207} \
208static DEVICE_ATTR(fan##num##_input, S_IRUGO, show_fan##num, NULL)
209
210sysfs_fan(1);
211sysfs_fan(2);
212sysfs_fan(3);
213sysfs_fan(4);
214
215#define device_create_file_fan(client, num) \
216 device_create_file(&client->dev, &dev_attr_fan##num##_input)
217
218static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind);
219
220static int smsc47b397_attach_adapter(struct i2c_adapter *adapter)
221{
222 if (!(adapter->class & I2C_CLASS_HWMON))
223 return 0;
224 return i2c_detect(adapter, &addr_data, smsc47b397_detect);
225}
226
227static int smsc47b397_detach_client(struct i2c_client *client)
228{
229 int err;
230
231 if ((err = i2c_detach_client(client))) {
232 dev_err(&client->dev, "Client deregistration failed, "
233 "client not detached.\n");
234 return err;
235 }
236
237 release_region(client->addr, SMSC_EXTENT);
238 kfree(i2c_get_clientdata(client));
239
240 return 0;
241}
242
243static struct i2c_driver smsc47b397_driver = {
244 .owner = THIS_MODULE,
245 .name = "smsc47b397",
246 .id = I2C_DRIVERID_SMSC47B397,
247 .flags = I2C_DF_NOTIFY,
248 .attach_adapter = smsc47b397_attach_adapter,
249 .detach_client = smsc47b397_detach_client,
250};
251
252static int smsc47b397_detect(struct i2c_adapter *adapter, int addr, int kind)
253{
254 struct i2c_client *new_client;
255 struct smsc47b397_data *data;
256 int err = 0;
257
258 if (!i2c_is_isa_adapter(adapter)) {
259 return 0;
260 }
261
262 if (!request_region(addr, SMSC_EXTENT, smsc47b397_driver.name)) {
263 dev_err(&adapter->dev, "Region 0x%x already in use!\n", addr);
264 return -EBUSY;
265 }
266
267 if (!(data = kmalloc(sizeof(struct smsc47b397_data), GFP_KERNEL))) {
268 err = -ENOMEM;
269 goto error_release;
270 }
271 memset(data, 0x00, sizeof(struct smsc47b397_data));
272
273 new_client = &data->client;
274 i2c_set_clientdata(new_client, data);
275 new_client->addr = addr;
276 init_MUTEX(&data->lock);
277 new_client->adapter = adapter;
278 new_client->driver = &smsc47b397_driver;
279 new_client->flags = 0;
280
281 strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE);
282
283 init_MUTEX(&data->update_lock);
284
285 if ((err = i2c_attach_client(new_client)))
286 goto error_free;
287
288 device_create_file_temp(new_client, 1);
289 device_create_file_temp(new_client, 2);
290 device_create_file_temp(new_client, 3);
291 device_create_file_temp(new_client, 4);
292
293 device_create_file_fan(new_client, 1);
294 device_create_file_fan(new_client, 2);
295 device_create_file_fan(new_client, 3);
296 device_create_file_fan(new_client, 4);
297
298 return 0;
299
300error_free:
301 kfree(new_client);
302error_release:
303 release_region(addr, SMSC_EXTENT);
304 return err;
305}
306
307static int __init smsc47b397_find(unsigned int *addr)
308{
309 u8 id, rev;
310
311 superio_enter();
312 id = superio_inb(SUPERIO_REG_DEVID);
313
314 if (id != 0x6f) {
315 superio_exit();
316 return -ENODEV;
317 }
318
319 rev = superio_inb(SUPERIO_REG_DEVREV);
320
321 superio_select(SUPERIO_REG_LD8);
322 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
323 | superio_inb(SUPERIO_REG_BASE_LSB);
324
325 printk(KERN_INFO "smsc47b397: found SMSC LPC47B397-NC "
326 "(base address 0x%04x, revision %u)\n", *addr, rev);
327
328 superio_exit();
329 return 0;
330}
331
332static int __init smsc47b397_init(void)
333{
334 int ret;
335
336 if ((ret = smsc47b397_find(normal_isa)))
337 return ret;
338
339 return i2c_add_driver(&smsc47b397_driver);
340}
341
342static void __exit smsc47b397_exit(void)
343{
344 i2c_del_driver(&smsc47b397_driver);
345}
346
347MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
348MODULE_DESCRIPTION("SMSC LPC47B397 driver");
349MODULE_LICENSE("GPL");
350
351module_init(smsc47b397_init);
352module_exit(smsc47b397_exit);
diff --git a/drivers/i2c/chips/smsc47m1.c b/drivers/i2c/chips/smsc47m1.c
deleted file mode 100644
index 0e12ca369413..000000000000
--- a/drivers/i2c/chips/smsc47m1.c
+++ /dev/null
@@ -1,591 +0,0 @@
1/*
2 smsc47m1.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M13x and LPC47M14x
6 Super-I/O chips.
7
8 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
9 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
10 Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com>
11 and Jean Delvare
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/
27
28#include <linux/module.h>
29#include <linux/slab.h>
30#include <linux/ioport.h>
31#include <linux/jiffies.h>
32#include <linux/i2c.h>
33#include <linux/i2c-sensor.h>
34#include <linux/init.h>
35#include <asm/io.h>
36
37static unsigned short normal_i2c[] = { I2C_CLIENT_END };
38/* Address is autodetected, there is no default value */
39static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
40static struct i2c_force_data forces[] = {{NULL}};
41
42enum chips { any_chip, smsc47m1 };
43static struct i2c_address_data addr_data = {
44 .normal_i2c = normal_i2c,
45 .normal_isa = normal_isa,
46 .forces = forces,
47};
48
49/* Super-I/0 registers and commands */
50
51#define REG 0x2e /* The register to read/write */
52#define VAL 0x2f /* The value to read/write */
53
54static inline void
55superio_outb(int reg, int val)
56{
57 outb(reg, REG);
58 outb(val, VAL);
59}
60
61static inline int
62superio_inb(int reg)
63{
64 outb(reg, REG);
65 return inb(VAL);
66}
67
68/* logical device for fans is 0x0A */
69#define superio_select() superio_outb(0x07, 0x0A)
70
71static inline void
72superio_enter(void)
73{
74 outb(0x55, REG);
75}
76
77static inline void
78superio_exit(void)
79{
80 outb(0xAA, REG);
81}
82
83#define SUPERIO_REG_ACT 0x30
84#define SUPERIO_REG_BASE 0x60
85#define SUPERIO_REG_DEVID 0x20
86
87/* Logical device registers */
88
89#define SMSC_EXTENT 0x80
90
91/* nr is 0 or 1 in the macros below */
92#define SMSC47M1_REG_ALARM 0x04
93#define SMSC47M1_REG_TPIN(nr) (0x34 - (nr))
94#define SMSC47M1_REG_PPIN(nr) (0x36 - (nr))
95#define SMSC47M1_REG_PWM(nr) (0x56 + (nr))
96#define SMSC47M1_REG_FANDIV 0x58
97#define SMSC47M1_REG_FAN(nr) (0x59 + (nr))
98#define SMSC47M1_REG_FAN_PRELOAD(nr) (0x5B + (nr))
99
100#define MIN_FROM_REG(reg,div) ((reg)>=192 ? 0 : \
101 983040/((192-(reg))*(div)))
102#define FAN_FROM_REG(reg,div,preload) ((reg)<=(preload) || (reg)==255 ? 0 : \
103 983040/(((reg)-(preload))*(div)))
104#define DIV_FROM_REG(reg) (1 << (reg))
105#define PWM_FROM_REG(reg) (((reg) & 0x7E) << 1)
106#define PWM_EN_FROM_REG(reg) ((~(reg)) & 0x01)
107#define PWM_TO_REG(reg) (((reg) >> 1) & 0x7E)
108
109struct smsc47m1_data {
110 struct i2c_client client;
111 struct semaphore lock;
112
113 struct semaphore update_lock;
114 unsigned long last_updated; /* In jiffies */
115
116 u8 fan[2]; /* Register value */
117 u8 fan_preload[2]; /* Register value */
118 u8 fan_div[2]; /* Register encoding, shifted right */
119 u8 alarms; /* Register encoding */
120 u8 pwm[2]; /* Register value (bit 7 is enable) */
121};
122
123
124static int smsc47m1_attach_adapter(struct i2c_adapter *adapter);
125static int smsc47m1_find(int *address);
126static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind);
127static int smsc47m1_detach_client(struct i2c_client *client);
128
129static int smsc47m1_read_value(struct i2c_client *client, u8 reg);
130static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value);
131
132static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
133 int init);
134
135
136static struct i2c_driver smsc47m1_driver = {
137 .owner = THIS_MODULE,
138 .name = "smsc47m1",
139 .id = I2C_DRIVERID_SMSC47M1,
140 .flags = I2C_DF_NOTIFY,
141 .attach_adapter = smsc47m1_attach_adapter,
142 .detach_client = smsc47m1_detach_client,
143};
144
145/* nr is 0 or 1 in the callback functions below */
146
147static ssize_t get_fan(struct device *dev, char *buf, int nr)
148{
149 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
150 /* This chip (stupidly) stops monitoring fan speed if PWM is
151 enabled and duty cycle is 0%. This is fine if the monitoring
152 and control concern the same fan, but troublesome if they are
153 not (which could as well happen). */
154 int rpm = (data->pwm[nr] & 0x7F) == 0x00 ? 0 :
155 FAN_FROM_REG(data->fan[nr],
156 DIV_FROM_REG(data->fan_div[nr]),
157 data->fan_preload[nr]);
158 return sprintf(buf, "%d\n", rpm);
159}
160
161static ssize_t get_fan_min(struct device *dev, char *buf, int nr)
162{
163 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
164 int rpm = MIN_FROM_REG(data->fan_preload[nr],
165 DIV_FROM_REG(data->fan_div[nr]));
166 return sprintf(buf, "%d\n", rpm);
167}
168
169static ssize_t get_fan_div(struct device *dev, char *buf, int nr)
170{
171 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
172 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
173}
174
175static ssize_t get_pwm(struct device *dev, char *buf, int nr)
176{
177 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
178 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
179}
180
181static ssize_t get_pwm_en(struct device *dev, char *buf, int nr)
182{
183 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
184 return sprintf(buf, "%d\n", PWM_EN_FROM_REG(data->pwm[nr]));
185}
186
187static ssize_t get_alarms(struct device *dev, char *buf)
188{
189 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
190 return sprintf(buf, "%d\n", data->alarms);
191}
192
193static ssize_t set_fan_min(struct device *dev, const char *buf,
194 size_t count, int nr)
195{
196 struct i2c_client *client = to_i2c_client(dev);
197 struct smsc47m1_data *data = i2c_get_clientdata(client);
198 long rpmdiv, val = simple_strtol(buf, NULL, 10);
199
200 down(&data->update_lock);
201 rpmdiv = val * DIV_FROM_REG(data->fan_div[nr]);
202
203 if (983040 > 192 * rpmdiv || 2 * rpmdiv > 983040) {
204 up(&data->update_lock);
205 return -EINVAL;
206 }
207
208 data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv);
209 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
210 data->fan_preload[nr]);
211 up(&data->update_lock);
212
213 return count;
214}
215
216/* Note: we save and restore the fan minimum here, because its value is
217 determined in part by the fan clock divider. This follows the principle
218 of least suprise; the user doesn't expect the fan minimum to change just
219 because the divider changed. */
220static ssize_t set_fan_div(struct device *dev, const char *buf,
221 size_t count, int nr)
222{
223 struct i2c_client *client = to_i2c_client(dev);
224 struct smsc47m1_data *data = i2c_get_clientdata(client);
225
226 long new_div = simple_strtol(buf, NULL, 10), tmp;
227 u8 old_div = DIV_FROM_REG(data->fan_div[nr]);
228
229 if (new_div == old_div) /* No change */
230 return count;
231
232 down(&data->update_lock);
233 switch (new_div) {
234 case 1: data->fan_div[nr] = 0; break;
235 case 2: data->fan_div[nr] = 1; break;
236 case 4: data->fan_div[nr] = 2; break;
237 case 8: data->fan_div[nr] = 3; break;
238 default:
239 up(&data->update_lock);
240 return -EINVAL;
241 }
242
243 tmp = smsc47m1_read_value(client, SMSC47M1_REG_FANDIV) & 0x0F;
244 tmp |= (data->fan_div[0] << 4) | (data->fan_div[1] << 6);
245 smsc47m1_write_value(client, SMSC47M1_REG_FANDIV, tmp);
246
247 /* Preserve fan min */
248 tmp = 192 - (old_div * (192 - data->fan_preload[nr])
249 + new_div / 2) / new_div;
250 data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191);
251 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr),
252 data->fan_preload[nr]);
253 up(&data->update_lock);
254
255 return count;
256}
257
258static ssize_t set_pwm(struct device *dev, const char *buf,
259 size_t count, int nr)
260{
261 struct i2c_client *client = to_i2c_client(dev);
262 struct smsc47m1_data *data = i2c_get_clientdata(client);
263
264 long val = simple_strtol(buf, NULL, 10);
265
266 if (val < 0 || val > 255)
267 return -EINVAL;
268
269 down(&data->update_lock);
270 data->pwm[nr] &= 0x81; /* Preserve additional bits */
271 data->pwm[nr] |= PWM_TO_REG(val);
272 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
273 data->pwm[nr]);
274 up(&data->update_lock);
275
276 return count;
277}
278
279static ssize_t set_pwm_en(struct device *dev, const char *buf,
280 size_t count, int nr)
281{
282 struct i2c_client *client = to_i2c_client(dev);
283 struct smsc47m1_data *data = i2c_get_clientdata(client);
284
285 long val = simple_strtol(buf, NULL, 10);
286
287 if (val != 0 && val != 1)
288 return -EINVAL;
289
290 down(&data->update_lock);
291 data->pwm[nr] &= 0xFE; /* preserve the other bits */
292 data->pwm[nr] |= !val;
293 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr),
294 data->pwm[nr]);
295 up(&data->update_lock);
296
297 return count;
298}
299
300#define fan_present(offset) \
301static ssize_t get_fan##offset (struct device *dev, char *buf) \
302{ \
303 return get_fan(dev, buf, offset - 1); \
304} \
305static ssize_t get_fan##offset##_min (struct device *dev, char *buf) \
306{ \
307 return get_fan_min(dev, buf, offset - 1); \
308} \
309static ssize_t set_fan##offset##_min (struct device *dev, \
310 const char *buf, size_t count) \
311{ \
312 return set_fan_min(dev, buf, count, offset - 1); \
313} \
314static ssize_t get_fan##offset##_div (struct device *dev, char *buf) \
315{ \
316 return get_fan_div(dev, buf, offset - 1); \
317} \
318static ssize_t set_fan##offset##_div (struct device *dev, \
319 const char *buf, size_t count) \
320{ \
321 return set_fan_div(dev, buf, count, offset - 1); \
322} \
323static ssize_t get_pwm##offset (struct device *dev, char *buf) \
324{ \
325 return get_pwm(dev, buf, offset - 1); \
326} \
327static ssize_t set_pwm##offset (struct device *dev, \
328 const char *buf, size_t count) \
329{ \
330 return set_pwm(dev, buf, count, offset - 1); \
331} \
332static ssize_t get_pwm##offset##_en (struct device *dev, char *buf) \
333{ \
334 return get_pwm_en(dev, buf, offset - 1); \
335} \
336static ssize_t set_pwm##offset##_en (struct device *dev, \
337 const char *buf, size_t count) \
338{ \
339 return set_pwm_en(dev, buf, count, offset - 1); \
340} \
341static DEVICE_ATTR(fan##offset##_input, S_IRUGO, get_fan##offset, \
342 NULL); \
343static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
344 get_fan##offset##_min, set_fan##offset##_min); \
345static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
346 get_fan##offset##_div, set_fan##offset##_div); \
347static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
348 get_pwm##offset, set_pwm##offset); \
349static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
350 get_pwm##offset##_en, set_pwm##offset##_en);
351
352fan_present(1);
353fan_present(2);
354
355static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
356
357static int smsc47m1_attach_adapter(struct i2c_adapter *adapter)
358{
359 if (!(adapter->class & I2C_CLASS_HWMON))
360 return 0;
361 return i2c_detect(adapter, &addr_data, smsc47m1_detect);
362}
363
364static int smsc47m1_find(int *address)
365{
366 u8 val;
367
368 superio_enter();
369 val = superio_inb(SUPERIO_REG_DEVID);
370
371 /*
372 * SMSC LPC47M10x/LPC47M13x (device id 0x59), LPC47M14x (device id
373 * 0x5F) and LPC47B27x (device id 0x51) have fan control.
374 * The LPC47M15x and LPC47M192 chips "with hardware monitoring block"
375 * can do much more besides (device id 0x60, unsupported).
376 */
377 if (val == 0x51)
378 printk(KERN_INFO "smsc47m1: Found SMSC47B27x\n");
379 else if (val == 0x59)
380 printk(KERN_INFO "smsc47m1: Found SMSC47M10x/SMSC47M13x\n");
381 else if (val == 0x5F)
382 printk(KERN_INFO "smsc47m1: Found SMSC47M14x\n");
383 else {
384 superio_exit();
385 return -ENODEV;
386 }
387
388 superio_select();
389 *address = (superio_inb(SUPERIO_REG_BASE) << 8)
390 | superio_inb(SUPERIO_REG_BASE + 1);
391 val = superio_inb(SUPERIO_REG_ACT);
392 if (*address == 0 || (val & 0x01) == 0) {
393 printk(KERN_INFO "smsc47m1: Device is disabled, will not use\n");
394 superio_exit();
395 return -ENODEV;
396 }
397
398 superio_exit();
399 return 0;
400}
401
402static int smsc47m1_detect(struct i2c_adapter *adapter, int address, int kind)
403{
404 struct i2c_client *new_client;
405 struct smsc47m1_data *data;
406 int err = 0;
407 int fan1, fan2, pwm1, pwm2;
408
409 if (!i2c_is_isa_adapter(adapter)) {
410 return 0;
411 }
412
413 if (!request_region(address, SMSC_EXTENT, smsc47m1_driver.name)) {
414 dev_err(&adapter->dev, "Region 0x%x already in use!\n", address);
415 return -EBUSY;
416 }
417
418 if (!(data = kmalloc(sizeof(struct smsc47m1_data), GFP_KERNEL))) {
419 err = -ENOMEM;
420 goto error_release;
421 }
422 memset(data, 0x00, sizeof(struct smsc47m1_data));
423
424 new_client = &data->client;
425 i2c_set_clientdata(new_client, data);
426 new_client->addr = address;
427 init_MUTEX(&data->lock);
428 new_client->adapter = adapter;
429 new_client->driver = &smsc47m1_driver;
430 new_client->flags = 0;
431
432 strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE);
433 init_MUTEX(&data->update_lock);
434
435 /* If no function is properly configured, there's no point in
436 actually registering the chip. */
437 fan1 = (smsc47m1_read_value(new_client, SMSC47M1_REG_TPIN(0)) & 0x05)
438 == 0x05;
439 fan2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_TPIN(1)) & 0x05)
440 == 0x05;
441 pwm1 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(0)) & 0x05)
442 == 0x04;
443 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05)
444 == 0x04;
445 if (!(fan1 || fan2 || pwm1 || pwm2)) {
446 dev_warn(&new_client->dev, "Device is not configured, will not use\n");
447 err = -ENODEV;
448 goto error_free;
449 }
450
451 if ((err = i2c_attach_client(new_client)))
452 goto error_free;
453
454 /* Some values (fan min, clock dividers, pwm registers) may be
455 needed before any update is triggered, so we better read them
456 at least once here. We don't usually do it that way, but in
457 this particular case, manually reading 5 registers out of 8
458 doesn't make much sense and we're better using the existing
459 function. */
460 smsc47m1_update_device(&new_client->dev, 1);
461
462 if (fan1) {
463 device_create_file(&new_client->dev, &dev_attr_fan1_input);
464 device_create_file(&new_client->dev, &dev_attr_fan1_min);
465 device_create_file(&new_client->dev, &dev_attr_fan1_div);
466 } else
467 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, "
468 "skipping\n");
469
470 if (fan2) {
471 device_create_file(&new_client->dev, &dev_attr_fan2_input);
472 device_create_file(&new_client->dev, &dev_attr_fan2_min);
473 device_create_file(&new_client->dev, &dev_attr_fan2_div);
474 } else
475 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, "
476 "skipping\n");
477
478 if (pwm1) {
479 device_create_file(&new_client->dev, &dev_attr_pwm1);
480 device_create_file(&new_client->dev, &dev_attr_pwm1_enable);
481 } else
482 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, "
483 "skipping\n");
484 if (pwm2) {
485 device_create_file(&new_client->dev, &dev_attr_pwm2);
486 device_create_file(&new_client->dev, &dev_attr_pwm2_enable);
487 } else
488 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, "
489 "skipping\n");
490
491 device_create_file(&new_client->dev, &dev_attr_alarms);
492
493 return 0;
494
495error_free:
496 kfree(new_client);
497error_release:
498 release_region(address, SMSC_EXTENT);
499 return err;
500}
501
502static int smsc47m1_detach_client(struct i2c_client *client)
503{
504 int err;
505
506 if ((err = i2c_detach_client(client))) {
507 dev_err(&client->dev, "Client deregistration failed, "
508 "client not detached.\n");
509 return err;
510 }
511
512 release_region(client->addr, SMSC_EXTENT);
513 kfree(i2c_get_clientdata(client));
514
515 return 0;
516}
517
518static int smsc47m1_read_value(struct i2c_client *client, u8 reg)
519{
520 int res;
521
522 down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
523 res = inb_p(client->addr + reg);
524 up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
525 return res;
526}
527
528static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value)
529{
530 down(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
531 outb_p(value, client->addr + reg);
532 up(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
533}
534
535static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
536 int init)
537{
538 struct i2c_client *client = to_i2c_client(dev);
539 struct smsc47m1_data *data = i2c_get_clientdata(client);
540
541 down(&data->update_lock);
542
543 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) {
544 int i;
545
546 for (i = 0; i < 2; i++) {
547 data->fan[i] = smsc47m1_read_value(client,
548 SMSC47M1_REG_FAN(i));
549 data->fan_preload[i] = smsc47m1_read_value(client,
550 SMSC47M1_REG_FAN_PRELOAD(i));
551 data->pwm[i] = smsc47m1_read_value(client,
552 SMSC47M1_REG_PWM(i));
553 }
554
555 i = smsc47m1_read_value(client, SMSC47M1_REG_FANDIV);
556 data->fan_div[0] = (i >> 4) & 0x03;
557 data->fan_div[1] = i >> 6;
558
559 data->alarms = smsc47m1_read_value(client,
560 SMSC47M1_REG_ALARM) >> 6;
561 /* Clear alarms if needed */
562 if (data->alarms)
563 smsc47m1_write_value(client, SMSC47M1_REG_ALARM, 0xC0);
564
565 data->last_updated = jiffies;
566 }
567
568 up(&data->update_lock);
569 return data;
570}
571
572static int __init sm_smsc47m1_init(void)
573{
574 if (smsc47m1_find(normal_isa)) {
575 return -ENODEV;
576 }
577
578 return i2c_add_driver(&smsc47m1_driver);
579}
580
581static void __exit sm_smsc47m1_exit(void)
582{
583 i2c_del_driver(&smsc47m1_driver);
584}
585
586MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>");
587MODULE_DESCRIPTION("SMSC LPC47M1xx fan sensors driver");
588MODULE_LICENSE("GPL");
589
590module_init(sm_smsc47m1_init);
591module_exit(sm_smsc47m1_exit);
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
new file mode 100644
index 000000000000..280e9638c0f8
--- /dev/null
+++ b/drivers/i2c/chips/tps65010.c
@@ -0,0 +1,1069 @@
1/*
2 * tps65010 - driver for tps6501x power management chips
3 *
4 * Copyright (C) 2004 Texas Instruments
5 * Copyright (C) 2004-2005 David Brownell
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/config.h>
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/device.h>
29#include <linux/i2c.h>
30#include <linux/delay.h>
31#include <linux/workqueue.h>
32#include <linux/suspend.h>
33#include <linux/debugfs.h>
34#include <linux/seq_file.h>
35
36#include <asm/irq.h>
37#include <asm/mach-types.h>
38
39#include <asm/arch/gpio.h>
40#include <asm/arch/mux.h>
41#include <asm/arch/tps65010.h>
42
43/*-------------------------------------------------------------------------*/
44
45#define DRIVER_VERSION "2 May 2005"
46#define DRIVER_NAME (tps65010_driver.name)
47
48MODULE_DESCRIPTION("TPS6501x Power Management Driver");
49MODULE_LICENSE("GPL");
50
51static unsigned short normal_i2c[] = { 0x48, /* 0x49, */ I2C_CLIENT_END };
52static unsigned short normal_i2c_range[] = { I2C_CLIENT_END };
53
54I2C_CLIENT_INSMOD;
55
56static struct i2c_driver tps65010_driver;
57
58/*-------------------------------------------------------------------------*/
59
60/* This driver handles a family of multipurpose chips, which incorporate
61 * voltage regulators, lithium ion/polymer battery charging, GPIOs, LEDs,
62 * and other features often needed in portable devices like cell phones
63 * or digital cameras.
64 *
65 * The tps65011 and tps65013 have different voltage settings compared
66 * to tps65010 and tps65012. The tps65013 has a NO_CHG status/irq.
67 * All except tps65010 have "wait" mode, possibly defaulted so that
68 * battery-insert != device-on.
69 *
70 * We could distinguish between some models by checking VDCDC1.UVLO or
71 * other registers, unless they've been changed already after powerup
72 * as part of board setup by a bootloader.
73 */
74enum tps_model {
75 TPS_UNKNOWN = 0,
76 TPS65010,
77 TPS65011,
78 TPS65012,
79 TPS65013,
80};
81
82struct tps65010 {
83 struct i2c_client client;
84 struct semaphore lock;
85 int irq;
86 struct work_struct work;
87 struct dentry *file;
88 unsigned charging:1;
89 unsigned por:1;
90 unsigned model:8;
91 u16 vbus;
92 unsigned long flags;
93#define FLAG_VBUS_CHANGED 0
94#define FLAG_IRQ_ENABLE 1
95
96 /* copies of last register state */
97 u8 chgstatus, regstatus, chgconf;
98 u8 nmask1, nmask2;
99
100 /* not currently tracking GPIO state */
101};
102
103#define POWER_POLL_DELAY msecs_to_jiffies(800)
104
105/*-------------------------------------------------------------------------*/
106
107#if defined(DEBUG) || defined(CONFIG_DEBUG_FS)
108
109static void dbg_chgstat(char *buf, size_t len, u8 chgstatus)
110{
111 snprintf(buf, len, "%02x%s%s%s%s%s%s%s%s\n",
112 chgstatus,
113 (chgstatus & TPS_CHG_USB) ? " USB" : "",
114 (chgstatus & TPS_CHG_AC) ? " AC" : "",
115 (chgstatus & TPS_CHG_THERM) ? " therm" : "",
116 (chgstatus & TPS_CHG_TERM) ? " done" :
117 ((chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
118 ? " (charging)" : ""),
119 (chgstatus & TPS_CHG_TAPER_TMO) ? " taper_tmo" : "",
120 (chgstatus & TPS_CHG_CHG_TMO) ? " charge_tmo" : "",
121 (chgstatus & TPS_CHG_PRECHG_TMO) ? " prechg_tmo" : "",
122 (chgstatus & TPS_CHG_TEMP_ERR) ? " temp_err" : "");
123}
124
125static void dbg_regstat(char *buf, size_t len, u8 regstatus)
126{
127 snprintf(buf, len, "%02x %s%s%s%s%s%s%s%s\n",
128 regstatus,
129 (regstatus & TPS_REG_ONOFF) ? "off" : "(on)",
130 (regstatus & TPS_REG_COVER) ? " uncover" : "",
131 (regstatus & TPS_REG_UVLO) ? " UVLO" : "",
132 (regstatus & TPS_REG_NO_CHG) ? " NO_CHG" : "",
133 (regstatus & TPS_REG_PG_LD02) ? " ld02_bad" : "",
134 (regstatus & TPS_REG_PG_LD01) ? " ld01_bad" : "",
135 (regstatus & TPS_REG_PG_MAIN) ? " main_bad" : "",
136 (regstatus & TPS_REG_PG_CORE) ? " core_bad" : "");
137}
138
139static void dbg_chgconf(int por, char *buf, size_t len, u8 chgconfig)
140{
141 const char *hibit;
142
143 if (por)
144 hibit = (chgconfig & TPS_CHARGE_POR)
145 ? "POR=69ms" : "POR=1sec";
146 else
147 hibit = (chgconfig & TPS65013_AUA) ? "AUA" : "";
148
149 snprintf(buf, len, "%02x %s%s%s AC=%d%% USB=%dmA %sCharge\n",
150 chgconfig, hibit,
151 (chgconfig & TPS_CHARGE_RESET) ? " reset" : "",
152 (chgconfig & TPS_CHARGE_FAST) ? " fast" : "",
153 ({int p; switch ((chgconfig >> 3) & 3) {
154 case 3: p = 100; break;
155 case 2: p = 75; break;
156 case 1: p = 50; break;
157 default: p = 25; break;
158 }; p; }),
159 (chgconfig & TPS_VBUS_CHARGING)
160 ? ((chgconfig & TPS_VBUS_500MA) ? 500 : 100)
161 : 0,
162 (chgconfig & TPS_CHARGE_ENABLE) ? "" : "No");
163}
164
165#endif
166
167#ifdef DEBUG
168
169static void show_chgstatus(const char *label, u8 chgstatus)
170{
171 char buf [100];
172
173 dbg_chgstat(buf, sizeof buf, chgstatus);
174 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
175}
176
177static void show_regstatus(const char *label, u8 regstatus)
178{
179 char buf [100];
180
181 dbg_regstat(buf, sizeof buf, regstatus);
182 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
183}
184
185static void show_chgconfig(int por, const char *label, u8 chgconfig)
186{
187 char buf [100];
188
189 dbg_chgconf(por, buf, sizeof buf, chgconfig);
190 pr_debug("%s: %s %s", DRIVER_NAME, label, buf);
191}
192
193#else
194
195static inline void show_chgstatus(const char *label, u8 chgstatus) { }
196static inline void show_regstatus(const char *label, u8 chgstatus) { }
197static inline void show_chgconfig(int por, const char *label, u8 chgconfig) { }
198
199#endif
200
201#ifdef CONFIG_DEBUG_FS
202
203static int dbg_show(struct seq_file *s, void *_)
204{
205 struct tps65010 *tps = s->private;
206 u8 value, v2;
207 unsigned i;
208 char buf[100];
209 const char *chip;
210
211 switch (tps->model) {
212 case TPS65010: chip = "tps65010"; break;
213 case TPS65011: chip = "tps65011"; break;
214 case TPS65012: chip = "tps65012"; break;
215 case TPS65013: chip = "tps65013"; break;
216 default: chip = NULL; break;
217 }
218 seq_printf(s, "driver %s\nversion %s\nchip %s\n\n",
219 DRIVER_NAME, DRIVER_VERSION, chip);
220
221 down(&tps->lock);
222
223 /* FIXME how can we tell whether a battery is present?
224 * likely involves a charge gauging chip (like BQ26501).
225 */
226
227 seq_printf(s, "%scharging\n\n", tps->charging ? "" : "(not) ");
228
229
230 /* registers for monitoring battery charging and status; note
231 * that reading chgstat and regstat may ack IRQs...
232 */
233 value = i2c_smbus_read_byte_data(&tps->client, TPS_CHGCONFIG);
234 dbg_chgconf(tps->por, buf, sizeof buf, value);
235 seq_printf(s, "chgconfig %s", buf);
236
237 value = i2c_smbus_read_byte_data(&tps->client, TPS_CHGSTATUS);
238 dbg_chgstat(buf, sizeof buf, value);
239 seq_printf(s, "chgstat %s", buf);
240 value = i2c_smbus_read_byte_data(&tps->client, TPS_MASK1);
241 dbg_chgstat(buf, sizeof buf, value);
242 seq_printf(s, "mask1 %s", buf);
243 /* ignore ackint1 */
244
245 value = i2c_smbus_read_byte_data(&tps->client, TPS_REGSTATUS);
246 dbg_regstat(buf, sizeof buf, value);
247 seq_printf(s, "regstat %s", buf);
248 value = i2c_smbus_read_byte_data(&tps->client, TPS_MASK2);
249 dbg_regstat(buf, sizeof buf, value);
250 seq_printf(s, "mask2 %s\n", buf);
251 /* ignore ackint2 */
252
253 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
254
255
256 /* VMAIN voltage, enable lowpower, etc */
257 value = i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC1);
258 seq_printf(s, "vdcdc1 %02x\n", value);
259
260 /* VCORE voltage, vibrator on/off */
261 value = i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC2);
262 seq_printf(s, "vdcdc2 %02x\n", value);
263
264 /* both LD0s, and their lowpower behavior */
265 value = i2c_smbus_read_byte_data(&tps->client, TPS_VREGS1);
266 seq_printf(s, "vregs1 %02x\n\n", value);
267
268
269 /* LEDs and GPIOs */
270 value = i2c_smbus_read_byte_data(&tps->client, TPS_LED1_ON);
271 v2 = i2c_smbus_read_byte_data(&tps->client, TPS_LED1_PER);
272 seq_printf(s, "led1 %s, on=%02x, per=%02x, %d/%d msec\n",
273 (value & 0x80)
274 ? ((v2 & 0x80) ? "on" : "off")
275 : ((v2 & 0x80) ? "blink" : "(nPG)"),
276 value, v2,
277 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
278
279 value = i2c_smbus_read_byte_data(&tps->client, TPS_LED2_ON);
280 v2 = i2c_smbus_read_byte_data(&tps->client, TPS_LED2_PER);
281 seq_printf(s, "led2 %s, on=%02x, per=%02x, %d/%d msec\n",
282 (value & 0x80)
283 ? ((v2 & 0x80) ? "on" : "off")
284 : ((v2 & 0x80) ? "blink" : "off"),
285 value, v2,
286 (value & 0x7f) * 10, (v2 & 0x7f) * 100);
287
288 value = i2c_smbus_read_byte_data(&tps->client, TPS_DEFGPIO);
289 v2 = i2c_smbus_read_byte_data(&tps->client, TPS_MASK3);
290 seq_printf(s, "defgpio %02x mask3 %02x\n", value, v2);
291
292 for (i = 0; i < 4; i++) {
293 if (value & (1 << (4 + i)))
294 seq_printf(s, " gpio%d-out %s\n", i + 1,
295 (value & (1 << i)) ? "low" : "hi ");
296 else
297 seq_printf(s, " gpio%d-in %s %s %s\n", i + 1,
298 (value & (1 << i)) ? "hi " : "low",
299 (v2 & (1 << i)) ? "no-irq" : "irq",
300 (v2 & (1 << (4 + i))) ? "rising" : "falling");
301 }
302
303 up(&tps->lock);
304 return 0;
305}
306
307static int dbg_tps_open(struct inode *inode, struct file *file)
308{
309 return single_open(file, dbg_show, inode->u.generic_ip);
310}
311
312static struct file_operations debug_fops = {
313 .open = dbg_tps_open,
314 .read = seq_read,
315 .llseek = seq_lseek,
316 .release = single_release,
317};
318
319#define DEBUG_FOPS &debug_fops
320
321#else
322#define DEBUG_FOPS NULL
323#endif
324
325/*-------------------------------------------------------------------------*/
326
327/* handle IRQS in a task context, so we can use I2C calls */
328static void tps65010_interrupt(struct tps65010 *tps)
329{
330 u8 tmp = 0, mask, poll;
331
332 /* IRQs won't trigger irqs for certain events, but we can get
333 * others by polling (normally, with external power applied).
334 */
335 poll = 0;
336
337 /* regstatus irqs */
338 if (tps->nmask2) {
339 tmp = i2c_smbus_read_byte_data(&tps->client, TPS_REGSTATUS);
340 mask = tmp ^ tps->regstatus;
341 tps->regstatus = tmp;
342 mask &= tps->nmask2;
343 } else
344 mask = 0;
345 if (mask) {
346 tps->regstatus = tmp;
347 /* may need to shut something down ... */
348
349 /* "off" usually means deep sleep */
350 if (tmp & TPS_REG_ONOFF) {
351 pr_info("%s: power off button\n", DRIVER_NAME);
352#if 0
353 /* REVISIT: this might need its own workqueue
354 * plus tweaks including deadlock avoidance ...
355 */
356 software_suspend();
357#endif
358 poll = 1;
359 }
360 }
361
362 /* chgstatus irqs */
363 if (tps->nmask1) {
364 tmp = i2c_smbus_read_byte_data(&tps->client, TPS_CHGSTATUS);
365 mask = tmp ^ tps->chgstatus;
366 tps->chgstatus = tmp;
367 mask &= tps->nmask1;
368 } else
369 mask = 0;
370 if (mask) {
371 unsigned charging = 0;
372
373 show_chgstatus("chg/irq", tmp);
374 if (tmp & (TPS_CHG_USB|TPS_CHG_AC))
375 show_chgconfig(tps->por, "conf", tps->chgconf);
376
377 /* Unless it was turned off or disabled, we charge any
378 * battery whenever there's power available for it
379 * and the charger hasn't been disabled.
380 */
381 if (!(tps->chgstatus & ~(TPS_CHG_USB|TPS_CHG_AC))
382 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
383 && (tps->chgconf & TPS_CHARGE_ENABLE)
384 ) {
385 if (tps->chgstatus & TPS_CHG_USB) {
386 /* VBUS options are readonly until reconnect */
387 if (mask & TPS_CHG_USB)
388 set_bit(FLAG_VBUS_CHANGED, &tps->flags);
389 charging = 1;
390 } else if (tps->chgstatus & TPS_CHG_AC)
391 charging = 1;
392 }
393 if (charging != tps->charging) {
394 tps->charging = charging;
395 pr_info("%s: battery %scharging\n",
396 DRIVER_NAME, charging ? "" :
397 ((tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC))
398 ? "NOT " : "dis"));
399 }
400 }
401
402 /* always poll to detect (a) power removal, without tps65013
403 * NO_CHG IRQ; or (b) restart of charging after stop.
404 */
405 if ((tps->model != TPS65013 || !tps->charging)
406 && (tps->chgstatus & (TPS_CHG_USB|TPS_CHG_AC)))
407 poll = 1;
408 if (poll)
409 (void) schedule_delayed_work(&tps->work, POWER_POLL_DELAY);
410
411 /* also potentially gpio-in rise or fall */
412}
413
414/* handle IRQs and polling using keventd for now */
415static void tps65010_work(void *_tps)
416{
417 struct tps65010 *tps = _tps;
418
419 down(&tps->lock);
420
421 tps65010_interrupt(tps);
422
423 if (test_and_clear_bit(FLAG_VBUS_CHANGED, &tps->flags)) {
424 int status;
425 u8 chgconfig, tmp;
426
427 chgconfig = i2c_smbus_read_byte_data(&tps->client,
428 TPS_CHGCONFIG);
429 chgconfig &= ~(TPS_VBUS_500MA | TPS_VBUS_CHARGING);
430 if (tps->vbus == 500)
431 chgconfig |= TPS_VBUS_500MA | TPS_VBUS_CHARGING;
432 else if (tps->vbus >= 100)
433 chgconfig |= TPS_VBUS_CHARGING;
434
435 status = i2c_smbus_write_byte_data(&tps->client,
436 TPS_CHGCONFIG, chgconfig);
437
438 /* vbus update fails unless VBUS is connected! */
439 tmp = i2c_smbus_read_byte_data(&tps->client, TPS_CHGCONFIG);
440 tps->chgconf = tmp;
441 show_chgconfig(tps->por, "update vbus", tmp);
442 }
443
444 if (test_and_clear_bit(FLAG_IRQ_ENABLE, &tps->flags))
445 enable_irq(tps->irq);
446
447 up(&tps->lock);
448}
449
450static irqreturn_t tps65010_irq(int irq, void *_tps, struct pt_regs *regs)
451{
452 struct tps65010 *tps = _tps;
453
454 disable_irq_nosync(irq);
455 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
456 (void) schedule_work(&tps->work);
457 return IRQ_HANDLED;
458}
459
460/*-------------------------------------------------------------------------*/
461
462static struct tps65010 *the_tps;
463
464static int __exit tps65010_detach_client(struct i2c_client *client)
465{
466 struct tps65010 *tps;
467
468 tps = container_of(client, struct tps65010, client);
469#ifdef CONFIG_ARM
470 if (machine_is_omap_h2())
471 omap_free_gpio(58);
472 if (machine_is_omap_osk())
473 omap_free_gpio(OMAP_MPUIO(1));
474#endif
475 free_irq(tps->irq, tps);
476 debugfs_remove(tps->file);
477 if (i2c_detach_client(client) == 0)
478 kfree(tps);
479 the_tps = NULL;
480 return 0;
481}
482
483static int tps65010_noscan(struct i2c_adapter *bus)
484{
485 /* pure paranoia, in case someone adds another i2c bus
486 * after our init section's gone...
487 */
488 return -ENODEV;
489}
490
491/* no error returns, they'd just make bus scanning stop */
492static int __init
493tps65010_probe(struct i2c_adapter *bus, int address, int kind)
494{
495 struct tps65010 *tps;
496 int status;
497
498 if (the_tps) {
499 dev_dbg(&bus->dev, "only one %s for now\n", DRIVER_NAME);
500 return 0;
501 }
502
503 tps = kmalloc(sizeof *tps, GFP_KERNEL);
504 if (!tps)
505 return 0;
506
507 memset(tps, 0, sizeof *tps);
508 init_MUTEX(&tps->lock);
509 INIT_WORK(&tps->work, tps65010_work, tps);
510 tps->irq = -1;
511 tps->client.addr = address;
512 tps->client.adapter = bus;
513 tps->client.driver = &tps65010_driver;
514 strlcpy(tps->client.name, DRIVER_NAME, I2C_NAME_SIZE);
515
516 status = i2c_attach_client(&tps->client);
517 if (status < 0) {
518 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n",
519 DRIVER_NAME, address, status);
520 goto fail1;
521 }
522
523#ifdef CONFIG_ARM
524 if (machine_is_omap_h2()) {
525 tps->model = TPS65010;
526 omap_cfg_reg(W4_GPIO58);
527 tps->irq = OMAP_GPIO_IRQ(58);
528 omap_request_gpio(58);
529 omap_set_gpio_direction(58, 1);
530 set_irq_type(tps->irq, IRQT_FALLING);
531 }
532 if (machine_is_omap_osk()) {
533 tps->model = TPS65010;
534 // omap_cfg_reg(U19_1610_MPUIO1);
535 tps->irq = OMAP_GPIO_IRQ(OMAP_MPUIO(1));
536 omap_request_gpio(OMAP_MPUIO(1));
537 omap_set_gpio_direction(OMAP_MPUIO(1), 1);
538 set_irq_type(tps->irq, IRQT_FALLING);
539 }
540 if (machine_is_omap_h3()) {
541 tps->model = TPS65013;
542
543 // FIXME set up this board's IRQ ...
544 }
545#else
546#define set_irq_type(num,trigger) do{}while(0)
547#endif
548
549 if (tps->irq > 0) {
550 set_irq_type(tps->irq, IRQT_LOW);
551 status = request_irq(tps->irq, tps65010_irq,
552 SA_SAMPLE_RANDOM, DRIVER_NAME, tps);
553 if (status < 0) {
554 dev_dbg(&tps->client.dev, "can't get IRQ %d, err %d\n",
555 tps->irq, status);
556 i2c_detach_client(&tps->client);
557 goto fail1;
558 }
559#ifdef CONFIG_ARM
560 /* annoying race here, ideally we'd have an option
561 * to claim the irq now and enable it later.
562 */
563 disable_irq(tps->irq);
564 set_bit(FLAG_IRQ_ENABLE, &tps->flags);
565#endif
566 } else
567 printk(KERN_WARNING "%s: IRQ not configured!\n",
568 DRIVER_NAME);
569
570
571 switch (tps->model) {
572 case TPS65010:
573 case TPS65012:
574 tps->por = 1;
575 break;
576 case TPS_UNKNOWN:
577 printk(KERN_WARNING "%s: unknown TPS chip\n", DRIVER_NAME);
578 break;
579 /* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
580 }
581 tps->chgconf = i2c_smbus_read_byte_data(&tps->client, TPS_CHGCONFIG);
582 show_chgconfig(tps->por, "conf/init", tps->chgconf);
583
584 show_chgstatus("chg/init",
585 i2c_smbus_read_byte_data(&tps->client, TPS_CHGSTATUS));
586 show_regstatus("reg/init",
587 i2c_smbus_read_byte_data(&tps->client, TPS_REGSTATUS));
588
589 pr_debug("%s: vdcdc1 0x%02x, vdcdc2 %02x, vregs1 %02x\n", DRIVER_NAME,
590 i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC1),
591 i2c_smbus_read_byte_data(&tps->client, TPS_VDCDC2),
592 i2c_smbus_read_byte_data(&tps->client, TPS_VREGS1));
593 pr_debug("%s: defgpio 0x%02x, mask3 0x%02x\n", DRIVER_NAME,
594 i2c_smbus_read_byte_data(&tps->client, TPS_DEFGPIO),
595 i2c_smbus_read_byte_data(&tps->client, TPS_MASK3));
596
597 tps65010_driver.attach_adapter = tps65010_noscan;
598 the_tps = tps;
599
600#if defined(CONFIG_USB_GADGET) && !defined(CONFIG_USB_OTG)
601 /* USB hosts can't draw VBUS. OTG devices could, later
602 * when OTG infrastructure enables it. USB peripherals
603 * could be relying on VBUS while booting, though.
604 */
605 tps->vbus = 100;
606#endif
607
608 /* unmask the "interesting" irqs, then poll once to
609 * kickstart monitoring, initialize shadowed status
610 * registers, and maybe disable VBUS draw.
611 */
612 tps->nmask1 = ~0;
613 (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK1, ~tps->nmask1);
614
615 tps->nmask2 = TPS_REG_ONOFF;
616 if (tps->model == TPS65013)
617 tps->nmask2 |= TPS_REG_NO_CHG;
618 (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK2, ~tps->nmask2);
619
620 (void) i2c_smbus_write_byte_data(&tps->client, TPS_MASK3, 0x0f
621 | i2c_smbus_read_byte_data(&tps->client, TPS_MASK3));
622
623 tps65010_work(tps);
624
625 tps->file = debugfs_create_file(DRIVER_NAME, S_IRUGO, NULL,
626 tps, DEBUG_FOPS);
627 return 0;
628fail1:
629 kfree(tps);
630 return 0;
631}
632
633static int __init tps65010_scan_bus(struct i2c_adapter *bus)
634{
635 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA))
636 return -EINVAL;
637 return i2c_probe(bus, &addr_data, tps65010_probe);
638}
639
640static struct i2c_driver tps65010_driver = {
641 .owner = THIS_MODULE,
642 .name = "tps65010",
643 .flags = I2C_DF_NOTIFY,
644 .attach_adapter = tps65010_scan_bus,
645 .detach_client = __exit_p(tps65010_detach_client),
646};
647
648/*-------------------------------------------------------------------------*/
649
650/* Draw from VBUS:
651 * 0 mA -- DON'T DRAW (might supply power instead)
652 * 100 mA -- usb unit load (slowest charge rate)
653 * 500 mA -- usb high power (fast battery charge)
654 */
655int tps65010_set_vbus_draw(unsigned mA)
656{
657 unsigned long flags;
658
659 if (!the_tps)
660 return -ENODEV;
661
662 /* assumes non-SMP */
663 local_irq_save(flags);
664 if (mA >= 500)
665 mA = 500;
666 else if (mA >= 100)
667 mA = 100;
668 else
669 mA = 0;
670 the_tps->vbus = mA;
671 if ((the_tps->chgstatus & TPS_CHG_USB)
672 && test_and_set_bit(
673 FLAG_VBUS_CHANGED, &the_tps->flags)) {
674 /* gadget drivers call this in_irq() */
675 (void) schedule_work(&the_tps->work);
676 }
677 local_irq_restore(flags);
678
679 return 0;
680}
681EXPORT_SYMBOL(tps65010_set_vbus_draw);
682
683/*-------------------------------------------------------------------------*/
684/* tps65010_set_gpio_out_value parameter:
685 * gpio: GPIO1, GPIO2, GPIO3 or GPIO4
686 * value: LOW or HIGH
687 */
688int tps65010_set_gpio_out_value(unsigned gpio, unsigned value)
689{
690 int status;
691 unsigned defgpio;
692
693 if (!the_tps)
694 return -ENODEV;
695 if ((gpio < GPIO1) || (gpio > GPIO4))
696 return -EINVAL;
697
698 down(&the_tps->lock);
699
700 defgpio = i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO);
701
702 /* Configure GPIO for output */
703 defgpio |= 1 << (gpio + 3);
704
705 /* Writing 1 forces a logic 0 on that GPIO and vice versa */
706 switch (value) {
707 case LOW:
708 defgpio |= 1 << (gpio - 1); /* set GPIO low by writing 1 */
709 break;
710 /* case HIGH: */
711 default:
712 defgpio &= ~(1 << (gpio - 1)); /* set GPIO high by writing 0 */
713 break;
714 }
715
716 status = i2c_smbus_write_byte_data(&the_tps->client,
717 TPS_DEFGPIO, defgpio);
718
719 pr_debug("%s: gpio%dout = %s, defgpio 0x%02x\n", DRIVER_NAME,
720 gpio, value ? "high" : "low",
721 i2c_smbus_read_byte_data(&the_tps->client, TPS_DEFGPIO));
722
723 up(&the_tps->lock);
724 return status;
725}
726EXPORT_SYMBOL(tps65010_set_gpio_out_value);
727
728/*-------------------------------------------------------------------------*/
729/* tps65010_set_led parameter:
730 * led: LED1 or LED2
731 * mode: ON, OFF or BLINK
732 */
733int tps65010_set_led(unsigned led, unsigned mode)
734{
735 int status;
736 unsigned led_on, led_per, offs;
737
738 if (!the_tps)
739 return -ENODEV;
740
741 if (led == LED1)
742 offs = 0;
743 else {
744 offs = 2;
745 led = LED2;
746 }
747
748 down(&the_tps->lock);
749
750 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
751 i2c_smbus_read_byte_data(&the_tps->client,
752 TPS_LED1_ON + offs));
753
754 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
755 i2c_smbus_read_byte_data(&the_tps->client,
756 TPS_LED1_PER + offs));
757
758 switch (mode) {
759 case OFF:
760 led_on = 1 << 7;
761 led_per = 0 << 7;
762 break;
763 case ON:
764 led_on = 1 << 7;
765 led_per = 1 << 7;
766 break;
767 case BLINK:
768 led_on = 0x30 | (0 << 7);
769 led_per = 0x08 | (1 << 7);
770 break;
771 default:
772 printk(KERN_ERR "%s: Wrong mode parameter for set_led()\n",
773 DRIVER_NAME);
774 up(&the_tps->lock);
775 return -EINVAL;
776 }
777
778 status = i2c_smbus_write_byte_data(&the_tps->client,
779 TPS_LED1_ON + offs, led_on);
780
781 if (status != 0) {
782 printk(KERN_ERR "%s: Failed to write led%i_on register\n",
783 DRIVER_NAME, led);
784 up(&the_tps->lock);
785 return status;
786 }
787
788 pr_debug("%s: led%i_on 0x%02x\n", DRIVER_NAME, led,
789 i2c_smbus_read_byte_data(&the_tps->client, TPS_LED1_ON + offs));
790
791 status = i2c_smbus_write_byte_data(&the_tps->client,
792 TPS_LED1_PER + offs, led_per);
793
794 if (status != 0) {
795 printk(KERN_ERR "%s: Failed to write led%i_per register\n",
796 DRIVER_NAME, led);
797 up(&the_tps->lock);
798 return status;
799 }
800
801 pr_debug("%s: led%i_per 0x%02x\n", DRIVER_NAME, led,
802 i2c_smbus_read_byte_data(&the_tps->client,
803 TPS_LED1_PER + offs));
804
805 up(&the_tps->lock);
806
807 return status;
808}
809EXPORT_SYMBOL(tps65010_set_led);
810
811/*-------------------------------------------------------------------------*/
812/* tps65010_set_vib parameter:
813 * value: ON or OFF
814 */
815int tps65010_set_vib(unsigned value)
816{
817 int status;
818 unsigned vdcdc2;
819
820 if (!the_tps)
821 return -ENODEV;
822
823 down(&the_tps->lock);
824
825 vdcdc2 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC2);
826 vdcdc2 &= ~(1 << 1);
827 if (value)
828 vdcdc2 |= (1 << 1);
829 status = i2c_smbus_write_byte_data(&the_tps->client,
830 TPS_VDCDC2, vdcdc2);
831
832 pr_debug("%s: vibrator %s\n", DRIVER_NAME, value ? "on" : "off");
833
834 up(&the_tps->lock);
835 return status;
836}
837EXPORT_SYMBOL(tps65010_set_vib);
838
839/*-------------------------------------------------------------------------*/
840/* tps65010_set_low_pwr parameter:
841 * mode: ON or OFF
842 */
843int tps65010_set_low_pwr(unsigned mode)
844{
845 int status;
846 unsigned vdcdc1;
847
848 if (!the_tps)
849 return -ENODEV;
850
851 down(&the_tps->lock);
852
853 pr_debug("%s: %s low_pwr, vdcdc1 0x%02x\n", DRIVER_NAME,
854 mode ? "enable" : "disable",
855 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
856
857 vdcdc1 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1);
858
859 switch (mode) {
860 case OFF:
861 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
862 break;
863 /* case ON: */
864 default:
865 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
866 break;
867 }
868
869 status = i2c_smbus_write_byte_data(&the_tps->client,
870 TPS_VDCDC1, vdcdc1);
871
872 if (status != 0)
873 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
874 DRIVER_NAME);
875 else
876 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
877 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
878
879 up(&the_tps->lock);
880
881 return status;
882}
883EXPORT_SYMBOL(tps65010_set_low_pwr);
884
885/*-------------------------------------------------------------------------*/
886/* tps65010_config_vregs1 parameter:
887 * value to be written to VREGS1 register
888 * Note: The complete register is written, set all bits you need
889 */
890int tps65010_config_vregs1(unsigned value)
891{
892 int status;
893
894 if (!the_tps)
895 return -ENODEV;
896
897 down(&the_tps->lock);
898
899 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
900 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
901
902 status = i2c_smbus_write_byte_data(&the_tps->client,
903 TPS_VREGS1, value);
904
905 if (status != 0)
906 printk(KERN_ERR "%s: Failed to write vregs1 register\n",
907 DRIVER_NAME);
908 else
909 pr_debug("%s: vregs1 0x%02x\n", DRIVER_NAME,
910 i2c_smbus_read_byte_data(&the_tps->client, TPS_VREGS1));
911
912 up(&the_tps->lock);
913
914 return status;
915}
916EXPORT_SYMBOL(tps65010_config_vregs1);
917
918/*-------------------------------------------------------------------------*/
919/* tps65013_set_low_pwr parameter:
920 * mode: ON or OFF
921 */
922
923/* FIXME: Assumes AC or USB power is present. Setting AUA bit is not
924 required if power supply is through a battery */
925
926int tps65013_set_low_pwr(unsigned mode)
927{
928 int status;
929 unsigned vdcdc1, chgconfig;
930
931 if (!the_tps || the_tps->por)
932 return -ENODEV;
933
934 down(&the_tps->lock);
935
936 pr_debug("%s: %s low_pwr, chgconfig 0x%02x vdcdc1 0x%02x\n",
937 DRIVER_NAME,
938 mode ? "enable" : "disable",
939 i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG),
940 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
941
942 chgconfig = i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG);
943 vdcdc1 = i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1);
944
945 switch (mode) {
946 case OFF:
947 chgconfig &= ~TPS65013_AUA; /* disable AUA bit */
948 vdcdc1 &= ~TPS_ENABLE_LP; /* disable ENABLE_LP bit */
949 break;
950 /* case ON: */
951 default:
952 chgconfig |= TPS65013_AUA; /* enable AUA bit */
953 vdcdc1 |= TPS_ENABLE_LP; /* enable ENABLE_LP bit */
954 break;
955 }
956
957 status = i2c_smbus_write_byte_data(&the_tps->client,
958 TPS_CHGCONFIG, chgconfig);
959 if (status != 0) {
960 printk(KERN_ERR "%s: Failed to write chconfig register\n",
961 DRIVER_NAME);
962 up(&the_tps->lock);
963 return status;
964 }
965
966 chgconfig = i2c_smbus_read_byte_data(&the_tps->client, TPS_CHGCONFIG);
967 the_tps->chgconf = chgconfig;
968 show_chgconfig(0, "chgconf", chgconfig);
969
970 status = i2c_smbus_write_byte_data(&the_tps->client,
971 TPS_VDCDC1, vdcdc1);
972
973 if (status != 0)
974 printk(KERN_ERR "%s: Failed to write vdcdc1 register\n",
975 DRIVER_NAME);
976 else
977 pr_debug("%s: vdcdc1 0x%02x\n", DRIVER_NAME,
978 i2c_smbus_read_byte_data(&the_tps->client, TPS_VDCDC1));
979
980 up(&the_tps->lock);
981
982 return status;
983}
984EXPORT_SYMBOL(tps65013_set_low_pwr);
985
986/*-------------------------------------------------------------------------*/
987
988static int __init tps_init(void)
989{
990 u32 tries = 3;
991 int status = -ENODEV;
992
993 printk(KERN_INFO "%s: version %s\n", DRIVER_NAME, DRIVER_VERSION);
994
995 /* some boards have startup glitches */
996 while (tries--) {
997 status = i2c_add_driver(&tps65010_driver);
998 if (the_tps)
999 break;
1000 i2c_del_driver(&tps65010_driver);
1001 if (!tries) {
1002 printk(KERN_ERR "%s: no chip?\n", DRIVER_NAME);
1003 return -ENODEV;
1004 }
1005 pr_debug("%s: re-probe ...\n", DRIVER_NAME);
1006 msleep(10);
1007 }
1008
1009#ifdef CONFIG_ARM
1010 if (machine_is_omap_osk()) {
1011
1012 // FIXME: More should be placed in the initialization code
1013 // of the submodules (DSP, ethernet, power management,
1014 // board-osk.c). Careful: I2C is initialized "late".
1015
1016 /* Let LED1 (D9) blink */
1017 tps65010_set_led(LED1, BLINK);
1018
1019 /* Disable LED 2 (D2) */
1020 tps65010_set_led(LED2, OFF);
1021
1022 /* Set GPIO 1 HIGH to disable VBUS power supply;
1023 * OHCI driver powers it up/down as needed.
1024 */
1025 tps65010_set_gpio_out_value(GPIO1, HIGH);
1026
1027 /* Set GPIO 2 low to turn on LED D3 */
1028 tps65010_set_gpio_out_value(GPIO2, HIGH);
1029
1030 /* Set GPIO 3 low to take ethernet out of reset */
1031 tps65010_set_gpio_out_value(GPIO3, LOW);
1032
1033 /* gpio4 for VDD_DSP */
1034
1035 /* Enable LOW_PWR */
1036 tps65010_set_low_pwr(ON);
1037
1038 /* Switch VLDO2 to 3.0V for AIC23 */
1039 tps65010_config_vregs1(TPS_LDO2_ENABLE | TPS_VLDO2_3_0V | TPS_LDO1_ENABLE);
1040
1041 } else if (machine_is_omap_h2()) {
1042 /* gpio3 for SD, gpio4 for VDD_DSP */
1043
1044 /* Enable LOW_PWR */
1045 tps65010_set_low_pwr(ON);
1046 } else if (machine_is_omap_h3()) {
1047 /* gpio4 for SD, gpio3 for VDD_DSP */
1048#ifdef CONFIG_PM
1049 /* Enable LOW_PWR */
1050 tps65013_set_low_pwr(ON);
1051#endif
1052 }
1053#endif
1054
1055 return status;
1056}
1057/* NOTE: this MUST be initialized before the other parts of the system
1058 * that rely on it ... but after the i2c bus on which this relies.
1059 * That is, much earlier than on PC-type systems, which don't often use
1060 * I2C as a core system bus.
1061 */
1062subsys_initcall(tps_init);
1063
1064static void __exit tps_exit(void)
1065{
1066 i2c_del_driver(&tps65010_driver);
1067}
1068module_exit(tps_exit);
1069
diff --git a/drivers/i2c/chips/via686a.c b/drivers/i2c/chips/via686a.c
deleted file mode 100644
index 6614a59cecd4..000000000000
--- a/drivers/i2c/chips/via686a.c
+++ /dev/null
@@ -1,878 +0,0 @@
1/*
2 via686a.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
6 Kyösti Mälkki <kmalkki@cc.hut.fi>,
7 Mark Studebaker <mdsxyz123@yahoo.com>,
8 and Bob Dougherty <bobd@stanford.edu>
9 (Some conversion-factor data were contributed by Jonathan Teh Soon Yew
10 <j.teh@iname.com> and Alex van Kaam <darkside@chello.nl>.)
11
12 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
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/
26
27/*
28 Supports the Via VT82C686A, VT82C686B south bridges.
29 Reports all as a 686A.
30 Warning - only supports a single device.
31*/
32
33#include <linux/config.h>
34#include <linux/module.h>
35#include <linux/slab.h>
36#include <linux/pci.h>
37#include <linux/delay.h>
38#include <linux/jiffies.h>
39#include <linux/i2c.h>
40#include <linux/i2c-sensor.h>
41#include <linux/init.h>
42#include <asm/io.h>
43
44
45/* If force_addr is set to anything different from 0, we forcibly enable
46 the device at the given address. */
47static unsigned short force_addr = 0;
48module_param(force_addr, ushort, 0);
49MODULE_PARM_DESC(force_addr,
50 "Initialize the base address of the sensors");
51
52/* Addresses to scan.
53 Note that we can't determine the ISA address until we have initialized
54 our module */
55static unsigned short normal_i2c[] = { I2C_CLIENT_END };
56static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END };
57
58/* Insmod parameters */
59SENSORS_INSMOD_1(via686a);
60
61/*
62 The Via 686a southbridge has a LM78-like chip integrated on the same IC.
63 This driver is a customized copy of lm78.c
64*/
65
66/* Many VIA686A constants specified below */
67
68/* Length of ISA address segment */
69#define VIA686A_EXTENT 0x80
70#define VIA686A_BASE_REG 0x70
71#define VIA686A_ENABLE_REG 0x74
72
73/* The VIA686A registers */
74/* ins numbered 0-4 */
75#define VIA686A_REG_IN_MAX(nr) (0x2b + ((nr) * 2))
76#define VIA686A_REG_IN_MIN(nr) (0x2c + ((nr) * 2))
77#define VIA686A_REG_IN(nr) (0x22 + (nr))
78
79/* fans numbered 1-2 */
80#define VIA686A_REG_FAN_MIN(nr) (0x3a + (nr))
81#define VIA686A_REG_FAN(nr) (0x28 + (nr))
82
83/* the following values are as speced by VIA: */
84static const u8 regtemp[] = { 0x20, 0x21, 0x1f };
85static const u8 regover[] = { 0x39, 0x3d, 0x1d };
86static const u8 reghyst[] = { 0x3a, 0x3e, 0x1e };
87
88/* temps numbered 1-3 */
89#define VIA686A_REG_TEMP(nr) (regtemp[nr])
90#define VIA686A_REG_TEMP_OVER(nr) (regover[nr])
91#define VIA686A_REG_TEMP_HYST(nr) (reghyst[nr])
92#define VIA686A_REG_TEMP_LOW1 0x4b // bits 7-6
93#define VIA686A_REG_TEMP_LOW23 0x49 // 2 = bits 5-4, 3 = bits 7-6
94
95#define VIA686A_REG_ALARM1 0x41
96#define VIA686A_REG_ALARM2 0x42
97#define VIA686A_REG_FANDIV 0x47
98#define VIA686A_REG_CONFIG 0x40
99/* The following register sets temp interrupt mode (bits 1-0 for temp1,
100 3-2 for temp2, 5-4 for temp3). Modes are:
101 00 interrupt stays as long as value is out-of-range
102 01 interrupt is cleared once register is read (default)
103 10 comparator mode- like 00, but ignores hysteresis
104 11 same as 00 */
105#define VIA686A_REG_TEMP_MODE 0x4b
106/* We'll just assume that you want to set all 3 simultaneously: */
107#define VIA686A_TEMP_MODE_MASK 0x3F
108#define VIA686A_TEMP_MODE_CONTINUOUS (0x00)
109
110/* Conversions. Limit checking is only done on the TO_REG
111 variants.
112
113********* VOLTAGE CONVERSIONS (Bob Dougherty) ********
114 From HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew):
115 voltagefactor[0]=1.25/2628; (2628/1.25=2102.4) // Vccp
116 voltagefactor[1]=1.25/2628; (2628/1.25=2102.4) // +2.5V
117 voltagefactor[2]=1.67/2628; (2628/1.67=1573.7) // +3.3V
118 voltagefactor[3]=2.6/2628; (2628/2.60=1010.8) // +5V
119 voltagefactor[4]=6.3/2628; (2628/6.30=417.14) // +12V
120 in[i]=(data[i+2]*25.0+133)*voltagefactor[i];
121 That is:
122 volts = (25*regVal+133)*factor
123 regVal = (volts/factor-133)/25
124 (These conversions were contributed by Jonathan Teh Soon Yew
125 <j.teh@iname.com>) */
126static inline u8 IN_TO_REG(long val, int inNum)
127{
128 /* To avoid floating point, we multiply constants by 10 (100 for +12V).
129 Rounding is done (120500 is actually 133000 - 12500).
130 Remember that val is expressed in 0.001V/bit, which is why we divide
131 by an additional 10000 (100000 for +12V): 1000 for val and 10 (100)
132 for the constants. */
133 if (inNum <= 1)
134 return (u8)
135 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255);
136 else if (inNum == 2)
137 return (u8)
138 SENSORS_LIMIT((val * 15737 - 1205000) / 250000, 0, 255);
139 else if (inNum == 3)
140 return (u8)
141 SENSORS_LIMIT((val * 10108 - 1205000) / 250000, 0, 255);
142 else
143 return (u8)
144 SENSORS_LIMIT((val * 41714 - 12050000) / 2500000, 0, 255);
145}
146
147static inline long IN_FROM_REG(u8 val, int inNum)
148{
149 /* To avoid floating point, we multiply constants by 10 (100 for +12V).
150 We also multiply them by 1000 because we want 0.001V/bit for the
151 output value. Rounding is done. */
152 if (inNum <= 1)
153 return (long) ((250000 * val + 1330000 + 21024 / 2) / 21024);
154 else if (inNum == 2)
155 return (long) ((250000 * val + 1330000 + 15737 / 2) / 15737);
156 else if (inNum == 3)
157 return (long) ((250000 * val + 1330000 + 10108 / 2) / 10108);
158 else
159 return (long) ((2500000 * val + 13300000 + 41714 / 2) / 41714);
160}
161
162/********* FAN RPM CONVERSIONS ********/
163/* Higher register values = slower fans (the fan's strobe gates a counter).
164 But this chip saturates back at 0, not at 255 like all the other chips.
165 So, 0 means 0 RPM */
166static inline u8 FAN_TO_REG(long rpm, int div)
167{
168 if (rpm == 0)
169 return 0;
170 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
171 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 255);
172}
173
174#define FAN_FROM_REG(val,div) ((val)==0?0:(val)==255?0:1350000/((val)*(div)))
175
176/******** TEMP CONVERSIONS (Bob Dougherty) *********/
177/* linear fits from HWMon.cpp (Copyright 1998-2000 Jonathan Teh Soon Yew)
178 if(temp<169)
179 return double(temp)*0.427-32.08;
180 else if(temp>=169 && temp<=202)
181 return double(temp)*0.582-58.16;
182 else
183 return double(temp)*0.924-127.33;
184
185 A fifth-order polynomial fits the unofficial data (provided by Alex van
186 Kaam <darkside@chello.nl>) a bit better. It also give more reasonable
187 numbers on my machine (ie. they agree with what my BIOS tells me).
188 Here's the fifth-order fit to the 8-bit data:
189 temp = 1.625093e-10*val^5 - 1.001632e-07*val^4 + 2.457653e-05*val^3 -
190 2.967619e-03*val^2 + 2.175144e-01*val - 7.090067e+0.
191
192 (2000-10-25- RFD: thanks to Uwe Andersen <uandersen@mayah.com> for
193 finding my typos in this formula!)
194
195 Alas, none of the elegant function-fit solutions will work because we
196 aren't allowed to use floating point in the kernel and doing it with
197 integers doesn't rpovide enough precision. So we'll do boring old
198 look-up table stuff. The unofficial data (see below) have effectively
199 7-bit resolution (they are rounded to the nearest degree). I'm assuming
200 that the transfer function of the device is monotonic and smooth, so a
201 smooth function fit to the data will allow us to get better precision.
202 I used the 5th-order poly fit described above and solved for
203 VIA register values 0-255. I *10 before rounding, so we get tenth-degree
204 precision. (I could have done all 1024 values for our 10-bit readings,
205 but the function is very linear in the useful range (0-80 deg C), so
206 we'll just use linear interpolation for 10-bit readings.) So, tempLUT
207 is the temp at via register values 0-255: */
208static const long tempLUT[] =
209 { -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519,
210 -503, -487, -471, -456, -442, -428, -414, -400, -387, -375,
211 -362, -350, -339, -327, -316, -305, -295, -285, -275, -265,
212 -255, -246, -237, -229, -220, -212, -204, -196, -188, -180,
213 -173, -166, -159, -152, -145, -139, -132, -126, -120, -114,
214 -108, -102, -96, -91, -85, -80, -74, -69, -64, -59, -54, -49,
215 -44, -39, -34, -29, -25, -20, -15, -11, -6, -2, 3, 7, 12, 16,
216 20, 25, 29, 33, 37, 42, 46, 50, 54, 59, 63, 67, 71, 75, 79, 84,
217 88, 92, 96, 100, 104, 109, 113, 117, 121, 125, 130, 134, 138,
218 142, 146, 151, 155, 159, 163, 168, 172, 176, 181, 185, 189,
219 193, 198, 202, 206, 211, 215, 219, 224, 228, 232, 237, 241,
220 245, 250, 254, 259, 263, 267, 272, 276, 281, 285, 290, 294,
221 299, 303, 307, 312, 316, 321, 325, 330, 334, 339, 344, 348,
222 353, 357, 362, 366, 371, 376, 380, 385, 390, 395, 399, 404,
223 409, 414, 419, 423, 428, 433, 438, 443, 449, 454, 459, 464,
224 469, 475, 480, 486, 491, 497, 502, 508, 514, 520, 526, 532,
225 538, 544, 551, 557, 564, 571, 578, 584, 592, 599, 606, 614,
226 621, 629, 637, 645, 654, 662, 671, 680, 689, 698, 708, 718,
227 728, 738, 749, 759, 770, 782, 793, 805, 818, 830, 843, 856,
228 870, 883, 898, 912, 927, 943, 958, 975, 991, 1008, 1026, 1044,
229 1062, 1081, 1101, 1121, 1141, 1162, 1184, 1206, 1229, 1252,
230 1276, 1301, 1326, 1352, 1378, 1406, 1434, 1462
231};
232
233/* the original LUT values from Alex van Kaam <darkside@chello.nl>
234 (for via register values 12-240):
235{-50,-49,-47,-45,-43,-41,-39,-38,-37,-35,-34,-33,-32,-31,
236-30,-29,-28,-27,-26,-25,-24,-24,-23,-22,-21,-20,-20,-19,-18,-17,-17,-16,-15,
237-15,-14,-14,-13,-12,-12,-11,-11,-10,-9,-9,-8,-8,-7,-7,-6,-6,-5,-5,-4,-4,-3,
238-3,-2,-2,-1,-1,0,0,1,1,1,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,9,10,10,11,11,12,
23912,12,13,13,13,14,14,15,15,16,16,16,17,17,18,18,19,19,20,20,21,21,21,22,22,
24022,23,23,24,24,25,25,26,26,26,27,27,27,28,28,29,29,30,30,30,31,31,32,32,33,
24133,34,34,35,35,35,36,36,37,37,38,38,39,39,40,40,41,41,42,42,43,43,44,44,45,
24245,46,46,47,48,48,49,49,50,51,51,52,52,53,53,54,55,55,56,57,57,58,59,59,60,
24361,62,62,63,64,65,66,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84,
24485,86,88,89,91,92,94,96,97,99,101,103,105,107,109,110};
245
246
247 Here's the reverse LUT. I got it by doing a 6-th order poly fit (needed
248 an extra term for a good fit to these inverse data!) and then
249 solving for each temp value from -50 to 110 (the useable range for
250 this chip). Here's the fit:
251 viaRegVal = -1.160370e-10*val^6 +3.193693e-08*val^5 - 1.464447e-06*val^4
252 - 2.525453e-04*val^3 + 1.424593e-02*val^2 + 2.148941e+00*val +7.275808e+01)
253 Note that n=161: */
254static const u8 viaLUT[] =
255 { 12, 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23,
256 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40,
257 41, 43, 45, 46, 48, 49, 51, 53, 55, 57, 59, 60, 62, 64, 66,
258 69, 71, 73, 75, 77, 79, 82, 84, 86, 88, 91, 93, 95, 98, 100,
259 103, 105, 107, 110, 112, 115, 117, 119, 122, 124, 126, 129,
260 131, 134, 136, 138, 140, 143, 145, 147, 150, 152, 154, 156,
261 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180,
262 182, 183, 185, 187, 188, 190, 192, 193, 195, 196, 198, 199,
263 200, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213,
264 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224,
265 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232,
266 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239,
267 239, 240
268};
269
270/* Converting temps to (8-bit) hyst and over registers
271 No interpolation here.
272 The +50 is because the temps start at -50 */
273static inline u8 TEMP_TO_REG(long val)
274{
275 return viaLUT[val <= -50000 ? 0 : val >= 110000 ? 160 :
276 (val < 0 ? val - 500 : val + 500) / 1000 + 50];
277}
278
279/* for 8-bit temperature hyst and over registers */
280#define TEMP_FROM_REG(val) (tempLUT[(val)] * 100)
281
282/* for 10-bit temperature readings */
283static inline long TEMP_FROM_REG10(u16 val)
284{
285 u16 eightBits = val >> 2;
286 u16 twoBits = val & 3;
287
288 /* no interpolation for these */
289 if (twoBits == 0 || eightBits == 255)
290 return TEMP_FROM_REG(eightBits);
291
292 /* do some linear interpolation */
293 return (tempLUT[eightBits] * (4 - twoBits) +
294 tempLUT[eightBits + 1] * twoBits) * 25;
295}
296
297#define ALARMS_FROM_REG(val) (val)
298
299#define DIV_FROM_REG(val) (1 << (val))
300#define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1)
301
302/* For the VIA686A, we need to keep some data in memory.
303 The structure is dynamically allocated, at the same time when a new
304 via686a client is allocated. */
305struct via686a_data {
306 struct i2c_client client;
307 struct semaphore update_lock;
308 char valid; /* !=0 if following fields are valid */
309 unsigned long last_updated; /* In jiffies */
310
311 u8 in[5]; /* Register value */
312 u8 in_max[5]; /* Register value */
313 u8 in_min[5]; /* Register value */
314 u8 fan[2]; /* Register value */
315 u8 fan_min[2]; /* Register value */
316 u16 temp[3]; /* Register value 10 bit */
317 u8 temp_over[3]; /* Register value */
318 u8 temp_hyst[3]; /* Register value */
319 u8 fan_div[2]; /* Register encoding, shifted right */
320 u16 alarms; /* Register encoding, combined */
321};
322
323static struct pci_dev *s_bridge; /* pointer to the (only) via686a */
324
325static int via686a_attach_adapter(struct i2c_adapter *adapter);
326static int via686a_detect(struct i2c_adapter *adapter, int address, int kind);
327static int via686a_detach_client(struct i2c_client *client);
328
329static inline int via686a_read_value(struct i2c_client *client, u8 reg)
330{
331 return (inb_p(client->addr + reg));
332}
333
334static inline void via686a_write_value(struct i2c_client *client, u8 reg,
335 u8 value)
336{
337 outb_p(value, client->addr + reg);
338}
339
340static struct via686a_data *via686a_update_device(struct device *dev);
341static void via686a_init_client(struct i2c_client *client);
342
343/* following are the sysfs callback functions */
344
345/* 7 voltage sensors */
346static ssize_t show_in(struct device *dev, char *buf, int nr) {
347 struct via686a_data *data = via686a_update_device(dev);
348 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in[nr], nr));
349}
350
351static ssize_t show_in_min(struct device *dev, char *buf, int nr) {
352 struct via686a_data *data = via686a_update_device(dev);
353 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_min[nr], nr));
354}
355
356static ssize_t show_in_max(struct device *dev, char *buf, int nr) {
357 struct via686a_data *data = via686a_update_device(dev);
358 return sprintf(buf, "%ld\n", IN_FROM_REG(data->in_max[nr], nr));
359}
360
361static ssize_t set_in_min(struct device *dev, const char *buf,
362 size_t count, int nr) {
363 struct i2c_client *client = to_i2c_client(dev);
364 struct via686a_data *data = i2c_get_clientdata(client);
365 unsigned long val = simple_strtoul(buf, NULL, 10);
366
367 down(&data->update_lock);
368 data->in_min[nr] = IN_TO_REG(val,nr);
369 via686a_write_value(client, VIA686A_REG_IN_MIN(nr),
370 data->in_min[nr]);
371 up(&data->update_lock);
372 return count;
373}
374static ssize_t set_in_max(struct device *dev, const char *buf,
375 size_t count, int nr) {
376 struct i2c_client *client = to_i2c_client(dev);
377 struct via686a_data *data = i2c_get_clientdata(client);
378 unsigned long val = simple_strtoul(buf, NULL, 10);
379
380 down(&data->update_lock);
381 data->in_max[nr] = IN_TO_REG(val,nr);
382 via686a_write_value(client, VIA686A_REG_IN_MAX(nr),
383 data->in_max[nr]);
384 up(&data->update_lock);
385 return count;
386}
387#define show_in_offset(offset) \
388static ssize_t \
389 show_in##offset (struct device *dev, char *buf) \
390{ \
391 return show_in(dev, buf, offset); \
392} \
393static ssize_t \
394 show_in##offset##_min (struct device *dev, char *buf) \
395{ \
396 return show_in_min(dev, buf, offset); \
397} \
398static ssize_t \
399 show_in##offset##_max (struct device *dev, char *buf) \
400{ \
401 return show_in_max(dev, buf, offset); \
402} \
403static ssize_t set_in##offset##_min (struct device *dev, \
404 const char *buf, size_t count) \
405{ \
406 return set_in_min(dev, buf, count, offset); \
407} \
408static ssize_t set_in##offset##_max (struct device *dev, \
409 const char *buf, size_t count) \
410{ \
411 return set_in_max(dev, buf, count, offset); \
412} \
413static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);\
414static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
415 show_in##offset##_min, set_in##offset##_min); \
416static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
417 show_in##offset##_max, set_in##offset##_max);
418
419show_in_offset(0);
420show_in_offset(1);
421show_in_offset(2);
422show_in_offset(3);
423show_in_offset(4);
424
425/* 3 temperatures */
426static ssize_t show_temp(struct device *dev, char *buf, int nr) {
427 struct via686a_data *data = via686a_update_device(dev);
428 return sprintf(buf, "%ld\n", TEMP_FROM_REG10(data->temp[nr]));
429}
430static ssize_t show_temp_over(struct device *dev, char *buf, int nr) {
431 struct via686a_data *data = via686a_update_device(dev);
432 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_over[nr]));
433}
434static ssize_t show_temp_hyst(struct device *dev, char *buf, int nr) {
435 struct via686a_data *data = via686a_update_device(dev);
436 return sprintf(buf, "%ld\n", TEMP_FROM_REG(data->temp_hyst[nr]));
437}
438static ssize_t set_temp_over(struct device *dev, const char *buf,
439 size_t count, int nr) {
440 struct i2c_client *client = to_i2c_client(dev);
441 struct via686a_data *data = i2c_get_clientdata(client);
442 int val = simple_strtol(buf, NULL, 10);
443
444 down(&data->update_lock);
445 data->temp_over[nr] = TEMP_TO_REG(val);
446 via686a_write_value(client, VIA686A_REG_TEMP_OVER(nr), data->temp_over[nr]);
447 up(&data->update_lock);
448 return count;
449}
450static ssize_t set_temp_hyst(struct device *dev, const char *buf,
451 size_t count, int nr) {
452 struct i2c_client *client = to_i2c_client(dev);
453 struct via686a_data *data = i2c_get_clientdata(client);
454 int val = simple_strtol(buf, NULL, 10);
455
456 down(&data->update_lock);
457 data->temp_hyst[nr] = TEMP_TO_REG(val);
458 via686a_write_value(client, VIA686A_REG_TEMP_HYST(nr), data->temp_hyst[nr]);
459 up(&data->update_lock);
460 return count;
461}
462#define show_temp_offset(offset) \
463static ssize_t show_temp_##offset (struct device *dev, char *buf) \
464{ \
465 return show_temp(dev, buf, offset - 1); \
466} \
467static ssize_t \
468show_temp_##offset##_over (struct device *dev, char *buf) \
469{ \
470 return show_temp_over(dev, buf, offset - 1); \
471} \
472static ssize_t \
473show_temp_##offset##_hyst (struct device *dev, char *buf) \
474{ \
475 return show_temp_hyst(dev, buf, offset - 1); \
476} \
477static ssize_t set_temp_##offset##_over (struct device *dev, \
478 const char *buf, size_t count) \
479{ \
480 return set_temp_over(dev, buf, count, offset - 1); \
481} \
482static ssize_t set_temp_##offset##_hyst (struct device *dev, \
483 const char *buf, size_t count) \
484{ \
485 return set_temp_hyst(dev, buf, count, offset - 1); \
486} \
487static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset, NULL);\
488static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
489 show_temp_##offset##_over, set_temp_##offset##_over); \
490static DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
491 show_temp_##offset##_hyst, set_temp_##offset##_hyst);
492
493show_temp_offset(1);
494show_temp_offset(2);
495show_temp_offset(3);
496
497/* 2 Fans */
498static ssize_t show_fan(struct device *dev, char *buf, int nr) {
499 struct via686a_data *data = via686a_update_device(dev);
500 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
501 DIV_FROM_REG(data->fan_div[nr])) );
502}
503static ssize_t show_fan_min(struct device *dev, char *buf, int nr) {
504 struct via686a_data *data = via686a_update_device(dev);
505 return sprintf(buf,"%d\n",
506 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])) );
507}
508static ssize_t show_fan_div(struct device *dev, char *buf, int nr) {
509 struct via686a_data *data = via686a_update_device(dev);
510 return sprintf(buf,"%d\n", DIV_FROM_REG(data->fan_div[nr]) );
511}
512static ssize_t set_fan_min(struct device *dev, const char *buf,
513 size_t count, int nr) {
514 struct i2c_client *client = to_i2c_client(dev);
515 struct via686a_data *data = i2c_get_clientdata(client);
516 int val = simple_strtol(buf, NULL, 10);
517
518 down(&data->update_lock);
519 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
520 via686a_write_value(client, VIA686A_REG_FAN_MIN(nr+1), data->fan_min[nr]);
521 up(&data->update_lock);
522 return count;
523}
524static ssize_t set_fan_div(struct device *dev, const char *buf,
525 size_t count, int nr) {
526 struct i2c_client *client = to_i2c_client(dev);
527 struct via686a_data *data = i2c_get_clientdata(client);
528 int val = simple_strtol(buf, NULL, 10);
529 int old;
530
531 down(&data->update_lock);
532 old = via686a_read_value(client, VIA686A_REG_FANDIV);
533 data->fan_div[nr] = DIV_TO_REG(val);
534 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
535 via686a_write_value(client, VIA686A_REG_FANDIV, old);
536 up(&data->update_lock);
537 return count;
538}
539
540#define show_fan_offset(offset) \
541static ssize_t show_fan_##offset (struct device *dev, char *buf) \
542{ \
543 return show_fan(dev, buf, offset - 1); \
544} \
545static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
546{ \
547 return show_fan_min(dev, buf, offset - 1); \
548} \
549static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
550{ \
551 return show_fan_div(dev, buf, offset - 1); \
552} \
553static ssize_t set_fan_##offset##_min (struct device *dev, \
554 const char *buf, size_t count) \
555{ \
556 return set_fan_min(dev, buf, count, offset - 1); \
557} \
558static ssize_t set_fan_##offset##_div (struct device *dev, \
559 const char *buf, size_t count) \
560{ \
561 return set_fan_div(dev, buf, count, offset - 1); \
562} \
563static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
564static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
565 show_fan_##offset##_min, set_fan_##offset##_min); \
566static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
567 show_fan_##offset##_div, set_fan_##offset##_div);
568
569show_fan_offset(1);
570show_fan_offset(2);
571
572/* Alarms */
573static ssize_t show_alarms(struct device *dev, char *buf) {
574 struct via686a_data *data = via686a_update_device(dev);
575 return sprintf(buf,"%d\n", ALARMS_FROM_REG(data->alarms));
576}
577static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
578
579/* The driver. I choose to use type i2c_driver, as at is identical to both
580 smbus_driver and isa_driver, and clients could be of either kind */
581static struct i2c_driver via686a_driver = {
582 .owner = THIS_MODULE,
583 .name = "via686a",
584 .id = I2C_DRIVERID_VIA686A,
585 .flags = I2C_DF_NOTIFY,
586 .attach_adapter = via686a_attach_adapter,
587 .detach_client = via686a_detach_client,
588};
589
590
591/* This is called when the module is loaded */
592static int via686a_attach_adapter(struct i2c_adapter *adapter)
593{
594 if (!(adapter->class & I2C_CLASS_HWMON))
595 return 0;
596 return i2c_detect(adapter, &addr_data, via686a_detect);
597}
598
599static int via686a_detect(struct i2c_adapter *adapter, int address, int kind)
600{
601 struct i2c_client *new_client;
602 struct via686a_data *data;
603 int err = 0;
604 const char client_name[] = "via686a";
605 u16 val;
606
607 /* Make sure we are probing the ISA bus!! */
608 if (!i2c_is_isa_adapter(adapter)) {
609 dev_err(&adapter->dev,
610 "via686a_detect called for an I2C bus adapter?!?\n");
611 return 0;
612 }
613
614 /* 8231 requires multiple of 256, we enforce that on 686 as well */
615 if(force_addr)
616 address = force_addr & 0xFF00;
617
618 if(force_addr) {
619 dev_warn(&adapter->dev,"forcing ISA address 0x%04X\n", address);
620 if (PCIBIOS_SUCCESSFUL !=
621 pci_write_config_word(s_bridge, VIA686A_BASE_REG, address))
622 return -ENODEV;
623 }
624 if (PCIBIOS_SUCCESSFUL !=
625 pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val))
626 return -ENODEV;
627 if (!(val & 0x0001)) {
628 dev_warn(&adapter->dev,"enabling sensors\n");
629 if (PCIBIOS_SUCCESSFUL !=
630 pci_write_config_word(s_bridge, VIA686A_ENABLE_REG,
631 val | 0x0001))
632 return -ENODEV;
633 }
634
635 /* Reserve the ISA region */
636 if (!request_region(address, VIA686A_EXTENT, via686a_driver.name)) {
637 dev_err(&adapter->dev,"region 0x%x already in use!\n",
638 address);
639 return -ENODEV;
640 }
641
642 if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) {
643 err = -ENOMEM;
644 goto ERROR0;
645 }
646 memset(data, 0, sizeof(struct via686a_data));
647
648 new_client = &data->client;
649 i2c_set_clientdata(new_client, data);
650 new_client->addr = address;
651 new_client->adapter = adapter;
652 new_client->driver = &via686a_driver;
653 new_client->flags = 0;
654
655 /* Fill in the remaining client fields and put into the global list */
656 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
657
658 data->valid = 0;
659 init_MUTEX(&data->update_lock);
660 /* Tell the I2C layer a new client has arrived */
661 if ((err = i2c_attach_client(new_client)))
662 goto ERROR3;
663
664 /* Initialize the VIA686A chip */
665 via686a_init_client(new_client);
666
667 /* Register sysfs hooks */
668 device_create_file(&new_client->dev, &dev_attr_in0_input);
669 device_create_file(&new_client->dev, &dev_attr_in1_input);
670 device_create_file(&new_client->dev, &dev_attr_in2_input);
671 device_create_file(&new_client->dev, &dev_attr_in3_input);
672 device_create_file(&new_client->dev, &dev_attr_in4_input);
673 device_create_file(&new_client->dev, &dev_attr_in0_min);
674 device_create_file(&new_client->dev, &dev_attr_in1_min);
675 device_create_file(&new_client->dev, &dev_attr_in2_min);
676 device_create_file(&new_client->dev, &dev_attr_in3_min);
677 device_create_file(&new_client->dev, &dev_attr_in4_min);
678 device_create_file(&new_client->dev, &dev_attr_in0_max);
679 device_create_file(&new_client->dev, &dev_attr_in1_max);
680 device_create_file(&new_client->dev, &dev_attr_in2_max);
681 device_create_file(&new_client->dev, &dev_attr_in3_max);
682 device_create_file(&new_client->dev, &dev_attr_in4_max);
683 device_create_file(&new_client->dev, &dev_attr_temp1_input);
684 device_create_file(&new_client->dev, &dev_attr_temp2_input);
685 device_create_file(&new_client->dev, &dev_attr_temp3_input);
686 device_create_file(&new_client->dev, &dev_attr_temp1_max);
687 device_create_file(&new_client->dev, &dev_attr_temp2_max);
688 device_create_file(&new_client->dev, &dev_attr_temp3_max);
689 device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
690 device_create_file(&new_client->dev, &dev_attr_temp2_max_hyst);
691 device_create_file(&new_client->dev, &dev_attr_temp3_max_hyst);
692 device_create_file(&new_client->dev, &dev_attr_fan1_input);
693 device_create_file(&new_client->dev, &dev_attr_fan2_input);
694 device_create_file(&new_client->dev, &dev_attr_fan1_min);
695 device_create_file(&new_client->dev, &dev_attr_fan2_min);
696 device_create_file(&new_client->dev, &dev_attr_fan1_div);
697 device_create_file(&new_client->dev, &dev_attr_fan2_div);
698 device_create_file(&new_client->dev, &dev_attr_alarms);
699
700 return 0;
701
702 ERROR3:
703 kfree(data);
704 ERROR0:
705 release_region(address, VIA686A_EXTENT);
706 return err;
707}
708
709static int via686a_detach_client(struct i2c_client *client)
710{
711 int err;
712
713 if ((err = i2c_detach_client(client))) {
714 dev_err(&client->dev,
715 "Client deregistration failed, client not detached.\n");
716 return err;
717 }
718
719 release_region(client->addr, VIA686A_EXTENT);
720 kfree(i2c_get_clientdata(client));
721
722 return 0;
723}
724
725/* Called when we have found a new VIA686A. Set limits, etc. */
726static void via686a_init_client(struct i2c_client *client)
727{
728 u8 reg;
729
730 /* Start monitoring */
731 reg = via686a_read_value(client, VIA686A_REG_CONFIG);
732 via686a_write_value(client, VIA686A_REG_CONFIG, (reg|0x01)&0x7F);
733
734 /* Configure temp interrupt mode for continuous-interrupt operation */
735 via686a_write_value(client, VIA686A_REG_TEMP_MODE,
736 via686a_read_value(client, VIA686A_REG_TEMP_MODE) &
737 !(VIA686A_TEMP_MODE_MASK | VIA686A_TEMP_MODE_CONTINUOUS));
738}
739
740static struct via686a_data *via686a_update_device(struct device *dev)
741{
742 struct i2c_client *client = to_i2c_client(dev);
743 struct via686a_data *data = i2c_get_clientdata(client);
744 int i;
745
746 down(&data->update_lock);
747
748 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
749 || !data->valid) {
750 for (i = 0; i <= 4; i++) {
751 data->in[i] =
752 via686a_read_value(client, VIA686A_REG_IN(i));
753 data->in_min[i] = via686a_read_value(client,
754 VIA686A_REG_IN_MIN
755 (i));
756 data->in_max[i] =
757 via686a_read_value(client, VIA686A_REG_IN_MAX(i));
758 }
759 for (i = 1; i <= 2; i++) {
760 data->fan[i - 1] =
761 via686a_read_value(client, VIA686A_REG_FAN(i));
762 data->fan_min[i - 1] = via686a_read_value(client,
763 VIA686A_REG_FAN_MIN(i));
764 }
765 for (i = 0; i <= 2; i++) {
766 data->temp[i] = via686a_read_value(client,
767 VIA686A_REG_TEMP(i)) << 2;
768 data->temp_over[i] =
769 via686a_read_value(client,
770 VIA686A_REG_TEMP_OVER(i));
771 data->temp_hyst[i] =
772 via686a_read_value(client,
773 VIA686A_REG_TEMP_HYST(i));
774 }
775 /* add in lower 2 bits
776 temp1 uses bits 7-6 of VIA686A_REG_TEMP_LOW1
777 temp2 uses bits 5-4 of VIA686A_REG_TEMP_LOW23
778 temp3 uses bits 7-6 of VIA686A_REG_TEMP_LOW23
779 */
780 data->temp[0] |= (via686a_read_value(client,
781 VIA686A_REG_TEMP_LOW1)
782 & 0xc0) >> 6;
783 data->temp[1] |=
784 (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) &
785 0x30) >> 4;
786 data->temp[2] |=
787 (via686a_read_value(client, VIA686A_REG_TEMP_LOW23) &
788 0xc0) >> 6;
789
790 i = via686a_read_value(client, VIA686A_REG_FANDIV);
791 data->fan_div[0] = (i >> 4) & 0x03;
792 data->fan_div[1] = i >> 6;
793 data->alarms =
794 via686a_read_value(client,
795 VIA686A_REG_ALARM1) |
796 (via686a_read_value(client, VIA686A_REG_ALARM2) << 8);
797 data->last_updated = jiffies;
798 data->valid = 1;
799 }
800
801 up(&data->update_lock);
802
803 return data;
804}
805
806static struct pci_device_id via686a_pci_ids[] = {
807 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
808 { 0, }
809};
810
811MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
812
813static int __devinit via686a_pci_probe(struct pci_dev *dev,
814 const struct pci_device_id *id)
815{
816 u16 val;
817 int addr = 0;
818
819 if (PCIBIOS_SUCCESSFUL !=
820 pci_read_config_word(dev, VIA686A_BASE_REG, &val))
821 return -ENODEV;
822
823 addr = val & ~(VIA686A_EXTENT - 1);
824 if (addr == 0 && force_addr == 0) {
825 dev_err(&dev->dev,"base address not set - upgrade BIOS or use force_addr=0xaddr\n");
826 return -ENODEV;
827 }
828 if (force_addr)
829 addr = force_addr; /* so detect will get called */
830
831 if (!addr) {
832 dev_err(&dev->dev,"No Via 686A sensors found.\n");
833 return -ENODEV;
834 }
835 normal_isa[0] = addr;
836
837 s_bridge = pci_dev_get(dev);
838 if (i2c_add_driver(&via686a_driver)) {
839 pci_dev_put(s_bridge);
840 s_bridge = NULL;
841 }
842
843 /* Always return failure here. This is to allow other drivers to bind
844 * to this pci device. We don't really want to have control over the
845 * pci device, we only wanted to read as few register values from it.
846 */
847 return -ENODEV;
848}
849
850static struct pci_driver via686a_pci_driver = {
851 .name = "via686a",
852 .id_table = via686a_pci_ids,
853 .probe = via686a_pci_probe,
854};
855
856static int __init sm_via686a_init(void)
857{
858 return pci_register_driver(&via686a_pci_driver);
859}
860
861static void __exit sm_via686a_exit(void)
862{
863 pci_unregister_driver(&via686a_pci_driver);
864 if (s_bridge != NULL) {
865 i2c_del_driver(&via686a_driver);
866 pci_dev_put(s_bridge);
867 s_bridge = NULL;
868 }
869}
870
871MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>, "
872 "Mark Studebaker <mdsxyz123@yahoo.com> "
873 "and Bob Dougherty <bobd@stanford.edu>");
874MODULE_DESCRIPTION("VIA 686A Sensor device");
875MODULE_LICENSE("GPL");
876
877module_init(sm_via686a_init);
878module_exit(sm_via686a_exit);
diff --git a/drivers/i2c/chips/w83627hf.c b/drivers/i2c/chips/w83627hf.c
deleted file mode 100644
index b1da5ed696d3..000000000000
--- a/drivers/i2c/chips/w83627hf.c
+++ /dev/null
@@ -1,1511 +0,0 @@
1/*
2 w83627hf.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org>
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/*
25 Supports following chips:
26
27 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
28 w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC)
29 w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC)
30 w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC)
31 w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
32
33 For other winbond chips, and for i2c support in the above chips,
34 use w83781d.c.
35
36 Note: automatic ("cruise") fan control for 697, 637 & 627thf not
37 supported yet.
38*/
39
40#include <linux/module.h>
41#include <linux/init.h>
42#include <linux/slab.h>
43#include <linux/jiffies.h>
44#include <linux/i2c.h>
45#include <linux/i2c-sensor.h>
46#include <linux/i2c-vid.h>
47#include <asm/io.h>
48#include "lm75.h"
49
50static u16 force_addr;
51module_param(force_addr, ushort, 0);
52MODULE_PARM_DESC(force_addr,
53 "Initialize the base address of the sensors");
54static u8 force_i2c = 0x1f;
55module_param(force_i2c, byte, 0);
56MODULE_PARM_DESC(force_i2c,
57 "Initialize the i2c address of the sensors");
58
59/* Addresses to scan */
60static unsigned short normal_i2c[] = { I2C_CLIENT_END };
61static unsigned int normal_isa[] = { 0, I2C_CLIENT_ISA_END };
62
63/* Insmod parameters */
64SENSORS_INSMOD_4(w83627hf, w83627thf, w83697hf, w83637hf);
65
66static int init = 1;
67module_param(init, bool, 0);
68MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
69
70/* modified from kernel/include/traps.c */
71static int REG; /* The register to read/write */
72#define DEV 0x07 /* Register: Logical device select */
73static int VAL; /* The value to read/write */
74
75/* logical device numbers for superio_select (below) */
76#define W83627HF_LD_FDC 0x00
77#define W83627HF_LD_PRT 0x01
78#define W83627HF_LD_UART1 0x02
79#define W83627HF_LD_UART2 0x03
80#define W83627HF_LD_KBC 0x05
81#define W83627HF_LD_CIR 0x06 /* w83627hf only */
82#define W83627HF_LD_GAME 0x07
83#define W83627HF_LD_MIDI 0x07
84#define W83627HF_LD_GPIO1 0x07
85#define W83627HF_LD_GPIO5 0x07 /* w83627thf only */
86#define W83627HF_LD_GPIO2 0x08
87#define W83627HF_LD_GPIO3 0x09
88#define W83627HF_LD_GPIO4 0x09 /* w83627thf only */
89#define W83627HF_LD_ACPI 0x0a
90#define W83627HF_LD_HWM 0x0b
91
92#define DEVID 0x20 /* Register: Device ID */
93
94#define W83627THF_GPIO5_EN 0x30 /* w83627thf only */
95#define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */
96#define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */
97
98static inline void
99superio_outb(int reg, int val)
100{
101 outb(reg, REG);
102 outb(val, VAL);
103}
104
105static inline int
106superio_inb(int reg)
107{
108 outb(reg, REG);
109 return inb(VAL);
110}
111
112static inline void
113superio_select(int ld)
114{
115 outb(DEV, REG);
116 outb(ld, VAL);
117}
118
119static inline void
120superio_enter(void)
121{
122 outb(0x87, REG);
123 outb(0x87, REG);
124}
125
126static inline void
127superio_exit(void)
128{
129 outb(0xAA, REG);
130}
131
132#define W627_DEVID 0x52
133#define W627THF_DEVID 0x82
134#define W697_DEVID 0x60
135#define W637_DEVID 0x70
136#define WINB_ACT_REG 0x30
137#define WINB_BASE_REG 0x60
138/* Constants specified below */
139
140/* Length of ISA address segment */
141#define WINB_EXTENT 8
142
143/* Where are the ISA address/data registers relative to the base address */
144#define W83781D_ADDR_REG_OFFSET 5
145#define W83781D_DATA_REG_OFFSET 6
146
147/* The W83781D registers */
148/* The W83782D registers for nr=7,8 are in bank 5 */
149#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
150 (0x554 + (((nr) - 7) * 2)))
151#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
152 (0x555 + (((nr) - 7) * 2)))
153#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
154 (0x550 + (nr) - 7))
155
156#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr))
157#define W83781D_REG_FAN(nr) (0x27 + (nr))
158
159#define W83781D_REG_TEMP2_CONFIG 0x152
160#define W83781D_REG_TEMP3_CONFIG 0x252
161#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
162 ((nr == 2) ? (0x0150) : \
163 (0x27)))
164#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \
165 ((nr == 2) ? (0x153) : \
166 (0x3A)))
167#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
168 ((nr == 2) ? (0x155) : \
169 (0x39)))
170
171#define W83781D_REG_BANK 0x4E
172
173#define W83781D_REG_CONFIG 0x40
174#define W83781D_REG_ALARM1 0x41
175#define W83781D_REG_ALARM2 0x42
176#define W83781D_REG_ALARM3 0x450
177
178#define W83781D_REG_IRQ 0x4C
179#define W83781D_REG_BEEP_CONFIG 0x4D
180#define W83781D_REG_BEEP_INTS1 0x56
181#define W83781D_REG_BEEP_INTS2 0x57
182#define W83781D_REG_BEEP_INTS3 0x453
183
184#define W83781D_REG_VID_FANDIV 0x47
185
186#define W83781D_REG_CHIPID 0x49
187#define W83781D_REG_WCHIPID 0x58
188#define W83781D_REG_CHIPMAN 0x4F
189#define W83781D_REG_PIN 0x4B
190
191#define W83781D_REG_VBAT 0x5D
192
193#define W83627HF_REG_PWM1 0x5A
194#define W83627HF_REG_PWM2 0x5B
195#define W83627HF_REG_PWMCLK12 0x5C
196
197#define W83627THF_REG_PWM1 0x01 /* 697HF and 637HF too */
198#define W83627THF_REG_PWM2 0x03 /* 697HF and 637HF too */
199#define W83627THF_REG_PWM3 0x11 /* 637HF too */
200
201#define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF too */
202
203static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 };
204static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2,
205 W83627THF_REG_PWM3 };
206#define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \
207 regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1])
208
209#define W83781D_REG_I2C_ADDR 0x48
210#define W83781D_REG_I2C_SUBADDR 0x4A
211
212/* Sensor selection */
213#define W83781D_REG_SCFG1 0x5D
214static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
215#define W83781D_REG_SCFG2 0x59
216static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
217#define W83781D_DEFAULT_BETA 3435
218
219/* Conversions. Limit checking is only done on the TO_REG
220 variants. Note that you should be a bit careful with which arguments
221 these macros are called: arguments may be evaluated more than once.
222 Fixing this is just not worth it. */
223#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
224#define IN_FROM_REG(val) ((val) * 16)
225
226static inline u8 FAN_TO_REG(long rpm, int div)
227{
228 if (rpm == 0)
229 return 255;
230 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
231 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
232 254);
233}
234
235#define TEMP_MIN (-128000)
236#define TEMP_MAX ( 127000)
237
238/* TEMP: 0.001C/bit (-128C to +127C)
239 REG: 1C/bit, two's complement */
240static u8 TEMP_TO_REG(int temp)
241{
242 int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX);
243 ntemp += (ntemp<0 ? -500 : 500);
244 return (u8)(ntemp / 1000);
245}
246
247static int TEMP_FROM_REG(u8 reg)
248{
249 return (s8)reg * 1000;
250}
251
252#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
253
254#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255))
255
256#define BEEP_MASK_FROM_REG(val) (val)
257#define BEEP_MASK_TO_REG(val) ((val) & 0xffffff)
258#define BEEP_ENABLE_TO_REG(val) ((val)?1:0)
259#define BEEP_ENABLE_FROM_REG(val) ((val)?1:0)
260
261#define DIV_FROM_REG(val) (1 << (val))
262
263static inline u8 DIV_TO_REG(long val)
264{
265 int i;
266 val = SENSORS_LIMIT(val, 1, 128) >> 1;
267 for (i = 0; i < 6; i++) {
268 if (val == 0)
269 break;
270 val >>= 1;
271 }
272 return ((u8) i);
273}
274
275/* For each registered chip, we need to keep some data in memory. That
276 data is pointed to by w83627hf_list[NR]->data. The structure itself is
277 dynamically allocated, at the same time when a new client is allocated. */
278struct w83627hf_data {
279 struct i2c_client client;
280 struct semaphore lock;
281 enum chips type;
282
283 struct semaphore update_lock;
284 char valid; /* !=0 if following fields are valid */
285 unsigned long last_updated; /* In jiffies */
286
287 struct i2c_client *lm75; /* for secondary I2C addresses */
288 /* pointer to array of 2 subclients */
289
290 u8 in[9]; /* Register value */
291 u8 in_max[9]; /* Register value */
292 u8 in_min[9]; /* Register value */
293 u8 fan[3]; /* Register value */
294 u8 fan_min[3]; /* Register value */
295 u8 temp;
296 u8 temp_max; /* Register value */
297 u8 temp_max_hyst; /* Register value */
298 u16 temp_add[2]; /* Register value */
299 u16 temp_max_add[2]; /* Register value */
300 u16 temp_max_hyst_add[2]; /* Register value */
301 u8 fan_div[3]; /* Register encoding, shifted right */
302 u8 vid; /* Register encoding, combined */
303 u32 alarms; /* Register encoding, combined */
304 u32 beep_mask; /* Register encoding, combined */
305 u8 beep_enable; /* Boolean */
306 u8 pwm[3]; /* Register value */
307 u16 sens[3]; /* 782D/783S only.
308 1 = pentium diode; 2 = 3904 diode;
309 3000-5000 = thermistor beta.
310 Default = 3435.
311 Other Betas unimplemented */
312 u8 vrm;
313 u8 vrm_ovt; /* Register value, 627thf & 637hf only */
314};
315
316
317static int w83627hf_attach_adapter(struct i2c_adapter *adapter);
318static int w83627hf_detect(struct i2c_adapter *adapter, int address,
319 int kind);
320static int w83627hf_detach_client(struct i2c_client *client);
321
322static int w83627hf_read_value(struct i2c_client *client, u16 register);
323static int w83627hf_write_value(struct i2c_client *client, u16 register,
324 u16 value);
325static struct w83627hf_data *w83627hf_update_device(struct device *dev);
326static void w83627hf_init_client(struct i2c_client *client);
327
328static struct i2c_driver w83627hf_driver = {
329 .owner = THIS_MODULE,
330 .name = "w83627hf",
331 .id = I2C_DRIVERID_W83627HF,
332 .flags = I2C_DF_NOTIFY,
333 .attach_adapter = w83627hf_attach_adapter,
334 .detach_client = w83627hf_detach_client,
335};
336
337/* following are the sysfs callback functions */
338#define show_in_reg(reg) \
339static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
340{ \
341 struct w83627hf_data *data = w83627hf_update_device(dev); \
342 return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr])); \
343}
344show_in_reg(in)
345show_in_reg(in_min)
346show_in_reg(in_max)
347
348#define store_in_reg(REG, reg) \
349static ssize_t \
350store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
351{ \
352 struct i2c_client *client = to_i2c_client(dev); \
353 struct w83627hf_data *data = i2c_get_clientdata(client); \
354 u32 val; \
355 \
356 val = simple_strtoul(buf, NULL, 10); \
357 \
358 down(&data->update_lock); \
359 data->in_##reg[nr] = IN_TO_REG(val); \
360 w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \
361 data->in_##reg[nr]); \
362 \
363 up(&data->update_lock); \
364 return count; \
365}
366store_in_reg(MIN, min)
367store_in_reg(MAX, max)
368
369#define sysfs_in_offset(offset) \
370static ssize_t \
371show_regs_in_##offset (struct device *dev, char *buf) \
372{ \
373 return show_in(dev, buf, offset); \
374} \
375static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL);
376
377#define sysfs_in_reg_offset(reg, offset) \
378static ssize_t show_regs_in_##reg##offset (struct device *dev, char *buf) \
379{ \
380 return show_in_##reg (dev, buf, offset); \
381} \
382static ssize_t \
383store_regs_in_##reg##offset (struct device *dev, \
384 const char *buf, size_t count) \
385{ \
386 return store_in_##reg (dev, buf, count, offset); \
387} \
388static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, \
389 show_regs_in_##reg##offset, store_regs_in_##reg##offset);
390
391#define sysfs_in_offsets(offset) \
392sysfs_in_offset(offset) \
393sysfs_in_reg_offset(min, offset) \
394sysfs_in_reg_offset(max, offset)
395
396sysfs_in_offsets(1);
397sysfs_in_offsets(2);
398sysfs_in_offsets(3);
399sysfs_in_offsets(4);
400sysfs_in_offsets(5);
401sysfs_in_offsets(6);
402sysfs_in_offsets(7);
403sysfs_in_offsets(8);
404
405/* use a different set of functions for in0 */
406static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg)
407{
408 long in0;
409
410 if ((data->vrm_ovt & 0x01) &&
411 (w83627thf == data->type || w83637hf == data->type))
412
413 /* use VRM9 calculation */
414 in0 = (long)((reg * 488 + 70000 + 50) / 100);
415 else
416 /* use VRM8 (standard) calculation */
417 in0 = (long)IN_FROM_REG(reg);
418
419 return sprintf(buf,"%ld\n", in0);
420}
421
422static ssize_t show_regs_in_0(struct device *dev, char *buf)
423{
424 struct w83627hf_data *data = w83627hf_update_device(dev);
425 return show_in_0(data, buf, data->in[0]);
426}
427
428static ssize_t show_regs_in_min0(struct device *dev, char *buf)
429{
430 struct w83627hf_data *data = w83627hf_update_device(dev);
431 return show_in_0(data, buf, data->in_min[0]);
432}
433
434static ssize_t show_regs_in_max0(struct device *dev, char *buf)
435{
436 struct w83627hf_data *data = w83627hf_update_device(dev);
437 return show_in_0(data, buf, data->in_max[0]);
438}
439
440static ssize_t store_regs_in_min0(struct device *dev,
441 const char *buf, size_t count)
442{
443 struct i2c_client *client = to_i2c_client(dev);
444 struct w83627hf_data *data = i2c_get_clientdata(client);
445 u32 val;
446
447 val = simple_strtoul(buf, NULL, 10);
448
449 down(&data->update_lock);
450
451 if ((data->vrm_ovt & 0x01) &&
452 (w83627thf == data->type || w83637hf == data->type))
453
454 /* use VRM9 calculation */
455 data->in_min[0] = (u8)(((val * 100) - 70000 + 244) / 488);
456 else
457 /* use VRM8 (standard) calculation */
458 data->in_min[0] = IN_TO_REG(val);
459
460 w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]);
461 up(&data->update_lock);
462 return count;
463}
464
465static ssize_t store_regs_in_max0(struct device *dev,
466 const char *buf, size_t count)
467{
468 struct i2c_client *client = to_i2c_client(dev);
469 struct w83627hf_data *data = i2c_get_clientdata(client);
470 u32 val;
471
472 val = simple_strtoul(buf, NULL, 10);
473
474 down(&data->update_lock);
475
476 if ((data->vrm_ovt & 0x01) &&
477 (w83627thf == data->type || w83637hf == data->type))
478
479 /* use VRM9 calculation */
480 data->in_max[0] = (u8)(((val * 100) - 70000 + 244) / 488);
481 else
482 /* use VRM8 (standard) calculation */
483 data->in_max[0] = IN_TO_REG(val);
484
485 w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]);
486 up(&data->update_lock);
487 return count;
488}
489
490static DEVICE_ATTR(in0_input, S_IRUGO, show_regs_in_0, NULL);
491static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
492 show_regs_in_min0, store_regs_in_min0);
493static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
494 show_regs_in_max0, store_regs_in_max0);
495
496#define device_create_file_in(client, offset) \
497do { \
498device_create_file(&client->dev, &dev_attr_in##offset##_input); \
499device_create_file(&client->dev, &dev_attr_in##offset##_min); \
500device_create_file(&client->dev, &dev_attr_in##offset##_max); \
501} while (0)
502
503#define show_fan_reg(reg) \
504static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
505{ \
506 struct w83627hf_data *data = w83627hf_update_device(dev); \
507 return sprintf(buf,"%ld\n", \
508 FAN_FROM_REG(data->reg[nr-1], \
509 (long)DIV_FROM_REG(data->fan_div[nr-1]))); \
510}
511show_fan_reg(fan);
512show_fan_reg(fan_min);
513
514static ssize_t
515store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
516{
517 struct i2c_client *client = to_i2c_client(dev);
518 struct w83627hf_data *data = i2c_get_clientdata(client);
519 u32 val;
520
521 val = simple_strtoul(buf, NULL, 10);
522
523 down(&data->update_lock);
524 data->fan_min[nr - 1] =
525 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
526 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr),
527 data->fan_min[nr - 1]);
528
529 up(&data->update_lock);
530 return count;
531}
532
533#define sysfs_fan_offset(offset) \
534static ssize_t show_regs_fan_##offset (struct device *dev, char *buf) \
535{ \
536 return show_fan(dev, buf, offset); \
537} \
538static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL);
539
540#define sysfs_fan_min_offset(offset) \
541static ssize_t show_regs_fan_min##offset (struct device *dev, char *buf) \
542{ \
543 return show_fan_min(dev, buf, offset); \
544} \
545static ssize_t \
546store_regs_fan_min##offset (struct device *dev, const char *buf, size_t count) \
547{ \
548 return store_fan_min(dev, buf, count, offset); \
549} \
550static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
551 show_regs_fan_min##offset, store_regs_fan_min##offset);
552
553sysfs_fan_offset(1);
554sysfs_fan_min_offset(1);
555sysfs_fan_offset(2);
556sysfs_fan_min_offset(2);
557sysfs_fan_offset(3);
558sysfs_fan_min_offset(3);
559
560#define device_create_file_fan(client, offset) \
561do { \
562device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
563device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
564} while (0)
565
566#define show_temp_reg(reg) \
567static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
568{ \
569 struct w83627hf_data *data = w83627hf_update_device(dev); \
570 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
571 return sprintf(buf,"%ld\n", \
572 (long)LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
573 } else { /* TEMP1 */ \
574 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
575 } \
576}
577show_temp_reg(temp);
578show_temp_reg(temp_max);
579show_temp_reg(temp_max_hyst);
580
581#define store_temp_reg(REG, reg) \
582static ssize_t \
583store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
584{ \
585 struct i2c_client *client = to_i2c_client(dev); \
586 struct w83627hf_data *data = i2c_get_clientdata(client); \
587 u32 val; \
588 \
589 val = simple_strtoul(buf, NULL, 10); \
590 \
591 down(&data->update_lock); \
592 \
593 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
594 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
595 w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \
596 data->temp_##reg##_add[nr-2]); \
597 } else { /* TEMP1 */ \
598 data->temp_##reg = TEMP_TO_REG(val); \
599 w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \
600 data->temp_##reg); \
601 } \
602 \
603 up(&data->update_lock); \
604 return count; \
605}
606store_temp_reg(OVER, max);
607store_temp_reg(HYST, max_hyst);
608
609#define sysfs_temp_offset(offset) \
610static ssize_t \
611show_regs_temp_##offset (struct device *dev, char *buf) \
612{ \
613 return show_temp(dev, buf, offset); \
614} \
615static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL);
616
617#define sysfs_temp_reg_offset(reg, offset) \
618static ssize_t show_regs_temp_##reg##offset (struct device *dev, char *buf) \
619{ \
620 return show_temp_##reg (dev, buf, offset); \
621} \
622static ssize_t \
623store_regs_temp_##reg##offset (struct device *dev, \
624 const char *buf, size_t count) \
625{ \
626 return store_temp_##reg (dev, buf, count, offset); \
627} \
628static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \
629 show_regs_temp_##reg##offset, store_regs_temp_##reg##offset);
630
631#define sysfs_temp_offsets(offset) \
632sysfs_temp_offset(offset) \
633sysfs_temp_reg_offset(max, offset) \
634sysfs_temp_reg_offset(max_hyst, offset)
635
636sysfs_temp_offsets(1);
637sysfs_temp_offsets(2);
638sysfs_temp_offsets(3);
639
640#define device_create_file_temp(client, offset) \
641do { \
642device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
643device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
644device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
645} while (0)
646
647static ssize_t
648show_vid_reg(struct device *dev, char *buf)
649{
650 struct w83627hf_data *data = w83627hf_update_device(dev);
651 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
652}
653static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
654#define device_create_file_vid(client) \
655device_create_file(&client->dev, &dev_attr_cpu0_vid)
656
657static ssize_t
658show_vrm_reg(struct device *dev, char *buf)
659{
660 struct w83627hf_data *data = w83627hf_update_device(dev);
661 return sprintf(buf, "%ld\n", (long) data->vrm);
662}
663static ssize_t
664store_vrm_reg(struct device *dev, const char *buf, size_t count)
665{
666 struct i2c_client *client = to_i2c_client(dev);
667 struct w83627hf_data *data = i2c_get_clientdata(client);
668 u32 val;
669
670 val = simple_strtoul(buf, NULL, 10);
671 data->vrm = val;
672
673 return count;
674}
675static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
676#define device_create_file_vrm(client) \
677device_create_file(&client->dev, &dev_attr_vrm)
678
679static ssize_t
680show_alarms_reg(struct device *dev, char *buf)
681{
682 struct w83627hf_data *data = w83627hf_update_device(dev);
683 return sprintf(buf, "%ld\n", (long) data->alarms);
684}
685static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
686#define device_create_file_alarms(client) \
687device_create_file(&client->dev, &dev_attr_alarms)
688
689#define show_beep_reg(REG, reg) \
690static ssize_t show_beep_##reg (struct device *dev, char *buf) \
691{ \
692 struct w83627hf_data *data = w83627hf_update_device(dev); \
693 return sprintf(buf,"%ld\n", \
694 (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \
695}
696show_beep_reg(ENABLE, enable)
697show_beep_reg(MASK, mask)
698
699#define BEEP_ENABLE 0 /* Store beep_enable */
700#define BEEP_MASK 1 /* Store beep_mask */
701
702static ssize_t
703store_beep_reg(struct device *dev, const char *buf, size_t count,
704 int update_mask)
705{
706 struct i2c_client *client = to_i2c_client(dev);
707 struct w83627hf_data *data = i2c_get_clientdata(client);
708 u32 val, val2;
709
710 val = simple_strtoul(buf, NULL, 10);
711
712 down(&data->update_lock);
713
714 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
715 data->beep_mask = BEEP_MASK_TO_REG(val);
716 w83627hf_write_value(client, W83781D_REG_BEEP_INTS1,
717 data->beep_mask & 0xff);
718 w83627hf_write_value(client, W83781D_REG_BEEP_INTS3,
719 ((data->beep_mask) >> 16) & 0xff);
720 val2 = (data->beep_mask >> 8) & 0x7f;
721 } else { /* We are storing beep_enable */
722 val2 =
723 w83627hf_read_value(client, W83781D_REG_BEEP_INTS2) & 0x7f;
724 data->beep_enable = BEEP_ENABLE_TO_REG(val);
725 }
726
727 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2,
728 val2 | data->beep_enable << 7);
729
730 up(&data->update_lock);
731 return count;
732}
733
734#define sysfs_beep(REG, reg) \
735static ssize_t show_regs_beep_##reg (struct device *dev, char *buf) \
736{ \
737 return show_beep_##reg(dev, buf); \
738} \
739static ssize_t \
740store_regs_beep_##reg (struct device *dev, const char *buf, size_t count) \
741{ \
742 return store_beep_reg(dev, buf, count, BEEP_##REG); \
743} \
744static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
745 show_regs_beep_##reg, store_regs_beep_##reg);
746
747sysfs_beep(ENABLE, enable);
748sysfs_beep(MASK, mask);
749
750#define device_create_file_beep(client) \
751do { \
752device_create_file(&client->dev, &dev_attr_beep_enable); \
753device_create_file(&client->dev, &dev_attr_beep_mask); \
754} while (0)
755
756static ssize_t
757show_fan_div_reg(struct device *dev, char *buf, int nr)
758{
759 struct w83627hf_data *data = w83627hf_update_device(dev);
760 return sprintf(buf, "%ld\n",
761 (long) DIV_FROM_REG(data->fan_div[nr - 1]));
762}
763
764/* Note: we save and restore the fan minimum here, because its value is
765 determined in part by the fan divisor. This follows the principle of
766 least suprise; the user doesn't expect the fan minimum to change just
767 because the divisor changed. */
768static ssize_t
769store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
770{
771 struct i2c_client *client = to_i2c_client(dev);
772 struct w83627hf_data *data = i2c_get_clientdata(client);
773 unsigned long min;
774 u8 reg;
775 unsigned long val = simple_strtoul(buf, NULL, 10);
776
777 down(&data->update_lock);
778
779 /* Save fan_min */
780 min = FAN_FROM_REG(data->fan_min[nr],
781 DIV_FROM_REG(data->fan_div[nr]));
782
783 data->fan_div[nr] = DIV_TO_REG(val);
784
785 reg = (w83627hf_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
786 & (nr==0 ? 0xcf : 0x3f))
787 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
788 w83627hf_write_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
789
790 reg = (w83627hf_read_value(client, W83781D_REG_VBAT)
791 & ~(1 << (5 + nr)))
792 | ((data->fan_div[nr] & 0x04) << (3 + nr));
793 w83627hf_write_value(client, W83781D_REG_VBAT, reg);
794
795 /* Restore fan_min */
796 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
797 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
798
799 up(&data->update_lock);
800 return count;
801}
802
803#define sysfs_fan_div(offset) \
804static ssize_t show_regs_fan_div_##offset (struct device *dev, char *buf) \
805{ \
806 return show_fan_div_reg(dev, buf, offset); \
807} \
808static ssize_t \
809store_regs_fan_div_##offset (struct device *dev, \
810 const char *buf, size_t count) \
811{ \
812 return store_fan_div_reg(dev, buf, count, offset - 1); \
813} \
814static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
815 show_regs_fan_div_##offset, store_regs_fan_div_##offset);
816
817sysfs_fan_div(1);
818sysfs_fan_div(2);
819sysfs_fan_div(3);
820
821#define device_create_file_fan_div(client, offset) \
822do { \
823device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
824} while (0)
825
826static ssize_t
827show_pwm_reg(struct device *dev, char *buf, int nr)
828{
829 struct w83627hf_data *data = w83627hf_update_device(dev);
830 return sprintf(buf, "%ld\n", (long) data->pwm[nr - 1]);
831}
832
833static ssize_t
834store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
835{
836 struct i2c_client *client = to_i2c_client(dev);
837 struct w83627hf_data *data = i2c_get_clientdata(client);
838 u32 val;
839
840 val = simple_strtoul(buf, NULL, 10);
841
842 down(&data->update_lock);
843
844 if (data->type == w83627thf) {
845 /* bits 0-3 are reserved in 627THF */
846 data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0;
847 w83627hf_write_value(client,
848 W836X7HF_REG_PWM(data->type, nr),
849 data->pwm[nr - 1] |
850 (w83627hf_read_value(client,
851 W836X7HF_REG_PWM(data->type, nr)) & 0x0f));
852 } else {
853 data->pwm[nr - 1] = PWM_TO_REG(val);
854 w83627hf_write_value(client,
855 W836X7HF_REG_PWM(data->type, nr),
856 data->pwm[nr - 1]);
857 }
858
859 up(&data->update_lock);
860 return count;
861}
862
863#define sysfs_pwm(offset) \
864static ssize_t show_regs_pwm_##offset (struct device *dev, char *buf) \
865{ \
866 return show_pwm_reg(dev, buf, offset); \
867} \
868static ssize_t \
869store_regs_pwm_##offset (struct device *dev, const char *buf, size_t count) \
870{ \
871 return store_pwm_reg(dev, buf, count, offset); \
872} \
873static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
874 show_regs_pwm_##offset, store_regs_pwm_##offset);
875
876sysfs_pwm(1);
877sysfs_pwm(2);
878sysfs_pwm(3);
879
880#define device_create_file_pwm(client, offset) \
881do { \
882device_create_file(&client->dev, &dev_attr_pwm##offset); \
883} while (0)
884
885static ssize_t
886show_sensor_reg(struct device *dev, char *buf, int nr)
887{
888 struct w83627hf_data *data = w83627hf_update_device(dev);
889 return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]);
890}
891
892static ssize_t
893store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
894{
895 struct i2c_client *client = to_i2c_client(dev);
896 struct w83627hf_data *data = i2c_get_clientdata(client);
897 u32 val, tmp;
898
899 val = simple_strtoul(buf, NULL, 10);
900
901 down(&data->update_lock);
902
903 switch (val) {
904 case 1: /* PII/Celeron diode */
905 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
906 w83627hf_write_value(client, W83781D_REG_SCFG1,
907 tmp | BIT_SCFG1[nr - 1]);
908 tmp = w83627hf_read_value(client, W83781D_REG_SCFG2);
909 w83627hf_write_value(client, W83781D_REG_SCFG2,
910 tmp | BIT_SCFG2[nr - 1]);
911 data->sens[nr - 1] = val;
912 break;
913 case 2: /* 3904 */
914 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
915 w83627hf_write_value(client, W83781D_REG_SCFG1,
916 tmp | BIT_SCFG1[nr - 1]);
917 tmp = w83627hf_read_value(client, W83781D_REG_SCFG2);
918 w83627hf_write_value(client, W83781D_REG_SCFG2,
919 tmp & ~BIT_SCFG2[nr - 1]);
920 data->sens[nr - 1] = val;
921 break;
922 case W83781D_DEFAULT_BETA: /* thermistor */
923 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
924 w83627hf_write_value(client, W83781D_REG_SCFG1,
925 tmp & ~BIT_SCFG1[nr - 1]);
926 data->sens[nr - 1] = val;
927 break;
928 default:
929 dev_err(&client->dev,
930 "Invalid sensor type %ld; must be 1, 2, or %d\n",
931 (long) val, W83781D_DEFAULT_BETA);
932 break;
933 }
934
935 up(&data->update_lock);
936 return count;
937}
938
939#define sysfs_sensor(offset) \
940static ssize_t show_regs_sensor_##offset (struct device *dev, char *buf) \
941{ \
942 return show_sensor_reg(dev, buf, offset); \
943} \
944static ssize_t \
945store_regs_sensor_##offset (struct device *dev, const char *buf, size_t count) \
946{ \
947 return store_sensor_reg(dev, buf, count, offset); \
948} \
949static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
950 show_regs_sensor_##offset, store_regs_sensor_##offset);
951
952sysfs_sensor(1);
953sysfs_sensor(2);
954sysfs_sensor(3);
955
956#define device_create_file_sensor(client, offset) \
957do { \
958device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
959} while (0)
960
961
962/* This function is called when:
963 * w83627hf_driver is inserted (when this module is loaded), for each
964 available adapter
965 * when a new adapter is inserted (and w83627hf_driver is still present) */
966static int w83627hf_attach_adapter(struct i2c_adapter *adapter)
967{
968 return i2c_detect(adapter, &addr_data, w83627hf_detect);
969}
970
971static int w83627hf_find(int sioaddr, int *address)
972{
973 u16 val;
974
975 REG = sioaddr;
976 VAL = sioaddr + 1;
977
978 superio_enter();
979 val= superio_inb(DEVID);
980 if(val != W627_DEVID &&
981 val != W627THF_DEVID &&
982 val != W697_DEVID &&
983 val != W637_DEVID) {
984 superio_exit();
985 return -ENODEV;
986 }
987
988 superio_select(W83627HF_LD_HWM);
989 val = (superio_inb(WINB_BASE_REG) << 8) |
990 superio_inb(WINB_BASE_REG + 1);
991 *address = val & ~(WINB_EXTENT - 1);
992 if (*address == 0 && force_addr == 0) {
993 superio_exit();
994 return -ENODEV;
995 }
996 if (force_addr)
997 *address = force_addr; /* so detect will get called */
998
999 superio_exit();
1000 return 0;
1001}
1002
1003int w83627hf_detect(struct i2c_adapter *adapter, int address,
1004 int kind)
1005{
1006 int val;
1007 struct i2c_client *new_client;
1008 struct w83627hf_data *data;
1009 int err = 0;
1010 const char *client_name = "";
1011
1012 if (!i2c_is_isa_adapter(adapter)) {
1013 err = -ENODEV;
1014 goto ERROR0;
1015 }
1016
1017 if(force_addr)
1018 address = force_addr & ~(WINB_EXTENT - 1);
1019
1020 if (!request_region(address, WINB_EXTENT, w83627hf_driver.name)) {
1021 err = -EBUSY;
1022 goto ERROR0;
1023 }
1024
1025 if(force_addr) {
1026 printk("w83627hf.o: forcing ISA address 0x%04X\n", address);
1027 superio_enter();
1028 superio_select(W83627HF_LD_HWM);
1029 superio_outb(WINB_BASE_REG, address >> 8);
1030 superio_outb(WINB_BASE_REG+1, address & 0xff);
1031 superio_exit();
1032 }
1033
1034 superio_enter();
1035 val= superio_inb(DEVID);
1036 if(val == W627_DEVID)
1037 kind = w83627hf;
1038 else if(val == W697_DEVID)
1039 kind = w83697hf;
1040 else if(val == W627THF_DEVID)
1041 kind = w83627thf;
1042 else if(val == W637_DEVID)
1043 kind = w83637hf;
1044 else {
1045 dev_info(&adapter->dev,
1046 "Unsupported chip (dev_id=0x%02X).\n", val);
1047 goto ERROR1;
1048 }
1049
1050 superio_select(W83627HF_LD_HWM);
1051 if((val = 0x01 & superio_inb(WINB_ACT_REG)) == 0)
1052 superio_outb(WINB_ACT_REG, 1);
1053 superio_exit();
1054
1055 /* OK. For now, we presume we have a valid client. We now create the
1056 client structure, even though we cannot fill it completely yet.
1057 But it allows us to access w83627hf_{read,write}_value. */
1058
1059 if (!(data = kmalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) {
1060 err = -ENOMEM;
1061 goto ERROR1;
1062 }
1063 memset(data, 0, sizeof(struct w83627hf_data));
1064
1065 new_client = &data->client;
1066 i2c_set_clientdata(new_client, data);
1067 new_client->addr = address;
1068 init_MUTEX(&data->lock);
1069 new_client->adapter = adapter;
1070 new_client->driver = &w83627hf_driver;
1071 new_client->flags = 0;
1072
1073
1074 if (kind == w83627hf) {
1075 client_name = "w83627hf";
1076 } else if (kind == w83627thf) {
1077 client_name = "w83627thf";
1078 } else if (kind == w83697hf) {
1079 client_name = "w83697hf";
1080 } else if (kind == w83637hf) {
1081 client_name = "w83637hf";
1082 }
1083
1084 /* Fill in the remaining client fields and put into the global list */
1085 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
1086 data->type = kind;
1087 data->valid = 0;
1088 init_MUTEX(&data->update_lock);
1089
1090 /* Tell the I2C layer a new client has arrived */
1091 if ((err = i2c_attach_client(new_client)))
1092 goto ERROR2;
1093
1094 data->lm75 = NULL;
1095
1096 /* Initialize the chip */
1097 w83627hf_init_client(new_client);
1098
1099 /* A few vars need to be filled upon startup */
1100 data->fan_min[0] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(1));
1101 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
1102 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1103
1104 /* Register sysfs hooks */
1105 device_create_file_in(new_client, 0);
1106 if (kind != w83697hf)
1107 device_create_file_in(new_client, 1);
1108 device_create_file_in(new_client, 2);
1109 device_create_file_in(new_client, 3);
1110 device_create_file_in(new_client, 4);
1111 if (kind != w83627thf && kind != w83637hf) {
1112 device_create_file_in(new_client, 5);
1113 device_create_file_in(new_client, 6);
1114 }
1115 device_create_file_in(new_client, 7);
1116 device_create_file_in(new_client, 8);
1117
1118 device_create_file_fan(new_client, 1);
1119 device_create_file_fan(new_client, 2);
1120 if (kind != w83697hf)
1121 device_create_file_fan(new_client, 3);
1122
1123 device_create_file_temp(new_client, 1);
1124 device_create_file_temp(new_client, 2);
1125 if (kind != w83697hf)
1126 device_create_file_temp(new_client, 3);
1127
1128 if (kind != w83697hf)
1129 device_create_file_vid(new_client);
1130
1131 if (kind != w83697hf)
1132 device_create_file_vrm(new_client);
1133
1134 device_create_file_fan_div(new_client, 1);
1135 device_create_file_fan_div(new_client, 2);
1136 if (kind != w83697hf)
1137 device_create_file_fan_div(new_client, 3);
1138
1139 device_create_file_alarms(new_client);
1140
1141 device_create_file_beep(new_client);
1142
1143 device_create_file_pwm(new_client, 1);
1144 device_create_file_pwm(new_client, 2);
1145 if (kind == w83627thf || kind == w83637hf)
1146 device_create_file_pwm(new_client, 3);
1147
1148 device_create_file_sensor(new_client, 1);
1149 device_create_file_sensor(new_client, 2);
1150 if (kind != w83697hf)
1151 device_create_file_sensor(new_client, 3);
1152
1153 return 0;
1154
1155 ERROR2:
1156 kfree(data);
1157 ERROR1:
1158 release_region(address, WINB_EXTENT);
1159 ERROR0:
1160 return err;
1161}
1162
1163static int w83627hf_detach_client(struct i2c_client *client)
1164{
1165 int err;
1166
1167 if ((err = i2c_detach_client(client))) {
1168 dev_err(&client->dev,
1169 "Client deregistration failed, client not detached.\n");
1170 return err;
1171 }
1172
1173 release_region(client->addr, WINB_EXTENT);
1174 kfree(i2c_get_clientdata(client));
1175
1176 return 0;
1177}
1178
1179
1180/*
1181 ISA access must always be locked explicitly!
1182 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1183 would slow down the W83781D access and should not be necessary.
1184 There are some ugly typecasts here, but the good news is - they should
1185 nowhere else be necessary! */
1186static int w83627hf_read_value(struct i2c_client *client, u16 reg)
1187{
1188 struct w83627hf_data *data = i2c_get_clientdata(client);
1189 int res, word_sized;
1190
1191 down(&data->lock);
1192 word_sized = (((reg & 0xff00) == 0x100)
1193 || ((reg & 0xff00) == 0x200))
1194 && (((reg & 0x00ff) == 0x50)
1195 || ((reg & 0x00ff) == 0x53)
1196 || ((reg & 0x00ff) == 0x55));
1197 if (reg & 0xff00) {
1198 outb_p(W83781D_REG_BANK,
1199 client->addr + W83781D_ADDR_REG_OFFSET);
1200 outb_p(reg >> 8,
1201 client->addr + W83781D_DATA_REG_OFFSET);
1202 }
1203 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1204 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET);
1205 if (word_sized) {
1206 outb_p((reg & 0xff) + 1,
1207 client->addr + W83781D_ADDR_REG_OFFSET);
1208 res =
1209 (res << 8) + inb_p(client->addr +
1210 W83781D_DATA_REG_OFFSET);
1211 }
1212 if (reg & 0xff00) {
1213 outb_p(W83781D_REG_BANK,
1214 client->addr + W83781D_ADDR_REG_OFFSET);
1215 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1216 }
1217 up(&data->lock);
1218 return res;
1219}
1220
1221static int w83627thf_read_gpio5(struct i2c_client *client)
1222{
1223 int res = 0xff, sel;
1224
1225 superio_enter();
1226 superio_select(W83627HF_LD_GPIO5);
1227
1228 /* Make sure these GPIO pins are enabled */
1229 if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) {
1230 dev_dbg(&client->dev, "GPIO5 disabled, no VID function\n");
1231 goto exit;
1232 }
1233
1234 /* Make sure the pins are configured for input
1235 There must be at least five (VRM 9), and possibly 6 (VRM 10) */
1236 sel = superio_inb(W83627THF_GPIO5_IOSR);
1237 if ((sel & 0x1f) != 0x1f) {
1238 dev_dbg(&client->dev, "GPIO5 not configured for VID "
1239 "function\n");
1240 goto exit;
1241 }
1242
1243 dev_info(&client->dev, "Reading VID from GPIO5\n");
1244 res = superio_inb(W83627THF_GPIO5_DR) & sel;
1245
1246exit:
1247 superio_exit();
1248 return res;
1249}
1250
1251static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
1252{
1253 struct w83627hf_data *data = i2c_get_clientdata(client);
1254 int word_sized;
1255
1256 down(&data->lock);
1257 word_sized = (((reg & 0xff00) == 0x100)
1258 || ((reg & 0xff00) == 0x200))
1259 && (((reg & 0x00ff) == 0x53)
1260 || ((reg & 0x00ff) == 0x55));
1261 if (reg & 0xff00) {
1262 outb_p(W83781D_REG_BANK,
1263 client->addr + W83781D_ADDR_REG_OFFSET);
1264 outb_p(reg >> 8,
1265 client->addr + W83781D_DATA_REG_OFFSET);
1266 }
1267 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1268 if (word_sized) {
1269 outb_p(value >> 8,
1270 client->addr + W83781D_DATA_REG_OFFSET);
1271 outb_p((reg & 0xff) + 1,
1272 client->addr + W83781D_ADDR_REG_OFFSET);
1273 }
1274 outb_p(value & 0xff,
1275 client->addr + W83781D_DATA_REG_OFFSET);
1276 if (reg & 0xff00) {
1277 outb_p(W83781D_REG_BANK,
1278 client->addr + W83781D_ADDR_REG_OFFSET);
1279 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1280 }
1281 up(&data->lock);
1282 return 0;
1283}
1284
1285/* Called when we have found a new W83781D. It should set limits, etc. */
1286static void w83627hf_init_client(struct i2c_client *client)
1287{
1288 struct w83627hf_data *data = i2c_get_clientdata(client);
1289 int i;
1290 int type = data->type;
1291 u8 tmp;
1292
1293 if(init) {
1294 /* save this register */
1295 i = w83627hf_read_value(client, W83781D_REG_BEEP_CONFIG);
1296 /* Reset all except Watchdog values and last conversion values
1297 This sets fan-divs to 2, among others */
1298 w83627hf_write_value(client, W83781D_REG_CONFIG, 0x80);
1299 /* Restore the register and disable power-on abnormal beep.
1300 This saves FAN 1/2/3 input/output values set by BIOS. */
1301 w83627hf_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80);
1302 /* Disable master beep-enable (reset turns it on).
1303 Individual beeps should be reset to off but for some reason
1304 disabling this bit helps some people not get beeped */
1305 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, 0);
1306 }
1307
1308 /* Minimize conflicts with other winbond i2c-only clients... */
1309 /* disable i2c subclients... how to disable main i2c client?? */
1310 /* force i2c address to relatively uncommon address */
1311 w83627hf_write_value(client, W83781D_REG_I2C_SUBADDR, 0x89);
1312 w83627hf_write_value(client, W83781D_REG_I2C_ADDR, force_i2c);
1313
1314 /* Read VID only once */
1315 if (w83627hf == data->type || w83637hf == data->type) {
1316 int lo = w83627hf_read_value(client, W83781D_REG_VID_FANDIV);
1317 int hi = w83627hf_read_value(client, W83781D_REG_CHIPID);
1318 data->vid = (lo & 0x0f) | ((hi & 0x01) << 4);
1319 } else if (w83627thf == data->type) {
1320 data->vid = w83627thf_read_gpio5(client) & 0x3f;
1321 }
1322
1323 /* Read VRM & OVT Config only once */
1324 if (w83627thf == data->type || w83637hf == data->type) {
1325 data->vrm_ovt =
1326 w83627hf_read_value(client, W83627THF_REG_VRM_OVT_CFG);
1327 data->vrm = (data->vrm_ovt & 0x01) ? 90 : 82;
1328 } else {
1329 /* Convert VID to voltage based on default VRM */
1330 data->vrm = i2c_which_vrm();
1331 }
1332
1333 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
1334 for (i = 1; i <= 3; i++) {
1335 if (!(tmp & BIT_SCFG1[i - 1])) {
1336 data->sens[i - 1] = W83781D_DEFAULT_BETA;
1337 } else {
1338 if (w83627hf_read_value
1339 (client,
1340 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1341 data->sens[i - 1] = 1;
1342 else
1343 data->sens[i - 1] = 2;
1344 }
1345 if ((type == w83697hf) && (i == 2))
1346 break;
1347 }
1348
1349 if(init) {
1350 /* Enable temp2 */
1351 tmp = w83627hf_read_value(client, W83781D_REG_TEMP2_CONFIG);
1352 if (tmp & 0x01) {
1353 dev_warn(&client->dev, "Enabling temp2, readings "
1354 "might not make sense\n");
1355 w83627hf_write_value(client, W83781D_REG_TEMP2_CONFIG,
1356 tmp & 0xfe);
1357 }
1358
1359 /* Enable temp3 */
1360 if (type != w83697hf) {
1361 tmp = w83627hf_read_value(client,
1362 W83781D_REG_TEMP3_CONFIG);
1363 if (tmp & 0x01) {
1364 dev_warn(&client->dev, "Enabling temp3, "
1365 "readings might not make sense\n");
1366 w83627hf_write_value(client,
1367 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1368 }
1369 }
1370
1371 if (type == w83627hf) {
1372 /* enable PWM2 control (can't hurt since PWM reg
1373 should have been reset to 0xff) */
1374 w83627hf_write_value(client, W83627HF_REG_PWMCLK12,
1375 0x19);
1376 }
1377 /* enable comparator mode for temp2 and temp3 so
1378 alarm indication will work correctly */
1379 i = w83627hf_read_value(client, W83781D_REG_IRQ);
1380 if (!(i & 0x40))
1381 w83627hf_write_value(client, W83781D_REG_IRQ,
1382 i | 0x40);
1383 }
1384
1385 /* Start monitoring */
1386 w83627hf_write_value(client, W83781D_REG_CONFIG,
1387 (w83627hf_read_value(client,
1388 W83781D_REG_CONFIG) & 0xf7)
1389 | 0x01);
1390}
1391
1392static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1393{
1394 struct i2c_client *client = to_i2c_client(dev);
1395 struct w83627hf_data *data = i2c_get_clientdata(client);
1396 int i;
1397
1398 down(&data->update_lock);
1399
1400 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1401 || !data->valid) {
1402 for (i = 0; i <= 8; i++) {
1403 /* skip missing sensors */
1404 if (((data->type == w83697hf) && (i == 1)) ||
1405 ((data->type == w83627thf || data->type == w83637hf)
1406 && (i == 4 || i == 5)))
1407 continue;
1408 data->in[i] =
1409 w83627hf_read_value(client, W83781D_REG_IN(i));
1410 data->in_min[i] =
1411 w83627hf_read_value(client,
1412 W83781D_REG_IN_MIN(i));
1413 data->in_max[i] =
1414 w83627hf_read_value(client,
1415 W83781D_REG_IN_MAX(i));
1416 }
1417 for (i = 1; i <= 3; i++) {
1418 data->fan[i - 1] =
1419 w83627hf_read_value(client, W83781D_REG_FAN(i));
1420 data->fan_min[i - 1] =
1421 w83627hf_read_value(client,
1422 W83781D_REG_FAN_MIN(i));
1423 }
1424 for (i = 1; i <= 3; i++) {
1425 u8 tmp = w83627hf_read_value(client,
1426 W836X7HF_REG_PWM(data->type, i));
1427 /* bits 0-3 are reserved in 627THF */
1428 if (data->type == w83627thf)
1429 tmp &= 0xf0;
1430 data->pwm[i - 1] = tmp;
1431 if(i == 2 &&
1432 (data->type == w83627hf || data->type == w83697hf))
1433 break;
1434 }
1435
1436 data->temp = w83627hf_read_value(client, W83781D_REG_TEMP(1));
1437 data->temp_max =
1438 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(1));
1439 data->temp_max_hyst =
1440 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(1));
1441 data->temp_add[0] =
1442 w83627hf_read_value(client, W83781D_REG_TEMP(2));
1443 data->temp_max_add[0] =
1444 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(2));
1445 data->temp_max_hyst_add[0] =
1446 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(2));
1447 if (data->type != w83697hf) {
1448 data->temp_add[1] =
1449 w83627hf_read_value(client, W83781D_REG_TEMP(3));
1450 data->temp_max_add[1] =
1451 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(3));
1452 data->temp_max_hyst_add[1] =
1453 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(3));
1454 }
1455
1456 i = w83627hf_read_value(client, W83781D_REG_VID_FANDIV);
1457 data->fan_div[0] = (i >> 4) & 0x03;
1458 data->fan_div[1] = (i >> 6) & 0x03;
1459 if (data->type != w83697hf) {
1460 data->fan_div[2] = (w83627hf_read_value(client,
1461 W83781D_REG_PIN) >> 6) & 0x03;
1462 }
1463 i = w83627hf_read_value(client, W83781D_REG_VBAT);
1464 data->fan_div[0] |= (i >> 3) & 0x04;
1465 data->fan_div[1] |= (i >> 4) & 0x04;
1466 if (data->type != w83697hf)
1467 data->fan_div[2] |= (i >> 5) & 0x04;
1468 data->alarms =
1469 w83627hf_read_value(client, W83781D_REG_ALARM1) |
1470 (w83627hf_read_value(client, W83781D_REG_ALARM2) << 8) |
1471 (w83627hf_read_value(client, W83781D_REG_ALARM3) << 16);
1472 i = w83627hf_read_value(client, W83781D_REG_BEEP_INTS2);
1473 data->beep_enable = i >> 7;
1474 data->beep_mask = ((i & 0x7f) << 8) |
1475 w83627hf_read_value(client, W83781D_REG_BEEP_INTS1) |
1476 w83627hf_read_value(client, W83781D_REG_BEEP_INTS3) << 16;
1477 data->last_updated = jiffies;
1478 data->valid = 1;
1479 }
1480
1481 up(&data->update_lock);
1482
1483 return data;
1484}
1485
1486static int __init sensors_w83627hf_init(void)
1487{
1488 int addr;
1489
1490 if (w83627hf_find(0x2e, &addr)
1491 && w83627hf_find(0x4e, &addr)) {
1492 return -ENODEV;
1493 }
1494 normal_isa[0] = addr;
1495
1496 return i2c_add_driver(&w83627hf_driver);
1497}
1498
1499static void __exit sensors_w83627hf_exit(void)
1500{
1501 i2c_del_driver(&w83627hf_driver);
1502}
1503
1504MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
1505 "Philip Edelbrock <phil@netroedge.com>, "
1506 "and Mark Studebaker <mdsxyz123@yahoo.com>");
1507MODULE_DESCRIPTION("W83627HF driver");
1508MODULE_LICENSE("GPL");
1509
1510module_init(sensors_w83627hf_init);
1511module_exit(sensors_w83627hf_exit);
diff --git a/drivers/i2c/chips/w83781d.c b/drivers/i2c/chips/w83781d.c
deleted file mode 100644
index 4954e465c419..000000000000
--- a/drivers/i2c/chips/w83781d.c
+++ /dev/null
@@ -1,1664 +0,0 @@
1/*
2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23/*
24 Supports following chips:
25
26 Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA
27 as99127f 7 3 0 3 0x31 0x12c3 yes no
28 as99127f rev.2 (type_name = as99127f) 0x31 0x5ca3 yes no
29 w83781d 7 3 0 3 0x10-1 0x5ca3 yes yes
30 w83627hf 9 3 2 3 0x21 0x5ca3 yes yes(LPC)
31 w83627thf 9 3 2 3 0x90 0x5ca3 no yes(LPC)
32 w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
33 w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
34 w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
35
36*/
37
38#include <linux/config.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/jiffies.h>
43#include <linux/i2c.h>
44#include <linux/i2c-sensor.h>
45#include <linux/i2c-vid.h>
46#include <asm/io.h>
47#include "lm75.h"
48
49/* Addresses to scan */
50static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
51 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
52 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
53static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
54
55/* Insmod parameters */
56SENSORS_INSMOD_6(w83781d, w83782d, w83783s, w83627hf, as99127f, w83697hf);
57I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
58 "{bus, clientaddr, subclientaddr1, subclientaddr2}");
59
60static int init = 1;
61module_param(init, bool, 0);
62MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
63
64/* Constants specified below */
65
66/* Length of ISA address segment */
67#define W83781D_EXTENT 8
68
69/* Where are the ISA address/data registers relative to the base address */
70#define W83781D_ADDR_REG_OFFSET 5
71#define W83781D_DATA_REG_OFFSET 6
72
73/* The W83781D registers */
74/* The W83782D registers for nr=7,8 are in bank 5 */
75#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
76 (0x554 + (((nr) - 7) * 2)))
77#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
78 (0x555 + (((nr) - 7) * 2)))
79#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
80 (0x550 + (nr) - 7))
81
82#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr))
83#define W83781D_REG_FAN(nr) (0x27 + (nr))
84
85#define W83781D_REG_BANK 0x4E
86#define W83781D_REG_TEMP2_CONFIG 0x152
87#define W83781D_REG_TEMP3_CONFIG 0x252
88#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
89 ((nr == 2) ? (0x0150) : \
90 (0x27)))
91#define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \
92 ((nr == 2) ? (0x153) : \
93 (0x3A)))
94#define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \
95 ((nr == 2) ? (0x155) : \
96 (0x39)))
97
98#define W83781D_REG_CONFIG 0x40
99#define W83781D_REG_ALARM1 0x41
100#define W83781D_REG_ALARM2 0x42
101#define W83781D_REG_ALARM3 0x450 /* not on W83781D */
102
103#define W83781D_REG_IRQ 0x4C
104#define W83781D_REG_BEEP_CONFIG 0x4D
105#define W83781D_REG_BEEP_INTS1 0x56
106#define W83781D_REG_BEEP_INTS2 0x57
107#define W83781D_REG_BEEP_INTS3 0x453 /* not on W83781D */
108
109#define W83781D_REG_VID_FANDIV 0x47
110
111#define W83781D_REG_CHIPID 0x49
112#define W83781D_REG_WCHIPID 0x58
113#define W83781D_REG_CHIPMAN 0x4F
114#define W83781D_REG_PIN 0x4B
115
116/* 782D/783S only */
117#define W83781D_REG_VBAT 0x5D
118
119/* PWM 782D (1-4) and 783S (1-2) only */
120#define W83781D_REG_PWM1 0x5B /* 782d and 783s/627hf datasheets disagree */
121 /* on which is which; */
122#define W83781D_REG_PWM2 0x5A /* We follow the 782d convention here, */
123 /* However 782d is probably wrong. */
124#define W83781D_REG_PWM3 0x5E
125#define W83781D_REG_PWM4 0x5F
126#define W83781D_REG_PWMCLK12 0x5C
127#define W83781D_REG_PWMCLK34 0x45C
128static const u8 regpwm[] = { W83781D_REG_PWM1, W83781D_REG_PWM2,
129 W83781D_REG_PWM3, W83781D_REG_PWM4
130};
131
132#define W83781D_REG_PWM(nr) (regpwm[(nr) - 1])
133
134#define W83781D_REG_I2C_ADDR 0x48
135#define W83781D_REG_I2C_SUBADDR 0x4A
136
137/* The following are undocumented in the data sheets however we
138 received the information in an email from Winbond tech support */
139/* Sensor selection - not on 781d */
140#define W83781D_REG_SCFG1 0x5D
141static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 };
142
143#define W83781D_REG_SCFG2 0x59
144static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
145
146#define W83781D_DEFAULT_BETA 3435
147
148/* RT Table registers */
149#define W83781D_REG_RT_IDX 0x50
150#define W83781D_REG_RT_VAL 0x51
151
152/* Conversions. Rounding and limit checking is only done on the TO_REG
153 variants. Note that you should be a bit careful with which arguments
154 these macros are called: arguments may be evaluated more than once.
155 Fixing this is just not worth it. */
156#define IN_TO_REG(val) (SENSORS_LIMIT((((val) * 10 + 8)/16),0,255))
157#define IN_FROM_REG(val) (((val) * 16) / 10)
158
159static inline u8
160FAN_TO_REG(long rpm, int div)
161{
162 if (rpm == 0)
163 return 255;
164 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
165 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
166}
167
168#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \
169 ((val) == 255 ? 0 : \
170 1350000 / ((val) * (div))))
171
172#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
173 : (val)) / 1000, 0, 0xff))
174#define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
175
176#define ALARMS_FROM_REG(val) (val)
177#define PWM_FROM_REG(val) (val)
178#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255))
179#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
180 (val) ^ 0x7fff : (val))
181#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
182 (~(val)) & 0x7fff : (val) & 0xffffff)
183
184#define BEEP_ENABLE_TO_REG(val) ((val) ? 1 : 0)
185#define BEEP_ENABLE_FROM_REG(val) ((val) ? 1 : 0)
186
187#define DIV_FROM_REG(val) (1 << (val))
188
189static inline u8
190DIV_TO_REG(long val, enum chips type)
191{
192 int i;
193 val = SENSORS_LIMIT(val, 1,
194 ((type == w83781d
195 || type == as99127f) ? 8 : 128)) >> 1;
196 for (i = 0; i < 6; i++) {
197 if (val == 0)
198 break;
199 val >>= 1;
200 }
201 return ((u8) i);
202}
203
204/* There are some complications in a module like this. First off, W83781D chips
205 may be both present on the SMBus and the ISA bus, and we have to handle
206 those cases separately at some places. Second, there might be several
207 W83781D chips available (well, actually, that is probably never done; but
208 it is a clean illustration of how to handle a case like that). Finally,
209 a specific chip may be attached to *both* ISA and SMBus, and we would
210 not like to detect it double. Fortunately, in the case of the W83781D at
211 least, a register tells us what SMBus address we are on, so that helps
212 a bit - except if there could be more than one SMBus. Groan. No solution
213 for this yet. */
214
215/* This module may seem overly long and complicated. In fact, it is not so
216 bad. Quite a lot of bookkeeping is done. A real driver can often cut
217 some corners. */
218
219/* For each registered W83781D, we need to keep some data in memory. That
220 data is pointed to by w83781d_list[NR]->data. The structure itself is
221 dynamically allocated, at the same time when a new w83781d client is
222 allocated. */
223struct w83781d_data {
224 struct i2c_client client;
225 struct semaphore lock;
226 enum chips type;
227
228 struct semaphore update_lock;
229 char valid; /* !=0 if following fields are valid */
230 unsigned long last_updated; /* In jiffies */
231
232 struct i2c_client *lm75[2]; /* for secondary I2C addresses */
233 /* array of 2 pointers to subclients */
234
235 u8 in[9]; /* Register value - 8 & 9 for 782D only */
236 u8 in_max[9]; /* Register value - 8 & 9 for 782D only */
237 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */
238 u8 fan[3]; /* Register value */
239 u8 fan_min[3]; /* Register value */
240 u8 temp;
241 u8 temp_max; /* Register value */
242 u8 temp_max_hyst; /* Register value */
243 u16 temp_add[2]; /* Register value */
244 u16 temp_max_add[2]; /* Register value */
245 u16 temp_max_hyst_add[2]; /* Register value */
246 u8 fan_div[3]; /* Register encoding, shifted right */
247 u8 vid; /* Register encoding, combined */
248 u32 alarms; /* Register encoding, combined */
249 u32 beep_mask; /* Register encoding, combined */
250 u8 beep_enable; /* Boolean */
251 u8 pwm[4]; /* Register value */
252 u8 pwmenable[4]; /* Boolean */
253 u16 sens[3]; /* 782D/783S only.
254 1 = pentium diode; 2 = 3904 diode;
255 3000-5000 = thermistor beta.
256 Default = 3435.
257 Other Betas unimplemented */
258 u8 vrm;
259};
260
261static int w83781d_attach_adapter(struct i2c_adapter *adapter);
262static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
263static int w83781d_detach_client(struct i2c_client *client);
264
265static int w83781d_read_value(struct i2c_client *client, u16 register);
266static int w83781d_write_value(struct i2c_client *client, u16 register,
267 u16 value);
268static struct w83781d_data *w83781d_update_device(struct device *dev);
269static void w83781d_init_client(struct i2c_client *client);
270
271static struct i2c_driver w83781d_driver = {
272 .owner = THIS_MODULE,
273 .name = "w83781d",
274 .id = I2C_DRIVERID_W83781D,
275 .flags = I2C_DF_NOTIFY,
276 .attach_adapter = w83781d_attach_adapter,
277 .detach_client = w83781d_detach_client,
278};
279
280/* following are the sysfs callback functions */
281#define show_in_reg(reg) \
282static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
283{ \
284 struct w83781d_data *data = w83781d_update_device(dev); \
285 return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr] * 10)); \
286}
287show_in_reg(in);
288show_in_reg(in_min);
289show_in_reg(in_max);
290
291#define store_in_reg(REG, reg) \
292static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
293{ \
294 struct i2c_client *client = to_i2c_client(dev); \
295 struct w83781d_data *data = i2c_get_clientdata(client); \
296 u32 val; \
297 \
298 val = simple_strtoul(buf, NULL, 10) / 10; \
299 \
300 down(&data->update_lock); \
301 data->in_##reg[nr] = IN_TO_REG(val); \
302 w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
303 \
304 up(&data->update_lock); \
305 return count; \
306}
307store_in_reg(MIN, min);
308store_in_reg(MAX, max);
309
310#define sysfs_in_offset(offset) \
311static ssize_t \
312show_regs_in_##offset (struct device *dev, char *buf) \
313{ \
314 return show_in(dev, buf, offset); \
315} \
316static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL);
317
318#define sysfs_in_reg_offset(reg, offset) \
319static ssize_t show_regs_in_##reg##offset (struct device *dev, char *buf) \
320{ \
321 return show_in_##reg (dev, buf, offset); \
322} \
323static ssize_t store_regs_in_##reg##offset (struct device *dev, const char *buf, size_t count) \
324{ \
325 return store_in_##reg (dev, buf, count, offset); \
326} \
327static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_in_##reg##offset, store_regs_in_##reg##offset);
328
329#define sysfs_in_offsets(offset) \
330sysfs_in_offset(offset); \
331sysfs_in_reg_offset(min, offset); \
332sysfs_in_reg_offset(max, offset);
333
334sysfs_in_offsets(0);
335sysfs_in_offsets(1);
336sysfs_in_offsets(2);
337sysfs_in_offsets(3);
338sysfs_in_offsets(4);
339sysfs_in_offsets(5);
340sysfs_in_offsets(6);
341sysfs_in_offsets(7);
342sysfs_in_offsets(8);
343
344#define device_create_file_in(client, offset) \
345do { \
346device_create_file(&client->dev, &dev_attr_in##offset##_input); \
347device_create_file(&client->dev, &dev_attr_in##offset##_min); \
348device_create_file(&client->dev, &dev_attr_in##offset##_max); \
349} while (0)
350
351#define show_fan_reg(reg) \
352static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
353{ \
354 struct w83781d_data *data = w83781d_update_device(dev); \
355 return sprintf(buf,"%ld\n", \
356 FAN_FROM_REG(data->reg[nr-1], (long)DIV_FROM_REG(data->fan_div[nr-1]))); \
357}
358show_fan_reg(fan);
359show_fan_reg(fan_min);
360
361static ssize_t
362store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
363{
364 struct i2c_client *client = to_i2c_client(dev);
365 struct w83781d_data *data = i2c_get_clientdata(client);
366 u32 val;
367
368 val = simple_strtoul(buf, NULL, 10);
369
370 down(&data->update_lock);
371 data->fan_min[nr - 1] =
372 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
373 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr),
374 data->fan_min[nr - 1]);
375
376 up(&data->update_lock);
377 return count;
378}
379
380#define sysfs_fan_offset(offset) \
381static ssize_t show_regs_fan_##offset (struct device *dev, char *buf) \
382{ \
383 return show_fan(dev, buf, offset); \
384} \
385static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL);
386
387#define sysfs_fan_min_offset(offset) \
388static ssize_t show_regs_fan_min##offset (struct device *dev, char *buf) \
389{ \
390 return show_fan_min(dev, buf, offset); \
391} \
392static ssize_t store_regs_fan_min##offset (struct device *dev, const char *buf, size_t count) \
393{ \
394 return store_fan_min(dev, buf, count, offset); \
395} \
396static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, show_regs_fan_min##offset, store_regs_fan_min##offset);
397
398sysfs_fan_offset(1);
399sysfs_fan_min_offset(1);
400sysfs_fan_offset(2);
401sysfs_fan_min_offset(2);
402sysfs_fan_offset(3);
403sysfs_fan_min_offset(3);
404
405#define device_create_file_fan(client, offset) \
406do { \
407device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
408device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
409} while (0)
410
411#define show_temp_reg(reg) \
412static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
413{ \
414 struct w83781d_data *data = w83781d_update_device(dev); \
415 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
416 return sprintf(buf,"%d\n", \
417 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
418 } else { /* TEMP1 */ \
419 return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \
420 } \
421}
422show_temp_reg(temp);
423show_temp_reg(temp_max);
424show_temp_reg(temp_max_hyst);
425
426#define store_temp_reg(REG, reg) \
427static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
428{ \
429 struct i2c_client *client = to_i2c_client(dev); \
430 struct w83781d_data *data = i2c_get_clientdata(client); \
431 s32 val; \
432 \
433 val = simple_strtol(buf, NULL, 10); \
434 \
435 down(&data->update_lock); \
436 \
437 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
438 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
439 w83781d_write_value(client, W83781D_REG_TEMP_##REG(nr), \
440 data->temp_##reg##_add[nr-2]); \
441 } else { /* TEMP1 */ \
442 data->temp_##reg = TEMP_TO_REG(val); \
443 w83781d_write_value(client, W83781D_REG_TEMP_##REG(nr), \
444 data->temp_##reg); \
445 } \
446 \
447 up(&data->update_lock); \
448 return count; \
449}
450store_temp_reg(OVER, max);
451store_temp_reg(HYST, max_hyst);
452
453#define sysfs_temp_offset(offset) \
454static ssize_t \
455show_regs_temp_##offset (struct device *dev, char *buf) \
456{ \
457 return show_temp(dev, buf, offset); \
458} \
459static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL);
460
461#define sysfs_temp_reg_offset(reg, offset) \
462static ssize_t show_regs_temp_##reg##offset (struct device *dev, char *buf) \
463{ \
464 return show_temp_##reg (dev, buf, offset); \
465} \
466static ssize_t store_regs_temp_##reg##offset (struct device *dev, const char *buf, size_t count) \
467{ \
468 return store_temp_##reg (dev, buf, count, offset); \
469} \
470static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_temp_##reg##offset, store_regs_temp_##reg##offset);
471
472#define sysfs_temp_offsets(offset) \
473sysfs_temp_offset(offset); \
474sysfs_temp_reg_offset(max, offset); \
475sysfs_temp_reg_offset(max_hyst, offset);
476
477sysfs_temp_offsets(1);
478sysfs_temp_offsets(2);
479sysfs_temp_offsets(3);
480
481#define device_create_file_temp(client, offset) \
482do { \
483device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
484device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
485device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
486} while (0)
487
488static ssize_t
489show_vid_reg(struct device *dev, char *buf)
490{
491 struct w83781d_data *data = w83781d_update_device(dev);
492 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
493}
494
495static
496DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
497#define device_create_file_vid(client) \
498device_create_file(&client->dev, &dev_attr_cpu0_vid);
499static ssize_t
500show_vrm_reg(struct device *dev, char *buf)
501{
502 struct w83781d_data *data = w83781d_update_device(dev);
503 return sprintf(buf, "%ld\n", (long) data->vrm);
504}
505
506static ssize_t
507store_vrm_reg(struct device *dev, const char *buf, size_t count)
508{
509 struct i2c_client *client = to_i2c_client(dev);
510 struct w83781d_data *data = i2c_get_clientdata(client);
511 u32 val;
512
513 val = simple_strtoul(buf, NULL, 10);
514 data->vrm = val;
515
516 return count;
517}
518
519static
520DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
521#define device_create_file_vrm(client) \
522device_create_file(&client->dev, &dev_attr_vrm);
523static ssize_t
524show_alarms_reg(struct device *dev, char *buf)
525{
526 struct w83781d_data *data = w83781d_update_device(dev);
527 return sprintf(buf, "%ld\n", (long) ALARMS_FROM_REG(data->alarms));
528}
529
530static
531DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
532#define device_create_file_alarms(client) \
533device_create_file(&client->dev, &dev_attr_alarms);
534static ssize_t show_beep_mask (struct device *dev, char *buf)
535{
536 struct w83781d_data *data = w83781d_update_device(dev);
537 return sprintf(buf, "%ld\n",
538 (long)BEEP_MASK_FROM_REG(data->beep_mask, data->type));
539}
540static ssize_t show_beep_enable (struct device *dev, char *buf)
541{
542 struct w83781d_data *data = w83781d_update_device(dev);
543 return sprintf(buf, "%ld\n",
544 (long)BEEP_ENABLE_FROM_REG(data->beep_enable));
545}
546
547#define BEEP_ENABLE 0 /* Store beep_enable */
548#define BEEP_MASK 1 /* Store beep_mask */
549
550static ssize_t
551store_beep_reg(struct device *dev, const char *buf, size_t count,
552 int update_mask)
553{
554 struct i2c_client *client = to_i2c_client(dev);
555 struct w83781d_data *data = i2c_get_clientdata(client);
556 u32 val, val2;
557
558 val = simple_strtoul(buf, NULL, 10);
559
560 down(&data->update_lock);
561
562 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
563 data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
564 w83781d_write_value(client, W83781D_REG_BEEP_INTS1,
565 data->beep_mask & 0xff);
566
567 if ((data->type != w83781d) && (data->type != as99127f)) {
568 w83781d_write_value(client, W83781D_REG_BEEP_INTS3,
569 ((data->beep_mask) >> 16) & 0xff);
570 }
571
572 val2 = (data->beep_mask >> 8) & 0x7f;
573 } else { /* We are storing beep_enable */
574 val2 = w83781d_read_value(client, W83781D_REG_BEEP_INTS2) & 0x7f;
575 data->beep_enable = BEEP_ENABLE_TO_REG(val);
576 }
577
578 w83781d_write_value(client, W83781D_REG_BEEP_INTS2,
579 val2 | data->beep_enable << 7);
580
581 up(&data->update_lock);
582 return count;
583}
584
585#define sysfs_beep(REG, reg) \
586static ssize_t show_regs_beep_##reg (struct device *dev, char *buf) \
587{ \
588 return show_beep_##reg(dev, buf); \
589} \
590static ssize_t store_regs_beep_##reg (struct device *dev, const char *buf, size_t count) \
591{ \
592 return store_beep_reg(dev, buf, count, BEEP_##REG); \
593} \
594static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, show_regs_beep_##reg, store_regs_beep_##reg);
595
596sysfs_beep(ENABLE, enable);
597sysfs_beep(MASK, mask);
598
599#define device_create_file_beep(client) \
600do { \
601device_create_file(&client->dev, &dev_attr_beep_enable); \
602device_create_file(&client->dev, &dev_attr_beep_mask); \
603} while (0)
604
605static ssize_t
606show_fan_div_reg(struct device *dev, char *buf, int nr)
607{
608 struct w83781d_data *data = w83781d_update_device(dev);
609 return sprintf(buf, "%ld\n",
610 (long) DIV_FROM_REG(data->fan_div[nr - 1]));
611}
612
613/* Note: we save and restore the fan minimum here, because its value is
614 determined in part by the fan divisor. This follows the principle of
615 least suprise; the user doesn't expect the fan minimum to change just
616 because the divisor changed. */
617static ssize_t
618store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
619{
620 struct i2c_client *client = to_i2c_client(dev);
621 struct w83781d_data *data = i2c_get_clientdata(client);
622 unsigned long min;
623 u8 reg;
624 unsigned long val = simple_strtoul(buf, NULL, 10);
625
626 down(&data->update_lock);
627
628 /* Save fan_min */
629 min = FAN_FROM_REG(data->fan_min[nr],
630 DIV_FROM_REG(data->fan_div[nr]));
631
632 data->fan_div[nr] = DIV_TO_REG(val, data->type);
633
634 reg = (w83781d_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
635 & (nr==0 ? 0xcf : 0x3f))
636 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
637 w83781d_write_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
638
639 /* w83781d and as99127f don't have extended divisor bits */
640 if (data->type != w83781d && data->type != as99127f) {
641 reg = (w83781d_read_value(client, W83781D_REG_VBAT)
642 & ~(1 << (5 + nr)))
643 | ((data->fan_div[nr] & 0x04) << (3 + nr));
644 w83781d_write_value(client, W83781D_REG_VBAT, reg);
645 }
646
647 /* Restore fan_min */
648 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
649 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
650
651 up(&data->update_lock);
652 return count;
653}
654
655#define sysfs_fan_div(offset) \
656static ssize_t show_regs_fan_div_##offset (struct device *dev, char *buf) \
657{ \
658 return show_fan_div_reg(dev, buf, offset); \
659} \
660static ssize_t store_regs_fan_div_##offset (struct device *dev, const char *buf, size_t count) \
661{ \
662 return store_fan_div_reg(dev, buf, count, offset - 1); \
663} \
664static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, show_regs_fan_div_##offset, store_regs_fan_div_##offset);
665
666sysfs_fan_div(1);
667sysfs_fan_div(2);
668sysfs_fan_div(3);
669
670#define device_create_file_fan_div(client, offset) \
671do { \
672device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
673} while (0)
674
675static ssize_t
676show_pwm_reg(struct device *dev, char *buf, int nr)
677{
678 struct w83781d_data *data = w83781d_update_device(dev);
679 return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr - 1]));
680}
681
682static ssize_t
683show_pwmenable_reg(struct device *dev, char *buf, int nr)
684{
685 struct w83781d_data *data = w83781d_update_device(dev);
686 return sprintf(buf, "%ld\n", (long) data->pwmenable[nr - 1]);
687}
688
689static ssize_t
690store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
691{
692 struct i2c_client *client = to_i2c_client(dev);
693 struct w83781d_data *data = i2c_get_clientdata(client);
694 u32 val;
695
696 val = simple_strtoul(buf, NULL, 10);
697
698 down(&data->update_lock);
699 data->pwm[nr - 1] = PWM_TO_REG(val);
700 w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]);
701 up(&data->update_lock);
702 return count;
703}
704
705static ssize_t
706store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
707{
708 struct i2c_client *client = to_i2c_client(dev);
709 struct w83781d_data *data = i2c_get_clientdata(client);
710 u32 val, reg;
711
712 val = simple_strtoul(buf, NULL, 10);
713
714 down(&data->update_lock);
715
716 switch (val) {
717 case 0:
718 case 1:
719 reg = w83781d_read_value(client, W83781D_REG_PWMCLK12);
720 w83781d_write_value(client, W83781D_REG_PWMCLK12,
721 (reg & 0xf7) | (val << 3));
722
723 reg = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG);
724 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG,
725 (reg & 0xef) | (!val << 4));
726
727 data->pwmenable[nr - 1] = val;
728 break;
729
730 default:
731 up(&data->update_lock);
732 return -EINVAL;
733 }
734
735 up(&data->update_lock);
736 return count;
737}
738
739#define sysfs_pwm(offset) \
740static ssize_t show_regs_pwm_##offset (struct device *dev, char *buf) \
741{ \
742 return show_pwm_reg(dev, buf, offset); \
743} \
744static ssize_t store_regs_pwm_##offset (struct device *dev, \
745 const char *buf, size_t count) \
746{ \
747 return store_pwm_reg(dev, buf, count, offset); \
748} \
749static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
750 show_regs_pwm_##offset, store_regs_pwm_##offset);
751
752#define sysfs_pwmenable(offset) \
753static ssize_t show_regs_pwmenable_##offset (struct device *dev, char *buf) \
754{ \
755 return show_pwmenable_reg(dev, buf, offset); \
756} \
757static ssize_t store_regs_pwmenable_##offset (struct device *dev, \
758 const char *buf, size_t count) \
759{ \
760 return store_pwmenable_reg(dev, buf, count, offset); \
761} \
762static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
763 show_regs_pwmenable_##offset, store_regs_pwmenable_##offset);
764
765sysfs_pwm(1);
766sysfs_pwm(2);
767sysfs_pwmenable(2); /* only PWM2 can be enabled/disabled */
768sysfs_pwm(3);
769sysfs_pwm(4);
770
771#define device_create_file_pwm(client, offset) \
772do { \
773device_create_file(&client->dev, &dev_attr_pwm##offset); \
774} while (0)
775
776#define device_create_file_pwmenable(client, offset) \
777do { \
778device_create_file(&client->dev, &dev_attr_pwm##offset##_enable); \
779} while (0)
780
781static ssize_t
782show_sensor_reg(struct device *dev, char *buf, int nr)
783{
784 struct w83781d_data *data = w83781d_update_device(dev);
785 return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]);
786}
787
788static ssize_t
789store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
790{
791 struct i2c_client *client = to_i2c_client(dev);
792 struct w83781d_data *data = i2c_get_clientdata(client);
793 u32 val, tmp;
794
795 val = simple_strtoul(buf, NULL, 10);
796
797 down(&data->update_lock);
798
799 switch (val) {
800 case 1: /* PII/Celeron diode */
801 tmp = w83781d_read_value(client, W83781D_REG_SCFG1);
802 w83781d_write_value(client, W83781D_REG_SCFG1,
803 tmp | BIT_SCFG1[nr - 1]);
804 tmp = w83781d_read_value(client, W83781D_REG_SCFG2);
805 w83781d_write_value(client, W83781D_REG_SCFG2,
806 tmp | BIT_SCFG2[nr - 1]);
807 data->sens[nr - 1] = val;
808 break;
809 case 2: /* 3904 */
810 tmp = w83781d_read_value(client, W83781D_REG_SCFG1);
811 w83781d_write_value(client, W83781D_REG_SCFG1,
812 tmp | BIT_SCFG1[nr - 1]);
813 tmp = w83781d_read_value(client, W83781D_REG_SCFG2);
814 w83781d_write_value(client, W83781D_REG_SCFG2,
815 tmp & ~BIT_SCFG2[nr - 1]);
816 data->sens[nr - 1] = val;
817 break;
818 case W83781D_DEFAULT_BETA: /* thermistor */
819 tmp = w83781d_read_value(client, W83781D_REG_SCFG1);
820 w83781d_write_value(client, W83781D_REG_SCFG1,
821 tmp & ~BIT_SCFG1[nr - 1]);
822 data->sens[nr - 1] = val;
823 break;
824 default:
825 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n",
826 (long) val, W83781D_DEFAULT_BETA);
827 break;
828 }
829
830 up(&data->update_lock);
831 return count;
832}
833
834#define sysfs_sensor(offset) \
835static ssize_t show_regs_sensor_##offset (struct device *dev, char *buf) \
836{ \
837 return show_sensor_reg(dev, buf, offset); \
838} \
839static ssize_t store_regs_sensor_##offset (struct device *dev, const char *buf, size_t count) \
840{ \
841 return store_sensor_reg(dev, buf, count, offset); \
842} \
843static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, show_regs_sensor_##offset, store_regs_sensor_##offset);
844
845sysfs_sensor(1);
846sysfs_sensor(2);
847sysfs_sensor(3);
848
849#define device_create_file_sensor(client, offset) \
850do { \
851device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
852} while (0)
853
854/* This function is called when:
855 * w83781d_driver is inserted (when this module is loaded), for each
856 available adapter
857 * when a new adapter is inserted (and w83781d_driver is still present) */
858static int
859w83781d_attach_adapter(struct i2c_adapter *adapter)
860{
861 if (!(adapter->class & I2C_CLASS_HWMON))
862 return 0;
863 return i2c_detect(adapter, &addr_data, w83781d_detect);
864}
865
866/* Assumes that adapter is of I2C, not ISA variety.
867 * OTHERWISE DON'T CALL THIS
868 */
869static int
870w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
871 struct i2c_client *new_client)
872{
873 int i, val1 = 0, id;
874 int err;
875 const char *client_name = "";
876 struct w83781d_data *data = i2c_get_clientdata(new_client);
877
878 data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
879 if (!(data->lm75[0])) {
880 err = -ENOMEM;
881 goto ERROR_SC_0;
882 }
883 memset(data->lm75[0], 0x00, sizeof (struct i2c_client));
884
885 id = i2c_adapter_id(adapter);
886
887 if (force_subclients[0] == id && force_subclients[1] == address) {
888 for (i = 2; i <= 3; i++) {
889 if (force_subclients[i] < 0x48 ||
890 force_subclients[i] > 0x4f) {
891 dev_err(&new_client->dev, "Invalid subclient "
892 "address %d; must be 0x48-0x4f\n",
893 force_subclients[i]);
894 err = -EINVAL;
895 goto ERROR_SC_1;
896 }
897 }
898 w83781d_write_value(new_client, W83781D_REG_I2C_SUBADDR,
899 (force_subclients[2] & 0x07) |
900 ((force_subclients[3] & 0x07) << 4));
901 data->lm75[0]->addr = force_subclients[2];
902 } else {
903 val1 = w83781d_read_value(new_client, W83781D_REG_I2C_SUBADDR);
904 data->lm75[0]->addr = 0x48 + (val1 & 0x07);
905 }
906
907 if (kind != w83783s) {
908
909 data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
910 if (!(data->lm75[1])) {
911 err = -ENOMEM;
912 goto ERROR_SC_1;
913 }
914 memset(data->lm75[1], 0x0, sizeof(struct i2c_client));
915
916 if (force_subclients[0] == id &&
917 force_subclients[1] == address) {
918 data->lm75[1]->addr = force_subclients[3];
919 } else {
920 data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07);
921 }
922 if (data->lm75[0]->addr == data->lm75[1]->addr) {
923 dev_err(&new_client->dev,
924 "Duplicate addresses 0x%x for subclients.\n",
925 data->lm75[0]->addr);
926 err = -EBUSY;
927 goto ERROR_SC_2;
928 }
929 }
930
931 if (kind == w83781d)
932 client_name = "w83781d subclient";
933 else if (kind == w83782d)
934 client_name = "w83782d subclient";
935 else if (kind == w83783s)
936 client_name = "w83783s subclient";
937 else if (kind == w83627hf)
938 client_name = "w83627hf subclient";
939 else if (kind == as99127f)
940 client_name = "as99127f subclient";
941
942 for (i = 0; i <= 1; i++) {
943 /* store all data in w83781d */
944 i2c_set_clientdata(data->lm75[i], NULL);
945 data->lm75[i]->adapter = adapter;
946 data->lm75[i]->driver = &w83781d_driver;
947 data->lm75[i]->flags = 0;
948 strlcpy(data->lm75[i]->name, client_name,
949 I2C_NAME_SIZE);
950 if ((err = i2c_attach_client(data->lm75[i]))) {
951 dev_err(&new_client->dev, "Subclient %d "
952 "registration at address 0x%x "
953 "failed.\n", i, data->lm75[i]->addr);
954 if (i == 1)
955 goto ERROR_SC_3;
956 goto ERROR_SC_2;
957 }
958 if (kind == w83783s)
959 break;
960 }
961
962 return 0;
963
964/* Undo inits in case of errors */
965ERROR_SC_3:
966 i2c_detach_client(data->lm75[0]);
967ERROR_SC_2:
968 if (NULL != data->lm75[1])
969 kfree(data->lm75[1]);
970ERROR_SC_1:
971 if (NULL != data->lm75[0])
972 kfree(data->lm75[0]);
973ERROR_SC_0:
974 return err;
975}
976
977static int
978w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
979{
980 int i = 0, val1 = 0, val2;
981 struct i2c_client *new_client;
982 struct w83781d_data *data;
983 int err;
984 const char *client_name = "";
985 int is_isa = i2c_is_isa_adapter(adapter);
986 enum vendor { winbond, asus } vendid;
987
988 if (!is_isa
989 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
990 err = -EINVAL;
991 goto ERROR0;
992 }
993
994 /* Prevent users from forcing a kind for a bus it isn't supposed
995 to possibly be on */
996 if (is_isa && (kind == as99127f || kind == w83783s)) {
997 dev_err(&adapter->dev,
998 "Cannot force I2C-only chip for ISA address 0x%02x.\n",
999 address);
1000 err = -EINVAL;
1001 goto ERROR0;
1002 }
1003 if (!is_isa && kind == w83697hf) {
1004 dev_err(&adapter->dev,
1005 "Cannot force ISA-only chip for I2C address 0x%02x.\n",
1006 address);
1007 err = -EINVAL;
1008 goto ERROR0;
1009 }
1010
1011 if (is_isa)
1012 if (!request_region(address, W83781D_EXTENT,
1013 w83781d_driver.name)) {
1014 dev_dbg(&adapter->dev, "Request of region "
1015 "0x%x-0x%x for w83781d failed\n", address,
1016 address + W83781D_EXTENT - 1);
1017 err = -EBUSY;
1018 goto ERROR0;
1019 }
1020
1021 /* Probe whether there is anything available on this address. Already
1022 done for SMBus clients */
1023 if (kind < 0) {
1024 if (is_isa) {
1025
1026#define REALLY_SLOW_IO
1027 /* We need the timeouts for at least some LM78-like
1028 chips. But only if we read 'undefined' registers. */
1029 i = inb_p(address + 1);
1030 if (inb_p(address + 2) != i
1031 || inb_p(address + 3) != i
1032 || inb_p(address + 7) != i) {
1033 dev_dbg(&adapter->dev, "Detection of w83781d "
1034 "chip failed at step 1\n");
1035 err = -ENODEV;
1036 goto ERROR1;
1037 }
1038#undef REALLY_SLOW_IO
1039
1040 /* Let's just hope nothing breaks here */
1041 i = inb_p(address + 5) & 0x7f;
1042 outb_p(~i & 0x7f, address + 5);
1043 val2 = inb_p(address + 5) & 0x7f;
1044 if (val2 != (~i & 0x7f)) {
1045 outb_p(i, address + 5);
1046 dev_dbg(&adapter->dev, "Detection of w83781d "
1047 "chip failed at step 2 (0x%x != "
1048 "0x%x at 0x%x)\n", val2, ~i & 0x7f,
1049 address + 5);
1050 err = -ENODEV;
1051 goto ERROR1;
1052 }
1053 }
1054 }
1055
1056 /* OK. For now, we presume we have a valid client. We now create the
1057 client structure, even though we cannot fill it completely yet.
1058 But it allows us to access w83781d_{read,write}_value. */
1059
1060 if (!(data = kmalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1061 err = -ENOMEM;
1062 goto ERROR1;
1063 }
1064 memset(data, 0, sizeof(struct w83781d_data));
1065
1066 new_client = &data->client;
1067 i2c_set_clientdata(new_client, data);
1068 new_client->addr = address;
1069 init_MUTEX(&data->lock);
1070 new_client->adapter = adapter;
1071 new_client->driver = &w83781d_driver;
1072 new_client->flags = 0;
1073
1074 /* Now, we do the remaining detection. */
1075
1076 /* The w8378?d may be stuck in some other bank than bank 0. This may
1077 make reading other information impossible. Specify a force=... or
1078 force_*=... parameter, and the Winbond will be reset to the right
1079 bank. */
1080 if (kind < 0) {
1081 if (w83781d_read_value(new_client, W83781D_REG_CONFIG) & 0x80) {
1082 dev_dbg(&new_client->dev, "Detection failed at step "
1083 "3\n");
1084 err = -ENODEV;
1085 goto ERROR2;
1086 }
1087 val1 = w83781d_read_value(new_client, W83781D_REG_BANK);
1088 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN);
1089 /* Check for Winbond or Asus ID if in bank 0 */
1090 if ((!(val1 & 0x07)) &&
1091 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
1092 || ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) {
1093 dev_dbg(&new_client->dev, "Detection failed at step "
1094 "4\n");
1095 err = -ENODEV;
1096 goto ERROR2;
1097 }
1098 /* If Winbond SMBus, check address at 0x48.
1099 Asus doesn't support, except for as99127f rev.2 */
1100 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) ||
1101 ((val1 & 0x80) && (val2 == 0x5c)))) {
1102 if (w83781d_read_value
1103 (new_client, W83781D_REG_I2C_ADDR) != address) {
1104 dev_dbg(&new_client->dev, "Detection failed "
1105 "at step 5\n");
1106 err = -ENODEV;
1107 goto ERROR2;
1108 }
1109 }
1110 }
1111
1112 /* We have either had a force parameter, or we have already detected the
1113 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1114 w83781d_write_value(new_client, W83781D_REG_BANK,
1115 (w83781d_read_value(new_client,
1116 W83781D_REG_BANK) & 0x78) |
1117 0x80);
1118
1119 /* Determine the chip type. */
1120 if (kind <= 0) {
1121 /* get vendor ID */
1122 val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN);
1123 if (val2 == 0x5c)
1124 vendid = winbond;
1125 else if (val2 == 0x12)
1126 vendid = asus;
1127 else {
1128 dev_dbg(&new_client->dev, "Chip was made by neither "
1129 "Winbond nor Asus?\n");
1130 err = -ENODEV;
1131 goto ERROR2;
1132 }
1133
1134 val1 = w83781d_read_value(new_client, W83781D_REG_WCHIPID);
1135 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1136 kind = w83781d;
1137 else if (val1 == 0x30 && vendid == winbond)
1138 kind = w83782d;
1139 else if (val1 == 0x40 && vendid == winbond && !is_isa
1140 && address == 0x2d)
1141 kind = w83783s;
1142 else if ((val1 == 0x21 || val1 == 0x90) && vendid == winbond)
1143 kind = w83627hf;
1144 else if (val1 == 0x31 && !is_isa && address >= 0x28)
1145 kind = as99127f;
1146 else if (val1 == 0x60 && vendid == winbond && is_isa)
1147 kind = w83697hf;
1148 else {
1149 if (kind == 0)
1150 dev_warn(&new_client->dev, "Ignoring 'force' "
1151 "parameter for unknown chip at "
1152 "adapter %d, address 0x%02x\n",
1153 i2c_adapter_id(adapter), address);
1154 err = -EINVAL;
1155 goto ERROR2;
1156 }
1157 }
1158
1159 if (kind == w83781d) {
1160 client_name = "w83781d";
1161 } else if (kind == w83782d) {
1162 client_name = "w83782d";
1163 } else if (kind == w83783s) {
1164 client_name = "w83783s";
1165 } else if (kind == w83627hf) {
1166 if (val1 == 0x90)
1167 client_name = "w83627thf";
1168 else
1169 client_name = "w83627hf";
1170 } else if (kind == as99127f) {
1171 client_name = "as99127f";
1172 } else if (kind == w83697hf) {
1173 client_name = "w83697hf";
1174 }
1175
1176 /* Fill in the remaining client fields and put into the global list */
1177 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
1178 data->type = kind;
1179
1180 data->valid = 0;
1181 init_MUTEX(&data->update_lock);
1182
1183 /* Tell the I2C layer a new client has arrived */
1184 if ((err = i2c_attach_client(new_client)))
1185 goto ERROR2;
1186
1187 /* attach secondary i2c lm75-like clients */
1188 if (!is_isa) {
1189 if ((err = w83781d_detect_subclients(adapter, address,
1190 kind, new_client)))
1191 goto ERROR3;
1192 } else {
1193 data->lm75[0] = NULL;
1194 data->lm75[1] = NULL;
1195 }
1196
1197 /* Initialize the chip */
1198 w83781d_init_client(new_client);
1199
1200 /* A few vars need to be filled upon startup */
1201 for (i = 1; i <= 3; i++) {
1202 data->fan_min[i - 1] = w83781d_read_value(new_client,
1203 W83781D_REG_FAN_MIN(i));
1204 }
1205 if (kind != w83781d && kind != as99127f)
1206 for (i = 0; i < 4; i++)
1207 data->pwmenable[i] = 1;
1208
1209 /* Register sysfs hooks */
1210 device_create_file_in(new_client, 0);
1211 if (kind != w83783s && kind != w83697hf)
1212 device_create_file_in(new_client, 1);
1213 device_create_file_in(new_client, 2);
1214 device_create_file_in(new_client, 3);
1215 device_create_file_in(new_client, 4);
1216 device_create_file_in(new_client, 5);
1217 device_create_file_in(new_client, 6);
1218 if (kind != as99127f && kind != w83781d && kind != w83783s) {
1219 device_create_file_in(new_client, 7);
1220 device_create_file_in(new_client, 8);
1221 }
1222
1223 device_create_file_fan(new_client, 1);
1224 device_create_file_fan(new_client, 2);
1225 if (kind != w83697hf)
1226 device_create_file_fan(new_client, 3);
1227
1228 device_create_file_temp(new_client, 1);
1229 device_create_file_temp(new_client, 2);
1230 if (kind != w83783s && kind != w83697hf)
1231 device_create_file_temp(new_client, 3);
1232
1233 if (kind != w83697hf)
1234 device_create_file_vid(new_client);
1235
1236 if (kind != w83697hf)
1237 device_create_file_vrm(new_client);
1238
1239 device_create_file_fan_div(new_client, 1);
1240 device_create_file_fan_div(new_client, 2);
1241 if (kind != w83697hf)
1242 device_create_file_fan_div(new_client, 3);
1243
1244 device_create_file_alarms(new_client);
1245
1246 device_create_file_beep(new_client);
1247
1248 if (kind != w83781d && kind != as99127f) {
1249 device_create_file_pwm(new_client, 1);
1250 device_create_file_pwm(new_client, 2);
1251 device_create_file_pwmenable(new_client, 2);
1252 }
1253 if (kind == w83782d && !is_isa) {
1254 device_create_file_pwm(new_client, 3);
1255 device_create_file_pwm(new_client, 4);
1256 }
1257
1258 if (kind != as99127f && kind != w83781d) {
1259 device_create_file_sensor(new_client, 1);
1260 device_create_file_sensor(new_client, 2);
1261 if (kind != w83783s && kind != w83697hf)
1262 device_create_file_sensor(new_client, 3);
1263 }
1264
1265 return 0;
1266
1267ERROR3:
1268 i2c_detach_client(new_client);
1269ERROR2:
1270 kfree(data);
1271ERROR1:
1272 if (is_isa)
1273 release_region(address, W83781D_EXTENT);
1274ERROR0:
1275 return err;
1276}
1277
1278static int
1279w83781d_detach_client(struct i2c_client *client)
1280{
1281 int err;
1282
1283 if (i2c_is_isa_client(client))
1284 release_region(client->addr, W83781D_EXTENT);
1285
1286 if ((err = i2c_detach_client(client))) {
1287 dev_err(&client->dev,
1288 "Client deregistration failed, client not detached.\n");
1289 return err;
1290 }
1291
1292 if (i2c_get_clientdata(client)==NULL) {
1293 /* subclients */
1294 kfree(client);
1295 } else {
1296 /* main client */
1297 kfree(i2c_get_clientdata(client));
1298 }
1299
1300 return 0;
1301}
1302
1303/* The SMBus locks itself, usually, but nothing may access the Winbond between
1304 bank switches. ISA access must always be locked explicitly!
1305 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1306 would slow down the W83781D access and should not be necessary.
1307 There are some ugly typecasts here, but the good news is - they should
1308 nowhere else be necessary! */
1309static int
1310w83781d_read_value(struct i2c_client *client, u16 reg)
1311{
1312 struct w83781d_data *data = i2c_get_clientdata(client);
1313 int res, word_sized, bank;
1314 struct i2c_client *cl;
1315
1316 down(&data->lock);
1317 if (i2c_is_isa_client(client)) {
1318 word_sized = (((reg & 0xff00) == 0x100)
1319 || ((reg & 0xff00) == 0x200))
1320 && (((reg & 0x00ff) == 0x50)
1321 || ((reg & 0x00ff) == 0x53)
1322 || ((reg & 0x00ff) == 0x55));
1323 if (reg & 0xff00) {
1324 outb_p(W83781D_REG_BANK,
1325 client->addr + W83781D_ADDR_REG_OFFSET);
1326 outb_p(reg >> 8,
1327 client->addr + W83781D_DATA_REG_OFFSET);
1328 }
1329 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1330 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET);
1331 if (word_sized) {
1332 outb_p((reg & 0xff) + 1,
1333 client->addr + W83781D_ADDR_REG_OFFSET);
1334 res =
1335 (res << 8) + inb_p(client->addr +
1336 W83781D_DATA_REG_OFFSET);
1337 }
1338 if (reg & 0xff00) {
1339 outb_p(W83781D_REG_BANK,
1340 client->addr + W83781D_ADDR_REG_OFFSET);
1341 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1342 }
1343 } else {
1344 bank = (reg >> 8) & 0x0f;
1345 if (bank > 2)
1346 /* switch banks */
1347 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1348 bank);
1349 if (bank == 0 || bank > 2) {
1350 res = i2c_smbus_read_byte_data(client, reg & 0xff);
1351 } else {
1352 /* switch to subclient */
1353 cl = data->lm75[bank - 1];
1354 /* convert from ISA to LM75 I2C addresses */
1355 switch (reg & 0xff) {
1356 case 0x50: /* TEMP */
1357 res = swab16(i2c_smbus_read_word_data(cl, 0));
1358 break;
1359 case 0x52: /* CONFIG */
1360 res = i2c_smbus_read_byte_data(cl, 1);
1361 break;
1362 case 0x53: /* HYST */
1363 res = swab16(i2c_smbus_read_word_data(cl, 2));
1364 break;
1365 case 0x55: /* OVER */
1366 default:
1367 res = swab16(i2c_smbus_read_word_data(cl, 3));
1368 break;
1369 }
1370 }
1371 if (bank > 2)
1372 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1373 }
1374 up(&data->lock);
1375 return res;
1376}
1377
1378static int
1379w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
1380{
1381 struct w83781d_data *data = i2c_get_clientdata(client);
1382 int word_sized, bank;
1383 struct i2c_client *cl;
1384
1385 down(&data->lock);
1386 if (i2c_is_isa_client(client)) {
1387 word_sized = (((reg & 0xff00) == 0x100)
1388 || ((reg & 0xff00) == 0x200))
1389 && (((reg & 0x00ff) == 0x53)
1390 || ((reg & 0x00ff) == 0x55));
1391 if (reg & 0xff00) {
1392 outb_p(W83781D_REG_BANK,
1393 client->addr + W83781D_ADDR_REG_OFFSET);
1394 outb_p(reg >> 8,
1395 client->addr + W83781D_DATA_REG_OFFSET);
1396 }
1397 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET);
1398 if (word_sized) {
1399 outb_p(value >> 8,
1400 client->addr + W83781D_DATA_REG_OFFSET);
1401 outb_p((reg & 0xff) + 1,
1402 client->addr + W83781D_ADDR_REG_OFFSET);
1403 }
1404 outb_p(value & 0xff, client->addr + W83781D_DATA_REG_OFFSET);
1405 if (reg & 0xff00) {
1406 outb_p(W83781D_REG_BANK,
1407 client->addr + W83781D_ADDR_REG_OFFSET);
1408 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET);
1409 }
1410 } else {
1411 bank = (reg >> 8) & 0x0f;
1412 if (bank > 2)
1413 /* switch banks */
1414 i2c_smbus_write_byte_data(client, W83781D_REG_BANK,
1415 bank);
1416 if (bank == 0 || bank > 2) {
1417 i2c_smbus_write_byte_data(client, reg & 0xff,
1418 value & 0xff);
1419 } else {
1420 /* switch to subclient */
1421 cl = data->lm75[bank - 1];
1422 /* convert from ISA to LM75 I2C addresses */
1423 switch (reg & 0xff) {
1424 case 0x52: /* CONFIG */
1425 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1426 break;
1427 case 0x53: /* HYST */
1428 i2c_smbus_write_word_data(cl, 2, swab16(value));
1429 break;
1430 case 0x55: /* OVER */
1431 i2c_smbus_write_word_data(cl, 3, swab16(value));
1432 break;
1433 }
1434 }
1435 if (bank > 2)
1436 i2c_smbus_write_byte_data(client, W83781D_REG_BANK, 0);
1437 }
1438 up(&data->lock);
1439 return 0;
1440}
1441
1442/* Called when we have found a new W83781D. It should set limits, etc. */
1443static void
1444w83781d_init_client(struct i2c_client *client)
1445{
1446 struct w83781d_data *data = i2c_get_clientdata(client);
1447 int i, p;
1448 int type = data->type;
1449 u8 tmp;
1450
1451 if (init && type != as99127f) { /* this resets registers we don't have
1452 documentation for on the as99127f */
1453 /* save these registers */
1454 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG);
1455 p = w83781d_read_value(client, W83781D_REG_PWMCLK12);
1456 /* Reset all except Watchdog values and last conversion values
1457 This sets fan-divs to 2, among others */
1458 w83781d_write_value(client, W83781D_REG_CONFIG, 0x80);
1459 /* Restore the registers and disable power-on abnormal beep.
1460 This saves FAN 1/2/3 input/output values set by BIOS. */
1461 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80);
1462 w83781d_write_value(client, W83781D_REG_PWMCLK12, p);
1463 /* Disable master beep-enable (reset turns it on).
1464 Individual beep_mask should be reset to off but for some reason
1465 disabling this bit helps some people not get beeped */
1466 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0);
1467 }
1468
1469 data->vrm = i2c_which_vrm();
1470
1471 if ((type != w83781d) && (type != as99127f)) {
1472 tmp = w83781d_read_value(client, W83781D_REG_SCFG1);
1473 for (i = 1; i <= 3; i++) {
1474 if (!(tmp & BIT_SCFG1[i - 1])) {
1475 data->sens[i - 1] = W83781D_DEFAULT_BETA;
1476 } else {
1477 if (w83781d_read_value
1478 (client,
1479 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1480 data->sens[i - 1] = 1;
1481 else
1482 data->sens[i - 1] = 2;
1483 }
1484 if ((type == w83783s || type == w83697hf) && (i == 2))
1485 break;
1486 }
1487 }
1488
1489 if (init && type != as99127f) {
1490 /* Enable temp2 */
1491 tmp = w83781d_read_value(client, W83781D_REG_TEMP2_CONFIG);
1492 if (tmp & 0x01) {
1493 dev_warn(&client->dev, "Enabling temp2, readings "
1494 "might not make sense\n");
1495 w83781d_write_value(client, W83781D_REG_TEMP2_CONFIG,
1496 tmp & 0xfe);
1497 }
1498
1499 /* Enable temp3 */
1500 if (type != w83783s && type != w83697hf) {
1501 tmp = w83781d_read_value(client,
1502 W83781D_REG_TEMP3_CONFIG);
1503 if (tmp & 0x01) {
1504 dev_warn(&client->dev, "Enabling temp3, "
1505 "readings might not make sense\n");
1506 w83781d_write_value(client,
1507 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1508 }
1509 }
1510
1511 if (type != w83781d) {
1512 /* enable comparator mode for temp2 and temp3 so
1513 alarm indication will work correctly */
1514 i = w83781d_read_value(client, W83781D_REG_IRQ);
1515 if (!(i & 0x40))
1516 w83781d_write_value(client, W83781D_REG_IRQ,
1517 i | 0x40);
1518 }
1519 }
1520
1521 /* Start monitoring */
1522 w83781d_write_value(client, W83781D_REG_CONFIG,
1523 (w83781d_read_value(client,
1524 W83781D_REG_CONFIG) & 0xf7)
1525 | 0x01);
1526}
1527
1528static struct w83781d_data *w83781d_update_device(struct device *dev)
1529{
1530 struct i2c_client *client = to_i2c_client(dev);
1531 struct w83781d_data *data = i2c_get_clientdata(client);
1532 int i;
1533
1534 down(&data->update_lock);
1535
1536 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1537 || !data->valid) {
1538 dev_dbg(dev, "Starting device update\n");
1539
1540 for (i = 0; i <= 8; i++) {
1541 if ((data->type == w83783s || data->type == w83697hf)
1542 && (i == 1))
1543 continue; /* 783S has no in1 */
1544 data->in[i] =
1545 w83781d_read_value(client, W83781D_REG_IN(i));
1546 data->in_min[i] =
1547 w83781d_read_value(client, W83781D_REG_IN_MIN(i));
1548 data->in_max[i] =
1549 w83781d_read_value(client, W83781D_REG_IN_MAX(i));
1550 if ((data->type != w83782d) && (data->type != w83697hf)
1551 && (data->type != w83627hf) && (i == 6))
1552 break;
1553 }
1554 for (i = 1; i <= 3; i++) {
1555 data->fan[i - 1] =
1556 w83781d_read_value(client, W83781D_REG_FAN(i));
1557 data->fan_min[i - 1] =
1558 w83781d_read_value(client, W83781D_REG_FAN_MIN(i));
1559 }
1560 if (data->type != w83781d && data->type != as99127f) {
1561 for (i = 1; i <= 4; i++) {
1562 data->pwm[i - 1] =
1563 w83781d_read_value(client,
1564 W83781D_REG_PWM(i));
1565 if ((data->type != w83782d
1566 || i2c_is_isa_client(client))
1567 && i == 2)
1568 break;
1569 }
1570 /* Only PWM2 can be disabled */
1571 data->pwmenable[1] = (w83781d_read_value(client,
1572 W83781D_REG_PWMCLK12) & 0x08) >> 3;
1573 }
1574
1575 data->temp = w83781d_read_value(client, W83781D_REG_TEMP(1));
1576 data->temp_max =
1577 w83781d_read_value(client, W83781D_REG_TEMP_OVER(1));
1578 data->temp_max_hyst =
1579 w83781d_read_value(client, W83781D_REG_TEMP_HYST(1));
1580 data->temp_add[0] =
1581 w83781d_read_value(client, W83781D_REG_TEMP(2));
1582 data->temp_max_add[0] =
1583 w83781d_read_value(client, W83781D_REG_TEMP_OVER(2));
1584 data->temp_max_hyst_add[0] =
1585 w83781d_read_value(client, W83781D_REG_TEMP_HYST(2));
1586 if (data->type != w83783s && data->type != w83697hf) {
1587 data->temp_add[1] =
1588 w83781d_read_value(client, W83781D_REG_TEMP(3));
1589 data->temp_max_add[1] =
1590 w83781d_read_value(client,
1591 W83781D_REG_TEMP_OVER(3));
1592 data->temp_max_hyst_add[1] =
1593 w83781d_read_value(client,
1594 W83781D_REG_TEMP_HYST(3));
1595 }
1596 i = w83781d_read_value(client, W83781D_REG_VID_FANDIV);
1597 if (data->type != w83697hf) {
1598 data->vid = i & 0x0f;
1599 data->vid |=
1600 (w83781d_read_value(client, W83781D_REG_CHIPID) &
1601 0x01)
1602 << 4;
1603 }
1604 data->fan_div[0] = (i >> 4) & 0x03;
1605 data->fan_div[1] = (i >> 6) & 0x03;
1606 if (data->type != w83697hf) {
1607 data->fan_div[2] = (w83781d_read_value(client,
1608 W83781D_REG_PIN)
1609 >> 6) & 0x03;
1610 }
1611 if ((data->type != w83781d) && (data->type != as99127f)) {
1612 i = w83781d_read_value(client, W83781D_REG_VBAT);
1613 data->fan_div[0] |= (i >> 3) & 0x04;
1614 data->fan_div[1] |= (i >> 4) & 0x04;
1615 if (data->type != w83697hf)
1616 data->fan_div[2] |= (i >> 5) & 0x04;
1617 }
1618 data->alarms =
1619 w83781d_read_value(client,
1620 W83781D_REG_ALARM1) +
1621 (w83781d_read_value(client, W83781D_REG_ALARM2) << 8);
1622 if ((data->type == w83782d) || (data->type == w83627hf)) {
1623 data->alarms |=
1624 w83781d_read_value(client,
1625 W83781D_REG_ALARM3) << 16;
1626 }
1627 i = w83781d_read_value(client, W83781D_REG_BEEP_INTS2);
1628 data->beep_enable = i >> 7;
1629 data->beep_mask = ((i & 0x7f) << 8) +
1630 w83781d_read_value(client, W83781D_REG_BEEP_INTS1);
1631 if ((data->type != w83781d) && (data->type != as99127f)) {
1632 data->beep_mask |=
1633 w83781d_read_value(client,
1634 W83781D_REG_BEEP_INTS3) << 16;
1635 }
1636 data->last_updated = jiffies;
1637 data->valid = 1;
1638 }
1639
1640 up(&data->update_lock);
1641
1642 return data;
1643}
1644
1645static int __init
1646sensors_w83781d_init(void)
1647{
1648 return i2c_add_driver(&w83781d_driver);
1649}
1650
1651static void __exit
1652sensors_w83781d_exit(void)
1653{
1654 i2c_del_driver(&w83781d_driver);
1655}
1656
1657MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
1658 "Philip Edelbrock <phil@netroedge.com>, "
1659 "and Mark Studebaker <mdsxyz123@yahoo.com>");
1660MODULE_DESCRIPTION("W83781D driver");
1661MODULE_LICENSE("GPL");
1662
1663module_init(sensors_w83781d_init);
1664module_exit(sensors_w83781d_exit);
diff --git a/drivers/i2c/chips/w83l785ts.c b/drivers/i2c/chips/w83l785ts.c
deleted file mode 100644
index 59bbc5881fa6..000000000000
--- a/drivers/i2c/chips/w83l785ts.c
+++ /dev/null
@@ -1,329 +0,0 @@
1/*
2 * w83l785ts.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org>
5 *
6 * Inspired from the lm83 driver. The W83L785TS-S is a sensor chip made
7 * by Winbond. It reports a single external temperature with a 1 deg
8 * resolution and a 3 deg accuracy. Datasheet can be obtained from
9 * Winbond's website at:
10 * http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/W83L785TS-S.pdf
11 *
12 * Ported to Linux 2.6 by Wolfgang Ziegler <nuppla@gmx.at> and Jean Delvare
13 * <khali@linux-fr.org>.
14 *
15 * Thanks to James Bolt <james@evilpenguin.com> for benchmarking the read
16 * error handling mechanism.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/config.h>
34#include <linux/module.h>
35#include <linux/delay.h>
36#include <linux/init.h>
37#include <linux/slab.h>
38#include <linux/jiffies.h>
39#include <linux/i2c.h>
40#include <linux/i2c-sensor.h>
41
42/* How many retries on register read error */
43#define MAX_RETRIES 5
44
45/*
46 * Address to scan
47 * Address is fully defined internally and cannot be changed.
48 */
49
50static unsigned short normal_i2c[] = { 0x2e, I2C_CLIENT_END };
51static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END };
52
53/*
54 * Insmod parameters
55 */
56
57SENSORS_INSMOD_1(w83l785ts);
58
59/*
60 * The W83L785TS-S registers
61 * Manufacturer ID is 0x5CA3 for Winbond.
62 */
63
64#define W83L785TS_REG_MAN_ID1 0x4D
65#define W83L785TS_REG_MAN_ID2 0x4C
66#define W83L785TS_REG_CHIP_ID 0x4E
67#define W83L785TS_REG_CONFIG 0x40
68#define W83L785TS_REG_TYPE 0x52
69#define W83L785TS_REG_TEMP 0x27
70#define W83L785TS_REG_TEMP_OVER 0x53 /* not sure about this one */
71
72/*
73 * Conversions
74 * The W83L785TS-S uses signed 8-bit values.
75 */
76
77#define TEMP_FROM_REG(val) ((val & 0x80 ? val-0x100 : val) * 1000)
78
79/*
80 * Functions declaration
81 */
82
83static int w83l785ts_attach_adapter(struct i2c_adapter *adapter);
84static int w83l785ts_detect(struct i2c_adapter *adapter, int address,
85 int kind);
86static int w83l785ts_detach_client(struct i2c_client *client);
87static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval);
88static struct w83l785ts_data *w83l785ts_update_device(struct device *dev);
89
90/*
91 * Driver data (common to all clients)
92 */
93
94static struct i2c_driver w83l785ts_driver = {
95 .owner = THIS_MODULE,
96 .name = "w83l785ts",
97 .id = I2C_DRIVERID_W83L785TS,
98 .flags = I2C_DF_NOTIFY,
99 .attach_adapter = w83l785ts_attach_adapter,
100 .detach_client = w83l785ts_detach_client,
101};
102
103/*
104 * Client data (each client gets its own)
105 */
106
107struct w83l785ts_data {
108 struct i2c_client client;
109 struct semaphore update_lock;
110 char valid; /* zero until following fields are valid */
111 unsigned long last_updated; /* in jiffies */
112
113 /* registers values */
114 u8 temp, temp_over;
115};
116
117/*
118 * Sysfs stuff
119 */
120
121static ssize_t show_temp(struct device *dev, char *buf)
122{
123 struct w83l785ts_data *data = w83l785ts_update_device(dev);
124 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
125}
126
127static ssize_t show_temp_over(struct device *dev, char *buf)
128{
129 struct w83l785ts_data *data = w83l785ts_update_device(dev);
130 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
131}
132
133static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL);
134static DEVICE_ATTR(temp1_max, S_IRUGO, show_temp_over, NULL);
135
136/*
137 * Real code
138 */
139
140static int w83l785ts_attach_adapter(struct i2c_adapter *adapter)
141{
142 if (!(adapter->class & I2C_CLASS_HWMON))
143 return 0;
144 return i2c_detect(adapter, &addr_data, w83l785ts_detect);
145}
146
147/*
148 * The following function does more than just detection. If detection
149 * succeeds, it also registers the new chip.
150 */
151static int w83l785ts_detect(struct i2c_adapter *adapter, int address, int kind)
152{
153 struct i2c_client *new_client;
154 struct w83l785ts_data *data;
155 int err = 0;
156
157
158 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
159 goto exit;
160
161 if (!(data = kmalloc(sizeof(struct w83l785ts_data), GFP_KERNEL))) {
162 err = -ENOMEM;
163 goto exit;
164 }
165 memset(data, 0, sizeof(struct w83l785ts_data));
166
167
168 /* The common I2C client data is placed right before the
169 * W83L785TS-specific data. */
170 new_client = &data->client;
171 i2c_set_clientdata(new_client, data);
172 new_client->addr = address;
173 new_client->adapter = adapter;
174 new_client->driver = &w83l785ts_driver;
175 new_client->flags = 0;
176
177 /*
178 * Now we do the remaining detection. A negative kind means that
179 * the driver was loaded with no force parameter (default), so we
180 * must both detect and identify the chip (actually there is only
181 * one possible kind of chip for now, W83L785TS-S). A zero kind means
182 * that the driver was loaded with the force parameter, the detection
183 * step shall be skipped. A positive kind means that the driver
184 * was loaded with the force parameter and a given kind of chip is
185 * requested, so both the detection and the identification steps
186 * are skipped.
187 */
188 if (kind < 0) { /* detection */
189 if (((w83l785ts_read_value(new_client,
190 W83L785TS_REG_CONFIG, 0) & 0x80) != 0x00)
191 || ((w83l785ts_read_value(new_client,
192 W83L785TS_REG_TYPE, 0) & 0xFC) != 0x00)) {
193 dev_dbg(&adapter->dev,
194 "W83L785TS-S detection failed at 0x%02x.\n",
195 address);
196 goto exit_free;
197 }
198 }
199
200 if (kind <= 0) { /* identification */
201 u16 man_id;
202 u8 chip_id;
203
204 man_id = (w83l785ts_read_value(new_client,
205 W83L785TS_REG_MAN_ID1, 0) << 8) +
206 w83l785ts_read_value(new_client,
207 W83L785TS_REG_MAN_ID2, 0);
208 chip_id = w83l785ts_read_value(new_client,
209 W83L785TS_REG_CHIP_ID, 0);
210
211 if (man_id == 0x5CA3) { /* Winbond */
212 if (chip_id == 0x70) { /* W83L785TS-S */
213 kind = w83l785ts;
214 }
215 }
216
217 if (kind <= 0) { /* identification failed */
218 dev_info(&adapter->dev,
219 "Unsupported chip (man_id=0x%04X, "
220 "chip_id=0x%02X).\n", man_id, chip_id);
221 goto exit_free;
222 }
223 }
224
225 /* We can fill in the remaining client fields. */
226 strlcpy(new_client->name, "w83l785ts", I2C_NAME_SIZE);
227 data->valid = 0;
228 init_MUTEX(&data->update_lock);
229
230 /* Default values in case the first read fails (unlikely). */
231 data->temp_over = data->temp = 0;
232
233 /* Tell the I2C layer a new client has arrived. */
234 if ((err = i2c_attach_client(new_client)))
235 goto exit_free;
236
237 /*
238 * Initialize the W83L785TS chip
239 * Nothing yet, assume it is already started.
240 */
241
242 /* Register sysfs hooks */
243 device_create_file(&new_client->dev, &dev_attr_temp1_input);
244 device_create_file(&new_client->dev, &dev_attr_temp1_max);
245
246 return 0;
247
248exit_free:
249 kfree(data);
250exit:
251 return err;
252}
253
254static int w83l785ts_detach_client(struct i2c_client *client)
255{
256 int err;
257
258 if ((err = i2c_detach_client(client))) {
259 dev_err(&client->dev, "Client deregistration failed, "
260 "client not detached.\n");
261 return err;
262 }
263
264 kfree(i2c_get_clientdata(client));
265 return 0;
266}
267
268static u8 w83l785ts_read_value(struct i2c_client *client, u8 reg, u8 defval)
269{
270 int value, i;
271
272 /* Frequent read errors have been reported on Asus boards, so we
273 * retry on read errors. If it still fails (unlikely), return the
274 * default value requested by the caller. */
275 for (i = 1; i <= MAX_RETRIES; i++) {
276 value = i2c_smbus_read_byte_data(client, reg);
277 if (value >= 0) {
278 dev_dbg(&client->dev, "Read 0x%02x from register "
279 "0x%02x.\n", value, reg);
280 return value;
281 }
282 dev_dbg(&client->dev, "Read failed, will retry in %d.\n", i);
283 msleep(i);
284 }
285
286 dev_err(&client->dev, "Couldn't read value from register 0x%02x. "
287 "Please report.\n", reg);
288 return defval;
289}
290
291static struct w83l785ts_data *w83l785ts_update_device(struct device *dev)
292{
293 struct i2c_client *client = to_i2c_client(dev);
294 struct w83l785ts_data *data = i2c_get_clientdata(client);
295
296 down(&data->update_lock);
297
298 if (!data->valid || time_after(jiffies, data->last_updated + HZ * 2)) {
299 dev_dbg(&client->dev, "Updating w83l785ts data.\n");
300 data->temp = w83l785ts_read_value(client,
301 W83L785TS_REG_TEMP, data->temp);
302 data->temp_over = w83l785ts_read_value(client,
303 W83L785TS_REG_TEMP_OVER, data->temp_over);
304
305 data->last_updated = jiffies;
306 data->valid = 1;
307 }
308
309 up(&data->update_lock);
310
311 return data;
312}
313
314static int __init sensors_w83l785ts_init(void)
315{
316 return i2c_add_driver(&w83l785ts_driver);
317}
318
319static void __exit sensors_w83l785ts_exit(void)
320{
321 i2c_del_driver(&w83l785ts_driver);
322}
323
324MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
325MODULE_DESCRIPTION("W83L785TS-S driver");
326MODULE_LICENSE("GPL");
327
328module_init(sensors_w83l785ts_init);
329module_exit(sensors_w83l785ts_exit);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 9011627d7eb0..dda472e5e8be 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -21,7 +21,6 @@
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */ 22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */
23 23
24#include <linux/config.h>
25#include <linux/module.h> 24#include <linux/module.h>
26#include <linux/kernel.h> 25#include <linux/kernel.h>
27#include <linux/errno.h> 26#include <linux/errno.h>
@@ -62,7 +61,7 @@ static int i2c_bus_resume(struct device * dev)
62 return rc; 61 return rc;
63} 62}
64 63
65static struct bus_type i2c_bus_type = { 64struct bus_type i2c_bus_type = {
66 .name = "i2c", 65 .name = "i2c",
67 .match = i2c_device_match, 66 .match = i2c_device_match,
68 .suspend = i2c_bus_suspend, 67 .suspend = i2c_bus_suspend,
@@ -79,13 +78,13 @@ static int i2c_device_remove(struct device *dev)
79 return 0; 78 return 0;
80} 79}
81 80
82static void i2c_adapter_dev_release(struct device *dev) 81void i2c_adapter_dev_release(struct device *dev)
83{ 82{
84 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 83 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
85 complete(&adap->dev_released); 84 complete(&adap->dev_released);
86} 85}
87 86
88static struct device_driver i2c_adapter_driver = { 87struct device_driver i2c_adapter_driver = {
89 .name = "i2c_adapter", 88 .name = "i2c_adapter",
90 .bus = &i2c_bus_type, 89 .bus = &i2c_bus_type,
91 .probe = i2c_device_probe, 90 .probe = i2c_device_probe,
@@ -98,12 +97,12 @@ static void i2c_adapter_class_dev_release(struct class_device *dev)
98 complete(&adap->class_dev_released); 97 complete(&adap->class_dev_released);
99} 98}
100 99
101static struct class i2c_adapter_class = { 100struct class i2c_adapter_class = {
102 .name = "i2c-adapter", 101 .name = "i2c-adapter",
103 .release = &i2c_adapter_class_dev_release, 102 .release = &i2c_adapter_class_dev_release,
104}; 103};
105 104
106static ssize_t show_adapter_name(struct device *dev, char *buf) 105static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
107{ 106{
108 struct i2c_adapter *adap = dev_to_i2c_adapter(dev); 107 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
109 return sprintf(buf, "%s\n", adap->name); 108 return sprintf(buf, "%s\n", adap->name);
@@ -117,7 +116,7 @@ static void i2c_client_release(struct device *dev)
117 complete(&client->released); 116 complete(&client->released);
118} 117}
119 118
120static ssize_t show_client_name(struct device *dev, char *buf) 119static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
121{ 120{
122 struct i2c_client *client = to_i2c_client(dev); 121 struct i2c_client *client = to_i2c_client(dev);
123 return sprintf(buf, "%s\n", client->name); 122 return sprintf(buf, "%s\n", client->name);
@@ -157,7 +156,7 @@ int i2c_add_adapter(struct i2c_adapter *adap)
157 goto out_unlock; 156 goto out_unlock;
158 } 157 }
159 158
160 res = idr_get_new(&i2c_adapter_idr, NULL, &id); 159 res = idr_get_new(&i2c_adapter_idr, adap, &id);
161 if (res < 0) { 160 if (res < 0) {
162 if (res == -EAGAIN) 161 if (res == -EAGAIN)
163 res = -ENOMEM; 162 res = -ENOMEM;
@@ -189,6 +188,8 @@ int i2c_add_adapter(struct i2c_adapter *adap)
189 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE); 188 strlcpy(adap->class_dev.class_id, adap->dev.bus_id, BUS_ID_SIZE);
190 class_device_register(&adap->class_dev); 189 class_device_register(&adap->class_dev);
191 190
191 dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
192
192 /* inform drivers of new adapters */ 193 /* inform drivers of new adapters */
193 list_for_each(item,&drivers) { 194 list_for_each(item,&drivers) {
194 driver = list_entry(item, struct i2c_driver, list); 195 driver = list_entry(item, struct i2c_driver, list);
@@ -197,8 +198,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
197 driver->attach_adapter(adap); 198 driver->attach_adapter(adap);
198 } 199 }
199 200
200 dev_dbg(&adap->dev, "registered as adapter #%d\n", adap->nr);
201
202out_unlock: 201out_unlock:
203 up(&core_lists); 202 up(&core_lists);
204 return res; 203 return res;
@@ -221,8 +220,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
221 break; 220 break;
222 } 221 }
223 if (adap_from_list != adap) { 222 if (adap_from_list != adap) {
224 pr_debug("I2C: Attempting to delete an unregistered " 223 pr_debug("i2c-core: attempting to delete unregistered "
225 "adapter\n"); 224 "adapter [%s]\n", adap->name);
226 res = -EINVAL; 225 res = -EINVAL;
227 goto out_unlock; 226 goto out_unlock;
228 } 227 }
@@ -231,15 +230,14 @@ int i2c_del_adapter(struct i2c_adapter *adap)
231 driver = list_entry(item, struct i2c_driver, list); 230 driver = list_entry(item, struct i2c_driver, list);
232 if (driver->detach_adapter) 231 if (driver->detach_adapter)
233 if ((res = driver->detach_adapter(adap))) { 232 if ((res = driver->detach_adapter(adap))) {
234 dev_warn(&adap->dev, "can't detach adapter " 233 dev_err(&adap->dev, "detach_adapter failed "
235 "while detaching driver %s: driver not " 234 "for driver [%s]\n", driver->name);
236 "detached!", driver->name);
237 goto out_unlock; 235 goto out_unlock;
238 } 236 }
239 } 237 }
240 238
241 /* detach any active clients. This must be done first, because 239 /* detach any active clients. This must be done first, because
242 * it can fail; in which case we give upp. */ 240 * it can fail; in which case we give up. */
243 list_for_each_safe(item, _n, &adap->clients) { 241 list_for_each_safe(item, _n, &adap->clients) {
244 client = list_entry(item, struct i2c_client, list); 242 client = list_entry(item, struct i2c_client, list);
245 243
@@ -248,9 +246,8 @@ int i2c_del_adapter(struct i2c_adapter *adap)
248 * must be deleted, as this would cause invalid states. 246 * must be deleted, as this would cause invalid states.
249 */ 247 */
250 if ((res=client->driver->detach_client(client))) { 248 if ((res=client->driver->detach_client(client))) {
251 dev_err(&adap->dev, "adapter not " 249 dev_err(&adap->dev, "detach_client failed for client "
252 "unregistered, because client at " 250 "[%s] at address 0x%02x\n", client->name,
253 "address %02x can't be detached. ",
254 client->addr); 251 client->addr);
255 goto out_unlock; 252 goto out_unlock;
256 } 253 }
@@ -271,7 +268,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
271 /* free dynamically allocated bus id */ 268 /* free dynamically allocated bus id */
272 idr_remove(&i2c_adapter_idr, adap->nr); 269 idr_remove(&i2c_adapter_idr, adap->nr);
273 270
274 dev_dbg(&adap->dev, "adapter unregistered\n"); 271 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
275 272
276 out_unlock: 273 out_unlock:
277 up(&core_lists); 274 up(&core_lists);
@@ -304,7 +301,7 @@ int i2c_add_driver(struct i2c_driver *driver)
304 goto out_unlock; 301 goto out_unlock;
305 302
306 list_add_tail(&driver->list,&drivers); 303 list_add_tail(&driver->list,&drivers);
307 pr_debug("i2c-core: driver %s registered.\n", driver->name); 304 pr_debug("i2c-core: driver [%s] registered\n", driver->name);
308 305
309 /* now look for instances of driver on our adapters */ 306 /* now look for instances of driver on our adapters */
310 if (driver->flags & I2C_DF_NOTIFY) { 307 if (driver->flags & I2C_DF_NOTIFY) {
@@ -332,21 +329,17 @@ int i2c_del_driver(struct i2c_driver *driver)
332 /* Have a look at each adapter, if clients of this driver are still 329 /* Have a look at each adapter, if clients of this driver are still
333 * attached. If so, detach them to be able to kill the driver 330 * attached. If so, detach them to be able to kill the driver
334 * afterwards. 331 * afterwards.
335 */ 332 *
336 pr_debug("i2c-core: unregister_driver - looking for clients.\n"); 333 * Removing clients does not depend on the notify flag, else
337 /* removing clients does not depend on the notify flag, else
338 * invalid operation might (will!) result, when using stale client 334 * invalid operation might (will!) result, when using stale client
339 * pointers. 335 * pointers.
340 */ 336 */
341 list_for_each(item1,&adapters) { 337 list_for_each(item1,&adapters) {
342 adap = list_entry(item1, struct i2c_adapter, list); 338 adap = list_entry(item1, struct i2c_adapter, list);
343 dev_dbg(&adap->dev, "examining adapter\n");
344 if (driver->detach_adapter) { 339 if (driver->detach_adapter) {
345 if ((res = driver->detach_adapter(adap))) { 340 if ((res = driver->detach_adapter(adap))) {
346 dev_warn(&adap->dev, "while unregistering " 341 dev_err(&adap->dev, "detach_adapter failed "
347 "dummy driver %s, adapter could " 342 "for driver [%s]\n", driver->name);
348 "not be detached properly; driver "
349 "not unloaded!",driver->name);
350 goto out_unlock; 343 goto out_unlock;
351 } 344 }
352 } else { 345 } else {
@@ -354,16 +347,13 @@ int i2c_del_driver(struct i2c_driver *driver)
354 client = list_entry(item2, struct i2c_client, list); 347 client = list_entry(item2, struct i2c_client, list);
355 if (client->driver != driver) 348 if (client->driver != driver)
356 continue; 349 continue;
357 pr_debug("i2c-core.o: detaching client %s:\n", client->name); 350 dev_dbg(&adap->dev, "detaching client [%s] "
351 "at 0x%02x\n", client->name,
352 client->addr);
358 if ((res = driver->detach_client(client))) { 353 if ((res = driver->detach_client(client))) {
359 dev_err(&adap->dev, "while " 354 dev_err(&adap->dev, "detach_client "
360 "unregistering driver " 355 "failed for client [%s] at "
361 "`%s', the client at " 356 "0x%02x\n", client->name,
362 "address %02x of "
363 "adapter could not "
364 "be detached; driver "
365 "not unloaded!",
366 driver->name,
367 client->addr); 357 client->addr);
368 goto out_unlock; 358 goto out_unlock;
369 } 359 }
@@ -373,7 +363,7 @@ int i2c_del_driver(struct i2c_driver *driver)
373 363
374 driver_unregister(&driver->driver); 364 driver_unregister(&driver->driver);
375 list_del(&driver->list); 365 list_del(&driver->list);
376 pr_debug("i2c-core: driver unregistered: %s\n", driver->name); 366 pr_debug("i2c-core: driver [%s] unregistered\n", driver->name);
377 367
378 out_unlock: 368 out_unlock:
379 up(&core_lists); 369 up(&core_lists);
@@ -418,15 +408,12 @@ int i2c_attach_client(struct i2c_client *client)
418 408
419 if (adapter->client_register) { 409 if (adapter->client_register) {
420 if (adapter->client_register(client)) { 410 if (adapter->client_register(client)) {
421 dev_warn(&adapter->dev, "warning: client_register " 411 dev_dbg(&adapter->dev, "client_register "
422 "seems to have failed for client %02x\n", 412 "failed for client [%s] at 0x%02x\n",
423 client->addr); 413 client->name, client->addr);
424 } 414 }
425 } 415 }
426 416
427 dev_dbg(&adapter->dev, "client [%s] registered to adapter\n",
428 client->name);
429
430 if (client->flags & I2C_CLIENT_ALLOW_USE) 417 if (client->flags & I2C_CLIENT_ALLOW_USE)
431 client->usage_count = 0; 418 client->usage_count = 0;
432 419
@@ -437,7 +424,8 @@ int i2c_attach_client(struct i2c_client *client)
437 424
438 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 425 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
439 "%d-%04x", i2c_adapter_id(adapter), client->addr); 426 "%d-%04x", i2c_adapter_id(adapter), client->addr);
440 pr_debug("registering %s\n", client->dev.bus_id); 427 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
428 client->name, client->dev.bus_id);
441 device_register(&client->dev); 429 device_register(&client->dev);
442 device_create_file(&client->dev, &dev_attr_client_name); 430 device_create_file(&client->dev, &dev_attr_client_name);
443 431
@@ -450,15 +438,19 @@ int i2c_detach_client(struct i2c_client *client)
450 struct i2c_adapter *adapter = client->adapter; 438 struct i2c_adapter *adapter = client->adapter;
451 int res = 0; 439 int res = 0;
452 440
453 if ((client->flags & I2C_CLIENT_ALLOW_USE) && (client->usage_count > 0)) 441 if ((client->flags & I2C_CLIENT_ALLOW_USE)
442 && (client->usage_count > 0)) {
443 dev_warn(&client->dev, "Client [%s] still busy, "
444 "can't detach\n", client->name);
454 return -EBUSY; 445 return -EBUSY;
446 }
455 447
456 if (adapter->client_unregister) { 448 if (adapter->client_unregister) {
457 res = adapter->client_unregister(client); 449 res = adapter->client_unregister(client);
458 if (res) { 450 if (res) {
459 dev_err(&client->dev, 451 dev_err(&client->dev,
460 "client_unregister [%s] failed, " 452 "client_unregister [%s] failed, "
461 "client not detached", client->name); 453 "client not detached\n", client->name);
462 goto out; 454 goto out;
463 } 455 }
464 } 456 }
@@ -612,27 +604,16 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
612 struct i2c_adapter *adap=client->adapter; 604 struct i2c_adapter *adap=client->adapter;
613 struct i2c_msg msg; 605 struct i2c_msg msg;
614 606
615 if (client->adapter->algo->master_xfer) { 607 msg.addr = client->addr;
616 msg.addr = client->addr; 608 msg.flags = client->flags & I2C_M_TEN;
617 msg.flags = client->flags & I2C_M_TEN; 609 msg.len = count;
618 msg.len = count; 610 msg.buf = (char *)buf;
619 msg.buf = (char *)buf;
620
621 dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n",
622 count);
623 611
624 down(&adap->bus_lock); 612 ret = i2c_transfer(adap, &msg, 1);
625 ret = adap->algo->master_xfer(adap,&msg,1);
626 up(&adap->bus_lock);
627 613
628 /* if everything went ok (i.e. 1 msg transmitted), return #bytes 614 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
629 * transmitted, else error code. 615 transmitted, else error code. */
630 */ 616 return (ret == 1) ? count : ret;
631 return (ret == 1 )? count : ret;
632 } else {
633 dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
634 return -ENOSYS;
635 }
636} 617}
637 618
638int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 619int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
@@ -640,31 +621,18 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
640 struct i2c_adapter *adap=client->adapter; 621 struct i2c_adapter *adap=client->adapter;
641 struct i2c_msg msg; 622 struct i2c_msg msg;
642 int ret; 623 int ret;
643 if (client->adapter->algo->master_xfer) { 624
644 msg.addr = client->addr; 625 msg.addr = client->addr;
645 msg.flags = client->flags & I2C_M_TEN; 626 msg.flags = client->flags & I2C_M_TEN;
646 msg.flags |= I2C_M_RD; 627 msg.flags |= I2C_M_RD;
647 msg.len = count; 628 msg.len = count;
648 msg.buf = buf; 629 msg.buf = buf;
649 630
650 dev_dbg(&client->adapter->dev, "master_recv: reading %d bytes.\n", 631 ret = i2c_transfer(adap, &msg, 1);
651 count); 632
652 633 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
653 down(&adap->bus_lock); 634 transmitted, else error code. */
654 ret = adap->algo->master_xfer(adap,&msg,1); 635 return (ret == 1) ? count : ret;
655 up(&adap->bus_lock);
656
657 dev_dbg(&client->adapter->dev, "master_recv: return:%d (count:%d, addr:0x%02x)\n",
658 ret, count, client->addr);
659
660 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
661 * transmitted, else error code.
662 */
663 return (ret == 1 )? count : ret;
664 } else {
665 dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
666 return -ENOSYS;
667 }
668} 636}
669 637
670 638
@@ -694,151 +662,141 @@ int i2c_control(struct i2c_client *client,
694 * Will not work for 10-bit addresses! 662 * Will not work for 10-bit addresses!
695 * ---------------------------------------------------- 663 * ----------------------------------------------------
696 */ 664 */
665static int i2c_probe_address(struct i2c_adapter *adapter, int addr, int kind,
666 int (*found_proc) (struct i2c_adapter *, int, int))
667{
668 int err;
669
670 /* Make sure the address is valid */
671 if (addr < 0x03 || addr > 0x77) {
672 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
673 addr);
674 return -EINVAL;
675 }
676
677 /* Skip if already in use */
678 if (i2c_check_addr(adapter, addr))
679 return 0;
680
681 /* Make sure there is something at this address, unless forced */
682 if (kind < 0) {
683 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
684 I2C_SMBUS_QUICK, NULL) < 0)
685 return 0;
686
687 /* prevent 24RF08 corruption */
688 if ((addr & ~0x0f) == 0x50)
689 i2c_smbus_xfer(adapter, addr, 0, 0, 0,
690 I2C_SMBUS_QUICK, NULL);
691 }
692
693 /* Finally call the custom detection function */
694 err = found_proc(adapter, addr, kind);
695
696 /* -ENODEV can be returned if there is a chip at the given address
697 but it isn't supported by this chip driver. We catch it here as
698 this isn't an error. */
699 return (err == -ENODEV) ? 0 : err;
700}
701
697int i2c_probe(struct i2c_adapter *adapter, 702int i2c_probe(struct i2c_adapter *adapter,
698 struct i2c_client_address_data *address_data, 703 struct i2c_client_address_data *address_data,
699 int (*found_proc) (struct i2c_adapter *, int, int)) 704 int (*found_proc) (struct i2c_adapter *, int, int))
700{ 705{
701 int addr,i,found,err; 706 int i, err;
702 int adap_id = i2c_adapter_id(adapter); 707 int adap_id = i2c_adapter_id(adapter);
703 708
704 /* Forget it if we can't probe using SMBUS_QUICK */ 709 /* Forget it if we can't probe using SMBUS_QUICK */
705 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) 710 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
706 return -1; 711 return -1;
707 712
708 for (addr = 0x00; addr <= 0x7f; addr++) { 713 /* Force entries are done first, and are not affected by ignore
709 714 entries */
710 /* Skip if already in use */ 715 if (address_data->forces) {
711 if (i2c_check_addr(adapter,addr)) 716 unsigned short **forces = address_data->forces;
712 continue; 717 int kind;
713 718
714 /* If it is in one of the force entries, we don't do any detection 719 for (kind = 0; forces[kind]; kind++) {
715 at all */ 720 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
716 found = 0; 721 i += 2) {
717 722 if (forces[kind][i] == adap_id
718 for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 2) { 723 || forces[kind][i] == ANY_I2C_BUS) {
719 if (((adap_id == address_data->force[i]) || 724 dev_dbg(&adapter->dev, "found force "
720 (address_data->force[i] == ANY_I2C_BUS)) && 725 "parameter for adapter %d, "
721 (addr == address_data->force[i+1])) { 726 "addr 0x%02x, kind %d\n",
722 dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", 727 adap_id, forces[kind][i + 1],
723 adap_id, addr); 728 kind);
724 if ((err = found_proc(adapter,addr,0))) 729 err = i2c_probe_address(adapter,
725 return err; 730 forces[kind][i + 1],
726 found = 1; 731 kind, found_proc);
727 } 732 if (err)
728 } 733 return err;
729 if (found) 734 }
730 continue;
731
732 /* If this address is in one of the ignores, we can forget about
733 it right now */
734 for (i = 0;
735 !found && (address_data->ignore[i] != I2C_CLIENT_END);
736 i += 2) {
737 if (((adap_id == address_data->ignore[i]) ||
738 ((address_data->ignore[i] == ANY_I2C_BUS))) &&
739 (addr == address_data->ignore[i+1])) {
740 dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, "
741 "addr %04x\n", adap_id ,addr);
742 found = 1;
743 }
744 }
745 for (i = 0;
746 !found && (address_data->ignore_range[i] != I2C_CLIENT_END);
747 i += 3) {
748 if (((adap_id == address_data->ignore_range[i]) ||
749 ((address_data->ignore_range[i]==ANY_I2C_BUS))) &&
750 (addr >= address_data->ignore_range[i+1]) &&
751 (addr <= address_data->ignore_range[i+2])) {
752 dev_dbg(&adapter->dev, "found ignore_range parameter for adapter %d, "
753 "addr %04x\n", adap_id,addr);
754 found = 1;
755 }
756 }
757 if (found)
758 continue;
759
760 /* Now, we will do a detection, but only if it is in the normal or
761 probe entries */
762 for (i = 0;
763 !found && (address_data->normal_i2c[i] != I2C_CLIENT_END);
764 i += 1) {
765 if (addr == address_data->normal_i2c[i]) {
766 found = 1;
767 dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, "
768 "addr %02x\n", adap_id, addr);
769 } 735 }
770 } 736 }
737 }
771 738
772 for (i = 0; 739 /* Probe entries are done second, and are not affected by ignore
773 !found && (address_data->normal_i2c_range[i] != I2C_CLIENT_END); 740 entries either */
774 i += 2) { 741 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
775 if ((addr >= address_data->normal_i2c_range[i]) && 742 if (address_data->probe[i] == adap_id
776 (addr <= address_data->normal_i2c_range[i+1])) { 743 || address_data->probe[i] == ANY_I2C_BUS) {
777 found = 1; 744 dev_dbg(&adapter->dev, "found probe parameter for "
778 dev_dbg(&adapter->dev, "found normal i2c_range entry for adapter %d, " 745 "adapter %d, addr 0x%02x\n", adap_id,
779 "addr %04x\n", adap_id,addr); 746 address_data->probe[i + 1]);
780 } 747 err = i2c_probe_address(adapter,
748 address_data->probe[i + 1],
749 -1, found_proc);
750 if (err)
751 return err;
781 } 752 }
753 }
782 754
783 for (i = 0; 755 /* Normal entries are done last, unless shadowed by an ignore entry */
784 !found && (address_data->probe[i] != I2C_CLIENT_END); 756 for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) {
785 i += 2) { 757 int j, ignore;
786 if (((adap_id == address_data->probe[i]) || 758
787 ((address_data->probe[i] == ANY_I2C_BUS))) && 759 ignore = 0;
788 (addr == address_data->probe[i+1])) { 760 for (j = 0; address_data->ignore[j] != I2C_CLIENT_END;
789 found = 1; 761 j += 2) {
790 dev_dbg(&adapter->dev, "found probe parameter for adapter %d, " 762 if ((address_data->ignore[j] == adap_id ||
791 "addr %04x\n", adap_id,addr); 763 address_data->ignore[j] == ANY_I2C_BUS)
792 } 764 && address_data->ignore[j + 1]
793 } 765 == address_data->normal_i2c[i]) {
794 for (i = 0; 766 dev_dbg(&adapter->dev, "found ignore "
795 !found && (address_data->probe_range[i] != I2C_CLIENT_END); 767 "parameter for adapter %d, "
796 i += 3) { 768 "addr 0x%02x\n", adap_id,
797 if (((adap_id == address_data->probe_range[i]) || 769 address_data->ignore[j + 1]);
798 (address_data->probe_range[i] == ANY_I2C_BUS)) &&
799 (addr >= address_data->probe_range[i+1]) &&
800 (addr <= address_data->probe_range[i+2])) {
801 found = 1;
802 dev_dbg(&adapter->dev, "found probe_range parameter for adapter %d, "
803 "addr %04x\n", adap_id,addr);
804 } 770 }
771 ignore = 1;
772 break;
805 } 773 }
806 if (!found) 774 if (ignore)
807 continue; 775 continue;
808 776
809 /* OK, so we really should examine this address. First check 777 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
810 whether there is some client here at all! */ 778 "addr 0x%02x\n", adap_id,
811 if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) 779 address_data->normal_i2c[i]);
812 if ((err = found_proc(adapter,addr,-1))) 780 err = i2c_probe_address(adapter, address_data->normal_i2c[i],
813 return err; 781 -1, found_proc);
782 if (err)
783 return err;
814 } 784 }
815 return 0;
816}
817 785
818/* 786 return 0;
819 * return id number for a specific adapter
820 */
821int i2c_adapter_id(struct i2c_adapter *adap)
822{
823 return adap->nr;
824} 787}
825 788
826struct i2c_adapter* i2c_get_adapter(int id) 789struct i2c_adapter* i2c_get_adapter(int id)
827{ 790{
828 struct list_head *item;
829 struct i2c_adapter *adapter; 791 struct i2c_adapter *adapter;
830 792
831 down(&core_lists); 793 down(&core_lists);
832 list_for_each(item,&adapters) { 794 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
833 adapter = list_entry(item, struct i2c_adapter, list); 795 if (adapter && !try_module_get(adapter->owner))
834 if (id == adapter->nr && 796 adapter = NULL;
835 try_module_get(adapter->owner)) { 797
836 up(&core_lists);
837 return adapter;
838 }
839 }
840 up(&core_lists); 798 up(&core_lists);
841 return NULL; 799 return adapter;
842} 800}
843 801
844void i2c_put_adapter(struct i2c_adapter *adap) 802void i2c_put_adapter(struct i2c_adapter *adap)
@@ -1236,6 +1194,12 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1236} 1194}
1237 1195
1238 1196
1197/* Next four are needed by i2c-isa */
1198EXPORT_SYMBOL_GPL(i2c_adapter_dev_release);
1199EXPORT_SYMBOL_GPL(i2c_adapter_driver);
1200EXPORT_SYMBOL_GPL(i2c_adapter_class);
1201EXPORT_SYMBOL_GPL(i2c_bus_type);
1202
1239EXPORT_SYMBOL(i2c_add_adapter); 1203EXPORT_SYMBOL(i2c_add_adapter);
1240EXPORT_SYMBOL(i2c_del_adapter); 1204EXPORT_SYMBOL(i2c_del_adapter);
1241EXPORT_SYMBOL(i2c_add_driver); 1205EXPORT_SYMBOL(i2c_add_driver);
@@ -1251,7 +1215,6 @@ EXPORT_SYMBOL(i2c_master_send);
1251EXPORT_SYMBOL(i2c_master_recv); 1215EXPORT_SYMBOL(i2c_master_recv);
1252EXPORT_SYMBOL(i2c_control); 1216EXPORT_SYMBOL(i2c_control);
1253EXPORT_SYMBOL(i2c_transfer); 1217EXPORT_SYMBOL(i2c_transfer);
1254EXPORT_SYMBOL(i2c_adapter_id);
1255EXPORT_SYMBOL(i2c_get_adapter); 1218EXPORT_SYMBOL(i2c_get_adapter);
1256EXPORT_SYMBOL(i2c_put_adapter); 1219EXPORT_SYMBOL(i2c_put_adapter);
1257EXPORT_SYMBOL(i2c_probe); 1220EXPORT_SYMBOL(i2c_probe);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 86c4d0149e82..aa7a4fadef64 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -29,7 +29,6 @@
29/* The devfs code is contributed by Philipp Matthias Hahn 29/* The devfs code is contributed by Philipp Matthias Hahn
30 <pmhahn@titan.lahn.de> */ 30 <pmhahn@titan.lahn.de> */
31 31
32#include <linux/config.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/module.h> 33#include <linux/module.h>
35#include <linux/fs.h> 34#include <linux/fs.h>
@@ -214,7 +213,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
214 sizeof(rdwr_arg))) 213 sizeof(rdwr_arg)))
215 return -EFAULT; 214 return -EFAULT;
216 215
217 /* Put an arbritrary limit on the number of messages that can 216 /* Put an arbitrary limit on the number of messages that can
218 * be sent at once */ 217 * be sent at once */
219 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 218 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
220 return -EINVAL; 219 return -EINVAL;
@@ -435,7 +434,8 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
435 434
436 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor), 435 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor),
437 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor); 436 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor);
438 dev_dbg(&adap->dev, "Registered as minor %d\n", i2c_dev->minor); 437 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
438 adap->name, i2c_dev->minor);
439 439
440 /* register this i2c device with the driver core */ 440 /* register this i2c device with the driver core */
441 i2c_dev->adap = adap; 441 i2c_dev->adap = adap;
@@ -472,7 +472,7 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
472 wait_for_completion(&i2c_dev->released); 472 wait_for_completion(&i2c_dev->released);
473 kfree(i2c_dev); 473 kfree(i2c_dev);
474 474
475 dev_dbg(&adap->dev, "Adapter unregistered\n"); 475 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
476 return 0; 476 return 0;
477} 477}
478 478
diff --git a/drivers/i2c/i2c-sensor-detect.c b/drivers/i2c/i2c-sensor-detect.c
deleted file mode 100644
index f99a8161a9f1..000000000000
--- a/drivers/i2c/i2c-sensor-detect.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 i2c-sensor-detect.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl> and
5 Mark D. Studebaker <mdsxyz123@yahoo.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/i2c.h>
25#include <linux/i2c-sensor.h>
26
27static unsigned short empty[] = {I2C_CLIENT_END};
28static unsigned int empty_isa[] = {I2C_CLIENT_ISA_END};
29
30/* Very inefficient for ISA detects, and won't work for 10-bit addresses! */
31int i2c_detect(struct i2c_adapter *adapter,
32 struct i2c_address_data *address_data,
33 int (*found_proc) (struct i2c_adapter *, int, int))
34{
35 int addr, i, found, j, err;
36 struct i2c_force_data *this_force;
37 int is_isa = i2c_is_isa_adapter(adapter);
38 int adapter_id =
39 is_isa ? ANY_I2C_ISA_BUS : i2c_adapter_id(adapter);
40 unsigned short *normal_i2c;
41 unsigned int *normal_isa;
42 unsigned short *probe;
43 unsigned short *ignore;
44
45 /* Forget it if we can't probe using SMBUS_QUICK */
46 if ((!is_isa) &&
47 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK))
48 return -1;
49
50 /* Use default "empty" list if the adapter doesn't specify any */
51 normal_i2c = probe = ignore = empty;
52 normal_isa = empty_isa;
53 if (address_data->normal_i2c)
54 normal_i2c = address_data->normal_i2c;
55 if (address_data->normal_isa)
56 normal_isa = address_data->normal_isa;
57 if (address_data->probe)
58 probe = address_data->probe;
59 if (address_data->ignore)
60 ignore = address_data->ignore;
61
62 for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) {
63 if (!is_isa && i2c_check_addr(adapter, addr))
64 continue;
65
66 /* If it is in one of the force entries, we don't do any
67 detection at all */
68 found = 0;
69 for (i = 0; !found && (this_force = address_data->forces + i, this_force->force); i++) {
70 for (j = 0; !found && (this_force->force[j] != I2C_CLIENT_END); j += 2) {
71 if ( ((adapter_id == this_force->force[j]) ||
72 ((this_force->force[j] == ANY_I2C_BUS) && !is_isa)) &&
73 (addr == this_force->force[j + 1]) ) {
74 dev_dbg(&adapter->dev, "found force parameter for adapter %d, addr %04x\n", adapter_id, addr);
75 if ((err = found_proc(adapter, addr, this_force->kind)))
76 return err;
77 found = 1;
78 }
79 }
80 }
81 if (found)
82 continue;
83
84 /* If this address is in one of the ignores, we can forget about it
85 right now */
86 for (i = 0; !found && (ignore[i] != I2C_CLIENT_END); i += 2) {
87 if ( ((adapter_id == ignore[i]) ||
88 ((ignore[i] == ANY_I2C_BUS) &&
89 !is_isa)) &&
90 (addr == ignore[i + 1])) {
91 dev_dbg(&adapter->dev, "found ignore parameter for adapter %d, addr %04x\n", adapter_id, addr);
92 found = 1;
93 }
94 }
95 if (found)
96 continue;
97
98 /* Now, we will do a detection, but only if it is in the normal or
99 probe entries */
100 if (is_isa) {
101 for (i = 0; !found && (normal_isa[i] != I2C_CLIENT_ISA_END); i += 1) {
102 if (addr == normal_isa[i]) {
103 dev_dbg(&adapter->dev, "found normal isa entry for adapter %d, addr %04x\n", adapter_id, addr);
104 found = 1;
105 }
106 }
107 } else {
108 for (i = 0; !found && (normal_i2c[i] != I2C_CLIENT_END); i += 1) {
109 if (addr == normal_i2c[i]) {
110 found = 1;
111 dev_dbg(&adapter->dev, "found normal i2c entry for adapter %d, addr %02x\n", adapter_id, addr);
112 }
113 }
114 }
115
116 for (i = 0;
117 !found && (probe[i] != I2C_CLIENT_END);
118 i += 2) {
119 if (((adapter_id == probe[i]) ||
120 ((probe[i] == ANY_I2C_BUS) && !is_isa))
121 && (addr == probe[i + 1])) {
122 dev_dbg(&adapter->dev, "found probe parameter for adapter %d, addr %04x\n", adapter_id, addr);
123 found = 1;
124 }
125 }
126 if (!found)
127 continue;
128
129 /* OK, so we really should examine this address. First check
130 whether there is some client here at all! */
131 if (is_isa ||
132 (i2c_smbus_xfer (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0))
133 if ((err = found_proc(adapter, addr, -1)))
134 return err;
135 }
136 return 0;
137}
138
139EXPORT_SYMBOL(i2c_detect);
140
141MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
142 "Rudolf Marek <r.marek@sh.cvut.cz>");
143
144MODULE_DESCRIPTION("i2c-sensor driver");
145MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/i2c-sensor-vid.c b/drivers/i2c/i2c-sensor-vid.c
deleted file mode 100644
index 922e22f054bb..000000000000
--- a/drivers/i2c/i2c-sensor-vid.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/*
2 i2c-sensor-vid.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <linux/config.h>
23#include <linux/module.h>
24#include <linux/kernel.h>
25
26struct vrm_model {
27 u8 vendor;
28 u8 eff_family;
29 u8 eff_model;
30 int vrm_type;
31};
32
33#define ANY 0xFF
34
35#ifdef CONFIG_X86
36
37static struct vrm_model vrm_models[] = {
38 {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */
39 {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */
40 {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */
41 {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* 0xB Tualatin */
42 {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */
43 {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */
44 {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */
45 {X86_VENDOR_INTEL, 0xF, ANY, 90}, /* P4 before Prescott */
46 {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */
47 {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */
48 };
49
50static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor)
51{
52 int i = 0;
53
54 while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) {
55 if (vrm_models[i].vendor==vendor)
56 if ((vrm_models[i].eff_family==eff_family)&& \
57 ((vrm_models[i].eff_model==eff_model)|| \
58 (vrm_models[i].eff_model==ANY)))
59 return vrm_models[i].vrm_type;
60 i++;
61 }
62
63 return 0;
64}
65
66int i2c_which_vrm(void)
67{
68 struct cpuinfo_x86 *c = cpu_data;
69 u32 eax;
70 u8 eff_family, eff_model;
71 int vrm_ret;
72
73 if (c->x86 < 6) return 0; /* any CPU with familly lower than 6
74 dont have VID and/or CPUID */
75 eax = cpuid_eax(1);
76 eff_family = ((eax & 0x00000F00)>>8);
77 eff_model = ((eax & 0x000000F0)>>4);
78 if (eff_family == 0xF) { /* use extended model & family */
79 eff_family += ((eax & 0x00F00000)>>20);
80 eff_model += ((eax & 0x000F0000)>>16)<<4;
81 }
82 vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor);
83 if (vrm_ret == 0)
84 printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your"
85 " x86 CPU\n");
86 return vrm_ret;
87}
88
89/* and now for something completely different for Non-x86 world*/
90#else
91int i2c_which_vrm(void)
92{
93 printk(KERN_INFO "i2c-sensor.o: Unknown VRM version of your CPU\n");
94 return 0;
95}
96#endif
97
98EXPORT_SYMBOL(i2c_which_vrm);