Skip to contentSkip to conversation

New driver for MAX663x temperature sensor.

DISCUSSION Evgeniy Polyakov 2 participants 19 messages May 19, 2005

lore
Share & tools
lore
#1 lore raw
Quoted 6 lines

Patch against 2.4 kernel.
Simple temperature sensor chip.
Implemented read temperature and write low/high values. Tested on UP ppc32.

Please review and commit.

We don't take patches for the 2.4 kernel. Marcelo doesn't want i2c patches from us anymore.

Either go and see with Marcelo directly (good luck) or submit your driver as a patch against our CVS lm_sensors2 repository.

A few comments BTW:

First of all: which MAX663x chips is the driver for? MAX6629-MAX6632 are non-I2C chips according to Maxim-IC, so I guess it's MAX6633-MAX6635?

You better name your driver max6633.c (or max6634.c, since that's the chip I suspect you are actually working with) then. We don't much like "x" in the driver names, they tend to be confusing (you may know which values of "x" it implies, but the newcomer doesn't). And list the supported chips in the header. See w83781d.c for a nice example.

Quoted 2 lines

+ * The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
+ * system and in the file COPYING in the Linux kernel source.

This doesn't belong to kernel code IMHO.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static struct i2c_driver max663x_driver = {
+	.name		= "max663x",
+	.flags		= I2C_DF_NOTIFY,
+	.id		= 1234,

No. Just don't give it an ID if you don't need one.

Review

Quoted 5 lines
(quoted diff) +5 -0
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
+	{
+		printk(KERN_ERR "Adapter doesn't support functionality.\n");
+		goto error1;
+	}

That's not an error. As you load an i2c chip driver, all adapters will be scanned. This may include adapters that don't support these functionalities (and so they just can't have a MAX6633 on them). I wouldn't even print a message.

Review

Quoted 1 line
(quoted diff) +1 -0
+	new_client->id		= 123;

No. The other drivers have a global, static variable for that. Just do the same.

I notice that your driver has no detection mechanism at all. I agree that the MAX6634 doesn't look like a chip that want to be identified (no manufacturer ID registers, no chip ID register, no die/revision registers...) but there is a common trick of checking for unused bits, which always return 0. There are two of them in the configuration register, and 7 more in each temperature limit register. 30 zero bits verified is far better than no check at all.

Also, since it seems that the address pointer registers only has 3 used bits, I would expect values to cycle every 8 registers. See lm75.c as an example. Could you please provide an i2cdump of the chip for confirmation (both byte and word modes)? I would then add support for the MAX6633/4/5 and LM76 (which seems to be compatible, but has different unused bits) to our sensors-detect script.

Review

Quoted 1 line
(quoted diff) +1 -0
+	__max663x_temp((unsigned long)new_client);

The function that reads values is usually called update. If is also supposed to cache the read data for a reasonable amount of time (typically 1.5 second) and it has a protecting lock. And it is usually not called at load time (although I admit we are reconsidering in some cases at the moment).

Review

Quoted 1 line
(quoted diff) +1 -0
+	printk("Found max663x I2C temperature sensor.\n");

KERN_INFO or KERN_DEBUG missing.

Quoted 24 lines
(quoted diff) +24 -0
+static inline int reg2temp(uint16_t temp)
+{
+	if (temp & 0x8000)
+	{
+		return (255 - (temp >> 7));
+	}
+	else
+	{
+		return (temp >> 7);
+	}
+}
+
+static inline uint16_t temp2reg(int temp)
+{
+	uint16_t reg;
+	
+	if (temp > 255)
+		temp = 255;
+	if (temp < -255)
+		temp = -255;
+	
+	if (temp < 0)
+	{
+		reg = temp + 255;

Review

Quoted 10 lines
(quoted diff) +10 -0
+		reg <<= 7;
+		reg |= 0x8000;
+	}
+	else
+	{
+		reg = (temp << 7);
+	}
+
+	return reg;
+}

These are usually defined as macros at the top of the file, with nice names. See exiting drivers for examples of what we expect you to do. It is important that all drivers follow a few common guidelines so that maintaining the whole thing (49 chip drivers so far!) is possible.

Quoted 19 lines
(quoted diff) +19 -0
+void max663x_temp(struct i2c_client *client, int operation, int ctl_name, int *nrels_mag, long *results)
+{
+	struct max663x_data *data = client->data;
+
+	if (operation = SENSORS_PROC_REAL_INFO)
+		*nrels_mag = 1;
+	else if (operation = SENSORS_PROC_REAL_READ) 
+	{
+		__max663x_temp((unsigned long)client);
+
+		results[0] = reg2temp(data->temp_max);
+		results[1] = reg2temp(data->temp_hyst);
+		results[2] = reg2temp(data->temp);
+		*nrels_mag = 3;
+	} 
+	else if (operation = SENSORS_PROC_REAL_WRITE) 
+	{
+		if (*nrels_mag >= 1) 
+		{

Review

Quoted 10 lines
(quoted diff) +10 -0
+			data->temp_max = temp2reg(results[0]);
+			i2c_smbus_write_word_data(client, MAX663x_HIGH, swap_bytes(data->temp_high));
+		}
+		if (*nrels_mag >= 2) 
+		{
+			data->temp_max = temp2reg(results[1]);
+			i2c_smbus_write_word_data(client, MAX663x_LOW, swap_bytes(data->temp_low));
+		}
+	}
+}

That's odd. Writing to the file doesn't set the same limits as the ones returned when reading the files. Confusing to say the least. And this also means that some limits cannot be read (low, high), and others cannot be set (max, hyst)? Oh well, the write part of your function, is plain broken anyway.

Either have a 5-value file and put everything in it (the lm80 and lm92 drivers do that, you would follow the order of lm92 (although the rest of the driver is *not* a good example for you to follow)) or put, say, max and hyst current value in the "temp" file and have one or two other files for high and low.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static void __exit max663x_fini(void)
+{
+	i2c_del_driver(&max663x_driver);
+}

Nice to see a french word in kernel code, still _exit is the common suffix for that function.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#2 lore raw
In reply to Evgeniy Polyakov

Answering to myself:

Quoted 2 lines

You better name your driver max6633.c (or max6634.c, since that's the chip I suspect you are actually working with) then.

Actually max6635 would probably be better, since the max6635 is obviously a lm76-clone, and the 6634 and 6633 are cut-down versions of these.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#5 lore raw
In reply to Evgeniy Polyakov
Quoted 2 lines

I don't insist on particular name, this was just for clarification. Will rename it into max6635.c

Fine, thanks :)

Quoted 5 lines
Quoted 3 lines

I don't say that you should skip the test. Just don't make it an error, i.e. exit in silence.
(...)

Ok, I have removed this error path, only warning.

No! Read what I just said. Do not ignore the fact that functionalities are missing, since it'll break later then. But do not return an error code and message either, because it isn't necessarily an error (due to the fact that each chip driver is possibly called for each bus on the system, and a given bus does not have to support functionalities that are used by chips on the other busses). So the correct code would be:

if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA))
{
printk(KERN_DEBUG "max6635.o: Adapter doesn't support needed

functionalities.\n");
    return 0;
}

BTW it's a common habit to prefix error/debug messages with the module name, as I did above. I just noticed that you didn't follow it in your driver.

Quoted 4 lines
Quoted 2 lines

Will you be able to run sensors-detect to test my detection function on your samples?

Nope. It doesn't have any kind of scripting languages.

OK, I guess I won't add support to sensors-detect at all then.

BTW, what is your system after all? I'm quite surprised to see a MAX6635
in a modern system, it looks like a rather "old" chip (designed 3 years ago). The level of support we want to add to our userspace tools (sensors-detect, libsensors, sensors) mainly depends on how likely it is that other users will have such a device on a system them just bought. So far the LM76 was listed as "unlikely to be found in a PC".

Quoted 26 lines

00: 0004 0005 0002 0003 <- registers

00: 000f 0014 000a 0005
08: 0000 0000 0000 0000
10: 000f 0014 000a 0005
18: 0000 0000 0000 0000
20: 000f 0014 000a 0005
28: 0000 0000 0000 0000
30: 000f 0014 000a 0005
38: 0000 0000 0000 0000
40: 000f 0014 000a 0005
48: 0000 0000 0000 0000
50: 000f 0014 000a 0005
58: 0000 0000 0000 0000
60: 000f 0014 000a 0005
68: 0000 0000 0000 0000
70: 000f 0014 000a 0005
78: 0000 0000 0000 0000
80: 0000 0000 0000 0000
88: 0000 0000 0000 0000
90: 0000 0000 0000 0000
98: 0000 0000 0000 0000
a0: 0000 0000 0000 0000
a8: 0000 0000 0000 0000
b0: 0000 0000 0000 0000
b8: 0000 0000 0000 0000

Quoted 8 lines

c0: 0000 0000 0000 0000
c8: 0000 0000 0000 0000
d0: 0000 0000 0000 0000
d8: 0000 0000 0000 0000
e0: 0000 0000 0000 0000
e8: 0000 0000 0000 0000
f0: 0000 0000 0000 0000
f8: 0000 0000 0000 0000

Which would tend to prove that the pointer register has actually 4 used bits. Or even 5 if we consider the second half of the dump. That's a bit surprising, I admit. Still this is enough to improve the chip's detection function.

Quoted 3 lines

Chip uses two's-complement format with 1LSB corresponding to 0.0625 and 1MSB as sign.
So with this conversation we lose ~0.5 degree.

OK, granted it's acceptable.

Quoted 2 lines

I just don't know how this accuracy should be presented in current i2c /proc processing.

You are free to use whatever magnitude you want for exporting values through procfs. The magnitude is what the callback function answers when called with operation = SENSORS_PROC_REAL_INFO. If you want improved accuracy, you can use magnitude of 2, and then export, for example, value 2481 (instead of 248 now) for a measured temperature of 24.8125.

I agree it doesn't matter much what you decide, reporting temperature with two decimal places isn't that interesting anyway.

Quoted 6 lines
Quoted 2 lines

You don't need swap_bytes here, if would be faster without it, don't you think?

It is called only once in load time, and main idea was to store this values as cache if they are valid. I think it should be implemented in this way, or not?

We usually do not, although I admit we could. Still, it only makes sense if you read *all* the values so that caching is possible. About this, I noticed that you don't properly protect your update function. See in other chip drivers how this is done. You are supposed to cache the read data for a given amount of time, and there's also a flag that says whether the values are OK or not (basically clear at driver load time, and set as soon as the update was called once).

If you want to fill the cache as soon as you start the driver, then you should simply call the update function and use the "returned" values for detection. Else you're basically coding the same function twice.

Oh BTW, you don't seem to use the 4-bit address cycle trick I mentioned before in your detection function yet. Please do.

And two more comments:

You can use the kernel function swab16() instead of your own swap_bytes function. I'm going to fix the othe drivers in the same way.

Review

Quoted 2 lines
(quoted diff) +1 -1
-MODULE_DESCRIPTION("MAX663x temerature sensor");
+MODULE_DESCRIPTION("MAX663{5,4,3} temerature sensor");

This is actually the only place where 'x' is accepted, I forgot to tell you ;)

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#6 lore raw
In reply to Evgeniy Polyakov

Hm, just noticed...

Looks like the LM76 is 100% compatible with the LM92, and we have a driver for the LM92 (lm92.c). Since the MAX6635 is obviously a clone of the LM76, it should fit well in the lm92 driver as well.

I admit that the lm92 driver isn't our best driver, there are several places where it does the things in a very different way when compared with the other drivers. Still it would be much better to extend and fix this existing driver that to duplicate the exact same functionality in a different driver.

Since the LM92 has a manufacturer ID register, you can use that to distinguish it from Maxim's clones. Also, I noticed that the five chips (LM76, LM92, MAX6633, MAX6634 and MAX6635) have different address ranges. That's something you can use to distinguish between the four of them that do not have a manufacturer's ID register (although it will of course not be perfect). You would also add the 4-bit cycle trick as mentioned in an earlier, and the unused bits in the temperature limits registers. The lm92.c driver has a very simple detection function at the moment because it could rely on the manufacturer's ID. Now that you can't, you have to use all the tricks we've discussed before.

You are welcome to clean whatever you fell like cleaning in the lm92.c driver, I don't like it much (although it's definitely better than no driver at all, I don't intend to denigrate Abraham's work, it's just that it is different from the other drivers, which makes it harder to maintain).

Sorry for not checking before, that would have saved us much time and work :/

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#8 lore raw
In reply to Evgeniy Polyakov
Quoted 3 lines
Quoted 3 lines

You can use the kernel function swab16() instead of your own swap_bytes function. I'm going to fix the othe drivers in the same way.

I see you used __swab16. I think you can (and should) use swab16 instead.

Quoted 2 lines

Reading "manufacturer" register from MAX663x here shows "0x0014". I don't know if this value may change.

I think it shows either the same value as register 0x05 does, or the value of the latest register that was read. It probably doesn't have a value per se (since there is in fact no register).

That's something that can be used for detection purposes too (once you will have confirmed which of the two behaviors it has) although I admit it's kind of tricky.

Quoted 6 lines
Quoted 3 lines

(LM76, LM92, MAX6633, MAX6634 and MAX6635) have different address ranges. That's something you can use to distinguish between the four of

It doesn't help very much - all of them may have 0x48 address for example. But it is something...

I know that the addresses overlap, it's a hint at best.

That said, we don't really care which chip it really is, since they are mostly compatible. It's more a convenience for the user (so that he knows which chip he/she has).

Maybe we can also use the missing registers of the MAX6634 and MAX6633 (same as the missing manufacturer id register) to refine the detection.

BTW, which chips do you have exactly?

Quoted 2 lines

I can just copy max663x detection path into lm92.c and turn it on when manufacturer id doesn't correspond needed one for lm92.

Yes, that's what I mean. The condition to be detected as a supported chip would be to either have the lm92 manufacturer's ID, or pass the tests we have defined. BTW we can make similar tests on the lm92 to prevent misdetection.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#9 lore raw
In reply to Evgeniy Polyakov
Quoted 6 lines · Jean Delvare
Quoted 3 lines
Quoted 3 lines

You can use the kernel function swab16() instead of your own swap_bytes function. I'm going to fix the othe drivers in the same way.

I see you used __swab16. I think you can (and should) use swab16 instead.

Replaced, although they are the same for kernel space.

Quoted 24 lines
Quoted 2 lines

Reading "manufacturer" register from MAX663x here shows "0x0014". I don't know if this value may change.

I think it shows either the same value as register 0x05 does, or the value of the latest register that was read. It probably doesn't have a value per se (since there is in fact no register).

That's something that can be used for detection purposes too (once you will have confirmed which of the two behaviors it has) although I admit it's kind of tricky.

Quoted 6 lines
Quoted 3 lines

(LM76, LM92, MAX6633, MAX6634 and MAX6635) have different address ranges. That's something you can use to distinguish between the four of

It doesn't help very much - all of them may have 0x48 address for example. But it is something...

I know that the addresses overlap, it's a hint at best.

That said, we don't really care which chip it really is, since they are mostly compatible. It's more a convenience for the user (so that he knows which chip he/she has).

Quoted 5 lines

Maybe we can also use the missing registers of the MAX6634 and MAX6633 (same as the missing manufacturer id register) to refine the detection.

BTW, which chips do you have exactly?

Only MAX6634.

Quoted 7 lines
Quoted 2 lines

I can just copy max663x detection path into lm92.c and turn it on when manufacturer id doesn't correspond needed one for lm92.

Yes, that's what I mean. The condition to be detected as a supported chip would be to either have the lm92 manufacturer's ID, or pass the tests we have defined. BTW we can make similar tests on the lm92 to prevent misdetection.

Patch attached.
Tested. Works.

Quoted 1 line

Thanks.

Signature · 10 lines
	Evgeniy Polaykov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040413/bc206c79/attachment.bin
#10 lore raw
In reply to Evgeniy Polyakov
Quoted 5 lines
Quoted 2 lines

Either go and see with Marcelo directly (good luck) or submit your driver as a patch against our CVS lm_sensors2 repository.

Will do when all technical questions will be resolved. I don't think sending it to Marcelo has any sense.

Agreed.

Quoted 6 lines
Quoted 3 lines

First of all: which MAX663x chips is the driver for? MAX6629-MAX6632 are non-I2C chips according to Maxim-IC, so I guess it's MAX6633-MAX6635?

MAX663x = any max663*. Maxim-IC produces only MAX6633-MAX6635 devices matching this regexp.

You did not read me carefully. There's a MAX6629-MAX6632 family:
http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2577/ln/en
Same kind of chips, different interface.

Which is why I think it's important to clearly state which chips you are supporting, like you did.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+ * The GNU GPL is contained in /usr/doc/copyright/GPL on a Debian
+ * system and in the file COPYING in the Linux kernel source.

This doesn't belong to kernel code IMHO.

It does.

Let me rephrase then. The kernel code is kernel code ;) It doesn't depend on a distribution.

