aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-06-17 03:38:23 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:34 -0400
commitf82b2c344994f23c003c967fb833d1a0d7b2527f (patch)
treee356d2765b5e45d1cdb1b96f99d7d53bed7def6b
parent11f7e494fd726c119c6f576b4cf1dc09e9f665b8 (diff)
hwmon: (ads7828) 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/ads7828.c52
1 files changed, 14 insertions, 38 deletions
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index 7092c78f814f..a622d40eec17 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -50,7 +50,7 @@ enum ads7828_chips { ads7828, ads7830 };
50 50
51/* Client specific data */ 51/* Client specific data */
52struct ads7828_data { 52struct ads7828_data {
53 struct device *hwmon_dev; 53 struct i2c_client *client;
54 struct mutex update_lock; /* Mutex protecting updates */ 54 struct mutex update_lock; /* Mutex protecting updates */
55 unsigned long last_updated; /* Last updated time (in jiffies) */ 55 unsigned long last_updated; /* Last updated time (in jiffies) */
56 u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH samples */ 56 u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH samples */
@@ -72,8 +72,8 @@ static inline u8 ads7828_cmd_byte(u8 cmd, int ch)
72/* Update data for the device (all 8 channels) */ 72/* Update data for the device (all 8 channels) */
73static struct ads7828_data *ads7828_update_device(struct device *dev) 73static struct ads7828_data *ads7828_update_device(struct device *dev)
74{ 74{
75 struct i2c_client *client = to_i2c_client(dev); 75 struct ads7828_data *data = dev_get_drvdata(dev);
76 struct ads7828_data *data = i2c_get_clientdata(client); 76 struct i2c_client *client = data->client;
77 77
78 mutex_lock(&data->update_lock); 78 mutex_lock(&data->update_lock);
79 79
@@ -116,7 +116,7 @@ static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, ads7828_show_in, NULL, 5);
116static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, ads7828_show_in, NULL, 6); 116static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, ads7828_show_in, NULL, 6);
117static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, ads7828_show_in, NULL, 7); 117static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, ads7828_show_in, NULL, 7);
118 118
119static struct attribute *ads7828_attributes[] = { 119static struct attribute *ads7828_attrs[] = {
120 &sensor_dev_attr_in0_input.dev_attr.attr, 120 &sensor_dev_attr_in0_input.dev_attr.attr,
121 &sensor_dev_attr_in1_input.dev_attr.attr, 121 &sensor_dev_attr_in1_input.dev_attr.attr,
122 &sensor_dev_attr_in2_input.dev_attr.attr, 122 &sensor_dev_attr_in2_input.dev_attr.attr,
@@ -128,29 +128,17 @@ static struct attribute *ads7828_attributes[] = {
128 NULL 128 NULL
129}; 129};
130 130
131static const struct attribute_group ads7828_group = { 131ATTRIBUTE_GROUPS(ads7828);
132 .attrs = ads7828_attributes,
133};
134
135static int ads7828_remove(struct i2c_client *client)
136{
137 struct ads7828_data *data = i2c_get_clientdata(client);
138
139 hwmon_device_unregister(data->hwmon_dev);
140 sysfs_remove_group(&client->dev.kobj, &ads7828_group);
141
142 return 0;
143}
144 132
145static int ads7828_probe(struct i2c_client *client, 133static int ads7828_probe(struct i2c_client *client,
146 const struct i2c_device_id *id) 134 const struct i2c_device_id *id)
147{ 135{
148 struct ads7828_platform_data *pdata = dev_get_platdata(&client->dev); 136 struct device *dev = &client->dev;
137 struct ads7828_platform_data *pdata = dev_get_platdata(dev);
149 struct ads7828_data *data; 138 struct ads7828_data *data;
150 int err; 139 struct device *hwmon_dev;
151 140
152 data = devm_kzalloc(&client->dev, sizeof(struct ads7828_data), 141 data = devm_kzalloc(dev, sizeof(struct ads7828_data), GFP_KERNEL);
153 GFP_KERNEL);
154 if (!data) 142 if (!data)
155 return -ENOMEM; 143 return -ENOMEM;
156 144
@@ -182,24 +170,13 @@ static int ads7828_probe(struct i2c_client *client,
182 if (!data->diff_input) 170 if (!data->diff_input)
183 data->cmd_byte |= ADS7828_CMD_SD_SE; 171 data->cmd_byte |= ADS7828_CMD_SD_SE;
184 172
185 i2c_set_clientdata(client, data); 173 data->client = client;
186 mutex_init(&data->update_lock); 174 mutex_init(&data->update_lock);
187 175
188 err = sysfs_create_group(&client->dev.kobj, &ads7828_group); 176 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
189 if (err) 177 data,
190 return err; 178 ads7828_groups);
191 179 return PTR_ERR_OR_ZERO(hwmon_dev);
192 data->hwmon_dev = hwmon_device_register(&client->dev);
193 if (IS_ERR(data->hwmon_dev)) {
194 err = PTR_ERR(data->hwmon_dev);
195 goto error;
196 }
197
198 return 0;
199
200error:
201 sysfs_remove_group(&client->dev.kobj, &ads7828_group);
202 return err;
203} 180}
204 181
205static const struct i2c_device_id ads7828_device_ids[] = { 182static const struct i2c_device_id ads7828_device_ids[] = {
@@ -216,7 +193,6 @@ static struct i2c_driver ads7828_driver = {
216 193
217 .id_table = ads7828_device_ids, 194 .id_table = ads7828_device_ids,
218 .probe = ads7828_probe, 195 .probe = ads7828_probe,
219 .remove = ads7828_remove,
220}; 196};
221 197
222module_i2c_driver(ads7828_driver); 198module_i2c_driver(ads7828_driver);