OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / Documentation / blackfin / gptimers-example.c
blobb1bd6340e748e2a612b0d088fb252e7bffe23d03
1 /*
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.
8 */
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"
20 struct gptimer_data {
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))
33 return IRQ_NONE;
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 */
43 return IRQ_HANDLED;
46 /* ... random driver code ... */
48 static int __init gptimer_example_init(void)
50 int ret;
52 /* grab the peripheral pins */
53 ret = peripheral_request(P_TMR5, DRIVER_NAME);
54 if (ret) {
55 printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");
56 return ret;
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");
63 peripheral_free(P_TMR5);
64 return ret;
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);
71 return 0;
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");