Linux的notifier机制在TP中的应用【转】
轉(zhuǎn)自:https://blog.csdn.net/armfpga123/article/details/51771666
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。 https://blog.csdn.net/armfpga123/article/details/51771666
在linux內(nèi)核系統(tǒng)中,各個(gè)模塊、子系統(tǒng)之間是相互獨(dú)立的。Linux內(nèi)核可以通過(guò)通知鏈機(jī)制來(lái)獲取由其它模塊或子系統(tǒng)產(chǎn)生的它感興趣的某些事件。
notifier_block結(jié)構(gòu)體在include/linux/notifier.h中定義:
struct notifier_block {
notifier_fn_t notifier_call;
struct notifier_block __rcu *next;
int priority;
};
priority用來(lái)定義優(yōu)先級(jí),高優(yōu)先級(jí)的處理例程將被優(yōu)先執(zhí)行,數(shù)值越大,優(yōu)先級(jí)越高。
回到函數(shù)的原型定義:
typedef int (*notifier_fn_t)(struct notifier_block *nb,
unsigned long action, void *data);
TP屬于輸入子系統(tǒng),可以通過(guò)獲取framebuffer子系統(tǒng)來(lái)實(shí)現(xiàn)亮屏和滅屏?xí)r觸發(fā)相應(yīng)的事件。
fb_register_client和fb_unregister_client函數(shù)定義在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);
}
當(dāng)framebuffer子系統(tǒng)發(fā)生事件時(shí),調(diào)用notifier_call_chain()來(lái)觸發(fā)相應(yīng)的處理函數(shù)。
/**
* 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);
}
下面是一個(gè)實(shí)例:
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函數(shù)中與notifier相關(guān)部分實(shí)現(xiàn):
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實(shí)現(xiàn):
#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
來(lái)源:CSDN
原文:https://blog.csdn.net/armfpga123/article/details/51771666
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!
轉(zhuǎn)載于:https://www.cnblogs.com/sky-heaven/p/10483249.html
總結(jié)
以上是生活随笔為你收集整理的Linux的notifier机制在TP中的应用【转】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MYSQL水平拆分与垂直拆分
- 下一篇: etcd代理组件的开发思想