Skip to contentSkip to conversation

hwmon/lm70: adding support for NS LM74 chip

PATCH In review Christophe Leroy 2 participants 5 messages Aug 23, 2012 – Aug 28, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon/lm70: adding support for NS LM74 chip

Hello,

This Patch adds support for the LM74 chip from National Semiconductor (NS) in the lm70 driver

drivers/hwmon/Kconfig +2 -2
diff -u linux-3.5-vanilla/drivers/hwmon/Kconfig linux-3.5/drivers/hwmon/Kconfig
@@ -530,11 +530,11 @@
 	  will be called lm63.
 
 config SENSORS_LM70
-	tristate "National Semiconductor LM70 / Texas Instruments TMP121"
+	tristate "National Semiconductor LM70&LM74 / Texas Instruments TMP121"
 	depends on SPI_MASTER
 	help
 	  If you say yes here you get support for the National Semiconductor
-	  LM70 and Texas Instruments TMP121/TMP123 digital temperature
+	  LM70 and LM74 and Texas Instruments TMP121/TMP123 digital temperature
 	  sensor chips.
 
 	  This driver can also be built as a module.  If so, the module
drivers/hwmon/lm70.c +13 -5
diff -u linux-3.5-vanilla/drivers/hwmon/lm70.c linux-3.5/drivers/hwmon/lm70.c
@@ -3,11 +3,12 @@
  *
  * The LM70 is a temperature sensor chip from National Semiconductor (NS).
  * Copyright (C) 2006 Kaiwan N Billimoria <[email protected]>
+ * Copyright (C) 2012 Christophe Leroy <[email protected]>
  *
  * The LM70 communicates with a host processor via an SPI/Microwire Bus
  * interface. The complete datasheet is available at National's website
  * here:
- * http://www.national.com/pf/LM/LM70.html
+ * http://www.ti.com/product/LM70
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,6 +44,7 @@
 
 #define LM70_CHIP_LM70		0	/* original NS LM70 */
 #define LM70_CHIP_TMP121	1	/* TI TMP121/TMP123 */
+#define LM70_CHIP_LM74		2	/* original NS LM74 */
 
 struct lm70 {
 	struct device *hwmon_dev;
@@ -98,6 +100,7 @@
 		break;
 
 	case LM70_CHIP_TMP121:
+	case LM70_CHIP_LM74:
 		val = ((int)raw / 8) * 625 / 10;
 		break;
 	}
@@ -123,6 +126,9 @@
 	case LM70_CHIP_TMP121:
 		ret = sprintf(buf, "tmp121\n");
 		break;
+	case LM70_CHIP_LM74:
+		ret = sprintf(buf, "lm74\n");
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -139,12 +145,13 @@
 	struct lm70 *p_lm70;
 	int status;
 
-	/* signaling is SPI_MODE_0 for both LM70 and TMP121 */
+	/* signaling is SPI_MODE_0 for LM70, LM74 and TMP121 */
 	if (spi->mode & (SPI_CPOL | SPI_CPHA))
 		return -EINVAL;
 
