spi core: Provide means to instantiate devices through sysfs
PATCH 1/1 spi core: Provide means to instantiate devices through sysfs
The I2C core provides a means to instantiate devices from userspace using sysfs attributes. Provide the same mechanism for SPI devices.
Signed-off-by Guenter Roeck <[email protected]>
---
This helped me tremendously for testing new SPI master and client drivers. Maybe it is useful for others as well.
Documentation/spi/spi-summary | 48 +++++++++++++ drivers/spi/spi.c | 159 +++++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi.h | 3 + 3 files changed, 210 insertions(+)
Documentation/spi/spi-summary +48 -0
@@ -331,6 +331,54 @@ configurations will also be dynamic. Fortunately, such devices all support basic device identification probes, so they should hotplug normally. +DECLARE SLAVE DEVICES FROM USER-SPACE + +In general, the kernel should know which SPI devices are connected and +what addresses they live at. However, in certain cases, it does not, so a +sysfs interface was added to let the user provide the information. This +interface is made of 2 attribute files which are created in every SPI master +directory: new_device and delete_device. Both files are write only and you +must write the right parameters to them in order to properly instantiate, +respectively delete, a SPI device. + +File new_device takes several parameters: + +Primary parameters are the name of the SPI device (a string), the SPI chip +select (a number, expressed in decimal or hexadecimal), the SPI bus speed +(a number, expressed in decimal or hexadecimal), and the SPI mode (a number, +expressed in decimal or hexadecimal). SPI device name, chip select, and speed +are mandatory. The mode parameter is optional and will be initialized with 0 if +not provided. + +For at25 type EEPROMs, additional parameters must be provided in < >. Those are +the EEPROM name (a string), the EEPROM capacity in bytes (a number, expressed in +decimal or hexadecimal), the EEPROM write page size (a number, expressed in +decimal or hexadecimal), and the EEPROM flags (a number, expressed in decimal or +hexadecimal). + +File delete_device takes a single parameter: the chip select of the SPI +device. As no two devices can live at the same chip select on a given SPI +master, the chip select is sufficient to uniquely identify the device to be +deleted. + +Examples: + cd /sys/class/spi_master/spi0 + Instantiate devices on SPI master 0 + + echo "lm70 0 400000" > new_device + Instantiate LM70 on CS0 + + echo "at25 1 1000000 0 < at25160b 2048 32 0x02 >" > new_device + Instantiate at25 driver with AT25160B on CS1 + + echo "sst25vf080b 2 1000000 3" > new_device + Instantiate SST25VF080B on CS2, using SPI mode 3 + +While this interface should only be used when in-kernel device declaration +can't be done, it can be helpful if you are developing a driver on a test board, +where you soldered the SPI device yourself, or in hot-plug situations. + + How do I write an "SPI Protocol Driver"? ---------------------------------------- Most SPI drivers are currently kernel drivers, but there's also support
drivers/spi/spi.c +159 -0
188 lines not on this page · raw message
include/linux/spi/spi.h +3 -0
@@ -91,6 +91,8 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ]; +struct list_head detected; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like:
@@ -273,6 +275,7 @@ struct spi_master {struct device dev;struct list_head list; +struct list_head userspace_devices;/* other than negative (== assign one dynamically), bus_num is fully * board-specific. usually that simplifies to being SOC-specific.
Signature · 1 line
1.7.9.7