v2m.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * Versatile Express V2M Motherboard Support
  3. */
  4. #include <linux/device.h>
  5. #include <linux/amba/bus.h>
  6. #include <linux/amba/mmci.h>
  7. #include <linux/io.h>
  8. #include <linux/smp.h>
  9. #include <linux/init.h>
  10. #include <linux/irqchip.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_fdt.h>
  13. #include <linux/of_irq.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/ata_platform.h>
  17. #include <linux/smsc911x.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/usb/isp1760.h>
  20. #include <linux/mtd/physmap.h>
  21. #include <linux/regulator/fixed.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/vexpress.h>
  24. #include <asm/arch_timer.h>
  25. #include <asm/mach-types.h>
  26. #include <asm/sizes.h>
  27. #include <asm/smp_twd.h>
  28. #include <asm/mach/arch.h>
  29. #include <asm/mach/map.h>
  30. #include <asm/mach/time.h>
  31. #include <asm/hardware/arm_timer.h>
  32. #include <asm/hardware/cache-l2x0.h>
  33. #include <asm/hardware/timer-sp.h>
  34. #include <mach/ct-ca9x4.h>
  35. #include <mach/motherboard.h>
  36. #include <plat/sched_clock.h>
  37. #include <plat/platsmp.h>
  38. #include "core.h"
  39. #define V2M_PA_CS0 0x40000000
  40. #define V2M_PA_CS1 0x44000000
  41. #define V2M_PA_CS2 0x48000000
  42. #define V2M_PA_CS3 0x4c000000
  43. #define V2M_PA_CS7 0x10000000
  44. static struct map_desc v2m_io_desc[] __initdata = {
  45. {
  46. .virtual = V2M_PERIPH,
  47. .pfn = __phys_to_pfn(V2M_PA_CS7),
  48. .length = SZ_128K,
  49. .type = MT_DEVICE,
  50. },
  51. };
  52. static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
  53. {
  54. if (WARN_ON(!base || irq == NO_IRQ))
  55. return;
  56. writel(0, base + TIMER_1_BASE + TIMER_CTRL);
  57. writel(0, base + TIMER_2_BASE + TIMER_CTRL);
  58. sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
  59. sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
  60. }
  61. static struct resource v2m_pcie_i2c_resource = {
  62. .start = V2M_SERIAL_BUS_PCI,
  63. .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
  64. .flags = IORESOURCE_MEM,
  65. };
  66. static struct platform_device v2m_pcie_i2c_device = {
  67. .name = "versatile-i2c",
  68. .id = 0,
  69. .num_resources = 1,
  70. .resource = &v2m_pcie_i2c_resource,
  71. };
  72. static struct resource v2m_ddc_i2c_resource = {
  73. .start = V2M_SERIAL_BUS_DVI,
  74. .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
  75. .flags = IORESOURCE_MEM,
  76. };
  77. static struct platform_device v2m_ddc_i2c_device = {
  78. .name = "versatile-i2c",
  79. .id = 1,
  80. .num_resources = 1,
  81. .resource = &v2m_ddc_i2c_resource,
  82. };
  83. static struct resource v2m_eth_resources[] = {
  84. {
  85. .start = V2M_LAN9118,
  86. .end = V2M_LAN9118 + SZ_64K - 1,
  87. .flags = IORESOURCE_MEM,
  88. }, {
  89. .start = IRQ_V2M_LAN9118,
  90. .end = IRQ_V2M_LAN9118,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. };
  94. static struct smsc911x_platform_config v2m_eth_config = {
  95. .flags = SMSC911X_USE_32BIT,
  96. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
  97. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  98. .phy_interface = PHY_INTERFACE_MODE_MII,
  99. };
  100. static struct platform_device v2m_eth_device = {
  101. .name = "smsc911x",
  102. .id = -1,
  103. .resource = v2m_eth_resources,
  104. .num_resources = ARRAY_SIZE(v2m_eth_resources),
  105. .dev.platform_data = &v2m_eth_config,
  106. };
  107. static struct regulator_consumer_supply v2m_eth_supplies[] = {
  108. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  109. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  110. };
  111. static struct resource v2m_usb_resources[] = {
  112. {
  113. .start = V2M_ISP1761,
  114. .end = V2M_ISP1761 + SZ_128K - 1,
  115. .flags = IORESOURCE_MEM,
  116. }, {
  117. .start = IRQ_V2M_ISP1761,
  118. .end = IRQ_V2M_ISP1761,
  119. .flags = IORESOURCE_IRQ,
  120. },
  121. };
  122. static struct isp1760_platform_data v2m_usb_config = {
  123. .is_isp1761 = true,
  124. .bus_width_16 = false,
  125. .port1_otg = true,
  126. .analog_oc = false,
  127. .dack_polarity_high = false,
  128. .dreq_polarity_high = false,
  129. };
  130. static struct platform_device v2m_usb_device = {
  131. .name = "isp1760",
  132. .id = -1,
  133. .resource = v2m_usb_resources,
  134. .num_resources = ARRAY_SIZE(v2m_usb_resources),
  135. .dev.platform_data = &v2m_usb_config,
  136. };
  137. static struct physmap_flash_data v2m_flash_data = {
  138. .width = 4,
  139. };
  140. static struct resource v2m_flash_resources[] = {
  141. {
  142. .start = V2M_NOR0,
  143. .end = V2M_NOR0 + SZ_64M - 1,
  144. .flags = IORESOURCE_MEM,
  145. }, {
  146. .start = V2M_NOR1,
  147. .end = V2M_NOR1 + SZ_64M - 1,
  148. .flags = IORESOURCE_MEM,
  149. },
  150. };
  151. static struct platform_device v2m_flash_device = {
  152. .name = "physmap-flash",
  153. .id = -1,
  154. .resource = v2m_flash_resources,
  155. .num_resources = ARRAY_SIZE(v2m_flash_resources),
  156. .dev.platform_data = &v2m_flash_data,
  157. };
  158. static struct pata_platform_info v2m_pata_data = {
  159. .ioport_shift = 2,
  160. };
  161. static struct resource v2m_pata_resources[] = {
  162. {
  163. .start = V2M_CF,
  164. .end = V2M_CF + 0xff,
  165. .flags = IORESOURCE_MEM,
  166. }, {
  167. .start = V2M_CF + 0x100,
  168. .end = V2M_CF + SZ_4K - 1,
  169. .flags = IORESOURCE_MEM,
  170. },
  171. };
  172. static struct platform_device v2m_cf_device = {
  173. .name = "pata_platform",
  174. .id = -1,
  175. .resource = v2m_pata_resources,
  176. .num_resources = ARRAY_SIZE(v2m_pata_resources),
  177. .dev.platform_data = &v2m_pata_data,
  178. };
  179. static struct mmci_platform_data v2m_mmci_data = {
  180. .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
  181. .gpio_wp = VEXPRESS_GPIO_MMC_WPROT,
  182. .gpio_cd = VEXPRESS_GPIO_MMC_CARDIN,
  183. };
  184. static struct resource v2m_sysreg_resources[] = {
  185. {
  186. .start = V2M_SYSREGS,
  187. .end = V2M_SYSREGS + 0xfff,
  188. .flags = IORESOURCE_MEM,
  189. },
  190. };
  191. static struct platform_device v2m_sysreg_device = {
  192. .name = "vexpress-sysreg",
  193. .id = -1,
  194. .resource = v2m_sysreg_resources,
  195. .num_resources = ARRAY_SIZE(v2m_sysreg_resources),
  196. };
  197. static struct platform_device v2m_muxfpga_device = {
  198. .name = "vexpress-muxfpga",
  199. .id = 0,
  200. .num_resources = 1,
  201. .resource = (struct resource []) {
  202. VEXPRESS_RES_FUNC(0, 7),
  203. }
  204. };
  205. static struct platform_device v2m_shutdown_device = {
  206. .name = "vexpress-shutdown",
  207. .id = 0,
  208. .num_resources = 1,
  209. .resource = (struct resource []) {
  210. VEXPRESS_RES_FUNC(0, 8),
  211. }
  212. };
  213. static struct platform_device v2m_reboot_device = {
  214. .name = "vexpress-reboot",
  215. .id = 0,
  216. .num_resources = 1,
  217. .resource = (struct resource []) {
  218. VEXPRESS_RES_FUNC(0, 9),
  219. }
  220. };
  221. static struct platform_device v2m_dvimode_device = {
  222. .name = "vexpress-dvimode",
  223. .id = 0,
  224. .num_resources = 1,
  225. .resource = (struct resource []) {
  226. VEXPRESS_RES_FUNC(0, 11),
  227. }
  228. };
  229. static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL);
  230. static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
  231. static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
  232. static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
  233. static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
  234. static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
  235. static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
  236. static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
  237. static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL);
  238. static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL);
  239. static struct amba_device *v2m_amba_devs[] __initdata = {
  240. &aaci_device,
  241. &mmci_device,
  242. &kmi0_device,
  243. &kmi1_device,
  244. &uart0_device,
  245. &uart1_device,
  246. &uart2_device,
  247. &uart3_device,
  248. &wdt_device,
  249. &rtc_device,
  250. };
  251. static void __init v2m_timer_init(void)
  252. {
  253. vexpress_clk_init(ioremap(V2M_SYSCTL, SZ_4K));
  254. v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
  255. }
  256. static void __init v2m_init_early(void)
  257. {
  258. if (ct_desc->init_early)
  259. ct_desc->init_early();
  260. versatile_sched_clock_init(vexpress_get_24mhz_clock_base(), 24000000);
  261. }
  262. struct ct_desc *ct_desc;
  263. static struct ct_desc *ct_descs[] __initdata = {
  264. #ifdef CONFIG_ARCH_VEXPRESS_CA9X4
  265. &ct_ca9x4_desc,
  266. #endif
  267. };
  268. static void __init v2m_populate_ct_desc(void)
  269. {
  270. int i;
  271. u32 current_tile_id;
  272. ct_desc = NULL;
  273. current_tile_id = vexpress_get_procid(VEXPRESS_SITE_MASTER)
  274. & V2M_CT_ID_MASK;
  275. for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
  276. if (ct_descs[i]->id == current_tile_id)
  277. ct_desc = ct_descs[i];
  278. if (!ct_desc)
  279. panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
  280. "You may need a device tree blob or a different kernel to boot on this board.\n",
  281. current_tile_id);
  282. }
  283. static void __init v2m_map_io(void)
  284. {
  285. iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
  286. vexpress_sysreg_early_init(ioremap(V2M_SYSREGS, SZ_4K));
  287. v2m_populate_ct_desc();
  288. ct_desc->map_io();
  289. }
  290. static void __init v2m_init_irq(void)
  291. {
  292. ct_desc->init_irq();
  293. }
  294. static void __init v2m_init(void)
  295. {
  296. int i;
  297. regulator_register_fixed(0, v2m_eth_supplies,
  298. ARRAY_SIZE(v2m_eth_supplies));
  299. platform_device_register(&v2m_muxfpga_device);
  300. platform_device_register(&v2m_shutdown_device);
  301. platform_device_register(&v2m_reboot_device);
  302. platform_device_register(&v2m_dvimode_device);
  303. platform_device_register(&v2m_sysreg_device);
  304. platform_device_register(&v2m_pcie_i2c_device);
  305. platform_device_register(&v2m_ddc_i2c_device);
  306. platform_device_register(&v2m_flash_device);
  307. platform_device_register(&v2m_cf_device);
  308. platform_device_register(&v2m_eth_device);
  309. platform_device_register(&v2m_usb_device);
  310. for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
  311. amba_device_register(v2m_amba_devs[i], &iomem_resource);
  312. pm_power_off = vexpress_power_off;
  313. ct_desc->init_tile();
  314. }
  315. MACHINE_START(VEXPRESS, "ARM-Versatile Express")
  316. .atag_offset = 0x100,
  317. .smp = smp_ops(vexpress_smp_ops),
  318. .map_io = v2m_map_io,
  319. .init_early = v2m_init_early,
  320. .init_irq = v2m_init_irq,
  321. .init_time = v2m_timer_init,
  322. .init_machine = v2m_init,
  323. .restart = vexpress_restart,
  324. MACHINE_END
  325. static struct map_desc v2m_rs1_io_desc __initdata = {
  326. .virtual = V2M_PERIPH,
  327. .pfn = __phys_to_pfn(0x1c000000),
  328. .length = SZ_2M,
  329. .type = MT_DEVICE,
  330. };
  331. static int __init v2m_dt_scan_memory_map(unsigned long node, const char *uname,
  332. int depth, void *data)
  333. {
  334. const char **map = data;
  335. if (strcmp(uname, "motherboard") != 0)
  336. return 0;
  337. *map = of_get_flat_dt_prop(node, "arm,v2m-memory-map", NULL);
  338. return 1;
  339. }
  340. void __init v2m_dt_map_io(void)
  341. {
  342. const char *map = NULL;
  343. of_scan_flat_dt(v2m_dt_scan_memory_map, &map);
  344. if (map && strcmp(map, "rs1") == 0)
  345. iotable_init(&v2m_rs1_io_desc, 1);
  346. else
  347. iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
  348. #if defined(CONFIG_SMP)
  349. vexpress_dt_smp_map_io();
  350. #endif
  351. }
  352. void __init v2m_dt_init_early(void)
  353. {
  354. u32 dt_hbi;
  355. vexpress_sysreg_of_early_init();
  356. /* Confirm board type against DT property, if available */
  357. if (of_property_read_u32(of_allnodes, "arm,hbi", &dt_hbi) == 0) {
  358. u32 hbi = vexpress_get_hbi(VEXPRESS_SITE_MASTER);
  359. if (WARN_ON(dt_hbi != hbi))
  360. pr_warning("vexpress: DT HBI (%x) is not matching "
  361. "hardware (%x)!\n", dt_hbi, hbi);
  362. }
  363. }
  364. static void __init v2m_dt_timer_init(void)
  365. {
  366. struct device_node *node = NULL;
  367. vexpress_clk_of_init();
  368. do {
  369. node = of_find_compatible_node(node, NULL, "arm,sp804");
  370. } while (node && vexpress_get_site_by_node(node) != VEXPRESS_SITE_MB);
  371. if (node) {
  372. pr_info("Using SP804 '%s' as a clock & events source\n",
  373. node->full_name);
  374. v2m_sp804_init(of_iomap(node, 0),
  375. irq_of_parse_and_map(node, 0));
  376. }
  377. if (arch_timer_of_register() != 0)
  378. twd_local_timer_of_register();
  379. if (arch_timer_sched_clock_init() != 0)
  380. versatile_sched_clock_init(vexpress_get_24mhz_clock_base(),
  381. 24000000);
  382. }
  383. static const struct of_device_id v2m_dt_bus_match[] __initconst = {
  384. { .compatible = "simple-bus", },
  385. { .compatible = "arm,amba-bus", },
  386. { .compatible = "arm,vexpress,config-bus", },
  387. {}
  388. };
  389. static void __init v2m_dt_init(void)
  390. {
  391. l2x0_of_init(0x00400000, 0xfe0fffff);
  392. of_platform_populate(NULL, v2m_dt_bus_match, NULL, NULL);
  393. pm_power_off = vexpress_power_off;
  394. }
  395. static const char * const v2m_dt_match[] __initconst = {
  396. "arm,vexpress",
  397. "xen,xenvm",
  398. NULL,
  399. };
  400. DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
  401. .dt_compat = v2m_dt_match,
  402. .smp = smp_ops(vexpress_smp_ops),
  403. .map_io = v2m_dt_map_io,
  404. .init_early = v2m_dt_init_early,
  405. .init_irq = irqchip_init,
  406. .init_time = v2m_dt_timer_init,
  407. .init_machine = v2m_dt_init,
  408. .restart = vexpress_restart,
  409. MACHINE_END