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