Changeset f53473f in rtems


Ignore:
Timestamp:
Feb 9, 2020, 7:21:44 PM (2 months ago)
Author:
G S Niteesh <gsnb.gn@…>
Branches:
master
Children:
88c40ef8
Parents:
5857e83c
git-author:
G S Niteesh <gsnb.gn@…> (02/09/20 19:21:44)
git-committer:
Christian Mauderer <oss@…> (02/16/20 15:55:20)
Message:

bsp/raspberrypi: Mini UART driver

This patch adds driver for Mini UART present in Raspberry Pi 3
and above, this UART is currently used as the primary UART in
these models.
The Mini UART is similar to ns16550, this driver is built
upon libchip/ns16550.

Location:
bsps/arm/raspberrypi
Files:
2 edited

Legend:

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

    r5857e83c rf53473f  
    2525#include <libchip/serial.h>
    2626#include <libfdt.h>
     27#include <libchip/ns16550.h>
    2728
    2829#include <bspopts.h>
     
    3536#include <bsp/fdt.h>
    3637#include <bsp/fatal.h>
    37 
    38 
    39 #define UART0     "/dev/ttyS0"
     38#include <bsp/gpio.h>
     39#include <bsp/rpi-gpio.h>
     40
     41/**
     42 * UART0 - PL011
     43 * UART1 - Mini UART
     44 */
     45#define PL011     "/dev/ttyAMA0"
     46#define MINIUART  "/dev/ttyS0"
    4047#define FBCONS    "/dev/fbcons"
    4148
    4249arm_pl011_context pl011_context;
     50ns16550_context mini_uart_context;
    4351
    4452rpi_fb_context fb_context;
    4553
    46 static void output_char_serial(char c)
     54static void output_char_pl011(char c)
    4755{
    4856  arm_pl011_write_polled(&pl011_context.base, c);
    4957}
    5058
     59static void output_char_mini_uart(char c)
     60{
     61  ns16550_polled_putchar(&mini_uart_context.base, c);
     62}
     63
    5164void output_char_fb(char c)
    5265{
    5366  fbcons_write_polled(&fb_context.base, c);
     67}
     68
     69static uint8_t mini_uart_get_reg(uintptr_t port, uint8_t index)
     70{
     71  volatile uint32_t *val = (volatile uint32_t *)port + index;
     72  return (uint8_t) *val;
     73}
     74
     75static void mini_uart_set_reg(uintptr_t port, uint8_t index, uint8_t val)
     76{
     77  volatile uint32_t *reg = (volatile uint32_t *)port + index;
     78  *reg = val;
    5479}
    5580
     
    6085{
    6186  arm_pl011_context *ctx = &pl011_context;
    62   rtems_termios_device_context_initialize(&ctx->base, "UART");
     87  rtems_termios_device_context_initialize(&ctx->base, "PL011UART");
    6388  ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
     89}
     90
     91static uint32_t calculate_baud_divisor(
     92  ns16550_context *ctx,
     93  uint32_t baud
     94)
     95{
     96  uint32_t baudDivisor = (ctx->clock / (8 * baud)) - 1;
     97  return baudDivisor;
     98}
     99
     100static void init_ctx_mini_uart(
     101  const void *fdt,
     102  int node
     103)
     104{
     105  const char *status;
     106  int len;
     107  ns16550_context *ctx;
     108
     109  memset(&mini_uart_context, 0, sizeof(mini_uart_context));
     110  ctx = &mini_uart_context;
     111
     112  rtems_termios_device_context_initialize(&ctx->base, "MiniUART");
     113
     114  status = fdt_getprop(fdt, node, "status", &len);
     115  if ( status == NULL || strcmp(status, "disabled" ) == 0){
     116    return ;
     117  }
     118
     119  ctx->port = (uintptr_t) raspberrypi_get_reg_of_node(fdt, node);
     120  ctx->initial_baud = MINI_UART_DEFAULT_BAUD;
     121  ctx->clock = BCM2835_CLOCK_FREQ;
     122  ctx->calculate_baud_divisor = calculate_baud_divisor;
     123  ctx->get_reg = mini_uart_get_reg;
     124  ctx->set_reg = mini_uart_set_reg;
     125
     126  rtems_gpio_bsp_select_specific_io(0, 14, RPI_ALT_FUNC_5, NULL);
     127  rtems_gpio_bsp_select_specific_io(0, 15, RPI_ALT_FUNC_5, NULL);
     128  rtems_gpio_bsp_set_resistor_mode(0, 14, NO_PULL_RESISTOR);
     129  rtems_gpio_bsp_set_resistor_mode(0, 15, NO_PULL_RESISTOR);
     130
     131  BCM2835_REG(AUX_ENABLES) |= 0x1;
     132  ns16550_probe(&ctx->base);
    64133}
    65134
     
    88157        return ;
    89158      }
     159    } else if ( strncmp( opt, MINIUART, sizeof(MINIUART) - 1 ) == 0) {
     160      BSP_output_char = output_char_mini_uart;
     161      link(MINIUART, CONSOLE_DEVICE_NAME);
     162    } else if ( strncmp( opt, PL011, sizeof(PL011) - 1 ) == 0) {
     163      BSP_output_char = output_char_pl011;
     164      link(PL011, CONSOLE_DEVICE_NAME);
    90165    }
    91   }
    92   BSP_output_char = output_char_serial;
    93   link(UART0, CONSOLE_DEVICE_NAME);
     166  }else {
     167    /**
     168     * If no command line option was given, default to PL011.
     169     */
     170    BSP_output_char = output_char_pl011;
     171    link(PL011, CONSOLE_DEVICE_NAME);
     172  }
    94173}
    95174
     
    98177  static bool initialized = false;
    99178  const void *fdt;
     179  const char *console;
     180  int len;
    100181  int node;
    101182
     
    105186
    106187  fdt = bsp_fdt_get();
     188
    107189  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-pl011");
    108 
    109190  init_ctx_arm_pl011(fdt, node);
    110191
     192  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-aux-uart");
     193  init_ctx_mini_uart(fdt, node);
     194
     195  node = fdt_path_offset(fdt, "/aliases");
     196  console = fdt_getprop(fdt, node, "serial0", &len);
     197
     198  if ( strcmp(console, "/soc/serial@7e215040" ) == 0) {
     199    BSP_output_char = output_char_mini_uart;
     200  }else {
     201    BSP_output_char = output_char_pl011;
     202  }
     203
    111204  initialized = true;
    112205}
     
    115208{
    116209  uart_probe();
    117   output_char_serial(c);
     210  (*BSP_output_char)(c);
    118211}
    119212
     
    128221  uart_probe();
    129222  rtems_termios_device_install(
    130     UART0,
     223    PL011,
    131224    &arm_pl011_fns,
    132225    NULL,
    133226    &pl011_context.base
     227  );
     228
     229  rtems_termios_device_install(
     230    MINIUART,
     231    &ns16550_handler_polled,
     232    NULL,
     233    &mini_uart_context.base
    134234  );
    135235
  • bsps/arm/raspberrypi/include/bsp/usart.h

    r5857e83c rf53473f  
    3434
    3535#define PL011_DEFAULT_BAUD 115000
     36#define MINI_UART_DEFAULT_BAUD   115200
    3637#define BCM2835_PL011_BASE (RPI_PERIPHERAL_BASE + 0x201000)
    3738
Note: See TracChangeset for help on using the changeset viewer.