X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fhwmon%2Flm77.c;h=9380fda7dcd129015af886f1360b650f216aad78;hb=787453c2397edcc3261efebb661739acd8c38547;hp=b98f449529976083b38c881f5cc9997050d500a7;hpb=1d492eb41371d9a5145651e8eb64bea1042a4057;p=linux-2.6-omap-h63xx.git diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c index b98f4495299..9380fda7dcd 100644 --- a/drivers/hwmon/lm77.c +++ b/drivers/hwmon/lm77.c @@ -30,15 +30,14 @@ #include #include #include -#include - +#include +#include /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm77); +I2C_CLIENT_INSMOD_1(lm77); /* The LM77 registers */ #define LM77_REG_TEMP 0x00 @@ -51,6 +50,7 @@ SENSORS_INSMOD_1(lm77); /* Each client has this additional data */ struct lm77_data { struct i2c_client client; + struct class_device *class_dev; struct semaphore update_lock; char valid; unsigned long last_updated; /* In jiffies */ @@ -208,10 +208,10 @@ static int lm77_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm77_detect); + return i2c_probe(adapter, &addr_data, lm77_detect); } -/* This function is called by i2c_detect */ +/* This function is called by i2c_probe */ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) { struct i2c_client *new_client; @@ -226,11 +226,10 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) /* OK. For now, we presume we have a valid client. We now create the client structure, even though we cannot fill it completely yet. But it allows us to access lm77_{read,write}_value. */ - if (!(data = kmalloc(sizeof(struct lm77_data), GFP_KERNEL))) { + if (!(data = kzalloc(sizeof(struct lm77_data), GFP_KERNEL))) { err = -ENOMEM; goto exit; } - memset(data, 0, sizeof(struct lm77_data)); new_client = &data->client; i2c_set_clientdata(new_client, data); @@ -317,6 +316,12 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) lm77_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_temp1_input); device_create_file(&new_client->dev, &dev_attr_temp1_crit); device_create_file(&new_client->dev, &dev_attr_temp1_min); @@ -327,6 +332,8 @@ static int lm77_detect(struct i2c_adapter *adapter, int address, int kind) device_create_file(&new_client->dev, &dev_attr_alarms); return 0; +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -335,8 +342,10 @@ exit: static int lm77_detach_client(struct i2c_client *client) { + struct lm77_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->class_dev); i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); + kfree(data); return 0; }