common.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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/exception.h>
  32. #include <asm/mach/irq.h>
  33. #include <asm/mach/map.h>
  34. #include <asm/mach/time.h>
  35. #include <asm/system_misc.h>
  36. #include <mach/hardware.h>
  37. static struct clk *clk_pll, *clk_bus, *clk_uart, *clk_timerl, *clk_timerh,
  38. *clk_tint, *clk_spi;
  39. /*
  40. * This maps the generic CLPS711x registers
  41. */
  42. static struct map_desc clps711x_io_desc[] __initdata = {
  43. {
  44. .virtual = (unsigned long)CLPS711X_VIRT_BASE,
  45. .pfn = __phys_to_pfn(CLPS711X_PHYS_BASE),
  46. .length = SZ_64K,
  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_eoi(struct irq_data *d)
  62. {
  63. switch (d->irq) {
  64. case IRQ_CSINT: clps_writel(0, COEOI); break;
  65. case IRQ_TC1OI: clps_writel(0, TC1EOI); break;
  66. case IRQ_TC2OI: clps_writel(0, TC2EOI); break;
  67. case IRQ_RTCMI: clps_writel(0, RTCEOI); break;
  68. case IRQ_TINT: clps_writel(0, TEOI); break;
  69. case IRQ_UMSINT: clps_writel(0, UMSEOI); break;
  70. }
  71. }
  72. static void int1_unmask(struct irq_data *d)
  73. {
  74. u32 intmr1;
  75. intmr1 = clps_readl(INTMR1);
  76. intmr1 |= 1 << d->irq;
  77. clps_writel(intmr1, INTMR1);
  78. }
  79. static struct irq_chip int1_chip = {
  80. .name = "Interrupt Vector 1",
  81. .irq_eoi = int1_eoi,
  82. .irq_mask = int1_mask,
  83. .irq_unmask = int1_unmask,
  84. };
  85. static void int2_mask(struct irq_data *d)
  86. {
  87. u32 intmr2;
  88. intmr2 = clps_readl(INTMR2);
  89. intmr2 &= ~(1 << (d->irq - 16));
  90. clps_writel(intmr2, INTMR2);
  91. }
  92. static void int2_eoi(struct irq_data *d)
  93. {
  94. switch (d->irq) {
  95. case IRQ_KBDINT: clps_writel(0, KBDEOI); break;
  96. }
  97. }
  98. static void int2_unmask(struct irq_data *d)
  99. {
  100. u32 intmr2;
  101. intmr2 = clps_readl(INTMR2);
  102. intmr2 |= 1 << (d->irq - 16);
  103. clps_writel(intmr2, INTMR2);
  104. }
  105. static struct irq_chip int2_chip = {
  106. .name = "Interrupt Vector 2",
  107. .irq_eoi = int2_eoi,
  108. .irq_mask = int2_mask,
  109. .irq_unmask = int2_unmask,
  110. };
  111. static void int3_mask(struct irq_data *d)
  112. {
  113. u32 intmr3;
  114. intmr3 = clps_readl(INTMR3);
  115. intmr3 &= ~(1 << (d->irq - 32));
  116. clps_writel(intmr3, INTMR3);
  117. }
  118. static void int3_unmask(struct irq_data *d)
  119. {
  120. u32 intmr3;
  121. intmr3 = clps_readl(INTMR3);
  122. intmr3 |= 1 << (d->irq - 32);
  123. clps_writel(intmr3, INTMR3);
  124. }
  125. static struct irq_chip int3_chip = {
  126. .name = "Interrupt Vector 3",
  127. .irq_mask = int3_mask,
  128. .irq_unmask = int3_unmask,
  129. };
  130. static struct {
  131. int nr;
  132. struct irq_chip *chip;
  133. irq_flow_handler_t handle;
  134. } clps711x_irqdescs[] __initdata = {
  135. { IRQ_CSINT, &int1_chip, handle_fasteoi_irq, },
  136. { IRQ_EINT1, &int1_chip, handle_level_irq, },
  137. { IRQ_EINT2, &int1_chip, handle_level_irq, },
  138. { IRQ_EINT3, &int1_chip, handle_level_irq, },
  139. { IRQ_TC1OI, &int1_chip, handle_fasteoi_irq, },
  140. { IRQ_TC2OI, &int1_chip, handle_fasteoi_irq, },
  141. { IRQ_RTCMI, &int1_chip, handle_fasteoi_irq, },
  142. { IRQ_TINT, &int1_chip, handle_fasteoi_irq, },
  143. { IRQ_UTXINT1, &int1_chip, handle_level_irq, },
  144. { IRQ_URXINT1, &int1_chip, handle_level_irq, },
  145. { IRQ_UMSINT, &int1_chip, handle_fasteoi_irq, },
  146. { IRQ_SSEOTI, &int1_chip, handle_level_irq, },
  147. { IRQ_KBDINT, &int2_chip, handle_fasteoi_irq, },
  148. { IRQ_SS2RX, &int2_chip, handle_level_irq, },
  149. { IRQ_SS2TX, &int2_chip, handle_level_irq, },
  150. { IRQ_UTXINT2, &int2_chip, handle_level_irq, },
  151. { IRQ_URXINT2, &int2_chip, handle_level_irq, },
  152. };
  153. void __init clps711x_init_irq(void)
  154. {
  155. unsigned int i;
  156. /* Disable interrupts */
  157. clps_writel(0, INTMR1);
  158. clps_writel(0, INTMR2);
  159. clps_writel(0, INTMR3);
  160. /* Clear down any pending interrupts */
  161. clps_writel(0, BLEOI);
  162. clps_writel(0, MCEOI);
  163. clps_writel(0, COEOI);
  164. clps_writel(0, TC1EOI);
  165. clps_writel(0, TC2EOI);
  166. clps_writel(0, RTCEOI);
  167. clps_writel(0, TEOI);
  168. clps_writel(0, UMSEOI);
  169. clps_writel(0, KBDEOI);
  170. clps_writel(0, SRXEOF);
  171. clps_writel(0xffffffff, DAISR);
  172. for (i = 0; i < ARRAY_SIZE(clps711x_irqdescs); i++) {
  173. irq_set_chip_and_handler(clps711x_irqdescs[i].nr,
  174. clps711x_irqdescs[i].chip,
  175. clps711x_irqdescs[i].handle);
  176. set_irq_flags(clps711x_irqdescs[i].nr,
  177. IRQF_VALID | IRQF_PROBE);
  178. }
  179. if (IS_ENABLED(CONFIG_FIQ)) {
  180. init_FIQ(0);
  181. irq_set_chip_and_handler(IRQ_DAIINT, &int3_chip,
  182. handle_bad_irq);
  183. set_irq_flags(IRQ_DAIINT,
  184. IRQF_VALID | IRQF_PROBE | IRQF_NOAUTOEN);
  185. }
  186. }
  187. inline u32 fls16(u32 x)
  188. {
  189. u32 r = 15;
  190. if (!(x & 0xff00)) {
  191. x <<= 8;
  192. r -= 8;
  193. }
  194. if (!(x & 0xf000)) {
  195. x <<= 4;
  196. r -= 4;
  197. }
  198. if (!(x & 0xc000)) {
  199. x <<= 2;
  200. r -= 2;
  201. }
  202. if (!(x & 0x8000))
  203. r--;
  204. return r;
  205. }
  206. asmlinkage void __exception_irq_entry clps711x_handle_irq(struct pt_regs *regs)
  207. {
  208. u32 irqstat;
  209. void __iomem *base = CLPS711X_VIRT_BASE;
  210. irqstat = readl_relaxed(base + INTSR1) & readl_relaxed(base + INTMR1);
  211. if (irqstat) {
  212. handle_IRQ(fls16(irqstat), regs);
  213. return;
  214. }
  215. irqstat = readl_relaxed(base + INTSR2) & readl_relaxed(base + INTMR2);
  216. if (likely(irqstat))
  217. handle_IRQ(fls16(irqstat) + 16, regs);
  218. }
  219. static void clps711x_clockevent_set_mode(enum clock_event_mode mode,
  220. struct clock_event_device *evt)
  221. {
  222. }
  223. static struct clock_event_device clockevent_clps711x = {
  224. .name = "CLPS711x Clockevents",
  225. .rating = 300,
  226. .features = CLOCK_EVT_FEAT_PERIODIC,
  227. .set_mode = clps711x_clockevent_set_mode,
  228. };
  229. static irqreturn_t clps711x_timer_interrupt(int irq, void *dev_id)
  230. {
  231. clockevent_clps711x.event_handler(&clockevent_clps711x);
  232. return IRQ_HANDLED;
  233. }
  234. static struct irqaction clps711x_timer_irq = {
  235. .name = "CLPS711x Timer Tick",
  236. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  237. .handler = clps711x_timer_interrupt,
  238. };
  239. static void add_fixed_clk(struct clk *clk, const char *name, int rate)
  240. {
  241. clk = clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate);
  242. clk_register_clkdev(clk, name, NULL);
  243. }
  244. static void __init clps711x_timer_init(void)
  245. {
  246. int osc, ext, pll, cpu, bus, timl, timh, uart, spi;
  247. u32 tmp;
  248. osc = 3686400;
  249. ext = 13000000;
  250. tmp = clps_readl(PLLR) >> 24;
  251. if (tmp)
  252. pll = (osc * tmp) / 2;
  253. else
  254. pll = 73728000; /* Default value */
  255. tmp = clps_readl(SYSFLG2);
  256. if (tmp & SYSFLG2_CKMODE) {
  257. cpu = ext;
  258. bus = cpu;
  259. spi = 135400;
  260. } else {
  261. cpu = pll;
  262. if (cpu >= 36864000)
  263. bus = cpu / 2;
  264. else
  265. bus = 36864000 / 2;
  266. spi = cpu / 576;
  267. }
  268. uart = bus / 10;
  269. if (tmp & SYSFLG2_CKMODE) {
  270. tmp = clps_readl(SYSCON2);
  271. if (tmp & SYSCON2_OSTB)
  272. timh = ext / 26;
  273. else
  274. timh = 541440;
  275. } else
  276. timh = cpu / 144;
  277. timl = timh / 256;
  278. /* All clocks are fixed */
  279. add_fixed_clk(clk_pll, "pll", pll);
  280. add_fixed_clk(clk_bus, "bus", bus);
  281. add_fixed_clk(clk_uart, "uart", uart);
  282. add_fixed_clk(clk_timerl, "timer_lf", timl);
  283. add_fixed_clk(clk_timerh, "timer_hf", timh);
  284. add_fixed_clk(clk_tint, "tint", 64);
  285. add_fixed_clk(clk_spi, "spi", spi);
  286. pr_info("CPU frequency set at %i Hz.\n", cpu);
  287. clps_writew(DIV_ROUND_CLOSEST(timh, HZ), TC2D);
  288. tmp = clps_readl(SYSCON1);
  289. tmp |= SYSCON1_TC2S | SYSCON1_TC2M;
  290. clps_writel(tmp, SYSCON1);
  291. clockevents_config_and_register(&clockevent_clps711x, timh, 1, 0xffff);
  292. setup_irq(IRQ_TC2OI, &clps711x_timer_irq);
  293. }
  294. struct sys_timer clps711x_timer = {
  295. .init = clps711x_timer_init,
  296. };
  297. void clps711x_restart(char mode, const char *cmd)
  298. {
  299. soft_restart(0);
  300. }
  301. static void clps711x_idle(void)
  302. {
  303. clps_writel(1, HALT);
  304. __asm__ __volatile__(
  305. "mov r0, r0\n\
  306. mov r0, r0");
  307. }
  308. static int __init clps711x_idle_init(void)
  309. {
  310. arm_pm_idle = clps711x_idle;
  311. return 0;
  312. }
  313. arch_initcall(clps711x_idle_init);