hwmon: (adm1031) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to simplify the code a bit. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
+38
-63
@@ -74,7 +74,8 @@ typedef u8 auto_chan_table_t[8][2];
|
|||||||
|
|
||||||
/* Each client has this additional data */
|
/* Each client has this additional data */
|
||||||
struct adm1031_data {
|
struct adm1031_data {
|
||||||
struct device *hwmon_dev;
|
struct i2c_client *client;
|
||||||
|
const struct attribute_group *groups[3];
|
||||||
struct mutex update_lock;
|
struct mutex update_lock;
|
||||||
int chip_type;
|
int chip_type;
|
||||||
char valid; /* !=0 if following fields are valid */
|
char valid; /* !=0 if following fields are valid */
|
||||||
@@ -118,8 +119,8 @@ adm1031_write_value(struct i2c_client *client, u8 reg, unsigned int value)
|
|||||||
|
|
||||||
static struct adm1031_data *adm1031_update_device(struct device *dev)
|
static struct adm1031_data *adm1031_update_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
unsigned long next_update;
|
unsigned long next_update;
|
||||||
int chan;
|
int chan;
|
||||||
|
|
||||||
@@ -342,8 +343,8 @@ static ssize_t
|
|||||||
set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
|
set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
u8 reg;
|
u8 reg;
|
||||||
@@ -417,8 +418,8 @@ static ssize_t
|
|||||||
set_auto_temp_min(struct device *dev, struct device_attribute *attr,
|
set_auto_temp_min(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -447,8 +448,8 @@ static ssize_t
|
|||||||
set_auto_temp_max(struct device *dev, struct device_attribute *attr,
|
set_auto_temp_max(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -490,8 +491,8 @@ static ssize_t show_pwm(struct device *dev,
|
|||||||
static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret, reg;
|
int ret, reg;
|
||||||
@@ -603,8 +604,8 @@ static ssize_t show_fan_min(struct device *dev,
|
|||||||
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -627,8 +628,8 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
|
|||||||
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
u8 tmp;
|
u8 tmp;
|
||||||
@@ -729,8 +730,8 @@ static ssize_t set_temp_offset(struct device *dev,
|
|||||||
struct device_attribute *attr, const char *buf,
|
struct device_attribute *attr, const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -750,8 +751,8 @@ static ssize_t set_temp_offset(struct device *dev,
|
|||||||
static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -771,8 +772,8 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
|
|||||||
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -792,8 +793,8 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
|
|||||||
static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
|
static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int nr = to_sensor_dev_attr(attr)->index;
|
int nr = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -869,8 +870,7 @@ static const unsigned int update_intervals[] = {
|
|||||||
static ssize_t show_update_interval(struct device *dev,
|
static ssize_t show_update_interval(struct device *dev,
|
||||||
struct device_attribute *attr, char *buf)
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
return sprintf(buf, "%u\n", data->update_interval);
|
return sprintf(buf, "%u\n", data->update_interval);
|
||||||
}
|
}
|
||||||
@@ -879,8 +879,8 @@ static ssize_t set_update_interval(struct device *dev,
|
|||||||
struct device_attribute *attr,
|
struct device_attribute *attr,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct adm1031_data *data = dev_get_drvdata(dev);
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
int i, err;
|
int i, err;
|
||||||
u8 reg;
|
u8 reg;
|
||||||
@@ -1046,15 +1046,16 @@ static void adm1031_init_client(struct i2c_client *client)
|
|||||||
static int adm1031_probe(struct i2c_client *client,
|
static int adm1031_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
|
struct device *dev = &client->dev;
|
||||||
|
struct device *hwmon_dev;
|
||||||
struct adm1031_data *data;
|
struct adm1031_data *data;
|
||||||
int err;
|
|
||||||
|
|
||||||
data = devm_kzalloc(&client->dev, sizeof(struct adm1031_data),
|
data = devm_kzalloc(dev, sizeof(struct adm1031_data), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
i2c_set_clientdata(client, data);
|
i2c_set_clientdata(client, data);
|
||||||
|
data->client = client;
|
||||||
data->chip_type = id->driver_data;
|
data->chip_type = id->driver_data;
|
||||||
mutex_init(&data->update_lock);
|
mutex_init(&data->update_lock);
|
||||||
|
|
||||||
@@ -1066,39 +1067,14 @@ static int adm1031_probe(struct i2c_client *client,
|
|||||||
/* Initialize the ADM1031 chip */
|
/* Initialize the ADM1031 chip */
|
||||||
adm1031_init_client(client);
|
adm1031_init_client(client);
|
||||||
|
|
||||||
/* Register sysfs hooks */
|
/* sysfs hooks */
|
||||||
err = sysfs_create_group(&client->dev.kobj, &adm1031_group);
|
data->groups[0] = &adm1031_group;
|
||||||
if (err)
|
if (data->chip_type == adm1031)
|
||||||
return err;
|
data->groups[1] = &adm1031_group_opt;
|
||||||
|
|
||||||
if (data->chip_type == adm1031) {
|
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
|
||||||
err = sysfs_create_group(&client->dev.kobj, &adm1031_group_opt);
|
data, data->groups);
|
||||||
if (err)
|
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||||
goto exit_remove;
|
|
||||||
}
|
|
||||||
|
|
||||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
|
||||||
if (IS_ERR(data->hwmon_dev)) {
|
|
||||||
err = PTR_ERR(data->hwmon_dev);
|
|
||||||
goto exit_remove;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
exit_remove:
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &adm1031_group);
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int adm1031_remove(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct adm1031_data *data = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &adm1031_group);
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct i2c_device_id adm1031_id[] = {
|
static const struct i2c_device_id adm1031_id[] = {
|
||||||
@@ -1114,7 +1090,6 @@ static struct i2c_driver adm1031_driver = {
|
|||||||
.name = "adm1031",
|
.name = "adm1031",
|
||||||
},
|
},
|
||||||
.probe = adm1031_probe,
|
.probe = adm1031_probe,
|
||||||
.remove = adm1031_remove,
|
|
||||||
.id_table = adm1031_id,
|
.id_table = adm1031_id,
|
||||||
.detect = adm1031_detect,
|
.detect = adm1031_detect,
|
||||||
.address_list = normal_i2c,
|
.address_list = normal_i2c,
|
||||||
|
|||||||
Reference in New Issue
Block a user