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>
11 #include <dt-structs.h>
16 #ifndef CONFIG_SYS_NS16550_CLK
17 #define CONFIG_SYS_NS16550_CLK 0
20 #ifdef CONFIG_DEBUG_UART_OMAP
22 #ifndef CONFIG_SYS_NS16550_IER
23 #define CONFIG_SYS_NS16550_IER 0x00
26 #define UART_MCRVAL 0x00
27 #define UART_LCRVAL UART_LCR_8N1
29 static inline void serial_out_shift(void *addr, int shift, int value)
31 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
32 outb(value, (ulong)addr);
33 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_LITTLE_ENDIAN)
34 out_le32(addr, value);
35 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
36 out_be32(addr, value);
37 #elif defined(CONFIG_SYS_NS16550_MEM32)
39 #elif defined(CONFIG_SYS_BIG_ENDIAN)
40 writeb(value, addr + (1 << shift) - 1);
46 static inline int serial_in_shift(void *addr, int shift)
48 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
49 return inb((ulong)addr);
50 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_LITTLE_ENDIAN)
52 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
54 #elif defined(CONFIG_SYS_NS16550_MEM32)
56 #elif defined(CONFIG_SYS_BIG_ENDIAN)
57 return readb(addr + (1 << shift) - 1);
63 #include <debug_uart.h>
65 static inline void _debug_uart_init(void)
67 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
70 baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
72 serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
73 serial_dout(&com_port->mdr1, 0x7);
74 serial_dout(&com_port->mcr, UART_MCRVAL);
75 serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
77 serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
78 serial_dout(&com_port->dll, baud_divisor & 0xff);
79 serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
80 serial_dout(&com_port->lcr, UART_LCRVAL);
81 serial_dout(&com_port->mdr1, 0x0);
84 static inline void _debug_uart_putc(int ch)
86 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
88 while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
90 serial_dout(&com_port->thr, ch);
97 #if CONFIG_IS_ENABLED(DM_SERIAL)
99 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
100 static int omap_serial_ofdata_to_platdata(struct udevice *dev)
102 struct ns16550_platdata *plat = dev->platdata;
107 /* try Processor Local Bus device first */
108 addr = dev_read_addr(dev);
109 if (addr == FDT_ADDR_T_NONE)
112 plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE);
114 plat->reg_offset = dev_read_u32_default(dev, "reg-offset", 0);
117 err = clk_get_by_index(dev, 0, &clk);
119 err = clk_get_rate(&clk);
120 if (!IS_ERR_VALUE(err))
122 } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
123 debug("omap serial failed to get clock\n");
128 plat->clock = dev_read_u32_default(dev, "clock-frequency",
129 CONFIG_SYS_NS16550_CLK);
131 debug("omap serial clock not defined\n");
135 plat->fcr = UART_FCR_DEFVAL;
140 static const struct udevice_id omap_serial_ids[] = {
141 { .compatible = "ti,omap2-uart", },
142 { .compatible = "ti,omap3-uart", },
143 { .compatible = "ti,omap4-uart", },
144 { .compatible = "ti,am3352-uart", },
145 { .compatible = "ti,am4372-uart", },
146 { .compatible = "ti,dra742-uart", },
147 { .compatible = "ti,am654-uart", },
150 #endif /* OF_CONTROL && !OF_PLATDATA */
152 #if CONFIG_IS_ENABLED(SERIAL_PRESENT)
153 U_BOOT_DRIVER(omap_serial) = {
154 .name = "omap_serial",
156 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
157 .of_match = omap_serial_ids,
158 .ofdata_to_platdata = omap_serial_ofdata_to_platdata,
159 .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
161 .priv_auto_alloc_size = sizeof(struct NS16550),
162 .probe = ns16550_serial_probe,
163 .ops = &ns16550_serial_ops,
164 #if !CONFIG_IS_ENABLED(OF_CONTROL)
165 .flags = DM_FLAG_PRE_RELOC,
169 #endif /* DM_SERIAL */