Source
80
80
DA9052_ADCCONT_AUTOVDDEN,
81
81
DA9052_ADCCONT_AUTOVDDEN);
82
82
}
83
83
84
84
static inline int da9052_disable_vddout_channel(struct da9052 *da9052)
85
85
{
86
86
return da9052_reg_update(da9052, DA9052_ADC_CONT_REG,
87
87
DA9052_ADCCONT_AUTOVDDEN, 0);
88
88
}
89
89
90
-
static ssize_t da9052_read_vddout(struct device *dev,
90
+
static ssize_t da9052_vddout_show(struct device *dev,
91
91
struct device_attribute *devattr, char *buf)
92
92
{
93
93
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
94
94
int ret, vdd;
95
95
96
96
mutex_lock(&hwmon->hwmon_lock);
97
97
98
98
ret = da9052_enable_vddout_channel(hwmon->da9052);
99
99
if (ret < 0)
100
100
goto hwmon_err;
112
112
mutex_unlock(&hwmon->hwmon_lock);
113
113
return sprintf(buf, "%d\n", volt_reg_to_mv(vdd));
114
114
115
115
hwmon_err_release:
116
116
da9052_disable_vddout_channel(hwmon->da9052);
117
117
hwmon_err:
118
118
mutex_unlock(&hwmon->hwmon_lock);
119
119
return ret;
120
120
}
121
121
122
-
static ssize_t da9052_read_ich(struct device *dev,
122
+
static ssize_t da9052_ich_show(struct device *dev,
123
123
struct device_attribute *devattr, char *buf)
124
124
{
125
125
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
126
126
int ret;
127
127
128
128
ret = da9052_reg_read(hwmon->da9052, DA9052_ICHG_AV_REG);
129
129
if (ret < 0)
130
130
return ret;
131
131
132
132
/* Equivalent to 3.9mA/bit in register ICHG_AV */
133
133
return sprintf(buf, "%d\n", DIV_ROUND_CLOSEST(ret * 39, 10));
134
134
}
135
135
136
-
static ssize_t da9052_read_tbat(struct device *dev,
136
+
static ssize_t da9052_tbat_show(struct device *dev,
137
137
struct device_attribute *devattr, char *buf)
138
138
{
139
139
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
140
140
141
141
return sprintf(buf, "%d\n", da9052_adc_read_temp(hwmon->da9052));
142
142
}
143
143
144
-
static ssize_t da9052_read_vbat(struct device *dev,
144
+
static ssize_t da9052_vbat_show(struct device *dev,
145
145
struct device_attribute *devattr, char *buf)
146
146
{
147
147
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
148
148
int ret;
149
149
150
150
ret = da9052_adc_manual_read(hwmon->da9052, DA9052_ADC_VBAT);
151
151
if (ret < 0)
152
152
return ret;
153
153
154
154
return sprintf(buf, "%d\n", volt_reg_to_mv(ret));
155
155
}
156
156
157
-
static ssize_t da9052_read_misc_channel(struct device *dev,
157
+
static ssize_t da9052_misc_channel_show(struct device *dev,
158
158
struct device_attribute *devattr,
159
159
char *buf)
160
160
{
161
161
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
162
162
int channel = to_sensor_dev_attr(devattr)->index;
163
163
int ret;
164
164
165
165
ret = da9052_adc_manual_read(hwmon->da9052, channel);
166
166
if (ret < 0)
167
167
return ret;
235
235
return ret;
236
236
237
237
/* Wait for an conversion done interrupt */
238
238
if (!wait_for_completion_timeout(&hwmon->tsidone,
239
239
msecs_to_jiffies(500)))
240
240
return -ETIMEDOUT;
241
241
242
242
return da9052_get_tsi_result(hwmon, channel);
243
243
}
244
244
245
-
static ssize_t da9052_read_tsi(struct device *dev,
246
-
struct device_attribute *devattr,
247
-
char *buf)
245
+
static ssize_t da9052_tsi_show(struct device *dev,
246
+
struct device_attribute *devattr, char *buf)
248
247
{
249
248
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
250
249
int channel = to_sensor_dev_attr(devattr)->index;
251
250
int ret;
252
251
253
252
mutex_lock(&hwmon->hwmon_lock);
254
253
ret = __da9052_read_tsi(dev, channel);
255
254
mutex_unlock(&hwmon->hwmon_lock);
256
255
257
256
if (ret < 0)
258
257
return ret;
259
258
else
260
259
return sprintf(buf, "%d\n", input_tsireg_to_mv(hwmon, ret));
261
260
}
262
261
263
-
static ssize_t da9052_read_tjunc(struct device *dev,
262
+
static ssize_t da9052_tjunc_show(struct device *dev,
264
263
struct device_attribute *devattr, char *buf)
265
264
{
266
265
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
267
266
int tjunc;
268
267
int toffset;
269
268
270
269
tjunc = da9052_reg_read(hwmon->da9052, DA9052_TJUNC_RES_REG);
271
270
if (tjunc < 0)
272
271
return tjunc;
273
272
275
274
if (toffset < 0)
276
275
return toffset;
277
276
278
277
/*
279
278
* Degrees celsius = 1.708 * (TJUNC_RES - T_OFFSET) - 108.8
280
279
* T_OFFSET is a trim value used to improve accuracy of the result
281
280
*/
282
281
return sprintf(buf, "%d\n", 1708 * (tjunc - toffset) - 108800);
283
282
}
284
283
285
-
static ssize_t da9052_read_vbbat(struct device *dev,
284
+
static ssize_t da9052_vbbat_show(struct device *dev,
286
285
struct device_attribute *devattr, char *buf)
287
286
{
288
287
struct da9052_hwmon *hwmon = dev_get_drvdata(dev);
289
288
int ret;
290
289
291
290
ret = da9052_adc_manual_read(hwmon->da9052, DA9052_ADC_VBBAT);
292
291
if (ret < 0)
293
292
return ret;
294
293
295
294
return sprintf(buf, "%d\n", vbbat_reg_to_mv(ret));
296
295
}
297
296
298
-
static ssize_t show_label(struct device *dev,
297
+
static ssize_t label_show(struct device *dev,
299
298
struct device_attribute *devattr, char *buf)
300
299
{
301
300
return sprintf(buf, "%s\n",
302
301
input_names[to_sensor_dev_attr(devattr)->index]);
303
302
}
304
303
305
304
static umode_t da9052_channel_is_visible(struct kobject *kobj,
306
305
struct attribute *attr, int index)
307
306
{
308
307
struct device *dev = container_of(kobj, struct device, kobj);
317
316
case DA9052_ADC_TSI_YP:
318
317
case DA9052_ADC_TSI_XN:
319
318
case DA9052_ADC_TSI_YN:
320
319
return 0;
321
320
}
322
321
}
323
322
324
323
return attr->mode;
325
324
}
326
325
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);
351
-
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);
368
-
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);
373
-
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);
326
+
static SENSOR_DEVICE_ATTR_RO(in0_input, da9052_vddout, DA9052_ADC_VDDOUT);
327
+
static SENSOR_DEVICE_ATTR_RO(in0_label, label, DA9052_ADC_VDDOUT);
328
+
static SENSOR_DEVICE_ATTR_RO(in3_input, da9052_vbat, DA9052_ADC_VBAT);
329
+
static SENSOR_DEVICE_ATTR_RO(in3_label, label, DA9052_ADC_VBAT);
330
+
static SENSOR_DEVICE_ATTR_RO(in4_input, da9052_misc_channel, DA9052_ADC_IN4);
331
+
static SENSOR_DEVICE_ATTR_RO(in4_label, label, DA9052_ADC_IN4);
332
+
static SENSOR_DEVICE_ATTR_RO(in5_input, da9052_misc_channel, DA9052_ADC_IN5);
333
+
static SENSOR_DEVICE_ATTR_RO(in5_label, label, DA9052_ADC_IN5);
334
+
static SENSOR_DEVICE_ATTR_RO(in6_input, da9052_misc_channel, DA9052_ADC_IN6);
335
+
static SENSOR_DEVICE_ATTR_RO(in6_label, label, DA9052_ADC_IN6);
336
+
static SENSOR_DEVICE_ATTR_RO(in9_input, da9052_vbbat, DA9052_ADC_VBBAT);
337
+
static SENSOR_DEVICE_ATTR_RO(in9_label, label, DA9052_ADC_VBBAT);
338
+
339
+
static SENSOR_DEVICE_ATTR_RO(in70_input, da9052_tsi, DA9052_ADC_TSI_XP);
340
+
static SENSOR_DEVICE_ATTR_RO(in70_label, label, DA9052_ADC_TSI_XP);
341
+
static SENSOR_DEVICE_ATTR_RO(in71_input, da9052_tsi, DA9052_ADC_TSI_XN);
342
+
static SENSOR_DEVICE_ATTR_RO(in71_label, label, DA9052_ADC_TSI_XN);
343
+
static SENSOR_DEVICE_ATTR_RO(in72_input, da9052_tsi, DA9052_ADC_TSI_YP);
344
+
static SENSOR_DEVICE_ATTR_RO(in72_label, label, DA9052_ADC_TSI_YP);
345
+
static SENSOR_DEVICE_ATTR_RO(in73_input, da9052_tsi, DA9052_ADC_TSI_YN);
346
+
static SENSOR_DEVICE_ATTR_RO(in73_label, label, DA9052_ADC_TSI_YN);
347
+
348
+
static SENSOR_DEVICE_ATTR_RO(curr1_input, da9052_ich, DA9052_ADC_ICH);
349
+
static SENSOR_DEVICE_ATTR_RO(curr1_label, label, DA9052_ADC_ICH);
350
+
351
+
static SENSOR_DEVICE_ATTR_RO(temp2_input, da9052_tbat, DA9052_ADC_TBAT);
352
+
static SENSOR_DEVICE_ATTR_RO(temp2_label, label, DA9052_ADC_TBAT);
353
+
static SENSOR_DEVICE_ATTR_RO(temp8_input, da9052_tjunc, DA9052_ADC_TJUNC);
354
+
static SENSOR_DEVICE_ATTR_RO(temp8_label, label, DA9052_ADC_TJUNC);
382
355
383
356
static struct attribute *da9052_attrs[] = {
384
357
&sensor_dev_attr_in0_input.dev_attr.attr,
385
358
&sensor_dev_attr_in0_label.dev_attr.attr,
386
359
&sensor_dev_attr_in3_input.dev_attr.attr,
387
360
&sensor_dev_attr_in3_label.dev_attr.attr,
388
361
&sensor_dev_attr_in4_input.dev_attr.attr,
389
362
&sensor_dev_attr_in4_label.dev_attr.attr,
390
363
&sensor_dev_attr_in5_input.dev_attr.attr,
391
364
&sensor_dev_attr_in5_label.dev_attr.attr,