amvecm: lc: add driver interface for pc tool [1/1]
authorBencheng Jing <bencheng.jing@amlogic.com>
Tue, 15 Jan 2019 05:37:44 +0000 (13:37 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Thu, 28 Feb 2019 08:27:39 +0000 (00:27 -0800)
PD#SWPL-3300

Problem:
local contrast interface for pc tool

Solution:
add driver interface for pc tool

Verify:
tl1

Change-Id: I874ebc6c234f1030fa64a48033580af644550048
Signed-off-by: Bencheng Jing <bencheng.jing@amlogic.com>
drivers/amlogic/media/enhancement/amvecm/amvecm.c
drivers/amlogic/media/enhancement/amvecm/local_contrast.c
drivers/amlogic/media/enhancement/amvecm/local_contrast.h

index d2bd8b6..12e2b30 100644 (file)
@@ -5418,9 +5418,14 @@ static ssize_t amvecm_get_hdr_type_store(struct class *cls,
        return count;
 }
 
-static void lc_rd_reg(enum lc_reg_lut_e reg_sel)
+static void lc_rd_reg(enum lc_reg_lut_e reg_sel, int data_type)
 {
        int i, tmp, tmp1, tmp2;
+       int lut_data[63] = {0};
+       char *stemp = NULL;
+
+       if (data_type == 1)
+               goto dump_as_string;
 
        switch (reg_sel) {
        case SATUR_LUT:
@@ -5491,6 +5496,70 @@ static void lc_rd_reg(enum lc_reg_lut_e reg_sel)
        default:
                break;
        }
+       return;
+
+dump_as_string:
+       stemp = kzalloc(300, GFP_KERNEL);
+       if (!stemp)
+               return;
+       switch (reg_sel) {
+       case SATUR_LUT:
+               for (i = 0; i < 31 ; i++) {
+                       tmp = READ_VPP_REG(SRSHARP1_LC_SAT_LUT_0_1 + i);
+                       tmp1 = (tmp >> 16) & 0xfff;
+                       tmp2 = tmp & 0xfff;
+                       lut_data[2*i] = tmp1;
+                       lut_data[2*i + 1] = tmp2;
+               }
+               tmp = READ_VPP_REG(SRSHARP1_LC_SAT_LUT_62);
+               lut_data[62] = tmp & 0xfff;
+               for (i = 0; i < 63 ; i++)
+                       d_convert_str(lut_data[i],
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+               break;
+       case YMINVAL_LMT:
+               for (i = 0; i < 6 ; i++) {
+                       tmp = READ_VPP_REG(LC_CURVE_YMINVAL_LMT_0_1 + i);
+                       tmp1 = (tmp >> 16) & 0x3ff;
+                       tmp2 = tmp & 0x3ff;
+                       lut_data[2*i] = tmp1;
+                       lut_data[2*i + 1] = tmp2;
+               }
+               for (i = 0; i < 12 ; i++)
+                       d_convert_str(lut_data[i],
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+               break;
+       case YPKBV_YMAXVAL_LMT:
+               for (i = 0; i < 6 ; i++) {
+                       tmp = READ_VPP_REG(LC_CURVE_YPKBV_YMAXVAL_LMT_0_1 + i);
+                       tmp1 = (tmp >> 16) & 0x3ff;
+                       tmp2 = tmp & 0x3ff;
+                       lut_data[2*i] = tmp1;
+                       lut_data[2*i + 1] = tmp2;
+               }
+               for (i = 0; i < 12 ; i++)
+                       d_convert_str(lut_data[i],
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+               break;
+       case YPKBV_RAT:
+               tmp = READ_VPP_REG(LC_CURVE_YPKBV_RAT);
+               lut_data[0] = (tmp>>24) & 0xff;
+               lut_data[1] = (tmp>>16) & 0xff;
+               lut_data[2] = (tmp>>8) & 0xff;
+               lut_data[3] = tmp & 0xff;
+               for (i = 0; i < 4 ; i++)
+                       d_convert_str(lut_data[i],
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+               break;
+       default:
+               break;
+       }
+       kfree(stemp);
+       return;
 }
 
 static void lc_wr_reg(int *p, enum lc_reg_lut_e reg_sel)
@@ -5594,10 +5663,16 @@ static ssize_t amvecm_lc_store(struct class *cls,
        char *buf_orig, *parm[8] = {NULL};
        int reg_lut[63] = {0};
        enum lc_reg_lut_e reg_sel;
+       int h, v, i, start_point;
        long val = 0;
+       char *stemp = NULL;
+       int curve_val[6] = {0};
 
        if (!buf)
                return count;
+       stemp = kzalloc(100, GFP_KERNEL);
+       if (!stemp)
+               return 0;
 
        buf_orig = kstrdup(buf, GFP_KERNEL);
        parse_param_amvecm(buf_orig, (char **)&parm);
@@ -5609,6 +5684,8 @@ static ssize_t amvecm_lc_store(struct class *cls,
                        lc_en = 0;
                else
                        pr_info("unsupprt cmd!\n");
+       } else if (!strcmp(parm[0], "lc_version")) {
+               pr_info("lc driver version :  %s\n", LC_VER);
        } else if (!strcmp(parm[0], "lc_dbg")) {
                if (kstrtoul(parm[1], 16, &val) < 0)
                        goto free_buf;
@@ -5620,25 +5697,39 @@ static ssize_t amvecm_lc_store(struct class *cls,
                        lc_demo_mode = 0;
                else
                        pr_info("unsupprt cmd!\n");
-       } else if (!strcmp(parm[0], "lc_dump_reg")) {
+       } else if (!strcmp(parm[0], "dump_lut_data")) {
                if (kstrtoul(parm[1], 16, &val) < 0)
                        goto free_buf;
                reg_sel = val;
                if (reg_sel == SATUR_LUT)
-                       lc_rd_reg(SATUR_LUT);
+                       lc_rd_reg(SATUR_LUT, 0);
                else if (reg_sel == YMINVAL_LMT)
-                       lc_rd_reg(YMINVAL_LMT);
+                       lc_rd_reg(YMINVAL_LMT, 0);
                else if (reg_sel == YPKBV_YMAXVAL_LMT)
-                       lc_rd_reg(YPKBV_YMAXVAL_LMT);
+                       lc_rd_reg(YPKBV_YMAXVAL_LMT, 0);
                else if (reg_sel == YPKBV_RAT)
-                       lc_rd_reg(YPKBV_RAT);
+                       lc_rd_reg(YPKBV_RAT, 0);
                else if (reg_sel == YPKBV_SLP_LMT)
-                       lc_rd_reg(YPKBV_SLP_LMT);
+                       lc_rd_reg(YPKBV_SLP_LMT, 0);
                else if (reg_sel == CNTST_LMT)
-                       lc_rd_reg(CNTST_LMT);
+                       lc_rd_reg(CNTST_LMT, 0);
                else
                        pr_info("unsupprt cmd!\n");
-       } else if (!strcmp(parm[0], "lc_wr_reg")) {
+       } else if (!strcmp(parm[0], "dump_lut_str")) {
+               if (kstrtoul(parm[1], 16, &val) < 0)
+                       goto free_buf;
+               reg_sel = val;
+               if (reg_sel == SATUR_LUT)
+                       lc_rd_reg(SATUR_LUT, 1);
+               else if (reg_sel == YMINVAL_LMT)
+                       lc_rd_reg(YMINVAL_LMT, 1);
+               else if (reg_sel == YPKBV_YMAXVAL_LMT)
+                       lc_rd_reg(YPKBV_YMAXVAL_LMT, 1);
+               else if (reg_sel == YPKBV_RAT)
+                       lc_rd_reg(YPKBV_RAT, 1);
+               else
+                       pr_info("unsupprt cmd!\n");
+       } else if (!strcmp(parm[0], "lc_wr_lut")) {
                if (kstrtoul(parm[1], 16, &val) < 0)
                        goto free_buf;
                reg_sel = val;
@@ -5760,15 +5851,75 @@ static ssize_t amvecm_lc_store(struct class *cls,
                        goto free_buf;
                amlc_iir_debug_en = val;
                pr_info("setting value: %d\n", amlc_iir_debug_en);
-       } else
+       } else if (!strcmp(parm[0], "get_blk_region")) {
+               val = READ_VPP_REG(LC_CURVE_HV_NUM);
+               h = (val >> 8) & 0x1f;
+               v = (val) & 0x1f;
+               if (!strcmp(parm[1], "htotal"))
+                       pr_info("%d\n", h);
+               else if (!strcmp(parm[1], "vtotal"))
+                       pr_info("%d\n", v);
+               else
+                       pr_info("unsupprt cmd!\n");
+       } else if (!strcmp(parm[0], "get_hist")) {
+               if (kstrtoul(parm[1], 10, &val) < 0)
+                       goto free_buf;
+               h = val;
+               if (kstrtoul(parm[2], 10, &val) < 0)
+                       goto free_buf;
+               v = val;
+               if ((h > 11) || (v > 7))
+                       goto free_buf;
+               start_point = (12*v+h)*17;
+               for (i = 0; i < 17; i++)
+                       d_convert_str(lc_hist[start_point + i] >> 4,
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+       } else if (!strcmp(parm[0], "get_curve")) {
+               if (kstrtoul(parm[1], 10, &val) < 0)
+                       goto free_buf;
+               h = val;
+               if (kstrtoul(parm[2], 10, &val) < 0)
+                       goto free_buf;
+               v = val;
+               if ((h > 11) || (v > 7))
+                       goto free_buf;
+               start_point = (12*v+h)*6;
+               for (i = 0; i < 6; i++)
+                       d_convert_str(curve_nodes_cur[start_point + i],
+                                               i, stemp, 4, 10);
+               pr_info("%s\n", stemp);
+       } else if (!strcmp(parm[0], "set_curve")) {
+               if (parm[3] == NULL)
+                       goto free_buf;
+               if (kstrtoul(parm[1], 10, &val) < 0)
+                       goto free_buf;
+               h = val;
+               if (kstrtoul(parm[2], 10, &val) < 0)
+                       goto free_buf;
+               v = val;
+               if ((h > 11) || (v > 7))
+                       goto free_buf;
+               start_point = (12*v+h)*6;
+               str_sapr_to_d(parm[3], curve_val, 5);
+               for (i = 0; i < 6; i++)
+                       curve_nodes_cur[start_point + i]
+                       = curve_val[i];
+       } else if (!strcmp(parm[0], "stop_refresh"))
+               lc_curve_fresh = false;
+       else if (!strcmp(parm[0], "refresh_curve"))
+               lc_curve_fresh = true;
+       else
                pr_info("unsupprt cmd!\n");
 
        kfree(buf_orig);
+       kfree(stemp);
        return count;
 
 free_buf:
        pr_info("Missing parameters !\n");
        kfree(buf_orig);
+       kfree(stemp);
        return -EINVAL;
 }
 
index aadeaf0..f8167ac 100644 (file)
@@ -66,14 +66,15 @@ unsigned int lc_hist_ve;
 unsigned int lc_hist_hs;
 unsigned int lc_hist_he;
 /*lc curve data and hist data*/
-static int *lc_szcurve;/*12*8*6+4*/
-static int *curve_nodes_cur;
+int *lc_szcurve;/*12*8*6+4*/
+int *curve_nodes_cur;
 static int *curve_nodes_pre;
-static int *lc_hist;/*12*8*17*/
+int *lc_hist;/*12*8*17*/
 static bool lc_malloc_ok;
 /*print one or more frame data*/
 unsigned int lc_hist_prcnt;
 unsigned int lc_curve_prcnt;
+bool lc_curve_fresh = true;
 
 /*lc saturation gain, low parameters*/
 static unsigned int lc_satur_gain[63] = {
@@ -1008,10 +1009,11 @@ static void lc_fw_curve_iir(struct vframe_s *vf,
        if (!vf)
                return;
 
+       if (!lc_curve_fresh)
+               goto stop_curvefresh;
        /* pre: get curve nodes from szCurveInfo and save to curve_nodes_cur*/
        for (i = 0; i < 580; i++)/*12*8*6+4*/
                curve_nodes_cur[i] = lc_szcurve[i];
-
        /* pre: osd flag delay*/
        osd_flag_cnt_below[0] = osd_flag_cnt_below[1];
        osd_flag_cnt_above[0] = osd_flag_cnt_above[1];
@@ -1062,7 +1064,11 @@ static void lc_fw_curve_iir(struct vframe_s *vf,
        frm_cnt_above--;
        if (frm_cnt_above < 0)
                frm_cnt_above = 0;
+       return;
 
+stop_curvefresh:
+       for (i = 0; i < 580; i++)
+               lc_szcurve[i] = curve_nodes_cur[i];/*output*/
 }
 
 static void lc_read_region(int blk_vnum, int blk_hnum)
@@ -1171,7 +1177,7 @@ void lc_init(void)
 
        /*default LC low parameters*/
        WRITE_VPP_REG(LC_CURVE_CONTRAST_LH, 0x000b000b);
-       WRITE_VPP_REG(LC_CURVE_CONTRAST_SCL_LH, 0x000b000b);
+       WRITE_VPP_REG(LC_CURVE_CONTRAST_SCL_LH, 0x00000b0b);
        WRITE_VPP_REG(LC_CURVE_MISC0, 0x00023028);
        WRITE_VPP_REG(LC_CURVE_YPKBV_RAT, 0x3e69443c);
        WRITE_VPP_REG(LC_CURVE_YPKBV_SLP_LMT, 0x00000b33);
@@ -1226,6 +1232,7 @@ void lc_process(struct vframe_s *vf,
        lc_config(lc_en, vf, sps_h_en, sps_v_en);
        /*get each block curve*/
        read_lc_curve(blk_vnum, blk_hnum);
+       lc_read_region(blk_vnum, blk_hnum);
        /*do time domain iir*/
        lc_fw_curve_iir(vf, lc_hist,
                lc_szcurve, blk_vnum, blk_hnum);
@@ -1233,7 +1240,6 @@ void lc_process(struct vframe_s *vf,
                lc_prt_curve();
                lc_curve_prcnt--;
        }
-       lc_read_region(blk_vnum, blk_hnum);
        if (set_lc_curve(0, 1))
                pr_amlc_dbg("%s: set lc curve fail", __func__);
 
index 8564b04..d9d7a22 100644 (file)
@@ -21,6 +21,9 @@
 
 #include <linux/amlogic/media/vfm/vframe.h>
 
+/*V1.0: Local_contrast Basic function, iir algorithm, debug interface for tool*/
+#define LC_VER         "Ref.2019/02/27-V1.0"
+
 enum lc_mtx_sel_e {
        INP_MTX = 0x1,
        OUTP_MTX = 0x2,
@@ -70,6 +73,11 @@ extern int alpha2;
 extern int refresh_bit;
 extern int ts;
 extern int scene_change_th;
+extern bool lc_curve_fresh;
+extern int *lc_szcurve;/*12*8*6+4*/
+extern int *curve_nodes_cur;
+extern int *lc_hist;/*12*8*17*/
+
 
 extern void lc_init(void);
 extern void lc_process(struct vframe_s *vf,