-	/* 3-wire link (shared SI/SO) for LM70 */
-	if (chip = LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
+	/* 3-wire link (shared SI/SO) for LM70 and LM74 */
+	if ((chip = LM70_CHIP_LM70 || chip = LM70_CHIP_LM74)
+			&& !(spi->mode & SPI_3WIRE))
 		return -EINVAL;
 
 	/* NOTE:  we assume 8-bit words, and convert to 16 bits manually */
@@ -202,6 +209,7 @@
 static const struct spi_device_id lm70_ids[] = {
 	{ "lm70",   LM70_CHIP_LM70 },
 	{ "tmp121", LM70_CHIP_TMP121 },
+	{ "lm74",   LM70_CHIP_LM74 },
 	{ },
 };
 MODULE_DEVICE_TABLE(spi, lm70_ids);
@@ -219,5 +227,5 @@
 module_spi_driver(lm70_driver);
 
 MODULE_AUTHOR("Kaiwan N Billimoria");
-MODULE_DESCRIPTION("NS LM70 / TI TMP121/TMP123 Linux driver");
+MODULE_DESCRIPTION("NS LM70 & LM74 / TI TMP121/TMP123 Linux driver");
 MODULE_LICENSE("GPL");
Documentation/hwmon/lm70 +8 -4
diff -u linux-3.5-vanilla/Documentation/hwmon/lm70 linux-3.5/Documentation/hwmon/lm70
@@ -3,7 +3,9 @@
 
 Supported chips:
   * National Semiconductor LM70
-    Datasheet: http://www.national.com/pf/LM/LM70.html
+    Datasheet: http://www.ti.com/product/LM70
+  * National Semiconductor LM74
+    Datasheet: http://www.ti.com/product/LM74
   * Texas Instruments TMP121/TMP123
     Information: http://focus.ti.com/docs/prod/folders/print/tmp121.html
 
@@ -31,9 +33,11 @@
 with a "SPI master controller driver", see drivers/spi/spi_lm70llp.c
 and its associated documentation.
 
-The TMP121/TMP123 are very similar; main differences are 4 wire SPI inter-
-face (read only) and 13-bit temperature data (0.0625 degrees celsius reso-
-lution).
+The LM74 is very similar; main differences is 13-bit temperature data 
+(0.0625 degrees celsius resolution).
+
+The TMP121/TMP123 are very similar to the LM74; main difference is 4 wire
+SPI interface (read only).
 
 Thanks to
 ---------

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

maintainer
#1 lore raw
Quoted 2 lines · Christophe Leroy

Hello,

Hi Christophe,

Just a nitpick, but as written the Hello is added to the commit log.

Quoted 9 lines

This Patch adds support for the LM74 chip from National Semiconductor (NS) in the lm70 driver

diff -u linux-3.5-vanilla/drivers/hwmon/Kconfig linux-3.5/drivers/hwmon/Kconfig

drivers/hwmon/Kconfig line 533

Quoted 5 lines
drivers/hwmon/Kconfig +1 -1
@@ -530,11 +530,11 @@
 	  will be called lm63.
 
 config SENSORS_LM70
-	tristate "National Semiconductor LM70 / Texas Instruments TMP121"
+	tristate "National Semiconductor LM70&LM74 / Texas Instruments TMP121"

Make it "LM70 and compatibles". There are other chips which should work as well, such as LM71 and TMP122/TMP124.

Quoted 12 lines
drivers/hwmon/Kconfig +1 -1
 	depends on SPI_MASTER
 	help
 	  If you say yes here you get support for the National Semiconductor
-	  LM70 and Texas Instruments TMP121/TMP123 digital temperature
+	  LM70 and LM74 and Texas Instruments TMP121/TMP123 digital temperature
 	  sensor chips.
 
 	  This driver can also be built as a module.  If so, the module

diff -u linux-3.5-vanilla/drivers/hwmon/lm70.c linux-3.5/drivers/hwmon/lm70.c

drivers/hwmon/lm70.c line 6

Quoted 4 lines
drivers/hwmon/lm70.c +1 -0
@@ -3,11 +3,12 @@
  *
  * The LM70 is a temperature sensor chip from National Semiconductor (NS).
  * Copyright (C) 2006 Kaiwan N Billimoria <[email protected]>
+ * Copyright (C) 2012 Christophe Leroy <[email protected]>

Not for a couple of lines of code.

drivers/hwmon/lm70.c line 11

Quoted 6 lines
drivers/hwmon/lm70.c +1 -1
  *
  * The LM70 communicates with a host processor via an SPI/Microwire Bus
  * interface. The complete datasheet is available at National's website
  * here:
- * http://www.national.com/pf/LM/LM70.html
+ * http://www.ti.com/product/LM70

Updating the data sheet link for LM70 would be a second patch. Only one change per patch, please (even more so since the old link still works).

drivers/hwmon/lm70.c line 48

Quoted 9 lines
drivers/hwmon/lm70.c +1 -0
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,6 +44,7 @@
 
 #define LM70_CHIP_LM70		0	/* original NS LM70 */
 #define LM70_CHIP_TMP121	1	/* TI TMP121/TMP123 */
+#define LM70_CHIP_LM74		2	/* original NS LM74 */
 

Drop the "original" here. All chips are "original". The "original LM70" statement above probably refers to the first chip supported by this driver.

Quoted 24 lines
drivers/hwmon/lm70.c +4 -0
 struct lm70 {
 	struct device *hwmon_dev;
@@ -98,6 +100,7 @@
 		break;
 
 	case LM70_CHIP_TMP121:
+	case LM70_CHIP_LM74:
 		val = ((int)raw / 8) * 625 / 10;
 		break;
 	}
@@ -123,6 +126,9 @@
 	case LM70_CHIP_TMP121:
 		ret = sprintf(buf, "tmp121\n");
 		break;
+	case LM70_CHIP_LM74:
+		ret = sprintf(buf, "lm74\n");
+		break;
 	default:
 		ret = -EINVAL;
 	}
