Skip to contentSkip to conversation

hwmon: TI TMP121 SPI temperature

PATCH Manuel Lauss 1 participant 1 message Sep 16, 2008

lore
Share & tools
lore
#0 lore raw

Good Morning Jean,

Quoted 15 lines · Jean Delvare

Hi Manuel,

Le lundi 15 septembre 2008, Manuel Lauss a ?crit?:

Quoted 11 lines

Driver for the Texas Instruments TMP121/TMP123 SPI temperature sensors. The code is 99% identical to the LM70 driver; only the formula to calculate the temperature (in 1/1000 deg celsius) has been adjusted.

---
 drivers/hwmon/Kconfig  |   10 +++
 drivers/hwmon/Makefile |    1 +
 drivers/hwmon/tmp121.c |  168 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hwmon/tmp121.c
Quoted 3 lines

Wouldn't it make more sense to just add support for the TMP121/TMP123 chips to the lm70 driver? Duplicating code is better avoided when possible. Thankfully these drivers are relatively small, but still...

I can do that, sure. New patch in the works.

Quoted 14 lines

drivers/hwmon/tmp121.c

Quoted 10 lines
drivers/hwmon/tmp121.c new file +7 -0
(...)
+	/*
+	 * The "raw" temperature read into rxbuf[] is a 16-bit signed 2's
+	 * complement value. Only the MSB 13 bits (1 sign + 12 temperature
+	 * bits) are meaningful; the LSB 3 bits are to be discarded.
+	 * Each bit represents 0.0625 degrees Celsius.
+	 */
+	val = (raw * 625) / 80;

This does not actually discard the 3 LSB. In order to do that, you would need to write the following:

Quoted 1 line
	val = (raw / 8) * 625 / 10;

Don't drink and code... (the lower 3 bits read back as zero, so I used the cheap equation).

Thank you!
Manuel Lauss

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