/*
* drivers/leds/leds-mt65xx.c
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*
* Hydrodent weiqifa modify add
*
*/
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/input.h>
#include <mach/upmu_hw.h>
#include <mach/mt_boot.h>
#include <mach/mt_gpio.h>
#include <mach/eint.h>
#include <cust_eint.h>
#include "cust_gpio_usage.h"
extern void mt_eint_unmask(unsigned int eint_num);
extern void mt_eint_set_polarity(unsigned int eint_num, unsigned int pol);
extern void mt_eint_set_hw_debounce(unsigned int eintno, unsigned int ms);
extern unsigned int mt_eint_set_sens(unsigned int eintno, unsigned int sens);
extern void mt_eint_registration(unsigned int eint_num, unsigned int flag, void (EINT_FUNC_PTR) (void), unsigned int is_auto_umask);
struct input_dev *hdy_input_dev;
//中断服务函数
void hal_eint_interrupt_handler(void)
{
printk("===%s=== mhall_pin value=%d\n",__FUNCTION__,mt_get_gpio_in(GPIO_MHALL_EINT_PIN));
/*设置中断触发方式,打开摄像头后产生了一次中断,然后改变中断触发方式,关闭摄像头后又会产生一次关闭摄像头的中断*/
if(mt_get_gpio_in(GPIO_MHALL_EINT_PIN))
{
mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_NEG);//中断触发方式设置成下降沿
//mt_eint_unmask(CUST_EINT_MHALL_NUM);
if(test_bit(KEY_N, hdy_input_dev->keybit)){
input_report_key(hdy_input_dev, KEY_N, 0);
input_sync(hdy_input_dev);
printk("===%s================ report key_n 0\n",__FUNCTION__);
}else{
printk("[AUTOTEST] Not Support KEY_N KEY!!\n");
}
}
else
{
mt_eint_set_polarity(CUST_EINT_MHALL_NUM, MT_EINT_POL_POS);//中断触发方式设置成上升沿
if(test_bit(KEY_N, hdy_input_dev->keybit)){
input_report_key(hdy_input_dev, KEY_N, 1);
input_sync(hdy_input_dev);
printk("===%s================ report key_n 1\n",__FUNCTION__);
}else{
printk("[AUTOTEST] Not Support KEY_N KEY!!\n");
}
}
mt_eint_unmask(CUST_EINT_MHALL_NUM);
}
static int __init hdyrodent_hall_init(void)
{
int err = -1;
int r=0;
printk("%s mhall_pin value=%d start\n",__FUNCTION__,mt_get_gpio_in(GPIO_MHALL_EINT_PIN));
/* initialize and register input device (/dev/input/eventX) */
hdy_input_dev = input_allocate_device();
if(!hdy_input_dev)
return -ENOMEM;
hdy_input_dev->name = "hdyrodent-hall";
//下面这两句很关键,如果设置不正确,很容易造成按键上报不成功
hdy_input_dev->evbit[0] = BIT_MASK(EV_KEY);/*设置按键信息*/
hdy_input_dev->keybit[BIT_WORD(KEY_N)] = BIT_MASK(KEY_N);
r = input_register_device(hdy_input_dev);
if (r) {
printk("Error:register input device failed (%d)\n", r);
input_free_device(hdy_input_dev);
return r;
}
//Init the irq gpio1_interrupt
mt_set_gpio_mode(GPIO_MHALL_EINT_PIN, GPIO_MHALL_EINT_PIN_M_EINT);
mt_set_gpio_dir(GPIO_MHALL_EINT_PIN, GPIO_DIR_IN);
mt_set_gpio_pull_enable(GPIO_MHALL_EINT_PIN, GPIO_PULL_ENABLE);
mt_set_gpio_pull_select(GPIO_MHALL_EINT_PIN, GPIO_PULL_UP);
msleep(50);
/*
mt_eint_set_hw_debounce
设置抖动
mt_eint_registration
第一个是中断号,触发极性,第二个是设定是否开启抖动,第三个是绑定中断函数,第四个关闭中断
mt_eint_unmask
屏蔽中断
*/
mt_eint_set_hw_debounce(CUST_EINT_MHALL_NUM, CUST_EINT_MHALL_DEBOUNCE_CN);
mt_eint_registration(CUST_EINT_MHALL_NUM, CUST_EINT_MHALL_TYPE, hal_eint_interrupt_handler, 0);
mt_eint_unmask(CUST_EINT_MHALL_NUM);
printk("%s end\n", __FUNCTION__);
return 0;
}
static void __exit hdyrodent_hall_exit(void)
{
input_free_device(hdy_input_dev);
input_unregister_device(hdy_input_dev);
printk("hdyrodent module cleanup OK!\n");
}
MODULE_AUTHOR("329410527@qq.com");
MODULE_DESCRIPTION("HDYRODENT HALL MODULE");
MODULE_LICENSE("GPL");
MODULE_VERSION("ver0.1");
module_init(hdyrodent_hall_init);
module_exit(hdyrodent_hall_exit);