mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-09 12:17:12 +09:00
backlight: add bl policy support [1/1]
PD#TV-11347 Problem: sometimes need power on from uboot state in kernel Solution: add bl policy to support different power on mode Verify: x301 Change-Id: I13c289523c6a77d713b3a770a5cdaf02afd01a11 Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
This commit is contained in:
@@ -1204,8 +1204,10 @@ static unsigned int aml_bl_get_level(void)
|
||||
return bl_drv->level;
|
||||
}
|
||||
|
||||
static unsigned int aml_bl_update_brightness_level(unsigned int bl_level)
|
||||
static unsigned int aml_bl_update_brightness_level(unsigned int brightness)
|
||||
{
|
||||
unsigned int bl_level = brightness;
|
||||
|
||||
mutex_lock(&bl_level_mutex);
|
||||
if (bl_level > 255) {
|
||||
BLPR("0-255 is the valid data\n");
|
||||
@@ -1224,23 +1226,21 @@ static unsigned int aml_bl_update_brightness_level(unsigned int bl_level)
|
||||
if ((bl_drv->state & BL_STATE_BL_ON) == 0)
|
||||
bl_power_on();
|
||||
}
|
||||
|
||||
if (bl_debug_print_flag) {
|
||||
BLPR("%s: %u, real brightness: %u, state: 0x%x\n",
|
||||
__func__, brightness, bl_level, bl_drv->state);
|
||||
}
|
||||
mutex_unlock(&bl_level_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int aml_bl_update_status(struct backlight_device *bd)
|
||||
{
|
||||
int brightness = bd->props.brightness;
|
||||
|
||||
if (brightness_bypass)
|
||||
return 0;
|
||||
|
||||
aml_bl_update_brightness_level(brightness);
|
||||
if (bl_debug_print_flag) {
|
||||
BLPR("%s: %u, real brightness: %u, state: 0x%x\n",
|
||||
__func__, bd->props.brightness,
|
||||
brightness, bl_drv->state);
|
||||
}
|
||||
aml_bl_update_brightness_level(bd->props.brightness);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1475,8 +1475,21 @@ static int aml_bl_config_load_from_dts(struct bl_config_s *bconf,
|
||||
bl_level_uboot = BL_LEVEL_DEFAULT;
|
||||
bconf->level_default = BL_LEVEL_DEFAULT;
|
||||
} else {
|
||||
bl_level_uboot = bl_para[0];
|
||||
bconf->level_default = bl_para[1];
|
||||
bl_level_uboot = bl_para[0] & BL_LEVEL_MASK;
|
||||
bconf->level_default = bl_para[1] & BL_LEVEL_MASK;
|
||||
|
||||
brightness_bypass =
|
||||
((bl_para[1] >> BL_POLICY_BRIGHTNESS_BYPASS_BIT) &
|
||||
BL_POLICY_BRIGHTNESS_BYPASS_MASK);
|
||||
if (brightness_bypass)
|
||||
BLPR("0x%x: enable brightness_bypass\n", bl_para[1]);
|
||||
bl_step_on_flag =
|
||||
((bl_para[1] >> BL_POLICY_POWER_ON_BIT) &
|
||||
BL_POLICY_POWER_ON_MASK);
|
||||
if (bl_step_on_flag) {
|
||||
BLPR("0x%x: bl_step_on_flag: %d\n",
|
||||
bl_para[1], bl_step_on_flag);
|
||||
}
|
||||
}
|
||||
|
||||
ret = of_property_read_u32_array(child, "bl_level_attr",
|
||||
@@ -1493,11 +1506,6 @@ static int aml_bl_config_load_from_dts(struct bl_config_s *bconf,
|
||||
bconf->level_mid = bl_para[2];
|
||||
bconf->level_mid_mapping = bl_para[3];
|
||||
}
|
||||
/* adjust brightness_bypass by level_default */
|
||||
if (bconf->level_default > bconf->level_max) {
|
||||
brightness_bypass = 1;
|
||||
BLPR("level_default > level_max, enable brightness_bypass\n");
|
||||
}
|
||||
|
||||
ret = of_property_read_u32(child, "bl_ctrl_method", &val);
|
||||
if (ret) {
|
||||
@@ -1780,6 +1788,7 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf)
|
||||
struct aml_lcd_unifykey_header_s bl_header;
|
||||
struct bl_pwm_config_s *bl_pwm;
|
||||
struct bl_pwm_config_s *pwm_combo0, *pwm_combo1;
|
||||
unsigned int level;
|
||||
int ret;
|
||||
|
||||
para = kmalloc((sizeof(unsigned char) * LCD_UKEY_BL_SIZE), GFP_KERNEL);
|
||||
@@ -1840,8 +1849,8 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf)
|
||||
/* level: 6byte */
|
||||
bl_level_uboot = (*(p + LCD_UKEY_BL_LEVEL_UBOOT) |
|
||||
((*(p + LCD_UKEY_BL_LEVEL_UBOOT + 1)) << 8));
|
||||
bconf->level_default = (*(p + LCD_UKEY_BL_LEVEL_KERNEL) |
|
||||
((*(p + LCD_UKEY_BL_LEVEL_KERNEL + 1)) << 8));
|
||||
level = (*(p + LCD_UKEY_BL_LEVEL_KERNEL) |
|
||||
((*(p + LCD_UKEY_BL_LEVEL_KERNEL + 1)) << 8));
|
||||
bconf->level_max = (*(p + LCD_UKEY_BL_LEVEL_MAX) |
|
||||
((*(p + LCD_UKEY_BL_LEVEL_MAX + 1)) << 8));
|
||||
bconf->level_min = (*(p + LCD_UKEY_BL_LEVEL_MIN) |
|
||||
@@ -1851,11 +1860,17 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf)
|
||||
bconf->level_mid_mapping = (*(p + LCD_UKEY_BL_LEVEL_MID_MAP) |
|
||||
((*(p + LCD_UKEY_BL_LEVEL_MID_MAP + 1)) << 8));
|
||||
|
||||
/* adjust brightness_bypass by level_default */
|
||||
if (bconf->level_default > bconf->level_max) {
|
||||
brightness_bypass = 1;
|
||||
BLPR("level_default > level_max, enable brightness_bypass\n");
|
||||
}
|
||||
bconf->level_default = level & BL_LEVEL_MASK;
|
||||
brightness_bypass =
|
||||
((level >> BL_POLICY_BRIGHTNESS_BYPASS_BIT) &
|
||||
BL_POLICY_BRIGHTNESS_BYPASS_MASK);
|
||||
if (brightness_bypass)
|
||||
BLPR("0x%x: enable brightness_bypass\n", level);
|
||||
bl_step_on_flag =
|
||||
((level >> BL_POLICY_POWER_ON_BIT) &
|
||||
BL_POLICY_POWER_ON_MASK);
|
||||
if (bl_step_on_flag)
|
||||
BLPR("0x%x: bl_step_on_flag: %d\n", level, bl_step_on_flag);
|
||||
|
||||
/* method: 8byte */
|
||||
temp = *(p + LCD_UKEY_BL_METHOD);
|
||||
@@ -2200,17 +2215,24 @@ static void aml_bl_on_function(void)
|
||||
bl_drv->state |= (BL_STATE_LCD_ON | BL_STATE_BL_POWER_ON);
|
||||
BLPR("%s: bl_level=%u, state=0x%x\n",
|
||||
__func__, bl_drv->level, bl_drv->state);
|
||||
if (brightness_bypass) {
|
||||
if ((bl_drv->state & BL_STATE_BL_ON) == 0)
|
||||
bl_power_on();
|
||||
} else {
|
||||
if (bl_step_on_flag) {
|
||||
aml_bl_step_on(bl_drv->bconf->level_default);
|
||||
BLPR("bl_on level: %d\n",
|
||||
bl_drv->bldev->props.brightness);
|
||||
}
|
||||
aml_bl_update_status(bl_drv->bldev);
|
||||
if (brightness_bypass)
|
||||
bl_drv->bldev->props.brightness = bl_drv->level;
|
||||
|
||||
switch (bl_step_on_flag) {
|
||||
case 1:
|
||||
aml_bl_step_on(bl_drv->bconf->level_default);
|
||||
BLPR("bl_on level: %d\n",
|
||||
bl_drv->bldev->props.brightness);
|
||||
break;
|
||||
case 2:
|
||||
bl_drv->bldev->props.brightness = bl_level_uboot;
|
||||
BLPR("bl_on level: %d\n",
|
||||
bl_drv->bldev->props.brightness);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
aml_bl_update_brightness_level(bl_drv->bldev->props.brightness);
|
||||
}
|
||||
|
||||
static void aml_bl_delayd_on(struct work_struct *work)
|
||||
@@ -2273,7 +2295,7 @@ static int aml_bl_off_notifier(struct notifier_block *nb,
|
||||
if (bl_drv->state & BL_STATE_BL_ON)
|
||||
bl_power_off();
|
||||
} else
|
||||
aml_bl_update_status(bl_drv->bldev);
|
||||
aml_bl_update_brightness_level(bl_drv->bldev->props.brightness);
|
||||
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
@@ -2298,13 +2320,14 @@ static inline int aml_bl_pwm_vs_lcd_update(struct bl_pwm_config_s *bl_pwm)
|
||||
}
|
||||
|
||||
cnt = bl_vcbus_read(ENCL_VIDEO_MAX_LNCNT) + 1;
|
||||
if (cnt != bl_pwm->pwm_cnt) {
|
||||
bl_pwm_config_init(bl_pwm);
|
||||
if (brightness_bypass)
|
||||
bl_set_duty_pwm(bl_pwm);
|
||||
else
|
||||
aml_bl_update_status(bl_drv->bldev);
|
||||
}
|
||||
if (cnt == bl_pwm->pwm_cnt)
|
||||
return 0;
|
||||
|
||||
bl_pwm_config_init(bl_pwm);
|
||||
if (brightness_bypass)
|
||||
bl_set_duty_pwm(bl_pwm);
|
||||
else
|
||||
aml_bl_update_brightness_level(bl_drv->bldev->props.brightness);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3451,7 +3474,7 @@ static void aml_bl_init_status_update(void)
|
||||
if (brightness_bypass)
|
||||
aml_bl_set_level(bl_on_level);
|
||||
else
|
||||
aml_bl_update_status(bl_drv->bldev);
|
||||
aml_bl_update_brightness_level(bl_drv->bldev->props.brightness);
|
||||
|
||||
switch (bl_drv->bconf->method) {
|
||||
case BL_CTRL_PWM:
|
||||
@@ -3479,10 +3502,8 @@ static int aml_bl_probe(struct platform_device *pdev)
|
||||
aml_bl_off_policy_cnt = 0;
|
||||
|
||||
/* init backlight parameters */
|
||||
brightness_bypass = 0;
|
||||
bl_pwm_bypass = 0;
|
||||
bl_pwm_duty_free = 0;
|
||||
bl_step_on_flag = 0;
|
||||
|
||||
bl_drv = kzalloc(sizeof(struct aml_bl_drv_s), GFP_KERNEL);
|
||||
if (!bl_drv) {
|
||||
|
||||
@@ -95,6 +95,12 @@ enum bl_off_policy_e {
|
||||
BL_OFF_POLICY_MAX,
|
||||
};
|
||||
|
||||
#define BL_LEVEL_MASK 0xfff
|
||||
#define BL_POLICY_BRIGHTNESS_BYPASS_BIT 15
|
||||
#define BL_POLICY_BRIGHTNESS_BYPASS_MASK 1
|
||||
#define BL_POLICY_POWER_ON_BIT 12
|
||||
#define BL_POLICY_POWER_ON_MASK 3
|
||||
|
||||
#define BL_GPIO_OUTPUT_LOW 0
|
||||
#define BL_GPIO_OUTPUT_HIGH 1
|
||||
#define BL_GPIO_INPUT 2
|
||||
|
||||
Reference in New Issue
Block a user