wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 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 <configs/ML2.h> |
| 27 | |
| 28 | #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2) |
| 29 | #include <ns16550.h> |
| 30 | #endif |
| 31 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
| 34 | #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2) |
| 35 | const NS16550_t COM_PORTS[] = { (NS16550_t) CFG_NS16550_COM1, |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 36 | (NS16550_t) CFG_NS16550_COM2 |
| 37 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 40 | int serial_init (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 42 | int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 43 | |
| 44 | #ifdef CFG_INIT_CHAN1 |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 45 | (void) NS16550_init (COM_PORTS[0], clock_divisor); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 46 | #endif |
| 47 | #ifdef CFG_INIT_CHAN2 |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 48 | (void) NS16550_init (COM_PORTS[1], clock_divisor); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | #endif |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 50 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 51 | |
| 52 | } |
| 53 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 54 | void serial_putc (const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 55 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 56 | if (c == '\n') |
| 57 | NS16550_putc (COM_PORTS[CFG_DUART_CHAN], '\r'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 58 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 59 | NS16550_putc (COM_PORTS[CFG_DUART_CHAN], c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 62 | int serial_getc (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 64 | return NS16550_getc (COM_PORTS[CFG_DUART_CHAN]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 67 | int serial_tstc (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 68 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 69 | return NS16550_tstc (COM_PORTS[CFG_DUART_CHAN]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 72 | void serial_setbrg (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 74 | int clock_divisor = CFG_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 75 | |
| 76 | #ifdef CFG_INIT_CHAN1 |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 77 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 78 | #endif |
| 79 | #ifdef CFG_INIT_CHAN2 |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 80 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 81 | #endif |
| 82 | } |
| 83 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 84 | void serial_puts (const char *s) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | { |
| 86 | while (*s) { |
| 87 | serial_putc (*s++); |
| 88 | } |
| 89 | } |
| 90 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 91 | #if defined(CONFIG_CMD_KGDB) |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 92 | void kgdb_serial_init (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | { |
| 94 | } |
| 95 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 96 | void putDebugChar (int c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | { |
| 98 | serial_putc (c); |
| 99 | } |
| 100 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 101 | void putDebugStr (const char *str) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 102 | { |
| 103 | serial_puts (str); |
| 104 | } |
| 105 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 106 | int getDebugChar (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | { |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 108 | return serial_getc (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 111 | void kgdb_interruptible (int yes) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | { |
| 113 | return; |
| 114 | } |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 115 | #endif |