Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - serial.c Blackfin Serial Driver |
| 3 | * |
| 4 | * Copyright (c) 2005-2008 Analog Devices Inc. |
| 5 | * |
| 6 | * Copyright (c) 2003 Bas Vermeulen <bas@buyways.nl>, |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 7 | * BuyWays B.V. (www.buyways.nl) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 8 | * |
| 9 | * Based heavily on: |
| 10 | * blkfinserial.c: Serial driver for BlackFin DSP internal USRTs. |
| 11 | * Copyright(c) 2003 Metrowerks <mwaddel@metrowerks.com> |
| 12 | * Copyright(c) 2001 Tony Z. Kou <tonyko@arcturusnetworks.com> |
| 13 | * Copyright(c) 2001-2002 Arcturus Networks Inc. <www.arcturusnetworks.com> |
| 14 | * |
| 15 | * Based on code from 68328 version serial driver imlpementation which was: |
| 16 | * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu> |
| 17 | * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com> |
| 18 | * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org> |
| 19 | * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com> |
| 20 | * |
| 21 | * (C) Copyright 2000-2004 |
| 22 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 23 | * |
| 24 | * Licensed under the GPL-2 or later. |
| 25 | */ |
| 26 | |
Mike Frysinger | aad4eca | 2009-04-04 09:10:27 -0400 | [diff] [blame] | 27 | /* Anomaly notes: |
| 28 | * 05000086 - we don't support autobaud |
| 29 | * 05000099 - we only use DR bit, so losing others is not a problem |
| 30 | * 05000100 - we don't use the UART_IIR register |
| 31 | * 05000215 - we poll the uart (no dma/interrupts) |
| 32 | * 05000225 - no workaround possible, but this shouldnt cause errors ... |
| 33 | * 05000230 - we tweak the baud rate calculation slightly |
| 34 | * 05000231 - we always use 1 stop bit |
| 35 | * 05000309 - we always enable the uart before we modify it in anyway |
| 36 | * 05000350 - we always enable the uart regardless of boot mode |
| 37 | * 05000363 - we don't support break signals, so don't generate one |
| 38 | */ |
| 39 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 40 | #include <common.h> |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 41 | #include <post.h> |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 42 | #include <watchdog.h> |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 43 | #include <serial.h> |
| 44 | #include <linux/compiler.h> |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 45 | #include <asm/blackfin.h> |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 46 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 47 | DECLARE_GLOBAL_DATA_PTR; |
| 48 | |
Mike Frysinger | 7633903 | 2008-10-11 21:52:17 -0400 | [diff] [blame] | 49 | #ifdef CONFIG_UART_CONSOLE |
| 50 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 51 | #include "serial.h" |
| 52 | |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 53 | #ifdef CONFIG_DEBUG_SERIAL |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 54 | static uart_lsr_t cached_lsr[256]; |
| 55 | static uart_lsr_t cached_rbr[256]; |
Mike Frysinger | 34a6d0b8 | 2011-04-29 23:10:54 -0400 | [diff] [blame] | 56 | static size_t cache_count; |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 57 | |
| 58 | /* The LSR is read-to-clear on some parts, so we have to make sure status |
Mike Frysinger | aad4eca | 2009-04-04 09:10:27 -0400 | [diff] [blame] | 59 | * bits aren't inadvertently lost when doing various tests. This also |
| 60 | * works around anomaly 05000099 at the same time by keeping a cumulative |
| 61 | * tally of all the status bits. |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 62 | */ |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 63 | static uart_lsr_t uart_lsr_save; |
| 64 | static uart_lsr_t uart_lsr_read(uint32_t uart_base) |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 65 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 66 | uart_lsr_t lsr = _lsr_read(pUART); |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 67 | uart_lsr_save |= (lsr & (OE|PE|FE|BI)); |
| 68 | return lsr | uart_lsr_save; |
| 69 | } |
| 70 | /* Just do the clear for everyone since it can't hurt. */ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 71 | static void uart_lsr_clear(uint32_t uart_base) |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 72 | { |
| 73 | uart_lsr_save = 0; |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 74 | _lsr_write(pUART, -1); |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 75 | } |
| 76 | #else |
Mike Frysinger | aad4eca | 2009-04-04 09:10:27 -0400 | [diff] [blame] | 77 | /* When debugging is disabled, we only care about the DR bit, so if other |
| 78 | * bits get set/cleared, we don't really care since we don't read them |
| 79 | * anyways (and thus anomaly 05000099 is irrelevant). |
| 80 | */ |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 81 | static inline uart_lsr_t uart_lsr_read(uint32_t uart_base) |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 82 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 83 | return _lsr_read(pUART); |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 84 | } |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 85 | static void uart_lsr_clear(uint32_t uart_base) |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 86 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 87 | _lsr_write(pUART, -1); |
Mike Frysinger | f948158 | 2009-11-12 18:42:53 -0500 | [diff] [blame] | 88 | } |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 89 | #endif |
| 90 | |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 91 | static void uart_putc(uint32_t uart_base, const char c) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 92 | { |
| 93 | /* send a \r for compatibility */ |
| 94 | if (c == '\n') |
| 95 | serial_putc('\r'); |
| 96 | |
| 97 | WATCHDOG_RESET(); |
| 98 | |
| 99 | /* wait for the hardware fifo to clear up */ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 100 | while (!(uart_lsr_read(uart_base) & THRE)) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 101 | continue; |
| 102 | |
| 103 | /* queue the character for transmission */ |
Mike Frysinger | b1e574d | 2011-06-06 16:47:31 -0400 | [diff] [blame] | 104 | bfin_write(&pUART->thr, c); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 105 | SSYNC(); |
| 106 | |
| 107 | WATCHDOG_RESET(); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 108 | } |
| 109 | |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 110 | static int uart_tstc(uint32_t uart_base) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 111 | { |
| 112 | WATCHDOG_RESET(); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 113 | return (uart_lsr_read(uart_base) & DR) ? 1 : 0; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 114 | } |
| 115 | |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 116 | static int uart_getc(uint32_t uart_base) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 117 | { |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 118 | uint16_t uart_rbr_val; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 119 | |
| 120 | /* wait for data ! */ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 121 | while (!uart_tstc(uart_base)) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 122 | continue; |
| 123 | |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 124 | /* grab the new byte */ |
Mike Frysinger | b1e574d | 2011-06-06 16:47:31 -0400 | [diff] [blame] | 125 | uart_rbr_val = bfin_read(&pUART->rbr); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 126 | |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 127 | #ifdef CONFIG_DEBUG_SERIAL |
| 128 | /* grab & clear the LSR */ |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 129 | uart_lsr_t uart_lsr_val = uart_lsr_read(uart_base); |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 130 | |
| 131 | cached_lsr[cache_count] = uart_lsr_val; |
| 132 | cached_rbr[cache_count] = uart_rbr_val; |
| 133 | cache_count = (cache_count + 1) % ARRAY_SIZE(cached_lsr); |
| 134 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 135 | if (uart_lsr_val & (OE|PE|FE|BI)) { |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 136 | printf("\n[SERIAL ERROR]\n"); |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 137 | do { |
| 138 | --cache_count; |
Mike Frysinger | f9aee4b | 2011-05-09 14:56:38 -0400 | [diff] [blame] | 139 | printf("\t%3zu: RBR=0x%02x LSR=0x%02x\n", cache_count, |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 140 | cached_rbr[cache_count], cached_lsr[cache_count]); |
| 141 | } while (cache_count > 0); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 142 | return -1; |
| 143 | } |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 144 | #endif |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 145 | uart_lsr_clear(uart_base); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 146 | |
Mike Frysinger | f177f42 | 2008-04-09 02:02:07 -0400 | [diff] [blame] | 147 | return uart_rbr_val; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 148 | } |
| 149 | |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 150 | #if CONFIG_POST & CONFIG_SYS_POST_UART |
| 151 | # define LOOP(x) x |
| 152 | #else |
| 153 | # define LOOP(x) |
| 154 | #endif |
| 155 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 156 | #if BFIN_UART_HW_VER < 4 |
| 157 | |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 158 | LOOP( |
| 159 | static void uart_loop(uint32_t uart_base, int state) |
| 160 | { |
| 161 | u16 mcr; |
| 162 | |
| 163 | /* Drain the TX fifo first so bytes don't come back */ |
| 164 | while (!(uart_lsr_read(uart_base) & TEMT)) |
| 165 | continue; |
| 166 | |
| 167 | mcr = bfin_read(&pUART->mcr); |
| 168 | if (state) |
| 169 | mcr |= LOOP_ENA | MRTS; |
| 170 | else |
| 171 | mcr &= ~(LOOP_ENA | MRTS); |
| 172 | bfin_write(&pUART->mcr, mcr); |
| 173 | } |
| 174 | ) |
| 175 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 176 | #else |
| 177 | |
| 178 | LOOP( |
| 179 | static void uart_loop(uint32_t uart_base, int state) |
| 180 | { |
| 181 | u32 control; |
| 182 | |
| 183 | /* Drain the TX fifo first so bytes don't come back */ |
| 184 | while (!(uart_lsr_read(uart_base) & TEMT)) |
| 185 | continue; |
| 186 | |
| 187 | control = bfin_read(&pUART->control); |
| 188 | if (state) |
| 189 | control |= LOOP_ENA | MRTS; |
| 190 | else |
| 191 | control &= ~(LOOP_ENA | MRTS); |
| 192 | bfin_write(&pUART->control, control); |
| 193 | } |
| 194 | ) |
| 195 | |
| 196 | #endif |
| 197 | |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 198 | #ifdef CONFIG_SYS_BFIN_UART |
| 199 | |
| 200 | static void uart_puts(uint32_t uart_base, const char *s) |
| 201 | { |
| 202 | while (*s) |
| 203 | uart_putc(uart_base, *s++); |
| 204 | } |
| 205 | |
| 206 | #define DECL_BFIN_UART(n) \ |
| 207 | static int uart##n##_init(void) \ |
| 208 | { \ |
| 209 | const unsigned short pins[] = { _P_UART(n, RX), _P_UART(n, TX), 0, }; \ |
| 210 | peripheral_request_list(pins, "bfin-uart"); \ |
| 211 | uart_init(MMR_UART(n)); \ |
| 212 | serial_early_set_baud(MMR_UART(n), gd->baudrate); \ |
| 213 | uart_lsr_clear(MMR_UART(n)); \ |
| 214 | return 0; \ |
| 215 | } \ |
| 216 | \ |
| 217 | static int uart##n##_uninit(void) \ |
| 218 | { \ |
| 219 | return serial_early_uninit(MMR_UART(n)); \ |
| 220 | } \ |
| 221 | \ |
| 222 | static void uart##n##_setbrg(void) \ |
| 223 | { \ |
| 224 | serial_early_set_baud(MMR_UART(n), gd->baudrate); \ |
| 225 | } \ |
| 226 | \ |
| 227 | static int uart##n##_getc(void) \ |
| 228 | { \ |
| 229 | return uart_getc(MMR_UART(n)); \ |
| 230 | } \ |
| 231 | \ |
| 232 | static int uart##n##_tstc(void) \ |
| 233 | { \ |
| 234 | return uart_tstc(MMR_UART(n)); \ |
| 235 | } \ |
| 236 | \ |
| 237 | static void uart##n##_putc(const char c) \ |
| 238 | { \ |
| 239 | uart_putc(MMR_UART(n), c); \ |
| 240 | } \ |
| 241 | \ |
| 242 | static void uart##n##_puts(const char *s) \ |
| 243 | { \ |
| 244 | uart_puts(MMR_UART(n), s); \ |
| 245 | } \ |
| 246 | \ |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 247 | LOOP( \ |
| 248 | static void uart##n##_loop(int state) \ |
| 249 | { \ |
| 250 | uart_loop(MMR_UART(n), state); \ |
| 251 | } \ |
| 252 | ) \ |
| 253 | \ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 254 | struct serial_device bfin_serial##n##_device = { \ |
| 255 | .name = "bfin_uart"#n, \ |
Marek Vasut | 89143fb | 2012-09-07 14:35:31 +0200 | [diff] [blame] | 256 | .start = uart##n##_init, \ |
| 257 | .stop = uart##n##_uninit, \ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 258 | .setbrg = uart##n##_setbrg, \ |
| 259 | .getc = uart##n##_getc, \ |
| 260 | .tstc = uart##n##_tstc, \ |
| 261 | .putc = uart##n##_putc, \ |
| 262 | .puts = uart##n##_puts, \ |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 263 | LOOP(.loop = uart##n##_loop) \ |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 264 | }; |
| 265 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 266 | #ifdef UART0_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 267 | DECL_BFIN_UART(0) |
| 268 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 269 | #ifdef UART1_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 270 | DECL_BFIN_UART(1) |
| 271 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 272 | #ifdef UART2_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 273 | DECL_BFIN_UART(2) |
| 274 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 275 | #ifdef UART3_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 276 | DECL_BFIN_UART(3) |
| 277 | #endif |
| 278 | |
| 279 | __weak struct serial_device *default_serial_console(void) |
| 280 | { |
| 281 | #if CONFIG_UART_CONSOLE == 0 |
| 282 | return &bfin_serial0_device; |
| 283 | #elif CONFIG_UART_CONSOLE == 1 |
| 284 | return &bfin_serial1_device; |
| 285 | #elif CONFIG_UART_CONSOLE == 2 |
| 286 | return &bfin_serial2_device; |
| 287 | #elif CONFIG_UART_CONSOLE == 3 |
| 288 | return &bfin_serial3_device; |
| 289 | #endif |
| 290 | } |
| 291 | |
Marek Vasut | 5ae1de0 | 2012-09-12 20:07:54 +0200 | [diff] [blame] | 292 | void bfin_serial_initialize(void) |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 293 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 294 | #ifdef UART0_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 295 | serial_register(&bfin_serial0_device); |
| 296 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 297 | #ifdef UART1_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 298 | serial_register(&bfin_serial1_device); |
| 299 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 300 | #ifdef UART2_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 301 | serial_register(&bfin_serial2_device); |
| 302 | #endif |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 303 | #ifdef UART3_RBR |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 304 | serial_register(&bfin_serial3_device); |
| 305 | #endif |
| 306 | } |
| 307 | |
| 308 | #else |
| 309 | |
| 310 | /* Symbol for our assembly to call. */ |
| 311 | void serial_set_baud(uint32_t baud) |
| 312 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 313 | serial_early_set_baud(UART_BASE, baud); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /* Symbol for common u-boot code to call. |
| 317 | * Setup the baudrate (brg: baudrate generator). |
| 318 | */ |
| 319 | void serial_setbrg(void) |
| 320 | { |
| 321 | serial_set_baud(gd->baudrate); |
| 322 | } |
| 323 | |
| 324 | /* Symbol for our assembly to call. */ |
| 325 | void serial_initialize(void) |
| 326 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 327 | serial_early_init(UART_BASE); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* Symbol for common u-boot code to call. */ |
| 331 | int serial_init(void) |
| 332 | { |
| 333 | serial_initialize(); |
| 334 | serial_setbrg(); |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 335 | uart_lsr_clear(UART_BASE); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | int serial_tstc(void) |
| 340 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 341 | return uart_tstc(UART_BASE); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | int serial_getc(void) |
| 345 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 346 | return uart_getc(UART_BASE); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | void serial_putc(const char c) |
| 350 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 351 | uart_putc(UART_BASE, c); |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 354 | void serial_puts(const char *s) |
| 355 | { |
| 356 | while (*s) |
| 357 | serial_putc(*s++); |
| 358 | } |
Mike Frysinger | 7633903 | 2008-10-11 21:52:17 -0400 | [diff] [blame] | 359 | |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 360 | LOOP( |
| 361 | void serial_loop(int state) |
| 362 | { |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame^] | 363 | uart_loop(UART_BASE, state); |
Mike Frysinger | 90a75b0 | 2011-05-14 12:17:46 -0400 | [diff] [blame] | 364 | } |
| 365 | ) |
| 366 | |
Mike Frysinger | 7633903 | 2008-10-11 21:52:17 -0400 | [diff] [blame] | 367 | #endif |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 368 | |
| 369 | #endif |