[U-Boot-Users] soft_i2c and ds1307 with tqm823l

Hi,
I'm working on getting a ds1307 realtime clock working with a tqm823l as a new user to u-boot (I've never compiled u-boot or ppcboot before).
I'd like to make some improvements to the README which is already excellent but seems to have a couple of omissions, particularly regarding the configuration of u-boot to work with i2c.
Firstly, the ds1307 code compiles fine, but of course it needs the i2c code to be compiled alongside it. Although this is obvious, the newcomer to u-boot doesn't (i.e. I didn't) know that calling for ds1307.c to be compiled doesn't in itself cause the i2c code to be compiled, so a note to this effect in the realtime clock section of the README would be a helpful addition.
Now, in trying to get I2C properly compiled, I find quite a lot of information about I2C setup in the README.
Here's a line from the README (starting at line 907):
"If this is selected, either CONFIG_HARD_I2C or CONFIG_SOFT_I2C must be defined to include the appropriate I2C driver."
No mention is made of what values the 'appropriate driver' might have or where to look for them. I assume you might define something like this:
#define CONFIG_HARD_I2C mpc8xx
But I can't see what you'd write for CONFIG_SOFT_I2C. A bit more clarification here would be useful.
There are a number of extra defines related to CONFIG_SOFT_I2C, such as I2C_INIT, I2C_PORT, etc. It's not too clear what these should be set to. The diff between my TQM823L.h and the original TQM823L.h is (also attached as changes.diff):
Some investigation has shown that I need to set I2C_SDA and I2C_SCL to the name of the correct functions. What are the possibilities for these? The same seems to be true of I2C_READ.
What are the units for I2C_DELAY? I'm assuming seconds. Why is there both I2C_DELAY and CFG_I2C_SPEED to configure? These seem to configure the same thing - the speed of the I2C clock line.
Ok, I think that should be enough for now,
best regards,
Seb James.

Just a couple of edits to my posting.
Seb James wrote:
Hi,
I'm working on getting a ds1307 realtime clock working with a tqm823l as a new user to u-boot (I've never compiled u-boot or ppcboot before).
I'd like to make some improvements to the README which is already excellent but seems to have a couple of omissions, particularly regarding the configuration of u-boot to work with i2c.
Firstly, the ds1307 code compiles fine, but of course it needs the i2c code to be compiled alongside it...
...in order to be able to link it into the u-boot image.
Although this is obvious, the newcomer to u-boot doesn't (i.e. I didn't) know that calling for ds1307.c to be compiled doesn't in itself cause the i2c code to be compiled, so a note to this effect in the realtime clock section of the README would be a helpful addition.
Now, in trying to get I2C properly compiled, I find quite a lot of information about I2C setup in the README.
Here's a line from the README (starting at line 907):
"If this is selected, either CONFIG_HARD_I2C or CONFIG_SOFT_I2C must be defined to include the appropriate I2C driver."
No mention is made of what values the 'appropriate driver' might have or where to look for them. I assume you might define something like this:
#define CONFIG_HARD_I2C mpc8xx
But I can't see what you'd write for CONFIG_SOFT_I2C. A bit more clarification here would be useful.
There are a number of extra defines related to CONFIG_SOFT_I2C, such as I2C_INIT, I2C_PORT, etc. It's not too clear what these should be set to.
Regarding this line:
The diff between my TQM823L.h and the original TQM823L.h is (also attached as changes.diff):
sorry - the diff wasn't attached, this line shouldn't have been in the posting. I was going to do this and then decided it wasn't necessary.
Some investigation has shown that I need to set I2C_SDA and I2C_SCL to the name of the correct functions. What are the possibilities for these? The same seems to be true of I2C_READ.
What are the units for I2C_DELAY? I'm assuming seconds. Why is there both I2C_DELAY and CFG_I2C_SPEED to configure? These seem to configure the same thing - the speed of the I2C clock line.
Ok, I think that should be enough for now,
best regards,
Seb James.
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01 _______________________________________________ U-Boot-Users mailing list U-Boot-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/u-boot-users

