This is a cache of https://www.96boards.org/documentation/consumer/dragonboard/dragonboard410c/guides/enable-spi.md.html. It is a snapshot of the page at 2024-11-25T01:27:25.792+0000.
Enabling SPI on Dragonboard 410c with SPIDEV - 96Boards

Enabling SPI on Dragonboard 410c with SPIDEV

This document provides instructions for enabling SPI (Serial Peripheral Interface) subsystem on Dragonboard410c along with SPIDEV userspace interface.

Table of Contents


1) SPIDEV

SPI devices have a limited userspace API, supporting basic half-duplex read() and write() access to SPI slave devices. SPIDEV is a kernel driver used to provide userspace interface to SPI subsystem.

This driver can be enabled by the following Kconfig option:

CONFIG_SPI_SPIDEV=y (or) CONFIG_SPI_SPIDEV=m

First option builds the driver into kernel while the later builds it as a separate module. Since latest linaro builds have this option enabled by default, only device tree modification is required.

2) Modifying device tree

For using SPIDEV driver it is necessary to add the relevant device tree node. Following instructions are used to add SPIDEV nodes into Dragonboard410c device tree.

  1. Run the following commands on the Dragonboard410c:
$ git clone https://github.com/96boards/dt-update
$ cd dt-update
$ make
$ sudo scripts/db410c/enable-spidev.sh
  1. Reboot your Dragonboard410c

Kernel warning when booting the kernel:

Since the SPIDEV module is not a representation of a real hardware, kernel will produce a warning when booting the system, such as:

[   11.566840] spidev spi1.0: buggy DT: spidev listed directly in DT
[   11.566934] ------------[ cut here ]------------
[   11.571901] WARNING: at ../drivers/spi/spidev.c:719

The device will still be functional, so just ignore while testing the SPIDEV devices.

3) Testing SPIDEV

Login to Dragnoboard410c and execute the following commands to test SPI using SPIDEV module with the help of spidev_test utility.

$ wget https://raw.githubusercontent.com/torvalds/linux/master/tools/spi/spidev_test.c
$ gcc -o spidev_test spidev_test.c
$ sudo ./spidev_test -CHOv -D /dev/spidev0.0
spi mode: 0x7
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF  | ................................

Since, SPI driver in Dragonboard410c supports Loopback functionality, we can test that too without any hardware connections.

$ sudo ./spidev_test -CHOv -D /dev/spidev0.0 -loop
spi mode: 0x27
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.
RX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....�..................�.