Skip to contentSkip to conversation

hwmon: TI TMP121 SPI temperature sensor driver.

PATCH In review Manuel Lauss 2 participants 2 messages Sep 15, 2008 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: TI TMP121 SPI temperature sensor driver.

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
drivers/hwmon/Kconfig +10 -0
index d402e8d..1b209c1 100644
@@ -670,6 +670,16 @@ config SENSORS_THMC50
 	  This driver can also be built as a module.  If so, the module
 	  will be called thmc50.
 
+config SENSORS_TMP121
+	tristate "Texas Instruments TMP121/TMP123 SPI Temperature sensor"
+	depends on SPI
+	help
+	  If you say yes here you get support for the Texas Instruments
+	  TMP121/TMP123 SPI temperature sensor.
+
+	  This driver can be built as a module.  If so, the module
+	  will be called tmp121.
+
 config SENSORS_VIA686A
 	tristate "VIA686A"
 	depends on PCI
drivers/hwmon/Makefile +1 -0
index 950134a..58b143c 100644
@@ -68,6 +68,7 @@ obj-$(CONFIG_SENSORS_SMSC47B397)+= smsc47b397.o
 obj-$(CONFIG_SENSORS_SMSC47M1)	+= smsc47m1.o
 obj-$(CONFIG_SENSORS_SMSC47M192)+= smsc47m192.o
 obj-$(CONFIG_SENSORS_THMC50)	+= thmc50.o
+obj-$(CONFIG_SENSORS_TMP121)	+= tmp121.o
 obj-$(CONFIG_SENSORS_VIA686A)	+= via686a.o
 obj-$(CONFIG_SENSORS_VT1211)	+= vt1211.o
 obj-$(CONFIG_SENSORS_VT8231)	+= vt8231.o
drivers/hwmon/tmp121.c new file +168 -0

168 lines not on this page · raw message

Signature · 7 lines
1.6.0.1


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

Re: [lm-sensors] [PATCH] hwmon: TI TMP121 SPI temperature sensor

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

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...

drivers/hwmon/tmp121.c line 75

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:

	val = (raw / 8) * 625 / 10;
Signature · 6 lines
Jean Delvare

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