From patchwork Wed Oct 16 03:33: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: 11192305 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 07B12112B for ; Wed, 16 Oct 2019 03:35:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB04621A49 for ; Wed, 16 Oct 2019 03:35:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="e6dZ4jnO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403808AbfJPDdq (ORCPT ); Tue, 15 Oct 2019 23:33:46 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40186 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730211AbfJPDdp (ORCPT ); Tue, 15 Oct 2019 23:33:45 -0400 Received: by mail-pl1-f196.google.com with SMTP id d22so10568774pll.7 for ; Tue, 15 Oct 2019 20:33:45 -0700 (PDT) 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=GYRc8Evk3wu8EUiuELp77RSTyUut+SJabJSgyybQCKc=; b=e6dZ4jnOdh701k6NIby9LePCeZk359ThphqZ/2dmJcm5ahDdEyvbcCb7e1qoumSLz0 8j+1PiF2T63bndbhCteIdZ/+q9rAHX7I70BI2N3BlLE9Mt562iWVzRA6MOYGzlpwWKcQ GxWtdyTnInOCSf5l461dxNA5c2yEklyi3Mzj6nxxJAWzf8tSW9nlA43PAX/DEFhL1x5K wmgkPA9ikT+8E1AQJ2eAIdMSaNcViHVg26qtyYT587vUUX/1mnFB4MICD79iJd31EkHg LFcGqZVjhYpd+WkBoT7+lhEmQevDkes86Ld4ASBmJgLVKKUK3mnqhH1jmHEmjuR00Kbw n2SQ== 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=GYRc8Evk3wu8EUiuELp77RSTyUut+SJabJSgyybQCKc=; b=X+qCpSjfgVpWjURbkIni6mscEXo1mY9XdcM2G2CLY4uC/9st+f105k6cGADURzLYkz QeTbSgwgcHFqEvVjc9ss+c1j3XmKmD1jnHf0pmcuRMuYo4Sz795GP7oQo2wtWTlxxluq DYmkhx/YETLnOLLPB2VgLgVx6Jt886/yyDuGiY7l4m+IAeu9Y0W6TSQllNNoNMfkUZPx 0rPGTkXe/oj2FNvcyHNf9qXNZhQwvYoM9Exs26YP+8oHiniS6Mbqe2OHxTaZBLnRS/41 1cnFmHmGzEspQU1lRDexW15M2qayc2SZ3dx0oz+5LUiZ9ZvPODYGiPsFszBHc4Witx0y 6z0g== X-Gm-Message-State: APjAAAXBoJtIwQA31KzoFEW737u9fhQj1rOF9myb8J8QODQnx/uA9okG oQgzypjnoIy13VeQfHGh8UCWtw== X-Google-Smtp-Source: APXvYqzi4gPMxKJwhqOxXiD5FPvDSBSoufhfjLaVn4yXk8AEbK4UogbAw0pn+zPiG0oPOnXiM33JVw== X-Received: by 2002:a17:902:a988:: with SMTP id bh8mr39613879plb.303.1571196824723; Tue, 15 Oct 2019 20:33:44 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:44 -0700 (PDT) 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 , linux-usb@vger.kernel.org, devicetree@vger.kernel.org Subject: [RFC][PATCH v3 01/11] dt-bindings: usb: rt1711h: Add connector bindings Date: Wed, 16 Oct 2019 03:33:30 +0000 Message-Id: <20191016033340.1288-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 connector binding documentation for Richtek RT1711H Type-C chip driver It was noted by Rob Herring that the rt1711h binding docs doesn't include the connector binding. Thus this patch adds such documentation following the details in Documentation/devicetree/bindings/usb/typec-tcpci.txt 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: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Reviewed-by: Rob Herring Signed-off-by: John Stultz --- .../bindings/usb/richtek,rt1711h.txt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/richtek,rt1711h.txt b/Documentation/devicetree/bindings/usb/richtek,rt1711h.txt index d4cf53c071d9..e3fc57e605ed 100644 --- a/Documentation/devicetree/bindings/usb/richtek,rt1711h.txt +++ b/Documentation/devicetree/bindings/usb/richtek,rt1711h.txt @@ -6,10 +6,39 @@ Required properties: - interrupts : where a is the interrupt number and b represents an encoding of the sense and level information for the interrupt. +Required sub-node: +- connector: The "usb-c-connector" attached to the tcpci chip, the bindings + of connector node are specified in + Documentation/devicetree/bindings/connector/usb-connector.txt + Example : rt1711h@4e { compatible = "richtek,rt1711h"; reg = <0x4e>; interrupt-parent = <&gpio26>; interrupts = <0 IRQ_TYPE_LEVEL_LOW>; + + usb_con: connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = ; + sink-pdos = ; + op-sink-microwatt = <10000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb_con_ss: endpoint { + remote-endpoint = <&usb3_data_ss>; + }; + }; + }; + }; }; From patchwork Wed Oct 16 03:33: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: 11192271 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 D122F112B for ; Wed, 16 Oct 2019 03:33:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AFA7421D7C for ; Wed, 16 Oct 2019 03:33:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lGAST+mY" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403834AbfJPDdt (ORCPT ); Tue, 15 Oct 2019 23:33:49 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36302 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403819AbfJPDds (ORCPT ); Tue, 15 Oct 2019 23:33:48 -0400 Received: by mail-pg1-f196.google.com with SMTP id 23so13413104pgk.3 for ; Tue, 15 Oct 2019 20:33:46 -0700 (PDT) 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=+L6QotxBXClg8Fe4NEIvH2M7vhWfz5AENh5gfCd6GV4=; b=lGAST+mYnUw2+fFUvOyyVN68vAR+ZDOyy8WoR3kjWo+W2+qfO342xlBSDzAujCE92W xE0pXYq5oYJMudqdUUTFcA4aWTLpzR+HCUmB2mLqubMM06EZSAOSYJjIUw4X7hTl3wuZ nuUIgEUQvBCjVCKdCz7w+QZpLjGw9uKQAXLeecMbO1I9Jv6BXS5VvWMhSILKzjD9zOKQ 13+n9QYnIPx0gCFbGdo1DDHBdarXxErH5EaN8Pyqbtxwar/4fbU5+fiWPJ2fPmqi1oJM +YU3v3GRs0ICUUyn1sNwz9LHFqOGijZHx5d3agCBmyOak2HuwQbcxym7UyWvVtNxdO5H 0a8Q== 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=+L6QotxBXClg8Fe4NEIvH2M7vhWfz5AENh5gfCd6GV4=; b=dnwPCOW2iaO+gv+1YE5JPo/tAOR9ilbyQwmkULXNMwtI4GZPHirxokctoifSN6/oGU 1cM3rPOFJk1tUheKFEdxnya2cB/g4QebFI6UDm/Mn2mLZEmgLATbW7TJXMP/LVm+LW9I d2ESIS56ofexMPZfTMTsaOgZ1RB4jwuORKxs/lu1aqvibDRhBYS4/5lKpSqvmMSO1K+S pENDEEKExD2Le+jw77OezJ3FqRAm080+J2BBQWEg9au0JJrgY3Aj6ivAOd2x+Dsve9gz gHHnXc3I1Qtk8pSVrjGP1KTqacW01qt6/0VNnI+wmqR0HTMtqPKtl8HWMdHO/zJkVyt9 16RA== X-Gm-Message-State: APjAAAWsEwZBmpCHTLvAg14QMZT1k0d+cEhEowy+UNcin4ckc9SL7nAC PZ8bvof1xE2YceMjQLlbknaVLw== X-Google-Smtp-Source: APXvYqx4mHE3Pk26QZ2wQVQI9bb5Z31XRA2QB6VDKjNpj4Ri/jYSuBD2qTj2kfwGMLGU4KLE6yoqJA== X-Received: by 2002:a63:d457:: with SMTP id i23mr42038764pgj.276.1571196826240; Tue, 15 Oct 2019 20:33:46 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:45 -0700 (PDT) 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: [RFC][PATCH v3 02/11] usb: dwc3: Execute GCTL Core Soft Reset while switch modes Date: Wed, 16 Oct 2019 03:33:31 +0000 Message-Id: <20191016033340.1288-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 On the HiKey960, we need to do a GCTL soft reset when switching modes. Jack Pham also noted that in the Synopsys databook it mentions performing a GCTL CoreSoftReset when changing the PrtCapDir between device & host modes. So this patch always does a GCTL Core Soft Reset when changing the mode. 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: Yu Chen Signed-off-by: John Stultz --- v3: Remove quirk conditional, as Jack Pham noted the Synopsis databook states this should be done generally. Also, at Jacks' suggestion, make the reset call before changing the prtcap direction. --- drivers/usb/dwc3/core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 999ce5e84d3c..a039e35ec7ad 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -112,6 +112,19 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode) dwc->current_dr_role = mode; } +static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc) +{ + u32 reg; + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg |= DWC3_GCTL_CORESOFTRESET; + dwc3_writel(dwc->regs, DWC3_GCTL, reg); + + reg = dwc3_readl(dwc->regs, DWC3_GCTL); + reg &= ~DWC3_GCTL_CORESOFTRESET; + dwc3_writel(dwc->regs, DWC3_GCTL, reg); +} + static void __dwc3_set_mode(struct work_struct *work) { struct dwc3 *dwc = work_to_dwc(work); @@ -154,6 +167,9 @@ static void __dwc3_set_mode(struct work_struct *work) spin_lock_irqsave(&dwc->lock, flags); + /* Execute a GCTL Core Soft Reset when switch mode */ + dwc3_gctl_core_soft_reset(dwc); + dwc3_set_prtcap(dwc, dwc->desired_dr_role); spin_unlock_irqrestore(&dwc->lock, flags); From patchwork Wed Oct 16 03:33: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: 11192299 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 89B9C112B for ; Wed, 16 Oct 2019 03:34:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68FC021928 for ; Wed, 16 Oct 2019 03:34:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vPB51r4E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403842AbfJPDdw (ORCPT ); Tue, 15 Oct 2019 23:33:52 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44447 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403824AbfJPDds (ORCPT ); Tue, 15 Oct 2019 23:33:48 -0400 Received: by mail-pl1-f193.google.com with SMTP id q15so10559622pll.11 for ; Tue, 15 Oct 2019 20:33:48 -0700 (PDT) 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=NtLLzsDOIuiH39rP2uuMmF0oaTj9DHzaakbaIjXt74A=; b=vPB51r4EZ8stXyXSv4G88Vclvyv30hhGw3Tpf379BTU6tuj4TcKIJfGOECfS9HgZxC sOrbB6xhou5OBa2HlB+vuU2WBsw4f/epqpY2AKZc4vX3zf/GGEi7NTWl3NRCe7TWT4xh gWLBrp4TL0Jjk5b9CCugv6PxSzCLRtTIAkR1zEpMsBJX8R06I74CldwORwLPGQGe6qTL HJEJ0mLdHAx4O2EJZm2EdpYqyXc00yPju4FmuoIeGvCO0cyES07xGg+PZECCBEsIKeIj drFgq8KvXV8U7VRXLDSQCSN3+2iDEOUJ+cCsx3GB7nVHoDqZcrH2wKcd/RNABDOj72qN WTCg== 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=NtLLzsDOIuiH39rP2uuMmF0oaTj9DHzaakbaIjXt74A=; b=TNI6UfPmKVdaD3+xprmZaTINeE9nn3ve0MI6RcVrRd/7/OKa3+OMXMUONNxLQwc+LE jCyP6AJSdbsVRHFkjraBrvrH7JEB+OMldeP2RJhY0sMhwKLdoQ14jCNrgTWyIfVF6MUQ uY9aRi0AsYASAdleIoHSq5FavyP5lrUUiP/jst+gUOdux5pF1VBanFVu7mtKnvnwM9fg WyniWZZY+kSnFOrwHs5Mod4P19eIKh2OatZNk2ZpnjdhPkSszuuCeT2rjjnTnWeHvac+ 6Tmu9EtOr5STIdaJ0oJUhkxvd1/cMvWISiIhqSNGGB/0FR0AfqbEFrDFsp200zN2kouJ evXQ== X-Gm-Message-State: APjAAAXXEU8BG+jDpg0FbMZJr6lOnb3/J4vBFUHZYhpTAJ4IFaR1Pu1u 4Zlhu+xgeCf1dJcRyu8QMCsGHg== X-Google-Smtp-Source: APXvYqzFCD/6MuKpzLdXxEtnegE2Po5uAh/iIxgZiDEZd0o2kcUaDRjQ4rIow2Sz5ik6Cxtqptfa3w== X-Received: by 2002:a17:902:d691:: with SMTP id v17mr37578925ply.340.1571196827898; Tue, 15 Oct 2019 20:33:47 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:47 -0700 (PDT) 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: [RFC][PATCH v3 03/11] usb: dwc3: Increase timeout for CmdAct cleared by device controller Date: Wed, 16 Oct 2019 03:33:32 +0000 Message-Id: <20191016033340.1288-4-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 It needs more time for the device controller to clear the CmdAct of DEPCMD on Hisilicon Kirin Soc. 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: Yu Chen Signed-off-by: John Stultz --- drivers/usb/dwc3/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 86dc1db788a9..168eb4a0a9b0 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -270,7 +270,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, { const struct usb_endpoint_descriptor *desc = dep->endpoint.desc; struct dwc3 *dwc = dep->dwc; - u32 timeout = 1000; + u32 timeout = 5000; u32 saved_config = 0; u32 reg; From patchwork Wed Oct 16 03:33: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: 11192273 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 052AA112B for ; Wed, 16 Oct 2019 03:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D92B520663 for ; Wed, 16 Oct 2019 03:33:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="i5842S39" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403835AbfJPDdu (ORCPT ); Tue, 15 Oct 2019 23:33:50 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46940 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403812AbfJPDdu (ORCPT ); Tue, 15 Oct 2019 23:33:50 -0400 Received: by mail-pg1-f193.google.com with SMTP id e15so5392318pgu.13 for ; Tue, 15 Oct 2019 20:33:50 -0700 (PDT) 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=Fk56Pt1fGccXmKmQ/Jeo40yXUyiG0Au7sOVELWBpmSc=; b=i5842S39DyNZjUZRJPov05KdX7BzPpP2NUVj577HofBXaFkmDioGcqwLERfGPCtRSo HxrufDjWomrDtclywcgyQlD/y+bxJRLcjN9o9sAc0492h3Sqk9lgZvAl3G9PDq4gU/Hq T8lEnvqFyCrhZWZLbPGC3IBEqFDHD0vSeAJP6CJMI6TeFEXj9lHjQ1gMcXvUshJNlSbV hQlwzNfdpEc8o1zpF4j8MeUNFET0RjQc3rMX03QpqyJyDqQ3SaEPhKKI+dAYa8HCcRdh 3kR7U+p+H01mWN3lCCwYydpOV9lAS3XXzH9hxXY97aQyeg0idEeovmkH84X+Db9lycVc albw== 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=Fk56Pt1fGccXmKmQ/Jeo40yXUyiG0Au7sOVELWBpmSc=; b=V0x3zrdD3kZls4qGqExuqBW9T5LSxmjzPqAqxpWz7r0U1LxLkurmTJOCfwu3hFBg60 CQ0J/s/F/uSafi9SufIU43kkY8upIK1TjJaCBTdTmj2cyWvCtfk3pA9ENRGI00YHoKdf AqOM5QXLJPUVi+9eLAJrXnP0G93/vzZmboo4vELd8xkW33Pt3jBA49SubTZJFzBdnTWN zdplXI6h6/nYf6fi2QhYzLza7oKlAMhP0zek/N37pLjXA7lWsx29a0fceKmTbnGkgLtu 0UKj3pHNIF/Yn1XOsQXxzwJodZmF4SuxlrIM7j236jd8ahdxXhRXQ4I7Io1MGilkOWSo 0mHw== X-Gm-Message-State: APjAAAVSkpDBalkWsLzQ5h8Egf7i6GBDrrXWFpa7iHOyxvtWpX4K4+4n zugZBwHIOs52qFdbiTao7JUQ9Q== X-Google-Smtp-Source: APXvYqyDkJPdQQMUkmfGn1srI4a3vVQ3+fGtZ+xRSHgsO+5CqQbLMJGruDMef6xeBYAvO7XFUOWfqg== X-Received: by 2002:aa7:8046:: with SMTP id y6mr42224599pfm.178.1571196829644; Tue, 15 Oct 2019 20:33:49 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:48 -0700 (PDT) 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: [RFC][PATCH v3 04/11] dt-bindings: usb: dwc3: Allow clock list & resets to be more flexible Date: Wed, 16 Oct 2019 03:33:33 +0000 Message-Id: <20191016033340.1288-5-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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: Jack Pham Cc: linux-usb@vger.kernel.org Cc: devicetree@vger.kernel.org Suggested-by: Rob Herring Signed-off-by: John Stultz Reviewed-by: Rob Herring --- 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 Wed Oct 16 03:33:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192303 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 5A7CA139A for ; Wed, 16 Oct 2019 03:34:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 321D521928 for ; Wed, 16 Oct 2019 03:34:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="uLkbH/AL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391082AbfJPDe6 (ORCPT ); Tue, 15 Oct 2019 23:34:58 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:42356 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403837AbfJPDdv (ORCPT ); Tue, 15 Oct 2019 23:33:51 -0400 Received: by mail-pf1-f194.google.com with SMTP id q12so13780282pff.9 for ; Tue, 15 Oct 2019 20:33:51 -0700 (PDT) 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=mmGMZQlCR6mgA59oWS1f2Nk927cLgLJYDtngM3i0DmQ=; b=uLkbH/AL8pOg7wAkq783Kv7Wli+S4S1fkwXvQK1hsdZz8RMDlTmkhaDVpBDw/mkoO4 zBTWunDgn6kC1ewqFmgahk4sa4DL54pMRwCKWKiTye44tvTXsqTp6tTiQkBUQj9ZE7WX GFlecPGJ8qg9BS/QnlLtz2ltiSGv/DD9h60Nk3yaik8zidbbaF1cr9PvCiBb3MgexH43 QqgoYOBBbb1zOJvedENxG6asKQFB/TzSZAY/z04OpFQSmYX6mevmQD1DMHMmEQbMZkNW uW8J/Od3UKmRiRZSjx5lUM8HYObGLRFjd7aVMByq0wV3Rc+Qi/ZvxrF44OpKP2tjyR0R 0vhw== 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=mmGMZQlCR6mgA59oWS1f2Nk927cLgLJYDtngM3i0DmQ=; b=mBXPZ8hLiMWHKw69R+PEbx6cXKXWgtUb6MyHDSi9PM5AHRyXfVbpdUMjQ2RtjDkH0a 2FjCzdL+QMqz72Kc1l8LLWi1pG9kLsOxS3UeD7PvIc35vKzY762dRXfTzOIw8K7KuAgb iRvc3ErDHhMTq02aHHh7VTV2EE1UyYJRD3crYo1vx33P5yqmpquhQqBjgtf+VesgXwwQ qNx8zLlQuQHOdTZV/XohykOud2XGmXZ5ntHDOrgpOGgIFTZriEK9CBT4hOBFUt3fOSyM sbdAqPSoiH2b4jGs1XSODYW4+KgITW5l/zSAz40zDN9ZCxPpEsUkAdARua8u3kNZLjdd JKLw== X-Gm-Message-State: APjAAAVsEbix79V09ArRvQAwJUtkQT6mJOQuBkGWvUtuoo1+Dwi5gWNV mOU2PMs/+DS8wP9ZtVSYnt5isg== X-Google-Smtp-Source: APXvYqws+YMGIIyJ9Z71j/JJfgVn5iU2tJXSMhO0gdaPFucclq53zCDhmjLlxCTNhG2oSTVllo97hA== X-Received: by 2002:a62:e206:: with SMTP id a6mr42231705pfi.64.1571196830986; Tue, 15 Oct 2019 20:33:50 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:50 -0700 (PDT) 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: [RFC][PATCH v3 05/11] usb: dwc3: Rework clock initialization to be more flexible Date: Wed, 16 Oct 2019 03:33:34 +0000 Message-Id: <20191016033340.1288-6-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 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 reccomended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware when the only unique bits were 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: 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. --- 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 a039e35ec7ad..4d4f1836b62c 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -305,12 +305,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 @@ -1418,11 +1412,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); @@ -1458,17 +1447,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 Wed Oct 16 03:33:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192293 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 091101668 for ; Wed, 16 Oct 2019 03:34:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCACC21848 for ; Wed, 16 Oct 2019 03:34:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="M+j3OSTd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403856AbfJPDdy (ORCPT ); Tue, 15 Oct 2019 23:33:54 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35459 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403849AbfJPDdx (ORCPT ); Tue, 15 Oct 2019 23:33:53 -0400 Received: by mail-pl1-f196.google.com with SMTP id c3so10579370plo.2 for ; Tue, 15 Oct 2019 20:33:53 -0700 (PDT) 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=XYmCRZgf8b2IcaP7U8709/cAdbizYn9CNcdmOHw1lAQ=; b=M+j3OSTd6OWlEcLeVpxIyqrceKfn8UXv80YolW6qvBqb5QXn0w1KjA3liz7wZvvEPE 2jK1cjfZbCKO8KDuKnvDQSgiagX/xGJbc7M3TJeUvCEhRvnvCmaM3oJ+CzoqDax+5nDM QhYddsNAxjU+dLqhpM1jwvYZ8hXoy1hMpKir6wed8XX+ayBTHSnLwfyIamo33p9a1xp2 PAFkXAZ1JRCrng+9VkPVr1NmtmNHaKLd8mlCKTBqHOgBYVb6XVr8pEhba5xWk52mw9+8 cSsq/uXaMZ29Xuo+Uq8QcmxDRCg2hc4P7CPQKjNqb4foAoUmOCclW3wtYJbBM6L5tf0X OSTA== 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=XYmCRZgf8b2IcaP7U8709/cAdbizYn9CNcdmOHw1lAQ=; b=PX04+Wb4r1DtCykqyOwXJehh4JiilQ0HDPQ1hl498UFPsQQHgffRY5z/ICee8pfIzp 8A3Yd5nd25MTNBlGh2jAav0RgzF1ryM36JYsGDYZR5zeYslBAxRYoo2tsy+oz/UJtafe dh7yqCWV6pXH5K2wEowAR5fTvyu2vmeu/y35EsfmxTxNb0HLgED8BGWa+MyuCLmoNhvb l49QhugilTmzOvyOANLPynkO5uIVe0F0G4BntsltGAvussZ5ejuh8YCN9QIF/rAivQlu M8UwbGjZwjy7tI4aK9fEfBdmfrmZJJhQiH5Mn0dLlmjNJ+KH0MpV5f7oU2u/yKzg3PeN oUUw== X-Gm-Message-State: APjAAAUAEfFg6kW8HChdUrJX/04kLtWhfRQmTYSlQJgWv3i9d1JaKEwH u4aqRuKszhgIVAr1OFf6/FV/vA== X-Google-Smtp-Source: APXvYqwtJMHOOIbFTp5wm3D/o0iQ0CChhCx+w+5i1GrQwEE/EFW7imOCSKYWaKsUoO/zz8QDQxMKfA== X-Received: by 2002:a17:902:a605:: with SMTP id u5mr37825346plq.140.1571196832574; Tue, 15 Oct 2019 20:33:52 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:51 -0700 (PDT) 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: [RFC][PATCH v3 06/11] usb: dwc3: Rework resets initialization to be more flexible Date: Wed, 16 Oct 2019 03:33:35 +0000 Message-Id: <20191016033340.1288-7-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 my not have more. So this patch reworks the reading of the resets to fetch all the resets specified in the dts together. This patch was reccomended by Rob Herring as an alternative to creating multiple bindings for each variant of hardware when the only unique bits were 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: 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. --- 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 4d4f1836b62c..ef52ffa5d6cb 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1442,7 +1442,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 Wed Oct 16 03:33:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192295 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 D76B21668 for ; Wed, 16 Oct 2019 03:34:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC5BE21848 for ; Wed, 16 Oct 2019 03:34:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="u9L/pE1C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391068AbfJPDeu (ORCPT ); Tue, 15 Oct 2019 23:34:50 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:37531 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403849AbfJPDdz (ORCPT ); Tue, 15 Oct 2019 23:33:55 -0400 Received: by mail-pf1-f193.google.com with SMTP id y5so13797836pfo.4 for ; Tue, 15 Oct 2019 20:33:54 -0700 (PDT) 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=2PoKh0+SG7fHxZLJh2y0Lp0GiZzbHmOzaEb4WWk+/NM=; b=u9L/pE1CJ4s0MCM+ENSOrn5WX8ACrKw+f7H+culvO6PxC99AEUEIDqUc/Od//7F4ux NGKoaw5O875g7vF+TdHz5jOtu/6ZqGT/u9eVpntdnCTT247RwTDWquw2hdvSCV+fBi1V m7ETBCC7pz06d+d+CYF7H/t97DpuXf3fs4XAntVl56c3A9yJOyJQ7AmCA1cdxAs/PqEq i9JwY1zgFvlchdZKDy82Wn/K4HljT0F70ysZwFzhzmhzYxoC2a7ppnxV/j3m3sWF+toz AaM2eMUwXZBux98pSL0V4XInnIoMgsw7qVjNKuwWmC2PUBfCABDddSm/pvOPJpHR+aZz VQEA== 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=2PoKh0+SG7fHxZLJh2y0Lp0GiZzbHmOzaEb4WWk+/NM=; b=hEIkU4lBlEtwmJzmyeIm1vodSq0o9s4+qOthg4jcb9wcAnTEIkf/E+Evm5ETV+FU87 urpjFept6aa8e0geI3gzJc6Xs8j9LWTgsKyWS4ODKC6t0Dd64wyJfJ/jqrWAQSm9rPYo gJyly5iURk991rKy5S2u9ps1k5kHA+WYVGnU4XZexZVqoSyGtroyKq8mhdBVBcB5EpuB s2Ye6SqJyr9bmJlpjZXAYGsO8sdRHSMbp4cTBluHwDEsojFsGaeD3Gf4qlG28VNFk3IF wyuqoWim+rW02tJj9/HN9lT3O9B11QUSunMq3UipUX1n4s+NCYtL25sVwSH/XMTbGCNo A15w== X-Gm-Message-State: APjAAAUNWeKwMfdcWzNLy19HhPGn/88WkwBrBBn0CACQaOh/Y87FkJDT zV4FxMzbwP8oCfinWUdM9eWJqA== X-Google-Smtp-Source: APXvYqwm2S497WA37OpvJu48WtPFC2QRdjOTLBX6kJACVlFLFjKUX/3rNVLnjoD4Lp5ERBCkjIvLaQ== X-Received: by 2002:aa7:8e47:: with SMTP id d7mr11104425pfr.125.1571196834268; Tue, 15 Oct 2019 20:33:54 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:53 -0700 (PDT) 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: [RFC][PATCH v3 07/11] usb: dwc3: Registering a role switch in the DRD code. Date: Wed, 16 Oct 2019 03:33:36 +0000 Message-Id: <20191016033340.1288-8-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 --- drivers/usb/dwc3/Kconfig | 1 + drivers/usb/dwc3/core.h | 3 ++ drivers/usb/dwc3/drd.c | 66 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index 89abc6078703..1104745c41a9 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -44,6 +44,7 @@ config USB_DWC3_DUAL_ROLE bool "Dual Role mode" depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || USB_GADGET=USB_DWC3)) depends on (EXTCON=y || EXTCON=USB_DWC3) + select USB_ROLE_SWITCH help This is the default mode of working of DWC3 controller where both host and gadget features are enabled. 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..61d4fd8aead4 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -476,6 +476,52 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) return edev; } +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; +} + int dwc3_drd_init(struct dwc3 *dwc) { int ret, irq; @@ -484,7 +530,22 @@ int dwc3_drd_init(struct dwc3 *dwc) if (IS_ERR(dwc->edev)) return PTR_ERR(dwc->edev); - if (dwc->edev) { + if (device_property_read_bool(dwc->dev, "usb-role-switch")) { + struct usb_role_switch_desc dwc3_role_switch = {NULL}; + u32 mode; + + mode = DWC3_GCTL_PRTCAP_DEVICE; + + 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, mode); + } 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 +592,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 Wed Oct 16 03:33:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192291 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 B75F7112B for ; Wed, 16 Oct 2019 03:34:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 968D72086A for ; Wed, 16 Oct 2019 03:34:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="v2mpFWC0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391065AbfJPDeq (ORCPT ); Tue, 15 Oct 2019 23:34:46 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34044 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403819AbfJPDd4 (ORCPT ); Tue, 15 Oct 2019 23:33:56 -0400 Received: by mail-pl1-f194.google.com with SMTP id k7so10588084pll.1 for ; Tue, 15 Oct 2019 20:33:56 -0700 (PDT) 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=2keRpRTlNq//agdfEU+WzxjuweOfNeyW5raNbEYcYgw=; b=v2mpFWC0YeHuM2R8yAg/xDpZt4YlyYEVb2YKwXwoQsMjqhvV4fsR1Q+zHo3hChIz74 MW6PS7z0+vutQPyCMifBfWFJu7BomzYe3pJZZNJX9fBPaYzen1Y83jxgqRXYBaS7U9H5 scyF2ijATEZVAZbM+jVPL3xBacyxLHMqGCOE2s+vXhdWKMN15J0X1c+Sg2O7EyOWXzvH V52YtiHaU85DASd1pNaSNMJRInWisTGPtptGEwmH6o7Nnegid13neEpqqP3dKTUMjQnJ tvTz2rC2F9gEnOwqvQdfEPwBq0sMvAzaAjD+WU5GOr/0YMnusEvDyJFkLqPqltkOQGC4 Vz+w== 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=2keRpRTlNq//agdfEU+WzxjuweOfNeyW5raNbEYcYgw=; b=qEwisTvzRpfuXpGsO39/vhwfH6VWEvhUDbCHws+kA6ve420FEzNFxXn0d9y512tkpB 0PWIQyXRiyBrsy3dT2QpbaXcnPHV+qdLgcaEegsizddA98N/21Kfqfs/144C7iiOVizi nFcOe1xdUssqHOZvds+EOsYteQHQdnHktf/zPYxnXFy5ElHJToFa2XO+a/HxabVbd1yk Id1S8WwMxYohtDp16140Z5IdcPZGiVVabDZJLtPbBfY4vZYzt8ntcaI4A3JgE5iEeC82 +hsWI9b/SqV98pigmWmCLo/1M6PQQxnDxb3J1oXfE+uvUE9gQl+/cnWL5wiEhh+yxX49 NYIA== X-Gm-Message-State: APjAAAXS1G302eZylVymo/FDPg217wmKm/5+4qEWeqk8+1UGDpFr2XAY 3TKixFz73+JKgi9SRDEsvCa9lg== X-Google-Smtp-Source: APXvYqzHJcZTagsu+7PgWeGgCQGg5oFBlQy68utODPD6pCC+Bv83uRYHQVAk7xRaFQ4dZKLhn4gl5g== X-Received: by 2002:a17:902:7891:: with SMTP id q17mr15072798pll.241.1571196835824; Tue, 15 Oct 2019 20:33:55 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:55 -0700 (PDT) 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: [RFC][PATCH v3 08/11] dt-bindings: usb: generic: Add role-switch-default-host binding Date: Wed, 16 Oct 2019 03:33:37 +0000 Message-Id: <20191016033340.1288-9-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 --- Documentation/devicetree/bindings/usb/generic.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/generic.txt b/Documentation/devicetree/bindings/usb/generic.txt index cf5a1ad456e6..013782fde293 100644 --- a/Documentation/devicetree/bindings/usb/generic.txt +++ b/Documentation/devicetree/bindings/usb/generic.txt @@ -34,6 +34,11 @@ 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-host: boolean, indicating if usb-role-switch is enabled + the device default operation mode of controller while + usb role is USB_ROLE_NONE is host mode. If this is not + set or false, it will be assumed the default is device + mode. This is an attribute to a USB controller such as: From patchwork Wed Oct 16 03:33:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192287 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 62114112B for ; Wed, 16 Oct 2019 03:34:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 381BF217D6 for ; Wed, 16 Oct 2019 03:34:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="S8QPNSs9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403886AbfJPDec (ORCPT ); Tue, 15 Oct 2019 23:34:32 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42937 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403885AbfJPDd6 (ORCPT ); Tue, 15 Oct 2019 23:33:58 -0400 Received: by mail-pl1-f193.google.com with SMTP id e5so10561947pls.9 for ; Tue, 15 Oct 2019 20:33:57 -0700 (PDT) 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=9P5p/4dcNs8ql4OyOSsDmP/Eo0cfZOKgwuYqI45wfJg=; b=S8QPNSs9adnyu7KEv9w2knTdoCT6Ms5rsg3c0ffAASNps2kXgSHXVyQ2mcSTBv21pX HpiPueBop6ANtnLDdDM219VIxyxIDzV1XIyQLdIlsn6H7kpXN08T4H2t6Rv5Y8ZDk7Qk aWEu4HWD6MZj/ZsgBOepxlViw6srTSWs4q/Myt8R5fJJeqDVHBoUhKafpkTSWkUOAqkv VRvYg/3dGEpUstTHwXoxRrGl5n+Oy7pbRQfziY29IchEfUJjKeaQY8viJhlbdeIqprsl Kpr+296Mg3oNMAwBKtzRlp2kndkIL+mCifQBnCMWIPjvIFMe0I1ZgkomiHsoALoX5zfh Unuw== 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=9P5p/4dcNs8ql4OyOSsDmP/Eo0cfZOKgwuYqI45wfJg=; b=kkvT7A5lh/4gAhijSFJqo3oe1VPtOVYz+kOXK0fsNOGjmmrF8gToNYc+jx8oKGc/M8 gWKHbzKzbtapSUhhFMHB1e7fyTunwM1vWssgZVdMcPLBCBSi0ZcUHeNtn+ENEU2MoOBN spUR4dkP4vXsbdAg+ASzTasNvI9QG4SOahYciKgqRZLGSlGNcw83EYEQD6AhYhM3As2Z rreUOquvO5bHCp+d1Jg88ems1qdC4e7uVUs/81UDu/fPn4Et+CJyAwcw6Q/+cbd0hQ5o 05YjoU13LohhVNmWRo/zWrKiNubxvbIekrlBJUUm65glw2sXIGTtIChJAImaVdHTyap3 Kwhw== X-Gm-Message-State: APjAAAX3h6wnKhaB3UGeCQhqg6SM+90B+Dwc6pjWcQaXxy+HCkCmWKTG JaxOwV0XbijcDauxCTIY+bTg8w== X-Google-Smtp-Source: APXvYqzppbYL+EYic/A6NgNFl9sC0kKMhtR0UaCTPvDBIK3mJX+2b+D+VGulj/UhBdNR+k2Qm9/DSA== X-Received: by 2002:a17:902:322:: with SMTP id 31mr36939961pld.162.1571196837356; Tue, 15 Oct 2019 20:33:57 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:56 -0700 (PDT) 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: [RFC][PATCH v3 09/11] usb: dwc3: Add host-mode as default support Date: Wed, 16 Oct 2019 03:33:38 +0000 Message-Id: <20191016033340.1288-10-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 configuring the default role the controller assumes as host mode 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 --- drivers/usb/dwc3/core.h | 3 +++ drivers/usb/dwc3/drd.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 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 61d4fd8aead4..0e3466fe5ac4 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -489,7 +489,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; } @@ -515,7 +518,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); @@ -534,8 +540,14 @@ int dwc3_drd_init(struct dwc3 *dwc) struct usb_role_switch_desc dwc3_role_switch = {NULL}; u32 mode; - mode = DWC3_GCTL_PRTCAP_DEVICE; - + if (device_property_read_bool(dwc->dev, + "role-switch-default-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; dwc3_role_switch.get = dwc3_usb_role_switch_get; From patchwork Wed Oct 16 03:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192285 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 17A1C1668 for ; Wed, 16 Oct 2019 03:34:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8F682168B for ; Wed, 16 Oct 2019 03:34:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xYd2AltO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403921AbfJPDeC (ORCPT ); Tue, 15 Oct 2019 23:34:02 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:33597 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403898AbfJPDeA (ORCPT ); Tue, 15 Oct 2019 23:34:00 -0400 Received: by mail-pg1-f193.google.com with SMTP id i76so13415048pgc.0 for ; Tue, 15 Oct 2019 20:33:59 -0700 (PDT) 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=g5sQMXSMdWuSqvmdQD58X3h1zk5SjaH8Y+Tanu+qv7s=; b=xYd2AltOxj3y/Ve5vEQPkHNfpCqVzUI4h1Hkf4GwUtrRjBAR3I8+P5vvRXlAMF+VIj lOAoFNsMsXMtTUfsDZmToG3ETzPD4KKFUT+JgO5tIITA5efcDQc7e5ADqNqyf7OnBFo7 8Trebi8naNe9Hrv3Wf8lzKTYnqJv/rBY0PwLAhpC6iOmx5HUgiovPLa/tEUg7wBG1iiu Q4aJv6u02XbtnyN0bEGS6bXVcn/wWy9ewpbWtyWcud7BrGvhVM2CKEdrJqo9/fTpDlwd D7Bhmm6SQvPwc6Wi0UibcLOg/tqbRtIh9CqaWfWS63sbVEk2I4v0MryE86bkFYVz1Ud6 CcrA== 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=g5sQMXSMdWuSqvmdQD58X3h1zk5SjaH8Y+Tanu+qv7s=; b=uiA7Eqm4NB6h3uHiptYCgnoa2JbWjA/V3tKv+IQpxUXixHRpZh8Pt1i6HwD5WnR7ZJ B+Rt1bxjidGqP8WVXHGnpXk7+9bPdbVTJ6uJ9ZjQ322Rie2N+iLdamsEauOiPof7fNzX Fvzu+fbiILU5LWgK/FlXpVCdFQRB3BcodQm+DLli7Z7HJD+aW4c4K1SNbQcJnNMvcvQa yIc/7d/Xd/j/lYEOHTcDFoHx7NkfKqm1IcWcICz84azzzis9w5OBBSoQAJqg2fztgnbE eRK0gKbbwN/xxB9+3sZZaZG9DMGUk1nRDBtFDZp+H2XvV4ROBf2x1KiNXsD7wj6YJPBH G/RA== X-Gm-Message-State: APjAAAV9IVTsvGkZ1NbEedShZcwGW9z0mm9k/DJVpRb075SUKjlTzWKH nGwCH47zLZuO/ziBlyU9JjrYZpb2Frw= X-Google-Smtp-Source: APXvYqxdFeMofjrhcmy13r5JUspDNYDwqOMXH2WgRGuNbN+bj9FrOOgg9uXV3EB0TMfrXMdil541Aw== X-Received: by 2002:aa7:908b:: with SMTP id i11mr42817988pfa.186.1571196839121; Tue, 15 Oct 2019 20:33:59 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:33:58 -0700 (PDT) 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: [RFC][PATCH v3 10/11] dt-bindings: misc: Add bindings for HiSilicon usb hub and data role switch functionality on HiKey960 Date: Wed, 16 Oct 2019 03:33:39 +0000 Message-Id: <20191016033340.1288-11-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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: 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 --- .../bindings/misc/hisilicon-hikey-usb.txt | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt diff --git a/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt new file mode 100644 index 000000000000..1e131b38230d --- /dev/null +++ b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt @@ -0,0 +1,40 @@ +Support usb hub and usb data role switch of Hisilicon HiKey960 Board. + +----------------------------- + +Required properties: +- compatible: "hisilicon,gpio_hubv1" +- typec-vbus-gpios: gpio to control the vbus of typeC port +- otg-switch-gpios: gpio to switch DP & DM between the hub and typeC port +- hub-vdd33-en-gpios: gpio to enable the power of hub +- pinctrl-names: pin configuration state name ("default") +- pinctrl-0: pinctrl config +- usb-role-switch: flags the driver as a role switch provider +- ports: two endpoints to connect the usb core role switch provider + to the usb-c tcpm driver. + +Example +----- + 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>; + pinctrl-names = "default"; + pinctrl-0 = <&usbhub5734_pmx_func>; + 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 Wed Oct 16 03:33:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 11192279 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 E12731668 for ; Wed, 16 Oct 2019 03:34:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD47621848 for ; Wed, 16 Oct 2019 03:34:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FCG3oi+w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403940AbfJPDeE (ORCPT ); Tue, 15 Oct 2019 23:34:04 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46956 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403926AbfJPDeD (ORCPT ); Tue, 15 Oct 2019 23:34:03 -0400 Received: by mail-pg1-f195.google.com with SMTP id e15so5392558pgu.13 for ; Tue, 15 Oct 2019 20:34:01 -0700 (PDT) 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=xagVe9Yqjp30L3CH/AkBbW6XTA2w//rI82PLgD7cLOY=; b=FCG3oi+wtp8WuNIu+Mj5Xi6zpckok2804ZhLuVVAM/UPmgGPZgIRNcoZ+FLno8BalL 9xR660aCw9gHCn4sb+789tetZoeFdSJms1H/XxtkX5QccB0ZsTiyzIc5daYbhF6X8FjX h3XndUeWdDaDZCdbOkUyGiAwpjE+e26OxhohCVmIM52DCq6qgZuH89RiHbG16RPMIuoa WxmViHk759exoEZaSWw6hHZut2L7m9+Q5RGVV8sKUC+l+kjNojogq9ZerxqGEMWAfoVK i5DfeGg8sqY8Ayiudd5l2B5+1l2RU+FUpctMXiPgfZbsc3plPulJJyoT+biy3nkerECK 4brg== 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=xagVe9Yqjp30L3CH/AkBbW6XTA2w//rI82PLgD7cLOY=; b=QDloms0UJFQwN+GNgzjYYSBBOegDk7x8OGBjkfDqP5uxe/dxLq5JRoa0uAwOFWEWh4 avb+84F01gJSmMJuI/pnZf9t1ps8j6gJJnebDgm2Ui3mX6SvpGO3iHIg/+oRkWfkcUCI q70cbECR2Phi65M5OQskUqP+lulejBVUoXnbBtOhdQhJ/hzj3bTIweGJ9TCDaqjtGmxt ZJNl4LxC63hr2QPXXnPJyms45vRNBzdX+LKolQbWhaAAMZ9MSQ/NB3e+CpEclFofMa2s rzEwoccBUL+h4/nTsjQ5qU0pn4ggH/D9IlSXDq/jdNVs3vE89/gwAp7SFtRRA0TAreJZ fkfA== X-Gm-Message-State: APjAAAX1vciLwaNjl6tilbvcvs/mTriDmPre3UW6rHyxEhSDmkWJEARH xAVgiW8D0x5f8pyuThNTTnYkKw== X-Google-Smtp-Source: APXvYqyjznVOrrf/7tKLsDK6LxpZJ0h4ZdLLFiHJOkW6Rcda1DTtbAt+tRl/yGJyszQBRoTNvSQgXA== X-Received: by 2002:a62:ce01:: with SMTP id y1mr2104635pfg.176.1571196840691; Tue, 15 Oct 2019 20:34:00 -0700 (PDT) Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id l23sm748356pjy.12.2019.10.15.20.33.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 20:34:00 -0700 (PDT) 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: [RFC][PATCH v3 11/11] misc: hisi_hikey_usb: Driver to support usb functionality of Hikey960 Date: Wed, 16 Oct 2019 03:33:40 +0000 Message-Id: <20191016033340.1288-12-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191016033340.1288-1-john.stultz@linaro.org> References: <20191016033340.1288-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 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. NOTE: It was noted that controlling the TYPEC_VBUS_POWER_OFF and TYPEC_VBUS_POWER_ON values here is not reccomended. I'm looking for a way to remove that bit from the logic here, but wanted to still get feedback on this approach. 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: Yu Chen [jstultz: Major rework to make the driver a usb-role-switch intermediary] Signed-off-by: John Stultz Signed-off-by: Mauro Carvalho Chehab --- v3: * Major rework to make the driver a usb-role-switch intermediary rather then trying to do notifier callbacks from the role switch logic --- drivers/misc/Kconfig | 6 ++ drivers/misc/Makefile | 1 + drivers/misc/hisi_hikey_usb.c | 178 ++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 drivers/misc/hisi_hikey_usb.c diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index c55b63750757..bf42d1e234ea 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -466,6 +466,12 @@ 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 functionality of HiSilicon Hikey Platform" + depends on OF && GPIOLIB + help + If you say yes here you get support for usb functionality of HiSilicon Hikey Platform. + 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");