The usual GPL disclaimer in front of the file is OK, it's even required. But your additional "pointer" to the file, especially for a specific distribution, doesn't make sense and won't be accepted. Remember that your driver will be part of the lm_sensors project (BTW you header should mention that, see the other drivers) so neither Debian's /usr/doc/copyright/GPL not "the file COPYING in the Linux kernel source" are part of the package. The COPYING file is part of the lm_sensors package and people pretty well know where it is.

Quoted 11 lines
Quoted 10 lines

Review

Quoted 5 lines
(quoted diff) +1 -0
+	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |

I2C_FUNC_SMBUS_WORD_DATA))+ {

(quoted diff) +3 -0
+		printk(KERN_ERR "Adapter doesn't support functionality.\n");
+		goto error1;
+	}

That's not an error. As you load an i2c chip driver, all adapters will be scanned. This may include adapters that don't support these functionalities (and so they just can't have a MAX6633 on them). I wouldn't even print a message.

Quoted 5 lines

What about situation when chip is connected to unsupported adapter or adapter which doesn't provide needed functionality?
Any reading/writing will confuse bus and reader/writer.
I think chip should not work if it is not connected to the right adapter.

I don't say that you should skip the test. Just don't make it an error, i.e. exit in silence.

The case where the chip is connected to an unsupported (I would say unsupporting) adapter is a hardware design issue, we are not supposed to handle that. If you really want to warn the user about it, it has to be a debug message.

Quoted 11 lines
Quoted 7 lines

I notice that your driver has no detection mechanism at all. I agree that the MAX6634 doesn't look like a chip that want to be identified (no manufacturer ID registers, no chip ID register, no die/revision registers...) but there is a common trick of checking for unused bits, which always return 0. There are two of them in the configuration register, and 7 more in each temperature limit register. 30 zero bits verified is far better than no check at all.

One may not rely on control register.
One of MAX663xes here has 1 in it's "reserved" field but working absolutely right.

Oh, OK. Unusual. This is why having physical samples when programming a driver is very, very helpful.

Quoted 2 lines

I have done "identification" based on reserved bits in MAX, LOW, HIGH and HYST registers.

OK, fine.

Quoted 23 lines
Quoted 6 lines

Also, since it seems that the address pointer registers only has 3 used bits, I would expect values to cycle every 8 registers. See lm75.c as an example. Could you please provide an i2cdump of the chip for confirmation (both byte and word modes)? I would then add support for the MAX6633/4/5 and LM76 (which seems to be compatible, but has different unused bits) to our sensors-detect script.

No, I can't.

ls /dev/i2c/
-------------- dir /dev/i2c/ ----------
0 .. .
MSG[14]:ls /dev/i2c/

/bin/i2cdump 0 0x4f b
New process started PID
file: /bin/i2cdump
MSG[23]:/bin/i2cdumpfile: /bin/i2cdump
WARNING! This program can confuse your I2C bus, cause data loss and
worse!
I will probe file /dev/i2c/0, address 0x4f, mode byte You have five seconds to reconsider and press CTRL-C!

Quoted 8 lines

ls /proc/13/
scandir("/proc/13/")No such file or directory
MSG[14]:ls /proc/13/

Without explicit fflush() one can't read output just after error with our embedded init.
Or may be i2cdump doesn't like big endian ppc32 and cross-compilation. Don't know where exit happens in i2cdump.

Oh, OK. That's a special system you have here. I guess you also don't intend to use sensors/libsensors, but only read/write the values through procfs?

Will you be able to run sensors-detect to test my detection function on your samples?

I would like you to test the 8-registers cycling in the driver itself. In your detection function, just read limits registers + 8 and see if you read the same four values. If can even be better to do that 32 times, to test the whole range. That's always interesting to ensure that you are probing the right chip like that, especially when there's no identification dedicated registers. See lm75.c for an example.

Quoted 4 lines

Actually there is race here, since update may only happen in process context but any userspace reading is not protected.
Now update_lock is using for protecting max663x_data when writing into it.

You're right, our drivers suffer from a race condition (although in most cases it works fine). We're thinking of a solutions, just need some more time to implement it.

Quoted 3 lines

now one can read 5 values and write 4 values:

read:   max, hyst, low, high, temp
write:  max, hyst, low, high.

OK, fine with me.

Quoted 3 lines

Please review and comment.
If all design and technical issues are resloved I will make a patch against lm_sensors tree.

A few more things:

Review

Quoted 2 lines
(quoted diff) +2 -0
+#define reg2temp(temp) ((temp & 0x8000)?(255 - (temp >> 7)):(temp >> 7))
+#define temp2reg(temp) ((temp < 0)?(((temp + 255) << 7) | 0x8000):(temp << 7))

These conversion functions look broken for negative temperatures, please check it. And even for positive ones, the ">> 7" looks like you are working with 9-bit values, while the chip is supposed to handle 12-bit ones (or even 13 with the sign?).

Likewise, I'm surprised by the fact that you export the values to userspace with a single decimal place. If I'm correct and you have 5 bits for the non-integer part, you're losing a significant part of this resolution when doing that.

Review

Quoted 6 lines
(quoted diff) +6 -0
+	temp_low 	= swap_bytes(i2c_smbus_read_word_data(client, MAX663x_LOW));
+	temp_high	= swap_bytes(i2c_smbus_read_word_data(client, MAX663x_HIGH));
+	temp_hyst	= swap_bytes(i2c_smbus_read_word_data(client, MAX663x_HYST));
+	temp_max	= swap_bytes(i2c_smbus_read_word_data(client, MAX663x_MAX));
+
+	return (!(temp_low & 0x7f) && !(temp_high & 0x7f) && !(temp_hyst & 0x7f) && !(temp_max & 0x7f));

You don't need swap_bytes here, if would be faster without it, don't you think?

Review

Quoted 3 lines

error3:

(quoted diff) +1 -0
+	max663x_id--;
 	kfree(new_client);

Interesting. None of our drivers do that. Not a big issue though.

And, again, please mass-rename max663x to max6635 (or any other). We don't like 'x' in the driver names, function names, constant names, etc.

Thanks.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#12 lore raw
In reply to Evgeniy Polyakov
Quoted 2 lines

Yep.
Attached.

-EDOESNTAPPLY

Please checkout the latest CVS version of the file and provide a patch that applies against that.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#13 lore raw
In reply to Evgeniy Polyakov
Quoted 1 line

Done.

My comments inline:

Quoted 10 lines
(quoted diff) +1 -1
@@ -126,7 +126,7 @@
 	if (tmp < 0) return (-EIO);
 
 	/* convert the data to little endian format */
-	*value = swab16((u16) tmp);
+	*value = ((u16) tmp >> 8) | (u16) ((u16) tmp << 8);
 
 	return (0);
 }

