Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gptimers-example.c
Go to the documentation of this file.
1 /*
2  * Simple gptimers example
3  * http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gptimers
4  *
5  * Copyright 2007-2009 Analog Devices Inc.
6  *
7  * Licensed under the GPL-2 or later.
8  */
9 
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
12 
13 #include <asm/gptimers.h>
14 #include <asm/portmux.h>
15 
16 /* ... random driver includes ... */
17 
18 #define DRIVER_NAME "gptimer_example"
19 
20 struct gptimer_data {
22 };
23 static struct gptimer_data data;
24 
25 /* ... random driver state ... */
26 
27 static irqreturn_t gptimer_example_irq(int irq, void *dev_id)
28 {
29  struct gptimer_data *data = dev_id;
30 
31  /* make sure it was our timer which caused the interrupt */
33  return IRQ_NONE;
34 
35  /* read the width/period values that were captured for the waveform */
38 
39  /* acknowledge the interrupt */
41 
42  /* tell the upper layers we took care of things */
43  return IRQ_HANDLED;
44 }
45 
46 /* ... random driver code ... */
47 
48 static int __init gptimer_example_init(void)
49 {
50  int ret;
51 
52  /* grab the peripheral pins */
54  if (ret) {
55  printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");
56  return ret;
57  }
58 
59  /* grab the IRQ for the timer */
60  ret = request_irq(IRQ_TIMER5, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data);
61  if (ret) {
62  printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");
64  return ret;
65  }
66 
67  /* setup the timer and enable it */
70 
71  return 0;
72 }
73 module_init(gptimer_example_init);
74 
75 static void __exit gptimer_example_exit(void)
76 {
78  free_irq(IRQ_TIMER5, &data);
80 }
81 module_exit(gptimer_example_exit);
82 
83 MODULE_LICENSE("BSD");