zsphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget/translations/zh_CN/spi/spidevmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/zh_TW/spi/spidevmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/it_IT/spi/spidevmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/ja_JP/spi/spidevmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/ko_KR/spi/spidevmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget/translations/sp_SP/spi/spidevmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hSPI userspace APIh]hSPI userspace API}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhh8/var/lib/git/docbuild/linux/Documentation/spi/spidev.rsthKubh paragraph)}(hSPI devices have a limited userspace API, supporting basic half-duplex read() and write() access to SPI slave devices. Using ioctl() requests, full duplex transfers and device I/O configuration are also available.h]hSPI devices have a limited userspace API, supporting basic half-duplex read() and write() access to SPI slave devices. Using ioctl() requests, full duplex transfers and device I/O configuration are also available.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh literal_block)}(ht#include #include #include #include #include h]ht#include #include #include #include #include }hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhK hhhhubh)}(hFSome reasons you might want to use this programming interface include:h]hFSome reasons you might want to use this programming interface include:}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh block_quote)}(hX* Prototyping in an environment that's not crash-prone; stray pointers in userspace won't normally bring down any Linux system. * Developing simple protocols used to talk to microcontrollers acting as SPI slaves, which you may need to change quite often. h]h bullet_list)}(hhh](h list_item)}(h~Prototyping in an environment that's not crash-prone; stray pointers in userspace won't normally bring down any Linux system. h]h)}(h}Prototyping in an environment that's not crash-prone; stray pointers in userspace won't normally bring down any Linux system.h]hPrototyping in an environment that’s not crash-prone; stray pointers in userspace won’t normally bring down any Linux system.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(h}Developing simple protocols used to talk to microcontrollers acting as SPI slaves, which you may need to change quite often. h]h)}(h|Developing simple protocols used to talk to microcontrollers acting as SPI slaves, which you may need to change quite often.h]h|Developing simple protocols used to talk to microcontrollers acting as SPI slaves, which you may need to change quite often.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhj ubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]bullet*uh1hhhhKhhubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hOf course there are drivers that can never be written in userspace, because they need to access kernel interfaces (such as IRQ handlers or other layers of the driver stack) that are not accessible to userspace.h]hOf course there are drivers that can never be written in userspace, because they need to access kernel interfaces (such as IRQ handlers or other layers of the driver stack) that are not accessible to userspace.}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hhh](h)}(hDEVICE CREATION, DRIVER BINDINGh]hDEVICE CREATION, DRIVER BINDING}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1hhj@hhhhhKubh)}(hwThe spidev driver contains lists of SPI devices that are supported for the different hardware topology representations.h]hwThe spidev driver contains lists of SPI devices that are supported for the different hardware topology representations.}(hjQhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK!hj@hhubh)}(hGThe following are the SPI device tables supported by the spidev driver:h]hGThe following are the SPI device tables supported by the spidev driver:}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK$hj@hhubh)}(hXD- struct spi_device_id spidev_spi_ids[]: list of devices that can be bound when these are defined using a struct spi_board_info with a .modalias field matching one of the entries in the table. - struct of_device_id spidev_dt_ids[]: list of devices that can be bound when these are defined using a Device Tree node that has a compatible string matching one of the entries in the table. - struct acpi_device_id spidev_acpi_ids[]: list of devices that can be bound when these are defined using a ACPI device object with a _HID matching one of the entries in the table. h]h)}(hhh](h)}(hstruct spi_device_id spidev_spi_ids[]: list of devices that can be bound when these are defined using a struct spi_board_info with a .modalias field matching one of the entries in the table. h]h)}(hstruct spi_device_id spidev_spi_ids[]: list of devices that can be bound when these are defined using a struct spi_board_info with a .modalias field matching one of the entries in the table.h]hstruct spi_device_id spidev_spi_ids[]: list of devices that can be bound when these are defined using a struct spi_board_info with a .modalias field matching one of the entries in the table.}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjtubah}(h]h ]h"]h$]h&]uh1hhjqubh)}(hstruct of_device_id spidev_dt_ids[]: list of devices that can be bound when these are defined using a Device Tree node that has a compatible string matching one of the entries in the table. h]h)}(hstruct of_device_id spidev_dt_ids[]: list of devices that can be bound when these are defined using a Device Tree node that has a compatible string matching one of the entries in the table.h]hstruct of_device_id spidev_dt_ids[]: list of devices that can be bound when these are defined using a Device Tree node that has a compatible string matching one of the entries in the table.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK*hjubah}(h]h ]h"]h$]h&]uh1hhjqubh)}(hstruct acpi_device_id spidev_acpi_ids[]: list of devices that can be bound when these are defined using a ACPI device object with a _HID matching one of the entries in the table. h]h)}(hstruct acpi_device_id spidev_acpi_ids[]: list of devices that can be bound when these are defined using a ACPI device object with a _HID matching one of the entries in the table.h]hstruct acpi_device_id spidev_acpi_ids[]: list of devices that can be bound when these are defined using a ACPI device object with a _HID matching one of the entries in the table.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjubah}(h]h ]h"]h$]h&]uh1hhjqubeh}(h]h ]h"]h$]h&]j*-uh1hhhhK&hjmubah}(h]h ]h"]h$]h&]uh1hhhhK&hj@hhubh)}(hYou are encouraged to add an entry for your SPI device name to relevant tables, if these don't already have an entry for the device. To do that, post a patch for spidev to the linux-spi@vger.kernel.org mailing list.h](hYou are encouraged to add an entry for your SPI device name to relevant tables, if these don’t already have an entry for the device. To do that, post a patch for spidev to the }(hjhhhNhNubh reference)}(hlinux-spi@vger.kernel.orgh]hlinux-spi@vger.kernel.org}(hjhhhNhNubah}(h]h ]h"]h$]h&]refuri mailto:linux-spi@vger.kernel.orguh1jhjubh mailing list.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK2hj@hhubh)}(hX It used to be supported to define an SPI device using the "spidev" name. For example, as .modalias = "spidev" or compatible = "spidev". But this is no longer supported by the Linux kernel and instead a real SPI device name as listed in one of the tables must be used.h]hXIt used to be supported to define an SPI device using the “spidev” name. For example, as .modalias = “spidev” or compatible = “spidev”. But this is no longer supported by the Linux kernel and instead a real SPI device name as listed in one of the tables must be used.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK6hj@hhubh)}(hmNot having a real SPI device name will lead to an error being printed and the spidev driver failing to probe.h]hmNot having a real SPI device name will lead to an error being printed and the spidev driver failing to probe.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hj@hhubh)}(hSysfs also supports userspace driven binding/unbinding of drivers to devices that do not bind automatically using one of the tables above. To make the spidev driver bind to such a device, use the following::h]hSysfs also supports userspace driven binding/unbinding of drivers to devices that do not bind automatically using one of the tables above. To make the spidev driver bind to such a device, use the following:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hj@hhubh)}(hhecho spidev > /sys/bus/spi/devices/spiB.C/driver_override echo spiB.C > /sys/bus/spi/drivers/spidev/bindh]hhecho spidev > /sys/bus/spi/devices/spiB.C/driver_override echo spiB.C > /sys/bus/spi/drivers/spidev/bind}hjsbah}(h]h ]h"]h$]h&]hhuh1hhhhKBhj@hhubh)}(hWhen the spidev driver is bound to a SPI device, the sysfs node for the device will include a child device node with a "dev" attribute that will be understood by udev or mdev (udev replacement from BusyBox; it's less featureful, but often enough).h]hWhen the spidev driver is bound to a SPI device, the sysfs node for the device will include a child device node with a “dev” attribute that will be understood by udev or mdev (udev replacement from BusyBox; it’s less featureful, but often enough).}(hj%hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKEhj@hhubh)}(h