]> git.ipfire.org Git - thirdparty/u-boot.git/blame - board/st/stm32f746-disco/stm32f746-disco.c
Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
[thirdparty/u-boot.git] / board / st / stm32f746-disco / stm32f746-disco.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
e66c49fa 2/*
3bc599c9
PC
3 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
e66c49fa
VM
5 */
6
d678a59d 7#include <common.h>
2d9c33ca 8#include <dm.h>
5255932f 9#include <init.h>
f7ae49fc 10#include <log.h>
77594d7f
PC
11#include <miiphy.h>
12#include <phy_interface.h>
2d9c33ca 13#include <ram.h>
b03e0510 14#include <serial.h>
b9747696 15#include <spl.h>
92eac584 16#include <splash.h>
92eac584 17#include <video.h>
401d1c4f 18#include <asm/global_data.h>
e66c49fa
VM
19#include <asm/io.h>
20#include <asm/armv7m.h>
21#include <asm/arch/stm32.h>
b20b70fc 22#include <asm/arch/syscfg.h>
2f80a9f7 23#include <asm/gpio.h>
c05ed00a 24#include <linux/delay.h>
e66c49fa
VM
25
26DECLARE_GLOBAL_DATA_PTR;
27
25c1b135
TN
28int dram_init(void)
29{
16613edb 30#ifndef CONFIG_SPL_BUILD
8ff21d6d 31 int rv;
b9747696 32 struct udevice *dev;
2d9c33ca
VM
33 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
34 if (rv) {
35 debug("DRAM init failed: %d\n", rv);
36 return rv;
37 }
57af3cc3 38
b9747696 39#endif
8ff21d6d 40 return fdtdec_setup_mem_size_base();
57af3cc3
VM
41}
42
43int dram_init_banksize(void)
44{
8ff21d6d 45 return fdtdec_setup_memory_banksize();
25c1b135
TN
46}
47
b9747696 48#ifdef CONFIG_SPL_BUILD
55a3ef71
VM
49#ifdef CONFIG_SPL_OS_BOOT
50int spl_start_uboot(void)
51{
52 debug("SPL: booting kernel\n");
53 /* break into full u-boot on 'c' */
54 return serial_tstc() && serial_getc() == 'c';
55}
56#endif
57
b9747696
VM
58int spl_dram_init(void)
59{
60 struct udevice *dev;
61 int rv;
62 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
63 if (rv)
64 debug("DRAM init failed: %d\n", rv);
65 return rv;
66}
67void spl_board_init(void)
68{
b9747696 69 preloader_console_init();
6bd8845a 70 spl_dram_init();
b9747696
VM
71 arch_cpu_init(); /* to configure mpu for sdram rw permissions */
72}
73u32 spl_boot_device(void)
74{
1a73bd84 75 return BOOT_DEVICE_XIP;
b9747696 76}
b9747696 77#endif
e66c49fa 78
2f80a9f7
VM
79int board_late_init(void)
80{
81 struct gpio_desc gpio = {};
82 int node;
83
84 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
85 if (node < 0)
86 return -1;
87
150c5afe 88 gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
2f80a9f7
VM
89 GPIOD_IS_OUT);
90
91 if (dm_gpio_is_valid(&gpio)) {
92 dm_gpio_set_value(&gpio, 0);
93 mdelay(10);
94 dm_gpio_set_value(&gpio, 1);
95 }
96
97 /* read button 1*/
98 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
99 if (node < 0)
100 return -1;
101
150c5afe
SG
102 gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
103 &gpio, GPIOD_IS_IN);
2f80a9f7
VM
104
105 if (dm_gpio_is_valid(&gpio)) {
106 if (dm_gpio_get_value(&gpio))
107 puts("usr button is at HIGH LEVEL\n");
108 else
109 puts("usr button is at LOW LEVEL\n");
110 }
111
112 return 0;
113}
114
e66c49fa
VM
115int board_init(void)
116{
20fe38e7 117#ifdef CONFIG_ETH_DESIGNWARE
123ca114 118 ofnode node;
77594d7f 119
123ca114
MB
120 node = ofnode_by_compatible(ofnode_null(), "st,stm32-dwmac");
121 if (!ofnode_valid(node))
77594d7f
PC
122 return -1;
123
123ca114 124 switch (ofnode_read_phy_mode(node)) {
77594d7f
PC
125 case PHY_INTERFACE_MODE_RMII:
126 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
127 break;
128 case PHY_INTERFACE_MODE_MII:
129 STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL;
130 break;
131 default:
123ca114 132 printf("Unsupported PHY interface!\n");
77594d7f 133 }
20fe38e7
PC
134#endif
135
e66c49fa
VM
136 return 0;
137}