From patchwork Thu Dec 12 01:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286715 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 9F22114B7 for ; Thu, 12 Dec 2019 01:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 728F422527 for ; Thu, 12 Dec 2019 01:43:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hMpTmiIn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727578AbfLLBmi (ORCPT ); Wed, 11 Dec 2019 20:42:38 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42811 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727509AbfLLBmh (ORCPT ); Wed, 11 Dec 2019 20:42:37 -0500 Received: by mail-pf1-f195.google.com with SMTP id 4so225267pfz.9 for ; Wed, 11 Dec 2019 17:42:37 -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=Ml1LjDh4MXlYnFnFE/FtxHnraLrSz8z9onh0HzsL760=; b=hMpTmiInIBymA2Q22Jm1fo58ppcLh0yU84O6ZMaompS+uew7ESCc6RQ/Z+KExCCCeq 1OIAAeu41gf7hcC+ncpsq/RBaqmO4vNJYxNNWcXIx6X0TmrcqevlJsSnOSjAKus/7P1K rovkRah8SrYcnnymkRABNxuseu+5fOqmI3Hhp7Gk8gJ25SCA4MANpT7auNqELLLs9ytW LdBssxJwlThBIAhGQ8iHaRonxhWYpSOTZbGBXZ7k8istps/jXfocrwu3lJD5Bzi1bCPo 4LGqtBYHvB1IBEVKpYB8OEplt6O/hkn1Mtgzi4FPhIi2MpNnazl/XsV6vjD6zUds3zSl AngQ== 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=Ml1LjDh4MXlYnFnFE/FtxHnraLrSz8z9onh0HzsL760=; b=E8MEomDbqHSvIvPCfbyR1x196sbW/VQp6zzgxwmRdDIm39+Rm9tt2x2AWpovvaNjnn l8IfZSgs5TYtTLGTgTkKJ3ZK3fK4cScwsXUnnCpmqrDK5E1H/k96dgae92NA4t83WCae uQDguENNTlsMCdC5C4zwi+r6+YUj4caK7WS1sA5Wk2cw1oeC7iG1cEsLfOCy4ojwUaAM GW7jXdToqN8PzDDyT/s/K3SLkF8lXiD3qbOvHCgLQnclWrr1MFN+IMFAaI/U8wvQcqtW uzq8EZn6IdklVt4G27ytdB3hx4WuRrSJ+8y+dWbyKb62o+sEvghZMMdhv7vAirCbcF1A cnsA== X-Gm-Message-State: APjAAAWABkAFPboHOxCkDOiNwEUb4+FQBNWeJ/aQstlpWbWR6G27wyZm TmO1s5iPopriqvHbqNs+F4wlDg== X-Google-Smtp-Source: APXvYqxHjCHCFrFsgxnWqrYumB5psG22m+Be/hnjF4m6nET2BX6Fx5pTV4teAFcB6L2y+7CzAlmjZg== X-Received: by 2002:a63:d62:: with SMTP id 34mr7941909pgn.268.1576114956964; Wed, 11 Dec 2019 17:42:36 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:36 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 1/8] usb: dwc3: Registering a role switch in the DRD code. Date: Thu, 12 Dec 2019 01:42:26 +0000 Message-Id: <20191212014233.32799-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-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: Guillaume Gardet 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 v6: Fix build issue Reported-by: kbuild test robot v7: Minor fix for CONFIG_USB_ROLE_SWITCH=m case not building the role switch handling code, reported by Guillaume Gardet --- 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..331c6e997f0c 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; } +#if IS_ENABLED(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) 0 +#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 Thu Dec 12 01:42:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286713 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 4709D15AB for ; Thu, 12 Dec 2019 01:43:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 277542464B for ; Thu, 12 Dec 2019 01:43:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="V0PrWbfK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727604AbfLLBmj (ORCPT ); Wed, 11 Dec 2019 20:42:39 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37217 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727580AbfLLBmi (ORCPT ); Wed, 11 Dec 2019 20:42:38 -0500 Received: by mail-pg1-f196.google.com with SMTP id q127so281808pga.4 for ; Wed, 11 Dec 2019 17:42:38 -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=X9Kc7R9+KeUY27tDEV+sMDYPQg0vMU8CdEEpsw9B7eY=; b=V0PrWbfKF6yh5jnUesdINqEzgHzMsX3X/h8mQRQt7abSsm8BD1zIM3mTyuJAm4y3kP fjCqZ+MT657YUqC5fFq+USYJQkg/nwLbiZzbLc1ZZ/+AH1ZY2o/P7I/ogmVWFT2eoKVD VvmvB8Nw8+/gE6DnMtNB+4sghteYtNdFYbeM6Q+B1VJiUIlyNXEbJbs1yHD/dUMged95 pH+vBbrBuz/G5kKvVuB1H/0Z3wWaXELPX8OJC9XBveAInCMPrFPLT1Ygauyjsf5HBtMl 4jvvIt4F9HQcgkLnmCLBWh5/bnO15j/5DUAR1SOnmrY3lzfgR/SF7SyOLeNBzoM7XasI kbWQ== 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=X9Kc7R9+KeUY27tDEV+sMDYPQg0vMU8CdEEpsw9B7eY=; b=RmPhbFS1eX9+X0r6yUYR7jKIcO3+IZELHxTLBmAkyrBuws8J+AFanzV0ZQQePLkSaD F/eTxoE2MAQGuGXDyhh6CoJzfx38mPziNTvk6/FkCGdFjWw/lMDyMhzpAqBO9p2+eFX9 yjPv5u5rnDzjwe+aQCJUbbWk55G27uHvY07lw4yMJp0TPyCAu7pcRGB3SVVrwpbd/fyJ M+pZX/qAqv5gCltD+pnixhbAd2Iw1sxq6OL9TFalOaddZYrNLa27/u95FHRk/hxZ5HHT Z3xYMKuTpzY/zyKXtZm0PQwHVIMRMhZJG18ZNdPXnOBstl8x71jFK7QsuMOlsBNaK2JQ kjSQ== X-Gm-Message-State: APjAAAXoJK1lLSw+qpCJ/s1RM6K1SSSnY+k46qj+M4v2BUBhRiqnHCrx 2VLoMN0hL982t8QovtMZp4D2qQ== X-Google-Smtp-Source: APXvYqy0BVmYHRBfzJOVdXEzf35ykOhMUK6HJkBTVjdR49V2P5zoAJ4NwvOkopcghcK3+EabZw/nPQ== X-Received: by 2002:a62:f842:: with SMTP id c2mr7196663pfm.104.1576114958243; Wed, 11 Dec 2019 17:42:38 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:37 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 2/8] dt-bindings: usb: generic: Add role-switch-default-mode binding Date: Thu, 12 Dec 2019 01:42:27 +0000 Message-Id: <20191212014233.32799-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: John Stultz --- 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 Thu Dec 12 01:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286709 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 1E42814DB for ; Thu, 12 Dec 2019 01:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F2ED32464B for ; Thu, 12 Dec 2019 01:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="m+mTiQrt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbfLLBml (ORCPT ); Wed, 11 Dec 2019 20:42:41 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:38726 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLLBmk (ORCPT ); Wed, 11 Dec 2019 20:42:40 -0500 Received: by mail-pj1-f67.google.com with SMTP id l4so321621pjt.5 for ; Wed, 11 Dec 2019 17:42:39 -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=32ma7jm/USpVtHg7Ie1n8hF+znRzdCi92DyYoi4rfjo=; b=m+mTiQrtpDWGf8kluPe58Em+efx6c+lCdtucq14oYvmCpsKuuTM8BUXaasXe14TZYn H6Tnrvxy9hRKBqwKqGUVUHcktLAxzgl9bnPjC8dOQLAG3TIGOMTMTPOJlsQX82RKIZYF 85UTwtwfUMAhZO3fAj9PeUoGJnIbRz8p0F/qD4JkkvXymwEMZpMxeoE2fIoC6Uhehbol gpfVQ/T/xagGQllRGVpT0qupuDtYnGHiin1ia/ZG0K7GT7qJtCqlNxw4hmwts5Cxw1uM o7ZzXtR961PKot2SEb2q/gyGr3a+13GlAP7UAD8VjGNexQXecbDhcglCwtYzWsp+2s2g RC0A== 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=32ma7jm/USpVtHg7Ie1n8hF+znRzdCi92DyYoi4rfjo=; b=h9m7dMLSA5XUNTtvHGaNzWgosKkISlMSoMFO9L51POMzHmd7q5gIc5ZV/OgkCQrTRC M/LJFokq2B909ixb8x7jMIHdXmexYEUbpmieBOlbSbWnhYsT6QgQSHlWmALnq5mjgBIZ yCu5lSxj0mqhcLF6sor1MlnVvXVNr3L2DZ50+QshoJkOVhfSdjL20O3+UKIjnS9wFD2J iT4GhxheXBgjUGPMoZY8Sqc5k1ET3iQ77YBP2UA733NWVuGrXHwy57g3iAc+BrB26neN x9u8pDiaYQC9j3PMlVP/FKcIhzllhoFoPUeWum91bRBNWmx9Q0BELDT0fPEmu+H/ghCV 32PQ== X-Gm-Message-State: APjAAAVEpxvCl0I2f9QjboFO8lVW9vbziJn9LdqnLyG+GWpBCEwqnxU/ o0eHnp6vFevk2llltC3Gxx+CuQ== X-Google-Smtp-Source: APXvYqxwMBPmGhcRAfOeLiir9tLLli4TVTdqLolBlxPaPpfE7Ngtm6Agj9aoLb0yUwDUnflxYeyX5g== X-Received: by 2002:a17:902:d204:: with SMTP id t4mr6880334ply.167.1576114959256; Wed, 11 Dec 2019 17:42:39 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:38 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 3/8] usb: dwc3: Add support for role-switch-default-mode binding Date: Thu, 12 Dec 2019 01:42:28 +0000 Message-Id: <20191212014233.32799-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-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: Guillaume Gardet 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 331c6e997f0c..db68d48c2267 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 From patchwork Thu Dec 12 01:42:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286711 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 E934F14DB for ; Thu, 12 Dec 2019 01:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C8D0C22527 for ; Thu, 12 Dec 2019 01:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ADWf++LN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727631AbfLLBnL (ORCPT ); Wed, 11 Dec 2019 20:43:11 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:33998 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727626AbfLLBml (ORCPT ); Wed, 11 Dec 2019 20:42:41 -0500 Received: by mail-pj1-f66.google.com with SMTP id j11so328555pjs.1 for ; Wed, 11 Dec 2019 17:42:41 -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=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=ADWf++LNikL2sGcTcPh38acVlVtjYE212k4TEnvD+Rlztp08dFU+PiVdolU95yghh6 if+zoAeLlhz35y8sJOpcVWTpgCkbiTRdT7UVFZ8NunPzp3KQLHiuLU72mrPDlXlgSFzF Qg76tZUqRmSr54W87h1n0CZgA6NFZHf0PBE/vqGlb5jKzdYrpuWrOVyOJEBBJG/+wKbG AjkTYbw+imyPgYY5IOoJieUH9yT/QpO6cub+CG/cQiNynfS9eC9OgqL54UdE51EvzMYi I1BjdPjZYGckxWevF0rkr1EtzpTBv6ZZjAcidkSpzf8uiRC9c/6TSiuLBHGL6on42fkM pptw== 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=jz3XZ9gPuD/g+1P6LY7Aq8wTOFKwQIrTyqi7Mx3AGIU=; b=fgwUuTu6JqBd01pRtoLdO0inGik9dVgrD3sJBM6aHOZyEt33XIsJ6hDxI69v0t8RzY 5SG/6LIMUX7hrEuOL/AuE/lJcSOQkfeCotDEW+tw/UqVaQDpDHCxsgj3emTeil1TVsca yMGqJxL4p5uPY0QN3F+kH4BCyI+BkalBcmryVcYNKX3NcxEKj3HS6dsUZKodfFvAxmDX jlb9JHbsyG4fygLXiKAgsATxlrflS3DdrqVGwroe4KE8x8PJUT155Az7lh4NVJJJjUFL guj8IQQ2ZhDsh6x3cmBJviyE5Q7TEo5r7k08ZPh48gNet5SVd2yZpzcuFeuleUzBDrJY ssnw== X-Gm-Message-State: APjAAAWX0PpeZM11HPeOWbTqeMNfwoXED+R1A8O8xsx2IVdaeCObbkUD OhGqAURPYxgjvaK5IRZN0qp50C5sKGM= X-Google-Smtp-Source: APXvYqz745Iom7BCnhPJbNjWnLV0N315h5uwmC47BUMzZV6zx6EdHy7BP/H0GGZcWSHDGlWW5rf7jA== X-Received: by 2002:a17:902:8608:: with SMTP id f8mr6851979plo.106.1576114960549; Wed, 11 Dec 2019 17:42:40 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:39 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 4/8] dt-bindings: usb: dwc3: Allow clock list & resets to be more flexible Date: Thu, 12 Dec 2019 01:42:29 +0000 Message-Id: <20191212014233.32799-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Rather then adding another device specific binding to support hikey960, Rob Herring suggested we expand the current dwc3 binding to allow for variable numbers of clocks and resets. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Reviewed-by: Rob Herring Signed-off-by: John Stultz --- Documentation/devicetree/bindings/usb/dwc3.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt b/Documentation/devicetree/bindings/usb/dwc3.txt index 66780a47ad85..29768b0ca923 100644 --- a/Documentation/devicetree/bindings/usb/dwc3.txt +++ b/Documentation/devicetree/bindings/usb/dwc3.txt @@ -7,7 +7,8 @@ Required properties: - compatible: must be "snps,dwc3" - reg : Address and length of the register set for the device - interrupts: Interrupts used by the dwc3 controller. - - clock-names: should contain "ref", "bus_early", "suspend" + - clock-names: list of clock names. Ideally should be "ref", + "bus_early", "suspend" but may be less or more. - clocks: list of phandle and clock specifier pairs corresponding to entries in the clock-names property. @@ -36,7 +37,7 @@ Optional properties: - phys: from the *Generic PHY* bindings - phy-names: from the *Generic PHY* bindings; supported names are "usb2-phy" or "usb3-phy". - - resets: a single pair of phandle and reset specifier + - resets: set of phandle and reset specifier pairs - snps,usb2-lpm-disable: indicate if we don't want to enable USB2 HW LPM - snps,usb3_lpm_capable: determines if platform is USB3 LPM capable - snps,dis-start-transfer-quirk: when set, disable isoc START TRANSFER command From patchwork Thu Dec 12 01:42:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286707 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 39C6014B7 for ; Thu, 12 Dec 2019 01:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 183CD2464B for ; Thu, 12 Dec 2019 01:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cGOZzqU1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727504AbfLLBnJ (ORCPT ); Wed, 11 Dec 2019 20:43:09 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38625 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727631AbfLLBmm (ORCPT ); Wed, 11 Dec 2019 20:42:42 -0500 Received: by mail-pg1-f195.google.com with SMTP id a33so278503pgm.5 for ; Wed, 11 Dec 2019 17:42:42 -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=G6kjJoovlC6cVfetXCubnmxNfzySZyzH70fmpOskqm8=; b=cGOZzqU13JOBPam+xdKigkTIGiAjbtkPvBYtjMIcRGUuLi4JiP7MUinvcn6DCHl3if FfTvBb4dk8U5AMVmF2CjA3dX++wBfx3pTTGhYpwAXjF+gVP7q2lyOJ71aGuUEDGgLDk+ TMnP3JbWjTdAvowKhz6F66lifrsJQu8cJUerpX+PE5lpkYRjgLc7ZYnOaB5FZFDeXZLZ 4XTD82pAK9BsC4PJHfrpswrG46E7SuRpdj1/clKJtXJ/dD0FqdjFwSmynLis5GtK1lV7 /4QvRxBrdkNP0ceSSZ49Ot9qJNQWbR+IUoA7OE66lecnIgheFt5rQQ4O7VaQtW+J/H3+ w9Gw== 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=G6kjJoovlC6cVfetXCubnmxNfzySZyzH70fmpOskqm8=; b=EVDeDKXdWiljyOzW8VbdPLvsef9lCmcLpsXpJzLAQNbuV0xZW3EC04wSdNfDW3QIrr phDYD9VNhjP1aQ5FV8sJCUnbrgOix8KPkDyzJ2oAuZgV2hVdpsRyCNCzJdk2ZKhJ4Zn1 2itDl9tj4y9CzHj5XfqSfw/liXTBD6I4Ld/LX/afWrBeBHxQPdWL9MWhW2EtE6l+Cw4n //M707/UHuBkRJaqF615omYhn8qJtqldCfHVmBSaPu34OdUIQDruHVfhhA8Qa3OtykMC m8Gj7xQgY/9XtkyRIJVNd2+K/DF3vum2K/s8ZpsRYx+3+5kj2F0fSrwgxNasUotfVWQP Y5fA== X-Gm-Message-State: APjAAAXEMSaI4uuxiWiI45VkX+aG4aPijb9flt3Eey2qNdKrNnhHZQx4 jOKVztvu0YpjGSWsquaAgSuQIg== X-Google-Smtp-Source: APXvYqwpqM70vNZbKae/RwdZ2CYgbgIkvtbmpvMV4ONBua+4aE8gJ9REa97neloI95Wm/o50zRSkzw== X-Received: by 2002:a62:1a97:: with SMTP id a145mr7398556pfa.244.1576114961674; Wed, 11 Dec 2019 17:42:41 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:41 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 5/8] usb: dwc3: Rework clock initialization to be more flexible Date: Thu, 12 Dec 2019 01:42:30 +0000 Message-Id: <20191212014233.32799-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The dwc3 core binding specifies three clocks: ref, bus_early, and suspend which are all controlled in the driver together. However some variants of the hardware my not have all three clks, or some may have more. Usually this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the clks from the dts to use devm_clk_bulk_get_all() will will fetch all the clocks specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index f561c6c9e8a9..c6316d4b7593 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -289,12 +289,6 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc) return 0; } -static const struct clk_bulk_data dwc3_core_clks[] = { - { .id = "ref" }, - { .id = "bus_early" }, - { .id = "suspend" }, -}; - /* * dwc3_frame_length_adjustment - Adjusts frame length if required * @dwc3: Pointer to our controller context structure @@ -1438,11 +1432,6 @@ static int dwc3_probe(struct platform_device *pdev) if (!dwc) return -ENOMEM; - dwc->clks = devm_kmemdup(dev, dwc3_core_clks, sizeof(dwc3_core_clks), - GFP_KERNEL); - if (!dwc->clks) - return -ENOMEM; - dwc->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -1478,17 +1467,18 @@ static int dwc3_probe(struct platform_device *pdev) return PTR_ERR(dwc->reset); if (dev->of_node) { - dwc->num_clks = ARRAY_SIZE(dwc3_core_clks); - - ret = devm_clk_bulk_get(dev, dwc->num_clks, dwc->clks); + ret = devm_clk_bulk_get_all(dev, &dwc->clks); if (ret == -EPROBE_DEFER) return ret; /* * Clocks are optional, but new DT platforms should support all * clocks as required by the DT-binding. */ - if (ret) + if (ret < 0) dwc->num_clks = 0; + else + dwc->num_clks = ret; + } ret = reset_control_deassert(dwc->reset); From patchwork Thu Dec 12 01:42:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286705 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 E9FF315AB for ; Thu, 12 Dec 2019 01:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7F802464B for ; Thu, 12 Dec 2019 01:42:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UZw/F1Ml" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727644AbfLLBmx (ORCPT ); Wed, 11 Dec 2019 20:42:53 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43879 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727647AbfLLBmn (ORCPT ); Wed, 11 Dec 2019 20:42:43 -0500 Received: by mail-pl1-f193.google.com with SMTP id q16so315472plr.10 for ; Wed, 11 Dec 2019 17:42:43 -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=lzv7sY1flH0+P+bTRde+D/HgFmOOUcTmct5WYnIY1iE=; b=UZw/F1MlTuPlHpKe4kDgjY8F/v9Xiz+1gFoJAVS8UHhspGP2Fpw30FdQGna543kbZg NbdJ1yCDvKj06pyzxBU0LtWEiCOyPP2nEnN5BQp2LQPpQQh1psGtyt854LkbViLnC/lZ zz5LUJ5yIGZ2v/n8y29ac7682PdEVLzC0fdyMrtdayTHw7t725nH9/M9yyMuNfvE9asz LvvbKS5ncKH2sjpaV1y6oNpbpM55xotDt0IKntm3jKD+mR2Cbrs0sG1O55wRIIcJcdVc haJ/fBVgZw5PBDj5189st+r/ZpQMkoJcgE/UEqyhv/NtKX4ai4J9wrizbLIRKyjvs6vz 8YTw== 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=lzv7sY1flH0+P+bTRde+D/HgFmOOUcTmct5WYnIY1iE=; b=gg5hEpBEsUVWgk7zGyAEUsCV2YOsYgnzw8r7bXr5BZdh8k6Lm18ukWa8XfBbNgkHZ6 TmQ8AVsbdY0OrHJ1syi36sv/l2BMGuNoLMN6LjC4qqiA8UDQJ422rA1LQ5DBLsM87WlS IiGY1lGpZVrAFI1Bqz+BaVHcEZ0b+SRCT0pWp9n9n3Bn3WFK+EzCdGPR9ToBsfsTry+j 9nRUo0cC0dg00/vws+QMEcxnxCrwPsWWb3FZfMKvi2HyYCvKQwyyRS+PqI80FGmo/ShR eCeVWAf1lIwYCqNYiDz19a4T6mYfZPWn1tluGeUMgfFwX2/RsC6jIjKTEpnKZCGTSIEv irOg== X-Gm-Message-State: APjAAAXsJ7F4CULlhST2zQ1Okuf1EkWnRWAJDmPpAzbmw2Mpn9/HAUx/ 1DXyAUYDay42pOJH5tl7cgtM8Q== X-Google-Smtp-Source: APXvYqz1y2cw7lalEK+SC8etwGXhPJDXQAo5rWmg0AyCI1cAqs37h6s3jVRWoE17CI7K8C0/J8/9lQ== X-Received: by 2002:a17:902:43:: with SMTP id 61mr6924104pla.88.1576114962763; Wed, 11 Dec 2019 17:42:42 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:42 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v7 6/8] usb: dwc3: Rework resets initialization to be more flexible Date: Thu, 12 Dec 2019 01:42:31 +0000 Message-Id: <20191212014233.32799-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-1-john.stultz@linaro.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The dwc3 core binding specifies one reset. However some variants of the hardware may have more. Previously this was handled by using the dwc3-of-simple glue driver, but that resulted in a proliferation of bindings for for every variant, when the only difference was the clocks and resets lists. So this patch reworks the reading of the resets to fetch all the resets specified in the dts together. This patch was recommended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz --- v3: Rework dwc3 core rather then adding another dwc-of-simple binding. v6: Re-introduce this patch, on Rob's suggestion --- drivers/usb/dwc3/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index c6316d4b7593..19504b907476 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1462,7 +1462,7 @@ static int dwc3_probe(struct platform_device *pdev) dwc3_get_properties(dwc); - dwc->reset = devm_reset_control_get_optional_shared(dev, NULL); + dwc->reset = devm_reset_control_array_get(dev, true, true); if (IS_ERR(dwc->reset)) return PTR_ERR(dwc->reset); From patchwork Thu Dec 12 01:42:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286703 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 6DF2914B7 for ; Thu, 12 Dec 2019 01:42:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42FD32464B for ; Thu, 12 Dec 2019 01:42:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="raMTtuMO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727674AbfLLBmr (ORCPT ); Wed, 11 Dec 2019 20:42:47 -0500 Received: from mail-pj1-f52.google.com ([209.85.216.52]:34724 "EHLO mail-pj1-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727658AbfLLBmp (ORCPT ); Wed, 11 Dec 2019 20:42:45 -0500 Received: by mail-pj1-f52.google.com with SMTP id j11so328606pjs.1 for ; Wed, 11 Dec 2019 17:42:44 -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=d5IhBp23ryMELmIbYMLe3sqyK/4LNM7fr/2bl3WTuCg=; b=raMTtuMOBRn5KhhTiB2f+cKZAxr9j94dux8XwBg+AdQkCEszcB2OukPcmMasMfVQ06 obOieKjaUu1K6HpjLXsqBa8lKtiiUbw9JKGzh1vTkCJR9L4im0LQY6BuNMr5ET9fqipd NbyMlxiNyOUaan4utvYpFBN4yr7w+UxPKgbkXFLyK6HxJnuutbTleFouaTh9nevPuXUQ nbIlbU5Wc6+YzMdLxUN01dtD7Z6Zs0TwmqTLfw+zQx8+mWebDDRTS93U/2fmuBPbC0Gy A9F5wrvWUQDpg+Ixnzo0cMRkcfHHIALCeLm/WJUdzdL0BkxyF7vkJgeRMyh+5iuytXHU 09Ew== 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=d5IhBp23ryMELmIbYMLe3sqyK/4LNM7fr/2bl3WTuCg=; b=bYhWgbWA4Sy4WhqnNRMXvoojAZnM87eOdJod/bGPirv4vR8km7ayRRR1o9m0i/eGTu XjzIRzkxCH5wFQkl8f6x/sk50sVh0SfwseRNK3YpIxeve89DT/l1IJP1AHPsLN/HCmT3 8oHOV2uJpoteO4AdXnKKyG5CVtN9jAbVuta2GIVlf0uKHrKrOSmhRA1qByp7gNaT+BOo Udm8fqsTd+00v10F7Ig76SajUcoADm1pcgAqMl6TkVmecJKoYhM7u1SImASfIYNdwxqs lifznaDTyaaMGgkn8Tg0YkSP9+UNHGlbOWatbCn2Yg4Y8atgaIz1hG1Wrn2B6KT5WtN3 Vhvg== X-Gm-Message-State: APjAAAVIMJ+M+vmSq0Oo050XGj8PkVXQgnIQe40zMvtqTejX3lWJSH/r lVxiIIEXohdLhqLdgzZZG9qwSw== X-Google-Smtp-Source: APXvYqx4StIFuAQtmNTyT3ogARV1ggychWzi6oW+9zl7DfM3kHg2TvXG6rV3Qqhf7Sfk/eBtLVc2yw== X-Received: by 2002:a17:902:d883:: with SMTP id b3mr6353801plz.231.1576114963862; Wed, 11 Dec 2019 17:42:43 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:43 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 7/8] dt-bindings: misc: Add bindings for HiSilicon usb hub and data role switch functionality on HiKey960 Date: Thu, 12 Dec 2019 01:42:32 +0000 Message-Id: <20191212014233.32799-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-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 This patch adds binding documentation to support usb hub and usb data role switch of Hisilicon HiKey960 Board. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Yu Chen Signed-off-by: John Stultz --- v3: Reworked as usb-role-switch intermediary v7: Switched over to YAML dt binding description --- .../bindings/misc/hisilicon-hikey-usb.yaml | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml diff --git a/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml new file mode 100644 index 000000000000..1fc3b198ef73 --- /dev/null +++ b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml @@ -0,0 +1,85 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright 2019 Linaro Ltd. +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/misc/hisilicon-hikey-usb.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: HiKey960 onboard USB GPIO Hub + +maintainers: + - John Stultz + +description: | + Supports the onboard HiKey960 USB GPIO hub, which acts as a + role-switch intermediary to detect the state of the USB-C + port, to switch the hub into dual-role USB-C or host mode, + which enables the onboard USB-A host ports. + + Schematics about the hub can be found here: + https://github.com/96boards/documentation/raw/master/consumer/hikey/hikey960/hardware-docs/HiKey960_Schematics.pdf + +properties: + compatible: + items: + - const: hisilicon,gpio_hubv1 + + typec-vbus-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the typec-vbus gpio + + otg-switch-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the otg-switch gpio + + hub-vdd33-en-gpios: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to the hub 3.3v power enablement gpio + + usb-role-switch: + $ref: /schemas/types.yaml#/definitions/flag + description: Support role switch. + + port: + description: | + any connector to the data bus of this controller should be modelled + using the OF graph bindings specified, if the "usb-role-switch" + property is used. Note for this driver, two ports are supported, + the first being the endpoint that will be notified by this driver, + and the second being the endpoint that notifies this driver of a + role switch. + + +required: + - compatible + - typec-vbus-gpios + - otg-switch-gpios + - hub-vdd33-en-gpios + - usb-role-switch + - port + +additionalProperties: false + +examples: + - | + hisi_hikey_usb: hisi_hikey_usb { + compatible = "hisilicon,gpio_hubv1"; + typec-vbus-gpios = <&gpio25 2 GPIO_ACTIVE_HIGH>; + otg-switch-gpios = <&gpio25 6 GPIO_ACTIVE_HIGH>; + hub-vdd33-en-gpios = <&gpio5 6 GPIO_ACTIVE_HIGH>; + usb-role-switch; + + port { + #address-cells = <1>; + #size-cells = <0>; + + hikey_usb_ep0: endpoint@0 { + reg = <0>; + remote-endpoint = <&dwc3_role_switch>; + }; + hikey_usb_ep1: endpoint@1 { + reg = <1>; + remote-endpoint = <&rt1711h_ep>; + }; + }; + }; From patchwork Thu Dec 12 01:42:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11286701 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 E894114B7 for ; Thu, 12 Dec 2019 01:42:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B1C792077B for ; Thu, 12 Dec 2019 01:42:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fEiCjzD2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727668AbfLLBmq (ORCPT ); Wed, 11 Dec 2019 20:42:46 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:41690 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727613AbfLLBmp (ORCPT ); Wed, 11 Dec 2019 20:42:45 -0500 Received: by mail-pj1-f67.google.com with SMTP id ca19so315231pjb.8 for ; Wed, 11 Dec 2019 17:42:45 -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=okKeUrpGRdRMM1YttfPu++dPsYz1GD2rw9QI6vDbyQ4=; b=fEiCjzD2vzN0vq5Yvk8MuiJWXuVxsYSs8Ohm9vcxVt4HuVC115y9PZl/iP6JFB87sD Z06vMHEE4ybMVnm6B7L+3RrKBdtDVBRTp84+7MFNLZHJpf8NsRBH0Z0Ed5sO4PoNfUnU Oegr5NAMSpg2elSJ82GKbecEiWSG67wATl7KVgPJjgAfBDc30uzZVDRG0FGo37OymIkV 9LPlAT8nhgXDqo63ZA58CJVNCEwElFMH/L39Iu2X/xYrkdv8WghJTFXi5h2PfVcfnToh UNY9DiOlKpZvUi6F+TJqBofFvhYrN6pA1HqcBuu/rTDjYvn+/wbILUCT8RP+m+RnKhf4 0fCA== 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=okKeUrpGRdRMM1YttfPu++dPsYz1GD2rw9QI6vDbyQ4=; b=P6tyqFJaB2wN2YcvuWVrms4H7QJC7lL5Wir3qS4VSEiZjTIJ5NNZSIeXPHeHf/yv4Y ayHb6QfOClUo3WoBI0we1xaYj2nxBpyupc4IvuCv3GDEnWmtJEtCbEWUIPaiABJU4MEm aSRqTivKe8D5GgrKqfbjYGTRTON/Cu4kWcLieDUE2eSMfDybomZwszG75ciM4vecKY8L U/YP1c+w6QBKgQi9DY2OruWKs0pr/Y9ZDLXxONxUkPnzVuGE8olvUW35wPB+gxUcWXp3 AFuv/wrpd9xTeOVFRvdaf5qFfTN/r8vh7Z5kj5BIecL/yOHjR+gvgCKMKbrrzSvXejho 4fsg== X-Gm-Message-State: APjAAAVrbCOZN5s3s6x/HJonTUvI655mP96EWeZuz/Uov8Gpf2PGMLc2 lWW+lwczk/i3WA2R1JsK33bGuQ== X-Google-Smtp-Source: APXvYqxvESeTDKX7aFK/kefdrKXspH/aC5ujQXlsEEpZCgVR9C5X2KaPnz+m0r/s83c6Ales87cUNQ== X-Received: by 2002:a17:90a:250a:: with SMTP id j10mr7112628pje.134.1576114965024; Wed, 11 Dec 2019 17:42:45 -0800 (PST) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id p16sm4217996pgi.50.2019.12.11.17.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2019 17:42:44 -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 , Guillaume Gardet , Jack Pham , linux-usb@vger.kernel.org, devicetree@vger.kernel.org, John Stultz Subject: [PATCH v7 8/8] misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on Hikey960 Date: Thu, 12 Dec 2019 01:42:33 +0000 Message-Id: <20191212014233.32799-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191212014233.32799-1-john.stultz@linaro.org> References: <20191212014233.32799-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 HiKey960 has a fairly complex USB configuration due to it needing to support a USB-C port for host/device mode and multiple USB-A ports in host mode, all using a single USB controller. See schematics here: https://github.com/96boards/documentation/raw/master/consumer/hikey/hikey960/hardware-docs/HiKey960_Schematics.pdf This driver acts as a usb-role-switch intermediary, intercepting the role switch notifications from the tcpm code, and passing them on to the dwc3 core. In doing so, it also controls the onboard hub and power gpios in order to properly route the data lines between the USB-C port and the onboard hub to the USB-A ports. 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: Guillaume Gardet Cc: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Signed-off-by: Yu Chen [jstultz: Major rework to make the driver a usb-role-switch intermediary] Signed-off-by: John Stultz --- v3: * Major rework to make the driver a usb-role-switch intermediary rather then trying to do notifier callbacks from the role switch logic v7: * Add MAINTAINERS entry and more verbose Kconfig description --- MAINTAINERS | 7 ++ drivers/misc/Kconfig | 9 ++ drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 178 ++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 drivers/misc/hisi_hikey_usb.c diff --git a/MAINTAINERS b/MAINTAINERS index bd5847e802de..ae5bebc2b3e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7422,6 +7422,13 @@ F: include/uapi/linux/if_hippi.h F: net/802/hippi.c F: drivers/net/hippi/ +HIKEY960 ONBOARD USB GPIO HUB DRIVER +M: John Stultz +L: linux-kernel@vger.kernel.org +S: Maintained +F: drivers/misc/hisi_hikey_usb.c +F: Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.yaml + HISILICON SECURITY ENGINE V2 DRIVER (SEC2) M: Zaibo Xu L: linux-crypto@vger.kernel.org diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 7f0d48f406e3..563492f67be3 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -465,6 +465,15 @@ config PVPANIC a paravirtualized device provided by QEMU; it lets a virtual machine (guest) communicate panic events to the host. +config HISI_HIKEY_USB + tristate "USB GPIO Hub on HiSilicon Hikey960 Platform" + depends on OF && GPIOLIB + help + If you say yes here this adds support for the on-board USB gpio hub + found on the HiKey960, which is necssary to support switching between + the dual-role USB-C port and the USB-A host ports using only one USB + controller. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index c1860d35dc7e..e5e85ad0dd57 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -57,3 +57,4 @@ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_HABANA_AI) += habanalabs/ obj-$(CONFIG_XILINX_SDFEC) += xilinx_sdfec.o +obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c new file mode 100644 index 000000000000..32015bc9ccf6 --- /dev/null +++ b/drivers/misc/hisi_hikey_usb.c @@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Support for usb functionality of Hikey series boards + * based on Hisilicon Kirin Soc. + * + * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd. + * http://www.huawei.com + * + * Authors: Yu Chen + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEVICE_DRIVER_NAME "hisi_hikey_usb" + +#define HUB_VBUS_POWER_ON 1 +#define HUB_VBUS_POWER_OFF 0 +#define USB_SWITCH_TO_HUB 1 +#define USB_SWITCH_TO_TYPEC 0 +#define TYPEC_VBUS_POWER_ON 1 +#define TYPEC_VBUS_POWER_OFF 0 + +struct hisi_hikey_usb { + struct gpio_desc *otg_switch; + struct gpio_desc *typec_vbus; + struct gpio_desc *hub_vbus; + + struct usb_role_switch *hub_role_sw; + struct usb_role_switch *dev_role_sw; + struct notifier_block nb; +}; + +static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value); +} + +static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, + int switch_to) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to); +} + +static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, + int value) +{ + gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value); +} + +static int hub_usb_role_switch_set(struct device *dev, enum usb_role role) +{ + struct hisi_hikey_usb *hisi_hikey_usb = dev_get_drvdata(dev); + + if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) + return -EINVAL; + + switch (role) { + case USB_ROLE_NONE: + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB); + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON); + break; + case USB_ROLE_HOST: + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_ON); + break; + case USB_ROLE_DEVICE: + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); + usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); + break; + default: + break; + } + + return usb_role_switch_set_role(hisi_hikey_usb->dev_role_sw, role); +} + +static enum usb_role hub_usb_role_switch_get(struct device *dev) +{ + struct hisi_hikey_usb *hisi_hikey_usb = dev_get_drvdata(dev); + + if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) + return -EINVAL; + + return usb_role_switch_get_role(hisi_hikey_usb->dev_role_sw); +} + +static int hisi_hikey_usb_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct hisi_hikey_usb *hisi_hikey_usb; + struct usb_role_switch_desc hub_role_switch = {NULL}; + + hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL); + if (!hisi_hikey_usb) + return -ENOMEM; + + hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus", + GPIOD_OUT_LOW); + if (IS_ERR(hisi_hikey_usb->typec_vbus)) + return PTR_ERR(hisi_hikey_usb->typec_vbus); + + hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", + GPIOD_OUT_HIGH); + if (IS_ERR(hisi_hikey_usb->otg_switch)) + return PTR_ERR(hisi_hikey_usb->otg_switch); + + /* hub-vdd33-en is optional */ + hisi_hikey_usb->hub_vbus = devm_gpiod_get_optional(dev, "hub-vdd33-en", + GPIOD_OUT_HIGH); + if (IS_ERR(hisi_hikey_usb->hub_vbus)) + return PTR_ERR(hisi_hikey_usb->hub_vbus); + + hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev); + if (!hisi_hikey_usb->dev_role_sw) + return -EPROBE_DEFER; + if (IS_ERR(hisi_hikey_usb->dev_role_sw)) + return PTR_ERR(hisi_hikey_usb->dev_role_sw); + + hub_role_switch.fwnode = dev_fwnode(dev); + hub_role_switch.set = hub_usb_role_switch_set; + hub_role_switch.get = hub_usb_role_switch_get; + hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev, + &hub_role_switch); + + if (IS_ERR(hisi_hikey_usb->hub_role_sw)) { + usb_role_switch_put(hisi_hikey_usb->dev_role_sw); + return PTR_ERR(hisi_hikey_usb->hub_role_sw); + } + + platform_set_drvdata(pdev, hisi_hikey_usb); + + return 0; +} + +static int hisi_hikey_usb_remove(struct platform_device *pdev) +{ + struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev); + + if (hisi_hikey_usb->hub_role_sw) + usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw); + + if (hisi_hikey_usb->dev_role_sw) + usb_role_switch_put(hisi_hikey_usb->dev_role_sw); + + return 0; +} + +static const struct of_device_id id_table_hisi_hikey_usb[] = { + {.compatible = "hisilicon,gpio_hubv1"}, + {} +}; +MODULE_DEVICE_TABLE(of, id_table_hisi_hikey_usb); + +static struct platform_driver hisi_hikey_usb_driver = { + .probe = hisi_hikey_usb_probe, + .remove = hisi_hikey_usb_remove, + .driver = { + .name = DEVICE_DRIVER_NAME, + .of_match_table = id_table_hisi_hikey_usb, + }, +}; + +module_platform_driver(hisi_hikey_usb_driver); + +MODULE_AUTHOR("Yu Chen "); +MODULE_DESCRIPTION("Driver Support for USB functionality of Hikey"); +MODULE_LICENSE("GPL v2");