setup-r8a7740.c 21 KB

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