Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Jan 2020 21:06:26 +0100
From:      Emmanuel Vadot <manu@bidouilliste.com>
To:        Gary Otten <gdotten@gmail.com>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: SPI support for A64-OLinuXino board Allwinner A64 processor
Message-ID:  <20200116210626.097ecdfab0a7aa5d03483944@bidouilliste.com>
In-Reply-To: <CABZQu%2BijYmWW836nBhEgJBKA9ia=EqqfSfWBqhBFXdokidMHbg@mail.gmail.com>
References:  <CABZQu%2BivgronnY=ro5CtQoyYR6B=gGFsaryKm%2BgEwubJWx3KzA@mail.gmail.com> <20191228161726.9efb08df5b69eaa0a0ff478f@bidouilliste.com> <CABZQu%2Bg_tRZvj=euDkMTbs4zubB5k1GN%2BT6iidoaxXxBYViwtQ@mail.gmail.com> <20191230123322.fa579638df66e3eac3e16c91@bidouilliste.com> <CABZQu%2BjnY0wU_qbpB30-1hzEFbs8dQcmXBQVyYoFawp6z54Epw@mail.gmail.com> <20200111193627.6616bc804ef15bbfa341dea0@bidouilliste.com> <CABZQu%2Bi4RW73J0xySfd1Ef=9ooQSxL7f74qUyoO=PP4F6cntag@mail.gmail.com> <CABZQu%2BijYmWW836nBhEgJBKA9ia=EqqfSfWBqhBFXdokidMHbg@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 14 Jan 2020 21:16:38 -0500
Gary Otten <gdotten@gmail.com> wrote:

> So that I have the same test environment as you do.  What version of
> Freebsd are you using and which overlay were you using to boot the Olimex
> board?
> I have used 12 stable and 13 current, and a couple of different overlays.
> (pine and olimex)
> 
> If this would be of interest to others these are the steps I took.  I
> mounted the boot partition of course.
> mkdir /aaa
> mount -t msdos  /dev/mmcsd0s1   /aaa
> cd /aaa
> ls
> EFI  dtb
> cd dtb
> cd  allwinner    (directory where overlays are loaded from at boot, this is
> not the main partition where most files are located, this is the boot
> partition)
> 
> 
> I am used the sun50i-a64-olinuxino.dtb with changes you previously
> suggested because my Bank E gpio wasn't working.
> Compiling of course merges sun50i-a64-olinuxino.dts and sun50i-a64.dtsi so
> my loaded overlay is sun50i-a64-olinuxino.dtb
> 
> The regulator powering Bank E is not turned on after reading the overlay.
> Directly writing to the register on the AXP803 did turn the regulator/bank
> on though.
> I inserted this code at the end of the axp8xx_attach function in the
> driver.   axp8xx_write(dev,AXP_POWERCTL3,(AXP_POWERCTL3_ALDO1|0xC8));
> 
> sysctl says always on, boot on regardless if the regulator is on or not.
> 
> hw.regulator.vcc-pe.always_on: 1
> hw.regulator.vcc-pe.boot_on: 1

 Since r356800 you will need only one patch for the DTS that specify
the vcc-pe-supply in the pio node (the regulator needed to be enabled
for bank E).
 I've submitted my change in Linux and waiting a few days before
commiting the patch to the FreeBSD source tree.
 The patch for the dts is here
https://patchwork.kernel.org/patch/11337723/

 Note that on this board the PE bank is also used for MIPI-CSI so the
regulator is set at 2.8V, if you want 3.3V you will need to use an
overlay or change the value in the reg_aldo1 node in the dts.

