blob: dc3a9dcade000c21bc7e35be3d80f393d2756820 [file] [log] [blame]
Vikas Manocha1b51c932016-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 Manocha096be332017-04-10 15:02:54 -07009#include <dm.h>
10#include <ram.h>
Vikas Manocha1b51c932016-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>
15#include <dm/platdata.h>
16#include <dm/platform_data/serial_stm32x7.h>
17#include <asm/arch/stm32_periph.h>
18#include <asm/arch/stm32_defs.h>
Michael Kurz812962b2017-01-22 16:04:27 +010019#include <asm/arch/syscfg.h>
Vikas Manocha9c7573e2017-04-10 15:03:00 -070020#include <asm/gpio.h>
Vikas Manocha1b51c932016-02-11 15:47:20 -080021
22DECLARE_GLOBAL_DATA_PTR;
23
Vikas Manochab6fd9eb2017-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 NISHINAGA18bd7632016-07-08 01:02:25 +090037int dram_init(void)
38{
Vikas Manocha096be332017-04-10 15:02:54 -070039 struct udevice *dev;
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090040 int rv;
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070041 fdt_addr_t mr_base, mr_size;
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090042
Vikas Manocha096be332017-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 }
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070048
49 rv = get_memory_base_size(&mr_base, &mr_size);
50 if (rv)
Vikas Manocha096be332017-04-10 15:02:54 -070051 return rv;
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070052 gd->ram_size = mr_size;
53 gd->ram_top = mr_base;
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090054
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070055 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 NISHINAGA18bd7632016-07-08 01:02:25 +090062 /*
63 * Fill in global info with description of SRAM configuration
64 */
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070065 gd->bd->bi_dram[0].start = mr_base;
66 gd->bd->bi_dram[0].size = mr_size;
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090067
Vikas Manochab6fd9eb2017-04-10 15:03:01 -070068 return 0;
Toshifumi NISHINAGA18bd7632016-07-08 01:02:25 +090069}
70
Michael Kurz812962b2017-01-22 16:04:27 +010071#ifdef CONFIG_ETH_DESIGNWARE
Michael Kurz812962b2017-01-22 16:04:27 +010072static int stmmac_setup(void)
73{
Michael Kurz812962b2017-01-22 16:04:27 +010074 clock_setup(SYSCFG_CLOCK_CFG);
Michael Kurz812962b2017-01-22 16:04:27 +010075 /* Set >RMII mode */
76 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
Michael Kurz812962b2017-01-22 16:04:27 +010077 clock_setup(STMMAC_CLOCK_CFG);
78
79 return 0;
80}
Michael Kurz812962b2017-01-22 16:04:27 +010081
Vikas Manocha1a8fde72017-04-10 15:02:59 -070082int board_early_init_f(void)
Michael Kurz337ff2a2017-01-22 16:04:30 +010083{
Vikas Manocha1a8fde72017-04-10 15:02:59 -070084 stmmac_setup();
85
Michael Kurz337ff2a2017-01-22 16:04:30 +010086 return 0;
87}
88#endif
89
Vikas Manocha1b51c932016-02-11 15:47:20 -080090u32 get_board_rev(void)
91{
Vikas Manocha1b51c932016-02-11 15:47:20 -080092 return 0;
93}
94
Vikas Manocha9c7573e2017-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 Manocha1b51c932016-02-11 15:47:20 -0800131int board_init(void)
132{
Vikas Manochab6fd9eb2017-04-10 15:03:01 -0700133 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Vikas Manocha1b51c932016-02-11 15:47:20 -0800134 return 0;
135}