Re: [PATCH] spi: Add a sysfs interface to instantiate devices
From: Randy Dunlap
Date: Thu Dec 21 2017 - 15:11:33 EST
On 12/21/2017 12:03 PM, Kyle Roeschley wrote:
> Add a sysfs interface to instantiate and delete SPI devices using the
> spidev driver. This can be used when developing a driver on a
> self-soldered board which doesn't yet have proper SPI device declaration
> at the platform level, and presumably for various debugging situations.
>
> Inspired by 99cd8e25875a ("i2c: Add a sysfs interface to instantiate
> devices").
>
> Signed-off-by: Kyle Roeschley <kyle.roeschley@xxxxxx>
> ---
> Documentation/spi/spi-summary | 14 ++++++++
> drivers/spi/spi.c | 78 +++++++++++++++++++++++++++++++++++++++++++
> include/linux/spi/spi.h | 3 ++
> 3 files changed, 95 insertions(+)
>
> diff --git a/Documentation/spi/spi-summary b/Documentation/spi/spi-summary
> index 1721c1b570c3..51d9747c4426 100644
> --- a/Documentation/spi/spi-summary
> +++ b/Documentation/spi/spi-summary
> @@ -339,6 +339,20 @@ up the spi bus master, and will likely need spi_new_device() to provide the
> board info based on the board that was hotplugged. Of course, you'd later
> call at least spi_unregister_device() when that board is removed.
>
> +Alternatively, a sysfs interface was added to let the user create devices which
when
> +using the spidev driver. 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 decimal SPI chip select number to them in
write-only
> +order to properly instantiate or delete a SPI device. As no two devices can be
> +attached to the same master with the same chip select line, the chip select
> +number is sufficient to uniquely identify the device to be deleted.
> +
> +Example:
> +# echo 1 > /sys/class/spi_master/spi0/new_device
> +
> +In general, this interface should only be used when in-kernel device
> +declaration can't be done.
> +
> When Linux includes support for MMC/SD/SDIO/DataFlash cards through SPI, those
> configurations will also be dynamic. Fortunately, such devices all support
> basic device identification probes, so they should hotplug normally.
thanks.
--
~Randy