libdrm_meson: the kernel keeps outputting a lot of prints [1/1]

PD#OTT-44931

Problem:
The kernel keeps outputting a lot of prints

Solution:
Add Print Output Level

Verify:
AP23A9-S905C3

Change-Id: Ic290f0d973e9906c09bd211e7a86237c4e921315
Signed-off-by: chen.wang1 <chen.wang1@amlogic.com>
diff --git a/meson/Makefile b/meson/Makefile
index d44c306..1c4c1b8 100644
--- a/meson/Makefile
+++ b/meson/Makefile
@@ -1,5 +1,4 @@
 LOCAL_PATH = $(shell pwd)
-
 MIN_GCC_VERSION = "10"
 GCC_VERSION := "`$(CC) -dumpversion | cut -f1 -d'.'`"
 IS_GCC_ABOVE_MIN_VERSION := $(shell expr "$(GCC_VERSION)" ">=" "$(MIN_GCC_VERSION)")
@@ -21,7 +20,8 @@
 	$(LOCAL_PATH)/meson_drm_util.c  \
 	$(LOCAL_PATH)/meson_drm_display.c  \
 	$(LOCAL_PATH)/meson_drm_event.c  \
-        $(LOCAL_PATH)/meson_drm_settings.c  \
+	$(LOCAL_PATH)/meson_drm_settings.c  \
+	$(LOCAL_PATH)/meson_drm_log.c  \
 	$(NULL)
 
 meson_drm_HEADERS = \
diff --git a/meson/libdrm_meson_connector.c b/meson/libdrm_meson_connector.c
index 1315898..d4e66ef 100644
--- a/meson/libdrm_meson_connector.c
+++ b/meson/libdrm_meson_connector.c
@@ -16,7 +16,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <linux/version.h>
-
+#include "meson_drm_log.h"
 
 #define MESON_DRM_MODE_GETCONNECTOR_HDMI     "/sys/class/drm/card0-HDMI-A-1/status"
 #define MESON_DRM_MODE_GETCONNECTOR_VBYONE    "/sys/class/drm/card0-VBYONE-A/status"
@@ -60,12 +60,12 @@
 	res= drmModeGetResources( drmFd );
 	ret = (struct mesonConnector*)calloc( 1,sizeof(struct mesonConnector) );
 	if ( !ret ) {
-		printf("\n mesonConnectorCreate:mesonConnector create fail \n");
+		DEBUG("mesonConnectorCreate:mesonConnector create fail");
 		goto exit;
 	}
 	if ( !res )
 	{
-		printf("\n mesonConnectorCreate: failed to get resources from drmFd (%d)", drmFd);
+		ERROR("mesonConnectorCreate: failed to get resources from drmFd (%d)", drmFd);
 		ret = NULL;
 		goto exit;
 	}
@@ -96,7 +96,7 @@
 		if (cur_encoder)
 			ret->crtc_id = cur_encoder->crtc_id;
 		else {
-			printf("\n cur encoder not exit, get crtcs[0]:%d ",res->crtcs[0]);
+			DEBUG("cur encoder not exit, get crtcs[0]:%d ",res->crtcs[0]);
 			ret->crtc_id = res->crtcs[0];
 		}
 		drmModeFreeEncoder(cur_encoder);
