common.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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/sizes.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/clk.h>
  28. #include <linux/clkdev.h>
  29. #include <linux/clockchips.h>
  30. #include <linux/clk-provider.h>
  31. #include <asm/mach/map.h>
  32. #include <asm/mach/time.h>
  33. #include <asm/system_misc.h>
  34. #include <mach/hardware.h>
  35. static struct clk *clk_pll, *clk_bus, *clk_uart, *clk_timerl, *clk_timerh,
  36. *clk_tint, *clk_spi;
  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_64K,
  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. }
  62. static void int1_eoi(struct irq_data *d)
  63. {
  64. switch (d->irq) {
  65. case IRQ_CSINT: clps_writel(0, COEOI); break;
  66. case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
  67. case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
  68. case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
  69. case IRQ_TINT: clps_writel(0, TEOI); break;
  70. case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
  71. }
  72. }
  73. static void int1_unmask(struct irq_data *d)
  74. {
  75. u32 intmr1;
  76. intmr1 = clps_readl(INTMR1);
  77. intmr1 |= 1 << d->irq;
  78. clps_writel(intmr1, INTMR1);
  79. }
  80. static struct irq_chip int1_chip = {
  81. .name = "Interrupt Vector 1 ",
  82. .irq_ack = int1_ack,
  83. .irq_eoi = int1_eoi,
  84. .irq_mask = int1_mask,
  85. .irq_unmask = int1_unmask,
  86. };
  87. static void int2_mask(struct irq_data *d)
  88. {
  89. u32 intmr2;
  90. intmr2 = clps_readl(INTMR2);
  91. intmr2 &= ~(1 << (d->irq - 16));
  92. clps_writel(intmr2, INTMR2);
  93. }
  94. static void int2_ack(struct irq_data *d)
  95. {
  96. }
  97. static void int2_eoi(struct irq_data *d)
  98. {
  99. switch (d->irq) {
  100. case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
  101. }
  102. }
  103. static void int2_unmask(struct irq_data *d)
  104. {
  105. u32 intmr2;
  106. intmr2 = clps_readl(INTMR2);
  107. intmr2 |= 1 << (d->irq - 16);
  108. clps_writel(intmr2, INTMR2);
  109. }
  110. static struct irq_chip int2_chip = {
  111. .name = "Interrupt Vector 2 ",
  112. .irq_ack = int2_ack,
  113. .irq_eoi = int2_eoi,
  114. .irq_mask = int2_mask,
  115. .irq_unmask = int2_unmask,
  116. };
  117. struct clps711x_irqdesc {
  118. int nr;
  119. struct irq_chip *chip;
  120. irq_flow_handler_t handle;
  121. };
  122. static struct clps711x_irqdesc clps711x_irqdescs[] __initdata = {
  123. { IRQ_CSINT, &int1_chip, handle_fasteoi_irq, },
  124. { IRQ_EINT1, &int1_chip, handle_level_irq, },
  125. { IRQ_EINT2, &int1_chip, handle_level_irq, },
  126. { IRQ_EINT3, &int1_chip, handle_level_irq, },
  127. { IRQ_TC1OI, &int1_chip, handle_fasteoi_irq, },
  128. { IRQ_TC2OI, &int1_chip, handle_fasteoi_irq, },
  129. { IRQ_RTCMI, &int1_chip, handle_fasteoi_irq, },
  130. { IRQ_TINT, &int1_chip, handle_fasteoi_irq, },
  131. { IRQ_UTXINT1, &int1_chip, handle_level_irq, },
  132. { IRQ_URXINT1, &int1_chip, handle_level_irq, },
  133. { IRQ_UMSINT, &int1_chip, handle_fasteoi_irq, },
  134. { IRQ_SSEOTI, &int1_chip, handle_level_irq, },
  135. { IRQ_KBDINT, &int2_chip, handle_fasteoi_irq, },
  136. { IRQ_SS2RX, &int2_chip, handle_level_irq, },
  137. { IRQ_SS2TX, &int2_chip, handle_level_irq, },
  138. { IRQ_UTXINT2, &int2_chip, handle_level_irq, },
  139. { IRQ_URXINT2, &int2_chip, handle_level_irq, },
  140. };
  141. void __init clps711x_init_irq(void)
  142. {
  143. unsigned int i;
  144. /* Disable interrupts */
  145. clps_writel(0, INTMR1);
  146. clps_writel(0, INTMR2);
  147. clps_writel(0, INTMR3);
  148. /* Clear down any pending interrupts */
  149. clps_writel(0, BLEOI);
  150. clps_writel(0, MCEOI);
  151. clps_writel(0, COEOI);
  152. clps_writel(0, TC1EOI);
  153. clps_writel(0, TC2EOI);
  154. clps_writel(0, RTCEOI);
  155. clps_writel(0, TEOI);
  156. clps_writel(0, UMSEOI);
  157. clps_writel(0, KBDEOI);
  158. clps_writel(0, SRXEOF);
  159. clps_writel(0xffffffff, DAISR);
  160. for (i = 0; i < ARRAY_SIZE(clps711x_irqdescs); i++) {
  161. irq_set_chip_and_handler(clps711x_irqdescs[i].nr,
  162. clps711x_irqdescs[i].chip,
  163. clps711x_irqdescs[i].handle);
  164. set_irq_flags(clps711x_irqdescs[i].nr,
  165. IRQF_VALID | IRQF_PROBE);
  166. }
  167. }
  168. static void clps711x_clockevent_set_mode(enum clock_event_mode mode,
  169. struct clock_event_device *evt)
  170. {
  171. }
  172. static struct clock_event_device clockevent_clps711x = {
  173. .name = "CLPS711x Clockevents",
  174. .rating = 300,
  175. .features = CLOCK_EVT_FEAT_PERIODIC,
  176. .set_mode = clps711x_clockevent_set_mode,
  177. };
  178. static irqreturn_t clps711x_timer_interrupt(int irq, void *dev_id)
  179. {
  180. clockevent_clps711x.event_handler(&clockevent_clps711x);
  181. return IRQ_HANDLED;
  182. }
  183. static struct irqaction clps711x_timer_irq = {
  184. .name = "CLPS711x Timer Tick",
  185. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  186. .handler = clps711x_timer_interrupt,
  187. };
  188. static void add_fixed_clk(struct clk *clk, const char *name, int rate)
  189. {
  190. clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
  191. clk_register_clkdev(clk, name, NULL);
  192. }
  193. static void __init clps711x_timer_init(void)
  194. {
  195. int osc, ext, pll, cpu, bus, timl, timh, uart, spi;
  196. u32 tmp;
  197. osc = 3686400;
  198. ext = 13000000;
  199. tmp = clps_readl(PLLR) >> 24;
  200. if (tmp)
  201. pll = (osc * tmp) / 2;
  202. else
  203. pll = 73728000; /* Default value */
  204. tmp = clps_readl(SYSFLG2);
  205. if (tmp & SYSFLG2_CKMODE) {
  206. cpu = ext;
  207. bus = cpu;
  208. spi = 135400;
  209. } else {
  210. cpu = pll;
  211. if (cpu >= 36864000)
  212. bus = cpu / 2;
  213. else
  214. bus = 36864000 / 2;
  215. spi = cpu / 576;
  216. }
  217. uart = bus / 10;
  218. if (tmp & SYSFLG2_CKMODE) {
  219. tmp = clps_readl(SYSCON2);
  220. if (tmp & SYSCON2_OSTB)
  221. timh = ext / 26;
  222. else
  223. timh = 541440;
  224. } else
  225. timh = cpu / 144;
  226. timl = timh / 256;
  227. /* All clocks are fixed */
  228. add_fixed_clk(clk_pll, "pll", pll);
  229. add_fixed_clk(clk_bus, "bus", bus);
  230. add_fixed_clk(clk_uart, "uart", uart);
  231. add_fixed_clk(clk_timerl, "timer_lf", timl);
  232. add_fixed_clk(clk_timerh, "timer_hf", timh);
  233. add_fixed_clk(clk_tint, "tint", 64);
  234. add_fixed_clk(clk_spi, "spi", spi);
  235. pr_info("CPU frequency set at %i Hz.\n", cpu);
  236. clps_writew(DIV_ROUND_CLOSEST(timh, HZ), TC2D);
  237. tmp = clps_readl(SYSCON1);
  238. tmp |= SYSCON1_TC2S | SYSCON1_TC2M;
  239. clps_writel(tmp, SYSCON1);
  240. clockevents_config_and_register(&clockevent_clps711x, timh, 1, 0xffff);
  241. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  242. }
  243. struct sys_timer clps711x_timer = {
  244. .init = clps711x_timer_init,
  245. };
  246. void clps711x_restart(char mode, const char *cmd)
  247. {
  248. soft_restart(0);
  249. }
  250. static void clps711x_idle(void)
  251. {
  252. clps_writel(1, HALT);
  253. __asm__ __volatile__(
  254. "mov r0, r0\n\
  255. mov r0, r0");
  256. }
  257. static int __init clps711x_idle_init(void)
  258. {
  259. arm_pm_idle = clps711x_idle;
  260. return 0;
  261. }
  262. arch_initcall(clps711x_idle_init);