Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: roles: intel: Enable static DRD mode for role switch

Enable static DRD mode in Intel platforms which guarantees
successful role switch all the time. This fixes issues like
software role switch failure after cold boot and issue with
role switch when USB 3.0 cable is used. But, do not enable
static DRD mode for Cherrytrail devices which rely on firmware
for role switch.

Signed-off-by: Saranya Gopal <saranya.gopal@intel.com>
Signed-off-by: Balaji Manoharan <m.balaji@intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/1567079760-24822-2-git-send-email-saranya.gopal@intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Saranya Gopal and committed by
Greg Kroah-Hartman
2be1fb64 6ed151f2

+25 -2
+25 -2
drivers/usb/roles/intel-xhci-usb-role-switch.c
··· 19 19 #include <linux/module.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pm_runtime.h> 22 + #include <linux/property.h> 22 23 #include <linux/usb/role.h> 23 24 24 25 /* register definition */ ··· 27 26 #define SW_VBUS_VALID BIT(24) 28 27 #define SW_IDPIN_EN BIT(21) 29 28 #define SW_IDPIN BIT(20) 29 + #define SW_SWITCH_EN BIT(16) 30 + 31 + #define DRD_CONFIG_DYNAMIC 0 32 + #define DRD_CONFIG_STATIC_HOST 1 33 + #define DRD_CONFIG_STATIC_DEVICE 2 34 + #define DRD_CONFIG_MASK 3 30 35 31 36 #define DUAL_ROLE_CFG1 0x6c 32 37 #define HOST_MODE BIT(29) ··· 44 37 struct intel_xhci_usb_data { 45 38 struct usb_role_switch *role_sw; 46 39 void __iomem *base; 40 + bool enable_sw_switch; 47 41 }; 48 42 49 43 static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) ··· 53 45 unsigned long timeout; 54 46 acpi_status status; 55 47 u32 glk, val; 48 + u32 drd_config = DRD_CONFIG_DYNAMIC; 56 49 57 50 /* 58 51 * On many CHT devices ACPI event (_AEI) handlers read / modify / ··· 68 59 69 60 pm_runtime_get_sync(dev); 70 61 71 - /* Set idpin value as requested */ 62 + /* 63 + * Set idpin value as requested. 64 + * Since some devices rely on firmware setting DRD_CONFIG and 65 + * SW_SWITCH_EN bits to be zero for role switch, 66 + * do not set these bits for those devices. 67 + */ 72 68 val = readl(data->base + DUAL_ROLE_CFG0); 73 69 switch (role) { 74 70 case USB_ROLE_NONE: 75 71 val |= SW_IDPIN; 76 72 val &= ~SW_VBUS_VALID; 73 + drd_config = DRD_CONFIG_DYNAMIC; 77 74 break; 78 75 case USB_ROLE_HOST: 79 76 val &= ~SW_IDPIN; 80 77 val &= ~SW_VBUS_VALID; 78 + drd_config = DRD_CONFIG_STATIC_HOST; 81 79 break; 82 80 case USB_ROLE_DEVICE: 83 81 val |= SW_IDPIN; 84 82 val |= SW_VBUS_VALID; 83 + drd_config = DRD_CONFIG_STATIC_DEVICE; 85 84 break; 86 85 } 87 86 val |= SW_IDPIN_EN; 88 - 87 + if (data->enable_sw_switch) { 88 + val &= ~DRD_CONFIG_MASK; 89 + val |= SW_SWITCH_EN | drd_config; 90 + } 89 91 writel(val, data->base + DUAL_ROLE_CFG0); 90 92 91 93 acpi_release_global_lock(glk); ··· 166 146 return -ENOMEM; 167 147 168 148 platform_set_drvdata(pdev, data); 149 + 150 + data->enable_sw_switch = !device_property_read_bool(dev, 151 + "sw_switch_disable"); 169 152 170 153 data->role_sw = usb_role_switch_register(dev, &sw_desc); 171 154 if (IS_ERR(data->role_sw))