Review line 139

Quoted 10 lines
(quoted diff) +2 -4
@@ -134,10 +134,8 @@
 static inline int lm92_write16 (struct i2c_client *client,u8 reg,u16 value)
 {
 	/* convert the data to big endian format */
-	if (i2c_smbus_write_word_data(client, reg, swab16(value)) < 0)
-		return -EIO;
-
-	return 0;
+	u16 be = (value >> 8) | (u16) (value << 8);
+	return (i2c_smbus_write_word_data (client,reg,be) < 0 ? -EIO : 0);
 }

These are two changes I just commited to the CVS repository. Please don't revert them.

Review

Quoted 4 lines
(quoted diff) +4 -0
+static int max6635_check(struct i2c_client *client)
+{
+	lm92_t *data = (lm92_t *) client->data;
+	int i, cn = 8;

I hardly can see any reason to define cn as a variable.

Review

Quoted 9 lines
(quoted diff) +9 -0
+	u16 temp_low, temp_high, temp_hyst, temp_max;
+
+	temp_low 	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW);
+	temp_high	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH);
+	temp_hyst	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS);
+	temp_max	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL);
+	
+	if (!(!(temp_low & 0x7f00) && !(temp_high & 0x7f00) && !(temp_hyst & 0x7f00) && !(temp_max & 0x7f00)))
+		return 0;

