X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fhwmon%2Fadm1031.c;h=7c545d5eee4570f0cbe9c4e175db925db36344bd;hb=f24e09754bcb4d367664ea635c0c4ccde6ec4df5;hp=9362509572709596d92849a666199f4cf1bcb46a;hpb=bebf4688e9dbbfdd421736685d607bced91a3c91;p=linux-2.6-omap-h63xx.git diff --git a/drivers/hwmon/adm1031.c b/drivers/hwmon/adm1031.c index 93625095727..7c545d5eee4 100644 --- a/drivers/hwmon/adm1031.c +++ b/drivers/hwmon/adm1031.c @@ -26,7 +26,8 @@ #include #include #include -#include +#include +#include /* Following macros takes channel parameter starting from 0 to 2 */ #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) @@ -59,16 +60,16 @@ /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(adm1030, adm1031); +I2C_CLIENT_INSMOD_2(adm1030, adm1031); typedef u8 auto_chan_table_t[8][2]; /* Each client has this additional data */ struct adm1031_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; int chip_type; char valid; /* !=0 if following fields are valid */ @@ -725,10 +726,10 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, adm1031_detect); + return i2c_probe(adapter, &addr_data, adm1031_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -739,11 +740,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) goto exit; - if (!(data = kmalloc(sizeof(struct adm1031_data), GFP_KERNEL))) { + if (!(data = kzalloc(sizeof(struct adm1031_data), GFP_KERNEL))) { err = -ENOMEM; goto exit; } - memset(data, 0, sizeof(struct adm1031_data)); new_client = &data->client; i2c_set_clientdata(new_client, data); @@ -788,6 +788,12 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) adm1031_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_fan1_input); device_create_file(&new_client->dev, &dev_attr_fan1_div); device_create_file(&new_client->dev, &dev_attr_fan1_min); @@ -833,6 +839,8 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -841,11 +849,14 @@ exit: static int adm1031_detach_client(struct i2c_client *client) { + struct adm1031_data *data = i2c_get_clientdata(client); int ret; + + hwmon_device_unregister(data->class_dev); if ((ret = i2c_detach_client(client)) != 0) { return ret; } - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; }