Skip to contentSkip to conversation

Update: SAA1064

DISCUSSION Sascha Volkenandt 2 participants 5 messages May 19, 2005

lore
Share & tools
lore
#0 lore raw

Hello folks, hi Jean,

I've updated my i2c-machine to 2.4.21 with an i2c layer from yesterday's CVS, as well as lm_sensors2 from yesterday. All checked out like suggested on your download page.

I have adapted the SAA1064 driver code to that version of lm_sensors (again using pcf8574.c as a template to what has changed), and I've also fixed some bugs, specifically:

- enhanced functionality test in saa1064_detect
- fixed handling of kind in saa1064_detect
- always force saa1064, since no real autodetection possible (yet)
- used i2c_smbus_write_data instead of i2c_master_send
+ added reading the status byte (sysctl PWRLOSS indicates LED power loss since last readout)

Greetings,
Sascha
-------------- next part --------------
A non-text attachment was scrubbed...
Name: saa1064.c
Type: text/x-csrc
Size: 16783 bytes
Desc: not available
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20030716/e5dfc1cc/saa1064.bin

#1 lore raw
Quoted 9 lines

I've updated my i2c-machine to 2.4.21 with an i2c layer from yesterday's CVS, as well as lm_sensors2 from yesterday. All checked out like suggested on your download page.

I have adapted the SAA1064 driver code to that version of lm_sensors (again using pcf8574.c as a template to what has changed), and I've also fixed some bugs, specifically:

Quoted 6 lines

- enhanced functionality test in saa1064_detect
- fixed handling of kind in saa1064_detect
- always force saa1064, since no real autodetection possible (yet)
- used i2c_smbus_write_data instead of i2c_master_send
+ added reading the status byte (sysctl PWRLOSS indicates LED power loss since last readout)

I've read your code source, here are my comments:

(All the following points express *my opinion*. It is not the True Truth. You do what you want. I may be wrong.)

1* Your second comment about the saa1064 is inaccurate (if my understanding is correct). You say you have to write to the 5 registers at once. It isn't true. You *can* do so, but the saa1064 is much more flexible than that. You can start writting at any address and stop writing at any address. All the saa1064 does is increasing the address by itself so you can send multiple bytes at once (I think it is similar in mind to the "quick write" feature in the I2C world?).

2* I would unify the two "blank" sysctl files into one single file with
2 values. What's more, I would change the convention. You have 0 blanked, 1 = not blanked, because it's that way in the datasheet, but it won't make much sense for the user. So I think you should either rename
the sysctl file and associated data to, say, "display", or, preferably,
I would decide that 1 stands for blanked.

3* I'm not sure about the pwrloss sysctl file. How do you intend to use it? The fact that the power loss bit vanishes upon read makes it hard to use from userland IMHO. I think you should make an internal only use of the flag. If my understanding is correct, the flag being set means that the device was freshly powered up. In the event this happens after the driver is loaded, it means that nothing is displayed on your LCD display anymore, regardless of the internal values you have in your driver. So this flag should idealy mean that you must rewrite to the chip registers from the driver values. Now the problem is that the flag does not come to you in such a case, you would have to poll its value, and polling is generally bad for performance, so we don't want to do that. What I imagine you could do is define a "refresh" sysctl file instead of "pwrloss". Reading from (or writing to, whatever) this file would not return anything (and would ignore the written value in the case of a write) but would poll the power loss flag. If it find it is set, it would write the internal data to the chip. I think it makes more sense that way than letting the user know (in userspace) a power loss has occured and leave him/her handle it. I think you should try powering it off while in use and see what happens. That way, we will know what the user will want to be done.

4* BTW, the power loss flag is the MSB in the status register, not the LSB, so SAA1064_STAT_PWRLOSS should be set to 0x80.

5* SAA1064_CTRL_SET_BRIGHT(c,val) is not safe. You don't limit the change to 3 bits. I would add a "& 0x07" for safety (no real danger though, I admit).

6* You don't have to define a saa1064_write_value function. This is done in some drivers (lm75 for example) because the function actually does something, but for simple drivers there is no need for such a function.

7* You can use a single call to i2c_check_functionality instead of two by or'ing the constants. BTW, why are you using READ_BYTE and WRITE_BYTE_DATA, but not READ_BYTE_DATA and WRITE_BYTE? This is a real question, I just don't know what the difference is (and I realize I may have set the wrong ones in the only driver I wrote so far).

