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
uint32_t period, width;
23
static struct gptimer_data data;
25
/* ... random driver state ... */
27
static irqreturn_t gptimer_example_irq(int irq, void *dev_id)
29
struct gptimer_data *data = dev_id;
31
/* make sure it was our timer which caused the interrupt */
32
if (!get_gptimer_intr(TIMER5_id))
35
/* read the width/period values that were captured for the waveform */
36
data->width = get_gptimer_pwidth(TIMER5_id);
37
data->period = get_gptimer_period(TIMER5_id);
39
/* acknowledge the interrupt */
40
clear_gptimer_intr(TIMER5_id);
42
/* tell the upper layers we took care of things */
46
/* ... random driver code ... */
48
static int __init gptimer_example_init(void)
52
/* grab the peripheral pins */
53
ret = peripheral_request(P_TMR5, DRIVER_NAME);
55
printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");
59
/* grab the IRQ for the timer */
60
ret = request_irq(IRQ_TIMER5, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data);
62
printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");
63
peripheral_free(P_TMR5);
67
/* setup the timer and enable it */
68
set_gptimer_config(TIMER5_id, WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA);
69
enable_gptimers(TIMER5bit);
73
module_init(gptimer_example_init);
75
static void __exit gptimer_example_exit(void)
77
disable_gptimers(TIMER5bit);
78
free_irq(IRQ_TIMER5, &data);
79
peripheral_free(P_TMR5);
81
module_exit(gptimer_example_exit);
83
MODULE_LICENSE("BSD");