2 * Copyright (c) 2004 Cucy Systems (http://www.cucy.com)
3 * Curt Brune <curt@cucy.com>
7 * http://www.dave-tech.it
8 * http://www.wawnet.biz
9 * mailto:info@wawnet.biz
11 * (C) Copyright 2002-2004
12 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
15 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
16 * Marius Groeger <mgroeger@sysgo.de>
19 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
20 * Alex Zuepke <azu@sysgo.de>
22 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 * Description: UART/Serial interface for Samsung S3C4510B SoC
40 * Runtime Env: ARM7TDMI
42 * 03-02-04 Create (Curt Brune) curt@cucy.com
48 #include <asm/hardware.h>
49 #include "s3c4510b_uart.h"
51 DECLARE_GLOBAL_DATA_PTR;
55 /* flush serial input queue. returns 0 on success or negative error
58 static int serial_flush_input(void)
62 /* keep on reading as long as the receiver is not empty */
63 while( uart->m_stat.bf.rxReady) {
71 /* flush output queue. returns 0 on success or negative error number
74 static int serial_flush_output(void)
76 /* wait until the transmitter is no longer busy */
77 while( !uart->m_stat.bf.txBufEmpty);
83 void serial_setbrg (void)
85 UART_LINE_CTRL ulctrl;
89 serial_flush_output();
92 /* control register */
94 uctrl.bf.rxMode = 0x1;
96 uctrl.bf.txMode = 0x1;
98 uctrl.bf.sendBreak = 0x0;
99 uctrl.bf.loopBack = 0x0;
100 uart->m_ctrl.ui = uctrl.ui;
102 /* line control register */
104 ulctrl.bf.wordLen = 0x3; /* 8 bit data */
105 ulctrl.bf.nStop = 0x0; /* 1 stop bit */
106 ulctrl.bf.parity = 0x0; /* no parity */
107 ulctrl.bf.clk = 0x0; /* internal clock */
108 ulctrl.bf.infra_red = 0x0; /* no infra_red */
109 uart->m_lineCtrl.ui = ulctrl.ui;
113 /* see table on page 10-15 in SAMSUNG S3C4510B manual */
114 /* get correct divisor */
115 switch(gd->baudrate) {
116 case 1200: ubd.bf.cnt0 = 1301; break;
117 case 2400: ubd.bf.cnt0 = 650; break;
118 case 4800: ubd.bf.cnt0 = 324; break;
119 case 9600: ubd.bf.cnt0 = 162; break;
120 case 19200: ubd.bf.cnt0 = 80; break;
121 case 38400: ubd.bf.cnt0 = 40; break;
122 case 57600: ubd.bf.cnt0 = 26; break;
123 case 115200: ubd.bf.cnt0 = 13; break;
126 uart->m_baudDiv.ui = ubd.ui;
127 uart->m_baudCnt = 0x0;
128 uart->m_baudClk = 0x0;
134 * Initialise the serial port with the given baudrate. The settings
135 * are always 8 data bits, no parity, 1 stop bit, no start bits.
138 int serial_init (void)
141 #if CONFIG_SERIAL1 == 1
142 uart = (UART *)UART0_BASE;
143 #elif CONFIG_SERIAL1 == 2
144 uart = (UART *)UART1_BASE;
146 #error CONFIG_SERIAL1 not equal to 1 or 2
156 * Output a single byte to the serial port.
158 void serial_putc (const char c)
160 /* wait for room in the transmit FIFO */
161 while( !uart->m_stat.bf.txBufEmpty);
166 to be polite with serial console add a line feed
167 to the carriage return character
174 * Test if an input byte is ready from the serial port. Returns non-zero on
175 * success, 0 otherwise.
177 int serial_tstc (void)
179 return uart->m_stat.bf.rxReady;
183 * Read a single byte from the serial port. Returns 1 on success, 0
184 * otherwise. When the function is succesfull, the character read is
185 * written into its argument c.
187 int serial_getc (void)
195 return uart->m_rx & 0xFF;
200 void serial_puts (const char *s)
206 /* busy wait for tx complete */
207 while ( !uart->m_stat.bf.txComplete);
210 uart->m_ctrl.bf.sendBreak = 0;