1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25
26#include <asm/arch/s3c6400.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30#ifdef CONFIG_SERIAL1
31#define UART_NR S3C64XX_UART0
32
33#elif defined(CONFIG_SERIAL2)
34#define UART_NR S3C64XX_UART1
35
36#elif defined(CONFIG_SERIAL3)
37#define UART_NR S3C64XX_UART2
38
39#else
40#error "Bad: you didn't configure serial ..."
41#endif
42
43#define barrier() asm volatile("" ::: "memory")
44
45
46
47
48
49
50
51
52static const int udivslot[] = {
53 0,
54 0x0080,
55 0x0808,
56 0x0888,
57 0x2222,
58 0x4924,
59 0x4a52,
60 0x54aa,
61 0x5555,
62 0xd555,
63 0xd5d5,
64 0xddd5,
65 0xdddd,
66 0xdfdd,
67 0xdfdf,
68 0xffdf,
69};
70
71void serial_setbrg(void)
72{
73 s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR);
74 u32 pclk = get_PCLK();
75 u32 baudrate = gd->baudrate;
76 int i;
77
78 i = (pclk / baudrate) % 16;
79
80 uart->UBRDIV = pclk / baudrate / 16 - 1;
81 uart->UDIVSLOT = udivslot[i];
82
83 for (i = 0; i < 100; i++)
84 barrier();
85}
86
87
88
89
90
91int serial_init(void)
92{
93 s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR);
94
95
96 uart->UFCON = 0xff;
97 uart->UMCON = 0;
98
99 uart->ULCON = 3;
100
101 uart->UCON = 5;
102
103 serial_setbrg();
104
105 return 0;
106}
107
108
109
110
111
112
113int serial_getc(void)
114{
115 s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR);
116
117
118 while (!(uart->UTRSTAT & 0x1));
119
120 return uart->URXH & 0xff;
121}
122
123#ifdef CONFIG_MODEM_SUPPORT
124static int be_quiet;
125void disable_putc(void)
126{
127 be_quiet = 1;
128}
129
130void enable_putc(void)
131{
132 be_quiet = 0;
133}
134#endif
135
136
137
138
139
140void serial_putc(const char c)
141{
142 s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR);
143
144#ifdef CONFIG_MODEM_SUPPORT
145 if (be_quiet)
146 return;
147#endif
148
149
150 while (!(uart->UTRSTAT & 0x2));
151
152 uart->UTXH = c;
153
154
155 if (c == '\n')
156 serial_putc('\r');
157}
158
159
160
161
162int serial_tstc(void)
163{
164 s3c64xx_uart *const uart = s3c64xx_get_base_uart(UART_NR);
165
166 return uart->UTRSTAT & 0x1;
167}
168
169void serial_puts(const char *s)
170{
171 while (*s)
172 serial_putc(*s++);
173}
174