@@ -104,7 +104,7 @@
 		if (ret->count_modes > 0) {
 			modes_info =  (drmModeModeInfo*)calloc( ret->count_modes, sizeof(drmModeModeInfo) );
 			if (!modes_info) {
-				printf("\n mesonConnectorCreate:calloc fail\n");
+				ERROR("mesonConnectorCreate:calloc fail");
 				goto exit;
 			}
 			memcpy(modes_info, conn->modes, ret->count_modes *sizeof(drmModeModeInfo));
@@ -150,16 +150,16 @@
 	conn= drmModeGetConnector( drmFd, connector->id );
 	//ret = (struct mesonConnector*)calloc( 1,sizeof(struct mesonConnector) );
 	if ( !connector ) {
-		printf("\n mesonConnectorUpdate:invalid parameters\n");
+		ERROR("mesonConnectorUpdate:invalid parameters ");
 		goto exit;
 	}
 	if ( !ret ) {
-		printf("\n mesonConnectorUpdate:mesonConnector create fail\n");
+		DEBUG("mesonConnectorUpdate:mesonConnector create fail");
 		goto exit;
 	}
 	if ( !conn ) {
-		printf("\n mesonConnectorCreate: unable to get connector for drmfd (%d) conn_id(%d)\n", drmFd,connector->id);
-		goto exit;
+		INFO("mesonConnectorCreate: unable to get connector for drmfd (%d) conn_id(%d)\n", drmFd,connector->id);
+	goto exit;
 	}
 	if ( conn ) {
 		connector->id = conn->connector_id;
@@ -229,7 +229,7 @@
 	if ( connector ) {
 		return connector->id;
 	} else {
-		printf("\n mesonConnectorGetId:invalid parameters\n");
+		ERROR("mesonConnectorGetId:invalid parameters");
 		return 0;
 	}
 }
@@ -238,7 +238,7 @@
 {
 	int ret = -1;
 	if ( !connector || !count_modes ) {
-		printf("\n mesonConnectorGetModes:invalid parameters\n");
+		ERROR("mesonConnectorGetModes:invalid parameters ");
 	} else {
 		*count_modes = connector->count_modes;
 		*modes = connector->modes;
@@ -251,7 +251,7 @@
 {
 	int ret = -1;
 	if ( !connector || !data_Len ) {
-		printf("\n mesonConnectorGetEdidBlob:invalid parameters\n");
+		ERROR("mesonConnectorGetEdidBlob:invalid parameters ");
 	} else {
 		*data_Len = connector->edid_data_Len;
 		*data = connector->edid_data;
@@ -264,7 +264,7 @@
 {
 	int ret = -1;
 	if ( !connector ) {
-			printf("\n mesonConnectorGetConnectState:invalid parameters\n");
+			ERROR("mesonConnectorGetConnectState:invalid parameters ");
 	} else {
 		ret = connector->connection;
 	}
@@ -274,7 +274,7 @@
 {
 	int ret = -1;
 	if ( !connector ) {
-		printf("\n mesonConnectorGetCRTCId:invalid parameters\n");
+		ERROR("mesonConnectorGetCRTCId:invalid parameters ");
 	} else {
 		ret = connector->crtc_id;
 	}
@@ -299,13 +299,13 @@
 	int j = 0;
 	drmModeModeInfo* mode = NULL;
 	if (connector) {
-		printf("\n connector:\n");
-		printf("id:%d\n",connector->id);
-		printf("type:%d\n",connector->type);
-		printf("connection:%d\n",connector->connection);
-		printf("count_modes:%d\n",connector->count_modes);
-		printf("modes:\n");
-		printf("\tname refresh (Hz) hdisp hss hse htot vdisp "
+		DEBUG("\n connector:\n");
+		DEBUG("id:%d\n",connector->id);
+		DEBUG("type:%d\n",connector->type);
+		DEBUG("connection:%d\n",connector->connection);
+		DEBUG("count_modes:%d\n",connector->count_modes);
+		DEBUG("modes:\n");
+		DEBUG("\tname refresh (Hz) hdisp hss hse htot vdisp "
 				   "vss vse vtot)\n");
 		for (j = 0; j < connector->count_modes; j++) {
 			mode = &connector->modes[j];
@@ -322,12 +322,12 @@
 			mode->vtotal,
 			mode->clock);
 		}
-		printf("edid_data_Len:%d\n",connector->edid_data_Len);
-		printf("edid\n");
+		INFO("edid_data_Len:%d\n",connector->edid_data_Len);
+		DEBUG("edid\n");
 		for (i = 0; i < connector->edid_data_Len; i++) {
 			if (i % 16 == 0)
 				printf("\n\t\t\t");
-			printf("%.2hhx", connector->edid_data[i]);
+			INFO("%.2hhx", connector->edid_data[i]);
 		}
 		printf("\n");
 	}
diff --git a/meson/libdrm_meson_property.c b/meson/libdrm_meson_property.c
index fca34b8..25acbc3 100644
--- a/meson/libdrm_meson_property.c
+++ b/meson/libdrm_meson_property.c
@@ -6,9 +6,11 @@
  *
  * Description:
  */
-
+#include <stdarg.h>

 #include <string.h>
 #include "libdrm_meson_property.h"
+#include "meson_drm_log.h"
+
 struct mesonProperty {
 	drmModePropertyPtr prop_ptr;
 	uint64_t mValue;
@@ -16,6 +18,7 @@
 	uint32_t mComponentId;
 	uint32_t drmObjectType;
 };
+

 struct mesonProperty *mesonPropertyCreate(int drmFd, uint32_t drmObject, uint32_t drmObjectType, char* name)
 {
 	int i = 0;
@@ -28,17 +31,17 @@
 	uint64_t* values_temp = NULL;
 	uint32_t* blob_ids_temp = NULL;
 	if ( !props ) {
-		printf("\t No properties:mesonPropertyCreate \n");
+		DEBUG("\t No properties:mesonPropertyCreate \n");
 		goto exit;
 	}
 	prop = (drmModePropertyPtr)calloc( 1, sizeof(drmModePropertyRes));
 	if ( !prop ) {
-		printf("\t mesonPropertyCreate alloc fail\n");
+		ERROR("mesonPropertyCreate alloc fail");
 		goto exit;
 	}
 	ret = (struct mesonProperty*)calloc( 1,sizeof(struct mesonProperty) );
 	if ( !ret ) {
-		printf("\t mesonPropertyCreate alloc mesonProperty fail\n");
+		DEBUG("mesonPropertyCreate alloc mesonProperty fail");
 		goto exit;
 	}
 	for (i = 0; i < props->count_props; i++) {
@@ -111,13 +114,13 @@
 	uint64_t* values_temp = NULL;
 	uint32_t* blob_ids_temp = NULL;
 	if ( !mesonProp ) {
-		printf("\t mesonPropertyUpdateValue invalid parameter\n");
+		ERROR("mesonPropertyUpdateValue invalid parameter" );
 		ret = -1;
 		goto exit;
 	}
 	props = drmModeObjectGetProperties(drmFd, mesonProp->mComponentId, mesonProp->drmObjectType);
 	if ( !props ) {
-		printf("\t No properties:mesonPropertyUpdateValue \n");
+		INFO("No properties:mesonPropertyUpdateValue ");
 		ret = -1;
 		goto exit;
 	}
@@ -183,7 +186,7 @@
 	if ( mesonProp ) {
 		ret = mesonProp->prop_ptr->prop_id;
 	} else {
-		printf("\t mesonPropertyGetValue invalid parameter\n");
+		ERROR("mesonPropertyGetId invalid parameter ");
 	}
 	return ret;
 }
@@ -194,7 +197,7 @@
 	if ( mesonProp ) {
 		ret = mesonProp->mValue;
 	} else {
-		printf("\t mesonPropertyGetValue invalid parameter\n");
+		ERROR("mesonPropertyGetValue invalid parameter ");
 	}
 	return ret;
 }
@@ -205,7 +208,7 @@
 	if ( mesonProp ) {
 		ret = mesonProp->mType;
 	} else {
-		printf("\t mesonPropertyGetType invalid parameter\n");
+		ERROR("mesonPropertyGetType invalid parameter ");
 	}
 	return ret;
 }
@@ -225,7 +228,7 @@
 		mesonProperty = NULL;
 		ret  = 0;
 	} else {
-		printf("\t mesonPropertyDestroy invalid parameter\n");
+		DEBUG("No properties:mesonPropertyUpdateValue ");
 	}
 	return ret;
 }
@@ -236,11 +239,11 @@
 	drmModePropertyBlobPtr blobProp =  NULL;
 	char *blob_data = NULL;
 	if (!mseonProp || !len ) {
-		printf("\t mesonPropertyGetBlobData invalid parameter\n");
+		ERROR(" mesonPropertyGetBlobData invalid parameter");
 		goto exit;
 	}
 	if (!drm_property_type_is(mseonProp->prop_ptr, DRM_MODE_PROP_BLOB)) {
-		printf("\t mesonPropertyGetBlobData invalid parameter is not a blob property!!!\n");
+		DEBUG(" mesonPropertyGetBlobData invalid parameter is not a blob property!!!");
 		goto exit;
 	}
 	if ( mseonProp && len ) {
@@ -256,7 +259,7 @@
 			*data = blob_data;
 		}
 		else
-			printf("\t mesonPropertyGetBlobData fail to alloc buffer\n");
+			ERROR("mesonPropertyCreate alloc mesonProperty fail");
 		drmModeFreePropertyBlob(blobProp);
 		ret = 0;
 	}
@@ -267,7 +270,7 @@
 {
 	int ret = -1;
 	if ( !mesonProp || !min || !max ) {
-		printf("\t mesonPropertyGetRange invalid parameter\n");
+		ERROR("mesonPropertyGetRange invalid parameter ");
 		goto exit;
 	}
 	if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_SIGNED_RANGE) || drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_RANGE)) {
@@ -275,21 +278,22 @@
 		*max = mesonProp->prop_ptr->values[1];
 		ret = 0;
 	} else {
-		printf("\t mesonPropertyGetRange invalid parameter,not a range property\n");
+		DEBUG("mesonPropertyGetRange invalid parameter,not a range property ");
 	}
 exit:
 	return ret;
 
 }
+

 int mesonPropertyGetEnumTypes(struct mesonProperty* mesonProp, int *len, struct drm_mode_property_enum** enumTypes)
 {
 	int ret = -1;
 	if ( !mesonProp || !len || !enumTypes ) {
-		printf("\t mesonPropertyGetEnumTypes invalid parameter\n");
+		ERROR("\t mesonPropertyGetEnumTypes invalid parameter\n");
 		goto exit;
 	}
 	if ( !mesonProp->prop_ptr ) {
-		printf("\t mesonPropertyGetEnumTypes invalid parameter\n");
+		DEBUG("\t mesonPropertyGetEnumTypes invalid parameter\n");
 		goto exit;
 	}
 	if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_ENUM)) {
@@ -297,7 +301,7 @@
 		*enumTypes = mesonProp->prop_ptr->enums;
 		ret = 0;
 	} else {
-		printf("\t mesonPropertyGetRange invalid parameter,not a enum property\n");
+		DEBUG("mesonPropertyGetRange invalid parameter,not a enum property ");
 	}
 exit:
 	return ret;
@@ -305,65 +309,65 @@
 
 void dump_property(struct mesonProperty* mesonProp,int drmFd)
 {
-	printf("\n dump_property \n");
+	DEBUG("dump_property ");
 	int i = 0;
 	if (mesonProp) {
-		printf("name:%s\n",mesonProp->prop_ptr->name);
-		printf("mComponentId:%d\n",mesonProp->mComponentId);
-		printf("drmObjectType:%d\n",mesonProp->drmObjectType);
-		printf("prop id:%d\n",mesonPropertyGetId(mesonProp));
-		printf("\t\tflags:");
+		DEBUG("name:%s\n",mesonProp->prop_ptr->name );
+		DEBUG("mComponentId:%d\n",mesonProp->mComponentId);
+		DEBUG("drmObjectType:%d\n",mesonProp->drmObjectType );
+		DEBUG("prop id:%d\n",mesonPropertyGetId(mesonProp) );
+		DEBUG("\t\tflags:" );
 		if (mesonProp->drmObjectType & DRM_MODE_PROP_PENDING)
-			printf(" pending");
+			INFO(" pending");
 		if (mesonProp->drmObjectType & DRM_MODE_PROP_IMMUTABLE)
-			printf(" immutable");
+			INFO(" immutable");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_SIGNED_RANGE))
-			printf(" signed range");
+			INFO(" signed range");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_RANGE))
-			printf(" range");
+			INFO(" range");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_ENUM))
-			printf(" enum");
+			INFO(" enum");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_BITMASK))
-			printf(" bitmask");
+			INFO(" bitmask");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_BLOB))
-			printf(" blob");
+			INFO(" blob");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_OBJECT))
-			printf(" object");
+			INFO(" object");
 		printf("\n");
-		printf("mValue:%d\n",(int)mesonProp->mValue);
+		INFO("mValue:%d\n",(int)mesonProp->mValue);
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_SIGNED_RANGE) ||
 			drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_RANGE) ) {
-			printf("\t\t range:");
+			DEBUG("\t\t range:");
 			uint64_t min = 0;
 			uint64_t max = 0;
 			mesonPropertyGetRange(mesonProp, &min, &max);
-			printf("min:%d max:%d\n", (int)min, (int)max);
+			DEBUG("min:%d max:%d\n", (int)min, (int)max );
 			printf("\n");
 		}
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_ENUM)) {
-			printf("\t\tenums:");
+			DEBUG("\t\tflags:" );
 			int enumTypeLen = 0;
 			struct drm_mode_property_enum** enumTypes = NULL;
 			mesonPropertyGetEnumTypes(mesonProp, &enumTypeLen, enumTypes );
-			printf("enumTypeLen:%d\n",enumTypeLen);
+			INFO("enumTypeLen:%d\n",enumTypeLen);
 			for ( i=0; i<enumTypeLen; i++ ) {
-				printf("%s=%llu",(*enumTypes)[i].name,(*enumTypes)[i].value);
+				INFO("%s=%llu",(*enumTypes)[i].name,(*enumTypes)[i].value);
 			}
 		}
-		printf("\t\blob:");
+		DEBUG("\t\blob:");
 		if (drm_property_type_is(mesonProp->prop_ptr, DRM_MODE_PROP_BLOB)) {
 			int blob_len = 0;
 			char** blob_data = NULL;
 			blob_data = (char**)calloc( 1, sizeof(char**) );
 			mesonPropertyGetBlobData(mesonProp, drmFd, &blob_len, blob_data);
-
 			for (i = 0; i < blob_len; i++) {
 				if (i % 16 == 0)
 					printf("\n\t\t\t");
-				printf("%x", (*blob_data)[i]);
+				INFO("%x", (*blob_data)[i]);
 			}
 			printf("\n");
 			free(blob_data);
 		}
 	}
 }
+

diff --git a/meson/meson_drm_display.c b/meson/meson_drm_display.c
index d766e80..eb1bf8f 100644
--- a/meson/meson_drm_display.c
+++ b/meson/meson_drm_display.c
@@ -6,7 +6,6 @@
  *
  * Description:
  */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -18,7 +17,7 @@
 #include "libdrm_meson_connector.h"
 #include "libdrm_meson_property.h"
 #include "meson_drm_display.h"
-
+#include "meson_drm_log.h"
 
 #define DEFAULT_CARD "/dev/dri/card0"
 #ifndef XDG_RUNTIME_DIR
@@ -32,11 +31,10 @@
 static int  _amsysfs_get_sysfs_str(const char *path, char *valstr, int size);
 static int  _get_frac_rate_policy();
 
