source: rtems/bsps/arm/beagle/start/bspstart.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * Copyright (c) 2013 embedded brains GmbH & Co. KG
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <bsp.h>
29#include <bsp/bootcard.h>
30#include <bsp/irq-generic.h>
31#include <bsp/fdt.h>
32#include <bsp/linker-symbols.h>
33#include <bsp/i2c.h>
34#include <rtems/sysinit.h>
35#include "bsp-soc-detect.h"
36#include <arm/ti/ti_pinmux.h>
37#include <ofw/ofw.h>
38#include <bsp/i2c.h>
39#include <string.h>
40#include <stdlib.h>
41#include <ctype.h>
42
43#include "bspdebug.h"
44
45void bsp_start(void)
46{
47  const char *type;
48
49  bsp_soc_detect();
50
51  switch (ti_chip()) {
52    case CHIP_AM335X:
53      type = "am335x-based";
54      break;
55    case CHIP_OMAP_3:
56      type = "dm3730-based";
57      break;
58    default:
59      type = "Unknown SOC";
60      break;
61  }
62
63  bsp_interrupt_initialize();
64  printk("\nRTEMS Beagleboard: %s\n", type);
65  printk("        ARM Debug: 0x%08x\n", (intptr_t) bbb_arm_debug_registers());
66  rtems_cache_coherent_add_area(
67      bsp_section_nocacheheap_begin,
68      (uintptr_t) bsp_section_nocacheheap_size
69  );
70}
71
72uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
73{
74  return intr[0];
75}
76
77static void traverse_fdt_nodes( phandle_t node )
78{
79
80  for (node = rtems_ofw_child(node); node != 0; node = rtems_ofw_peer(node)) {
81    traverse_fdt_nodes(node);
82
83    if (!rtems_ofw_node_status(node))
84      continue;
85
86    /*
87     * Put all driver initialization functions here
88     */
89    beagle_pinmux_init(node);
90    beagle_i2c_init(node);
91  }
92}
93
94static void bbb_drivers_initialize(void)
95{
96  phandle_t node = rtems_ofw_peer(0);
97
98  traverse_fdt_nodes(node);
99}
100
101int beagle_get_node_unit(phandle_t node)
102{
103  char name[30];
104  char prop[30];
105  char prop_val[30];
106  static int unit;
107  phandle_t aliases;
108  int rv;
109  int i;
110
111  rv = rtems_ofw_get_prop(node, "name", name, sizeof(name));
112  if (rv <= 0)
113    return unit++;
114
115  aliases = rtems_ofw_find_device("/aliases");
116
117  rv = rtems_ofw_next_prop(aliases, NULL, &prop[0], sizeof(prop));
118
119  while (rv > 0) {
120    rv = rtems_ofw_get_prop(aliases, prop, prop_val, sizeof(prop_val));
121
122    if (strstr(prop_val, name) != NULL) {
123      for (i = strlen(prop) - 1; i >= 0; i--) {
124        if (!isdigit((int)prop[i]))
125          break;
126      }
127
128      return strtol(&prop[i + 1], NULL, 10);
129    }
130    rv = rtems_ofw_next_prop(aliases, prop, prop, sizeof(prop));
131  }
132
133  return unit++;
134}
135
136RTEMS_SYSINIT_ITEM(
137        bbb_drivers_initialize,
138        RTEMS_SYSINIT_BSP_PRE_DRIVERS,
139        RTEMS_SYSINIT_ORDER_LAST
140);
Note: See TracBrowser for help on using the repository browser.