Changeset 1a19239 in rtems


Ignore:
Timestamp:
Jul 6, 2018, 9:20:31 AM (7 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
76c03152
Parents:
31f90a2
git-author:
Sebastian Huber <sebastian.huber@…> (07/06/18 09:20:31)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/06/18 12:27:39)
Message:

bsp/riscv: Add console support for NS16550 devices

Update #3433.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • bsps/include/bsp/fatal.h

    r31f90a2 r1a19239  
    141141
    142142  /* RISC-V fatal codes */
    143   RISCV_FATAL_NO_TIMEBASE_FREQUENCY_IN_DEVICE_TREE = BSP_FATAL_CODE_BLOCK(13)
     143  RISCV_FATAL_NO_TIMEBASE_FREQUENCY_IN_DEVICE_TREE = BSP_FATAL_CODE_BLOCK(13),
     144  RISCV_FATAL_NO_NS16550_REG_IN_DEVICE_TREE,
     145  RISCV_FATAL_NO_NS16550_CLOCK_FREQUENCY_IN_DEVICE_TREE
    144146} bsp_fatal_code;
    145147
  • bsps/riscv/riscv/console/console-config.c

    r31f90a2 r1a19239  
    1919
    2020#include <bsp.h>
     21#include <bsp/fatal.h>
    2122#include <bsp/fdt.h>
    2223#include <bsp/irq.h>
    2324
    2425#include <dev/serial/htif.h>
     26#include <libchip/ns16550.h>
    2527
    2628#include <libfdt.h>
     
    2830#if RISCV_ENABLE_HTIF_SUPPORT > 0
    2931static htif_console_context htif_console_instance;
     32#endif
     33
     34#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     35static ns16550_context ns16550_instances[RISCV_CONSOLE_MAX_NS16550_DEVICES];
    3036#endif
    3137
     
    5662}
    5763
     64#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     65static uint8_t get_register(uintptr_t addr, uint8_t i)
     66{
     67  volatile uint8_t *reg;
     68
     69  reg = (uint8_t *) addr;
     70  return reg[i];
     71}
     72
     73static void set_register(uintptr_t addr, uint8_t i, uint8_t val)
     74{
     75  volatile uint8_t *reg;
     76
     77  reg = (uint8_t *)addr;
     78  reg[i] = val;
     79}
     80#endif
     81
    5882static void riscv_console_probe(void)
    5983{
     
    6185  int node;
    6286  int console_node;
     87#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     88  size_t ns16550_devices;
     89#endif
    6390
    6491  fdt = bsp_fdt_get();
    6592  console_node = riscv_get_console_node(fdt);
     93#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     94  ns16550_devices = 0;
     95#endif
    6696
    6797  node = fdt_next_node(fdt, -1, NULL);
     
    76106      riscv_console.getchar = htif_console_getchar;
    77107    };
     108#endif
     109
     110#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     111    if (fdt_node_check_compatible(fdt, node, "ns16550a") == 0) {
     112      if (ns16550_devices < RISCV_CONSOLE_MAX_NS16550_DEVICES) {
     113        ns16550_context *ctx;
     114        fdt32_t *val;
     115        int len;
     116
     117        ctx = &ns16550_instances[ns16550_devices];
     118        ctx->get_reg = get_register;
     119        ctx->set_reg = set_register;
     120        ctx->initial_baud = BSP_CONSOLE_BAUD;
     121
     122        val = (fdt32_t *) fdt_getprop(fdt, node, "reg", &len);
     123
     124        if (val == NULL || (len != 8 && len != 16)) {
     125          bsp_fatal(RISCV_FATAL_NO_NS16550_REG_IN_DEVICE_TREE);
     126        }
     127
     128        if (len == 16) {
     129          ctx->port = fdt32_to_cpu(val[1]);
     130        } else {
     131          ctx->port = fdt32_to_cpu(val[0]);
     132        }
     133
     134        val = (fdt32_t *) fdt_getprop(fdt, node, "clock-frequency", &len);
     135
     136        if (val == NULL || len != 4) {
     137          bsp_fatal(RISCV_FATAL_NO_NS16550_CLOCK_FREQUENCY_IN_DEVICE_TREE);
     138        }
     139
     140        ctx->clock = fdt32_to_cpu(val[0]);
     141
     142        if (node == console_node) {
     143          riscv_console.context = &ctx->base;
     144          riscv_console.putchar = ns16550_polled_putchar;
     145          riscv_console.getchar = ns16550_polled_getchar;
     146        }
     147
     148        rtems_termios_device_context_initialize(&ctx->base, "NS16550");
     149        ns16550_probe(&ctx->base);
     150
     151        ++ns16550_devices;
     152      }
     153    }
    78154#endif
    79155
     
    102178  rtems_termios_device_context *base;
    103179  char htif_path[] = "/dev/ttyShtif";
     180#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     181  char path[] = "/dev/ttyS?";
     182  size_t i;
     183#endif
    104184
    105185  rtems_termios_initialize();
     
    111191  if (base == riscv_console.context) {
    112192    link(htif_path, CONSOLE_DEVICE_NAME);
     193  }
     194#endif
     195
     196#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
     197  for (i = 0; i < RISCV_CONSOLE_MAX_NS16550_DEVICES; ++i) {
     198    ns16550_context *ctx;
     199
     200    ctx = &ns16550_instances[i];
     201    path[sizeof(path) - 2] = (char) ('0' + i);
     202
     203    rtems_termios_device_install(
     204      path,
     205      &ns16550_handler_polled,
     206      NULL,
     207      &ctx->base
     208    );
     209
     210    if (&ctx->base == riscv_console.context) {
     211      link(path, CONSOLE_DEVICE_NAME);
     212    }
    113213  }
    114214#endif
  • c/src/lib/libbsp/riscv/riscv/configure.ac

    r31f90a2 r1a19239  
    2828RTEMS_BSPOPTS_HELP([BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA],[copy the FDT blob into the read-only load area via bsp_fdt_copy()])
    2929
     30RTEMS_BSPOPTS_SET([BSP_CONSOLE_BAUD],[*],[115200])
     31RTEMS_BSPOPTS_HELP([BSP_CONSOLE_BAUD],[default baud for console driver devices (default 115200)])
     32
    3033RTEMS_BSPOPTS_SET([RISCV_ENABLE_HTIF_SUPPORT],[*],[1])
    3134RTEMS_BSPOPTS_HELP([RISCV_ENABLE_HTIF_SUPPORT],[enables the HTIF support if defined to a non-zero value, otherwise it is disabled (enabled by default)])
     35
     36RTEMS_BSPOPTS_SET([RISCV_CONSOLE_MAX_NS16550_DEVICES],[*],[2])
     37RTEMS_BSPOPTS_HELP([RISCV_CONSOLE_MAX_NS16550_DEVICES],[maximum number of NS16550 devices supported by the console driver (2 by default)])
    3238
    3339RTEMS_BSP_CLEANUP_OPTIONS
Note: See TracChangeset for help on using the changeset viewer.