lcd: add prbs test support [2/2]
authorEvoke Zhang <evoke.zhang@amlogic.com>
Tue, 8 Oct 2019 11:07:24 +0000 (19:07 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Thu, 24 Oct 2019 02:26:46 +0000 (19:26 -0700)
PD#SWPL-15371

Problem:
need lcd prbs test

Solution:
add lcd prbs test function

Verify:
x301

Change-Id: Id218acb1585713e920b361d7597ab0868e706390
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
drivers/amlogic/media/vout/lcd/lcd_debug.c

index 777612b..bb501a5 100644 (file)
@@ -1532,6 +1532,114 @@ static void lcd_screen_black(void)
        lcd_mute_setting(1);
 }
 
+static unsigned int lcd_prbs_flag;
+static unsigned int lcd_prbs_cnt;
+static void aml_lcd_prbs_test(unsigned int s)
+{
+       struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver();
+       unsigned int reg0, reg1;
+       unsigned int val1, val2, cnt = 0, timeout;
+       int i, ret;
+
+       switch (lcd_drv->data->chip_type) {
+       case LCD_CHIP_GXL:
+       case LCD_CHIP_GXM:
+       case LCD_CHIP_AXG:
+       case LCD_CHIP_G12A:
+       case LCD_CHIP_G12B:
+       case LCD_CHIP_SM1:
+               LCDERR("not support\n");
+               return;
+       case LCD_CHIP_TXL:
+       case LCD_CHIP_TXLX:
+               reg0 = HHI_LVDS_TX_PHY_CNTL0;
+               reg1 = HHI_LVDS_TX_PHY_CNTL1;
+               break;
+       default:
+               reg0 = HHI_LVDS_TX_PHY_CNTL0_TL1;
+               reg1 = HHI_LVDS_TX_PHY_CNTL1_TL1;
+               break;
+       }
+
+       lcd_hiu_write(reg0, 0xfff20c4);
+       lcd_hiu_setb(reg0, 1, 12, 1);
+       val1 = lcd_hiu_getb(reg1, 12, 12);
+
+       s = (s > 1800) ? 1800 : s;
+       timeout = s * 200;
+       while (lcd_prbs_flag) {
+               if (s > 1) { /* when s=1, means always run */
+                       if (cnt++ >= timeout)
+                               break;
+               }
+               usleep_range(5000, 5001);
+               ret = 1;
+               for (i = 0; i < 5; i++) {
+                       val2 = lcd_hiu_getb(reg1, 12, 12);
+                       if (val2 != val1) {
+                               ret = 0;
+                               break;
+                       }
+               }
+               if (ret) {
+                       LCDERR("lcd prbs check error 1, val:0x%03x, cnt:%d\n",
+                              val2, lcd_prbs_cnt);
+                       return;
+               }
+               val1 = val2;
+               if (lcd_hiu_getb(reg1, 0, 12)) {
+                       LCDERR("lcd prbs check error 2, cnt:%d\n",
+                              lcd_prbs_cnt);
+                       return;
+               }
+               if (lcd_prbs_cnt >= 0xffffffff)
+                       lcd_prbs_cnt = 0;
+               else
+                       lcd_prbs_cnt++;
+       }
+
+       lcd_prbs_cnt = 0;
+       LCDPR("lcd prbs check ok\n");
+}
+
+static ssize_t lcd_debug_prbs_show(struct class *class,
+                                  struct class_attribute *attr, char *buf)
+{
+       return sprintf(buf, "lcd prbs flag: %d, cnt: %d\n",
+                      lcd_prbs_flag, lcd_prbs_cnt);
+}
+
+static ssize_t lcd_debug_prbs_store(struct class *class,
+                                   struct class_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       int ret = 0;
+       unsigned int temp = 1;
+
+       ret = kstrtouint(buf, 10, &temp);
+       if (ret) {
+               LCDERR("invalid data\n");
+               return -EINVAL;
+       }
+       if (temp) {
+               if (lcd_prbs_flag) {
+                       LCDPR("lcd prbs check is already running\n");
+                       return count;
+               }
+               lcd_prbs_cnt = 0;
+               lcd_prbs_flag = 1;
+               aml_lcd_prbs_test(temp);
+       } else {
+               if (lcd_prbs_flag == 0) {
+                       LCDPR("lcd prbs check is already stopped\n");
+                       return count;
+               }
+               lcd_prbs_flag = 0;
+       }
+
+       return count;
+}
+
 static void lcd_vinfo_update(void)
 {
        struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver();
@@ -3159,6 +3267,7 @@ static struct class_attribute lcd_debug_class_attrs[] = {
        __ATTR(clk,         0644, lcd_debug_clk_show, lcd_debug_clk_store),
        __ATTR(test,        0644, lcd_debug_test_show, lcd_debug_test_store),
        __ATTR(mute,        0644, lcd_debug_mute_show, lcd_debug_mute_store),
+       __ATTR(prbs,        0644, lcd_debug_prbs_show, lcd_debug_prbs_store),
        __ATTR(reg,         0200, NULL, lcd_debug_reg_store),
        __ATTR(dither,      0644,
                lcd_debug_dither_show, lcd_debug_dither_store),