From patchwork Fri Mar 15 07:38:28 2019 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: 10854161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D93111575 for ; Fri, 15 Mar 2019 07:40:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BBC412A890 for ; Fri, 15 Mar 2019 07:40:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEDCB2A893; Fri, 15 Mar 2019 07:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A4A512A890 for ; Fri, 15 Mar 2019 07:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bLqAeGOn5I2BGrGSu/S0XVTEwJ5n5wNzLcXNaTqeE5I=; b=Rp2k7eSsbaU4wx 6ltyg66TI/DUX4kzej64XnCvVO9m3SKj0sGw0BeOPMrtwpCF2HVZUDsynE1546l2+BvBZ0qlOr2rq kRINQK7UUV2kyDeJzvU3JLVT5Kbf2a1rId/IeuAEuxGzpq0AWepoFHMIUZ5c4UXUO9m4Fg61BM6Vl FzqEe5qBJt3gOi7FoNnyMa56kSTdgU3SN4kNjOJbzAIzvbf/gYurftbztDFKJH4l0tcA7HLnUzK4+ DISZBKFEC3alcFI+Nmng5QblDUKLfrvPXUUKX3Sjx8jpSDHCpOpYLZ3I6WJA/MzOQ1CvkXvUY2kmr tImewT+CZhMrLjqQ9/jA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hSC-0004Mm-DJ; Fri, 15 Mar 2019 07:40:32 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hRw-00046x-Qc; Fri, 15 Mar 2019 07:40:18 +0000 X-UUID: 7fb2aed11fb847a0a53dcc4c623e9a42-20190314 X-UUID: 7fb2aed11fb847a0a53dcc4c623e9a42-20190314 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 67411313; Thu, 14 Mar 2019 23:40:13 -0800 Received: from MTKMBS31N2.mediatek.inc (172.27.4.87) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:11 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:08 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:07 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 1/6] dt-bindings: connector: add optional properties for Type-B Date: Fri, 15 Mar 2019 15:38:28 +0800 Message-ID: <1552635513-2378-2-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004016_874629_14512698 X-CRM114-Status: UNSURE ( 8.29 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add id-gpios, vbus-gpios, vbus-supply and pinctrl properties for usb-b-connector Signed-off-by: Chunfeng Yun --- v2 changes: 1. describe more clear for vbus-gpios and vbus-supply suggested by Hans --- .../devicetree/bindings/connector/usb-connector.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/connector/usb-connector.txt b/Documentation/devicetree/bindings/connector/usb-connector.txt index a9a2f2fc44f2..1c4ed6c9afa8 100644 --- a/Documentation/devicetree/bindings/connector/usb-connector.txt +++ b/Documentation/devicetree/bindings/connector/usb-connector.txt @@ -17,6 +17,15 @@ Optional properties: - self-powered: Set this property if the usb device that has its own power source. +Optional properties for usb-b-connector: +- id-gpios: gpio for USB ID pin. +- vbus-gpios: gpio for USB VBUS pin, used to detect presence of VBUS 5V. + see gpio/gpio.txt. +- vbus-supply: a phandle to the regulator for USB VBUS if needed. +- pinctrl-names : a pinctrl state named "default" is optional +- pinctrl-0 : pin control group + see pinctrl/pinctrl-bindings.txt + Optional properties for usb-c-connector: - power-role: should be one of "source", "sink" or "dual"(DRP) if typec connector has power support. From patchwork Fri Mar 15 07:38:29 2019 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: 10854181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A33A51575 for ; Fri, 15 Mar 2019 07:41:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 841322A890 for ; Fri, 15 Mar 2019 07:41:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 739812A892; Fri, 15 Mar 2019 07:41:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 201522A890 for ; Fri, 15 Mar 2019 07:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ndrab5IFjobndx8AIoIJXAeutlMCBuylHtxOboCgNm4=; b=h0QC622iL9SgnJ K6+DT0BSd270RoYrG6aSpZ5Pz60QZQ4gtj05LHuPTy2SdNJ8TJCrQHrMgZ71Z0A0Upv3AW0oIFReA a6oqDKdnA1i5R92vatmoIjFR08g2Xwgl1G1u/im7dJo57KrLPEnU6J6Gmf1hmRtSpIK5LMlIJT0MM d5m47/v491Z/sOPhS+0EumvkYZ4gnk5IYFF8YueFxz4r3LKjyWq9o4pY1Yl8sKRTyyiD/YMBmvKkp a8C4+0pepcB5LPnWxJgbzNQzgQXPtS9eopCZ+X1prH8JacRcLU9pReEO5GM6J0kaq7jqizpqC1cX/ 18xlPX7jaI6G0JdDWGUQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hSj-0004y7-Te; Fri, 15 Mar 2019 07:41:06 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hS6-0004GD-GA; Fri, 15 Mar 2019 07:40:28 +0000 X-UUID: a8032c80ab494910a0f3ec12ebdfa273-20190314 X-UUID: a8032c80ab494910a0f3ec12ebdfa273-20190314 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1438202368; Thu, 14 Mar 2019 23:40:17 -0800 Received: from MTKMBS31N1.mediatek.inc (172.27.4.69) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:15 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:12 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:09 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 2/6] dt-bindings: usb: add binding for Type-B dual role switch by GPIO Date: Fri, 15 Mar 2019 15:38:29 +0800 Message-ID: <1552635513-2378-3-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004026_745591_5ACD2984 X-CRM114-Status: GOOD ( 10.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP It's used to support dual role switch via GPIO when use Type-B receptacle Signed-off-by: Chunfeng Yun --- v2 changes: 1. new patch to make binding clear suggested by Hans --- .../bindings/usb/typeb-switch-gpio.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/typeb-switch-gpio.txt diff --git a/Documentation/devicetree/bindings/usb/typeb-switch-gpio.txt b/Documentation/devicetree/bindings/usb/typeb-switch-gpio.txt new file mode 100644 index 000000000000..d46d83bc6500 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/typeb-switch-gpio.txt @@ -0,0 +1,26 @@ +USB Type-B dual role switch via a GPIO + +This is a virtual device used to switch dual role mode from the USB ID pin +connected to a GPIO pin. + +Required properties: +- compatible: Should be "linux,typeb-switch-gpio" + +Either one of id-gpios or vbus-gpios must be present, and both can be present +as well. +vbus-supply could be present if needed when support dual role mode. + see connector/usb-connector.txt + +Example: + +&mtu3 { + status = "okay"; + + connector@0 { + compatible = "usb-b-connector", "linux,typeb-switch-gpio"; + label = "micro-USB"; + type = "micro"; + id-gpio = <&pio 12 GPIO_ACTIVE_HIGH>; + vbus-supply = <&usb_p0_vbus>; + }; +}; From patchwork Fri Mar 15 07:38:30 2019 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: 10854169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE6CF15AC for ; Fri, 15 Mar 2019 07:40:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A218B2A890 for ; Fri, 15 Mar 2019 07:40:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 961362A892; Fri, 15 Mar 2019 07:40:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 461D22A890 for ; Fri, 15 Mar 2019 07:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CUbvMO36uoalKrPZSDwD0hKX/uhga67TKJENlRaRslQ=; b=TsCUlAZIKAtIy+ Iktfy96U4pafQMTbmPbrBhrjtFxvLrTsdUS09o+ukRadZwGnuZyN645VBzmQHVSTPVLQQHId9rCKZ xAqlCk965/fSV0JwxdVt7414S0Mw8PPbRRy87FSunzSJRTNRPi5Y6FpWteVDeIQU7nklXaiT74pBN d/XMQIlOvekUJY0h9ZG3kuKTu3cbycu90ObpHYIDaKRM5clbtonyEJZSnLKZ0q89E5DLL5PvURLoq byvScShCcwI9HUfBlo2DdTKKvSVUUXc6xE7zBtvxjngFEFBwn5qNzTdDUbaXp8qlncU7miaFEzuZS 0aDWS1t1c4VkkDOlBLEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hST-0004gM-TN; Fri, 15 Mar 2019 07:40:50 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hS2-0004Bl-PI; Fri, 15 Mar 2019 07:40:24 +0000 X-UUID: 288f2577da844cbe964d3dbad405b90b-20190314 X-UUID: 288f2577da844cbe964d3dbad405b90b-20190314 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 594324835; Thu, 14 Mar 2019 23:40:19 -0800 Received: from MTKMBS31DR.mediatek.inc (172.27.6.102) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:17 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31DR.mediatek.inc (172.27.6.102) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:14 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:14 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 3/6] dt-bindings: usb: mtu3: add properties about USB Role Switch Date: Fri, 15 Mar 2019 15:38:30 +0800 Message-ID: <1552635513-2378-4-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004022_882496_0ED7BCD7 X-CRM114-Status: GOOD ( 11.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now the USB Role Switch is supported, so add properties about it Signed-off-by: Chunfeng Yun --- v2 changes: 1. fix typo 2. refer new binding about connector property --- .../devicetree/bindings/usb/mediatek,mtu3.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt index 3382b5cb471d..359e8d565b54 100644 --- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt +++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt @@ -27,7 +27,9 @@ Optional properties: - ranges : allows valid 1:1 translation between child's address space and parent's address space - extcon : external connector for vbus and idpin changes detection, needed - when supports dual-role mode. + when supports dual-role mode; it's consiedered valid for compatibility + reasons, and not allowed for new bindings, use the property + usb-role-switch instead. - vbus-supply : reference to the VBUS regulator, needed when supports dual-role mode. - pinctrl-names : a pinctrl state named "default" is optional, and need be @@ -36,7 +38,8 @@ Optional properties: is not set. - pinctrl-0 : pin control group See: Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt - + - usb-role-switch : use USB Role Switch to support dual-role switch, but + not extcon - maximum-speed : valid arguments are "super-speed", "high-speed" and "full-speed"; refer to usb/generic.txt - enable-manual-drd : supports manual dual-role switch via debugfs; usually @@ -61,6 +64,9 @@ The xhci should be added as subnode to mtu3 as shown in the following example if host mode is enabled. The DT binding details of xhci can be found in: Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt +The connector would be added as subnode if receptacle is Micro. + see usb/typeb-switch-gpio.txt + Example: ssusb: usb@11271000 { compatible = "mediatek,mt8173-mtu3"; From patchwork Fri Mar 15 07:38:31 2019 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: 10854187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCA311575 for ; Fri, 15 Mar 2019 07:41:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0C272A891 for ; Fri, 15 Mar 2019 07:41:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4CC12A893; Fri, 15 Mar 2019 07:41:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5908D2A891 for ; Fri, 15 Mar 2019 07:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VtFyKIAoei5FdX2/rBYS6XzXjZuhP6ftGlW6EPP2Btw=; b=cjlVxyAvPr6QUh N73lWo4a1UT+9vgQY9LOeM73bwd+w3DqZ+00IpUBVwhg4F/9JVmPwJ89MPH1m1r8sfUqZ/Zo1TfFk o35FqLRLLcBXnXRo9okScxoCbYSffmchqV+z3qGdPzdsyHV0M0Ta4BtnLsGtLzKkDxM3XFiNgEJj7 oj52xTK5JTdxmYd/AuHBvIQzVYmXnAFRWsye8Lp6ArX4ajEh1kuR/IPsluldCkPfe+Hbv/dVdETla mpIC34N57lsciPGHRNaVFjK4e6/MFlJD0Fgk/bAfMhO3A5dXMSEO65JfuDdI8DDE3fNYPwofDOBed xJl3ftwR4jjrFVZNkGYw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTC-0005Kb-Jx; Fri, 15 Mar 2019 07:41:34 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTA-0005K0-Fq; Fri, 15 Mar 2019 07:41:33 +0000 X-UUID: 094b2f2d470f4a0ba620726caf0924e5-20190314 X-UUID: 094b2f2d470f4a0ba620726caf0924e5-20190314 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1927192848; Thu, 14 Mar 2019 23:40:27 -0800 Received: from MTKMBS31N2.mediatek.inc (172.27.4.87) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:26 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:23 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:16 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 4/6] usb: roles: add API to get usb_role_switch by node Date: Fri, 15 Mar 2019 15:38:31 +0800 Message-ID: <1552635513-2378-5-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004132_529384_3C319D01 X-CRM114-Status: GOOD ( 12.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add usb_role_switch_get_by_node() to make easier to get usb_role_switch by node which register it. It's useful when there is not device_connection registered between two drivers and only knows the node which register usb_role_switch. Signed-off-by: Chunfeng Yun --- drivers/usb/roles/class.c | 30 ++++++++++++++++++++++++++++++ include/linux/usb/role.h | 1 + 2 files changed, 31 insertions(+) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 99116af07f1d..284b19856dc4 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -11,6 +11,7 @@ #include #include #include +#include #include static struct class *role_class; @@ -121,6 +122,35 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev) } EXPORT_SYMBOL_GPL(usb_role_switch_get); +static int __switch_match_node(struct device *dev, const void *node) +{ + return dev->parent->of_node == (const struct device_node *)node; +} + +/** + * usb_role_switch_get_by_node - Find USB role switch by it's parent node + * @node: The node that register USB role switch + * + * Finds and returns role switch registered by @node. The reference count + * for the found switch is incremented. + */ +struct usb_role_switch *usb_role_switch_get_by_node(struct device_node *node) +{ + struct usb_role_switch *sw; + struct device *dev; + + dev = class_find_device(role_class, NULL, node, + __switch_match_node); + if (!dev) + return ERR_PTR(-EPROBE_DEFER); + + sw = to_role_switch(dev); + WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); + + return sw; +} +EXPORT_SYMBOL_GPL(usb_role_switch_get_by_node); + /** * usb_role_switch_put - Release handle to a switch * @sw: USB Role Switch diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h index edc51be4a77c..056498b83dee 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -42,6 +42,7 @@ struct usb_role_switch_desc { int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role); enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw); +struct usb_role_switch *usb_role_switch_get_by_node(struct device_node *node); struct usb_role_switch *usb_role_switch_get(struct device *dev); void usb_role_switch_put(struct usb_role_switch *sw); From patchwork Fri Mar 15 07:38:32 2019 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: 10854191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7DF8415AC for ; Fri, 15 Mar 2019 07:41:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60E362A891 for ; Fri, 15 Mar 2019 07:41:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54B272A893; Fri, 15 Mar 2019 07:41:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AE8592A891 for ; Fri, 15 Mar 2019 07:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CufhLoam6OB9Dm7sUhSSgNKiumg+1R9kZnwKgceVGzQ=; b=TNiX1WzFwRm2Ag SuGMn0AqazL69nSpQIciwRSEg/vEq6Za2ICxbuPFzROMzzJh+6uxyVtIWz+xRf7tL9CwtctBmN4hM EvfKDi9wGjUfV+rQ4pzY/ZoY8lJ5zOge4CvYFGpkeDJmj60rZW+kbcbYV3B7uNcQFNVAOlzkJbGud DC9Qa6P0mOxBvTO4i9P4Ld/pAv5T1PXqOPvZ6QwCuej6C9gEo27edjfv/acKIIOcvTsENmLSWCYVz 28SBRfoN/jfAq1kf8I87Sv63Uk0Oh5hmMRLegGNGKtM8OIyd0rJojNlkdBq/8bp4Qv9Q4iwhP8jmw ClZDRvWWVw51e4Pqrh+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTP-0005YM-7a; Fri, 15 Mar 2019 07:41:47 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTB-0005K0-A3; Fri, 15 Mar 2019 07:41:35 +0000 X-UUID: df22113a7cf34484a74526e462d8448a-20190314 X-UUID: df22113a7cf34484a74526e462d8448a-20190314 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1959287264; Thu, 14 Mar 2019 23:40:30 -0800 Received: from MTKMBS31N1.mediatek.inc (172.27.4.69) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:28 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:26 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:24 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 5/6] usb: roles: add driver of USB Type-B role switch by GPIO Date: Fri, 15 Mar 2019 15:38:32 +0800 Message-ID: <1552635513-2378-6-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004133_353982_35087FF9 X-CRM114-Status: GOOD ( 19.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Due to the requirement of usb-connector.txt binding, the old way using extcon to support USB Dual-Role switch is now deprecated when use Type-B connector. This patch introduce a Type-B connector driver and try to replace the function provided by extcon-usb-gpio driver Signed-off-by: Chunfeng Yun --- v2 changes: 1. file name is changed 2. use new compatible --- drivers/usb/roles/Kconfig | 14 ++ drivers/usb/roles/Makefile | 1 + drivers/usb/roles/typeb-switch-gpio.c | 285 ++++++++++++++++++++++++++ 3 files changed, 300 insertions(+) create mode 100644 drivers/usb/roles/typeb-switch-gpio.c diff --git a/drivers/usb/roles/Kconfig b/drivers/usb/roles/Kconfig index e4194ac94510..3c4320a73d17 100644 --- a/drivers/usb/roles/Kconfig +++ b/drivers/usb/roles/Kconfig @@ -24,4 +24,18 @@ config USB_ROLES_INTEL_XHCI To compile the driver as a module, choose M here: the module will be called intel-xhci-usb-role-switch. +config TYPEB_SWITCH_GPIO + tristate "USB Type-B Role Switch Via GPIO" + depends on GPIOLIB + help + The driver supports USB role switch between host and device via GPIO + based USB cable detection, used typically if GPIO is used for USB ID + pin detection. And it's used to replace the function provided by + drivers/extcon/extcon-usb-gpio.c driver due to the requirement by + connector/usb-connector.txt + + Say Y here if your USB Type-B Connector supports Dual-Role mode. + To compile the driver as a module, choose M here: the module will + be called usb-b-connector.ko + endif # USB_ROLE_SWITCH diff --git a/drivers/usb/roles/Makefile b/drivers/usb/roles/Makefile index c02873206fc1..00f697bd419f 100644 --- a/drivers/usb/roles/Makefile +++ b/drivers/usb/roles/Makefile @@ -1,3 +1,4 @@ obj-$(CONFIG_USB_ROLE_SWITCH) += roles.o roles-y := class.o +obj-$(CONFIG_TYPEB_SWITCH_GPIO) += typeb-switch-gpio.o obj-$(CONFIG_USB_ROLES_INTEL_XHCI) += intel-xhci-usb-role-switch.o diff --git a/drivers/usb/roles/typeb-switch-gpio.c b/drivers/usb/roles/typeb-switch-gpio.c new file mode 100644 index 000000000000..d8a15269bf8f --- /dev/null +++ b/drivers/usb/roles/typeb-switch-gpio.c @@ -0,0 +1,285 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * USB Type-B Connector Driver + * + * Copyright (C) 2019 MediaTek Inc. + * + * Author: Chunfeng Yun + * + * Some code borrowed from drivers/extcon/extcon-usb-gpio.c + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB_GPIO_DEB_MS 20 /* ms */ +#define USB_GPIO_DEB_US ((USB_GPIO_DEB_MS) * 1000) /* us */ + +#define USB_CONN_IRQF \ + (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT) + +struct usb_conn_info { + struct device *dev; + struct usb_role_switch *role_sw; + enum usb_role last_role; + struct regulator *vbus; + struct delayed_work dw_det; + unsigned long debounce_jiffies; + + struct gpio_desc *id_gpiod; + struct gpio_desc *vbus_gpiod; + int id_irq; + int vbus_irq; +}; + +/** + * "DEVICE" = VBUS and "HOST" = !ID, so we have: + * Both "DEVICE" and "HOST" can't be set as active at the same time + * so if "HOST" is active (i.e. ID is 0) we keep "DEVICE" inactive + * even if VBUS is on. + * + * Role | ID | VBUS + * ------------------------------------ + * [1] DEVICE | H | H + * [2] NONE | H | L + * [3] HOST | L | H + * [4] HOST | L | L + * + * In case we have only one of these signals: + * - VBUS only - we want to distinguish between [1] and [2], so ID is always 1 + * - ID only - we want to distinguish between [1] and [4], so VBUS = ID + */ +static void usb_conn_detect_cable(struct work_struct *work) +{ + struct usb_conn_info *info; + enum usb_role role; + int id, vbus, ret; + + info = container_of(to_delayed_work(work), + struct usb_conn_info, dw_det); + + /* check ID and VBUS */ + id = info->id_gpiod ? + gpiod_get_value_cansleep(info->id_gpiod) : 1; + vbus = info->vbus_gpiod ? + gpiod_get_value_cansleep(info->vbus_gpiod) : id; + + if (!id) + role = USB_ROLE_HOST; + else if (vbus) + role = USB_ROLE_DEVICE; + else + role = USB_ROLE_NONE; + + dev_dbg(info->dev, "role %d/%d, gpios: id %d, vbus %d\n", + info->last_role, role, id, vbus); + + if (info->last_role == role) { + dev_warn(info->dev, "repeated role: %d\n", role); + return; + } + + if (info->last_role == USB_ROLE_HOST) + regulator_disable(info->vbus); + + ret = usb_role_switch_set_role(info->role_sw, role); + if (ret) + dev_err(info->dev, "failed to set role: %d\n", ret); + + if (role == USB_ROLE_HOST) { + ret = regulator_enable(info->vbus); + if (ret) + dev_err(info->dev, "enable vbus regulator failed\n"); + } + + info->last_role = role; + + dev_dbg(info->dev, "vbus regulator is %s\n", + regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); +} + +static void usb_conn_queue_dwork(struct usb_conn_info *info, + unsigned long delay) +{ + queue_delayed_work(system_power_efficient_wq, &info->dw_det, delay); +} + +static irqreturn_t usb_conn_isr(int irq, void *dev_id) +{ + struct usb_conn_info *info = dev_id; + + usb_conn_queue_dwork(info, info->debounce_jiffies); + + return IRQ_HANDLED; +} + +static int usb_conn_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct device_node *parent; + struct usb_conn_info *info; + int ret = 0; + + if (!np) + return -EINVAL; + + info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->dev = dev; + info->id_gpiod = devm_gpiod_get_optional(dev, "id", GPIOD_IN); + if (IS_ERR(info->id_gpiod)) + return PTR_ERR(info->id_gpiod); + + info->vbus_gpiod = devm_gpiod_get_optional(dev, "vbus", GPIOD_IN); + if (IS_ERR(info->vbus_gpiod)) + return PTR_ERR(info->vbus_gpiod); + + if (!info->id_gpiod && !info->vbus_gpiod) { + dev_err(dev, "failed to get gpios\n"); + return -ENODEV; + } + + if (info->id_gpiod) + ret = gpiod_set_debounce(info->id_gpiod, USB_GPIO_DEB_US); + if (!ret && info->vbus_gpiod) + ret = gpiod_set_debounce(info->vbus_gpiod, USB_GPIO_DEB_US); + if (ret < 0) + info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEB_MS); + + INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable); + + info->vbus = devm_regulator_get(dev, "vbus"); + if (IS_ERR(info->vbus)) { + dev_err(dev, "failed to get vbus\n"); + return PTR_ERR(info->vbus); + } + + parent = of_get_parent(np); + info->role_sw = usb_role_switch_get_by_node(parent); + if (IS_ERR_OR_NULL(info->role_sw)) { + dev_err(dev, "failed to get role switch\n"); + return PTR_ERR(info->role_sw); + } + + of_node_put(parent); + + if (info->id_gpiod) { + info->id_irq = gpiod_to_irq(info->id_gpiod); + if (info->id_irq < 0) { + dev_err(dev, "failed to get ID IRQ\n"); + return info->id_irq; + } + + ret = devm_request_threaded_irq(dev, info->id_irq, NULL, + usb_conn_isr, USB_CONN_IRQF, + pdev->name, info); + if (ret < 0) { + dev_err(dev, "failed to request ID IRQ\n"); + return ret; + } + } + + if (info->vbus_gpiod) { + info->vbus_irq = gpiod_to_irq(info->vbus_gpiod); + if (info->vbus_irq < 0) { + dev_err(dev, "failed to get VBUS IRQ\n"); + return info->vbus_irq; + } + + ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL, + usb_conn_isr, USB_CONN_IRQF, + pdev->name, info); + if (ret < 0) { + dev_err(dev, "failed to request VBUS IRQ\n"); + return ret; + } + } + + platform_set_drvdata(pdev, info); + + /* Perform initial detection */ + usb_conn_queue_dwork(info, 0); + + return 0; +} + +static int usb_conn_remove(struct platform_device *pdev) +{ + struct usb_conn_info *info = platform_get_drvdata(pdev); + + cancel_delayed_work_sync(&info->dw_det); + + if (info->last_role == USB_ROLE_HOST) + regulator_disable(info->vbus); + + usb_role_switch_put(info->role_sw); + + return 0; +} + +static int __maybe_unused usb_conn_suspend(struct device *dev) +{ + struct usb_conn_info *info = dev_get_drvdata(dev); + + if (info->id_gpiod) + disable_irq(info->id_irq); + if (info->vbus_gpiod) + disable_irq(info->vbus_irq); + + pinctrl_pm_select_sleep_state(dev); + + return 0; +} + +static int __maybe_unused usb_conn_resume(struct device *dev) +{ + struct usb_conn_info *info = dev_get_drvdata(dev); + + pinctrl_pm_select_default_state(dev); + + if (info->id_gpiod) + enable_irq(info->id_irq); + if (info->vbus_gpiod) + enable_irq(info->vbus_irq); + + usb_conn_queue_dwork(info, 0); + + return 0; +} + +static SIMPLE_DEV_PM_OPS(usb_conn_pm_ops, + usb_conn_suspend, usb_conn_resume); + +#define DEV_PMS_OPS (IS_ENABLED(CONFIG_PM_SLEEP) ? &usb_conn_pm_ops : NULL) + +static const struct of_device_id usb_conn_dt_match[] = { + { .compatible = "linux,typeb-switch-gpio", }, + { } +}; +MODULE_DEVICE_TABLE(of, usb_conn_dt_match); + +static struct platform_driver usb_conn_driver = { + .probe = usb_conn_probe, + .remove = usb_conn_remove, + .driver = { + .name = "usb_b_conn", + .pm = DEV_PMS_OPS, + .of_match_table = usb_conn_dt_match, + }, +}; + +module_platform_driver(usb_conn_driver); + +MODULE_AUTHOR("Chunfeng Yun "); +MODULE_DESCRIPTION("USB GPIO conn driver"); +MODULE_LICENSE("GPL v2"); From patchwork Fri Mar 15 07:38:33 2019 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: 10854195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02F701575 for ; Fri, 15 Mar 2019 07:42:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAB822A891 for ; Fri, 15 Mar 2019 07:42:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCECB2A893; Fri, 15 Mar 2019 07:42:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 64D8F2A891 for ; Fri, 15 Mar 2019 07:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UwRUO4t56LnSnXwMHRfpvgR6DGZOxwHx9fEa83AMzRI=; b=LTJraPzvd2YrU7 7IFgFPtcREYm3+I4lshf217iT/uI5ukAuJc4u7RFWz3LWhw9XibufnbcpCFeNJEBnuudHTemCTymS /9K/aspaWax1Vqx+kdKABusLx5cN4itF3jbnpxmuUj2j/LnYb8raWs2md2dPdAwnvaQ/uBIlAuXts bu9JG9EZdVPVitgC0/hznESBx7I+0aXdiLNYvjP3w1YvbXInhA/BRt5AsEFANn5ujxgGNSUk5sl1D VcZzzW+kMOuRI0QZznVXJ3rV6du7Pd4m0iAuBXMCfeB1vLEgfZYNNmig5ylFYTaM9XXhY7JAFrBca rlyWoMlzCYtSezhgi7yg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTj-0005vq-KT; Fri, 15 Mar 2019 07:42:07 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h4hTe-0005qW-RV; Fri, 15 Mar 2019 07:42:05 +0000 X-UUID: 4788998158a246f1a3cfad098d3b4599-20190314 X-UUID: 4788998158a246f1a3cfad098d3b4599-20190314 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1694920073; Thu, 14 Mar 2019 23:40:33 -0800 Received: from MTKMBS31DR.mediatek.inc (172.27.6.102) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 00:40:31 -0700 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31DR.mediatek.inc (172.27.6.102) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 15 Mar 2019 15:40:27 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Fri, 15 Mar 2019 15:40:26 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus Subject: [PATCH v2 6/6] usb: mtu3: register a USB Role Switch for dual role mode Date: Fri, 15 Mar 2019 15:38:33 +0800 Message-ID: <1552635513-2378-7-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> References: <1552635513-2378-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190315_004203_120309_A8AAF593 X-CRM114-Status: GOOD ( 14.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Badhri Jagan Sridharan , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Matthias Brugger , Andy Shevchenko , linux-mediatek@lists.infradead.org, Min Guo , Chunfeng Yun , Adam Thomson , linux-arm-kernel@lists.infradead.org, Li Jun Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Due to extcon is not allowed for new bindings, and the dual role switch is supported by USB Role Switch, especially for Type-C drivers, so register a USB Role Switch to support the new way Signed-off-by: Chunfeng Yun --- drivers/usb/mtu3/mtu3.h | 5 ++++ drivers/usb/mtu3/mtu3_dr.c | 50 +++++++++++++++++++++++++++++++++--- drivers/usb/mtu3/mtu3_plat.c | 3 ++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h index 87823ac0d120..8f9da03255b6 100644 --- a/drivers/usb/mtu3/mtu3.h +++ b/drivers/usb/mtu3/mtu3.h @@ -202,6 +202,9 @@ struct mtu3_gpd_ring { * @id_nb : notifier for iddig(idpin) detection * @id_work : work of iddig detection notifier * @id_event : event of iddig detecion notifier +* @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. * @is_u3_drd: whether port0 supports usb3.0 dual-role device or not * @manual_drd_enabled: it's true when supports dual-role device by debugfs * to switch host/device modes depending on user input. @@ -215,6 +218,8 @@ struct otg_switch_mtk { struct notifier_block id_nb; struct work_struct id_work; unsigned long id_event; + struct usb_role_switch *role_sw; + bool role_sw_used; bool is_u3_drd; bool manual_drd_enabled; }; diff --git a/drivers/usb/mtu3/mtu3_dr.c b/drivers/usb/mtu3/mtu3_dr.c index ac60e9c8564e..b9272295fe2b 100644 --- a/drivers/usb/mtu3/mtu3_dr.c +++ b/drivers/usb/mtu3/mtu3_dr.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "mtu3.h" #include "mtu3_dr.h" @@ -266,7 +267,7 @@ static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx) * This is useful in special cases, such as uses TYPE-A receptacle but also * wants to support dual-role mode. */ -static void ssusb_mode_manual_switch(struct ssusb_mtk *ssusb, int to_host) +static void ssusb_mode_switch(struct ssusb_mtk *ssusb, int to_host) { struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; @@ -308,9 +309,9 @@ static ssize_t ssusb_mode_write(struct file *file, return -EFAULT; if (!strncmp(buf, "host", 4) && !ssusb->is_host) { - ssusb_mode_manual_switch(ssusb, 1); + ssusb_mode_switch(ssusb, 1); } else if (!strncmp(buf, "device", 6) && ssusb->is_host) { - ssusb_mode_manual_switch(ssusb, 0); + ssusb_mode_switch(ssusb, 0); } else { dev_err(ssusb->dev, "wrong or duplicated setting\n"); return -EINVAL; @@ -412,6 +413,46 @@ void ssusb_set_force_mode(struct ssusb_mtk *ssusb, mtu3_writel(ssusb->ippc_base, SSUSB_U2_CTRL(0), value); } +static int ssusb_role_sw_set(struct device *dev, enum usb_role role) +{ + struct ssusb_mtk *ssusb = dev_get_drvdata(dev); + bool to_host = false; + + if (role == USB_ROLE_HOST) + to_host = true; + + if (to_host ^ ssusb->is_host) + ssusb_mode_switch(ssusb, to_host); + + return 0; +} + +static enum usb_role ssusb_role_sw_get(struct device *dev) +{ + struct ssusb_mtk *ssusb = dev_get_drvdata(dev); + enum usb_role role; + + role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE; + + return role; +} + +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); + + if (!otg_sx->role_sw_used) + return 0; + + role_sx_desc.set = ssusb_role_sw_set; + role_sx_desc.get = ssusb_role_sw_get; + otg_sx->role_sw = usb_role_switch_register(ssusb->dev, &role_sx_desc); + + return PTR_ERR_OR_ZERO(otg_sx->role_sw); +} + int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) { struct otg_switch_mtk *otg_sx = &ssusb->otg_switch; @@ -421,6 +462,8 @@ int ssusb_otg_switch_init(struct ssusb_mtk *ssusb) if (otg_sx->manual_drd_enabled) ssusb_debugfs_init(ssusb); + else if (otg_sx->role_sw_used) + ssusb_role_sw_register(otg_sx); else ssusb_extcon_register(otg_sx); @@ -436,4 +479,5 @@ void ssusb_otg_switch_exit(struct ssusb_mtk *ssusb) cancel_work_sync(&otg_sx->id_work); cancel_work_sync(&otg_sx->vbus_work); + usb_role_switch_unregister(otg_sx->role_sw); } diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c index e086630e41a9..02c288a85989 100644 --- a/drivers/usb/mtu3/mtu3_plat.c +++ b/drivers/usb/mtu3/mtu3_plat.c @@ -313,8 +313,9 @@ static int get_ssusb_rscs(struct platform_device *pdev, struct ssusb_mtk *ssusb) otg_sx->is_u3_drd = of_property_read_bool(node, "mediatek,usb3-drd"); otg_sx->manual_drd_enabled = of_property_read_bool(node, "enable-manual-drd"); + otg_sx->role_sw_used = of_property_read_bool(node, "usb-role-switch"); - if (of_property_read_bool(node, "extcon")) { + if (!otg_sx->role_sw_used && of_property_read_bool(node, "extcon")) { otg_sx->edev = extcon_get_edev_by_phandle(ssusb->dev, 0); if (IS_ERR(otg_sx->edev)) { dev_err(ssusb->dev, "couldn't get extcon device\n");