-
 static int meson_drm_setprop(int obj_id, char* prop_name, int prop_value )
 {
     int ret = -1;
-    printf(" meson_drm_setprop: obj_id %d, prop_name: %s, prop_value:%d\n",obj_id, prop_name,prop_value);
+    DEBUG("meson_drm_setprop: obj_id %d, prop_name: %s, prop_value:%d",obj_id, prop_name,prop_value);
     char* xdgRunDir = getenv("XDG_RUNTIME_DIR");
     if (!xdgRunDir)
         xdgRunDir = XDG_RUNTIME_DIR;
@@ -45,19 +43,19 @@
             char cmdBuf[512] = {'\0'};
             snprintf(cmdBuf, sizeof(cmdBuf)-1, "export XDG_RUNTIME_DIR=%s;westeros-gl-console set property -s %d:%s:%d | grep \"Response\"",
                     xdgRunDir, obj_id, prop_name, prop_value);
-            printf("Executing '%s'\n", cmdBuf);
+            DEBUG("Executing '%s'\n", cmdBuf);
             FILE* fp = popen(cmdBuf, "r");
             if (NULL != fp) {
                 char output[64] = {'\0'};
                 while (fgets(output, sizeof(output)-1, fp)) {
                     if (strlen(output) && strstr(output, "[0:")) {
                         ret = 0;
-                        printf("\n meson_drm_setprop:%s\n",output);
+                        DEBUG("\n meson_drm_setprop:%s\n",output);
                     }
                 }
                 pclose(fp);
             } else {
-                printf("meson_drm_setprop: popen failed\n");
+                ERROR("meson_drm_setprop: popen failed");
             }
             if (ret != 0 ) {
                 if (strcmp(xdgRunDir, XDG_RUNTIME_DIR) == 0) {
@@ -73,7 +71,7 @@
 static uint32_t _getHDRSupportedList(uint64_t hdrlist, uint64_t dvlist)
 {
     uint32_t ret = 0;
-    printf("\n _getHDRSupportedList hdrlist:%llu, dvlist:%llu\n", hdrlist, dvlist);
+    DEBUG("\n _getHDRSupportedList hdrlist:%llu, dvlist:%llu\n", hdrlist, dvlist);
     if (!!(hdrlist & 0x1))
         ret = ret | (0x1 << (int)MESON_DRM_HDR10PLUS);
 
@@ -114,7 +112,7 @@
         do {
             snprintf(cmdBuf, sizeof(cmdBuf)-1, "export XDG_RUNTIME_DIR=%s;westeros-gl-console set mode %s | grep \"Response\"",
                     xdgRunDir, modeSet);
-            printf("Executing '%s'\n", cmdBuf);
+            DEBUG("Executing '%s'\n", cmdBuf);
             /* FIXME: popen in use */
             FILE* fp = popen(cmdBuf, "r");
             if (NULL != fp) {
@@ -127,12 +125,12 @@
                 }
                 pclose(fp);
             } else {
-                printf(" popen failed\n");
+                ERROR(" popen failed\n");
                 ret = -1;
             }
             if (ret != 0 ) {
                 if (strcmp(xdgRunDir, XDG_RUNTIME_DIR) == 0) {
-                    printf("meson_drm_setMode: failed !!\n");
+                    ERROR("meson_drm_setMode: failed !!");
                     break;
                 }
                 xdgRunDir = XDG_RUNTIME_DIR;
@@ -148,7 +146,7 @@
     drmModeModeInfo* mode = NULL;
     int drmFd = -1;
     if (modeInfo == NULL) {
-        printf("\n %s %d modeInfo == NULL return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d modeInfo == NULL return",__FUNCTION__,__LINE__);
         return ret;
     }
     drmFd = meson_drm_open();
@@ -165,10 +163,10 @@
             mode = NULL;
             ret = 0;
         } else {
-            printf("\n %s %d mode get fail \n",__FUNCTION__,__LINE__);
+            ERROR("%s %d mode get fail ",__FUNCTION__,__LINE__);
         }
     } else {
-        printf("\n %s %d conn create fail \n",__FUNCTION__,__LINE__);
+        ERROR("%s %d conn create fail ",__FUNCTION__,__LINE__);
     }
     if (conn)
         mesonConnectorDestroy(drmFd,conn);
@@ -186,7 +184,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
     drmModeModeInfo* modeall = NULL;
     int count = 0;
@@ -224,7 +222,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
 
     if (0 != mesonConnectorGetModes(conn, drmFd, &modes, &count))
@@ -261,7 +259,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
     if (0 != mesonConnectorGetEdidBlob(conn, &count, &edid_data))
         goto out;
@@ -296,7 +294,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
     if (conn) {
         int ConnectState = -1;
@@ -309,7 +307,7 @@
             ret = MESON_DRM_UNKNOWNCONNECTION;
         }
     } else {
-        printf("\n drm open fail\n");
+        ERROR(" drm open fail");
     }
     if (conn)
         mesonConnectorDestroy(drmFd,conn);
@@ -325,7 +323,7 @@
     char propName[50] = {'\0'};
     bool force1_4 = false;
     if (enProp >= ENUM_DRM_PROP_MAX) {
-        printf("\n%s %d invalid para\n",__FUNCTION__,__LINE__);
+        INFO("%s %d invalid para",__FUNCTION__,__LINE__);
         goto out;
     }
     int drmFd = -1;
@@ -334,7 +332,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
         goto out;
     }
     switch (enProp)
@@ -417,7 +415,7 @@
     int objtype = -1;
     char propName[50] = {'\0'};
     if (!prop_value || enProp >= ENUM_DRM_PROP_MAX) {
-        printf("\n%s %d invalid para\n",__FUNCTION__,__LINE__);
+        DEBUG("%s %d invalid para",__FUNCTION__,__LINE__);
         goto out;
     }
     int drmFd = -1;
@@ -426,7 +424,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
         goto out;
     }
     switch (enProp)
@@ -514,11 +512,11 @@
     struct mesonProperty* meson_prop = NULL;
     meson_prop = mesonPropertyCreate(drmFd, objID, objtype, propName);
     if (!meson_prop) {
-        printf("\n meson_prop create fail\n");
+        ERROR("meson_prop create fail");
         goto out;
     }
     uint64_t value = mesonPropertyGetValue(meson_prop);
-    printf("\n prop value:%llu objID:%d,name:%s\n",value, objID,propName);
+    DEBUG("\n prop value:%llu objID:%d,name:%s\n",value, objID,propName);
     if (enProp == ENUM_DRM_PROP_HDMI_ENABLE)
         value = value ? 0:1;
     *prop_value = (uint32_t)value;
@@ -555,7 +553,7 @@
             meson_prop_HDCP = mesonPropertyCreate(drmFd, objID, objtype, propName);
             uint64_t value_3 = mesonPropertyGetValue(meson_prop_HDCP);
             mesonPropertyDestroy(meson_prop_HDCP);
-            printf("\n prop value:%llu objID:%d,name:%s\n",value_3, objID,propName);
+            DEBUG("\n prop value:%llu objID:%d,name:%s\n",value_3, objID,propName);
             if (value_3 == 1)
                 *prop_value = 2;
         }
