From patchwork Fri Jan 13 04:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 42929 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp73610wrt; Thu, 12 Jan 2023 20:15:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXu5/v70WRCmlhTVf3t2D5l8lz5JlKreQygVJgdr0MxRboYZrzhF/isCHFqDGmXefbKr56c0 X-Received: by 2002:a62:6001:0:b0:582:33b4:4c57 with SMTP id u1-20020a626001000000b0058233b44c57mr8687306pfb.33.1673583327894; Thu, 12 Jan 2023 20:15:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673583327; cv=none; d=google.com; s=arc-20160816; b=JJ24wDPcqnG5foLBeoq65NHkCXd+2WUgqylLitkE9xA3s1aWIQyRccxcrF+JB9DerG Tj6UOCRB1NPEsFmiKDQm7l2/tO6MKTzLoCwiBvKNuGZwPDVrLN5k5M415ttph2zp+lBr /nykimHXBH1TOMx1pAJ8wbnIhlPZbOmHVmySYFZkijUbL2g3Szc/acyoGt7b0KEyVfTV aRywFRViKHJoMsDu9QhjCjgpR4XFBS9MsCjYNJBVsIKAu/OC8y0LGcA1eFQ+ho+hLc5p SxYkFvA8dVccTt4rzIpKlxr2P/Bt/qXHYjHIFojjrx3pRMjbgCZT6U/SpLoM6RjGdFxF O+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=skrZtyW7NuL4lgx1XrK+XW2ygr1LktK1dYdsKpmSYZI=; b=osW7W4e8iSB8ZEasDezWA9yh8s2e23UYjJTqdFi+NiNUqFwQ7TIx9+OHw96Vk1bQmw kBBW/vh7FdVtfptyqYhYhJh5uOD/7aFKj8r50CeDrxCf0dpjU23PXLnhnW06Em7Q4/KE a6oScdOLu0+lBCWceqAxKBlwDFoHhNDJOhWujDX4M3QCeC63Brk7tpKLmtybJjMLWrdt 58cBrndkIP7O0EjnIZqgFTUEiRRbRRWAP+vCbA50HqsqffoS2g6rz4q2KzvRjYYvsSSO IingPZg3H9a0z2mFo520hHGly4VUbcXODlKPiptZdYmcXJPvEGZvcr8ink+YLB/PGjpH zGjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cArHySgA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x19-20020aa78f13000000b0056ea2b1b0fesi19390573pfr.119.2023.01.12.20.15.15; Thu, 12 Jan 2023 20:15:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=cArHySgA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233217AbjAMEMY (ORCPT + 99 others); Thu, 12 Jan 2023 23:12:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232888AbjAMELl (ORCPT ); Thu, 12 Jan 2023 23:11:41 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C68F6534C; Thu, 12 Jan 2023 20:11:26 -0800 (PST) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30D3LieJ012588; Fri, 13 Jan 2023 04:11:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=skrZtyW7NuL4lgx1XrK+XW2ygr1LktK1dYdsKpmSYZI=; b=cArHySgA4nWd1mKUrqVo0uTm2hXy0rj2G9qs5Vq93AS14Y9UDh+iBjVGNHG0bq6ddoP5 qPHAJ8x5OV/g3btSIhAVS3NBM9uOS+2POlgtElHyG3Wc0rSDJAOMGBHPP12UPrXCm9Nz RLX8t/2lKz4NJ/g2VroP9yxZCUj0DCaFXZQFCDlD+iPJSVhcDugL2N4Cm1dZyHqkUFiS gJhhTuknc8FEXO+FXelZKQu9RTiWJ/mvAwdNEHv51SSy3JLDCbRMgzS/407uqo16i1KJ dls8xAVDb9b75l6rBQt7+W09Jl0K9On+1EQVbGJ4hWF1wr0RubGgxtiwIaz0iKMVtXFh 0g== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3n2evhtbr8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 04:11:22 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 30D4BLsj011461 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 04:11:21 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 12 Jan 2023 20:11:21 -0800 From: Bjorn Andersson To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Heikki Krogerus , Bjorn Andersson CC: , , Subject: [PATCH v2 1/2] dt-bindings: usb: Introduce GPIO-based SBU mux Date: Thu, 12 Jan 2023 20:11:14 -0800 Message-ID: <20230113041115.4189210-1-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 6_7VJjfV4A7p7lB44GeN4MTarRk4kCPc X-Proofpoint-ORIG-GUID: 6_7VJjfV4A7p7lB44GeN4MTarRk4kCPc X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-12_14,2023-01-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 clxscore=1011 mlxlogscore=741 mlxscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301130026 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754879311960258315?= X-GMAIL-MSGID: =?utf-8?q?1754879311960258315?= From: Bjorn Andersson Introduce a binding for GPIO-based mux hardware used for connecting, disconnecting and switching orientation of the SBU lines in USB Type-C applications. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson --- Changes since v1: - Expanded the example to indicate how this fits with the TCPM - Updated maintainer email address. .../devicetree/bindings/usb/gpio-sbu-mux.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml diff --git a/Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml b/Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml new file mode 100644 index 000000000000..bf4b1d016e1f --- /dev/null +++ b/Documentation/devicetree/bindings/usb/gpio-sbu-mux.yaml @@ -0,0 +1,110 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/gpio-sbu-mux.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: GPIO-based SBU mux + +maintainers: + - Bjorn Andersson + +description: + In USB Type-C applications the SBU lines needs to be connected, disconnected + and swapped depending on the altmode and orientation. This binding describes + a family of hardware solutions which switches between these modes using GPIO + signals. + +properties: + compatible: + items: + - enum: + - onnn,fsusb43l10x + - pericom,pi3usb102 + - const: gpio-sbu-mux + + enable-gpios: + description: Switch enable GPIO + + select-gpios: + description: Orientation select + + vcc-supply: + description: power supply + + mode-switch: + description: Flag the port as possible handle of altmode switching + type: boolean + + orientation-switch: + description: Flag the port as possible handler of orientation switching + type: boolean + + port: + $ref: /schemas/graph.yaml#/properties/port + description: + A port node to link the SBU mux to a TypeC controller for the purpose of + handling altmode muxing and orientation switching. + +required: + - compatible + - enable-gpios + - select-gpios + - mode-switch + - orientation-switch + - port + +additionalProperties: false + +examples: + - | + #include + + tcpm { + connector { + compatible = "usb-c-connector"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + tcpm_hs_out: endpoint { + remote-endpoint = <&usb_hs_phy_in>; + }; + }; + + port@1 { + reg = <1>; + tcpm_ss_out: endpoint { + remote-endpoint = <&usb_ss_phy_in>; + }; + }; + + port@2 { + reg = <2>; + tcpm_sbu_out: endpoint { + remote-endpoint = <&sbu_mux_in>; + }; + }; + }; + }; + }; + + sbu-mux { + compatible = "pericom,pi3usb102", "gpio-sbu-mux"; + + enable-gpios = <&tlmm 101 GPIO_ACTIVE_LOW>; + select-gpios = <&tlmm 164 GPIO_ACTIVE_HIGH>; + + mode-switch; + orientation-switch; + + port { + sbu_mux_in: endpoint { + remote-endpoint = <&tcpm_sbu_out>; + }; + }; + }; +... From patchwork Fri Jan 13 04:11:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 42925 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp73328wrt; Thu, 12 Jan 2023 20:14:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXVhGTW7U4W/VKe2NMFdeglNKefKJhnRKd/o9MxS5OXgeWPi/GRGuOQMrRUGxFb2oVUuqp X-Received: by 2002:a05:6a21:9186:b0:b6:2bd6:a79a with SMTP id tp6-20020a056a21918600b000b62bd6a79amr14541447pzb.36.1673583264133; Thu, 12 Jan 2023 20:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673583264; cv=none; d=google.com; s=arc-20160816; b=a4Bg0LhHOVTuBRjL4Xoan89Q7m/OJtJn2x8mSKLznPWyU7izthf3wSRHRPk6Xjc/Ai GM7P70p+Yq3YdgUtasSpj/brS/ckZuU6qufmLrF3prVggfGhV5SALZCwxCJMITpjPlau lLXENT7pEVpBrsuIzQwMn945/rNS9d7a69F6Lz1uGV9KAZnMy1Ok9YnVKZKwla5kk3oN OdylP/0UWMIvt6bT9oKTTDvhCzko+lc+pO9Gm3LLuhkt6Dvad9QTFTvX+CFYwUyipBR7 CRg+daHnrTc/39rJ1+w36EgyOaPjg3XVPaRsCPoqlQyi1VqDfrKVR3o+8nty94d3F1z1 jhLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0D6Fjvc3NxXQBk6jAWjWbsDYNmDhmP6kCq1JnFpueXA=; b=MSuuhkZhhyj9rVbkHDEfQswgRHh2mPu0E9zam4dmOxS6u/RZIug/1bqSwv9UAywAUi c2P03M4kUv3FmseXFCMGtzl6hzHLn2bOnIS55PDcRtL3x4Yh6ztNohKZ1uLxslYSDZIM u85dgEhct4HLlwIcm3HKWyjBVwMUdTMCKUvZgLT8hdMqEYTbaBPojk//OEuJoDZYLNPr ceh4PN2FQu3sGVBRRM/WsXqZk/5VPqlwi1/MRFnEaQL/ozsDOyqHtbzN2ge3hHwgz75/ SJCjoP6POWSs0NUU/IP/u4/U2p4Hag0dwidV9QL82yvbKG/FqGkKa/kpB6xwQsHX4D2M 6Sfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QB3yMaIt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a056a00170200b00582ef2e62d8si20218183pfc.283.2023.01.12.20.14.12; Thu, 12 Jan 2023 20:14:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=QB3yMaIt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235583AbjAMEMf (ORCPT + 99 others); Thu, 12 Jan 2023 23:12:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234223AbjAMELm (ORCPT ); Thu, 12 Jan 2023 23:11:42 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 359E365352; Thu, 12 Jan 2023 20:11:28 -0800 (PST) Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30D3xABO029564; Fri, 13 Jan 2023 04:11:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=qcppdkim1; bh=0D6Fjvc3NxXQBk6jAWjWbsDYNmDhmP6kCq1JnFpueXA=; b=QB3yMaIt+ABJBjk133hKGUPpDvW9nBTJTXhaCIo7HdOJHSD0RH4q3d0LXyoQ+UUpmffa srvf2HtzDRaDewSzAmHX0+LDQgTHN9MB3cTtyEVeUyq+sAfv24C0Ze1xZ8mR7rdk5OBM aWWD333C6+9+VQexbXj1yl064TZmK7fBpmlvhVIHXN9mf5JjF4YtxzesluPbH74HgLvi LvB7IW1Z4LxwmLd7dc0/5HfPI/gylrfadz16zdOqwRrKhoieZ0jqnDbvTS3pHhisRqkC 8BGZkhDTk4rD2zsE53dDrZwLGcMimF7mIib7y+bsq94S6HKx/1IIdn+9k1Bj80XKSdHk 0w== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3n2s0crpt5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 04:11:22 +0000 Received: from nalasex01c.na.qualcomm.com (nalasex01c.na.qualcomm.com [10.47.97.35]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 30D4BLZm011464 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 13 Jan 2023 04:11:21 GMT Received: from hu-bjorande-lv.qualcomm.com (10.49.16.6) by nalasex01c.na.qualcomm.com (10.47.97.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Thu, 12 Jan 2023 20:11:21 -0800 From: Bjorn Andersson To: Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Heikki Krogerus , Bjorn Andersson CC: , , Subject: [PATCH v2 2/2] usb: typec: mux: Introduce GPIO-based SBU mux Date: Thu, 12 Jan 2023 20:11:15 -0800 Message-ID: <20230113041115.4189210-2-quic_bjorande@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230113041115.4189210-1-quic_bjorande@quicinc.com> References: <20230113041115.4189210-1-quic_bjorande@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01c.na.qualcomm.com (10.47.97.35) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: N0qIkdJR3d6XBGuAV1H4QrUWkbpG7o65 X-Proofpoint-GUID: N0qIkdJR3d6XBGuAV1H4QrUWkbpG7o65 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-12_14,2023-01-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 suspectscore=0 malwarescore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301130026 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754879244453063000?= X-GMAIL-MSGID: =?utf-8?q?1754879244453063000?= From: Bjorn Andersson A design found in various Qualcomm-based boards is to use a USB switch, controlled through a pair of GPIO lines to connect, disconnect and switch the orientation of the SBU lines in USB Type-C applications. This introduces a generic driver, which implements the typec_switch and typec_mux interfaces to perform these operations. Signed-off-by: Bjorn Andersson Signed-off-by: Bjorn Andersson Reviewed-by: Heikki Krogerus --- Changes since v1: - Fixed "swapped" being uninitialized for TYPEC_ORIENTATION_NONE in switch_set drivers/usb/typec/mux/Kconfig | 6 + drivers/usb/typec/mux/Makefile | 1 + drivers/usb/typec/mux/gpio-sbu-mux.c | 172 +++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 drivers/usb/typec/mux/gpio-sbu-mux.c diff --git a/drivers/usb/typec/mux/Kconfig b/drivers/usb/typec/mux/Kconfig index 5eb2c17d72c1..c46fa4f9d3df 100644 --- a/drivers/usb/typec/mux/Kconfig +++ b/drivers/usb/typec/mux/Kconfig @@ -12,6 +12,12 @@ config TYPEC_MUX_FSA4480 common USB Type-C connector. If compiled as a module, the module will be named fsa4480. +config TYPEC_MUX_GPIO_SBU + tristate "Generic GPIO based SBU mux for USB Type-C applications" + help + Say Y or M if your system uses a GPIO based mux for managing the + connected state and the swapping of the SBU lines in a Type-C port. + config TYPEC_MUX_PI3USB30532 tristate "Pericom PI3USB30532 Type-C cross switch driver" depends on I2C diff --git a/drivers/usb/typec/mux/Makefile b/drivers/usb/typec/mux/Makefile index e52a56c16bfb..dda67e19b58b 100644 --- a/drivers/usb/typec/mux/Makefile +++ b/drivers/usb/typec/mux/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC_MUX_FSA4480) += fsa4480.o +obj-$(CONFIG_TYPEC_MUX_GPIO_SBU) += gpio-sbu-mux.o obj-$(CONFIG_TYPEC_MUX_PI3USB30532) += pi3usb30532.o obj-$(CONFIG_TYPEC_MUX_INTEL_PMC) += intel_pmc_mux.o diff --git a/drivers/usb/typec/mux/gpio-sbu-mux.c b/drivers/usb/typec/mux/gpio-sbu-mux.c new file mode 100644 index 000000000000..f62516dafe8f --- /dev/null +++ b/drivers/usb/typec/mux/gpio-sbu-mux.c @@ -0,0 +1,172 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct gpio_sbu_mux { + struct gpio_desc *enable_gpio; + struct gpio_desc *select_gpio; + + struct typec_switch_dev *sw; + struct typec_mux_dev *mux; + + struct mutex lock; /* protect enabled and swapped */ + bool enabled; + bool swapped; +}; + +static int gpio_sbu_switch_set(struct typec_switch_dev *sw, + enum typec_orientation orientation) +{ + struct gpio_sbu_mux *sbu_mux = typec_switch_get_drvdata(sw); + bool enabled; + bool swapped; + + mutex_lock(&sbu_mux->lock); + + enabled = sbu_mux->enabled; + swapped = sbu_mux->swapped; + + switch (orientation) { + case TYPEC_ORIENTATION_NONE: + enabled = false; + break; + case TYPEC_ORIENTATION_NORMAL: + swapped = false; + break; + case TYPEC_ORIENTATION_REVERSE: + swapped = true; + break; + } + + if (enabled != sbu_mux->enabled) + gpiod_set_value(sbu_mux->enable_gpio, enabled); + + if (swapped != sbu_mux->swapped) + gpiod_set_value(sbu_mux->select_gpio, swapped); + + sbu_mux->enabled = enabled; + sbu_mux->swapped = swapped; + + mutex_unlock(&sbu_mux->lock); + + return 0; +} + +static int gpio_sbu_mux_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct gpio_sbu_mux *sbu_mux = typec_mux_get_drvdata(mux); + + mutex_lock(&sbu_mux->lock); + + switch (state->mode) { + case TYPEC_STATE_SAFE: + case TYPEC_STATE_USB: + sbu_mux->enabled = false; + break; + case TYPEC_DP_STATE_C: + case TYPEC_DP_STATE_D: + case TYPEC_DP_STATE_E: + sbu_mux->enabled = true; + break; + default: + break; + } + + gpiod_set_value(sbu_mux->enable_gpio, sbu_mux->enabled); + + mutex_unlock(&sbu_mux->lock); + + return 0; +} + +static int gpio_sbu_mux_probe(struct platform_device *pdev) +{ + struct typec_switch_desc sw_desc = { }; + struct typec_mux_desc mux_desc = { }; + struct device *dev = &pdev->dev; + struct gpio_sbu_mux *sbu_mux; + + sbu_mux = devm_kzalloc(dev, sizeof(*sbu_mux), GFP_KERNEL); + if (!sbu_mux) + return -ENOMEM; + + mutex_init(&sbu_mux->lock); + + sbu_mux->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); + if (IS_ERR(sbu_mux->enable_gpio)) + return dev_err_probe(dev, PTR_ERR(sbu_mux->enable_gpio), + "unable to acquire enable gpio\n"); + + sbu_mux->select_gpio = devm_gpiod_get(dev, "select", GPIOD_OUT_LOW); + if (IS_ERR(sbu_mux->select_gpio)) + return dev_err_probe(dev, PTR_ERR(sbu_mux->select_gpio), + "unable to acquire select gpio\n"); + + sw_desc.drvdata = sbu_mux; + sw_desc.fwnode = dev_fwnode(dev); + sw_desc.set = gpio_sbu_switch_set; + + sbu_mux->sw = typec_switch_register(dev, &sw_desc); + if (IS_ERR(sbu_mux->sw)) + return dev_err_probe(dev, PTR_ERR(sbu_mux->sw), + "failed to register typec switch\n"); + + mux_desc.drvdata = sbu_mux; + mux_desc.fwnode = dev_fwnode(dev); + mux_desc.set = gpio_sbu_mux_set; + + sbu_mux->mux = typec_mux_register(dev, &mux_desc); + if (IS_ERR(sbu_mux->mux)) { + typec_switch_unregister(sbu_mux->sw); + return dev_err_probe(dev, PTR_ERR(sbu_mux->mux), + "failed to register typec mux\n"); + } + + platform_set_drvdata(pdev, sbu_mux); + + return 0; +} + +static int gpio_sbu_mux_remove(struct platform_device *pdev) +{ + struct gpio_sbu_mux *sbu_mux = platform_get_drvdata(pdev); + + gpiod_set_value(sbu_mux->enable_gpio, 0); + + typec_mux_unregister(sbu_mux->mux); + typec_switch_unregister(sbu_mux->sw); + + return 0; +} + +static const struct of_device_id gpio_sbu_mux_match[] = { + { .compatible = "gpio-sbu-mux", }, + {} +}; +MODULE_DEVICE_TABLE(of, gpio_sbu_mux_match); + +static struct platform_driver gpio_sbu_mux_driver = { + .probe = gpio_sbu_mux_probe, + .remove = gpio_sbu_mux_remove, + .driver = { + .name = "gpio_sbu_mux", + .of_match_table = gpio_sbu_mux_match, + }, +}; +module_platform_driver(gpio_sbu_mux_driver); + +MODULE_DESCRIPTION("GPIO based SBU mux driver"); +MODULE_LICENSE("GPL");