1 | /* |
---|
2 | * SPDX-License-Identifier: BSD-2-Clause |
---|
3 | * |
---|
4 | * Copyright (C) 2013, 2017 embedded brains GmbH & Co. KG |
---|
5 | * |
---|
6 | * Copyright (C) 2019 DornerWorks |
---|
7 | * |
---|
8 | * Written by Jeff Kubascik <jeff.kubascik@dornerworks.com> |
---|
9 | * and Josh Whitehead <josh.whitehead@dornerworks.com> |
---|
10 | * |
---|
11 | * Redistribution and use in source and binary forms, with or without |
---|
12 | * modification, are permitted provided that the following conditions |
---|
13 | * are met: |
---|
14 | * 1. Redistributions of source code must retain the above copyright |
---|
15 | * notice, this list of conditions and the following disclaimer. |
---|
16 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
17 | * notice, this list of conditions and the following disclaimer in the |
---|
18 | * documentation and/or other materials provided with the distribution. |
---|
19 | * |
---|
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
30 | * POSSIBILITY OF SUCH DAMAGE. |
---|
31 | */ |
---|
32 | |
---|
33 | #include <rtems/console.h> |
---|
34 | #include <rtems/bspIo.h> |
---|
35 | #include <rtems/sysinit.h> |
---|
36 | |
---|
37 | #include <bsp/irq.h> |
---|
38 | #include <dev/serial/zynq-uart.h> |
---|
39 | |
---|
40 | #include <bspopts.h> |
---|
41 | |
---|
42 | static zynq_uart_context zynqmp_uart_instances[2] = { |
---|
43 | { |
---|
44 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 0" ), |
---|
45 | .regs = (volatile struct zynq_uart *) 0xff000000, |
---|
46 | .irq = ZYNQMP_IRQ_UART_0 |
---|
47 | }, { |
---|
48 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER( "Zynq UART 1" ), |
---|
49 | .regs = (volatile struct zynq_uart *) 0xff010000, |
---|
50 | .irq = ZYNQMP_IRQ_UART_1 |
---|
51 | } |
---|
52 | }; |
---|
53 | |
---|
54 | rtems_status_code console_initialize( |
---|
55 | rtems_device_major_number major, |
---|
56 | rtems_device_minor_number minor, |
---|
57 | void *arg |
---|
58 | ) |
---|
59 | { |
---|
60 | size_t i; |
---|
61 | |
---|
62 | rtems_termios_initialize(); |
---|
63 | |
---|
64 | for (i = 0; i < RTEMS_ARRAY_SIZE(zynqmp_uart_instances); ++i) { |
---|
65 | char uart[] = "/dev/ttySX"; |
---|
66 | |
---|
67 | uart[sizeof(uart) - 2] = (char) ('0' + i); |
---|
68 | rtems_termios_device_install( |
---|
69 | &uart[0], |
---|
70 | &zynq_uart_handler, |
---|
71 | NULL, |
---|
72 | &zynqmp_uart_instances[i].base |
---|
73 | ); |
---|
74 | |
---|
75 | if (i == BSP_CONSOLE_MINOR) { |
---|
76 | link(&uart[0], CONSOLE_DEVICE_NAME); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | return RTEMS_SUCCESSFUL; |
---|
81 | } |
---|
82 | |
---|
83 | void zynqmp_debug_console_flush(void) |
---|
84 | { |
---|
85 | zynq_uart_reset_tx_flush(&zynqmp_uart_instances[BSP_CONSOLE_MINOR]); |
---|
86 | } |
---|
87 | |
---|
88 | static void zynqmp_debug_console_out(char c) |
---|
89 | { |
---|
90 | rtems_termios_device_context *base = |
---|
91 | &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base; |
---|
92 | |
---|
93 | zynq_uart_write_polled(base, c); |
---|
94 | } |
---|
95 | |
---|
96 | static void zynqmp_debug_console_init(void) |
---|
97 | { |
---|
98 | rtems_termios_device_context *base = |
---|
99 | &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base; |
---|
100 | |
---|
101 | zynq_uart_initialize(base); |
---|
102 | BSP_output_char = zynqmp_debug_console_out; |
---|
103 | } |
---|
104 | |
---|
105 | static void zynqmp_debug_console_early_init(char c) |
---|
106 | { |
---|
107 | rtems_termios_device_context *base = |
---|
108 | &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base; |
---|
109 | |
---|
110 | zynq_uart_initialize(base); |
---|
111 | zynqmp_debug_console_out(c); |
---|
112 | } |
---|
113 | |
---|
114 | static int zynqmp_debug_console_in(void) |
---|
115 | { |
---|
116 | rtems_termios_device_context *base = |
---|
117 | &zynqmp_uart_instances[BSP_CONSOLE_MINOR].base; |
---|
118 | |
---|
119 | return zynq_uart_read_polled(base); |
---|
120 | } |
---|
121 | |
---|
122 | BSP_output_char_function_type BSP_output_char = zynqmp_debug_console_early_init; |
---|
123 | |
---|
124 | BSP_polling_getchar_function_type BSP_poll_char = zynqmp_debug_console_in; |
---|
125 | |
---|
126 | RTEMS_SYSINIT_ITEM( |
---|
127 | zynqmp_debug_console_init, |
---|
128 | RTEMS_SYSINIT_BSP_START, |
---|
129 | RTEMS_SYSINIT_ORDER_LAST_BUT_5 |
---|
130 | ); |
---|