Pps-gpio for s905x

Yes, this working great, here are the overlay rising edge changes -

/*
 * Copyright (c) 2022 Da Xue
 * Author: Da Xue <da@libre.computer>
 *
 * SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 */
 
/*
 * Overlay aimed to create pps-gpio on 7J1 pin 12 (GPIOAO_6)
 * This requires an GPIO to IRQ enabled kernel and will not work without one.
 */

/*
 * Edited to switch interrupt to rising edge
 *
/

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/meson-gxl-gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/interrupt-controller/meson-gic.h>

/ {
	compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			pps_gpio: pps-gpio {
				compatible = "pps-gpio";
				pinctrl-names = "default";
				pinctrl-o = <&spdif_out_ao_6_pins>;
				gpios = <&gpio_ao GPIOAO_6 GPIO_ACTIVE_HIGH>;
				interrupts = <&gpio_intc MESON_GIC_GXL_GPIOAO_6 IRQ_TYPE_EDGE_RISING>;
				assert-rising-edge;
				status = "okay";
			};
		};
	};
};

This is the version I used, have trouble with the includes -

/*
 * Copyright (c) 2022 Da Xue
 * Author: Da Xue <da@libre.computer>
 *
 * SPDX-License-Identifier: (GPL-2.0+ OR MIT)
 */
 
/*
 * Overlay aimed to create pps-gpio on 7J1 pin 12 (GPIOAO_6)
 * This requires an GPIO to IRQ enabled kernel and will not work without one.
 */

/*
 * Modified to switch to rising edge interrupt and
 * Modified to remove symbols so can be compiled without includes
*/


/dts-v1/;
/plugin/;

/*
#include "/boot/mydt/dt-bindings/gpio/gpio.h"
#include "/boot/mydt/dt-bindings/gpio/meson-gxl-gpio.h"
#include "/boot/mydt/dt-bindings/interrupt-controller/irq.h"
#include "/boot/mydt/dt-bindings/interrupt-controller/meson-gic.h"
*/

/ {
	compatible = "libretech,cc", "amlogic,s905x", "amlogic,meson-gxl";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			pps_gpio: pps-gpio {
				compatible = "pps-gpio";
				pinctrl-names = "default";
				pinctrl-o = <&spdif_out_ao_6_pins>;
				gpios = <&gpio_ao 6 0>; /*  =<&gpio_ao GPIOAO_6 GPIO_ACTIVE_HIGH>; */
				interrupts = <&gpio_intc 6 1>; /* =<&gpio_intc MESON_GIC_GXL_GPIOAO_6 IRQ_TYPE_EDGE_RISING>;  */
				assert-rising-edge;
				status = "okay";
			};
		};
	};
};

Compile the above with this command -

#dtc -I dts -O dtb pps-gpio-7j1-12-rising.dts -o pps-gpio-7j1-12-rising.dtbo

Copy into place prior to merge where ever your overlays are located ??libretech-wiring-tool/libre-computer/aml-s905x-cc/dt/

Here is a quick synopsis of the procedure I used to get this working -

Physical Connection to the GT-U7 gps module.
5v in, 3.3v pps and serial signals

GPS     7j1 Pin 
Vin ----- 4, 5volts
Gnd ----- 6, Ground
Tx  ----- 5, UART_RX_AO_B
Rx  ----- 7, UART_TX_AO_B
PPS ----- 12, GPIOAO_6 -The magic interrupt



Pre req - Le Potato running - 2022-09-22-raspbian-bullseye-arm64+aml-s905x-cc.img
        - pps-gpio modified for rising edge see post above 

Here we go - 
#apt update
#apt upgrade
#apt install linux-image-6.1.y-lts-irq-arm64
#apt install gpsd
#apt install chronyc
#apt install pps-tools
#git clone https://github.com/libre-computer-project/libretech-wiring-tool.git
#cd libretech-wiring-tool/
#./install.sh
//Overlay modified to use rising edge if interrupt
#ldto merge pps-gpio-7j1-12-rising
#ldto merge uart-ao-b

#reboot

//well lookee here !!
pi@raspberrypi:~ $ dmesg|grep pps
[    0.663946] pps_core: LinuxPPS API ver. 1 registered
[    0.663960] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    8.733323] pps pps0: new PPS source pps-gpio.-1
[    8.733399] pps pps0: Registered IRQ 42 as PPS source
pi@raspberrypi:~ $ 

---------- chrony.conf ------------------
//add the follwing lines, optionally delete unneeded servers/pools
#nano /etc/chrony/chrony.conf 

# PPS from the pps-gpio interrupts
refclock PPS /dev/pps0 refid PPS0 prefer precision 1e-5

# Serial data from ttyAML2.  offset is the estimate of the fraction of
# a second the serial data arrives behind the pps.  Found experimentally. 
refclock SHM 0 refid AML2 offset 0.126 precision 1e-1

-------------------------------------------

-----------gpsd.service file---------------

#nano /usr/lib/systemd/system/gpsd.service 

//Change the Exec line to - 
ExecStart=/usr/sbin/gpsd -n -s 9600 /dev/ttyAML2

--------------------------------------------

#reboot

Hopefully you are golden in 5 or 30 minutes - 

pi@raspberrypi:~ $ chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
#* PPS0                          0   4   377    14   +547ns[ +639ns] +/-   10us
#- AML2                          0   4   377    15  -4707us[-4707us] +/-  100ms
^- time2.google.com              1   8   377   172  -3059us[-3058us] +/-   15ms
^- time-d-b.nist.gov             1   8   377   171  -2999us[-2998us] +/-   12ms
pi@raspberrypi:~ $ 

Thats under 1 us accuracy stratum 1 ntp server for about $50 (Le Potato=$35 + GT-U7=$10)! (Does fluctuate up to 2 or 3 us occasionally)

2 Likes

Thanks. We have updated the overlay in the repo.

2 Likes

Hmm, would this work on an S805x (La Frite) on 7J1 / 35 ? That’s PWM_F there, which also seems to be an IRQ-capable pin (used as SDIO_IRQ if needed).

PPS works on any pin on any of our platforms.