]>
Commit | Line | Data |
---|---|---|
660888b7 TR |
1 | /* |
2 | * Copyright (c) 2009 Wind River Systems, Inc. | |
3 | * Tom Rix <Tom.Rix@windriver.com> | |
4 | * | |
1a459660 | 5 | * SPDX-License-Identifier: GPL-2.0+ |
660888b7 | 6 | * |
a47a12be | 7 | * This file was adapted from arch/powerpc/cpu/mpc5xxx/serial.c |
660888b7 TR |
8 | */ |
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 | ||
16 | int 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 | ||
67 | void 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); | |
2ec1abea TR |
75 | } else { |
76 | usbtty_putc(c); | |
660888b7 TR |
77 | } |
78 | } | |
79 | ||
80 | void 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++); | |
2ec1abea TR |
85 | } else { |
86 | usbtty_puts(s); | |
660888b7 TR |
87 | } |
88 | } | |
89 | ||
90 | int quad_getc_dev (unsigned long base) | |
91 | { | |
92 | if (zoom2_debug_board_connected ()) | |
93 | return NS16550_getc ((NS16550_t) base); | |
2ec1abea TR |
94 | |
95 | return usbtty_getc(); | |
660888b7 TR |
96 | } |
97 | ||
98 | int quad_tstc_dev (unsigned long base) | |
99 | { | |
100 | if (zoom2_debug_board_connected ()) | |
101 | return NS16550_tstc ((NS16550_t) base); | |
2ec1abea TR |
102 | |
103 | return usbtty_tstc(); | |
660888b7 TR |
104 | } |
105 | ||
106 | void 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 | ||
117 | QUAD_INIT (0) | |
118 | QUAD_INIT (1) | |
119 | QUAD_INIT (2) | |
120 | QUAD_INIT (3) | |
6c768ca7 MF |
121 | |
122 | struct serial_device *default_serial_console(void) | |
123 | { | |
425101e1 MV |
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; | |
129 | } | |
6c768ca7 | 130 | } |