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