You can spare negations by just using ||'s instead of &&'s (De Morgan's law, http://en.wikipedia.org/wiki/De_Morgan's_law).

Review

Quoted 1 line
(quoted diff) +1 -0
+	for (i=0; i<32; ++i)

You can skip i=0, it cannot fail.

Quoted 6 lines
(quoted diff) +6 -0
+	{
+		if ((i % 2 = 0) && (i < 16))
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != temp_low) ||
+				(temp_high != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(temp_hyst != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||

Review

Quoted 10 lines
(quoted diff) +10 -0
+				(temp_max != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;
+		}
+		else
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != 0) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;

I don't think you can rely of these zeroes. Maybe other chips would return random values or the limits.

I would simply do "for (i=2; i<16; i+=2)" (or even "for (i=1; i<8; ++i)" with cn) and discard that second test.

Review

Quoted 5 lines
(quoted diff) +5 -0
+	data->temp.low 	= swab16(temp_low);
+	data->temp.high = swab16(temp_high);
+	data->temp.crit	= swab16(temp_max);
+	data->temp.hyst = swab16(temp_hyst);
+	data->temp.low 	= swab16(i2c_smbus_read_word_data(client, LM92_REG_TEMPERATURE));

Bug here.

Anyway I don't see the point in filling the variables since you don't update data->timestamp accordingly (so everything will be read again anyway). And you cannot update data->timestamp if you don't read the alarms too. All in all you would have to duplicate lm92_read here. So either don't store the values at all (recommended) or call lm92_read instead or rewriting it.

Quoted 24 lines
(quoted diff) +6 -8
@@ -294,20 +335,25 @@
 		return (-ERESTARTSYS);
 	}
 
