setup-r8a7740.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. /*
  2. * R8A7740 processor support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/io.h>
  25. #include <linux/irqchip.h>
  26. #include <linux/irqchip/arm-gic.h>
  27. #include <linux/platform_data/irq-renesas-intc-irqpin.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/of_platform.h>
  30. #include <linux/serial_sci.h>
  31. #include <linux/sh_dma.h>
  32. #include <linux/sh_timer.h>
  33. #include <linux/platform_data/sh_ipmmu.h>
  34. #include <mach/dma-register.h>
  35. #include <mach/r8a7740.h>
  36. #include <mach/pm-rmobile.h>
  37. #include <mach/common.h>
  38. #include <mach/irqs.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/arch.h>
  42. #include <asm/mach/time.h>
  43. static struct map_desc r8a7740_io_desc[] __initdata = {
  44. /*
  45. * for CPGA/INTC/PFC
  46. * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
  47. */
  48. {
  49. .virtual = 0xe6000000,
  50. .pfn = __phys_to_pfn(0xe6000000),
  51. .length = 160 << 20,
  52. .type = MT_DEVICE_NONSHARED
  53. },
  54. #ifdef CONFIG_CACHE_L2X0
  55. /*
  56. * for l2x0_init()
  57. * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
  58. */
  59. {
  60. .virtual = 0xf0002000,
  61. .pfn = __phys_to_pfn(0xf0100000),
  62. .length = PAGE_SIZE,
  63. .type = MT_DEVICE_NONSHARED
  64. },
  65. #endif
  66. };
  67. void __init r8a7740_map_io(void)
  68. {
  69. iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
  70. }
  71. /* PFC */
  72. static const struct resource pfc_resources[] = {
  73. DEFINE_RES_MEM(0xe6050000, 0x8000),
  74. DEFINE_RES_MEM(0xe605800c, 0x0020),
  75. };
  76. void __init r8a7740_pinmux_init(void)
  77. {
  78. platform_device_register_simple("pfc-r8a7740", -1, pfc_resources,
  79. ARRAY_SIZE(pfc_resources));
  80. }
  81. static struct renesas_intc_irqpin_config irqpin0_platform_data = {
  82. .irq_base = irq_pin(0), /* IRQ0 -> IRQ7 */
  83. };
  84. static struct resource irqpin0_resources[] = {
  85. DEFINE_RES_MEM(0xe6900000, 4), /* ICR1A */
  86. DEFINE_RES_MEM(0xe6900010, 4), /* INTPRI00A */
  87. DEFINE_RES_MEM(0xe6900020, 1), /* INTREQ00A */
  88. DEFINE_RES_MEM(0xe6900040, 1), /* INTMSK00A */
  89. DEFINE_RES_MEM(0xe6900060, 1), /* INTMSKCLR00A */
  90. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ0 */
  91. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ1 */
  92. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ2 */
  93. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ3 */
  94. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ4 */
  95. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ5 */
  96. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ6 */
  97. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ7 */
  98. };
  99. static struct platform_device irqpin0_device = {
  100. .name = "renesas_intc_irqpin",
  101. .id = 0,
  102. .resource = irqpin0_resources,
  103. .num_resources = ARRAY_SIZE(irqpin0_resources),
  104. .dev = {
  105. .platform_data = &irqpin0_platform_data,
  106. },
  107. };
  108. static struct renesas_intc_irqpin_config irqpin1_platform_data = {
  109. .irq_base = irq_pin(8), /* IRQ8 -> IRQ15 */
  110. };
  111. static struct resource irqpin1_resources[] = {
  112. DEFINE_RES_MEM(0xe6900004, 4), /* ICR2A */
  113. DEFINE_RES_MEM(0xe6900014, 4), /* INTPRI10A */
  114. DEFINE_RES_MEM(0xe6900024, 1), /* INTREQ10A */
  115. DEFINE_RES_MEM(0xe6900044, 1), /* INTMSK10A */
  116. DEFINE_RES_MEM(0xe6900064, 1), /* INTMSKCLR10A */
  117. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ8 */
  118. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ9 */
  119. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ10 */
  120. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ11 */
  121. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ12 */
  122. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ13 */
  123. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ14 */
  124. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ15 */
  125. };
  126. static struct platform_device irqpin1_device = {
  127. .name = "renesas_intc_irqpin",
  128. .id = 1,
  129. .resource = irqpin1_resources,
  130. .num_resources = ARRAY_SIZE(irqpin1_resources),
  131. .dev = {
  132. .platform_data = &irqpin1_platform_data,
  133. },
  134. };
  135. static struct renesas_intc_irqpin_config irqpin2_platform_data = {
  136. .irq_base = irq_pin(16), /* IRQ16 -> IRQ23 */
  137. };
  138. static struct resource irqpin2_resources[] = {
  139. DEFINE_RES_MEM(0xe6900008, 4), /* ICR3A */
  140. DEFINE_RES_MEM(0xe6900018, 4), /* INTPRI30A */
  141. DEFINE_RES_MEM(0xe6900028, 1), /* INTREQ30A */
  142. DEFINE_RES_MEM(0xe6900048, 1), /* INTMSK30A */
  143. DEFINE_RES_MEM(0xe6900068, 1), /* INTMSKCLR30A */
  144. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ16 */
  145. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ17 */
  146. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ18 */
  147. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ19 */
  148. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ20 */
  149. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ21 */
  150. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ22 */
  151. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ23 */
  152. };
  153. static struct platform_device irqpin2_device = {
  154. .name = "renesas_intc_irqpin",
  155. .id = 2,
  156. .resource = irqpin2_resources,
  157. .num_resources = ARRAY_SIZE(irqpin2_resources),
  158. .dev = {
  159. .platform_data = &irqpin2_platform_data,
  160. },
  161. };
  162. static struct renesas_intc_irqpin_config irqpin3_platform_data = {
  163. .irq_base = irq_pin(24), /* IRQ24 -> IRQ31 */
  164. };
  165. static struct resource irqpin3_resources[] = {
  166. DEFINE_RES_MEM(0xe690000c, 4), /* ICR3A */
  167. DEFINE_RES_MEM(0xe690001c, 4), /* INTPRI30A */
  168. DEFINE_RES_MEM(0xe690002c, 1), /* INTREQ30A */
  169. DEFINE_RES_MEM(0xe690004c, 1), /* INTMSK30A */
  170. DEFINE_RES_MEM(0xe690006c, 1), /* INTMSKCLR30A */
  171. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ24 */
  172. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ25 */
  173. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ26 */
  174. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ27 */
  175. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ28 */
  176. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ29 */
  177. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ30 */
  178. DEFINE_RES_IRQ(gic_spi(149)), /* IRQ31 */
  179. };
  180. static struct platform_device irqpin3_device = {
  181. .name = "renesas_intc_irqpin",
  182. .id = 3,
  183. .resource = irqpin3_resources,
  184. .num_resources = ARRAY_SIZE(irqpin3_resources),
  185. .dev = {
  186. .platform_data = &irqpin3_platform_data,
  187. },
  188. };
  189. /* SCIF */
  190. #define R8A7740_SCIF(scif_type, index, baseaddr, irq) \
  191. static struct plat_sci_port scif##index##_platform_data = { \
  192. .type = scif_type, \
  193. .flags = UPF_BOOT_AUTOCONF, \
  194. .scscr = SCSCR_RE | SCSCR_TE, \
  195. }; \
  196. \
  197. static struct resource scif##index##_resources[] = { \
  198. DEFINE_RES_MEM(baseaddr, 0x100), \
  199. DEFINE_RES_IRQ(irq), \
  200. }; \
  201. \
  202. static struct platform_device scif##index##_device = { \
  203. .name = "sh-sci", \
  204. .id = index, \
  205. .resource = scif##index##_resources, \
  206. .num_resources = ARRAY_SIZE(scif##index##_resources), \
  207. .dev = { \
  208. .platform_data = &scif##index##_platform_data, \
  209. }, \
  210. }
  211. R8A7740_SCIF(PORT_SCIFA, 0, 0xe6c40000, gic_spi(100));
  212. R8A7740_SCIF(PORT_SCIFA, 1, 0xe6c50000, gic_spi(101));
  213. R8A7740_SCIF(PORT_SCIFA, 2, 0xe6c60000, gic_spi(102));
  214. R8A7740_SCIF(PORT_SCIFA, 3, 0xe6c70000, gic_spi(103));
  215. R8A7740_SCIF(PORT_SCIFA, 4, 0xe6c80000, gic_spi(104));
  216. R8A7740_SCIF(PORT_SCIFA, 5, 0xe6cb0000, gic_spi(105));
  217. R8A7740_SCIF(PORT_SCIFA, 6, 0xe6cc0000, gic_spi(106));
  218. R8A7740_SCIF(PORT_SCIFA, 7, 0xe6cd0000, gic_spi(107));
  219. R8A7740_SCIF(PORT_SCIFB, 8, 0xe6c30000, gic_spi(108));
  220. /* CMT */
  221. static struct sh_timer_config cmt10_platform_data = {
  222. .name = "CMT10",
  223. .channel_offset = 0x10,
  224. .timer_bit = 0,
  225. .clockevent_rating = 125,
  226. .clocksource_rating = 125,
  227. };
  228. static struct resource cmt10_resources[] = {
  229. [0] = {
  230. .name = "CMT10",
  231. .start = 0xe6138010,
  232. .end = 0xe613801b,
  233. .flags = IORESOURCE_MEM,
  234. },
  235. [1] = {
  236. .start = gic_spi(58),
  237. .flags = IORESOURCE_IRQ,
  238. },
  239. };
  240. static struct platform_device cmt10_device = {
  241. .name = "sh_cmt",
  242. .id = 10,
  243. .dev = {
  244. .platform_data = &cmt10_platform_data,
  245. },
  246. .resource = cmt10_resources,
  247. .num_resources = ARRAY_SIZE(cmt10_resources),
  248. };
  249. /* TMU */
  250. static struct sh_timer_config tmu00_platform_data = {
  251. .name = "TMU00",
  252. .channel_offset = 0x4,
  253. .timer_bit = 0,
  254. .clockevent_rating = 200,
  255. };
  256. static struct resource tmu00_resources[] = {
  257. [0] = {
  258. .name = "TMU00",
  259. .start = 0xfff80008,
  260. .end = 0xfff80014 - 1,
  261. .flags = IORESOURCE_MEM,
  262. },
  263. [1] = {
  264. .start = gic_spi(198),
  265. .flags = IORESOURCE_IRQ,
  266. },
  267. };
  268. static struct platform_device tmu00_device = {
  269. .name = "sh_tmu",
  270. .id = 0,
  271. .dev = {
  272. .platform_data = &tmu00_platform_data,
  273. },
  274. .resource = tmu00_resources,
  275. .num_resources = ARRAY_SIZE(tmu00_resources),
  276. };
  277. static struct sh_timer_config tmu01_platform_data = {
  278. .name = "TMU01",
  279. .channel_offset = 0x10,
  280. .timer_bit = 1,
  281. .clocksource_rating = 200,
  282. };
  283. static struct resource tmu01_resources[] = {
  284. [0] = {
  285. .name = "TMU01",
  286. .start = 0xfff80014,
  287. .end = 0xfff80020 - 1,
  288. .flags = IORESOURCE_MEM,
  289. },
  290. [1] = {
  291. .start = gic_spi(199),
  292. .flags = IORESOURCE_IRQ,
  293. },
  294. };
  295. static struct platform_device tmu01_device = {
  296. .name = "sh_tmu",
  297. .id = 1,
  298. .dev = {
  299. .platform_data = &tmu01_platform_data,
  300. },
  301. .resource = tmu01_resources,
  302. .num_resources = ARRAY_SIZE(tmu01_resources),
  303. };
  304. static struct sh_timer_config tmu02_platform_data = {
  305. .name = "TMU02",
  306. .channel_offset = 0x1C,
  307. .timer_bit = 2,
  308. .clocksource_rating = 200,
  309. };
  310. static struct resource tmu02_resources[] = {
  311. [0] = {
  312. .name = "TMU02",
  313. .start = 0xfff80020,
  314. .end = 0xfff8002C - 1,
  315. .flags = IORESOURCE_MEM,
  316. },
  317. [1] = {
  318. .start = gic_spi(200),
  319. .flags = IORESOURCE_IRQ,
  320. },
  321. };
  322. static struct platform_device tmu02_device = {
  323. .name = "sh_tmu",
  324. .id = 2,
  325. .dev = {
  326. .platform_data = &tmu02_platform_data,
  327. },
  328. .resource = tmu02_resources,
  329. .num_resources = ARRAY_SIZE(tmu02_resources),
  330. };
  331. /* IPMMUI (an IPMMU module for ICB/LMB) */
  332. static struct resource ipmmu_resources[] = {
  333. [0] = {
  334. .name = "IPMMUI",
  335. .start = 0xfe951000,
  336. .end = 0xfe9510ff,
  337. .flags = IORESOURCE_MEM,
  338. },
  339. };
  340. static const char * const ipmmu_dev_names[] = {
  341. "sh_mobile_lcdc_fb.0",
  342. "sh_mobile_lcdc_fb.1",
  343. "sh_mobile_ceu.0",
  344. };
  345. static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
  346. .dev_names = ipmmu_dev_names,
  347. .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
  348. };
  349. static struct platform_device ipmmu_device = {
  350. .name = "ipmmu",
  351. .id = -1,
  352. .dev = {
  353. .platform_data = &ipmmu_platform_data,
  354. },
  355. .resource = ipmmu_resources,
  356. .num_resources = ARRAY_SIZE(ipmmu_resources),
  357. };
  358. static struct platform_device *r8a7740_devices_dt[] __initdata = {
  359. &scif0_device,
  360. &scif1_device,
  361. &scif2_device,
  362. &scif3_device,
  363. &scif4_device,
  364. &scif5_device,
  365. &scif6_device,
  366. &scif7_device,
  367. &scif8_device,
  368. &cmt10_device,
  369. };
  370. static struct platform_device *r8a7740_early_devices[] __initdata = {
  371. &irqpin0_device,
  372. &irqpin1_device,
  373. &irqpin2_device,
  374. &irqpin3_device,
  375. &tmu00_device,
  376. &tmu01_device,
  377. &tmu02_device,
  378. &ipmmu_device,
  379. };
  380. /* DMA */
  381. static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
  382. {
  383. .slave_id = SHDMA_SLAVE_SDHI0_TX,
  384. .addr = 0xe6850030,
  385. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  386. .mid_rid = 0xc1,
  387. }, {
  388. .slave_id = SHDMA_SLAVE_SDHI0_RX,
  389. .addr = 0xe6850030,
  390. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  391. .mid_rid = 0xc2,
  392. }, {
  393. .slave_id = SHDMA_SLAVE_SDHI1_TX,
  394. .addr = 0xe6860030,
  395. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  396. .mid_rid = 0xc9,
  397. }, {
  398. .slave_id = SHDMA_SLAVE_SDHI1_RX,
  399. .addr = 0xe6860030,
  400. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  401. .mid_rid = 0xca,
  402. }, {
  403. .slave_id = SHDMA_SLAVE_SDHI2_TX,
  404. .addr = 0xe6870030,
  405. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  406. .mid_rid = 0xcd,
  407. }, {
  408. .slave_id = SHDMA_SLAVE_SDHI2_RX,
  409. .addr = 0xe6870030,
  410. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  411. .mid_rid = 0xce,
  412. }, {
  413. .slave_id = SHDMA_SLAVE_FSIA_TX,
  414. .addr = 0xfe1f0024,
  415. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  416. .mid_rid = 0xb1,
  417. }, {
  418. .slave_id = SHDMA_SLAVE_FSIA_RX,
  419. .addr = 0xfe1f0020,
  420. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  421. .mid_rid = 0xb2,
  422. }, {
  423. .slave_id = SHDMA_SLAVE_FSIB_TX,
  424. .addr = 0xfe1f0064,
  425. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  426. .mid_rid = 0xb5,
  427. }, {
  428. .slave_id = SHDMA_SLAVE_MMCIF_TX,
  429. .addr = 0xe6bd0034,
  430. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  431. .mid_rid = 0xd1,
  432. }, {
  433. .slave_id = SHDMA_SLAVE_MMCIF_RX,
  434. .addr = 0xe6bd0034,
  435. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  436. .mid_rid = 0xd2,
  437. },
  438. };
  439. #define DMA_CHANNEL(a, b, c) \
  440. { \
  441. .offset = a, \
  442. .dmars = b, \
  443. .dmars_bit = c, \
  444. .chclr_offset = (0x220 - 0x20) + a \
  445. }
  446. static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
  447. DMA_CHANNEL(0x00, 0, 0),
  448. DMA_CHANNEL(0x10, 0, 8),
  449. DMA_CHANNEL(0x20, 4, 0),
  450. DMA_CHANNEL(0x30, 4, 8),
  451. DMA_CHANNEL(0x50, 8, 0),
  452. DMA_CHANNEL(0x60, 8, 8),
  453. };
  454. static struct sh_dmae_pdata dma_platform_data = {
  455. .slave = r8a7740_dmae_slaves,
  456. .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
  457. .channel = r8a7740_dmae_channels,
  458. .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
  459. .ts_low_shift = TS_LOW_SHIFT,
  460. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  461. .ts_high_shift = TS_HI_SHIFT,
  462. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  463. .ts_shift = dma_ts_shift,
  464. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  465. .dmaor_init = DMAOR_DME,
  466. .chclr_present = 1,
  467. };
  468. /* Resource order important! */
  469. static struct resource r8a7740_dmae0_resources[] = {
  470. {
  471. /* Channel registers and DMAOR */
  472. .start = 0xfe008020,
  473. .end = 0xfe00828f,
  474. .flags = IORESOURCE_MEM,
  475. },
  476. {
  477. /* DMARSx */
  478. .start = 0xfe009000,
  479. .end = 0xfe00900b,
  480. .flags = IORESOURCE_MEM,
  481. },
  482. {
  483. .name = "error_irq",
  484. .start = gic_spi(34),
  485. .end = gic_spi(34),
  486. .flags = IORESOURCE_IRQ,
  487. },
  488. {
  489. /* IRQ for channels 0-5 */
  490. .start = gic_spi(28),
  491. .end = gic_spi(33),
  492. .flags = IORESOURCE_IRQ,
  493. },
  494. };
  495. /* Resource order important! */
  496. static struct resource r8a7740_dmae1_resources[] = {
  497. {
  498. /* Channel registers and DMAOR */
  499. .start = 0xfe018020,
  500. .end = 0xfe01828f,
  501. .flags = IORESOURCE_MEM,
  502. },
  503. {
  504. /* DMARSx */
  505. .start = 0xfe019000,
  506. .end = 0xfe01900b,
  507. .flags = IORESOURCE_MEM,
  508. },
  509. {
  510. .name = "error_irq",
  511. .start = gic_spi(41),
  512. .end = gic_spi(41),
  513. .flags = IORESOURCE_IRQ,
  514. },
  515. {
  516. /* IRQ for channels 0-5 */
  517. .start = gic_spi(35),
  518. .end = gic_spi(40),
  519. .flags = IORESOURCE_IRQ,
  520. },
  521. };
  522. /* Resource order important! */
  523. static struct resource r8a7740_dmae2_resources[] = {
  524. {
  525. /* Channel registers and DMAOR */
  526. .start = 0xfe028020,
  527. .end = 0xfe02828f,
  528. .flags = IORESOURCE_MEM,
  529. },
  530. {
  531. /* DMARSx */
  532. .start = 0xfe029000,
  533. .end = 0xfe02900b,
  534. .flags = IORESOURCE_MEM,
  535. },
  536. {
  537. .name = "error_irq",
  538. .start = gic_spi(48),
  539. .end = gic_spi(48),
  540. .flags = IORESOURCE_IRQ,
  541. },
  542. {
  543. /* IRQ for channels 0-5 */
  544. .start = gic_spi(42),
  545. .end = gic_spi(47),
  546. .flags = IORESOURCE_IRQ,
  547. },
  548. };
  549. static struct platform_device dma0_device = {
  550. .name = "sh-dma-engine",
  551. .id = 0,
  552. .resource = r8a7740_dmae0_resources,
  553. .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
  554. .dev = {
  555. .platform_data = &dma_platform_data,
  556. },
  557. };
  558. static struct platform_device dma1_device = {
  559. .name = "sh-dma-engine",
  560. .id = 1,
  561. .resource = r8a7740_dmae1_resources,
  562. .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
  563. .dev = {
  564. .platform_data = &dma_platform_data,
  565. },
  566. };
  567. static struct platform_device dma2_device = {
  568. .name = "sh-dma-engine",
  569. .id = 2,
  570. .resource = r8a7740_dmae2_resources,
  571. .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
  572. .dev = {
  573. .platform_data = &dma_platform_data,
  574. },
  575. };
  576. /* USB-DMAC */
  577. static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
  578. {
  579. .offset = 0,
  580. }, {
  581. .offset = 0x20,
  582. },
  583. };
  584. static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
  585. {
  586. .slave_id = SHDMA_SLAVE_USBHS_TX,
  587. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  588. }, {
  589. .slave_id = SHDMA_SLAVE_USBHS_RX,
  590. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  591. },
  592. };
  593. static struct sh_dmae_pdata usb_dma_platform_data = {
  594. .slave = r8a7740_usb_dma_slaves,
  595. .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
  596. .channel = r8a7740_usb_dma_channels,
  597. .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
  598. .ts_low_shift = USBTS_LOW_SHIFT,
  599. .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
  600. .ts_high_shift = USBTS_HI_SHIFT,
  601. .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
  602. .ts_shift = dma_usbts_shift,
  603. .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
  604. .dmaor_init = DMAOR_DME,
  605. .chcr_offset = 0x14,
  606. .chcr_ie_bit = 1 << 5,
  607. .dmaor_is_32bit = 1,
  608. .needs_tend_set = 1,
  609. .no_dmars = 1,
  610. .slave_only = 1,
  611. };
  612. static struct resource r8a7740_usb_dma_resources[] = {
  613. {
  614. /* Channel registers and DMAOR */
  615. .start = 0xe68a0020,
  616. .end = 0xe68a0064 - 1,
  617. .flags = IORESOURCE_MEM,
  618. },
  619. {
  620. /* VCR/SWR/DMICR */
  621. .start = 0xe68a0000,
  622. .end = 0xe68a0014 - 1,
  623. .flags = IORESOURCE_MEM,
  624. },
  625. {
  626. /* IRQ for channels */
  627. .start = gic_spi(49),
  628. .end = gic_spi(49),
  629. .flags = IORESOURCE_IRQ,
  630. },
  631. };
  632. static struct platform_device usb_dma_device = {
  633. .name = "sh-dma-engine",
  634. .id = 3,
  635. .resource = r8a7740_usb_dma_resources,
  636. .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
  637. .dev = {
  638. .platform_data = &usb_dma_platform_data,
  639. },
  640. };
  641. /* I2C */
  642. static struct resource i2c0_resources[] = {
  643. [0] = {
  644. .name = "IIC0",
  645. .start = 0xfff20000,
  646. .end = 0xfff20425 - 1,
  647. .flags = IORESOURCE_MEM,
  648. },
  649. [1] = {
  650. .start = gic_spi(201),
  651. .end = gic_spi(204),
  652. .flags = IORESOURCE_IRQ,
  653. },
  654. };
  655. static struct resource i2c1_resources[] = {
  656. [0] = {
  657. .name = "IIC1",
  658. .start = 0xe6c20000,
  659. .end = 0xe6c20425 - 1,
  660. .flags = IORESOURCE_MEM,
  661. },
  662. [1] = {
  663. .start = gic_spi(70), /* IIC1_ALI1 */
  664. .end = gic_spi(73), /* IIC1_DTEI1 */
  665. .flags = IORESOURCE_IRQ,
  666. },
  667. };
  668. static struct platform_device i2c0_device = {
  669. .name = "i2c-sh_mobile",
  670. .id = 0,
  671. .resource = i2c0_resources,
  672. .num_resources = ARRAY_SIZE(i2c0_resources),
  673. };
  674. static struct platform_device i2c1_device = {
  675. .name = "i2c-sh_mobile",
  676. .id = 1,
  677. .resource = i2c1_resources,
  678. .num_resources = ARRAY_SIZE(i2c1_resources),
  679. };
  680. static struct resource pmu_resources[] = {
  681. [0] = {
  682. .start = gic_spi(83),
  683. .end = gic_spi(83),
  684. .flags = IORESOURCE_IRQ,
  685. },
  686. };
  687. static struct platform_device pmu_device = {
  688. .name = "arm-pmu",
  689. .id = -1,
  690. .num_resources = ARRAY_SIZE(pmu_resources),
  691. .resource = pmu_resources,
  692. };
  693. static struct platform_device *r8a7740_late_devices[] __initdata = {
  694. &i2c0_device,
  695. &i2c1_device,
  696. &dma0_device,
  697. &dma1_device,
  698. &dma2_device,
  699. &usb_dma_device,
  700. &pmu_device,
  701. };
  702. /*
  703. * r8a7740 chip has lasting errata on MERAM buffer.
  704. * this is work-around for it.
  705. * see
  706. * "Media RAM (MERAM)" on r8a7740 documentation
  707. */
  708. #define MEBUFCNTR 0xFE950098
  709. void r8a7740_meram_workaround(void)
  710. {
  711. void __iomem *reg;
  712. reg = ioremap_nocache(MEBUFCNTR, 4);
  713. if (reg) {
  714. iowrite32(0x01600164, reg);
  715. iounmap(reg);
  716. }
  717. }
  718. #define ICCR 0x0004
  719. #define ICSTART 0x0070
  720. #define i2c_read(reg, offset) ioread8(reg + offset)
  721. #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
  722. /*
  723. * r8a7740 chip has lasting errata on I2C I/O pad reset.
  724. * this is work-around for it.
  725. */
  726. static void r8a7740_i2c_workaround(struct platform_device *pdev)
  727. {
  728. struct resource *res;
  729. void __iomem *reg;
  730. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  731. if (unlikely(!res)) {
  732. pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
  733. return;
  734. }
  735. reg = ioremap(res->start, resource_size(res));
  736. if (unlikely(!reg)) {
  737. pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
  738. return;
  739. }
  740. i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
  741. i2c_read(reg, ICCR); /* dummy read */
  742. i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
  743. i2c_read(reg, ICSTART); /* dummy read */
  744. udelay(10);
  745. i2c_write(reg, ICCR, 0x01);
  746. i2c_write(reg, ICSTART, 0x00);
  747. udelay(10);
  748. i2c_write(reg, ICCR, 0x10);
  749. udelay(10);
  750. i2c_write(reg, ICCR, 0x00);
  751. udelay(10);
  752. i2c_write(reg, ICCR, 0x10);
  753. udelay(10);
  754. iounmap(reg);
  755. }
  756. void __init r8a7740_add_standard_devices(void)
  757. {
  758. /* I2C work-around */
  759. r8a7740_i2c_workaround(&i2c0_device);
  760. r8a7740_i2c_workaround(&i2c1_device);
  761. r8a7740_init_pm_domains();
  762. /* add devices */
  763. platform_add_devices(r8a7740_early_devices,
  764. ARRAY_SIZE(r8a7740_early_devices));
  765. platform_add_devices(r8a7740_devices_dt,
  766. ARRAY_SIZE(r8a7740_devices_dt));
  767. platform_add_devices(r8a7740_late_devices,
  768. ARRAY_SIZE(r8a7740_late_devices));
  769. /* add devices to PM domain */
  770. rmobile_add_device_to_domain("A3SP", &scif0_device);
  771. rmobile_add_device_to_domain("A3SP", &scif1_device);
  772. rmobile_add_device_to_domain("A3SP", &scif2_device);
  773. rmobile_add_device_to_domain("A3SP", &scif3_device);
  774. rmobile_add_device_to_domain("A3SP", &scif4_device);
  775. rmobile_add_device_to_domain("A3SP", &scif5_device);
  776. rmobile_add_device_to_domain("A3SP", &scif6_device);
  777. rmobile_add_device_to_domain("A3SP", &scif7_device);
  778. rmobile_add_device_to_domain("A3SP", &scif8_device);
  779. rmobile_add_device_to_domain("A3SP", &i2c1_device);
  780. }
  781. void __init r8a7740_add_early_devices(void)
  782. {
  783. early_platform_add_devices(r8a7740_early_devices,
  784. ARRAY_SIZE(r8a7740_early_devices));
  785. early_platform_add_devices(r8a7740_devices_dt,
  786. ARRAY_SIZE(r8a7740_devices_dt));
  787. /* setup early console here as well */
  788. shmobile_setup_console();
  789. }
  790. #ifdef CONFIG_USE_OF
  791. void __init r8a7740_add_early_devices_dt(void)
  792. {
  793. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  794. early_platform_add_devices(r8a7740_early_devices,
  795. ARRAY_SIZE(r8a7740_early_devices));
  796. /* setup early console here as well */
  797. shmobile_setup_console();
  798. }
  799. void __init r8a7740_add_standard_devices_dt(void)
  800. {
  801. platform_add_devices(r8a7740_devices_dt,
  802. ARRAY_SIZE(r8a7740_devices_dt));
  803. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  804. }
  805. void __init r8a7740_init_delay(void)
  806. {
  807. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  808. };
  809. void __init r8a7740_init_irq_of(void)
  810. {
  811. void __iomem *intc_prio_base = ioremap_nocache(0xe6900010, 0x10);
  812. void __iomem *intc_msk_base = ioremap_nocache(0xe6900040, 0x10);
  813. void __iomem *pfc_inta_ctrl = ioremap_nocache(0xe605807c, 0x4);
  814. irqchip_init();
  815. /* route signals to GIC */
  816. iowrite32(0x0, pfc_inta_ctrl);
  817. /*
  818. * To mask the shared interrupt to SPI 149 we must ensure to set
  819. * PRIO *and* MASK. Else we run into IRQ floods when registering
  820. * the intc_irqpin devices
  821. */
  822. iowrite32(0x0, intc_prio_base + 0x0);
  823. iowrite32(0x0, intc_prio_base + 0x4);
  824. iowrite32(0x0, intc_prio_base + 0x8);
  825. iowrite32(0x0, intc_prio_base + 0xc);
  826. iowrite8(0xff, intc_msk_base + 0x0);
  827. iowrite8(0xff, intc_msk_base + 0x4);
  828. iowrite8(0xff, intc_msk_base + 0x8);
  829. iowrite8(0xff, intc_msk_base + 0xc);
  830. iounmap(intc_prio_base);
  831. iounmap(intc_msk_base);
  832. iounmap(pfc_inta_ctrl);
  833. }
  834. static void __init r8a7740_generic_init(void)
  835. {
  836. r8a7740_clock_init(0);
  837. r8a7740_add_standard_devices_dt();
  838. }
  839. static const char *r8a7740_boards_compat_dt[] __initdata = {
  840. "renesas,r8a7740",
  841. NULL,
  842. };
  843. DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
  844. .map_io = r8a7740_map_io,
  845. .init_early = r8a7740_init_delay,
  846. .init_irq = r8a7740_init_irq_of,
  847. .init_machine = r8a7740_generic_init,
  848. .dt_compat = r8a7740_boards_compat_dt,
  849. MACHINE_END
  850. #endif /* CONFIG_USE_OF */