backlight: ldim: algorithms clear up
authorEvoke Zhang <evoke.zhang@amlogic.com>
Fri, 27 Jul 2018 12:08:19 +0000 (20:08 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Fri, 3 Aug 2018 07:31:02 +0000 (00:31 -0700)
PD#170815: backlight: ldim: algorithms clear up

Change-Id: Ic6fc691dc67478ae4af6fc842427a839acf9d381
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
14 files changed:
MAINTAINERS
drivers/amlogic/media/Kconfig
drivers/amlogic/media/Makefile
drivers/amlogic/media/algorithm/Kconfig [new file with mode: 0644]
drivers/amlogic/media/algorithm/Makefile [new file with mode: 0644]
drivers/amlogic/media/vout/backlight/aml_ldim/Kconfig
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_dev_drv.c
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_drv.c
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_drv.h
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.c
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.h [deleted file]
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_reg.h
include/linux/amlogic/media/vout/lcd/aml_ldim.h
include/linux/amlogic/media/vout/lcd/ldim_alg.h [new file with mode: 0644]

index 180dcbfc657c24c519fb22e18896714b8772fb93..df4636af1e108974b749f11c305d50a67d6a1e15 100644 (file)
@@ -14555,6 +14555,11 @@ AMLOGIC PARTITION DTSI
 M: Jiaming Huang <jiaming.huang@amlogic.com>
 F: arch/arm64/boot/dts/amlogic/partition_tv_4G.dtsi
 
+AMLOGIC LCD BACKLIGHT LDIM
+M:      evoke zhang <evoke.zhang@amlogic.com>
+F:      drivers/amlogic/media/algorithm/*
+F:      drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.h
+
 AMLOGIC AVIN DETECT DRIVER
 M:     Xingyu Chen <xingyu.chen@amlogic.com>
 F:     drivers/amlogic/input/avin_detect/*
index bb5673d11933bc8e39288d126f97b27c99f7830a..d476845f4331d37ab2a49fbb015e6cd29d4b0410 100644 (file)
@@ -62,6 +62,7 @@ source "drivers/amlogic/media/vin/Kconfig"
 source "drivers/amlogic/media/video_processor/Kconfig"
 source "drivers/amlogic/media/enhancement/Kconfig"
 source "drivers/amlogic/media/gdc/Kconfig"
+source "drivers/amlogic/media/algorithm/Kconfig"
 endif
 source "drivers/amlogic/media/dtv_demod/Kconfig"
 endmenu
index 8db1870f34092bbd3f4db892177934b59258b1e2..dfb73164f56547d318c89c848191817b6a8c08f5 100644 (file)
@@ -10,3 +10,5 @@ obj-$(CONFIG_AMLOGIC_MEDIA_VIDEO_PROCESSOR)   +=      video_processor/
 obj-$(CONFIG_AMLOGIC_MEDIA_ENHANCEMENT) += enhancement/
 obj-$(CONFIG_AMLOGIC_DTV_DEMOD) += dtv_demod/
 obj-$(CONFIG_AMLOGIC_MEDIA_GDC) += gdc/
+
+obj-$(CONFIG_AMLOGIC_MEDIA_ALGORITHM) += algorithm/
diff --git a/drivers/amlogic/media/algorithm/Kconfig b/drivers/amlogic/media/algorithm/Kconfig
new file mode 100644 (file)
index 0000000..f28ecad
--- /dev/null
@@ -0,0 +1,21 @@
+#
+# Amlogic multimedia algorithm configuration
+#
+
+menu "Amlogic multimedia algorithm configuration"
+
+config AMLOGIC_MEDIA_ALGORITHM
+       bool "Amlgoic Multimedia Algorithm Support"
+       default n
+       help
+               Amlogic multimedia algorithm include:
+               dnlp
+               hdr10
+               sl_hdr
+               ldim
+
+if AMLOGIC_MEDIA_ALGORITHM
+#source "drivers/amlogic/media/algorithm/ldim/Kconfig"
+endif
+
+endmenu
diff --git a/drivers/amlogic/media/algorithm/Makefile b/drivers/amlogic/media/algorithm/Makefile
new file mode 100644 (file)
index 0000000..9cdffe6
--- /dev/null
@@ -0,0 +1 @@
+obj-$(CONFIG_AMLOGIC_MEDIA_ALGORITHM) = ldim/
index f8548e2849f4ba7d25feb2a1fa97f7e65b3ea755..bae6348e9d60e25c3829b33583cdcff565fed6fe 100644 (file)
@@ -2,11 +2,11 @@
 # LDIM Device Driver Configuration
 #
 config AMLOGIC_LOCAL_DIMMING
-       bool "Amlogic Local dimming"
+       bool "Amlogic Local Dimming"
        default n
        help
-         Say Y if you want to use Amlogic Local dimming.
-         The role of local dimming is according to each
-         image information, calculate the corresponding
-         brightness values, to improve the effect of image quality,
+               Say Y if you want to use Amlogic Local dimming.
+               The role of local dimming is according to each
+               image information, calculate the corresponding
+               brightness values, to improve the effect of image quality
 
index d7fe8dd6d8d90cd29813b8ed7414f5c6420f3bfe..491ff07ff1202365f1a408cdfbc3661544a30542 100644 (file)
@@ -989,7 +989,7 @@ static struct platform_driver ldim_dev_platform_driver = {
 static int __init ldim_dev_init(void)
 {
        if (platform_driver_register(&ldim_dev_platform_driver)) {
-               BLPR("failed to register bl driver module\n");
+               LDIMPR("failed to register ldim_dev driver module\n");
                return -ENODEV;
        }
        return 0;
@@ -1004,7 +1004,7 @@ late_initcall(ldim_dev_init);
 module_exit(ldim_dev_exit);
 
 
-MODULE_DESCRIPTION("LDIM Driver for LCD Backlight");
+MODULE_DESCRIPTION("LDIM device Driver for LCD Backlight");
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Amlogic, Inc.");
 
index 440f3649ef4340c33bf3c7a0f65d7142a1d0fae1..87e4735fe417a2b7aded8c548b00f23596d94d30 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/io.h>
 #include <linux/mm.h>
 #include <linux/mutex.h>
-#include <linux/device.h>
 #include <linux/cdev.h>
 #include <linux/uaccess.h>
 #include <linux/timer.h>
 #include <linux/platform_device.h>
 #include <linux/moduleparam.h>
 #include <linux/timer.h>
-#include <linux/amlogic/media/vfm/vframe.h>
 #include <linux/spinlock.h>
 #include <linux/amlogic/iomap.h>
-#include "ldim_drv.h"
-#include "ldim_func.h"
-#include "ldim_reg.h"
 #include <linux/workqueue.h>
+#include <linux/amlogic/media/vfm/vframe.h>
 #include <linux/amlogic/media/vout/lcd/aml_ldim.h>
 #include <linux/amlogic/media/vout/lcd/aml_bl.h>
 #include <linux/amlogic/media/vout/vout_notify.h>
 #include <linux/amlogic/media/vout/lcd/lcd_vout.h>
 #include <linux/amlogic/media/utils/vdec_reg.h>
 #include <linux/amlogic/media/vout/lcd/lcd_unifykey.h>
+#include <linux/amlogic/media/vout/lcd/ldim_alg.h>
+#include "ldim_drv.h"
+#include "ldim_reg.h"
 
 #define AML_LDIM_DEV_NAME            "aml_ldim"
 
-#ifndef MAX
-#define MAX(a, b)   ((a > b) ? a:b)
-#endif
-#ifndef MIN
-#define MIN(a, b)   ((a < b) ? a:b)
-#endif
-
-#ifndef ABS
-#define ABS(a)   ((a < 0) ? (-a):a)
-#endif
-
-#define FRM_NUM_DBG 5
-
 const char ldim_dev_id[] = "ldim-dev";
 unsigned char ldim_debug_print;
 
@@ -81,8 +67,10 @@ struct ldim_dev_s {
 };
 static struct ldim_dev_s ldim_dev;
 static struct ldim_param_s ldim_db_para;
-struct LDReg nPRM;
-struct FW_DAT FDat;
+struct LDReg_s nPRM;
+struct FW_DAT_s FDat;
+static struct ldim_fw_para_s ldim_fw_para;
+static struct aml_ldim_driver_s ldim_driver;
 
 static unsigned int ldim_hist_row = 1;
 static unsigned int ldim_hist_col = 1;
@@ -90,6 +78,7 @@ static unsigned int ldim_blk_row = 1;
 static unsigned int ldim_blk_col = 1;
 static unsigned int ldim_data_min = LD_DATA_MIN;
 static unsigned int ldim_brightness_level;
+static unsigned long litgain = LD_DATA_MAX;
 
 static unsigned char ldim_on_flag;
 static unsigned char LDIM_DATA_FROM_DB, db_print_flag;
@@ -109,66 +98,6 @@ static struct work_struct ldim_off_vs_work;
 static unsigned int ldim_irq_cnt;
 static unsigned int rdma_ldim_irq_cnt;
 
-/* ************************************************* */
-static unsigned long val_1[16] = {512, 512, 512, 512, 546, 546,
-       585, 630, 745, 819, 910, 1170, 512, 512, 512, 512};
-static unsigned long bin_1[16] = {4, 4, 4, 4, 4, 4,
-       4, 4, 4, 4, 4, 4, 4, 4, 4, 4};/* 0~32 */
-static unsigned long val_2[16] = {3712, 3712, 3712, 3712, 3823, 3823,
-       3647, 3455, 3135, 3007, 2879, 2623, 3750, 3800, 4000, 4055};
-static unsigned long bin_2[16] = {29, 29, 29, 29, 29, 29,
-       25, 22, 17, 15, 13, 28, 28, 27, 26, 25};
-
-
-/* *************** alg parameters ******************* */
-#define LD_FW_ALG_FRM_V0     0 /* gxtvbb, txlx local dimming, 201806 */
-#define LD_FW_ALG_FRM_V1     1 /* txlx local contrast, 2017.10 round */
-#define LD_FW_ALG_FRM_SEL    LD_FW_ALG_FRM_V0
-
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
-static unsigned long fw_LD_ThSF_l = 1600;
-static unsigned long fw_LD_ThTF_l = 32;/* note*/
-static unsigned long boost_gain = 2;
-static unsigned long boost_gain_neg = 3;
-static unsigned long alpha_delta = 255;/* to fix flicker */
-#define LD_FW_ALG_FRM_VER    "V1 - 20180612"
-
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
-static unsigned long fw_LD_ThSF_l = 1600;
-static unsigned long fw_LD_ThTF_l = 256;
-static unsigned long boost_gain = 456; /*norm 256 to 1,T960 finally use*/
-static unsigned long TF_alpha = 256; /*256;*/
-static unsigned long lpf_gain = 128;  /* [0~128~256], norm 128 as 1*/
-#define LD_FW_ALG_FRM_VER    "V0 - 20180628"
-#endif /* LD_FW_ALG_FRM_V0 */
-
-/*LPF tap: 0-lpf_res 41,1-lpf_res 114,...*/
-static unsigned long lpf_res = 14;    /* 1024/9*9 = 13,LPF_method=3 */
-static unsigned long rgb_base = 127;
-
-static unsigned int ov_gain = 16;
-static unsigned int incr_dif_gain = 16;
-
-static unsigned int LPF_method = 3;
-static unsigned int LD_TF_STEP_TH = 100;
-static unsigned int TF_step_method = 3;
-static unsigned int TF_FRESH_BL = 8;
-
-static unsigned int TF_BLK_FRESH_BL = 5;
-static unsigned int side_blk_diff_th = 100;
-static unsigned int bbd_th = 200;
-static unsigned char bbd_detect_en = 1;
-static unsigned char diff_blk_luma_en = 1;
-
-static unsigned int fw_rgb_diff_th = 32760;
-static unsigned int max_luma = 4060;
-static unsigned int lmh_avg_TH = 200;/*for woman flicker*/
-static unsigned int fw_TF_sum_th = 32760;/*20180530*/
-
-static unsigned long avg_gain = LD_DATA_MAX;
-static unsigned long litgain = LD_DATA_MAX;
-/* *************** alg parameters ******************* */
-
 /*BL_matrix remap curve*/
 static unsigned long bl_remap_curve[16] = {
        612, 654, 721, 851, 1001, 1181, 1339, 1516,
@@ -178,15 +107,6 @@ static unsigned long fw_LD_Whist[16] = {
        32, 64, 96, 128, 160, 192, 224, 256,
        288, 320, 352, 384, 416, 448, 480, 512
 };
-static unsigned char Sf_bypass, Boost_light_bypass;
-static unsigned char Lpf_bypass, Ld_remap_bypass;
-static unsigned char black_frm;
-
-static unsigned char fw_hist_print;/*20180525*/
-static unsigned char Debug;/*20180606*/
-static unsigned int db_cnt;
-static unsigned int fw_print_frequent = 8;/*20180606,print every 8 frame*/
-static unsigned int Dbprint_lv;
 
 static unsigned int ldim_hist_en;
 module_param(ldim_hist_en, uint, 0664);
@@ -208,14 +128,12 @@ static unsigned int ldim_top_en;
 module_param(ldim_top_en, uint, 0664);
 MODULE_PARM_DESC(ldim_top_en, "ldim_top_en");
 
-static struct aml_ldim_driver_s ldim_driver;
 static void ldim_on_vs_brightness(void);
 static void ldim_off_vs_brightness(void);
 static void ldim_on_vs_arithmetic(void);
-static void ldim_update_setting(void);
+static void ldim_dump_histgram(void);
 static void ldim_get_matrix_info_max_rgb(void);
-static void ldim_bl_remap_curve(int slop_gain);
-static void ldim_bl_remap_curve_print(void);
+
 static struct ldim_config_s ldim_config = {
        .hsize = 3840,
        .vsize = 2160,
@@ -236,1438 +154,207 @@ static void ldim_off_update_brightness(struct work_struct *work)
        ldim_off_vs_brightness();
 }
 
-void LDIM_WR_32Bits(unsigned int addr, unsigned int data)
-{
-#ifdef CONFIG_VSYNC_RDMA
-       VSYNC_WR_MPEG_REG(LDIM_BL_ADDR_PORT, addr);
-       VSYNC_WR_MPEG_REG(LDIM_BL_DATA_PORT, data);
-#else
-       Wr(LDIM_BL_ADDR_PORT, addr);
-       Wr(LDIM_BL_DATA_PORT, data);
-#endif
-}
-
-unsigned int LDIM_RD_32Bits(unsigned int addr)
+static void ldim_db_para_print(struct LDReg_s *mLDReg)
 {
-       Wr(LDIM_BL_ADDR_PORT, addr);
-       return Rd(LDIM_BL_DATA_PORT);
-}
+       int i, len;
+       char *buf;
 
-void LDIM_wr_reg_bits(unsigned int addr, unsigned int val,
-                               unsigned int start, unsigned int len)
-{
-       unsigned int data;
+       len = 32 * 10 + 10;
+       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
+       if (buf == NULL) {
+               LDIMERR("print buf malloc error\n");
+               return;
+       }
 
-       data = LDIM_RD_32Bits(addr);
-       data = (data & (~((1 << len) - 1)<<start))  |
-               ((val & ((1 << len) - 1)) << start);
-       LDIM_WR_32Bits(addr, data);
-}
+       LDIMPR("rgb_base = %ld\n"
+               "boost_gain = %ld\n"
+               "lpf_res = %ld\n"
+               "fw_LD_ThSF = %ld\n\n",
+               ldim_fw_para.rgb_base,
+               ldim_fw_para.boost_gain,
+               ldim_fw_para.lpf_res,
+               ldim_fw_para.fw_LD_ThSF_l);
 
-void LDIM_WR_BASE_LUT(unsigned int base, unsigned int *pData,
-                               unsigned int size_t, unsigned int len)
-{
-       unsigned int i;
-       unsigned int addr, data;
-       unsigned int mask, subCnt;
-       unsigned int cnt;
-
-       addr   = base;/* (base<<4); */
-       mask   = (1 << size_t)-1;
-       subCnt = 32 / size_t;
-       cnt  = 0;
-       data = 0;
+       LDIMPR("ld_vgain = %d\n"
+               "ld_hgain = %d\n"
+               "ld_litgain = %d\n\n",
+               mLDReg->reg_LD_Vgain,
+               mLDReg->reg_LD_Hgain,
+               mLDReg->reg_LD_Litgain);
 
-       Wr(LDIM_BL_ADDR_PORT, addr);
+       LDIMPR("ld_lut_vdg_lext = %d\n"
+               "ld_lut_hdg_lext = %d\n"
+               "ld_lut_vhk_lext = %d\n\n",
+               mLDReg->reg_LD_LUT_Vdg_LEXT,
+               mLDReg->reg_LD_LUT_Hdg_LEXT,
+               mLDReg->reg_LD_LUT_VHk_LEXT);
 
-       for (i = 0; i < len; i++) {
-               data = data | ((pData[i] & mask) << (size_t *cnt));
-               cnt++;
-               if (cnt == subCnt) {
-                       Wr(LDIM_BL_DATA_PORT, data);
-                       data = 0;
-                       cnt = 0;
-                       addr++;
-               }
+       len = 0;
+       LDIMPR("ld_lut_hdg:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_Hdg[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
        }
-       if (cnt != 0)
-               Wr(LDIM_BL_DATA_PORT, data);
-}
-void LDIM_RD_BASE_LUT(unsigned int base, unsigned int *pData,
-                               unsigned int size_t, unsigned int len)
-{
-       unsigned int i;
-       unsigned int addr, data;
-       unsigned int mask, subCnt;
-       unsigned int cnt;
-
-       addr   = base;/* (base<<4); */
-       mask   = (1 << size_t)-1;
-       subCnt = 32 / size_t;
-       cnt  = 0;
-       data = 0;
+       pr_info("%s\n", buf);
 
-       Wr(LDIM_BL_ADDR_PORT, addr);
-
-       for (i = 0; i < len; i++) {
-               cnt++;
-               if (cnt == subCnt) {
-                       data = Rd(LDIM_BL_DATA_PORT);
-                       pData[i-1] = data & mask;
-                       pData[i] = mask & (data >> size_t);
-                       data = 0;
-                       cnt = 0;
-                       addr++;
-               }
+       len = 0;
+       LDIMPR("ld_lut_vdg:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_Vdg[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
        }
-       if (cnt != 0)
-               data = Rd(LDIM_BL_DATA_PORT);
-}
-void LDIM_RD_BASE_LUT_2(unsigned int base, unsigned int *pData,
-                               unsigned int size_t, unsigned int len)
-{
-       unsigned int i;
-       unsigned int addr, data;
-       unsigned int mask, subCnt;
-       unsigned int cnt;
-
-       addr   = base;/* (base<<4); */
-       mask   = (1 << size_t)-1;
-       subCnt = 2;
-       cnt  = 0;
-       data = 0;
+       pr_info("%s\n", buf);
 
-       Wr(LDIM_BL_ADDR_PORT, addr);
-
-       for (i = 0; i < len; i++) {
-               cnt++;
-               if (cnt == subCnt) {
-                       data = Rd(LDIM_BL_DATA_PORT);
-                       pData[i-1] = data & mask;
-                       pData[i] = mask & (data >> size_t);
-                       data = 0;
-                       cnt = 0;
-                       addr++;
-               }
+       len = 0;
+       LDIMPR("ld_lut_vhk:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_VHk[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
        }
-       if (cnt != 0)
-               data = Rd(LDIM_BL_DATA_PORT);
-}
-
+       pr_info("%s\n", buf);
 
-static void ldim_bl_remap_curve(int slop_gain)
-{
-       int i = 0, ii = 0;
-       int t_bl_remap_curve[16] = {0};
-       int bl_max = 0, mid_value = 0;
-
-       LDIMPR("%s:\n", __func__);
-       for (i = 0; i < 16; i++) {
-               ii = (i + 1) * 256;
-               mid_value = ii * ii >> 17;
-               t_bl_remap_curve[i] = mid_value * slop_gain + 512;
+       len = 0;
+       LDIMPR("ld_lut_vhk_pos:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_VHk_pos[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
        }
-       bl_max = t_bl_remap_curve[15];
+       pr_info("%s\n", buf);
 
-       for (i = 0; i < 16; i++)
-               bl_remap_curve[i] = t_bl_remap_curve[i] * 4095 / bl_max;
-}
+       len = 0;
+       LDIMPR("ld_lut_vhk_neg:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_VHk_neg[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
+       }
+       pr_info("%s\n", buf);
 
-static void ldim_bl_remap_curve_print(void)
-{
-       int i = 0, len;
-       char *buf;
+       len = 0;
+       LDIMPR("ld_lut_hhk:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_HHk[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
+       }
+       pr_info("%s\n", buf);
 
-       len = 16 * 8 + 20;
-       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
-       if (buf == NULL) {
-               LDIMERR("print buf malloc error\n");
-               return;
+       len = 0;
+       LDIMPR("ld_lut_vho_pos:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_VHo_pos[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
        }
+       pr_info("%s\n", buf);
 
-       pr_info("bl_remap_curve:\n");
        len = 0;
-       for (i = 0; i < 16; i++)
-               len += sprintf(buf+len, "\t%ld\n", bl_remap_curve[i]);
+       LDIMPR("ld_lut_vho_neg:\n");
+       for (i = 0; i < 32; i++) {
+               len += sprintf(buf+len, "\t%d",
+                       mLDReg->reg_LD_LUT_VHo_neg[i]);
+               if (i % 8 == 7)
+                       len += sprintf(buf+len, "\n");
+       }
        pr_info("%s\n", buf);
 
        kfree(buf);
 }
 
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
-static void ld_fw_alg_frm_txlx(struct LDReg *nPRM1, struct FW_DAT *FDat1,
-       unsigned int *max_matrix, unsigned int *hist_matrix)
+static void ldim_db_load_update(struct LDReg_s *mLDReg)
 {
-       /* Notes, nPRM will be set here in SW algorithm too */
-       int dif, blkRow, blkCol, k, m, n;
-       unsigned long sum;
-       int adpt_alp;
-       unsigned int avg, alpha = 256, Bmin, Bmax, bl_value;
-       unsigned int Vnum  = (nPRM1->reg_LD_BLK_Vnum);
-       unsigned int Hnum  = (nPRM1->reg_LD_BLK_Hnum);
-       unsigned int *tBL_matrix;
-       unsigned int BLmax = 4096;   /* maximum BL value */
-       int stride = ldim_hist_col;
-       int RGBmax, Histmx, maxNB, curNB = 0;
-       unsigned int fw_blk_num  = Vnum*Hnum;
-       unsigned int fw_LD_Thist = ((fw_blk_num*5)>>2);
-       unsigned int fw_pic_size =
-                       (nPRM1->reg_LD_pic_RowMax)*(nPRM1->reg_LD_pic_ColMax);
-       int fw_LD_ThSF = 1600;
-       unsigned int fw_LD_ThTF = 32;
-       unsigned int fw_LD_BLEst_ACmode = 1;
-       unsigned int fw_hist_mx;
-       unsigned int SF_sum = 0, TF_sum = 0, dif_sum = 0;
-       int gain_neg_delta = 0;
-       int pr_flag = 0;
-
-       fw_LD_ThSF = fw_LD_ThSF_l;
-       fw_LD_ThTF = fw_LD_ThTF_l;
-       tBL_matrix = FDat1->TF_BL_matrix_2;
-
-       /* first 8 frame & every 2 min print*/
-       pr_flag = (db_cnt < 8) || (db_cnt % 120 == 0);
-       if (Dbprint_lv == 1) {
-               if (pr_flag) {
-                       pr_info("input:\n"
-                               "Vnum = [%4d]\n"
-                               "Hnum = [%4d]\n"
-                               "reg_LD_pic_RowMax = [%4d]\n"
-                               "reg_LD_pic_ColMax = [%4d]\n\n"
-                               "stride(ldim_hist_col) = [%4d]\n\n",
-                               Vnum, Hnum,
-                               nPRM1->reg_LD_pic_RowMax,
-                               nPRM1->reg_LD_pic_ColMax,
-                               ldim_hist_col);
-                       if (fw_hist_print) {
-                               for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                                       for (blkCol = 0; blkCol < Hnum;
-                                               blkCol++) {
-                                               pr_info("(%d,%d,%d); ",
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 0],
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 1],
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 2]);
-                                       }
-                                       pr_info("\n");
-                               }
-                               pr_info("\n\n");
-                       }
-               }
-       }
-
-       /* calculate the current frame */
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       RGBmax = MAX(MAX(max_matrix[blkRow*3*stride +
-                               blkCol*3 + 0],
-                       max_matrix[blkRow*3*stride + blkCol*3 + 1]),
-                       max_matrix[blkRow*3*stride + blkCol*3 + 2]);
-                       /* Consider the sitrogram */
-                       Histmx = 0;
-                       for (k = 0; k < 16; k++) {
-                               Histmx += (hist_matrix[blkRow*LD_STA_BIN_NUM*
-                                       stride + blkCol*LD_STA_BIN_NUM + k] *
-                                       fw_LD_Whist[k]);
-                               }
-                       fw_hist_mx =
-                               ((Histmx>>8)*fw_LD_Thist*2/(fw_pic_size>>8));
-                       /* further debug */
-                       tBL_matrix[blkRow*Hnum + blkCol] =
-                               ((BLmax*MIN(fw_hist_mx, RGBmax))>>10);
-                               nPRM1->BL_matrix[blkCol*Vnum +
-                                       blkRow] = tBL_matrix[blkRow*Hnum +
-                                               blkCol];
-               }
-       }
-
-       if (Dbprint_lv == 1) {
-               if (pr_flag) {
-                       pr_info("BL_0[%d * %d] info(LD_STA_BIN_NUM: %d): [\n ",
-                               Vnum, Hnum, LD_STA_BIN_NUM);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d) ",
-                                       tBL_matrix[blkRow*Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n ");
-                       }
-                       pr_info(" ]\n\n ");
-               }
-       }
+       int i;
 
-       /* Spatial Filter the BackLits */
-       sum = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       maxNB = 0;
-                       for (m =  -1; m < 2; m++) {
-                               for (n =  -1; n < 2; n++) {
-                                       if ((m == 0) && (n == 0))
-                                               curNB =
-                                               tBL_matrix[blkRow*Hnum +
-                                               blkCol];
-                                       else if (((blkRow+m) >= 1) &&
-                                               ((blkRow+m) <= Vnum) &&
-                                               ((blkCol+n) >= 1) &&
-                                               ((blkCol+n) <= Hnum))
-                                               maxNB = MAX(maxNB, tBL_matrix[
-                                                       blkRow*Hnum + blkCol]);
-                               }
-                       }
-                       /* SF matrix */
-                       FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] =
-                               MAX(curNB, (maxNB-fw_LD_ThSF));
-                       sum += FDat1->SF_BL_matrix[blkRow*Hnum + blkCol];
-                       /* for SF_BL_matrix average calculation */
-               }
-       }
+       if (LDIM_DATA_FROM_DB == 1) {
+               LDIMPR("ldim_db_load_update\n");
+               /* beam model */
+               ldim_fw_para.rgb_base = (unsigned long)ldim_db_para.rgb_base;
+               ldim_fw_para.boost_gain =
+                       (unsigned long)ldim_db_para.boost_gain;
+               ldim_fw_para.lpf_res = (unsigned long)ldim_db_para.lpf_res;
+               ldim_fw_para.fw_LD_ThSF_l =
+                       (unsigned long)ldim_db_para.fw_ld_th_sf;
 
-       if (Dbprint_lv == 1) {
-               if (pr_flag) {
-                       pr_info("BL_SF[%d * %d] info: [\n ", Vnum, Hnum);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d) ",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow*Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n ");
-                       }
-                       pr_info(" ]\n\n ");
-               }
-       }
+               /* beam curve */
+               mLDReg->reg_LD_Vgain = ldim_db_para.ld_vgain;
+               mLDReg->reg_LD_Hgain = ldim_db_para.ld_hgain;
+               mLDReg->reg_LD_Litgain = ldim_db_para.ld_litgain;
 
