1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/fs.h> #include <linux/cdev.h> #include <linux/device.h> #include <asm/io.h> #include <linux/platform_device.h> #include <linux/interrupt.h>
struct timer_list key2_timer; struct timer_list key3_timer;
extern int fs4412_led_on(int ledno); extern int fs4412_led_off(int ledno);
void k2_timer_fn(unsigned long data) { printk("k2_time_fn\n"); fs4412_led_on(2); fs4412_led_on(3); fs4412_led_off(4); fs4412_led_off(5); }
irqreturn_t key2_fn(int irqno,void *data) { printk("key2 is pressed %d \n",irqno); printk("hello i am key2\n"); mod_timer(&key2_timer, jiffies+500); return IRQ_HANDLED; }
void k3_timer_fn(unsigned long data) { printk("k3_time_fn\n"); printk("\n\n\n\n"); fs4412_led_on(4); fs4412_led_on(5); fs4412_led_off(2); fs4412_led_off(3); }
irqreturn_t key3_fn(int irqno,void *data) { printk("key3 is pressed %d \n",irqno); printk("hello i am key3\n"); mod_timer(&key3_timer, jiffies+500); return IRQ_HANDLED; }
int fs4412_key_probe(struct platform_device *pdev) { int i = 0; for(;i < pdev->num_resources; i++) {
printk("%p\n",pdev->resource[i].start); printk("%p\n",pdev->resource[i].end); printk("%p\n",pdev->resource[i].flags); } request_irq(pdev->resource[0].start,key2_fn,pdev->resource[0].flags,"key2",NULL);
request_irq(pdev->resource[1].start,key3_fn,pdev->resource[1].flags,"key3",NULL);
key2_timer.function = k2_timer_fn; init_timer(&key2_timer); key3_timer.function = k3_timer_fn; init_timer(&key3_timer);
return 0; }
int fs4412_key_remove(struct platform_device *pdev) { printk("fs4412_key_remove\n"); free_irq(pdev->resource[0].start,NULL); free_irq(pdev->resource[1].start,NULL); return 0; }
int fs4412_key_suspend(struct platform_device *pdev,pm_message_t state) { printk("fs4412_key_suspened\n"); return 0; } int fs4412_key_resume(struct platform_device *pdev) { printk("fs4412_key_resume\n"); return 0; }
struct of_device_id key_tbl[] = { { .compatible = "fs4412,key",}, };
struct platform_driver pdrv = { .probe = fs4412_key_probe, .remove = fs4412_key_remove, .suspend = fs4412_key_suspend, .resume = fs4412_key_resume, .driver.name = "fs4412-key", .driver.of_match_table = key_tbl, };
static int __init fs4412_key_driver_init(void) { printk("fs4412_key_driver_init\n"); platform_driver_register(&pdrv); return 0; }
static void __exit fs4412_key_driver_exit(void) { printk("fs4412_key_driver_exit\n"); platform_driver_unregister(&pdrv);
}
MODULE_LICENSE("GPL"); module_init(fs4412_key_driver_init); module_exit(fs4412_key_driver_exit);
|