integrator_ap.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /*
  2. * linux/arch/arm/mach-integrator/integrator_ap.c
  3. *
  4. * Copyright (C) 2000-2003 Deep Blue Solutions Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/list.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/slab.h>
  26. #include <linux/string.h>
  27. #include <linux/sysdev.h>
  28. #include <linux/amba/bus.h>
  29. #include <linux/amba/kmi.h>
  30. #include <linux/clocksource.h>
  31. #include <linux/clockchips.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/io.h>
  34. #include <mach/hardware.h>
  35. #include <mach/platform.h>
  36. #include <asm/hardware/arm_timer.h>
  37. #include <asm/irq.h>
  38. #include <asm/setup.h>
  39. #include <asm/param.h> /* HZ */
  40. #include <asm/mach-types.h>
  41. #include <mach/lm.h>
  42. #include <asm/mach/arch.h>
  43. #include <asm/mach/flash.h>
  44. #include <asm/mach/irq.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/mach/time.h>
  47. #include "common.h"
  48. /*
  49. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  50. * is the (PA >> 12).
  51. *
  52. * Setup a VA for the Integrator interrupt controller (for header #0,
  53. * just for now).
  54. */
  55. #define VA_IC_BASE IO_ADDRESS(INTEGRATOR_IC_BASE)
  56. #define VA_SC_BASE IO_ADDRESS(INTEGRATOR_SC_BASE)
  57. #define VA_EBI_BASE IO_ADDRESS(INTEGRATOR_EBI_BASE)
  58. #define VA_CMIC_BASE IO_ADDRESS(INTEGRATOR_HDR_IC)
  59. /*
  60. * Logical Physical
  61. * e8000000 40000000 PCI memory PHYS_PCI_MEM_BASE (max 512M)
  62. * ec000000 61000000 PCI config space PHYS_PCI_CONFIG_BASE (max 16M)
  63. * ed000000 62000000 PCI V3 regs PHYS_PCI_V3_BASE (max 64k)
  64. * ee000000 60000000 PCI IO PHYS_PCI_IO_BASE (max 16M)
  65. * ef000000 Cache flush
  66. * f1000000 10000000 Core module registers
  67. * f1100000 11000000 System controller registers
  68. * f1200000 12000000 EBI registers
  69. * f1300000 13000000 Counter/Timer
  70. * f1400000 14000000 Interrupt controller
  71. * f1600000 16000000 UART 0
  72. * f1700000 17000000 UART 1
  73. * f1a00000 1a000000 Debug LEDs
  74. * f1b00000 1b000000 GPIO
  75. */
  76. static struct map_desc ap_io_desc[] __initdata = {
  77. {
  78. .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE),
  79. .pfn = __phys_to_pfn(INTEGRATOR_HDR_BASE),
  80. .length = SZ_4K,
  81. .type = MT_DEVICE
  82. }, {
  83. .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE),
  84. .pfn = __phys_to_pfn(INTEGRATOR_SC_BASE),
  85. .length = SZ_4K,
  86. .type = MT_DEVICE
  87. }, {
  88. .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE),
  89. .pfn = __phys_to_pfn(INTEGRATOR_EBI_BASE),
  90. .length = SZ_4K,
  91. .type = MT_DEVICE
  92. }, {
  93. .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE),
  94. .pfn = __phys_to_pfn(INTEGRATOR_CT_BASE),
  95. .length = SZ_4K,
  96. .type = MT_DEVICE
  97. }, {
  98. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  99. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  100. .length = SZ_4K,
  101. .type = MT_DEVICE
  102. }, {
  103. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  104. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  105. .length = SZ_4K,
  106. .type = MT_DEVICE
  107. }, {
  108. .virtual = IO_ADDRESS(INTEGRATOR_UART1_BASE),
  109. .pfn = __phys_to_pfn(INTEGRATOR_UART1_BASE),
  110. .length = SZ_4K,
  111. .type = MT_DEVICE
  112. }, {
  113. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  114. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  115. .length = SZ_4K,
  116. .type = MT_DEVICE
  117. }, {
  118. .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
  119. .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
  120. .length = SZ_4K,
  121. .type = MT_DEVICE
  122. }, {
  123. .virtual = PCI_MEMORY_VADDR,
  124. .pfn = __phys_to_pfn(PHYS_PCI_MEM_BASE),
  125. .length = SZ_16M,
  126. .type = MT_DEVICE
  127. }, {
  128. .virtual = PCI_CONFIG_VADDR,
  129. .pfn = __phys_to_pfn(PHYS_PCI_CONFIG_BASE),
  130. .length = SZ_16M,
  131. .type = MT_DEVICE
  132. }, {
  133. .virtual = PCI_V3_VADDR,
  134. .pfn = __phys_to_pfn(PHYS_PCI_V3_BASE),
  135. .length = SZ_64K,
  136. .type = MT_DEVICE
  137. }, {
  138. .virtual = PCI_IO_VADDR,
  139. .pfn = __phys_to_pfn(PHYS_PCI_IO_BASE),
  140. .length = SZ_64K,
  141. .type = MT_DEVICE
  142. }
  143. };
  144. static void __init ap_map_io(void)
  145. {
  146. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  147. }
  148. #define INTEGRATOR_SC_VALID_INT 0x003fffff
  149. static void sc_mask_irq(unsigned int irq)
  150. {
  151. writel(1 << irq, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  152. }
  153. static void sc_unmask_irq(unsigned int irq)
  154. {
  155. writel(1 << irq, VA_IC_BASE + IRQ_ENABLE_SET);
  156. }
  157. static struct irq_chip sc_chip = {
  158. .name = "SC",
  159. .ack = sc_mask_irq,
  160. .mask = sc_mask_irq,
  161. .unmask = sc_unmask_irq,
  162. };
  163. static void __init ap_init_irq(void)
  164. {
  165. unsigned int i;
  166. /* Disable all interrupts initially. */
  167. /* Do the core module ones */
  168. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  169. /* do the header card stuff next */
  170. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  171. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  172. for (i = 0; i < NR_IRQS; i++) {
  173. if (((1 << i) & INTEGRATOR_SC_VALID_INT) != 0) {
  174. set_irq_chip(i, &sc_chip);
  175. set_irq_handler(i, handle_level_irq);
  176. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  177. }
  178. }
  179. }
  180. #ifdef CONFIG_PM
  181. static unsigned long ic_irq_enable;
  182. static int irq_suspend(struct sys_device *dev, pm_message_t state)
  183. {
  184. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  185. return 0;
  186. }
  187. static int irq_resume(struct sys_device *dev)
  188. {
  189. /* disable all irq sources */
  190. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  191. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  192. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  193. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  194. return 0;
  195. }
  196. #else
  197. #define irq_suspend NULL
  198. #define irq_resume NULL
  199. #endif
  200. static struct sysdev_class irq_class = {
  201. .name = "irq",
  202. .suspend = irq_suspend,
  203. .resume = irq_resume,
  204. };
  205. static struct sys_device irq_device = {
  206. .id = 0,
  207. .cls = &irq_class,
  208. };
  209. static int __init irq_init_sysfs(void)
  210. {
  211. int ret = sysdev_class_register(&irq_class);
  212. if (ret == 0)
  213. ret = sysdev_register(&irq_device);
  214. return ret;
  215. }
  216. device_initcall(irq_init_sysfs);
  217. /*
  218. * Flash handling.
  219. */
  220. #define SC_CTRLC (VA_SC_BASE + INTEGRATOR_SC_CTRLC_OFFSET)
  221. #define SC_CTRLS (VA_SC_BASE + INTEGRATOR_SC_CTRLS_OFFSET)
  222. #define EBI_CSR1 (VA_EBI_BASE + INTEGRATOR_EBI_CSR1_OFFSET)
  223. #define EBI_LOCK (VA_EBI_BASE + INTEGRATOR_EBI_LOCK_OFFSET)
  224. static int ap_flash_init(void)
  225. {
  226. u32 tmp;
  227. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
  228. tmp = readl(EBI_CSR1) | INTEGRATOR_EBI_WRITE_ENABLE;
  229. writel(tmp, EBI_CSR1);
  230. if (!(readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE)) {
  231. writel(0xa05f, EBI_LOCK);
  232. writel(tmp, EBI_CSR1);
  233. writel(0, EBI_LOCK);
  234. }
  235. return 0;
  236. }
  237. static void ap_flash_exit(void)
  238. {
  239. u32 tmp;
  240. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP, SC_CTRLC);
  241. tmp = readl(EBI_CSR1) & ~INTEGRATOR_EBI_WRITE_ENABLE;
  242. writel(tmp, EBI_CSR1);
  243. if (readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE) {
  244. writel(0xa05f, EBI_LOCK);
  245. writel(tmp, EBI_CSR1);
  246. writel(0, EBI_LOCK);
  247. }
  248. }
  249. static void ap_flash_set_vpp(int on)
  250. {
  251. unsigned long reg = on ? SC_CTRLS : SC_CTRLC;
  252. writel(INTEGRATOR_SC_CTRL_nFLVPPEN, reg);
  253. }
  254. static struct flash_platform_data ap_flash_data = {
  255. .map_name = "cfi_probe",
  256. .width = 4,
  257. .init = ap_flash_init,
  258. .exit = ap_flash_exit,
  259. .set_vpp = ap_flash_set_vpp,
  260. };
  261. static struct resource cfi_flash_resource = {
  262. .start = INTEGRATOR_FLASH_BASE,
  263. .end = INTEGRATOR_FLASH_BASE + INTEGRATOR_FLASH_SIZE - 1,
  264. .flags = IORESOURCE_MEM,
  265. };
  266. static struct platform_device cfi_flash_device = {
  267. .name = "armflash",
  268. .id = 0,
  269. .dev = {
  270. .platform_data = &ap_flash_data,
  271. },
  272. .num_resources = 1,
  273. .resource = &cfi_flash_resource,
  274. };
  275. static void __init ap_init(void)
  276. {
  277. unsigned long sc_dec;
  278. int i;
  279. platform_device_register(&cfi_flash_device);
  280. sc_dec = readl(VA_SC_BASE + INTEGRATOR_SC_DEC_OFFSET);
  281. for (i = 0; i < 4; i++) {
  282. struct lm_device *lmdev;
  283. if ((sc_dec & (16 << i)) == 0)
  284. continue;
  285. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  286. if (!lmdev)
  287. continue;
  288. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  289. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  290. lmdev->resource.flags = IORESOURCE_MEM;
  291. lmdev->irq = IRQ_AP_EXPINT0 + i;
  292. lmdev->id = i;
  293. lm_device_register(lmdev);
  294. }
  295. }
  296. /*
  297. * Where is the timer (VA)?
  298. */
  299. #define TIMER0_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER0_BASE)
  300. #define TIMER1_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER1_BASE)
  301. #define TIMER2_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER2_BASE)
  302. /*
  303. * How long is the timer interval?
  304. */
  305. #define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
  306. #if TIMER_INTERVAL >= 0x100000
  307. #define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
  308. #elif TIMER_INTERVAL >= 0x10000
  309. #define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
  310. #else
  311. #define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
  312. #endif
  313. static unsigned long timer_reload;
  314. static void __iomem * const clksrc_base = (void __iomem *)TIMER2_VA_BASE;
  315. static cycle_t timersp_read(struct clocksource *cs)
  316. {
  317. return ~(readl(clksrc_base + TIMER_VALUE) & 0xffff);
  318. }
  319. static struct clocksource clocksource_timersp = {
  320. .name = "timer2",
  321. .rating = 200,
  322. .read = timersp_read,
  323. .mask = CLOCKSOURCE_MASK(16),
  324. .shift = 16,
  325. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  326. };
  327. static void integrator_clocksource_init(u32 khz)
  328. {
  329. struct clocksource *cs = &clocksource_timersp;
  330. void __iomem *base = clksrc_base;
  331. u32 ctrl = TIMER_CTRL_ENABLE;
  332. if (khz >= 1500) {
  333. khz /= 16;
  334. ctrl = TIMER_CTRL_DIV16;
  335. }
  336. writel(ctrl, base + TIMER_CTRL);
  337. writel(0xffff, base + TIMER_LOAD);
  338. cs->mult = clocksource_khz2mult(khz, cs->shift);
  339. clocksource_register(cs);
  340. }
  341. static void __iomem * const clkevt_base = (void __iomem *)TIMER1_VA_BASE;
  342. /*
  343. * IRQ handler for the timer
  344. */
  345. static irqreturn_t integrator_timer_interrupt(int irq, void *dev_id)
  346. {
  347. struct clock_event_device *evt = dev_id;
  348. /* clear the interrupt */
  349. writel(1, clkevt_base + TIMER_INTCLR);
  350. evt->event_handler(evt);
  351. return IRQ_HANDLED;
  352. }
  353. static void clkevt_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)
  354. {
  355. u32 ctrl = readl(clkevt_base + TIMER_CTRL) & ~TIMER_CTRL_ENABLE;
  356. BUG_ON(mode == CLOCK_EVT_MODE_ONESHOT);
  357. if (mode == CLOCK_EVT_MODE_PERIODIC) {
  358. writel(ctrl, clkevt_base + TIMER_CTRL);
  359. writel(timer_reload, clkevt_base + TIMER_LOAD);
  360. ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
  361. }
  362. writel(ctrl, clkevt_base + TIMER_CTRL);
  363. }
  364. static int clkevt_set_next_event(unsigned long next, struct clock_event_device *evt)
  365. {
  366. unsigned long ctrl = readl(clkevt_base + TIMER_CTRL);
  367. writel(ctrl & ~TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
  368. writel(next, clkevt_base + TIMER_LOAD);
  369. writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
  370. return 0;
  371. }
  372. static struct clock_event_device integrator_clockevent = {
  373. .name = "timer1",
  374. .shift = 34,
  375. .features = CLOCK_EVT_FEAT_PERIODIC,
  376. .set_mode = clkevt_set_mode,
  377. .set_next_event = clkevt_set_next_event,
  378. .rating = 300,
  379. .cpumask = cpu_all_mask,
  380. };
  381. static struct irqaction integrator_timer_irq = {
  382. .name = "timer",
  383. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  384. .handler = integrator_timer_interrupt,
  385. .dev_id = &integrator_clockevent,
  386. };
  387. static void integrator_clockevent_init(u32 khz)
  388. {
  389. struct clock_event_device *evt = &integrator_clockevent;
  390. unsigned int ctrl = 0;
  391. if (khz * 1000 > 0x100000 * HZ) {
  392. khz /= 256;
  393. ctrl |= TIMER_CTRL_DIV256;
  394. } else if (khz * 1000 > 0x10000 * HZ) {
  395. khz /= 16;
  396. ctrl |= TIMER_CTRL_DIV16;
  397. }
  398. timer_reload = khz * 1000 / HZ;
  399. writel(ctrl, clkevt_base + TIMER_CTRL);
  400. evt->irq = IRQ_TIMERINT1;
  401. evt->mult = div_sc(khz, NSEC_PER_MSEC, evt->shift);
  402. evt->max_delta_ns = clockevent_delta2ns(0xffff, evt);
  403. evt->min_delta_ns = clockevent_delta2ns(0xf, evt);
  404. setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
  405. clockevents_register_device(evt);
  406. }
  407. /*
  408. * Set up timer(s).
  409. */
  410. static void __init ap_init_timer(void)
  411. {
  412. u32 khz = TICKS_PER_uSEC * 1000;
  413. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  414. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  415. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  416. integrator_clocksource_init(khz);
  417. integrator_clockevent_init(khz);
  418. }
  419. static struct sys_timer ap_timer = {
  420. .init = ap_init_timer,
  421. };
  422. MACHINE_START(INTEGRATOR, "ARM-Integrator")
  423. /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
  424. .phys_io = 0x16000000,
  425. .io_pg_offst = ((0xf1600000) >> 18) & 0xfffc,
  426. .boot_params = 0x00000100,
  427. .map_io = ap_map_io,
  428. .reserve = integrator_reserve,
  429. .init_irq = ap_init_irq,
  430. .timer = &ap_timer,
  431. .init_machine = ap_init,
  432. MACHINE_END