Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 1 | /* |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 2 | * (C) Copyright 2012-2013 Stephen Warren |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 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> |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 18 | #include <config.h> |
| 19 | #include <lcd.h> |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 20 | #include <asm/arch/mbox.h> |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 21 | #include <asm/arch/sdhci.h> |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 22 | #include <asm/global_data.h> |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 26 | struct msg_get_arm_mem { |
| 27 | struct bcm2835_mbox_hdr hdr; |
| 28 | struct bcm2835_mbox_tag_get_arm_mem get_arm_mem; |
| 29 | u32 end_tag; |
| 30 | }; |
| 31 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 32 | struct msg_set_power_state { |
| 33 | struct bcm2835_mbox_hdr hdr; |
| 34 | struct bcm2835_mbox_tag_set_power_state set_power_state; |
| 35 | u32 end_tag; |
| 36 | }; |
| 37 | |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 38 | struct msg_get_clock_rate { |
| 39 | struct bcm2835_mbox_hdr hdr; |
| 40 | struct bcm2835_mbox_tag_get_clock_rate get_clock_rate; |
| 41 | u32 end_tag; |
| 42 | }; |
| 43 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 44 | int dram_init(void) |
| 45 | { |
Stephen Warren | 3f39778 | 2013-01-29 16:37:37 +0000 | [diff] [blame] | 46 | ALLOC_ALIGN_BUFFER(struct msg_get_arm_mem, msg, 1, 16); |
| 47 | int ret; |
| 48 | |
| 49 | BCM2835_MBOX_INIT_HDR(msg); |
| 50 | BCM2835_MBOX_INIT_TAG(&msg->get_arm_mem, GET_ARM_MEMORY); |
| 51 | |
| 52 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg->hdr); |
| 53 | if (ret) { |
| 54 | printf("bcm2835: Could not query ARM memory size\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | gd->ram_size = msg->get_arm_mem.body.resp.mem_size; |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 63 | static int power_on_module(u32 module) |
| 64 | { |
| 65 | ALLOC_ALIGN_BUFFER(struct msg_set_power_state, msg_pwr, 1, 16); |
| 66 | int ret; |
| 67 | |
| 68 | BCM2835_MBOX_INIT_HDR(msg_pwr); |
| 69 | BCM2835_MBOX_INIT_TAG(&msg_pwr->set_power_state, |
| 70 | SET_POWER_STATE); |
| 71 | msg_pwr->set_power_state.body.req.device_id = module; |
| 72 | msg_pwr->set_power_state.body.req.state = |
| 73 | BCM2835_MBOX_SET_POWER_STATE_REQ_ON | |
| 74 | BCM2835_MBOX_SET_POWER_STATE_REQ_WAIT; |
| 75 | |
| 76 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, |
| 77 | &msg_pwr->hdr); |
| 78 | if (ret) { |
| 79 | printf("bcm2835: Could not set module %u power state\n", |
| 80 | module); |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 87 | int board_init(void) |
| 88 | { |
| 89 | gd->bd->bi_boot_params = 0x100; |
| 90 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 91 | return power_on_module(BCM2835_MBOX_POWER_DEVID_USB_HCD); |
Stephen Warren | 0d04f34 | 2012-08-05 16:07:22 +0000 | [diff] [blame] | 92 | } |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 93 | |
| 94 | int board_mmc_init(void) |
| 95 | { |
| 96 | ALLOC_ALIGN_BUFFER(struct msg_get_clock_rate, msg_clk, 1, 16); |
| 97 | int ret; |
| 98 | |
Stephen Warren | f66f2aa | 2014-01-13 19:50:11 -0700 | [diff] [blame] | 99 | power_on_module(BCM2835_MBOX_POWER_DEVID_SDHCI); |
| 100 | |
Stephen Warren | 131a1e6 | 2013-01-29 16:37:42 +0000 | [diff] [blame] | 101 | BCM2835_MBOX_INIT_HDR(msg_clk); |
| 102 | BCM2835_MBOX_INIT_TAG(&msg_clk->get_clock_rate, GET_CLOCK_RATE); |
| 103 | msg_clk->get_clock_rate.body.req.clock_id = BCM2835_MBOX_CLOCK_ID_EMMC; |
| 104 | |
| 105 | ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_clk->hdr); |
| 106 | if (ret) { |
| 107 | printf("bcm2835: Could not query eMMC clock rate\n"); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | return bcm2835_sdhci_init(BCM2835_SDHCI_BASE, |
| 112 | msg_clk->get_clock_rate.body.resp.rate_hz); |
| 113 | } |
Stephen Warren | ea697ae | 2013-05-27 18:31:18 +0000 | [diff] [blame] | 114 | |
| 115 | void ft_board_setup(void *blob, bd_t *bd) |
| 116 | { |
| 117 | /* |
| 118 | * For now, we simply always add the simplefb DT node. Later, we |
| 119 | * should be more intelligent, and e.g. only do this if no enabled DT |
| 120 | * node exists for the "real" graphics driver. |
| 121 | */ |
| 122 | lcd_dt_simplefb_add_node(blob); |
| 123 | } |