X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fhwmon%2Fvia686a.c;h=6f696f897176b678b05a11228a775d3abc603c05;hb=8a87a0b6313109d2fea87b1271d497c954ce2ca8;hp=164d47948390d39206537b206c5e11c9a2c6faa1;hpb=2d986010ad13a00b83851238d52601d6092df40e;p=linux-2.6-omap-h63xx.git diff --git a/drivers/hwmon/via686a.c b/drivers/hwmon/via686a.c index 164d4794839..6f696f89717 100644 --- a/drivers/hwmon/via686a.c +++ b/drivers/hwmon/via686a.c @@ -35,26 +35,24 @@ #include #include #include -#include +#include +#include +#include #include #include /* If force_addr is set to anything different from 0, we forcibly enable the device at the given address. */ -static unsigned short force_addr = 0; +static unsigned short force_addr; 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. @@ -200,7 +198,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) but the function is very linear in the useful range (0-80 deg C), so we'll just use linear interpolation for 10-bit readings.) So, tempLUT is the temp at via register values 0-255: */ -static const long tempLUT[] = +static const s16 tempLUT[] = { -709, -688, -667, -646, -627, -607, -589, -570, -553, -536, -519, -503, -487, -471, -456, -442, -428, -414, -400, -387, -375, -362, -350, -339, -327, -316, -305, -295, -285, -275, -265, @@ -272,7 +270,7 @@ static inline u8 TEMP_TO_REG(long val) } /* for 8-bit temperature hyst and over registers */ -#define TEMP_FROM_REG(val) (tempLUT[(val)] * 100) +#define TEMP_FROM_REG(val) ((long)tempLUT[val] * 100) /* for 10-bit temperature readings */ static inline long TEMP_FROM_REG10(u16 val) @@ -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,18 +588,9 @@ 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; - if (force_addr) { + address = force_addr & 0xFF00; dev_warn(&adapter->dev, "forcing ISA address 0x%04X\n", address); if (PCIBIOS_SUCCESSFUL != @@ -621,11 +601,17 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) pci_read_config_word(s_bridge, VIA686A_ENABLE_REG, &val)) return -ENODEV; if (!(val & 0x0001)) { - dev_warn(&adapter->dev, "enabling sensors\n"); - if (PCIBIOS_SUCCESSFUL != - pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, - val | 0x0001)) + if (force_addr) { + dev_info(&adapter->dev, "enabling sensors\n"); + if (PCIBIOS_SUCCESSFUL != + pci_write_config_word(s_bridge, VIA686A_ENABLE_REG, + val | 0x0001)) + return -ENODEV; + } else { + dev_warn(&adapter->dev, "sensors disabled - enable " + "with force_addr=0x%x\n", address); return -ENODEV; + } } /* Reserve the ISA region */ @@ -635,11 +621,10 @@ static int via686a_detect(struct i2c_adapter *adapter, int address, int kind) return -ENODEV; } - if (!(data = kmalloc(sizeof(struct via686a_data), GFP_KERNEL))) { + if (!(data = kzalloc(sizeof(struct via686a_data), GFP_KERNEL))) { err = -ENOMEM; - goto ERROR0; + goto exit_release; } - memset(data, 0, sizeof(struct via686a_data)); new_client = &data->client; i2c_set_clientdata(new_client, data); @@ -655,12 +640,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,30 +686,31 @@ 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; } -/* Called when we have found a new VIA686A. Set limits, etc. */ static void via686a_init_client(struct i2c_client *client) { u8 reg; @@ -810,29 +802,20 @@ 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) { - 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 +842,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; }