]> git.sur5r.net Git - u-boot/blobdiff - board/st-ericsson/snowball/snowball.c
Merge branch 'master' of git://git.denx.de/u-boot-blackfin
[u-boot] / board / st-ericsson / snowball / snowball.c
index 4bcc649724b65ae22a36f8031353aed0f6fb8186..c3061e20d95d4f7eb15e20c60d5f9b2abbbbe4a8 100644 (file)
@@ -1,19 +1,7 @@
 /*
  * Copyright (C) ST-Ericsson SA 2009
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
 #include <asm/io.h>
 #include <asm/errno.h>
 #include <asm/arch/db8500_pincfg.h>
+#include <asm/arch/prcmu.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/sys_proto.h>
 
+#ifdef CONFIG_MMC
+#include "../../../drivers/mmc/arm_pl180_mmci.h"
+#endif
 #include "db8500_pins.h"
 
 /*
@@ -164,3 +158,183 @@ int dram_init(void)
 
        return 0;
 }
+
+static int raise_ab8500_gpio16(void)
+{
+       int ret;
+
+       /* selection */
+       ret = ab8500_read(AB8500_MISC, AB8500_GPIO_SEL2_REG);
+       if (ret < 0)
+               goto out;
+
+       ret |= 0x80;
+       ret = ab8500_write(AB8500_MISC, AB8500_GPIO_SEL2_REG, ret);
+       if (ret < 0)
+               goto out;
+
+       /* direction */
+       ret = ab8500_read(AB8500_MISC, AB8500_GPIO_DIR2_REG);
+       if (ret < 0)
+               goto out;
+
+       ret |= 0x80;
+       ret = ab8500_write(AB8500_MISC, AB8500_GPIO_DIR2_REG, ret);
+       if (ret < 0)
+               goto out;
+
+       /* out */
+       ret = ab8500_read(AB8500_MISC, AB8500_GPIO_OUT2_REG);
+       if (ret < 0)
+               goto out;
+
+       ret |= 0x80;
+       ret = ab8500_write(AB8500_MISC, AB8500_GPIO_OUT2_REG, ret);
+
+out:
+       return ret;
+}
+
+static int raise_ab8500_gpio26(void)
+{
+       int ret;
+
+       /* selection */
+       ret = ab8500_read(AB8500_MISC, AB8500_GPIO_DIR4_REG);
+       if (ret < 0)
+               goto out;
+
+       ret |= 0x2;
+       ret = ab8500_write(AB8500_MISC, AB8500_GPIO_DIR4_REG, ret);
+       if (ret < 0)
+               goto out;
+
+       /* out */
+       ret = ab8500_read(AB8500_MISC, AB8500_GPIO_OUT4_REG);
+       if (ret < 0)
+               goto out;
+
+       ret |= 0x2;
+       ret = ab8500_write(AB8500_MISC, AB8500_GPIO_OUT4_REG, ret);
+
+out:
+       return ret;
+}
+
+int board_late_init(void)
+{
+       /* enable 3V3 for LAN controller */
+       if (raise_ab8500_gpio26() >= 0) {
+               /* Turn on FSMC device */
+               writel(0x1, 0x8000f000);
+               writel(0x1, 0x8000f008);
+
+               /* setup FSMC for LAN controler */
+               writel(0x305b, 0x80000000);
+
+               /* run at the highest possible speed */
+               writel(0x01010210, 0x80000004);
+       } else
+               printf("error: can't raise GPIO26\n");
+
+       /* enable 3v6 for GBF chip */
+       if ((raise_ab8500_gpio16() < 0))
+               printf("error: cant' raise GPIO16\n");
+
+       /* empty UART RX FIFO */
+       while (tstc())
+               (void) getc();
+
+       return 0;
+}
+
+#ifdef CONFIG_MMC
+/*
+ * emmc_host_init - initialize the emmc controller.
+ * Configure GPIO settings, set initial clock and power for emmc slot.
+ * Initialize mmc struct and register with mmc framework.
+ */
+static int emmc_host_init(void)
+{
+       struct pl180_mmc_host *host;
+
+       host = malloc(sizeof(struct pl180_mmc_host));
+       if (!host)
+               return -ENOMEM;
+       memset(host, 0, sizeof(*host));
+
+       host->base = (struct sdi_registers *)CFG_EMMC_BASE;
+       host->pwr_init = SDI_PWR_OPD | SDI_PWR_PWRCTRL_ON;
+       host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V2 |
+                                SDI_CLKCR_CLKEN | SDI_CLKCR_HWFC_EN;
+       strcpy(host->name, "EMMC");
+       host->caps = MMC_MODE_8BIT | MMC_MODE_HS | MMC_MODE_HS_52MHz;
+       host->voltages = VOLTAGE_WINDOW_MMC;
+       host->clock_min = ARM_MCLK / (2 + SDI_CLKCR_CLKDIV_INIT_V2);
+       host->clock_max = ARM_MCLK / 2;
+       host->clock_in = ARM_MCLK;
+       host->version2 = 1;
+
+       return arm_pl180_mmci_init(host);
+}
+
+/*
+ * mmc_host_init - initialize the external mmc controller.
+ * Configure GPIO settings, set initial clock and power for mmc slot.
+ * Initialize mmc struct and register with mmc framework.
+ */
+static int mmc_host_init(void)
+{
+       struct pl180_mmc_host *host;
+       u32 sdi_u32;
+
+       host = malloc(sizeof(struct pl180_mmc_host));
+       if (!host)
+               return -ENOMEM;
+       memset(host, 0, sizeof(*host));
+
+       host->base = (struct sdi_registers *)CFG_MMC_BASE;
+       sdi_u32 = 0xBF;
+       writel(sdi_u32, &host->base->power);
+       host->pwr_init = 0xBF;
+       host->clkdiv_init = SDI_CLKCR_CLKDIV_INIT_V2 |
+                                SDI_CLKCR_CLKEN | SDI_CLKCR_HWFC_EN;
+       strcpy(host->name, "MMC");
+       host->caps = MMC_MODE_8BIT;
+       host->b_max = 0;
+       host->voltages = VOLTAGE_WINDOW_SD;
+       host->clock_min = ARM_MCLK / (2 + SDI_CLKCR_CLKDIV_INIT_V2);
+       host->clock_max = ARM_MCLK / 2;
+       host->clock_in = ARM_MCLK;
+       host->version2 = 1;
+
+       return arm_pl180_mmci_init(host);
+}
+
+/*
+ * board_mmc_init - initialize all the mmc/sd host controllers.
+ * Called by generic mmc framework.
+ */
+int board_mmc_init(bd_t *bis)
+{
+       int error;
+
+       (void) bis;
+
+       error = emmc_host_init();
+       if (error) {
+               printf("emmc_host_init() %d\n", error);
+               return -1;
+       }
+
+       u8500_mmc_power_init();
+
+       error = mmc_host_init();
+       if (error) {
+               printf("mmc_host_init() %d\n", error);
+               return -1;
+       }
+
+       return 0;
+}
+#endif /* CONFIG_MMC */