blob: 370db15bea900100dc127322beba9590f34dba62 [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>
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 Kurzb20b70f2017-01-22 16:04:27 +010019#include <asm/arch/syscfg.h>
Vikas Manochae66c49f2016-02-11 15:47:20 -080020
21DECLARE_GLOBAL_DATA_PTR;
22
23const struct stm32_gpio_ctl gpio_ctl_gpout = {
24 .mode = STM32_GPIO_MODE_OUT,
25 .otype = STM32_GPIO_OTYPE_PP,
26 .speed = STM32_GPIO_SPEED_50M,
27 .pupd = STM32_GPIO_PUPD_NO,
28 .af = STM32_GPIO_AF0
29};
30
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090031static int fmc_setup_gpio(void)
32{
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090033 clock_setup(GPIO_B_CLOCK_CFG);
34 clock_setup(GPIO_C_CLOCK_CFG);
35 clock_setup(GPIO_D_CLOCK_CFG);
36 clock_setup(GPIO_E_CLOCK_CFG);
37 clock_setup(GPIO_F_CLOCK_CFG);
38 clock_setup(GPIO_G_CLOCK_CFG);
39 clock_setup(GPIO_H_CLOCK_CFG);
40
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070041 return 0;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090042}
43
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090044int dram_init(void)
45{
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070046 struct udevice *dev;
47 struct ram_info ram;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090048 int rv;
49
50 rv = fmc_setup_gpio();
51 if (rv)
52 return rv;
53
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070054 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
55 if (rv) {
56 debug("DRAM init failed: %d\n", rv);
57 return rv;
58 }
59 rv = ram_get_info(dev, &ram);
60 if (rv) {
61 debug("Cannot get DRAM size: %d\n", rv);
62 return rv;
63 }
64 debug("SDRAM base=%lx, size=%x\n", ram.base, ram.size);
65 gd->ram_size = ram.size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090066
67 /*
68 * Fill in global info with description of SRAM configuration
69 */
70 gd->bd->bi_dram[0].start = CONFIG_SYS_RAM_BASE;
Vikas Manocha2d9c33c2017-04-10 15:02:54 -070071 gd->bd->bi_dram[0].size = ram.size;
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090072
Toshifumi NISHINAGA25c1b132016-07-08 01:02:25 +090073 return rv;
74}
75
Vikas Manochae66c49f2016-02-11 15:47:20 -080076int uart_setup_gpio(void)
77{
Tom Rini95d52732016-07-21 15:38:13 -040078 clock_setup(GPIO_A_CLOCK_CFG);
79 clock_setup(GPIO_B_CLOCK_CFG);
Vikas Manochae34e19f2017-02-12 10:25:51 -080080 return 0;
Vikas Manochae66c49f2016-02-11 15:47:20 -080081}
82
Michael Kurzb20b70f2017-01-22 16:04:27 +010083#ifdef CONFIG_ETH_DESIGNWARE
Michael Kurzb20b70f2017-01-22 16:04:27 +010084
85static int stmmac_setup(void)
86{
Michael Kurzb20b70f2017-01-22 16:04:27 +010087 clock_setup(SYSCFG_CLOCK_CFG);
Michael Kurzb20b70f2017-01-22 16:04:27 +010088 /* Set >RMII mode */
89 STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
90
91 clock_setup(GPIO_A_CLOCK_CFG);
92 clock_setup(GPIO_C_CLOCK_CFG);
93 clock_setup(GPIO_G_CLOCK_CFG);
Michael Kurzb20b70f2017-01-22 16:04:27 +010094 clock_setup(STMMAC_CLOCK_CFG);
95
96 return 0;
97}
98#endif
99
Michael Kurzd4363ba2017-01-22 16:04:30 +0100100#ifdef CONFIG_STM32_QSPI
Michael Kurzd4363ba2017-01-22 16:04:30 +0100101
102static int qspi_setup(void)
103{
Michael Kurzd4363ba2017-01-22 16:04:30 +0100104 clock_setup(GPIO_B_CLOCK_CFG);
105 clock_setup(GPIO_D_CLOCK_CFG);
106 clock_setup(GPIO_E_CLOCK_CFG);
Michael Kurzd4363ba2017-01-22 16:04:30 +0100107 return 0;
108}
109#endif
110
Vikas Manochae66c49f2016-02-11 15:47:20 -0800111u32 get_board_rev(void)
112{
113 return 0;
114}
115
116int board_early_init_f(void)
117{
118 int res;
119
120 res = uart_setup_gpio();
Vikas Manochae66c49f2016-02-11 15:47:20 -0800121 if (res)
122 return res;
123
Michael Kurzb20b70f2017-01-22 16:04:27 +0100124#ifdef CONFIG_ETH_DESIGNWARE
125 res = stmmac_setup();
126 if (res)
127 return res;
128#endif
129
Michael Kurzd4363ba2017-01-22 16:04:30 +0100130#ifdef CONFIG_STM32_QSPI
131 res = qspi_setup();
132 if (res)
133 return res;
134#endif
135
Vikas Manochae66c49f2016-02-11 15:47:20 -0800136 return 0;
137}
138
139int board_init(void)
140{
141 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
142
143 return 0;
144}