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