]> git.sur5r.net Git - u-boot/blobdiff - board/ti/am335x/board.c
env: Rename setenv() to env_set()
[u-boot] / board / ti / am335x / board.c
index 8eaf3e9a5c95023246387bc8fb1b9f615a839088..5751b814ca263f5649ad718634e7cb40c2ee8210 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <spl.h>
 #include <serial.h>
@@ -25,7 +26,9 @@
 #include <asm/io.h>
 #include <asm/emif.h>
 #include <asm/gpio.h>
+#include <asm/omap_common.h>
 #include <asm/omap_sec_common.h>
+#include <asm/omap_mmc.h>
 #include <i2c.h>
 #include <miiphy.h>
 #include <cpsw.h>
@@ -70,7 +73,8 @@ void do_board_detect(void)
        enable_i2c0_pin_mux();
        i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
 
-       if (ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR))
+       if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
+                                CONFIG_EEPROM_CHIP_ADDRESS))
                printf("ti_i2c_eeprom_init failed\n");
 }
 #endif
@@ -245,7 +249,7 @@ int spl_start_uboot(void)
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
        env_init();
-       env_relocate_spec();
+       env_load();
        if (getenv_yesno("boot_os") != 1)
                return 1;
 #endif
@@ -254,163 +258,215 @@ int spl_start_uboot(void)
 }
 #endif
 
-#define OSC    (V_OSCK/1000000)
-const struct dpll_params dpll_ddr = {
-               266, OSC-1, 1, -1, -1, -1, -1};
-const struct dpll_params dpll_ddr_evm_sk = {
-               303, OSC-1, 1, -1, -1, -1, -1};
-const struct dpll_params dpll_ddr_bone_black = {
-               400, OSC-1, 1, -1, -1, -1, -1};
-
-void am33xx_spl_board_init(void)
+const struct dpll_params *get_dpll_ddr_params(void)
 {
-       int mpu_vdd;
+       int ind = get_sys_clk_index();
 
-       /* Get the frequency */
-       dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
+       if (board_is_evm_sk())
+               return &dpll_ddr3_303MHz[ind];
+       else if (board_is_bone_lt() || board_is_icev2())
+               return &dpll_ddr3_400MHz[ind];
+       else if (board_is_evm_15_or_later())
+               return &dpll_ddr3_303MHz[ind];
+       else
+               return &dpll_ddr2_266MHz[ind];
+}
 
-       if (board_is_bone() || board_is_bone_lt()) {
-               /* BeagleBone PMIC Code */
-               int usb_cur_lim;
+static u8 bone_not_connected_to_ac_power(void)
+{
+       if (board_is_bone()) {
+               uchar pmic_status_reg;
+               if (tps65217_reg_read(TPS65217_STATUS,
+                                     &pmic_status_reg))
+                       return 1;
+               if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
+                       puts("No AC power, switching to default OPP\n");
+                       return 1;
+               }
+       }
+       return 0;
+}
 
-               /*
-                * Only perform PMIC configurations if board rev > A1
-                * on Beaglebone White
-                */
-               if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
-                       return;
+const struct dpll_params *get_dpll_mpu_params(void)
+{
+       int ind = get_sys_clk_index();
+       int freq = am335x_get_efuse_mpu_max_freq(cdev);
+
+       if (bone_not_connected_to_ac_power())
+               freq = MPUPLL_M_600;
+
+       if (board_is_bone_lt())
+               freq = MPUPLL_M_1000;
+
+       switch (freq) {
+       case MPUPLL_M_1000:
+               return &dpll_mpu_opp[ind][5];
+       case MPUPLL_M_800:
+               return &dpll_mpu_opp[ind][4];
+       case MPUPLL_M_720:
+               return &dpll_mpu_opp[ind][3];
+       case MPUPLL_M_600:
+               return &dpll_mpu_opp[ind][2];
+       case MPUPLL_M_500:
+               return &dpll_mpu_opp100;
+       case MPUPLL_M_300:
+               return &dpll_mpu_opp[ind][0];
+       }
 
-               if (i2c_probe(TPS65217_CHIP_PM))
-                       return;
+       return &dpll_mpu_opp[ind][0];
+}
 
-               /*
-                * On Beaglebone White we need to ensure we have AC power
-                * before increasing the frequency.
-                */
-               if (board_is_bone()) {
-                       uchar pmic_status_reg;
-                       if (tps65217_reg_read(TPS65217_STATUS,
-                                             &pmic_status_reg))
-                               return;
-                       if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
-                               puts("No AC power, disabling frequency switch\n");
-                               return;
-                       }
-               }
+static void scale_vcores_bone(int freq)
+{
+       int usb_cur_lim, mpu_vdd;
 
-               /*
-                * Override what we have detected since we know if we have
-                * a Beaglebone Black it supports 1GHz.
-                */
-               if (board_is_bone_lt())
-                       dpll_mpu_opp100.m = MPUPLL_M_1000;
+       /*
+        * Only perform PMIC configurations if board rev > A1
+        * on Beaglebone White
+        */
+       if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
+               return;
 
-               /*
-                * Increase USB current limit to 1300mA or 1800mA and set
-                * the MPU voltage controller as needed.
-                */
-               if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
-                       usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
-                       mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
-               } else {
-                       usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
-                       mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
-               }
+       if (i2c_probe(TPS65217_CHIP_PM))
+               return;
 
-               if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
-                                      TPS65217_POWER_PATH,
-                                      usb_cur_lim,
-                                      TPS65217_USB_INPUT_CUR_LIMIT_MASK))
-                       puts("tps65217_reg_write failure\n");
+       /*
+        * On Beaglebone White we need to ensure we have AC power
+        * before increasing the frequency.
+        */
+       if (bone_not_connected_to_ac_power())
+               freq = MPUPLL_M_600;
 
-               /* Set DCDC3 (CORE) voltage to 1.125V */
-               if (tps65217_voltage_update(TPS65217_DEFDCDC3,
-                                           TPS65217_DCDC_VOLT_SEL_1125MV)) {
-                       puts("tps65217_voltage_update failure\n");
-                       return;
-               }
+       /*
+        * Override what we have detected since we know if we have
+        * a Beaglebone Black it supports 1GHz.
+        */
+       if (board_is_bone_lt())
+               freq = MPUPLL_M_1000;
+
+       switch (freq) {
+       case MPUPLL_M_1000:
+               mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
+               usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
+               break;
+       case MPUPLL_M_800:
+               mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
+               usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
+               break;
+       case MPUPLL_M_720:
+               mpu_vdd = TPS65217_DCDC_VOLT_SEL_1200MV;
+               usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
+               break;
+       case MPUPLL_M_600:
+       case MPUPLL_M_500:
+       case MPUPLL_M_300:
+       default:
+               mpu_vdd = TPS65217_DCDC_VOLT_SEL_1100MV;
+               usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
+               break;
+       }
 
-               /* Set CORE Frequencies to OPP100 */
-               do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
+       if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
+                              TPS65217_POWER_PATH,
+                              usb_cur_lim,
+                              TPS65217_USB_INPUT_CUR_LIMIT_MASK))
+               puts("tps65217_reg_write failure\n");
 
-               /* Set DCDC2 (MPU) voltage */
-               if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
-                       puts("tps65217_voltage_update failure\n");
-                       return;
-               }
+       /* Set DCDC3 (CORE) voltage to 1.10V */
+       if (tps65217_voltage_update(TPS65217_DEFDCDC3,
+                                   TPS65217_DCDC_VOLT_SEL_1100MV)) {
+               puts("tps65217_voltage_update failure\n");
+               return;
+       }
 
-               /*
-                * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
-                * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
-                */
-               if (board_is_bone()) {
-                       if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
-                                              TPS65217_DEFLS1,
-                                              TPS65217_LDO_VOLTAGE_OUT_3_3,
-                                              TPS65217_LDO_MASK))
-                               puts("tps65217_reg_write failure\n");
-               } else {
-                       if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
-                                              TPS65217_DEFLS1,
-                                              TPS65217_LDO_VOLTAGE_OUT_1_8,
-                                              TPS65217_LDO_MASK))
-                               puts("tps65217_reg_write failure\n");
-               }
+       /* Set DCDC2 (MPU) voltage */
+       if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
+               puts("tps65217_voltage_update failure\n");
+               return;
+       }
 
+       /*
+        * Set LDO3, LDO4 output voltage to 3.3V for Beaglebone.
+        * Set LDO3 to 1.8V and LDO4 to 3.3V for Beaglebone Black.
+        */
+       if (board_is_bone()) {
                if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
-                                      TPS65217_DEFLS2,
+                                      TPS65217_DEFLS1,
                                       TPS65217_LDO_VOLTAGE_OUT_3_3,
                                       TPS65217_LDO_MASK))
                        puts("tps65217_reg_write failure\n");
        } else {
-               int sil_rev;
+               if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
+                                      TPS65217_DEFLS1,
+                                      TPS65217_LDO_VOLTAGE_OUT_1_8,
+                                      TPS65217_LDO_MASK))
+                       puts("tps65217_reg_write failure\n");
+       }
 
-               /*
-                * The GP EVM, IDK and EVM SK use a TPS65910 PMIC.  For all
-                * MPU frequencies we support we use a CORE voltage of
-                * 1.1375V.  For MPU voltage we need to switch based on
-                * the frequency we are running at.
-                */
-               if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
-                       return;
+       if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
+                              TPS65217_DEFLS2,
+                              TPS65217_LDO_VOLTAGE_OUT_3_3,
+                              TPS65217_LDO_MASK))
+               puts("tps65217_reg_write failure\n");
+}
 
