aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/it87.c
diff options
context:
space:
mode:
authorcorentin.labbe <corentin.labbe@geomatys.fr>2007-06-13 14:27:36 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-07-19 14:22:14 -0400
commitb74f3fdd98c7186930b8ee841dc542dfdba95473 (patch)
treea154e178724a40cd7b82634ad9d0cb4b538786e3 /drivers/hwmon/it87.c
parent04a6217df28e3004ba4e76eb0a356a30f72c564f (diff)
hwmon: convert it87 to platform driver
This is the patch for converting it87 to a platform driver (and remove i2c-isa). Signed-off-by: Corentin LABBE <corentin.labbe@geomatys.fr> Acked-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r--drivers/hwmon/it87.c496
1 files changed, 277 insertions, 219 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 1dd7654cf00b..eff6036e15c0 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -31,8 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/jiffies.h> 33#include <linux/jiffies.h>
34#include <linux/i2c.h> 34#include <linux/platform_device.h>
35#include <linux/i2c-isa.h>
36#include <linux/hwmon.h> 35#include <linux/hwmon.h>
37#include <linux/hwmon-sysfs.h> 36#include <linux/hwmon-sysfs.h>
38#include <linux/hwmon-vid.h> 37#include <linux/hwmon-vid.h>
@@ -41,10 +40,12 @@
41#include <linux/sysfs.h> 40#include <linux/sysfs.h>
42#include <asm/io.h> 41#include <asm/io.h>
43 42
43#define DRVNAME "it87"
44 44
45static unsigned short isa_address;
46enum chips { it87, it8712, it8716, it8718 }; 45enum chips { it87, it8712, it8716, it8718 };
47 46
47static struct platform_device *pdev;
48
48#define REG 0x2e /* The register to read/write */ 49#define REG 0x2e /* The register to read/write */
49#define DEV 0x07 /* Register: Logical device select */ 50#define DEV 0x07 /* Register: Logical device select */
50#define VAL 0x2f /* The value to read/write */ 51#define VAL 0x2f /* The value to read/write */
@@ -112,10 +113,6 @@ static int update_vbat;
112/* Not all BIOSes properly configure the PWM registers */ 113/* Not all BIOSes properly configure the PWM registers */
113static int fix_pwm_polarity; 114static int fix_pwm_polarity;
114 115
115/* Values read from Super-I/O config space */
116static u16 chip_type;
117static u8 vid_value;
118
119/* Many IT87 constants specified below */ 116/* Many IT87 constants specified below */
120 117
121/* Length of ISA address segment */ 118/* Length of ISA address segment */
@@ -216,13 +213,20 @@ static const unsigned int pwm_freq[8] = {
216}; 213};
217 214
218 215
216struct it87_sio_data {
217 enum chips type;
218 /* Values read from Super-I/O config space */
219 u8 vid_value;
220};
221
219/* For each registered chip, we need to keep some data in memory. 222/* For each registered chip, we need to keep some data in memory.
220 The structure is dynamically allocated. */ 223 The structure is dynamically allocated. */
221struct it87_data { 224struct it87_data {
222 struct i2c_client client;
223 struct class_device *class_dev; 225 struct class_device *class_dev;
224 enum chips type; 226 enum chips type;
225 227
228 unsigned short addr;
229 const char *name;
226 struct mutex update_lock; 230 struct mutex update_lock;
227 char valid; /* !=0 if following fields are valid */ 231 char valid; /* !=0 if following fields are valid */
228 unsigned long last_updated; /* In jiffies */ 232 unsigned long last_updated; /* In jiffies */
@@ -247,26 +251,25 @@ struct it87_data {
247}; 251};
248 252
249 253
250static int it87_detect(struct i2c_adapter *adapter); 254static int it87_probe(struct platform_device *pdev);
251static int it87_detach_client(struct i2c_client *client); 255static int it87_remove(struct platform_device *pdev);
252 256
253static int it87_read_value(struct i2c_client *client, u8 reg); 257static int it87_read_value(struct it87_data *data, u8 reg);
254static void it87_write_value(struct i2c_client *client, u8 reg, u8 value); 258static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
255static struct it87_data *it87_update_device(struct device *dev); 259static struct it87_data *it87_update_device(struct device *dev);
256static int it87_check_pwm(struct i2c_client *client); 260static int it87_check_pwm(struct device *dev);
257static void it87_init_client(struct i2c_client *client, struct it87_data *data); 261static void it87_init_device(struct platform_device *pdev);
258 262
259 263
260static struct i2c_driver it87_isa_driver = { 264static struct platform_driver it87_driver = {
261 .driver = { 265 .driver = {
262 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
263 .name = "it87-isa", 267 .name = DRVNAME,
264 }, 268 },
265 .attach_adapter = it87_detect, 269 .probe = it87_probe,
266 .detach_client = it87_detach_client, 270 .remove = __devexit_p(it87_remove),
267}; 271};
268 272
269
270static ssize_t show_in(struct device *dev, struct device_attribute *attr, 273static ssize_t show_in(struct device *dev, struct device_attribute *attr,
271 char *buf) 274 char *buf)
272{ 275{
@@ -303,13 +306,12 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
303 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 306 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
304 int nr = sensor_attr->index; 307 int nr = sensor_attr->index;
305 308
306 struct i2c_client *client = to_i2c_client(dev); 309 struct it87_data *data = dev_get_drvdata(dev);
307 struct it87_data *data = i2c_get_clientdata(client);
308 unsigned long val = simple_strtoul(buf, NULL, 10); 310 unsigned long val = simple_strtoul(buf, NULL, 10);
309 311
310 mutex_lock(&data->update_lock); 312 mutex_lock(&data->update_lock);
311 data->in_min[nr] = IN_TO_REG(val); 313 data->in_min[nr] = IN_TO_REG(val);
312 it87_write_value(client, IT87_REG_VIN_MIN(nr), 314 it87_write_value(data, IT87_REG_VIN_MIN(nr),
313 data->in_min[nr]); 315 data->in_min[nr]);
314 mutex_unlock(&data->update_lock); 316 mutex_unlock(&data->update_lock);
315 return count; 317 return count;
@@ -320,13 +322,12 @@ static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
320 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 322 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
321 int nr = sensor_attr->index; 323 int nr = sensor_attr->index;
322 324
323 struct i2c_client *client = to_i2c_client(dev); 325 struct it87_data *data = dev_get_drvdata(dev);
324 struct it87_data *data = i2c_get_clientdata(client);
325 unsigned long val = simple_strtoul(buf, NULL, 10); 326 unsigned long val = simple_strtoul(buf, NULL, 10);
326 327
327 mutex_lock(&data->update_lock); 328 mutex_lock(&data->update_lock);
328 data->in_max[nr] = IN_TO_REG(val); 329 data->in_max[nr] = IN_TO_REG(val);
329 it87_write_value(client, IT87_REG_VIN_MAX(nr), 330 it87_write_value(data, IT87_REG_VIN_MAX(nr),
330 data->in_max[nr]); 331 data->in_max[nr]);
331 mutex_unlock(&data->update_lock); 332 mutex_unlock(&data->update_lock);
332 return count; 333 return count;
@@ -394,13 +395,12 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
394 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 395 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
395 int nr = sensor_attr->index; 396 int nr = sensor_attr->index;
396 397
397 struct i2c_client *client = to_i2c_client(dev); 398 struct it87_data *data = dev_get_drvdata(dev);
398 struct it87_data *data = i2c_get_clientdata(client);
399 int val = simple_strtol(buf, NULL, 10); 399 int val = simple_strtol(buf, NULL, 10);
400 400
401 mutex_lock(&data->update_lock); 401 mutex_lock(&data->update_lock);
402 data->temp_high[nr] = TEMP_TO_REG(val); 402 data->temp_high[nr] = TEMP_TO_REG(val);
403 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); 403 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
404 mutex_unlock(&data->update_lock); 404 mutex_unlock(&data->update_lock);
405 return count; 405 return count;
406} 406}
@@ -410,13 +410,12 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
410 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 410 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
411 int nr = sensor_attr->index; 411 int nr = sensor_attr->index;
412 412
413 struct i2c_client *client = to_i2c_client(dev); 413 struct it87_data *data = dev_get_drvdata(dev);
414 struct it87_data *data = i2c_get_clientdata(client);
415 int val = simple_strtol(buf, NULL, 10); 414 int val = simple_strtol(buf, NULL, 10);
416 415
417 mutex_lock(&data->update_lock); 416 mutex_lock(&data->update_lock);
418 data->temp_low[nr] = TEMP_TO_REG(val); 417 data->temp_low[nr] = TEMP_TO_REG(val);
419 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); 418 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
420 mutex_unlock(&data->update_lock); 419 mutex_unlock(&data->update_lock);
421 return count; 420 return count;
422} 421}
@@ -453,8 +452,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
453 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 452 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
454 int nr = sensor_attr->index; 453 int nr = sensor_attr->index;
455 454
456 struct i2c_client *client = to_i2c_client(dev); 455 struct it87_data *data = dev_get_drvdata(dev);
457 struct it87_data *data = i2c_get_clientdata(client);
458 int val = simple_strtol(buf, NULL, 10); 456 int val = simple_strtol(buf, NULL, 10);
459 457
460 mutex_lock(&data->update_lock); 458 mutex_lock(&data->update_lock);
@@ -470,7 +468,7 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
470 mutex_unlock(&data->update_lock); 468 mutex_unlock(&data->update_lock);
471 return -EINVAL; 469 return -EINVAL;
472 } 470 }
473 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); 471 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
474 mutex_unlock(&data->update_lock); 472 mutex_unlock(&data->update_lock);
475 return count; 473 return count;
476} 474}
@@ -544,13 +542,12 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
544 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 542 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
545 int nr = sensor_attr->index; 543 int nr = sensor_attr->index;
546 544
547 struct i2c_client *client = to_i2c_client(dev); 545 struct it87_data *data = dev_get_drvdata(dev);
548 struct it87_data *data = i2c_get_clientdata(client);
549 int val = simple_strtol(buf, NULL, 10); 546 int val = simple_strtol(buf, NULL, 10);
550 u8 reg; 547 u8 reg;
551 548
552 mutex_lock(&data->update_lock); 549 mutex_lock(&data->update_lock);
553 reg = it87_read_value(client, IT87_REG_FAN_DIV); 550 reg = it87_read_value(data, IT87_REG_FAN_DIV);
554 switch (nr) { 551 switch (nr) {
555 case 0: data->fan_div[nr] = reg & 0x07; break; 552 case 0: data->fan_div[nr] = reg & 0x07; break;
556 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; 553 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
@@ -558,7 +555,7 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
558 } 555 }
559 556
560 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 557 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
561 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 558 it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
562 mutex_unlock(&data->update_lock); 559 mutex_unlock(&data->update_lock);
563 return count; 560 return count;
564} 561}
@@ -568,14 +565,13 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
568 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 565 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
569 int nr = sensor_attr->index; 566 int nr = sensor_attr->index;
570 567
571 struct i2c_client *client = to_i2c_client(dev); 568 struct it87_data *data = dev_get_drvdata(dev);
572 struct it87_data *data = i2c_get_clientdata(client);
573 unsigned long val = simple_strtoul(buf, NULL, 10); 569 unsigned long val = simple_strtoul(buf, NULL, 10);
574 int min; 570 int min;
575 u8 old; 571 u8 old;
576 572
577 mutex_lock(&data->update_lock); 573 mutex_lock(&data->update_lock);
578 old = it87_read_value(client, IT87_REG_FAN_DIV); 574 old = it87_read_value(data, IT87_REG_FAN_DIV);
579 575
580 /* Save fan min limit */ 576 /* Save fan min limit */
581 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); 577 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
@@ -596,11 +592,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
596 val |= (data->fan_div[1] & 0x07) << 3; 592 val |= (data->fan_div[1] & 0x07) << 3;
597 if (data->fan_div[2] == 3) 593 if (data->fan_div[2] == 3)
598 val |= 0x1 << 6; 594 val |= 0x1 << 6;
599 it87_write_value(client, IT87_REG_FAN_DIV, val); 595 it87_write_value(data, IT87_REG_FAN_DIV, val);
600 596
601 /* Restore fan min limit */ 597 /* Restore fan min limit */
602 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 598 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
603 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); 599 it87_write_value(data, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
604 600
605 mutex_unlock(&data->update_lock); 601 mutex_unlock(&data->update_lock);
606 return count; 602 return count;
@@ -611,8 +607,7 @@ static ssize_t set_pwm_enable(struct device *dev,
611 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 607 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
612 int nr = sensor_attr->index; 608 int nr = sensor_attr->index;
613 609
614 struct i2c_client *client = to_i2c_client(dev); 610 struct it87_data *data = dev_get_drvdata(dev);
615 struct it87_data *data = i2c_get_clientdata(client);
616 int val = simple_strtol(buf, NULL, 10); 611 int val = simple_strtol(buf, NULL, 10);
617 612
618 mutex_lock(&data->update_lock); 613 mutex_lock(&data->update_lock);
@@ -620,17 +615,17 @@ static ssize_t set_pwm_enable(struct device *dev,
620 if (val == 0) { 615 if (val == 0) {
621 int tmp; 616 int tmp;
622 /* make sure the fan is on when in on/off mode */ 617 /* make sure the fan is on when in on/off mode */
623 tmp = it87_read_value(client, IT87_REG_FAN_CTL); 618 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
624 it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); 619 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
625 /* set on/off mode */ 620 /* set on/off mode */
626 data->fan_main_ctrl &= ~(1 << nr); 621 data->fan_main_ctrl &= ~(1 << nr);
627 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 622 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
628 } else if (val == 1) { 623 } else if (val == 1) {
629 /* set SmartGuardian mode */ 624 /* set SmartGuardian mode */
630 data->fan_main_ctrl |= (1 << nr); 625 data->fan_main_ctrl |= (1 << nr);
631 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 626 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
632 /* set saved pwm value, clear FAN_CTLX PWM mode bit */ 627 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
633 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 628 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
634 } else { 629 } else {
635 mutex_unlock(&data->update_lock); 630 mutex_unlock(&data->update_lock);
636 return -EINVAL; 631 return -EINVAL;
@@ -645,8 +640,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
645 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 640 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
646 int nr = sensor_attr->index; 641 int nr = sensor_attr->index;
647 642
648 struct i2c_client *client = to_i2c_client(dev); 643 struct it87_data *data = dev_get_drvdata(dev);
649 struct it87_data *data = i2c_get_clientdata(client);
650 int val = simple_strtol(buf, NULL, 10); 644 int val = simple_strtol(buf, NULL, 10);
651 645
652 if (val < 0 || val > 255) 646 if (val < 0 || val > 255)
@@ -655,15 +649,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
655 mutex_lock(&data->update_lock); 649 mutex_lock(&data->update_lock);
656 data->manual_pwm_ctl[nr] = val; 650 data->manual_pwm_ctl[nr] = val;
657 if (data->fan_main_ctrl & (1 << nr)) 651 if (data->fan_main_ctrl & (1 << nr))
658 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); 652 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
659 mutex_unlock(&data->update_lock); 653 mutex_unlock(&data->update_lock);
660 return count; 654 return count;
661} 655}
662static ssize_t set_pwm_freq(struct device *dev, 656static ssize_t set_pwm_freq(struct device *dev,
663 struct device_attribute *attr, const char *buf, size_t count) 657 struct device_attribute *attr, const char *buf, size_t count)
664{ 658{
665 struct i2c_client *client = to_i2c_client(dev); 659 struct it87_data *data = dev_get_drvdata(dev);
666 struct it87_data *data = i2c_get_clientdata(client);
667 unsigned long val = simple_strtoul(buf, NULL, 10); 660 unsigned long val = simple_strtoul(buf, NULL, 10);
668 int i; 661 int i;
669 662
@@ -674,9 +667,9 @@ static ssize_t set_pwm_freq(struct device *dev,
674 } 667 }
675 668
676 mutex_lock(&data->update_lock); 669 mutex_lock(&data->update_lock);
677 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL) & 0x8f; 670 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
678 data->fan_ctl |= i << 4; 671 data->fan_ctl |= i << 4;
679 it87_write_value(client, IT87_REG_FAN_CTL, data->fan_ctl); 672 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
680 mutex_unlock(&data->update_lock); 673 mutex_unlock(&data->update_lock);
681 674
682 return count; 675 return count;
@@ -731,15 +724,14 @@ static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
731{ 724{
732 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 725 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
733 int nr = sensor_attr->index; 726 int nr = sensor_attr->index;
734 struct i2c_client *client = to_i2c_client(dev); 727 struct it87_data *data = dev_get_drvdata(dev);
735 struct it87_data *data = i2c_get_clientdata(client);
736 int val = simple_strtol(buf, NULL, 10); 728 int val = simple_strtol(buf, NULL, 10);
737 729
738 mutex_lock(&data->update_lock); 730 mutex_lock(&data->update_lock);
739 data->fan_min[nr] = FAN16_TO_REG(val); 731 data->fan_min[nr] = FAN16_TO_REG(val);
740 it87_write_value(client, IT87_REG_FAN_MIN(nr), 732 it87_write_value(data, IT87_REG_FAN_MIN(nr),
741 data->fan_min[nr] & 0xff); 733 data->fan_min[nr] & 0xff);
742 it87_write_value(client, IT87_REG_FANX_MIN(nr), 734 it87_write_value(data, IT87_REG_FANX_MIN(nr),
743 data->fan_min[nr] >> 8); 735 data->fan_min[nr] >> 8);
744 mutex_unlock(&data->update_lock); 736 mutex_unlock(&data->update_lock);
745 return count; 737 return count;
@@ -777,8 +769,7 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
777static ssize_t 769static ssize_t
778store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 770store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
779{ 771{
780 struct i2c_client *client = to_i2c_client(dev); 772 struct it87_data *data = dev_get_drvdata(dev);
781 struct it87_data *data = i2c_get_clientdata(client);
782 u32 val; 773 u32 val;
783 774
784 val = simple_strtoul(buf, NULL, 10); 775 val = simple_strtoul(buf, NULL, 10);
@@ -796,6 +787,14 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
796} 787}
797static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 788static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
798 789
790static ssize_t show_name(struct device *dev, struct device_attribute
791 *devattr, char *buf)
792{
793 struct it87_data *data = dev_get_drvdata(dev);
794 return sprintf(buf, "%s\n", data->name);
795}
796static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
797
799static struct attribute *it87_attributes[] = { 798static struct attribute *it87_attributes[] = {
800 &sensor_dev_attr_in0_input.dev_attr.attr, 799 &sensor_dev_attr_in0_input.dev_attr.attr,
801 &sensor_dev_attr_in1_input.dev_attr.attr, 800 &sensor_dev_attr_in1_input.dev_attr.attr,
@@ -837,6 +836,7 @@ static struct attribute *it87_attributes[] = {
837 &sensor_dev_attr_temp3_type.dev_attr.attr, 836 &sensor_dev_attr_temp3_type.dev_attr.attr,
838 837
839 &dev_attr_alarms.attr, 838 &dev_attr_alarms.attr,
839 &dev_attr_name.attr,
840 NULL 840 NULL
841}; 841};
842 842
@@ -879,18 +879,36 @@ static const struct attribute_group it87_group_opt = {
879}; 879};
880 880
881/* SuperIO detection - will change isa_address if a chip is found */ 881/* SuperIO detection - will change isa_address if a chip is found */
882static int __init it87_find(unsigned short *address) 882static int __init it87_find(unsigned short *address,
883 struct it87_sio_data *sio_data)
883{ 884{
884 int err = -ENODEV; 885 int err = -ENODEV;
886 u16 chip_type;
885 887
886 superio_enter(); 888 superio_enter();
887 chip_type = superio_inw(DEVID); 889 chip_type = superio_inw(DEVID);
888 if (chip_type != IT8712F_DEVID 890
889 && chip_type != IT8716F_DEVID 891 switch (chip_type) {
890 && chip_type != IT8726F_DEVID 892 case IT8705F_DEVID:
891 && chip_type != IT8718F_DEVID 893 sio_data->type = it87;
892 && chip_type != IT8705F_DEVID) 894 break;
893 goto exit; 895 case IT8712F_DEVID:
896 sio_data->type = it8712;
897 break;
898 case IT8716F_DEVID:
899 case IT8726F_DEVID:
900 sio_data->type = it8716;
901 break;
902 case IT8718F_DEVID:
903 sio_data->type = it8718;
904 break;
905 case 0xffff: /* No device at all */
906 goto exit;
907 default:
908 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
909 chip_type);
910 goto exit;
911 }
894 912
895 superio_select(PME); 913 superio_select(PME);
896 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 914 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
@@ -914,7 +932,7 @@ static int __init it87_find(unsigned short *address)
914 932
915 superio_select(GPIO); 933 superio_select(GPIO);
916 if (chip_type == it8718) 934 if (chip_type == it8718)
917 vid_value = superio_inb(IT87_SIO_VID_REG); 935 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
918 936
919 reg = superio_inb(IT87_SIO_PINX2_REG); 937 reg = superio_inb(IT87_SIO_PINX2_REG);
920 if (reg & (1 << 0)) 938 if (reg & (1 << 0))
@@ -928,18 +946,26 @@ exit:
928 return err; 946 return err;
929} 947}
930 948
931/* This function is called by i2c_probe */ 949static int __devinit it87_probe(struct platform_device *pdev)
932static int it87_detect(struct i2c_adapter *adapter)
933{ 950{
934 struct i2c_client *new_client;
935 struct it87_data *data; 951 struct it87_data *data;
952 struct resource *res;
953 struct device *dev = &pdev->dev;
954 struct it87_sio_data *sio_data = dev->platform_data;
936 int err = 0; 955 int err = 0;
937 const char *name;
938 int enable_pwm_interface; 956 int enable_pwm_interface;
939 957 static const char *names[] = {
940 /* Reserve the ISA region */ 958 "it87",
941 if (!request_region(isa_address, IT87_EXTENT, 959 "it8712",
942 it87_isa_driver.driver.name)){ 960 "it8716",
961 "it8718",
962 };
963
964 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
965 if (!request_region(res->start, IT87_EXTENT, DRVNAME)) {
966 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
967 (unsigned long)res->start,
968 (unsigned long)(res->start + IT87_EXTENT - 1));
943 err = -EBUSY; 969 err = -EBUSY;
944 goto ERROR0; 970 goto ERROR0;
945 } 971 }
@@ -949,131 +975,104 @@ static int it87_detect(struct i2c_adapter *adapter)
949 goto ERROR1; 975 goto ERROR1;
950 } 976 }
951 977
952 new_client = &data->client; 978 data->addr = res->start;
953 i2c_set_clientdata(new_client, data); 979 data->type = sio_data->type;
954 new_client->addr = isa_address; 980 data->name = names[sio_data->type];
955 new_client->adapter = adapter;
956 new_client->driver = &it87_isa_driver;
957 981
958 /* Now, we do the remaining detection. */ 982 /* Now, we do the remaining detection. */
959 if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) 983 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
960 || it87_read_value(new_client, IT87_REG_CHIPID) != 0x90) { 984 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
961 err = -ENODEV; 985 err = -ENODEV;
962 goto ERROR2; 986 goto ERROR2;
963 } 987 }
964 988
965 /* Determine the chip type. */ 989 platform_set_drvdata(pdev, data);
966 switch (chip_type) {
967 case IT8712F_DEVID:
968 data->type = it8712;
969 name = "it8712";
970 break;
971 case IT8726F_DEVID:
972 /* fall through */
973 case IT8716F_DEVID:
974 data->type = it8716;
975 name = "it8716";
976 break;
977 case IT8718F_DEVID:
978 data->type = it8718;
979 name = "it8718";
980 break;
981 default:
982 data->type = it87;
983 name = "it87";
984 }
985 990
986 /* Fill in the remaining client fields and put it into the global list */
987 strlcpy(new_client->name, name, I2C_NAME_SIZE);
988 mutex_init(&data->update_lock); 991 mutex_init(&data->update_lock);
989 992
990 /* Tell the I2C layer a new client has arrived */
991 if ((err = i2c_attach_client(new_client)))
992 goto ERROR2;
993
994 /* Check PWM configuration */ 993 /* Check PWM configuration */
995 enable_pwm_interface = it87_check_pwm(new_client); 994 enable_pwm_interface = it87_check_pwm(dev);
996 995
997 /* Initialize the IT87 chip */ 996 /* Initialize the IT87 chip */
998 it87_init_client(new_client, data); 997 it87_init_device(pdev);
999 998
1000 /* Register sysfs hooks */ 999 /* Register sysfs hooks */
1001 if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group))) 1000 if ((err = sysfs_create_group(&dev->kobj, &it87_group)))
1002 goto ERROR3; 1001 goto ERROR2;
1003 1002
1004 /* Do not create fan files for disabled fans */ 1003 /* Do not create fan files for disabled fans */
1005 if (data->type == it8716 || data->type == it8718) { 1004 if (data->type == it8716 || data->type == it8718) {
1006 /* 16-bit tachometers */ 1005 /* 16-bit tachometers */
1007 if (data->has_fan & (1 << 0)) { 1006 if (data->has_fan & (1 << 0)) {
1008 if ((err = device_create_file(&new_client->dev, 1007 if ((err = device_create_file(dev,
1009 &sensor_dev_attr_fan1_input16.dev_attr)) 1008 &sensor_dev_attr_fan1_input16.dev_attr))
1010 || (err = device_create_file(&new_client->dev, 1009 || (err = device_create_file(dev,
1011 &sensor_dev_attr_fan1_min16.dev_attr))) 1010 &sensor_dev_attr_fan1_min16.dev_attr)))
1012 goto ERROR4; 1011 goto ERROR4;
1013 } 1012 }
1014 if (data->has_fan & (1 << 1)) { 1013 if (data->has_fan & (1 << 1)) {
1015 if ((err = device_create_file(&new_client->dev, 1014 if ((err = device_create_file(dev,
1016 &sensor_dev_attr_fan2_input16.dev_attr)) 1015 &sensor_dev_attr_fan2_input16.dev_attr))
1017 || (err = device_create_file(&new_client->dev, 1016 || (err = device_create_file(dev,
1018 &sensor_dev_attr_fan2_min16.dev_attr))) 1017 &sensor_dev_attr_fan2_min16.dev_attr)))
1019 goto ERROR4; 1018 goto ERROR4;
1020 } 1019 }
1021 if (data->has_fan & (1 << 2)) { 1020 if (data->has_fan & (1 << 2)) {
1022 if ((err = device_create_file(&new_client->dev, 1021 if ((err = device_create_file(dev,
1023 &sensor_dev_attr_fan3_input16.dev_attr)) 1022 &sensor_dev_attr_fan3_input16.dev_attr))
1024 || (err = device_create_file(&new_client->dev, 1023 || (err = device_create_file(dev,
1025 &sensor_dev_attr_fan3_min16.dev_attr))) 1024 &sensor_dev_attr_fan3_min16.dev_attr)))
1026 goto ERROR4; 1025 goto ERROR4;
1027 } 1026 }
1028 } else { 1027 } else {
1029 /* 8-bit tachometers with clock divider */ 1028 /* 8-bit tachometers with clock divider */
1030 if (data->has_fan & (1 << 0)) { 1029 if (data->has_fan & (1 << 0)) {
1031 if ((err = device_create_file(&new_client->dev, 1030 if ((err = device_create_file(dev,
1032 &sensor_dev_attr_fan1_input.dev_attr)) 1031 &sensor_dev_attr_fan1_input.dev_attr))
1033 || (err = device_create_file(&new_client->dev, 1032 || (err = device_create_file(dev,
1034 &sensor_dev_attr_fan1_min.dev_attr)) 1033 &sensor_dev_attr_fan1_min.dev_attr))
1035 || (err = device_create_file(&new_client->dev, 1034 || (err = device_create_file(dev,
1036 &sensor_dev_attr_fan1_div.dev_attr))) 1035 &sensor_dev_attr_fan1_div.dev_attr)))
1037 goto ERROR4; 1036 goto ERROR4;
1038 } 1037 }
1039 if (data->has_fan & (1 << 1)) { 1038 if (data->has_fan & (1 << 1)) {
1040 if ((err = device_create_file(&new_client->dev, 1039 if ((err = device_create_file(dev,
1041 &sensor_dev_attr_fan2_input.dev_attr)) 1040 &sensor_dev_attr_fan2_input.dev_attr))
1042 || (err = device_create_file(&new_client->dev, 1041 || (err = device_create_file(dev,
1043 &sensor_dev_attr_fan2_min.dev_attr)) 1042 &sensor_dev_attr_fan2_min.dev_attr))
1044 || (err = device_create_file(&new_client->dev, 1043 || (err = device_create_file(dev,
1045 &sensor_dev_attr_fan2_div.dev_attr))) 1044 &sensor_dev_attr_fan2_div.dev_attr)))
1046 goto ERROR4; 1045 goto ERROR4;
1047 } 1046 }
1048 if (data->has_fan & (1 << 2)) { 1047 if (data->has_fan & (1 << 2)) {
1049 if ((err = device_create_file(&new_client->dev, 1048 if ((err = device_create_file(dev,
1050 &sensor_dev_attr_fan3_input.dev_attr)) 1049 &sensor_dev_attr_fan3_input.dev_attr))
1051 || (err = device_create_file(&new_client->dev, 1050 || (err = device_create_file(dev,
1052 &sensor_dev_attr_fan3_min.dev_attr)) 1051 &sensor_dev_attr_fan3_min.dev_attr))
1053 || (err = device_create_file(&new_client->dev, 1052 || (err = device_create_file(dev,
1054 &sensor_dev_attr_fan3_div.dev_attr))) 1053 &sensor_dev_attr_fan3_div.dev_attr)))
1055 goto ERROR4; 1054 goto ERROR4;
1056 } 1055 }
1057 } 1056 }
1058 1057
1059 if (enable_pwm_interface) { 1058 if (enable_pwm_interface) {
1060 if ((err = device_create_file(&new_client->dev, 1059 if ((err = device_create_file(dev,
1061 &sensor_dev_attr_pwm1_enable.dev_attr)) 1060 &sensor_dev_attr_pwm1_enable.dev_attr))
1062 || (err = device_create_file(&new_client->dev, 1061 || (err = device_create_file(dev,
1063 &sensor_dev_attr_pwm2_enable.dev_attr)) 1062 &sensor_dev_attr_pwm2_enable.dev_attr))
1064 || (err = device_create_file(&new_client->dev, 1063 || (err = device_create_file(dev,
1065 &sensor_dev_attr_pwm3_enable.dev_attr)) 1064 &sensor_dev_attr_pwm3_enable.dev_attr))
1066 || (err = device_create_file(&new_client->dev, 1065 || (err = device_create_file(dev,
1067 &sensor_dev_attr_pwm1.dev_attr)) 1066 &sensor_dev_attr_pwm1.dev_attr))
1068 || (err = device_create_file(&new_client->dev, 1067 || (err = device_create_file(dev,
1069 &sensor_dev_attr_pwm2.dev_attr)) 1068 &sensor_dev_attr_pwm2.dev_attr))
1070 || (err = device_create_file(&new_client->dev, 1069 || (err = device_create_file(dev,
1071 &sensor_dev_attr_pwm3.dev_attr)) 1070 &sensor_dev_attr_pwm3.dev_attr))
1072 || (err = device_create_file(&new_client->dev, 1071 || (err = device_create_file(dev,
1073 &dev_attr_pwm1_freq)) 1072 &dev_attr_pwm1_freq))
1074 || (err = device_create_file(&new_client->dev, 1073 || (err = device_create_file(dev,
1075 &dev_attr_pwm2_freq)) 1074 &dev_attr_pwm2_freq))
1076 || (err = device_create_file(&new_client->dev, 1075 || (err = device_create_file(dev,
1077 &dev_attr_pwm3_freq))) 1076 &dev_attr_pwm3_freq)))
1078 goto ERROR4; 1077 goto ERROR4;
1079 } 1078 }
@@ -1082,15 +1081,15 @@ static int it87_detect(struct i2c_adapter *adapter)
1082 || data->type == it8718) { 1081 || data->type == it8718) {
1083 data->vrm = vid_which_vrm(); 1082 data->vrm = vid_which_vrm();
1084 /* VID reading from Super-I/O config space if available */ 1083 /* VID reading from Super-I/O config space if available */
1085 data->vid = vid_value; 1084 data->vid = sio_data->vid_value;
1086 if ((err = device_create_file(&new_client->dev, 1085 if ((err = device_create_file(dev,
1087 &dev_attr_vrm)) 1086 &dev_attr_vrm))
1088 || (err = device_create_file(&new_client->dev, 1087 || (err = device_create_file(dev,
1089 &dev_attr_cpu0_vid))) 1088 &dev_attr_cpu0_vid)))
1090 goto ERROR4; 1089 goto ERROR4;
1091 } 1090 }
1092 1091
1093 data->class_dev = hwmon_device_register(&new_client->dev); 1092 data->class_dev = hwmon_device_register(dev);
1094 if (IS_ERR(data->class_dev)) { 1093 if (IS_ERR(data->class_dev)) {
1095 err = PTR_ERR(data->class_dev); 1094 err = PTR_ERR(data->class_dev);
1096 goto ERROR4; 1095 goto ERROR4;
@@ -1099,31 +1098,27 @@ static int it87_detect(struct i2c_adapter *adapter)
1099 return 0; 1098 return 0;
1100 1099
1101ERROR4: 1100ERROR4:
1102 sysfs_remove_group(&new_client->dev.kobj, &it87_group); 1101 sysfs_remove_group(&dev->kobj, &it87_group);
1103 sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt); 1102 sysfs_remove_group(&dev->kobj, &it87_group_opt);
1104ERROR3:
1105 i2c_detach_client(new_client);
1106ERROR2: 1103ERROR2:
1104 platform_set_drvdata(pdev, NULL);
1107 kfree(data); 1105 kfree(data);
1108ERROR1: 1106ERROR1:
1109 release_region(isa_address, IT87_EXTENT); 1107 release_region(res->start, IT87_EXTENT);
1110ERROR0: 1108ERROR0:
1111 return err; 1109 return err;
1112} 1110}
1113 1111
1114static int it87_detach_client(struct i2c_client *client) 1112static int __devexit it87_remove(struct platform_device *pdev)
1115{ 1113{
1116 struct it87_data *data = i2c_get_clientdata(client); 1114 struct it87_data *data = platform_get_drvdata(pdev);
1117 int err;
1118 1115
1119 hwmon_device_unregister(data->class_dev); 1116 hwmon_device_unregister(data->class_dev);
1120 sysfs_remove_group(&client->dev.kobj, &it87_group); 1117 sysfs_remove_group(&pdev->dev.kobj, &it87_group);
1121 sysfs_remove_group(&client->dev.kobj, &it87_group_opt); 1118 sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
1122 1119
1123 if ((err = i2c_detach_client(client))) 1120 release_region(data->addr, IT87_EXTENT);
1124 return err; 1121 platform_set_drvdata(pdev, NULL);
1125
1126 release_region(client->addr, IT87_EXTENT);
1127 kfree(data); 1122 kfree(data);
1128 1123
1129 return 0; 1124 return 0;
@@ -1132,28 +1127,29 @@ static int it87_detach_client(struct i2c_client *client)
1132/* Must be called with data->update_lock held, except during initialization. 1127/* Must be called with data->update_lock held, except during initialization.
1133 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1128 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1134 would slow down the IT87 access and should not be necessary. */ 1129 would slow down the IT87 access and should not be necessary. */
1135static int it87_read_value(struct i2c_client *client, u8 reg) 1130static int it87_read_value(struct it87_data *data, u8 reg)
1136{ 1131{
1137 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1132 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1138 return inb_p(client->addr + IT87_DATA_REG_OFFSET); 1133 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
1139} 1134}
1140 1135
1141/* Must be called with data->update_lock held, except during initialization. 1136/* Must be called with data->update_lock held, except during initialization.
1142 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, 1137 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1143 would slow down the IT87 access and should not be necessary. */ 1138 would slow down the IT87 access and should not be necessary. */
1144static void it87_write_value(struct i2c_client *client, u8 reg, u8 value) 1139static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
1145{ 1140{
1146 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); 1141 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1147 outb_p(value, client->addr + IT87_DATA_REG_OFFSET); 1142 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
1148} 1143}
1149 1144
1150/* Return 1 if and only if the PWM interface is safe to use */ 1145/* Return 1 if and only if the PWM interface is safe to use */
1151static int it87_check_pwm(struct i2c_client *client) 1146static int __devinit it87_check_pwm(struct device *dev)
1152{ 1147{
1148 struct it87_data *data = dev_get_drvdata(dev);
1153 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off 1149 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1154 * and polarity set to active low is sign that this is the case so we 1150 * and polarity set to active low is sign that this is the case so we
1155 * disable pwm control to protect the user. */ 1151 * disable pwm control to protect the user. */
1156 int tmp = it87_read_value(client, IT87_REG_FAN_CTL); 1152 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1157 if ((tmp & 0x87) == 0) { 1153 if ((tmp & 0x87) == 0) {
1158 if (fix_pwm_polarity) { 1154 if (fix_pwm_polarity) {
1159 /* The user asks us to attempt a chip reconfiguration. 1155 /* The user asks us to attempt a chip reconfiguration.
@@ -1163,7 +1159,7 @@ static int it87_check_pwm(struct i2c_client *client)
1163 u8 pwm[3]; 1159 u8 pwm[3];
1164 1160
1165 for (i = 0; i < 3; i++) 1161 for (i = 0; i < 3; i++)
1166 pwm[i] = it87_read_value(client, 1162 pwm[i] = it87_read_value(data,
1167 IT87_REG_PWM(i)); 1163 IT87_REG_PWM(i));
1168 1164
1169 /* If any fan is in automatic pwm mode, the polarity 1165 /* If any fan is in automatic pwm mode, the polarity
@@ -1171,26 +1167,26 @@ static int it87_check_pwm(struct i2c_client *client)
1171 * better don't change anything (but still disable the 1167 * better don't change anything (but still disable the
1172 * PWM interface). */ 1168 * PWM interface). */
1173 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { 1169 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1174 dev_info(&client->dev, "Reconfiguring PWM to " 1170 dev_info(dev, "Reconfiguring PWM to "
1175 "active high polarity\n"); 1171 "active high polarity\n");
1176 it87_write_value(client, IT87_REG_FAN_CTL, 1172 it87_write_value(data, IT87_REG_FAN_CTL,
1177 tmp | 0x87); 1173 tmp | 0x87);
1178 for (i = 0; i < 3; i++) 1174 for (i = 0; i < 3; i++)
1179 it87_write_value(client, 1175 it87_write_value(data,
1180 IT87_REG_PWM(i), 1176 IT87_REG_PWM(i),
1181 0x7f & ~pwm[i]); 1177 0x7f & ~pwm[i]);
1182 return 1; 1178 return 1;
1183 } 1179 }
1184 1180
1185 dev_info(&client->dev, "PWM configuration is " 1181 dev_info(dev, "PWM configuration is "
1186 "too broken to be fixed\n"); 1182 "too broken to be fixed\n");
1187 } 1183 }
1188 1184
1189 dev_info(&client->dev, "Detected broken BIOS " 1185 dev_info(dev, "Detected broken BIOS "
1190 "defaults, disabling PWM interface\n"); 1186 "defaults, disabling PWM interface\n");
1191 return 0; 1187 return 0;
1192 } else if (fix_pwm_polarity) { 1188 } else if (fix_pwm_polarity) {
1193 dev_info(&client->dev, "PWM configuration looks " 1189 dev_info(dev, "PWM configuration looks "
1194 "sane, won't touch\n"); 1190 "sane, won't touch\n");
1195 } 1191 }
1196 1192
@@ -1198,8 +1194,9 @@ static int it87_check_pwm(struct i2c_client *client)
1198} 1194}
1199 1195
1200/* Called when we have found a new IT87. */ 1196/* Called when we have found a new IT87. */
1201static void it87_init_client(struct i2c_client *client, struct it87_data *data) 1197static void __devinit it87_init_device(struct platform_device *pdev)
1202{ 1198{
1199 struct it87_data *data = platform_get_drvdata(pdev);
1203 int tmp, i; 1200 int tmp, i;
1204 1201
1205 /* initialize to sane defaults: 1202 /* initialize to sane defaults:
@@ -1219,48 +1216,48 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1219 * means -1 degree C, which surprisingly doesn't trigger an alarm, 1216 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1220 * but is still confusing, so change to 127 degrees C. */ 1217 * but is still confusing, so change to 127 degrees C. */
1221 for (i = 0; i < 8; i++) { 1218 for (i = 0; i < 8; i++) {
1222 tmp = it87_read_value(client, IT87_REG_VIN_MIN(i)); 1219 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
1223 if (tmp == 0xff) 1220 if (tmp == 0xff)
1224 it87_write_value(client, IT87_REG_VIN_MIN(i), 0); 1221 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
1225 } 1222 }
1226 for (i = 0; i < 3; i++) { 1223 for (i = 0; i < 3; i++) {
1227 tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i)); 1224 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1228 if (tmp == 0xff) 1225 if (tmp == 0xff)
1229 it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127); 1226 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
1230 } 1227 }
1231 1228
1232 /* Check if temperature channnels are reset manually or by some reason */ 1229 /* Check if temperature channnels are reset manually or by some reason */
1233 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1230 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1234 if ((tmp & 0x3f) == 0) { 1231 if ((tmp & 0x3f) == 0) {
1235 /* Temp1,Temp3=thermistor; Temp2=thermal diode */ 1232 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1236 tmp = (tmp & 0xc0) | 0x2a; 1233 tmp = (tmp & 0xc0) | 0x2a;
1237 it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); 1234 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
1238 } 1235 }
1239 data->sensor = tmp; 1236 data->sensor = tmp;
1240 1237
1241 /* Check if voltage monitors are reset manually or by some reason */ 1238 /* Check if voltage monitors are reset manually or by some reason */
1242 tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); 1239 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
1243 if ((tmp & 0xff) == 0) { 1240 if ((tmp & 0xff) == 0) {
1244 /* Enable all voltage monitors */ 1241 /* Enable all voltage monitors */
1245 it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); 1242 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
1246 } 1243 }
1247 1244
1248 /* Check if tachometers are reset manually or by some reason */ 1245 /* Check if tachometers are reset manually or by some reason */
1249 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1246 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
1250 if ((data->fan_main_ctrl & 0x70) == 0) { 1247 if ((data->fan_main_ctrl & 0x70) == 0) {
1251 /* Enable all fan tachometers */ 1248 /* Enable all fan tachometers */
1252 data->fan_main_ctrl |= 0x70; 1249 data->fan_main_ctrl |= 0x70;
1253 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1250 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1254 } 1251 }
1255 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; 1252 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1256 1253
1257 /* Set tachometers to 16-bit mode if needed */ 1254 /* Set tachometers to 16-bit mode if needed */
1258 if (data->type == it8716 || data->type == it8718) { 1255 if (data->type == it8716 || data->type == it8718) {
1259 tmp = it87_read_value(client, IT87_REG_FAN_16BIT); 1256 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
1260 if (~tmp & 0x07 & data->has_fan) { 1257 if (~tmp & 0x07 & data->has_fan) {
1261 dev_dbg(&client->dev, 1258 dev_dbg(&pdev->dev,
1262 "Setting fan1-3 to 16-bit mode\n"); 1259 "Setting fan1-3 to 16-bit mode\n");
1263 it87_write_value(client, IT87_REG_FAN_16BIT, 1260 it87_write_value(data, IT87_REG_FAN_16BIT,
1264 tmp | 0x07); 1261 tmp | 0x07);
1265 } 1262 }
1266 } 1263 }
@@ -1270,7 +1267,7 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1270 for (i = 0; i < 3; i++) { 1267 for (i = 0; i < 3; i++) {
1271 if (data->fan_main_ctrl & (1 << i)) { 1268 if (data->fan_main_ctrl & (1 << i)) {
1272 /* pwm mode */ 1269 /* pwm mode */
1273 tmp = it87_read_value(client, IT87_REG_PWM(i)); 1270 tmp = it87_read_value(data, IT87_REG_PWM(i));
1274 if (tmp & 0x80) { 1271 if (tmp & 0x80) {
1275 /* automatic pwm - not yet implemented, but 1272 /* automatic pwm - not yet implemented, but
1276 * leave the settings made by the BIOS alone 1273 * leave the settings made by the BIOS alone
@@ -1284,15 +1281,14 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1284 } 1281 }
1285 1282
1286 /* Start monitoring */ 1283 /* Start monitoring */
1287 it87_write_value(client, IT87_REG_CONFIG, 1284 it87_write_value(data, IT87_REG_CONFIG,
1288 (it87_read_value(client, IT87_REG_CONFIG) & 0x36) 1285 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
1289 | (update_vbat ? 0x41 : 0x01)); 1286 | (update_vbat ? 0x41 : 0x01));
1290} 1287}
1291 1288
1292static struct it87_data *it87_update_device(struct device *dev) 1289static struct it87_data *it87_update_device(struct device *dev)
1293{ 1290{
1294 struct i2c_client *client = to_i2c_client(dev); 1291 struct it87_data *data = dev_get_drvdata(dev);
1295 struct it87_data *data = i2c_get_clientdata(client);
1296 int i; 1292 int i;
1297 1293
1298 mutex_lock(&data->update_lock); 1294 mutex_lock(&data->update_lock);
@@ -1303,20 +1299,20 @@ static struct it87_data *it87_update_device(struct device *dev)
1303 if (update_vbat) { 1299 if (update_vbat) {
1304 /* Cleared after each update, so reenable. Value 1300 /* Cleared after each update, so reenable. Value
1305 returned by this read will be previous value */ 1301 returned by this read will be previous value */
1306 it87_write_value(client, IT87_REG_CONFIG, 1302 it87_write_value(data, IT87_REG_CONFIG,
1307 it87_read_value(client, IT87_REG_CONFIG) | 0x40); 1303 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
1308 } 1304 }
1309 for (i = 0; i <= 7; i++) { 1305 for (i = 0; i <= 7; i++) {
1310 data->in[i] = 1306 data->in[i] =
1311 it87_read_value(client, IT87_REG_VIN(i)); 1307 it87_read_value(data, IT87_REG_VIN(i));
1312 data->in_min[i] = 1308 data->in_min[i] =
1313 it87_read_value(client, IT87_REG_VIN_MIN(i)); 1309 it87_read_value(data, IT87_REG_VIN_MIN(i));
1314 data->in_max[i] = 1310 data->in_max[i] =
1315 it87_read_value(client, IT87_REG_VIN_MAX(i)); 1311 it87_read_value(data, IT87_REG_VIN_MAX(i));
1316 } 1312 }
1317 /* in8 (battery) has no limit registers */ 1313 /* in8 (battery) has no limit registers */
1318 data->in[8] = 1314 data->in[8] =
1319 it87_read_value(client, IT87_REG_VIN(8)); 1315 it87_read_value(data, IT87_REG_VIN(8));
1320 1316
1321 for (i = 0; i < 3; i++) { 1317 for (i = 0; i < 3; i++) {
1322 /* Skip disabled fans */ 1318 /* Skip disabled fans */
@@ -1324,46 +1320,47 @@ static struct it87_data *it87_update_device(struct device *dev)
1324 continue; 1320 continue;
1325 1321
1326 data->fan_min[i] = 1322 data->fan_min[i] =
1327 it87_read_value(client, IT87_REG_FAN_MIN(i)); 1323 it87_read_value(data, IT87_REG_FAN_MIN(i));
1328 data->fan[i] = it87_read_value(client, 1324 data->fan[i] = it87_read_value(data,
1329 IT87_REG_FAN(i)); 1325 IT87_REG_FAN(i));
1330 /* Add high byte if in 16-bit mode */ 1326 /* Add high byte if in 16-bit mode */
1331 if (data->type == it8716 || data->type == it8718) { 1327 if (data->type == it8716 || data->type == it8718) {
1332 data->fan[i] |= it87_read_value(client, 1328 data->fan[i] |= it87_read_value(data,
1333 IT87_REG_FANX(i)) << 8; 1329 IT87_REG_FANX(i)) << 8;
1334 data->fan_min[i] |= it87_read_value(client, 1330 data->fan_min[i] |= it87_read_value(data,
1335 IT87_REG_FANX_MIN(i)) << 8; 1331 IT87_REG_FANX_MIN(i)) << 8;
1336 } 1332 }
1337 } 1333 }
1338 for (i = 0; i < 3; i++) { 1334 for (i = 0; i < 3; i++) {
1339 data->temp[i] = 1335 data->temp[i] =
1340 it87_read_value(client, IT87_REG_TEMP(i)); 1336 it87_read_value(data, IT87_REG_TEMP(i));
1341 data->temp_high[i] = 1337 data->temp_high[i] =
1342 it87_read_value(client, IT87_REG_TEMP_HIGH(i)); 1338 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
1343 data->temp_low[i] = 1339 data->temp_low[i] =
1344 it87_read_value(client, IT87_REG_TEMP_LOW(i)); 1340 it87_read_value(data, IT87_REG_TEMP_LOW(i));
1345 } 1341 }
1346 1342
1347 /* Newer chips don't have clock dividers */ 1343 /* Newer chips don't have clock dividers */
1348 if ((data->has_fan & 0x07) && data->type != it8716 1344 if ((data->has_fan & 0x07) && data->type != it8716
1349 && data->type != it8718) { 1345 && data->type != it8718) {
1350 i = it87_read_value(client, IT87_REG_FAN_DIV); 1346 i = it87_read_value(data, IT87_REG_FAN_DIV);
1351 data->fan_div[0] = i & 0x07; 1347 data->fan_div[0] = i & 0x07;
1352 data->fan_div[1] = (i >> 3) & 0x07; 1348 data->fan_div[1] = (i >> 3) & 0x07;
1353 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1349 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1354 } 1350 }
1355 1351
1356 data->alarms = 1352 data->alarms =
1357 it87_read_value(client, IT87_REG_ALARM1) | 1353 it87_read_value(data, IT87_REG_ALARM1) |
1358 (it87_read_value(client, IT87_REG_ALARM2) << 8) | 1354 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1359 (it87_read_value(client, IT87_REG_ALARM3) << 16); 1355 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1360 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); 1356 data->fan_main_ctrl = it87_read_value(data,
1361 data->fan_ctl = it87_read_value(client, IT87_REG_FAN_CTL); 1357 IT87_REG_FAN_MAIN_CTRL);
1362 1358 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
1363 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1359
1360 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
1364 /* The 8705 does not have VID capability */ 1361 /* The 8705 does not have VID capability */
1365 if (data->type == it8712 || data->type == it8716) { 1362 if (data->type == it8712 || data->type == it8716) {
1366 data->vid = it87_read_value(client, IT87_REG_VID); 1363 data->vid = it87_read_value(data, IT87_REG_VID);
1367 /* The older IT8712F revisions had only 5 VID pins, 1364 /* The older IT8712F revisions had only 5 VID pins,
1368 but we assume it is always safe to read 6 bits. */ 1365 but we assume it is always safe to read 6 bits. */
1369 data->vid &= 0x3f; 1366 data->vid &= 0x3f;
@@ -1377,18 +1374,79 @@ static struct it87_data *it87_update_device(struct device *dev)
1377 return data; 1374 return data;
1378} 1375}
1379 1376
1377static int __init it87_device_add(unsigned short address,
1378 const struct it87_sio_data *sio_data)
1379{
1380 struct resource res = {
1381 .start = address ,
1382 .end = address + IT87_EXTENT - 1,
1383 .name = DRVNAME,
1384 .flags = IORESOURCE_IO,
1385 };
1386 int err;
1387
1388 pdev = platform_device_alloc(DRVNAME, address);
1389 if (!pdev) {
1390 err = -ENOMEM;
1391 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1392 goto exit;
1393 }
1394
1395 err = platform_device_add_resources(pdev, &res, 1);
1396 if (err) {
1397 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1398 "(%d)\n", err);
1399 goto exit_device_put;
1400 }
1401
1402 err = platform_device_add_data(pdev, sio_data,
1403 sizeof(struct it87_sio_data));
1404 if (err) {
1405 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1406 goto exit_device_put;
1407 }
1408
1409 err = platform_device_add(pdev);
1410 if (err) {
1411 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1412 err);
1413 goto exit_device_put;
1414 }
1415
1416 return 0;
1417
1418exit_device_put:
1419 platform_device_put(pdev);
1420exit:
1421 return err;
1422}
1423
1380static int __init sm_it87_init(void) 1424static int __init sm_it87_init(void)
1381{ 1425{
1382 int res; 1426 int err;
1427 unsigned short isa_address=0;
1428 struct it87_sio_data sio_data;
1429
1430 err = it87_find(&isa_address, &sio_data);
1431 if (err)
1432 return err;
1433 err = platform_driver_register(&it87_driver);
1434 if (err)
1435 return err;
1383 1436
1384 if ((res = it87_find(&isa_address))) 1437 err = it87_device_add(isa_address, &sio_data);
1385 return res; 1438 if (err){
1386 return i2c_isa_add_driver(&it87_isa_driver); 1439 platform_driver_unregister(&it87_driver);
1440 return err;
1441 }
1442
1443 return 0;
1387} 1444}
1388 1445
1389static void __exit sm_it87_exit(void) 1446static void __exit sm_it87_exit(void)
1390{ 1447{
1391 i2c_isa_del_driver(&it87_isa_driver); 1448 platform_device_unregister(pdev);
1449 platform_driver_unregister(&it87_driver);
1392} 1450}
1393 1451
1394 1452