Dear Zaheer,
Here is my i2c slave mode test code for i.MX28 EVK board to receive and send arbitrary number of bytes. It is based on BSP L2.6.35_10.12. After patching, the i2c slave test option can be enabled in the kernel configuration.
Device Driver
I2C support
I2C Hardware Bus support --->
[*] MXS I2C SLAVE test
On my MX28 EVK, i2c1 is connected to the i2c0 externally. The i2c0 acts as the master and i2c1 acts as slave. The steps to test the i2c bus is as below:
// prepare i2c slave for receive
$ cd /sys/devices/platform/mxs-i2c-slave.1
$ cat test &
// send data from i2c master
$ cd /sys/devices/platform/mxs-i2c.0
$ echo 7 > test
// prepare i2c slave for send
$ cd /sys/devices/platform/mxs-i2c-slave.1
$ echo 5 > test &
// read data from i2c master
$ cd /sys/devices/platform/mxs-i2c.0
$ cat test
In this patch, the address byte is received in PIO mode and the i2c IRQ handler determine whether this transaction is a i2c read or write. For i2c slave write (master read), it simply setup a dma descriptor to send the number of wanted bytes. For i2c slave read (master write), a dma descriptor is setup to receive 1 byte. Whenever dma complete irq, the received byte is copied to the destination buffer and then setup another dma descriptor to receive the next byte. The i2c slave receive always ends with an i2c early terminate irq. After an i2c slave transfer complete, Both i2c device and its dma channel are reset.
Due to the i.MX28 errata #2836, the i2c slave is not suitable for high data throughput connection.
Hope the above information can help you.
Regards,
Peter