Merge branch 'master' of git://www.denx.de/git/u-boot-socfpga
[oweals/u-boot.git] / board / ti / dra7xx / evm.c
index 7f19655cfeb6041377bbe4ab48547603307611b3..d4648558ec375abbd201f2627a3d76b40bc342e5 100644 (file)
 #include <common.h>
 #include <palmas.h>
 #include <sata.h>
+#include <asm/gpio.h>
+#include <usb.h>
+#include <linux/usb/gadget.h>
+#include <asm/arch/gpio.h>
 #include <asm/arch/sys_proto.h>
 #include <asm/arch/mmc_host_def.h>
 #include <asm/arch/sata.h>
 #include <environment.h>
+#include <dwc3-uboot.h>
+#include <dwc3-omap-uboot.h>
+#include <ti-usb-phy-uboot.h>
 
 #include "mux_data.h"
 
@@ -26,6 +33,9 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+/* GPIO 7_11 */
+#define GPIO_DDR_VTT_EN 203
+
 const struct omap_sysinfo sysinfo = {
        "Board: DRA7xx\n"
 };
@@ -83,24 +93,17 @@ int board_init(void)
 int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
+       u32 id[4];
+
        if (omap_revision() == DRA722_ES1_0)
                setenv("board_name", "dra72x");
        else
                setenv("board_name", "dra7xx");
-#endif
-       init_sata(0);
-       return 0;
-}
 
-/**
- * @brief misc_init_r - Configure EVM board specific configurations
- * such as power configurations, ethernet initialization as phase2 of
- * boot sequence
- *
- * @return 0
- */
-int misc_init_r(void)
-{
+       id[0] = readl((*ctrl)->control_std_fuse_die_id_0);
+       id[1] = readl((*ctrl)->control_std_fuse_die_id_1);
+       usb_set_serial_num_from_die_id(id);
+#endif
        return 0;
 }
 
@@ -131,6 +134,110 @@ int board_mmc_init(bd_t *bis)
 }
 #endif
 
