From patchwork Fri Aug 5 07:17:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595890 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 F00A4C25B08 for ; Fri, 5 Aug 2022 07:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240323AbiHEHR6 (ORCPT ); Fri, 5 Aug 2022 03:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240309AbiHEHRy (ORCPT ); Fri, 5 Aug 2022 03:17:54 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B97543E75; Fri, 5 Aug 2022 00:17:53 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id f65so1942054pgc.12; Fri, 05 Aug 2022 00:17:53 -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=4LUOCGnqvpB3ikVZAyY+IzlAAUdQ46t+B/c2CTutSek=; b=eDcSfnuaMdUmbGs80FYVW6w/bzZ7vapm/yugMr3FI751C5geXmskPmk7FsK/EcmPe1 cIMjoKyo16Pdbbp2vTv3ZiY7mj6uTcjK6Ure32hp02tbXVegRrTz7kRA6bilNeQW5FLS 9a5ZFkWzzAjaHaJO6slXENv0yvDchA9aBzBh1uIS7lXAH3gyZqqbBTUGCw1e6cOeHsHE lmjTiPsK8WfcZ2aH2ljmEk1NbmQtMlenWd4BiMuFC29crcGj6cdwQBpG1le/jPOrwWaK /zW6Ei5Dd8v6fJpr55kOTf2OrzJmoOungI1O6A/GxcGrisTqumvloHwEd9ZeXN8Xg0LF 36/g== 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=4LUOCGnqvpB3ikVZAyY+IzlAAUdQ46t+B/c2CTutSek=; b=ljKxLCL4PQuboOMJKHRuHpjoJKOA47Ubr8q+752BidnrgQEn47qj7DdywKmW4CJ2q1 COHp/XSBvp5jYOMhG50J676ycPUk3Ej5URNGFZ3jwcmTnmKEocxgxUXePaQGkx7Ohpo5 jBHST75J9n67zcwQNcA7r2MF4+CmuUFh1GpdJGgT6fIDW2BS3UpA/GhiGheSQp2cdpQx Mg8E5dXBhYNP5b4pXNwcIhKBJgFXHIGbtPGSSsmlFZVF6Dzis+gLGNXK9Sfvi6Y5A3Nc aNMBZoAws9K96FFCbMyO+715z8a9JwBt8dB4k6DJ8yok3VRGaAPhOuFn4G6pRgOKpUQ+ jy0g== X-Gm-Message-State: ACgBeo074tQUfcL8SLL4MPJn9tMk7ejni6vHCJiobsZNjkLi6LRhlFoC 1kdCUEC/VIbiXAAm7f+5zog= X-Google-Smtp-Source: AA6agR6lkRElDutx6frjc4OTHiFmD3P6JjNae00CeLIzwKMqGsbMhPeO1XMvqtChruP5vlHWpFTA5A== X-Received: by 2002:a63:6846:0:b0:415:bb65:d6f0 with SMTP id d67-20020a636846000000b00415bb65d6f0mr4779792pgc.238.1659683872265; Fri, 05 Aug 2022 00:17:52 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.17.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:17:52 -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 v4 1/7] dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H Date: Fri, 5 Aug 2022 15:17:07 +0800 Message-Id: <20220805071714.150882-2-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Gene Chen Add binding for Richtek RT1711H Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../devicetree/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 0000000..1999f61 --- /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 Fri Aug 5 07:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595636 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 2A6E0C25B0C for ; Fri, 5 Aug 2022 07:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240287AbiHEHR7 (ORCPT ); Fri, 5 Aug 2022 03:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240286AbiHEHR5 (ORCPT ); Fri, 5 Aug 2022 03:17:57 -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 1F41139BBC; Fri, 5 Aug 2022 00:17:56 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id d65-20020a17090a6f4700b001f303a97b14so2028156pjk.1; Fri, 05 Aug 2022 00:17:56 -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=9WTjcqdDZvIrd9m4Mp2PI6jdF4as7Bk5HjXH3pJQMAY=; b=fcFg+oQ+PIlmNy+t0TMXA2kt/X2BRMRodge2iTGUPLtCdDZk+1dADCiLzsUL4c8yIs LYLedsfiXe2+32JYD7TdCh0RAbch2WOBfPzZ5JeJjLwtnQWnsK5FCjjNltOtLm12F/Hn saJM2NZ9vkkfkhQs7GDEvqbSfARf/3ES+vzFBD6pEuiwuxgsEAgcEGD4y56JXxLWDDyz aQ04vsL0mRqWGSQjsO48rkFpKqQE/3M6tpeq7KdpZBGcereboAmkAyzm9oQ7Xb7okvaE jyfINauOe2xbaODyafnBpho+qxoDSRxh62yS9y8bdj23CpSU5tzw+NJp1rEaK6JEByXL 4FxQ== 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=9WTjcqdDZvIrd9m4Mp2PI6jdF4as7Bk5HjXH3pJQMAY=; b=cRaQfNGoNwmeytZCwfXS2w1t7X63EC/CjCIJjSPnO+N3IlihrDRXXTO7x3Uh2CIJ2L uDC2/esfDfHOKgwee/+ssyBlhUTjeXUd0RFavcbd0iv0biwRLp+15cx+QEHWtmrSiwpn CHlpEcdbNhl6Bn/0xXq9An+JVe/mfjbfxrbuj3GJCjpGRUn/4nH0xw9PzBx3CDSxSoTA 1NUWxHRcreWEcbgu9RUIDNiyc9Uuc1hiNHXKfCOlWhNEQE+yTo5hrJZ5MsEZWmXtufYh PC+NRdZFQEEaJ6nrQsKaH8FHA2xJFhx/QDZd0fsEaFGZ/eFc3U+Hptx/2zxTauPd0yYV C+wQ== X-Gm-Message-State: ACgBeo01XXSX5Lm6XBpkqFPFkuqDShZmpPqNJtoTotURi4yZgYZhoxd2 dSQoQQFeLSqTkJS0+IP/WtE= X-Google-Smtp-Source: AA6agR6e1MxYjIpLHRvBco9uxv7WzOENqjp+HKFYy1T2n5ptNIfYViK1+IoDoPTKhV6rf078Kjiq4A== X-Received: by 2002:a17:902:6bc2:b0:16d:d2c2:7ff with SMTP id m2-20020a1709026bc200b0016dd2c207ffmr5505944plt.87.1659683875579; Fri, 05 Aug 2022 00:17:55 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:17:55 -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 v4 2/7] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn Date: Fri, 5 Aug 2022 15:17:08 +0800 Message-Id: <20220805071714.150882-3-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Gene Chen replace overwrite whole register with update bits Signed-off-by: Gene Chen Reviewed-by: Guenter Roeck --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index 3291ca4..f2f1fb0 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -5,6 +5,7 @@ * Richtek RT1711H Type-C Chip Driver */ +#include #include #include #include @@ -23,6 +24,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 +111,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 Fri Aug 5 07:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595635 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 755A8C00140 for ; Fri, 5 Aug 2022 07:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240391AbiHEHSK (ORCPT ); Fri, 5 Aug 2022 03:18:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236316AbiHEHSA (ORCPT ); Fri, 5 Aug 2022 03:18:00 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A9F06FA1C; Fri, 5 Aug 2022 00:18:00 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d20so1537131pfq.5; Fri, 05 Aug 2022 00:18:00 -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=wmQvfTLfhSexD9Eu2cDWkazSz8+Yx4MBahcS3Xy6S+Q=; b=JAKhImu3eGgYN6HOXihH6/c/bb7lHbLwfwWYgYh2T2VvoDNj38ySz6uhHOsANgpOFW Lsy4TpYGhYt6fsf0YKfDri6YKemLuJHJi7JnrFvFI/9M/4T3v25ZZ549CvfKevXodLlp kv33BT1SjRym9itPtEpxvmm94mafo88v9Wg2jqBS9DQNy7AUDZ1vzkzXp8WqWaNpo5Ia Y7z83FcVY+EPsastjdJB4abRaD//aEHTOW6ieAJsZQm85C3EnpTgvYW5dOUk0qeX2Zan eFAiJFVjhica/8UnZpINZNMrLkUHBerjdIuIYJRlM3yxcJPY18V8CkmKD1uYNveWUMNj NKLQ== 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=wmQvfTLfhSexD9Eu2cDWkazSz8+Yx4MBahcS3Xy6S+Q=; b=YZYvchpID3YPRriIeGXCA8xMxFyaHp54+tS68NWKUIrEViZLNhVeqvXI9HOkW/zNhd gu9V2S2AU5SGRg2Mwwelw1yYj3a3PAcUq+t2x6Z8Pzm9iKzba0YuYDyAypOV2mQd5xIs hjsiocoVxfX4O5Ck/jKFZ+oTG4QoTRbzGzUCDjrdxVJ31Zeb+4/yT8wqD2cyqMt/oDHZ 7j+TDwigO7SLTmcsnwb5NSE9nNNnr3RhXLiBg6MOYSKJXVVNzAIO1bG/pXs4MSHOPPYD wzKyWDDrgXGKmtCDM/RSqboVluelPNVYgMo+azbPM+wBG5CeTxbiDZay1afn/e4pNQqj BwHw== X-Gm-Message-State: ACgBeo32Sy0vKLPyeTQ8MmY6x3Bp7L9LaP4xoAHB33G/qQFIJXPz4FGS mBgEQABoaAfDf4D7Sw7DWCM= X-Google-Smtp-Source: AA6agR7xYlDesKGSE+vAQqDfsv7sf27mKnxcGVl9UmTspDmudfGeeoDRnFGwmIJIBB3tY0+/wIs8+Q== X-Received: by 2002:a05:6a00:b89:b0:52b:2bc7:68ab with SMTP id g9-20020a056a000b8900b0052b2bc768abmr5724112pfj.80.1659683879503; Fri, 05 Aug 2022 00:17:59 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:17:59 -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 v4 3/7] usb: typec: tcpci_rt1711h: Add regulator support when source vbus Date: Fri, 5 Aug 2022 15:17:09 +0800 Message-Id: <20220805071714.150882-4-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 f2f1fb0..fb19d7b 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -14,6 +14,7 @@ #include #include #include +#include #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 @@ -41,6 +42,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) @@ -104,6 +107,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, @@ -247,7 +270,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 Fri Aug 5 07:17:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595889 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 F40BFC00140 for ; Fri, 5 Aug 2022 07:18:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240404AbiHEHS3 (ORCPT ); Fri, 5 Aug 2022 03:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237056AbiHEHSQ (ORCPT ); Fri, 5 Aug 2022 03:18:16 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46F2C74CE2; Fri, 5 Aug 2022 00:18:04 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id m2so1930241pls.4; Fri, 05 Aug 2022 00:18:04 -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=Ujg4hDDvyV4s7RmKQP40QabcGXdYDiqK7t+igL1GTqc=; b=J3uEOywwe0pFzy3VX05gPSwfkeohBApGj2UdiQkUW9SGez1S9KotXjqMCQtGSLBhXo jwzkcQ7oJmNrp3dqjR5niQyO9fPtcza7xUhgCa1sGHGpcVheG2HSIZ73/8rz7AmuHALA AdghWgzxDSBfC4/zwuh8w4MRRj4b1w6MvMsFCBP2DlUKIThYJmJN7Mw/9hStAoOH2Nai kMin8TIIfYQvxyPIvfQbEZoXP+wAoDqCuYsbk0DV5Kd/BeaBZ5fjtR7r3R1Yd72kKBPL QQJp1TfcJHKwktlYvwS9k2TJ5kkFJ80KSM8wWe15QyazCaxn8F4z6cbIeOKcx9fT1/nF T/Tg== 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=Ujg4hDDvyV4s7RmKQP40QabcGXdYDiqK7t+igL1GTqc=; b=5jvltgAmzNySci7ETG5m9gLn9E/t6Fzvs5Quclk5UHgq+H6bGOTOMGxETGG6WLJpDm 5j6DZgXp9Eo8AVEWIgnWorAC75hTbs55ktO9vkomZQKERe3yvHT6OIwpA4bSvKPX4AsZ XEsK1WZrXN74FscqIHoATg5gBoUYH4x5c3xh+lqlMGDfkZNEw38CdoeBPOomiGuUWL/A sFvQsibxPlKOnNnrvJRPrFy1LXgz9av/WqnSCBVaI+n3y3Rcd3P8cJeSoexmmcBQjRUt xb0S8RsFstfrP1HGXCJYIebToNLZYfqqEssIBRyvK/eNV92QZJ6qed1KE2EI9KpSGvlw X6eQ== X-Gm-Message-State: ACgBeo3HH9DNz/jvg5R9e/MDgDw8H3t967B0kPqTMpyb7C/2YPv8iCmN DPQvCvl+v0kIQK00mdM+W74= X-Google-Smtp-Source: AA6agR4R+Q+n5hbfkkc52HAhugGr23JgYwh+VNGWFJkq11ngBHDKLfijymiEX+8FlpqtN8yEN8PxhQ== X-Received: by 2002:a17:90b:b13:b0:1f3:7ab:35b2 with SMTP id bf19-20020a17090b0b1300b001f307ab35b2mr14738615pjb.118.1659683883698; Fri, 05 Aug 2022 00:18:03 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:18:03 -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 v4 4/7] usb: typec: tcpci_rt1711h: Add initial phy setting Date: Fri, 5 Aug 2022 15:17:10 +0800 Message-Id: <20220805071714.150882-5-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Gene Chen Add initial phy setting about phy dicard retry, rx filter deglitch 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 fb19d7b..5c51d04 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -19,6 +19,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 */ @@ -106,8 +109,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 deglitch 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 Fri Aug 5 07:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595634 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 80927C00140 for ; Fri, 5 Aug 2022 07:18:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240483AbiHEHSo (ORCPT ); Fri, 5 Aug 2022 03:18:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235498AbiHEHSX (ORCPT ); Fri, 5 Aug 2022 03:18:23 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DB2B74DFF; Fri, 5 Aug 2022 00:18:08 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id s5-20020a17090a13c500b001f4da9ffe5fso7462707pjf.5; Fri, 05 Aug 2022 00:18:08 -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=dEVGEWigHsjLc/9KUb1DdWR50Rx5DGz/VoYfslPo05w=; b=qmNnXznenDiFBsdgJDVRWbtNE+WQ+7M53YC9VxiHCqqVSb9yD2AYW9MTxTfaul2x3E 9aUwUfYzKZyAf3VzYj3sfXZnA+wGxyoJWL78hnZfwNfgSVhwN+GXLVvQQAVaAyBC/P1b O75sgbcTWntlPiNt06BxkH8SWxrPM+6t1w4xsdKRIfSsTFj+fEFKGF3ppM5JntSVWDpD 6gatcDSJFdjjn3eCmB5D2lC0brxOCXq6NqHpT639JY4pUUdoflY72i+SqxBwwckTGb0s R1GL0MqtP9s0b6QQBLJRSPZh0KMc6NW5W28MkaTgOBrNbPGEyKLJTWfX128v44V0xOAO OQUA== 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=dEVGEWigHsjLc/9KUb1DdWR50Rx5DGz/VoYfslPo05w=; b=RSNuk6V56tkCyAk0l85nYejipV1mGpOfmsQRuA7x4RGDSQAoPQ9lE/plIv6O8HzNMq w4KwgHl9Rt4VPGqrUx4Dfh616F/4r13lGiVoOIe+jWZdMLZO2ScxdSRZmEPI6J0cgaJN GOfuNDu/L3ce97VHErYeYfAlpO+4DOvFrFw+o+U4uJpd1QMgUKJESgU2+N0wKEUj1j46 Yf9IrL0lsC/uuYrPB38Hm30b0nd98qiYOh2ypAWzXx8bXe2i0UoOFin30QwYVZaFG4jA 9sONxvIRorn+M7JVugRAzVmOsUdZg0SNH7Gye+TOUa1PQ7hejXGUie/qo5XxYlgCug+o kw1g== X-Gm-Message-State: ACgBeo1p9f5lt3Cuz4cZhkFtrbm4oeZ6EzMudNez6mzRxTO3yFxo1xoi JZyCgtb3b0bWQZrii1bwPeY= X-Google-Smtp-Source: AA6agR5w1kRyMmJe2RLaIkObkC5qWpAjhhuaR8cKPGGqF+Wd9GpK1ZuiWFj3nNJwPCv1iAwgQOJ4mw== X-Received: by 2002:a17:90a:1b8e:b0:1f3:7c7:9c3 with SMTP id w14-20020a17090a1b8e00b001f307c709c3mr14660124pjc.8.1659683887706; Fri, 05 Aug 2022 00:18:07 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:18:07 -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 v4 5/7] usb: typec: tcpci_rt1711h: Add compatible id with rt1715 Date: Fri, 5 Aug 2022 15:17:11 +0800 Message-Id: <20220805071714.150882-6-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Reviewed-by: Guenter Roeck --- 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 5c51d04..ff7deae 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -18,6 +18,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 @@ -29,6 +31,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 @@ -47,6 +50,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) @@ -83,8 +87,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, @@ -92,6 +97,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)); @@ -229,7 +242,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; @@ -247,7 +260,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, @@ -256,16 +277,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)) @@ -316,13 +339,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 Fri Aug 5 07:17:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595888 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 4DA21C00140 for ; Fri, 5 Aug 2022 07:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237727AbiHEHSs (ORCPT ); Fri, 5 Aug 2022 03:18:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240450AbiHEHSi (ORCPT ); Fri, 5 Aug 2022 03:18:38 -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 B5AA775396; Fri, 5 Aug 2022 00:18:12 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id w14so1905111plp.9; Fri, 05 Aug 2022 00:18:12 -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=Zbgh2rgkAipGuhCwaEdIJ5QN1l75SbejwY6P2FNLcRI=; b=Cz/6Sm8o9QXAi1UDUhJXmuLmUEO+SyQQpke2NROxKqtVltCrCBKcWc+bhtmVqR336W I878a8T0XAjVHqbvRKdWKLb4xWIGGT+SkYiE1NC6X04f31pzksExIsej6B9CCYcEgOws QJi0Bk0vuBQCSB3sLGecm+SjoLjUKB/jgjTQ/Na1IOlQUacTQ1QpME0bddO/9qgIby68 Nd3kypS+2TGAUMpt3XuHkiLHG7R4ryoy4hY+uQP+o8pAktjRLHb5tUwOa6Y1OPHwftE2 v227ArLR0nqaJ87toTtV3SftjXgbIZ9M+2rHdtXSSte1w99vI9bze5gj8vpaX1SrgnuW S8bA== 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=Zbgh2rgkAipGuhCwaEdIJ5QN1l75SbejwY6P2FNLcRI=; b=YnAMp+pGt+e1uyq4LwPjLAf5YxWM1Z+qHE6o9HQsGXK4j6B4xL8s7VD+iv/EQdThtM /5sVqh+uhEdanr2iv12lvOahd31Ys0d35DkbSAQN/naPd+JR8jiCL9APl2NxVRyIrRKq m274Xrvlhy+2Br5o9f3sVNv8GIXdKVEUeERd+U72kwNmemJarapg2TV5sGUkiJUwh5OE JKLQTFGUg8FJQZRgsWQy6nv+ENtNHvw2hGl9RXNDIl33AdQe94frtRN4M9Xnv3X6pNf6 3CbA/mnjj301XPBAWx341vS2PMt1p01sM4jyG91sNh1Y66lteYEsiz7o9m44WyR2WLzl zpBA== X-Gm-Message-State: ACgBeo07mtNRz4Spf9nZ9caUFG3tHrp/sBLBK/s4cZAc+ZlGwWgCAVFm UOuaEAmatU0KZqTay9iGX2Q= X-Google-Smtp-Source: AA6agR5biHhF/rWe8KEFpxANXG5AOxXtNntHsmoSVPpqYj4LvoiSr16ElVesJP7lj+tnp//FIYMhIw== X-Received: by 2002:a17:90a:c690:b0:1f5:858e:f538 with SMTP id n16-20020a17090ac69000b001f5858ef538mr2556673pjt.10.1659683891719; Fri, 05 Aug 2022 00:18:11 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:18:11 -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 v4 6/7] usb: typec: tcpci: Move function "tcpci_to_typec_cc" to common Date: Fri, 5 Aug 2022 15:17:12 +0800 Message-Id: <20220805071714.150882-7-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Gene Chen Move transition function "tcpci_to_typec_cc" to common header Signed-off-by: Gene Chen Acked-by: Heikki Krogerus --- drivers/usb/typec/tcpm/tcpci.c | 22 ---------------------- include/linux/usb/tcpci.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index 8127847..50674ec 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -27,11 +27,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; @@ -218,23 +213,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/include/linux/usb/tcpci.h b/include/linux/usb/tcpci.h index 20c0bed..1765745 100644 --- a/include/linux/usb/tcpci.h +++ b/include/linux/usb/tcpci.h @@ -167,6 +167,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; /* @@ -207,4 +212,21 @@ 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 Fri Aug 5 07:17:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 595633 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 6B11BC00140 for ; Fri, 5 Aug 2022 07:19:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240466AbiHEHTD (ORCPT ); Fri, 5 Aug 2022 03:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240376AbiHEHSj (ORCPT ); Fri, 5 Aug 2022 03:18:39 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E246A74DEB; Fri, 5 Aug 2022 00:18:15 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id g12so1541812pfb.3; Fri, 05 Aug 2022 00:18:15 -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=fdJjDYFxYS68E9ZUvuM71CJZvMzbAXojm0SHTDHnZVE=; b=M3EQBeTYuIoV/C+5aXlU6ck4Rp/nhgyHrBFT4nyoKJpeGmGV/3BnSE+U8efjyBwvRh xSeToo/qe1lbMQvTxoG8trK9RwJZVy7aLGKsmC1m+03T/N8/YocjMURbDvc8SAbnUbUe Q6NG0tRwQ0u+AL0Vf059aCqTmZAzsjUxHO2DUZqz3t14qXefAgpTUmZFWJPvh5EbsBYO weEHeVxNYsUvilfQb2tQgU1rv8CAdFPgbOCmV2MeXV4Ir3nz7FikZPWUacR/bpF6zDXV NmG2nE9sfC3j9jVk/7cCGxUb9/sKPZrrApFa2MWI9tG2ktRaKLOoUvgtU6AnTVC+srcL hynQ== 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=fdJjDYFxYS68E9ZUvuM71CJZvMzbAXojm0SHTDHnZVE=; b=zO4YJyXhHEIAn4+yFmkfCw/X62wrD30qrUfjc2YvrqeznbkCM9uhIJRVpGbq5j8Tj5 2g7bCXitp3L02sfTWjHVZlXUUHeSrqK5uSDXZvNi/JQPQCZLdM8FYrh9Bylegy3+2a6n XuepxpCWfnRdl1SLiHQP6ddb9Zi+rZnMIDZuiPvLrX2euto/G6rWxdgB1Sk28B7Wg5dv R2mgfwG6Uq2bXbyZbLKBTYlNFRvsDHd77vzeoGLby2WmALziei68X2Rzzx/DI8EppjBZ 89mqLexAu5gFnXY0ub7EsWbLelzea2NYKCuWLi0VitD6ONIyB6WMvSB6zZ8M/WO51rDi fOzg== X-Gm-Message-State: ACgBeo0UGMZ079zldl+RqUcl8tbyVN5YCKcv9kJWYFVO138X3ZW96GpJ Y6VM9/jK35NC9p3Ck1xNDsU= X-Google-Smtp-Source: AA6agR4R+qMqVIYB7Z74fLjIVNabHS1FWajL6pXrjCuEVY7QZGtf2FlklqvJkHAnccpqIcZEjxzXzQ== X-Received: by 2002:a65:46c1:0:b0:41a:f5f9:b878 with SMTP id n1-20020a6546c1000000b0041af5f9b878mr4724374pgr.497.1659683895201; Fri, 05 Aug 2022 00:18:15 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:579:6a6f:254a:2074:501f:264b]) by smtp.gmail.com with ESMTPSA id z23-20020aa79597000000b00528c066678csm2226147pfj.72.2022.08.05.00.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 00:18:14 -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 v4 7/7] usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level Date: Fri, 5 Aug 2022 15:17:13 +0800 Message-Id: <20220805071714.150882-8-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220805071714.150882-1-gene.chen.richtek@gmail.com> References: <20220805071714.150882-1-gene.chen.richtek@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Reviewed-by: Guenter Roeck --- 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 ff7deae..5dc34f9 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -24,8 +24,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) | \ @@ -44,6 +47,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; @@ -164,6 +171,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) @@ -224,6 +278,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: