setup-r8a7740.c 18 KB

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