Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Mar 2015 11:38:09 -0300
From:      Luiz Otavio O Souza <lists.br@gmail.com>
To:        Milan Obuch <freebsd-arm@dino.sk>
Cc:        "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   Re: Raspberry Pi SPI device example?
Message-ID:  <CAB=2f8xqq=dMr12qb8WSiG5AMBnH%2BXzayiKch9kOC_YebO3M8g@mail.gmail.com>
In-Reply-To: <20150305123903.1050694f@zeta.dino.sk>
References:  <20150216093418.3d1be83b@zeta.dino.sk> <CAB=2f8xUGKWUPu1nk4PoD1ea4PO1BEy=fOZF8X2Y_hNEvTTPtg@mail.gmail.com> <20150219075342.7d2e7eec@zeta.dino.sk> <20150302124103.689135d3@zeta.dino.sk> <CAB=2f8zgy8WdFVK9wdN8VXUSw5vpUCOhqPxv2cSHAxiiAw23KA@mail.gmail.com> <20150303215040.13f8439f@zeta.dino.sk> <CAB=2f8x0MRWDXm30BA_Pc8VSEpLvHt5szb_9L4QEDuz1J%2BLstA@mail.gmail.com> <20150305123903.1050694f@zeta.dino.sk>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAB=2f8xqq=dMr12qb8WSiG5AMBnH%2BXzayiKch9kOC_YebO3M8g>