aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorPeng Fan <peng.fan@nxp.com>2017-12-11 13:18:36 +0800
committerSilvano di Ninno <silvano.dininno@nxp.com>2018-08-02 15:37:22 +0200
commit2737e479a9352be8f0e9eacdc9ab26323a525810 (patch)
treef53ad1479b345d99870d1592a049233cb84a59d1 /core
parent3076b1fcb20f3daae4c50258f0b645d82092ba33 (diff)
drivers: imx_lpuart: add i.MX lpuart driver
add new lpuart driver This driver is used by the i.MX 7ulp SoC Signed-off-by: Peng Fan <peng.fan@nxp.com>
Diffstat (limited to 'core')
-rw-r--r--core/drivers/imx_lpuart.c73
-rw-r--r--core/drivers/sub.mk1
-rw-r--r--core/include/drivers/imx_lpuart.h19
3 files changed, 93 insertions, 0 deletions
diff --git a/core/drivers/imx_lpuart.c b/core/drivers/imx_lpuart.c
new file mode 100644
index 00000000..8997bb49
--- /dev/null
+++ b/core/drivers/imx_lpuart.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright 2017-2018 NXP
+ *
+ */
+
+#include <assert.h>
+#include <drivers/imx_lpuart.h>
+#include <io.h>
+#include <keep.h>
+#include <util.h>
+
+#define STAT 0x14
+#define DATA 0x1C
+#define STAT_TDRE BIT(23)
+#define STAT_RDRF BIT(21)
+#define STAT_OR BIT(19)
+
+static vaddr_t chip_to_base(struct serial_chip *chip)
+{
+ struct imx_lpuart_data *pd =
+ container_of(chip, struct imx_lpuart_data, chip);
+
+ return io_pa_or_va(&pd->base);
+}
+
+static void imx_lpuart_flush(struct serial_chip *chip __unused)
+{
+
+}
+
+static int imx_lpuart_getchar(struct serial_chip *chip)
+{
+ int ch;
+ vaddr_t base = chip_to_base(chip);
+
+ while (read32(base + STAT) & STAT_RDRF)
+ ;
+
+ ch = (read32(base + DATA) & 0x3ff);
+
+ if (read32(base + STAT) & STAT_OR)
+ write32(base + STAT, STAT_OR);
+
+ return ch;
+}
+
+static void imx_lpuart_putc(struct serial_chip *chip, int ch)
+{
+ vaddr_t base = chip_to_base(chip);
+
+ while (!(read32(base + STAT) & STAT_TDRE))
+ __asm__ __volatile__("" : : : "memory");
+ write32(ch, base + DATA);
+}
+
+static const struct serial_ops imx_lpuart_ops = {
+ .flush = imx_lpuart_flush,
+ .getchar = imx_lpuart_getchar,
+ .putc = imx_lpuart_putc,
+};
+KEEP_PAGER(imx_lpuart_ops);
+
+void imx_lpuart_init(struct imx_lpuart_data *pd, paddr_t base)
+{
+ pd->base.pa = base;
+ pd->chip.ops = &imx_lpuart_ops;
+
+ /*
+ * Do nothing, debug uart(sc lpuart) share with normal world,
+ * everything for uart0 intialization is done in scfw.
+ */
+}
diff --git a/core/drivers/sub.mk b/core/drivers/sub.mk
index ac058155..6ae44875 100644
--- a/core/drivers/sub.mk
+++ b/core/drivers/sub.mk
@@ -11,6 +11,7 @@ srcs-$(CFG_8250_UART) += serial8250_uart.c
srcs-$(CFG_16550_UART) += ns16550.c
srcs-$(CFG_IMX_SNVS) += imx_snvs.c
srcs-$(CFG_IMX_UART) += imx_uart.c
+srcs-$(CFG_IMX_LPUART) += imx_lpuart.c
srcs-$(CFG_IMX_WDOG) += imx_wdog.c
cflags-imx_wdog.c-y += -Wno-suggest-attribute=noreturn
srcs-$(CFG_SPRD_UART) += sprd_uart.c
diff --git a/core/include/drivers/imx_lpuart.h b/core/include/drivers/imx_lpuart.h
new file mode 100644
index 00000000..8048fcd9
--- /dev/null
+++ b/core/include/drivers/imx_lpuart.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+/*
+ * Copyright 2017-2018 NXP
+ *
+ */
+#ifndef IMX_LPUART_H
+#define IMX_LPUART_H
+
+#include <types_ext.h>
+#include <drivers/serial.h>
+
+struct imx_lpuart_data {
+ struct io_pa_va base;
+ struct serial_chip chip;
+};
+
+void imx_lpuart_init(struct imx_lpuart_data *pd, paddr_t base);
+
+#endif /* IMX_LPUART_H */