Commit 797eaa4b authored by Jean Delvare's avatar Jean Delvare

hwmon: (lm95241) Convert to new-style i2c driver

The legacy i2c binding model is going away really soon now, so convert
the lm95241 driver to the new binding model or it will break.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Davide Rizzo <elpa.rizzo@gmail.com>
parent d508afb4
...@@ -87,25 +87,11 @@ I2C_CLIENT_INSMOD_1(lm95241); ...@@ -87,25 +87,11 @@ I2C_CLIENT_INSMOD_1(lm95241);
(val_h)) * 1000 + (val_l) * 1000 / 256) (val_h)) * 1000 + (val_l) * 1000 / 256)
/* Functions declaration */ /* Functions declaration */
static int lm95241_attach_adapter(struct i2c_adapter *adapter);
static int lm95241_detect(struct i2c_adapter *adapter, int address,
int kind);
static void lm95241_init_client(struct i2c_client *client); static void lm95241_init_client(struct i2c_client *client);
static int lm95241_detach_client(struct i2c_client *client);
static struct lm95241_data *lm95241_update_device(struct device *dev); static struct lm95241_data *lm95241_update_device(struct device *dev);
/* Driver data (common to all clients) */
static struct i2c_driver lm95241_driver = {
.driver = {
.name = "lm95241",
},
.attach_adapter = lm95241_attach_adapter,
.detach_client = lm95241_detach_client,
};
/* Client data (each client gets its own) */ /* Client data (each client gets its own) */
struct lm95241_data { struct lm95241_data {
struct i2c_client client;
struct device *hwmon_dev; struct device *hwmon_dev;
struct mutex update_lock; struct mutex update_lock;
unsigned long last_updated, rate; /* in jiffies */ unsigned long last_updated, rate; /* in jiffies */
...@@ -323,42 +309,16 @@ static const struct attribute_group lm95241_group = { ...@@ -323,42 +309,16 @@ static const struct attribute_group lm95241_group = {
.attrs = lm95241_attributes, .attrs = lm95241_attributes,
}; };
/* Init/exit code */ /* Return 0 if detection is successful, -ENODEV otherwise */
static int lm95241_attach_adapter(struct i2c_adapter *adapter) static int lm95241_detect(struct i2c_client *new_client, int kind,
struct i2c_board_info *info)
{ {
if (!(adapter->class & I2C_CLASS_HWMON)) struct i2c_adapter *adapter = new_client->adapter;
return 0; int address = new_client->addr;
return i2c_probe(adapter, &addr_data, lm95241_detect);
}
/*
* The following function does more than just detection. If detection
* succeeds, it also registers the new chip.
*/
static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind)
{
struct i2c_client *new_client;
struct lm95241_data *data;
int err = 0;
const char *name = ""; const char *name = "";
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
goto exit; return -ENODEV;
data = kzalloc(sizeof(struct lm95241_data), GFP_KERNEL);
if (!data) {
err = -ENOMEM;
goto exit;
}
/* The common I2C client data is placed right before the
LM95241-specific data. */
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &lm95241_driver;
new_client->flags = 0;
/* /*
* Now we do the remaining detection. A negative kind means that * Now we do the remaining detection. A negative kind means that
...@@ -378,7 +338,7 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -378,7 +338,7 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind)
dev_dbg(&adapter->dev, dev_dbg(&adapter->dev,
"LM95241 detection failed at 0x%02x.\n", "LM95241 detection failed at 0x%02x.\n",
address); address);
goto exit_free; return -ENODEV;
} }
} }
...@@ -392,23 +352,32 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -392,23 +352,32 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind)
if (kind <= 0) { /* identification failed */ if (kind <= 0) { /* identification failed */
dev_info(&adapter->dev, "Unsupported chip\n"); dev_info(&adapter->dev, "Unsupported chip\n");
goto exit_free; return -ENODEV;
} }
} }
} }
/* Fill the i2c board info */
if (kind == lm95241) if (kind == lm95241)
name = "lm95241"; name = "lm95241";
strlcpy(info->type, name, I2C_NAME_SIZE);
return 0;
}
/* We can fill in the remaining client fields */ static int lm95241_probe(struct i2c_client *new_client,
strlcpy(new_client->name, name, I2C_NAME_SIZE); const struct i2c_device_id *id)
data->valid = 0; {
mutex_init(&data->update_lock); struct lm95241_data *data;
int err;
/* Tell the I2C layer a new client has arrived */ data = kzalloc(sizeof(struct lm95241_data), GFP_KERNEL);
err = i2c_attach_client(new_client); if (!data) {
if (err) err = -ENOMEM;
goto exit_free; goto exit;
}
i2c_set_clientdata(new_client, data);
mutex_init(&data->update_lock);
/* Initialize the LM95241 chip */ /* Initialize the LM95241 chip */
lm95241_init_client(new_client); lm95241_init_client(new_client);
...@@ -416,7 +385,7 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -416,7 +385,7 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind)
/* Register sysfs hooks */ /* Register sysfs hooks */
err = sysfs_create_group(&new_client->dev.kobj, &lm95241_group); err = sysfs_create_group(&new_client->dev.kobj, &lm95241_group);
if (err) if (err)
goto exit_detach; goto exit_free;
data->hwmon_dev = hwmon_device_register(&new_client->dev); data->hwmon_dev = hwmon_device_register(&new_client->dev);
if (IS_ERR(data->hwmon_dev)) { if (IS_ERR(data->hwmon_dev)) {
...@@ -428,8 +397,6 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -428,8 +397,6 @@ static int lm95241_detect(struct i2c_adapter *adapter, int address, int kind)
exit_remove_files: exit_remove_files:
sysfs_remove_group(&new_client->dev.kobj, &lm95241_group); sysfs_remove_group(&new_client->dev.kobj, &lm95241_group);
exit_detach:
i2c_detach_client(new_client);
exit_free: exit_free:
kfree(data); kfree(data);
exit: exit:
...@@ -456,18 +423,14 @@ static void lm95241_init_client(struct i2c_client *client) ...@@ -456,18 +423,14 @@ static void lm95241_init_client(struct i2c_client *client)
data->model); data->model);
} }
static int lm95241_detach_client(struct i2c_client *client) static int lm95241_remove(struct i2c_client *client)
{ {
struct lm95241_data *data = i2c_get_clientdata(client); struct lm95241_data *data = i2c_get_clientdata(client);
int err;
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &lm95241_group); sysfs_remove_group(&client->dev.kobj, &lm95241_group);
err = i2c_detach_client(client); i2c_set_clientdata(client, NULL);
if (err)
return err;
kfree(data); kfree(data);
return 0; return 0;
} }
...@@ -509,6 +472,25 @@ static struct lm95241_data *lm95241_update_device(struct device *dev) ...@@ -509,6 +472,25 @@ static struct lm95241_data *lm95241_update_device(struct device *dev)
return data; return data;
} }
/* Driver data (common to all clients) */
static const struct i2c_device_id lm95241_id[] = {
{ "lm95241", lm95241 },
{ }
};
MODULE_DEVICE_TABLE(i2c, lm95241_id);
static struct i2c_driver lm95241_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "lm95241",
},
.probe = lm95241_probe,
.remove = lm95241_remove,
.id_table = lm95241_id,
.detect = lm95241_detect,
.address_data = &addr_data,
};
static int __init sensors_lm95241_init(void) static int __init sensors_lm95241_init(void)
{ {
return i2c_add_driver(&lm95241_driver); return i2c_add_driver(&lm95241_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment