.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * HWMON Driver for Dialog DA9052 |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright(c) 2012 Dialog Semiconductor Ltd. |
---|
5 | 6 | * |
---|
6 | 7 | * Author: David Dajun Chen <dchen@diasemi.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify it |
---|
9 | | - * under the terms of the GNU General Public License as published by the |
---|
10 | | - * Free Software Foundation; either version 2 of the License, or (at your |
---|
11 | | - * option) any later version. |
---|
12 | | - * |
---|
13 | 8 | */ |
---|
14 | 9 | |
---|
15 | 10 | #include <linux/err.h> |
---|
.. | .. |
---|
87 | 82 | DA9052_ADCCONT_AUTOVDDEN, 0); |
---|
88 | 83 | } |
---|
89 | 84 | |
---|
90 | | -static ssize_t da9052_read_vddout(struct device *dev, |
---|
| 85 | +static ssize_t da9052_vddout_show(struct device *dev, |
---|
91 | 86 | struct device_attribute *devattr, char *buf) |
---|
92 | 87 | { |
---|
93 | 88 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
119 | 114 | return ret; |
---|
120 | 115 | } |
---|
121 | 116 | |
---|
122 | | -static ssize_t da9052_read_ich(struct device *dev, |
---|
| 117 | +static ssize_t da9052_ich_show(struct device *dev, |
---|
123 | 118 | struct device_attribute *devattr, char *buf) |
---|
124 | 119 | { |
---|
125 | 120 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
133 | 128 | return sprintf(buf, "%d\n", DIV_ROUND_CLOSEST(ret * 39, 10)); |
---|
134 | 129 | } |
---|
135 | 130 | |
---|
136 | | -static ssize_t da9052_read_tbat(struct device *dev, |
---|
| 131 | +static ssize_t da9052_tbat_show(struct device *dev, |
---|
137 | 132 | struct device_attribute *devattr, char *buf) |
---|
138 | 133 | { |
---|
139 | 134 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
141 | 136 | return sprintf(buf, "%d\n", da9052_adc_read_temp(hwmon->da9052)); |
---|
142 | 137 | } |
---|
143 | 138 | |
---|
144 | | -static ssize_t da9052_read_vbat(struct device *dev, |
---|
| 139 | +static ssize_t da9052_vbat_show(struct device *dev, |
---|
145 | 140 | struct device_attribute *devattr, char *buf) |
---|
146 | 141 | { |
---|
147 | 142 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
154 | 149 | return sprintf(buf, "%d\n", volt_reg_to_mv(ret)); |
---|
155 | 150 | } |
---|
156 | 151 | |
---|
157 | | -static ssize_t da9052_read_misc_channel(struct device *dev, |
---|
| 152 | +static ssize_t da9052_misc_channel_show(struct device *dev, |
---|
158 | 153 | struct device_attribute *devattr, |
---|
159 | 154 | char *buf) |
---|
160 | 155 | { |
---|
.. | .. |
---|
242 | 237 | return da9052_get_tsi_result(hwmon, channel); |
---|
243 | 238 | } |
---|
244 | 239 | |
---|
245 | | -static ssize_t da9052_read_tsi(struct device *dev, |
---|
246 | | - struct device_attribute *devattr, |
---|
247 | | - char *buf) |
---|
| 240 | +static ssize_t da9052_tsi_show(struct device *dev, |
---|
| 241 | + struct device_attribute *devattr, char *buf) |
---|
248 | 242 | { |
---|
249 | 243 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
250 | 244 | int channel = to_sensor_dev_attr(devattr)->index; |
---|
.. | .. |
---|
260 | 254 | return sprintf(buf, "%d\n", input_tsireg_to_mv(hwmon, ret)); |
---|
261 | 255 | } |
---|
262 | 256 | |
---|
263 | | -static ssize_t da9052_read_tjunc(struct device *dev, |
---|
| 257 | +static ssize_t da9052_tjunc_show(struct device *dev, |
---|
264 | 258 | struct device_attribute *devattr, char *buf) |
---|
265 | 259 | { |
---|
266 | 260 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
282 | 276 | return sprintf(buf, "%d\n", 1708 * (tjunc - toffset) - 108800); |
---|
283 | 277 | } |
---|
284 | 278 | |
---|
285 | | -static ssize_t da9052_read_vbbat(struct device *dev, |
---|
| 279 | +static ssize_t da9052_vbbat_show(struct device *dev, |
---|
286 | 280 | struct device_attribute *devattr, char *buf) |
---|
287 | 281 | { |
---|
288 | 282 | struct da9052_hwmon *hwmon = dev_get_drvdata(dev); |
---|
.. | .. |
---|
295 | 289 | return sprintf(buf, "%d\n", vbbat_reg_to_mv(ret)); |
---|
296 | 290 | } |
---|
297 | 291 | |
---|
298 | | -static ssize_t show_label(struct device *dev, |
---|
| 292 | +static ssize_t label_show(struct device *dev, |
---|
299 | 293 | struct device_attribute *devattr, char *buf) |
---|
300 | 294 | { |
---|
301 | 295 | return sprintf(buf, "%s\n", |
---|
.. | .. |
---|
324 | 318 | return attr->mode; |
---|
325 | 319 | } |
---|
326 | 320 | |
---|
327 | | -static SENSOR_DEVICE_ATTR(in0_input, 0444, da9052_read_vddout, NULL, |
---|
328 | | - DA9052_ADC_VDDOUT); |
---|
329 | | -static SENSOR_DEVICE_ATTR(in0_label, 0444, show_label, NULL, |
---|
330 | | - DA9052_ADC_VDDOUT); |
---|
331 | | -static SENSOR_DEVICE_ATTR(in3_input, 0444, da9052_read_vbat, NULL, |
---|
332 | | - DA9052_ADC_VBAT); |
---|
333 | | -static SENSOR_DEVICE_ATTR(in3_label, 0444, show_label, NULL, |
---|
334 | | - DA9052_ADC_VBAT); |
---|
335 | | -static SENSOR_DEVICE_ATTR(in4_input, 0444, da9052_read_misc_channel, NULL, |
---|
336 | | - DA9052_ADC_IN4); |
---|
337 | | -static SENSOR_DEVICE_ATTR(in4_label, 0444, show_label, NULL, |
---|
338 | | - DA9052_ADC_IN4); |
---|
339 | | -static SENSOR_DEVICE_ATTR(in5_input, 0444, da9052_read_misc_channel, NULL, |
---|
340 | | - DA9052_ADC_IN5); |
---|
341 | | -static SENSOR_DEVICE_ATTR(in5_label, 0444, show_label, NULL, |
---|
342 | | - DA9052_ADC_IN5); |
---|
343 | | -static SENSOR_DEVICE_ATTR(in6_input, 0444, da9052_read_misc_channel, NULL, |
---|
344 | | - DA9052_ADC_IN6); |
---|
345 | | -static SENSOR_DEVICE_ATTR(in6_label, 0444, show_label, NULL, |
---|
346 | | - DA9052_ADC_IN6); |
---|
347 | | -static SENSOR_DEVICE_ATTR(in9_input, 0444, da9052_read_vbbat, NULL, |
---|
348 | | - DA9052_ADC_VBBAT); |
---|
349 | | -static SENSOR_DEVICE_ATTR(in9_label, 0444, show_label, NULL, |
---|
350 | | - DA9052_ADC_VBBAT); |
---|
| 321 | +static SENSOR_DEVICE_ATTR_RO(in0_input, da9052_vddout, DA9052_ADC_VDDOUT); |
---|
| 322 | +static SENSOR_DEVICE_ATTR_RO(in0_label, label, DA9052_ADC_VDDOUT); |
---|
| 323 | +static SENSOR_DEVICE_ATTR_RO(in3_input, da9052_vbat, DA9052_ADC_VBAT); |
---|
| 324 | +static SENSOR_DEVICE_ATTR_RO(in3_label, label, DA9052_ADC_VBAT); |
---|
| 325 | +static SENSOR_DEVICE_ATTR_RO(in4_input, da9052_misc_channel, DA9052_ADC_IN4); |
---|
| 326 | +static SENSOR_DEVICE_ATTR_RO(in4_label, label, DA9052_ADC_IN4); |
---|
| 327 | +static SENSOR_DEVICE_ATTR_RO(in5_input, da9052_misc_channel, DA9052_ADC_IN5); |
---|
| 328 | +static SENSOR_DEVICE_ATTR_RO(in5_label, label, DA9052_ADC_IN5); |
---|
| 329 | +static SENSOR_DEVICE_ATTR_RO(in6_input, da9052_misc_channel, DA9052_ADC_IN6); |
---|
| 330 | +static SENSOR_DEVICE_ATTR_RO(in6_label, label, DA9052_ADC_IN6); |
---|
| 331 | +static SENSOR_DEVICE_ATTR_RO(in9_input, da9052_vbbat, DA9052_ADC_VBBAT); |
---|
| 332 | +static SENSOR_DEVICE_ATTR_RO(in9_label, label, DA9052_ADC_VBBAT); |
---|
351 | 333 | |
---|
352 | | -static SENSOR_DEVICE_ATTR(in70_input, 0444, da9052_read_tsi, NULL, |
---|
353 | | - DA9052_ADC_TSI_XP); |
---|
354 | | -static SENSOR_DEVICE_ATTR(in70_label, 0444, show_label, NULL, |
---|
355 | | - DA9052_ADC_TSI_XP); |
---|
356 | | -static SENSOR_DEVICE_ATTR(in71_input, 0444, da9052_read_tsi, NULL, |
---|
357 | | - DA9052_ADC_TSI_XN); |
---|
358 | | -static SENSOR_DEVICE_ATTR(in71_label, 0444, show_label, NULL, |
---|
359 | | - DA9052_ADC_TSI_XN); |
---|
360 | | -static SENSOR_DEVICE_ATTR(in72_input, 0444, da9052_read_tsi, NULL, |
---|
361 | | - DA9052_ADC_TSI_YP); |
---|
362 | | -static SENSOR_DEVICE_ATTR(in72_label, 0444, show_label, NULL, |
---|
363 | | - DA9052_ADC_TSI_YP); |
---|
364 | | -static SENSOR_DEVICE_ATTR(in73_input, 0444, da9052_read_tsi, NULL, |
---|
365 | | - DA9052_ADC_TSI_YN); |
---|
366 | | -static SENSOR_DEVICE_ATTR(in73_label, 0444, show_label, NULL, |
---|
367 | | - DA9052_ADC_TSI_YN); |
---|
| 334 | +static SENSOR_DEVICE_ATTR_RO(in70_input, da9052_tsi, DA9052_ADC_TSI_XP); |
---|
| 335 | +static SENSOR_DEVICE_ATTR_RO(in70_label, label, DA9052_ADC_TSI_XP); |
---|
| 336 | +static SENSOR_DEVICE_ATTR_RO(in71_input, da9052_tsi, DA9052_ADC_TSI_XN); |
---|
| 337 | +static SENSOR_DEVICE_ATTR_RO(in71_label, label, DA9052_ADC_TSI_XN); |
---|
| 338 | +static SENSOR_DEVICE_ATTR_RO(in72_input, da9052_tsi, DA9052_ADC_TSI_YP); |
---|
| 339 | +static SENSOR_DEVICE_ATTR_RO(in72_label, label, DA9052_ADC_TSI_YP); |
---|
| 340 | +static SENSOR_DEVICE_ATTR_RO(in73_input, da9052_tsi, DA9052_ADC_TSI_YN); |
---|
| 341 | +static SENSOR_DEVICE_ATTR_RO(in73_label, label, DA9052_ADC_TSI_YN); |
---|
368 | 342 | |
---|
369 | | -static SENSOR_DEVICE_ATTR(curr1_input, 0444, da9052_read_ich, NULL, |
---|
370 | | - DA9052_ADC_ICH); |
---|
371 | | -static SENSOR_DEVICE_ATTR(curr1_label, 0444, show_label, NULL, |
---|
372 | | - DA9052_ADC_ICH); |
---|
| 343 | +static SENSOR_DEVICE_ATTR_RO(curr1_input, da9052_ich, DA9052_ADC_ICH); |
---|
| 344 | +static SENSOR_DEVICE_ATTR_RO(curr1_label, label, DA9052_ADC_ICH); |
---|
373 | 345 | |
---|
374 | | -static SENSOR_DEVICE_ATTR(temp2_input, 0444, da9052_read_tbat, NULL, |
---|
375 | | - DA9052_ADC_TBAT); |
---|
376 | | -static SENSOR_DEVICE_ATTR(temp2_label, 0444, show_label, NULL, |
---|
377 | | - DA9052_ADC_TBAT); |
---|
378 | | -static SENSOR_DEVICE_ATTR(temp8_input, 0444, da9052_read_tjunc, NULL, |
---|
379 | | - DA9052_ADC_TJUNC); |
---|
380 | | -static SENSOR_DEVICE_ATTR(temp8_label, 0444, show_label, NULL, |
---|
381 | | - DA9052_ADC_TJUNC); |
---|
| 346 | +static SENSOR_DEVICE_ATTR_RO(temp2_input, da9052_tbat, DA9052_ADC_TBAT); |
---|
| 347 | +static SENSOR_DEVICE_ATTR_RO(temp2_label, label, DA9052_ADC_TBAT); |
---|
| 348 | +static SENSOR_DEVICE_ATTR_RO(temp8_input, da9052_tjunc, DA9052_ADC_TJUNC); |
---|
| 349 | +static SENSOR_DEVICE_ATTR_RO(temp8_label, label, DA9052_ADC_TJUNC); |
---|
382 | 350 | |
---|
383 | 351 | static struct attribute *da9052_attrs[] = { |
---|
384 | 352 | &sensor_dev_attr_in0_input.dev_attr.attr, |
---|