Explicitly set USB Switch (PTN5150A) to UFP * The default configuration (via resistor stuffing) is DFP (host). This means that on Type-C hosts fastboot won't work. * Set to UFP to ensure fastboot works properly. Change-Id: I2b63d95e08df70da43dee1f8f7bb59d1863943f4 (cherry picked from commit 50fe9f8704cafd1dc5cb824079f491be00d6df15)
diff --git a/board/freescale/imx8mq_phanbell/imx8m_phanbell.c b/board/freescale/imx8mq_phanbell/imx8m_phanbell.c index 1689bbb..b066ed2 100644 --- a/board/freescale/imx8mq_phanbell/imx8m_phanbell.c +++ b/board/freescale/imx8mq_phanbell/imx8m_phanbell.c
@@ -11,10 +11,12 @@ #include <asm/io.h> #include <miiphy.h> #include <netdev.h> +#include <dm.h> #include <asm/imx-common/iomux-v3.h> #include <asm/imx-common/boot_mode.h> #include <asm-generic/gpio.h> #include <fsl_esdhc.h> +#include <i2c.h> #include <mmc.h> #include <asm/arch/imx8mq_pins.h> #include <asm/arch/sys_proto.h> @@ -164,6 +166,12 @@ #define USB_PHY_CTRL2 0xF0048 #define USB_PHY_CTRL2_TXENABLEN0 BIT(8) +#define PTN5150A_BUS 2 +#define PTN5150A_ADDR 0x3D +#define PTN5150A_CONTROL 0x2 +#define PTN5150A_CONTROL_PORT_MASK 0x6 + + static struct dwc3_device dwc3_device_data = { .maximum_speed = USB_SPEED_HIGH, .base = USB1_BASE_ADDR, @@ -200,6 +208,37 @@ RegData &= ~(USB_PHY_CTRL1_RESET | USB_PHY_CTRL1_ATERESET); writel(RegData, dwc3->base + USB_PHY_CTRL1); } + +static void configure_cc_switch() { + uint8_t value; + int ret; + struct udevice *bus, *dev; + + ret = uclass_get_device_by_seq(UCLASS_I2C, PTN5150A_BUS, &bus); + if (ret) { + printf("%s: No bus %d\n", __func__, PTN5150A_BUS); + return; + } + + ret = dm_i2c_probe(bus, PTN5150A_ADDR, 0, &dev); + if (ret) { + printf("%s: Can't find device id=0x%x, on bus %d\n", + __func__, PTN5150A_ADDR, PTN5150A_BUS); + return; + } + + if (dm_i2c_read(dev, PTN5150A_CONTROL, &value, 1)) { + printf("Unable to configure USB switch"); + return; + } + + value &= ~PTN5150A_CONTROL_PORT_MASK; + if (dm_i2c_write(dev, PTN5150A_CONTROL, &value, 1)) { + printf("Unable to configure USB switch"); + return; + } + printf("Configured USB Switch for UFP\n"); +} #endif #if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_IMX8M) @@ -207,6 +246,10 @@ { imx8m_usb_power(index, true); + /* Explicitly set USB switch to UFP (device) to ensure proper + * fastboot operation on type-C ports. */ + configure_cc_switch(); + if (index == 0 && init == USB_INIT_DEVICE) { dwc3_nxp_usb_phy_init(&dwc3_device_data); return dwc3_uboot_init(&dwc3_device_data);