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