blob: eca5b2bf1076c6d4bed2a95f1057253dd521b664 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wenyou Yangc64a75a2015-10-30 09:55:52 +08002/*
3 * Copyright (C) 2015 Atmel Corporation
4 * Wenyou.Yang <wenyou.yang@atmel.com>
Wenyou Yangc64a75a2015-10-30 09:55:52 +08005 */
6
Wenyou Yang113e1d12016-10-17 09:55:26 +08007#include <debug_uart.h>
Simon Glassa7b51302019-11-14 12:57:46 -07008#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Wenyou Yangc64a75a2015-10-30 09:55:52 +080010#include <asm/io.h>
11#include <asm/arch/at91_common.h>
Wenyou Yangc64a75a2015-10-30 09:55:52 +080012#include <asm/arch/atmel_pio4.h>
Wenyou Yang3acd9cc2016-02-01 18:18:21 +080013#include <asm/arch/atmel_mpddrc.h>
Wenyou Yangc64a75a2015-10-30 09:55:52 +080014#include <asm/arch/atmel_sdhci.h>
15#include <asm/arch/clk.h>
16#include <asm/arch/gpio.h>
17#include <asm/arch/sama5d2.h>
18
Eugen Hristev0c9ffe32018-09-18 10:35:43 +030019extern void at91_pda_detect(void);
20
Wenyou Yangc64a75a2015-10-30 09:55:52 +080021DECLARE_GLOBAL_DATA_PTR;
22
Mihai Sainca453022022-03-07 11:20:50 +020023static void rgb_leds_init(void)
24{
25 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 6, 1); /* LED RED */
26 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 5, 1); /* LED GREEN */
27 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 0, 0); /* LED BLUE */
28}
29
Josef Lustickya0f2af32020-04-17 09:32:25 +020030#ifdef CONFIG_CMD_USB
Wenyou Yangc64a75a2015-10-30 09:55:52 +080031static void board_usb_hw_init(void)
32{
33 atmel_pio4_set_pio_output(AT91_PIO_PORTB, 10, 1);
34}
Josef Lustickya0f2af32020-04-17 09:32:25 +020035#endif
Wenyou Yangc64a75a2015-10-30 09:55:52 +080036
Wenyou Yang3ec18a62017-09-18 15:25:57 +080037#ifdef CONFIG_BOARD_LATE_INIT
38int board_late_init(void)
Wenyou Yangc64a75a2015-10-30 09:55:52 +080039{
Simon Glass52cb5042022-10-18 07:46:31 -060040#ifdef CONFIG_VIDEO
Wenyou Yang3ec18a62017-09-18 15:25:57 +080041 at91_video_show_board_info();
42#endif
Eugen Hristev0c9ffe32018-09-18 10:35:43 +030043 at91_pda_detect();
Wenyou Yang3ec18a62017-09-18 15:25:57 +080044 return 0;
Wenyou Yangc64a75a2015-10-30 09:55:52 +080045}
Wenyou Yang3ec18a62017-09-18 15:25:57 +080046#endif
Wenyou Yangc64a75a2015-10-30 09:55:52 +080047
Wenyou Yang4b1fa802017-03-23 14:26:26 +080048#ifdef CONFIG_DEBUG_UART_BOARD_INIT
Wenyou Yangc64a75a2015-10-30 09:55:52 +080049static void board_uart1_hw_init(void)
50{
Ludovic Desroches86504912018-04-24 10:16:01 +030051 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 2, ATMEL_PIO_PUEN_MASK); /* URXD1 */
Wenyou Yangc64a75a2015-10-30 09:55:52 +080052 atmel_pio4_set_a_periph(AT91_PIO_PORTD, 3, 0); /* UTXD1 */
53
54 at91_periph_clk_enable(ATMEL_ID_UART1);
55}
56
Wenyou Yang113e1d12016-10-17 09:55:26 +080057void board_debug_uart_init(void)
58{
59 board_uart1_hw_init();
60}
61#endif
62
63#ifdef CONFIG_BOARD_EARLY_INIT_F
Wenyou Yangc64a75a2015-10-30 09:55:52 +080064int board_early_init_f(void)
65{
Wenyou Yangc64a75a2015-10-30 09:55:52 +080066 return 0;
67}
Wenyou Yang113e1d12016-10-17 09:55:26 +080068#endif
Wenyou Yangc64a75a2015-10-30 09:55:52 +080069
70int board_init(void)
71{
72 /* address of boot parameters */
Clément Légerd8842642021-08-16 14:25:42 +020073 gd->bd->bi_boot_params = gd->bd->bi_dram[0].start + 0x100;
Wenyou Yangc64a75a2015-10-30 09:55:52 +080074
Mihai Sainca453022022-03-07 11:20:50 +020075 rgb_leds_init();
76
Wenyou Yangc64a75a2015-10-30 09:55:52 +080077#ifdef CONFIG_CMD_USB
78 board_usb_hw_init();
79#endif
Wenyou Yangc64a75a2015-10-30 09:55:52 +080080
81 return 0;
82}
83
Clément Légerd8842642021-08-16 14:25:42 +020084int dram_init_banksize(void)
85{
86 return fdtdec_setup_memory_banksize();
87}
88
Wenyou Yangc64a75a2015-10-30 09:55:52 +080089int dram_init(void)
90{
Clément Légerd8842642021-08-16 14:25:42 +020091 return fdtdec_setup_mem_size_base();
Wenyou Yangc64a75a2015-10-30 09:55:52 +080092}
93
Wenyou Yanga1e24ec2017-09-01 16:26:17 +080094#define AT24MAC_MAC_OFFSET 0x9a
Wenyou Yang3ce80fa2016-10-17 09:55:25 +080095
96#ifdef CONFIG_MISC_INIT_R
97int misc_init_r(void)
98{
Wenyou Yanga1e24ec2017-09-01 16:26:17 +080099#ifdef CONFIG_I2C_EEPROM
100 at91_set_ethaddr(AT24MAC_MAC_OFFSET);
101#endif
Wenyou Yang3ce80fa2016-10-17 09:55:25 +0800102
103 return 0;
104}
105#endif
106
Wenyou Yang3acd9cc2016-02-01 18:18:21 +0800107/* SPL */
Simon Glass49c24a82024-09-29 19:49:47 -0600108#ifdef CONFIG_XPL_BUILD
Wenyou Yang3acd9cc2016-02-01 18:18:21 +0800109void spl_board_init(void)
110{
Wenyou Yang3acd9cc2016-02-01 18:18:21 +0800111}
112
113static void ddrc_conf(struct atmel_mpddrc_config *ddrc)
114{
115 ddrc->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR3_SDRAM);
116
117 ddrc->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
118 ATMEL_MPDDRC_CR_NR_ROW_14 |
119 ATMEL_MPDDRC_CR_CAS_DDR_CAS5 |
120 ATMEL_MPDDRC_CR_DIC_DS |
121 ATMEL_MPDDRC_CR_DIS_DLL |
122 ATMEL_MPDDRC_CR_NB_8BANKS |
123 ATMEL_MPDDRC_CR_DECOD_INTERLEAVED |
124 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
125
126 ddrc->rtr = 0x511;
127
128 ddrc->tpr0 = (6 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
129 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
130 4 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
131 9 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
132 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
133 4 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
134 4 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
135 4 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
136
137 ddrc->tpr1 = (27 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET |
138 29 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
139 0 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
140 3 << ATMEL_MPDDRC_TPR1_TXP_OFFSET);
141
142 ddrc->tpr2 = (0 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET |
143 0 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
144 0 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
145 4 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
146 7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET);
147}
148
Jerome Forissierab4e2532024-09-11 11:58:16 +0200149void at91_mem_init(void)
Wenyou Yang3acd9cc2016-02-01 18:18:21 +0800150{
151 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
152 struct atmel_mpddr *mpddrc = (struct atmel_mpddr *)ATMEL_BASE_MPDDRC;
153 struct atmel_mpddrc_config ddrc_config;
154 u32 reg;
155
156 ddrc_conf(&ddrc_config);
157
158 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
159 writel(AT91_PMC_DDR, &pmc->scer);
160
161 reg = readl(&mpddrc->io_calibr);
162 reg &= ~ATMEL_MPDDRC_IO_CALIBR_RDIV;
163 reg |= ATMEL_MPDDRC_IO_CALIBR_DDR3_RZQ_55;
164 reg &= ~ATMEL_MPDDRC_IO_CALIBR_TZQIO;
165 reg |= ATMEL_MPDDRC_IO_CALIBR_TZQIO_(100);
166 writel(reg, &mpddrc->io_calibr);
167
168 writel(ATMEL_MPDDRC_RD_DATA_PATH_SHIFT_TWO_CYCLE,
169 &mpddrc->rd_data_path);
170
171 ddr3_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddrc_config);
172
173 writel(0x3, &mpddrc->cal_mr4);
174 writel(64, &mpddrc->tim_cal);
175}
176
177void at91_pmc_init(void)
178{
179 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
180 u32 tmp;
181
Wenyou Yang8344ebd2017-09-13 14:58:50 +0800182 /*
183 * while coming from the ROM code, we run on PLLA @ 492 MHz / 164 MHz
184 * so we need to slow down and configure MCKR accordingly.
185 * This is why we have a special flavor of the switching function.
186 */
187 tmp = AT91_PMC_MCKR_PLLADIV_2 |
188 AT91_PMC_MCKR_MDIV_3 |
189 AT91_PMC_MCKR_CSS_MAIN;
190 at91_mck_init_down(tmp);
191
Wenyou Yang3acd9cc2016-02-01 18:18:21 +0800192 tmp = AT91_PMC_PLLAR_29 |
193 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
194 AT91_PMC_PLLXR_MUL(82) |
195 AT91_PMC_PLLXR_DIV(1);
196 at91_plla_init(tmp);
197
198 writel(0x0 << 8, &pmc->pllicpr);
199
200 tmp = AT91_PMC_MCKR_H32MXDIV |
201 AT91_PMC_MCKR_PLLADIV_2 |
202 AT91_PMC_MCKR_MDIV_3 |
203 AT91_PMC_MCKR_CSS_PLLA;
204 at91_mck_init(tmp);
205}
206#endif