forked from RTEMS/rtems
/
bspstart.c
135 lines (112 loc) · 2.79 KB
/
bspstart.c
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
/*
* Copyright (c) 2013 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <info@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 <bsp.h>
#include <bsp/bootcard.h>
#include <bsp/irq-generic.h>
#include <bsp/fdt.h>
#include <bsp/linker-symbols.h>
#include <bsp/i2c.h>
#include <rtems/sysinit.h>
#include "bsp-soc-detect.h"
#include <arm/ti/ti_cpuid.h>
#include <arm/ti/ti_pinmux.h>
#include <arm/ti/ti_prcm.h>
#include <arm/ti/ti_scm.h>
#include <rtems.h>
#include <ofw/ofw.h>
#include <bsp/i2c.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "bspdebug.h"
#define MIN(l,r) ((l) < (r) ? (l) : (r))
void bsp_start(void)
{
const char *type;
bsp_soc_detect();
switch (ti_chip()) {
case CHIP_AM335X:
type = "am335x-based";
break;
case CHIP_OMAP_3:
type = "dm3730-based";
break;
default:
type = "Unknown SOC";
break;
}
bsp_interrupt_initialize();
printk("\nRTEMS Beagleboard: %s\n", type);
printk(" ARM Debug: 0x%08x\n", (intptr_t) bbb_arm_debug_registers());
rtems_cache_coherent_add_area(
bsp_section_nocacheheap_begin,
(uintptr_t) bsp_section_nocacheheap_size
);
}
uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
{
return intr[0];
}
static void traverse_fdt_nodes( phandle_t node )
{
for (node = rtems_ofw_child(node); node != 0; node = rtems_ofw_peer(node)) {
traverse_fdt_nodes(node);
if (!rtems_ofw_node_status_okay(node))
continue;
/*
* Put all driver initialization functions here
*/
beagle_pinmux_init(node);
am335x_prcm_init(node);
beagle_scm_init(node);
beagle_i2c_init(node);
}
}
static void bbb_drivers_initialize(void)
{
phandle_t node = rtems_ofw_peer(0);
traverse_fdt_nodes(node);
}
int beagle_get_node_unit(phandle_t node)
{
char name[30];
char prop[30];
char prop_val[30];
static int unit;
phandle_t aliases;
int rv;
int i;
rv = rtems_ofw_get_prop(node, "name", name, sizeof(name));
if (rv <= 0)
return unit++;
aliases = rtems_ofw_find_device("/aliases");
rv = rtems_ofw_next_prop(aliases, NULL, &prop[0], sizeof(prop));
while (rv > 0) {
rv = rtems_ofw_get_prop(aliases, prop, prop_val, sizeof(prop_val));
if (strstr(prop_val, name) != NULL) {
for (i = strlen(prop) - 1; i >= 0; i--) {
if (!isdigit(prop[i]))
break;
}
return strtol(&prop[i + 1], NULL, 10);
}
rv = rtems_ofw_next_prop(aliases, prop, prop, sizeof(prop));
}
return unit++;
}
RTEMS_SYSINIT_ITEM(
bbb_drivers_initialize,
RTEMS_SYSINIT_BSP_PRE_DRIVERS,
RTEMS_SYSINIT_ORDER_LAST
);