2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
5 * SPDX-License-Identifier: GPL-2.0+
7 * This file was adapted from arch/powerpc/cpu/mpc5xxx/serial.c
13 #include <asm/arch/cpu.h>
14 #include "zoom2_serial.h"
16 int quad_init_dev (unsigned long base)
19 * The Quad UART is on the debug board.
20 * Check if the debug board is attached before using the UART
22 if (zoom2_debug_board_connected ()) {
23 NS16550_t com_port = (NS16550_t) base;
24 int baud_divisor = CONFIG_SYS_NS16550_CLK / 16 /
28 * Zoom2 has a board specific initialization of its UART.
29 * This generic initialization has been copied from
30 * drivers/serial/ns16550.c. The macros have been expanded.
32 * Do the following instead of
34 * NS16550_init (com_port, clock_divisor);
39 * On Zoom2 board Set pre-scalar to 1
40 * CLKSEL is GND => MCR[7] is 1 => preslr is 4
41 * So change the prescl to 1
44 com_port->fcr |= 0x10;
45 com_port->mcr &= 0x7F;
47 /* This is generic ns16550.c setup */
48 com_port->lcr = UART_LCR_BKSE | UART_LCR_8N1;
51 com_port->lcr = UART_LCR_8N1;
52 com_port->mcr = UART_MCR_DTR | UART_MCR_RTS;
53 com_port->fcr = UART_FCR_FIFO_EN | UART_FCR_RXSR |
55 com_port->lcr = UART_LCR_BKSE | UART_LCR_8N1;
56 com_port->dll = baud_divisor & 0xff;
57 com_port->dlm = (baud_divisor >> 8) & 0xff;
58 com_port->lcr = UART_LCR_8N1;
61 * We have to lie here, otherwise the board init code will hang
67 void quad_putc_dev (unsigned long base, const char c)
69 if (zoom2_debug_board_connected ()) {
72 quad_putc_dev (base, '\r');
74 NS16550_putc ((NS16550_t) base, c);
80 void quad_puts_dev (unsigned long base, const char *s)
82 if (zoom2_debug_board_connected ()) {
83 while ((s != NULL) && (*s != '\0'))
84 quad_putc_dev (base, *s++);
90 int quad_getc_dev (unsigned long base)
92 if (zoom2_debug_board_connected ())
93 return NS16550_getc ((NS16550_t) base);
98 int quad_tstc_dev (unsigned long base)
100 if (zoom2_debug_board_connected ())
101 return NS16550_tstc ((NS16550_t) base);
103 return usbtty_tstc();
106 void quad_setbrg_dev (unsigned long base)
108 if (zoom2_debug_board_connected ()) {
110 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 /
113 NS16550_reinit ((NS16550_t) base, clock_divisor);
122 struct serial_device *default_serial_console(void)
124 switch (ZOOM2_DEFAULT_SERIAL_DEVICE) {
125 case 0: return &zoom2_serial_device0;
126 case 1: return &zoom2_serial_device1;
127 case 2: return &zoom2_serial_device2;
128 case 3: return &zoom2_serial_device3;