diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-30 22:57:38 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:37 -0400 |
commit | e47c39b3a8299e2d84d9e3ca5e591bc5055dd1d8 (patch) | |
tree | 88d8758a986d084eb794d4d2f3b8884a527861be | |
parent | 15ac4ddb3271af9471225ef018eb3907989aaf6a (diff) |
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>
-rw-r--r-- | drivers/hwmon/g760a.c | 53 |
1 files changed, 13 insertions, 40 deletions
diff --git a/drivers/hwmon/g760a.c b/drivers/hwmon/g760a.c index 8460f8062efc..ec6a77da411a 100644 --- a/drivers/hwmon/g760a.c +++ b/drivers/hwmon/g760a.c | |||
@@ -38,7 +38,6 @@ enum g760a_regs { | |||
38 | 38 | ||
39 | struct g760a_data { | 39 | struct g760a_data { |
40 | struct i2c_client *client; | 40 | struct i2c_client *client; |
41 | struct device *hwmon_dev; | ||
42 | struct mutex update_lock; | 41 | struct mutex update_lock; |
43 | 42 | ||
44 | /* board specific parameters */ | 43 | /* board specific parameters */ |
@@ -86,8 +85,8 @@ static int g760a_write_value(struct i2c_client *client, enum g760a_regs reg, | |||
86 | 85 | ||
87 | static struct g760a_data *g760a_update_client(struct device *dev) | 86 | static struct g760a_data *g760a_update_client(struct device *dev) |
88 | { | 87 | { |
89 | struct i2c_client *client = to_i2c_client(dev); | 88 | struct g760a_data *data = dev_get_drvdata(dev); |
90 | struct g760a_data *data = i2c_get_clientdata(client); | 89 | struct i2c_client *client = data->client; |
91 | 90 | ||
92 | mutex_lock(&data->update_lock); | 91 | mutex_lock(&data->update_lock); |
93 | 92 | ||
@@ -143,8 +142,8 @@ static ssize_t get_pwm(struct device *dev, struct device_attribute *da, | |||
143 | static ssize_t set_pwm(struct device *dev, struct device_attribute *da, | 142 | static ssize_t set_pwm(struct device *dev, struct device_attribute *da, |
144 | const char *buf, size_t count) | 143 | const char *buf, size_t count) |
145 | { | 144 | { |
146 | struct i2c_client *client = to_i2c_client(dev); | ||
147 | struct g760a_data *data = g760a_update_client(dev); | 145 | struct g760a_data *data = g760a_update_client(dev); |
146 | struct i2c_client *client = data->client; | ||
148 | unsigned long val; | 147 | unsigned long val; |
149 | 148 | ||
150 | if (kstrtoul(buf, 10, &val)) | 149 | if (kstrtoul(buf, 10, &val)) |
@@ -162,16 +161,14 @@ static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm); | |||
162 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL); | 161 | static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL); |
163 | static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL); | 162 | static DEVICE_ATTR(fan1_alarm, S_IRUGO, show_fan_alarm, NULL); |
164 | 163 | ||
165 | static struct attribute *g760a_attributes[] = { | 164 | static struct attribute *g760a_attrs[] = { |
166 | &dev_attr_pwm1.attr, | 165 | &dev_attr_pwm1.attr, |
167 | &dev_attr_fan1_input.attr, | 166 | &dev_attr_fan1_input.attr, |
168 | &dev_attr_fan1_alarm.attr, | 167 | &dev_attr_fan1_alarm.attr, |
169 | NULL | 168 | NULL |
170 | }; | 169 | }; |
171 | 170 | ||
172 | static const struct attribute_group g760a_group = { | 171 | ATTRIBUTE_GROUPS(g760a); |
173 | .attrs = g760a_attributes, | ||
174 | }; | ||
175 | 172 | ||
176 | /* | 173 | /* |
177 | * new-style driver model code | 174 | * new-style driver model code |
@@ -180,20 +177,17 @@ static const struct attribute_group g760a_group = { | |||
180 | static int g760a_probe(struct i2c_client *client, | 177 | static int g760a_probe(struct i2c_client *client, |
181 | const struct i2c_device_id *id) | 178 | const struct i2c_device_id *id) |
182 | { | 179 | { |
180 | struct device *dev = &client->dev; | ||
183 | struct g760a_data *data; | 181 | struct g760a_data *data; |
184 | int err; | 182 | struct device *hwmon_dev; |
185 | 183 | ||
186 | if (!i2c_check_functionality(client->adapter, | 184 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
187 | I2C_FUNC_SMBUS_BYTE_DATA)) | ||
188 | return -EIO; | 185 | return -EIO; |
189 | 186 | ||
190 | data = devm_kzalloc(&client->dev, sizeof(struct g760a_data), | 187 | data = devm_kzalloc(dev, sizeof(struct g760a_data), GFP_KERNEL); |
191 | GFP_KERNEL); | ||
192 | if (!data) | 188 | if (!data) |
193 | return -ENOMEM; | 189 | return -ENOMEM; |
194 | 190 | ||
195 | i2c_set_clientdata(client, data); | ||
196 | |||
197 | data->client = client; | 191 | data->client = client; |
198 | mutex_init(&data->update_lock); | 192 | mutex_init(&data->update_lock); |
199 | 193 | ||
@@ -201,30 +195,10 @@ static int g760a_probe(struct i2c_client *client, | |||
201 | data->fan_div = G760A_DEFAULT_FAN_DIV; | 195 | data->fan_div = G760A_DEFAULT_FAN_DIV; |
202 | data->clk = G760A_DEFAULT_CLK; | 196 | data->clk = G760A_DEFAULT_CLK; |
203 | 197 | ||
204 | /* Register sysfs hooks */ | 198 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
205 | err = sysfs_create_group(&client->dev.kobj, &g760a_group); | 199 | data, |
206 | if (err) | 200 | g760a_groups); |
207 | return err; | 201 | return PTR_ERR_OR_ZERO(hwmon_dev); |
208 | |||
209 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
210 | if (IS_ERR(data->hwmon_dev)) { | ||
211 | err = PTR_ERR(data->hwmon_dev); | ||
212 | goto error_hwmon_device_register; | ||
213 | } | ||
214 | |||
215 | return 0; | ||
216 | |||
217 | error_hwmon_device_register: | ||
218 | sysfs_remove_group(&client->dev.kobj, &g760a_group); | ||
219 | return err; | ||
220 | } | ||
221 | |||
222 | static int g760a_remove(struct i2c_client *client) | ||
223 | { | ||
224 | struct g760a_data *data = i2c_get_clientdata(client); | ||
225 | hwmon_device_unregister(data->hwmon_dev); | ||
226 | sysfs_remove_group(&client->dev.kobj, &g760a_group); | ||
227 | return 0; | ||
228 | } | 202 | } |
229 | 203 | ||
230 | static const struct i2c_device_id g760a_id[] = { | 204 | static const struct i2c_device_id g760a_id[] = { |
@@ -238,7 +212,6 @@ static struct i2c_driver g760a_driver = { | |||
238 | .name = "g760a", | 212 | .name = "g760a", |
239 | }, | 213 | }, |
240 | .probe = g760a_probe, | 214 | .probe = g760a_probe, |
241 | .remove = g760a_remove, | ||
242 | .id_table = g760a_id, | 215 | .id_table = g760a_id, |
243 | }; | 216 | }; |
244 | 217 | ||