1 // SPDX-License-Identifier: GPL-2.0+
3 * Texas Instruments' OMAP serial driver
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
10 #include <debug_uart.h>
12 #include <dt-structs.h>
17 #ifndef CONFIG_SYS_NS16550_CLK
18 #define CONFIG_SYS_NS16550_CLK 0
21 #ifdef CONFIG_DEBUG_UART_OMAP
23 #include <debug_uart.h>
25 static inline void _debug_uart_init(void)
27 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
30 baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
32 serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
33 serial_dout(&com_port->mdr1, 0x7);
34 serial_dout(&com_port->mcr, UART_MCRVAL);
35 serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
37 serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
38 serial_dout(&com_port->dll, baud_divisor & 0xff);
39 serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
40 serial_dout(&com_port->lcr, UART_LCRVAL);
41 serial_dout(&com_port->mdr1, 0x0);
44 static inline void _debug_uart_putc(int ch)
46 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
48 while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
50 serial_dout(&com_port->thr, ch);
57 #if CONFIG_IS_ENABLED(DM_SERIAL)
59 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
60 static int omap_serial_ofdata_to_platdata(struct udevice *dev)
62 struct ns16550_platdata *plat = dev->platdata;
67 /* try Processor Local Bus device first */
68 addr = dev_read_addr(dev);
69 if (addr == FDT_ADDR_T_NONE)
72 plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE);
74 plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0);
77 err = clk_get_by_index(dev, 0, &clk);
79 err = clk_get_rate(&clk);
80 if (!IS_ERR_VALUE(err))
82 } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
83 debug("omap serial failed to get clock\n");
88 plat->clock = dev_read_u32_default(dev, "clock-frequency",
89 CONFIG_SYS_NS16550_CLK);
91 debug("omap serial clock not defined\n");
95 plat->fcr = UART_FCR_DEFVAL;
100 static const struct udevice_id omap_serial_ids[] = {
101 { .compatible = "ti,omap2-uart", },
102 { .compatible = "ti,omap3-uart", },
103 { .compatible = "ti,omap4-uart", },
104 { .compatible = "ti,am3352-uart", },
105 { .compatible = "ti,am4372-uart", },
106 { .compatible = "ti,dra742-uart", },
107 { .compatible = "ti,am654-uart", },
110 #endif /* OF_CONTROL && !OF_PLATDATA */
112 #if CONFIG_IS_ENABLED(SERIAL_PRESENT)
113 U_BOOT_DRIVER(omap_serial) = {
114 .name = "omap_serial",
116 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
117 .of_match = omap_serial_ids,
118 .ofdata_to_platdata = omap_serial_ofdata_to_platdata,
119 .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
121 .priv_auto_alloc_size = sizeof(struct NS16550),
122 .probe = ns16550_serial_probe,
123 .ops = &ns16550_serial_ops,
124 .flags = DM_FLAG_PRE_RELOC,
127 #endif /* DM_SERIAL */