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