summaryrefslogtreecommitdiffstats
path: root/bsps/arm/raspberrypi/start/bspstart.c
blob: 8d7f6aa503407af7c50fb0528c9ba5817fada9e9 (plain) (blame)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
 * @file
 *
 * @ingroup arm_start
 *
 * @brief Raspberry pi startup code.
 */

/*
 * Copyright (c) 2013 by Alan Cudmore
 *
 *  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/irq.h>
#include <bsp/linker-symbols.h>
#include <bsp/stackalloc.h>
#include <bsp/raspberrypi.h>
#include <bsp/vc.h>
#include <bsp/fdt.h>

#include <libfdt.h>

static const struct {
    uint32_t code;
    const char* label;
} rpi_codes[] =
{
    { 0x900021, "A+ 1.1 (512MB)" },
    { 0x900032, "B+ 1.2 (512MB)" },
    { 0x900092, "Zero 1.2 (512MB)" },
    { 0x900093, "Zero 1.3 (512MB)" },
    { 0x9000c1, "Zero W 1.1 (512MB)" },
    { 0x9020e0, "3A+ 1.0 (512MB)" },
    { 0x920092, "Zero 1.2 (512MB)" },
    { 0x920093, "Zero 1.3 (512MB)" },
    { 0x900061, "CM 1.1 (512MB)" },
    { 0xa01040, "2B 1.0 (1GB)" },
    { 0xa01041, "2B 1.1 (1GB)" },
    { 0xa02082, "3B 1.2 (1GB)" },
    { 0xa020a0, "CM3 1.0 (1GB)" },
    { 0xa020d3, "3B+ 1.3 (1GB)" },
    { 0xa21041, "2B 1.1 (1GB)" },
    { 0xa22042, "2B 1,2 (with BCM2837) (1GB)" },
    { 0xa22082, "3B 1.2 (1GB)" },
    { 0xa220a0, "CM3 1.0 (1GB)" },
    { 0xa32082, "3B 1.2 (1GB)" },
    { 0xa52082, "3B 1.2 (1GB)" },
    { 0xa22083, "3B 1.3 (1GB)" },
    { 0xa02100, "CM3+ 1.0 (1GB)" },
    { 0xa03111, "4B 1.1 (1GB)" },
    { 0xb03111, "4B 1.1 (2GB)" },
    { 0xc03111, "4B 1.1 (4GB)" },
};

static const char* rpi_types[] = {
    "A",
    "B",
    "A+",
    "B+",
    "2B",
    "Alpha (early prototype)",
    "CM1",
    "3B",
    "Zero",
    "CM3",
    "Zero W",
    "3B+",
    "3A+",
    "Internal use only",
    "CM3+",
    "4B",
};

static const char* rpi_mem[] =
{
    "256MB",
    "512MB",
    "1GB",
    "2GB",
    "4GB"
};

#define NUMOF(_s) (sizeof(_s) / sizeof(_s[0]))

void *raspberrypi_get_reg_of_node(const void *fdt, int node)
{
  int len;
  const uint32_t *val;

  val = fdt_getprop(fdt, node, "reg", &len);
  if (val == NULL || len < 4) {
    return NULL;
  }

  return (BUS_TO_PHY((void *) fdt32_to_cpu(val[0])));
}

#ifdef BSP_FDT_IS_SUPPORTED
uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
{
  uint32_t controller = intr[0];
  uint32_t source = intr[1];

  switch ( controller ) {
    case 0:
        return source + BCM2835_IRQ_ID_BASIC_BASE_ID;
        break;
    case 1:
        return source + BCM2835_IRQ_SET1_MIN;
        break;
    case 2:
        return source + BCM2835_IRQ_SET2_MIN;
        break;
    default:
        return BSP_INTERRUPT_VECTOR_INVALID;
        break;
  }
}
#endif /* BSP_FDT_IS_SUPPORTED */

void bsp_start(void)
{
    bcm2835_get_board_spec_entries spec = { 0 };

    printk("\nRTEMS RPi ");
    if (bcm2835_mailbox_get_board_revision( &spec ) >= 0) {
	size_t i;
	for (i = 0; i < NUMOF(rpi_codes); ++i) {
	    if (rpi_codes[i].code == spec.spec) {
		printk("%s [%08x]", rpi_codes[i].label, spec.spec);
		break;
	    }
	}
	if (i >= NUMOF(rpi_codes)) {
	    uint32_t type = (spec.spec >> 4) & 0xff;
	    uint32_t mem = (spec.spec >> (4 + 4 + 8 + 4)) & 0xf;
	    printk(" unknown code [%08x] ", spec.spec);
	    if (type < NUMOF(rpi_types))
		printk(rpi_types[type]);
	    else
		printk("type: %02x", type);
	    if (mem < NUMOF(rpi_mem))
		printk(" %s", rpi_mem[mem]);
	    else
		printk(" mem: %x", mem);
	}
	printk("\n");
    }
    else {
	printk(": ERROR reading mailbox\n");
    }

    bsp_interrupt_initialize();
}