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 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * serial.c - serial support for the gal ev board |
| 10 | */ |
| 11 | |
| 12 | /* supports both the 16650 duart and the MPSC */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <command.h> |
| 16 | #include <galileo/memory.h> |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 17 | #include <serial.h> |
| 18 | #include <linux/compiler.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 19 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 21 | #include <ns16550.h> |
| 22 | #endif |
| 23 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 24 | #include "mpsc.h" |
| 25 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 28 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
| 29 | const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1, |
| 30 | (NS16550_t) CONFIG_SYS_NS16550_COM2 }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #ifdef CONFIG_MPSC |
| 34 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 35 | static int evb64260_serial_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
| 38 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | mpsc_init(gd->baudrate); |
| 42 | |
| 43 | /* 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] | 44 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 45 | NS16550_reinit(COM_PORTS[0], clock_divisor); |
| 46 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 48 | NS16550_reinit(COM_PORTS[1], clock_divisor); |
| 49 | #endif |
| 50 | return (0); |
| 51 | } |
| 52 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 53 | static void evb64260_serial_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | { |
| 55 | if (c == '\n') |
| 56 | mpsc_putchar('\r'); |
| 57 | |
| 58 | mpsc_putchar(c); |
| 59 | } |
| 60 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 61 | static int evb64260_serial_getc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | { |
| 63 | return mpsc_getchar(); |
| 64 | } |
| 65 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 66 | static int evb64260_serial_tstc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 67 | { |
| 68 | return mpsc_test_char(); |
| 69 | } |
| 70 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 71 | static void evb64260_serial_setbrg(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 72 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate); |
| 74 | } |
| 75 | |
| 76 | #else /* ! CONFIG_MPSC */ |
| 77 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 78 | static int evb64260_serial_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 81 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 82 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 83 | (void)NS16550_init(COM_PORTS[0], clock_divisor); |
| 84 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | (void)NS16550_init(COM_PORTS[1], clock_divisor); |
| 87 | #endif |
| 88 | |
| 89 | return (0); |
| 90 | } |
| 91 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 92 | static void evb64260_serial_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | { |
| 94 | if (c == '\n') |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 95 | NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 100 | static int evb64260_serial_getc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 105 | static int evb64260_serial_tstc(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 110 | static void evb64260_serial_setbrg(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 112 | int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 113 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 114 | #ifdef CONFIG_SYS_INIT_CHAN1 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 115 | NS16550_reinit(COM_PORTS[0], clock_divisor); |
| 116 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | #ifdef CONFIG_SYS_INIT_CHAN2 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | NS16550_reinit(COM_PORTS[1], clock_divisor); |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | #endif /* CONFIG_MPSC */ |
| 123 | |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 124 | static struct serial_device evb64260_serial_drv = { |
| 125 | .name = "evb64260_serial", |
| 126 | .start = evb64260_serial_init, |
| 127 | .stop = NULL, |
| 128 | .setbrg = evb64260_serial_setbrg, |
| 129 | .putc = evb64260_serial_putc, |
Marek Vasut | ec3fd68 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 130 | .puts = default_serial_puts, |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 131 | .getc = evb64260_serial_getc, |
| 132 | .tstc = evb64260_serial_tstc, |
| 133 | }; |
| 134 | |
| 135 | void evb64260_serial_initialize(void) |
| 136 | { |
| 137 | serial_register(&evb64260_serial_drv); |
| 138 | } |
| 139 | |
| 140 | __weak struct serial_device *default_serial_console(void) |
| 141 | { |
| 142 | return &evb64260_serial_drv; |
| 143 | } |
Marek Vasut | 829b3b2 | 2012-09-13 12:33:50 +0200 | [diff] [blame] | 144 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 145 | #if defined(CONFIG_CMD_KGDB) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 146 | void |
| 147 | kgdb_serial_init(void) |
| 148 | { |
| 149 | } |
| 150 | |
| 151 | void |
| 152 | putDebugChar (int c) |
| 153 | { |
| 154 | serial_putc (c); |
| 155 | } |
| 156 | |
| 157 | void |
| 158 | putDebugStr (const char *str) |
| 159 | { |
| 160 | serial_puts (str); |
| 161 | } |
| 162 | |
| 163 | int |
| 164 | getDebugChar (void) |
| 165 | { |
| 166 | return serial_getc(); |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | kgdb_interruptible (int yes) |
| 171 | { |
| 172 | return; |
| 173 | } |
Jon Loeliger | 77a3185 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 174 | #endif |