source: rtems/c/src/lib/libbsp/arm/altera-cyclone-v/console/console-config.c @ 774ee002

4.115
Last change on this file since 774ee002 was c8b7b32, checked in by Ralf Kirchner <ralf.kirchner@…>, on 05/12/14 at 13:21:52

bsp/altera-caclone-v: Early printk support

Make sure printk can work early during BSP startup.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <assert.h>
16#include <stdint.h>
17#include <stdbool.h>
18#include <libchip/serial.h>
19#include <libchip/ns16550.h>
20
21#include <bsp.h>
22#include <bsp/irq.h>
23#include <bsp/alt_clock_manager.h>
24#include "socal/alt_rstmgr.h"
25#include "socal/socal.h"
26#include "socal/alt_uart.h"
27#include "socal/hps.h"
28
29bool altera_cyclone_v_uart_probe( int minor );
30
31static uint8_t altera_cyclone_v_uart_get_register(uintptr_t addr, uint8_t i)
32{
33  volatile uint32_t *reg = (volatile uint32_t *) addr;
34
35  return (uint8_t) reg [i];
36}
37
38static void altera_cyclone_v_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
39{
40  volatile uint32_t *reg = (volatile uint32_t *) addr;
41
42  reg [i] = val;
43}
44
45console_tbl Console_Configuration_Ports[] = {
46#ifdef CYCLONE_V_CONFIG_CONSOLE
47  {
48    .sDeviceName   = "/dev/ttyS0",
49    .deviceType    = SERIAL_NS16550,
50    .pDeviceFns    = &ns16550_fns,
51    .deviceProbe   = altera_cyclone_v_uart_probe,
52    .pDeviceFlow   = NULL,
53    .ulMargin      = 16,
54    .ulHysteresis  = 8,
55    .pDeviceParams = (void *)CYCLONE_V_UART_BAUD,
56    .ulCtrlPort1   = (uint32_t)ALT_UART0_ADDR,
57    .ulCtrlPort2   = 0,
58    .ulDataPort    = (uint32_t)ALT_UART0_ADDR,
59    .getRegister   = altera_cyclone_v_uart_get_register,
60    .setRegister   = altera_cyclone_v_uart_set_register,
61    .getData       = NULL,
62    .setData       = NULL,
63    .ulClock       = 0,
64    .ulIntVector   = ALT_INT_INTERRUPT_UART0
65  },
66#endif
67#ifdef CYCLONE_V_CONFIG_UART_1
68  {
69    .sDeviceName   = "/dev/ttyS1",
70    .deviceType    = SERIAL_NS16550,
71    .pDeviceFns    = &ns16550_fns,
72    .deviceProbe   = altera_cyclone_v_uart_probe,
73    .pDeviceFlow   = NULL,
74    .ulMargin      = 16,
75    .ulHysteresis  = 8,
76    .pDeviceParams = (void *)CYCLONE_V_UART_BAUD,
77    .ulCtrlPort1   = (uint32_t)ALT_UART1_ADDR,
78    .ulCtrlPort2   = 0,
79    .ulDataPort    = (uint32_t)ALT_UART1_ADDR,
80    .getRegister   = altera_cyclone_v_uart_get_register,
81    .setRegister   = altera_cyclone_v_uart_set_register,
82    .getData       = NULL,
83    .setData       = NULL,
84    .ulClock       = 0,
85    .ulIntVector   = ALT_INT_INTERRUPT_UART1
86  }
87#endif
88};
89
90unsigned long Console_Configuration_Count =
91  RTEMS_ARRAY_SIZE(Console_Configuration_Ports);
92
93bool altera_cyclone_v_uart_probe(int minor)
94{
95  bool            ret           = true;
96  uint32_t        uart_set_mask;
97  uint32_t        ucr;
98  ALT_STATUS_CODE sc;
99  void*           location;
100
101  /* The ALT_CLK_L4_SP is required for all SoCFPGA UARTs.
102   * Check that it's enabled. */
103  assert( alt_clk_is_enabled(ALT_CLK_L4_SP) == ALT_E_TRUE );
104  if ( alt_clk_is_enabled(ALT_CLK_L4_SP) != ALT_E_TRUE ) {
105    ret = false;
106  }
107
108  if ( ret ) {
109    switch(minor)
110    {
111      case(0):
112        /* UART 0 */
113        uart_set_mask = ALT_RSTMGR_PERMODRST_UART0_SET_MSK;
114        location      = ALT_UART0_ADDR;
115      break;
116      case(1):
117        /* UART 1 */
118        uart_set_mask = ALT_RSTMGR_PERMODRST_UART1_SET_MSK;
119        location      = ALT_UART1_ADDR;
120      break;
121      default:
122        /* Unknown case */
123        assert( minor == 0 || minor == 1 );
124        ret = false;
125      break;
126    }
127  }
128  if ( ret ) {
129    sc = alt_clk_freq_get(ALT_CLK_L4_SP, &Console_Configuration_Ports[minor].ulClock);
130    assert( sc == ALT_E_SUCCESS );
131    if ( sc != ALT_E_SUCCESS ) {
132      ret = false;
133    }
134  }
135
136  if ( ret ) {
137    // Bring UART out of reset.
138    alt_clrbits_word(ALT_RSTMGR_PERMODRST_ADDR, uart_set_mask);
139
140    // Verify the UCR (UART Component Version)
141    ucr = alt_read_word( ALT_UART_UCV_ADDR( location ) );
142
143    assert( ucr == ALT_UART_UCV_UART_COMPONENT_VER_RESET );
144    if ( ucr != ALT_UART_UCV_UART_COMPONENT_VER_RESET ) {
145      ret = false;
146    }
147  }
148
149  if ( ret ) {
150    // Write SRR::UR (Shadow Reset Register :: UART Reset)
151    alt_write_word( ALT_UART_SRR_ADDR( location ), ALT_UART_SRR_UR_SET_MSK );
152
153    // Read the MSR to work around case:119085.
154    (void)alt_read_word( ALT_UART_MSR_ADDR( location ) );
155  }
156
157  return ret;
158}
159
160static void output_char(char c)
161{
162  int minor = (int) Console_Port_Minor;
163  console_tbl *ct = Console_Port_Tbl != NULL ?
164    Console_Port_Tbl[minor] : &Console_Configuration_Ports[minor];
165
166  if (c == '\n') {
167    ns16550_outch_polled( ct, '\r' );
168  }
169
170  ns16550_outch_polled( ct, c );
171}
172
173BSP_output_char_function_type BSP_output_char = output_char;
174
175BSP_polling_getchar_function_type BSP_poll_char = NULL;
Note: See TracBrowser for help on using the repository browser.