1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
5 */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <init.h>
10 #include <lcd.h>
11 #include <log.h>
12 #include <miiphy.h>
13 #include <phy_interface.h>
14 #include <ram.h>
15 #include <serial.h>
16 #include <spl.h>
17 #include <splash.h>
18 #include <st_logo_data.h>
19 #include <video.h>
20 #include <asm/global_data.h>
21 #include <asm/io.h>
22 #include <asm/armv7m.h>
23 #include <asm/arch/stm32.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/arch/syscfg.h>
26 #include <asm/gpio.h>
27 #include <linux/delay.h>
28
29 DECLARE_GLOBAL_DATA_PTR;
30
dram_init(void)31 int dram_init(void)
32 {
33 #ifndef CONFIG_SUPPORT_SPL
34 int rv;
35 struct udevice *dev;
36 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
37 if (rv) {
38 debug("DRAM init failed: %d\n", rv);
39 return rv;
40 }
41
42 #endif
43 return fdtdec_setup_mem_size_base();
44 }
45
dram_init_banksize(void)46 int dram_init_banksize(void)
47 {
48 return fdtdec_setup_memory_banksize();
49 }
50
51 #ifdef CONFIG_SPL_BUILD
52 #ifdef CONFIG_SPL_OS_BOOT
spl_start_uboot(void)53 int spl_start_uboot(void)
54 {
55 debug("SPL: booting kernel\n");
56 /* break into full u-boot on 'c' */
57 return serial_tstc() && serial_getc() == 'c';
58 }
59 #endif
60
spl_dram_init(void)61 int spl_dram_init(void)
62 {
63 struct udevice *dev;
64 int rv;
65 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
66 if (rv)
67 debug("DRAM init failed: %d\n", rv);
68 return rv;
69 }
spl_board_init(void)70 void spl_board_init(void)
71 {
72 spl_dram_init();
73 preloader_console_init();
74 arch_cpu_init(); /* to configure mpu for sdram rw permissions */
75 }
spl_boot_device(void)76 u32 spl_boot_device(void)
77 {
78 return BOOT_DEVICE_XIP;
79 }
80
81 #endif
get_board_rev(void)82 u32 get_board_rev(void)
83 {
84 return 0;
85 }
86
board_late_init(void)87 int board_late_init(void)
88 {
89 struct gpio_desc gpio = {};
90 int node;
91
92 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
93 if (node < 0)
94 return -1;
95
96 gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
97 GPIOD_IS_OUT);
98
99 if (dm_gpio_is_valid(&gpio)) {
100 dm_gpio_set_value(&gpio, 0);
101 mdelay(10);
102 dm_gpio_set_value(&gpio, 1);
103 }
104
105 /* read button 1*/
106 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
107 if (node < 0)
108 return -1;
109
110 gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
111 &gpio, GPIOD_IS_IN);
112
113 if (dm_gpio_is_valid(&gpio)) {
114 if (dm_gpio_get_value(&gpio))
115 puts("usr button is at HIGH LEVEL\n");
116 else
117 puts("usr button is at LOW LEVEL\n");
118 }
119
120 return 0;
121 }
122
board_init(void)123 int board_init(void)
124 {
125 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
126
127 #ifdef CONFIG_ETH_DESIGNWARE
128 const char *phy_mode;
129 int node;
130
131 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac");
132 if (node < 0)
133 return -1;
134
135 phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
136
137 switch (phy_get_interface_by_name(phy_mode)) {
138 case PHY_INTERFACE_MODE_RMII:
139 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
140 break;
141 case PHY_INTERFACE_MODE_MII:
142 STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL;
143 break;
144 default:
145 printf("PHY interface %s not supported !\n", phy_mode);
146 }
147 #endif
148
149 #if defined(CONFIG_CMD_BMP)
150 bmp_display((ulong)stmicroelectronics_uboot_logo_8bit_rle,
151 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
152 #endif /* CONFIG_CMD_BMP */
153
154 return 0;
155 }
156