@@ -580,7 +578,7 @@
     }
     ret_fd = open(card, O_RDONLY|O_CLOEXEC);
     if ( ret_fd < 0 )
-        printf("\n drm card:%s open fail\n",card);
+        ERROR(" drm card:%s open fail",card);
     else
         drmDropMaster(ret_fd);
     return ret_fd;
@@ -650,7 +648,7 @@
     struct mesonConnector* connector = NULL;
     drmModeModeInfo* mode = NULL;
     if (drmFd < 0) {
-        printf("\n drmFd error\n");
+        ERROR(" drmFd error");
         goto out;
     }
     if (nextVsync < 0)
@@ -674,7 +672,7 @@
     vbl.request.signal= 0;
     rc = drmWaitVBlank(drmFd, &vbl );
     if (rc != 0 ) {
-        printf("drmWaitVBlank failed: rc %d errno %d",rc, errno);
+        ERROR("drmWaitVBlank failed: rc %d errno %d",rc, errno);
         ret = -1;
         goto out;
     }
@@ -687,4 +685,3 @@
     return ret;
 }
 
-
diff --git a/meson/meson_drm_event.c b/meson/meson_drm_event.c
index 8ad4847..05c3092 100644
--- a/meson/meson_drm_event.c
+++ b/meson/meson_drm_event.c
@@ -6,7 +6,6 @@
  *
  * Description:
  */
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
@@ -17,6 +16,7 @@
 
 #include "meson_drm_event.h"
 #include "meson_drm_display.h"
+#include "meson_drm_log.h"
 
 #ifndef XDG_RUNTIME_DIR
 #define XDG_RUNTIME_DIR     "/run"
@@ -36,10 +36,10 @@
     pthread_attr_t attr;
     pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
-    printf("[%s:%d]\n", __FUNCTION__, __LINE__);
+    DEBUG("[%s:%d]\n", __FUNCTION__, __LINE__);
     err = pthread_create (&event_monitor_threadId, &attr,uevent_monitor_thread,NULL);
     if (err) {
-        printf("DSHAL : Failed to Ceate HDMI Hot Plug Thread ....\r\n");
+        ERROR("DSHAL : Failed to Ceate HDMI Hot Plug Thread ....\r\n");
         event_monitor_threadId = -1;
     }
 }
@@ -47,12 +47,11 @@
 {
     isMonitoringAlive = false;
 }
-
 bool RegisterDisplayEventCallback(displayEventCallback cb)
 {
     bool ret = true;
     if (cb == NULL) {
-        printf("ERROR[%s:%d] argument NULL\n", __FUNCTION__, __LINE__);
+        ERROR("ERROR[%s:%d] argument NULL\n", __FUNCTION__, __LINE__);
         ret = false;
     } else {
         _DisplayEventCb = cb;
@@ -75,7 +74,7 @@
 
 static void* uevent_monitor_thread(void *arg)
 {
-    printf("[%s:%d]start\n", __FUNCTION__, __LINE__);
+    DEBUG("[%s:%d]start\n", __FUNCTION__, __LINE__);
     bool wasConnected = false;
     struct udev *udev = NULL;
     struct udev_device *dev = NULL;
@@ -88,7 +87,7 @@
     /* create udev object */
     udev = udev_new();
     if (!udev) {
-        printf("ERROR[%s:%d] Can't create udev monitor for DRM,\n", __FUNCTION__, __LINE__);
+        ERROR("ERROR[%s:%d] Can't create udev monitor for DRM", __FUNCTION__, __LINE__);
     } else {
         mon = udev_monitor_new_from_netlink(udev, LIBUDEV_EVT_TYPE_KERNEL);
         if (mon) {
@@ -97,13 +96,13 @@
             struct timeval tv;
             int ret;
             if ((fd = udev_monitor_get_fd(mon)) < 0) {
-                printf("ERROR[%s:%d] udev_monitor_get_fd failed,\n", __FUNCTION__, __LINE__);
+                ERROR("ERROR[%s:%d] udev_monitor_get_fd failed,\n", __FUNCTION__, __LINE__);
             } else {
                 if (udev_monitor_filter_add_match_subsystem_devtype(mon, LIBUDEV_SUBSYSTEM_DRM, NULL) < 0) {
-                    printf("ERROR[%s:%d] udev_monitor_filter_add_match_subsystem_devtype failed,\n", __FUNCTION__, __LINE__);
+                    ERROR("ERROR[%s:%d] udev_monitor_filter_add_match_subsystem_devtype failed,\n", __FUNCTION__, __LINE__);
                 } else {
                     if (udev_monitor_enable_receiving(mon) < 0) {
-                        printf("ERROR[%s:%d] udev_monitor_enable_receiving\n", __FUNCTION__, __LINE__);
+                        DEBUG("ERROR[%s:%d] udev_monitor_enable_receiving\n", __FUNCTION__, __LINE__);
                     } else {
                         while (isMonitoringAlive) {
                             FD_ZERO(&fds);
@@ -115,13 +114,13 @@
                                 dev = udev_monitor_receive_device(mon);
                                 if (dev) {
                                     if (!strcmp(udev_device_get_action(dev), "change")) {
-                                        printf("I: ACTION=%s\n", udev_device_get_action(dev));
-                                        printf("I: DEVNAME=%s\n", udev_device_get_sysname(dev));
-                                        printf("I: DEVPATH=%s\n", udev_device_get_devpath(dev));
+                                        DEBUG("I: ACTION=%s\n", udev_device_get_action(dev));
+                                        DEBUG("I: DEVNAME=%s\n", udev_device_get_sysname(dev));
+                                        DEBUG("I: DEVPATH=%s\n", udev_device_get_devpath(dev));
                                         enConnection = meson_drm_getConnection();
                                         if ( enPreConnection != enConnection) {
                                             enPreConnection = enConnection;
-                                            printf("Send %s HDMI Hot Plug Event !!!\n",
+                                            DEBUG("Send %s HDMI Hot Plug Event !!!\n",
                                                     (enConnection ? "Connect":"DisConnect"));
                                             enDisplayEvent = enConnection ? DISPLAY_EVENT_CONNECTED:DISPLAY_EVENT_DISCONNECTED;
                                             if (_DisplayEventCb) {
@@ -129,11 +128,11 @@
                                             }
                                         }
                                         if ( !get_hdcp_status(&enCurStatus) )
-                                            printf("%s:%d: get_hdcp_status fail\n", __func__, __LINE__);
+                                            ERROR("%s:%d: get_hdcp_status fail", __func__, __LINE__);
                                         if ( enCurStatus != enPreStatus ) {
                                             enPreStatus = enCurStatus;
                                             enDisplayEvent = enCurStatus ? DISPLAY_HDCP_AUTHENTICATIONFAILURE:DISPLAY_HDCP_AUTHENTICATED;
-                                            printf("Send %s !!!\n", (enCurStatus ? "DISPLAY_HDCP_AUTHENTICATIONFAILURE":"DISPLAY_HDCP_AUTHENTICATED"));
+                                            DEBUG("Send %s !!!\n", (enCurStatus ? "DISPLAY_HDCP_AUTHENTICATIONFAILURE":"DISPLAY_HDCP_AUTHENTICATED"));
                                             if (_DisplayEventCb) {
                                                 _DisplayEventCb( enDisplayEvent, NULL);
                                             }
@@ -143,7 +142,7 @@
                                     udev_device_unref(dev);
                                 }
                                 else {
-                                    printf("I:[%s:%d] udev_monitor_receive_device failed\n", __FUNCTION__, __LINE__);
+                                    DEBUG("I:[%s:%d] udev_monitor_receive_device failed", __FUNCTION__, __LINE__);
                                     enConnection = MESON_DRM_UNKNOWNCONNECTION;
                                     enPreConnection = MESON_DRM_UNKNOWNCONNECTION;
                                 }
@@ -155,7 +154,7 @@
                 }
             }
         } else {
-            printf("ERROR[%s:%d] udev_monitor_new_from_netlink failed\n", __FUNCTION__, __LINE__);
+            ERROR("ERROR[%s:%d] udev_monitor_new_from_netlink failed", __FUNCTION__, __LINE__);
         }
     }
     udev = NULL;
diff --git a/meson/meson_drm_log.c b/meson/meson_drm_log.c
new file mode 100644
index 0000000..cc3e60a
--- /dev/null
+++ b/meson/meson_drm_log.c
@@ -0,0 +1,54 @@
+#include <time.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdbool.h>
+#include "meson_drm_log.h"
+#include <sys/time.h>
+
+static int g_activeLevel= 1;
+
+long long getMonotonicTimeMicros( void )
+{
+   int rc;
+   struct timespec tm;
+   long long timeMicro;
+   static bool reportedError= false;
+   if ( !reportedError )
+   {
+      rc= clock_gettime( CLOCK_MONOTONIC, &tm );
+   }
+   if ( reportedError || rc )
+   {
+      struct timeval tv;
+      if ( !reportedError )
+      {
+         reportedError= true;
+         ERROR("clock_gettime failed rc %d - using timeofday", rc);
+      }
+      gettimeofday(&tv,0);
+      timeMicro= tv.tv_sec*1000000LL+tv.tv_usec;
+   }
+   else
+   {
+      timeMicro= tm.tv_sec*1000000LL+(tm.tv_nsec/1000LL);
+   }
+   return timeMicro;
+}
+
+void mesonDrmLog( int level, const char *fmt, ... )
+{
+   const char *env= getenv( "LIBMESON_GL_DEBUG" );
+   if ( env )
+   {
+      int level= atoi( env );
+      g_activeLevel= level;
+   }
+   if ( level <= g_activeLevel )
+   {
+      va_list argptr;
+      fprintf( stderr, "%lld: ", getMonotonicTimeMicros());
+      va_start( argptr, fmt );
+      vfprintf( stderr, fmt, argptr );
+      va_end( argptr );
+   }
+}
diff --git a/meson/meson_drm_log.h b/meson/meson_drm_log.h
new file mode 100644
index 0000000..4c7d4c7
--- /dev/null
+++ b/meson/meson_drm_log.h
@@ -0,0 +1,27 @@
+#ifndef LIBDRM_MESON_LOG_H_
+#define LIBDRM_MESON_LOG_H_
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void mesonDrmLog( int level, const char *fmt, ... );
+long long getMonotonicTimeMicros( void );
+
+#define INT_ERROR(FORMAT, ...)      mesonDrmLog(0, "ERROR: %s:%d " FORMAT "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define INT_INFO(FORMAT, ...)       mesonDrmLog(1, "INFO: %s:%d " FORMAT "\n", __FILE__, __LINE__, __VA_ARGS__)
+#define INT_DEBUG(FORMAT, ...)      mesonDrmLog(2, "DEBUG: %s:%d " FORMAT "\n", __FILE__, __LINE__, __VA_ARGS__)
+
+#define ERROR(...)                  INT_ERROR(__VA_ARGS__, "")
+#define INFO(...)                   INT_INFO(__VA_ARGS__, "")
+#define DEBUG(...)                  INT_DEBUG(__VA_ARGS__, "")
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/meson/meson_drm_settings.c b/meson/meson_drm_settings.c
index 08b54a7..f1ea2da 100644
--- a/meson/meson_drm_settings.c
+++ b/meson/meson_drm_settings.c
@@ -17,6 +17,7 @@
 #include "libdrm_meson_connector.h"
 #include "libdrm_meson_property.h"
 #include "meson_drm_settings.h"
+#include "meson_drm_log.h"
 
 #define DEFAULT_CARD "/dev/dri/card0"
 #define PROP_NAME_MAX_LEN 50
@@ -38,13 +39,13 @@
     struct mesonConnector* conn = NULL;
     if ( drmFd < 0 || name == NULL || propValue == NULL)
     {
-        fprintf(stderr, "\n%s %d drmfd invalid, or property name invalid\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmfd invalid, or property name invalid",__FUNCTION__,__LINE__);
         goto out;
     }
     conn = get_current_connector(drmFd, connType);
     if ( conn == NULL )
     {
-        fprintf(stderr, "\n%s %d get_current_connector fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d get_current_connector fail",__FUNCTION__,__LINE__);
         goto out;
     }
     objID =  mesonConnectorGetId(conn);
@@ -53,12 +54,12 @@
     struct mesonProperty* meson_prop = NULL;
     meson_prop = mesonPropertyCreate(drmFd, objID, objType, name);
     if (!meson_prop) {
-        printf("\n meson_prop create fail\n");
+        ERROR("meson_prop create fail");
         goto out;
     }
     uint64_t value = mesonPropertyGetValue(meson_prop);
     *propValue = (uint32_t)value;
-    fprintf(stderr, "\n prop value:%llu objID:%d,name:%s\n",value, objID,name);
+    DEBUG("prop value:%llu objID:%d,name:%s",value, objID,name);
     mesonPropertyDestroy(meson_prop);
     ret = 0;
 out:
@@ -82,7 +83,7 @@
     struct mesonConnector* connector = NULL;
     int drmConnType = DRM_MODE_CONNECTOR_HDMIA;
     if (drmFd < 0) {
-        fprintf(stderr, "\n %s %d invalid drmFd return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid drmFd return",__FUNCTION__,__LINE__);
         return NULL;
     }
     switch (connType)
@@ -117,16 +118,16 @@
     }
     ret_fd = open(card, O_RDONLY|O_CLOEXEC);
     if ( ret_fd < 0 )
-        fprintf(stderr, "\n meson_open_drm  drm card:%s open fail\n",card);
+        ERROR(" meson_open_drm  drm card:%s open fail",card);
     else
         drmDropMaster(ret_fd);
     ret = drmSetClientCap(ret_fd, DRM_CLIENT_CAP_ATOMIC, 1);
     if (ret < 0)
-        fprintf(stderr, "Unable to set DRM atomic capability\n");
+        DEBUG("Unable to set DRM atomic capability");
 
     ret = drmSetClientCap(ret_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1);
     if (ret < 0)
-        fprintf(stderr, "Unable to set UNIVERSAL_PLANES\n");
+        DEBUG("Unable to set UNIVERSAL_PLANES");
     return ret_fd;
 }
 void meson_close_drm(int drmFd)
@@ -141,17 +142,17 @@
     uint32_t propId;
     int rc = -1;
     if (drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return rc;
     }
     struct mesonProperty *prop = NULL;
     prop = mesonPropertyCreate(drmFd, objId, objType, name);
     propId = mesonPropertyGetId(prop);
     mesonPropertyDestroy(prop);
-    fprintf(stderr, "\nmeson_drm_set_property name:%s objId:%d propId:%d value:%llu\n", name, objId, propId, value);
+    DEBUG("meson_drm_set_property name:%s objId:%d propId:%d value:%llu", name, objId, propId, value);
     rc = drmModeAtomicAddProperty( req, objId, propId, value );
     if (rc < 0)
-        fprintf(stderr, "\n %s %d meson_drm_set_property fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d meson_drm_set_property fail",__FUNCTION__,__LINE__);
     return rc;
 }
 
@@ -166,7 +167,7 @@
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
     if (0 != mesonConnectorGetModes(conn, drmFd, &modes, &count))
         goto out;
@@ -195,13 +196,13 @@
     int ret = -1;
     struct mesonConnector* conn = NULL;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = mesonConnectorCreate(drmFd, DRM_MODE_CONNECTOR_HDMIA);
     if (conn == NULL || drmFd < 0)
     {
-        printf("\n%s %d connector create fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail",__FUNCTION__,__LINE__);
     }
     drmModeModeInfo* modeall = NULL;
     int count = 0;
@@ -232,7 +233,7 @@
     struct mesonConnector* conn = NULL;
     drmModeModeInfo* mode = NULL;
     if (modeInfo == NULL || drmFd < 0) {
-        fprintf(stderr, "\n %s %d modeInfo == NULL || drmFd < 0 return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d modeInfo == NULL || drmFd < 0 return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -248,10 +249,10 @@
             mode = NULL;
             ret = 0;
         } else {
-            fprintf(stderr, "\n %s %d mode get fail \n",__FUNCTION__,__LINE__);
+            ERROR(" %s %d mode get fail ",__FUNCTION__,__LINE__);
         }
     } else {
-        fprintf(stderr, "\n %s %d conn create fail \n",__FUNCTION__,__LINE__);
+        ERROR("%s %d conn create fail ",__FUNCTION__,__LINE__);
     }
     if (conn)
         mesonConnectorDestroy(drmFd,conn);
@@ -277,7 +278,7 @@
     int modesNumber = 0;
 
     if (modeInfo == NULL || drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     if (connType == MESON_CONNECTOR_CVBS)
@@ -289,7 +290,7 @@
         HDMIconnId = mesonConnectorGetId(connHDMI);
         rc4 = meson_drm_set_property(drmFd, req, HDMIconnId, DRM_MODE_OBJECT_CONNECTOR, "CRTC_ID", 0);
         mesonConnectorDestroy(drmFd,connHDMI);
-        fprintf(stderr, "\n %s %d change mode to cvbs, disconnect HDMI :%d \n",__FUNCTION__,__LINE__,rc4);
+        DEBUG(" %s %d change mode to cvbs, disconnect HDMI :%d ",__FUNCTION__,__LINE__,rc4);
     }
     conn = get_current_connector(drmFd, connType);
     connId = mesonConnectorGetId(conn);
@@ -309,7 +310,7 @@
             }
         }
     } else {
-        fprintf(stderr, "\n %s %d conn create fail \n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d conn create fail ",__FUNCTION__,__LINE__);
     }
 
     if (found) {
@@ -318,7 +319,7 @@
         if (rc == 0) {
             rc2 = meson_drm_set_property(drmFd, req, crtcId, DRM_MODE_OBJECT_CRTC, "MODE_ID", blobId);
             rc3 = meson_drm_set_property(drmFd, req, crtcId, DRM_MODE_OBJECT_CRTC, "ACTIVE", 1);
-            fprintf(stderr, "\n %s %d  rc1:%d rc:%d rc2:%d, rc3:%d\n",__FUNCTION__,__LINE__, rc1, rc,rc2,rc3);
+            DEBUG("%s %d  rc1:%d rc:%d rc2:%d, rc3:%d",__FUNCTION__,__LINE__, rc1, rc,rc2,rc3);
             if (rc1 >= 0 && rc2 >= 0 && rc3 >= 0)
                 ret = 0;
         }
@@ -333,7 +334,7 @@
     ENUM_MESON_CONN_CONNECTION ret = MESON_UNKNOWNCONNECTION;
     struct mesonConnector* conn = NULL;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR( "%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -348,7 +349,7 @@
             ret = MESON_UNKNOWNCONNECTION;
         }
     } else {
-        fprintf(stderr, "\n drm open fail\n");
+        ERROR(" drm open fail");
     }
     if (conn)
         mesonConnectorDestroy(drmFd,conn);
@@ -362,7 +363,7 @@
     uint32_t value = 0;
     ENUM_MESON_COLOR_SPACE colorSpace = MESON_COLOR_SPACE_RESERVED;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return colorSpace;
     }
     if ( 0 == meson_drm_get_conn_prop_value(drmFd, connType, propName, &value )) {
@@ -385,7 +386,7 @@
                 break;
         }
     } else {
-        fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+        ERROR("\n%s %d fail\n",__FUNCTION__,__LINE__);
     }
     return colorSpace;
 }
