Changeset 56b0387 in rtems


Ignore:
Timestamp:
Aug 1, 2018, 6:13:39 AM (17 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
dee2ebb
Parents:
a7cd4b73
git-author:
Sebastian Huber <sebastian.huber@…> (08/01/18 06:13:39)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/01/18 09:15:14)
Message:

bsp/riscv: Add NS16750 support to console driver

Update #3433.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bsps/riscv/riscv/console/console-config.c

    ra7cd4b73 r56b0387  
    2727
    2828#include <libfdt.h>
     29#include <string.h>
    2930
    3031#if RISCV_ENABLE_HTIF_SUPPORT != 0
     
    6364
    6465#if RISCV_CONSOLE_MAX_NS16550_DEVICES > 0
    65 static uint8_t get_register(uintptr_t addr, uint8_t i)
     66static uint8_t riscv_console_get_reg_8(uintptr_t addr, uint8_t i)
    6667{
    6768  volatile uint8_t *reg;
     
    7172}
    7273
    73 static void set_register(uintptr_t addr, uint8_t i, uint8_t val)
     74static void riscv_console_set_reg_8(uintptr_t addr, uint8_t i, uint8_t val)
    7475{
    7576  volatile uint8_t *reg;
     
    7879  reg[i] = val;
    7980}
    80 #endif
     81
     82static uint8_t riscv_console_get_reg_32(uintptr_t addr, uint8_t i)
     83{
     84  volatile uint32_t *reg;
     85
     86  reg = (uint32_t *) addr;
     87  return reg[i];
     88}
     89
     90static void riscv_console_set_reg_32(uintptr_t addr, uint8_t i, uint8_t val)
     91{
     92  volatile uint32_t *reg;
     93
     94  reg = (uint32_t *)addr;
     95  reg[i] = val;
     96}
     97#endif
     98
     99#define RISCV_CONSOLE_IS_COMPATIBLE(actual, actual_len, desired) \
     100  (actual_len == sizeof(desired) \
     101     && memcmp(actual, desired, sizeof(desired) - 1) == 0)
    81102
    82103static void riscv_console_probe(void)
     
    98119
    99120  while (node >= 0) {
    100 #if RISCV_ENABLE_HTIF_SUPPORT != 0
    101     if (fdt_node_check_compatible(fdt, node, "ucb,htif0") == 0) {
     121    const char *compat;
     122    int compat_len;
     123
     124    compat = fdt_getprop(fdt, node, "compatible", &compat_len);
     125    if (compat == NULL) {
     126      compat_len = 0;
     127    }
     128
     129#if RISCV_ENABLE_HTIF_SUPPORT != 0
     130    if (RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "ucb,htif0")) {
    102131      htif_console_context_init(&htif_console_instance.base, node);
    103132
     
    109138
    110139#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         ctx->port = (uintptr_t) riscv_fdt_get_address(fdt, node);
    123 
    124         if (ctx->port == 0) {
    125           bsp_fatal(RISCV_FATAL_NO_NS16550_REG_IN_DEVICE_TREE);
    126         }
    127 
    128         val = (fdt32_t *) fdt_getprop(fdt, node, "clock-frequency", &len);
    129 
    130         if (val == NULL || len != 4) {
    131           bsp_fatal(RISCV_FATAL_NO_NS16550_CLOCK_FREQUENCY_IN_DEVICE_TREE);
    132         }
    133 
    134         ctx->clock = fdt32_to_cpu(val[0]);
    135 
    136         val = (fdt32_t *) fdt_getprop(fdt, node, "interrupts", &len);
    137 
    138         if (val == NULL || len != 4) {
    139           bsp_fatal(RISCV_FATAL_NO_NS16550_INTERRUPTS_IN_DEVICE_TREE);
    140         }
    141 
    142         ctx->irq = RISCV_INTERRUPT_VECTOR_EXTERNAL(fdt32_to_cpu(val[0]));
    143 
    144         if (node == console_node) {
    145           riscv_console.context = &ctx->base;
    146           riscv_console.putchar = ns16550_polled_putchar;
    147           riscv_console.getchar = ns16550_polled_getchar;
    148         }
    149 
    150         rtems_termios_device_context_initialize(&ctx->base, "NS16550");
    151         ns16550_probe(&ctx->base);
    152 
    153         ++ns16550_devices;
    154       }
     140    if (
     141      (RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "ns16550a")
     142          || RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "ns16750"))
     143        && ns16550_devices < RISCV_CONSOLE_MAX_NS16550_DEVICES
     144    ) {
     145      ns16550_context *ctx;
     146      fdt32_t *val;
     147      int len;
     148
     149      ctx = &ns16550_instances[ns16550_devices];
     150      ctx->initial_baud = BSP_CONSOLE_BAUD;
     151
     152      if (RISCV_CONSOLE_IS_COMPATIBLE(compat, compat_len, "ns16750")) {
     153        ctx->has_precision_clock_synthesizer = true;
     154        ctx->get_reg = riscv_console_get_reg_32;
     155        ctx->set_reg = riscv_console_set_reg_32;
     156      } else {
     157        ctx->get_reg = riscv_console_get_reg_8;
     158        ctx->set_reg = riscv_console_set_reg_8;
     159      }
     160
     161      ctx->port = (uintptr_t) riscv_fdt_get_address(fdt, node);
     162
     163      if (ctx->port == 0) {
     164        bsp_fatal(RISCV_FATAL_NO_NS16550_REG_IN_DEVICE_TREE);
     165      }
     166
     167      val = (fdt32_t *) fdt_getprop(fdt, node, "clock-frequency", &len);
     168
     169      if (val == NULL || len != 4) {
     170        bsp_fatal(RISCV_FATAL_NO_NS16550_CLOCK_FREQUENCY_IN_DEVICE_TREE);
     171      }
     172
     173      ctx->clock = fdt32_to_cpu(val[0]);
     174
     175      val = (fdt32_t *) fdt_getprop(fdt, node, "interrupts", &len);
     176
     177      if (val == NULL || len != 4) {
     178        bsp_fatal(RISCV_FATAL_NO_NS16550_INTERRUPTS_IN_DEVICE_TREE);
     179      }
     180
     181      ctx->irq = RISCV_INTERRUPT_VECTOR_EXTERNAL(fdt32_to_cpu(val[0]));
     182
     183      if (node == console_node) {
     184        riscv_console.context = &ctx->base;
     185        riscv_console.putchar = ns16550_polled_putchar;
     186        riscv_console.getchar = ns16550_polled_getchar;
     187      }
     188
     189      rtems_termios_device_context_initialize(&ctx->base, "NS16550");
     190      ns16550_probe(&ctx->base);
     191
     192      ++ns16550_devices;
    155193    }
    156194#endif
Note: See TracChangeset for help on using the changeset viewer.