Hi Serguei,
In Linux Kernel codebase (currently I am referring latest Linux Kernel source 3.19), these procedure has been implemented under i2c-mpc.c as below
/* Sometimes 9th clock pulse isn't generated, and slave doesn't release
* the bus, because it wants to send ACK.
* Following sequence of enabling/disabling and sending start/stop generates
* the 9 pulses, so it's all OK.
*/
static void mpc_i2c_fixup(struct mpc_i2c *i2c)
{
int k;
u32 delay_val = 1000000 / i2c->real_clk + 1;
if (delay_val < 2)
delay_val = 2;
for (k = 9; k; k--) {
writeccr(i2c, 0);
writeccr(i2c, CCR_MSTA | CCR_MTX | CCR_MEN);
readb(i2c->base + MPC_I2C_DR);
writeccr(i2c, CCR_MEN);
udelay(delay_val << 1);
}
}
I got confused by seeing this piece of code. Because in linux kernel they are trying to execute these set of steps for 9 times in a loop when they detected bus as busy before initiating a transaction.
Could you please tell me why this discrepancy is there?
What could be the reason that its executing for 9 times in Linux Kernel I2C MPC driver code?
Thanks and Regards,
Kasi