]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/raspberrypi/rpi_b/rpi_b.c
fdt: Allow ft_board_setup() to report failure
[people/ms/u-boot.git] / board / raspberrypi / rpi_b / rpi_b.c
CommitLineData
0d04f34a 1/*
ea697ae7 2 * (C) Copyright 2012-2013 Stephen Warren
0d04f34a
SW
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <common.h>
ea697ae7 18#include <config.h>
41e98e01 19#include <dm.h>
5dfd162e 20#include <fdt_support.h>
ea697ae7 21#include <lcd.h>
5dfd162e 22#include <mmc.h>
41e98e01 23#include <asm/gpio.h>
3f397782 24#include <asm/arch/mbox.h>
131a1e60 25#include <asm/arch/sdhci.h>
0d04f34a
SW
26#include <asm/global_data.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
41e98e01
SG
30static const struct bcm2835_gpio_platdata gpio_platdata = {
31 .base = BCM2835_GPIO_BASE,
32};
33
34U_BOOT_DEVICE(bcm2835_gpios) = {
35 .name = "gpio_bcm2835",
36 .platdata = &gpio_platdata,
37};
38
3f397782
SW
39struct msg_get_arm_mem {
40 struct bcm2835_mbox_hdr hdr;
41 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
42 u32 end_tag;
43};
44
4f80a06d
SW
45struct msg_get_mac_address {
46 struct bcm2835_mbox_hdr hdr;
47 struct bcm2835_mbox_tag_get_mac_address get_mac_address;
48 u32 end_tag;
49};
50
f66f2aa2
SW
51struct msg_set_power_state {
52 struct bcm2835_mbox_hdr hdr;
53 struct bcm2835_mbox_tag_set_power_state set_power_state;
54 u32 end_tag;
55};
56
131a1e60
SW
57struct msg_get_clock_rate {
58 struct bcm2835_mbox_hdr hdr;
59 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
60 u32 end_tag;
61};
62
0d04f34a
SW
63int dram_init(void)
64{
3f397782
SW
65 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
66 int ret;
67
68 BCM2835_MBOX_INIT_HDR(msg);
69 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
70
71 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
72 if (ret) {
73 printf("bcm2835: Could not query ARM memory size\n");
74 return -1;
75 }
76
77 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
0d04f34a
SW
78
79 return 0;
80}
81
4f80a06d
SW
82int misc_init_r(void)
83{
84 ALLOC_ALIGN_BUFFER(struct msg_get_mac_address, msg, 1, 16);
85 int ret;
86
87 if (getenv("usbethaddr"))
88 return 0;
89
90 BCM2835_MBOX_INIT_HDR(msg);
91 BCM2835_MBOX_INIT_TAG(&msg->get_mac_address, GET_MAC_ADDRESS);
92
93 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
94 if (ret) {
95 printf("bcm2835: Could not query MAC address\n");
96 /* Ignore error; not critical */
97 return 0;
98 }
99
100 eth_setenv_enetaddr("usbethaddr", msg->get_mac_address.body.resp.mac);
101
102 return 0;
103}
104
f66f2aa2
SW
105static int power_on_module(u32 module)
106{
107 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
108 int ret;
109
110 BCM2835_MBOX_INIT_HDR(msg_pwr);
111 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
112 SET_POWER_STATE);
113 msg_pwr->set_power_state.body.req.device_id = module;
114 msg_pwr->set_power_state.body.req.state =
115 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
116 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
117
118 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
119 &msg_pwr->hdr);
120 if (ret) {
121 printf("bcm2835: Could not set module %u power state\n",
122 module);
123 return -1;
124 }
125
126 return 0;
127}
128
0d04f34a
SW
129int board_init(void)
130{
131 gd->bd->bi_boot_params = 0x100;
132
f66f2aa2 133 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
0d04f34a 134}
131a1e60 135
5dfd162e 136int board_mmc_init(bd_t *bis)
131a1e60
SW
137{
138 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
139 int ret;
140
f66f2aa2
SW
141 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
142
131a1e60
SW
143 BCM2835_MBOX_INIT_HDR(msg_clk);
144 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
145 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
146
147 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
148 if (ret) {
149 printf("bcm2835: Could not query eMMC clock rate\n");
150 return -1;
151 }
152
153 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
154 msg_clk->get_clock_rate.body.resp.rate_hz);
155}
ea697ae7 156
e895a4b0 157int ft_board_setup(void *blob, bd_t *bd)
ea697ae7
SW
158{
159 /*
160 * For now, we simply always add the simplefb DT node. Later, we
161 * should be more intelligent, and e.g. only do this if no enabled DT
162 * node exists for the "real" graphics driver.
163 */
164 lcd_dt_simplefb_add_node(blob);
e895a4b0
SG
165
166 return 0;
ea697ae7 167}