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