1 | /* |
---|
2 | * Copyright (c) 2013 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * The license and distribution terms for this file may be |
---|
5 | * found in the file LICENSE in this distribution or at |
---|
6 | * http://www.rtems.org/license/LICENSE. |
---|
7 | */ |
---|
8 | |
---|
9 | #include <bsp.h> |
---|
10 | #include <bsp/bootcard.h> |
---|
11 | #include <bsp/irq-generic.h> |
---|
12 | #include <bsp/fdt.h> |
---|
13 | #include <bsp/linker-symbols.h> |
---|
14 | #include <bsp/i2c.h> |
---|
15 | #include <rtems/sysinit.h> |
---|
16 | #include "bsp-soc-detect.h" |
---|
17 | #include <arm/ti/ti_pinmux.h> |
---|
18 | #include <ofw/ofw.h> |
---|
19 | #include <bsp/i2c.h> |
---|
20 | #include <string.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include <ctype.h> |
---|
23 | |
---|
24 | #include "bspdebug.h" |
---|
25 | |
---|
26 | void bsp_start(void) |
---|
27 | { |
---|
28 | const char *type; |
---|
29 | |
---|
30 | bsp_soc_detect(); |
---|
31 | |
---|
32 | switch (ti_chip()) { |
---|
33 | case CHIP_AM335X: |
---|
34 | type = "am335x-based"; |
---|
35 | break; |
---|
36 | case CHIP_OMAP_3: |
---|
37 | type = "dm3730-based"; |
---|
38 | break; |
---|
39 | default: |
---|
40 | type = "Unknown SOC"; |
---|
41 | break; |
---|
42 | } |
---|
43 | |
---|
44 | bsp_interrupt_initialize(); |
---|
45 | printk("\nRTEMS Beagleboard: %s\n", type); |
---|
46 | printk(" ARM Debug: 0x%08x\n", (intptr_t) bbb_arm_debug_registers()); |
---|
47 | rtems_cache_coherent_add_area( |
---|
48 | bsp_section_nocacheheap_begin, |
---|
49 | (uintptr_t) bsp_section_nocacheheap_size |
---|
50 | ); |
---|
51 | } |
---|
52 | |
---|
53 | uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells) |
---|
54 | { |
---|
55 | return intr[0]; |
---|
56 | } |
---|
57 | |
---|
58 | static void traverse_fdt_nodes( phandle_t node ) |
---|
59 | { |
---|
60 | |
---|
61 | for (node = rtems_ofw_child(node); node != 0; node = rtems_ofw_peer(node)) { |
---|
62 | traverse_fdt_nodes(node); |
---|
63 | |
---|
64 | if (!rtems_ofw_node_status(node)) |
---|
65 | continue; |
---|
66 | |
---|
67 | /* |
---|
68 | * Put all driver initialization functions here |
---|
69 | */ |
---|
70 | beagle_pinmux_init(node); |
---|
71 | beagle_i2c_init(node); |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | static void bbb_drivers_initialize(void) |
---|
76 | { |
---|
77 | phandle_t node = rtems_ofw_peer(0); |
---|
78 | |
---|
79 | traverse_fdt_nodes(node); |
---|
80 | } |
---|
81 | |
---|
82 | int beagle_get_node_unit(phandle_t node) |
---|
83 | { |
---|
84 | char name[30]; |
---|
85 | char prop[30]; |
---|
86 | char prop_val[30]; |
---|
87 | static int unit; |
---|
88 | phandle_t aliases; |
---|
89 | int rv; |
---|
90 | int i; |
---|
91 | |
---|
92 | rv = rtems_ofw_get_prop(node, "name", name, sizeof(name)); |
---|
93 | if (rv <= 0) |
---|
94 | return unit++; |
---|
95 | |
---|
96 | aliases = rtems_ofw_find_device("/aliases"); |
---|
97 | |
---|
98 | rv = rtems_ofw_next_prop(aliases, NULL, &prop[0], sizeof(prop)); |
---|
99 | |
---|
100 | while (rv > 0) { |
---|
101 | rv = rtems_ofw_get_prop(aliases, prop, prop_val, sizeof(prop_val)); |
---|
102 | |
---|
103 | if (strstr(prop_val, name) != NULL) { |
---|
104 | for (i = strlen(prop) - 1; i >= 0; i--) { |
---|
105 | if (!isdigit(prop[i])) |
---|
106 | break; |
---|
107 | } |
---|
108 | |
---|
109 | return strtol(&prop[i + 1], NULL, 10); |
---|
110 | } |
---|
111 | rv = rtems_ofw_next_prop(aliases, prop, prop, sizeof(prop)); |
---|
112 | } |
---|
113 | |
---|
114 | return unit++; |
---|
115 | } |
---|
116 | |
---|
117 | RTEMS_SYSINIT_ITEM( |
---|
118 | bbb_drivers_initialize, |
---|
119 | RTEMS_SYSINIT_BSP_PRE_DRIVERS, |
---|
120 | RTEMS_SYSINIT_ORDER_LAST |
---|
121 | ); |
---|