blob: e89ed2153bc3894148760da5d1f688dbf1489443 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vikas Manocha1b51c932016-02-11 15:47:20 -08002/*
Patrice Chotard789ee0e2017-10-23 09:53:58 +02003 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
Vikas Manocha1b51c932016-02-11 15:47:20 -08005 */
6
7#include <common.h>
Vikas Manocha096be332017-04-10 15:02:54 -07008#include <dm.h>
yannick fertre030af822018-03-02 15:59:28 +01009#include <lcd.h>
Patrice Chotardd8c77552019-02-22 15:04:44 +010010#include <miiphy.h>
11#include <phy_interface.h>
Vikas Manocha096be332017-04-10 15:02:54 -070012#include <ram.h>
Vikas Manocha50218ae2017-05-28 12:55:10 -070013#include <spl.h>
yannick fertre030af822018-03-02 15:59:28 +010014#include <splash.h>
15#include <st_logo_data.h>
16#include <video.h>
Vikas Manocha1b51c932016-02-11 15:47:20 -080017#include <asm/io.h>
18#include <asm/armv7m.h>
19#include <asm/arch/stm32.h>
20#include <asm/arch/gpio.h>
Michael Kurz812962b2017-01-22 16:04:27 +010021#include <asm/arch/syscfg.h>
Vikas Manocha9c7573e2017-04-10 15:03:00 -070022#include <asm/gpio.h>
Vikas Manocha1b51c932016-02-11 15:47:20 -080023
24DECLARE_GLOBAL_DATA_PTR;
25
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090026int dram_init(void)
27{
Vikas Manocha50218ae2017-05-28 12:55:10 -070028#ifndef CONFIG_SUPPORT_SPL
Patrice Chotardb75feec2018-08-03 13:09:55 +020029 int rv;
Vikas Manocha50218ae2017-05-28 12:55:10 -070030 struct udevice *dev;
Vikas Manocha096be332017-04-10 15:02:54 -070031 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
32 if (rv) {
33 debug("DRAM init failed: %d\n", rv);
34 return rv;
35 }
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070036
Vikas Manocha50218ae2017-05-28 12:55:10 -070037#endif
Patrice Chotardb75feec2018-08-03 13:09:55 +020038 return fdtdec_setup_mem_size_base();
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070039}
40
41int dram_init_banksize(void)
42{
Patrice Chotardb75feec2018-08-03 13:09:55 +020043 return fdtdec_setup_memory_banksize();
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090044}
45
Vikas Manocha1a8fde72017-04-10 15:02:59 -070046int board_early_init_f(void)
Michael Kurz337ff2a2017-01-22 16:04:30 +010047{
Michael Kurz337ff2a2017-01-22 16:04:30 +010048 return 0;
49}
Michael Kurz337ff2a2017-01-22 16:04:30 +010050
Vikas Manocha50218ae2017-05-28 12:55:10 -070051#ifdef CONFIG_SPL_BUILD
Vikas Manochab785bb42017-05-28 12:55:13 -070052#ifdef CONFIG_SPL_OS_BOOT
53int 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
Vikas Manocha50218ae2017-05-28 12:55:10 -070061int 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}
70void 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}
76u32 spl_boot_device(void)
77{
Vikas Manochaf0e32c02017-05-28 12:55:14 -070078 return BOOT_DEVICE_XIP;
Vikas Manocha50218ae2017-05-28 12:55:10 -070079}
80
81#endif
Vikas Manocha1b51c932016-02-11 15:47:20 -080082u32 get_board_rev(void)
83{
Vikas Manocha1b51c932016-02-11 15:47:20 -080084 return 0;
85}
86
Vikas Manocha9c7573e2017-04-10 15:03:00 -070087int 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
Simon Glass1d9af1f2017-05-30 21:47:09 -060096 gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
Vikas Manocha9c7573e2017-04-10 15:03:00 -070097 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
Simon Glass1d9af1f2017-05-30 21:47:09 -0600110 gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
111 &gpio, GPIOD_IS_IN);
Vikas Manocha9c7573e2017-04-10 15:03:00 -0700112
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
Vikas Manocha1b51c932016-02-11 15:47:20 -0800123int board_init(void)
124{
Vikas Manochab6fd9eb2017-04-10 15:03:01 -0700125 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Patrice Chotarde2d564e2018-01-18 14:10:05 +0100126
127#ifdef CONFIG_ETH_DESIGNWARE
Patrice Chotardd8c77552019-02-22 15:04:44 +0100128 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 }
Patrice Chotarde2d564e2018-01-18 14:10:05 +0100147#endif
148
yannick fertre030af822018-03-02 15:59:28 +0100149#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
Vikas Manocha1b51c932016-02-11 15:47:20 -0800154 return 0;
155}