setup-r8a7740.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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/platform_device.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/serial_sci.h>
  28. #include <linux/sh_dma.h>
  29. #include <linux/sh_timer.h>
  30. #include <linux/platform_data/sh_ipmmu.h>
  31. #include <mach/dma-register.h>
  32. #include <mach/r8a7740.h>
  33. #include <mach/pm-rmobile.h>
  34. #include <mach/common.h>
  35. #include <mach/irqs.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/time.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. iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
  67. }
  68. /* PFC */
  69. static struct resource r8a7740_pfc_resources[] = {
  70. [0] = {
  71. .start = 0xe6050000,
  72. .end = 0xe6057fff,
  73. .flags = IORESOURCE_MEM,
  74. },
  75. [1] = {
  76. .start = 0xe605800c,
  77. .end = 0xe605802b,
  78. .flags = IORESOURCE_MEM,
  79. }
  80. };
  81. static struct platform_device r8a7740_pfc_device = {
  82. .name = "pfc-r8a7740",
  83. .id = -1,
  84. .resource = r8a7740_pfc_resources,
  85. .num_resources = ARRAY_SIZE(r8a7740_pfc_resources),
  86. };
  87. void __init r8a7740_pinmux_init(void)
  88. {
  89. platform_device_register(&r8a7740_pfc_device);
  90. }
  91. /* SCIFA0 */
  92. static struct plat_sci_port scif0_platform_data = {
  93. .mapbase = 0xe6c40000,
  94. .flags = UPF_BOOT_AUTOCONF,
  95. .scscr = SCSCR_RE | SCSCR_TE,
  96. .scbrr_algo_id = SCBRR_ALGO_4,
  97. .type = PORT_SCIFA,
  98. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
  99. };
  100. static struct platform_device scif0_device = {
  101. .name = "sh-sci",
  102. .id = 0,
  103. .dev = {
  104. .platform_data = &scif0_platform_data,
  105. },
  106. };
  107. /* SCIFA1 */
  108. static struct plat_sci_port scif1_platform_data = {
  109. .mapbase = 0xe6c50000,
  110. .flags = UPF_BOOT_AUTOCONF,
  111. .scscr = SCSCR_RE | SCSCR_TE,
  112. .scbrr_algo_id = SCBRR_ALGO_4,
  113. .type = PORT_SCIFA,
  114. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
  115. };
  116. static struct platform_device scif1_device = {
  117. .name = "sh-sci",
  118. .id = 1,
  119. .dev = {
  120. .platform_data = &scif1_platform_data,
  121. },
  122. };
  123. /* SCIFA2 */
  124. static struct plat_sci_port scif2_platform_data = {
  125. .mapbase = 0xe6c60000,
  126. .flags = UPF_BOOT_AUTOCONF,
  127. .scscr = SCSCR_RE | SCSCR_TE,
  128. .scbrr_algo_id = SCBRR_ALGO_4,
  129. .type = PORT_SCIFA,
  130. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
  131. };
  132. static struct platform_device scif2_device = {
  133. .name = "sh-sci",
  134. .id = 2,
  135. .dev = {
  136. .platform_data = &scif2_platform_data,
  137. },
  138. };
  139. /* SCIFA3 */
  140. static struct plat_sci_port scif3_platform_data = {
  141. .mapbase = 0xe6c70000,
  142. .flags = UPF_BOOT_AUTOCONF,
  143. .scscr = SCSCR_RE | SCSCR_TE,
  144. .scbrr_algo_id = SCBRR_ALGO_4,
  145. .type = PORT_SCIFA,
  146. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
  147. };
  148. static struct platform_device scif3_device = {
  149. .name = "sh-sci",
  150. .id = 3,
  151. .dev = {
  152. .platform_data = &scif3_platform_data,
  153. },
  154. };
  155. /* SCIFA4 */
  156. static struct plat_sci_port scif4_platform_data = {
  157. .mapbase = 0xe6c80000,
  158. .flags = UPF_BOOT_AUTOCONF,
  159. .scscr = SCSCR_RE | SCSCR_TE,
  160. .scbrr_algo_id = SCBRR_ALGO_4,
  161. .type = PORT_SCIFA,
  162. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
  163. };
  164. static struct platform_device scif4_device = {
  165. .name = "sh-sci",
  166. .id = 4,
  167. .dev = {
  168. .platform_data = &scif4_platform_data,
  169. },
  170. };
  171. /* SCIFA5 */
  172. static struct plat_sci_port scif5_platform_data = {
  173. .mapbase = 0xe6cb0000,
  174. .flags = UPF_BOOT_AUTOCONF,
  175. .scscr = SCSCR_RE | SCSCR_TE,
  176. .scbrr_algo_id = SCBRR_ALGO_4,
  177. .type = PORT_SCIFA,
  178. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
  179. };
  180. static struct platform_device scif5_device = {
  181. .name = "sh-sci",
  182. .id = 5,
  183. .dev = {
  184. .platform_data = &scif5_platform_data,
  185. },
  186. };
  187. /* SCIFA6 */
  188. static struct plat_sci_port scif6_platform_data = {
  189. .mapbase = 0xe6cc0000,
  190. .flags = UPF_BOOT_AUTOCONF,
  191. .scscr = SCSCR_RE | SCSCR_TE,
  192. .scbrr_algo_id = SCBRR_ALGO_4,
  193. .type = PORT_SCIFA,
  194. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
  195. };
  196. static struct platform_device scif6_device = {
  197. .name = "sh-sci",
  198. .id = 6,
  199. .dev = {
  200. .platform_data = &scif6_platform_data,
  201. },
  202. };
  203. /* SCIFA7 */
  204. static struct plat_sci_port scif7_platform_data = {
  205. .mapbase = 0xe6cd0000,
  206. .flags = UPF_BOOT_AUTOCONF,
  207. .scscr = SCSCR_RE | SCSCR_TE,
  208. .scbrr_algo_id = SCBRR_ALGO_4,
  209. .type = PORT_SCIFA,
  210. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
  211. };
  212. static struct platform_device scif7_device = {
  213. .name = "sh-sci",
  214. .id = 7,
  215. .dev = {
  216. .platform_data = &scif7_platform_data,
  217. },
  218. };
  219. /* SCIFB */
  220. static struct plat_sci_port scifb_platform_data = {
  221. .mapbase = 0xe6c30000,
  222. .flags = UPF_BOOT_AUTOCONF,
  223. .scscr = SCSCR_RE | SCSCR_TE,
  224. .scbrr_algo_id = SCBRR_ALGO_4,
  225. .type = PORT_SCIFB,
  226. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
  227. };
  228. static struct platform_device scifb_device = {
  229. .name = "sh-sci",
  230. .id = 8,
  231. .dev = {
  232. .platform_data = &scifb_platform_data,
  233. },
  234. };
  235. /* CMT */
  236. static struct sh_timer_config cmt10_platform_data = {
  237. .name = "CMT10",
  238. .channel_offset = 0x10,
  239. .timer_bit = 0,
  240. .clockevent_rating = 125,
  241. .clocksource_rating = 125,
  242. };
  243. static struct resource cmt10_resources[] = {
  244. [0] = {
  245. .name = "CMT10",
  246. .start = 0xe6138010,
  247. .end = 0xe613801b,
  248. .flags = IORESOURCE_MEM,
  249. },
  250. [1] = {
  251. .start = evt2irq(0x0b00),
  252. .flags = IORESOURCE_IRQ,
  253. },
  254. };
  255. static struct platform_device cmt10_device = {
  256. .name = "sh_cmt",
  257. .id = 10,
  258. .dev = {
  259. .platform_data = &cmt10_platform_data,
  260. },
  261. .resource = cmt10_resources,
  262. .num_resources = ARRAY_SIZE(cmt10_resources),
  263. };
  264. /* TMU */
  265. static struct sh_timer_config tmu00_platform_data = {
  266. .name = "TMU00",
  267. .channel_offset = 0x4,
  268. .timer_bit = 0,
  269. .clockevent_rating = 200,
  270. };
  271. static struct resource tmu00_resources[] = {
  272. [0] = {
  273. .name = "TMU00",
  274. .start = 0xfff80008,
  275. .end = 0xfff80014 - 1,
  276. .flags = IORESOURCE_MEM,
  277. },
  278. [1] = {
  279. .start = intcs_evt2irq(0xe80),
  280. .flags = IORESOURCE_IRQ,
  281. },
  282. };
  283. static struct platform_device tmu00_device = {
  284. .name = "sh_tmu",
  285. .id = 0,
  286. .dev = {
  287. .platform_data = &tmu00_platform_data,
  288. },
  289. .resource = tmu00_resources,
  290. .num_resources = ARRAY_SIZE(tmu00_resources),
  291. };
  292. static struct sh_timer_config tmu01_platform_data = {
  293. .name = "TMU01",
  294. .channel_offset = 0x10,
  295. .timer_bit = 1,
  296. .clocksource_rating = 200,
  297. };
  298. static struct resource tmu01_resources[] = {
  299. [0] = {
  300. .name = "TMU01",
  301. .start = 0xfff80014,
  302. .end = 0xfff80020 - 1,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .start = intcs_evt2irq(0xea0),
  307. .flags = IORESOURCE_IRQ,
  308. },
  309. };
  310. static struct platform_device tmu01_device = {
  311. .name = "sh_tmu",
  312. .id = 1,
  313. .dev = {
  314. .platform_data = &tmu01_platform_data,
  315. },
  316. .resource = tmu01_resources,
  317. .num_resources = ARRAY_SIZE(tmu01_resources),
  318. };
  319. static struct sh_timer_config tmu02_platform_data = {
  320. .name = "TMU02",
  321. .channel_offset = 0x1C,
  322. .timer_bit = 2,
  323. .clocksource_rating = 200,
  324. };
  325. static struct resource tmu02_resources[] = {
  326. [0] = {
  327. .name = "TMU02",
  328. .start = 0xfff80020,
  329. .end = 0xfff8002C - 1,
  330. .flags = IORESOURCE_MEM,
  331. },
  332. [1] = {
  333. .start = intcs_evt2irq(0xec0),
  334. .flags = IORESOURCE_IRQ,
  335. },
  336. };
  337. static struct platform_device tmu02_device = {
  338. .name = "sh_tmu",
  339. .id = 2,
  340. .dev = {
  341. .platform_data = &tmu02_platform_data,
  342. },
  343. .resource = tmu02_resources,
  344. .num_resources = ARRAY_SIZE(tmu02_resources),
  345. };
  346. /* IPMMUI (an IPMMU module for ICB/LMB) */
  347. static struct resource ipmmu_resources[] = {
  348. [0] = {
  349. .name = "IPMMUI",
  350. .start = 0xfe951000,
  351. .end = 0xfe9510ff,
  352. .flags = IORESOURCE_MEM,
  353. },
  354. };
  355. static const char * const ipmmu_dev_names[] = {
  356. "sh_mobile_lcdc_fb.0",
  357. "sh_mobile_lcdc_fb.1",
  358. "sh_mobile_ceu.0",
  359. };
  360. static struct shmobile_ipmmu_platform_data ipmmu_platform_data = {
  361. .dev_names = ipmmu_dev_names,
  362. .num_dev_names = ARRAY_SIZE(ipmmu_dev_names),
  363. };
  364. static struct platform_device ipmmu_device = {
  365. .name = "ipmmu",
  366. .id = -1,
  367. .dev = {
  368. .platform_data = &ipmmu_platform_data,
  369. },
  370. .resource = ipmmu_resources,
  371. .num_resources = ARRAY_SIZE(ipmmu_resources),
  372. };
  373. static struct platform_device *r8a7740_early_devices[] __initdata = {
  374. &scif0_device,
  375. &scif1_device,
  376. &scif2_device,
  377. &scif3_device,
  378. &scif4_device,
  379. &scif5_device,
  380. &scif6_device,
  381. &scif7_device,
  382. &scifb_device,
  383. &cmt10_device,
  384. &tmu00_device,
  385. &tmu01_device,
  386. &tmu02_device,
  387. &ipmmu_device,
  388. };
  389. /* DMA */
  390. static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
  391. {
  392. .slave_id = SHDMA_SLAVE_SDHI0_TX,
  393. .addr = 0xe6850030,
  394. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  395. .mid_rid = 0xc1,
  396. }, {
  397. .slave_id = SHDMA_SLAVE_SDHI0_RX,
  398. .addr = 0xe6850030,
  399. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  400. .mid_rid = 0xc2,
  401. }, {
  402. .slave_id = SHDMA_SLAVE_SDHI1_TX,
  403. .addr = 0xe6860030,
  404. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  405. .mid_rid = 0xc9,
  406. }, {
  407. .slave_id = SHDMA_SLAVE_SDHI1_RX,
  408. .addr = 0xe6860030,
  409. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  410. .mid_rid = 0xca,
  411. }, {
  412. .slave_id = SHDMA_SLAVE_SDHI2_TX,
  413. .addr = 0xe6870030,
  414. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  415. .mid_rid = 0xcd,
  416. }, {
  417. .slave_id = SHDMA_SLAVE_SDHI2_RX,
  418. .addr = 0xe6870030,
  419. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  420. .mid_rid = 0xce,
  421. }, {
  422. .slave_id = SHDMA_SLAVE_FSIA_TX,
  423. .addr = 0xfe1f0024,
  424. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  425. .mid_rid = 0xb1,
  426. }, {
  427. .slave_id = SHDMA_SLAVE_FSIA_RX,
  428. .addr = 0xfe1f0020,
  429. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  430. .mid_rid = 0xb2,
  431. }, {
  432. .slave_id = SHDMA_SLAVE_FSIB_TX,
  433. .addr = 0xfe1f0064,
  434. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  435. .mid_rid = 0xb5,
  436. },
  437. };
  438. #define DMA_CHANNEL(a, b, c) \
  439. { \
  440. .offset = a, \
  441. .dmars = b, \
  442. .dmars_bit = c, \
  443. .chclr_offset = (0x220 - 0x20) + a \
  444. }
  445. static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
  446. DMA_CHANNEL(0x00, 0, 0),
  447. DMA_CHANNEL(0x10, 0, 8),
  448. DMA_CHANNEL(0x20, 4, 0),
  449. DMA_CHANNEL(0x30, 4, 8),
  450. DMA_CHANNEL(0x50, 8, 0),
  451. DMA_CHANNEL(0x60, 8, 8),
  452. };
  453. static struct sh_dmae_pdata dma_platform_data = {
  454. .slave = r8a7740_dmae_slaves,
  455. .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
  456. .channel = r8a7740_dmae_channels,
  457. .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
  458. .ts_low_shift = TS_LOW_SHIFT,
  459. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  460. .ts_high_shift = TS_HI_SHIFT,
  461. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  462. .ts_shift = dma_ts_shift,
  463. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  464. .dmaor_init = DMAOR_DME,
  465. .chclr_present = 1,
  466. };
  467. /* Resource order important! */
  468. static struct resource r8a7740_dmae0_resources[] = {
  469. {
  470. /* Channel registers and DMAOR */
  471. .start = 0xfe008020,
  472. .end = 0xfe00828f,
  473. .flags = IORESOURCE_MEM,
  474. },
  475. {
  476. /* DMARSx */
  477. .start = 0xfe009000,
  478. .end = 0xfe00900b,
  479. .flags = IORESOURCE_MEM,
  480. },
  481. {
  482. .name = "error_irq",
  483. .start = evt2irq(0x20c0),
  484. .end = evt2irq(0x20c0),
  485. .flags = IORESOURCE_IRQ,
  486. },
  487. {
  488. /* IRQ for channels 0-5 */
  489. .start = evt2irq(0x2000),
  490. .end = evt2irq(0x20a0),
  491. .flags = IORESOURCE_IRQ,
  492. },
  493. };
  494. /* Resource order important! */
  495. static struct resource r8a7740_dmae1_resources[] = {
  496. {
  497. /* Channel registers and DMAOR */
  498. .start = 0xfe018020,
  499. .end = 0xfe01828f,
  500. .flags = IORESOURCE_MEM,
  501. },
  502. {
  503. /* DMARSx */
  504. .start = 0xfe019000,
  505. .end = 0xfe01900b,
  506. .flags = IORESOURCE_MEM,
  507. },
  508. {
  509. .name = "error_irq",
  510. .start = evt2irq(0x21c0),
  511. .end = evt2irq(0x21c0),
  512. .flags = IORESOURCE_IRQ,
  513. },
  514. {
  515. /* IRQ for channels 0-5 */
  516. .start = evt2irq(0x2100),
  517. .end = evt2irq(0x21a0),
  518. .flags = IORESOURCE_IRQ,
  519. },
  520. };
  521. /* Resource order important! */
  522. static struct resource r8a7740_dmae2_resources[] = {
  523. {
  524. /* Channel registers and DMAOR */
  525. .start = 0xfe028020,
  526. .end = 0xfe02828f,
  527. .flags = IORESOURCE_MEM,
  528. },
  529. {
  530. /* DMARSx */
  531. .start = 0xfe029000,
  532. .end = 0xfe02900b,
  533. .flags = IORESOURCE_MEM,
  534. },
  535. {
  536. .name = "error_irq",
  537. .start = evt2irq(0x22c0),
  538. .end = evt2irq(0x22c0),
  539. .flags = IORESOURCE_IRQ,
  540. },
  541. {
  542. /* IRQ for channels 0-5 */
  543. .start = evt2irq(0x2200),
  544. .end = evt2irq(0x22a0),
  545. .flags = IORESOURCE_IRQ,
  546. },
  547. };
  548. static struct platform_device dma0_device = {
  549. .name = "sh-dma-engine",
  550. .id = 0,
  551. .resource = r8a7740_dmae0_resources,
  552. .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
  553. .dev = {
  554. .platform_data = &dma_platform_data,
  555. },
  556. };
  557. static struct platform_device dma1_device = {
  558. .name = "sh-dma-engine",
  559. .id = 1,
  560. .resource = r8a7740_dmae1_resources,
  561. .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
  562. .dev = {
  563. .platform_data = &dma_platform_data,
  564. },
  565. };
  566. static struct platform_device dma2_device = {
  567. .name = "sh-dma-engine",
  568. .id = 2,
  569. .resource = r8a7740_dmae2_resources,
  570. .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
  571. .dev = {
  572. .platform_data = &dma_platform_data,
  573. },
  574. };
  575. /* USB-DMAC */
  576. static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
  577. {
  578. .offset = 0,
  579. }, {
  580. .offset = 0x20,
  581. },
  582. };
  583. static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
  584. {
  585. .slave_id = SHDMA_SLAVE_USBHS_TX,
  586. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  587. }, {
  588. .slave_id = SHDMA_SLAVE_USBHS_RX,
  589. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  590. },
  591. };
  592. static struct sh_dmae_pdata usb_dma_platform_data = {
  593. .slave = r8a7740_usb_dma_slaves,
  594. .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
  595. .channel = r8a7740_usb_dma_channels,
  596. .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
  597. .ts_low_shift = USBTS_LOW_SHIFT,
  598. .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
  599. .ts_high_shift = USBTS_HI_SHIFT,
  600. .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
  601. .ts_shift = dma_usbts_shift,
  602. .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
  603. .dmaor_init = DMAOR_DME,
  604. .chcr_offset = 0x14,
  605. .chcr_ie_bit = 1 << 5,
  606. .dmaor_is_32bit = 1,
  607. .needs_tend_set = 1,
  608. .no_dmars = 1,
  609. .slave_only = 1,
  610. };
  611. static struct resource r8a7740_usb_dma_resources[] = {
  612. {
  613. /* Channel registers and DMAOR */
  614. .start = 0xe68a0020,
  615. .end = 0xe68a0064 - 1,
  616. .flags = IORESOURCE_MEM,
  617. },
  618. {
  619. /* VCR/SWR/DMICR */
  620. .start = 0xe68a0000,
  621. .end = 0xe68a0014 - 1,
  622. .flags = IORESOURCE_MEM,
  623. },
  624. {
  625. /* IRQ for channels */
  626. .start = evt2irq(0x0a00),
  627. .end = evt2irq(0x0a00),
  628. .flags = IORESOURCE_IRQ,
  629. },
  630. };
  631. static struct platform_device usb_dma_device = {
  632. .name = "sh-dma-engine",
  633. .id = 3,
  634. .resource = r8a7740_usb_dma_resources,
  635. .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
  636. .dev = {
  637. .platform_data = &usb_dma_platform_data,
  638. },
  639. };
  640. /* I2C */
  641. static struct resource i2c0_resources[] = {
  642. [0] = {
  643. .name = "IIC0",
  644. .start = 0xfff20000,
  645. .end = 0xfff20425 - 1,
  646. .flags = IORESOURCE_MEM,
  647. },
  648. [1] = {
  649. .start = intcs_evt2irq(0xe00),
  650. .end = intcs_evt2irq(0xe60),
  651. .flags = IORESOURCE_IRQ,
  652. },
  653. };
  654. static struct resource i2c1_resources[] = {
  655. [0] = {
  656. .name = "IIC1",
  657. .start = 0xe6c20000,
  658. .end = 0xe6c20425 - 1,
  659. .flags = IORESOURCE_MEM,
  660. },
  661. [1] = {
  662. .start = evt2irq(0x780), /* IIC1_ALI1 */
  663. .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
  664. .flags = IORESOURCE_IRQ,
  665. },
  666. };
  667. static struct platform_device i2c0_device = {
  668. .name = "i2c-sh_mobile",
  669. .id = 0,
  670. .resource = i2c0_resources,
  671. .num_resources = ARRAY_SIZE(i2c0_resources),
  672. };
  673. static struct platform_device i2c1_device = {
  674. .name = "i2c-sh_mobile",
  675. .id = 1,
  676. .resource = i2c1_resources,
  677. .num_resources = ARRAY_SIZE(i2c1_resources),
  678. };
  679. static struct resource pmu_resources[] = {
  680. [0] = {
  681. .start = evt2irq(0x19a0),
  682. .end = evt2irq(0x19a0),
  683. .flags = IORESOURCE_IRQ,
  684. },
  685. };
  686. static struct platform_device pmu_device = {
  687. .name = "arm-pmu",
  688. .id = -1,
  689. .num_resources = ARRAY_SIZE(pmu_resources),
  690. .resource = pmu_resources,
  691. };
  692. static struct platform_device *r8a7740_late_devices[] __initdata = {
  693. &i2c0_device,
  694. &i2c1_device,
  695. &dma0_device,
  696. &dma1_device,
  697. &dma2_device,
  698. &usb_dma_device,
  699. &pmu_device,
  700. };
  701. /*
  702. * r8a7740 chip has lasting errata on MERAM buffer.
  703. * this is work-around for it.
  704. * see
  705. * "Media RAM (MERAM)" on r8a7740 documentation
  706. */
  707. #define MEBUFCNTR 0xFE950098
  708. void r8a7740_meram_workaround(void)
  709. {
  710. void __iomem *reg;
  711. reg = ioremap_nocache(MEBUFCNTR, 4);
  712. if (reg) {
  713. iowrite32(0x01600164, reg);
  714. iounmap(reg);
  715. }
  716. }
  717. #define ICCR 0x0004
  718. #define ICSTART 0x0070
  719. #define i2c_read(reg, offset) ioread8(reg + offset)
  720. #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
  721. /*
  722. * r8a7740 chip has lasting errata on I2C I/O pad reset.
  723. * this is work-around for it.
  724. */
  725. static void r8a7740_i2c_workaround(struct platform_device *pdev)
  726. {
  727. struct resource *res;
  728. void __iomem *reg;
  729. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  730. if (unlikely(!res)) {
  731. pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
  732. return;
  733. }
  734. reg = ioremap(res->start, resource_size(res));
  735. if (unlikely(!reg)) {
  736. pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
  737. return;
  738. }
  739. i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
  740. i2c_read(reg, ICCR); /* dummy read */
  741. i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
  742. i2c_read(reg, ICSTART); /* dummy read */
  743. udelay(10);
  744. i2c_write(reg, ICCR, 0x01);
  745. i2c_write(reg, ICSTART, 0x00);
  746. udelay(10);
  747. i2c_write(reg, ICCR, 0x10);
  748. udelay(10);
  749. i2c_write(reg, ICCR, 0x00);
  750. udelay(10);
  751. i2c_write(reg, ICCR, 0x10);
  752. udelay(10);
  753. iounmap(reg);
  754. }
  755. void __init r8a7740_add_standard_devices(void)
  756. {
  757. /* I2C work-around */
  758. r8a7740_i2c_workaround(&i2c0_device);
  759. r8a7740_i2c_workaround(&i2c1_device);
  760. r8a7740_init_pm_domains();
  761. /* add devices */
  762. platform_add_devices(r8a7740_early_devices,
  763. ARRAY_SIZE(r8a7740_early_devices));
  764. platform_add_devices(r8a7740_late_devices,
  765. ARRAY_SIZE(r8a7740_late_devices));
  766. /* add devices to PM domain */
  767. rmobile_add_device_to_domain("A3SP", &scif0_device);
  768. rmobile_add_device_to_domain("A3SP", &scif1_device);
  769. rmobile_add_device_to_domain("A3SP", &scif2_device);
  770. rmobile_add_device_to_domain("A3SP", &scif3_device);
  771. rmobile_add_device_to_domain("A3SP", &scif4_device);
  772. rmobile_add_device_to_domain("A3SP", &scif5_device);
  773. rmobile_add_device_to_domain("A3SP", &scif6_device);
  774. rmobile_add_device_to_domain("A3SP", &scif7_device);
  775. rmobile_add_device_to_domain("A3SP", &scifb_device);
  776. rmobile_add_device_to_domain("A3SP", &i2c1_device);
  777. }
  778. void __init r8a7740_add_early_devices(void)
  779. {
  780. early_platform_add_devices(r8a7740_early_devices,
  781. ARRAY_SIZE(r8a7740_early_devices));
  782. /* setup early console here as well */
  783. shmobile_setup_console();
  784. }
  785. #ifdef CONFIG_USE_OF
  786. void __init r8a7740_add_early_devices_dt(void)
  787. {
  788. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  789. early_platform_add_devices(r8a7740_early_devices,
  790. ARRAY_SIZE(r8a7740_early_devices));
  791. /* setup early console here as well */
  792. shmobile_setup_console();
  793. }
  794. static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
  795. { }
  796. };
  797. void __init r8a7740_add_standard_devices_dt(void)
  798. {
  799. /* clocks are setup late during boot in the case of DT */
  800. r8a7740_clock_init(0);
  801. platform_add_devices(r8a7740_early_devices,
  802. ARRAY_SIZE(r8a7740_early_devices));
  803. of_platform_populate(NULL, of_default_bus_match_table,
  804. r8a7740_auxdata_lookup, NULL);
  805. }
  806. static const char *r8a7740_boards_compat_dt[] __initdata = {
  807. "renesas,r8a7740",
  808. NULL,
  809. };
  810. DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
  811. .map_io = r8a7740_map_io,
  812. .init_early = r8a7740_add_early_devices_dt,
  813. .init_irq = r8a7740_init_irq,
  814. .handle_irq = shmobile_handle_irq_intc,
  815. .init_machine = r8a7740_add_standard_devices_dt,
  816. .init_time = shmobile_timer_init,
  817. .dt_compat = r8a7740_boards_compat_dt,
  818. MACHINE_END
  819. #endif /* CONFIG_USE_OF */