Repository navigation
soc: google: gnssif_spi: the Pixel 9a's GNSS link (Kepler over SPI) - #185
Conversation
|
Tested on the palmtop (Pixel 9a), 2026-11-02, with GNSS running through this series. I built gnss_spi and gnssif from 26f4f35 with no changes, out of tree against my daily kernel (
That matches what the out-of-tree port gave on 11-01 (568 of 570 and 558 of 567 in two 600 s sessions). |
|
Thank you, @W4HO-ham. This is a model import: Google's files in one commit, byte for byte (I Two things:
One question, not a blocker: the two compatibles are Google's generic names, and our tree will For the 9a, the option also needs to go into |
|
Thanks, Derek, and thanks for checking the import file by file.
Those two commits changed, so they're waiting on my sign-off again; the other five keep theirs. The |
The GNSS receiver of the Pixel 9a is Samsung's Kepler core inside the
S5300 modem. Its data goes over SPI 21 of the Tensor G4 (USI3 of HSI0),
and two lines pace the transfers: the core's request line (gpa5-4,
which is also its interrupt) and the host's (gpp2-3). Google's kernel
describes them with two nodes, which Google's gnssif_spi driver binds:
a "samsung,gnss-spi" device on the SPI bus and a "samsung,exynos-gnss"
node holding the two lines (kernel/devices/google/zuma,
dts/zuma-cp-s5400-phone-gnss.dtsi, included by tegu's MP board).
Document both, as the 9a's device tree will use them. The differences
from Google's nodes:
- The lines are gnss2ap-spi-gpios and ap2gnss-spi-gpios, for GPIO
descriptors, instead of gpio_gnss2ap_spi and gpio_ap2gnss_spi. Google's
nodes flag them GPIO_ACTIVE_LOW, but Google's driver uses raw levels
through the legacy GPIO numbers, and both lines are active high: the
core's request is a level-high interrupt, and the host's line idles
low. So the binding's example says GPIO_ACTIVE_HIGH.
- device,name ("KEPLER", used only in log lines) and device_node_name
("gnss_ipc", the name of the character device the GNSS daemon opens)
are left out: neither describes the hardware, "device" is not a
vendor prefix, and the driver uses fixed names instead.
The compatibles stay Google's generic names, as stock's device tree and
gnssd know the device by them. A specific compatible for the S5300's
GNSS core belongs with the single-node binding an upstream submission
would want, not with this port.
The SPI device takes Samsung's SPI controller-data for the feedback
delay; stock's is 0. Stock's swap-mode belongs to the vendor SPI
controller's node and is not part of these bindings.
Link: https://android.googlesource.com/kernel/devices/google/zuma/+/42395e8adcb880aa336f0da6bb2a19ed53929c40/dts/zuma-cp-s5400-phone-gnss.dtsi
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Import Google's driver for the Kepler GNSS core of the Pixel 9a's S5300 modem (drivers/soc/google/gnssif_spi of google-modules/soc/gs in Google's GPL kernel for tegu, branch android-gs-tegu-6.1-android16, at 204078758737, "Update kernel to ab/13436148"). It is Samsung's code, GPL-2.0, and makes two modules: - gnss_spi.ko, the SPI device driver for "samsung,gnss-spi": one function to write a buffer and one to read one; - gnssif.ko, the platform driver for "samsung,exynos-gnss": the two request lines and their handshake (gnss_keplerctl_device.c), the read work and the write path over gnss_spi (gnss_link_device.c), and the character device the GNSS daemon talks to, /dev/gnss_ipc (gnss_io_device.c, gnss_main.c, gnss_utils.c). The kernel side of the core's firmware loading is not here: the daemon loads the firmware through the modem driver (CPIF's gnss_boot device). The ten .c and .h files are byte for byte Google's, with Google's style; Google's Kconfig and Makefile are not imported. Nothing builds them yet: the next commits port the driver to this kernel and wire it up. Link: https://android.googlesource.com/kernel/google-modules/soc/gs/+/204078758737776959ecc85c527a00fd2cabb62f/drivers/soc/google/gnssif_spi Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Build Google's GNSS SPI interface driver as the two modules Google
builds, gnss_spi.ko and gnssif.ko, under EXYNOS_GNSS_IF_SPI (Google's
option name), and make it take its lines and names as the binding
describes:
- drivers/soc/google is new on omamobile. Its Kconfig menu and Makefile
are laid out as the curated series adds them for the GSA and AoC
drivers (linux-omarchy-mobile#141), so whichever lands second keeps
both sets of lines.
- GPIOs: of_gpio.h is gone. The two lines are GPIO descriptors,
gnss2ap-spi-gpios (an input, also the interrupt, through
gpiod_to_irq()) and ap2gnss-spi-gpios (an output that starts low, as
Google's driver sets it). devm releases them. The node's lines are
active high, so the logical values are Google's raw ones.
- The error path freed the interrupt with &gc as its cookie instead of
gc, which never matches; it now passes gc, as remove() does too.
- A failed enable_irq_wake() no longer fails the probe: GNSS works
without it, it just can't wake the AP.
- device,name and device_node_name are not in the binding: the names
are fixed ("KEPLER", which only appears in log lines, and "gnss_ipc",
the device the GNSS daemon opens), and the macros that read them go.
- Google's subsystem coredump (sscoredump) is not in this kernel. A dump
the daemon writes to the coredump attribute goes to devcoredump, its
counterpart here, with the reason logged.
- API drift: remove() returns void, strscpy() instead of strncpy(),
__poll_t and EPOLL*, __user on the read buffer, %zu for size_t; the
unused gif_trace() (with the gone %pF) and the leftover linux/gpio.h
includes go.
- W=1: init_io_device() is static, and an unused variable in open goes.
- checkpatch: the static last_trigger_time loses its "= 0".
- gnss_spi gets an spi_device_id table ("gnss-spi"): without one the SPI
core warns, when the driver registers, that it has none for the
compatible.
The SPI transfers are still Google's; the next commits change them.
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
Google's gnssif leaves most of what it sets up behind: - Every create_*_device() returns NULL on failure and the probe returns -ENOMEM, so an -EPROBE_DEFER from the GPIO lookup is lost. On the Pixel 9a the core's request line is on GPA5 of the FAR_ALIVE pin controller, which can bind after this driver; the driver would then never bind. Return the error and pass it on with dev_err_probe(). - A failure after the interrupt is requested frees the control data with the handler still installed, and the probe's last message dereferences pdata, which is NULL when the node is missing. - The work queue, the wakeup source and the character device are never released, on a failed probe or on remove, so after rmmod /dev/gnss_ipc points at freed memory. remove() does not stop the read work either, which enables the interrupt again when it ends. - gif_disable_irq_sync() takes the interrupt's lock without disabling interrupts, and the handler takes the same lock (through gif_disable_irq_nosync()): a deadlock if the interrupt arrives on that CPU. Use devm for the interrupt (and its wake setting), the work queue (an ordered one, the current form of Google's unbound queue with one active work item), the wakeup source and the character device. In remove(), disable the interrupt, wait for the read work, and disable it again before devm releases the rest. The coredump attribute moves to the driver's dev_groups. Take the lock with interrupts disabled in gif_disable_irq_sync(). Suppress the bind attributes, as gnss_spi already does: the module can't be removed while the GNSS daemon holds /dev/gnss_ipc open, but a manual unbind could. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
gnssif reads and writes through functions gnss_spi.ko exports, which use the SPI device gnss_spi stored at probe. Loading gnssif loads gnss_spi for its symbols, but nothing makes the SPI device bind first: if gnssif binds before it (built in, or the SPI controller probing later), the first request from the core makes the read work call spi_sync() on a NULL device. Google's header also defines that device holder static, so every file that includes it gets an unused copy. Keep the holder in gnss_spi.c, export gnss_spi_bound(), and defer gnssif's probe until it is true; the SPI device's binding retries the deferred probe. The transfer functions return -ENODEV without a device, and gnss_spi's remove() clears it. The exports become EXPORT_SYMBOL_GPL, and the driver structure loses .owner, which the SPI core sets. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
…fers
Google's gnss_spi sends 32-bit words in one transfer per call, and
relies on Google's SPI controller driver for two things this kernel's
spi-s3c64xx does not do:
- The board's SPI 21 node has swap-mode = <1>, for which Google's
driver programs the controller's SWAP_CFG to swap the bytes and
half-words of each word on TX and RX, so the bytes go on the wire in
memory order. spi-s3c64xx shifts a 32-bit word out most significant
byte first, which on a little-endian CPU reverses every group of
four bytes. Swap each word in gnss_spi instead, on the way out and on
the way in, and give the caller its TX buffer back unswapped. Every
transfer is a whole number of words (gnssif rounds writes up to 4
bytes and reads 64), so an odd size is refused.
- The core's data comes in 64-byte blocks, and reads are one block per
transfer. spi-s3c64xx moves a transfer that fills the 64-byte FIFO in
one piece on zumapro, but cuts a longer one into 60-byte pieces. Send
writes as one message of transfers of 64 bytes at most, as the reads
are.
On the Pixel 9a (MODEM-PLAN G3, 2026-10-30, the bring-up driver of
linux-omarchy-mobile#137 with these two settings, SPI mode 0, stock's
feedback delay 0 and the controller driving chip select) the receiver
got its position fix: in a session by a window 54 of 56 GGA sentences
had a fix, with 10 satellites, HDOP 1.2, and no CHPP checksum error,
ACK timeout or permanent failure. That boot had no swap mode in the
controller, which a bring-up patch also tried with the same result, so
neither the device tree nor spi-s3c64xx needs one. The palmtop has run
this setting since.
8-bit words would put the bytes in memory order too, but they have not
been tried since the SPI flush fix ("spi: s3c64xx: turn the channels off
before clearing the packet count") that ended the link's bit slips, so
this keeps stock's word size. The bring-up's module parameters for the
word size, the transfer size and the SPI mode are not carried over:
these are fixed, and the mode and clock come from the device tree.
Link: derekross#137
Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
… is open Google's gnssif enables the core's request interrupt at the end of its probe, so from the moment the module loads, a high level on the line starts the read work, which keeps reading 64-byte blocks for as long as the line stays high, whether or not anyone will read them: what it queues is thrown away at the last release of /dev/gnss_ipc anyway. On the Pixel 9a the line is GPA5 pin 4, the same bank as the modem's own lines, and the core has nothing to say until the modem is up and the GNSS daemon has loaded its firmware, which it does before it talks to the core. Loading the driver should not be able to take an interrupt there early. Enable the interrupt, and arm it as a wake source, on the first open of /dev/gnss_ipc, and disable and disarm it on the last release, after waiting for the read work (which enables the interrupt again when it ends). The line is level-triggered, so a request the core raises before the open is taken as soon as the interrupt is enabled. A mutex keeps a first open and a last release from interleaving. The interrupt is still requested at probe, disabled, so a missing interrupt still fails the probe. This is MODEM-PLAN K5's "IRQ requested at open rather than probe", done by enabling rather than requesting it there. Signed-off-by: W4HO <87742609+W4HO-ham@users.noreply.github.com>
|
Thank you, @W4HO-ham, that was quick. I checked the new head commit by commit: the rebase resolves A few small things for a later commit, none blocking:
Once this is in, I'll close #137, since this series replaces it. |
This brings in the Pixel 9a's GNSS link. The receiver is Samsung's Kepler core inside the S5300 modem. It talks to the AP over SPI 21 with two request lines, and Google's gnssif_spi driver turns that into /dev/gnss_ipc for gnssd. I followed what #144 did for cpif: Google's files come in unchanged in one commit (google-modules/soc/gs, android-gs-tegu-6.1-android16 at 204078758737), and the port happens in place after that. The binding comes first. It documents the two nodes Google's device tree uses, with GPIO-descriptor line names and without device,name and device_node_name, which describe no hardware.
The port builds gnss_spi.ko and gnssif.ko under Google's EXYNOS_GNSS_IF_SPI, moves the lines to GPIO descriptors and hands coredumps to devcoredump. Three commits fix Google's code. The probe lost -EPROBE_DEFER and leaked the IRQ, work queue, wakeup source and misc device, so /dev/gnss_ipc outlived rmmod. gnssif could bind before the SPI device and pass spi_sync() a NULL device. And gif_disable_irq_sync() could deadlock against its own handler.
Two commits change behaviour. gnss_spi now swaps the 32-bit words itself and sends at most 64 bytes per transfer, because spi-s3c64xx has no swap mode and cuts longer PIO transfers into 60-byte pieces. That's the setting the palmtop has run out of tree since its first position fix on 10-30 (54 of 56 GGA sentences fixed, no CHPP errors). The last commit enables the request interrupt only while /dev/gnss_ipc is open.
Every commit builds W=1 clean. checkpatch --strict is clean apart from MAINTAINERS notes, except the unchanged import, which keeps Google's style; its one error (
static ... = 0) will turn the checkpatch step red. I left it so the import stays byte-identical to Google's, as #144's cpif import is; if you'd rather have the gate green, I'll drop the initializer in the import and say so in its message. The bindings pass dt-doc-validate and their examples validate.Tested on the palmtop (2026-11-02), MODEM-PLAN G1: the modem off, a full kernel from this branch (
7.3.0-rc6-omamobile-push1-g30e9d94b4a91,defconfig+kernel/configs/omamobile.config+CONFIG_EXYNOS_GNSS_IF_SPI=m), booted with the tegu DTB from the same tree plus a test overlay that adds usi3, spi21 with the controller driving chip select,gnss@0at 3.125 MHz with feedback delay 0, and thegnssnode (gpa5-4, gpp2-3). The modules were blacklisted at boot and loaded by hand:modprobe gnss_spiandmodprobe gnssifboth returned 0; gnss_spi boundspi1.0and gnssif bound the platform device;/dev/gnss_ipcappeared.kepler_spi_irq_handlerregistered on gpa5-4 (IRQ 66) with a count of 0, still 0 after 30 s;ap2gnss-spion gpp2-3 readout lo./dev/gnss_ipcopen for 10 s: the IRQ'swakeupread enabled while open and disabled after close, with no interrupt either way (the last commit's behaviour).rmmod gnssifremoved/dev/gnss_ipcand the IRQ;modprobe gnssifbrought both back.tools/phone-smoke: 14 ok; the not-ok rows are the daily kernel's out-of-tree helper modules refusing this release (version magic) and the cameras, which this test DTB doesn't describe.What this doesn't cover yet: a GNSS session through this driver needs the modem up, which needs CPIF on the 9a (#173, on #144). The position fixes so far ran on the out-of-tree port with the same SPI setting.
Notes for review:
omamobile, so the gate runs. It addsdrivers/soc/google/{Kconfig,Makefile}in the same shape as Audio on gs201: CS35L41 amplifiers, Trusty, GSA and the AoC (curated 2/8) #141's, so merging with your curated stack is "keep both lines".