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 @@ #include <linux/pci.h> #include <linux/jiffies.h> #include <linux/i2c.h> -#include <linux/i2c-sensor.h> +#include <linux/i2c-isa.h> +#include <linux/hwmon.h> +#include <linux/err.h> #include <linux/init.h> #include <asm/io.h> @@ -47,14 +49,10 @@ module_param(force_addr, ushort, 0); MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors"); -/* Addresses to scan. +/* Device address Note that we can't determine the ISA address until we have initialized our module */ -static unsigned short normal_i2c[] = { I2C_CLIENT_END }; -static unsigned int normal_isa[] = { 0x0000, I2C_CLIENT_ISA_END }; - -/* Insmod parameters */ -SENSORS_INSMOD_1(via686a); +static unsigned short address; /* 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) via686a client is allocated. */ struct via686a_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -315,8 +314,7 @@ struct via686a_data { static struct pci_dev *s_bridge; /* pointer to the (only) via686a */ -static int via686a_attach_adapter(struct i2c_adapter *adapter); -static int via686a_detect(struct i2c_adapter *adapter, int address, int kind); +static int via686a_detect(struct i2c_adapter *adapter); static int via686a_detach_client(struct i2c_client *client); 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); static struct i2c_driver via686a_driver = { .owner = THIS_MODULE, .name = "via686a", - .id = I2C_DRIVERID_VIA686A, - .flags = I2C_DF_NOTIFY, - .attach_adapter = via686a_attach_adapter, + .attach_adapter = via686a_detect, .detach_client = via686a_detach_client, }; /* This is called when the module is loaded */ -static int via686a_attach_adapter(struct i2c_adapter *adapter) -{ - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_detect(adapter, &addr_data, via686a_detect); -} - -static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) +static int via686a_detect(struct i2c_adapter *adapter) { struct i2c_client *new_client; struct via686a_data *data; @@ -599,13 +588,6 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) const char client_name[] = "via686a"; u16 val; - /* Make sure we are probing the ISA bus!! */ - if (!i2c_is_isa_adapter(adapter)) { - dev_err(&adapter->dev, - "via686a_detect called for an I2C bus adapter?!?\n"); - return 0; - } - /* 8231 requires multiple of 256, we enforce that on 686 as well */ if (force_addr) address = force_addr & 0xFF00; @@ -637,7 +619,7 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { err = -ENOMEM; - goto ERROR0; + goto exit_release; } memset(data, 0, sizeof(struct via686a_data)); @@ -655,12 +637,18 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) init_MUTEX(&data->update_lock); /* Tell the I2C layer a new client has arrived */ if ((err = i2c_attach_client(new_client))) - goto ERROR3; + goto exit_free; /* Initialize the VIA686A chip */ via686a_init_client(new_client); /* Register sysfs hooks */ + data->class_dev = hwmon_device_register(&new_client->dev); + if (IS_ERR(data->class_dev)) { + err = PTR_ERR(data->class_dev); + goto exit_detach; + } + device_create_file(&new_client->dev, &dev_attr_in0_input); device_create_file(&new_client->dev, &dev_attr_in1_input); 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) return 0; -ERROR3: +exit_detach: + i2c_detach_client(new_client); +exit_free: kfree(data); -ERROR0: +exit_release: release_region(address, VIA686A_EXTENT); return err; } static int via686a_detach_client(struct i2c_client *client) { + struct via686a_data *data = i2c_get_clientdata(client); int err; - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, - "Client deregistration failed, client not detached.\n"); + hwmon_device_unregister(data->class_dev); + + if ((err = i2c_detach_client(client))) return err; - } release_region(client->addr, VIA686A_EXTENT); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; } @@ -810,29 +800,25 @@ static int __devinit via686a_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { u16 val; - int addr = 0; if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VIA686A_BASE_REG, &val)) return -ENODEV; - addr = val & ~(VIA686A_EXTENT - 1); - if (addr == 0 && force_addr == 0) { + address = val & ~(VIA686A_EXTENT - 1); + if (address == 0 && force_addr == 0) { dev_err(&dev->dev, "base address not set - upgrade BIOS " "or use force_addr=0xaddr\n"); return -ENODEV; } - if (force_addr) - addr = force_addr; /* so detect will get called */ - if (!addr) { + if (!address) { dev_err(&dev->dev, "No Via 686A sensors found.\n"); return -ENODEV; } - normal_isa[0] = addr; s_bridge = pci_dev_get(dev); - if (i2c_add_driver(&via686a_driver)) { + if (i2c_isa_add_driver(&via686a_driver)) { pci_dev_put(s_bridge); s_bridge = NULL; } @@ -859,7 +845,7 @@ static void __exit sm_via686a_exit(void) { pci_unregister_driver(&via686a_pci_driver); if (s_bridge != NULL) { - i2c_del_driver(&via686a_driver); + i2c_isa_del_driver(&via686a_driver); pci_dev_put(s_bridge); s_bridge = NULL; } |