thermal: fix Mediatek thermal controller build
[linux/fpc-iii.git] / Documentation / blackfin / gptimers-example.c
blob283eba993d9d62115db668c3fa67ced228a047ac
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 #ifdef IRQ_TIMER5
21 #define SAMPLE_IRQ_TIMER IRQ_TIMER5
22 #else
23 #define SAMPLE_IRQ_TIMER IRQ_TIMER2
24 #endif
26 struct gptimer_data {
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))
39 return IRQ_NONE;
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 */
49 return IRQ_HANDLED;
52 /* ... random driver code ... */
54 static int __init gptimer_example_init(void)
56 int ret;
58 /* grab the peripheral pins */
59 ret = peripheral_request(P_TMR5, DRIVER_NAME);
60 if (ret) {
61 printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");
62 return ret;
65 /* grab the IRQ for the timer */
66 ret = request_irq(SAMPLE_IRQ_TIMER, gptimer_example_irq,
67 IRQF_SHARED, DRIVER_NAME, &data);
68 if (ret) {
69 printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");
70 peripheral_free(P_TMR5);
71 return ret;
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);
79 return 0;
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");