Bug 233489 - SPI on the Raspberry Pi 3 is not working
Summary: SPI on the Raspberry Pi 3 is not working
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm64 Any
: --- Affects Many People
Assignee: Oleksandr Tymoshenko
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-25 02:31 UTC by Vincent Stemen
Modified: 2019-02-03 15:34 UTC (History)
3 users (show)

See Also:


Attachments
device tree (3.91 KB, text/plain)
2018-11-25 02:31 UTC, Vincent Stemen
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Stemen 2018-11-25 02:31:09 UTC
Created attachment 199531 [details]
device tree

Hi.

We are trying to gain userland access to SPI on the raspberry PI 3 on FreeBSD
12 and FreeBSD 13.0-CURRENT.

When we load the spigen.ko kernel module, it successfully loads but no spigen
devices appear in /dev.

There is a dtb file in the rpi boot partition, bcm2710-rpi-3-b.dtb, and we
confirmed it is being loaded.  SPI is enabled in config.txt with the line,

"dtparam=audio=on,i2c_arm=on,spi=on".

sysctl output shows 

dev.gpio.0.pin.11.function: alt0
dev.gpio.0.pin.10.function: alt0
dev.gpio.0.pin.9.function: alt0

alt0 is correct for SPI according to the Broadcom manual.

Yet no /dev/spigen0.n appear with the spigen.ko module loaded.

To confirm, we set spi=off in config.txt, for testing, and rebooted and those
three pins changed to

dev.gpio.0.pin.11.function: input
dev.gpio.0.pin.10.function: input
dev.gpio.0.pin.9.function: input

I have attached the device tree with SPI enabled as output by

    "ofwdump -a".

We also tested with the latest snapshot for FreeBSD 13 as of 11/20/2018.

BTW, i2c seems to work fine except that setting the speed via sysctl does not
work.
Comment 1 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2018-11-25 03:13:14 UTC
spigen now requires overlay. You need spigen-rpi3.dtso from this review: https://reviews.freebsd.org/D16088

Compile it: dtc -@ -o spigen-rpi3.dtbo spigen-rpi3.dtso and move dtbo to /boot/dtb/overlays/

Add following line to /boot/loader.conf:
fdt_overlays="spigen-rpi3"

After reboot spigen should be functioning.
Comment 2 Ian Lepore freebsd_committer freebsd_triage 2018-11-25 15:50:40 UTC
In looking at that ofwdump output, it appears that setting "spi=on" automatically enabled 2 "spidev" devices, which are the linux equivelent of our spi(8) (aka spigen) devices.  We specifically used a different compatible string, because our driver isn't compatible with linux (it has a different userland API).

Now I'm wondering whether it would be better for us to go ahead and add the linux "spidev" compat string to our driver, so that people can use the off-the-shelf overlays on rpi.  They would still have to cope with a slightly different userland api to use spi(8).
Comment 3 Vincent Stemen 2018-11-27 05:04:01 UTC
(In reply to Oleksandr Tymoshenko from comment #1)

Thank you Oleksandr.  That worked.  That puts our ICE40 FPGA project back on
track.  

Tested the SPIGENIOC_SET_CLOCK_SPEED and SPIGENIOC_TRANSFER ioctls and they
worked great.
Comment 4 commit-hook freebsd_committer freebsd_triage 2019-01-16 01:09:05 UTC
A commit references this bug:

Author: gonzo
Date: Wed Jan 16 01:08:35 UTC 2019
New revision: 343069
URL: https://svnweb.freebsd.org/changeset/base/343069

Log:
  [rpi] Reorganize spigen(4) overlays for Raspberry Pi

  - Remove CS=2 entry from spigen-rpi2 since it didn't work
  - Add spigen-rpi3 overlay for Raspberry Pi 3
  - Enable rpi overlay modules for GENERIC kernel on aarch64

  PR:		233489
  Submitted by:	bobf@mrp3.com
  Reviewed by:	db
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D16088

Changes:
  head/sys/arm64/conf/GENERIC
  head/sys/dts/arm/overlays/spigen-rpi2.dtso
  head/sys/dts/arm64/overlays/spigen-rpi3.dtso
  head/sys/modules/dtb/rpi/Makefile
Comment 5 Oleksandr Tymoshenko freebsd_committer freebsd_triage 2019-01-16 01:17:14 UTC
spigen-rpi3 overlay was committed to HEAD. I'm going to close this PR as fixed since the original issue is addressed now.
Comment 6 commit-hook freebsd_committer freebsd_triage 2019-02-03 15:34:54 UTC
A commit references this bug:

Author: gonzo
Date: Sun Feb  3 15:34:10 UTC 2019
New revision: 343718
URL: https://svnweb.freebsd.org/changeset/base/343718

Log:
  MFC r343069:

  [rpi] Reorganize spigen(4) overlays for Raspberry Pi

  - Remove CS=2 entry from spigen-rpi2 since it didn't work
  - Add spigen-rpi3 overlay for Raspberry Pi 3
  - Enable rpi overlay modules for GENERIC kernel on aarch64

  PR:		233489
  Submitted by:	bobf@mrp3.com
  Reviewed by:	db
  Differential Revision:	https://reviews.freebsd.org/D16088

Changes:
_U  stable/12/
  stable/12/sys/arm64/conf/GENERIC
  stable/12/sys/dts/arm/overlays/spigen-rpi2.dtso
  stable/12/sys/dts/arm64/overlays/spigen-rpi3.dtso
  stable/12/sys/modules/dtb/rpi/Makefile