Skip to contentSkip to conversation

lm75 with tmp101

PATCH Ben Dooks 2 participants 3 messages May 19, 2005

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

I've done some quick tests, and the tmp101 seems to be fine with the lm75 driver, using the following cmdline:

"lm75.force_lm75=-1,0x48"

Is there any way to pass the kind parameter of the probe call via this method?

Attached is a patch to add resolution to the sysfs, which read-only if we detect an lm75, and r/w if it is forced.

I could add a small bit of code to probe the presence of the resolution bits if the probe is forced. -------------- next part --------------

drivers/i2c/chips/lm75.c +51 -0
diff -urN -X ../dontdiff linux-2.6.11-rc4-bk8/drivers/i2c/chips/lm75.c linux-2.6.11-rc4-bk8-tmp101-v2/drivers/i2c/chips/lm75.c
@@ -43,6 +43,16 @@
 #define LM75_REG_TEMP_HYST	0x02
 #define LM75_REG_TEMP_OS	0x03
 
+/* resolution defines for extended systems */
+#define LM75_RESOLUTION_MASK	(3<<5)
+#define LM75_RESOLUTION_SHIFT	(5)
+#define LM75_RESOLUTION_BASE	(9)		/* 9..12 bits */
+#define LM75_RESOLUTION_9BIT	(0<<5)
+#define LM75_RESOLUTION_10BIT	(1<<5)
+#define LM75_RESOLUTION_11BIT	(2<<5)
+#define LM75_RESOLUTION_12BIT	(3<<5)
+
+
 /* Each client has this additional data */
 struct lm75_data {
 	struct i2c_client	client;
@@ -98,6 +108,43 @@
 set(temp_max, LM75_REG_TEMP_OS);
 set(temp_hyst, LM75_REG_TEMP_HYST);
 
+
+static ssize_t lm75_show_resolution(struct device *dev, char *buf)
+{
+ 	struct i2c_client *client = to_i2c_client(dev);
+	int value;
+
+	value = lm75_read_value(client, LM75_REG_CONF);
+	value &= LM75_RESOLUTION_MASK;
+	value >>= LM75_RESOLUTION_SHIFT;
+	value += 9;
+
+	return snprintf(buf, PAGE_SIZE, "%d\n", value);
+}
+
+static ssize_t lm75_set_resolution(struct device *dev, const char *buf,
+				   size_t count)
+{
+ 	struct i2c_client *client = to_i2c_client(dev);
+	int value = simple_strtoul(buf, NULL, 10);
+	int conf;
+
+	value -= LM75_RESOLUTION_BASE;
+
+	if (value < 0 || value > 3)
+		return -EINVAL;		/* out of range */
+
+	conf = lm75_read_value(client, LM75_REG_CONF);
+	conf &= ~LM75_RESOLUTION_MASK;
+	conf |= value << LM75_RESOLUTION_SHIFT;
+	lm75_write_value(client, LM75_REG_CONF, conf);
+
+	return count;
+}
+
+static DEVICE_ATTR(resolution, S_IWUSR | S_IRUGO,
+		   lm75_show_resolution, lm75_set_resolution);
+
 static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max);
 static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_temp_hyst, set_temp_hyst);
 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL);
@@ -189,6 +236,8 @@
 	/* Determine the chip type - only one kind supported! */
 	if (kind <= 0)
 		kind = lm75;
+	else if (kind != lm75)
+		dev_attr_resolution.attr.mode |= S_IWUSR;
 
 	if (kind = lm75) {
 		name = "lm75";
@@ -213,6 +262,8 @@
 	device_create_file(&new_client->dev, &dev_attr_temp1_max_hyst);
 	device_create_file(&new_client->dev, &dev_attr_temp1_input);
 
+	device_create_file(&new_client->dev, &dev_attr_resolution);
+
 	return 0;
 
 exit_free:
author
#1 lore raw
Quoted 14 lines · Jean Delvare

Hi Ben,

Quoted 4 lines

I've done some quick tests, and the tmp101 seems to be fine with the lm75 driver, using the following cmdline:

"lm75.force_lm75=-1,0x48"

I didn't know that syntax, I guess this comes from the "new" module_param stuff? Good thing to know, thanks for pointing out.

Anyway, this at least proves that the TMP101 is LM75-compatible as Mark and I thought.

Quoted 6 lines
Quoted 2 lines

Is there any way to pass the kind parameter of the probe call via this method?

This is exactly what you did. The force_lm75 parameter sets the "kind" to lm75. force (without _lm75) would set the "kind" to 0 insead - which currently makes no difference for the lm75 driver.

thanks, it isn't entirely obvious what is going on.

Quoted 5 lines
Quoted 2 lines

Attached is a patch to add resolution to the sysfs, which read-only if we detect an lm75, and r/w if it is forced.

I doubt it really does that. Quoting your code:

Quoted 10 lines

drivers/i2c/chips/lm75.c line 240

Quoted 7 lines
drivers/i2c/chips/lm75.c +4 -0
+static DEVICE_ATTR(resolution, S_IWUSR | S_IRUGO,
+		   lm75_show_resolution, lm75_set_resolution);
(...)
 	if (kind <= 0)
 		kind = lm75;
+	else if (kind != lm75)
+		dev_attr_resolution.attr.mode |= S_IWUSR;

So in the first place the file is r/w, then you conditionally add the write permission - without any effect, needless to say.

It _should_ have been read-only by default

Quoted 22 lines

Also note that this last line is actually never run - the first test copes with kind = -1 and kind = 0, and the only case left (kind = lm75) is explicitely excluded by the second test.

In short, that part of your patch is severly broken ;)

