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> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 9 | #include <init.h> |
yannick fertre | 92eac58 | 2018-03-02 15:59:28 +0100 | [diff] [blame] | 10 | #include <lcd.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame^] | 11 | #include <log.h> |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 12 | #include <miiphy.h> |
| 13 | #include <phy_interface.h> |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 14 | #include <ram.h> |
Simon Glass | b03e051 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 15 | #include <serial.h> |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 16 | #include <spl.h> |
yannick fertre | 92eac58 | 2018-03-02 15:59:28 +0100 | [diff] [blame] | 17 | #include <splash.h> |
| 18 | #include <st_logo_data.h> |
| 19 | #include <video.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 20 | #include <asm/io.h> |
| 21 | #include <asm/armv7m.h> |
| 22 | #include <asm/arch/stm32.h> |
| 23 | #include <asm/arch/gpio.h> |
Michael Kurz | b20b70f | 2017-01-22 16:04:27 +0100 | [diff] [blame] | 24 | #include <asm/arch/syscfg.h> |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 29 | int dram_init(void) |
| 30 | { |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 31 | #ifndef CONFIG_SUPPORT_SPL |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 32 | int rv; |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 33 | struct udevice *dev; |
Vikas Manocha | 2d9c33c | 2017-04-10 15:02:54 -0700 | [diff] [blame] | 34 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 35 | if (rv) { |
| 36 | debug("DRAM init failed: %d\n", rv); |
| 37 | return rv; |
| 38 | } |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 39 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 40 | #endif |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 41 | return fdtdec_setup_mem_size_base(); |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | int dram_init_banksize(void) |
| 45 | { |
Patrice Chotard | 8ff21d6 | 2018-08-03 13:09:55 +0200 | [diff] [blame] | 46 | return fdtdec_setup_memory_banksize(); |
Toshifumi NISHINAGA | 25c1b13 | 2016-07-08 01:02:25 +0900 | [diff] [blame] | 47 | } |
| 48 | |
Vikas Manocha | 280057b | 2017-04-10 15:02:59 -0700 | [diff] [blame] | 49 | int board_early_init_f(void) |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 50 | { |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 51 | return 0; |
| 52 | } |
Michael Kurz | d4363ba | 2017-01-22 16:04:30 +0100 | [diff] [blame] | 53 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 54 | #ifdef CONFIG_SPL_BUILD |
Vikas Manocha | 55a3ef7 | 2017-05-28 12:55:13 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_SPL_OS_BOOT |
| 56 | int spl_start_uboot(void) |
| 57 | { |
| 58 | debug("SPL: booting kernel\n"); |
| 59 | /* break into full u-boot on 'c' */ |
| 60 | return serial_tstc() && serial_getc() == 'c'; |
| 61 | } |
| 62 | #endif |
| 63 | |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 64 | int spl_dram_init(void) |
| 65 | { |
| 66 | struct udevice *dev; |
| 67 | int rv; |
| 68 | rv = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 69 | if (rv) |
| 70 | debug("DRAM init failed: %d\n", rv); |
| 71 | return rv; |
| 72 | } |
| 73 | void spl_board_init(void) |
| 74 | { |
| 75 | spl_dram_init(); |
| 76 | preloader_console_init(); |
| 77 | arch_cpu_init(); /* to configure mpu for sdram rw permissions */ |
| 78 | } |
| 79 | u32 spl_boot_device(void) |
| 80 | { |
Vikas Manocha | 1a73bd8 | 2017-05-28 12:55:14 -0700 | [diff] [blame] | 81 | return BOOT_DEVICE_XIP; |
Vikas Manocha | b974769 | 2017-05-28 12:55:10 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | #endif |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 85 | u32 get_board_rev(void) |
| 86 | { |
| 87 | return 0; |
| 88 | } |
| 89 | |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 90 | int board_late_init(void) |
| 91 | { |
| 92 | struct gpio_desc gpio = {}; |
| 93 | int node; |
| 94 | |
| 95 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1"); |
| 96 | if (node < 0) |
| 97 | return -1; |
| 98 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 99 | 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] | 100 | GPIOD_IS_OUT); |
| 101 | |
| 102 | if (dm_gpio_is_valid(&gpio)) { |
| 103 | dm_gpio_set_value(&gpio, 0); |
| 104 | mdelay(10); |
| 105 | dm_gpio_set_value(&gpio, 1); |
| 106 | } |
| 107 | |
| 108 | /* read button 1*/ |
| 109 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1"); |
| 110 | if (node < 0) |
| 111 | return -1; |
| 112 | |
Simon Glass | 150c5af | 2017-05-30 21:47:09 -0600 | [diff] [blame] | 113 | gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0, |
| 114 | &gpio, GPIOD_IS_IN); |
Vikas Manocha | 2f80a9f | 2017-04-10 15:03:00 -0700 | [diff] [blame] | 115 | |
| 116 | if (dm_gpio_is_valid(&gpio)) { |
| 117 | if (dm_gpio_get_value(&gpio)) |
| 118 | puts("usr button is at HIGH LEVEL\n"); |
| 119 | else |
| 120 | puts("usr button is at LOW LEVEL\n"); |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 126 | int board_init(void) |
| 127 | { |
Vikas Manocha | 57af3cc | 2017-04-10 15:03:01 -0700 | [diff] [blame] | 128 | gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100; |
Patrice Chotard | 20fe38e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 129 | |
| 130 | #ifdef CONFIG_ETH_DESIGNWARE |
Patrice Chotard | 77594d7 | 2019-02-22 15:04:44 +0100 | [diff] [blame] | 131 | const char *phy_mode; |
| 132 | int node; |
| 133 | |
| 134 | node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac"); |
| 135 | if (node < 0) |
| 136 | return -1; |
| 137 | |
| 138 | phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); |
| 139 | |
| 140 | switch (phy_get_interface_by_name(phy_mode)) { |
| 141 | case PHY_INTERFACE_MODE_RMII: |
| 142 | STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL; |
| 143 | break; |
| 144 | case PHY_INTERFACE_MODE_MII: |
| 145 | STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL; |
| 146 | break; |
| 147 | default: |
| 148 | printf("PHY interface %s not supported !\n", phy_mode); |
| 149 | } |
Patrice Chotard | 20fe38e | 2018-01-18 14:10:05 +0100 | [diff] [blame] | 150 | #endif |
| 151 | |
yannick fertre | 92eac58 | 2018-03-02 15:59:28 +0100 | [diff] [blame] | 152 | #if defined(CONFIG_CMD_BMP) |
| 153 | bmp_display((ulong)stmicroelectronics_uboot_logo_8bit_rle, |
| 154 | BMP_ALIGN_CENTER, BMP_ALIGN_CENTER); |
| 155 | #endif /* CONFIG_CMD_BMP */ |
| 156 | |
Vikas Manocha | e66c49f | 2016-02-11 15:47:20 -0800 | [diff] [blame] | 157 | return 0; |
| 158 | } |