-       /* boost the bright region lights a little bit. */
-       avg = ((sum*7/fw_blk_num)>>3);
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       dif = (FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] - avg);
-                       if (dif > 0)
-                               FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] +=
-                                       (boost_gain*dif);
-                       if (dif < 0) {
-                               gain_neg_delta = -boost_gain_neg*dif;
-                               if (FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] >
-                                       gain_neg_delta) {
-                                       FDat1->SF_BL_matrix[
-                                               blkRow*Hnum + blkCol] -=
-                                               gain_neg_delta;
-                               } else {
-                                       FDat1->SF_BL_matrix[
-                                               blkRow*Hnum + blkCol] = 0;
-                               }
-                       }
-                       if (FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] > 4095)
-                               FDat1->SF_BL_matrix[blkRow*Hnum + blkCol]
-                                       = 4095;
-                       if (FDat1->SF_BL_matrix[blkRow*Hnum + blkCol] < 0)
-                               FDat1->SF_BL_matrix[blkRow*Hnum + blkCol]
-                                       = 0; /*clip*/
-               }
-       }
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       SF_sum += FDat1->SF_BL_matrix[blkRow*Hnum + blkCol];
-                       TF_sum += FDat1->TF_BL_matrix[blkRow*Hnum + blkCol];
-               }
-       }
+               mLDReg->reg_LD_LUT_Vdg_LEXT = ldim_db_para.ld_lut_vdg_lext;
+               mLDReg->reg_LD_LUT_Hdg_LEXT = ldim_db_para.ld_lut_hdg_lext;
+               mLDReg->reg_LD_LUT_VHk_LEXT = ldim_db_para.ld_lut_vhk_lext;
 
-       if (Dbprint_lv == 1) {
-               if (pr_flag) {
-                       pr_info("BL_boost_SF [%d * %d] info:\n",
-                               Vnum, Hnum);
-                       pr_info("boost_gain: %ld,%ld:\n"
-                               "luma_avg = %d, SF_sum= %d, TF_sum = %d\n\n ",
-                               boost_gain, boost_gain_neg,
-                               avg, SF_sum, TF_sum);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d) ",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow*Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n");
-                       }
-                       pr_info(" ]\n\n");
+               for (i = 0; i < 32; i++) {
+                       mLDReg->reg_LD_LUT_Hdg[i] = ldim_db_para.ld_lut_hdg[i];
+                       mLDReg->reg_LD_LUT_Vdg[i] = ldim_db_para.ld_lut_vdg[i];
+                       mLDReg->reg_LD_LUT_VHk[i] = ldim_db_para.ld_lut_vhk[i];
                }
-       }
 
-       /* Temperary filter */
-       sum = 0; Bmin = 4096; Bmax = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       /* Optimization needed here */
-                       adpt_alp = ABS((FDat1->SF_BL_matrix[
-                               blkRow*Hnum + blkCol]) -
-                               (FDat1->TF_BL_matrix[
-                               blkRow*Hnum + blkCol]));
-
-                       dif_sum = ABS(SF_sum - TF_sum);
-                       if (dif_sum > fw_TF_sum_th)
-                               alpha = 256-alpha_delta;
-                       else
-                               alpha = MIN(256, fw_LD_ThTF);
-
-                       FDat1->TF_BL_alpha[blkRow*Hnum + blkCol] = alpha;
-
-                       /* get the temporary filtered BL_value */
-                       bl_value = (((256-alpha) * (FDat1->TF_BL_matrix[
-                               blkRow*Hnum + blkCol]) +
-                               alpha*(FDat1->SF_BL_matrix[
-                               blkRow*Hnum + blkCol]) +
-                               128) >> 8);
-
-                       /* Set the TF_BL_matrix to the BL_matrix */
-                       if (nPRM1->reg_LD_BackLit_mode == 1)
-                               nPRM1->BL_matrix[blkCol*Vnum +
-                                       blkRow] = bl_value;
-                       else
-                               nPRM1->BL_matrix[blkRow*Hnum +
-                                       blkCol] = bl_value;
-
-                       /* Get the TF_BL_matrix */
-                       FDat1->TF_BL_matrix[blkRow*Hnum + blkCol] = bl_value;
-
-                       /* leave the Delayed version for next frame */
-                       for (k = 0; k < 3; k++)
-                               FDat1->last_STA1_MaxRGB[blkRow*3*stride +
-                               blkCol*3 + k] =
-                                       max_matrix[blkRow*3*stride +
-                                               blkCol*3 + k];
-
-                       /* get the sum/min/max */
-                       sum += bl_value;
-                       Bmin = MIN(Bmin, bl_value);
-                       Bmax = MAX(Bmax, bl_value);
+               /* beam shape minor adjustment */
+               for (i = 0; i < 32; i++) {
+                       mLDReg->reg_LD_LUT_VHk_pos[i] =
+                               ldim_db_para.ld_lut_vhk_pos[i];
+                       mLDReg->reg_LD_LUT_VHk_neg[i] =
+                               ldim_db_para.ld_lut_vhk_neg[i];
+                       mLDReg->reg_LD_LUT_HHk[i] =
+                               ldim_db_para.ld_lut_hhk[i];
+                       mLDReg->reg_LD_LUT_VHo_pos[i] =
+                               ldim_db_para.ld_lut_vho_pos[i];
+                       mLDReg->reg_LD_LUT_VHo_neg[i] =
+                               ldim_db_para.ld_lut_vho_neg[i];
                }
-       }
 
-       if (Dbprint_lv == 1) {
-               if (pr_flag) {
-                       pr_info("BL_TF(final out)[%d*%d] info(alpha:%d,): [\n",
-                               Vnum, Hnum, alpha);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d) ",
-                                       FDat1->TF_BL_matrix[
-                                               blkRow*Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n ");
-                       }
-                       pr_info(" ]\n\n ");
-               }
+               /* remapping */
+               /*ldim_db_para.lit_idx_th;*/
+               /*ldim_db_para.comp_gain;*/
        }
 
-       db_cnt++;
-       if (db_cnt > 4095)
-               db_cnt = 0;
-
-       /* set the DC reduction for the BL_modeling */
-       if (fw_LD_BLEst_ACmode == 0)
-               nPRM1->reg_BL_matrix_AVG = 0;
-       else if (fw_LD_BLEst_ACmode == 1)
-               nPRM1->reg_BL_matrix_AVG = (sum/fw_blk_num);
-       else if (fw_LD_BLEst_ACmode == 2)
-               nPRM1->reg_BL_matrix_AVG = Bmin;
-       else if (fw_LD_BLEst_ACmode == 3)
-               nPRM1->reg_BL_matrix_AVG = Bmax;
-       else if (fw_LD_BLEst_ACmode == 4)
-               nPRM1->reg_BL_matrix_AVG = 2048;
-       else
-               nPRM1->reg_BL_matrix_AVG = 1024;
-       nPRM1->reg_BL_matrix_Compensate = nPRM1->reg_BL_matrix_AVG;
+       if (db_print_flag == 1)
+               ldim_db_para_print(mLDReg);
 }
 
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
-static unsigned long  black_time_cnt; /*black_display statue */
-static void ld_fw_alg_frm_gxtvbb(struct LDReg *nPRM1, struct FW_DAT *FDat1,
-       unsigned int *max_matrix, unsigned int *hist_matrix)
+static void ldim_stts_initial(unsigned int pic_h, unsigned int pic_v,
+               unsigned int BLK_Vnum, unsigned int BLK_Hnum)
 {
-       /* Notes, nPRM will be set here in SW algorithm too */
-       int dif, blkRow, blkCol, k, m, n, i, tmp;
-       unsigned long sum;
-       unsigned int avg, alpha = 256, Bmin, Bmax; /*local here*/
-       unsigned int bl_value, bl_valuex128;
-       static unsigned int  Map_bl_matrix[192];
-       static unsigned int  Tf_bl_matrix_map[192];
-       static unsigned int  TF_bl_matrix_t[384]; /*max=16*24*/
-       static unsigned int  Map_bl_matrix_Compensate;
-       static unsigned int  Map_bl_matrix_AVG;
-       /*consistent with ldim hist_row*/
-       unsigned int Vnum  = (nPRM1->reg_LD_BLK_Vnum);
-       /*consistent with ldim hist_col*/
-       unsigned int Hnum  = (nPRM1->reg_LD_BLK_Hnum);
-       unsigned int *tBL_matrix;
-       unsigned int BLmax = 4096;
-       int stride = ldim_hist_col;/* inherit from ldim_hist_col */
-       int RGBmax, Histmx, maxNB, curNB = 0;
-       unsigned int fw_blk_num  = Vnum * Hnum;
-       unsigned int fw_LD_Thist = ((fw_blk_num * 5) >> 2);
-       /*consistent with ldim picture size: ldim_pic_row * ldim_pic_col*/
-       unsigned int fw_pic_size =
-                       (nPRM1->reg_LD_pic_RowMax) * (nPRM1->reg_LD_pic_ColMax);
-       int fw_LD_ThSF = 1600;
-       unsigned int fw_LD_ThTF = 32;
-       static unsigned int  Tf_luma_avg_frm[FRM_NUM_DBG] = {0, 0, 0, 0, 0};
-       /* note!  when Hnum,Vnum changed.
-        * make sure Hnum*Vnum<= 16 or change 16 to other num
-        */
-       static unsigned int  Tf_blkLuma_avg[FRM_NUM_DBG][16];
-       static unsigned int  Tf_bl_matrix[FRM_NUM_DBG][16];
-       static unsigned int  Tf_diff_frm_luma[FRM_NUM_DBG] = {0, 0, 0, 0, 0};
-       static unsigned int  Tf_diff_blk_luma[FRM_NUM_DBG][16];
-       unsigned int fw_LD_BLEst_ACmode = 1;
-       int num = 0, mm = 0, nn = 0;
-       unsigned int fw_hist_mx;
-       unsigned int SF_sum = 0, TF_sum = 0;
-       int int_x, rmd_x, norm;
-       int left,  right, bl_value_map;
-       int Luma_avg = 0, blkLuma_avg = 0, lmh_avg = 0, blk_sum = 0;
-       int diff_frm_luma = 0, diff_blk_luma = 0;
-       int diff_blk_matrix = 0, remap_value = 0;
-       int dif_r = 0, dif_g = 0, dif_b = 0, adpt_alp = 0, dif_sum = 0;
-       int tvalue = 0, min_diff = 0;
-       int Bmax_lpf = 0;
-       int frm_rgbmax = 0, black_blk_num = 0;
-       int tdiff = 0, mx_diff = 0;
-
-       /* for debug */
-       unsigned int pr_flag = 0;
-       static unsigned int frm_cnt;
-
-       /*patch for fast luma change. */
-       int step = 0;
-       static unsigned int TF_bl_matrix_t2[16]; /*>Vnum*Hnum*/
-       static unsigned int TF_bl_matrix_t3[16]; /*>Vnum*Hnum*/
-       int diff_blk_matrix_tf_avg = 0;
-       int Tf_diff_frm_luma_tf_avg = 0;
-       int side_blk_diff = 0;
-
-       fw_LD_ThSF = fw_LD_ThSF_l;
-       fw_LD_ThTF = fw_LD_ThTF_l;
-
-       tBL_matrix = FDat1->TF_BL_matrix_2;
-
-       /* first 8 frame & every 8(fw_print_frequent) frames print once*/
-       pr_flag = (frm_cnt < 8) || (frm_cnt % fw_print_frequent == 0);
-
-       if ((Dbprint_lv == 1) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("input: Vnum = [%4d],Hnum = [%4d],\n"
-                       "RowMax=[%4d],ColMax=[%4d],ldim_hist_col=[%4d]\n",
-                               Vnum, Hnum,
-                               nPRM1->reg_LD_pic_RowMax,
-                               nPRM1->reg_LD_pic_ColMax,
-                               ldim_hist_col);
-                       if (fw_hist_print) {
-                               for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                                       for (blkCol = 0; blkCol < Hnum;
-                                               blkCol++) {
-                                               pr_info("(%d,%d,%d)\n ",
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 0],
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 1],
-                                               max_matrix[blkRow*3*stride +
-                                                       blkCol*3 + 2]);
-                                       }
-                                       pr_info(";\n");
-                               }
-                               pr_info("];\n");
-                       }
-               }
-       }
+       unsigned int resolution, resolution_region, blk_height, blk_width;
+       unsigned int row_start, col_start;
+       struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
 
-       /* store 5 frames Luma_avg */
-       for (i = 0; i < (FRM_NUM_DBG - 1); i++) {
-               for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                       for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                               tmp = blkRow * Hnum + blkCol;
-                               Tf_blkLuma_avg[i][tmp] =
-                                       Tf_blkLuma_avg[i+1][tmp];
-                               Tf_bl_matrix[i][tmp] =
-                                       Tf_bl_matrix[i+1][tmp];
-                               Tf_diff_blk_luma[i][tmp] =
-                                       Tf_diff_blk_luma[i+1][tmp];
-                       }
-               }
-               Tf_luma_avg_frm[i] = Tf_luma_avg_frm[i+1];
-               Tf_diff_frm_luma[i] = Tf_diff_frm_luma[i+1];
-       }
+       BLK_Vnum = (BLK_Vnum == 0) ? 1 : BLK_Vnum;
+       BLK_Hnum = (BLK_Hnum == 0) ? 1 : BLK_Hnum;
+       LDIMPR("%s: %d %d %d %d\n", __func__, pic_h, pic_v, BLK_Vnum, BLK_Hnum);
 
-       if ((Dbprint_lv == 2) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-pre:5 frames info:\n ");
-                       for (i = 0; i < FRM_NUM_DBG; i++) {
-                               for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                                       for (blkCol = 0; blkCol < Hnum;
-                                               blkCol++) {
-                                               tmp = blkRow * Hnum + blkCol;
-                                               pr_info("Tf_blkLuma_avg[%d][%4d],Tf_bl_matrix[%d][%4d],Tf_diff_blk_luma[%d][%4d]\n",
-                                               i,
-                                               Tf_blkLuma_avg[i][tmp],
-                                               i,
-                                               Tf_bl_matrix[i][tmp],
-                                               i,
-                                               Tf_diff_blk_luma[i][tmp]);
-                                       }
-                                       pr_info(" ;\n ");
-                               }
-                               pr_info("];\n ");
-                       }
-               }
-       }
+       ldim_fw_para.hist_col = BLK_Vnum;
+       ldim_fw_para.hist_row = BLK_Hnum;
 
