Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp5920039rwl; Mon, 9 Jan 2023 01:29:06 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/jDirbbP4OCidDDqQj168ypdxTNxDDg7OpdV9OBKQrWPFoBVSo/Nce0cYa6oXzXS9LHHY X-Received: by 2002:a17:907:d388:b0:846:cdd9:d29 with SMTP id vh8-20020a170907d38800b00846cdd90d29mr50970091ejc.28.1673256546652; Mon, 09 Jan 2023 01:29:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673256546; cv=none; d=google.com; s=arc-20160816; b=YnrECHAWUdFVFJDDlbqxRU94W6opUfZ/pRp5EDIYgvp23EtB4+Vv9jhvx7gHMyZz2z Q3Ta9Uu+IsQGzjEZ8uPH58mJt7tb9M7MrT9GPAKD25l1Fr89k8DB9xhkvMc6IP4lMTL8 HMCTFXqBDSvZOSQTNbJqkxOWpEqLflWm+gIRKaDv3KQW0ucYJZBJxUVl0BkqRmxfJNKq ktk4JwVVrQqbbmY7c/lhbUXT1QdnD03WtGMqH9yOplN5fRboLGEqaz/SodAHkU0v9e+a kEc2MXGRAcTR1ebuU3CwANMqtpQaxhhHuTqZ1GRucbObAT5a49/rjvFWAmbDPaoaHF5o 1Cmg== 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=9iAqigrmRtbOwkIjEJ3yqHcs8IpEn5bVcl0Fnp8oBxA=; b=XqFDABX3AAVYCzTz/Lj3B5mt7i5UeE+51bn/2NDqbaDmhgleArvsOFGBNEz8g3j6Jg CiQOHm71XfGsqPEDWAeoIqHuPNhxGuCZWJhgMfSD/qhFs+jpM0bIauGBZiWbl1FvcuFp xOEG8NL9ZFC9eaZXThhaJfo72DQjqePKUG96wRuSw2c9KckqhtgRCqDTkd8yJC4rMjLn hpsoeulIinFVm9JbHOPUjZt3tgP7+iYVAKoyPI4iBWFYh2I/QecgvUYPabXoLuwjnGo3 N9i0SZOQtuG97TkIhV+ycYnf7hTYj+Vv/cp2uhseVWgA0h8B1paGpK0S1U1IyrQGPaY4 H6Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UsXasHbi; 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 dr17-20020a170907721100b008334aeea096si8542138ejc.240.2023.01.09.01.28.53; Mon, 09 Jan 2023 01:29:06 -0800 (PST) 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=UsXasHbi; 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 S236726AbjAIIm4 (ORCPT + 54 others); Mon, 9 Jan 2023 03:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbjAIImI (ORCPT ); Mon, 9 Jan 2023 03:42:08 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFA3612D2C for ; Mon, 9 Jan 2023 00:42:03 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so12061788pjj.2 for ; Mon, 09 Jan 2023 00:42:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=9iAqigrmRtbOwkIjEJ3yqHcs8IpEn5bVcl0Fnp8oBxA=; b=UsXasHbilcmH352bWImADdEHGkeKLDKY8/6LTgkfSwTDOlG3fZbpIS6jGqe5W2B/9D HwQNfa5wSvNFIbxNsyPR7nKuty0ce3XFiUo/sEkI5eyHTPdIPaH0Wq8a3Uuiw44EB3Zs +7SVGSXED0FlrhRmhE2qJO5Z6uIp0t8QNaGF8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9iAqigrmRtbOwkIjEJ3yqHcs8IpEn5bVcl0Fnp8oBxA=; b=Bj95PiKQXExT5kJqkaMoJjr9vIQTZWiPcAdB6Nk3BvtTxbkFTORIylCRkpaS7KFFud kTD//Cvze2kSlntVZtnRxbt13Ms+tqHPGNGy3d5J+33z5RL3O7ymDVDyZpzb1EWrCORv Y9LWcG+e9l3x96wVYTHJNX8VCX5/GpZ6f9e6Kr8ZNS2qSyc83dxaG9DtUqljCUgFqB3S WmTa8MP05K8MSq9uWQ+g1UnUWqdlZlcBshJhBcG5fOxG7RosTHaG5NJmOJzR1l4aPUo7 fgRuodTsB+NGg21atYZyS+e0Wx3Kk9uJCjvx4f18JaFO/rM4MGCC2P5uhYa50Ef3Ba+8 KdUA== X-Gm-Message-State: AFqh2kr16ObCWQmCfkj69ykKcVMYl0PW9qusaMTGtEH7w6iIonyuPT2C 8CWBIk8pXK2e08xwk3FFlVSHAg== X-Received: by 2002:a17:902:6ac6:b0:192:cd8a:f358 with SMTP id i6-20020a1709026ac600b00192cd8af358mr24722274plt.69.1673253723421; Mon, 09 Jan 2023 00:42:03 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:801:a736:715:9a15]) by smtp.gmail.com with ESMTPSA id c14-20020a170902d48e00b00186acb14c4asm5568119plg.67.2023.01.09.00.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jan 2023 00:42:03 -0800 (PST) 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: Hsin-Yi Wang , Pin-yen Lin , dri-devel@lists.freedesktop.org, Marek Vasut , Stephen Boyd , AngeloGioacchino Del Regno , Xin Ji , linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, chrome-platform@lists.linux.dev, Thomas Zimmermann , Allen Chen , Javier Martinez Canillas , Lyude Paul , =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , linux-kernel@vger.kernel.org Subject: [PATCH v9 9/9] drm/bridge: it6505: Register Type C mode switches Date: Mon, 9 Jan 2023 16:41:01 +0800 Message-Id: <20230109084101.265664-10-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230109084101.265664-1-treapking@chromium.org> References: <20230109084101.265664-1-treapking@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 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 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 Register USB Type-C mode switches when the "mode-switch" property and relevant port are available in Device Tree. Configure the "lane_swap" state based on the entered alternate mode for a specific Type-C connector, which ends up updating the lane swap registers of the it6505 chip. Signed-off-by: Pin-yen Lin --- (no changes since v7) Changes in v7: - Fixed style issues in it6505 driver - Removed the redundant sleep in it6505 driver - Removed DT property validation in it6505 driver - Rebased to drm-misc-next - Extracted common codes to another commit Changes in v6: - Changed it6505_typec_mux_set callback function to accommodate with the latest drm-misc patches - Changed the driver implementation to accommodate with the new binding - Squashed to a single patch drivers/gpu/drm/bridge/Kconfig | 1 + drivers/gpu/drm/bridge/ite-it6505.c | 119 +++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index 737578dd57ed..33803f581562 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -87,6 +87,7 @@ config DRM_FSL_LDB config DRM_ITE_IT6505 tristate "ITE IT6505 DisplayPort bridge" depends on OF + depends on TYPEC || TYPEC=n select DRM_DISPLAY_DP_HELPER select DRM_DISPLAY_HDCP_HELPER select DRM_DISPLAY_HELPER diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 9cda2df21b88..d9be09e889e2 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include @@ -455,6 +458,7 @@ struct it6505 { struct delayed_work delayed_audio; struct it6505_audio_data audio; struct dentry *debugfs; + struct drm_dp_typec_switch_desc switch_desc; /* it6505 driver hold option */ bool enable_drv_hold; @@ -3346,12 +3350,105 @@ static void it6505_shutdown(struct i2c_client *client) it6505_lane_off(it6505); } +static void it6505_typec_ports_update(struct it6505 *it6505) +{ + struct drm_dp_typec_switch_desc switch_desc = it6505->switch_desc; + + /* Check if both ports available and do nothing to retain the current one */ + if (switch_desc.typec_ports[0].dp_connected && switch_desc.typec_ports[1].dp_connected) + return; + + if (switch_desc.typec_ports[0].dp_connected) + it6505->lane_swap = false; + else if (switch_desc.typec_ports[1].dp_connected) + it6505->lane_swap = true; +} + +static int it6505_typec_mux_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct drm_dp_typec_port_data *port_data = typec_mux_get_drvdata(mux); + struct it6505 *it6505 = (struct it6505 *) port_data->data; + struct device *dev = &it6505->client->dev; + struct drm_dp_typec_switch_desc switch_desc = it6505->switch_desc; + bool old_dp_connected, new_dp_connected; + + if (switch_desc.num_typec_switches == 1) + return 0; + + mutex_lock(&it6505->extcon_lock); + + old_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + port_data->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", + switch_desc.typec_ports[0].dp_connected, switch_desc.typec_ports[1].dp_connected); + + new_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + if (it6505->enable_drv_hold) { + dev_dbg(dev, "enable driver hold\n"); + goto unlock; + } + + it6505_typec_ports_update(it6505); + + if (!old_dp_connected && new_dp_connected) { + int ret = pm_runtime_get_sync(dev); + + /* + * pm_runtime_force_suspend() disables runtime PM when the + * system enters suspend state. But on system resume, mux_set + * can be triggered before pm_runtime_force_resume() re-enables + * runtime PM. This makes the bridge stay powered off if the + * downstream display is connected when the system is suspended. + * Handling the error here to make sure the bridge is powered + * on, and leave the PM runtime usage count incremented so + * the future runtime PM calls is balanced. + */ + if (ret < 0) + it6505_poweron(it6505); + + complete_all(&it6505->extcon_completion); + } + + if (old_dp_connected && !new_dp_connected) { + reinit_completion(&it6505->extcon_completion); + pm_runtime_put_sync(dev); + if (it6505->bridge.dev) + drm_helper_hpd_irq_event(it6505->bridge.dev); + memset(it6505->dpcd, 0, sizeof(it6505->dpcd)); + } + +unlock: + mutex_unlock(&it6505->extcon_lock); + return 0; +} + +static void it6505_unregister_typec_switches(struct it6505 *it6505) +{ + drm_dp_unregister_typec_switches(&it6505->switch_desc); +} + +static int it6505_register_typec_switches(struct device *dev, struct it6505 *it6505) +{ + struct device_node *port = of_graph_get_port_by_id(dev->of_node, 1); + + return drm_dp_register_typec_switches(dev, port, &it6505->switch_desc, + it6505, it6505_typec_mux_set); +} + static int it6505_i2c_probe(struct i2c_client *client) { struct it6505 *it6505; struct device *dev = &client->dev; struct extcon_dev *extcon; - int err, intp_irq; + int err, intp_irq, ret; it6505 = devm_kzalloc(&client->dev, sizeof(*it6505), GFP_KERNEL); if (!it6505) @@ -3371,11 +3468,24 @@ static int it6505_i2c_probe(struct i2c_client *client) if (PTR_ERR(extcon) == -EPROBE_DEFER) return -EPROBE_DEFER; if (IS_ERR(extcon)) { - dev_err(dev, "can not get extcon device!"); - return PTR_ERR(extcon); + if (PTR_ERR(extcon) != -ENODEV) + dev_warn(dev, "Cannot get extcon device: %ld\n", + PTR_ERR(extcon)); + it6505->extcon = NULL; + } else { + it6505->extcon = extcon; } - it6505->extcon = extcon; + ret = it6505_register_typec_switches(dev, it6505); + if (ret) { + if (ret != -ENODEV) + dev_warn(dev, "Didn't register Type-C switches, err: %d\n", + ret); + if (!it6505->extcon) { + dev_err(dev, "Both extcon and typec-switch are not registered.\n"); + return -EINVAL; + } + } it6505->regmap = devm_regmap_init_i2c(client, &it6505_regmap_config); if (IS_ERR(it6505->regmap)) { @@ -3447,6 +3557,7 @@ static void it6505_i2c_remove(struct i2c_client *client) it6505_debugfs_remove(it6505); it6505_poweroff(it6505); it6505_remove_edid(it6505); + it6505_unregister_typec_switches(it6505); } static const struct i2c_device_id it6505_id[] = { -- 2.39.0.314.g84b9a713c41-goog