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 ...
随机推荐
- data_type
import logging logger = logging.getLogger("simple_example") logger.setLevel(logging.DEBUG) ...
- nGrinder TestRunner http post json
s nGrinder学习笔记 — post请求 https://blog.csdn.net/meyoung01/article/details/50435881 import HTTPClient.H ...
- CentOS 网络设置
CentOS 网络设置有两种方式配置网络可以连接外网: 自动分配与手动设置Ip 一,自动分配ip: 新装的centos6.0,用ifconfig只显示ifcfg-lo的信息,可以用ifup eth0的 ...
- MySql 游标笔记
delimiter &&create PROCEDURE findProjectDetailsByProjectId(in p_userId int)BEGIN DECLARE d ...
- C#设计模式(11)——装饰者模式
1.装饰者模式介绍 装饰者顾名思义就是对一个类添加一些额外的装饰(功能).我们想给一个对象添加一些额外的功能又不改变对象内方法的签名怎么做呢?最常用的方法就是继承了,子类继承父类,然后重写父类的方法. ...
- C#设计模式(8)——外观模式
1.外观模式介绍 外观模式也被叫做门面模式,这种模式的作用是:隐藏系统的复杂性,并向客户端提供了一个可以访问系统的统一接口,这个统一的接口组合了子系统的多个接口.使用统一的接口使得子系统更容易被访问或 ...
- ruby数据库表添加字段、修改字段类型、修改字段名称
Rails 手册 3.8 使用 change 方法 1.为表添加字段 rails g migration add_column_to_d_groups_equip_num class AddColum ...
- DirectX11 With Windows SDK--03 索引缓冲区、常量缓冲区
前言 一个立方体有8个顶点,然而绘制一个立方体需要画12个三角形,如果按照前面的方法绘制的话,则需要提供36个顶点,而且这里面的顶点数据会重复4次甚至5次.这样的绘制方法会占用大量的内存空间. 接下来 ...
- 【转载】 C#读写注册表
文章地址:https://blog.csdn.net/younghaiqing/article/details/61918968 自Windows95以来的所有Windows版本中,注册表是包含Win ...
- 使用jedis客户端连接redis,单机版和集群版
单机版 1.入门实例 @Test public void testJedis(){ //创建一个jedis对象,需要指定服务的ip和端口号 Jedis jedis=new Jedis("19 ...