Skip to contentSkip to conversation

hwmon: (pmbus/ltc2978) Fix temperature reporting

PATCH Superseded Guenter Roeck 2 participants 4 messages Feb 26, 2013 – Feb 27, 2013 Hardware monitoring

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH v2 5/7 hwmon: (pmbus/ltc2978) Fix temperature reporting

On LTC2978, only READ_TEMPERATURE is supported. It reports the internal junction temperature. This register is unpaged.

On LTC3880, READ_TEMPERATURE and READ_TEMPERATURE2 are supported. READ_TEMPERATURE is paged and reports external temperatures. READ_TEMPERATURE2 is unpaged and reports the internal junction temperature.

---
Candidate for -stable.

v2: v1 converted temp2_max from an array to a scalar.
This is now done in an earlier patch.

 drivers/hwmon/pmbus/ltc2978.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +9 -7
index a58de38..a729c1c 100644
@@ -59,7 +59,7 @@ enum chips { ltc2978, ltc3880 };
 struct ltc2978_data {
 	enum chips id;
 	int vin_min, vin_max;
-	int temp_min, temp_max;
+	int temp_min, temp_max[8];
 	int vout_min[8], vout_max[8];
 	int iout_max[2];
 	int temp2_max;
@@ -113,9 +113,10 @@ static int ltc2978_read_word_data_common(struct i2c_client *client, int page,
 		ret = pmbus_read_word_data(client, page,
 					   LTC2978_MFR_TEMPERATURE_PEAK);
 		if (ret >= 0) {
-			if (lin11_to_val(ret) > lin11_to_val(data->temp_max))
-				data->temp_max = ret;
-			ret = data->temp_max;
+			if (lin11_to_val(ret)
+			    > lin11_to_val(data->temp_max[page]))
+				data->temp_max[page] = ret;
+			ret = data->temp_max[page];
 		}
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
@@ -266,7 +267,7 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
 		data->temp_min = 0x7bff;
-		data->temp_max = 0x7c00;
+		data->temp_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -323,7 +324,6 @@ static int ltc2978_probe(struct i2c_client *client,
 	data->vin_min = 0x7bff;
 	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7c00;
 	data->temp2_max = 0x7c00;
 
 	switch (data->id) {
@@ -357,8 +357,10 @@ static int ltc2978_probe(struct i2c_client *client,
 	default:
 		return -ENODEV;
 	}
-	for (i = 0; i < info->pages; i++)
+	for (i = 0; i < info->pages; i++) {
+		data->temp_max[i] = 0x7c00;
 		data->vout_min[i] = 0xffff;
+	}
 
 	return pmbus_do_probe(client, id, info);
 }
Signature · 7 lines
1.7.9.7


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 23 lines · Guenter Roeck

On LTC2978, only READ_TEMPERATURE is supported. It reports the internal junction temperature. This register is unpaged.

On LTC3880, READ_TEMPERATURE and READ_TEMPERATURE2 are supported. READ_TEMPERATURE is paged and reports external temperatures. READ_TEMPERATURE2 is unpaged and reports the internal junction temperature.

---
Candidate for -stable.

v2: v1 converted temp2_max from an array to a scalar.
This is now done in an earlier patch.

 drivers/hwmon/pmbus/ltc2978.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/hwmon/pmbus/ltc2978.c +0 -0
index a58de38..a729c1c 100644

drivers/hwmon/pmbus/ltc2978.c enum chips { ltc2978, ltc3880 }; · line 62

Quoted 5 lines
drivers/hwmon/pmbus/ltc2978.c +1 -1
@@ -59,7 +59,7 @@ enum chips { ltc2978, ltc3880 };
 struct ltc2978_data {
 	enum chips id;
 	int vin_min, vin_max;
-	int temp_min, temp_max;
+	int temp_min, temp_max[8];

I'm confused. LTC2978 only has 1 temperature, LTC3880 has 3, so why have room for 8? I'm not even sure you need 2, as I suspect LTC3880's TEMP2 doesn't actually support peak recording, so 2 should be enough?

Quoted 35 lines
drivers/hwmon/pmbus/ltc2978.c +5 -5
 	int vout_min[8], vout_max[8];
 	int iout_max[2];
 	int temp2_max;
@@ -113,9 +113,10 @@ static int ltc2978_read_word_data_common(struct i2c_client *client, int page,
 		ret = pmbus_read_word_data(client, page,
 					   LTC2978_MFR_TEMPERATURE_PEAK);
 		if (ret >= 0) {
-			if (lin11_to_val(ret) > lin11_to_val(data->temp_max))
-				data->temp_max = ret;
-			ret = data->temp_max;
+			if (lin11_to_val(ret)
+			    > lin11_to_val(data->temp_max[page]))
+				data->temp_max[page] = ret;
+			ret = data->temp_max[page];
 		}
 		break;
 	case PMBUS_VIRT_RESET_VOUT_HISTORY:
@@ -266,7 +267,7 @@ static int ltc2978_write_word_data(struct i2c_client *client, int page,
 		break;
 	case PMBUS_VIRT_RESET_TEMP_HISTORY:
 		data->temp_min = 0x7bff;
-		data->temp_max = 0x7c00;
+		data->temp_max[page] = 0x7c00;
 		ret = ltc2978_clear_peaks(client, page, data->id);
 		break;
 	default:
@@ -323,7 +324,6 @@ static int ltc2978_probe(struct i2c_client *client,
 	data->vin_min = 0x7bff;
 	data->vin_max = 0x7c00;
 	data->temp_min = 0x7bff;
-	data->temp_max = 0x7c00;
 	data->temp2_max = 0x7c00;
 
 	switch (data->id) {

drivers/hwmon/pmbus/ltc2978.c static int ltc2978_probe(struct i2c_client *client, · line 361

Quoted 6 lines
drivers/hwmon/pmbus/ltc2978.c +2 -1
@@ -357,8 +357,10 @@ static int ltc2978_probe(struct i2c_client *client,
 	default:
 		return -ENODEV;
 	}
-	for (i = 0; i < info->pages; i++)
+	for (i = 0; i < info->pages; i++) {
+		data->temp_max[i] = 0x7c00;

I would leave the initialization of data->temp_max[0] where it was originally and initialize data->temp_max[1] in the "case ltc3880" section above.

I have yet to read the next patches in the series, but in general using info->pages as the upper bound for this initialization loop seems a little dangerous and inappropriate if you want to initialize several unrelated arrays there. It might be less bother to initialize every array using its ARRAY_SIZE upfront. Remember that probe() is only called once, so we don't care about optimizing every bit of speed out of it. We do care about correctness and lack of array overrun though ;) and also about the code and data structure being as small as reasonably possible.

Quoted 5 lines
drivers/hwmon/pmbus/ltc2978.c +1 -0
 		data->vout_min[i] = 0xffff;
+	}
 
 	return pmbus_do_probe(client, id, info);
 }
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#2 lore raw
In reply to Guenter Roeck
Quoted 15 lines · Jean Delvare

drivers/hwmon/pmbus/ltc2978.c enum chips { ltc2978, ltc3880 }; · line 62

Quoted 10 lines · Guenter Roeck
drivers/hwmon/pmbus/ltc2978.c +1 -1
index a58de38..a729c1c 100644
@@ -59,7 +59,7 @@ enum chips { ltc2978, ltc3880 };
 struct ltc2978_data {
 	enum chips id;
 	int vin_min, vin_max;
-	int temp_min, temp_max;
+	int temp_min, temp_max[8];

I'm confused. LTC2978 only has 1 temperature, LTC3880 has 3, so why have room for 8? I'm not even sure you need 2, as I suspect LTC3880's TEMP2 doesn't actually support peak recording, so 2 should be enough?

I'm not paying attention it seems ;) The last sentence above should read:

I'm not even sure you need 3, as temp2 has its own attribute for max peak recording, so 2 should be enough?

Conclusion is the same though.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#3 lore raw
In reply to Guenter Roeck
Quoted 17 lines · Jean Delvare
Quoted 15 lines · Jean Delvare

drivers/hwmon/pmbus/ltc2978.c enum chips { ltc2978, ltc3880 }; · line 62

Quoted 10 lines · Guenter Roeck
drivers/hwmon/pmbus/ltc2978.c +1 -1
index a58de38..a729c1c 100644
@@ -59,7 +59,7 @@ enum chips { ltc2978, ltc3880 };
 struct ltc2978_data {
 	enum chips id;
 	int vin_min, vin_max;
-	int temp_min, temp_max;
+	int temp_min, temp_max[8];

I'm confused. LTC2978 only has 1 temperature, LTC3880 has 3, so why have room for 8? I'm not even sure you need 2, as I suspect LTC3880's TEMP2 doesn't actually support peak recording, so 2 should be enough?

Quoted 6 lines

I'm not paying attention it seems ;) The last sentence above should read:

I'm not even sure you need 3, as temp2 has its own attribute for max peak recording, so 2 should be enough?

I wanted to be able to use the loop at the end of the chip specific initialization code to initialize the limit. So I figured I'd just use the maximum size for all arrays and waste a bit of memory. Another reason was that I wanted to avoid the risk of forgetting to increase it when new chips are added (LTC2974 needs four). Happened before, after all ;). You'll notice that I added a constant for the maximum array size in the patch adding support for LTC2974 and LTC3883, and use it for all array variables.

I could save some of the 'wasted' memory by using u16 instead of int for the variables; that might make more sense than limiting each array to the actual per-attribute maximum and writing device specific code to initialize it.

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors