blob: 752492fc7d17d3c99d33fb536d13e4c3aec6f892 [file] [log] [blame]
wdenk5da7f2f2004-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 Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk5da7f2f2004-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 Vasut4c2ced32012-09-13 12:26:39 +020019#include <serial.h>
20#include <linux/compiler.h>
21
wdenk5da7f2f2004-01-03 00:43:19 +000022#include "../include/memory.h"
wdenk5da7f2f2004-01-03 00:43:19 +000023
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
Wolfgang Denk6405a152006-03-31 18:32:53 +020034DECLARE_GLOBAL_DATA_PTR;
35
wdenk5da7f2f2004-01-03 00:43:19 +000036#ifdef CONFIG_MPSC
Marek Vasut4c2ced32012-09-13 12:26:39 +020037static int marvell_serial_init(void)
wdenk5da7f2f2004-01-03 00:43:19 +000038{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenk5da7f2f2004-01-03 00:43:19 +000040 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 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046#ifdef CONFIG_SYS_INIT_CHAN1
wdenk5da7f2f2004-01-03 00:43:19 +000047 NS16550_reinit (COM_PORTS[0], clock_divisor);
48#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049#ifdef CONFIG_SYS_INIT_CHAN2
wdenk5da7f2f2004-01-03 00:43:19 +000050 NS16550_reinit (COM_PORTS[1], clock_divisor);
51#endif
52 return (0);
53}
54
Marek Vasut4c2ced32012-09-13 12:26:39 +020055static void marvell_serial_putc(const char c)
wdenk5da7f2f2004-01-03 00:43:19 +000056{
57 if (c == '\n')
58 mpsc_putchar ('\r');
59
60 mpsc_putchar (c);
61}
62
Marek Vasut4c2ced32012-09-13 12:26:39 +020063static int marvell_serial_getc(void)
wdenk5da7f2f2004-01-03 00:43:19 +000064{
65 return mpsc_getchar ();
66}
67
Marek Vasut4c2ced32012-09-13 12:26:39 +020068static int marvell_serial_tstc(void)
wdenk5da7f2f2004-01-03 00:43:19 +000069{
70 return mpsc_test_char ();
71}
72
Marek Vasut4c2ced32012-09-13 12:26:39 +020073static void marvell_serial_setbrg(void)
wdenk5da7f2f2004-01-03 00:43:19 +000074{
wdenk5da7f2f2004-01-03 00:43:19 +000075 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
76}
77
78#else /* ! CONFIG_MPSC */
79
Marek Vasut4c2ced32012-09-13 12:26:39 +020080static int marvell_serial_init(void)
wdenk5da7f2f2004-01-03 00:43:19 +000081{
wdenk5da7f2f2004-01-03 00:43:19 +000082 int clock_divisor = 230400 / gd->baudrate;
83
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#ifdef CONFIG_SYS_INIT_CHAN1
wdenk5da7f2f2004-01-03 00:43:19 +000085 (void) NS16550_init (0, clock_divisor);
86#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#ifdef CONFIG_SYS_INIT_CHAN2
wdenk5da7f2f2004-01-03 00:43:19 +000088 (void) NS16550_init (1, clock_divisor);
89#endif
90 return (0);
91}
92
Marek Vasut4c2ced32012-09-13 12:26:39 +020093static void marvell_serial_putc(const char c)
wdenk5da7f2f2004-01-03 00:43:19 +000094{
95 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020096 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenk5da7f2f2004-01-03 00:43:19 +000097
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenk5da7f2f2004-01-03 00:43:19 +000099}
100
Marek Vasut4c2ced32012-09-13 12:26:39 +0200101static int marvell_serial_getc(void)
wdenk5da7f2f2004-01-03 00:43:19 +0000102{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200103 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk5da7f2f2004-01-03 00:43:19 +0000104}
105
Marek Vasut4c2ced32012-09-13 12:26:39 +0200106static int marvell_serial_tstc(void)
wdenk5da7f2f2004-01-03 00:43:19 +0000107{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenk5da7f2f2004-01-03 00:43:19 +0000109}
110
Marek Vasut4c2ced32012-09-13 12:26:39 +0200111static void marvell_serial_setbrg(void)
wdenk5da7f2f2004-01-03 00:43:19 +0000112{
wdenk5da7f2f2004-01-03 00:43:19 +0000113 int clock_divisor = 230400 / gd->baudrate;
114
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115#ifdef CONFIG_SYS_INIT_CHAN1
wdenk5da7f2f2004-01-03 00:43:19 +0000116 NS16550_reinit (COM_PORTS[0], clock_divisor);
117#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118#ifdef CONFIG_SYS_INIT_CHAN2
wdenk5da7f2f2004-01-03 00:43:19 +0000119 NS16550_reinit (COM_PORTS[1], clock_divisor);
120#endif
121}
122
123#endif /* CONFIG_MPSC */
124
Marek Vasut4c2ced32012-09-13 12:26:39 +0200125static 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,
Marek Vasutd9c64492012-10-06 14:07:02 +0000131 .puts = default_serial_puts,
Marek Vasut4c2ced32012-09-13 12:26:39 +0200132 .getc = marvell_serial_getc,
133 .tstc = marvell_serial_tstc,
134};
135
136void 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}
Marek Vasut4c2ced32012-09-13 12:26:39 +0200145
Jon Loeligerd299abc2007-07-09 18:19:09 -0500146#if defined(CONFIG_CMD_KGDB)
wdenk5da7f2f2004-01-03 00:43:19 +0000147void kgdb_serial_init (void)
148{
149}
150
151void putDebugChar (int c)
152{
153 serial_putc (c);
154}
155
156void putDebugStr (const char *str)
157{
158 serial_puts (str);
159}
160
161int getDebugChar (void)
162{
163 return serial_getc ();
164}
165
166void kgdb_interruptible (int yes)
167{
168 return;
169}
Jon Loeliger13f75992007-07-10 10:39:10 -0500170#endif