X-Git-Url: https://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=drivers%2Fhwmon%2Fgl518sm.c;h=9e685e3a3bc97ea911c10853e835f6b8f2de4422;hb=37ef4399a6bb265d3035e6d6e45f7677b132a3ba;hp=6bedf729dcf5c251b27c18676af66fab4b68793f;hpb=f7f24758ac98a506770bc5910d33567610fa3403;p=pandora-kernel.git diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 6bedf729dcf5..9e685e3a3bc9 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c @@ -41,14 +41,14 @@ #include #include #include -#include +#include +#include /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80); +I2C_CLIENT_INSMOD_2(gl518sm_r00, gl518sm_r80); /* Many GL518 constants specified below */ @@ -117,6 +117,7 @@ static inline u8 FAN_TO_REG(long rpm, int div) /* Each client has this additional data */ struct gl518_data { struct i2c_client client; + struct class_device *class_dev; enum chips type; struct semaphore update_lock; @@ -150,10 +151,10 @@ static struct gl518_data *gl518_update_device(struct device *dev); /* This is the driver that will be inserted */ static struct i2c_driver gl518_driver = { - .owner = THIS_MODULE, - .name = "gl518sm", + .driver = { + .name = "gl518sm", + }, .id = I2C_DRIVERID_GL518, - .flags = I2C_DF_NOTIFY, .attach_adapter = gl518_attach_adapter, .detach_client = gl518_detach_client, }; @@ -346,7 +347,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, gl518_detect); + return i2c_probe(adapter, &addr_data, gl518_detect); } static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) @@ -364,11 +365,10 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) client structure, even though we cannot fill it completely yet. But it allows us to access gl518_{read,write}_value. */ - if (!(data = kmalloc(sizeof(struct gl518_data), GFP_KERNEL))) { + if (!(data = kzalloc(sizeof(struct gl518_data), GFP_KERNEL))) { err = -ENOMEM; goto exit; } - memset(data, 0, sizeof(struct gl518_data)); new_client = &data->client; i2c_set_clientdata(new_client, data); @@ -419,6 +419,12 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) gl518_init_client((struct i2c_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); @@ -450,6 +456,8 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind) /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ +exit_detach: + i2c_detach_client(new_client); exit_free: kfree(data); exit: @@ -477,16 +485,15 @@ static void gl518_init_client(struct i2c_client *client) static int gl518_detach_client(struct i2c_client *client) { + struct gl518_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"); - return err; - } + hwmon_device_unregister(data->class_dev); - kfree(i2c_get_clientdata(client)); + if ((err = i2c_detach_client(client))) + return err; + kfree(data); return 0; }