v2m.c 11 KB

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