From patchwork Fri Jul 15 10:04:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 12918965 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 3B2C7CCA480 for ; Fri, 15 Jul 2022 10:04:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbiGOKEf (ORCPT ); Fri, 15 Jul 2022 06:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232366AbiGOKEd (ORCPT ); Fri, 15 Jul 2022 06:04:33 -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 6940420BEC; Fri, 15 Jul 2022 03:04:32 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id x21so2825298plb.3; Fri, 15 Jul 2022 03:04:32 -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+IFkwURZ9TzI4d4nsyuIECKELcBe+Ufdc+HAFumbKk=; b=eWBrxVJdIdl4Mm1ckW/tC6XW1WSGRVUJyH0w6bWcKioK0c27Jst1K7eIhYYzm0JyeF CkZct692RTUtWFV7fYyCHzUJVJKVZ8+DWx8HO2xLts+/Ce8WjIks0bTYbPg2uyJ0iZR/ 1vYpGeNz6trP1Waf7nKr3LC8gGTSzghwktpeScv2xBbLnTvxucoXPS+6WzR14MMhdYXs 3SYirghPZmZtBaGf6bat6Z88AQynnyaXyT3UDYH8QYkJCD7q0PA2kweFXY24YHs3AMTY iBJIaiI9J4pz9X/xNpbLeQMhB/2OvmfkVD5dTXSUqSQaeIE2j6aVpn9GPOSwEVL0Ilra DQiw== 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+IFkwURZ9TzI4d4nsyuIECKELcBe+Ufdc+HAFumbKk=; b=Xz3JvjONuT0xBzDhkYbx7TiaNQnF7mwn6HIvk7DzcMjoMaLh2pf9ihTbazArdvJ4V3 wDeiAWaw94/V8aw3hiwKk8fL9+Gs2LJYcB67qp8xcDAASLzmwRHbcpdobcV2z6OJpfbY ZIm6V6N0/jgxpZIXKbMk0X8i+sWTls+VVL2SZUs2g6bfi2Tz834mhUaNVIqarQfysqIj E/KLBhxTdWQZkj5FIscsb0PeJbi+p6uZyOI2ioI6Tv1K0VV/sL6qLt9KpbndXxvPmbUQ IEIYpcM3SHwxFuDp0QqXMf6NDWh+G8c1zaaK5Mmbh7D+a3i7uxSC+SuHvsxG1ub91+AR YvTw== X-Gm-Message-State: AJIora8BVFSB3YN2wXmHIUs3gU18jKa+azsX0IWdGUDtqo3YvnsYzrue 8chcY7bykx+zrbE6J3aZX7sQzDzIjeM= X-Google-Smtp-Source: AGRyM1tnIGku2iwT1sqcON7jJXF1MGuTORPoOmAE7LlfdSRjXs4AODN4DJlbjJbq90U1Gkipmrftcw== X-Received: by 2002:a17:903:22d0:b0:16b:f798:1cff with SMTP id y16-20020a17090322d000b0016bf7981cffmr12718103plg.23.1657879471883; Fri, 15 Jul 2022 03:04:31 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:569:4518:3851:6d9:846d:fbd1]) by smtp.gmail.com with ESMTPSA id v12-20020a1709028d8c00b0016c1948ef7esm3033791plo.296.2022.07.15.03.04.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 03:04:31 -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 1/3] dt-bindings usb: typec: rt1711h: Add binding for Richtek RT1711H Date: Fri, 15 Jul 2022 18:04:16 +0800 Message-Id: <20220715100418.155011-2-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715100418.155011-1-gene.chen.richtek@gmail.com> References: <20220715100418.155011-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 --- .../bindings/usb/richtek,rt1711h.yaml | 96 +++++++++++++++++++ 1 file changed, 96 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..b6daca71429b --- /dev/null +++ b/Documentation/devicetree/bindings/usb/richtek,rt1711h.yaml @@ -0,0 +1,96 @@ +# 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 DT bindings + +maintainers: + - Gene Chen + +description: | + - Richtek RT1711H TypeC PD Controller. + +properties: + compatible: + oneOf: + - enum: + - richtek,rt1711h + - richtek,rt1715 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + wakeup-source: + description: enable IRQ remote wakeup, see power/wakeup-source.txt + type: boolean + + connector: + type: object + $ref: ../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 Jul 15 10:04:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 12918966 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 009D8C433EF for ; Fri, 15 Jul 2022 10:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232755AbiGOKEm (ORCPT ); Fri, 15 Jul 2022 06:04:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232684AbiGOKEh (ORCPT ); Fri, 15 Jul 2022 06:04:37 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AE1929837; Fri, 15 Jul 2022 03:04:36 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id v7so4314977pfb.0; Fri, 15 Jul 2022 03:04:36 -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=isy+lqfdGWbdDvwuazChaQNb0abTWcyitW2EDjnWOlI=; b=Q2M7MrRqF6mFSv571FjGLMdC73JlNSuFahX8KuP03e+1J2X+jJCFB78fZUVKId4AFZ LURcLafpCeRXfJBk9/uflAbz/sXgpClSrjaZXz5zZFpi2E/Mnhl4mtbbl+DIZGIuoWiG 3dGrFc75ib2a9NPFjey/XYCwyyKUJNHZyCYyO3ovu4h+s3Av0LOkYF3X9psH2Oclox/i PRDPgZYCljVhW1eKvKJ3/sjFiGGTk0wBMbDymMEI4wrfnnFecrEPlws8vXtjNOlAPH2V EFB4sOHNTmwIPIgTnnoKtbX69y1AOxJmfjzhK/DVP0uEcpMXmXKI/vHaIzHY/lhuq+wY cfJg== 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=isy+lqfdGWbdDvwuazChaQNb0abTWcyitW2EDjnWOlI=; b=zdY3s2doChVY/SEZCQx+Rky12LntcN/psVqY5M5y8sj1bOBaKcNHsZAtdY7/t0h5vL pHyb3VsC3gI6orhcpF3DF/JWzKUWaxd85stvZP4VDGP1RdeksDsHEBOLIhw+L79U0clC Tft4zdUCLsjj7DaW3cZhxTPU5sv+sK72ankM4Oc6XijijsAv5pxnmAsPKlpPgXoFVuAX x0G3rNnpim1TddUKFzfthwYE+MGViZFhA1a5GooPhQkGaQqao9fx9MfwGvnvnN7px/Vb cQntNxFBe66z45ybzgVsNNiGfb/3W5qGjs4xgx5ATs1rWvxJ6GlmHth3fKHUhcZuphwF 8sbA== X-Gm-Message-State: AJIora9LA4rwXINbO6Xyc8Rw0dgA77o/i59sNEwVE+t05WUn8CkLotAG rGpwmMwMSqEitMkhn4kXL3s= X-Google-Smtp-Source: AGRyM1tGkAL8CWV7X9Zma5mjqKMu840RrZuAzMkZdYdpVesc0xZ/Pbg/0AJEzPaGNYJzYp/9/ANAqg== X-Received: by 2002:a05:6a00:8cf:b0:522:93a6:46e9 with SMTP id s15-20020a056a0008cf00b0052293a646e9mr13508450pfu.62.1657879476014; Fri, 15 Jul 2022 03:04:36 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:569:4518:3851:6d9:846d:fbd1]) by smtp.gmail.com with ESMTPSA id v12-20020a1709028d8c00b0016c1948ef7esm3033791plo.296.2022.07.15.03.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 03:04:35 -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 2/3] usb: typec: tcpci: Add get cc tcpci callback Date: Fri, 15 Jul 2022 18:04:17 +0800 Message-Id: <20220715100418.155011-3-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715100418.155011-1-gene.chen.richtek@gmail.com> References: <20220715100418.155011-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 set_vbus tcpci callback for vendor IC workaround. According to different rp level detected, set corresponding rx dead zone threshold in order to decode right pd message. Signed-off-by: Gene Chen --- drivers/usb/typec/tcpm/tcpci.c | 3 +++ drivers/usb/typec/tcpm/tcpci.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c index f33e08eb7670..fc2f6191b7d3 100644 --- a/drivers/usb/typec/tcpm/tcpci.c +++ b/drivers/usb/typec/tcpm/tcpci.c @@ -243,6 +243,9 @@ static int tcpci_get_cc(struct tcpc_dev *tcpc, unsigned int reg, role_control; int ret; + if (tcpci->data->get_cc) + return tcpci->data->get_cc(tcpci, tcpci->data, cc1, cc2); + ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, &role_control); if (ret < 0) return ret; diff --git a/drivers/usb/typec/tcpm/tcpci.h b/drivers/usb/typec/tcpm/tcpci.h index b2edd45f13c6..2cef19e131f8 100644 --- a/drivers/usb/typec/tcpm/tcpci.h +++ b/drivers/usb/typec/tcpm/tcpci.h @@ -190,6 +190,8 @@ struct tcpci_data { unsigned char vbus_vsafe0v:1; int (*init)(struct tcpci *tcpci, struct tcpci_data *data); + int (*get_cc)(struct tcpci *tcpci, struct tcpci_data *data, + enum typec_cc_status *cc1, enum typec_cc_status *cc2); int (*set_vconn)(struct tcpci *tcpci, struct tcpci_data *data, bool enable); int (*start_drp_toggling)(struct tcpci *tcpci, struct tcpci_data *data, From patchwork Fri Jul 15 10:04:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gene Chen X-Patchwork-Id: 12918967 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 2502FC433EF for ; Fri, 15 Jul 2022 10:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbiGOKEp (ORCPT ); Fri, 15 Jul 2022 06:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbiGOKEn (ORCPT ); Fri, 15 Jul 2022 06:04:43 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E5D229837; Fri, 15 Jul 2022 03:04:41 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id x184so4280247pfx.2; Fri, 15 Jul 2022 03:04:41 -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=fo6J+XbkB7jjFutwN0VEI7YAOj/+xVVF5CCYclhdBW8=; b=cpZqSeLeXgdFr2xselYTiiyS8QmVWfuiDmxChj7HxYmgiUfjLE8/1PgSKTdXI2l6AY hDVqVGF8dd9yNNRSx+ar2TvH/V4prpOelnV9VCpx6zeWFGdsf+aYsYw+2Ea4rIHWsSqF tNg9bQagye59J/1AAQy8y0pbU4lyXJH7H+FWPM8uIvg1WjPQNB6zF8MIKhMhNWb8ptvt 7NbqvmrV1pjyRfVFhhd2UArs2lM0Fhw/hFtZ1OlfT3KrTAAajj+LRSF7IpIAxaEA2ZmP QkviGo1oZ6fm4BGxoCSQIQyQYrdMaiTZzSFbQwq2SQ4IisfhWe+izHODLXyFZyWS9Bmv ZDCw== 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=fo6J+XbkB7jjFutwN0VEI7YAOj/+xVVF5CCYclhdBW8=; b=T00zc1G+q5ptnahUDonJzuHFwdVnU6EW+SjsjyO/Bb1ibTeqPIenPqmFXRjxUvdUCt idLr60xqjV8VmJWICL6/WSBLXnrx7HzxkElsxBkY1nZjvb+axnbyEf+NR1N5oCyvcgjm fD4WP2Ctya4VN44vnIEdkQ6rmhBYG92sFBAyIcv29GfLH5ID8CTv+qpd1Lp5+FQ6pezh x0GR9TEQaIWvs+pUbXeEb4w418dWM/kMpyTUDx2Qged1wGdKYKYuQhACH1ZYFtji68VB c9Lngf8mm+fKLWoFiU157mbqdsSflQfhQJhjimoQBXTB7PrQa7HglNNjxDhVv7jQ92dP HR1Q== X-Gm-Message-State: AJIora9J2SPrPl3ChtDE/eLJyivacFPO4RkbEZksOBGvE+leOOpLkOdn jEZAanit+U2fLs7yH4hEnwU= X-Google-Smtp-Source: AGRyM1tIJYCQbdShB8m/Lq0TBH8HHecZlnvolRiCPWc6nIJdTSDw0VUSFNsGsQCNp4wIVp0QnCZ4bA== X-Received: by 2002:a05:6a00:1d8f:b0:52a:b787:b480 with SMTP id z15-20020a056a001d8f00b0052ab787b480mr13150767pfw.71.1657879480774; Fri, 15 Jul 2022 03:04:40 -0700 (PDT) Received: from genechen-System-Product-Name.richtek.com ([2402:7500:569:4518:3851:6d9:846d:fbd1]) by smtp.gmail.com with ESMTPSA id v12-20020a1709028d8c00b0016c1948ef7esm3033791plo.296.2022.07.15.03.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 03:04:40 -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 3/3] usb: typec: tcpci_rt1711h: Add compatible with rt1715 Date: Fri, 15 Jul 2022 18:04:18 +0800 Message-Id: <20220715100418.155011-4-gene.chen.richtek@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220715100418.155011-1-gene.chen.richtek@gmail.com> References: <20220715100418.155011-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 with rt1715 Signed-off-by: Gene Chen Reported-by: kernel test robot --- drivers/usb/typec/tcpm/tcpci_rt1711h.c | 168 +++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 7 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpci_rt1711h.c b/drivers/usb/typec/tcpm/tcpci_rt1711h.c index b56a0880a044..1fba98e4ef03 100644 --- a/drivers/usb/typec/tcpm/tcpci_rt1711h.c +++ b/drivers/usb/typec/tcpm/tcpci_rt1711h.c @@ -10,22 +10,31 @@ #include #include #include +#include #include #include #include "tcpci.h" #define RT1711H_VID 0x29CF #define RT1711H_PID 0x1711 +#define RT1715_DID 0x2173 -#define RT1711H_RTCTRL8 0x9B +#define RT1711H_PHYCTRL1 0x80 +#define RT1711H_PHYCTRL2 0x81 + +#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) | \ ((auto_idle) << 3) | ((tout) & 0x07)) +#define RT1711H_AUTOIDLEEN_MASK BIT(3) +#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)) @@ -35,10 +44,17 @@ #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; struct device *dev; + struct regulator *vbus; + bool src_en; + u16 did; }; static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val) @@ -75,8 +91,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, @@ -84,6 +101,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)); @@ -101,7 +126,37 @@ 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, + 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, @@ -109,8 +164,93 @@ 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); +} + +/* + * 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 EC_SUCCESS if writes succeed; failure code otherwise + */ +static inline int rt1711h_init_cc_params(struct rt1711h_chip *chip, + enum typec_cc_status cc1, enum typec_cc_status cc2) +{ + u32 rxdz_en = 0, rxdz_sel = 0; + int ret; + + 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_en); +} + +#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; + } +} + +static int rt1711h_get_cc(struct tcpci *tcpci, struct tcpci_data *tdata, + enum typec_cc_status *cc1, enum typec_cc_status *cc2) +{ + struct rt1711h_chip *chip = tdata_to_rt1711h(tdata); + unsigned int reg, role_control; + int ret; + + ret = regmap_read(chip->data.regmap, TCPC_ROLE_CTRL, &role_control); + if (ret < 0) + return ret; + + ret = regmap_read(chip->data.regmap, TCPC_CC_STATUS, ®); + if (ret < 0) + return ret; + + *cc1 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC1_SHIFT) & + TCPC_CC_STATUS_CC1_MASK, + reg & TCPC_CC_STATUS_TERM || + tcpc_presenting_rd(role_control, CC1)); + *cc2 = tcpci_to_typec_cc((reg >> TCPC_CC_STATUS_CC2_SHIFT) & + TCPC_CC_STATUS_CC2_MASK, + reg & TCPC_CC_STATUS_TERM || + tcpc_presenting_rd(role_control, CC2)); + + return rt1711h_init_cc_params(chip, *cc1, *cc2); } static int rt1711h_start_drp_toggling(struct tcpci *tcpci, @@ -209,7 +349,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, @@ -228,6 +372,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)) @@ -245,8 +391,14 @@ 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.get_cc = rt1711h_get_cc; chip->data.start_drp_toggling = rt1711h_start_drp_toggling; chip->tcpci = tcpci_register_port(chip->dev, &chip->data); if (IS_ERR_OR_NULL(chip->tcpci)) @@ -273,6 +425,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); @@ -280,6 +433,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);