b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [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 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 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> |
| 19 | #include <serial.h> |
| 20 | #include <linux/compiler.h> |
| 21 | |
| 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 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | #ifdef CONFIG_MPSC |
| 38 | static int marvell_serial_init(void) |
| 39 | { |
| 40 | #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2) |
| 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 */ |
| 47 | #ifdef CONFIG_SYS_INIT_CHAN1 |
| 48 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 49 | #endif |
| 50 | #ifdef CONFIG_SYS_INIT_CHAN2 |
| 51 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 52 | #endif |
| 53 | return (0); |
| 54 | } |
| 55 | |
| 56 | static void marvell_serial_putc(const char c) |
| 57 | { |
| 58 | if (c == '\n') |
| 59 | mpsc_putchar ('\r'); |
| 60 | |
| 61 | mpsc_putchar (c); |
| 62 | } |
| 63 | |
| 64 | static int marvell_serial_getc(void) |
| 65 | { |
| 66 | return mpsc_getchar (); |
| 67 | } |
| 68 | |
| 69 | static int marvell_serial_tstc(void) |
| 70 | { |
| 71 | return mpsc_test_char (); |
| 72 | } |
| 73 | |
| 74 | static void marvell_serial_setbrg(void) |
| 75 | { |
| 76 | galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate); |
| 77 | } |
| 78 | |
| 79 | #else /* ! CONFIG_MPSC */ |
| 80 | |
| 81 | static int marvell_serial_init(void) |
| 82 | { |
| 83 | int clock_divisor = 230400 / gd->baudrate; |
| 84 | |
| 85 | #ifdef CONFIG_SYS_INIT_CHAN1 |
| 86 | (void) NS16550_init (0, clock_divisor); |
| 87 | #endif |
| 88 | #ifdef CONFIG_SYS_INIT_CHAN2 |
| 89 | (void) NS16550_init (1, clock_divisor); |
| 90 | #endif |
| 91 | return (0); |
| 92 | } |
| 93 | |
| 94 | static void marvell_serial_putc(const char c) |
| 95 | { |
| 96 | if (c == '\n') |
| 97 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r'); |
| 98 | |
| 99 | NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c); |
| 100 | } |
| 101 | |
| 102 | static int marvell_serial_getc(void) |
| 103 | { |
| 104 | return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
| 105 | } |
| 106 | |
| 107 | static int marvell_serial_tstc(void) |
| 108 | { |
| 109 | return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]); |
| 110 | } |
| 111 | |
| 112 | static void marvell_serial_setbrg(void) |
| 113 | { |
| 114 | int clock_divisor = 230400 / gd->baudrate; |
| 115 | |
| 116 | #ifdef CONFIG_SYS_INIT_CHAN1 |
| 117 | NS16550_reinit (COM_PORTS[0], clock_divisor); |
| 118 | #endif |
| 119 | #ifdef CONFIG_SYS_INIT_CHAN2 |
| 120 | NS16550_reinit (COM_PORTS[1], clock_divisor); |
| 121 | #endif |
| 122 | } |
| 123 | |
| 124 | #endif /* CONFIG_MPSC */ |
| 125 | |
| 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, |
| 132 | .puts = default_serial_puts, |
| 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 | } |
| 146 | |
| 147 | #if defined(CONFIG_CMD_KGDB) |
| 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 | } |
| 171 | #endif |