blob: bf7740950fd339ed20275f675e93f9acf3965d36 [file] [log] [blame]
wdenk281e00a2004-08-01 22:48:16 +00001/*
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>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020026#include <stdio_dev.h>
wdenk281e00a2004-08-01 22:48:16 +000027
Wolfgang Denkd87080b2006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
wdenk281e00a2004-08-01 22:48:16 +000030static struct serial_device *serial_devices = NULL;
31static struct serial_device *serial_current = NULL;
32
Mike Frysingerc52b4f72011-04-29 18:03:30 +000033void serial_register(struct serial_device *dev)
wdenk281e00a2004-08-01 22:48:16 +000034{
Wolfgang Denk2e5167c2010-10-28 20:00:11 +020035#ifdef CONFIG_NEEDS_MANUAL_RELOC
wdenk281e00a2004-08-01 22:48:16 +000036 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;
Peter Tyser521af042009-09-21 11:20:36 -050042#endif
wdenk281e00a2004-08-01 22:48:16 +000043
44 dev->next = serial_devices;
45 serial_devices = dev;
wdenk281e00a2004-08-01 22:48:16 +000046}
47
wdenk2ee66532004-10-11 22:43:02 +000048void serial_initialize (void)
wdenk281e00a2004-08-01 22:48:16 +000049{
50#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
wdenk2ee66532004-10-11 22:43:02 +000051 serial_register (&serial_smc_device);
wdenk281e00a2004-08-01 22:48:16 +000052#endif
53#if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
54 || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
wdenk2ee66532004-10-11 22:43:02 +000055 serial_register (&serial_scc_device);
wdenk281e00a2004-08-01 22:48:16 +000056#endif
57
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020058#if defined(CONFIG_SYS_NS16550_SERIAL)
59#if defined(CONFIG_SYS_NS16550_COM1)
Wolfgang Denk0fd30252006-08-30 23:02:10 +020060 serial_register(&eserial1_device);
61#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020062#if defined(CONFIG_SYS_NS16550_COM2)
Wolfgang Denk0fd30252006-08-30 23:02:10 +020063 serial_register(&eserial2_device);
64#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065#if defined(CONFIG_SYS_NS16550_COM3)
Wolfgang Denk0fd30252006-08-30 23:02:10 +020066 serial_register(&eserial3_device);
67#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020068#if defined(CONFIG_SYS_NS16550_COM4)
Wolfgang Denk0fd30252006-08-30 23:02:10 +020069 serial_register(&eserial4_device);
70#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020071#endif /* CONFIG_SYS_NS16550_SERIAL */
stefano babic80172c62007-08-30 22:57:04 +020072#if defined (CONFIG_FFUART)
73 serial_register(&serial_ffuart_device);
74#endif
75#if defined (CONFIG_BTUART)
76 serial_register(&serial_btuart_device);
77#endif
78#if defined (CONFIG_STUART)
79 serial_register(&serial_stuart_device);
80#endif
Harald Weltea7c185e2007-12-19 14:24:40 +010081#if defined(CONFIG_S3C2410)
82 serial_register(&s3c24xx_serial0_device);
83 serial_register(&s3c24xx_serial1_device);
84 serial_register(&s3c24xx_serial2_device);
85#endif
Minkyu Kang889a2752010-08-23 19:52:03 +090086#if defined(CONFIG_S5P)
Minkyu Kang46a3b5c2010-03-24 16:59:30 +090087 serial_register(&s5p_serial0_device);
88 serial_register(&s5p_serial1_device);
89 serial_register(&s5p_serial2_device);
90 serial_register(&s5p_serial3_device);
Minkyu Kangdd2c9e62009-10-01 17:20:28 +090091#endif
Anatolij Gustschine3b28e62010-04-24 19:27:05 +020092#if defined(CONFIG_MPC512X)
93#if defined(CONFIG_SYS_PSC1)
94 serial_register(&serial1_device);
95#endif
96#if defined(CONFIG_SYS_PSC3)
97 serial_register(&serial3_device);
98#endif
99#if defined(CONFIG_SYS_PSC4)
100 serial_register(&serial4_device);
101#endif
102#if defined(CONFIG_SYS_PSC6)
103 serial_register(&serial6_device);
104#endif
105#endif
wdenk2ee66532004-10-11 22:43:02 +0000106 serial_assign (default_serial_console ()->name);
wdenk281e00a2004-08-01 22:48:16 +0000107}
108
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200109void serial_stdio_init (void)
wdenk281e00a2004-08-01 22:48:16 +0000110{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200111 struct stdio_dev dev;
wdenk281e00a2004-08-01 22:48:16 +0000112 struct serial_device *s = serial_devices;
113
wdenk2ee66532004-10-11 22:43:02 +0000114 while (s) {
wdenk281e00a2004-08-01 22:48:16 +0000115 memset (&dev, 0, sizeof (dev));
116
117 strcpy (dev.name, s->name);
118 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
119
120 dev.start = s->init;
Anatolij Gustschine3b28e62010-04-24 19:27:05 +0200121 dev.stop = s->uninit;
wdenk281e00a2004-08-01 22:48:16 +0000122 dev.putc = s->putc;
123 dev.puts = s->puts;
124 dev.getc = s->getc;
125 dev.tstc = s->tstc;
126
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200127 stdio_register (&dev);
wdenk281e00a2004-08-01 22:48:16 +0000128
129 s = s->next;
130 }
131}
132
wdenk2ee66532004-10-11 22:43:02 +0000133int serial_assign (char *name)
wdenk281e00a2004-08-01 22:48:16 +0000134{
135 struct serial_device *s;
136
wdenk2ee66532004-10-11 22:43:02 +0000137 for (s = serial_devices; s; s = s->next) {
138 if (strcmp (s->name, name) == 0) {
wdenk281e00a2004-08-01 22:48:16 +0000139 serial_current = s;
140 return 0;
141 }
142 }
143
144 return 1;
145}
146
wdenk2ee66532004-10-11 22:43:02 +0000147void serial_reinit_all (void)
wdenk281e00a2004-08-01 22:48:16 +0000148{
149 struct serial_device *s;
150
wdenk2ee66532004-10-11 22:43:02 +0000151 for (s = serial_devices; s; s = s->next) {
152 s->init ();
wdenk281e00a2004-08-01 22:48:16 +0000153 }
154}
155
wdenk2ee66532004-10-11 22:43:02 +0000156int serial_init (void)
wdenk281e00a2004-08-01 22:48:16 +0000157{
wdenk2ee66532004-10-11 22:43:02 +0000158 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
159 struct serial_device *dev = default_serial_console ();
160
161 return dev->init ();
wdenk281e00a2004-08-01 22:48:16 +0000162 }
163
wdenk2ee66532004-10-11 22:43:02 +0000164 return serial_current->init ();
wdenk281e00a2004-08-01 22:48:16 +0000165}
166
wdenk2ee66532004-10-11 22:43:02 +0000167void serial_setbrg (void)
wdenk281e00a2004-08-01 22:48:16 +0000168{
wdenk2ee66532004-10-11 22:43:02 +0000169 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
170 struct serial_device *dev = default_serial_console ();
171
172 dev->setbrg ();
wdenk281e00a2004-08-01 22:48:16 +0000173 return;
174 }
175
wdenk2ee66532004-10-11 22:43:02 +0000176 serial_current->setbrg ();
wdenk281e00a2004-08-01 22:48:16 +0000177}
178
wdenk2ee66532004-10-11 22:43:02 +0000179int serial_getc (void)
wdenk281e00a2004-08-01 22:48:16 +0000180{
wdenk2ee66532004-10-11 22:43:02 +0000181 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
182 struct serial_device *dev = default_serial_console ();
183
184 return dev->getc ();
wdenk281e00a2004-08-01 22:48:16 +0000185 }
186
wdenk2ee66532004-10-11 22:43:02 +0000187 return serial_current->getc ();
wdenk281e00a2004-08-01 22:48:16 +0000188}
189
wdenk2ee66532004-10-11 22:43:02 +0000190int serial_tstc (void)
wdenk281e00a2004-08-01 22:48:16 +0000191{
wdenk2ee66532004-10-11 22:43:02 +0000192 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
193 struct serial_device *dev = default_serial_console ();
194
195 return dev->tstc ();
wdenk281e00a2004-08-01 22:48:16 +0000196 }
197
wdenk2ee66532004-10-11 22:43:02 +0000198 return serial_current->tstc ();
wdenk281e00a2004-08-01 22:48:16 +0000199}
200
wdenk2ee66532004-10-11 22:43:02 +0000201void serial_putc (const char c)
wdenk281e00a2004-08-01 22:48:16 +0000202{
wdenk2ee66532004-10-11 22:43:02 +0000203 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
204 struct serial_device *dev = default_serial_console ();
205
206 dev->putc (c);
wdenk281e00a2004-08-01 22:48:16 +0000207 return;
208 }
209
wdenk2ee66532004-10-11 22:43:02 +0000210 serial_current->putc (c);
wdenk281e00a2004-08-01 22:48:16 +0000211}
212
wdenk2ee66532004-10-11 22:43:02 +0000213void serial_puts (const char *s)
wdenk281e00a2004-08-01 22:48:16 +0000214{
wdenk2ee66532004-10-11 22:43:02 +0000215 if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
216 struct serial_device *dev = default_serial_console ();
217
218 dev->puts (s);
wdenk281e00a2004-08-01 22:48:16 +0000219 return;
220 }
221
wdenk2ee66532004-10-11 22:43:02 +0000222 serial_current->puts (s);
wdenk281e00a2004-08-01 22:48:16 +0000223}