Skip to contentSkip to conversation

i2c_init - is this a bug?

U-Boot-Users Michael 2 participants 2 messages Dec 20, 2006

lore
Share & tools
lore

Michael

author
#0 lore raw

Hi, guys.
Here is something suspicious about i2c_init(int speed, int slaveadd), in i2c.c and fsl_i2c.c -
the speed parameter passed to it is never used, instead the value is hard-coded.

/* set clock */
writeb(0x3f, &I2C->fdr);

Sets the speed.
Shouldn't it be writeb(speed, &I2C->fdr); , with speed being the divider value?

Regards,
Mic

#1 lore raw
Quoted 10 lines · Michael

Hi, guys.
Here is something suspicious about i2c_init(int speed, int slaveadd), in i2c.c and fsl_i2c.c -
the speed parameter passed to it is never used, instead the value is hard-coded.

/* set clock */
writeb(0x3f, &I2C->fdr);

Sets the speed.
Shouldn't it be writeb(speed, &I2C->fdr); , with speed being the divider value?

Yes, the code is currently wrong, but no, 'speed' should not be the divider value.

I have code which calculates the correct value for the FDR based on the real speed, the bus clock rate, and a CPU-specific table lookup. I just haven't gotten around to cleaning it up and submitting it yet. It's on my to-do list for next month.

3F is a conservative value for the bus speed that (so far) works for all Freescale boards. The only drawback is that I2C operations are not as fast as they could be. However, the difference is practically imperceptible, at least in U-Boot. If you were doing heavy I2C I/O in Linux, then you might notice something.

Signature · 2 lines
Timur Tabi
Linux Kernel Developer @ Freescale