]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/serial.c
505c2c6b8985c0361ce30de251f71b02fdbc6ce1
[karo-tx-uboot.git] / common / serial.c
1 /*
2  * (C) Copyright 2004
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <serial.h>
26 #include <stdio_dev.h>
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 static struct serial_device *serial_devices = NULL;
31 static struct serial_device *serial_current = NULL;
32
33 int serial_register (struct serial_device *dev)
34 {
35 #ifdef CONFIG_NEEDS_MANUAL_RELOC
36         dev->init += gd->reloc_off;
37         dev->setbrg += gd->reloc_off;
38         dev->getc += gd->reloc_off;
39         dev->tstc += gd->reloc_off;
40         dev->putc += gd->reloc_off;
41         dev->puts += gd->reloc_off;
42 #endif
43
44         dev->next = serial_devices;
45         serial_devices = dev;
46
47         return 0;
48 }
49
50 void serial_initialize (void)
51 {
52 #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
53         serial_register (&serial_smc_device);
54 #endif
55 #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
56  || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
57         serial_register (&serial_scc_device);
58 #endif
59
60 #if defined(CONFIG_SYS_NS16550_SERIAL)
61 #if defined(CONFIG_SYS_NS16550_COM1)
62         serial_register(&eserial1_device);
63 #endif
64 #if defined(CONFIG_SYS_NS16550_COM2)
65         serial_register(&eserial2_device);
66 #endif
67 #if defined(CONFIG_SYS_NS16550_COM3)
68         serial_register(&eserial3_device);
69 #endif
70 #if defined(CONFIG_SYS_NS16550_COM4)
71         serial_register(&eserial4_device);
72 #endif
73 #endif /* CONFIG_SYS_NS16550_SERIAL */
74 #if defined (CONFIG_FFUART)
75         serial_register(&serial_ffuart_device);
76 #endif
77 #if defined (CONFIG_BTUART)
78         serial_register(&serial_btuart_device);
79 #endif
80 #if defined (CONFIG_STUART)
81         serial_register(&serial_stuart_device);
82 #endif
83 #if defined(CONFIG_S3C2410)
84         serial_register(&s3c24xx_serial0_device);
85         serial_register(&s3c24xx_serial1_device);
86         serial_register(&s3c24xx_serial2_device);
87 #endif
88 #if defined(CONFIG_S5P)
89         serial_register(&s5p_serial0_device);
90         serial_register(&s5p_serial1_device);
91         serial_register(&s5p_serial2_device);
92         serial_register(&s5p_serial3_device);
93 #endif
94 #if defined(CONFIG_MPC512X)
95 #if defined(CONFIG_SYS_PSC1)
96         serial_register(&serial1_device);
97 #endif
98 #if defined(CONFIG_SYS_PSC3)
99         serial_register(&serial3_device);
100 #endif
101 #if defined(CONFIG_SYS_PSC4)
102         serial_register(&serial4_device);
103 #endif
104 #if defined(CONFIG_SYS_PSC6)
105         serial_register(&serial6_device);
106 #endif
107 #endif
108         serial_assign (default_serial_console ()->name);
109 }
110
111 void serial_stdio_init (void)
112 {
113         struct stdio_dev dev;
114         struct serial_device *s = serial_devices;
115
116         while (s) {
117                 memset (&dev, 0, sizeof (dev));
118
119                 strcpy (dev.name, s->name);
120                 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
121
122                 dev.start = s->init;
123                 dev.stop = s->uninit;
124                 dev.putc = s->putc;
125                 dev.puts = s->puts;
126                 dev.getc = s->getc;
127                 dev.tstc = s->tstc;
128
129                 stdio_register (&dev);
130
131                 s = s->next;
132         }
133 }
134
135 int serial_assign (char *name)
136 {
137         struct serial_device *s;
138
139         for (s = serial_devices; s; s = s->next) {
140                 if (strcmp (s->name, name) == 0) {
141                         serial_current = s;
142                         return 0;
143                 }
144         }
145
146         return 1;
147 }
148
149 void serial_reinit_all (void)
150 {
151         struct serial_device *s;
152
153         for (s = serial_devices; s; s = s->next) {
154                 s->init ();
155         }
156 }
157
158 int serial_init (void)
159 {
160         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
161                 struct serial_device *dev = default_serial_console ();
162
163                 return dev->init ();
164         }
165
166         return serial_current->init ();
167 }
168
169 void serial_setbrg (void)
170 {
171         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
172                 struct serial_device *dev = default_serial_console ();
173
174                 dev->setbrg ();
175                 return;
176         }
177
178         serial_current->setbrg ();
179 }
180
181 int serial_getc (void)
182 {
183         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
184                 struct serial_device *dev = default_serial_console ();
185
186                 return dev->getc ();
187         }
188
189         return serial_current->getc ();
190 }
191
192 int serial_tstc (void)
193 {
194         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
195                 struct serial_device *dev = default_serial_console ();
196
197                 return dev->tstc ();
198         }
199
200         return serial_current->tstc ();
201 }
202
203 void serial_putc (const char c)
204 {
205         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
206                 struct serial_device *dev = default_serial_console ();
207
208                 dev->putc (c);
209                 return;
210         }
211
212         serial_current->putc (c);
213 }
214
215 void serial_puts (const char *s)
216 {
217         if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
218                 struct serial_device *dev = default_serial_console ();
219
220                 dev->puts (s);
221                 return;
222         }
223
224         serial_current->puts (s);
225 }