All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lm75: add lm75b detection
@ 2019-10-26  8:10 Rain Wang
  2019-10-27 23:03 ` Guenter Roeck
  0 siblings, 1 reply; 7+ messages in thread
From: Rain Wang @ 2019-10-26  8:10 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck; +Cc: linux-kernel

The National Semiconductor LM75B is very similar as the
LM75A, but it has no ID byte register 7, and unused registers
return 0xff rather than the last read value like LM75A.

Signed-off-by: Rain Wang <rain_wang@jabil.com>
---
 drivers/hwmon/lm75.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 5e6392294c03..a718f9eb4d72 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -760,6 +760,7 @@ static int lm75_detect(struct i2c_client *new_client,
 	int i;
 	int conf, hyst, os;
 	bool is_lm75a = 0;
+	bool is_lm75b = 0;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
 				     I2C_FUNC_SMBUS_WORD_DATA))
@@ -780,8 +781,12 @@ static int lm75_detect(struct i2c_client *new_client,
 	 * register 7, and unused registers return 0xff rather than the
 	 * last read value.
 	 *
+	 * The National Semiconductor LM75B is very similar as the
+	 * LM75A, but it has no ID byte register 7, and unused registers 
+	 * return 0xff rather than the last read value like LM75A.
+	 *
 	 * Note that this function only detects the original National
-	 * Semiconductor LM75 and the LM75A. Clones from other vendors
+	 * Semiconductor LM75 and the LM75A/B. Clones from other vendors
 	 * aren't detected, on purpose, because they are typically never
 	 * found on PC hardware. They are found on embedded designs where
 	 * they can be instantiated explicitly so detection is not needed.
@@ -806,6 +811,13 @@ static int lm75_detect(struct i2c_client *new_client,
 		is_lm75a = 1;
 		hyst = i2c_smbus_read_byte_data(new_client, 2);
 		os = i2c_smbus_read_byte_data(new_client, 3);
+	} else if (i2c_smbus_read_byte_data(new_client, 4) == 0xff
+		 && i2c_smbus_read_byte_data(new_client, 5) == 0xff
+		 && i2c_smbus_read_byte_data(new_client, 6) == 0xff) {
+		/* LM75B detection */
+		is_lm75b = 1;
+		hyst = i2c_smbus_read_byte_data(new_client, 2);
+		os = i2c_smbus_read_byte_data(new_client, 3);
 	} else { /* Traditional style LM75 detection */
 		/* Unused addresses */
 		hyst = i2c_smbus_read_byte_data(new_client, 2);
@@ -839,7 +851,8 @@ static int lm75_detect(struct i2c_client *new_client,
 			return -ENODEV;
 	}
 
-	strlcpy(info->type, is_lm75a ? "lm75a" : "lm75", I2C_NAME_SIZE);
+	strlcpy(info->type, is_lm75a ? 
+		"lm75a" : (is_lm75b ? "lm75b" : "lm75"), I2C_NAME_SIZE);
 
 	return 0;
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread
* Re: [PATCH] lm75: add lm75b detection
@ 2019-10-28 11:28 Rain Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Rain Wang @ 2019-10-28 11:28 UTC (permalink / raw)
  To: Guenter Roeck, Jean Delvare; +Cc: linux-kernel

> I am quite hesitant to touch the detect function for this chip.
> Each addition increases the risk for false positives. What is the
> use case ?

we just have one board design of Intel Rangeley C2516 SoC with LM75B sensor.
only making the detection pass could we make the sensor working on standard
Linux distribution like Ubuntu.

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: [PATCH] lm75: add lm75b detection
@ 2019-10-28 11:37 Rain Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Rain Wang @ 2019-10-28 11:37 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Guenter Roeck, linux-kernel, linux-hwmon

> Please send hwmon-related patches to the linux-hwmon list.

Sure, will do in future.

> I'm positively certain I don't want this. Ideally there should be no
> detection at all for device without ID registers. The only reason there
> are some occurrences of that is because there were no way to explicitly
> instantiate I2C devices back then, and we have left the detection in
> place to avoid perceived regressions. But today there are plenty of
> ways to explicitly instantiate your I2C devices so there are no excuses
> for more crappy detect functions. Ideally we would even get rid of
> existing ones at some point in the future.

I understand the concern, but there could be scenarios device tree doesn't
apply while some dynamic detection is still a valid requirement, not sure
maybe I'm wrong from beginning.

> This patch is bad anyway as it only changes the device name without
> implementing proper support for the LM75B.

This is only change we made just have our Intel C1516 board with LM75B sensor
working anyway, while majority common features of LM75 just work.

Regards
Rain

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-07  6:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-26  8:10 [PATCH] lm75: add lm75b detection Rain Wang
2019-10-27 23:03 ` Guenter Roeck
2019-10-28  9:46   ` Jean Delvare
2019-10-29 14:02     ` Guenter Roeck
2019-11-07  6:18       ` Rain Wang
2019-10-28 11:28 Rain Wang
2019-10-28 11:37 Rain Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.