Reputation: 41
I am interested in working on SPI devices available in linux. I have a specific controller which supports SPI in both master and slave mode. I have to configure the SPI controller in slave mode.
My question: Does the Linux frame work support SPI slaves? I will get asynchronous data on SPI bus, I have to read this data and process it, then send back a command.
Upvotes: 4
Views: 9331
Reputation: 41
Support of SPI Slave Mode has been in the Linux kernel from revision v4.13-rc1. From SPI Documentation of Linux Kernel:
This document (and Linux) supports both the master and slave sides of SPI interactions.
[...]
A "struct spi_device" encapsulates the controller-side interface between those two types of drivers.
[...]
/sys/devices/.../CTLR/slave ... virtual file for (un)registering the slave device for an SPI slave controller.
Writing the driver name of an SPI slave handler to this file registers the slave device; writing "(null)" unregisters the slave device.
Reading from this file shows the name of the slave device ("(null)" if not registered).
/sys/class/spi_slave/spiB ... symlink (or actual device node) to a logical node which could hold class related state for the SPI slave controller on bus "B". When registered, a single spiB.* device is present here, possible sharing the physical SPI bus segment with other SPI slave devices.
I do not have any example C++/C code to support this off-hand.
Upvotes: 4
Reputation: 4821
The two most common examples of SPI slave implementation on Linux are the i.MX28-specific patches:
Ishaqe Ahamed has posted some code for an SPI slave driver for OMAP2 on https://e2e.ti.com/support/embedded/linux/f/354/t/162748 but has not posted a full patch.
You might me able to get some information from Intel's Moorestown SPI Slave Controller chip driver posted at http://git.yoctoproject.org/cgit/cgit.cgi/meta-extras/plain/recipes-kernel/linux/linux-netbook-2.6.33.2/linux-2.6.34-moorestown-spi-slave-controller-driver-1.1.patch .
Note that all of these examples were done some years ago, and will need to be ported to whatever newer kernel you are using. None of the examples provides a cross-architecture framework for SPI slave drivers.
Upvotes: 2
Reputation: 1022
No, Linux does not support operating as a SPI slave.
From the Overview of Linux kernel SPI support:
A "struct spi_device" encapsulates the master-side interface between those two types of driver. At this writing, Linux has no slave side programming interface.
Upvotes: 3