Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Mar 2015 19:19:57 +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:  <20150306191957.0603e0f3@zeta.dino.sk>
In-Reply-To: <CAB=2f8xqq=dMr12qb8WSiG5AMBnH%2BXzayiKch9kOC_YebO3M8g@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> <20150305123903.1050694f@zeta.dino.sk> <CAB=2f8xqq=dMr12qb8WSiG5AMBnH%2BXzayiKch9kOC_YebO3M8g@mail.gmail.com>

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

> On 5 March 2015 at 08:39, Milan Obuch wrote:

[ snip ]

> > 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

OK, understand now, when I saw your patch for the first time, it was
not clear to me why the modification is put there. Now I changed my
code similarly and I am able to read chip id in start task. Your help
is really appreciated.

Now I get (dmesg | grep tsc) this:

tsc0: <Touchscreen Controller> at cs 1 on spibus0
tsc0: read 01 08 (err 0)
tsc0: read 04 11 (err 0)
tsc0: read 08 03 (err 0)
tsc0: chip id 0811, rev. 03 

Three 'read' lines are just kind of debug, they will be left out later.

Now there is another problem to solve - there are two devices on the
spibus0, ILI9341 and STMPE610, on chip selects 0 and 1 respectively.
In the end, there will be 'ili' driver for the former and 'tsc' driver
for the later. Both will use SPIBUS_TRANSFER to transfer their
respective bytes, but could they interfere as they are on the same bus?
Is it necessary to use some kind of protection against that or does spi
bus driver ensure transfers cound not interfere?

And one more question - STMPE610 is actually a spi/i2c connected
register file, in my aplication spi is selected, and part of that
register file controls touchscreen controller while other part is for
some gpio. How to do that in a driver? Do we have an example of such a
compound device in our sources? And how should this be described in FDT?

As usual, all hints are welcomed.

Regards,
Milan



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