SPDX: Convert all of our single license tags to Linux Kernel style
[platform/kernel/u-boot.git] / board / samsung / odroid / odroid.c
index ac19527..1c2bd01 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2014 Samsung Electronics
  * Przemyslaw Marczak <p.marczak@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <asm/arch/gpio.h>
 #include <asm/gpio.h>
 #include <asm/arch/cpu.h>
+#include <dm.h>
 #include <power/pmic.h>
+#include <power/regulator.h>
 #include <power/max77686_pmic.h>
 #include <errno.h>
+#include <mmc.h>
 #include <usb.h>
-#include <usb/s3c_udc.h>
+#include <usb/dwc2_udc.h>
 #include <samsung/misc.h>
 #include "setup.h"
 
@@ -61,27 +63,29 @@ const char *get_board_type(void)
 #endif
 
 #ifdef CONFIG_SET_DFU_ALT_INFO
-char *get_dfu_alt_system(void)
+char *get_dfu_alt_system(char *interface, char *devstr)
 {
-       return getenv("dfu_alt_system");
+       return env_get("dfu_alt_system");
 }
 
-char *get_dfu_alt_boot(void)
+char *get_dfu_alt_boot(char *interface, char *devstr)
 {
+       struct mmc *mmc;
        char *alt_boot;
+       int dev_num;
+
+       dev_num = simple_strtoul(devstr, NULL, 10);
+
+       mmc = find_mmc_device(dev_num);
+       if (!mmc)
+               return NULL;
+
+       if (mmc_init(mmc))
+               return NULL;
+
+       alt_boot = IS_SD(mmc) ? CONFIG_DFU_ALT_BOOT_SD :
+                               CONFIG_DFU_ALT_BOOT_EMMC;
 
-       switch (get_boot_mode()) {
-       case BOOT_MODE_SD:
-               alt_boot = CONFIG_DFU_ALT_BOOT_SD;
-               break;
-       case BOOT_MODE_EMMC:
-       case BOOT_MODE_EMMC_SD:
-               alt_boot = CONFIG_DFU_ALT_BOOT_EMMC;
-               break;
-       default:
-               alt_boot = NULL;
-               break;
-       }
        return alt_boot;
 }
 #endif
@@ -158,10 +162,10 @@ static void board_clock_init(void)
         * For MOUThpm = 1000 MHz (MOUTapll)
         * doutcopy = MOUThpm / (ratio + 1) = 200 (4)
         * sclkhpm = doutcopy / (ratio + 1) = 200 (4)
-        * cores_out = armclk / (ratio + 1) = 1000 (0)
+        * cores_out = armclk / (ratio + 1) = 200 (4)
         */
        clr = COPY_RATIO(7) | HPM_RATIO(7) | CORES_RATIO(7);
-       set = COPY_RATIO(4) | HPM_RATIO(4) | CORES_RATIO(0);
+       set = COPY_RATIO(4) | HPM_RATIO(4) | CORES_RATIO(4);
 
        clrsetbits_le32(&clk->div_cpu1, clr, set);
 
@@ -248,12 +252,12 @@ static void board_clock_init(void)
         * MOUTc2c = 800 Mhz
         * MOUTpwi = 108 MHz
         *
-        * sclk_g2d_acp = MOUTg2d / (ratio + 1) = 400 (1)
+        * sclk_g2d_acp = MOUTg2d / (ratio + 1) = 200 (3)
         * sclk_c2c = MOUTc2c / (ratio + 1) = 400 (1)
         * aclk_c2c = sclk_c2c / (ratio + 1) = 200 (1)
         * sclk_pwi = MOUTpwi / (ratio + 1) = 18 (5)
         */
-       set = G2D_ACP_RATIO(1) | C2C_RATIO(1) | PWI_RATIO(5) |
+       set = G2D_ACP_RATIO(3) | C2C_RATIO(1) | PWI_RATIO(5) |
              C2C_ACLK_RATIO(1) | DVSEM_RATIO(1) | DPM_RATIO(1);
 
        clrsetbits_le32(&clk->div_dmc1, clr, set);
