1 | /* |
---|
2 | * This file contains the TTY driver for the GRLIb APBUART |
---|
3 | * |
---|
4 | * This driver uses the termios pseudo driver. |
---|
5 | * |
---|
6 | * COPYRIGHT (c) 1989-1999. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * Modified for GRLIB BSP. |
---|
10 | * COPYRIGHT (c) 2011. |
---|
11 | * Aeroflex Gaisler. |
---|
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 | #include <bsp.h> |
---|
19 | #include <amba.h> |
---|
20 | #include <rtems/libio.h> |
---|
21 | #include <rtems/sysinit.h> |
---|
22 | #include <stdlib.h> |
---|
23 | #include <assert.h> |
---|
24 | #include <stdio.h> |
---|
25 | #include <grlib/apbuart.h> |
---|
26 | #include <grlib/ambapp.h> |
---|
27 | |
---|
28 | int grlib_debug_uart_index __attribute__((weak)) = 0; |
---|
29 | struct apbuart_regs *grlib_debug_uart = NULL; |
---|
30 | |
---|
31 | /* Before UART driver has registered (or when no UART is available), calls to |
---|
32 | * printk that gets to bsp_out_char() will be filling data into the |
---|
33 | * pre_printk_dbgbuf[] buffer, hopefully the buffer can help debugging the |
---|
34 | * early BSP boot.. At least the last printk() will be caught. |
---|
35 | * |
---|
36 | static char pre_printk_dbgbuf[32] = {0}; |
---|
37 | static int pre_printk_pos = 0; |
---|
38 | */ |
---|
39 | |
---|
40 | /* Initialize the BSP system debug console layer. It will scan AMBA Plu&Play |
---|
41 | * for a debug APBUART and enable RX/TX for that UART. |
---|
42 | */ |
---|
43 | static void bsp_debug_uart_init(void) |
---|
44 | { |
---|
45 | int i; |
---|
46 | struct ambapp_dev *adev; |
---|
47 | struct ambapp_apb_info *apb; |
---|
48 | |
---|
49 | /* Update grlib_debug_uart_index to index used as debug console. Let user |
---|
50 | * select Debug console by setting grlib_debug_uart_index. If the BSP is to |
---|
51 | * provide the default UART (grlib_debug_uart_index==0): |
---|
52 | * non-MP: APBUART[0] is debug console |
---|
53 | * MP: LEON CPU index select UART |
---|
54 | */ |
---|
55 | if (grlib_debug_uart_index == 0) { |
---|
56 | #if defined(RTEMS_MULTIPROCESSING) |
---|
57 | grlib_debug_uart_index = GRLIB_Cpu_Index; |
---|
58 | #else |
---|
59 | grlib_debug_uart_index = 0; |
---|
60 | #endif |
---|
61 | } else { |
---|
62 | grlib_debug_uart_index--; /* User selected dbg-console */ |
---|
63 | } |
---|
64 | |
---|
65 | /* Find APBUART core for System Debug Console */ |
---|
66 | i = grlib_debug_uart_index; |
---|
67 | adev = (void *)ambapp_for_each(&ambapp_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS), |
---|
68 | VENDOR_GAISLER, GAISLER_APBUART, |
---|
69 | ambapp_find_by_idx, (void *)&i); |
---|
70 | if (adev) { |
---|
71 | /* Found a matching debug console, initialize debug uart if present |
---|
72 | * for printk |
---|
73 | */ |
---|
74 | apb = (struct ambapp_apb_info *)adev->devinfo; |
---|
75 | grlib_debug_uart = (struct apbuart_regs *)apb->start; |
---|
76 | grlib_debug_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE; |
---|
77 | grlib_debug_uart->status = 0; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | RTEMS_SYSINIT_ITEM( |
---|
82 | bsp_debug_uart_init, |
---|
83 | RTEMS_SYSINIT_BSP_START, |
---|
84 | RTEMS_SYSINIT_ORDER_FOURTH |
---|
85 | ); |
---|
86 | |
---|
87 | /* putchar/getchar for printk */ |
---|
88 | static void bsp_out_char(char c) |
---|
89 | { |
---|
90 | if (grlib_debug_uart == NULL) { |
---|
91 | /* Try to assign standard UART address to debug driver to pass some tests */ |
---|
92 | grlib_debug_uart = (struct apbuart_regs *) 0x80000100; |
---|
93 | grlib_debug_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE; |
---|
94 | grlib_debug_uart->status = 0; |
---|
95 | /* Local debug buffer when UART driver has not registered */ |
---|
96 | /* |
---|
97 | pre_printk_dbgbuf[pre_printk_pos++] = c; |
---|
98 | pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1); |
---|
99 | return; |
---|
100 | */ |
---|
101 | } |
---|
102 | |
---|
103 | apbuart_outbyte_polled(grlib_debug_uart, c, 1, 1); |
---|
104 | } |
---|
105 | |
---|
106 | /* |
---|
107 | * To support printk |
---|
108 | */ |
---|
109 | |
---|
110 | #include <rtems/bspIo.h> |
---|
111 | |
---|
112 | BSP_output_char_function_type BSP_output_char = bsp_out_char; |
---|
113 | |
---|
114 | static int bsp_in_char(void) |
---|
115 | { |
---|
116 | int tmp; |
---|
117 | |
---|
118 | if (grlib_debug_uart == NULL) |
---|
119 | return EOF; |
---|
120 | |
---|
121 | while ((tmp = apbuart_inbyte_nonblocking(grlib_debug_uart)) < 0) |
---|
122 | ; |
---|
123 | return tmp; |
---|
124 | } |
---|
125 | |
---|
126 | BSP_polling_getchar_function_type BSP_poll_char = bsp_in_char; |
---|