drm/msm/sde: update encoder dmesg logging to use sde macros

This change modifies the video and command mode encoders to use
local sde defined macros for debug and error logging rather than
standard drm ones. The local sde macros allow the logs to be
enabled both from the normal drm_debug and Linux dynamic debug
interfaces.

Change-Id: I25775dbe30f140f3833b3aa7c735f31bbc987f26
Signed-off-by: Clarence Ip <cip@codeaurora.org>
diff --git a/drivers/gpu/drm/msm/sde/sde_encoder.c b/drivers/gpu/drm/msm/sde/sde_encoder.c
index 67190a3..69fbe3a 100644
--- a/drivers/gpu/drm/msm/sde/sde_encoder.c
+++ b/drivers/gpu/drm/msm/sde/sde_encoder.c
@@ -10,6 +10,7 @@
  * GNU General Public License for more details.
  */
 
+#define pr_fmt(fmt)	"[drm:%s:%d] " fmt, __func__, __LINE__
 #include "msm_drv.h"
 #include "sde_kms.h"
 #include "drm_crtc.h"
@@ -23,6 +24,12 @@
 #include "sde_encoder_phys.h"
 #include "display_manager.h"
 
+#define SDE_DEBUG_ENC(e, fmt, ...) SDE_DEBUG("enc%d " fmt,\
+		(e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
+
+#define SDE_ERROR_ENC(e, fmt, ...) SDE_ERROR("enc%d " fmt,\
+		(e) ? (e)->base.base.id : -1, ##__VA_ARGS__)
+
 /*
  * Two to anticipate panels that can do cmd/vid dynamic switching
  * plan is to create all possible physical encoder types, and switch between
@@ -120,13 +127,24 @@
 
 static void bs_init(struct sde_encoder_virt *sde_enc)
 {
+	if (!sde_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+
 	sde_enc->bus_scaling_client =
 	    msm_bus_scale_register_client(&mdp_bus_scale_table);
-	DBG("bus scale client: %08x", sde_enc->bus_scaling_client);
+	SDE_DEBUG_ENC(sde_enc, "bus scale client %08x\n",
+			sde_enc->bus_scaling_client);
 }
 
 static void bs_fini(struct sde_encoder_virt *sde_enc)
 {
+	if (!sde_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+
 	if (sde_enc->bus_scaling_client) {
 		msm_bus_scale_unregister_client(sde_enc->bus_scaling_client);
 		sde_enc->bus_scaling_client = 0;
@@ -135,8 +153,13 @@
 
 static void bs_set(struct sde_encoder_virt *sde_enc, int idx)
 {
+	if (!sde_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+
 	if (sde_enc->bus_scaling_client) {
-		DBG("set bus scaling: %d", idx);
+		SDE_DEBUG_ENC(sde_enc, "set bus scaling to %d\n", idx);
 		idx = 1;
 		msm_bus_scale_client_update_request(sde_enc->bus_scaling_client,
 						    idx);
@@ -163,14 +186,14 @@
 	struct sde_encoder_virt *sde_enc = NULL;
 	int i = 0;
 
-	DBG("");
-
 	if (!hw_res || !drm_enc || !conn_state) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid argument(s), drm_enc %d, res %d, state %d\n",
+				drm_enc != 0, hw_res != 0, conn_state != 0);
 		return;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
 
 	/* Query resources used by phys encs, expected to be without overlap */
 	memset(hw_res, 0, sizeof(*hw_res));
@@ -190,7 +213,7 @@
 	struct sde_encoder_phys *phys;
 
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid pointer\n");
 		return false;
 	}
 	sde_enc = to_sde_encoder_virt(drm_enc);
@@ -207,14 +230,13 @@
 	struct sde_encoder_virt *sde_enc = NULL;
 	int i = 0;
 
-	DBG("");
-
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid encoder\n");
 		return;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
 
 	for (i = 0; i < ARRAY_SIZE(sde_enc->phys_encs); i++) {
 		struct sde_encoder_phys *phys = sde_enc->phys_encs[i];
@@ -227,7 +249,7 @@
 	}
 
 	if (sde_enc->num_phys_encs) {
-		DRM_ERROR("Expected num_phys_encs to be 0 not %d\n",
+		SDE_ERROR_ENC(sde_enc, "expected 0 num_phys_encs not %d\n",
 				sde_enc->num_phys_encs);
 	}
 
@@ -249,14 +271,15 @@
 	int i = 0;
 	int ret = 0;
 
-	DBG("");
-
 	if (!drm_enc || !crtc_state || !conn_state) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid arg(s), drm_enc %d, crtc/conn state %d/%d\n",
+				drm_enc != 0, crtc_state != 0, conn_state != 0);
 		return -EINVAL;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
+
 	priv = drm_enc->dev->dev_private;
 	sde_kms = to_sde_kms(priv->kms);
 	mode = &crtc_state->mode;
@@ -275,8 +298,8 @@
 				ret = -EINVAL;
 
 		if (ret) {
-			SDE_ERROR("enc %d mode unsupported, phys %d\n",
-					drm_enc->base.id, i);
+			SDE_ERROR_ENC(sde_enc,
+					"mode unsupported, phys idx %d\n", i);
 			break;
 		}
 	}
@@ -305,14 +328,14 @@
 	struct drm_connector *conn = NULL, *conn_iter;
 	int i = 0, ret;
 
-	DBG("");
-
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid encoder\n");
 		return;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
+
 	priv = drm_enc->dev->dev_private;
 	sde_kms = to_sde_kms(priv->kms);
 	connector_list = &sde_kms->dev->mode_config.connector_list;
@@ -324,8 +347,7 @@
 			conn = conn_iter;
 
 	if (!conn) {
-		SDE_ERROR("enc %d failed to find attached connector\n",
-				drm_enc->base.id);
+		SDE_ERROR_ENC(sde_enc, "failed to find attached connector\n");
 		return;
 	}
 
@@ -333,8 +355,8 @@
 	ret = sde_rm_reserve(&sde_kms->rm, drm_enc, drm_enc->crtc->state,
 			conn->state, false);
 	if (ret) {
-		SDE_ERROR("enc %d failed to reserve hw resources, ret %d\n",
-				drm_enc->base.id, ret);
+		SDE_ERROR_ENC(sde_enc,
+				"failed to reserve hw resources, %d\n", ret);
 		return;
 	}
 
@@ -351,14 +373,14 @@
 	struct sde_encoder_virt *sde_enc = NULL;
 	int i = 0;
 
-	DBG("");
-
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid encoder\n");
 		return;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
+
 	MSM_EVT(drm_enc->dev, 0, 0);
 
 	bs_set(sde_enc, 1);
@@ -376,7 +398,8 @@
 			 * the encoder role found at panel probe time
 			 */
 			if (phys->ops.is_master && phys->ops.is_master(phys)) {
-				DBG("phys enc master is now idx %d", i);
+				SDE_DEBUG_ENC(sde_enc,
+						"master is now idx %d\n", i);
 				sde_enc->cur_master = phys;
 			}
 		}
@@ -390,14 +413,14 @@
 	struct sde_kms *sde_kms;
 	int i = 0;
 
-	DBG("");
-
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid encoder\n");
 		return;
 	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
+
 	priv = drm_enc->dev->dev_private;
 	sde_kms = to_sde_kms(priv->kms);
 
@@ -411,7 +434,7 @@
 	}
 
 	sde_enc->cur_master = NULL;
-	DBG("clear phys enc master");
+	SDE_DEBUG_ENC(sde_enc, "cleared master\n");
 
 	bs_set(sde_enc, 0);
 
@@ -434,8 +457,6 @@
 {
 	int i = 0;
 
-	DBG("");
-
 	for (i = 0; i < catalog->intf_count; i++) {
 		if (catalog->intf[i].type == type
 		    && catalog->intf[i].controller_id == controller_id) {
@@ -460,10 +481,8 @@
 	struct sde_encoder_virt *sde_enc = NULL;
 	unsigned long lock_flags;
 
-	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+	if (!drm_enc)
 		return;
-	}
 
 	sde_enc = to_sde_encoder_virt(drm_enc);
 
@@ -483,6 +502,11 @@
 
 	enable = vbl_cb ? true : false;
 
+	if (!drm_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_ENC(sde_enc, "\n");
 	MSM_EVT(drm_enc->dev, enable, 0);
 
 	spin_lock_irqsave(&sde_enc->spin_lock, lock_flags);
@@ -532,11 +556,12 @@
 	int ret;
 
 	if (!drm_enc) {
-		DRM_ERROR("invalid arguments");
+		SDE_ERROR("invalid encoder\n");
 		return;
 	}
 	sde_enc = to_sde_encoder_virt(drm_enc);
 
+	SDE_DEBUG_ENC(sde_enc, "\n");
 	MSM_EVT(drm_enc->dev, 0, 0);
 
 	spin_lock_irqsave(&sde_enc->spin_lock, lock_flags);
@@ -572,7 +597,8 @@
 				msecs_to_jiffies(WAIT_TIMEOUT_MSEC));
 		spin_unlock_irqrestore(&sde_enc->spin_lock, lock_flags);
 		if (!ret)
-			DBG("wait %u msec timed out", WAIT_TIMEOUT_MSEC);
+			SDE_DEBUG_ENC(sde_enc, "wait %ums timed out\n",
+					WAIT_TIMEOUT_MSEC);
 	}
 
 	/* All phys encs are ready to go, trigger the kickoff */
@@ -595,7 +621,7 @@
 {
 	struct sde_encoder_phys *enc = NULL;
 
-	DBG("");
+	SDE_DEBUG_ENC(sde_enc, "\n");
 
 	/*
 	 * We may create up to NUM_PHYS_ENCODER_TYPES physical encoder types
@@ -603,7 +629,7 @@
 	 */
 	if (sde_enc->num_phys_encs + NUM_PHYS_ENCODER_TYPES >=
 			ARRAY_SIZE(sde_enc->phys_encs)) {
-		DRM_ERROR("Too many physical encoders %d, unable to add\n",
+		SDE_ERROR_ENC(sde_enc, "too many physical encoders %d\n",
 			  sde_enc->num_phys_encs);
 		return -EINVAL;
 	}
@@ -612,7 +638,7 @@
 		enc = sde_encoder_phys_vid_init(params);
 
 		if (IS_ERR_OR_NULL(enc)) {
-			DRM_ERROR("Failed to initialize phys vid enc: %ld\n",
+			SDE_ERROR_ENC(sde_enc, "failed to init vid enc: %ld\n",
 				PTR_ERR(enc));
 			return enc == 0 ? -EINVAL : PTR_ERR(enc);
 		}
@@ -625,7 +651,7 @@
 		enc = sde_encoder_phys_cmd_init(params);
 
 		if (IS_ERR_OR_NULL(enc)) {
-			DRM_ERROR("Failed to initialize phys cmd enc: %ld\n",
+			SDE_ERROR_ENC(sde_enc, "failed to init cmd enc: %ld\n",
 				PTR_ERR(enc));
 			return enc == 0 ? -EINVAL : PTR_ERR(enc);
 		}
@@ -642,10 +668,15 @@
 {
 	struct sde_encoder_phys *enc = NULL;
 
-	DBG("");
+	if (!sde_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+
+	SDE_DEBUG_ENC(sde_enc, "\n");
 
 	if (sde_enc->num_phys_encs + 1 >= ARRAY_SIZE(sde_enc->phys_encs)) {
-		DRM_ERROR("Too many physical encoders %d, unable to add\n",
+		SDE_ERROR_ENC(sde_enc, "too many physical encoders %d\n",
 			  sde_enc->num_phys_encs);
 		return -EINVAL;
 	}
@@ -653,7 +684,7 @@
 	enc = sde_encoder_phys_wb_init(params);
 
 	if (IS_ERR_OR_NULL(enc)) {
-		DRM_ERROR("Failed to initialize phys wb enc: %ld\n",
+		SDE_ERROR_ENC(sde_enc, "failed to init wb enc: %ld\n",
 			PTR_ERR(enc));
 		return enc == 0 ? -EINVAL : PTR_ERR(enc);
 	}
@@ -678,12 +709,18 @@
 	};
 	struct sde_enc_phys_init_params phys_params;
 
+	if (!sde_enc || !sde_kms) {
+		SDE_ERROR("invalid arg(s), enc %d kms %d\n",
+				sde_enc != 0, sde_kms != 0);
+		return -EINVAL;
+	}
+
 	memset(&phys_params, 0, sizeof(phys_params));
 	phys_params.sde_kms = sde_kms;
 	phys_params.parent = &sde_enc->base;
 	phys_params.parent_ops = parent_ops;
 
-	DBG("");
+	SDE_DEBUG("\n");
 
 	if (disp_info->intf_type == DRM_MODE_CONNECTOR_DSI) {
 		*drm_enc_mode = DRM_MODE_ENCODER_DSI;
@@ -695,7 +732,7 @@
 		*drm_enc_mode = DRM_MODE_ENCODER_VIRTUAL;
 		intf_type = INTF_WB;
 	} else {
-		DRM_ERROR("Unsupported display interface type");
+		SDE_ERROR_ENC(sde_enc, "unsupported display interface type\n");
 		return -EINVAL;
 	}
 
@@ -703,7 +740,7 @@
 
 	sde_enc->display_num_of_h_tiles = disp_info->num_of_h_tiles;
 
-	DBG("dsi_info->num_of_h_tiles %d", disp_info->num_of_h_tiles);
+	SDE_DEBUG("dsi_info->num_of_h_tiles %d\n", disp_info->num_of_h_tiles);
 
 	for (i = 0; i < disp_info->num_of_h_tiles && !ret; i++) {
 		/*
@@ -722,7 +759,7 @@
 			phys_params.split_role = ENC_ROLE_SOLO;
 		}
 
-		DBG("h_tile_instance %d = %d, split_role %d",
+		SDE_DEBUG("h_tile_instance %d = %d, split_role %d\n",
 				i, controller_id, phys_params.split_role);
 
 		if (intf_type == INTF_WB) {
@@ -731,8 +768,8 @@
 					sde_kms->catalog,
 					intf_type, controller_id);
 			if (phys_params.wb_idx == WB_MAX) {
-				DRM_ERROR(
-					"Error: could not get writeback: type %d, id %d\n",
+				SDE_ERROR_ENC(sde_enc,
+					"could not get wb: type %d, id %d\n",
 					intf_type, controller_id);
 				ret = -EINVAL;
 			}
@@ -742,8 +779,8 @@
 					sde_kms->catalog, intf_type,
 					controller_id);
 			if (phys_params.intf_idx == INTF_MAX) {
-				DRM_ERROR(
-					"Error: could not get writeback: type %d, id %d\n",
+				SDE_ERROR_ENC(sde_enc,
+					"could not get wb: type %d, id %d\n",
 					intf_type, controller_id);
 				ret = -EINVAL;
 			}
@@ -759,7 +796,8 @@
 						sde_enc,
 						&phys_params);
 			if (ret)
-				DRM_ERROR("Failed to add phys encs\n");
+				SDE_ERROR_ENC(sde_enc,
+						"failed to add phys encs\n");
 		}
 	}
 
@@ -777,8 +815,6 @@
 	int drm_enc_mode = DRM_MODE_ENCODER_NONE;
 	int ret = 0;
 
-	DBG("");
-
 	sde_enc = kzalloc(sizeof(*sde_enc), GFP_KERNEL);
 	if (!sde_enc) {
 		ret = -ENOMEM;
@@ -799,12 +835,12 @@
 	sde_enc->pending_kickoff_mask = 0;
 	init_waitqueue_head(&sde_enc->pending_kickoff_wq);
 
-	DBG("Created encoder");
+	SDE_DEBUG_ENC(sde_enc, "created\n");
 
 	return drm_enc;
 
 fail:
-	DRM_ERROR("Failed to create encoder\n");
+	SDE_ERROR("failed to create encoder\n");
 	if (drm_enc)
 		sde_encoder_destroy(drm_enc);
 
@@ -816,13 +852,12 @@
 	struct sde_encoder_virt *sde_enc = NULL;
 	int i, ret = 0;
 
-	DBG("");
-
 	if (!drm_enc) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid encoder\n");
 		return -EINVAL;
 	}
 	sde_enc = to_sde_encoder_virt(drm_enc);
+	SDE_DEBUG_ENC(sde_enc, "\n");
 
 	for (i = 0; i < sde_enc->num_phys_encs; i++) {
 		struct sde_encoder_phys *phys = sde_enc->phys_encs[i];
@@ -847,27 +882,28 @@
 	u32 i = 0;
 	u32 num_displays = 0;
 
-	DBG("");
+	SDE_DEBUG("\n");
 
 	if (!dev || !dev->dev_private) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid device %d\n", dev != 0);
 		return;
 	}
 
 	priv = dev->dev_private;
 	priv->num_encoders = 0;
 	if (!priv->kms || !priv->dm) {
-		DRM_ERROR("Invalid pointer");
+		SDE_ERROR("invalid priv pointer, kms %d dm %d\n",
+				priv->kms != 0, priv->dm != 0);
 		return;
 	}
 	disp_man = priv->dm;
 
 	num_displays = display_manager_get_count(disp_man);
-	DBG("num_displays %d", num_displays);
+	SDE_DEBUG("num_displays %d\n", num_displays);
 
 	if (num_displays > ARRAY_SIZE(priv->encoders)) {
 		num_displays = ARRAY_SIZE(priv->encoders);
-		DRM_ERROR("Too many displays found, capping to %d",
+		SDE_ERROR("too many displays found, capping to %d\n",
 				num_displays);
 	}
 
@@ -878,19 +914,19 @@
 
 		ret = display_manager_get_info_by_index(disp_man, i, &info);
 		if (ret) {
-			DRM_ERROR("Failed to get display info, %d", ret);
+			SDE_ERROR("failed to get display info, %d\n", ret);
 			return;
 		}
 
 		enc = sde_encoder_virt_init(dev, &info);
 		if (IS_ERR_OR_NULL(enc)) {
-			DRM_ERROR("Encoder initialization failed");
+			SDE_ERROR("encoder initialization failed\n");
 			return;
 		}
 
 		ret = display_manager_drm_init_by_index(disp_man, i, enc);
 		if (ret) {
-			DRM_ERROR("Display drm_init failed, %d", ret);
+			SDE_ERROR("display drm_init failed, %d\n", ret);
 			return;
 		}
 
diff --git a/drivers/gpu/drm/msm/sde/sde_encoder_phys_cmd.c b/drivers/gpu/drm/msm/sde/sde_encoder_phys_cmd.c
index 95011d9..477afcf 100644
--- a/drivers/gpu/drm/msm/sde/sde_encoder_phys_cmd.c
+++ b/drivers/gpu/drm/msm/sde/sde_encoder_phys_cmd.c
@@ -12,6 +12,7 @@
  *
  */
 
+#define pr_fmt(fmt)	"[drm:%s:%d] " fmt, __func__, __LINE__
 #include <linux/jiffies.h>
 
 #include "sde_encoder_phys.h"
@@ -19,6 +20,16 @@
 #include "sde_core_irq.h"
 #include "sde_formats.h"
 
+#define SDE_DEBUG_CMDENC(e, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt, \
+		(e) && (e)->base.parent ? \
+		(e)->base.parent->base.id : -1, \
+		(e) ? (e)->intf_idx - INTF_0 : -1, ##__VA_ARGS__)
+
+#define SDE_ERROR_CMDENC(e, fmt, ...) SDE_ERROR("enc%d intf%d " fmt, \
+		(e) && (e)->base.parent ? \
+		(e)->base.parent->base.id : -1, \
+		(e) ? (e)->intf_idx - INTF_0 : -1, ##__VA_ARGS__)
+
 #define to_sde_encoder_phys_cmd(x) \
 	container_of(x, struct sde_encoder_phys_cmd, base)
 
@@ -45,6 +56,8 @@
 		const struct drm_display_mode *mode,
 		struct drm_display_mode *adj_mode)
 {
+	if (phys_enc)
+		SDE_DEBUG_CMDENC(to_sde_encoder_phys_cmd(phys_enc), "\n");
 	return true;
 }
 
@@ -59,8 +72,13 @@
 	struct sde_rm_hw_iter iter;
 	int i, instance;
 
+	if (!phys_enc || !mode || !adj_mode) {
+		SDE_ERROR("invalid arg(s), enc %d mode %d adj_mode %d\n",
+				phys_enc != 0, mode != 0, adj_mode != 0);
+		return;
+	}
 	phys_enc->cached_mode = *adj_mode;
-	SDE_DEBUG("intf %d, caching mode:\n", cmd_enc->intf_idx);
+	SDE_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
 	drm_mode_debug_printmodeline(adj_mode);
 
 	instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
@@ -74,7 +92,8 @@
 	}
 
 	if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
-		SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
+		SDE_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
+				PTR_ERR(phys_enc->hw_ctl));
 		phys_enc->hw_ctl = NULL;
 		return;
 	}
@@ -88,7 +107,7 @@
 	}
 
 	if (IS_ERR_OR_NULL(cmd_enc->hw_pp)) {
-		SDE_ERROR("failed init pingpong: %ld\n",
+		SDE_ERROR_CMDENC(cmd_enc, "failed to init pingpong: %ld\n",
 				PTR_ERR(cmd_enc->hw_pp));
 		cmd_enc->hw_pp = NULL;
 		phys_enc->hw_ctl = NULL;
@@ -100,9 +119,13 @@
 static void sde_encoder_phys_cmd_pp_tx_done_irq(void *arg, int irq_idx)
 {
 	struct sde_encoder_phys_cmd *cmd_enc = arg;
-	struct sde_encoder_phys *phys_enc = &cmd_enc->base;
+	struct sde_encoder_phys *phys_enc;
 	int new_pending_cnt;
 
+	if (!cmd_enc)
+		return;
+
+	phys_enc = &cmd_enc->base;
 	new_pending_cnt = atomic_dec_return(&cmd_enc->pending_cnt);
 	MSM_EVT(DEV(phys_enc), cmd_enc->hw_pp->idx, new_pending_cnt);
 
@@ -119,6 +142,9 @@
 	struct sde_encoder_phys_cmd *cmd_enc = arg;
 	struct sde_encoder_phys *phys_enc = &cmd_enc->base;
 
+	if (!cmd_enc)
+		return;
+
 	phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent);
 }
 
@@ -134,13 +160,17 @@
 	struct sde_irq_callback irq_cb;
 	int ret = 0;
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
 	*irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms, intr_type,
 			cmd_enc->hw_pp->idx);
 	if (*irq_idx < 0) {
-		DRM_ERROR(
-			"Failed to lookup IRQ index for %s with pp=%d",
+		SDE_ERROR_CMDENC(cmd_enc,
+			"failed to lookup IRQ index for %s with pp=%d\n",
 			irq_name,
-			cmd_enc->hw_pp->idx);
+			cmd_enc->hw_pp->idx - PINGPONG_0);
 		return -EINVAL;
 	}
 
@@ -149,16 +179,18 @@
 	ret = sde_core_irq_register_callback(phys_enc->sde_kms, *irq_idx,
 			&irq_cb);
 	if (ret) {
-		DRM_ERROR("Failed to register IRQ callback %s", irq_name);
+		SDE_ERROR_CMDENC(cmd_enc,
+				"failed to register IRQ callback %s\n",
+				irq_name);
 		return ret;
 	}
 
 	ret = sde_core_irq_enable(phys_enc->sde_kms, irq_idx, 1);
 	if (ret) {
-		DRM_ERROR(
-			"Failed to enable IRQ for %s, pp %d, irq_idx=%d",
+		SDE_ERROR_CMDENC(cmd_enc,
+			"failed to enable IRQ for %s, pp %d, irq_idx %d\n",
 			irq_name,
-			cmd_enc->hw_pp->idx,
+			cmd_enc->hw_pp->idx - PINGPONG_0,
 			*irq_idx);
 		*irq_idx = -EINVAL;
 
@@ -168,9 +200,9 @@
 		return ret;
 	}
 
-	DBG("registered IRQ %s for pp %d, irq_idx=%d",
+	SDE_DEBUG_CMDENC(cmd_enc, "registered IRQ %s for pp %d, irq_idx %d\n",
 			irq_name,
-			cmd_enc->hw_pp->idx,
+			cmd_enc->hw_pp->idx - PINGPONG_0,
 			*irq_idx);
 
 	return ret;
@@ -183,12 +215,17 @@
 	struct sde_encoder_phys_cmd *cmd_enc =
 			to_sde_encoder_phys_cmd(phys_enc);
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+
 	sde_core_irq_disable(phys_enc->sde_kms, &irq_idx, 1);
 	sde_core_irq_register_callback(phys_enc->sde_kms, irq_idx,
 			NULL);
 
-	DBG("unregister IRQ for pp %d, irq_idx=%d\n",
-			cmd_enc->hw_pp->idx,
+	SDE_DEBUG_CMDENC(cmd_enc, "unregistered IRQ for pp %d, irq_idx %d\n",
+			cmd_enc->hw_pp->idx - PINGPONG_0,
 			irq_idx);
 
 	return 0;
@@ -206,11 +243,16 @@
 	struct msm_drm_private *priv;
 	struct sde_kms *sde_kms;
 
-	DBG("intf %d, pp %d", cmd_enc->intf_idx, cmd_enc->hw_pp->idx);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+
+	SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", cmd_enc->hw_pp->idx - PINGPONG_0);
 
 	if (!cmd_enc->hw_pp->ops.setup_tearcheck ||
 		!cmd_enc->hw_pp->ops.enable_tearcheck) {
-		DBG("tearcheck unsupported");
+		SDE_DEBUG_CMDENC(cmd_enc, "tearcheck not supported\n");
 		return;
 	}
 
@@ -227,7 +269,7 @@
 	 */
 	vsync_hz = sde_power_clk_get_rate(&priv->phandle, "vsync_clk");
 	if (!vsync_hz) {
-		DBG("invalid vsync clock rate");
+		SDE_DEBUG_CMDENC(cmd_enc, "invalid vsync clock rate\n");
 		return;
 	}
 
@@ -246,16 +288,21 @@
 	tc_cfg.start_pos = mode->vdisplay;
 	tc_cfg.rd_ptr_irq = mode->vdisplay + 1;
 
-	DBG("tc %d vsync_clk_speed_hz %u mode->vtotal %u mode->vrefresh %u",
-		cmd_enc->hw_pp->idx, vsync_hz, mode->vtotal, mode->vrefresh);
-	DBG("tc %d enable %u start_pos %u rd_ptr_irq %u",
-		tc_enable, cmd_enc->hw_pp->idx, tc_cfg.start_pos,
+	SDE_DEBUG_CMDENC(cmd_enc,
+		"tc %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
+		cmd_enc->hw_pp->idx - PINGPONG_0, vsync_hz,
+		mode->vtotal, mode->vrefresh);
+	SDE_DEBUG_CMDENC(cmd_enc,
+		"tc %d enable %u start_pos %u rd_ptr_irq %u\n",
+		cmd_enc->hw_pp->idx - PINGPONG_0, tc_enable, tc_cfg.start_pos,
 		tc_cfg.rd_ptr_irq);
-	DBG("tc %d hw_vsync_mode %u vsync_count %u vsync_init_val %u",
-		cmd_enc->hw_pp->idx, tc_cfg.hw_vsync_mode, tc_cfg.vsync_count,
-		tc_cfg.vsync_init_val);
-	DBG("tc %d sync_cfgheight %u sync_thresh_start %u sync_thresh_cont %u",
-		cmd_enc->hw_pp->idx, tc_cfg.sync_cfg_height,
+	SDE_DEBUG_CMDENC(cmd_enc,
+		"tc %d hw_vsync_mode %u vsync_count %u vsync_init_val %u\n",
+		cmd_enc->hw_pp->idx - PINGPONG_0, tc_cfg.hw_vsync_mode,
+		tc_cfg.vsync_count, tc_cfg.vsync_init_val);
+	SDE_DEBUG_CMDENC(cmd_enc,
+		"tc %d cfgheight %u thresh_start %u thresh_cont %u\n",
+		cmd_enc->hw_pp->idx - PINGPONG_0, tc_cfg.sync_cfg_height,
 		tc_cfg.sync_threshold_start, tc_cfg.sync_threshold_continue);
 
 	cmd_enc->hw_pp->ops.setup_tearcheck(cmd_enc->hw_pp, &tc_cfg);
@@ -269,11 +316,14 @@
 		to_sde_encoder_phys_cmd(phys_enc);
 	struct sde_hw_intf_cfg intf_cfg = { 0 };
 
-	if (!phys_enc->hw_ctl->ops.setup_intf_cfg)
+	if (!phys_enc || !phys_enc->hw_ctl ||
+			!phys_enc->hw_ctl->ops.setup_intf_cfg) {
+		SDE_ERROR("invalid arg(s), enc %d\n", phys_enc != 0);
 		return;
+	}
 
-	DBG("intf %d pp %d, enabling mode:", cmd_enc->intf_idx,
-			cmd_enc->hw_pp->idx);
+	SDE_DEBUG_CMDENC(cmd_enc, "pp %d, enabling mode:\n",
+			cmd_enc->hw_pp->idx - PINGPONG_0);
 	drm_mode_debug_printmodeline(&phys_enc->cached_mode);
 
 	intf_cfg.intf = cmd_enc->intf_idx;
@@ -293,7 +343,11 @@
 	struct sde_hw_mdp *hw_mdptop = phys_enc->hw_mdptop;
 	struct split_pipe_cfg cfg = { 0 };
 
-	DBG("enable %d", enable);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "enable %d\n", enable);
 
 	cfg.en = enable;
 	cfg.mode = INTF_MODE_CMD;
@@ -312,7 +366,11 @@
 		to_sde_encoder_phys_cmd(phys_enc);
 	int ret = 0;
 
-	DBG("enable %d", enable);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "enable %d\n", enable);
 
 	/* Slave encoders don't report vblank */
 	if (sde_encoder_phys_cmd_is_master(phys_enc)) {
@@ -328,8 +386,9 @@
 	}
 
 	if (ret)
-		DRM_ERROR("control vblank irq error %d, enable %d\n", ret,
-				enable);
+		SDE_ERROR_CMDENC(cmd_enc,
+				"control vblank irq error %d, enable %d\n",
+				ret, enable);
 
 	return ret;
 }
@@ -338,15 +397,19 @@
 {
 	struct sde_encoder_phys_cmd *cmd_enc =
 		to_sde_encoder_phys_cmd(phys_enc);
-	struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
+	struct sde_hw_ctl *ctl;
 	u32 flush_mask;
 	int ret = 0;
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", cmd_enc->hw_pp->idx - PINGPONG_0);
+
 	if (WARN_ON(phys_enc->enable_state == SDE_ENC_ENABLED))
 		return;
 
-	DBG("intf %d, pp %d", cmd_enc->intf_idx, cmd_enc->hw_pp->idx);
-
 	/*
 	 * Only master configures master/slave configuration, so no slave check
 	 * In solo configuration, solo encoder needs to program no-split
@@ -375,12 +438,13 @@
 		return;
 	}
 
+	ctl = phys_enc->hw_ctl;
 	ctl->ops.get_bitmask_intf(ctl, &flush_mask, cmd_enc->intf_idx);
 	ctl->ops.update_pending_flush(ctl, flush_mask);
 	phys_enc->enable_state = SDE_ENC_ENABLED;
 
-	DBG("Update pending flush CTL_ID %d flush_mask %x, INTF %d",
-			ctl->idx, flush_mask, cmd_enc->intf_idx);
+	SDE_DEBUG_CMDENC(cmd_enc, "update pending flush ctl %d flush_mask %x\n",
+			ctl->idx - CTL_0, flush_mask);
 }
 
 static void sde_encoder_phys_cmd_disable(struct sde_encoder_phys *phys_enc)
@@ -388,7 +452,11 @@
 	struct sde_encoder_phys_cmd *cmd_enc =
 		to_sde_encoder_phys_cmd(phys_enc);
 
-	DBG("intf %d, pp %d", cmd_enc->intf_idx, cmd_enc->hw_pp->idx);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", cmd_enc->hw_pp->idx - PINGPONG_0);
 
 	if (WARN_ON(phys_enc->enable_state == SDE_ENC_DISABLED))
 		return;
@@ -407,6 +475,10 @@
 	struct sde_encoder_phys_cmd *cmd_enc =
 		to_sde_encoder_phys_cmd(phys_enc);
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
 	kfree(cmd_enc);
 }
 
@@ -418,7 +490,11 @@
 	struct sde_encoder_phys_cmd *cmd_enc =
 		to_sde_encoder_phys_cmd(phys_enc);
 
-	DBG("intf %d", cmd_enc->intf_idx);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "\n");
 	hw_res->intfs[cmd_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
 }
 
@@ -442,7 +518,11 @@
 			to_sde_encoder_phys_cmd(phys_enc);
 	int new_pending_cnt;
 
-	DBG("intf %d, pp %d", cmd_enc->intf_idx, cmd_enc->hw_pp->idx);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_CMDENC(cmd_enc, "pp %d\n", cmd_enc->hw_pp->idx - PINGPONG_0);
 
 	/*
 	 * Mark kickoff request as outstanding. If there are more than one,
@@ -452,8 +532,9 @@
 	*need_to_wait = new_pending_cnt != 1;
 
 	if (*need_to_wait)
-		SDE_DEBUG("intf %d pp %d needs to wait, new_pending_cnt %d",
-				cmd_enc->intf_idx, cmd_enc->hw_pp->idx,
+		SDE_DEBUG_CMDENC(cmd_enc,
+				"pp %d needs to wait, new_pending_cnt %d",
+				cmd_enc->hw_pp->idx - PINGPONG_0,
 				new_pending_cnt);
 	MSM_EVT(DEV(phys_enc), cmd_enc->hw_pp->idx, new_pending_cnt);
 }
@@ -488,11 +569,12 @@
 	struct sde_hw_mdp *hw_mdp;
 	int ret = 0;
 
-	DBG("intf %d", p->intf_idx);
+	SDE_DEBUG("intf %d\n", p->intf_idx - INTF_0);
 
 	cmd_enc = kzalloc(sizeof(*cmd_enc), GFP_KERNEL);
 	if (!cmd_enc) {
 		ret = -ENOMEM;
+		SDE_ERROR("failed to allocate\n");
 		goto fail;
 	}
 	phys_enc = &cmd_enc->base;
@@ -521,7 +603,7 @@
 
 	init_waitqueue_head(&cmd_enc->pp_tx_done_wq);
 
-	DBG("Created sde_encoder_phys_cmd for intf %d", cmd_enc->intf_idx);
+	SDE_DEBUG_CMDENC(cmd_enc, "created\n");
 
 	return phys_enc;
 
diff --git a/drivers/gpu/drm/msm/sde/sde_encoder_phys_vid.c b/drivers/gpu/drm/msm/sde/sde_encoder_phys_vid.c
index 0432b04..9f11273 100644
--- a/drivers/gpu/drm/msm/sde/sde_encoder_phys_vid.c
+++ b/drivers/gpu/drm/msm/sde/sde_encoder_phys_vid.c
@@ -10,6 +10,7 @@
  * GNU General Public License for more details.
  */
 
+#define pr_fmt(fmt)	"[drm:%s:%d] " fmt, __func__, __LINE__
 #include <linux/jiffies.h>
 
 #include "sde_encoder_phys.h"
@@ -17,6 +18,18 @@
 #include "sde_core_irq.h"
 #include "sde_formats.h"
 
+#define SDE_DEBUG_VIDENC(e, fmt, ...) SDE_DEBUG("enc%d intf%d " fmt, \
+		(e) && (e)->base.parent ? \
+		(e)->base.parent->base.id : -1, \
+		(e) && (e)->hw_intf ? \
+		(e)->hw_intf->idx - INTF_0 : -1, ##__VA_ARGS__)
+
+#define SDE_ERROR_VIDENC(e, fmt, ...) SDE_ERROR("enc%d intf%d " fmt, \
+		(e) && (e)->base.parent ? \
+		(e)->base.parent->base.id : -1, \
+		(e) && (e)->hw_intf ? \
+		(e)->hw_intf->idx - INTF_0 : -1, ##__VA_ARGS__)
+
 #define VBLANK_TIMEOUT msecs_to_jiffies(100)
 
 #define to_sde_encoder_phys_vid(x) \
@@ -42,11 +55,15 @@
 {
 	int rc = 0;
 
-	DBG("intf %d", vid_enc->hw_intf->idx);
+	if (!vid_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
 	rc = wait_for_completion_timeout(&vid_enc->vblank_completion,
 			VBLANK_TIMEOUT);
 	if (rc == 0)
-		DRM_ERROR("timed out waiting for vblank irq\n");
+		SDE_ERROR_VIDENC(vid_enc, "timed out waiting for vblank irq\n");
 }
 
 static void drm_mode_to_intf_timing_params(
@@ -143,26 +160,29 @@
 	u32 actual_vfp_lines = 0;
 
 	/* Fetch must be outside active lines, otherwise undefined. */
-
 	if (start_of_frame_lines >= worst_case_needed_lines) {
-		DBG("Programmable fetch is not needed due to large vbp+vsw");
+		SDE_DEBUG_VIDENC(vid_enc,
+				"prog fetch is not needed, large vbp+vsw\n");
 		actual_vfp_lines = 0;
 	} else if (timing->v_front_porch < needed_vfp_lines) {
 		/* Warn fetch needed, but not enough porch in panel config */
 		pr_warn_once
 			("low vbp+vfp may lead to perf issues in some cases\n");
-		DBG("Less vfp than fetch requires, using entire vfp");
+		SDE_DEBUG_VIDENC(vid_enc,
+				"less vfp than fetch req, using entire vfp\n");
 		actual_vfp_lines = timing->v_front_porch;
 	} else {
-		DBG("Room in vfp for needed prefetch");
+		SDE_DEBUG_VIDENC(vid_enc, "room in vfp for needed prefetch\n");
 		actual_vfp_lines = needed_vfp_lines;
 	}
 
-	DBG("v_front_porch %u v_back_porch %u vsync_pulse_width %u",
-	    timing->v_front_porch, timing->v_back_porch,
-	    timing->vsync_pulse_width);
-	DBG("wc_lines %u needed_vfp_lines %u actual_vfp_lines %u",
-	    worst_case_needed_lines, needed_vfp_lines, actual_vfp_lines);
+	SDE_DEBUG_VIDENC(vid_enc,
+		"v_front_porch %u v_back_porch %u vsync_pulse_width %u\n",
+		timing->v_front_porch, timing->v_back_porch,
+		timing->vsync_pulse_width);
+	SDE_DEBUG_VIDENC(vid_enc,
+		"wc_lines %u needed_vfp_lines %u actual_vfp_lines %u\n",
+		worst_case_needed_lines, needed_vfp_lines, actual_vfp_lines);
 
 	return actual_vfp_lines;
 }
@@ -202,8 +222,9 @@
 		f.fetch_start = vfp_fetch_start_vsync_counter;
 	}
 
-	DBG("vfp_fetch_lines %u vfp_fetch_start_vsync_counter %u",
-	    vfp_fetch_lines, vfp_fetch_start_vsync_counter);
+	SDE_DEBUG_VIDENC(vid_enc,
+		"vfp_fetch_lines %u vfp_fetch_start_vsync_counter %u\n",
+		vfp_fetch_lines, vfp_fetch_start_vsync_counter);
 
 	spin_lock_irqsave(&phys_enc->spin_lock, lock_flags);
 	vid_enc->hw_intf->ops.setup_prg_fetch(vid_enc->hw_intf, &f);
@@ -215,7 +236,8 @@
 		const struct drm_display_mode *mode,
 		struct drm_display_mode *adj_mode)
 {
-	DBG("");
+	if (phys_enc)
+		SDE_DEBUG_VIDENC(to_sde_encoder_phys_vid(phys_enc), "\n");
 
 	/*
 	 * Modifying mode has consequences when the mode comes back to us
@@ -235,13 +257,14 @@
 	unsigned long lock_flags;
 	struct sde_hw_intf_cfg intf_cfg = { 0 };
 
-	if (WARN_ON(!vid_enc->hw_intf->ops.setup_timing_gen))
+	if (!phys_enc ||
+			!vid_enc->hw_intf->ops.setup_timing_gen ||
+			!phys_enc->hw_ctl->ops.setup_intf_cfg) {
+		SDE_ERROR("invalid encoder %d\n", phys_enc != 0);
 		return;
+	}
 
-	if (WARN_ON(!phys_enc->hw_ctl->ops.setup_intf_cfg))
-		return;
-
-	DBG("intf %d, enabling mode:", vid_enc->hw_intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "enabling mode:\n");
 	drm_mode_debug_printmodeline(&mode);
 
 	if (phys_enc->split_role != ENC_ROLE_SOLO) {
@@ -250,16 +273,17 @@
 		mode.hsync_start >>= 1;
 		mode.hsync_end >>= 1;
 
-		DBG("split_role %d, halve horizontal: %d %d %d %d",
-				phys_enc->split_role,
-				mode.hdisplay, mode.htotal,
-				mode.hsync_start, mode.hsync_end);
+		SDE_DEBUG_VIDENC(vid_enc,
+			"split_role %d, halve horizontal %d %d %d %d\n",
+			phys_enc->split_role,
+			mode.hdisplay, mode.htotal,
+			mode.hsync_start, mode.hsync_end);
 	}
 
 	drm_mode_to_intf_timing_params(vid_enc, &mode, &timing_params);
 
 	fmt = sde_get_sde_format(fmt_fourcc);
-	DBG("fmt_fourcc %d", fmt_fourcc);
+	SDE_DEBUG_VIDENC(vid_enc, "fmt_fourcc 0x%X\n", fmt_fourcc);
 
 	intf_cfg.intf = vid_enc->hw_intf->idx;
 	intf_cfg.wb = SDE_NONE;
@@ -279,15 +303,19 @@
 static void sde_encoder_phys_vid_vblank_irq(void *arg, int irq_idx)
 {
 	struct sde_encoder_phys_vid *vid_enc = arg;
-	struct sde_encoder_phys *phys_enc = &vid_enc->base;
+	struct sde_encoder_phys *phys_enc;
 
+	if (!vid_enc)
+		return;
+
+	phys_enc = &vid_enc->base;
 	phys_enc->parent_ops.handle_vblank_virt(phys_enc->parent);
 
 	/* signal VBLANK completion */
 	complete_all(&vid_enc->vblank_completion);
 }
 
-static void sde_encoder_phys_vid_split_config(
+static void _sde_encoder_phys_vid_split_config(
 		struct sde_encoder_phys *phys_enc, bool enable)
 {
 	struct sde_encoder_phys_vid *vid_enc =
@@ -295,7 +323,7 @@
 	struct sde_hw_mdp *hw_mdptop = phys_enc->hw_mdptop;
 	struct split_pipe_cfg cfg = { 0 };
 
-	DBG("enable %d", enable);
+	SDE_DEBUG_VIDENC(vid_enc, "enable %d\n", enable);
 
 	cfg.en = enable;
 	cfg.mode = INTF_MODE_VIDEO;
@@ -319,12 +347,16 @@
 	struct sde_irq_callback irq_cb;
 	int ret = 0;
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+
 	vid_enc->irq_idx = sde_core_irq_idx_lookup(phys_enc->sde_kms,
 			SDE_IRQ_TYPE_INTF_VSYNC, vid_enc->hw_intf->idx);
 	if (vid_enc->irq_idx < 0) {
-		DRM_ERROR(
-			"Failed to lookup IRQ index for INTF_VSYNC with intf=%d\n",
-			vid_enc->hw_intf->idx);
+		SDE_ERROR_VIDENC(vid_enc,
+				"failed to lookup IRQ index for INTF_VSYNC\n");
 		return -EINVAL;
 	}
 
@@ -333,15 +365,15 @@
 	ret = sde_core_irq_register_callback(phys_enc->sde_kms,
 			vid_enc->irq_idx, &irq_cb);
 	if (ret) {
-		DRM_ERROR("failed to register IRQ callback INTF_VSYNC");
+		SDE_ERROR_VIDENC(vid_enc,
+				"failed to register IRQ callback INTF_VSYNC");
 		return ret;
 	}
 
 	ret = sde_core_irq_enable(phys_enc->sde_kms, &vid_enc->irq_idx, 1);
 	if (ret) {
-		DRM_ERROR(
-			"failed to enable IRQ for INTF_VSYNC, intf %d, irq_idx=%d",
-				vid_enc->hw_intf->idx,
+		SDE_ERROR_VIDENC(vid_enc,
+			"enable IRQ for INTF_VSYNC failed, irq_idx %d\n",
 				vid_enc->irq_idx);
 		vid_enc->irq_idx = -EINVAL;
 
@@ -351,9 +383,7 @@
 		return ret;
 	}
 
-	DBG("registered IRQ for intf %d, irq_idx=%d",
-			vid_enc->hw_intf->idx,
-			vid_enc->irq_idx);
+	SDE_DEBUG_VIDENC(vid_enc, "registered %d\n", vid_enc->irq_idx);
 
 	return ret;
 }
@@ -364,13 +394,16 @@
 	struct sde_encoder_phys_vid *vid_enc =
 			to_sde_encoder_phys_vid(phys_enc);
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+
 	sde_core_irq_register_callback(phys_enc->sde_kms, vid_enc->irq_idx,
 			NULL);
 	sde_core_irq_disable(phys_enc->sde_kms, &vid_enc->irq_idx, 1);
 
-	DBG("unregister IRQ for intf %d, irq_idx=%d",
-			vid_enc->hw_intf->idx,
-			vid_enc->irq_idx);
+	SDE_DEBUG_VIDENC(vid_enc, "unregistered %d\n", vid_enc->irq_idx);
 
 	return 0;
 }
@@ -386,8 +419,13 @@
 	struct sde_rm_hw_iter iter;
 	int i, instance;
 
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+
 	phys_enc->cached_mode = *adj_mode;
-	SDE_DEBUG("intf %d, caching mode:\n", vid_enc->hw_intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "caching mode:\n");
 	drm_mode_debug_printmodeline(adj_mode);
 
 	instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
@@ -401,7 +439,8 @@
 	}
 
 	if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
-		SDE_ERROR("failed init ctl: %ld\n", PTR_ERR(phys_enc->hw_ctl));
+		SDE_ERROR_VIDENC(vid_enc, "failed to init ctl, %ld\n",
+				PTR_ERR(phys_enc->hw_ctl));
 		phys_enc->hw_ctl = NULL;
 		return;
 	}
@@ -411,9 +450,16 @@
 		struct sde_encoder_phys *phys_enc,
 		bool enable)
 {
+	struct sde_encoder_phys_vid *vid_enc =
+		to_sde_encoder_phys_vid(phys_enc);
 	int ret = 0;
 
-	DBG("enable %d", enable);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return -EINVAL;
+	}
+
+	SDE_DEBUG_VIDENC(vid_enc, "enable %d\n", enable);
 
 	/* Slave encoders don't report vblank */
 	if (sde_encoder_phys_vid_is_master(phys_enc)) {
@@ -424,8 +470,9 @@
 	}
 
 	if (ret)
-		DRM_ERROR("control vblank irq error %d, enable %d\n", ret,
-				enable);
+		SDE_ERROR_VIDENC(vid_enc,
+				"control vblank irq error %d, enable %d\n",
+				ret, enable);
 
 	return ret;
 }
@@ -438,21 +485,24 @@
 	struct sde_hw_ctl *ctl = phys_enc->hw_ctl;
 	u32 flush_mask = 0;
 
-	if (!vid_enc->hw_intf || !phys_enc->hw_ctl) {
-		SDE_ERROR("invalid hw: intf %pK ctl %pK\n", vid_enc->hw_intf,
-				phys_enc->hw_ctl);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	} else if (!vid_enc->hw_intf || !phys_enc->hw_ctl) {
+		SDE_ERROR("invalid hw_intf %d hw_ctl %d\n",
+				vid_enc->hw_intf != 0, phys_enc->hw_ctl != 0);
 		return;
 	}
 
-	DBG("intf %d", vid_enc->hw_intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
 
 	if (WARN_ON(!vid_enc->hw_intf->ops.enable_timing))
 		return;
 
 	if (phys_enc->split_role == ENC_ROLE_MASTER)
-		sde_encoder_phys_vid_split_config(phys_enc, true);
+		_sde_encoder_phys_vid_split_config(phys_enc, true);
 	else if (phys_enc->split_role == ENC_ROLE_SOLO)
-		sde_encoder_phys_vid_split_config(phys_enc, false);
+		_sde_encoder_phys_vid_split_config(phys_enc, false);
 
 	sde_encoder_phys_vid_setup_timing_engine(phys_enc);
 	sde_encoder_phys_vid_control_vblank_irq(phys_enc, true);
@@ -460,8 +510,8 @@
 	ctl->ops.get_bitmask_intf(ctl, &flush_mask, intf->idx);
 	ctl->ops.update_pending_flush(ctl, flush_mask);
 
-	DBG("Update pending flush CTL_ID %d flush_mask %x, INTF %d",
-		ctl->idx, flush_mask, intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "update pending flush ctl %d flush_mask %x\n",
+		ctl->idx - CTL_0, flush_mask);
 
 	/* ctl_flush & timing engine enable will be triggered by framework */
 	if (phys_enc->enable_state == SDE_ENC_DISABLED)
@@ -474,19 +524,24 @@
 	struct sde_encoder_phys_vid *vid_enc =
 			to_sde_encoder_phys_vid(phys_enc);
 
-	if (!vid_enc->hw_intf || !phys_enc->hw_ctl) {
-		SDE_ERROR("invalid hw: intf %pK ctl %pK\n", vid_enc->hw_intf,
-				phys_enc->hw_ctl);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	} else if (!vid_enc->hw_intf || !phys_enc->hw_ctl) {
+		SDE_ERROR("invalid hw_intf %d hw_ctl %d\n",
+				vid_enc->hw_intf != 0, phys_enc->hw_ctl != 0);
 		return;
 	}
 
-	DBG("intf %d", vid_enc->hw_intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
 
 	if (WARN_ON(!vid_enc->hw_intf->ops.enable_timing))
 		return;
 
-	if (WARN_ON(phys_enc->enable_state == SDE_ENC_DISABLED))
+	if (phys_enc->enable_state == SDE_ENC_DISABLED) {
+		SDE_ERROR("already disabled\n");
 		return;
+	}
 
 	spin_lock_irqsave(&phys_enc->spin_lock, lock_flags);
 	vid_enc->hw_intf->ops.enable_timing(vid_enc->hw_intf, 0);
@@ -513,7 +568,11 @@
 	struct sde_encoder_phys_vid *vid_enc =
 	    to_sde_encoder_phys_vid(phys_enc);
 
-	DBG("intf %d", vid_enc->hw_intf->idx);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
 	kfree(vid_enc);
 }
 
@@ -525,7 +584,12 @@
 	struct sde_encoder_phys_vid *vid_enc =
 		to_sde_encoder_phys_vid(phys_enc);
 
-	DBG("intf %d", vid_enc->hw_intf->idx);
+	if (!phys_enc || !hw_res || !vid_enc->hw_intf) {
+		SDE_ERROR("invalid arg(s), enc %d hw_res %d conn_state %d\n",
+				phys_enc != 0, hw_res != 0, conn_state != 0);
+		return;
+	}
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
 	hw_res->intfs[vid_enc->hw_intf->idx - INTF_0] = INTF_MODE_VIDEO;
 }
 
@@ -539,15 +603,18 @@
 	if (!sde_encoder_phys_vid_is_master(phys_enc))
 		return 0;
 
-	if (phys_enc->enable_state != SDE_ENC_ENABLED)
+	if (phys_enc->enable_state != SDE_ENC_ENABLED) {
+		SDE_ERROR("encoder not enabled\n");
 		return -EWOULDBLOCK;
+	}
 
 	MSM_EVTMSG(DEV(phys_enc), "waiting", 0, 0);
 
 	ret = wait_for_completion_timeout(&vid_enc->vblank_completion,
 			msecs_to_jiffies(WAIT_TIMEOUT_MSEC));
 	if (!ret) {
-		DBG("wait %u msec timed out", WAIT_TIMEOUT_MSEC);
+		SDE_DEBUG_VIDENC(vid_enc, "wait %u ms timed out\n",
+				WAIT_TIMEOUT_MSEC);
 		MSM_EVTMSG(DEV(phys_enc), "wait_timeout", 0, 0);
 		return -ETIMEDOUT;
 	}
@@ -578,7 +645,11 @@
 	struct sde_encoder_phys_vid *vid_enc =
 			to_sde_encoder_phys_vid(phys_enc);
 
-	DBG("enable_state %d", phys_enc->enable_state);
+	if (!phys_enc) {
+		SDE_ERROR("invalid encoder\n");
+		return;
+	}
+	SDE_DEBUG_VIDENC(vid_enc, "enable_state %d\n", phys_enc->enable_state);
 
 	/*
 	 * Video mode must flush CTL before enabling timing engine
@@ -624,7 +695,10 @@
 	struct sde_hw_mdp *hw_mdp;
 	int ret = 0;
 
-	DBG("intf %d", p->intf_idx);
+	if (!p) {
+		ret = -EINVAL;
+		goto fail;
+	}
 
 	vid_enc = kzalloc(sizeof(*vid_enc), GFP_KERNEL);
 	if (!vid_enc) {
@@ -660,10 +734,12 @@
 
 	if (!vid_enc->hw_intf) {
 		ret = -EINVAL;
-		DRM_ERROR("failed to get hw_intf\n");
+		SDE_ERROR("failed to get hw_intf\n");
 		goto fail;
 	}
 
+	SDE_DEBUG_VIDENC(vid_enc, "\n");
+
 	sde_encoder_phys_vid_init_ops(&phys_enc->ops);
 	phys_enc->parent = p->parent;
 	phys_enc->parent_ops = p->parent_ops;
@@ -679,13 +755,12 @@
 
 	phys_enc->enable_state = SDE_ENC_DISABLED;
 
-
-	DBG("Created sde_encoder_phys_vid for intf %d", vid_enc->hw_intf->idx);
+	SDE_DEBUG_VIDENC(vid_enc, "created\n");
 
 	return phys_enc;
 
 fail:
-	DRM_ERROR("Failed to create encoder\n");
+	SDE_ERROR("failed to create encoder\n");
 	if (vid_enc)
 		sde_encoder_phys_vid_destroy(phys_enc);