Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Mar 2015 12:39:03 +0100
From:      Milan Obuch <freebsd-arm@dino.sk>
To:        Luiz Otavio O Souza <lists.br@gmail.com>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: Raspberry Pi SPI device example?
Message-ID:  <20150305123903.1050694f@zeta.dino.sk>
In-Reply-To: <CAB=2f8x0MRWDXm30BA_Pc8VSEpLvHt5szb_9L4QEDuz1J%2BLstA@mail.gmail.com>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 4 Mar 2015 14:11:29 -0300
Luiz Otavio O Souza <lists.br@gmail.com> wrote:

> On 3 March 2015 at 17:50, Milan Obuch wrote:

[ snip ]

> > no success yet. I wrote simple skeleton containing only basic
> > functions, attached, but nothing shows any call to them. In my dts,
> > I put
> >
> >                 spi0 {
> >                         tsc0 {
> >                                 compatible = "st,stmpe_tc";
> >                                 spi-chipselect = <0>;
> >                         };
> >                 };
> >
> > I tried some variations, too, but no change. There are just two
> > lines in dmesg mentioning spi:
> >
> > spi0: <BCM2708/2835 SPI controller> mem 0x204000-0x20401f irq 62 on
> > simplebus0 spibus0: <OFW SPI bus> on spi0
> >
> > I think I am just missing something simple and obvious, but I can't
> > see it. Anybody knows what is missing here?
> >
> > Regards,
> > Milan
> 
> It (kinda) works for me:
> 
> spi0: <BCM2708/2835 SPI controller> mem 0x204000-0x20401f irq 62 on
> simplebus0 spibus0: <OFW SPI bus> on spi0
> tsc0: probe
> tsc0: probe
> tsc0: <Touchscreen Controller> at cs 0 on spibus0
> tsc0: attach
>

That was the intended result of this skeleton code.

[ snip ]

> Check if your dtb has the necessary nodes:
> 
> # ofwdump -a
> [...]
>     Node 0x1704: bsc1
>     Node 0x17a0: spi0
>       Node 0x1818: tsc0
>     Node 0x1854: dma
>     Node 0x1914: mbox
> [...]
> 

[ snip ]

Good hint, and stupid pilot error. I had wrong dtb select statement in
config.txt boot file... Now it works as expected.

I am trying now some SPI transaction to communicate with the device. As
there are actually two SPI devices, just for test I made two instances
in FDT:

spi0 {
        tsc0 {
                compatible = "st,stmpe_tc";
                spi-chipselect = <0>;
        };

        tsc1 {
                compatible = "st,stmpe_tc";
                spi-chipselect = <1>;
        };
};

and changed my attach function like this:

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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150305123903.1050694f>