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