v2m.c 12 KB

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