SPI driver for RPi

Luiz Otavio O Souza loos.br at gmail.com
Thu Aug 22 13:57:59 UTC 2013


Hello,

Here is a SPI driver for RPi.

It has been tested with a hardware loopback (MOSI wired to MISO) and with a s25fl032 spansion flash (removed from a wr941nd router).

I've tested the reading from the flash up to 10Mhz of clock and surprisingly my (simple) wiring support it without any fail.

At boot the SPI clock is set to 500Khz, not fast and not too slow (as the 3.814Khz default):

# dd if=/dev/flash/spi0 of=flash-wr941nd-2 bs=64k
64+0 records in
64+0 records out
4194304 bytes transferred in 75.632316 secs (55457 bytes/sec)
# diff flash-wr941nd flash-wr941nd-2
# sysctl dev.spi.0.clock=1000000
dev.spi.0.clock: 500000 -> 1000000
# dd if=/dev/flash/spi0 of=flash-wr941nd-2 bs=64k
64+0 records in
64+0 records out
4194304 bytes transferred in 37.896805 secs (110677 bytes/sec)
# diff flash-wr941nd flash-wr941nd-2             
# sysctl dev.spi.0.clock=2000000                 
dev.spi.0.clock: 1000000 -> 2016129
# dd if=/dev/flash/spi0 of=flash-wr941nd-2 bs=64k
64+0 records in
64+0 records out
4194304 bytes transferred in 18.879980 secs (222156 bytes/sec)
# diff flash-wr941nd flash-wr941nd-2             
# sysctl dev.spi.0.clock=4000000                 
dev.spi.0.clock: 2016129 -> 4032258
# dd if=/dev/flash/spi0 of=flash-wr941nd-2 bs=64k
64+0 records in
64+0 records out
4194304 bytes transferred in 9.642490 secs (434981 bytes/sec)
# diff flash-wr941nd flash-wr941nd-2             
# sysctl dev.spi.0.clock=10000000                
dev.spi.0.clock: 4032258 -> 10416666
# dd if=/dev/flash/spi0 of=flash-wr941nd-2 bs=64k
64+0 records in
64+0 records out
4194304 bytes transferred in 4.317743 secs (971411 bytes/sec)
# diff flash-wr941nd flash-wr941nd-2             


It export a few handy sysctl knobs:

# sysctl dev.spi
dev.spi.0.%desc: BCM2708/2835 SPI controller
dev.spi.0.%driver: spi
dev.spi.0.%parent: simplebus0
dev.spi.0.clock: 500000
dev.spi.0.cpol: 0
dev.spi.0.cpha: 0
dev.spi.0.cspol0: 0
dev.spi.0.cspol1: 0


About the patches:

 - bcm2835_spi.diff implements the SPI driver, the dts and kernel changes;

 - ofw_spibus.diff adds the OFW SPI bus glue to attach the SPI children as described in the FDT.

- mx25l-fdt-intr.diff adds the support for FDT and configure a intr hook so the device identification runs only when the interrupts are active (the SPI driver is interrupt based);

- rpi-mx25l-dts.diff the change i did to add my mx25l on the rpi dts (only as reference).


Luiz




-------------- next part --------------
A non-text attachment was scrubbed...
Name: bcm2835_spi.diff
Type: application/octet-stream
Size: 17267 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/8ea84ae3/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ofw_spibus.diff
Type: application/octet-stream
Size: 7178 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/8ea84ae3/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mx25l-fdt-intr.diff
Type: application/octet-stream
Size: 1988 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/8ea84ae3/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rpi-mx25l-dts.diff
Type: application/octet-stream
Size: 420 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arm/attachments/20130822/8ea84ae3/attachment-0003.obj>


More information about the freebsd-arm mailing list