drm/bridge: Add debugfs print for bridge chains
authorTomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Wed, 2 Aug 2023 07:04:11 +0000 (10:04 +0300)
committerNeil Armstrong <neil.armstrong@linaro.org>
Wed, 2 Aug 2023 08:05:01 +0000 (10:05 +0200)
DRM bridges are not visible to the userspace and it may not be
immediately clear if the chain is somehow constructed incorrectly. I
have had two separate instances of a bridge driver failing to do a
drm_bridge_attach() call, resulting in the bridge connector not being
part of the chain. In some situations this doesn't seem to cause issues,
but it will if DRM_BRIDGE_ATTACH_NO_CONNECTOR flag is used.

Add a debugfs file to print the bridge chains. For me, on this TI AM62
based platform, I get the following output:

encoder[39]
bridge[0] type: 0, ops: 0x0
bridge[1] type: 0, ops: 0x0, OF: /bus@f0000/i2c@20000000/dsi@e:toshiba,tc358778
bridge[2] type: 0, ops: 0x3, OF: /bus@f0000/i2c@20010000/hdmi@48:lontium,lt8912b
bridge[3] type: 11, ops: 0x7, OF: /hdmi-connector:hdmi-connector

Tested-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20230802-drm-bridge-chain-debugfs-v4-1-7e3ae3d137c0@ideasonboard.com
drivers/gpu/drm/drm_bridge.c
drivers/gpu/drm/drm_debugfs.c
include/drm/drm_bridge.h

index c3d69af..39e68e4 100644 (file)
 #include <linux/mutex.h>
 
 #include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_debugfs.h>
 #include <drm/drm_bridge.h>
 #include <drm/drm_encoder.h>
+#include <drm/drm_file.h>
 #include <drm/drm_of.h>
 #include <drm/drm_print.h>
 
@@ -1345,6 +1347,50 @@ struct drm_bridge *of_drm_find_bridge(struct device_node *np)
 EXPORT_SYMBOL(of_drm_find_bridge);
 #endif
 
+#ifdef CONFIG_DEBUG_FS
+static int drm_bridge_chains_info(struct seq_file *m, void *data)
+{
+       struct drm_debugfs_entry *entry = m->private;
+       struct drm_device *dev = entry->dev;
+       struct drm_printer p = drm_seq_file_printer(m);
+       struct drm_mode_config *config = &dev->mode_config;
+       struct drm_encoder *encoder;
+       unsigned int bridge_idx = 0;
+
+       list_for_each_entry(encoder, &config->encoder_list, head) {
+               struct drm_bridge *bridge;
+
+               drm_printf(&p, "encoder[%u]\n", encoder->base.id);
+
+               drm_for_each_bridge_in_chain(encoder, bridge) {
+                       drm_printf(&p, "\tbridge[%u] type: %u, ops: %#x",
+                                  bridge_idx, bridge->type, bridge->ops);
+
+#ifdef CONFIG_OF
+                       if (bridge->of_node)
+                               drm_printf(&p, ", OF: %pOFfc", bridge->of_node);
+#endif
+
+                       drm_printf(&p, "\n");
+
+                       bridge_idx++;
+               }
+       }
+
+       return 0;
+}
+
+static const struct drm_debugfs_info drm_bridge_debugfs_list[] = {
+       { "bridge_chains", drm_bridge_chains_info, 0 },
+};
+
+void drm_bridge_debugfs_init(struct drm_minor *minor)
+{
+       drm_debugfs_add_files(minor->dev, drm_bridge_debugfs_list,
+                             ARRAY_SIZE(drm_bridge_debugfs_list));
+}
+#endif
+
 MODULE_AUTHOR("Ajay Kumar <ajaykumar.rs@samsung.com>");
 MODULE_DESCRIPTION("DRM bridge infrastructure");
 MODULE_LICENSE("GPL and additional rights");
index a3a4882..2de43ff 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_auth.h>
+#include <drm/drm_bridge.h>
 #include <drm/drm_client.h>
 #include <drm/drm_debugfs.h>
 #include <drm/drm_device.h>
@@ -274,6 +275,7 @@ int drm_debugfs_init(struct drm_minor *minor, int minor_id,
 
        if (drm_drv_uses_atomic_modeset(dev)) {
                drm_atomic_debugfs_init(minor);
+               drm_bridge_debugfs_init(minor);
        }
 
        if (drm_core_check_feature(dev, DRIVER_MODESET)) {
index bf964cd..c339fc8 100644 (file)
@@ -36,6 +36,7 @@ struct drm_bridge;
 struct drm_bridge_timings;
 struct drm_connector;
 struct drm_display_info;
+struct drm_minor;
 struct drm_panel;
 struct edid;
 struct i2c_adapter;
@@ -949,4 +950,6 @@ static inline struct drm_bridge *drmm_of_get_bridge(struct drm_device *drm,
 }
 #endif
 
+void drm_bridge_debugfs_init(struct drm_minor *minor);
+
 #endif