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