summaryrefslogtreecommitdiff
path: root/drivers/serial
diff options
context:
space:
mode:
authorAbel Vesa <abel.vesa@nxp.com>2018-08-02 18:57:56 +0300
committerTeo Hall <teo.hall@nxp.com>2018-08-09 15:14:28 -0500
commit7586aa50fdb4144ddcd79a75c4ed2510fa8ee753 (patch)
tree30490b2e1e9bae69d867dc23b823f573c1dbf82f /drivers/serial
parentfacc02d13a3f806a1fa8db37b26994ec027171a1 (diff)
MLK-19183-1 iMX8QXP SPL: serial_lpuart: Add non DM serial device
In case CONFIG_DM is not enabled, the driver needs to be initialized through serial_initfunc. All the ops are implemented again this time using the lpuart_serial_data. Signed-off-by: Abel Vesa <abel.vesa@nxp.com>
Diffstat (limited to 'drivers/serial')
-rw-r--r--drivers/serial/serial.c2
-rw-r--r--drivers/serial/serial_lpuart.c162
2 files changed, 132 insertions, 32 deletions
diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index fc18906c62..1ef27ca4b2 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -136,6 +136,7 @@ serial_initfunc(ml2_serial_initialize);
serial_initfunc(mpc85xx_serial_initialize);
serial_initfunc(mpc8xx_serial_initialize);
serial_initfunc(mxc_serial_initialize);
+serial_initfunc(serial_lpuart_initialize);
serial_initfunc(mxs_auart_initialize);
serial_initfunc(ns16550_serial_initialize);
serial_initfunc(oc_serial_initialize);
@@ -224,6 +225,7 @@ void serial_initialize(void)
mpc85xx_serial_initialize();
mpc8xx_serial_initialize();
mxc_serial_initialize();
+ serial_lpuart_initialize();
mxs_auart_initialize();
ns16550_serial_initialize();
oc_serial_initialize();
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index b5b1d5af0c..23f8fb8f97 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -101,13 +101,6 @@ u32 __weak get_lpuart_clk(void)
return CONFIG_SYS_CLK_FREQ;
}
-static bool is_lpuart32(struct udevice *dev)
-{
- struct lpuart_serial_platdata *plat = dev->platdata;
-
- return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG;
-}
-
static void _lpuart_serial_setbrg(struct lpuart_serial_platdata *plat,
int baudrate)
{
@@ -144,17 +137,6 @@ static void _lpuart_serial_putc(struct lpuart_serial_platdata *plat,
__raw_writeb(c, &base->ud);
}
-/* Test whether a character is in the RX buffer */
-static int _lpuart_serial_tstc(struct lpuart_serial_platdata *plat)
-{
- struct lpuart_fsl *base = plat->reg;
-
- if (__raw_readb(&base->urcfifo) == 0)
- return 0;
-
- return 1;
-}
-
/*
* Initialise the serial port with the given baudrate. The settings
* are always 8 data bits, no parity, 1 stop bit, no start bits.
@@ -300,20 +282,6 @@ static void _lpuart32_serial_putc(struct lpuart_serial_platdata *plat,
lpuart_write32(plat->flags, &base->data, c);
}
-/* Test whether a character is in the RX buffer */
-static int _lpuart32_serial_tstc(struct lpuart_serial_platdata *plat)
-{
- struct lpuart_fsl_reg32 *base = plat->reg;
- u32 water;
-
- lpuart_read32(plat->flags, &base->water, &water);
-
- if ((water >> 24) == 0)
- return 0;
-
- return 1;
-}
-
/*
* Initialise the serial port with the given baudrate. The settings
* are always 8 data bits, no parity, 1 stop bit, no start bits.
@@ -355,6 +323,133 @@ static int _lpuart32_serial_init(struct lpuart_serial_platdata *plat)
return 0;
}
+#ifndef CONFIG_DM_SERIAL
+
+#ifndef CONFIG_SERIAL_LPUART_BASE
+#error "define CONFIG_SERIAL_LPUART_BASE to use the MXC UART driver"
+#endif
+
+#define lpuart_base ((struct mxc_uart *)CONFIG_SERIAL_LPUART_BASE)
+
+struct lpuart_serial_platdata lpuart_serial_data = {
+ .reg = lpuart_base,
+ .devtype = DEV_IMX8,
+ .flags = LPUART_FLAG_REGMAP_32BIT_REG,
+};
+
+static void serial_lpuart_setbrg(void)
+{
+ struct lpuart_serial_platdata *plat = &lpuart_serial_data;
+
+ if (plat->flags & LPUART_FLAG_REGMAP_32BIT_REG) {
+ if (plat->devtype == DEV_MX7ULP || plat->devtype == DEV_IMX8)
+ _lpuart32_serial_setbrg_7ulp(plat, gd->baudrate);
+ else
+ _lpuart32_serial_setbrg(plat, gd->baudrate);
+ } else {
+ _lpuart_serial_setbrg(plat, gd->baudrate);
+ }
+
+}
+
+static int serial_lpuart_init(void)
+{
+ struct lpuart_serial_platdata *plat = &lpuart_serial_data;
+
+ if (plat->flags & LPUART_FLAG_REGMAP_32BIT_REG)
+ return _lpuart32_serial_init(plat);
+ else
+ return _lpuart_serial_init(plat);
+
+ return 0;
+}
+
+static int serial_lpuart_getc(void)
+{
+ struct lpuart_serial_platdata *plat = &lpuart_serial_data;
+
+ if (plat->flags & LPUART_FLAG_REGMAP_32BIT_REG)
+ return _lpuart32_serial_getc(plat);
+
+ return _lpuart_serial_getc(plat);
+}
+
+static void serial_lpuart_putc(const char c)
+{
+ struct lpuart_serial_platdata *plat = &lpuart_serial_data;
+
+ if (plat->flags & LPUART_FLAG_REGMAP_32BIT_REG)
+ _lpuart32_serial_putc(plat, c);
+ else
+ _lpuart_serial_putc(plat, c);
+}
+
+static int serial_lpuart_tstc(void)
+{
+ struct lpuart_serial_platdata *plat = &lpuart_serial_data;
+ struct lpuart_fsl *base = plat->reg;
+
+ if (__raw_readb(&base->urcfifo) == 0)
+ return 0;
+
+ return 1;
+}
+
+static struct serial_device serial_lpuart_drv = {
+ .name = "serial_lpuart",
+ .start = serial_lpuart_init,
+ .stop = NULL,
+ .setbrg = serial_lpuart_setbrg,
+ .putc = serial_lpuart_putc,
+ .puts = default_serial_puts,
+ .getc = serial_lpuart_getc,
+ .tstc = serial_lpuart_tstc,
+};
+
+__weak struct serial_device *default_serial_console(void)
+{
+ return &serial_lpuart_drv;
+}
+
+void serial_lpuart_initialize(void)
+{
+ serial_register(&serial_lpuart_drv);
+}
+
+#else /* CONFIG_DM_SERIAL */
+
+static bool is_lpuart32(struct udevice *dev)
+{
+ struct lpuart_serial_platdata *plat = dev->platdata;
+
+ return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG;
+}
+
+/* Test whether a character is in the RX buffer */
+static int _lpuart_serial_tstc(struct lpuart_serial_platdata *plat)
+{
+ struct lpuart_fsl *base = plat->reg;
+
+ if (__raw_readb(&base->urcfifo) == 0)
+ return 0;
+
+ return 1;
+}
+
+/* Test whether a character is in the RX buffer */
+static int _lpuart32_serial_tstc(struct lpuart_serial_platdata *plat)
+{
+ struct lpuart_fsl_reg32 *base = plat->reg;
+ u32 water;
+
+ lpuart_read32(plat->flags, &base->water, &water);
+
+ if ((water >> 24) == 0)
+ return 0;
+
+ return 1;
+}
+
static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
{
struct lpuart_serial_platdata *plat = dev->platdata;
@@ -415,6 +510,7 @@ static int lpuart_serial_pending(struct udevice *dev, bool input)
return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
}
+
static int lpuart_serial_probe(struct udevice *dev)
{
struct lpuart_serial_platdata *plat = dev->platdata;
@@ -479,3 +575,5 @@ U_BOOT_DRIVER(serial_lpuart) = {
.ops = &lpuart_serial_ops,
.flags = DM_FLAG_PRE_RELOC,
};
+
+#endif