setup-r8a7740.c 17 KB

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