diff options
author | Jean Delvare <khali@linux-fr.org> | 2007-05-08 11:22:00 -0400 |
---|---|---|
committer | Jean Delvare <khali@hyperion.delvare> | 2007-05-08 11:22:00 -0400 |
commit | 787c72b107888805981faf148c8fea96a752d22e (patch) | |
tree | d43b24a9e08fc7bee8e322392aaa09034a7bce21 | |
parent | d27c37c0be3fd97a696dafb28507277d49875dcb (diff) |
hwmon/w83627hf: Convert to a platform driver
Convert the w83627hf driver from the nonsensical i2c-isa hack to a
regular platform driver.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r-- | drivers/hwmon/Kconfig | 3 | ||||
-rw-r--r-- | drivers/hwmon/w83627hf.c | 591 |
2 files changed, 311 insertions, 283 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index 399b6a92e9b0..ae3ab9169d52 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig | |||
@@ -550,8 +550,7 @@ config SENSORS_W83L785TS | |||
550 | 550 | ||
551 | config SENSORS_W83627HF | 551 | config SENSORS_W83627HF |
552 | tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF" | 552 | tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF" |
553 | depends on HWMON && I2C | 553 | depends on HWMON |
554 | select I2C_ISA | ||
555 | select HWMON_VID | 554 | select HWMON_VID |
556 | help | 555 | help |
557 | If you say yes here you get support for the Winbond W836X7 series | 556 | If you say yes here you get support for the Winbond W836X7 series |
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c index 7738d30a11b8..a5b774b07cbd 100644 --- a/drivers/hwmon/w83627hf.c +++ b/drivers/hwmon/w83627hf.c | |||
@@ -5,6 +5,7 @@ | |||
5 | Philip Edelbrock <phil@netroedge.com>, | 5 | Philip Edelbrock <phil@netroedge.com>, |
6 | and Mark Studebaker <mdsxyz123@yahoo.com> | 6 | and Mark Studebaker <mdsxyz123@yahoo.com> |
7 | Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> | 7 | Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> |
8 | Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> | ||
8 | 9 | ||
9 | This program is free software; you can redistribute it and/or modify | 10 | 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 | it under the terms of the GNU General Public License as published by |
@@ -42,8 +43,7 @@ | |||
42 | #include <linux/init.h> | 43 | #include <linux/init.h> |
43 | #include <linux/slab.h> | 44 | #include <linux/slab.h> |
44 | #include <linux/jiffies.h> | 45 | #include <linux/jiffies.h> |
45 | #include <linux/i2c.h> | 46 | #include <linux/platform_device.h> |
46 | #include <linux/i2c-isa.h> | ||
47 | #include <linux/hwmon.h> | 47 | #include <linux/hwmon.h> |
48 | #include <linux/hwmon-vid.h> | 48 | #include <linux/hwmon-vid.h> |
49 | #include <linux/err.h> | 49 | #include <linux/err.h> |
@@ -52,8 +52,7 @@ | |||
52 | #include <asm/io.h> | 52 | #include <asm/io.h> |
53 | #include "lm75.h" | 53 | #include "lm75.h" |
54 | 54 | ||
55 | /* The actual ISA address is read from Super-I/O configuration space */ | 55 | static struct platform_device *pdev; |
56 | static unsigned short address; | ||
57 | 56 | ||
58 | #define DRVNAME "w83627hf" | 57 | #define DRVNAME "w83627hf" |
59 | enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf }; | 58 | enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf }; |
@@ -157,9 +156,9 @@ superio_exit(void) | |||
157 | #define WINB_REGION_OFFSET 5 | 156 | #define WINB_REGION_OFFSET 5 |
158 | #define WINB_REGION_SIZE 2 | 157 | #define WINB_REGION_SIZE 2 |
159 | 158 | ||
160 | /* Where are the sensors address/data registers relative to the base address */ | 159 | /* Where are the sensors address/data registers relative to the region offset */ |
161 | #define W83781D_ADDR_REG_OFFSET 5 | 160 | #define W83781D_ADDR_REG_OFFSET 0 |
162 | #define W83781D_DATA_REG_OFFSET 6 | 161 | #define W83781D_DATA_REG_OFFSET 1 |
163 | 162 | ||
164 | /* The W83781D registers */ | 163 | /* The W83781D registers */ |
165 | /* The W83782D registers for nr=7,8 are in bank 5 */ | 164 | /* The W83782D registers for nr=7,8 are in bank 5 */ |
@@ -290,7 +289,8 @@ static inline u8 DIV_TO_REG(long val) | |||
290 | /* For each registered chip, we need to keep some data in memory. | 289 | /* For each registered chip, we need to keep some data in memory. |
291 | The structure is dynamically allocated. */ | 290 | The structure is dynamically allocated. */ |
292 | struct w83627hf_data { | 291 | struct w83627hf_data { |
293 | struct i2c_client client; | 292 | unsigned short addr; |
293 | const char *name; | ||
294 | struct class_device *class_dev; | 294 | struct class_device *class_dev; |
295 | struct mutex lock; | 295 | struct mutex lock; |
296 | enum chips type; | 296 | enum chips type; |
@@ -325,22 +325,26 @@ struct w83627hf_data { | |||
325 | u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ | 325 | u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ |
326 | }; | 326 | }; |
327 | 327 | ||
328 | struct w83627hf_sio_data { | ||
329 | enum chips type; | ||
330 | }; | ||
328 | 331 | ||
329 | static int w83627hf_detect(struct i2c_adapter *adapter); | ||
330 | static int w83627hf_detach_client(struct i2c_client *client); | ||
331 | 332 | ||
332 | static int w83627hf_read_value(struct i2c_client *client, u16 reg); | 333 | static int w83627hf_probe(struct platform_device *pdev); |
333 | static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value); | 334 | static int w83627hf_remove(struct platform_device *pdev); |
335 | |||
336 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg); | ||
337 | static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value); | ||
334 | static struct w83627hf_data *w83627hf_update_device(struct device *dev); | 338 | static struct w83627hf_data *w83627hf_update_device(struct device *dev); |
335 | static void w83627hf_init_client(struct i2c_client *client); | 339 | static void w83627hf_init_device(struct platform_device *pdev); |
336 | 340 | ||
337 | static struct i2c_driver w83627hf_driver = { | 341 | static struct platform_driver w83627hf_driver = { |
338 | .driver = { | 342 | .driver = { |
339 | .owner = THIS_MODULE, | 343 | .owner = THIS_MODULE, |
340 | .name = DRVNAME, | 344 | .name = DRVNAME, |
341 | }, | 345 | }, |
342 | .attach_adapter = w83627hf_detect, | 346 | .probe = w83627hf_probe, |
343 | .detach_client = w83627hf_detach_client, | 347 | .remove = __devexit_p(w83627hf_remove), |
344 | }; | 348 | }; |
345 | 349 | ||
346 | /* following are the sysfs callback functions */ | 350 | /* following are the sysfs callback functions */ |
@@ -358,15 +362,14 @@ show_in_reg(in_max) | |||
358 | static ssize_t \ | 362 | static ssize_t \ |
359 | store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ | 363 | store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ |
360 | { \ | 364 | { \ |
361 | struct i2c_client *client = to_i2c_client(dev); \ | 365 | struct w83627hf_data *data = dev_get_drvdata(dev); \ |
362 | struct w83627hf_data *data = i2c_get_clientdata(client); \ | ||
363 | u32 val; \ | 366 | u32 val; \ |
364 | \ | 367 | \ |
365 | val = simple_strtoul(buf, NULL, 10); \ | 368 | val = simple_strtoul(buf, NULL, 10); \ |
366 | \ | 369 | \ |
367 | mutex_lock(&data->update_lock); \ | 370 | mutex_lock(&data->update_lock); \ |
368 | data->in_##reg[nr] = IN_TO_REG(val); \ | 371 | data->in_##reg[nr] = IN_TO_REG(val); \ |
369 | w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \ | 372 | w83627hf_write_value(data, W83781D_REG_IN_##REG(nr), \ |
370 | data->in_##reg[nr]); \ | 373 | data->in_##reg[nr]); \ |
371 | \ | 374 | \ |
372 | mutex_unlock(&data->update_lock); \ | 375 | mutex_unlock(&data->update_lock); \ |
@@ -450,8 +453,7 @@ static ssize_t show_regs_in_max0(struct device *dev, struct device_attribute *at | |||
450 | static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr, | 453 | static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr, |
451 | const char *buf, size_t count) | 454 | const char *buf, size_t count) |
452 | { | 455 | { |
453 | struct i2c_client *client = to_i2c_client(dev); | 456 | struct w83627hf_data *data = dev_get_drvdata(dev); |
454 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
455 | u32 val; | 457 | u32 val; |
456 | 458 | ||
457 | val = simple_strtoul(buf, NULL, 10); | 459 | val = simple_strtoul(buf, NULL, 10); |
@@ -470,7 +472,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a | |||
470 | /* use VRM8 (standard) calculation */ | 472 | /* use VRM8 (standard) calculation */ |
471 | data->in_min[0] = IN_TO_REG(val); | 473 | data->in_min[0] = IN_TO_REG(val); |
472 | 474 | ||
473 | w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]); | 475 | w83627hf_write_value(data, W83781D_REG_IN_MIN(0), data->in_min[0]); |
474 | mutex_unlock(&data->update_lock); | 476 | mutex_unlock(&data->update_lock); |
475 | return count; | 477 | return count; |
476 | } | 478 | } |
@@ -478,8 +480,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a | |||
478 | static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr, | 480 | static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr, |
479 | const char *buf, size_t count) | 481 | const char *buf, size_t count) |
480 | { | 482 | { |
481 | struct i2c_client *client = to_i2c_client(dev); | 483 | struct w83627hf_data *data = dev_get_drvdata(dev); |
482 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
483 | u32 val; | 484 | u32 val; |
484 | 485 | ||
485 | val = simple_strtoul(buf, NULL, 10); | 486 | val = simple_strtoul(buf, NULL, 10); |
@@ -498,7 +499,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a | |||
498 | /* use VRM8 (standard) calculation */ | 499 | /* use VRM8 (standard) calculation */ |
499 | data->in_max[0] = IN_TO_REG(val); | 500 | data->in_max[0] = IN_TO_REG(val); |
500 | 501 | ||
501 | w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]); | 502 | w83627hf_write_value(data, W83781D_REG_IN_MAX(0), data->in_max[0]); |
502 | mutex_unlock(&data->update_lock); | 503 | mutex_unlock(&data->update_lock); |
503 | return count; | 504 | return count; |
504 | } | 505 | } |
@@ -523,8 +524,7 @@ show_fan_reg(fan_min); | |||
523 | static ssize_t | 524 | static ssize_t |
524 | store_fan_min(struct device *dev, const char *buf, size_t count, int nr) | 525 | store_fan_min(struct device *dev, const char *buf, size_t count, int nr) |
525 | { | 526 | { |
526 | struct i2c_client *client = to_i2c_client(dev); | 527 | struct w83627hf_data *data = dev_get_drvdata(dev); |
527 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
528 | u32 val; | 528 | u32 val; |
529 | 529 | ||
530 | val = simple_strtoul(buf, NULL, 10); | 530 | val = simple_strtoul(buf, NULL, 10); |
@@ -532,7 +532,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr) | |||
532 | mutex_lock(&data->update_lock); | 532 | mutex_lock(&data->update_lock); |
533 | data->fan_min[nr - 1] = | 533 | data->fan_min[nr - 1] = |
534 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); | 534 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); |
535 | w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr), | 535 | w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr), |
536 | data->fan_min[nr - 1]); | 536 | data->fan_min[nr - 1]); |
537 | 537 | ||
538 | mutex_unlock(&data->update_lock); | 538 | mutex_unlock(&data->update_lock); |
@@ -585,8 +585,7 @@ show_temp_reg(temp_max_hyst); | |||
585 | static ssize_t \ | 585 | static ssize_t \ |
586 | store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ | 586 | store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ |
587 | { \ | 587 | { \ |
588 | struct i2c_client *client = to_i2c_client(dev); \ | 588 | struct w83627hf_data *data = dev_get_drvdata(dev); \ |
589 | struct w83627hf_data *data = i2c_get_clientdata(client); \ | ||
590 | u32 val; \ | 589 | u32 val; \ |
591 | \ | 590 | \ |
592 | val = simple_strtoul(buf, NULL, 10); \ | 591 | val = simple_strtoul(buf, NULL, 10); \ |
@@ -595,11 +594,11 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ | |||
595 | \ | 594 | \ |
596 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ | 595 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ |
597 | data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ | 596 | data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ |
598 | w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \ | 597 | w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \ |
599 | data->temp_##reg##_add[nr-2]); \ | 598 | data->temp_##reg##_add[nr-2]); \ |
600 | } else { /* TEMP1 */ \ | 599 | } else { /* TEMP1 */ \ |
601 | data->temp_##reg = TEMP_TO_REG(val); \ | 600 | data->temp_##reg = TEMP_TO_REG(val); \ |
602 | w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \ | 601 | w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \ |
603 | data->temp_##reg); \ | 602 | data->temp_##reg); \ |
604 | } \ | 603 | } \ |
605 | \ | 604 | \ |
@@ -657,8 +656,7 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | |||
657 | static ssize_t | 656 | static ssize_t |
658 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 657 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
659 | { | 658 | { |
660 | struct i2c_client *client = to_i2c_client(dev); | 659 | struct w83627hf_data *data = dev_get_drvdata(dev); |
661 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
662 | u32 val; | 660 | u32 val; |
663 | 661 | ||
664 | val = simple_strtoul(buf, NULL, 10); | 662 | val = simple_strtoul(buf, NULL, 10); |
@@ -693,8 +691,7 @@ static ssize_t | |||
693 | store_beep_reg(struct device *dev, const char *buf, size_t count, | 691 | store_beep_reg(struct device *dev, const char *buf, size_t count, |
694 | int update_mask) | 692 | int update_mask) |
695 | { | 693 | { |
696 | struct i2c_client *client = to_i2c_client(dev); | 694 | struct w83627hf_data *data = dev_get_drvdata(dev); |
697 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
698 | u32 val, val2; | 695 | u32 val, val2; |
699 | 696 | ||
700 | val = simple_strtoul(buf, NULL, 10); | 697 | val = simple_strtoul(buf, NULL, 10); |
@@ -703,18 +700,18 @@ store_beep_reg(struct device *dev, const char *buf, size_t count, | |||
703 | 700 | ||
704 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ | 701 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ |
705 | data->beep_mask = BEEP_MASK_TO_REG(val); | 702 | data->beep_mask = BEEP_MASK_TO_REG(val); |
706 | w83627hf_write_value(client, W83781D_REG_BEEP_INTS1, | 703 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, |
707 | data->beep_mask & 0xff); | 704 | data->beep_mask & 0xff); |
708 | w83627hf_write_value(client, W83781D_REG_BEEP_INTS3, | 705 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, |
709 | ((data->beep_mask) >> 16) & 0xff); | 706 | ((data->beep_mask) >> 16) & 0xff); |
710 | val2 = (data->beep_mask >> 8) & 0x7f; | 707 | val2 = (data->beep_mask >> 8) & 0x7f; |
711 | } else { /* We are storing beep_enable */ | 708 | } else { /* We are storing beep_enable */ |
712 | val2 = | 709 | val2 = |
713 | w83627hf_read_value(client, W83781D_REG_BEEP_INTS2) & 0x7f; | 710 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; |
714 | data->beep_enable = BEEP_ENABLE_TO_REG(val); | 711 | data->beep_enable = BEEP_ENABLE_TO_REG(val); |
715 | } | 712 | } |
716 | 713 | ||
717 | w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, | 714 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, |
718 | val2 | data->beep_enable << 7); | 715 | val2 | data->beep_enable << 7); |
719 | 716 | ||
720 | mutex_unlock(&data->update_lock); | 717 | mutex_unlock(&data->update_lock); |
@@ -752,8 +749,7 @@ show_fan_div_reg(struct device *dev, char *buf, int nr) | |||
752 | static ssize_t | 749 | static ssize_t |
753 | store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) | 750 | store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) |
754 | { | 751 | { |
755 | struct i2c_client *client = to_i2c_client(dev); | 752 | struct w83627hf_data *data = dev_get_drvdata(dev); |
756 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
757 | unsigned long min; | 753 | unsigned long min; |
758 | u8 reg; | 754 | u8 reg; |
759 | unsigned long val = simple_strtoul(buf, NULL, 10); | 755 | unsigned long val = simple_strtoul(buf, NULL, 10); |
@@ -766,19 +762,19 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
766 | 762 | ||
767 | data->fan_div[nr] = DIV_TO_REG(val); | 763 | data->fan_div[nr] = DIV_TO_REG(val); |
768 | 764 | ||
769 | reg = (w83627hf_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) | 765 | reg = (w83627hf_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) |
770 | & (nr==0 ? 0xcf : 0x3f)) | 766 | & (nr==0 ? 0xcf : 0x3f)) |
771 | | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); | 767 | | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); |
772 | w83627hf_write_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); | 768 | w83627hf_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); |
773 | 769 | ||
774 | reg = (w83627hf_read_value(client, W83781D_REG_VBAT) | 770 | reg = (w83627hf_read_value(data, W83781D_REG_VBAT) |
775 | & ~(1 << (5 + nr))) | 771 | & ~(1 << (5 + nr))) |
776 | | ((data->fan_div[nr] & 0x04) << (3 + nr)); | 772 | | ((data->fan_div[nr] & 0x04) << (3 + nr)); |
777 | w83627hf_write_value(client, W83781D_REG_VBAT, reg); | 773 | w83627hf_write_value(data, W83781D_REG_VBAT, reg); |
778 | 774 | ||
779 | /* Restore fan_min */ | 775 | /* Restore fan_min */ |
780 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | 776 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
781 | w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); | 777 | w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); |
782 | 778 | ||
783 | mutex_unlock(&data->update_lock); | 779 | mutex_unlock(&data->update_lock); |
784 | return count; | 780 | return count; |
@@ -812,8 +808,7 @@ show_pwm_reg(struct device *dev, char *buf, int nr) | |||
812 | static ssize_t | 808 | static ssize_t |
813 | store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) | 809 | store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) |
814 | { | 810 | { |
815 | struct i2c_client *client = to_i2c_client(dev); | 811 | struct w83627hf_data *data = dev_get_drvdata(dev); |
816 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
817 | u32 val; | 812 | u32 val; |
818 | 813 | ||
819 | val = simple_strtoul(buf, NULL, 10); | 814 | val = simple_strtoul(buf, NULL, 10); |
@@ -823,14 +818,14 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
823 | if (data->type == w83627thf) { | 818 | if (data->type == w83627thf) { |
824 | /* bits 0-3 are reserved in 627THF */ | 819 | /* bits 0-3 are reserved in 627THF */ |
825 | data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0; | 820 | data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0; |
826 | w83627hf_write_value(client, | 821 | w83627hf_write_value(data, |
827 | W836X7HF_REG_PWM(data->type, nr), | 822 | W836X7HF_REG_PWM(data->type, nr), |
828 | data->pwm[nr - 1] | | 823 | data->pwm[nr - 1] | |
829 | (w83627hf_read_value(client, | 824 | (w83627hf_read_value(data, |
830 | W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); | 825 | W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); |
831 | } else { | 826 | } else { |
832 | data->pwm[nr - 1] = PWM_TO_REG(val); | 827 | data->pwm[nr - 1] = PWM_TO_REG(val); |
833 | w83627hf_write_value(client, | 828 | w83627hf_write_value(data, |
834 | W836X7HF_REG_PWM(data->type, nr), | 829 | W836X7HF_REG_PWM(data->type, nr), |
835 | data->pwm[nr - 1]); | 830 | data->pwm[nr - 1]); |
836 | } | 831 | } |
@@ -866,8 +861,7 @@ show_sensor_reg(struct device *dev, char *buf, int nr) | |||
866 | static ssize_t | 861 | static ssize_t |
867 | store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | 862 | store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) |
868 | { | 863 | { |
869 | struct i2c_client *client = to_i2c_client(dev); | 864 | struct w83627hf_data *data = dev_get_drvdata(dev); |
870 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
871 | u32 val, tmp; | 865 | u32 val, tmp; |
872 | 866 | ||
873 | val = simple_strtoul(buf, NULL, 10); | 867 | val = simple_strtoul(buf, NULL, 10); |
@@ -876,31 +870,31 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) | |||
876 | 870 | ||
877 | switch (val) { | 871 | switch (val) { |
878 | case 1: /* PII/Celeron diode */ | 872 | case 1: /* PII/Celeron diode */ |
879 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); | 873 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
880 | w83627hf_write_value(client, W83781D_REG_SCFG1, | 874 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
881 | tmp | BIT_SCFG1[nr - 1]); | 875 | tmp | BIT_SCFG1[nr - 1]); |
882 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG2); | 876 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
883 | w83627hf_write_value(client, W83781D_REG_SCFG2, | 877 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
884 | tmp | BIT_SCFG2[nr - 1]); | 878 | tmp | BIT_SCFG2[nr - 1]); |
885 | data->sens[nr - 1] = val; | 879 | data->sens[nr - 1] = val; |
886 | break; | 880 | break; |
887 | case 2: /* 3904 */ | 881 | case 2: /* 3904 */ |
888 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); | 882 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
889 | w83627hf_write_value(client, W83781D_REG_SCFG1, | 883 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
890 | tmp | BIT_SCFG1[nr - 1]); | 884 | tmp | BIT_SCFG1[nr - 1]); |
891 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG2); | 885 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
892 | w83627hf_write_value(client, W83781D_REG_SCFG2, | 886 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
893 | tmp & ~BIT_SCFG2[nr - 1]); | 887 | tmp & ~BIT_SCFG2[nr - 1]); |
894 | data->sens[nr - 1] = val; | 888 | data->sens[nr - 1] = val; |
895 | break; | 889 | break; |
896 | case W83781D_DEFAULT_BETA: /* thermistor */ | 890 | case W83781D_DEFAULT_BETA: /* thermistor */ |
897 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); | 891 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
898 | w83627hf_write_value(client, W83781D_REG_SCFG1, | 892 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
899 | tmp & ~BIT_SCFG1[nr - 1]); | 893 | tmp & ~BIT_SCFG1[nr - 1]); |
900 | data->sens[nr - 1] = val; | 894 | data->sens[nr - 1] = val; |
901 | break; | 895 | break; |
902 | default: | 896 | default: |
903 | dev_err(&client->dev, | 897 | dev_err(dev, |
904 | "Invalid sensor type %ld; must be 1, 2, or %d\n", | 898 | "Invalid sensor type %ld; must be 1, 2, or %d\n", |
905 | (long) val, W83781D_DEFAULT_BETA); | 899 | (long) val, W83781D_DEFAULT_BETA); |
906 | break; | 900 | break; |
@@ -927,21 +921,52 @@ sysfs_sensor(1); | |||
927 | sysfs_sensor(2); | 921 | sysfs_sensor(2); |
928 | sysfs_sensor(3); | 922 | sysfs_sensor(3); |
929 | 923 | ||
930 | static int __init w83627hf_find(int sioaddr, unsigned short *addr) | 924 | static ssize_t show_name(struct device *dev, struct device_attribute |
925 | *devattr, char *buf) | ||
926 | { | ||
927 | struct w83627hf_data *data = dev_get_drvdata(dev); | ||
928 | |||
929 | return sprintf(buf, "%s\n", data->name); | ||
930 | } | ||
931 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | ||
932 | |||
933 | static int __init w83627hf_find(int sioaddr, unsigned short *addr, | ||
934 | struct w83627hf_sio_data *sio_data) | ||
931 | { | 935 | { |
932 | int err = -ENODEV; | 936 | int err = -ENODEV; |
933 | u16 val; | 937 | u16 val; |
934 | 938 | ||
939 | static const __initdata char *names[] = { | ||
940 | "W83627HF", | ||
941 | "W83627THF", | ||
942 | "W83697HF", | ||
943 | "W83637HF", | ||
944 | "W83687THF", | ||
945 | }; | ||
946 | |||
935 | REG = sioaddr; | 947 | REG = sioaddr; |
936 | VAL = sioaddr + 1; | 948 | VAL = sioaddr + 1; |
937 | 949 | ||
938 | superio_enter(); | 950 | superio_enter(); |
939 | val= superio_inb(DEVID); | 951 | val= superio_inb(DEVID); |
940 | if(val != W627_DEVID && | 952 | switch (val) { |
941 | val != W627THF_DEVID && | 953 | case W627_DEVID: |
942 | val != W697_DEVID && | 954 | sio_data->type = w83627hf; |
943 | val != W637_DEVID && | 955 | break; |
944 | val != W687THF_DEVID) { | 956 | case W627THF_DEVID: |
957 | sio_data->type = w83627thf; | ||
958 | break; | ||
959 | case W697_DEVID: | ||
960 | sio_data->type = w83697hf; | ||
961 | break; | ||
962 | case W637_DEVID: | ||
963 | sio_data->type = w83637hf; | ||
964 | break; | ||
965 | case W687THF_DEVID: | ||
966 | sio_data->type = w83687thf; | ||
967 | break; | ||
968 | default: | ||
969 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", val); | ||
945 | goto exit; | 970 | goto exit; |
946 | } | 971 | } |
947 | 972 | ||
@@ -969,6 +994,8 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr) | |||
969 | } | 994 | } |
970 | 995 | ||
971 | err = 0; | 996 | err = 0; |
997 | pr_info(DRVNAME ": Found %s chip at %#x\n", | ||
998 | names[sio_data->type], *addr); | ||
972 | 999 | ||
973 | exit: | 1000 | exit: |
974 | superio_exit(); | 1001 | superio_exit(); |
@@ -1018,6 +1045,7 @@ static struct attribute *w83627hf_attributes[] = { | |||
1018 | &dev_attr_pwm1.attr, | 1045 | &dev_attr_pwm1.attr, |
1019 | &dev_attr_pwm2.attr, | 1046 | &dev_attr_pwm2.attr, |
1020 | 1047 | ||
1048 | &dev_attr_name.attr, | ||
1021 | NULL | 1049 | NULL |
1022 | }; | 1050 | }; |
1023 | 1051 | ||
@@ -1054,147 +1082,92 @@ static const struct attribute_group w83627hf_group_opt = { | |||
1054 | .attrs = w83627hf_attributes_opt, | 1082 | .attrs = w83627hf_attributes_opt, |
1055 | }; | 1083 | }; |
1056 | 1084 | ||
1057 | static int w83627hf_detect(struct i2c_adapter *adapter) | 1085 | static int __devinit w83627hf_probe(struct platform_device *pdev) |
1058 | { | 1086 | { |
1059 | int val, kind; | 1087 | struct device *dev = &pdev->dev; |
1060 | struct i2c_client *new_client; | 1088 | struct w83627hf_sio_data *sio_data = dev->platform_data; |
1061 | struct w83627hf_data *data; | 1089 | struct w83627hf_data *data; |
1062 | int err = 0; | 1090 | struct resource *res; |
1063 | const char *client_name = ""; | 1091 | int err; |
1064 | 1092 | ||
1065 | if (!request_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE, | 1093 | static const char *names[] = { |
1066 | w83627hf_driver.driver.name)) { | 1094 | "w83627hf", |
1095 | "w83627thf", | ||
1096 | "w83697hf", | ||
1097 | "w83637hf", | ||
1098 | "w83687thf", | ||
1099 | }; | ||
1100 | |||
1101 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
1102 | if (!request_region(res->start, WINB_REGION_SIZE, DRVNAME)) { | ||
1103 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", | ||
1104 | (unsigned long)res->start, | ||
1105 | (unsigned long)(res->start + WINB_REGION_SIZE - 1)); | ||
1067 | err = -EBUSY; | 1106 | err = -EBUSY; |
1068 | goto ERROR0; | 1107 | goto ERROR0; |
1069 | } | 1108 | } |
1070 | 1109 | ||
1071 | superio_enter(); | ||
1072 | val= superio_inb(DEVID); | ||
1073 | if(val == W627_DEVID) | ||
1074 | kind = w83627hf; | ||
1075 | else if(val == W697_DEVID) | ||
1076 | kind = w83697hf; | ||
1077 | else if(val == W627THF_DEVID) | ||
1078 | kind = w83627thf; | ||
1079 | else if(val == W637_DEVID) | ||
1080 | kind = w83637hf; | ||
1081 | else if (val == W687THF_DEVID) | ||
1082 | kind = w83687thf; | ||
1083 | else { | ||
1084 | dev_info(&adapter->dev, | ||
1085 | "Unsupported chip (dev_id=0x%02X).\n", val); | ||
1086 | goto ERROR1; | ||
1087 | } | ||
1088 | superio_exit(); | ||
1089 | |||
1090 | /* OK. For now, we presume we have a valid client. We now create the | ||
1091 | client structure, even though we cannot fill it completely yet. | ||
1092 | But it allows us to access w83627hf_{read,write}_value. */ | ||
1093 | |||
1094 | if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { | 1110 | if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { |
1095 | err = -ENOMEM; | 1111 | err = -ENOMEM; |
1096 | goto ERROR1; | 1112 | goto ERROR1; |
1097 | } | 1113 | } |
1098 | 1114 | data->addr = res->start; | |
1099 | new_client = &data->client; | 1115 | data->type = sio_data->type; |
1100 | i2c_set_clientdata(new_client, data); | 1116 | data->name = names[sio_data->type]; |
1101 | new_client->addr = address; | ||
1102 | mutex_init(&data->lock); | 1117 | mutex_init(&data->lock); |
1103 | new_client->adapter = adapter; | ||
1104 | new_client->driver = &w83627hf_driver; | ||
1105 | new_client->flags = 0; | ||
1106 | |||
1107 | |||
1108 | if (kind == w83627hf) { | ||
1109 | client_name = "w83627hf"; | ||
1110 | } else if (kind == w83627thf) { | ||
1111 | client_name = "w83627thf"; | ||
1112 | } else if (kind == w83697hf) { | ||
1113 | client_name = "w83697hf"; | ||
1114 | } else if (kind == w83637hf) { | ||
1115 | client_name = "w83637hf"; | ||
1116 | } else if (kind == w83687thf) { | ||
1117 | client_name = "w83687thf"; | ||
1118 | } | ||
1119 | |||
1120 | /* Fill in the remaining client fields and put into the global list */ | ||
1121 | strlcpy(new_client->name, client_name, I2C_NAME_SIZE); | ||
1122 | data->type = kind; | ||
1123 | data->valid = 0; | ||
1124 | mutex_init(&data->update_lock); | 1118 | mutex_init(&data->update_lock); |
1125 | 1119 | platform_set_drvdata(pdev, data); | |
1126 | /* Tell the I2C layer a new client has arrived */ | ||
1127 | if ((err = i2c_attach_client(new_client))) | ||
1128 | goto ERROR2; | ||
1129 | 1120 | ||
1130 | /* Initialize the chip */ | 1121 | /* Initialize the chip */ |
1131 | w83627hf_init_client(new_client); | 1122 | w83627hf_init_device(pdev); |
1132 | 1123 | ||
1133 | /* A few vars need to be filled upon startup */ | 1124 | /* A few vars need to be filled upon startup */ |
1134 | data->fan_min[0] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(1)); | 1125 | data->fan_min[0] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(1)); |
1135 | data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); | 1126 | data->fan_min[1] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(2)); |
1136 | data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); | 1127 | data->fan_min[2] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(3)); |
1137 | 1128 | ||
1138 | /* Register common device attributes */ | 1129 | /* Register common device attributes */ |
1139 | if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group))) | 1130 | if ((err = sysfs_create_group(&dev->kobj, &w83627hf_group))) |
1140 | goto ERROR3; | 1131 | goto ERROR3; |
1141 | 1132 | ||
1142 | /* Register chip-specific device attributes */ | 1133 | /* Register chip-specific device attributes */ |
1143 | if (kind == w83627hf || kind == w83697hf) | 1134 | if (data->type == w83627hf || data->type == w83697hf) |
1144 | if ((err = device_create_file(&new_client->dev, | 1135 | if ((err = device_create_file(dev, &dev_attr_in5_input)) |
1145 | &dev_attr_in5_input)) | 1136 | || (err = device_create_file(dev, &dev_attr_in5_min)) |
1146 | || (err = device_create_file(&new_client->dev, | 1137 | || (err = device_create_file(dev, &dev_attr_in5_max)) |
1147 | &dev_attr_in5_min)) | 1138 | || (err = device_create_file(dev, &dev_attr_in6_input)) |
1148 | || (err = device_create_file(&new_client->dev, | 1139 | || (err = device_create_file(dev, &dev_attr_in6_min)) |
1149 | &dev_attr_in5_max)) | 1140 | || (err = device_create_file(dev, &dev_attr_in6_max))) |
1150 | || (err = device_create_file(&new_client->dev, | ||
1151 | &dev_attr_in6_input)) | ||
1152 | || (err = device_create_file(&new_client->dev, | ||
1153 | &dev_attr_in6_min)) | ||
1154 | || (err = device_create_file(&new_client->dev, | ||
1155 | &dev_attr_in6_max))) | ||
1156 | goto ERROR4; | 1141 | goto ERROR4; |
1157 | 1142 | ||
1158 | if (kind != w83697hf) | 1143 | if (data->type != w83697hf) |
1159 | if ((err = device_create_file(&new_client->dev, | 1144 | if ((err = device_create_file(dev, &dev_attr_in1_input)) |
1160 | &dev_attr_in1_input)) | 1145 | || (err = device_create_file(dev, &dev_attr_in1_min)) |
1161 | || (err = device_create_file(&new_client->dev, | 1146 | || (err = device_create_file(dev, &dev_attr_in1_max)) |
1162 | &dev_attr_in1_min)) | 1147 | || (err = device_create_file(dev, &dev_attr_fan3_input)) |
1163 | || (err = device_create_file(&new_client->dev, | 1148 | || (err = device_create_file(dev, &dev_attr_fan3_min)) |
1164 | &dev_attr_in1_max)) | 1149 | || (err = device_create_file(dev, &dev_attr_fan3_div)) |
1165 | || (err = device_create_file(&new_client->dev, | 1150 | || (err = device_create_file(dev, &dev_attr_temp3_input)) |
1166 | &dev_attr_fan3_input)) | 1151 | || (err = device_create_file(dev, &dev_attr_temp3_max)) |
1167 | || (err = device_create_file(&new_client->dev, | 1152 | || (err = device_create_file(dev, &dev_attr_temp3_max_hyst)) |
1168 | &dev_attr_fan3_min)) | 1153 | || (err = device_create_file(dev, &dev_attr_temp3_type))) |
1169 | || (err = device_create_file(&new_client->dev, | ||
1170 | &dev_attr_fan3_div)) | ||
1171 | || (err = device_create_file(&new_client->dev, | ||
1172 | &dev_attr_temp3_input)) | ||
1173 | || (err = device_create_file(&new_client->dev, | ||
1174 | &dev_attr_temp3_max)) | ||
1175 | || (err = device_create_file(&new_client->dev, | ||
1176 | &dev_attr_temp3_max_hyst)) | ||
1177 | || (err = device_create_file(&new_client->dev, | ||
1178 | &dev_attr_temp3_type))) | ||
1179 | goto ERROR4; | 1154 | goto ERROR4; |
1180 | 1155 | ||
1181 | if (kind != w83697hf && data->vid != 0xff) { | 1156 | if (data->type != w83697hf && data->vid != 0xff) { |
1182 | /* Convert VID to voltage based on VRM */ | 1157 | /* Convert VID to voltage based on VRM */ |
1183 | data->vrm = vid_which_vrm(); | 1158 | data->vrm = vid_which_vrm(); |
1184 | 1159 | ||
1185 | if ((err = device_create_file(&new_client->dev, | 1160 | if ((err = device_create_file(dev, &dev_attr_cpu0_vid)) |
1186 | &dev_attr_cpu0_vid)) | 1161 | || (err = device_create_file(dev, &dev_attr_vrm))) |
1187 | || (err = device_create_file(&new_client->dev, | ||
1188 | &dev_attr_vrm))) | ||
1189 | goto ERROR4; | 1162 | goto ERROR4; |
1190 | } | 1163 | } |
1191 | 1164 | ||
1192 | if (kind == w83627thf || kind == w83637hf || kind == w83687thf) | 1165 | if (data->type == w83627thf || data->type == w83637hf |
1193 | if ((err = device_create_file(&new_client->dev, | 1166 | || data->type == w83687thf) |
1194 | &dev_attr_pwm3))) | 1167 | if ((err = device_create_file(dev, &dev_attr_pwm3))) |
1195 | goto ERROR4; | 1168 | goto ERROR4; |
1196 | 1169 | ||
1197 | data->class_dev = hwmon_device_register(&new_client->dev); | 1170 | data->class_dev = hwmon_device_register(dev); |
1198 | if (IS_ERR(data->class_dev)) { | 1171 | if (IS_ERR(data->class_dev)) { |
1199 | err = PTR_ERR(data->class_dev); | 1172 | err = PTR_ERR(data->class_dev); |
1200 | goto ERROR4; | 1173 | goto ERROR4; |
@@ -1203,47 +1176,37 @@ static int w83627hf_detect(struct i2c_adapter *adapter) | |||
1203 | return 0; | 1176 | return 0; |
1204 | 1177 | ||
1205 | ERROR4: | 1178 | ERROR4: |
1206 | sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group); | 1179 | sysfs_remove_group(&dev->kobj, &w83627hf_group); |
1207 | sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt); | 1180 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); |
1208 | ERROR3: | 1181 | ERROR3: |
1209 | i2c_detach_client(new_client); | ||
1210 | ERROR2: | ||
1211 | kfree(data); | 1182 | kfree(data); |
1212 | ERROR1: | 1183 | ERROR1: |
1213 | release_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE); | 1184 | release_region(res->start, WINB_REGION_SIZE); |
1214 | ERROR0: | 1185 | ERROR0: |
1215 | return err; | 1186 | return err; |
1216 | } | 1187 | } |
1217 | 1188 | ||
1218 | static int w83627hf_detach_client(struct i2c_client *client) | 1189 | static int __devexit w83627hf_remove(struct platform_device *pdev) |
1219 | { | 1190 | { |
1220 | struct w83627hf_data *data = i2c_get_clientdata(client); | 1191 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
1221 | int err; | 1192 | struct resource *res; |
1222 | 1193 | ||
1194 | platform_set_drvdata(pdev, NULL); | ||
1223 | hwmon_device_unregister(data->class_dev); | 1195 | hwmon_device_unregister(data->class_dev); |
1224 | 1196 | ||
1225 | sysfs_remove_group(&client->dev.kobj, &w83627hf_group); | 1197 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); |
1226 | sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt); | 1198 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); |
1227 | |||
1228 | if ((err = i2c_detach_client(client))) | ||
1229 | return err; | ||
1230 | |||
1231 | release_region(client->addr + WINB_REGION_OFFSET, WINB_REGION_SIZE); | ||
1232 | kfree(data); | 1199 | kfree(data); |
1233 | 1200 | ||
1201 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
1202 | release_region(res->start, WINB_REGION_SIZE); | ||
1203 | |||
1234 | return 0; | 1204 | return 0; |
1235 | } | 1205 | } |
1236 | 1206 | ||
1237 | 1207 | ||
1238 | /* | 1208 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) |
1239 | ISA access must always be locked explicitly! | ||
1240 | We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, | ||
1241 | would slow down the W83781D access and should not be necessary. | ||
1242 | There are some ugly typecasts here, but the good news is - they should | ||
1243 | nowhere else be necessary! */ | ||
1244 | static int w83627hf_read_value(struct i2c_client *client, u16 reg) | ||
1245 | { | 1209 | { |
1246 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
1247 | int res, word_sized; | 1210 | int res, word_sized; |
1248 | 1211 | ||
1249 | mutex_lock(&data->lock); | 1212 | mutex_lock(&data->lock); |
@@ -1254,29 +1217,29 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg) | |||
1254 | || ((reg & 0x00ff) == 0x55)); | 1217 | || ((reg & 0x00ff) == 0x55)); |
1255 | if (reg & 0xff00) { | 1218 | if (reg & 0xff00) { |
1256 | outb_p(W83781D_REG_BANK, | 1219 | outb_p(W83781D_REG_BANK, |
1257 | client->addr + W83781D_ADDR_REG_OFFSET); | 1220 | data->addr + W83781D_ADDR_REG_OFFSET); |
1258 | outb_p(reg >> 8, | 1221 | outb_p(reg >> 8, |
1259 | client->addr + W83781D_DATA_REG_OFFSET); | 1222 | data->addr + W83781D_DATA_REG_OFFSET); |
1260 | } | 1223 | } |
1261 | outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); | 1224 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
1262 | res = inb_p(client->addr + W83781D_DATA_REG_OFFSET); | 1225 | res = inb_p(data->addr + W83781D_DATA_REG_OFFSET); |
1263 | if (word_sized) { | 1226 | if (word_sized) { |
1264 | outb_p((reg & 0xff) + 1, | 1227 | outb_p((reg & 0xff) + 1, |
1265 | client->addr + W83781D_ADDR_REG_OFFSET); | 1228 | data->addr + W83781D_ADDR_REG_OFFSET); |
1266 | res = | 1229 | res = |
1267 | (res << 8) + inb_p(client->addr + | 1230 | (res << 8) + inb_p(data->addr + |
1268 | W83781D_DATA_REG_OFFSET); | 1231 | W83781D_DATA_REG_OFFSET); |
1269 | } | 1232 | } |
1270 | if (reg & 0xff00) { | 1233 | if (reg & 0xff00) { |
1271 | outb_p(W83781D_REG_BANK, | 1234 | outb_p(W83781D_REG_BANK, |
1272 | client->addr + W83781D_ADDR_REG_OFFSET); | 1235 | data->addr + W83781D_ADDR_REG_OFFSET); |
1273 | outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); | 1236 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
1274 | } | 1237 | } |
1275 | mutex_unlock(&data->lock); | 1238 | mutex_unlock(&data->lock); |
1276 | return res; | 1239 | return res; |
1277 | } | 1240 | } |
1278 | 1241 | ||
1279 | static int w83627thf_read_gpio5(struct i2c_client *client) | 1242 | static int __devinit w83627thf_read_gpio5(struct platform_device *pdev) |
1280 | { | 1243 | { |
1281 | int res = 0xff, sel; | 1244 | int res = 0xff, sel; |
1282 | 1245 | ||
@@ -1285,7 +1248,7 @@ static int w83627thf_read_gpio5(struct i2c_client *client) | |||
1285 | 1248 | ||
1286 | /* Make sure these GPIO pins are enabled */ | 1249 | /* Make sure these GPIO pins are enabled */ |
1287 | if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { | 1250 | if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { |
1288 | dev_dbg(&client->dev, "GPIO5 disabled, no VID function\n"); | 1251 | dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); |
1289 | goto exit; | 1252 | goto exit; |
1290 | } | 1253 | } |
1291 | 1254 | ||
@@ -1293,12 +1256,12 @@ static int w83627thf_read_gpio5(struct i2c_client *client) | |||
1293 | There must be at least five (VRM 9), and possibly 6 (VRM 10) */ | 1256 | There must be at least five (VRM 9), and possibly 6 (VRM 10) */ |
1294 | sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; | 1257 | sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; |
1295 | if ((sel & 0x1f) != 0x1f) { | 1258 | if ((sel & 0x1f) != 0x1f) { |
1296 | dev_dbg(&client->dev, "GPIO5 not configured for VID " | 1259 | dev_dbg(&pdev->dev, "GPIO5 not configured for VID " |
1297 | "function\n"); | 1260 | "function\n"); |
1298 | goto exit; | 1261 | goto exit; |
1299 | } | 1262 | } |
1300 | 1263 | ||
1301 | dev_info(&client->dev, "Reading VID from GPIO5\n"); | 1264 | dev_info(&pdev->dev, "Reading VID from GPIO5\n"); |
1302 | res = superio_inb(W83627THF_GPIO5_DR) & sel; | 1265 | res = superio_inb(W83627THF_GPIO5_DR) & sel; |
1303 | 1266 | ||
1304 | exit: | 1267 | exit: |
@@ -1306,7 +1269,7 @@ exit: | |||
1306 | return res; | 1269 | return res; |
1307 | } | 1270 | } |
1308 | 1271 | ||
1309 | static int w83687thf_read_vid(struct i2c_client *client) | 1272 | static int __devinit w83687thf_read_vid(struct platform_device *pdev) |
1310 | { | 1273 | { |
1311 | int res = 0xff; | 1274 | int res = 0xff; |
1312 | 1275 | ||
@@ -1315,13 +1278,13 @@ static int w83687thf_read_vid(struct i2c_client *client) | |||
1315 | 1278 | ||
1316 | /* Make sure these GPIO pins are enabled */ | 1279 | /* Make sure these GPIO pins are enabled */ |
1317 | if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { | 1280 | if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { |
1318 | dev_dbg(&client->dev, "VID disabled, no VID function\n"); | 1281 | dev_dbg(&pdev->dev, "VID disabled, no VID function\n"); |
1319 | goto exit; | 1282 | goto exit; |
1320 | } | 1283 | } |
1321 | 1284 | ||
1322 | /* Make sure the pins are configured for input */ | 1285 | /* Make sure the pins are configured for input */ |
1323 | if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { | 1286 | if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { |
1324 | dev_dbg(&client->dev, "VID configured as output, " | 1287 | dev_dbg(&pdev->dev, "VID configured as output, " |
1325 | "no VID function\n"); | 1288 | "no VID function\n"); |
1326 | goto exit; | 1289 | goto exit; |
1327 | } | 1290 | } |
@@ -1333,9 +1296,8 @@ exit: | |||
1333 | return res; | 1296 | return res; |
1334 | } | 1297 | } |
1335 | 1298 | ||
1336 | static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) | 1299 | static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value) |
1337 | { | 1300 | { |
1338 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
1339 | int word_sized; | 1301 | int word_sized; |
1340 | 1302 | ||
1341 | mutex_lock(&data->lock); | 1303 | mutex_lock(&data->lock); |
@@ -1345,31 +1307,31 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) | |||
1345 | || ((reg & 0x00ff) == 0x55)); | 1307 | || ((reg & 0x00ff) == 0x55)); |
1346 | if (reg & 0xff00) { | 1308 | if (reg & 0xff00) { |
1347 | outb_p(W83781D_REG_BANK, | 1309 | outb_p(W83781D_REG_BANK, |
1348 | client->addr + W83781D_ADDR_REG_OFFSET); | 1310 | data->addr + W83781D_ADDR_REG_OFFSET); |
1349 | outb_p(reg >> 8, | 1311 | outb_p(reg >> 8, |
1350 | client->addr + W83781D_DATA_REG_OFFSET); | 1312 | data->addr + W83781D_DATA_REG_OFFSET); |
1351 | } | 1313 | } |
1352 | outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); | 1314 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
1353 | if (word_sized) { | 1315 | if (word_sized) { |
1354 | outb_p(value >> 8, | 1316 | outb_p(value >> 8, |
1355 | client->addr + W83781D_DATA_REG_OFFSET); | 1317 | data->addr + W83781D_DATA_REG_OFFSET); |
1356 | outb_p((reg & 0xff) + 1, | 1318 | outb_p((reg & 0xff) + 1, |
1357 | client->addr + W83781D_ADDR_REG_OFFSET); | 1319 | data->addr + W83781D_ADDR_REG_OFFSET); |
1358 | } | 1320 | } |
1359 | outb_p(value & 0xff, | 1321 | outb_p(value & 0xff, |
1360 | client->addr + W83781D_DATA_REG_OFFSET); | 1322 | data->addr + W83781D_DATA_REG_OFFSET); |
1361 | if (reg & 0xff00) { | 1323 | if (reg & 0xff00) { |
1362 | outb_p(W83781D_REG_BANK, | 1324 | outb_p(W83781D_REG_BANK, |
1363 | client->addr + W83781D_ADDR_REG_OFFSET); | 1325 | data->addr + W83781D_ADDR_REG_OFFSET); |
1364 | outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); | 1326 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
1365 | } | 1327 | } |
1366 | mutex_unlock(&data->lock); | 1328 | mutex_unlock(&data->lock); |
1367 | return 0; | 1329 | return 0; |
1368 | } | 1330 | } |
1369 | 1331 | ||
1370 | static void w83627hf_init_client(struct i2c_client *client) | 1332 | static void __devinit w83627hf_init_device(struct platform_device *pdev) |
1371 | { | 1333 | { |
1372 | struct w83627hf_data *data = i2c_get_clientdata(client); | 1334 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
1373 | int i; | 1335 | int i; |
1374 | enum chips type = data->type; | 1336 | enum chips type = data->type; |
1375 | u8 tmp; | 1337 | u8 tmp; |
@@ -1380,53 +1342,53 @@ static void w83627hf_init_client(struct i2c_client *client) | |||
1380 | speed...) so it is now optional. It might even go away if | 1342 | speed...) so it is now optional. It might even go away if |
1381 | nobody reports it as being useful, as I see very little | 1343 | nobody reports it as being useful, as I see very little |
1382 | reason why this would be needed at all. */ | 1344 | reason why this would be needed at all. */ |
1383 | dev_info(&client->dev, "If reset=1 solved a problem you were " | 1345 | dev_info(&pdev->dev, "If reset=1 solved a problem you were " |
1384 | "having, please report!\n"); | 1346 | "having, please report!\n"); |
1385 | 1347 | ||
1386 | /* save this register */ | 1348 | /* save this register */ |
1387 | i = w83627hf_read_value(client, W83781D_REG_BEEP_CONFIG); | 1349 | i = w83627hf_read_value(data, W83781D_REG_BEEP_CONFIG); |
1388 | /* Reset all except Watchdog values and last conversion values | 1350 | /* Reset all except Watchdog values and last conversion values |
1389 | This sets fan-divs to 2, among others */ | 1351 | This sets fan-divs to 2, among others */ |
1390 | w83627hf_write_value(client, W83781D_REG_CONFIG, 0x80); | 1352 | w83627hf_write_value(data, W83781D_REG_CONFIG, 0x80); |
1391 | /* Restore the register and disable power-on abnormal beep. | 1353 | /* Restore the register and disable power-on abnormal beep. |
1392 | This saves FAN 1/2/3 input/output values set by BIOS. */ | 1354 | This saves FAN 1/2/3 input/output values set by BIOS. */ |
1393 | w83627hf_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80); | 1355 | w83627hf_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80); |
1394 | /* Disable master beep-enable (reset turns it on). | 1356 | /* Disable master beep-enable (reset turns it on). |
1395 | Individual beeps should be reset to off but for some reason | 1357 | Individual beeps should be reset to off but for some reason |
1396 | disabling this bit helps some people not get beeped */ | 1358 | disabling this bit helps some people not get beeped */ |
1397 | w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, 0); | 1359 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, 0); |
1398 | } | 1360 | } |
1399 | 1361 | ||
1400 | /* Minimize conflicts with other winbond i2c-only clients... */ | 1362 | /* Minimize conflicts with other winbond i2c-only clients... */ |
1401 | /* disable i2c subclients... how to disable main i2c client?? */ | 1363 | /* disable i2c subclients... how to disable main i2c client?? */ |
1402 | /* force i2c address to relatively uncommon address */ | 1364 | /* force i2c address to relatively uncommon address */ |
1403 | w83627hf_write_value(client, W83781D_REG_I2C_SUBADDR, 0x89); | 1365 | w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89); |
1404 | w83627hf_write_value(client, W83781D_REG_I2C_ADDR, force_i2c); | 1366 | w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c); |
1405 | 1367 | ||
1406 | /* Read VID only once */ | 1368 | /* Read VID only once */ |
1407 | if (type == w83627hf || type == w83637hf) { | 1369 | if (type == w83627hf || type == w83637hf) { |
1408 | int lo = w83627hf_read_value(client, W83781D_REG_VID_FANDIV); | 1370 | int lo = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
1409 | int hi = w83627hf_read_value(client, W83781D_REG_CHIPID); | 1371 | int hi = w83627hf_read_value(data, W83781D_REG_CHIPID); |
1410 | data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); | 1372 | data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); |
1411 | } else if (type == w83627thf) { | 1373 | } else if (type == w83627thf) { |
1412 | data->vid = w83627thf_read_gpio5(client); | 1374 | data->vid = w83627thf_read_gpio5(pdev); |
1413 | } else if (type == w83687thf) { | 1375 | } else if (type == w83687thf) { |
1414 | data->vid = w83687thf_read_vid(client); | 1376 | data->vid = w83687thf_read_vid(pdev); |
1415 | } | 1377 | } |
1416 | 1378 | ||
1417 | /* Read VRM & OVT Config only once */ | 1379 | /* Read VRM & OVT Config only once */ |
1418 | if (type == w83627thf || type == w83637hf || type == w83687thf) { | 1380 | if (type == w83627thf || type == w83637hf || type == w83687thf) { |
1419 | data->vrm_ovt = | 1381 | data->vrm_ovt = |
1420 | w83627hf_read_value(client, W83627THF_REG_VRM_OVT_CFG); | 1382 | w83627hf_read_value(data, W83627THF_REG_VRM_OVT_CFG); |
1421 | } | 1383 | } |
1422 | 1384 | ||
1423 | tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); | 1385 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
1424 | for (i = 1; i <= 3; i++) { | 1386 | for (i = 1; i <= 3; i++) { |
1425 | if (!(tmp & BIT_SCFG1[i - 1])) { | 1387 | if (!(tmp & BIT_SCFG1[i - 1])) { |
1426 | data->sens[i - 1] = W83781D_DEFAULT_BETA; | 1388 | data->sens[i - 1] = W83781D_DEFAULT_BETA; |
1427 | } else { | 1389 | } else { |
1428 | if (w83627hf_read_value | 1390 | if (w83627hf_read_value |
1429 | (client, | 1391 | (data, |
1430 | W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) | 1392 | W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) |
1431 | data->sens[i - 1] = 1; | 1393 | data->sens[i - 1] = 1; |
1432 | else | 1394 | else |
@@ -1438,38 +1400,37 @@ static void w83627hf_init_client(struct i2c_client *client) | |||
1438 | 1400 | ||
1439 | if(init) { | 1401 | if(init) { |
1440 | /* Enable temp2 */ | 1402 | /* Enable temp2 */ |
1441 | tmp = w83627hf_read_value(client, W83781D_REG_TEMP2_CONFIG); | 1403 | tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG); |
1442 | if (tmp & 0x01) { | 1404 | if (tmp & 0x01) { |
1443 | dev_warn(&client->dev, "Enabling temp2, readings " | 1405 | dev_warn(&pdev->dev, "Enabling temp2, readings " |
1444 | "might not make sense\n"); | 1406 | "might not make sense\n"); |
1445 | w83627hf_write_value(client, W83781D_REG_TEMP2_CONFIG, | 1407 | w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG, |
1446 | tmp & 0xfe); | 1408 | tmp & 0xfe); |
1447 | } | 1409 | } |
1448 | 1410 | ||
1449 | /* Enable temp3 */ | 1411 | /* Enable temp3 */ |
1450 | if (type != w83697hf) { | 1412 | if (type != w83697hf) { |
1451 | tmp = w83627hf_read_value(client, | 1413 | tmp = w83627hf_read_value(data, |
1452 | W83781D_REG_TEMP3_CONFIG); | 1414 | W83781D_REG_TEMP3_CONFIG); |
1453 | if (tmp & 0x01) { | 1415 | if (tmp & 0x01) { |
1454 | dev_warn(&client->dev, "Enabling temp3, " | 1416 | dev_warn(&pdev->dev, "Enabling temp3, " |
1455 | "readings might not make sense\n"); | 1417 | "readings might not make sense\n"); |
1456 | w83627hf_write_value(client, | 1418 | w83627hf_write_value(data, |
1457 | W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); | 1419 | W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); |
1458 | } | 1420 | } |
1459 | } | 1421 | } |
1460 | } | 1422 | } |
1461 | 1423 | ||
1462 | /* Start monitoring */ | 1424 | /* Start monitoring */ |
1463 | w83627hf_write_value(client, W83781D_REG_CONFIG, | 1425 | w83627hf_write_value(data, W83781D_REG_CONFIG, |
1464 | (w83627hf_read_value(client, | 1426 | (w83627hf_read_value(data, |
1465 | W83781D_REG_CONFIG) & 0xf7) | 1427 | W83781D_REG_CONFIG) & 0xf7) |
1466 | | 0x01); | 1428 | | 0x01); |
1467 | } | 1429 | } |
1468 | 1430 | ||
1469 | static struct w83627hf_data *w83627hf_update_device(struct device *dev) | 1431 | static struct w83627hf_data *w83627hf_update_device(struct device *dev) |
1470 | { | 1432 | { |
1471 | struct i2c_client *client = to_i2c_client(dev); | 1433 | struct w83627hf_data *data = dev_get_drvdata(dev); |
1472 | struct w83627hf_data *data = i2c_get_clientdata(client); | ||
1473 | int i; | 1434 | int i; |
1474 | 1435 | ||
1475 | mutex_lock(&data->update_lock); | 1436 | mutex_lock(&data->update_lock); |
@@ -1483,23 +1444,23 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1483 | && (i == 5 || i == 6))) | 1444 | && (i == 5 || i == 6))) |
1484 | continue; | 1445 | continue; |
1485 | data->in[i] = | 1446 | data->in[i] = |
1486 | w83627hf_read_value(client, W83781D_REG_IN(i)); | 1447 | w83627hf_read_value(data, W83781D_REG_IN(i)); |
1487 | data->in_min[i] = | 1448 | data->in_min[i] = |
1488 | w83627hf_read_value(client, | 1449 | w83627hf_read_value(data, |
1489 | W83781D_REG_IN_MIN(i)); | 1450 | W83781D_REG_IN_MIN(i)); |
1490 | data->in_max[i] = | 1451 | data->in_max[i] = |
1491 | w83627hf_read_value(client, | 1452 | w83627hf_read_value(data, |
1492 | W83781D_REG_IN_MAX(i)); | 1453 | W83781D_REG_IN_MAX(i)); |
1493 | } | 1454 | } |
1494 | for (i = 1; i <= 3; i++) { | 1455 | for (i = 1; i <= 3; i++) { |
1495 | data->fan[i - 1] = | 1456 | data->fan[i - 1] = |
1496 | w83627hf_read_value(client, W83781D_REG_FAN(i)); | 1457 | w83627hf_read_value(data, W83781D_REG_FAN(i)); |
1497 | data->fan_min[i - 1] = | 1458 | data->fan_min[i - 1] = |
1498 | w83627hf_read_value(client, | 1459 | w83627hf_read_value(data, |
1499 | W83781D_REG_FAN_MIN(i)); | 1460 | W83781D_REG_FAN_MIN(i)); |
1500 | } | 1461 | } |
1501 | for (i = 1; i <= 3; i++) { | 1462 | for (i = 1; i <= 3; i++) { |
1502 | u8 tmp = w83627hf_read_value(client, | 1463 | u8 tmp = w83627hf_read_value(data, |
1503 | W836X7HF_REG_PWM(data->type, i)); | 1464 | W836X7HF_REG_PWM(data->type, i)); |
1504 | /* bits 0-3 are reserved in 627THF */ | 1465 | /* bits 0-3 are reserved in 627THF */ |
1505 | if (data->type == w83627thf) | 1466 | if (data->type == w83627thf) |
@@ -1510,47 +1471,47 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1510 | break; | 1471 | break; |
1511 | } | 1472 | } |
1512 | 1473 | ||
1513 | data->temp = w83627hf_read_value(client, W83781D_REG_TEMP(1)); | 1474 | data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); |
1514 | data->temp_max = | 1475 | data->temp_max = |
1515 | w83627hf_read_value(client, W83781D_REG_TEMP_OVER(1)); | 1476 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1)); |
1516 | data->temp_max_hyst = | 1477 | data->temp_max_hyst = |
1517 | w83627hf_read_value(client, W83781D_REG_TEMP_HYST(1)); | 1478 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1)); |
1518 | data->temp_add[0] = | 1479 | data->temp_add[0] = |
1519 | w83627hf_read_value(client, W83781D_REG_TEMP(2)); | 1480 | w83627hf_read_value(data, W83781D_REG_TEMP(2)); |
1520 | data->temp_max_add[0] = | 1481 | data->temp_max_add[0] = |
1521 | w83627hf_read_value(client, W83781D_REG_TEMP_OVER(2)); | 1482 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(2)); |
1522 | data->temp_max_hyst_add[0] = | 1483 | data->temp_max_hyst_add[0] = |
1523 | w83627hf_read_value(client, W83781D_REG_TEMP_HYST(2)); | 1484 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(2)); |
1524 | if (data->type != w83697hf) { | 1485 | if (data->type != w83697hf) { |
1525 | data->temp_add[1] = | 1486 | data->temp_add[1] = |
1526 | w83627hf_read_value(client, W83781D_REG_TEMP(3)); | 1487 | w83627hf_read_value(data, W83781D_REG_TEMP(3)); |
1527 | data->temp_max_add[1] = | 1488 | data->temp_max_add[1] = |
1528 | w83627hf_read_value(client, W83781D_REG_TEMP_OVER(3)); | 1489 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(3)); |
1529 | data->temp_max_hyst_add[1] = | 1490 | data->temp_max_hyst_add[1] = |
1530 | w83627hf_read_value(client, W83781D_REG_TEMP_HYST(3)); | 1491 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(3)); |
1531 | } | 1492 | } |
1532 | 1493 | ||
1533 | i = w83627hf_read_value(client, W83781D_REG_VID_FANDIV); | 1494 | i = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
1534 | data->fan_div[0] = (i >> 4) & 0x03; | 1495 | data->fan_div[0] = (i >> 4) & 0x03; |
1535 | data->fan_div[1] = (i >> 6) & 0x03; | 1496 | data->fan_div[1] = (i >> 6) & 0x03; |
1536 | if (data->type != w83697hf) { | 1497 | if (data->type != w83697hf) { |
1537 | data->fan_div[2] = (w83627hf_read_value(client, | 1498 | data->fan_div[2] = (w83627hf_read_value(data, |
1538 | W83781D_REG_PIN) >> 6) & 0x03; | 1499 | W83781D_REG_PIN) >> 6) & 0x03; |
1539 | } | 1500 | } |
1540 | i = w83627hf_read_value(client, W83781D_REG_VBAT); | 1501 | i = w83627hf_read_value(data, W83781D_REG_VBAT); |
1541 | data->fan_div[0] |= (i >> 3) & 0x04; | 1502 | data->fan_div[0] |= (i >> 3) & 0x04; |
1542 | data->fan_div[1] |= (i >> 4) & 0x04; | 1503 | data->fan_div[1] |= (i >> 4) & 0x04; |
1543 | if (data->type != w83697hf) | 1504 | if (data->type != w83697hf) |
1544 | data->fan_div[2] |= (i >> 5) & 0x04; | 1505 | data->fan_div[2] |= (i >> 5) & 0x04; |
1545 | data->alarms = | 1506 | data->alarms = |
1546 | w83627hf_read_value(client, W83781D_REG_ALARM1) | | 1507 | w83627hf_read_value(data, W83781D_REG_ALARM1) | |
1547 | (w83627hf_read_value(client, W83781D_REG_ALARM2) << 8) | | 1508 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | |
1548 | (w83627hf_read_value(client, W83781D_REG_ALARM3) << 16); | 1509 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); |
1549 | i = w83627hf_read_value(client, W83781D_REG_BEEP_INTS2); | 1510 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
1550 | data->beep_enable = i >> 7; | 1511 | data->beep_enable = i >> 7; |
1551 | data->beep_mask = ((i & 0x7f) << 8) | | 1512 | data->beep_mask = ((i & 0x7f) << 8) | |
1552 | w83627hf_read_value(client, W83781D_REG_BEEP_INTS1) | | 1513 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | |
1553 | w83627hf_read_value(client, W83781D_REG_BEEP_INTS3) << 16; | 1514 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; |
1554 | data->last_updated = jiffies; | 1515 | data->last_updated = jiffies; |
1555 | data->valid = 1; | 1516 | data->valid = 1; |
1556 | } | 1517 | } |
@@ -1560,19 +1521,87 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev) | |||
1560 | return data; | 1521 | return data; |
1561 | } | 1522 | } |
1562 | 1523 | ||
1524 | static int __init w83627hf_device_add(unsigned short address, | ||
1525 | const struct w83627hf_sio_data *sio_data) | ||
1526 | { | ||
1527 | struct resource res = { | ||
1528 | .start = address + WINB_REGION_OFFSET, | ||
1529 | .end = address + WINB_REGION_OFFSET + WINB_REGION_SIZE - 1, | ||
1530 | .name = DRVNAME, | ||
1531 | .flags = IORESOURCE_IO, | ||
1532 | }; | ||
1533 | int err; | ||
1534 | |||
1535 | pdev = platform_device_alloc(DRVNAME, address); | ||
1536 | if (!pdev) { | ||
1537 | err = -ENOMEM; | ||
1538 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | ||
1539 | goto exit; | ||
1540 | } | ||
1541 | |||
1542 | err = platform_device_add_resources(pdev, &res, 1); | ||
1543 | if (err) { | ||
1544 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | ||
1545 | "(%d)\n", err); | ||
1546 | goto exit_device_put; | ||
1547 | } | ||
1548 | |||
1549 | pdev->dev.platform_data = kmalloc(sizeof(struct w83627hf_sio_data), | ||
1550 | GFP_KERNEL); | ||
1551 | if (!pdev->dev.platform_data) { | ||
1552 | err = -ENOMEM; | ||
1553 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | ||
1554 | goto exit_device_put; | ||
1555 | } | ||
1556 | memcpy(pdev->dev.platform_data, sio_data, | ||
1557 | sizeof(struct w83627hf_sio_data)); | ||
1558 | |||
1559 | err = platform_device_add(pdev); | ||
1560 | if (err) { | ||
1561 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | ||
1562 | err); | ||
1563 | goto exit_device_put; | ||
1564 | } | ||
1565 | |||
1566 | return 0; | ||
1567 | |||
1568 | exit_device_put: | ||
1569 | platform_device_put(pdev); | ||
1570 | exit: | ||
1571 | return err; | ||
1572 | } | ||
1573 | |||
1563 | static int __init sensors_w83627hf_init(void) | 1574 | static int __init sensors_w83627hf_init(void) |
1564 | { | 1575 | { |
1565 | if (w83627hf_find(0x2e, &address) | 1576 | int err; |
1566 | && w83627hf_find(0x4e, &address)) { | 1577 | unsigned short address; |
1578 | struct w83627hf_sio_data sio_data; | ||
1579 | |||
1580 | if (w83627hf_find(0x2e, &address, &sio_data) | ||
1581 | && w83627hf_find(0x4e, &address, &sio_data)) | ||
1567 | return -ENODEV; | 1582 | return -ENODEV; |
1568 | } | ||
1569 | 1583 | ||
1570 | return i2c_isa_add_driver(&w83627hf_driver); | 1584 | err = platform_driver_register(&w83627hf_driver); |
1585 | if (err) | ||
1586 | goto exit; | ||
1587 | |||
1588 | /* Sets global pdev as a side effect */ | ||
1589 | err = w83627hf_device_add(address, &sio_data); | ||
1590 | if (err) | ||
1591 | goto exit_driver; | ||
1592 | |||
1593 | return 0; | ||
1594 | |||
1595 | exit_driver: | ||
1596 | platform_driver_unregister(&w83627hf_driver); | ||
1597 | exit: | ||
1598 | return err; | ||
1571 | } | 1599 | } |
1572 | 1600 | ||
1573 | static void __exit sensors_w83627hf_exit(void) | 1601 | static void __exit sensors_w83627hf_exit(void) |
1574 | { | 1602 | { |
1575 | i2c_isa_del_driver(&w83627hf_driver); | 1603 | platform_device_unregister(pdev); |
1604 | platform_driver_unregister(&w83627hf_driver); | ||
1576 | } | 1605 | } |
1577 | 1606 | ||
1578 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " | 1607 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " |