blob: 432aa0660efac575b5986b88172281df6c93c6ac [file] [log] [blame]
wdenk3a473b22004-01-03 00:43:19 +00001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk3a473b22004-01-03 00:43:19 +00009 */
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>
Marek Vasutafe4c382012-09-13 12:26:39 +020019#include <serial.h>
20#include <linux/compiler.h>
21
wdenk3a473b22004-01-03 00:43:19 +000022#include "../include/memory.h"
wdenk3a473b22004-01-03 00:43:19 +000023
wdenk3a473b22004-01-03 00:43:19 +000024#include "ns16550.h"
25
Wolfgang Denkd87080b2006-03-31 18:32:53 +020026DECLARE_GLOBAL_DATA_PTR;
27
wdenk3a473b22004-01-03 00:43:19 +000028#ifdef CONFIG_MPSC
Marek Vasutafe4c382012-09-13 12:26:39 +020029static int marvell_serial_init(void)
wdenk3a473b22004-01-03 00:43:19 +000030{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020031#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenk3a473b22004-01-03 00:43:19 +000032 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 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +000039 NS16550_reinit (COM_PORTS[0], clock_divisor);
40#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041#ifdef CONFIG_SYS_INIT_CHAN2
wdenk3a473b22004-01-03 00:43:19 +000042 NS16550_reinit (COM_PORTS[1], clock_divisor);
43#endif
44 return (0);
45}
46
Marek Vasutafe4c382012-09-13 12:26:39 +020047static void marvell_serial_putc(const char c)
wdenk3a473b22004-01-03 00:43:19 +000048{
49 if (c == '\n')
50 mpsc_putchar ('\r');
51
52 mpsc_putchar (c);
53}
54
Marek Vasutafe4c382012-09-13 12:26:39 +020055static int marvell_serial_getc(void)
wdenk3a473b22004-01-03 00:43:19 +000056{
57 return mpsc_getchar ();
58}
59
Marek Vasutafe4c382012-09-13 12:26:39 +020060static int marvell_serial_tstc(void)
wdenk3a473b22004-01-03 00:43:19 +000061{
62 return mpsc_test_char ();
63}
64
Marek Vasutafe4c382012-09-13 12:26:39 +020065static void marvell_serial_setbrg(void)
wdenk3a473b22004-01-03 00:43:19 +000066{
wdenk3a473b22004-01-03 00:43:19 +000067 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
68}
69
70#else /* ! CONFIG_MPSC */
71
Marek Vasutafe4c382012-09-13 12:26:39 +020072static int marvell_serial_init(void)
wdenk3a473b22004-01-03 00:43:19 +000073{
wdenk3a473b22004-01-03 00:43:19 +000074 int clock_divisor = 230400 / gd->baudrate;
75
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +000077 (void) NS16550_init (0, clock_divisor);
78#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079#ifdef CONFIG_SYS_INIT_CHAN2
wdenk3a473b22004-01-03 00:43:19 +000080 (void) NS16550_init (1, clock_divisor);
81#endif
82 return (0);
83}
84
Marek Vasutafe4c382012-09-13 12:26:39 +020085static void marvell_serial_putc(const char c)
wdenk3a473b22004-01-03 00:43:19 +000086{
87 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020088 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenk3a473b22004-01-03 00:43:19 +000089
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenk3a473b22004-01-03 00:43:19 +000091}
92
Marek Vasutafe4c382012-09-13 12:26:39 +020093static int marvell_serial_getc(void)
wdenk3a473b22004-01-03 00:43:19 +000094{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk3a473b22004-01-03 00:43:19 +000096}
97
Marek Vasutafe4c382012-09-13 12:26:39 +020098static int marvell_serial_tstc(void)
wdenk3a473b22004-01-03 00:43:19 +000099{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk3a473b22004-01-03 00:43:19 +0000101}
102
Marek Vasutafe4c382012-09-13 12:26:39 +0200103static void marvell_serial_setbrg(void)
wdenk3a473b22004-01-03 00:43:19 +0000104{
wdenk3a473b22004-01-03 00:43:19 +0000105 int clock_divisor = 230400 / gd->baudrate;
106
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107#ifdef CONFIG_SYS_INIT_CHAN1
wdenk3a473b22004-01-03 00:43:19 +0000108 NS16550_reinit (COM_PORTS[0], clock_divisor);
109#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200110#ifdef CONFIG_SYS_INIT_CHAN2
wdenk3a473b22004-01-03 00:43:19 +0000111 NS16550_reinit (COM_PORTS[1], clock_divisor);
112#endif
113}
114
115#endif /* CONFIG_MPSC */
116
Marek Vasutafe4c382012-09-13 12:26:39 +0200117static 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,
Marek Vasutec3fd682012-10-06 14:07:02 +0000123 .puts = default_serial_puts,
Marek Vasutafe4c382012-09-13 12:26:39 +0200124 .getc = marvell_serial_getc,
125 .tstc = marvell_serial_tstc,
126};
127
128void 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}
Marek Vasutafe4c382012-09-13 12:26:39 +0200137
Jon Loeligerfcec2eb2007-07-09 18:19:09 -0500138#if defined(CONFIG_CMD_KGDB)
wdenk3a473b22004-01-03 00:43:19 +0000139void kgdb_serial_init (void)
140{
141}
142
143void putDebugChar (int c)
144{
145 serial_putc (c);
146}
147
148void putDebugStr (const char *str)
149{
150 serial_puts (str);
151}
152
153int getDebugChar (void)
154{
155 return serial_getc ();
156}
157
158void kgdb_interruptible (int yes)
159{
160 return;
161}
Jon Loeliger77a31852007-07-10 10:39:10 -0500162#endif