Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:04

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsARMLPC32XX
0007  *
0008  * @brief Console configuration.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2009, 2014 embedded brains GmbH & Co. KG
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 <libchip/ns16550.h>
0037 
0038 #include <bsp.h>
0039 #include <bsp/lpc32xx.h>
0040 #include <bsp/irq.h>
0041 #include <bsp/hsu.h>
0042 #include <bsp/console-termios.h>
0043 
0044 static uint8_t lpc32xx_uart_get_register(uintptr_t addr, uint8_t i)
0045 {
0046   volatile uint32_t *reg = (volatile uint32_t *) addr;
0047 
0048   return (uint8_t) reg [i];
0049 }
0050 
0051 static void lpc32xx_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0052 {
0053   volatile uint32_t *reg = (volatile uint32_t *) addr;
0054 
0055   reg [i] = val;
0056 }
0057 
0058 #ifdef LPC32XX_UART_3_BAUD
0059   static bool lpc32xx_uart_probe_3(rtems_termios_device_context *context)
0060   {
0061     LPC32XX_UARTCLK_CTRL |= BSP_BIT32(0);
0062     LPC32XX_U3CLK = LPC32XX_CONFIG_U3CLK;
0063     LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 4, 5);
0064 
0065     return ns16550_probe(context);
0066   }
0067 #endif
0068 
0069 #ifdef LPC32XX_UART_4_BAUD
0070   static bool lpc32xx_uart_probe_4(rtems_termios_device_context *context)
0071   {
0072     volatile lpc32xx_gpio *gpio = &lpc32xx.gpio;
0073 
0074     /*
0075      * Set GPO_21/U4_TX/LCDVD[3] to U4_TX.  This works only if LCD module is
0076      * disabled.
0077      */
0078     gpio->p2_mux_set = BSP_BIT32(2);
0079 
0080     LPC32XX_UARTCLK_CTRL |= BSP_BIT32(1);
0081     LPC32XX_U4CLK = LPC32XX_CONFIG_U4CLK;
0082     LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 6, 7);
0083 
0084     return ns16550_probe(context);
0085   }
0086 #endif
0087 
0088 #ifdef LPC32XX_UART_6_BAUD
0089   static bool lpc32xx_uart_probe_6(rtems_termios_device_context *context)
0090   {
0091     /* Bypass the IrDA modulator/demodulator */
0092     LPC32XX_UART_CTRL |= BSP_BIT32(5);
0093 
0094     LPC32XX_UARTCLK_CTRL |= BSP_BIT32(3);
0095     LPC32XX_U6CLK = LPC32XX_CONFIG_U6CLK;
0096     LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 10, 11);
0097 
0098     return ns16550_probe(context);
0099   }
0100 #endif
0101 
0102 /* FIXME: Console selection */
0103 
0104 #ifdef LPC32XX_UART_5_BAUD
0105 static ns16550_context lpc32xx_uart_context_5 = {
0106   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 5"),
0107   .get_reg = lpc32xx_uart_get_register,
0108   .set_reg = lpc32xx_uart_set_register,
0109   .port = LPC32XX_BASE_UART_5,
0110   .irq = LPC32XX_IRQ_UART_5,
0111   .clock = 16 * LPC32XX_UART_5_BAUD,
0112   .initial_baud = LPC32XX_UART_5_BAUD
0113 };
0114 #endif
0115 
0116 #ifdef LPC32XX_UART_3_BAUD
0117 static ns16550_context lpc32xx_uart_context_3 = {
0118   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"),
0119   .get_reg = lpc32xx_uart_get_register,
0120   .set_reg = lpc32xx_uart_set_register,
0121   .port = LPC32XX_BASE_UART_3,
0122   .irq = LPC32XX_IRQ_UART_3,
0123   .clock = 16 * LPC32XX_UART_3_BAUD,
0124   .initial_baud = LPC32XX_UART_3_BAUD
0125 };
0126 #endif
0127 
0128 #ifdef LPC32XX_UART_4_BAUD
0129 static ns16550_context lpc32xx_uart_context_4 = {
0130   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 4"),
0131   .get_reg = lpc32xx_uart_get_register,
0132   .set_reg = lpc32xx_uart_set_register,
0133   .port = LPC32XX_BASE_UART_4,
0134   .irq = LPC32XX_IRQ_UART_4,
0135   .clock = 16 * LPC32XX_UART_4_BAUD,
0136   .initial_baud = LPC32XX_UART_4_BAUD
0137 };
0138 #endif
0139 
0140 #ifdef LPC32XX_UART_6_BAUD
0141 static ns16550_context lpc32xx_uart_context_6 = {
0142   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 6"),
0143   .get_reg = lpc32xx_uart_get_register,
0144   .set_reg = lpc32xx_uart_set_register,
0145   .port = LPC32XX_BASE_UART_6,
0146   .irq = LPC32XX_IRQ_UART_6,
0147   .clock = 16 * LPC32XX_UART_6_BAUD,
0148   .initial_baud = LPC32XX_UART_6_BAUD
0149 };
0150 #endif
0151 
0152 #ifdef LPC32XX_UART_1_BAUD
0153 static lpc32xx_hsu_context lpc32xx_uart_context_1 = {
0154   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
0155   .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_1,
0156   .irq = LPC32XX_IRQ_UART_1,
0157   .initial_baud = LPC32XX_UART_1_BAUD
0158 };
0159 #endif
0160 
0161 #ifdef LPC32XX_UART_2_BAUD
0162 static lpc32xx_hsu_context lpc32xx_uart_context_2 = {
0163   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"),
0164   .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_2,
0165   .irq = LPC32XX_IRQ_UART_2,
0166   .initial_baud = LPC32XX_UART_2_BAUD
0167 };
0168 #endif
0169 
0170 #ifdef LPC32XX_UART_7_BAUD
0171 static lpc32xx_hsu_context lpc32xx_uart_context_7 = {
0172   .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 7"),
0173   .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_7,
0174   .irq = LPC32XX_IRQ_UART_7,
0175   .initial_baud = LPC32XX_UART_7_BAUD
0176 };
0177 #endif
0178 
0179 const console_device console_device_table[] = {
0180   #ifdef LPC32XX_UART_5_BAUD
0181     {
0182       .device_file = "/dev/ttyS5",
0183       .probe = console_device_probe_default,
0184       .handler = &ns16550_handler_interrupt,
0185       .context = &lpc32xx_uart_context_5.base
0186     },
0187   #endif
0188   #ifdef LPC32XX_UART_3_BAUD
0189     {
0190       .device_file = "/dev/ttyS3",
0191       .probe = lpc32xx_uart_probe_3,
0192       .handler = &ns16550_handler_interrupt,
0193       .context = &lpc32xx_uart_context_3.base
0194     },
0195   #endif
0196   #ifdef LPC32XX_UART_4_BAUD
0197     {
0198       .device_file = "/dev/ttyS4",
0199       .probe = lpc32xx_uart_probe_4,
0200       .handler = &ns16550_handler_interrupt,
0201       .context = &lpc32xx_uart_context_4.base
0202     },
0203   #endif
0204   #ifdef LPC32XX_UART_6_BAUD
0205     {
0206       .device_file = "/dev/ttyS6",
0207       .probe = lpc32xx_uart_probe_6,
0208       .handler = &ns16550_handler_interrupt,
0209       .context = &lpc32xx_uart_context_6.base
0210     },
0211   #endif
0212   #ifdef LPC32XX_UART_1_BAUD
0213     {
0214       .device_file = "/dev/ttyS1",
0215       .probe = lpc32xx_hsu_probe,
0216       .handler = &lpc32xx_hsu_fns,
0217       .context = &lpc32xx_uart_context_1.base
0218     },
0219   #endif
0220   #ifdef LPC32XX_UART_2_BAUD
0221     {
0222       .device_file = "/dev/ttyS2",
0223       .probe = lpc32xx_hsu_probe,
0224       .handler = &lpc32xx_hsu_fns,
0225       .context = &lpc32xx_uart_context_2.base
0226     },
0227   #endif
0228   #ifdef LPC32XX_UART_7_BAUD
0229     {
0230       .device_file = "/dev/ttyS7",
0231       .probe = lpc32xx_hsu_probe,
0232       .handler = &lpc32xx_hsu_fns,
0233       .context = &lpc32xx_uart_context_7.base
0234     },
0235   #endif
0236 };
0237 
0238 const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);