int dsi_panel_set_backlight(struct dsi_panel panel, u32 bl_lvl) { int rc = 0; struct dsi_backlight_config bl = &panel->bl_config; if (panel->host_config.ext_bridge_mode) return 0; DSI_DEBUG("backlight type:%d lvl:%d\n", bl->type, bl_lvl); switch (bl->type) { case DSI_BACKLIGHT_WLED: rc = backlight_device_set_brightness(bl->raw_bd, bl_lvl); break; case DSI_BACKLIGHT_DCS: rc = dsi_panel_update_backlight(panel, bl_lvl); break; case DSI_BACKLIGHT_EXTERNAL: rc = lcd_bl_set_led_brightness(bl_lvl); //pr_err("dsi set bias brightness: %d\n", bl_lvl); rc = lcd_bias_set_led_brightness(bl_lvl); //pr_err("dsi set brightness: %d\n", bl_lvl); break; case DSI_BACKLIGHT_PWM: rc = dsi_panel_update_pwm_backlight(panel, bl_lvl); break; default: DSI_ERR("Backlight type(%d) not supported\n", bl->type); rc = -ENOTSUPP; } return rc; } int lcd_bl_set_led_brightness(int value)//for set bringhtness { dev_warn(&lcd_bl_i2c_client->dev, "lcm 8866 bl = %d\n", value); if (value < 0) { dev_warn(&lcd_bl_i2c_client->dev, "value=%d\n", value); return 0; } if (value > 0) { lcd_bl_write_byte(KTZ8866_DISP_BB_LSB, value & 0x07);// lsb lcd_bl_write_byte(KTZ8866_DISP_BB_MSB, (value >> 3) & 0xFF);// msb lcd_bl_write_byte(KTZ8866_DISP_BL_ENABLE, 0x4F); / BL enabled and Current sink 1/2/3/4 enabled;/ } else { lcd_bl_write_byte(KTZ8866_DISP_BB_LSB, 0x00);// lsb lcd_bl_write_byte(KTZ8866_DISP_BB_MSB, 0x00);// msb lcd_bl_write_byte(KTZ8866_DISP_BL_ENABLE, 0x00); /* BL enabled and Current sink 1/2/3/4 disabled;/ } return 0; } int lcd_bias_set_led_brightness(int value)//for set bringhtness { dev_warn(&lcd_bl_bias_i2c_client->dev, "lcm 8866 bl = %d\n", value); if (value < 0) { dev_warn(&lcd_bl_bias_i2c_client->dev, "invalid value=%d\n", value); return 0; } if (value > 0) { lcd_bl_bias_write_byte(KTZ8866_DISP_BB_LSB, value & 0x07);// lsb lcd_bl_bias_write_byte(KTZ8866_DISP_BB_MSB, (value >> 3) & 0xFF);// msb lcd_bl_bias_write_byte(KTZ8866_DISP_BL_ENABLE, 0x4F); / BL enabled and Current sink 1/2/3/4 enabled;/ } else { lcd_bl_bias_write_byte(KTZ8866_DISP_BB_LSB, 0x00);// lsb lcd_bl_bias_write_byte(KTZ8866_DISP_BB_MSB, 0x00);// msb lcd_bl_bias_write_byte(KTZ8866_DISP_BL_ENABLE, 0x00); / BL enabled and Current sink 1/2/3/4 disabled;*/ } return 0; } dsi_panel_set_backlight、lcd_bl_set_led_brightness和lcd_bias_set_led_brightness源码如上,帮忙用内核线程的方式,同时实现在case DSI_BACKLIGHT_EXTERNAL:下并发执行lcd_bl_set_led_brightness和lcd_bias_set_led_brightness两个函数
时间: 2023-08-26 18:03:51 浏览: 64
好的,我理解你的问题了。你需要用内核线程的方式,在case DSI_BACKLIGHT_EXTERNAL:下并发执行lcd_bl_set_led_brightness和lcd_bias_set_led_brightness两个函数。
为了实现这个目的,你可以创建两个内核线程,一个用于调用lcd_bl_set_led_brightness函数,另一个用于调用lcd_bias_set_led_brightness函数。这两个线程可以同时运行,从而实现并发执行这两个函数的目的。
具体实现方法如下所示:
首先,在dsi_panel_set_backlight函数的case DSI_BACKLIGHT_EXTERNAL:分支下,创建两个内核线程:
```
case DSI_BACKLIGHT_EXTERNAL:
{
int ret1, ret2;
struct task_struct *thread1 = kthread_run(lcd_bl_thread, (void *)&value, "lcd_bl_thread");
struct task_struct *thread2 = kthread_run(lcd_bias_thread, (void *)&value, "lcd_bias_thread");
if (IS_ERR(thread1)) {
ret1 = PTR_ERR(thread1);
pr_err("Failed to create lcd_bl_thread: %d\n", ret1);
}
if (IS_ERR(thread2)) {
ret2 = PTR_ERR(thread2);
pr_err("Failed to create lcd_bias_thread: %d\n", ret2);
}
break;
}
```
其中,lcd_bl_thread和lcd_bias_thread是两个内核线程的函数,value是传递给这两个函数的参数。
接下来,实现lcd_bl_thread和lcd_bias_thread函数:
```
static int lcd_bl_thread(void *data)
{
int value = *(int *)data;
lcd_bl_set_led_brightness(value);
return 0;
}
static int lcd_bias_thread(void *data)
{
int value = *(int *)data;
lcd_bias_set_led_brightness(value);
return 0;
}
```
这两个函数分别调用lcd_bl_set_led_brightness和lcd_bias_set_led_brightness函数,从而实现了并发执行这两个函数的目的。
最后,不要忘记在模块初始化时创建线程:
```
static int __init my_module_init(void)
{
// ...
lcd_bl_thread = kthread_create(lcd_bl_thread, NULL, "lcd_bl_thread");
lcd_bias_thread = kthread_create(lcd_bias_thread, NULL, "lcd_bias_thread");
// ...
return 0;
}
```
这样,当模块加载时,lcd_bl_thread和lcd_bias_thread线程将被创建,并在需要时被dsi_panel_set_backlight函数调用。
阅读全文