diff --git a/arch/arm64/boot/dts/amlogic/mesontxlx_r311-panel.dtsi b/arch/arm64/boot/dts/amlogic/mesontxlx_r311-panel.dtsi index f1905c41125a..e6e9c29bbfeb 100644 --- a/arch/arm64/boot/dts/amlogic/mesontxlx_r311-panel.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesontxlx_r311-panel.dtsi @@ -27,23 +27,17 @@ &clkc CLKID_VCLK2_VENCL>; clock-names = "encl_top_gate", "encl_int_gate"; - reg = <0x0 0xff634000 0x0 0x100>; + reg = <0x0 0xff634400 0x0 0x100>; interrupts = <0 3 1 0 78 1>; - interrupt-names = "vbyone","vbyone_vsync"; + interrupt-names = "vsync","vbyone"; pinctrl-names = "vbyone"; pinctrl-0 = <&lcd_vbyone_pins>; pinctrl_version = <2>; /* for uboot */ - /* power type:(0=cpu_gpio, 1=pmu_gpio, - * 2=signal, 3=extern, 0xff=ending) - */ - /* power index:(point gpios_index, - * or extern_index, 0xff=invalid) - */ - /* power value:(0=output low, - * 1=output high, 2=input) - */ + /* power type:(0=cpu_gpio, 2=signal, 3=extern, 0xff=ending) */ + /* power index:(gpios_index, or extern_index, 0xff=invalid) */ + /* power value:(0=output low, 1=output high, 2=input) */ /* power delay:(unit in ms) */ lcd_cpu-gpios = <&gpio GPIOZ_13 GPIO_ACTIVE_HIGH &gpio GPIOZ_8 GPIO_ACTIVE_HIGH @@ -70,10 +64,9 @@ 44 148 0 /*hs_width, hs_bp, hs_pol*/ 5 30 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 3 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -115,10 +108,9 @@ 44 148 0 /*hs_width, hs_bp, hs_pol*/ 5 30 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 4 /* - *fr_adj_type + 4 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 0 /*clk_ss_level */ 1 /*clk_auto_generate*/ @@ -160,10 +152,9 @@ 56 64 0 /*hs_width, hs_bp, hs_pol*/ 3 28 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 3 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -205,10 +196,9 @@ 33 477 0 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 1 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -248,10 +238,9 @@ 33 477 0 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 1 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -293,10 +282,9 @@ 33 477 0 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 4 /* - *fr_adj_type + 4 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 0 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -338,10 +326,9 @@ 33 477 1 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 1 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -385,10 +372,9 @@ 33 477 1 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 1 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -432,10 +418,9 @@ 33 477 0 /*hs_width, hs_bp, hs_pol*/ 6 65 0>; /*vs_width, vs_bp, vs_pol*/ clk_attr = < - 2 /* - *fr_adj_type + 2 /*fr_adj_type *(0=clk, 1=htotal, 2=vtotal, 3=auto_range, - *4=hdmi_mode) + * 4=hdmi_mode) */ 1 /*clk_ss_level*/ 1 /*clk_auto_generate*/ @@ -638,8 +623,7 @@ 1 0 /*on_value, off_value*/ 200 200>; /*on_delay(ms), off_delay(ms)*/ bl_ldim_region_row_col = <1 8>; - bl_ldim_mode = <1>; /* - *1=single_side + bl_ldim_mode = <1>; /*1=single_side * (top, bottom, left or right), *2=uniform(top/bottom, left/right) */ @@ -657,8 +641,7 @@ 1 0 /*on_value, off_value*/ 200 200>; /* on_delay(ms), off_delay(ms)*/ bl_ldim_region_row_col = <1 1>; - bl_ldim_mode = <1>; /* - *1=single_side + bl_ldim_mode = <1>; /*1=single_side * (top, bottom, left or right), *2=uniform(top/bottom, left/right) */ diff --git a/drivers/amlogic/media/vout/backlight/aml_bl.c b/drivers/amlogic/media/vout/backlight/aml_bl.c index be0498805026..762eb1bd30ad 100644 --- a/drivers/amlogic/media/vout/backlight/aml_bl.c +++ b/drivers/amlogic/media/vout/backlight/aml_bl.c @@ -97,11 +97,11 @@ static struct bl_config_s bl_config = { .pwm_off_delay = 0, .bl_gpio = { - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, }, }; @@ -204,7 +204,7 @@ struct aml_bl_drv_s *aml_bl_get_driver(void) return bl_drv; } -static void bl_gpio_register(int index) +static void bl_gpio_probe(int index) { struct bl_gpio_s *bl_gpio; const char *str; @@ -215,7 +215,7 @@ static void bl_gpio_register(int index) return; } bl_gpio = &bl_drv->bconf->bl_gpio[index]; - if (bl_gpio->flag) { + if (bl_gpio->probe_flag) { if (bl_debug_print_flag) { BLPR("gpio %s[%d] is already registered\n", bl_gpio->name, index); @@ -232,20 +232,60 @@ static void bl_gpio_register(int index) } strcpy(bl_gpio->name, str); + /* init gpio flag */ + bl_gpio->probe_flag = 1; + bl_gpio->register_flag = 0; +} + +static int bl_gpio_register(int index, int init_value) +{ + struct bl_gpio_s *bl_gpio; + int value; + + if (index >= BL_GPIO_NUM_MAX) { + BLERR("%s: gpio index %d, exit\n", __func__, index); + return -1; + } + bl_gpio = &bl_drv->bconf->bl_gpio[index]; + if (bl_gpio->probe_flag == 0) { + BLERR("%s: gpio [%d] is not probed, exit\n", __func__, index); + return -1; + } + if (bl_gpio->register_flag) { + BLPR("%s: gpio %s[%d] is already registered\n", + __func__, bl_gpio->name, index); + return 0; + } + + switch (init_value) { + case BL_GPIO_OUTPUT_LOW: + value = GPIOD_OUT_LOW; + break; + case BL_GPIO_OUTPUT_HIGH: + value = GPIOD_OUT_HIGH; + break; + case BL_GPIO_INPUT: + default: + value = GPIOD_IN; + break; + } + /* request gpio */ - bl_gpio->gpio = devm_gpiod_get_index( - bl_drv->dev, "bl", index, GPIOD_OUT_HIGH); + bl_gpio->gpio = devm_gpiod_get_index(bl_drv->dev, "bl", index, value); if (IS_ERR(bl_gpio->gpio)) { BLERR("register gpio %s[%d]: %p, err: %d\n", bl_gpio->name, index, bl_gpio->gpio, IS_ERR(bl_gpio->gpio)); - } else { - bl_gpio->flag = 1; - if (bl_debug_print_flag) { - BLPR("register gpio %s[%d]: %p\n", - bl_gpio->name, index, bl_gpio->gpio); - } + return -1; } + + bl_gpio->register_flag = 1; + if (bl_debug_print_flag) { + BLPR("register gpio %s[%d]: %p, init value: %d\n", + bl_gpio->name, index, bl_gpio->gpio, init_value); + } + + return 0; } static void bl_gpio_set(int index, int value) @@ -257,11 +297,16 @@ static void bl_gpio_set(int index, int value) return; } bl_gpio = &bl_drv->bconf->bl_gpio[index]; - if (bl_gpio->flag == 0) { - BLERR("gpio [%d] is not registered\n", index); + if (bl_gpio->probe_flag == 0) { + BLERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return; } - if (IS_ERR(bl_gpio->gpio)) { + if (bl_gpio->register_flag == 0) { + bl_gpio_register(index, value); + return; + } + + if (IS_ERR_OR_NULL(bl_gpio->gpio)) { BLERR("gpio %s[%d]: %p, err: %ld\n", bl_gpio->name, index, bl_gpio->gpio, PTR_ERR(bl_gpio->gpio)); @@ -1334,7 +1379,7 @@ static int aml_bl_config_load_from_dts(struct bl_config_s *bconf, bconf->en_gpio = BL_GPIO_MAX; } else { bconf->en_gpio = bl_para[0]; - bl_gpio_register(bconf->en_gpio); + bl_gpio_probe(bconf->en_gpio); } bconf->en_gpio_on = bl_para[1]; bconf->en_gpio_off = bl_para[2]; @@ -1670,7 +1715,7 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf) bconf->en_gpio = BL_GPIO_MAX; } else { bconf->en_gpio = temp; - bl_gpio_register(bconf->en_gpio); + bl_gpio_probe(bconf->en_gpio); } p += LCD_UKEY_BL_EN_GPIO; bconf->en_gpio_on = *p; diff --git a/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_dev_drv.c b/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_dev_drv.c index 2885ea15fd29..ae6a3ad85047 100644 --- a/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_dev_drv.c +++ b/drivers/amlogic/media/vout/backlight/aml_ldim/ldim_dev_drv.c @@ -38,7 +38,13 @@ #include "ldim_dev_drv.h" #include "../aml_bl_reg.h" -struct bl_gpio_s ldim_gpio[BL_GPIO_NUM_MAX]; +struct bl_gpio_s ldim_gpio[BL_GPIO_NUM_MAX] = { + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, +}; static struct spi_board_info ldim_spi_dev = { .modalias = "ldim_dev", @@ -120,7 +126,7 @@ static void ldim_gpio_release(int index) } #endif -static void ldim_gpio_register(int index) +static void ldim_gpio_probe(int index) { struct bl_gpio_s *ld_gpio; struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver(); @@ -132,7 +138,7 @@ static void ldim_gpio_register(int index) return; } ld_gpio = &ldim_gpio[index]; - if (ld_gpio->flag) { + if (ld_gpio->probe_flag) { if (ldim_debug_print) { LDIMPR("gpio %s[%d] is already registered\n", ld_gpio->name, index); @@ -149,20 +155,63 @@ static void ldim_gpio_register(int index) } strcpy(ld_gpio->name, str); + /* init gpio flag */ + ld_gpio->probe_flag = 1; + ld_gpio->register_flag = 0; +} + +static int ldim_gpio_register(int index, int init_value) +{ + struct bl_gpio_s *ld_gpio; + struct aml_ldim_driver_s *ldim_drv = aml_ldim_get_driver(); + int value; + + if (index >= BL_GPIO_NUM_MAX) { + LDIMERR("%s: gpio index %d, exit\n", __func__, index); + return -1; + } + ld_gpio = &ldim_gpio[index]; + if (ld_gpio->probe_flag == 0) { + LDIMERR("%s: gpio [%d] is not probed, exit\n", __func__, index); + return -1; + } + if (ld_gpio->register_flag) { + if (ldim_debug_print) { + LDIMPR("%s: gpio %s[%d] is already registered\n", + __func__, ld_gpio->name, index); + } + return 0; + } + + switch (init_value) { + case BL_GPIO_OUTPUT_LOW: + value = GPIOD_OUT_LOW; + break; + case BL_GPIO_OUTPUT_HIGH: + value = GPIOD_OUT_HIGH; + break; + case BL_GPIO_INPUT: + default: + value = GPIOD_IN; + break; + } + /* request gpio */ ld_gpio->gpio = devm_gpiod_get_index(ldim_drv->dev, - "ldim_dev", index, GPIOD_OUT_HIGH); + "ldim_dev", index, value); if (IS_ERR(ld_gpio->gpio)) { LDIMERR("register gpio %s[%d]: %p, err: %d\n", ld_gpio->name, index, ld_gpio->gpio, IS_ERR(ld_gpio->gpio)); - } else { - ld_gpio->flag = 1; - if (ldim_debug_print) { - LDIMPR("register gpio %s[%d]: %p\n", - ld_gpio->name, index, ld_gpio->gpio); - } + return -1; } + ld_gpio->register_flag = 1; + if (ldim_debug_print) { + LDIMPR("register gpio %s[%d]: %p, init value: %d\n", + ld_gpio->name, index, ld_gpio->gpio, init_value); + } + + return 0; } void ldim_gpio_set(int index, int value) @@ -174,11 +223,15 @@ void ldim_gpio_set(int index, int value) return; } ld_gpio = &ldim_gpio[index]; - if (ld_gpio->flag == 0) { - LDIMERR("gpio [%d] is not registered\n", index); + if (ld_gpio->probe_flag == 0) { + BLERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return; } - if (IS_ERR(ld_gpio->gpio)) { + if (ld_gpio->register_flag == 0) { + ldim_gpio_register(index, value); + return; + } + if (IS_ERR_OR_NULL(ld_gpio->gpio)) { LDIMERR("gpio %s[%d]: %p, err: %ld\n", ld_gpio->name, index, ld_gpio->gpio, PTR_ERR(ld_gpio->gpio)); @@ -211,11 +264,16 @@ unsigned int ldim_gpio_get(int index) } ld_gpio = &ldim_gpio[index]; - if (ld_gpio->flag == 0) { - LDIMERR("gpio[%d] is not registered\n", index); + if (ld_gpio->probe_flag == 0) { + LDIMERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return -1; } - if (IS_ERR(ld_gpio->gpio)) { + if (ld_gpio->register_flag == 0) { + LDIMERR("%s: gpio %s[%d] is not registered\n", + __func__, ld_gpio->name, index); + return -1; + } + if (IS_ERR_OR_NULL(ld_gpio->gpio)) { LDIMERR("gpio %s[%d]: %p, err: %ld\n", ld_gpio->name, index, ld_gpio->gpio, PTR_ERR(ld_gpio->gpio)); @@ -526,7 +584,7 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index) ldim_dev_config.en_gpio = BL_GPIO_MAX; } else { ldim_dev_config.en_gpio = temp[0]; - ldim_gpio_register(ldim_dev_config.en_gpio); + ldim_gpio_probe(ldim_dev_config.en_gpio); } ldim_dev_config.en_gpio_on = temp[1]; ldim_dev_config.en_gpio_off = temp[2]; @@ -603,7 +661,7 @@ static int ldim_dev_get_config_from_dts(struct device_node *np, int index) } else { ldim_dev_config.lamp_err_gpio = val; ldim_dev_config.fault_check = 1; - ldim_gpio_register( + ldim_gpio_probe( ldim_dev_config.lamp_err_gpio); ldim_gpio_set(ldim_dev_config.lamp_err_gpio, BL_GPIO_INPUT); diff --git a/drivers/amlogic/media/vout/lcd/lcd_common.c b/drivers/amlogic/media/vout/lcd/lcd_common.c index d0a4f957ecfe..b5ed2eca50df 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_common.c +++ b/drivers/amlogic/media/vout/lcd/lcd_common.c @@ -106,16 +106,8 @@ char *lcd_mode_mode_to_str(int mode) * lcd gpio * ********************************** */ -#if 0 -#define lcd_gpio_request(dev, str) gpiod_get(dev, str) -#define lcd_gpio_free(gdesc) gpiod_put(gdesc) -#define lcd_gpio_input(gdesc) gpiod_direction_input(gdesc) -#define lcd_gpio_output(gdesc, val) gpiod_direction_output(gdesc, val) -#define lcd_gpio_get_value(gdesc) gpiod_get_value(gdesc) -#define lcd_gpio_set_value(gdesc, val) gpiod_set_value(gdesc, val) -#endif -void lcd_cpu_gpio_register(unsigned int index) +void lcd_cpu_gpio_probe(unsigned int index) { struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver(); struct lcd_cpu_gpio_s *cpu_gpio; @@ -127,7 +119,7 @@ void lcd_cpu_gpio_register(unsigned int index) return; } cpu_gpio = &lcd_drv->lcd_config->lcd_power->cpu_gpio[index]; - if (cpu_gpio->flag) { + if (cpu_gpio->probe_flag) { if (lcd_debug_print_flag) { LCDPR("gpio %s[%d] is already registered\n", cpu_gpio->name, index); @@ -144,20 +136,61 @@ void lcd_cpu_gpio_register(unsigned int index) } strcpy(cpu_gpio->name, str); + /* init gpio flag */ + cpu_gpio->probe_flag = 1; + cpu_gpio->register_flag = 0; +} + +static int lcd_cpu_gpio_register(unsigned int index, int init_value) +{ + struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver(); + struct lcd_cpu_gpio_s *cpu_gpio; + int value; + + if (index >= LCD_CPU_GPIO_NUM_MAX) { + LCDERR("%s: gpio index %d, exit\n", __func__, index); + return -1; + } + cpu_gpio = &lcd_drv->lcd_config->lcd_power->cpu_gpio[index]; + if (cpu_gpio->probe_flag == 0) { + LCDERR("%s: gpio [%d] is not probed, exit\n", __func__, index); + return -1; + } + if (cpu_gpio->register_flag) { + LCDPR("%s: gpio %s[%d] is already registered\n", + __func__, cpu_gpio->name, index); + return 0; + } + + switch (init_value) { + case LCD_GPIO_OUTPUT_LOW: + value = GPIOD_OUT_LOW; + break; + case LCD_GPIO_OUTPUT_HIGH: + value = GPIOD_OUT_HIGH; + break; + case LCD_GPIO_INPUT: + default: + value = GPIOD_IN; + break; + } + /* request gpio */ cpu_gpio->gpio = devm_gpiod_get_index(lcd_drv->dev, - "lcd_cpu", index, GPIOD_OUT_HIGH); + "lcd_cpu", index, value); if (IS_ERR(cpu_gpio->gpio)) { LCDERR("register gpio %s[%d]: %p, err: %d\n", cpu_gpio->name, index, cpu_gpio->gpio, IS_ERR(cpu_gpio->gpio)); - } else { - cpu_gpio->flag = 1; - if (lcd_debug_print_flag) { - LCDPR("register gpio %s[%d]: %p\n", - cpu_gpio->name, index, cpu_gpio->gpio); - } + return -1; } + cpu_gpio->register_flag = 1; + if (lcd_debug_print_flag) { + LCDPR("register gpio %s[%d]: %p, init value: %d\n", + cpu_gpio->name, index, cpu_gpio->gpio, init_value); + } + + return 0; } void lcd_cpu_gpio_set(unsigned int index, int value) @@ -170,11 +203,16 @@ void lcd_cpu_gpio_set(unsigned int index, int value) return; } cpu_gpio = &lcd_drv->lcd_config->lcd_power->cpu_gpio[index]; - if (cpu_gpio->flag == 0) { - LCDERR("gpio [%d] is not registered\n", index); + if (cpu_gpio->probe_flag == 0) { + LCDERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return; } - if (IS_ERR(cpu_gpio->gpio)) { + if (cpu_gpio->register_flag == 0) { + lcd_cpu_gpio_register(index, value); + return; + } + + if (IS_ERR_OR_NULL(cpu_gpio->gpio)) { LCDERR("gpio %s[%d]: %p, err: %ld\n", cpu_gpio->name, index, cpu_gpio->gpio, PTR_ERR(cpu_gpio->gpio)); @@ -203,11 +241,16 @@ unsigned int lcd_cpu_gpio_get(unsigned int index) struct lcd_cpu_gpio_s *cpu_gpio; cpu_gpio = &lcd_drv->lcd_config->lcd_power->cpu_gpio[index]; - if (cpu_gpio->flag == 0) { - LCDERR("gpio[%d] is not registered\n", index); + if (cpu_gpio->probe_flag == 0) { + LCDERR("%s: gpio [%d] is not probed\n", __func__, index); return -1; } - if (IS_ERR(cpu_gpio->gpio)) { + if (cpu_gpio->register_flag == 0) { + LCDERR("%s: gpio %s[%d] is not registered\n", + __func__, cpu_gpio->name, index); + return -1; + } + if (IS_ERR_OR_NULL(cpu_gpio->gpio)) { LCDERR("gpio[%d]: %p, err: %ld\n", index, cpu_gpio->gpio, PTR_ERR(cpu_gpio->gpio)); return -1; @@ -428,12 +471,12 @@ int lcd_power_load_from_dts(struct lcd_config_s *pconf, "power_on_step", j, &val); lcd_power->power_on_step[i].delay = val; - /* gpio request */ + /* gpio probe */ switch (lcd_power->power_on_step[i].type) { case LCD_POWER_TYPE_CPU: index = lcd_power->power_on_step[i].index; if (index < LCD_CPU_GPIO_NUM_MAX) - lcd_cpu_gpio_register(index); + lcd_cpu_gpio_probe(index); break; default: break; @@ -479,12 +522,12 @@ int lcd_power_load_from_dts(struct lcd_config_s *pconf, "power_off_step", j, &val); lcd_power->power_off_step[i].delay = val; - /* gpio request */ + /* gpio probe */ switch (lcd_power->power_off_step[i].type) { case LCD_POWER_TYPE_CPU: index = lcd_power->power_off_step[i].index; if (index < LCD_CPU_GPIO_NUM_MAX) - lcd_cpu_gpio_register(index); + lcd_cpu_gpio_probe(index); break; default: break; @@ -549,12 +592,12 @@ int lcd_power_load_from_unifykey(struct lcd_config_s *pconf, (*p | ((*(p + 1)) << 8)); p += LCD_UKEY_PWR_DELAY; - /* gpio request */ + /* gpio probe */ switch (pconf->lcd_power->power_on_step[i].type) { case LCD_POWER_TYPE_CPU: index = pconf->lcd_power->power_on_step[i].index; if (index < LCD_CPU_GPIO_NUM_MAX) - lcd_cpu_gpio_register(index); + lcd_cpu_gpio_probe(index); break; default: break; @@ -596,12 +639,12 @@ int lcd_power_load_from_unifykey(struct lcd_config_s *pconf, (*p | ((*(p + 1)) << 8)); p += LCD_UKEY_PWR_DELAY; - /* gpio request */ + /* gpio probe */ switch (pconf->lcd_power->power_off_step[i].type) { case LCD_POWER_TYPE_CPU: index = pconf->lcd_power->power_off_step[i].index; if (index < LCD_CPU_GPIO_NUM_MAX) - lcd_cpu_gpio_register(index); + lcd_cpu_gpio_probe(index); break; default: break; diff --git a/drivers/amlogic/media/vout/lcd/lcd_common.h b/drivers/amlogic/media/vout/lcd/lcd_common.h index 41d86a1771d7..189b7d0b298c 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_common.h +++ b/drivers/amlogic/media/vout/lcd/lcd_common.h @@ -39,7 +39,7 @@ extern char *lcd_type_type_to_str(int type); extern unsigned char lcd_mode_str_to_mode(const char *str); extern char *lcd_mode_mode_to_str(int mode); -extern void lcd_cpu_gpio_register(unsigned int index); +extern void lcd_cpu_gpio_probe(unsigned int index); extern void lcd_cpu_gpio_set(unsigned int index, int value); extern unsigned int lcd_cpu_gpio_get(unsigned int index); extern void lcd_ttl_pinmux_set(int status); diff --git a/drivers/amlogic/media/vout/lcd/lcd_debug.c b/drivers/amlogic/media/vout/lcd/lcd_debug.c index 160fb39ff94c..e688715b7554 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_debug.c +++ b/drivers/amlogic/media/vout/lcd/lcd_debug.c @@ -128,7 +128,7 @@ static const char *lcd_debug_usage_str = { " echo info > debug ; show lcd information\n" " echo reg > debug ; show lcd registers\n" " echo dump > debug ; show lcd information & registers\n" -" echo dith > debug ; set vpu_vencl_dith_ctrl\n" +" echo dith > debug ; set vpu_vencl_dith_ctrl\n" " echo key > debug ; show lcd_key_valid config, and lcd unifykey raw data\n" "\n" " echo reset > debug; reset lcd driver\n" @@ -171,11 +171,21 @@ static int lcd_cpu_gpio_register_print(struct lcd_config_s *pconf, i = 0; while (i < LCD_CPU_GPIO_NUM_MAX) { cpu_gpio = &pconf->lcd_power->cpu_gpio[i]; - if (cpu_gpio->flag) { + if (cpu_gpio->probe_flag == 0) { + i++; + continue; + } + + if (cpu_gpio->register_flag) { n = lcd_debug_info_len(len + offset); len += snprintf((buf+len), n, "%d: name=%s, gpio=%p\n", i, cpu_gpio->name, cpu_gpio->gpio); + } else { + n = lcd_debug_info_len(len + offset); + len += snprintf((buf+len), n, + "%d: name=%s, no registered\n", + i, cpu_gpio->name); } i++; } @@ -1466,9 +1476,9 @@ static ssize_t lcd_debug_resume_show(struct class *class, { struct aml_lcd_drv_s *lcd_drv = aml_lcd_get_driver(); - return sprintf(buf, "lcd resume flag: %d(%s)\n", - lcd_drv->lcd_resume_flag, - lcd_drv->lcd_resume_flag ? "workqueue" : "directly"); + return sprintf(buf, "lcd resume type: %d(%s)\n", + lcd_drv->lcd_resume_type, + lcd_drv->lcd_resume_type ? "workqueue" : "directly"); } static ssize_t lcd_debug_resume_store(struct class *class, @@ -1483,8 +1493,8 @@ static ssize_t lcd_debug_resume_store(struct class *class, LCDERR("invalid data\n"); return -EINVAL; } - lcd_drv->lcd_resume_flag = (unsigned char)temp; - LCDPR("set lcd resume flag: %d\n", lcd_drv->lcd_resume_flag); + lcd_drv->lcd_resume_type = (unsigned char)temp; + LCDPR("set lcd resume flag: %d\n", lcd_drv->lcd_resume_type); return count; } @@ -2139,11 +2149,11 @@ static ssize_t lcd_debug_print_store(struct class *class, static struct class_attribute lcd_debug_class_attrs[] = { __ATTR(help, 0444, lcd_debug_common_help, NULL), __ATTR(debug, 0644, lcd_debug_show, lcd_debug_store), - __ATTR(change, 0644, lcd_debug_change_show, + __ATTR(change, 0644, lcd_debug_change_show, lcd_debug_change_store), __ATTR(enable, 0644, lcd_debug_enable_show, lcd_debug_enable_store), - __ATTR(resume, 0644, + __ATTR(resume_type, 0644, lcd_debug_resume_show, lcd_debug_resume_store), __ATTR(power, 0644, lcd_debug_power_show, lcd_debug_power_store), __ATTR(frame_rate, 0644, @@ -2157,7 +2167,7 @@ static struct class_attribute lcd_debug_class_attrs[] = { __ATTR(reg, 0200, NULL, lcd_debug_reg_store), __ATTR(dither, 0644, lcd_debug_dither_show, lcd_debug_dither_store), - __ATTR(dump, 0644, + __ATTR(dump, 0644, lcd_debug_dump_show, lcd_debug_dump_store), __ATTR(print, 0644, lcd_debug_print_show, lcd_debug_print_store), }; diff --git a/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.c b/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.c index 2404802bc115..e7cebf73a72d 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.c +++ b/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.c @@ -40,16 +40,17 @@ static unsigned char lcd_ext_config_load; struct lcd_ext_gpio_s { char name[15]; struct gpio_desc *gpio; - int flag; + int probe_flag; + int register_flag; }; static struct lcd_ext_gpio_s lcd_extern_gpio[LCD_EXTERN_GPIO_NUM_MAX] = { - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, }; struct aml_lcd_extern_driver_s *aml_lcd_extern_get_driver(int index) @@ -92,7 +93,7 @@ static struct aml_lcd_extern_driver_s #endif #ifdef CONFIG_OF -void lcd_extern_gpio_register(unsigned char index) +void lcd_extern_gpio_probe(unsigned char index) { struct lcd_ext_gpio_s *ext_gpio; const char *str; @@ -103,7 +104,7 @@ void lcd_extern_gpio_register(unsigned char index) return; } ext_gpio = &lcd_extern_gpio[index]; - if (ext_gpio->flag) { + if (ext_gpio->probe_flag) { if (lcd_debug_print_flag) { EXTPR("gpio %s[%d] is already registered\n", ext_gpio->name, index); @@ -120,20 +121,61 @@ void lcd_extern_gpio_register(unsigned char index) } strcpy(ext_gpio->name, str); + /* init gpio flag */ + ext_gpio->probe_flag = 1; + ext_gpio->register_flag = 0; +} + +static int lcd_extern_gpio_register(unsigned char index, int init_value) +{ + struct lcd_ext_gpio_s *ext_gpio; + int value; + + if (index >= LCD_EXTERN_GPIO_NUM_MAX) { + EXTERR("gpio index %d, exit\n", index); + return -1; + } + ext_gpio = &lcd_extern_gpio[index]; + if (ext_gpio->probe_flag == 0) { + EXTERR("%s: gpio [%d] is not probed, exit\n", __func__, index); + return -1; + } + if (ext_gpio->register_flag) { + EXTPR("%s: gpio %s[%d] is already registered\n", + __func__, ext_gpio->name, index); + return 0; + } + + switch (init_value) { + case LCD_GPIO_OUTPUT_LOW: + value = GPIOD_OUT_LOW; + break; + case LCD_GPIO_OUTPUT_HIGH: + value = GPIOD_OUT_HIGH; + break; + case LCD_GPIO_INPUT: + default: + value = GPIOD_IN; + break; + } + /* request gpio */ ext_gpio->gpio = devm_gpiod_get_index( - lcd_extern_dev, "extern", index, GPIOD_OUT_HIGH); + lcd_extern_dev, "extern", index, value); if (IS_ERR(ext_gpio->gpio)) { EXTERR("register gpio %s[%d]: %p, err: %d\n", ext_gpio->name, index, ext_gpio->gpio, IS_ERR(ext_gpio->gpio)); ext_gpio->gpio = NULL; - } else { - if (lcd_debug_print_flag) { - EXTPR("register gpio %s[%d]: %p\n", - ext_gpio->name, index, ext_gpio->gpio); - } + return -1; } + ext_gpio->register_flag = 1; + if (lcd_debug_print_flag) { + EXTPR("register gpio %s[%d]: %p, init value: %d\n", + ext_gpio->name, index, ext_gpio->gpio, init_value); + } + + return 0; } #endif @@ -146,11 +188,16 @@ void lcd_extern_gpio_set(unsigned char index, int value) return; } ext_gpio = &lcd_extern_gpio[index]; - if (ext_gpio->flag == 0) { - EXTERR("gpio [%d] is not registered\n", index); + if (ext_gpio->probe_flag == 0) { + EXTERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return; } - if (IS_ERR(ext_gpio->gpio)) { + if (ext_gpio->register_flag == 0) { + lcd_extern_gpio_register(index, value); + return; + } + + if (IS_ERR_OR_NULL(ext_gpio->gpio)) { EXTERR("gpio %s[%d]: %p, err: %ld\n", ext_gpio->name, index, ext_gpio->gpio, PTR_ERR(ext_gpio->gpio)); @@ -182,11 +229,16 @@ unsigned int lcd_extern_gpio_get(unsigned char index) return -1; } ext_gpio = &lcd_extern_gpio[index]; - if (ext_gpio->flag == 0) { - EXTERR("gpio [%d] is not registered\n", index); + if (ext_gpio->probe_flag == 0) { + EXTERR("%s: gpio [%d] is not probed, exit\n", __func__, index); return -1; } - if (IS_ERR(ext_gpio->gpio)) { + if (ext_gpio->register_flag == 0) { + EXTERR("%s: gpio %s[%d] is not registered\n", + __func__, ext_gpio->name, index); + return -1; + } + if (IS_ERR_OR_NULL(ext_gpio->gpio)) { EXTERR("gpio %s[%d]: %p, err: %ld\n", ext_gpio->name, index, ext_gpio->gpio, PTR_ERR(ext_gpio->gpio)); @@ -292,10 +344,10 @@ static int lcd_extern_init_table_dynamic_size_load_dts( init_table[i+2+j] = (unsigned char)val; } if (type == LCD_EXTERN_INIT_GPIO) { - /* gpio request */ + /* gpio probe */ index = init_table[i+2]; if (index < LCD_EXTERN_GPIO_NUM_MAX) - lcd_extern_gpio_register(index); + lcd_extern_gpio_probe(index); } step++; i += (cmd_size + 2); @@ -340,10 +392,10 @@ static int lcd_extern_init_table_fixed_size_load_dts( if (init_table[i] == LCD_EXTERN_INIT_END) { break; } else if (init_table[i] == LCD_EXTERN_INIT_GPIO) { - /* gpio request */ + /* gpio probe */ index = init_table[i+1]; if (index < LCD_EXTERN_GPIO_NUM_MAX) - lcd_extern_gpio_register(index); + lcd_extern_gpio_probe(index); } step++; i += cmd_size; @@ -489,7 +541,7 @@ static int lcd_extern_get_config_dts(struct device_node *of_node, return -1; } extconf->spi_gpio_cs = val; - lcd_extern_gpio_register(val); + lcd_extern_gpio_probe(val); if (lcd_debug_print_flag) EXTPR("spi_gpio_cs: %d\n", extconf->spi_gpio_cs); ret = of_property_read_u32(of_node, "gpio_spi_clk", &val); @@ -500,7 +552,7 @@ static int lcd_extern_get_config_dts(struct device_node *of_node, return -1; } extconf->spi_gpio_clk = val; - lcd_extern_gpio_register(val); + lcd_extern_gpio_probe(val); if (lcd_debug_print_flag) EXTPR("spi_gpio_clk: %d\n", extconf->spi_gpio_clk); ret = of_property_read_u32(of_node, "gpio_spi_data", &val); @@ -511,7 +563,7 @@ static int lcd_extern_get_config_dts(struct device_node *of_node, return -1; } extconf->spi_gpio_data = val; - lcd_extern_gpio_register(val); + lcd_extern_gpio_probe(val); if (lcd_debug_print_flag) EXTPR("spi_gpio_data: %d\n", extconf->spi_gpio_data); ret = of_property_read_u32(of_node, "spi_clk_freq", &val); @@ -686,10 +738,10 @@ static int lcd_extern_init_table_dynamic_size_load_unifykey( if (init_table[i] == LCD_EXTERN_INIT_END) { break; } else if (init_table[i] == LCD_EXTERN_INIT_GPIO) { - /* gpio request */ + /* gpio probe */ index = init_table[i+1]; if (index < LCD_EXTERN_GPIO_NUM_MAX) - lcd_extern_gpio_register(index); + lcd_extern_gpio_probe(index); } step++; i += (cmd_size + 2); @@ -736,10 +788,10 @@ static int lcd_extern_init_table_fixed_size_load_unifykey( if (init_table[i] == LCD_EXTERN_INIT_END) { break; } else if (init_table[i] == LCD_EXTERN_INIT_GPIO) { - /* gpio request */ + /* gpio probe */ index = init_table[i+1]; if (index < LCD_EXTERN_GPIO_NUM_MAX) - lcd_extern_gpio_register(index); + lcd_extern_gpio_probe(index); } step++; i += cmd_size; @@ -851,13 +903,13 @@ static int lcd_extern_get_config_unifykey(struct lcd_extern_config_s *extconf) break; case LCD_EXTERN_SPI: extconf->spi_gpio_cs = *p; - lcd_extern_gpio_register(*p); + lcd_extern_gpio_probe(*p); p += LCD_UKEY_EXT_TYPE_VAL_0; extconf->spi_gpio_clk = *p; - lcd_extern_gpio_register(*p); + lcd_extern_gpio_probe(*p); p += LCD_UKEY_EXT_TYPE_VAL_1; extconf->spi_gpio_data = *p; - lcd_extern_gpio_register(*p); + lcd_extern_gpio_probe(*p); p += LCD_UKEY_EXT_TYPE_VAL_2; extconf->spi_clk_freq = (*p | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) | diff --git a/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.h b/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.h index a6b827940b08..104b0e52d1fd 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.h +++ b/drivers/amlogic/media/vout/lcd/lcd_extern/lcd_extern.h @@ -31,7 +31,7 @@ #ifdef CONFIG_USE_OF extern struct device_node *aml_lcd_extern_get_dts_child(int index); #endif -extern void lcd_extern_gpio_register(unsigned char index); +extern void lcd_extern_gpio_probe(unsigned char index); extern void lcd_extern_gpio_set(unsigned char index, int value); extern unsigned int lcd_extern_gpio_get(unsigned char index); diff --git a/drivers/amlogic/media/vout/lcd/lcd_tablet/lcd_tablet.c b/drivers/amlogic/media/vout/lcd/lcd_tablet/lcd_tablet.c index 5e6933d8be3b..4a16e4944fe1 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_tablet/lcd_tablet.c +++ b/drivers/amlogic/media/vout/lcd/lcd_tablet/lcd_tablet.c @@ -308,7 +308,7 @@ static int lcd_resume(void) if (lcd_resume_flag) return 0; - if (lcd_drv->lcd_resume_flag) { + if (lcd_drv->lcd_resume_type) { if (lcd_drv->workqueue) { queue_work(lcd_drv->workqueue, &(lcd_drv->lcd_resume_work)); diff --git a/drivers/amlogic/media/vout/lcd/lcd_tablet/mipi_dsi_util.c b/drivers/amlogic/media/vout/lcd/lcd_tablet/mipi_dsi_util.c index 48d130018c49..0b5c49163e08 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_tablet/mipi_dsi_util.c +++ b/drivers/amlogic/media/vout/lcd/lcd_tablet/mipi_dsi_util.c @@ -300,10 +300,10 @@ int lcd_mipi_dsi_init_table_detect(struct device_node *m_node, if (val == 0xff) break; } else if (val == 0xf0) { /* cpu_gpio */ - /* register gpio */ + /* probe gpio */ ret = of_property_read_u32_index(m_node, propname, (i + DSI_GPIO_INDEX), &val); - lcd_cpu_gpio_register(val); + lcd_cpu_gpio_probe(val); /* cmd size */ ret = of_property_read_u32_index(m_node, diff --git a/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_drv.c b/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_drv.c index 6bf4ed1d04ef..137af6bd049c 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_drv.c +++ b/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_drv.c @@ -1463,8 +1463,8 @@ int lcd_vbyone_interrupt_up(void) viu_vsync_irq = lcd_drv->res_vsync_irq->start; LCDPR("viu_vsync_irq: %d\n", viu_vsync_irq); - if (request_irq(viu_vsync_irq, lcd_vbyone_vsync_isr, 0, - "vbyone_vsync", (void *)"vbyone_vsync")) + if (request_irq(viu_vsync_irq, lcd_vbyone_vsync_isr, + IRQF_SHARED, "vbyone_vsync", (void *)"vbyone_vsync")) LCDERR("can't request viu_vsync_irq\n"); else { if (lcd_debug_print_flag) diff --git a/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_tv.c b/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_tv.c index ab3ba9ddc06c..b58b5771cbfd 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_tv.c +++ b/drivers/amlogic/media/vout/lcd/lcd_tv/lcd_tv.c @@ -536,7 +536,7 @@ static int lcd_resume(void) if (lcd_resume_flag) return 0; - if (lcd_drv->lcd_resume_flag) { + if (lcd_drv->lcd_resume_type) { if (lcd_drv->workqueue) { queue_work(lcd_drv->workqueue, &(lcd_drv->lcd_resume_work)); diff --git a/drivers/amlogic/media/vout/lcd/lcd_vout.c b/drivers/amlogic/media/vout/lcd/lcd_vout.c index 756195d402b2..9618f81d8336 100644 --- a/drivers/amlogic/media/vout/lcd/lcd_vout.c +++ b/drivers/amlogic/media/vout/lcd/lcd_vout.c @@ -133,16 +133,16 @@ static struct dsi_config_s lcd_mipi_config = { static struct lcd_power_ctrl_s lcd_power_config = { .cpu_gpio = { - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, - {.flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, + {.probe_flag = 0, .register_flag = 0,}, }, .power_on_step = { { @@ -800,7 +800,7 @@ static int lcd_config_probe(struct platform_device *pdev) lcd_driver->lcd_info = &lcd_vinfo; lcd_driver->lcd_config = &lcd_config_dft; lcd_driver->lcd_test_flag = 0; - lcd_driver->lcd_resume_flag = 1; /* default workqueue */ + lcd_driver->lcd_resume_type = 1; /* default workqueue */ lcd_driver->power_ctrl = lcd_power_ctrl; lcd_driver->module_reset = lcd_module_reset; lcd_driver->power_tiny_ctrl = lcd_power_tiny_ctrl; @@ -972,7 +972,7 @@ static int lcd_remove(struct platform_device *pdev) static int lcd_resume(struct platform_device *pdev) { - if (lcd_driver->lcd_resume_flag) { + if (lcd_driver->lcd_resume_type) { lcd_resume_flag = 1; if (lcd_driver->workqueue) { queue_work(lcd_driver->workqueue, diff --git a/include/linux/amlogic/media/vout/lcd/aml_bl.h b/include/linux/amlogic/media/vout/lcd/aml_bl.h index f2103ea0d4fc..b715c99bde40 100644 --- a/include/linux/amlogic/media/vout/lcd/aml_bl.h +++ b/include/linux/amlogic/media/vout/lcd/aml_bl.h @@ -99,7 +99,8 @@ enum bl_off_policy_e { struct bl_gpio_s { char name[15]; struct gpio_desc *gpio; - int flag; + int probe_flag; + int register_flag; }; struct pwm_data_s { diff --git a/include/linux/amlogic/media/vout/lcd/lcd_vout.h b/include/linux/amlogic/media/vout/lcd/lcd_vout.h index b9f40c7fe6aa..62f3e86df218 100644 --- a/include/linux/amlogic/media/vout/lcd/lcd_vout.h +++ b/include/linux/amlogic/media/vout/lcd/lcd_vout.h @@ -345,7 +345,8 @@ enum lcd_pmu_gpio_e { struct lcd_cpu_gpio_s { char name[15]; struct gpio_desc *gpio; - int flag; + int probe_flag; + int register_flag; }; #define LCD_PMU_GPIO_NUM_MAX 3 @@ -403,7 +404,7 @@ struct aml_lcd_drv_s { unsigned char lcd_key_valid; unsigned char lcd_config_load; unsigned char lcd_test_flag; - unsigned char lcd_resume_flag; /* 0=directly, 1=workqueue */ + unsigned char lcd_resume_type; /* 0=directly, 1=workqueue */ unsigned char lcd_mute; unsigned char clk_gate_state;