]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amirix/ap1000/serial.c
2c2e9f9d7699593f82e328fc7f19c5037eb8f402
[karo-tx-uboot.git] / board / amirix / ap1000 / serial.c
1 /*
2  * (C) Copyright 2002
3  * Peter De Schrijver (p2@mind.be), Mind Linux Solutions, NV.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  *
20  */
21
22 #include <common.h>
23 #include <asm/u-boot.h>
24 #include <asm/processor.h>
25 #include <command.h>
26 #include <config.h>
27 #include <serial.h>
28 #include <linux/compiler.h>
29
30 #include <ns16550.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 const NS16550_t COM_PORTS[] =
35         { (NS16550_t) CONFIG_SYS_NS16550_COM1, (NS16550_t) CONFIG_SYS_NS16550_COM2 };
36
37 #undef CONFIG_SYS_DUART_CHAN
38 #define CONFIG_SYS_DUART_CHAN gComPort
39 static int gComPort = 0;
40
41 static int amirix_serial_init(void)
42 {
43         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
44
45         (void) NS16550_init (COM_PORTS[0], clock_divisor);
46         gComPort = 0;
47
48         return 0;
49 }
50
51 static void amirix_serial_putc(const char c)
52 {
53         if (c == '\n') {
54                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
55         }
56
57         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
58 }
59
60 static int amirix_serial_getc(void)
61 {
62         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
63 }
64
65 static int amirix_serial_tstc(void)
66 {
67         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
68 }
69
70 static void amirix_serial_setbrg(void)
71 {
72         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
73
74 #ifdef CONFIG_SYS_INIT_CHAN1
75         NS16550_reinit (COM_PORTS[0], clock_divisor);
76 #endif
77 #ifdef CONFIG_SYS_INIT_CHAN2
78         NS16550_reinit (COM_PORTS[1], clock_divisor);
79 #endif
80 }
81
82 static void amirix_serial_puts(const char *s)
83 {
84         while (*s) {
85                 serial_putc (*s++);
86         }
87 }
88
89 #ifdef CONFIG_SERIAL_MULTI
90 static struct serial_device amirix_serial_drv = {
91         .name   = "amirix_serial",
92         .start  = amirix_serial_init,
93         .stop   = NULL,
94         .setbrg = amirix_serial_setbrg,
95         .putc   = amirix_serial_putc,
96         .puts   = amirix_serial_puts,
97         .getc   = amirix_serial_getc,
98         .tstc   = amirix_serial_tstc,
99 };
100
101 void amirix_serial_initialize(void)
102 {
103         serial_register(&amirix_serial_drv);
104 }
105
106 __weak struct serial_device *default_serial_console(void)
107 {
108         return &amirix_serial_drv;
109 }
110 #else
111 int serial_init(void)
112 {
113         return amirix_serial_init();
114 }
115
116 void serial_setbrg(void)
117 {
118         amirix_serial_setbrg();
119 }
120
121 void serial_putc(const char c)
122 {
123         amirix_serial_putc(c);
124 }
125
126 void serial_puts(const char *s)
127 {
128         amirix_serial_puts(s);
129 }
130
131 int serial_getc(void)
132 {
133         return amirix_serial_getc();
134 }
135
136 int serial_tstc(void)
137 {
138         return amirix_serial_tstc();
139 }
140 #endif
141 #if defined(CONFIG_CMD_KGDB)
142 void kgdb_serial_init (void)
143 {
144 }
145
146 void putDebugChar (int c)
147 {
148         serial_putc (c);
149 }
150
151 void putDebugStr (const char *str)
152 {
153         serial_puts (str);
154 }
155
156 int getDebugChar (void)
157 {
158         return serial_getc ();
159 }
160
161 void kgdb_interruptible (int yes)
162 {
163         return;
164 }
165 #endif