[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250110-drm-hdmi-connector-cec-v2-7-9067c8f34663@linaro.org>
Date: Fri, 10 Jan 2025 13:28:50 +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 v2 7/8] 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 | 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 <linux/types.h>
+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 <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