setup-r8a7740.c 17 KB

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