Raspberry Pi SPI device example?
Luiz Otavio O Souza
lists.br at gmail.com
Fri Mar 6 14:38:11 UTC 2015
On 5 March 2015 at 08:39, Milan Obuch wrote:
[...]
>
> static int
> tsc_attach(device_t dev)
> {
> struct tsc_softc *sc;
>
> uint8_t txBuf[2], rxBuf[2];
> struct spi_command cmd;
> int err;
>
> sc = device_get_softc(dev);
> sc->dev = dev;
>
> memset(&cmd, 0, sizeof(cmd));
> memset(txBuf, 0, sizeof(txBuf));
> memset(rxBuf, 0, sizeof(rxBuf));
>
> txBuf[0] = 0x80; //CMD_READ | REG_CHIP_ID;
> cmd.tx_cmd = txBuf;
> cmd.tx_cmd_sz = 2;
> cmd.rx_cmd = rxBuf;
> cmd.rx_cmd_sz = 2;
> err = SPIBUS_TRANSFER(device_get_parent(dev), dev, &cmd);
>
> device_printf(dev, "chip id %.2x %.2x (err %d)\n", rxBuf[0], rxBuf[1], err);
>
> return (0);
> }
>
> With following result in dmesg:
>
> spi0: <BCM2708/2835 SPI controller> mem 0x204000-0x20401f irq 62 on simplebus0
> spibus0: <OFW SPI bus> on spi0
> tsc0: <Touchscreen Controller> at cs 0 on spibus0
> tsc0: chip id 00 00 (err 0)
> tsc1: <Touchscreen Controller> at cs 1 on spibus0
> tsc1: chip id 00 00 (err 0)
>
> As the first one is actually ILI9341, where undefined command 0x80 is
> treated as NOP, and the second one should read device identification of
> STMPE610, 0x811 according the docs, I think my SPI transaction does not
> work the expected way. Code snippet was taken from mx25l_get_status
> function almost verbatim, I did not find any docs for spibus, so that's
> the only source I have to study. Some description of various fields of
> spi_command structure would be helpfull, too, but there is none.
>
> Do I need anything more to do, like some pin setup or spi
> initialisation? I did not see anything like this in sources present in
> our tree.
>
> Again, any hint greatly appreciated.
>
> Regards,
> Milan
The SPI driver for RPi uses interrupts to do the data tx/rx and as
such, it won't work that early (at proble/attach time).
You have to use config_intrhook_establish() to set a callback that
will run when interrupts are enabled.
Look at the mx25l patch to see how convert an existent driver:
http://loos.com.br/mx25l-fdt-intr.diff
Regards,
Luiz
More information about the freebsd-arm
mailing list