blob: c4f263332c8b06b65a30ffab00f4499378e305d7 [file] [log] [blame]
Vikas Manochae66c49f2016-02-11 15:47:20 -08001/*
Patrice Chotard3bc599c2017-10-23 09:53:58 +02002 * Copyright (C) 2016, STMicroelectronics - All Rights Reserved
3 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
Vikas Manochae66c49f2016-02-11 15:47:20 -08004 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Vikas Manocha2d9c33c2017-04-10 15:02:54 -07009#include <dm.h>
yannick fertre92eac582018-03-02 15:59:28 +010010#include <lcd.h>
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070011#include <ram.h>
Vikas Manochab9747692017-05-28 12:55:10 -070012#include <spl.h>
yannick fertre92eac582018-03-02 15:59:28 +010013#include <splash.h>
14#include <st_logo_data.h>
15#include <video.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080016#include <asm/io.h>
17#include <asm/armv7m.h>
18#include <asm/arch/stm32.h>
19#include <asm/arch/gpio.h>
Michael Kurzb20b70f2017-01-22 16:04:27 +010020#include <asm/arch/syscfg.h>
Vikas Manocha2f80a9f2017-04-10 15:03:00 -070021#include <asm/gpio.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080022
23DECLARE_GLOBAL_DATA_PTR;
24
Vikas Manocha57af3cc2017-04-10 15:03:01 -070025int get_memory_base_size(fdt_addr_t *mr_base, fdt_addr_t *mr_size)
26{
27 int mr_node;
28
29 mr_node = fdt_path_offset(gd->fdt_blob, "/memory");
30 if (mr_node < 0)
31 return mr_node;
32 *mr_base = fdtdec_get_addr_size_auto_noparent(gd->fdt_blob, mr_node,
33 "reg", 0, mr_size, false);
34 debug("mr_base = %lx, mr_size= %lx\n", *mr_base, *mr_size);
35
36 return 0;
37}
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090038int dram_init(void)
39{
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090040 int rv;
Vikas Manocha57af3cc2017-04-10 15:03:01 -070041 fdt_addr_t mr_base, mr_size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090042
Vikas Manochab9747692017-05-28 12:55:10 -070043#ifndef CONFIG_SUPPORT_SPL
44 struct udevice *dev;
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070045 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
46 if (rv) {
47 debug("DRAM init failed: %d\n", rv);
48 return rv;
49 }
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090050
Vikas Manochab9747692017-05-28 12:55:10 -070051#endif
Vikas Manocha57af3cc2017-04-10 15:03:01 -070052 rv = get_memory_base_size(&mr_base, &mr_size);
53 if (rv)
54 return rv;
55 gd->ram_size = mr_size;
56 gd->ram_top = mr_base;
57
58 return rv;
59}
60
61int dram_init_banksize(void)
62{
63 fdt_addr_t mr_base, mr_size;
64 get_memory_base_size(&mr_base, &mr_size);
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090065 /*
66 * Fill in global info with description of SRAM configuration
67 */
Vikas Manocha57af3cc2017-04-10 15:03:01 -070068 gd->bd->bi_dram[0].start = mr_base;
69 gd->bd->bi_dram[0].size = mr_size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090070
Vikas Manocha57af3cc2017-04-10 15:03:01 -070071 return 0;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090072}
73
Vikas Manocha280057b2017-04-10 15:02:59 -070074int board_early_init_f(void)
Michael Kurzd4363ba2017-01-22 16:04:30 +010075{
Michael Kurzd4363ba2017-01-22 16:04:30 +010076 return 0;
77}
Michael Kurzd4363ba2017-01-22 16:04:30 +010078
Vikas Manochab9747692017-05-28 12:55:10 -070079#ifdef CONFIG_SPL_BUILD
Vikas Manocha55a3ef72017-05-28 12:55:13 -070080#ifdef CONFIG_SPL_OS_BOOT
81int spl_start_uboot(void)
82{
83 debug("SPL: booting kernel\n");
84 /* break into full u-boot on 'c' */
85 return serial_tstc() && serial_getc() == 'c';
86}
87#endif
88
Vikas Manochab9747692017-05-28 12:55:10 -070089int spl_dram_init(void)
90{
91 struct udevice *dev;
92 int rv;
93 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
94 if (rv)
95 debug("DRAM init failed: %d\n", rv);
96 return rv;
97}
98void spl_board_init(void)
99{
100 spl_dram_init();
101 preloader_console_init();
102 arch_cpu_init(); /* to configure mpu for sdram rw permissions */
103}
104u32 spl_boot_device(void)
105{
Vikas Manocha1a73bd82017-05-28 12:55:14 -0700106 return BOOT_DEVICE_XIP;
Vikas Manochab9747692017-05-28 12:55:10 -0700107}
108
109#endif
Vikas Manochae66c49f2016-02-11 15:47:20 -0800110u32 get_board_rev(void)
111{
112 return 0;
113}
114
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700115int board_late_init(void)
116{
117 struct gpio_desc gpio = {};
118 int node;
119
120 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
121 if (node < 0)
122 return -1;
123
Simon Glass150c5af2017-05-30 21:47:09 -0600124 gpio_request_by_name_nodev(offset_to_ofnode(node), "led-gpio", 0, &gpio,
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700125 GPIOD_IS_OUT);
126
127 if (dm_gpio_is_valid(&gpio)) {
128 dm_gpio_set_value(&gpio, 0);
129 mdelay(10);
130 dm_gpio_set_value(&gpio, 1);
131 }
132
133 /* read button 1*/
134 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
135 if (node < 0)
136 return -1;
137
Simon Glass150c5af2017-05-30 21:47:09 -0600138 gpio_request_by_name_nodev(offset_to_ofnode(node), "button-gpio", 0,
139 &gpio, GPIOD_IS_IN);
Vikas Manocha2f80a9f2017-04-10 15:03:00 -0700140
141 if (dm_gpio_is_valid(&gpio)) {
142 if (dm_gpio_get_value(&gpio))
143 puts("usr button is at HIGH LEVEL\n");
144 else
145 puts("usr button is at LOW LEVEL\n");
146 }
147
148 return 0;
149}
150
Vikas Manochae66c49f2016-02-11 15:47:20 -0800151int board_init(void)
152{
Vikas Manocha57af3cc2017-04-10 15:03:01 -0700153 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Patrice Chotard20fe38e2018-01-18 14:10:05 +0100154
155#ifdef CONFIG_ETH_DESIGNWARE
156 /* Set >RMII mode */
157 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
158#endif
159
yannick fertre92eac582018-03-02 15:59:28 +0100160#if defined(CONFIG_CMD_BMP)
161 bmp_display((ulong)stmicroelectronics_uboot_logo_8bit_rle,
162 BMP_ALIGN_CENTER, BMP_ALIGN_CENTER);
163#endif /* CONFIG_CMD_BMP */
164
Vikas Manochae66c49f2016-02-11 15:47:20 -0800165 return 0;
166}