mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 23:51:37 +00:00
hwmon: (amc6821) 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:
parent
28e6274d8f
commit
1276fae2a9
@ -152,7 +152,7 @@ static const u8 fan_reg_hi[] = {AMC6821_REG_TDATA_HI,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct amc6821_data {
|
struct amc6821_data {
|
||||||
struct device *hwmon_dev;
|
struct i2c_client *client;
|
||||||
struct mutex update_lock;
|
struct mutex update_lock;
|
||||||
char valid; /* zero until following fields are valid */
|
char valid; /* zero until following fields are valid */
|
||||||
unsigned long last_updated; /* in jiffies */
|
unsigned long last_updated; /* in jiffies */
|
||||||
@ -176,8 +176,8 @@ struct amc6821_data {
|
|||||||
|
|
||||||
static struct amc6821_data *amc6821_update_device(struct device *dev)
|
static struct amc6821_data *amc6821_update_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int timeout = HZ;
|
int timeout = HZ;
|
||||||
u8 reg;
|
u8 reg;
|
||||||
int i;
|
int i;
|
||||||
@ -294,8 +294,8 @@ static ssize_t set_temp(
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int ix = to_sensor_dev_attr(attr)->index;
|
int ix = to_sensor_dev_attr(attr)->index;
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
@ -379,8 +379,8 @@ static ssize_t set_pwm1(
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
long val;
|
long val;
|
||||||
int ret = kstrtol(buf, 10, &val);
|
int ret = kstrtol(buf, 10, &val);
|
||||||
if (ret)
|
if (ret)
|
||||||
@ -408,8 +408,8 @@ static ssize_t set_pwm1_enable(
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
long val;
|
long val;
|
||||||
int config = kstrtol(buf, 10, &val);
|
int config = kstrtol(buf, 10, &val);
|
||||||
if (config)
|
if (config)
|
||||||
@ -519,8 +519,8 @@ static ssize_t set_temp_auto_point_temp(
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
|
||||||
struct amc6821_data *data = amc6821_update_device(dev);
|
struct amc6821_data *data = amc6821_update_device(dev);
|
||||||
|
struct i2c_client *client = data->client;
|
||||||
int ix = to_sensor_dev_attr_2(attr)->index;
|
int ix = to_sensor_dev_attr_2(attr)->index;
|
||||||
int nr = to_sensor_dev_attr_2(attr)->nr;
|
int nr = to_sensor_dev_attr_2(attr)->nr;
|
||||||
u8 *ptemp;
|
u8 *ptemp;
|
||||||
@ -592,8 +592,8 @@ static ssize_t set_pwm1_auto_point_pwm(
|
|||||||
const char *buf,
|
const char *buf,
|
||||||
size_t count)
|
size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
int dpwm;
|
int dpwm;
|
||||||
long val;
|
long val;
|
||||||
int ret = kstrtol(buf, 10, &val);
|
int ret = kstrtol(buf, 10, &val);
|
||||||
@ -655,8 +655,8 @@ static ssize_t set_fan(
|
|||||||
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 amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
long val;
|
long val;
|
||||||
int ix = to_sensor_dev_attr(attr)->index;
|
int ix = to_sensor_dev_attr(attr)->index;
|
||||||
int ret = kstrtol(buf, 10, &val);
|
int ret = kstrtol(buf, 10, &val);
|
||||||
@ -696,8 +696,8 @@ static ssize_t set_fan1_div(
|
|||||||
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 amc6821_data *data = dev_get_drvdata(dev);
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
long val;
|
long val;
|
||||||
int config = kstrtol(buf, 10, &val);
|
int config = kstrtol(buf, 10, &val);
|
||||||
if (config)
|
if (config)
|
||||||
@ -834,9 +834,7 @@ static struct attribute *amc6821_attrs[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct attribute_group amc6821_attr_grp = {
|
ATTRIBUTE_GROUPS(amc6821);
|
||||||
.attrs = amc6821_attrs,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Return 0 if detection is successful, -ENODEV otherwise */
|
/* Return 0 if detection is successful, -ENODEV otherwise */
|
||||||
static int amc6821_detect(
|
static int amc6821_detect(
|
||||||
@ -973,15 +971,16 @@ static int amc6821_init_client(struct i2c_client *client)
|
|||||||
static int amc6821_probe(struct i2c_client *client,
|
static int amc6821_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
|
struct device *dev = &client->dev;
|
||||||
struct amc6821_data *data;
|
struct amc6821_data *data;
|
||||||
|
struct device *hwmon_dev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
data = devm_kzalloc(&client->dev, sizeof(struct amc6821_data),
|
data = devm_kzalloc(dev, sizeof(struct amc6821_data), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
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);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -991,28 +990,10 @@ static int amc6821_probe(struct i2c_client *client,
|
|||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = sysfs_create_group(&client->dev.kobj, &amc6821_attr_grp);
|
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
|
||||||
if (err)
|
data,
|
||||||
return err;
|
amc6821_groups);
|
||||||
|
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
|
||||||
if (!IS_ERR(data->hwmon_dev))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err = PTR_ERR(data->hwmon_dev);
|
|
||||||
dev_err(&client->dev, "error registering hwmon device.\n");
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int amc6821_remove(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct amc6821_data *data = i2c_get_clientdata(client);
|
|
||||||
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &amc6821_attr_grp);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct i2c_device_id amc6821_id[] = {
|
static const struct i2c_device_id amc6821_id[] = {
|
||||||
@ -1028,7 +1009,6 @@ static struct i2c_driver amc6821_driver = {
|
|||||||
.name = "amc6821",
|
.name = "amc6821",
|
||||||
},
|
},
|
||||||
.probe = amc6821_probe,
|
.probe = amc6821_probe,
|
||||||
.remove = amc6821_remove,
|
|
||||||
.id_table = amc6821_id,
|
.id_table = amc6821_id,
|
||||||
.detect = amc6821_detect,
|
.detect = amc6821_detect,
|
||||||
.address_list = normal_i2c,
|
.address_list = normal_i2c,
|
||||||
|
Loading…
Reference in New Issue
Block a user