2 * Simple gptimers example
3 * http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gptimers
5 * Copyright 2007-2009 Analog Devices Inc.
7 * Licensed under the GPL-2 or later.
10 #include <linux/interrupt.h>
11 #include <linux/module.h>
13 #include <asm/gptimers.h>
14 #include <asm/portmux.h>
16 /* ... random driver includes ... */
18 #define DRIVER_NAME "gptimer_example"
21 #define SAMPLE_IRQ_TIMER IRQ_TIMER5
23 #define SAMPLE_IRQ_TIMER IRQ_TIMER2
27 uint32_t period, width;
29 static struct gptimer_data data;
31 /* ... random driver state ... */
33 static irqreturn_t gptimer_example_irq(int irq, void *dev_id)
35 struct gptimer_data *data = dev_id;
37 /* make sure it was our timer which caused the interrupt */
38 if (!get_gptimer_intr(TIMER5_id))
41 /* read the width/period values that were captured for the waveform */
42 data->width = get_gptimer_pwidth(TIMER5_id);
43 data->period = get_gptimer_period(TIMER5_id);
45 /* acknowledge the interrupt */
46 clear_gptimer_intr(TIMER5_id);
48 /* tell the upper layers we took care of things */
52 /* ... random driver code ... */
54 static int __init gptimer_example_init(void)
58 /* grab the peripheral pins */
59 ret = peripheral_request(P_TMR5, DRIVER_NAME);
61 printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");
65 /* grab the IRQ for the timer */
66 ret = request_irq(SAMPLE_IRQ_TIMER, gptimer_example_irq,
67 IRQF_SHARED, DRIVER_NAME, &data);
69 printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");
70 peripheral_free(P_TMR5);
74 /* setup the timer and enable it */
75 set_gptimer_config(TIMER5_id,
76 WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA);
77 enable_gptimers(TIMER5bit);
81 module_init(gptimer_example_init);
83 static void __exit gptimer_example_exit(void)
85 disable_gptimers(TIMER5bit);
86 free_irq(SAMPLE_IRQ_TIMER, &data);
87 peripheral_free(P_TMR5);
89 module_exit(gptimer_example_exit);
91 MODULE_LICENSE("BSD");