Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:42

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsAArch64XilinxVersal
0007  *
0008  * @brief This source file contains this BSP's console configuration.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2021 Gedare Bloom <gedare@rtems.org>
0013  *
0014  * Redistribution and use in source and binary forms, with or without
0015  * modification, are permitted provided that the following conditions
0016  * are met:
0017  * 1. Redistributions of source code must retain the above copyright
0018  *    notice, this list of conditions and the following disclaimer.
0019  * 2. Redistributions in binary form must reproduce the above copyright
0020  *    notice, this list of conditions and the following disclaimer in the
0021  *    documentation and/or other materials provided with the distribution.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #include <rtems/console.h>
0037 #include <rtems/bspIo.h>
0038 #include <rtems/sysinit.h>
0039 
0040 #include <bsp/irq.h>
0041 #include <dev/serial/arm-pl011.h>
0042 #include <dev/serial/versal-uart.h>
0043 
0044 #include <bspopts.h>
0045 
0046 static versal_pl011_context versal_uart_instances[2] = {
0047   {
0048     .pl011_ctx = {
0049       .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("Versal UART 0"),
0050       .regs = (arm_pl011_uart *) 0xff000000,
0051       .irq = VERSAL_IRQ_UART_0,
0052       .clock = VERSAL_CLOCK_UART,
0053       .initial_baud = VERSAL_UART_DEFAULT_BAUD
0054     }
0055   }, {
0056     .pl011_ctx = {
0057       .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("Versal UART 1"),
0058       .regs = (arm_pl011_uart *) 0xff010000,
0059       .irq = VERSAL_IRQ_UART_1,
0060       .clock = VERSAL_CLOCK_UART,
0061       .initial_baud = VERSAL_UART_DEFAULT_BAUD
0062     }
0063   }
0064 };
0065 
0066 rtems_status_code console_initialize(
0067   rtems_device_major_number major,
0068   rtems_device_minor_number minor,
0069   void *arg
0070 )
0071 {
0072   size_t i;
0073 
0074   rtems_termios_initialize();
0075 
0076   for (i = 0; i < RTEMS_ARRAY_SIZE(versal_uart_instances); ++i) {
0077     char uart[] = "/dev/ttySX";
0078 
0079     uart[sizeof(uart) - 2] = (char) ('0' + i);
0080     rtems_termios_device_install(
0081       &uart[0],
0082       &versal_uart_handler,
0083       NULL,
0084       &versal_uart_instances[i].pl011_ctx.base
0085     );
0086 
0087     if (i == BSP_CONSOLE_MINOR) {
0088       link(&uart[0], CONSOLE_DEVICE_NAME);
0089     }
0090   }
0091 
0092   return RTEMS_SUCCESSFUL;
0093 }
0094 
0095 void versal_debug_console_flush(void)
0096 {
0097   versal_uart_reset_tx_flush(
0098     &versal_uart_instances[BSP_CONSOLE_MINOR].pl011_ctx.base
0099   );
0100 }
0101 
0102 static void versal_debug_console_out(char c)
0103 {
0104   rtems_termios_device_context *base =
0105     &versal_uart_instances[BSP_CONSOLE_MINOR].pl011_ctx.base;
0106 
0107   arm_pl011_write_polled(base, c);
0108 }
0109 
0110 static void versal_debug_console_init(void)
0111 {
0112   rtems_termios_device_context *base =
0113     &versal_uart_instances[BSP_CONSOLE_MINOR].pl011_ctx.base;
0114 
0115   (void) versal_uart_initialize(base);
0116   BSP_output_char = versal_debug_console_out;
0117 }
0118 
0119 static void versal_debug_console_early_init(char c)
0120 {
0121   rtems_termios_device_context *base =
0122     &versal_uart_instances[BSP_CONSOLE_MINOR].pl011_ctx.base;
0123 
0124   (void) versal_uart_initialize(base);
0125   BSP_output_char = versal_debug_console_out;
0126   versal_debug_console_out(c);
0127 }
0128 
0129 static int versal_debug_console_in(void)
0130 {
0131   rtems_termios_device_context *base =
0132     &versal_uart_instances[BSP_CONSOLE_MINOR].pl011_ctx.base;
0133 
0134   return arm_pl011_read_polled(base);
0135 }
0136 
0137 BSP_output_char_function_type BSP_output_char = versal_debug_console_early_init;
0138 
0139 BSP_polling_getchar_function_type BSP_poll_char = versal_debug_console_in;
0140 
0141 RTEMS_SYSINIT_ITEM(
0142   versal_debug_console_init,
0143   RTEMS_SYSINIT_BSP_START,
0144   RTEMS_SYSINIT_ORDER_LAST_BUT_5
0145 );