Changeset 362cf319 in rtems


Ignore:
Timestamp:
Jan 4, 2020, 7:50:46 PM (7 weeks ago)
Author:
G S Niteesh <gsnb.gn@…>
Branches:
master
Children:
5e7b3c65
Parents:
eca25ef
git-author:
G S Niteesh <gsnb.gn@…> (01/04/20 19:50:46)
git-committer:
Christian Mauderer <christian.mauderer@…> (01/07/20 17:21:16)
Message:

bsp/raspberrypi: Updated the console API.

Replaces the legacy termios API with new termios API (#3034)
Replaces the custom PL011 serial driver with RTEMS arm-pl011.
Update #3034

Files:
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/raspberrypi/console/console-config.c

    reca25ef r362cf319  
    2020
    2121#include <rtems/bspIo.h>
     22#include <rtems/console.h>
     23#include <rtems/sysinit.h>
    2224
    2325#include <libchip/serial.h>
     26#include <libfdt.h>
    2427
    2528#include <bspopts.h>
    26 #include <bsp/irq.h>
    2729#include <bsp/usart.h>
    2830#include <bsp/raspberrypi.h>
    2931#include <bsp/fbcons.h>
     32#include <bsp.h>
     33#include <bsp/arm-pl011.h>
     34#include <bsp/console-termios.h>
     35#include <bsp/fdt.h>
     36#include <bsp/fatal.h>
    3037
    31 console_tbl Console_Configuration_Ports [] = {
    32     {
    33       .sDeviceName = "/dev/ttyS0",
    34       .deviceType = SERIAL_CUSTOM,
    35       .pDeviceFns = &bcm2835_usart_fns,
    36       .deviceProbe = NULL,
    37       .pDeviceFlow = NULL,
    38       .ulCtrlPort1 = BCM2835_UART0_BASE,
    39       .ulCtrlPort2 = 0,
    40       .ulClock = USART0_DEFAULT_BAUD,
    41       .ulIntVector = BCM2835_IRQ_ID_UART
    42     },
    43     {
    44       .sDeviceName ="/dev/fbcons",
    45       .deviceType = SERIAL_CUSTOM,
    46       .pDeviceFns = &fbcons_fns,
    47       .deviceProbe = fbcons_probe,
    48       .pDeviceFlow = NULL,
    49     },
    50 };
    5138
    52 #define PORT_COUNT \
    53   (sizeof(Console_Configuration_Ports) \
    54     / sizeof(Console_Configuration_Ports [0]))
     39#define UART0     "/dev/ttyS0"
     40#define FBCONS    "/dev/fbcons"
    5541
    56 unsigned long Console_Configuration_Count = PORT_COUNT;
     42arm_pl011_context pl011_context;
     43
     44rpi_fb_context fb_context;
     45
     46static void output_char_serial(char c)
     47{
     48  arm_pl011_write_polled(&pl011_context.base, c);
     49}
     50
     51void output_char_fb(char c)
     52{
     53  fbcons_write_polled(&fb_context.base, c);
     54}
     55
     56static void init_ctx_arm_pl011(
     57  const void *fdt,
     58  int node
     59)
     60{
     61  arm_pl011_context *ctx = &pl011_context;
     62  rtems_termios_device_context_initialize(&ctx->base, "UART");
     63  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
     64}
     65
     66static void register_fb( void )
     67{
     68  if (fbcons_probe(&fb_context.base) == true) {
     69    rtems_termios_device_install(
     70      FBCONS,
     71      &fbcons_fns,
     72      NULL,
     73      &fb_context.base);
     74  }
     75}
     76
     77static void console_select( void )
     78{
     79  const char *opt;
     80
     81  opt = rpi_cmdline_get_arg("--console=");
     82
     83  if ( opt ) {
     84    if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 ) == 0 ) {
     85      if ( rpi_video_is_initialized() > 0 ) {
     86        BSP_output_char = output_char_fb;
     87        link(FBCONS, CONSOLE_DEVICE_NAME);
     88        return ;
     89      }
     90    }
     91  }
     92  BSP_output_char = output_char_serial;
     93  link(UART0, CONSOLE_DEVICE_NAME);
     94}
     95
     96static void uart_probe(void)
     97{
     98  static bool initialized = false;
     99  const void *fdt;
     100  int node;
     101
     102  if ( initialized ) {
     103    return ;
     104  }
     105
     106  fdt = bsp_fdt_get();
     107  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-pl011");
     108
     109  init_ctx_arm_pl011(fdt, node);
     110
     111  initialized = true;
     112}
    57113
    58114static void output_char(char c)
    59115{
    60   const console_fns *con =
    61     Console_Configuration_Ports [Console_Port_Minor].pDeviceFns;
     116  uart_probe();
     117  output_char_serial(c);
     118}
    62119
    63   con->deviceWritePolled((int) Console_Port_Minor, c);
     120rtems_status_code console_initialize(
     121  rtems_device_major_number major,
     122  rtems_device_minor_number minor,
     123  void *arg
     124)
     125{
     126  rtems_termios_initialize();
     127
     128  uart_probe();
     129  rtems_termios_device_install(
     130    UART0,
     131    &arm_pl011_fns,
     132    NULL,
     133    &pl011_context.base
     134  );
     135
     136  register_fb();
     137
     138  console_select();
     139
     140  return RTEMS_SUCCESSFUL;
    64141}
    65142
     
    67144
    68145BSP_polling_getchar_function_type BSP_poll_char = NULL;
     146
     147RTEMS_SYSINIT_ITEM(
     148  uart_probe,
     149  RTEMS_SYSINIT_BSP_START,
     150  RTEMS_SYSINIT_ORDER_LAST
     151);
  • bsps/arm/raspberrypi/console/fbcons.c

    reca25ef r362cf319  
    1919#include <rtems.h>
    2020#include <rtems/libio.h>
     21#include <rtems/termiostypes.h>
    2122
    2223#include <stdlib.h>
     
    3132
    3233/*
    33  *  fbcons_init
    34  *
    35  *  This function initializes the fb console to a quiecsent state.
    36  */
    37 static void fbcons_init( int minor )
    38 {
    39 }
    40 
    41 /*
    4234 *  fbcons_open
    4335 *
     
    4638 *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
    4739 */
    48 static int fbcons_open(
    49   int   major,
    50   int   minor,
    51   void *arg
     40static bool fbcons_open(
     41  struct rtems_termios_tty *tty,
     42  rtems_termios_device_context *base,
     43  struct termios *term,
     44  rtems_libio_open_close_args_t *args
    5245)
    5346{
    54   return RTEMS_SUCCESSFUL;
     47  return true;
    5548}
    5649
     
    6053 *  This function shuts down the requested port.
    6154 */
    62 static int fbcons_close(
    63   int   major,
    64   int   minor,
    65   void *arg
     55static void fbcons_close(
     56  struct rtems_termios_tty *tty,
     57  rtems_termios_device_context *base,
     58  rtems_libio_open_close_args_t *args
    6659)
    6760{
    68   return ( RTEMS_SUCCESSFUL );
    6961}
    7062
     
    7466 *  This routine polls out the requested character.
    7567 */
    76 static void fbcons_write_polled(
    77   int  minor,
     68void fbcons_write_polled(
     69  rtems_termios_device_context *base,
    7870  char c
    7971)
     
    9183 *
    9284 */
    93 static ssize_t fbcons_write_support_polled(
    94   int         minor,
     85static void fbcons_write_support_polled(
     86  rtems_termios_device_context *base,
    9587  const char *buf,
    9688  size_t      len
     
    10395   */
    10496  while ( nwrite < len ) {
    105     fbcons_write_polled( minor, *buf++ );
     97    fbcons_write_polled( base, *buf++ );
    10698    nwrite++;
    10799  }
    108 
    109   /*
    110    * return the number of bytes written.
    111    */
    112   return nwrite;
    113100}
    114101
     
    118105 *  Console Termios polling input entry point.
    119106 */
    120 static int fbcons_inbyte_nonblocking_polled( int minor )
     107static int fbcons_inbyte_nonblocking_polled(
     108  rtems_termios_device_context *base
     109)
    121110{
    122111  // if( rtems_kbpoll() ) {
     
    134123 *  port settings.
    135124 */
    136 static int fbcons_set_attributes(
    137   int                   minor,
     125static bool fbcons_set_attributes(
     126  rtems_termios_device_context *base,
    138127  const struct termios *t
    139128)
    140129{
    141   return 0;
     130  return true;
    142131}
    143132
    144 bool fbcons_probe( int minor )
     133bool fbcons_probe(
     134  rtems_termios_device_context *context
     135)
    145136{
    146137  // rtems_status_code status;
     
    164155}
    165156
    166 const console_fns fbcons_fns =
     157const rtems_termios_device_handler fbcons_fns =
    167158{
    168   .deviceProbe = libchip_serial_default_probe,     /* deviceProbe */
    169   .deviceFirstOpen = fbcons_open,                 /* deviceFirstOpen */
    170   .deviceLastClose = fbcons_close,                /* deviceLastClose */
    171   .deviceRead = fbcons_inbyte_nonblocking_polled, /* deviceRead */
    172   .deviceWrite = fbcons_write_support_polled,     /* deviceWrite */
    173   .deviceInitialize = fbcons_init,                /* deviceInitialize */
    174   .deviceWritePolled = fbcons_write_polled,       /* deviceWritePolled */
    175   .deviceSetAttributes = fbcons_set_attributes,   /* deviceSetAttributes */
    176   .deviceOutputUsesInterrupts = FALSE,           /* deviceOutputUsesInterrupts*/
     159  .first_open = fbcons_open,
     160  .last_close = fbcons_close,
     161  .poll_read = fbcons_inbyte_nonblocking_polled,
     162  .write = fbcons_write_support_polled,
     163  .set_attributes = fbcons_set_attributes,
     164  .mode = TERMIOS_POLLED
    177165};
  • bsps/arm/raspberrypi/include/bsp.h

    reca25ef r362cf319  
    5555#define BSP_CONSOLE_FB      1
    5656
     57void *raspberrypi_get_reg_of_node(const void *fdt, int node);
     58
    5759void rpi_init_cmdline(void);
    5860const char *rpi_cmdline_get_cached(void);
  • bsps/arm/raspberrypi/include/bsp/fbcons.h

    reca25ef r362cf319  
    2121
    2222#include <libchip/serial.h>
     23#include <rtems/termiostypes.h>
    2324
    2425#ifdef __cplusplus
     
    3435#define FB_CONSOLE 0x50492835
    3536
    36 bool fbcons_probe( int minor );
     37bool fbcons_probe(
     38  rtems_termios_device_context *base
     39 );
     40
     41void fbcons_write_polled(
     42  rtems_termios_device_context *base,
     43  char c
     44);
     45
     46void output_char_fb(char c);
     47
     48typedef struct {
     49    rtems_termios_device_context base;
     50} rpi_fb_context ;
    3751
    3852/*
    3953 * Driver function table
    4054 */
    41 extern const console_fns fbcons_fns;
     55extern const rtems_termios_device_handler fbcons_fns;
    4256
    4357#ifdef __cplusplus
  • bsps/arm/raspberrypi/include/bsp/raspberrypi.h

    reca25ef r362cf319  
    5454
    5555#if (BSP_IS_RPI2 == 1)
    56    #define RPI_PERIPHERAL_BASE      0x3F000000
     56  #define RPI_PERIPHERAL_BASE    0x3F000000
     57  #define BASE_OFFSET            0X3F000000
    5758#else
    58    #define RPI_PERIPHERAL_BASE      0x20000000
     59  #define RPI_PERIPHERAL_BASE    0x20000000
     60  #define BASE_OFFSET            0X5E000000
    5961#endif
    6062
    61 #define RPI_PERIPHERAL_SIZE         0x01000000
     63#define RPI_PERIPHERAL_SIZE      0x01000000
     64
     65/**
     66 * @name Bus to Physical address translation
     67 *       Macro.
     68 * @{
     69 */
     70
     71#define BUS_TO_PHY(x)            ((x) - BASE_OFFSET)
     72
     73/** @} */
    6274
    6375/**
     
    184196
    185197/** @} */
    186 
    187 /**
    188  * @name UART 0 (PL011) Registers
    189  *
    190  * @{
    191  */
    192 
    193 #define BCM2835_UART0_BASE       (RPI_PERIPHERAL_BASE + 0x201000)
    194 
    195 #define BCM2835_UART0_DR         (BCM2835_UART0_BASE + 0x00)
    196 #define BCM2835_UART0_RSRECR     (BCM2835_UART0_BASE + 0x04)
    197 #define BCM2835_UART0_FR         (BCM2835_UART0_BASE + 0x18)
    198 #define BCM2835_UART0_ILPR       (BCM2835_UART0_BASE + 0x20)
    199 #define BCM2835_UART0_IBRD       (BCM2835_UART0_BASE + 0x24)
    200 #define BCM2835_UART0_FBRD       (BCM2835_UART0_BASE + 0x28)
    201 #define BCM2835_UART0_LCRH       (BCM2835_UART0_BASE + 0x2C)
    202 #define BCM2835_UART0_CR         (BCM2835_UART0_BASE + 0x30)
    203 #define BCM2835_UART0_IFLS       (BCM2835_UART0_BASE + 0x34)
    204 #define BCM2835_UART0_IMSC       (BCM2835_UART0_BASE + 0x38)
    205 #define BCM2835_UART0_RIS        (BCM2835_UART0_BASE + 0x3C)
    206 #define BCM2835_UART0_MIS        (BCM2835_UART0_BASE + 0x40)
    207 #define BCM2835_UART0_ICR        (BCM2835_UART0_BASE + 0x44)
    208 #define BCM2835_UART0_DMACR      (BCM2835_UART0_BASE + 0x48)
    209 #define BCM2835_UART0_ITCR       (BCM2835_UART0_BASE + 0x80)
    210 #define BCM2835_UART0_ITIP       (BCM2835_UART0_BASE + 0x84)
    211 #define BCM2835_UART0_ITOP       (BCM2835_UART0_BASE + 0x88)
    212 #define BCM2835_UART0_TDR        (BCM2835_UART0_BASE + 0x8C)
    213 
    214 #define BCM2835_UART0_MIS_RX    0x10
    215 #define BCM2835_UART0_MIS_TX    0x20
    216 #define BCM2835_UART0_IMSC_RX   0x10
    217 #define BCM2835_UART0_IMSC_TX   0x20
    218 #define BCM2835_UART0_FR_RXFE   0x10
    219 #define BCM2835_UART0_FR_TXFF   0x20
    220 #define BCM2835_UART0_ICR_RX    0x10
    221 #define BCM2835_UART0_ICR_TX    0x20
    222198
    223199/** @} */
  • bsps/arm/raspberrypi/include/bsp/usart.h

    reca25ef r362cf319  
    3333#endif /* __cplusplus */
    3434
    35 #define USART0_DEFAULT_BAUD 115000
    36 
    37 extern const console_fns bcm2835_usart_fns;
     35#define PL011_DEFAULT_BAUD 115000
     36#define BCM2835_PL011_BASE (RPI_PERIPHERAL_BASE + 0x201000)
    3837
    3938#ifdef __cplusplus
  • bsps/arm/raspberrypi/start/bspstart.c

    reca25ef r362cf319  
    2424#include <bsp/raspberrypi.h>
    2525#include <bsp/vc.h>
     26
     27#include <libfdt.h>
    2628
    2729static const struct {
     
    8789#define NUMOF(_s) (sizeof(_s) / sizeof(_s[0]))
    8890
     91void *raspberrypi_get_reg_of_node(const void *fdt, int node)
     92{
     93  int len;
     94  const uint32_t *val;
     95
     96  val = fdt_getprop(fdt, node, "reg", &len);
     97  if (val == NULL || len < 4) {
     98    return NULL;
     99  }
     100
     101  return (BUS_TO_PHY((void *) fdt32_to_cpu(val[0])));
     102}
     103
    89104void bsp_start(void)
    90105{
  • c/src/lib/libbsp/arm/raspberrypi/Makefile.am

    reca25ef r362cf319  
    6464
    6565# Console
    66 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/legacy-console.c
    67 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/legacy-console-control.c
     66librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
     67librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/shared/serial/arm-pl011.c
    6868librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/console/console-config.c
    69 librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/console/console_select.c
    70 librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/console/usart.c
    7169librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/console/fb.c
    7270librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/raspberrypi/console/fbcons.c
Note: See TracChangeset for help on using the changeset viewer.