[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241225-drm-hdmi-connector-cec-v1-8-b80380c67221@linaro.org>
Date: Wed, 25 Dec 2024 01:10:16 +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 8/9] drm/display: hdmi-cec-helper: add
bridge-related functions
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 <dmitry.baryshkov@...aro.org>
---
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 <linux/types.h>
+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 <drm/drm_mode_object.h>
#include <drm/drm_modes.h>
+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);
--
2.39.5
Powered by blists - more mailing lists