-	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
-		manufacturer != LM92_MANUFACTURER_ID) {
-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
-	}
-
 	if ((result = i2c_attach_client (client))) {
 		kfree (client);
 		up (&mutex);
 		return (result);
 	}
 
-	if ((result = i2c_register_entry (client,client->name,lm92_dir_table)) < 0) {
+	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
+		manufacturer != LM92_MANUFACTURER_ID) {
+
+		if (!max6635_check(client))
+		{
+			i2c_detach_client (client);

Review line 359

Quoted 10 lines
(quoted diff) +7 -0
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
+	}
+
+	if ((result = i2c_register_entry (client,client->name,lm92_dir_table, THIS_MODULE)) < 0) {
 		i2c_detach_client (client);
 		kfree (client);
 		up (&mutex);

Why did you move swapped the detection and the client attachement? Detecting before we attempt to attach the client is actually the correct order.

The additional parameter to i2c_register_entry breaks compilation. I suspect that you use an outdated version of i2c. Get at least version 2.8.2.

Review

Quoted 7 lines

static struct i2c_driver lm92_driver = {

(quoted diff) +0 -2
-	.owner		= THIS_MODULE,
 	.name		= "lm92",
-	.id		= I2C_DRIVERID_LM92,
 	.flags		= I2C_DF_NOTIFY,
 	.attach_adapter	= lm92_attach_adapter,
 	.detach_client	= lm92_detach_client,

No, don't do that.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#14 lore raw
In reply to Evgeniy Polyakov
Quoted 4 lines · On Tue, 13 Apr 2004 20:02:42 +0200 Jean Delvare <[email protected]> wrote:
Quoted 2 lines

Patch attached.
Tested. Works.

-ENOPATCH

Yep.
Attached.

Quoted 3 lines
Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------

chips/lm92.c renamed from chips/lm92.c.orig +15 -11
@@ -28,6 +28,7 @@
 #include <linux/proc_fs.h>
 #include <linux/sysctl.h>
 #include <asm/semaphore.h>
+#include "version.h"
 
 /* if defined, 4 faults must occur consecutively to set alarm flags */
 /* #define ENABLE_FAULT_QUEUE */
@@ -266,7 +267,7 @@
 	data->temp.high = swab16(temp_high);
 	data->temp.crit	= swab16(temp_max);
 	data->temp.hyst = swab16(temp_hyst);
-	data->temp.low 	= swab16(i2c_smbus_read_word_data(client, MAX6635_TEMP));
+	data->temp.low 	= swab16(i2c_smbus_read_word_data(client, LM92_REG_TEMPERATURE));
 
 	return 1;
 }
@@ -334,20 +335,25 @@
 		return (-ERESTARTSYS);
 	}
 
-	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
-		manufacturer != LM92_MANUFACTURER_ID) {
-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
-	}
-
 	if ((result = i2c_attach_client (client))) {
 		kfree (client);
 		up (&mutex);
 		return (result);
 	}
 
