Changes between Version 3 and Version 4 of SPI
- Timestamp:
- 11/30/2017 10:06:15 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SPI
v3 v4 16 16 == On-Board SPI controllers == 17 17 18 [=#spitable] 18 19 === Newport / Ventana === 19 20 Various Gateworks boards support 3.3V TTL SPI to an off-board expansion connector with a single CS#: 20 ||= Family =||= Board =||= Device 21 || Newport || GW630x || SPI0|| J8 ||22 || || GW640x || SPI0|| J8 ||21 ||= Family =||= Board =||= Device Tree Node =||= Connector =|| 22 || Newport || GW630x || spi_7_0 || J8 || 23 || || GW640x || spi_7_0 || J8 || 23 24 || || 24 || Ventana || GW552x || ECSPI3|| J24 ||25 || || GW54xx-E+ || ECSPI2|| J32 ||25 || Ventana || GW552x || ecspi3 || J24 || 26 || || GW54xx-E+ || ecspi2 || J32 || 26 27 27 28 Pinout (all signals are 3.3V TTL): … … 45 46 46 47 [=#usb] 47 == USB Expansion devices ==48 == USB SPI controllers == 48 49 A SPI master can also be added via USB expansion. For example: 49 50 * [http://trac.gateworks.com/wiki/expansion/gw16113 GW16113 firmware-flexible USB 2.0 FS expansion] … … 51 52 52 53 53 [=#spidev] 54 == Adding Kernel Support for Specific SPI Devices == 55 In order to support the specific device you plan to connect an addition to the GW5220 device tree must be made. 54 [=#linux] 55 == Using a Linux SPI kernel driver == 56 56 57 1. Follow [http://trac.gateworks.com/wiki/linux/kernel#BuildingtheLinuxkernelout-of-tree these instructions] up to and including step 5 of "Building the Linux Kernel" 58 2. Open the file at {{{.../linux-imx6/arch/arm/boot/dts/imx6qdl-gw52xx.dtsi}}} and find the node labeled "&ecspi3" (if absent, jump to the above section before continuing) 59 3. In the same location as the comment in step 5 of the above section, add your appropriate device configuration in a node beginning with "flash: " 60 4. Continue the instructions from step 1 to finish building your new kernel 57 === device-tree: Newport / Ventana === 58 Linux kernels that utilize the device-tree need to add a device-tree node to the SPI controller to use a kernel driver. Note that you can also access SPI from userspace using {{{spidev}}} (see [#spidev below]) 61 59 62 An example of a properly made configurationnode for a m25p32-vme6g nor flash device would be:60 An example device-tree child node for a m25p32-vme6g nor flash device would be: 63 61 {{{#!c 64 62 flash: m25p80@0 { /* "m25p80@0" parameter is the driver responsible for controlling your device */ … … 76 74 }; 77 75 }}} 76 77 Note that this node must appear within the SPI host controller. For a list of device-tree nodes [#spitable see above]. 78 78 79 Note that the values shown in the above node are specific to the m25p32-vme6g, and can vary greatly from the actual device you are using. Replace attribute values as necessary. 79 80 80 When searching for your device ID string or its controlling driver, searching via a L XR site like the one at [https://lxr.missinglinkelectronics.com/linux missing link electronics] for your device name can be helpful.81 When searching for your device ID string or its controlling driver, searching via a Linux LXR site like the one at [https://lxr.missinglinkelectronics.com/linux missing link electronics] for your device name can be helpful. 81 82 82 == spidev - Userspace SPI API == 83 === non-device-tree: Laguna === 84 Linux kernels that do not utilize device-tree need to register a {{{spi_board_info}}} struct with the kernel via {{{spi_register_board_info()}}}. 83 85 84 SPI 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. 85 {{{ 86 #include <fcntl.h> 87 #include <unistd.h> 88 #include <sys/ioctl.h> 89 #include <linux/types.h> 90 #include <linux/spi/spidev.h> 91 }}} 86 To add a SPI device to Laguna you would add it to the spi_board_info array in {{{laguna.c}}}. Be sure to specify chip_select=1 to use CS1 as CS0 is used for the on-board SPI FLASH device. 87 88 References: 89 * [https://github.com/Gateworks/openwrt/blob/16.02/target/linux/cns3xxx/files/arch/arm/mach-cns3xxx/laguna.c#L188 spi_board_info struct] 90 * [https://github.com/Gateworks/openwrt/blob/16.02/target/linux/cns3xxx/files/arch/arm/mach-cns3xxx/laguna.c#L1097 call to spi_register_board_info()] 91 92 93 94 [=#spidev] 95 == Linux spidev userspace API == 96 SPI devices have a limited userspace API, supporting basic half-duplex read() and write() access to SPI slave devices referred to as {{{spidev}}}. Using ioctl() requests, full duplex transfers and device I/O configuration are also available. 97 92 98 Some reasons you might want to use this programming interface include: 93 94 * Prototyping in an environment that's not crash-prone; stray pointers in userspace won't normally bring down any Linux system. 95 * Developing simple protocols used to talk to microcontrollers acting as SPI slaves, which you may need to change quite often. 99 * Prototyping in an environment that's not crash-prone; stray pointers in userspace won't normally bring down any Linux system. 100 * Developing simple protocols used to talk to micro-controllers acting as SPI slaves, which you may need to change quite often. 96 101 97 102 Of 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. … … 99 104 Userspace access to SPI devices is done through the /dev/spidev<bus>.<chip-select> device interface. In order to use this you must have spidev enabled in the kernel (CONFIG_SPI_SPIDEV) and have a spidev node defined under the SPI controller in the device-tree. 100 105 106 In order to support {{{spidev}}} a spidev child node needs to be present in the device-tree under the SPI host controller. For example, a GW54xx which brings out the ecspi2 host interface: 107 {{{#!c 108 &ecspi2 { 109 cs-gpios = <&gpio2 26 GPIO_ACTIVE_HIGH>; 110 pinctrl-names = "default"; 111 pinctrl-0 = <&pinctrl_ecspi2>; 112 status = "okay"; 113 114 spidev0: spidev@0 { 115 compatible = "rohm,dh2228fv"; 116 reg = <0>; 117 spi-max-frequency = <60000000>; 118 }; 119 }; 120 }}} 121 122 For instructions on compiling and updating a device-tree see [wiki:linux/devicetree linux/devicetree] 123 124 An application using {{{spidev}}} would include the {{{<linux/spi/spidev.h>}}} header file. 125 101 126 For more info see: 102 127 * [https://web.archive.org/web/20170619204541/https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/spi/spidev spidev Kernel Documentation] 103 128 * [https://web.archive.org/web/20170619204541/https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/spi/spidev spidev examples] 104 129 * [https://web.archive.org/web/20170619204541/https://lxr.missinglinkelectronics.com/linux/drivers/spi/spidev.c spidev kernel driver] 130