高通sm6225平台linux 驱动如何注册获取亮灭屏通知链
时间: 2023-11-21 07:05:32 浏览: 46
在高通sm6225平台上,驱动可以通过注册input子系统的设备来获取亮灭屏通知链。具体实现方式如下:
1. 定义input子系统设备结构体,其中包括input_dev结构体和platform_device结构体。例如:
```
struct msm6225_input_dev {
struct input_dev *input_dev;
struct platform_device *pdev;
};
static struct msm6225_input_dev msm6225_input = {
.input_dev = NULL,
.pdev = NULL,
};
```
2. 在probe函数中初始化input_dev结构体,并注册input子系统设备。例如:
```
static int msm6225_input_probe(struct platform_device *pdev)
{
struct msm6225_input_dev *dev;
int error = 0;
dev = kzalloc(sizeof(struct msm6225_input_dev), GFP_KERNEL);
if (!dev) {
error = -ENOMEM;
goto err_alloc;
}
dev->input_dev = input_allocate_device();
if (!dev->input_dev) {
error = -ENOMEM;
goto err_alloc;
}
dev->input_dev->name = "msm6225_input";
dev->input_dev->id.bustype = BUS_HOST;
dev->input_dev->dev.parent = &pdev->dev;
dev->input_dev->evbit[0] = BIT_MASK(EV_KEY);
dev->input_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
error = input_register_device(dev->input_dev);
if (error) {
goto err_reg;
}
dev->pdev = pdev;
platform_set_drvdata(pdev, dev);
return 0;
err_reg:
input_free_device(dev->input_dev);
err_alloc:
kfree(dev);
return error;
}
```
3. 在remove函数中注销input子系统设备。例如:
```
static int msm6225_input_remove(struct platform_device *pdev)
{
struct msm6225_input_dev *dev = platform_get_drvdata(pdev);
input_unregister_device(dev->input_dev);
input_free_device(dev->input_dev);
kfree(dev);
return 0;
}
```
4. 在设备树中添加input节点,并设置相关属性。例如:
```
input {
compatible = "qcom,msm-input";
status = "okay";
};
```
5. 在驱动中注册input子系统设备驱动。例如:
```
static struct platform_driver msm6225_input_driver = {
.driver = {
.name = "msm6225_input",
.owner = THIS_MODULE,
},
.probe = msm6225_input_probe,
.remove = msm6225_input_remove,
};
module_platform_driver(msm6225_input_driver);
```
以上是一种注册获取亮灭屏通知链的实现方式,具体实现可能因设备而异,需要参考具体的设备和内核版本。