]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/Marvell/common/serial.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / board / Marvell / common / serial.c
1 /*
2  * (C) Copyright 2001
3  * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4  *
5  * modified for marvell db64360 eval board by
6  * Ingo Assmus <ingo.assmus@keymile.com>
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 /*
12  * serial.c - serial support for the gal ev board
13  */
14
15 /* supports both the 16650 duart and the MPSC */
16
17 #include <common.h>
18 #include <command.h>
19 #include <serial.h>
20 #include <linux/compiler.h>
21
22 #include "../include/memory.h"
23
24 #ifdef CONFIG_DB64360
25 #include "../db64360/mpsc.h"
26 #endif
27
28 #ifdef CONFIG_DB64460
29 #include "../db64460/mpsc.h"
30 #endif
31
32 #include "ns16550.h"
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 #ifdef CONFIG_MPSC
37 static int marvell_serial_init(void)
38 {
39 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
40         int clock_divisor = 230400 / gd->baudrate;
41 #endif
42
43         mpsc_init (gd->baudrate);
44
45         /* init the DUART chans so that KGDB in the kernel can use them */
46 #ifdef CONFIG_SYS_INIT_CHAN1
47         NS16550_reinit (COM_PORTS[0], clock_divisor);
48 #endif
49 #ifdef CONFIG_SYS_INIT_CHAN2
50         NS16550_reinit (COM_PORTS[1], clock_divisor);
51 #endif
52         return (0);
53 }
54
55 static void marvell_serial_putc(const char c)
56 {
57         if (c == '\n')
58                 mpsc_putchar ('\r');
59
60         mpsc_putchar (c);
61 }
62
63 static int marvell_serial_getc(void)
64 {
65         return mpsc_getchar ();
66 }
67
68 static int marvell_serial_tstc(void)
69 {
70         return mpsc_test_char ();
71 }
72
73 static void marvell_serial_setbrg(void)
74 {
75         galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
76 }
77
78 #else  /* ! CONFIG_MPSC */
79
80 static int marvell_serial_init(void)
81 {
82         int clock_divisor = 230400 / gd->baudrate;
83
84 #ifdef CONFIG_SYS_INIT_CHAN1
85         (void) NS16550_init (0, clock_divisor);
86 #endif
87 #ifdef CONFIG_SYS_INIT_CHAN2
88         (void) NS16550_init (1, clock_divisor);
89 #endif
90         return (0);
91 }
92
93 static void marvell_serial_putc(const char c)
94 {
95         if (c == '\n')
96                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
97
98         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
99 }
100
101 static int marvell_serial_getc(void)
102 {
103         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
104 }
105
106 static int marvell_serial_tstc(void)
107 {
108         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
109 }
110
111 static void marvell_serial_setbrg(void)
112 {
113         int clock_divisor = 230400 / gd->baudrate;
114
115 #ifdef CONFIG_SYS_INIT_CHAN1
116         NS16550_reinit (COM_PORTS[0], clock_divisor);
117 #endif
118 #ifdef CONFIG_SYS_INIT_CHAN2
119         NS16550_reinit (COM_PORTS[1], clock_divisor);
120 #endif
121 }
122
123 #endif /* CONFIG_MPSC */
124
125 static struct serial_device marvell_serial_drv = {
126         .name   = "marvell_serial",
127         .start  = marvell_serial_init,
128         .stop   = NULL,
129         .setbrg = marvell_serial_setbrg,
130         .putc   = marvell_serial_putc,
131         .puts   = default_serial_puts,
132         .getc   = marvell_serial_getc,
133         .tstc   = marvell_serial_tstc,
134 };
135
136 void marvell_serial_initialize(void)
137 {
138         serial_register(&marvell_serial_drv);
139 }
140
141 __weak struct serial_device *default_serial_console(void)
142 {
143         return &marvell_serial_drv;
144 }
145
146 #if defined(CONFIG_CMD_KGDB)
147 void kgdb_serial_init (void)
148 {
149 }
150
151 void putDebugChar (int c)
152 {
153         serial_putc (c);
154 }
155
156 void putDebugStr (const char *str)
157 {
158         serial_puts (str);
159 }
160
161 int getDebugChar (void)
162 {
163         return serial_getc ();
164 }
165
166 void kgdb_interruptible (int yes)
167 {
168         return;
169 }
170 #endif