wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc. |
| 4 | * |
| 5 | * modified for marvell db64360 eval board by |
| 6 | * Ingo Assmus <ingo.assmus@keymile.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | * serial.c - serial support for the gal ev board |
| 29 | */ |
| 30 | |
| 31 | /* supports both the 16650 duart and the MPSC */ |
| 32 | |
| 33 | #include <common.h> |
| 34 | #include <command.h> |
| 35 | #include "../include/memory.h" |
| 36 | #include "serial.h" |
| 37 | |
| 38 | #ifdef CONFIG_DB64360 |
| 39 | #include "../db64360/mpsc.h" |
| 40 | #endif |
| 41 | |
| 42 | #ifdef CONFIG_DB64460 |
| 43 | #include "../db64460/mpsc.h" |
| 44 | #endif |
| 45 | |
| 46 | #include "ns16550.h" |
| 47 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 48 | DECLARE_GLOBAL_DATA_PTR; |
| 49 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_MPSC |
| 51 | |
| 52 | |
| 53 | int serial_init (void) |
| 54 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 55 | #if (defined CFG_INIT_CHAN1) || (defined CFG_INIT_CHAN2) |
| 56 | int clock_divisor = 230400 / gd->baudrate; |
| 57 | #endif |
| 58 | |
| 59 | mpsc_init (gd->baudrate); |
| 60 | |
| 61 | /* init the DUART chans so that KGDB in the kernel can use them */ |
| 62 | #ifdef CFG_INIT_CHAN1 |
| 63 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 64 | #endif |
| 65 | #ifdef CFG_INIT_CHAN2 |
| 66 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 67 | #endif |
| 68 | return (0); |
| 69 | } |
| 70 | |
| 71 | void serial_putc (const char c) |
| 72 | { |
| 73 | if (c == '\n') |
| 74 | mpsc_putchar ('\r'); |
| 75 | |
| 76 | mpsc_putchar (c); |
| 77 | } |
| 78 | |
| 79 | int serial_getc (void) |
| 80 | { |
| 81 | return mpsc_getchar (); |
| 82 | } |
| 83 | |
| 84 | int serial_tstc (void) |
| 85 | { |
| 86 | return mpsc_test_char (); |
| 87 | } |
| 88 | |
| 89 | void serial_setbrg (void) |
| 90 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 91 | galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate); |
| 92 | } |
| 93 | |
| 94 | #else /* ! CONFIG_MPSC */ |
| 95 | |
| 96 | int serial_init (void) |
| 97 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 98 | int clock_divisor = 230400 / gd->baudrate; |
| 99 | |
| 100 | #ifdef CFG_INIT_CHAN1 |
| 101 | (void) NS16550_init (0, clock_divisor); |
| 102 | #endif |
| 103 | #ifdef CFG_INIT_CHAN2 |
| 104 | (void) NS16550_init (1, clock_divisor); |
| 105 | #endif |
| 106 | return (0); |
| 107 | } |
| 108 | |
| 109 | void serial_putc (const char c) |
| 110 | { |
| 111 | if (c == '\n') |
| 112 | NS16550_putc (COM_PORTS[CFG_DUART_CHAN], '\r'); |
| 113 | |
| 114 | NS16550_putc (COM_PORTS[CFG_DUART_CHAN], c); |
| 115 | } |
| 116 | |
| 117 | int serial_getc (void) |
| 118 | { |
| 119 | return NS16550_getc (COM_PORTS[CFG_DUART_CHAN]); |
| 120 | } |
| 121 | |
| 122 | int serial_tstc (void) |
| 123 | { |
| 124 | return NS16550_tstc (COM_PORTS[CFG_DUART_CHAN]); |
| 125 | } |
| 126 | |
| 127 | void serial_setbrg (void) |
| 128 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 129 | int clock_divisor = 230400 / gd->baudrate; |
| 130 | |
| 131 | #ifdef CFG_INIT_CHAN1 |
| 132 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 133 | #endif |
| 134 | #ifdef CFG_INIT_CHAN2 |
| 135 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 136 | #endif |
| 137 | } |
| 138 | |
| 139 | #endif /* CONFIG_MPSC */ |
| 140 | |
| 141 | void serial_puts (const char *s) |
| 142 | { |
| 143 | while (*s) { |
| 144 | serial_putc (*s++); |
| 145 | } |
| 146 | } |
| 147 | |
Jon Loeliger | d299abc | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 148 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 149 | void kgdb_serial_init (void) |
| 150 | { |
| 151 | } |
| 152 | |
| 153 | void putDebugChar (int c) |
| 154 | { |
| 155 | serial_putc (c); |
| 156 | } |
| 157 | |
| 158 | void putDebugStr (const char *str) |
| 159 | { |
| 160 | serial_puts (str); |
| 161 | } |
| 162 | |
| 163 | int getDebugChar (void) |
| 164 | { |
| 165 | return serial_getc (); |
| 166 | } |
| 167 | |
| 168 | void kgdb_interruptible (int yes) |
| 169 | { |
| 170 | return; |
| 171 | } |
Jon Loeliger | 13f7599 | 2007-07-10 10:39:10 -0500 | [diff] [blame^] | 172 | #endif |