-	if ((result = i2c_register_entry (client,client->name,lm92_dir_table)) < 0) {
+	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
+		manufacturer != LM92_MANUFACTURER_ID) {
+
+		if (!max6635_check(client))
+		{
+			i2c_detach_client (client);
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
+	}
+
+	if ((result = i2c_register_entry (client,client->name,lm92_dir_table, THIS_MODULE)) < 0) {
 		i2c_detach_client (client);
 		kfree (client);
 		up (&mutex);
@@ -405,9 +411,7 @@
 
 
 static struct i2c_driver lm92_driver = {
-	.owner		= THIS_MODULE,
 	.name		= "lm92",
-	.id		= I2C_DRIVERID_LM92,
 	.flags		= I2C_DF_NOTIFY,
 	.attach_adapter	= lm92_attach_adapter,
 	.detach_client	= lm92_detach_client,
#15 lore raw
In reply to Evgeniy Polyakov
Quoted 7 lines · On Tue, 13 Apr 2004 20:42:06 +0200 Jean Delvare <[email protected]> wrote:
Quoted 2 lines

Yep.
Attached.

-EDOESNTAPPLY

Please checkout the latest CVS version of the file and provide a patch that applies against that.

Done.

Quoted 3 lines
Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------

chips/lm92.c renamed from chips/lm92.c.orig +60 -16
@@ -107,7 +107,7 @@
 
 /* addresses to scan */
 static unsigned short normal_i2c[] = { SENSORS_I2C_END };
-static unsigned short normal_i2c_range[] = { 0x48, 0x4b, SENSORS_I2C_END };
+static unsigned short normal_i2c_range[] = { 0x48, 0x4f, SENSORS_I2C_END };
 static unsigned int normal_isa[] = { SENSORS_ISA_END };
 static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
 
@@ -126,7 +126,7 @@
 	if (tmp < 0) return (-EIO);
 
 	/* convert the data to little endian format */
-	*value = swab16((u16) tmp);
+	*value = ((u16) tmp >> 8) | (u16) ((u16) tmp << 8);
 
 	return (0);
 }
@@ -134,10 +134,8 @@
 static inline int lm92_write16 (struct i2c_client *client,u8 reg,u16 value)
 {
 	/* convert the data to big endian format */
-	if (i2c_smbus_write_word_data(client, reg, swab16(value)) < 0)
-		return -EIO;
-
-	return 0;
+	u16 be = (value >> 8) | (u16) (value << 8);
+	return (i2c_smbus_write_word_data (client,reg,be) < 0 ? -EIO : 0);
 }
 
 static int lm92_read (struct i2c_client *client)
@@ -231,6 +229,49 @@
 	}
 }
 
+static int max6635_check(struct i2c_client *client)
+{
+	lm92_t *data = (lm92_t *) client->data;
+	int i, cn = 8;
+	u16 temp_low, temp_high, temp_hyst, temp_max;
+
+	temp_low 	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW);
+	temp_high	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH);
+	temp_hyst	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS);
+	temp_max	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL);
+	
+	if (!(!(temp_low & 0x7f00) && !(temp_high & 0x7f00) && !(temp_hyst & 0x7f00) && !(temp_max & 0x7f00)))
+		return 0;
+
+	for (i=0; i<32; ++i)
+	{
+		if ((i % 2 = 0) && (i < 16))
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != temp_low) ||
+				(temp_high != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(temp_hyst != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
+				(temp_max != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;
+		}
+		else
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != 0) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;
+		}
+	}
+	
+	data->temp.low 	= swab16(temp_low);
+	data->temp.high = swab16(temp_high);
+	data->temp.crit	= swab16(temp_max);
+	data->temp.hyst = swab16(temp_hyst);
+	data->temp.low 	= swab16(i2c_smbus_read_word_data(client, LM92_REG_TEMPERATURE));
+
+	return 1;
+}
+
 static int lm92_init_client (struct i2c_client *client)
 {
 	lm92_t *data = (lm92_t *) client->data;
@@ -294,20 +335,25 @@
 		return (-ERESTARTSYS);
 	}
 
-	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
-		manufacturer != LM92_MANUFACTURER_ID) {
-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
-	}
-
 	if ((result = i2c_attach_client (client))) {
 		kfree (client);
 		up (&mutex);
 		return (result);
 	}
 
-	if ((result = i2c_register_entry (client,client->name,lm92_dir_table)) < 0) {
+	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
+		manufacturer != LM92_MANUFACTURER_ID) {
+
+		if (!max6635_check(client))
+		{
+			i2c_detach_client (client);
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
+	}
+
+	if ((result = i2c_register_entry (client,client->name,lm92_dir_table, THIS_MODULE)) < 0) {
 		i2c_detach_client (client);
 		kfree (client);
 		up (&mutex);
@@ -365,9 +411,7 @@
 
 
 static struct i2c_driver lm92_driver = {
-	.owner		= THIS_MODULE,
 	.name		= "lm92",
-	.id		= I2C_DRIVERID_LM92,
 	.flags		= I2C_DF_NOTIFY,
 	.attach_adapter	= lm92_attach_adapter,
 	.detach_client	= lm92_detach_client,
#16 lore raw
In reply to Evgeniy Polyakov
Quoted 22 lines · On Tue, 13 Apr 2004 22:56:51 +0400 Evgeniy Polyakov <[email protected]> wrote:
(quoted diff) +3 -5
@@ -126,7 +126,7 @@
 	if (tmp < 0) return (-EIO);
 
 	/* convert the data to little endian format */
-	*value = swab16((u16) tmp);
+	*value = ((u16) tmp >> 8) | (u16) ((u16) tmp << 8);
 
 	return (0);
 }
@@ -134,10 +134,8 @@
 static inline int lm92_write16 (struct i2c_client *client,u8 reg,u16
 value){
 	/* convert the data to big endian format */
-	if (i2c_smbus_write_word_data(client, reg, swab16(value)) < 0)
-		return -EIO;
-
-	return 0;
+	u16 be = (value >> 8) | (u16) (value << 8);
+	return (i2c_smbus_write_word_data (client,reg,be) < 0 ? -EIO :
 0);
 }
 
Quoted 1 line

static int lm92_read (struct i2c_client *client)

This part is bogus.
Please review attached patch instead.

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------

chips/lm92.c renamed from chips/lm92.c.orig +57 -11
@@ -107,7 +107,7 @@
 
 /* addresses to scan */
 static unsigned short normal_i2c[] = { SENSORS_I2C_END };
-static unsigned short normal_i2c_range[] = { 0x48, 0x4b, SENSORS_I2C_END };
+static unsigned short normal_i2c_range[] = { 0x48, 0x4f, SENSORS_I2C_END };
 static unsigned int normal_isa[] = { SENSORS_ISA_END };
 static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
 
@@ -231,6 +229,49 @@
 	}
 }
 
