Linux的notifier机制在TP中的应用【转】
转自:https://blog.csdn.net/armfpga123/article/details/51771666
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/armfpga123/article/details/51771666
在linux内核系统中,各个模块、子系统之间是相互独立的。Linux内核可以通过通知链机制来获取由其它模块或子系统产生的它感兴趣的某些事件。
notifier_block结构体在include/linux/notifier.h中定义:
struct notifier_block {
notifier_fn_t notifier_call;
struct notifier_block __rcu *next;
int priority;
};
priority用来定义优先级,高优先级的处理例程将被优先执行,数值越大,优先级越高。
回到函数的原型定义:
typedef int (*notifier_fn_t)(struct notifier_block *nb,
unsigned long action, void *data);
TP属于输入子系统,可以通过获取framebuffer子系统来实现亮屏和灭屏时触发相应的事件。
fb_register_client和fb_unregister_client函数定义在drivers/video/fb_notify.c:
/**
* fb_register_client - register a client notifier
* @nb: notifier block to callback on events
*/
int fb_register_client(struct notifier_block *nb)
{
return blocking_notifier_chain_register(&fb_notifier_list, nb);
}
/**
* fb_unregister_client - unregister a client notifier
* @nb: notifier block to callback on events
*/
int fb_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
}
当framebuffer子系统发生事件时,调用notifier_call_chain()来触发相应的处理函数。
/**
* fb_notifier_call_chain - notify clients of fb_events
*
*/
int fb_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&fb_notifier_list, val, v);
}
下面是一个实例:
struct msg21xx_ts_data {
struct input_dev *input;
struct hrtimer timer;
struct work_struct work;
int irq;
struct dentry *dir;
char *ts_info;
u8 addr;
int fw_major;
int fw_minor;
#ifdef CONFIG_FB
struct notifier_block fb_notif;
#endif
bool suspended;
struct i2c_client *client;
struct regulator *vdd;
struct regulator *vcc_i2c;
struct msg21xx_platform_data *pdata;
struct workqueue_struct *msg21xx_wq;
struct mutex msg21xx_mutex;
};
probe函数中与notifier相关部分实现:
struct msg21xx_ts_data *data;
data = kzalloc(sizeof(struct msg21xx_ts_data), GFP_KERNEL);
if (!data) {
dev_err(&client->dev, "%s: Alloc mem fail!", __func__);
err = -ENOMEM;
goto exit;
}
#ifdef CONFIG_FB
data->fb_notif.notifier_call = fb_notifier_callback;
err = fb_register_client(&data->fb_notif);
if (err)
dev_err(&client->dev, "Unable to register fb_notifier: %d\n",
err);
#endif
fb_notifier_callback实现:
#ifdef CONFIG_FB
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
struct fb_event *evdata = data;
int *blank;
struct msg21xx_ts_data *msg21xx_data =
container_of(self, struct msg21xx_ts_data, fb_notif);
if (evdata && evdata->data && event == FB_EVENT_BLANK &&
msg21xx_data && msg21xx_data->client) {
blank = evdata->data;
if (*blank == FB_BLANK_UNBLANK)
msg21xx_ts_resume(&msg21xx_data->client->dev);
else if (*blank == FB_BLANK_POWERDOWN)
---------------------
作者:ELinux2607
来源:CSDN
原文:https://blog.csdn.net/armfpga123/article/details/51771666
版权声明:本文为博主原创文章,转载请附上博文链接!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
2015-03-06 CC254x/CC2540/CC2541库函数速查(转)
2015-03-06 BLE获取iphone mac地址的方法--【原创】