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