setup-r8a7740.c 17 KB

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