-               /*
-                * Depending on MPU clock and PG we will need a different
-                * VDD to drive at that speed.
-                */
-               sil_rev = readl(&cdev->deviceid) >> 28;
-               mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
-                                                     dpll_mpu_opp100.m);
+void scale_vcores_generic(int freq)
+{
+       int sil_rev, mpu_vdd;
 
-               /* Tell the TPS65910 to use i2c */
-               tps65910_set_i2c_control();
+       /*
+        * The GP EVM, IDK and EVM SK use a TPS65910 PMIC.  For all
+        * MPU frequencies we support we use a CORE voltage of
+        * 1.10V.  For MPU voltage we need to switch based on
+        * the frequency we are running at.
+        */
+       if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
+               return;
 
-               /* First update MPU voltage. */
-               if (tps65910_voltage_update(MPU, mpu_vdd))
-                       return;
+       /*
+        * Depending on MPU clock and PG we will need a different
+        * VDD to drive at that speed.
+        */
+       sil_rev = readl(&cdev->deviceid) >> 28;
+       mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev, freq);
 
-               /* Second, update the CORE voltage. */
-               if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
-                       return;
+       /* Tell the TPS65910 to use i2c */
+       tps65910_set_i2c_control();
 
-               /* Set CORE Frequencies to OPP100 */
-               do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
-       }
+       /* First update MPU voltage. */
+       if (tps65910_voltage_update(MPU, mpu_vdd))
+               return;
+
+       /* Second, update the CORE voltage. */
+       if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_0))
+               return;
 
-       /* Set MPU Frequency to what we detected now that voltages are set */
-       do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
 }
 
-const struct dpll_params *get_dpll_ddr_params(void)
+void gpi2c_init(void)
 {
-       if (board_is_evm_sk())
-               return &dpll_ddr_evm_sk;
-       else if (board_is_bone_lt() || board_is_icev2())
-               return &dpll_ddr_bone_black;
-       else if (board_is_evm_15_or_later())
-               return &dpll_ddr_evm_sk;
+       /* When needed to be invoked prior to BSS initialization */
+       static bool first_time = true;
+
+       if (first_time) {
+               enable_i2c0_pin_mux();
+               i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
+                        CONFIG_SYS_OMAP24_I2C_SLAVE);
+               first_time = false;
+       }
+}
+
+void scale_vcores(void)
+{
+       int freq;
+
+       gpi2c_init();
+       freq = am335x_get_efuse_mpu_max_freq(cdev);
+
+       if (board_is_beaglebonex())
+               scale_vcores_bone(freq);
        else
-               return &dpll_ddr;
+               scale_vcores_generic(freq);
 }
 
 void set_uart_mux_conf(void)
@@ -651,6 +707,21 @@ int board_late_init(void)
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
        char *name = NULL;
 
+       if (board_is_bone_lt()) {
+               /* BeagleBoard.org BeagleBone Black Wireless: */
+               if (!strncmp(board_ti_get_rev(), "BWA", 3)) {
+                       name = "BBBW";
+               }
+               /* SeeedStudio BeagleBone Green Wireless */
+               if (!strncmp(board_ti_get_rev(), "GW1", 3)) {
+                       name = "BBGW";
+               }
+               /* BeagleBoard.org BeagleBone Blue */
+               if (!strncmp(board_ti_get_rev(), "BLA", 3)) {
+                       name = "BBBL";
+               }
+       }
+
        if (board_is_bbg1())
                name = "BBG1";
        set_board_info_env(name);
@@ -660,7 +731,7 @@ int board_late_init(void)
         * on HS devices.
         */
        if (get_device_type() == HS_DEVICE)
-               setenv("boot_fit", "1");
+               env_set("boot_fit", "1");
 #endif
 
 #if !defined(CONFIG_SPL_BUILD)
@@ -877,3 +948,33 @@ void board_fit_image_post_process(void **p_image, size_t *p_size)
        secure_boot_verify_image(p_image, p_size);
 }
 #endif
+
+#if !CONFIG_IS_ENABLED(OF_CONTROL)
+static const struct omap_hsmmc_plat am335x_mmc0_platdata = {
+       .base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE,
+       .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_4BIT,
+       .cfg.f_min = 400000,
+       .cfg.f_max = 52000000,
+       .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
+       .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
+};
+
+U_BOOT_DEVICE(am335x_mmc0) = {
+       .name = "omap_hsmmc",
+       .platdata = &am335x_mmc0_platdata,
+};
+
+static const struct omap_hsmmc_plat am335x_mmc1_platdata = {
+       .base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE,
+       .cfg.host_caps = MMC_MODE_HS_52MHz | MMC_MODE_HS | MMC_MODE_8BIT,
+       .cfg.f_min = 400000,
+       .cfg.f_max = 52000000,
+       .cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195,
+       .cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
+};
+
+U_BOOT_DEVICE(am335x_mmc1) = {
+       .name = "omap_hsmmc",
+       .platdata = &am335x_mmc1_platdata,
+};
+#endif