From 0333c27c9a81dbf1bb0f625f42ea9201a34a96ac Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:21:03 -0647 Subject: [PATCH 01/36] Bring-up, not for merge: gnssif_spi: Google's GNSS SPI driver as ported for the Pixel 9a Bring-up, not for merge. The gnssif_spi driver that runs the Pixel 9a's GNSS core (Kepler, on SPI 21 of USI3 in HSI0) as it ran on the palmtop at the start of the night of 2026-10-28/29, before any of MODEM-PLAN G3's link experiments: the base every later commit on this branch changes. It is the gnssif_spi directory of google-modules/soc/gs in Google's GPL zumapro kernel (drivers/soc/google/gnssif_spi, Samsung's GPL-2.0 files), ported to this tree: mainline spi-s3c64xx has no swap mode, so the port sends 8-bit words to put the bytes on the wire in memory order (stock sends 32-bit words with the vendor driver's byte and half-word swap), and the Kepler control device uses the GNSS firmware carve-out and the two GPIO lines of the device tree's gnssif node. gnss_spi binds the samsung,gnss-spi device under spi21; gnssif gives gnssd /dev/gnss_ipc, /dev/gnss_boot and the control ioctls (IOCTL_LOAD_GNSS_IMAGE copies kepler.bin into the carve-out in RAM; nothing touches a partition). This is the "as ported" setting of G3's tables (8-bit words, 64-byte reads, feedback delay 2, SPI mode 0): the control row of the ninth to fourteenth tries and the baseline of the fifteenth to twenty-third, and what the palmtop runs again now that GNSS is parked. The Kconfig symbol defaults to n. The published omamobile branch has no drivers/soc/google yet, so this adds the directory with only this driver in it. --- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/google/Kconfig | 11 + drivers/soc/google/Makefile | 2 + drivers/soc/google/gnssif_spi/Kconfig | 11 + drivers/soc/google/gnssif_spi/Makefile | 6 + .../soc/google/gnssif_spi/gnss_io_device.c | 259 ++++++++++++++++++ .../google/gnssif_spi/gnss_keplerctl_device.c | 149 ++++++++++ .../soc/google/gnssif_spi/gnss_link_device.c | 246 +++++++++++++++++ drivers/soc/google/gnssif_spi/gnss_main.c | 216 +++++++++++++++ drivers/soc/google/gnssif_spi/gnss_prj.h | 77 ++++++ drivers/soc/google/gnssif_spi/gnss_spi.c | 112 ++++++++ drivers/soc/google/gnssif_spi/gnss_spi.h | 34 +++ drivers/soc/google/gnssif_spi/gnss_utils.c | 105 +++++++ drivers/soc/google/gnssif_spi/gnss_utils.h | 84 ++++++ drivers/soc/google/gnssif_spi/include/gnss.h | 95 +++++++ 16 files changed, 1409 insertions(+) create mode 100644 drivers/soc/google/Kconfig create mode 100644 drivers/soc/google/Makefile create mode 100644 drivers/soc/google/gnssif_spi/Kconfig create mode 100644 drivers/soc/google/gnssif_spi/Makefile create mode 100644 drivers/soc/google/gnssif_spi/gnss_io_device.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_keplerctl_device.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_link_device.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_main.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_prj.h create mode 100644 drivers/soc/google/gnssif_spi/gnss_spi.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_spi.h create mode 100644 drivers/soc/google/gnssif_spi/gnss_utils.c create mode 100644 drivers/soc/google/gnssif_spi/gnss_utils.h create mode 100644 drivers/soc/google/gnssif_spi/include/gnss.h diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index a2d65adffb..3ad4aaae6d 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -22,6 +22,7 @@ source "drivers/soc/pxa/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig" +source "drivers/soc/google/Kconfig" source "drivers/soc/samsung/Kconfig" source "drivers/soc/sophgo/Kconfig" source "drivers/soc/sunxi/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index c9e689080c..b4950ca567 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -28,6 +28,7 @@ obj-y += amlogic/ obj-y += qcom/ obj-y += renesas/ obj-y += rockchip/ +obj-y += google/ obj-$(CONFIG_SOC_SAMSUNG) += samsung/ obj-y += sophgo/ obj-y += sunxi/ diff --git a/drivers/soc/google/Kconfig b/drivers/soc/google/Kconfig new file mode 100644 index 0000000000..c7abe0d185 --- /dev/null +++ b/drivers/soc/google/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only + +if ARCH_EXYNOS || COMPILE_TEST + +menu "Google SoC drivers" + +source "drivers/soc/google/gnssif_spi/Kconfig" + +endmenu + +endif diff --git a/drivers/soc/google/Makefile b/drivers/soc/google/Makefile new file mode 100644 index 0000000000..e011922026 --- /dev/null +++ b/drivers/soc/google/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-y += gnssif_spi/ diff --git a/drivers/soc/google/gnssif_spi/Kconfig b/drivers/soc/google/gnssif_spi/Kconfig new file mode 100644 index 0000000000..b0fc1d5861 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +config EXYNOS_GNSS_IF_SPI + tristate "Exynos GNSS SPI interface driver (Pixel 9a bring-up)" + depends on SPI && OF + default n + help + Bring-up only, not for merge: Google's gnssif_spi driver for the + GNSS core behind a SPI link (Kepler on the Pixel 9a), as ported to + this tree for MODEM-PLAN G3. gnss_spi binds the SPI device and + gnssif exposes /dev/gnss_ipc, /dev/gnss_boot and the Kepler control + device to gnssd. diff --git a/drivers/soc/google/gnssif_spi/Makefile b/drivers/soc/google/gnssif_spi/Makefile new file mode 100644 index 0000000000..e97a1ed40f --- /dev/null +++ b/drivers/soc/google/gnssif_spi/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_EXYNOS_GNSS_IF_SPI) += gnss_spi.o + +obj-$(CONFIG_EXYNOS_GNSS_IF_SPI) += gnssif.o +gnssif-y += gnss_main.o gnss_io_device.o gnss_keplerctl_device.o gnss_link_device.o +gnssif-y += gnss_utils.o diff --git a/drivers/soc/google/gnssif_spi/gnss_io_device.c b/drivers/soc/google/gnssif_spi/gnss_io_device.c new file mode 100644 index 0000000000..2c978c41b8 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_io_device.c @@ -0,0 +1,259 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gnss_prj.h" +#include "gnss_utils.h" + +#define WAKE_TIME (HZ/2) /* 500 msec */ +#define MAX_RXQ_DEPTH 1024 + +static inline void iodev_lock_wlock(struct io_device *iod) +{ + if (iod->waketime > 0 && !gnssif_wlock_active(iod->ws)) { + gnssif_wlock_unlock(iod->ws); + gnssif_wlock_lock_timeout(iod->ws, iod->waketime); + } +} + +static void io_dev_recv_betp(struct io_device *iod, + struct link_device *ld, struct sk_buff *skb) +{ + struct sk_buff_head *rxq = &iod->sk_rx_q; + + iodev_lock_wlock(iod); + + if (unlikely(rxq->qlen >= MAX_RXQ_DEPTH)) { + gif_err_limited("Too much rx betps are queued: total %d\n", + MAX_RXQ_DEPTH); + dev_kfree_skb_any(skb); + goto wakeup; + } + skb_queue_tail(rxq, skb); + +wakeup: + wake_up(&iod->wq); + +} + +static int misc_open(struct inode *inode, struct file *filp) +{ + struct io_device *iod = container_of(filp->private_data, struct io_device, + miscdev); + int ref_cnt; + + filp->private_data = (void *)iod; + + ref_cnt = atomic_inc_return(&iod->opened); + + gif_info("%s (opened %d)\n", iod->name, ref_cnt); + + return 0; +} + +static int misc_release(struct inode *inode, struct file *filp) +{ + struct io_device *iod = (struct io_device *)filp->private_data; + int ref_cnt; + + ref_cnt = atomic_dec_return(&iod->opened); + if (ref_cnt == 0) + skb_queue_purge(&iod->sk_rx_q); + + gif_info("%s (opened %d)\n", iod->name, ref_cnt); + + return 0; +} + +static unsigned int misc_poll(struct file *filp, struct poll_table_struct *wait) +{ + struct io_device *iod = (struct io_device *)filp->private_data; + + if (skb_queue_empty(&iod->sk_rx_q)) + poll_wait(filp, &iod->wq, wait); + + if (!skb_queue_empty(&iod->sk_rx_q)) + return POLLIN | POLLRDNORM; + + return 0; +} + +static long misc_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + struct io_device *iod = (struct io_device *)filp->private_data; + + gif_err("%s: ERR! undefined cmd 0x%X\n", iod->name, cmd); + + return -EINVAL; +} + +static ssize_t misc_write(struct file *filp, const char __user *data, + size_t count, loff_t *fpos) +{ + struct io_device *iod = (struct io_device *)filp->private_data; + struct link_device *ld = iod->ld; + char *buff; + int ret; + + /* Store IPC message */ + buff = kzalloc(roundup(count, ALIGNMENT_4BYTE), GFP_KERNEL); + if (!buff) + return -ENOMEM; + + if (copy_from_user(buff, data, count)) { + gif_err("%s->%s: ERR! copy_from_user fail (count %ld)\n", + iod->name, ld->name, count); + kfree(buff); + return -EFAULT; + } + + ret = ld->send(ld, iod, buff, roundup(count, ALIGNMENT_4BYTE)); + if (ret < 0) { + gif_err("%s->%s: ERR! ld->send fail (err %d, count %ld)\n", + iod->name, ld->name, ret, count); + kfree(buff); + return ret; + } + + kfree(buff); + return count; +} + +static ssize_t misc_read(struct file *filp, char *buf, size_t count, + loff_t *fpos) +{ + struct io_device *iod = (struct io_device *)filp->private_data; + struct sk_buff_head *rxq = &iod->sk_rx_q; + struct sk_buff *skb; + int copied = 0; + + if (skb_queue_empty(rxq)) { + gif_err("%s: ERR! no data in rxq\n", iod->name); + return 0; + } + + skb = skb_dequeue(rxq); + if (unlikely(!skb)) { + gif_err("%s: No data in RXQ\n", iod->name); + return 0; + } + + if (count <= 0) { + gif_err("%s: bytes to read not specified\n", iod->name); + return 0; + } + + copied = skb->len > count ? count : skb->len; + + if (copy_to_user(buf, skb->data, copied)) { + gif_err("%s: ERR! copy_to_user fail\n", iod->name); + dev_kfree_skb_any(skb); + return -EFAULT; + } + + gif_debug("%s: data:%d copied:%d qlen:%d\n", + iod->name, skb->len, copied, rxq->qlen); + + if (skb->len > count) { + skb_pull(skb, count); + skb_queue_head(rxq, skb); + } else { + dev_kfree_skb_any(skb); + } + + return copied; +} + +static const struct file_operations misc_io_fops = { + .owner = THIS_MODULE, + .open = misc_open, + .release = misc_release, + .poll = misc_poll, + .unlocked_ioctl = misc_ioctl, +#if IS_ENABLED(CONFIG_COMPAT) + .compat_ioctl = misc_ioctl, +#endif + .write = misc_write, + .read = misc_read, +}; + +static int init_io_device(struct io_device *iod, struct device *dev) +{ + int ret = 0; + + gif_info("+++\n"); + + iod->recv_betp = io_dev_recv_betp; + + init_waitqueue_head(&iod->wq); + skb_queue_head_init(&iod->sk_rx_q); + + iod->miscdev.minor = MISC_DYNAMIC_MINOR; + iod->miscdev.name = iod->name; + iod->miscdev.fops = &misc_io_fops; + iod->waketime = WAKE_TIME; + iod->ws = gnssif_wlock_register(dev, iod->name); + if (iod->ws == NULL) { + gif_err("%s: wakeup_source_register fail\n", iod->name); + return -EINVAL; + } + + ret = misc_register(&iod->miscdev); + if (ret) + gif_err("%s: ERR! misc_register failed\n", iod->name); + + gif_info("---\n"); + + return ret; +} + +struct io_device *create_io_device(struct platform_device *pdev, + struct link_device *ld, struct gnss_ctl *gc, struct gnss_pdata *pdata) +{ + int ret; + struct device *dev = &pdev->dev; + struct io_device *iod; + + gif_info("+++\n"); + iod = devm_kzalloc(dev, sizeof(struct io_device), GFP_KERNEL); + if (!iod) { + gif_err("iod is NULL\n"); + return NULL; + } + + iod->name = pdata->node_name; + atomic_set(&iod->opened, 0); + + iod->gc = gc; + gc->iod = iod; + + iod->ld = ld; + ld->iod = iod; + + ret = init_io_device(iod, dev); + if (ret) { + devm_kfree(dev, iod); + gif_err("init_io_device fail (%d)\n", ret); + return NULL; + } + + gif_info("---\n"); + + return iod; +} diff --git a/drivers/soc/google/gnssif_spi/gnss_keplerctl_device.c b/drivers/soc/google/gnssif_spi/gnss_keplerctl_device.c new file mode 100644 index 0000000000..50929b9b3e --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_keplerctl_device.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include + +#include "include/gnss.h" +#include "gnss_prj.h" +#include "gnss_utils.h" + +/* handling interrupt by BETP messages from kepler through SPI */ +static irqreturn_t kepler_spi_irq_handler(int irq, void *data) +{ + struct gnss_ctl *gc = data; + struct link_device *ld = gc->iod->ld; + + gif_disable_irq_nosync(&gc->irq_gnss2ap_spi); + + if (atomic_read(&gc->wait_rdy)) { + atomic_set(&gc->wait_rdy, 0); + complete_all(&gc->gnss_rdy_cmpl); + return IRQ_HANDLED; + } + + if (atomic_read(&gc->rx_in_progress) == 0) { + queue_delayed_work(ld->rx_wq, &ld->rx_dwork, 0); + } + + return IRQ_HANDLED; +} + +static int kepler_spi_status(struct gnss_ctl *gc) +{ + return gpiod_get_value(gc->gpio_gnss2ap_spi.desc); +} + +static void kepler_send_betp_int(struct gnss_ctl *gc, int value) +{ + gif_debug("About to Set ap2gnss_spi value to %d\n", value); + gpiod_set_value(gc->gpio_ap2gnss_spi.desc, value); + gif_debug("complete to set ap2gnss_spi value to %d\n", value); +} + +static int kepler_betp_int_status(struct gnss_ctl *gc) +{ + return gpiod_get_value(gc->gpio_ap2gnss_spi.desc); +} + +static void gnss_set_ops(struct gnss_ctl *gc) +{ + gc->ops.gnss_spi_status = kepler_spi_status; + gc->ops.gnss_send_betp_int = kepler_send_betp_int; + gc->ops.gnss_betp_int_status = kepler_betp_int_status; +} + +static int init_ctl_device(struct gnss_ctl *gc, struct gnss_pdata *pdata) +{ + int ret; + + gnss_set_ops(gc); + + dev_set_drvdata(gc->dev, gc); + + + /* + * omamobile: the lines as GPIO descriptors from the node's + * gnss2ap-spi-gpios and ap2gnss-spi-gpios (stock: of_get_named_gpio() + * on gpio_gnss2ap_spi and gpio_ap2gnss_spi), released by devm. + */ + gc->gpio_gnss2ap_spi.label = "GNSS2AP_SPI"; + gc->gpio_gnss2ap_spi.desc = devm_gpiod_get(gc->dev, "gnss2ap-spi", GPIOD_IN); + if (IS_ERR(gc->gpio_gnss2ap_spi.desc)) { + gif_err("Can't get gnss2ap-spi-gpios (%ld)\n", + PTR_ERR(gc->gpio_gnss2ap_spi.desc)); + return PTR_ERR(gc->gpio_gnss2ap_spi.desc); + } + ret = gpiod_to_irq(gc->gpio_gnss2ap_spi.desc); + if (ret < 0) { + gif_err("gnss2ap-spi has no interrupt (%d)\n", ret); + return ret; + } + gc->irq_gnss2ap_spi.num = ret; + + /* Disable the interrupt until gnss_main.c probe function finish */ + gif_configure_irq(&gc->irq_gnss2ap_spi, gc->irq_gnss2ap_spi.num, + "kepler_spi_irq_handler", IRQF_TRIGGER_HIGH | IRQF_NO_AUTOEN); + + ret = gif_request_irq(&gc->irq_gnss2ap_spi, kepler_spi_irq_handler, gc); + if (ret) { + gif_err("Request irq fail - kepler_spi_irq_handler(%d)\n", ret); + return ret; + } + + ret = enable_irq_wake(gc->irq_gnss2ap_spi.num); + if (ret) /* omamobile: not fatal, the line still interrupts */ + gif_err("enable_irq_wake failed (%d): no wake from GNSS\n", ret); + + gc->gpio_ap2gnss_spi.label = "AP2GNSS_SPI"; + gc->gpio_ap2gnss_spi.desc = devm_gpiod_get(gc->dev, "ap2gnss-spi", GPIOD_OUT_LOW); + if (IS_ERR(gc->gpio_ap2gnss_spi.desc)) { + ret = PTR_ERR(gc->gpio_ap2gnss_spi.desc); + gif_err("Can't get ap2gnss-spi-gpios (%d)\n", ret); + goto free_gpio_irq; + } + + init_completion(&gc->gnss_rdy_cmpl); + + atomic_set(&gc->wait_rdy, 0); + atomic_set(&gc->tx_in_progress, 0); + atomic_set(&gc->rx_in_progress, 0); + + return 0; + +free_gpio_irq: + free_irq(gc->irq_gnss2ap_spi.num, gc); /* stock passed &gc */ + + return ret; + +} + +struct gnss_ctl *create_ctl_device(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct gnss_pdata *pdata = pdev->dev.platform_data; + struct gnss_ctl *gc; + int ret; + + gc = devm_kzalloc(dev, sizeof(struct gnss_ctl), GFP_KERNEL); + if (!gc) + return NULL; + gc->dev = dev; + gc->pdata = pdata; + gc->name = pdata->name; + + ret = init_ctl_device(gc, pdata); + if (ret) { + gif_err("%s: init_ctl_device fail (err %d)\n", + pdata->name, ret); + devm_kfree(dev, gc); + return NULL; + } + + return gc; +} diff --git a/drivers/soc/google/gnssif_spi/gnss_link_device.c b/drivers/soc/google/gnssif_spi/gnss_link_device.c new file mode 100644 index 0000000000..fca0798a66 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include +#include + +#include "include/gnss.h" +#include "gnss_prj.h" +#include "gnss_utils.h" +#include "gnss_spi.h" + +/* #define GNSS_PKT_DEBUG 1 */ + +#if defined(GNSS_PKT_DEBUG) +#define PR_BUFFER_SIZE 64 + +static inline void dump2hex(char *buff, size_t buff_size, + const char *data, size_t data_len) +{ + static const char *hex = "0123456789abcdef"; + char *dest = buff; + size_t len; + size_t i; + + if (buff_size < (data_len * 3)) + len = buff_size / 3; + else + len = data_len; + + for (i = 0; i < len; i++) { + *dest++ = hex[(data[i] >> 4) & 0xf]; + *dest++ = hex[data[i] & 0xf]; + *dest++ = ' '; + } + + /* The last character must be overwritten with NULL */ + if (likely(len > 0)) + dest--; + + *dest = 0; +} + +static int pr_buffer(const char *tag, const char *data, size_t data_len, + size_t max_len) +{ + size_t len = min(data_len, max_len); + unsigned char str[PR_BUFFER_SIZE * 3]; /* 1 <= sizeof <= max_len*3 */ + + if (len > PR_BUFFER_SIZE) + len = PR_BUFFER_SIZE; + + dump2hex(str, (len ? len * 3 : 1), data, len); + + /* don't change this printk to mif_debug for print this as level7 */ + return pr_info("%s: %s(%ld): %s%s\n", "gnss_spi", tag, (long)data_len, + str, (len == data_len) ? "" : " ..."); +} +#else /* GNSS_PKT_DEBUG */ +static inline int pr_buffer(const char *tag, const char *data, size_t data_len, + size_t max_len) +{ + return 0; +} +#endif /* GNSS_PKT_DEBUG */ + +static void rx_work(struct work_struct *ws) +{ + struct link_device *ld = container_of(ws, struct link_device, + rx_dwork.work); + struct gnss_ctl *gc = ld->gc; + struct io_device *iod = ld->iod; + struct sk_buff *skb = NULL; + char *buff = NULL; + unsigned int len = ld->spi_rx_size; + unsigned int max_len = ld->max_spi_rx_size; + unsigned int iter = 0; + int ret = 0; + + atomic_set(&gc->rx_in_progress, 1); + + do { + if (!skb) { + gc->ops.gnss_send_betp_int(gc, 1); + if (atomic_read(&gc->tx_in_progress) == 0) { + udelay(100); + gc->ops.gnss_send_betp_int(gc, 0); + } + + skb = alloc_skb(max_len, GFP_KERNEL); + if (!skb) { + gif_err("%s: ERR! rx alloc_skb fail (msg size:%u)\n", + iod->name, len); + goto exit; + } + } + + buff = skb_put(skb, len); + ret = gnss_spi_recv(buff, len); + if (ret) { + gif_err("gnss_spi_recv() error:%d\n", ret); + dev_kfree_skb_any(skb); + goto exit; + } + + iter++; + if (skb->len >= max_len || atomic_read(&gc->wait_rdy) == 1) { + pr_buffer("RX", skb->data, skb->len, skb->len); + gif_debug("Received %d(%d * %d) bytes data from kepler.\n", + skb->len, len, iter); + + iod->recv_betp(iod, ld, skb); + skb = NULL; /* skb to be freed by gnss iod*/ + iter = 0; + + if (atomic_read(&gc->wait_rdy) == 1) { + atomic_set(&gc->wait_rdy, 0); + complete_all(&gc->gnss_rdy_cmpl); + gif_debug("TX request while Rx is in-progress\n"); + + while (atomic_read(&gc->tx_in_progress) == 1) + udelay(10); + } + } + } while (gc->ops.gnss_spi_status(gc)); + + if (skb) { + pr_buffer("RX", skb->data, skb->len, skb->len); + gif_debug("Received %d(%d * %d) bytes data from kepler.\n", + skb->len, len, iter); + + iod->recv_betp(iod, ld, skb); + } +exit: + atomic_set(&gc->rx_in_progress, 0); + if (atomic_read(&gc->tx_in_progress) == 0) + gc->ops.gnss_send_betp_int(gc, 0); + + gif_debug("Done receiving from kepler\n"); + + gif_enable_irq(&gc->irq_gnss2ap_spi); +} + +static int send_betp(struct link_device *ld, struct io_device *iod, char *buff, + unsigned int size) +{ + struct gnss_ctl *gc = ld->gc; + struct sk_buff *skb; + int ret = 0; + + if (size > ld->spi_tx_size) { + gif_err("size(%d) is over %d\n", size, ld->spi_tx_size); + size = ld->spi_tx_size; + } + + skb = alloc_skb(size, GFP_KERNEL); + if (!skb) { + gif_err("%s: ERR! tx alloc_skb fail (msg size:%u)\n", + iod->name, size); + return -ENOMEM; + } + skb_put(skb, size); + + atomic_set(&gc->tx_in_progress, 1); + + reinit_completion(&gc->gnss_rdy_cmpl); + atomic_set(&gc->wait_rdy, 1); + + gc->ops.gnss_send_betp_int(gc, 1); + + gif_enable_irq(&gc->irq_gnss2ap_spi); + + ret = wait_for_completion_timeout(&gc->gnss_rdy_cmpl, GNSS_RDY_TIMEOUT); + if (ret == 0) { + gif_err("TIMEOUT(%lu): gnss ready signal not came from kepler\n", GNSS_RDY_TIMEOUT); + dev_kfree_skb_any(skb); + ret = -EBUSY; + goto exit; + } + + ret = gnss_spi_send(buff, size, (char *)skb->data); + if (ret) { + gif_err("gnss_spi_send() error:%d\n", ret); + dev_kfree_skb_any(skb); + goto exit; + } else { + gif_debug("Sent %d bytes to kepler\n", size); + pr_buffer("TX", buff, size, size); + iod->recv_betp(iod, ld, skb); + } + +exit: + atomic_set(&gc->wait_rdy, 0); + atomic_set(&gc->tx_in_progress, 0); + gc->ops.gnss_send_betp_int(gc, 0); + + gif_enable_irq(&gc->irq_gnss2ap_spi); + + return ret; +} + +struct link_device *create_link_device(struct platform_device *pdev) +{ + struct link_device *ld = NULL; + struct gnss_pdata *pdata = NULL; + struct device *dev = &pdev->dev; + + gif_info("+++\n"); + + pdata = (struct gnss_pdata *)dev->platform_data; + if (!pdata) { + gif_err("ERR! gnss == NULL\n"); + return NULL; + } + + ld = devm_kzalloc(dev, sizeof(struct link_device), GFP_KERNEL); + if (!ld) { + gif_err("ERR! link device kzalloc fail\n"); + return NULL; + } + + ld->pdata = pdata; + ld->name = "GNSS_LINK_DEVICE"; + ld->send = send_betp; + ld->spi_rx_size = DEFAULT_SPI_RX_SIZE; + ld->max_spi_rx_size = MAX_SPI_RX_SIZE; + ld->spi_tx_size = DEFAULT_SPI_TX_SIZE; + + ld->rx_wq = alloc_workqueue("gnss_spi_wq", + __WQ_LEGACY | WQ_MEM_RECLAIM | WQ_UNBOUND, 1); + if (!ld->rx_wq) { + gif_err("alloc_workqueue() error\n"); + goto exit; + } + INIT_DELAYED_WORK(&ld->rx_dwork, rx_work); + + gif_info("---\n"); + +exit: + return ld; +} diff --git a/drivers/soc/google/gnssif_spi/gnss_main.c b/drivers/soc/google/gnssif_spi/gnss_main.c new file mode 100644 index 0000000000..35932ffde8 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_main.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ +#include +#include +#include +#include +#include +#include + +#include "gnss_prj.h" +#include "gnss_utils.h" + +#define DEVICE_NAME "gnss" + +/* + * omamobile: Google's subsystem coredump (sscoredump) is not in mainline; + * a coredump written to the sysfs file is logged and dropped. + */ + +static ssize_t coredump_store(struct device *dev, struct device_attribute *attr, const char *buf, + size_t count) +{ + int symbol = (int)';'; + const char *next = NULL; + char *coredump = NULL; + char *reason = NULL; + int length = 0; + static time64_t last_trigger_time = 0; + time64_t trigger_time = ktime_get_seconds(); + + // Ignore the trigger time less than 30 seconds + if (trigger_time - last_trigger_time < 30) { + goto clean; + } + last_trigger_time = trigger_time; + + gif_err("Trigger Coredump string: %s\n", buf); + next = strchr(buf, symbol); + if (next) { + length = (int)(next - buf); + reason = kmalloc(length + 1, GFP_KERNEL); + if (!reason) { + gif_err("Allocate crash reason failed\n"); + goto clean; + } + memcpy(reason, buf, length); + reason[length] = '\0'; + length = strlen(next + 1); + coredump = kmalloc(length, GFP_KERNEL); + if (!coredump) { + gif_err("Allocate crash coredump failed\n"); + goto clean; + } + memcpy(coredump, next + 1, length); + gnss_set_coredump(coredump, length, reason); + } +clean: + if (reason) + kfree(reason); + if (coredump) + kfree(coredump); + return count; +} + +static DEVICE_ATTR_WO(coredump); + +static int parse_dt_common_pdata(struct device_node *np, struct gnss_pdata *pdata) +{ + gif_dt_read_string(np, "device,name", pdata->name); + gif_dt_read_string(np, "device_node_name", pdata->node_name); + + gif_info("device name: %s node name: %s\n", pdata->name, pdata->node_name); + return 0; +} + +static struct gnss_pdata *gnss_if_parse_dt_pdata(struct device *dev) +{ + struct gnss_pdata *pdata; + int ret = 0; + + pdata = devm_kzalloc(dev, sizeof(struct gnss_pdata), GFP_KERNEL); + if (!pdata) { + gif_err("gnss_pdata: alloc fail\n"); + return ERR_PTR(-ENOMEM); + } + dev->platform_data = pdata; + + ret = parse_dt_common_pdata(dev->of_node, pdata); + if (ret != 0) { + gif_err("Failed to parse common pdata from dt\n"); + goto parse_dt_pdata_err; + } + + gif_info("DT parse complete!\n"); + return pdata; + +parse_dt_pdata_err: + if (pdata) + devm_kfree(dev, pdata); + dev->platform_data = NULL; + + return ERR_PTR(-EINVAL); +} + +static void gnss_remove(struct platform_device *pdev) +{ + struct gnss_ctl *gc = platform_get_drvdata(pdev); + + gif_disable_irq_sync(&gc->irq_gnss2ap_spi); + + gpiod_set_value(gc->gpio_ap2gnss_spi.desc, 0); + + free_irq(gc->irq_gnss2ap_spi.num, gc); /* the lines are devm */ + + device_remove_file(&pdev->dev, &dev_attr_coredump); +} + +static int gnss_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct gnss_pdata *pdata = dev->platform_data; + struct gnss_ctl *gc; + struct io_device *iod; + struct link_device *ld; + + gif_info("Exynos GNSS interface driver probe begins\n"); + + gif_info("%s: +++\n", pdev->name); + + if (!dev->of_node) { + gif_err("No DT data!\n"); + goto probe_fail; + } + + pdata = gnss_if_parse_dt_pdata(dev); + if (IS_ERR(pdata)) { + gif_err("DT parse error!\n"); + return PTR_ERR(pdata); + } + + gc = create_ctl_device(pdev); + if (!gc) { + gif_err("%s: Could not create gc\n", pdata->name); + goto probe_fail; + } + + ld = create_link_device(pdev); + if (!ld) { + gif_err("%s: Could not create ld\n", pdata->name); + goto free_gc; + } + + ld->gc = gc; + + iod = create_io_device(pdev, ld, gc, pdata); + if (!iod) { + gif_err("%s: Could not create iod\n", pdata->name); + goto free_ld; + } + + platform_set_drvdata(pdev, gc); + + + if (device_create_file(dev, &dev_attr_coredump)) + gif_err("Unable to create sysfs coredump entry"); + + /* wa: to prevent wrong irq handling during probe */ + gif_enable_irq(&gc->irq_gnss2ap_spi); + + gif_info("%s: ---\n", pdev->name); + + return 0; + +free_ld: + devm_kfree(dev, ld); +free_gc: + devm_kfree(dev, gc); +probe_fail: + gif_err("%s: xxx\n", pdata->name); + + return -ENOMEM; +} + +static const struct of_device_id gnss_dt_match[] = { + { + .compatible = "samsung,exynos-gnss", + }, + {}, +}; +MODULE_DEVICE_TABLE(of, gnss_dt_match); + +static struct platform_driver gnss_driver = { + .probe = gnss_probe, + .remove = gnss_remove, + .driver = { + .name = "gnss_interface", + .owner = THIS_MODULE, +#if IS_ENABLED(CONFIG_OF) + .of_match_table = of_match_ptr(gnss_dt_match), +#endif + }, +}; + +module_platform_driver(gnss_driver); + +int gnss_set_coredump(const char *buf, int buf_len, const char *info) +{ + gif_err("GNSS coredump (%d bytes, %s) dropped: no sscoredump\n", buf_len, info); + return 0; +} + +MODULE_DESCRIPTION("Exynos GNSS interface driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/soc/google/gnssif_spi/gnss_prj.h b/drivers/soc/google/gnssif_spi/gnss_prj.h new file mode 100644 index 0000000000..8e51d32d09 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_prj.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022, Samsung Electronics. + * + */ + +#ifndef __GNSS_PRJ_H__ +#define __GNSS_PRJ_H__ + +#include +#include +#include +#include + +#include "include/gnss.h" + +#define GNSS_RDY_TIMEOUT msecs_to_jiffies(5000) +#define ALIGNMENT_4BYTE 4 + +struct io_device { + char *name; + struct link_device *ld; + struct gnss_ctl *gc; + atomic_t opened; + wait_queue_head_t wq; + struct miscdevice miscdev; + struct sk_buff_head sk_rx_q; + struct wakeup_source *ws; + long waketime; + + void (*recv_betp)(struct io_device *iod, struct link_device *ld, + struct sk_buff *skb); +}; + +struct link_device { + char *name; + struct gnss_pdata *pdata; + struct gnss_ctl *gc; + struct io_device *iod; + struct gnss_spi *gnss_if; + unsigned int spi_rx_size; + unsigned int max_spi_rx_size; + unsigned int spi_tx_size; + struct workqueue_struct *rx_wq; + struct delayed_work rx_dwork; + + int (*send)(struct link_device *ld, struct io_device *iod, char *buff, + unsigned int size); +}; + +struct gnssctl_ops { + int (*gnss_spi_status)(struct gnss_ctl *gc); + void (*gnss_send_betp_int)(struct gnss_ctl *gc, int value); + int (*gnss_betp_int_status)(struct gnss_ctl *gc); +}; + +struct gnss_ctl { + struct device *dev; + char *name; + struct gnss_pdata *pdata; + struct gnssctl_ops ops; + struct io_device *iod; + struct completion gnss_rdy_cmpl; + struct gnss_irq irq_gnss2ap_spi; + struct gnss_gpio gpio_gnss2ap_spi; + struct gnss_gpio gpio_ap2gnss_spi; + atomic_t wait_rdy; + atomic_t tx_in_progress; + atomic_t rx_in_progress; +}; + +struct gnss_ctl *create_ctl_device(struct platform_device *pdev); +struct link_device *create_link_device(struct platform_device *pdev); +struct io_device *create_io_device(struct platform_device *pdev, + struct link_device *ld, struct gnss_ctl *gc, struct gnss_pdata *pdata); + +#endif /* end of __GNSS_PRJ_H__ */ diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c new file mode 100644 index 0000000000..83680d08dc --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include +#include +#include + +#include "include/gnss.h" +#include "gnss_spi.h" + + +int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) +{ + int ret = 0; + struct spi_message msg; + struct spi_transfer tx; + + memset(&tx, 0, sizeof(struct spi_transfer)); + spi_message_init(&msg); + tx.len = size; + tx.tx_buf = buff; + tx.bits_per_word = SPI_BITS_PER_WORD; + if (rx_buff) + tx.rx_buf = rx_buff; + spi_message_add_tail(&tx, &msg); + ret = spi_sync(gnss_if.spi, &msg); + if (ret < 0) + gif_err("spi_sync() error:%d\n", ret); + + return ret; +} +EXPORT_SYMBOL(gnss_spi_send); + +int gnss_spi_recv(char *buff, unsigned int size) +{ + int ret = 0; + struct spi_message msg; + struct spi_transfer rx; + + memset(&rx, 0, sizeof(struct spi_transfer)); + rx.len = size; + rx.rx_buf = buff; + rx.bits_per_word = SPI_BITS_PER_WORD; + spi_message_init(&msg); + spi_message_add_tail(&rx, &msg); + ret = spi_sync(gnss_if.spi, &msg); + if (ret < 0) + gif_err("spi_sync() error:%d\n", ret); + + return ret; + +} +EXPORT_SYMBOL(gnss_spi_recv); + +static int gnss_spi_probe(struct spi_device *spi) +{ + int ret = 0; + + gif_info("+++\n"); + mutex_init(&gnss_if.lock); + + if (spi_setup(spi)) { + gif_err("ERR! spi_setup fail\n"); + ret = -EINVAL; + goto err_setup; + } + spi_set_drvdata(spi, &gnss_if); + gnss_if.spi = spi; + gif_info("---\n"); + + return 0; + +err_setup: + mutex_destroy(&gnss_if.lock); + + return ret; +} + +static void gnss_spi_remove (struct spi_device *spi) +{ + struct gnss_spi *gnss_if = spi_get_drvdata(spi); + + mutex_destroy(&gnss_if->lock); +} + +static const struct of_device_id gnss_spi_dt_match[] = { + { .compatible = "samsung,gnss-spi" }, + {}, +}; +MODULE_DEVICE_TABLE(of, gnss_spi_dt_match); + +static struct spi_driver gnss_spi_driver = { + .probe = gnss_spi_probe, + .remove = gnss_spi_remove, + .driver = { + .name = "gnss_spi", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(gnss_spi_dt_match), + .suppress_bind_attrs = true, + }, +}; +module_spi_driver(gnss_spi_driver); + +MODULE_DESCRIPTION("Exynos SPI driver for GNSS communication"); +MODULE_LICENSE("GPL"); + diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h new file mode 100644 index 0000000000..84ebf7c6df --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022, Samsung Electronics. + * + */ + +#ifndef __GNSS_SPI_H__ +#define __GNSS_SPI_H__ + +#include +#include + +#define DEFAULT_SPI_RX_SIZE 64 +#define MAX_SPI_RX_SIZE SZ_2K +#define DEFAULT_SPI_TX_SIZE SZ_4K +/* + * omamobile: stock sends 32-bit words with the vendor SPI driver's + * "swap-mode" (byte and half-word swap), which puts bytes on the wire in + * memory order; mainline spi-s3c64xx has no swap mode, and 8-bit words give + * that order. + */ +#define SPI_BITS_PER_WORD 8 + +struct gnss_spi { + struct spi_device *spi; + struct mutex lock; +}; + +static struct gnss_spi gnss_if; + +extern int gnss_spi_send(char *buff, unsigned int size, char *recv_buff); +extern int gnss_spi_recv(char *buff, unsigned int size); + +#endif /* __GNSS_SPI_H__ */ diff --git a/drivers/soc/google/gnssif_spi/gnss_utils.c b/drivers/soc/google/gnssif_spi/gnss_utils.c new file mode 100644 index 0000000000..0825d80b85 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_utils.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include +#include + +#include "gnss_prj.h" +#include "gnss_utils.h" + + +void gif_configure_irq(struct gnss_irq *irq, unsigned int num, const char *name, + unsigned long flags) +{ + spin_lock_init(&irq->lock); + irq->num = num; + strscpy(irq->name, name, sizeof(irq->name)); + irq->flags = flags; + gif_info("name:%s num:%d flags:0x%08lX\n", name, num, flags); +} + +int gif_request_irq(struct gnss_irq *irq, irq_handler_t isr, void *data) +{ + int ret; + + ret = request_irq(irq->num, isr, irq->flags, irq->name, data); + if (ret) { + gif_err("%s: ERR! request_irq fail (%d)\n", irq->name, ret); + return ret; + } + + irq->active = irq->flags & IRQF_NO_AUTOEN ? false : true; + irq->registered = true; + + gif_info("%s(#%d) handler registered (flags:0x%08lX)\n", + irq->name, irq->num, irq->flags); + + return 0; +} + +void gif_enable_irq(struct gnss_irq *irq) +{ + unsigned long flags; + + spin_lock_irqsave(&irq->lock, flags); + + if (irq->active) + goto exit; + + enable_irq(irq->num); + + irq->active = true; + +exit: + spin_unlock_irqrestore(&irq->lock, flags); +} + +void gif_disable_irq_nosync(struct gnss_irq *irq) +{ + unsigned long flags; + + if (irq->registered == false) + return; + + spin_lock_irqsave(&irq->lock, flags); + + if (!irq->active) + goto exit; + disable_irq_nosync(irq->num); + irq->active = false; + +exit: + spin_unlock_irqrestore(&irq->lock, flags); +} + +void gif_disable_irq_sync(struct gnss_irq *irq) +{ + if (irq->registered == false) + return; + + spin_lock(&irq->lock); + + if (!irq->active) { + spin_unlock(&irq->lock); + gif_debug("%s(#%d) is not active <%ps>\n", + irq->name, irq->num, CALLER); + return; + } + + spin_unlock(&irq->lock); + + disable_irq(irq->num); + + spin_lock(&irq->lock); + irq->active = false; + spin_unlock(&irq->lock); + + gif_debug("%s(#%d) is disabled <%ps>\n", + irq->name, irq->num, CALLER); +} diff --git a/drivers/soc/google/gnssif_spi/gnss_utils.h b/drivers/soc/google/gnssif_spi/gnss_utils.h new file mode 100644 index 0000000000..9125e6a410 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_utils.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022, Samsung Electronics. + * + */ + +#ifndef __GNSS_UTILS_H__ +#define __GNSS_UTILS_H__ + +#include "gnss_prj.h" + +static inline struct wakeup_source *gnssif_wlock_register(struct device *dev, + const char *name) +{ + struct wakeup_source *ws = NULL; + + ws = wakeup_source_register(dev, name); + if (ws == NULL) { + gif_err("%s: wakelock register fail\n", name); + return NULL; + } + + return ws; +} + +static inline void gnssif_wlock_unregister(struct wakeup_source *ws) +{ + if (ws == NULL) { + gif_err("wakelock unregister fail\n"); + return; + } + + wakeup_source_unregister(ws); +} + +static inline void gnssif_wlock_lock(struct wakeup_source *ws) +{ + if (ws == NULL) { + gif_err("wakelock fail\n"); + return; + } + + __pm_stay_awake(ws); +} + +static inline void gnssif_wlock_lock_timeout(struct wakeup_source *ws, long timeout) +{ + if (ws == NULL) { + gif_err("wakelock timeout fail\n"); + return; + } + + __pm_wakeup_event(ws, jiffies_to_msecs(timeout)); +} + +static inline void gnssif_wlock_unlock(struct wakeup_source *ws) +{ + if (ws == NULL) { + gif_err("wake unlock fail\n"); + return; + } + + __pm_relax(ws); +} + +static inline int gnssif_wlock_active(struct wakeup_source *ws) +{ + if (ws == NULL) { + gif_err("wakelock active fail\n"); + return 0; + } + + return ws->active; +} + +/* gnss irq */ +void gif_configure_irq(struct gnss_irq *irq, unsigned int num, const char *name, + unsigned long flags); +int gif_request_irq(struct gnss_irq *irq, irq_handler_t isr, void *data); +void gif_enable_irq(struct gnss_irq *irq); +void gif_disable_irq_nosync(struct gnss_irq *irq); +void gif_disable_irq_sync(struct gnss_irq *irq); + +#endif /* end of __GNSS_UTILS_H__ */ diff --git a/drivers/soc/google/gnssif_spi/include/gnss.h b/drivers/soc/google/gnssif_spi/include/gnss.h new file mode 100644 index 0000000000..5226f88bb3 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/include/gnss.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2022, Samsung Electronics. + * + */ + +#ifndef __GNSS_IF_H__ +#define __GNSS_IF_H__ + +#include +#include + +#define MAX_NAME_LEN 64 + +struct gnss_pdata { + char *name; /* device name (ex. KEPLER) */ + char *node_name; /* device node (ex. gnss_ipc) */ + + int irq_gnss2ap_spi; + int irq_gnss2ap_wdt; + + struct gnss_io_t *iodev; + struct gnss_link_dev *link_dev; + +}; + +struct gnss_irq { + spinlock_t lock; + unsigned int num; + char name[MAX_NAME_LEN]; + unsigned long flags; + bool active; + bool registered; +}; + +struct gnss_gpio { + struct gpio_desc *desc; /* omamobile: gpiod, not a global number */ + const char *label; +}; + +#define gif_dt_read_enum(np, prop, dest) \ + do { \ + u32 val; \ + if (of_property_read_u32(np, prop, &val)) \ + return -EINVAL; \ + dest = (__typeof__(dest))(val); \ + } while (0) + +#define gif_dt_read_bool(np, prop, dest) \ + do { \ + u32 val; \ + if (of_property_read_u32(np, prop, &val)) \ + return -EINVAL; \ + dest = val ? true : false; \ + } while (0) + +#define gif_dt_read_string(np, prop, dest) \ + do { \ + if (of_property_read_string(np, prop, \ + (const char **)&dest)) \ + return -EINVAL; \ + } while (0) + +#define gif_dt_read_u32(np, prop, dest) \ + do { \ + u32 val; \ + if (of_property_read_u32(np, prop, &val)) \ + return -EINVAL; \ + dest = val; \ + } while (0) +#define gif_dt_read_u32_array(np, prop, dest, sz) \ + do { \ + if (of_property_read_u32_array(np, prop, dest, (sz))) \ + return -EINVAL; \ + } while (0) + +#define LOG_TAG "gif: " +#define CALLEE (__func__) +#define CALLER (__builtin_return_address(0)) + +#define gif_err_limited(fmt, ...) \ + printk_ratelimited(KERN_ERR LOG_TAG "%s: " pr_fmt(fmt), __func__, ##__VA_ARGS__) +#define gif_err(fmt, ...) \ + pr_err(LOG_TAG "%s: " pr_fmt(fmt), __func__, ##__VA_ARGS__) +#define gif_debug(fmt, ...) \ + pr_debug(LOG_TAG "%s: " pr_fmt(fmt), __func__, ##__VA_ARGS__) +#define gif_info(fmt, ...) \ + pr_info(LOG_TAG "%s: " pr_fmt(fmt), __func__, ##__VA_ARGS__) +#define gif_trace(fmt, ...) \ + printk(KERN_DEBUG "gif: %s: %d: called(%pS): " fmt, \ + __func__, __LINE__, __builtin_return_address(0), ##__VA_ARGS__) + +int gnss_set_coredump(const char *buf, int buf_len, const char *info); + +#endif /* __GNSS_IF_H__ */ From acb2e9776733f7db5fff656d3b1a22a49c7dfa99 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 02/36] Bring-up, not for merge: gnssif_spi: 32-byte reads Bring-up, not for merge. DEFAULT_SPI_RX_SIZE 64 to 32, so rx_work reads Kepler in 32-byte transfers, which stay under spi-s3c64xx's 64-byte FIFO and never get cut. MODEM-PLAN G3, ninth to fourteenth tries: the "rx chunk 32" rows (mode 0, delay 2: 17 bad checksums, Kepler opstate 0; then with the feedback-delay-0 DTB of this branch: 93). Smaller reads alone did not give a working link. --- drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 84ebf7c6df..0a8d0a263e 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 64 +#define DEFAULT_SPI_RX_SIZE 32 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* From d5c871bc2b075033f355201f796abf391c363394 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 03/36] Bring-up, not for merge: gnssif_spi: spi_mode and speed_hz module parameters Bring-up, not for merge. gnss_spi takes spi_mode (0-3, written into spi->mode at probe) and speed_hz (spi->max_speed_hz), so one module tries the SPI modes and a slower clock without a DTB round. MODEM-PLAN G3, ninth to fourteenth tries: mode 1 with 32-byte reads (34 bad checksums, opstate 0), mode 1 with 64-byte reads (RX clean, but Kepler never sees our RESET-ACK: TX lost), mode 0 at "1 MHz" (63; the clock did not change, see the twenty-fourth try) and mode 3 (32). The 32-byte read size of the previous commit stays in gnss_spi.h; the 64-byte row put it back by hand. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 83680d08dc..0ab3e229b5 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -58,10 +58,22 @@ int gnss_spi_recv(char *buff, unsigned int size) } EXPORT_SYMBOL(gnss_spi_recv); +static unsigned int spi_mode; +static unsigned int speed_hz; +module_param(speed_hz, uint, 0444); +module_param(spi_mode, uint, 0444); +MODULE_PARM_DESC(spi_mode, "SPI mode for Kepler (test): 0-3"); + static int gnss_spi_probe(struct spi_device *spi) { int ret = 0; + spi->mode = (spi->mode & ~SPI_MODE_X_MASK) | (spi_mode & SPI_MODE_X_MASK); + if (speed_hz) + spi->max_speed_hz = speed_hz; + gif_info("spi speed %u\n", spi->max_speed_hz); + gif_info("spi mode %u\n", spi->mode & SPI_MODE_X_MASK); + gif_info("+++\n"); mutex_init(&gnss_if.lock); From d511589a85c9cd0abde727f8d1786207b4d9dc46 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 04/36] Bring-up, not for merge: gnssif_spi: 32-bit words, byte-swapped in software Bring-up, not for merge. SPI_BITS_PER_WORD 32, as stock, with every word swapped (swab32) before a write and after a read, so the bytes go on the wire in memory order as the vendor driver's swap-mode does; CHPP frames are padded to a multiple of 4 and a size that is not is refused. The spi_mode and speed_hz parameters go. MODEM-PLAN G3, ninth to fourteenth tries, "32-bit words (swapped in gnss_spi)": 1 bad checksum, but every 64-byte RX transfer timed out (-110) under mainline spi-s3c64xx and Kepler stayed at opstate 0, with and without the auto-chip-select DTB of this branch. The cause was found later: spi-s3c64xx cut a 64-byte PIO transfer into 63 + 1 bytes, which 32-bit words cannot be split into (fixed in kernel PR #135, the base of this branch). --- drivers/soc/google/gnssif_spi/gnss_spi.c | 43 +++++++++++++++++------- drivers/soc/google/gnssif_spi/gnss_spi.h | 4 +-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 0ab3e229b5..12786623d2 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -15,16 +17,37 @@ #include "gnss_spi.h" +/* + * omamobile test: 32-bit words, as stock, with each word byte-swapped in + * software (stock: the vendor driver's swap-mode), so the bytes go on the + * wire in memory order. CHPP pads its frames to a multiple of 4. + */ +static void gnss_spi_swab(void *buf, unsigned int size) +{ + u32 *w = buf; + unsigned int i; + + for (i = 0; i < size / 4; i++) + w[i] = swab32(w[i]); +} + int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { + char *tmp; int ret = 0; struct spi_message msg; struct spi_transfer tx; + if (size % 4) + return -EINVAL; + tmp = kmemdup(buff, size, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + gnss_spi_swab(tmp, size); memset(&tx, 0, sizeof(struct spi_transfer)); spi_message_init(&msg); tx.len = size; - tx.tx_buf = buff; + tx.tx_buf = tmp; tx.bits_per_word = SPI_BITS_PER_WORD; if (rx_buff) tx.rx_buf = rx_buff; @@ -33,6 +56,10 @@ int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) if (ret < 0) gif_err("spi_sync() error:%d\n", ret); + kfree(tmp); + if (rx_buff) + gnss_spi_swab(rx_buff, size); + return ret; } EXPORT_SYMBOL(gnss_spi_send); @@ -53,27 +80,17 @@ int gnss_spi_recv(char *buff, unsigned int size) if (ret < 0) gif_err("spi_sync() error:%d\n", ret); + gnss_spi_swab(buff, size); + return ret; } EXPORT_SYMBOL(gnss_spi_recv); -static unsigned int spi_mode; -static unsigned int speed_hz; -module_param(speed_hz, uint, 0444); -module_param(spi_mode, uint, 0444); -MODULE_PARM_DESC(spi_mode, "SPI mode for Kepler (test): 0-3"); - static int gnss_spi_probe(struct spi_device *spi) { int ret = 0; - spi->mode = (spi->mode & ~SPI_MODE_X_MASK) | (spi_mode & SPI_MODE_X_MASK); - if (speed_hz) - spi->max_speed_hz = speed_hz; - gif_info("spi speed %u\n", spi->max_speed_hz); - gif_info("spi mode %u\n", spi->mode & SPI_MODE_X_MASK); - gif_info("+++\n"); mutex_init(&gnss_if.lock); diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 0a8d0a263e..26c1f21d59 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 32 +#define DEFAULT_SPI_RX_SIZE 64 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* @@ -19,7 +19,7 @@ * memory order; mainline spi-s3c64xx has no swap mode, and 8-bit words give * that order. */ -#define SPI_BITS_PER_WORD 8 +#define SPI_BITS_PER_WORD 32 struct gnss_spi { struct spi_device *spi; From 2b1763f3e651f06f4557d0a70f012dc8d7557a39 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 05/36] Bring-up, not for merge: gnssif_spi: cut transfers into 60-byte pieces of one message Bring-up, not for merge. Back to 8-bit words; gnss_spi_xfer() splits every transfer into 60-byte spi_transfers of one spi_message (chip select held between them), so every pause falls on a 32-bit boundary and spi-s3c64xx, which cut PIO transfers of 64 bytes or more into 63-byte pieces, never cuts. MODEM-PLAN G3, "What the link does (10-29, night)": with the cut gone the link garbled just the same (369 bad checksums, Kepler tracking, then its watchdog), so the split alone was not the cause. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 61 +++++++++++++++--------- drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 12786623d2..cf64831989 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -18,36 +17,53 @@ /* - * omamobile test: 32-bit words, as stock, with each word byte-swapped in - * software (stock: the vendor driver's swap-mode), so the bytes go on the - * wire in memory order. CHPP pads its frames to a multiple of 4. + * omamobile test: mainline spi-s3c64xx cuts PIO transfers of 64 bytes or + * more into 63-byte pieces, mid 32-bit word. Cut them here instead, into + * 60-byte transfers of one message (chip select held), so every pause falls + * on a 32-bit boundary and the controller never cuts again. */ -static void gnss_spi_swab(void *buf, unsigned int size) +#define GNSS_SPI_PIECE 60 + +static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) { - u32 *w = buf; - unsigned int i; + unsigned int n = DIV_ROUND_UP(size, GNSS_SPI_PIECE), i, off; + struct spi_transfer *t; + struct spi_message msg; + int ret; - for (i = 0; i < size / 4; i++) - w[i] = swab32(w[i]); + t = kcalloc(n, sizeof(*t), GFP_KERNEL); + if (!t) + return -ENOMEM; + spi_message_init(&msg); + for (i = 0, off = 0; i < n; i++, off += GNSS_SPI_PIECE) { + t[i].len = min(GNSS_SPI_PIECE, size - off); + t[i].tx_buf = tx ? tx + off : NULL; + t[i].rx_buf = rx ? rx + off : NULL; + t[i].bits_per_word = SPI_BITS_PER_WORD; + spi_message_add_tail(&t[i], &msg); + } + ret = spi_sync(gnss_if.spi, &msg); + if (ret < 0) + gif_err("spi_sync() error:%d\n", ret); + kfree(t); + return ret; } int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { - char *tmp; + return gnss_spi_xfer(buff, rx_buff, size); +} + +static int __maybe_unused gnss_spi_send_old(char *buff, unsigned int size, char *rx_buff) +{ int ret = 0; struct spi_message msg; struct spi_transfer tx; - if (size % 4) - return -EINVAL; - tmp = kmemdup(buff, size, GFP_KERNEL); - if (!tmp) - return -ENOMEM; - gnss_spi_swab(tmp, size); memset(&tx, 0, sizeof(struct spi_transfer)); spi_message_init(&msg); tx.len = size; - tx.tx_buf = tmp; + tx.tx_buf = buff; tx.bits_per_word = SPI_BITS_PER_WORD; if (rx_buff) tx.rx_buf = rx_buff; @@ -56,15 +72,16 @@ int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) if (ret < 0) gif_err("spi_sync() error:%d\n", ret); - kfree(tmp); - if (rx_buff) - gnss_spi_swab(rx_buff, size); - return ret; } EXPORT_SYMBOL(gnss_spi_send); int gnss_spi_recv(char *buff, unsigned int size) +{ + return gnss_spi_xfer(NULL, buff, size); +} + +static int __maybe_unused gnss_spi_recv_old(char *buff, unsigned int size) { int ret = 0; struct spi_message msg; @@ -80,8 +97,6 @@ int gnss_spi_recv(char *buff, unsigned int size) if (ret < 0) gif_err("spi_sync() error:%d\n", ret); - gnss_spi_swab(buff, size); - return ret; } diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 26c1f21d59..84ebf7c6df 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -19,7 +19,7 @@ * memory order; mainline spi-s3c64xx has no swap mode, and 8-bit words give * that order. */ -#define SPI_BITS_PER_WORD 32 +#define SPI_BITS_PER_WORD 8 struct gnss_spi { struct spi_device *spi; From 3ac6a09923c514c4f645d630ed91c9f493fe49e7 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 06/36] Bring-up, not for merge: gnssif_spi: 32-bit words in 32-byte pieces, 32-byte reads Bring-up, not for merge. 32-bit swapped words again, every transfer cut into 32-byte spi_transfers of one message (each fits the polling path, as stock's 64-byte reads do in Google's driver), and DEFAULT_SPI_RX_SIZE 32. MODEM-PLAN G3, fifteenth to twenty-third tries: the "w32rx32" row (7 bad checksums, no watchdog, the link stops after RESET-ACK) and, with 64-byte reads, the "w32p32" row (19). The raw bytes later showed why the counts are low: with 32-bit words the CHPP frames arrive at any bit offset, so few frames are recognised at all. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 85 +++++++++++------------- drivers/soc/google/gnssif_spi/gnss_spi.h | 4 +- 2 files changed, 39 insertions(+), 50 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index cf64831989..b5c470b7f1 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -17,27 +18,53 @@ /* - * omamobile test: mainline spi-s3c64xx cuts PIO transfers of 64 bytes or - * more into 63-byte pieces, mid 32-bit word. Cut them here instead, into - * 60-byte transfers of one message (chip select held), so every pause falls - * on a 32-bit boundary and the controller never cuts again. + * omamobile test: 32-bit words, as stock, with each word byte-swapped in + * software (stock: the vendor driver's swap-mode), so the bytes go on the + * wire in memory order. CHPP pads its frames to a multiple of 4. */ -#define GNSS_SPI_PIECE 60 +static void gnss_spi_swab(void *buf, unsigned int size) +{ + u32 *w = buf; + unsigned int i; + + for (i = 0; i < size / 4; i++) + w[i] = swab32(w[i]); +} + +/* + * omamobile test: mainline spi-s3c64xx cuts a PIO transfer of 64 bytes or + * more into 63-byte pieces, which a 32-bit word can't be split into (the + * -110 timeouts of the plain 32-bit test). Send 32-byte transfers of one + * message instead (chip select held): each fits the polling path, as stock's + * 64-byte reads do in Google's driver. + */ +#define GNSS_SPI_PIECE 32 static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) { unsigned int n = DIV_ROUND_UP(size, GNSS_SPI_PIECE), i, off; struct spi_transfer *t; struct spi_message msg; + char *tmp = NULL; int ret; + if (size % 4) + return -EINVAL; + if (tx) { + tmp = kmemdup(tx, size, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + gnss_spi_swab(tmp, size); + } t = kcalloc(n, sizeof(*t), GFP_KERNEL); - if (!t) + if (!t) { + kfree(tmp); return -ENOMEM; + } spi_message_init(&msg); for (i = 0, off = 0; i < n; i++, off += GNSS_SPI_PIECE) { t[i].len = min(GNSS_SPI_PIECE, size - off); - t[i].tx_buf = tx ? tx + off : NULL; + t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; t[i].bits_per_word = SPI_BITS_PER_WORD; spi_message_add_tail(&t[i], &msg); @@ -45,7 +72,10 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) ret = spi_sync(gnss_if.spi, &msg); if (ret < 0) gif_err("spi_sync() error:%d\n", ret); + if (rx) + gnss_spi_swab(rx, size); kfree(t); + kfree(tmp); return ret; } @@ -53,53 +83,12 @@ int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { return gnss_spi_xfer(buff, rx_buff, size); } - -static int __maybe_unused gnss_spi_send_old(char *buff, unsigned int size, char *rx_buff) -{ - int ret = 0; - struct spi_message msg; - struct spi_transfer tx; - - memset(&tx, 0, sizeof(struct spi_transfer)); - spi_message_init(&msg); - tx.len = size; - tx.tx_buf = buff; - tx.bits_per_word = SPI_BITS_PER_WORD; - if (rx_buff) - tx.rx_buf = rx_buff; - spi_message_add_tail(&tx, &msg); - ret = spi_sync(gnss_if.spi, &msg); - if (ret < 0) - gif_err("spi_sync() error:%d\n", ret); - - return ret; -} EXPORT_SYMBOL(gnss_spi_send); int gnss_spi_recv(char *buff, unsigned int size) { return gnss_spi_xfer(NULL, buff, size); } - -static int __maybe_unused gnss_spi_recv_old(char *buff, unsigned int size) -{ - int ret = 0; - struct spi_message msg; - struct spi_transfer rx; - - memset(&rx, 0, sizeof(struct spi_transfer)); - rx.len = size; - rx.rx_buf = buff; - rx.bits_per_word = SPI_BITS_PER_WORD; - spi_message_init(&msg); - spi_message_add_tail(&rx, &msg); - ret = spi_sync(gnss_if.spi, &msg); - if (ret < 0) - gif_err("spi_sync() error:%d\n", ret); - - return ret; - -} EXPORT_SYMBOL(gnss_spi_recv); static int gnss_spi_probe(struct spi_device *spi) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 84ebf7c6df..ecdb505143 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 64 +#define DEFAULT_SPI_RX_SIZE 32 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* @@ -19,7 +19,7 @@ * memory order; mainline spi-s3c64xx has no swap mode, and 8-bit words give * that order. */ -#define SPI_BITS_PER_WORD 8 +#define SPI_BITS_PER_WORD 32 struct gnss_spi { struct spi_device *spi; From fefbbcd2639373bd501ce54763ff94d333395565 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:38 -0647 Subject: [PATCH 07/36] Bring-up, not for merge: gnssif_spi: fb_delay, cs_setup_us, osc and speed_hz parameters Bring-up, not for merge. 64-byte reads again, and four module parameters: fb_delay overrides the controller's feedback delay (s3c64xx_spi_csinfo fb_delay, FB_CLK_SEL) after spi_setup; cs_setup_us sets spi->cs_setup; speed_hz the rate asked for; and osc=1 writes bit 0 of CMU_HSI0's USI3 mux (0x11001020) at probe, behind the clock framework's back, moving the mux from its 399.36 MHz parent to OSCCLK; the divider (0x11001820) is read and logged after the first transfer. MODEM-PLAN G3, fifteenth to twenty-third tries: "fb3" (delay 3: 5 bad checksums), "cs200" (delay 3, 200 us setup: 0), "osc" (OSCCLK, about 1.5 MHz: 0) and "acs" (the auto-chip-select DTB: 0), all 32-bit, all stopping after RESET-ACK. The divider read showed the real clock: the mux sat on 399.36 MHz and the 4-bit divider stops at /16, so the SPI ran at 6.24 MHz, twice stock's, whatever the driver asked for. Writing CMU registers from a module is a bring-up shortcut, replaced by the clk-zumapro change of kernel PR #135. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 76 ++++++++++++++++++++++++ drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index b5c470b7f1..ea28757a46 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "include/gnss.h" #include "gnss_spi.h" @@ -40,6 +42,58 @@ static void gnss_spi_swab(void *buf, unsigned int size) */ #define GNSS_SPI_PIECE 32 +/* omamobile test: override the controller's feedback delay (FB_CLK_SEL) */ +static int fb_delay = -1; +module_param(fb_delay, int, 0444); + +/* + * omamobile test: CMU_HSI0 USI3. The clock driver keeps the mux read-only + * on its 399.36 MHz parent and the divider stops at /16, so the SPI runs at + * 24.96 MHz / 4 = 6.24 MHz whatever it asks for. osc=1 moves the mux to + * OSCCLK (24.576 MHz), so the divider the driver then picks gives a slower + * clock; speed_hz sets the rate the driver asks for. + */ +#define CMU_HSI0_USI3_MUX 0x11001020 +#define CMU_HSI0_USI3_DIV 0x11001820 +static int osc; +module_param(osc, int, 0444); +static int speed_hz; +module_param(speed_hz, int, 0444); + +static void gnss_spi_cmu(void) +{ + void __iomem *mux, *div; + + mux = ioremap(CMU_HSI0_USI3_MUX, 4); + div = ioremap(CMU_HSI0_USI3_DIV, 4); + if (!mux || !div) + goto out; + gif_info("usi3 mux 0x%08x div 0x%08x\n", readl(mux), readl(div)); + if (osc) { + writel(readl(mux) | 1, mux); + gif_info("usi3 mux now 0x%08x\n", readl(mux)); + } +out: + if (mux) + iounmap(mux); + if (div) + iounmap(div); +} + +static void __maybe_unused gnss_spi_cmu_div(void) +{ + void __iomem *div = ioremap(CMU_HSI0_USI3_DIV, 4); + + if (div) { + gif_info("usi3 div 0x%08x\n", readl(div)); + iounmap(div); + } +} + +/* omamobile test: microseconds from chip select to the first clock */ +static int cs_setup_us; +module_param(cs_setup_us, int, 0444); + static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) { unsigned int n = DIV_ROUND_UP(size, GNSS_SPI_PIECE), i, off; @@ -72,6 +126,14 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) ret = spi_sync(gnss_if.spi, &msg); if (ret < 0) gif_err("spi_sync() error:%d\n", ret); + { + static bool once; + + if (!once) { + once = true; + gnss_spi_cmu_div(); + } + } if (rx) gnss_spi_swab(rx, size); kfree(t); @@ -98,11 +160,25 @@ static int gnss_spi_probe(struct spi_device *spi) gif_info("+++\n"); mutex_init(&gnss_if.lock); + gnss_spi_cmu(); + if (speed_hz > 0) + spi->max_speed_hz = speed_hz; if (spi_setup(spi)) { gif_err("ERR! spi_setup fail\n"); ret = -EINVAL; goto err_setup; } + if (fb_delay >= 0 && spi->controller_data) { + struct s3c64xx_spi_csinfo *cs = spi->controller_data; + + gif_info("feedback delay %u -> %d\n", cs->fb_delay, fb_delay); + cs->fb_delay = fb_delay; + } + if (cs_setup_us > 0) { + spi->cs_setup.value = cs_setup_us; + spi->cs_setup.unit = SPI_DELAY_UNIT_USECS; + gif_info("cs_setup %d us\n", cs_setup_us); + } spi_set_drvdata(spi, &gnss_if); gnss_if.spi = spi; gif_info("---\n"); diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index ecdb505143..26c1f21d59 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 32 +#define DEFAULT_SPI_RX_SIZE 64 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* From 6b5d5e7b2d220dac3fe8b2d16a09bbab96d59fa5 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 08/36] Bring-up, not for merge: gnssif_spi: 8-bit words with the same parameters Bring-up, not for merge. SPI_BITS_PER_WORD back to 8 with the swap and the multiple-of-4 check skipped for 8-bit words, and one transfer per message (piece size 64 KiB). MODEM-PLAN G3, fifteenth to twenty-third tries, "osc8": 8-bit, OSCCLK (about 1.5 MHz), feedback delay 0: 1 bad checksum, the link still stopping after RESET-ACK. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 7 +++++-- drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index ea28757a46..a7498c219d 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -29,6 +29,9 @@ static void gnss_spi_swab(void *buf, unsigned int size) u32 *w = buf; unsigned int i; + if (SPI_BITS_PER_WORD != 32) + return; + for (i = 0; i < size / 4; i++) w[i] = swab32(w[i]); } @@ -40,7 +43,7 @@ static void gnss_spi_swab(void *buf, unsigned int size) * message instead (chip select held): each fits the polling path, as stock's * 64-byte reads do in Google's driver. */ -#define GNSS_SPI_PIECE 32 +#define GNSS_SPI_PIECE SZ_64K /* omamobile test: override the controller's feedback delay (FB_CLK_SEL) */ static int fb_delay = -1; @@ -102,7 +105,7 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) char *tmp = NULL; int ret; - if (size % 4) + if (SPI_BITS_PER_WORD == 32 && size % 4) return -EINVAL; if (tx) { tmp = kmemdup(tx, size, GFP_KERNEL); diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 26c1f21d59..84ebf7c6df 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -19,7 +19,7 @@ * memory order; mainline spi-s3c64xx has no swap mode, and 8-bit words give * that order. */ -#define SPI_BITS_PER_WORD 32 +#define SPI_BITS_PER_WORD 8 struct gnss_spi { struct spi_device *spi; From 975307f40a8cae0e9c783ef93272638f024cb57c Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 09/36] Bring-up, not for merge: gnssif_spi: hs=1 forces HIGH_SPEED_EN, one spi_sync per 32-byte piece Bring-up, not for merge. hs=1 keeps the controller runtime-resumed, maps SPI 21's registers (0x111e0000) and sets CH_CFG bit 6 (HIGH_SPEED_EN, which spi-s3c64xx sets only at 30 MHz and up and clears in every FIFO flush) before every transfer; each 32-byte piece is its own spi_sync so the bit is set again after the flush. MODEM-PLAN G3, fifteenth to twenty-third tries, "hs": 17 bad checksums, stopping after RESET-ACK. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index a7498c219d..4789522ec5 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "include/gnss.h" #include "gnss_spi.h" @@ -43,7 +44,17 @@ static void gnss_spi_swab(void *buf, unsigned int size) * message instead (chip select held): each fits the polling path, as stock's * 64-byte reads do in Google's driver. */ -#define GNSS_SPI_PIECE SZ_64K +#define GNSS_SPI_PIECE 32 + +/* + * omamobile test: hs=1 sets CH_CFG HIGH_SPEED_EN before every transfer + * (the driver sets it only at 30 MHz and up, and clears it in every FIFO + * flush), so each 32-byte piece is its own spi_sync. + */ +#define GNSS_SPI_REGS 0x111e0000 +static int hs; +module_param(hs, int, 0444); +static void __iomem *gnss_spi_regs; /* omamobile test: override the controller's feedback delay (FB_CLK_SEL) */ static int fb_delay = -1; @@ -118,15 +129,18 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) kfree(tmp); return -ENOMEM; } - spi_message_init(&msg); - for (i = 0, off = 0; i < n; i++, off += GNSS_SPI_PIECE) { + ret = 0; + for (i = 0, off = 0; i < n && ret >= 0; i++, off += GNSS_SPI_PIECE) { t[i].len = min(GNSS_SPI_PIECE, size - off); t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; t[i].bits_per_word = SPI_BITS_PER_WORD; + spi_message_init(&msg); spi_message_add_tail(&t[i], &msg); + if (hs && gnss_spi_regs) + writel(readl(gnss_spi_regs) | BIT(6), gnss_spi_regs); + ret = spi_sync(gnss_if.spi, &msg); } - ret = spi_sync(gnss_if.spi, &msg); if (ret < 0) gif_err("spi_sync() error:%d\n", ret); { @@ -164,6 +178,19 @@ static int gnss_spi_probe(struct spi_device *spi) mutex_init(&gnss_if.lock); gnss_spi_cmu(); + if (hs) { + /* keep the controller clocked, so its registers can be touched */ + ret = pm_runtime_resume_and_get(spi->controller->dev.parent); + if (ret < 0) { + gif_err("hs: controller resume failed %d\n", ret); + hs = 0; + } else { + gnss_spi_regs = ioremap(GNSS_SPI_REGS, 0x40); + gif_info("hs: CH_CFG 0x%08x\n", + gnss_spi_regs ? readl(gnss_spi_regs) : 0); + } + ret = 0; + } if (speed_hz > 0) spi->max_speed_hz = speed_hz; if (spi_setup(spi)) { From 07ccb2a0bf71b5f3b2e97d0eb2cfbe33296c620f Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 10/36] Bring-up, not for merge: gnssif_spi: hs=1 with 60-byte reads in one transfer Bring-up, not for merge. The same HIGH_SPEED_EN parameter with one transfer per message and DEFAULT_SPI_RX_SIZE 60, so spi-s3c64xx never splits a read. MODEM-PLAN G3, fifteenth to twenty-third tries, "hs60": 408 bad checksums, Kepler tracking satellites, then its watchdog (38 hard faults). The reset at 348 s that followed came from the modem's PCIe link ("PHY isolated"), not from the SPI path. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 2 +- drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 4789522ec5..a7b2101a47 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -44,7 +44,7 @@ static void gnss_spi_swab(void *buf, unsigned int size) * message instead (chip select held): each fits the polling path, as stock's * 64-byte reads do in Google's driver. */ -#define GNSS_SPI_PIECE 32 +#define GNSS_SPI_PIECE SZ_64K /* * omamobile test: hs=1 sets CH_CFG HIGH_SPEED_EN before every transfer diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index 84ebf7c6df..acdc41cdb7 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 64 +#define DEFAULT_SPI_RX_SIZE 60 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* From 2864857ca85d9d1bc3f01d3a3dbab3c7bc1a1cfa Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 11/36] Bring-up, not for merge: gnssif_spi: div holds the USI3 divider (stock's 12 MHz, osc=1 div=1) Bring-up, not for merge. The hs parameter goes; div >= 0 maps CMU_HSI0's USI3 divider and holds it at that value, written at probe and again around every transfer (the clock driver sets it back to /16 whenever spi-s3c64xx asks for a rate), waiting for the divider's busy bit. With osc=1 div=1 this is Google's zuma CMU table for USI3's 12 MHz (cmucal-vclk.c, div_clk_hsi0_usix_12mhz_lut_params: OSCCLK / 2, 12.288 MHz, a 3.07 MHz SPI clock). 64-byte reads again. MODEM-PLAN G3, "Stock's clock, tried (twenty-fourth try)": 8-bit, delay 0, 1 bad checksum, and Kepler's frames arriving shifted by the same 4, then 5, then 6 bits across many reads, so its bit counter runs on across chip-select cycles and gains or loses clocks on OSCCLK. This is the "module that set USI3's mux and divider behind the clock framework"; kernel PR #135 lets the framework do it instead. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 58 ++++++++++++------------ drivers/soc/google/gnssif_spi/gnss_spi.h | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index a7b2101a47..3f57d9404f 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "include/gnss.h" #include "gnss_spi.h" @@ -46,16 +46,6 @@ static void gnss_spi_swab(void *buf, unsigned int size) */ #define GNSS_SPI_PIECE SZ_64K -/* - * omamobile test: hs=1 sets CH_CFG HIGH_SPEED_EN before every transfer - * (the driver sets it only at 30 MHz and up, and clears it in every FIFO - * flush), so each 32-byte piece is its own spi_sync. - */ -#define GNSS_SPI_REGS 0x111e0000 -static int hs; -module_param(hs, int, 0444); -static void __iomem *gnss_spi_regs; - /* omamobile test: override the controller's feedback delay (FB_CLK_SEL) */ static int fb_delay = -1; module_param(fb_delay, int, 0444); @@ -73,6 +63,26 @@ static int osc; module_param(osc, int, 0444); static int speed_hz; module_param(speed_hz, int, 0444); +/* div >= 0: hold the USI3 divider at this value (stock 12 MHz: osc=1, div=1) */ +static int div = -1; +module_param(div, int, 0444); +static void __iomem *gnss_spi_div; + +static void gnss_spi_hold_div(void) +{ + u32 v; + int i; + + if (div < 0 || !gnss_spi_div) + return; + v = readl(gnss_spi_div); + if ((v & 0xf) == div) + return; + writel((v & ~0xf) | div, gnss_spi_div); + for (i = 0; i < 1000 && (readl(gnss_spi_div) & BIT(16)); i++) + udelay(1); + gif_info("usi3 div 0x%08x -> 0x%08x\n", v, readl(gnss_spi_div)); +} static void gnss_spi_cmu(void) { @@ -129,20 +139,19 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) kfree(tmp); return -ENOMEM; } - ret = 0; - for (i = 0, off = 0; i < n && ret >= 0; i++, off += GNSS_SPI_PIECE) { + spi_message_init(&msg); + for (i = 0, off = 0; i < n; i++, off += GNSS_SPI_PIECE) { t[i].len = min(GNSS_SPI_PIECE, size - off); t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; t[i].bits_per_word = SPI_BITS_PER_WORD; - spi_message_init(&msg); spi_message_add_tail(&t[i], &msg); - if (hs && gnss_spi_regs) - writel(readl(gnss_spi_regs) | BIT(6), gnss_spi_regs); - ret = spi_sync(gnss_if.spi, &msg); } + gnss_spi_hold_div(); + ret = spi_sync(gnss_if.spi, &msg); if (ret < 0) gif_err("spi_sync() error:%d\n", ret); + gnss_spi_hold_div(); { static bool once; @@ -178,18 +187,9 @@ static int gnss_spi_probe(struct spi_device *spi) mutex_init(&gnss_if.lock); gnss_spi_cmu(); - if (hs) { - /* keep the controller clocked, so its registers can be touched */ - ret = pm_runtime_resume_and_get(spi->controller->dev.parent); - if (ret < 0) { - gif_err("hs: controller resume failed %d\n", ret); - hs = 0; - } else { - gnss_spi_regs = ioremap(GNSS_SPI_REGS, 0x40); - gif_info("hs: CH_CFG 0x%08x\n", - gnss_spi_regs ? readl(gnss_spi_regs) : 0); - } - ret = 0; + if (div >= 0) { + gnss_spi_div = ioremap(CMU_HSI0_USI3_DIV, 4); + gnss_spi_hold_div(); } if (speed_hz > 0) spi->max_speed_hz = speed_hz; diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.h b/drivers/soc/google/gnssif_spi/gnss_spi.h index acdc41cdb7..84ebf7c6df 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.h +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -10,7 +10,7 @@ #include #include -#define DEFAULT_SPI_RX_SIZE 60 +#define DEFAULT_SPI_RX_SIZE 64 #define MAX_SPI_RX_SIZE SZ_2K #define DEFAULT_SPI_TX_SIZE SZ_4K /* From 06ad2f8cbb883bde4b2c562ac2860b2cde402caf Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 12/36] Bring-up, not for merge: gnssif_spi: rx_cpha=1 reads in SPI mode 1, writes in mode 0 Bring-up, not for merge. rx_cpha=1 switches spi->mode per transfer under the driver's mutex: read-only transfers get SPI_CPHA (mode 1), transfers with a tx buffer run in mode 0. spi-s3c64xx takes the mode from spi->mode each time it reconfigures, and it reconfigures on every transfer here because its cur_speed (the 6.24 MHz it gets) never equals the rate asked. MODEM-PLAN G3, twenty-fifth to twenty-seventh tries: every frame at bit offset 0 for the first time on the as-ported clock, short frames pass, the engine reports satellites, the watchdog fires later (260 bad checksums; 101 with cs_setup_us=50 in the twenty-seventh try, through 14 Kepler watchdog resets without a reset of the palmtop); long frames (279 bytes) lose one or two bytes at each 64-byte read boundary. The twenty-sixth try ran this module with 60-byte reads (DEFAULT_SPI_RX_SIZE 60 as in the hs60 commit), with no change. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 3f57d9404f..bfd77f9b1c 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -65,6 +65,9 @@ static int speed_hz; module_param(speed_hz, int, 0444); /* div >= 0: hold the USI3 divider at this value (stock 12 MHz: osc=1, div=1) */ static int div = -1; +/* rx_cpha=1: read-only transfers in SPI mode 1, writes stay in mode 0 */ +static int rx_cpha; +module_param(rx_cpha, int, 0444); module_param(div, int, 0444); static void __iomem *gnss_spi_div; @@ -148,7 +151,22 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) spi_message_add_tail(&t[i], &msg); } gnss_spi_hold_div(); + if (rx_cpha) + mutex_lock(&gnss_if.lock); + if (rx_cpha) { + /* + * spi-s3c64xx reconfigures on every transfer here (its + * cur_speed is the 6.24 MHz it gets, never the rate asked), + * and takes cur_mode from spi->mode when it does. + */ + if (tx) + gnss_if.spi->mode &= ~SPI_CPHA; + else + gnss_if.spi->mode |= SPI_CPHA; + } ret = spi_sync(gnss_if.spi, &msg); + if (rx_cpha) + mutex_unlock(&gnss_if.lock); if (ret < 0) gif_err("spi_sync() error:%d\n", ret); gnss_spi_hold_div(); From 51cc1165d787b989ae72f739ed537972d69b8c62 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 13/36] Bring-up, not for merge: gnssif_spi: hold=1 keeps chip select across a Kepler message Bring-up, not for merge. hold=1 sets cs_change on the last transfer of every read, so chip select stays asserted between rx_work's consecutive reads of one Kepler message; gnss_spi_release() (an empty transfer the core ends with chip select off) releases it when gnss2ap drops at the end of rx_work's loop and before every write. MODEM-PLAN G3, twenty-eighth try: with mode 1 reads it made things worse (292 bad checksums, 279-byte frames ending in zeros, footer 0): Kepler wants chip select released between its 64-byte reads, as stock does. --- .../soc/google/gnssif_spi/gnss_link_device.c | 2 ++ drivers/soc/google/gnssif_spi/gnss_spi.c | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_link_device.c b/drivers/soc/google/gnssif_spi/gnss_link_device.c index fca0798a66..15dc86e1c7 100644 --- a/drivers/soc/google/gnssif_spi/gnss_link_device.c +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -14,6 +14,7 @@ #include "gnss_prj.h" #include "gnss_utils.h" #include "gnss_spi.h" +void gnss_spi_release(void); /* #define GNSS_PKT_DEBUG 1 */ @@ -128,6 +129,7 @@ static void rx_work(struct work_struct *ws) } } } while (gc->ops.gnss_spi_status(gc)); + gnss_spi_release(); if (skb) { pr_buffer("RX", skb->data, skb->len, skb->len); diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index bfd77f9b1c..d99cdc1a47 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -68,6 +68,10 @@ static int div = -1; /* rx_cpha=1: read-only transfers in SPI mode 1, writes stay in mode 0 */ static int rx_cpha; module_param(rx_cpha, int, 0444); +/* hold=1: keep chip select asserted between the reads of one Kepler message */ +static int hold; +module_param(hold, int, 0444); +static bool held; module_param(div, int, 0444); static void __iomem *gnss_spi_div; @@ -148,6 +152,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; t[i].bits_per_word = SPI_BITS_PER_WORD; + if (hold && !tx && i == n - 1) + t[i].cs_change = 1; /* last transfer: keep CS after it */ spi_message_add_tail(&t[i], &msg); } gnss_spi_hold_div(); @@ -165,6 +171,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) gnss_if.spi->mode |= SPI_CPHA; } ret = spi_sync(gnss_if.spi, &msg); + if (hold) + held = !tx; if (rx_cpha) mutex_unlock(&gnss_if.lock); if (ret < 0) @@ -185,8 +193,24 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) return ret; } +/* end a held chip select: an empty transfer, which the core ends with CS off */ +void gnss_spi_release(void) +{ + struct spi_transfer t = { .len = 0 }; + struct spi_message msg; + + if (!hold || !held) + return; + spi_message_init(&msg); + spi_message_add_tail(&t, &msg); + spi_sync(gnss_if.spi, &msg); + held = false; +} +EXPORT_SYMBOL(gnss_spi_release); + int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { + gnss_spi_release(); return gnss_spi_xfer(buff, rx_buff, size); } EXPORT_SYMBOL(gnss_spi_send); From d289a2fb84de85548e3443fd040b1093741409d0 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 14/36] Bring-up, not for merge: gnssif_spi: realign=1 shifts every read left one bit Bring-up, not for merge. The hold parameter and the link device's release call go. realign=1 shifts every received buffer left by one bit before the swap, because at feedback delay 3 (mode 0, 8 bits, the as-ported clock) Kepler's frames arrived intact but one bit late: offline, shifting the saved reads left one bit turned 11 valid CHPP frames into 123 (CRC32 over the 8-byte header and payload), where at delay 2 the same shift recovered nothing. MODEM-PLAN G3, twenty-ninth and thirtieth tries: Kepler is on time just after it starts and one bit late later, so the fixed shift lost its first RESET-ACKs for 2 s and set off a reset storm (125 RESETs from Kepler, 144 RESET-ACKs from gnssd). --- .../soc/google/gnssif_spi/gnss_link_device.c | 2 - drivers/soc/google/gnssif_spi/gnss_spi.c | 40 ++++++++----------- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_link_device.c b/drivers/soc/google/gnssif_spi/gnss_link_device.c index 15dc86e1c7..fca0798a66 100644 --- a/drivers/soc/google/gnssif_spi/gnss_link_device.c +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -14,7 +14,6 @@ #include "gnss_prj.h" #include "gnss_utils.h" #include "gnss_spi.h" -void gnss_spi_release(void); /* #define GNSS_PKT_DEBUG 1 */ @@ -129,7 +128,6 @@ static void rx_work(struct work_struct *ws) } } } while (gc->ops.gnss_spi_status(gc)); - gnss_spi_release(); if (skb) { pr_buffer("RX", skb->data, skb->len, skb->len); diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index d99cdc1a47..6dfd538ee2 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -68,10 +68,20 @@ static int div = -1; /* rx_cpha=1: read-only transfers in SPI mode 1, writes stay in mode 0 */ static int rx_cpha; module_param(rx_cpha, int, 0444); -/* hold=1: keep chip select asserted between the reads of one Kepler message */ -static int hold; -module_param(hold, int, 0444); -static bool held; +/* + * realign=1: Kepler's data comes in exactly one bit late with feedback + * delay 3 (MODEM-PLAN G3), so shift every received buffer left one bit. + */ +static int realign; +module_param(realign, int, 0444); + +static void gnss_spi_shl1(u8 *b, unsigned int n) +{ + unsigned int i; + + for (i = 0; i < n; i++) + b[i] = (b[i] << 1) | (i + 1 < n ? b[i + 1] >> 7 : 0); +} module_param(div, int, 0444); static void __iomem *gnss_spi_div; @@ -152,8 +162,6 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; t[i].bits_per_word = SPI_BITS_PER_WORD; - if (hold && !tx && i == n - 1) - t[i].cs_change = 1; /* last transfer: keep CS after it */ spi_message_add_tail(&t[i], &msg); } gnss_spi_hold_div(); @@ -171,8 +179,6 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) gnss_if.spi->mode |= SPI_CPHA; } ret = spi_sync(gnss_if.spi, &msg); - if (hold) - held = !tx; if (rx_cpha) mutex_unlock(&gnss_if.lock); if (ret < 0) @@ -186,6 +192,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) gnss_spi_cmu_div(); } } + if (rx && realign && ret >= 0) + gnss_spi_shl1(rx, size); if (rx) gnss_spi_swab(rx, size); kfree(t); @@ -193,24 +201,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) return ret; } -/* end a held chip select: an empty transfer, which the core ends with CS off */ -void gnss_spi_release(void) -{ - struct spi_transfer t = { .len = 0 }; - struct spi_message msg; - - if (!hold || !held) - return; - spi_message_init(&msg); - spi_message_add_tail(&t, &msg); - spi_sync(gnss_if.spi, &msg); - held = false; -} -EXPORT_SYMBOL(gnss_spi_release); - int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { - gnss_spi_release(); return gnss_spi_xfer(buff, rx_buff, size); } EXPORT_SYMBOL(gnss_spi_send); From fc46976691f3da850c70d8cf37d29222bcb4ed4d Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 15/36] Bring-up, not for merge: gnssif_spi: txshift=1 sends every write one bit later Bring-up, not for merge. txshift=1 shifts each write right by one bit into a buffer one byte longer (the last bit lands in the extra byte) and drops the extra received byte, in case Kepler sampled our writes a slot late as it sent its own data a slot late. MODEM-PLAN G3, thirty-first try: it killed the link outright (0 RESET-ACKs, nothing received), so our writes were right as they were. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 6dfd538ee2..8bccb51a8a 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -75,6 +75,45 @@ module_param(rx_cpha, int, 0444); static int realign; module_param(realign, int, 0444); +/* txshift=1: send every write one bit later, with one byte added for the last bit */ +static int txshift; +module_param(txshift, int, 0444); + +static void gnss_spi_shl1(u8 *b, unsigned int n); + +static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size); + +static int gnss_spi_xfer_txshift(const char *tx, char *rx, unsigned int size) +{ + u8 *t, *r = NULL; + unsigned int i; + int ret; + + t = kzalloc(size + 1, GFP_KERNEL); + if (!t) + return -ENOMEM; + if (rx) { + r = kzalloc(size + 1, GFP_KERNEL); + if (!r) { + kfree(t); + return -ENOMEM; + } + } + /* t = tx >> 1 bit: Kepler samples each bit one slot late */ + for (i = 0; i <= size; i++) + t[i] = (i < size ? (u8)tx[i] >> 1 : 0) | (i ? ((u8)tx[i - 1] & 1) << 7 : 0); + txshift = -txshift; /* call the plain path once */ + ret = gnss_spi_xfer((char *)t, (char *)r, size + 1); + txshift = -txshift; + if (r) { + /* gnss_spi_xfer already shifted the read left one bit */ + memcpy(rx, r, size); + kfree(r); + } + kfree(t); + return ret; +} + static void gnss_spi_shl1(u8 *b, unsigned int n) { unsigned int i; @@ -203,6 +242,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { + if (txshift > 0) + return gnss_spi_xfer_txshift(buff, rx_buff, size); return gnss_spi_xfer(buff, rx_buff, size); } EXPORT_SYMBOL(gnss_spi_send); From 8fc7d7929c9d9fa395939593fe1ba1a023f1dd68 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:39 -0647 Subject: [PATCH 16/36] Bring-up, not for merge: gnssif_spi: realign=2 chooses the shift per read from the CHPP preamble Bring-up, not for merge. txshift goes. realign=2 looks for the CHPP preamble (68 43) in each read: found at bit 0, the read is kept; at bit 1, the read is shifted left one bit; a read without a preamble keeps the last choice, and each change is logged. MODEM-PLAN G3, thirty-second try: clean short frames and the engine reporting satellites, but the 279- and 361-byte frames still failed (290 bad checksums, 34 hard faults over the session); offline, setting the one dropped bit at each 64-byte boundary every possible way (tools/tegu-gnss/offline/brute.py) repaired none of them, so more than a bit goes missing at each chip-select release. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 61 ++++++++++-------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 8bccb51a8a..6124cbc706 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -75,43 +75,26 @@ module_param(rx_cpha, int, 0444); static int realign; module_param(realign, int, 0444); -/* txshift=1: send every write one bit later, with one byte added for the last bit */ -static int txshift; -module_param(txshift, int, 0444); - -static void gnss_spi_shl1(u8 *b, unsigned int n); - -static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size); +/* + * realign=2: Kepler's data is on time at first and one bit late later, so + * choose per read: a CHPP preamble (68 43) at bit 0 keeps the read as it + * is, one at bit 1 shifts it; a read without one keeps the last choice. + */ +static bool gnss_spi_late; -static int gnss_spi_xfer_txshift(const char *tx, char *rx, unsigned int size) +static int gnss_spi_preamble_at(const u8 *b, unsigned int n) { - u8 *t, *r = NULL; unsigned int i; - int ret; - t = kzalloc(size + 1, GFP_KERNEL); - if (!t) - return -ENOMEM; - if (rx) { - r = kzalloc(size + 1, GFP_KERNEL); - if (!r) { - kfree(t); - return -ENOMEM; - } - } - /* t = tx >> 1 bit: Kepler samples each bit one slot late */ - for (i = 0; i <= size; i++) - t[i] = (i < size ? (u8)tx[i] >> 1 : 0) | (i ? ((u8)tx[i - 1] & 1) << 7 : 0); - txshift = -txshift; /* call the plain path once */ - ret = gnss_spi_xfer((char *)t, (char *)r, size + 1); - txshift = -txshift; - if (r) { - /* gnss_spi_xfer already shifted the read left one bit */ - memcpy(rx, r, size); - kfree(r); + for (i = 0; i + 2 < n; i++) { + u32 w = b[i] << 16 | b[i + 1] << 8 | b[i + 2]; + + if ((w >> 8) == 0x6843) + return 0; + if (((w >> 7) & 0xffff) == 0x6843) + return 1; } - kfree(t); - return ret; + return -1; } static void gnss_spi_shl1(u8 *b, unsigned int n) @@ -231,8 +214,18 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) gnss_spi_cmu_div(); } } - if (rx && realign && ret >= 0) + if (rx && realign == 1 && ret >= 0) gnss_spi_shl1(rx, size); + if (rx && realign == 2 && ret >= 0) { + int at = gnss_spi_preamble_at(rx, size); + + if (at >= 0 && gnss_spi_late != at) { + gnss_spi_late = at; + gif_info("realign: Kepler data %s\n", at ? "one bit late" : "on time"); + } + if (gnss_spi_late) + gnss_spi_shl1(rx, size); + } if (rx) gnss_spi_swab(rx, size); kfree(t); @@ -242,8 +235,6 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { - if (txshift > 0) - return gnss_spi_xfer_txshift(buff, rx_buff, size); return gnss_spi_xfer(buff, rx_buff, size); } EXPORT_SYMBOL(gnss_spi_send); From caa9ff599bea0abaeabeabe32f2cc47a7c407452 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 17/36] Bring-up, not for merge: gnssif_spi: realign=3 tracks Kepler's bit offset 0-7, txk delays writes by it Bring-up, not for merge. realign=3 finds the preamble at any of the 8 bit offsets, shifts the read by the offset found and keeps it for reads without one, logging each change; txk=1 then sends writes that many bits later, so they land on Kepler's byte boundaries. MODEM-PLAN G3, thirty-third and thirty-fourth tries, at stock's clock through the osc/div parameters: at OSCCLK / 2 (osc=1 div=1, 3.07 MHz) the offset walked by one or two bits about every 100 ms (0, 2, 3, 5, 6, 7, 0, 1, 3 in the first second), and with the writes delayed to match, 20 frames came through clean but Kepler only answered RESETs; at OSCCLK / 1 (div=0, 6.14 MHz) the offset changed twice in 100 s. So the drift grows as the clock slows. The 05:02 reset in that session was the CP link (CLUSTER0_NONCPU_WDTRESET), not the SPI. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 6124cbc706..7ed14ed2e0 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -81,6 +81,31 @@ module_param(realign, int, 0444); * is, one at bit 1 shifts it; a read without one keeps the last choice. */ static bool gnss_spi_late; +static int gnss_spi_k; /* realign=3: Kepler's bit offset, 0-7 */ + +static int gnss_spi_preamble_k(const u8 *b, unsigned int n) +{ + unsigned int i, k; + + for (i = 0; i + 2 < n; i++) { + u32 w = b[i] << 16 | b[i + 1] << 8 | b[i + 2]; + + for (k = 0; k < 8; k++) + if (((w >> (8 - k)) & 0xffff) == 0x6843) + return k; + } + return -1; +} + +static void gnss_spi_shlk(u8 *b, unsigned int n, int k) +{ + unsigned int i; + + if (!k) + return; + for (i = 0; i < n; i++) + b[i] = (b[i] << k) | (i + 1 < n ? b[i + 1] >> (8 - k) : 0); +} static int gnss_spi_preamble_at(const u8 *b, unsigned int n) { @@ -216,6 +241,15 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) } if (rx && realign == 1 && ret >= 0) gnss_spi_shl1(rx, size); + if (rx && realign == 3 && ret >= 0) { + int at = gnss_spi_preamble_k(rx, size); + + if (at >= 0 && at != gnss_spi_k) { + gif_info("realign: Kepler bit offset %d -> %d\n", gnss_spi_k, at); + gnss_spi_k = at; + } + gnss_spi_shlk(rx, size, gnss_spi_k); + } if (rx && realign == 2 && ret >= 0) { int at = gnss_spi_preamble_at(rx, size); @@ -233,8 +267,39 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) return ret; } +static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size); + +/* realign=3 and txk=1: send writes k bits later, so they land on Kepler's byte boundaries */ +static int txk; +module_param(txk, int, 0444); + +static int gnss_spi_send_k(const char *tx, char *rx, unsigned int size, int k) +{ + u8 *t, *r = NULL; + unsigned int i; + int ret; + + t = kzalloc(size + 1, GFP_KERNEL); + if (!t) + return -ENOMEM; + if (rx) + r = kzalloc(size + 1, GFP_KERNEL); + for (i = 0; i <= size; i++) + t[i] = (i < size ? (u8)tx[i] >> k : 0) | + (i ? (u8)((u8)tx[i - 1] << (8 - k)) : 0); + ret = gnss_spi_xfer((char *)t, r ? (char *)r : NULL, size + 1); + if (r) { + memcpy(rx, r, size); + kfree(r); + } + kfree(t); + return ret; +} + int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) { + if (realign == 3 && txk && gnss_spi_k) + return gnss_spi_send_k(buff, rx_buff, size, gnss_spi_k); return gnss_spi_xfer(buff, rx_buff, size); } EXPORT_SYMBOL(gnss_spi_send); From 43267506ca0d591776500ff33ebcd4de3565ffc0 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 18/36] Bring-up, not for merge: gnssif_spi: piece sets the transfer size within a message Bring-up, not for merge. The fixed 64 KiB piece becomes the piece parameter: the size of each spi_transfer within one message (chip select held between them), 64 KiB meaning one transfer. MODEM-PLAN G3, the morning of 10-29 ("the clock fixed, the cut fixed"): the 32 + 32 test (piece=32) showed every frame that crossed a piece boundary failing with chip select held, which pointed at spi-s3c64xx's cut rather than the chip-select release as what lost the bytes, and led to the "Do not cut a PIO transfer that fills the FIFO" commit of kernel PR #135 (the p32 run in logs/tegu-gnss-w32-20261029: 83 bad checksums, no watchdog). --- drivers/soc/google/gnssif_spi/gnss_spi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 7ed14ed2e0..0668a65482 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -44,7 +44,10 @@ static void gnss_spi_swab(void *buf, unsigned int size) * message instead (chip select held): each fits the polling path, as stock's * 64-byte reads do in Google's driver. */ -#define GNSS_SPI_PIECE SZ_64K +/* piece: transfer size within one message (chip select held); 64K = one transfer */ +static unsigned int piece = SZ_64K; +module_param(piece, uint, 0444); +#define GNSS_SPI_PIECE piece /* omamobile test: override the controller's feedback delay (FB_CLK_SEL) */ static int fb_delay = -1; From 859979c2a031d9d12651054efb29742943ba8202 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 19/36] Bring-up, not for merge: gnssif_spi: carry=1 carries the dropped bit into the next read Bring-up, not for merge. With realign=2, the bit the one-bit shift drops at the end of a read is Kepler's last bit of that block and the first bit sampled in the next read; carry=1 puts it back when the next read lands right after it in the same buffer (rx_work's skb). MODEM-PLAN G3, the morning of 10-29: no measurable change (the carry run in logs/tegu-gnss-w32-20261029). --- drivers/soc/google/gnssif_spi/gnss_spi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 0668a65482..2647f420f1 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -84,6 +84,14 @@ module_param(realign, int, 0444); * is, one at bit 1 shifts it; a read without one keeps the last choice. */ static bool gnss_spi_late; +/* + * carry=1: the bit the shift drops at the end of a read (Kepler's last bit of + * the block) is the first bit sampled in the next read, when that read lands + * right after it in the same buffer (rx_work's skb). + */ +static int carry; +module_param(carry, int, 0444); +static u8 *gnss_spi_carry_at; static int gnss_spi_k; /* realign=3: Kepler's bit offset, 0-7 */ static int gnss_spi_preamble_k(const u8 *b, unsigned int n) @@ -255,6 +263,12 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) } if (rx && realign == 2 && ret >= 0) { int at = gnss_spi_preamble_at(rx, size); + u8 first = ((u8 *)rx)[0] >> 7; + + if (carry && !tx && gnss_spi_carry_at && + gnss_spi_carry_at + 1 == (u8 *)rx && gnss_spi_late) + *gnss_spi_carry_at |= first; + gnss_spi_carry_at = tx ? NULL : (u8 *)rx + size - 1; if (at >= 0 && gnss_spi_late != at) { gnss_spi_late = at; From 90eb29fc5dcd618c3c962d7b7a617afd05317961 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 20/36] Bring-up, not for merge: gnssif_spi: rx_gap_us waits before each read Bring-up, not for merge. rx_gap_us sleeps that long before every read-only transfer, giving Kepler time to have its next block ready. MODEM-PLAN G3, the morning of 10-29: a 500 us gap before each read made Kepler stop sending long frames. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 2647f420f1..ee2a039325 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -91,6 +91,9 @@ static bool gnss_spi_late; */ static int carry; module_param(carry, int, 0444); +/* rx_gap_us: wait this long before each read-only transfer (Kepler's next block) */ +static int rx_gap_us; +module_param(rx_gap_us, int, 0444); static u8 *gnss_spi_carry_at; static int gnss_spi_k; /* realign=3: Kepler's bit offset, 0-7 */ @@ -223,6 +226,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) spi_message_add_tail(&t[i], &msg); } gnss_spi_hold_div(); + if (!tx && rx_gap_us > 0) + usleep_range(rx_gap_us, rx_gap_us + 50); if (rx_cpha) mutex_lock(&gnss_if.lock); if (rx_cpha) { From 937c3f991900bed4f502110b08808955d6117de4 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 21/36] Bring-up, not for merge: gnssif_spi: dump every byte of every transfer to the kernel log Bring-up, not for merge. GNSS_PKT_DEBUG on, and pr_buffer() prints the whole buffer, 64 bytes per line with the offset ("gnss_spi: RX(n)+off: ..."), instead of the first 64 bytes. MODEM-PLAN G3, the morning of 10-29: the reads of the thirty-fifth to forty-fourth tries were taken from this log (tools/tegu-gnss/g7-min saves them as rx.txt; tools/tegu-gnss/offline/frames_dump.py checks the CHPP CRCs in them) instead of from strace of gnssd. --- .../soc/google/gnssif_spi/gnss_link_device.c | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_link_device.c b/drivers/soc/google/gnssif_spi/gnss_link_device.c index fca0798a66..bcfa20ab86 100644 --- a/drivers/soc/google/gnssif_spi/gnss_link_device.c +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -15,7 +15,7 @@ #include "gnss_utils.h" #include "gnss_spi.h" -/* #define GNSS_PKT_DEBUG 1 */ +#define GNSS_PKT_DEBUG 1 #if defined(GNSS_PKT_DEBUG) #define PR_BUFFER_SIZE 64 @@ -49,17 +49,20 @@ static inline void dump2hex(char *buff, size_t buff_size, static int pr_buffer(const char *tag, const char *data, size_t data_len, size_t max_len) { - size_t len = min(data_len, max_len); - unsigned char str[PR_BUFFER_SIZE * 3]; /* 1 <= sizeof <= max_len*3 */ - - if (len > PR_BUFFER_SIZE) - len = PR_BUFFER_SIZE; - - dump2hex(str, (len ? len * 3 : 1), data, len); - - /* don't change this printk to mif_debug for print this as level7 */ - return pr_info("%s: %s(%ld): %s%s\n", "gnss_spi", tag, (long)data_len, - str, (len == data_len) ? "" : " ..."); + /* omamobile: every byte, 64 per line, with the offset */ + size_t off; + + for (off = 0; off < data_len; off += 64) { + size_t n = min_t(size_t, 64, data_len - off); + unsigned char str[64 * 3 + 1]; + size_t i; + + for (i = 0; i < n; i++) + sprintf(str + i * 3, "%02x ", (unsigned char)data[off + i]); + str[n * 3] = 0; + pr_info("gnss_spi: %s(%zu)+%zu: %s\n", tag, data_len, off, str); + } + return 0; } #else /* GNSS_PKT_DEBUG */ static inline int pr_buffer(const char *tag, const char *data, size_t data_len, From 09aa5d95ab490ef13a9cee35cf9a7d353052be76 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 22/36] Bring-up, not for merge: gnssif_spi: tx_gap_us waits before each write Bring-up, not for merge. tx_gap_us sleeps that long before every transfer with a tx buffer, in case Kepler needed a pause in its stream before our write. MODEM-PLAN G3, the morning of 10-29 (the txgap run in logs/tegu-gnss-w32-20261029): no change. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index ee2a039325..2eab861a6a 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -94,6 +94,9 @@ module_param(carry, int, 0444); /* rx_gap_us: wait this long before each read-only transfer (Kepler's next block) */ static int rx_gap_us; module_param(rx_gap_us, int, 0444); +/* tx_gap_us: wait this long before each write (Kepler pausing its stream) */ +static int tx_gap_us; +module_param(tx_gap_us, int, 0444); static u8 *gnss_spi_carry_at; static int gnss_spi_k; /* realign=3: Kepler's bit offset, 0-7 */ @@ -228,6 +231,8 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) gnss_spi_hold_div(); if (!tx && rx_gap_us > 0) usleep_range(rx_gap_us, rx_gap_us + 50); + if (tx && tx_gap_us > 0) + usleep_range(tx_gap_us, tx_gap_us + 100); if (rx_cpha) mutex_lock(&gnss_if.lock); if (rx_cpha) { From 87f92713e842f5bd19ec448a31d56200d7d3f2bb Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 23/36] Bring-up, not for merge: gnssif_spi: pad every write to a whole 64-byte exchange Bring-up, not for merge. Kepler moves one 64-byte block per chip-select cycle, so the link device rounds every write up to a multiple of 64 bytes (zero padding) and delivers all the received bytes of the exchange to the reader (CHPP skips the zeros). MODEM-PLAN G3, the morning of 10-29, "Padding each write to a whole 64-byte exchange (gnssif) changed nothing measurable." --- .../soc/google/gnssif_spi/gnss_link_device.c | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_link_device.c b/drivers/soc/google/gnssif_spi/gnss_link_device.c index bcfa20ab86..ac540ef697 100644 --- a/drivers/soc/google/gnssif_spi/gnss_link_device.c +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -154,6 +154,8 @@ static int send_betp(struct link_device *ld, struct io_device *iod, char *buff, { struct gnss_ctl *gc = ld->gc; struct sk_buff *skb; + unsigned int xfer; + char *tx; int ret = 0; if (size > ld->spi_tx_size) { @@ -161,13 +163,24 @@ static int send_betp(struct link_device *ld, struct io_device *iod, char *buff, size = ld->spi_tx_size; } - skb = alloc_skb(size, GFP_KERNEL); + /* + * omamobile: Kepler moves one 64-byte block per chip-select cycle, + * so a write is a whole 64-byte exchange: the packet, zero padding, + * and all 64 received bytes delivered (CHPP skips the zeros). + */ + xfer = round_up(size, 64); + tx = kzalloc(xfer, GFP_KERNEL); + if (!tx) + return -ENOMEM; + memcpy(tx, buff, size); + skb = alloc_skb(xfer, GFP_KERNEL); if (!skb) { gif_err("%s: ERR! tx alloc_skb fail (msg size:%u)\n", iod->name, size); + kfree(tx); return -ENOMEM; } - skb_put(skb, size); + skb_put(skb, xfer); atomic_set(&gc->tx_in_progress, 1); @@ -186,7 +199,7 @@ static int send_betp(struct link_device *ld, struct io_device *iod, char *buff, goto exit; } - ret = gnss_spi_send(buff, size, (char *)skb->data); + ret = gnss_spi_send(tx, xfer, (char *)skb->data); if (ret) { gif_err("gnss_spi_send() error:%d\n", ret); dev_kfree_skb_any(skb); @@ -198,6 +211,7 @@ static int send_betp(struct link_device *ld, struct io_device *iod, char *buff, } exit: + kfree(tx); atomic_set(&gc->wait_rdy, 0); atomic_set(&gc->tx_in_progress, 0); gc->ops.gnss_send_betp_int(gc, 0); From 6c368efbb15a220c76105cae38d231270e7522cb Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 24/36] Bring-up, not for merge: gnssif_spi: psr writes the SPI block's prescaler, bench times reads Bring-up, not for merge. psr >= 0 writes CLK_CFG (SPI 21 register 0x04: ENCLK bit 8, PSR bits 7:0) at probe, in case the IP had its own prescaler; bench=1 times ten 64-byte reads at probe, before Kepler runs, to see the real clock (82 us each at 6.24 MHz, 164 at 3.12). MODEM-PLAN G3, the morning of 10-29: "The SPI block's own prescaler does not exist on this IP (CLK_CFG reads 0 and ignores writes)." --- drivers/soc/google/gnssif_spi/gnss_spi.c | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 2eab861a6a..8dfbd2842d 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "include/gnss.h" #include "gnss_spi.h" @@ -94,6 +96,19 @@ module_param(carry, int, 0444); /* rx_gap_us: wait this long before each read-only transfer (Kepler's next block) */ static int rx_gap_us; module_param(rx_gap_us, int, 0444); +/* + * psr >= 0: the SPI block's own prescaler (CLK_CFG at 0x04: ENCLK bit 8, + * PSR bits 7:0; SPICLK = IPCLK / (2 * (PSR + 1)) if the IP has it). The + * driver never writes CLK_CFG for a CMU-clocked port. bench=1 times ten + * 64-byte reads at probe (Kepler not running yet) to see the real clock. + */ +#define GNSS_SPI_REGS 0x111e0000 +static int psr = -1; +module_param(psr, int, 0444); +static int bench; +module_param(bench, int, 0444); +static void __iomem *gnss_spi_regs; + /* tx_gap_us: wait this long before each write (Kepler pausing its stream) */ static int tx_gap_us; module_param(tx_gap_us, int, 0444); @@ -362,11 +377,39 @@ static int gnss_spi_probe(struct spi_device *spi) gif_info("feedback delay %u -> %d\n", cs->fb_delay, fb_delay); cs->fb_delay = fb_delay; } + if (psr >= 0 || bench) { + ret = pm_runtime_resume_and_get(spi->controller->dev.parent); + if (ret < 0) + gif_err("controller resume failed %d\n", ret); + else + gnss_spi_regs = ioremap(GNSS_SPI_REGS, 0x40); + ret = 0; + } + if (psr >= 0 && gnss_spi_regs) { + gif_info("CLK_CFG 0x%08x\n", readl(gnss_spi_regs + 4)); + writel(BIT(8) | (psr & 0xff), gnss_spi_regs + 4); + gif_info("CLK_CFG now 0x%08x\n", readl(gnss_spi_regs + 4)); + } if (cs_setup_us > 0) { spi->cs_setup.value = cs_setup_us; spi->cs_setup.unit = SPI_DELAY_UNIT_USECS; gif_info("cs_setup %d us\n", cs_setup_us); } + if (bench) { + char *buf = kzalloc(64, GFP_KERNEL); + ktime_t t0; + int i; + + if (buf) { + gnss_if.spi = spi; + t0 = ktime_get(); + for (i = 0; i < 10; i++) + gnss_spi_xfer(NULL, buf, 64); + gif_info("bench: ten 64-byte reads in %lld us (82 us each at 6.24 MHz, 164 at 3.12)\n", + ktime_us_delta(ktime_get(), t0)); + kfree(buf); + } + } spi_set_drvdata(spi, &gnss_if); gnss_if.spi = spi; gif_info("---\n"); From cd160bb570c75f7be7d60cf93b17cbb58792277a Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:22:40 -0647 Subject: [PATCH 25/36] Bring-up, not for merge: gnssif_spi: cs_hold_us keeps chip select after the last clock Bring-up, not for merge. cs_hold_us sets spi->cs_hold, so chip select stays asserted that long after a transfer's last clock. MODEM-PLAN G3, the morning of 10-29, the last try: "a 50 us chip-select hold did nothing" (the g7min-cpha-hold run). This is the module as it was left on maclab (~/tegu/gnssif-realign) when GNSS was parked; the palmtop runs the as-ported driver of the first commit. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 8dfbd2842d..168711b8ad 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -213,6 +213,9 @@ static void __maybe_unused gnss_spi_cmu_div(void) /* omamobile test: microseconds from chip select to the first clock */ static int cs_setup_us; module_param(cs_setup_us, int, 0444); +/* cs_hold_us: keep chip select asserted this long after the last clock */ +static int cs_hold_us; +module_param(cs_hold_us, int, 0444); static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) { @@ -390,6 +393,11 @@ static int gnss_spi_probe(struct spi_device *spi) writel(BIT(8) | (psr & 0xff), gnss_spi_regs + 4); gif_info("CLK_CFG now 0x%08x\n", readl(gnss_spi_regs + 4)); } + if (cs_hold_us > 0) { + spi->cs_hold.value = cs_hold_us; + spi->cs_hold.unit = SPI_DELAY_UNIT_USECS; + gif_info("cs_hold %d us\n", cs_hold_us); + } if (cs_setup_us > 0) { spi->cs_setup.value = cs_setup_us; spi->cs_setup.unit = SPI_DELAY_UNIT_USECS; From 75c9c928cac5a423ca1a0686df06fab87ad22025 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:23:57 -0647 Subject: [PATCH 26/36] Bring-up, not for merge: soc: samsung: tegu-pdma-probe: Read the Pixel 9a's pdma1 PrimeCell IDs Bring-up, not for merge. Stock drives the GNSS SPI with DMA through pdma1, a PL330 at 0x10130000 (GIC SPI 806) that our device tree does not have. Before giving it a node, this module reads its four PrimeCell ID registers once from Linux, one register per read, and returns -EAGAIN so nothing stays loaded. MODEM-PLAN G3, "DMA" (2026-10-29): periph 0x30 0x13, cell 0x0d 0xf0, read without an abort, so a DT node can probe it (logs/tegu-gnss-autocs-20261029/pdma-probe-kmsg.txt). It ran as tegu-pdma-probe.ko on the gn3 kernel; the Kconfig entry defaults to n. --- drivers/soc/samsung/Kconfig | 9 +++++++++ drivers/soc/samsung/Makefile | 2 ++ drivers/soc/samsung/tegu-pdma-probe.c | 28 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 drivers/soc/samsung/tegu-pdma-probe.c diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index 1a5dfdc978..2dffb93440 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -75,4 +75,13 @@ config SAMSUNG_PM_CHECK_CHUNKSIZE config EXYNOS_REGULATOR_COUPLER bool "Exynos SoC Regulator Coupler" if COMPILE_TEST depends on ARCH_EXYNOS || COMPILE_TEST + +config TEGU_PDMA_PROBE + tristate "Pixel 9a pdma1 PrimeCell ID probe (bring-up)" + depends on ARCH_EXYNOS + default n + help + Bring-up only, not for merge: reads the four PL330 PrimeCell ID + registers of the Pixel 9a's pdma1 (0x10130000) once at load and + fails the load, so nothing stays resident. For MODEM-PLAN G3. endif diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index 636a762608..861658063b 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -14,3 +14,5 @@ obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \ obj-$(CONFIG_EXYNOS_REGULATOR_COUPLER) += exynos-regulator-coupler.o obj-$(CONFIG_SAMSUNG_PM_CHECK) += s3c-pm-check.o + +obj-$(CONFIG_TEGU_PDMA_PROBE) += tegu-pdma-probe.o diff --git a/drivers/soc/samsung/tegu-pdma-probe.c b/drivers/soc/samsung/tegu-pdma-probe.c new file mode 100644 index 0000000000..439a9a2253 --- /dev/null +++ b/drivers/soc/samsung/tegu-pdma-probe.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Read-only probe (MODEM-PLAN G3, DMA for the GNSS SPI): read the PL330 + * PrimeCell IDs of stock's pdma1 (0x10130000) once, one register per read, + * to see whether the block answers Linux before a DT node probes it. + */ +#include +#include + +static int __init pdma_probe_init(void) +{ + void __iomem *b = ioremap(0x10130000, 0x1000); + u32 p0, p1, c0, c1; + + if (!b) + return -ENOMEM; + p0 = readl(b + 0xfe0); + p1 = readl(b + 0xfe4); + c0 = readl(b + 0xff0); + c1 = readl(b + 0xff4); + pr_info("tegu-pdma-probe: periph 0x%02x 0x%02x cell 0x%02x 0x%02x\n", + p0 & 0xff, p1 & 0xff, c0 & 0xff, c1 & 0xff); + iounmap(b); + return -EAGAIN; /* nothing to keep loaded */ +} +module_init(pdma_probe_init); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Read-only PL330 ID probe for the Pixel 9a's pdma1"); From 1162bf28ce72042c49efda6e35826de6a957d209 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:23:57 -0647 Subject: [PATCH 27/36] Bring-up, not for merge: soc: samsung: tegu-pdma-rt: Register pdma1 at runtime and run a memcpy Bring-up, not for merge. The "runtime test module" of MODEM-PLAN G3's DMA step (2026-10-29, night): it maps GIC SPI 806 through the GIC's fwnode, registers a fixed 200 MHz clock as pdma1's apb_pclk, allocates an AMBA device "10130000.pdma" for stock's pdma1 (PL330 at 0x10130000) and adds it, so the built-in pl330 driver probes it, then asks for a DMA_MEMCPY channel of that device and copies 256 bytes through it. On the palmtop the pl330 driver probed it ("DMAC-341330, 8 channels, 32 peripherals") and the copy matched (logs/tegu-gnss-dma-20261029/pdma-rt-kmsg.txt), which is why a DT node for pdma1 followed. With that node and dmas on the GNSS SPI, RX DMA moved nothing (residue 64): the SPI's requests do not reach pdma1, so some routing stock sets up is still missing. It ran as tegu-pdma-rt.ko on the gn3 kernel; the Kconfig entry defaults to n. --- drivers/soc/samsung/Kconfig | 11 +++ drivers/soc/samsung/Makefile | 1 + drivers/soc/samsung/tegu-pdma-rt.c | 118 +++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/soc/samsung/tegu-pdma-rt.c diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index 2dffb93440..f5f093a9b0 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -84,4 +84,15 @@ config TEGU_PDMA_PROBE Bring-up only, not for merge: reads the four PL330 PrimeCell ID registers of the Pixel 9a's pdma1 (0x10130000) once at load and fails the load, so nothing stays resident. For MODEM-PLAN G3. + +config TEGU_PDMA_RT + tristate "Pixel 9a pdma1 runtime registration and memcpy test (bring-up)" + depends on ARCH_EXYNOS && ARM_AMBA && DMADEVICES + default n + help + Bring-up only, not for merge: registers the Pixel 9a's pdma1 (PL330 + at 0x10130000, GIC SPI 806, a fixed 200 MHz APB clock) as an AMBA + device at load, so the pl330 driver probes it without a device-tree + node, then runs one 256-byte DMA memcpy through it and compares the + buffers. For MODEM-PLAN G3. endif diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index 861658063b..35f97eb445 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -16,3 +16,4 @@ obj-$(CONFIG_EXYNOS_REGULATOR_COUPLER) += exynos-regulator-coupler.o obj-$(CONFIG_SAMSUNG_PM_CHECK) += s3c-pm-check.o obj-$(CONFIG_TEGU_PDMA_PROBE) += tegu-pdma-probe.o +obj-$(CONFIG_TEGU_PDMA_RT) += tegu-pdma-rt.o diff --git a/drivers/soc/samsung/tegu-pdma-rt.c b/drivers/soc/samsung/tegu-pdma-rt.c new file mode 100644 index 0000000000..1a86260a3e --- /dev/null +++ b/drivers/soc/samsung/tegu-pdma-rt.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Runtime test (MODEM-PLAN G3): register stock's pdma1 (PL330 at + * 0x10130000, SPI 806) as an AMBA device so the built-in pl330 driver + * probes it, then run one 256-byte DMA memcpy through it and compare. + * Proves the controller works from Linux before a DT node probes it at boot. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct amba_device *adev; +static struct clk_hw *hw; + +static bool filter(struct dma_chan *chan, void *param) +{ + return chan->device->dev == param; +} + +static int __init rt_init(void) +{ + struct irq_fwspec fw = { 0 }; + struct device_node *gic; + struct dma_chan *ch; + dma_cap_mask_t mask; + void *src, *dst; + dma_addr_t s, d; + struct dma_async_tx_descriptor *tx; + dma_cookie_t ck; + int ret, irq, i; + + gic = of_find_compatible_node(NULL, NULL, "arm,gic-v3"); + if (!gic) + return -ENODEV; + fw.fwnode = of_fwnode_handle(gic); + fw.param_count = 3; + fw.param[0] = 0; /* SPI */ + fw.param[1] = 806; + fw.param[2] = IRQ_TYPE_LEVEL_HIGH; + irq = irq_create_fwspec_mapping(&fw); + of_node_put(gic); + if (irq <= 0) + return -EINVAL; + + hw = clk_hw_register_fixed_rate(NULL, "tegu-pdma1-apb", NULL, 0, 200000000); + if (IS_ERR(hw)) + return PTR_ERR(hw); + clk_hw_register_clkdev(hw, "apb_pclk", "10130000.pdma"); + + adev = amba_device_alloc("10130000.pdma", 0x10130000, 0x1000); + if (!adev) + return -ENOMEM; + adev->irq[0] = irq; + adev->dev.coherent_dma_mask = DMA_BIT_MASK(32); + adev->dev.dma_mask = &adev->dev.coherent_dma_mask; + ret = amba_device_add(adev, &iomem_resource); + if (ret) { + pr_err("tegu-pdma-rt: amba_device_add %d\n", ret); + amba_device_put(adev); + adev = NULL; + return ret; + } + msleep(200); + pr_info("tegu-pdma-rt: device added, driver %s\n", + adev->dev.driver ? adev->dev.driver->name : "(none)"); + if (!adev->dev.driver) + return 0; + + dma_cap_zero(mask); + dma_cap_set(DMA_MEMCPY, mask); + ch = dma_request_channel(mask, filter, &adev->dev); + if (!ch) { + pr_err("tegu-pdma-rt: no memcpy channel\n"); + return 0; + } + src = dma_alloc_coherent(ch->device->dev, 256, &s, GFP_KERNEL); + dst = dma_alloc_coherent(ch->device->dev, 256, &d, GFP_KERNEL); + if (!src || !dst) + goto out; + for (i = 0; i < 256; i++) + ((u8 *)src)[i] = i ^ 0x5a; + memset(dst, 0, 256); + tx = dmaengine_prep_dma_memcpy(ch, d, s, 256, DMA_PREP_INTERRUPT); + if (!tx) { + pr_err("tegu-pdma-rt: prep failed\n"); + goto out; + } + ck = dmaengine_submit(tx); + dma_async_issue_pending(ch); + ret = dma_sync_wait(ch, ck); + pr_info("tegu-pdma-rt: memcpy status %d, %s (src %pad dst %pad)\n", ret, + memcmp(src, dst, 256) ? "MISMATCH" : "data matches", &s, &d); +out: + if (src) + dma_free_coherent(ch->device->dev, 256, src, s); + if (dst) + dma_free_coherent(ch->device->dev, 256, dst, d); + dma_release_channel(ch); + return 0; +} + +static void __exit rt_exit(void) +{ + if (adev) + amba_device_unregister(adev); +} + +module_init(rt_init); +module_exit(rt_exit); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Runtime test of the Pixel 9a's pdma1 (PL330)"); From 1cf256c712abe94debbcd3ea417094acf2b7c7a9 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:23:57 -0647 Subject: [PATCH 28/36] Bring-up, not for merge: arm64: dts: exynos: google: zumapro-tegu: The GNSS SPI test overlays Bring-up, not for merge. The device-tree changes behind MODEM-PLAN G3's tries on the Pixel 9a, as overlays on the palmtop's integration DTB (gn3; the published omamobile branch has no zumapro-tegu.dts yet, so there is no board file here to change): - zumapro-tegu-gnss-spi-fb0.dtso: stock's feedback delay 0 on the GNSS SPI device (ninth to fourteenth tries, the "feedback delay 0" rows); - zumapro-tegu-gnss-spi-autocs.dtso: automatic chip select, by leaving spi21 with the google,gs101-spi compatible only (the "auto CS" rows of the ninth to fourteenth tries and "acs" of the fifteenth to twenty-third: no change with 8-bit words); - zumapro-tegu-pdma1.dtso: stock's pdma1 (PL330 at 0x10130000, GIC SPI 806, a fixed 200 MHz APB clock) and dmas on spi21 in stock's order (0x14 tx, 0x15 rx): the pl330 driver probed it at boot, but RX DMA moved nothing (residue 64); - zumapro-tegu-pdma1-swapped.dtso: the second boot, channels the other way round, the same result; the boot after it reset at 69 s, cause not seen. Each test DTB was the gn3 DTB with the change compiled in (the dts in logs/tegu-gnss-dma-20261029 is gn3's source with the pdma1 node), copied into the build kit, packed into slot B's images by the kit's "omamobile images" twice (the two packs had to match) and written with "omamobile push"; the palmtop is back on the gn3 DTB without any of them. The overlays are not wired into the Makefile: the board DTB they apply to is not in this tree. --- .../google/zumapro-tegu-gnss-spi-autocs.dtso | 15 ++++++++ .../google/zumapro-tegu-gnss-spi-fb0.dtso | 16 ++++++++ .../google/zumapro-tegu-pdma1-swapped.dtso | 13 +++++++ .../dts/exynos/google/zumapro-tegu-pdma1.dtso | 37 +++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-autocs.dtso create mode 100644 arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-fb0.dtso create mode 100644 arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1-swapped.dtso create mode 100644 arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1.dtso diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-autocs.dtso b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-autocs.dtso new file mode 100644 index 0000000000..86d7d52cd7 --- /dev/null +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-autocs.dtso @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; +/plugin/; + +/* + * Pixel 9a bring-up, not for merge (MODEM-PLAN G3): the GNSS SPI with + * the controller's automatic chip select, as Google's driver uses for + * this device (no samsung,spi-chip-select-mode). Dropping the + * google,zumapro-spi compatible leaves google,gs101-spi, for which + * spi-s3c64xx in this tree lets the controller drive chip select itself. + * Applied to the palmtop's integration DTB (gn3). + */ +&spi21 { + compatible = "google,gs101-spi"; +}; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-fb0.dtso b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-fb0.dtso new file mode 100644 index 0000000000..499e208dd6 --- /dev/null +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-fb0.dtso @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; +/plugin/; + +/* + * Pixel 9a bring-up, not for merge (MODEM-PLAN G3): the GNSS SPI with + * stock's feedback delay 0 instead of the ported node's 2. Applied to + * the palmtop's integration DTB (gn3), which has the spi21 label. + */ +&spi21 { + gnss@0 { + controller-data { + samsung,spi-feedback-delay = <0>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1-swapped.dtso b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1-swapped.dtso new file mode 100644 index 0000000000..224dda985c --- /dev/null +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1-swapped.dtso @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; +/plugin/; + +/* + * Pixel 9a bring-up, not for merge (MODEM-PLAN G3): the second boot with + * pdma1, the GNSS SPI's two DMA channels the other way round (0x15 tx, + * 0x14 rx), in case stock's order was wrong for mainline. Applied on top + * of zumapro-tegu-pdma1.dtso. + */ +&spi21 { + dma-names = "rx", "tx"; +}; diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1.dtso b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1.dtso new file mode 100644 index 0000000000..1c5ef741bd --- /dev/null +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-pdma1.dtso @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; +/plugin/; + +#include + +/* + * Pixel 9a bring-up, not for merge (MODEM-PLAN G3): stock's pdma1, a + * PL330 at 0x10130000 on GIC SPI 806, with a fixed 200 MHz APB clock + * (the clock tree has no node for it yet), and the GNSS SPI's DMA + * channels as stock's overlay gives them (0x14 tx, 0x15 rx). Samsung's + * 36-bit address wrappers around the PL330 are not described. Applied + * to the palmtop's integration DTB (gn3), which has the soc and spi21 + * labels. + */ +&soc { + pdma1_apb: clock-pdma-200m { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + clock-output-names = "pdma1-apb"; + }; + + pdma1: dma-controller@10130000 { + compatible = "arm,pl330", "arm,primecell"; + reg = <0x0 0x10130000 0x1000>; + interrupts = ; + clocks = <&pdma1_apb>; + clock-names = "apb_pclk"; + #dma-cells = <1>; + }; +}; + +&spi21 { + dmas = <&pdma1 0x14>, <&pdma1 0x15>; + dma-names = "tx", "rx"; +}; From da50642ab5f2c44c777e99808fde2a99c90ee631 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:23:58 -0647 Subject: [PATCH 29/36] Bring-up, not for merge: tools/tegu-gnss: The scripts behind MODEM-PLAN G3's tries Bring-up, not for merge. The on-palmtop scripts (g7-strace.sh from the fifth try on, g7-min for the morning's short sessions), the laptop's run-case.sh and run-short.sh that ran one case per fresh boot with the gnss_spi module parameters in GNSS_SPI_ARGS, and the offline Python checks of the saved reads (CHPP CRC32, bit offsets, shifts, the boundary brute force), as they were in /tmp/w32p32 on the laptop and logs/tegu-modem-20261027/phone in the omarchy-mobile tree, with one change: the three scripts that imported from /tmp/w32p32 now import from their own directory. The README says what each does. No captured GNSS data is included. --- tools/tegu-gnss/README | 47 ++++++++++++++++++++++++++ tools/tegu-gnss/g7-min | 22 ++++++++++++ tools/tegu-gnss/g7-strace.sh | 41 ++++++++++++++++++++++ tools/tegu-gnss/offline/bits.py | 12 +++++++ tools/tegu-gnss/offline/brute.py | 22 ++++++++++++ tools/tegu-gnss/offline/chpp.py | 23 +++++++++++++ tools/tegu-gnss/offline/diffpos.py | 25 ++++++++++++++ tools/tegu-gnss/offline/frames.py | 11 ++++++ tools/tegu-gnss/offline/frames_dump.py | 22 ++++++++++++ tools/tegu-gnss/offline/long.py | 13 +++++++ tools/tegu-gnss/offline/realign.py | 15 ++++++++ tools/tegu-gnss/offline/realign2.py | 17 ++++++++++ tools/tegu-gnss/offline/xor.py | 5 +++ tools/tegu-gnss/run-case.sh | 5 +++ tools/tegu-gnss/run-short.sh | 5 +++ 15 files changed, 285 insertions(+) create mode 100644 tools/tegu-gnss/README create mode 100755 tools/tegu-gnss/g7-min create mode 100755 tools/tegu-gnss/g7-strace.sh create mode 100644 tools/tegu-gnss/offline/bits.py create mode 100644 tools/tegu-gnss/offline/brute.py create mode 100644 tools/tegu-gnss/offline/chpp.py create mode 100644 tools/tegu-gnss/offline/diffpos.py create mode 100644 tools/tegu-gnss/offline/frames.py create mode 100644 tools/tegu-gnss/offline/frames_dump.py create mode 100644 tools/tegu-gnss/offline/long.py create mode 100644 tools/tegu-gnss/offline/realign.py create mode 100644 tools/tegu-gnss/offline/realign2.py create mode 100644 tools/tegu-gnss/offline/xor.py create mode 100755 tools/tegu-gnss/run-case.sh create mode 100755 tools/tegu-gnss/run-short.sh diff --git a/tools/tegu-gnss/README b/tools/tegu-gnss/README new file mode 100644 index 0000000000..b9a0dd7b55 --- /dev/null +++ b/tools/tegu-gnss/README @@ -0,0 +1,47 @@ +Pixel 9a GNSS SPI bring-up scripts (MODEM-PLAN G3, 2026-10-28/29) +================================================================= + +Bring-up only, not for merge. The scripts that ran the tries of +MODEM-PLAN G3 (derekross/omarchy-mobile, device/tegu/MODEM-PLAN.md) on +the palmtop and the offline checks of their captures, published so the +plan can link each try to what ran. Paths are the palmtop's and the +laptop's as they were. + +On the palmtop (/usr/local/bin): + + g7-strace.sh fifth try onwards: start the modem with GNSS, attach + strace to gnssd, request a location, record 240 s of + syscalls and gnssd's log under /var/log/omamobile/g7. + g7-min the morning's short sessions (installed as g7-short): + engine start, 35 s of frames dumped by the gnssif + built with GNSS_PKT_DEBUG, then stop, so Kepler's + watchdog resets do not pile up; rx.txt holds the bytes. + +On the laptop, one case per fresh boot: + + run-case.sh NAME "ARGS" waits for the palmtop, runs g7-strace under + systemd-run with GNSS_SPI_ARGS=ARGS (the + device package's omamobile-tegu-modem-up + appends them to insmod gnss_spi.ko), then + counts bad checksums, ACK timeouts, watchdog + and hard-fault lines in gnssd's log. + run-short.sh NAME "ARGS" the same with g7-short. + +Offline, on a saved strace (reads of /dev/gnss_ipc) or rx.txt: + + chpp.py CHPP frames in the reads and whether their CRC32 (over + the 8-byte header and payload) matches the footer. + realign.py valid frames per left shift of 0-7 bits (the one-bit-late + finding of the twenty-ninth try). + realign2.py valid and invalid frames by length after a one-bit shift, + whole buffer and per 64-byte read. + bits.py at which bit offset modulo 8 the CHPP preamble arrives. + frames.py the first N reads that hold a preamble, as hex. + frames_dump.py the same CRC check on the kernel-log dump of g7-min. + brute.py set the dropped bit at every 64-byte read boundary of a + long frame every possible way and see if any passes. + diffpos.py where copies of a resent frame disagree, by offset in + the 64-byte read. + long.py the first three reads of 192 bytes or more, in 64-byte + rows. + xor.py footer against computed CRC of the "BAD checksum" lines. diff --git a/tools/tegu-gnss/g7-min b/tools/tegu-gnss/g7-min new file mode 100755 index 0000000000..210abe1b00 --- /dev/null +++ b/tools/tegu-gnss/g7-min @@ -0,0 +1,22 @@ +#!/bin/bash +# A short GNSS session: engine start, 35 s of frames, then the location request +# stops, so Kepler's watchdog resets (and the CP link cycling) don't pile up. +set -uo pipefail +O=/var/log/omamobile/g7min; rm -rf "$O"; mkdir -p "$O" +say() { printf 'g7min: %s\n' "$*"; } +for n in gnss-core gnss-rf gnss-aux; do + r=$(grep -lx "$n" /sys/class/regulator/*/name 2>/dev/null | head -1) + [[ -n $r && $(cat "$(dirname "$r")/state") == enabled ]] || { say "STOP: $n"; exit 1; } +done +/usr/local/bin/omamobile-tegu-modem-up --gnss || { say "STOP: modem not ONLINE"; exit 1; } +for _ in $(seq 1 120); do pgrep -x gnssd >/dev/null && break; sleep 0.25; done +pgrep -x gnssd >/dev/null || { say "STOP: no gnssd"; exit 1; } +dmesg -C +sleep 5 +systemd-run -q --unit=x-gnss-slsi -p KillMode=control-group sh -c \ + "OMAMOBILE_GNSS_NMEA_OUT=stdout /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start > $O/gnss-slsi.log 2>&1" +sleep 35 +systemctl stop x-gnss-slsi 2>/dev/null +dmesg | grep -a "gnss_spi: " > "$O/rx.txt" +tail -n 400 /var/log/omamobile/modem.log > "$O/modem.log" +say "done: $(wc -l < "$O/rx.txt") dump lines" diff --git a/tools/tegu-gnss/g7-strace.sh b/tools/tegu-gnss/g7-strace.sh new file mode 100755 index 0000000000..45eca40305 --- /dev/null +++ b/tools/tegu-gnss/g7-strace.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# G3, fifth try: strace gnssd across engine starts (observation only). +# Starts the modem with GNSS (once per boot), attaches strace to gnssd as +# soon as it runs, and records 240 s of its syscalls plus gnssd's own log. +# Stop condition: a modem not ONLINE, or the rails off. Afterwards the modem +# stays up (no stop by hand); the next try needs a reboot. +set -uo pipefail +L=/var/log/omamobile/modem.log +O=/var/log/omamobile/g7; mkdir -p "$O" +say() { printf 'g7: %s\n' "$*"; } +for n in gnss-core gnss-rf gnss-aux; do + r=$(grep -lx "$n" /sys/class/regulator/*/name 2>/dev/null | head -1) + [[ -n $r ]] || { say "STOP: no $n regulator"; exit 1; } + s=$(cat "$(dirname "$r")/state" 2>/dev/null) + say "$n: $s"; [[ $s == enabled ]] || { say "STOP: $n is $s"; exit 1; } +done +touch "$L"; start=$(wc -l < "$L") +/usr/local/bin/omamobile-tegu-modem-up --gnss || { say "STOP: modem not ONLINE"; exit 1; } +pid= +for _ in $(seq 1 120); do + pid=$(pgrep -x gnssd | head -1) && [[ -n $pid ]] && break + sleep 0.25 +done +[[ -n $pid ]] || { say "STOP: no gnssd"; exit 1; } +say "gnssd pid $pid" +timeout 240 strace -f -tt -T -yy -s 256 -p "$pid" -o "$O/strace.txt" 2>"$O/strace.err" & +sp=$! +# the HAL and our client: a location request, so the engine starts +sleep 5 +systemd-run -q --unit=x-gnss-slsi -p KillMode=control-group sh -c \ + "OMAMOBILE_GNSS_NMEA_OUT=stdout /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start > $O/gnss-slsi.log 2>&1" +for i in $(seq 1 48); do + sleep 5 + t=$(tail -n +"$((start + 1))" "$L") + hf=$(grep -c "HARDFAULT" <<<"$t"); nm=$(grep -c -E '\$G[PNL][A-Z]{3},' <<<"$t") + say "t=$((i * 5))s hardfaults=$hf nmea=$nm" +done +wait "$sp" 2>/dev/null +tail -n +"$((start + 1))" "$L" > "$O/modem.log" +journalctl -b --no-pager -o short-monotonic | grep -iE "gnss|kepler|cpif|ufshcd" > "$O/journal.txt" +say "strace lines $(wc -l < "$O/strace.txt"); output in $O" diff --git a/tools/tegu-gnss/offline/bits.py b/tools/tegu-gnss/offline/bits.py new file mode 100644 index 0000000000..03a3ea6aad --- /dev/null +++ b/tools/tegu-gnss/offline/bits.py @@ -0,0 +1,12 @@ +import sys,re,ast,collections +c=collections.Counter(); first=collections.Counter() +for l in open(sys.argv[1],errors='replace'): + m=re.search(r'read\(\d+<[^>]*gnss_ipc>, "(.*)", \d+\) = (\d+)',l) + if not m: continue + b=ast.literal_eval('b"'+m.group(1)+'"') + bits=''.join(f'{x:08b}' for x in b) + offs=[i for i in range(len(bits)-16) if bits[i:i+16]=='0110100001000011'] + for o in offs: c[o%8]+=1 + if offs: first[(offs[0]%8, offs[0]//8)]+=1 +print('preamble bit offset mod 8:',sorted(c.items())) +print('first preamble (bit, byte):',first.most_common(12)) diff --git a/tools/tegu-gnss/offline/brute.py b/tools/tegu-gnss/offline/brute.py new file mode 100644 index 0000000000..a72a4041af --- /dev/null +++ b/tools/tegu-gnss/offline/brute.py @@ -0,0 +1,22 @@ +import sys,zlib,struct,itertools,collections +sys.path.insert(0, __import__('os').path.dirname(__file__)) +from chpp import reads +res=collections.Counter() +for b in reads(sys.argv[1]): + i=b.find(b'hC') + while i>=0 and i+10<=len(b): + ln=struct.unpack_from('54 and end<=len(b): + fr=bytearray(b[i:end]) + # byte positions (in frame) that are the last byte of a 64-byte read + pos=[p-i for p in range(63,len(b),64) if i<=p]*gnss_ipc>, "(.*)", \d+\) = (\d+)',l) + if m: yield ast.literal_eval('b"'+m.group(1)+'"') +def frames(buf): + out=[];i=0 + while True: + i=buf.find(b'hC',i) + if i<0 or i+10>len(buf): break + h=buf[i+2:i+10] + ln=struct.unpack_from(']*gnss_ipc>, "(.*)", \d+\) = (\d+)',l) + if m: reads.append(ast.literal_eval('b"'+m.group(1)+'"')) +# normalise: strip to the first preamble +frames=collections.defaultdict(list) +for b in reads: + i=b.find(b'hC') + if i<0 or len(b)-i<40: continue + frames[b[i:i+12]].append((i,b)) +pos=collections.Counter(); tot=collections.Counter() +for k,v in frames.items(): + if len(v)<3: continue + L=min(len(b)-i for i,b in v) + # majority byte per frame offset + for o in range(L): + vals=collections.Counter(b[i+o] for i,b in v) + maj=vals.most_common(1)[0][0] + for i,b in v: + ro=(i+o)%64 # offset inside the 64-byte read + tot[ro]+=1 + if b[i+o]!=maj: pos[ro]+=1 +print('read offset: bad/total') +print(' '.join('%d:%d/%d'%(o,pos[o],tot[o]) for o in range(64) if pos[o])) diff --git a/tools/tegu-gnss/offline/frames.py b/tools/tegu-gnss/offline/frames.py new file mode 100644 index 0000000000..35e61fa715 --- /dev/null +++ b/tools/tegu-gnss/offline/frames.py @@ -0,0 +1,11 @@ +import sys,re,ast +n=0 +for l in open(sys.argv[1],errors='replace'): + m=re.search(r'read\(\d+<[^>]*gnss_ipc>, "(.*)", \d+\) = (\d+)',l) + if not m: continue + b=ast.literal_eval('b"'+m.group(1)+'"') + i=b.find(b'hC') + if i<0: continue + print(l[6:21], b[i:i+40].hex(' ')) + n+=1 + if n>=int(sys.argv[2]): break diff --git a/tools/tegu-gnss/offline/frames_dump.py b/tools/tegu-gnss/offline/frames_dump.py new file mode 100644 index 0000000000..f8fe59a3da --- /dev/null +++ b/tools/tegu-gnss/offline/frames_dump.py @@ -0,0 +1,22 @@ +import re,struct,zlib,sys,collections +lines=open(sys.argv[1],errors='replace').read().splitlines() +bufs=[]; cur=None +for l in lines: + m=re.search(r'gnss_spi: (RX|TX)\((\d+)\)\+(\d+): ([0-9a-f ]*)',l) + if not m: continue + tag,n,off,hx=m.group(1),int(m.group(2)),int(m.group(3)),m.group(4) + if off==0: cur=bytearray(); bufs.append((tag,n,cur)) + if cur is not None: cur+=bytes.fromhex(hx.replace(' ','')) +ok=collections.Counter(); bad=collections.Counter() +for tag,n,b in bufs: + if tag!='RX': continue + i=0 + while True: + i=b.find(b'hC',i) + if i<0 or i+10>len(b): break + ln=struct.unpack_from(']*gnss_ipc>, "(.*)", \d+\) = (\d+)',l) + if m: reads.append((l[6:21],ast.literal_eval('b"'+m.group(1)+'"'))) +shown=0 +for i,(t,b) in enumerate(reads): + if len(b)>=192: + print(t,len(b)) + for k in range(0,min(len(b),320),64): + print(' %3d'%k, b[k:k+64].hex()) + shown+=1 + if shown>=3: break diff --git a/tools/tegu-gnss/offline/realign.py b/tools/tegu-gnss/offline/realign.py new file mode 100644 index 0000000000..e91c73f9ec --- /dev/null +++ b/tools/tegu-gnss/offline/realign.py @@ -0,0 +1,15 @@ +import sys,collections +sys.path.insert(0, __import__('os').path.dirname(__file__)) +from chpp import reads,frames +def shl(b,k): + n=int.from_bytes(b,'big')<0]+=1 + if max(res.values())==0 and b.find(b'hC')>=0: bad_all+=1 + print(path.split('/')[-1], 'valid frames per shift:', dict(tot), 'reads with any valid:', dict(best)) diff --git a/tools/tegu-gnss/offline/realign2.py b/tools/tegu-gnss/offline/realign2.py new file mode 100644 index 0000000000..371c1dcca0 --- /dev/null +++ b/tools/tegu-gnss/offline/realign2.py @@ -0,0 +1,17 @@ +import sys,collections +sys.path.insert(0, __import__('os').path.dirname(__file__)) +from chpp import reads,frames +from realign import shl +ok=collections.Counter(); bad=collections.Counter() +for b in reads(sys.argv[1]): + if not any(b): continue + for ln,v in frames(shl(b,1)): + (ok if v else bad)[ln]+=1 +print('valid by length', sorted(ok.items())); print('invalid by length', sorted(bad.items())) +# per-chunk shift instead of whole buffer +ok2=collections.Counter(); bad2=collections.Counter() +for b in reads(sys.argv[1]): + if not any(b): continue + c=b''.join(shl(b[i:i+64],1) for i in range(0,len(b),64)) + for ln,v in frames(c): (ok2 if v else bad2)[ln]+=1 +print('per-64 chunk: valid', sum(ok2.values()), 'invalid', sum(bad2.values()), sorted(bad2.items())[:8]) diff --git a/tools/tegu-gnss/offline/xor.py b/tools/tegu-gnss/offline/xor.py new file mode 100644 index 0000000000..d2fbc0c38f --- /dev/null +++ b/tools/tegu-gnss/offline/xor.py @@ -0,0 +1,5 @@ +import sys,re +for l in sys.stdin: + h=re.findall(r"0x([0-9a-f]+)",l); n=l.split("len=")[1].strip() + f=int(h[0],16);c=int(h[1],16);x=f^c + print("%08x %08x xor=%08x bits=%d len=%s"%(f,c,x,bin(x).count("1"),n)) diff --git a/tools/tegu-gnss/run-case.sh b/tools/tegu-gnss/run-case.sh new file mode 100755 index 0000000000..3963d65696 --- /dev/null +++ b/tools/tegu-gnss/run-case.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# usage: run-case.sh NAME "GNSS_SPI_ARGS" (palmtop freshly booted) +cd ~/git/omarchy-mobile +until tools/phone-ssh --fresh true 2>/dev/null; do sleep 5; done +tools/phone-ssh "until [ \$(cut -d. -f1 /proc/uptime) -ge 60 ]; do sleep 2; done; systemd-run -q --unit=x-g7 -E GNSS_SPI_ARGS='$2' sh -c '/usr/local/bin/g7-strace > /var/log/omamobile/g7-run.txt 2>&1'; sleep 30; dmesg | grep -iE 'feedback delay|cs_setup|usi3|hs:|realign'; while systemctl is-active -q x-g7; do sleep 10; done; L=/var/log/omamobile/g7/modem.log; for p in 'BAD checksum' 'ACK timeout' 'soft_dog pos' HARDFAULT 'RX RESET-ACK' 'RX packet len'; do printf '%s: ' \"\$p\"; grep -ac \"\$p\" \$L; done; grep -aiE 'svid|sv_id|C/N0|cn0' \$L | tail -3; grep -ao 'BAD checksum: footer=0x[0-9a-f]*, calc=0x[0-9a-f]*, len=[0-9]*' \$L; mv /var/log/omamobile/g7 /var/log/omamobile/g7-$1" diff --git a/tools/tegu-gnss/run-short.sh b/tools/tegu-gnss/run-short.sh new file mode 100755 index 0000000000..791817d18b --- /dev/null +++ b/tools/tegu-gnss/run-short.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# usage: run-case.sh NAME "GNSS_SPI_ARGS" (palmtop freshly booted) +cd ~/git/omarchy-mobile +until tools/phone-ssh --fresh true 2>/dev/null; do sleep 5; done +tools/phone-ssh "until [ \$(cut -d. -f1 /proc/uptime) -ge 60 ]; do sleep 2; done; systemd-run -q --unit=x-g7 -E GNSS_SPI_ARGS='$2' sh -c '/usr/local/bin/g7-short > /var/log/omamobile/g7-run.txt 2>&1'; sleep 30; dmesg | grep -iE 'feedback delay|cs_setup|usi3|hs:|realign'; while systemctl is-active -q x-g7; do sleep 10; done; L=/var/log/omamobile/g7/modem.log; for p in 'BAD checksum' 'ACK timeout' 'soft_dog pos' HARDFAULT 'RX RESET-ACK' 'RX packet len'; do printf '%s: ' \"\$p\"; grep -ac \"\$p\" \$L; done; grep -aiE 'svid|sv_id|C/N0|cn0' \$L | tail -3; grep -ao 'BAD checksum: footer=0x[0-9a-f]*, calc=0x[0-9a-f]*, len=[0-9]*' \$L; mv /var/log/omamobile/g7 /var/log/omamobile/g7-$1" From 268ba7f92bae280827b5bd18d42694ae61299c2b Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:29:07 -0647 Subject: [PATCH 30/36] Bring-up, not for merge: tools/tegu-gnss: the palmtop's g7-short, and run-short.sh's usage line g7-short on the palmtop was the fifth try's 240 s strace session writing to /var/log/omamobile/g7/, not g7-min; run-short.sh counts that directory, so it now ships the real script and names itself in its usage line. --- tools/tegu-gnss/README | 5 +++++ tools/tegu-gnss/g7-short | 41 ++++++++++++++++++++++++++++++++++++ tools/tegu-gnss/run-short.sh | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100755 tools/tegu-gnss/g7-short diff --git a/tools/tegu-gnss/README b/tools/tegu-gnss/README index b9a0dd7b55..027d3f2dba 100644 --- a/tools/tegu-gnss/README +++ b/tools/tegu-gnss/README @@ -45,3 +45,8 @@ Offline, on a saved strace (reads of /dev/gnss_ipc) or rx.txt: long.py the first three reads of 192 bytes or more, in 64-byte rows. xor.py footer against computed CRC of the "BAD checksum" lines. + +g7-short: the palmtop's own copy (recovered 2026-10-29): the fifth try's +240 s strace session, output in /var/log/omamobile/g7/, which is what +run-short.sh counts. g7-min is the later 12 s session with its own +directory; the two are different scripts. diff --git a/tools/tegu-gnss/g7-short b/tools/tegu-gnss/g7-short new file mode 100755 index 0000000000..3eb4108b78 --- /dev/null +++ b/tools/tegu-gnss/g7-short @@ -0,0 +1,41 @@ +#!/bin/bash +# G3, fifth try: strace gnssd across engine starts (observation only). +# Starts the modem with GNSS (once per boot), attaches strace to gnssd as +# soon as it runs, and records 240 s of its syscalls plus gnssd's own log. +# Stop condition: a modem not ONLINE, or the rails off. Afterwards the modem +# stays up (no stop by hand); the next try needs a reboot. +set -uo pipefail +L=/var/log/omamobile/modem.log +O=/var/log/omamobile/g7; mkdir -p "$O" +say() { printf 'g7: %s\n' "$*"; } +for n in gnss-core gnss-rf gnss-aux; do + r=$(grep -lx "$n" /sys/class/regulator/*/name 2>/dev/null | head -1) + [[ -n $r ]] || { say "STOP: no $n regulator"; exit 1; } + s=$(cat "$(dirname "$r")/state" 2>/dev/null) + say "$n: $s"; [[ $s == enabled ]] || { say "STOP: $n is $s"; exit 1; } +done +touch "$L"; start=$(wc -l < "$L") +/usr/local/bin/omamobile-tegu-modem-up --gnss || { say "STOP: modem not ONLINE"; exit 1; } +pid= +for _ in $(seq 1 120); do + pid=$(pgrep -x gnssd | head -1) && [[ -n $pid ]] && break + sleep 0.25 +done +[[ -n $pid ]] || { say "STOP: no gnssd"; exit 1; } +say "gnssd pid $pid" +timeout 75 strace -f -tt -T -yy -s 4096 -p "$pid" -o "$O/strace.txt" 2>"$O/strace.err" & +sp=$! +# the HAL and our client: a location request, so the engine starts +sleep 5 +systemd-run -q --unit=x-gnss-slsi -p KillMode=control-group sh -c \ + "OMAMOBILE_GNSS_NMEA_OUT=stdout /usr/lib/omamobile-vendor/omamobile-vendor-chroot gnss-slsi start > $O/gnss-slsi.log 2>&1" +for i in $(seq 1 15); do + sleep 5 + t=$(tail -n +"$((start + 1))" "$L") + hf=$(grep -c "HARDFAULT" <<<"$t"); nm=$(grep -c -E '\$G[PNL][A-Z]{3},' <<<"$t") + say "t=$((i * 5))s hardfaults=$hf nmea=$nm" +done +wait "$sp" 2>/dev/null +tail -n +"$((start + 1))" "$L" > "$O/modem.log" +journalctl -b --no-pager -o short-monotonic | grep -iE "gnss|kepler|cpif|ufshcd" > "$O/journal.txt" +say "strace lines $(wc -l < "$O/strace.txt"); output in $O" diff --git a/tools/tegu-gnss/run-short.sh b/tools/tegu-gnss/run-short.sh index 791817d18b..e89e6b9301 100755 --- a/tools/tegu-gnss/run-short.sh +++ b/tools/tegu-gnss/run-short.sh @@ -1,5 +1,5 @@ #!/bin/bash -# usage: run-case.sh NAME "GNSS_SPI_ARGS" (palmtop freshly booted) +# usage: run-short.sh NAME "GNSS_SPI_ARGS" (palmtop freshly booted; runs g7-short, counts /var/log/omamobile/g7) cd ~/git/omarchy-mobile until tools/phone-ssh --fresh true 2>/dev/null; do sleep 5; done tools/phone-ssh "until [ \$(cut -d. -f1 /proc/uptime) -ge 60 ]; do sleep 2; done; systemd-run -q --unit=x-g7 -E GNSS_SPI_ARGS='$2' sh -c '/usr/local/bin/g7-short > /var/log/omamobile/g7-run.txt 2>&1'; sleep 30; dmesg | grep -iE 'feedback delay|cs_setup|usi3|hs:|realign'; while systemctl is-active -q x-g7; do sleep 10; done; L=/var/log/omamobile/g7/modem.log; for p in 'BAD checksum' 'ACK timeout' 'soft_dog pos' HARDFAULT 'RX RESET-ACK' 'RX packet len'; do printf '%s: ' \"\$p\"; grep -ac \"\$p\" \$L; done; grep -aiE 'svid|sv_id|C/N0|cn0' \$L | tail -3; grep -ao 'BAD checksum: footer=0x[0-9a-f]*, calc=0x[0-9a-f]*, len=[0-9]*' \$L; mv /var/log/omamobile/g7 /var/log/omamobile/g7-$1" From 7218edbf57a4138610fa728b9a5a6e1a1fe151f5 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Thu, 29 Oct 2026 13:44:32 -0647 Subject: [PATCH 31/36] Bring-up, not for merge: spi: s3c64xx: Google's swap-mode for 16- and 32-bit words Stock drives the Pixel 9a's GNSS SPI with 32-bit words and the controller's own byte and half-word swap (SWAP_CFG, programmed by Google's spi-s3c64xx.c when the node has swap-mode), so the bytes land in memory in wire order. Mainline has no swap support and the night's 32-bit tries swapped in software. This adds the property and programs SWAP_CFG by word size as Google does, for G3-A's second step (32-bit words at stock's clock with the controller's swap). Compiles W=1 clean against the palmtop's tree; not booted. --- drivers/spi/spi-s3c64xx.c | 18 ++++++++++++++++++ include/linux/platform_data/spi-s3c64xx.h | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 870aae6592..abd927ee31 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -758,14 +758,26 @@ static int s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd) case 32: val |= S3C64XX_SPI_MODE_BUS_TSZ_WORD; val |= S3C64XX_SPI_MODE_CH_TSZ_WORD; + if (sdd->cntrlr_info->swap_mode) + writel(S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE | + S3C64XX_SPI_SWAP_TX_HALF_WORD | + S3C64XX_SPI_SWAP_RX_EN | S3C64XX_SPI_SWAP_RX_BYTE | + S3C64XX_SPI_SWAP_RX_HALF_WORD, + regs + S3C64XX_SPI_SWAP_CFG); break; case 16: val |= S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD; val |= S3C64XX_SPI_MODE_CH_TSZ_HALFWORD; + if (sdd->cntrlr_info->swap_mode) + writel(S3C64XX_SPI_SWAP_TX_EN | S3C64XX_SPI_SWAP_TX_BYTE | + S3C64XX_SPI_SWAP_RX_EN | S3C64XX_SPI_SWAP_RX_BYTE, + regs + S3C64XX_SPI_SWAP_CFG); break; default: val |= S3C64XX_SPI_MODE_BUS_TSZ_BYTE; val |= S3C64XX_SPI_MODE_CH_TSZ_BYTE; + if (sdd->cntrlr_info->swap_mode) + writel(0, regs + S3C64XX_SPI_SWAP_CFG); break; } @@ -1224,6 +1236,12 @@ static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev) sci->no_cs = of_property_read_bool(dev->of_node, "no-cs-readback"); sci->polling = !of_property_present(dev->of_node, "dmas"); + /* + * Bring-up (Pixel 9a GNSS): Google's "swap-mode" property, the + * controller's byte and half-word swap for 16- and 32-bit words, so + * the bytes land in memory in wire order as with 8-bit words. + */ + sci->swap_mode = of_property_read_bool(dev->of_node, "swap-mode"); return sci; } diff --git a/include/linux/platform_data/spi-s3c64xx.h b/include/linux/platform_data/spi-s3c64xx.h index f92bb4a121..b0de2401f3 100644 --- a/include/linux/platform_data/spi-s3c64xx.h +++ b/include/linux/platform_data/spi-s3c64xx.h @@ -38,6 +38,7 @@ struct s3c64xx_spi_info { int num_cs; bool no_cs; bool polling; + bool swap_mode; int (*cfg_gpio)(void); }; From 6556aaf61d8b2c963e23e42150d0ebbb7ccf79f4 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:54:50 -0647 Subject: [PATCH 32/36] Bring-up, not for merge: gnssif_spi: word32 sends 32-bit words with no software swap Stock drives the Pixel 9a's GNSS SPI with 32-bit words and the controller's own byte and half-word swap (SWAP_CFG), so the bytes reach the wire in memory order. Our 8-bit path, and the 32-bit tries that swapped each word in software, have never matched stock's framing. With word32=1 the transfers use 32-bit words and leave the swapping to a controller running with Google's swap-mode (the spi-s3c64xx change on this branch). Default off: nothing changes for the 8-bit path. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 168711b8ad..8e3fa75b23 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -27,12 +27,28 @@ * software (stock: the vendor driver's swap-mode), so the bytes go on the * wire in memory order. CHPP pads its frames to a multiple of 4. */ +/* + * omamobile test (G3-A2): word32=1 sends 32-bit words with no software + * swap, for a controller that does the swap itself (spi-s3c64xx with + * Google's swap-mode programmed in SWAP_CFG: bytes and half-words of each + * word swapped on TX and RX, so the bytes leave in memory order, as stock's + * vendor driver does). Default off: the 8-bit path is unchanged. + */ +static bool word32; +module_param(word32, bool, 0444); +MODULE_PARM_DESC(word32, "32-bit words, no software swap (the controller swaps)"); + +static inline unsigned int gnss_spi_bpw(void) +{ + return word32 ? 32 : SPI_BITS_PER_WORD; +} + static void gnss_spi_swab(void *buf, unsigned int size) { u32 *w = buf; unsigned int i; - if (SPI_BITS_PER_WORD != 32) + if (word32 || SPI_BITS_PER_WORD != 32) return; for (i = 0; i < size / 4; i++) @@ -225,7 +241,7 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) char *tmp = NULL; int ret; - if (SPI_BITS_PER_WORD == 32 && size % 4) + if (gnss_spi_bpw() == 32 && size % 4) return -EINVAL; if (tx) { tmp = kmemdup(tx, size, GFP_KERNEL); @@ -243,7 +259,7 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) t[i].len = min(GNSS_SPI_PIECE, size - off); t[i].tx_buf = tmp ? tmp + off : NULL; t[i].rx_buf = rx ? rx + off : NULL; - t[i].bits_per_word = SPI_BITS_PER_WORD; + t[i].bits_per_word = gnss_spi_bpw(); spi_message_add_tail(&t[i], &msg); } gnss_spi_hold_div(); From 370fb9d1074b77bef6d820be0f4f9a284a70a4a1 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 30 Oct 2026 16:47:57 -0643 Subject: [PATCH 33/36] Bring-up, not for merge: gnssif_spi: spi_mode overrides CPOL and CPHA For the G3-A3 clock-phase sweep: in G3-A2 the chip's replies arrived intact but shifted right by 2, 4 and 6 bits on successive reads, sampled out of step with SCK. spi_mode 0..3 sets the mode for every transfer before spi_setup in probe and logs the result; -1 keeps the device tree's. --- drivers/soc/google/gnssif_spi/gnss_spi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 8e3fa75b23..b5f6218e20 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -89,6 +89,14 @@ static int div = -1; /* rx_cpha=1: read-only transfers in SPI mode 1, writes stay in mode 0 */ static int rx_cpha; module_param(rx_cpha, int, 0444); +/* + * omamobile test (G3-A3): spi_mode 0..3 replaces the device tree's CPOL and + * CPHA for every transfer, for a clock-phase sweep (RX arrived 2, 4 and 6 + * bits late in G3-A2); -1 keeps the device tree's mode. + */ +static int spi_mode = -1; +module_param(spi_mode, int, 0444); +MODULE_PARM_DESC(spi_mode, "0..3: SPI mode (CPOL/CPHA) for all transfers; -1 keeps the DT's"); /* * realign=1: Kepler's data comes in exactly one bit late with feedback * delay 3 (MODEM-PLAN G3), so shift every received buffer left one bit. @@ -385,11 +393,16 @@ static int gnss_spi_probe(struct spi_device *spi) } if (speed_hz > 0) spi->max_speed_hz = speed_hz; + if (spi_mode >= 0 && spi_mode <= 3) + spi->mode = (spi->mode & ~(SPI_CPHA | SPI_CPOL)) | spi_mode; if (spi_setup(spi)) { gif_err("ERR! spi_setup fail\n"); ret = -EINVAL; goto err_setup; } + gif_info("spi mode 0x%x (CPOL %d, CPHA %d)%s\n", spi->mode, + !!(spi->mode & SPI_CPOL), !!(spi->mode & SPI_CPHA), + spi_mode >= 0 ? " from spi_mode" : ""); if (fb_delay >= 0 && spi->controller_data) { struct s3c64xx_spi_csinfo *cs = spi->controller_data; From 329e8f82562847530b1a79b383c4f914c81f494b Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 30 Oct 2026 17:46:40 -0643 Subject: [PATCH 34/36] Bring-up, not for merge: gnssif_spi: realign=4 carries the bit offset across reads --- drivers/soc/google/gnssif_spi/gnss_spi.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index b5f6218e20..0200093417 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -313,6 +313,30 @@ static int gnss_spi_xfer(const char *tx, char *rx, unsigned int size) } gnss_spi_shlk(rx, size, gnss_spi_k); } + if (rx && realign == 4 && ret >= 0 && !tx && size) { + /* + * realign=4: as 3, but carry across reads instead of dropping the + * last k bits: each output byte takes its high bits from the byte + * before it (the previous read's last raw byte for the first), so + * the stream stays continuous and byte-aligned, one byte later. + */ + static u8 prev; + u8 *b = rx; + int at = gnss_spi_preamble_k(b, size); + unsigned int i; + u8 last = b[size - 1]; + + if (at >= 0 && at != gnss_spi_k) { + gif_info("realign: Kepler bit offset %d -> %d\n", gnss_spi_k, at); + gnss_spi_k = at; + } + if (gnss_spi_k) { + for (i = size - 1; i > 0; i--) + b[i] = (b[i - 1] << gnss_spi_k) | (b[i] >> (8 - gnss_spi_k)); + b[0] = (prev << gnss_spi_k) | (b[0] >> (8 - gnss_spi_k)); + } + prev = last; + } if (rx && realign == 2 && ret >= 0) { int at = gnss_spi_preamble_at(rx, size); u8 first = ((u8 *)rx)[0] >> 7; From c4c673ac704d8a4f38d03963a50e6578a61fb891 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:08:47 -0643 Subject: [PATCH 35/36] spi: s3c64xx: turn the channels off before clearing the packet count s3c64xx_flush_fifo() cleared PACKET_CNT (and with it PACKET_CNT_EN) while RXCH_ON was still set. For that register write the controller clocks freely, and with automatic chip select the slave stays selected, so it shifts out bits that the flush then discards. A slave that streams across chip-select cycles, like the Pixel 9a's GNSS core over CHPP, loses a couple of bits per transfer: on the 9a every read arrived 0, 2, 4 or 6 bits off. Google's driver turns the channels off first; do the same. With this, the 9a's GNSS SPI in stock's configuration (mode 0, 32-bit words, swap mode, feedback delay 0, automatic chip select) reads every frame at bit 0 with a valid CRC, and the receiver gets a fix. Also adds the bring-up overlay that gives the GNSS SPI's pins (gpp22-0..3) function 2 and drive 3: without a pinctrl the bus ran on the bootloader's drive 0. --- .../google/zumapro-tegu-gnss-spi-pins.dtso | 30 +++++++++++++++++++ drivers/spi/spi-s3c64xx.c | 9 ++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-pins.dtso diff --git a/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-pins.dtso b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-pins.dtso new file mode 100644 index 0000000000..26f9c5019e --- /dev/null +++ b/arch/arm64/boot/dts/exynos/google/zumapro-tegu-gnss-spi-pins.dtso @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; +/plugin/; + +/* + * Pixel 9a bring-up only (MODEM-PLAN G3-A4): the GNSS SPI's pins in the + * device tree. Our SPI21 node has no pinctrl, so the bus runs on the + * bootloader's pin state: gpp22-0..3 in function 2 at drive 0, gpp22-2 + * pulled down. This gives them function 2 and drive 3 (as gpp21, the + * other SPI bus on PERIC1), keeping the pulls as found. + */ +&pinctrl_peric1 { + gnss_spi_pins: gnss-spi-pins { + samsung,pins = "gpp22-0", "gpp22-1", "gpp22-3"; + samsung,pin-function = <2>; + samsung,pin-pud = <0>; + samsung,pin-drv = <3>; + }; + gnss_spi_miso: gnss-spi-miso-pins { + samsung,pins = "gpp22-2"; + samsung,pin-function = <2>; + samsung,pin-pud = <1>; + samsung,pin-drv = <3>; + }; +}; + +&spi21 { + pinctrl-names = "default"; + pinctrl-0 = <&gnss_spi_pins &gnss_spi_miso>; +}; diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index abd927ee31..9388e9d693 100644 --- a/drivers/spi/spi-s3c64xx.c +++ b/drivers/spi/spi-s3c64xx.c @@ -235,12 +235,17 @@ static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd) unsigned long loops; u32 val; - writel(0, regs + S3C64XX_SPI_PACKET_CNT); - val = readl(regs + S3C64XX_SPI_CH_CFG); val &= ~(S3C64XX_SPI_CH_RXCH_ON | S3C64XX_SPI_CH_TXCH_ON); writel(val, regs + S3C64XX_SPI_CH_CFG); + /* + * Clear the count only with the channels off, as Google's driver does: + * with RXCH_ON set and PACKET_CNT_EN cleared the controller clocks + * freely, and with automatic chip select the slave sees those edges. + */ + writel(0, regs + S3C64XX_SPI_PACKET_CNT); + val = readl(regs + S3C64XX_SPI_CH_CFG); val |= S3C64XX_SPI_CH_SW_RST; val &= ~S3C64XX_SPI_CH_HS_EN; From 77c05f405131a6277f1c47a2d5441f8d5d180026 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Fri, 30 Oct 2026 19:15:19 -0643 Subject: [PATCH 36/36] Bring-up, not for merge: gnssif_spi: word32=2 swaps the bytes in software --- drivers/soc/google/gnssif_spi/gnss_spi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/soc/google/gnssif_spi/gnss_spi.c b/drivers/soc/google/gnssif_spi/gnss_spi.c index 0200093417..b8242aef29 100644 --- a/drivers/soc/google/gnssif_spi/gnss_spi.c +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -34,9 +34,13 @@ * word swapped on TX and RX, so the bytes leave in memory order, as stock's * vendor driver does). Default off: the 8-bit path is unchanged. */ -static bool word32; -module_param(word32, bool, 0444); -MODULE_PARM_DESC(word32, "32-bit words, no software swap (the controller swaps)"); +/* + * word32=2: 32-bit words with the byte swap done here (swab32 on TX and RX), + * for a controller without swap-mode: tests whether the DT property is needed. + */ +static int word32; +module_param(word32, int, 0444); +MODULE_PARM_DESC(word32, "1: 32-bit words, the controller swaps; 2: 32-bit words, swapped in software"); static inline unsigned int gnss_spi_bpw(void) { @@ -48,7 +52,7 @@ static void gnss_spi_swab(void *buf, unsigned int size) u32 *w = buf; unsigned int i; - if (word32 || SPI_BITS_PER_WORD != 32) + if (word32 == 1 || (word32 != 2 && SPI_BITS_PER_WORD != 32)) return; for (i = 0; i < size / 4; i++)