]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/serial/serial_sa1100.c
Merge remote-tracking branch 'u-boot-ti/master'
[karo-tx-uboot.git] / drivers / serial / serial_sa1100.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * (C) Copyright 2002
10  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11  * Alex Zuepke <azu@sysgo.de>
12  *
13  * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
14  *
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.
19  *
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.
24  *
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
28  *
29  */
30
31 #include <common.h>
32 #include <SA-1100.h>
33 #include <serial.h>
34 #include <linux/compiler.h>
35
36 DECLARE_GLOBAL_DATA_PTR;
37
38 static void sa1100_serial_setbrg(void)
39 {
40         unsigned int reg = 0;
41
42         if (gd->baudrate == 1200)
43                 reg = 191;
44         else if (gd->baudrate == 9600)
45                 reg = 23;
46         else if (gd->baudrate == 19200)
47                 reg = 11;
48         else if (gd->baudrate == 38400)
49                 reg = 5;
50         else if (gd->baudrate == 57600)
51                 reg = 3;
52         else if (gd->baudrate == 115200)
53                 reg = 1;
54         else
55                 hang ();
56
57 #ifdef CONFIG_SERIAL1
58         /* SA1110 uart function */
59         Ser1SDCR0 |= SDCR0_SUS;
60
61         /* Wait until port is ready ... */
62         while(Ser1UTSR1 & UTSR1_TBY) {}
63
64         /* init serial serial 1 */
65         Ser1UTCR3 = 0x00;
66         Ser1UTSR0 = 0xff;
67         Ser1UTCR0 = ( UTCR0_1StpBit | UTCR0_8BitData );
68         Ser1UTCR1 = 0;
69         Ser1UTCR2 = (u32)reg;
70         Ser1UTCR3 = ( UTCR3_RXE | UTCR3_TXE );
71 #elif defined(CONFIG_SERIAL3)
72         /* Wait until port is ready ... */
73         while (Ser3UTSR1 & UTSR1_TBY) {
74         }
75
76         /* init serial serial 3 */
77         Ser3UTCR3 = 0x00;
78         Ser3UTSR0 = 0xff;
79         Ser3UTCR0 = (UTCR0_1StpBit | UTCR0_8BitData);
80         Ser3UTCR1 = 0;
81         Ser3UTCR2 = (u32) reg;
82         Ser3UTCR3 = (UTCR3_RXE | UTCR3_TXE);
83 #else
84 #error "Bad: you didn't configured serial ..."
85 #endif
86 }
87
88
89 /*
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.
92  *
93  */
94 static int sa1100_serial_init(void)
95 {
96         serial_setbrg ();
97
98         return (0);
99 }
100
101
102 /*
103  * Output a single byte to the serial port.
104  */
105 static void sa1100_serial_putc(const char c)
106 {
107 #ifdef CONFIG_SERIAL1
108         /* wait for room in the tx FIFO on SERIAL1 */
109         while ((Ser1UTSR0 & UTSR0_TFS) == 0);
110
111         Ser1UTDR = c;
112 #elif defined(CONFIG_SERIAL3)
113         /* wait for room in the tx FIFO on SERIAL3 */
114         while ((Ser3UTSR0 & UTSR0_TFS) == 0);
115
116         Ser3UTDR = c;
117 #endif
118
119         /* If \n, also do \r */
120         if (c == '\n')
121                 serial_putc ('\r');
122 }
123
124 /*
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.
128  */
129 static int sa1100_serial_tstc(void)
130 {
131 #ifdef CONFIG_SERIAL1
132         return Ser1UTSR1 & UTSR1_RNE;
133 #elif defined(CONFIG_SERIAL3)
134         return Ser3UTSR1 & UTSR1_RNE;
135 #endif
136 }
137
138 /*
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.
142  */
143 static int sa1100_serial_getc(void)
144 {
145 #ifdef CONFIG_SERIAL1
146         while (!(Ser1UTSR1 & UTSR1_RNE));
147
148         return (char) Ser1UTDR & 0xff;
149 #elif defined(CONFIG_SERIAL3)
150         while (!(Ser3UTSR1 & UTSR1_RNE));
151
152         return (char) Ser3UTDR & 0xff;
153 #endif
154 }
155
156 static struct serial_device sa1100_serial_drv = {
157         .name   = "sa1100_serial",
158         .start  = sa1100_serial_init,
159         .stop   = NULL,
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,
165 };
166
167 void sa1100_serial_initialize(void)
168 {
169         serial_register(&sa1100_serial_drv);
170 }
171
172 __weak struct serial_device *default_serial_console(void)
173 {
174         return &sa1100_serial_drv;
175 }