Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / tty / serial / imx_earlycon.c
blob795606e1a22f963b954bf300147fbe04ea2af9b3
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2020 NXP
4 */
6 #include <linux/module.h>
7 #include <linux/ioport.h>
8 #include <linux/init.h>
9 #include <linux/serial_core.h>
10 #include <linux/serial.h>
11 #include <linux/delay.h>
12 #include <linux/of.h>
13 #include <linux/io.h>
15 #define URTX0 0x40 /* Transmitter Register */
16 #define UTS_TXFULL (1<<4) /* TxFIFO full */
17 #define IMX21_UTS 0xb4 /* UART Test Register on all other i.mx*/
19 static void imx_uart_console_early_putchar(struct uart_port *port, int ch)
21 while (readl_relaxed(port->membase + IMX21_UTS) & UTS_TXFULL)
22 cpu_relax();
24 writel_relaxed(ch, port->membase + URTX0);
27 static void imx_uart_console_early_write(struct console *con, const char *s,
28 unsigned count)
30 struct earlycon_device *dev = con->data;
32 uart_console_write(&dev->port, s, count, imx_uart_console_early_putchar);
35 static int __init
36 imx_console_early_setup(struct earlycon_device *dev, const char *opt)
38 if (!dev->port.membase)
39 return -ENODEV;
41 dev->con->write = imx_uart_console_early_write;
43 return 0;
45 OF_EARLYCON_DECLARE(ec_imx6q, "fsl,imx6q-uart", imx_console_early_setup);
46 OF_EARLYCON_DECLARE(ec_imx21, "fsl,imx21-uart", imx_console_early_setup);
48 MODULE_AUTHOR("NXP");
49 MODULE_DESCRIPTION("IMX earlycon driver");
50 MODULE_LICENSE("GPL");