setup-emev2.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. /*
  2. * Emma Mobile EV2 processor support
  3. *
  4. * Copyright (C) 2012 Magnus Damm
  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; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/irqchip.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/platform_data/gpio-em.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/delay.h>
  28. #include <linux/input.h>
  29. #include <linux/io.h>
  30. #include <linux/irqchip/arm-gic.h>
  31. #include <mach/hardware.h>
  32. #include <mach/common.h>
  33. #include <mach/emev2.h>
  34. #include <mach/irqs.h>
  35. #include <asm/mach-types.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/time.h>
  39. static struct map_desc emev2_io_desc[] __initdata = {
  40. #ifdef CONFIG_SMP
  41. /* 128K entity map for 0xe0100000 (SMU) */
  42. {
  43. .virtual = 0xe0100000,
  44. .pfn = __phys_to_pfn(0xe0100000),
  45. .length = SZ_128K,
  46. .type = MT_DEVICE
  47. },
  48. /* 2M mapping for SCU + L2 controller */
  49. {
  50. .virtual = 0xf0000000,
  51. .pfn = __phys_to_pfn(0x1e000000),
  52. .length = SZ_2M,
  53. .type = MT_DEVICE
  54. },
  55. #endif
  56. };
  57. void __init emev2_map_io(void)
  58. {
  59. iotable_init(emev2_io_desc, ARRAY_SIZE(emev2_io_desc));
  60. }
  61. /* UART */
  62. static struct resource uart0_resources[] = {
  63. [0] = {
  64. .start = 0xe1020000,
  65. .end = 0xe1020037,
  66. .flags = IORESOURCE_MEM,
  67. },
  68. [1] = {
  69. .start = 40,
  70. .flags = IORESOURCE_IRQ,
  71. }
  72. };
  73. static struct platform_device uart0_device = {
  74. .name = "serial8250-em",
  75. .id = 0,
  76. .num_resources = ARRAY_SIZE(uart0_resources),
  77. .resource = uart0_resources,
  78. };
  79. static struct resource uart1_resources[] = {
  80. [0] = {
  81. .start = 0xe1030000,
  82. .end = 0xe1030037,
  83. .flags = IORESOURCE_MEM,
  84. },
  85. [1] = {
  86. .start = 41,
  87. .flags = IORESOURCE_IRQ,
  88. }
  89. };
  90. static struct platform_device uart1_device = {
  91. .name = "serial8250-em",
  92. .id = 1,
  93. .num_resources = ARRAY_SIZE(uart1_resources),
  94. .resource = uart1_resources,
  95. };
  96. static struct resource uart2_resources[] = {
  97. [0] = {
  98. .start = 0xe1040000,
  99. .end = 0xe1040037,
  100. .flags = IORESOURCE_MEM,
  101. },
  102. [1] = {
  103. .start = 42,
  104. .flags = IORESOURCE_IRQ,
  105. }
  106. };
  107. static struct platform_device uart2_device = {
  108. .name = "serial8250-em",
  109. .id = 2,
  110. .num_resources = ARRAY_SIZE(uart2_resources),
  111. .resource = uart2_resources,
  112. };
  113. static struct resource uart3_resources[] = {
  114. [0] = {
  115. .start = 0xe1050000,
  116. .end = 0xe1050037,
  117. .flags = IORESOURCE_MEM,
  118. },
  119. [1] = {
  120. .start = 43,
  121. .flags = IORESOURCE_IRQ,
  122. }
  123. };
  124. static struct platform_device uart3_device = {
  125. .name = "serial8250-em",
  126. .id = 3,
  127. .num_resources = ARRAY_SIZE(uart3_resources),
  128. .resource = uart3_resources,
  129. };
  130. /* STI */
  131. static struct resource sti_resources[] = {
  132. [0] = {
  133. .name = "STI",
  134. .start = 0xe0180000,
  135. .end = 0xe0180053,
  136. .flags = IORESOURCE_MEM,
  137. },
  138. [1] = {
  139. .start = 157,
  140. .flags = IORESOURCE_IRQ,
  141. },
  142. };
  143. static struct platform_device sti_device = {
  144. .name = "em_sti",
  145. .id = 0,
  146. .resource = sti_resources,
  147. .num_resources = ARRAY_SIZE(sti_resources),
  148. };
  149. /* GIO */
  150. static struct gpio_em_config gio0_config = {
  151. .gpio_base = 0,
  152. .irq_base = EMEV2_GPIO_IRQ(0),
  153. .number_of_pins = 32,
  154. };
  155. static struct resource gio0_resources[] = {
  156. [0] = {
  157. .name = "GIO_000",
  158. .start = 0xe0050000,
  159. .end = 0xe005002b,
  160. .flags = IORESOURCE_MEM,
  161. },
  162. [1] = {
  163. .name = "GIO_000",
  164. .start = 0xe0050040,
  165. .end = 0xe005005f,
  166. .flags = IORESOURCE_MEM,
  167. },
  168. [2] = {
  169. .start = 99,
  170. .flags = IORESOURCE_IRQ,
  171. },
  172. [3] = {
  173. .start = 100,
  174. .flags = IORESOURCE_IRQ,
  175. },
  176. };
  177. static struct platform_device gio0_device = {
  178. .name = "em_gio",
  179. .id = 0,
  180. .resource = gio0_resources,
  181. .num_resources = ARRAY_SIZE(gio0_resources),
  182. .dev = {
  183. .platform_data = &gio0_config,
  184. },
  185. };
  186. static struct gpio_em_config gio1_config = {
  187. .gpio_base = 32,
  188. .irq_base = EMEV2_GPIO_IRQ(32),
  189. .number_of_pins = 32,
  190. };
  191. static struct resource gio1_resources[] = {
  192. [0] = {
  193. .name = "GIO_032",
  194. .start = 0xe0050080,
  195. .end = 0xe00500ab,
  196. .flags = IORESOURCE_MEM,
  197. },
  198. [1] = {
  199. .name = "GIO_032",
  200. .start = 0xe00500c0,
  201. .end = 0xe00500df,
  202. .flags = IORESOURCE_MEM,
  203. },
  204. [2] = {
  205. .start = 101,
  206. .flags = IORESOURCE_IRQ,
  207. },
  208. [3] = {
  209. .start = 102,
  210. .flags = IORESOURCE_IRQ,
  211. },
  212. };
  213. static struct platform_device gio1_device = {
  214. .name = "em_gio",
  215. .id = 1,
  216. .resource = gio1_resources,
  217. .num_resources = ARRAY_SIZE(gio1_resources),
  218. .dev = {
  219. .platform_data = &gio1_config,
  220. },
  221. };
  222. static struct gpio_em_config gio2_config = {
  223. .gpio_base = 64,
  224. .irq_base = EMEV2_GPIO_IRQ(64),
  225. .number_of_pins = 32,
  226. };
  227. static struct resource gio2_resources[] = {
  228. [0] = {
  229. .name = "GIO_064",
  230. .start = 0xe0050100,
  231. .end = 0xe005012b,
  232. .flags = IORESOURCE_MEM,
  233. },
  234. [1] = {
  235. .name = "GIO_064",
  236. .start = 0xe0050140,
  237. .end = 0xe005015f,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. [2] = {
  241. .start = 103,
  242. .flags = IORESOURCE_IRQ,
  243. },
  244. [3] = {
  245. .start = 104,
  246. .flags = IORESOURCE_IRQ,
  247. },
  248. };
  249. static struct platform_device gio2_device = {
  250. .name = "em_gio",
  251. .id = 2,
  252. .resource = gio2_resources,
  253. .num_resources = ARRAY_SIZE(gio2_resources),
  254. .dev = {
  255. .platform_data = &gio2_config,
  256. },
  257. };
  258. static struct gpio_em_config gio3_config = {
  259. .gpio_base = 96,
  260. .irq_base = EMEV2_GPIO_IRQ(96),
  261. .number_of_pins = 32,
  262. };
  263. static struct resource gio3_resources[] = {
  264. [0] = {
  265. .name = "GIO_096",
  266. .start = 0xe0050100,
  267. .end = 0xe005012b,
  268. .flags = IORESOURCE_MEM,
  269. },
  270. [1] = {
  271. .name = "GIO_096",
  272. .start = 0xe0050140,
  273. .end = 0xe005015f,
  274. .flags = IORESOURCE_MEM,
  275. },
  276. [2] = {
  277. .start = 105,
  278. .flags = IORESOURCE_IRQ,
  279. },
  280. [3] = {
  281. .start = 106,
  282. .flags = IORESOURCE_IRQ,
  283. },
  284. };
  285. static struct platform_device gio3_device = {
  286. .name = "em_gio",
  287. .id = 3,
  288. .resource = gio3_resources,
  289. .num_resources = ARRAY_SIZE(gio3_resources),
  290. .dev = {
  291. .platform_data = &gio3_config,
  292. },
  293. };
  294. static struct gpio_em_config gio4_config = {
  295. .gpio_base = 128,
  296. .irq_base = EMEV2_GPIO_IRQ(128),
  297. .number_of_pins = 31,
  298. };
  299. static struct resource gio4_resources[] = {
  300. [0] = {
  301. .name = "GIO_128",
  302. .start = 0xe0050200,
  303. .end = 0xe005022b,
  304. .flags = IORESOURCE_MEM,
  305. },
  306. [1] = {
  307. .name = "GIO_128",
  308. .start = 0xe0050240,
  309. .end = 0xe005025f,
  310. .flags = IORESOURCE_MEM,
  311. },
  312. [2] = {
  313. .start = 107,
  314. .flags = IORESOURCE_IRQ,
  315. },
  316. [3] = {
  317. .start = 108,
  318. .flags = IORESOURCE_IRQ,
  319. },
  320. };
  321. static struct platform_device gio4_device = {
  322. .name = "em_gio",
  323. .id = 4,
  324. .resource = gio4_resources,
  325. .num_resources = ARRAY_SIZE(gio4_resources),
  326. .dev = {
  327. .platform_data = &gio4_config,
  328. },
  329. };
  330. static struct resource pmu_resources[] = {
  331. [0] = {
  332. .start = 152,
  333. .end = 152,
  334. .flags = IORESOURCE_IRQ,
  335. },
  336. [1] = {
  337. .start = 153,
  338. .end = 153,
  339. .flags = IORESOURCE_IRQ,
  340. },
  341. };
  342. static struct platform_device pmu_device = {
  343. .name = "arm-pmu",
  344. .id = -1,
  345. .num_resources = ARRAY_SIZE(pmu_resources),
  346. .resource = pmu_resources,
  347. };
  348. static struct platform_device *emev2_early_devices[] __initdata = {
  349. &uart0_device,
  350. &uart1_device,
  351. &uart2_device,
  352. &uart3_device,
  353. };
  354. static struct platform_device *emev2_late_devices[] __initdata = {
  355. &sti_device,
  356. &gio0_device,
  357. &gio1_device,
  358. &gio2_device,
  359. &gio3_device,
  360. &gio4_device,
  361. &pmu_device,
  362. };
  363. void __init emev2_add_standard_devices(void)
  364. {
  365. emev2_clock_init();
  366. platform_add_devices(emev2_early_devices,
  367. ARRAY_SIZE(emev2_early_devices));
  368. platform_add_devices(emev2_late_devices,
  369. ARRAY_SIZE(emev2_late_devices));
  370. }
  371. void __init emev2_init_delay(void)
  372. {
  373. shmobile_setup_delay(533, 1, 3); /* Cortex-A9 @ 533MHz */
  374. }
  375. void __init emev2_add_early_devices(void)
  376. {
  377. emev2_init_delay();
  378. early_platform_add_devices(emev2_early_devices,
  379. ARRAY_SIZE(emev2_early_devices));
  380. /* setup early console here as well */
  381. shmobile_setup_console();
  382. }
  383. void __init emev2_init_irq(void)
  384. {
  385. void __iomem *gic_dist_base;
  386. void __iomem *gic_cpu_base;
  387. /* Static mappings, never released */
  388. gic_dist_base = ioremap(0xe0028000, PAGE_SIZE);
  389. gic_cpu_base = ioremap(0xe0020000, PAGE_SIZE);
  390. BUG_ON(!gic_dist_base || !gic_cpu_base);
  391. /* Use GIC to handle interrupts */
  392. gic_init(0, 29, gic_dist_base, gic_cpu_base);
  393. }
  394. #ifdef CONFIG_USE_OF
  395. static const struct of_dev_auxdata emev2_auxdata_lookup[] __initconst = {
  396. { }
  397. };
  398. void __init emev2_add_standard_devices_dt(void)
  399. {
  400. of_platform_populate(NULL, of_default_bus_match_table,
  401. emev2_auxdata_lookup, NULL);
  402. }
  403. static const char *emev2_boards_compat_dt[] __initdata = {
  404. "renesas,emev2",
  405. NULL,
  406. };
  407. DT_MACHINE_START(EMEV2_DT, "Generic Emma Mobile EV2 (Flattened Device Tree)")
  408. .smp = smp_ops(emev2_smp_ops),
  409. .init_early = emev2_init_delay,
  410. .nr_irqs = NR_IRQS_LEGACY,
  411. .init_irq = irqchip_init,
  412. .init_machine = emev2_add_standard_devices_dt,
  413. .init_time = shmobile_timer_init,
  414. .dt_compat = emev2_boards_compat_dt,
  415. MACHINE_END
  416. #endif /* CONFIG_USE_OF */