Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: convert it87 to platform driver

This is the patch for converting it87 to a platform driver (and remove i2c-isa).

Signed-off-by: Corentin LABBE <corentin.labbe@geomatys.fr>
Acked-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by

corentin.labbe and committed by
Mark M. Hoffman
b74f3fdd 04a6217d

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