setup-r8a7740.c 15 KB

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