+static int max6635_check(struct i2c_client *client)
+{
+	lm92_t *data = (lm92_t *) client->data;
+	int i, cn = 8;
+	u16 temp_low, temp_high, temp_hyst, temp_max;
+
+	temp_low 	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW);
+	temp_high	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH);
+	temp_hyst	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS);
+	temp_max	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL);
+	
+	if (!(!(temp_low & 0x7f00) && !(temp_high & 0x7f00) && !(temp_hyst & 0x7f00) && !(temp_max & 0x7f00)))
+		return 0;
+
+	for (i=0; i<32; ++i)
+	{
+		if ((i % 2 = 0) && (i < 16))
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != temp_low) ||
+				(temp_high != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(temp_hyst != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
+				(temp_max != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;
+		}
+		else
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*cn) != 0) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
+				(0 != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*cn)))
+				return 0;
+		}
+	}
+	
+	data->temp.low 	= swab16(temp_low);
+	data->temp.high = swab16(temp_high);
+	data->temp.crit	= swab16(temp_max);
+	data->temp.hyst = swab16(temp_hyst);
+	data->temp.low 	= swab16(i2c_smbus_read_word_data(client, LM92_REG_TEMPERATURE));
+
+	return 1;
+}
+
 static int lm92_init_client (struct i2c_client *client)
 {
 	lm92_t *data = (lm92_t *) client->data;
@@ -294,20 +335,25 @@
 		return (-ERESTARTSYS);
 	}
 
-	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
-		manufacturer != LM92_MANUFACTURER_ID) {
-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
-	}
-
 	if ((result = i2c_attach_client (client))) {
 		kfree (client);
 		up (&mutex);
 		return (result);
 	}
 
-	if ((result = i2c_register_entry (client,client->name,lm92_dir_table)) < 0) {
+	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
+		manufacturer != LM92_MANUFACTURER_ID) {
+
+		if (!max6635_check(client))
+		{
+			i2c_detach_client (client);
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
+	}
+
+	if ((result = i2c_register_entry (client,client->name,lm92_dir_table, THIS_MODULE)) < 0) {
 		i2c_detach_client (client);
 		kfree (client);
 		up (&mutex);
@@ -365,9 +411,7 @@
 
 
 static struct i2c_driver lm92_driver = {
-	.owner		= THIS_MODULE,
 	.name		= "lm92",
-	.id		= I2C_DRIVERID_LM92,
 	.flags		= I2C_DF_NOTIFY,
 	.attach_adapter	= lm92_attach_adapter,
 	.detach_client	= lm92_detach_client,
#17 lore raw
In reply to Evgeniy Polyakov
Quoted 21 lines · On Tue, 13 Apr 2004 21:26:45 +0200 Jean Delvare <[email protected]> wrote:
Quoted 1 line

Done.

My comments inline:

Quoted 17 lines
(quoted diff) +1 -5
@@ -126,7 +126,7 @@
 	if (tmp < 0) return (-EIO);
 
 	/* convert the data to little endian format */
-	*value = swab16((u16) tmp);
+	*value = ((u16) tmp >> 8) | (u16) ((u16) tmp << 8);
 
 	return (0);
 }
@@ -134,10 +134,8 @@
 static inline int lm92_write16 (struct i2c_client *client,u8
 reg,u16 value){
 	/* convert the data to big endian format */
-	if (i2c_smbus_write_word_data(client, reg, swab16(value)) < 0)
-		return -EIO;
-
-	return 0;
Quoted 8 lines

Review line 140

Quoted 4 lines
(quoted diff) +2 -0
+	u16 be = (value >> 8) | (u16) (value << 8);
+	return (i2c_smbus_write_word_data (client,reg,be) < 0 ? -EIO :
 0);
 }

These are two changes I just commited to the CVS repository. Please don't revert them.

I've reverted them in previous e-mail.
Attached patch also doesn't conain them.

Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+static int max6635_check(struct i2c_client *client)
+{
+	lm92_t *data = (lm92_t *) client->data;
+	int i, cn = 8;

I hardly can see any reason to define cn as a variable.

Removed.

Quoted 4 lines
Quoted 4 lines
(quoted diff) +3 -0
+	u16 temp_low, temp_high, temp_hyst, temp_max;
+
+	temp_low 	= i2c_smbus_read_word_data(client,

LM92_REG_TRIP_LOW);+ temp_high = i2c_smbus_read_word_data(client,

Quoted 8 lines
Quoted 5 lines

LM92_REG_TRIP_HIGH);+ temp_hyst = i2c_smbus_read_word_data(client,
LM92_REG_TRIP_HYSTERESIS);+ temp_max = i2c_smbus_read_word_data(client,
LM92_REG_TRIP_CRITICAL);+

(quoted diff) +1 -0
+	if (!(!(temp_low & 0x7f00) && !(temp_high & 0x7f00) &&

!(temp_hyst & 0x7f00) && !(temp_max & 0x7f00)))+ return 0;

You can spare negations by just using ||'s instead of &&'s (De Morgan's law, http://en.wikipedia.org/wiki/De_Morgan's_law).

:)

Quoted 17 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	for (i=0; i<32; ++i)

You can skip i=0, it cannot fail.

Quoted 13 lines
(quoted diff) +5 -0
+	{
+		if ((i % 2 = 0) && (i < 16))
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW
+ i*cn) != temp_low) ||+				(temp_high !> > i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*cn)) ||+	
		(temp_hyst != i2c_smbus_read_word_data(client,
		LM92_REG_TRIP_HYSTERESIS + i*cn)) ||
(quoted diff) +1 -0
+				(temp_max != i2c_smbus_read_word_data(client,

LM92_REG_TRIP_CRITICAL + i*cn)))+ return 0;

(quoted diff) +4 -0
+		}
+		else
+		{
+			if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW
Quoted 8 lines
Quoted 5 lines

+ i*cn) != 0) ||+ (0 != i2c_smbus_read_word_data(client,
LM92_REG_TRIP_HIGH + i*cn)) ||+ (0 !> > i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*cn))
||

(quoted diff) +1 -0
+				(0 != i2c_smbus_read_word_data(client,

LM92_REG_TRIP_CRITICAL + i*cn)))+ return 0;

