3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
27 #include <linux/compiler.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 void (*sconsole_putc) (char) = 0;
34 void (*sconsole_puts) (const char *) = 0;
35 int (*sconsole_getc) (void) = 0;
36 int (*sconsole_tstc) (void) = 0;
37 void (*sconsole_setbrg) (void) = 0;
39 static int sconsole_serial_init(void)
41 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
45 sb->baud = gd->baudrate;
46 sb->max_size = CONFIG_SYS_SCONSOLE_SIZE - sizeof (sconsole_buffer_t);
51 static void sconsole_serial_putc(char c)
56 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
59 sb->data[sb->pos++] = c;
60 if (sb->pos == sb->max_size) {
63 if (sb->size < sb->max_size) {
70 static void sconsole_serial_puts(const char *s)
75 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
78 sb->data[sb->pos++] = *s++;
79 if (sb->pos == sb->max_size) {
82 if (sb->size < sb->max_size) {
89 static int sconsole_serial_getc(void)
92 return (*sconsole_getc) ();
98 static int sconsole_serial_tstc(void)
101 return (*sconsole_tstc) ();
107 static void sconsole_serial_setbrg(void)
109 if (sconsole_setbrg) {
110 (*sconsole_setbrg) ();
112 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
114 sb->baud = gd->baudrate;
118 #ifdef CONFIG_SERIAL_MULTI
119 static struct serial_device sconsole_serial_drv = {
120 .name = "sconsole_serial",
121 .start = sconsole_serial_init,
123 .setbrg = sconsole_serial_setbrg,
124 .putc = sconsole_serial_putc,
125 .puts = sconsole_serial_puts,
126 .getc = sconsole_serial_getc,
127 .tstc = sconsole_serial_tstc,
130 void sconsole_serial_initialize(void)
132 serial_register(&sconsole_serial_drv);
135 __weak struct serial_device *default_serial_console(void)
137 return &sconsole_serial_drv;
140 int serial_init(void)
142 return sconsole_serial_init();
145 void serial_setbrg(void)
147 sconsole_serial_setbrg();
150 void serial_putc(const char c)
152 sconsole_serial_putc(c);
155 void serial_puts(const char *s)
157 sconsole_serial_puts(s);
160 int serial_getc(void)
162 return sconsole_serial_getc();
165 int serial_tstc(void)
167 return sconsole_serial_tstc();
170 int sconsole_get_baudrate (void)
172 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
177 void sconsole_flush (void)
180 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
181 unsigned int end = sb->pos < sb->size
182 ? sb->pos + sb->max_size - sb->size
183 : sb->pos - sb->size;
186 (*sconsole_putc) (sb->data[end++]);
187 if (end == sb->max_size) {