Skip to contentSkip to conversation

hwmon: (lm95241) Add support for LM95231

PATCH In review Guenter Roeck 2 participants 2 messages Jul 7, 2011 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (lm95241) Add support for LM95231

LM95231 is fully compatible to LM95241; only necessary change is to add chip detection.

---
 drivers/hwmon/lm95241.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)
drivers/hwmon/lm95241.c +19 -7
index d1bbdf8..94a8f3c 100644
@@ -75,7 +75,8 @@ static const unsigned short normal_i2c[] = {
 #define TT_ON 1
 #define TT_MASK 7
 #define MANUFACTURER_ID 0x01
-#define DEFAULT_REVISION 0xA4
+#define LM95231_CHIP_ID	0xA1
+#define LM95241_CHIP_ID	0xA4
 
 static const u8 lm95241_reg_address[] = {
 	LM95241_REG_R_LOCAL_TEMPH,
@@ -331,17 +332,27 @@ static int lm95241_detect(struct i2c_client *new_client,
 {
 	struct i2c_adapter *adapter = new_client->adapter;
 	const char *name;
+	int mfg_id;
+	int chip_id;
 
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -ENODEV;
 
-	if (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
-	    != MANUFACTURER_ID
-	    || i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
-	    != DEFAULT_REVISION)
+	mfg_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID);
+	if (mfg_id != MANUFACTURER_ID)
 		return -ENODEV;
 
-	name = DEVNAME;
+	chip_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID);
+	switch (chip_id) {
+	case LM95231_CHIP_ID:
+		name = "lm95231";
+		break;
+	case LM95241_CHIP_ID:
+		name = "lm95241";
+		break;
+	default:
+		return -ENODEV;
+	}
 
 	strlcpy(info->type, name, I2C_NAME_SIZE);
 	return 0;
@@ -418,7 +429,8 @@ static int lm95241_remove(struct i2c_client *client)
 
 /* Driver data (common to all clients) */
 static const struct i2c_device_id lm95241_id[] = {
-	{ DEVNAME, 0 },
+	{ "lm95231", 0 },
+	{ "lm95241", 0 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, lm95241_id);
Signature · 7 lines
1.7.3.1


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

LM95231 is fully compatible to LM95241; only necessary change is to add chip detection.

---
 drivers/hwmon/lm95241.c |   26 +++++++++++++++++++-------
 1 files changed, 19 insertions(+), 7 deletions(-)
drivers/hwmon/lm95241.c +2 -1
index d1bbdf8..94a8f3c 100644
@@ -75,7 +75,8 @@ static const unsigned short normal_i2c[] = {
 #define TT_ON 1
 #define TT_MASK 7
 #define MANUFACTURER_ID 0x01
-#define DEFAULT_REVISION 0xA4
+#define LM95231_CHIP_ID	0xA1
+#define LM95241_CHIP_ID	0xA4
 
 static const u8 lm95241_reg_address[] = {
 	LM95241_REG_R_LOCAL_TEMPH,

drivers/hwmon/lm95241.c static int lm95241_detect(struct i2c_client *new_client, · line 336

Quoted 5 lines
drivers/hwmon/lm95241.c +2 -0
@@ -331,17 +332,27 @@ static int lm95241_detect(struct i2c_client *new_client,
 {
 	struct i2c_adapter *adapter = new_client->adapter;
 	const char *name;
+	int mfg_id;
+	int chip_id;

Nitpicking: fits nicely on a single line.

Quoted 28 lines
drivers/hwmon/lm95241.c +13 -5
 	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
 		return -ENODEV;
 
-	if (i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID)
-	    != MANUFACTURER_ID
-	    || i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID)
-	    != DEFAULT_REVISION)
+	mfg_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_MAN_ID);
+	if (mfg_id != MANUFACTURER_ID)
 		return -ENODEV;
 
-	name = DEVNAME;
+	chip_id = i2c_smbus_read_byte_data(new_client, LM95241_REG_R_CHIP_ID);
+	switch (chip_id) {
+	case LM95231_CHIP_ID:
+		name = "lm95231";
+		break;
+	case LM95241_CHIP_ID:
+		name = "lm95241";
+		break;
+	default:
+		return -ENODEV;
+	}
 
 	strlcpy(info->type, name, I2C_NAME_SIZE);
 	return 0;

drivers/hwmon/lm95241.c static int lm95241_remove(struct i2c_client *client) · line 436

Quoted 9 lines
drivers/hwmon/lm95241.c +2 -1
@@ -418,7 +429,8 @@ static int lm95241_remove(struct i2c_client *client)
 
 /* Driver data (common to all clients) */
 static const struct i2c_device_id lm95241_id[] = {
-	{ DEVNAME, 0 },
+	{ "lm95231", 0 },
+	{ "lm95241", 0 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, lm95241_id);

Looks very good:

An update to drivers/hwmon/Kconfig would be welcome though.

Signature · 6 lines
Jean Delvare

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