]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/ml2/serial.c
0ed1150d905038fce288782eb97815bfe26913f3
[karo-tx-uboot.git] / board / ml2 / 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 <configs/ML2.h>
27 #include <serial.h>
28 #include <linux/compiler.h>
29
30 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
31 #include <ns16550.h>
32 #endif
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
37 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
38         (NS16550_t) CONFIG_SYS_NS16550_COM2
39 };
40 #endif
41
42 static int ml2_serial_init(void)
43 {
44         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
45
46 #ifdef CONFIG_SYS_INIT_CHAN1
47         (void) NS16550_init (COM_PORTS[0], clock_divisor);
48 #endif
49 #ifdef CONFIG_SYS_INIT_CHAN2
50         (void) NS16550_init (COM_PORTS[1], clock_divisor);
51 #endif
52         return 0;
53
54 }
55
56 static void ml2_serial_putc(const char c)
57 {
58         if (c == '\n')
59                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
60
61         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
62 }
63
64 static int ml2_serial_getc(void)
65 {
66         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
67 }
68
69 static int ml2_serial_tstc(void)
70 {
71         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
72 }
73
74 static void ml2_serial_setbrg(void)
75 {
76         int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
77
78 #ifdef CONFIG_SYS_INIT_CHAN1
79         NS16550_reinit (COM_PORTS[0], clock_divisor);
80 #endif
81 #ifdef CONFIG_SYS_INIT_CHAN2
82         NS16550_reinit (COM_PORTS[1], clock_divisor);
83 #endif
84 }
85
86 static void ml2_serial_puts(const char *s)
87 {
88         while (*s) {
89                 serial_putc (*s++);
90         }
91 }
92
93 #ifdef CONFIG_SERIAL_MULTI
94 static struct serial_device ml2_serial_drv = {
95         .name   = "ml2_serial",
96         .start  = ml2_serial_init,
97         .stop   = NULL,
98         .setbrg = ml2_serial_setbrg,
99         .putc   = ml2_serial_putc,
100         .puts   = ml2_serial_puts,
101         .getc   = ml2_serial_getc,
102         .tstc   = ml2_serial_tstc,
103 };
104
105 void ml2_serial_initialize(void)
106 {
107         serial_register(&ml2_serial_drv);
108 }
109
110 __weak struct serial_device *default_serial_console(void)
111 {
112         return &ml2_serial_drv;
113 }
114 #else
115 int serial_init(void)
116 {
117         return ml2_serial_init();
118 }
119
120 void serial_setbrg(void)
121 {
122         ml2_serial_setbrg();
123 }
124
125 void serial_putc(const char c)
126 {
127         ml2_serial_putc(c);
128 }
129
130 void serial_puts(const char *s)
131 {
132         ml2_serial_puts(s);
133 }
134
135 int serial_getc(void)
136 {
137         return ml2_serial_getc();
138 }
139
140 int serial_tstc(void)
141 {
142         return ml2_serial_tstc();
143 }
144 #endif
145 #if defined(CONFIG_CMD_KGDB)
146 void kgdb_serial_init (void)
147 {
148 }
149
150 void putDebugChar (int c)
151 {
152         serial_putc (c);
153 }
154
155 void putDebugStr (const char *str)
156 {
157         serial_puts (str);
158 }
159
160 int getDebugChar (void)
161 {
162         return serial_getc ();
163 }
164
165 void kgdb_interruptible (int yes)
166 {
167         return;
168 }
169 #endif