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