3 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
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.
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.
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
22 #if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || \
23 defined(CONFIG_S3C2440) || defined (CONFIG_S3C2442) || \
26 #if defined(CONFIG_S3C2400) || defined(CONFIG_TRAB)
28 #elif defined(CONFIG_S3C2410)
30 #elif defined(CONFIG_S3C2440) || defined(CONFIG_S3C2442)
34 DECLARE_GLOBAL_DATA_PTR
;
37 #define UART_NR S3C24X0_UART0
39 #elif defined(CONFIG_SERIAL2)
40 # if defined(CONFIG_TRAB)
41 # error "TRAB supports only CONFIG_SERIAL1"
43 #define UART_NR S3C24X0_UART1
45 #elif defined(CONFIG_SERIAL3)
46 # if defined(CONFIG_TRAB)
47 # #error "TRAB supports only CONFIG_SERIAL1"
49 #define UART_NR S3C24X0_UART2
52 #error "Bad: you didn't configure serial ..."
55 #if defined(CONFIG_SERIAL_MULTI)
58 /* Multi serial device functions */
59 #define DECLARE_S3C_SERIAL_FUNCTIONS(port) \
60 int s3serial##port##_init (void) {\
61 return serial_init_dev(port);}\
62 void s3serial##port##_setbrg (void) {\
63 serial_setbrg_dev(port);}\
64 int s3serial##port##_getc (void) {\
65 return serial_getc_dev(port);}\
66 int s3serial##port##_tstc (void) {\
67 return serial_tstc_dev(port);}\
68 void s3serial##port##_putc (const char c) {\
69 serial_putc_dev(port, c);}\
70 void s3serial##port##_puts (const char *s) {\
71 serial_puts_dev(port, s);}
73 #define INIT_S3C_SERIAL_STRUCTURE(port,name,bus) {\
76 s3serial##port##_init,\
77 s3serial##port##_setbrg,\
78 s3serial##port##_getc,\
79 s3serial##port##_tstc,\
80 s3serial##port##_putc,\
81 s3serial##port##_puts, }
83 #endif /* CONFIG_SERIAL_MULTI */
85 void _serial_setbrg(const int dev_index
)
87 S3C24X0_UART
* const uart
= S3C24X0_GetBase_UART(dev_index
);
91 /* value is calculated so : (int)(PCLK/16./baudrate) -1 */
92 reg
= get_PCLK() / (16 * gd
->baudrate
) - 1;
95 for (i
= 0; i
< 100; i
++);
97 #if defined(CONFIG_SERIAL_MULTI)
99 serial_setbrg_dev(unsigned int dev_index
)
101 _serial_setbrg(dev_index
);
104 void serial_setbrg(void)
106 _serial_setbrg(UART_NR
);
111 /* Initialise the serial port. The settings are always 8 data bits, no parity,
112 * 1 stop bit, no start bits.
114 static int serial_init_dev(const int dev_index
)
116 S3C24X0_UART
* const uart
= S3C24X0_GetBase_UART(dev_index
);
118 /* FIFO enable, Tx/Rx FIFO clear */
122 /* Normal,No parity,1 stop,8 bit */
125 * tx=level,rx=edge,disable timeout int.,enable rx error int.,
126 * normal,interrupt or polling
131 uart
->UMCON
= 0x1; /* RTS up */
134 /* FIXME: This is sooooooooooooooooooo ugly */
136 #if defined(CONFIG_GTA02_REVISION)
137 /* we need auto hw flow control on the gsm and gps port */
138 if (dev_index
== 0 || dev_index
== 1)
141 _serial_setbrg(dev_index
);
146 #if !defined(CONFIG_SERIAL_MULTI)
147 /* Initialise the serial port. The settings are always 8 data bits, no parity,
148 * 1 stop bit, no start bits.
150 int serial_init (void)
152 return serial_init_dev(UART_NR
);
157 * Read a single byte from the serial port. Returns 1 on success, 0
158 * otherwise. When the function is succesfull, the character read is
159 * written into its argument c.
161 int _serial_getc (const int dev_index
)
163 S3C24X0_UART
* const uart
= S3C24X0_GetBase_UART(dev_index
);
165 /* wait for character to arrive */
166 while (!(uart
->UTRSTAT
& 0x1));
168 return uart
->URXH
& 0xff;
170 #if defined(CONFIG_SERIAL_MULTI)
171 static inline int serial_getc_dev(unsigned int dev_index
)
173 return _serial_getc(dev_index
);
176 int serial_getc (void)
178 return _serial_getc(UART_NR
);
183 static int hwflow
= 0; /* turned off by default */
184 int hwflow_onoff(int on
)
189 break; /* return current */
191 hwflow
= 1; /* turn on */
194 hwflow
= 0; /* turn off */
201 #ifdef CONFIG_MODEM_SUPPORT
202 static int be_quiet
= 0;
203 void disable_putc(void)
208 void enable_putc(void)
216 * Output a single byte to the serial port.
218 void _serial_putc (const char c
, const int dev_index
)
220 S3C24X0_UART
* const uart
= S3C24X0_GetBase_UART(dev_index
);
221 #ifdef CONFIG_MODEM_SUPPORT
226 /* wait for room in the tx FIFO */
227 while (!(uart
->UTRSTAT
& 0x2));
230 /* Wait for CTS up */
231 while(hwflow
&& !(uart
->UMSTAT
& 0x1))
237 /* If \n, also do \r */
241 #if defined(CONFIG_SERIAL_MULTI)
242 static inline void serial_putc_dev(unsigned int dev_index
, const char c
)
244 _serial_putc(c
, dev_index
);
247 void serial_putc(const char c
)
249 _serial_putc(c
, UART_NR
);
255 * Test whether a character is in the RX buffer
257 int _serial_tstc(const int dev_index
)
259 S3C24X0_UART
* const uart
= S3C24X0_GetBase_UART(dev_index
);
261 return uart
->UTRSTAT
& 0x1;
263 #if defined(CONFIG_SERIAL_MULTI)
265 serial_tstc_dev(unsigned int dev_index
)
267 return _serial_tstc(dev_index
);
270 int serial_tstc(void)
272 return _serial_tstc(UART_NR
);
276 void _serial_puts(const char *s
, const int dev_index
)
279 _serial_putc (*s
++, dev_index
);
282 #if defined(CONFIG_SERIAL_MULTI)
284 serial_puts_dev(int dev_index
, const char *s
)
286 _serial_puts(s
, dev_index
);
290 serial_puts (const char *s
)
292 _serial_puts(s
, UART_NR
);
296 #if defined(CONFIG_SERIAL_MULTI)
297 DECLARE_S3C_SERIAL_FUNCTIONS(0);
298 struct serial_device s3c24xx_serial0_device
=
299 INIT_S3C_SERIAL_STRUCTURE(0, "s3ser0", "S3UART1");
300 DECLARE_S3C_SERIAL_FUNCTIONS(1);
301 struct serial_device s3c24xx_serial1_device
=
302 INIT_S3C_SERIAL_STRUCTURE(1, "s3ser1", "S3UART2");
303 DECLARE_S3C_SERIAL_FUNCTIONS(2);
304 struct serial_device s3c24xx_serial2_device
=
305 INIT_S3C_SERIAL_STRUCTURE(2, "s3ser2", "S3UART3");
307 #endif /* CONFIG_SERIAL_MULTI */
309 #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) ||
310 defined(CONFIG_S3C2440) || defined (CONFIG_S3C2442) ||
311 defined (CONFIG_TRAB) */