I don't think you can rely of these zeroes. Maybe other chips would return random values or the limits.

I removed them, although they were always zero.

Quoted 12 lines

I would simply do "for (i=2; i<16; i+=2)" (or even "for (i=1; i<8; ++i)" with cn) and discard that second test.

Quoted 6 lines
(quoted diff) +5 -0
+	data->temp.low 	= swab16(temp_low);
+	data->temp.high = swab16(temp_high);
+	data->temp.crit	= swab16(temp_max);
+	data->temp.hyst = swab16(temp_hyst);
+	data->temp.low 	= swab16(i2c_smbus_read_word_data(client,

LM92_REG_TEMPERATURE));

Bug here.

Quoted 6 lines

Anyway I don't see the point in filling the variables since you don't update data->timestamp accordingly (so everything will be read again anyway). And you cannot update data->timestamp if you don't read the alarms too. All in all you would have to duplicate lm92_read here. So either don't store the values at all (recommended) or call lm92_read instead or rewriting it.

I just removed caching from detect path.

Quoted 30 lines
Quoted 30 lines
(quoted diff) +0 -6
@@ -294,20 +335,25 @@
 		return (-ERESTARTSYS);
 	}
 
-	if ((kind < 0 && lm92_read16
 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||-		manufacturer !> > LM92_MANUFACTURER_ID) {-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
-	}
-
 	if ((result = i2c_attach_client (client))) {
 		kfree (client);
 		up (&mutex);
 		return (result);
 	}
 
-	if ((result = i2c_register_entry

(client,client->name,lm92_dir_table)) < 0) {+ if ((kind < 0 &&
lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||+ manufacturer != LM92_MANUFACTURER_ID) {+

(quoted diff) +10 -0
+		if (!max6635_check(client))
+		{
+			i2c_detach_client (client);
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
+	}
+
+	if ((result = i2c_register_entry
Quoted 8 lines

Review

Quoted 4 lines

(client,client->name,lm92_dir_table, THIS_MODULE)) < 0) {

(quoted diff) +0 -0
 		i2c_detach_client (client);
 		kfree (client);
 		up (&mutex);

Why did you move swapped the detection and the client attachement? Detecting before we attempt to attach the client is actually the correct order.

Just to be sure that adapter can manage this client, but it is actually not needed.

Quoted 3 lines

The additional parameter to i2c_register_entry breaks compilation. I suspect that you use an outdated version of i2c. Get at least version 2.8.2.

i2c from 2.4.25 requires this. Attached patch for lm_sensors doesn't contain this change.

Quoted 9 lines

Review

Quoted 7 lines

static struct i2c_driver lm92_driver = {

(quoted diff) +0 -2
-	.owner		= THIS_MODULE,
 	.name		= "lm92",
-	.id		= I2C_DRIVERID_LM92,
 	.flags		= I2C_DF_NOTIFY,
 	.attach_adapter	= lm92_attach_adapter,
 	.detach_client	= lm92_detach_client,

No, don't do that.

The same here. Attached patch doesn't contain this change.

Quoted 3 lines
Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------

home/s0mbre/aWork/bitkeeper/exp-i2c/drivers/i2c/max6635.c renamed from tmp/lm_sensors-2.8.6/kernel/chips/lm92.c.orig +34 -4
@@ -107,7 +107,7 @@
 
 /* addresses to scan */
 static unsigned short normal_i2c[] = { SENSORS_I2C_END };
-static unsigned short normal_i2c_range[] = { 0x48, 0x4b, SENSORS_I2C_END };
+static unsigned short normal_i2c_range[] = { 0x48, 0x4f, SENSORS_I2C_END };
 static unsigned int normal_isa[] = { SENSORS_ISA_END };
 static unsigned int normal_isa_range[] = { SENSORS_ISA_END };
 
@@ -231,6 +229,32 @@
 	}
 }
 
+static int max6635_check(struct i2c_client *client)
+{
+	lm92_t *data = (lm92_t *) client->data;
+	int i;
+	u16 temp_low, temp_high, temp_hyst, temp_max;
+
+	temp_low 	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW);
+	temp_high	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH);
+	temp_hyst	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS);
+	temp_max	= i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL);
+	
+	if ((temp_low & 0x7f00) || (temp_high & 0x7f00) || (temp_hyst & 0x7f00) || (temp_max & 0x7f00))
+		return 0;
+
+	for (i=1; i<8; ++i)
+	{
+		if ((i2c_smbus_read_word_data(client, LM92_REG_TRIP_LOW + i*16) != temp_low) ||
+			(temp_high != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HIGH + i*16)) ||
+			(temp_hyst != i2c_smbus_read_word_data(client, LM92_REG_TRIP_HYSTERESIS + i*16)) ||
+			(temp_max != i2c_smbus_read_word_data(client, LM92_REG_TRIP_CRITICAL + i*16)))
+			return 0;
+	}
+	
+	return 1;
+}
+
 static int lm92_init_client (struct i2c_client *client)
 {
 	lm92_t *data = (lm92_t *) client->data;
@@ -296,9 +320,13 @@
 
 	if ((kind < 0 && lm92_read16 (client,LM92_REG_MANUFACTURER,&manufacturer) < 0) ||
 		manufacturer != LM92_MANUFACTURER_ID) {
-		kfree (client);
-		up (&mutex);
-		return (-ENODEV);
+
+		if (!max6635_check(client))
+		{
+			kfree (client);
+			up (&mutex);
+			return (-ENODEV);
+		}
 	}
 
 	if ((result = i2c_attach_client (client))) {
#18 lore raw
In reply to Evgeniy Polyakov
Quoted 1 line

Attached patch for lm_sensors (...)

OK, applied with some changes, fixes and improvements. I would appreciate it if you could check it out from CVS and test.

BTW, quoting myself:

Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	for (i=0; i<32; ++i)

You can skip i=0, it cannot fail.

Of course not. It cannot fail *if* the registers are read only, but we don't know if they are (hey, this is why we are testing). That said, reverting the for loop order would leave more time for the values to change if they have to (but I didn't do that it the patch however).

Thanks for your contribution to our project.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/