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