setup-r8a7740.c 15 KB

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