aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/ad7414.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-01 10:31:44 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:35 -0400
commit045c1391ec3b703ee00643fe9bda7cd65cd463e1 (patch)
tree368e859dca293a637df0d9d6cc603b51a4c52875 /drivers/hwmon/ad7414.c
parented67f0872be1aa516831332c732752022d4edc7c (diff)
hwmon: (ad7414) 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>
Diffstat (limited to 'drivers/hwmon/ad7414.c')
-rw-r--r--drivers/hwmon/ad7414.c57
1 files changed, 16 insertions, 41 deletions
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index 5d501adc3e54..763490acc0df 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -39,7 +39,7 @@
39static u8 AD7414_REG_LIMIT[] = { AD7414_REG_T_HIGH, AD7414_REG_T_LOW }; 39static u8 AD7414_REG_LIMIT[] = { AD7414_REG_T_HIGH, AD7414_REG_T_LOW };
40 40
41struct ad7414_data { 41struct ad7414_data {
42 struct device *hwmon_dev; 42 struct i2c_client *client;
43 struct mutex lock; /* atomic read data updates */ 43 struct mutex lock; /* atomic read data updates */
44 char valid; /* !=0 if following fields are valid */ 44 char valid; /* !=0 if following fields are valid */
45 unsigned long next_update; /* In jiffies */ 45 unsigned long next_update; /* In jiffies */
@@ -72,8 +72,8 @@ static inline int ad7414_write(struct i2c_client *client, u8 reg, u8 value)
72 72
73static struct ad7414_data *ad7414_update_device(struct device *dev) 73static struct ad7414_data *ad7414_update_device(struct device *dev)
74{ 74{
75 struct i2c_client *client = to_i2c_client(dev); 75 struct ad7414_data *data = dev_get_drvdata(dev);
76 struct ad7414_data *data = i2c_get_clientdata(client); 76 struct i2c_client *client = data->client;
77 77
78 mutex_lock(&data->lock); 78 mutex_lock(&data->lock);
79 79
@@ -127,8 +127,8 @@ static ssize_t set_max_min(struct device *dev,
127 struct device_attribute *attr, 127 struct device_attribute *attr,
128 const char *buf, size_t count) 128 const char *buf, size_t count)
129{ 129{
130 struct i2c_client *client = to_i2c_client(dev); 130 struct ad7414_data *data = dev_get_drvdata(dev);
131 struct ad7414_data *data = i2c_get_clientdata(client); 131 struct i2c_client *client = data->client;
132 int index = to_sensor_dev_attr(attr)->index; 132 int index = to_sensor_dev_attr(attr)->index;
133 u8 reg = AD7414_REG_LIMIT[index]; 133 u8 reg = AD7414_REG_LIMIT[index];
134 long temp; 134 long temp;
@@ -164,7 +164,7 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
164static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 3); 164static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 3);
165static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 4); 165static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 4);
166 166
167static struct attribute *ad7414_attributes[] = { 167static struct attribute *ad7414_attrs[] = {
168 &sensor_dev_attr_temp1_input.dev_attr.attr, 168 &sensor_dev_attr_temp1_input.dev_attr.attr,
169 &sensor_dev_attr_temp1_max.dev_attr.attr, 169 &sensor_dev_attr_temp1_max.dev_attr.attr,
170 &sensor_dev_attr_temp1_min.dev_attr.attr, 170 &sensor_dev_attr_temp1_min.dev_attr.attr,
@@ -173,27 +173,25 @@ static struct attribute *ad7414_attributes[] = {
173 NULL 173 NULL
174}; 174};
175 175
176static const struct attribute_group ad7414_group = { 176ATTRIBUTE_GROUPS(ad7414);
177 .attrs = ad7414_attributes,
178};
179 177
180static int ad7414_probe(struct i2c_client *client, 178static int ad7414_probe(struct i2c_client *client,
181 const struct i2c_device_id *dev_id) 179 const struct i2c_device_id *dev_id)
182{ 180{
181 struct device *dev = &client->dev;
183 struct ad7414_data *data; 182 struct ad7414_data *data;
183 struct device *hwmon_dev;
184 int conf; 184 int conf;
185 int err;
186 185
187 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA | 186 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA |
188 I2C_FUNC_SMBUS_READ_WORD_DATA)) 187 I2C_FUNC_SMBUS_READ_WORD_DATA))
189 return -EOPNOTSUPP; 188 return -EOPNOTSUPP;
190 189
191 data = devm_kzalloc(&client->dev, sizeof(struct ad7414_data), 190 data = devm_kzalloc(dev, sizeof(struct ad7414_data), GFP_KERNEL);
192 GFP_KERNEL);
193 if (!data) 191 if (!data)
194 return -ENOMEM; 192 return -ENOMEM;
195 193
196 i2c_set_clientdata(client, data); 194 data->client = client;
197 mutex_init(&data->lock); 195 mutex_init(&data->lock);
198 196
199 dev_info(&client->dev, "chip found\n"); 197 dev_info(&client->dev, "chip found\n");
@@ -201,38 +199,16 @@ static int ad7414_probe(struct i2c_client *client,
201 /* Make sure the chip is powered up. */ 199 /* Make sure the chip is powered up. */
202 conf = i2c_smbus_read_byte_data(client, AD7414_REG_CONF); 200 conf = i2c_smbus_read_byte_data(client, AD7414_REG_CONF);
203 if (conf < 0) 201 if (conf < 0)
204 dev_warn(&client->dev, 202 dev_warn(dev, "ad7414_probe unable to read config register.\n");
205 "ad7414_probe unable to read config register.\n");
206 else { 203 else {
207 conf &= ~(1 << 7); 204 conf &= ~(1 << 7);
208 i2c_smbus_write_byte_data(client, AD7414_REG_CONF, conf); 205 i2c_smbus_write_byte_data(client, AD7414_REG_CONF, conf);
209 } 206 }
210 207
211 /* Register sysfs hooks */ 208 hwmon_dev = devm_hwmon_device_register_with_groups(dev,
212 err = sysfs_create_group(&client->dev.kobj, &ad7414_group); 209 client->name,
213 if (err) 210 data, ad7414_groups);
214 return err; 211 return PTR_ERR_OR_ZERO(hwmon_dev);
215
216 data->hwmon_dev = hwmon_device_register(&client->dev);
217 if (IS_ERR(data->hwmon_dev)) {
218 err = PTR_ERR(data->hwmon_dev);
219 goto exit_remove;
220 }
221
222 return 0;
223
224exit_remove:
225 sysfs_remove_group(&client->dev.kobj, &ad7414_group);
226 return err;
227}
228
229static int ad7414_remove(struct i2c_client *client)
230{
231 struct ad7414_data *data = i2c_get_clientdata(client);
232
233 hwmon_device_unregister(data->hwmon_dev);
234 sysfs_remove_group(&client->dev.kobj, &ad7414_group);
235 return 0;
236} 212}
237 213
238static const struct i2c_device_id ad7414_id[] = { 214static const struct i2c_device_id ad7414_id[] = {
@@ -246,7 +222,6 @@ static struct i2c_driver ad7414_driver = {
246 .name = "ad7414", 222 .name = "ad7414",
247 }, 223 },
248 .probe = ad7414_probe, 224 .probe = ad7414_probe,
249 .remove = ad7414_remove,
250 .id_table = ad7414_id, 225 .id_table = ad7414_id,
251}; 226};
252 227