[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241225-drm-hdmi-connector-cec-v1-1-b80380c67221@linaro.org>
Date: Wed, 25 Dec 2024 01:10:09 +0200
From: Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
To: Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
Dave Stevenson <dave.stevenson@...pberrypi.com>,
MaĆra Canal <mcanal@...lia.com>,
Raspberry Pi Kernel Maintenance <kernel-list@...pberrypi.com>,
Andrzej Hajda <andrzej.hajda@...el.com>,
Neil Armstrong <neil.armstrong@...aro.org>, Robert Foss <rfoss@...nel.org>,
Laurent Pinchart <Laurent.pinchart@...asonboard.com>,
Jonas Karlman <jonas@...boo.se>, Jernej Skrabec <jernej.skrabec@...il.com>
Cc: dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: [PATCH RFC/RFT 1/9] drm/connector: add CEC-related fields
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 <dmitry.baryshkov@...aro.org>
---
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;
--
2.39.5
Powered by blists - more mailing lists