'How to configure an I2c Controller in the PS of the Zynq 7000 as a slave from Linux

I am using a zed board with a Zynq 7000 on it. The end goal is to have the I2c-0 controller in the physical PS of the Zynq7000 to act as an I2c slave device.

I am using yocto/bitbake to generate linux images for my device. So far, I have been able to map my I2c-0 device SDA and SCK lines to physical pins on the zed board. I have overwritten the zynq-7000.dtsi with my own device tree to enable the i2c0 device.

From the linux shell of my board, I can see the i2c device with "i2cdetect -l" which gives the following output:

root@zed-board:~# i2cdetect -l
i2c-0   i2c             Cadence I2C at e0004000                 I2C adapter

From a simple hello.c program I can use

#include <sys/ioctl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>

to write data with the i2c master and I can see the data coming out of my pins.

However, I have no idea how to configure this device as a slave. I can see from the cadence i2c driver code https://github.com/torvalds/linux/blob/master/drivers/i2c/busses/i2c-cadence.c that slave mode is supported. I just don't know what i need to do so that from a user space application I can put the device into slave mode and register the callbacks for slave events.

Any help is much appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source