In message 3F002ED5.4050803@peak.uklinux.net you wrote:
Some investigation has shown that I need to set I2C_SDA and I2C_SCL to the name of the correct functions. What are the possibilities for these? The same seems to be true of I2C_READ.
These are macros that define code (think of inline functions) to set the SDA resp. SCL port pin to high (bit=1) or low (bit-0). I2C_READ will read the state of the SDA port pin.
Isn't this obvious from the sources?
What are the units for I2C_DELAY? I'm assuming seconds. Why is there
Again, see the source code. A definition like this should be self-explainatory:
#define I2C_DELAY udelay(5) /* 1/4 I2C clock duration */
both I2C_DELAY and CFG_I2C_SPEED to configure? These seem to configure the same thing - the speed of the I2C clock line.
Hysterical reasons. I2C_DELAY => soft_i2c, CFG_I2C_SPEED => hard-i2c
Best regards,
Wolfgang Denk

Dear Seb,
in message 3F002BCA.9070609@peak.uklinux.net you wrote:
I'm working on getting a ds1307 realtime clock working with a tqm823l as a new user to u-boot (I've never compiled u-boot or ppcboot before).
This is not correct. You compiled and installed PPCBoot in our training a year and a couple of days ago :-)
Firstly, the ds1307 code compiles fine, but of course it needs the i2c code to be compiled alongside it. Although this is obvious, the newcomer to u-boot doesn't (i.e. I didn't) know that calling for ds1307.c to be compiled doesn't in itself cause the i2c code to be compiled, so a note to this effect in the realtime clock section of the README would be a helpful addition.
Please feel free to submit a patch...
Here's a line from the README (starting at line 907):
"If this is selected, either CONFIG_HARD_I2C or CONFIG_SOFT_I2C must be defined to include the appropriate I2C driver."
No mention is made of what values the 'appropriate driver' might have or where to look for them. I assume you might define something like this:
#define CONFIG_HARD_I2C mpc8xx
No. Just "#define CONFIG_HARD_I2C" is OK, as for each CPU there is always exactly one hard-i2c and one soft-i2c driver.
But I can't see what you'd write for CONFIG_SOFT_I2C. A bit more clarification here would be useful.
Just: #define CONFIG_SOFT_I2C
It must be defined - that's all :-)
There are a number of extra defines related to CONFIG_SOFT_I2C, such as I2C_INIT, I2C_PORT, etc. It's not too clear what these should be set to. The diff between my TQM823L.h and the original TQM823L.h is (also attached as changes.diff):
No diff attached.
Best regards,
Wolfgang Denk