@@ -139,12 +145,13 @@
 	struct lm70 *p_lm70;
 	int status;
 

drivers/hwmon/lm70.c line 154

Quoted 10 lines
drivers/hwmon/lm70.c +4 -3
-	/* signaling is SPI_MODE_0 for both LM70 and TMP121 */
+	/* signaling is SPI_MODE_0 for LM70, LM74 and TMP121 */
 	if (spi->mode & (SPI_CPOL | SPI_CPHA))
 		return -EINVAL;
 
-	/* 3-wire link (shared SI/SO) for LM70 */
-	if (chip = LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
+	/* 3-wire link (shared SI/SO) for LM70 and LM74 */
+	if ((chip = LM70_CHIP_LM70 || chip = LM70_CHIP_LM74)
+			&& !(spi->mode & SPI_3WIRE))

Ok for now, but I'll have to check this. The driver does not really write anything to the chip, so it should be irrelevant which mode the SPI master controller supports (MOSI does not have to be connected). Besides, from the chip specification it looks like it is possible to connect the chip to a standard SPI interface by adding a 10k resistor between MOSI and MISO.

Quoted 22 lines
drivers/hwmon/lm70.c +2 -1
 		return -EINVAL;
 
 	/* NOTE:  we assume 8-bit words, and convert to 16 bits manually */
@@ -202,6 +209,7 @@
 static const struct spi_device_id lm70_ids[] = {
 	{ "lm70",   LM70_CHIP_LM70 },
 	{ "tmp121", LM70_CHIP_TMP121 },
+	{ "lm74",   LM70_CHIP_LM74 },
 	{ },
 };
 MODULE_DEVICE_TABLE(spi, lm70_ids);
@@ -219,5 +227,5 @@
 module_spi_driver(lm70_driver);
 
 MODULE_AUTHOR("Kaiwan N Billimoria");
-MODULE_DESCRIPTION("NS LM70 / TI TMP121/TMP123 Linux driver");
+MODULE_DESCRIPTION("NS LM70 & LM74 / TI TMP121/TMP123 Linux driver");
 MODULE_LICENSE("GPL");

diff -u linux-3.5-vanilla/Documentation/hwmon/lm70 linux-3.5/Documentation/hwmon/lm70

Documentation/hwmon/lm70 line 6

Quoted 5 lines
Documentation/hwmon/lm70 +1 -1
@@ -3,7 +3,9 @@
 
 Supported chips:
   * National Semiconductor LM70
-    Datasheet: http://www.national.com/pf/LM/LM70.html
+    Datasheet: http://www.ti.com/product/LM70

Again, separate patch

Documentation/hwmon/lm70 line 36

Quoted 13 lines
Documentation/hwmon/lm70 +3 -3
+  * National Semiconductor LM74
+    Datasheet: http://www.ti.com/product/LM74
   * Texas Instruments TMP121/TMP123
     Information: http://focus.ti.com/docs/prod/folders/print/tmp121.html
 
@@ -31,9 +33,11 @@
 with a "SPI master controller driver", see drivers/spi/spi_lm70llp.c
 and its associated documentation.
 
-The TMP121/TMP123 are very similar; main differences are 4 wire SPI inter-
-face (read only) and 13-bit temperature data (0.0625 degrees celsius reso-
-lution).
+The LM74 is very similar; main differences is 13-bit temperature data 

ERROR: trailing whitespace
#131: FILE: Documentation/hwmon/lm70:36:
+The LM74 is very similar; main differences is 13-bit temperature data $

Documentation/hwmon/lm70 line 43

Quoted 8 lines
Documentation/hwmon/lm70 +4 -0
+(0.0625 degrees celsius resolution).
+
+The TMP121/TMP123 are very similar to the LM74; main difference is 4 wire
+SPI interface (read only).
 
 Thanks to
 ---------

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

maintainer
#2 lore raw
Quoted 5 lines · Guenter Roeck
Quoted 2 lines · Christophe Leroy

Hello,

Hi Christophe,

Hi again,

[ ... ]

Quoted 13 lines

drivers/hwmon/lm70.c line 154

Quoted 6 lines
drivers/hwmon/lm70.c +3 -2
-	/* 3-wire link (shared SI/SO) for LM70 */
-	if (chip = LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
+	/* 3-wire link (shared SI/SO) for LM70 and LM74 */
+	if ((chip = LM70_CHIP_LM70 || chip = LM70_CHIP_LM74)
+			&& !(spi->mode & SPI_3WIRE))

Ok for now, but I'll have to check this. The driver does not really write anything to the chip, so it should be irrelevant which mode the SPI master controller supports (MOSI does not have to be connected). Besides, from the chip specification it looks like it is possible to connect the chip to a standard SPI interface by adding a 10k resistor between MOSI and MISO.

After looking into the above, the proper change or fix is really to remove the above check for SPI_3WIRE entirely. The driver works perfectly fine if a LM70 is connected to a controller which does not explicitly support SPI_3WIRE; all that needs to be done is to connect MOSI through a resistor or not at all. This is, however, a board design decision, not a SPI master chip limitation.

With that, we don't need to explicitly add any LM74 specific code to the driver, since the TMP121 code does the trick. All we need to do is to update the documentation, adding a note that LM74 is supported as well, and that it can be selected with 'tmp121'.

Thanks,
Guenter

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

#3 lore raw
Quoted 9 lines · Guenter Roeck
Quoted 5 lines · Guenter Roeck
Quoted 2 lines · Christophe Leroy

Hello,

Hi Christophe,

Hi again,

[ ... ]

Hi Guenter,

Quoted 12 lines
Quoted 12 lines

drivers/hwmon/lm70.c line 154

Quoted 6 lines
drivers/hwmon/lm70.c +3 -2
-	/* 3-wire link (shared SI/SO) for LM70 */
-	if (chip == LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
+	/* 3-wire link (shared SI/SO) for LM70 and LM74 */
+	if ((chip == LM70_CHIP_LM70 || chip == LM70_CHIP_LM74)
+			&& !(spi->mode & SPI_3WIRE))

Ok for now, but I'll have to check this. The driver does not really write anything to the chip, so it should be irrelevant which mode the SPI master controller supports (MOSI does not have to be connected). Besides, from the chip specification it looks like it is possible to connect the chip to a standard SPI interface by adding a 10k resistor between MOSI and MISO.

Quoted 5 lines

After looking into the above, the proper change or fix is really to remove the above check for SPI_3WIRE entirely. The driver works perfectly fine if a LM70 is connected to a controller which does not explicitly support SPI_3WIRE; all that needs to be done is to connect MOSI through a resistor or not at all. This is, however, a board design decision, not a SPI master chip limitation.

Ok, then I'll prepare a patch for this.

Quoted 5 lines

With that, we don't need to explicitly add any LM74 specific code to the driver, since the TMP121 code does the trick. All we need to do is to update the documentation, adding a note that LM74 is supported as well, and that it can be selected with 'tmp121'.

Yes, could be the solution, but I'm however a bit puzzled with doing this. The driver is originaly for NS LM70 component. Later on an extension has been added for TMP121 which is from a different family, even if compatible. Now we are talking about the LM74 which is in the same family as the original LM70. Therefore I would expect to be able to handle the LM74 directly from this driver, not through a tricky compatibility with the 'tmp121'. I would expect to handle it the other way round, ie consider the 'tmp121' as compatible with the LM74. One of the reasons for that is that the driver reports the component ID through /sys/class/hwmon/hwmonX/name

As the 'tmp121' is already in the driver, it is not a good idea to replace it by LM74, however, I would prefer having the LM74 explicitly addressable by the driver, in additional to the 'tmp121'

I'm preparing a patch to include support for both LM71 and LM74 in the LM70 driver, in order to have a driver handling the complete family. Do you see a problem for that ? It would look strange that the LM70 driver handles LM70 and LM71, but LM74 through the compatible 'tmp121'

Nb, refer to your first answer, implementation for 'tmp122/124' is another story because those have a programmable precision, not a fixed one.

Quoted 4 lines

Thanks,
Guenter

Thanks
Christophe

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

maintainer
#4 lore raw
Quoted 51 lines · leroy christophe
Quoted 9 lines · Guenter Roeck
Quoted 5 lines · Guenter Roeck
Quoted 2 lines · Christophe Leroy

Hello,

Hi Christophe,

Hi again,

[ ... ]

Hi Guenter,

Quoted 11 lines
Quoted 11 lines

drivers/hwmon/lm70.c line 154

Quoted 5 lines
drivers/hwmon/lm70.c +3 -2
-	/* 3-wire link (shared SI/SO) for LM70 */
-	if (chip == LM70_CHIP_LM70 && !(spi->mode & SPI_3WIRE))
+	/* 3-wire link (shared SI/SO) for LM70 and LM74 */
+	if ((chip == LM70_CHIP_LM70 || chip == LM70_CHIP_LM74)
+			&& !(spi->mode & SPI_3WIRE))

Ok for now, but I'll have to check this. The driver does not really write anything to the chip, so it should be irrelevant which mode the SPI master controller supports (MOSI does not have to be connected). Besides, from the chip specification it looks like it is possible to connect the chip to a standard SPI interface by adding a 10k resistor between MOSI and MISO.

Quoted 5 lines

After looking into the above, the proper change or fix is really to remove the above check for SPI_3WIRE entirely. The driver works perfectly fine if a LM70 is connected to a controller which does not explicitly support SPI_3WIRE; all that needs to be done is to connect MOSI through a resistor or not at all. This is, however, a board design decision, not a SPI master chip limitation.

Ok, then I'll prepare a patch for this.

Quoted 5 lines

With that, we don't need to explicitly add any LM74 specific code to the driver, since the TMP121 code does the trick. All we need to do is to update the documentation, adding a note that LM74 is supported as well, and that it can be selected with 'tmp121'.

Yes, could be the solution, but I'm however a bit puzzled with doing this. The driver is originaly for NS LM70 component. Later on an extension has been added for TMP121 which is from a different family, even if compatible. Now we are talking about the LM74 which is in the same family as the original LM70. Therefore I would expect to be able to handle the LM74 directly from this driver, not through a tricky compatibility with the 'tmp121'. I would expect to handle it the other way round, ie consider the 'tmp121' as compatible with the LM74.
One of the reasons for that is that the driver reports the component ID through /sys/class/hwmon/hwmonX/name

As the 'tmp121' is already in the driver, it is not a good idea to replace it by LM74, however, I would prefer having the LM74 explicitly addressable by the driver, in additional to the 'tmp121'

Quoted 6 lines

I'm preparing a patch to include support for both LM71 and LM74 in the LM70 driver, in order to have a driver handling the complete family. Do you see a problem for that ? It would look strange that the LM70 driver handles LM70 and LM71, but LM74 through the compatible 'tmp121'

Ok, I'll accept that.

Quoted 3 lines

Nb, refer to your first answer, implementation for 'tmp122/124' is another story because those have a programmable precision, not a fixed one.

That isn't really a reason - we could just assume the highest precision, since the chip returns 0 in the lower bits if it is not configured for it. But then we can as well wait until someone asks for it, which will probably never happen. The more intersting aspect of the tmp122/124 is that it has limit registers, and supporting those would be more interesting anyway.

Thanks,
Guenter