Skip to content

Commit

Permalink
hwmon: (ltc4215) Convert to devm_hwmon_device_register_with_groups
Browse files Browse the repository at this point in the history
Simplify code, reduce code size, and attach sysfs attributes to hwmon device.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Jean Delvare <jdelvare@suse.de>
  • Loading branch information
groeck committed Mar 3, 2014
1 parent d72d19c commit 6c588b4
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions drivers/hwmon/ltc4215.c
Expand Up @@ -33,7 +33,7 @@ enum ltc4215_cmd {
};

struct ltc4215_data {
struct device *hwmon_dev;
struct i2c_client *client;

struct mutex update_lock;
bool valid;
Expand All @@ -45,8 +45,8 @@ struct ltc4215_data {

static struct ltc4215_data *ltc4215_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct ltc4215_data *data = i2c_get_clientdata(client);
struct ltc4215_data *data = dev_get_drvdata(dev);
struct i2c_client *client = data->client;
s32 val;
int i;

Expand Down Expand Up @@ -214,7 +214,7 @@ static SENSOR_DEVICE_ATTR(in2_min_alarm, S_IRUGO, ltc4215_show_alarm, NULL,
* Finally, construct an array of pointers to members of the above objects,
* as required for sysfs_create_group()
*/
static struct attribute *ltc4215_attributes[] = {
static struct attribute *ltc4215_attrs[] = {
&sensor_dev_attr_curr1_input.dev_attr.attr,
&sensor_dev_attr_curr1_max_alarm.dev_attr.attr,

Expand All @@ -229,57 +229,33 @@ static struct attribute *ltc4215_attributes[] = {

NULL,
};

static const struct attribute_group ltc4215_group = {
.attrs = ltc4215_attributes,
};
ATTRIBUTE_GROUPS(ltc4215);

static int ltc4215_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
struct ltc4215_data *data;
int ret;
struct device *hwmon_dev;

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV;

data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

i2c_set_clientdata(client, data);
data->client = client;
mutex_init(&data->update_lock);

/* Initialize the LTC4215 chip */
i2c_smbus_write_byte_data(client, LTC4215_FAULT, 0x00);

/* Register sysfs hooks */
ret = sysfs_create_group(&client->dev.kobj, &ltc4215_group);
if (ret)
return ret;

data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
ret = PTR_ERR(data->hwmon_dev);
goto out_hwmon_device_register;
}

return 0;

out_hwmon_device_register:
sysfs_remove_group(&client->dev.kobj, &ltc4215_group);
return ret;
}

static int ltc4215_remove(struct i2c_client *client)
{
struct ltc4215_data *data = i2c_get_clientdata(client);

hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &ltc4215_group);

return 0;
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
data,
ltc4215_groups);
return PTR_ERR_OR_ZERO(hwmon_dev);
}

static const struct i2c_device_id ltc4215_id[] = {
Expand All @@ -294,7 +270,6 @@ static struct i2c_driver ltc4215_driver = {
.name = "ltc4215",
},
.probe = ltc4215_probe,
.remove = ltc4215_remove,
.id_table = ltc4215_id,
};

Expand Down

0 comments on commit 6c588b4

Please sign in to comment.