-       frm_rgbmax = 0; black_blk_num = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       RGBmax = MAX(MAX(max_matrix[blkRow * 3 * stride +
-                               blkCol * 3], max_matrix[blkRow * 3 * stride +
-                               blkCol * 3 + 1]), max_matrix[blkRow * 3 *
-                               stride + blkCol * 3 + 2]);
-                       if ((RGBmax == 0) &&
-                               (hist_matrix[blkRow * LD_STA_BIN_NUM * stride +
-                               blkCol * LD_STA_BIN_NUM + 0] >= 1030800))
-                               black_blk_num++;
-                       frm_rgbmax = MAX(frm_rgbmax, RGBmax);
-               }
-       }
-
-       /* calculate the current frame */
-       sum = 0; Luma_avg = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       RGBmax = MAX(MAX(max_matrix[blkRow * 3 * stride +
-                               blkCol * 3], max_matrix[blkRow * 3 * stride +
-                               blkCol * 3 + 1]), max_matrix[blkRow * 3 *
-                               stride + blkCol * 3 + 2]);
-                       if (frm_rgbmax != 0) {
-                               if (RGBmax < rgb_base)
-                                       RGBmax = rgb_base;
-                       }
-                       /* Consider the histogram */
-                       Histmx = 0;
-                       blkLuma_avg = 0;
-                       blk_sum = 0;
-                       for (k = 0; k < 16; k++) {
-                               Histmx += (hist_matrix[blkRow * LD_STA_BIN_NUM *
-                                       stride + blkCol * LD_STA_BIN_NUM + k] *
-                                       fw_LD_Whist[k]);
-                               blk_sum += hist_matrix[blkRow * LD_STA_BIN_NUM *
-                                       stride + blkCol * LD_STA_BIN_NUM + k];
-                               blkLuma_avg += hist_matrix[blkRow *
-                                       LD_STA_BIN_NUM * stride + blkCol *
-                                       LD_STA_BIN_NUM + k] * k * 32;
-                       }
-                       Tf_blkLuma_avg[FRM_NUM_DBG - 1][tmp] =
-                               ((blkLuma_avg + (blk_sum >> 1)) /
-                               (blk_sum + 1));
-                       Luma_avg += Tf_blkLuma_avg[FRM_NUM_DBG - 1][tmp];
-                       fw_hist_mx = ((Histmx >> 8) * fw_LD_Thist * 2 /
-                               (fw_pic_size >> 8));
-                       /* further debug */
-                       tBL_matrix[tmp] =
-                               ((BLmax * MIN(fw_hist_mx, RGBmax)) >> 10);
-               }
-       }
-
-       if ((Dbprint_lv == 3) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-0: BL_0[%d * %d]:\n ", Vnum, Hnum);
-                       pr_info(
-                       " LD_STA_BIN_NUM=%d, rgb_base=%ld, frm_rgbmax=%d [\n ",
-                               LD_STA_BIN_NUM,
-                               rgb_base,
-                               frm_rgbmax);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       tBL_matrix[blkRow*Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       /*To solve black/white woman flicker*/
-       lmh_avg = (Luma_avg / (Vnum * Hnum));
-       Tf_luma_avg_frm[FRM_NUM_DBG - 1] = lmh_avg;
-
-       /* Spatial Filter the BackLits */
-       sum = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       maxNB = 0;
-                       for (m =  -1; m < 2; m++) {
-                               for (n =  -1; n < 2; n++) {
-                                       if ((m == 0) && (n == 0)) {
-                                               curNB = tBL_matrix[tmp];
-                                       } else if (((blkRow + m) >= 0) &&
-                                               ((blkRow + m) < Vnum) &&
-                                               ((blkCol + n) >= 0) &&
-                                               ((blkCol+n) < Hnum)) {
-                                               maxNB = MAX(maxNB,
-                                               tBL_matrix[(blkRow + m) * Hnum
-                                                       + blkCol + n]);
-                                       }
-                               }
-                       }
-                       /* SF matrix */
-                       if (Sf_bypass == 1) {
-                               FDat1->SF_BL_matrix[tmp] = tBL_matrix[tmp];
-                       } else {
-                               FDat1->SF_BL_matrix[tmp] =
-                                       MAX(curNB, (maxNB - fw_LD_ThSF));
-                       }
-                       sum += FDat1->SF_BL_matrix[tmp];
-                       /* for SF_BL_matrix average calculation */
-               }
-       }
-
-       if ((Dbprint_lv == 4) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-1: BL_SF:\n ");
-                       pr_info("Sf_bypass=%d, fw_LD_ThSF=%d, sum=%ld [\n ",
-                               Sf_bypass,
-                               fw_LD_ThSF,
-                               sum);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                               FDat1->SF_BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(" ;\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       /*side black bar detect*/
-       avg = sum / fw_blk_num;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       dif = avg - (FDat1->SF_BL_matrix[tmp]);
-                       dif = ABS(dif);
-
-                       if ((blkCol == 0) &&
-                               (dif > bbd_th) &&
-                               bbd_detect_en) {
-                               /*1-0*/
-                               side_blk_diff =
-                                       FDat1->SF_BL_matrix[tmp + 1] -
-                                       FDat1->SF_BL_matrix[tmp];
-                               if (side_blk_diff > side_blk_diff_th) {
-                                       FDat1->SF_BL_matrix[tmp] =
-                                               FDat1->SF_BL_matrix[tmp + 1] -
-                                               side_blk_diff_th; /*8-9*/
-                               }
-                       }
-                       if ((blkCol == (Hnum - 1)) &&
-                               (dif > bbd_th) &&
-                               bbd_detect_en) {
-                               side_blk_diff = FDat1->SF_BL_matrix[tmp - 1] -
-                                       FDat1->SF_BL_matrix[tmp];
-                               if (side_blk_diff > side_blk_diff_th) {
-                                       FDat1->SF_BL_matrix[tmp] =
-                                               FDat1->SF_BL_matrix[tmp - 1] -
-                                               side_blk_diff_th;
-                               }
-                       }
-               }
-       }
-
-       if ((Dbprint_lv == 13) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-2.5: BL_SF_bbd:\n ");
-                       pr_info(
-                       " bbd_detect_en=%d, bbd_th=%d, side_blk_diff=%d,avg=%d\n ",
-                               bbd_detect_en,
-                               bbd_th,
-                               side_blk_diff,
-                               avg);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info(" ];\n ");
-               }
-       }
-
-       /* boost the bright region lights a little bit. */
-       avg = ((sum * 7 / fw_blk_num) >> 3);
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       dif = (FDat1->SF_BL_matrix[tmp] - avg);
-
-                       FDat1->SF_BL_matrix[tmp] += 0;
-                       if (Boost_light_bypass == 0) {
-                               FDat1->SF_BL_matrix[tmp] =
-                                       (FDat1->SF_BL_matrix[tmp] *
-                                       boost_gain + 64) >> 7;
-                       }
-                       if (FDat1->SF_BL_matrix[tmp] > 4095)
-                               FDat1->SF_BL_matrix[tmp] = 4095;
-               }
-       }
-
-       if ((Dbprint_lv == 5) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-2: BL_SF_boost:\n ");
-                       pr_info(
-                       " Boost_light_bypass=%d, boost_gain=%ld, avg=%d [\n ",
-                               Boost_light_bypass,
-                               boost_gain,
-                               avg);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info(" ];\n ");
-               }
-       }
-
-       SF_sum = 0;
-       TF_sum = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       SF_sum += FDat1->SF_BL_matrix[blkRow * Hnum + blkCol];
-                       TF_sum += FDat1->TF_BL_matrix[blkRow * Hnum + blkCol];
-               }
-       }
-
-       /* LPF  Only for Xiaomi 8 Led ,here Vnum = 1;*/
-       Bmin = 4096; Bmax_lpf = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       sum = 0;
-                       if (LPF_method == 0) {/* 5*5 lpf_res=1024/25=41 */
-                               for (m = -2; m < 3; m++) {
-                                       for (n = -2; n < 3; n++) {
-                                               /* be careful here */
-                                               mm = MIN(MAX(blkRow + m, 0),
-                                                       Vnum-1);
-                                               nn = MIN(MAX(blkCol + n, 0),
-                                                       Hnum-1);
-                                               num = MIN(MAX((mm * Hnum + nn),
-                                                       0), (Vnum * Hnum - 1));
-                                               sum += FDat1->SF_BL_matrix[num];
-                                       }
-                               }
-                       } else if (LPF_method == 1) {/*3*3,lpf_res=1024/9=114*/
-                               for (m = -1; m < 2; m++) {
-                                       for (n = -1; n < 2; n++) {
-                                               /* be careful here */
-                                               mm = MIN(MAX(blkRow + m, 0),
-                                                       Vnum-1);
-                                               nn = MIN(MAX(blkCol + n, 0),
-                                                       Hnum-1);
-                                               num = MIN(MAX((mm * Hnum + nn),
-                                                       0),
-                                                       (Vnum * Hnum - 1));
-                                               sum += FDat1->SF_BL_matrix[num];
-                                       }
-                               }
-                       } else if (LPF_method == 2) {/*7*7,lpf_res=1024/49=21*/
-                               for (m = -3; m < 4; m++) {
-                                       for (n = -3; n < 4; n++) {
-                                               /* be careful here */
-                                               mm = MIN(MAX(blkRow + m, 0),
-                                                       Vnum-1);
-                                               nn = MIN(MAX(blkCol + n, 0),
-                                                       Hnum-1);
-                                               num = MIN(MAX((mm * Hnum + nn),
-                                                       0),
-                                                       (Vnum * Hnum - 1));
-                                               sum += FDat1->SF_BL_matrix[num];
-                                       }
-                               }
-                       } else if (LPF_method == 3) {/*9*9,lpf_res=1024/81=13*/
-                               for (m = -4; m < 5; m++) {
-                                       for (n = -4; n < 5; n++) {
-                                               /* be careful here */
-                                               mm = MIN(MAX(blkRow + m, 0),
-                                                       Vnum-1);
-                                               nn = MIN(MAX(blkCol + n, 0),
-                                                       Hnum-1);
-                                               num = MIN(MAX((mm * Hnum + nn),
-                                                       0),
-                                                       (Vnum * Hnum - 1));
-                                               sum += FDat1->SF_BL_matrix[num];
-                                       }
-                               }
-                       }
-
-                       if (Lpf_bypass == 0) {
-                               FDat1->SF_BL_matrix[tmp] =
-                               (((sum * lpf_res >> 10) * lpf_gain) >> 7);
-                       }
-
-                       /*check if sum overflow*/
-                       if (Dbprint_lv == 6)
-                               pr_info("step 3.1: sum=%ld:\n ", sum);
-                       tvalue = FDat1->SF_BL_matrix[tmp];
-                       tvalue = (tvalue * ov_gain + 16) >> 4;
-                       min_diff = tvalue - FDat1->SF_BL_matrix[tmp];
-                       Bmin = MIN(Bmin, min_diff);
-
-                       Bmax_lpf = MAX(Bmax_lpf,
-                               Tf_bl_matrix[FRM_NUM_DBG-2][tmp]);
-
-                       if (FDat1->SF_BL_matrix[tmp] > 4095)
-                               FDat1->SF_BL_matrix[tmp] = 4095;
-               }
-       }
-
-       if ((Dbprint_lv == 6) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step 3.1: BL_SF_lpf:\n ");
-                       pr_info(" LPF_method=%d, Lpf_bypass=%d, lpf_res=%ld, lpf_gain=%ld\n",
-                               LPF_method,
-                               Lpf_bypass,
-                               lpf_res,
-                               lpf_gain);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-                       pr_info("Bmax_lpf=%d, Bmin=%d\n ", Bmax_lpf, Bmin);
-               }
-       }
-
-
-       /*hivicast00082*/
-       if (lmh_avg > lmh_avg_TH) {
-               for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                       for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                               tmp = blkRow * Hnum + blkCol;
-                               tdiff = max_luma - FDat1->SF_BL_matrix[tmp];
-                               mx_diff = MAX(tdiff, 0);
-
-                               FDat1->SF_BL_matrix[tmp] =
-                                       FDat1->SF_BL_matrix[tmp] +
-                                       ((mx_diff + 1) >> 1);
-                       }
-               }
-       }
-       if ((Dbprint_lv == 7) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-3.2:BL_SF(hivicast00082:\n ");
-                       pr_info(" max_luma=%d, mx_diff=%d,lmh_avg_TH=%d\n ",
-                               max_luma,
-                               mx_diff,
-                               lmh_avg_TH);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       FDat1->SF_BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       /* Temperary filter */
-       sum = 0; Bmin = 4096; Bmax = 0;
-       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                       tmp = blkRow * Hnum + blkCol;
-                       /* Optimization needed here */
-                       dif_r = FDat1->last_STA1_MaxRGB[blkRow * 3 * stride
-                               + blkCol * 3] - max_matrix[blkRow * 3 * stride
-                               + blkCol * 3];
-                       dif_r = ABS(dif_r);
-                       dif_g = FDat1->last_STA1_MaxRGB[blkRow * 3 * stride
-                               + blkCol * 3 + 1] - max_matrix[blkRow * 3
-                               * stride + blkCol * 3 + 1];
-                       dif_g = ABS(dif_g);
-                       dif_b = FDat1->last_STA1_MaxRGB[blkRow * 3 * stride
-                               + blkCol * 3 + 2] - max_matrix[blkRow * 3
-                               * stride + blkCol * 3 + 2];
-                       dif_b = ABS(dif_b);
-                       adpt_alp = (FDat1->SF_BL_matrix[tmp]) -
-                               (FDat1->TF_BL_matrix[tmp]);
-                       adpt_alp = ABS(adpt_alp);
-
-                       dif_sum = SF_sum - TF_sum;
-                       dif_sum = ABS(dif_sum);
-                       /*note: T968&T960 only use current BL_matrix:
-                        *TF_alpha =256,fw_LD_ThTF=256
-                        *20180612
-                        */
-                       /*note: manual set TF_alpha no useful anymore*/
-                       TF_alpha = 1 << TF_FRESH_BL;
-                       if (dif_sum > fw_rgb_diff_th) /* 32760 */
-                               alpha = TF_alpha; /* 256 */
-                       else
-                               alpha = MIN(TF_alpha, fw_LD_ThTF);
-                       bl_valuex128 = 0;
-
-                       FDat1->TF_BL_alpha[tmp] = alpha;
-
-                       /*4.1: TF: get the temporary filtered BL_value */
-                       bl_value = (((TF_alpha - alpha) *
-                               (FDat1->TF_BL_matrix[tmp]) +
-                               alpha * (FDat1->SF_BL_matrix[tmp]) +
-                               (TF_alpha >> 1)) >> TF_FRESH_BL);
-                               /*2^8 = TF_alpha*/
-                       if (bl_value > 4095)
-                               bl_value = 4095;
-                       /* for debug */
-                       TF_bl_matrix_t[tmp] = bl_value;
-
-                       /*4.2: remap: ld_curve map*/
-                       int_x = bl_value >> 8;
-                       rmd_x = bl_value % 256;
-                       norm  = 256;
-                       if (int_x == 0)
-                               left = 0;
-                       else
-                               left = bl_remap_curve[int_x - 1];
-
-                       right = bl_remap_curve[int_x];
-
-                       if (Ld_remap_bypass == 1) {
-                               bl_value_map = bl_value;
-                       } else {
-                               bl_value_map = left +
-                                       (((right-left) * rmd_x + 128) >> 8);
-                       }
-                       bl_value_map = (bl_value_map > 4095) ? 4095 :
-                               bl_value_map;
-
-                       Tf_bl_matrix_map[tmp] = bl_value_map;
-
-                       /*4.3 tiir optimize */
-                       diff_frm_luma = Tf_luma_avg_frm[FRM_NUM_DBG - 1] -
-                               Tf_luma_avg_frm[FRM_NUM_DBG - 2];
-                       diff_frm_luma = ABS(diff_frm_luma);
-                       Tf_diff_frm_luma[FRM_NUM_DBG - 1] = diff_frm_luma;
-                       if (Tf_luma_avg_frm[FRM_NUM_DBG - 1] <= 1) {
-                               /* Tf_bl_matrix[FRM_NUM_DBG - 2][tmp] =
-                                *      Bmax_lpf>>1;
-                                */
-                               Tf_bl_matrix[FRM_NUM_DBG - 2][tmp] =
-                                       Tf_bl_matrix[FRM_NUM_DBG - 2][tmp];
-                               /* do nothing. need to optimise */
-                       }
-                       if (diff_frm_luma < 10) {/*same video scene*/
-                               diff_blk_luma =
-                                       Tf_blkLuma_avg[FRM_NUM_DBG - 1][tmp] -
-                                       Tf_blkLuma_avg[FRM_NUM_DBG - 2][tmp];
-                               diff_blk_matrix = bl_value_map -
-                                       Tf_bl_matrix[FRM_NUM_DBG-2][tmp];
-                               diff_blk_matrix = ABS(diff_blk_matrix);
-                               Tf_diff_blk_luma[FRM_NUM_DBG - 1][tmp] =
-                                       diff_blk_matrix;
-
-                               /*Debug print local value*/
-                               if (Dbprint_lv == 200) {
-                                       if ((db_cnt % 4) == 0) {
-                                               /*4 frames print once*/
-                                               pr_info(
-                                               "##4.3_tiir-1: diff_frm_luma <10\n"
-                                               "diff_blk_matrix[%4d]\n"
-                                               "bl_value_map[%4d]\n"
-                                               "Tf_bl_matrix[%4d]\n",
-                                               diff_blk_matrix,
-                                               bl_value_map,
-                                               Tf_bl_matrix[FRM_NUM_DBG - 2]
-                                                       [tmp]);
-                                       }
-                               }
-                               if ((diff_blk_matrix > 50) &&
-                                       (diff_blk_luma_en)) {
-                                       if (bl_value_map >=
-                                       Tf_bl_matrix[FRM_NUM_DBG-2][tmp]) {
-                                               bl_value_map =
-                                               Tf_bl_matrix[FRM_NUM_DBG-2]
-                                                       [tmp] +
-                                               ((diff_blk_matrix + 16) >> 5);
-                                       } else { /* any difference ? */
-                                               bl_value_map =
-                                               Tf_bl_matrix[FRM_NUM_DBG-2]
-                                                       [tmp] -
-                                               ((diff_blk_matrix + 16) >> 5);
-                                       }
-                                       if (Dbprint_lv == 2) {
-                                               /* just for confirm */
-                                               pr_info("##--2: diff_blk_matrix >50\n");
-                                       }
-
-                                       if ((Dbprint_lv == 200) &&
-                                               ((db_cnt % 4) == 0)) {
-                                               /*4 frames print once*/
-                                               pr_info(
-                                               "##4.3_tiir-2: diff_blk_matrix > 50\n"
-                                               "bl_value_map= [%4d]\n"
-                                               "blkRow * Hnum + blkCol = %d(cnt)\n"
-                                               "Tf_bl_matrix[FRM_NUM_DBG-1][cnt])= [%4d]\n"
-                                               "Tf_bl_matrix[FRM_NUM_DBG-2][cnt])= [%4d]\n"
-                                               "Tf_bl_matrix[FRM_NUM_DBG-3][cnt])= [%4d]\n"
-                                               "Tf_bl_matrix[FRM_NUM_DBG-4][cnt])= [%4d]\n"
-                                               "Tf_bl_matrix[FRM_NUM_DBG-5][cnt])= [%4d]\n",
-                                               bl_value_map,
-                                               tmp,
-                                               Tf_bl_matrix[FRM_NUM_DBG - 1]
-                                                       [tmp],
-                                               Tf_bl_matrix[FRM_NUM_DBG - 2]
-                                                       [tmp],
-                                               Tf_bl_matrix[FRM_NUM_DBG - 3]
-                                                       [tmp],
-                                               Tf_bl_matrix[FRM_NUM_DBG - 4]
-                                                       [tmp],
-                                               Tf_bl_matrix[FRM_NUM_DBG - 5]
-                                                       [tmp]);
-                                       }
-                               } else
-                                       bl_value_map = bl_value_map;
-
-                               if (bl_value_map > 4095)
-                                       bl_value_map = 4095;
-                               if (bl_value_map <= 0)
-                                       bl_value_map = 0;
-                       }
-
-                       /* for debug */
-                       TF_bl_matrix_t3[tmp] = bl_value_map;
-
-                       /*4.4 patch for fast luma change.20180621*/
-                       diff_frm_luma = Tf_luma_avg_frm[FRM_NUM_DBG - 1] -
-                               Tf_luma_avg_frm[FRM_NUM_DBG - 2];/*0~512*/
-                       /*current*/
-                       Tf_diff_frm_luma[FRM_NUM_DBG - 1] = diff_frm_luma;
-                       Tf_diff_frm_luma_tf_avg =
-                               (Tf_diff_frm_luma[FRM_NUM_DBG - 1] +
-                               Tf_diff_frm_luma[FRM_NUM_DBG - 2] +
-                               Tf_diff_frm_luma[FRM_NUM_DBG - 3] +
-                               Tf_diff_frm_luma[FRM_NUM_DBG - 4]) * 2;
-                       /*(/4*8,12bit)4 frames avg. note: FRM_NUM_DBG >=4*/
-
-                       diff_blk_matrix = bl_value_map -
-                               Tf_bl_matrix[FRM_NUM_DBG-2][tmp];
-                       diff_blk_matrix_tf_avg =
-                               (Tf_diff_blk_luma[FRM_NUM_DBG - 2][tmp] +
-                               Tf_diff_blk_luma[FRM_NUM_DBG - 3][tmp] +
-                               Tf_diff_blk_luma[FRM_NUM_DBG - 4][tmp] +
-                               Tf_diff_blk_luma[FRM_NUM_DBG - 5][tmp]) >> 2;
-                       /*make sure FRM_NUM_DBG > 5 */
-
-                       if ((dif_sum < fw_rgb_diff_th) &&
-                               (ABS(diff_frm_luma*8) > LD_TF_STEP_TH)) {
-
-                               if (TF_step_method == 1) {
-                                       step = diff_frm_luma * 8;/*12bit*/
-                               /* dark --> bright, limit increase step,u12*/
-                                       if (step > LD_TF_STEP_TH)
-                                               step = LD_TF_STEP_TH;/*12bit*/
-                               /*bright --> dark, limit decrease step,u12*/
-                                       else if (step < (-LD_TF_STEP_TH))
-                                               step = -(LD_TF_STEP_TH);
-                                       bl_value_map =
-                                       (FDat1->TF_BL_matrix[tmp]) + step;
-                               } else if (TF_step_method == 2) {
-                                       step =
-                                       (Tf_diff_frm_luma[FRM_NUM_DBG - 1] +
-                                       Tf_diff_frm_luma[FRM_NUM_DBG - 2] +
-                                       Tf_diff_frm_luma[FRM_NUM_DBG - 3] +
-                                       Tf_diff_frm_luma[FRM_NUM_DBG - 4]) * 2;
-                       /*(/4*8,12bit)4 frames avg. note: FRM_NUM_DBG >=4*/
-
-                               /* dark --> bright, limit increase step,u12*/
-                                       if (step > LD_TF_STEP_TH)
-                                               step = LD_TF_STEP_TH ;/*12bit*/
-                               /*bright --> dark, limit decrease step,u12*/
-                                       else if (step < (-LD_TF_STEP_TH))
-                                               step = -(LD_TF_STEP_TH);
-
-                                       bl_value_map =
-                                       (FDat1->TF_BL_matrix[tmp]) + step;
-                               } else if (TF_step_method == 3) {
-                                       diff_blk_matrix = bl_value_map -
-                                       Tf_bl_matrix[FRM_NUM_DBG-2][tmp];
-
-                                       if (diff_blk_matrix > 0) {
-                                               bl_value_map =
-                                               Tf_bl_matrix[FRM_NUM_DBG-2][tmp]
-                                               + ((diff_blk_matrix +
-                                               (1 << (TF_BLK_FRESH_BL-1))) >>
-                                                       TF_BLK_FRESH_BL);
-                                       } else {
-                                               bl_value_map =
-                                               Tf_bl_matrix[FRM_NUM_DBG-2][tmp]
-                                               - ((ABS(diff_blk_matrix) +
-                                               (1 << (TF_BLK_FRESH_BL-1))) >>
-                                                       TF_BLK_FRESH_BL);
-                                       }
-                               } else
-                                       bl_value_map = bl_value_map;
-                       }
-
-                       if (Dbprint_lv == 100 && pr_flag) {
-                               pr_info("new TF filter:row[%d],col[%d]:dif_sum=%d(th(%d))\n",
-                                       blkRow, blkCol, dif_sum,
-                                       fw_rgb_diff_th);
-                               pr_info("diff_frm_luma:%4d,step:%4d, LD_TF_STEP_TH:%4d (pre_bl[%4d] => bl[%4d])\n\n",
-                                       diff_frm_luma,
-                                       step, LD_TF_STEP_TH,
-                                       (FDat1->TF_BL_matrix[tmp]),
-                                       bl_value_map);
-                       }
-
-                       if (Dbprint_lv == 100 && pr_flag &&
-                               (TF_step_method == 3)) {
-                               pr_info("new TF filter:row[%d],col[%d]:dif_sum=%d(th(%d))\n",
-                                       blkRow, blkCol, dif_sum,
-                                       fw_rgb_diff_th);
-                               pr_info("diff_frm_luma:%4d,diff_blk_matrix:%4d, TF_BLK_FRESH_BL:%4d (pre_bl[%4d] => bl[%4d])\n\n",
-                                       diff_frm_luma,
-                                       diff_blk_matrix, TF_BLK_FRESH_BL,
-                                       Tf_bl_matrix[FRM_NUM_DBG-2][tmp],
-                                       bl_value_map);
-                       }
-
-                       /* debug */
-                       TF_bl_matrix_t2[tmp] = bl_value_map;
-
-                       remap_value = bl_value_map;
-                       if (remap_value > 4095)
-                               remap_value = 4095;
-                       if (nPRM1->reg_LD_BackLit_mode == 1) {
-                               nPRM1->BL_matrix[blkCol * Vnum + blkRow] =
-                                       bl_value_map;
-                               Map_bl_matrix[blkCol * Vnum + blkRow] =
-                                       remap_value;
-                       } else {
-                               nPRM1->BL_matrix[tmp] = bl_value_map;
-                               Map_bl_matrix[tmp] = remap_value;
-                       }
-
-                       /* Get the TF_BL_matrix */
-                       FDat1->TF_BL_matrix[tmp] = bl_value_map;
-                       Tf_bl_matrix[FRM_NUM_DBG-1][tmp] = bl_value_map;
-
-                       /* leave the Delayed version for next frame */
-                       for (k = 0; k < 3; k++) {
-                               FDat1->last_STA1_MaxRGB[blkRow * 3 * stride +
-                                       blkCol * 3 + k] =
-                                               max_matrix[blkRow * 3 * stride +
-                                               blkCol * 3 + k];
-                       }
-                       /* get the sum/min/max */
-                       sum += bl_value_map;
-                       Bmin = MIN(Bmin, bl_value_map);
-                       Bmax = MAX(Bmax, bl_value_map);
-               }
-       }
-
-       if ((Dbprint_lv == 8) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-4.1: BL_TF: [\n ");
-                       pr_info("alpha =%d, dif_sum =%d\n ", alpha, dif_sum);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       TF_bl_matrix_t[blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n");
-               }
-       }
-
-       if ((Dbprint_lv == 9) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-4.2: BL_remap: [\n ");
-                       pr_info("Ld_remap_bypass =%d\n ", Ld_remap_bypass);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       Tf_bl_matrix_map[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       if ((Dbprint_lv == 10) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-4.3: BL_remap_patch_old: [\n ");
-                       pr_info(" diff_frm_luma=%d,\n ", diff_frm_luma);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       TF_bl_matrix_t3[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       if ((Dbprint_lv == 11) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step-4.4: BL_remap_patch_new: [\n ");
-                       pr_info(" diff_frm_luma=%d, dif_sum=%d, LD_TF_STEP_TH=%d, TF_step_method=%d\n ",
-                               diff_frm_luma,
-                               dif_sum,
-                               LD_TF_STEP_TH,
-                               TF_step_method);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                               TF_bl_matrix_t2
-                                               [blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-       if ((Dbprint_lv == 12) || (Dbprint_lv == 1024)) {
-               if (pr_flag) {
-                       pr_info("step 5: BL_TF_optimise(final BL_matrix):\n ");
-                       pr_info("frm_print_cnt = %d, diff_frm_luma =%d, diff_blk_matrix =%d\n ",
-                               fw_print_frequent,
-                               diff_frm_luma,
-                               diff_blk_matrix);
-                       for (blkRow = 0; blkRow < Vnum; blkRow++) {
-                               for (blkCol = 0; blkCol < Hnum; blkCol++) {
-                                       pr_info("(%4d)\n",
-                                       nPRM1->BL_matrix[
-                                               blkRow * Hnum + blkCol]);
-                               }
-                               pr_info(";\n ");
-                       }
-                       pr_info("];\n ");
-               }
-       }
-
-       db_cnt++;
-       if (db_cnt > 4095)
-               db_cnt = 0;
-
-       frm_cnt++;
-       if (frm_cnt > 4095)
-               frm_cnt = 0;
-
-       /* set the DC reduction for the BL_modeling */
-       if (fw_LD_BLEst_ACmode == 0)
-               nPRM1->reg_BL_matrix_AVG = 0;
-       else if (fw_LD_BLEst_ACmode == 1) {
-               /*nPRM->reg_BL_matrix_AVG = (sum/fw_blk_num);*/
-               nPRM1->reg_BL_matrix_AVG = ((sum / fw_blk_num) *
-                       avg_gain + 2048) >> 12;
-               Map_bl_matrix_AVG = ((sum / fw_blk_num) *
-                       avg_gain + 2048) >> 12;
-               Map_bl_matrix_Compensate = ((sum / fw_blk_num) *
-                       avg_gain + 2048) >> 12;
-       } else if (fw_LD_BLEst_ACmode == 2)
-               nPRM1->reg_BL_matrix_AVG = Bmin;
-       else if (fw_LD_BLEst_ACmode == 3)
-               nPRM1->reg_BL_matrix_AVG = Bmax;
-       else if (fw_LD_BLEst_ACmode == 4)
-               nPRM1->reg_BL_matrix_AVG = 2048;
-       else
-               nPRM1->reg_BL_matrix_AVG = 1024;
-
-       nPRM1->reg_BL_matrix_Compensate = nPRM1->reg_BL_matrix_AVG;
-
-       /*black_display statue */
-       if (Hnum == 10) {
-               if (frm_rgbmax < 10) {
-                       black_time_cnt++;
-                       if (black_time_cnt > 120)
-                               black_frm = 1;
-               } else {
-                       black_time_cnt = 0;
-                       black_frm = 0;
-                       ldim_level_update = 1;
-               }
-       } else {
-               if (frm_rgbmax < 10) {
-                       black_frm = 1;
-               } else {
-                       black_frm = 0;
-                       ldim_level_update = 1;
-               }
-       }
-       /*note: black_frm should co-work with brightness controlling(spi)*/
-}
-#endif
-
-void LDIM_WR_BASE_LUT_DRT(int base, int *pData, int len)
-{
-       int i;
-       int addr;
-
-       addr  = base;/*(base<<4)*/
-#ifdef CONFIG_VSYNC_RDMA
-       VSYNC_WR_MPEG_REG(LDIM_BL_ADDR_PORT, addr);
-       for (i = 0; i < len; i++)
-               VSYNC_WR_MPEG_REG(LDIM_BL_DATA_PORT, pData[i]);
-#else
-       Wr(LDIM_BL_ADDR_PORT, addr);
-       for (i = 0; i < len; i++)
-               Wr(LDIM_BL_DATA_PORT, pData[i]);
-#endif
-}
-
-static void ldim_stts_initial(unsigned int pic_h, unsigned int pic_v,
-               unsigned int BLK_Vnum, unsigned int BLK_Hnum)
-{
-       unsigned int resolution, resolution_region, blk_height, blk_width;
-       unsigned int row_start, col_start;
-       struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
-
-       BLK_Vnum = (BLK_Vnum == 0) ? 1 : BLK_Vnum;
-       BLK_Hnum = (BLK_Hnum == 0) ? 1 : BLK_Hnum;
-       LDIMPR("%s: %d %d %d %d\n", __func__, pic_h, pic_v, BLK_Vnum, BLK_Hnum);
-
-       resolution = (((pic_h - 1) & 0xffff) << 16) | ((pic_v - 1) & 0xffff);
-       /*Wr(VDIN0_HIST_CTRL, 0x10d);*/
-
-       switch (bl_drv->data->chip_type) {
-       case BL_CHIP_TXLX:
-               Wr(LDIM_STTS_CTRL0, 7 << 2);
-               ldim_set_matrix_ycbcr2rgb();
-               ldim_stts_en(resolution, 0, 0, 1, 1, 1, 0);
-               break;
-       case BL_CHIP_GXTVBB:
-               Wr(LDIM_STTS_CTRL0, 3<<3);/*4 mux to vpp_dout*/
-               ldim_set_matrix_ycbcr2rgb();
-               /*ldim_set_matrix_rgb2ycbcr(0);*/
-               ldim_stts_en(resolution, 0, 0, 1, 1, 1, 0);
-               break;
-       default:
-               break;
+       resolution = (((pic_h - 1) & 0xffff) << 16) | ((pic_v - 1) & 0xffff);
+       /*Wr_reg(VDIN0_HIST_CTRL, 0x10d);*/
+
+       switch (bl_drv->data->chip_type) {
+       case BL_CHIP_TXLX:
+               Wr_reg(LDIM_STTS_CTRL0, 7 << 2);
+               ldim_set_matrix_ycbcr2rgb();
+               ldim_stts_en(resolution, 0, 0, 1, 1, 1, 0);
+               break;
+       case BL_CHIP_GXTVBB:
+               Wr_reg(LDIM_STTS_CTRL0, 3 << 3);/*4 mux to vpp_dout*/
+               ldim_set_matrix_ycbcr2rgb();
+               /*ldim_set_matrix_rgb2ycbcr(0);*/
+               ldim_stts_en(resolution, 0, 0, 1, 1, 1, 0);
+               break;
+       default:
+               break;
        }
 
        resolution_region = 0;
@@ -1680,174 +367,6 @@ static void ldim_stts_initial(unsigned int pic_h, unsigned int pic_v,
                row_start, col_start, BLK_Hnum);
 }
 
-static void ldim_db_para_print(struct LDReg *mLDReg)
-{
-       int i, len;
-       char *buf;
-
-       len = 32 * 10 + 10;
-       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
-       if (buf == NULL) {
-               LDIMERR("print buf malloc error\n");
-               return;
-       }
-
-       LDIMPR("rgb_base = %ld\n"
-               "boost_gain = %ld\n"
-               "lpf_res = %ld\n"
-               "fw_LD_ThSF = %ld\n\n",
-               rgb_base,
-               boost_gain,
-               lpf_res,
-               fw_LD_ThSF_l);
-
-       LDIMPR("ld_vgain = %d\n"
-               "ld_hgain = %d\n"
-               "ld_litgain = %d\n\n",
-               mLDReg->reg_LD_Vgain,
-               mLDReg->reg_LD_Hgain,
-               mLDReg->reg_LD_Litgain);
-
-       LDIMPR("ld_lut_vdg_lext = %d\n"
-               "ld_lut_hdg_lext = %d\n"
-               "ld_lut_vhk_lext = %d\n\n",
-               mLDReg->reg_LD_LUT_Vdg_LEXT,
-               mLDReg->reg_LD_LUT_Hdg_LEXT,
-               mLDReg->reg_LD_LUT_VHk_LEXT);
-
-       len = 0;
-       LDIMPR("ld_lut_hdg:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_Hdg[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vdg:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_Vdg[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vhk:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_VHk[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vhk_pos:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_VHk_pos[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vhk_neg:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_VHk_neg[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_hhk:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_HHk[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vho_pos:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_VHo_pos[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       len = 0;
-       LDIMPR("ld_lut_vho_neg:\n");
-       for (i = 0; i < 32; i++) {
-               len += sprintf(buf+len, "\t%d",
-                       mLDReg->reg_LD_LUT_VHo_neg[i]);
-               if (i % 8 == 7)
-                       len += sprintf(buf+len, "\n");
-       }
-       pr_info("%s\n", buf);
-
-       kfree(buf);
-}
-
-static void ldim_db_load_update(struct LDReg *mLDReg)
-{
-       int i;
-
-       if (LDIM_DATA_FROM_DB == 1) {
-               LDIMPR("ldim_db_load_update\n");
-               /* beam model */
-               rgb_base = (unsigned long)ldim_db_para.rgb_base;
-               boost_gain = (unsigned long)ldim_db_para.boost_gain;
-               lpf_res = (unsigned long)ldim_db_para.lpf_res;
-               fw_LD_ThSF_l = (unsigned long)ldim_db_para.fw_ld_th_sf;
-
-               /* beam curve */
-               mLDReg->reg_LD_Vgain = ldim_db_para.ld_vgain;
-               mLDReg->reg_LD_Hgain = ldim_db_para.ld_hgain;
-               mLDReg->reg_LD_Litgain = ldim_db_para.ld_litgain;
-
-               mLDReg->reg_LD_LUT_Vdg_LEXT = ldim_db_para.ld_lut_vdg_lext;
-               mLDReg->reg_LD_LUT_Hdg_LEXT = ldim_db_para.ld_lut_hdg_lext;
-               mLDReg->reg_LD_LUT_VHk_LEXT = ldim_db_para.ld_lut_vhk_lext;
-
-               for (i = 0; i < 32; i++) {
-                       mLDReg->reg_LD_LUT_Hdg[i] = ldim_db_para.ld_lut_hdg[i];
-                       mLDReg->reg_LD_LUT_Vdg[i] = ldim_db_para.ld_lut_vdg[i];
-                       mLDReg->reg_LD_LUT_VHk[i] = ldim_db_para.ld_lut_vhk[i];
-               }
-
-               /* beam shape minor adjustment */
-               for (i = 0; i < 32; i++) {
-                       mLDReg->reg_LD_LUT_VHk_pos[i] =
-                               ldim_db_para.ld_lut_vhk_pos[i];
-                       mLDReg->reg_LD_LUT_VHk_neg[i] =
-                               ldim_db_para.ld_lut_vhk_neg[i];
-                       mLDReg->reg_LD_LUT_HHk[i] =
-                               ldim_db_para.ld_lut_hhk[i];
-                       mLDReg->reg_LD_LUT_VHo_pos[i] =
-                               ldim_db_para.ld_lut_vho_pos[i];
-                       mLDReg->reg_LD_LUT_VHo_neg[i] =
-                               ldim_db_para.ld_lut_vho_neg[i];
-               }
-
-               /* remapping */
-               /*ldim_db_para.lit_idx_th;*/
-               /*ldim_db_para.comp_gain;*/
-       }
-
-       if (db_print_flag == 1)
-               ldim_db_para_print(mLDReg);
-}
-
 static void LDIM_Initial_GXTVBB(unsigned int ldim_bl_en,
                unsigned int ldim_hvcnt_bypass)
 {
@@ -2184,231 +703,132 @@ static void LDIM_Initial_TXLX(unsigned int ldim_bl_en,
 
        /*reg_LD_LUT_VHk[8][32]: u10*8*32*/
        LDIM_WR_BASE_LUT(REG_LD_LUT_VHK_BASE_TXLX,
-               nPRM.reg_LD_LUT_VHk_TXLX[0], 16, 8*32);
-
-       /*reg_LD_LUT_Id[16][24]: u3*16*24=u3*384 */
-       LDIM_WR_BASE_LUT(REG_LD_LUT_ID_BASE_TXLX, nPRM.reg_LD_LUT_Id, 4, 384);
-
-       /*enable the CBUS configure the RAM*/
-       /*LD_MISC_CTRL0  {reg_blmat_ram_mode,
-        *1'h0,ram_bus_sel,ram_clk_sel,ram_clk_gate_en,
-        *2'h0,reg_hvcnt_bypass,reg_demo_synmode,reg_ldbl_synmode,
-        *reg_ldim_bl_en,soft_bl_start,reg_soft_rst)
-        */
-       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
-       data = (data & (~(3 << 9))) | (1 << 8);
-       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
-
-       /*X_lut[3][16][16]*/
-       LDIM_WR_BASE_LUT_DRT(REG_LD_RGB_LUT_BASE, nPRM.X_lut2[0][0], 3*16*16);
-       data = 0 | (0 << 1) | ((ldim_bl_en & 0x1) << 2) |
-               (ldim_hvcnt_bypass << 5) | (1 << 8) |
-               (3 << 9) | (1 << 12);
-       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
-
-       LDIM_Update_Matrix(nPRM.BL_matrix, 16 * 24);
-
-       kfree(arrayTmp);
-}
-
-static void LDIM_Initial(unsigned int pic_h, unsigned int pic_v,
-               unsigned int BLK_Vnum, unsigned int BLK_Hnum,
-               unsigned int BackLit_mode, unsigned int ldim_bl_en,
-               unsigned int ldim_hvcnt_bypass)
-{
-       struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
-
-       LDIMPR("%s: %d %d %d %d %d %d %d\n",
-               __func__, pic_h, pic_v, BLK_Vnum, BLK_Hnum,
-               BackLit_mode, ldim_bl_en, ldim_hvcnt_bypass);
-
-       ldim_matrix_update_en = ldim_bl_en;
-       LD_ConLDReg(&nPRM);
-       /* config params begin */
-       /* configuration of the panel parameters */
-       nPRM.reg_LD_pic_RowMax = pic_v;
-       nPRM.reg_LD_pic_ColMax = pic_h;
-       /* Maximum to BLKVMAX  , Maximum to BLKHMAX */
-       nPRM.reg_LD_BLK_Vnum     = BLK_Vnum;
-       nPRM.reg_LD_BLK_Hnum     = BLK_Hnum;
-       nPRM.reg_LD_BackLit_mode = BackLit_mode;
-       /*config params end */
-       ld_fw_cfg_once(&nPRM);
-       ldim_db_load_update(&nPRM);
-
-       switch (bl_drv->data->chip_type) {
-       case BL_CHIP_TXLX:
-               LDIM_Initial_TXLX(ldim_bl_en, ldim_hvcnt_bypass);
-               break;
-       case BL_CHIP_GXTVBB:
-               LDIM_Initial_GXTVBB(ldim_bl_en, ldim_hvcnt_bypass);
-               break;
-       default:
-               break;
-       }
-}
-
-static int ldim_open(struct inode *inode, struct file *file)
-{
-       struct ldim_dev_s *devp;
-       /* Get the per-device structure that contains this cdev */
-       devp = container_of(inode->i_cdev, struct ldim_dev_s, cdev);
-       file->private_data = devp;
-       return 0;
-}
-
-static int ldim_release(struct inode *inode, struct file *file)
-{
-       file->private_data = NULL;
-       return 0;
-}
-
-static long ldim_ioctl(struct file *file, unsigned int cmd,
-                       unsigned long arg)
-{
-       int ret = 0;
-
-       switch (cmd) {
-       /*********local dimming ioctl************/
-       case LDIM_IOC_PARA:
-               if (!LDIM_DATA_FROM_DB)
-                       return -EINVAL;
-
-               if (copy_from_user(&ldim_db_para, (void __user *)arg,
-                       sizeof(struct ldim_param_s)))
-                       ret = -EFAULT;
-               break;
-
-       default:
-               ret = -EINVAL;
-               break;
-       }
-
-       return ret;
-}
-
-#ifdef CONFIG_COMPAT
-static long ldim_compat_ioctl(struct file *file, unsigned int cmd,
-       unsigned long arg)
-{
-       unsigned long ret;
-
-       arg = (unsigned long)compat_ptr(arg);
-       ret = ldim_ioctl(file, cmd, arg);
-       return ret;
-}
-#endif
-
-static const struct file_operations ldim_fops = {
-       .owner          = THIS_MODULE,
-       .open           = ldim_open,
-       .release        = ldim_release,
-       .unlocked_ioctl = ldim_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl = ldim_compat_ioctl,
-#endif
-};
-
-static void ldim_dump_histgram(void)
-{
-       unsigned int i, j, k, len;
-       unsigned int *p = NULL;
-       char *buf;
-
-       p = kcalloc(2048, sizeof(unsigned int), GFP_KERNEL);
-       if (p == NULL) {
-               LDIMERR("ldim_matrix_t malloc error\n");
-               return;
-       }
-
-       len = 16 * 10 + 20;
-       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
-       if (buf == NULL) {
-               LDIMERR("print buf malloc error\n");
-               kfree(p);
-               return;
-       }
-
-       memcpy(p, ldim_driver.hist_matrix,
-               ldim_hist_row*ldim_hist_col*16*sizeof(unsigned int));
+               nPRM.reg_LD_LUT_VHk_TXLX[0], 16, 8*32);
 
-       for (i = 0; i < ldim_hist_row; i++) {
-               pr_info("%s: row %d:\n", __func__, i);
-               for (j = 0; j < ldim_hist_col; j++) {
-                       len = sprintf(buf, "col %d:\n", j);
-                       for (k = 0; k < 16; k++) {
-                               len += sprintf(buf+len, "\t0x%x",
-                                       *(p+i*16*ldim_hist_col+j*16+k));
-                               if (k == 7)
-                                       len += sprintf(buf+len, "\n");
-                       }
-                       pr_info("%s\n\n", buf);
-               }
-               msleep(20);
-       }
+       /*reg_LD_LUT_Id[16][24]: u3*16*24=u3*384 */
+       LDIM_WR_BASE_LUT(REG_LD_LUT_ID_BASE_TXLX, nPRM.reg_LD_LUT_Id, 4, 384);
 
-       kfree(buf);
-       kfree(p);
-}
+       /*enable the CBUS configure the RAM*/
+       /*LD_MISC_CTRL0  {reg_blmat_ram_mode,
+        *1'h0,ram_bus_sel,ram_clk_sel,ram_clk_gate_en,
+        *2'h0,reg_hvcnt_bypass,reg_demo_synmode,reg_ldbl_synmode,
+        *reg_ldim_bl_en,soft_bl_start,reg_soft_rst)
+        */
+       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
+       data = (data & (~(3 << 9))) | (1 << 8);
+       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
 
-static irqreturn_t rdma_ldim_intr(int irq, void *dev_id)
-{
-       ulong flags;
+       /*X_lut[3][16][16]*/
+       LDIM_WR_BASE_LUT_DRT(REG_LD_RGB_LUT_BASE, nPRM.X_lut2[0][0], 3*16*16);
+       data = 0 | (0 << 1) | ((ldim_bl_en & 0x1) << 2) |
+               (ldim_hvcnt_bypass << 5) | (1 << 8) |
+               (3 << 9) | (1 << 12);
+       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
 
-       /*LDIMPR("*********rdma_ldim_intr start*********\n");*/
-       spin_lock_irqsave(&rdma_ldim_isr_lock, flags);
+       LDIM_Update_Matrix(nPRM.BL_matrix, 16 * 24);
 
-       if (ldim_hist_en) {
-               /*schedule_work(&ldim_on_vs_work);*/
-               queue_work(ldim_queue, &ldim_on_vs_work);
-       }
-       rdma_ldim_irq_cnt++;
-       if (rdma_ldim_irq_cnt > 0xfffffff)
-               rdma_ldim_irq_cnt = 0;
-       spin_unlock_irqrestore(&rdma_ldim_isr_lock, flags);
-       /*LDIMPR("*********rdma_ldim_intr end*********\n");*/
-       return IRQ_HANDLED;
+       kfree(arrayTmp);
 }
 
-static irqreturn_t ldim_vsync_isr(int irq, void *dev_id)
+static void LDIM_Initial(unsigned int pic_h, unsigned int pic_v,
+               unsigned int BLK_Vnum, unsigned int BLK_Hnum,
+               unsigned int BackLit_mode, unsigned int ldim_bl_en,
+               unsigned int ldim_hvcnt_bypass)
 {
-       ulong flags;
        struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
 
-       if (ldim_on_flag == 0)
-               return IRQ_HANDLED;
-
-       spin_lock_irqsave(&ldim_isr_lock, flags);
+       LDIMPR("%s: %d %d %d %d %d %d %d\n",
+               __func__, pic_h, pic_v, BLK_Vnum, BLK_Hnum,
+               BackLit_mode, ldim_bl_en, ldim_hvcnt_bypass);
 
-       if (ldim_func_en) {
-               if (ldim_avg_update_en)
-                       ldim_update_setting();
+       ldim_matrix_update_en = ldim_bl_en;
+       LD_ConLDReg(&nPRM);
+       /* config params begin */
+       /* configuration of the panel parameters */
+       nPRM.reg_LD_pic_RowMax = pic_v;
+       nPRM.reg_LD_pic_ColMax = pic_h;
+       /* Maximum to BLKVMAX  , Maximum to BLKHMAX */
+       nPRM.reg_LD_BLK_Vnum     = BLK_Vnum;
+       nPRM.reg_LD_BLK_Hnum     = BLK_Hnum;
+       nPRM.reg_LD_BackLit_mode = BackLit_mode;
+       /*config params end */
+       ld_fw_cfg_once(&nPRM);
+       ldim_db_load_update(&nPRM);
 
-               switch (bl_drv->data->chip_type) {
-               case BL_CHIP_TXLX:
-                       if (ldim_hist_en) {
-                               /*schedule_work(&ldim_on_vs_work);*/
-                               queue_work(ldim_queue, &ldim_on_vs_work);
-                       }
-                       break;
-               case BL_CHIP_GXTVBB:
-                       break;
-               default:
-                       break;
-               }
-       } else {
-               /*schedule_work(&ldim_off_vs_work);*/
-               queue_work(ldim_queue, &ldim_off_vs_work);
+       switch (bl_drv->data->chip_type) {
+       case BL_CHIP_TXLX:
+               LDIM_Initial_TXLX(ldim_bl_en, ldim_hvcnt_bypass);
+               break;
+       case BL_CHIP_GXTVBB:
+               LDIM_Initial_GXTVBB(ldim_bl_en, ldim_hvcnt_bypass);
+               break;
+       default:
+               break;
        }
+}
 
-       ldim_irq_cnt++;
-       if (ldim_irq_cnt > 0xfffffff)
-               ldim_irq_cnt = 0;
+static void ldim_update_matrix(unsigned int mode)
+{
+       unsigned int data;
+       int bl_matrix[8] = {0};
+       unsigned int reg_BL_matrix_Compensate = 0x0;
+       int bl_matrix_1[8] = {0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
+                       0xfff, 0xfff};
+       unsigned int reg_BL_matrix_Compensate_1 = 0xfff;
+       int bl_matrix_2[8] = {0xfff, 0xfff, 0xfff, 0x000, 0x000, 0xfff,
+                       0xfff, 0xfff};
+       unsigned int reg_BL_matrix_Compensate_2 = 0xbff;
+       int bl_matrix_3[8] = {0, 0, 0, 0xfff, 0, 0, 0, 0};
+       unsigned int reg_BL_matrix_Compensate_3 = 0x1ff;
+       int bl_matrix_4[8] = {0xfff, 0xfff, 0xfff, 0, 0xfff, 0xfff,
+                       0xfff, 0xfff};
+       unsigned int reg_BL_matrix_Compensate_4 = 0xdff;
 
-       spin_unlock_irqrestore(&ldim_isr_lock, flags);
-       /*      LDIMPR("***ldim_vsync_isr end****\n");*/
+       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
+       data = data & (~(3<<4));
+       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
 
-       return IRQ_HANDLED;
+       /* gMatrix_LUT: s12*100 ==> max to 8*8 enum ##r/w ram method*/
+       if (mode == 0) {
+               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
+                       &bl_matrix[0], 8);
+               /*  compensate  */
+               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
+               data = data|(reg_BL_matrix_Compensate&0xfff);
+               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       } else if (mode == 1) {
+               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
+                       &bl_matrix_1[0], 8);
+       /*  compensate  */
+               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
+               data = data | (reg_BL_matrix_Compensate_1 & 0xfff);
+               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       } else if (mode == 2) {
+               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
+                       &bl_matrix_2[0], 8);
+       /*  compensate  */
+               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
+               data = data|(reg_BL_matrix_Compensate_2 & 0xfff);
+               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       } else if (mode == 3) {
+               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
+                       &bl_matrix_3[0], 8);
+       /* compensate */
+               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
+               data = data | (reg_BL_matrix_Compensate_3 & 0xfff);
+               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       } else if (mode == 4) {
+               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
+                       &bl_matrix_4[0], 8);
+       /* compensate */
+               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
+               data = data | (reg_BL_matrix_Compensate_4 & 0xfff);
+               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       }
+       /* disable the CBUS configure the RAM */
+       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
+       data = data | (3<<4);
+       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
 }
 
 static void ldim_update_gxtvbb(void)
@@ -2487,70 +907,66 @@ static void ldim_update_setting(void)
        }
 }
 
-static void ldim_update_matrix(unsigned int mode)
+static irqreturn_t rdma_ldim_intr(int irq, void *dev_id)
 {
-       unsigned int data;
-       int bl_matrix[8] = {0};
-       unsigned int reg_BL_matrix_Compensate = 0x0;
-       int bl_matrix_1[8] = {0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
-                                       0xfff, 0xfff};
-       unsigned int reg_BL_matrix_Compensate_1 = 0xfff;
-       int bl_matrix_2[8] = {0xfff, 0xfff, 0xfff, 0x000, 0x000, 0xfff,
-                                       0xfff, 0xfff};
-       unsigned int reg_BL_matrix_Compensate_2 = 0xbff;
-       int bl_matrix_3[8] = {0, 0, 0, 0xfff, 0, 0, 0, 0};
-       unsigned int reg_BL_matrix_Compensate_3 = 0x1ff;
-       int bl_matrix_4[8] = {0xfff, 0xfff, 0xfff, 0, 0xfff, 0xfff,
-                                       0xfff, 0xfff};
-       unsigned int reg_BL_matrix_Compensate_4 = 0xdff;
+       ulong flags;
 
-       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
-       data = data & (~(3<<4));
-       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
+       /*LDIMPR("*********rdma_ldim_intr start*********\n");*/
+       spin_lock_irqsave(&rdma_ldim_isr_lock, flags);
 
-       /* gMatrix_LUT: s12*100 ==> max to 8*8 enum ##r/w ram method*/
-       if (mode == 0) {
-               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
-                       &bl_matrix[0], 8);
-               /*  compensate  */
-               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
-               data = data|(reg_BL_matrix_Compensate&0xfff);
-               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
-       } else if (mode == 1) {
-               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
-                       &bl_matrix_1[0], 8);
-       /*  compensate  */
-               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
-               data = data | (reg_BL_matrix_Compensate_1 & 0xfff);
-               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
-       } else if (mode == 2) {
-               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
-                       &bl_matrix_2[0], 8);
-       /*  compensate  */
-               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
-               data = data|(reg_BL_matrix_Compensate_2 & 0xfff);
-               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
-       } else if (mode == 3) {
-               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
-                       &bl_matrix_3[0], 8);
-       /* compensate */
-               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
-               data = data | (reg_BL_matrix_Compensate_3 & 0xfff);
-               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
-       } else if (mode == 4) {
-               LDIM_WR_BASE_LUT_DRT(REG_LD_MATRIX_BASE,
-                       &bl_matrix_4[0], 8);
-       /* compensate */
-               data = LDIM_RD_32Bits(REG_LD_LIT_GAIN_COMP);
-               data = data | (reg_BL_matrix_Compensate_4 & 0xfff);
-               LDIM_WR_32Bits(REG_LD_LIT_GAIN_COMP, data);
+       if (ldim_hist_en) {
+               /*schedule_work(&ldim_on_vs_work);*/
+               queue_work(ldim_queue, &ldim_on_vs_work);
+       }
+       rdma_ldim_irq_cnt++;
+       if (rdma_ldim_irq_cnt > 0xfffffff)
+               rdma_ldim_irq_cnt = 0;
+       spin_unlock_irqrestore(&rdma_ldim_isr_lock, flags);
+       /*LDIMPR("*********rdma_ldim_intr end*********\n");*/
+       return IRQ_HANDLED;
+}
+
+static irqreturn_t ldim_vsync_isr(int irq, void *dev_id)
+{
+       ulong flags;
+       struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
+
+       if (ldim_on_flag == 0)
+               return IRQ_HANDLED;
+
+       spin_lock_irqsave(&ldim_isr_lock, flags);
+
+       if (ldim_func_en) {
+               if (ldim_avg_update_en)
+                       ldim_update_setting();
+
+               switch (bl_drv->data->chip_type) {
+               case BL_CHIP_TXLX:
+                       if (ldim_hist_en) {
+                               /*schedule_work(&ldim_on_vs_work);*/
+                               queue_work(ldim_queue, &ldim_on_vs_work);
+                       }
+                       break;
+               case BL_CHIP_GXTVBB:
+                       break;
+               default:
+                       break;
+               }
+       } else {
+               /*schedule_work(&ldim_off_vs_work);*/
+               queue_work(ldim_queue, &ldim_off_vs_work);
        }
-       /* disable the CBUS configure the RAM */
-       data = LDIM_RD_32Bits(REG_LD_MISC_CTRL0);
-       data = data | (3<<4);
-       LDIM_WR_32Bits(REG_LD_MISC_CTRL0, data);
+
+       ldim_irq_cnt++;
+       if (ldim_irq_cnt > 0xfffffff)
+               ldim_irq_cnt = 0;
+
+       spin_unlock_irqrestore(&ldim_isr_lock, flags);
+
+       return IRQ_HANDLED;
 }
 
+static int brightness_vs_cnt;
 static void ldim_on_vs_brightness(void)
 {
        unsigned int size;
@@ -2559,9 +975,18 @@ static void ldim_on_vs_brightness(void)
        if (ldim_on_flag == 0)
                return;
 
+       if (brightness_vs_cnt++ >= 30)
+               brightness_vs_cnt = 0;
+
        if (ldim_func_bypass)
                return;
 
+       if (ldim_fw_para.fw_alg_frm == NULL) {
+               if (brightness_vs_cnt == 0)
+                       LDIMERR("%s: ldim_alg ko is not installed\n", __func__);
+               return;
+       }
+
        size = ldim_blk_row * ldim_blk_col;
 
        if (ldim_test_en) {
@@ -2586,11 +1011,14 @@ static void ldim_on_vs_brightness(void)
                ldim_driver.device_bri_update(ldim_driver.ldim_matrix_buf,
                        size);
                if (ldim_driver.static_pic_flag == 1) {
-                       ldim_get_matrix_info_max_rgb();
-                       ldim_dump_histgram();
+                       if (brightness_vs_cnt == 0) {
+                               ldim_get_matrix_info_max_rgb();
+                               ldim_dump_histgram();
+                       }
                }
        } else {
-               /*LDIMERR("%s: device_bri_update is null\n", __func__);*/
+               if (brightness_vs_cnt == 0)
+                       LDIMERR("%s: device_bri_update is null\n", __func__);
        }
 }
 
@@ -2603,12 +1031,18 @@ static void ldim_off_vs_brightness(void)
        if (ldim_on_flag == 0)
                return;
 
+       if (brightness_vs_cnt++ >= 30)
+               brightness_vs_cnt = 0;
+
        size = ldim_blk_row * ldim_blk_col;
 
        if (ldim_level_update) {
                ldim_level_update = 0;
-               if (ldim_debug_print)
-                       LDIMPR("%s: level update: 0x%lx\n", __func__, litgain);
+               if (ldim_debug_print) {
+                       if (brightness_vs_cnt == 0)
+                               LDIMPR("%s: level update: 0x%lx\n", __func__,
+                                       litgain);
+               }
                for (i = 0; i < size; i++) {
                        ldim_driver.local_ldim_matrix[i] =
                                (unsigned short)nPRM.BL_matrix[i];
@@ -2620,8 +1054,11 @@ static void ldim_off_vs_brightness(void)
                        ret = ldim_driver.device_bri_check();
                        if (ret) {
                                if (ldim_debug_print) {
-                                       LDIMERR("%s: device_bri_check error\n",
+                                       if (brightness_vs_cnt == 0) {
+                                               LDIMERR(
+                                               "%s: device_bri_check error\n",
                                                __func__);
+                                       }
                                }
                                ldim_level_update = 1;
                        }
@@ -2633,24 +1070,17 @@ static void ldim_off_vs_brightness(void)
                ldim_driver.device_bri_update(ldim_driver.ldim_matrix_buf,
                        size);
                if (ldim_driver.static_pic_flag == 1) {
-                       ldim_get_matrix_info_max_rgb();
-                       ldim_dump_histgram();
+                       if (brightness_vs_cnt == 0) {
+                               ldim_get_matrix_info_max_rgb();
+                               ldim_dump_histgram();
+                       }
                }
        } else {
-               /*LDIMERR("%s: device_bri_update is null\n", __func__);*/
+               if (brightness_vs_cnt == 0)
+                       LDIMERR("%s: device_bri_update is null\n", __func__);
        }
 }
 
-static inline void ld_fw_alg_frm(struct LDReg *nPRM1, struct FW_DAT *FDat1,
-       unsigned int *max_matrix, unsigned int *hist_matrix)
-{
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
-       ld_fw_alg_frm_txlx(nPRM1, FDat1, max_matrix, hist_matrix);
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
-       ld_fw_alg_frm_gxtvbb(nPRM1, FDat1, max_matrix, hist_matrix);
-#endif
-}
-
 static void ldim_on_vs_arithmetic(void)
 {
        unsigned int *local_ldim_hist = NULL;
@@ -2692,8 +1122,10 @@ static void ldim_on_vs_arithmetic(void)
                        (*(local_ldim_max+i))>>20&0x3ff;
        }
        if (ldim_alg_en) {
-               ld_fw_alg_frm(&nPRM, &FDat,
-                       local_ldim_max_rgb, local_ldim_hist);
+               if (ldim_fw_para.fw_alg_frm) {
+                       ldim_fw_para.fw_alg_frm(&ldim_fw_para,
+                               local_ldim_max_rgb, local_ldim_hist);
+               }
        }
 
        kfree(local_ldim_hist);
@@ -2701,6 +1133,112 @@ static void ldim_on_vs_arithmetic(void)
        kfree(local_ldim_max_rgb);
 }
 
+static void ldim_bl_remap_curve_print(void)
+{
+       int i = 0, len;
+       char *buf;
+
+       len = 16 * 8 + 20;
+       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
+       if (buf == NULL) {
+               LDIMERR("print buf malloc error\n");
+               return;
+       }
+
+       pr_info("bl_remap_curve:\n");
+       len = 0;
+       for (i = 0; i < 16; i++)
+               len += sprintf(buf+len, "\t%ld", bl_remap_curve[i]);
+       pr_info("%s\n", buf);
+
+       kfree(buf);
+}
+
+static void ldim_ld_remap_lut_print(int index)
+{
+       int i, j, len;
+       char *buf;
+
+       len = 32 * 8 + 20;
+       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
+       if (buf == NULL) {
+               LDIMERR("print buf malloc error\n");
+               return;
+       }
+
+       if (index == 0xff) {
+               pr_info("LD_remap_lut:\n");
+               for (i = 0; i < 16; i++) {
+                       pr_info("  %d:\n", i);
+                       len = 0;
+                       for (j = 0; j < 32; j++) {
+                               if (j == 16)
+                                       len += sprintf(buf+len, "\n");
+                               len += sprintf(buf+len, "\t%d",
+                                       LD_remap_lut[i][j]);
+                       }
+                       pr_info("%s\n", buf);
+               }
+       } else if (index < 16) {
+               pr_info("LD_remap_lut %d:\n", index);
+               len = 0;
+               for (j = 0; j < 32; j++) {
+                       if (j == 16)
+                               len += sprintf(buf+len, "\n");
+                       len += sprintf(buf+len, "\t%d",
+                               LD_remap_lut[index][j]);
+               }
+               pr_info("%s\n", buf);
+       } else {
+               pr_info("LD_remap_lut invalid index %d\n", index);
+       }
+       pr_info("\n");
+
+       kfree(buf);
+}
+
+static void ldim_dump_histgram(void)
+{
+       unsigned int i, j, k, len;
+       unsigned int *p = NULL;
+       char *buf;
+
+       p = kcalloc(2048, sizeof(unsigned int), GFP_KERNEL);
+       if (p == NULL) {
+               LDIMERR("ldim_matrix_t malloc error\n");
+               return;
+       }
+
+       len = 16 * 10 + 20;
+       buf = kcalloc(len, sizeof(char), GFP_KERNEL);
+       if (buf == NULL) {
+               LDIMERR("print buf malloc error\n");
+               kfree(p);
+               return;
+       }
+
+       memcpy(p, ldim_driver.hist_matrix,
+               ldim_hist_row*ldim_hist_col*16*sizeof(unsigned int));
+
+       for (i = 0; i < ldim_hist_row; i++) {
+               pr_info("%s: row %d:\n", __func__, i);
+               for (j = 0; j < ldim_hist_col; j++) {
+                       len = sprintf(buf, "col %d:\n", j);
+                       for (k = 0; k < 16; k++) {
+                               len += sprintf(buf+len, "\t0x%x",
+                                       *(p+i*16*ldim_hist_col+j*16+k));
+                               if (k == 7)
+                                       len += sprintf(buf+len, "\n");
+                       }
+                       pr_info("%s\n\n", buf);
+               }
+               msleep(20);
+       }
+
+       kfree(buf);
+       kfree(p);
+}
+
 static void ldim_get_matrix_info_TF(void)
 {
        unsigned int i, j, len;
@@ -2739,6 +1277,7 @@ static void ldim_get_matrix_info_TF(void)
        kfree(buf);
        kfree(ldim_matrix_t);
 }
+
 static void ldim_get_matrix_info_SF(void)
 {
        unsigned int i, j, len;
@@ -2777,6 +1316,7 @@ static void ldim_get_matrix_info_SF(void)
        kfree(buf);
        kfree(ldim_matrix_t);
 }
+
 static void ldim_get_matrix_info_4(void)
 {
        unsigned int i, j, k, len;
@@ -2819,6 +1359,7 @@ static void ldim_get_matrix_info_4(void)
        kfree(buf);
        kfree(ldim_matrix_t);
 }
+
 static void ldim_get_matrix_info_alpha(void)
 {
        unsigned int i, j, len;
@@ -2971,7 +1512,7 @@ static void ldim_get_matrix_info(void)
                msleep(20);
        }
 
-       pr_info("current black_frm: %d\n", black_frm);
+       pr_info("current black_frm: %d\n", ldim_fw_para.black_frm);
        pr_info("spi transfer_matrix:\n");
        for (i = 0; i < ldim_blk_row; i++) {
                len = 0;
@@ -3018,6 +1559,7 @@ static void ldim_nPRM_bl_matrix_info(void)
 
        kfree(buf);
 }
+
 static void ldim_set_matrix(unsigned int *data, unsigned int reg_sel,
                unsigned int cnt)
 {
@@ -3093,7 +1635,7 @@ static int ldim_on_init(void)
 
        /* init ldim */
        ldim_stts_initial(ldim_config.hsize, ldim_config.vsize,
-               ldim_blk_row, ldim_blk_col);
+               ldim_hist_row, ldim_hist_col);
        LDIM_Initial(ldim_config.hsize, ldim_config.vsize,
                ldim_blk_row, ldim_blk_col, ldim_config.bl_mode, 1, 0);
 
@@ -3199,6 +1741,67 @@ struct aml_ldim_driver_s *aml_ldim_get_driver(void)
        return &ldim_driver;
 }
 
+static int ldim_open(struct inode *inode, struct file *file)
+{
+       struct ldim_dev_s *devp;
+       /* Get the per-device structure that contains this cdev */
+       devp = container_of(inode->i_cdev, struct ldim_dev_s, cdev);
+       file->private_data = devp;
+       return 0;
+}
+
+static int ldim_release(struct inode *inode, struct file *file)
+{
+       file->private_data = NULL;
+       return 0;
+}
+
+static long ldim_ioctl(struct file *file, unsigned int cmd,
+                       unsigned long arg)
+{
+       int ret = 0;
+
+       switch (cmd) {
+       /*********local dimming ioctl************/
+       case LDIM_IOC_PARA:
+               if (!LDIM_DATA_FROM_DB)
+                       return -EINVAL;
+
+               if (copy_from_user(&ldim_db_para, (void __user *)arg,
+                       sizeof(struct ldim_param_s)))
+                       ret = -EFAULT;
+               break;
+
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
+#ifdef CONFIG_COMPAT
+static long ldim_compat_ioctl(struct file *file, unsigned int cmd,
+       unsigned long arg)
+{
+       unsigned long ret;
+
+       arg = (unsigned long)compat_ptr(arg);
+       ret = ldim_ioctl(file, cmd, arg);
+       return ret;
+}
+#endif
+
+static const struct file_operations ldim_fops = {
+       .owner          = THIS_MODULE,
+       .open           = ldim_open,
+       .release        = ldim_release,
+       .unlocked_ioctl = ldim_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = ldim_compat_ioctl,
+#endif
+};
+
 static ssize_t ldim_attr_show(struct class *cla,
                struct class_attribute *attr, char *buf)
 {
@@ -3225,7 +1828,7 @@ static ssize_t ldim_attr_show(struct class *cla,
        len += sprintf(buf+len,
        "echo info > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
-       "echo alg_para > /sys/class/aml_ldim/attr\n");
+       "echo alg_info > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo test_mode 0 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
@@ -3241,12 +1844,10 @@ static ssize_t ldim_attr_show(struct class *cla,
        "echo fw_LD_ThTF_l 32 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo boost_gain 4 > /sys/class/aml_ldim/attr\n");
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
        len += sprintf(buf+len,
        "echo alpha_delta 0 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo boost_gain_neg 4 > /sys/class/aml_ldim/attr\n");
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
        len += sprintf(buf+len,
        "echo TF_alpha 256 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
@@ -3255,13 +1856,10 @@ static ssize_t ldim_attr_show(struct class *cla,
        "echo lpf_res 0 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo rgb_base 128 > /sys/class/aml_ldim/attr\n");
-#endif
 
        len += sprintf(buf+len,
        "echo ov_gain 16 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
-       "echo incr_dif_gain 16 > /sys/class/aml_ldim/attr\n");
-       len += sprintf(buf+len,
        "echo avg_gain 2048 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo litgain 4096 > /sys/class/aml_ldim/attr\n");
@@ -3290,6 +1888,8 @@ static ssize_t ldim_attr_show(struct class *cla,
        "echo bl_remap_curve > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo fw_LD_Whist > /sys/class/aml_ldim/attr\n");
+       len += sprintf(buf+len,
+       "echo LD_remap_lut > /sys/class/aml_ldim/attr\n");
 
        len += sprintf(buf+len,
        "echo Sf_bypass 0 > /sys/class/aml_ldim/attr\n");
@@ -3303,8 +1903,6 @@ static ssize_t ldim_attr_show(struct class *cla,
        len += sprintf(buf+len,
        "echo fw_hist_print 1 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
-       "echo Debug 1 > /sys/class/aml_ldim/attr\n");
-       len += sprintf(buf+len,
        "echo fw_print_frequent 8 > /sys/class/aml_ldim/attr\n");
        len += sprintf(buf+len,
        "echo Dbprint_lv 1 > /sys/class/aml_ldim/attr\n");
@@ -3358,7 +1956,7 @@ static ssize_t ldim_attr_store(struct class *cla,
        char *parm[47] = {NULL};
        char str[3] = {' ', '\n', '\0'};
        unsigned int size;
-       int i;
+       int i, j;
        char *pr_buf;
        ssize_t pr_len = 0;
 
@@ -3627,101 +2225,89 @@ static ssize_t ldim_attr_store(struct class *cla,
                }
        } else if (!strcmp(parm[0], "bl_remap_curve")) {
                ldim_bl_remap_curve_print();
+               if (parm[16] != NULL) {
+                       for (i = 0; i < 16; i++) {
+                               if (kstrtoul(parm[i+1], 10,
+                                       &bl_remap_curve[i]) < 0) {
+                                       goto ldim_attr_store_end;
+                               }
+                       }
+
+                       ldim_bl_remap_curve_print();
+                       pr_info("\n********bl_remap_curve ok*********\n");
+               }
        } else if (!strcmp(parm[0], "fw_LD_Whist")) {
                for (i = 0; i < 16; i++)
                        pr_info("(%d),", (unsigned int)fw_LD_Whist[i]);
                if (parm[16] != NULL) {
-                       if (kstrtoul(parm[1], 10, &fw_LD_Whist[0]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[2], 10, &fw_LD_Whist[1]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[3], 10, &fw_LD_Whist[2]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[4], 10, &fw_LD_Whist[3]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[5], 10, &fw_LD_Whist[4]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[6], 10, &fw_LD_Whist[5]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[7], 10, &fw_LD_Whist[6]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[8], 10, &fw_LD_Whist[7]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[9], 10, &fw_LD_Whist[8]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[10], 10, &fw_LD_Whist[9]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[11], 10, &fw_LD_Whist[10]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[12], 10, &fw_LD_Whist[11]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[13], 10, &fw_LD_Whist[12]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[14], 10, &fw_LD_Whist[13]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[15], 10, &fw_LD_Whist[14]) < 0)
-                               goto ldim_attr_store_end;
-                       if (kstrtoul(parm[16], 10, &fw_LD_Whist[15]) < 0)
-                               goto ldim_attr_store_end;
+                       for (i = 0; i < 16; i++) {
+                               if (kstrtoul(parm[i+1], 10,
+                                       &fw_LD_Whist[i]) < 0) {
+                                       goto ldim_attr_store_end;
+                               }
+                       }
 
                        for (i = 0; i < 16; i++)
                                pr_info("(%d),", (unsigned int)fw_LD_Whist[i]);
                        pr_info("\n********fw_LD_Whist ok*********\n");
                }
+       } else if (!strcmp(parm[0], "LD_remap_lut")) {
+               if (parm[33] != NULL) {
+                       if (kstrtouint(parm[1], 10, &i) < 0)
+                               goto ldim_attr_store_end;
+                       ldim_ld_remap_lut_print(i);
+                       for (j = 0; j < 32; j++) {
+                               if (kstrtouint(parm[j+2], 10,
+                                       &LD_remap_lut[i][j]) < 0) {
+                                       goto ldim_attr_store_end;
+                               }
+                       }
+
+                       ldim_ld_remap_lut_print(i);
+                       pr_info("\n********LD_remap_lut ok*********\n");
+               } else if (parm[1] != NULL) {
+                       if (kstrtouint(parm[1], 10, &i) < 0)
+                               goto ldim_attr_store_end;
+                       ldim_ld_remap_lut_print(i);
+               } else {
+                       ldim_ld_remap_lut_print(0xff);
+               }
        } else if (!strcmp(parm[0], "Sf_bypass")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       Sf_bypass = (unsigned char)val1;
+                       ldim_fw_para.Sf_bypass = (unsigned char)val1;
                }
-               pr_info("Sf_bypass = %d\n", Sf_bypass);
+               pr_info("Sf_bypass = %d\n", ldim_fw_para.Sf_bypass);
        } else if (!strcmp(parm[0], "Boost_light_bypass")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       Boost_light_bypass = (unsigned char)val1;
+                       ldim_fw_para.Boost_light_bypass = (unsigned char)val1;
                }
-               pr_info("Boost_light_bypass = %d\n", Boost_light_bypass);
+               pr_info("Boost_light_bypass = %d\n",
+                       ldim_fw_para.Boost_light_bypass);
        } else if (!strcmp(parm[0], "Lpf_bypass")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       Lpf_bypass = (unsigned char)val1;
+                       ldim_fw_para.Lpf_bypass = (unsigned char)val1;
                }
-               pr_info("Lpf_bypass = %d\n", Lpf_bypass);
+               pr_info("Lpf_bypass = %d\n", ldim_fw_para.Lpf_bypass);
        } else if (!strcmp(parm[0], "Ld_remap_bypass")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       Ld_remap_bypass = (unsigned char)val1;
-               }
-               pr_info("Ld_remap_bypass = %d\n", Ld_remap_bypass);
-       } else if (!strcmp(parm[0], "slp_gain")) {
-               unsigned int slop_gain = 0;
-
-               if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &val1) < 0)
-                               goto ldim_attr_store_end;
-
-                       slop_gain = (unsigned int)val1;
-                       ldim_bl_remap_curve(slop_gain);
-                       pr_info("slp_gain = %d\n", slop_gain);
-                       ldim_bl_remap_curve_print();
+                       ldim_fw_para.Ld_remap_bypass = (unsigned char)val1;
                }
+               pr_info("Ld_remap_bypass = %d\n", ldim_fw_para.Ld_remap_bypass);
        } else if (!strcmp(parm[0], "ov_gain")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       ov_gain = (unsigned int)val1;
-               }
-               pr_info("ov_gain = %d\n", ov_gain);
-       } else if (!strcmp(parm[0], "incr_dif_gain")) {
-               if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &val1) < 0)
-                               goto ldim_attr_store_end;
-                       incr_dif_gain = (unsigned int)val1;
+                       ldim_fw_para.ov_gain = (unsigned int)val1;
                }
