integrator_ap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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/syscore_ops.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 <linux/irqchip/versatile-fpga.h>
  35. #include <linux/mtd/physmap.h>
  36. #include <linux/clk.h>
  37. #include <linux/platform_data/clk-integrator.h>
  38. #include <linux/of_irq.h>
  39. #include <linux/of_address.h>
  40. #include <linux/of_platform.h>
  41. #include <linux/stat.h>
  42. #include <linux/sys_soc.h>
  43. #include <linux/termios.h>
  44. #include <video/vga.h>
  45. #include <mach/hardware.h>
  46. #include <mach/platform.h>
  47. #include <asm/hardware/arm_timer.h>
  48. #include <asm/setup.h>
  49. #include <asm/param.h> /* HZ */
  50. #include <asm/mach-types.h>
  51. #include <asm/sched_clock.h>
  52. #include <mach/lm.h>
  53. #include <mach/irqs.h>
  54. #include <asm/mach/arch.h>
  55. #include <asm/mach/irq.h>
  56. #include <asm/mach/map.h>
  57. #include <asm/mach/pci.h>
  58. #include <asm/mach/time.h>
  59. #include "common.h"
  60. /* Base address to the AP system controller */
  61. void __iomem *ap_syscon_base;
  62. /*
  63. * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  64. * is the (PA >> 12).
  65. *
  66. * Setup a VA for the Integrator interrupt controller (for header #0,
  67. * just for now).
  68. */
  69. #define VA_IC_BASE __io_address(INTEGRATOR_IC_BASE)
  70. #define VA_EBI_BASE __io_address(INTEGRATOR_EBI_BASE)
  71. #define VA_CMIC_BASE __io_address(INTEGRATOR_HDR_IC)
  72. /*
  73. * Logical Physical
  74. * e8000000 40000000 PCI memory PHYS_PCI_MEM_BASE (max 512M)
  75. * ec000000 61000000 PCI config space PHYS_PCI_CONFIG_BASE (max 16M)
  76. * ed000000 62000000 PCI V3 regs PHYS_PCI_V3_BASE (max 64k)
  77. * fee00000 60000000 PCI IO PHYS_PCI_IO_BASE (max 16M)
  78. * ef000000 Cache flush
  79. * f1000000 10000000 Core module registers
  80. * f1100000 11000000 System controller registers
  81. * f1200000 12000000 EBI registers
  82. * f1300000 13000000 Counter/Timer
  83. * f1400000 14000000 Interrupt controller
  84. * f1600000 16000000 UART 0
  85. * f1700000 17000000 UART 1
  86. * f1a00000 1a000000 Debug LEDs
  87. * f1b00000 1b000000 GPIO
  88. */
  89. static struct map_desc ap_io_desc[] __initdata __maybe_unused = {
  90. {
  91. .virtual = IO_ADDRESS(INTEGRATOR_HDR_BASE),
  92. .pfn = __phys_to_pfn(INTEGRATOR_HDR_BASE),
  93. .length = SZ_4K,
  94. .type = MT_DEVICE
  95. }, {
  96. .virtual = IO_ADDRESS(INTEGRATOR_EBI_BASE),
  97. .pfn = __phys_to_pfn(INTEGRATOR_EBI_BASE),
  98. .length = SZ_4K,
  99. .type = MT_DEVICE
  100. }, {
  101. .virtual = IO_ADDRESS(INTEGRATOR_CT_BASE),
  102. .pfn = __phys_to_pfn(INTEGRATOR_CT_BASE),
  103. .length = SZ_4K,
  104. .type = MT_DEVICE
  105. }, {
  106. .virtual = IO_ADDRESS(INTEGRATOR_IC_BASE),
  107. .pfn = __phys_to_pfn(INTEGRATOR_IC_BASE),
  108. .length = SZ_4K,
  109. .type = MT_DEVICE
  110. }, {
  111. .virtual = IO_ADDRESS(INTEGRATOR_UART0_BASE),
  112. .pfn = __phys_to_pfn(INTEGRATOR_UART0_BASE),
  113. .length = SZ_4K,
  114. .type = MT_DEVICE
  115. }, {
  116. .virtual = IO_ADDRESS(INTEGRATOR_DBG_BASE),
  117. .pfn = __phys_to_pfn(INTEGRATOR_DBG_BASE),
  118. .length = SZ_4K,
  119. .type = MT_DEVICE
  120. }, {
  121. .virtual = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
  122. .pfn = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
  123. .length = SZ_4K,
  124. .type = MT_DEVICE
  125. }, {
  126. .virtual = (unsigned long)PCI_MEMORY_VADDR,
  127. .pfn = __phys_to_pfn(PHYS_PCI_MEM_BASE),
  128. .length = SZ_16M,
  129. .type = MT_DEVICE
  130. }, {
  131. .virtual = (unsigned long)PCI_CONFIG_VADDR,
  132. .pfn = __phys_to_pfn(PHYS_PCI_CONFIG_BASE),
  133. .length = SZ_16M,
  134. .type = MT_DEVICE
  135. }, {
  136. .virtual = (unsigned long)PCI_V3_VADDR,
  137. .pfn = __phys_to_pfn(PHYS_PCI_V3_BASE),
  138. .length = SZ_64K,
  139. .type = MT_DEVICE
  140. }
  141. };
  142. static void __init ap_map_io(void)
  143. {
  144. iotable_init(ap_io_desc, ARRAY_SIZE(ap_io_desc));
  145. vga_base = (unsigned long)PCI_MEMORY_VADDR;
  146. pci_map_io_early(__phys_to_pfn(PHYS_PCI_IO_BASE));
  147. }
  148. #ifdef CONFIG_PM
  149. static unsigned long ic_irq_enable;
  150. static int irq_suspend(void)
  151. {
  152. ic_irq_enable = readl(VA_IC_BASE + IRQ_ENABLE);
  153. return 0;
  154. }
  155. static void irq_resume(void)
  156. {
  157. /* disable all irq sources */
  158. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  159. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  160. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  161. writel(ic_irq_enable, VA_IC_BASE + IRQ_ENABLE_SET);
  162. }
  163. #else
  164. #define irq_suspend NULL
  165. #define irq_resume NULL
  166. #endif
  167. static struct syscore_ops irq_syscore_ops = {
  168. .suspend = irq_suspend,
  169. .resume = irq_resume,
  170. };
  171. static int __init irq_syscore_init(void)
  172. {
  173. register_syscore_ops(&irq_syscore_ops);
  174. return 0;
  175. }
  176. device_initcall(irq_syscore_init);
  177. /*
  178. * Flash handling.
  179. */
  180. #define EBI_CSR1 (VA_EBI_BASE + INTEGRATOR_EBI_CSR1_OFFSET)
  181. #define EBI_LOCK (VA_EBI_BASE + INTEGRATOR_EBI_LOCK_OFFSET)
  182. static int ap_flash_init(struct platform_device *dev)
  183. {
  184. u32 tmp;
  185. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
  186. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  187. tmp = readl(EBI_CSR1) | INTEGRATOR_EBI_WRITE_ENABLE;
  188. writel(tmp, EBI_CSR1);
  189. if (!(readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE)) {
  190. writel(0xa05f, EBI_LOCK);
  191. writel(tmp, EBI_CSR1);
  192. writel(0, EBI_LOCK);
  193. }
  194. return 0;
  195. }
  196. static void ap_flash_exit(struct platform_device *dev)
  197. {
  198. u32 tmp;
  199. writel(INTEGRATOR_SC_CTRL_nFLVPPEN | INTEGRATOR_SC_CTRL_nFLWP,
  200. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  201. tmp = readl(EBI_CSR1) & ~INTEGRATOR_EBI_WRITE_ENABLE;
  202. writel(tmp, EBI_CSR1);
  203. if (readl(EBI_CSR1) & INTEGRATOR_EBI_WRITE_ENABLE) {
  204. writel(0xa05f, EBI_LOCK);
  205. writel(tmp, EBI_CSR1);
  206. writel(0, EBI_LOCK);
  207. }
  208. }
  209. static void ap_flash_set_vpp(struct platform_device *pdev, int on)
  210. {
  211. if (on)
  212. writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
  213. ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  214. else
  215. writel(INTEGRATOR_SC_CTRL_nFLVPPEN,
  216. ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  217. }
  218. static struct physmap_flash_data ap_flash_data = {
  219. .width = 4,
  220. .init = ap_flash_init,
  221. .exit = ap_flash_exit,
  222. .set_vpp = ap_flash_set_vpp,
  223. };
  224. /*
  225. * For the PL010 found in the Integrator/AP some of the UART control is
  226. * implemented in the system controller and accessed using a callback
  227. * from the driver.
  228. */
  229. static void integrator_uart_set_mctrl(struct amba_device *dev,
  230. void __iomem *base, unsigned int mctrl)
  231. {
  232. unsigned int ctrls = 0, ctrlc = 0, rts_mask, dtr_mask;
  233. u32 phybase = dev->res.start;
  234. if (phybase == INTEGRATOR_UART0_BASE) {
  235. /* UART0 */
  236. rts_mask = 1 << 4;
  237. dtr_mask = 1 << 5;
  238. } else {
  239. /* UART1 */
  240. rts_mask = 1 << 6;
  241. dtr_mask = 1 << 7;
  242. }
  243. if (mctrl & TIOCM_RTS)
  244. ctrlc |= rts_mask;
  245. else
  246. ctrls |= rts_mask;
  247. if (mctrl & TIOCM_DTR)
  248. ctrlc |= dtr_mask;
  249. else
  250. ctrls |= dtr_mask;
  251. __raw_writel(ctrls, ap_syscon_base + INTEGRATOR_SC_CTRLS_OFFSET);
  252. __raw_writel(ctrlc, ap_syscon_base + INTEGRATOR_SC_CTRLC_OFFSET);
  253. }
  254. struct amba_pl010_data ap_uart_data = {
  255. .set_mctrl = integrator_uart_set_mctrl,
  256. };
  257. /*
  258. * Where is the timer (VA)?
  259. */
  260. #define TIMER0_VA_BASE __io_address(INTEGRATOR_TIMER0_BASE)
  261. #define TIMER1_VA_BASE __io_address(INTEGRATOR_TIMER1_BASE)
  262. #define TIMER2_VA_BASE __io_address(INTEGRATOR_TIMER2_BASE)
  263. static unsigned long timer_reload;
  264. static u32 notrace integrator_read_sched_clock(void)
  265. {
  266. return -readl((void __iomem *) TIMER2_VA_BASE + TIMER_VALUE);
  267. }
  268. static void integrator_clocksource_init(unsigned long inrate,
  269. void __iomem *base)
  270. {
  271. u32 ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
  272. unsigned long rate = inrate;
  273. if (rate >= 1500000) {
  274. rate /= 16;
  275. ctrl |= TIMER_CTRL_DIV16;
  276. }
  277. writel(0xffff, base + TIMER_LOAD);
  278. writel(ctrl, base + TIMER_CTRL);
  279. clocksource_mmio_init(base + TIMER_VALUE, "timer2",
  280. rate, 200, 16, clocksource_mmio_readl_down);
  281. setup_sched_clock(integrator_read_sched_clock, 16, rate);
  282. }
  283. static void __iomem * clkevt_base;
  284. /*
  285. * IRQ handler for the timer
  286. */
  287. static irqreturn_t integrator_timer_interrupt(int irq, void *dev_id)
  288. {
  289. struct clock_event_device *evt = dev_id;
  290. /* clear the interrupt */
  291. writel(1, clkevt_base + TIMER_INTCLR);
  292. evt->event_handler(evt);
  293. return IRQ_HANDLED;
  294. }
  295. static void clkevt_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)
  296. {
  297. u32 ctrl = readl(clkevt_base + TIMER_CTRL) & ~TIMER_CTRL_ENABLE;
  298. /* Disable timer */
  299. writel(ctrl, clkevt_base + TIMER_CTRL);
  300. switch (mode) {
  301. case CLOCK_EVT_MODE_PERIODIC:
  302. /* Enable the timer and start the periodic tick */
  303. writel(timer_reload, clkevt_base + TIMER_LOAD);
  304. ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
  305. writel(ctrl, clkevt_base + TIMER_CTRL);
  306. break;
  307. case CLOCK_EVT_MODE_ONESHOT:
  308. /* Leave the timer disabled, .set_next_event will enable it */
  309. ctrl &= ~TIMER_CTRL_PERIODIC;
  310. writel(ctrl, clkevt_base + TIMER_CTRL);
  311. break;
  312. case CLOCK_EVT_MODE_UNUSED:
  313. case CLOCK_EVT_MODE_SHUTDOWN:
  314. case CLOCK_EVT_MODE_RESUME:
  315. default:
  316. /* Just leave in disabled state */
  317. break;
  318. }
  319. }
  320. static int clkevt_set_next_event(unsigned long next, struct clock_event_device *evt)
  321. {
  322. unsigned long ctrl = readl(clkevt_base + TIMER_CTRL);
  323. writel(ctrl & ~TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
  324. writel(next, clkevt_base + TIMER_LOAD);
  325. writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
  326. return 0;
  327. }
  328. static struct clock_event_device integrator_clockevent = {
  329. .name = "timer1",
  330. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  331. .set_mode = clkevt_set_mode,
  332. .set_next_event = clkevt_set_next_event,
  333. .rating = 300,
  334. };
  335. static struct irqaction integrator_timer_irq = {
  336. .name = "timer",
  337. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  338. .handler = integrator_timer_interrupt,
  339. .dev_id = &integrator_clockevent,
  340. };
  341. static void integrator_clockevent_init(unsigned long inrate,
  342. void __iomem *base, int irq)
  343. {
  344. unsigned long rate = inrate;
  345. unsigned int ctrl = 0;
  346. clkevt_base = base;
  347. /* Calculate and program a divisor */
  348. if (rate > 0x100000 * HZ) {
  349. rate /= 256;
  350. ctrl |= TIMER_CTRL_DIV256;
  351. } else if (rate > 0x10000 * HZ) {
  352. rate /= 16;
  353. ctrl |= TIMER_CTRL_DIV16;
  354. }
  355. timer_reload = rate / HZ;
  356. writel(ctrl, clkevt_base + TIMER_CTRL);
  357. setup_irq(irq, &integrator_timer_irq);
  358. clockevents_config_and_register(&integrator_clockevent,
  359. rate,
  360. 1,
  361. 0xffffU);
  362. }
  363. void __init ap_init_early(void)
  364. {
  365. }
  366. #ifdef CONFIG_OF
  367. static void __init ap_of_timer_init(void)
  368. {
  369. struct device_node *node;
  370. const char *path;
  371. void __iomem *base;
  372. int err;
  373. int irq;
  374. struct clk *clk;
  375. unsigned long rate;
  376. clk = clk_get_sys("ap_timer", NULL);
  377. BUG_ON(IS_ERR(clk));
  378. clk_prepare_enable(clk);
  379. rate = clk_get_rate(clk);
  380. err = of_property_read_string(of_aliases,
  381. "arm,timer-primary", &path);
  382. if (WARN_ON(err))
  383. return;
  384. node = of_find_node_by_path(path);
  385. base = of_iomap(node, 0);
  386. if (WARN_ON(!base))
  387. return;
  388. writel(0, base + TIMER_CTRL);
  389. integrator_clocksource_init(rate, base);
  390. err = of_property_read_string(of_aliases,
  391. "arm,timer-secondary", &path);
  392. if (WARN_ON(err))
  393. return;
  394. node = of_find_node_by_path(path);
  395. base = of_iomap(node, 0);
  396. if (WARN_ON(!base))
  397. return;
  398. irq = irq_of_parse_and_map(node, 0);
  399. writel(0, base + TIMER_CTRL);
  400. integrator_clockevent_init(rate, base, irq);
  401. }
  402. static const struct of_device_id fpga_irq_of_match[] __initconst = {
  403. { .compatible = "arm,versatile-fpga-irq", .data = fpga_irq_of_init, },
  404. { /* Sentinel */ }
  405. };
  406. static void __init ap_init_irq_of(void)
  407. {
  408. /* disable core module IRQs */
  409. writel(0xffffffffU, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  410. of_irq_init(fpga_irq_of_match);
  411. integrator_clk_init(false);
  412. }
  413. /* For the Device Tree, add in the UART callbacks as AUXDATA */
  414. static struct of_dev_auxdata ap_auxdata_lookup[] __initdata = {
  415. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_RTC_BASE,
  416. "rtc", NULL),
  417. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART0_BASE,
  418. "uart0", &ap_uart_data),
  419. OF_DEV_AUXDATA("arm,primecell", INTEGRATOR_UART1_BASE,
  420. "uart1", &ap_uart_data),
  421. OF_DEV_AUXDATA("arm,primecell", KMI0_BASE,
  422. "kmi0", NULL),
  423. OF_DEV_AUXDATA("arm,primecell", KMI1_BASE,
  424. "kmi1", NULL),
  425. OF_DEV_AUXDATA("cfi-flash", INTEGRATOR_FLASH_BASE,
  426. "physmap-flash", &ap_flash_data),
  427. { /* sentinel */ },
  428. };
  429. static void __init ap_init_of(void)
  430. {
  431. unsigned long sc_dec;
  432. struct device_node *root;
  433. struct device_node *syscon;
  434. struct device *parent;
  435. struct soc_device *soc_dev;
  436. struct soc_device_attribute *soc_dev_attr;
  437. u32 ap_sc_id;
  438. int err;
  439. int i;
  440. /* Here we create an SoC device for the root node */
  441. root = of_find_node_by_path("/");
  442. if (!root)
  443. return;
  444. syscon = of_find_node_by_path("/syscon");
  445. if (!syscon)
  446. return;
  447. ap_syscon_base = of_iomap(syscon, 0);
  448. if (!ap_syscon_base)
  449. return;
  450. ap_sc_id = readl(ap_syscon_base);
  451. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  452. if (!soc_dev_attr)
  453. return;
  454. err = of_property_read_string(root, "compatible",
  455. &soc_dev_attr->soc_id);
  456. if (err)
  457. return;
  458. err = of_property_read_string(root, "model", &soc_dev_attr->machine);
  459. if (err)
  460. return;
  461. soc_dev_attr->family = "Integrator";
  462. soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%c",
  463. 'A' + (ap_sc_id & 0x0f));
  464. soc_dev = soc_device_register(soc_dev_attr);
  465. if (IS_ERR_OR_NULL(soc_dev)) {
  466. kfree(soc_dev_attr->revision);
  467. kfree(soc_dev_attr);
  468. return;
  469. }
  470. parent = soc_device_to_device(soc_dev);
  471. if (!IS_ERR_OR_NULL(parent))
  472. integrator_init_sysfs(parent, ap_sc_id);
  473. of_platform_populate(root, of_default_bus_match_table,
  474. ap_auxdata_lookup, parent);
  475. sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
  476. for (i = 0; i < 4; i++) {
  477. struct lm_device *lmdev;
  478. if ((sc_dec & (16 << i)) == 0)
  479. continue;
  480. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  481. if (!lmdev)
  482. continue;
  483. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  484. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  485. lmdev->resource.flags = IORESOURCE_MEM;
  486. lmdev->irq = IRQ_AP_EXPINT0 + i;
  487. lmdev->id = i;
  488. lm_device_register(lmdev);
  489. }
  490. }
  491. static const char * ap_dt_board_compat[] = {
  492. "arm,integrator-ap",
  493. NULL,
  494. };
  495. DT_MACHINE_START(INTEGRATOR_AP_DT, "ARM Integrator/AP (Device Tree)")
  496. .reserve = integrator_reserve,
  497. .map_io = ap_map_io,
  498. .init_early = ap_init_early,
  499. .init_irq = ap_init_irq_of,
  500. .handle_irq = fpga_handle_irq,
  501. .init_time = ap_of_timer_init,
  502. .init_machine = ap_init_of,
  503. .restart = integrator_restart,
  504. .dt_compat = ap_dt_board_compat,
  505. MACHINE_END
  506. #endif
  507. #ifdef CONFIG_ATAGS
  508. /*
  509. * For the ATAG boot some static mappings are needed. This will
  510. * go away with the ATAG support down the road.
  511. */
  512. static struct map_desc ap_io_desc_atag[] __initdata = {
  513. {
  514. .virtual = IO_ADDRESS(INTEGRATOR_SC_BASE),
  515. .pfn = __phys_to_pfn(INTEGRATOR_SC_BASE),
  516. .length = SZ_4K,
  517. .type = MT_DEVICE
  518. },
  519. };
  520. static void __init ap_map_io_atag(void)
  521. {
  522. iotable_init(ap_io_desc_atag, ARRAY_SIZE(ap_io_desc_atag));
  523. ap_map_io();
  524. }
  525. /*
  526. * This is where non-devicetree initialization code is collected and stashed
  527. * for eventual deletion.
  528. */
  529. static struct resource cfi_flash_resource = {
  530. .start = INTEGRATOR_FLASH_BASE,
  531. .end = INTEGRATOR_FLASH_BASE + INTEGRATOR_FLASH_SIZE - 1,
  532. .flags = IORESOURCE_MEM,
  533. };
  534. static struct platform_device cfi_flash_device = {
  535. .name = "physmap-flash",
  536. .id = 0,
  537. .dev = {
  538. .platform_data = &ap_flash_data,
  539. },
  540. .num_resources = 1,
  541. .resource = &cfi_flash_resource,
  542. };
  543. static void __init ap_timer_init(void)
  544. {
  545. struct clk *clk;
  546. unsigned long rate;
  547. clk = clk_get_sys("ap_timer", NULL);
  548. BUG_ON(IS_ERR(clk));
  549. clk_prepare_enable(clk);
  550. rate = clk_get_rate(clk);
  551. writel(0, TIMER0_VA_BASE + TIMER_CTRL);
  552. writel(0, TIMER1_VA_BASE + TIMER_CTRL);
  553. writel(0, TIMER2_VA_BASE + TIMER_CTRL);
  554. integrator_clocksource_init(rate, (void __iomem *)TIMER2_VA_BASE);
  555. integrator_clockevent_init(rate, (void __iomem *)TIMER1_VA_BASE,
  556. IRQ_TIMERINT1);
  557. }
  558. #define INTEGRATOR_SC_VALID_INT 0x003fffff
  559. static void __init ap_init_irq(void)
  560. {
  561. /* Disable all interrupts initially. */
  562. /* Do the core module ones */
  563. writel(-1, VA_CMIC_BASE + IRQ_ENABLE_CLEAR);
  564. /* do the header card stuff next */
  565. writel(-1, VA_IC_BASE + IRQ_ENABLE_CLEAR);
  566. writel(-1, VA_IC_BASE + FIQ_ENABLE_CLEAR);
  567. fpga_irq_init(VA_IC_BASE, "SC", IRQ_PIC_START,
  568. -1, INTEGRATOR_SC_VALID_INT, NULL);
  569. integrator_clk_init(false);
  570. }
  571. static void __init ap_init(void)
  572. {
  573. unsigned long sc_dec;
  574. int i;
  575. platform_device_register(&cfi_flash_device);
  576. ap_syscon_base = __io_address(INTEGRATOR_SC_BASE);
  577. sc_dec = readl(ap_syscon_base + INTEGRATOR_SC_DEC_OFFSET);
  578. for (i = 0; i < 4; i++) {
  579. struct lm_device *lmdev;
  580. if ((sc_dec & (16 << i)) == 0)
  581. continue;
  582. lmdev = kzalloc(sizeof(struct lm_device), GFP_KERNEL);
  583. if (!lmdev)
  584. continue;
  585. lmdev->resource.start = 0xc0000000 + 0x10000000 * i;
  586. lmdev->resource.end = lmdev->resource.start + 0x0fffffff;
  587. lmdev->resource.flags = IORESOURCE_MEM;
  588. lmdev->irq = IRQ_AP_EXPINT0 + i;
  589. lmdev->id = i;
  590. lm_device_register(lmdev);
  591. }
  592. integrator_init(false);
  593. }
  594. MACHINE_START(INTEGRATOR, "ARM-Integrator")
  595. /* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
  596. .atag_offset = 0x100,
  597. .reserve = integrator_reserve,
  598. .map_io = ap_map_io_atag,
  599. .init_early = ap_init_early,
  600. .init_irq = ap_init_irq,
  601. .handle_irq = fpga_handle_irq,
  602. .init_time = ap_timer_init,
  603. .init_machine = ap_init,
  604. .restart = integrator_restart,
  605. MACHINE_END
  606. #endif