+#ifdef CONFIG_USB_DWC3
+static struct dwc3_device usb_otg_ss1 = {
+       .maximum_speed = USB_SPEED_SUPER,
+       .base = DRA7_USB_OTG_SS1_BASE,
+       .tx_fifo_resize = false,
+       .index = 0,
+};
+
+static struct dwc3_omap_device usb_otg_ss1_glue = {
+       .base = (void *)DRA7_USB_OTG_SS1_GLUE_BASE,
+       .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+       .vbus_id_status = OMAP_DWC3_VBUS_VALID,
+       .index = 0,
+};
+
+static struct ti_usb_phy_device usb_phy1_device = {
+       .pll_ctrl_base = (void *)DRA7_USB3_PHY1_PLL_CTRL,
+       .usb2_phy_power = (void *)DRA7_USB2_PHY1_POWER,
+       .usb3_phy_power = (void *)DRA7_USB3_PHY1_POWER,
+       .index = 0,
+};
+
+static struct dwc3_device usb_otg_ss2 = {
+       .maximum_speed = USB_SPEED_SUPER,
+       .base = DRA7_USB_OTG_SS2_BASE,
+       .tx_fifo_resize = false,
+       .index = 1,
+};
+
+static struct dwc3_omap_device usb_otg_ss2_glue = {
+       .base = (void *)DRA7_USB_OTG_SS2_GLUE_BASE,
+       .utmi_mode = DWC3_OMAP_UTMI_MODE_SW,
+       .vbus_id_status = OMAP_DWC3_VBUS_VALID,
+       .index = 1,
+};
+
+static struct ti_usb_phy_device usb_phy2_device = {
+       .usb2_phy_power = (void *)DRA7_USB2_PHY2_POWER,
+       .index = 1,
+};
+
+int board_usb_init(int index, enum usb_init_type init)
+{
+       switch (index) {
+       case 0:
+               if (init == USB_INIT_DEVICE) {
+                       usb_otg_ss1.dr_mode = USB_DR_MODE_PERIPHERAL;
+                       usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+               } else {
+                       usb_otg_ss1.dr_mode = USB_DR_MODE_HOST;
+                       usb_otg_ss1_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+               }
+
+               ti_usb_phy_uboot_init(&usb_phy1_device);
+               dwc3_omap_uboot_init(&usb_otg_ss1_glue);
+               dwc3_uboot_init(&usb_otg_ss1);
+               break;
+       case 1:
+               if (init == USB_INIT_DEVICE) {
+                       usb_otg_ss2.dr_mode = USB_DR_MODE_PERIPHERAL;
+                       usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_VBUS_VALID;
+               } else {
+                       usb_otg_ss2.dr_mode = USB_DR_MODE_HOST;
+                       usb_otg_ss2_glue.vbus_id_status = OMAP_DWC3_ID_GROUND;
+               }
+
+               ti_usb_phy_uboot_init(&usb_phy2_device);
+               dwc3_omap_uboot_init(&usb_otg_ss2_glue);
+               dwc3_uboot_init(&usb_otg_ss2);
+               break;
+       default:
+               printf("Invalid Controller Index\n");
+       }
+
+       return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+       switch (index) {
+       case 0:
+       case 1:
+               ti_usb_phy_uboot_exit(index);
+               dwc3_uboot_exit(index);
+               dwc3_omap_uboot_exit(index);
+               break;
+       default:
+               printf("Invalid Controller Index\n");
+       }
+       return 0;
+}
+
+int usb_gadget_handle_interrupts(int index)
+{
+       u32 status;
+
+       status = dwc3_omap_uboot_interrupt_status(index);
+       if (status)
+               dwc3_uboot_handle_interrupt(index);
+
+       return 0;
+}
+#endif
+
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_OS_BOOT)
 int spl_start_uboot(void)
 {
@@ -163,6 +270,8 @@ int spl_start_uboot(void)
 #define VIN2A_D15_DLY_VAL              ((0x4 << 5) + 0x0)
 #define VIN2A_D14_DLY_VAL              ((0x4 << 5) + 0x0)
 
+extern u32 *const omap_si_rev;
+
 static void cpsw_control(int enabled)
 {
        /* VTP can be added here */
@@ -189,7 +298,7 @@ static struct cpsw_platform_data cpsw_data = {
        .mdio_div               = 0xff,
        .channels               = 8,
        .cpdma_reg_ofs          = 0x800,
-       .slaves                 = 1,
+       .slaves                 = 2,
        .slave_data             = cpsw_slaves,
        .ale_reg_ofs            = 0xd00,
        .ale_entries            = 1024,
@@ -238,7 +347,7 @@ int board_eth_init(bd_t *bis)
        if (!getenv("ethaddr")) {
                printf("<ethaddr> not set. Validating first E-fuse MAC\n");
 
-               if (is_valid_ether_addr(mac_addr))
+               if (is_valid_ethaddr(mac_addr))
                        eth_setenv_enetaddr("ethaddr", mac_addr);
        }
 
@@ -252,7 +361,7 @@ int board_eth_init(bd_t *bis)
        mac_addr[5] = mac_lo & 0xFF;
 
        if (!getenv("eth1addr")) {
-               if (is_valid_ether_addr(mac_addr))
+               if (is_valid_ethaddr(mac_addr))
                        eth_setenv_enetaddr("eth1addr", mac_addr);
        }
 
@@ -260,6 +369,9 @@ int board_eth_init(bd_t *bis)
        ctrl_val |= 0x22;
        writel(ctrl_val, (*ctrl)->control_core_control_io1);
 
+       if (*omap_si_rev == DRA722_ES1_0)
+               cpsw_data.active_slave = 1;
+
        ret = cpsw_register(&cpsw_data);
        if (ret < 0)
                printf("Error %d registering CPSW switch\n", ret);
@@ -267,3 +379,29 @@ int board_eth_init(bd_t *bis)
        return ret;
 }
 #endif
+
+#ifdef CONFIG_BOARD_EARLY_INIT_F
+/* VTT regulator enable */
+static inline void vtt_regulator_enable(void)
+{
+       if (omap_hw_init_context() == OMAP_INIT_CONTEXT_UBOOT_AFTER_SPL)
+               return;
+
+       /* Do not enable VTT for DRA722 */
+       if (omap_revision() == DRA722_ES1_0)
+               return;
+
+       /*
+        * EVM Rev G and later use gpio7_11 for DDR3 termination.
+        * This is safe enough to do on older revs.
+        */
+       gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
+       gpio_direction_output(GPIO_DDR_VTT_EN, 1);
+}
+
+int board_early_init_f(void)
+{
+       vtt_regulator_enable();
+       return 0;
+}
+#endif