I2C & SPI driver

1k views Asked by At

Recently, I have been writing a camera driver use I2C interface read/write registers, and use spi interface to write firmware data to it. So my question is how to obtain a spi_device pointer in the I2C driver?

Thanks.

3

There are 3 answers

1
user2879844 On

Why you need SPI handle in I2C driver.Currently I am assuming u mean application i.e. the place where you are writing/reading registers and writing firmware.U need to open both I2C ans SPI instances using the function that is returning the respective handle.

0
Dražen Grašovec On

You can register two separate drivers, SPI and I2C from one I2C driver.

You have to define your device structure containing spi_driver and spi_device

And from I2C probe() you register your spi_driver and initialize spi_device from SPI probe()function.

0
QQVEI On

Got the same question as you. After a while of digging in the kernel. I found this: https://elixir.bootlin.com/linux/v4.9.80/source/drivers/media/i2c/s5c73m3/s5c73m3-spi.c#L123. You will need to define an spi_driver in your driver's private data, and then use that to register an SPI driver. In the probe function of SPI, you will be able to retrieve the private data from the pointer of the SPI driver.

Note: I don't know if the same trick works on other versions of Linux kernel. But I think it worth a try.