integrator_ap.c 18 KB

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