blob: 39c415792592e91157adc6eeee57ac464d9af091 [file] [log] [blame]
Wolfgang Denk7521af12005-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
22#include <asm/u-boot.h>
23#include <asm/processor.h>
24#include <common.h>
25#include <command.h>
26#include <config.h>
27
28#include <ns16550.h>
29
30#if 0
31#include "serial.h"
32#endif
33
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020034const NS16550_t COM_PORTS[] =
35 { (NS16550_t) CFG_NS16550_COM1, (NS16550_t) CFG_NS16550_COM2 };
Wolfgang Denk7521af12005-10-09 01:04:33 +020036
37#undef CFG_DUART_CHAN
38#define CFG_DUART_CHAN gComPort
39static int gComPort = 0;
40
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020041int serial_init (void)
Wolfgang Denk7521af12005-10-09 01:04:33 +020042{
43 DECLARE_GLOBAL_DATA_PTR;
44
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020045 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
46
47 (void) NS16550_init (COM_PORTS[0], clock_divisor);
48 gComPort = 0;
49
50 return 0;
51}
52
53void serial_putc (const char c)
54{
55 if (c == '\n') {
56 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], '\r');
57 }
58
59 NS16550_putc (COM_PORTS[CFG_DUART_CHAN], c);
60}
61
62int serial_getc (void)
63{
64 return NS16550_getc (COM_PORTS[CFG_DUART_CHAN]);
65}
66
67int serial_tstc (void)
68{
69 return NS16550_tstc (COM_PORTS[CFG_DUART_CHAN]);
70}
71
72void serial_setbrg (void)
73{
74 DECLARE_GLOBAL_DATA_PTR;
75
76 int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate;
Wolfgang Denk7521af12005-10-09 01:04:33 +020077
78#ifdef CFG_INIT_CHAN1
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020079 NS16550_reinit (COM_PORTS[0], clock_divisor);
Wolfgang Denk7521af12005-10-09 01:04:33 +020080#endif
81#ifdef CFG_INIT_CHAN2
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020082 NS16550_reinit (COM_PORTS[1], clock_divisor);
Wolfgang Denk7521af12005-10-09 01:04:33 +020083#endif
84}
85
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020086void serial_puts (const char *s)
Wolfgang Denk7521af12005-10-09 01:04:33 +020087{
88 while (*s) {
89 serial_putc (*s++);
90 }
91}
92
93#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020094void kgdb_serial_init (void)
Wolfgang Denk7521af12005-10-09 01:04:33 +020095{
96}
97
Wolfgang Denk3df5bea2005-10-09 01:41:48 +020098void putDebugChar (int c)
Wolfgang Denk7521af12005-10-09 01:04:33 +020099{
100 serial_putc (c);
101}
102
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200103void putDebugStr (const char *str)
Wolfgang Denk7521af12005-10-09 01:04:33 +0200104{
105 serial_puts (str);
106}
107
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200108int getDebugChar (void)
Wolfgang Denk7521af12005-10-09 01:04:33 +0200109{
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200110 return serial_getc ();
Wolfgang Denk7521af12005-10-09 01:04:33 +0200111}
112
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200113void kgdb_interruptible (int yes)
Wolfgang Denk7521af12005-10-09 01:04:33 +0200114{
115 return;
116}
Wolfgang Denk3df5bea2005-10-09 01:41:48 +0200117#endif /* CFG_CMD_KGDB */