blob: d9113ab9381a9a3cf282884a436af9d5255bfdfe [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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020028#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenkc6097192002-11-03 00:24:07 +000029#include <ns16550.h>
30#endif
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
wdenkc6097192002-11-03 00:24:07 +000033
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
35const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
36 (NS16550_t) CONFIG_SYS_NS16550_COM2
Wolfgang Denkd87080b2006-03-31 18:32:53 +020037};
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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000043
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044#ifdef CONFIG_SYS_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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020047#ifdef CONFIG_SYS_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')
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +000058
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 NS16550_putc (COM_PORTS[CONFIG_SYS_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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 return NS16550_getc (COM_PORTS[CONFIG_SYS_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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069 return NS16550_tstc (COM_PORTS[CONFIG_SYS_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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020074 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000075
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076#ifdef CONFIG_SYS_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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020079#ifdef CONFIG_SYS_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