-               pr_info("incr_dif_gain = %d\n", incr_dif_gain);
+               pr_info("ov_gain = %d\n", ldim_fw_para.ov_gain);
        } else if (!strcmp(parm[0], "litgain")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &litgain) < 0)
@@ -3739,216 +2325,218 @@ static ssize_t ldim_attr_store(struct class *cla,
                pr_info("brightness_bypass = %d\n", ldim_brightness_bypass);
        } else if (!strcmp(parm[0], "fw_LD_ThSF_l")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &fw_LD_ThSF_l) < 0)
+                       if (kstrtoul(parm[1], 10,
+                               &ldim_fw_para.fw_LD_ThSF_l) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("fw_LD_ThSF_l = %ld\n", fw_LD_ThSF_l);
+               pr_info("fw_LD_ThSF_l = %ld\n", ldim_fw_para.fw_LD_ThSF_l);
        } else if (!strcmp(parm[0], "fw_LD_ThTF_l")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &fw_LD_ThTF_l) < 0)
+                       if (kstrtoul(parm[1], 10,
+                               &ldim_fw_para.fw_LD_ThTF_l) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("fw_LD_ThTF_l = %ld\n", fw_LD_ThTF_l);
+               pr_info("fw_LD_ThTF_l = %ld\n", ldim_fw_para.fw_LD_ThTF_l);
        } else if (!strcmp(parm[0], "boost_gain")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &boost_gain) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.boost_gain) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("boost_gain = %ld\n", boost_gain);
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
+               pr_info("boost_gain = %ld\n", ldim_fw_para.boost_gain);
        } else if (!strcmp(parm[0], "boost_gain_neg")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &boost_gain_neg) < 0)
