blob: 87003be9c12450c21e9e4c0c6be8ee25d534fe1c [file] [log] [blame]
Wolfgang Denk56811f62005-10-09 01:04:33 +02001/*
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 Denk20a5f782008-07-03 22:34:08 +020022#include <common.h>
Wolfgang Denk56811f62005-10-09 01:04:33 +020023#include <asm/u-boot.h>
24#include <asm/processor.h>
Wolfgang Denk56811f62005-10-09 01:04:33 +020025#include <command.h>
26#include <config.h>
27
28#include <ns16550.h>
29
Wolfgang Denk6405a152006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
Wolfgang Denk56811f62005-10-09 01:04:33 +020031
Wolfgang Denk3193a652005-10-09 01:41:48 +020032const NS16550_t COM_PORTS[] =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033 { (NS16550_t) CONFIG_SYS_NS16550_COM1, (NS16550_t) CONFIG_SYS_NS16550_COM2 };
Wolfgang Denk56811f62005-10-09 01:04:33 +020034
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020035#undef CONFIG_SYS_DUART_CHAN
36#define CONFIG_SYS_DUART_CHAN gComPort
Wolfgang Denk56811f62005-10-09 01:04:33 +020037static int gComPort = 0;
38
Wolfgang Denk3193a652005-10-09 01:41:48 +020039int serial_init (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +020040{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
Wolfgang Denk56811f62005-10-09 01:04:33 +020042
Wolfgang Denk3193a652005-10-09 01:41:48 +020043 (void) NS16550_init (COM_PORTS[0], clock_divisor);
44 gComPort = 0;
Wolfgang Denk56811f62005-10-09 01:04:33 +020045
Wolfgang Denk3193a652005-10-09 01:41:48 +020046 return 0;
Wolfgang Denk56811f62005-10-09 01:04:33 +020047}
48
Wolfgang Denk3193a652005-10-09 01:41:48 +020049void serial_putc (const char c)
Wolfgang Denk56811f62005-10-09 01:04:33 +020050{
Wolfgang Denk3193a652005-10-09 01:41:48 +020051 if (c == '\n') {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
Wolfgang Denk3193a652005-10-09 01:41:48 +020053 }
Wolfgang Denk56811f62005-10-09 01:04:33 +020054
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
Wolfgang Denk56811f62005-10-09 01:04:33 +020056}
57
Wolfgang Denk3193a652005-10-09 01:41:48 +020058int serial_getc (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +020059{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020060 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
Wolfgang Denk56811f62005-10-09 01:04:33 +020061}
62
Wolfgang Denk3193a652005-10-09 01:41:48 +020063int serial_tstc (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +020064{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
Wolfgang Denk56811f62005-10-09 01:04:33 +020066}
67
Wolfgang Denk3193a652005-10-09 01:41:48 +020068void serial_setbrg (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +020069{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
Wolfgang Denk56811f62005-10-09 01:04:33 +020071
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072#ifdef CONFIG_SYS_INIT_CHAN1
Wolfgang Denk3193a652005-10-09 01:41:48 +020073 NS16550_reinit (COM_PORTS[0], clock_divisor);
Wolfgang Denk56811f62005-10-09 01:04:33 +020074#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075#ifdef CONFIG_SYS_INIT_CHAN2
Wolfgang Denk3193a652005-10-09 01:41:48 +020076 NS16550_reinit (COM_PORTS[1], clock_divisor);
Wolfgang Denk56811f62005-10-09 01:04:33 +020077#endif
78}
79
Wolfgang Denk3193a652005-10-09 01:41:48 +020080void serial_puts (const char *s)
Wolfgang Denk56811f62005-10-09 01:04:33 +020081{
82 while (*s) {
83 serial_putc (*s++);
84 }
85}
86
Jon Loeligerd299abc2007-07-09 18:19:09 -050087#if defined(CONFIG_CMD_KGDB)
Wolfgang Denk3193a652005-10-09 01:41:48 +020088void kgdb_serial_init (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +020089{
90}
91
Wolfgang Denk3193a652005-10-09 01:41:48 +020092void putDebugChar (int c)
Wolfgang Denk56811f62005-10-09 01:04:33 +020093{
94 serial_putc (c);
95}
96
Wolfgang Denk3193a652005-10-09 01:41:48 +020097void putDebugStr (const char *str)
Wolfgang Denk56811f62005-10-09 01:04:33 +020098{
99 serial_puts (str);
100}
101
Wolfgang Denk3193a652005-10-09 01:41:48 +0200102int getDebugChar (void)
Wolfgang Denk56811f62005-10-09 01:04:33 +0200103{
Wolfgang Denk3193a652005-10-09 01:41:48 +0200104 return serial_getc ();
Wolfgang Denk56811f62005-10-09 01:04:33 +0200105}
106
Wolfgang Denk3193a652005-10-09 01:41:48 +0200107void kgdb_interruptible (int yes)
Wolfgang Denk56811f62005-10-09 01:04:33 +0200108{
109 return;
110}
Jon Loeliger13f75992007-07-10 10:39:10 -0500111#endif