@@ -356,74 +360,75 @@ static void board_clock_init(void)
 static void board_gpio_init(void)
 {
        /* eMMC Reset Pin */
+       gpio_request(EXYNOS4X12_GPIO_K12, "eMMC Reset");
+
        gpio_cfg_pin(EXYNOS4X12_GPIO_K12, S5P_GPIO_FUNC(0x1));
        gpio_set_pull(EXYNOS4X12_GPIO_K12, S5P_GPIO_PULL_NONE);
        gpio_set_drv(EXYNOS4X12_GPIO_K12, S5P_GPIO_DRV_4X);
 
        /* Enable FAN (Odroid U3) */
+       gpio_request(EXYNOS4X12_GPIO_D00, "FAN Control");
+
        gpio_set_pull(EXYNOS4X12_GPIO_D00, S5P_GPIO_PULL_UP);
        gpio_set_drv(EXYNOS4X12_GPIO_D00, S5P_GPIO_DRV_4X);
        gpio_direction_output(EXYNOS4X12_GPIO_D00, 1);
 
        /* OTG Vbus output (Odroid U3+) */
+       gpio_request(EXYNOS4X12_GPIO_L20, "OTG Vbus");
+
        gpio_set_pull(EXYNOS4X12_GPIO_L20, S5P_GPIO_PULL_NONE);
        gpio_set_drv(EXYNOS4X12_GPIO_L20, S5P_GPIO_DRV_4X);
        gpio_direction_output(EXYNOS4X12_GPIO_L20, 0);
 
        /* OTG INT (Odroid U3+) */
+       gpio_request(EXYNOS4X12_GPIO_X31, "OTG INT");
+
        gpio_set_pull(EXYNOS4X12_GPIO_X31, S5P_GPIO_PULL_UP);
        gpio_set_drv(EXYNOS4X12_GPIO_X31, S5P_GPIO_DRV_4X);
        gpio_direction_input(EXYNOS4X12_GPIO_X31);
-}
 
-static int pmic_init_max77686(void)
-{
-       struct pmic *p = pmic_get("MAX77686_PMIC");
+       /* Blue LED (Odroid X2/U2/U3) */
+       gpio_request(EXYNOS4X12_GPIO_C10, "Blue LED");
 
-       if (pmic_probe(p))
-               return -ENODEV;
+       gpio_direction_output(EXYNOS4X12_GPIO_C10, 0);
 
-       /* Set LDO Voltage */
-       max77686_set_ldo_voltage(p, 20, 1800000);       /* LDO20 eMMC */
-       max77686_set_ldo_voltage(p, 21, 2800000);       /* LDO21 SD */
-       max77686_set_ldo_voltage(p, 22, 2800000);       /* LDO22 eMMC */
+#ifdef CONFIG_CMD_USB
+       /* USB3503A Reference frequency */
+       gpio_request(EXYNOS4X12_GPIO_X30, "USB3503A RefFreq");
 
-       return 0;
-}
+       /* USB3503A Connect */
+       gpio_request(EXYNOS4X12_GPIO_X34, "USB3503A Connect");
 
-#ifdef CONFIG_SYS_I2C_INIT_BOARD
-static void board_init_i2c(void)
-{
-       /* I2C_0 */
-       if (exynos_pinmux_config(PERIPH_ID_I2C0, PINMUX_FLAG_NONE))
-               debug("I2C%d not configured\n", (I2C_0));
-}
+       /* USB3503A Reset */
+       gpio_request(EXYNOS4X12_GPIO_X35, "USB3503A Reset");
 #endif
+}
 
 int exynos_early_init_f(void)
 {
        board_clock_init();
-       board_gpio_init();
 
        return 0;
 }
 
 int exynos_init(void)
 {
-       /* The last MB of memory is reserved for secure firmware */
-       gd->ram_size -= SZ_1M;
-       gd->bd->bi_dram[CONFIG_NR_DRAM_BANKS - 1].size -= SZ_1M;
+       board_gpio_init();
 
        return 0;
 }
 
 int exynos_power_init(void)
 {
-#ifdef CONFIG_SYS_I2C_INIT_BOARD
-       board_init_i2c();
-#endif
-       pmic_init(I2C_0);
-       pmic_init_max77686();
+       const char *mmc_regulators[] = {
+               "VDDQ_EMMC_1.8V",
+               "VDDQ_EMMC_2.8V",
+               "TFLASH_2.8V",
+               NULL,
+       };
+
+       if (regulator_list_autoset(mmc_regulators, NULL, true))
+               pr_err("Unable to init all mmc regulators");
 
        return 0;
 }