+                       if (kstrtoul(parm[1], 10,
+                               &ldim_fw_para.boost_gain_neg) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("boost_gain_neg = %ld\n", boost_gain_neg);
+               pr_info("boost_gain_neg = %ld\n", ldim_fw_para.boost_gain_neg);
        } else if (!strcmp(parm[0], "alpha_delta")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &alpha_delta) < 0)
+                       if (kstrtoul(parm[1], 10,
+                               &ldim_fw_para.alpha_delta) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("alpha_delta = %ld\n", alpha_delta);
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
+               pr_info("alpha_delta = %ld\n", ldim_fw_para.alpha_delta);
        } else if (!strcmp(parm[0], "TF_alpha")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &TF_alpha) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.TF_alpha) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("TF_alpha = %ld\n", TF_alpha);
+               pr_info("TF_alpha = %ld\n", ldim_fw_para.TF_alpha);
        } else if (!strcmp(parm[0], "lpf_gain")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &lpf_gain) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.lpf_gain) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("lpf_gain = %ld\n", lpf_gain);
+               pr_info("lpf_gain = %ld\n", ldim_fw_para.lpf_gain);
        } else if (!strcmp(parm[0], "lpf_res")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &lpf_res) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.lpf_res) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("lpf_res = %ld\n", lpf_res);
+               pr_info("lpf_res = %ld\n", ldim_fw_para.lpf_res);
        } else if (!strcmp(parm[0], "rgb_base")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &rgb_base) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.rgb_base) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("rgb_base = %ld\n", rgb_base);
-#endif
+               pr_info("rgb_base = %ld\n", ldim_fw_para.rgb_base);
        } else if (!strcmp(parm[0], "avg_gain")) {
                if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &avg_gain) < 0)
+                       if (kstrtoul(parm[1], 10, &ldim_fw_para.avg_gain) < 0)
                                goto ldim_attr_store_end;
                }
-               pr_info("avg_gain = %ld\n", avg_gain);
+               pr_info("avg_gain = %ld\n", ldim_fw_para.avg_gain);
        } else if (!strcmp(parm[0], "fw_rgb_diff_th")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       fw_rgb_diff_th = (unsigned int)val1;
+                       ldim_fw_para.fw_rgb_diff_th = (unsigned int)val1;
                }
-               pr_info("fw_rgb_diff_th = %d\n", fw_rgb_diff_th);
+               pr_info("fw_rgb_diff_th = %d\n", ldim_fw_para.fw_rgb_diff_th);
        } else if (!strcmp(parm[0], "max_luma")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       max_luma = (unsigned int)val1;
+                       ldim_fw_para.max_luma = (unsigned int)val1;
                }
