drm/msm/dsi-stagging: add panel jitter parsing

Update dsi panel parsing with panel jitter and
prefill line requirement to set the display rsc
backoff time on command mode panel. It also updates
these information on display info structure.

Change-Id: I930f335ca55082085f719b1ee4a6ecb035811e15
Signed-off-by: Dhaval Patel <pdhaval@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/dsi-staging/dsi_display.c b/drivers/gpu/drm/msm/dsi-staging/dsi_display.c
index 77c4b19..1525cb2 100644
--- a/drivers/gpu/drm/msm/dsi-staging/dsi_display.c
+++ b/drivers/gpu/drm/msm/dsi-staging/dsi_display.c
@@ -2660,13 +2660,19 @@
 {
 	struct dsi_display *display;
 	struct dsi_panel_phy_props phy_props;
+	struct dsi_mode_info *timing;
 	int i, rc;
 
 	if (!info || !disp) {
 		pr_err("invalid params\n");
 		return -EINVAL;
 	}
+
 	display = disp;
+	if (!display->panel) {
+		pr_err("invalid display panel\n");
+		return -EINVAL;
+	}
 
 	mutex_lock(&display->display_lock);
 	rc = dsi_panel_get_phy_props(display->panel, &phy_props);
@@ -2677,6 +2683,7 @@
 	}
 
 	info->intf_type = DRM_MODE_CONNECTOR_DSI;
+	timing = &display->panel->mode.timing;
 
 	info->num_of_h_tiles = display->ctrl_count;
 	for (i = 0; i < info->num_of_h_tiles; i++)
@@ -2684,6 +2691,10 @@
 
 	info->is_connected = true;
 	info->is_primary = true;
+	info->frame_rate = timing->refresh_rate;
+	info->vtotal = DSI_V_TOTAL(timing);
+	info->prefill_lines = display->panel->panel_prefill_lines;
+	info->jitter = display->panel->panel_jitter;
 	info->width_mm = phy_props.panel_width_mm;
 	info->height_mm = phy_props.panel_height_mm;
 	info->max_width = 1920;
diff --git a/drivers/gpu/drm/msm/dsi-staging/dsi_panel.c b/drivers/gpu/drm/msm/dsi-staging/dsi_panel.c
index fa10b55..23f0577 100644
--- a/drivers/gpu/drm/msm/dsi-staging/dsi_panel.c
+++ b/drivers/gpu/drm/msm/dsi-staging/dsi_panel.c
@@ -24,6 +24,10 @@
 
 #define DEFAULT_MDP_TRANSFER_TIME 14000
 
+#define DEFAULT_PANEL_JITTER		5
+#define MAX_PANEL_JITTER		25
+#define DEFAULT_PANEL_PREFILL_LINES	16
+
 static int dsi_panel_vreg_get(struct dsi_panel *panel)
 {
 	int rc = 0;
@@ -1361,6 +1365,37 @@
 	return rc;
 }
 
+static int dsi_panel_parse_jitter_config(struct dsi_panel *panel,
+				     struct device_node *of_node)
+{
+	int rc;
+
+	rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-jitter",
+				  &panel->panel_jitter);
+	if (rc) {
+		pr_debug("panel jitter is not defined rc=%d\n", rc);
+		panel->panel_jitter = DEFAULT_PANEL_JITTER;
+	} else if (panel->panel_jitter > MAX_PANEL_JITTER) {
+		pr_debug("invalid jitter config=%d setting to:%d\n",
+			panel->panel_jitter, DEFAULT_PANEL_JITTER);
+		panel->panel_jitter = DEFAULT_PANEL_JITTER;
+	}
+
+	rc = of_property_read_u32(of_node, "qcom,mdss-dsi-panel-prefill-lines",
+				  &panel->panel_prefill_lines);
+	if (rc) {
+		pr_debug("panel prefill lines are not defined rc=%d\n", rc);
+		panel->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES;
+	} else if (panel->panel_prefill_lines >=
+					DSI_V_TOTAL(&panel->mode.timing))  {
+		pr_debug("invalid prefill lines config=%d setting to:%d\n",
+		      panel->panel_prefill_lines, DEFAULT_PANEL_PREFILL_LINES);
+		panel->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES;
+	}
+
+	return 0;
+}
+
 static int dsi_panel_parse_power_cfg(struct device *parent,
 				     struct dsi_panel *panel,
 				     struct device_node *of_node)
@@ -1643,6 +1678,10 @@
 	if (rc)
 		pr_err("failed to parse backlight config, rc=%d\n", rc);
 
+	rc = dsi_panel_parse_jitter_config(panel, of_node);
+	if (rc)
+		pr_err("failed to parse panel jitter config, rc=%d\n", rc);
+
 	panel->panel_of_node = of_node;
 	drm_panel_init(&panel->drm_panel);
 	mutex_init(&panel->panel_lock);
diff --git a/drivers/gpu/drm/msm/dsi-staging/dsi_panel.h b/drivers/gpu/drm/msm/dsi-staging/dsi_panel.h
index 7b60193..386e8a9 100644
--- a/drivers/gpu/drm/msm/dsi-staging/dsi_panel.h
+++ b/drivers/gpu/drm/msm/dsi-staging/dsi_panel.h
@@ -176,6 +176,8 @@
 	bool ulps_enabled;
 	bool allow_phy_power_off;
 
+	u32 panel_jitter;
+	u32 panel_prefill_lines;
 	bool panel_initialized;
 };
 
diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
index 211ae6f..ca4d213 100644
--- a/drivers/gpu/drm/msm/msm_drv.h
+++ b/drivers/gpu/drm/msm/msm_drv.h
@@ -199,13 +199,17 @@
  * @h_tile_instance:    Controller instance used per tile. Number of elements is
  *                      based on num_of_h_tiles
  * @is_connected:       Set to true if display is connected
- * @is_primary:         Set to true if display is primary display
  * @width_mm:           Physical width
  * @height_mm:          Physical height
  * @max_width:          Max width of display. In case of hot pluggable display
  *                      this is max width supported by controller
  * @max_height:         Max height of display. In case of hot pluggable display
  *                      this is max height supported by controller
+ * @is_primary:         Set to true if display is primary display
+ * @frame_rate:		Display frame rate
+ * @prefill_lines:	prefill lines based on porches.
+ * @vtotal:		display vertical total
+ * @jitter:		display jitter configuration
  * @compression:        Compression supported by the display
  */
 struct msm_display_info {
@@ -216,7 +220,6 @@
 	uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
 
 	bool is_connected;
-	bool is_primary;
 
 	unsigned int width_mm;
 	unsigned int height_mm;
@@ -224,6 +227,12 @@
 	uint32_t max_width;
 	uint32_t max_height;
 
+	bool is_primary;
+	uint32_t frame_rate;
+	uint32_t prefill_lines;
+	uint32_t vtotal;
+	uint32_t jitter;
+
 	enum msm_display_compression compression;
 };