blob: aeaa31146a5ad073e981fe21e338a9334abaabd4 [file] [log] [blame]
Vikas Manochae66c49f2016-02-11 15:47:20 -08001/*
2 * (C) Copyright 2016
3 * Vikas Manocha, <vikas.manocha@st.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
Vikas Manocha2d9c33c2017-04-10 15:02:54 -07009#include <dm.h>
10#include <ram.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080011#include <asm/io.h>
12#include <asm/armv7m.h>
13#include <asm/arch/stm32.h>
14#include <asm/arch/gpio.h>
Simon Glass9d922452017-05-17 17:18:03 -060015#include <asm/arch/fmc.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080016#include <dm/platform_data/serial_stm32x7.h>
17#include <asm/arch/stm32_periph.h>
18#include <asm/arch/stm32_defs.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{
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070039 struct udevice *dev;
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 Manocha2d9c33c2017-04-10 15:02:54 -070043 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
44 if (rv) {
45 debug("DRAM init failed: %d\n", rv);
46 return rv;
47 }
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090048
Vikas Manocha57af3cc2017-04-10 15:03:01 -070049 rv = get_memory_base_size(&mr_base, &mr_size);
50 if (rv)
51 return rv;
52 gd->ram_size = mr_size;
53 gd->ram_top = mr_base;
54
55 return rv;
56}
57
58int dram_init_banksize(void)
59{
60 fdt_addr_t mr_base, mr_size;
61 get_memory_base_size(&mr_base, &mr_size);
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090062 /*
63 * Fill in global info with description of SRAM configuration
64 */
Vikas Manocha57af3cc2017-04-10 15:03:01 -070065 gd->bd->bi_dram[0].start = mr_base;
66 gd->bd->bi_dram[0].size = mr_size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090067
Vikas Manocha57af3cc2017-04-10 15:03:01 -070068 return 0;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090069}
70
Michael Kurzb20b70f2017-01-22 16:04:27 +010071#ifdef CONFIG_ETH_DESIGNWARE
Michael Kurzb20b70f2017-01-22 16:04:27 +010072static int stmmac_setup(void)
73{
Michael Kurzb20b70f2017-01-22 16:04:27 +010074 clock_setup(SYSCFG_CLOCK_CFG);
Michael Kurzb20b70f2017-01-22 16:04:27 +010075 /* Set >RMII mode */
76 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
Michael Kurzb20b70f2017-01-22 16:04:27 +010077 clock_setup(STMMAC_CLOCK_CFG);
78
79 return 0;
80}
Michael Kurzb20b70f2017-01-22 16:04:27 +010081
Vikas Manocha280057b2017-04-10 15:02:59 -070082int board_early_init_f(void)
Michael Kurzd4363ba2017-01-22 16:04:30 +010083{
Vikas Manocha280057b2017-04-10 15:02:59 -070084 stmmac_setup();
85
Michael Kurzd4363ba2017-01-22 16:04:30 +010086 return 0;
87}
88#endif
89
Vikas Manochae66c49f2016-02-11 15:47:20 -080090u32 get_board_rev(void)
91{
92 return 0;
93}
94
Vikas Manocha2f80a9f2017-04-10 15:03:00 -070095int board_late_init(void)
96{
97 struct gpio_desc gpio = {};
98 int node;
99
100 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,led1");
101 if (node < 0)
102 return -1;
103
104 gpio_request_by_name_nodev(gd->fdt_blob, node, "led-gpio", 0, &gpio,
105 GPIOD_IS_OUT);
106
107 if (dm_gpio_is_valid(&gpio)) {
108 dm_gpio_set_value(&gpio, 0);
109 mdelay(10);
110 dm_gpio_set_value(&gpio, 1);
111 }
112
113 /* read button 1*/
114 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,button1");
115 if (node < 0)
116 return -1;
117
118 gpio_request_by_name_nodev(gd->fdt_blob, node, "button-gpio", 0, &gpio,
119 GPIOD_IS_IN);
120
121 if (dm_gpio_is_valid(&gpio)) {
122 if (dm_gpio_get_value(&gpio))
123 puts("usr button is at HIGH LEVEL\n");
124 else
125 puts("usr button is at LOW LEVEL\n");
126 }
127
128 return 0;
129}
130
Vikas Manochae66c49f2016-02-11 15:47:20 -0800131int board_init(void)
132{
Vikas Manocha57af3cc2017-04-10 15:03:01 -0700133 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Vikas Manochae66c49f2016-02-11 15:47:20 -0800134 return 0;
135}