@@ -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)
@@ -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
@@ -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);
@@ -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);
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(+)