diff options
Diffstat (limited to 'drivers/hwmon/ltc4261.c')
-rw-r--r-- | drivers/hwmon/ltc4261.c | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/drivers/hwmon/ltc4261.c b/drivers/hwmon/ltc4261.c index 487da58ec86c..0becd69842bb 100644 --- a/drivers/hwmon/ltc4261.c +++ b/drivers/hwmon/ltc4261.c | |||
@@ -55,7 +55,7 @@ | |||
55 | #define FAULT_OC (1<<2) | 55 | #define FAULT_OC (1<<2) |
56 | 56 | ||
57 | struct ltc4261_data { | 57 | struct ltc4261_data { |
58 | struct device *hwmon_dev; | 58 | struct i2c_client *client; |
59 | 59 | ||
60 | struct mutex update_lock; | 60 | struct mutex update_lock; |
61 | bool valid; | 61 | bool valid; |
@@ -67,8 +67,8 @@ struct ltc4261_data { | |||
67 | 67 | ||
68 | static struct ltc4261_data *ltc4261_update_device(struct device *dev) | 68 | static struct ltc4261_data *ltc4261_update_device(struct device *dev) |
69 | { | 69 | { |
70 | struct i2c_client *client = to_i2c_client(dev); | 70 | struct ltc4261_data *data = dev_get_drvdata(dev); |
71 | struct ltc4261_data *data = i2c_get_clientdata(client); | 71 | struct i2c_client *client = data->client; |
72 | struct ltc4261_data *ret = data; | 72 | struct ltc4261_data *ret = data; |
73 | 73 | ||
74 | mutex_lock(&data->update_lock); | 74 | mutex_lock(&data->update_lock); |
@@ -150,7 +150,6 @@ static ssize_t ltc4261_show_bool(struct device *dev, | |||
150 | struct device_attribute *da, char *buf) | 150 | struct device_attribute *da, char *buf) |
151 | { | 151 | { |
152 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); | 152 | struct sensor_device_attribute *attr = to_sensor_dev_attr(da); |
153 | struct i2c_client *client = to_i2c_client(dev); | ||
154 | struct ltc4261_data *data = ltc4261_update_device(dev); | 153 | struct ltc4261_data *data = ltc4261_update_device(dev); |
155 | u8 fault; | 154 | u8 fault; |
156 | 155 | ||
@@ -159,7 +158,7 @@ static ssize_t ltc4261_show_bool(struct device *dev, | |||
159 | 158 | ||
160 | fault = data->regs[LTC4261_FAULT] & attr->index; | 159 | fault = data->regs[LTC4261_FAULT] & attr->index; |
161 | if (fault) /* Clear reported faults in chip register */ | 160 | if (fault) /* Clear reported faults in chip register */ |
162 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, ~fault); | 161 | i2c_smbus_write_byte_data(data->client, LTC4261_FAULT, ~fault); |
163 | 162 | ||
164 | return snprintf(buf, PAGE_SIZE, "%d\n", fault ? 1 : 0); | 163 | return snprintf(buf, PAGE_SIZE, "%d\n", fault ? 1 : 0); |
165 | } | 164 | } |
@@ -197,7 +196,7 @@ static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, ltc4261_show_value, NULL, | |||
197 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4261_show_bool, NULL, | 196 | static SENSOR_DEVICE_ATTR(curr1_max_alarm, S_IRUGO, ltc4261_show_bool, NULL, |
198 | FAULT_OC); | 197 | FAULT_OC); |
199 | 198 | ||
200 | static struct attribute *ltc4261_attributes[] = { | 199 | static struct attribute *ltc4261_attrs[] = { |
201 | &sensor_dev_attr_in1_input.dev_attr.attr, | 200 | &sensor_dev_attr_in1_input.dev_attr.attr, |
202 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, | 201 | &sensor_dev_attr_in1_min_alarm.dev_attr.attr, |
203 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, | 202 | &sensor_dev_attr_in1_max_alarm.dev_attr.attr, |
@@ -210,62 +209,38 @@ static struct attribute *ltc4261_attributes[] = { | |||
210 | 209 | ||
211 | NULL, | 210 | NULL, |
212 | }; | 211 | }; |
213 | 212 | ATTRIBUTE_GROUPS(ltc4261); | |
214 | static const struct attribute_group ltc4261_group = { | ||
215 | .attrs = ltc4261_attributes, | ||
216 | }; | ||
217 | 213 | ||
218 | static int ltc4261_probe(struct i2c_client *client, | 214 | static int ltc4261_probe(struct i2c_client *client, |
219 | const struct i2c_device_id *id) | 215 | const struct i2c_device_id *id) |
220 | { | 216 | { |
221 | struct i2c_adapter *adapter = client->adapter; | 217 | struct i2c_adapter *adapter = client->adapter; |
218 | struct device *dev = &client->dev; | ||
222 | struct ltc4261_data *data; | 219 | struct ltc4261_data *data; |
223 | int ret; | 220 | struct device *hwmon_dev; |
224 | 221 | ||
225 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 222 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
226 | return -ENODEV; | 223 | return -ENODEV; |
227 | 224 | ||
228 | if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) { | 225 | if (i2c_smbus_read_byte_data(client, LTC4261_STATUS) < 0) { |
229 | dev_err(&client->dev, "Failed to read status register\n"); | 226 | dev_err(dev, "Failed to read status register\n"); |
230 | return -ENODEV; | 227 | return -ENODEV; |
231 | } | 228 | } |
232 | 229 | ||
233 | data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL); | 230 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
234 | if (!data) | 231 | if (!data) |
235 | return -ENOMEM; | 232 | return -ENOMEM; |
236 | 233 | ||
237 | i2c_set_clientdata(client, data); | 234 | data->client = client; |
238 | mutex_init(&data->update_lock); | 235 | mutex_init(&data->update_lock); |
239 | 236 | ||
240 | /* Clear faults */ | 237 | /* Clear faults */ |
241 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, 0x00); | 238 | i2c_smbus_write_byte_data(client, LTC4261_FAULT, 0x00); |
242 | 239 | ||
243 | /* Register sysfs hooks */ | 240 | hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, |
244 | ret = sysfs_create_group(&client->dev.kobj, <c4261_group); | 241 | data, |
245 | if (ret) | 242 | ltc4261_groups); |
246 | return ret; | 243 | return PTR_ERR_OR_ZERO(hwmon_dev); |
247 | |||
248 | data->hwmon_dev = hwmon_device_register(&client->dev); | ||
249 | if (IS_ERR(data->hwmon_dev)) { | ||
250 | ret = PTR_ERR(data->hwmon_dev); | ||
251 | goto out_hwmon_device_register; | ||
252 | } | ||
253 | |||
254 | return 0; | ||
255 | |||
256 | out_hwmon_device_register: | ||
257 | sysfs_remove_group(&client->dev.kobj, <c4261_group); | ||
258 | return ret; | ||
259 | } | ||
260 | |||
261 | static int ltc4261_remove(struct i2c_client *client) | ||
262 | { | ||
263 | struct ltc4261_data *data = i2c_get_clientdata(client); | ||
264 | |||
265 | hwmon_device_unregister(data->hwmon_dev); | ||
266 | sysfs_remove_group(&client->dev.kobj, <c4261_group); | ||
267 | |||
268 | return 0; | ||
269 | } | 244 | } |
270 | 245 | ||
271 | static const struct i2c_device_id ltc4261_id[] = { | 246 | static const struct i2c_device_id ltc4261_id[] = { |
@@ -281,7 +256,6 @@ static struct i2c_driver ltc4261_driver = { | |||
281 | .name = "ltc4261", | 256 | .name = "ltc4261", |
282 | }, | 257 | }, |
283 | .probe = ltc4261_probe, | 258 | .probe = ltc4261_probe, |
284 | .remove = ltc4261_remove, | ||
285 | .id_table = ltc4261_id, | 259 | .id_table = ltc4261_id, |
286 | }; | 260 | }; |
287 | 261 | ||