hwmon: (g760a) 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
15ac4ddb32
commit
e47c39b3a8
@ -38,7 +38,6 @@ enum g760a_regs {
|
|||||||
|
|
||||||
struct g760a_data {
|
struct g760a_data {
|
||||||
struct i2c_client *client;
|
struct i2c_client *client;
|
||||||
struct device *hwmon_dev;
|
|
||||||
struct mutex update_lock;
|
struct mutex update_lock;
|
||||||
|
|
||||||
/* board specific parameters */
|
/* board specific parameters */
|
||||||
@ -86,8 +85,8 @@ static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg,
|
|||||||
|
|
||||||
static struct g760a_data *g760a_update_client(struct device *dev)
|
static struct g760a_data *g760a_update_client(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct g760a_data *data = dev_get_drvdata(dev);
|
||||||
struct g760a_data *data = i2c_get_clientdata(client);
|
struct i2c_client *client = data->client;
|
||||||
|
|
||||||
mutex_lock(&data->update_lock);
|
mutex_lock(&data->update_lock);
|
||||||
|
|
||||||
@ -143,8 +142,8 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *da,
|
|||||||
static ssize_t set_pwm(struct device *dev, struct device_attribute *da,
|
static ssize_t set_pwm(struct device *dev, struct device_attribute *da,
|
||||||
const char *buf, size_t count)
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
|
||||||
struct g760a_data *data = g760a_update_client(dev);
|
struct g760a_data *data = g760a_update_client(dev);
|
||||||
|
struct i2c_client *client = data->client;
|
||||||
unsigned long val;
|
unsigned long val;
|
||||||
|
|
||||||
if (kstrtoul(buf, 10, &val))
|
if (kstrtoul(buf, 10, &val))
|
||||||
@ -162,16 +161,14 @@ static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm);
|
|||||||
static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL);
|
static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL);
|
||||||
static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL);
|
static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL);
|
||||||
|
|
||||||
static struct attribute *g760a_attributes[] = {
|
static struct attribute *g760a_attrs[] = {
|
||||||
&dev_attr_pwm1.attr,
|
&dev_attr_pwm1.attr,
|
||||||
&dev_attr_fan1_input.attr,
|
&dev_attr_fan1_input.attr,
|
||||||
&dev_attr_fan1_alarm.attr,
|
&dev_attr_fan1_alarm.attr,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct attribute_group g760a_group = {
|
ATTRIBUTE_GROUPS(g760a);
|
||||||
.attrs = g760a_attributes,
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* new-style driver model code
|
* new-style driver model code
|
||||||
@ -180,20 +177,17 @@ static const struct attribute_group g760a_group = {
|
|||||||
static int g760a_probe(struct i2c_client *client,
|
static int g760a_probe(struct i2c_client *client,
|
||||||
const struct i2c_device_id *id)
|
const struct i2c_device_id *id)
|
||||||
{
|
{
|
||||||
|
struct device *dev = &client->dev;
|
||||||
struct g760a_data *data;
|
struct g760a_data *data;
|
||||||
int err;
|
struct device *hwmon_dev;
|
||||||
|
|
||||||
if (!i2c_check_functionality(client->adapter,
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||||
I2C_FUNC_SMBUS_BYTE_DATA))
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
data = devm_kzalloc(&client->dev, sizeof(struct g760a_data),
|
data = devm_kzalloc(dev, sizeof(struct g760a_data), GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
i2c_set_clientdata(client, data);
|
|
||||||
|
|
||||||
data->client = client;
|
data->client = client;
|
||||||
mutex_init(&data->update_lock);
|
mutex_init(&data->update_lock);
|
||||||
|
|
||||||
@ -201,30 +195,10 @@ static int g760a_probe(struct i2c_client *client,
|
|||||||
data->fan_div = G760A_DEFAULT_FAN_DIV;
|
data->fan_div = G760A_DEFAULT_FAN_DIV;
|
||||||
data->clk = G760A_DEFAULT_CLK;
|
data->clk = G760A_DEFAULT_CLK;
|
||||||
|
|
||||||
/* Register sysfs hooks */
|
hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
|
||||||
err = sysfs_create_group(&client->dev.kobj, &g760a_group);
|
data,
|
||||||
if (err)
|
g760a_groups);
|
||||||
return err;
|
return PTR_ERR_OR_ZERO(hwmon_dev);
|
||||||
|
|
||||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
|
||||||
if (IS_ERR(data->hwmon_dev)) {
|
|
||||||
err = PTR_ERR(data->hwmon_dev);
|
|
||||||
goto error_hwmon_device_register;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
error_hwmon_device_register:
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &g760a_group);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int g760a_remove(struct i2c_client *client)
|
|
||||||
{
|
|
||||||
struct g760a_data *data = i2c_get_clientdata(client);
|
|
||||||
hwmon_device_unregister(data->hwmon_dev);
|
|
||||||
sysfs_remove_group(&client->dev.kobj, &g760a_group);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct i2c_device_id g760a_id[] = {
|
static const struct i2c_device_id g760a_id[] = {
|
||||||
@ -238,7 +212,6 @@ static struct i2c_driver g760a_driver = {
|
|||||||
.name = "g760a",
|
.name = "g760a",
|
||||||
},
|
},
|
||||||
.probe = g760a_probe,
|
.probe = g760a_probe,
|
||||||
.remove = g760a_remove,
|
|
||||||
.id_table = g760a_id,
|
.id_table = g760a_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user