drm/msm/sde: avoid programming same plane source address

This change adds a check to the plane's pipe programming to
avoid writing the source address registers if the new values
are the same as what was written before. This avoids clutter
on the register logs and reduces the register programming
traffic slightly for those situations.

Change-Id: If9c17f14d68e3e82ea37edaf4bb5d7c8cf4eb46e
Signed-off-by: Clarence Ip <cip@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/sde/sde_formats.c b/drivers/gpu/drm/msm/sde/sde_formats.c
index 7a60643..34e710d 100644
--- a/drivers/gpu/drm/msm/sde/sde_formats.c
+++ b/drivers/gpu/drm/msm/sde/sde_formats.c
@@ -675,7 +675,8 @@
 		struct drm_framebuffer *fb,
 		struct sde_hw_fmt_layout *layout)
 {
-	int ret;
+	uint32_t plane_addr[SDE_MAX_PLANES];
+	int i, ret;
 
 	if (!fb || !layout) {
 		DRM_ERROR("invalid arguments\n");
@@ -696,12 +697,19 @@
 	if (ret)
 		return ret;
 
+	for (i = 0; i < SDE_MAX_PLANES; ++i)
+		plane_addr[i] = layout->plane_addr[i];
+
 	/* Populate the addresses given the fb */
 	if (SDE_FORMAT_IS_UBWC(layout->format))
 		ret = _sde_format_populate_addrs_ubwc(mmu_id, fb, layout);
 	else
 		ret = _sde_format_populate_addrs_linear(mmu_id, fb, layout);
 
+	/* check if anything changed */
+	if (!ret && !memcmp(plane_addr, layout->plane_addr, sizeof(plane_addr)))
+		ret = -EAGAIN;
+
 	return ret;
 }
 
diff --git a/drivers/gpu/drm/msm/sde/sde_formats.h b/drivers/gpu/drm/msm/sde/sde_formats.h
index db2a4d3..5dcdfbb 100644
--- a/drivers/gpu/drm/msm/sde/sde_formats.h
+++ b/drivers/gpu/drm/msm/sde/sde_formats.h
@@ -80,7 +80,8 @@
  * @fb:                framebuffer pointer
  * @fmtl:              format layout structure to populate
  *
- * Return: error code on failure, 0 on success
+ * Return: error code on failure, -EAGAIN if success but the addresses
+ *         are the same as before or 0 if new addresses were populated
  */
 int sde_format_populate_layout(
 		int mmu_id,
diff --git a/drivers/gpu/drm/msm/sde/sde_plane.c b/drivers/gpu/drm/msm/sde/sde_plane.c
index 41b9ede..9674cc0 100644
--- a/drivers/gpu/drm/msm/sde/sde_plane.c
+++ b/drivers/gpu/drm/msm/sde/sde_plane.c
@@ -550,14 +550,17 @@
 	}
 
 	psde = to_sde_plane(plane);
-
-	ret = sde_format_populate_layout(psde->mmu_id, fb, &pipe_cfg->layout);
-	if (ret) {
-		SDE_ERROR_PLANE(psde, "failed to get format layout, %d\n", ret);
+	if (!psde->pipe_hw) {
+		SDE_ERROR_PLANE(psde, "invalid pipe_hw\n");
 		return;
 	}
 
-	if (psde->pipe_hw && psde->pipe_hw->ops.setup_sourceaddress)
+	ret = sde_format_populate_layout(psde->mmu_id, fb, &pipe_cfg->layout);
+	if (ret == -EAGAIN)
+		SDE_DEBUG_PLANE(psde, "not updating same src addrs\n");
+	else if (ret)
+		SDE_ERROR_PLANE(psde, "failed to get format layout, %d\n", ret);
+	else if (psde->pipe_hw->ops.setup_sourceaddress)
 		psde->pipe_hw->ops.setup_sourceaddress(psde->pipe_hw, pipe_cfg);
 }