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-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/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"; +}; 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..ac540ef697 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -0,0 +1,263 @@ +// 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) +{ + /* 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, + 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; + unsigned int xfer; + char *tx; + 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; + } + + /* + * 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, xfer); + + 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(tx, xfer, (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: + kfree(tx); + 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..b8242aef29 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -0,0 +1,517 @@ +// 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 "include/gnss.h" +#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. + */ +/* + * 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. + */ +/* + * 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) +{ + return word32 ? 32 : SPI_BITS_PER_WORD; +} + +static void gnss_spi_swab(void *buf, unsigned int size) +{ + u32 *w = buf; + unsigned int i; + + if (word32 == 1 || (word32 != 2 && SPI_BITS_PER_WORD != 32)) + return; + + 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. + */ +/* 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; +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); +/* 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); +/* + * 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. + */ +static int realign; +module_param(realign, int, 0444); + +/* + * 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; +/* + * 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); +/* 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); +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) +{ + 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) +{ + unsigned int i; + + 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; + } + return -1; +} + +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; + +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) +{ + 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); +/* 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) +{ + 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 (gnss_spi_bpw() == 32 && 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) { + 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 = tmp ? tmp + off : NULL; + t[i].rx_buf = rx ? rx + off : NULL; + t[i].bits_per_word = gnss_spi_bpw(); + 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 (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) { + /* + * 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(); + { + static bool once; + + if (!once) { + once = true; + gnss_spi_cmu_div(); + } + } + 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 == 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; + + 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; + 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); + kfree(tmp); + 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); + +int gnss_spi_recv(char *buff, unsigned int size) +{ + return gnss_spi_xfer(NULL, buff, size); +} +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); + + gnss_spi_cmu(); + 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; + 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; + + 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_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; + 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"); + + 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__ */ diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index 1a5dfdc978..f5f093a9b0 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -75,4 +75,24 @@ 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. + +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 636a762608..35f97eb445 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -14,3 +14,6 @@ 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 +obj-$(CONFIG_TEGU_PDMA_RT) += tegu-pdma-rt.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"); 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)"); diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c index 870aae6592..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; @@ -758,14 +763,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 +1241,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); }; diff --git a/tools/tegu-gnss/README b/tools/tegu-gnss/README new file mode 100644 index 0000000000..027d3f2dba --- /dev/null +++ b/tools/tegu-gnss/README @@ -0,0 +1,52 @@ +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. + +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-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-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/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..e89e6b9301 --- /dev/null +++ b/tools/tegu-gnss/run-short.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# 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"