setup-r8a7740.c 16 KB

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