blob: e21cfc6e495579ef2762c1039adc119b113843bc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vikas Manochae66c49f2016-02-11 15:47:20 -08002/*
Patrice Chotard3bc599c2017-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 Manochae66c49f2016-02-11 15:47:20 -08005 */
6
7#include <common.h>
Vikas Manocha2d9c33c2017-04-10 15:02:54 -07008#include <dm.h>
yannick fertre92eac582018-03-02 15:59:28 +01009#include <lcd.h>
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070010#include <ram.h>
Vikas Manochab9747692017-05-28 12:55:10 -070011#include <spl.h>
yannick fertre92eac582018-03-02 15:59:28 +010012#include <splash.h>
13#include <st_logo_data.h>
14#include <video.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080015#include <asm/io.h>
16#include <asm/armv7m.h>
17#include <asm/arch/stm32.h>
18#include <asm/arch/gpio.h>
Michael Kurzb20b70f2017-01-22 16:04:27 +010019#include <asm/arch/syscfg.h>
Vikas Manocha2f80a9f2017-04-10 15:03:00 -070020#include <asm/gpio.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080021
22DECLARE_GLOBAL_DATA_PTR;
23
Vikas Manocha57af3cc2017-04-10 15:03:01 -070024int get_memory_base_size(fdt_addr_t *mr_base, fdt_addr_t *mr_size)
25{
26 int mr_node;
27
28 mr_node = fdt_path_offset(gd->fdt_blob, "/memory");
29 if (mr_node < 0)
30 return mr_node;
31 *mr_base = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, mr_node,
32 "reg", 0, mr_size, false);
33 debug("mr_base = %lx, mr_size= %lx\n", *mr_base, *mr_size);
34
35 return 0;
36}
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090037int dram_init(void)
38{
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090039 int rv;
Vikas Manocha57af3cc2017-04-10 15:03:01 -070040 fdt_addr_t mr_base, mr_size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090041
Vikas Manochab9747692017-05-28 12:55:10 -070042#ifndef CONFIG_SUPPORT_SPL
43 struct udevice *dev;
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070044 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
45 if (rv) {
46 debug("DRAM init failed: %d\n", rv);
47 return rv;
48 }
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090049
Vikas Manochab9747692017-05-28 12:55:10 -070050#endif
Vikas Manocha57af3cc2017-04-10 15:03:01 -070051 rv = get_memory_base_size(&mr_base, &mr_size);
52 if (rv)
53 return rv;
54 gd->ram_size = mr_size;
55 gd->ram_top = mr_base;
56
57 return rv;
58}
59
60int dram_init_banksize(void)
61{
62 fdt_addr_t mr_base, mr_size;
63 get_memory_base_size(&mr_base, &mr_size);
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090064 /*
65 * Fill in global info with description of SRAM configuration
66 */
Vikas Manocha57af3cc2017-04-10 15:03:01 -070067 gd->bd->bi_dram[0].start = mr_base;
68 gd->bd->bi_dram[0].size = mr_size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090069
Vikas Manocha57af3cc2017-04-10 15:03:01 -070070 return 0;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090071}
72
Vikas Manocha280057b2017-04-10 15:02:59 -070073int board_early_init_f(void)
Michael Kurzd4363ba2017-01-22 16:04:30 +010074{
Michael Kurzd4363ba2017-01-22 16:04:30 +010075 return 0;
76}
Michael Kurzd4363ba2017-01-22 16:04:30 +010077
Vikas Manochab9747692017-05-28 12:55:10 -070078#ifdef CONFIG_SPL_BUILD
Vikas Manocha55a3ef72017-05-28 12:55:13 -070079#ifdef CONFIG_SPL_OS_BOOT
80int spl_start_uboot(void)
81{
82 debug("SPL: booting kernel\n");
83 /* break into full u-boot on 'c' */
84 return serial_tstc() && serial_getc() == 'c';
85}
86#endif
87
Vikas Manochab9747692017-05-28 12:55:10 -070088int spl_dram_init(void)
89{
90 struct udevice *dev;
91 int rv;
92 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
93 if (rv)
94 debug("DRAM init failed: %d\n", rv);
95 return rv;
96}
97void spl_board_init(void)
98{
99 spl_dram_init();
100 preloader_console_init();
101 arch_cpu_init(); /* to configure mpu for sdram rw permissions */
102}
103u32 spl_boot_device(void)
104{
Vikas Manocha1a73bd82017-05-28 12:55:14 -0700105 return BOOT_DEVICE_XIP;
Vikas Manochab9747692017-05-28 12:55:10 -0700106}
107
108#endif
Vikas Manochae66c49f2016-02-11 15:47:20 -0800109u32 get_board_rev(void)
110{
111 return 0;
112}
113
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700114int board_late_init(void)
115{
116 struct gpio_desc gpio = {};
117 int node;
118
119 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
120 if (node < 0)
121 return -1;
122
Simon Glass150c5af2017-05-30 21:47:09 -0600123 gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700124 GPIOD_IS_OUT);
125
126 if (dm_gpio_is_valid(&gpio)) {
127 dm_gpio_set_value(&gpio, 0);
128 mdelay(10);
129 dm_gpio_set_value(&gpio, 1);
130 }
131
132 /* read button 1*/
133 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
134 if (node < 0)
135 return -1;
136
Simon Glass150c5af2017-05-30 21:47:09 -0600137 gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
138 &gpio, GPIOD_IS_IN);
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700139
140 if (dm_gpio_is_valid(&gpio)) {
141 if (dm_gpio_get_value(&gpio))
142 puts("usr button is at HIGH LEVEL\n");
143 else
144 puts("usr button is at LOW LEVEL\n");
145 }
146
147 return 0;
148}
149
Vikas Manochae66c49f2016-02-11 15:47:20 -0800150int board_init(void)
151{
Vikas Manocha57af3cc2017-04-10 15:03:01 -0700152 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Patrice Chotard20fe38e2018-01-18 14:10:05 +0100153
154#ifdef CONFIG_ETH_DESIGNWARE
155 /* Set >RMII mode */
156 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
157#endif
158
yannick fertre92eac582018-03-02 15:59:28 +0100159#if defined(CONFIG_CMD_BMP)
160 bmp_display((ulong)stmicroelectronics_uboot_logo_8bit_rle,
161 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
162#endif /* CONFIG_CMD_BMP */
163
Vikas Manochae66c49f2016-02-11 15:47:20 -0800164 return 0;
165}