Thanks for the help Wolfgang,
Wolfgang Denk wrote:
Dear Seb,
in message 3F002BCA.9070609@peak.uklinux.net you wrote:
I'm working on getting a ds1307 realtime clock working with a tqm823l as a new user to u-boot (I've never compiled u-boot or ppcboot before).
This is not correct. You compiled and installed PPCBoot in our training a year and a couple of days ago :-)
That's true. Ok, not for a while though...
Firstly, the ds1307 code compiles fine, but of course it needs the i2c code to be compiled alongside it. Although this is obvious, the newcomer to u-boot doesn't (i.e. I didn't) know that calling for ds1307.c to be compiled doesn't in itself cause the i2c code to be compiled, so a note to this effect in the realtime clock section of the README would be a helpful addition.
Please feel free to submit a patch...
Yes, I'll do that when I'm sure I think there needs to be one and what it should be :)
Here's a line from the README (starting at line 907):
"If this is selected, either CONFIG_HARD_I2C or CONFIG_SOFT_I2C must be defined to include the appropriate I2C driver."
No mention is made of what values the 'appropriate driver' might have or where to look for them. I assume you might define something like this:
#define CONFIG_HARD_I2C mpc8xx
No. Just "#define CONFIG_HARD_I2C" is OK, as for each CPU there is always exactly one hard-i2c and one soft-i2c driver.
But I can't see what you'd write for CONFIG_SOFT_I2C. A bit more clarification here would be useful.
Just: #define CONFIG_SOFT_I2C
It must be defined - that's all :-)
Ok, well I've successfully compiled with CONFIG_HARD_I2C and have communicated with my clock, so that is good. Next up is transferring the date in u-boot to linux, but I'm sure that will be documented somewhere.
As for CONFIG_SOFT_I2C; Attached (really this time) is a diff between the original u-boot-0.4.0/include/configs/TQM823L.h and the one that I have altered. The compile of soft_i2c.c fails with the following error messages:
ppc_8xx-gcc -g -Os -mrelocatable -ffixed-r14 -meabi -D__KERNEL__ -DTEXT_BASE=0x40000000 -I/eldk/ppc_8xx/usr/src/u-boot-0.4.0/include -fno-builtin -nostdinc -isystem /eldk/usr/lib/gcc-lib/ppc-linux/2.95.4/include -pipe -DCONFIG_PPC -D__powerpc__ -DCONFIG_8xx -ffixed-r2 -ffixed-r29 -mstring -mcpu=860 -msoft-float -Wall -Wstrict-prototypes -c -o soft_i2c.o soft_i2c.c soft_i2c.c: In function `send_reset': soft_i2c.c:86: warning: implicit declaration of function `I2C_SCL' soft_i2c.c:87: warning: implicit declaration of function `I2C_SDA' soft_i2c.c:91: `I2C_TRISTATE' undeclared (first use in this function) soft_i2c.c:91: (Each undeclared identifier is reported only once soft_i2c.c:91: for each function it appears in.) soft_i2c.c:94: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:82: warning: unused variable `immr' soft_i2c.c: In function `send_start': soft_i2c.c:116: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:118: `I2C_ACTIVE' undeclared (first use in this function) soft_i2c.c:113: warning: unused variable `immr' soft_i2c.c: In function `send_stop': soft_i2c.c:139: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:141: `I2C_ACTIVE' undeclared (first use in this function) soft_i2c.c:147: `I2C_TRISTATE' undeclared (first use in this function) soft_i2c.c:135: warning: unused variable `immr' soft_i2c.c: In function `send_ack': soft_i2c.c:163: `I2C_ACTIVE' undeclared (first use in this function) soft_i2c.c:165: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:160: warning: unused variable `immr' soft_i2c.c: In function `write_byte': soft_i2c.c:193: `I2C_ACTIVE' undeclared (first use in this function) soft_i2c.c:196: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:212: `I2C_TRISTATE' undeclared (first use in this function) soft_i2c.c:217: `I2C_READ' undeclared (first use in this function) soft_i2c.c:188: warning: unused variable `immr' soft_i2c.c:191: warning: `nack' might be used uninitialized in this function soft_i2c.c: In function `read_byte': soft_i2c.c:244: `I2C_TRISTATE' undeclared (first use in this function) soft_i2c.c:248: `I2C_DELAY' undeclared (first use in this function) soft_i2c.c:252: `I2C_READ' undeclared (first use in this function) soft_i2c.c:236: warning: unused variable `immr' make[1]: *** [soft_i2c.o] Error 1 make[1]: Leaving directory `/eldk/ppc_8xx/usr/src/u-boot-0.4.0/common' make: *** [subdirs] Error 1 [seb@mst26 u-boot-0.4.0]$
50c50 < #define CONFIG_BOOTDELAY 5 /* autoboot after 5 seconds */ ---
#define CONFIG_BOOTDELAY 1 /* autoboot after 1 second */
73,74c73,74 < "rootpath=/opt/eldk/ppc_8xx\0" \ < "bootfile=/tftpboot/TQM860L/uImage\0" \ ---
"rootpath=/eldk/ppc_8xx\0" \ "bootfile=/tftpboot/pImage\0" \
98c98,112 < #define CONFIG_RTC_MPC8xx /* use internal RTC of MPC8xx */ ---
#define CONFIG_RTC_DS1307 /* Use ds1307 as realtime clock */
#define CONFIG_SOFT_I2C /* Include I2C functionality */ //#define CONFIG_HARD_I2C
#define CFG_I2C_SPEED 100000 /* I want to run at 100 kHz */ #define CFG_I2C_SLAVE 0 /* My mpc8xx should be the i2c master */
//#define I2C_TRISTATE NULL /* mpc8xx has open drain output */ //#define I2C_ACTIVE NULL /* mpc8xx has open drain output */ //#define I2C_READ some_macro /* if you want this function defined */ //#define I2C_SDA some_macro /* if you want this function defined */ //#define I2C_SCL some_macro /* if you want this function defined */ //#define I2C_DELAY 0.0000025 /* I want 100 kHz, so this is the // delay in seconds that I think is required */
103a118
CFG_CMD_I2C | \