-               pr_info("max_luma = %d\n", max_luma);
+               pr_info("max_luma = %d\n", ldim_fw_para.max_luma);
        } else if (!strcmp(parm[0], "lmh_avg_TH")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       lmh_avg_TH = (unsigned int)val1;
+                       ldim_fw_para.lmh_avg_TH = (unsigned int)val1;
                }
-               pr_info("lmh_avg_TH = %d\n", lmh_avg_TH);
+               pr_info("lmh_avg_TH = %d\n", ldim_fw_para.lmh_avg_TH);
        } else if (!strcmp(parm[0], "fw_TF_sum_th")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       fw_TF_sum_th = (unsigned int)val1;
+                       ldim_fw_para.fw_TF_sum_th = (unsigned int)val1;
                }
-               pr_info("fw_TF_sum_th = %d\n", fw_TF_sum_th);
+               pr_info("fw_TF_sum_th = %d\n", ldim_fw_para.fw_TF_sum_th);
        } else if (!strcmp(parm[0], "LPF_method")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       LPF_method = (unsigned int)val1;
+                       ldim_fw_para.LPF_method = (unsigned int)val1;
                }
-               pr_info("LPF_method = %d\n", LPF_method);
+               pr_info("LPF_method = %d\n", ldim_fw_para.LPF_method);
        } else if (!strcmp(parm[0], "LD_TF_STEP_TH")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       LD_TF_STEP_TH = (unsigned int)val1;
+                       ldim_fw_para.LD_TF_STEP_TH = (unsigned int)val1;
                }
-               pr_info("LD_TF_STEP_TH = %d\n", LD_TF_STEP_TH);
+               pr_info("LD_TF_STEP_TH = %d\n", ldim_fw_para.LD_TF_STEP_TH);
        } else if (!strcmp(parm[0], "TF_step_method")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       TF_step_method = (unsigned int)val1;
+                       ldim_fw_para.TF_step_method = (unsigned int)val1;
                }
-               pr_info("TF_step_method = %d\n", TF_step_method);
+               pr_info("TF_step_method = %d\n", ldim_fw_para.TF_step_method);
        } else if (!strcmp(parm[0], "TF_FRESH_BL")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       TF_FRESH_BL = (unsigned int)val1;
+                       ldim_fw_para.TF_FRESH_BL = (unsigned int)val1;
                }
-               pr_info("TF_FRESH_BL = %d\n", TF_FRESH_BL);
+               pr_info("TF_FRESH_BL = %d\n", ldim_fw_para.TF_FRESH_BL);
        } else if (!strcmp(parm[0], "TF_BLK_FRESH_BL")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       TF_BLK_FRESH_BL = (unsigned int)val1;
+                       ldim_fw_para.TF_BLK_FRESH_BL = (unsigned int)val1;
                }
-               pr_info("TF_BLK_FRESH_BL = %d\n", TF_BLK_FRESH_BL);
+               pr_info("TF_BLK_FRESH_BL = %d\n", ldim_fw_para.TF_BLK_FRESH_BL);
        } else if (!strcmp(parm[0], "bbd_detect_en")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       bbd_detect_en = (unsigned char)val1;
+                       ldim_fw_para.bbd_detect_en = (unsigned char)val1;
                }
-               pr_info("bbd_detect_en = %d\n", bbd_detect_en);
+               pr_info("bbd_detect_en = %d\n", ldim_fw_para.bbd_detect_en);
        } else if (!strcmp(parm[0], "side_blk_diff_th")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       side_blk_diff_th = (unsigned int)val1;
+                       ldim_fw_para.side_blk_diff_th = (unsigned int)val1;
                }
-               pr_info("side_blk_diff_th = %d\n", side_blk_diff_th);
+               pr_info("side_blk_diff_th = %d\n",
+                       ldim_fw_para.side_blk_diff_th);
        } else if (!strcmp(parm[0], "bbd_th")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       bbd_th = (unsigned int)val1;
+                       ldim_fw_para.bbd_th = (unsigned int)val1;
                }
-               pr_info("bbd_th = %d\n", bbd_th);
+               pr_info("bbd_th = %d\n", ldim_fw_para.bbd_th);
        } else if (!strcmp(parm[0], "diff_blk_luma_en")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       diff_blk_luma_en = (unsigned char)val1;
+                       ldim_fw_para.diff_blk_luma_en = (unsigned char)val1;
                }
-               pr_info("diff_blk_luma_en = %d\n", diff_blk_luma_en);
+               pr_info("diff_blk_luma_en = %d\n",
+                       ldim_fw_para.diff_blk_luma_en);
        } else if (!strcmp(parm[0], "fw_hist_print")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       fw_hist_print = (unsigned char)val1;
-               }
-               pr_info("fw_hist_print = %d\n", fw_hist_print);
-       } else if (!strcmp(parm[0], "Debug")) {
-               if (parm[1] != NULL) {
-                       if (kstrtoul(parm[1], 10, &val1) < 0)
-                               goto ldim_attr_store_end;
-                       Debug = (unsigned char)val1;
+                       ldim_fw_para.fw_hist_print = (unsigned char)val1;
                }
-               pr_info("Debug = %d\n", Debug);
+               pr_info("fw_hist_print = %d\n", ldim_fw_para.fw_hist_print);
        } else if (!strcmp(parm[0], "fw_print_frequent")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       fw_print_frequent = (unsigned int)val1;
+                       ldim_fw_para.fw_print_frequent = (unsigned int)val1;
                }
-               pr_info("fw_print_frequent = %d\n", fw_print_frequent);
+               pr_info("fw_print_frequent = %d\n",
+                       ldim_fw_para.fw_print_frequent);
        } else if (!strcmp(parm[0], "Dbprint_lv")) {
                if (parm[1] != NULL) {
                        if (kstrtoul(parm[1], 10, &val1) < 0)
                                goto ldim_attr_store_end;
-                       Dbprint_lv = (unsigned int)val1;
+                       ldim_fw_para.Dbprint_lv = (unsigned int)val1;
+               }
+               pr_info("Dbprint_lv = %d\n", ldim_fw_para.Dbprint_lv);
+       } else if (!strcmp(parm[0], "alg_info")) {
+               pr_info("ldim_alg_ver: %s\n", ldim_fw_para.ver_str);
+               pr_info("ldim_fw_alg_frm: 0x%p\n\n", ldim_fw_para.fw_alg_frm);
+               switch (ldim_fw_para.ver_num) {
+               case 0:
+                       pr_info("fw_LD_ThSF_l         = %ld\n"
+                               "fw_LD_ThTF_l         = %ld\n"
+                               "boost_gain           = %ld\n"
+                               "TF_alpha             = %ld\n"
+                               "lpf_gain             = %ld\n"
+                               "lpf_res              = %ld\n"
+                               "rgb_base             = %ld\n\n",
+                               ldim_fw_para.fw_LD_ThSF_l,
+                               ldim_fw_para.fw_LD_ThTF_l,
+                               ldim_fw_para.boost_gain,
+                               ldim_fw_para.TF_alpha,
+                               ldim_fw_para.lpf_gain,
+                               ldim_fw_para.lpf_res,
+                               ldim_fw_para.rgb_base);
+                       break;
+               case 1:
+                       pr_info("fw_LD_ThSF_l         = %ld\n"
+                               "fw_LD_ThTF_l         = %ld\n"
+                               "boost_gain           = %ld\n"
+                               "boost_gain_neg       = %ld\n"
+                               "alpha_delta          = %ld\n\n",
+                               ldim_fw_para.fw_LD_ThSF_l,
+                               ldim_fw_para.fw_LD_ThTF_l,
+                               ldim_fw_para.boost_gain,
+                               ldim_fw_para.boost_gain_neg,
+                               ldim_fw_para.alpha_delta);
+                       break;
+               default:
+                       break;
                }
-               pr_info("Dbprint_lv = %d\n", Dbprint_lv);
-       } else if (!strcmp(parm[0], "alg_para")) {
-               pr_info("ldim_alg_ver         = %s\n",
-                       LD_FW_ALG_FRM_VER);
-#if (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V1)
-               pr_info("fw_LD_ThSF_l         = %ld\n"
-                       "fw_LD_ThTF_l         = %ld\n"
-                       "boost_gain           = %ld\n"
-                       "boost_gain_neg       = %ld\n"
-                       "alpha_delta          = %ld\n\n",
-                       fw_LD_ThSF_l,
-                       fw_LD_ThTF_l,
-                       boost_gain,
-                       boost_gain_neg,
-                       alpha_delta);
-#elif (LD_FW_ALG_FRM_SEL == LD_FW_ALG_FRM_V0)
-               pr_info("fw_LD_ThSF_l         = %ld\n"
-                       "fw_LD_ThTF_l         = %ld\n"
-                       "boost_gain           = %ld\n"
-                       "TF_alpha             = %ld\n"
-                       "lpf_gain             = %ld\n"
-                       "lpf_res              = %ld\n"
-                       "rgb_base             = %ld\n\n",
-                       fw_LD_ThSF_l,
-                       fw_LD_ThTF_l,
-                       boost_gain,
-                       TF_alpha,
-                       lpf_gain,
-                       lpf_res,
-                       rgb_base);
-#endif
                pr_info("fw_rgb_diff_th       = %d\n"
                        "max_luma             = %d\n"
                        "lmh_avg_TH           = %d\n"
@@ -3957,48 +2545,44 @@ static ssize_t ldim_attr_store(struct class *cla,
                        "LD_TF_STEP_TH        = %d\n"
                        "TF_step_method       = %d\n"
                        "TF_FRESH_BL          = %d\n\n",
-                       fw_rgb_diff_th,
-                       max_luma,
-                       lmh_avg_TH,
-                       fw_TF_sum_th,
-                       LPF_method,
-                       LD_TF_STEP_TH,
-                       TF_step_method,
-                       TF_FRESH_BL);
+                       ldim_fw_para.fw_rgb_diff_th,
+                       ldim_fw_para.max_luma,
+                       ldim_fw_para.lmh_avg_TH,
+                       ldim_fw_para.fw_TF_sum_th,
+                       ldim_fw_para.LPF_method,
+                       ldim_fw_para.LD_TF_STEP_TH,
+                       ldim_fw_para.TF_step_method,
+                       ldim_fw_para.TF_FRESH_BL);
                pr_info("TF_BLK_FRESH_BL      = %d\n"
                        "side_blk_diff_th     = %d\n"
                        "bbd_th               = %d\n"
                        "bbd_detect_en        = %d\n"
                        "diff_blk_luma_en     = %d\n\n",
-                       TF_BLK_FRESH_BL,
-                       side_blk_diff_th,
-                       bbd_th,
-                       bbd_detect_en,
-                       diff_blk_luma_en);
+                       ldim_fw_para.TF_BLK_FRESH_BL,
+                       ldim_fw_para.side_blk_diff_th,
+                       ldim_fw_para.bbd_th,
+                       ldim_fw_para.bbd_detect_en,
+                       ldim_fw_para.diff_blk_luma_en);
                pr_info("ov_gain              = %d\n"
-                       "incr_dif_gain        = %d\n"
                        "avg_gain             = %ld\n"
                        "litgain              = %ld\n\n",
-                       ov_gain,
-                       incr_dif_gain,
-                       avg_gain,
+                       ldim_fw_para.ov_gain,
+                       ldim_fw_para.avg_gain,
                        litgain);
                pr_info("Sf_bypass            = %d\n"
                        "Boost_light_bypass   = %d\n"
                        "Lpf_bypass           = %d\n"
                        "Ld_remap_bypass      = %d\n\n",
-                       Sf_bypass,
-                       Boost_light_bypass,
-                       Lpf_bypass,
-                       Ld_remap_bypass);
+                       ldim_fw_para.Sf_bypass,
+                       ldim_fw_para.Boost_light_bypass,
+                       ldim_fw_para.Lpf_bypass,
+                       ldim_fw_para.Ld_remap_bypass);
                pr_info("fw_hist_print        = %d\n"
-                       "Debug                = %d\n"
                        "fw_print_frequent    = %d\n"
                        "Dbprint_lv           = %d\n\n",
-                       fw_hist_print,
-                       Debug,
-                       fw_print_frequent,
-                       Dbprint_lv);
+                       ldim_fw_para.fw_hist_print,
+                       ldim_fw_para.fw_print_frequent,
+                       ldim_fw_para.Dbprint_lv);
        } else if (!strcmp(parm[0], "info")) {
                pr_info("ldim_drv_ver: %s\n", LDIM_DRV_VER);
                ldim_driver.config_print();
@@ -4172,6 +2756,66 @@ int aml_ldim_get_config_unifykey(unsigned char *buf)
        return 0;
 }
 
