blob: c18815bf88a38bbbe5e95334ed0921afced90e35 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
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
Wolfgang Denk4ff170a2008-07-03 22:34:08 +020022#include <common.h>
wdenkc6097192002-11-03 00:24:07 +000023#include <asm/u-boot.h>
24#include <asm/processor.h>
wdenkc6097192002-11-03 00:24:07 +000025#include <command.h>
26#include <configs/ML2.h>
27
28#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
29#include <ns16550.h>
30#endif
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
wdenkc6097192002-11-03 00:24:07 +000033
34#if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2)
35const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1,
Wolfgang Denkd87080b2006-03-31 18:32:53 +020036 (NS16550_t) CFG_NS16550_COM2
37};
wdenkc6097192002-11-03 00:24:07 +000038#endif
39
Wolfgang Denkd87080b2006-03-31 18:32:53 +020040int serial_init (void)
wdenkc6097192002-11-03 00:24:07 +000041{
Wolfgang Denkd87080b2006-03-31 18:32:53 +020042 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000043
44#ifdef CFG_INIT_CHAN1
Wolfgang Denkd87080b2006-03-31 18:32:53 +020045 (void) NS16550_init (COM_PORTS[0], clock_divisor);
wdenkc6097192002-11-03 00:24:07 +000046#endif
47#ifdef CFG_INIT_CHAN2
Wolfgang Denkd87080b2006-03-31 18:32:53 +020048 (void) NS16550_init (COM_PORTS[1], clock_divisor);
wdenkc6097192002-11-03 00:24:07 +000049#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020050 return 0;
wdenkc6097192002-11-03 00:24:07 +000051
52}
53
Wolfgang Denkd87080b2006-03-31 18:32:53 +020054void serial_putc (const char c)
wdenkc6097192002-11-03 00:24:07 +000055{
Wolfgang Denkd87080b2006-03-31 18:32:53 +020056 if (c == '\n')
57 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +000058
Wolfgang Denkd87080b2006-03-31 18:32:53 +020059 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], c);
wdenkc6097192002-11-03 00:24:07 +000060}
61
Wolfgang Denkd87080b2006-03-31 18:32:53 +020062int serial_getc (void)
wdenkc6097192002-11-03 00:24:07 +000063{
Wolfgang Denkd87080b2006-03-31 18:32:53 +020064 return NS16550_getc (COM_PORTS[CFG_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +000065}
66
Wolfgang Denkd87080b2006-03-31 18:32:53 +020067int serial_tstc (void)
wdenkc6097192002-11-03 00:24:07 +000068{
Wolfgang Denkd87080b2006-03-31 18:32:53 +020069 return NS16550_tstc (COM_PORTS[CFG_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +000070}
71
Wolfgang Denkd87080b2006-03-31 18:32:53 +020072void serial_setbrg (void)
wdenkc6097192002-11-03 00:24:07 +000073{
Wolfgang Denkd87080b2006-03-31 18:32:53 +020074 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000075
76#ifdef CFG_INIT_CHAN1
Wolfgang Denkd87080b2006-03-31 18:32:53 +020077 NS16550_reinit (COM_PORTS[0], clock_divisor);
wdenkc6097192002-11-03 00:24:07 +000078#endif
79#ifdef CFG_INIT_CHAN2
Wolfgang Denkd87080b2006-03-31 18:32:53 +020080 NS16550_reinit (COM_PORTS[1], clock_divisor);
wdenkc6097192002-11-03 00:24:07 +000081#endif
82}
83
Wolfgang Denkd87080b2006-03-31 18:32:53 +020084void serial_puts (const char *s)
wdenkc6097192002-11-03 00:24:07 +000085{
86 while (*s) {
87 serial_putc (*s++);
88 }
89}
90
Jon Loeliger3fe00102007-07-09 18:38:39 -050091#if defined(CONFIG_CMD_KGDB)
Wolfgang Denkd87080b2006-03-31 18:32:53 +020092void kgdb_serial_init (void)
wdenkc6097192002-11-03 00:24:07 +000093{
94}
95
Wolfgang Denkd87080b2006-03-31 18:32:53 +020096void putDebugChar (int c)
wdenkc6097192002-11-03 00:24:07 +000097{
98 serial_putc (c);
99}
100
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200101void putDebugStr (const char *str)
wdenkc6097192002-11-03 00:24:07 +0000102{
103 serial_puts (str);
104}
105
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200106int getDebugChar (void)
wdenkc6097192002-11-03 00:24:07 +0000107{
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200108 return serial_getc ();
wdenkc6097192002-11-03 00:24:07 +0000109}
110
Wolfgang Denkd87080b2006-03-31 18:32:53 +0200111void kgdb_interruptible (int yes)
wdenkc6097192002-11-03 00:24:07 +0000112{
113 return;
114}
Jon Loeliger3fe00102007-07-09 18:38:39 -0500115#endif