2 * Copyright (C) 2013 ROCKCHIP, Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/delay.h>
16 #include <linux/slab.h>
17 #include "hw_iep_reg.h"
19 #include "hw_iep_config_addr.h"
21 static void iep_config_src_size(struct IEP_MSG *iep_msg)
23 IEP_REGB_SRC_IMG_WIDTH(iep_msg->base, iep_msg->src.act_w - 1);
24 IEP_REGB_SRC_IMG_HEIGHT(iep_msg->base, iep_msg->src.act_h - 1);
26 IEP_DBG(" //==source image size config===================//\n\n");
27 IEP_DBG("sw_src_img_height = %d;//source image height \n",
28 iep_msg->src.act_h - 1);
29 IEP_DBG("sw_src_img_width = %d;//source image width \n\n",
30 iep_msg->src.act_w - 1);
34 static void iep_config_dst_size(struct IEP_MSG *iep_msg)
36 IEP_REGB_DST_IMG_WIDTH(iep_msg->base, iep_msg->dst.act_w - 1);
37 IEP_REGB_DST_IMG_HEIGHT(iep_msg->base, iep_msg->dst.act_h - 1);
39 IEP_DBG(" //==destination image size config===================//\n\n");
40 IEP_DBG("sw_dst_img_height = %d;//source image height \n",
41 iep_msg->dst.act_h - 1);
42 IEP_DBG("sw_dst_img_width = %d;//source image width \n",
43 iep_msg->dst.act_w - 1);
47 static void iep_config_dst_width_tile(struct IEP_MSG *iep_msg)
49 /*IEP_REGB_DST_IMG_WIDTH_TILE0();
50 IEP_REGB_DST_IMG_WIDTH_TILE1();
51 IEP_REGB_DST_IMG_WIDTH_TILE2();
52 IEP_REGB_DST_IMG_WIDTH_TILE3();*/
54 IEP_DBG("sw_dst_width_tile0 = 0;\n");
55 IEP_DBG("sw_dst_width_tile1 = 0;\n");
56 IEP_DBG("sw_dst_width_tile2 = 0;\n");
57 IEP_DBG("sw_dst_width_tile3 = 0;\n\n");
61 static void iep_config_dst_fmt(struct IEP_MSG *iep_msg)
63 unsigned int dst_fmt = 0;
64 unsigned int dst_rgb_swap = 0;
65 unsigned int dst_yuv_swap = 0;
66 switch (iep_msg->dst.format) {
67 case IEP_FORMAT_ARGB_8888 :
68 IEP_REGB_DST_FMT(iep_msg->base, 0);
69 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 0);
74 case IEP_FORMAT_ABGR_8888 :
75 IEP_REGB_DST_FMT(iep_msg->base, 0);
76 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 1);
81 case IEP_FORMAT_RGBA_8888 :
82 IEP_REGB_DST_FMT(iep_msg->base, 0);
83 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 2);
88 case IEP_FORMAT_BGRA_8888 :
89 IEP_REGB_DST_FMT(iep_msg->base, 0);
90 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 3);
95 case IEP_FORMAT_RGB_565 :
96 IEP_REGB_DST_FMT(iep_msg->base, 1);
97 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 0);
102 case IEP_FORMAT_BGR_565 :
103 IEP_REGB_DST_FMT(iep_msg->base, 1);
104 IEP_REGB_DST_RGB_SWAP(iep_msg->base, 1);
109 case IEP_FORMAT_YCbCr_422_SP :
110 IEP_REGB_DST_FMT(iep_msg->base, 2);
111 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 0);
115 case IEP_FORMAT_YCbCr_422_P :
116 IEP_REGB_DST_FMT(iep_msg->base, 2);
117 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 2);
121 case IEP_FORMAT_YCbCr_420_SP :
122 IEP_REGB_DST_FMT(iep_msg->base, 3);
123 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 0);
127 case IEP_FORMAT_YCbCr_420_P :
128 IEP_REGB_DST_FMT(iep_msg->base, 3);
129 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 2);
133 case IEP_FORMAT_YCrCb_422_SP :
134 IEP_REGB_DST_FMT(iep_msg->base, 2);
135 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 1);
139 case IEP_FORMAT_YCrCb_422_P :
140 IEP_REGB_DST_FMT(iep_msg->base, 2);
141 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 2);
145 case IEP_FORMAT_YCrCb_420_SP :
146 IEP_REGB_DST_FMT(iep_msg->base, 3);
147 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 1);
151 case IEP_FORMAT_YCrCb_420_P :
152 IEP_REGB_DST_FMT(iep_msg->base, 3);
153 IEP_REGB_DST_YUV_SWAP(iep_msg->base, 2);
160 #ifdef IEP_PRINT_INFO
161 IEP_DBG(" //==destination data format config============//\n\n");
162 IEP_DBG("sw_dst_yuv_swap = %d;//0:sp uv; 1:sp vu; 2:p ;"
165 IEP_DBG("sw_dst_rgb_swap = %d;//if ARGB 0:argb; "
166 "1,abgr; 2:rgba; 3:bgra; if rgb565: 0,2:rgb; 1,3:bgr;\n",
168 IEP_DBG("sw_dst_fmt = %d;//0:argb; 1:rgb565; 2:yuv422;"
169 " 3:yuv420;\n\n", dst_fmt);
173 static void iep_config_src_fmt(struct IEP_MSG *iep_msg)
175 unsigned int src_fmt = 0;
176 unsigned int src_rgb_swap = 0;
177 unsigned int src_yuv_swap = 0;
178 switch (iep_msg->src.format) {
179 case IEP_FORMAT_ARGB_8888 :
180 IEP_REGB_SRC_FMT(iep_msg->base, 0);
181 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 0);
185 case IEP_FORMAT_ABGR_8888 :
186 IEP_REGB_SRC_FMT(iep_msg->base, 0);
187 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 1);
191 case IEP_FORMAT_RGBA_8888 :
192 IEP_REGB_SRC_FMT(iep_msg->base, 0);
193 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 2);
197 case IEP_FORMAT_BGRA_8888 :
198 IEP_REGB_SRC_FMT(iep_msg->base, 0);
199 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 3);
203 case IEP_FORMAT_RGB_565 :
204 IEP_REGB_SRC_FMT(iep_msg->base, 1);
205 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 0);
209 case IEP_FORMAT_BGR_565 :
210 IEP_REGB_SRC_FMT(iep_msg->base, 1);
211 IEP_REGB_SRC_RGB_SWAP(iep_msg->base, 1);
215 case IEP_FORMAT_YCbCr_422_SP :
216 IEP_REGB_SRC_FMT(iep_msg->base, 2);
217 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 0);
221 case IEP_FORMAT_YCbCr_422_P :
222 IEP_REGB_SRC_FMT(iep_msg->base, 2);
223 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 2);
227 case IEP_FORMAT_YCbCr_420_SP :
228 IEP_REGB_SRC_FMT(iep_msg->base, 3);
229 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 0);
233 case IEP_FORMAT_YCbCr_420_P :
234 IEP_REGB_SRC_FMT(iep_msg->base, 3);
235 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 2);
239 case IEP_FORMAT_YCrCb_422_SP :
240 IEP_REGB_SRC_FMT(iep_msg->base, 2);
241 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 1);
245 case IEP_FORMAT_YCrCb_422_P :
246 IEP_REGB_SRC_FMT(iep_msg->base, 2);
247 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 2);
251 case IEP_FORMAT_YCrCb_420_SP :
252 IEP_REGB_SRC_FMT(iep_msg->base, 3);
253 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 1);
257 case IEP_FORMAT_YCrCb_420_P :
258 IEP_REGB_SRC_FMT(iep_msg->base, 3);
259 IEP_REGB_SRC_YUV_SWAP(iep_msg->base, 2);
266 #ifdef IEP_PRINT_INFO
267 IEP_DBG(" //==source data format config=================//\n\n");
268 IEP_DBG("sw_src_yuv_swap = %d;//0:sp uv; 1:sp vu;"
269 " 2:p ; 3:p;\n", src_yuv_swap);
270 IEP_DBG("sw_src_rgb_swap = %d;//if ARGB 0:argb; 1,abgr;"
271 " 2:rgba; 3:bgra; if rgb565: 0,2:rgb; 1,3:bgr;\n",
273 IEP_DBG("sw_src_fmt = %d;//0:argb; 1:rgb565;"
274 " 2:yuv422; 3:yuv420;\n\n", src_fmt);
278 static void iep_config_scl(struct IEP_MSG *iep_msg)
285 unsigned int src_height, src_width, dst_height, dst_width;
287 int div_height_dst_src;
288 int div_width_dst_src;
290 src_height = iep_msg->src.act_h - 1;
291 src_width = iep_msg->src.act_w - 1;
292 dst_height = iep_msg->dst.act_h - 1;
293 dst_width = iep_msg->dst.act_w - 1;
295 if ((iep_msg->src.act_w == iep_msg->dst.act_w) &&
296 (iep_msg->src.act_h == iep_msg->dst.act_h))
301 if ((iep_msg->src.act_w >= iep_msg->dst.act_w) &&
302 (iep_msg->src.act_h >= iep_msg->dst.act_h))
304 else if ((iep_msg->src.act_w >= iep_msg->dst.act_w) &&
305 (iep_msg->src.act_h <= iep_msg->dst.act_h))
307 else if ((iep_msg->src.act_w <= iep_msg->dst.act_w) &&
308 (iep_msg->src.act_h >= iep_msg->dst.act_h))
314 if ((scl_sel == 1) || (scl_sel == 3)) {
315 div_height_dst_src = src_height * 65536 / dst_height;
317 div_height_dst_src = (dst_height + 1) * 65536 /
319 if ((div_height_dst_src * (src_height + 1)) <
320 ((dst_height + 1) * 65536))
321 div_height_dst_src = div_height_dst_src + 1;
324 if (div_height_dst_src == 65536)
325 div_height_dst_src = 0;
328 if ((scl_sel == 2) || (scl_sel == 3)) {
329 div_width_dst_src = src_width * 65536 / dst_width;
331 div_width_dst_src = (dst_width + 1) * 65536 / (src_width + 1);
332 if ((div_width_dst_src * (src_width + 1)) <
333 ((dst_width + 1) * 65536))
334 div_width_dst_src = div_width_dst_src + 1;
337 if (div_width_dst_src == 65536)
338 div_width_dst_src = 0;
341 IEP_REGB_SCL_EN(iep_msg->base, scl_en);
344 IEP_REGB_SCL_SEL(iep_msg->base, scl_sel);
345 IEP_REGB_SCL_UP_COE_SEL(iep_msg->base, iep_msg->scale_up_mode);
346 IEP_REGB_SCL_VRT_FCT(iep_msg->base, div_height_dst_src);
347 IEP_REGB_SCL_HRZ_FCT(iep_msg->base, div_width_dst_src);
349 #ifdef IEP_PRINT_INFO
350 IEP_DBG(" //==scaling config============================//\n\n");
351 IEP_DBG("sw_scl_en = %d;//0:disable; 1:enable;\n",
353 IEP_DBG("sw_scl_sel = %d;//0:hrz down & vrt down;"
354 " 1:hrz down & vrt up; 2:hrz up & vrt down; 3:hrz up &"
355 " vrt up;\n", scl_sel);
356 IEP_DBG("sw_scl_up_coe_sel = %d;//select four groups of"
357 " up scaling coefficient\n", iep_msg->scale_up_mode);
358 IEP_DBG("sw_scl_vrt_fct = %d;//if up-scaling,equal"
359 " to floor(src_img_height/dst_image_height)*2^16;"
360 " if down-scaling,equal to ceiling(dst_image_height/"
361 "src_image_height)*2^16;\n", div_height_dst_src);
362 IEP_DBG("sw_scl_hrz_fct = %d;//if up-scaling,equal"
363 " to floor(src_img_widht/dst_image_width)*2^16; if"
364 " down-scaling,equal to ceiling(dst_image_width/"
365 "src_image_width)*2^16 ; \n\n", div_width_dst_src);
369 static void iep_config_cg_order(struct IEP_MSG *iep_msg)
371 IEP_REGB_CON_GAM_ORDER(iep_msg->base,
372 iep_msg->rgb_contrast_enhance_mode);
373 #ifdef IEP_PRINT_INFO
374 IEP_DBG(" //==rgb enhancement & denoise config==========//\n\n");
375 IEP_DBG("sw_con_gam_order = %d;//0:CG(contrast/gamma"
376 " operation)prior to DDE(de-noise/detail/edge enhance);"
377 " 1:DDE prior to CG;\n",
378 iep_msg->rgb_contrast_enhance_mode);
382 static void iep_config_cg(struct IEP_MSG *iep_msg)
385 unsigned int cg_conf_addr;
387 IEP_REGB_RGB_CON_GAM_EN(iep_msg->base, iep_msg->rgb_cg_en);
389 if (iep_msg->rgb_cg_en) {
390 cg_conf_addr = rIEP_CG_TAB_ADDR;
392 for (i = 0; i < 192; i++) {
393 WriteReg32(iep_msg->base, cg_conf_addr,
395 cg_conf_addr += 0x04;
399 #ifdef IEP_PRINT_INFO
400 IEP_DBG("sw_rgb_con_gam_en = 0;//0:contrast"
401 " & gamma disable; 1:enable;\n",
406 static void iep_config_dde(struct IEP_MSG *iep_msg)
408 IEP_REGB_RGB_ENH_SEL(iep_msg->base, iep_msg->rgb_enhance_mode);
409 IEP_REGB_ENH_THRESHOLD(iep_msg->base, iep_msg->enh_threshold);
410 IEP_REGB_ENH_ALPHA(iep_msg->base, iep_msg->enh_alpha);
411 IEP_REGB_ENH_RADIUS(iep_msg->base, iep_msg->enh_radius);
412 #ifdef IEP_PRINT_INFO
413 IEP_DBG("sw_rgb_enh_sel = %d;//0:no operation;"
414 " 1:de-noise; 2:detail enhance; 3:edge enhance;\n",
415 iep_msg->rgb_enhance_mode);
420 static void iep_config_color_enh(struct IEP_MSG *iep_msg)
422 IEP_REGB_RGB_COLOR_ENH_EN(iep_msg->base, iep_msg->rgb_color_enhance_en);
423 IEP_REGB_ENH_C_COE(iep_msg->base, iep_msg->rgb_enh_coe);
424 #ifdef IEP_PRINT_INFO
425 IEP_DBG("sw_rgb_color_enh_en = %d;//0:color enhance disable;"
427 iep_msg->rgb_color_enhance_en);
431 static void iep_config_yuv_dns(struct IEP_MSG *iep_msg)
433 IEP_REGB_YUV_DNS_EN(iep_msg->base, iep_msg->yuv_3D_denoise_en);
434 IEP_REGB_YUV_DNS_LUMA_SPAT_SEL(iep_msg->base, 0);
435 IEP_REGB_YUV_DNS_LUMA_TEMP_SEL(iep_msg->base, 1);
436 IEP_REGB_YUV_DNS_CHROMA_SPAT_SEL(iep_msg->base, 2);
437 IEP_REGB_YUV_DNS_CHROMA_TEMP_SEL(iep_msg->base, 3);
438 #ifdef IEP_PRINT_INFO
439 IEP_DBG("//==yuv denoise config========================// \n\n");
440 IEP_DBG("sw_yuv_dns_en = %d;//0:yuv 3d denoise disable;"
441 " 1:enable\n\n", iep_msg->yuv_3D_denoise_en);
446 static void iep_config_dil(struct IEP_MSG *iep_msg)
449 switch (iep_msg->dein_mode) {
450 case IEP_DEINTERLACE_MODE_DISABLE:
451 dein_mode = dein_mode_bypass_dis;
453 case IEP_DEINTERLACE_MODE_I2O1:
454 dein_mode = iep_msg->field_order == FIELD_ORDER_TOP_FIRST ? dein_mode_I2O1T : dein_mode_I2O1B;
456 case IEP_DEINTERLACE_MODE_I4O1:
458 dein_mode = iep_msg->field_order == FIELD_ORDER_TOP_FIRST ? dein_mode_I4O1B : dein_mode_I4O1T;
460 dein_mode = iep_msg->field_order == FIELD_ORDER_TOP_FIRST ? dein_mode_I4O1T : dein_mode_I4O1B;
463 case IEP_DEINTERLACE_MODE_I4O2:
464 dein_mode = dein_mode_I4O2;
466 case IEP_DEINTERLACE_MODE_BYPASS:
467 dein_mode = dein_mode_bypass;
470 IEP_ERR("unknown deinterlace mode, set deinterlace mode (bypass)\n");
471 dein_mode = dein_mode_bypass;
474 IEP_REGB_DIL_MODE(iep_msg->base, dein_mode);
476 IEP_REGB_DIL_HF_EN(iep_msg->base, iep_msg->dein_high_fre_en);
477 if (iep_msg->dein_high_fre_en == 1) IEP_REGB_DIL_HF_FCT(iep_msg->base, iep_msg->dein_high_fre_fct);
479 IEP_REGB_DIL_EI_MODE(iep_msg->base, iep_msg->dein_ei_mode);
480 IEP_REGB_DIL_EI_SMOOTH(iep_msg->base, iep_msg->dein_ei_smooth);
481 IEP_REGB_DIL_EI_SEL(iep_msg->base, iep_msg->dein_ei_sel);
482 if (iep_msg->dein_ei_sel == 0) IEP_REGB_DIL_EI_RADIUS(iep_msg->base, iep_msg->dein_ei_radius);
483 IEP_REGB_DIL_MTN_TAB0(iep_msg->base, 0x40404040);
484 IEP_REGB_DIL_MTN_TAB1(iep_msg->base, 0x3c3e3f3f);
485 IEP_REGB_DIL_MTN_TAB2(iep_msg->base, 0x3336393b);
486 IEP_REGB_DIL_MTN_TAB3(iep_msg->base, 0x272a2d31);
487 IEP_REGB_DIL_MTN_TAB4(iep_msg->base, 0x181c2023);
488 IEP_REGB_DIL_MTN_TAB5(iep_msg->base, 0x0c0e1215);
489 IEP_REGB_DIL_MTN_TAB6(iep_msg->base, 0x03040609);
490 IEP_REGB_DIL_MTN_TAB7(iep_msg->base, 0x00000001);
493 static void iep_config_yuv_enh(struct IEP_MSG *iep_msg)
495 IEP_REGB_YUV_ENH_EN(iep_msg->base, iep_msg->yuv_enhance_en);
496 if (iep_msg->yuv_enhance_en == 1) {
497 IEP_REGB_VIDEO_MODE(iep_msg->base, iep_msg->video_mode);
498 if (iep_msg->video_mode == normal_mode) {
499 IEP_REGB_SAT_CON(iep_msg->base, iep_msg->sat_con_int);
500 IEP_REGB_CONTRAST(iep_msg->base,
501 iep_msg->contrast_int);
502 IEP_REGB_BRIGHTNESS(iep_msg->base,
503 iep_msg->yuv_enh_brightness);
504 IEP_REGB_COS_HUE(iep_msg->base, iep_msg->cos_hue_int);
505 IEP_REGB_SIN_HUE(iep_msg->base, iep_msg->sin_hue_int);
506 } else if (iep_msg->video_mode == color_bar) { //color bar
507 IEP_REGB_COLOR_BAR_Y(iep_msg->base,
508 iep_msg->color_bar_y);
509 IEP_REGB_COLOR_BAR_U(iep_msg->base,
510 iep_msg->color_bar_u);
511 IEP_REGB_COLOR_BAR_V(iep_msg->base,
512 iep_msg->color_bar_v);
518 static void iep_config_rgb2yuv(struct IEP_MSG *iep_msg)
520 unsigned char cond1, cond2;
521 unsigned int rgb2yuv_en = 0;
524 cond1 = ((iep_msg->src.format <= 5) && (iep_msg->dst.format > 5)) ?
527 //rgb process,yuv out
528 cond2 = (((iep_msg->rgb_color_enhance_en == 1) ||
529 (iep_msg->rgb_cg_en == 1) ||
530 (iep_msg->rgb_enhance_mode != rgb_enhance_bypass)) &&
531 (iep_msg->dst.format > 5)) ? 1 : 0;
534 if ((cond1 == 1) || (cond2 == 1)) {
535 IEP_REGB_RGB_TO_YUV_EN(iep_msg->base, 1);
537 IEP_REGB_RGB2YUV_COE_SEL(iep_msg->base, iep_msg->rgb2yuv_mode);
538 IEP_REGB_RGB2YUV_INPUT_CLIP(iep_msg->base,
539 iep_msg->rgb2yuv_clip_en);
541 IEP_REGB_RGB_TO_YUV_EN(iep_msg->base, 0);
542 #ifdef IEP_PRINT_INFO
543 IEP_DBG("//==color space conversion config============//\n\n");
544 IEP_DBG("sw_rgb_to_yuv_en = %d;\n", rgb2yuv_en);
545 IEP_DBG("sw_rgb2yuv_coe_sel = %d;\n", iep_msg->rgb2yuv_mode);
546 IEP_DBG("sw_rgb2yuv_input_clip = %d;\n\n", iep_msg->rgb2yuv_clip_en);
551 static void iep_config_yuv2rgb(struct IEP_MSG *iep_msg)
553 unsigned char cond1, cond2;
554 unsigned int yuv2rgb_en = 0;
557 cond1 = ((iep_msg->src.format > 5) &&
558 (iep_msg->dst.format <= 5)) ? 1 : 0;
561 cond2 = (((iep_msg->rgb_color_enhance_en == 1) ||
562 (iep_msg->rgb_cg_en == 1) ||
563 (iep_msg->rgb_enhance_mode != rgb_enhance_bypass)) &&
564 (iep_msg->src.format > 5)) ? 1 : 0;
566 if ((cond1 == 1) || (cond2 == 1)) {
567 IEP_REGB_YUV_TO_RGB_EN(iep_msg->base, 1);
569 IEP_REGB_YUV2RGB_COE_SEL(iep_msg->base,
570 iep_msg->yuv2rgb_mode);
571 IEP_REGB_YUV2RGB_INPUT_CLIP(iep_msg->base,
572 iep_msg->yuv2rgb_clip_en);
574 IEP_REGB_YUV_TO_RGB_EN(iep_msg->base, 0);
576 #ifdef IEP_PRINT_INFO
577 IEP_DBG("sw_yuv_to_rgb_en = %d;\n", yuv2rgb_en);
578 IEP_DBG("sw_yuv2rgb_coe_sel = %d;\n", iep_msg->yuv2rgb_mode);
579 IEP_DBG("sw_yuv2rgb_input_clip = %d;\n\n", iep_msg->yuv2rgb_clip_en);
583 static void iep_config_dither_up(struct IEP_MSG *iep_msg)
585 unsigned int dither_up = 0;
586 if ((iep_msg->src.format == IEP_FORMAT_RGB_565) ||
587 (iep_msg->src.format == IEP_FORMAT_BGR_565)) {
588 IEP_REGB_DITHER_UP_EN(iep_msg->base, iep_msg->dither_up_en);
589 dither_up = iep_msg->dither_up_en;
591 IEP_REGB_DITHER_UP_EN(iep_msg->base, 0);
593 #ifdef IEP_PRINT_INFO
594 IEP_DBG("//==dither config=============================//\n\n");
595 IEP_DBG("sw_dither_up_en = %d;\n", dither_up);
599 static void iep_config_dither_down(struct IEP_MSG *iep_msg)
601 unsigned int dither_down = 0;
602 if ((iep_msg->dst.format == IEP_FORMAT_RGB_565) ||
603 (iep_msg->dst.format == IEP_FORMAT_BGR_565)) {
604 IEP_REGB_DITHER_DOWN_EN(iep_msg->base, 1);
607 IEP_REGB_DITHER_DOWN_EN(iep_msg->base, 0);
609 #ifdef IEP_PRINT_INFO
610 IEP_DBG("sw_dither_down_en = %d;\n\n", dither_down);
614 static void iep_config_glb_alpha(struct IEP_MSG *iep_msg)
616 IEP_REGB_GLB_ALPHA(iep_msg->base, iep_msg->global_alpha_value);
617 #ifdef IEP_PRINT_INFO
618 IEP_DBG("//==global alpha for ARGB config=============//\n\n");
619 IEP_DBG("sw_glb_alpha = %d;//global alpha value for output ARGB\n\n",
620 iep_msg->global_alpha_value);
624 static void iep_config_vir_line(struct IEP_MSG *iep_msg)
626 unsigned int src_vir_w;
627 unsigned int dst_vir_w;
629 switch (iep_msg->src.format) {
630 case IEP_FORMAT_ARGB_8888 :
631 src_vir_w = iep_msg->src.vir_w;
633 case IEP_FORMAT_ABGR_8888 :
634 src_vir_w = iep_msg->src.vir_w;
636 case IEP_FORMAT_RGBA_8888 :
637 src_vir_w = iep_msg->src.vir_w;
639 case IEP_FORMAT_BGRA_8888 :
640 src_vir_w = iep_msg->src.vir_w;
642 case IEP_FORMAT_RGB_565 :
643 if (iep_msg->src.vir_w % 2 == 1)
644 src_vir_w = (iep_msg->src.vir_w + 1) / 2;
646 src_vir_w = iep_msg->src.vir_w / 2;
648 case IEP_FORMAT_BGR_565 :
649 if (iep_msg->src.vir_w % 2 == 1)
650 src_vir_w = iep_msg->src.vir_w / 2 + 1;
652 src_vir_w = iep_msg->src.vir_w / 2;
654 case IEP_FORMAT_YCbCr_422_SP :
655 if (iep_msg->src.vir_w % 4 != 0)
656 src_vir_w = iep_msg->src.vir_w / 4 + 1;
658 src_vir_w = iep_msg->src.vir_w / 4;
660 case IEP_FORMAT_YCbCr_422_P :
661 if (iep_msg->src.vir_w % 4 != 0)
662 src_vir_w = iep_msg->src.vir_w / 4 + 1;
664 src_vir_w = iep_msg->src.vir_w / 4;
666 case IEP_FORMAT_YCbCr_420_SP :
667 if (iep_msg->src.vir_w % 4 != 0)
668 src_vir_w = iep_msg->src.vir_w / 4 + 1;
670 src_vir_w = iep_msg->src.vir_w / 4;
672 case IEP_FORMAT_YCbCr_420_P :
673 if (iep_msg->src.vir_w % 4 != 0)
674 src_vir_w = iep_msg->src.vir_w / 4 + 1;
676 src_vir_w = iep_msg->src.vir_w / 4;
678 case IEP_FORMAT_YCrCb_422_SP :
679 if (iep_msg->src.vir_w % 4 != 0)
680 src_vir_w = iep_msg->src.vir_w / 4 + 1;
682 src_vir_w = iep_msg->src.vir_w / 4;
684 case IEP_FORMAT_YCrCb_422_P :
685 if (iep_msg->src.vir_w % 4 != 0)
686 src_vir_w = iep_msg->src.vir_w / 4 + 1;
688 src_vir_w = iep_msg->src.vir_w / 4;
690 case IEP_FORMAT_YCrCb_420_SP :
691 if (iep_msg->src.vir_w % 4 != 0)
692 src_vir_w = iep_msg->src.vir_w / 4 + 1;
694 src_vir_w = iep_msg->src.vir_w / 4;
696 case IEP_FORMAT_YCrCb_420_P :
697 if (iep_msg->src.vir_w % 4 != 0)
698 src_vir_w = iep_msg->src.vir_w / 4 + 1;
700 src_vir_w = iep_msg->src.vir_w / 4;
703 IEP_ERR("Unkown format,"
704 "set the source image virtual width 0\n");
709 switch (iep_msg->dst.format) {
710 case IEP_FORMAT_ARGB_8888 :
711 dst_vir_w = iep_msg->dst.vir_w;
713 case IEP_FORMAT_ABGR_8888 :
714 dst_vir_w = iep_msg->dst.vir_w;
716 case IEP_FORMAT_RGBA_8888 :
717 dst_vir_w = iep_msg->dst.vir_w;
719 case IEP_FORMAT_BGRA_8888 :
720 dst_vir_w = iep_msg->dst.vir_w;
722 case IEP_FORMAT_RGB_565 :
723 if (iep_msg->dst.vir_w % 2 == 1)
724 dst_vir_w = (iep_msg->dst.vir_w + 1) / 2;
726 dst_vir_w = iep_msg->dst.vir_w / 2;
728 case IEP_FORMAT_BGR_565 :
729 if (iep_msg->dst.vir_w % 2 == 1)
730 dst_vir_w = iep_msg->dst.vir_w / 2 + 1;
732 dst_vir_w = iep_msg->dst.vir_w / 2;
734 case IEP_FORMAT_YCbCr_422_SP :
735 if (iep_msg->dst.vir_w % 4 != 0)
736 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
738 dst_vir_w = iep_msg->dst.vir_w / 4;
740 case IEP_FORMAT_YCbCr_422_P :
741 if (iep_msg->dst.vir_w % 4 != 0)
742 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
744 dst_vir_w = iep_msg->dst.vir_w / 4;
746 case IEP_FORMAT_YCbCr_420_SP :
747 if (iep_msg->dst.vir_w % 4 != 0)
748 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
750 dst_vir_w = iep_msg->dst.vir_w / 4;
752 case IEP_FORMAT_YCbCr_420_P :
753 if (iep_msg->dst.vir_w % 4 != 0)
754 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
756 dst_vir_w = iep_msg->dst.vir_w / 4;
758 case IEP_FORMAT_YCrCb_422_SP :
759 if (iep_msg->dst.vir_w % 4 != 0)
760 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
762 dst_vir_w = iep_msg->dst.vir_w / 4;
764 case IEP_FORMAT_YCrCb_422_P :
765 if (iep_msg->dst.vir_w % 4 != 0)
766 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
768 dst_vir_w = iep_msg->dst.vir_w / 4;
770 case IEP_FORMAT_YCrCb_420_SP :
771 if (iep_msg->dst.vir_w % 4 != 0)
772 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
774 dst_vir_w = iep_msg->dst.vir_w / 4;
776 case IEP_FORMAT_YCrCb_420_P :
777 if (iep_msg->dst.vir_w % 4 != 0)
778 dst_vir_w = iep_msg->dst.vir_w / 4 + 1;
780 dst_vir_w = iep_msg->dst.vir_w / 4;
783 IEP_ERR("Unkown format, set the destination"
784 " image virtual width 0\n");
788 IEP_REGB_DST_VIR_LINE_WIDTH(iep_msg->base, dst_vir_w);
789 IEP_REGB_SRC_VIR_LINE_WIDTH(iep_msg->base, src_vir_w);
792 static void iep_config_src_addr(struct IEP_MSG *iep_msg)
800 u32 src_addr_y_itemp;
801 u32 src_addr_cbcr_itemp;
802 u32 src_addr_cr_itemp;
803 u32 src_addr_y_ftemp;
804 u32 src_addr_cbcr_ftemp;
805 u32 src_addr_cr_ftemp;
806 unsigned int offset_addr_y = 0;
807 unsigned int offset_addr_uv = 0;
808 unsigned int offset_addr_v = 0;
809 //unsigned int offset_addr_y_w = 0;
810 unsigned int offset_addr_uv_w = 0;
811 unsigned int offset_addr_v_w = 0;
812 //unsigned int offset_addr_y_h = 0;
813 unsigned int offset_addr_uv_h = 0;
814 unsigned int offset_addr_v_h = 0;
816 unsigned int offset_x_equ_uv;
817 unsigned int offset_x_u_byte;
818 unsigned int offset_x_v_byte;
819 unsigned int vir_w_euq_uv;
820 unsigned int line_u_byte;
821 unsigned int line_v_byte;
822 unsigned int offset_y_equ_420_uv = 0;
824 //**********************************************//
825 //***********y addr offset**********************//
826 //**********************************************//
827 if (iep_msg->src.format <= 3) {
828 offset_addr_y = iep_msg->src.y_off * 4 *
829 iep_msg->src.vir_w + iep_msg->src.x_off * 4;
830 } else if (iep_msg->src.format <= 5) {
831 offset_addr_y = iep_msg->src.y_off * 2 *
832 iep_msg->src.vir_w + iep_msg->src.x_off * 2;
834 offset_addr_y = iep_msg->src.y_off *
835 iep_msg->src.vir_w + iep_msg->src.x_off;
838 //**********************************************//
839 //***********uv addr offset*********************//
840 //**********************************************//
841 // note: image size align to even when image format is yuv
843 //----------offset_w--------//
844 if (iep_msg->src.x_off % 2 == 1)
845 offset_x_equ_uv = iep_msg->src.x_off + 1;
847 offset_x_equ_uv = iep_msg->src.x_off;
849 offset_x_u_byte = offset_x_equ_uv / 2;
850 offset_x_v_byte = offset_x_equ_uv / 2;
852 if ((iep_msg->src.format == IEP_FORMAT_YCbCr_422_SP) ||
853 (iep_msg->src.format == IEP_FORMAT_YCbCr_420_SP)
854 || (iep_msg->src.format == IEP_FORMAT_YCrCb_422_SP) ||
855 (iep_msg->src.format == IEP_FORMAT_YCrCb_420_SP))
856 offset_addr_uv_w = offset_x_u_byte + offset_x_v_byte;
858 offset_addr_uv_w = offset_x_u_byte;
859 offset_addr_v_w = offset_x_v_byte;
862 //----------offset_h--------//
863 if (iep_msg->src.vir_w % 2 == 1)
864 vir_w_euq_uv = iep_msg->src.vir_w + 1;
866 vir_w_euq_uv = iep_msg->src.vir_w;
868 line_u_byte = vir_w_euq_uv / 2;
869 line_v_byte = vir_w_euq_uv / 2;
871 if (iep_msg->src.y_off % 2 == 1)
872 offset_y_equ_420_uv = iep_msg->src.y_off + 1;
874 offset_y_equ_420_uv = iep_msg->src.y_off;
876 switch (iep_msg->src.format) {
877 case IEP_FORMAT_YCbCr_422_SP :
878 offset_addr_uv_h = (line_u_byte + line_v_byte) *
881 case IEP_FORMAT_YCbCr_422_P :
882 offset_addr_uv_h = line_u_byte * iep_msg->src.y_off;
883 offset_addr_v_h = line_v_byte * iep_msg->src.y_off;
885 case IEP_FORMAT_YCbCr_420_SP :
886 offset_addr_uv_h = (line_u_byte + line_v_byte) *
887 offset_y_equ_420_uv / 2;
889 case IEP_FORMAT_YCbCr_420_P :
890 offset_addr_uv_h = line_u_byte * offset_y_equ_420_uv / 2;
891 offset_addr_v_h = line_v_byte * offset_y_equ_420_uv / 2;
893 case IEP_FORMAT_YCrCb_422_SP :
894 offset_addr_uv_h = (line_u_byte + line_v_byte) *
897 case IEP_FORMAT_YCrCb_422_P :
898 offset_addr_uv_h = line_u_byte * iep_msg->src.y_off;
899 offset_addr_v_h = line_v_byte * iep_msg->src.y_off;
901 case IEP_FORMAT_YCrCb_420_SP :
902 offset_addr_uv_h = (line_u_byte + line_v_byte) *
903 offset_y_equ_420_uv / 2;
905 case IEP_FORMAT_YCrCb_420_P :
906 offset_addr_uv_h = line_u_byte * offset_y_equ_420_uv / 2;
907 offset_addr_v_h = line_v_byte * offset_y_equ_420_uv / 2;
912 //----------offset u/v addr--------//
914 offset_addr_uv = offset_addr_uv_w + offset_addr_uv_h;
915 offset_addr_v = offset_addr_v_w + offset_addr_v_h;
916 //**********************************************//
917 //***********yuv address *********************//
918 //**********************************************//
919 src_addr_yrgb = ((u32)iep_msg->src.mem_addr) + offset_addr_y;
920 src_addr_cbcr = ((u32)iep_msg->src.uv_addr) + offset_addr_uv;
921 src_addr_cr = ((u32)iep_msg->src.v_addr) + offset_addr_v;
923 // former frame when processing deinterlace
924 src_addr_y1 = ((u32)iep_msg->src1.mem_addr) + offset_addr_y;
925 src_addr_cbcr1 = ((u32)iep_msg->src1.uv_addr) + offset_addr_uv;
926 src_addr_cr1 = ((u32)iep_msg->src1.v_addr) + offset_addr_v;
928 src_addr_y_itemp = ((u32)iep_msg->src_itemp.mem_addr) +
930 src_addr_cbcr_itemp = ((u32)iep_msg->src_itemp.uv_addr) +
932 src_addr_cr_itemp = ((u32)iep_msg->src_itemp.v_addr) +
935 src_addr_y_ftemp = ((u32)iep_msg->src_ftemp.mem_addr) +
937 src_addr_cbcr_ftemp = ((u32)iep_msg->src_ftemp.uv_addr) +
939 src_addr_cr_ftemp = ((u32)iep_msg->src_ftemp.v_addr) +
942 if ((iep_msg->dein_mode == IEP_DEINTERLACE_MODE_I4O1 ||
943 iep_msg->dein_mode == IEP_DEINTERLACE_MODE_I4O2) &&
945 iep_msg->field_order == FIELD_ORDER_BOTTOM_FIRST
947 iep_msg->field_order == FIELD_ORDER_TOP_FIRST
950 IEP_REGB_SRC_ADDR_YRGB(iep_msg->base, src_addr_y1);
951 IEP_REGB_SRC_ADDR_CBCR(iep_msg->base, src_addr_cbcr1);
952 IEP_REGB_SRC_ADDR_CR(iep_msg->base, src_addr_cr1);
953 IEP_REGB_SRC_ADDR_Y1(iep_msg->base, src_addr_yrgb);
954 IEP_REGB_SRC_ADDR_CBCR1(iep_msg->base, src_addr_cbcr);
955 IEP_REGB_SRC_ADDR_CR1(iep_msg->base, src_addr_cr);
957 IEP_REGB_SRC_ADDR_YRGB(iep_msg->base, src_addr_yrgb);
958 IEP_REGB_SRC_ADDR_CBCR(iep_msg->base, src_addr_cbcr);
959 IEP_REGB_SRC_ADDR_CR(iep_msg->base, src_addr_cr);
960 IEP_REGB_SRC_ADDR_Y1(iep_msg->base, src_addr_y1);
961 IEP_REGB_SRC_ADDR_CBCR1(iep_msg->base, src_addr_cbcr1);
962 IEP_REGB_SRC_ADDR_CR1(iep_msg->base, src_addr_cr1);
965 if (iep_msg->yuv_3D_denoise_en) {
966 IEP_REGB_SRC_ADDR_Y_ITEMP(iep_msg->base,
968 IEP_REGB_SRC_ADDR_CBCR_ITEMP(iep_msg->base,
969 src_addr_cbcr_itemp);
970 IEP_REGB_SRC_ADDR_Y_FTEMP(iep_msg->base,
972 IEP_REGB_SRC_ADDR_CBCR_FTEMP(iep_msg->base,
973 src_addr_cbcr_ftemp);
974 if ((iep_msg->src.format == IEP_FORMAT_YCbCr_422_P) ||
975 (iep_msg->src.format == IEP_FORMAT_YCbCr_420_P)
976 || (iep_msg->src.format == IEP_FORMAT_YCrCb_422_P) ||
977 (iep_msg->src.format == IEP_FORMAT_YCrCb_420_P)) {
978 IEP_REGB_SRC_ADDR_CR_ITEMP(iep_msg->base,
980 IEP_REGB_SRC_ADDR_CR_FTEMP(iep_msg->base,
984 #ifdef IEP_PRINT_INFO
985 IEP_DBG("//-------source address for image-------// \n\n");
986 IEP_DBG("sw_src_addr_yrgb = 32'h%x;\n", src_addr_yrgb);
987 IEP_DBG("sw_src_addr_cbcr = 32'h%x;\n", src_addr_cbcr);
988 IEP_DBG("sw_src_addr_cr = 32'h%x;\n", src_addr_cr);
989 IEP_DBG("sw_src_addr_y1 = 32'h%x;\n", src_addr_y1);
990 IEP_DBG("sw_src_addr_cbcr0 = 32'h%x;\n", src_addr_cbcr1);
991 IEP_DBG("sw_src_addr_cr0 = 32'h%x;\n", src_addr_cr1);
992 IEP_DBG("sw_src_addr_y_itemp = 32'h%x;\n", src_addr_y_itemp);
993 IEP_DBG("sw_src_addr_cbcr_itemp = 32'h%x;\n", src_addr_cbcr_itemp);
994 IEP_DBG("sw_src_addr_cr_itemp = 32'h%x;\n", src_addr_cr_itemp);
995 IEP_DBG("sw_src_addr_y_ftemp = 32'h%x;\n", src_addr_y_ftemp);
996 IEP_DBG("sw_src_addr_cbcr_ftemp = 32'h%x;\n", src_addr_cbcr_ftemp);
997 IEP_DBG("sw_src_addr_cr_ftemp = 32'h%x;\n\n", src_addr_cr_ftemp);
1001 static void iep_config_dst_addr(struct IEP_MSG *iep_msg)
1003 IEP_REGB_DST_ADDR_YRGB(iep_msg->base, (u32)iep_msg->dst.mem_addr);
1004 IEP_REGB_DST_ADDR_CBCR(iep_msg->base, (u32)iep_msg->dst.uv_addr);
1005 IEP_REGB_DST_ADDR_Y1(iep_msg->base, (u32)iep_msg->dst1.mem_addr);
1006 IEP_REGB_DST_ADDR_CBCR1(iep_msg->base, (u32)iep_msg->dst1.uv_addr);
1007 IEP_REGB_DST_ADDR_CR(iep_msg->base, (u32)iep_msg->dst.v_addr);
1008 IEP_REGB_DST_ADDR_CR1(iep_msg->base, (u32)iep_msg->dst1.v_addr);
1010 if (iep_msg->yuv_3D_denoise_en) {
1011 IEP_REGB_DST_ADDR_Y_ITEMP(iep_msg->base,
1012 (u32)iep_msg->dst_itemp.mem_addr);
1013 IEP_REGB_DST_ADDR_CBCR_ITEMP(iep_msg->base,
1014 (u32)iep_msg->dst_itemp.uv_addr);
1015 IEP_REGB_DST_ADDR_Y_FTEMP(iep_msg->base,
1016 (u32)iep_msg->dst_ftemp.mem_addr);
1017 IEP_REGB_DST_ADDR_CBCR_FTEMP(iep_msg->base,
1018 (u32)iep_msg->dst_ftemp.uv_addr);
1019 if ((iep_msg->dst.format == IEP_FORMAT_YCbCr_422_P) ||
1020 (iep_msg->dst.format == IEP_FORMAT_YCbCr_420_P) ||
1021 (iep_msg->dst.format == IEP_FORMAT_YCrCb_422_P) ||
1022 (iep_msg->dst.format == IEP_FORMAT_YCrCb_420_P)) {
1023 IEP_REGB_DST_ADDR_CR_ITEMP(iep_msg->base,
1024 (u32)iep_msg->dst_itemp.v_addr);
1025 IEP_REGB_DST_ADDR_CR_FTEMP(iep_msg->base,
1026 (u32)iep_msg->dst_ftemp.v_addr);
1029 #ifdef IEP_PRINT_INFO
1030 IEP_DBG("//-------destination address for image-------// \n\n");
1031 IEP_DBG("sw_dst_addr_yrgb = 32'h%x;\n",
1032 (u32)iep_msg->dst.mem_addr);
1033 IEP_DBG("sw_dst_addr_cbcr = 32'h%x;\n",
1034 (u32)iep_msg->dst.uv_addr);
1035 IEP_DBG("sw_dst_addr_cr = 32'h%x;\n",
1036 (u32)iep_msg->dst.v_addr);
1037 IEP_DBG("sw_dst_addr_y1 = 32'h%x;\n",
1038 (u32)iep_msg->dst1.mem_addr);
1039 IEP_DBG("sw_dst_addr_cbcr0 = 32'h%x;\n",
1040 (u32)iep_msg->dst1.uv_addr);
1041 IEP_DBG("sw_dst_addr_cr0 = 32'h%x;\n",
1042 (u32)iep_msg->dst1.v_addr);
1043 IEP_DBG("sw_dst_addr_y_itemp = 32'h%x;\n",
1044 (u32)iep_msg->dst_itemp.mem_addr);
1045 IEP_DBG("sw_dst_addr_cbcr_itemp = 32'h%x;\n",
1046 (u32)iep_msg->dst_itemp.uv_addr);
1047 IEP_DBG("sw_dst_addr_cr_itemp = 32'h%x;\n",
1048 (u32)iep_msg->dst_itemp.v_addr);
1049 IEP_DBG("sw_dst_addr_y_ftemp = 32'h%x;\n",
1050 (u32)iep_msg->dst_ftemp.mem_addr);
1051 IEP_DBG("sw_dst_addr_cbcr_ftemp = 32'h%x;\n",
1052 (u32)iep_msg->dst_ftemp.uv_addr);
1053 IEP_DBG("sw_dst_addr_cr_ftemp = 32'h%x;\n\n",
1054 (u32)iep_msg->dst_ftemp.v_addr);
1058 void iep_config_lcdc_path(struct IEP_MSG *iep_msg)
1060 IEP_REGB_LCDC_PATH_EN(iep_msg->base, iep_msg->lcdc_path_en);
1062 #ifdef IEP_PRINT_INFO
1063 IEP_DBG("//==write back or lcdc direct path config=====// \n\n");
1064 IEP_DBG("sw_lcdc_path_en = %d;//lcdc direct path enable,c"
1065 " model don't care this value\n\n", iep_msg->lcdc_path_en);
1069 int iep_probe_int(void *base)
1071 return ReadReg32(base, rIEP_INT) & 1;
1074 void iep_config_frame_end_int_clr(void *base)
1076 IEP_REGB_FRAME_END_INT_CLR(base, 1);
1079 void iep_config_frame_end_int_en(void *base)
1081 IEP_REGB_FRAME_END_INT_CLR(base, 1);
1082 IEP_REGB_FRAME_END_INT_EN(base, 1);
1085 #if defined(CONFIG_IEP_MMU)
1086 struct iep_mmu_int_status iep_probe_mmu_int_status(void *base)
1088 uint32_t mmu_int_sts = IEP_REGB_MMU_INT_STATUS(base);
1089 struct iep_mmu_int_status sts;
1091 memcpy(&sts, &mmu_int_sts, 4);
1096 void iep_config_mmu_page_fault_int_en(void *base, bool en)
1098 IEP_REGB_MMU_INT_MASK_PAGE_FAULT_INT_EN(base, en);
1101 void iep_config_mmu_page_fault_int_clr(void *base)
1103 IEP_REGB_MMU_INT_CLEAR_PAGE_FAULT_CLEAR(base, 1);
1106 void iep_config_mmu_read_bus_error_int_clr(void *base)
1108 IEP_REGB_MMU_INT_CLEAR_READ_BUS_ERROR_CLEAR(base, 1);
1111 uint32_t iep_probe_mmu_page_fault_addr(void *base)
1113 return IEP_REGB_MMU_PAGE_FAULT_ADDR(base);
1116 void iep_config_mmu_cmd(void *base, enum iep_mmu_cmd cmd)
1118 IEP_REGB_MMU_CMD(base, cmd);
1121 void iep_config_mmu_dte_addr(void *base, uint32_t addr)
1123 IEP_REGB_MMU_DTE_ADDR(base, addr);
1127 void iep_config_misc(struct IEP_MSG *iep_msg)
1129 // IEP_REGB_V_REVERSE_DISP();
1130 // IEP_REGB_H_REVERSE_DISP();
1131 #ifdef IEP_PRINT_INFO
1132 IEP_DBG("//==misc config==========================//\n\n");
1133 IEP_DBG("sw_v_reverse_disp = 0;\n");
1134 IEP_DBG("sw_u_reverse_disp = 0;\n\n");
1138 #define IEP_RESET_TIMEOUT 1000
1139 void iep_soft_rst(void *base)
1141 unsigned int rst_state = 0;
1143 WriteReg32(base, rIEP_SOFT_RST, 2);
1144 WriteReg32(base, rIEP_SOFT_RST, 1);
1145 while (i++ < IEP_RESET_TIMEOUT) {
1146 rst_state = ReadReg32(base, IEP_STATUS);
1147 if ((rst_state & 0x200) == 0x200) {
1153 WriteReg32(base, IEP_SOFT_RST, 2);
1155 if (i == IEP_RESET_TIMEOUT)
1156 IEP_DBG("soft reset timeout.\n");
1159 void iep_config_done(void *base)
1161 WriteReg32(base, rIEP_CONF_DONE, 1);
1164 void iep_config_frm_start(void *base)
1166 IEP_REGB_FRM_START(base, 1);
1169 struct iep_status iep_get_status(void *base)
1171 uint32_t sts_int = IEP_REGB_STATUS(base);
1172 struct iep_status sts;
1174 memcpy(&sts, &sts_int, 4);
1179 int iep_get_deinterlace_mode(void *base)
1181 int cfg = ReadReg32(base, IEP_CONFIG0);
1182 return (cfg >> 8) & 0x7;
1185 void iep_set_deinterlace_mode(int mode, void *base)
1189 if (mode > dein_mode_bypass) {
1190 IEP_ERR("invalid deinterlace mode\n");
1194 cfg = ReadReg32(base, RAW_IEP_CONFIG0);
1195 cfg = (cfg & (~(7 << 8))) | (mode << 8);
1196 WriteReg32(base, IEP_CONFIG0, cfg);
1198 //IEP_REGB_DIL_MODE(base, mode);
1201 void iep_switch_input_address(void *base)
1203 u32 src_addr_yrgb = ReadReg32(base, IEP_SRC_ADDR_YRGB);
1204 u32 src_addr_cbcr = ReadReg32(base, IEP_SRC_ADDR_CBCR);
1205 u32 src_addr_cr = ReadReg32(base, IEP_SRC_ADDR_CR);
1207 u32 src_addr_y1 = ReadReg32(base, IEP_SRC_ADDR_Y1);
1208 u32 src_addr_cbcr1 = ReadReg32(base, IEP_SRC_ADDR_CBCR1);
1209 u32 src_addr_cr1 = ReadReg32(base, IEP_SRC_ADDR_CR1);
1211 IEP_REGB_SRC_ADDR_YRGB(base, src_addr_y1);
1212 IEP_REGB_SRC_ADDR_CBCR(base, src_addr_cbcr1);
1213 IEP_REGB_SRC_ADDR_CR(base, src_addr_cr1);
1214 IEP_REGB_SRC_ADDR_Y1(base, src_addr_yrgb);
1215 IEP_REGB_SRC_ADDR_CBCR1(base, src_addr_cbcr);
1216 IEP_REGB_SRC_ADDR_CR1(base, src_addr_cr);
1219 #if defined(CONFIG_IEP_IOMMU)
1220 static int iep_bufid_to_iova(iep_service_info *pservice, u8 *tbl,
1221 int size, struct iep_reg *reg)
1227 if (tbl == NULL || size <= 0) {
1228 dev_err(pservice->iommu_dev, "input arguments invalidate\n");
1232 for (i = 0; i < size; i++) {
1233 usr_fd = reg->reg[tbl[i]] & 0x3FF;
1234 offset = reg->reg[tbl[i]] >> 10;
1236 struct ion_handle *hdl;
1238 struct iep_mem_region *mem_region;
1240 hdl = ion_import_dma_buf(pservice->ion_client, usr_fd);
1242 dev_err(pservice->iommu_dev,
1243 "import dma-buf from fd %d"
1244 " failed, reg[%d]\n",
1246 return PTR_ERR(hdl);
1249 mem_region = kzalloc(sizeof(struct iep_mem_region),
1252 if (mem_region == NULL) {
1253 dev_err(pservice->iommu_dev,
1254 "allocate memory for"
1255 " iommu memory region failed\n");
1256 ion_free(pservice->ion_client, hdl);
1260 mem_region->hdl = hdl;
1262 ret = ion_map_iommu(pservice->iommu_dev,
1263 pservice->ion_client, mem_region->hdl,
1264 &mem_region->iova, &mem_region->len);
1266 dev_err(pservice->iommu_dev,
1267 "ion map iommu failed\n");
1269 ion_free(pservice->ion_client, hdl);
1273 reg->reg[tbl[i]] = mem_region->iova + offset;
1274 INIT_LIST_HEAD(&mem_region->reg_lnk);
1275 list_add_tail(&mem_region->reg_lnk,
1276 ®->mem_region_list);
1283 static u8 addr_tbl_iep[] = {
1284 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55
1287 static int iep_reg_address_translate(iep_service_info *pservice, struct iep_reg *reg)
1289 return iep_bufid_to_iova(pservice, addr_tbl_iep, sizeof(addr_tbl_iep), reg);
1294 * generating a series of registers copy from iep message
1296 extern iep_service_info iep_service;
1297 void iep_config(iep_session *session, struct IEP_MSG *iep_msg)
1299 struct iep_reg *reg = kzalloc(sizeof(struct iep_reg), GFP_KERNEL);
1301 reg->session = session;
1302 iep_msg->base = reg->reg;
1303 atomic_set(®->session->done, 0);
1305 INIT_LIST_HEAD(®->session_link);
1306 INIT_LIST_HEAD(®->status_link);
1308 #if defined(CONFIG_IEP_IOMMU)
1309 INIT_LIST_HEAD(®->mem_region_list);
1313 iep_config_src_size(iep_msg);
1314 iep_config_dst_size(iep_msg);
1315 iep_config_dst_width_tile(iep_msg); //not implement
1316 iep_config_dst_fmt(iep_msg);
1317 iep_config_src_fmt(iep_msg);
1318 iep_config_scl(iep_msg);
1319 iep_config_cg_order(iep_msg);
1321 iep_config_cg(iep_msg);
1322 iep_config_dde(iep_msg); //not implement
1323 iep_config_color_enh(iep_msg); //not implement
1324 iep_config_yuv_dns(iep_msg);
1325 iep_config_dil(iep_msg);
1326 iep_config_yuv_enh(iep_msg);
1327 iep_config_rgb2yuv(iep_msg);
1328 iep_config_yuv2rgb(iep_msg);
1329 iep_config_dither_up(iep_msg);
1330 iep_config_dither_down(iep_msg);
1331 iep_config_glb_alpha(iep_msg);
1332 iep_config_vir_line(iep_msg);
1333 iep_config_src_addr(iep_msg);
1334 iep_config_dst_addr(iep_msg);
1335 iep_config_lcdc_path(iep_msg);
1336 iep_config_misc(iep_msg); //not implement
1338 if (iep_msg->lcdc_path_en) {
1340 reg->act_width = iep_msg->dst.act_w;
1341 reg->act_height = iep_msg->dst.act_h;
1342 reg->off_x = iep_msg->off_x;
1343 reg->off_y = iep_msg->off_y;
1344 reg->vir_width = iep_msg->width;
1345 reg->vir_height = iep_msg->height;
1346 reg->layer = iep_msg->layer;
1347 reg->format = iep_msg->dst.format;
1349 reg->dpi_en = false;
1352 #if defined(CONFIG_IEP_MMU)
1353 if (iep_msg->vir_addr_enable) {
1354 iep_config_mmu_cmd(iep_msg->base, MMU_ENABLE_PAGING);
1355 iep_config_mmu_page_fault_int_en(iep_msg->base, 1);
1357 iep_config_mmu_cmd(iep_msg->base, MMU_DISABLE_PAGING);
1358 iep_config_mmu_page_fault_int_en(iep_msg->base, 0);
1360 iep_config_mmu_dte_addr(iep_msg->base,
1361 (uint32_t)virt_to_phys((uint32_t *)session->dte_table));
1364 #if defined(CONFIG_IEP_IOMMU)
1365 if (iep_service.iommu_dev) {
1366 if (0 > iep_reg_address_translate(&iep_service, reg)) {
1367 IEP_ERR("error: translate reg address failed\n");
1374 mutex_lock(&iep_service.lock);
1376 list_add_tail(®->status_link, &iep_service.waiting);
1377 list_add_tail(®->session_link, &session->waiting);
1378 mutex_unlock(&iep_service.lock);