8* The init function could be shortened using memset() (for setting digits to 0x00). Also, you are not using the auto-increment feature as described in the datasheet. I don't know if it is possible with our i2c subsystem. Maybe that's what WRITE_I2C_BLOCK is for? (Just wondering, I don't know much about this.)

9* I'm a bit skeptical about saa1064_update_client. (See 3*.) I don't think you need an update function since your driver is write only by nature. I don't know if you can remove it completely though. (As you can see, there are really many things I don't know yet).

10* I suggest you be more flexible about the user writing too many values to your sysctl files. You basically don't need to care about that. Just ignore the extra values. I think that's what most of our drivers do.

That's it. Don't be afraid because I seem to criticize much. It's actually very good work. I just want to make it even better (perfect if we only could). Each of the points above is subject to discussion, so I want to hear you!

Thanks for the good work so far :)

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#2 lore raw
In reply to Sascha Volkenandt
Quoted 5 lines · At Freitag, 18. Juli 2003 12:38 Jean Delvare wrote:

1* Your second comment about the saa1064 is inaccurate (if my understanding is correct). You say you have to write to the 5 registers at once. It isn't true. You *can* do so, but the saa1064 is much more flexible than that. You can start writting at any address and stop [...]

Yes, that's an outdated piece of comment. I merely forgot to correct it :-)

Quoted 5 lines

2* I would unify the two "blank" sysctl files into one single file with
2 values. What's more, I would change the convention. You have 0 > blanked, 1 = not blanked, because it's that way in the datasheet, but it won't make much sense for the user. So I think you should either rename
the sysctl file and associated data to, say, "display", or, preferably,
I would decide that 1 stands for blanked.

That's a good idea, I think I'll just do it. Maybe I should even but the dynamic flag into this sysctl, as well, since the blank bits are IMHO unnecessary when dynamic mode is on. As far as I've understood, dynamic mode means all digits are displayed repeatedly (at a very fast rate so the viewer doesn't notice), and in static mode only those digits not blanked by blank13/24 are shown.

I'll check that again, if this is the case all could be reduced to one tri-state sysctl (0=display all four digits, 1=display 1+3, 2=display 2+4). What do you think?

Quoted 8 lines

3* I'm not sure about the pwrloss sysctl file. How do you intend to use [...]
write) but would poll the power loss flag. If it find it is set, it would write the internal data to the chip. I think it makes more sense that way than letting the user know (in userspace) a power loss has occured and leave him/her handle it. I think you should try powering it off while in use and see what happens. That way, we will know what the user will want to be done.

I've already checked that yesterday (when re-checking detection), and if the power is unplugged while the device is running, the old sysctl pwrloss gives a 1 once. That's exactly the expected behaviour, after powering *on* the device, a read returns 0x80 *once*.

I'll implement your "refresh" suggestion - by the way is it really possible to write to a read-only (mode 0444) sysctl??!

Quoted 2 lines

4* BTW, the power loss flag is the MSB in the status register, not the LSB, so SAA1064_STAT_PWRLOSS should be set to 0x80.

How in the world did i get *that* wrong??! :-) Clearly a bug, will be fixed.

Quoted 3 lines

5* SAA1064_CTRL_SET_BRIGHT(c,val) is not safe. You don't limit the change to 3 bits. I would add a "& 0x07" for safety (no real danger though, I admit).

I've thought about that and found it not dangerous, too. I didn't know if you folks count on that kind of construct, or maybe even dislike it. I'll put it in now I know it's ok :-).

Quoted 3 lines

6* You don't have to define a saa1064_write_value function. This is done in some drivers (lm75 for example) because the function actually does something, but for simple drivers there is no need for such a function.

I've used it when transferring the data via i2c_master_send (since the values had to be packed into a byte-array then), and merely left it intact while switching to i2c_smbus_write_byte_data. I'll remove it.

Quoted 5 lines

7* You can use a single call to i2c_check_functionality instead of two by or'ing the constants. BTW, why are you using READ_BYTE and WRITE_BYTE_DATA, but not READ_BYTE_DATA and WRITE_BYTE? This is a real question, I just don't know what the difference is (and I realize I may have set the wrong ones in the only driver I wrote so far).

