Thursday, March 06, 2014

Get /dev/spidev on an Raspberrypi running under Archlinux ARM working again.

Currently, when running a raspberry-pi with the latest kernel available for Archlinux, access to the SPI bus via /dev/spidev no longer works. Bugs have been filed, but apparently the late-binding logic available via spi_register_board_info just seems to be broken right now.

I've written a small kernel module that doesn't fix the initial bug, but just does the binding of spidev to the first two chipselects of the first spi master. It's available on github.


$ ls -la /dev/spidev*
zsh: no matches found: /dev/spidev*

$ sudo insmod rpi_add_spidev_module/rpi_add_spidev_module.ko 

$ dmesg
(...)
[  245.299487] spi_master spi0: ...is the master for device #0.
[  245.299709] spi spi0.0: ...is the device #0.
[  245.299734] spi_master spi0: ...is the master for device #1.
[  245.304763] spi spi0.1: ...is the device #1.

$ ls -la /dev/spidev0.*
crw------- 1 root root 153, 0 Mar  6 16:47 /dev/spidev0.0
crw------- 1 root root 153, 1 Mar  6 16:47 /dev/spidev0.1

# cd /sys/bus/spi/drivers/spidev
# ls -l
total 0
--w------- 1 root root 4096 Jan  1 00:03 bind
lrwxrwxrwx 1 root root    0 Jan  1 00:02 module -> ../../../../module/spidev
lrwxrwxrwx 1 root root    0 Jan  1 00:03 spi0.0 -> ../../../../devices/platform/bcm2708_spi.0/spi_master/spi0/spi0.0
lrwxrwxrwx 1 root root    0 Jan  1 00:02 spi0.1 -> ../../../../devices/platform/bcm2708_spi.0/spi_master/spi0/spi0.1
--w------- 1 root root 4096 Jan  1 00:00 uevent
--w------- 1 root root 4096 Jan  1 00:02 unbind

Using software to talk to a proprietary SPI gyro/accelerometer module works again.

$ sudo ./rpi_gyro /dev/null  
Opened gpio25 direction as fd 5.
Opened gpio25 value as fd 6.
Opened /dev/spidev0.0 as fd 7 (0x03, 8, 0).
Opened /dev/spidev0.1 as fd 8 (0x03, 8, 0).
lsm330dlc_dump_regs: dumping accelerometer registers.
$00: $00 $00 $00 $00   $00 $00 $00 $ff
$08: $00 $00 $00 $00   $00 $00 $00 $33
$10: $86 $16 $a6 $26   $48 $25 $21 $1e
$18: $1b $a3 $50 $65   $c0 $00 $50 $00
$20: $27 $00 $00 $80   $40 $00 $00 $ff
$28: $00 $2d $c0 $01   $40 $27 $80 $9e
$30: $00 $00 $00 $00   $00 $00 $00 $00
$38: $00 $00 $00 $00   $00 $00 $00 $00
lsm330dlc_dump_regs: dumping gyro registers.
$00: $d3 $66 $a8 $cc   $4d $d0 $11 $f1
$08: $20 $06 $ff $18   $02 $83 $00 $d3
$10: $90 $2b $19 $44   $0c $e0 $61 $60
(...)

4 comments:

Unknown said...

I am getting a SPI bus 0 unknown error in dmesg. Any idea what could cause this?

Unknown said...

Hi Kyle,

I just booted up my RPI and tried with the last two kernels supplied by ArchLinux (before and after a pacman update):

Linux raspberrypi 3.14.4-1-ARCH #1 PREEMPT Wed May 14 20:04:37 MDT 2014 armv6l GNU/Linux

and

Linux raspberrypi 3.14.4-5-ARCH #1 PREEMPT Wed May 28 18:52:31 MDT 2014 armv6l GNU/Linux

and it assigns the spidev device just fine.

Have you loaded the spi_bcm2708 module ("modprobe spi_bcm2708")?

Chris

ghen said...

SPI works fine when enabled in /boot/config.txt.... unless the bug you've mentioned has been fixed already :).

Unknown said...

Yes, ghen, this blog post no longer applies. Everything is fine by now.