diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-09-01 21:32:52 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2013-10-13 19:16:28 -0400 |
commit | 3710263f136e629af1e4bae8df1c02b7fdec6260 (patch) | |
tree | 1e427533d11a97a09ff95e7cfeeaad0d4b6e1d50 | |
parent | 9bd024e9fd2bb82fdeb2a2bc8a4b687548f1467e (diff) |
hwmon: (lm73) Convert to use devm_hwmon_device_register_with_groups
Also introduce new variable dev pointing to client->dev in the probe
function, and use new macro ATTRIBUTE_GROUPS to declare attribute groups.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm73.c | 70 |
1 files changed, 22 insertions, 48 deletions
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c index 9bde9644b102..9653bb870a47 100644 --- a/drivers/hwmon/lm73.c +++ b/drivers/hwmon/lm73.c | |||
@@ -55,7 +55,7 @@ static const unsigned short lm73_convrates[] = { | |||
55 | }; | 55 | }; |
56 | 56 | ||
57 | struct lm73_data { | 57 | struct lm73_data { |
58 | struct device *hwmon_dev; | 58 | struct i2c_client *client; |
59 | struct mutex lock; | 59 | struct mutex lock; |
60 | u8 ctrl; /* control register value */ | 60 | u8 ctrl; /* control register value */ |
61 | }; | 61 | }; |
@@ -66,7 +66,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
66 | const char *buf, size_t count) | 66 | const char *buf, size_t count) |
67 | { | 67 | { |
68 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 68 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
69 | struct i2c_client *client = to_i2c_client(dev); | 69 | struct lm73_data *data = dev_get_drvdata(dev); |
70 | long temp; | 70 | long temp; |
71 | short value; | 71 | short value; |
72 | s32 err; | 72 | s32 err; |
@@ -77,7 +77,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da, | |||
77 | 77 | ||
78 | /* Write value */ | 78 | /* Write value */ |
79 | value = clamp_val(temp / 250, LM73_TEMP_MIN, LM73_TEMP_MAX) << 5; | 79 | value = clamp_val(temp / 250, LM73_TEMP_MIN, LM73_TEMP_MAX) << 5; |
80 | err = i2c_smbus_write_word_swapped(client, attr->index, value); | 80 | err = i2c_smbus_write_word_swapped(data->client, attr->index, value); |
81 | return (err < 0) ? err : count; | 81 | return (err < 0) ? err : count; |
82 | } | 82 | } |
83 | 83 | ||
@@ -85,10 +85,10 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da, | |||
85 | char *buf) | 85 | char *buf) |
86 | { | 86 | { |
87 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 87 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
88 | struct i2c_client *client = to_i2c_client(dev); | 88 | struct lm73_data *data = dev_get_drvdata(dev); |
89 | int temp; | 89 | int temp; |
90 | 90 | ||
91 | s32 err = i2c_smbus_read_word_swapped(client, attr->index); | 91 | s32 err = i2c_smbus_read_word_swapped(data->client, attr->index); |
92 | if (err < 0) | 92 | if (err < 0) |
93 | return err; | 93 | return err; |
94 | 94 | ||
@@ -101,8 +101,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da, | |||
101 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | 101 | static ssize_t set_convrate(struct device *dev, struct device_attribute *da, |
102 | const char *buf, size_t count) | 102 | const char *buf, size_t count) |
103 | { | 103 | { |
104 | struct i2c_client *client = to_i2c_client(dev); | 104 | struct lm73_data *data = dev_get_drvdata(dev); |
105 | struct lm73_data *data = i2c_get_clientdata(client); | ||
106 | unsigned long convrate; | 105 | unsigned long convrate; |
107 | s32 err; | 106 | s32 err; |
108 | int res = 0; | 107 | int res = 0; |
@@ -124,7 +123,8 @@ static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | |||
124 | mutex_lock(&data->lock); | 123 | mutex_lock(&data->lock); |
125 | data->ctrl &= LM73_CTRL_TO_MASK; | 124 | data->ctrl &= LM73_CTRL_TO_MASK; |
126 | data->ctrl |= res << LM73_CTRL_RES_SHIFT; | 125 | data->ctrl |= res << LM73_CTRL_RES_SHIFT; |
127 | err = i2c_smbus_write_byte_data(client, LM73_REG_CTRL, data->ctrl); | 126 | err = i2c_smbus_write_byte_data(data->client, LM73_REG_CTRL, |
127 | data->ctrl); | ||
128 | mutex_unlock(&data->lock); | 128 | mutex_unlock(&data->lock); |
129 | 129 | ||
130 | if (err < 0) | 130 | if (err < 0) |
@@ -136,8 +136,7 @@ static ssize_t set_convrate(struct device *dev, struct device_attribute *da, | |||
136 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, | 136 | static ssize_t show_convrate(struct device *dev, struct device_attribute *da, |
137 | char *buf) | 137 | char *buf) |
138 | { | 138 | { |
139 | struct i2c_client *client = to_i2c_client(dev); | 139 | struct lm73_data *data = dev_get_drvdata(dev); |
140 | struct lm73_data *data = i2c_get_clientdata(client); | ||
141 | int res; | 140 | int res; |
142 | 141 | ||
143 | res = (data->ctrl & LM73_CTRL_RES_MASK) >> LM73_CTRL_RES_SHIFT; | 142 | res = (data->ctrl & LM73_CTRL_RES_MASK) >> LM73_CTRL_RES_SHIFT; |
@@ -147,13 +146,12 @@ static ssize_t show_convrate(struct device *dev, struct device_attribute *da, | |||
147 | static ssize_t show_maxmin_alarm(struct device *dev, | 146 | static ssize_t show_maxmin_alarm(struct device *dev, |
148 | struct device_attribute *da, char *buf) | 147 | struct device_attribute *da, char *buf) |
149 | { | 148 | { |
150 | struct i2c_client *client = to_i2c_client(dev); | ||
151 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 149 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
152 | struct lm73_data *data = i2c_get_clientdata(client); | 150 | struct lm73_data *data = dev_get_drvdata(dev); |
153 | s32 ctrl; | 151 | s32 ctrl; |
154 | 152 | ||
155 | mutex_lock(&data->lock); | 153 | mutex_lock(&data->lock); |
156 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); | 154 | ctrl = i2c_smbus_read_byte_data(data->client, LM73_REG_CTRL); |
157 | if (ctrl < 0) | 155 | if (ctrl < 0) |
158 | goto abort; | 156 | goto abort; |
159 | data->ctrl = ctrl; | 157 | data->ctrl = ctrl; |
@@ -183,7 +181,7 @@ static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, | |||
183 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, | 181 | static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, |
184 | show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); | 182 | show_maxmin_alarm, NULL, LM73_CTRL_LO_SHIFT); |
185 | 183 | ||
186 | static struct attribute *lm73_attributes[] = { | 184 | static struct attribute *lm73_attrs[] = { |
187 | &sensor_dev_attr_temp1_input.dev_attr.attr, | 185 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
188 | &sensor_dev_attr_temp1_max.dev_attr.attr, | 186 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
189 | &sensor_dev_attr_temp1_min.dev_attr.attr, | 187 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
@@ -192,10 +190,7 @@ static struct attribute *lm73_attributes[] = { | |||
192 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, | 190 | &sensor_dev_attr_temp1_min_alarm.dev_attr.attr, |
193 | NULL | 191 | NULL |
194 | }; | 192 | }; |
195 | 193 | ATTRIBUTE_GROUPS(lm73); | |
196 | static const struct attribute_group lm73_group = { | ||
197 | .attrs = lm73_attributes, | ||
198 | }; | ||
199 | 194 | ||
200 | /*-----------------------------------------------------------------------*/ | 195 | /*-----------------------------------------------------------------------*/ |
201 | 196 | ||
@@ -204,16 +199,16 @@ static const struct attribute_group lm73_group = { | |||
204 | static int | 199 | static int |
205 | lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) | 200 | lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) |
206 | { | 201 | { |
207 | int status; | 202 | struct device *dev = &client->dev; |
203 | struct device *hwmon_dev; | ||
208 | struct lm73_data *data; | 204 | struct lm73_data *data; |
209 | int ctrl; | 205 | int ctrl; |
210 | 206 | ||
211 | data = devm_kzalloc(&client->dev, sizeof(struct lm73_data), | 207 | data = devm_kzalloc(dev, sizeof(struct lm73_data), GFP_KERNEL); |
212 | GFP_KERNEL); | ||
213 | if (!data) | 208 | if (!data) |
214 | return -ENOMEM; | 209 | return -ENOMEM; |
215 | 210 | ||
216 | i2c_set_clientdata(client, data); | 211 | data->client = client; |
217 | mutex_init(&data->lock); | 212 | mutex_init(&data->lock); |
218 | 213 | ||
219 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); | 214 | ctrl = i2c_smbus_read_byte_data(client, LM73_REG_CTRL); |
@@ -221,33 +216,13 @@ lm73_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
221 | return ctrl; | 216 | return ctrl; |
222 | data->ctrl = ctrl; | 217 | data->ctrl = ctrl; |
223 | 218 | ||
224 | /* Register sysfs hooks */ | 219 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
225 | status = sysfs_create_group(&client->dev.kobj, &lm73_group); | 220 | data, lm73_groups); |
226 | if (status) | 221 | if (IS_ERR(hwmon_dev)) |
227 | return status; | 222 | return PTR_ERR(hwmon_dev); |
228 | |||
229 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
230 | if (IS_ERR(data->hwmon_dev)) { | ||
231 | status = PTR_ERR(data->hwmon_dev); | ||
232 | goto exit_remove; | ||
233 | } | ||
234 | 223 | ||
235 | dev_info(&client->dev, "%s: sensor '%s'\n", | 224 | dev_info(dev, "sensor '%s'\n", client->name); |
236 | dev_name(data->hwmon_dev), client->name); | ||
237 | |||
238 | return 0; | ||
239 | |||
240 | exit_remove: | ||
241 | sysfs_remove_group(&client->dev.kobj, &lm73_group); | ||
242 | return status; | ||
243 | } | ||
244 | |||
245 | static int lm73_remove(struct i2c_client *client) | ||
246 | { | ||
247 | struct lm73_data *data = i2c_get_clientdata(client); | ||
248 | 225 | ||
249 | hwmon_device_unregister(data->hwmon_dev); | ||
250 | sysfs_remove_group(&client->dev.kobj, &lm73_group); | ||
251 | return 0; | 226 | return 0; |
252 | } | 227 | } |
253 | 228 | ||
@@ -300,7 +275,6 @@ static struct i2c_driver lm73_driver = { | |||
300 | .name = "lm73", | 275 | .name = "lm73", |
301 | }, | 276 | }, |
302 | .probe = lm73_probe, | 277 | .probe = lm73_probe, |
303 | .remove = lm73_remove, | ||
304 | .id_table = lm73_ids, | 278 | .id_table = lm73_ids, |
305 | .detect = lm73_detect, | 279 | .detect = lm73_detect, |
306 | .address_list = normal_i2c, | 280 | .address_list = normal_i2c, |