3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
13 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <linux/compiler.h>
36 DECLARE_GLOBAL_DATA_PTR;
38 static void sa1100_serial_setbrg(void)
42 if (gd->baudrate == 1200)
44 else if (gd->baudrate == 9600)
46 else if (gd->baudrate == 19200)
48 else if (gd->baudrate == 38400)
50 else if (gd->baudrate == 57600)
52 else if (gd->baudrate == 115200)
58 /* SA1110 uart function */
59 Ser1SDCR0 |= SDCR0_SUS;
61 /* Wait until port is ready ... */
62 while(Ser1UTSR1 & UTSR1_TBY) {}
64 /* init serial serial 1 */
67 Ser1UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData );
70 Ser1UTCR3 = ( UTCR3_RXE | UTCR3_TXE );
71 #elif defined(CONFIG_SERIAL3)
72 /* Wait until port is ready ... */
73 while (Ser3UTSR1 & UTSR1_TBY) {
76 /* init serial serial 3 */
79 Ser3UTCR0 = (UTCR0_1StpBit | UTCR0_8BitData);
81 Ser3UTCR2 = (u32) reg;
82 Ser3UTCR3 = (UTCR3_RXE | UTCR3_TXE);
84 #error "Bad: you didn't configured serial ..."
90 * Initialise the serial port with the given baudrate. The settings
91 * are always 8 data bits, no parity, 1 stop bit, no start bits.
94 static int sa1100_serial_init(void)
103 * Output a single byte to the serial port.
105 static void sa1100_serial_putc(const char c)
107 #ifdef CONFIG_SERIAL1
108 /* wait for room in the tx FIFO on SERIAL1 */
109 while ((Ser1UTSR0 & UTSR0_TFS) == 0);
112 #elif defined(CONFIG_SERIAL3)
113 /* wait for room in the tx FIFO on SERIAL3 */
114 while ((Ser3UTSR0 & UTSR0_TFS) == 0);
119 /* If \n, also do \r */
125 * Read a single byte from the serial port. Returns 1 on success, 0
126 * otherwise. When the function is succesfull, the character read is
127 * written into its argument c.
129 static int sa1100_serial_tstc(void)
131 #ifdef CONFIG_SERIAL1
132 return Ser1UTSR1 & UTSR1_RNE;
133 #elif defined(CONFIG_SERIAL3)
134 return Ser3UTSR1 & UTSR1_RNE;
139 * Read a single byte from the serial port. Returns 1 on success, 0
140 * otherwise. When the function is succesfull, the character read is
141 * written into its argument c.
143 static int sa1100_serial_getc(void)
145 #ifdef CONFIG_SERIAL1
146 while (!(Ser1UTSR1 & UTSR1_RNE));
148 return (char) Ser1UTDR & 0xff;
149 #elif defined(CONFIG_SERIAL3)
150 while (!(Ser3UTSR1 & UTSR1_RNE));
152 return (char) Ser3UTDR & 0xff;
156 static struct serial_device sa1100_serial_drv = {
157 .name = "sa1100_serial",
158 .start = sa1100_serial_init,
160 .setbrg = sa1100_serial_setbrg,
161 .putc = sa1100_serial_putc,
162 .puts = default_serial_puts,
163 .getc = sa1100_serial_getc,
164 .tstc = sa1100_serial_tstc,
167 void sa1100_serial_initialize(void)
169 serial_register(&sa1100_serial_drv);
172 __weak struct serial_device *default_serial_console(void)
174 return &sa1100_serial_drv;