From patchwork Tue Dec 24 23:10:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F645E77188 for ; Tue, 24 Dec 2024 23:10:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7BF0910E1B9; Tue, 24 Dec 2024 23:10:23 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vm1IUzbV"; dkim-atps=neutral Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by gabe.freedesktop.org (Postfix) with ESMTPS id 57CD010E1B9 for ; Tue, 24 Dec 2024 23:10:21 +0000 (UTC) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-5401b7f7141so4891982e87.1 for ; Tue, 24 Dec 2024 15:10:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081819; x=1735686619; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gkEAYK8kPNECxsGkRJpsJ7xiXmTY2irxwmm/stUUQ/U=; b=vm1IUzbV/3YpHhLGQPRdsnc6doAHPKcYWmsjHq40d8lJrM9hHENRysMFAGLdp6o8hS gaCtZAWPukN8jWDa0jmaqG27k71HbSX0kW/aqHI1xSV6v1kkkZlTxGmHUYDObmrYMSvB ZO6/9PSHPjvz1HtHyuxsXvwTJ7SrCMVoOwwyf9sUTUhcJvhdOZIerSr98mtEFhK3Rakt 4nEpgZQ9jHKeTrS5Y3OsodCKWlMwdhWibveO+L6PzK0UGIkbS27ctbi4j9IMrwNDb8Xj CgrC7e1BXU7BHvExUbZlPmU5qiPE2JiEVUuBdogWf7+ukxioJSvLIsdvtshe1gyIu6KH XQGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081819; x=1735686619; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gkEAYK8kPNECxsGkRJpsJ7xiXmTY2irxwmm/stUUQ/U=; b=RxcMnl8TIGQ6cA7i9yCK7cy/UyBfNB8OdX3F5PDcG1RMYA6y5X6HquNP/yAlDTKtz1 KcDxggtfLXIICJcZF6WKhQsGiYQP/5TvMe2sdmwOP1p24cNO1tfbeUNJnhX96OuK2nKh ESQcxfyLuDV5ZRPZvimzqxbe0bvVqR/YoiuKlI7xAOE1vYeHiuiPQALRj9IY8K15pyYF dbBAmcwOVGrcFsaB3DPTjJCp7K97gKxcCvtqRpcKOOI+Pv/lKV/Dfr024PQKldciRRhf NDd/nybIYhjm3jzZcrNSm2cAqZzryRFcaNPrzfPc3+CaSkMQtVJu7xrPHVOUZy3uD8x4 f8Hw== X-Gm-Message-State: AOJu0YzV3Wh7+P/8uaHqWsKcEGEtydQdO1BdKuDPqWhWRJxQCq2WrcBn 7+NlmIZ52ezaSYFDydKR2bTHsE3Bj61k8H0EVhPPKAZaeQJPn/tw9Z7ezO8iw4L4mlrZaF225p5 + X-Gm-Gg: ASbGncsBHrNqiwyo6AVFcJn2UUZT3AB4UD/KIrNvSlYMUTgULu5na64YtlFvgAt9AP0 zgW+37d2V7c4WM+ToIkSH87V82kIEbu/D3D/LZOWrYQMS2a8ye3IwlnAfUlZDpcxNqXquib8s6V 7EET8Zjt+GPcwB1UPcHxAzVdN10uCTc0/nq+6tdoAxgYfLpH2+XUQaR8ptEEetGvAu7kqzRnego J+bHxKxcXtjlEfjoCDRnN2U4G8tAXTzFo0MU+8/bAxJOP4XuiBM7IXjxgh7OvV0 X-Google-Smtp-Source: AGHT+IEwyLXiTl6HwqZYINQzprUx9IZAjXK9evHUTV0H4dLVrHUyChVy+Pe58BeM4nIcvMJsFNUKTA== X-Received: by 2002:a05:6512:239b:b0:53e:44a4:34e0 with SMTP id 2adb3069b0e04-5422953306amr6782564e87.16.1735081819558; Tue, 24 Dec 2024 15:10:19 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:18 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:09 +0200 Subject: [PATCH RFC/RFT 1/9] drm/connector: add CEC-related fields MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-1-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4628; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=zAP9ylKK8F/k8ADKJQaYiAs3G6twCNuwzluDDLOa0/w=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9VkF4oX+7gjkZP8Y1yKMqgeZkKR90iM2yAs HhTV8Tw6NqJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VQAKCRCLPIo+Aiko 1XUoCACouGUa5oAtjD5GnC3gjruGwotvNm5gGr85SrA2/2pOOxq9l+xKlniMFWQJUctZSR4hwUw z0FsPogNoXzjPlpIbcOy8l0yL2OqeY67nIRTP+dn2BPL6hu7Z/p1WLqJ+hZ65DN/FCYC2Wd4TrW 5qY5PssSUpxywdZIow7P62xhJvUcMleK8wob+tB9b4ObCb6IjBJDEdT3+3+JBfXP5aV5CgwrEUP 3uN3u9K4Xu4JgIDHBR2y9E0wMjOkPr5X71LPX8QRkhXC+eSJdFyqEtx2tZzgUR34lPLW8ZGf8xL ygyhLgFERD3wYyQXapYukJPLcrwhdQLUDKmWmX83FUAxvjvc X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" As a preparation to adding HDMI CEC helper code, add CEC-related fields to the struct drm_connector. Include both cec_adapter and cec_notifier, allowing drivers to select which one to use. The unregister callback is provided to let drivers unregister CEC-related data in a generic way without polluting drm_connector.c with dependencies on the CEC functions. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/drm_connector.c | 23 ++++++++++++++++++++++ include/drm/drm_connector.h | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 1383fa9fff9bcf31488453e209a36c6fe97be2f1..ef299733041e2c64bebd73c3fe21d4492bc07d3a 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -279,6 +279,7 @@ static int drm_connector_init_only(struct drm_device *dev, INIT_LIST_HEAD(&connector->probed_modes); INIT_LIST_HEAD(&connector->modes); mutex_init(&connector->mutex); + mutex_init(&connector->cec.mutex); mutex_init(&connector->eld_mutex); mutex_init(&connector->edid_override_mutex); mutex_init(&connector->hdmi.infoframes.lock); @@ -698,6 +699,26 @@ static void drm_mode_remove(struct drm_connector *connector, drm_mode_destroy(connector->dev, mode); } +/** + * drm_connector_cec_unregister - clean up CEC registration + * @connector: connector to cleanup + * + * Reverse corresponding CEC registration. This function is supposed to be + * called only by bridge drivers which need to handle CEC manually. Normally + * CEC adapter or notifier are automatically unregistered during drm_connector + * teardown. + */ +void drm_connector_cec_unregister(struct drm_connector *connector) +{ + mutex_lock(&connector->cec.mutex); + + if (connector->cec.unregister) + connector->cec.unregister(connector); + + mutex_unlock(&connector->cec.mutex); +} +EXPORT_SYMBOL(drm_connector_cec_unregister); + /** * drm_connector_cleanup - cleans up an initialised connector * @connector: connector to cleanup @@ -718,6 +739,8 @@ void drm_connector_cleanup(struct drm_connector *connector) platform_device_unregister(connector->hdmi_audio.codec_pdev); + drm_connector_cec_unregister(connector); + if (connector->privacy_screen) { drm_privacy_screen_put(connector->privacy_screen); connector->privacy_screen = NULL; diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index f13d597370a30dc1b14c630ee00145256052ba56..feecd02e7c698cc0c553b79048c9130f69121012 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -46,6 +46,7 @@ struct drm_property_blob; struct drm_printer; struct drm_privacy_screen; struct drm_edid; +struct cec_adapter; struct edid; struct hdmi_codec_daifmt; struct hdmi_codec_params; @@ -1832,6 +1833,41 @@ struct drm_connector_hdmi { } infoframes; }; +/** + * struct drm_connector_cec - DRM Connector CEC-related structure + */ +struct drm_connector_cec { + /** + * @mutex: protects all CEC-related fields + */ + struct mutex mutex; + + /** + * @adap: CEC adapter corresponding to the DRM connector. + */ + struct cec_adapter *adapter; + + /** + * @notifier: CEC notifier corresponding to the DRM connector. + */ + struct cec_notifier *notifier; + + /** + * @adap_unregister: unregister CEC adapter / notifier. + * + * The callback to unregister CEC adapter or notifier, so that the core + * DRM layer doesn't depend on the CEC_CORE. + */ + void (*unregister)(struct drm_connector *connector); + + /** + * @uninit_cec_cb: teardown CEC adapter + * + * Perform additional tasks to teardown the CEC adapter. + */ + void (*uninit_cec)(struct drm_connector *connector); +}; + /** * struct drm_connector - central DRM connector control structure * @@ -2253,6 +2289,11 @@ struct drm_connector { * @hdmi_audio: HDMI codec properties and non-DRM state. */ struct drm_connector_hdmi_audio hdmi_audio; + + /** + * @cec: CEC-related data. + */ + struct drm_connector_cec cec; }; #define obj_to_connector(x) container_of(x, struct drm_connector, base) @@ -2294,6 +2335,8 @@ int drm_connector_attach_encoder(struct drm_connector *connector, void drm_connector_cleanup(struct drm_connector *connector); +void drm_connector_cec_unregister(struct drm_connector *connector); + static inline unsigned int drm_connector_index(const struct drm_connector *connector) { return connector->index; From patchwork Tue Dec 24 23:10:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920550 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 78160E7718D for ; Tue, 24 Dec 2024 23:10:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D22F810E2A1; Tue, 24 Dec 2024 23:10:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="gvRhpd2Q"; dkim-atps=neutral Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1337610E2A1 for ; Tue, 24 Dec 2024 23:10:24 +0000 (UTC) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-3003943288bso61443261fa.0 for ; Tue, 24 Dec 2024 15:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081822; x=1735686622; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KX9VHwXLWT0YXb/R/ow61sjiLOZURcf2NMX0NiYRIEM=; b=gvRhpd2Qpwbx/QElG78JlmiCKWB6LZ0N4IoFXYJ0z4Mb2+USSfZhkD26smmvydQrs4 RSUvRxiJgJ2NTSrJ2j9irWMsfZ1PJzfyNIq1a4QfcYuEuU8GzDSq8jBsIs7SBul5uGbB sCPIvHEUeoQkMzuLVgaxo8oam9nqbEzCGHw8R2AxQI1Sh6w9ATRko9FDacLwK8jMcitF yejLancvd+U5jjwqZqBkz1dbHYOwftEsy5XO42CQvN9WLkD3twegh391fLy55/Ic7cbP OYma0g5X2dxvTF/nCvO+3vnUYnFxVkEmqt4yFswbQi7ra1RUQUQL2iKkFdEKXmfxdju0 rgwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081822; x=1735686622; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KX9VHwXLWT0YXb/R/ow61sjiLOZURcf2NMX0NiYRIEM=; b=Z2iFlsuwjU4jfeb6vfwR04DepOJQ8h+pWlQXLfhi7lsIqWcP8U8I4psAvvdo/UOPqJ JyWh2Xo5YXG+snOA+TG8LK4t/nBmjOtRdDMOR3Yxy4OG0eG+PxNekPns6rmUr0wLZnJX RMtI2ZWh8WCZvrh82oFRk9V+AfOeoJ6cYTdRd0FCkS2xUnyKCOovY7M+yLFfaG7CayOU zYcj+amnfbBVucJSGB5Z1yEvKEiwMRQOYBtzVm6IV1CH9ubFzR8lFlN2xTDmzaE72zP8 cydyuPk3cmVPZo8jOL/Bbra0iGt/DiVQfIqH17ltlicLqdqVDfL2PLvdIEiDCsXIN1r0 jWxA== X-Gm-Message-State: AOJu0YzzVyJ3KSRvQK0Q01WyLQ3F8PDDeO0r9RiS/UPtknjrVXwhn+PG fXcdgcLzhCGS1MeKfR5csxX7lhVNjEExbNzsHyzm+NYLifF3ysCL8t+WWrVAhMM= X-Gm-Gg: ASbGncu7Se8RdOODwDBH2Y6bbR1HNQpKXlTU+Ngi+IZ2RbTL8FN+SUGU3poP+c1iIkN u1qUAB1GPFC4Hf8QedhaO4hiN9sJypu5otBlfqxrc/tfLhfIFGQG1fQOYcBlBvRft1nJvEP9rvI okx2vjaPpMLkJjFXN8aSoor9leD82zXBqfYtrR0U491JPrhozufoCzZrzji3s2Osmudfkqv5BBg DBj7wycHjKEqyppceaCjXNflVDQVkSXUH4oTsxZ9BzBUdFjzXljPQG+U1R24OwQ X-Google-Smtp-Source: AGHT+IG972DXnJb1escms0CYD4KMALk35eIDWaRXFeinstt5fliin23jsUMKxcsnmxW5LlakxR0NMQ== X-Received: by 2002:a05:6512:3d16:b0:53e:ca48:776e with SMTP id 2adb3069b0e04-54229562a17mr6138588e87.36.1735081821954; Tue, 24 Dec 2024 15:10:21 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:20 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:10 +0200 Subject: [PATCH RFC/RFT 2/9] drm/display: add CEC helpers code MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-2-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=7698; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=TXbfNS4WNhmW98nls+Q/o0v6k1eUVeztIzkOAy5ZwIE=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9VzbgIsXwGp4Xf8rPMw0gjWs+nKOS9ukA/L ma5Akr/5EWJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VQAKCRCLPIo+Aiko 1WpUB/9yAcMX4COUKb5mTuTykvEREiVKw8IKEoJLLJbNGnPsoXsO0WELpmQOU0ULFA5lP+J04wS 2YsT60IOP7OboojHe+pvH9LXKj2hSabm0efZJZBA2YyciRno0vfoUSwUF/2UPB2Hh+myDIHvA5H RWpkR6EeKCroYhXk+fT7CfghC2cg5qgM2+qBNXhtwEqH6K7n7recDcR63nxbly9MZp3ICdGJqvE 3kGu7WLrvmPRpKSCgHPh57zCkPy5rewL34dtl1dWRegtysd784AiP7eY/OA2iam1fWYwpl88s16 9Zn2VwYXyPnRRmFmJhfkmozesPCM3gcUSIuB5FbeeQgu9zTD X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add generic CEC helpers to be used by HDMI drivers. Both notifier and and adapter are supported for registration. Once registered, the driver can call common set of functions to update physical address, to invalidate it or to unregister CEC data. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/display/Kconfig | 5 + drivers/gpu/drm/display/Makefile | 2 + drivers/gpu/drm/display/drm_hdmi_cec_helper.c | 145 ++++++++++++++++++++++++++ include/drm/display/drm_hdmi_cec_helper.h | 38 +++++++ 4 files changed, 190 insertions(+) diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kconfig index 8d22b7627d41f7bc015decf24ae02a05bc00f055..49da9b768acf3e5f84f2cefae4bb042cfd57a50c 100644 --- a/drivers/gpu/drm/display/Kconfig +++ b/drivers/gpu/drm/display/Kconfig @@ -82,6 +82,11 @@ config DRM_DISPLAY_HDMI_AUDIO_HELPER DRM display helpers for HDMI Audio functionality (generic HDMI Codec implementation). +config DRM_DISPLAY_HDMI_CEC_HELPER + bool + help + DRM display helpers for HDMI CEC implementation. + config DRM_DISPLAY_HDMI_HELPER bool help diff --git a/drivers/gpu/drm/display/Makefile b/drivers/gpu/drm/display/Makefile index b17879b957d5401721396e247fa346387cf6c48a..2cd078e2b81c1a9e6b336c4187b444bcb8a50e51 100644 --- a/drivers/gpu/drm/display/Makefile +++ b/drivers/gpu/drm/display/Makefile @@ -16,6 +16,8 @@ drm_display_helper-$(CONFIG_DRM_DISPLAY_DSC_HELPER) += \ drm_display_helper-$(CONFIG_DRM_DISPLAY_HDCP_HELPER) += drm_hdcp_helper.o drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_AUDIO_HELPER) += \ drm_hdmi_audio_helper.o +drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_CEC_HELPER) += \ + drm_hdmi_cec_helper.o drm_display_helper-$(CONFIG_DRM_DISPLAY_HDMI_HELPER) += \ drm_hdmi_helper.o \ drm_scdc_helper.o diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c new file mode 100644 index 0000000000000000000000000000000000000000..2a3832e68232fa3b839a3c7457b2013779cada86 --- /dev/null +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright (c) 2024 Linaro Ltd + */ + +#include +#include +#include + +#include + +#include +#include + +static void drm_connector_hdmi_cec_adapter_unregister(struct drm_connector *connector) +{ + cec_unregister_adapter(connector->cec.adapter); + connector->cec.adapter = NULL; + connector->cec.unregister = NULL; +} + +int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector, + const struct cec_adap_ops *ops, + const char *name, + u8 available_las, + int (*init_cec)(struct drm_connector *connector), + void (*uninit_cec)(struct drm_connector *connector), + struct device *dev) +{ + struct cec_connector_info conn_info; + struct cec_adapter *cec_adap; + int ret; + + mutex_lock(&connector->cec.mutex); + + if (connector->cec.unregister) { + ret = -EBUSY; + goto err_unlock; + } + + cec_adap = cec_allocate_adapter(ops, connector, name, + CEC_CAP_DEFAULTS | CEC_CAP_CONNECTOR_INFO, + available_las); + ret = PTR_ERR_OR_ZERO(cec_adap); + if (ret < 0) + goto err_unlock; + + cec_fill_conn_info_from_drm(&conn_info, connector); + cec_s_conn_info(cec_adap, &conn_info); + + connector->cec.adapter = cec_adap; + + ret = init_cec(connector); + if (ret < 0) + goto err_delete_adapter; + + ret = cec_register_adapter(cec_adap, dev); + if (ret < 0) + goto err_delete_adapter; + + connector->cec.unregister = drm_connector_hdmi_cec_adapter_unregister; + connector->cec.uninit_cec = uninit_cec; + mutex_unlock(&connector->cec.mutex); + + return 0; + +err_delete_adapter: + cec_delete_adapter(cec_adap); + + connector->cec.adapter = NULL; + +err_unlock: + mutex_unlock(&connector->cec.mutex); + + return ret; +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_adapter_register); + +static void drm_connector_hdmi_cec_notifier_unregister(struct drm_connector *connector) +{ + cec_notifier_conn_unregister(connector->cec.notifier); + connector->cec.notifier = NULL; + connector->cec.unregister = NULL; +} + +int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector, + const char *port_name, + struct device *dev) +{ + struct cec_connector_info conn_info; + struct cec_notifier *notifier; + int ret; + + mutex_lock(&connector->cec.mutex); + + if (connector->cec.unregister) { + ret = -EBUSY; + goto err_unlock; + } + + cec_fill_conn_info_from_drm(&conn_info, connector); + + notifier = cec_notifier_conn_register(dev, port_name, &conn_info); + if (!notifier) { + ret = -ENOMEM; + goto err_unlock; + } + + connector->cec.notifier = notifier; + connector->cec.unregister = drm_connector_hdmi_cec_notifier_unregister; + + mutex_unlock(&connector->cec.mutex); + + return 0; + +err_unlock: + mutex_unlock(&connector->cec.mutex); + + return ret; +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_register); + +void drm_connector_hdmi_cec_phys_addr_invalidate(struct drm_connector *connector) +{ + mutex_lock(&connector->cec.mutex); + + cec_phys_addr_invalidate(connector->cec.adapter); + cec_notifier_phys_addr_invalidate(connector->cec.notifier); + + mutex_unlock(&connector->cec.mutex); +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_phys_addr_invalidate); + +void drm_connector_hdmi_cec_phys_addr_set(struct drm_connector *connector) +{ + mutex_lock(&connector->cec.mutex); + + cec_s_phys_addr(connector->cec.adapter, + connector->display_info.source_physical_address, false); + cec_notifier_set_phys_addr(connector->cec.notifier, + connector->display_info.source_physical_address); + + mutex_unlock(&connector->cec.mutex); +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_phys_addr_set); diff --git a/include/drm/display/drm_hdmi_cec_helper.h b/include/drm/display/drm_hdmi_cec_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..75e6476498a31a05af5a813f1df138e7786520be --- /dev/null +++ b/include/drm/display/drm_hdmi_cec_helper.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef DRM_DISPLAY_HDMI_CEC_HELPER +#define DRM_DISPLAY_HDMI_CEC_HELPER + +#include + +struct drm_connector; + +struct cec_adap_ops; +struct cec_adapter; +struct device; + +int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector, + const struct cec_adap_ops *ops, + const char *name, + u8 available_las, + int (*init_cec)(struct drm_connector *connector), + void (*uninit_cec)(struct drm_connector *connector), + struct device *dev); + +int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector, + const char *port_name, + struct device *dev); + +/* + * These functions are used by the state helper, so we end up linking to the + * same module. Define stubs to simplify the code. + */ +#ifdef CONFIG_DRM_DISPLAY_HDMI_CEC_HELPER +void drm_connector_hdmi_cec_phys_addr_invalidate(struct drm_connector *connector); +void drm_connector_hdmi_cec_phys_addr_set(struct drm_connector *connector); +#else +static inline void drm_connector_hdmi_cec_phys_addr_invalidate(struct drm_connector *connector) {} +static inline void drm_connector_hdmi_cec_phys_addr_set(struct drm_connector *connector) {} +#endif + +#endif From patchwork Tue Dec 24 23:10:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 22714E77188 for ; Tue, 24 Dec 2024 23:10:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0EED210E2AD; Tue, 24 Dec 2024 23:10:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="lPppI7KK"; dkim-atps=neutral Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4E54510E2A1 for ; Tue, 24 Dec 2024 23:10:26 +0000 (UTC) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5401c52000dso6193028e87.3 for ; Tue, 24 Dec 2024 15:10:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081824; x=1735686624; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+lCA58zl22vmnlxhnNGgCm+vw5K42PZ70YAVZOIIBqQ=; b=lPppI7KK96tQ7yajKiN54qlJ1uvuc0/Ijs/V11tFG1sGDKjD90VaS2sXz1IsLxpvMU mDWL4XbP8sk5Fl8GGJB7OGnk26X8lL6jDgZrSqy865rcIgvf9WOBIpAIuR3TSxf3zuCQ 43rylfDS8cJZRpuJvi3X+gNXq9ydPu/ds0g2esAuv1UxSnMuG1EBxp/riNZVHMVa64AS qbKhQn29x+nZmCQIeu5M18l5fJGrOFh9U4ihers3bRGJzEB3wwi4sG/OrIlKUOkkhhrE KCpZw2cXgrTGp6yh70FoqkWiCR/oe+OB7J5m94Aw3F0Tp4ACwsRd7QfUmFvw0qhJ4lSN etKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081824; x=1735686624; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+lCA58zl22vmnlxhnNGgCm+vw5K42PZ70YAVZOIIBqQ=; b=eK4G4FwxVFBvwbzpQnPjAzr04PMUS6AGmsObDfOoFc7H4uS2HxYWnKnFr5VSzlAnjX Uoe2/cNirfjYzW/P+nfIcgx1Ye9Tc3QsrlDu4iiwlfIQ64hPJAqh+if2a+GoZ3TODQrt KLt9KZRsAuNGBstNmHKHsIMK8XOq/I8ZeQv/ksmt8T2nGw4+Jovd76NkwMV6fTp0EySt 5ZlqSnmRW6MpEDxfghrg9Zz9Jz7BwPa5inTIAn3JT2YT8CRhW8ZRj57gs+o3qHIM/eXx SJzC60lVwB7/+4z/pZaa7pIdT5nn1E3idw9yUF0YSWpk8248Wm+9YztwK7xK8/NNo7ek wTYQ== X-Gm-Message-State: AOJu0YyRVxcyQe+WjPMQpk6BVx7Uipl0e5QcBHXFr5eW4nTQ+/oI8Bmr Ewlqx2ST1z7Jq1BY+3LUiR0APnawdvI7TZyIrNNTIQmnulR2HpsYppr9NrsEWlQ= X-Gm-Gg: ASbGncumQjMOWp1F9ulFXQ8082UQ0BlPuisPcIjxAhJkc/0FO4pwSBPvh0+hwHt0+p3 X2NfqdzAxllkYTELTQbVFwWEJci/gg97yQ6+l1qx+HRRs2B7xWtjMu5hoJv+67epd6yi8jIiRlI yt09OyGjrYPGxuCOCSmIzywiO8NYSx4cot4E9zcBrwG1GrFIjYrUDdTBvAUUQJX34YxCJL7Iy71 HoVE27nwLjnXKYrQu0q0az+ZrhmrQomGA2naEbDOO+S8SlriESt3l6mzZKZJ1ME X-Google-Smtp-Source: AGHT+IEqVd0zSQub31oV2g65K9x/pjyEkinx0KbkdvnnKPyCFsvSxarjDL/hYDMYWbVAGaCyIhNstA== X-Received: by 2002:a05:6512:3a90:b0:53e:3a73:6ddc with SMTP id 2adb3069b0e04-5422953c384mr5965630e87.33.1735081824409; Tue, 24 Dec 2024 15:10:24 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:23 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:11 +0200 Subject: [PATCH RFC/RFT 3/9] drm/display: hdmi-state-helper: handle CEC physicall address MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-3-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1748; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=j8/VCHgmb1raNVFOKXZe7b5PFQfOvnrzhw7RbdPY+gs=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9V7pF8AmPHdoSaF6VBQtkkwzHsayf+rKMgP P+HfcDklDCJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VQAKCRCLPIo+Aiko 1S0pCACOQ4XE7VYVMUKjPFSrgvVqFk9iSmwZpK8Dtwv1Vy08pv5j1GB1fJC9MZhVRUd9KMjlJF1 wGd0R4RLFh6kJ0I0o1dWtmUwyh02bpZISXzErwCRlnJsW+i+cCO9WpN6aTvGd0Ry4gq/A+EK9n5 kP6n9tGPGZVNTx4akZwBFj8elQ3k+/DXRmtNfKevHmvfpETzPh3dvIyqV43jebnQnAvVhiifQB7 ttYx2pyDX6Jyc+/8h9dOyBTjONVQA2DR9ZlnYN34Lx+MN8LDk03d1kcXBA3h0qNv1Xnhe15k9Tg ks5YVeFi//+jfUz+he55nKsHSgYld+YXwYQ7AhvCYu5/yOv9 X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Call HDMI CEC helpers in order to update physical address of the adapter. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/display/drm_hdmi_state_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/display/drm_hdmi_state_helper.c b/drivers/gpu/drm/display/drm_hdmi_state_helper.c index cfc2aaee1da08a103cbf933c891d5cc31b0886a8..b060cc265221049f5509e852903bd0a4ca651e80 100644 --- a/drivers/gpu/drm/display/drm_hdmi_state_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_state_helper.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -786,8 +787,9 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector, const struct drm_edid *drm_edid; if (status == connector_status_disconnected) { - // TODO: also handle CEC and scramber, HDMI sink disconnected. + // TODO: also handle scramber, HDMI sink disconnected. drm_connector_hdmi_audio_plugged_notify(connector, false); + drm_connector_hdmi_cec_phys_addr_invalidate(connector); } if (connector->hdmi.funcs->read_edid) @@ -800,8 +802,9 @@ drm_atomic_helper_connector_hdmi_update(struct drm_connector *connector, drm_edid_free(drm_edid); if (status == connector_status_connected) { - // TODO: also handle CEC and scramber, HDMI sink is now connected. + // TODO: also handle scramber, HDMI sink is now connected. drm_connector_hdmi_audio_plugged_notify(connector, true); + drm_connector_hdmi_cec_phys_addr_set(connector); } } From patchwork Tue Dec 24 23:10:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 177C3E77188 for ; Tue, 24 Dec 2024 23:10:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92DF910E2AF; Tue, 24 Dec 2024 23:10:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="J3DQrRRQ"; dkim-atps=neutral Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by gabe.freedesktop.org (Postfix) with ESMTPS id AFF7A10E2AF for ; Tue, 24 Dec 2024 23:10:28 +0000 (UTC) Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-3011c7b39c7so62372151fa.1 for ; Tue, 24 Dec 2024 15:10:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081827; x=1735686627; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=S7U9m2UAtvR0vrRqhfic+TwuHs1eVqtQ6Xbp0YLelcE=; b=J3DQrRRQjvBO1o/Q/5w9SGD3mMjDYjAmYyO3hLmXBu5x1HHCfWTmqZ78u+MgJAL/bh WufObg84fXu95WscsDldjhhYE3V0UZi1qjCdrUkHrPvGOCR8Afn2I2rxI/vdvAcPluh1 O4e+2ae+EwJ0vVwaK33ALff3hYyfeczlPECeHNh+S440Km8h9CMUPqsHu9sJA+YtTM31 PEu8KjdVh8TQHMVVnYvSz40qVPcyao0x/d8UsARD0QxbjxKWbfU6kHWLL5wsTspVJgVO huG73MaQLheRgKYhqThLPrRPZ2G5KEsgQQfoMWw5jIitG4YPIPKI7C+NsbzDb7+WzKEc JXxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081827; x=1735686627; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S7U9m2UAtvR0vrRqhfic+TwuHs1eVqtQ6Xbp0YLelcE=; b=afFWIj81pKILa2zZkpcQTwBHIjkvKenMW9brThs+CuHbBEWyuFVZMIag1yQu4ak/JD VU9kHQB8pDI5iox6UgpA4yBZqYa3tYFy8sQ98277WLPOKwQ2sLz2OccFwpcMDdOkea+S kEk32DpQRUgHMl/qkNFYEFEXyi4+lBuG/HZ6b850PrvzD/4KfLNFLTwZzilM+6cOqmiW Q/42QAlNxY0rkEnCEsxbyeH56gVAXlRwywuvHl7KOrowrZE6YNmLlko7hZWv5vYDRSvq wfxHub8r8SFyJZ0mbuOhPD5ODC5d6c6XU1L3zkB7QwvHnqelKblwm+sin3OlzzpBqHwj pUFg== X-Gm-Message-State: AOJu0YzGs8kfENR3ZgernMZNm/uJbvHyENCcDRJoFh1wXaLAWzZHZeRF RO9t0MNZAEKhsCz+GaMYgM/biQjPhqN/VvAE0nRQRE4rYpa0Xf5COyKwDuXZdwU= X-Gm-Gg: ASbGnctk0+QtEHFquCLMltDXIGsR7n4DRyxwCzh8QZbttsAkmrNqyKoWZ7ulfCZTUL8 WaoGTR+CI6IhkyAss8ehuNQnpGzevhpLeSNy2kpQkglZcIy1EBAHu3Sru5MA0xaYawfTPkXYbyj ndnf4jhPxXdHrRQ5EekmB7SJ4Ux9s5zTyPmH1IV2evYprdEJ92UZHVFFYQUK28cr59lvjAS2CFx 4raZigs7rufMd/5n8ZAe7bH4T+DJx5aGIVwqoFybqQkKxTYRmotL/t1pbEI/ryU X-Google-Smtp-Source: AGHT+IHen8WkbHetDjZQUHCGpSfWfZ2iTSRPneMJChbm/PXpW+1mtg547OwR/8sNyzK9Lh4FmC+TOA== X-Received: by 2002:a05:6512:3f20:b0:540:1c8e:b3eb with SMTP id 2adb3069b0e04-54229561a02mr5987873e87.44.1735081826847; Tue, 24 Dec 2024 15:10:26 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:25 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:12 +0200 Subject: [PATCH RFC/RFT 4/9] drm/vc4: hdmi: switch to generic CEC helpers MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-4-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8623; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=5qzeIIyAF5KQwVBCVNabcKuWk55QXl7IXd/PJzxgS7A=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9V94IWHdtqnQ/XR0V2LAXDTDF6YL/gnHeH7 2vDr06yQQqJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VQAKCRCLPIo+Aiko 1Qd/B/4pOMGvhxbD5fGVxfcAFDZ86b5wCbg1KYCV7feH72+tNDtUUaE6GvGJiAfKdsgADhc7zr+ QfcErHhSE6hwtTtSFXpIF1gRZ8ZHAbzKJpjB5bJd4/94ZcH0kA5kGkHgYF21HLU7egiEg+NwprW WyeS36N6fkdBtW3+7Lz21pufyh8Yjw/jTTrWxwkEnGdfioRVkGi/FS3hbfPFDGaPSkDfYERe67m cE5hHfQ/9YlPFsl7WhHJU8ab8WEvCejUeLxXNCMuK7WEksnmuJPtTglBXu11Pv67CHtlMu+p5R4 WWuLmZDlAHQCEIB4iz4sU14sGJKF1PIHEl7LIH3JDOtNBamz X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Switch VC4 driver to using CEC helpers code, simplifying hotplug and registration / cleanup. The existing vc4_hdmi_cec_release() is kept for now. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/vc4/Kconfig | 1 + drivers/gpu/drm/vc4/vc4_hdmi.c | 92 ++++++++++++++++++++---------------------- drivers/gpu/drm/vc4/vc4_hdmi.h | 1 - 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/vc4/Kconfig b/drivers/gpu/drm/vc4/Kconfig index 6cc7b7e6294a1bfa54137ca65296cd47e46b1e1e..360fbe755951cc40fecb4f9d643a096a6cf92b8e 100644 --- a/drivers/gpu/drm/vc4/Kconfig +++ b/drivers/gpu/drm/vc4/Kconfig @@ -34,6 +34,7 @@ config DRM_VC4_HDMI_CEC bool "Broadcom VC4 HDMI CEC Support" depends on DRM_VC4 select CEC_CORE + select DRM_DISPLAY_HDMI_CEC_HELPER help Choose this option if you have a Broadcom VC4 GPU and want to use CEC. diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 47d9ada98430634cfd8c1e21c2a4d00d501bab7e..3086c2ad3bb2e8fafdc1f37ba985aa5785d49f9a 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -32,6 +32,7 @@ */ #include +#include #include #include #include @@ -400,16 +401,8 @@ static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi, * the lock for now. */ - if (status == connector_status_disconnected) { - cec_phys_addr_invalidate(vc4_hdmi->cec_adap); - return; - } - drm_atomic_helper_connector_hdmi_hotplug(connector, status); - cec_s_phys_addr(vc4_hdmi->cec_adap, - connector->display_info.source_physical_address, false); - if (status != connector_status_connected) return; @@ -2388,7 +2381,7 @@ static irqreturn_t vc4_cec_irq_handler_rx_thread(int irq, void *priv) struct vc4_hdmi *vc4_hdmi = priv; if (vc4_hdmi->cec_rx_msg.len) - cec_received_msg(vc4_hdmi->cec_adap, + cec_received_msg(vc4_hdmi->connector.cec.adapter, &vc4_hdmi->cec_rx_msg); return IRQ_HANDLED; @@ -2399,14 +2392,14 @@ static irqreturn_t vc4_cec_irq_handler_tx_thread(int irq, void *priv) struct vc4_hdmi *vc4_hdmi = priv; if (vc4_hdmi->cec_tx_ok) { - cec_transmit_done(vc4_hdmi->cec_adap, CEC_TX_STATUS_OK, + cec_transmit_done(vc4_hdmi->connector.cec.adapter, CEC_TX_STATUS_OK, 0, 0, 0, 0); } else { /* * This CEC implementation makes 1 retry, so if we * get a NACK, then that means it made 2 attempts. */ - cec_transmit_done(vc4_hdmi->cec_adap, CEC_TX_STATUS_NACK, + cec_transmit_done(vc4_hdmi->connector.cec.adapter, CEC_TX_STATUS_NACK, 0, 2, 0, 0); } return IRQ_HANDLED; @@ -2566,7 +2559,8 @@ static irqreturn_t vc4_cec_irq_handler(int irq, void *priv) static int vc4_hdmi_cec_enable(struct cec_adapter *adap) { - struct vc4_hdmi *vc4_hdmi = cec_get_drvdata(adap); + struct drm_connector *connector = cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); struct drm_device *drm = vc4_hdmi->connector.dev; /* clock period in microseconds */ const u32 usecs = 1000000 / CEC_CLOCK_FREQ; @@ -2633,7 +2627,8 @@ static int vc4_hdmi_cec_enable(struct cec_adapter *adap) static int vc4_hdmi_cec_disable(struct cec_adapter *adap) { - struct vc4_hdmi *vc4_hdmi = cec_get_drvdata(adap); + struct drm_connector *connector = cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); struct drm_device *drm = vc4_hdmi->connector.dev; unsigned long flags; int idx; @@ -2677,7 +2672,8 @@ static int vc4_hdmi_cec_adap_enable(struct cec_adapter *adap, bool enable) static int vc4_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 log_addr) { - struct vc4_hdmi *vc4_hdmi = cec_get_drvdata(adap); + struct drm_connector *connector = cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); struct drm_device *drm = vc4_hdmi->connector.dev; unsigned long flags; int idx; @@ -2706,7 +2702,8 @@ static int vc4_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 log_addr) static int vc4_hdmi_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, u32 signal_free_time, struct cec_msg *msg) { - struct vc4_hdmi *vc4_hdmi = cec_get_drvdata(adap); + struct drm_connector *connector = cec_get_drvdata(adap); + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); struct drm_device *dev = vc4_hdmi->connector.dev; unsigned long flags; u32 val; @@ -2757,62 +2754,64 @@ static const struct cec_adap_ops vc4_hdmi_cec_adap_ops = { static void vc4_hdmi_cec_release(void *ptr) { - struct vc4_hdmi *vc4_hdmi = ptr; + struct drm_connector *connector = ptr; - cec_unregister_adapter(vc4_hdmi->cec_adap); - vc4_hdmi->cec_adap = NULL; + drm_connector_cec_unregister(connector); } -static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) +static int vc4_hdmi_cec_init(struct drm_connector *connector) { - struct cec_connector_info conn_info; + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); struct platform_device *pdev = vc4_hdmi->pdev; struct device *dev = &pdev->dev; int ret; - if (!of_property_present(dev->of_node, "interrupts")) { - dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); - return 0; - } - - vc4_hdmi->cec_adap = cec_allocate_adapter(&vc4_hdmi_cec_adap_ops, - vc4_hdmi, - vc4_hdmi->variant->card_name, - CEC_CAP_DEFAULTS | - CEC_CAP_CONNECTOR_INFO, 1); - ret = PTR_ERR_OR_ZERO(vc4_hdmi->cec_adap); - if (ret < 0) - return ret; - - cec_fill_conn_info_from_drm(&conn_info, &vc4_hdmi->connector); - cec_s_conn_info(vc4_hdmi->cec_adap, &conn_info); - if (vc4_hdmi->variant->external_irq_controller) { ret = devm_request_threaded_irq(dev, platform_get_irq_byname(pdev, "cec-rx"), vc4_cec_irq_handler_rx_bare, vc4_cec_irq_handler_rx_thread, 0, "vc4 hdmi cec rx", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; ret = devm_request_threaded_irq(dev, platform_get_irq_byname(pdev, "cec-tx"), vc4_cec_irq_handler_tx_bare, vc4_cec_irq_handler_tx_thread, 0, "vc4 hdmi cec tx", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; } else { ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0), vc4_cec_irq_handler, vc4_cec_irq_handler_thread, 0, "vc4 hdmi cec", vc4_hdmi); if (ret) - goto err_delete_cec_adap; + return ret; } - ret = cec_register_adapter(vc4_hdmi->cec_adap, &pdev->dev); + return 0; +} + +static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) +{ + struct platform_device *pdev = vc4_hdmi->pdev; + struct device *dev = &pdev->dev; + int ret; + + if (!of_property_present(dev->of_node, "interrupts")) { + dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); + return 0; + } + + ret = drm_connector_hdmi_cec_adapter_register(&vc4_hdmi->connector, + &vc4_hdmi_cec_adap_ops, + vc4_hdmi->variant->card_name, + 1, + vc4_hdmi_cec_init, + NULL, + &pdev->dev); if (ret < 0) - goto err_delete_cec_adap; + return ret; /* * NOTE: Strictly speaking, we should probably use a DRM-managed @@ -2842,14 +2841,9 @@ static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) return ret; return 0; - -err_delete_cec_adap: - cec_delete_adapter(vc4_hdmi->cec_adap); - - return ret; } #else -static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) +static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) { return 0; } @@ -3271,7 +3265,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) if (ret) goto err_put_runtime_pm; - ret = vc4_hdmi_cec_init(vc4_hdmi); + ret = vc4_hdmi_cec_register(vc4_hdmi); if (ret) goto err_put_runtime_pm; diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h index e3d989ca302b72533c374dfa3fd0d5bd7fe64a82..5acbe27fb57659d02f32ca571dd3ded4a1a0d9dc 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h @@ -146,7 +146,6 @@ struct vc4_hdmi { */ bool disable_wifi_frequencies; - struct cec_adapter *cec_adap; struct cec_msg cec_rx_msg; bool cec_tx_ok; bool cec_irq_was_rx; From patchwork Tue Dec 24 23:10:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 23AB0E77188 for ; Tue, 24 Dec 2024 23:11:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9EAE910E2B1; Tue, 24 Dec 2024 23:11:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="o9TcrQYe"; dkim-atps=neutral Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0080710E2B1 for ; Tue, 24 Dec 2024 23:11:30 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-30167f4c1deso52030791fa.1 for ; Tue, 24 Dec 2024 15:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081829; x=1735686629; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=r1EY0TAniKnLpFn4xNvyIctQ/nFp584TbFvXHwDHEIc=; b=o9TcrQYeuWcW65q6+SBbSfXRLxPRh+1/7Rvq11UOSLTJEKCtxb8lxfwPVLOqKW6RER hz9ICxlBEca+8jVus7UAIXZ/KkG72SBInGQUcnB3Dv2qh0EUjFxWiyVw714wHkBzxfIu 99fb/Neb1jRrp1mNpudhFM9fKurIQAQLmZhWZRhLQ4e+PvohTlmh9QtWN2KXKwV+1aRm Ch2ASzhpkEqqPy9/+4SBi3zNJdfe6F3+E7gbdjex4Onns6pz90dJttY6qvfyBgyeI2nn Wp7apjhmIAHam+kaNW3PKlAnVfyR0v3d/Fn8Zmf8cAhTjtQ6+wod2kxWR6bBI9GP0366 IZ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081829; x=1735686629; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r1EY0TAniKnLpFn4xNvyIctQ/nFp584TbFvXHwDHEIc=; b=Ll80iRsTAnEAZ7LjuxN+6/3AizNSOsZwKnk+HOZmQ2M8Ly/fB8FujAcpBSNPVEVjNl BSyOOgJuobHDg1/A35XQCBDz+UBjcJXCN4dFcGmDGKsJZWAuI7CYrJm1I5JpHG1hYSDU FHcG/N3Lgxm1/Vssc66UTJjZ4YPvK/YBqKZdULa1VkmOVZd9aU3SzaDjVJqwbSyAbT3S c6ABr2qkgtWs18BjudePtuBZdbkBVyTJ5Lfb6pUVBNJeSaYF9G/OGGVn15WbiAo5/eva iyjoA3C4p8MQOO3ZYleLkMYCSuR2vJBWILCE0Cpipa1jLncnvuWLEoltOllRjddia3Jq FwJA== X-Gm-Message-State: AOJu0Yx2FqIu+PFqLuqVmI5kdog+Mus4F882TVf+QC3F4qHISZyxcQCm 3jYQ2xluqQ6bDMGlcVkRXWHrdq9eQ68qMdAEvroCk0du+VKMds2dm102xyiOQ2U= X-Gm-Gg: ASbGnctAv9Zxo61hLeO5f0nQM3zsV773eiogMvo+OflJYLLQdp2DBiS59ex5r11y0K2 lijk0fp21ziLR4euPR2plVToHb+T6rrA41Fj9nhpMPiHn5dza0uIXGp+IO8T+XGgZOH0f1eTX8e M56+RZJAbuRazUMgOh55pRgReoUy42TbyKGYxGezLHEgtONpt4H9llg1tyuYIZe56YWNz3moLgC s2hCRpX2doMY6LwOvKeD9OZf6T/d9pGpF9SeHkccoYdS2VAT5ZiP2jERw3zZ2Lx X-Google-Smtp-Source: AGHT+IEhSnvY1Lvr+9QANPt7qjpETgM45/cQFbDwGgyPmxoRhRX07yjNQMX95QCriBppU0wUr6ahEA== X-Received: by 2002:a05:6512:6411:b0:542:29a8:e8c7 with SMTP id 2adb3069b0e04-54229a8edcemr6282315e87.3.1735081829327; Tue, 24 Dec 2024 15:10:29 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:27 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:13 +0200 Subject: [PATCH RFC/RFT 5/9] drm/vc4: hdmi: drop separate CEC unregistration MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-5-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3327; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=bpU/QTzs/6e35Bs6BI4kFzNjxwYaRMD/cnt3/GPJ2Gc=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ3q2fWhpzI+yzW89hZV2uz5qz/xw+5u+yrIJn75LxgcF3 U4/6LCuk9GYhYGRi0FWTJHFp6Blasym5LAPO6bWwwxiZQKZwsDFKQAT+XyN/Z+VcF/BYY0t5Rre a57rHwxZsEp5yYupEcHHj4nent/NHdIaqsT9fl3bqYjbB4r4nGIeWjBEW9zQdorKOptrw7XVYFv ltry/6Y7B9zvuL+142RlQWeb/4vX/IDfzq+FXFbQbj3QuecP/5FiH57ON+ftvGy7p0+3l6hZYa/ zz+CO2902zmFeaT1vkt25hyIM2zjupQVNtts8RPCZToGtZ7lRZw/qEv0XeVjrUtMOfTeq3XklT7 LbnL9Vyeduj9bSunwi0tg/QOLH64jW5Jba9h1pnCOq5ep9fb2zXG39XNWzaLG8Ls+55y3OVZFwn T2PfeZypwMhGzSxJndVdNjde6VHDMwfHr3nzQlKTIrYBAA== X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" CEC adapter functions are protected by drm_dev_enter() / _exit(), so it is safe to keep CEC registered until DRM device is being torn down. Drop custom CEC unsregistration code and rely on the DRM core to unregister CEC adapter. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/vc4/vc4_hdmi.c | 53 ++++++------------------------------------ 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 3086c2ad3bb2e8fafdc1f37ba985aa5785d49f9a..7b39000369e50f5368384575aa81919df5a7133c 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -2752,13 +2752,6 @@ static const struct cec_adap_ops vc4_hdmi_cec_adap_ops = { .adap_transmit = vc4_hdmi_cec_adap_transmit, }; -static void vc4_hdmi_cec_release(void *ptr) -{ - struct drm_connector *connector = ptr; - - drm_connector_cec_unregister(connector); -} - static int vc4_hdmi_cec_init(struct drm_connector *connector) { struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector); @@ -2796,51 +2789,19 @@ static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) { struct platform_device *pdev = vc4_hdmi->pdev; struct device *dev = &pdev->dev; - int ret; if (!of_property_present(dev->of_node, "interrupts")) { dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); return 0; } - ret = drm_connector_hdmi_cec_adapter_register(&vc4_hdmi->connector, - &vc4_hdmi_cec_adap_ops, - vc4_hdmi->variant->card_name, - 1, - vc4_hdmi_cec_init, - NULL, - &pdev->dev); - if (ret < 0) - return ret; - - /* - * NOTE: Strictly speaking, we should probably use a DRM-managed - * registration there to avoid removing the CEC adapter by the - * time the DRM driver doesn't have any user anymore. - * - * However, the CEC framework already cleans up the CEC adapter - * only when the last user has closed its file descriptor, so we - * don't need to handle it in DRM. - * - * By the time the device-managed hook is executed, we will give - * up our reference to the CEC adapter and therefore don't - * really care when it's actually freed. - * - * There's still a problematic sequence: if we unregister our - * CEC adapter, but the userspace keeps a handle on the CEC - * adapter but not the DRM device for some reason. In such a - * case, our vc4_hdmi structure will be freed, but the - * cec_adapter structure will have a dangling pointer to what - * used to be our HDMI controller. If we get a CEC call at that - * moment, we could end up with a use-after-free. Fortunately, - * the CEC framework already handles this too, by calling - * cec_is_registered() in cec_ioctl() and cec_poll(). - */ - ret = devm_add_action_or_reset(dev, vc4_hdmi_cec_release, vc4_hdmi); - if (ret) - return ret; - - return 0; + return drm_connector_hdmi_cec_adapter_register(&vc4_hdmi->connector, + &vc4_hdmi_cec_adap_ops, + vc4_hdmi->variant->card_name, + 1, + vc4_hdmi_cec_init, + NULL, + &pdev->dev); } #else static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) From patchwork Tue Dec 24 23:10:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920556 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E00AE7718D for ; Tue, 24 Dec 2024 23:11:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 26D7C10E2B8; Tue, 24 Dec 2024 23:11:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GS71nQ5+"; dkim-atps=neutral Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F6D210E2B8 for ; Tue, 24 Dec 2024 23:11:33 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-3043e84c687so45690751fa.1 for ; Tue, 24 Dec 2024 15:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081832; x=1735686632; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=/r+u0sZE5D8VurlC5VRIQEwPG+dElpWFh3HNgGqIo1o=; b=GS71nQ5+nCMUBpBQ4LaYT+d92tBjoCCMor+HRsG2ZwlUlQ7KdgbtDGxEEKfERNk5hs eJEK/lPNQRCAJCZmpWBblcApn3fp0d1jUZ0bbbbLcPvF7K4LCpt5yKqRS+fQSjs9Xpy4 bPhuuaIT32kUcnwwyQMWFfykaUYaoPmnf7XXoPwYj3WwPHVSdJVqFA5TSsObdY8FehKy caZ4ByW2pfbyPU2Wa7EIWHPqFQXiKDCXTF7Euwu2fSPluHZbSKwsZiAh+5Z0OShfjizC wwx7CUNodtoGtgbIeTODv0Q28Lcr+XRLjrbryH2pY1/gsC2CsOdUQGVFtqgavr0LcYDB cL6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081832; x=1735686632; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/r+u0sZE5D8VurlC5VRIQEwPG+dElpWFh3HNgGqIo1o=; b=HcNPzr1Hm55qqe9hWlecOLCWT5R6qmkdeRkprKglpaoSAh8nS2Uh9ZKAwY3snIHeeQ dBCRD+ngs7VGyN8U/tbahQElUFbbdnJSJfTjyjHTT1GTfmEVdd2Etng8OZTHncnM3XRo POky6mogYGi0tDYDk9vuSVeYTSXzZLqYGUcOQ551o5/8dC5wJAonqt3Sq7C4hvM/wrA1 x0ygozxY4e5/KdhMh/xTcjLUyufhBv2E4H11ovt8yQLP6zZverdqt5rJFl/HxjCmtXjE L5UMnwrdjRKofjf82G4Si/EgJYEbr1q8O4KBJtr11s1GZARtfKBbI+ZP1mkCJkH9AO5C YHww== X-Gm-Message-State: AOJu0YwwnS1dnlt7VTOkK8Km2MtnoiC2JDd2p//SfhdqBE4pmE2udPJJ 8HU555teIMs03hYDCIr0CP/iQrcUhZJSu0b1WHbi+mtvi8nfzR0EDzISUvNskGM= X-Gm-Gg: ASbGncvyrdMSxLDxzpi9wdrB53f3XzwtNBuf1wxTWBWiKFtHEWU9xvpa91doNtJqBSG zlfwsD94s0ljD9jGzlPoc47gxrYcCGd0JiRhk6QLHahXh/8tJljlKOcjgTGfFB4DiucKJ3QEBG7 iAelZKwgqcct/9yR0X5ejtKprdGbVCi3bjI0tLLPSG4XVSDh9Lsw/bukY77JSiXKF2MoZrAlgbV DlS2AIw2DwBfZlfdcpfEj8zZ+GoWM3aw1UeISVQkxv3XKLW0XssONUkEoLtKQbk X-Google-Smtp-Source: AGHT+IGjrUB2TLrzUQREEAc+sh0JQA205RIs49HjA/2I8kEtZbGCHfFtOhnbPSuud5zG5HU9ctH4Wg== X-Received: by 2002:a05:6512:3f0d:b0:540:358d:d9b5 with SMTP id 2adb3069b0e04-542294ae2e9mr5758211e87.0.1735081831786; Tue, 24 Dec 2024 15:10:31 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:30 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:14 +0200 Subject: [PATCH RFC/RFT 6/9] drm/display: bridge-connector: hook in CEC notifier support MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-6-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4084; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=90ejgcy/tGTeJU3XG+cQM6w/AiRHbpg85t5Qz6ihKHQ=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9W9t2brPmk3nz0O8zZEEUvpaYxz558zo7IB EI4VTfwLoqJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VgAKCRCLPIo+Aiko 1XR3B/93XfwazjnkzjUluIQWuNP9h20/xSLWiT2KkQvFMkqFAKZl7sZlhjifLwUl2MZmr5AEEL3 L8tbeBq8BCfg4VBQpUQAAuRudKXxW1tR+i1CMUTLwXsBOa7//5ROpwTD/mCRf08JdN41ldhQ3O7 m1WEVTps/Hq4l/NCD3dScYOHgWk9+yL0RJ7EaWWeO3wJhAmuDehNEcHjiP0Iy5DpyxNeSRrNzFd +P09EG4eTy9xsaQyPJrylcXpYrTrebv+3xReXzQBvNUv+KA0lZkLbh/PSjUYzXncj3UR5mXuN70 dU3h/5S0IE0oGZcH8i2ZzjLG8kOlyzsk1rZM8/lugPxohmXz X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Allow HDMI DRM bridges to create CEC notifier. Physical address is handled automatically by drm_atomic_helper_connector_hdmi_hotplug() being called from .detect() path. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/bridge/lontium-lt9611.c | 2 +- drivers/gpu/drm/display/Kconfig | 1 + drivers/gpu/drm/display/drm_bridge_connector.c | 11 ++++++++++- include/drm/drm_bridge.h | 9 +++++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/lontium-lt9611.c b/drivers/gpu/drm/bridge/lontium-lt9611.c index e650cd83fc8d880012edb8a85c69b2f1d378f64c..41156aee5d9f1ecd7bd3f0aeb866487325063c11 100644 --- a/drivers/gpu/drm/bridge/lontium-lt9611.c +++ b/drivers/gpu/drm/bridge/lontium-lt9611.c @@ -1138,7 +1138,7 @@ static int lt9611_probe(struct i2c_client *client) lt9611->bridge.type = DRM_MODE_CONNECTOR_HDMIA; lt9611->bridge.vendor = "Lontium"; lt9611->bridge.product = "LT9611"; - lt9611->bridge.hdmi_audio_dev = dev; + lt9611->bridge.hdmi_dev = dev; lt9611->bridge.hdmi_audio_max_i2s_playback_channels = 8; lt9611->bridge.hdmi_audio_dai_port = 2; diff --git a/drivers/gpu/drm/display/Kconfig b/drivers/gpu/drm/display/Kconfig index 49da9b768acf3e5f84f2cefae4bb042cfd57a50c..d35d945a3811c30247a9f3e282a16c9eedd0d4e9 100644 --- a/drivers/gpu/drm/display/Kconfig +++ b/drivers/gpu/drm/display/Kconfig @@ -16,6 +16,7 @@ if DRM_DISPLAY_HELPER config DRM_BRIDGE_CONNECTOR bool select DRM_DISPLAY_HDMI_AUDIO_HELPER + select DRM_DISPLAY_HDMI_CEC_HELPER select DRM_DISPLAY_HDMI_STATE_HELPER help DRM connector implementation terminating DRM bridge chains. diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c index e53f01681b795c41879167d066d382952bf50bce..291abb4bcfefd12e1a57a22ba5ccce21c15196a4 100644 --- a/drivers/gpu/drm/display/drm_bridge_connector.c +++ b/drivers/gpu/drm/display/drm_bridge_connector.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -616,7 +617,7 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, return ERR_PTR(-EINVAL); ret = drm_connector_hdmi_audio_init(connector, - bridge->hdmi_audio_dev, + bridge->hdmi_dev, &drm_bridge_connector_hdmi_audio_funcs, bridge->hdmi_audio_max_i2s_playback_channels, bridge->hdmi_audio_spdif_playback, @@ -624,6 +625,14 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, if (ret) return ERR_PTR(ret); } + + if (bridge->hdmi_cec_notifier) { + ret = drm_connector_hdmi_cec_notifier_register(connector, + NULL, + bridge->hdmi_dev); + if (ret) + return ERR_PTR(ret); + } } else { ret = drmm_connector_init(drm, connector, &drm_bridge_connector_funcs, diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 4b84faf14e368310dd20aa964e8178ec80aa6fa7..1f1670e3c6aac39b8b891b0d5e7e91254eb0d3a1 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -914,9 +914,9 @@ struct drm_bridge { unsigned int max_bpc; /** - * @hdmi_audio_dev: device to be used as a parent for the HDMI Codec + * @hdmi_dev: device to be used as a parent for the HDMI Codec */ - struct device *hdmi_audio_dev; + struct device *hdmi_dev; /** * @hdmi_audio_max_i2s_playback_channels: maximum number of playback @@ -933,6 +933,11 @@ struct drm_bridge { * @hdmi_audio_dai_port: sound DAI port, -1 if it is not enabled */ int hdmi_audio_dai_port; + + /** + * @hdmi_cec_notifier: use this bridge to register a CEC notifier + */ + bool hdmi_cec_notifier; }; static inline struct drm_bridge * From patchwork Tue Dec 24 23:10:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDAC2E7718D for ; Tue, 24 Dec 2024 23:11:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7710D10E2BA; Tue, 24 Dec 2024 23:11:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="eAyag60E"; dkim-atps=neutral Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id C72D010E2BA for ; Tue, 24 Dec 2024 23:11:35 +0000 (UTC) Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5401e6efffcso6535716e87.3 for ; Tue, 24 Dec 2024 15:11:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081834; x=1735686634; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=efhfp+4qW1iSmQeuDMr+e/8ImYQLWTnZeSHC6Pg4yQI=; b=eAyag60E5miNdMEpwkHsSu4Ncnu21yE6nph4hpAaYw1LHo5S0YwlfZNNGUxwsabm7c t7yf2y4YthuVsk+SMojQMR8SvAwG0yqq8mV0n9NZVP6VyyPpxBBMV1sAnxGvIw42PR12 iNV74UtEFwbijUR+IQfEci55s3YgFKx59z2WstYLaEKlCNy08SNlYCMNd1diec3awh/R RudSajf9JIil4SD+52CLCGf4JR2M3DDlUUMjEHBpH/LefMDwbW+D3btZZiyjQes5LLTM ge7lIdMsmP3NXsjQ6S8vsru6aB8zinp5JGNwFjPGHVexkr/it8YYM8yQ7kzTSyXRIrzD UssA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081834; x=1735686634; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=efhfp+4qW1iSmQeuDMr+e/8ImYQLWTnZeSHC6Pg4yQI=; b=eDnzPG4fwxLPOqU26vEHkUYrwavP8t4CvaR08JKJNa8f+s/0swbQ5R+pCO09e1xDwY /yerlFWFBmfg0IazeL6rQzV0TPmgMn/SltK8ZGSmHxc36AvwdcakdZTsiQt2MyX1KZLL yiwSDJ9xtKFWR3G8TMVPSTOphhoAsMamff9nysTupTRjXhEi4IpF/BrnsppFVhiv668b hW3u5VkZ/gL+7AMS0FX332nZCy/d9P8hK4e8aEql3VjvNvgEZ/0dZqtSsxNlmOhVKgRF O37aIypodORV0ll4QEG6VaEr+EFhZzB7QayiQXIrZbvHIFBXCJ6x2Qun93JSk8bvucLA fj4w== X-Gm-Message-State: AOJu0Yxm4JUlMYlaLokhBrOKom1niAz7gowCOFi/NYQFIH5j0g0j2RGm /RwjOkMchsKHVKi9mW2gt0xfqkG7aDSgb8fWaW/TcT+FNlDP+rKsJLMv0Lh1og4= X-Gm-Gg: ASbGncsMw21YqcCUORSOAuCg67Ls/s/uyytLuOBd9GN7YkasTSWIPemJ53OioJN+Xt4 65aggI5X5gGBT7u+Ubbkkmt3kfeQ6ZOnFcgAcqPq6Mnf/dbfkEmUPlEz1Y/VjuCgPcIJm4lYMKm aJEqFMVXqAbbQ7m33FsuprVNSX3fp7sO5nYX9X5Mm90ZJMZ7f2EK3OTdjJa3HmSvpUpmTQJbXqo TfUURrCD7bBfFbRszGM05/O4rUsZpJrL0uxB0FRVfyfSzCmuBTl0mGtQ1+ivvyi X-Google-Smtp-Source: AGHT+IEhaltbYVeYVnWcTZEGij7INLhjOGoVthIuxjQxvZSLrBa/jDt55eu9hG868SnM0PHocdwMyg== X-Received: by 2002:a05:6512:438b:b0:542:2999:2e43 with SMTP id 2adb3069b0e04-54229992e47mr6635799e87.24.1735081834230; Tue, 24 Dec 2024 15:10:34 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:32 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:15 +0200 Subject: [PATCH RFC/RFT 7/9] drm/bridge: move private data to the end of the struct MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-7-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1860; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=Bh587iD2fc71HoCxezk2yuAVtboO7fHMro855SCGYPU=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9WxA+sQ8KjJROIrN1f0Hf4EKmOFjAonnPpL YW1LIJq3eCJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VgAKCRCLPIo+Aiko 1YOtCACyMIuozXLT74TZyjuf318MVOI0LGrevexAAORnXjfKs4jVI5zj0NBxle/Q4OYEKgCL+ia 3sMwKNg495laf8mJGOrgC2iOJ4gjvwTLxApO2F12iPsOsjHBezwr/pYup2f37ktYIKXflBtnYRD K2Bz6u6XGiaVcQR31TH6W2vBjt2g0HRGslOg66IlgR1noYnKJNa16r2kMfAYNUHpDnTv19cZAnB 2oAyJZrMkcuEUA7YvjUkXm665gFMrRIY66sLOgvVpvcMFM6QxvTjyuhxAQuyGemdbjim3AhlQ+a 4FxPKxOKY0nfJwfrDz+sDqVs+/SL3UaeL3JVz8yGvinz41vj X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" WHen adding HDMI fields I didn't notice the private: declaration for HPD fields. Move private fields to the end of the struct drm_bride to have clear distinction between private and public fields. Signed-off-by: Dmitry Baryshkov --- include/drm/drm_bridge.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 1f1670e3c6aac39b8b891b0d5e7e91254eb0d3a1..348778f233b06265a6ae577762c6558e69cdb396 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -872,21 +872,6 @@ struct drm_bridge { * @ddc: Associated I2C adapter for DDC access, if any. */ struct i2c_adapter *ddc; - /** private: */ - /** - * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields. - */ - struct mutex hpd_mutex; - /** - * @hpd_cb: Hot plug detection callback, registered with - * drm_bridge_hpd_enable(). - */ - void (*hpd_cb)(void *data, enum drm_connector_status status); - /** - * @hpd_data: Private data passed to the Hot plug detection callback - * @hpd_cb. - */ - void *hpd_data; /** * @vendor: Vendor of the product to be used for the SPD InfoFrame @@ -938,6 +923,22 @@ struct drm_bridge { * @hdmi_cec_notifier: use this bridge to register a CEC notifier */ bool hdmi_cec_notifier; + + /** private: */ + /** + * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields. + */ + struct mutex hpd_mutex; + /** + * @hpd_cb: Hot plug detection callback, registered with + * drm_bridge_hpd_enable(). + */ + void (*hpd_cb)(void *data, enum drm_connector_status status); + /** + * @hpd_data: Private data passed to the Hot plug detection callback + * @hpd_cb. + */ + void *hpd_data; }; static inline struct drm_bridge * From patchwork Tue Dec 24 23:10:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920553 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E549E77188 for ; Tue, 24 Dec 2024 23:10:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 08EF110E2B2; Tue, 24 Dec 2024 23:10:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="R1CqiW2t"; dkim-atps=neutral Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5143410E2B1 for ; Tue, 24 Dec 2024 23:10:38 +0000 (UTC) Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-53e384e3481so5067323e87.2 for ; Tue, 24 Dec 2024 15:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081837; x=1735686637; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BCaN0AnQNgYbXUjxYsj4Dfl7LjnUIb+yQn6Obl4zIV0=; b=R1CqiW2tFGFjMMQ3P7jObi+XKGRrCIJu+He1O/uR0Wh33pIqvDDV1uW+MMbK/XdJxT 5ADm6uEEnycQDRQSqU2IGC24euqm6CQqm/ipHuOh4+1pQUWmyb8NjJ3QyFHgut2NpQoC H4VxxuARBYQh8ioba3v/NZv+X4cmUIG1BhMt7E41LnS9u7n44CXJ8LMWUtalatm98uVq qzDFZDJWvg31ha7m6taSFPgmCYdYleyVEXywbTiQqtTza9Lp0Q2jqS+48jHbDQWMucV4 fL56+lc5ptpN/9MclYGXCtn1dZllwgCfSP+Fw4wf5d8T2dPNBoO4empB1jjpSqWr+VQS XJXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081837; x=1735686637; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BCaN0AnQNgYbXUjxYsj4Dfl7LjnUIb+yQn6Obl4zIV0=; b=h5FxxCoIxSlGQcDLlVebYxAr39ivIVlIB8bBiOPpIJKmX4OaYr1sEwxGmlY07IE2nV lxA2F3WDxWmGwJR3gc3IAyrb/x+IIjW/+Pk+aGfCINfHbtHQkkx57MMUITtiQuEK39O9 mmzSHoFYptn2sZ67EwV63tiUGcfJwYxjA92MNDMlF0Z1EW+hkn2/ogQrUCWrxXFBm2SN PI+rnkl6d2QpSW9gsDPm1mPsSvN49tCvaS5j9+QHqipTwJFz/mEXdbJmv72uNRBU2JLV LjLEqReTSmiKnBujn+h+wUcASHT/+Btq894/Y7PFGQYIguKOu32MAdV1pU9zrehMHfz4 /bhg== X-Gm-Message-State: AOJu0YxKpuvxILpFgYf+xZ+wGAi4Zb8pF89GPcEsOPkOnnLlgueUGqNM f3dsn2yl1ZjvFSd55gD1dBF+Uz83/2mLsyzxHWpRJ58r7Jv6mXojlnRofxtPauk= X-Gm-Gg: ASbGncujEuSxHqjX/GUl2N/3T/MF+0cNrENO1g/Ut+3mEX+0ngBxVMqSXtBASc0TAcy xJBxZpQbQFBZaK4btlT+gNWUOEENFa+ZAyhao8s6XcsvPof6hqN8ujFq0BzlaA3A9ep6Muc0ctB 2b+kvdi4vZLrnOGIaWXNsDNGEotoUpMBSarmq71GAsXu4jP8PKYXgz7T1stN+4EPBS9mom1xBIB iq3VXTrUTKl66wO7HA6/xFfHiLWIp4SKL0dlrcuGDRzxhJPAzrFnqWBim0gufLB X-Google-Smtp-Source: AGHT+IFVrzVeCp6RMk6VBemfxzPgO1kh+EDDGjra7lj5L6m71WVsinWmKcRRmBsISaTMnTyHjGjfmg== X-Received: by 2002:a05:6512:114f:b0:540:1d37:e6e with SMTP id 2adb3069b0e04-542295434f9mr6247183e87.33.1735081836626; Tue, 24 Dec 2024 15:10:36 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:35 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:16 +0200 Subject: [PATCH RFC/RFT 8/9] drm/display: hdmi-cec-helper: add bridge-related functions MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-8-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5683; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=7t8N+meJkwqjJEAn7i1o2Y6T8jyDOQeiyIXpOu8i+xc=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9WGJm8rCdTIkETaImddvza2ifHFNozBK3UT klZZOM/+xyJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VgAKCRCLPIo+Aiko 1f6lB/0a1gIGKUgRbL2RzO61mKzyulTDa78dCT9iHzkTg/bYdyu3Pvk5DOWi76iM/XSrgAPZCZG 2JX4ueHs5bj8Gsh005sL5+fzjVFPBUTp8kpj0yxKiAzcGMW2dxFRyvXYRb7nkcv6Ur2nEQpmDQG 4hAlaCAFU3Vez1OhojmdYV2CZKk0nE8MNIni3GYkO28hW6/uAqdoJCyFhHEZ46Thkyu3XIKq5nG 1YDfkyJk6RVXJT+7LgIELQHvv6XcjJ3TG9PoyczfKTGdzdyH2S/35u7+Bbwior3oiDUYnKw8LSA Fqw6W3za7slpt5/OL00DyPgB+l/uuQ3vHGdmBOJWqWIg6AWF X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Let drm_bridge drivers handle CEC adapters in a generic way. Add a set of helper functions to be called by DRM bridge drivers to report CEC message-related events. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/display/drm_hdmi_cec_helper.c | 37 +++++++++++++++++++++++++++ drivers/gpu/drm/drm_bridge.c | 16 ++++++++++++ include/drm/display/drm_hdmi_cec_helper.h | 10 ++++++++ include/drm/drm_bridge.h | 13 ++++++++++ 4 files changed, 76 insertions(+) diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c index 2a3832e68232fa3b839a3c7457b2013779cada86..f54142c6b656b0708e60b009c21ee7584c79a130 100644 --- a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c @@ -143,3 +143,40 @@ void drm_connector_hdmi_cec_phys_addr_set(struct drm_connector *connector) mutex_unlock(&connector->cec.mutex); } EXPORT_SYMBOL(drm_connector_hdmi_cec_phys_addr_set); + +void drm_bridge_cec_transmit_done(struct drm_bridge *bridge, u8 status, + u8 arb_lost_cnt, u8 nack_cnt, + u8 low_drive_cnt, u8 error_cnt) +{ + mutex_lock(&bridge->cec_mutex); + + if (bridge->cec_adapter) + cec_transmit_done(bridge->cec_adapter, status, arb_lost_cnt, + nack_cnt, low_drive_cnt, error_cnt); + + mutex_unlock(&bridge->cec_mutex); +} +EXPORT_SYMBOL_GPL(drm_bridge_cec_transmit_done); + +void drm_bridge_cec_transmit_attempt_done(struct drm_bridge *bridge, u8 status) +{ + mutex_lock(&bridge->cec_mutex); + + if (bridge->cec_adapter) + cec_transmit_attempt_done(bridge->cec_adapter, status); + + mutex_unlock(&bridge->cec_mutex); +} +EXPORT_SYMBOL_GPL(drm_bridge_cec_transmit_attempt_done); + +void drm_bridge_cec_received_msg(struct drm_bridge *bridge, + struct cec_msg *msg) +{ + mutex_lock(&bridge->cec_mutex); + + if (bridge->cec_adapter) + cec_received_msg(bridge->cec_adapter, msg); + + mutex_unlock(&bridge->cec_mutex); +} +EXPORT_SYMBOL_GPL(drm_bridge_cec_received_msg); diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index c6af46dd02bfa9e15b59e4c460debdd7fd84be44..c7522e20009977632d9fcd0327d856b9d60893d0 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -206,6 +206,7 @@ static LIST_HEAD(bridge_list); void drm_bridge_add(struct drm_bridge *bridge) { mutex_init(&bridge->hpd_mutex); + mutex_init(&bridge->cec_mutex); mutex_lock(&bridge_lock); list_add_tail(&bridge->list, &bridge_list); @@ -248,6 +249,7 @@ void drm_bridge_remove(struct drm_bridge *bridge) mutex_unlock(&bridge_lock); mutex_destroy(&bridge->hpd_mutex); + mutex_destroy(&bridge->cec_mutex); } EXPORT_SYMBOL(drm_bridge_remove); @@ -1302,6 +1304,20 @@ void drm_bridge_hpd_notify(struct drm_bridge *bridge, } EXPORT_SYMBOL_GPL(drm_bridge_hpd_notify); +void drm_bridge_cec_adapter_set(struct drm_bridge *bridge, + struct cec_adapter *cec_adapter) +{ + if (!(bridge->ops & DRM_BRIDGE_OP_HDMI)) + return; + + mutex_lock(&bridge->cec_mutex); + + bridge->cec_adapter = cec_adapter; + + mutex_unlock(&bridge->cec_mutex); +} +EXPORT_SYMBOL_GPL(drm_bridge_cec_adapter_set); + #ifdef CONFIG_OF /** * of_drm_find_bridge - find the bridge corresponding to the device node in diff --git a/include/drm/display/drm_hdmi_cec_helper.h b/include/drm/display/drm_hdmi_cec_helper.h index 75e6476498a31a05af5a813f1df138e7786520be..8d31f9e2e4bd3a62a8b92ebcd1e4672daf8f585e 100644 --- a/include/drm/display/drm_hdmi_cec_helper.h +++ b/include/drm/display/drm_hdmi_cec_helper.h @@ -5,10 +5,12 @@ #include +struct drm_bridge; struct drm_connector; struct cec_adap_ops; struct cec_adapter; +struct cec_msg; struct device; int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector, @@ -35,4 +37,12 @@ static inline void drm_connector_hdmi_cec_phys_addr_invalidate(struct drm_connec static inline void drm_connector_hdmi_cec_phys_addr_set(struct drm_connector *connector) {} #endif +void drm_bridge_cec_transmit_done(struct drm_bridge *bridge, u8 status, + u8 arb_lost_cnt, u8 nack_cnt, + u8 low_drive_cnt, u8 error_cnt); +void drm_bridge_cec_transmit_attempt_done(struct drm_bridge *bridge, u8 status); + +void drm_bridge_cec_received_msg(struct drm_bridge *bridge, + struct cec_msg *msg); + #endif diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 348778f233b06265a6ae577762c6558e69cdb396..a848ab63cc8e9c917e7ca3fe4e279bcf2a83cbb2 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -32,6 +32,7 @@ #include #include +struct cec_adapter; struct device_node; struct drm_bridge; @@ -939,6 +940,15 @@ struct drm_bridge { * @hpd_cb. */ void *hpd_data; + + /** + * @cec_mutex: Protects the @cec_adapter field. + */ + struct mutex cec_mutex; + /** + * @cec_adapter: Private data to be used by the CEC callbacks. + */ + struct cec_adapter *cec_adapter; }; static inline struct drm_bridge * @@ -1062,6 +1072,9 @@ void drm_bridge_hpd_disable(struct drm_bridge *bridge); void drm_bridge_hpd_notify(struct drm_bridge *bridge, enum drm_connector_status status); +void drm_bridge_cec_adapter_set(struct drm_bridge *bridge, + struct cec_adapter *cec_adapter); + #ifdef CONFIG_DRM_PANEL_BRIDGE bool drm_bridge_is_panel(const struct drm_bridge *bridge); struct drm_bridge *drm_panel_bridge_add(struct drm_panel *panel); From patchwork Tue Dec 24 23:10:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13920558 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E2A1E7718D for ; Tue, 24 Dec 2024 23:11:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8E9D410E33D; Tue, 24 Dec 2024 23:11:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="zIBaJrfK"; dkim-atps=neutral Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by gabe.freedesktop.org (Postfix) with ESMTPS id A537010E33D for ; Tue, 24 Dec 2024 23:11:40 +0000 (UTC) Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-3003943288bso61444511fa.0 for ; Tue, 24 Dec 2024 15:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735081839; x=1735686639; darn=lists.freedesktop.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CdewCk/PRTWQN0dylNFNsSEtCEp3tuP1E7w2vIr9TcQ=; b=zIBaJrfK+ZqW7/+pbtV7Tn9AvWpPdcFEsWh/7Oqz4+WMcOrB8j2FerveOAR/yTseFi dlj3MC/HefQK2sbJkp+Irm5drIixmNA01BdzrK2tvbxXFxL2/EinU6+gr21bc3UQGCFi NT6LhhWMHPCL0o1zwWuDouMXeVkIWwZjhBe+l0O9C1HK4q0ksTnp3WZXkxaVloHrQzU9 gwX0zm/u5Yiry4n1ReuHrX59Dt5YTn33f2gIrranqH/uuIGgC38OrzJ9rlZXV6bXhiCy SorvbjlNZvICigVUl2DC06/CjD2LhZZo4wzh4QssRktnw5j1Pk/Z7SccpyKt7y+doevM t3kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735081839; x=1735686639; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CdewCk/PRTWQN0dylNFNsSEtCEp3tuP1E7w2vIr9TcQ=; b=ZRiuCqcaFF9btbFe4It1VWPb+D5EmrDzhNpt8fic4nsruOv3rAR8gUFYuS1DZkIJ5e X8CaJKp1Fo/3a3daVMNOGYnZFUOP2753/LkJcLstEYvFOkIOVCwEhHkrwlTJkzRtVz35 x2C4YmxU6sJE1e/EmxWx1aPEyytGFR6qX12CiEFLe4Q5mZ/i321DsMAk0Oi61/3xfXVJ tLR0K5XsooSaySYULxlN+4cCmAwgA+USgLxLPQ1cMVAk7dPwuTvbsWaRGpg2W6KZIGd6 oim+VVacjYePZl5Sbb38ON/wZz+gxGgAruOD0HUu1SGKAntCbIh1u41zrWGfNO5L46Rk I3Qg== X-Gm-Message-State: AOJu0YySWsfB9RTB9fZrgM+YNojoz8SLJ4y2pRSuLQ5l4UFW46sPpuGS ttvjS9ivggpVEZpIsAmdXjx3Pz+D1gMqUV/8o71O3WGFpJHPMnfPkwaPmRJ39L4= X-Gm-Gg: ASbGncvTyuxSErTJzIVQ3xNwlNn35uu1+Gi0oS5MZ7XjL5ZxB6l4dYMHMOyqzwpBxEW X8WH5iaScPrqA94WApOYkC5MWerGYMHqfLi1H3rRoZkkfeyVxUMt2WWOOl3RRAk/AeKXJ25nclx sLTCMWtfqOlug7c8hQg5FDsnnkahl0mVZ3fZejLjb2erzZIfGQmSwJDo9MSzPy3aAFejvAjBIuA Hwsy88O9noq54+tILJ1K2WWh4w/iBSagvoYgiPcQMS/Aw/gRDu1wIBlJx7UO/Tc X-Google-Smtp-Source: AGHT+IF7yX8NB3dL2I9oCyrwUW/216+uMBZnO7rofkTlzB1tv6R2FT8+EMKGiGeqgjQOzx4R1mgDeg== X-Received: by 2002:a05:6512:6512:b0:542:297f:4f69 with SMTP id 2adb3069b0e04-542297f4fe6mr4383196e87.41.1735081839049; Tue, 24 Dec 2024 15:10:39 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-542235f5f74sm1721283e87.43.2024.12.24.15.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 15:10:37 -0800 (PST) From: Dmitry Baryshkov Date: Wed, 25 Dec 2024 01:10:17 +0200 Subject: [PATCH RFC/RFT 9/9] drm/display: bridge-connector: handle CEC adapters MIME-Version: 1.0 Message-Id: <20241225-drm-hdmi-connector-cec-v1-9-b80380c67221@linaro.org> References: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> In-Reply-To: <20241225-drm-hdmi-connector-cec-v1-0-b80380c67221@linaro.org> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Dave Stevenson , =?utf-8?q?Ma=C3=ADra_Cana?= =?utf-8?q?l?= , Raspberry Pi Kernel Maintenance , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5825; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=X9IwqP014YM7Yqs7I1CTwyxkzFvnciX/pqhUwGCgKmI=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBnaz9WRj8gJm92HaOlOvdvAm82lKlETw5HUFrkp Djq2qO2o3yJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ2s/VgAKCRCLPIo+Aiko 1eEeB/0bxzxQhHj2XJ/dcUJ79F7c1hHbybD9qcBjuaYPrBxbGxm1/PdrpjTFEa7Rpthx3TJZw38 b90yxkRyc3iAJp1C/XKuCZSLj1k9AjEEd5tzCYth8QJ3M+caNnETQDHQw25twDNxJSR8jyjf8GF YVn8EOghnQgd1jU7Yl06fKZv1VApgGfDHy44wZ/ZHyCjaNI7LHG7uDoKAFIkYxnhwRE70TmykB5 Wm3/8mS7eWm7xFxlvHPOaBm2HOW/MDjX0+M1aF6Ly9z7HbVOHHLz5SIbvnAK8arikIZ1qVIC/js D8HV9NAmd4q02rYDJGxmq40Ikvrjgqm3SqpXZA5UUUn3derG X-Developer-Key: i=dmitry.baryshkov@linaro.org; a=openpgp; fpr=8F88381DD5C873E4AE487DA5199BF1243632046A X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Implement necessary glue code to let DRM bridge drivers to implement CEC adapters support. Signed-off-by: Dmitry Baryshkov --- drivers/gpu/drm/display/drm_bridge_connector.c | 95 ++++++++++++++++++++++++++ include/drm/drm_bridge.h | 25 +++++++ 2 files changed, 120 insertions(+) diff --git a/drivers/gpu/drm/display/drm_bridge_connector.c b/drivers/gpu/drm/display/drm_bridge_connector.c index 291abb4bcfefd12e1a57a22ba5ccce21c15196a4..f6d04f5aa261b3d0cec4057d4c9595e494c34264 100644 --- a/drivers/gpu/drm/display/drm_bridge_connector.c +++ b/drivers/gpu/drm/display/drm_bridge_connector.c @@ -9,6 +9,8 @@ #include #include +#include + #include #include #include @@ -497,6 +499,80 @@ static const struct drm_connector_hdmi_audio_funcs drm_bridge_connector_hdmi_aud .mute_stream = drm_bridge_connector_audio_mute_stream, }; +static int drm_bridge_connector_cec_adap_enable(struct cec_adapter *adap, bool enable) +{ + struct drm_connector *connector = cec_get_drvdata(adap); + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + + return bridge->funcs->hdmi_cec_adap_enable(bridge, enable); +} + +static int drm_bridge_connector_cec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr) +{ + struct drm_connector *connector = cec_get_drvdata(adap); + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + + return bridge->funcs->hdmi_cec_adap_log_addr(bridge, logical_addr); +} + +static int drm_bridge_connector_cec_adap_transmit(struct cec_adapter *adap, + u8 attempts, + u32 signal_free_time, + struct cec_msg *msg) +{ + struct drm_connector *connector = cec_get_drvdata(adap); + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + + return bridge->funcs->hdmi_cec_adap_transmit(bridge, attempts, + signal_free_time, + msg); +} + +static const struct cec_adap_ops drm_bridge_connector_cec_adap_ops = { + .adap_enable = drm_bridge_connector_cec_adap_enable, + .adap_log_addr = drm_bridge_connector_cec_adap_log_addr, + .adap_transmit = drm_bridge_connector_cec_adap_transmit, +}; + +static int drm_bridge_connector_hdmi_cec_init(struct drm_connector *connector) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + + drm_bridge_cec_adapter_set(bridge, connector->cec.adapter); + + if (!bridge->funcs->hdmi_cec_adap_init) + return 0; + + return bridge->funcs->hdmi_cec_adap_init(connector, bridge); +} + +static void drm_bridge_connector_hdmi_cec_uninit(struct drm_connector *connector) +{ + struct drm_bridge_connector *bridge_connector = + to_drm_bridge_connector(connector); + struct drm_bridge *bridge; + + bridge = bridge_connector->bridge_hdmi; + + drm_bridge_cec_adapter_set(bridge, NULL); +} + /* ----------------------------------------------------------------------------- * Bridge Connector Initialisation */ @@ -633,6 +709,25 @@ struct drm_connector *drm_bridge_connector_init(struct drm_device *drm, if (ret) return ERR_PTR(ret); } + + if (bridge->hdmi_cec_adapter_name) { + u8 num_las = bridge->hdmi_cec_available_las ? : CEC_MAX_LOG_ADDRS; + + if (!bridge->funcs->hdmi_cec_adap_enable || + !bridge->funcs->hdmi_cec_adap_log_addr || + !bridge->funcs->hdmi_cec_adap_transmit) + return ERR_PTR(-EINVAL); + + ret = drm_connector_hdmi_cec_adapter_register(connector, + &drm_bridge_connector_cec_adap_ops, + bridge->hdmi_cec_adapter_name, + num_las, + drm_bridge_connector_hdmi_cec_init, + drm_bridge_connector_hdmi_cec_uninit, + bridge->hdmi_dev); + if (ret) + return ERR_PTR(ret); + } } else { ret = drmm_connector_init(drm, connector, &drm_bridge_connector_funcs, diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index a848ab63cc8e9c917e7ca3fe4e279bcf2a83cbb2..65545f9b94cc942e21a2394197faf8219f5d69b2 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -33,6 +33,7 @@ #include struct cec_adapter; +struct cec_msg; struct device_node; struct drm_bridge; @@ -730,6 +731,20 @@ struct drm_bridge_funcs { struct drm_bridge *bridge, bool enable, int direction); + int (*hdmi_cec_adap_init)(struct drm_connector *connector, + struct drm_bridge *bridge); + + int (*hdmi_cec_adap_enable)(struct drm_bridge *bridge, + bool enable); + + int (*hdmi_cec_adap_log_addr)(struct drm_bridge *bridge, + u8 logical_addr); + + int (*hdmi_cec_adap_transmit)(struct drm_bridge *bridge, + u8 attempts, + u32 signal_free_time, + struct cec_msg *msg); + /** * @debugfs_init: * @@ -925,6 +940,16 @@ struct drm_bridge { */ bool hdmi_cec_notifier; + /** + * @hdmi_cec_adapter_name: the name of the adapter to register + */ + const char *hdmi_cec_adapter_name; + + /** + * @hdmi_cec_available_las: number of logical addresses, CEC_MAX_LOG_ADDRS if unset + */ + u8 hdmi_cec_available_las; + /** private: */ /** * @hpd_mutex: Protects the @hpd_cb and @hpd_data fields.