From patchwork Thu Jul 21 06:11:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 592397 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 C4082C43334 for ; Thu, 21 Jul 2022 06:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231998AbiGUGMA (ORCPT ); Thu, 21 Jul 2022 02:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiGUGLz (ORCPT ); Thu, 21 Jul 2022 02:11:55 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C696270E65; Wed, 20 Jul 2022 23:11:54 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id q43-20020a17090a17ae00b001f1f67e053cso533853pja.4; Wed, 20 Jul 2022 23:11:54 -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=qmTXLgSYfe8i7w6gO6nOarXTiH3i5mk/SE0uP1HtN2c=; b=DsLS6IZYhi/zohzXQDQOxiMx/WmBzMUtQFNI2iCoM1lrbRT9t2zXVw6hF/x7pS0CA4 A0X7H/hqnps45GXVFJrzNA3OMKKkjyc99B8wUL45vZRhJRi3A0eY1MHVdJ1w5pbudSuK rnAf+pmDPVCv5K1vB/10d2s9E2sjp1PbfjwLavUakeGOOaImofCSe+OEpPT1g0Y22Gps 28Zd4j9n4hh5bRYKDW/B32d+1YPfVodmFj+oPAj1vTUO51y5IBDqxXOsxJ34rv+Nq6Ef FeG2DfF3bp7h/cp5RjxNG04y5rmN8sztOLv0no5xUeCokrhubaBD9JjCu3LY+O1yYzBo sDig== 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=qmTXLgSYfe8i7w6gO6nOarXTiH3i5mk/SE0uP1HtN2c=; b=U41N9Z7Yhdor6m07JU4UY2kU8yExTfaAT11L7nXhz0gIxfnznMWkf6fJuG7Iyz/vDb v3y94HJgXy8xE7TNjfllcrYLKei67N0Pg2A4mbCX+Qu4z+sYmZp0KI+Uq2j7f8MPV+/6 n3/4v+rQALr1bkRMiu/rWfxAyIFC/W5G5A7sPFwCsjE6PZSV4DbFFNob0eR6ic99jEg9 wufe9DawAhJOdOAAe8v1eIVNRfchWkCMDwhCLBB9RUZN9QdY/yCbFUgJr6QtxYyoXFXp zGQdhuluT5hYVMul1aZO7VlxDevl1S0F4/zcJCD0BDBQqoJLL0GJlCAUXRYoXzD4mdrx ZdLw== X-Gm-Message-State: AJIora//ii3yw3Hu4sMdqS5+XwPPm469I45JGnNsmqO1mv2FQsC+EZYV aPah3w3zuO3aa/CCo4Uol6E= X-Google-Smtp-Source: AGRyM1sN4636z4jnPwe/yE4JQWpojZ5lFQ02VWdbDJUpn3Z77XJknm8Hxm8UFDgBFDUcVv9mmKD4KA== X-Received: by 2002:a17:90b:3b8d:b0:1f0:22f1:27d8 with SMTP id pc13-20020a17090b3b8d00b001f022f127d8mr9701266pjb.56.1658383914036; Wed, 20 Jul 2022 23:11:54 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.11.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:11:53 -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 v2 1/6] dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H Date: Thu, 21 Jul 2022 14:11:39 +0800 Message-Id: <20220721061144.35139-2-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 Thu Jul 21 06:11:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 593264 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 DB6E7CCA489 for ; Thu, 21 Jul 2022 06:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232020AbiGUGMC (ORCPT ); Thu, 21 Jul 2022 02:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231975AbiGUGMA (ORCPT ); Thu, 21 Jul 2022 02:12:00 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6F3C7AB1E; Wed, 20 Jul 2022 23:11:57 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d7so872257plr.9; Wed, 20 Jul 2022 23:11:57 -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=/6bklssnojwIUB7PlTKbvwW+7Fz0WRmqD7QIsHQizsM=; b=ib98ZEbOYYyXc+kUyu2sZl/lRw2L/UFUUHjFtpXOAsUSWK7RJMhQkdhIF6vlWKlXXP Hk2hE2E66KZ8qltGVGGbdSAr3xTotyYsbs7h0KDMnO8kxyqZdUk9RmpaYuAv1XBVsC2h 85zQNQMvMmuhouxM4CHvomwkvtqThxdlkwKsfJxAf67jmZU4h7rDO5jubX8E1TtnHg/x YzEME3jFhL3R431l8xZGjKOnC4M0lOLJhHaFBbxK+FTaa4TneCGsBuXJsJMv7oCmI459 pMSlY9wKyTwUbXxDZhBVq6Hllgng3incY0GiW/JWLhy012EMhpgMxQPqxlhgKkrVIYa+ 2KRA== 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=/6bklssnojwIUB7PlTKbvwW+7Fz0WRmqD7QIsHQizsM=; b=A3i7d7AVjLK+ph5V2gXuxvY6KonBhKXWBH7kRPQgg3pnM2wmfurs1N1yJMEZbpa7zz 7k4pvFinoGFf0Fj7gy0dojGPMxC8b7nE3yQrO4WYNLG8bEwr868IO/hPoUjQtrFFaRX7 YMDWKDQ47w3jk20ab38yDnHZ4N+2XgBL2Mqfythbn7PboxjxR5375dhxitfjleIQJmRX 6wHF3def+LJVtYh+yylTpUjO9R+1njSw9qao5sNjP1dP4QdA00r0g/I6FLdfF1hfyvwJ SMujhlYd/prKEK/b5coZn9pq8czaCuQey35q/OwzVbX7vWnuszSpglMY2s4BK0Rhb6OG PEZA== X-Gm-Message-State: AJIora8ZJcruuUwzJvQvuVfNtJL9WM93Cc/3cO31udpPpyIq6HgLjofi UBayfpdhA/UcNY7xsRToQ24= X-Google-Smtp-Source: AGRyM1vOwVfAeQWrdhF6r2NPxaGqAYCsBD4WQRI5rFhY7+qBvGRSTmv/++MJTDNBwz7xSKg422XF4A== X-Received: by 2002:a17:902:f544:b0:16c:5119:d4b6 with SMTP id h4-20020a170902f54400b0016c5119d4b6mr41796103plf.28.1658383917124; Wed, 20 Jul 2022 23:11:57 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:11:56 -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 v2 2/6] usb: typec: tcpci_rt1711h: Fix vendor setting when set vconn Date: Thu, 21 Jul 2022 14:11:40 +0800 Message-Id: <20220721061144.35139-3-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index b56a0880a044..3309ceace2b2 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -23,6 +23,7 @@ #define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \ (((ck300) << 7) | ((ship_off) << 5) | \ ((auto_idle) << 3) | ((tout) & 0x07)) +#define RT1711H_AUTOIDLEEN_MASK BIT(3) #define RT1711H_RTCTRL11 0x9E @@ -109,8 +110,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_MASK, enable ? 0 : 0xFF); } static int rt1711h_start_drp_toggling(struct tcpci *tcpci, From patchwork Thu Jul 21 06:11: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: 592396 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 384EFCCA479 for ; Thu, 21 Jul 2022 06:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbiGUGMD (ORCPT ); Thu, 21 Jul 2022 02:12:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbiGUGMC (ORCPT ); Thu, 21 Jul 2022 02:12:02 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18A207859F; Wed, 20 Jul 2022 23:12:00 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id bf13so722921pgb.11; Wed, 20 Jul 2022 23:12: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=6sF8VJbpidhbdsrvIAVkvPjdZOS37WXf+C4sKxMlkj4=; b=MlZBc9WnBM1JQcT/JZtcUavjwfHgEnHx2myTDkl3q84VKT/Ztb1PeXIyZEBArzd2qU 6Agxh/SqYh2PS8GgX7AQDopKsI6c+FglP3J6u9xD0SwpEWCfz0hdHNJfGF672dcVYMRb Y7DpCu0ixooie8cY55HeVNIu2JqR3uz3qHm/RY+GU4twmjlLfJtbTwrNRmGNS13uIXR7 fOgOoVMkM2XfRCv8nn8dHpPM6FxjcCRJadAL10Q9pKXsXQcd0w1OUpjTQxiL/AalJT44 jEPqbRQ9dILkluIDFDR/mCzaTyNpIhXwU9rLzKG9cu+vm0fAptg/1Rv+hDANwT5vA9MR 52VQ== 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=6sF8VJbpidhbdsrvIAVkvPjdZOS37WXf+C4sKxMlkj4=; b=HfABtk79INbUllH9dDN0x3GIIlJlOl1oPY+NH7IyIXTn1pey2WB1cdtILbn2yMJub2 u7XyMa6zwYcphV/UU8hIi1ma1mUKEJcR/cFYcCRHgzHX8jTibv0mApAZaEx8FvMy7BWe +Tw1QT4J5lH+RRsv4pOunNAzVenuMU7KBlXXVHqDLHLElzG9zmEkL5zNoR1OPCAkraAU AWElp85c4LZDElNxh9RWpug+q85ADGVGlah579mZBkjqw3Fmnwel3YxmZOFjJ7YdFRU5 ANPADbNo9/mbBNZInYcS7nFCriC61a8iRGwGXk+D1cvXiqJztC1gQn874XA6DiDGq3zm LVSA== X-Gm-Message-State: AJIora8J8f8dhwxUd6Tbc5gb1jzwTPV+Qw9bhTrR1Qb495Ds7jO0qnRN NPjpQBLaoqCiXTlp/6VCRXg= X-Google-Smtp-Source: AGRyM1vcjYkOvrCXzM8VN+s2Q5kugMc1hPNGKeopAgUbzjuVJvXngm/Gc84CM47+fHTD295B4/tv1g== X-Received: by 2002:a65:6151:0:b0:412:e419:d651 with SMTP id o17-20020a656151000000b00412e419d651mr37227145pgv.378.1658383919592; Wed, 20 Jul 2022 23:11:59 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:11: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 v2 3/6] usb: typec: tcpci_rt1711h: Add regulator support when source vbus Date: Thu, 21 Jul 2022 14:11:41 +0800 Message-Id: <20220721061144.35139-4-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 --- 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 3309ceace2b2..52c9594e531d 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include "tcpci.h" @@ -40,6 +41,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) @@ -103,6 +106,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 1; + + if (src) + ret = regulator_enable(chip->vbus); + else + ret = regulator_disable(chip->vbus); + + if (!ret) + chip->src_en = src; + return ret ? ret : 1; } static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, @@ -246,7 +269,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 Thu Jul 21 06:11: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: 593263 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 EE995CCA479 for ; Thu, 21 Jul 2022 06:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232087AbiGUGMQ (ORCPT ); Thu, 21 Jul 2022 02:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232083AbiGUGMN (ORCPT ); Thu, 21 Jul 2022 02:12:13 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3219C7AB34; Wed, 20 Jul 2022 23:12:03 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id r24so895870plg.3; Wed, 20 Jul 2022 23:12:02 -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=2pwyKcg194H4QO3VdCUZ/f9cmXrK4hIaWcesJcv68aM=; b=MrlMZr9GI2jwKVd1keTJceu9SVOCG/RKmLX/D7nIZVlR+o3ltwcLTG2Wep2pT1L46v KpdFZCiQs4mBgYemwI7TD46X0dr05pFyINJa4qy9uECHixk477NUnIg+49kuHKYbM95K J+pkfkC2LyRxdtgOwOWPumXEBhDiIcZL1cmWQ8S3MzBjcBDh3FJUkbVQdIM3kzs7r1sf xPeaIcCqGi2O7vfmpkK9stJCLw/bkcyGQ+JXcx1EKBWkAa18mjLgNMrtKceNVEEKVekD CGWiCyd0Q0wYRXKxfLFNC1cf7Y09Bif5qeSrCfe/eluG0Mta1vmRGFxhLQbv4rwR6ZMT BhVg== 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=2pwyKcg194H4QO3VdCUZ/f9cmXrK4hIaWcesJcv68aM=; b=zfW6IX7vXOKD2zwpJCQlNRA2ZHJ6J6RcZXUQSYqPzSFMoofO3Hsx53GnFMEBV0b6TL b0EEr8repgoC7ynhXnx/OVGGVKLcLSC/lCJBtGG4aQoDIME5r/jwyRhaB0o5zgQGExX8 wOtYtPgeQURcj/9Z1IPnkfG5o0a4CYdNsAJbTUQVsvB/kZxnpyfpYxGHG4FXLuY7Dzl5 IljbgZnUBkI5eXTRRks3gJE2DltXqRVF27mG0696ZJ6La9KFanG8Rvm3Aq8A7FSgMkv6 EQVPgw3FF5P7ek/zsMMbTFJgb7bso49L2klQPWyU16+O6zjfCZE3rXMY3HRjCfW2xi+R WdpQ== X-Gm-Message-State: AJIora+DOsKcoFj7HiQqbxpsKBq5Wl0I2JCrtMfGGW0f9a04PAqi8xIi 086Tk/wQKCAdyD2hsnvVQMIaCDeDEQg= X-Google-Smtp-Source: AGRyM1sVMzEvjBoulO9EZjW5+s+Wrx6ov32xfiZ9FJHhylrB35dhzLunOd7fGkdE0HVfDPFHblbDew== X-Received: by 2002:a17:902:a38e:b0:16d:a30:8a4a with SMTP id x14-20020a170902a38e00b0016d0a308a4amr13060012pla.42.1658383922247; Wed, 20 Jul 2022 23:12:02 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:12:01 -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 v2 4/6] usb: typec: tcpci_rt1711h: Add initial phy setting Date: Thu, 21 Jul 2022 14:11:42 +0800 Message-Id: <20220721061144.35139-5-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 --- 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 52c9594e531d..e65b568959e9 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -18,6 +18,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 */ @@ -105,8 +108,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 Thu Jul 21 06:11: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: 592395 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 E4A6CCCA479 for ; Thu, 21 Jul 2022 06:12:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232068AbiGUGMS (ORCPT ); Thu, 21 Jul 2022 02:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbiGUGMO (ORCPT ); Thu, 21 Jul 2022 02:12:14 -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 26D707AB01; Wed, 20 Jul 2022 23:12:06 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id q5so866713plr.11; Wed, 20 Jul 2022 23:12:05 -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=drWqUOesH6j18Q/j83y/2/spkHUtKTZKcE3ccf/wsyY=; b=OF6zWbm4Yk1jFhUIpiM6u6FMgIcfvoAsgZ6ovnfazRt4IDeG8O2MAFq16hcKC3Ij/r vBsXypbpnuPnpk/Bun9fpoit5cCJGo7iYox5P/V/+ElkOxw7Ep8z51AlhYdtZOhnCb7A G9xhkfE1I2wzot1K/fL+DPGtW0uj1os0NJlhS3dOgdUB79sxXtD5wPx31ekref58p5Uo V8YonP49bKQ4s67ByTR7RliAhSXCwqZ2ND8S5qreHBn8UBDIN7fWmZvedj1EUHNB/6TH ijZFzBUwmbeMQt6UdIGIt07L68vrn9bhQ3eU8wnqh/MouzAAV6Q7dWAexiVpeQVzuywD bL7g== 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=drWqUOesH6j18Q/j83y/2/spkHUtKTZKcE3ccf/wsyY=; b=L+SxNJAdGprS8g0q3Cypd3G79ZWWqaT45tXVioiiaSA5i4qgM+kBvFunBja+2KQk9E OYggOCEnljC30RFLvP4vej6XocKEwdoUDP8Hci6HBA73NBwLT0l7F6NsNUuehWBwb/m2 8++P4n32U6RdunTag95MOIu4JfiUss/Hev2SiqeRY5bBZf4PHCwCWDOpHWRsV5dgAwgE IUWXahIkw9FM5xlDDjtjo6yJay1Z8RJIslD32EDXdivE7KlAj/jgalhhWeTYZdqvFfUb hDFYM3lI/pvpULHJc55VN59Sx9LCx6WpFi3tIFM43DIaA5nARJ9yzoTfiUlKRj5fdKvE uKsA== X-Gm-Message-State: AJIora+mahezO5BCaZtUrLDs2hgmtP2CGxPn26HfZTsOBSGeMKszVlQe XxBUJgF6O3W07v3PA1d5NaI= X-Google-Smtp-Source: AGRyM1v6AWHC+c6EDZFxv0ZMJMj6Ku5xpBIgbe0Tf9/iw7e7ksxiE+Zyu07dZT/Nltm/wg9ZhFX6nQ== X-Received: by 2002:a17:90b:1d8a:b0:1f0:419f:66b1 with SMTP id pf10-20020a17090b1d8a00b001f0419f66b1mr9805074pjb.119.1658383925293; Wed, 20 Jul 2022 23:12:05 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.12.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:12:05 -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 v2 5/6] usb: typec: tcpci_rt1711h: Add compatible id with rt1715 Date: Thu, 21 Jul 2022 14:11:43 +0800 Message-Id: <20220721061144.35139-6-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index e65b568959e9..3316dfaeee0d 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -17,6 +17,7 @@ #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 +#define RT1715_DID 0x2173 #define RT1711H_PHYCTRL1 0x80 #define RT1711H_PHYCTRL2 0x81 @@ -28,6 +29,7 @@ (((ck300) << 7) | ((ship_off) << 5) | \ ((auto_idle) << 3) | ((tout) & 0x07)) #define RT1711H_AUTOIDLEEN_MASK BIT(3) +#define RT1711H_ENEXTMSG_MASK BIT(4) #define RT1711H_RTCTRL11 0x9E @@ -46,6 +48,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) @@ -82,8 +85,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, @@ -91,6 +95,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_MASK, 0xFF); + if (ret < 0) + return ret; + } + /* I2C reset : (val + 1) * 12.5ms */ ret = rt1711h_write8(chip, RT1711H_RTCTRL11, RT1711H_RTCTRL11_SET(1, 0x0F)); @@ -246,7 +258,11 @@ 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; + dev_info(&i2c->dev, "did is 0x%04x\n", ret); + return ret; } static int rt1711h_probe(struct i2c_client *client, @@ -265,6 +281,8 @@ static int rt1711h_probe(struct i2c_client *client, if (!chip) return -ENOMEM; + chip->did = ret; + chip->data.regmap = devm_regmap_init_i2c(client, &rt1711h_regmap_config); if (IS_ERR(chip->data.regmap)) @@ -315,6 +333,7 @@ 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); @@ -322,6 +341,7 @@ MODULE_DEVICE_TABLE(i2c, rt1711h_id); #ifdef CONFIG_OF static const struct of_device_id rt1711h_of_match[] = { { .compatible = "richtek,rt1711h", }, + { .compatible = "richtek,rt1715", }, {}, }; MODULE_DEVICE_TABLE(of, rt1711h_of_match); From patchwork Thu Jul 21 06:11: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: 593262 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 0EEEBC43334 for ; Thu, 21 Jul 2022 06:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232169AbiGUGMU (ORCPT ); Thu, 21 Jul 2022 02:12:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbiGUGMP (ORCPT ); Thu, 21 Jul 2022 02:12:15 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79547B368; Wed, 20 Jul 2022 23:12:08 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id l124so844338pfl.8; Wed, 20 Jul 2022 23:12: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=8hzEOaxWyXcgWSZbVbpmgwfVNJAPnS8A7yGnafWxV6w=; b=ZtIshzHxy4tiyIn3KVe9cqqVXS6JR2xz+WNqNDM/cVO/QFKiqAbE2iTmRAYbIO2xt9 DsfRuavLBDufzR/cSBidtfg9LHZT6Z+SHB2FC5I67zeUUTE4f8MvZsRzmjDSrs3J8xdt sFwlepI7y9Y5HwCzz59CjJrYD21KM5/A1aI7pnWR9cTSVKSTT2sEStIj8xXCZQ9Ghk7l KTjoLWd/N8Ul/WNJBKUD/EQVDPQW/vUQLFjjuSgXW9GgZgRgysaNInHDPfWQcaPxg0Tr qzLXT7HPQpfyuEzchRQVZPrmFTtFn8uLMNlPPc9jWnnAQ+CI2pNle6sCzU/G+7sD7xld t9ww== 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=8hzEOaxWyXcgWSZbVbpmgwfVNJAPnS8A7yGnafWxV6w=; b=ffM4byYxSPG3s1TNdf4DLf4nDiVRHXimNjQBYJcT0srJ21H3o5SzDU5TgC4hb7OAZs ahJ+NEzrGzglucaj03gFAWydUZX4fkJzwkg08UDxTEAdzlN0n+Eo1mS80PMREUE0vAsM S/f6h7UpSO9Sj/J1FIBIe/yQ5t0opSARA64f2q4adP1hoAn4RmFTgViFEvdtWKdLtlFh L8j/59EPGw2LgYM9woZGRO5wiNvcqIMi0F74kMazqtQ1JM4yLW2BvzaCCu8ZZqKSlTU7 1mmN279y6KWzn/LdOq01yfvF1JMI1ukpfwkyeae2Z5jJW79+5UaeQTAu09m5PsfiUPfe kn3g== X-Gm-Message-State: AJIora/PuEqOZVTajg6HmiG4RrdTqCeAfXM+NfTl7lmffVUZYgRL8u1S Ipk9qvnSFSKf1MphHCXK52o= X-Google-Smtp-Source: AGRyM1sO5bBbid2lrf5WMRi/9TD8OOKKc2UByghI8Jd45LDLjGvqJv/Bms8BApu2wAfyBb2f88cJvA== X-Received: by 2002:a05:6a00:428e:b0:52b:7e40:56cf with SMTP id bx14-20020a056a00428e00b0052b7e4056cfmr15842729pfb.72.1658383928073; Wed, 20 Jul 2022 23:12:08 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:46a:8b75:f825:a44d:6d0d:6d6e]) by smtp.gmail.com with ESMTPSA id 13-20020a62170d000000b0052ba782f4cbsm744998pfx.7.2022.07.20.23.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 23:12: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 v2 6/6] usb: typec: tcpci_rt1711h: Fix CC PHY noise filter of voltage level Date: Thu, 21 Jul 2022 14:11:44 +0800 Message-Id: <20220721061144.35139-7-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220721061144.35139-1-gene.chen.richtek@gmail.com> References: <20220721061144.35139-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 --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 83 +++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index 3316dfaeee0d..f0c46bf7f00b 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -22,8 +22,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) | \ @@ -32,7 +35,6 @@ #define RT1711H_ENEXTMSG_MASK BIT(4) #define RT1711H_RTCTRL11 0x9E - /* I2C timeout = (tout + 1) * 12.5ms */ #define RT1711H_RTCTRL11_SET(en, tout) \ (((en) << 7) | ((tout) & 0x0F)) @@ -42,6 +44,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_MASK BIT(0) + struct rt1711h_chip { struct tcpci_data data; struct tcpci *tcpci; @@ -162,6 +168,77 @@ static int rt1711h_set_vconn(struct tcpci *tcpci, struct tcpci_data *tdata, RT1711H_AUTOIDLEEN_MASK, enable ? 0 : 0xFF); } +#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))) + +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; + } +} + +/* + * Selects the CC PHY noise filter voltage level according to the current + * CC voltage level. + * + * @param cc_level The CC voltage level for the port's current role + * @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 = 0, rxdz_sel = 0; + + 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)) { + if (chip->did == RT1715_DID) { + rxdz_en = 1; + rxdz_sel = 1; + } else { + rxdz_en = 1; + rxdz_sel = 0; + } + } else { + rxdz_en = 0; + rxdz_sel = 1; + } + + ret = regmap_update_bits(chip->data.regmap, RT1711H_RTCTRL18, + BMCIO_RXDZEN_MASK, 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) @@ -222,6 +299,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: