Skip to contentSkip to conversation

drm/bridge/synopsys: dsi: Allow VPG to be enabled via debugfs

PATCH Superseded Matt Redfearn 2 participants 3 messages Apr 24, 2019 – Apr 25, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge/synopsys: dsi: Allow VPG to be enabled via debugfs

The Synopsys MIPI DSI IP contains a video test pattern generator which is helpful in debugging video timing with connected displays. Add a debugfs directory containing files which allow the VPG to be enabled and disabled, and it's orientation to be changed.

---

 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +55 -0
index 0ee440216b8..a1ee2306382 100644
@@ -10,6 +10,7 @@
 
 #include <linux/clk.h>
 #include <linux/component.h>
+#include <linux/debugfs.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
@@ -86,6 +87,8 @@
 #define VID_MODE_TYPE_NON_BURST_SYNC_EVENTS	0x1
 #define VID_MODE_TYPE_BURST			0x2
 #define VID_MODE_TYPE_MASK			0x3
+#define VID_MODE_VPG_ENABLE		BIT(16)
+#define VID_MODE_VPG_HORIZONTAL		BIT(24)
 
 #define DSI_VID_PKT_SIZE		0x3c
 #define VID_PKT_SIZE(p)			((p) & 0x3fff)
@@ -234,6 +237,15 @@ struct dw_mipi_dsi {
 	u32 format;
 	unsigned long mode_flags;
 
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs_root;
+	struct dentry *debugfs_vpg;
+	struct dentry *debugfs_vpg_horizontal;
+
+	bool vpg;
+	bool vpg_horizontal;
+#endif /* CONFIG_DEBUG_FS */
+
 	struct dw_mipi_dsi *master; /* dual-dsi master ptr */
 	struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */
 
@@ -525,6 +537,11 @@ static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi)
 	else
 		val |= VID_MODE_TYPE_NON_BURST_SYNC_EVENTS;
 
+	if (dsi->vpg) {
+		val |= VID_MODE_VPG_ENABLE;
+		val |= dsi->vpg_horizontal ? VID_MODE_VPG_HORIZONTAL : 0;
+	}
+
 	dsi_write(dsi, DSI_VID_MODE_CFG, val);
 }
 
@@ -935,6 +952,41 @@ static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = {
 	.attach	      = dw_mipi_dsi_bridge_attach,
 };
 
+#ifdef CONFIG_DEBUG_FS
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi)
+{
+	struct dentry *d;
+
+	d = debugfs_create_dir(dev_name(dsi->dev), NULL);
+	if (IS_ERR(d)) {
+		dev_err(dsi->dev, "failed to create debugfs root\n");
+		return;
+	}
+	dsi->debugfs_root = d;
+
+	d = debugfs_create_bool("vpg", 0660, dsi->debugfs_root, &dsi->vpg);
+	dsi->debugfs_vpg = d;
+
+	d = debugfs_create_bool("vpg_horizontal", 0660, dsi->debugfs_root,
+				&dsi->vpg_horizontal);
+	dsi->debugfs_vpg_horizontal = d;
+}
+
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi)
+{
+	debugfs_remove(dsi->debugfs_vpg_horizontal);
+	debugfs_remove(dsi->debugfs_vpg);
+	debugfs_remove(dsi->debugfs_root);
+}
+
+#else
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) { }
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) { }
+
+#endif /* CONFIG_DEBUG_FS */
+
 static struct dw_mipi_dsi *
 __dw_mipi_dsi_probe(struct platform_device *pdev,
 		    const struct dw_mipi_dsi_plat_data *plat_data)
@@ -1005,6 +1057,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 		clk_disable_unprepare(dsi->pclk);
 	}
 
+	dw_mipi_dsi_debugfs_init(dsi);
 	pm_runtime_enable(dev);
 
 	dsi->dsi_host.ops = &dw_mipi_dsi_host_ops;
@@ -1012,6 +1065,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 	ret = mipi_dsi_host_register(&dsi->dsi_host);
 	if (ret) {
 		dev_err(dev, "Failed to register MIPI host: %d\n", ret);
+		dw_mipi_dsi_debugfs_remove(dsi);
 		return ERR_PTR(ret);
 	}
 
@@ -1029,6 +1083,7 @@ static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi)
 	mipi_dsi_host_unregister(&dsi->dsi_host);
 
 	pm_runtime_disable(dsi->dev);
+	dw_mipi_dsi_debugfs_remove(dsi);
 }
 
 void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Matt Redfearn

The Synopsys MIPI DSI IP contains a video test pattern generator which is helpful in debugging video timing with connected displays. Add a debugfs directory containing files which allow the VPG to be enabled and disabled, and it's orientation to be changed.

s/it's/its/

Quoted 46 lines

---

 drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 55 +++++++++++++++++++
 1 file changed, 55 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +12 -0
index 0ee440216b8..a1ee2306382 100644
@@ -10,6 +10,7 @@
 
 #include <linux/clk.h>
 #include <linux/component.h>
+#include <linux/debugfs.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
@@ -86,6 +87,8 @@
 #define VID_MODE_TYPE_NON_BURST_SYNC_EVENTS	0x1
 #define VID_MODE_TYPE_BURST			0x2
 #define VID_MODE_TYPE_MASK			0x3
+#define VID_MODE_VPG_ENABLE		BIT(16)
+#define VID_MODE_VPG_HORIZONTAL		BIT(24)
 
 #define DSI_VID_PKT_SIZE		0x3c
 #define VID_PKT_SIZE(p)			((p) & 0x3fff)
@@ -234,6 +237,15 @@ struct dw_mipi_dsi {
 	u32 format;
 	unsigned long mode_flags;
 
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs_root;
+	struct dentry *debugfs_vpg;
+	struct dentry *debugfs_vpg_horizontal;
+
+	bool vpg;
+	bool vpg_horizontal;
+#endif /* CONFIG_DEBUG_FS */
+
 	struct dw_mipi_dsi *master; /* dual-dsi master ptr */
 	struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */
 

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi) · line 540

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +1 -0
@@ -525,6 +537,11 @@ static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi)
 	else
 		val |= VID_MODE_TYPE_NON_BURST_SYNC_EVENTS;
 
+	if (dsi->vpg) {

Won't this break if CONFIG_DDEBUG_FS is not defined ?

Quoted 16 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +9 -0
+		val |= VID_MODE_VPG_ENABLE;
+		val |= dsi->vpg_horizontal ? VID_MODE_VPG_HORIZONTAL : 0;
+	}
+
 	dsi_write(dsi, DSI_VID_MODE_CFG, val);
 }
 
@@ -935,6 +952,41 @@ static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = {
 	.attach	      = dw_mipi_dsi_bridge_attach,
 };
 
+#ifdef CONFIG_DEBUG_FS
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi)
+{
+	struct dentry *d;

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = { · line 969

Quoted 10 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +10 -0
+
+	d = debugfs_create_dir(dev_name(dsi->dev), NULL);
+	if (IS_ERR(d)) {
+		dev_err(dsi->dev, "failed to create debugfs root\n");
+		return;
+	}
+	dsi->debugfs_root = d;
+
+	d = debugfs_create_bool("vpg", 0660, dsi->debugfs_root, &dsi->vpg);
+	dsi->debugfs_vpg = d;

If you don't handle failures here you don't need the intermediate d variable, you can just assign dsi->debugfs_vpg directly.

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = { · line 973

Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +4 -0
+
+	d = debugfs_create_bool("vpg_horizontal", 0660, dsi->debugfs_root,
+				&dsi->vpg_horizontal);
+	dsi->debugfs_vpg_horizontal = d;

Same here.

Quoted 43 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +19 -0
+}
+
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi)
+{
+	debugfs_remove(dsi->debugfs_vpg_horizontal);
+	debugfs_remove(dsi->debugfs_vpg);
+	debugfs_remove(dsi->debugfs_root);
+}
+
+#else
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) { }
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) { }
+
+#endif /* CONFIG_DEBUG_FS */
+
 static struct dw_mipi_dsi *
 __dw_mipi_dsi_probe(struct platform_device *pdev,
 		    const struct dw_mipi_dsi_plat_data *plat_data)
@@ -1005,6 +1057,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 		clk_disable_unprepare(dsi->pclk);
 	}
 
+	dw_mipi_dsi_debugfs_init(dsi);
 	pm_runtime_enable(dev);
 
 	dsi->dsi_host.ops = &dw_mipi_dsi_host_ops;
@@ -1012,6 +1065,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
 	ret = mipi_dsi_host_register(&dsi->dsi_host);
 	if (ret) {
 		dev_err(dev, "Failed to register MIPI host: %d\n", ret);
+		dw_mipi_dsi_debugfs_remove(dsi);
 		return ERR_PTR(ret);
 	}
 
@@ -1029,6 +1083,7 @@ static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi)
 	mipi_dsi_host_unregister(&dsi->dsi_host);
 
 	pm_runtime_disable(dsi->dev);
+	dw_mipi_dsi_debugfs_remove(dsi);
 }
 
 void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave)
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

Thanks for the review!

Quoted 52 lines · Laurent Pinchart
Quoted 4 lines · Matt Redfearn

The Synopsys MIPI DSI IP contains a video test pattern generator which is helpful in debugging video timing with connected displays. Add a debugfs directory containing files which allow the VPG to be enabled and disabled, and it's orientation to be changed.

s/it's/its/

Quoted 45 lines

---

  drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c | 55 +++++++++++++++++++
  1 file changed, 55 insertions(+)
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +12 -0
index 0ee440216b8..a1ee2306382 100644
@@ -10,6 +10,7 @@
 
  #include <linux/clk.h>
  #include <linux/component.h>
+#include <linux/debugfs.h>
  #include <linux/iopoll.h>
  #include <linux/module.h>
  #include <linux/of_device.h>
@@ -86,6 +87,8 @@
  #define VID_MODE_TYPE_NON_BURST_SYNC_EVENTS	0x1
  #define VID_MODE_TYPE_BURST			0x2
  #define VID_MODE_TYPE_MASK			0x3
+#define VID_MODE_VPG_ENABLE		BIT(16)
+#define VID_MODE_VPG_HORIZONTAL		BIT(24)
 
  #define DSI_VID_PKT_SIZE		0x3c
  #define VID_PKT_SIZE(p)			((p) & 0x3fff)
@@ -234,6 +237,15 @@ struct dw_mipi_dsi {
  	u32 format;
  	unsigned long mode_flags;
 
+#ifdef CONFIG_DEBUG_FS
+	struct dentry *debugfs_root;
+	struct dentry *debugfs_vpg;
+	struct dentry *debugfs_vpg_horizontal;
+
+	bool vpg;
+	bool vpg_horizontal;
+#endif /* CONFIG_DEBUG_FS */
+
  	struct dw_mipi_dsi *master; /* dual-dsi master ptr */
  	struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */
 
Quoted 7 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi) · line 540

Quoted 5 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +1 -0
@@ -525,6 +537,11 @@ static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi)
  	else
  		val |= VID_MODE_TYPE_NON_BURST_SYNC_EVENTS;
 
+	if (dsi->vpg) {

Won't this break if CONFIG_DDEBUG_FS is not defined ?

Ah yes - quite right.

Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +14 -0
+		val |= VID_MODE_VPG_ENABLE;
+		val |= dsi->vpg_horizontal ? VID_MODE_VPG_HORIZONTAL : 0;
+	}
+
  	dsi_write(dsi, DSI_VID_MODE_CFG, val);
  }
 
@@ -935,6 +952,41 @@ static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = {
  	.attach	      = dw_mipi_dsi_bridge_attach,
  };
 
+#ifdef CONFIG_DEBUG_FS
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi)
+{
+	struct dentry *d;
+
+	d = debugfs_create_dir(dev_name(dsi->dev), NULL);
+	if (IS_ERR(d)) {
+		dev_err(dsi->dev, "failed to create debugfs root\n");
+		return;
Quoted 8 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = { · line 969

Quoted 5 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +5 -0
+	}
+	dsi->debugfs_root = d;
+
+	d = debugfs_create_bool("vpg", 0660, dsi->debugfs_root, &dsi->vpg);
+	dsi->debugfs_vpg = d;

If you don't handle failures here you don't need the intermediate d variable, you can just assign dsi->debugfs_vpg directly.

True - I will update it.

Quoted 7 lines

drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c static const struct drm_bridge_funcs dw_mipi_dsi_bridge_funcs = { · line 973

Quoted 5 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +4 -0
+
+	d = debugfs_create_bool("vpg_horizontal", 0660, dsi->debugfs_root,
+				&dsi->vpg_horizontal);
+	dsi->debugfs_vpg_horizontal = d;

Same here.

And here - thanks!

Matt

Quoted 45 lines
Quoted 44 lines
drivers/gpu/drm/bridge/synopsys/dw-mipi-dsi.c +19 -0
+}
+
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi)
+{
+	debugfs_remove(dsi->debugfs_vpg_horizontal);
+	debugfs_remove(dsi->debugfs_vpg);
+	debugfs_remove(dsi->debugfs_root);
+}
+
+#else
+
+static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) { }
+static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) { }
+
+#endif /* CONFIG_DEBUG_FS */
+
  static struct dw_mipi_dsi *
  __dw_mipi_dsi_probe(struct platform_device *pdev,
  		    const struct dw_mipi_dsi_plat_data *plat_data)
@@ -1005,6 +1057,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
  		clk_disable_unprepare(dsi->pclk);
  	}
 
+	dw_mipi_dsi_debugfs_init(dsi);
  	pm_runtime_enable(dev);
 
  	dsi->dsi_host.ops = &dw_mipi_dsi_host_ops;
@@ -1012,6 +1065,7 @@ __dw_mipi_dsi_probe(struct platform_device *pdev,
  	ret = mipi_dsi_host_register(&dsi->dsi_host);
  	if (ret) {
  		dev_err(dev, "Failed to register MIPI host: %d\n", ret);
+		dw_mipi_dsi_debugfs_remove(dsi);
  		return ERR_PTR(ret);
  	}
 
@@ -1029,6 +1083,7 @@ static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi)
  	mipi_dsi_host_unregister(&dsi->dsi_host);
 
  	pm_runtime_disable(dsi->dev);
+	dw_mipi_dsi_debugfs_remove(dsi);
  }
 
  void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave)