Source
243
243
}
244
244
data->alarms = alarms;
245
245
data->last_updated = jiffies;
246
246
data->valid = true;
247
247
abort:
248
248
mutex_unlock(&data->update_lock);
249
249
250
250
return ret;
251
251
}
252
252
253
-
static ssize_t show_temp_input(struct device *dev,
253
+
static ssize_t temp_input_show(struct device *dev,
254
254
struct device_attribute *devattr, char *buf)
255
255
{
256
256
int index = to_sensor_dev_attr(devattr)->index;
257
257
struct max6697_data *data = max6697_update_device(dev);
258
258
int temp;
259
259
260
260
if (IS_ERR(data))
261
261
return PTR_ERR(data);
262
262
263
263
temp = (data->temp[index][MAX6697_TEMP_INPUT] - data->temp_offset) << 3;
264
264
temp |= data->temp[index][MAX6697_TEMP_EXT] >> 5;
265
265
266
266
return sprintf(buf, "%d\n", temp * 125);
267
267
}
268
268
269
-
static ssize_t show_temp(struct device *dev,
270
-
struct device_attribute *devattr, char *buf)
269
+
static ssize_t temp_show(struct device *dev, struct device_attribute *devattr,
270
+
char *buf)
271
271
{
272
272
int nr = to_sensor_dev_attr_2(devattr)->nr;
273
273
int index = to_sensor_dev_attr_2(devattr)->index;
274
274
struct max6697_data *data = max6697_update_device(dev);
275
275
int temp;
276
276
277
277
if (IS_ERR(data))
278
278
return PTR_ERR(data);
279
279
280
280
temp = data->temp[nr][index];
281
281
temp -= data->temp_offset;
282
282
283
283
return sprintf(buf, "%d\n", temp * 1000);
284
284
}
285
285
286
-
static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
286
+
static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
287
287
char *buf)
288
288
{
289
289
int index = to_sensor_dev_attr(attr)->index;
290
290
struct max6697_data *data = max6697_update_device(dev);
291
291
292
292
if (IS_ERR(data))
293
293
return PTR_ERR(data);
294
294
295
295
if (data->chip->alarm_map)
296
296
index = data->chip->alarm_map[index];
297
297
298
298
return sprintf(buf, "%u\n", (data->alarms >> index) & 0x1);
299
299
}
300
300
301
-
static ssize_t set_temp(struct device *dev,
302
-
struct device_attribute *devattr,
303
-
const char *buf, size_t count)
301
+
static ssize_t temp_store(struct device *dev,
302
+
struct device_attribute *devattr, const char *buf,
303
+
size_t count)
304
304
{
305
305
int nr = to_sensor_dev_attr_2(devattr)->nr;
306
306
int index = to_sensor_dev_attr_2(devattr)->index;
307
307
struct max6697_data *data = dev_get_drvdata(dev);
308
308
long temp;
309
309
int ret;
310
310
311
311
ret = kstrtol(buf, 10, &temp);
312
312
if (ret < 0)
313
313
return ret;
318
318
data->temp[nr][index] = temp;
319
319
ret = i2c_smbus_write_byte_data(data->client,
320
320
index == 2 ? MAX6697_REG_MAX[nr]
321
321
: MAX6697_REG_CRIT[nr],
322
322
temp);
323
323
mutex_unlock(&data->update_lock);
324
324
325
325
return ret < 0 ? ret : count;
326
326
}
327
327
328
-
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0);
329
-
static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
330
-
0, MAX6697_TEMP_MAX);
331
-
static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
332
-
0, MAX6697_TEMP_CRIT);
333
-
334
-
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1);
335
-
static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
336
-
1, MAX6697_TEMP_MAX);
337
-
static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
338
-
1, MAX6697_TEMP_CRIT);
339
-
340
-
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2);
341
-
static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
342
-
2, MAX6697_TEMP_MAX);
343
-
static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
344
-
2, MAX6697_TEMP_CRIT);
345
-
346
-
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp_input, NULL, 3);
347
-
static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
348
-
3, MAX6697_TEMP_MAX);
349
-
static SENSOR_DEVICE_ATTR_2(temp4_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
350
-
3, MAX6697_TEMP_CRIT);
351
-
352
-
static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, show_temp_input, NULL, 4);
353
-
static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
354
-
4, MAX6697_TEMP_MAX);
355
-
static SENSOR_DEVICE_ATTR_2(temp5_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
356
-
4, MAX6697_TEMP_CRIT);
357
-
358
-
static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO, show_temp_input, NULL, 5);
359
-
static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
360
-
5, MAX6697_TEMP_MAX);
361
-
static SENSOR_DEVICE_ATTR_2(temp6_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
362
-
5, MAX6697_TEMP_CRIT);
363
-
364
-
static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO, show_temp_input, NULL, 6);
365
-
static SENSOR_DEVICE_ATTR_2(temp7_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
366
-
6, MAX6697_TEMP_MAX);
367
-
static SENSOR_DEVICE_ATTR_2(temp7_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
368
-
6, MAX6697_TEMP_CRIT);
369
-
370
-
static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp_input, NULL, 7);
371
-
static SENSOR_DEVICE_ATTR_2(temp8_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
372
-
7, MAX6697_TEMP_MAX);
373
-
static SENSOR_DEVICE_ATTR_2(temp8_crit, S_IRUGO | S_IWUSR, show_temp, set_temp,
374
-
7, MAX6697_TEMP_CRIT);
375
-
376
-
static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 22);
377
-
static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 16);
378
-
static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 17);
379
-
static SENSOR_DEVICE_ATTR(temp4_max_alarm, S_IRUGO, show_alarm, NULL, 18);
380
-
static SENSOR_DEVICE_ATTR(temp5_max_alarm, S_IRUGO, show_alarm, NULL, 19);
381
-
static SENSOR_DEVICE_ATTR(temp6_max_alarm, S_IRUGO, show_alarm, NULL, 20);
382
-
static SENSOR_DEVICE_ATTR(temp7_max_alarm, S_IRUGO, show_alarm, NULL, 21);
383
-
static SENSOR_DEVICE_ATTR(temp8_max_alarm, S_IRUGO, show_alarm, NULL, 23);
384
-
385
-
static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
386
-
static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 8);
387
-
static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
388
-
static SENSOR_DEVICE_ATTR(temp4_crit_alarm, S_IRUGO, show_alarm, NULL, 10);
389
-
static SENSOR_DEVICE_ATTR(temp5_crit_alarm, S_IRUGO, show_alarm, NULL, 11);
390
-
static SENSOR_DEVICE_ATTR(temp6_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
391
-
static SENSOR_DEVICE_ATTR(temp7_crit_alarm, S_IRUGO, show_alarm, NULL, 13);
392
-
static SENSOR_DEVICE_ATTR(temp8_crit_alarm, S_IRUGO, show_alarm, NULL, 15);
393
-
394
-
static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 1);
395
-
static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 2);
396
-
static SENSOR_DEVICE_ATTR(temp4_fault, S_IRUGO, show_alarm, NULL, 3);
397
-
static SENSOR_DEVICE_ATTR(temp5_fault, S_IRUGO, show_alarm, NULL, 4);
398
-
static SENSOR_DEVICE_ATTR(temp6_fault, S_IRUGO, show_alarm, NULL, 5);
399
-
static SENSOR_DEVICE_ATTR(temp7_fault, S_IRUGO, show_alarm, NULL, 6);
400
-
static SENSOR_DEVICE_ATTR(temp8_fault, S_IRUGO, show_alarm, NULL, 7);
328
+
static SENSOR_DEVICE_ATTR_RO(temp1_input, temp_input, 0);
329
+
static SENSOR_DEVICE_ATTR_2_RW(temp1_max, temp, 0, MAX6697_TEMP_MAX);
330
+
static SENSOR_DEVICE_ATTR_2_RW(temp1_crit, temp, 0, MAX6697_TEMP_CRIT);
331
+
332
+
static SENSOR_DEVICE_ATTR_RO(temp2_input, temp_input, 1);
333
+
static SENSOR_DEVICE_ATTR_2_RW(temp2_max, temp, 1, MAX6697_TEMP_MAX);
334
+
static SENSOR_DEVICE_ATTR_2_RW(temp2_crit, temp, 1, MAX6697_TEMP_CRIT);
335
+
336
+
static SENSOR_DEVICE_ATTR_RO(temp3_input, temp_input, 2);
337
+
static SENSOR_DEVICE_ATTR_2_RW(temp3_max, temp, 2, MAX6697_TEMP_MAX);
338
+
static SENSOR_DEVICE_ATTR_2_RW(temp3_crit, temp, 2, MAX6697_TEMP_CRIT);
339
+
340
+
static SENSOR_DEVICE_ATTR_RO(temp4_input, temp_input, 3);
341
+
static SENSOR_DEVICE_ATTR_2_RW(temp4_max, temp, 3, MAX6697_TEMP_MAX);
342
+
static SENSOR_DEVICE_ATTR_2_RW(temp4_crit, temp, 3, MAX6697_TEMP_CRIT);
343
+
344
+
static SENSOR_DEVICE_ATTR_RO(temp5_input, temp_input, 4);
345
+
static SENSOR_DEVICE_ATTR_2_RW(temp5_max, temp, 4, MAX6697_TEMP_MAX);
346
+
static SENSOR_DEVICE_ATTR_2_RW(temp5_crit, temp, 4, MAX6697_TEMP_CRIT);
347
+
348
+
static SENSOR_DEVICE_ATTR_RO(temp6_input, temp_input, 5);
349
+
static SENSOR_DEVICE_ATTR_2_RW(temp6_max, temp, 5, MAX6697_TEMP_MAX);
350
+
static SENSOR_DEVICE_ATTR_2_RW(temp6_crit, temp, 5, MAX6697_TEMP_CRIT);
351
+
352
+
static SENSOR_DEVICE_ATTR_RO(temp7_input, temp_input, 6);
353
+
static SENSOR_DEVICE_ATTR_2_RW(temp7_max, temp, 6, MAX6697_TEMP_MAX);
354
+
static SENSOR_DEVICE_ATTR_2_RW(temp7_crit, temp, 6, MAX6697_TEMP_CRIT);
355
+
356
+
static SENSOR_DEVICE_ATTR_RO(temp8_input, temp_input, 7);
357
+
static SENSOR_DEVICE_ATTR_2_RW(temp8_max, temp, 7, MAX6697_TEMP_MAX);
358
+
static SENSOR_DEVICE_ATTR_2_RW(temp8_crit, temp, 7, MAX6697_TEMP_CRIT);
359
+
360
+
static SENSOR_DEVICE_ATTR_RO(temp1_max_alarm, alarm, 22);
361
+
static SENSOR_DEVICE_ATTR_RO(temp2_max_alarm, alarm, 16);
362
+
static SENSOR_DEVICE_ATTR_RO(temp3_max_alarm, alarm, 17);
363
+
static SENSOR_DEVICE_ATTR_RO(temp4_max_alarm, alarm, 18);
364
+
static SENSOR_DEVICE_ATTR_RO(temp5_max_alarm, alarm, 19);
365
+
static SENSOR_DEVICE_ATTR_RO(temp6_max_alarm, alarm, 20);
366
+
static SENSOR_DEVICE_ATTR_RO(temp7_max_alarm, alarm, 21);
367
+
static SENSOR_DEVICE_ATTR_RO(temp8_max_alarm, alarm, 23);
368
+
369
+
static SENSOR_DEVICE_ATTR_RO(temp1_crit_alarm, alarm, 14);
370
+
static SENSOR_DEVICE_ATTR_RO(temp2_crit_alarm, alarm, 8);
371
+
static SENSOR_DEVICE_ATTR_RO(temp3_crit_alarm, alarm, 9);
372
+
static SENSOR_DEVICE_ATTR_RO(temp4_crit_alarm, alarm, 10);
373
+
static SENSOR_DEVICE_ATTR_RO(temp5_crit_alarm, alarm, 11);
374
+
static SENSOR_DEVICE_ATTR_RO(temp6_crit_alarm, alarm, 12);
375
+
static SENSOR_DEVICE_ATTR_RO(temp7_crit_alarm, alarm, 13);
376
+
static SENSOR_DEVICE_ATTR_RO(temp8_crit_alarm, alarm, 15);
377
+
378
+
static SENSOR_DEVICE_ATTR_RO(temp2_fault, alarm, 1);
379
+
static SENSOR_DEVICE_ATTR_RO(temp3_fault, alarm, 2);
380
+
static SENSOR_DEVICE_ATTR_RO(temp4_fault, alarm, 3);
381
+
static SENSOR_DEVICE_ATTR_RO(temp5_fault, alarm, 4);
382
+
static SENSOR_DEVICE_ATTR_RO(temp6_fault, alarm, 5);
383
+
static SENSOR_DEVICE_ATTR_RO(temp7_fault, alarm, 6);
384
+
static SENSOR_DEVICE_ATTR_RO(temp8_fault, alarm, 7);
401
385
402
386
static DEVICE_ATTR(dummy, 0, NULL, NULL);
403
387
404
388
static umode_t max6697_is_visible(struct kobject *kobj, struct attribute *attr,
405
389
int index)
406
390
{
407
391
struct device *dev = container_of(kobj, struct device, kobj);
408
392
struct max6697_data *data = dev_get_drvdata(dev);
409
393
const struct max6697_chip_data *chip = data->chip;
410
394
int channel = index / 6; /* channel number */