In message 3F0037AA.7060205@peak.uklinux.net you wrote:
This is not correct. You compiled and installed PPCBoot in our training a year and a couple of days ago :-)
That's true. Ok, not for a while though...
:-)
Please feel free to submit a patch...
Yes, I'll do that when I'm sure I think there needs to be one and what it should be :)
There shouldbe one. You asked these questions after all - prrof that such an explanation is needed.
Ok, well I've successfully compiled with CONFIG_HARD_I2C and have communicated with my clock, so that is good. Next up is transferring the date in u-boot to linux, but I'm sure that will be documented somewhere.
You don't "transfer" the daye. Linux will pick it up itself (which requires an RTC driver and eventually some modifications).
As for CONFIG_SOFT_I2C; Attached (really this time) is a diff between the original u-boot-0.4.0/include/configs/TQM823L.h and the one that I have altered. The compile of soft_i2c.c fails with the following error messages:
That's because you did not define the required macros (see for example the configuration in lwmon.h).
Best regards,
Wolfgang Denk

Wolfgang Denk wrote: [ snip ]
Ok, well I've successfully compiled with CONFIG_HARD_I2C and have communicated with my clock, so that is good. Next up is transferring the date in u-boot to linux, but I'm sure that will be documented somewhere.
You don't "transfer" the daye. Linux will pick it up itself (which requires an RTC driver and eventually some modifications).
Let me check that I understand: As far as I can see the u-boot realtime clock drivers just allow you to set and read the time from the u-boot command line; a useful utility. If linux is to read the time from the realtime clock it must have a realtime clock driver of its own; there's no way that u-boot can pass the time to linux at boot time? (Of course, this would be fraught with difficulties, because depending on how fast your cpu boots linux, a different amount of time would elapse before linux could actually do something with the passed date stamp).
So, next up for me is to write a linux driver for the ds1307. I was actually in the middle of that before getting sidetracked by the u-boot rtc code. However, the u-boot code has enabled me to hardware debug my realtime clock circuit, so that was very useful. Has anyone written a linux driver for the ds1307 or similar? (I'm cross posting to the linuxppc-embedded list to ask this question).
As for CONFIG_SOFT_I2C; Attached (really this time) is a diff between the original u-boot-0.4.0/include/configs/TQM823L.h and the one that I have altered. The compile of soft_i2c.c fails with the following error messages:
That's because you did not define the required macros (see for example the configuration in lwmon.h).
Right, so it's not the case that you just #define CONFIG_SOFT_I2C; you have to correctly define the macros. I shall do some work on the readme and post a diff later on. Thanks for the pointers.
best,
Seb

Dear Seb,
in message 3F004440.6000301@peak.uklinux.net you wrote:
command line; a useful utility. If linux is to read the time from the realtime clock it must have a realtime clock driver of its own; there's no way that u-boot can pass the time to linux at boot time? (Of course,
Correct.
Best regards,
Wolfgang Denk

Wolfgang Denk wrote:
Dear Seb,
in message 3F004440.6000301@peak.uklinux.net you wrote:
command line; a useful utility. If linux is to read the time from the realtime clock it must have a realtime clock driver of its own; there's no way that u-boot can pass the time to linux at boot time? (Of course,
Correct.
Ok. Here is a diff (created as specified in the README) of the README. The old file is the README file that came in the u-boot-0.4.0 tarball. The changes that I've made are some extra information to help someone to add i2c and realtime clock support to u-boot.
Seb.
--- README 2003-06-21 00:10:58.000000000 +0100 +++ README.new 2003-06-30 15:51:30.000000000 +0100 @@ -653,6 +653,9 @@ The following options need to be configu CONFIG_RTC_DS1338 - use Maxim, Inc. DS1338 RTC CONFIG_RTC_DS164x - use Dallas DS164x RTC
+ Note that if the RTC uses I2C, then the I2C interface + must also be configured. See I2C Support, below. + - Timestamp Support:
When CONFIG_TIMESTAMP is selected, the timestamp @@ -904,29 +907,48 @@ The following options need to be configu
- I2C Support: CONFIG_HARD_I2C | CONFIG_SOFT_I2C
- Enables I2C serial bus commands. If this is selected, - either CONFIG_HARD_I2C or CONFIG_SOFT_I2C must be defined - to include the appropriate I2C driver. - - See also: common/cmd_i2c.c for a description of the + These enable I2C serial bus commands. Defining either of + (but not both of) CONFIG_HARD_I2C or CONFIG_SOFT_I2C will + include the appropriate I2C driver for the selected cpu. + + This will allow you to use i2c commands at the u-boot + command line (as long as you set CFG_CMD_I2C in + CONFIG_COMMANDS) and communicate with i2c based realtime + clock chips. See common/cmd_i2c.c for a description of the command line interface.
+ CONFIG_HARD_I2C selects the CPM hardware driver for I2C.
- CONFIG_HARD_I2C - - Selects the CPM hardware driver for I2C. - - CONFIG_SOFT_I2C - - Use software (aka bit-banging) driver instead of CPM - or similar hardware support for I2C. This is configured - via the following defines. + CONFIG_SOFT_I2C configures u-boot to use a software (aka + bit-banging) driver instead of CPM or similar hardware + support for I2C. + + There are several other quantities that must also be + defined when you define CONFIG_HARD_I2C or CONFIG_SOFT_I2C. + + In both cases you will need to define CFG_I2C_SPEED + to be the frequency (in Hz) at which you wish your i2c bus + to run and CFG_I2C_SLAVE to be the address of this node (ie + the cpu's i2c node address). + + Now, the u-boot i2c code for the mpc8xx (cpu/mpc8xx/i2c.c) + sets the cpu up as a master node and so its address should + therefore be cleared to 0 (See, eg, MPC823e User's Manual + p.16-473). So, set CFG_I2C_SLAVE to 0. + + That's all that's required for CONFIG_HARD_I2C. + + If you use the software i2c interface (CONFIG_SOFT_I2C) + then the following macros need to be defined (examples are + from include/configs/lwmon.h):
I2C_INIT
- (Optional). Any commands necessary to enable I2C + (Optional). Any commands necessary to enable the I2C controller or configure ports.
+ eg: #define I2C_INIT (immr->im_cpm.cp_pbdir |= PB_SCL) + I2C_PORT
(Only for MPC8260 CPU). The I/O port to use (the code @@ -939,32 +961,49 @@ The following options need to be configu (driven). If the data line is open collector, this define can be null.
+ eg: #define I2C_ACTIVE (immr->im_cpm.cp_pbdir |= PB_SDA) + I2C_TRISTATE
The code necessary to make the I2C data line tri-stated (inactive). If the data line is open collector, this define can be null.
+ eg: #define I2C_TRISTATE (immr->im_cpm.cp_pbdir &= ~PB_SDA) + I2C_READ
Code that returns TRUE if the I2C data line is high, FALSE if it is low.
+ eg: #define I2C_READ ((immr->im_cpm.cp_pbdat & PB_SDA) != 0) + I2C_SDA(bit)
If <bit> is TRUE, sets the I2C data line high. If it is FALSE, it clears it (low).
+ eg: #define I2C_SDA(bit) \ + if(bit) immr->im_cpm.cp_pbdat |= PB_SDA; \ + else immr->im_cpm.cp_pbdat &= ~PB_SDA + I2C_SCL(bit)
If <bit> is TRUE, sets the I2C clock line high. If it is FALSE, it clears it (low).
+ eg: #define I2C_SCL(bit) \ + if(bit) immr->im_cpm.cp_pbdat |= PB_SCL; \ + else immr->im_cpm.cp_pbdat &= ~PB_SCL + I2C_DELAY
This delay is invoked four times per clock cycle so this controls the rate of data transfer. The data rate thus - is 1 / (I2C_DELAY * 4). + is 1 / (I2C_DELAY * 4). Often defined to be something + like: + + #define I2C_DELAY udelay(2)
CFG_I2C_INIT_BOARD

In message 3F005003.7020202@peak.uklinux.net you wrote:
Ok. Here is a diff (created as specified in the README) of the README. The old file is the README file that came in the u-boot-0.4.0 tarball.
Thanks, added.
Best regards,
Wolfgang Denk
participants (2)
-
Seb James
-
Wolfgang Denk