···11+/*22+ * Simple gptimers example33+ * http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gptimers44+ *55+ * Copyright 2007-2009 Analog Devices Inc.66+ *77+ * Licensed under the GPL-2 or later.88+ */99+1010+#include <linux/interrupt.h>1111+#include <linux/module.h>1212+1313+#include <asm/gptimers.h>1414+#include <asm/portmux.h>1515+1616+/* ... random driver includes ... */1717+1818+#define DRIVER_NAME "gptimer_example"1919+2020+struct gptimer_data {2121+ uint32_t period, width;2222+};2323+static struct gptimer_data data;2424+2525+/* ... random driver state ... */2626+2727+static irqreturn_t gptimer_example_irq(int irq, void *dev_id)2828+{2929+ struct gptimer_data *data = dev_id;3030+3131+ /* make sure it was our timer which caused the interrupt */3232+ if (!get_gptimer_intr(TIMER5_id))3333+ return IRQ_NONE;3434+3535+ /* read the width/period values that were captured for the waveform */3636+ data->width = get_gptimer_pwidth(TIMER5_id);3737+ data->period = get_gptimer_period(TIMER5_id);3838+3939+ /* acknowledge the interrupt */4040+ clear_gptimer_intr(TIMER5_id);4141+4242+ /* tell the upper layers we took care of things */4343+ return IRQ_HANDLED;4444+}4545+4646+/* ... random driver code ... */4747+4848+static int __init gptimer_example_init(void)4949+{5050+ int ret;5151+5252+ /* grab the peripheral pins */5353+ ret = peripheral_request(P_TMR5, DRIVER_NAME);5454+ if (ret) {5555+ printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");5656+ return ret;5757+ }5858+5959+ /* grab the IRQ for the timer */6060+ ret = request_irq(IRQ_TIMER5, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data);6161+ if (ret) {6262+ printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");6363+ peripheral_free(P_TMR5);6464+ return ret;6565+ }6666+6767+ /* setup the timer and enable it */6868+ set_gptimer_config(TIMER5_id, WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA);6969+ enable_gptimers(TIMER5bit);7070+7171+ return 0;7272+}7373+module_init(gptimer_example_init);7474+7575+static void __exit gptimer_example_exit(void)7676+{7777+ disable_gptimers(TIMER5bit);7878+ free_irq(IRQ_TIMER5, &data);7979+ peripheral_free(P_TMR5);8080+}8181+module_exit(gptimer_example_exit);8282+8383+MODULE_LICENSE("BSD");