Source
146
146
goto done;
147
147
148
148
abort:
149
149
ret = ERR_PTR(rv);
150
150
data->valid = false;
151
151
done:
152
152
mutex_unlock(&data->update_lock);
153
153
return ret;
154
154
}
155
155
156
-
static ssize_t adc128_show_in(struct device *dev, struct device_attribute *attr,
157
-
char *buf)
156
+
static ssize_t adc128_in_show(struct device *dev,
157
+
struct device_attribute *attr, char *buf)
158
158
{
159
159
struct adc128_data *data = adc128_update_device(dev);
160
160
int index = to_sensor_dev_attr_2(attr)->index;
161
161
int nr = to_sensor_dev_attr_2(attr)->nr;
162
162
int val;
163
163
164
164
if (IS_ERR(data))
165
165
return PTR_ERR(data);
166
166
167
167
val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095);
168
168
return sprintf(buf, "%d\n", val);
169
169
}
170
170
171
-
static ssize_t adc128_set_in(struct device *dev, struct device_attribute *attr,
172
-
const char *buf, size_t count)
171
+
static ssize_t adc128_in_store(struct device *dev,
172
+
struct device_attribute *attr, const char *buf,
173
+
size_t count)
173
174
{
174
175
struct adc128_data *data = dev_get_drvdata(dev);
175
176
int index = to_sensor_dev_attr_2(attr)->index;
176
177
int nr = to_sensor_dev_attr_2(attr)->nr;
177
178
u8 reg, regval;
178
179
long val;
179
180
int err;
180
181
181
182
err = kstrtol(buf, 10, &val);
182
183
if (err < 0)
186
187
/* 10 mV LSB on limit registers */
187
188
regval = clamp_val(DIV_ROUND_CLOSEST(val, 10), 0, 255);
188
189
data->in[index][nr] = regval << 4;
189
190
reg = index == 1 ? ADC128_REG_IN_MIN(nr) : ADC128_REG_IN_MAX(nr);
190
191
i2c_smbus_write_byte_data(data->client, reg, regval);
191
192
mutex_unlock(&data->update_lock);
192
193
193
194
return count;
194
195
}
195
196
196
-
static ssize_t adc128_show_temp(struct device *dev,
197
+
static ssize_t adc128_temp_show(struct device *dev,
197
198
struct device_attribute *attr, char *buf)
198
199
{
199
200
struct adc128_data *data = adc128_update_device(dev);
200
201
int index = to_sensor_dev_attr(attr)->index;
201
202
int temp;
202
203
203
204
if (IS_ERR(data))
204
205
return PTR_ERR(data);
205
206
206
207
temp = sign_extend32(data->temp[index], 8);
207
208
return sprintf(buf, "%d\n", temp * 500);/* 0.5 degrees C resolution */
208
209
}
209
210
210
-
static ssize_t adc128_set_temp(struct device *dev,
211
-
struct device_attribute *attr,
212
-
const char *buf, size_t count)
211
+
static ssize_t adc128_temp_store(struct device *dev,
212
+
struct device_attribute *attr,
213
+
const char *buf, size_t count)
213
214
{
214
215
struct adc128_data *data = dev_get_drvdata(dev);
215
216
int index = to_sensor_dev_attr(attr)->index;
216
217
long val;
217
218
int err;
218
219
s8 regval;
219
220
220
221
err = kstrtol(buf, 10, &val);
221
222
if (err < 0)
222
223
return err;
226
227
data->temp[index] = regval << 1;
227
228
i2c_smbus_write_byte_data(data->client,
228
229
index == 1 ? ADC128_REG_TEMP_MAX
229
230
: ADC128_REG_TEMP_HYST,
230
231
regval);
231
232
mutex_unlock(&data->update_lock);
232
233
233
234
return count;
234
235
}
235
236
236
-
static ssize_t adc128_show_alarm(struct device *dev,
237
+
static ssize_t adc128_alarm_show(struct device *dev,
237
238
struct device_attribute *attr, char *buf)
238
239
{
239
240
struct adc128_data *data = adc128_update_device(dev);
240
241
int mask = 1 << to_sensor_dev_attr(attr)->index;
241
242
u8 alarms;
242
243
243
244
if (IS_ERR(data))
244
245
return PTR_ERR(data);
245
246
246
247
/*
265
266
return 0;
266
267
} else {
267
268
/* Temperature, visible if not in mode 1 */
268
269
if (data->mode == 1)
269
270
return 0;
270
271
}
271
272
272
273
return attr->mode;
273
274
}
274
275
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);
281
-
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);
288
-
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);
295
-
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);
302
-
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);
309
-
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);
316
-
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);
323
-
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);
330
-
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);
336
-
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);
276
+
static SENSOR_DEVICE_ATTR_2_RO(in0_input, adc128_in, 0, 0);
277
+
static SENSOR_DEVICE_ATTR_2_RW(in0_min, adc128_in, 0, 1);
278
+
static SENSOR_DEVICE_ATTR_2_RW(in0_max, adc128_in, 0, 2);
279
+
280
+
static SENSOR_DEVICE_ATTR_2_RO(in1_input, adc128_in, 1, 0);
281
+
static SENSOR_DEVICE_ATTR_2_RW(in1_min, adc128_in, 1, 1);
282
+
static SENSOR_DEVICE_ATTR_2_RW(in1_max, adc128_in, 1, 2);
283
+
284
+
static SENSOR_DEVICE_ATTR_2_RO(in2_input, adc128_in, 2, 0);
285
+
static SENSOR_DEVICE_ATTR_2_RW(in2_min, adc128_in, 2, 1);
286
+
static SENSOR_DEVICE_ATTR_2_RW(in2_max, adc128_in, 2, 2);
287
+
288
+
static SENSOR_DEVICE_ATTR_2_RO(in3_input, adc128_in, 3, 0);
289
+
static SENSOR_DEVICE_ATTR_2_RW(in3_min, adc128_in, 3, 1);
290
+
static SENSOR_DEVICE_ATTR_2_RW(in3_max, adc128_in, 3, 2);
291
+
292
+
static SENSOR_DEVICE_ATTR_2_RO(in4_input, adc128_in, 4, 0);
293
+
static SENSOR_DEVICE_ATTR_2_RW(in4_min, adc128_in, 4, 1);
294
+
static SENSOR_DEVICE_ATTR_2_RW(in4_max, adc128_in, 4, 2);
295
+
296
+
static SENSOR_DEVICE_ATTR_2_RO(in5_input, adc128_in, 5, 0);
297
+
static SENSOR_DEVICE_ATTR_2_RW(in5_min, adc128_in, 5, 1);
298
+
static SENSOR_DEVICE_ATTR_2_RW(in5_max, adc128_in, 5, 2);
299
+
300
+
static SENSOR_DEVICE_ATTR_2_RO(in6_input, adc128_in, 6, 0);
301
+
static SENSOR_DEVICE_ATTR_2_RW(in6_min, adc128_in, 6, 1);
302
+
static SENSOR_DEVICE_ATTR_2_RW(in6_max, adc128_in, 6, 2);
303
+
304
+
static SENSOR_DEVICE_ATTR_2_RO(in7_input, adc128_in, 7, 0);
305
+
static SENSOR_DEVICE_ATTR_2_RW(in7_min, adc128_in, 7, 1);
306
+
static SENSOR_DEVICE_ATTR_2_RW(in7_max, adc128_in, 7, 2);
307
+
308
+
static SENSOR_DEVICE_ATTR_RO(temp1_input, adc128_temp, 0);
309
+
static SENSOR_DEVICE_ATTR_RW(temp1_max, adc128_temp, 1);
310
+
static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, adc128_temp, 2);
311
+
312
+
static SENSOR_DEVICE_ATTR_RO(in0_alarm, adc128_alarm, 0);
313
+
static SENSOR_DEVICE_ATTR_RO(in1_alarm, adc128_alarm, 1);
314
+
static SENSOR_DEVICE_ATTR_RO(in2_alarm, adc128_alarm, 2);
315
+
static SENSOR_DEVICE_ATTR_RO(in3_alarm, adc128_alarm, 3);
316
+
static SENSOR_DEVICE_ATTR_RO(in4_alarm, adc128_alarm, 4);
317
+
static SENSOR_DEVICE_ATTR_RO(in5_alarm, adc128_alarm, 5);
318
+
static SENSOR_DEVICE_ATTR_RO(in6_alarm, adc128_alarm, 6);
319
+
static SENSOR_DEVICE_ATTR_RO(in7_alarm, adc128_alarm, 7);
320
+
static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, adc128_alarm, 7);
346
321
347
322
static struct attribute *adc128_attrs[] = {
348
323
&sensor_dev_attr_in0_alarm.dev_attr.attr,
349
324
&sensor_dev_attr_in0_input.dev_attr.attr,
350
325
&sensor_dev_attr_in0_max.dev_attr.attr,
351
326
&sensor_dev_attr_in0_min.dev_attr.attr,
352
327
&sensor_dev_attr_in1_alarm.dev_attr.attr,
353
328
&sensor_dev_attr_in1_input.dev_attr.attr,
354
329
&sensor_dev_attr_in1_max.dev_attr.attr,
355
330
&sensor_dev_attr_in1_min.dev_attr.attr,