]> 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 #include "ns16550.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 #ifdef CONFIG_MPSC
29 static int marvell_serial_init(void)
30 {
31 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
32         int clock_divisor = 230400 / gd->baudrate;
33 #endif
34
35         mpsc_init (gd->baudrate);
36
37         /* init the DUART chans so that KGDB in the kernel can use them */
38 #ifdef CONFIG_SYS_INIT_CHAN1
39         NS16550_reinit (COM_PORTS[0], clock_divisor);
40 #endif
41 #ifdef CONFIG_SYS_INIT_CHAN2
42         NS16550_reinit (COM_PORTS[1], clock_divisor);
43 #endif
44         return (0);
45 }
46
47 static void marvell_serial_putc(const char c)
48 {
49         if (c == '\n')
50                 mpsc_putchar ('\r');
51
52         mpsc_putchar (c);
53 }
54
55 static int marvell_serial_getc(void)
56 {
57         return mpsc_getchar ();
58 }
59
60 static int marvell_serial_tstc(void)
61 {
62         return mpsc_test_char ();
63 }
64
65 static void marvell_serial_setbrg(void)
66 {
67         galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
68 }
69
70 #else  /* ! CONFIG_MPSC */
71
72 static int marvell_serial_init(void)
73 {
74         int clock_divisor = 230400 / gd->baudrate;
75
76 #ifdef CONFIG_SYS_INIT_CHAN1
77         (void) NS16550_init (0, clock_divisor);
78 #endif
79 #ifdef CONFIG_SYS_INIT_CHAN2
80         (void) NS16550_init (1, clock_divisor);
81 #endif
82         return (0);
83 }
84
85 static void marvell_serial_putc(const char c)
86 {
87         if (c == '\n')
88                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
89
90         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
91 }
92
93 static int marvell_serial_getc(void)
94 {
95         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
96 }
97
98 static int marvell_serial_tstc(void)
99 {
100         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
101 }
102
103 static void marvell_serial_setbrg(void)
104 {
105         int clock_divisor = 230400 / gd->baudrate;
106
107 #ifdef CONFIG_SYS_INIT_CHAN1
108         NS16550_reinit (COM_PORTS[0], clock_divisor);
109 #endif
110 #ifdef CONFIG_SYS_INIT_CHAN2
111         NS16550_reinit (COM_PORTS[1], clock_divisor);
112 #endif
113 }
114
115 #endif /* CONFIG_MPSC */
116
117 static struct serial_device marvell_serial_drv = {
118         .name   = "marvell_serial",
119         .start  = marvell_serial_init,
120         .stop   = NULL,
121         .setbrg = marvell_serial_setbrg,
122         .putc   = marvell_serial_putc,
123         .puts   = default_serial_puts,
124         .getc   = marvell_serial_getc,
125         .tstc   = marvell_serial_tstc,
126 };
127
128 void marvell_serial_initialize(void)
129 {
130         serial_register(&marvell_serial_drv);
131 }
132
133 __weak struct serial_device *default_serial_console(void)
134 {
135         return &marvell_serial_drv;
136 }
137
138 #if defined(CONFIG_CMD_KGDB)
139 void kgdb_serial_init (void)
140 {
141 }
142
143 void putDebugChar (int c)
144 {
145         serial_putc (c);
146 }
147
148 void putDebugStr (const char *str)
149 {
150         serial_puts (str);
151 }
152
153 int getDebugChar (void)
154 {
155         return serial_getc ();
156 }
157
158 void kgdb_interruptible (int yes)
159 {
160         return;
161 }
162 #endif