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