blob: 29592761161919b30919832f788607d41df5c68a [file] [log] [blame]
Tom Rix93bed9b2009-05-31 12:44:37 +02001/*
2 * Copyright (c) 2009 Wind River Systems, Inc.
3 * Tom Rix <Tom.Rix@windriver.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Tom Rix93bed9b2009-05-31 12:44:37 +02006 *
Stefan Roese88fbf932010-04-15 16:07:28 +02007 * This file was adapted from arch/powerpc/cpu/mpc5xxx/serial.c
Tom Rix93bed9b2009-05-31 12:44:37 +02008 */
9
10#include <common.h>
11#include <serial.h>
12#include <ns16550.h>
13#include <asm/arch/cpu.h>
14#include "zoom2_serial.h"
15
16int quad_init_dev (unsigned long base)
17{
18 /*
19 * The Quad UART is on the debug board.
20 * Check if the debug board is attached before using the UART
21 */
22 if (zoom2_debug_board_connected ()) {
23 NS16550_t com_port = (NS16550_t) base;
24 int baud_divisor = CONFIG_SYS_NS16550_CLK / 16 /
25 CONFIG_BAUDRATE;
26
27 /*
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.
31 *
32 * Do the following instead of
33 *
34 * NS16550_init (com_port, clock_divisor);
35 */
36 com_port->ier = 0x00;
37
38 /*
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
42 */
43 com_port->lcr = 0xBF;
44 com_port->fcr |= 0x10;
45 com_port->mcr &= 0x7F;
46
47 /* This is generic ns16550.c setup */
48 com_port->lcr = UART_LCR_BKSE | UART_LCR_8N1;
49 com_port->dll = 0;
50 com_port->dlm = 0;
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 |
54 UART_FCR_TXSR;
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;
59 }
60 /*
61 * We have to lie here, otherwise the board init code will hang
62 * on the check
63 */
64 return 0;
65}
66
67void quad_putc_dev (unsigned long base, const char c)
68{
69 if (zoom2_debug_board_connected ()) {
70
71 if (c == '\n')
72 quad_putc_dev (base, '\r');
73
74 NS16550_putc ((NS16550_t) base, c);
Tom Rix7bea8682009-10-31 12:37:45 -050075 } else {
76 usbtty_putc(c);
Tom Rix93bed9b2009-05-31 12:44:37 +020077 }
78}
79
80void quad_puts_dev (unsigned long base, const char *s)
81{
82 if (zoom2_debug_board_connected ()) {
83 while ((s != NULL) && (*s != '\0'))
84 quad_putc_dev (base, *s++);
Tom Rix7bea8682009-10-31 12:37:45 -050085 } else {
86 usbtty_puts(s);
Tom Rix93bed9b2009-05-31 12:44:37 +020087 }
88}
89
90int quad_getc_dev (unsigned long base)
91{
92 if (zoom2_debug_board_connected ())
93 return NS16550_getc ((NS16550_t) base);
Tom Rix7bea8682009-10-31 12:37:45 -050094
95 return usbtty_getc();
Tom Rix93bed9b2009-05-31 12:44:37 +020096}
97
98int quad_tstc_dev (unsigned long base)
99{
100 if (zoom2_debug_board_connected ())
101 return NS16550_tstc ((NS16550_t) base);
Tom Rix7bea8682009-10-31 12:37:45 -0500102
103 return usbtty_tstc();
Tom Rix93bed9b2009-05-31 12:44:37 +0200104}
105
106void quad_setbrg_dev (unsigned long base)
107{
108 if (zoom2_debug_board_connected ()) {
109
110 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 /
111 CONFIG_BAUDRATE;
112
113 NS16550_reinit ((NS16550_t) base, clock_divisor);
114 }
115}
116
117QUAD_INIT (0)
118QUAD_INIT (1)
119QUAD_INIT (2)
120QUAD_INIT (3)
Mike Frysingerf96c0422011-04-29 18:03:29 +0000121
122struct serial_device *default_serial_console(void)
123{
Marek Vasut6b6fcfc2012-09-12 20:15:06 +0200124 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;
129 }
Mike Frysingerf96c0422011-04-29 18:03:29 +0000130}