mbox series

[0/2] device tree spidev solution - driver_override for SPI

Message ID 20180918224525.28001-1-tpiepho@impinj.com (mailing list archive)
Headers show
Series device tree spidev solution - driver_override for SPI | expand

Message

Trent Piepho Sept. 18, 2018, 10:45 p.m. UTC
This is an attempt to solve the problem of binding spidev to a device on
a device-tree system.

Explicitly listing spidev in the "compatible" property of a device is not
allowed, as it not type of the device but rather a Linux specific driver
name.

The current solution is to list every possible device spidev can be
bound to, but this is highly unsatisfactory.

1.  Needing to patch and compile the kernel is a significant barrier to
many who could otherwise make use of embedded dev kits, such as RPi,
that have SPI hardware.

2.  Up-streaming a new spi device ID is a lengthy undertaking even to
those who know how.  This causes unneeded delay in upstream kernel
support for a new device.

3.  Maintaining a list of obscure and one-off device IDs in the spidev
driver is largely a waste of effort to nearly every developer to use the
driver.

4.  It's not possible to bind a device that has a kernel SPI driver to
spidev instead of its normal driver.  This is quite useful to debug
hardware problems, development of the kernel driver, and testing SPI bus
timing, impedance, etc.  It can also be used to access device features,
like a one time programming step, that the device's kernel driver does
not necessary need to support.

This approach should solve these problems.

Three existing Linux busses - AMBA, PCI, and platform - give device's a
"driver_override" attribute, which can be used to bind them to a driver
without requiring a match against the driver's device ID table.

This can be used to bind spidev to a device without needing to add the
device to some list inside the spidev driver.

Udev rules can be written to make this automatic, example:

ACTION=="add|change",, SUBSYSTEM=="spi", 
    ENV{MODALIAS}=="spi:adrf6820", ATTR{driver_override}+="spidev"

This will automatically bind a device that claims (likely via
device-tree compatible value) to be an "adrf6820" to spidev.  Additional
rules could be imagined to bind specific spi bus chip selects, or any
device on a certain bus, or via the device's node name in the device
tree, to spidev.

Trent Piepho (2):
  spi: Add driver_override SPI device attribute
  spi: spidev: Fix OF tree warning logic

 drivers/spi/spi.c       | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/spi/spidev.c    |  5 +++--
 include/linux/spi/spi.h |  1 +
 3 files changed, 57 insertions(+), 2 deletions(-)

Comments

Henry Gomersall Sept. 19, 2018, 9:47 a.m. UTC | #1
On 18/09/18 23:45, Trent Piepho wrote:
> This is an attempt to solve the problem of binding spidev to a device on
> a device-tree system.

This is great, thank you!

Henry