Well since i use i2c_smbus_write_byte_data(i2c_client*, u8, u8) and i2c_smbus_read_byte(i2c_client*), I thought it would be best to check the same funcs that I'm using :-) (WRITE_BYTE_DATA for write_byte_data and READ_BYTE for read_byte). The difference is, that the _data functions expect a register address to write to/read from, and the ones without _data merely write a byte to the bus with no register address. Since the read register has no address, I use i2c_smbus_read_byte instead of .._byte_data.

Quoted 5 lines

8* The init function could be shortened using memset() (for setting digits to 0x00). Also, you are not using the auto-increment feature as described in the datasheet. I don't know if it is possible with our i2c subsystem. Maybe that's what WRITE_I2C_BLOCK is for? (Just wondering, I don't know much about this.)

I'll put memset in. Well I was successful in writing a block of data using i2c_master_send, but since i2c_check_functionality claims that plain I2C-commands are not possible with a primitive parallelport adapter, I decided to use the smbus functions again. I'll check if I can make use of any of the block write functions for the digits (and for the combined "blank" sysctl).

Quoted 4 lines

9* I'm a bit skeptical about saa1064_update_client. (See 3*.) I don't think you need an update function since your driver is write only by nature. I don't know if you can remove it completely though. (As you can see, there are really many things I don't know yet).

I just adapted the pcf8574 behaviour of reading the only register in update_client, which is only done if the last read has been some time earlier (the jiffies count is compared there). I think this isn't very safe, since two reads with only a very short delay between would both return "1" for powerloss (but the bit has been reset in the meantime). I think this function won't be necessary anymore if I implement the "refresh" sysctl instead.

Anyway I've even found a driver in your package containing the update_client skeleton, saying /* Nothing yet */ instead of doing anything (except updating the jiffies count).

Quoted 4 lines

10* I suggest you be more flexible about the user writing too many values to your sysctl files. You basically don't need to care about that. Just ignore the extra values. I think that's what most of our drivers do.

You mean, remove that "this device has only 4 digits" message? Well, I'll embrace it with #ifdef DEBUG..#endif, just to be sure :-)))

Quoted 4 lines

That's it. Don't be afraid because I seem to criticize much. It's actually very good work. I just want to make it even better (perfect if we only could). Each of the points above is subject to discussion, so I want to hear you!

That's what you get, and don't you be afraid, since I'm working in the field of Quality Assurance currently, I know how it's like to be criticized as a programmer, as well as how it's like to actually criticize a programmer myself :-)

Quoted 1 line

Thanks for the good work so far :)

And that's the sentence where the flames lighten up again :-))

BTW: Concerning your new sensors-detect, I'll check it tomorrow or sunday, since my only i2c-machine has a really small installation (10 MB so far) and I think you understand there's no perl yet, within 10 MB, so I have to install it first :-)

Greetings,
Sascha

#3 lore raw
In reply to Sascha Volkenandt
Quoted 16 lines
Quoted 8 lines

2* I would unify the two "blank" sysctl files into one single file with 2 values. What's more, I would change the convention. You have 0 = blanked, 1 = not blanked, because it's that way in the datasheet, but it won't make much sense for the user. So I think you should either rename the sysctl file and associated data to, say, "display", or, preferably, I would decide that 1 stands for blanked.

That's a good idea, I think I'll just do it. Maybe I should even but the dynamic flag into this sysctl, as well, since the blank bits are IMHO unnecessary when dynamic mode is on. As far as I've understood, dynamic mode means all digits are displayed repeatedly (at a very fast rate so the viewer doesn't notice), and in static mode only those digits not blanked by blank13/24 are shown.

Quoted 3 lines

I'll check that again, if this is the case all could be reduced to one tri-state sysctl (0=display all four digits, 1=display 1+3, 2=display 2+4). What do you think?

I'm not sure. I read the datasheet again, and I find a total of 7 possibilities, not 3 as you seem to think. I even took a sheet of paper and a pencil to draw a nice table. Yes, really. I can scan it and send it to you if you want ;) In the meantime, I'll try to recap my findings here.

