]>
Commit | Line | Data |
---|---|---|
281e00a3 WD |
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 <devices.h> | |
27 | ||
28 | #if defined(CONFIG_SERIAL_MULTI) | |
29 | ||
30 | static struct serial_device *serial_devices = NULL; | |
31 | static struct serial_device *serial_current = NULL; | |
32 | ||
33 | #ifndef CONFIG_LWMON | |
2ee66533 | 34 | struct serial_device *default_serial_console (void) |
281e00a3 WD |
35 | { |
36 | #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2) | |
37 | return &serial_smc_device; | |
38 | #elif defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \ | |
39 | || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4) | |
40 | return &serial_scc_device; | |
41 | #else | |
42 | #error No default console | |
43 | #endif | |
44 | } | |
45 | #endif | |
46 | ||
2ee66533 | 47 | static int serial_register (struct serial_device *dev) |
281e00a3 WD |
48 | { |
49 | DECLARE_GLOBAL_DATA_PTR; | |
50 | ||
51 | dev->init += gd->reloc_off; | |
52 | dev->setbrg += gd->reloc_off; | |
53 | dev->getc += gd->reloc_off; | |
54 | dev->tstc += gd->reloc_off; | |
55 | dev->putc += gd->reloc_off; | |
56 | dev->puts += gd->reloc_off; | |
57 | ||
58 | dev->next = serial_devices; | |
59 | serial_devices = dev; | |
60 | ||
61 | return 0; | |
62 | } | |
63 | ||
2ee66533 | 64 | void serial_initialize (void) |
281e00a3 WD |
65 | { |
66 | #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2) | |
2ee66533 | 67 | serial_register (&serial_smc_device); |
281e00a3 WD |
68 | #endif |
69 | #if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \ | |
70 | || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4) | |
2ee66533 | 71 | serial_register (&serial_scc_device); |
281e00a3 WD |
72 | #endif |
73 | ||
2ee66533 | 74 | serial_assign (default_serial_console ()->name); |
281e00a3 WD |
75 | } |
76 | ||
2ee66533 | 77 | void serial_devices_init (void) |
281e00a3 WD |
78 | { |
79 | device_t dev; | |
80 | struct serial_device *s = serial_devices; | |
81 | ||
2ee66533 | 82 | while (s) { |
281e00a3 WD |
83 | memset (&dev, 0, sizeof (dev)); |
84 | ||
85 | strcpy (dev.name, s->name); | |
86 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT; | |
87 | ||
88 | dev.start = s->init; | |
89 | dev.putc = s->putc; | |
90 | dev.puts = s->puts; | |
91 | dev.getc = s->getc; | |
92 | dev.tstc = s->tstc; | |
93 | ||
94 | device_register (&dev); | |
95 | ||
96 | s = s->next; | |
97 | } | |
98 | } | |
99 | ||
2ee66533 | 100 | int serial_assign (char *name) |
281e00a3 WD |
101 | { |
102 | struct serial_device *s; | |
103 | ||
2ee66533 WD |
104 | for (s = serial_devices; s; s = s->next) { |
105 | if (strcmp (s->name, name) == 0) { | |
281e00a3 WD |
106 | serial_current = s; |
107 | return 0; | |
108 | } | |
109 | } | |
110 | ||
111 | return 1; | |
112 | } | |
113 | ||
2ee66533 | 114 | void serial_reinit_all (void) |
281e00a3 WD |
115 | { |
116 | struct serial_device *s; | |
117 | ||
2ee66533 WD |
118 | for (s = serial_devices; s; s = s->next) { |
119 | s->init (); | |
281e00a3 WD |
120 | } |
121 | } | |
122 | ||
2ee66533 | 123 | int serial_init (void) |
281e00a3 | 124 | { |
2ee66533 | 125 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 126 | |
2ee66533 WD |
127 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
128 | struct serial_device *dev = default_serial_console (); | |
129 | ||
130 | return dev->init (); | |
281e00a3 WD |
131 | } |
132 | ||
2ee66533 | 133 | return serial_current->init (); |
281e00a3 WD |
134 | } |
135 | ||
2ee66533 | 136 | void serial_setbrg (void) |
281e00a3 | 137 | { |
2ee66533 | 138 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 139 | |
2ee66533 WD |
140 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
141 | struct serial_device *dev = default_serial_console (); | |
142 | ||
143 | dev->setbrg (); | |
281e00a3 WD |
144 | return; |
145 | } | |
146 | ||
2ee66533 | 147 | serial_current->setbrg (); |
281e00a3 WD |
148 | } |
149 | ||
2ee66533 | 150 | int serial_getc (void) |
281e00a3 | 151 | { |
2ee66533 | 152 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 153 | |
2ee66533 WD |
154 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
155 | struct serial_device *dev = default_serial_console (); | |
156 | ||
157 | return dev->getc (); | |
281e00a3 WD |
158 | } |
159 | ||
2ee66533 | 160 | return serial_current->getc (); |
281e00a3 WD |
161 | } |
162 | ||
2ee66533 | 163 | int serial_tstc (void) |
281e00a3 | 164 | { |
2ee66533 | 165 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 166 | |
2ee66533 WD |
167 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
168 | struct serial_device *dev = default_serial_console (); | |
169 | ||
170 | return dev->tstc (); | |
281e00a3 WD |
171 | } |
172 | ||
2ee66533 | 173 | return serial_current->tstc (); |
281e00a3 WD |
174 | } |
175 | ||
2ee66533 | 176 | void serial_putc (const char c) |
281e00a3 | 177 | { |
2ee66533 | 178 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 179 | |
2ee66533 WD |
180 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
181 | struct serial_device *dev = default_serial_console (); | |
182 | ||
183 | dev->putc (c); | |
281e00a3 WD |
184 | return; |
185 | } | |
186 | ||
2ee66533 | 187 | serial_current->putc (c); |
281e00a3 WD |
188 | } |
189 | ||
2ee66533 | 190 | void serial_puts (const char *s) |
281e00a3 | 191 | { |
2ee66533 | 192 | DECLARE_GLOBAL_DATA_PTR; |
8b74bf31 | 193 | |
2ee66533 WD |
194 | if (!(gd->flags & GD_FLG_RELOC) || !serial_current) { |
195 | struct serial_device *dev = default_serial_console (); | |
196 | ||
197 | dev->puts (s); | |
281e00a3 WD |
198 | return; |
199 | } | |
200 | ||
2ee66533 | 201 | serial_current->puts (s); |
281e00a3 WD |
202 | } |
203 | ||
204 | #endif /* CONFIG_SERIAL_MULTI */ |