[PATCH RFC v2 3/3] drm/panel: Introduce simulated panel bridge API

Jessica Zhang posted 3 patches 1 month, 2 weeks ago
[PATCH RFC v2 3/3] drm/panel: Introduce simulated panel bridge API
Posted by Jessica Zhang 1 month, 2 weeks ago
Add separate bridge and drm_panel API for getting the simulated panel.
If the panel_simulation kernel module is enabled, the DRM framework will
get the sim panel bridge instead of the physical panel or bridge.

Signed-off-by: Jessica Zhang <quic_jesszhan@quicinc.com>
---
 drivers/gpu/drm/bridge/panel.c | 28 ++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_panel.c    | 33 +++++++++++++++++++++++++++++++++
 include/drm/drm_bridge.h       |  1 +
 include/drm/drm_panel.h        |  1 +
 4 files changed, 63 insertions(+)

diff --git a/drivers/gpu/drm/bridge/panel.c b/drivers/gpu/drm/bridge/panel.c
index 6e88339dec0f5faee690b7c53e8dcd0f1ee2281c..e703a770a86e60887ecb669011f311210fac695e 100644
--- a/drivers/gpu/drm/bridge/panel.c
+++ b/drivers/gpu/drm/bridge/panel.c
@@ -482,6 +482,30 @@ struct drm_connector *drm_panel_bridge_connector(struct drm_bridge *bridge)
 }
 EXPORT_SYMBOL(drm_panel_bridge_connector);
 
+/**
+ * drm_get_sim_panel_bridge - return the simulated panel bridge
+ * @dev: device to tie the bridge lifetime to
+ *
+ * This function will return a bridge for the simulated panel.
+ *
+ * Returns a pointer to the bridge if successful, or an error pointer
+ * otherwise.
+ */
+struct drm_bridge *drm_get_sim_panel_bridge(struct device *dev)
+{
+	struct drm_bridge *bridge;
+	struct drm_panel *panel;
+
+	panel = drm_find_sim_panel();
+	if (IS_ERR(panel))
+		return ERR_PTR(-EPROBE_DEFER);
+
+	bridge = devm_drm_panel_bridge_add(dev, panel);
+
+	return bridge;
+}
+EXPORT_SYMBOL(drm_get_sim_panel_bridge);
+
 #ifdef CONFIG_OF
 /**
  * devm_drm_of_get_bridge - Return next bridge in the chain
@@ -505,6 +529,10 @@ struct drm_bridge *devm_drm_of_get_bridge(struct device *dev,
 	struct drm_panel *panel;
 	int ret;
 
+	bridge = drm_get_sim_panel_bridge(dev);
+	if (!IS_ERR(bridge))
+		return bridge;
+
 	ret = drm_of_find_panel_or_bridge(np, port, endpoint,
 					  &panel, &bridge);
 	if (ret)
diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c
index 19ab0a794add31f34275d53dfab0a7c0050476e3..1e532f8e5bff99467f058fe0a441141c80ca95d6 100644
--- a/drivers/gpu/drm/drm_panel.c
+++ b/drivers/gpu/drm/drm_panel.c
@@ -313,6 +313,39 @@ int drm_panel_get_modes(struct drm_panel *panel,
 }
 EXPORT_SYMBOL(drm_panel_get_modes);
 
+/**
+ * drm_find_sim_panel - look up the simulated panel
+ *
+ * Searches for the simulated panel in the panel list.
+ *
+ * Return: A pointer to the simulated panel or an ERR_PTR() if the simulated
+ * panel was not found in the panel list.
+ *
+ * Possible error codes returned by this function:
+ * - EPROBE_DEFER: the panel device has not been probed yet, and the caller
+ *   should retry later
+ */
+struct drm_panel *drm_find_sim_panel(void)
+{
+	struct drm_panel *panel;
+
+	mutex_lock(&panel_lock);
+
+	list_for_each_entry(panel, &panel_list, list) {
+		bool is_sim_panel = !strncmp(panel->dev->driver->name,
+				"panel_simulation",
+				strlen("panel_simulation"));
+		if (is_sim_panel) {
+			mutex_unlock(&panel_lock);
+			return panel;
+		}
+	}
+
+	mutex_unlock(&panel_lock);
+	return ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL(drm_find_sim_panel);
+
 #ifdef CONFIG_OF
 /**
  * of_drm_find_panel - look up a panel using a device tree node
diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h
index 75019d16be643ae87f756e131a079feffd9b4d59..8c1ae06ecbcdb2e9d1fba6845bd85a54a9643502 100644
--- a/include/drm/drm_bridge.h
+++ b/include/drm/drm_bridge.h
@@ -1006,6 +1006,7 @@ static inline int drm_panel_bridge_set_orientation(struct drm_connector *connect
 }
 #endif
 
+struct drm_bridge *drm_get_sim_panel_bridge(struct device *dev);
 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL_BRIDGE)
 struct drm_bridge *devm_drm_of_get_bridge(struct device *dev, struct device_node *node,
 					  u32 port, u32 endpoint);
diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h
index 10015891b056f816c7a992a2052b36fd26943c5b..c3a5944c35a911b809a6567040cea7bc7da07ba6 100644
--- a/include/drm/drm_panel.h
+++ b/include/drm/drm_panel.h
@@ -283,6 +283,7 @@ int drm_panel_enable(struct drm_panel *panel);
 int drm_panel_disable(struct drm_panel *panel);
 
 int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector);
+struct drm_panel *drm_find_sim_panel(void);
 
 #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL)
 struct drm_panel *of_drm_find_panel(const struct device_node *np);

-- 
2.34.1