2 * Copyright (C) 2015 Marek Vasut <marex@denx.de>
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/at91_common.h>
10 #include <asm/arch/at91_pmc.h>
11 #include <asm/arch/at91_rstc.h>
12 #include <asm/arch/atmel_mpddrc.h>
13 #include <asm/arch/atmel_usba_udc.h>
14 #include <asm/arch/gpio.h>
15 #include <asm/arch/clk.h>
16 #include <asm/arch/sama5d3_smc.h>
17 #include <asm/arch/sama5d4.h>
18 #include <atmel_hlcdc.h>
19 #include <atmel_mci.h>
25 #include <spi_flash.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 static u8 boot_mode_sf;
33 /* FIXME gpio code here need to handle through DM_GPIO */
35 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
37 return bus == 0 && cs == 0;
40 void spi_cs_activate(struct spi_slave *slave)
42 at91_set_pio_output(AT91_PIO_PORTC, 3, 0);
45 void spi_cs_deactivate(struct spi_slave *slave)
47 at91_set_pio_output(AT91_PIO_PORTC, 3, 1);
50 static void ma5d4evk_spi0_hw_init(void)
52 at91_pio3_set_a_periph(AT91_PIO_PORTC, 0, 0); /* SPI0_MISO */
53 at91_pio3_set_a_periph(AT91_PIO_PORTC, 1, 0); /* SPI0_MOSI */
54 at91_pio3_set_a_periph(AT91_PIO_PORTC, 2, 0); /* SPI0_SPCK */
56 at91_set_pio_output(AT91_PIO_PORTC, 3, 1); /* SPI0_CS0 */
59 at91_periph_clk_enable(ATMEL_ID_SPI0);
61 #endif /* CONFIG_DM_SPI */
64 static void ma5d4evk_usb_hw_init(void)
66 at91_set_pio_output(AT91_PIO_PORTE, 11, 0);
67 at91_set_pio_output(AT91_PIO_PORTE, 14, 0);
72 vidinfo_t panel_info = {
80 .vl_right_margin = 164,
82 .vl_upper_margin = 23,
83 .vl_lower_margin = 10,
84 .mmio = ATMEL_BASE_LCDC,
87 /* No power up/down pin for the LCD pannel */
88 void lcd_enable(void) { /* Empty! */ }
89 void lcd_disable(void) { /* Empty! */ }
91 unsigned int has_lcdc(void)
96 static void ma5d4evk_lcd_hw_init(void)
98 at91_pio3_set_a_periph(AT91_PIO_PORTA, 24, 1); /* LCDPWM */
99 at91_pio3_set_a_periph(AT91_PIO_PORTA, 25, 0); /* LCDDISP */
100 at91_pio3_set_a_periph(AT91_PIO_PORTA, 26, 0); /* LCDVSYNC */
101 at91_pio3_set_a_periph(AT91_PIO_PORTA, 27, 0); /* LCDHSYNC */
102 at91_pio3_set_a_periph(AT91_PIO_PORTA, 28, 0); /* LCDDOTCK */
103 at91_pio3_set_a_periph(AT91_PIO_PORTA, 29, 1); /* LCDDEN */
105 at91_pio3_set_a_periph(AT91_PIO_PORTA, 0, 0); /* LCDD0 */
106 at91_pio3_set_a_periph(AT91_PIO_PORTA, 1, 0); /* LCDD1 */
107 at91_pio3_set_a_periph(AT91_PIO_PORTA, 2, 0); /* LCDD2 */
108 at91_pio3_set_a_periph(AT91_PIO_PORTA, 3, 0); /* LCDD3 */
109 at91_pio3_set_a_periph(AT91_PIO_PORTA, 4, 0); /* LCDD4 */
110 at91_pio3_set_a_periph(AT91_PIO_PORTA, 5, 0); /* LCDD5 */
111 at91_pio3_set_a_periph(AT91_PIO_PORTA, 6, 0); /* LCDD6 */
112 at91_pio3_set_a_periph(AT91_PIO_PORTA, 7, 0); /* LCDD7 */
114 at91_pio3_set_a_periph(AT91_PIO_PORTA, 8, 0); /* LCDD9 */
115 at91_pio3_set_a_periph(AT91_PIO_PORTA, 9, 0); /* LCDD8 */
116 at91_pio3_set_a_periph(AT91_PIO_PORTA, 10, 0); /* LCDD10 */
117 at91_pio3_set_a_periph(AT91_PIO_PORTA, 11, 0); /* LCDD11 */
118 at91_pio3_set_a_periph(AT91_PIO_PORTA, 12, 0); /* LCDD12 */
119 at91_pio3_set_a_periph(AT91_PIO_PORTA, 13, 0); /* LCDD13 */
120 at91_pio3_set_a_periph(AT91_PIO_PORTA, 14, 0); /* LCDD14 */
121 at91_pio3_set_a_periph(AT91_PIO_PORTA, 15, 0); /* LCDD15 */
123 at91_pio3_set_a_periph(AT91_PIO_PORTA, 16, 0); /* LCDD16 */
124 at91_pio3_set_a_periph(AT91_PIO_PORTA, 17, 0); /* LCDD17 */
125 at91_pio3_set_a_periph(AT91_PIO_PORTA, 18, 0); /* LCDD18 */
126 at91_pio3_set_a_periph(AT91_PIO_PORTA, 19, 0); /* LCDD19 */
127 at91_pio3_set_a_periph(AT91_PIO_PORTA, 20, 0); /* LCDD20 */
128 at91_pio3_set_a_periph(AT91_PIO_PORTA, 21, 0); /* LCDD21 */
129 at91_pio3_set_a_periph(AT91_PIO_PORTA, 22, 0); /* LCDD22 */
130 at91_pio3_set_a_periph(AT91_PIO_PORTA, 23, 0); /* LCDD23 */
133 at91_periph_clk_enable(ATMEL_ID_LCDC);
136 #endif /* CONFIG_LCD */
138 #ifdef CONFIG_GENERIC_ATMEL_MCI
140 void ma5d4evk_mci0_hw_init(void)
142 at91_pio3_set_b_periph(AT91_PIO_PORTC, 5, 1); /* MCI1 CDA */
143 at91_pio3_set_b_periph(AT91_PIO_PORTC, 6, 1); /* MCI1 DA0 */
144 at91_pio3_set_b_periph(AT91_PIO_PORTC, 7, 1); /* MCI1 DA1 */
145 at91_pio3_set_b_periph(AT91_PIO_PORTC, 8, 1); /* MCI1 DA2 */
146 at91_pio3_set_b_periph(AT91_PIO_PORTC, 9, 1); /* MCI1 DA3 */
147 at91_pio3_set_b_periph(AT91_PIO_PORTC, 10, 1); /* MCI1 DA4 */
148 at91_pio3_set_b_periph(AT91_PIO_PORTC, 11, 1); /* MCI1 DA5 */
149 at91_pio3_set_b_periph(AT91_PIO_PORTC, 12, 1); /* MCI1 DA6 */
150 at91_pio3_set_b_periph(AT91_PIO_PORTC, 13, 1); /* MCI1 DA7 */
151 at91_pio3_set_b_periph(AT91_PIO_PORTC, 4, 0); /* MCI1 CLK */
154 * As the mci io internal pull down is too strong, so if the io needs
155 * external pull up, the pull up resistor will be very small, if so
156 * the power consumption will increase, so disable the internal pull
157 * down to save the power.
159 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 5, 0);
160 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 6, 0);
161 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 7, 0);
162 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 8, 0);
163 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 9, 0);
164 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 10, 0);
165 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 11, 0);
166 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 12, 0);
167 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 13, 0);
168 at91_pio3_set_pio_pulldown(AT91_PIO_PORTC, 4, 0);
171 at91_periph_clk_enable(ATMEL_ID_MCI0);
174 /* On-board MicroSD slot */
175 void ma5d4evk_mci1_hw_init(void)
177 at91_pio3_set_c_periph(AT91_PIO_PORTE, 19, 1); /* MCI1 CDA */
178 at91_pio3_set_c_periph(AT91_PIO_PORTE, 20, 1); /* MCI1 DA0 */
179 at91_pio3_set_c_periph(AT91_PIO_PORTE, 21, 1); /* MCI1 DA1 */
180 at91_pio3_set_c_periph(AT91_PIO_PORTE, 22, 1); /* MCI1 DA2 */
181 at91_pio3_set_c_periph(AT91_PIO_PORTE, 23, 1); /* MCI1 DA3 */
182 at91_pio3_set_c_periph(AT91_PIO_PORTE, 18, 0); /* MCI1 CLK */
185 * As the mci io internal pull down is too strong, so if the io needs
186 * external pull up, the pull up resistor will be very small, if so
187 * the power consumption will increase, so disable the internal pull
188 * down to save the power.
190 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 18, 0);
191 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 19, 0);
192 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 20, 0);
193 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 21, 0);
194 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 22, 0);
195 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 23, 0);
197 /* Deal with WP pin on the microSD slot. */
198 at91_set_pio_output(AT91_PIO_PORTE, 16, 0);
199 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 16, 1);
202 at91_periph_clk_enable(ATMEL_ID_MCI1);
205 int board_mmc_init(bd_t *bis)
208 void *mci0 = (void *)ATMEL_BASE_MCI0;
209 void *mci1 = (void *)ATMEL_BASE_MCI1;
211 /* De-assert reset on On-SoM eMMC */
212 at91_set_pio_output(AT91_PIO_PORTE, 15, 1);
213 at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 15, 0);
215 ret = atmel_mci_init(boot_mode_sf ? mci0 : mci1);
216 if (ret) /* eMMC init failed, skip it. */
217 at91_set_pio_output(AT91_PIO_PORTE, 15, 0);
219 /* Enable the power supply to On-board MicroSD */
220 at91_set_pio_output(AT91_PIO_PORTE, 17, 0);
221 ret = atmel_mci_init(boot_mode_sf ? mci1 : mci0);
222 if (ret) /* uSD init failed, power it down. */
223 at91_set_pio_output(AT91_PIO_PORTE, 17, 1);
227 #endif /* CONFIG_GENERIC_ATMEL_MCI */
230 void ma5d4evk_macb0_hw_init(void)
232 at91_pio3_set_a_periph(AT91_PIO_PORTB, 0, 0); /* ETXCK_EREFCK */
233 at91_pio3_set_a_periph(AT91_PIO_PORTB, 6, 0); /* ERXDV */
234 at91_pio3_set_a_periph(AT91_PIO_PORTB, 8, 0); /* ERX0 */
235 at91_pio3_set_a_periph(AT91_PIO_PORTB, 9, 0); /* ERX1 */
236 at91_pio3_set_a_periph(AT91_PIO_PORTB, 7, 0); /* ERXER */
237 at91_pio3_set_a_periph(AT91_PIO_PORTB, 2, 0); /* ETXEN */
238 at91_pio3_set_a_periph(AT91_PIO_PORTB, 12, 0); /* ETX0 */
239 at91_pio3_set_a_periph(AT91_PIO_PORTB, 13, 0); /* ETX1 */
240 at91_pio3_set_a_periph(AT91_PIO_PORTB, 17, 0); /* EMDIO */
241 at91_pio3_set_a_periph(AT91_PIO_PORTB, 16, 0); /* EMDC */
244 at91_periph_clk_enable(ATMEL_ID_GMAC0);
248 static void ma5d4evk_serial_hw_init(void)
251 at91_pio3_set_a_periph(AT91_PIO_PORTD, 13, 1); /* TXD */
252 at91_pio3_set_a_periph(AT91_PIO_PORTD, 12, 0); /* RXD */
253 at91_pio3_set_a_periph(AT91_PIO_PORTD, 11, 0); /* RTS */
254 at91_pio3_set_a_periph(AT91_PIO_PORTD, 10, 0); /* CTS */
255 at91_periph_clk_enable(ATMEL_ID_USART0);
258 at91_pio3_set_a_periph(AT91_PIO_PORTD, 17, 1); /* TXD */
259 at91_pio3_set_a_periph(AT91_PIO_PORTD, 16, 0); /* RXD */
260 at91_pio3_set_a_periph(AT91_PIO_PORTD, 15, 0); /* RTS */
261 at91_pio3_set_a_periph(AT91_PIO_PORTD, 14, 0); /* CTS */
262 at91_periph_clk_enable(ATMEL_ID_USART1);
265 int board_early_init_f(void)
267 at91_periph_clk_enable(ATMEL_ID_PIOA);
268 at91_periph_clk_enable(ATMEL_ID_PIOB);
269 at91_periph_clk_enable(ATMEL_ID_PIOC);
270 at91_periph_clk_enable(ATMEL_ID_PIOD);
271 at91_periph_clk_enable(ATMEL_ID_PIOE);
273 /* Configure LEDs as OFF */
274 at91_set_pio_output(AT91_PIO_PORTD, 28, 0);
275 at91_set_pio_output(AT91_PIO_PORTD, 29, 0);
276 at91_set_pio_output(AT91_PIO_PORTD, 30, 0);
278 ma5d4evk_serial_hw_init();
283 static void board_identify(void)
285 struct spi_flash *sf;
286 sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
287 CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
288 boot_mode_sf = (sf != NULL);
293 /* adress of boot parameters */
294 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
296 #ifndef CONFIG_DM_SPI
297 ma5d4evk_spi0_hw_init();
299 #ifdef CONFIG_GENERIC_ATMEL_MCI
300 ma5d4evk_mci0_hw_init();
301 ma5d4evk_mci1_hw_init();
304 ma5d4evk_macb0_hw_init();
307 ma5d4evk_lcd_hw_init();
309 #ifdef CONFIG_CMD_USB
310 ma5d4evk_usb_hw_init();
312 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
318 /* Reset CAN controllers */
319 at91_set_pio_output(AT91_PIO_PORTB, 21, 0);
321 at91_set_pio_output(AT91_PIO_PORTB, 21, 1);
322 at91_pio3_set_pio_pulldown(AT91_PIO_PORTB, 21, 0);
327 int board_late_init(void)
329 env_set("bootmode", boot_mode_sf ? "sf" : "emmc");
335 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
336 CONFIG_SYS_SDRAM_SIZE);
340 int board_eth_init(bd_t *bis)
345 rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC0, 0x00);
348 #ifdef CONFIG_USB_GADGET_ATMEL_USBA
349 usba_udc_probe(&pdata);
350 #ifdef CONFIG_USB_ETH_RNDIS
351 usb_eth_initialize(bis);
359 #ifdef CONFIG_SPL_BUILD
360 void spl_board_init(void)
362 #ifndef CONFIG_DM_SPI
363 ma5d4evk_spi0_hw_init();
365 #ifdef CONFIG_GENERIC_ATMEL_MCI
366 ma5d4evk_mci0_hw_init();
367 ma5d4evk_mci1_hw_init();
372 void board_boot_order(u32 *spl_boot_list)
374 spl_boot_list[0] = spl_boot_device();
376 switch (spl_boot_list[0]) {
377 case BOOT_DEVICE_MMC1:
378 case BOOT_DEVICE_MMC2:
379 spl_boot_list[0] = BOOT_DEVICE_MMC1;
381 case BOOT_DEVICE_SPI:
383 case BOOT_DEVICE_USB:
384 spl_boot_list[0] = BOOT_DEVICE_MMC2;
389 static void ddr2_conf(struct atmel_mpddrc_config *ddr2)
391 ddr2->md = (ATMEL_MPDDRC_MD_DBW_32_BITS | ATMEL_MPDDRC_MD_DDR2_SDRAM);
393 ddr2->cr = (ATMEL_MPDDRC_CR_NC_COL_10 |
394 ATMEL_MPDDRC_CR_NR_ROW_13 |
395 ATMEL_MPDDRC_CR_CAS_DDR_CAS3 |
396 ATMEL_MPDDRC_CR_NB_8BANKS |
397 ATMEL_MPDDRC_CR_NDQS_DISABLED |
398 ATMEL_MPDDRC_CR_UNAL_SUPPORTED);
402 ddr2->tpr0 = (8 << ATMEL_MPDDRC_TPR0_TRAS_OFFSET |
403 3 << ATMEL_MPDDRC_TPR0_TRCD_OFFSET |
404 3 << ATMEL_MPDDRC_TPR0_TWR_OFFSET |
405 10 << ATMEL_MPDDRC_TPR0_TRC_OFFSET |
406 3 << ATMEL_MPDDRC_TPR0_TRP_OFFSET |
407 2 << ATMEL_MPDDRC_TPR0_TRRD_OFFSET |
408 2 << ATMEL_MPDDRC_TPR0_TWTR_OFFSET |
409 2 << ATMEL_MPDDRC_TPR0_TMRD_OFFSET);
411 ddr2->tpr1 = (2 << ATMEL_MPDDRC_TPR1_TXP_OFFSET |
412 200 << ATMEL_MPDDRC_TPR1_TXSRD_OFFSET |
413 25 << ATMEL_MPDDRC_TPR1_TXSNR_OFFSET |
414 23 << ATMEL_MPDDRC_TPR1_TRFC_OFFSET);
416 ddr2->tpr2 = (7 << ATMEL_MPDDRC_TPR2_TFAW_OFFSET |
417 2 << ATMEL_MPDDRC_TPR2_TRTP_OFFSET |
418 3 << ATMEL_MPDDRC_TPR2_TRPA_OFFSET |
419 2 << ATMEL_MPDDRC_TPR2_TXARDS_OFFSET |
420 8 << ATMEL_MPDDRC_TPR2_TXARD_OFFSET);
425 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
426 struct atmel_mpddrc_config ddr2;
430 /* enable MPDDR clock */
431 at91_periph_clk_enable(ATMEL_ID_MPDDRC);
432 writel(AT91_PMC_DDR, &pmc->scer);
434 /* DDRAM2 Controller initialize */
435 ddr2_init(ATMEL_BASE_MPDDRC, ATMEL_BASE_DDRCS, &ddr2);
438 void at91_pmc_init(void)
440 struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
443 tmp = AT91_PMC_PLLAR_29 |
444 AT91_PMC_PLLXR_PLLCOUNT(0x3f) |
445 AT91_PMC_PLLXR_MUL(87) |
446 AT91_PMC_PLLXR_DIV(1);
449 writel(0x0 << 8, &pmc->pllicpr);
451 tmp = AT91_PMC_MCKR_H32MXDIV |
452 AT91_PMC_MCKR_PLLADIV_2 |
453 AT91_PMC_MCKR_MDIV_3 |
454 AT91_PMC_MCKR_CSS_PLLA;