summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/qoriq/console/console-config.c
blob: b14c6bdd634ff3575548d4d235854c760ca0832c (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
196
197
198
199
200
201
202
/**
 * @file
 *
 * @ingroup QorIQ
 *
 * @brief Console configuration.
 */

/*
 * Copyright (c) 2010 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  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.com/license/LICENSE.
 *
 * $Id$
 */

#include <assert.h>

#include <rtems/bspIo.h>

#include <libchip/serial.h>
#include <libchip/ns16550.h>
#include "../../../shared/console_private.h"

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

#define CONSOLE_COUNT \
  (QORIQ_UART_0_ENABLE \
    + QORIQ_UART_1_ENABLE \
    + QORIQ_UART_BRIDGE_0_ENABLE \
    + QORIQ_UART_BRIDGE_1_ENABLE)

#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 BRIDGE_MASTER
  #define BRIDGE_FNS &qoriq_uart_bridge_master
  #if QORIQ_UART_BRIDGE_0_ENABLE
    static uart_bridge_master_control bridge_0_control = {
      .device_path = "/dev/ttyS0",
      .type = INTERCOM_TYPE_UART_0,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_0_control.transmit_fifo
      )
    };
    #define BRIDGE_0_CONTROL &bridge_0_control
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    static uart_bridge_master_control bridge_1_control = {
      .device_path = "/dev/ttyS1",
      .type = INTERCOM_TYPE_UART_1,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_1_control.transmit_fifo
      )
    };
    #define BRIDGE_1_CONTROL &bridge_1_control
  #endif
#endif

#ifdef BRIDGE_SLAVE
  #define BRIDGE_FNS &qoriq_uart_bridge_slave
  #if QORIQ_UART_BRIDGE_0_ENABLE
    static uart_bridge_slave_control bridge_0_control = {
      .type = INTERCOM_TYPE_UART_0,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_0_control.transmit_fifo
      )
    };
    #define BRIDGE_0_CONTROL &bridge_0_control
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    static uart_bridge_slave_control bridge_1_control = {
      .type = INTERCOM_TYPE_UART_1,
      .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY(
        bridge_1_control.transmit_fifo
      )
    };
    #define BRIDGE_1_CONTROL &bridge_1_control
  #endif
#endif

#ifdef BSP_USE_UART_INTERRUPTS
  #define DEVICE_FNS &ns16550_fns
#else
  #define DEVICE_FNS &ns16550_fns_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

unsigned long Console_Configuration_Count = CONSOLE_COUNT;
console_tbl Console_Configuration_Ports [CONSOLE_COUNT] = {
  #if QORIQ_UART_0_ENABLE
    {
      .sDeviceName = "/dev/ttyS0",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = DEVICE_FNS,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) BSP_CONSOLE_BAUD,
      .ulCtrlPort1 = (uintptr_t) &qoriq.uart_0,
      .ulCtrlPort2 = 0,
      .ulDataPort =  (uintptr_t) &qoriq.uart_0,
      .getRegister = get_register,
      .setRegister = set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 0,
      .ulIntVector = QORIQ_IRQ_DUART
    },
  #endif
  #if QORIQ_UART_1_ENABLE
    {
      .sDeviceName = "/dev/ttyS1",
      .deviceType = SERIAL_NS16550,
      .pDeviceFns = DEVICE_FNS,
      .deviceProbe = NULL,
      .pDeviceFlow = NULL,
      .ulMargin = 16,
      .ulHysteresis = 8,
      .pDeviceParams = (void *) BSP_CONSOLE_BAUD,
      .ulCtrlPort1 = (uintptr_t) &qoriq.uart_1,
      .ulCtrlPort2 = 0,
      .ulDataPort =  (uintptr_t) &qoriq.uart_1,
      .getRegister = get_register,
      .setRegister = set_register,
      .getData = NULL,
      .setData = NULL,
      .ulClock = 0,
      .ulIntVector = QORIQ_IRQ_DUART
    },
  #endif
  #if QORIQ_UART_BRIDGE_0_ENABLE
    {
      #if QORIQ_UART_1_ENABLE
        .sDeviceName = "/dev/ttyB0",
      #else
        .sDeviceName = "/dev/ttyS0",
      #endif
      .deviceType = SERIAL_CUSTOM,
      .pDeviceFns = BRIDGE_FNS,
      .pDeviceParams = BRIDGE_0_CONTROL
    },
  #endif
  #if QORIQ_UART_BRIDGE_1_ENABLE
    {
      #if QORIQ_UART_1_ENABLE
        .sDeviceName = "/dev/ttyB1",
      #else
        .sDeviceName = "/dev/ttyS1",
      #endif
      .deviceType = SERIAL_CUSTOM,
      .pDeviceFns = BRIDGE_FNS,
      .pDeviceParams = BRIDGE_1_CONTROL
    }
  #endif
};

static void output_char(char c)
{
  const console_fns *con = Console_Port_Tbl [Console_Port_Minor]->pDeviceFns;
  
  if (c == '\n') {
    con->deviceWritePolled((int) Console_Port_Minor, '\r');
  }
  con->deviceWritePolled((int) Console_Port_Minor, c);
}

BSP_output_char_function_type BSP_output_char = output_char;

BSP_polling_getchar_function_type BSP_poll_char = NULL;