> Anyway I want to make sure I am using the exact same overlay as you so that
> I can narrow down why my SPI isn't working and Bank E isn't being read
> correctly from the overlay.
> 
> Thanks
> 
> 
> 
> On Mon, Jan 13, 2020 at 10:23 AM Gary Otten <gdotten@gmail.com> wrote:
> 
> > Thanks for checking.  I will do further testing and report my results.
> >
> > On Sat, Jan 11, 2020 at 1:36 PM Emmanuel Vadot <manu@bidouilliste.com>
> > wrote:
> >
> >> On Mon, 30 Dec 2019 16:13:41 -0500
> >> Gary Otten <gdotten@gmail.com> wrote:
> >>
> >> > On Mon, Dec 30, 2019 at 6:33 AM Emmanuel Vadot <manu@bidouilliste.com>
> >> > wrote:
> >> >
> >> > > On Sun, 29 Dec 2019 23:40:19 -0500
> >> > > Gary Otten <gdotten@gmail.com> wrote:
> >> > >
> >> > > > Thanks,  Ian Lepore mentioned this too, spigen wasn't loaded.  I
> >> have now
> >> > > > loaded spigen.   The driver appears to be working, but I am not
> >> seeing
> >> > > any
> >> > > > output.
> >> > > >
> >> > > > I can toggle pins PC0,PC1,PC2, PC3 with  gpioctl,  but I don't get
> >> > > anything
> >> > > > with spi.
> >> > >
> >> > >  You mean settings them as gpio, toggling them and check the pins on
> >> > > the uext port ?
> >> > >
> >> >
> >> > Yes that is correct,  toggling them with gpioctl and seeing the voltage
> >> > swing  after setting that pin to OUT with gpioctl.
> >> >
> >> > >
> >> > > > I also had another odd behavior with BANK E. not having any output,
> >> using
> >> > > > gpoictl, I was not able to get any pin on Bank E to toggle. I did
> >> turn on
> >> > > > the voltage regulator as suggested.
> >> > >
> >> > >  The SPI pins for SPI0 are on BANKC which is always powered on.
> >> > >
> >> >
> >> > OK, I was mentioning this on the chance that the gpioctl doesn't work
> >> with
> >> > BANK E because Bank E is set to work with the csi function on the
> >> > A64-OLinuXino board.
> >> >
> >> > >
> >> > > > I wonder if FreeBSD is properly setting the configuration registers
> >> for
> >> > > > each port/pin of the the A64.
> >> > >
> >> > >  I'll not say that the code is bug free but this really should be ok,
> >> > > especially for such basic pin setting like spi0 where you only have
> >> one
> >> > > pin group.
> >> > >
> >> > > > Basically letting the A64 know to use alt
> >> > > > function or general gpio in/out in the proper way for each pin,
> >> maybe
> >> > > some
> >> > > > of the (default?) settings for the more popular pine boards work,
> >> but
> >> > > > don't  work correctly for the Olimex A64 board, or maybe there is
> >> some
> >> > > > setting in the overlays that I am overlooking that need to be set
> >> to use
> >> > > an
> >> > > > alt function or gpio in/out to get the pins to function properly.
> >>  If in
> >> > > > the overlay I have spi0 enabled, should I still be able to toggle
> >> the
> >> > > pins
> >> > > > with gpioctl?  Thanks for the help.
> >> > >
> >> > >  Yes unfortunately the gpio/pinmux code is shared on allwinner and
> >> > > doesn't have all the needed "protection" so you can toggle a pin even
> >> > > if it's not in gpio mode. I don't remember if the value is still
> >> output
> >> > > on the physical pin or not.
> >> > >
> >> >
> >> > Yes with SPI enabled in the overlay  after a boot, I am still able to
> >> set
> >> > the pins to output with gpioctl and see the voltage swing.  I must set
> >> the
> >> > pins to output to see the voltage swing.  Reloading gpio_aw.ko or
> >> running
> >> > spi after that  doesn't appear to change the fact that the pins are set
> >> to
> >> > output as I am still able to run gpioctl and see the toggle.
> >> >
> >> >
> >> >  Are you using the -sXM version on the board (where you have an spi
> >> > > flash present on the board) or did you wire something via the uext
> >> > > port ? If the later what's wired and how ?
> >> > >
> >> >
> >> > On my board the flash isn't populated. I wasn't aware of the uext port
> >> so I
> >> > just soldered wires on to the pads where the flash would have been, and
> >> a
> >> > ground. These wires go to my logic analyzer setup to edge detect. For
> >> > testing I used a loopback (short between) MOSI (PC0) /MISO(PC1)
> >> >
> >> >
> >> > >  I have this board but I will not have time to do a proper setup to
> >> > > test something for some time.
> >> > >
> >> >
> >> > Ok that would be great.  I will also order a pine board today to have
> >> > another board to test on.  Any help or advice would be appreciated. I
> >> could
> >> > be making a simple mistake or have the most basic of settings wrong, it
> >> > could be  something simple I am overlooking.  Is there anyway to read
> >> back
> >> > the configuration of a pin from user land?  I wonder if anyone else can
> >> use
> >> > GPIO pins on bank E on the Olimex A64 board, or has a working SPI on
> >> this
> >> > board.
> >> >
> >> > Thanks
> >>
> >>  I've just tested on my a64-olinuxino using the UEXT port and the
> >> overlay I've just commited (which is the one you wrote).
> >>  I've hooked up an spiflash on a breadboard and I can use it properly.
> >>
> >> >
> >> >
> >> > > > My diagnostics
> >> > > > ******************************************
> >> > > > root@:/dev # spi -i
> >> > > > Device name:   /dev/spigen0.0
> >> > > > Device mode:   2
> >> > > > Device speed:  500000
> >> > > > root@:/dev # spi -d r -m 0 -C '9F 00' -v -c 2
> >> > > > Binary output of 2 bytes
> >> > > > 2 command bytes and 2 data bytes read from SPI device
> >> > > >         |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F |
> >> > > >  |
> >> > > >       0 | 00 00 00 00                                     | ....
> >> > > >   |
> >> > > >
> >> > > > I
> >> > > >
> >> > > >
> >> > > >
> >> > > > On Sat, Dec 28, 2019 at 10:44 AM Emmanuel Vadot <
> >> manu@bidouilliste.com>
> >> > > > wrote:
> >> > > >
> >> > > > > On Wed, 25 Dec 2019 19:12:28 -0500
> >> > > > > Gary Otten <gdotten@gmail.com> wrote:
> >> > > > >
> >> > > > > > Thanks,  I have created the following overlay and tried a
> >> variety of
> >> > > > > other
> >> > > > > > things but I haven't been able to get spigen0.0 to appear in
> >> /dev.
> >> > > > > >
> >> > > > > >
> >> > > > > >
> >> > > > > > /* $FreeBSD$ */
> >> > > > > > /dts-v1/;
> >> > > > > > /plugin/;
> >> > > > > >
> >> > > > > > / {
> >> > > > > >         compatible = "allwinner,sun50i-a64";
> >> > > > > > };
> >> > > > > >
> >> > > > > > &{/soc/spi@1c68000} {
> >> > > > > >
> >> > > > > >                 status = "okay";
> >> > > > > >
> >> > > > > >                 spigen0: spigen0 {
> >> > > > > >                 compatible = "freebsd,spigen";
> >> > > > > >                 reg = <0>;
> >> > > > > >                 spi-max-frequency = <500000>;
> >> > > > > >                 status = "okay";
> >> > > > > >         };
> >> > > > > >
> >> > > > > > };
> >> > > > > >
> >> > > > > >
> >> > > > > >
> >> > > > > > Some diagnostics
> >> > > > > >
> >> > > > > > -------------------------------------------------------
> >> > > > > > On Boot
> >> > > > > >
> >> > > > > > Loading DTB overlays: 'sun50i-a64-spi-spidev'
> >> > > > > > /boot/dtb/overlays/sun50i-a64-spi-spidev.dtbo size=0x15c
> >> > > > > > applying DTB overlay
> >> '/boot/dtb/overlays/sun50i-a64-spi-spidev.dtbo'
> >> > > > > > ..
> >> > > > > > ....
> >> > > > > > .....
> >> > > > > >
> >> > > > > > Autoloading module: aw_spi.ko
> >> > > > > > aw_spi0: <Allwinner SPI> mem 0x1c68000-0x1c68fff irq 29 on
> >> simplebus0
> >> > > > > > spibus0: <OFW SPI bus> on aw_spi0
> >> > > > > > spibus0: <unknown card> at cs 0 mode 0
> >> > > > > >
> >> > > > > >
> >> > > > > > -------------------------------------------------------
> >> > > > > > root@:/boot/dtb/overlays # kldstat
> >> > > > > > Id Refs Address                Size Name
> >> > > > > >  1    5 0xffff000000000000  144dda8 kernel
> >> > > > > >  2    1 0xffff000054c00000    41000 aw_spi.ko
> >> > > > > >
> >> > > > > >  -------------------------------------------------------
> >> > > > > > root@:/boot/dtb/overlays # devinfo
> >> > > > > > ..
> >> > > > > > ...
> >> > > > > >   aw_spi0
> >> > > > > >         spibus0
> >> > > > > >
> >> > > > > > -------------------------------------------------------
> >> > > > > > root@:/boot/dtb/overlays # devinfo
> >> > > > > >
> >> > > > > > ....
> >> > > > > > ......
> >> > > > > >  Node 0x2f60: spi@1c68000
> >> > > > > >       Node 0x309c: spigen0
> >> > > > > > _______________________________________________
> >> > > > > > freebsd-arm@freebsd.org mailing list
> >> > > > > > https://lists.freebsd.org/mailman/listinfo/freebsd-arm
> >> > > > > > To unsubscribe, send any mail to "
> >> > > freebsd-arm-unsubscribe@freebsd.org"
> >> > > > >
> >> > > > >  Hi Gary,
> >> > > > >
> >> > > > >  You overlay worked for me on the pine64-lts. Here is what I did :
> >> > > > >  - Use https://github.com/evadot/freebsd/commits/aw_spigen
> >> > > > >  - aw_spi is autoloaded via devmatch
> >> > > > >  - kldload spigen (it's not in GENERIC for arm64, maybe we should
> >> add
> >> > > it
> >> > > > > or do some devmatch magic)
> >> > > > >  - root@pine64-lts:~ # spi -i
> >> > > > > Device name:   /dev/spigen0.0
> >> > > > > Device mode:   0
> >> > > > > Device speed:  500000
> >> > > > > root@pine64-lts:~ # spi -d r -m 0 -C '9F 00' -v -c 2
> >> > > > > Binary output of 2 bytes
> >> > > > > 2 command bytes and 2 data bytes read from SPI device
> >> > > > >         |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
> >> > > > > |                  | 0 | 00 ef 40 18
> >> > >    |
> >> > > > > ..@.             |
> >> > > > >
> >> > > > >  Maybe you just forgot to load spigen ?
> >> > > > >
> >> > > > > --
> >> > > > > Emmanuel Vadot <manu@bidouilliste.com> <manu@freebsd.org>
> >> > > > >
> >> > >
> >> > >
> >> > > --
> >> > > Emmanuel Vadot <manu@bidouilliste.com>
> >> > >
> >>
> >>
> >> --
> >> Emmanuel Vadot <manu@bidouilliste.com> <manu@freebsd.org>
> >>
> >


-- 
Emmanuel Vadot <manu@bidouilliste.com> <manu@freebsd.org>



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