source: rtems/bsps/arm/raspberrypi/console/console_select.c @ d7d66d7

Last change on this file since d7d66d7 was d7d66d7, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 19, 2018 at 4:28:01 AM

bsps: Move console drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup raspberrypi_console
5 *
6 * @brief console select
7 */
8
9/*
10 * Copyright (c) 2015 Yang Qiao
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *
15 *  http://www.rtems.org/license/LICENSE
16 *
17 */
18
19#include <bsp.h>
20#include <bsp/fatal.h>
21#include <rtems/libio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <assert.h>
25#include <termios.h>
26
27#include <rtems/termiostypes.h>
28#include <libchip/serial.h>
29#include "../../shared/dev/serial/legacy-console.h"
30#include <bsp/rpi-fb.h>
31
32rtems_device_minor_number BSPPrintkPort = 0;
33
34/*
35 * Method to return true if the device associated with the
36 * minor number probs available.
37 */
38static bool bsp_Is_Available( rtems_device_minor_number minor )
39{
40  console_tbl *cptr = Console_Port_Tbl[ minor ];
41
42  /*
43   * First perform the configuration dependent probe, then the
44   * device dependent probe
45   */
46  if ( ( !cptr->deviceProbe || cptr->deviceProbe( minor ) ) &&
47       cptr->pDeviceFns->deviceProbe( minor ) ) {
48    return true;
49  }
50
51  return false;
52}
53
54/*
55 * Method to return the first available device.
56 */
57static rtems_device_minor_number bsp_First_Available_Device( void )
58{
59  rtems_device_minor_number minor;
60
61  for ( minor = 0; minor < Console_Port_Count; minor++ ) {
62    console_tbl *cptr = Console_Port_Tbl[ minor ];
63
64    /*
65     * First perform the configuration dependent probe, then the
66     * device dependent probe
67     */
68
69    if ( ( !cptr->deviceProbe || cptr->deviceProbe( minor ) ) &&
70         cptr->pDeviceFns->deviceProbe( minor ) ) {
71      return minor;
72    }
73  }
74
75  /*
76   *  Error No devices were found.  We will want to bail here.
77   */
78  bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV );
79}
80
81void bsp_console_select( void )
82{
83  /*
84   *  Reset Console_Port_Minor and
85   *  BSPPrintkPort here if desired.
86   *
87   *  This default version allows the bsp to set these
88   *  values at creation and will not touch them again
89   *  unless the selected port number is not available.
90   */
91  const char *opt;
92
93  Console_Port_Minor = BSP_CONSOLE_UART0;
94  BSPPrintkPort = BSP_CONSOLE_UART0;
95
96  opt = rpi_cmdline_get_arg( "--console=" );
97
98  if ( opt ) {
99    if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 ) == 0 ) {
100      if ( rpi_video_is_initialized() > 0 ) {
101        Console_Port_Minor = BSP_CONSOLE_FB;
102        BSPPrintkPort = BSP_CONSOLE_FB;
103      }
104    }
105  }
106
107  /*
108   * If the device that was selected isn't available then
109   * let the user know and select the first available device.
110   */
111  if ( !bsp_Is_Available( Console_Port_Minor ) ) {
112    Console_Port_Minor = bsp_First_Available_Device();
113  }
114}
Note: See TracBrowser for help on using the repository browser.