Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2016 |
| 3 | * Vikas Manocha, <vikas.manocha@st.com> |
| 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <ram.h> |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 11 | #include <spl.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/armv7m.h> |
| 14 | #include <asm/arch/stm32.h> |
| 15 | #include <asm/arch/gpio.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 16 | #include <asm/arch/fmc.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 17 | #include <dm/platform_data/serial_stm32x7.h> |
| 18 | #include <asm/arch/stm32_periph.h> |
| 19 | #include <asm/arch/stm32_defs.h> |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 20 | #include <asm/arch/syscfg.h> |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 21 | #include <asm/gpio.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 25 | int get_memory_base_size(fdt_addr_t *mr_base, fdt_addr_t *mr_size) |
| 26 | { |
| 27 | int mr_node; |
| 28 | |
| 29 | mr_node = fdt_path_offset(gd->fdt_blob, "/memory"); |
| 30 | if (mr_node < 0) |
| 31 | return mr_node; |
| 32 | *mr_base = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, mr_node, |
| 33 | "reg", 0, mr_size, false); |
| 34 | debug("mr_base = %lx, mr_size= %lx\n", *mr_base, *mr_size); |
| 35 | |
| 36 | return 0; |
| 37 | } |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 38 | int dram_init(void) |
| 39 | { |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 40 | int rv; |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 41 | fdt_addr_t mr_base, mr_size; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 42 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 43 | #ifndef CONFIG_SUPPORT_SPL |
| 44 | struct udevice *dev; |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 45 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 46 | if (rv) { |
| 47 | debug("DRAM init failed: %d\n", rv); |
| 48 | return rv; |
| 49 | } |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 50 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 51 | #endif |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 52 | rv = get_memory_base_size(&mr_base, &mr_size); |
| 53 | if (rv) |
| 54 | return rv; |
| 55 | gd->ram_size = mr_size; |
| 56 | gd->ram_top = mr_base; |
| 57 | |
| 58 | return rv; |
| 59 | } |
| 60 | |
| 61 | int dram_init_banksize(void) |
| 62 | { |
| 63 | fdt_addr_t mr_base, mr_size; |
| 64 | get_memory_base_size(&mr_base, &mr_size); |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 65 | /* |
| 66 | * Fill in global info with description of SRAM configuration |
| 67 | */ |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 68 | gd->bd->bi_dram[0].start = mr_base; |
| 69 | gd->bd->bi_dram[0].size = mr_size; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 70 | |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 71 | return 0; |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 72 | } |
| 73 | |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_ETH_DESIGNWARE |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 75 | static int stmmac_setup(void) |
| 76 | { |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 77 | clock_setup(SYSCFG_CLOCK_CFG); |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 78 | /* Set >RMII mode */ |
| 79 | STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL; |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 80 | clock_setup(STMMAC_CLOCK_CFG); |
| 81 | |
| 82 | return 0; |
| 83 | } |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 84 | |
Vikas Manocha | 280057b | 2017-04-10 15:02:59 -0700 | [diff] [blame] | 85 | int board_early_init_f(void) |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 86 | { |
Vikas Manocha | 280057b | 2017-04-10 15:02:59 -0700 | [diff] [blame] | 87 | stmmac_setup(); |
| 88 | |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | #endif |
| 92 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 93 | #ifdef CONFIG_SPL_BUILD |
Vikas Manocha | 55a3ef7 | 2017-05-28 12:55:13 -0700 | [diff] [blame^] | 94 | #ifdef CONFIG_SPL_OS_BOOT |
| 95 | int spl_start_uboot(void) |
| 96 | { |
| 97 | debug("SPL: booting kernel\n"); |
| 98 | /* break into full u-boot on 'c' */ |
| 99 | return serial_tstc() && serial_getc() == 'c'; |
| 100 | } |
| 101 | #endif |
| 102 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 103 | int spl_dram_init(void) |
| 104 | { |
| 105 | struct udevice *dev; |
| 106 | int rv; |
| 107 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 108 | if (rv) |
| 109 | debug("DRAM init failed: %d\n", rv); |
| 110 | return rv; |
| 111 | } |
| 112 | void spl_board_init(void) |
| 113 | { |
| 114 | spl_dram_init(); |
| 115 | preloader_console_init(); |
| 116 | arch_cpu_init(); /* to configure mpu for sdram rw permissions */ |
| 117 | } |
| 118 | u32 spl_boot_device(void) |
| 119 | { |
| 120 | return BOOT_DEVICE_NOR; |
| 121 | } |
| 122 | |
| 123 | #endif |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 124 | u32 get_board_rev(void) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 129 | int board_late_init(void) |
| 130 | { |
| 131 | struct gpio_desc gpio = {}; |
| 132 | int node; |
| 133 | |
| 134 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); |
| 135 | if (node < 0) |
| 136 | return -1; |
| 137 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 138 | gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio, |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 139 | GPIOD_IS_OUT); |
| 140 | |
| 141 | if (dm_gpio_is_valid(&gpio)) { |
| 142 | dm_gpio_set_value(&gpio, 0); |
| 143 | mdelay(10); |
| 144 | dm_gpio_set_value(&gpio, 1); |
| 145 | } |
| 146 | |
| 147 | /* read button 1*/ |
| 148 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); |
| 149 | if (node < 0) |
| 150 | return -1; |
| 151 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 152 | gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0, |
| 153 | &gpio, GPIOD_IS_IN); |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 154 | |
| 155 | if (dm_gpio_is_valid(&gpio)) { |
| 156 | if (dm_gpio_get_value(&gpio)) |
| 157 | puts("usr button is at HIGH LEVEL\n"); |
| 158 | else |
| 159 | puts("usr button is at LOW LEVEL\n"); |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 165 | int board_init(void) |
| 166 | { |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 167 | gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100; |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 168 | return 0; |
| 169 | } |