Quoted 2 lines

I could add a small bit of code to probe the presence of the resolution bits if the probe is forced.

I don't get what you mean here, but since your patch didn't seem to really reflect what you had in mind, it's not all that surprising.

Your patch is broken in several other respects, namely:
1* It creates the resolution file for any LM75-compatible chip, while most don't support resolution change. It will be fine (providing the file is read-only) for the LM75 itself because theses configuration bits are 0, so the resolution will properly be displayed as 9. However, I think that some compatible chips - there is a long list - may use these bits for something different. Did you check?
2* You do not make any use of the additional resolution bits. The current lm75 code will strip them. So what's the point?

Quoted 6 lines

I do not think that the benefit of the additional resolution is worth the effort. The TMP101 part is given with a 2 degrees accuracy, so a resolution of 0.5 degree seems to be just fine. I doubt we really need anything more precise than that in computer equipement. (When we have additional resolution at no cost, I'm all for it, but in this special case the cost exists and seems a bit high to me.)

Ok, will ignore this for the moment.

Quoted 7 lines

What might be more useful to work on would be a TMP101 detection algorithm so that the chip is properly detected without the need of a force parameter. I can help you achieve that if you provide the output of i2cdump (in word mode) for your chip. The command would be "i2cdump <n> 0x48 w" where <n> is the number of the i2c bus the chip sits on. i2cdetect can help you find which bus number it is. You'll need to load i2c-dev before running both commands.

I think i've got something which will work, i'll post a patch once i've tidied up the patch

Signature · 3 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'
#2 lore raw
In reply to Ben Dooks

Hi Ben,

Quoted 4 lines

I've done some quick tests, and the tmp101 seems to be fine with the lm75 driver, using the following cmdline:

"lm75.force_lm75=-1,0x48"

I didn't know that syntax, I guess this comes from the "new" module_param stuff? Good thing to know, thanks for pointing out.

Anyway, this at least proves that the TMP101 is LM75-compatible as Mark and I thought.

Quoted 2 lines

Is there any way to pass the kind parameter of the probe call via this method?

This is exactly what you did. The force_lm75 parameter sets the "kind" to lm75. force (without _lm75) would set the "kind" to 0 insead - which currently makes no difference for the lm75 driver.

Quoted 2 lines

Attached is a patch to add resolution to the sysfs, which read-only if we detect an lm75, and r/w if it is forced.

I doubt it really does that. Quoting your code:

drivers/i2c/chips/lm75.c line 240

Quoted 7 lines
drivers/i2c/chips/lm75.c +4 -0
+static DEVICE_ATTR(resolution, S_IWUSR | S_IRUGO,
+		   lm75_show_resolution, lm75_set_resolution);
(...)
 	if (kind <= 0)
 		kind = lm75;
+	else if (kind != lm75)
+		dev_attr_resolution.attr.mode |= S_IWUSR;

So in the first place the file is r/w, then you conditionally add the write permission - without any effect, needless to say.

Also note that this last line is actually never run - the first test copes with kind = -1 and kind = 0, and the only case left (kind = lm75) is explicitely excluded by the second test.

In short, that part of your patch is severly broken ;)

Quoted 2 lines

I could add a small bit of code to probe the presence of the resolution bits if the probe is forced.

I don't get what you mean here, but since your patch didn't seem to really reflect what you had in mind, it's not all that surprising.

Your patch is broken in several other respects, namely:
1* It creates the resolution file for any LM75-compatible chip, while most don't support resolution change. It will be fine (providing the file is read-only) for the LM75 itself because theses configuration bits are 0, so the resolution will properly be displayed as 9. However, I think that some compatible chips - there is a long list - may use these bits for something different. Did you check?
2* You do not make any use of the additional resolution bits. The current lm75 code will strip them. So what's the point?

I do not think that the benefit of the additional resolution is worth the effort. The TMP101 part is given with a 2 degrees accuracy, so a resolution of 0.5 degree seems to be just fine. I doubt we really need anything more precise than that in computer equipement. (When we have additional resolution at no cost, I'm all for it, but in this special case the cost exists and seems a bit high to me.)

What might be more useful to work on would be a TMP101 detection algorithm so that the chip is properly detected without the need of a force parameter. I can help you achieve that if you provide the output of i2cdump (in word mode) for your chip. The command would be "i2cdump <n> 0x48 w" where <n> is the number of the i2c bus the chip sits on. i2cdetect can help you find which bus number it is. You'll need to load i2c-dev before running both commands.

Thanks,
--
Jean Delvare