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
版权声明:本文为博主原创文章,转载请附上博文链接!
Linux的notifier机制在TP中的应用【转】的更多相关文章
- Linux的notifier机制的应用
在linux内核系统中,各个模块.子系统之间是相互独立的.Linux内核可以通过通知链机制来获取由其它模块或子系统产生的它感兴趣的某些事件. notifier_block结构体在include/lin ...
- Linux下IPC机制
Linux下IPC机制 实践要求 研究Linux下IPC机制:原理,优缺点,每种机制至少给一个示例,提交研究博客的链接 共享内存 管道 FIFO 信号 消息队列 IPC 进程间通信(IPC,Inter ...
- 浅谈Linux内存管理机制
经常遇到一些刚接触Linux的新手会问内存占用怎么那么多?在Linux中经常发现空闲内存很少,似乎所有的内存都被系统占用了,表面感觉是内存不够用了,其实不然.这是Linux内存管理的一个优秀特性,在这 ...
- Linux的io机制
Linux的io机制 Buffered-IO 和Direct-IO Linux磁盘I/O分为Buffered IO和Direct IO,这两者有何区别呢? 对于Buffered IO: 当应用程序尝试 ...
- 转载~kxcfzyk:Linux C语言多线程库Pthread中条件变量的的正确用法逐步详解
Linux C语言多线程库Pthread中条件变量的的正确用法逐步详解 多线程c语言linuxsemaphore条件变量 (本文的读者定位是了解Pthread常用多线程API和Pthread互斥锁 ...
- [内核同步]浅析Linux内核同步机制
转自:http://blog.csdn.net/fzubbsc/article/details/37736683?utm_source=tuicool&utm_medium=referral ...
- Linux内核同步机制--转发自蜗窝科技
Linux内核同步机制之(一):原子操作 http://www.wowotech.net/linux_kenrel/atomic.html 一.源由 我们的程序逻辑经常遇到这样的操作序列: 1.读一个 ...
- 了解linux内存管理机制(转)
今天了解了下linux内存管理机制,在这里记录下,原文在这里http://ixdba.blog.51cto.com/2895551/541355 根据自己的理解画了张图: 下面是转载的内容: 一 物理 ...
- 【Linux下进程机制】从一道面试题谈linux下fork的运行机制
今天一位朋友去一个不错的外企面试linux开发职位,面试官出了一个如下的题目: 给出如下C程序,在linux下使用gcc编译: #include "stdio.h" #includ ...
随机推荐
- Python中函数的嵌套及闭包
函数的嵌套 调用:在函数中调用函数 定义:在函数中定义函数 地址:函数名有内存地址,内存地址可赋值 示例 a = 1 def outer(): a = 1 def inner(): a = 2 def ...
- MyBatis-SqlSessionFactory的创建
Main 方法,mybatis 版本为 3.5.0 解析配置文件的所有信息,保存在 Configuration 中,返回包含 Configuration 的 DefaultSqlSession Map ...
- Sidekiq定时任务时间设置
minutely(2) #每2分钟执行一次 hourly.minute_of_hour(27) #每小时的27分钟执行 dail ...
- SpringCloud微服务之跨服务调用后端接口
SpringCloud微服务系列博客: SpringCloud微服务之快速搭建EurekaServer:https://blog.csdn.net/egg1996911/article/details ...
- 转载---滋滋有味看完的一篇文章关于python与java夜话
这是一个程序员的电脑硬盘,在一个叫做"学习"的目录下曾经生活着两个小程序,一个叫做Hello.java,即Java小子:另外一个叫做hello.c ,也就是C老头儿. C老头儿的命 ...
- 缓存之 -Redis
其实这类服务还一样, server , client 两端... WIN 和 linux 均可,开源发现源码还是 C 看来 C 还是王者哦...后悔没深入学 Redis支持五种数据类型:string( ...
- oracle修改密码为永久不过期
sqlplus /as sysdba ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
- Information Retrieval 倒排索引 学习笔记
一,问题描述 在Shakespeare文集(有很多文档Document)中,寻找哪个文档包含了单词“Brutus”和"Caesar",且不包含"Calpurnia&quo ...
- Mac 下搭建环境 homebrew/git/node.js/npm/vsCode...
主要记录一下 homebrew/git/node.js/npm/mysql 的命令行安装 1. 首先安装 homebrew 也是一个包管理工具: mac 里打开终端命令行工具,粘下面一行回车安装br ...
- Jupyter NoteBook使用快捷键
命令模式 (按键 Esc 开启) Enter : 转入编辑模式 Shift-Enter : 运行本单元,选中下个单元 Ctrl-Enter : 运行本单元 Alt-Enter : 运行本单元,在其下插 ...