disable_irq与disable_irq_nosync使用场景
static irqreturn_t ltr559_irq_handler(int irq, void *arg)
{
struct ltr559_data *data = (struct ltr559_data *)arg;
//printk("%s\n",__func__);
if (NULL == data)
return IRQ_HANDLED;
//后面必须有使能中断
disable_irq_nosync(data->irq);
//屏蔽中断,不会造成死锁
schedule_delayed_work(&data->ps_work, 0);
//调用延时工作队列
return IRQ_HANDLED;
}
//PS工作任务
//重要接口
static void ltr559_ps_work_func(struct work_struct *work)
{
struct ltr559_data *data = container_of(work, struct ltr559_data, ps_work.work);
struct i2c_client *client=data->client;
int als_ps_status;
int psval_lo, psval_hi, psdata;
static u32 ps_state_last = 2;
//Far as default.
mutex_lock(&data->op_lock);
als_ps_status = i2c_smbus_read_byte_data(client, LTR559_ALS_PS_STATUS);
//printk("%s ps_open_state=%d, als_ps_status=0x%x\n",__func__,data->ps_open_state,als_ps_status);
if (als_ps_status < 0)
goto workout;
/* Here should check data status,ignore interrupt status. */
/* Bit 0: PS Data
* Bit 1: PS interrupt
* Bit 2: ASL Data
* Bit 3: ASL interrupt
* Bit 4: ASL Gain 0: ALS measurement data is in dynamic range 2 (2 to 64k lux)
* 1: ALS measurement data is in dynamic range 1 (0.01 to 320 lux)
*/
//使能情况
if ((data->ps_open_state == 1) && (als_ps_status & 0x02)) {
psval_lo = i2c_smbus_read_byte_data(client, LTR559_PS_DATA_0);
if (psval_lo < 0) {
psdata = psval_lo;
goto workout;
}
psval_hi = i2c_smbus_read_byte_data(client, LTR559_PS_DATA_1);
if (psval_hi < 0) {
psdata = psval_hi;
goto workout;
}
psdata = ((psval_hi & 7) << 8) | psval_lo;
printk("%s: psdata=%d(0x%x), near_thrd=%u, far_thrd=%u, dynamic_noise=%u\n",
__func__, psdata, (u32)psdata, data->platform_data->prox_threshold,
data->platform_data->prox_hsyteresis_threshold, data->dynamic_noise);
if(psdata >= data->platform_data->prox_threshold){
data->ps_state = 0; //near
ltr559_set_ps_threshold(client, LTR559_PS_THRES_LOW_0, data->platform_data->prox_hsyteresis_threshold);
ltr559_set_ps_threshold(client, LTR559_PS_THRES_UP_0, 0x07ff);
printk("%s: near, update near_thrd=%u, far_thrd=%u\n",
__func__, 0x7ff, data->platform_data->prox_hsyteresis_threshold);
} else if (psdata <= data->platform_data->prox_hsyteresis_threshold){
data->ps_state = 1; //far
//该宏已经定义
#if defined(CONFIG_PICCOLO_COMMON)
if (data->dynamic_noise > 20 && psdata < (data->dynamic_noise - 50) ) {
data->dynamic_noise = psdata;
if(psdata < 100) {
}else if(psdata < 200){
data->platform_data->prox_threshold = psdata+230;
data->platform_data->prox_hsyteresis_threshold = psdata+180;
}else if(psdata < 500){
data->platform_data->prox_threshold = psdata+280;
data->platform_data->prox_hsyteresis_threshold = psdata+230;
}else if(psdata < 1500){
data->platform_data->prox_threshold = psdata+420;
data->platform_data->prox_hsyteresis_threshold = psdata+350;
}else{
data->platform_data->prox_threshold= 1800;
data->platform_data->prox_hsyteresis_threshold= 1700;
pr_err("ltr559 the proximity sensor rubber or structure is error!\n");
}
printk("%s: NEW prox_threshold=%u, prox_hsyteresis_threshold=%u !!!\n",
__func__, data->platform_data->prox_threshold,
data->platform_data->prox_hsyteresis_threshold);
}
#endif
ltr559_set_ps_threshold(client, LTR559_PS_THRES_LOW_0, 0);
ltr559_set_ps_threshold(client, LTR559_PS_THRES_UP_0, data->platform_data->prox_threshold);
printk("%s: far, update near_thrd=%u, far_thrd=0\n",
__func__, data->platform_data->prox_threshold);
} else {
data->ps_state = ps_state_last;
}
printk("%s: ps_state_last = %u, ps_state = %u\n", __func__, ps_state_last, data->ps_state);
if((ps_state_last != data->ps_state) || (data->ps_state == 0)) //need report the input event constant when near
{
//上报数据
input_report_abs(data->input_dev_ps, ABS_DISTANCE, data->ps_state);
input_sync(data->input_dev_ps);
printk("%s: report ABS_DISTANCE=%s\n",__func__, data->ps_state ? "far" : "near");
ps_state_last = data->ps_state;
//Report ABS value only if the state changed.
}
else
printk("%s: ps_state still %s\n", __func__, data->ps_state ? "far" : "near");
}
workout:
enable_irq(data->irq);
//使能
irq
mutex_unlock(&data->op_lock);
//解锁
}
disable_irq与disable_irq_nosync使用场景的更多相关文章
- disable_irq()与disable_irq_nosync()区别
disable_irq关闭中断并等待中断处理完后返回, 而disable_irq_nosync立即返回.
- 【转】中断处理函数中不用disable_irq而用disable_irq_nosync原因
原文网址:http://blog.csdn.net/skyflying2012/article/details/8265869 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现 ...
- 中断处理函数中不用disable_irq而用disable_irq_nosync原因【转】
转自:http://blog.csdn.net/beyondioi/article/details/9201695 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现在进入中断处 ...
- Linux内核设计与实现 读书笔记
第三章 进程管理 1. fork系统调用从内核返回两次: 一次返回到子进程,一次返回到父进程 2. task_struct结构是用slab分配器分配的,2.6以前的是放在内核栈的栈底的:所有进程的ta ...
- kernel笔记——中断
cpu与磁盘.网卡.键盘等外围设备(相对于cpu和内存而言)交互时,cpu下发I/O请求到这些设备后,相对cpu的处理能力而言,磁盘.网卡等设备需要较长时间完成请求处理. 那么在请求发出到处理完成这段 ...
- Linux设备驱动 之 中断处理程序
注册中断处理程序 中断处理程序是管理硬件驱动程序的组成部分:如果设备使用中断,那么相应的驱动程序就注册一个中断处理程序: 驱动程序通过request_irq()函数注册,并且激活给定的中断线,以处理中 ...
- local_irq_disable和disable_irq的区别
local_irq_disable: local_irq_disable的功能是屏蔽当前CPU上的所有中断,通过操作arm核心中的寄存器来屏蔽到达CPU上的中断,此时中断控制器中所有送往该CPU上的中 ...
- 拨开迷雾,找回自我:DDD 应对具体业务场景,Domain Model 到底如何设计?
写在前面 除了博文内容之外,和 netfocus 兄的讨论,也可以让你学到很多(至少我是这样),不要错过哦. 阅读目录: 迷雾森林 找回自我 开源地址 后记 毫无疑问,领域驱动设计的核心是领域模型,领 ...
- [NodeJS] 优缺点及适用场景讨论
概述: NodeJS宣称其目标是“旨在提供一种简单的构建可伸缩网络程序的方法”,那么它的出现是为了解决什么问题呢,它有什么优缺点以及它适用于什么场景呢? 本文就个人使用经验对这些问题进行探讨. 一. ...
随机推荐
- alert样式修改
HTML: <div id="div">1223325</div> CSS: .btn_alert button{font-size: 1em;border ...
- oracle 参考
create or replace function fun_try(v_name varchar,v_outname out varchar)return varchar2 is Result va ...
- Xcode使用HTTP配置
Xcode7 出现获取网络请求时出现如下异常: App Transport Security has blocked a cleartext HTTP (http://) resource load ...
- Go语言的GOPATH与工作目录详解
这篇文章主要介绍了Go语言的GOPATH与工作目录详解,本文详细讲解了GOPATH设置.应用目录结构.编译应用等内容,需要的朋友可以参考下 GOPATH设置 go 命令依赖一个重要的环境变量:$GOP ...
- CSS元素居中的常用方法
只有普通流和绝对定位的元素可以设置居中,浮动元素是不存在居中的. 1.块级元素居中 1) 普通流元素(position : static 或 position : relative) 水平居中:{ m ...
- php面试题
1.用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) <?php date_default_timezone_set('Asia/shanghai'); echo d ...
- C#类继承和接口继承时一些模棱两可的问题[转]
原文地址:http://www.cnblogs.com/harleyhu/archive/2012/11/29/2794809.html 1.在father定义的方法若含有virtual关键字,chi ...
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 错误解决
今天在做LNMP的时候,启动nginx服务,无法开启,导致网页打不开.把服务从起一下发现提示错误如下: Starting nginx: nginx: [emerg] bind() to 0.0.0.0 ...
- CURL in windows
目前版本为: 7.50.3 >> 不同操作系统及版本的下载页面 https://curl.haxx.se/download/?C=M;O=D Windows上的下载入口及地址为: htt ...
- PRML读书笔记——3 Linear Models for Regression
Linear Basis Function Models 线性模型的一个关键属性是它是参数的一个线性函数,形式如下: w是参数,x可以是原始的数据,也可以是关于原始数据的一个函数值,这个函数就叫bas ...