]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/glsdk-u-boot.git/blob - drivers/serial/serial_s3c44b0.c
Merge remote-tracking branch 'u-boot-atmel/master'
[glsdk/glsdk-u-boot.git] / drivers / serial / serial_s3c44b0.c
1 /*
2  * (C) Copyright 2004
3  * DAVE Srl
4  * http://www.dave-tech.it
5  * http://www.wawnet.biz
6  * mailto:info@wawnet.biz
7  *
8  * (C) Copyright 2002-2004
9  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
10  *
11  * (C) Copyright 2002
12  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13  * Marius Groeger <mgroeger@sysgo.de>
14  *
15  * (C) Copyright 2002
16  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
17  * Alex Zuepke <azu@sysgo.de>
18  *
19  * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
20  *
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, write to the Free Software
33  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
34  *
35  */
37 #include <common.h>
38 #include <asm/hardware.h>
40 DECLARE_GLOBAL_DATA_PTR;
42 /* flush serial input queue. returns 0 on success or negative error
43  * number otherwise
44  */
45 static int serial_flush_input(void)
46 {
47         volatile u32 tmp;
49         /* keep on reading as long as the receiver is not empty */
50         while(UTRSTAT0&0x01) {
51                 tmp = REGB(URXH0);
52         }
54         return 0;
55 }
58 /* flush output queue. returns 0 on success or negative error number
59  * otherwise
60  */
61 static int serial_flush_output(void)
62 {
63         /* wait until the transmitter is no longer busy */
64         while(!(UTRSTAT0 & 0x02)) {
65         }
67         return 0;
68 }
71 static void s3c44b0_serial_setbrg(void)
72 {
73         u32 divisor = 0;
75         /* get correct divisor */
76         switch(gd->baudrate) {
78         case 1200:
79 #if CONFIG_S3C44B0_CLOCK_SPEED==66
80                 divisor = 3124;
81 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
82                 divisor = 3905;
83 #else
84 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
85 #endif
86                 break;
88         case 9600:
89 #if CONFIG_S3C44B0_CLOCK_SPEED==66
90                 divisor = 390;
91 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
92                 divisor = 487;
93 #else
94 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
95 #endif
96                 break;
98         case 19200:
99 #if CONFIG_S3C44B0_CLOCK_SPEED==66
100                 divisor = 194;
101 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
102                 divisor = 243;
103 #else
104 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
105 #endif
106                 break;
108         case 38400:
109 #if CONFIG_S3C44B0_CLOCK_SPEED==66
110                 divisor = 97;
111 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
112                 divisor = 121;
113 #else
114 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
115 #endif  /* break; */
117         case 57600:
118 #if CONFIG_S3C44B0_CLOCK_SPEED==66
119                 divisor = 64;
120 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
121                 divisor = 80;
122 #else
123 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
124 #endif  /* break; */
126         case 115200:
127 #if CONFIG_S3C44B0_CLOCK_SPEED==66
128                 divisor = 32;
129 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
130                 divisor = 40;
131 #else
132 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
133 #endif  /* break; */
134         }
136         serial_flush_output();
137         serial_flush_input();
138         UFCON0 = 0x0;
139         ULCON0 = 0x03;
140         UCON0 = 0x05;
141         UBRDIV0 = divisor;
143         UFCON1 = 0x0;
144         ULCON1 = 0x03;
145         UCON1 = 0x05;
146         UBRDIV1 = divisor;
148         for(divisor=0; divisor<100; divisor++) {
149                 /* NOP */
150         }
154 /*
155  * Initialise the serial port with the given baudrate. The settings
156  * are always 8 data bits, no parity, 1 stop bit, no start bits.
157  *
158  */
159 static int s3c44b0_serial_init(void)
161         serial_setbrg ();
163         return (0);
167 /*
168  * Output a single byte to the serial port.
169  */
170 static void s3c44b0_serial_putc(const char c)
172         /* wait for room in the transmit FIFO */
173         while(!(UTRSTAT0 & 0x02));
175         UTXH0 = (unsigned char)c;
177         /*
178                 to be polite with serial console add a line feed
179                 to the carriage return character
180         */
181         if (c=='\n')
182                 serial_putc('\r');
185 /*
186  * Read a single byte from the serial port. Returns 1 on success, 0
187  * otherwise. When the function is succesfull, the character read is
188  * written into its argument c.
189  */
190 static int s3c44b0_serial_tstc(void)
192         return (UTRSTAT0 & 0x01);
195 /*
196  * Read a single byte from the serial port. Returns 1 on success, 0
197  * otherwise. When the function is succesfull, the character read is
198  * written into its argument c.
199  */
200 static int s3c44b0_serial_getc(void)
202         int rv;
204         for(;;) {
205                 rv = s3c44b0_serial_tstc();
207                 if(rv > 0)
208                         return URXH0;
209         }
212 static struct serial_device s3c44b0_serial_drv = {
213         .name   = "s3c44b0_serial",
214         .start  = s3c44b0_serial_init,
215         .stop   = NULL,
216         .setbrg = s3c44b0_serial_setbrg,
217         .putc   = s3c44b0_serial_putc,
218         .puts   = default_serial_puts,
219         .getc   = s3c44b0_serial_getc,
220         .tstc   = s3c44b0_serial_tstc,
221 };
223 void s3c44b0_serial_initialize(void)
225         serial_register(&s3c44b0_serial_drv);
228 __weak struct serial_device *default_serial_console(void)
230         return &s3c44b0_serial_drv;