lcd: local dimming: add unifykey support [2/2]
authorWeiming Liu <weiming.liu@amlogic.com>
Tue, 15 May 2018 11:29:01 +0000 (19:29 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Tue, 22 May 2018 07:33:49 +0000 (00:33 -0700)
PD#166418: ldim: add unifykey support

Change-Id: I0cb7629ed9824c50d5f85b7ec34e26c165a60a1e
Signed-off-by: Weiming Liu <weiming.liu@amlogic.com>
arch/arm64/boot/dts/amlogic/mesontxlx_r311-panel.dtsi
drivers/amlogic/media/vout/backlight/aml_bl.c
drivers/amlogic/media/vout/backlight/aml_ldim/ldim_drv.c
include/linux/amlogic/media/vout/lcd/aml_ldim.h

index 010ea2b..a2cce58 100644 (file)
                                50>;/*duty(%)*/
                        spi_bus_num = <0>;
                        spi_chip_select = <0>;
-                       spi_max_frequency = <400000>; /* unit: hz */
+                       spi_max_frequency = <1000000>; /* unit: hz */
                        spi_mode = <0>; /* mode: 0, 1, 2, 3 */
                        spi_cs_delay = <10  /* hold_high_delay */
                                100>; /* clk_cs_delay (unit: us) */
index 22fbdb5..d2119ea 100644 (file)
@@ -1863,6 +1863,11 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf)
                bl_pwm_config_init(pwm_combo0);
                bl_pwm_config_init(pwm_combo1);
                break;
+#ifdef CONFIG_AMLOGIC_LOCAL_DIMMING
+       case BL_CTRL_LOCAL_DIMING:
+               bconf->ldim_flag = 1;
+               break;
+#endif
        default:
                break;
        }
@@ -1998,7 +2003,7 @@ static int aml_bl_config_load(struct bl_config_s *bconf,
 
 #ifdef CONFIG_AMLOGIC_LOCAL_DIMMING
        if (bconf->ldim_flag)
-               aml_ldim_probe(pdev);
+               aml_ldim_probe(pdev, load_id);
 #endif
 
        switch (bconf->method) {
index 78d067c..484d14b 100644 (file)
@@ -52,6 +52,8 @@
 #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>
+
 
 #define AML_LDIM_DEV_NAME            "aml_ldim"
 const char ldim_dev_id[] = "ldim-dev";
@@ -2960,7 +2962,7 @@ static struct class_attribute aml_ldim_class_attrs[] = {
        __ATTR_NULL,
 };
 
-static int aml_ldim_get_config(struct ldim_config_s *ldconf,
+static int aml_ldim_get_config_dts(struct ldim_config_s *ldconf,
                struct device *dev)
 {
        struct vinfo_s *vinfo = get_current_vinfo();
@@ -3046,6 +3048,98 @@ static int aml_ldim_get_config(struct ldim_config_s *ldconf,
        return 0;
 }
 
+static int aml_ldim_get_config_unifykey(struct ldim_config_s *ldconf)
+{
+       unsigned char *para;
+       int key_len, len;
+       unsigned char *p;
+       struct aml_lcd_unifykey_header_s bl_header;
+       struct aml_bl_drv_s *bl_drv = aml_bl_get_driver();
+       struct vinfo_s *vinfo = get_current_vinfo();
+       int i, ret;
+
+       ldconf->hsize = vinfo->width;
+       ldconf->vsize = vinfo->height;
+       for (i = 0; i < LD_BLKREGNUM; i++)
+               ldconf->bl_mapping[i] = (unsigned short)i;
+
+       para = kmalloc((sizeof(unsigned char) * LCD_UKEY_BL_SIZE), GFP_KERNEL);
+       if (!para) {
+               BLERR("%s: Not enough memory\n", __func__);
+               return -1;
+       }
+
+       key_len = LCD_UKEY_BL_SIZE;
+       memset(para, 0, (sizeof(unsigned char) * key_len));
+       ret = lcd_unifykey_get("backlight", para, &key_len);
+       if (ret < 0) {
+               kfree(para);
+               return -1;
+       }
+
+       /* step 1: check header */
+       len = LCD_UKEY_HEAD_SIZE;
+       ret = lcd_unifykey_len_check(key_len, len);
+       if (ret < 0) {
+               BLERR("unifykey header length is incorrect\n");
+               kfree(para);
+               return -1;
+       }
+
+       lcd_unifykey_header_check(para, &bl_header);
+       BLPR("unifykey version: 0x%04x\n", bl_header.version);
+       switch (bl_header.version) {
+       case 2:
+               len = 10 + 30 + 12 + 8 + 32 + 10;
+               break;
+       default:
+               len = 10 + 30 + 12 + 8 + 32;
+               break;
+       }
+
+       /* step 2: check backlight parameters */
+       ret = lcd_unifykey_len_check(key_len, len);
+       if (ret < 0) {
+               BLERR("unifykey length is incorrect\n");
+               kfree(para);
+               return -1;
+       }
+
+       /* 60byte */
+       p = para + 60;
+
+       /* ldim: 24byte */
+       switch (bl_drv->bconf->method) {
+       case BL_CTRL_LOCAL_DIMING:
+               /* get bl_ldim_region_row_col 4byte*/
+               ldim_blk_row = (*p | ((*(p + 1)) << 8));
+               ldim_blk_col = (*(p + 2) | ((*(p + 3)) << 8));
+               ldim_hist_row = ldim_blk_row;
+               ldim_hist_col = ldim_blk_col;
+               if (ldim_debug_print) {
+                       LDIMPR("get region row = %d, col = %d\n",
+                               ldim_blk_row, ldim_blk_col);
+               }
+
+               /* get ldim_dev_index 1byte*/
+               ldim_driver.dev_index = *(p + 4);
+               if (ldim_debug_print)
+                       LDIMPR("get dev_index = %d\n", ldim_driver.dev_index);
+
+               /* get bl_ldim_mode 1byte*/
+               ldconf->bl_mode = *(p + 5);
+               if (ldim_debug_print)
+                       LDIMPR("get bl_mode = %d\n", ldconf->bl_mode);
+
+               break;
+       default:
+               break;
+       }
+
+       kfree(para);
+       return 0;
+}
+
 static int aml_ldim_kzalloc(unsigned int ldim_blk_row1,
        unsigned int ldim_blk_col1)
 {
@@ -3136,7 +3230,7 @@ err0:
 
 }
 
-int aml_ldim_probe(struct platform_device *pdev)
+int aml_ldim_probe(struct platform_device *pdev, int load_id)
 {
        int ret = 0;
        unsigned int i;
@@ -3169,7 +3263,11 @@ int aml_ldim_probe(struct platform_device *pdev)
        nPRM.bin_1 = &bin_1[0];
        nPRM.val_2 = &val_2[0];
        nPRM.bin_2 = &bin_2[0];
-       aml_ldim_get_config(&ldim_config, &pdev->dev);
+       if (load_id)
+               aml_ldim_get_config_unifykey(&ldim_config);
+       else
+               aml_ldim_get_config_dts(&ldim_config, &pdev->dev);
+
        aml_ldim_kzalloc(ldim_blk_row, ldim_blk_col);
 
        ret = alloc_chrdev_region(&devp->aml_ldim_devno, 0, 1,
index 5e3ad23..03ea281 100644 (file)
@@ -117,7 +117,7 @@ struct vpu_ldim_param_s {
 };
 
 extern struct aml_ldim_driver_s *aml_ldim_get_driver(void);
-extern int aml_ldim_probe(struct platform_device *pdev);
+extern int aml_ldim_probe(struct platform_device *pdev, int load_id);
 extern int aml_ldim_remove(void);
 
 #endif