日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux的notifier机制在TP中的应用【转】

發布時間:2025/7/25 linux 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

轉載于:https://www.cnblogs.com/sky-heaven/p/10483249.html

總結

以上是生活随笔為你收集整理的Linux的notifier机制在TP中的应用【转】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。