Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp814922pxy; Sun, 1 Aug 2021 03:09:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyu+EHfqVSi0WxAjtgFQ4VpvzXQEq/MYrKG9Av2t3p1Sipg8hGHUOXo5kvIheGedMWIqvVu X-Received: by 2002:a17:906:9bf1:: with SMTP id de49mr10434284ejc.480.1627812590367; Sun, 01 Aug 2021 03:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627812590; cv=none; d=google.com; s=arc-20160816; b=dQKC9CPCh8i62hVWsOu/XuHrQrjNDrhaPYTAVCCHnxZ7X9J+CQG3ZtcLkAprZuX0yC OMfC1STxbR4KZKvtcbJgNv4lgPPDWsSzd90IdrfjUbhemJQ0oE3o8Fs7XXBnecOoSh8a 2ga6+LL2SKnOUtkvH/TxnuvKD7w/VuxAbBKkPbrCzyLpqf2DayuNzCfqMC7OTEbKaHpL PcnzUVHBdR/dQpv1GDQ08g0TB4RCBlpC8BkIVpq/D2MTAsRMD4LQi1mLNInYRyh4VwG8 QlWx1yCo7y2bPFQdUKlrOgETNNZNKUnY/mNYzeHZhwoI26WKgUg6InRgWkbdlpCghvjJ 6ROA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=cKSXPQaFS0GkTDYT3pJQpgc7Jddui/4xYTd67zjx9rs=; b=cY+BVTaUvTCF1u4FoBLbk8kJPUo00puR7EF/KdSdKGMeYljgoMwJjsBn87z8KDHH2y 89W4k8B07d4Nbc+KeaLXPRtE8ER7B7xj23oQw/7qrOtJucHtoKMlf30mkEH+s77xuS49 fP8OuwMze7+B3axZ1N/TDn+YI/yxkhXvIeffSO0qSNzeaCPIvxbgKgm02dtoxcvsalcL KXuOnKunYUNKcZI3Hh9Ozrp84eW1alO5ZUqKY6OnhWV1x+DZeCp64gIEw87J1j2CwRcc Tz+l2ABH7F7wd14rfHk7j5fK/gPC50gc6XNMRAtcGW4R1Z+mBIR1l3mZni/CNx7c1i4D IlXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=No6ylmOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gf9si7180242ejb.635.2021.08.01.03.09.27; Sun, 01 Aug 2021 03:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=No6ylmOO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231766AbhHAKHl (ORCPT + 99 others); Sun, 1 Aug 2021 06:07:41 -0400 Received: from mail-40135.protonmail.ch ([185.70.40.135]:31775 "EHLO mail-40135.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbhHAKHk (ORCPT ); Sun, 1 Aug 2021 06:07:40 -0400 Date: Sun, 01 Aug 2021 10:07:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1627812450; bh=cKSXPQaFS0GkTDYT3pJQpgc7Jddui/4xYTd67zjx9rs=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=No6ylmOOv6eZauDjPhJgNcexjWGxFbdlVozGnDOqN7/fA70YMCD365SYakxcQw6Xl k6CK1fPGvCO6YoX0BvrU+ssh4czvFczOfZSpvLzWPM1P22HcNnonLKRAdWuWuSYLYB qvENBbWlqxfzJ3i7OXEMcOeSsbb5/sEhtiomvFFE= To: MyungJoo Ham , Chanwoo Choi , Rob Herring From: Yassine Oudjana Cc: Yassine Oudjana , Michael Auchter , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Reply-To: Yassine Oudjana Subject: [PATCH v3 2/3] extcon: usbc-tusb320: Add support for TUSB320L Message-ID: <20210801100519.440574-3-y.oudjana@protonmail.com> In-Reply-To: <20210801100519.440574-1-y.oudjana@protonmail.com> References: <20210801100519.440574-1-y.oudjana@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TUSB320L is a newer chip with additional features, and it has additional st= eps in its mode changing sequence: - Disable CC state machine, - Write to mode register, - Wait for 5 ms, - Re-enable CC state machine. It also has an additional register that a revision number can be read from. Add support for the mode changing sequence, and read the revision number du= ring probe and print it as info. Changes since v2: - Use a separate mode setting function for each of TUSB320 and TUSB320L. = =20 Signed-off-by: Yassine Oudjana --- drivers/extcon/extcon-usbc-tusb320.c | 74 +++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/drivers/extcon/extcon-usbc-tusb320.c b/drivers/extcon/extcon-u= sbc-tusb320.c index 867fb2bf2bdc..5a80ca7a15eb 100644 --- a/drivers/extcon/extcon-usbc-tusb320.c +++ b/drivers/extcon/extcon-usbc-tusb320.c @@ -21,10 +21,13 @@ #define TUSB320_REG9_INTERRUPT_STATUS=09=09BIT(4) =20 #define TUSB320_REGA=09=09=09=090xa +#define TUSB320L_REGA_DISABLE_TERM=09=09BIT(0) #define TUSB320_REGA_I2C_SOFT_RESET=09=09BIT(3) #define TUSB320_REGA_MODE_SELECT_SHIFT=09=094 #define TUSB320_REGA_MODE_SELECT_MASK=09=090x3 =20 +#define TUSB320L_REGA0_REVISION=09=09=090xa0 + enum tusb320_attached_state { =09TUSB320_ATTACHED_STATE_NONE, =09TUSB320_ATTACHED_STATE_DFP, @@ -39,9 +42,16 @@ enum tusb320_mode { =09TUSB320_MODE_DRP, }; =20 +enum tusb320_type { +=09TYPE_TUSB320, +=09TYPE_TUSB320L, +}; + + struct tusb320_priv { =09struct device *dev; =09struct regmap *regmap; +=09enum tusb320_type type; =09struct extcon_dev *edev; =20 =09enum tusb320_attached_state state; @@ -106,12 +116,53 @@ static int tusb320_set_mode(struct tusb320_priv *priv= , enum tusb320_mode mode) =09return 0; } =20 +static int tusb320l_set_mode(struct tusb320_priv *priv, enum tusb320_mode = mode) +{ +=09int ret; + +=09/* Disable CC state machine */ +=09ret =3D regmap_write_bits(priv->regmap, TUSB320_REGA, +=09=09TUSB320L_REGA_DISABLE_TERM, 1); +=09if (ret) { +=09=09dev_err(priv->dev, +=09=09=09"failed to disable CC state machine: %d\n", ret); +=09=09return ret; +=09} + +=09/* Write mode */ +=09ret =3D regmap_write_bits(priv->regmap, TUSB320_REGA, +=09=09TUSB320_REGA_MODE_SELECT_MASK << TUSB320_REGA_MODE_SELECT_SHIFT, +=09=09mode << TUSB320_REGA_MODE_SELECT_SHIFT); +=09if (ret) { +=09=09dev_err(priv->dev, "failed to write mode: %d\n", ret); +=09=09goto err; +=09} + +=09msleep(5); +err: +=09/* Re-enable CC state machine */ +=09ret =3D regmap_write_bits(priv->regmap, TUSB320_REGA, +=09=09TUSB320L_REGA_DISABLE_TERM, 0); +=09if (ret) +=09=09dev_err(priv->dev, +=09=09=09"failed to re-enable CC state machine: %d\n", ret); + +=09return ret; +} + static int tusb320_reset(struct tusb320_priv *priv) { =09int ret; =20 =09/* Set mode to default (follow PORT pin) */ -=09ret =3D tusb320_set_mode(priv, TUSB320_MODE_PORT); +=09switch (priv->type) { +=09case TYPE_TUSB320: +=09=09ret =3D tusb320_set_mode(priv, TUSB320_MODE_PORT); +=09=09break; +=09case TYPE_TUSB320L: +=09=09ret =3D tusb320l_set_mode(priv, TUSB320_MODE_PORT); +=09=09break; +=09} =09if (ret && ret !=3D -EBUSY) { =09=09dev_err(priv->dev, =09=09=09"failed to set mode to PORT: %d\n", ret); @@ -183,6 +234,8 @@ static int tusb320_extcon_probe(struct i2c_client *clie= nt, =09=09=09=09const struct i2c_device_id *id) { =09struct tusb320_priv *priv; +=09const void *match_data; +=09unsigned int revision; =09int ret; =20 =09priv =3D devm_kzalloc(&client->dev, sizeof(*priv), GFP_KERNEL); @@ -198,12 +251,28 @@ static int tusb320_extcon_probe(struct i2c_client *cl= ient, =09if (ret) =09=09return ret; =20 +=09match_data =3D device_get_match_data(&client->dev); +=09if (!match_data) +=09=09return -EINVAL; + +=09priv->type =3D (enum tusb320_type)match_data; + =09priv->edev =3D devm_extcon_dev_allocate(priv->dev, tusb320_extcon_cable= ); =09if (IS_ERR(priv->edev)) { =09=09dev_err(priv->dev, "failed to allocate extcon device\n"); =09=09return PTR_ERR(priv->edev); =09} =20 +=09if (priv->type =3D=3D TYPE_TUSB320L) { +=09=09ret =3D regmap_read(priv->regmap, TUSB320L_REGA0_REVISION, &revision= ); + +=09=09if (ret) +=09=09=09dev_warn(priv->dev, +=09=09=09=09"failed to read revision register: %d\n", ret); +=09=09else +=09=09=09dev_info(priv->dev, "chip revision %d\n", revision); +=09} + =09ret =3D devm_extcon_dev_register(priv->dev, priv->edev); =09if (ret < 0) { =09=09dev_err(priv->dev, "failed to register extcon device\n"); @@ -238,7 +307,8 @@ static int tusb320_extcon_probe(struct i2c_client *clie= nt, } =20 static const struct of_device_id tusb320_extcon_dt_match[] =3D { -=09{ .compatible =3D "ti,tusb320", }, +=09{ .compatible =3D "ti,tusb320", .data =3D (void *)TYPE_TUSB320, }, +=09{ .compatible =3D "ti,tusb320l", .data =3D (void *)TYPE_TUSB320L, }, =09{ } }; MODULE_DEVICE_TABLE(of, tusb320_extcon_dt_match); --=20 2.32.0