1 | /* |
---|
2 | * This file contains the TTY driver for the serial ports on the LEON. |
---|
3 | * |
---|
4 | * This driver uses the termios pseudo driver. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1998. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * Modified for LEON3 BSP. |
---|
10 | * COPYRIGHT (c) 2004. |
---|
11 | * Gaisler Research. |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | /* Define CONSOLE_USE_INTERRUPTS to enable APBUART interrupt handling instead |
---|
19 | * of polling mode. |
---|
20 | * |
---|
21 | * Note that it is not possible to use the interrupt mode of the driver |
---|
22 | * together with the "old" APBUART and -u to GRMON. However the new |
---|
23 | * APBUART core (from GRLIB 1.0.17-b2710) has the GRMON debug bit and can |
---|
24 | * handle interrupts. |
---|
25 | * |
---|
26 | * NOTE: This can be defined in the make/custom/leon3.cfg file. |
---|
27 | */ |
---|
28 | |
---|
29 | #include <bsp.h> |
---|
30 | #include <bsp/fatal.h> |
---|
31 | #include <bsp/apbuart_termios.h> |
---|
32 | |
---|
33 | /* The LEON3 BSP UART driver can rely on the Driver Manager if the |
---|
34 | * DrvMgr is initialized during startup. Otherwise the classic driver |
---|
35 | * must be used. |
---|
36 | * |
---|
37 | * The DrvMgr APBUART driver is located in the shared/uart directory |
---|
38 | */ |
---|
39 | #ifndef RTEMS_DRVMGR_STARTUP |
---|
40 | |
---|
41 | int syscon_uart_index __attribute__((weak)) = 0; |
---|
42 | |
---|
43 | /* body is in debugputs.c */ |
---|
44 | static struct apbuart_context apbuarts[BSP_NUMBER_OF_TERMIOS_PORTS]; |
---|
45 | static int uarts = 0; |
---|
46 | |
---|
47 | static rtems_termios_device_context *leon3_console_get_context(int minor) |
---|
48 | { |
---|
49 | struct apbuart_context *uart; |
---|
50 | |
---|
51 | if (minor == 0) |
---|
52 | uart = &apbuarts[syscon_uart_index]; |
---|
53 | else |
---|
54 | uart = &apbuarts[minor - 1]; |
---|
55 | |
---|
56 | rtems_termios_device_context_initialize(&uart->base, "APBUART"); |
---|
57 | |
---|
58 | return &uart->base; |
---|
59 | } |
---|
60 | |
---|
61 | /* AMBA PP find routine. Extract AMBA PnP information into data structure. */ |
---|
62 | static int find_matching_apbuart(struct ambapp_dev *dev, int index, void *arg) |
---|
63 | { |
---|
64 | struct ambapp_apb_info *apb = (struct ambapp_apb_info *)dev->devinfo; |
---|
65 | |
---|
66 | /* Extract needed information of one APBUART */ |
---|
67 | apbuarts[uarts].regs = (struct apbuart_regs *)apb->start; |
---|
68 | apbuarts[uarts].irq = apb->irq; |
---|
69 | /* Get APBUART core frequency, it is assumed that it is the same |
---|
70 | * as Bus frequency where the UART is situated |
---|
71 | */ |
---|
72 | apbuarts[uarts].freq_hz = ambapp_freq_get(&ambapp_plb, dev); |
---|
73 | uarts++; |
---|
74 | |
---|
75 | if (uarts >= BSP_NUMBER_OF_TERMIOS_PORTS) |
---|
76 | return 1; /* Satisfied number of UARTs, stop search */ |
---|
77 | else |
---|
78 | return 0; /* Continue searching for more UARTs */ |
---|
79 | } |
---|
80 | |
---|
81 | /* Find all UARTs */ |
---|
82 | static void leon3_console_scan_uarts(void) |
---|
83 | { |
---|
84 | memset(apbuarts, 0, sizeof(apbuarts)); |
---|
85 | |
---|
86 | /* Find APBUART cores */ |
---|
87 | ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), VENDOR_GAISLER, |
---|
88 | GAISLER_APBUART, find_matching_apbuart, NULL); |
---|
89 | } |
---|
90 | |
---|
91 | rtems_device_driver console_initialize( |
---|
92 | rtems_device_major_number major, |
---|
93 | rtems_device_minor_number minor, |
---|
94 | void *arg |
---|
95 | ) |
---|
96 | { |
---|
97 | const rtems_termios_device_handler *handler = |
---|
98 | #if CONSOLE_USE_INTERRUPTS |
---|
99 | &apbuart_handler_interrupt; |
---|
100 | #else |
---|
101 | &apbuart_handler_polled; |
---|
102 | #endif |
---|
103 | rtems_status_code status; |
---|
104 | int i; |
---|
105 | char console_name[16]; |
---|
106 | |
---|
107 | rtems_termios_initialize(); |
---|
108 | |
---|
109 | /* Find UARTs */ |
---|
110 | leon3_console_scan_uarts(); |
---|
111 | |
---|
112 | /* Update syscon_uart_index to index used as /dev/console |
---|
113 | * Let user select System console by setting syscon_uart_index. If the |
---|
114 | * BSP is to provide the default UART (syscon_uart_index==0): |
---|
115 | * non-MP: APBUART[0] is system console |
---|
116 | * MP: LEON CPU index select UART |
---|
117 | */ |
---|
118 | if (syscon_uart_index == 0) { |
---|
119 | #if defined(RTEMS_MULTIPROCESSING) |
---|
120 | syscon_uart_index = LEON3_Cpu_Index; |
---|
121 | #else |
---|
122 | syscon_uart_index = 0; |
---|
123 | #endif |
---|
124 | } else { |
---|
125 | syscon_uart_index = syscon_uart_index - 1; /* User selected sys-console */ |
---|
126 | } |
---|
127 | |
---|
128 | /* Register Device Names |
---|
129 | * |
---|
130 | * 0 /dev/console - APBUART[USER-SELECTED, DEFAULT=APBUART[0]] |
---|
131 | * 1 /dev/console_a - APBUART[0] (by default not present because is console) |
---|
132 | * 2 /dev/console_b - APBUART[1] |
---|
133 | * ... |
---|
134 | * |
---|
135 | * On a MP system one should not open UARTs that other OS instances use. |
---|
136 | */ |
---|
137 | if (syscon_uart_index < uarts) { |
---|
138 | minor = 0; |
---|
139 | status = rtems_termios_device_install( |
---|
140 | CONSOLE_DEVICE_NAME, |
---|
141 | major, |
---|
142 | minor, |
---|
143 | handler, |
---|
144 | NULL, |
---|
145 | leon3_console_get_context(syscon_uart_index) |
---|
146 | ); |
---|
147 | if (status != RTEMS_SUCCESSFUL) |
---|
148 | bsp_fatal(LEON3_FATAL_CONSOLE_REGISTER_DEV); |
---|
149 | } |
---|
150 | strcpy(console_name,"/dev/console_a"); |
---|
151 | for (i = 0; i < uarts; i++) { |
---|
152 | if (i == syscon_uart_index) |
---|
153 | continue; /* skip UART that is registered as /dev/console */ |
---|
154 | console_name[13] = 'a' + i; |
---|
155 | minor = i + 1; |
---|
156 | rtems_termios_device_install( |
---|
157 | console_name, |
---|
158 | major, |
---|
159 | minor, |
---|
160 | handler, |
---|
161 | NULL, |
---|
162 | leon3_console_get_context(syscon_uart_index) |
---|
163 | ); |
---|
164 | } |
---|
165 | |
---|
166 | return RTEMS_SUCCESSFUL; |
---|
167 | } |
---|
168 | |
---|
169 | #endif |
---|