@@ -397,7 +398,7 @@
     int rc = -1;
     struct mesonConnector* conn = NULL;
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -419,11 +420,11 @@
     sprintf( propName, "%s", DRM_CONNECTOR_PROP_COLOR_DEPTH);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("\n%s %d fail\n",__FUNCTION__,__LINE__);
     }
     return value;
 }
@@ -436,7 +437,7 @@
     uint32_t connId = 0;
     conn = get_current_connector(drmFd, connType);
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     if (conn) {
@@ -456,7 +457,7 @@
     uint32_t value = 0;
     ENUM_MESON_HDR_POLICY hdrPolicy = MESON_HDR_POLICY_FOLLOW_SINK;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR( "%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return hdrPolicy;
     }
     if ( 0 == meson_drm_get_crtc_prop_value( drmFd, connType, propName, &value )) {
@@ -477,7 +478,7 @@
     uint32_t crtcId = 0;
     conn = get_current_connector(drmFd, connType);
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     if (conn) {
@@ -498,7 +499,7 @@
     uint32_t value = 0;
     ENUM_MESON_HDCP_VERSION hdcpVersion = MESON_HDCP_RESERVED;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return hdcpVersion;
     }
     if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
@@ -517,7 +518,7 @@
     uint32_t value = 0;
     ENUM_MESON_HDR_MODE hdrMode = MESON_SDR;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return hdrMode;
     }
     if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
@@ -549,7 +550,7 @@
                 break;
         }
     } else {
-        fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
     return hdrMode;
 }
