Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * linux/arch/arm/mach-at91/at91sam926x_time.c
  3  *
  4  * Copyright (C) 2005-2006 M. Amine SAYA, ATMEL Rousset, France
  5  * Revision      2005 M. Nicolas Diremdjian, ATMEL Rousset, France
  6  *
  7  * This program is free software; you can redistribute it and/or modify
  8  * it under the terms of the GNU General Public License version 2 as
  9  * published by the Free Software Foundation.
 10  */
 11 
 12 #include <linux/init.h>
 13 #include <linux/interrupt.h>
 14 #include <linux/irq.h>
 15 #include <linux/kernel.h>
 16 #include <linux/sched.h>
 17 #include <linux/time.h>
 18 
 19 #include <asm/hardware.h>
 20 #include <asm/io.h>
 21 #include <asm/mach/time.h>
 22 
 23 #include <asm/arch/at91_pit.h>
 24 
 25 
 26 #define PIT_CPIV(x)     ((x) & AT91_PIT_CPIV)
 27 #define PIT_PICNT(x)    (((x) & AT91_PIT_PICNT) >> 20)
 28 
 29 /*
 30  * Returns number of microseconds since last timer interrupt.  Note that interrupts
 31  * will have been disabled by do_gettimeofday()
 32  *  'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
 33  */
 34 static unsigned long at91sam926x_gettimeoffset(void)
 35 {
 36         unsigned long elapsed;
 37         unsigned long t = at91_sys_read(AT91_PIT_PIIR);
 38 
 39         elapsed = (PIT_PICNT(t) * LATCH) + PIT_CPIV(t);         /* hardware clock cycles */
 40 
 41         return (unsigned long)(elapsed * jiffies_to_usecs(1)) / LATCH;
 42 }
 43 
 44 /*
 45  * IRQ handler for the timer.
 46  */
 47 static irqreturn_t at91sam926x_timer_interrupt(int irq, void *dev_id)
 48 {
 49         volatile long nr_ticks;
 50 
 51         if (at91_sys_read(AT91_PIT_SR) & AT91_PIT_PITS) {       /* This is a shared interrupt */
 52                 /* Get number to ticks performed before interrupt and clear PIT interrupt */
 53                 nr_ticks = PIT_PICNT(at91_sys_read(AT91_PIT_PIVR));
 54                 do {
 55                         timer_tick();
 56                         nr_ticks--;
 57                 } while (nr_ticks);
 58 
 59                 return IRQ_HANDLED;
 60         } else
 61                 return IRQ_NONE;                /* not handled */
 62 }
 63 
 64 static struct irqaction at91sam926x_timer_irq = {
 65         .name           = "at91_tick",
 66         .flags          = IRQF_SHARED | IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
 67         .handler        = at91sam926x_timer_interrupt
 68 };
 69 
 70 void at91sam926x_timer_reset(void)
 71 {
 72         /* Disable timer */
 73         at91_sys_write(AT91_PIT_MR, 0);
 74 
 75         /* Clear any pending interrupts */
 76         (void) at91_sys_read(AT91_PIT_PIVR);
 77 
 78         /* Set Period Interval timer and enable its interrupt */
 79         at91_sys_write(AT91_PIT_MR, (LATCH & AT91_PIT_PIV) | AT91_PIT_PITIEN | AT91_PIT_PITEN);
 80 }
 81 
 82 /*
 83  * Set up timer interrupt.
 84  */
 85 void __init at91sam926x_timer_init(void)
 86 {
 87         /* Initialize and enable the timer */
 88         at91sam926x_timer_reset();
 89 
 90         /* Make IRQs happen for the system timer. */
 91         setup_irq(AT91_ID_SYS, &at91sam926x_timer_irq);
 92 }
 93 
 94 #ifdef CONFIG_PM
 95 static void at91sam926x_timer_suspend(void)
 96 {
 97         /* Disable timer */
 98         at91_sys_write(AT91_PIT_MR, 0);
 99 }
100 #else
101 #define at91sam926x_timer_suspend       NULL
102 #endif
103 
104 struct sys_timer at91sam926x_timer = {
105         .init           = at91sam926x_timer_init,
106         .offset         = at91sam926x_gettimeoffset,
107         .suspend        = at91sam926x_timer_suspend,
108         .resume         = at91sam926x_timer_reset,
109 };
110 
111 
  This page was automatically generated by the LXR engine.