I think we agree on the fact that C0, C1 and C2 values all have an effect on what is displayed. So lets try to see what is displayed for all possible values (8) of C2C1C0. I'll represent the four digits in the order "1 2 3 4". If they are actually in the order "4 3 2 1", just invert the results. It won't change the meaning anyway. I use an "8" to say a digit is used, a white space to say a digit is blanked.

Static mode:

C2C1C0 1 2 3 4
0 0 0
0 1 0 8
1 0 0 8
1 1 0 8 8

Dynamic mode:

C2C1C0 1 2 3 4
0 0 1
0 1 1 8 8
1 0 1 8 8
1 1 1 8 8 8 8

So as you can see, except for the fact that dynamic mode is useless if C2C1=00, all other modes are different.

Now the real point is to know what you need as a user. The fact that we can do all that with that chip does not mean you have to implement it in your driver. If there is no need for that in userland, just don't implement it.

One think I don't really understand is the reason they did these flags after all. In which way is it different to blank one digit and to display nothing (I guess the value is 0x00) on it? Does it show in a different way on your display (such as very low light vs. no light at all)? Or maybe is it faster to "unhide" a digit than to set it's value? In this case, we could imagine that some users want to write the value while the digit is blanked, and display it "at once"? However, I doubt this is the case, because the display change speed must be limited by the physical speed of the leds more than by any other factor. Third possibility, this allows one to keep the value "in memory" while not displaying it. Maybe interesting in some cases, but I don't see the need in our case.

Since you are the only user, can you tell me your point about all these? I really think we should not use these bits unless we have a real reason to do so. I will still be possible to add them later if we want to.

(3*)

Quoted 2 lines

I'll implement your "refresh" suggestion - by the way is it really possible to write to a read-only (mode 0444) sysctl??!

Of course not, but you could make it write-only (mode 0222 or 0200, at your option). Anyway, I think it's better to make it read only, and trigger the refresh on read. It's more in the spirit of the other driver, so to say.

Quoted 7 lines
Quoted 3 lines

5* SAA1064_CTRL_SET_BRIGHT(c,val) is not safe. You don't limit the change to 3 bits. I would add a "& 0x07" for safety (no real danger though, I admit).

I've thought about that and found it not dangerous, too. I didn't know if you folks count on that kind of construct, or maybe even dislike it. I'll put it in now I know it's ok :-).

I don't think we have a policy for that. Our drivers have been written by dozens of different people, so it's kind of hard to be really strict on all things (and why would we want to?). I guess I should have kept quiet this time ;) In my own driver, I remember I skipped some limit checking too, for code simplicity. So do as you want.

Quoted 7 lines
Quoted 6 lines

7* You can use a single call to i2c_check_functionality instead of two by or'ing the constants. BTW, why are you using READ_BYTE and WRITE_BYTE_DATA, but not READ_BYTE_DATA and WRITE_BYTE? This is a real question, I just don't know what the difference is (and I realize I may have set the wrong ones in the only driver I wrote so far).

Quoted 8 lines

Well since i use i2c_smbus_write_byte_data(i2c_client*, u8, u8) and i2c_smbus_read_byte(i2c_client*), I thought it would be best to check the same funcs that I'm using :-) (WRITE_BYTE_DATA for write_byte_data and READ_BYTE for read_byte). The difference is, that the _data functions expect a register address to write to/read from, and the ones without _data merely write a byte to the bus with no register address. Since the read register has no address, I use i2c_smbus_read_byte instead of .._byte_data.

Oh of course, it's all clear to me know. That's rather logical. Anyway I guess I'll end up reading the I2C specs (at least this part) to know more about the different modes, and what happens if one uses a mode the chip does not particularly like. I really would like to know that, because that's what I do for the SAA1064 in sensors-detect. I use the READ_DATA_BYTE mode while the SAA1064 want READ_BYTE mode. I wonder what will happen... Well, you tell me when you try ;)

Quoted 8 lines
Quoted 4 lines

9* I'm a bit skeptical about saa1064_update_client. (See 3*.) I don't think you need an update function since your driver is write only by nature. I don't know if you can remove it completely though. (As you can see, there are really many things I don't know yet).

I just adapted the pcf8574 behaviour of reading the only register in update_client, which is only done if the last read has been some time earlier (the jiffies count is compared there).

