From patchwork Mon Aug 1 10:14:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 594836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0389C19F29 for ; Mon, 1 Aug 2022 10:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbiHAK1U (ORCPT ); Mon, 1 Aug 2022 06:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229987AbiHAK1S (ORCPT ); Mon, 1 Aug 2022 06:27:18 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 132A3193FF; Mon, 1 Aug 2022 03:27:18 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id h132so9288100pgc.10; Mon, 01 Aug 2022 03:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=A+DCZgVJ0CsaRwE83F/0raSGoaEkswc7t3B15LpI0LQ=; b=c/UcHHep3nR8roeLhAGe11ERMCmDBIvnPCIvKoe22wfOjXeupbCvwDXH8yuyOHcpGM 8TsvCRIc1hlI1mGX2IiGZWHVqx97SuASvBOSRnyrlTCjYxwlK7SwTEXqs+k1fSVCDy7Z JATdW96dSHuBczPjXSGWNhjZSy9oqpwawRYRHOIi2i3jhN0/WDW3sUN/SBXYbvRiA+Cn IEVXpCF13nqn2/gOsI1Dj/hOfDIBXiV8xr6X83NtlOKE7wcAQVkyvtUM1tYbtZEtEVsy OIq01oskUp+s78P/ZSJmTgMnBAJkydzwv5dYcJBMvej+4ZFU1C+gsT9kQv0rJuq4kj56 vK3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=A+DCZgVJ0CsaRwE83F/0raSGoaEkswc7t3B15LpI0LQ=; b=Kf5BnL0c4Ah10ioKNXLdtqbURw9OAgxJK/JS30XtfxG74lF09drOritU1lQTB+SlaX vdA4eYTBlTAM6LWz/zqpv42IO0M9h84IIwOjvZw117ojaBp+wxMQPSngV72/dyq8AiJF c1BZL75YERHfTZ/6/+0ObpPYlRQiT5JPdfeBzy6KZw/GfI7973dylJtULP50e3Mmpvm5 HwedNDulq+Z49qm91SqXBYi0qdUexJDyxG9chzDb4HnHdYPiDncrIS6mtjc+CtKB0x2E oYrv0KYMh3rI6ZVj+9C0SQd+QO+dzNSY0KE+gL7OEoqDi1ULt9IH7op0foT/eG0ADIoU om4g== X-Gm-Message-State: ACgBeo1pdyWRN/tZq6fpNM0aUvWHWv3HsGkuqhSkl97vpXfvd07AIBII iCwqFHqwRDNBfARnQ0sdFs6nAIw6Kx0= X-Google-Smtp-Source: AA6agR7LDhIUnkFvMdkr+sGmWldlqEVConHLcJAy+OaIqQ8Le7ZQ+KFcC1ClV+DtPyNlLO8uRxfcnw== X-Received: by 2002:a05:6a00:cc1:b0:52d:a29d:fb1 with SMTP id b1-20020a056a000cc100b0052da29d0fb1mr1500585pfv.56.1659349637550; Mon, 01 Aug 2022 03:27:17 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:17 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com, Rob Herring Subject: [PATCH v3 1/7] dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H Date: Mon, 1 Aug 2022 18:14:41 +0800 Message-Id: <20220801101447.86207-2-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Add binding for Richtek RT1711H Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../bindings/usb/richtek,rt1711h.yaml | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml diff --git a/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml b/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml new file mode 100644 index 000000000000..1999f614c89b --- /dev/null +++ b/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml @@ -0,0 +1,100 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/richtek,rt1711h.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Richtek RT1711H Type-C Port Switch and Power Delivery controller + +maintainers: + - Gene Chen + +description: | + The RT1711H is a USB Type-C controller that complies with the latest + USB Type-C and PD standards. It does the USB Type-C detection including attach + and orientation. It integrates the physical layer of the USB BMC power + delivery protocol to allow up to 100W of power. The BMC PD block enables full + support for alternative interfaces of the Type-C specification. + +properties: + compatible: + enum: + - richtek,rt1711h + - richtek,rt1715 + description: + RT1711H support PD20, RT1715 support PD30 except Fast Role Swap. + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + wakeup-source: + type: boolean + + connector: + type: object + $ref: /schemas/connector/usb-connector.yaml# + description: + Properties for usb c connector. + +additionalProperties: false + +required: + - compatible + - reg + - connector + - interrupts + +examples: + - | + #include + #include + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + + rt1711h@4e { + compatible = "richtek,rt1711h"; + reg = <0x4e>; + interrupts-extended = <&gpio26 3 IRQ_TYPE_LEVEL_LOW>; + wakeup-source; + + connector { + compatible = "usb-c-connector"; + label = "USB-C"; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = ; + sink-pdos = ; + op-sink-microwatt = <10000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + endpoint { + remote-endpoint = <&usb_hs>; + }; + }; + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&usb_ss>; + }; + }; + port@2 { + reg = <2>; + endpoint { + remote-endpoint = <&dp_aux>; + }; + }; + }; + }; + }; + }; +... From patchwork Mon Aug 1 10:14:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595086 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DF5EC19F2C for ; Mon, 1 Aug 2022 10:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230149AbiHAK1W (ORCPT ); Mon, 1 Aug 2022 06:27:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiHAK1V (ORCPT ); Mon, 1 Aug 2022 06:27:21 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B762319C10; Mon, 1 Aug 2022 03:27:20 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id q7-20020a17090a7a8700b001f300db8677so11479659pjf.5; Mon, 01 Aug 2022 03:27:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=frVSMV4VhRB7VzLFLyUnxtQ5dfraq7Cu44qOlKTHpGs=; b=HYqDPObCoEF46Ks9CpZo0dQbp/b+zny2p7vsC98SS8LeSyDRu031hTVUxMFZeXtvPT VMi6P2f0rEHzW1bNA9qsDbSs5CA24TjZR/HRPEk0rW1Meft1rtMH4CX7dG0jqsYZYHY5 YKRyY8CK68UsBsWX/DH33vLya28bMV6aqffjNnfl9ZnYjiTvR3mCzSfKwUkQq6lusqM+ 1POYcmrtaWU2JzKpEHgcsZ5PDT3kfD2dBvdASSFWb2E1b29Xg67G+t2o+fYPjTEixjOX 6tD5bznwG5l5VsRwY4pt5Z/dIHHlKBQhoYrRhgFCyXPb47OmfmAAjiiSCBWz5rJ2y8Rg FD6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=frVSMV4VhRB7VzLFLyUnxtQ5dfraq7Cu44qOlKTHpGs=; b=Mbx3TmorzCK7Zqzgx7d8Peck9eSEpKXRWJzQ8RK4zwncScXMrLyNah4dxQlcvUQOwq 5eTgw1eSLq48UhnCntQPLS335rxDVjHEJwIz01n/JmAe7nCQdNeam7k7ksejVaAbvNm6 jXAYjO9ufVJ2YDc2tAsXV/K4u1A5GE8yxO72HIcWxjUQDsT4DajxHNQc3ZMNngUc1TDm bq2ms9BkFZIBKySDFAiGeFC97tSJwlM1NpLMGz5d7LPhXeGNFBaVnB8aEVXXJXlI9HAb +zfp9YFM31nJ1u97luQJ16F/CzYo45pbNGfxpvh1sLBEsOJnzGezcFQw8RklpqHxJjj5 QKcg== X-Gm-Message-State: ACgBeo0L6WOadT3AZuxba2i4x+fgvuCrF/q2dJSU3drGNw7WlLgxM+5B 2urbRwdhe/gbZmwRL3b2HHM= X-Google-Smtp-Source: AA6agR7YuShjPPKdweyXhZC9uAYiud+U8Cm+OkZeaNI6XQuiVt9+ugfDwC32pJhrO5ElGpJG9xj+0w== X-Received: by 2002:a17:90b:4c8d:b0:1f2:c360:5e6b with SMTP id my13-20020a17090b4c8d00b001f2c3605e6bmr18919118pjb.195.1659349640305; Mon, 01 Aug 2022 03:27:20 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:19 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 2/7] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn Date: Mon, 1 Aug 2022 18:14:42 +0800 Message-Id: <20220801101447.86207-3-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen replace overwrite whole register with update bits Signed-off-by: Gene Chen --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index b56a0880a044..6197d9a05d36 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -5,13 +5,15 @@ * Richtek RT1711H Type-C Chip Driver */ -#include -#include +#include +#include #include #include -#include -#include +#include +#include #include +#include + #include "tcpci.h" #define RT1711H_VID 0x29CF @@ -23,6 +25,7 @@ #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ (((ck300) << 7) | ((ship_off) << 5) | \ ((auto_idle) << 3) | ((tout) & 0x07)) +#define RT1711H_AUTOIDLEEN BIT(3) #define RT1711H_RTCTRL11 0x9E @@ -109,8 +112,8 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, { struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); - return rt1711h_write8(chip, RT1711H_RTCTRL8, - RT1711H_RTCTRL8_SET(0, 1, !enable, 2)); + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL8, + RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN); } static int rt1711h_start_drp_toggling(struct tcpci *tcpci, From patchwork Mon Aug 1 10:14:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 594835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B87C0C3F6B0 for ; Mon, 1 Aug 2022 10:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbiHAK1c (ORCPT ); Mon, 1 Aug 2022 06:27:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230192AbiHAK10 (ORCPT ); Mon, 1 Aug 2022 06:27:26 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DF201BEB8; Mon, 1 Aug 2022 03:27:24 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id m2so3282195pls.4; Mon, 01 Aug 2022 03:27:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Y7hOrypHABOrUYY7mPx6WzbUKkmZSajxEE3MVrQlsPs=; b=b15uEYkWYgfp537+pzlYAD4ZzavMpQrl+KgbOwrIyXQi8OU009J7s9NjHe8OnT47MB ors41+qa2lRASDWKPsTsfnjUDwtkjPIG/KWSWzeaLTp3nAQHD44xlO47gqzxMYtLECZZ sUjSkOKTwJuR8iMXlXOwoSoWU8z4Ojl2Y3mqvi49oSpYeiCkhlplDbtJGl+3k/AfshqB p8QtT8IJDrgs4jS8cZaWJxv6lbYVgfSBeusyuteTDF8p+elq7jWwiOOOppWiwWeIjTG0 qYil2bBabWn+ucGIa950ukMpFJmgwFQq9QLzIG58SU3jUr14YuAFUR5aBK22cbBNlt/o 8Jrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Y7hOrypHABOrUYY7mPx6WzbUKkmZSajxEE3MVrQlsPs=; b=onQfLqw+BrbjL62iARaeLef8JznkBxMimyeparagUPVvqsz1UAwrLL/SF/8FiJ67Ec I7DpYcUIU5VeznnNK6TP+m5+z/wRXnVIq8qSoaboSzdGo6Sq972VcFoO0nEHtPy+nz31 1/zDSBgMbqkGj4febU15+L7hcjrJK5h1hCwPn34SPnZwecYzpRShUl0WbjeMsv+wHqCS Fv/WmPVS7/ifKx7RQ48AFjdRE6ch+/b1p5Z1vAT8IsxUmJHfu81i56QmD9CpeKuqJm/9 x73gZ6ZNk3mMjxU8xy4Dp5DfcPbN5HzcjPZ/2e//V0krnvACN/tA9qDw4EIOXestiUEs HQLA== X-Gm-Message-State: ACgBeo2cag/vXRkrIB4xoJz7BngCSMPYtOVvd5PwnzJsoWM4/jaxo+HK pGNHCEb8D8UbrZ3G7iT/lko= X-Google-Smtp-Source: AA6agR4unMXM/o8ReAcZPhZYlQvKEykwqvDuzjzFUoluKCpKIsGMEVPbfjJmmeMiZtpmk8I3s2wRkw== X-Received: by 2002:a17:90b:3702:b0:1f3:366c:8c77 with SMTP id mg2-20020a17090b370200b001f3366c8c77mr17409901pjb.119.1659349643076; Mon, 01 Aug 2022 03:27:23 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:22 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 3/7] usb: typec: tcpci_rt1711h: Add regulator support when source vbus Date: Mon, 1 Aug 2022 18:14:43 +0800 Message-Id: <20220801101447.86207-4-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Add regulator support when source vbus Signed-off-by: Gene Chen Acked-by: Heikki Krogerus --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index 6197d9a05d36..df7bfe299987 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "tcpci.h" @@ -42,6 +43,8 @@ struct rt1711h_chip { struct tcpci_data data; struct tcpci *tcpci; struct device *dev; + struct regulator *vbus; + bool src_en; }; static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) @@ -105,6 +108,26 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) /* dcSRC.DRP : 33% */ return rt1711h_write16(chip, RT1711H_RTCTRL16, 330); + +} + +static int rt1711h_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, + bool src, bool snk) +{ + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); + int ret; + + if (chip->src_en == src) + return 0; + + if (src) + ret = regulator_enable(chip->vbus); + else + ret = regulator_disable(chip->vbus); + + if (!ret) + chip->src_en = src; + return ret; } static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, @@ -248,7 +271,12 @@ static int rt1711h_probe(struct i2c_client *client, if (ret < 0) return ret; + chip->vbus = devm_regulator_get(&client->dev, "vbus"); + if (IS_ERR(chip->vbus)) + return PTR_ERR(chip->vbus); + chip->data.init = rt1711h_init; + chip->data.set_vbus = rt1711h_set_vbus; chip->data.set_vconn = rt1711h_set_vconn; chip->data.start_drp_toggling = rt1711h_start_drp_toggling; chip->tcpci = tcpci_register_port(chip->dev, &chip->data); From patchwork Mon Aug 1 10:14:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A1A9C19F2C for ; Mon, 1 Aug 2022 10:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230353AbiHAK1g (ORCPT ); Mon, 1 Aug 2022 06:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbiHAK1c (ORCPT ); Mon, 1 Aug 2022 06:27:32 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D942419C38; Mon, 1 Aug 2022 03:27:26 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id t22so2381905pjy.1; Mon, 01 Aug 2022 03:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g5YVwMbfoYCofIWCorsteoCV1pt7aCEVid0X5JBcygY=; b=Y+lx3Dwm1gkBmrkas25JUF15WSaRBt8UhZa+Nr5YzrMDbiK2+wZekQHXeATtlzKzLB aorpp0O/x0i8UVqAxvGqWOU+pAu+KQ5HDGznBxfO5m1LySNfz35MKzKZ6YHoieMufzHy 01BVxdB+aCzyThk7qP/T/i/UrNW13V4tDfxjnqDELSQ4Jqn+G3TCZmz9EuQiblIPaXzj TvfLBMXqpAExhomORPvXnY7ZMTTBHvu6ceNZlcmC/XVunjrk8MpMxfQJ5IqvHEyUsRdx YEowOvuNCaud13azGongKR4A4eyO9ZT29flerZtCV95fGmMfQ8mebQ2CLYaiRa+faPpW fQVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g5YVwMbfoYCofIWCorsteoCV1pt7aCEVid0X5JBcygY=; b=dyUPsSQqa4emVeeiQVOdGj3gYNIOzFGqCWpC/8tYU/32kIJm9+vjG/5feL+zKr6+Qi DjjSul4BZnyR6CkgMJJNHbb1TldXaq0GA7cHaJykSskgcETCHhom+wr1hqzcU8Bd5fD2 E2zNCSks31N3RrppC3PXwX7RQENKgk8CmKSMftK8gSDpZMPLxSECuk5fWwHYBoHne42k Vcq1rHgPcFvV2Hx+XQZDQy5CCC7H351jaxYP4qQRbSsSCe+68+NR9591XNLrkRTSW/pX U6g5Qho3k22+lQI3W5YFQ/qM0yychPD6DTW0G0ZNnkT0uAG4tXxugJLGeRBx6qNtu+/W 7aPw== X-Gm-Message-State: ACgBeo18NVsaVuAKuJnxpt/jPZfRjrGvQ646Wb49ubLbvHtAFw//V09J KUF/GvKeA2p9yu5/v+dVTcU= X-Google-Smtp-Source: AA6agR413BUb0F1GXJaukYg7s1OSc3wndvXfdZS6iFk+Odl1NEbVqGLO2xjgdowqCkhojUSxx+LnDA== X-Received: by 2002:a17:90b:3947:b0:1f5:104:f8cd with SMTP id oe7-20020a17090b394700b001f50104f8cdmr4270191pjb.26.1659349645692; Mon, 01 Aug 2022 03:27:25 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:25 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 4/7] usb: typec: tcpci_rt1711h: Add initial phy setting Date: Mon, 1 Aug 2022 18:14:44 +0800 Message-Id: <20220801101447.86207-5-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Add initial phy setting about phy dicard retry, rx filter deglitech time and BMC-encoded wait time Signed-off-by: Gene Chen Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index df7bfe299987..33d8ea95b7c1 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -20,6 +20,9 @@ #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 +#define RT1711H_PHYCTRL1 0x80 +#define RT1711H_PHYCTRL2 0x81 + #define RT1711H_RTCTRL8 0x9B /* Autoidle timeout = (tout * 2 + 1) * 6.4ms */ @@ -107,8 +110,18 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) return ret; /* dcSRC.DRP : 33% */ - return rt1711h_write16(chip, RT1711H_RTCTRL16, 330); + ret = rt1711h_write16(chip, RT1711H_RTCTRL16, 330); + if (ret < 0) + return ret; + + /* Enable phy discard retry, retry count 7, rx filter deglitech 100 us */ + ret = rt1711h_write8(chip, RT1711H_PHYCTRL1, 0xF1); + if (ret < 0) + return ret; + /* Decrease wait time of BMC-encoded 1 bit from 2.67us to 2.55us */ + /* wait time : (val * .4167) us */ + return rt1711h_write8(chip, RT1711H_PHYCTRL2, 62); } static int rt1711h_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, From patchwork Mon Aug 1 10:14:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 594834 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 542DEC19F2C for ; Mon, 1 Aug 2022 10:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbiHAK1n (ORCPT ); Mon, 1 Aug 2022 06:27:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbiHAK1e (ORCPT ); Mon, 1 Aug 2022 06:27:34 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D2531A04A; Mon, 1 Aug 2022 03:27:30 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id w7so10027041ply.12; Mon, 01 Aug 2022 03:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hld/LwJZmpI7SSFkZzrwucLdPGX6JD19gxp/p1qSXXA=; b=Axx8121q9h4v9e99XYadG6Kg7vgzQec74kh60Otf9yCT/h/x3UgvEyNiCNIGiw+ina jmHyAI9BKZtj3QEvkoTnkZ+q5xLBcvS5umkwM+QPyzREv9bdjlCKU9lqWxuILm0z5eh3 Kbhb1ycRsWAWRGi6QTHCrk0NYBPOm4lVBZobu5PD7+2ASpHqeEaGkHbLRGwi756GUu1N bHvFdO1cUzU5bbc1vrLhFMAGTLxArGBmAHZS1y7vOQpuziwquBHks6q535OECy8yeDFX pI6E8OK812rb7pCVylB3Bbx/HSq/+nKyrkGaTITU+aGEu0PpWpprBi2I8VNIh5UR4qf8 IlhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hld/LwJZmpI7SSFkZzrwucLdPGX6JD19gxp/p1qSXXA=; b=lo1dEuDWzCM1/Ii9Du3+ChE/LbKSnqrw30JeVRdbsMS07uLfNxlvCsLw2+B5KsDa47 VFd8pWukV/mEhJKDMLTFNKrXes5QT1s1xeoU2lvO4hq7Mju4vOK7hdZB0fT3PiV5EwBm cVRc+Hko+koQA+0B8N6TuKRcrN81OCluD377cNrfiorLwTXa3pw0a3krzBJnRCBXcYpT +ze5RMd/mdl9J2AzKmduDNqH+R13f72+HZ00CQRzbRTiO+x1abMaYLyZ3Xf5egHDtOZe 5X4f0cKNOSEtiRhfMbRIlJu0GdNQ+N37PPU6OssJbu8iZ6Dfvez4VFykz/irFwQHjfUu f4zw== X-Gm-Message-State: ACgBeo1U1Pto64NChsliouO0EG+QIApoW1oQAvguqtCX1+5oko1ybFXs DGOphTo3VQDcTjP+2BQNQJrpefq93Qw= X-Google-Smtp-Source: AA6agR4wZ1ePsXl/0MxEGav1fKUQLipX9uPB5Uw9DNNNZsGCAmkrqonwyl6Ou+ZfFjL7RcLszY+AHg== X-Received: by 2002:a17:902:ca0b:b0:16d:d562:42dc with SMTP id w11-20020a170902ca0b00b0016dd56242dcmr13586425pld.26.1659349648338; Mon, 01 Aug 2022 03:27:28 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:28 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 5/7] usb: typec: tcpci_rt1711h: Add compatible id with rt1715 Date: Mon, 1 Aug 2022 18:14:45 +0800 Message-Id: <20220801101447.86207-6-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Add compatible id with rt1715, and add initial setting for specific support PD30 command. Signed-off-by: Gene Chen Acked-by: Heikki Krogerus --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 43 ++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index 33d8ea95b7c1..da35dd3e8a59 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -19,6 +19,8 @@ #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 +#define RT1711H_DID 0x2171 +#define RT1715_DID 0x2173 #define RT1711H_PHYCTRL1 0x80 #define RT1711H_PHYCTRL2 0x81 @@ -30,6 +32,7 @@ (((ck300) << 7) | ((ship_off) << 5) | \ ((auto_idle) << 3) | ((tout) & 0x07)) #define RT1711H_AUTOIDLEEN BIT(3) +#define RT1711H_ENEXTMSG BIT(4) #define RT1711H_RTCTRL11 0x9E @@ -48,6 +51,7 @@ struct rt1711h_chip { struct device *dev; struct regulator *vbus; bool src_en; + u16 did; }; static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) @@ -84,8 +88,9 @@ static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata) static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) { - int ret; struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); + struct regmap *regmap = chip->data.regmap; + int ret; /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */ ret = rt1711h_write8(chip, RT1711H_RTCTRL8, @@ -93,6 +98,14 @@ static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata) if (ret < 0) return ret; + /* Enable PD30 extended message for RT1715 */ + if (chip->did == RT1715_DID) { + ret = regmap_update_bits(regmap, RT1711H_RTCTRL8, + RT1711H_ENEXTMSG, RT1711H_ENEXTMSG); + if (ret < 0) + return ret; + } + /* I2C reset : (val + 1) * 12.5ms */ ret = rt1711h_write8(chip, RT1711H_RTCTRL11, RT1711H_RTCTRL11_SET(1, 0x0F)); @@ -230,7 +243,7 @@ static int rt1711h_sw_reset(struct rt1711h_chip *chip) return 0; } -static int rt1711h_check_revision(struct i2c_client *i2c) +static int rt1711h_check_revision(struct i2c_client *i2c, struct rt1711h_chip *chip) { int ret; @@ -248,7 +261,15 @@ static int rt1711h_check_revision(struct i2c_client *i2c) dev_err(&i2c->dev, "pid is not correct, 0x%04x\n", ret); return -ENODEV; } - return 0; + ret = i2c_smbus_read_word_data(i2c, TCPC_BCD_DEV); + if (ret < 0) + return ret; + if (ret != chip->did) { + dev_err(&i2c->dev, "did is not correct, 0x%04x\n", ret); + return -ENODEV; + } + dev_dbg(&i2c->dev, "did is 0x%04x\n", ret); + return ret; } static int rt1711h_probe(struct i2c_client *client, @@ -257,16 +278,18 @@ static int rt1711h_probe(struct i2c_client *client, int ret; struct rt1711h_chip *chip; - ret = rt1711h_check_revision(client); + chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->did = (size_t)device_get_match_data(&client->dev); + + ret = rt1711h_check_revision(client, chip); if (ret < 0) { dev_err(&client->dev, "check vid/pid fail\n"); return ret; } - chip = devm_kzalloc(&client->dev, sizeof(*chip), GFP_KERNEL); - if (!chip) - return -ENOMEM; - chip->data.regmap = devm_regmap_init_i2c(client, &rt1711h_regmap_config); if (IS_ERR(chip->data.regmap)) @@ -317,13 +340,15 @@ static int rt1711h_remove(struct i2c_client *client) static const struct i2c_device_id rt1711h_id[] = { { "rt1711h", 0 }, + { "rt1715", 0 }, { } }; MODULE_DEVICE_TABLE(i2c, rt1711h_id); #ifdef CONFIG_OF static const struct of_device_id rt1711h_of_match[] = { - { .compatible = "richtek,rt1711h", }, + { .compatible = "richtek,rt1711h", .data = (void *)RT1711H_DID }, + { .compatible = "richtek,rt1715", .data = (void *)RT1715_DID }, {}, }; MODULE_DEVICE_TABLE(of, rt1711h_of_match); From patchwork Mon Aug 1 10:14:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1408AC19F29 for ; Mon, 1 Aug 2022 10:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbiHAK1q (ORCPT ); Mon, 1 Aug 2022 06:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiHAK1h (ORCPT ); Mon, 1 Aug 2022 06:27:37 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 147413135D; Mon, 1 Aug 2022 03:27:31 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id c19-20020a17090ae11300b001f2f94ed5c6so11541217pjz.1; Mon, 01 Aug 2022 03:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aMQXlAeibSzqAHZrn8sdnWaDWRBBULUI/PyUWAhs7hM=; b=oCzMuYJfl7tSHzg8p3lJYwNGlbDHl7kcbAon3AdnoL8p611lgqJUpV1ltxHDvaPZbf CMftQN02NbtnXCmy4R0Xa6Ea4DrNraeKR0ecFWy5sXVskcT4ORFm1Ve5aSNSIE2XukzG HnnBAseDVFRHeAfq9/NgzGuPn4rZDp/US1va8giByPVulMxX8STkQvMyicoD4t23kbNr G7vlpVllv1HpS9bIwG2a7RNRzUmHj0Wet8vWn7HDnbdkP46u4vNN2cFhJJr7F7pTWmz4 t8nsODWOFOhrFtWYnqvKtrC9PqMXIFUKw+RRE6eeAcBOwiJ9vYsE0rYhL7Acwyk4gLlD 6chw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aMQXlAeibSzqAHZrn8sdnWaDWRBBULUI/PyUWAhs7hM=; b=pDBkzwwhZQCic7rV/C/Eh3Le+WSQsvF6xOMXasqeLvwpjkMUi84E3leM/yRQOwtUUz c6Zzoblqle+2yie00rg/oCFtgiRb4f6DInmGBCZiMCfL1Ynn2bTMXc5tkfE/dHWRgwkX dKIMd1kAb0pJT5K6izZmHLG55f4g3LS3OQOGc0kayEXT/fdKfKZBfhmd8VDEZZnmA0Ps Uv0Ufe9xBl9T0rPb+yEUy3cvXgRbohwOIay0t0OuuHnc1iZCDcDACtIX7f4Ai5Ool6cE RLR2O5AUmh8OkQezd7Dy7rEXaMVl6O5KDNurpKk5+XODOBfKeqCftrT1AVYnvhfN9Ejw jxeQ== X-Gm-Message-State: ACgBeo24v0Cv7fNkhAd6fhdPokNNC+goSK64tvty8/SPs+JUXc7yt+07 8H9aCim63I5AgtzKdXwVXTQ= X-Google-Smtp-Source: AA6agR6qM15kGKNw3PzJ7gxZyJ2rJPPP423PNyoDHHmeRqNJA/vprLTjiuEKCv+OSqcnND59rYVS1g== X-Received: by 2002:a17:902:e749:b0:16c:3d6f:aba3 with SMTP id p9-20020a170902e74900b0016c3d6faba3mr15607878plf.135.1659349650979; Mon, 01 Aug 2022 03:27:30 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:30 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 6/7] usb: typec: tcpci: Move function "tcpci_to_typec_cc" to common Date: Mon, 1 Aug 2022 18:14:46 +0800 Message-Id: <20220801101447.86207-7-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Move transition function "tcpci_to_typec_cc" to common header Signed-off-by: Gene Chen --- drivers/usb/typec/tcpm/tcpci.c | 22 ---------------------- drivers/usb/typec/tcpm/tcpci.h | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index f33e08eb7670..0f45d456df32 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -28,11 +28,6 @@ #define VPPS_VALID_MIN_MV 100 #define VSINKDISCONNECT_PD_MIN_PERCENT 90 -#define tcpc_presenting_rd(reg, cc) \ - (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ - (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ - (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) - struct tcpci { struct device *dev; @@ -219,23 +214,6 @@ static int tcpci_start_toggling(struct tcpc_dev *tcpc, TCPC_CMD_LOOK4CONNECTION); } -static enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink) -{ - switch (cc) { - case 0x1: - return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA; - case 0x2: - return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD; - case 0x3: - if (sink) - return TYPEC_CC_RP_3_0; - fallthrough; - case 0x0: - default: - return TYPEC_CC_OPEN; - } -} - static int tcpci_get_cc(struct tcpc_dev *tcpc, enum typec_cc_status *cc1, enum typec_cc_status *cc2) { diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h index b2edd45f13c6..3f45cb0426df 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h @@ -166,6 +166,11 @@ /* I2C_WRITE_BYTE_COUNT + 1 when TX_BUF_BYTE_x is only accessible I2C_WRITE_BYTE_COUNT */ #define TCPC_TRANSMIT_BUFFER_MAX_LEN 31 +#define tcpc_presenting_rd(reg, cc) \ + (!(TCPC_ROLE_CTRL_DRP & (reg)) && \ + (((reg) & (TCPC_ROLE_CTRL_## cc ##_MASK << TCPC_ROLE_CTRL_## cc ##_SHIFT)) == \ + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_## cc ##_SHIFT))) + struct tcpci; /* @@ -206,4 +211,22 @@ irqreturn_t tcpci_irq(struct tcpci *tcpci); struct tcpm_port; struct tcpm_port *tcpci_get_tcpm_port(struct tcpci *tcpci); + +static inline enum typec_cc_status tcpci_to_typec_cc(unsigned int cc, bool sink) +{ + switch (cc) { + case 0x1: + return sink ? TYPEC_CC_RP_DEF : TYPEC_CC_RA; + case 0x2: + return sink ? TYPEC_CC_RP_1_5 : TYPEC_CC_RD; + case 0x3: + if (sink) + return TYPEC_CC_RP_3_0; + fallthrough; + case 0x0: + default: + return TYPEC_CC_OPEN; + } +} + #endif /* __LINUX_USB_TCPCI_H */ From patchwork Mon Aug 1 10:14:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 594833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E527EC19F2C for ; Mon, 1 Aug 2022 10:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbiHAK2B (ORCPT ); Mon, 1 Aug 2022 06:28:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230229AbiHAK1l (ORCPT ); Mon, 1 Aug 2022 06:27:41 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86093B95B; Mon, 1 Aug 2022 03:27:34 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id v18so10031754plo.8; Mon, 01 Aug 2022 03:27:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=56/QJjULF7AfhC6vcAuv9Bly6Dkpm9meWtKBdCbDI90=; b=dCOo1FunfTVLFeGxeKtOmWYLZCwAVx/HuA8tXZY5lJnHrME/Hj8XXx2MnuAJNAddbq HkVSSdNXTBOn2cZgxRihFz5B7W9OvtFD76g76TiO4tYCeCkCXa2LB2iG9+xDgUVem4k8 peaevhqX6B0MxW0njkE5X3gzrn1a+bmYtj3z8eaZdrENnexDbOQXuT8CkNAbycy7jfXg HXjUPSj0TNM9U4JIBQuJvycAyIFSYVbouvanEfRUkmcVXLmQkkgwAL7psrb/X06H0IEb guc1x4GwPJ/7FVmOEtcfkYj60ii9o+142ioyeYs8Q7uc8W8h+vAoZwi6K+AG6On9UOPX fZrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=56/QJjULF7AfhC6vcAuv9Bly6Dkpm9meWtKBdCbDI90=; b=Db8VOWwCntLS5HZjIr/5Yl3MSTMuT2z0frxaSsGr2rZdoG+JYVbbSaqEJsg4TWAum1 kdyVm70giLN1ah0eD5VWQjG00khncj2QvHts6QknfO6369hZnsQyKxYMQQnyK9q9EUIP YqmTLfX4XeqdA0CoFy9dEjTivvDDgMfpapfu3RiygVtsp6Ddkf3sgf/bph+QGmXf9C7l YPPrkyufLKvfK194tqB6m4Lzh0+WfppPQNull6naD8ZB/jV1S/RlsfPMZPtjFam/KfF6 WJmHaVKeFt+hFURot1hW5hp2NpjDtrrh4OvJbS+0iCA8iCSfzw5vfohQD7W08yhyMMhq 97mw== X-Gm-Message-State: ACgBeo0cGwGBdHFr24ETulL4O4ALHhK0nh2kBPQaMeRbYntfbCgNQNdp jM3FYKGT5F8Ctnj3HFqtIsA= X-Google-Smtp-Source: AA6agR6eVx8+14LniTe55nM7Nmy9BGY51yMgSjQnu/IXnM2mbJT04adOamzI3yk5kjDdW47CwxL2Ew== X-Received: by 2002:a17:902:8302:b0:16d:d74f:e5cc with SMTP id bd2-20020a170902830200b0016dd74fe5ccmr13541293plb.6.1659349653572; Mon, 01 Aug 2022 03:27:33 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:8d46:b2ef:57e3:7c30]) by smtp.gmail.com with ESMTPSA id q12-20020a170902a3cc00b0016c6a6d8967sm9199302plb.83.2022.08.01.03.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Aug 2022 03:27:33 -0700 (PDT) From: Gene Chen To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, gene_chen@richtek.com, cy_huang@richtek.com Subject: [PATCH v3 7/7] usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level Date: Mon, 1 Aug 2022 18:14:47 +0800 Message-Id: <20220801101447.86207-8-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220801101447.86207-1-gene.chen.richtek@gmail.com> References: <20220801101447.86207-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Gene Chen Fix CC PHY noise filter of voltage level according to current cc voltage level Signed-off-by: Gene Chen Acked-by: Heikki Krogerus --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 58 +++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index da35dd3e8a59..6d2568de553b 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -25,8 +25,11 @@ #define RT1711H_PHYCTRL1 0x80 #define RT1711H_PHYCTRL2 0x81 -#define RT1711H_RTCTRL8 0x9B +#define RT1711H_RTCTRL4 0x93 +/* rx threshold of rd/rp: 1b0 for level 0.4V/0.7V, 1b1 for 0.35V/0.75V */ +#define RT1711H_BMCIO_RXDZSEL BIT(0) +#define RT1711H_RTCTRL8 0x9B /* Autoidle timeout = (tout * 2 + 1) * 6.4ms */ #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ (((ck300) << 7) | ((ship_off) << 5) | \ @@ -45,6 +48,10 @@ #define RT1711H_RTCTRL15 0xA2 #define RT1711H_RTCTRL16 0xA3 +#define RT1711H_RTCTRL18 0xAF +/* 1b0 as fixed rx threshold of rd/rp 0.55V, 1b1 depends on RTCRTL4[0] */ +#define BMCIO_RXDZEN BIT(0) + struct rt1711h_chip { struct tcpci_data data; struct tcpci *tcpci; @@ -165,6 +172,53 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, RT1711H_AUTOIDLEEN, enable ? 0 : RT1711H_AUTOIDLEEN); } +/* + * Selects the CC PHY noise filter voltage level according to the remote current + * CC voltage level. + * + * @status: The port's current cc status read from IC + * Return 0 if writes succeed; failure code otherwise + */ +static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, u8 status) +{ + int ret, cc1, cc2; + u8 role = 0; + u32 rxdz_en, rxdz_sel; + + ret = rt1711h_read8(chip, TCPC_ROLE_CTRL, &role); + if (ret < 0) + return ret; + + cc1 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC1_SHIFT) & + TCPC_CC_STATUS_CC1_MASK, + status & TCPC_CC_STATUS_TERM || + tcpc_presenting_rd(role, CC1)); + cc2 = tcpci_to_typec_cc((status >> TCPC_CC_STATUS_CC2_SHIFT) & + TCPC_CC_STATUS_CC2_MASK, + status & TCPC_CC_STATUS_TERM || + tcpc_presenting_rd(role, CC2)); + + if ((cc1 >= TYPEC_CC_RP_1_5 && cc2 < TYPEC_CC_RP_DEF) || + (cc2 >= TYPEC_CC_RP_1_5 && cc1 < TYPEC_CC_RP_DEF)) { + rxdz_en = BMCIO_RXDZEN; + if (chip->did == RT1715_DID) + rxdz_sel = RT1711H_BMCIO_RXDZSEL; + else + rxdz_sel = 0; + } else { + rxdz_en = 0; + rxdz_sel = RT1711H_BMCIO_RXDZSEL; + } + + ret = regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL18, + BMCIO_RXDZEN, rxdz_en); + if (ret < 0) + return ret; + + return regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL4, + RT1711H_BMCIO_RXDZSEL, rxdz_sel); +} + static int rt1711h_start_drp_toggling(struct tcpci *tcpci, struct tcpci_data *tdata, enum typec_cc_status cc) @@ -225,6 +279,8 @@ static irqreturn_t rt1711h_irq(int irq, void *dev_id) /* Clear cc change event triggered by starting toggling */ if (status & TCPC_CC_STATUS_TOGGLING) rt1711h_write8(chip, TCPC_ALERT, TCPC_ALERT_CC_STATUS); + else + rt1711h_init_cc_params(chip, status); } out: