Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp552143iog; Wed, 15 Jun 2022 07:37:10 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uWuE1z8X7fC0LLsVXEzHuuJFEdanSko/FqjFYlqU2bNHrXxMrQRluHnjYStRrrQCF9/zpS X-Received: by 2002:a05:6402:28a2:b0:42d:e116:de8f with SMTP id eg34-20020a05640228a200b0042de116de8fmr3498edb.305.1655303829739; Wed, 15 Jun 2022 07:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655303829; cv=none; d=google.com; s=arc-20160816; b=w1+fn9xYh9q9qB5kwUG+/z5Q/bspGrRtOrhpi6CZKb9besShuplWUg4vV9l4x7IXM4 R53BtQfF7XhaXDQ4fiL761IoGF3mwhTv3yFUc6ibsR/xyevGrklmzSFtRBEXt+tm0PYf vhxPJ1frpT0cITH4Y+Z/uIbFbJpb/GzOlwNBh3PUJp2R/o7L1L+i8czMiOKURdL6gbtb KLHko8O0Syrs9KV/QjehPtCgXxpx5nnMmgS3fMBhnVRpCl6q9C48CsZGBMCWDOOesHVk xx++pZzRhLhL5ogxNQItYSbj2I3ghkXlFF+YTEKyeZhPWIDHPZhjwhN1Q2NxByUGGuZc qFZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uz0xSL6P+65YLgtRAWyQs9daLy3HAryqasa769O1w8k=; b=CBcMZzmt3oCikcLB1wWhwWLGQDo2ODaBhoYJAR/sqRtOHUyDJiMQTpurnLku0UyZED MNGWfs8oToLzpKeARZnoda/aRo8KicYPyzBD5sw8FNqIF1AGZZzpid5x0e6/zGS00NF2 csziC+SjcrZXCR8zkNrSLeIQEfN8KVDHp9XZVIkwny0o5LaYO7yXDc0Erydifce9Hg1t KIfyvMHuDfuOLgMMZXCb5yOWw4bHGjtWC1vXqfOtSHOBK+NXHohQHoEQm219/VUfvcb1 yfICU22vZun8xsi0QbCTkMiHv13YUrM9T8i10+iMpLnrhxfySlTKOmcR9AQqE6xyhKbn mEkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MufCONJC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb36-20020a170907162400b0071209f03c59si16768300ejc.630.2022.06.15.07.36.42; Wed, 15 Jun 2022 07:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MufCONJC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355207AbiFON65 (ORCPT + 99 others); Wed, 15 Jun 2022 09:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353817AbiFON6Q (ORCPT ); Wed, 15 Jun 2022 09:58:16 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A867E017; Wed, 15 Jun 2022 06:58:00 -0700 (PDT) Received: from [192.168.1.100] (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id DFD566601701; Wed, 15 Jun 2022 14:57:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1655301479; bh=FFs8T8AY3TkghM9Ue1wO41/Alt1IIwwAZGlkReIRBMA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=MufCONJCJaFd78/i7BkklmNqEafwzy0hYnARqR2ChECDqeyog4T+oxPDSqRyieQKo 05baBqalwxSZ9L6EhVJCHlbtZv664NpgTzpSVHwaVjoADtRJAsorkC17Gt325I87XR 5GDI1F5Neg6PUHdVhXAd6GO+BSiBn086Bz8weN1ZPym8jtoDctGGZ0PZOtN4yV38a4 yyYNhH3ia3tst8Fi0Onl+a7mW2hhArWZk4T+ZT+NlwtaO4CRb89KoG9oHrpahotXgH E2Xw/O5EAjUIkIac/gV6Gec8gUgkU2jYJMwidYG4DSHYhLkq+m0dQBe06SyMANAeuK dMKpdGoXbB6qA== Message-ID: <77302f99-cda5-00a2-ab00-07716b0dc470@collabora.com> Date: Wed, 15 Jun 2022 15:57:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2 7/7] drm/bridge: anx7625: Add typec_mux_set callback function Content-Language: en-US To: Prashant Malani , Pin-yen Lin Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, heikki.krogerus@linux.intel.com, Andrzej Hajda , Neil Armstrong , David Airlie , "open list:DRM DRIVERS" , Laurent Pinchart , Krzysztof Kozlowski , Sam Ravnborg , Jernej Skrabec , Tzung-Bi Shih , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Thomas Zimmermann , =?UTF-8?B?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , Jonas Karlman , swboyd@chromium.org, Rob Herring , Maxime Ripard , Hsin-Yi Wang , Xin Ji , Greg Kroah-Hartman , Robert Foss , =?UTF-8?B?Sm9zw6kgRXhww7NzaXRv?= References: <20220609181106.3695103-1-pmalani@chromium.org> <20220609181106.3695103-8-pmalani@chromium.org> <1191703c-efa5-7fe6-7dd0-e3e786b58411@collabora.com> From: AngeloGioacchino Del Regno In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Il 14/06/22 18:58, Prashant Malani ha scritto: > On Tue, Jun 14, 2022 at 2:08 AM Pin-yen Lin wrote: >> >> Hi AngeloGioacchino, >> >> >> On Tue, Jun 14, 2022 at 4:15 PM AngeloGioacchino Del Regno >> wrote: >>> >>> Il 09/06/22 20:09, Prashant Malani ha scritto: >>>> From: Pin-Yen Lin >>>> >>>> Add the callback function when the driver receives state >>>> changes of the Type-C port. The callback function configures the >>>> crosspoint switch of the anx7625 bridge chip, which can change the >>>> output pins of the signals according to the port state. >>>> >>>> Signed-off-by: Pin-Yen Lin >>>> Signed-off-by: Prashant Malani >>>> --- >>>> >>>> Changes since v2: >>>> - No changes. >>>> >>>> drivers/gpu/drm/bridge/analogix/anx7625.c | 58 +++++++++++++++++++++++ >>>> drivers/gpu/drm/bridge/analogix/anx7625.h | 13 +++++ >>>> 2 files changed, 71 insertions(+) >>>> >>>> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c >>>> index d41a21103bd3..2c308d12fab2 100644 >>>> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c >>>> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c >>>> @@ -15,6 +15,7 @@ >>>> #include >>>> #include >>>> #include >>>> +#include >>>> #include >>>> #include >>>> >>>> @@ -2582,9 +2583,66 @@ static void anx7625_runtime_disable(void *data) >>>> pm_runtime_disable(data); >>>> } >>>> >>>> +static void anx7625_set_crosspoint_switch(struct anx7625_data *ctx, >>>> + enum typec_orientation orientation) >>>> +{ >>>> + if (orientation == TYPEC_ORIENTATION_NORMAL) { >>>> + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, >>>> + SW_SEL1_SSRX_RX1 | SW_SEL1_DPTX0_RX2); >>>> + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, >>>> + SW_SEL2_SSTX_TX1 | SW_SEL2_DPTX1_TX2); >>>> + } else if (orientation == TYPEC_ORIENTATION_REVERSE) { >>>> + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, >>>> + SW_SEL1_SSRX_RX2 | SW_SEL1_DPTX0_RX1); >>>> + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, >>>> + SW_SEL2_SSTX_TX2 | SW_SEL2_DPTX1_TX1); >>>> + } >>>> +} >>>> + >>>> +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx) >>>> +{ >>>> + if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected) >>>> + /* Both ports available, do nothing to retain the current one. */ >>>> + return; >>>> + else if (ctx->typec_ports[0].dp_connected) >>>> + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL); >>>> + else if (ctx->typec_ports[1].dp_connected) >>>> + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE); >>>> +} >>>> + >>>> static int anx7625_typec_mux_set(struct typec_mux_dev *mux, >>>> struct typec_mux_state *state) >>>> { >>>> + struct anx7625_port_data *data = typec_mux_get_drvdata(mux); >>>> + struct anx7625_data *ctx = data->ctx; >>>> + struct device *dev = &ctx->client->dev; >>>> + >>>> + bool old_dp_connected = (ctx->typec_ports[0].dp_connected || >>>> + ctx->typec_ports[1].dp_connected); >>> >>> So the old connection state is "either port0 or port1 are currently connected"... >>> >>>> + bool new_dp_connected; >>>> + >>>> + if (ctx->num_typec_switches == 1) >>>> + return 0; >>>> + >>>> + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", >>>> + ctx->typec_ports[0].dp_connected, ctx->typec_ports[1].dp_connected); >>>> + >>>> + data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID && >>>> + state->alt->mode == USB_TYPEC_DP_MODE); >>>> + > + new_dp_connected = (ctx->typec_ports[0].dp_connected || >>>> + ctx->typec_ports[1].dp_connected); >>> >>> ...and the new connection state is the same as the old one, because I don't see >>> anything that could ever modify it in this function's flow, until reaching this >>> assignment. >> >> The typec mux driver data (`struct anx7625_port_data *data = >> typec_mux_get_drvdata(mux)`) is set to one of the >> `ctx->typec_ports[*]` in `anx7625_register_mode_switch` (see patch 6 >> of this series). >> >> So, the `data->dp_connected = ...` assignment may change the new >> connection state. > > Angelo, I think your interpretation of this logic is not accurate.. > |old_dp_connected| represents *whether* port1 or port0 has a DP > partner connected, not that *either* of them has it. > > So, this logic looks OK to me. > Hello Prashant, You're completely right: I've finally seen where this is happening, so yes we don't know, nor care at that moment, whether data->dp_connected is port0 or port1, we assign and check 'em both again, which is actually smart. I'm sorry for the misunderstandment - and thank you for your reply. Feel free to add my Reviewed-by: AngeloGioacchino Del Regno Regards, Angelo