setup-r8a7740.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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/dma-mapping.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. static struct platform_device *r8a7740_early_devices[] __initdata = {
  265. &scif0_device,
  266. &scif1_device,
  267. &scif2_device,
  268. &scif3_device,
  269. &scif4_device,
  270. &scif5_device,
  271. &scif6_device,
  272. &scif7_device,
  273. &scifb_device,
  274. &cmt10_device,
  275. };
  276. /* DMA */
  277. static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
  278. {
  279. .slave_id = SHDMA_SLAVE_SDHI0_TX,
  280. .addr = 0xe6850030,
  281. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  282. .mid_rid = 0xc1,
  283. }, {
  284. .slave_id = SHDMA_SLAVE_SDHI0_RX,
  285. .addr = 0xe6850030,
  286. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  287. .mid_rid = 0xc2,
  288. }, {
  289. .slave_id = SHDMA_SLAVE_SDHI1_TX,
  290. .addr = 0xe6860030,
  291. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  292. .mid_rid = 0xc9,
  293. }, {
  294. .slave_id = SHDMA_SLAVE_SDHI1_RX,
  295. .addr = 0xe6860030,
  296. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  297. .mid_rid = 0xca,
  298. }, {
  299. .slave_id = SHDMA_SLAVE_SDHI2_TX,
  300. .addr = 0xe6870030,
  301. .chcr = CHCR_TX(XMIT_SZ_16BIT),
  302. .mid_rid = 0xcd,
  303. }, {
  304. .slave_id = SHDMA_SLAVE_SDHI2_RX,
  305. .addr = 0xe6870030,
  306. .chcr = CHCR_RX(XMIT_SZ_16BIT),
  307. .mid_rid = 0xce,
  308. }, {
  309. .slave_id = SHDMA_SLAVE_FSIA_TX,
  310. .addr = 0xfe1f0024,
  311. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  312. .mid_rid = 0xb1,
  313. }, {
  314. .slave_id = SHDMA_SLAVE_FSIA_RX,
  315. .addr = 0xfe1f0020,
  316. .chcr = CHCR_RX(XMIT_SZ_32BIT),
  317. .mid_rid = 0xb2,
  318. }, {
  319. .slave_id = SHDMA_SLAVE_FSIB_TX,
  320. .addr = 0xfe1f0064,
  321. .chcr = CHCR_TX(XMIT_SZ_32BIT),
  322. .mid_rid = 0xb5,
  323. },
  324. };
  325. #define DMA_CHANNEL(a, b, c) \
  326. { \
  327. .offset = a, \
  328. .dmars = b, \
  329. .dmars_bit = c, \
  330. .chclr_offset = (0x220 - 0x20) + a \
  331. }
  332. static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
  333. DMA_CHANNEL(0x00, 0, 0),
  334. DMA_CHANNEL(0x10, 0, 8),
  335. DMA_CHANNEL(0x20, 4, 0),
  336. DMA_CHANNEL(0x30, 4, 8),
  337. DMA_CHANNEL(0x50, 8, 0),
  338. DMA_CHANNEL(0x60, 8, 8),
  339. };
  340. static struct sh_dmae_pdata dma_platform_data = {
  341. .slave = r8a7740_dmae_slaves,
  342. .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
  343. .channel = r8a7740_dmae_channels,
  344. .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
  345. .ts_low_shift = TS_LOW_SHIFT,
  346. .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
  347. .ts_high_shift = TS_HI_SHIFT,
  348. .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
  349. .ts_shift = dma_ts_shift,
  350. .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
  351. .dmaor_init = DMAOR_DME,
  352. .chclr_present = 1,
  353. };
  354. /* Resource order important! */
  355. static struct resource r8a7740_dmae0_resources[] = {
  356. {
  357. /* Channel registers and DMAOR */
  358. .start = 0xfe008020,
  359. .end = 0xfe00828f,
  360. .flags = IORESOURCE_MEM,
  361. },
  362. {
  363. /* DMARSx */
  364. .start = 0xfe009000,
  365. .end = 0xfe00900b,
  366. .flags = IORESOURCE_MEM,
  367. },
  368. {
  369. .name = "error_irq",
  370. .start = evt2irq(0x20c0),
  371. .end = evt2irq(0x20c0),
  372. .flags = IORESOURCE_IRQ,
  373. },
  374. {
  375. /* IRQ for channels 0-5 */
  376. .start = evt2irq(0x2000),
  377. .end = evt2irq(0x20a0),
  378. .flags = IORESOURCE_IRQ,
  379. },
  380. };
  381. /* Resource order important! */
  382. static struct resource r8a7740_dmae1_resources[] = {
  383. {
  384. /* Channel registers and DMAOR */
  385. .start = 0xfe018020,
  386. .end = 0xfe01828f,
  387. .flags = IORESOURCE_MEM,
  388. },
  389. {
  390. /* DMARSx */
  391. .start = 0xfe019000,
  392. .end = 0xfe01900b,
  393. .flags = IORESOURCE_MEM,
  394. },
  395. {
  396. .name = "error_irq",
  397. .start = evt2irq(0x21c0),
  398. .end = evt2irq(0x21c0),
  399. .flags = IORESOURCE_IRQ,
  400. },
  401. {
  402. /* IRQ for channels 0-5 */
  403. .start = evt2irq(0x2100),
  404. .end = evt2irq(0x21a0),
  405. .flags = IORESOURCE_IRQ,
  406. },
  407. };
  408. /* Resource order important! */
  409. static struct resource r8a7740_dmae2_resources[] = {
  410. {
  411. /* Channel registers and DMAOR */
  412. .start = 0xfe028020,
  413. .end = 0xfe02828f,
  414. .flags = IORESOURCE_MEM,
  415. },
  416. {
  417. /* DMARSx */
  418. .start = 0xfe029000,
  419. .end = 0xfe02900b,
  420. .flags = IORESOURCE_MEM,
  421. },
  422. {
  423. .name = "error_irq",
  424. .start = evt2irq(0x22c0),
  425. .end = evt2irq(0x22c0),
  426. .flags = IORESOURCE_IRQ,
  427. },
  428. {
  429. /* IRQ for channels 0-5 */
  430. .start = evt2irq(0x2200),
  431. .end = evt2irq(0x22a0),
  432. .flags = IORESOURCE_IRQ,
  433. },
  434. };
  435. static struct platform_device dma0_device = {
  436. .name = "sh-dma-engine",
  437. .id = 0,
  438. .resource = r8a7740_dmae0_resources,
  439. .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
  440. .dev = {
  441. .platform_data = &dma_platform_data,
  442. },
  443. };
  444. static struct platform_device dma1_device = {
  445. .name = "sh-dma-engine",
  446. .id = 1,
  447. .resource = r8a7740_dmae1_resources,
  448. .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
  449. .dev = {
  450. .platform_data = &dma_platform_data,
  451. },
  452. };
  453. static struct platform_device dma2_device = {
  454. .name = "sh-dma-engine",
  455. .id = 2,
  456. .resource = r8a7740_dmae2_resources,
  457. .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
  458. .dev = {
  459. .platform_data = &dma_platform_data,
  460. },
  461. };
  462. /* USB-DMAC */
  463. static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
  464. {
  465. .offset = 0,
  466. }, {
  467. .offset = 0x20,
  468. },
  469. };
  470. static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
  471. {
  472. .slave_id = SHDMA_SLAVE_USBHS_TX,
  473. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  474. }, {
  475. .slave_id = SHDMA_SLAVE_USBHS_RX,
  476. .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
  477. },
  478. };
  479. static struct sh_dmae_pdata usb_dma_platform_data = {
  480. .slave = r8a7740_usb_dma_slaves,
  481. .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
  482. .channel = r8a7740_usb_dma_channels,
  483. .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
  484. .ts_low_shift = USBTS_LOW_SHIFT,
  485. .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
  486. .ts_high_shift = USBTS_HI_SHIFT,
  487. .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
  488. .ts_shift = dma_usbts_shift,
  489. .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
  490. .dmaor_init = DMAOR_DME,
  491. .chcr_offset = 0x14,
  492. .chcr_ie_bit = 1 << 5,
  493. .dmaor_is_32bit = 1,
  494. .needs_tend_set = 1,
  495. .no_dmars = 1,
  496. .slave_only = 1,
  497. };
  498. static struct resource r8a7740_usb_dma_resources[] = {
  499. {
  500. /* Channel registers and DMAOR */
  501. .start = 0xe68a0020,
  502. .end = 0xe68a0064 - 1,
  503. .flags = IORESOURCE_MEM,
  504. },
  505. {
  506. /* VCR/SWR/DMICR */
  507. .start = 0xe68a0000,
  508. .end = 0xe68a0014 - 1,
  509. .flags = IORESOURCE_MEM,
  510. },
  511. {
  512. /* IRQ for channels */
  513. .start = evt2irq(0x0a00),
  514. .end = evt2irq(0x0a00),
  515. .flags = IORESOURCE_IRQ,
  516. },
  517. };
  518. static struct platform_device usb_dma_device = {
  519. .name = "sh-dma-engine",
  520. .id = 3,
  521. .resource = r8a7740_usb_dma_resources,
  522. .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
  523. .dev = {
  524. .platform_data = &usb_dma_platform_data,
  525. },
  526. };
  527. /* I2C */
  528. static struct resource i2c0_resources[] = {
  529. [0] = {
  530. .name = "IIC0",
  531. .start = 0xfff20000,
  532. .end = 0xfff20425 - 1,
  533. .flags = IORESOURCE_MEM,
  534. },
  535. [1] = {
  536. .start = intcs_evt2irq(0xe00),
  537. .end = intcs_evt2irq(0xe60),
  538. .flags = IORESOURCE_IRQ,
  539. },
  540. };
  541. static struct resource i2c1_resources[] = {
  542. [0] = {
  543. .name = "IIC1",
  544. .start = 0xe6c20000,
  545. .end = 0xe6c20425 - 1,
  546. .flags = IORESOURCE_MEM,
  547. },
  548. [1] = {
  549. .start = evt2irq(0x780), /* IIC1_ALI1 */
  550. .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
  551. .flags = IORESOURCE_IRQ,
  552. },
  553. };
  554. static struct platform_device i2c0_device = {
  555. .name = "i2c-sh_mobile",
  556. .id = 0,
  557. .resource = i2c0_resources,
  558. .num_resources = ARRAY_SIZE(i2c0_resources),
  559. };
  560. static struct platform_device i2c1_device = {
  561. .name = "i2c-sh_mobile",
  562. .id = 1,
  563. .resource = i2c1_resources,
  564. .num_resources = ARRAY_SIZE(i2c1_resources),
  565. };
  566. static struct resource pmu_resources[] = {
  567. [0] = {
  568. .start = evt2irq(0x19a0),
  569. .end = evt2irq(0x19a0),
  570. .flags = IORESOURCE_IRQ,
  571. },
  572. };
  573. static struct platform_device pmu_device = {
  574. .name = "arm-pmu",
  575. .id = -1,
  576. .num_resources = ARRAY_SIZE(pmu_resources),
  577. .resource = pmu_resources,
  578. };
  579. static struct platform_device *r8a7740_late_devices[] __initdata = {
  580. &i2c0_device,
  581. &i2c1_device,
  582. &dma0_device,
  583. &dma1_device,
  584. &dma2_device,
  585. &usb_dma_device,
  586. &pmu_device,
  587. };
  588. /*
  589. * r8a7740 chip has lasting errata on MERAM buffer.
  590. * this is work-around for it.
  591. * see
  592. * "Media RAM (MERAM)" on r8a7740 documentation
  593. */
  594. #define MEBUFCNTR 0xFE950098
  595. void r8a7740_meram_workaround(void)
  596. {
  597. void __iomem *reg;
  598. reg = ioremap_nocache(MEBUFCNTR, 4);
  599. if (reg) {
  600. iowrite32(0x01600164, reg);
  601. iounmap(reg);
  602. }
  603. }
  604. #define ICCR 0x0004
  605. #define ICSTART 0x0070
  606. #define i2c_read(reg, offset) ioread8(reg + offset)
  607. #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
  608. /*
  609. * r8a7740 chip has lasting errata on I2C I/O pad reset.
  610. * this is work-around for it.
  611. */
  612. static void r8a7740_i2c_workaround(struct platform_device *pdev)
  613. {
  614. struct resource *res;
  615. void __iomem *reg;
  616. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  617. if (unlikely(!res)) {
  618. pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
  619. return;
  620. }
  621. reg = ioremap(res->start, resource_size(res));
  622. if (unlikely(!reg)) {
  623. pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
  624. return;
  625. }
  626. i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
  627. i2c_read(reg, ICCR); /* dummy read */
  628. i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
  629. i2c_read(reg, ICSTART); /* dummy read */
  630. udelay(10);
  631. i2c_write(reg, ICCR, 0x01);
  632. i2c_write(reg, ICSTART, 0x00);
  633. udelay(10);
  634. i2c_write(reg, ICCR, 0x10);
  635. udelay(10);
  636. i2c_write(reg, ICCR, 0x00);
  637. udelay(10);
  638. i2c_write(reg, ICCR, 0x10);
  639. udelay(10);
  640. iounmap(reg);
  641. }
  642. void __init r8a7740_add_standard_devices(void)
  643. {
  644. /* I2C work-around */
  645. r8a7740_i2c_workaround(&i2c0_device);
  646. r8a7740_i2c_workaround(&i2c1_device);
  647. r8a7740_init_pm_domains();
  648. /* add devices */
  649. platform_add_devices(r8a7740_early_devices,
  650. ARRAY_SIZE(r8a7740_early_devices));
  651. platform_add_devices(r8a7740_late_devices,
  652. ARRAY_SIZE(r8a7740_late_devices));
  653. /* add devices to PM domain */
  654. rmobile_add_device_to_domain("A3SP", &scif0_device);
  655. rmobile_add_device_to_domain("A3SP", &scif1_device);
  656. rmobile_add_device_to_domain("A3SP", &scif2_device);
  657. rmobile_add_device_to_domain("A3SP", &scif3_device);
  658. rmobile_add_device_to_domain("A3SP", &scif4_device);
  659. rmobile_add_device_to_domain("A3SP", &scif5_device);
  660. rmobile_add_device_to_domain("A3SP", &scif6_device);
  661. rmobile_add_device_to_domain("A3SP", &scif7_device);
  662. rmobile_add_device_to_domain("A3SP", &scifb_device);
  663. rmobile_add_device_to_domain("A3SP", &i2c1_device);
  664. }
  665. static void __init r8a7740_earlytimer_init(void)
  666. {
  667. r8a7740_clock_init(0);
  668. shmobile_earlytimer_init();
  669. }
  670. void __init r8a7740_add_early_devices(void)
  671. {
  672. early_platform_add_devices(r8a7740_early_devices,
  673. ARRAY_SIZE(r8a7740_early_devices));
  674. /* setup early console here as well */
  675. shmobile_setup_console();
  676. /* override timer setup with soc-specific code */
  677. shmobile_timer.init = r8a7740_earlytimer_init;
  678. }
  679. #ifdef CONFIG_USE_OF
  680. void __init r8a7740_add_early_devices_dt(void)
  681. {
  682. shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
  683. early_platform_add_devices(r8a7740_early_devices,
  684. ARRAY_SIZE(r8a7740_early_devices));
  685. /* setup early console here as well */
  686. shmobile_setup_console();
  687. }
  688. static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
  689. { }
  690. };
  691. void __init r8a7740_add_standard_devices_dt(void)
  692. {
  693. /* clocks are setup late during boot in the case of DT */
  694. r8a7740_clock_init(0);
  695. platform_add_devices(r8a7740_early_devices,
  696. ARRAY_SIZE(r8a7740_early_devices));
  697. of_platform_populate(NULL, of_default_bus_match_table,
  698. r8a7740_auxdata_lookup, NULL);
  699. }
  700. static const char *r8a7740_boards_compat_dt[] __initdata = {
  701. "renesas,r8a7740",
  702. NULL,
  703. };
  704. DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
  705. .map_io = r8a7740_map_io,
  706. .init_early = r8a7740_add_early_devices_dt,
  707. .init_irq = r8a7740_init_irq,
  708. .handle_irq = shmobile_handle_irq_intc,
  709. .init_machine = r8a7740_add_standard_devices_dt,
  710. .timer = &shmobile_timer,
  711. .dt_compat = r8a7740_boards_compat_dt,
  712. MACHINE_END
  713. #endif /* CONFIG_USE_OF */