core.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Copyright 1999 - 2003 ARM Limited
  3. * Copyright 2000 Deep Blue Solutions Ltd
  4. * Copyright 2008 Cavium Networks
  5. *
  6. * This file is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, Version 2, as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/clockchips.h>
  13. #include <linux/io.h>
  14. #include <linux/irqchip/arm-gic.h>
  15. #include <asm/mach/map.h>
  16. #include <asm/mach/time.h>
  17. #include <asm/mach/irq.h>
  18. #include <asm/hardware/cache-l2x0.h>
  19. #include <mach/cns3xxx.h>
  20. #include "core.h"
  21. static struct map_desc cns3xxx_io_desc[] __initdata = {
  22. {
  23. .virtual = CNS3XXX_TC11MP_SCU_BASE_VIRT,
  24. .pfn = __phys_to_pfn(CNS3XXX_TC11MP_SCU_BASE),
  25. .length = SZ_8K,
  26. .type = MT_DEVICE,
  27. }, {
  28. .virtual = CNS3XXX_TIMER1_2_3_BASE_VIRT,
  29. .pfn = __phys_to_pfn(CNS3XXX_TIMER1_2_3_BASE),
  30. .length = SZ_4K,
  31. .type = MT_DEVICE,
  32. }, {
  33. .virtual = CNS3XXX_GPIOA_BASE_VIRT,
  34. .pfn = __phys_to_pfn(CNS3XXX_GPIOA_BASE),
  35. .length = SZ_4K,
  36. .type = MT_DEVICE,
  37. }, {
  38. .virtual = CNS3XXX_GPIOB_BASE_VIRT,
  39. .pfn = __phys_to_pfn(CNS3XXX_GPIOB_BASE),
  40. .length = SZ_4K,
  41. .type = MT_DEVICE,
  42. }, {
  43. .virtual = CNS3XXX_MISC_BASE_VIRT,
  44. .pfn = __phys_to_pfn(CNS3XXX_MISC_BASE),
  45. .length = SZ_4K,
  46. .type = MT_DEVICE,
  47. }, {
  48. .virtual = CNS3XXX_PM_BASE_VIRT,
  49. .pfn = __phys_to_pfn(CNS3XXX_PM_BASE),
  50. .length = SZ_4K,
  51. .type = MT_DEVICE,
  52. },
  53. };
  54. void __init cns3xxx_map_io(void)
  55. {
  56. iotable_init(cns3xxx_io_desc, ARRAY_SIZE(cns3xxx_io_desc));
  57. }
  58. /* used by entry-macro.S */
  59. void __init cns3xxx_init_irq(void)
  60. {
  61. gic_init(0, 29, IOMEM(CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT),
  62. IOMEM(CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT));
  63. }
  64. void cns3xxx_power_off(void)
  65. {
  66. u32 __iomem *pm_base = IOMEM(CNS3XXX_PM_BASE_VIRT);
  67. u32 clkctrl;
  68. printk(KERN_INFO "powering system down...\n");
  69. clkctrl = readl(pm_base + PM_SYS_CLK_CTRL_OFFSET);
  70. clkctrl &= 0xfffff1ff;
  71. clkctrl |= (0x5 << 9); /* Hibernate */
  72. writel(clkctrl, pm_base + PM_SYS_CLK_CTRL_OFFSET);
  73. }
  74. /*
  75. * Timer
  76. */
  77. static void __iomem *cns3xxx_tmr1;
  78. static void cns3xxx_timer_set_mode(enum clock_event_mode mode,
  79. struct clock_event_device *clk)
  80. {
  81. unsigned long ctrl = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  82. int pclk = cns3xxx_cpu_clock() / 8;
  83. int reload;
  84. switch (mode) {
  85. case CLOCK_EVT_MODE_PERIODIC:
  86. reload = pclk * 20 / (3 * HZ) * 0x25000;
  87. writel(reload, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
  88. ctrl |= (1 << 0) | (1 << 2) | (1 << 9);
  89. break;
  90. case CLOCK_EVT_MODE_ONESHOT:
  91. /* period set, and timer enabled in 'next_event' hook */
  92. ctrl |= (1 << 2) | (1 << 9);
  93. break;
  94. case CLOCK_EVT_MODE_UNUSED:
  95. case CLOCK_EVT_MODE_SHUTDOWN:
  96. default:
  97. ctrl = 0;
  98. }
  99. writel(ctrl, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  100. }
  101. static int cns3xxx_timer_set_next_event(unsigned long evt,
  102. struct clock_event_device *unused)
  103. {
  104. unsigned long ctrl = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  105. writel(evt, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
  106. writel(ctrl | (1 << 0), cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  107. return 0;
  108. }
  109. static struct clock_event_device cns3xxx_tmr1_clockevent = {
  110. .name = "cns3xxx timer1",
  111. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  112. .set_mode = cns3xxx_timer_set_mode,
  113. .set_next_event = cns3xxx_timer_set_next_event,
  114. .rating = 350,
  115. .cpumask = cpu_all_mask,
  116. };
  117. static void __init cns3xxx_clockevents_init(unsigned int timer_irq)
  118. {
  119. cns3xxx_tmr1_clockevent.irq = timer_irq;
  120. clockevents_config_and_register(&cns3xxx_tmr1_clockevent,
  121. (cns3xxx_cpu_clock() >> 3) * 1000000,
  122. 0xf, 0xffffffff);
  123. }
  124. /*
  125. * IRQ handler for the timer
  126. */
  127. static irqreturn_t cns3xxx_timer_interrupt(int irq, void *dev_id)
  128. {
  129. struct clock_event_device *evt = &cns3xxx_tmr1_clockevent;
  130. u32 __iomem *stat = cns3xxx_tmr1 + TIMER1_2_INTERRUPT_STATUS_OFFSET;
  131. u32 val;
  132. /* Clear the interrupt */
  133. val = readl(stat);
  134. writel(val & ~(1 << 2), stat);
  135. evt->event_handler(evt);
  136. return IRQ_HANDLED;
  137. }
  138. static struct irqaction cns3xxx_timer_irq = {
  139. .name = "timer",
  140. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  141. .handler = cns3xxx_timer_interrupt,
  142. };
  143. /*
  144. * Set up the clock source and clock events devices
  145. */
  146. static void __init __cns3xxx_timer_init(unsigned int timer_irq)
  147. {
  148. u32 val;
  149. u32 irq_mask;
  150. /*
  151. * Initialise to a known state (all timers off)
  152. */
  153. /* disable timer1 and timer2 */
  154. writel(0, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  155. /* stop free running timer3 */
  156. writel(0, cns3xxx_tmr1 + TIMER_FREERUN_CONTROL_OFFSET);
  157. /* timer1 */
  158. writel(0x5C800, cns3xxx_tmr1 + TIMER1_COUNTER_OFFSET);
  159. writel(0x5C800, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
  160. writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V1_OFFSET);
  161. writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V2_OFFSET);
  162. /* mask irq, non-mask timer1 overflow */
  163. irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
  164. irq_mask &= ~(1 << 2);
  165. irq_mask |= 0x03;
  166. writel(irq_mask, cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
  167. /* down counter */
  168. val = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  169. val |= (1 << 9);
  170. writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  171. /* timer2 */
  172. writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V1_OFFSET);
  173. writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V2_OFFSET);
  174. /* mask irq */
  175. irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
  176. irq_mask |= ((1 << 3) | (1 << 4) | (1 << 5));
  177. writel(irq_mask, cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
  178. /* down counter */
  179. val = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  180. val |= (1 << 10);
  181. writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
  182. /* Make irqs happen for the system timer */
  183. setup_irq(timer_irq, &cns3xxx_timer_irq);
  184. cns3xxx_clockevents_init(timer_irq);
  185. }
  186. void __init cns3xxx_timer_init(void)
  187. {
  188. cns3xxx_tmr1 = IOMEM(CNS3XXX_TIMER1_2_3_BASE_VIRT);
  189. __cns3xxx_timer_init(IRQ_CNS3XXX_TIMER0);
  190. }
  191. #ifdef CONFIG_CACHE_L2X0
  192. void __init cns3xxx_l2x0_init(void)
  193. {
  194. void __iomem *base = ioremap(CNS3XXX_L2C_BASE, SZ_4K);
  195. u32 val;
  196. if (WARN_ON(!base))
  197. return;
  198. /*
  199. * Tag RAM Control register
  200. *
  201. * bit[10:8] - 1 cycle of write accesses latency
  202. * bit[6:4] - 1 cycle of read accesses latency
  203. * bit[3:0] - 1 cycle of setup latency
  204. *
  205. * 1 cycle of latency for setup, read and write accesses
  206. */
  207. val = readl(base + L2X0_TAG_LATENCY_CTRL);
  208. val &= 0xfffff888;
  209. writel(val, base + L2X0_TAG_LATENCY_CTRL);
  210. /*
  211. * Data RAM Control register
  212. *
  213. * bit[10:8] - 1 cycles of write accesses latency
  214. * bit[6:4] - 1 cycles of read accesses latency
  215. * bit[3:0] - 1 cycle of setup latency
  216. *
  217. * 1 cycle of latency for setup, read and write accesses
  218. */
  219. val = readl(base + L2X0_DATA_LATENCY_CTRL);
  220. val &= 0xfffff888;
  221. writel(val, base + L2X0_DATA_LATENCY_CTRL);
  222. /* 32 KiB, 8-way, parity disable */
  223. l2x0_init(base, 0x00540000, 0xfe000fff);
  224. }
  225. #endif /* CONFIG_CACHE_L2X0 */