common.c 5.0 KB

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