common.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * linux/arch/arm/mach-clps711x/core.c
  3. *
  4. * Core support for the CLPS711x-based machines.
  5. *
  6. * Copyright (C) 2001,2011 Deep Blue Solutions Ltd
  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 as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/mm.h>
  24. #include <linux/init.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/io.h>
  27. #include <linux/irq.h>
  28. #include <linux/sched.h>
  29. #include <asm/sizes.h>
  30. #include <mach/hardware.h>
  31. #include <asm/irq.h>
  32. #include <asm/leds.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/page.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/time.h>
  37. #include <asm/system_misc.h>
  38. /*
  39. * This maps the generic CLPS711x registers
  40. */
  41. static struct map_desc clps711x_io_desc[] __initdata = {
  42. {
  43. .virtual = (unsigned long)CLPS711X_VIRT_BASE,
  44. .pfn = __phys_to_pfn(CLPS711X_PHYS_BASE),
  45. .length = SZ_1M,
  46. .type = MT_DEVICE
  47. }
  48. };
  49. void __init clps711x_map_io(void)
  50. {
  51. iotable_init(clps711x_io_desc, ARRAY_SIZE(clps711x_io_desc));
  52. }
  53. static void int1_mask(struct irq_data *d)
  54. {
  55. u32 intmr1;
  56. intmr1 = clps_readl(INTMR1);
  57. intmr1 &= ~(1 << d->irq);
  58. clps_writel(intmr1, INTMR1);
  59. }
  60. static void int1_ack(struct irq_data *d)
  61. {
  62. switch (d->irq) {
  63. case IRQ_CSINT: clps_writel(0, COEOI); break;
  64. case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
  65. case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
  66. case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
  67. case IRQ_TINT: clps_writel(0, TEOI); break;
  68. case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
  69. }
  70. }
  71. static void int1_unmask(struct irq_data *d)
  72. {
  73. u32 intmr1;
  74. intmr1 = clps_readl(INTMR1);
  75. intmr1 |= 1 << d->irq;
  76. clps_writel(intmr1, INTMR1);
  77. }
  78. static struct irq_chip int1_chip = {
  79. .irq_ack = int1_ack,
  80. .irq_mask = int1_mask,
  81. .irq_unmask = int1_unmask,
  82. };
  83. static void int2_mask(struct irq_data *d)
  84. {
  85. u32 intmr2;
  86. intmr2 = clps_readl(INTMR2);
  87. intmr2 &= ~(1 << (d->irq - 16));
  88. clps_writel(intmr2, INTMR2);
  89. }
  90. static void int2_ack(struct irq_data *d)
  91. {
  92. switch (d->irq) {
  93. case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
  94. }
  95. }
  96. static void int2_unmask(struct irq_data *d)
  97. {
  98. u32 intmr2;
  99. intmr2 = clps_readl(INTMR2);
  100. intmr2 |= 1 << (d->irq - 16);
  101. clps_writel(intmr2, INTMR2);
  102. }
  103. static struct irq_chip int2_chip = {
  104. .irq_ack = int2_ack,
  105. .irq_mask = int2_mask,
  106. .irq_unmask = int2_unmask,
  107. };
  108. void __init clps711x_init_irq(void)
  109. {
  110. unsigned int i;
  111. for (i = 0; i < NR_IRQS; i++) {
  112. if (INT1_IRQS & (1 << i)) {
  113. irq_set_chip_and_handler(i, &int1_chip,
  114. handle_level_irq);
  115. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  116. }
  117. if (INT2_IRQS & (1 << i)) {
  118. irq_set_chip_and_handler(i, &int2_chip,
  119. handle_level_irq);
  120. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  121. }
  122. }
  123. /*
  124. * Disable interrupts
  125. */
  126. clps_writel(0, INTMR1);
  127. clps_writel(0, INTMR2);
  128. /*
  129. * Clear down any pending interrupts
  130. */
  131. clps_writel(0, COEOI);
  132. clps_writel(0, TC1EOI);
  133. clps_writel(0, TC2EOI);
  134. clps_writel(0, RTCEOI);
  135. clps_writel(0, TEOI);
  136. clps_writel(0, UMSEOI);
  137. clps_writel(0, SYNCIO);
  138. clps_writel(0, KBDEOI);
  139. }
  140. /*
  141. * gettimeoffset() returns time since last timer tick, in usecs.
  142. *
  143. * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
  144. * 'tick' is usecs per jiffy.
  145. */
  146. static unsigned long clps711x_gettimeoffset(void)
  147. {
  148. unsigned long hwticks;
  149. hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */
  150. return (hwticks * (tick_nsec / 1000)) / LATCH;
  151. }
  152. /*
  153. * IRQ handler for the timer
  154. */
  155. static irqreturn_t p720t_timer_interrupt(int irq, void *dev_id)
  156. {
  157. timer_tick();
  158. return IRQ_HANDLED;
  159. }
  160. static struct irqaction clps711x_timer_irq = {
  161. .name = "CLPS711x Timer Tick",
  162. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  163. .handler = p720t_timer_interrupt,
  164. };
  165. static void __init clps711x_timer_init(void)
  166. {
  167. unsigned int syscon;
  168. syscon = clps_readl(SYSCON1);
  169. syscon |= SYSCON1_TC2S | SYSCON1_TC2M;
  170. clps_writel(syscon, SYSCON1);
  171. clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */
  172. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  173. }
  174. struct sys_timer clps711x_timer = {
  175. .init = clps711x_timer_init,
  176. .offset = clps711x_gettimeoffset,
  177. };
  178. void clps711x_restart(char mode, const char *cmd)
  179. {
  180. soft_restart(0);
  181. }
  182. static void clps711x_idle(void)
  183. {
  184. clps_writel(1, HALT);
  185. __asm__ __volatile__(
  186. "mov r0, r0\n\
  187. mov r0, r0");
  188. }
  189. static int __init clps711x_idle_init(void)
  190. {
  191. arm_pm_idle = clps711x_idle;
  192. return 0;
  193. }
  194. arch_initcall(clps711x_idle_init);