hwmon: (ltc4245) Convert to use hwmon_device_register_with_groups

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
Guenter Roeck 2013-07-06 09:46:38 -07:00
parent 7258a12536
commit 9a85d53cfc

View file

@ -51,7 +51,9 @@ enum ltc4245_cmd {
}; };
struct ltc4245_data { struct ltc4245_data {
struct device *hwmon_dev; struct i2c_client *client;
const struct attribute_group *groups[3];
struct mutex update_lock; struct mutex update_lock;
bool valid; bool valid;
@ -77,8 +79,8 @@ struct ltc4245_data {
*/ */
static void ltc4245_update_gpios(struct device *dev) static void ltc4245_update_gpios(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct ltc4245_data *data = dev_get_drvdata(dev);
struct ltc4245_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
u8 gpio_curr, gpio_next, gpio_reg; u8 gpio_curr, gpio_next, gpio_reg;
int i; int i;
@ -130,8 +132,8 @@ static void ltc4245_update_gpios(struct device *dev)
static struct ltc4245_data *ltc4245_update_device(struct device *dev) static struct ltc4245_data *ltc4245_update_device(struct device *dev)
{ {
struct i2c_client *client = to_i2c_client(dev); struct ltc4245_data *data = dev_get_drvdata(dev);
struct ltc4245_data *data = i2c_get_clientdata(client); struct i2c_client *client = data->client;
s32 val; s32 val;
int i; int i;
@ -455,41 +457,14 @@ static const struct attribute_group ltc4245_gpio_group = {
.attrs = ltc4245_gpio_attributes, .attrs = ltc4245_gpio_attributes,
}; };
static int ltc4245_sysfs_create_groups(struct i2c_client *client) static void ltc4245_sysfs_add_groups(struct ltc4245_data *data)
{ {
struct ltc4245_data *data = i2c_get_clientdata(client); /* standard sysfs attributes */
struct device *dev = &client->dev; data->groups[0] = &ltc4245_std_group;
int ret;
/* register the standard sysfs attributes */
ret = sysfs_create_group(&dev->kobj, &ltc4245_std_group);
if (ret) {
dev_err(dev, "unable to register standard attributes\n");
return ret;
}
/* if we're using the extra gpio support, register it's attributes */ /* if we're using the extra gpio support, register it's attributes */
if (data->use_extra_gpios) {
ret = sysfs_create_group(&dev->kobj, &ltc4245_gpio_group);
if (ret) {
dev_err(dev, "unable to register gpio attributes\n");
sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
return ret;
}
}
return 0;
}
static void ltc4245_sysfs_remove_groups(struct i2c_client *client)
{
struct ltc4245_data *data = i2c_get_clientdata(client);
struct device *dev = &client->dev;
if (data->use_extra_gpios) if (data->use_extra_gpios)
sysfs_remove_group(&dev->kobj, &ltc4245_gpio_group); data->groups[1] = &ltc4245_gpio_group;
sysfs_remove_group(&dev->kobj, &ltc4245_std_group);
} }
static bool ltc4245_use_extra_gpios(struct i2c_client *client) static bool ltc4245_use_extra_gpios(struct i2c_client *client)
@ -517,7 +492,7 @@ static int ltc4245_probe(struct i2c_client *client,
{ {
struct i2c_adapter *adapter = client->adapter; struct i2c_adapter *adapter = client->adapter;
struct ltc4245_data *data; struct ltc4245_data *data;
int ret; struct device *hwmon_dev;
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
return -ENODEV; return -ENODEV;
@ -526,7 +501,7 @@ static int ltc4245_probe(struct i2c_client *client,
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
i2c_set_clientdata(client, data); data->client = client;
mutex_init(&data->update_lock); mutex_init(&data->update_lock);
data->use_extra_gpios = ltc4245_use_extra_gpios(client); data->use_extra_gpios = ltc4245_use_extra_gpios(client);
@ -534,30 +509,25 @@ static int ltc4245_probe(struct i2c_client *client,
i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00); i2c_smbus_write_byte_data(client, LTC4245_FAULT1, 0x00);
i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00); i2c_smbus_write_byte_data(client, LTC4245_FAULT2, 0x00);
/* Register sysfs hooks */ /* Add sysfs hooks */
ret = ltc4245_sysfs_create_groups(client); ltc4245_sysfs_add_groups(data);
if (ret)
return ret;
data->hwmon_dev = hwmon_device_register(&client->dev); hwmon_dev = hwmon_device_register_with_groups(&client->dev,
if (IS_ERR(data->hwmon_dev)) { client->name, data,
ret = PTR_ERR(data->hwmon_dev); data->groups);
goto out_hwmon_device_register; if (IS_ERR(hwmon_dev))
} return PTR_ERR(hwmon_dev);
i2c_set_clientdata(client, hwmon_dev);
return 0; return 0;
out_hwmon_device_register:
ltc4245_sysfs_remove_groups(client);
return ret;
} }
static int ltc4245_remove(struct i2c_client *client) static int ltc4245_remove(struct i2c_client *client)
{ {
struct ltc4245_data *data = i2c_get_clientdata(client); struct device *hwmon_dev = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(hwmon_dev);
ltc4245_sysfs_remove_groups(client);
return 0; return 0;
} }