]>
Commit | Line | Data |
---|---|---|
c609719b WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Gary Jennejohn, DENX Software Engineering, <gj@denx.de> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <common.h> | |
22 | #if defined(CONFIG_S3C2400) || defined(CONFIG_TRAB) | |
23 | #include <s3c2400.h> | |
24 | #elif defined(CONFIG_S3C2410) | |
25 | #include <s3c2410.h> | |
26 | #endif | |
27 | ||
48b42616 WD |
28 | #ifdef CONFIG_SERIAL1 |
29 | #define UART_NR S3C24X0_UART0 | |
30 | ||
31 | #elif CONFIG_SERIAL2 | |
32 | # if defined(CONFIG_TRAB) | |
33 | # #error "TRAB supports only CONFIG_SERIAL1" | |
34 | # endif | |
35 | #define UART_NR S3C24X0_UART1 | |
36 | ||
37 | #elif CONFIG_SERIAL3 | |
38 | # if defined(CONFIG_TRAB) | |
39 | # #error "TRAB supports only CONFIG_SERIAL1" | |
40 | # endif | |
41 | #define UART_NR S3C24X0_UART2 | |
42 | ||
43 | #else | |
44 | #error "Bad: you didn't configure serial ..." | |
45 | #endif | |
c609719b WD |
46 | |
47 | void serial_setbrg (void) | |
48 | { | |
49 | DECLARE_GLOBAL_DATA_PTR; | |
48b42616 | 50 | S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR); |
c609719b WD |
51 | int i; |
52 | unsigned int reg = 0; | |
53 | ||
54 | /* value is calculated so : (int)(PCLK/16./baudrate) -1 */ | |
55 | reg = get_PCLK() / (16 * gd->baudrate) - 1; | |
56 | ||
c609719b | 57 | /* FIFO enable, Tx/Rx FIFO clear */ |
48b42616 WD |
58 | uart->UFCON = 0x07; |
59 | uart->UMCON = 0x0; | |
c609719b | 60 | /* Normal,No parity,1 stop,8 bit */ |
48b42616 | 61 | uart->ULCON = 0x3; |
c609719b WD |
62 | /* |
63 | * tx=level,rx=edge,disable timeout int.,enable rx error int., | |
64 | * normal,interrupt or polling | |
65 | */ | |
48b42616 WD |
66 | uart->UCON = 0x245; |
67 | uart->UBRDIV = reg; | |
c609719b WD |
68 | |
69 | #ifdef CONFIG_HWFLOW | |
48b42616 | 70 | uart->UMCON = 0x1; /* RTS up */ |
c609719b WD |
71 | #endif |
72 | for (i = 0; i < 100; i++); | |
c609719b WD |
73 | } |
74 | ||
75 | /* | |
76 | * Initialise the serial port with the given baudrate. The settings | |
77 | * are always 8 data bits, no parity, 1 stop bit, no start bits. | |
78 | * | |
79 | */ | |
80 | int serial_init (void) | |
81 | { | |
82 | serial_setbrg (); | |
83 | ||
84 | return (0); | |
85 | } | |
86 | ||
87 | /* | |
88 | * Read a single byte from the serial port. Returns 1 on success, 0 | |
89 | * otherwise. When the function is succesfull, the character read is | |
90 | * written into its argument c. | |
91 | */ | |
92 | int serial_getc (void) | |
93 | { | |
48b42616 | 94 | S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR); |
8bde7f77 | 95 | |
48b42616 WD |
96 | /* wait for character to arrive */ |
97 | while (!(uart->UTRSTAT & 0x1)); | |
c609719b | 98 | |
48b42616 | 99 | return uart->URXH & 0xff; |
c609719b WD |
100 | } |
101 | ||
102 | #ifdef CONFIG_HWFLOW | |
103 | static int hwflow = 0; /* turned off by default */ | |
104 | int hwflow_onoff(int on) | |
105 | { | |
106 | switch(on) { | |
107 | case 0: | |
108 | default: | |
109 | break; /* return current */ | |
110 | case 1: | |
111 | hwflow = 1; /* turn on */ | |
112 | break; | |
113 | case -1: | |
114 | hwflow = 0; /* turn off */ | |
115 | break; | |
116 | } | |
117 | return hwflow; | |
118 | } | |
119 | #endif | |
120 | ||
121 | #ifdef CONFIG_MODEM_SUPPORT | |
122 | static int be_quiet = 0; | |
123 | void disable_putc(void) | |
124 | { | |
125 | be_quiet = 1; | |
126 | } | |
127 | ||
128 | void enable_putc(void) | |
129 | { | |
130 | be_quiet = 0; | |
131 | } | |
132 | #endif | |
133 | ||
134 | ||
135 | /* | |
136 | * Output a single byte to the serial port. | |
137 | */ | |
138 | void serial_putc (const char c) | |
139 | { | |
48b42616 | 140 | S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR); |
c609719b WD |
141 | #ifdef CONFIG_MODEM_SUPPORT |
142 | if (be_quiet) | |
143 | return; | |
144 | #endif | |
145 | ||
48b42616 WD |
146 | /* wait for room in the tx FIFO */ |
147 | while (!(uart->UTRSTAT & 0x2)); | |
c609719b WD |
148 | |
149 | #ifdef CONFIG_HWFLOW | |
150 | /* Wait for CTS up */ | |
48b42616 | 151 | while(hwflow && !(uart->UMSTAT & 0x1)) |
c609719b WD |
152 | ; |
153 | #endif | |
154 | ||
48b42616 | 155 | uart->UTXH = c; |
c609719b WD |
156 | |
157 | /* If \n, also do \r */ | |
158 | if (c == '\n') | |
159 | serial_putc ('\r'); | |
160 | } | |
161 | ||
162 | /* | |
163 | * Test whether a character is in the RX buffer | |
164 | */ | |
165 | int serial_tstc (void) | |
166 | { | |
48b42616 WD |
167 | S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR); |
168 | ||
169 | return uart->UTRSTAT & 0x1; | |
c609719b WD |
170 | } |
171 | ||
172 | void | |
173 | serial_puts (const char *s) | |
174 | { | |
175 | while (*s) { | |
176 | serial_putc (*s++); | |
177 | } | |
178 | } |