+static struct ldim_fw_para_s ldim_fw_para = {
+       .ver_str = "not installed",
+       .ver_num = 0,
+
+       .nPRM = &nPRM,
+       .FDat = &FDat,
+       .bl_remap_curve = bl_remap_curve,
+       .fw_LD_Whist = fw_LD_Whist,
+
+       .fw_LD_ThSF_l = 1600,
+       .fw_LD_ThTF_l = 256,
+       .boost_gain = 456, /*norm 256 to 1,T960 finally use*/
+       .TF_alpha = 256, /*256;*/
+       .lpf_gain = 128,  /* [0~128~256], norm 128 as 1*/
+       .boost_gain_neg = 3,
+       .alpha_delta = 255,/* to fix flicker */
+
+       .lpf_res = 14,    /* 1024/9*9 = 13,LPF_method=3 */
+       .rgb_base = 127,
+
+       .ov_gain = 16,
+
+       .LPF_method = 3,
+       .LD_TF_STEP_TH = 100,
+       .TF_step_method = 3,
+       .TF_FRESH_BL = 8,
+
+       .TF_BLK_FRESH_BL = 5,
+       .side_blk_diff_th = 100,
+       .bbd_th = 200,
+       .bbd_detect_en = 1,
+       .diff_blk_luma_en = 1,
+
+       .fw_rgb_diff_th = 32760,
+       .max_luma = 4060,
+       .lmh_avg_TH = 200,/*for woman flicker*/
+       .fw_TF_sum_th = 32760,/*20180530*/
+
+       .avg_gain = LD_DATA_MAX,
+
+       .Sf_bypass = 0,
+       .Boost_light_bypass = 0,
+       .Lpf_bypass = 0,
+       .Ld_remap_bypass = 0,
+       .black_frm = 0,
+
+       /* debug print flag */
+       .fw_hist_print = 0,
+       .fw_print_frequent = 8,
+       .Dbprint_lv = 0,
+
+       .fw_alg_frm = NULL,
+};
+
+struct ldim_fw_para_s *aml_ldim_get_fw_para(void)
+{
+       return &ldim_fw_para;
+}
+EXPORT_SYMBOL(aml_ldim_get_fw_para);
+
 static int aml_ldim_kzalloc(unsigned int ldim_blk_row1,
        unsigned int ldim_blk_col1)
 {
@@ -4289,14 +2933,6 @@ int aml_ldim_probe(struct platform_device *pdev)
        ldim_alg_en = 0;
        ldim_top_en = 0;
        ldim_hist_en = 0;
-       Dbprint_lv = 0;
-       db_cnt = 0;
-
-       memset(devp, 0, (sizeof(struct ldim_dev_s)));
-       nPRM.val_1 = &val_1[0];
-       nPRM.bin_1 = &bin_1[0];
-       nPRM.val_2 = &val_2[0];
-       nPRM.bin_2 = &bin_2[0];
 
        ret = aml_ldim_kzalloc(ldim_blk_row, ldim_blk_col);
        if (ret) {
@@ -4304,6 +2940,8 @@ int aml_ldim_probe(struct platform_device *pdev)
                goto err;
        }
 
+       memset(devp, 0, (sizeof(struct ldim_dev_s)));
+
        ret = alloc_chrdev_region(&devp->aml_ldim_devno, 0, 1,
                AML_LDIM_DEVICE_NAME);
        if (ret < 0) {
@@ -4433,8 +3071,17 @@ int aml_ldim_remove(void)
        kfree(ldim_driver.ldim_test_matrix);
        kfree(ldim_driver.local_ldim_matrix);
 
-       free_irq(bl_drv->res_ldim_rdma_irq->start, (void *)"ldim_rdma");
        free_irq(bl_drv->res_ldim_vsync_irq->start, (void *)"ldim_vsync");
+       switch (bl_drv->data->chip_type) {
+       case BL_CHIP_GXTVBB:
+               if (bl_drv->res_ldim_rdma_irq) {
+                       free_irq(bl_drv->res_ldim_rdma_irq->start,
+                               (void *)"ldim_rdma");
+               }
+               break;
+       default:
+               break;
+       }
 
        cdev_del(devp->aml_ldim_cdevp);
        kfree(devp->aml_ldim_cdevp);
index 1e08047ea6d251c9138d8c789de66de7ca894cba..ec66dc779df51fb5b6156fb1214b43275397a424 100644 (file)
 
 #ifndef _AML_LDIM_DRV_H_
 #define _AML_LDIM_DRV_H_
-#include <linux/cdev.h>
-#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
-
-#define AML_LDIM_MODULE_NAME "aml_ldim"
-#define AML_LDIM_DRIVER_NAME "aml_ldim"
-#define AML_LDIM_DEVICE_NAME "aml_ldim"
-#define AML_LDIM_CLASS_NAME  "aml_ldim"
-
-#define Wr(reg, val)   aml_write_vcbus(reg, val)
-#define Rd(adr)       aml_read_vcbus(adr)
-
-/*#define LDIM_DEBUG_INFO*/
-#define LDIMPR(fmt, args...)     pr_info("ldim: "fmt"", ## args)
-#define LDIMERR(fmt, args...)    pr_err("ldim: error: "fmt"", ## args)
+#include <linux/amlogic/media/vout/lcd/ldim_alg.h>
 
 /*20180629: initial version */
 /*20180725: new pwm control flow support */
-#define LDIM_DRV_VER    "20180725"
+/*20180730: algorithm clear up */
+#define LDIM_DRV_VER    "20180730"
 
 extern unsigned char ldim_debug_print;
 
-/*** GXTVBB & TXLX common use register*/
-/* each base has 16 address space */
-#define REG_LD_CFG_BASE           0x00
-#define REG_LD_RGB_IDX_BASE       0x10
-#define REG_LD_RGB_LUT_BASE       0x2000
-#define REG_LD_MATRIX_BASE        0x3000
-/* LD_CFG_BASE */
-#define REG_LD_FRM_SIZE           0x0
-#define REG_LD_RGB_MOD            0x1
-#define REG_LD_BLK_HVNUM          0x2
-#define REG_LD_HVGAIN             0x3
-#define REG_LD_BKLIT_VLD          0x4
-#define REG_LD_BKLIT_PARAM        0x5
-#define REG_LD_LIT_GAIN_COMP      0x7
-#define REG_LD_FRM_RST_POS        0x8
-#define REG_LD_FRM_BL_START_POS   0x9
-#define REG_LD_MISC_CTRL0         0xa
-#define REG_LD_FRM_HBLAN_VHOLS    0xb
-#define REG_LD_XLUT_DEMO_ROI_XPOS 0xc
-#define REG_LD_XLUT_DEMO_ROI_YPOS 0xd
-#define REG_LD_XLUT_DEMO_ROI_CTRL 0xe
-
-
-/* each base has 16 address space */
-/******  GXTVBB ******/
-#define REG_LD_G_IDX_BASE          0x20
-#define REG_LD_B_IDX_BASE          0x30
-#define REG_LD_RGB_NRMW_BASE       0x40
-#define REG_LD_LUT_HDG_BASE        0x50
-#define REG_LD_LUT_VHK_BASE        0x60
-#define REG_LD_LUT_VDG_BASE        0x70
-#define REG_LD_BLK_HIDX_BASE       0x80
-#define REG_LD_BLK_VIDX_BASE       0xa0
-#define REG_LD_LUT_VHK_NEGPOS_BASE 0xc0
-#define REG_LD_LUT_VHO_NEGPOS_BASE 0xd0
-#define REG_LD_LUT_HHK_BASE        0xe0
-#define REG_LD_REFLECT_DGR_BASE    0xf0
-/* LD_CFG_BASE */
-#define REG_LD_LUT_XDG_LEXT        0x6
-
-
-
-/* each base has 16 address space */
-/******  TXLX  ******/
-#define REG_LD_RGB_NRMW_BASE_TXLX       0x20
-#define REG_LD_BLK_HIDX_BASE_TXLX       0x30
-#define REG_LD_BLK_VIDX_BASE_TXLX       0x50
-#define REG_LD_LUT_VHK_NEGPOS_BASE_TXLX 0x60
-#define REG_LD_LUT_VHO_NEGPOS_BASE_TXLX 0x70
-#define REG_LD_LUT_HHK_BASE_TXLX        0x80
-#define REG_LD_REFLECT_DGR_BASE_TXLX    0x90
-#define REG_LD_LUT_LEXT_BASE_TXLX       0xa0
-#define REG_LD_LUT_HDG_BASE_TXLX        0x100
-#define REG_LD_LUT_VDG_BASE_TXLX        0x180
-#define REG_LD_LUT_VHK_BASE_TXLX        0x200
-#define REG_LD_LUT_ID_BASE_TXLX         0x300
-/* LD_CFG_BASE */
-#define REG_LD_BLMAT_RAM_MISC           0xf
+extern int LD_remap_lut[16][32];
 
+#define AML_LDIM_MODULE_NAME "aml_ldim"
+#define AML_LDIM_DRIVER_NAME "aml_ldim"
+#define AML_LDIM_DEVICE_NAME "aml_ldim"
+#define AML_LDIM_CLASS_NAME  "aml_ldim"
 
 /*========================================*/
-#define LD_STA_BIN_NUM 16
-#define LD_STA_LEN_V 17
-/*  support maximum 16x4 regions for statistics (16+1) */
-#define LD_STA_LEN_H 25
-/*  support maximum 16x4 regions for statistics (24+1)*/
-#define LD_BLK_LEN_V 25
-/*  support maximum 16 led of each side left/right(16+4+4+1)*/
-#define LD_BLK_LEN_H 33
-/*  support maximum 24 led of each side top/bot  (24+4+4+1)*/
-#define LD_LUT_LEN 32
-#define LD_BLKHMAX 32
-#define LD_BLKVMAX 32
-
-
-#define LD_DATA_DEPTH   12
-#define LD_DATA_MIN     10
-#define LD_DATA_MAX     0xfff
-
-struct LDReg {
-       int reg_LD_pic_RowMax;            /*u13*/
-       int reg_LD_pic_ColMax;            /*u13*/
-       int reg_LD_pic_YUVsum[3];
-       /* only output u16*3, (internal ACC will be u32x3)*/
-       int reg_LD_pic_RGBsum[3];
-       /* Statistic options */
-       int reg_LD_STA_Vnum;
-       /*u8: statistic region number of V, maximum to (STA_LEN_V-1)   (0~16)*/
-       int reg_LD_STA_Hnum;
-       /*u8: statistic region number of H, maximum to (STA_LEN_H-1)   (0~24)*/
-       int reg_LD_BLK_Vnum;
-       /*u8: Maximum to 16*/
-       int reg_LD_BLK_Hnum;
-       /*u8: Maximum to 24*/
-       int reg_LD_STA1max_LPF;
-       /*u1: STA1max statistics on [1 2 1]/4 filtered results*/
-       int reg_LD_STA2max_LPF;
-       /*u1: STA2max statistics on [1 2 1]/4 filtered results*/
-       int reg_LD_STAhist_LPF;
-       /*u1: STAhist statistics on [1 2 1]/4 filtered results*/
-       int reg_LD_STA1max_Hdlt;
-       /* u2: (2^x) extra pixels into Max calculation*/
-       int reg_LD_STA1max_Vdlt;
-       /* u4: extra pixels into Max calculation vertically*/
-       int reg_LD_STA2max_Hdlt;
-       /* u2: (2^x) extra pixels into Max calculation*/
-       int reg_LD_STA2max_Vdlt;
-       /* u4: extra pixels into Max calculation vertically*/
-       int reg_LD_STA1max_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
-       int reg_LD_STA1max_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
-       int reg_LD_STA2max_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
-       int reg_LD_STA2max_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
-
-       int reg_LD_STAhist_mode;
-               /*u3: histogram statistics on XX separately 20bits*16bins:
-                *0: R-only,1:G-only 2:B-only 3:Y-only;
-                *4: MAX(R,G,B), 5/6/7: R&G&B
-                */
-       int reg_LD_STAhist_pix_drop_mode;
-               /* u2:histogram statistics pixel drop mode:
-                * 0:no drop; 1:only statistic
-                * x%2=0; 2:only statistic x%4=0; 3: only statistic x%8=0;
-                */
-       int reg_LD_STAhist_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
-       int reg_LD_STAhist_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
-
-       /***** FBC3 fw_hw_alg_frm *****/
-       int reg_ldfw_BLmax;/* maximum BL value*/
-       int reg_ldfw_blk_norm;
-               /*u8: normalization gain for blk number,
-                *1/blk_num= norm>>(rs+8), norm = (1<<(rs+8))/blk_num
-                */
-       int reg_ldfw_blk_norm_rs;/*u3: 0~7,  1/blk_num= norm>>(rs+8) */
-       int reg_ldfw_sta_hdg_weight[8];
-               /*  u8x8, weighting to each
-                * block's max to decide that block's ld.
-                */
-       int reg_ldfw_sta_max_mode;
-               /* u2: maximum selection for
-                *components: 0: r_max, 1: g_max, 2: b_max; 3: max(r,g,b)
-                */
-       int reg_ldfw_sta_max_hist_mode;
-               /* u2: mode of reference
-                * max/hist mode:0: MIN(max, hist), 1: MAX(max, hist)
-                * 2: (max+hist)/2, 3: (max(a,b)*3 + min(a,b))/4
-                */
-       int reg_ldfw_hist_valid_rate;
-               /* u8, norm to 512 as "1", if hist_matrix[i]>(rate*histavg)>>9*/
-       int reg_ldfw_hist_valid_ofst;/*u8, hist valid bin upward offset*/
-       int reg_ldfw_sedglit_RL;/*u1: single edge lit right/bottom mode*/
-       int reg_ldfw_sf_thrd;/*u12: threshold of difference to enable the sf;*/
-       int reg_ldfw_boost_gain;
-               /* u8: boost gain for the region that
-                * is larger than the average, norm to 16 as "1"
-                */
-       int reg_ldfw_tf_alpha_rate;
-               /*u8: rate to SFB_BL_matrix from
-                *last frame difference;
-                */
-       int reg_ldfw_tf_alpha_ofst;
-               /*u8: ofset to alpha SFB_BL_matrix
-                *from last frame difference;
-                */
-       int reg_ldfw_tf_disable_th;
-               /*u8: 4x is the threshod to disable
-                *tf to the alpha (SFB_BL_matrix from last frame difference;
-                */
-       int reg_ldfw_blest_acmode;
-               /*u3: 0: est on BLmatrix;
-                *1: est on(BL-DC); 2: est on (BL-MIN);
-                *3: est on (BL-MAX) 4: 2048; 5:1024
-                */
-       int reg_ldfw_sf_enable;
-       /*u1: enable signal for spatial filter on the tbl_matrix*/
-       int reg_ldfw_enable;
-       int reg_ldfw_sta_hdg_vflt;
-       int reg_ldfw_sta_norm;
-       int reg_ldfw_sta_norm_rs;
-       int reg_ldfw_tf_enable;
-       int reg_LD_LUT_Hdg_TXLX[8][32];
-       int reg_LD_LUT_Vdg_TXLX[8][32];
-       int reg_LD_LUT_VHk_TXLX[8][32];
-       int reg_LD_LUT_Id[16 * 24];
-       int reg_LD_LUT_Hdg_LEXT_TXLX[8];
-       int reg_LD_LUT_Vdg_LEXT_TXLX[8];
-       int reg_LD_LUT_VHk_LEXT_TXLX[8];
-       int reg_ldfw_boost_enable;
-               /*u1: enable signal for Boost
-                *filter on the tbl_matrix
-                */
-       int ro_ldfw_bl_matrix_avg;/*u12: read-only register for bl_matrix*/
-
-       /* Backlit Modeling registers*/
-       int BL_matrix[LD_BLKREGNUM];
-       /* Define the RAM Matrix*/
-       int reg_LD_BackLit_Xtlk;
-       /*u1: 0 no block to block Xtalk model needed;   1: Xtalk model needed*/
-       int reg_LD_BackLit_mode;
-       /*u2: 0- LEFT/RIGHT Edge Lit; 1- Top/Bot Edge Lit; 2 - DirectLit
-        *modeled H/V independent; 3- DirectLit modeled HV Circle distribution
-        */
-       int reg_LD_Reflect_Hnum;
-       /*u3: numbers of band reflection considered in Horizontal direction;
-        *      0~4
-        */
-       int reg_LD_Reflect_Vnum;
-       /*u3: numbers of band reflection considered in Horizontal direction;
-        *      0~4
-        */
-       int reg_LD_BkLit_curmod;
-       /*u1: 0: H/V separately, 1 Circle distribution*/
-       int reg_LD_BkLUT_Intmod;
-       /*u1: 0: linear interpolation, 1 cubical interpolation*/
-       int reg_LD_BkLit_Intmod;
-       /*u1: 0: linear interpolation, 1 cubical interpolation*/
-       int reg_LD_BkLit_LPFmod;
-       /*u3: 0: no LPF, 1:[1 14 1]/16;2:[1 6 1]/8; 3: [1 2 1]/4;
-        *      4:[9 14 9]/32  5/6/7: [5 6 5]/16;
-        */
-       int reg_LD_BkLit_Celnum;
-       /*u8: 0: 1920~ 61*/
-       int reg_BL_matrix_AVG;
-       /*u12: DC of whole picture BL to be subtract from BL_matrix
-        *      during modeling (Set by FW daynamically)
-        */
-       int reg_BL_matrix_Compensate;
-       /*u12: DC of whole picture BL to be compensated back to
-        *      Litfull after the model (Set by FW dynamically);
-        */
-       int reg_LD_Reflect_Hdgr[20];
-       /*20*u6:  cells 1~20 for H Gains of different dist of
-        * Left/Right;
-        */
-       int reg_LD_Reflect_Vdgr[20];
-       /*20*u6:  cells 1~20 for V Gains of different dist of Top/Bot;*/
-       int reg_LD_Reflect_Xdgr[4];     /*4*u6:*/
-       int reg_LD_Vgain;               /*u12*/
-       int reg_LD_Hgain;               /*u12*/
-       int reg_LD_Litgain;             /*u12*/
-       int reg_LD_Litshft;
-       /*u3   right shif of bits for the all Lit's sum*/
-       int reg_LD_BkLit_valid[32];
-       /*u1x32: valid bits for the 32 cell Bklit to contribut to current
-        *      position (refer to the backlit padding pattern)
-        */
-       /* region division index 1 2 3 4 5(0) 6(1) 7(2)
-        *      8(3) 9(4)  10(5)11(6)12(7)13(8) 14(9)15(10) 16 17 18 19
-        */
-       int reg_LD_BLK_Hidx[LD_BLK_LEN_H]; /* S14* BLK_LEN*/
-       int reg_LD_BLK_Vidx[LD_BLK_LEN_V]; /* S14* BLK_LEN*/
-       /* Define the RAM Matrix*/
-       int reg_LD_LUT_Hdg[LD_LUT_LEN];  /*u10*/
-       int reg_LD_LUT_Vdg[LD_LUT_LEN];  /*u10*/
-       int reg_LD_LUT_VHk[LD_LUT_LEN];  /*u10*/
-       /* VHk positive and negative side gain, normalized to 128
-        *      as "1" 20150428
-        */
-       int reg_LD_LUT_VHk_pos[32];   /* u8*/
-       int reg_LD_LUT_VHk_neg[32];   /* u8*/
-       int reg_LD_LUT_HHk[32];
-       /* u8 side gain for LED direction hdist gain for different LED*/
-       /* VHo possitive and negative side offset, use with LS, (x<<LS)*/
-       int reg_LD_LUT_VHo_pos[32];   /* s8*/
-       int reg_LD_LUT_VHo_neg[32];   /* s8*/
-       int reg_LD_LUT_VHo_LS;/* u3:0~6,left shift bits of VH0_pos/neg*/
-       /* adding three cells for left boundary extend during
-        *      Cubic interpolation
-        */
-       int reg_LD_LUT_Hdg_LEXT;
-       int reg_LD_LUT_Vdg_LEXT;
-       int reg_LD_LUT_VHk_LEXT;
-       /* adding demo window mode for LD for RGB lut compensation*/
-       int reg_LD_xlut_demo_roi_xstart;
-       /* u14 start col index of the region of interest*/
-       int reg_LD_xlut_demo_roi_xend;
-       /* u14 end col index of the region of interest*/
-       int reg_LD_xlut_demo_roi_ystart;
-       /* u14 start row index of the region of interest*/
-       int reg_LD_xlut_demo_roi_yend;
-       /* u14 end row index of the region of interest*/
-       int reg_LD_xlut_iroi_enable;
-       /* u1: enable rgb LUT remapping inside regon of interest:
-        *      0: no rgb remapping; 1: enable rgb remapping
-        */
-       int reg_LD_xlut_oroi_enable;
-       /* u1: enable rgb LUT remapping outside regon of interest:
-        *      0: no rgb remapping; 1: enable rgb remapping
-        */
-       /* Register used in RGB remapping*/
-       int reg_LD_RGBmapping_demo;
-       /*u2: 0 no demo mode 1: display BL_fulpel on RGB*/
-       int reg_LD_X_LUT_interp_mode[3];
-       /*U1 0: using linear interpolation between to neighbour LUT;
-        *      1: use the nearest LUT results
-        */
-       int X_idx[1][16];
-       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
-       int X_nrm[1][16];
-       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
-       int X_lut[3][16][32];
-       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
-       /* only do the Lit modleing on the AC part*/
-       int X_lut2[3][16][16];
-       int fw_LD_BLEst_ACmode;
-       /*u2: 0: est on BLmatrix; 1: est on (BL-DC);
-        *      2: est on (BL-MIN); 3: est on (BL-MAX)
-        */
-       unsigned long *val_1;
-       unsigned long *bin_1;
-       unsigned long *val_2;
-       unsigned long *bin_2;
-};
 
-struct FW_DAT {
-       /* for temporary Firmware algorithm */
-       unsigned int *TF_BL_alpha;
-       unsigned int *last_YUVsum;
-       unsigned int *last_RGBsum;
-       unsigned int *last_STA1_MaxRGB;
-       unsigned int *SF_BL_matrix;
-       unsigned int *TF_BL_matrix;
-       unsigned int *TF_BL_matrix_2;
-};
 
-/* #define LDIM_STTS_HIST_REGION_IDX      0x1aa0 */
-#define LOCAL_DIM_STATISTIC_EN_BIT          31
-#define LOCAL_DIM_STATISTIC_EN_WID           1
-#define EOL_EN_BIT                          28
-#define EOL_EN_WID                           1
+extern int  ldim_round(int ix, int ib);
+extern void ldim_stts_en(unsigned int resolution, unsigned int pix_drop_mode,
+       unsigned int eol_en, unsigned int hist_mode, unsigned int lpf_en,
+       unsigned int rd_idx_auto_inc_mode, unsigned int one_ram_en);
+extern void ldim_set_region(unsigned int resolution, unsigned int blk_height,
+       unsigned int blk_width, unsigned int row_start, unsigned int col_start,
+       unsigned int blk_hnum);
+extern void LD_ConLDReg(struct LDReg_s *Reg);
+extern void ld_fw_cfg_once(struct LDReg_s *nPRM);
+extern void ldim_stts_read_region(unsigned int nrow, unsigned int ncol);
 
-/* 0: 17 pix, 1: 9 pix, 2: 5 pix, 3: 3 pix, 4: 0 pix */
-#define HOVLP_NUM_SEL_BIT                   21
-#define HOVLP_NUM_SEL_WID                    2
-#define LPF_BEFORE_STATISTIC_EN_BIT         20
-#define LPF_BEFORE_STATISTIC_EN_WID          1
-#define BLK_HV_POS_IDXS_BIT                 16
-#define BLK_HV_POS_IDXS_WID                  4
-#define RD_INDEX_INC_MODE_BIT               14
-#define RD_INDEX_INC_MODE_WID                2
-#define REGION_RD_SUB_INDEX_BIT              8
-#define REGION_RD_SUB_INDEX_WID              4
-#define REGION_RD_INDEX_BIT                  0
-#define REGION_RD_INDEX_WID                  7
+extern void ldim_set_matrix_ycbcr2rgb(void);
+extern void ldim_set_matrix_rgb2ycbcr(int mode);
 
 #endif
index 7d2b42a45fbb95d1cf056f0e44b0ff633208d92c..46b4a9a8ae2cd332cc5e2b045edea8d737ee96f2 100644 (file)
 #include <linux/io.h>
 #include <linux/mm.h>
 #include <linux/mutex.h>
-#include <linux/device.h>
 #include <linux/timer.h>
 #include <linux/delay.h>
 #include <linux/major.h>
-#include <linux/sched.h>
-#include <linux/vmalloc.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
-#include <linux/interrupt.h>
-#include <linux/fs.h>
-#include <linux/miscdevice.h>
-#include <linux/platform_device.h>
-#include <linux/moduleparam.h>
 #include <linux/timer.h>
-/* #include <mach/am_regs.h> */
-#include <linux/amlogic/media/vfm/vframe.h>
-#include <linux/spinlock.h>
-#include <linux/amlogic/iomap.h>
+#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
 #include "ldim_drv.h"
-#include "ldim_func.h"
 #include "ldim_reg.h"
-#include <linux/amlogic/media/vout/lcd/aml_bl.h>
-#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
 
 #ifndef MIN
 #define MIN(a, b)   ((a < b) ? a:b)
 #endif
 
+#define Wr(reg, val)    Wr_reg(reg, val)
+#define Rd(reg)         Rd_reg(reg)
+
 static int LD_STA1max_Hidx[25] = {
        /*  U12* 25     */
        0, 480, 960, 1440, 1920, 2400, 2880,
@@ -759,7 +748,7 @@ void LD_MtxInv(int *oDat, int *iDat, int nRow, int nCol)
        }
 }
 
-static int Remap_lut[16][32] = {
+int LD_remap_lut[16][32] = {
        {
                128, 258, 387, 517, 646, 776, 905, 1034,
                1163, 1291, 1420, 1548, 1676, 1804, 1932, 2059,
@@ -859,7 +848,7 @@ static int Remap_lut[16][32] = {
 };
 
 static int Remap_lut2[16][16] = {};
-void LD_LUTInit(struct LDReg *Reg)
+void LD_LUTInit(struct LDReg_s *Reg)
 {
        int i, j, k, t;
        struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
@@ -868,8 +857,8 @@ void LD_LUTInit(struct LDReg *Reg)
        case BL_CHIP_TXLX:
                for (i = 0; i < 16; i++) {
                        for (j = 0; j < 16; j++)
-                               Remap_lut2[i][j] = Remap_lut[i][j * 2] |
-                                       (Remap_lut[i][j * 2 + 1] << 16);
+                               Remap_lut2[i][j] = LD_remap_lut[i][j * 2] |
+                                       (LD_remap_lut[i][j * 2 + 1] << 16);
                }
                /* Emulate the FW to set the LUTs */
                for (k = 0; k < 16; k++) {
@@ -892,9 +881,9 @@ void LD_LUTInit(struct LDReg *Reg)
                        Reg->X_idx[0][k] = 4095 - 256 * k;
                        Reg->X_nrm[0][k] = 8;
                        for (t = 0; t < 32; t++) {
-                               Reg->X_lut[0][k][t] = Remap_lut[k][t];
-                               Reg->X_lut[1][k][t] = Remap_lut[k][t];
-                               Reg->X_lut[2][k][t] = Remap_lut[k][t];
+                               Reg->X_lut[0][k][t] = LD_remap_lut[k][t];
+                               Reg->X_lut[1][k][t] = LD_remap_lut[k][t];
+                               Reg->X_lut[2][k][t] = LD_remap_lut[k][t];
                        }
                }
                break;
@@ -903,7 +892,7 @@ void LD_LUTInit(struct LDReg *Reg)
        }
 }
 
-static void ConLDReg_GXTVBB(struct LDReg *Reg)
+static void ConLDReg_GXTVBB(struct LDReg_s *Reg)
 {
        unsigned int T = 0;
        unsigned int Vnum = 0;
@@ -1147,7 +1136,7 @@ static void ConLDReg_GXTVBB(struct LDReg *Reg)
 }
 
 
-static void ConLDReg_TXLX(struct LDReg *Reg)
+static void ConLDReg_TXLX(struct LDReg_s *Reg)
 {
        int i, j;
        unsigned int T = 0;
@@ -1402,7 +1391,7 @@ static void ConLDReg_TXLX(struct LDReg *Reg)
 
 
 #if 1
-void LD_ConLDReg(struct LDReg *Reg)
+void LD_ConLDReg(struct LDReg_s *Reg)
 {
        struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
 
@@ -1422,7 +1411,7 @@ void LD_ConLDReg(struct LDReg *Reg)
        /* 0: left/top side,
         *      1: right/bot side, others: non-one-side
         */
-void ld_fw_cfg_once(struct LDReg *nPRM)
+void ld_fw_cfg_once(struct LDReg_s *nPRM)
 {
        int k, dlt, j, i;
        int hofst = 4;
diff --git a/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.h b/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.h
deleted file mode 100644 (file)
index c714f26..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * drivers/amlogic/media/vout/backlight/aml_ldim/ldim_func.h
- *
- * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- */
-
-#include <linux/cdev.h>
-#include <linux/amlogic/iomap.h>
-
-#define Wr_reg_bits(adr, val, start, len)  \
-               aml_vcbus_update_bits(adr, ((1<<len)-1)<<start, val<<start)
-/*     #define Rd_reg_bits(adr, start, len)  \
- *             (aml_read_vcbus(adr)&(((1<<len)-1)<<start))
- */
-#define Rd_reg_bits(adr, start, len)  \
-               ((aml_read_vcbus(adr)>>start)&((1<<len)-1))
-
-extern int  ldim_round(int ix, int ib);
-extern void ldim_stts_en(unsigned int resolution, unsigned int pix_drop_mode,
-       unsigned int eol_en, unsigned int hist_mode, unsigned int lpf_en,
-       unsigned int rd_idx_auto_inc_mode, unsigned int one_ram_en);
-extern void ldim_set_region(unsigned int resolution, unsigned int blk_height,
-       unsigned int blk_width, unsigned int row_start, unsigned int col_start,
-       unsigned int blk_hnum);
-extern void LD_ConLDReg(struct LDReg *Reg);
-extern void ld_fw_cfg_once(struct LDReg *nPRM);
-extern void ldim_stts_read_region(unsigned int nrow, unsigned int ncol);
-
-extern void ldim_set_matrix_ycbcr2rgb(void);
-extern void ldim_set_matrix_rgb2ycbcr(int mode);
-
index 69eeb8dbbf9736c3d492dc02285fd54e8008201b..6ffa062c92c95a1806c2485a2b92d951dbf8d304 100644 (file)
  *
  */
 
-#define LDIM_BL_ADDR_PORT                              0x144e
-#define LDIM_BL_DATA_PORT                              0x144f
+#include <linux/amlogic/iomap.h>
+#include <linux/amlogic/media/utils/vdec_reg.h>
+
+#define LDIM_BL_ADDR_PORT                      0x144e
+#define LDIM_BL_DATA_PORT                      0x144f
 #define ASSIST_SPARE8_REG1                     0x1f58
 
 /*gxtvbb new add*/
-#define LDIM_STTS_CTRL0                                        0x1ac1
-#define LDIM_STTS_GCLK_CTRL0                                           0x1ac0
-#define LDIM_STTS_WIDTHM1_HEIGHTM1                     0x1ac2
-#define LDIM_STTS_MATRIX_COEF00_01                     0x1ac3
-#define LDIM_STTS_MATRIX_COEF02_10                     0x1ac4
-#define LDIM_STTS_MATRIX_COEF11_12                     0x1ac5
-#define LDIM_STTS_MATRIX_COEF20_21                     0x1ac6
-#define LDIM_STTS_MATRIX_COEF22                                        0x1ac7
-#define LDIM_STTS_MATRIX_OFFSET0_1                     0x1ac8
-#define LDIM_STTS_MATRIX_OFFSET2                               0x1ac9
-#define LDIM_STTS_MATRIX_PRE_OFFSET0_1 0x1aca
+#define LDIM_STTS_CTRL0                                0x1ac1
+#define LDIM_STTS_GCLK_CTRL0                   0x1ac0
+#define LDIM_STTS_WIDTHM1_HEIGHTM1             0x1ac2
+#define LDIM_STTS_MATRIX_COEF00_01             0x1ac3
+#define LDIM_STTS_MATRIX_COEF02_10             0x1ac4
+#define LDIM_STTS_MATRIX_COEF11_12             0x1ac5
+#define LDIM_STTS_MATRIX_COEF20_21             0x1ac6
+#define LDIM_STTS_MATRIX_COEF22                        0x1ac7
+#define LDIM_STTS_MATRIX_OFFSET0_1             0x1ac8
+#define LDIM_STTS_MATRIX_OFFSET2               0x1ac9
+#define LDIM_STTS_MATRIX_PRE_OFFSET0_1         0x1aca
 #define LDIM_STTS_MATRIX_PRE_OFFSET2           0x1acb
-#define LDIM_STTS_MATRIX_HL_COLOR                              0x1acc
-#define LDIM_STTS_MATRIX_PROBE_POS                     0x1acd
+#define LDIM_STTS_MATRIX_HL_COLOR              0x1acc
+#define LDIM_STTS_MATRIX_PROBE_POS             0x1acd
 #define LDIM_STTS_MATRIX_PROBE_COLOR           0x1ace
-#define LDIM_STTS_HIST_REGION_IDX                              0x1ad0
-#define LDIM_STTS_HIST_SET_REGION                              0x1ad1
-#define LDIM_STTS_HIST_READ_REGION                     0x1ad2
-#define LDIM_STTS_HIST_START_RD_REGION  0x1ad3
+#define LDIM_STTS_HIST_REGION_IDX              0x1ad0
+#define LDIM_STTS_HIST_SET_REGION              0x1ad1
+#define LDIM_STTS_HIST_READ_REGION             0x1ad2
+#define LDIM_STTS_HIST_START_RD_REGION         0x1ad3
+
+#define VDIN0_HIST_CTRL                                0x1230
+
+
+/*** GXTVBB & TXLX common use register*/
+/* each base has 16 address space */
+#define REG_LD_CFG_BASE           0x00
+#define REG_LD_RGB_IDX_BASE       0x10
+#define REG_LD_RGB_LUT_BASE       0x2000
+#define REG_LD_MATRIX_BASE        0x3000
+/* LD_CFG_BASE */
+#define REG_LD_FRM_SIZE           0x0
+#define REG_LD_RGB_MOD            0x1
+#define REG_LD_BLK_HVNUM          0x2
+#define REG_LD_HVGAIN             0x3
+#define REG_LD_BKLIT_VLD          0x4
+#define REG_LD_BKLIT_PARAM        0x5
+#define REG_LD_LIT_GAIN_COMP      0x7
+#define REG_LD_FRM_RST_POS        0x8
+#define REG_LD_FRM_BL_START_POS   0x9
+#define REG_LD_MISC_CTRL0         0xa
+#define REG_LD_FRM_HBLAN_VHOLS    0xb
+#define REG_LD_XLUT_DEMO_ROI_XPOS 0xc
+#define REG_LD_XLUT_DEMO_ROI_YPOS 0xd
+#define REG_LD_XLUT_DEMO_ROI_CTRL 0xe
+
+
+/* each base has 16 address space */
+/******  GXTVBB ******/
+#define REG_LD_G_IDX_BASE          0x20
+#define REG_LD_B_IDX_BASE          0x30
+#define REG_LD_RGB_NRMW_BASE       0x40
+#define REG_LD_LUT_HDG_BASE        0x50
+#define REG_LD_LUT_VHK_BASE        0x60
+#define REG_LD_LUT_VDG_BASE        0x70
+#define REG_LD_BLK_HIDX_BASE       0x80
+#define REG_LD_BLK_VIDX_BASE       0xa0
+#define REG_LD_LUT_VHK_NEGPOS_BASE 0xc0
+#define REG_LD_LUT_VHO_NEGPOS_BASE 0xd0
+#define REG_LD_LUT_HHK_BASE        0xe0
+#define REG_LD_REFLECT_DGR_BASE    0xf0
+/* LD_CFG_BASE */
+#define REG_LD_LUT_XDG_LEXT        0x6
+
+
+
+/* each base has 16 address space */
+/******  TXLX  ******/
+#define REG_LD_RGB_NRMW_BASE_TXLX       0x20
+#define REG_LD_BLK_HIDX_BASE_TXLX       0x30
+#define REG_LD_BLK_VIDX_BASE_TXLX       0x50
+#define REG_LD_LUT_VHK_NEGPOS_BASE_TXLX 0x60
+#define REG_LD_LUT_VHO_NEGPOS_BASE_TXLX 0x70
+#define REG_LD_LUT_HHK_BASE_TXLX        0x80
+#define REG_LD_REFLECT_DGR_BASE_TXLX    0x90
+#define REG_LD_LUT_LEXT_BASE_TXLX       0xa0
+#define REG_LD_LUT_HDG_BASE_TXLX        0x100
+#define REG_LD_LUT_VDG_BASE_TXLX        0x180
+#define REG_LD_LUT_VHK_BASE_TXLX        0x200
+#define REG_LD_LUT_ID_BASE_TXLX         0x300
+/* LD_CFG_BASE */
+#define REG_LD_BLMAT_RAM_MISC           0xf
+
+/* #define LDIM_STTS_HIST_REGION_IDX      0x1aa0 */
+#define LOCAL_DIM_STATISTIC_EN_BIT          31
+#define LOCAL_DIM_STATISTIC_EN_WID           1
+#define EOL_EN_BIT                          28
+#define EOL_EN_WID                           1
+
+/* 0: 17 pix, 1: 9 pix, 2: 5 pix, 3: 3 pix, 4: 0 pix */
+#define HOVLP_NUM_SEL_BIT                   21
+#define HOVLP_NUM_SEL_WID                    2
+#define LPF_BEFORE_STATISTIC_EN_BIT         20
+#define LPF_BEFORE_STATISTIC_EN_WID          1
+#define BLK_HV_POS_IDXS_BIT                 16
+#define BLK_HV_POS_IDXS_WID                  4
+#define RD_INDEX_INC_MODE_BIT               14
+#define RD_INDEX_INC_MODE_WID                2
+#define REGION_RD_SUB_INDEX_BIT              8
+#define REGION_RD_SUB_INDEX_WID              4
+#define REGION_RD_INDEX_BIT                  0
+#define REGION_RD_INDEX_WID                  7
+
+
+#ifndef CONFIG_AMLOGIC_MEDIA_RDMA
+#define LDIM_VSYNC_RDMA      0
+#else
+#define LDIM_VSYNC_RDMA      0
+#endif
+
+#define Wr_reg_bits(adr, val, start, len)  \
+               aml_vcbus_update_bits(adr, ((1<<len)-1)<<start, val<<start)
+#define Rd_reg_bits(adr, start, len)  \
+               ((aml_read_vcbus(adr)>>start)&((1<<len)-1))
+
+#define Wr_reg(reg, val)    aml_write_vcbus(reg, val)
+#define Rd_reg(reg)         aml_read_vcbus(reg)
+
+
+static inline void LDIM_WR_32Bits(unsigned int addr, unsigned int data)
+{
+#if (LDIM_VSYNC_RDMA == 1)
+       VSYNC_WR_MPEG_REG(LDIM_BL_ADDR_PORT, addr);
+       VSYNC_WR_MPEG_REG(LDIM_BL_DATA_PORT, data);
+#else
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+       aml_write_vcbus(LDIM_BL_DATA_PORT, data);
+#endif
+}
+
+static inline unsigned int LDIM_RD_32Bits(unsigned int addr)
+{
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+       return aml_read_vcbus(LDIM_BL_DATA_PORT);
+}
+
+static inline void LDIM_wr_reg_bits(unsigned int addr, unsigned int val,
+                               unsigned int start, unsigned int len)
+{
+       unsigned int data;
 
-#define VDIN0_HIST_CTRL                        0x1230
+       data = LDIM_RD_32Bits(addr);
+       data = (data & (~((1 << len) - 1)<<start))  |
+               ((val & ((1 << len) - 1)) << start);
+       LDIM_WR_32Bits(addr, data);
+}
 
-static inline void W_APB_BIT(unsigned int reg,
-                                   unsigned int value,
-                                   unsigned int start,
-                                   unsigned int  len)
+static inline void LDIM_WR_BASE_LUT(unsigned int base, unsigned int *pData,
+                               unsigned int size_t, unsigned int len)
 {
-       aml_write_vcbus(reg, ((aml_read_vcbus(reg) &
-                            ~(((1L << (len)) - 1) << (start))) |
-                           (((value) & ((1L << (len)) - 1)) << (start))));
+       unsigned int i;
+       unsigned int addr, data;
+       unsigned int mask, subCnt;
+       unsigned int cnt;
+
+       addr   = base;/* (base<<4); */
+       mask   = (1 << size_t)-1;
+       subCnt = 32 / size_t;
+       cnt  = 0;
+       data = 0;
+
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+
+       for (i = 0; i < len; i++) {
+               data = data | ((pData[i] & mask) << (size_t *cnt));
+               cnt++;
+               if (cnt == subCnt) {
+                       aml_write_vcbus(LDIM_BL_DATA_PORT, data);
+                       data = 0;
+                       cnt = 0;
+                       addr++;
+               }
+       }
+       if (cnt != 0)
+               aml_write_vcbus(LDIM_BL_DATA_PORT, data);
 }
 
+static inline void LDIM_RD_BASE_LUT(unsigned int base, unsigned int *pData,
+                               unsigned int size_t, unsigned int len)
+{
+       unsigned int i;
+       unsigned int addr, data;
+       unsigned int mask, subCnt;
+       unsigned int cnt;
+
+       addr   = base;/* (base<<4); */
+       mask   = (1 << size_t)-1;
+       subCnt = 32 / size_t;
+       cnt  = 0;
+       data = 0;
 
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+
+       for (i = 0; i < len; i++) {
+               cnt++;
+               if (cnt == subCnt) {
+                       data = aml_read_vcbus(LDIM_BL_DATA_PORT);
+                       pData[i-1] = data & mask;
+                       pData[i] = mask & (data >> size_t);
+                       data = 0;
+                       cnt = 0;
+                       addr++;
+               }
+       }
+       if (cnt != 0)
+               data = aml_read_vcbus(LDIM_BL_DATA_PORT);
+}
+
+static inline void LDIM_RD_BASE_LUT_2(unsigned int base, unsigned int *pData,
+                               unsigned int size_t, unsigned int len)
+{
+       unsigned int i;
+       unsigned int addr, data;
+       unsigned int mask, subCnt;
+       unsigned int cnt;
+
+       addr   = base;/* (base<<4); */
+       mask   = (1 << size_t)-1;
+       subCnt = 2;
+       cnt  = 0;
+       data = 0;
+
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+
+       for (i = 0; i < len; i++) {
+               cnt++;
+               if (cnt == subCnt) {
+                       data = aml_read_vcbus(LDIM_BL_DATA_PORT);
+                       pData[i-1] = data & mask;
+                       pData[i] = mask & (data >> size_t);
+                       data = 0;
+                       cnt = 0;
+                       addr++;
+               }
+       }
+       if (cnt != 0)
+               data = aml_read_vcbus(LDIM_BL_DATA_PORT);
+}
+
+static inline void LDIM_WR_BASE_LUT_DRT(int base, int *pData, int len)
+{
+       int i;
+       int addr;
+
+       addr  = base;/*(base<<4)*/
+#if (LDIM_VSYNC_RDMA == 1)
+       VSYNC_WR_MPEG_REG(LDIM_BL_ADDR_PORT, addr);
+       for (i = 0; i < len; i++)
+               VSYNC_WR_MPEG_REG(LDIM_BL_DATA_PORT, pData[i]);
+#else
+       aml_write_vcbus(LDIM_BL_ADDR_PORT, addr);
+       for (i = 0; i < len; i++)
+               aml_write_vcbus(LDIM_BL_DATA_PORT, pData[i]);
+#endif
+}
 
index dac5accad6a1c2a62810d5606fb80a2be5721747..6852f7c0f05e2726d3594aa49566bd3da4f6bc75 100644 (file)
 #include <linux/amlogic/media/vout/lcd/aml_bl.h>
 #include <linux/spi/spi.h>
 
+/*#define LDIM_DEBUG_INFO*/
+#define LDIMPR(fmt, args...)     pr_info("ldim: "fmt"", ## args)
+#define LDIMERR(fmt, args...)    pr_err("ldim: error: "fmt"", ## args)
+
+
+#define LD_STA_BIN_NUM 16
+#define LD_STA_LEN_V   17
+/*  support maximum 16x4 regions for statistics (16+1) */
+#define LD_STA_LEN_H   25
+/*  support maximum 16x4 regions for statistics (24+1)*/
+#define LD_BLK_LEN_V   25
+/*  support maximum 16 led of each side left/right(16+4+4+1)*/
+#define LD_BLK_LEN_H   33
+/*  support maximum 24 led of each side top/bot  (24+4+4+1)*/
+#define LD_LUT_LEN     32
+#define LD_BLKHMAX     32
+#define LD_BLKVMAX     32
+
+
+#define LD_DATA_DEPTH   12
+#define LD_DATA_MIN     10
+#define LD_DATA_MAX     0xfff
+
+
 extern int  dirspi_write(struct spi_device *spi, u8 *buf, int len);
 extern int  dirspi_read(struct spi_device *spi, u8 *buf, int len);
 extern void dirspi_start(struct spi_device *spi);
diff --git a/include/linux/amlogic/media/vout/lcd/ldim_alg.h b/include/linux/amlogic/media/vout/lcd/ldim_alg.h
new file mode 100644 (file)
index 0000000..f5cbbc3
--- /dev/null
@@ -0,0 +1,337 @@
+/*
+ * include/linux/amlogic/media/vout/lcd/ldim_alg.h
+ *
+ * Copyright (C) 2017 Amlogic, Inc. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#ifndef _INC_AML_LDIM_ALG_H_
+#define _INC_AML_LDIM_ALG_H_
+#include <linux/amlogic/media/vout/lcd/aml_ldim.h>
+
+/*========================================*/
+#define LD_STA_BIN_NUM 16
+#define LD_STA_LEN_V 17
+/*  support maximum 16x4 regions for statistics (16+1) */
+#define LD_STA_LEN_H 25
+/*  support maximum 16x4 regions for statistics (24+1)*/
+#define LD_BLK_LEN_V 25
+/*  support maximum 16 led of each side left/right(16+4+4+1)*/
+#define LD_BLK_LEN_H 33
+/*  support maximum 24 led of each side top/bot  (24+4+4+1)*/
+#define LD_LUT_LEN 32
+#define LD_BLKHMAX 32
+#define LD_BLKVMAX 32
+
+struct LDReg_s {
+       int reg_LD_pic_RowMax;            /*u13*/
+       int reg_LD_pic_ColMax;            /*u13*/
+       int reg_LD_pic_YUVsum[3];
+       /* only output u16*3, (internal ACC will be u32x3)*/
+       int reg_LD_pic_RGBsum[3];
+       /* Statistic options */
+       int reg_LD_STA_Vnum;
+       /*u8: statistic region number of V, maximum to (STA_LEN_V-1)   (0~16)*/
+       int reg_LD_STA_Hnum;
+       /*u8: statistic region number of H, maximum to (STA_LEN_H-1)   (0~24)*/
+       int reg_LD_BLK_Vnum;
+       /*u8: Maximum to 16*/
+       int reg_LD_BLK_Hnum;
+       /*u8: Maximum to 24*/
+       int reg_LD_STA1max_LPF;
+       /*u1: STA1max statistics on [1 2 1]/4 filtered results*/
+       int reg_LD_STA2max_LPF;
+       /*u1: STA2max statistics on [1 2 1]/4 filtered results*/
+       int reg_LD_STAhist_LPF;
+       /*u1: STAhist statistics on [1 2 1]/4 filtered results*/
+       int reg_LD_STA1max_Hdlt;
+       /* u2: (2^x) extra pixels into Max calculation*/
+       int reg_LD_STA1max_Vdlt;
+       /* u4: extra pixels into Max calculation vertically*/
+       int reg_LD_STA2max_Hdlt;
+       /* u2: (2^x) extra pixels into Max calculation*/
+       int reg_LD_STA2max_Vdlt;
+       /* u4: extra pixels into Max calculation vertically*/
+       int reg_LD_STA1max_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
+       int reg_LD_STA1max_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
+       int reg_LD_STA2max_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
+       int reg_LD_STA2max_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
+
+       int reg_LD_STAhist_mode;
+               /*u3: histogram statistics on XX separately 20bits*16bins:
+                *0: R-only,1:G-only 2:B-only 3:Y-only;
+                *4: MAX(R,G,B), 5/6/7: R&G&B
+                */
+       int reg_LD_STAhist_pix_drop_mode;
+               /* u2:histogram statistics pixel drop mode:
+                * 0:no drop; 1:only statistic
+                * x%2=0; 2:only statistic x%4=0; 3: only statistic x%8=0;
+                */
+       int reg_LD_STAhist_Hidx[LD_STA_LEN_H];  /* U12* STA_LEN_H*/
+       int reg_LD_STAhist_Vidx[LD_STA_LEN_V];  /* u12x STA_LEN_V*/
+
+       /***** FBC3 fw_hw_alg_frm *****/
+       int reg_ldfw_BLmax;/* maximum BL value*/
+       int reg_ldfw_blk_norm;
+               /*u8: normalization gain for blk number,
+                *1/blk_num= norm>>(rs+8), norm = (1<<(rs+8))/blk_num
+                */
+       int reg_ldfw_blk_norm_rs;/*u3: 0~7,  1/blk_num= norm>>(rs+8) */
+       int reg_ldfw_sta_hdg_weight[8];
+               /*  u8x8, weighting to each
+                * block's max to decide that block's ld.
+                */
+       int reg_ldfw_sta_max_mode;
+               /* u2: maximum selection for
+                *components: 0: r_max, 1: g_max, 2: b_max; 3: max(r,g,b)
+                */
+       int reg_ldfw_sta_max_hist_mode;
+               /* u2: mode of reference
+                * max/hist mode:0: MIN(max, hist), 1: MAX(max, hist)
+                * 2: (max+hist)/2, 3: (max(a,b)*3 + min(a,b))/4
+                */
+       int reg_ldfw_hist_valid_rate;
+               /* u8, norm to 512 as "1", if hist_matrix[i]>(rate*histavg)>>9*/
+       int reg_ldfw_hist_valid_ofst;/*u8, hist valid bin upward offset*/
+       int reg_ldfw_sedglit_RL;/*u1: single edge lit right/bottom mode*/
+       int reg_ldfw_sf_thrd;/*u12: threshold of difference to enable the sf;*/
+       int reg_ldfw_boost_gain;
+               /* u8: boost gain for the region that
+                * is larger than the average, norm to 16 as "1"
+                */
+       int reg_ldfw_tf_alpha_rate;
+               /*u8: rate to SFB_BL_matrix from
+                *last frame difference;
+                */
+       int reg_ldfw_tf_alpha_ofst;
+               /*u8: ofset to alpha SFB_BL_matrix
+                *from last frame difference;
+                */
+       int reg_ldfw_tf_disable_th;
+               /*u8: 4x is the threshod to disable
+                *tf to the alpha (SFB_BL_matrix from last frame difference;
+                */
+       int reg_ldfw_blest_acmode;
+               /*u3: 0: est on BLmatrix;
+                *1: est on(BL-DC); 2: est on (BL-MIN);
+                *3: est on (BL-MAX) 4: 2048; 5:1024
+                */
+       int reg_ldfw_sf_enable;
+       /*u1: enable signal for spatial filter on the tbl_matrix*/
+       int reg_ldfw_enable;
+       int reg_ldfw_sta_hdg_vflt;
+       int reg_ldfw_sta_norm;
+       int reg_ldfw_sta_norm_rs;
+       int reg_ldfw_tf_enable;
+       int reg_LD_LUT_Hdg_TXLX[8][32];
+       int reg_LD_LUT_Vdg_TXLX[8][32];
+       int reg_LD_LUT_VHk_TXLX[8][32];
+       int reg_LD_LUT_Id[16 * 24];
+       int reg_LD_LUT_Hdg_LEXT_TXLX[8];
+       int reg_LD_LUT_Vdg_LEXT_TXLX[8];
+       int reg_LD_LUT_VHk_LEXT_TXLX[8];
+       int reg_ldfw_boost_enable;
+               /*u1: enable signal for Boost
+                *filter on the tbl_matrix
+                */
+       int ro_ldfw_bl_matrix_avg;/*u12: read-only register for bl_matrix*/
+
+       /* Backlit Modeling registers*/
+       int BL_matrix[LD_BLKREGNUM];
+       /* Define the RAM Matrix*/
+       int reg_LD_BackLit_Xtlk;
+       /*u1: 0 no block to block Xtalk model needed;   1: Xtalk model needed*/
+       int reg_LD_BackLit_mode;
+       /*u2: 0- LEFT/RIGHT Edge Lit; 1- Top/Bot Edge Lit; 2 - DirectLit
+        *modeled H/V independent; 3- DirectLit modeled HV Circle distribution
+        */
+       int reg_LD_Reflect_Hnum;
+       /*u3: numbers of band reflection considered in Horizontal direction;
+        *      0~4
+        */
+       int reg_LD_Reflect_Vnum;
+       /*u3: numbers of band reflection considered in Horizontal direction;
+        *      0~4
+        */
+       int reg_LD_BkLit_curmod;
+       /*u1: 0: H/V separately, 1 Circle distribution*/
+       int reg_LD_BkLUT_Intmod;
+       /*u1: 0: linear interpolation, 1 cubical interpolation*/
+       int reg_LD_BkLit_Intmod;
+       /*u1: 0: linear interpolation, 1 cubical interpolation*/
+       int reg_LD_BkLit_LPFmod;
+       /*u3: 0: no LPF, 1:[1 14 1]/16;2:[1 6 1]/8; 3: [1 2 1]/4;
+        *      4:[9 14 9]/32  5/6/7: [5 6 5]/16;
+        */
+       int reg_LD_BkLit_Celnum;
+       /*u8: 0: 1920~ 61*/
+       int reg_BL_matrix_AVG;
+       /*u12: DC of whole picture BL to be subtract from BL_matrix
+        *      during modeling (Set by FW daynamically)
+        */
+       int reg_BL_matrix_Compensate;
+       /*u12: DC of whole picture BL to be compensated back to
+        *      Litfull after the model (Set by FW dynamically);
+        */
+       int reg_LD_Reflect_Hdgr[20];
+       /*20*u6:  cells 1~20 for H Gains of different dist of
+        * Left/Right;
+        */
+       int reg_LD_Reflect_Vdgr[20];
+       /*20*u6:  cells 1~20 for V Gains of different dist of Top/Bot;*/
+       int reg_LD_Reflect_Xdgr[4];     /*4*u6:*/
+       int reg_LD_Vgain;               /*u12*/
+       int reg_LD_Hgain;               /*u12*/
+       int reg_LD_Litgain;             /*u12*/
+       int reg_LD_Litshft;
+       /*u3   right shif of bits for the all Lit's sum*/
+       int reg_LD_BkLit_valid[32];
+       /*u1x32: valid bits for the 32 cell Bklit to contribut to current
+        *      position (refer to the backlit padding pattern)
+        */
+       /* region division index 1 2 3 4 5(0) 6(1) 7(2)
+        *      8(3) 9(4)  10(5)11(6)12(7)13(8) 14(9)15(10) 16 17 18 19
+        */
+       int reg_LD_BLK_Hidx[LD_BLK_LEN_H]; /* S14* BLK_LEN*/
+       int reg_LD_BLK_Vidx[LD_BLK_LEN_V]; /* S14* BLK_LEN*/
+       /* Define the RAM Matrix*/
+       int reg_LD_LUT_Hdg[LD_LUT_LEN];  /*u10*/
+       int reg_LD_LUT_Vdg[LD_LUT_LEN];  /*u10*/
+       int reg_LD_LUT_VHk[LD_LUT_LEN];  /*u10*/
+       /* VHk positive and negative side gain, normalized to 128
+        *      as "1" 20150428
+        */
+       int reg_LD_LUT_VHk_pos[32];   /* u8*/
+       int reg_LD_LUT_VHk_neg[32];   /* u8*/
+       int reg_LD_LUT_HHk[32];
+       /* u8 side gain for LED direction hdist gain for different LED*/
+       /* VHo possitive and negative side offset, use with LS, (x<<LS)*/
+       int reg_LD_LUT_VHo_pos[32];   /* s8*/
+       int reg_LD_LUT_VHo_neg[32];   /* s8*/
+       int reg_LD_LUT_VHo_LS;/* u3:0~6,left shift bits of VH0_pos/neg*/
+       /* adding three cells for left boundary extend during
+        *      Cubic interpolation
+        */
+       int reg_LD_LUT_Hdg_LEXT;
+       int reg_LD_LUT_Vdg_LEXT;
+       int reg_LD_LUT_VHk_LEXT;
+       /* adding demo window mode for LD for RGB lut compensation*/
+       int reg_LD_xlut_demo_roi_xstart;
+       /* u14 start col index of the region of interest*/
+       int reg_LD_xlut_demo_roi_xend;
+       /* u14 end col index of the region of interest*/
+       int reg_LD_xlut_demo_roi_ystart;
+       /* u14 start row index of the region of interest*/
+       int reg_LD_xlut_demo_roi_yend;
+       /* u14 end row index of the region of interest*/
+       int reg_LD_xlut_iroi_enable;
+       /* u1: enable rgb LUT remapping inside regon of interest:
+        *      0: no rgb remapping; 1: enable rgb remapping
+        */
+       int reg_LD_xlut_oroi_enable;
+       /* u1: enable rgb LUT remapping outside regon of interest:
+        *      0: no rgb remapping; 1: enable rgb remapping
+        */
+       /* Register used in RGB remapping*/
+       int reg_LD_RGBmapping_demo;
+       /*u2: 0 no demo mode 1: display BL_fulpel on RGB*/
+       int reg_LD_X_LUT_interp_mode[3];
+       /*U1 0: using linear interpolation between to neighbour LUT;
+        *      1: use the nearest LUT results
+        */
+       int X_idx[1][16];
+       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
+       int X_nrm[1][16];
+       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
+       int X_lut[3][16][32];
+       /* Changed to 16 Lits define 32 Bin LUT to save cost*/
+       /* only do the Lit modleing on the AC part*/
+       int X_lut2[3][16][16];
+       int fw_LD_BLEst_ACmode;
+       /*u2: 0: est on BLmatrix; 1: est on (BL-DC);
+        *      2: est on (BL-MIN); 3: est on (BL-MAX)
+        */
+};
+
+struct FW_DAT_s {
+       /* for temporary Firmware algorithm */
+       unsigned int *TF_BL_alpha;
+       unsigned int *last_YUVsum;
+       unsigned int *last_RGBsum;
+       unsigned int *last_STA1_MaxRGB;
+       unsigned int *SF_BL_matrix;
+       unsigned int *TF_BL_matrix;
+       unsigned int *TF_BL_matrix_2;
+};
+
+struct ldim_fw_para_s {
+       char ver_str[20];
+       unsigned char ver_num;
+       unsigned char hist_col;
+       unsigned char hist_row;
+
+       struct LDReg_s *nPRM;
+       struct FW_DAT_s *FDat;
+       unsigned long *bl_remap_curve; /* size: 16 */
+       unsigned long *fw_LD_Whist;    /* size: 16 */
+
+       unsigned long fw_LD_ThSF_l;
+       unsigned long fw_LD_ThTF_l;
+       unsigned long boost_gain; /*norm 256 to 1,T960 finally use*/
+       unsigned long TF_alpha; /*256;*/
+       unsigned long lpf_gain;  /* [0~128~256], norm 128 as 1*/
+
+       unsigned long boost_gain_neg;
+       unsigned long alpha_delta;
+
+       /*LPF tap: 0-lpf_res 41,1-lpf_res 114,...*/
+       unsigned long lpf_res;    /* 1024/9*9 = 13,LPF_method=3 */
+       unsigned long rgb_base;
+
+       unsigned int ov_gain;
+       /*unsigned int incr_dif_gain; //16 */
+
+       unsigned long avg_gain;
+
+       unsigned int fw_rgb_diff_th;
+       unsigned int max_luma;
+       unsigned int lmh_avg_TH;/*for woman flicker*/
+       unsigned int fw_TF_sum_th;/*20180530*/
+
+       unsigned int LPF_method;
+       unsigned int LD_TF_STEP_TH;
+       unsigned int TF_step_method;
+       unsigned int TF_FRESH_BL;
+
+       unsigned int TF_BLK_FRESH_BL;
+       unsigned int side_blk_diff_th;
+       unsigned int bbd_th;
+       unsigned char bbd_detect_en;
+       unsigned char diff_blk_luma_en;
+
+       unsigned char Sf_bypass, Boost_light_bypass;
+       unsigned char Lpf_bypass, Ld_remap_bypass;
+       unsigned char black_frm;
+
+       /* for debug print */
+       unsigned char fw_hist_print;/*20180525*/
+       unsigned int fw_print_frequent;/*20180606,print every 8 frame*/
+       unsigned int Dbprint_lv;
+
+       void (*fw_alg_frm)(struct ldim_fw_para_s *fw_para,
+               unsigned int *max_matrix, unsigned int *hist_matrix);
+};
+
+extern struct ldim_fw_para_s *aml_ldim_get_fw_para(void);
+
+#endif