common.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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/io.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/clk.h>
  27. #include <linux/clkdev.h>
  28. #include <linux/clk-provider.h>
  29. #include <asm/sizes.h>
  30. #include <asm/mach/map.h>
  31. #include <asm/mach/time.h>
  32. #include <asm/system_misc.h>
  33. #include <mach/hardware.h>
  34. static struct clk *clk_pll, *clk_bus, *clk_uart, *clk_timerl, *clk_timerh,
  35. *clk_tint, *clk_spi;
  36. static unsigned long latch;
  37. /*
  38. * This maps the generic CLPS711x registers
  39. */
  40. static struct map_desc clps711x_io_desc[] __initdata = {
  41. {
  42. .virtual = (unsigned long)CLPS711X_VIRT_BASE,
  43. .pfn = __phys_to_pfn(CLPS711X_PHYS_BASE),
  44. .length = SZ_1M,
  45. .type = MT_DEVICE
  46. }
  47. };
  48. void __init clps711x_map_io(void)
  49. {
  50. iotable_init(clps711x_io_desc, ARRAY_SIZE(clps711x_io_desc));
  51. }
  52. static void int1_mask(struct irq_data *d)
  53. {
  54. u32 intmr1;
  55. intmr1 = clps_readl(INTMR1);
  56. intmr1 &= ~(1 << d->irq);
  57. clps_writel(intmr1, INTMR1);
  58. }
  59. static void int1_ack(struct irq_data *d)
  60. {
  61. switch (d->irq) {
  62. case IRQ_CSINT: clps_writel(0, COEOI); break;
  63. case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
  64. case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
  65. case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
  66. case IRQ_TINT: clps_writel(0, TEOI); break;
  67. case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
  68. }
  69. }
  70. static void int1_unmask(struct irq_data *d)
  71. {
  72. u32 intmr1;
  73. intmr1 = clps_readl(INTMR1);
  74. intmr1 |= 1 << d->irq;
  75. clps_writel(intmr1, INTMR1);
  76. }
  77. static struct irq_chip int1_chip = {
  78. .irq_ack = int1_ack,
  79. .irq_mask = int1_mask,
  80. .irq_unmask = int1_unmask,
  81. };
  82. static void int2_mask(struct irq_data *d)
  83. {
  84. u32 intmr2;
  85. intmr2 = clps_readl(INTMR2);
  86. intmr2 &= ~(1 << (d->irq - 16));
  87. clps_writel(intmr2, INTMR2);
  88. }
  89. static void int2_ack(struct irq_data *d)
  90. {
  91. switch (d->irq) {
  92. case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
  93. }
  94. }
  95. static void int2_unmask(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. }
  102. static struct irq_chip int2_chip = {
  103. .irq_ack = int2_ack,
  104. .irq_mask = int2_mask,
  105. .irq_unmask = int2_unmask,
  106. };
  107. void __init clps711x_init_irq(void)
  108. {
  109. unsigned int i;
  110. for (i = 0; i < NR_IRQS; i++) {
  111. if (INT1_IRQS & (1 << i)) {
  112. irq_set_chip_and_handler(i, &int1_chip,
  113. handle_level_irq);
  114. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  115. }
  116. if (INT2_IRQS & (1 << i)) {
  117. irq_set_chip_and_handler(i, &int2_chip,
  118. handle_level_irq);
  119. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  120. }
  121. }
  122. /*
  123. * Disable interrupts
  124. */
  125. clps_writel(0, INTMR1);
  126. clps_writel(0, INTMR2);
  127. /*
  128. * Clear down any pending interrupts
  129. */
  130. clps_writel(0, COEOI);
  131. clps_writel(0, TC1EOI);
  132. clps_writel(0, TC2EOI);
  133. clps_writel(0, RTCEOI);
  134. clps_writel(0, TEOI);
  135. clps_writel(0, UMSEOI);
  136. clps_writel(0, SYNCIO);
  137. clps_writel(0, KBDEOI);
  138. }
  139. /*
  140. * gettimeoffset() returns time since last timer tick, in usecs.
  141. *
  142. * 'LATCH' is hwclock ticks (see CLOCK_TICK_RATE in timex.h) per jiffy.
  143. * 'tick' is usecs per jiffy.
  144. */
  145. static unsigned long clps711x_gettimeoffset(void)
  146. {
  147. unsigned long hwticks;
  148. hwticks = latch - (clps_readl(TC2D) & 0xffff);
  149. return (hwticks * (tick_nsec / 1000)) / latch;
  150. }
  151. /*
  152. * IRQ handler for the timer
  153. */
  154. static irqreturn_t p720t_timer_interrupt(int irq, void *dev_id)
  155. {
  156. timer_tick();
  157. return IRQ_HANDLED;
  158. }
  159. static struct irqaction clps711x_timer_irq = {
  160. .name = "CLPS711x Timer Tick",
  161. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  162. .handler = p720t_timer_interrupt,
  163. };
  164. static void add_fixed_clk(struct clk *clk, const char *name, int rate)
  165. {
  166. clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
  167. clk_register_clkdev(clk, name, NULL);
  168. }
  169. static void __init clps711x_timer_init(void)
  170. {
  171. int osc, ext, pll, cpu, bus, timl, timh, uart, spi;
  172. u32 tmp;
  173. osc = 3686400;
  174. ext = 13000000;
  175. tmp = clps_readl(PLLR) >> 24;
  176. if (tmp)
  177. pll = (osc * tmp) / 2;
  178. else
  179. pll = 73728000; /* Default value */
  180. tmp = clps_readl(SYSFLG2);
  181. if (tmp & SYSFLG2_CKMODE) {
  182. cpu = ext;
  183. bus = cpu;
  184. spi = 135400;
  185. } else {
  186. cpu = pll;
  187. if (cpu >= 36864000)
  188. bus = cpu / 2;
  189. else
  190. bus = 36864000 / 2;
  191. spi = cpu / 576;
  192. }
  193. uart = bus / 10;
  194. if (tmp & SYSFLG2_CKMODE) {
  195. tmp = clps_readl(SYSCON2);
  196. if (tmp & SYSCON2_OSTB)
  197. timh = ext / 26;
  198. else
  199. timh = 541440;
  200. } else
  201. timh = cpu / 144;
  202. timl = timh / 256;
  203. /* All clocks are fixed */
  204. add_fixed_clk(clk_pll, "pll", pll);
  205. add_fixed_clk(clk_bus, "bus", bus);
  206. add_fixed_clk(clk_uart, "uart", uart);
  207. add_fixed_clk(clk_timerl, "timer_lf", timl);
  208. add_fixed_clk(clk_timerh, "timer_hf", timh);
  209. add_fixed_clk(clk_tint, "tint", 64);
  210. add_fixed_clk(clk_spi, "spi", spi);
  211. pr_info("CPU frequency set at %i Hz.\n", cpu);
  212. latch = (timh + HZ / 2) / HZ;
  213. tmp = clps_readl(SYSCON1);
  214. tmp |= SYSCON1_TC2S | SYSCON1_TC2M;
  215. clps_writel(tmp, SYSCON1);
  216. clps_writel(latch - 1, TC2D);
  217. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  218. }
  219. struct sys_timer clps711x_timer = {
  220. .init = clps711x_timer_init,
  221. .offset = clps711x_gettimeoffset,
  222. };
  223. void clps711x_restart(char mode, const char *cmd)
  224. {
  225. soft_restart(0);
  226. }
  227. static void clps711x_idle(void)
  228. {
  229. clps_writel(1, HALT);
  230. __asm__ __volatile__(
  231. "mov r0, r0\n\
  232. mov r0, r0");
  233. }
  234. static int __init clps711x_idle_init(void)
  235. {
  236. arm_pm_idle = clps711x_idle;
  237. return 0;
  238. }
  239. arch_initcall(clps711x_idle_init);