aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorWei Ni <wni@nvidia.com>2013-11-15 04:40:39 -0500
committerJean Delvare <khali@endymion.delvare>2013-11-15 04:40:39 -0500
commit40465d9424453aa499ea91114d94b52ef8f75d61 (patch)
treec6485097c1d774aeb83dd8fe7f008d0a34318439 /drivers/hwmon
parent109b1283fb532ac773a076748ffccf76a7067cab (diff)
hwmon: (lm90) Use enums for the indexes of temp8 and temp11
Using enums for the indexes and nrs of temp8 and temp11. This make the code much more readable. Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm90.c152
1 files changed, 88 insertions, 64 deletions
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 499f473e0780..6b0a39264bb0 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -314,6 +314,36 @@ static const struct lm90_params lm90_params[] = {
314}; 314};
315 315
316/* 316/*
317 * TEMP8 register index
318 */
319enum lm90_temp8_reg_index {
320 LOCAL_LOW = 0,
321 LOCAL_HIGH,
322 LOCAL_CRIT,
323 REMOTE_CRIT,
324 LOCAL_EMERG, /* max6659 and max6695/96 */
325 REMOTE_EMERG, /* max6659 and max6695/96 */
326 REMOTE2_CRIT, /* max6695/96 only */
327 REMOTE2_EMERG, /* max6695/96 only */
328 TEMP8_REG_NUM
329};
330
331/*
332 * TEMP11 register index
333 */
334enum lm90_temp11_reg_index {
335 REMOTE_TEMP = 0,
336 REMOTE_LOW,
337 REMOTE_HIGH,
338 REMOTE_OFFSET, /* except max6646, max6657/58/59, and max6695/96 */
339 LOCAL_TEMP,
340 REMOTE2_TEMP, /* max6695/96 only */
341 REMOTE2_LOW, /* max6695/96 only */
342 REMOTE2_HIGH, /* max6695/96 only */
343 TEMP11_REG_NUM
344};
345
346/*
317 * Client data (each client gets its own) 347 * Client data (each client gets its own)
318 */ 348 */
319 349
@@ -335,25 +365,8 @@ struct lm90_data {
335 u8 reg_local_ext; /* local extension register offset */ 365 u8 reg_local_ext; /* local extension register offset */
336 366
337 /* registers values */ 367 /* registers values */
338 s8 temp8[8]; /* 0: local low limit 368 s8 temp8[TEMP8_REG_NUM];
339 * 1: local high limit 369 s16 temp11[TEMP11_REG_NUM];
340 * 2: local critical limit
341 * 3: remote critical limit
342 * 4: local emergency limit (max6659 and max6695/96)
343 * 5: remote emergency limit (max6659 and max6695/96)
344 * 6: remote 2 critical limit (max6695/96 only)
345 * 7: remote 2 emergency limit (max6695/96 only)
346 */
347 s16 temp11[8]; /* 0: remote input
348 * 1: remote low limit
349 * 2: remote high limit
350 * 3: remote offset (except max6646, max6657/58/59,
351 * and max6695/96)
352 * 4: local input
353 * 5: remote 2 input (max6695/96 only)
354 * 6: remote 2 low limit (max6695/96 only)
355 * 7: remote 2 high limit (max6695/96 only)
356 */
357 u8 temp_hyst; 370 u8 temp_hyst;
358 u16 alarms; /* bitvector (upper 8 bits for max6695/96) */ 371 u16 alarms; /* bitvector (upper 8 bits for max6695/96) */
359}; 372};
@@ -495,37 +508,42 @@ static struct lm90_data *lm90_update_device(struct device *dev)
495 u8 alarms; 508 u8 alarms;
496 509
497 dev_dbg(&client->dev, "Updating lm90 data.\n"); 510 dev_dbg(&client->dev, "Updating lm90 data.\n");
498 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW, &data->temp8[0]); 511 lm90_read_reg(client, LM90_REG_R_LOCAL_LOW,
499 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH, &data->temp8[1]); 512 &data->temp8[LOCAL_LOW]);
500 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT, &data->temp8[2]); 513 lm90_read_reg(client, LM90_REG_R_LOCAL_HIGH,
501 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, &data->temp8[3]); 514 &data->temp8[LOCAL_HIGH]);
515 lm90_read_reg(client, LM90_REG_R_LOCAL_CRIT,
516 &data->temp8[LOCAL_CRIT]);
517 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
518 &data->temp8[REMOTE_CRIT]);
502 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst); 519 lm90_read_reg(client, LM90_REG_R_TCRIT_HYST, &data->temp_hyst);
503 520
504 if (data->reg_local_ext) { 521 if (data->reg_local_ext) {
505 lm90_read16(client, LM90_REG_R_LOCAL_TEMP, 522 lm90_read16(client, LM90_REG_R_LOCAL_TEMP,
506 data->reg_local_ext, 523 data->reg_local_ext,
507 &data->temp11[4]); 524 &data->temp11[LOCAL_TEMP]);
508 } else { 525 } else {
509 if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP, 526 if (lm90_read_reg(client, LM90_REG_R_LOCAL_TEMP,
510 &h) == 0) 527 &h) == 0)
511 data->temp11[4] = h << 8; 528 data->temp11[LOCAL_TEMP] = h << 8;
512 } 529 }
513 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 530 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
514 LM90_REG_R_REMOTE_TEMPL, &data->temp11[0]); 531 LM90_REG_R_REMOTE_TEMPL,
532 &data->temp11[REMOTE_TEMP]);
515 533
516 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) { 534 if (lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h) == 0) {
517 data->temp11[1] = h << 8; 535 data->temp11[REMOTE_LOW] = h << 8;
518 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) 536 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
519 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL, 537 && lm90_read_reg(client, LM90_REG_R_REMOTE_LOWL,
520 &l) == 0) 538 &l) == 0)
521 data->temp11[1] |= l; 539 data->temp11[REMOTE_LOW] |= l;
522 } 540 }
523 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) { 541 if (lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h) == 0) {
524 data->temp11[2] = h << 8; 542 data->temp11[REMOTE_HIGH] = h << 8;
525 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT) 543 if ((data->flags & LM90_HAVE_REM_LIMIT_EXT)
526 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL, 544 && lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHL,
527 &l) == 0) 545 &l) == 0)
528 data->temp11[2] |= l; 546 data->temp11[REMOTE_HIGH] |= l;
529 } 547 }
530 548
531 if (data->flags & LM90_HAVE_OFFSET) { 549 if (data->flags & LM90_HAVE_OFFSET) {
@@ -533,13 +551,13 @@ static struct lm90_data *lm90_update_device(struct device *dev)
533 &h) == 0 551 &h) == 0
534 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL, 552 && lm90_read_reg(client, LM90_REG_R_REMOTE_OFFSL,
535 &l) == 0) 553 &l) == 0)
536 data->temp11[3] = (h << 8) | l; 554 data->temp11[REMOTE_OFFSET] = (h << 8) | l;
537 } 555 }
538 if (data->flags & LM90_HAVE_EMERGENCY) { 556 if (data->flags & LM90_HAVE_EMERGENCY) {
539 lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG, 557 lm90_read_reg(client, MAX6659_REG_R_LOCAL_EMERG,
540 &data->temp8[4]); 558 &data->temp8[LOCAL_EMERG]);
541 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, 559 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
542 &data->temp8[5]); 560 &data->temp8[REMOTE_EMERG]);
543 } 561 }
544 lm90_read_reg(client, LM90_REG_R_STATUS, &alarms); 562 lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
545 data->alarms = alarms; /* save as 16 bit value */ 563 data->alarms = alarms; /* save as 16 bit value */
@@ -547,15 +565,16 @@ static struct lm90_data *lm90_update_device(struct device *dev)
547 if (data->kind == max6696) { 565 if (data->kind == max6696) {
548 lm90_select_remote_channel(client, data, 1); 566 lm90_select_remote_channel(client, data, 1);
549 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT, 567 lm90_read_reg(client, LM90_REG_R_REMOTE_CRIT,
550 &data->temp8[6]); 568 &data->temp8[REMOTE2_CRIT]);
551 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG, 569 lm90_read_reg(client, MAX6659_REG_R_REMOTE_EMERG,
552 &data->temp8[7]); 570 &data->temp8[REMOTE2_EMERG]);
553 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH, 571 lm90_read16(client, LM90_REG_R_REMOTE_TEMPH,
554 LM90_REG_R_REMOTE_TEMPL, &data->temp11[5]); 572 LM90_REG_R_REMOTE_TEMPL,
573 &data->temp11[REMOTE2_TEMP]);
555 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h)) 574 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_LOWH, &h))
556 data->temp11[6] = h << 8; 575 data->temp11[REMOTE2_LOW] = h << 8;
557 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h)) 576 if (!lm90_read_reg(client, LM90_REG_R_REMOTE_HIGHH, &h))
558 data->temp11[7] = h << 8; 577 data->temp11[REMOTE2_HIGH] = h << 8;
559 lm90_select_remote_channel(client, data, 0); 578 lm90_select_remote_channel(client, data, 0);
560 579
561 if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2, 580 if (!lm90_read_reg(client, MAX6696_REG_R_STATUS2,
@@ -744,7 +763,7 @@ static ssize_t show_temp8(struct device *dev, struct device_attribute *devattr,
744static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr, 763static ssize_t set_temp8(struct device *dev, struct device_attribute *devattr,
745 const char *buf, size_t count) 764 const char *buf, size_t count)
746{ 765{
747 static const u8 reg[8] = { 766 static const u8 reg[TEMP8_REG_NUM] = {
748 LM90_REG_W_LOCAL_LOW, 767 LM90_REG_W_LOCAL_LOW,
749 LM90_REG_W_LOCAL_HIGH, 768 LM90_REG_W_LOCAL_HIGH,
750 LM90_REG_W_LOCAL_CRIT, 769 LM90_REG_W_LOCAL_CRIT,
@@ -897,11 +916,11 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
897 916
898 mutex_lock(&data->update_lock); 917 mutex_lock(&data->update_lock);
899 if (data->kind == adt7461) 918 if (data->kind == adt7461)
900 temp = temp_from_u8_adt7461(data, data->temp8[2]); 919 temp = temp_from_u8_adt7461(data, data->temp8[LOCAL_CRIT]);
901 else if (data->kind == max6646) 920 else if (data->kind == max6646)
902 temp = temp_from_u8(data->temp8[2]); 921 temp = temp_from_u8(data->temp8[LOCAL_CRIT]);
903 else 922 else
904 temp = temp_from_s8(data->temp8[2]); 923 temp = temp_from_s8(data->temp8[LOCAL_CRIT]);
905 924
906 data->temp_hyst = hyst_to_reg(temp - val); 925 data->temp_hyst = hyst_to_reg(temp - val);
907 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, 926 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
@@ -955,25 +974,28 @@ static ssize_t set_update_interval(struct device *dev,
955 return count; 974 return count;
956} 975}
957 976
958static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL, 0, 4); 977static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp11, NULL,
959static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL, 0, 0); 978 0, LOCAL_TEMP);
979static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp11, NULL,
980 0, REMOTE_TEMP);
960static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8, 981static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp8,
961 set_temp8, 0); 982 set_temp8, LOCAL_LOW);
962static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11, 983static SENSOR_DEVICE_ATTR_2(temp2_min, S_IWUSR | S_IRUGO, show_temp11,
963 set_temp11, 0, 1); 984 set_temp11, 0, REMOTE_LOW);
964static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8, 985static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp8,
965 set_temp8, 1); 986 set_temp8, LOCAL_HIGH);
966static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11, 987static SENSOR_DEVICE_ATTR_2(temp2_max, S_IWUSR | S_IRUGO, show_temp11,
967 set_temp11, 1, 2); 988 set_temp11, 1, REMOTE_HIGH);
968static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8, 989static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp8,
969 set_temp8, 2); 990 set_temp8, LOCAL_CRIT);
970static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8, 991static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_temp8,
971 set_temp8, 3); 992 set_temp8, REMOTE_CRIT);
972static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst, 993static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temphyst,
973 set_temphyst, 2); 994 set_temphyst, LOCAL_CRIT);
974static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL, 3); 995static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, show_temphyst, NULL,
996 REMOTE_CRIT);
975static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11, 997static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IWUSR | S_IRUGO, show_temp11,
976 set_temp11, 2, 3); 998 set_temp11, 2, REMOTE_OFFSET);
977 999
978/* Individual alarm files */ 1000/* Individual alarm files */
979static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0); 1001static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 0);
@@ -1021,13 +1043,13 @@ static const struct attribute_group lm90_group = {
1021 * Additional attributes for devices with emergency sensors 1043 * Additional attributes for devices with emergency sensors
1022 */ 1044 */
1023static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8, 1045static SENSOR_DEVICE_ATTR(temp1_emergency, S_IWUSR | S_IRUGO, show_temp8,
1024 set_temp8, 4); 1046 set_temp8, LOCAL_EMERG);
1025static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8, 1047static SENSOR_DEVICE_ATTR(temp2_emergency, S_IWUSR | S_IRUGO, show_temp8,
1026 set_temp8, 5); 1048 set_temp8, REMOTE_EMERG);
1027static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst, 1049static SENSOR_DEVICE_ATTR(temp1_emergency_hyst, S_IRUGO, show_temphyst,
1028 NULL, 4); 1050 NULL, LOCAL_EMERG);
1029static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst, 1051static SENSOR_DEVICE_ATTR(temp2_emergency_hyst, S_IRUGO, show_temphyst,
1030 NULL, 5); 1052 NULL, REMOTE_EMERG);
1031 1053
1032static struct attribute *lm90_emergency_attributes[] = { 1054static struct attribute *lm90_emergency_attributes[] = {
1033 &sensor_dev_attr_temp1_emergency.dev_attr.attr, 1055 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
@@ -1057,18 +1079,20 @@ static const struct attribute_group lm90_emergency_alarm_group = {
1057/* 1079/*
1058 * Additional attributes for devices with 3 temperature sensors 1080 * Additional attributes for devices with 3 temperature sensors
1059 */ 1081 */
1060static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL, 0, 5); 1082static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp11, NULL,
1083 0, REMOTE2_TEMP);
1061static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11, 1084static SENSOR_DEVICE_ATTR_2(temp3_min, S_IWUSR | S_IRUGO, show_temp11,
1062 set_temp11, 3, 6); 1085 set_temp11, 3, REMOTE2_LOW);
1063static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11, 1086static SENSOR_DEVICE_ATTR_2(temp3_max, S_IWUSR | S_IRUGO, show_temp11,
1064 set_temp11, 4, 7); 1087 set_temp11, 4, REMOTE2_HIGH);
1065static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8, 1088static SENSOR_DEVICE_ATTR(temp3_crit, S_IWUSR | S_IRUGO, show_temp8,
1066 set_temp8, 6); 1089 set_temp8, REMOTE2_CRIT);
1067static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL, 6); 1090static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, show_temphyst, NULL,
1091 REMOTE2_CRIT);
1068static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8, 1092static SENSOR_DEVICE_ATTR(temp3_emergency, S_IWUSR | S_IRUGO, show_temp8,
1069 set_temp8, 7); 1093 set_temp8, REMOTE2_EMERG);
1070static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst, 1094static SENSOR_DEVICE_ATTR(temp3_emergency_hyst, S_IRUGO, show_temphyst,
1071 NULL, 7); 1095 NULL, REMOTE2_EMERG);
1072 1096
1073static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9); 1097static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 9);
1074static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10); 1098static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 10);