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 static struct serial_device sconsole_serial_drv = {
119 .name = "sconsole_serial",
120 .start = sconsole_serial_init,
122 .setbrg = sconsole_serial_setbrg,
123 .putc = sconsole_serial_putc,
124 .puts = sconsole_serial_puts,
125 .getc = sconsole_serial_getc,
126 .tstc = sconsole_serial_tstc,
129 void sconsole_serial_initialize(void)
131 serial_register(&sconsole_serial_drv);
134 __weak struct serial_device *default_serial_console(void)
136 return &sconsole_serial_drv;
139 int sconsole_get_baudrate (void)
141 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
146 void sconsole_flush (void)
149 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
150 unsigned int end = sb->pos < sb->size
151 ? sb->pos + sb->max_size - sb->size
152 : sb->pos - sb->size;
155 (*sconsole_putc) (sb->data[end++]);
156 if (end == sb->max_size) {