static flag = 1;
static a = 1;
struct tpd_device {
struct device *tpd_dev;
struct regulator *reg;
struct input_dev *dev;
struct input_dev *kpd;
struct timer_list timer;
struct tasklet_struct tasklet;
int btn_state;
};
static int dat;
unsigned int gpio_num ;
struct timer_list timer;
struct class *newmobi_class;
struct device *newmobi_cmd_dev;
static dev_t newmobi_devno;
static struct cdev newmobi_cdev;
extern struct tpd_device *tpd;
struct input_dev *dev;
void timer_func(int data)
{
}
static void Timer_Init(void)
{
init_timer(&timer);
timer.data=10;
timer.expires=jiffies+(5*HZ);
timer.function=timer_func;
add_timer(&timer);
}
static ssize_t Gpio_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t size)
{
unsigned long num;
printk(" gpio_ctrl\n");
strict_strtoul(buf, 0, &num);
gpio_num = (unsigned int)num;
return size;
}
void newmobi_eint_interrupt_handler()
{
//屏蔽中断
mt_eint_mask(2);
mdelay(40);
if(flag == 1)
{
//防止键值抖动
mt_eint_set_polarity(GPIO2,MT_EINT_POL_POS);
//上报KEY_F1键值(按下键值)
input_report_key(dev, KEY_F1, 1);
//上报键值结束
input_sync(dev);
}
// mdelay(20);
if(flag == 0)
{
mt_eint_set_polarity(GPIO2,MT_EINT_POL_NEG);
//上报键值(松开键值)
input_report_key(dev, KEY_F1, 0);
//上报键值结束
input_sync(dev);
}
mdelay(20);
flag = flag ^ a;
//解锁屏蔽中断
mt_eint_unmask(2);
}
static ssize_t Gpio_inout_show(struct device *dev,struct device_attribute *attr, char *buf)
{
mt_set_gpio_mode(gpio_num,0);
mt_set_gpio_dir(gpio_num,GPIO_DIR_IN);
dat = mt_get_gpio_in(gpio_num);
return sprintf(buf, "%d\n", dat);
}
static ssize_t Gpio_inout_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t size)
{
unsigned long num;
mt_set_gpio_mode(gpio_num,0);
mt_set_gpio_dir(gpio_num,GPIO_DIR_OUT);
strict_strtoul(buf, 0, &num);
if(num == 0)
mt_set_gpio_out(gpio_num,0);
else
mt_set_gpio_out(gpio_num,1);
return size;
}
void input_dev_init(struct input_dev *dev)
{
//按键事件
__set_bit(EV_SYN, dev->evbit);
__set_bit(EV_KEY, dev->evbit);
//按键类型
__set_bit(KEY_F1, dev->keybit);
}
static void Gpio_Init(void)
{
printk("init\n");
//模式设置
mt_set_gpio_mode(GPIO2, 0);
//状态
mt_set_gpio_dir(GPIO2, GPIO_DIR_IN);
mt_set_gpio_pull_enable(GPIO2, GPIO_PULL_ENABLE);
//上下拉
mt_set_gpio_pull_select(GPIO2, GPIO_PULL_UP);
//中断引脚
mt_set_gpio_mode(GPIO121, 0);
mt_set_gpio_dir(GPIO121, GPIO_DIR_OUT);
mt_set_gpio_out(GPIO121, GPIO_OUT_ONE);
mt_set_gpio_mode(GPIO122, 0);
mt_set_gpio_dir(GPIO122, GPIO_DIR_OUT);
mt_set_gpio_out(GPIO122, GPIO_OUT_ONE);
mt_eint_mask(2);
//调用函数进入中断,上升沿有效
mt_eint_registration(2, IRQF_TRIGGER_FALLING, newmobi_eint_interrupt_handler, 1); //CUST_EINTF_TRIGGER_RISING//CUST_EINTF_TRIGGER_FALLING //IRQF_TRIGGER_HIGH
mt_eint_unmask(2);
}
static ssize_t Test_store(struct device *dev,struct device_attribute *attr, const char *buf, size_t size)
{
unsigned long num;
strict_strtoul(buf, 0, &num);
return size;
}
static ssize_t Test_show(struct device *dev,struct device_attribute *attr, char *buf)
{
int dat;
dat = 1;
dat = mt_get_gpio_in(GPIO2);
return sprintf(buf, "%d\n", dat);
}
static DEVICE_ATTR(Test, 0777, Test_show , Test_store);
static DEVICE_ATTR(Gpio_inout, 0777, Gpio_inout_show , Gpio_inout_store);
static DEVICE_ATTR(Gpio, 0777, NULL , Gpio_store);
static struct file_operations newmobi_fops = {
.owner = THIS_MODULE
};
static int newmobi_probe(struct platform_device *pdev)
{
Gpio_Init();
alloc_chrdev_region(&newmobi_devno, 0, 1, "gpio_new");
cdev_add(&newmobi_cdev, newmobi_devno, 1);
cdev_init(&newmobi_cdev, &newmobi_fops);
newmobi_cdev.owner = THIS_MODULE;
newmobi_class = class_create(THIS_MODULE, "gpio_new");
newmobi_cmd_dev = device_create(newmobi_class,NULL, 0, NULL, "gpio_new");
device_create_file(newmobi_cmd_dev, &dev_attr_Test);
device_create_file(newmobi_cmd_dev , &dev_attr_Gpio_inout);
device_create_file(newmobi_cmd_dev , &dev_attr_Gpio);
dev = input_allocate_device();
input_dev_init(dev);
input_register_device(dev);
return 0;
}
static struct platform_driver newmobi_Driver = {
.probe = newmobi_probe,
.driver =
{
.name = "gpio_new",
.owner = THIS_MODULE,
}
};
static struct platform_device newmobi_Device = {
.name = "gpio_new",
.id = 0,
.dev = {}
};
static int newmobi_init(void)
{
platform_driver_register(&newmobi_Driver);
platform_device_register(&newmobi_Device);
return 0;
}
static void newmobi_exit(void)
{
cdev_del(&newmobi_cdev);
platform_driver_unregister(&newmobi_Driver);
platform_device_unregister(&newmobi_Device);
device_remove_file(newmobi_cmd_dev, &dev_attr_Test);
device_destroy(newmobi_class , newmobi_devno);
class_destroy(newmobi_class);
input_unregister_device(dev);
input_free_device(dev);
}
MODULE_LICENSE("Dual BSD/GPL");
module_init( newmobi_init );
module_exit( newmobi_exit );