setup-r8a7740.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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 <asm/mach-types.h>
  35. #include <asm/mach/map.h>
  36. #include <asm/mach/arch.h>
  37. #include <asm/mach/time.h>
  38. #include "common.h"
  39. #include "dma-register.h"
  40. #include "irqs.h"
  41. #include "pm-rmobile.h"
  42. #include "r8a7740.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 cmt1_platform_data = {
  222. .channels_mask = 0x3f,
  223. };
  224. static struct resource cmt1_resources[] = {
  225. DEFINE_RES_MEM(0xe6138000, 0x170),
  226. DEFINE_RES_IRQ(gic_spi(58)),
  227. };
  228. static struct platform_device cmt1_device = {
  229. .name = "sh-cmt-48",
  230. .id = 1,
  231. .dev = {
  232. .platform_data = &cmt1_platform_data,
  233. },
  234. .resource = cmt1_resources,
  235. .num_resources = ARRAY_SIZE(cmt1_resources),
  236. };
  237. /* TMU */
  238. static struct sh_timer_config tmu0_platform_data = {
  239. .channels_mask = 7,
  240. };
  241. static struct resource tmu0_resources[] = {
  242. DEFINE_RES_MEM(0xfff80000, 0x2c),
  243. DEFINE_RES_IRQ(gic_spi(198)),
  244. DEFINE_RES_IRQ(gic_spi(199)),
  245. DEFINE_RES_IRQ(gic_spi(200)),
  246. };
  247. static struct platform_device tmu0_device = {
  248. .name = "sh-tmu",
  249. .id = 0,
  250. .dev = {
  251. .platform_data = &tmu0_platform_data,
  252. },
  253. .resource = tmu0_resources,
  254. .num_resources = ARRAY_SIZE(tmu0_resources),
  255. };
  256. /* IPMMUI (an IPMMU module for ICB/LMB) */
  257. static struct resource ipmmu_resources[] = {
  258. [0] = {
  259. .name = "IPMMUI",
  260. .start = 0xfe951000,
  261. .end = 0xfe9510ff,
  262. .flags = IORESOURCE_MEM,
  263. },
  264. };
  265. static const char * const ipmmu_dev_names[] = {
  266. "sh_mobile_lcdc_fb.0",
  267. "sh_mobile_lcdc_fb.1",
  268. "sh_mobile_ceu.0",
  269. };
  270. static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
  271. .dev_names = ipmmu_dev_names,
  272. .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
  273. };
  274. static struct platform_device ipmmu_device = {
  275. .name = "ipmmu",
  276. .id = -1,
  277. .dev = {
  278. .platform_data = &ipmmu_platform_data,
  279. },
  280. .resource = ipmmu_resources,
  281. .num_resources = ARRAY_SIZE(ipmmu_resources),
  282. };
  283. static struct platform_device *r8a7740_devices_dt[] __initdata = {
  284. &cmt1_device,
  285. };
  286. static struct platform_device *r8a7740_early_devices[] __initdata = {
  287. &scif0_device,
  288. &scif1_device,
  289. &scif2_device,
  290. &scif3_device,
  291. &scif4_device,
  292. &scif5_device,
  293. &scif6_device,
  294. &scif7_device,
  295. &scif8_device,
  296. &irqpin0_device,
  297. &irqpin1_device,
  298. &irqpin2_device,
  299. &irqpin3_device,
  300. &tmu0_device,
  301. &ipmmu_device,
  302. };
  303. /* DMA */
  304. static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
  305. {
  306. .slave_id = SHDMA_SLAVE_SDHI0_TX,
  307. .addr = 0xe6850030,
  308. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  309. .mid_rid = 0xc1,
  310. }, {
  311. .slave_id = SHDMA_SLAVE_SDHI0_RX,
  312. .addr = 0xe6850030,
  313. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  314. .mid_rid = 0xc2,
  315. }, {
  316. .slave_id = SHDMA_SLAVE_SDHI1_TX,
  317. .addr = 0xe6860030,
  318. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  319. .mid_rid = 0xc9,
  320. }, {
  321. .slave_id = SHDMA_SLAVE_SDHI1_RX,
  322. .addr = 0xe6860030,
  323. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  324. .mid_rid = 0xca,
  325. }, {
  326. .slave_id = SHDMA_SLAVE_SDHI2_TX,
  327. .addr = 0xe6870030,
  328. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  329. .mid_rid = 0xcd,
  330. }, {
  331. .slave_id = SHDMA_SLAVE_SDHI2_RX,
  332. .addr = 0xe6870030,
  333. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  334. .mid_rid = 0xce,
  335. }, {
  336. .slave_id = SHDMA_SLAVE_FSIA_TX,
  337. .addr = 0xfe1f0024,
  338. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  339. .mid_rid = 0xb1,
  340. }, {
  341. .slave_id = SHDMA_SLAVE_FSIA_RX,
  342. .addr = 0xfe1f0020,
  343. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  344. .mid_rid = 0xb2,
  345. }, {
  346. .slave_id = SHDMA_SLAVE_FSIB_TX,
  347. .addr = 0xfe1f0064,
  348. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  349. .mid_rid = 0xb5,
  350. }, {
  351. .slave_id = SHDMA_SLAVE_MMCIF_TX,
  352. .addr = 0xe6bd0034,
  353. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  354. .mid_rid = 0xd1,
  355. }, {
  356. .slave_id = SHDMA_SLAVE_MMCIF_RX,
  357. .addr = 0xe6bd0034,
  358. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  359. .mid_rid = 0xd2,
  360. },
  361. };
  362. #define DMA_CHANNEL(a, b, c) \
  363. { \
  364. .offset = a, \
  365. .dmars = b, \
  366. .dmars_bit = c, \
  367. .chclr_offset = (0x220 - 0x20) + a \
  368. }
  369. static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
  370. DMA_CHANNEL(0x00, 0, 0),
  371. DMA_CHANNEL(0x10, 0, 8),
  372. DMA_CHANNEL(0x20, 4, 0),
  373. DMA_CHANNEL(0x30, 4, 8),
  374. DMA_CHANNEL(0x50, 8, 0),
  375. DMA_CHANNEL(0x60, 8, 8),
  376. };
  377. static struct sh_dmae_pdata dma_platform_data = {
  378. .slave = r8a7740_dmae_slaves,
  379. .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
  380. .channel = r8a7740_dmae_channels,
  381. .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
  382. .ts_low_shift = TS_LOW_SHIFT,
  383. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  384. .ts_high_shift = TS_HI_SHIFT,
  385. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  386. .ts_shift = dma_ts_shift,
  387. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  388. .dmaor_init = DMAOR_DME,
  389. .chclr_present = 1,
  390. };
  391. /* Resource order important! */
  392. static struct resource r8a7740_dmae0_resources[] = {
  393. {
  394. /* Channel registers and DMAOR */
  395. .start = 0xfe008020,
  396. .end = 0xfe00828f,
  397. .flags = IORESOURCE_MEM,
  398. },
  399. {
  400. /* DMARSx */
  401. .start = 0xfe009000,
  402. .end = 0xfe00900b,
  403. .flags = IORESOURCE_MEM,
  404. },
  405. {
  406. .name = "error_irq",
  407. .start = gic_spi(34),
  408. .end = gic_spi(34),
  409. .flags = IORESOURCE_IRQ,
  410. },
  411. {
  412. /* IRQ for channels 0-5 */
  413. .start = gic_spi(28),
  414. .end = gic_spi(33),
  415. .flags = IORESOURCE_IRQ,
  416. },
  417. };
  418. /* Resource order important! */
  419. static struct resource r8a7740_dmae1_resources[] = {
  420. {
  421. /* Channel registers and DMAOR */
  422. .start = 0xfe018020,
  423. .end = 0xfe01828f,
  424. .flags = IORESOURCE_MEM,
  425. },
  426. {
  427. /* DMARSx */
  428. .start = 0xfe019000,
  429. .end = 0xfe01900b,
  430. .flags = IORESOURCE_MEM,
  431. },
  432. {
  433. .name = "error_irq",
  434. .start = gic_spi(41),
  435. .end = gic_spi(41),
  436. .flags = IORESOURCE_IRQ,
  437. },
  438. {
  439. /* IRQ for channels 0-5 */
  440. .start = gic_spi(35),
  441. .end = gic_spi(40),
  442. .flags = IORESOURCE_IRQ,
  443. },
  444. };
  445. /* Resource order important! */
  446. static struct resource r8a7740_dmae2_resources[] = {
  447. {
  448. /* Channel registers and DMAOR */
  449. .start = 0xfe028020,
  450. .end = 0xfe02828f,
  451. .flags = IORESOURCE_MEM,
  452. },
  453. {
  454. /* DMARSx */
  455. .start = 0xfe029000,
  456. .end = 0xfe02900b,
  457. .flags = IORESOURCE_MEM,
  458. },
  459. {
  460. .name = "error_irq",
  461. .start = gic_spi(48),
  462. .end = gic_spi(48),
  463. .flags = IORESOURCE_IRQ,
  464. },
  465. {
  466. /* IRQ for channels 0-5 */
  467. .start = gic_spi(42),
  468. .end = gic_spi(47),
  469. .flags = IORESOURCE_IRQ,
  470. },
  471. };
  472. static struct platform_device dma0_device = {
  473. .name = "sh-dma-engine",
  474. .id = 0,
  475. .resource = r8a7740_dmae0_resources,
  476. .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
  477. .dev = {
  478. .platform_data = &dma_platform_data,
  479. },
  480. };
  481. static struct platform_device dma1_device = {
  482. .name = "sh-dma-engine",
  483. .id = 1,
  484. .resource = r8a7740_dmae1_resources,
  485. .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
  486. .dev = {
  487. .platform_data = &dma_platform_data,
  488. },
  489. };
  490. static struct platform_device dma2_device = {
  491. .name = "sh-dma-engine",
  492. .id = 2,
  493. .resource = r8a7740_dmae2_resources,
  494. .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
  495. .dev = {
  496. .platform_data = &dma_platform_data,
  497. },
  498. };
  499. /* USB-DMAC */
  500. static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
  501. {
  502. .offset = 0,
  503. }, {
  504. .offset = 0x20,
  505. },
  506. };
  507. static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
  508. {
  509. .slave_id = SHDMA_SLAVE_USBHS_TX,
  510. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  511. }, {
  512. .slave_id = SHDMA_SLAVE_USBHS_RX,
  513. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  514. },
  515. };
  516. static struct sh_dmae_pdata usb_dma_platform_data = {
  517. .slave = r8a7740_usb_dma_slaves,
  518. .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
  519. .channel = r8a7740_usb_dma_channels,
  520. .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
  521. .ts_low_shift = USBTS_LOW_SHIFT,
  522. .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
  523. .ts_high_shift = USBTS_HI_SHIFT,
  524. .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
  525. .ts_shift = dma_usbts_shift,
  526. .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
  527. .dmaor_init = DMAOR_DME,
  528. .chcr_offset = 0x14,
  529. .chcr_ie_bit = 1 << 5,
  530. .dmaor_is_32bit = 1,
  531. .needs_tend_set = 1,
  532. .no_dmars = 1,
  533. .slave_only = 1,
  534. };
  535. static struct resource r8a7740_usb_dma_resources[] = {
  536. {
  537. /* Channel registers and DMAOR */
  538. .start = 0xe68a0020,
  539. .end = 0xe68a0064 - 1,
  540. .flags = IORESOURCE_MEM,
  541. },
  542. {
  543. /* VCR/SWR/DMICR */
  544. .start = 0xe68a0000,
  545. .end = 0xe68a0014 - 1,
  546. .flags = IORESOURCE_MEM,
  547. },
  548. {
  549. /* IRQ for channels */
  550. .start = gic_spi(49),
  551. .end = gic_spi(49),
  552. .flags = IORESOURCE_IRQ,
  553. },
  554. };
  555. static struct platform_device usb_dma_device = {
  556. .name = "sh-dma-engine",
  557. .id = 3,
  558. .resource = r8a7740_usb_dma_resources,
  559. .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
  560. .dev = {
  561. .platform_data = &usb_dma_platform_data,
  562. },
  563. };
  564. /* I2C */
  565. static struct resource i2c0_resources[] = {
  566. [0] = {
  567. .name = "IIC0",
  568. .start = 0xfff20000,
  569. .end = 0xfff20425 - 1,
  570. .flags = IORESOURCE_MEM,
  571. },
  572. [1] = {
  573. .start = gic_spi(201),
  574. .end = gic_spi(204),
  575. .flags = IORESOURCE_IRQ,
  576. },
  577. };
  578. static struct resource i2c1_resources[] = {
  579. [0] = {
  580. .name = "IIC1",
  581. .start = 0xe6c20000,
  582. .end = 0xe6c20425 - 1,
  583. .flags = IORESOURCE_MEM,
  584. },
  585. [1] = {
  586. .start = gic_spi(70), /* IIC1_ALI1 */
  587. .end = gic_spi(73), /* IIC1_DTEI1 */
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. };
  591. static struct platform_device i2c0_device = {
  592. .name = "i2c-sh_mobile",
  593. .id = 0,
  594. .resource = i2c0_resources,
  595. .num_resources = ARRAY_SIZE(i2c0_resources),
  596. };
  597. static struct platform_device i2c1_device = {
  598. .name = "i2c-sh_mobile",
  599. .id = 1,
  600. .resource = i2c1_resources,
  601. .num_resources = ARRAY_SIZE(i2c1_resources),
  602. };
  603. static struct resource pmu_resources[] = {
  604. [0] = {
  605. .start = gic_spi(83),
  606. .end = gic_spi(83),
  607. .flags = IORESOURCE_IRQ,
  608. },
  609. };
  610. static struct platform_device pmu_device = {
  611. .name = "arm-pmu",
  612. .id = -1,
  613. .num_resources = ARRAY_SIZE(pmu_resources),
  614. .resource = pmu_resources,
  615. };
  616. static struct platform_device *r8a7740_late_devices[] __initdata = {
  617. &i2c0_device,
  618. &i2c1_device,
  619. &dma0_device,
  620. &dma1_device,
  621. &dma2_device,
  622. &usb_dma_device,
  623. &pmu_device,
  624. };
  625. /*
  626. * r8a7740 chip has lasting errata on MERAM buffer.
  627. * this is work-around for it.
  628. * see
  629. * "Media RAM (MERAM)" on r8a7740 documentation
  630. */
  631. #define MEBUFCNTR 0xFE950098
  632. void __init r8a7740_meram_workaround(void)
  633. {
  634. void __iomem *reg;
  635. reg = ioremap_nocache(MEBUFCNTR, 4);
  636. if (reg) {
  637. iowrite32(0x01600164, reg);
  638. iounmap(reg);
  639. }
  640. }
  641. #define ICCR 0x0004
  642. #define ICSTART 0x0070
  643. #define i2c_read(reg, offset) ioread8(reg + offset)
  644. #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
  645. /*
  646. * r8a7740 chip has lasting errata on I2C I/O pad reset.
  647. * this is work-around for it.
  648. */
  649. static void r8a7740_i2c_workaround(struct platform_device *pdev)
  650. {
  651. struct resource *res;
  652. void __iomem *reg;
  653. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  654. if (unlikely(!res)) {
  655. pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
  656. return;
  657. }
  658. reg = ioremap(res->start, resource_size(res));
  659. if (unlikely(!reg)) {
  660. pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
  661. return;
  662. }
  663. i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
  664. i2c_read(reg, ICCR); /* dummy read */
  665. i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
  666. i2c_read(reg, ICSTART); /* dummy read */
  667. udelay(10);
  668. i2c_write(reg, ICCR, 0x01);
  669. i2c_write(reg, ICSTART, 0x00);
  670. udelay(10);
  671. i2c_write(reg, ICCR, 0x10);
  672. udelay(10);
  673. i2c_write(reg, ICCR, 0x00);
  674. udelay(10);
  675. i2c_write(reg, ICCR, 0x10);
  676. udelay(10);
  677. iounmap(reg);
  678. }
  679. void __init r8a7740_add_standard_devices(void)
  680. {
  681. /* I2C work-around */
  682. r8a7740_i2c_workaround(&i2c0_device);
  683. r8a7740_i2c_workaround(&i2c1_device);
  684. r8a7740_init_pm_domains();
  685. /* add devices */
  686. platform_add_devices(r8a7740_early_devices,
  687. ARRAY_SIZE(r8a7740_early_devices));
  688. platform_add_devices(r8a7740_devices_dt,
  689. ARRAY_SIZE(r8a7740_devices_dt));
  690. platform_add_devices(r8a7740_late_devices,
  691. ARRAY_SIZE(r8a7740_late_devices));
  692. /* add devices to PM domain */
  693. rmobile_add_device_to_domain("A3SP", &scif0_device);
  694. rmobile_add_device_to_domain("A3SP", &scif1_device);
  695. rmobile_add_device_to_domain("A3SP", &scif2_device);
  696. rmobile_add_device_to_domain("A3SP", &scif3_device);
  697. rmobile_add_device_to_domain("A3SP", &scif4_device);
  698. rmobile_add_device_to_domain("A3SP", &scif5_device);
  699. rmobile_add_device_to_domain("A3SP", &scif6_device);
  700. rmobile_add_device_to_domain("A3SP", &scif7_device);
  701. rmobile_add_device_to_domain("A3SP", &scif8_device);
  702. rmobile_add_device_to_domain("A3SP", &i2c1_device);
  703. }
  704. void __init r8a7740_add_early_devices(void)
  705. {
  706. early_platform_add_devices(r8a7740_early_devices,
  707. ARRAY_SIZE(r8a7740_early_devices));
  708. early_platform_add_devices(r8a7740_devices_dt,
  709. ARRAY_SIZE(r8a7740_devices_dt));
  710. /* setup early console here as well */
  711. shmobile_setup_console();
  712. }
  713. #ifdef CONFIG_USE_OF
  714. void __init r8a7740_add_standard_devices_dt(void)
  715. {
  716. platform_add_devices(r8a7740_devices_dt,
  717. ARRAY_SIZE(r8a7740_devices_dt));
  718. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  719. }
  720. void __init r8a7740_init_irq_of(void)
  721. {
  722. void __iomem *intc_prio_base = ioremap_nocache(0xe6900010, 0x10);
  723. void __iomem *intc_msk_base = ioremap_nocache(0xe6900040, 0x10);
  724. void __iomem *pfc_inta_ctrl = ioremap_nocache(0xe605807c, 0x4);
  725. irqchip_init();
  726. /* route signals to GIC */
  727. iowrite32(0x0, pfc_inta_ctrl);
  728. /*
  729. * To mask the shared interrupt to SPI 149 we must ensure to set
  730. * PRIO *and* MASK. Else we run into IRQ floods when registering
  731. * the intc_irqpin devices
  732. */
  733. iowrite32(0x0, intc_prio_base + 0x0);
  734. iowrite32(0x0, intc_prio_base + 0x4);
  735. iowrite32(0x0, intc_prio_base + 0x8);
  736. iowrite32(0x0, intc_prio_base + 0xc);
  737. iowrite8(0xff, intc_msk_base + 0x0);
  738. iowrite8(0xff, intc_msk_base + 0x4);
  739. iowrite8(0xff, intc_msk_base + 0x8);
  740. iowrite8(0xff, intc_msk_base + 0xc);
  741. iounmap(intc_prio_base);
  742. iounmap(intc_msk_base);
  743. iounmap(pfc_inta_ctrl);
  744. }
  745. static void __init r8a7740_generic_init(void)
  746. {
  747. r8a7740_clock_init(0);
  748. r8a7740_add_standard_devices_dt();
  749. }
  750. static const char *r8a7740_boards_compat_dt[] __initdata = {
  751. "renesas,r8a7740",
  752. NULL,
  753. };
  754. DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
  755. .map_io = r8a7740_map_io,
  756. .init_early = shmobile_init_delay,
  757. .init_irq = r8a7740_init_irq_of,
  758. .init_machine = r8a7740_generic_init,
  759. .init_late = shmobile_init_late,
  760. .dt_compat = r8a7740_boards_compat_dt,
  761. MACHINE_END
  762. #endif /* CONFIG_USE_OF */