Path: blob/master/Documentation/blackfin/gptimers-example.c
10821 views
/*1* Simple gptimers example2* http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:gptimers3*4* Copyright 2007-2009 Analog Devices Inc.5*6* Licensed under the GPL-2 or later.7*/89#include <linux/interrupt.h>10#include <linux/module.h>1112#include <asm/gptimers.h>13#include <asm/portmux.h>1415/* ... random driver includes ... */1617#define DRIVER_NAME "gptimer_example"1819struct gptimer_data {20uint32_t period, width;21};22static struct gptimer_data data;2324/* ... random driver state ... */2526static irqreturn_t gptimer_example_irq(int irq, void *dev_id)27{28struct gptimer_data *data = dev_id;2930/* make sure it was our timer which caused the interrupt */31if (!get_gptimer_intr(TIMER5_id))32return IRQ_NONE;3334/* read the width/period values that were captured for the waveform */35data->width = get_gptimer_pwidth(TIMER5_id);36data->period = get_gptimer_period(TIMER5_id);3738/* acknowledge the interrupt */39clear_gptimer_intr(TIMER5_id);4041/* tell the upper layers we took care of things */42return IRQ_HANDLED;43}4445/* ... random driver code ... */4647static int __init gptimer_example_init(void)48{49int ret;5051/* grab the peripheral pins */52ret = peripheral_request(P_TMR5, DRIVER_NAME);53if (ret) {54printk(KERN_NOTICE DRIVER_NAME ": peripheral request failed\n");55return ret;56}5758/* grab the IRQ for the timer */59ret = request_irq(IRQ_TIMER5, gptimer_example_irq, IRQF_SHARED, DRIVER_NAME, &data);60if (ret) {61printk(KERN_NOTICE DRIVER_NAME ": IRQ request failed\n");62peripheral_free(P_TMR5);63return ret;64}6566/* setup the timer and enable it */67set_gptimer_config(TIMER5_id, WDTH_CAP | PULSE_HI | PERIOD_CNT | IRQ_ENA);68enable_gptimers(TIMER5bit);6970return 0;71}72module_init(gptimer_example_init);7374static void __exit gptimer_example_exit(void)75{76disable_gptimers(TIMER5bit);77free_irq(IRQ_TIMER5, &data);78peripheral_free(P_TMR5);79}80module_exit(gptimer_example_exit);8182MODULE_LICENSE("BSD");838485