void ddp_mmp_wdma_layer(WDMA_CONFIG_STRUCT *wdma_layer,unsigned int wdma_num, unsigned int down_sample_x,unsigned int down_sample_y)
{
    if(wdma_num > 1)
    {
        DDPERR("dprec_mmp_dump_wdma_layer is error %d\n",wdma_num);
        return;
    }
    
    MMP_MetaDataBitmap_t Bitmap;
    MMP_MetaData_t meta;
    int raw = 0;

    Bitmap.data1 = wdma_layer->dstAddress;
    Bitmap.width = wdma_layer->srcWidth;
    Bitmap.height = wdma_layer->srcHeight;
    switch (wdma_layer->outputFormat)
    {
        case eRGB565:
        case eBGR565: 
            Bitmap.format = MMProfileBitmapRGB565; 
            Bitmap.bpp = 16;
            break;
        case eRGB888: 
            Bitmap.format = MMProfileBitmapRGB888; 
            Bitmap.bpp = 24;
            break;
        case eBGRA8888:   
            Bitmap.format = MMProfileBitmapBGRA8888; 
            Bitmap.bpp = 32;
            break;
        case eBGR888: 
            Bitmap.format = MMProfileBitmapBGR888; 
            Bitmap.bpp = 24; 
            break;
        case eRGBA8888:
            Bitmap.format = MMProfileBitmapRGBA8888; 
            Bitmap.bpp = 32; 
            break;
        default:
          DDPERR("dprec_mmp_dump_wdma_layer(), unknow fmt=%d, dump raw\n", wdma_layer->outputFormat);
          raw = 1;
    }
    if(!raw)
    {
        Bitmap.start_pos =0;
        Bitmap.pitch = wdma_layer->dstPitch;
        Bitmap.data_size = Bitmap.pitch * Bitmap.height;
        Bitmap.down_sample_x = down_sample_x;
        Bitmap.down_sample_y = down_sample_y;
        if (m4u_mva_map_kernel(wdma_layer->dstAddress, Bitmap.data_size,(unsigned long*)&Bitmap.pData, &Bitmap.data_size)==0)
        {
            MMProfileLogMetaBitmap(DDP_MMP_Events.wdma_dump[wdma_num], MMProfileFlagPulse, &Bitmap);
            m4u_mva_unmap_kernel(wdma_layer->dstAddress, Bitmap.data_size, (unsigned long)Bitmap.pData);
        }
        else
        {
            DDPERR("dprec_mmp_dump_wdma_layer(),fail to dump rgb(0x%x)\n", wdma_layer->outputFormat);
        }
    }
    else
    {
        meta.data_type = MMProfileMetaRaw;
        meta.size = wdma_layer->dstPitch * wdma_layer->srcHeight;
        if(m4u_mva_map_kernel(wdma_layer->dstAddress, meta.size, (unsigned long*)&meta.pData, &meta.size)==0)
        {
            MMProfileLogMeta(DDP_MMP_Events.wdma_dump[wdma_num], MMProfileFlagPulse, &meta);
        }
        else
        {
            DDPERR("dprec_mmp_dump_wdma_layer(),fail to dump raw(0x%x)\n", wdma_layer->outputFormat);
        }            
    }
    
    return 0;

}
void ddp_mmp_ovl_layer(OVL_CONFIG_STRUCT* pLayer,unsigned int down_sample_x,unsigned int down_sample_y,unsigned int session/*1:primary, 2:external, 3:memory*/)
{
    MMP_MetaDataBitmap_t Bitmap;
    MMP_MetaData_t meta;
    int raw = 0;

	if(session == 1)
    	MMProfileLogEx(DDP_MMP_Events.layer_dump_parent,MMProfileFlagStart, pLayer->layer, pLayer->layer_en);
	else if(session == 2)
		MMProfileLogEx(DDP_MMP_Events.Extd_layer_dump_parent,MMProfileFlagStart, pLayer->layer, pLayer->layer_en);

    if (pLayer->layer_en)
    {
        Bitmap.data1 = pLayer->vaddr;
        Bitmap.width = pLayer->dst_w;
        Bitmap.height = pLayer->dst_h;
        switch (pLayer->fmt)
        {
            case eRGB565:
            case eBGR565: 
                Bitmap.format = MMProfileBitmapRGB565; 
                Bitmap.bpp = 16;
                break;
            case eRGB888: 
                Bitmap.format = MMProfileBitmapRGB888; 
                Bitmap.bpp = 24;
                break;
            case eBGRA8888:   
                Bitmap.format = MMProfileBitmapBGRA8888; 
                Bitmap.bpp = 32;
                break;
            case eBGR888: 
                Bitmap.format = MMProfileBitmapBGR888; 
                Bitmap.bpp = 24; 
                break;
            case eRGBA8888:
                Bitmap.format = MMProfileBitmapRGBA8888; 
                Bitmap.bpp = 32; 
                break;
            default:
              DDPERR("ddp_mmp_ovl_layer(), unknow fmt=%d, dump raw\n", pLayer->fmt);
              raw = 1;
        }
        if(!raw)
        {
            Bitmap.start_pos =0;
            Bitmap.pitch = pLayer->src_pitch;
            Bitmap.data_size = Bitmap.pitch * Bitmap.height;
            Bitmap.down_sample_x = down_sample_x;
            Bitmap.down_sample_y = down_sample_y;
            if (m4u_mva_map_kernel(pLayer->addr, Bitmap.data_size,(unsigned long*)&Bitmap.pData, &Bitmap.data_size)==0)
            {
            	if(session == 1)
                	MMProfileLogMetaBitmap(DDP_MMP_Events.layer_dump[pLayer->layer], MMProfileFlagPulse, &Bitmap);
				else if(session == 2)
					MMProfileLogMetaBitmap(DDP_MMP_Events.ovl1layer_dump[pLayer->layer], MMProfileFlagPulse, &Bitmap);
                m4u_mva_unmap_kernel(pLayer->addr, Bitmap.data_size, (unsigned long)Bitmap.pData);
            }
            else
            {
                DDPERR("ddp_mmp_ovl_layer(),fail to dump rgb(0x%x)\n", pLayer->fmt);
            }
        }
        else
        {
            meta.data_type = MMProfileMetaRaw;
            meta.size = pLayer->src_pitch * pLayer->src_h;
            if(m4u_mva_map_kernel(pLayer->addr, meta.size, (unsigned long*)&meta.pData, &meta.size)==0)
            {
            	if(session == 1)
                	MMProfileLogMeta(DDP_MMP_Events.layer_dump[pLayer->layer], MMProfileFlagPulse, &meta);
				else if(session == 2)
					MMProfileLogMeta(DDP_MMP_Events.ovl1layer_dump[pLayer->layer], MMProfileFlagPulse, &meta);
                m4u_mva_unmap_kernel(pLayer->addr, meta.size, (unsigned long)meta.pData);
            }
            else
            {
                DDPERR("ddp_mmp_ovl_layer(),fail to dump raw(0x%x)\n", pLayer->fmt);
            }            
        }
    }

	if(session == 1)
    	MMProfileLogEx(DDP_MMP_Events.layer_dump_parent,MMProfileFlagEnd, pLayer->fmt, pLayer->addr);
	else if(session == 2)
		MMProfileLogEx(DDP_MMP_Events.Extd_layer_dump_parent,MMProfileFlagEnd, pLayer->fmt, pLayer->addr);
	
    return ;
}
static long fbconfig_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	int ret = 0;
	void __user *argp = (void __user *)arg;
	DISP_DRV_WRAN("sxk=>run in fbconfig_ioctl**\n");

	switch (cmd) {
	case LCM_GET_ID:
		{
			/* get_lcm_id() need implemented in lcm driver ... */
#if 0
			LCM_DRIVER *lcm = lcm_drv;
			unsigned int lcm_id = lcm->get_lcm_id();
#else
			unsigned int lcm_id = 0;
#endif
			return copy_to_user(argp, &lcm_id, sizeof(lcm_id)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CONTINU:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(10);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_CONTINU:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_TEST_DSI_CLK:
		{
			LCM_TYPE_FB lcm_fb;
			lcm_fb.clock = lcm_params->dsi.PLL_CLOCK;
			lcm_fb.lcm_type = lcm_params->dsi.mode;
			DISP_DRV_WRAN("fbconfig=>LCM_TEST_DSI_CLK:%d\n", ret);
			return copy_to_user(argp, &lcm_fb, sizeof(lcm_fb)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CLK:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(11);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_CLK:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_CLK_V2:
		{
			unsigned int ret = 0;
			MIPI_CLK_V2 clock_v2;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(11);
			clock_v2.div1 = ret & 0x00000600;
			clock_v2.div2 = ret & 0x00000180;
			clock_v2.fbk_div = ret & 0x0000007F;
			return copy_to_user(argp, &clock_v2, sizeof(clock_v2)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_SSC:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(9);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_SSC:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_LANE_NUM:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(12);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_LANE_NUM:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_TE:
		{
			int ret;
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(13);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_TE:%d\n", ret);
			return copy_to_user(argp, &ret, sizeof(ret)) ? -EFAULT : 0;
		}
	case LCM_GET_DSI_TIMING:
		{
			int ret = 0;
			MIPI_TIMING timing;
			if (copy_from_user(&timing, (void __user *)argp, sizeof(timing))) {
				DISP_DRV_WRAN("[MIPI_SET_TIMING]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			if (fbconfig_if_drv->set_spread_frequency)
				ret = fbconfig_if_drv->set_spread_frequency(100 + timing.type);
			DISP_DRV_WRAN("fbconfig=>LCM_GET_DSI_TIMING:%d\n", ret);
			timing.value = ret;
			return copy_to_user(argp, &timing, sizeof(timing)) ? -EFAULT : 0;
		}
	case DRIVER_IC_CONFIG:
		{
			DISP_DRV_WRAN("sxk=>run in case:DRIVER_IC_CONFIG**\n");
			if (record_list_initialed == 0) {
				record_list_init();
				if (copy_from_user(record_head, (void __user *)arg, sizeof(CONFIG_RECORD))) {
					DISP_DRV_WRAN("sxk=>copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				}
#if 0
				print_record(record_head);
#endif
				record_list_initialed = 1;
			} else {
				if (copy_from_user(record_tmp, (void __user *)arg, sizeof(CONFIG_RECORD))) {
					DISP_DRV_WRAN("[DRIVER_IC_CONFIG]: copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				}
#if 0				/* FBCONFIG_DEBUG */
				DISP_DRV_WRAN("sxk=>will print before add to list\n");
				print_record(record_tmp);
#endif
				record_list_add();	/* add new node to list ; */

			}

			return 0;
		}
	case MIPI_SET_CLK:
		{
			unsigned int clk;
			if (copy_from_user(&clk, (void __user *)argp, sizeof(clk))) {
				DISP_DRV_WRAN("[MIPI_SET_CLK]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				fbconfig_disp_set_mipi_clk(clk);
			}
			return 0;
		}
	case MIPI_SET_CLK_V2:
		{
			MIPI_CLK_V2 clk;
			if (copy_from_user(&clk, (void __user *)argp, sizeof(clk))) {
				DISP_DRV_WRAN("[MIPI_SET_CLK]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				unsigned int clk_v2 = 0;
				/* div1_2bits  div2_2bits  fbk_div_7bits */
				clk_v2 = (clk.div1 << 9) | (clk.div2 << 7) | clk.fbk_div;
				fbconfig_disp_set_mipi_clk(clk_v2);
			}
			return 0;
		}
	case MIPI_SET_SSC:
		{
			unsigned int ssc;
			DISP_DRV_WRAN("sxk=>debug.c call set mipi ssc line:%d\n", __LINE__);
			if (copy_from_user(&ssc, (void __user *)argp, sizeof(ssc))) {
				DISP_DRV_WRAN("[MIPI_SET_SSC]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				DISP_DRV_WRAN("sxk=>debug.c call set mipi ssc line:%d\n", __LINE__);
				fbconfig_disp_set_mipi_ssc(ssc);
			}
			return 0;
		}
	case MIPI_SET_LANE:
		{
			unsigned int lane_num;
			if (copy_from_user(&lane_num, (void __user *)argp, sizeof(lane_num))) {
				DISP_DRV_WRAN("[MIPI_SET_LANE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				fbconfig_disp_set_mipi_lane_num(lane_num);
			}
			return 0;
		}
	case MIPI_SET_TIMING:
		{
			if (!is_early_suspended) {
				MIPI_TIMING timing;
				if (copy_from_user(&timing, (void __user *)argp, sizeof(timing))) {
					DISP_DRV_WRAN("[MIPI_SET_TIMING]: copy_from_user failed! line:%d\n", __LINE__);
					return -EFAULT;
				} else {
					fbconfig_disp_set_mipi_timing(timing);
				}
				return 0;
			} else
				return -EFAULT;
		}
	case TE_SET_ENABLE:
		{
			char enable;
			if (copy_from_user(&enable, (void __user *)argp, sizeof(enable))) {
				DISP_DRV_WRAN("[TE_SET_ENABLE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				if (fbconfig_if_drv->set_te_enable)
					fbconfig_if_drv->set_te_enable(enable);
			}
			return 0;
		}
	case FB_LAYER_GET_EN:
		{
			FBCONFIG_LAYER_INFO layers;
			fbconfig_get_layer_info(&layers);
			return copy_to_user(argp, &layers, sizeof(layers)) ? -EFAULT : 0;
		}
	case FB_LAYER_GET_SIZE:
		{
			LAYER_H_SIZE tmp;
			int layer_size, enable, height, fmt;
			if (copy_from_user(&tmp, (void __user *)argp, sizeof(LAYER_H_SIZE))) {
				DISP_DRV_WRAN("[TE_SET_ENABLE]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			global_layer_id = tmp.height;
			DISP_DRV_WRAN("sxk==>global_layer_id is %d\n", global_layer_id);
			fbconfig_get_layer_height(global_layer_id, &layer_size, &enable, &height, &fmt);
			if ((layer_size == 0) || (enable == 0) || (height == 0))
				return -2;
			else {
				tmp.height = height;
				tmp.layer_size = layer_size;
				tmp.fmt = DP_COLOR_BITS_PER_PIXEL(fmt);
				return copy_to_user(argp, &tmp, sizeof(tmp)) ? -EFAULT : 0;
			}
		}
	case FB_LAYER_DUMP:
		{
			int layer_size, enable;
			int ret = 0;
			unsigned int kva = 0;
			unsigned int mapped_size = 0;
			unsigned int mva = fbconfig_get_layer_vaddr(global_layer_id, &layer_size, &enable);
			if ((layer_size != 0) && (enable != 0)) {
				DISP_DRV_WRAN("sxk==>FB_LAYER_DUMP==>layer_size is %d   mva is 0x%x\n", layer_size,
					      mva);
				m4u_mva_map_kernel(mva, layer_size, 0, &kva, &mapped_size);
				DISP_DRV_WRAN("sxk==> addr from user space is 0x%x\n", (unsigned int)argp);
				DISP_DRV_WRAN("sxk==> kva is 0x%x   mmaped size is %d\n", kva, mapped_size);
				ret = copy_to_user(argp, (void *)kva, mapped_size) ? -EFAULT : 0;
				m4u_mva_unmap_kernel(mva, mapped_size, kva);
				return ret;
			} else
				return -2;
		}
	case MIPI_SET_CC:
		{
			int enable;
			if (copy_from_user(&enable, (void __user *)argp, sizeof(enable))) {
				DISP_DRV_WRAN("[MIPI_SET_CC]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			} else {
				if (fbconfig_if_drv->set_continuous_clock)
					fbconfig_if_drv->set_continuous_clock(enable);
			}
			return 0;
		}
	case LCM_GET_ESD:
		{
			ESD_PARA esd_para;
			int i = 0;
			if (copy_from_user(&esd_para, (void __user *)arg, sizeof(esd_para))) {
				DISP_DRV_WRAN("[LCM_GET_ESD]: copy_from_user failed! line:%d\n", __LINE__);
				return -EFAULT;
			}
			esd_check_addr = esd_para.addr;
			esd_check_para_num = esd_para.para_num;
			ret = fbconfig_get_esd_check();
			if ((ret != 0) && (esd_check_buffer != NULL)) {
				kfree(esd_check_buffer);
				return -2;
			} else {
				for (i = 0; i < esd_check_para_num + 6; i++)
					DISP_DRV_WRAN("sxk=>%s, esd_check_buffer[%d]=0x%x\n", __func__, i,
						      esd_check_buffer[i]);
				return 0;
			}
		}
	case LCM_GET_ESD_RET:
		{
			ret =
			    (copy_to_user(argp, (void *)esd_check_buffer, sizeof(char) * (esd_check_para_num + 6)) ?
			     -EFAULT : 0);
			if (esd_check_buffer != NULL) {
				kfree(esd_check_buffer);
				esd_check_buffer = NULL;
			}
			return ret;
		}
	case DRIVER_IC_RESET:
		{
			fbconfig_reset_lcm_setting();
			fbconfig_free_backup_setting();
			return 0;
		}
	default:
		return ret;
	}
}
int disphal_dma_map_kernel(unsigned int dma_pa, unsigned int size, unsigned int* kva, unsigned int* mapsize)
{
    m4u_mva_map_kernel(dma_pa, size, 0, kva, mapsize);
    return 0;
}
void _debug_pattern(unsigned int mva, unsigned int va, unsigned int w, unsigned int h, unsigned int linepitch, unsigned int color, unsigned int layerid, unsigned int bufidx)
{
	if(g_display_debug_pattern_index == 0)
		return;
	
	unsigned int addr = 0;
	unsigned int layer_size = 0;
	unsigned int mapped_size = 0;
	
	unsigned int bcolor = 0xff808080;
	if(layerid == 0) bcolor = 0x0000ffff;
	else if(layerid == 1) bcolor = 0x00ff00ff;
	else if(layerid == 2) bcolor = 0xff0000ff;
	else if(layerid == 3) bcolor = 0xffff00ff;

	if(va)
	{
		addr = va;
	}
	else
	{
		layer_size = linepitch*h;
		m4u_mva_map_kernel(mva, layer_size,&addr, &mapped_size);		
		if(mapped_size == 0)
		{
			DISPERR("m4u_mva_map_kernel failed\n");
			return;
		}
	}
	
	switch(g_display_debug_pattern_index)
	{
		case 1:
		{
			unsigned int resize_factor = layerid+1;

			_draw_rect(addr, w/10*resize_factor+0, h/10*resize_factor+0, w/10*(10-resize_factor)-0, h/10*(10-resize_factor)-0, linepitch, bcolor);
			_draw_rect(addr, w/10*resize_factor+1, h/10*resize_factor+1, w/10*(10-resize_factor)-1, h/10*(10-resize_factor)-1, linepitch, bcolor);
			_draw_rect(addr, w/10*resize_factor+2, h/10*resize_factor+2, w/10*(10-resize_factor)-2, h/10*(10-resize_factor)-2, linepitch, bcolor);
			_draw_rect(addr, w/10*resize_factor+3, h/10*resize_factor+3, w/10*(10-resize_factor)-3, h/10*(10-resize_factor)-3, linepitch, bcolor);
			break;
		}
		case 2:
		{
			int x = 0;
			int y = 0;
			int bw = 20;
			int bh = 20;
			_draw_block(addr, bufidx%(w/bw)*bw, bufidx%(w*h/bh/bh)/(w/bh)*bh, bw, bh, linepitch, bcolor);
			break;
		}
	}
#ifndef CONFIG_MTK_FPGA		
	//smp_inner_dcache_flush_all();
	//outer_flush_all();//remove in early porting
#endif
	if(mapped_size)
	{
		m4u_mva_unmap_kernel(addr, layer_size, addr);
	}

	return;
}