wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * serial.c - serial support for the gal ev board |
| 26 | */ |
| 27 | |
| 28 | /* supports both the 16650 duart and the MPSC */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <command.h> |
| 32 | #include <galileo/memory.h> |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 33 | #include <serial.h> |
| 34 | #include <linux/compiler.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 35 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | #include <ns16550.h> |
| 38 | #endif |
| 39 | |
| 40 | #include "serial.h" |
| 41 | |
| 42 | #include "mpsc.h" |
| 43 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 44 | DECLARE_GLOBAL_DATA_PTR; |
| 45 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
| 47 | const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1, |
| 48 | (NS16550_t) CONFIG_SYS_NS16550_COM2 }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
| 51 | #ifdef CONFIG_MPSC |
| 52 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 53 | static int evb64260_serial_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
| 56 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 57 | #endif |
| 58 | |
| 59 | mpsc_init(gd->baudrate); |
| 60 | |
| 61 | /* 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] | 62 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | NS16550_reinit(COM_PORTS[0], clock_divisor); |
| 64 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 65 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 66 | NS16550_reinit(COM_PORTS[1], clock_divisor); |
| 67 | #endif |
| 68 | return (0); |
| 69 | } |
| 70 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 71 | static void evb64260_serial_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 72 | { |
| 73 | if (c == '\n') |
| 74 | mpsc_putchar('\r'); |
| 75 | |
| 76 | mpsc_putchar(c); |
| 77 | } |
| 78 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 79 | static int evb64260_serial_getc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | { |
| 81 | return mpsc_getchar(); |
| 82 | } |
| 83 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 84 | static int evb64260_serial_tstc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | { |
| 86 | return mpsc_test_char(); |
| 87 | } |
| 88 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 89 | static void evb64260_serial_setbrg(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate); |
| 92 | } |
| 93 | |
| 94 | #else /* ! CONFIG_MPSC */ |
| 95 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 96 | static int evb64260_serial_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | (void)NS16550_init(COM_PORTS[0], clock_divisor); |
| 102 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 103 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | (void)NS16550_init(COM_PORTS[1], clock_divisor); |
| 105 | #endif |
| 106 | |
| 107 | return (0); |
| 108 | } |
| 109 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 110 | static void evb64260_serial_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +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 | c609719 | 2002-11-03 00:24:07 +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 | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 118 | static int evb64260_serial_getc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +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 | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 123 | static int evb64260_serial_tstc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +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 | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 128 | static void evb64260_serial_setbrg(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 129 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 130 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 131 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +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 | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 136 | NS16550_reinit(COM_PORTS[1], clock_divisor); |
| 137 | #endif |
| 138 | } |
| 139 | |
| 140 | #endif /* CONFIG_MPSC */ |
| 141 | |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 142 | static struct serial_device evb64260_serial_drv = { |
| 143 | .name = "evb64260_serial", |
| 144 | .start = evb64260_serial_init, |
| 145 | .stop = NULL, |
| 146 | .setbrg = evb64260_serial_setbrg, |
| 147 | .putc = evb64260_serial_putc, |
Marek Vasut | d9c6449 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 148 | .puts = default_serial_puts, |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 149 | .getc = evb64260_serial_getc, |
| 150 | .tstc = evb64260_serial_tstc, |
| 151 | }; |
| 152 | |
| 153 | void evb64260_serial_initialize(void) |
| 154 | { |
| 155 | serial_register(&evb64260_serial_drv); |
| 156 | } |
| 157 | |
| 158 | __weak struct serial_device *default_serial_console(void) |
| 159 | { |
| 160 | return &evb64260_serial_drv; |
| 161 | } |
Marek Vasut | adede69 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 162 | |
Jon Loeliger | 4ed9ed6 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 163 | #if defined(CONFIG_CMD_KGDB) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | void |
| 165 | kgdb_serial_init(void) |
| 166 | { |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | putDebugChar (int c) |
| 171 | { |
| 172 | serial_putc (c); |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | putDebugStr (const char *str) |
| 177 | { |
| 178 | serial_puts (str); |
| 179 | } |
| 180 | |
| 181 | int |
| 182 | getDebugChar (void) |
| 183 | { |
| 184 | return serial_getc(); |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | kgdb_interruptible (int yes) |
| 189 | { |
| 190 | return; |
| 191 | } |
Jon Loeliger | 13f7599 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 192 | #endif |