Merge tag 'xilinx-for-v2021.04-rc3' of https://gitlab.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / board / st / stm32f746-disco / stm32f746-disco.c
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
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
46 int dram_init_banksize(void)
47 {
48         return fdtdec_setup_memory_banksize();
49 }
50
51 int board_early_init_f(void)
52 {
53         return 0;
54 }
55
56 #ifdef CONFIG_SPL_BUILD
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
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 {
83         return BOOT_DEVICE_XIP;
84 }
85
86 #endif
87 u32 get_board_rev(void)
88 {
89         return 0;
90 }
91
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
101         gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
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
115         gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
116                                    &gpio, GPIOD_IS_IN);
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
128 int board_init(void)
129 {
130         gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
131
132 #ifdef CONFIG_ETH_DESIGNWARE
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         }
152 #endif
153
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
159         return 0;
160 }