From patchwork Fri Nov 8 01:17:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11233967 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B51CC1390 for ; Fri, 8 Nov 2019 01:17:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 881B4222C2 for ; Fri, 8 Nov 2019 01:17:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bKADj403" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728983AbfKHBRm (ORCPT ); Thu, 7 Nov 2019 20:17:42 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40720 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728569AbfKHBRa (ORCPT ); Thu, 7 Nov 2019 20:17:30 -0500 Received: by mail-pg1-f193.google.com with SMTP id 15so3039377pgt.7 for ; Thu, 07 Nov 2019 17:17:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OkKRy5y8eyF3IUkqSp9qwVY1typargMwIHR68X5ogBg=; b=bKADj403sq2wgRxhLTB0jzzEUBQtuwtF4yInOpHLvRlI3FA+MUSvA8qERETwg3iPGV hbus0BGgRczNiiZjHp+pf12C1sV37/RAmAODn4l4dVL4ndXNlaOWRZn558921G82oZ2B 7vU6osMkXDbl3l6Ip3HvQUauWegpW3gdcgLeiAzUILpm6aH9msqtIMBSA/5WcyBa5PAC OBFPXwJturmtlRhDgXilUz09yZVNcBDfG9hq8i3ORtX4f9aUBKMKesAStlY/GMBICzIe bjNYiyUI/qX83c9O+zu63GCz3ktjHkZ/V8Im/t3UkNbxGkJBpd6af+JY2IYRizXISDGq /RGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OkKRy5y8eyF3IUkqSp9qwVY1typargMwIHR68X5ogBg=; b=I9e64l3CIJnpA9F70+4joUzpboptsc2KCsmaJ+4g9Y13wnr0IeShUTTuSyyY1PlbMz EoEOAUFGYZ/dBZ1sqqmJYc22qwT39sYZ2bUdhJYwaHt7VdaZMQCkDeQnBnaKFGZ+aQiH +63XJ7Cxqq7ZQmIZRZ2MHSQHRTryeYiuVm5/aV9pqhQIOu+flwUiDrNmyN1B6nVzeDRt oGo+98HcxmuPBGq6yjhwjy2FAVAvh+OgW7fMHa98tkiyZl1RWGzcVZYjMa58fBGtuqX3 aQbLacfWM/nnN9XG3p8zifXl3lpg0zSiTe7fx1Vbh/LJF1YVmYISONQ+NvyM1MXBZeN9 ipDg== X-Gm-Message-State: APjAAAWVGm6UDnKUwt+eX7xW06ljkOViHZkKL0R5OYFaKb3T8N/+VRnR a0vRU1AVZ3skqFtFxngXmLvgXg== X-Google-Smtp-Source: APXvYqz0GcFhjlba4rgNNP0k3FvzkjxCStNTLxMvkwPwrcGQff21L6hAhhwiV+9ykGe69+IWAbqNPg== X-Received: by 2002:a63:cf45:: with SMTP id b5mr8364414pgj.36.1573175848197; Thu, 07 Nov 2019 17:17:28 -0800 (PST) Received: from localhost.localdomain (c-67-170-172-113.hsd1.or.comcast.net. [67.170.172.113]) by smtp.gmail.com with ESMTPSA id s23sm3801627pgh.21.2019.11.07.17.17.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 17:17:27 -0800 (PST) From: John Stultz To: lkml Cc: Yu Chen , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v5 1/3] usb: dwc3: Registering a role switch in the DRD code. Date: Fri, 8 Nov 2019 01:17:21 +0000 Message-Id: <20191108011723.32390-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191108011723.32390-1-john.stultz@linaro.org> References: <20191108011723.32390-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Yu Chen The Type-C drivers use USB role switch API to inform the system about the negotiated data role, so registering a role switch in the DRD code in order to support platforms with USB Type-C connectors. Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Mark Rutland CC: ShuFan Lee Cc: Heikki Krogerus Cc: Suzuki K Poulose Cc: Chunfeng Yun Cc: Yu Chen Cc: Felipe Balbi Cc: Hans de Goede Cc: Andy Shevchenko Cc: Jun Li Cc: Valentin Schneider Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Heikki Krogerus Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v2: Fix role_sw and role_switch_default_mode descriptions as reported by kbuild test robot v3: Split out the role-switch-default-host logic into its own patch v5: Drop selecting CONFIG_USB_ROLE_SWITCH & ifdef dependent code --- drivers/usb/dwc3/core.h | 3 ++ drivers/usb/dwc3/drd.c | 77 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 1c8b349379af..6f19e9891767 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -951,6 +952,7 @@ struct dwc3_scratchpad_array { * @hsphy_mode: UTMI phy mode, one of following: * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW + * @role_sw: usb_role_switch handle * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1084,6 +1086,7 @@ struct dwc3 { struct extcon_dev *edev; struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; + struct usb_role_switch *role_sw; u32 fladj; u32 irq_gadget; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index c946d64142ad..cd43dc2a96c6 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -476,6 +476,73 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) return edev; } +#ifdef CONFIG_USB_ROLE_SWITCH +#define ROLE_SWITCH 1 +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + u32 mode; + + switch (role) { + case USB_ROLE_HOST: + mode = DWC3_GCTL_PRTCAP_HOST; + break; + case USB_ROLE_DEVICE: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + default: + mode = DWC3_GCTL_PRTCAP_DEVICE; + break; + } + + dwc3_set_mode(dwc, mode); + return 0; +} + +static enum usb_role dwc3_usb_role_switch_get(struct device *dev) +{ + struct dwc3 *dwc = dev_get_drvdata(dev); + unsigned long flags; + enum usb_role role; + + spin_lock_irqsave(&dwc->lock, flags); + switch (dwc->current_dr_role) { + case DWC3_GCTL_PRTCAP_HOST: + role = USB_ROLE_HOST; + break; + case DWC3_GCTL_PRTCAP_DEVICE: + role = USB_ROLE_DEVICE; + break; + case DWC3_GCTL_PRTCAP_OTG: + role = dwc->current_otg_role; + break; + default: + role = USB_ROLE_DEVICE; + break; + } + spin_unlock_irqrestore(&dwc->lock, flags); + return role; +} + +static int dwc3_setup_role_switch(struct dwc3 *dwc) +{ + struct usb_role_switch_desc dwc3_role_switch = {NULL}; + + dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); + dwc3_role_switch.set = dwc3_usb_role_switch_set; + dwc3_role_switch.get = dwc3_usb_role_switch_get; + dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch); + if (IS_ERR(dwc->role_sw)) + return PTR_ERR(dwc->role_sw); + + dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + return 0; +} +#else +#define ROLE_SWITCH 0 +#define dwc3_setup_role_switch(x) +#endif + int dwc3_drd_init(struct dwc3 *dwc) { int ret, irq; @@ -484,7 +551,12 @@ int dwc3_drd_init(struct dwc3 *dwc) if (IS_ERR(dwc->edev)) return PTR_ERR(dwc->edev); - if (dwc->edev) { + if (ROLE_SWITCH && + device_property_read_bool(dwc->dev, "usb-role-switch")) { + ret = dwc3_setup_role_switch(dwc); + if (ret < 0) + return ret; + } else if (dwc->edev) { dwc->edev_nb.notifier_call = dwc3_drd_notifier; ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); @@ -531,6 +603,9 @@ void dwc3_drd_exit(struct dwc3 *dwc) { unsigned long flags; + if (dwc->role_sw) + usb_role_switch_unregister(dwc->role_sw); + if (dwc->edev) extcon_unregister_notifier(dwc->edev, EXTCON_USB_HOST, &dwc->edev_nb); From patchwork Fri Nov 8 01:17:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11233965 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4108914E5 for ; Fri, 8 Nov 2019 01:17:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DA62222CE for ; Fri, 8 Nov 2019 01:17:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="u/JvJWNt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728574AbfKHBRa (ORCPT ); Thu, 7 Nov 2019 20:17:30 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42241 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728568AbfKHBRa (ORCPT ); Thu, 7 Nov 2019 20:17:30 -0500 Received: by mail-pl1-f193.google.com with SMTP id j12so2852556plt.9 for ; Thu, 07 Nov 2019 17:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LLXZrZ84x0Pyw/nld9adeknAuwlBiKPfBfqjo8+Ifgo=; b=u/JvJWNtCX0x9O+sSjvMa/QWd8kyTLghXlBUPWCupQcRCLT+i3CCELlTUCl24eIxb5 zA/Pz9hWhV9GWJrulx67Xr59HQk32CVEqgT/eaRosc79Z3ycVrHIlbOvcFDSqfds/JnK 6Uj4VLci3lcaQ/cn4WkmbVndipKWjYnelFlhJtAh0IKamhRF1hkS0OeElXESfWmKqYFi oXo+/V0PdT6sOAfet/xjOUDfhbjWHflFooe0WhgiY4NqAsnaXE51DgIQ7D57AltUmhD2 yFT/0Jtdudw3tuIeNGwAy/fPpGhRhQSWNqziPBMnVBUbEr3VRp+H6wiITyKQork4q4f/ 5ZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LLXZrZ84x0Pyw/nld9adeknAuwlBiKPfBfqjo8+Ifgo=; b=fhOGR65m40Fhx4rgt0EqeX+4j/rstmjaOq6Ef/LR3Zvz253ij3oHFlgvSOSVEcxWN8 IOAFNBB3dfzfi1AbcBfGFQEFGHhcSaiEcF2lon9gkBQPyt6axbkJmGGCt1s7DwugZIL1 a0dfswNYLYo23zVjd9/dM8z3nOz0XSBelJbAEnMhPNyDPfq15uuNVm+0WZmRUW6KFvDL H5MTyLOLp9xo8uXb+y0rIHhs7gAOclWuImIP0Pv6LNS55MQlRch6Jfc0YzSg7e3b4ymW pqArOAWxQPZlSkG88G+kKgnu+zgbcglOXI6YpKDwENh0DGu7iFFeNNRxt0tBwds13x/Z bdiQ== X-Gm-Message-State: APjAAAW96MJ6yEYQN2/IqVTj5H8fo5YprhbmW+HlQbAQDe9DKveG7/ds PZefv340iSgKCIXWPGOSafjImg== X-Google-Smtp-Source: APXvYqwS5DMlcFIk+38hkbxym79JhkVpzW7JM1wV8qZd6lco9HB/8rFAXIE8J/Oq0TJUCqk28jNfIQ== X-Received: by 2002:a17:902:6946:: with SMTP id k6mr7463711plt.60.1573175849449; Thu, 07 Nov 2019 17:17:29 -0800 (PST) Received: from localhost.localdomain (c-67-170-172-113.hsd1.or.comcast.net. [67.170.172.113]) by smtp.gmail.com with ESMTPSA id s23sm3801627pgh.21.2019.11.07.17.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 17:17:28 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Yu Chen , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v5 2/3] dt-bindings: usb: generic: Add role-switch-default-mode binding Date: Fri, 8 Nov 2019 01:17:22 +0000 Message-Id: <20191108011723.32390-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191108011723.32390-1-john.stultz@linaro.org> References: <20191108011723.32390-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add binding to configure the default role the controller assumes is host mode when the usb role is USB_ROLE_NONE. Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Mark Rutland CC: ShuFan Lee Cc: Heikki Krogerus Cc: Suzuki K Poulose Cc: Chunfeng Yun Cc: Yu Chen Cc: Felipe Balbi Cc: Hans de Goede Cc: Andy Shevchenko Cc: Jun Li Cc: Valentin Schneider Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: John Stultz Reviewed-by: Rob Herring --- v5: Switch to string rather then a bool --- Documentation/devicetree/bindings/usb/generic.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index cf5a1ad456e6..dd733fa81fad 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -34,6 +34,12 @@ Optional properties: the USB data role (USB host or USB device) for a given USB connector, such as Type-C, Type-B(micro). see connector/usb-connector.txt. + - role-switch-default-mode: indicating if usb-role-switch is enabled, the + device default operation mode of controller while usb + role is USB_ROLE_NONE. Valid arguments are "host" and + "peripheral". Defaults to "peripheral" if not + specified. + This is an attribute to a USB controller such as: From patchwork Fri Nov 8 01:17:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11233963 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 757D014E5 for ; Fri, 8 Nov 2019 01:17:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46A3B21D7F for ; Fri, 8 Nov 2019 01:17:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ACJVwJRk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728687AbfKHBRj (ORCPT ); Thu, 7 Nov 2019 20:17:39 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36809 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728734AbfKHBRd (ORCPT ); Thu, 7 Nov 2019 20:17:33 -0500 Received: by mail-pf1-f194.google.com with SMTP id v19so3625210pfm.3 for ; Thu, 07 Nov 2019 17:17:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YbemW7AL+I9zYGvxXlbJg+1m1dDalQtynuOAJrGAmWs=; b=ACJVwJRkBGFF/+sRj9R7QOdB9bAbJ6DEyprQOIneKcH3rKcMgobDzmL8cbBhYlFlhK UG2Ts4IPnKEi0BvogIAVPjdl0GyD/nmlUMJ8j3nrOqWM4sZhl4iScMGH6pMgUdIp3agF bAhVgzQJJibox07IVXnsi/E0RBsgmbS4Be+JPffq8vWgbVwBcK/204cFgjRz8+tYE+AW NyEqeFkwbX6OcClJTe51TB9TQpaxHfkYHRX9N6XVF/cffjl/FHsbZQGK/bFdbMs7MisO s6FQbdYw7P81hKyHCx5wpCeqZldGJFTnOsLYsjfKnKeWzlWpzvYZBckyZBX1n6C8/3tY 3rog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YbemW7AL+I9zYGvxXlbJg+1m1dDalQtynuOAJrGAmWs=; b=K3C0+St+EVa6i/bX+vfOf8OW1UQefK0cmPwvthO0zQB6wnMcgv0KWkcXEZC7PhpH39 wNKCDFvHY7muWtOzfgSwixjxGCDR1bKLuHWOALtRrcaW672CJTDKLPmzV3TZnSmweb1W XemZqONQTzPywTj5u39lXPPaAqffkCUi4rTx+p6WbLQAMrWrcXK49zXNq52GB/FTVsc1 nKm0kKbRH9YRXzszdFnmbi3dr6zo9sjgOiTIMD69iuPF8bt293KoWHHIaEGXYyCZq9R4 +j+sHDk07Ogjguuc1NL/efmZVo/W+Kl9EIlQNy81B+ErIDzM6eVqQXpucLQ5vE8R7ufU BU9g== X-Gm-Message-State: APjAAAX+qrTx2To935C2c0OZzy1xmzvAYKOUOo7Db2SUcilPZJ4ZiMfE hd2lvY5+kx06wYU5QTtQIMxZMA== X-Google-Smtp-Source: APXvYqyDhmgyCW2jRU4VkuvCxHq08LF27f3i1nfLBp9RaV09aT68CPvXaoPm9q4dclh6MPOcwKx78Q== X-Received: by 2002:a63:e84d:: with SMTP id a13mr8340878pgk.226.1573175850634; Thu, 07 Nov 2019 17:17:30 -0800 (PST) Received: from localhost.localdomain (c-67-170-172-113.hsd1.or.comcast.net. [67.170.172.113]) by smtp.gmail.com with ESMTPSA id s23sm3801627pgh.21.2019.11.07.17.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 17:17:30 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Greg Kroah-Hartman , Rob Herring , Mark Rutland , ShuFan Lee , Heikki Krogerus , Suzuki K Poulose , Chunfeng Yun , Yu Chen , Felipe Balbi , Hans de Goede , Andy Shevchenko , Jun Li , Valentin Schneider , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v5 3/3] usb: dwc3: Add support for role-switch-default-mode binding Date: Fri, 8 Nov 2019 01:17:23 +0000 Message-Id: <20191108011723.32390-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191108011723.32390-1-john.stultz@linaro.org> References: <20191108011723.32390-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Support the new role-switch-default-mode binding for configuring the default role the controller assumes as when the usb role is USB_ROLE_NONE This patch was split out from a larger patch originally by Yu Chen Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Mark Rutland CC: ShuFan Lee Cc: Heikki Krogerus Cc: Suzuki K Poulose Cc: Chunfeng Yun Cc: Yu Chen Cc: Felipe Balbi Cc: Hans de Goede Cc: Andy Shevchenko Cc: Jun Li Cc: Valentin Schneider Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: John Stultz --- v3: Split this patch out from addition of usb-role-switch handling v5: Reworked to use string based role-switch-default-mode --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/drd.c | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 6f19e9891767..3c879c9ab1aa 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -953,6 +953,8 @@ struct dwc3_scratchpad_array { * - USBPHY_INTERFACE_MODE_UTMI * - USBPHY_INTERFACE_MODE_UTMIW * @role_sw: usb_role_switch handle + * @role_switch_default_mode: default operation mode of controller while + * usb role is USB_ROLE_NONE. * @usb2_phy: pointer to USB2 PHY * @usb3_phy: pointer to USB3 PHY * @usb2_generic_phy: pointer to USB2 PHY @@ -1087,6 +1089,7 @@ struct dwc3 { struct notifier_block edev_nb; enum usb_phy_interface hsphy_mode; struct usb_role_switch *role_sw; + enum usb_dr_mode role_switch_default_mode; u32 fladj; u32 irq_gadget; diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index cd43dc2a96c6..dbb881863297 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -491,7 +491,10 @@ static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role) mode = DWC3_GCTL_PRTCAP_DEVICE; break; default: - mode = DWC3_GCTL_PRTCAP_DEVICE; + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) + mode = DWC3_GCTL_PRTCAP_HOST; + else + mode = DWC3_GCTL_PRTCAP_DEVICE; break; } @@ -517,7 +520,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) role = dwc->current_otg_role; break; default: - role = USB_ROLE_DEVICE; + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) + role = USB_ROLE_HOST; + else + role = USB_ROLE_DEVICE; break; } spin_unlock_irqrestore(&dwc->lock, flags); @@ -527,6 +533,19 @@ static enum usb_role dwc3_usb_role_switch_get(struct device *dev) static int dwc3_setup_role_switch(struct dwc3 *dwc) { struct usb_role_switch_desc dwc3_role_switch = {NULL}; + const char *str; + u32 mode; + int ret; + + ret = device_property_read_string(dwc->dev, "role-switch-default-mode", + &str); + if (ret >= 0 && !strncmp(str, "host", strlen("host"))) { + dwc->role_switch_default_mode = USB_DR_MODE_HOST; + mode = DWC3_GCTL_PRTCAP_HOST; + } else { + dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL; + mode = DWC3_GCTL_PRTCAP_DEVICE; + } dwc3_role_switch.fwnode = dev_fwnode(dwc->dev); dwc3_role_switch.set = dwc3_usb_role_switch_set; @@ -535,7 +554,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc) if (IS_ERR(dwc->role_sw)) return PTR_ERR(dwc->role_sw); - dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); + dwc3_set_mode(dwc, mode); return 0; } #else