core.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * linux/arch/arm/mach-aaec2000/core.c
  3. *
  4. * Code common to all AAEC-2000 machines
  5. *
  6. * Copyright (c) 2005 Nicolas Bellido Y Ortega
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/list.h>
  17. #include <linux/errno.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/timex.h>
  20. #include <linux/signal.h>
  21. #include <asm/hardware.h>
  22. #include <asm/irq.h>
  23. #include <asm/mach/irq.h>
  24. #include <asm/mach/time.h>
  25. #include <asm/mach/map.h>
  26. /*
  27. * Common I/O mapping:
  28. *
  29. * Static virtual address mappings are as follow:
  30. *
  31. * 0xf8000000-0xf8001ffff: Devices connected to APB bus
  32. * 0xf8002000-0xf8003ffff: Devices connected to AHB bus
  33. *
  34. * Below 0xe8000000 is reserved for vm allocation.
  35. *
  36. * The machine specific code must provide the extra mapping beside the
  37. * default mapping provided here.
  38. */
  39. static struct map_desc standard_io_desc[] __initdata = {
  40. /* virtual physical length type */
  41. { VIO_APB_BASE, PIO_APB_BASE, IO_APB_LENGTH, MT_DEVICE },
  42. { VIO_AHB_BASE, PIO_AHB_BASE, IO_AHB_LENGTH, MT_DEVICE }
  43. };
  44. void __init aaec2000_map_io(void)
  45. {
  46. iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
  47. }
  48. /*
  49. * Interrupt handling routines
  50. */
  51. static void aaec2000_int_ack(unsigned int irq)
  52. {
  53. IRQ_INTSR = 1 << irq;
  54. }
  55. static void aaec2000_int_mask(unsigned int irq)
  56. {
  57. IRQ_INTENC |= (1 << irq);
  58. }
  59. static void aaec2000_int_unmask(unsigned int irq)
  60. {
  61. IRQ_INTENS |= (1 << irq);
  62. }
  63. static struct irqchip aaec2000_irq_chip = {
  64. .ack = aaec2000_int_ack,
  65. .mask = aaec2000_int_mask,
  66. .unmask = aaec2000_int_unmask,
  67. };
  68. void __init aaec2000_init_irq(void)
  69. {
  70. unsigned int i;
  71. for (i = 0; i < NR_IRQS; i++) {
  72. set_irq_handler(i, do_level_IRQ);
  73. set_irq_chip(i, &aaec2000_irq_chip);
  74. set_irq_flags(i, IRQF_VALID);
  75. }
  76. /* Disable all interrupts */
  77. IRQ_INTENC = 0xffffffff;
  78. /* Clear any pending interrupts */
  79. IRQ_INTSR = IRQ_INTSR;
  80. }
  81. /*
  82. * Time keeping
  83. */
  84. /* IRQs are disabled before entering here from do_gettimeofday() */
  85. static unsigned long aaec2000_gettimeoffset(void)
  86. {
  87. unsigned long ticks_to_match, elapsed, usec;
  88. /* Get ticks before next timer match */
  89. ticks_to_match = TIMER1_LOAD - TIMER1_VAL;
  90. /* We need elapsed ticks since last match */
  91. elapsed = LATCH - ticks_to_match;
  92. /* Now, convert them to usec */
  93. usec = (unsigned long)(elapsed * (tick_nsec / 1000))/LATCH;
  94. return usec;
  95. }
  96. /* We enter here with IRQs enabled */
  97. static irqreturn_t
  98. aaec2000_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  99. {
  100. /* TODO: Check timer accuracy */
  101. write_seqlock(&xtime_lock);
  102. timer_tick(regs);
  103. TIMER1_CLEAR = 1;
  104. write_sequnlock(&xtime_lock);
  105. return IRQ_HANDLED;
  106. }
  107. static struct irqaction aaec2000_timer_irq = {
  108. .name = "AAEC-2000 Timer Tick",
  109. .flags = SA_INTERRUPT | SA_TIMER,
  110. .handler = aaec2000_timer_interrupt,
  111. };
  112. static void __init aaec2000_timer_init(void)
  113. {
  114. /* Disable timer 1 */
  115. TIMER1_CTRL = 0;
  116. /* We have somehow to generate a 100Hz clock.
  117. * We then use the 508KHz timer in periodic mode.
  118. */
  119. TIMER1_LOAD = LATCH;
  120. TIMER1_CLEAR = 1; /* Clear interrupt */
  121. setup_irq(INT_TMR1_OFL, &aaec2000_timer_irq);
  122. TIMER1_CTRL = TIMER_CTRL_ENABLE |
  123. TIMER_CTRL_PERIODIC |
  124. TIMER_CTRL_CLKSEL_508K;
  125. }
  126. struct sys_timer aaec2000_timer = {
  127. .init = aaec2000_timer_init,
  128. .offset = aaec2000_gettimeoffset,
  129. };