blob: 220bb90dc1ae025ddf37e8fe9636201843c00650 [file] [log] [blame]
Stephen Warren0d04f342012-08-05 16:07:22 +00001/*
Stephen Warrenea697ae2013-05-27 18:31:18 +00002 * (C) Copyright 2012-2013 Stephen Warren
Stephen Warren0d04f342012-08-05 16:07:22 +00003 *
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>
Stephen Warrenea697ae2013-05-27 18:31:18 +000018#include <config.h>
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +020019#include <fdt_support.h>
Stephen Warrenea697ae2013-05-27 18:31:18 +000020#include <lcd.h>
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +020021#include <mmc.h>
Stephen Warren3f397782013-01-29 16:37:37 +000022#include <asm/arch/mbox.h>
Stephen Warren131a1e62013-01-29 16:37:42 +000023#include <asm/arch/sdhci.h>
Stephen Warren0d04f342012-08-05 16:07:22 +000024#include <asm/global_data.h>
25
26DECLARE_GLOBAL_DATA_PTR;
27
Stephen Warren3f397782013-01-29 16:37:37 +000028struct msg_get_arm_mem {
29 struct bcm2835_mbox_hdr hdr;
30 struct bcm2835_mbox_tag_get_arm_mem get_arm_mem;
31 u32 end_tag;
32};
33
Stephen Warrenf66f2aa2014-01-13 19:50:11 -070034struct msg_set_power_state {
35 struct bcm2835_mbox_hdr hdr;
36 struct bcm2835_mbox_tag_set_power_state set_power_state;
37 u32 end_tag;
38};
39
Stephen Warren131a1e62013-01-29 16:37:42 +000040struct msg_get_clock_rate {
41 struct bcm2835_mbox_hdr hdr;
42 struct bcm2835_mbox_tag_get_clock_rate get_clock_rate;
43 u32 end_tag;
44};
45
Stephen Warren0d04f342012-08-05 16:07:22 +000046int dram_init(void)
47{
Stephen Warren3f397782013-01-29 16:37:37 +000048 ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16);
49 int ret;
50
51 BCM2835_MBOX_INIT_HDR(msg);
52 BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY);
53
54 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr);
55 if (ret) {
56 printf("bcm2835: Could not query ARM memory size\n");
57 return -1;
58 }
59
60 gd->ram_size = msg->get_arm_mem.body.resp.mem_size;
Stephen Warren0d04f342012-08-05 16:07:22 +000061
62 return 0;
63}
64
Stephen Warrenf66f2aa2014-01-13 19:50:11 -070065static int power_on_module(u32 module)
66{
67 ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16);
68 int ret;
69
70 BCM2835_MBOX_INIT_HDR(msg_pwr);
71 BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state,
72 SET_POWER_STATE);
73 msg_pwr->set_power_state.body.req.device_id = module;
74 msg_pwr->set_power_state.body.req.state =
75 BCM2835_MBOX_SET_POWER_STATE_REQ_ON |
76 BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT;
77
78 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN,
79 &msg_pwr->hdr);
80 if (ret) {
81 printf("bcm2835: Could not set module %u power state\n",
82 module);
83 return -1;
84 }
85
86 return 0;
87}
88
Stephen Warren0d04f342012-08-05 16:07:22 +000089int board_init(void)
90{
91 gd->bd->bi_boot_params = 0x100;
92
Stephen Warrenf66f2aa2014-01-13 19:50:11 -070093 return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD);
Stephen Warren0d04f342012-08-05 16:07:22 +000094}
Stephen Warren131a1e62013-01-29 16:37:42 +000095
Jeroen Hofstee5dfd1622014-07-13 22:01:51 +020096int board_mmc_init(bd_t *bis)
Stephen Warren131a1e62013-01-29 16:37:42 +000097{
98 ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16);
99 int ret;
100
Stephen Warrenf66f2aa2014-01-13 19:50:11 -0700101 power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI);
102
Stephen Warren131a1e62013-01-29 16:37:42 +0000103 BCM2835_MBOX_INIT_HDR(msg_clk);
104 BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE);
105 msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC;
106
107 ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr);
108 if (ret) {
109 printf("bcm2835: Could not query eMMC clock rate\n");
110 return -1;
111 }
112
113 return bcm2835_sdhci_init(BCM2835_SDHCI_BASE,
114 msg_clk->get_clock_rate.body.resp.rate_hz);
115}
Stephen Warrenea697ae2013-05-27 18:31:18 +0000116
117void ft_board_setup(void *blob, bd_t *bd)
118{
119 /*
120 * For now, we simply always add the simplefb DT node. Later, we
121 * should be more intelligent, and e.g. only do this if no enabled DT
122 * node exists for the "real" graphics driver.
123 */
124 lcd_dt_simplefb_add_node(blob);
125}