@@ -560,19 +561,19 @@
     char* edid_data = NULL;
     struct mesonConnector* conn = NULL;
     if (drmFd < 0 || data_Len == NULL || data == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return;
     }
     conn = get_current_connector(drmFd, connType);
     if (conn == NULL) {
-        fprintf(stderr, "\n%s %d connector create fail.return \n",__FUNCTION__,__LINE__);
+        ERROR("%s %d connector create fail.return ",__FUNCTION__,__LINE__);
         return;
     }
     if (0 != mesonConnectorGetEdidBlob(conn, &count, &edid_data))
         goto out;
     char* edid =  (char*)calloc(count, sizeof(char));
     if (edid == NULL) {
-        fprintf(stderr, "\n%s %d edid alloc mem fail.return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d edid alloc mem fail.return",__FUNCTION__,__LINE__);
         return;
     }
     for (i = 0; i < count; i++)
@@ -595,7 +596,7 @@
     struct mesonConnector* conn = NULL;
     uint32_t connId = 0;
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -616,13 +617,13 @@
     sprintf( propName, "%s", MESON_DRM_HDMITX_PROP_AVMUTE);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
-    fprintf(stderr, "\n AVMute control, 1 means set avmute, 0 means not avmute\n");
+    DEBUG("AVMute control, 1 means set avmute, 0 means not avmute");
     return value;
 }
 
@@ -633,7 +634,7 @@
     uint32_t value = 0;
     ENUM_MESON_HDCPAUTH_STATUS hdcpAuthStatus = MESON_AUTH_STATUS_FAIL;
     if ( drmFd < 0 ) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return hdcpAuthStatus;
     }
     if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
@@ -652,7 +653,7 @@
     struct mesonConnector* conn = NULL;
     uint32_t connId = 0;
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -675,7 +676,7 @@
     struct mesonConnector* conn = NULL;
     uint32_t connId = 0;
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR( " %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     conn = get_current_connector(drmFd, connType);
@@ -697,7 +698,7 @@
     uint32_t value = 0;
     ENUM_MESON_HDCP_Content_Type ContentType = MESON_HDCP_Type_RESERVED;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return ContentType;
     }
     if ( 0 == meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
@@ -714,7 +715,7 @@
                 break;
         }
     } else {
-        fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
     return ContentType;
 }
@@ -726,7 +727,7 @@
     uint32_t value = 0;
     MESON_CONTENT_TYPE ContentType = MESON_CONTENT_TYPE_RESERVED;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return ContentType;
     }
     if ( 0 == meson_drm_get_conn_prop_value(drmFd, connType, propName, &value )) {
@@ -752,7 +753,7 @@
                 break;
         }
     } else {
-        fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
     return ContentType;
 }
@@ -766,7 +767,7 @@
     uint32_t crtcId = 0;
     conn = get_current_connector(drmFd, connType);
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     if (conn) {
@@ -786,11 +787,11 @@
     sprintf( propName, "%s", DRM_CONNECTOR_PROP_DV_ENABLE);
     uint32_t value = -1;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_crtc_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
     return value;
 }
@@ -804,7 +805,7 @@
     uint32_t crtcId = 0;
     conn = get_current_connector(drmFd, connType);
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR(" %s %d invalid parameter return",__FUNCTION__,__LINE__);
         return ret;
     }
     if (conn) {
@@ -824,11 +825,11 @@
     sprintf( propName, "%s", DRM_CONNECTOR_PROP_ACTIVE);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_crtc_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("\n%s %d fail\n",__FUNCTION__,__LINE__);
     }
     return value;
 }
@@ -842,7 +843,7 @@
     uint32_t crtcId = 0;
     conn = get_current_connector(drmFd, connType);
     if ( drmFd < 0 || req == NULL) {
-        fprintf(stderr, "\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
+        ERROR("\n %s %d invalid parameter return\n",__FUNCTION__,__LINE__);
         return ret;
     }
     if (conn) {
@@ -862,11 +863,11 @@
     sprintf( propName, "%s", DRM_CONNECTOR_VRR_ENABLED);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_crtc_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
     return value;
 }
@@ -877,13 +878,13 @@
     sprintf( propName, "%s", DRM_CONNECTOR_PROP_RX_HDR_CAP);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
-    fprintf(stderr, "hdr_cap:presents the RX HDR capability [r]\n");
+    DEBUG("hdr_cap:presents the RX HDR capability [r]");
     return value;
 }
 
@@ -893,15 +894,13 @@
     sprintf( propName, "%s", DRM_CONNECTOR_PROP_RX_DV_CAP);
     uint32_t value = 0;
     if ( drmFd < 0) {
-        fprintf(stderr, "\n%s %d drmFd < 0\n",__FUNCTION__,__LINE__);
+        ERROR("%s %d drmFd < 0",__FUNCTION__,__LINE__);
         return value;
     }
     if ( 0 != meson_drm_get_conn_prop_value( drmFd, connType, propName, &value )) {
-         fprintf(stderr, "\n%s %d fail\n",__FUNCTION__,__LINE__);
+         ERROR("%s %d fail",__FUNCTION__,__LINE__);
     }
-    fprintf(stderr, "dv_cap:presents the RX dolbyvision capability, [r] such as std or ll mode \n");
+    DEBUG("dv_cap:presents the RX dolbyvision capability, [r] such as std or ll mode ");
     return value;
 }
 
-
-