common.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 <linux/timex.h>
  30. #include <asm/sizes.h>
  31. #include <mach/hardware.h>
  32. #include <asm/irq.h>
  33. #include <asm/leds.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/page.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/time.h>
  38. #include <asm/hardware/clps7111.h>
  39. #include <asm/system_misc.h>
  40. /*
  41. * This maps the generic CLPS711x registers
  42. */
  43. static struct map_desc clps711x_io_desc[] __initdata = {
  44. {
  45. .virtual = CLPS7111_VIRT_BASE,
  46. .pfn = __phys_to_pfn(CLPS7111_PHYS_BASE),
  47. .length = SZ_1M,
  48. .type = MT_DEVICE
  49. }
  50. };
  51. void __init clps711x_map_io(void)
  52. {
  53. iotable_init(clps711x_io_desc, ARRAY_SIZE(clps711x_io_desc));
  54. }
  55. static void int1_mask(struct irq_data *d)
  56. {
  57. u32 intmr1;
  58. intmr1 = clps_readl(INTMR1);
  59. intmr1 &= ~(1 << d->irq);
  60. clps_writel(intmr1, INTMR1);
  61. }
  62. static void int1_ack(struct irq_data *d)
  63. {
  64. u32 intmr1;
  65. intmr1 = clps_readl(INTMR1);
  66. intmr1 &= ~(1 << d->irq);
  67. clps_writel(intmr1, INTMR1);
  68. switch (d->irq) {
  69. case IRQ_CSINT: clps_writel(0, COEOI); break;
  70. case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
  71. case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
  72. case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
  73. case IRQ_TINT: clps_writel(0, TEOI); break;
  74. case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
  75. }
  76. }
  77. static void int1_unmask(struct irq_data *d)
  78. {
  79. u32 intmr1;
  80. intmr1 = clps_readl(INTMR1);
  81. intmr1 |= 1 << d->irq;
  82. clps_writel(intmr1, INTMR1);
  83. }
  84. static struct irq_chip int1_chip = {
  85. .irq_ack = int1_ack,
  86. .irq_mask = int1_mask,
  87. .irq_unmask = int1_unmask,
  88. };
  89. static void int2_mask(struct irq_data *d)
  90. {
  91. u32 intmr2;
  92. intmr2 = clps_readl(INTMR2);
  93. intmr2 &= ~(1 << (d->irq - 16));
  94. clps_writel(intmr2, INTMR2);
  95. }
  96. static void int2_ack(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. switch (d->irq) {
  103. case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
  104. }
  105. }
  106. static void int2_unmask(struct irq_data *d)
  107. {
  108. u32 intmr2;
  109. intmr2 = clps_readl(INTMR2);
  110. intmr2 |= 1 << (d->irq - 16);
  111. clps_writel(intmr2, INTMR2);
  112. }
  113. static struct irq_chip int2_chip = {
  114. .irq_ack = int2_ack,
  115. .irq_mask = int2_mask,
  116. .irq_unmask = int2_unmask,
  117. };
  118. void __init clps711x_init_irq(void)
  119. {
  120. unsigned int i;
  121. for (i = 0; i < NR_IRQS; i++) {
  122. if (INT1_IRQS & (1 << i)) {
  123. irq_set_chip_and_handler(i, &int1_chip,
  124. handle_level_irq);
  125. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  126. }
  127. if (INT2_IRQS & (1 << i)) {
  128. irq_set_chip_and_handler(i, &int2_chip,
  129. handle_level_irq);
  130. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  131. }
  132. }
  133. /*
  134. * Disable interrupts
  135. */
  136. clps_writel(0, INTMR1);
  137. clps_writel(0, INTMR2);
  138. /*
  139. * Clear down any pending interrupts
  140. */
  141. clps_writel(0, COEOI);
  142. clps_writel(0, TC1EOI);
  143. clps_writel(0, TC2EOI);
  144. clps_writel(0, RTCEOI);
  145. clps_writel(0, TEOI);
  146. clps_writel(0, UMSEOI);
  147. clps_writel(0, SYNCIO);
  148. clps_writel(0, KBDEOI);
  149. }
  150. /*
  151. * gettimeoffset() returns time since last timer tick, in usecs.
  152. *
  153. * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
  154. * 'tick' is usecs per jiffy.
  155. */
  156. static unsigned long clps711x_gettimeoffset(void)
  157. {
  158. unsigned long hwticks;
  159. hwticks = LATCH - (clps_readl(TC2D) & 0xffff); /* since last underflow */
  160. return (hwticks * (tick_nsec / 1000)) / LATCH;
  161. }
  162. /*
  163. * IRQ handler for the timer
  164. */
  165. static irqreturn_t p720t_timer_interrupt(int irq, void *dev_id)
  166. {
  167. timer_tick();
  168. return IRQ_HANDLED;
  169. }
  170. static struct irqaction clps711x_timer_irq = {
  171. .name = "CLPS711x Timer Tick",
  172. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  173. .handler = p720t_timer_interrupt,
  174. };
  175. static void __init clps711x_timer_init(void)
  176. {
  177. struct timespec tv;
  178. unsigned int syscon;
  179. syscon = clps_readl(SYSCON1);
  180. syscon |= SYSCON1_TC2S | SYSCON1_TC2M;
  181. clps_writel(syscon, SYSCON1);
  182. clps_writel(LATCH-1, TC2D); /* 512kHz / 100Hz - 1 */
  183. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  184. tv.tv_nsec = 0;
  185. tv.tv_sec = clps_readl(RTCDR);
  186. do_settimeofday(&tv);
  187. }
  188. struct sys_timer clps711x_timer = {
  189. .init = clps711x_timer_init,
  190. .offset = clps711x_gettimeoffset,
  191. };
  192. void clps711x_restart(char mode, const char *cmd)
  193. {
  194. soft_restart(0);
  195. }
  196. static void clps711x_idle(void)
  197. {
  198. clps_writel(1, HALT);
  199. __asm__ __volatile__(
  200. "mov r0, r0\n\
  201. mov r0, r0");
  202. }
  203. static int __init clps711x_idle_init(void)
  204. {
  205. arm_pm_idle = clps711x_idle;
  206. return 0;
  207. }
  208. arch_initcall(clps711x_idle_init);