Skip to content

soc: google: gnssif_spi: the Pixel 9a's GNSS link (Kepler over SPI) - #185

Merged
derekross merged 7 commits into
derekross:omamobilefrom
W4HO-ham:tegu-gnssif
Nov 3, 2026
Merged

derekross merged 7 commits into
derekross:omamobilefrom
W4HO-ham:tegu-gnssif

Conversation

@W4HO-ham

@W4HO-ham W4HO-ham commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

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@0 at 3.125 MHz with feedback delay 0, and the gnss node (gpa5-4, gpp2-3). The modules were blacklisted at boot and loaded by hand:

  • modprobe gnss_spi and modprobe gnssif both returned 0; gnss_spi bound spi1.0 and gnssif bound the platform device; /dev/gnss_ipc appeared.
  • kepler_spi_irq_handler registered on gpa5-4 (IRQ 66) with a count of 0, still 0 after 30 s; ap2gnss-spi on gpp2-3 read out lo.
  • Holding /dev/gnss_ipc open for 10 s: the IRQ's wakeup read enabled while open and disabled after close, with no interrupt either way (the last commit's behaviour).
  • rmmod gnssif removed /dev/gnss_ipc and the IRQ; modprobe gnssif brought both back.
  • No UFS or I/O error lines, no oops or WARN. 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:

  • Base: omamobile, so the gate runs. It adds drivers/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".
  • Shape: the binding keeps stock's two nodes, generic compatibles and two modules, so it matches Google's DT and gnssd. A single SPI node with a specific compatible is what upstream would want; I'd do that when this goes upstream, not now.
  • Naming: Google's Kconfig symbol, and no MAINTAINERS entry, as for cpif.
  • The 9a's DT nodes (usi3, spi21 with the controller driving chip select, the gnss node) follow in a separate arm64: dts PR.

@W4HO-ham
W4HO-ham marked this pull request as ready for review November 2, 2026 15:45
@W4HO-ham

W4HO-ham commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

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 (7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty, W=1 clean). They replaced the out-of-tree bring-up modules, with no module parameters, on the daily device tree, which already uses the binding's gnss2ap-spi-gpios and ap2gnss-spi-gpios. I brought the modem up with GNSS, turned on Location and kept a client connected for 10 minutes with the CP link cycling as usual.

  • 556 GGA sentences, 538 fixed; the first fix came 62 s after connect, and every sentence after it was fixed.
  • 7-22 satellites used (median 16) at HDOP 0.4-1.6 (median 0.6), with GPS, Galileo, BeiDou, GLONASS, QZSS and NavIC in view.
  • CHPP received 8321 packets with one bad checksum (before the first fix), no ACK timeouts, no permanent failure, no hardfault, and no Kepler reset after the initial code load.
  • The request interrupt took 16722 interrupts, was armed for wakeup while gnssd held /dev/gnss_ipc open, and nothing was lost by enabling it at open.
  • The CP link went through 1336 power-offs with no reset, no UFS errors and no oops or WARN.

That matches what the out-of-tree port gave on 11-01 (568 of 570 and 558 of 567 in two 600 s sessions).

@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham. This is a model import: Google's files in one commit, byte for byte (I
fetched each one from google-modules/soc/gs at 204078758737 and compared: all ten are
identical), then the port and each fix in its own commit with the reason in the message. The
probe and remove fixes and the IRQ only while /dev/gnss_ipc is open are exactly the kind of
thing I'd want before this runs on more phones, and the ten-minute session (538 of 556 fixed,
1336 link power-offs, no reset) is a convincing result.

