blob: 7e8df8eaef4e2ec1b066bf9cf31b935b92c9b29d [file] [log] [blame]
rev13@wp.pled09a552015-03-01 12:44:42 +01001/*
2 * (C) Copyright 2011, 2012, 2013
3 * Yuri Tikhonov, Emcraft Systems, yur@emcraft.com
4 * Alexander Potashev, Emcraft Systems, aspotashev@emcraft.com
5 * Vladimir Khusainov, Emcraft Systems, vlad@emcraft.com
6 * Pavel Boldin, Emcraft Systems, paboldin@emcraft.com
7 *
8 * (C) Copyright 2015
Kamil Lulko66562412015-12-01 09:08:19 +01009 * Kamil Lulko, <kamil.lulko@gmail.com>
rev13@wp.pled09a552015-03-01 12:44:42 +010010 *
11 * SPDX-License-Identifier: GPL-2.0+
12 */
13
14#include <common.h>
Simon Glass9d922452017-05-17 17:18:03 -060015#include <dm.h>
Patrice Chotard014a9532017-11-15 13:14:53 +010016#include <stm32_rcc.h>
rev13@wp.pled09a552015-03-01 12:44:42 +010017#include <asm/io.h>
rev13@wp.pled09a552015-03-01 12:44:42 +010018#include <asm/arch/stm32.h>
19#include <asm/arch/gpio.h>
Kamil Lulko66562412015-12-01 09:08:19 +010020#include <dm/platform_data/serial_stm32.h>
Vikas Manochadffceb42016-01-26 18:12:20 -080021#include <asm/arch/stm32_periph.h>
22#include <asm/arch/stm32_defs.h>
rev13@wp.pled09a552015-03-01 12:44:42 +010023
24DECLARE_GLOBAL_DATA_PTR;
25
26const struct stm32_gpio_ctl gpio_ctl_gpout = {
27 .mode = STM32_GPIO_MODE_OUT,
28 .otype = STM32_GPIO_OTYPE_PP,
29 .speed = STM32_GPIO_SPEED_50M,
30 .pupd = STM32_GPIO_PUPD_NO,
31 .af = STM32_GPIO_AF0
32};
33
34const struct stm32_gpio_ctl gpio_ctl_usart = {
35 .mode = STM32_GPIO_MODE_AF,
36 .otype = STM32_GPIO_OTYPE_PP,
37 .speed = STM32_GPIO_SPEED_50M,
38 .pupd = STM32_GPIO_PUPD_UP,
kunhuahuang60570df2015-04-28 03:01:19 +080039 .af = STM32_GPIO_USART
rev13@wp.pled09a552015-03-01 12:44:42 +010040};
41
kunhuahuang60570df2015-04-28 03:01:19 +080042static const struct stm32_gpio_dsc usart_gpio[] = {
43 {STM32_GPIO_PORT_X, STM32_GPIO_PIN_TX}, /* TX */
44 {STM32_GPIO_PORT_X, STM32_GPIO_PIN_RX}, /* RX */
rev13@wp.pled09a552015-03-01 12:44:42 +010045};
46
kunhuahuang60570df2015-04-28 03:01:19 +080047int uart_setup_gpio(void)
rev13@wp.pled09a552015-03-01 12:44:42 +010048{
49 int i;
50 int rv = 0;
51
Vikas Manocha14cec062016-02-11 15:47:17 -080052 clock_setup(GPIO_A_CLOCK_CFG);
kunhuahuang60570df2015-04-28 03:01:19 +080053 for (i = 0; i < ARRAY_SIZE(usart_gpio); i++) {
54 rv = stm32_gpio_config(&usart_gpio[i], &gpio_ctl_usart);
rev13@wp.pled09a552015-03-01 12:44:42 +010055 if (rv)
56 goto out;
57 }
58
59out:
60 return rv;
61}
62
63const struct stm32_gpio_ctl gpio_ctl_fmc = {
64 .mode = STM32_GPIO_MODE_AF,
65 .otype = STM32_GPIO_OTYPE_PP,
66 .speed = STM32_GPIO_SPEED_100M,
67 .pupd = STM32_GPIO_PUPD_NO,
68 .af = STM32_GPIO_AF12
69};
70
71static const struct stm32_gpio_dsc ext_ram_fmc_gpio[] = {
72 /* Chip is LQFP144, see DM00077036.pdf for details */
73 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_10}, /* 79, FMC_D15 */
74 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_9}, /* 78, FMC_D14 */
75 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_8}, /* 77, FMC_D13 */
76 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_15}, /* 68, FMC_D12 */
77 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_14}, /* 67, FMC_D11 */
78 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_13}, /* 66, FMC_D10 */
79 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_12}, /* 65, FMC_D9 */
80 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_11}, /* 64, FMC_D8 */
81 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_10}, /* 63, FMC_D7 */
82 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_9}, /* 60, FMC_D6 */
83 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_8}, /* 59, FMC_D5 */
84 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_7}, /* 58, FMC_D4 */
85 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_1}, /* 115, FMC_D3 */
86 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_0}, /* 114, FMC_D2 */
87 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_15}, /* 86, FMC_D1 */
88 {STM32_GPIO_PORT_D, STM32_GPIO_PIN_14}, /* 85, FMC_D0 */
89 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_1}, /* 142, FMC_NBL1 */
90 {STM32_GPIO_PORT_E, STM32_GPIO_PIN_0}, /* 141, FMC_NBL0 */
91 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_5}, /* 90, FMC_A15, BA1 */
92 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_4}, /* 89, FMC_A14, BA0 */
93 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_1}, /* 57, FMC_A11 */
94 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_0}, /* 56, FMC_A10 */
95 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_15}, /* 55, FMC_A9 */
96 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_14}, /* 54, FMC_A8 */
97 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_13}, /* 53, FMC_A7 */
98 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_12}, /* 50, FMC_A6 */
99 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_5}, /* 15, FMC_A5 */
100 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_4}, /* 14, FMC_A4 */
101 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_3}, /* 13, FMC_A3 */
102 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_2}, /* 12, FMC_A2 */
103 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_1}, /* 11, FMC_A1 */
104 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_0}, /* 10, FMC_A0 */
105 {STM32_GPIO_PORT_B, STM32_GPIO_PIN_6}, /* 136, SDRAM_NE */
106 {STM32_GPIO_PORT_F, STM32_GPIO_PIN_11}, /* 49, SDRAM_NRAS */
107 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_15}, /* 132, SDRAM_NCAS */
108 {STM32_GPIO_PORT_C, STM32_GPIO_PIN_0}, /* 26, SDRAM_NWE */
109 {STM32_GPIO_PORT_B, STM32_GPIO_PIN_5}, /* 135, SDRAM_CKE */
110 {STM32_GPIO_PORT_G, STM32_GPIO_PIN_8}, /* 93, SDRAM_CLK */
111};
112
113static int fmc_setup_gpio(void)
114{
115 int rv = 0;
116 int i;
117
Vikas Manocha14cec062016-02-11 15:47:17 -0800118 clock_setup(GPIO_B_CLOCK_CFG);
119 clock_setup(GPIO_C_CLOCK_CFG);
120 clock_setup(GPIO_D_CLOCK_CFG);
121 clock_setup(GPIO_E_CLOCK_CFG);
122 clock_setup(GPIO_F_CLOCK_CFG);
123 clock_setup(GPIO_G_CLOCK_CFG);
124
rev13@wp.pled09a552015-03-01 12:44:42 +0100125 for (i = 0; i < ARRAY_SIZE(ext_ram_fmc_gpio); i++) {
126 rv = stm32_gpio_config(&ext_ram_fmc_gpio[i],
127 &gpio_ctl_fmc);
128 if (rv)
129 goto out;
130 }
131
132out:
133 return rv;
134}
135
136/*
137 * STM32 RCC FMC specific definitions
138 */
139#define STM32_RCC_ENR_FMC (1 << 0) /* FMC module clock */
140
rev13@wp.pled09a552015-03-01 12:44:42 +0100141int dram_init(void)
142{
rev13@wp.pled09a552015-03-01 12:44:42 +0100143 int rv;
Patrice Chotard7fd65ef2017-12-12 09:49:34 +0100144 struct udevice *dev;
rev13@wp.pled09a552015-03-01 12:44:42 +0100145
146 rv = fmc_setup_gpio();
147 if (rv)
148 return rv;
149
150 setbits_le32(&STM32_RCC->ahb3enr, STM32_RCC_ENR_FMC);
151
Patrice Chotard7fd65ef2017-12-12 09:49:34 +0100152 rv = uclass_get_device(UCLASS_RAM, 0, &dev);
153 if (rv) {
154 debug("DRAM init failed: %d\n", rv);
155 return rv;
156 }
rev13@wp.pled09a552015-03-01 12:44:42 +0100157
Patrice Chotard7fd65ef2017-12-12 09:49:34 +0100158 if (fdtdec_setup_memory_size() != 0)
159 rv = -EINVAL;
rev13@wp.pled09a552015-03-01 12:44:42 +0100160
161 return rv;
162}
163
Patrice Chotard7fd65ef2017-12-12 09:49:34 +0100164int dram_init_banksize(void)
165{
166 fdtdec_setup_memory_banksize();
167
168 return 0;
169}
170
Kamil Lulko66562412015-12-01 09:08:19 +0100171static const struct stm32_serial_platdata serial_platdata = {
172 .base = (struct stm32_usart *)STM32_USART1_BASE,
173};
174
175U_BOOT_DEVICE(stm32_serials) = {
176 .name = "serial_stm32",
177 .platdata = &serial_platdata,
178};
179
rev13@wp.pled09a552015-03-01 12:44:42 +0100180u32 get_board_rev(void)
181{
182 return 0;
183}
184
185int board_early_init_f(void)
186{
187 int res;
188
Patrice Chotardc729fb22017-11-16 08:59:21 +0100189 configure_clocks();
190
kunhuahuang60570df2015-04-28 03:01:19 +0800191 res = uart_setup_gpio();
rev13@wp.pled09a552015-03-01 12:44:42 +0100192 if (res)
193 return res;
Vikas Manochadffceb42016-01-26 18:12:20 -0800194 clock_setup(USART1_CLOCK_CFG);
rev13@wp.pled09a552015-03-01 12:44:42 +0100195
196 return 0;
197}
198
199int board_init(void)
200{
201 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
202
203 return 0;
204}
Antonio Borneo089fddf2015-07-19 22:19:46 +0800205
206#ifdef CONFIG_MISC_INIT_R
207int misc_init_r(void)
208{
209 char serialno[25];
210 uint32_t u_id_low, u_id_mid, u_id_high;
211
Simon Glass00caae62017-08-03 12:22:12 -0600212 if (!env_get("serial#")) {
Antonio Borneo089fddf2015-07-19 22:19:46 +0800213 u_id_low = readl(&STM32_U_ID->u_id_low);
214 u_id_mid = readl(&STM32_U_ID->u_id_mid);
215 u_id_high = readl(&STM32_U_ID->u_id_high);
216 sprintf(serialno, "%08x%08x%08x",
217 u_id_high, u_id_mid, u_id_low);
Simon Glass382bee52017-08-03 12:22:09 -0600218 env_set("serial#", serialno);
Antonio Borneo089fddf2015-07-19 22:19:46 +0800219 }
220
221 return 0;
222}
223#endif