SAA1064 sensors chip driver
Hello,
I've started to write an i2c sensors chip driver for the Philips SAA1064 LED driver (on http://www.magoa.net/linux/index.php?view=kathrein you can see two of those working). Work is progressing, first tests already work with 2.4.20, as that thing is really easy to handle (I used to drive it with from userspace before). I'd hereby like to request a driver ID (I2C_DRIVERID_SAA1064) and yes, you may put my name onto the new drivers page if you like :-). Also, I'd like to be added as a recipient for the lm_sensors mailing list. Please enter [email protected], as that's the account I am using to manage my mailing lists.
Greetings,
Sascha Volkenandt
Quoted 9 lines
I've started to write an i2c sensors chip driver for the Philips SAA1064 LED driver (on
http://www.magoa.net/linux/index.php?view=kathrein you can see two of those working). Work is progressing, first tests already work with 2.4.20, as that thing is really easy to handle (I used to drive it with from userspace before). I'd hereby like to request a driver ID (I2C_DRIVERID_SAA1064) and yes, you may put my name onto the new drivers page if you like :-).
Here you are:
#define I2C_DRIVERID_SAA1064 1041
You should take a look at our matorb driver, which handles Matrix Orbital LCD displays. There may be similar mechanisms with the hardware you are writing a driver for. Probably not enough to make a similar driver (not even the same I2C address) but worth the look anyway.
Once you have your driver ready, send it to us so that we can have a look and tell you what we think about it. If you follow the guidelines as found in our docs, it should be OK. Howevern, due to a recent change in our structures, if you have written your driver for the 2.4.21 Linux kernel, it won't integrate directly into lm_sensors CVS. Don't worry, we'll take care of this point.
We also have to find a detection mechanism for the SAA1064. It doesn't seem to have any register dedicated to identification, so it will be tricky. However, it looks like there are only three wires for register selection, so maybe the data will "cycle" over 8-byte boundaries (the same way the LM75 cycles over 4-byte boundaries. That, plus the fact that the SAA1064 uses an unusual address range (0x38-0x3b), should make the detection possible. Could you send us the output of i2cdump for confirmation? Also, bit 7 of the control register seems to be unused, as seem to be the registers 0x05 to 0x07. That may help for the detection too.
Quoted 3 lines
Also, I'd like to be added as a recipient for the
lm_sensorsmailing list. Please enter [email protected], as that's the account I am using to manage my mailing lists.
Phil will do so when he's back, I hope.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 2 lines · At Montag, 14. Juli 2003 13:46 you wrote:
Here you are:
#defineI2C_DRIVERID_SAA10641041
Thanks :-)
Quoted 4 lines
You should take a look at our matorb driver, which handles Matrix Orbital LCD displays. There may be similar mechanisms with the hardware you are writing a driver for. Probably not enough to make a similar driver (not even the same I2C address) but worth the look anyway.
Yes, I have used pcf8574.c as a template, and matorb.c to "steal" the code for the digit registers, but I implemented communication differently, since this chip doesn't react to smbus-like commands (like those two do), but needs real i2c-com.
I have to look about the addresses, my devices are hardwired on 0x38 and 0x3b, but the datasheet says something completely different about possible addresses. Also, the datasheet says reading (one status byte with one bit indicating a power loss) is on a different address than writing. By now, I have these two addresses as the only probed ones (which also conflict with the pcf8574a driver :-( ).
Quoted 6 lines
Once you have your driver ready, send it to us so that we can have a look and tell you what we think about it. If you follow the guidelines as found in our docs, it should be OK. Howevern, due to a recent change in our structures, if you have written your driver for the 2.4.21 Linux kernel, it won't integrate directly into
lm_sensorsCVS. Don't worry, we'll take care of this point.
Currently I'm using a sensors- and i2c-2.7.0 patched kernel. But I guess "recent" doesn't include that :-)
Quoted 10 lines
We also have to find a detection mechanism for the SAA1064. It doesn't seem to have any register dedicated to identification, so it will be tricky. However, it looks like there are only three wires for register selection, so maybe the data will "cycle" over 8-byte boundaries (the same way the LM75 cycles over 4-byte boundaries. That, plus the fact that the SAA1064 uses an unusual address range (0x38-0x3b), should make the detection possible. Could you send us the output of i2cdump for confirmation? Also, bit 7 of the control register seems to be unused, as seem to be the registers
0x05to0x07. That may help for the detection too.
The chip receives an register-address byte followed by n (don't know how many, datasheet only specifies 6 at once) data bytes. The register address is encreased by every data byte, wrapping around at 7. The data has to be written in one physical block, since the device expects a new block starting with the register-address after a stop-condition. That's why smbus-commands don't work either, I guess.
Well i2cdump doesn't give ME much info, maybe it does for you (output for modes byte, word and i2cblock attached).
Quoted 1 line
Phil will do so when he's back, I hope.
Thx.
Greetings,
Sascha
-------------- next part --------------
# i2cdump 2 0x38 b
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................# i2cdump 2 0x38 w
0,8 1,9 2,a 3,b 4,c 5,d 6,e 7,f
00: 0000 0000 0000 0000 0000 0000 0000 0000
08: 0000 0000 0000 0000 0000 0000 0000 0000
10: 0000 0000 0000 0000 0000 0000 0000 0000
18: 0000 0000 0000 0000 0000 0000 0000 0000
20: 0000 0000 0000 0000 0000 0000 0000 0000
28: 0000 0000 0000 0000 0000 0000 0000 0000
30: 0000 0000 0000 0000 0000 0000 0000 0000
38: 0000 0000 0000 0000 0000 0000 0000 0000
40: 0000 0000 0000 0000 0000 0000 0000 0000
48: 0000 0000 0000 0000 0000 0000 0000 0000
50: 0000 0000 0000 0000 0000 0000 0000 0000
58: 0000 0000 0000 0000 0000 0000 0000 0000
60: 0000 0000 0000 0000 0000 0000 0000 0000
68: 0000 0000 0000 0000 0000 0000 0000 0000
70: 0000 0000 0000 0000 0000 0000 0000 0000
78: 0000 0000 0000 0000 0000 0000 0000 0000
80: 0000 0000 0000 0000 0000 0000 0000 0000
88: 0000 0000 0000 0000 0000 0000 0000 0000
90: 0000 0000 0000 0000 0000 0000 0000 0000
98: 0000 0000 0000 0000 0000 0000 0000 0000
a0: 0000 0000 0000 0000 0000 0000 0000 0000
a8: 0000 0000 0000 0000 0000 0000 0000 0000
b0: 0000 0000 0000 0000 0000 0000 0000 0000
b8: 0000 0000 0000 0000 0000 0000 0000 0000
c0: 0000 0000 0000 0000 0000 0000 0000 0000
c8: 0000 0000 0000 0000 0000 0000 0000 0000
d0: 0000 0000 0000 0000 0000 0000 0000 0000
d8: 0000 0000 0000 0000 0000 0000 0000 0000
e0: 0000 0000 0000 0000 0000 0000 0000 0000
e8: 0000 0000 0000 0000 0000 0000 0000 0000
f0: 0000 0000 0000 0000 0000 0000 0000 0000
f8: 0000 0000 0000 0000 0000 0000 0000 0000 # i2cdump 2 0x38 i
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................Quoted 7 lines
I have to look about the addresses, my devices are hardwired on
0x38and0x3b, but the datasheet says something completely different about possible addresses. Also, the datasheet says reading (one status byte with one bit indicating a power loss) is on a different address than writing. By now, I have these two addresses as the only probed ones (which also conflict with the pcf8574a driver :-( ).
Although the datasheet wasn't easy to understand at first, I think they say the same as we do. I2C adresses are *7-bit* addresses, but you send an 8-bit value over the I2C bus, the LSB meaning read (1) or write (0). That's why the datasheet says the read and write addresses are different. The address is actually the same, but the byte value you send is different. When they say the read address is 0x71 and the write address is 0x70, the real address is 0x70>>1, that is 0x38, which is the address you see your own chip at. So you really have to consider that the address range is 0x38-0x3b. Our I2C layer will add the eigth bit in its own, you don't have to worry about that. And you definitely don't have to handle a different address for reading and writing. Sounds clearer now?
Quoted 2 lines
Currently I'm using a sensors- and i2c-2.7.0 patched kernel. But I guess "recent" doesn't include that :-)
No, the change occured after 2.7.0 was released. But don't worry about that, I'll make the few changes needed before integration, it's easy.
Quoted 6 lines
The chip receives an register-address byte followed by n (don't know how many, datasheet only specifies 6 at once) data bytes. The register address is encreased by every data byte, wrapping around at 7. The data has to be written in one physical block, since the device expects a new block starting with the register-address after a stop-condition. That's why smbus-commands don't work either, I guess.
I'm no I2C vs. SMBus expert, but this seem to make sense.
Quoted 2 lines
Well i2cdump doesn't give ME much info, maybe it does for you (output for modes byte, word and i2cblock attached).
Not really useful to me either. The interesting one should have been the byte mode, but it shows only zeroes (as the others do). In a way, the data cycles over 8-byte boundaries, and the bits I expected to be zeroes are, but that's not very helpful since everything is zero. However, this is the expected data if the LEDs are all off (and the control register is in a particular state). Was it the case? If it was, I would like to see the same I2C dump (byte mode) with some LEDs arbirary switched on. I'm quite pessimistic however, the probability that everything was set to zero is *low* ;)
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 6 lines
Ok here's the first version - all functions work on my setup so far, please have a look at it, if everything went right or if I got something basically wrong. I guess the proc-interface is self-explaining for sensors-experts, and I'll supply you with doc-files for the module, too, soon.
I'll take a look at it tomorrow. BTW, how may I get my hands on such a device? I have to say I'd *love* playing around with a 4-digit LCD display :) How do you get it plugged on your computer? Using the parallel port I guess?
Quoted 3 lines
BTW: Hmpf, my last mail did go to the common address (stupid mailing-client), I'm forwarding it to yours now. If anyone asks, tell the other's it was a mistake, please :-)
This is what you are expected to do! The more eyes read you, the better. There are only a few dozens persons on the list, on purpose. So people on the list *are* interested in the project and will want to know everything that's going on.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 5 lines · At Montag, 14. Juli 2003 22:02 you wrote:
[...]
the address range is 0x38-0x3b. Our I2C layer will add the eigth bit in its own, you don't have to worry about that. And you definitely don't have to handle a different address for reading and writing. Sounds clearer now?
Definitely, thx :-)
Quoted 2 lines
No, the change occured after 2.7.0 was released. But don't worry about that, I'll make the few changes needed before integration, it's easy.
Thx again.
Quoted 9 lines
Not really useful to me either. The interesting one should have been the byte mode, but it shows only zeroes (as the others do). In a way, the data cycles over 8-byte boundaries, and the bits I expected to be zeroes are, but that's not very helpful since everything is zero. However, this is the expected data if the LEDs are all off (and the control register is in a particular state). Was it the case? If it was, I would like to see the same I2C dump (byte mode) with some LEDs arbirary switched on. I'm quite pessimistic however, the probability that everything was set to zero is *low* ;)
Well, the driver blanks all digits, setting the testmode bit in the control-block (all digits on, ignore data). The i2cdump I've sent to you was indeed exactly that case. But as I've just checked, output is exactly the same when the led's are displaying some random digits at a variable brightness.
Quoted 4 lines · At Montag, 14. Juli 2003 22:19 you wrote:
I'll take a look at it tomorrow. BTW, how may I get my hands on such a device? I have to say I'd *love* playing around with a 4-digit LCD display :) How do you get it plugged on your computer? Using the parallel port I guess?
Look at http://www.magoa.net/linux/index.php?view=kathrein
I hope when this driver is released someone will find other "old" devices carrying this chip - in my case it's a Kathrein analogue Sat-Twin-Receiver (two displays) or Single-Receiver (one display). It's connected to i2c-pport indeed. In the meantime, an additional PCF8574 chip has been connected to that bus, works fine alltogether (when loading pcf8574 after saa1064) :-).
Quoted 4 lines
This is what you are expected to do! The more eyes read you, the better. There are only a few dozens persons on the list, on purpose. So people on the list *are* interested in the project and will want to know everything that's going on.
OK I'll stick to that - thsi mail goes to the right address though :-)))
Greetings,
Sascha
Quoted 9 lines · Jean Delvare
Quoted 4 lines
Another small thing (@all *g*):
Most of your modules lack the #ifdef MODULE...#endif construct usually embracinginit_moduleandcleanup_module. That prevents most of these to run smoothly compiled into the kernel. Is this a bug or a feature?Bug, definitely. I noticed this too, because I didn't do so in my own driver... I'll check every driver tomorrow. Anyway, drivers that get mkpatched must be OK, or I guess someone would have noticed, by the time...
No, this isn't a bug. The #ifdef MODULE is not needed anymore. Just use:
module_init(foo_init()); module_exit(foo_exit());
and everything will work just fine for when the code is build as a module or within the kernel.
thanks,
greg k-h
Quoted 2 lines
Here's the driver.
OK, I took a look. Overall it's great, but some things would need to be fixed:
1* We do not support old kernels. Thus:
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)) || \
(LINUX_VERSION_CODE = KERNEL_VERSION(2,3,0))
#define init_MUTEX(s) do { *(s) = MUTEX; } while(0)
#endifis unnecessary. Did you find such code in one of our drivers?
2* According to the datasheet, the SAA1064 has four possible I2C addresses, ranging from 0x38 to 0x3b. So, you will want to replace:
static unsigned short normal_i2c[] = { 0x38, 0x3b, SENSORS_I2C_END };
static unsigned short normal_i2c_range[] = { SENSORS_I2C_END };with:
static unsigned short normal_i2c[] = { SENSORS_I2C_END }; static unsigned short normal_i2c_range[] = { 0x38, 0x3b,SENSORS_I2C_END };
3* Use hexa where it makes more sense than decimal. For example,
#define SAA1064_INIT 127
would better be written:
#define SAA1064_INIT 0x7f
because it really is a bitfield.
4* Use C99 style struct initializers. The following:
static struct i2c_driver saa1064_driver = {
/* name */ "SAA1064 sensor chip driver",
/* id */ I2C_DRIVERID_SAA1064,
/* flags */ I2C_DF_NOTIFY,
/* attach_adapter */ &saa1064_attach_adapter,
/* detach_client */ &saa1064_detach_client,
/* command */ &saa1064_command,
/* inc_use */ &saa1064_inc_use,
/* dec_use */ &saa1064_dec_use};
should be:
static struct i2c_driver saa1064_driver = {
.name = "SAA1064 sensor chip driver",
.id = I2C_DRIVERID_SAA1064,
.flags = I2C_DF_NOTIFY,
.attach_adapter = &saa1064_attach_adapter,
.detach_client = &saa1064_detach_client,
.command = &saa1064_command,
.inc_use = &saa1064_inc_use,
.dec_use = &saa1064_dec_use};
Now, more important: is it working OK, at least for you? :)
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 11 lines
Quoted 10 lines
Not really useful to me either. The interesting one should have been the byte mode, but it shows only zeroes (as the others do). In a way, the data cycles over 8-byte boundaries, and the bits I expected to be zeroes are, but that's not very helpful since everything is zero. However, this is the expected data if the LEDs are all off (and the control register is in a particular state). Was it the case? If it was, I would like to see the same I2C dump (byte mode) with some LEDs arbirary switched on. I'm quite pessimistic however, the probability that everything was set to zero is *low* ;)
Quoted 5 lines
Well, the driver blanks all digits, setting the testmode bit in the control-block (all digits on, ignore data). The i2cdump I've sent to you was indeed exactly that case. But as I've just checked, output is exactly the same when the led's are displaying some random digits at a variable brightness.
Was your module loaded at that time. Maybe you need to unload the module in order to have i2cdump working.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 5 lines · At Dienstag, 15. Juli 2003 18:28 you wrote:
1* We do not support old kernels. Thus:
[...]
is unnecessary. Did you find such code in one of our drivers?
Like I said, I used lm_sensors-2.7.0 pcf8574.c as a template. There it is still included :-)
Quoted 5 lines
2* According to the datasheet, the SAA1064 has four possible I2C addresses, ranging from
0x38to0x3b. So, you will want to replace:[...]
Done.
Quoted 3 lines
4* Use C99 style struct initializers. The following:
[...]
Again, bad template :-) Fixed. Does this have to be done in the ctl_table, too, cause I suppose that would look quite ugly for long tables?
I've just checked back on your current CVS. Okay my template was too old :-). I see the ctl_table doesn't use C99 struct initializers, and I also see that your SYSCTL defines went into the sources now. Is that part of the API change you spoke about? I've inserted them into my code now, too... One bug is fixed: ...SYSCTL_DIGIT0 should really be ...SYSCTL_DISP (as the function and proc names also are "disp"). Tell me if anything needs still be changed, also regarding new APIs, since it's the first time I'm doing things in kernel space (and I'm having a good time *g*).
Quoted 1 line
Now, more important: is it working OK, at least for you? :)
Yup :-) Works very fine, here. On startup, everything lights up (maybe I should put "init" on, instead?), then I disable the testmode, everything gets dark, and I can program the digits...
Another small thing (@all *g*):
Most of your modules lack the #ifdef MODULE...#endif construct usually embracing init_module and cleanup_module. That prevents most of these to run smoothly compiled into the kernel. Is this a bug or a feature?
Since I am using a highly compact kernel for a thin client, with LIRC, em8300 and even I2C compiled into the kernel, all working fine (after adding the missing #ifdef construct), it can't be principle-caused.
Greetings,
Sascha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: saa1064.c
Type: text/x-csrc
Size: 17700 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20030715/5b804f00/saa1064.bin
Quoted 4 lines
Like I said, I used lm_sensors-2.7.0
pcf8574.cas a template. There it is still included :-)
Just checked and it isn't. You must have been using an old file, as you said below.
Quoted 7 lines
Quoted 5 lines
2* According to the datasheet, the SAA1064 has four possible I2C addresses, ranging from
0x38to0x3b. So, you will want to replace:[...]
Done.
You should modify your "detection" procedure in the same way. Actually, I don't think you did it the right way at all. The "kind" parameter is set according to the force options that are passed to the module as you load it. kind < 0 means no force parameter was set (default). kind = 0 means force, but no particular chip, kind > 0 means force a given kind of chip. Since there is only one chip in your driver, = 0 and > 0 are all the same. What's more, you don't have to take the address into account. You won't be called for an address you don't like unless the force parameter is used. And if it is used, you have to trust it. So you should have the following detection procedure:
kind < 0: set kind to saa1064, try to detect the chip (see below) kind >= 0: set kind to saa1064, don't try to detect the chip
As you noticed, the saa1064 doesn't really want to be detected. However, I still think there are things we can check:
1* The MSB of the control register has to be zero.
2* Registers 0x05 to 0x07 should be set to 0x00 (unless we can't read from them).
3* Registers should cycle over 8-byte boundaries.
Unfortunately, this couldn't be confirmed by i2cdump. I'd like you to insist, this would really help. Maybe the chip doesn't like the was i2cdump reads it. You still could try adding these checks in your driver code (for kind < 0) and see if the module still loads. Another possibility is to add detection to sensors-detect (what I could do.)
Quoted 2 lines
it's the first time I'm doing things in kernel space (and I'm having a good time *g*).
Same for me a few weeks ago. And it feels great actually, isn't it? :)
Quoted 3 lines
Yup :-) Works very fine, here. On startup, everything lights up (maybe I should put "init" on, instead?), then I disable the testmode, everything gets dark, and I can program the digits...
No, keep it this way. Setting every led on is a good practice, it lets the user check that no led is dead.
Quoted 4 lines
Another small thing (@all *g*):
Most of your modules lack the #ifdef MODULE...#endif construct usually embracinginit_moduleandcleanup_module. That prevents most of these to run smoothly compiled into the kernel. Is this a bug or a feature?
Bug, definitely. I noticed this too, because I didn't do so in my own driver... I'll check every driver tomorrow. Anyway, drivers that get mkpatched must be OK, or I guess someone would have noticed, by the time...
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 11 lines · At Dienstag, 15. Juli 2003 19:37 you wrote:
You should modify your "detection" procedure in the same way. Actually, I don't think you did it the right way at all. The "kind" parameter is set according to the force options that are passed to the module as you load it. kind < 0 means no force parameter was set (default). kind = 0 means force, but no particular chip, kind > 0 means force a given kind of chip. Since there is only one chip in your driver, = 0 and > 0 are all the same. What's more, you don't have to take the address into account. You won't be called for an address you don't like unless the force parameter is used. And if it is used, you have to trust it. So you should have the following detection procedure:
Quoted 2 lines
kind < 0: set kind to saa1064, try to detect the chip (see below) kind >= 0: set kind to saa1064, don't try to detect the chip
Ok I'll do this but no more programming for today. It's damn hot here and I just can't _think_ :-)
I've re-checked the current pcf8574 sources, and of course I found the bug in mine pretty quickly :-). But if this chip is really impossible to detect, I think just setting saa1064 for kind in every case would make sense.
Quoted 6 lines
As you noticed, the saa1064 doesn't really want to be detected. However, I still think there are things we can check:
1* The MSB of the control register has to be zero.
2* Registers0x05to0x07should be set to0x00(unless we can't read from them).
3* Registers should cycle over 8-byte boundaries.
But how can this actually be checked when the chip doesn't provide any read operation (according to the data sheet is doesn't). It reads a status byte where only one bit is significant. I'll add read support for this byte tomorrow, too, maybe some of the other bits are static or something.
Quoted 5 lines
Unfortunately, this couldn't be confirmed by i2cdump. I'd like you to insist, this would really help. Maybe the chip doesn't like the was i2cdump reads it. You still could try adding these checks in your driver code (for kind < 0) and see if the module still loads. Another possibility is to add detection to sensors-detect (what I could do.)
I assumed that sensors-detect should contain all detectable chips, for scanning unknown busses. So I assumed both kinds of detection would be necessary :-)
Quoted 1 line
Same for me a few weeks ago. And it feels great actually, isn't it? :)
Definitely :-)
Well, the main problem really was to find something useful to start with.
Quoted 4 lines
Bug, definitely. I noticed this too, because I didn't do so in my own driver... I'll check every driver tomorrow. Anyway, drivers that get mkpatched must be OK, or I guess someone would have noticed, by the time...
Well at least for i2c-core, i2c-dev and i2c-proc, they are double-initialized (first by init and later again by init_module) when the construct is missing. Clearly those drivers did NOT work as expected after initialization in the kernel. /dev/i2c-0 was not existent, but i2c-1 was responding etc.
Greetings,
Sascha
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Another small thing (@all *g*):
Most of your modules lack the #ifdef MODULE...#endif construct usually embracinginit_moduleandcleanup_module. That prevents most of these to run smoothly compiled into the kernel. Is this a bug or a feature?Bug, definitely. I noticed this too, because I didn't do so in my own driver... I'll check every driver tomorrow. Anyway, drivers that get mkpatched must be OK, or I guess someone would have noticed, by the time...
Quoted 7 lines
No, this isn't a bug. The #ifdef MODULE is not needed anymore. Just use:
module_init(foo_init()); module_exit(foo_exit());and everything will work just fine for when the code is build as a module or within the kernel.
OK, thanks for the clarification :)
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 5 lines · At Dienstag, 15. Juli 2003 19:37 Jean Delvare wrote:
Unfortunately, this couldn't be confirmed by i2cdump. I'd like you to insist, this would really help. Maybe the chip doesn't like the was i2cdump reads it. You still could try adding these checks in your driver code (for kind < 0) and see if the module still loads. Another possibility is to add detection to sensors-detect (what I could do.)
I *think* I've found a way to detect this thing. WHen the chip is freshly powered on (nothing is displayed), a byte read results in 0x80 (power failure indicator set to 1), while a subsequent byte read results in 0x00 (no power-failure since last read-out). So, if two byte reads result in 0x80, followed by 0x00, we'd probably have found a saa1064 chip. What do you think, is this secure enough or could it confuse other chips possibly using the same address?
Main problem will be that this will only work one time, after powering the chip.
Greetings,
Sascha
Quoted 11 lines
I *think* I've found a way to detect this thing. WHen the chip is freshly powered on (nothing is displayed), a byte read results in
0x80(power failure indicator set to 1), while a subsequent byte read results in0x00(no power-failure since last read-out). So, if two byte reads result in0x80, followed by0x00, we'd probably have found a saa1064 chip. What do you think, is this secure enough or could it confuse other chips possibly using the same address?Main problem will be that this will only work one time, after powering the chip.
Possible method, but as you say, it ain't really reliable.
I read the datasheet again and finally understood what I first got wrong. I thought that the saa1064 had 8 R/W registers. Actually it has 8 (5 in use) write only registers, and one read only register. This means that you can't read back values you wrote in registers (not really practical, but you can still read the driver's values). What's more, the readable register doesn't seem to have an address. So whatever address you try to read, you read this register. Since only one bit in this register can be set, and it usually isn't, this explains why the i2cdump command I asked you to try returned only 00 values.
I think that if you power-off the saa1064, power it on again and run the i2cdump command once at this time, you will have all 00 bytes again, *except* the first one which will be 80. Could you try that? It would confirm my understanding is correct.
So, the way to detect it now seems clearer:
1* The most basic way is to read the whole range and say it is a saa1064 if all bytes are 0x00 or 0x80 (that is, (a & 0x7F)=0).
2* We can give it a greater confidence if the first read returns 0x80 and the later ones return 0x00. I do something similar for the lm75 (greater confidence if the temperature limits are the default ones).
3* Instead of 2*, we can re-read the same address if it returns 0x80 once. It should return 0x00 next time, if it is a saa1064.
I like the ideas, but in fact 2* and 3* may not even be necessary. As far as I know, there are no other chips in our package at the adresses the saa1064 can use, so we don't need something bulletproof. Let's go for 1* with maybe a bit of 2*. I'll do it or you can do it if you want. If you do it, first checkout the latest version of sensors-detect and send back a patch, not the whole file.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 9 lines · At Donnerstag, 17. Juli 2003 20:56 Jean Delvare wrote:
I read the datasheet again and finally understood what I first got wrong. I thought that the saa1064 had 8 R/W registers. Actually it has 8 (5 in use) write only registers, and one read only register. This means that you can't read back values you wrote in registers (not really practical, but you can still read the driver's values). What's more, the readable register doesn't seem to have an address. So whatever address you try to read, you read this register. Since only one bit in this register can be set, and it usually isn't, this explains why the i2cdump command I asked you to try returned only 00 values.
That's what I tried to explain - there's only one read register, and only one bit matters there :-)
Quoted 4 lines
I think that if you power-off the saa1064, power it on again and run the i2cdump command once at this time, you will have all 00 bytes again, *except* the first one which will be 80. Could you try that? It would confirm my understanding is correct.
Exactly - on first readout (_before_ loading the driver the first time, that's why I didn't notice) it says 0x80 in the first byte.
Quoted 4 lines
So, the way to detect it now seems clearer:
1* The most basic way is to read the whole range and say it is a saa1064 if all bytes are
0x00or0x80(that is, (a & 0x7F)=0).
Well - why all bytes? Only the very first read ever returns 0x80.
Quoted 2 lines
2* We can give it a greater confidence if the first read returns
0x80and the later ones return0x00. I do something similar for the lm75
Yup that's what I thought, too - 0x80 followed by 0x00
Quoted 2 lines
3* Instead of 2*, we can re-read the same address if it returns
0x80once. It should return0x00next time, if it is a saa1064.
As I said - it only returns 0x80 in case of a power loss (which is the case after powering up the device). You'd have to force a hardware power-off of the chip before it would return 0x80 ever again.
Quoted 6 lines
I like the ideas, but in fact 2* and 3* may not even be necessary. As far as I know, there are no other chips in our package at the adresses the saa1064 can use, so we don't need something bulletproof. Let's go for 1* with maybe a bit of 2*. I'll do it or you can do it if you want. If you do it, first checkout the latest version of sensors-detect and send back a patch, not the whole file.
The PCF8574A uses the range 0x38 to 0x3f, and detects a saa1064 as a pcf8574a when loaded first. I'll put the two-byte-sequence (0x80 followed by 0x00) into the module. Maybe you'll do something for sensors-detect?
I hope this weekend I'll find time to finish "the rest" (in-module detection, doc, and finally a complete patchset).
Greetings,
Sascha
Quoted 3 lines
That's what I tried to explain - there's only one read register, and only one bit matters there :-)
Yeah but you know, I'm kinda stupid, so you have to repeat the things over and over again before I finally catch it ;)
Quoted 2 lines
Exactly - on first readout (_before_ loading the driver the first time, that's why I didn't notice) it says
0x80in the first byte.
I guess it's a matter of powering the device up, not of loading the driver.
Quoted 6 lines
Quoted 4 lines
So, the way to detect it now seems clearer:
1* The most basic way is to read the whole range and say it is a saa1064 if all bytes are
0x00or0x80(that is, (a & 0x7F)=0).Well - why all bytes? Only the very first read ever returns
0x80.
I was writing about the detection in sensors-detect. The detection method in the driver and in sensors-detect are of different natures. In your driver, you just want to know if whan you have *can be* what your driver supports. So reading, say, 4 times, and expect either "0x80 0x00 0x00 0x00" or "0x00 0x00 0x00 0x00" is just fine. In sensors-detect, we want to know if what we have is more likely to be one chip that any other that can possibly exist at the same address. So the fact that the saa1064 ignores the read address is very interesting. No other chip is likely to do the same (or at least none that I know of) so either if reading all bytes makes no sense for the saa1064, it would make sense for other chips, and these other chips are unlilely to have 0x00 bytes everywhere. So the saa1064 detection should be rather good.
Quoted 6 lines
Quoted 4 lines
2* We can give it a greater confidence if the first read returns
0x80and the later ones return0x00. I do something similar for the lm75Yup that's what I thought, too -
0x80followed by0x00
Again, this is for sensors-detect. You don't have any confidence idea in the drivers.
Quoted 2 lines
The PCF8574A uses the range
0x38to0x3f, and detects a saa1064 as a pcf8574a when loaded first.
I didn't know that. I just checked sensors-detect and the pcf8574a isn't supported. I think I will take a look at the datasheet and add detection to sensors-detect. I'll also see if I can enhance the detection for the pcf8591. The more devices we detect in sensors-detect, the better, even if they are not sensors, and even if we wouldn't have drivers for them. It lowers the risk of misdetection for the other chips.
Quoted 2 lines
I'll put the two-byte-sequence (
0x80followed by0x00) into the module.
No, don't do that. You have to load the module even if the device wasn't freshly powered up. The method I suggest is reading four times, and accept to load if the first read returns either 0x80 or 0x00 (that is, (a & 0x7f)=0), and the three other reads return 0x00. As said earlier, you don't have to load if and only if it is a saa1064. You have to load if it *behaves like* a saa1064.
Of course, if the force parameter is used (kind>=0), you have to skip the detection.
Quoted 1 line
Maybe you'll do something for sensors-detect?
Yeah, no problem. I'll let you know when it's done.
Quoted 2 lines
I hope this weekend I'll find time to finish "the rest" (in-module detection, doc, and finally a complete patchset).
OK.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 2 lines
Maybe you'll do something for sensors-detect?
Done. Please checkout and test! I expect it to return a confidence value of 7 if the device was just powered up, and 4 if not. In any case, it is greater than the confidence 1 returned for the PCF8574A so sensors-detect should tell you to use the saa1064 driver.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
Quoted 4 lines · At Freitag, 18. Juli 2003 10:42 Jean Delvare wrote:
Done. Please checkout and test! I expect it to return a confidence value of 7 if the device was just powered up, and 4 if not. In any case, it is greater than the confidence 1 returned for the PCF8574A so sensors-detect should tell you to use the saa1064 driver.
I am very happy to tell you the detection has worked perfectly. The PCF8574 at 0x20 has been detected with a confidence of one, the SAA1064 at 0x38 and 0x3b has first been mis-detected (PCF8574A, conf 1), then correctly detected as a SAA1064 (confidence 4, not freshly powered-up). The module parameters are then accurate (load saa1064 first, tell pcf8574 to ignore 0x38 and 0x3b). Well done!
Greetings,
Sascha