The PCF8574 has a readable register, really? Could not find in in the datasheet. That could help me detect it in sensors-detect... (Some reading after) Hm, it ain't a register but the I/O value, so I can't assume anything about it. It can have any value and even change if it is in input mode (I'm not sure I really understand how input vs. output works though).

Quoted 3 lines

I think this isn't very
safe, since two reads with only a very short delay between would both return "1" for powerloss (but the bit has been reset in the meantime).

I hadn't think about that. Well seen.

Quoted 2 lines

I think this function won't be necessary anymore if I implement the "refresh" sysctl instead.

Right.

Quoted 3 lines

Anyway I've even found a driver in your package containing the update_client skeleton, saying /* Nothing yet */ instead of doing anything (except updating the jiffies count).

OK, this means you can do just the same if you don't have anything do to there anymore.

Quoted 7 lines
Quoted 4 lines

10* I suggest you be more flexible about the user writing too many values to your sysctl files. You basically don't need to care about that. Just ignore the extra values. I think that's what most of our drivers do.

You mean, remove that "this device has only 4 digits" message? Well, I'll embrace it with #ifdef DEBUG..#endif, just to be sure :-)))

That, plus replacing "if (*nrels_mag = 1)" with "if (*nrels_mag >= 1)" for the other files. I think most of our drivers do that.

Quoted 4 lines

BTW: Concerning your new sensors-detect, I'll check it tomorrow or sunday, since my only i2c-machine has a really small installation (10 MB so far) and I think you understand there's no perl yet, within 10 MB, so I have to install it first :-)

Of course. You know it could increase your disk usage by up to 180%? :/ My perl package uses 18MB. You don't need all the modules though, and I guess you'll remove the whole think as soon as the tests are over.

Thanks for your help and good work.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#4 lore raw
In reply to Sascha Volkenandt
Quoted 11 lines · At Samstag, 19. Juli 2003 09:50 you wrote:
Quoted 3 lines

I'll check that again, if this is the case all could be reduced to one tri-state sysctl (0=display all four digits, 1=display 1+3, 2=display 2+4). What do you think?

I'm not sure. I read the datasheet again, and I find a total of 7 possibilities, not 3 as you seem to think. I even took a sheet of paper and a pencil to draw a nice table. Yes, really. I can scan it and send it to you if you want ;) In the meantime, I'll try to recap my findings here.

[...]

I've checked this, and - well your assumptions were not quite correct (for static mode) - neither were mine :-). I don't know why this might have been implemented, here are the results:

C2C1C0 1 2 3 4
static

 0 0 0  8   8
 0 1 0  8   8
 1 0 0  8   8
 1 1 0  8   8

dynamic
0 0 1
0 1 1 8 8
1 0 1 8 8
1 1 1 8 8 8 8

The only difference is, that in static mode the digits are slighty brighter than in dynamic mode (even when only displaying two digits).

I think just leaving them out and using dynamic mode with all digits lit might be just fine, unless anyone tells me he actually needs this.

Quoted 7 lines

Oh of course, it's all clear to me know. That's rather logical. Anyway I guess I'll end up reading the I2C specs (at least this part) to know more about the different modes, and what happens if one uses a mode the chip does not particularly like. I really would like to know that, because that's what I do for the SAA1064 in sensors-detect. I use the READ_DATA_BYTE mode while the SAA1064 want READ_BYTE mode. I wonder what will happen... Well, you tell me when you try ;)

I guess this chip just ignores any read-address, since all reads (with read-address and without) result in 0x80 if the device has just been powered up, 0x00 otherwise.

Quoted 6 lines

The PCF8574 has a readable register, really? Could not find in in the datasheet. That could help me detect it in sensors-detect... (Some reading after) Hm, it ain't a register but the I/O value, so I can't assume anything about it. It can have any value and even change if it is in input mode (I'm not sure I really understand how input vs. output works though).

I think it is implemented by setting an output bit to "1" , then re-reading it and it will change to "0" when pulled to GND. Just an assumption from what I remember about that subject :-)

Quoted 3 lines

Of course. You know it could increase your disk usage by up to 180%? :/ My perl package uses 18MB. You don't need all the modules though, and I guess you'll remove the whole think as soon as the tests are over.

I think I'll have two installations, then I can zip the large one whenever I don't need it. Who knows what changes after I delete it :-)

Greetings,
Sascha