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> |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 35 | #include <serial.h> |
| 36 | #include <linux/compiler.h> |
| 37 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 38 | #include "../include/memory.h" |
| 39 | #include "serial.h" |
| 40 | |
| 41 | #ifdef CONFIG_DB64360 |
| 42 | #include "../db64360/mpsc.h" |
| 43 | #endif |
| 44 | |
| 45 | #ifdef CONFIG_DB64460 |
| 46 | #include "../db64460/mpsc.h" |
| 47 | #endif |
| 48 | |
| 49 | #include "ns16550.h" |
| 50 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_MPSC |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 54 | static int marvell_serial_init(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 55 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 57 | int clock_divisor = 230400 / gd->baudrate; |
| 58 | #endif |
| 59 | |
| 60 | mpsc_init (gd->baudrate); |
| 61 | |
| 62 | /* init the DUART chans so that KGDB in the kernel can use them */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 64 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 65 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 67 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 68 | #endif |
| 69 | return (0); |
| 70 | } |
| 71 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 72 | static void marvell_serial_putc(const char c) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 73 | { |
| 74 | if (c == '\n') |
| 75 | mpsc_putchar ('\r'); |
| 76 | |
| 77 | mpsc_putchar (c); |
| 78 | } |
| 79 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 80 | static int marvell_serial_getc(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 81 | { |
| 82 | return mpsc_getchar (); |
| 83 | } |
| 84 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 85 | static int marvell_serial_tstc(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 86 | { |
| 87 | return mpsc_test_char (); |
| 88 | } |
| 89 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 90 | static void marvell_serial_setbrg(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 91 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 92 | galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate); |
| 93 | } |
| 94 | |
| 95 | #else /* ! CONFIG_MPSC */ |
| 96 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 97 | static int marvell_serial_init(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 98 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 99 | int clock_divisor = 230400 / gd->baudrate; |
| 100 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 102 | (void) NS16550_init (0, clock_divisor); |
| 103 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 105 | (void) NS16550_init (1, clock_divisor); |
| 106 | #endif |
| 107 | return (0); |
| 108 | } |
| 109 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 110 | static void marvell_serial_putc(const char c) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 111 | { |
| 112 | if (c == '\n') |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r'); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 114 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 115 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 118 | static int marvell_serial_getc(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 119 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 123 | static int marvell_serial_tstc(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 124 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 128 | static void marvell_serial_setbrg(void) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 129 | { |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 130 | int clock_divisor = 230400 / gd->baudrate; |
| 131 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 133 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 134 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 135 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 136 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 137 | #endif |
| 138 | } |
| 139 | |
| 140 | #endif /* CONFIG_MPSC */ |
| 141 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 142 | static void marvell_serial_puts(const char *s) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 143 | { |
| 144 | while (*s) { |
| 145 | serial_putc (*s++); |
| 146 | } |
| 147 | } |
| 148 | |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 149 | static struct serial_device marvell_serial_drv = { |
| 150 | .name = "marvell_serial", |
| 151 | .start = marvell_serial_init, |
| 152 | .stop = NULL, |
| 153 | .setbrg = marvell_serial_setbrg, |
| 154 | .putc = marvell_serial_putc, |
| 155 | .puts = marvell_serial_puts, |
| 156 | .getc = marvell_serial_getc, |
| 157 | .tstc = marvell_serial_tstc, |
| 158 | }; |
| 159 | |
| 160 | void marvell_serial_initialize(void) |
| 161 | { |
| 162 | serial_register(&marvell_serial_drv); |
| 163 | } |
| 164 | |
| 165 | __weak struct serial_device *default_serial_console(void) |
| 166 | { |
| 167 | return &marvell_serial_drv; |
| 168 | } |
Marek Vasut | 4c2ced3 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 169 | |
Jon Loeliger | d299abc | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 170 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 5da7f2f | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 171 | void kgdb_serial_init (void) |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | void putDebugChar (int c) |
| 176 | { |
| 177 | serial_putc (c); |
| 178 | } |
| 179 | |
| 180 | void putDebugStr (const char *str) |
| 181 | { |
| 182 | serial_puts (str); |
| 183 | } |
| 184 | |
| 185 | int getDebugChar (void) |
| 186 | { |
| 187 | return serial_getc (); |
| 188 | } |
| 189 | |
| 190 | void kgdb_interruptible (int yes) |
| 191 | { |
| 192 | return; |
| 193 | } |
Jon Loeliger | 13f7599 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 194 | #endif |