Skip to content

Commit

Permalink
backlight: driver defect clean up
Browse files Browse the repository at this point in the history
driver defect clean up:
torvalds#40
torvalds#41
torvalds#99
torvalds#100
torvalds#395
torvalds#396
torvalds#475
torvalds#614
torvalds#669

Change-Id: I581aaa8a1b950278bbf74d0c94aa647de89e07a9
Signed-off-by: Evoke Zhang <evoke.zhang@amlogic.com>
  • Loading branch information
Evoke Zhang authored and akiernan committed Nov 4, 2022
1 parent 2386245 commit 225647f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
82 changes: 56 additions & 26 deletions drivers/amlogic/media/vout/backlight/aml_bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ static char *bl_pinmux_str[] = {
"pwm_combo_0_1_on", /* 2 */
"pwm_combo_0_vs_1_on", /* 3 */
"pwm_combo_0_1_vs_on", /* 4 */
"none",
};

static void bl_pwm_pinmux_set(struct bl_config_s *bconf)
Expand Down Expand Up @@ -1070,6 +1071,7 @@ static char *bl_pwm_name[] = {
"PWM_E",
"PWM_F",
"PWM_VS",
"invalid",
};

enum bl_pwm_port_e bl_pwm_str_to_pwm(const char *str)
Expand Down Expand Up @@ -1271,7 +1273,9 @@ static int aml_bl_config_load_from_dts(struct bl_config_s *bconf,
BLERR("failed to get bl_name\n");
str = "backlight";
}
strcpy(bconf->name, str);
strncpy(bconf->name, str, BL_NAME_MAX);
/* ensure string ending */
bconf->name[BL_NAME_MAX-1] = '\0';

ret = of_property_read_u32_array(child, "bl_level_default_uboot_kernel",
&bl_para[0], 2);
Expand Down Expand Up @@ -1591,9 +1595,10 @@ static int aml_bl_config_load_from_unifykey(struct bl_config_s *bconf)

/* basic: 30byte */
p = para + LCD_UKEY_HEAD_SIZE;
*(p + LCD_UKEY_BL_NAME - 1) = '\0'; /* ensure string ending */
str = (const char *)p;
strcpy(bconf->name, str);
strncpy(bconf->name, str, BL_NAME_MAX);
/* ensure string ending */
bconf->name[BL_NAME_MAX-1] = '\0';
p += LCD_UKEY_BL_NAME;

/* level: 6byte */
Expand Down Expand Up @@ -2531,33 +2536,61 @@ static ssize_t bl_debug_pwm_store(struct class *class,
case 'f':
if (buf[3] == 'q') { /* frequency */
ret = sscanf(buf, "freq %d %d", &index, &val);
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_FREQ);
if (ret == 2)
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_FREQ);
else
BLERR("invalid parameters\n");
} else if (buf[3] == 'e') { /* duty free */
ret = sscanf(buf, "free %d", &val);
bl_pwm_duty_free = (unsigned char)val;
BLPR("set bl_pwm_duty_free: %d\n", bl_pwm_duty_free);
if (ret == 1) {
bl_pwm_duty_free = (unsigned char)val;
BLPR("set bl_pwm_duty_free: %d\n",
bl_pwm_duty_free);
} else {
BLERR("invalid parameters\n");
}
}
break;
case 'd': /* duty */
ret = sscanf(buf, "duty %d %d", &index, &val);
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_DUTY);
if (ret == 2)
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_DUTY);
else
BLERR("invalid parameters\n");
break;
case 'p': /* polarity */
ret = sscanf(buf, "pol %d %d", &index, &val);
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_POL);
if (ret == 2)
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_POL);
else
BLERR("invalid parameters\n");
break;
case 'b': /* bypass */
ret = sscanf(buf, "bypass %d", &val);
bl_pwm_bypass = (unsigned char)val;
BLPR("set bl_pwm_bypass: %d\n", bl_pwm_bypass);
if (ret == 1) {
bl_pwm_bypass = (unsigned char)val;
BLPR("set bl_pwm_bypass: %d\n", bl_pwm_bypass);
} else {
BLERR("invalid parameters\n");
}
break;
case 'm':
if (buf[1] == 'a') { /* max */
ret = sscanf(buf, "max %d %d", &index, &val);
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_DUTY_MAX);
if (ret == 2) {
bl_debug_pwm_set(index, val,
BL_DEBUG_PWM_DUTY_MAX);
} else {
BLERR("invalid parameters\n");
}
} else if (buf[1] == 'i') { /* min */
ret = sscanf(buf, "min %d %d", &index, &val);
bl_debug_pwm_set(index, val, BL_DEBUG_PWM_DUTY_MIN);
if (ret == 2) {
bl_debug_pwm_set(index, val,
BL_DEBUG_PWM_DUTY_MIN);
} else {
BLERR("invalid parameters\n");
}
}
break;
default:
Expand Down Expand Up @@ -2591,8 +2624,10 @@ static ssize_t bl_debug_power_store(struct class *class,
unsigned int temp = 0;

ret = kstrtouint(buf, 10, &temp);
if (ret != 0)
if (ret != 0) {
BLERR("invalid data\n");
return -EINVAL;
}

BLPR("power control: %u\n", temp);
if ((bl_drv->state & BL_STATE_LCD_ON) == 0) {
Expand Down Expand Up @@ -2680,19 +2715,14 @@ static ssize_t bl_debug_print_store(struct class *class,
}

static struct class_attribute bl_debug_class_attrs[] = {
__ATTR(help, 0644, bl_debug_help, NULL),
__ATTR(status, 0644, bl_status_read, NULL),
__ATTR(pwm, 0644, bl_debug_pwm_show,
bl_debug_pwm_store),
__ATTR(power, 0644, bl_debug_power_show,
bl_debug_power_store),
__ATTR(delay, 0644, bl_debug_delay_show,
bl_debug_delay_store),
__ATTR(key_valid, 0644, bl_debug_key_valid_show, NULL),
__ATTR(config_load, 0644,
bl_debug_config_load_show, NULL),
__ATTR(print, 0644, bl_debug_print_show,
bl_debug_print_store),
__ATTR(help, 0444, bl_debug_help, NULL),
__ATTR(status, 0444, bl_status_read, NULL),
__ATTR(pwm, 0644, bl_debug_pwm_show, bl_debug_pwm_store),
__ATTR(power, 0644, bl_debug_power_show, bl_debug_power_store),
__ATTR(delay, 0644, bl_debug_delay_show, bl_debug_delay_store),
__ATTR(key_valid, 0444, bl_debug_key_valid_show, NULL),
__ATTR(config_load, 0444, bl_debug_config_load_show, NULL),
__ATTR(print, 0644, bl_debug_print_show, bl_debug_print_store),
};

static int aml_bl_creat_class(void)
Expand Down
3 changes: 2 additions & 1 deletion include/linux/amlogic/media/vout/lcd/aml_bl.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ struct bl_pwm_config_s {
unsigned int pwm_level; /* internal used for pwm control */
};

#define BL_NAME_MAX 30
struct bl_config_s {
char name[30];
char name[BL_NAME_MAX];
unsigned int level_default;
unsigned int level_min;
unsigned int level_max;
Expand Down

0 comments on commit 225647f

Please sign in to comment.