1

I'm trying to read and write data off i2c in slave mode and have found several examples to do this in userspace including this most relevant one from NXP (I'm using the iMX8MQ): https://source.codeaurora.org/external/imx/imx-test/tree/test/mxc_i2c_slave_test/mxc_i2c_slave_test.c?h=imx_4.14.78_1.0.0_ga

However, it looks like if I want to read data, it would be a polling based implementation because it looks like i2c-dev does not provide a way to register userspace callbacks when i2c data is available. Not even sure if any Linux device drivers allow doing this at all. Am I correct in assuming that there is no non-blocking and asynchronous way of doing an i2c read from userspace in slave mode?

I'm not very familiar with writing device drivers so even if I wanted to implement my own, similar to this one: https://github.com/torvalds/linux/blob/master/drivers/i2c/i2c-slave-eeprom.c is it a good idea to call a userspace function when data became available (for instance when the driver received an I2C_SLAVE_STOP)?

Gowri
  • 11
  • 3
  • Do `select`, `poll` and other non-blocking functions work with i2c-dev? – domen Jan 29 '19 at 15:52
  • Thanks for your comment. I did come across some posts that talked about this but I think select would only tell you when data became available in the "file" but not really when the i2c transaction was complete? This means that you would have to know the length of the message in advance which I don't in my case. – Gowri Jan 30 '19 at 01:25
  • *If* these work, I'd expect them to signal when transaction completes/fails, not in the middle of it (same as ioctl/read/write for i2c-dev). – domen Jan 30 '19 at 08:32
  • you can use the [fasync](https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch05s04.html) operation in the fops, this will serve your purpose. I have tested this operation with character driver and I think it should also work with i2c device. – yashC Jan 30 '19 at 14:33
  • Drivers should be written in kernel in Linux, they can't perform well in user space. – 0andriy Feb 07 '19 at 16:41

0 Answers0