frank-w / BPI-Router-Linux

Linux kernel 4.14+ for BPI-R2, 5.4+ for R64, 6.1+ for R2Pro and R3
Other
132 stars 47 forks source link

BPI-r3 expose pps #104

Closed gustavobsch closed 1 year ago

gustavobsch commented 1 year ago

I want to setup a gps disciplined ntp server and I'm wondering how to setup a gpio to fee pps to on the bpi-r3 board.

I can see the kernel has pps and gpio modules builtin but I think I need to setup an spcific pps gpio pin 'pps_gpio_pin'

I an old thread where explaining how to do it on kernel 4.9 in your wiki below.

https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:gpio

How can I make this process work with your kernel 6.2 or 6.3?

Thanks

frank-w commented 1 year ago

I have not tested pps only added description from forum user to my wiki....

gustavobsch commented 1 year ago

I tried adding the section below under gpio-keys to the file arch/arm64/boot/dts/mediatek/mt7986a-bananapi-bpi-r3.dts before compiling. Is this the right way to do it? I couldnt find other dts file in the file system

pps { pinctrl-names = “default”; compatible = “pps-gpio”; gpios = <&pio 15 0>; status = “okay”; };

frank-w commented 1 year ago

file is right, but you have to do it at top-level, not under gpio-keys and don't forget the driver

gustavobsch commented 1 year ago

I meant I added below, so it looks like this.


    gpio-keys {
        compatible = "gpio-keys";

        reset-key {
            label = "reset";
            linux,code = <KEY_RESTART>;
            gpios = <&pio 9 GPIO_ACTIVE_LOW>;
        };

        wps-key {
            label = "wps";
            linux,code = <KEY_WPS_BUTTON>;
            gpios = <&pio 10 GPIO_ACTIVE_LOW>;
        };
    };

    pps {
       pinctrl-names = "default";
       compatible = "pps-gpio";
       gpios = <&pio 15 0>;
       status = "okay";
    }; 

I recompiled with the required modules and it's almost working. Do you know what the issue might be?

dmesg | grep pps
[    0.046661] pps_core: LinuxPPS API ver. 1 registered
[    0.046668] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[   17.994579] pps-gpio pps: error -EBUSY: failed to request PPS GPIO
[   18.000797] pps-gpio: probe of pps failed with error -16

dmesg | grep -i gpio
[    0.046507] i2c-gpio i2c-gpio-0: using lines 528 (SDA) and 529 (SCL)
[    0.046618] i2c-gpio i2c-gpio-1: using lines 530 (SDA) and 531 (SCL)
[   17.994579] pps-gpio pps: error -EBUSY: failed to request PPS GPIO
[   18.000797] pps-gpio: probe of pps failed with error -16
frank-w commented 1 year ago

why gpio 15? it is not on gpio-header

https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r3:gpio

gustavobsch commented 1 year ago

Thanks, I was using the pin number instead of Mainfunction number, which is 65. Now it seems to work fine!

[    0.046642] pps_core: LinuxPPS API ver. 1 registered
[    0.046648] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[   11.334951] pps pps0: new PPS source pps.-1
[   11.339227] pps pps0: Registered IRQ 80 as PPS source
gustavobsch commented 1 year ago

Any chance you can add GPIO 65 as PPS to the bpir3 device tree? this pin it's perfectly located next to UART2, 3v3 and GND which are used to to connect to the GPS


    gpio-keys {
        compatible = "gpio-keys";

        reset-key {
            label = "reset";
            linux,code = <KEY_RESTART>;
            gpios = <&pio 9 GPIO_ACTIVE_LOW>;
        };

        wps-key {
            label = "wps";
            linux,code = <KEY_WPS_BUTTON>;
            gpios = <&pio 10 GPIO_ACTIVE_LOW>;
        };
    };

    pps {
       pinctrl-names = "default";
       compatible = "pps-gpio";
       gpios = <&pio 65 0>;
       status = "okay";
    }; 

Testing PPS with a ublox GPS


root@bpi-r3:~# ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1681494540.959480083, sequence: 7350545 - clear  0.000000000, sequence: 0
source 0 - assert 1681494541.959483346, sequence: 7350546 - clear  0.000000000, sequence: 0
source 0 - assert 1681494542.959479360, sequence: 7350547 - clear  0.000000000, sequence: 0
source 0 - assert 1681494543.959464814, sequence: 7350548 - clear  0.000000000, sequence: 0
frank-w commented 1 year ago

sry, missed this one...very few users use a gps module here, so i would leave this unconfigured, but you can form my repo and add it by yourself ;) but you should use only main-branches, because the rc-branches are rebased from time to time and may create conflicts if you want to update your source from my tree