wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 35 | #include <serial.h> |
| 36 | #include <linux/compiler.h> |
| 37 | |
wdenk | 3a473b2 | 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 | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 51 | DECLARE_GLOBAL_DATA_PTR; |
| 52 | |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 53 | #ifdef CONFIG_MPSC |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 54 | static int marvell_serial_init(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 55 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
wdenk | 3a473b2 | 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 | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 63 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 64 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 65 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 66 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 72 | static void marvell_serial_putc(const char c) |
wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 80 | static int marvell_serial_getc(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 81 | { |
| 82 | return mpsc_getchar (); |
| 83 | } |
| 84 | |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 85 | static int marvell_serial_tstc(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 86 | { |
| 87 | return mpsc_test_char (); |
| 88 | } |
| 89 | |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 90 | static void marvell_serial_setbrg(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 91 | { |
wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 97 | static int marvell_serial_init(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 98 | { |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 99 | int clock_divisor = 230400 / gd->baudrate; |
| 100 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 102 | (void) NS16550_init (0, clock_divisor); |
| 103 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 110 | static void marvell_serial_putc(const char c) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 111 | { |
| 112 | if (c == '\n') |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 113 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r'); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 114 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 115 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 118 | static int marvell_serial_getc(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 119 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 123 | static int marvell_serial_tstc(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 124 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 128 | static void marvell_serial_setbrg(void) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 129 | { |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 130 | int clock_divisor = 230400 / gd->baudrate; |
| 131 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 133 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 134 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 135 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | 3a473b2 | 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 | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 142 | static struct serial_device marvell_serial_drv = { |
| 143 | .name = "marvell_serial", |
| 144 | .start = marvell_serial_init, |
| 145 | .stop = NULL, |
| 146 | .setbrg = marvell_serial_setbrg, |
| 147 | .putc = marvell_serial_putc, |
Marek Vasut | ec3fd68 | 2012-10-06 14:07:02 +0000 | [diff] [blame^] | 148 | .puts = default_serial_puts, |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 149 | .getc = marvell_serial_getc, |
| 150 | .tstc = marvell_serial_tstc, |
| 151 | }; |
| 152 | |
| 153 | void marvell_serial_initialize(void) |
| 154 | { |
| 155 | serial_register(&marvell_serial_drv); |
| 156 | } |
| 157 | |
| 158 | __weak struct serial_device *default_serial_console(void) |
| 159 | { |
| 160 | return &marvell_serial_drv; |
| 161 | } |
Marek Vasut | afe4c38 | 2012-09-13 12:26:39 +0200 | [diff] [blame] | 162 | |
Jon Loeliger | fcec2eb | 2007-07-09 18:19:09 -0500 | [diff] [blame] | 163 | #if defined(CONFIG_CMD_KGDB) |
wdenk | 3a473b2 | 2004-01-03 00:43:19 +0000 | [diff] [blame] | 164 | void kgdb_serial_init (void) |
| 165 | { |
| 166 | } |
| 167 | |
| 168 | void putDebugChar (int c) |
| 169 | { |
| 170 | serial_putc (c); |
| 171 | } |
| 172 | |
| 173 | void putDebugStr (const char *str) |
| 174 | { |
| 175 | serial_puts (str); |
| 176 | } |
| 177 | |
| 178 | int getDebugChar (void) |
| 179 | { |
| 180 | return serial_getc (); |
| 181 | } |
| 182 | |
| 183 | void kgdb_interruptible (int yes) |
| 184 | { |
| 185 | return; |
| 186 | } |
Jon Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 187 | #endif |