Two things:

  1. A rebase, please. omamobile took the Pixel 7 Pro's curated series last night
    (kernel-2026.11.01), so drivers/soc/google/Kconfig and Makefile now exist there with the
    AoC and cpif entries, and the branch no longer merges, which is also why CI shows no checks.
    It's the "keep both lines" you expected. I tried it in a scratch tree: add
    source "drivers/soc/google/gnssif_spi/Kconfig" after the cpif line in the Kconfig and
    obj-$(CONFIG_EXYNOS_GNSS_IF_SPI) += gnssif_spi/ at the end of the Makefile, and the other
    six commits apply cleanly. On that tree our gate passes everything else: all seven signed
    off, W=1 builds of the six C files with no warnings.
  2. The import's checkpatch error. Keep the import byte-identical, as you did. I'd rather be
    able to prove the import with a cmp than have a green check on that one commit, so I'll
    merge past that single INITIALISED_STATIC error and say so when I merge. Could you drop
    the = 0 from static time64_t last_trigger_time in gnss_main.c in the port commit,
    though? The port doesn't touch that line today, so it would land as it is.

One question, not a blocker: the two compatibles are Google's generic names, and our tree will
carry them as ABI once the 9a's DT and device package use them. If you already know you'd want
a specific one upstream (for the S5300's GNSS), now is the cheap time to switch. If you'd rather
keep stock's names for now, that's fine too; just say so in the binding commit.

For the 9a, the option also needs to go into kernel/configs/omamobile.config in
omarchy-mobile when the DT PR comes, so the release kernel builds it.

@W4HO-ham

W4HO-ham commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, Derek, and thanks for checking the import file by file.

  • Rebased onto omamobile 4cf2c8b, keeping both lines as you did: source "drivers/soc/google/gnssif_spi/Kconfig" after the cpif line, and obj-$(CONFIG_EXYNOS_GNSS_IF_SPI) += gnssif_spi/ at the end of the Makefile. The other commits applied unchanged (git range-diff shows them identical).
  • The import stays byte-identical. The port commit now drops the = 0 from static time64_t last_trigger_time in gnss_main.c, with a line in its message. checkpatch --strict: the only error left is the import's INITIALISED_STATIC; the other six commits have none (the binding and the port keep the MAINTAINERS note).
  • The compatibles: I'll keep stock's names for now, since stock's device tree and gnssd know the device by them. A specific compatible for the S5300's GNSS belongs with the single-node binding an upstream submission would want. The binding commit now says so.

Those two commits changed, so they're waiting on my sign-off again; the other five keep theirs. The omamobile.config line goes in with the DT PR, as you said.

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>
@derekross

Copy link
Copy Markdown
Owner

Thank you, @W4HO-ham, that was quick. I checked the new head commit by commit: the rebase resolves drivers/soc/google/Kconfig and Makefile exactly as in my scratch tree, the import is unchanged (so it still cmps against Google's files), the port drops the = 0 with a line in its message, and the binding now says why the generic compatibles stay. The driver files differ from the build you ran for ten minutes only by that initializer, so your session covers this head. Our gate passes on today's omamobile apart from the import's one INITIALISED_STATIC, which I'm merging past as agreed; each port and fix commit also builds on its own as modules with W=1 and no warnings.

A few small things for a later commit, none blocking:

  • gnss_if_parse_dt_pdata() puts devm memory in dev->platform_data, and only the parse-failure path clears it. After a later probe failure or remove() it dangles, and the platform core kfrees platform_data if the device is ever released. Keeping pdata in gnss_ctl (or clearing the pointer) would finish the cleanup commit's job.
  • coredump_store() logs the whole string it's given. If gnssd's dump text can contain a position, I'd rather it didn't land in dmesg, which people paste into reports.
  • gnss_spi_xfer() reads gnss_if.spi twice; one READ_ONCE into a local would do.
  • For the 9a's DT PR: spi-s3c64xx uses DMA for any transfer of at least the FIFO depth when the node has dmas, so 64-byte transfers would stop being the single PIO fills your swap commit relies on. Please leave spi21 without dmas, as the gs201 SPI nodes are, or say what you ran with. And the CONFIG_EXYNOS_GNSS_IF_SPI=m line in kernel/configs/omamobile.config, as we said.

Once this is in, I'll close #137, since this series replaces it.

@derekross
derekross merged commit fe9627c into derekross:omamobile Nov 3, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants