Commit 2be1fb64 authored by Saranya Gopal's avatar Saranya Gopal Committed by Greg Kroah-Hartman

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: default avatarSaranya Gopal <saranya.gopal@intel.com>
Signed-off-by: default avatarBalaji Manoharan <m.balaji@intel.com>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Tested-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/1567079760-24822-2-git-send-email-saranya.gopal@intel.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6ed151f2
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/property.h>
#include <linux/usb/role.h> #include <linux/usb/role.h>
/* register definition */ /* register definition */
...@@ -26,6 +27,12 @@ ...@@ -26,6 +27,12 @@
#define SW_VBUS_VALID BIT(24) #define SW_VBUS_VALID BIT(24)
#define SW_IDPIN_EN BIT(21) #define SW_IDPIN_EN BIT(21)
#define SW_IDPIN BIT(20) #define SW_IDPIN BIT(20)
#define SW_SWITCH_EN BIT(16)
#define DRD_CONFIG_DYNAMIC 0
#define DRD_CONFIG_STATIC_HOST 1
#define DRD_CONFIG_STATIC_DEVICE 2
#define DRD_CONFIG_MASK 3
#define DUAL_ROLE_CFG1 0x6c #define DUAL_ROLE_CFG1 0x6c
#define HOST_MODE BIT(29) #define HOST_MODE BIT(29)
...@@ -37,6 +44,7 @@ ...@@ -37,6 +44,7 @@
struct intel_xhci_usb_data { struct intel_xhci_usb_data {
struct usb_role_switch *role_sw; struct usb_role_switch *role_sw;
void __iomem *base; void __iomem *base;
bool enable_sw_switch;
}; };
static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role)
...@@ -45,6 +53,7 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) ...@@ -45,6 +53,7 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role)
unsigned long timeout; unsigned long timeout;
acpi_status status; acpi_status status;
u32 glk, val; u32 glk, val;
u32 drd_config = DRD_CONFIG_DYNAMIC;
/* /*
* On many CHT devices ACPI event (_AEI) handlers read / modify / * On many CHT devices ACPI event (_AEI) handlers read / modify /
...@@ -59,24 +68,35 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role) ...@@ -59,24 +68,35 @@ static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role)
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
/* Set idpin value as requested */ /*
* Set idpin value as requested.
* Since some devices rely on firmware setting DRD_CONFIG and
* SW_SWITCH_EN bits to be zero for role switch,
* do not set these bits for those devices.
*/
val = readl(data->base + DUAL_ROLE_CFG0); val = readl(data->base + DUAL_ROLE_CFG0);
switch (role) { switch (role) {
case USB_ROLE_NONE: case USB_ROLE_NONE:
val |= SW_IDPIN; val |= SW_IDPIN;
val &= ~SW_VBUS_VALID; val &= ~SW_VBUS_VALID;
drd_config = DRD_CONFIG_DYNAMIC;
break; break;
case USB_ROLE_HOST: case USB_ROLE_HOST:
val &= ~SW_IDPIN; val &= ~SW_IDPIN;
val &= ~SW_VBUS_VALID; val &= ~SW_VBUS_VALID;
drd_config = DRD_CONFIG_STATIC_HOST;
break; break;
case USB_ROLE_DEVICE: case USB_ROLE_DEVICE:
val |= SW_IDPIN; val |= SW_IDPIN;
val |= SW_VBUS_VALID; val |= SW_VBUS_VALID;
drd_config = DRD_CONFIG_STATIC_DEVICE;
break; break;
} }
val |= SW_IDPIN_EN; val |= SW_IDPIN_EN;
if (data->enable_sw_switch) {
val &= ~DRD_CONFIG_MASK;
val |= SW_SWITCH_EN | drd_config;
}
writel(val, data->base + DUAL_ROLE_CFG0); writel(val, data->base + DUAL_ROLE_CFG0);
acpi_release_global_lock(glk); acpi_release_global_lock(glk);
...@@ -147,6 +167,9 @@ static int intel_xhci_usb_probe(struct platform_device *pdev) ...@@ -147,6 +167,9 @@ static int intel_xhci_usb_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, data); platform_set_drvdata(pdev, data);
data->enable_sw_switch = !device_property_read_bool(dev,
"sw_switch_disable");
data->role_sw = usb_role_switch_register(dev, &sw_desc); data->role_sw = usb_role_switch_register(dev, &sw_desc);
if (IS_ERR(data->role_sw)) if (IS_ERR(data->role_sw))
return PTR_ERR(data->role_sw); return PTR_ERR(data->role_sw);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment