# GPIO Interupts on AllWinner H3



## JamesElstone (Apr 11, 2020)

Hi All,

Am I correct in thinking that Rising Edge Interupts on All Winner H3 GPIO lines are not supported in FreeBSD yet, and hence an attempt to get a /dev/pps0 is futile at this point in time please?

I am trying to assign PG11 (pin 91) to be a PPS device and have updated the FDT to include this but get the following output:

```
gpiopps0: <GPIO PPS> irq 0 on ofwbus0
gpiopps0: PPS input on gpio0 pin 91
gpiopps0: Pin cannot be configured for the requested signal edge
device_attach: gpiopps0 attach returned 45
```

The FDT I am using is as follows:

```
/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun8i-h3";

        fragment@0 {
                target-path = "/";
                __overlay__ {
                        pps@0 {
                                compatible = "pps-gpio";
                                gpios = <&gpio PG11 0>;
                                status = "okay";
                        };
                };
        };
};
```

The output of `gpioctl` is as follows and is not showing the interupt as a capability:

```
pin 91: 0       PG11<>, caps:<IN,OUT,PU,PD>
```

Yet the pad configuration in /usr/src/sys/arm/allwinner/h3/h3_padconf.c (in head) states it is an interrupt:

```
{"PG11", 6, 11, {"gpio_in", "gpio_out", "i2s1", NULL, NULL, NULL, "pg_eint11", NULL}, 6, 11, 1},
```

I believe the gpiopps() driver is looking for a rising edge interrupt...

Any advice as I have seen people getting this to work on FreeBSD on a Raspberry Pi and also using Armbian on an H3 CPU so I know it is possible which is the fustrating bit; Happy to attempt to code any missing bits...

Thanks for reading, and all feedback welcomed...


----------



## unitrunker (Apr 11, 2020)

Can you sample the pin state?


----------



## manu (Apr 11, 2020)

Hello,

I honestly don't know how this overlay compile or even apply ...

I don't have a real way to test gpiopps but here is what I did :

$ fetch https://download.freebsd.org/ftp/sn...T-arm-armv7-GENERICSD-20200409-r359731.img.xz
$ unxz FreeBSD-13.0-CURRENT-arm-armv7-GENERICSD-20200409-r359731.img.xz
$ sudo dd if=FreeBSD-13.0-CURRENT-arm-armv7-GENERICSD-20200409-r359731.img of=/dev/da0 bs=1M
$ sudo dd if=/usr/local/share/u-boot/u-boot-orangepi-one/u-boot-sunxi-with-spl.bin of=/dev/da0 bs=1k seek=8 conv=sync

$ cd $FBSDSRCTREE
$ cat > gpiopps.dtso


```
/dts-v1/;
/plugin/;

/ {
        compatible = "allwinner,sun8i-h3";
};

&{/} {
        pps@0 {
                compatible = "pps-gpio";
                gpios = <&pio 0 20 0>; /* PA20 */
                status = "okay";
        };
};
```
$ MACHINE=armv7 sys/tools/fdt/make_dtbo.sh `pwd`/sys/ gpiopps.dtso .
The I copied gpiopps.dtbo on the sdcard into /boot/dtb/overlays/
I've added fdt_overlays="gpiopps.dtbo" and gpiopps_load=YES to /boot/loader.conf
Boot the board (orangepi one in my case) :
# dmesg | grep gpiopps
gpiopps0: <GPIO PPS> on ofwbus0
gpiopps0: PPS input on gpio0 pin 20

Toggle the pin a few times, then :
$ vmstat -i | grep gpio
gic0,s11: gpio0                                           5          0
gpio0,pa_eint20:-s0                                       5          0

So interrupts are correcly arriving into the controller (and probably into gpiopps).
Note that when a pin is into interrupts mode on Allwinner you can't see it's state with gpioctl, that's how the hardware is designed.
This is using PA20 as it's easy enough to access on this board, if you want to sue PG11 replace the gpios property in the dtso by :
gpios = <&pio 6 11 0>; /* PG11 */
That's bank number 6, pin 11 in this bank.


Let me know if that helps you.


----------



## unitrunker (Apr 11, 2020)

I know even less of device trees.

I was thinking you could set a timer to trigger a periodic interrupt. Your interrupt code could sample the gpio pin. This isn't as good as an edge triggered interrupt but is meant as a workaround.


----------

