summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/qoriq/console/console-config.c
blob: 352b118c2a3cb4db3ed111009ded20fc0c8a7a6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/**
 * @file
 *
 * @ingroup QorIQ
 *
 * @brief Console configuration.
 */

/*
 * Copyright (c) 2010-2014 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#include <rtems/bspIo.h>

#include <libchip/ns16550.h>

#include <bsp.h>
#include <bsp/irq.h>
#include <bsp/qoriq.h>
#include <bsp/intercom.h>
#include <bsp/uart-bridge.h>
#include <bsp/console-termios.h>

#if (QORIQ_UART_0_ENABLE + QORIQ_UART_BRIDGE_0_ENABLE == 2) \
  || (QORIQ_UART_1_ENABLE + QORIQ_UART_BRIDGE_1_ENABLE == 2)
  #define BRIDGE_MASTER
#elif QORIQ_UART_BRIDGE_0_ENABLE || QORIQ_UART_BRIDGE_1_ENABLE
  #define BRIDGE_SLAVE
#endif

#ifdef BSP_USE_UART_INTERRUPTS
  #define DEVICE_FNS &ns16550_handler_interrupt
#else
  #define DEVICE_FNS &ns16550_handler_polled
#endif

#if QORIQ_UART_0_ENABLE || QORIQ_UART_1_ENABLE
  static uint8_t get_register(uintptr_t addr, uint8_t i)
  {
    volatile uint8_t *reg = (uint8_t *) addr;

    return reg [i];
  }

  static void set_register(uintptr_t addr, uint8_t i, uint8_t val)
  {
    volatile uint8_t *reg = (uint8_t *) addr;

    reg [i] = val;
  }
#endif

#if QORIQ_UART_0_ENABLE
static ns16550_context qoriq_uart_context_0 = {
  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 0"),
  .get_reg = get_register,
  .set_reg = set_register,
  .port = (uintptr_t) &qoriq.uart_0,
  .irq = QORIQ_IRQ_DUART,
  .initial_baud = BSP_CONSOLE_BAUD
};
#endif

#if QORIQ_UART_1_ENABLE
static ns16550_context qoriq_uart_context_1 = {
  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
  .get_reg = get_register,
  .set_reg = set_register,
  .port = (uintptr_t) &qoriq.uart_1,
  .irq = QORIQ_IRQ_DUART,
  .initial_baud = BSP_CONSOLE_BAUD
};
#endif

#ifdef BRIDGE_MASTER
  #define BRIDGE_PROBE qoriq_uart_bridge_master_probe
  #define BRIDGE_FNS &qoriq_uart_bridge_master
  #if QORIQ_UART_BRIDGE_0_ENABLE
    static uart_bridge_master_context bridge_0_context = {
      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 0"),
      .device_path = "/dev/ttyS0",
      .type = INTERCOM_TYPE_UART_0,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_0_context.transmit_fifo
      )
    };
    #define BRIDGE_0_CONTEXT &bridge_0_context.base
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    static uart_bridge_master_context bridge_1_context = {
      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 1"),
      .device_path = "/dev/ttyS1",
      .type = INTERCOM_TYPE_UART_1,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_1_context.transmit_fifo
      )
    };
    #define BRIDGE_1_CONTEXT &bridge_1_context.base
  #endif
#endif

#ifdef BRIDGE_SLAVE
  #define BRIDGE_PROBE console_device_probe_default
  #define BRIDGE_FNS &qoriq_uart_bridge_slave
  #if QORIQ_UART_BRIDGE_0_ENABLE
    static uart_bridge_slave_context bridge_0_context = {
      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 0"),
      .type = INTERCOM_TYPE_UART_0,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_0_context.transmit_fifo
      )
    };
    #define BRIDGE_0_CONTEXT &bridge_0_context.base
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    static uart_bridge_slave_context bridge_1_context = {
      .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART Bridge 1"),
      .type = INTERCOM_TYPE_UART_1,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_1_context.transmit_fifo
      )
    };
    #define BRIDGE_1_CONTEXT &bridge_1_context.base
  #endif
#endif

const console_device console_device_table[] = {
  #if QORIQ_UART_0_ENABLE
    {
      .device_file = "/dev/ttyS0",
      .probe = ns16550_probe,
      .handler = DEVICE_FNS,
      .context = &qoriq_uart_context_0.base
    },
  #endif
  #if QORIQ_UART_1_ENABLE
    {
      .device_file = "/dev/ttyS1",
      .probe = ns16550_probe,
      .handler = DEVICE_FNS,
      .context = &qoriq_uart_context_1.base
    },
  #endif
  #if QORIQ_UART_BRIDGE_0_ENABLE
    {
      #if QORIQ_UART_1_ENABLE
        .device_file = "/dev/ttyB0",
      #else
        .device_file = "/dev/ttyS0",
      #endif
      .probe = BRIDGE_PROBE,
      .handler = BRIDGE_FNS,
      .context = BRIDGE_0_CONTEXT
    },
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    {
      #if QORIQ_UART_1_ENABLE
        .device_file = "/dev/ttyB1",
      #else
        .device_file = "/dev/ttyS1",
      #endif
      .probe = BRIDGE_PROBE,
      .handler = BRIDGE_FNS,
      .context = BRIDGE_1_CONTEXT
    }
  #endif
};

const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);

static void output_char(char c)
{
  rtems_termios_device_context *ctx = console_device_table[0].context;

  if (c == '\n') {
    ns16550_polled_putchar(ctx, '\r');
  }

  ns16550_polled_putchar(ctx, c);
}

BSP_output_char_function_type BSP_output_char = output_char;

BSP_polling_getchar_function_type BSP_poll_char = NULL;