setup-r8a7740.c 21 KB

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