]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amirix/ap1000/serial.c
ppc4xx: Remove ML2 board support
[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 static struct serial_device amirix_serial_drv = {
90         .name   = "amirix_serial",
91         .start  = amirix_serial_init,
92         .stop   = NULL,
93         .setbrg = amirix_serial_setbrg,
94         .putc   = amirix_serial_putc,
95         .puts   = amirix_serial_puts,
96         .getc   = amirix_serial_getc,
97         .tstc   = amirix_serial_tstc,
98 };
99
100 void amirix_serial_initialize(void)
101 {
102         serial_register(&amirix_serial_drv);
103 }
104
105 __weak struct serial_device *default_serial_console(void)
106 {
107         return &amirix_serial_drv;
108 }
109
110 #if defined(CONFIG_CMD_KGDB)
111 void kgdb_serial_init (void)
112 {
113 }
114
115 void putDebugChar (int c)
116 {
117         serial_putc (c);
118 }
119
120 void putDebugStr (const char *str)
121 {
122         serial_puts (str);
123 }
124
125 int getDebugChar (void)
126 {
127         return serial_getc ();
128 }
129
130 void kgdb_interruptible (int yes)
131 {
132         return;
133 }
134 #endif