Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1253386iog; Tue, 14 Jun 2022 02:22:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vEtpg8ZE0X4kYkkiAFpAQCMjA/UkrUD2w4+Od6ZN/J6YofXBdD9sF74FBR3cxRcXx/aXHU X-Received: by 2002:a17:90a:f2ce:b0:1e8:3e55:bbfa with SMTP id gt14-20020a17090af2ce00b001e83e55bbfamr3584455pjb.204.1655198554799; Tue, 14 Jun 2022 02:22:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655198554; cv=none; d=google.com; s=arc-20160816; b=vfKIwpa8DBTTJ223bJ0UKOf27/6HPCuXuuOM9rHKJjeqkBnu50dSwlf/lMBx6xZgqe B/agMj6gi/toJGZPgJKAA2bfxZBBqRSYlAbMTVAGfQ0Gq+4VNY+vkKZQDUEa+b3LRpkX 3tsjhbubr5VCGEwdLhT/YmfbYU6Hv/O2kh/dZ99Y6qoItNTuUVrkA9dcSjvt3+p+DqcY 39oxxwmsIQpq/46hvJoRdtke995eSv2/PJ6EJzc168TqVseD5auptIngwho8KzPz1fNx Zc/sqQJ1bhmuC1RS2Eac9Nv+N83ar89kDWUPksHWQcgToeDJ0pdNYYzTWgRlTwALxi+a rrFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=QhvvxqBDc4O6cqtxNWaREqrfN92rGnha8HhGfNJEYIY=; b=whKuygHYIscCg0evDfbStOvJ+1gCZfd7SsvtnCcl3da0FStmr+7qJPvxenhervHKDn 5eIJSz+82z82H1GhnVkHAaTd0gd85STRxueZf9xzO6fOeqzf/CllCAqdiSdJG2zp4aB5 qTJRVleLF6zkO2Hnex43pmzhbFj8PBi3s7v3QqLoD2HxMzokJZ3RjFAR6zDHEfEZBUeX OvL/IKgsEsXLGnOnyyqYoMo5hylVpx4FjhNH2UzmJbc4hLGWqQ+Go54GdUBYUpeS5xmB flcU1JZSeLxKj8VjfRI/pvnNkMcBrJa+hqfSnU62Vv8SMy/1+qSWkpd5zgGwwBK+cwJu XIjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=douVYUls; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a056a00244b00b0050a7b4bf744si14414219pfj.128.2022.06.14.02.22.22; Tue, 14 Jun 2022 02:22:34 -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=@chromium.org header.s=google header.b=douVYUls; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237448AbiFNJIR (ORCPT + 99 others); Tue, 14 Jun 2022 05:08:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232251AbiFNJIP (ORCPT ); Tue, 14 Jun 2022 05:08:15 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DEA63F306 for ; Tue, 14 Jun 2022 02:08:13 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id m16-20020a7bca50000000b0039c8a224c95so3520485wml.2 for ; Tue, 14 Jun 2022 02:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QhvvxqBDc4O6cqtxNWaREqrfN92rGnha8HhGfNJEYIY=; b=douVYUlsdf+Xh3MuzIfeY0X8Ce+uwGOB4VX1fszrw5WlSXQfxYVaK7H0LCFX+l06al G5Pt7vxmjI/oNJX86GkWkmt9jVl9oIs5040FZFsPravjzgf3NF8nQgvJXGT86lajFlGA a5M9bPfdwTcVtYWDnAAyvWPcyA0DlWZOO4P5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QhvvxqBDc4O6cqtxNWaREqrfN92rGnha8HhGfNJEYIY=; b=3XKytKhXPAvvwKq093Bi8uJxVnL6QP4pMWb0NyQ8eWeY+QEM1w/miithckXHNfJ5SK EVL0BTmCzfbhEg97wDk/WhImh8H6a5rQsBNGOqIOg1r0rEHdPo3hmx/7JHrMbwstBhzD WsU6g4FaN8PvOM8tZWFtIHBGkaNNe8exratSV7rJPONBJk4um3zOrFhYShphoXKGjA4d /kS/JN9PJYRrQgXJjUr9KhOh3BXZC3ZYzxCxuzbklq2VPPSD5a9uFCqAIOQJSRm5h7H2 G4SIF7bcoGtCa2rxYPacFgwTrJqKX0dr0bQwJI12rArQdREnVlI518uBRWAuSXyMGecu FjqA== X-Gm-Message-State: AOAM5332vxCp+9GdZOXAkj6/ykgF/eu6OI42ZaZH1retLXQSBmT6AJLF XR3eqXoDVhqoP1WfxM8+tva129tj/wm6NO7LWdf0XQ== X-Received: by 2002:a05:600c:3cd:b0:39c:880e:dc7b with SMTP id z13-20020a05600c03cd00b0039c880edc7bmr2968699wmd.168.1655197691993; Tue, 14 Jun 2022 02:08:11 -0700 (PDT) MIME-Version: 1.0 References: <20220609181106.3695103-1-pmalani@chromium.org> <20220609181106.3695103-8-pmalani@chromium.org> <1191703c-efa5-7fe6-7dd0-e3e786b58411@collabora.com> In-Reply-To: <1191703c-efa5-7fe6-7dd0-e3e786b58411@collabora.com> From: Pin-yen Lin Date: Tue, 14 Jun 2022 17:08:00 +0800 Message-ID: Subject: Re: [PATCH v2 7/7] drm/bridge: anx7625: Add typec_mux_set callback function To: AngeloGioacchino Del Regno Cc: Prashant Malani , 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?= Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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. Best regards, Pin-yen > > > + > > + /* dp on, power on first */ > > + if (!old_dp_connected && new_dp_connected) > > + pm_runtime_get_sync(dev); > > ...so that will never happen... > > > + > > + anx7625_typec_two_ports_update(ctx); > > + > > + /* dp off, power off last */ > > + if (old_dp_connected && !new_dp_connected) > > + pm_runtime_put_sync(dev); > > ...and same here. > > Regards, > Angelo