diff options
Diffstat (limited to 'drivers/hwmon/adm1029.c')
| -rw-r--r-- | drivers/hwmon/adm1029.c | 221 |
1 files changed, 86 insertions, 135 deletions
diff --git a/drivers/hwmon/adm1029.c b/drivers/hwmon/adm1029.c index 2c6608d453c..2804571b269 100644 --- a/drivers/hwmon/adm1029.c +++ b/drivers/hwmon/adm1029.c @@ -1,9 +1,9 @@ /* * adm1029.c - Part of lm_sensors, Linux kernel modules for hardware monitoring * - * Copyright (C) 2006 Corentin LABBE <corentin.labbe@geomatys.fr> + * Copyright (C) 2006 Corentin LABBE <clabbe.montjoie@gmail.com> * - * Based on LM83 Driver by Jean Delvare <khali@linux-fr.org> + * Based on LM83 Driver by Jean Delvare <jdelvare@suse.de> * * Give only processor, motherboard temperatures and fan tachs * Very rare chip please let me know if you use it @@ -44,12 +44,6 @@ static const unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, }; /* - * Insmod parameters - */ - -I2C_CLIENT_INSMOD_1(adm1029); - -/* * The ADM1029 registers * Manufacturer ID is 0x41 for Analog Devices */ @@ -84,7 +78,7 @@ I2C_CLIENT_INSMOD_1(adm1029); #define TEMP_FROM_REG(val) ((val) * 1000) -#define DIV_FROM_REG(val) ( 1 << (((val) >> 6) - 1)) +#define DIV_FROM_REG(val) (1 << (((val) >> 6) - 1)) /* Registers to be checked by adm1029_update_device() */ static const u8 ADM1029_REG_TEMP[] = { @@ -115,9 +109,11 @@ static const u8 ADM1029_REG_FAN_DIV[] = { * Functions declaration */ -static int adm1029_attach_adapter(struct i2c_adapter *adapter); -static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind); -static int adm1029_detach_client(struct i2c_client *client); +static int adm1029_probe(struct i2c_client *client, + const struct i2c_device_id *id); +static int adm1029_detect(struct i2c_client *client, + struct i2c_board_info *info); +static int adm1029_remove(struct i2c_client *client); static struct adm1029_data *adm1029_update_device(struct device *dev); static int adm1029_init_client(struct i2c_client *client); @@ -125,12 +121,22 @@ static int adm1029_init_client(struct i2c_client *client); * Driver data (common to all clients) */ +static const struct i2c_device_id adm1029_id[] = { + { "adm1029", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, adm1029_id); + static struct i2c_driver adm1029_driver = { + .class = I2C_CLASS_HWMON, .driver = { .name = "adm1029", }, - .attach_adapter = adm1029_attach_adapter, - .detach_client = adm1029_detach_client, + .probe = adm1029_probe, + .remove = adm1029_remove, + .id_table = adm1029_id, + .detect = adm1029_detect, + .address_list = normal_i2c, }; /* @@ -138,7 +144,6 @@ static struct i2c_driver adm1029_driver = { */ struct adm1029_data { - struct i2c_client client; struct device *hwmon_dev; struct mutex update_lock; char valid; /* zero until following fields are valid */ @@ -168,7 +173,8 @@ show_fan(struct device *dev, struct device_attribute *devattr, char *buf) struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm1029_data *data = adm1029_update_device(dev); u16 val; - if (data->fan[attr->index] == 0 || data->fan_div[attr->index] == 0 + if (data->fan[attr->index] == 0 + || (data->fan_div[attr->index] & 0xC0) == 0 || data->fan[attr->index] == 255) { return sprintf(buf, "0\n"); } @@ -183,7 +189,7 @@ show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); struct adm1029_data *data = adm1029_update_device(dev); - if (data->fan_div[attr->index] == 0) + if ((data->fan_div[attr->index] & 0xC0) == 0) return sprintf(buf, "0\n"); return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index])); } @@ -194,8 +200,11 @@ static ssize_t set_fan_div(struct device *dev, struct i2c_client *client = to_i2c_client(dev); struct adm1029_data *data = i2c_get_clientdata(client); struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); - long val = simple_strtol(buf, NULL, 10); u8 reg; + long val; + int ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; mutex_lock(&data->update_lock); @@ -215,13 +224,17 @@ static ssize_t set_fan_div(struct device *dev, break; default: mutex_unlock(&data->update_lock); - dev_err(&client->dev, "fan_div value %ld not " - "supported. Choose one of 1, 2 or 4!\n", val); + dev_err(&client->dev, + "fan_div value %ld not supported. Choose one of 1, 2 or 4!\n", + val); return -EINVAL; } /* Update the value */ reg = (reg & 0x3F) | (val << 6); + /* Update the cache */ + data->fan_div[attr->index] = reg; + /* Write value */ i2c_smbus_write_byte_data(client, ADM1029_REG_FAN_DIV[attr->index], reg); @@ -231,9 +244,9 @@ static ssize_t set_fan_div(struct device *dev, } /* -Access rights on sysfs, S_IRUGO stand for Is Readable by User, Group and Others - S_IWUSR stand for Is Writable by User -*/ + * Access rights on sysfs. S_IRUGO: Is Readable by User, Group and Others + * S_IWUSR: Is Writable by User. + */ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0); static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1); static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2); @@ -284,110 +297,74 @@ static const struct attribute_group adm1029_group = { * Real code */ -static int adm1029_attach_adapter(struct i2c_adapter *adapter) +/* Return 0 if detection is successful, -ENODEV otherwise */ +static int adm1029_detect(struct i2c_client *client, + struct i2c_board_info *info) { - if (!(adapter->class & I2C_CLASS_HWMON)) - return 0; - return i2c_probe(adapter, &addr_data, adm1029_detect); -} - -/* - * The following function does more than just detection. If detection - * succeeds, it also registers the new chip. - */ + struct i2c_adapter *adapter = client->adapter; + u8 man_id, chip_id, temp_devices_installed, nb_fan_support; -static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) -{ - struct i2c_client *client; - struct adm1029_data *data; - int err = 0; - const char *name = ""; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) - goto exit; + return -ENODEV; - if (!(data = kzalloc(sizeof(struct adm1029_data), GFP_KERNEL))) { - err = -ENOMEM; - goto exit; - } - - client = &data->client; - i2c_set_clientdata(client, data); - client->addr = address; - client->adapter = adapter; - client->driver = &adm1029_driver; - - /* Now we do the detection and identification. A negative kind - * means that the driver was loaded with no force parameter - * (default), so we must both detect and identify the chip - * (actually there is only one possible kind of chip for now, adm1029). - * A zero kind means that the driver was loaded with the force - * parameter, the detection step shall be skipped. A positive kind - * means that the driver was loaded with the force parameter and a - * given kind of chip is requested, so both the detection and the - * identification steps are skipped. */ - - /* Default to an adm1029 if forced */ - if (kind == 0) - kind = adm1029; - - /* ADM1029 doesn't have CHIP ID, check just MAN ID + /* + * ADM1029 doesn't have CHIP ID, check just MAN ID * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED, * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values * documented */ - if (kind <= 0) { /* identification */ - u8 man_id, chip_id, temp_devices_installed, nb_fan_support; - - man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID); - chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID); - temp_devices_installed = i2c_smbus_read_byte_data(client, + man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID); + chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID); + temp_devices_installed = i2c_smbus_read_byte_data(client, ADM1029_REG_TEMP_DEVICES_INSTALLED); - nb_fan_support = i2c_smbus_read_byte_data(client, + nb_fan_support = i2c_smbus_read_byte_data(client, ADM1029_REG_NB_FAN_SUPPORT); - /* 0x41 is Analog Devices */ - if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01 - && nb_fan_support == 0x03) { - if ((chip_id & 0xF0) == 0x00) { - kind = adm1029; - } else { - /* There are no "official" CHIP ID, so actually - * we use Major/Minor revision for that */ - printk(KERN_INFO - "adm1029: Unknown major revision %x, " - "please let us know\n", chip_id); - } - } - - if (kind <= 0) { /* identification failed */ - pr_debug("adm1029: Unsupported chip (man_id=0x%02X, " - "chip_id=0x%02X)\n", man_id, chip_id); - goto exit_free; - } + /* 0x41 is Analog Devices */ + if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01 + || nb_fan_support != 0x03) + return -ENODEV; + + if ((chip_id & 0xF0) != 0x00) { + /* + * There are no "official" CHIP ID, so actually + * we use Major/Minor revision for that + */ + pr_info("Unknown major revision %x, please let us know\n", + chip_id); + return -ENODEV; } - if (kind == adm1029) { - name = "adm1029"; - } + strlcpy(info->type, "adm1029", I2C_NAME_SIZE); - /* We can fill in the remaining client fields */ - strlcpy(client->name, name, I2C_NAME_SIZE); - mutex_init(&data->update_lock); + return 0; +} + +static int adm1029_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct adm1029_data *data; + int err; + + data = devm_kzalloc(&client->dev, sizeof(struct adm1029_data), + GFP_KERNEL); + if (!data) + return -ENOMEM; - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(client))) - goto exit_free; + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); /* * Initialize the ADM1029 chip * Check config register */ if (adm1029_init_client(client) == 0) - goto exit_detach; + return -ENODEV; /* Register sysfs hooks */ - if ((err = sysfs_create_group(&client->dev.kobj, &adm1029_group))) - goto exit_detach; + err = sysfs_create_group(&client->dev.kobj, &adm1029_group); + if (err) + return err; data->hwmon_dev = hwmon_device_register(&client->dev); if (IS_ERR(data->hwmon_dev)) { @@ -399,11 +376,6 @@ static int adm1029_detect(struct i2c_adapter *adapter, int address, int kind) exit_remove_files: sysfs_remove_group(&client->dev.kobj, &adm1029_group); - exit_detach: - i2c_detach_client(client); - exit_free: - kfree(data); - exit: return err; } @@ -424,24 +396,19 @@ static int adm1029_init_client(struct i2c_client *client) return 1; } -static int adm1029_detach_client(struct i2c_client *client) +static int adm1029_remove(struct i2c_client *client) { struct adm1029_data *data = i2c_get_clientdata(client); - int err; hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&client->dev.kobj, &adm1029_group); - if ((err = i2c_detach_client(client))) - return err; - - kfree(data); return 0; } /* -function that update the status of the chips (temperature for exemple) -*/ + * function that update the status of the chips (temperature for example) + */ static struct adm1029_data *adm1029_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); @@ -483,24 +450,8 @@ static struct adm1029_data *adm1029_update_device(struct device *dev) return data; } -/* - Common module stuff -*/ -static int __init sensors_adm1029_init(void) -{ - - return i2c_add_driver(&adm1029_driver); -} - -static void __exit sensors_adm1029_exit(void) -{ - - i2c_del_driver(&adm1029_driver); -} +module_i2c_driver(adm1029_driver); -MODULE_AUTHOR("Corentin LABBE <corentin.labbe@geomatys.fr>"); +MODULE_AUTHOR("Corentin LABBE <clabbe.montjoie@gmail.com>"); MODULE_DESCRIPTION("adm1029 driver"); MODULE_LICENSE("GPL v2"); - -module_init(sensors_adm1029_init); -module_exit(sensors_adm1029_exit); |
