a.saurabh
a.saurabh

Reputation: 1231

How to handle two SPI devices in linux kernel with single SPI Platform Driver?

I have developed a SPI platform driver for a single SPI device.Which SPI device we are using,that configuration can be given in Device Tree.probe() function of SPI platform driver is called when name matching happens with name give in driver and the same present in DT.

In SPI platform driver module_init() method, we register SPI device structure (struct spi_driver spidev_spi_driver) with function call: spi_register_driver().

Please refer to the (static struct spi_driver spidev_spi_driver) in below link for example. Link: http://lxr.free-electrons.com/source/drivers/spi/spidev.c#L664

Here Probe() is one important method registered in this call. When probe function is called, kernel passes pointer of SPI device (e.g struct spi_device *spi) in probe() function which is further utilized in read and write operation with SPI device. All the above procedure happens only once for a single SPI device.

Now I have query here that if I want to use more than one SPI device present in my micro controller e.g. imx6 then how I will handle this situation? How will I receive SPI device pointers in this case? Is the probe function will be called twice (bcoz here only I get SPI device pointers from kernel)? Do I need to create entries such as done in spidev_dt_ids: http://lxr.free-electrons.com/source/drivers/spi/spidev.c#L657

Upvotes: 4

Views: 3247

Answers (1)

shingaridavesh
shingaridavesh

Reputation: 991

I haven't worked on specifically spi device, but I think I might give you some basic idea. The logic is that probe is called whenever there is matching between device->name and device_driver->name. So 2 devices can use same driver but 2 drivers should not be there for same device.

For configuring 2 devices to same driver, the 2 device will be registered on same name and hence same probe will be called. But then in probe you can differentiate. You will have access to the device struct of spi which you can use to set one parameter to distinguish and set the relevant parameters.

One more approach is like using core framework used by i2c in which general functionality functions are made and used by client driver whenever needed.

I hope this helps.

Upvotes: 0

Related Questions