Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp717080iog; Wed, 15 Jun 2022 10:41:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vYCRzL8eJpf8Mod6vbGr+X9NCGm2fJmbIo+sksFP6G3CPKA+Hqtziog07qo1S2bQ7PFFIf X-Received: by 2002:a05:6402:3490:b0:42f:b592:f364 with SMTP id v16-20020a056402349000b0042fb592f364mr1164071edc.66.1655314900783; Wed, 15 Jun 2022 10:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655314900; cv=none; d=google.com; s=arc-20160816; b=X/ybpSOrsJLeO2bPcJT5HMWP+Uj1SCJI8F3jpRq2/+X5EhlW8xbQKS7mq/5j7qIsUr 0AZlSkWN8SIiN922HEZon6YtibRm9DIPpp0VaQBg8cskWzk+h7AMVsK3gGrmBpd3HoVT CCOLpfvvSyrdnGbN2pHS5IV86fuYrPAWK41xPFcDzJ3W2gx2GMLRGf47ZeCIiuj4f+Y6 qq8kDufAB797a3U3lP5ajQUbU7uI+ReAVkF/8pcm8u6McG6LQ18zEVQoE3s3SboKnOqV mUHEpjYPQiDNIdA/UU216mow4L0iITgxoLe7djxQPMS2TIaLEXDIWRr70bpYY6/k1mfO 5SmA== 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:date:subject:cc:to:from :dkim-signature; bh=wmCuVasGBHT+oeeLMMo5433/xEeQJbzTl6n4hqXBTCk=; b=B4o7CJ59ezWdJ4P8E29LEuoszfKr/oqBNzcop7YlagNXfLZPdzHtJFonbtGADSczqE 9hdFYpe0WG0nhv4Y6q3MNy016cxM1gs1GQOGcMgE69pBrIae6ULFJOrZaxxIaajvg2vN VZc9muKnCsHkBHhtTKTmlpApTK9GYFN4hlFLzp/SJ+KWN4sJ12VWU3q+4qku3osrgzlF aOYbsHj+JEjRn/huokLY8JGqo0PDixCF0aOdtT3Tgr8UTyVFmCdhQCnxXNigKlV/J77I X2CbvTEqFeWoeG8Qb/cNZ4ujeSJ1re5EF7IyQW0o4eZUSPZST8Jh7nfzKaZvHtV071ln TpHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HJHVVJnd; 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 t18-20020a056402525200b0042b2c20f039si18067515edd.523.2022.06.15.10.41.15; Wed, 15 Jun 2022 10:41:40 -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=HJHVVJnd; 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 S233117AbiFORcO (ORCPT + 99 others); Wed, 15 Jun 2022 13:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357618AbiFORbw (ORCPT ); Wed, 15 Jun 2022 13:31:52 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7040B50469 for ; Wed, 15 Jun 2022 10:31:24 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id s135so11972265pgs.10 for ; Wed, 15 Jun 2022 10:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wmCuVasGBHT+oeeLMMo5433/xEeQJbzTl6n4hqXBTCk=; b=HJHVVJndWSroXL8p792C1jSRti6XTfPSo+LFfFDAIlYBl1LifrQ0MEWldc7GhWY3zE VNvHCvuE3vrAZ0XaLbT2RsXT9KEDuEYk9Edpvxeqr5Lm3Z3PqEorVFpkALmFU1bHN4nP FstsaD9Wo+lVZ5T+I6Vj3XudDBgklJHfIZwlM= 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=wmCuVasGBHT+oeeLMMo5433/xEeQJbzTl6n4hqXBTCk=; b=r4mTuwHOCKkBWYRkbbSoZORpOmgRJEvSwEp8d/2dq/x2h+czUG+3EVTN5sBefrLUIH 9oHTh64i87vwEqfAbPLXm6LxZiCubK5DDFJqBzFIKGanxJzlvuqTVaj2KVzBO3PC0V10 rfJzQQzCA8cCpnOLTb/RteQYgjPq8ueY8UsuZYVT4OqhvL6dc1a7OZeFpzERs/DM8hbv c+QRs6ryCKrdnMZW92Pd/Pvuh/7d9CABvaotfUiPguhas4OdPC8HaZdQHGBiByZy9fIq Wzij/xNcVwGgGwAKeir+ksNfY5ZZd7k4JJ31Ahb/ZdZgPKVU3ha9JH8NWmAKBD8IDEsN L+ZA== X-Gm-Message-State: AJIora/Kf8q4oqN3bULhD2Vo7jOjLbpT5f9RKkeDp5yNLIaev1wT7umQ 7fvkAHkzqCl5wigMWh8bbVHOrDAWCNOEuQ== X-Received: by 2002:a63:155:0:b0:3fd:1b8e:16ca with SMTP id 82-20020a630155000000b003fd1b8e16camr749024pgb.407.1655314283666; Wed, 15 Jun 2022 10:31:23 -0700 (PDT) Received: from pmalani.c.googlers.com.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id d10-20020aa7814a000000b005103abd2fdbsm10147433pfn.206.2022.06.15.10.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 10:31:22 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Cc: bleung@chromium.org, swboyd@chromium.org, heikki.krogerus@linux.intel.com, Pin-Yen Lin , AngeloGioacchino Del Regno , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Prashant Malani , Andrzej Hajda , Daniel Vetter , David Airlie , devicetree@vger.kernel.org (open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS), dri-devel@lists.freedesktop.org (open list:DRM DRIVERS), Greg Kroah-Hartman , Hsin-Yi Wang , Jernej Skrabec , Jonas Karlman , =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= , Krzysztof Kozlowski , Laurent Pinchart , Maxime Ripard , Neil Armstrong , Robert Foss , Rob Herring , Sam Ravnborg , Thomas Zimmermann , Xin Ji Subject: [PATCH v4 7/7] drm/bridge: anx7625: Add typec_mux_set callback function Date: Wed, 15 Jun 2022 17:20:23 +0000 Message-Id: <20220615172129.1314056-8-pmalani@chromium.org> X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog In-Reply-To: <20220615172129.1314056-1-pmalani@chromium.org> References: <20220615172129.1314056-1-pmalani@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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. Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: NĂ­colas F. R. A. Prado Tested-by: NĂ­colas F. R. A. Prado Signed-off-by: Pin-Yen Lin Signed-off-by: Prashant Malani --- Changes since v3: - Added Reviewed-by tag from Angelo. Changes since v2: - Moved num_typec_switches check to beginning of function - Made dp_connected assignments fit on one line (and removed unnecessary parentheses) - Added Reviewed-by and Tested-by tags. Changes since v1: - No changes. drivers/gpu/drm/bridge/analogix/anx7625.c | 56 +++++++++++++++++++++++ drivers/gpu/drm/bridge/analogix/anx7625.h | 13 ++++++ 2 files changed, 69 insertions(+) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index bd21f159b973..5992fc8beeeb 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,64 @@ 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 new_dp_connected, old_dp_connected; + + if (ctx->num_typec_switches == 1) + return 0; + + old_dp_connected = ctx->typec_ports[0].dp_connected || ctx->typec_ports[1].dp_connected; + + 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; + + /* dp on, power on first */ + if (!old_dp_connected && new_dp_connected) + pm_runtime_get_sync(dev); + + anx7625_typec_two_ports_update(ctx); + + /* dp off, power off last */ + if (old_dp_connected && !new_dp_connected) + pm_runtime_put_sync(dev); + return 0; } diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h index 76cfc64f7574..7d6c6fdf9a3a 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.h +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h @@ -55,6 +55,18 @@ #define HPD_STATUS_CHANGE 0x80 #define HPD_STATUS 0x80 +#define TCPC_SWITCH_0 0xB4 +#define SW_SEL1_DPTX0_RX2 BIT(0) +#define SW_SEL1_DPTX0_RX1 BIT(1) +#define SW_SEL1_SSRX_RX2 BIT(4) +#define SW_SEL1_SSRX_RX1 BIT(5) + +#define TCPC_SWITCH_1 0xB5 +#define SW_SEL2_DPTX1_TX2 BIT(0) +#define SW_SEL2_DPTX1_TX1 BIT(1) +#define SW_SEL2_SSTX_TX2 BIT(4) +#define SW_SEL2_SSTX_TX1 BIT(5) + /******** END of I2C Address 0x58 ********/ /***************************************************************/ @@ -444,6 +456,7 @@ struct anx7625_i2c_client { }; struct anx7625_port_data { + bool dp_connected; struct typec_mux_dev *typec_mux; struct anx7625_data *ctx; }; -- 2.36.1.476.g0c4daa206d-goog