diff options
Diffstat (limited to 'drivers/hwmon/via686a.c')
-rw-r--r-- | drivers/hwmon/via686a.c | 76 |
1 files changed, 31 insertions, 45 deletions
diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 164d47948390..eb84997627c8 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c | |||
@@ -35,7 +35,9 @@ | |||
35 | #include <linux/pci.h> | 35 | #include <linux/pci.h> |
36 | #include <linux/jiffies.h> | 36 | #include <linux/jiffies.h> |
37 | #include <linux/i2c.h> | 37 | #include <linux/i2c.h> |
38 | #include <linux/i2c-sensor.h> | 38 | #include <linux/i2c-isa.h> |
39 | #include <linux/hwmon.h> | ||
40 | #include <linux/err.h> | ||
39 | #include <linux/init.h> | 41 | #include <linux/init.h> |
40 | #include <asm/io.h> | 42 | #include <asm/io.h> |
41 | 43 | ||
@@ -47,14 +49,10 @@ module_param(force_addr, ushort, 0); | |||
47 | MODULE_PARM_DESC(force_addr, | 49 | MODULE_PARM_DESC(force_addr, |
48 | "Initialize the base address of the sensors"); | 50 | "Initialize the base address of the sensors"); |
49 | 51 | ||
50 | /* Addresses to scan. | 52 | /* Device address |
51 | Note that we can't determine the ISA address until we have initialized | 53 | Note that we can't determine the ISA address until we have initialized |
52 | our module */ | 54 | our module */ |
53 | static unsigned short normal_i2c[] = { I2C_CLIENT_END }; | 55 | static unsigned short address; |
54 | static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END }; | ||
55 | |||
56 | /* Insmod parameters */ | ||
57 | SENSORS_INSMOD_1(via686a); | ||
58 | 56 | ||
59 | /* | 57 | /* |
60 | The Via 686a southbridge has a LM78-like chip integrated on the same IC. | 58 | The Via 686a southbridge has a LM78-like chip integrated on the same IC. |
@@ -297,6 +295,7 @@ static inline long TEMP_FROM_REG10(u16 val) | |||
297 | via686a client is allocated. */ | 295 | via686a client is allocated. */ |
298 | struct via686a_data { | 296 | struct via686a_data { |
299 | struct i2c_client client; | 297 | struct i2c_client client; |
298 | struct class_device *class_dev; | ||
300 | struct semaphore update_lock; | 299 | struct semaphore update_lock; |
301 | char valid; /* !=0 if following fields are valid */ | 300 | char valid; /* !=0 if following fields are valid */ |
302 | unsigned long last_updated; /* In jiffies */ | 301 | unsigned long last_updated; /* In jiffies */ |
@@ -315,8 +314,7 @@ struct via686a_data { | |||
315 | 314 | ||
316 | static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ | 315 | static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ |
317 | 316 | ||
318 | static int via686a_attach_adapter(struct i2c_adapter *adapter); | 317 | static int via686a_detect(struct i2c_adapter *adapter); |
319 | static int via686a_detect(struct i2c_adapter *adapter, int address, int kind); | ||
320 | static int via686a_detach_client(struct i2c_client *client); | 318 | static int via686a_detach_client(struct i2c_client *client); |
321 | 319 | ||
322 | static inline int via686a_read_value(struct i2c_client *client, u8 reg) | 320 | static inline int via686a_read_value(struct i2c_client *client, u8 reg) |
@@ -576,22 +574,13 @@ static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | |||
576 | static struct i2c_driver via686a_driver = { | 574 | static struct i2c_driver via686a_driver = { |
577 | .owner = THIS_MODULE, | 575 | .owner = THIS_MODULE, |
578 | .name = "via686a", | 576 | .name = "via686a", |
579 | .id = I2C_DRIVERID_VIA686A, | 577 | .attach_adapter = via686a_detect, |
580 | .flags = I2C_DF_NOTIFY, | ||
581 | .attach_adapter = via686a_attach_adapter, | ||
582 | .detach_client = via686a_detach_client, | 578 | .detach_client = via686a_detach_client, |
583 | }; | 579 | }; |
584 | 580 | ||
585 | 581 | ||
586 | /* This is called when the module is loaded */ | 582 | /* This is called when the module is loaded */ |
587 | static int via686a_attach_adapter(struct i2c_adapter *adapter) | 583 | static int via686a_detect(struct i2c_adapter *adapter) |
588 | { | ||
589 | if (!(adapter->class & I2C_CLASS_HWMON)) | ||
590 | return 0; | ||
591 | return i2c_detect(adapter, &addr_data, via686a_detect); | ||
592 | } | ||
593 | |||
594 | static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | ||
595 | { | 584 | { |
596 | struct i2c_client *new_client; | 585 | struct i2c_client *new_client; |
597 | struct via686a_data *data; | 586 | struct via686a_data *data; |
@@ -599,13 +588,6 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
599 | const char client_name[] = "via686a"; | 588 | const char client_name[] = "via686a"; |
600 | u16 val; | 589 | u16 val; |
601 | 590 | ||
602 | /* Make sure we are probing the ISA bus!! */ | ||
603 | if (!i2c_is_isa_adapter(adapter)) { | ||
604 | dev_err(&adapter->dev, | ||
605 | "via686a_detect called for an I2C bus adapter?!?\n"); | ||
606 | return 0; | ||
607 | } | ||
608 | |||
609 | /* 8231 requires multiple of 256, we enforce that on 686 as well */ | 591 | /* 8231 requires multiple of 256, we enforce that on 686 as well */ |
610 | if (force_addr) | 592 | if (force_addr) |
611 | address = force_addr & 0xFF00; | 593 | address = force_addr & 0xFF00; |
@@ -637,7 +619,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
637 | 619 | ||
638 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { | 620 | if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { |
639 | err = -ENOMEM; | 621 | err = -ENOMEM; |
640 | goto ERROR0; | 622 | goto exit_release; |
641 | } | 623 | } |
642 | memset(data, 0, sizeof(struct via686a_data)); | 624 | memset(data, 0, sizeof(struct via686a_data)); |
643 | 625 | ||
@@ -655,12 +637,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
655 | init_MUTEX(&data->update_lock); | 637 | init_MUTEX(&data->update_lock); |
656 | /* Tell the I2C layer a new client has arrived */ | 638 | /* Tell the I2C layer a new client has arrived */ |
657 | if ((err = i2c_attach_client(new_client))) | 639 | if ((err = i2c_attach_client(new_client))) |
658 | goto ERROR3; | 640 | goto exit_free; |
659 | 641 | ||
660 | /* Initialize the VIA686A chip */ | 642 | /* Initialize the VIA686A chip */ |
661 | via686a_init_client(new_client); | 643 | via686a_init_client(new_client); |
662 | 644 | ||
663 | /* Register sysfs hooks */ | 645 | /* Register sysfs hooks */ |
646 | data->class_dev = hwmon_device_register(&new_client->dev); | ||
647 | if (IS_ERR(data->class_dev)) { | ||
648 | err = PTR_ERR(data->class_dev); | ||
649 | goto exit_detach; | ||
650 | } | ||
651 | |||
664 | device_create_file(&new_client->dev, &dev_attr_in0_input); | 652 | device_create_file(&new_client->dev, &dev_attr_in0_input); |
665 | device_create_file(&new_client->dev, &dev_attr_in1_input); | 653 | device_create_file(&new_client->dev, &dev_attr_in1_input); |
666 | device_create_file(&new_client->dev, &dev_attr_in2_input); | 654 | device_create_file(&new_client->dev, &dev_attr_in2_input); |
@@ -695,25 +683,27 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) | |||
695 | 683 | ||
696 | return 0; | 684 | return 0; |
697 | 685 | ||
698 | ERROR3: | 686 | exit_detach: |
687 | i2c_detach_client(new_client); | ||
688 | exit_free: | ||
699 | kfree(data); | 689 | kfree(data); |
700 | ERROR0: | 690 | exit_release: |
701 | release_region(address, VIA686A_EXTENT); | 691 | release_region(address, VIA686A_EXTENT); |
702 | return err; | 692 | return err; |
703 | } | 693 | } |
704 | 694 | ||
705 | static int via686a_detach_client(struct i2c_client *client) | 695 | static int via686a_detach_client(struct i2c_client *client) |
706 | { | 696 | { |
697 | struct via686a_data *data = i2c_get_clientdata(client); | ||
707 | int err; | 698 | int err; |
708 | 699 | ||
709 | if ((err = i2c_detach_client(client))) { | 700 | hwmon_device_unregister(data->class_dev); |
710 | dev_err(&client->dev, | 701 | |
711 | "Client deregistration failed, client not detached.\n"); | 702 | if ((err = i2c_detach_client(client))) |
712 | return err; | 703 | return err; |
713 | } | ||
714 | 704 | ||
715 | release_region(client->addr, VIA686A_EXTENT); | 705 | release_region(client->addr, VIA686A_EXTENT); |
716 | kfree(i2c_get_clientdata(client)); | 706 | kfree(data); |
717 | 707 | ||
718 | return 0; | 708 | return 0; |
719 | } | 709 | } |
@@ -810,29 +800,25 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev, | |||
810 | const struct pci_device_id *id) | 800 | const struct pci_device_id *id) |
811 | { | 801 | { |
812 | u16 val; | 802 | u16 val; |
813 | int addr = 0; | ||
814 | 803 | ||
815 | if (PCIBIOS_SUCCESSFUL != | 804 | if (PCIBIOS_SUCCESSFUL != |
816 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) | 805 | pci_read_config_word(dev, VIA686A_BASE_REG, &val)) |
817 | return -ENODEV; | 806 | return -ENODEV; |
818 | 807 | ||
819 | addr = val & ~(VIA686A_EXTENT - 1); | 808 | address = val & ~(VIA686A_EXTENT - 1); |
820 | if (addr == 0 && force_addr == 0) { | 809 | if (address == 0 && force_addr == 0) { |
821 | dev_err(&dev->dev, "base address not set - upgrade BIOS " | 810 | dev_err(&dev->dev, "base address not set - upgrade BIOS " |
822 | "or use force_addr=0xaddr\n"); | 811 | "or use force_addr=0xaddr\n"); |
823 | return -ENODEV; | 812 | return -ENODEV; |
824 | } | 813 | } |
825 | if (force_addr) | ||
826 | addr = force_addr; /* so detect will get called */ | ||
827 | 814 | ||
828 | if (!addr) { | 815 | if (!address) { |
829 | dev_err(&dev->dev, "No Via 686A sensors found.\n"); | 816 | dev_err(&dev->dev, "No Via 686A sensors found.\n"); |
830 | return -ENODEV; | 817 | return -ENODEV; |
831 | } | 818 | } |
832 | normal_isa[0] = addr; | ||
833 | 819 | ||
834 | s_bridge = pci_dev_get(dev); | 820 | s_bridge = pci_dev_get(dev); |
835 | if (i2c_add_driver(&via686a_driver)) { | 821 | if (i2c_isa_add_driver(&via686a_driver)) { |
836 | pci_dev_put(s_bridge); | 822 | pci_dev_put(s_bridge); |
837 | s_bridge = NULL; | 823 | s_bridge = NULL; |
838 | } | 824 | } |
@@ -859,7 +845,7 @@ static void __exit sm_via686a_exit(void) | |||
859 | { | 845 | { |
860 | pci_unregister_driver(&via686a_pci_driver); | 846 | pci_unregister_driver(&via686a_pci_driver); |
861 | if (s_bridge != NULL) { | 847 | if (s_bridge != NULL) { |
862 | i2c_del_driver(&via686a_driver); | 848 | i2c_isa_del_driver(&via686a_driver); |
863 | pci_dev_put(s_bridge); | 849 | pci_dev_put(s_bridge); |
864 | s_bridge = NULL; | 850 | s_bridge = NULL; |
865 | } | 851 | } |