diff --git a/Documentation/devicetree/bindings/gnss/samsung,exynos-gnss.yaml b/Documentation/devicetree/bindings/gnss/samsung,exynos-gnss.yaml new file mode 100644 index 0000000000..6051df2eeb --- /dev/null +++ b/Documentation/devicetree/bindings/gnss/samsung,exynos-gnss.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gnss/samsung,exynos-gnss.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung Kepler GNSS core, handshake lines + +maintainers: + - W4HO <87742609+W4HO-ham@users.noreply.github.com> + +description: | + The control side of the Kepler GNSS core's SPI link (samsung,gnss-spi): + two lines between the core and the host that pace the transfers. The + core raises its line while it has data for the host, and to answer the + host's request to write. The host raises its line to ask to write, and + pulses it to acknowledge the core's request before reading. The node has + no registers, clocks or supplies of its own. + +properties: + compatible: + const: samsung,exynos-gnss + + gnss2ap-spi-gpios: + maxItems: 1 + description: + Core to host request line, active high. It is also the host's + interrupt, so its GPIO controller must be able to raise one. + + ap2gnss-spi-gpios: + maxItems: 1 + description: + Host to core request line, active high. Low when the host is idle. + +required: + - compatible + - gnss2ap-spi-gpios + - ap2gnss-spi-gpios + +additionalProperties: false + +examples: + - | + #include + + gnss { + compatible = "samsung,exynos-gnss"; + gnss2ap-spi-gpios = <&gpa5 4 GPIO_ACTIVE_HIGH>; + ap2gnss-spi-gpios = <&gpp2 3 GPIO_ACTIVE_HIGH>; + }; diff --git a/Documentation/devicetree/bindings/gnss/samsung,gnss-spi.yaml b/Documentation/devicetree/bindings/gnss/samsung,gnss-spi.yaml new file mode 100644 index 0000000000..75939d415b --- /dev/null +++ b/Documentation/devicetree/bindings/gnss/samsung,gnss-spi.yaml @@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gnss/samsung,gnss-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Samsung Kepler GNSS core, SPI data link + +maintainers: + - W4HO <87742609+W4HO-ham@users.noreply.github.com> + +description: | + Samsung's Kepler GNSS core is part of the S5300 modem in the Google + Pixel 9a. It runs firmware that the host loads into the modem's shared + memory, and it exchanges its data with the host over an SPI bus of the + application processor (USI3 of HSI0 on Tensor G4), in blocks of 64 + bytes. The core and its supplies belong to the modem; this node is only + the SPI device. The two lines that pace the transfers are described by + a samsung,exynos-gnss node. + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: samsung,gnss-spi + + reg: + maxItems: 1 + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + spi { + #address-cells = <1>; + #size-cells = <0>; + + gnss@0 { + compatible = "samsung,gnss-spi"; + reg = <0>; + spi-max-frequency = <3125000>; + + controller-data { + samsung,spi-feedback-delay = <0>; + }; + }; + }; diff --git a/drivers/soc/google/Kconfig b/drivers/soc/google/Kconfig index f4dd87cb8c..7fb05aefa5 100644 --- a/drivers/soc/google/Kconfig +++ b/drivers/soc/google/Kconfig @@ -95,6 +95,7 @@ config GS201_AOC_ALSA limits in device/cheetah/AUDIO-PLAN.md. source "drivers/soc/google/cpif/Kconfig" +source "drivers/soc/google/gnssif_spi/Kconfig" endmenu diff --git a/drivers/soc/google/Makefile b/drivers/soc/google/Makefile index db9ae79805..3cf5691f67 100644 --- a/drivers/soc/google/Makefile +++ b/drivers/soc/google/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_GS201_AOC_RAILS) += gs201-aoc-rails.o obj-$(CONFIG_GS201_CAM_POWER) += gs201-cam-power.o obj-y += aoc/ obj-y += cpif/ +obj-$(CONFIG_EXYNOS_GNSS_IF_SPI) += gnssif_spi/ diff --git a/drivers/soc/google/gnssif_spi/Kconfig b/drivers/soc/google/gnssif_spi/Kconfig new file mode 100644 index 0000000000..22432974fa --- /dev/null +++ b/drivers/soc/google/gnssif_spi/Kconfig @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +config EXYNOS_GNSS_IF_SPI + tristate "Samsung Kepler GNSS interface over SPI" + depends on SPI && GPIOLIB && OF + select WANT_DEV_COREDUMP + help + Google's driver for the Kepler GNSS core in Samsung's S5300 modem, + as in the Pixel 9a. gnss_spi binds the core's SPI device, and + gnssif binds its two request lines and gives the GNSS daemon the + character device /dev/gnss_ipc. The core runs only while the modem + is up, with firmware the daemon loads through the modem driver. + + To compile this driver as modules, choose M here: the modules will + be called gnss_spi and gnssif. 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..deafeacf2a --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_io_device.c @@ -0,0 +1,288 @@ +// 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; + + mutex_lock(&iod->open_lock); + ref_cnt = atomic_inc_return(&iod->opened); + if (ref_cnt == 1) + gnss_ctl_irq_on(iod->gc); + mutex_unlock(&iod->open_lock); + + 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; + + mutex_lock(&iod->open_lock); + ref_cnt = atomic_dec_return(&iod->opened); + if (ref_cnt == 0) { + gnss_ctl_irq_off(iod->gc); + skb_queue_purge(&iod->sk_rx_q); + } + mutex_unlock(&iod->open_lock); + + gif_info("%s (opened %d)\n", iod->name, ref_cnt); + + return 0; +} + +static __poll_t 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 EPOLLIN | EPOLLRDNORM; + + 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 %zu)\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 %zu)\n", + iod->name, ld->name, ret, count); + kfree(buff); + return ret; + } + + kfree(buff); + return count; +} + +static ssize_t misc_read(struct file *filp, char __user *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 void gnss_wlock_unregister(void *data) +{ + gnssif_wlock_unregister(data); +} + +static void gnss_misc_deregister(void *data) +{ + struct io_device *iod = data; + + misc_deregister(&iod->miscdev); + skb_queue_purge(&iod->sk_rx_q); +} + +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); + mutex_init(&iod->open_lock); + + 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 = devm_add_action_or_reset(dev, gnss_wlock_unregister, iod->ws); + if (ret) + return ret; + + ret = misc_register(&iod->miscdev); + if (ret) { + gif_err("%s: ERR! misc_register failed\n", iod->name); + return ret; + } + ret = devm_add_action_or_reset(dev, gnss_misc_deregister, iod); + if (ret) + return ret; + + gif_info("---\n"); + + return 0; +} + +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 ERR_PTR(-ENOMEM); + } + + 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) { + gif_err("init_io_device fail (%d)\n", ret); + return ERR_PTR(ret); + } + + 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..a2a216d0d4 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_keplerctl_device.c @@ -0,0 +1,168 @@ +// 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); +} + +/* + * Take the core's requests only while /dev/gnss_ipc is open: what it + * sends with nobody listening is thrown away at the last release anyway, + * and a request line that rises while the modem is off or starting can't + * set the read work going. + */ +void gnss_ctl_irq_on(struct gnss_ctl *gc) +{ + int ret; + + /* Without a wake source GNSS still works; it can't wake the AP. */ + ret = enable_irq_wake(gc->irq_gnss2ap_spi.num); + if (ret) + gif_err("Failed to enable wakeup_source - enable_irq_wake(%d)\n", ret); + else + gc->irq_wake = true; + + gif_enable_irq(&gc->irq_gnss2ap_spi); +} + +void gnss_ctl_irq_off(struct gnss_ctl *gc) +{ + struct link_device *ld = gc->iod->ld; + + /* The read work enables the interrupt again when it ends. */ + gif_disable_irq_sync(&gc->irq_gnss2ap_spi); + cancel_delayed_work_sync(&ld->rx_dwork); + gif_disable_irq_sync(&gc->irq_gnss2ap_spi); + + if (gc->irq_wake) { + disable_irq_wake(gc->irq_gnss2ap_spi.num); + gc->irq_wake = false; + } +} + +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); + + /* GNSS2AP SPI INT */ + 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!\n"); + return PTR_ERR(gc->gpio_gnss2ap_spi.desc); + } + ret = gpiod_to_irq(gc->gpio_gnss2ap_spi.desc); + if (ret < 0) { + gif_err("gnss2ap-spi-gpios has no interrupt (%d)\n", ret); + return ret; + } + gc->irq_gnss2ap_spi.num = ret; + + /* Disabled until /dev/gnss_ipc is opened */ + 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->dev, &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; + } + + /* The line starts low, as Google's driver sets it. */ + 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); + return ret; + } + + 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; +} + +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 ERR_PTR(-ENOMEM); + 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); + return ERR_PTR(ret); + } + + 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..1d402ffba6 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_link_device.c @@ -0,0 +1,245 @@ +// 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 ERR_PTR(-EINVAL); + } + + ld = devm_kzalloc(dev, sizeof(struct link_device), GFP_KERNEL); + if (!ld) { + gif_err("ERR! link device kzalloc fail\n"); + return ERR_PTR(-ENOMEM); + } + + 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; + + /* Google's: unbound, one work item at a time */ + ld->rx_wq = devm_alloc_ordered_workqueue(dev, "gnss_spi_wq", WQ_MEM_RECLAIM); + if (!ld->rx_wq) { + gif_err("alloc_workqueue() error\n"); + return ERR_PTR(-ENOMEM); + } + INIT_DELAYED_WORK(&ld->rx_dwork, rx_work); + + gif_info("---\n"); + + 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..5db532baf6 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_main.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gnss_prj.h" +#include "gnss_spi.h" +#include "gnss_utils.h" + +/* Hand a dump to devcoredump, which frees it. */ +static void gnss_set_coredump(struct device *dev, void *dump, size_t len, + const char *reason) +{ + gif_err("GNSS coredump: %s (%zu bytes)\n", reason, len); + dev_coredumpv(dev, dump, len, GFP_KERNEL); +} + +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; + 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 = vmalloc(length); + if (!coredump) { + gif_err("Allocate crash coredump failed\n"); + goto clean; + } + memcpy(coredump, next + 1, length); + gnss_set_coredump(dev, coredump, length, reason); + coredump = NULL; + } +clean: + kfree(reason); + vfree(coredump); + return count; +} + +static DEVICE_ATTR_WO(coredump); + +static struct attribute *gnss_attrs[] = { + &dev_attr_coredump.attr, + NULL +}; +ATTRIBUTE_GROUPS(gnss); + +static int parse_dt_common_pdata(struct device_node *np, struct gnss_pdata *pdata) +{ + /* + * Google's device tree names these in device,name and + * device_node_name. They describe no hardware, and the GNSS daemon + * opens /dev/gnss_ipc, so they are fixed here. + */ + pdata->name = "KEPLER"; + pdata->node_name = "gnss_ipc"; + + 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); + + /* + * Nobody holds /dev/gnss_ipc open (it pins the module), so the + * interrupt is off already; devm releases the device node, the work + * queue and the interrupt. + */ + gif_disable_irq_sync(&gc->irq_gnss2ap_spi); + + gpiod_set_value(gc->gpio_ap2gnss_spi.desc, 0); +} + +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"); + return -ENODEV; + } + + /* + * The core's requests are read over gnss_spi: without its device + * the read work would find nothing to read from while the request + * line stays high. + */ + if (!gnss_spi_bound()) + return dev_err_probe(dev, -EPROBE_DEFER, "no GNSS SPI device yet\n"); + + pdata = gnss_if_parse_dt_pdata(dev); + if (IS_ERR(pdata)) { + gif_err("DT parse error!\n"); + return PTR_ERR(pdata); + } + + /* The lines' controller may come later: keep -EPROBE_DEFER. */ + gc = create_ctl_device(pdev); + if (IS_ERR(gc)) + return dev_err_probe(dev, PTR_ERR(gc), "%s: Could not create gc\n", + pdata->name); + + ld = create_link_device(pdev); + if (IS_ERR(ld)) + return dev_err_probe(dev, PTR_ERR(ld), "%s: Could not create ld\n", + pdata->name); + + ld->gc = gc; + + iod = create_io_device(pdev, ld, gc, pdata); + if (IS_ERR(iod)) + return dev_err_probe(dev, PTR_ERR(iod), "%s: Could not create iod\n", + pdata->name); + + platform_set_drvdata(pdev, gc); + + gif_info("%s: ---\n", pdev->name); + + return 0; +} + +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", + .dev_groups = gnss_groups, + /* gnssd may hold the device node open */ + .suppress_bind_attrs = true, +#if IS_ENABLED(CONFIG_OF) + .of_match_table = of_match_ptr(gnss_dt_match), +#endif + }, +}; + +module_platform_driver(gnss_driver); + +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..2aefdeea9a --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_prj.h @@ -0,0 +1,82 @@ +/* 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 "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; + struct mutex open_lock; /* the first open and the last release */ + 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; + bool irq_wake; +}; + +struct gnss_ctl *create_ctl_device(struct platform_device *pdev); +void gnss_ctl_irq_on(struct gnss_ctl *gc); +void gnss_ctl_irq_off(struct gnss_ctl *gc); +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..8e47f1315a --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_spi.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Samsung Electronics. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/gnss.h" +#include "gnss_spi.h" + +static struct gnss_spi gnss_if; + +/* gnssif binds only once the SPI device is there. */ +bool gnss_spi_bound(void) +{ + return !!READ_ONCE(gnss_if.spi); +} +EXPORT_SYMBOL_GPL(gnss_spi_bound); + +/* + * Swap the bytes of each 32-bit word. Google's SPI controller driver + * sends GNSS's 32-bit words in its swap mode (swap-mode in the board's + * device tree: bytes and half-words swapped on TX and RX), which puts + * them on the wire in memory order. spi-s3c64xx has no swap mode and + * shifts each word out most significant byte first, so swap here. + */ +static void gnss_spi_swab(char *buf, unsigned int size) +{ + u32 *w = (u32 *)buf; + unsigned int i; + + for (i = 0; i < size / 4; i++) + w[i] = swab32(w[i]); +} + +/* + * One message of transfers of GNSS_SPI_BLOCK bytes at most. The core's + * data comes in 64-byte blocks, and Google's driver reads one block per + * transfer. spi-s3c64xx moves a transfer that fills its 64-byte FIFO in + * one piece, but cuts a longer one into 60-byte pieces, and on the Pixel + * 9a the cuts lost data; so writes go in blocks too. + */ +static int gnss_spi_xfer(char *tx_buf, char *rx_buf, unsigned int size) +{ + unsigned int n = DIV_ROUND_UP(size, GNSS_SPI_BLOCK); + struct spi_transfer *t; + struct spi_message msg; + unsigned int i, off; + int ret; + + if (!gnss_spi_bound()) + return -ENODEV; + if (!size || size % sizeof(u32)) + return -EINVAL; + + t = kcalloc(n, sizeof(*t), GFP_KERNEL); + if (!t) + return -ENOMEM; + + if (tx_buf) + gnss_spi_swab(tx_buf, size); + + spi_message_init(&msg); + for (i = 0, off = 0; i < n; i++, off += GNSS_SPI_BLOCK) { + t[i].len = min(size - off, GNSS_SPI_BLOCK); + t[i].tx_buf = tx_buf ? tx_buf + off : NULL; + t[i].rx_buf = rx_buf ? rx_buf + 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); + + /* Give the caller its buffer back as it was. */ + if (tx_buf) + gnss_spi_swab(tx_buf, size); + if (rx_buf && !ret) + gnss_spi_swab(rx_buf, size); + + kfree(t); + + return ret; +} + +int gnss_spi_send(char *buff, unsigned int size, char *rx_buff) +{ + return gnss_spi_xfer(buff, rx_buff, size); +} +EXPORT_SYMBOL_GPL(gnss_spi_send); + +int gnss_spi_recv(char *buff, unsigned int size) +{ + return gnss_spi_xfer(NULL, buff, size); +} +EXPORT_SYMBOL_GPL(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); + WRITE_ONCE(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); + + WRITE_ONCE(gnss_if->spi, NULL); + 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 const struct spi_device_id gnss_spi_ids[] = { + { "gnss-spi" }, + { } +}; +MODULE_DEVICE_TABLE(spi, gnss_spi_ids); + +static struct spi_driver gnss_spi_driver = { + .id_table = gnss_spi_ids, + .probe = gnss_spi_probe, + .remove = gnss_spi_remove, + .driver = { + .name = "gnss_spi", + .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..e10067c0b6 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_spi.h @@ -0,0 +1,29 @@ +/* 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 +#define SPI_BITS_PER_WORD 32 +/* the core's block, and the FIFO depth of the SPI controller it is on */ +#define GNSS_SPI_BLOCK 64U + +struct gnss_spi { + struct spi_device *spi; + struct mutex lock; +}; + +bool gnss_spi_bound(void); +int gnss_spi_send(char *buff, unsigned int size, char *recv_buff); +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..36499d30c3 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_utils.c @@ -0,0 +1,108 @@ +// 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 device *dev, struct gnss_irq *irq, irq_handler_t isr, + void *data) +{ + int ret; + + ret = devm_request_irq(dev, 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) +{ + unsigned long flags; + + if (irq->registered == false) + return; + + spin_lock_irqsave(&irq->lock, flags); + + if (!irq->active) { + spin_unlock_irqrestore(&irq->lock, flags); + gif_debug("%s(#%d) is not active <%ps>\n", + irq->name, irq->num, CALLER); + return; + } + + spin_unlock_irqrestore(&irq->lock, flags); + + disable_irq(irq->num); + + spin_lock_irqsave(&irq->lock, flags); + irq->active = false; + spin_unlock_irqrestore(&irq->lock, flags); + + 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..7b089e4e08 --- /dev/null +++ b/drivers/soc/google/gnssif_spi/gnss_utils.h @@ -0,0 +1,85 @@ +/* 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 device *dev, 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..ccbd91faad --- /dev/null +++ b/drivers/soc/google/gnssif_spi/include/gnss.h @@ -0,0 +1,54 @@ +/* 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; + const char *label; +}; + +#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__) + +#endif /* __GNSS_IF_H__ */