]> git.sur5r.net Git - u-boot/blobdiff - board/aries/ma5d4evk/ma5d4evk.c
Merge branch 'master' of git://git.denx.de/u-boot-spi
[u-boot] / board / aries / ma5d4evk / ma5d4evk.c
index 0293b29d0ea628784e87ed5515d70c293f59a78a..c2b6845edc9ca16319fad733183dcf09d09ff18a 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2015 Marek Vasut <marex@denx.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <net.h>
 #include <netdev.h>
 #include <spi.h>
+#include <spi_flash.h>
+#include <spl.h>
 #include <version.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#ifdef CONFIG_ATMEL_SPI
+static u8 boot_mode_sf;
+
+/* FIXME gpio code here need to handle through DM_GPIO */
+#ifndef CONFIG_DM_SPI
 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
 {
        return bus == 0 && cs == 0;
@@ -53,7 +57,7 @@ static void ma5d4evk_spi0_hw_init(void)
        /* Enable clock */
        at91_periph_clk_enable(ATMEL_ID_SPI0);
 }
-#endif /* CONFIG_ATMEL_SPI */
+#endif /* CONFIG_DM_SPI */
 
 #ifdef CONFIG_CMD_USB
 static void ma5d4evk_usb_hw_init(void)
@@ -200,18 +204,20 @@ void ma5d4evk_mci1_hw_init(void)
 int board_mmc_init(bd_t *bis)
 {
        int ret;
+       void *mci0 = (void *)ATMEL_BASE_MCI0;
+       void *mci1 = (void *)ATMEL_BASE_MCI1;
 
        /* De-assert reset on On-SoM eMMC */
        at91_set_pio_output(AT91_PIO_PORTE, 15, 1);
        at91_pio3_set_pio_pulldown(AT91_PIO_PORTE, 15, 0);
 
-       ret = atmel_mci_init((void *)ATMEL_BASE_MCI1);
+       ret = atmel_mci_init(boot_mode_sf ? mci0 : mci1);
        if (ret)        /* eMMC init failed, skip it. */
                at91_set_pio_output(AT91_PIO_PORTE, 15, 0);
 
        /* Enable the power supply to On-board MicroSD */
        at91_set_pio_output(AT91_PIO_PORTE, 17, 0);
-       ret = atmel_mci_init((void *)ATMEL_BASE_MCI0);
+       ret = atmel_mci_init(boot_mode_sf ? mci1 : mci0);
        if (ret)        /* uSD init failed, power it down. */
                at91_set_pio_output(AT91_PIO_PORTE, 17, 1);
 
@@ -273,12 +279,20 @@ int board_early_init_f(void)
        return 0;
 }
 
+static void board_identify(void)
+{
+       struct spi_flash *sf;
+       sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
+                            CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
+       boot_mode_sf = (sf != NULL);
+}
+
 int board_init(void)
 {
        /* adress of boot parameters */
        gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
 
-#ifdef CONFIG_ATMEL_SPI
+#ifndef CONFIG_DM_SPI
        ma5d4evk_spi0_hw_init();
 #endif
 #ifdef CONFIG_GENERIC_ATMEL_MCI
@@ -298,6 +312,8 @@ int board_init(void)
        at91_udp_hw_init();
 #endif
 
+       board_identify();
+
        /* Reset CAN controllers */
        at91_set_pio_output(AT91_PIO_PORTB, 21, 0);
        udelay(100);
@@ -307,6 +323,12 @@ int board_init(void)
        return 0;
 }
 
+int board_late_init(void)
+{
+       env_set("bootmode", boot_mode_sf ? "sf" : "emmc");
+       return 0;
+}
+
 int dram_init(void)
 {
        gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
@@ -336,13 +358,31 @@ int board_eth_init(bd_t *bis)
 #ifdef CONFIG_SPL_BUILD
 void spl_board_init(void)
 {
-#ifdef CONFIG_ATMEL_SPI
+#ifndef CONFIG_DM_SPI
        ma5d4evk_spi0_hw_init();
 #endif
 #ifdef CONFIG_GENERIC_ATMEL_MCI
        ma5d4evk_mci0_hw_init();
        ma5d4evk_mci1_hw_init();
 #endif
+       board_identify();
+}
+
+void board_boot_order(u32 *spl_boot_list)
+{
+       spl_boot_list[0] = spl_boot_device();
+
+       switch (spl_boot_list[0]) {
+       case BOOT_DEVICE_MMC1:
+       case BOOT_DEVICE_MMC2:
+               spl_boot_list[0] = BOOT_DEVICE_MMC1;
+               break;
+       case BOOT_DEVICE_SPI:
+               break;
+       case BOOT_DEVICE_USB:
+               spl_boot_list[0] = BOOT_DEVICE_MMC2;
+               break;
+       }
 }
 
 static void ddr2_conf(struct atmel_mpddrc_config *ddr2)