MLK-17573-3 imx8mq_evk: Enable USB host support on typec port
authorYe Li <ye.li@nxp.com>
Sun, 11 Feb 2018 10:47:55 +0000 (02:47 -0800)
committerYe Li <ye.li@nxp.com>
Sat, 24 Feb 2018 08:06:04 +0000 (00:06 -0800)
On i.MX8MQ EVK board, the u-boot only supports the USB host mode on
USB3 port. This patch adds the host support for typec port.
So the typec port now can support both host and device mode.

Signed-off-by: Ye Li <ye.li@nxp.com>
Acked-by: Jun Li <jun.li@nxp.com>
board/freescale/imx8mq_evk/imx8m_evk.c
include/configs/imx8mq_evk.h

index 26191c4..4d7d4d3 100644 (file)
@@ -204,30 +204,6 @@ static void dwc3_nxp_usb_phy_init(struct dwc3_device *dwc3)
 }
 #endif
 
-#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_IMX8M)
-int board_usb_init(int index, enum usb_init_type init)
-{
-       imx8m_usb_power(index, true);
-
-       if (index == 0 && init == USB_INIT_DEVICE) {
-               dwc3_nxp_usb_phy_init(&dwc3_device_data);
-               return dwc3_uboot_init(&dwc3_device_data);
-       }
-
-       return 0;
-}
-
-int board_usb_cleanup(int index, enum usb_init_type init)
-{
-       if (index == 0 && init == USB_INIT_DEVICE)
-               dwc3_uboot_exit(index);
-
-       imx8m_usb_power(index, false);
-
-       return 0;
-}
-#endif
-
 #ifdef CONFIG_USB_TCPC
 struct tcpc_port port;
 struct tcpc_port_config port_config = {
@@ -240,11 +216,28 @@ struct tcpc_port_config port_config = {
        .op_snk_mv = 9000,
 };
 
+#define USB_TYPEC_SEL IMX_GPIO_NR(3, 15)
+
+static iomux_v3_cfg_t ss_mux_gpio[] = {
+       IMX8MQ_PAD_NAND_RE_B__GPIO3_IO15 | MUX_PAD_CTRL(NO_PAD_CTRL),
+};
+
+void ss_mux_select(enum typec_cc_polarity pol)
+{
+       if (pol == TYPEC_POLARITY_CC1)
+               gpio_direction_output(USB_TYPEC_SEL, 1);
+       else
+               gpio_direction_output(USB_TYPEC_SEL, 0);
+}
+
 static int setup_typec(void)
 {
        int ret;
 
-       ret = tcpc_init(&port, port_config, NULL);
+       imx_iomux_v3_setup_multiple_pads(ss_mux_gpio, ARRAY_SIZE(ss_mux_gpio));
+       gpio_request(USB_TYPEC_SEL, "typec_sel");
+
+       ret = tcpc_init(&port, port_config, &ss_mux_select);
        if (ret) {
                printf("%s: tcpc init failed, err=%d\n",
                       __func__, ret);
@@ -254,6 +247,46 @@ static int setup_typec(void)
 }
 #endif
 
+#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_IMX8M)
+int board_usb_init(int index, enum usb_init_type init)
+{
+       int ret = 0;
+       imx8m_usb_power(index, true);
+
+       if (index == 0 && init == USB_INIT_DEVICE) {
+#ifdef CONFIG_USB_TCPC
+               ret = tcpc_setup_ufp_mode(&port);
+#endif
+               dwc3_nxp_usb_phy_init(&dwc3_device_data);
+               return dwc3_uboot_init(&dwc3_device_data);
+       } else if (index == 0 && init == USB_INIT_HOST) {
+#ifdef CONFIG_USB_TCPC
+               ret = tcpc_setup_dfp_mode(&port);
+#endif
+               return ret;
+       }
+
+       return 0;
+}
+
+int board_usb_cleanup(int index, enum usb_init_type init)
+{
+       int ret = 0;
+       if (index == 0 && init == USB_INIT_DEVICE) {
+               dwc3_uboot_exit(index);
+       } else if (index == 0 && init == USB_INIT_HOST) {
+#ifdef CONFIG_USB_TCPC
+               ret = tcpc_disable_src_vbus(&port);
+#endif
+       }
+
+       imx8m_usb_power(index, false);
+
+       return ret;
+}
+#endif
+
+
 int board_init(void)
 {
        board_qspi_init();
index 4b9f2e6..315df99 100644 (file)
 #define CONFIG_USB_XHCI_IMX8M
 #define CONFIG_USB_XHCI_DWC3
 #define CONFIG_USB_XHCI_HCD
-#define CONFIG_USB_MAX_CONTROLLER_COUNT         1
+#define CONFIG_USB_MAX_CONTROLLER_COUNT         2
 #define CONFIG_SYS_USB_XHCI_MAX_ROOT_PORTS      2
 #endif