alloc_chrdev_region(&dev->devno, 0, 1, "fpga_key_to_app");
cdev_init(&dev->cdev, &meassage_operatons);
cdev_add(&dev->cdev, dev->devno, 1);
dev->fpga_key_class = class_create(THIS_MODULE, "fpga_key_class");
if(IS_ERR(dev->fpga_key_class)) {
printk("Err: failed in creating class./n");
goto fail1;
}
device_create(dev->fpga_key_class, NULL, dev->devno, NULL, "fpga_key");
//init irq
ret = gpio_request(GPIO_TO_PIN(1, 27), "fpga_key_inter");
if(ret){
printk("gpio_request() failed !\n");
goto fail1;
}
ret = gpio_direction_input(GPIO_TO_PIN(1, 27));
if(ret){
printk("gpio_direction_input() failed !\n");
goto fail2;
}
inter = gpio_to_irq(GPIO_TO_PIN(1, 27));
if(inter < 0){
printk("gpio_to_irq() failed !\n");
ret = inter;
goto fail2;
}
printk("inter = %d", inter);
ret = request_irq(inter,
irq_handler,
IRQF_TRIGGER_FALLING | IRQF_SHARED,
"fpga_key_inter",
&dev->devno);
if(ret){
printk("request_irq() failed ! %d\n", ret);
goto fail2;
}
printk("fpga_key_to_app_init(void)--\n");
return 0;
fail2:
gpio_free(GPIO_TO_PIN(1, 27));
fail1:
device_destroy(dev->fpga_key_class, dev->devno);
class_destroy(dev->fpga_key_class);
cdev_del(&dev->cdev);
unregister_chrdev_region(dev->devno, 1);
return ret;
}
static void __exit fpga_key_exit(void)
{
struct fpga_key_dev *dev = &fpga_key_dev;
printk("fpga_key_to_app_exit(void)++\n");
free_irq(AM33XX_IRQ_GPIO1_1, NULL);
gpio_free(GPIO_TO_PIN(1, 27));
device_destroy(dev->fpga_key_class, dev->devno);
class_destroy(dev->fpga_key_class);
cdev_del(&dev->cdev);
unregister_chrdev_region(dev->devno, 1);
printk("fpga_key_to_app_exit(void)--\n");
}
module_init(fpga_key_init);
module_exit(fpga_key_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Driver Monkey");
MODULE_DESCRIPTION("Test fpga_key to App");