drm/msm/sde: cleanup alpha calc and plane stage in crtc

The foreground and background alpha calculation is
overlapping between crtc and lm interface. It can
be handled cleanly at single stage and update on
layer mixer. The plane staging is also complex in
same API because same plane is staged multiple times
with multiple mixers. Such invalid configurations
are leading to underruns. This patch fixes the
issues, reduces the complexity of the code and
removes extra register updates on each composition
cycle.

Change-Id: I8ea1367be06963253011ebf7e00a7555a35c7d7c
Signed-off-by: Dhaval Patel <pdhaval@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/sde/sde_plane.c b/drivers/gpu/drm/msm/sde/sde_plane.c
index 421d031..a15985e 100644
--- a/drivers/gpu/drm/msm/sde/sde_plane.c
+++ b/drivers/gpu/drm/msm/sde/sde_plane.c
@@ -22,6 +22,7 @@
 #include "sde_formats.h"
 #include "sde_hw_sspp.h"
 #include "sde_trace.h"
+#include "sde_crtc.h"
 
 #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci))
 #define PHASE_STEP_SHIFT	21
@@ -1058,7 +1059,7 @@
 static int _sde_plane_mode_set(struct drm_plane *plane,
 				struct drm_plane_state *state)
 {
-	uint32_t nplanes, src_flags;
+	uint32_t nplanes, src_flags, zpos, split_width;
 	struct sde_plane *psde;
 	struct sde_plane_state *pstate;
 	const struct sde_format *fmt;
@@ -1135,6 +1136,14 @@
 
 	_sde_plane_setup_scaler(psde, fmt, pstate);
 
+	/* base layer source split needs update */
+	zpos = sde_plane_get_property(pstate, PLANE_PROP_ZPOS);
+	if (zpos == SDE_STAGE_BASE) {
+		split_width = get_crtc_split_width(crtc);
+		if (psde->pipe_cfg.dst_rect.x >= split_width)
+			psde->pipe_cfg.dst_rect.x -= split_width;
+	}
+
 	if (psde->pipe_hw->ops.setup_format)
 		psde->pipe_hw->ops.setup_format(psde->pipe_hw,
 				fmt, src_flags);
@@ -1510,7 +1519,7 @@
 	}
 
 	msm_property_install_range(&psde->property_info, "zpos", 0x0, 0,
-		max_blendstages, STAGE_BASE, PLANE_PROP_ZPOS);
+		max_blendstages, SDE_STAGE_BASE, PLANE_PROP_ZPOS);
 
 	msm_property_install_range(&psde->property_info, "alpha",
 		0x0, 0, 255, 255, PLANE_PROP_ALPHA);