client = kzalloc(sizeof(*client), GFP_KERNEL);
时间: 2023-05-16 12:07:04 浏览: 283
这是一个内核分配内存的函数,用于在内核中动态分配内存。具体来说,它会分配一个大小为 sizeof(*client) 的内存块,并返回指向该内存块的指针。这个函数的参数 GFP_KERNEL 表示内存分配的标志,它告诉内核这个内存块是用于内核的,而不是用户空间的。
相关问题
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两个函数
好的,我可以为您提供一个使用工作队列来实现并发执行`lcd_bl_set_led_brightness`和`lcd_bias_set_led_brightness`的示例代码。具体实现方法如下:
1. 定义一个工作结构体`struct work_struct`,并在其中传递参数。
```
struct backlight_work {
struct work_struct work;
struct i2c_client *lcd_bl_i2c_client;
struct i2c_client *lcd_bl_bias_i2c_client;
int value;
};
```
2. 定义工作队列。
```
static struct workqueue_struct *bl_workqueue;
```
3. 在`dsi_panel_set_backlight`函数中,将`lcd_bl_set_led_brightness`和`lcd_bias_set_led_brightness`函数的调用封装成一个工作任务,并将任务推入工作队列。
```
case DSI_BACKLIGHT_EXTERNAL:
{
struct backlight_work *bl_work;
bl_work = kzalloc(sizeof(*bl_work), GFP_KERNEL);
if (!bl_work)
return -ENOMEM;
INIT_WORK(&bl_work->work, backlight_worker);
bl_work->lcd_bl_i2c_client = lcd_bl_i2c_client;
bl_work->lcd_bl_bias_i2c_client = lcd_bl_bias_i2c_client;
bl_work->value = bl_lvl;
queue_work(bl_workqueue, &bl_work->work);
break;
}
```
4. 在`backlight_worker`函数中,实现`lcd_bl_set_led_brightness`和`lcd_bias_set_led_brightness`函数的并发执行。
```
static void backlight_worker(struct work_struct *work)
{
struct backlight_work *bl_work = container_of(work, struct backlight_work, work);
int value = bl_work->value;
if (value < 0) {
dev_warn(&bl_work->lcd_bl_i2c_client->dev, "invalid value=%d\n", value);
} else if (value > 0) {
lcd_bl_write_byte(KTZ8866_DISP_BB_LSB, value & 0x07);
lcd_bl_write_byte(KTZ8866_DISP_BB_MSB, (value >> 3) & 0xFF);
lcd_bl_write_byte(KTZ8866_DISP_BL_ENABLE, 0x4F);
lcd_bl_bias_write_byte(KTZ8866_DISP_BB_LSB, value & 0x07);
lcd_bl_bias_write_byte(KTZ8866_DISP_BB_MSB, (value >> 3) & 0xFF);
lcd_bl_bias_write_byte(KTZ8866_DISP_BL_ENABLE, 0x4F);
} else {
lcd_bl_write_byte(KTZ8866_DISP_BB_LSB, 0x00);
lcd_bl_write_byte(KTZ8866_DISP_BB_MSB, 0x00);
lcd_bl_write_byte(KTZ8866_DISP_BL_ENABLE, 0x00);
lcd_bl_bias_write_byte(KTZ8866_DISP_BB_LSB, 0x00);
lcd_bl_bias_write_byte(KTZ8866_DISP_BB_MSB, 0x00);
lcd_bl_bias_write_byte(KTZ8866_DISP_BL_ENABLE, 0x00);
}
kfree(bl_work);
}
```
这样,当`dsi_panel_set_backlight`函数中调用`lcd_bl_set_led_brightness`和`lcd_bias_set_led_brightness`时,会将其封装成一个工作任务并推入工作队列中,`backlight_worker`函数实现这两个函数的并发执行。
高通单安卓平台没有i2c_client_get_device_id函数怎么办
在 Android 平台上,如果没有 `i2c_client_get_device_id` 函数,可以尝试使用 `i2c_adapter_id` 和 `addr` 字段来实现类似的功能。具体的实现方法如下:
1. 获取 `i2c_adapter` 结构体对象:
```C
struct i2c_adapter *adapter = i2c_get_adapter(bus_num);
```
其中,`bus_num` 是 I2C 总线的编号。
2. 构造 `i2c_client` 结构体对象:
```C
struct i2c_client *client = kzalloc(sizeof(*client), GFP_KERNEL);
client->adapter = adapter;
client->addr = slave_address;
```
其中,`slave_address` 是 I2C 从设备的地址。
3. 获取从设备的 ID:
```C
int id = (int)client->adapter->nr << 16 | client->addr;
```
其中,`id` 可以作为从设备的唯一标识符来使用。
需要注意的是,不同的 I2C 控制器可能会有不同的实现方式,因此具体的实现细节可能会有所不同。建议先查看相关文档或者参考其他相关代码实现。
阅读全文