Hi John,
> I'm looking into the AP_HAL_Linux SPI driver implementation, and it seems
> that for current targets at least, all SPI chip selects are assumed to be
> on GPIO pins, and as a consequence userspace/mmap GPIO bit banging is the
> only mode supported.
yes, though I'm very happy to generalise the SPI driver code to support
other approaches
yes, and we did try this. I spent quite a bit of time fiddling on the
BBB to try to get separate SPI devices registered for each CS line in
/dev. Getting it to do two was fine. We never managed to get 3 to work
on one bus.
It is perfectly possible that we just didn't understand the device tree
well enough, or perhaps it is something to do with the particular 3.8
kernels we were using (BBB only transitioned to using device trees quite
recently).
> Of course the kernel needs to own the GPIO controller in this
> scenario, and given that the existing platforms appear to use the same
> GPIO banks for CS and GPIO duties, this could get a little tricky!
yep!
> I see a few options:
> * Zynq use GPIOs exclusively, and I wire the CS lines to GPIO pins
> instead of the inbuilt ones. Distasteful but it will work. It
> circumvents the Linux SPI API and so nothing will work except with the
> dedicated code in AP_HAL_Linux/SPIDriver to bit-bang the CS.
acceptable, but as you say its a bit icky
> * Zynq uses the full device tree method for SPI, with a dedicated
> GPIO controller instantiated just for any 'left over' GPIO CS pins.
> The kernel owns this GPIO and the others are bit-banged from APM.
> This is clean but I'll have to duplicate or refactor the existing
> SPIDriver class to take out the explicit chip select behaviour and use
> proper spidevX.N bindings.
yep.
I think adding an extra parameter in the LinuxSPIDeviceDriver
constructor should allow that to work fairly cleanly. Or
change cs_pin to be int16_t and have a special reserved value for
in-kernel CS handling.
> * Port the existing platforms (including Zynq) across to use the
> kernel-managed GPIO/CS approach, and take a chance that the kernel
> GPIO drivers are clean enough not to stomp on bits which are being
> managed by userspace through bitbanging, and that we never hit a
> read/modify/write race between kernel and userspace :)
if you could make this work for BBB I'd be interested to see it. We did
try previously, but I must admit this is my first foray into the
wonderful world of dts files so maybe I just got it wrong :-)
btw, I'm not sure you've realised just how ugly the current BBB solution
is. We couldn't find a easy way to actually disable the use of the CS
pin by the kernel driver, so we had to redirect it to a different pin
where it would do no harm. It currently is mapped to a couple of LEDs
that blink on SPI activity. I guess we could claim that is a feature :-)
Cheers, Tridge