From patchwork Tue Jun 8 07:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99606C4743D for ; Tue, 8 Jun 2021 07:57:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81E336128A for ; Tue, 8 Jun 2021 07:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230323AbhFHH7s (ORCPT ); Tue, 8 Jun 2021 03:59:48 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53175 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229556AbhFHH7s (ORCPT ); Tue, 8 Jun 2021 03:59:48 -0400 X-UUID: 961ffe8519ee45a09939ee1e180ac802-20210608 X-UUID: 961ffe8519ee45a09939ee1e180ac802-20210608 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1270453410; Tue, 08 Jun 2021 15:57:53 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:57:51 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:57:50 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 01/23] dt-bindings: usb: mtu3: remove support VBUS detection of extcon Date: Tue, 8 Jun 2021 15:57:27 +0800 Message-ID: <1623139069-8173-2-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Due to no platforms use a multi-funtion pin to detect VBUS status until now when support dual role mode, prefer not to support it anymore; Another reason is that the controller doesn't support idle status, the dual role port works as device or as host, using an IDDIG pin is good enough, this will help to save another multi-function pin; And fix a typo of 'neede'; Last modify example using VBUS to turn on/off device, for device only mode, the driver doesn't get extcon. Signed-off-by: Chunfeng Yun --- .../bindings/usb/mediatek,mtu3.yaml | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml index dbc7876e0a0b..2cac7a87ce36 100644 --- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml +++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml @@ -106,7 +106,7 @@ properties: extcon: deprecated: true description: | - Phandle to the extcon device detecting the IDDIG/VBUS state, neede + Phandle to the extcon device detecting the IDDIG state, needed when supports dual-role mode. It's considered valid for compatibility reasons, not allowed for new bindings, and use "usb-role-switch" property instead. @@ -230,7 +230,7 @@ examples: }; }; - # Enable/disable device by an input gpio for VBUS pin + # Dual role switch by gpio-usb-b-connector - | #include #include @@ -244,13 +244,27 @@ examples: power-domains = <&scpsys MT2712_POWER_DOMAIN_USB2>; clocks = <&topckgen CLK_TOP_USB30_SEL>; clock-names = "sys_ck"; - dr_mode = "peripheral"; + dr_mode = "otg"; usb-role-switch; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + host0: usb@11270000 { + compatible = "mediatek,mt2712-xhci", "mediatek,mtk-xhci"; + reg = <0x11270000 0x1000>; + reg-names = "mac"; + interrupts = ; + power-domains = <&scpsys MT2712_POWER_DOMAIN_USB>; + clocks = <&topckgen CLK_TOP_USB30_SEL>, <&clk26m>; + clock-names = "sys_ck", "ref_ck"; + }; connector { compatible = "gpio-usb-b-connector", "usb-b-connector"; type = "micro"; - vbus-gpios = <&pio 13 GPIO_ACTIVE_HIGH>; + id-gpios = <&pio 12 GPIO_ACTIVE_HIGH>; + vbus-supply = <&usb_p0_vbus>; }; }; From patchwork Tue Jun 8 07:57:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456064 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D37E0C4743F for ; Tue, 8 Jun 2021 07:58:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE04661363 for ; Tue, 8 Jun 2021 07:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230145AbhFHH75 (ORCPT ); Tue, 8 Jun 2021 03:59:57 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49258 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230398AbhFHH74 (ORCPT ); Tue, 8 Jun 2021 03:59:56 -0400 X-UUID: acb27eb3aae24e45b57e0c2709290f8c-20210608 X-UUID: acb27eb3aae24e45b57e0c2709290f8c-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 225533379; Tue, 08 Jun 2021 15:58:00 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:57:58 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:57:51 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 02/23] dt-bindings: usb: mtu3: add optional property to disable usb2 ports Date: Tue, 8 Jun 2021 15:57:28 +0800 Message-ID: <1623139069-8173-3-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support to disable specific usb2 host ports, it's useful when a usb2 port is disabled on some platforms, but enabled on others for the same SoC, another case is that the different package may support different number of ports. Signed-off-by: Chunfeng Yun --- Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml index 2cac7a87ce36..3e6f2750f48d 100644 --- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml +++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml @@ -166,6 +166,12 @@ properties: description: The mask to disable u3ports, bit0 for u3port0, bit1 for u3port1, ... etc + mediatek,u2p-dis-msk: + $ref: /schemas/types.yaml#/definitions/uint32 + description: The mask to disable u2ports, bit0 for u2port0, + bit1 for u2port1, ... etc; but can't disable u2port0 if dual role mode + is enabled, so will be skipped in this case. + # Required child node when support dual-role patternProperties: "^usb@[0-9a-f]+$": From patchwork Tue Jun 8 07:57:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1C58C47082 for ; Tue, 8 Jun 2021 07:58:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EB7461208 for ; Tue, 8 Jun 2021 07:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230396AbhFHH75 (ORCPT ); Tue, 8 Jun 2021 03:59:57 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49231 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229507AbhFHH74 (ORCPT ); Tue, 8 Jun 2021 03:59:56 -0400 X-UUID: 7b7042cc4b0642e3884ba160ae5d8eee-20210608 X-UUID: 7b7042cc4b0642e3884ba160ae5d8eee-20210608 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 44543316; Tue, 08 Jun 2021 15:58:01 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:57:59 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:57:58 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 03/23] dt-bindings: usb: mtu3: add support property role-switch-default-mode Date: Tue, 8 Jun 2021 15:57:29 +0800 Message-ID: <1623139069-8173-4-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support optional property of role-switch-default-mode, used to set default mode while usb role is USB_ROLE_NONE when use usb-role-switch to switch mode. Signed-off-by: Chunfeng Yun --- Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml index 3e6f2750f48d..104f1f7edaf0 100644 --- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml +++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml @@ -116,6 +116,10 @@ properties: description: Support role switch. type: boolean + role-switch-default-mode: + enum: [host, peripheral] + default: host + connector: $ref: /connector/usb-connector.yaml# description: @@ -184,6 +188,7 @@ patternProperties: dependencies: connector: [ 'usb-role-switch' ] port: [ 'usb-role-switch' ] + role-switch-default-mode: [ 'usb-role-switch' ] wakeup-source: [ 'mediatek,syscon-wakeup' ] required: @@ -288,6 +293,7 @@ examples: wakeup-source; dr_mode = "otg"; usb-role-switch; + role-switch-default-mode = "host"; #address-cells = <1>; #size-cells = <1>; ranges; From patchwork Tue Jun 8 07:57:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5AABC48BCF for ; Tue, 8 Jun 2021 07:58:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADA5E61287 for ; Tue, 8 Jun 2021 07:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230421AbhFHH76 (ORCPT ); Tue, 8 Jun 2021 03:59:58 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49258 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230414AbhFHH75 (ORCPT ); Tue, 8 Jun 2021 03:59:57 -0400 X-UUID: e8b6c510f11f4b85ae010398e53fec28-20210608 X-UUID: e8b6c510f11f4b85ae010398e53fec28-20210608 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 566930608; Tue, 08 Jun 2021 15:58:02 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:00 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:57:59 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 04/23] dt-bindings: usb: mtu3: add wakeup interrupt Date: Tue, 8 Jun 2021 15:57:30 +0800 Message-ID: <1623139069-8173-5-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add an dedicated interrupt which is usually EINT to support runtime PM, meanwhile add "interrupt-names" property, for backward compatibility, it's optional and used when wakeup interrupt exists Signed-off-by: Chunfeng Yun --- .../devicetree/bindings/usb/mediatek,mtu3.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml index 104f1f7edaf0..77db1233516e 100644 --- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml +++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.yaml @@ -38,7 +38,18 @@ properties: - const: ippc interrupts: - maxItems: 1 + description: + use "interrupts-extended" when the interrupts are connected to the + separate interrupt controllers + minItems: 1 + items: + - description: SSUSB device controller interrupt + - description: optional, wakeup interrupt used to support runtime PM + + interrupt-names: + items: + - const: device + - const: wakeup power-domains: description: A phandle to USB power domain node to control USB's MTCMOS From patchwork Tue Jun 8 07:57:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E2DEC48BD1 for ; Tue, 8 Jun 2021 07:58:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1BC3B6128B for ; Tue, 8 Jun 2021 07:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbhFHH77 (ORCPT ); Tue, 8 Jun 2021 03:59:59 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49289 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S229556AbhFHH76 (ORCPT ); Tue, 8 Jun 2021 03:59:58 -0400 X-UUID: c72503c1d3b94a7faa17b529fecce6e5-20210608 X-UUID: c72503c1d3b94a7faa17b529fecce6e5-20210608 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 927584645; Tue, 08 Jun 2021 15:58:02 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:01 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:00 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 05/23] usb: mtu3: power down device IP by default Date: Tue, 8 Jun 2021 15:57:31 +0800 Message-ID: <1623139069-8173-6-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Power down device IP by default until @udc_start is called. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 6b5da98de648..e306b93c007d 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -921,16 +921,15 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb) device_init_wakeup(dev, true); + /* power down device IP for power saving by default */ + mtu3_stop(mtu); + ret = mtu3_gadget_setup(mtu); if (ret) { dev_err(dev, "mtu3 gadget init failed:%d\n", ret); goto gadget_err; } - /* init as host mode, power down device IP for power saving */ - if (mtu->ssusb->dr_mode == USB_DR_MODE_OTG) - mtu3_stop(mtu); - ssusb_dev_debugfs_init(ssusb); dev_dbg(dev, " %s() done...\n", __func__); From patchwork Tue Jun 8 07:57:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D470C48BCF for ; Tue, 8 Jun 2021 07:58:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16ED861287 for ; Tue, 8 Jun 2021 07:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbhFHIAD (ORCPT ); Tue, 8 Jun 2021 04:00:03 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53395 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230468AbhFHIAB (ORCPT ); Tue, 8 Jun 2021 04:00:01 -0400 X-UUID: 1a6c6aec8d56468b925f5e9622be2249-20210608 X-UUID: 1a6c6aec8d56468b925f5e9622be2249-20210608 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 933752272; Tue, 08 Jun 2021 15:58:04 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:02 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:01 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 06/23] usb: mtu3: power down port when power down device IP Date: Tue, 8 Jun 2021 15:57:32 +0800 Message-ID: <1623139069-8173-7-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org When power down device IP, we can also power down device port, then power on the port again when power on device ip, it's helpful to make device ip enter ip sleep mode. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index e306b93c007d..562f4357831e 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -334,6 +334,10 @@ void mtu3_start(struct mtu3 *mtu) mtu3_readl(mbase, U3D_DEVICE_CONTROL)); mtu3_clrbits(mtu->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); + if (mtu->is_u3_ip) + mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); + + mtu3_clrbits(mtu->ippc_base, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); mtu3_csr_init(mtu); mtu3_set_speed(mtu, mtu->speed); @@ -356,6 +360,11 @@ void mtu3_stop(struct mtu3 *mtu) mtu3_dev_on_off(mtu, 0); mtu->is_active = 0; + + if (mtu->is_u3_ip) + mtu3_setbits(mtu->ippc_base, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); + + mtu3_setbits(mtu->ippc_base, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); mtu3_setbits(mtu->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); } From patchwork Tue Jun 8 07:57:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECC32C4743D for ; Tue, 8 Jun 2021 07:58:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D52BC61289 for ; Tue, 8 Jun 2021 07:58:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230514AbhFHIAB (ORCPT ); Tue, 8 Jun 2021 04:00:01 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53358 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230448AbhFHIAA (ORCPT ); Tue, 8 Jun 2021 04:00:00 -0400 X-UUID: c19e3ec7b6794f9e9fa0ed358f2c3cfe-20210608 X-UUID: c19e3ec7b6794f9e9fa0ed358f2c3cfe-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 763172550; Tue, 08 Jun 2021 15:58:04 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:03 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:02 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 07/23] usb: mtu3: remove wakelock Date: Tue, 8 Jun 2021 15:57:33 +0800 Message-ID: <1623139069-8173-8-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Prefer to use /sys/power/wake_lock instead. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 04f666e85731..82301001f2f6 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -174,11 +174,8 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, break; case MTU3_VBUS_OFF: mtu3_stop(mtu); - pm_relax(ssusb->dev); break; case MTU3_VBUS_VALID: - /* avoid suspend when works as device */ - pm_stay_awake(ssusb->dev); mtu3_start(mtu); break; default: From patchwork Tue Jun 8 07:57:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F312AC48BE0 for ; Tue, 8 Jun 2021 07:58:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E249C6128A for ; Tue, 8 Jun 2021 07:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230526AbhFHIAE (ORCPT ); Tue, 8 Jun 2021 04:00:04 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53409 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230508AbhFHIAC (ORCPT ); Tue, 8 Jun 2021 04:00:02 -0400 X-UUID: 85fd1e8ed4a440da9bc54b8049bee8e1-20210608 X-UUID: 85fd1e8ed4a440da9bc54b8049bee8e1-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 3534966; Tue, 08 Jun 2021 15:58:05 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:04 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:03 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 08/23] usb: mtu3: drop support vbus detection Date: Tue, 8 Jun 2021 15:57:34 +0800 Message-ID: <1623139069-8173-9-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Until now it's never used on any platform, and will not used later. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 7 ------ drivers/usb/mtu3/mtu3_dr.c | 50 ++------------------------------------ 2 files changed, 2 insertions(+), 55 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 531b9c78d7c3..df2856782426 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -192,10 +192,6 @@ struct mtu3_gpd_ring { /** * @vbus: vbus 5V used by host mode * @edev: external connector used to detect vbus and iddig changes -* @vbus_nb: notifier for vbus detection -* @vbus_work : work of vbus detection notifier, used to avoid sleep in -* notifier callback which is atomic context -* @vbus_event : event of vbus detecion notifier * @id_nb : notifier for iddig(idpin) detection * @id_work : work of iddig detection notifier * @id_event : event of iddig detecion notifier @@ -209,9 +205,6 @@ struct mtu3_gpd_ring { struct otg_switch_mtk { struct regulator *vbus; struct extcon_dev *edev; - struct notifier_block vbus_nb; - struct work_struct vbus_work; - unsigned long vbus_event; struct notifier_block id_nb; struct work_struct id_work; unsigned long id_event; diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 82301001f2f6..89ad448f2b2d 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -147,10 +147,6 @@ int ssusb_set_vbus(struct otg_switch_mtk *otg_sx, int is_on) return 0; } -/* - * switch to host: -> MTU3_VBUS_OFF --> MTU3_ID_GROUND - * switch to device: -> MTU3_ID_FLOAT --> MTU3_VBUS_VALID - */ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, enum mtu3_vbus_id_state status) { @@ -163,6 +159,7 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, switch (status) { case MTU3_ID_GROUND: + mtu3_stop(mtu); switch_port_to_host(ssusb); ssusb_set_vbus(otg_sx, 1); ssusb->is_host = true; @@ -171,11 +168,6 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, ssusb->is_host = false; ssusb_set_vbus(otg_sx, 0); switch_port_to_device(ssusb); - break; - case MTU3_VBUS_OFF: - mtu3_stop(mtu); - break; - case MTU3_VBUS_VALID: mtu3_start(mtu); break; default: @@ -194,17 +186,6 @@ static void ssusb_id_work(struct work_struct *work) ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); } -static void ssusb_vbus_work(struct work_struct *work) -{ - struct otg_switch_mtk *otg_sx = - container_of(work, struct otg_switch_mtk, vbus_work); - - if (otg_sx->vbus_event) - ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID); - else - ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF); -} - /* * @ssusb_id_notifier is called in atomic context, but @ssusb_set_mailbox * may sleep, so use work queue here @@ -221,18 +202,6 @@ static int ssusb_id_notifier(struct notifier_block *nb, return NOTIFY_DONE; } -static int ssusb_vbus_notifier(struct notifier_block *nb, - unsigned long event, void *ptr) -{ - struct otg_switch_mtk *otg_sx = - container_of(nb, struct otg_switch_mtk, vbus_nb); - - otg_sx->vbus_event = event; - schedule_work(&otg_sx->vbus_work); - - return NOTIFY_DONE; -} - static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) { struct ssusb_mtk *ssusb = @@ -244,14 +213,6 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) if (!edev) return 0; - otg_sx->vbus_nb.notifier_call = ssusb_vbus_notifier; - ret = devm_extcon_register_notifier(ssusb->dev, edev, EXTCON_USB, - &otg_sx->vbus_nb); - if (ret < 0) { - dev_err(ssusb->dev, "failed to register notifier for USB\n"); - return ret; - } - otg_sx->id_nb.notifier_call = ssusb_id_notifier; ret = devm_extcon_register_notifier(ssusb->dev, edev, EXTCON_USB_HOST, &otg_sx->id_nb); @@ -260,15 +221,12 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) return ret; } - dev_dbg(ssusb->dev, "EXTCON_USB: %d, EXTCON_USB_HOST: %d\n", - extcon_get_state(edev, EXTCON_USB), + dev_dbg(ssusb->dev, "EXTCON_USB_HOST: %d\n", extcon_get_state(edev, EXTCON_USB_HOST)); /* default as host, switch to device mode if needed */ if (extcon_get_state(edev, EXTCON_USB_HOST) == false) ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); - if (extcon_get_state(edev, EXTCON_USB) == true) - ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID); return 0; } @@ -285,12 +243,10 @@ void ssusb_mode_switch(struct ssusb_mtk *ssusb, int to_host) if (to_host) { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); - ssusb_set_mailbox(otg_sx, MTU3_VBUS_OFF); ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND); } else { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE); ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); - ssusb_set_mailbox(otg_sx, MTU3_VBUS_VALID); } } @@ -365,7 +321,6 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) int ret = 0; INIT_WORK(&otg_sx->id_work, ssusb_id_work); - INIT_WORK(&otg_sx->vbus_work, ssusb_vbus_work); if (otg_sx->manual_drd_enabled) ssusb_dr_debugfs_init(ssusb); @@ -382,6 +337,5 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb) struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; cancel_work_sync(&otg_sx->id_work); - cancel_work_sync(&otg_sx->vbus_work); usb_role_switch_unregister(otg_sx->role_sw); } From patchwork Tue Jun 8 07:57:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE29BC48BD1 for ; Tue, 8 Jun 2021 07:58:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ACE566128A for ; Tue, 8 Jun 2021 07:58:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbhFHIAD (ORCPT ); Tue, 8 Jun 2021 04:00:03 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49337 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230475AbhFHIAB (ORCPT ); Tue, 8 Jun 2021 04:00:01 -0400 X-UUID: 46e9a1638e11407b8b74b780c374e03a-20210608 X-UUID: 46e9a1638e11407b8b74b780c374e03a-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1208718175; Tue, 08 Jun 2021 15:58:06 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:05 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:04 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 09/23] usb: mtu3: use enum usb_role instead of private defined ones Date: Tue, 8 Jun 2021 15:57:35 +0800 Message-ID: <1623139069-8173-10-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Now we mainly use usb-role-switch to set dual role mode, and all three ways supported use the same function to switch mode, use usb_role enum will make code clear Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.c | 52 +++++++++++--------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 89ad448f2b2d..7eabce9d5f3b 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -16,29 +16,6 @@ #define USB2_PORT 2 #define USB3_PORT 3 -enum mtu3_vbus_id_state { - MTU3_ID_FLOAT = 1, - MTU3_ID_GROUND, - MTU3_VBUS_OFF, - MTU3_VBUS_VALID, -}; - -static char *mailbox_state_string(enum mtu3_vbus_id_state state) -{ - switch (state) { - case MTU3_ID_FLOAT: - return "ID_FLOAT"; - case MTU3_ID_GROUND: - return "ID_GROUND"; - case MTU3_VBUS_OFF: - return "VBUS_OFF"; - case MTU3_VBUS_VALID: - return "VBUS_VALID"; - default: - return "UNKNOWN"; - } -} - static void toggle_opstate(struct ssusb_mtk *ssusb) { if (!ssusb->otg_switch.is_u3_drd) { @@ -147,31 +124,32 @@ int ssusb_set_vbus(struct otg_switch_mtk *otg_sx, int is_on) return 0; } -static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx, - enum mtu3_vbus_id_state status) +static void ssusb_set_role(struct otg_switch_mtk *otg_sx, enum usb_role role) { struct ssusb_mtk *ssusb = container_of(otg_sx, struct ssusb_mtk, otg_switch); struct mtu3 *mtu = ssusb->u3d; - dev_dbg(ssusb->dev, "mailbox %s\n", mailbox_state_string(status)); - mtu3_dbg_trace(ssusb->dev, "mailbox %s", mailbox_state_string(status)); + dev_dbg(ssusb->dev, "set role : %d\n", role); + mtu3_dbg_trace(ssusb->dev, "set role : %d", role); - switch (status) { - case MTU3_ID_GROUND: + switch (role) { + case USB_ROLE_HOST: mtu3_stop(mtu); switch_port_to_host(ssusb); ssusb_set_vbus(otg_sx, 1); ssusb->is_host = true; break; - case MTU3_ID_FLOAT: + case USB_ROLE_DEVICE: ssusb->is_host = false; ssusb_set_vbus(otg_sx, 0); switch_port_to_device(ssusb); mtu3_start(mtu); break; + case USB_ROLE_NONE: + break; default: - dev_err(ssusb->dev, "invalid state\n"); + dev_err(ssusb->dev, "invalid role\n"); } } @@ -181,13 +159,13 @@ static void ssusb_id_work(struct work_struct *work) container_of(work, struct otg_switch_mtk, id_work); if (otg_sx->id_event) - ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND); + ssusb_set_role(otg_sx, USB_ROLE_HOST); else - ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); + ssusb_set_role(otg_sx, USB_ROLE_DEVICE); } /* - * @ssusb_id_notifier is called in atomic context, but @ssusb_set_mailbox + * @ssusb_id_notifier is called in atomic context, but ssusb_set_role() * may sleep, so use work queue here */ static int ssusb_id_notifier(struct notifier_block *nb, @@ -226,7 +204,7 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) /* default as host, switch to device mode if needed */ if (extcon_get_state(edev, EXTCON_USB_HOST) == false) - ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); + ssusb_set_role(otg_sx, USB_ROLE_DEVICE); return 0; } @@ -243,10 +221,10 @@ void ssusb_mode_switch(struct ssusb_mtk *ssusb, int to_host) if (to_host) { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); - ssusb_set_mailbox(otg_sx, MTU3_ID_GROUND); + ssusb_set_role(otg_sx, USB_ROLE_HOST); } else { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE); - ssusb_set_mailbox(otg_sx, MTU3_ID_FLOAT); + ssusb_set_role(otg_sx, USB_ROLE_DEVICE); } } From patchwork Tue Jun 8 07:57:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5321BC48BE6 for ; Tue, 8 Jun 2021 07:58:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 396DE61208 for ; Tue, 8 Jun 2021 07:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231133AbhFHIAF (ORCPT ); Tue, 8 Jun 2021 04:00:05 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53422 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230473AbhFHIAD (ORCPT ); Tue, 8 Jun 2021 04:00:03 -0400 X-UUID: 8c09d2b8981a42c8b79a01d95003533d-20210608 X-UUID: 8c09d2b8981a42c8b79a01d95003533d-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 911552793; Tue, 08 Jun 2021 15:58:07 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n2.mediatek.inc (172.21.101.130) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:06 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:05 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 10/23] usb: mtu3: rebuild role switch flow of extcon Date: Tue, 8 Jun 2021 15:57:36 +0800 Message-ID: <1623139069-8173-11-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org This is a preparation patch to plan to use the same work to handle role switch for all three supported ways. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 9 +++--- drivers/usb/mtu3/mtu3_dr.c | 61 +++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index df2856782426..daf2b294ccdf 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -21,6 +21,7 @@ #include #include #include +#include struct mtu3; struct mtu3_ep; @@ -193,8 +194,8 @@ struct mtu3_gpd_ring { * @vbus: vbus 5V used by host mode * @edev: external connector used to detect vbus and iddig changes * @id_nb : notifier for iddig(idpin) detection -* @id_work : work of iddig detection notifier -* @id_event : event of iddig detecion notifier +* @dr_work : work for drd mode switch, used to avoid sleep in atomic context +* @desired_role : role desired to switch * @role_sw : use USB Role Switch to support dual-role switch, can't use * extcon at the same time, and extcon is deprecated. * @role_sw_used : true when the USB Role Switch is used. @@ -206,8 +207,8 @@ struct otg_switch_mtk { struct regulator *vbus; struct extcon_dev *edev; struct notifier_block id_nb; - struct work_struct id_work; - unsigned long id_event; + struct work_struct dr_work; + enum usb_role desired_role; struct usb_role_switch *role_sw; bool role_sw_used; bool is_u3_drd; diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 7eabce9d5f3b..1cf56f129b15 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -7,8 +7,6 @@ * Author: Chunfeng Yun */ -#include - #include "mtu3.h" #include "mtu3_dr.h" #include "mtu3_debug.h" @@ -124,16 +122,28 @@ int ssusb_set_vbus(struct otg_switch_mtk *otg_sx, int is_on) return 0; } -static void ssusb_set_role(struct otg_switch_mtk *otg_sx, enum usb_role role) +static void ssusb_mode_sw_work(struct work_struct *work) { + struct otg_switch_mtk *otg_sx = + container_of(work, struct otg_switch_mtk, dr_work); struct ssusb_mtk *ssusb = container_of(otg_sx, struct ssusb_mtk, otg_switch); struct mtu3 *mtu = ssusb->u3d; + enum usb_role desired_role = otg_sx->desired_role; + enum usb_role current_role; + + current_role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; + + if (desired_role == USB_ROLE_NONE) + desired_role = USB_ROLE_HOST; - dev_dbg(ssusb->dev, "set role : %d\n", role); - mtu3_dbg_trace(ssusb->dev, "set role : %d", role); + if (current_role == desired_role) + return; + + dev_dbg(ssusb->dev, "set role : %s\n", usb_role_string(desired_role)); + mtu3_dbg_trace(ssusb->dev, "set role : %s", usb_role_string(desired_role)); - switch (role) { + switch (desired_role) { case USB_ROLE_HOST: mtu3_stop(mtu); switch_port_to_host(ssusb); @@ -147,35 +157,30 @@ static void ssusb_set_role(struct otg_switch_mtk *otg_sx, enum usb_role role) mtu3_start(mtu); break; case USB_ROLE_NONE: - break; default: dev_err(ssusb->dev, "invalid role\n"); } } -static void ssusb_id_work(struct work_struct *work) +static void ssusb_set_mode(struct otg_switch_mtk *otg_sx, enum usb_role role) { - struct otg_switch_mtk *otg_sx = - container_of(work, struct otg_switch_mtk, id_work); + struct ssusb_mtk *ssusb = + container_of(otg_sx, struct ssusb_mtk, otg_switch); - if (otg_sx->id_event) - ssusb_set_role(otg_sx, USB_ROLE_HOST); - else - ssusb_set_role(otg_sx, USB_ROLE_DEVICE); + if (ssusb->dr_mode != USB_DR_MODE_OTG) + return; + + otg_sx->desired_role = role; + queue_work(system_freezable_wq, &otg_sx->dr_work); } -/* - * @ssusb_id_notifier is called in atomic context, but ssusb_set_role() - * may sleep, so use work queue here - */ static int ssusb_id_notifier(struct notifier_block *nb, unsigned long event, void *ptr) { struct otg_switch_mtk *otg_sx = container_of(nb, struct otg_switch_mtk, id_nb); - otg_sx->id_event = event; - schedule_work(&otg_sx->id_work); + ssusb_set_mode(otg_sx, event ? USB_ROLE_HOST : USB_ROLE_DEVICE); return NOTIFY_DONE; } @@ -199,12 +204,12 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) return ret; } - dev_dbg(ssusb->dev, "EXTCON_USB_HOST: %d\n", - extcon_get_state(edev, EXTCON_USB_HOST)); + ret = extcon_get_state(edev, EXTCON_USB_HOST); + dev_dbg(ssusb->dev, "EXTCON_USB_HOST: %d\n", ret); /* default as host, switch to device mode if needed */ - if (extcon_get_state(edev, EXTCON_USB_HOST) == false) - ssusb_set_role(otg_sx, USB_ROLE_DEVICE); + if (!ret) + ssusb_set_mode(otg_sx, USB_ROLE_DEVICE); return 0; } @@ -221,10 +226,10 @@ void ssusb_mode_switch(struct ssusb_mtk *ssusb, int to_host) if (to_host) { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); - ssusb_set_role(otg_sx, USB_ROLE_HOST); + ssusb_set_mode(otg_sx, USB_ROLE_HOST); } else { ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE); - ssusb_set_role(otg_sx, USB_ROLE_DEVICE); + ssusb_set_mode(otg_sx, USB_ROLE_DEVICE); } } @@ -298,7 +303,7 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; int ret = 0; - INIT_WORK(&otg_sx->id_work, ssusb_id_work); + INIT_WORK(&otg_sx->dr_work, ssusb_mode_sw_work); if (otg_sx->manual_drd_enabled) ssusb_dr_debugfs_init(ssusb); @@ -314,6 +319,6 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb) { struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; - cancel_work_sync(&otg_sx->id_work); + cancel_work_sync(&otg_sx->dr_work); usb_role_switch_unregister(otg_sx->role_sw); } From patchwork Tue Jun 8 07:57:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED4A5C48BE8 for ; Tue, 8 Jun 2021 07:58:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D970261285 for ; Tue, 8 Jun 2021 07:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231165AbhFHIAG (ORCPT ); Tue, 8 Jun 2021 04:00:06 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49376 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230525AbhFHIAE (ORCPT ); Tue, 8 Jun 2021 04:00:04 -0400 X-UUID: 6942b27bea5b4653b3877847b9233af5-20210608 X-UUID: 6942b27bea5b4653b3877847b9233af5-20210608 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 889753829; Tue, 08 Jun 2021 15:58:08 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:06 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:06 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 11/23] usb: mtu3: add helper to get pointer of ssusb_mtk struct Date: Tue, 8 Jun 2021 15:57:37 +0800 Message-ID: <1623139069-8173-12-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add a helper to get pointer of ssusb_mtk struct from the pointer of otg_switch_mtk struct. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 1cf56f129b15..486d26a366b8 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -14,6 +14,11 @@ #define USB2_PORT 2 #define USB3_PORT 3 +static inline struct ssusb_mtk *otg_sx_to_ssusb(struct otg_switch_mtk *otg_sx) +{ + return container_of(otg_sx, struct ssusb_mtk, otg_switch); +} + static void toggle_opstate(struct ssusb_mtk *ssusb) { if (!ssusb->otg_switch.is_u3_drd) { @@ -98,8 +103,7 @@ static void switch_port_to_device(struct ssusb_mtk *ssusb) int ssusb_set_vbus(struct otg_switch_mtk *otg_sx, int is_on) { - struct ssusb_mtk *ssusb = - container_of(otg_sx, struct ssusb_mtk, otg_switch); + struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); struct regulator *vbus = otg_sx->vbus; int ret; @@ -126,8 +130,7 @@ static void ssusb_mode_sw_work(struct work_struct *work) { struct otg_switch_mtk *otg_sx = container_of(work, struct otg_switch_mtk, dr_work); - struct ssusb_mtk *ssusb = - container_of(otg_sx, struct ssusb_mtk, otg_switch); + struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); struct mtu3 *mtu = ssusb->u3d; enum usb_role desired_role = otg_sx->desired_role; enum usb_role current_role; @@ -164,8 +167,7 @@ static void ssusb_mode_sw_work(struct work_struct *work) static void ssusb_set_mode(struct otg_switch_mtk *otg_sx, enum usb_role role) { - struct ssusb_mtk *ssusb = - container_of(otg_sx, struct ssusb_mtk, otg_switch); + struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); if (ssusb->dr_mode != USB_DR_MODE_OTG) return; @@ -187,8 +189,7 @@ static int ssusb_id_notifier(struct notifier_block *nb, static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) { - struct ssusb_mtk *ssusb = - container_of(otg_sx, struct ssusb_mtk, otg_switch); + struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); struct extcon_dev *edev = otg_sx->edev; int ret; @@ -283,8 +284,7 @@ static enum usb_role ssusb_role_sw_get(struct usb_role_switch *sw) static int ssusb_role_sw_register(struct otg_switch_mtk *otg_sx) { struct usb_role_switch_desc role_sx_desc = { 0 }; - struct ssusb_mtk *ssusb = - container_of(otg_sx, struct ssusb_mtk, otg_switch); + struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); if (!otg_sx->role_sw_used) return 0; From patchwork Tue Jun 8 07:57:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CADFFC49EA3 for ; Tue, 8 Jun 2021 07:58:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B515E61208 for ; Tue, 8 Jun 2021 07:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbhFHIAH (ORCPT ); Tue, 8 Jun 2021 04:00:07 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49395 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231151AbhFHIAG (ORCPT ); Tue, 8 Jun 2021 04:00:06 -0400 X-UUID: 7e1a97eb2e474ef99b480ef8eba83467-20210608 X-UUID: 7e1a97eb2e474ef99b480ef8eba83467-20210608 Received: from mtkcas06.mediatek.inc [(172.21.101.30)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1351158784; Tue, 08 Jun 2021 15:58:09 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:07 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:07 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 12/23] usb: mtu3: use force mode for dual role switch Date: Tue, 8 Jun 2021 15:57:38 +0800 Message-ID: <1623139069-8173-13-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Force IDDIG status for all three ways of dual role switch, this is needed when use Type-C to switch mode. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.c | 10 +++------- drivers/usb/mtu3/mtu3_host.c | 6 +----- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 486d26a366b8..cf9e5b59a77e 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -148,12 +148,14 @@ static void ssusb_mode_sw_work(struct work_struct *work) switch (desired_role) { case USB_ROLE_HOST: + ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); mtu3_stop(mtu); switch_port_to_host(ssusb); ssusb_set_vbus(otg_sx, 1); ssusb->is_host = true; break; case USB_ROLE_DEVICE: + ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE); ssusb->is_host = false; ssusb_set_vbus(otg_sx, 0); switch_port_to_device(ssusb); @@ -225,13 +227,7 @@ void ssusb_mode_switch(struct ssusb_mtk *ssusb, int to_host) { struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; - if (to_host) { - ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); - ssusb_set_mode(otg_sx, USB_ROLE_HOST); - } else { - ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE); - ssusb_set_mode(otg_sx, USB_ROLE_DEVICE); - } + ssusb_set_mode(otg_sx, to_host ? USB_ROLE_HOST : USB_ROLE_DEVICE); } void ssusb_set_force_mode(struct ssusb_mtk *ssusb, diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c index 0a8cd446cf1b..93a1a4c11e1e 100644 --- a/drivers/usb/mtu3/mtu3_host.c +++ b/drivers/usb/mtu3/mtu3_host.c @@ -213,8 +213,6 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) static void ssusb_host_setup(struct ssusb_mtk *ssusb) { - struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; - host_ports_num_get(ssusb); /* @@ -222,9 +220,7 @@ static void ssusb_host_setup(struct ssusb_mtk *ssusb) * if support OTG, gadget driver will switch port0 to device mode */ ssusb_host_enable(ssusb); - - if (otg_sx->manual_drd_enabled) - ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); + ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST); /* if port0 supports dual-role, works as host mode by default */ ssusb_set_vbus(&ssusb->otg_switch, 1); From patchwork Tue Jun 8 07:57:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB5BC49EA5 for ; Tue, 8 Jun 2021 07:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4349B61351 for ; Tue, 8 Jun 2021 07:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231197AbhFHIAI (ORCPT ); Tue, 8 Jun 2021 04:00:08 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53488 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231157AbhFHIAG (ORCPT ); Tue, 8 Jun 2021 04:00:06 -0400 X-UUID: 231562fd6c9a49229c7ddd20d27c4f01-20210608 X-UUID: 231562fd6c9a49229c7ddd20d27c4f01-20210608 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 617785521; Tue, 08 Jun 2021 15:58:10 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:08 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:07 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 13/23] usb: mtu3: rebuild role switch get/set hooks Date: Tue, 8 Jun 2021 15:57:39 +0800 Message-ID: <1623139069-8173-14-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Use common helper ssusb_set_mode() to do role switch instead of manual switch helper; Remove unnecessary local variable when get role status Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index cf9e5b59a77e..318fbc618137 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -256,13 +256,9 @@ void ssusb_set_force_mode(struct ssusb_mtk *ssusb, static int ssusb_role_sw_set(struct usb_role_switch *sw, enum usb_role role) { struct ssusb_mtk *ssusb = usb_role_switch_get_drvdata(sw); - bool to_host = false; - - if (role == USB_ROLE_HOST) - to_host = true; + struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; - if (to_host ^ ssusb->is_host) - ssusb_mode_switch(ssusb, to_host); + ssusb_set_mode(otg_sx, role); return 0; } @@ -270,11 +266,8 @@ static int ssusb_role_sw_set(struct usb_role_switch *sw, enum usb_role role) static enum usb_role ssusb_role_sw_get(struct usb_role_switch *sw) { struct ssusb_mtk *ssusb = usb_role_switch_get_drvdata(sw); - enum usb_role role; - - role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; - return role; + return ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; } static int ssusb_role_sw_register(struct otg_switch_mtk *otg_sx) From patchwork Tue Jun 8 07:57:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE56FC49EA7 for ; Tue, 8 Jun 2021 07:58:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AADD761360 for ; Tue, 8 Jun 2021 07:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbhFHIAI (ORCPT ); Tue, 8 Jun 2021 04:00:08 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53510 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230414AbhFHIAH (ORCPT ); Tue, 8 Jun 2021 04:00:07 -0400 X-UUID: c174c026973d44e3abdc8d7639e77412-20210608 X-UUID: c174c026973d44e3abdc8d7639e77412-20210608 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 2031709269; Tue, 08 Jun 2021 15:58:11 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:09 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:08 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 14/23] usb: common: add helper to get role-switch-default-mode Date: Tue, 8 Jun 2021 15:57:40 +0800 Message-ID: <1623139069-8173-15-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add helper to get "role-switch-default-mode", and convert it to the corresponding enum usb_dr_mode Signed-off-by: Chunfeng Yun --- drivers/usb/common/common.c | 20 ++++++++++++++++++++ include/linux/usb/otg.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c index 347fb3d3894a..c9bdeb4ddcb5 100644 --- a/drivers/usb/common/common.c +++ b/drivers/usb/common/common.c @@ -200,6 +200,26 @@ enum usb_dr_mode usb_get_dr_mode(struct device *dev) } EXPORT_SYMBOL_GPL(usb_get_dr_mode); +/** + * usb_get_role_switch_default_mode - Get default mode for given device + * @dev: Pointer to the given device + * + * The function gets string from property 'role-switch-default-mode', + * and returns the corresponding enum usb_dr_mode. + */ +enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev) +{ + const char *str; + int ret; + + ret = device_property_read_string(dev, "role-switch-default-mode", &str); + if (ret < 0) + return USB_DR_MODE_UNKNOWN; + + return usb_get_dr_mode_from_string(str); +} +EXPORT_SYMBOL_GPL(usb_get_role_switch_default_mode); + /** * usb_decode_interval - Decode bInterval into the time expressed in 1us unit * @epd: The descriptor of the endpoint diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h index 69f1b6328532..1550b8e5f039 100644 --- a/include/linux/usb/otg.h +++ b/include/linux/usb/otg.h @@ -128,5 +128,6 @@ enum usb_dr_mode { * and returns the correspondig enum usb_dr_mode */ extern enum usb_dr_mode usb_get_dr_mode(struct device *dev); +extern enum usb_dr_mode usb_get_role_switch_default_mode(struct device *dev); #endif /* __LINUX_USB_OTG_H */ From patchwork Tue Jun 8 07:57:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD2B8C49EB9 for ; Tue, 8 Jun 2021 07:58:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7BB56128B for ; Tue, 8 Jun 2021 07:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231231AbhFHIAJ (ORCPT ); Tue, 8 Jun 2021 04:00:09 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49450 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231179AbhFHIAH (ORCPT ); Tue, 8 Jun 2021 04:00:07 -0400 X-UUID: b4cbf075f954461db5382267c351760c-20210608 X-UUID: b4cbf075f954461db5382267c351760c-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 959427143; Tue, 08 Jun 2021 15:58:11 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:10 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:09 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 15/23] usb: dwc3: drd: use helper to get role-switch-default-mode Date: Tue, 8 Jun 2021 15:57:41 +0800 Message-ID: <1623139069-8173-16-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Use the new helper usb_get_role_switch_default_mode() to get property of "role-switch-default-mode" Signed-off-by: Chunfeng Yun --- drivers/usb/dwc3/drd.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index e2b68bb770d1..4e0a26683b06 100644 --- a/drivers/usb/dwc3/drd.c +++ b/drivers/usb/dwc3/drd.c @@ -541,14 +541,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct usb_role_switch *sw) 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; + dwc->role_switch_default_mode = usb_get_role_switch_default_mode(dwc->dev); + if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) { mode = DWC3_GCTL_PRTCAP_HOST; } else { dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL; From patchwork Tue Jun 8 07:57:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E159C49EAF for ; Tue, 8 Jun 2021 07:58:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2997C6128D for ; Tue, 8 Jun 2021 07:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231222AbhFHIAJ (ORCPT ); Tue, 8 Jun 2021 04:00:09 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49395 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231176AbhFHIAH (ORCPT ); Tue, 8 Jun 2021 04:00:07 -0400 X-UUID: a103e5406b164c1db3f383743404283d-20210608 X-UUID: a103e5406b164c1db3f383743404283d-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 697482548; Tue, 08 Jun 2021 15:58:12 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:11 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:10 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 16/23] usb: mtu3: support property role-switch-default-mode Date: Tue, 8 Jun 2021 15:57:42 +0800 Message-ID: <1623139069-8173-17-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Support default mode config when use usb-role-switch Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 2 ++ drivers/usb/mtu3/mtu3_dr.c | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index daf2b294ccdf..b56284d28c71 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -196,6 +196,7 @@ struct mtu3_gpd_ring { * @id_nb : notifier for iddig(idpin) detection * @dr_work : work for drd mode switch, used to avoid sleep in atomic context * @desired_role : role desired to switch +* @default_role : default mode while usb role is USB_ROLE_NONE * @role_sw : use USB Role Switch to support dual-role switch, can't use * extcon at the same time, and extcon is deprecated. * @role_sw_used : true when the USB Role Switch is used. @@ -209,6 +210,7 @@ struct otg_switch_mtk { struct notifier_block id_nb; struct work_struct dr_work; enum usb_role desired_role; + enum usb_role default_role; struct usb_role_switch *role_sw; bool role_sw_used; bool is_u3_drd; diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 318fbc618137..30e7e5fc0f88 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -137,8 +137,12 @@ static void ssusb_mode_sw_work(struct work_struct *work) current_role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; - if (desired_role == USB_ROLE_NONE) + if (desired_role == USB_ROLE_NONE) { + /* the default mode is host as probe does */ desired_role = USB_ROLE_HOST; + if (otg_sx->default_role == USB_ROLE_DEVICE) + desired_role = USB_ROLE_DEVICE; + } if (current_role == desired_role) return; @@ -274,17 +278,29 @@ static int ssusb_role_sw_register(struct otg_switch_mtk *otg_sx) { struct usb_role_switch_desc role_sx_desc = { 0 }; struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx); + struct device *dev = ssusb->dev; + enum usb_dr_mode mode; if (!otg_sx->role_sw_used) return 0; + mode = usb_get_role_switch_default_mode(dev); + if (mode == USB_DR_MODE_PERIPHERAL) + otg_sx->default_role = USB_ROLE_DEVICE; + else + otg_sx->default_role = USB_ROLE_HOST; + role_sx_desc.set = ssusb_role_sw_set; role_sx_desc.get = ssusb_role_sw_get; - role_sx_desc.fwnode = dev_fwnode(ssusb->dev); + role_sx_desc.fwnode = dev_fwnode(dev); role_sx_desc.driver_data = ssusb; - otg_sx->role_sw = usb_role_switch_register(ssusb->dev, &role_sx_desc); + otg_sx->role_sw = usb_role_switch_register(dev, &role_sx_desc); + if (IS_ERR(otg_sx->role_sw)) + return PTR_ERR(otg_sx->role_sw); - return PTR_ERR_OR_ZERO(otg_sx->role_sw); + ssusb_set_mode(otg_sx, otg_sx->default_role); + + return 0; } int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) From patchwork Tue Jun 8 07:57:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEDAAC49EBB for ; Tue, 8 Jun 2021 07:58:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8EB561289 for ; Tue, 8 Jun 2021 07:58:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbhFHIAL (ORCPT ); Tue, 8 Jun 2021 04:00:11 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49464 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231192AbhFHIAJ (ORCPT ); Tue, 8 Jun 2021 04:00:09 -0400 X-UUID: 78c3b632e6c1433dbe7995e899ac5cc6-20210608 X-UUID: 78c3b632e6c1433dbe7995e899ac5cc6-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 501344108; Tue, 08 Jun 2021 15:58:12 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:12 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:11 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 17/23] usb: mtu3: support option to disable usb2 ports Date: Tue, 8 Jun 2021 15:57:43 +0800 Message-ID: <1623139069-8173-18-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add support to disable specific usb2 host ports, it's useful when a usb2 port is disabled on some platforms, but enabled on others for the same SoC. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 4 ++++ drivers/usb/mtu3/mtu3_host.c | 8 +++++++- drivers/usb/mtu3/mtu3_plat.c | 11 +++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index b56284d28c71..710abe83ba1a 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -229,6 +229,9 @@ struct otg_switch_mtk { * host only, device only or dual-role mode * @u2_ports: number of usb2.0 host ports * @u3_ports: number of usb3.0 host ports + * @u2p_dis_msk: mask of disabling usb2 ports, e.g. bit0==1 to + * disable u2port0, bit1==1 to disable u2port1,... etc, + * but when use dual-role mode, can't disable u2port0 * @u3p_dis_msk: mask of disabling usb3 ports, for example, bit0==1 to * disable u3port0, bit1==1 to disable u3port1,... etc * @dbgfs_root: only used when supports manual dual-role switch via debugfs @@ -256,6 +259,7 @@ struct ssusb_mtk { bool is_host; int u2_ports; int u3_ports; + int u2p_dis_msk; int u3p_dis_msk; struct dentry *dbgfs_root; /* usb wakeup for host mode */ diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c index 93a1a4c11e1e..6185bac5fecf 100644 --- a/drivers/usb/mtu3/mtu3_host.c +++ b/drivers/usb/mtu3/mtu3_host.c @@ -155,6 +155,9 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb) /* power on and enable all u2 ports */ for (i = 0; i < num_u2p; i++) { + if ((0x1 << i) & ssusb->u2p_dis_msk) + continue; + value = mtu3_readl(ibase, SSUSB_U2_CTRL(i)); value &= ~(SSUSB_U2_PORT_PDN | SSUSB_U2_PORT_DIS); value |= SSUSB_U2_PORT_HOST_SEL; @@ -188,8 +191,11 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) mtu3_writel(ibase, SSUSB_U3_CTRL(i), value); } - /* power down and disable all u2 ports */ + /* power down and disable u2 ports except skipped ones */ for (i = 0; i < num_u2p; i++) { + if ((0x1 << i) & ssusb->u2p_dis_msk) + continue; + value = mtu3_readl(ibase, SSUSB_U2_CTRL(i)); value |= SSUSB_U2_PORT_PDN; value |= suspend ? 0 : SSUSB_U2_PORT_DIS; diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index bbfabdc1e79b..93e52e6b6811 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -283,6 +283,8 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) /* optional property, ignore the error if it does not exist */ of_property_read_u32(node, "mediatek,u3p-dis-msk", &ssusb->u3p_dis_msk); + of_property_read_u32(node, "mediatek,u2p-dis-msk", + &ssusb->u2p_dis_msk); otg_sx->vbus = devm_regulator_get(dev, "vbus"); if (IS_ERR(otg_sx->vbus)) { @@ -299,6 +301,9 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) of_property_read_bool(node, "enable-manual-drd"); otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch"); + /* can't disable port0 when use dual-role mode */ + ssusb->u2p_dis_msk &= ~0x1; + if (otg_sx->role_sw_used || otg_sx->manual_drd_enabled) goto out; @@ -311,9 +316,11 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) } out: - dev_info(dev, "dr_mode: %d, is_u3_dr: %d, u3p_dis_msk: %x, drd: %s\n", - ssusb->dr_mode, otg_sx->is_u3_drd, ssusb->u3p_dis_msk, + dev_info(dev, "dr_mode: %d, is_u3_dr: %d, drd: %s\n", + ssusb->dr_mode, otg_sx->is_u3_drd, otg_sx->manual_drd_enabled ? "manual" : "auto"); + dev_info(dev, "u2p_dis_msk: %x, u3p_dis_msk: %x\n", + ssusb->u2p_dis_msk, ssusb->u3p_dis_msk); return 0; } From patchwork Tue Jun 8 07:57:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D845DC49EBE for ; Tue, 8 Jun 2021 07:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6E846128A for ; Tue, 8 Jun 2021 07:58:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231280AbhFHIAM (ORCPT ); Tue, 8 Jun 2021 04:00:12 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53601 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231243AbhFHIAL (ORCPT ); Tue, 8 Jun 2021 04:00:11 -0400 X-UUID: 936080b2a7ff420d8a0d73b4cae6e829-20210608 X-UUID: 936080b2a7ff420d8a0d73b4cae6e829-20210608 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1381146255; Tue, 08 Jun 2021 15:58:14 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:13 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:12 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 18/23] usb: mtu3: add new helpers for host suspend/resume Date: Tue, 8 Jun 2021 15:57:44 +0800 Message-ID: <1623139069-8173-19-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Extract two helpers for host suspend and resume, will make it easy to support dual-role mode suspend/resume later. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_dr.h | 8 ++-- drivers/usb/mtu3/mtu3_host.c | 92 ++++++++++++++++++++++++++++++++---- drivers/usb/mtu3/mtu3_plat.c | 4 +- 3 files changed, 88 insertions(+), 16 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h index 760fe7d69c6b..70dbf4706138 100644 --- a/drivers/usb/mtu3/mtu3_dr.h +++ b/drivers/usb/mtu3/mtu3_dr.h @@ -16,8 +16,8 @@ int ssusb_host_init(struct ssusb_mtk *ssusb, struct device_node *parent_dn); void ssusb_host_exit(struct ssusb_mtk *ssusb); int ssusb_wakeup_of_property_parse(struct ssusb_mtk *ssusb, struct device_node *dn); -int ssusb_host_enable(struct ssusb_mtk *ssusb); -int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend); +int ssusb_host_resume(struct ssusb_mtk *ssusb, bool p0_skipped); +int ssusb_host_suspend(struct ssusb_mtk *ssusb); void ssusb_wakeup_set(struct ssusb_mtk *ssusb, bool enable); #else @@ -38,12 +38,12 @@ static inline int ssusb_wakeup_of_property_parse( return 0; } -static inline int ssusb_host_enable(struct ssusb_mtk *ssusb) +static inline int ssusb_host_resume(struct ssusb_mtk *ssusb, bool p0_skipped) { return 0; } -static inline int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) +static inline int ssusb_host_suspend(struct ssusb_mtk *ssusb) { return 0; } diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c index 6185bac5fecf..a0a6a181b752 100644 --- a/drivers/usb/mtu3/mtu3_host.c +++ b/drivers/usb/mtu3/mtu3_host.c @@ -126,7 +126,7 @@ static void host_ports_num_get(struct ssusb_mtk *ssusb) } /* only configure ports will be used later */ -int ssusb_host_enable(struct ssusb_mtk *ssusb) +static int ssusb_host_enable(struct ssusb_mtk *ssusb) { void __iomem *ibase = ssusb->ippc_base; int num_u3p = ssusb->u3_ports; @@ -171,13 +171,12 @@ int ssusb_host_enable(struct ssusb_mtk *ssusb) return ssusb_check_clocks(ssusb, check_clk); } -int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) +static int ssusb_host_disable(struct ssusb_mtk *ssusb) { void __iomem *ibase = ssusb->ippc_base; int num_u3p = ssusb->u3_ports; int num_u2p = ssusb->u2_ports; u32 value; - int ret; int i; /* power down and disable u3 ports except skipped ones */ @@ -186,8 +185,7 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) continue; value = mtu3_readl(ibase, SSUSB_U3_CTRL(i)); - value |= SSUSB_U3_PORT_PDN; - value |= suspend ? 0 : SSUSB_U3_PORT_DIS; + value |= SSUSB_U3_PORT_PDN | SSUSB_U3_PORT_DIS; mtu3_writel(ibase, SSUSB_U3_CTRL(i), value); } @@ -197,16 +195,90 @@ int ssusb_host_disable(struct ssusb_mtk *ssusb, bool suspend) continue; value = mtu3_readl(ibase, SSUSB_U2_CTRL(i)); - value |= SSUSB_U2_PORT_PDN; - value |= suspend ? 0 : SSUSB_U2_PORT_DIS; + value |= SSUSB_U2_PORT_PDN | SSUSB_U2_PORT_DIS; mtu3_writel(ibase, SSUSB_U2_CTRL(i), value); } /* power down host ip */ mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN); - if (!suspend) - return 0; + return 0; +} + +int ssusb_host_resume(struct ssusb_mtk *ssusb, bool p0_skipped) +{ + void __iomem *ibase = ssusb->ippc_base; + int u3p_skip_msk = ssusb->u3p_dis_msk; + int u2p_skip_msk = ssusb->u2p_dis_msk; + int num_u3p = ssusb->u3_ports; + int num_u2p = ssusb->u2_ports; + u32 value; + int i; + + if (p0_skipped) { + u2p_skip_msk |= 0x1; + if (ssusb->otg_switch.is_u3_drd) + u3p_skip_msk |= 0x1; + } + + /* power on host ip */ + mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN); + + /* power on u3 ports except skipped ones */ + for (i = 0; i < num_u3p; i++) { + if ((0x1 << i) & u3p_skip_msk) + continue; + + value = mtu3_readl(ibase, SSUSB_U3_CTRL(i)); + value &= ~SSUSB_U3_PORT_PDN; + mtu3_writel(ibase, SSUSB_U3_CTRL(i), value); + } + + /* power on all u2 ports except skipped ones */ + for (i = 0; i < num_u2p; i++) { + if ((0x1 << i) & u2p_skip_msk) + continue; + + value = mtu3_readl(ibase, SSUSB_U2_CTRL(i)); + value &= ~SSUSB_U2_PORT_PDN; + mtu3_writel(ibase, SSUSB_U2_CTRL(i), value); + } + + return 0; +} + +/* here not skip port0 due to PDN can be set repeatedly */ +int ssusb_host_suspend(struct ssusb_mtk *ssusb) +{ + void __iomem *ibase = ssusb->ippc_base; + int num_u3p = ssusb->u3_ports; + int num_u2p = ssusb->u2_ports; + u32 value; + int ret; + int i; + + /* power down u3 ports except skipped ones */ + for (i = 0; i < num_u3p; i++) { + if ((0x1 << i) & ssusb->u3p_dis_msk) + continue; + + value = mtu3_readl(ibase, SSUSB_U3_CTRL(i)); + value |= SSUSB_U3_PORT_PDN; + mtu3_writel(ibase, SSUSB_U3_CTRL(i), value); + } + + /* power down u2 ports except skipped ones */ + for (i = 0; i < num_u2p; i++) { + if ((0x1 << i) & ssusb->u2p_dis_msk) + continue; + + value = mtu3_readl(ibase, SSUSB_U2_CTRL(i)); + value |= SSUSB_U2_PORT_PDN; + mtu3_writel(ibase, SSUSB_U2_CTRL(i), value); + } + + /* power down host ip */ + mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN); /* wait for host ip to sleep */ ret = readl_poll_timeout(ibase + U3D_SSUSB_IP_PW_STS1, value, @@ -237,7 +309,7 @@ static void ssusb_host_cleanup(struct ssusb_mtk *ssusb) if (ssusb->is_host) ssusb_set_vbus(&ssusb->otg_switch, 0); - ssusb_host_disable(ssusb, false); + ssusb_host_disable(ssusb); } /* diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 93e52e6b6811..30b940ebe9b4 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -469,7 +469,7 @@ static int __maybe_unused mtu3_suspend(struct device *dev) if (!ssusb->is_host) return 0; - ssusb_host_disable(ssusb, true); + ssusb_host_suspend(ssusb); ssusb_phy_power_off(ssusb); ssusb_clks_disable(ssusb); ssusb_wakeup_set(ssusb, true); @@ -496,7 +496,7 @@ static int __maybe_unused mtu3_resume(struct device *dev) if (ret) goto phy_err; - ssusb_host_enable(ssusb); + ssusb_host_resume(ssusb, false); return 0; From patchwork Tue Jun 8 07:57:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15C78C49EC7 for ; Tue, 8 Jun 2021 07:58:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F380161289 for ; Tue, 8 Jun 2021 07:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbhFHIAM (ORCPT ); Tue, 8 Jun 2021 04:00:12 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53573 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231228AbhFHIAK (ORCPT ); Tue, 8 Jun 2021 04:00:10 -0400 X-UUID: ced58110a58f4509a4277dd642c5ec22-20210608 X-UUID: ced58110a58f4509a4277dd642c5ec22-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 231150256; Tue, 08 Jun 2021 15:58:15 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:13 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 19/23] usb: mtu3: support runtime PM for host mode Date: Tue, 8 Jun 2021 15:57:45 +0800 Message-ID: <1623139069-8173-20-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Use a dedicated wakeup irq for runtime suspend/resume, and interrupts names are provided if using wakeup irq, this patch only support host mode. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 1 + drivers/usb/mtu3/mtu3_core.c | 13 ++++++-- drivers/usb/mtu3/mtu3_plat.c | 62 +++++++++++++++++++++++++++++++++--- 3 files changed, 68 insertions(+), 8 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 710abe83ba1a..1f479a867ed1 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -247,6 +247,7 @@ struct ssusb_mtk { void __iomem *ippc_base; struct phy **phys; int num_phys; + int wakeup_irq; /* common power & clock */ struct regulator *vusb33; struct clk *sys_clk; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 562f4357831e..6d23acb4fffc 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -888,9 +888,16 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb) if (mtu == NULL) return -ENOMEM; - mtu->irq = platform_get_irq(pdev, 0); - if (mtu->irq < 0) - return mtu->irq; + mtu->irq = platform_get_irq_byname_optional(pdev, "device"); + if (mtu->irq < 0) { + if (mtu->irq == -EPROBE_DEFER) + return mtu->irq; + + /* for backward compatibility */ + mtu->irq = platform_get_irq(pdev, 0); + if (mtu->irq < 0) + return mtu->irq; + } dev_info(dev, "irq %d\n", mtu->irq); mtu->mac_base = devm_platform_ioremap_resource_byname(pdev, "mac"); diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 30b940ebe9b4..9f8f2759b08e 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "mtu3.h" #include "mtu3_dr.h" @@ -266,6 +267,10 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) if (IS_ERR(ssusb->ippc_base)) return PTR_ERR(ssusb->ippc_base); + ssusb->wakeup_irq = platform_get_irq_byname_optional(pdev, "wakeup"); + if (ssusb->wakeup_irq == -EPROBE_DEFER) + return ssusb->wakeup_irq; + ssusb->dr_mode = usb_get_dr_mode(dev); if (ssusb->dr_mode == USB_DR_MODE_UNKNOWN) ssusb->dr_mode = USB_DR_MODE_OTG; @@ -353,14 +358,25 @@ static int mtu3_probe(struct platform_device *pdev) ssusb_debugfs_create_root(ssusb); /* enable power domain */ + pm_runtime_set_active(dev); + pm_runtime_use_autosuspend(dev); + pm_runtime_set_autosuspend_delay(dev, 4000); pm_runtime_enable(dev); pm_runtime_get_sync(dev); - device_enable_async_suspend(dev); ret = ssusb_rscs_init(ssusb); if (ret) goto comm_init_err; + if (ssusb->wakeup_irq > 0) { + ret = dev_pm_set_dedicated_wake_irq(dev, ssusb->wakeup_irq); + if (ret) { + dev_err(dev, " failed to set wakeup irq %d\n", ssusb->wakeup_irq); + goto comm_exit; + } + dev_info(dev, "wakeup irq %d\n", ssusb->wakeup_irq); + } + ssusb_ip_sw_reset(ssusb); if (IS_ENABLED(CONFIG_USB_MTU3_HOST)) @@ -411,6 +427,11 @@ static int mtu3_probe(struct platform_device *pdev) goto comm_exit; } + device_enable_async_suspend(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + pm_runtime_forbid(dev); + return 0; host_exit: @@ -431,6 +452,8 @@ static int mtu3_remove(struct platform_device *pdev) { struct ssusb_mtk *ssusb = platform_get_drvdata(pdev); + pm_runtime_get_sync(&pdev->dev); + switch (ssusb->dr_mode) { case USB_DR_MODE_PERIPHERAL: ssusb_gadget_exit(ssusb); @@ -448,9 +471,10 @@ static int mtu3_remove(struct platform_device *pdev) } ssusb_rscs_exit(ssusb); - pm_runtime_put_sync(&pdev->dev); - pm_runtime_disable(&pdev->dev); ssusb_debugfs_remove_root(ssusb); + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); return 0; } @@ -459,7 +483,7 @@ static int mtu3_remove(struct platform_device *pdev) * when support dual-role mode, we reject suspend when * it works as device mode; */ -static int __maybe_unused mtu3_suspend(struct device *dev) +static int mtu3_suspend_common(struct device *dev, pm_message_t msg) { struct ssusb_mtk *ssusb = dev_get_drvdata(dev); @@ -477,7 +501,7 @@ static int __maybe_unused mtu3_suspend(struct device *dev) return 0; } -static int __maybe_unused mtu3_resume(struct device *dev) +static int mtu3_resume_common(struct device *dev, pm_message_t msg) { struct ssusb_mtk *ssusb = dev_get_drvdata(dev); int ret; @@ -506,8 +530,36 @@ static int __maybe_unused mtu3_resume(struct device *dev) return ret; } +static int __maybe_unused mtu3_suspend(struct device *dev) +{ + return mtu3_suspend_common(dev, PMSG_SUSPEND); +} + +static int __maybe_unused mtu3_resume(struct device *dev) +{ + return mtu3_resume_common(dev, PMSG_SUSPEND); +} + +static int __maybe_unused mtu3_runtime_suspend(struct device *dev) +{ + if (!device_may_wakeup(dev)) + return 0; + + return mtu3_suspend_common(dev, PMSG_AUTO_SUSPEND); +} + +static int __maybe_unused mtu3_runtime_resume(struct device *dev) +{ + if (!device_may_wakeup(dev)) + return 0; + + return mtu3_resume_common(dev, PMSG_AUTO_SUSPEND); +} + static const struct dev_pm_ops mtu3_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(mtu3_suspend, mtu3_resume) + SET_RUNTIME_PM_OPS(mtu3_runtime_suspend, + mtu3_runtime_resume, NULL) }; #define DEV_PM_OPS (IS_ENABLED(CONFIG_PM) ? &mtu3_pm_ops : NULL) From patchwork Tue Jun 8 07:57:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ED3DC49EBC for ; Tue, 8 Jun 2021 07:58:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5AA5D61289 for ; Tue, 8 Jun 2021 07:58:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231261AbhFHIAL (ORCPT ); Tue, 8 Jun 2021 04:00:11 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53559 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231200AbhFHIAJ (ORCPT ); Tue, 8 Jun 2021 04:00:09 -0400 X-UUID: 07a1d4591a5a49548c1f2443f9719484-20210608 X-UUID: 07a1d4591a5a49548c1f2443f9719484-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 853202935; Tue, 08 Jun 2021 15:58:15 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:13 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 20/23] usb: mtu3: add helper to power on/down device Date: Tue, 8 Jun 2021 15:57:46 +0800 Message-ID: <1623139069-8173-21-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add helper to power on/down device ports and ip, it will be used when support device suspend/resume Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_core.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 6d23acb4fffc..648e970d77ba 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -141,6 +141,28 @@ static void mtu3_device_disable(struct mtu3 *mtu) mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); } +static void mtu3_dev_power_on(struct mtu3 *mtu) +{ + void __iomem *ibase = mtu->ippc_base; + + mtu3_clrbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); + if (mtu->is_u3_ip) + mtu3_clrbits(ibase, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); + + mtu3_clrbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); +} + +static void mtu3_dev_power_down(struct mtu3 *mtu) +{ + void __iomem *ibase = mtu->ippc_base; + + if (mtu->is_u3_ip) + mtu3_setbits(ibase, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); + + mtu3_setbits(ibase, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); + mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); +} + /* reset U3D's device module. */ static void mtu3_device_reset(struct mtu3 *mtu) { @@ -333,12 +355,7 @@ void mtu3_start(struct mtu3 *mtu) dev_dbg(mtu->dev, "%s devctl 0x%x\n", __func__, mtu3_readl(mbase, U3D_DEVICE_CONTROL)); - mtu3_clrbits(mtu->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); - if (mtu->is_u3_ip) - mtu3_clrbits(mtu->ippc_base, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); - - mtu3_clrbits(mtu->ippc_base, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); - + mtu3_dev_power_on(mtu); mtu3_csr_init(mtu); mtu3_set_speed(mtu, mtu->speed); @@ -360,12 +377,7 @@ void mtu3_stop(struct mtu3 *mtu) mtu3_dev_on_off(mtu, 0); mtu->is_active = 0; - - if (mtu->is_u3_ip) - mtu3_setbits(mtu->ippc_base, SSUSB_U3_CTRL(0), SSUSB_U3_PORT_PDN); - - mtu3_setbits(mtu->ippc_base, SSUSB_U2_CTRL(0), SSUSB_U2_PORT_PDN); - mtu3_setbits(mtu->ippc_base, U3D_SSUSB_IP_PW_CTRL2, SSUSB_IP_DEV_PDN); + mtu3_dev_power_down(mtu); } /* for non-ep0 */ From patchwork Tue Jun 8 07:57:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A777BC49EC9 for ; Tue, 8 Jun 2021 07:58:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90AD161289 for ; Tue, 8 Jun 2021 07:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbhFHIAO (ORCPT ); Tue, 8 Jun 2021 04:00:14 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53643 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231277AbhFHIAN (ORCPT ); Tue, 8 Jun 2021 04:00:13 -0400 X-UUID: 9fecf6fb0c9044bc9bcd4f6e07960963-20210608 X-UUID: 9fecf6fb0c9044bc9bcd4f6e07960963-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1972132383; Tue, 08 Jun 2021 15:58:17 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:15 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:14 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 21/23] usb: mtu3: support suspend/resume for device mode Date: Tue, 8 Jun 2021 15:57:47 +0800 Message-ID: <1623139069-8173-22-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Support suspend/resume for device mode if the device is not connected with a host, otherwise reject to suspend. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 1 + drivers/usb/mtu3/mtu3_core.c | 68 +++++++++++++++++++++++++++++++++- drivers/usb/mtu3/mtu3_dr.h | 14 +++++++ drivers/usb/mtu3/mtu3_gadget.c | 5 +++ drivers/usb/mtu3/mtu3_plat.c | 47 +++++++++++++++++------ 5 files changed, 121 insertions(+), 14 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 1f479a867ed1..ad063fec7f17 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -360,6 +360,7 @@ struct mtu3 { unsigned is_u3_ip:1; unsigned delayed_status:1; unsigned gen2cp:1; + unsigned connected:1; u8 address; u8 test_mode_nr; diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index 648e970d77ba..a800920d38b9 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -380,6 +381,24 @@ void mtu3_stop(struct mtu3 *mtu) mtu3_dev_power_down(mtu); } +static void mtu3_dev_suspend(struct mtu3 *mtu) +{ + if (!mtu->is_active) + return; + + mtu3_intr_disable(mtu); + mtu3_dev_power_down(mtu); +} + +static void mtu3_dev_resume(struct mtu3 *mtu) +{ + if (!mtu->is_active) + return; + + mtu3_dev_power_on(mtu); + mtu3_intr_enable(mtu); +} + /* for non-ep0 */ int mtu3_config_ep(struct mtu3 *mtu, struct mtu3_ep *mep, int interval, int burst, int mult) @@ -700,11 +719,15 @@ static irqreturn_t mtu3_link_isr(struct mtu3 *mtu) mtu->g.speed = udev_speed; mtu->g.ep0->maxpacket = maxpkt; mtu->ep0_state = MU3D_EP0_STATE_SETUP; + mtu->connected = !!(udev_speed != USB_SPEED_UNKNOWN); - if (udev_speed == USB_SPEED_UNKNOWN) + if (udev_speed == USB_SPEED_UNKNOWN) { mtu3_gadget_disconnect(mtu); - else + pm_runtime_put(mtu->dev); + } else { + pm_runtime_get(mtu->dev); mtu3_ep0_setup(mtu); + } return IRQ_HANDLED; } @@ -984,3 +1007,44 @@ void ssusb_gadget_exit(struct ssusb_mtk *ssusb) device_init_wakeup(ssusb->dev, false); mtu3_hw_exit(mtu); } + +int ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg) +{ + struct mtu3 *mtu = ssusb->u3d; + void __iomem *ibase = mtu->ippc_base; + u32 value; + int ret = 0; + + if (!mtu->gadget_driver) + return 0; + + if (mtu->connected) + return -EBUSY; + + mtu3_dev_suspend(mtu); + synchronize_irq(mtu->irq); + + /* wait for ip to sleep */ + if (mtu->is_active && mtu->softconnect) { + ret = readl_poll_timeout(ibase + U3D_SSUSB_IP_PW_STS1, + value, (value & SSUSB_IP_SLEEP_STS), 100, 100000); + if (ret) { + dev_err(mtu->dev, "ip sleep failed!!!\n"); + ret = -EBUSY; + } + } + + return ret; +} + +int ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg) +{ + struct mtu3 *mtu = ssusb->u3d; + + if (!mtu->gadget_driver) + return 0; + + mtu3_dev_resume(mtu); + + return 0; +} diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h index 70dbf4706138..5286f9f5ee18 100644 --- a/drivers/usb/mtu3/mtu3_dr.h +++ b/drivers/usb/mtu3/mtu3_dr.h @@ -57,6 +57,8 @@ static inline void ssusb_wakeup_set(struct ssusb_mtk *ssusb, bool enable) #if IS_ENABLED(CONFIG_USB_MTU3_GADGET) || IS_ENABLED(CONFIG_USB_MTU3_DUAL_ROLE) int ssusb_gadget_init(struct ssusb_mtk *ssusb); void ssusb_gadget_exit(struct ssusb_mtk *ssusb); +int ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg); +int ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg); #else static inline int ssusb_gadget_init(struct ssusb_mtk *ssusb) { @@ -65,6 +67,18 @@ static inline int ssusb_gadget_init(struct ssusb_mtk *ssusb) static inline void ssusb_gadget_exit(struct ssusb_mtk *ssusb) {} + +static inline int +ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg) +{ + return 0; +} + +static inline int +ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg) +{ + return 0; +} #endif diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c index 5e21ba05ebf0..7b54631ca335 100644 --- a/drivers/usb/mtu3/mtu3_gadget.c +++ b/drivers/usb/mtu3/mtu3_gadget.c @@ -469,6 +469,8 @@ static int mtu3_gadget_pullup(struct usb_gadget *gadget, int is_on) dev_dbg(mtu->dev, "%s (%s) for %sactive device\n", __func__, is_on ? "on" : "off", mtu->is_active ? "" : "in"); + pm_runtime_get_sync(mtu->dev); + /* we'd rather not pullup unless the device is active. */ spin_lock_irqsave(&mtu->lock, flags); @@ -482,6 +484,7 @@ static int mtu3_gadget_pullup(struct usb_gadget *gadget, int is_on) } spin_unlock_irqrestore(&mtu->lock, flags); + pm_runtime_put(mtu->dev); return 0; } @@ -499,6 +502,7 @@ static int mtu3_gadget_start(struct usb_gadget *gadget, } dev_dbg(mtu->dev, "bind driver %s\n", driver->function); + pm_runtime_get_sync(mtu->dev); spin_lock_irqsave(&mtu->lock, flags); @@ -509,6 +513,7 @@ static int mtu3_gadget_start(struct usb_gadget *gadget, mtu3_start(mtu); spin_unlock_irqrestore(&mtu->lock, flags); + pm_runtime_put(mtu->dev); return 0; } diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 9f8f2759b08e..4c50b3663b66 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -479,21 +479,32 @@ static int mtu3_remove(struct platform_device *pdev) return 0; } -/* - * when support dual-role mode, we reject suspend when - * it works as device mode; - */ static int mtu3_suspend_common(struct device *dev, pm_message_t msg) { struct ssusb_mtk *ssusb = dev_get_drvdata(dev); + int ret = 0; dev_dbg(dev, "%s\n", __func__); - /* REVISIT: disconnect it for only device mode? */ - if (!ssusb->is_host) - return 0; + switch (ssusb->dr_mode) { + case USB_DR_MODE_PERIPHERAL: + ret = ssusb_gadget_suspend(ssusb, msg); + if (ret) + return ret; - ssusb_host_suspend(ssusb); + break; + case USB_DR_MODE_HOST: + ssusb_host_suspend(ssusb); + break; + case USB_DR_MODE_OTG: + if (!ssusb->is_host) + return 0; + + ssusb_host_suspend(ssusb); + break; + default: + return -EINVAL; + } ssusb_phy_power_off(ssusb); ssusb_clks_disable(ssusb); ssusb_wakeup_set(ssusb, true); @@ -508,9 +519,6 @@ static int mtu3_resume_common(struct device *dev, pm_message_t msg) dev_dbg(dev, "%s\n", __func__); - if (!ssusb->is_host) - return 0; - ssusb_wakeup_set(ssusb, false); ret = ssusb_clks_enable(ssusb); if (ret) @@ -520,7 +528,22 @@ static int mtu3_resume_common(struct device *dev, pm_message_t msg) if (ret) goto phy_err; - ssusb_host_resume(ssusb, false); + switch (ssusb->dr_mode) { + case USB_DR_MODE_PERIPHERAL: + ssusb_gadget_resume(ssusb, msg); + break; + case USB_DR_MODE_HOST: + ssusb_host_resume(ssusb, false); + break; + case USB_DR_MODE_OTG: + if (!ssusb->is_host) + return 0; + + ssusb_host_resume(ssusb, true); + break; + default: + return -EINVAL; + } return 0; From patchwork Tue Jun 8 07:57:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 457124 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17379C49EC8 for ; Tue, 8 Jun 2021 07:58:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04D1C61285 for ; Tue, 8 Jun 2021 07:58:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231288AbhFHIAO (ORCPT ); Tue, 8 Jun 2021 04:00:14 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:53601 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231271AbhFHIAN (ORCPT ); Tue, 8 Jun 2021 04:00:13 -0400 X-UUID: 952e9afeb9b24aee9bbf1b0dfb01555d-20210608 X-UUID: 952e9afeb9b24aee9bbf1b0dfb01555d-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 166798777; Tue, 08 Jun 2021 15:58:17 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:16 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:15 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 22/23] usb: mtu3: support suspend/resume for dual-role mode Date: Tue, 8 Jun 2021 15:57:48 +0800 Message-ID: <1623139069-8173-23-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Support suspend/resume for dual-role mode including the single port and multi-ports supported by host controller, when the host supports mult-ports, only port0 (u2/u3) is used to support dual role mode. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3_core.c | 32 +++++++------- drivers/usb/mtu3/mtu3_dr.c | 2 + drivers/usb/mtu3/mtu3_dr.h | 8 ++++ drivers/usb/mtu3/mtu3_host.c | 10 +---- drivers/usb/mtu3/mtu3_plat.c | 84 ++++++++++++++++++++++++++---------- 5 files changed, 89 insertions(+), 47 deletions(-) diff --git a/drivers/usb/mtu3/mtu3_core.c b/drivers/usb/mtu3/mtu3_core.c index a800920d38b9..f90e5cdec614 100644 --- a/drivers/usb/mtu3/mtu3_core.c +++ b/drivers/usb/mtu3/mtu3_core.c @@ -9,7 +9,6 @@ */ #include -#include #include #include #include @@ -1008,12 +1007,25 @@ void ssusb_gadget_exit(struct ssusb_mtk *ssusb) mtu3_hw_exit(mtu); } +bool ssusb_gadget_ip_sleep_check(struct ssusb_mtk *ssusb) +{ + struct mtu3 *mtu = ssusb->u3d; + + /* host only, should wait for ip sleep */ + if (!mtu) + return true; + + /* device is started and pullup D+, ip can sleep */ + if (mtu->is_active && mtu->softconnect) + return true; + + /* ip can't sleep if not pullup D+ when support device mode */ + return false; +} + int ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg) { struct mtu3 *mtu = ssusb->u3d; - void __iomem *ibase = mtu->ippc_base; - u32 value; - int ret = 0; if (!mtu->gadget_driver) return 0; @@ -1024,17 +1036,7 @@ int ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg) mtu3_dev_suspend(mtu); synchronize_irq(mtu->irq); - /* wait for ip to sleep */ - if (mtu->is_active && mtu->softconnect) { - ret = readl_poll_timeout(ibase + U3D_SSUSB_IP_PW_STS1, - value, (value & SSUSB_IP_SLEEP_STS), 100, 100000); - if (ret) { - dev_err(mtu->dev, "ip sleep failed!!!\n"); - ret = -EBUSY; - } - } - - return ret; + return 0; } int ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg) diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index 30e7e5fc0f88..a6b04831b20b 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -149,6 +149,7 @@ static void ssusb_mode_sw_work(struct work_struct *work) dev_dbg(ssusb->dev, "set role : %s\n", usb_role_string(desired_role)); mtu3_dbg_trace(ssusb->dev, "set role : %s", usb_role_string(desired_role)); + pm_runtime_get_sync(ssusb->dev); switch (desired_role) { case USB_ROLE_HOST: @@ -169,6 +170,7 @@ static void ssusb_mode_sw_work(struct work_struct *work) default: dev_err(ssusb->dev, "invalid role\n"); } + pm_runtime_put(ssusb->dev); } static void ssusb_set_mode(struct otg_switch_mtk *otg_sx, enum usb_role role) diff --git a/drivers/usb/mtu3/mtu3_dr.h b/drivers/usb/mtu3/mtu3_dr.h index 5286f9f5ee18..e325508bddf4 100644 --- a/drivers/usb/mtu3/mtu3_dr.h +++ b/drivers/usb/mtu3/mtu3_dr.h @@ -59,6 +59,8 @@ int ssusb_gadget_init(struct ssusb_mtk *ssusb); void ssusb_gadget_exit(struct ssusb_mtk *ssusb); int ssusb_gadget_suspend(struct ssusb_mtk *ssusb, pm_message_t msg); int ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg); +bool ssusb_gadget_ip_sleep_check(struct ssusb_mtk *ssusb); + #else static inline int ssusb_gadget_init(struct ssusb_mtk *ssusb) { @@ -79,6 +81,12 @@ ssusb_gadget_resume(struct ssusb_mtk *ssusb, pm_message_t msg) { return 0; } + +static inline bool ssusb_gadget_ip_sleep_check(struct ssusb_mtk *ssusb) +{ + return true; +} + #endif diff --git a/drivers/usb/mtu3/mtu3_host.c b/drivers/usb/mtu3/mtu3_host.c index a0a6a181b752..7d528f3c2482 100644 --- a/drivers/usb/mtu3/mtu3_host.c +++ b/drivers/usb/mtu3/mtu3_host.c @@ -8,7 +8,6 @@ */ #include -#include #include #include #include @@ -254,7 +253,6 @@ int ssusb_host_suspend(struct ssusb_mtk *ssusb) int num_u3p = ssusb->u3_ports; int num_u2p = ssusb->u2_ports; u32 value; - int ret; int i; /* power down u3 ports except skipped ones */ @@ -280,13 +278,7 @@ int ssusb_host_suspend(struct ssusb_mtk *ssusb) /* power down host ip */ mtu3_setbits(ibase, U3D_SSUSB_IP_PW_CTRL1, SSUSB_IP_HOST_PDN); - /* wait for host ip to sleep */ - ret = readl_poll_timeout(ibase + U3D_SSUSB_IP_PW_STS1, value, - (value & SSUSB_IP_SLEEP_STS), 100, 100000); - if (ret) - dev_err(ssusb->dev, "ip sleep failed!!!\n"); - - return ret; + return 0; } static void ssusb_host_setup(struct ssusb_mtk *ssusb) diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 4c50b3663b66..0beae0c8e2d6 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -46,6 +46,29 @@ int ssusb_check_clocks(struct ssusb_mtk *ssusb, u32 ex_clks) return 0; } +static int wait_for_ip_sleep(struct ssusb_mtk *ssusb) +{ + bool sleep_check = true; + u32 value; + int ret; + + if (!ssusb->is_host) + sleep_check = ssusb_gadget_ip_sleep_check(ssusb); + + if (!sleep_check) + return 0; + + /* wait for ip enter sleep mode */ + ret = readl_poll_timeout(ssusb->ippc_base + U3D_SSUSB_IP_PW_STS1, value, + (value & SSUSB_IP_SLEEP_STS), 100, 100000); + if (ret) { + dev_err(ssusb->dev, "ip sleep failed!!!\n"); + ret = -EBUSY; + } + + return ret; +} + static int ssusb_phy_init(struct ssusb_mtk *ssusb) { int i; @@ -479,6 +502,28 @@ static int mtu3_remove(struct platform_device *pdev) return 0; } +static int resume_ip_and_ports(struct ssusb_mtk *ssusb, pm_message_t msg) +{ + switch (ssusb->dr_mode) { + case USB_DR_MODE_PERIPHERAL: + ssusb_gadget_resume(ssusb, msg); + break; + case USB_DR_MODE_HOST: + ssusb_host_resume(ssusb, false); + break; + case USB_DR_MODE_OTG: + ssusb_host_resume(ssusb, !ssusb->is_host); + if (!ssusb->is_host) + ssusb_gadget_resume(ssusb, msg); + + break; + default: + return -EINVAL; + } + + return 0; +} + static int mtu3_suspend_common(struct device *dev, pm_message_t msg) { struct ssusb_mtk *ssusb = dev_get_drvdata(dev); @@ -490,26 +535,36 @@ static int mtu3_suspend_common(struct device *dev, pm_message_t msg) case USB_DR_MODE_PERIPHERAL: ret = ssusb_gadget_suspend(ssusb, msg); if (ret) - return ret; + goto err; break; case USB_DR_MODE_HOST: ssusb_host_suspend(ssusb); break; case USB_DR_MODE_OTG: - if (!ssusb->is_host) - return 0; - + if (!ssusb->is_host) { + ret = ssusb_gadget_suspend(ssusb, msg); + if (ret) + goto err; + } ssusb_host_suspend(ssusb); break; default: return -EINVAL; } + + ret = wait_for_ip_sleep(ssusb); + if (ret) + goto sleep_err; + ssusb_phy_power_off(ssusb); ssusb_clks_disable(ssusb); ssusb_wakeup_set(ssusb, true); - return 0; +sleep_err: + resume_ip_and_ports(ssusb, msg); +err: + return ret; } static int mtu3_resume_common(struct device *dev, pm_message_t msg) @@ -528,24 +583,7 @@ static int mtu3_resume_common(struct device *dev, pm_message_t msg) if (ret) goto phy_err; - switch (ssusb->dr_mode) { - case USB_DR_MODE_PERIPHERAL: - ssusb_gadget_resume(ssusb, msg); - break; - case USB_DR_MODE_HOST: - ssusb_host_resume(ssusb, false); - break; - case USB_DR_MODE_OTG: - if (!ssusb->is_host) - return 0; - - ssusb_host_resume(ssusb, true); - break; - default: - return -EINVAL; - } - - return 0; + return resume_ip_and_ports(ssusb, msg); phy_err: ssusb_clks_disable(ssusb); From patchwork Tue Jun 8 07:57:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 456054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75786C49ECB for ; Tue, 8 Jun 2021 07:58:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 603AE61285 for ; Tue, 8 Jun 2021 07:58:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbhFHIAP (ORCPT ); Tue, 8 Jun 2021 04:00:15 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:49528 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231286AbhFHIAO (ORCPT ); Tue, 8 Jun 2021 04:00:14 -0400 X-UUID: 0ed1e004e9ca4d0e9f524ae7a8f9b04f-20210608 X-UUID: 0ed1e004e9ca4d0e9f524ae7a8f9b04f-20210608 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 404231016; Tue, 08 Jun 2021 15:58:18 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs05n2.mediatek.inc (172.21.101.140) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 15:58:17 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 15:58:16 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman , Rob Herring , Felipe Balbi CC: Chunfeng Yun , Matthias Brugger , Thinh Nguyen , , , , , , Yuwen Ng , Eddie Hung Subject: [PATCH 23/23] usb: mtu3: use clock bulk to get clocks Date: Tue, 8 Jun 2021 15:57:49 +0800 Message-ID: <1623139069-8173-24-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.8.1.1.dirty In-Reply-To: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> References: <1623139069-8173-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Use clock bulk helpers to get/enable/disable clocks, meanwhile make sys_ck optional, then will be easier to handle clocks. Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 12 ++--- drivers/usb/mtu3/mtu3_plat.c | 86 ++++++------------------------------ 2 files changed, 18 insertions(+), 80 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index ad063fec7f17..022bbdc54e68 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -10,6 +10,7 @@ #ifndef __MTU3_H__ #define __MTU3_H__ +#include #include #include #include @@ -89,6 +90,8 @@ struct mtu3_request; */ #define EP0_RESPONSE_BUF 6 +#define BULK_CLKS_CNT 4 + /* device operated link and speed got from DEVICE_CONF register */ enum mtu3_speed { MTU3_SPEED_INACTIVE = 0, @@ -221,10 +224,6 @@ struct otg_switch_mtk { * @mac_base: register base address of device MAC, exclude xHCI's * @ippc_base: register base address of IP Power and Clock interface (IPPC) * @vusb33: usb3.3V shared by device/host IP - * @sys_clk: system clock of mtu3, shared by device/host IP - * @ref_clk: reference clock - * @mcu_clk: mcu_bus_ck clock for AHB bus etc - * @dma_clk: dma_bus_ck clock for AXI bus etc * @dr_mode: works in which mode: * host only, device only or dual-role mode * @u2_ports: number of usb2.0 host ports @@ -250,10 +249,7 @@ struct ssusb_mtk { int wakeup_irq; /* common power & clock */ struct regulator *vusb33; - struct clk *sys_clk; - struct clk *ref_clk; - struct clk *mcu_clk; - struct clk *dma_clk; + struct clk_bulk_data clks[BULK_CLKS_CNT]; /* otg */ struct otg_switch_mtk otg_switch; enum usb_dr_mode dr_mode; diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index 0beae0c8e2d6..57a71af8e151 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -5,7 +5,6 @@ * Author: Chunfeng Yun */ -#include #include #include #include @@ -125,54 +124,6 @@ static void ssusb_phy_power_off(struct ssusb_mtk *ssusb) phy_power_off(ssusb->phys[i]); } -static int ssusb_clks_enable(struct ssusb_mtk *ssusb) -{ - int ret; - - ret = clk_prepare_enable(ssusb->sys_clk); - if (ret) { - dev_err(ssusb->dev, "failed to enable sys_clk\n"); - goto sys_clk_err; - } - - ret = clk_prepare_enable(ssusb->ref_clk); - if (ret) { - dev_err(ssusb->dev, "failed to enable ref_clk\n"); - goto ref_clk_err; - } - - ret = clk_prepare_enable(ssusb->mcu_clk); - if (ret) { - dev_err(ssusb->dev, "failed to enable mcu_clk\n"); - goto mcu_clk_err; - } - - ret = clk_prepare_enable(ssusb->dma_clk); - if (ret) { - dev_err(ssusb->dev, "failed to enable dma_clk\n"); - goto dma_clk_err; - } - - return 0; - -dma_clk_err: - clk_disable_unprepare(ssusb->mcu_clk); -mcu_clk_err: - clk_disable_unprepare(ssusb->ref_clk); -ref_clk_err: - clk_disable_unprepare(ssusb->sys_clk); -sys_clk_err: - return ret; -} - -static void ssusb_clks_disable(struct ssusb_mtk *ssusb) -{ - clk_disable_unprepare(ssusb->dma_clk); - clk_disable_unprepare(ssusb->mcu_clk); - clk_disable_unprepare(ssusb->ref_clk); - clk_disable_unprepare(ssusb->sys_clk); -} - static int ssusb_rscs_init(struct ssusb_mtk *ssusb) { int ret = 0; @@ -183,7 +134,7 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb) goto vusb33_err; } - ret = ssusb_clks_enable(ssusb); + ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks); if (ret) goto clks_err; @@ -204,7 +155,7 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb) phy_err: ssusb_phy_exit(ssusb); phy_init_err: - ssusb_clks_disable(ssusb); + clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); clks_err: regulator_disable(ssusb->vusb33); vusb33_err: @@ -213,7 +164,7 @@ static int ssusb_rscs_init(struct ssusb_mtk *ssusb) static void ssusb_rscs_exit(struct ssusb_mtk *ssusb) { - ssusb_clks_disable(ssusb); + clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); regulator_disable(ssusb->vusb33); ssusb_phy_power_off(ssusb); ssusb_phy_exit(ssusb); @@ -239,6 +190,7 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) { struct device_node *node = pdev->dev.of_node; struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; + struct clk_bulk_data *clks = ssusb->clks; struct device *dev = &pdev->dev; int i; int ret; @@ -249,23 +201,13 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) return PTR_ERR(ssusb->vusb33); } - ssusb->sys_clk = devm_clk_get(dev, "sys_ck"); - if (IS_ERR(ssusb->sys_clk)) { - dev_err(dev, "failed to get sys clock\n"); - return PTR_ERR(ssusb->sys_clk); - } - - ssusb->ref_clk = devm_clk_get_optional(dev, "ref_ck"); - if (IS_ERR(ssusb->ref_clk)) - return PTR_ERR(ssusb->ref_clk); - - ssusb->mcu_clk = devm_clk_get_optional(dev, "mcu_ck"); - if (IS_ERR(ssusb->mcu_clk)) - return PTR_ERR(ssusb->mcu_clk); - - ssusb->dma_clk = devm_clk_get_optional(dev, "dma_ck"); - if (IS_ERR(ssusb->dma_clk)) - return PTR_ERR(ssusb->dma_clk); + clks[0].id = "sys_ck"; + clks[1].id = "ref_ck"; + clks[2].id = "mcu_ck"; + clks[3].id = "dma_ck"; + ret = devm_clk_bulk_get_optional(dev, BULK_CLKS_CNT, clks); + if (ret) + return ret; ssusb->num_phys = of_count_phandle_with_args(node, "phys", "#phy-cells"); @@ -558,7 +500,7 @@ static int mtu3_suspend_common(struct device *dev, pm_message_t msg) goto sleep_err; ssusb_phy_power_off(ssusb); - ssusb_clks_disable(ssusb); + clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); ssusb_wakeup_set(ssusb, true); sleep_err: @@ -575,7 +517,7 @@ static int mtu3_resume_common(struct device *dev, pm_message_t msg) dev_dbg(dev, "%s\n", __func__); ssusb_wakeup_set(ssusb, false); - ret = ssusb_clks_enable(ssusb); + ret = clk_bulk_prepare_enable(BULK_CLKS_CNT, ssusb->clks); if (ret) goto clks_err; @@ -586,7 +528,7 @@ static int mtu3_resume_common(struct device *dev, pm_message_t msg) return resume_ip_and_ports(ssusb, msg); phy_err: - ssusb_clks_disable(ssusb); + clk_bulk_disable_unprepare(BULK_CLKS_CNT, ssusb->clks); clks_err: return ret; }