@@ -431,40 +436,79 @@ int exynos_power_init(void)
 #ifdef CONFIG_USB_GADGET
 static int s5pc210_phy_control(int on)
 {
-       struct pmic *p_pmic;
+       struct udevice *dev;
+       int ret;
 
-       p_pmic = pmic_get("MAX77686_PMIC");
-       if (!p_pmic)
-               return -ENODEV;
-
-       if (pmic_probe(p_pmic))
-               return -1;
+       ret = regulator_get_by_platname("VDD_UOTG_3.0V", &dev);
+       if (ret) {
+               pr_err("Regulator get error: %d", ret);
+               return ret;
+       }
 
        if (on)
-               return max77686_set_ldo_mode(p_pmic, 12, OPMODE_ON);
+               return regulator_set_mode(dev, OPMODE_ON);
        else
-               return max77686_set_ldo_mode(p_pmic, 12, OPMODE_LPM);
+               return regulator_set_mode(dev, OPMODE_LPM);
 }
 
-struct s3c_plat_otg_data s5pc210_otg_data = {
+struct dwc2_plat_otg_data s5pc210_otg_data = {
        .phy_control    = s5pc210_phy_control,
        .regs_phy       = EXYNOS4X12_USBPHY_BASE,
        .regs_otg       = EXYNOS4X12_USBOTG_BASE,
        .usb_phy_ctrl   = EXYNOS4X12_USBPHY_CONTROL,
        .usb_flags      = PHY0_SLEEP,
 };
+#endif
+
+#if defined(CONFIG_USB_GADGET) || defined(CONFIG_CMD_USB)
 
 int board_usb_init(int index, enum usb_init_type init)
 {
+#ifdef CONFIG_CMD_USB
+       struct udevice *dev;
+       int ret;
+
+       /* Set Ref freq 0 => 24MHz, 1 => 26MHz*/
+       /* Odroid Us have it at 24MHz, Odroid Xs at 26MHz */
+       if (gd->board_type == ODROID_TYPE_U3)
+               gpio_direction_output(EXYNOS4X12_GPIO_X30, 0);
+       else
+               gpio_direction_output(EXYNOS4X12_GPIO_X30, 1);
+
+       /* Disconnect, Reset, Connect */
+       gpio_direction_output(EXYNOS4X12_GPIO_X34, 0);
+       gpio_direction_output(EXYNOS4X12_GPIO_X35, 0);
+       gpio_direction_output(EXYNOS4X12_GPIO_X35, 1);
+       gpio_direction_output(EXYNOS4X12_GPIO_X34, 1);
+
+       /* Power off and on BUCK8 for LAN9730 */
+       debug("LAN9730 - Turning power buck 8 OFF and ON.\n");
+
+       ret = regulator_get_by_platname("VCC_P3V3_2.85V", &dev);
+       if (ret) {
+               pr_err("Regulator get error: %d", ret);
+               return ret;
+       }
+
+       ret = regulator_set_enable(dev, true);
+       if (ret) {
+               pr_err("Regulator %s enable setting error: %d", dev->name, ret);
+               return ret;
+       }
+
+       ret = regulator_set_value(dev, 750000);
+       if (ret) {
+               pr_err("Regulator %s value setting error: %d", dev->name, ret);
+               return ret;
+       }
+
+       ret = regulator_set_value(dev, 3300000);
+       if (ret) {
+               pr_err("Regulator %s value setting error: %d", dev->name, ret);
+               return ret;
+       }
+#endif
        debug("USB_udc_probe\n");
-       return s3c_udc_probe(&s5pc210_otg_data);
+       return dwc2_udc_probe(&s5pc210_otg_data);
 }
 #endif
-
-void reset_misc(void)
-{
-       /* Reset eMMC*/
-       gpio_set_value(EXYNOS4X12_GPIO_K12, 0);
-       mdelay(10);
-       gpio_set_value(EXYNOS4X12_GPIO_K12, 1);
-}