From patchwork Fri Jan 10 11:28:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934318 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 72005E7719C for ; Fri, 10 Jan 2025 11:28:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EEAF910E10D; Fri, 10 Jan 2025 11:28:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="UkrAyrUx"; dkim-atps=neutral Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C9F310E10D for ; Fri, 10 Jan 2025 11:28:54 +0000 (UTC) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-30227ccf803so15667851fa.2 for ; Fri, 10 Jan 2025 03:28:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508532; x=1737113332; 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=d0vao2kszZEOdw8Rw0H4k+cRcCSPFR9JmZje0hGSkB0=; b=UkrAyrUxUYRPUw2bExI7AfLgwG8p+4iTB70zO7DK7VysAFTAmSbWMDPBOccgpzo074 MxRl4eg4h/HruJGWZby8doHRSmbbOppuC2aXmpY/bgIsPg3Co+N5AxLHfXXN7wJLhBue uZiS7yRKwOG4dd5MJcRtgYfK3LWJ0F+O9K+1vbOODd5k1HwWiCaGJk3AQ8hAkT9zvO/v 3Koat6kStxIknx35b2llrhyruKpmBewN6u2RiAU82iLj/lxgosETyJu+LKMAzOL0Esuy hMUsdQJNHSgLtwGSvmdDsg14a7fPYKr64kRh4jHudbfz8GQXsk7iUvGFqyinoefVeAdV gxOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508532; x=1737113332; 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=d0vao2kszZEOdw8Rw0H4k+cRcCSPFR9JmZje0hGSkB0=; b=wrX3UcUNmFGhzknxqCjOV5RcTLmzPCCcBPrFqD72zmNRKv/7l9YlI9A5aI6S82xGoQ f4WGX/qzJmGON7DKib5gHBLMh5pNcIXJi44s2KHTk3wXOfD3H1OF6XGrhrm+82DrzG4g pkmDFpfPpQOkxBeliqUIZDvBPEtBIFiOUI/eGTUp5Hs1J9S4it80AJUahoJZVvK/S7ZJ AYqSwoYalbYXxEBaOegQnyXwws7EKhQqc/A0r+ybSSeZuAYOjjt2kkJYt5S2f2WSwrsA UNMUQMKObWELXdAendHSYe+AaCwC8WW6wlECHaDKUWCq8VtjMRIrDGslqtFm/GmAuwEC /AMQ== X-Gm-Message-State: AOJu0YzR6yrDTK4rLc/Pp5SgW75zWpccUC0TIZTijc9PiHU7PSgwJsZl X61bN2T6ajnVMWt1a6/JO+cYiC0urWUgV/7W7iIH204LIJMy58/HHlLm7O8NzPk= X-Gm-Gg: ASbGncv4YyXUCyHH+j0A/edHzCu8DdAy+3Bmkz2TIzi0suSF4DEgmBtcGTDExMRSNMV OWkahQwhRIyh5i056rlrlJFWu2jqjpb2oFMkQyvF/WXLkCD0vmQqyd+GaRRv1xu2MepAFiR6nK5 PlkYUGGwM4uPzlD8oT1nmUReXadEprGJ/DrDhJIAc02/KPJOqauqYlYWSUZcRLGvLXIPCo+W2/X ZZnpkv3WbXcrbzSscPKIYJf1tYgi9INKkCRaZpLXT9i/MIb1ia3nRIGAxZlBLz+ X-Google-Smtp-Source: AGHT+IFq2Z+1hncub4AWL3RFD0wdO8EZoDd5lrO7r7RLlPYAnsU1t4IN+aU/L5cOw5xszRkkuOIqeA== X-Received: by 2002:a2e:bea8:0:b0:302:1b18:2c09 with SMTP id 38308e7fff4ca-305f45ba080mr33912761fa.27.1736508532537; Fri, 10 Jan 2025 03:28:52 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.28.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:28:51 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:44 +0200 Subject: [PATCH RFC/RFT v2 1/8] drm/connector: add CEC-related fields MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-1-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=4115; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=exgmtXH0OIK6SdS9CCUitkYz/uNC3k7yD8vdgvaJocQ=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBngQRu7ntUsyUqEneqm2g2HPWApf+peseyOwvvh gO4anRBflSJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1UhOB/9tLLGv24SNNG70JoNw3S7167gU88XGOGIVikq6nxtFGNDDNcPIuQTG095LMLScPVhJi+/ m7eWbJBCRO1pY4xvbcvm78R+Hny0RWJvuWAJ0IN+FjvJTdMLCOTHmKmJsVWJkJovs14hCnMVb7j TICa6T9JKM+8rfRUmA3Z7A/lAFr3eQlCFj+DZ+znLEzFwiDj0c1K3UWDetCg4iEI3BEih9VaLJq mnGggk+LPhS4wIxdZKegKFLm6gnyiEtridK3I7L8ktoZB2SX6T+B1qmtZYCLLU3B4TdwJUGtxpV Ic34Y3W1kIJeZ96J5CnR+wpdK+SqzdGays2dYJSw3VzzLJRY 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 | 13 ++++++++++++ include/drm/drm_connector.h | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 1383fa9fff9bcf31488453e209a36c6fe97be2f1..fffb718b09eaaac200e6abc7524bbfe98c4741f4 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,16 @@ static void drm_mode_remove(struct drm_connector *connector, drm_mode_destroy(connector->dev, mode); } +static void drm_connector_cec_unregister(struct drm_connector *connector) +{ + mutex_lock(&connector->cec.mutex); + + if (connector->cec.funcs->unregister) + connector->cec.funcs->unregister(connector); + + mutex_unlock(&connector->cec.mutex); +} + /** * drm_connector_cleanup - cleans up an initialised connector * @connector: connector to cleanup @@ -718,6 +729,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..6da840673b1209c84bbc396643c6033679a7ec74 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; @@ -1191,6 +1192,19 @@ struct drm_connector_hdmi_audio_funcs { bool enable, int direction); }; +/** + * struct drm_connector_cec_funcs - drm_hdmi_connector control functions + */ +struct drm_connector_cec_funcs { + /** + * @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); +}; + /** * struct drm_connector_hdmi_funcs - drm_hdmi_connector control functions */ @@ -1832,6 +1846,31 @@ 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; + + /** + * @funcs: CEC Control Functions + */ + const struct drm_connector_cec_funcs *funcs; +}; + /** * struct drm_connector - central DRM connector control structure * @@ -2253,6 +2292,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) From patchwork Fri Jan 10 11:28:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934331 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 0E581E7719C for ; Fri, 10 Jan 2025 11:29:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F4A310E4F8; Fri, 10 Jan 2025 11:29:57 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="SOH5a55A"; dkim-atps=neutral Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by gabe.freedesktop.org (Postfix) with ESMTPS id A18BA10E4F8 for ; Fri, 10 Jan 2025 11:29:56 +0000 (UTC) Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-3003c82c95cso13821591fa.3 for ; Fri, 10 Jan 2025 03:29:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508535; x=1737113335; 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=E+zsDCZfFigYSgeVB6rzkjLbqhGSHEHUBpHs4Qh2FwU=; b=SOH5a55AWa/4QCUsbuXmTkqzznU090Ak8riBSruRXpulgtxstWYsEvJtBgNq5pXXfW CCCELT0u6cW3CKHh003yiIuMWZeWg0ASPqfZvvAT8d943nDZd0mO9lA6zHjrlWziYTOX 0YJUSRtF9FCJWPzbDlEb7JofFdnsQNeRVjhZ33xeAmlUN1Kmjb2TADg0wY+A2qoicrfj t1HRwB5ucu08OmlRC6fNit1HSfccrSCHmRx1O3Lr4jkcxAWf7tVkswgEqjEgBLJCEwLb akuPSDi/9KHefJx/l0oS0veOdNB7oT/khIHnvpDAa8tosG2po+4cG24TnJMF3Mbq04pO GLQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508535; x=1737113335; 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=E+zsDCZfFigYSgeVB6rzkjLbqhGSHEHUBpHs4Qh2FwU=; b=qdy1nvY7olGNYNQQhAFvSI5ERggP4MTwf8ZM8C2TZdvriSycaZB8d+Ms8KIHKo5BXm aJqQjHnG1Unq6XcFEiVeTNrb7L7D/qnxeQy9f6iTuF/Wn0m4lzhbkuS7T35nHFYhShVV fhLZj16FHtcGH4+nShhdi7vVD314ZGCBg2UDWQsK9sOZGSCSz1scviG6XbL5+rP6y1lx HhfuUxh0m6fgJTv+Pa9Vh9vqL2esGUcGeKUTLnUMCn8M7KGYmAbrvMQBRaknNZIRd6Rd 6WSJIyIeHJokmeVw44YRnLAaF4CKu2VVLmrYwVWJKOYkgkqnIvt1US0ix12X9h0HnTh1 9ESA== X-Gm-Message-State: AOJu0YzmQ7kHjZKpCHh9cnmlXBERvLbXsKCXLryzbRueWeiRPhXStmBF vjafNzAHn9hGIEceb22EAn2meF/wdxl5qigdeO7jGn9nwrU2bp9cWdJC8jtbqfU= X-Gm-Gg: ASbGncuS+BXeFNa1IvLjTNXaS8K7TdSpZMktOBYTjcgloE7c1vzl82lhA0ubrDAnQkE 6NBCB5hAwlDStY1WYXBLlUIz0LqqICulH+bJIblfYmKiD57YokLOjwNBi85gm74JQBWk0y3DKzt l8qJ7pE24aHb/I5rcem0lbozYdqg3JE44dgJVhjFoOyDvcfJ0k+FUHBApm8kzYME/wh94QbW+Jz UW5si0VWEtAG3jBpPXGdFZGvLZCwaJEbJCraKtdmVGz2A5+poiwgi+xIfwhPJU/ X-Google-Smtp-Source: AGHT+IG/t0YcxmPdoJ6ISqYYZH4iCdobwBVzdCsRkfIZj0ncdGkwuaaaKlCp32XDmBXWyFepH3EjlA== X-Received: by 2002:a05:651c:543:b0:2fb:cc0:2a05 with SMTP id 38308e7fff4ca-305f462586cmr32040641fa.37.1736508534986; Fri, 10 Jan 2025 03:28:54 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:28:53 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:45 +0200 Subject: [PATCH RFC/RFT v2 2/8] drm/display: add CEC helpers code MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-2-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=10706; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=3qw0nxZ6Zp0DIwWrz9kstqe0BFq7IIVKp+gE/6lrOcE=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBngQRuuGhtVUXT3QTJqE0B1Is1C6Uha61gULrG6 B408Fm3EKuJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1cGeB/47b+BAHqAZ0QS13y5qzjvXXSTVA0fAmZ9Z6r5KnCO/RcfTHTjcpMNPwbidEPlShNi/2/q lXCCk209+Qca/WgRCyZb0AcX0KNDNtZPItDbx1sia/cDZJQ82mfPilKMbIt8YL4JEfXaRy13SYL pbWNelvCA/Ap4GaBstcmSgqS6E3ShluQ2u7bwLOTipiF1la+/Rr3RV4hLZGM8bXFuHSY16cc0JM o9h2oK8inqEHIRGkHWZOW8q9LLwJv3+RyBuoMB4aWODI9sOi9h2LsAOkQQKtCwTOQsqlGtqPJec FRMBm4X5eJUfnS1k2kYOFswgIvU3OO2+NLe9lEz6tOR1rWKN 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 | 209 ++++++++++++++++++++++++++ include/drm/display/drm_hdmi_cec_helper.h | 61 ++++++++ 4 files changed, 277 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..8f6d66d813ca1981d827147d951aafe596151d97 --- /dev/null +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c @@ -0,0 +1,209 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright (c) 2024 Linaro Ltd + */ + +#include +#include +#include + +#include + +#include +#include + +void drm_connector_hdmi_cec_unregister(struct drm_connector *connector) +{ + cec_unregister_adapter(connector->cec.adapter); + connector->cec.adapter = NULL; + + cec_notifier_conn_unregister(connector->cec.notifier); + connector->cec.notifier = NULL; + + connector->cec.funcs = NULL; +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_unregister); + +static const struct drm_connector_cec_funcs drm_connector_hdmi_cec_funcs = { + .unregister = drm_connector_hdmi_cec_unregister, +}; + +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.funcs) { + 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.funcs = &drm_connector_hdmi_cec_funcs; + + mutex_unlock(&connector->cec.mutex); + + return 0; + +err_unlock: + mutex_unlock(&connector->cec.mutex); + + return ret; +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_notifier_register); + +#define to_hdmi_cec_adapter_ops(ops) \ + container_of(ops, struct drm_connector_hdmi_cec_adapter_ops, base) + +static int drm_connector_hdmi_cec_adap_enable(struct cec_adapter *adap, bool enable) +{ + struct drm_connector *connector = cec_get_drvdata(adap); + struct drm_connector_hdmi_cec_adapter_ops *ops = + to_hdmi_cec_adapter_ops(connector->cec.funcs); + + return ops->enable(connector, enable); +} + +static int drm_connector_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 logical_addr) +{ + struct drm_connector *connector = cec_get_drvdata(adap); + struct drm_connector_hdmi_cec_adapter_ops *ops = + to_hdmi_cec_adapter_ops(connector->cec.funcs); + + return ops->log_addr(connector, logical_addr); +} + +static int drm_connector_hdmi_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_connector_hdmi_cec_adapter_ops *ops = + to_hdmi_cec_adapter_ops(connector->cec.funcs); + + return ops->transmit(connector, attempts, signal_free_time, msg); +} + +static const struct cec_adap_ops drm_connector_hdmi_cec_adap_ops = { + .adap_enable = drm_connector_hdmi_cec_adap_enable, + .adap_log_addr = drm_connector_hdmi_cec_adap_log_addr, + .adap_transmit = drm_connector_hdmi_cec_adap_transmit, +}; + +int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector, + const struct drm_connector_hdmi_cec_adapter_ops *ops, + const char *name, + u8 available_las, + struct device *dev) +{ + struct cec_connector_info conn_info; + struct cec_adapter *cec_adap; + int ret; + + mutex_lock(&connector->cec.mutex); + + if (connector->cec.funcs) { + ret = -EBUSY; + goto err_unlock; + } + + if (!ops->base.unregister || + !ops->init || !!ops->enable || !ops->log_addr || !ops->transmit) + return -EINVAL; + + cec_adap = cec_allocate_adapter(&drm_connector_hdmi_cec_adap_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; + connector->cec.funcs = &ops->base; + + ret = ops->init(connector); + if (ret < 0) + goto err_delete_adapter; + + ret = cec_register_adapter(cec_adap, dev); + if (ret < 0) + goto err_delete_adapter; + + 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); + +void drm_connector_hdmi_cec_received_msg(struct drm_connector *connector, + struct cec_msg *msg) +{ + cec_received_msg(connector->cec.adapter, msg); +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_received_msg); + +void drm_connector_hdmi_cec_transmit_attempt_done(struct drm_connector *connector, + u8 status) +{ + cec_transmit_attempt_done(connector->cec.adapter, status); +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_transmit_attempt_done); + +void drm_connector_hdmi_cec_transmit_done(struct drm_connector *connector, + u8 status, + u8 arb_lost_cnt, u8 nack_cnt, + u8 low_drive_cnt, u8 error_cnt) +{ + cec_transmit_done(connector->cec.adapter, status, + arb_lost_cnt, nack_cnt, low_drive_cnt, error_cnt); +} +EXPORT_SYMBOL(drm_connector_hdmi_cec_transmit_done); + +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..b4d76b605017e4824ba2050018c05c7138bee258 --- /dev/null +++ b/include/drm/display/drm_hdmi_cec_helper.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: MIT */ + +#ifndef DRM_DISPLAY_HDMI_CEC_HELPER +#define DRM_DISPLAY_HDMI_CEC_HELPER + +#include + +#include + +struct drm_connector; + +struct cec_msg; +struct device; + +struct drm_connector_hdmi_cec_adapter_ops { + struct drm_connector_cec_funcs base; + + int (*init)(struct drm_connector *connector); + void (*uninit)(struct drm_connector *connector); + + int (*enable)(struct drm_connector *connector, bool enable); + int (*log_addr)(struct drm_connector *connector, u8 logical_addr); + int (*transmit)(struct drm_connector *connector, u8 attempts, + u32 signal_free_time, struct cec_msg *msg); +}; + +int drm_connector_hdmi_cec_adapter_register(struct drm_connector *connector, + const struct drm_connector_hdmi_cec_adapter_ops *ops, + const char *name, + u8 available_las, + struct device *dev); + +int drm_connector_hdmi_cec_notifier_register(struct drm_connector *connector, + const char *port_name, + struct device *dev); + +void drm_connector_hdmi_cec_unregister(struct drm_connector *connector); + +void drm_connector_hdmi_cec_received_msg(struct drm_connector *connector, + struct cec_msg *msg); + +void drm_connector_hdmi_cec_transmit_done(struct drm_connector *connector, + u8 status, + u8 arb_lost_cnt, u8 nack_cnt, + u8 low_drive_cnt, u8 error_cnt); + +void drm_connector_hdmi_cec_transmit_attempt_done(struct drm_connector *connector, + u8 status); +/* + * 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 Fri Jan 10 11:28:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934332 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 7B474E77188 for ; Fri, 10 Jan 2025 11:30:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DA31D10F074; Fri, 10 Jan 2025 11:29:59 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="l6yc5gI9"; dkim-atps=neutral Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2F8B810F074 for ; Fri, 10 Jan 2025 11:29:58 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-30227ccf803so15668121fa.2 for ; Fri, 10 Jan 2025 03:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508536; x=1737113336; 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=l6yc5gI9TBx5x7DzgP5qXmuwB/LHEb6z8bo1M4K1X7JHQB05I4P/YR2gUzuKLkJCbO bIhuGIG5EhpPxnYMJ55zanSrqY1ccZU4ughFglg2SupX9PrZRD+lG0bTtZ77LLnj+9WA gbm9umDNOrspnOzPRzVVmc8AdpS2JG+CiNIbKDfjXNnywOyAj7O22nG32Q+bhQAZzl/K G6K9ApQkXVhG6m57SG9437fvo3VLpZFVl3SG//NO5WshOW6HegWDQTGukTKubmUSlTt3 NtkLLhkTjWGZ5GCIreyRldDwLg3+cThazSgJJo5e/ZS5/hiprrWb9Uwmbe9W0XZVMFJP FZDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508536; x=1737113336; 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=apqD+Rz1Ds9Y2j4iR1J/FWmPFw7cYXAWLrXOwhFGSJYfNPTW9kFHEdYAnEFXAUaSEi BOybktsNKCUvtTqAWPCi6WARx+ESF3NMHc0rMdL5i09hG+FXVM+oOCZg6GQthnBmpYgP vfqcU1R91VBq5aDIb8x0LwjQ4luxJM7y47CVK2YthVb4/RclVS+EUtnW4q+WYTYejbRf TH7yAGFDS9xB2oXGuTVYqxdv9sBPx6uepAYWrEK5IuAS3YR+D4YN2lCFSqMaV9B6r2op e07VlxD6dvj79q2ePUSZBiMu5kx4zArAXPcrxnQM4009TDmwbOSvZeRL5iMXOQzkGP0i xQJw== X-Gm-Message-State: AOJu0Yw798mOmJFfQJsA5XxlPNCahQT0OiW77/kndiH3O5ntR+bU4Eu0 mVeD9G+vN3sAaATDdoyRJ/0i0gtlbUUdS0He4JwSq39HbBL2xx6aT5lX8bEnLh4= X-Gm-Gg: ASbGncuK9jwaxco1FcEi7INcsHkMv7P01jaHSZocDSiwFXtABiHeWosZATB6niF8RhS T62Nix1iss5LCVyPsLG95YgZ3OknWjQrHm9FR3bFIicmTxgVC1m3mYyKQQHBItCGnGh13IBfuX+ IKzsg2pASwZ6CZIxu7JT/CU+5oJehj7yT2doESzPKDV+XvizXrXHRcHcjmmPzjw7FP4IG+czAY3 GvCU9DUcjgjOGr9uN6zr2+YXgOpUgUOSu2rffS7scpgjSmmSg4YQi76p2WyaFs8 X-Google-Smtp-Source: AGHT+IEOPIMRVDtDLngWQv6T4mJCYf94Cls0yjVGrelXIXJN7WYv2+ZfXiTOIPUP1xGQ/AFV4XTzPA== X-Received: by 2002:a05:651c:505:b0:300:26bc:4311 with SMTP id 38308e7fff4ca-305f4560b73mr37374901fa.18.1736508536499; Fri, 10 Jan 2025 03:28:56 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:28:56 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:46 +0200 Subject: [PATCH RFC/RFT v2 3/8] drm/display: hdmi-state-helper: handle CEC physicall address MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-3-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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/pANAwAKAYs8ij4CKSjVAcsmYgBngQRuXgTmjpnV77bPG2LC26+aPczuLo/m1ppW9 3R6veBDEUSJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1f/vB/0aijxn/oGkAbYDK/tnKmfkOUE5zcXSkq3jWXc14Svo5QCOLNU0QjE1pq3Z5cHqrjAsXXP Z+ecOyJh1g+M6v+oQz5Bq0bwF1jWhJYGEyP6DXcDkD97wDWJ4plKOoHsjQQI7OpJaaqKRIfgBEm wd4olaWCVfZNSUHJkS/Fs2Mc45DKUVHcyBuc+FgknU31WH07hOzruJCnMnP/BDIB5LV+06fTvqC Lvd/uYt7ptVgCXUPWSSh0u/3sz+KQPP8EgH/LOuLesQl8uC0LXINqyw+toSMkVBhiwpvXNGk7Dr VYVRkWAN7EMEfrmjz6qY2piQ4Vy0wc9+n1fK3MITbM3RLHI3 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 Fri Jan 10 11:28:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934333 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 1CD49E7719D for ; Fri, 10 Jan 2025 11:30:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A12B10F075; Fri, 10 Jan 2025 11:30:01 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="uUK/W7Sd"; dkim-atps=neutral Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE40F10F076 for ; Fri, 10 Jan 2025 11:30:00 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-303548a933aso14526951fa.3 for ; Fri, 10 Jan 2025 03:30:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508539; x=1737113339; 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=jXLvAulPpr4jkjumE6jfbPSF3GlWNhWiDNTbhYjkW2k=; b=uUK/W7SdIZAsDZpH7vf+GVwQ1Jf7wwhTG7drG0P1o5L3hBFAHrPL7N6MU1R9ZzkKhB rApQKUxuxJ8VYHwtiPH3J8zqiUwl/NtVbeLRGErtJb151nuY1yuhzbCyvA0CuT65MGbj 2bcDA1d3tKYkuTqBwI8te9XQiBZqQVHDakBWL9EbUbVX+usxdu6W7KnN36uq91Rg+ivg FWp2eBPTH/vrxznvxBtCs3QL5zuK8PW4Av3cp/8re46ewkB83FIgztOmmtXHy3PEr7YI oFUHTc/q6ixepKpX2wWwogBPl58JIf3ez+C0Vj56BWY7FucqqkQfSSDVwdM3ybgHXg4A 1UkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508539; x=1737113339; 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=jXLvAulPpr4jkjumE6jfbPSF3GlWNhWiDNTbhYjkW2k=; b=VIpKpeIrlf7sCo22AgJQTy8vwTzbiHX+ptj2Xfan30GlMof5Rre/Wjbl/i8NRxor2E ALwHaIzsWxM0vAJn/+kliEMGjndzDzV+8W+N9A+9Ib1fu5zUSS5TL4usHtVbxS21XJGV 3FZl/gr8mSTkE5Kt+lmIf3HiF7alVaQ1CLyRdY6Qhd5s9zf4d/FoB4XKPH/keCNIdglG Pc87CqG1HbQNKyJmwLlMDazag/ciIQLmiSySoF0aG6GU9KhK0UsWRJ89+3YSuqMU7fsi Y+2iAG2MbGvzdIipO0G33lAHIKG4M2k09nczGRTcxA0xkb1y7kPwMgxtyX4pnNutRUQO n3Ag== X-Gm-Message-State: AOJu0Yz1u6uQkTlnkeAoyZeMOoyLYPlea2wEKiPBNWr7Vkssrdm/3uGt WEucoVR4TPJDOYyzxmFvDrvhS443ty7eKqypSnFe4MsLqNwy/CnpLwSfn8kZC0s= X-Gm-Gg: ASbGncvwAbEVezIqBLrmh2gHv0er+kHFBOhuL+xVYy49mGqpFkAl98prdzGanaLq440 FNfmhtVvGkvorNw5J+IZ0C5+PDU1iuxvO/K8EIJ82ZSBOlczbe+9cuyo7Yz6rOwPsJEn6TWP3VA TIti7fZoPCnDh08sm5bEQmK+Fq5tea5kQeXHCfCAxAc4itGBnkfpqSG8uLE3W7phlvVuN2mFsHH Y0zDfgFhkdEJaR7PRLGmF5RlcPJQW4M4uFzWkweBDFDlGwNuYeQVzS93gg25yaw X-Google-Smtp-Source: AGHT+IEe1K9Q7LiO1WkxXo1d8T5/rhk/cZHPgTBbPrPWZ9Xj7fuG8rwuRZTzyYxyigjgNMULiW+q2A== X-Received: by 2002:a2e:be09:0:b0:300:3a15:8f19 with SMTP id 38308e7fff4ca-305f45dc70dmr36643481fa.32.1736508538963; Fri, 10 Jan 2025 03:28:58 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:28:57 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:47 +0200 Subject: [PATCH RFC/RFT v2 4/8] drm/vc4: hdmi: switch to generic CEC helpers MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-4-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=10580; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=0ZotjbV1DxJPJdFPgp8OMTa7xwQM2FkLyaMbbSKa+Ac=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBngQRuDaGPSc1Bs32NHcUSP8ln1ODjEg3O3TU4n SyazyxHlcyJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1cVSB/wJwYDjKbpqen8xiMj1HCeZbe+k4NGmoKngk6nej+LHzjGepw6Rus4XTEAR2CVlT3PsGEs IbWi0Z3ByIANS4alzcFA9WSe/VCjq2L4dfnz3ctbO6iSmPy+rt2EKE1sDsr3pTjivXENpS9/1Gu PZRlr5AIbcEm85zqR0C7y/MF9VqRMIw7ELfzRHKZ9k5YD/qoOLOALi2HQ72kqZtW13EuNrwjsn9 FQ9/bfHwhQLTvCiPgORgQ4iesRlrHDR7rMUtP9xV87ZW0qbvsnI3msPQX887nUGqBw7Bk3vS5a1 eAGRrALsEJMfyUjP00JmY0bJiOeK0QZS/OHpo7KXLRHymleJ 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 | 132 ++++++++++++++++------------------------- drivers/gpu/drm/vc4/vc4_hdmi.h | 1 - 3 files changed, 52 insertions(+), 82 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..755c6454b3b71c753f8afc4651e74ec81dc5c6dc 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,8 +2381,8 @@ 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, - &vc4_hdmi->cec_rx_msg); + drm_connector_hdmi_cec_received_msg(&vc4_hdmi->connector, + &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; @@ -2564,9 +2557,9 @@ static irqreturn_t vc4_cec_irq_handler(int irq, void *priv) return ret; } -static int vc4_hdmi_cec_enable(struct cec_adapter *adap) +static int vc4_hdmi_cec_enable(struct drm_connector *connector) { - struct vc4_hdmi *vc4_hdmi = 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; @@ -2631,9 +2624,9 @@ static int vc4_hdmi_cec_enable(struct cec_adapter *adap) return 0; } -static int vc4_hdmi_cec_disable(struct cec_adapter *adap) +static int vc4_hdmi_cec_disable(struct drm_connector *connector) { - struct vc4_hdmi *vc4_hdmi = 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; @@ -2667,17 +2660,17 @@ static int vc4_hdmi_cec_disable(struct cec_adapter *adap) return 0; } -static int vc4_hdmi_cec_adap_enable(struct cec_adapter *adap, bool enable) +static int vc4_hdmi_cec_adap_enable(struct drm_connector *connector, bool enable) { if (enable) - return vc4_hdmi_cec_enable(adap); + return vc4_hdmi_cec_enable(connector); else - return vc4_hdmi_cec_disable(adap); + return vc4_hdmi_cec_disable(connector); } -static int vc4_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 log_addr) +static int vc4_hdmi_cec_adap_log_addr(struct drm_connector *connector, u8 log_addr) { - struct vc4_hdmi *vc4_hdmi = 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; @@ -2703,10 +2696,10 @@ static int vc4_hdmi_cec_adap_log_addr(struct cec_adapter *adap, u8 log_addr) return 0; } -static int vc4_hdmi_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, +static int vc4_hdmi_cec_adap_transmit(struct drm_connector *connector, u8 attempts, u32 signal_free_time, struct cec_msg *msg) { - struct vc4_hdmi *vc4_hdmi = 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; @@ -2749,84 +2742,66 @@ static int vc4_hdmi_cec_adap_transmit(struct cec_adapter *adap, u8 attempts, return 0; } -static const struct cec_adap_ops vc4_hdmi_cec_adap_ops = { - .adap_enable = vc4_hdmi_cec_adap_enable, - .adap_log_addr = vc4_hdmi_cec_adap_log_addr, - .adap_transmit = vc4_hdmi_cec_adap_transmit, -}; - -static void vc4_hdmi_cec_release(void *ptr) -{ - struct vc4_hdmi *vc4_hdmi = ptr; - - cec_unregister_adapter(vc4_hdmi->cec_adap); - vc4_hdmi->cec_adap = NULL; -} - -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); - if (ret < 0) - goto err_delete_cec_adap; + return 0; +} + +static const struct drm_connector_hdmi_cec_adapter_ops vc4_hdmi_cec_adap_ops = { + .base.unregister = drm_connector_hdmi_cec_unregister, + .init = vc4_hdmi_cec_init, + .enable = vc4_hdmi_cec_adap_enable, + .log_addr = vc4_hdmi_cec_adap_log_addr, + .transmit = vc4_hdmi_cec_adap_transmit, +}; + +static int vc4_hdmi_cec_register(struct vc4_hdmi *vc4_hdmi) +{ + struct platform_device *pdev = vc4_hdmi->pdev; + struct device *dev = &pdev->dev; + + if (!of_property_present(dev->of_node, "interrupts")) { + dev_warn(dev, "'interrupts' DT property is missing, no CEC\n"); + return 0; + } /* - * 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. + * NOTE: the CEC adapter will be unregistered from + * drm_connector_cleanup(), which is called from drm_dev_unplug() + * during device unbind. * * 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 @@ -2837,19 +2812,14 @@ static int vc4_hdmi_cec_init(struct vc4_hdmi *vc4_hdmi) * 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; - -err_delete_cec_adap: - cec_delete_adapter(vc4_hdmi->cec_adap); - - return ret; + return drm_connector_hdmi_cec_adapter_register(&vc4_hdmi->connector, + &vc4_hdmi_cec_adap_ops, + vc4_hdmi->variant->card_name, + 1, + &pdev->dev); } #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 +3241,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 Fri Jan 10 11:28:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934334 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 85CBDE7719C for ; Fri, 10 Jan 2025 11:30:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EC3DC10F077; Fri, 10 Jan 2025 11:30:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vs2P1TUv"; dkim-atps=neutral Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4175A10F077 for ; Fri, 10 Jan 2025 11:30:03 +0000 (UTC) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-53e3a227b82so1730131e87.0 for ; Fri, 10 Jan 2025 03:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508541; x=1737113341; 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=W/tqSb31qGGCwBlb1m0/W2hThVfhbDZ9QU4QBFYB05E=; b=vs2P1TUv8GQaZHMe5fUTwI2VErNR+W/3LL7zQklAzaBdzAXdR3GL0Jcd9rQikJY1UW TicMFJ+1Ng7rc0Rr7/BEXtt4TGaRn5Mwde4g09abfWXW/DgVqedfVjVkLA7LE9Sxxrod /1pdvC9lxJsoIkQdpHb1SzDy4I2lvmNmSte+PoITmwEO8SAMgqOGuHBz8XVcQBA/fBkt hK+54MhWEyLxC4Gd3sqYPuBxez5UEOhzfhdM6tNMsl5wt5sfmGL8uDYfNKAiX8H043Wk /zPg8srT8qm16viRtuTZupaRFylYkpz/HQxMvVgBfb6KhPKq1dOwnylcWEtrkRUuOJkt bUsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508541; x=1737113341; 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=W/tqSb31qGGCwBlb1m0/W2hThVfhbDZ9QU4QBFYB05E=; b=xTyshQC1p9BY0EAJQroNroFpB6R2bZ53Bcs81kCpnlRUssqOnmyjNXlnpK3nqtTgi3 xp5RrADAhC10IwI3E2l4FSe/p3lFYmF6dzCDvYDBSRtBGgciM6rUsz6d+FzsO3syfJqJ ZPMTmjxCAkpa0Swm1PPt5c3FynjoeJGsUbQm1MpHAu85INyjhdvtJqV5p5L81nuKhpew qY0saiPGKzca2YNdhHa1rU97mFIaLBk1cKS4fGbIj1PKRji0aXrHUnxPT/IcJ8Nh7rHG 7e8ldur0vcMcvaGQrCvic1ZuwKbz8k9mQ5o4I3ZUx9sA1mNgbSPZB9zNQ+IpOJQ3VySr uVHw== X-Gm-Message-State: AOJu0YwH6T0473AoEiz1jbrrYf39AuGkS322EFfxSW+6zH+c01UqX/Hf aZae+yavZar8O5updZkEQsS/mp+/aZhtQFZi/AOS98HlPNwgg9Kh8EpzoTqP/Sc= X-Gm-Gg: ASbGnctZgdmkf3T5/AzYIUQkA9/ZbcNAJlS3HCJM6j0AHiXQgRYRCQfqvvZtpD+LeIm X2AJgN/xbCjhfESG2QNuyuyxqyRJ8rKfsCIZvlys1Lo8gm8XtZ7QiZouEg4vZvqJ6m+JsX8RjN8 xlnAtnsb3M5gZmFgqMnUNSJWhFd0LWXVUMQehs/FcfpJCN90Pz42exbQt/eRm8w46orh/KV5GWO yJ495b7CBz2cG1rpPEa1a85XnE4PNhj3Ef8pdPeJ9MKZGy0R4+4kN60QjIIRfQj X-Google-Smtp-Source: AGHT+IHhxltgCHaHz0RpWVzZinhG2zG9rGhewcWu1qAIsyOS2v+ld6wbJKx2apoM8Z8I5cqyOGcYjw== X-Received: by 2002:a05:6512:114f:b0:542:1b6a:b476 with SMTP id 2adb3069b0e04-542845a6e3fmr2961801e87.7.1736508541496; Fri, 10 Jan 2025 03:29:01 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:29:00 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:48 +0200 Subject: [PATCH RFC/RFT v2 5/8] drm/display: bridge-connector: hook in CEC notifier support MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-5-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=b4oCscnxFqOQjxw6r241dx0Y/7ZqV4V9S3UFT8VHuZw=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBngQRu1ODTVx+2MoDccv0P1SZLBZWClocFuvy4c PA43qEOuH6JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1ckdCACEbgQTQdXF1XWpi5tWWZLD92j+uV6osStPBSjAefbhu/oGntH4J2FGKB/iPRxkMzGuDsw 1DP8jcxUNWsv35adX2J386EK6JGsdtrvcjD1RDUggYSw4RMNgOCnWW/b3X+g+yZgd0VqNFP4y9H XkP68ut+b0/MuQwKkCi3KBuBCN7v8rrtMxLFNjHmnw13CXrhMIVzhfpsjB7foomi/vadfoZpbkd g4hUOhLlcVJbQXpsLkbrLRW1lCdPoCJv9TJYYyO+WxkLIIXODOVJWRjLW3rdYC69TL+Zb1sCaP/ i2xGu0nIUxdGbLXsFNYOUcS6dMDJFBIY6qnSsydrAZFbmH8U 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 32108307de66560029ddf319169ac7d7e2af40d2..5f11243dea9c889e90a5074955f5a56208f8d622 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 Fri Jan 10 11:28:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934335 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 85B6CE77188 for ; Fri, 10 Jan 2025 11:30:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 081F110F07E; Fri, 10 Jan 2025 11:30:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="xW8njn1S"; dkim-atps=neutral Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by gabe.freedesktop.org (Postfix) with ESMTPS id 836A310F079 for ; Fri, 10 Jan 2025 11:30:05 +0000 (UTC) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-300392cc4caso16509481fa.3 for ; Fri, 10 Jan 2025 03:30:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508544; x=1737113344; 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=xW8njn1Ss6/eJZ6dg85NDOh8DQ2dP8BmNDSfFSlmIR3/lJT7tcivuQP0RivVokt18Q 2uFC15dfxv1enQpC86s5T0jEymqpHUg5h2wyuW7/p/u/ovNyewMj/JI1ER3eQ1VAjHlk +wob09RZGNdgtDqZOc+L8gcWedTEwp+E7BTLUfzZn4dOAHNt9o8+vO8KkIlP64zeUiQr woIBU2eANtdpz2IBN80CJutDMdNQP4Jh3ivEsFDFZ1C5WufES8S6jve72mQJsYauqYIK fR+da91b09CyWrxmOkJ264OGpfzKqhCW/CLKUy2BNW2cj4ASs4kUVQguR046Zu5Fh+QG XZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508544; x=1737113344; 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=p6deTACYIAWUAH8WC474ZJ7xwKJMdTGPNyMgTFRk+UzS6Sc5ViaSYnDSRHtzh9WiIh xPp5dt/errclqFBOuwL0YJV2z1uqwBysunNGtL1JNhSaHEjvfIec2lxQjjd06qlszbsi 6Zo8Awo4QzVb5jHvi+2Kv2yfAdFgpdaMNqp8hKW5zywctNkZ9HuibR+9TXEX42x62a+Z CpnWeFE6cF/YHRIQDzmPOv6w++Bnqbluldl8dsXmp9wXOQg26fLEVfVDgsqyQ1Zk4N+A KIL70ZAL3KRT5IXv/D2oIoNW9YqhYGiRnwPO6uYw3zIzyGVmLTyMFbByjRovaBMq7jAb lmfQ== X-Gm-Message-State: AOJu0Yw7r2H29H4Dw++faZnE187VmF/3u7KQtpERW3/px8uwk7PVtSym jiz6q40AQ+24Wn6AfSFzySv7zd8PiYPFUV0730ymzwczJW6viUuCz/HWecOmi5M= X-Gm-Gg: ASbGncszmJZQaW2/qY3FlHsqlaG7+SfHXeigq+j6fhIbyrn2gluf7ORQs72LEHY7yFX IBh9cxtPktJ2+e1+cYDuSSVSDM4toInNCo1iKw0/Idz2/ZyPlCdboxfxAKh627//+EBBKPJOJOr FQBDPj9r7BfnKkcGhEYJdlxmq5XjfLE4E4WCQLNNfWVCnoVGdpSgCOKgVoFw8u+oWwyQzpMmkrQ 1RLvyQ0o4w9cyGROjEXtRJm3TKSy+bUb8ft9Ka1l2l981IeNz/T8RaX5I2fKJd/ X-Google-Smtp-Source: AGHT+IELKchtP92aOpFw3XM5wlsKG8Uevo4+w3dzN0oJeZ9l75FlDd5o6YCfnywwrTl8ztwdLrA8dQ== X-Received: by 2002:a2e:be1d:0:b0:2ff:d81f:2d33 with SMTP id 38308e7fff4ca-305f4626544mr37979751fa.28.1736508543908; Fri, 10 Jan 2025 03:29:03 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.29.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:29:02 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:49 +0200 Subject: [PATCH RFC/RFT v2 6/8] drm/bridge: move private data to the end of the struct MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-6-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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/pANAwAKAYs8ij4CKSjVAcsmYgBngQRuvIK7/M5jESK6eq77ENHck1AvXhAiBpC1H Dlcg9pu5O6JATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbgAKCRCLPIo+Aiko 1V6WCACbF6mVItphA6yzidODsi++Cdnh365y83JVCTos76UZogo92z63gmq5yauLNtzbWrBJSpG FmUZG9WMrnpZvw0hlP6JVBKOpevS5bLLPiBCaA484esl7a7I9miciJ4zyxwwAs6Mn9FIqcHoPZE FxmRepqFRt73zTUywYwR+7nyJLT9MEGWkOPa8/vZYloqBDmGUU8UZgUbjpJmyk5+35sNia60JM6 K+WiuzYSoVEC6rsoU/RJXvUcV1RBz905Tdva/pk4bTK0TkYGbYKky/7l/FULo9GTkWVaWj5BVIC 8ytuBAlcmOiPyHHIK2mjw2jDnQwf7Yt9QSdOyO1/FXmpCETe 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 Fri Jan 10 11:28:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934336 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 DFD46E77188 for ; Fri, 10 Jan 2025 11:30:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 66A6E10F076; Fri, 10 Jan 2025 11:30:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vegPVVSf"; dkim-atps=neutral Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id E22AC10F07F for ; Fri, 10 Jan 2025 11:30:07 +0000 (UTC) Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-30167f4c1deso15555321fa.1 for ; Fri, 10 Jan 2025 03:30:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508546; x=1737113346; 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=/UIU8+/OFGECrtOiHmDAlFRm29snZGdSGyeHEE4qcYk=; b=vegPVVSfMXV7L5VlyWBw4nzslYkAcpcg/holkZBC7Ryrtvv9I7VkUeHpcISNzgpGi3 PzeDxC7lIoiXe+tFuGUS1j/vmcAy46/RO/Lm5rvKYlO/KZ/ohVUQ+Yo46N9k2HyzGLPL teLI/jAtXHby7WGl6Cvij6ugFNjaSVchiAsbuwS7XtKQr+/P63zhQoFCnrCjqwDxCerd y4xhPx/Ioj18boQMUgNZBUgJTMzvLx8rQLFQPEQD+ZGCMCJXYS0Q2D9FFfmfKdxbjaks hO8tkZopIj7MAdbBgVa/gkxfdMtS1YU1VQDAvmz24Fy6dml3RBa0GyS6AGqox4KP1vOe 9JZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508546; x=1737113346; 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=/UIU8+/OFGECrtOiHmDAlFRm29snZGdSGyeHEE4qcYk=; b=G6W7zSxGRNJAxuzOcuemFCZEnj39RZ9wmf/btLxO93ZKaM4d0vARJ3lXZcsLOtiic0 3XA63W/DLeLZPfeOqPzWbG7laje49+FE6pFECZ1btNKB5/E4XN0gbzTBwm3HQzEb6Ceo 23h5LYdr+Bxlagv2uqC9fTWMAcUM2eBVGD0MjFHvZ4Gmxhl3yIf+l2SFyNlZ0iQSLsja uMyE4L2fmUr+36u458y1/gqSMaoJv8lFquTpG6ZPuL6hQ1DPT/vrnMIvLDa+YBlQ78Pb 2h3tvjenSJOoia13mN0FKWSyPS/4G4ZBDsCPl0SX3fUmJsw3Xj6MUD372LNrDiqcGI8Z qBEw== X-Gm-Message-State: AOJu0Yz18fPEOin3F9mfIrvYrmKpgWLnKMGNsgkexDgqYoz57h5Ar5xq 4qUvTEhGOEE53oDZFKu4PKaiwDyRMYj4B6/oOcHlu8a6hv094f1Bvw8o7BLsbN4= X-Gm-Gg: ASbGncvLWxAPJWALGvOF2gti6KDC/ho+pLS4KC3ByWO7VZqJUrHsC548O0d7ds5mcom Kd+JodEfWBPrTTNEC9hpzkaj7elGrCQoX195OofF+E5sP0u8CQBmerPmuOAnVE62tOrTEu5L/7c Oo8Vn29VanMWLWAkIWgqdrdBds6CJOayWTe6LoxHviq8nkGh8Tq5RwXrlP9DVM1C68WeYtcCKRm YmKcIryP0x9FuC+UzvbBB0NTTkH5d3N7+zvpvhReQd9nR/VmUtQZPRizsRF1Tmn X-Google-Smtp-Source: AGHT+IH4tmBunOAbZD3tkCTayg2Su5G96QZkPq0CESPADlHHvyj2u9kTJYKconf8AwE9q4O/CPJTZw== X-Received: by 2002:a05:651c:1415:b0:302:3356:3a98 with SMTP id 38308e7fff4ca-305f45fc6c9mr24401721fa.37.1736508546260; Fri, 10 Jan 2025 03:29:06 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:29:05 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:50 +0200 Subject: [PATCH RFC/RFT v2 7/8] drm/display: hdmi-cec-helper: add bridge-related functions MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-7-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=5536; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=ZlamDX7RUQmt18Od9tY7nbhEE651D+BmJ29Xlgw91xs=; b=owGbwMvMwMXYbdNlx6SpcZXxtFoSQ3ojS37Qv+kBE7ht5x1+b3i15FNlapnbSbX0e8v59Y5wf w7fX8rcyWjMwsDIxSArpsjiU9AyNWZTctiHHVPrYQaxMoFMYeDiFICJlF1l/58Q5r/23lzDLVZL Th1gyK1wEj4uWahz3qaxp6qt7P0EzunKTZtCeoX2qEmuvFPgWWaYv1cwbKYEJ0umxfcFFY22Rkm 3Qk4aXI/Rsf9UGD43TeWpzc+K+Q+WeEvudZz96XHR/XafPbuS1j4Tq+bSTdZ9rfJ9ztdFp7NXOu jY3gyIUuj8mzq9z8jQ7yfbnqx9KhWcV/+bHl00obgk9g33v/9nvAqSv8o5ZW1oCFaZxKZcYXtjK WPztM/iLxK2/Ix9kirl0lAdYnzv/qbZO2sMT8d5FtnoVf2OXFzCbdm/jjlzmqzTI8adQu5PvWKO HD7uJG2ZcGznJed6oYn6CzKXNsnGsJ63WxW97fuNk4JzAA== 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 | 9 +++++++ include/drm/drm_bridge.h | 13 ++++++++++ 4 files changed, 75 insertions(+) diff --git a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c index 8f6d66d813ca1981d827147d951aafe596151d97..6f60f092a9ad1369824170e6bd996849f4060cc8 100644 --- a/drivers/gpu/drm/display/drm_hdmi_cec_helper.c +++ b/drivers/gpu/drm/display/drm_hdmi_cec_helper.c @@ -207,3 +207,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 b4d76b605017e4824ba2050018c05c7138bee258..b8a820d5d774e3fb9c7f982cb7dee588e3292f42 100644 --- a/include/drm/display/drm_hdmi_cec_helper.h +++ b/include/drm/display/drm_hdmi_cec_helper.h @@ -7,6 +7,7 @@ #include +struct drm_bridge; struct drm_connector; struct cec_msg; @@ -58,4 +59,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 Fri Jan 10 11:28:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Baryshkov X-Patchwork-Id: 13934337 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 DAFB2E7719C for ; Fri, 10 Jan 2025 11:30:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D90210F080; Fri, 10 Jan 2025 11:30:11 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="HLDIIwX3"; dkim-atps=neutral Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3F85010F080 for ; Fri, 10 Jan 2025 11:30:10 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-3011c7b39c7so16725841fa.1 for ; Fri, 10 Jan 2025 03:30:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1736508549; x=1737113349; 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=8+YIB52U4I0egsUniMdB1l3nr9fwGImyIeykNsvRPmg=; b=HLDIIwX30kBdjJ7kqyPJW2uuWli+5agEMTdgR/LAynvg1G/qjsJlzcoyAI9jSqpxo0 4YYxG3Jk4EOGYSdYFxNsRJIAnwSMxs7NahHeklJF1m13X0uGHH76IWIX0zxjO1D2Hj7q Q6tsIW/WJ4vBl5mvUpZWlwsX/UkodUh6uWYfIpcHC3uwW/FzAbpsVJzqj/WYmrbg/NdP uuVVOX/Bf5be6s020rqkdXC3Xm0F37dM2yFXn0xh5vRVdduowhMZgOd+epJCfU7YczV4 cYP3NJmBXXfsxVhBzWcqTji0ILGwFiq7ADeYs75b1Q+8zEsrDiuEUYtsju5QrGxkCAGP 9IKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736508549; x=1737113349; 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=8+YIB52U4I0egsUniMdB1l3nr9fwGImyIeykNsvRPmg=; b=D4rxFSfv6DgZ2AGLG+Yy8LkaUonzWttZ9FvQrBubIyFP4/GgTjVpwZiH2hgTOq7SMC BRKR7ayzJgq1280YR8l7NxilE6CxSk30yPp+3VqJrJpi+GDgQZ7qfu6cEofir7kwG0fY JasGbHvPPTMK2TXcH/k7hIOiqnaXOsSTLIkBpjTcs0oE8mIAwIlUWtUyBpAlesZmDwC4 s9l8ecmz+00NjlFjT06mmAO3yqn5iNaqv6HXUoKu54LBG9EMguYU6P1mGv999YJeyVvp UiPX+QMfGAKR1wv4DbrUvitV9z2YddljnrT0Z2e2eaLOLl2CFBq7CZ4jkb+2lH1Ntmhi 6DzA== X-Gm-Message-State: AOJu0YxyBxGq8aa7jd6rHUbgw9XRyuXkomCZKW+T+qBU66UKoZydWP71 pLfnEay++TgQlaxcBzaDCc3URDGE+uaMI5pBwSAkoj8rU56AmziuDQ1KimJRFhs= X-Gm-Gg: ASbGncvhPf//IGOmBUJ1MG4SF9VT1GoMylQ944/yFEwd+FvxmQHDtts8xVt5YQe9U/O L/m0xrykRG2AE0NSuM8+PoJ1x4qf7geVpqUEOQoqbNT8cSIcebOdIEqbj0a6MJSw+XdoMQ5PJDr 6ETxMk71WCyptl3Es66YFeLjnbtrRyDV9iiLhZ7El1txrbQhqRMGRd3+AfAwDfYNhHKhQDcvhMW eCtykls+yJrUSYHvEYijjKWBukZaKkaJpMbdRyAOW+NK7DZEybi1YvWIoV8H8NF X-Google-Smtp-Source: AGHT+IGGO0hV7d+zOhOaSbmlFHHH9MeNC5ZrAqEpzlzaPMm6YljCQcX1Sz/YlUFHdHm3aOjtVorpBA== X-Received: by 2002:a05:651c:2222:b0:300:38ff:f8e2 with SMTP id 38308e7fff4ca-305f453f9d5mr31201951fa.10.1736508548618; Fri, 10 Jan 2025 03:29:08 -0800 (PST) Received: from umbar.lan ([192.130.178.90]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-305ff1c78e8sm4711081fa.86.2025.01.10.03.29.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 03:29:07 -0800 (PST) From: Dmitry Baryshkov Date: Fri, 10 Jan 2025 13:28:51 +0200 Subject: [PATCH RFC/RFT v2 8/8] drm/display: bridge-connector: handle CEC adapters MIME-Version: 1.0 Message-Id: <20250110-drm-hdmi-connector-cec-v2-8-9067c8f34663@linaro.org> References: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@linaro.org> In-Reply-To: <20250110-drm-hdmi-connector-cec-v2-0-9067c8f34663@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=5677; i=dmitry.baryshkov@linaro.org; h=from:subject:message-id; bh=BwAZN8edy4A87oLbta1XuTrc0RKbA56lgaUrctITA/4=; b=owEBbQGS/pANAwAKAYs8ij4CKSjVAcsmYgBngQRv/bgC+zrUD+iX8UWyTXDUsJSZHnTGhXuTR +34osXvuliJATMEAAEKAB0WIQRMcISVXLJjVvC4lX+LPIo+Aiko1QUCZ4EEbwAKCRCLPIo+Aiko 1aeZB/9h3I/U9zJZbqCmtLmblFpi07dcQwlq9LQ0/65WSXneGkmf/DE5B0X+oGArfKCFRN5excx 8JxnXC5QeM3/RJ1o5m1xp/mQ+aGMybyLTC58KUEfVf037NxdQb3hs5jARGV0DxOFSy65uvivF8S HgdfOvfLxrLVk/tY3V4/xAcWIKp8Ud4oXQ9WGyt95YXrak28Vfxp1XIKepXu/V3RXoPSCSQZ1RP iiBDPfisexIUFPrIhzcEmk5fOZ4otunhl1DnOyZQVPxdiAjqYJi4i3xBEgfvAev06T3Vg3gag8B HNKviR3lWuUJ0uHGOGd3C8CoxuzuflYKJzMfqa5l11ffFwE7 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 5f11243dea9c889e90a5074955f5a56208f8d622..42d670f9781a47688c9620660078dc8f5ae49fa5 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,82 @@ 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_hdmi_cec_enable(struct drm_connector *connector, bool enable) +{ + 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_enable(bridge, enable); +} + +static int drm_bridge_connector_hdmi_cec_log_addr(struct drm_connector *connector, u8 logical_addr) +{ + 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_log_addr(bridge, logical_addr); +} + +static int drm_bridge_connector_hdmi_cec_transmit(struct drm_connector *connector, + u8 attempts, + u32 signal_free_time, + struct cec_msg *msg) +{ + 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_transmit(bridge, attempts, + signal_free_time, + msg); +} + +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_init) + return 0; + + return bridge->funcs->hdmi_cec_init(connector, bridge); +} + +static void drm_bridge_connector_hdmi_cec_unregister(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); + + drm_connector_hdmi_cec_unregister(connector); +} + +static const struct drm_connector_hdmi_cec_adapter_ops drm_bridge_connector_hdmi_cec_ops = { + .base.unregister = drm_bridge_connector_hdmi_cec_unregister, + .init = drm_bridge_connector_hdmi_cec_init, + .enable = drm_bridge_connector_hdmi_cec_enable, + .log_addr = drm_bridge_connector_hdmi_cec_log_addr, + .transmit = drm_bridge_connector_hdmi_cec_transmit, +}; + + /* ----------------------------------------------------------------------------- * Bridge Connector Initialisation */ @@ -633,6 +711,23 @@ 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_enable || + !bridge->funcs->hdmi_cec_log_addr || + !bridge->funcs->hdmi_cec_transmit) + return ERR_PTR(-EINVAL); + + ret = drm_connector_hdmi_cec_adapter_register(connector, + &drm_bridge_connector_hdmi_cec_ops, + bridge->hdmi_cec_adapter_name, + num_las, + 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..bbfbb50fddf9b12f6e573ba79d1f13641515bd47 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_init)(struct drm_connector *connector, + struct drm_bridge *bridge); + + int (*hdmi_cec_enable)(struct drm_bridge *bridge, + bool enable); + + int (*hdmi_cec_log_addr)(struct drm_bridge *bridge, + u8 logical_addr); + + int (*hdmi_cec_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.