Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5885330rwl; Wed, 22 Mar 2023 03:49:52 -0700 (PDT) X-Google-Smtp-Source: AK7set8SYvZk5sIMwXJb9uWjEu93+yE/OD+MKxQBT+p/1M85Lzws1Mepha0Mbo1JG6HH74yaEnUV X-Received: by 2002:a17:906:8057:b0:8aa:33c4:87d5 with SMTP id x23-20020a170906805700b008aa33c487d5mr6340658ejw.10.1679482192490; Wed, 22 Mar 2023 03:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679482192; cv=none; d=google.com; s=arc-20160816; b=NrAB3MCfmQF9bNQHocm0CUtms3wutpH3mY8YJWG62bPtdF/S6PUvB1JZTKInjyUogM jceef6Lmau8YxbMAo8x1wLavUH0snacjyrB5Hd0KksbKDYOBuYHwaTIwkb7M5owqEImE +z7QdHSMDWSFsfEl69y53om9h5NOKzK9l+YVfHqRrGsUtyMN+6+xs2agE/q7ji8YqTLI xZpsoDtidbs2FpwXjrjnTNxVkbQMGxgkuh8h8T2vJXXeedF3LtfxkPPAih1iXsp1h0Ob 5Vj5r2FRYICCM7GHKEXTATSiqsLbBJuopIVROjRSfVe3xwLLULkE6PCKt/tEGrC1yhTw 14Fg== 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=/4YiSH1IkJ0n1Hd2VWWavtDAOx8Cy0N2XlN60ziReaI=; b=dSFyu+k/xaP3JlVlRwe8ljXa8UBUvovM7GYxljorWvI9sgeEDYPKoFxsmY8W6OurEv HcOS6UBZU0QRAmKF8Iu4wvC/Rl0IisKEtektlkMQ3zxoCfGSB8MfO9xzXNmNWOFuCLXf J8QNoKKhSE5XKCgXB9E6Ux9zYsTo9GQOsfep2pTaYH7mSIJ+1pnsfVueJjVn3ELxzNNJ 4eEzEgLK/0qVjl9DLKe0Fr+JiXvPky7Wef70iKca9c5W3j/FSB30VR8P2TLhodtv+ls8 5cvHWGUV9rhGLjVScpY0U34eupQbhwXBDIFceDqUWjC+wZjTyvBmx7+WdQtGd6IYuBG7 LVwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HMoxZvWc; 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 z20-20020a170906815400b0093448e806d3si9034648ejw.85.2023.03.22.03.49.27; Wed, 22 Mar 2023 03:49:52 -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=HMoxZvWc; 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 S230418AbjCVKsf (ORCPT + 99 others); Wed, 22 Mar 2023 06:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbjCVKr5 (ORCPT ); Wed, 22 Mar 2023 06:47:57 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F05CE62850 for ; Wed, 22 Mar 2023 03:47:27 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id w4so10801607plg.9 for ; Wed, 22 Mar 2023 03:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1679482047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/4YiSH1IkJ0n1Hd2VWWavtDAOx8Cy0N2XlN60ziReaI=; b=HMoxZvWcxSqJHdCMgZLmXJJNIKvGaKv6dXzaLAo1QHugMoIP+unIbrgSH/h1m1qUBn /uH4OYpG7wd6VPDpkjPFEaPsm5usYw/9sOvF/3weGpy7UWUw1AlkgB3oqDcnEEL2SOBs nZlruRxQzeu7py18C0vst2G4EwuSi3B6eTglo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679482047; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/4YiSH1IkJ0n1Hd2VWWavtDAOx8Cy0N2XlN60ziReaI=; b=wDQYvLV+Fg4tfj8pzCXj6AR6W4Nh17GfIpBOYnbhX1GpjXotDatx/p+ps/Ebo/M8fb CZ2bP0X1GtjThqjnoN3t1lA6vb8+fpdprr4jfZZyu0/YXiy1ggjXuNjWm9QsRwvBGvY5 hpVO5KixtUn9QOYnEFkieb06NwkeJfzlDFByxO9yEWTMmCpDWENNgFmvL9lUh+ViYptK Kwnfeu2Ei4pDp7WU9qrB4oJf17SwcKEeaMQ+mn96NCYcaXTHd8Z61DXFQXZemLY5M7Ep avMTqT54x6XSpcZgrToKLeOnftzv/xxe/AZUK79VqNAihGE8P5LU3Biq6nSP5z69RAu+ WjZQ== X-Gm-Message-State: AAQBX9fR3OCXO1blj0WSKyLQi9GSgboeUYb/A6famU7NgotAlV2MEuFQ lSe//eAlWSMT6G8st8XtWWsQkw== X-Received: by 2002:a17:90b:3b90:b0:23d:27fc:8437 with SMTP id pc16-20020a17090b3b9000b0023d27fc8437mr1682775pjb.14.1679482047532; Wed, 22 Mar 2023 03:47:27 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:343d:79bf:55f9:1da5]) by smtp.gmail.com with ESMTPSA id hg4-20020a17090b300400b002340d317f3esm9508742pjb.52.2023.03.22.03.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 03:47:27 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: Xin Ji , linux-kernel@vger.kernel.org, Thomas Zimmermann , linux-acpi@vger.kernel.org, Javier Martinez Canillas , AngeloGioacchino Del Regno , Pin-yen Lin , Hsin-Yi Wang , Lyude Paul , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Allen Chen , dri-devel@lists.freedesktop.org, Marek Vasut , Stephen Boyd , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org Subject: [PATCH v14 07/10] drm/bridge: anx7625: Register Type C mode switches Date: Wed, 22 Mar 2023 18:46:36 +0800 Message-Id: <20230322104639.221402-8-treapking@chromium.org> X-Mailer: git-send-email 2.40.0.rc1.284.g88254d51c5-goog In-Reply-To: <20230322104639.221402-1-treapking@chromium.org> References: <20230322104639.221402-1-treapking@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 Register USB Type-C mode switches when the "mode-switch" property and relevant ports are available in Device Tree. Configure the crosspoint switch based on the entered alternate mode for a specific Type-C connector. Crosspoint switch can also be used for switching the output signal for different orientations of a single USB Type-C connector, but the orientation switch is not implemented yet. A TODO is added for this. Signed-off-by: Pin-yen Lin --- Changes in v14: - Fix style issues Changes in v12: - Fixed style issues in anx7625 driver - Fixed the inverted orientation setting in anx7625 driver - Changed "&ctx->client->dev" to "ctx->dev" - Fix style issues - Updated the error logs when parsing data-lanes property Changes in v11: - Added back "data-lanes" parsing logics - Removed Kconfig dependency - Updated the usage of the private data - Dropped Tested-by tag because of the new changes Changes in v10: - Added a TODO for implementing orientation switch for anx7625 - Updated the commit message for the absence of orientation switch - Fixed typo in the commit message - Collected Tested-by tag Changes in v7: - Fixed style issues in anx7625 driver - Removed DT property validation in anx7625 driver. - Extracted common codes to another commit. Changes in v6: - Squashed to a single patch drivers/gpu/drm/bridge/analogix/anx7625.c | 148 ++++++++++++++++++++++ drivers/gpu/drm/bridge/analogix/anx7625.h | 20 +++ 2 files changed, 168 insertions(+) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 76d46db3f8dc..9b259c07743f 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -2570,6 +2572,145 @@ 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) +{ + unsigned int i; + + /* Check if both ports available and do nothing to retain the current one */ + if (ctx->port_data[0].dp_connected && ctx->port_data[1].dp_connected) + return; + + for (i = 0; i < 2; i++) { + if (ctx->port_data[i].dp_connected) + anx7625_set_crosspoint_switch(ctx, + ctx->port_data[i].orientation); + } +} + +static int anx7625_typec_mux_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct drm_dp_typec_port_data *port = typec_mux_get_drvdata(mux); + struct anx7625_data *ctx = port->data; + struct device *dev = ctx->dev; + struct drm_dp_typec_switch_desc switch_desc = ctx->switch_desc; + bool new_dp_connected, old_dp_connected; + + if (switch_desc.num_typec_switches == 1) + return 0; + + wait_for_completion(&ctx->mux_register); + + old_dp_connected = ctx->port_data[0].dp_connected || + ctx->port_data[1].dp_connected; + + ctx->port_data[port->port_num].dp_connected = + state->alt && + state->alt->svid == USB_TYPEC_DP_SID && + state->alt->mode == USB_TYPEC_DP_MODE; + + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", + ctx->port_data[0].dp_connected, ctx->port_data[1].dp_connected); + + new_dp_connected = ctx->port_data[0].dp_connected || + ctx->port_data[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; +} + +static void anx7625_unregister_typec_switches(struct anx7625_data *ctx) +{ + drm_dp_unregister_typec_switches(&ctx->switch_desc); +} + +static int anx7625_register_typec_switches(struct device *dev, struct anx7625_data *ctx) +{ + struct device_node *port_node = of_graph_get_port_by_id(dev->of_node, 1); + struct drm_dp_typec_switch_desc *switch_desc = &ctx->switch_desc; + int ret; + u32 dp_lanes[4]; + unsigned int i, num_lanes; + + /* + * Currently, only mode switch is implemented. + * TODO: Implement Type-C orientation switch for anx7625. + */ + ret = drm_dp_register_typec_switches(dev, &port_node->fwnode, + &ctx->switch_desc, ctx, + anx7625_typec_mux_set); + if (ret) + return ret; + + ctx->port_data = devm_kcalloc(dev, switch_desc->num_typec_switches, + sizeof(struct anx7625_typec_port_data), + GFP_KERNEL); + if (!ctx->port_data) { + ret = -ENOMEM; + goto unregister_mux; + } + + for (i = 0; i < switch_desc->num_typec_switches; i++) { + struct drm_dp_typec_port_data *port = &switch_desc->typec_ports[i]; + struct fwnode_handle *fwnode = port->fwnode; + + ret = fwnode_property_count_u32(fwnode, "data-lanes"); + if (ret < 0) { + dev_err(dev, + "Error on getting data lanes count from %pfwP: %d\n", + fwnode, ret); + goto unregister_mux; + } + num_lanes = ret; + + ret = fwnode_property_read_u32_array(fwnode, "data-lanes", + dp_lanes, num_lanes); + if (ret) { + dev_err(dev, + "Failed to read the data-lanes variable: %d\n", + ret); + goto unregister_mux; + } + + ctx->port_data[i].orientation = dp_lanes[0] < 2 ? + TYPEC_ORIENTATION_REVERSE : TYPEC_ORIENTATION_NORMAL; + ctx->port_data[i].dp_connected = false; + } + complete_all(&ctx->mux_register); + + return 0; + +unregister_mux: + complete_all(&ctx->mux_register); + anx7625_unregister_typec_switches(ctx); + return ret; +} + static int anx7625_i2c_probe(struct i2c_client *client) { struct anx7625_data *platform; @@ -2607,6 +2748,7 @@ static int anx7625_i2c_probe(struct i2c_client *client) mutex_init(&platform->lock); mutex_init(&platform->hdcp_wq_lock); + init_completion(&platform->mux_register); INIT_DELAYED_WORK(&platform->hdcp_work, hdcp_check_work_func); platform->hdcp_workqueue = create_workqueue("hdcp workqueue"); @@ -2677,6 +2819,10 @@ static int anx7625_i2c_probe(struct i2c_client *client) if (platform->pdata.intp_irq) queue_work(platform->workqueue, &platform->work); + ret = anx7625_register_typec_switches(dev, platform); + if (ret && ret != -ENODEV) + dev_warn(dev, "Didn't register Type-C switches, err: %d\n", ret); + platform->bridge.funcs = &anx7625_bridge_funcs; platform->bridge.of_node = client->dev.of_node; if (!anx7625_of_panel_on_aux_bus(&client->dev)) @@ -2728,6 +2874,8 @@ static void anx7625_i2c_remove(struct i2c_client *client) drm_bridge_remove(&platform->bridge); + anx7625_unregister_typec_switches(platform); + if (platform->pdata.intp_irq) destroy_workqueue(platform->workqueue); diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h index 5af819611ebc..5a200da34800 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 ********/ /***************************************************************/ @@ -449,6 +461,11 @@ struct anx7625_i2c_client { struct i2c_client *tcpc_client; }; +struct anx7625_typec_port_data { + bool dp_connected; + enum typec_orientation orientation; +}; + struct anx7625_data { struct anx7625_platform_data pdata; struct platform_device *audio_pdev; @@ -479,6 +496,9 @@ struct anx7625_data { struct drm_connector *connector; struct mipi_dsi_device *dsi; struct drm_dp_aux aux; + struct completion mux_register; + struct drm_dp_typec_switch_desc switch_desc; + struct anx7625_typec_port_data *port_data; }; #endif /* __ANX7625_H__ */ -- 2.40.0.rc1.284.g88254d51c5-goog