.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for TI ADC128D818 System Monitor with Temperature Sensor |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * Derived from lm80.c |
---|
7 | 8 | * Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> |
---|
8 | 9 | * and Philip Edelbrock <phil@netroedge.com> |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify |
---|
11 | | - * it under the terms of the GNU General Public License as published by |
---|
12 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
13 | | - * (at your option) any later version. |
---|
14 | | - * |
---|
15 | | - * This program is distributed in the hope that it will be useful, |
---|
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | | - * GNU General Public License for more details. |
---|
19 | 10 | */ |
---|
20 | 11 | |
---|
21 | 12 | #include <linux/module.h> |
---|
.. | .. |
---|
153 | 144 | return ret; |
---|
154 | 145 | } |
---|
155 | 146 | |
---|
156 | | -static ssize_t adc128_show_in(struct device *dev, struct device_attribute *attr, |
---|
157 | | - char *buf) |
---|
| 147 | +static ssize_t adc128_in_show(struct device *dev, |
---|
| 148 | + struct device_attribute *attr, char *buf) |
---|
158 | 149 | { |
---|
159 | 150 | struct adc128_data *data = adc128_update_device(dev); |
---|
160 | 151 | int index = to_sensor_dev_attr_2(attr)->index; |
---|
.. | .. |
---|
168 | 159 | return sprintf(buf, "%d\n", val); |
---|
169 | 160 | } |
---|
170 | 161 | |
---|
171 | | -static ssize_t adc128_set_in(struct device *dev, struct device_attribute *attr, |
---|
172 | | - const char *buf, size_t count) |
---|
| 162 | +static ssize_t adc128_in_store(struct device *dev, |
---|
| 163 | + struct device_attribute *attr, const char *buf, |
---|
| 164 | + size_t count) |
---|
173 | 165 | { |
---|
174 | 166 | struct adc128_data *data = dev_get_drvdata(dev); |
---|
175 | 167 | int index = to_sensor_dev_attr_2(attr)->index; |
---|
.. | .. |
---|
193 | 185 | return count; |
---|
194 | 186 | } |
---|
195 | 187 | |
---|
196 | | -static ssize_t adc128_show_temp(struct device *dev, |
---|
| 188 | +static ssize_t adc128_temp_show(struct device *dev, |
---|
197 | 189 | struct device_attribute *attr, char *buf) |
---|
198 | 190 | { |
---|
199 | 191 | struct adc128_data *data = adc128_update_device(dev); |
---|
.. | .. |
---|
207 | 199 | return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */ |
---|
208 | 200 | } |
---|
209 | 201 | |
---|
210 | | -static ssize_t adc128_set_temp(struct device *dev, |
---|
211 | | - struct device_attribute *attr, |
---|
212 | | - const char *buf, size_t count) |
---|
| 202 | +static ssize_t adc128_temp_store(struct device *dev, |
---|
| 203 | + struct device_attribute *attr, |
---|
| 204 | + const char *buf, size_t count) |
---|
213 | 205 | { |
---|
214 | 206 | struct adc128_data *data = dev_get_drvdata(dev); |
---|
215 | 207 | int index = to_sensor_dev_attr(attr)->index; |
---|
.. | .. |
---|
233 | 225 | return count; |
---|
234 | 226 | } |
---|
235 | 227 | |
---|
236 | | -static ssize_t adc128_show_alarm(struct device *dev, |
---|
| 228 | +static ssize_t adc128_alarm_show(struct device *dev, |
---|
237 | 229 | struct device_attribute *attr, char *buf) |
---|
238 | 230 | { |
---|
239 | 231 | struct adc128_data *data = adc128_update_device(dev); |
---|
.. | .. |
---|
272 | 264 | return attr->mode; |
---|
273 | 265 | } |
---|
274 | 266 | |
---|
275 | | -static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, |
---|
276 | | - adc128_show_in, NULL, 0, 0); |
---|
277 | | -static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, |
---|
278 | | - adc128_show_in, adc128_set_in, 0, 1); |
---|
279 | | -static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, |
---|
280 | | - adc128_show_in, adc128_set_in, 0, 2); |
---|
| 267 | +static SENSOR_DEVICE_ATTR_2_RO(in0_input, adc128_in, 0, 0); |
---|
| 268 | +static SENSOR_DEVICE_ATTR_2_RW(in0_min, adc128_in, 0, 1); |
---|
| 269 | +static SENSOR_DEVICE_ATTR_2_RW(in0_max, adc128_in, 0, 2); |
---|
281 | 270 | |
---|
282 | | -static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, |
---|
283 | | - adc128_show_in, NULL, 1, 0); |
---|
284 | | -static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, |
---|
285 | | - adc128_show_in, adc128_set_in, 1, 1); |
---|
286 | | -static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, |
---|
287 | | - adc128_show_in, adc128_set_in, 1, 2); |
---|
| 271 | +static SENSOR_DEVICE_ATTR_2_RO(in1_input, adc128_in, 1, 0); |
---|
| 272 | +static SENSOR_DEVICE_ATTR_2_RW(in1_min, adc128_in, 1, 1); |
---|
| 273 | +static SENSOR_DEVICE_ATTR_2_RW(in1_max, adc128_in, 1, 2); |
---|
288 | 274 | |
---|
289 | | -static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, |
---|
290 | | - adc128_show_in, NULL, 2, 0); |
---|
291 | | -static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, |
---|
292 | | - adc128_show_in, adc128_set_in, 2, 1); |
---|
293 | | -static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, |
---|
294 | | - adc128_show_in, adc128_set_in, 2, 2); |
---|
| 275 | +static SENSOR_DEVICE_ATTR_2_RO(in2_input, adc128_in, 2, 0); |
---|
| 276 | +static SENSOR_DEVICE_ATTR_2_RW(in2_min, adc128_in, 2, 1); |
---|
| 277 | +static SENSOR_DEVICE_ATTR_2_RW(in2_max, adc128_in, 2, 2); |
---|
295 | 278 | |
---|
296 | | -static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, |
---|
297 | | - adc128_show_in, NULL, 3, 0); |
---|
298 | | -static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, |
---|
299 | | - adc128_show_in, adc128_set_in, 3, 1); |
---|
300 | | -static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, |
---|
301 | | - adc128_show_in, adc128_set_in, 3, 2); |
---|
| 279 | +static SENSOR_DEVICE_ATTR_2_RO(in3_input, adc128_in, 3, 0); |
---|
| 280 | +static SENSOR_DEVICE_ATTR_2_RW(in3_min, adc128_in, 3, 1); |
---|
| 281 | +static SENSOR_DEVICE_ATTR_2_RW(in3_max, adc128_in, 3, 2); |
---|
302 | 282 | |
---|
303 | | -static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, |
---|
304 | | - adc128_show_in, NULL, 4, 0); |
---|
305 | | -static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, |
---|
306 | | - adc128_show_in, adc128_set_in, 4, 1); |
---|
307 | | -static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, |
---|
308 | | - adc128_show_in, adc128_set_in, 4, 2); |
---|
| 283 | +static SENSOR_DEVICE_ATTR_2_RO(in4_input, adc128_in, 4, 0); |
---|
| 284 | +static SENSOR_DEVICE_ATTR_2_RW(in4_min, adc128_in, 4, 1); |
---|
| 285 | +static SENSOR_DEVICE_ATTR_2_RW(in4_max, adc128_in, 4, 2); |
---|
309 | 286 | |
---|
310 | | -static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, |
---|
311 | | - adc128_show_in, NULL, 5, 0); |
---|
312 | | -static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, |
---|
313 | | - adc128_show_in, adc128_set_in, 5, 1); |
---|
314 | | -static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, |
---|
315 | | - adc128_show_in, adc128_set_in, 5, 2); |
---|
| 287 | +static SENSOR_DEVICE_ATTR_2_RO(in5_input, adc128_in, 5, 0); |
---|
| 288 | +static SENSOR_DEVICE_ATTR_2_RW(in5_min, adc128_in, 5, 1); |
---|
| 289 | +static SENSOR_DEVICE_ATTR_2_RW(in5_max, adc128_in, 5, 2); |
---|
316 | 290 | |
---|
317 | | -static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, |
---|
318 | | - adc128_show_in, NULL, 6, 0); |
---|
319 | | -static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, |
---|
320 | | - adc128_show_in, adc128_set_in, 6, 1); |
---|
321 | | -static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, |
---|
322 | | - adc128_show_in, adc128_set_in, 6, 2); |
---|
| 291 | +static SENSOR_DEVICE_ATTR_2_RO(in6_input, adc128_in, 6, 0); |
---|
| 292 | +static SENSOR_DEVICE_ATTR_2_RW(in6_min, adc128_in, 6, 1); |
---|
| 293 | +static SENSOR_DEVICE_ATTR_2_RW(in6_max, adc128_in, 6, 2); |
---|
323 | 294 | |
---|
324 | | -static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, |
---|
325 | | - adc128_show_in, NULL, 7, 0); |
---|
326 | | -static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO, |
---|
327 | | - adc128_show_in, adc128_set_in, 7, 1); |
---|
328 | | -static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO, |
---|
329 | | - adc128_show_in, adc128_set_in, 7, 2); |
---|
| 295 | +static SENSOR_DEVICE_ATTR_2_RO(in7_input, adc128_in, 7, 0); |
---|
| 296 | +static SENSOR_DEVICE_ATTR_2_RW(in7_min, adc128_in, 7, 1); |
---|
| 297 | +static SENSOR_DEVICE_ATTR_2_RW(in7_max, adc128_in, 7, 2); |
---|
330 | 298 | |
---|
331 | | -static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, adc128_show_temp, NULL, 0); |
---|
332 | | -static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, |
---|
333 | | - adc128_show_temp, adc128_set_temp, 1); |
---|
334 | | -static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, |
---|
335 | | - adc128_show_temp, adc128_set_temp, 2); |
---|
| 299 | +static SENSOR_DEVICE_ATTR_RO(temp1_input, adc128_temp, 0); |
---|
| 300 | +static SENSOR_DEVICE_ATTR_RW(temp1_max, adc128_temp, 1); |
---|
| 301 | +static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, adc128_temp, 2); |
---|
336 | 302 | |
---|
337 | | -static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, adc128_show_alarm, NULL, 0); |
---|
338 | | -static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, adc128_show_alarm, NULL, 1); |
---|
339 | | -static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, adc128_show_alarm, NULL, 2); |
---|
340 | | -static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, adc128_show_alarm, NULL, 3); |
---|
341 | | -static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, adc128_show_alarm, NULL, 4); |
---|
342 | | -static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, adc128_show_alarm, NULL, 5); |
---|
343 | | -static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, adc128_show_alarm, NULL, 6); |
---|
344 | | -static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, adc128_show_alarm, NULL, 7); |
---|
345 | | -static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, adc128_show_alarm, NULL, 7); |
---|
| 303 | +static SENSOR_DEVICE_ATTR_RO(in0_alarm, adc128_alarm, 0); |
---|
| 304 | +static SENSOR_DEVICE_ATTR_RO(in1_alarm, adc128_alarm, 1); |
---|
| 305 | +static SENSOR_DEVICE_ATTR_RO(in2_alarm, adc128_alarm, 2); |
---|
| 306 | +static SENSOR_DEVICE_ATTR_RO(in3_alarm, adc128_alarm, 3); |
---|
| 307 | +static SENSOR_DEVICE_ATTR_RO(in4_alarm, adc128_alarm, 4); |
---|
| 308 | +static SENSOR_DEVICE_ATTR_RO(in5_alarm, adc128_alarm, 5); |
---|
| 309 | +static SENSOR_DEVICE_ATTR_RO(in6_alarm, adc128_alarm, 6); |
---|
| 310 | +static SENSOR_DEVICE_ATTR_RO(in7_alarm, adc128_alarm, 7); |
---|
| 311 | +static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, adc128_alarm, 7); |
---|
346 | 312 | |
---|
347 | 313 | static struct attribute *adc128_attrs[] = { |
---|
348 | 314 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
---|
.. | .. |
---|
427 | 393 | { |
---|
428 | 394 | struct i2c_client *client = data->client; |
---|
429 | 395 | int err; |
---|
| 396 | + u8 regval = 0x0; |
---|
430 | 397 | |
---|
431 | 398 | /* |
---|
432 | 399 | * Reset chip to defaults. |
---|
.. | .. |
---|
437 | 404 | return err; |
---|
438 | 405 | |
---|
439 | 406 | /* Set operation mode, if non-default */ |
---|
440 | | - if (data->mode != 0) { |
---|
441 | | - err = i2c_smbus_write_byte_data(client, |
---|
442 | | - ADC128_REG_CONFIG_ADV, |
---|
443 | | - data->mode << 1); |
---|
| 407 | + if (data->mode != 0) |
---|
| 408 | + regval |= data->mode << 1; |
---|
| 409 | + |
---|
| 410 | + /* If external vref is selected, configure the chip to use it */ |
---|
| 411 | + if (data->regulator) |
---|
| 412 | + regval |= 0x01; |
---|
| 413 | + |
---|
| 414 | + /* Write advanced configuration register */ |
---|
| 415 | + if (regval != 0x0) { |
---|
| 416 | + err = i2c_smbus_write_byte_data(client, ADC128_REG_CONFIG_ADV, |
---|
| 417 | + regval); |
---|
444 | 418 | if (err) |
---|
445 | 419 | return err; |
---|
446 | 420 | } |
---|
.. | .. |
---|
450 | 424 | if (err) |
---|
451 | 425 | return err; |
---|
452 | 426 | |
---|
453 | | - /* If external vref is selected, configure the chip to use it */ |
---|
454 | | - if (data->regulator) { |
---|
455 | | - err = i2c_smbus_write_byte_data(client, |
---|
456 | | - ADC128_REG_CONFIG_ADV, 0x01); |
---|
457 | | - if (err) |
---|
458 | | - return err; |
---|
459 | | - } |
---|
460 | | - |
---|
461 | 427 | return 0; |
---|
462 | 428 | } |
---|
463 | 429 | |
---|
464 | | -static int adc128_probe(struct i2c_client *client, |
---|
465 | | - const struct i2c_device_id *id) |
---|
| 430 | +static int adc128_probe(struct i2c_client *client) |
---|
466 | 431 | { |
---|
467 | 432 | struct device *dev = &client->dev; |
---|
468 | 433 | struct regulator *regulator; |
---|
.. | .. |
---|
546 | 511 | }; |
---|
547 | 512 | MODULE_DEVICE_TABLE(i2c, adc128_id); |
---|
548 | 513 | |
---|
549 | | -static const struct of_device_id adc128_of_match[] = { |
---|
| 514 | +static const struct of_device_id __maybe_unused adc128_of_match[] = { |
---|
550 | 515 | { .compatible = "ti,adc128d818" }, |
---|
551 | 516 | { }, |
---|
552 | 517 | }; |
---|
.. | .. |
---|
558 | 523 | .name = "adc128d818", |
---|
559 | 524 | .of_match_table = of_match_ptr(adc128_of_match), |
---|
560 | 525 | }, |
---|
561 | | - .probe = adc128_probe, |
---|
| 526 | + .probe_new = adc128_probe, |
---|
562 | 527 | .remove = adc128_remove, |
---|
563 | 528 | .id_table = adc128_id, |
---|
564 | 529 | .detect = adc128_detect, |
---|