setup-r8a7740.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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_timer.h>
  28. #include <mach/r8a7740.h>
  29. #include <mach/common.h>
  30. #include <mach/irqs.h>
  31. #include <asm/mach-types.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach/arch.h>
  34. #include <asm/mach/time.h>
  35. static struct map_desc r8a7740_io_desc[] __initdata = {
  36. /*
  37. * for CPGA/INTC/PFC
  38. * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
  39. */
  40. {
  41. .virtual = 0xe6000000,
  42. .pfn = __phys_to_pfn(0xe6000000),
  43. .length = 160 << 20,
  44. .type = MT_DEVICE_NONSHARED
  45. },
  46. #ifdef CONFIG_CACHE_L2X0
  47. /*
  48. * for l2x0_init()
  49. * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
  50. */
  51. {
  52. .virtual = 0xf0002000,
  53. .pfn = __phys_to_pfn(0xf0100000),
  54. .length = PAGE_SIZE,
  55. .type = MT_DEVICE_NONSHARED
  56. },
  57. #endif
  58. };
  59. void __init r8a7740_map_io(void)
  60. {
  61. iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
  62. /*
  63. * DMA memory at 0xff200000 - 0xffdfffff. The default 2MB size isn't
  64. * enough to allocate the frame buffer memory.
  65. */
  66. init_consistent_dma_size(12 << 20);
  67. }
  68. /* SCIFA0 */
  69. static struct plat_sci_port scif0_platform_data = {
  70. .mapbase = 0xe6c40000,
  71. .flags = UPF_BOOT_AUTOCONF,
  72. .scscr = SCSCR_RE | SCSCR_TE,
  73. .scbrr_algo_id = SCBRR_ALGO_4,
  74. .type = PORT_SCIFA,
  75. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
  76. };
  77. static struct platform_device scif0_device = {
  78. .name = "sh-sci",
  79. .id = 0,
  80. .dev = {
  81. .platform_data = &scif0_platform_data,
  82. },
  83. };
  84. /* SCIFA1 */
  85. static struct plat_sci_port scif1_platform_data = {
  86. .mapbase = 0xe6c50000,
  87. .flags = UPF_BOOT_AUTOCONF,
  88. .scscr = SCSCR_RE | SCSCR_TE,
  89. .scbrr_algo_id = SCBRR_ALGO_4,
  90. .type = PORT_SCIFA,
  91. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
  92. };
  93. static struct platform_device scif1_device = {
  94. .name = "sh-sci",
  95. .id = 1,
  96. .dev = {
  97. .platform_data = &scif1_platform_data,
  98. },
  99. };
  100. /* SCIFA2 */
  101. static struct plat_sci_port scif2_platform_data = {
  102. .mapbase = 0xe6c60000,
  103. .flags = UPF_BOOT_AUTOCONF,
  104. .scscr = SCSCR_RE | SCSCR_TE,
  105. .scbrr_algo_id = SCBRR_ALGO_4,
  106. .type = PORT_SCIFA,
  107. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
  108. };
  109. static struct platform_device scif2_device = {
  110. .name = "sh-sci",
  111. .id = 2,
  112. .dev = {
  113. .platform_data = &scif2_platform_data,
  114. },
  115. };
  116. /* SCIFA3 */
  117. static struct plat_sci_port scif3_platform_data = {
  118. .mapbase = 0xe6c70000,
  119. .flags = UPF_BOOT_AUTOCONF,
  120. .scscr = SCSCR_RE | SCSCR_TE,
  121. .scbrr_algo_id = SCBRR_ALGO_4,
  122. .type = PORT_SCIFA,
  123. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
  124. };
  125. static struct platform_device scif3_device = {
  126. .name = "sh-sci",
  127. .id = 3,
  128. .dev = {
  129. .platform_data = &scif3_platform_data,
  130. },
  131. };
  132. /* SCIFA4 */
  133. static struct plat_sci_port scif4_platform_data = {
  134. .mapbase = 0xe6c80000,
  135. .flags = UPF_BOOT_AUTOCONF,
  136. .scscr = SCSCR_RE | SCSCR_TE,
  137. .scbrr_algo_id = SCBRR_ALGO_4,
  138. .type = PORT_SCIFA,
  139. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
  140. };
  141. static struct platform_device scif4_device = {
  142. .name = "sh-sci",
  143. .id = 4,
  144. .dev = {
  145. .platform_data = &scif4_platform_data,
  146. },
  147. };
  148. /* SCIFA5 */
  149. static struct plat_sci_port scif5_platform_data = {
  150. .mapbase = 0xe6cb0000,
  151. .flags = UPF_BOOT_AUTOCONF,
  152. .scscr = SCSCR_RE | SCSCR_TE,
  153. .scbrr_algo_id = SCBRR_ALGO_4,
  154. .type = PORT_SCIFA,
  155. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
  156. };
  157. static struct platform_device scif5_device = {
  158. .name = "sh-sci",
  159. .id = 5,
  160. .dev = {
  161. .platform_data = &scif5_platform_data,
  162. },
  163. };
  164. /* SCIFA6 */
  165. static struct plat_sci_port scif6_platform_data = {
  166. .mapbase = 0xe6cc0000,
  167. .flags = UPF_BOOT_AUTOCONF,
  168. .scscr = SCSCR_RE | SCSCR_TE,
  169. .scbrr_algo_id = SCBRR_ALGO_4,
  170. .type = PORT_SCIFA,
  171. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
  172. };
  173. static struct platform_device scif6_device = {
  174. .name = "sh-sci",
  175. .id = 6,
  176. .dev = {
  177. .platform_data = &scif6_platform_data,
  178. },
  179. };
  180. /* SCIFA7 */
  181. static struct plat_sci_port scif7_platform_data = {
  182. .mapbase = 0xe6cd0000,
  183. .flags = UPF_BOOT_AUTOCONF,
  184. .scscr = SCSCR_RE | SCSCR_TE,
  185. .scbrr_algo_id = SCBRR_ALGO_4,
  186. .type = PORT_SCIFA,
  187. .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
  188. };
  189. static struct platform_device scif7_device = {
  190. .name = "sh-sci",
  191. .id = 7,
  192. .dev = {
  193. .platform_data = &scif7_platform_data,
  194. },
  195. };
  196. /* SCIFB */
  197. static struct plat_sci_port scifb_platform_data = {
  198. .mapbase = 0xe6c30000,
  199. .flags = UPF_BOOT_AUTOCONF,
  200. .scscr = SCSCR_RE | SCSCR_TE,
  201. .scbrr_algo_id = SCBRR_ALGO_4,
  202. .type = PORT_SCIFB,
  203. .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
  204. };
  205. static struct platform_device scifb_device = {
  206. .name = "sh-sci",
  207. .id = 8,
  208. .dev = {
  209. .platform_data = &scifb_platform_data,
  210. },
  211. };
  212. /* CMT */
  213. static struct sh_timer_config cmt10_platform_data = {
  214. .name = "CMT10",
  215. .channel_offset = 0x10,
  216. .timer_bit = 0,
  217. .clockevent_rating = 125,
  218. .clocksource_rating = 125,
  219. };
  220. static struct resource cmt10_resources[] = {
  221. [0] = {
  222. .name = "CMT10",
  223. .start = 0xe6138010,
  224. .end = 0xe613801b,
  225. .flags = IORESOURCE_MEM,
  226. },
  227. [1] = {
  228. .start = evt2irq(0x0b00),
  229. .flags = IORESOURCE_IRQ,
  230. },
  231. };
  232. static struct platform_device cmt10_device = {
  233. .name = "sh_cmt",
  234. .id = 10,
  235. .dev = {
  236. .platform_data = &cmt10_platform_data,
  237. },
  238. .resource = cmt10_resources,
  239. .num_resources = ARRAY_SIZE(cmt10_resources),
  240. };
  241. static struct platform_device *r8a7740_early_devices[] __initdata = {
  242. &scif0_device,
  243. &scif1_device,
  244. &scif2_device,
  245. &scif3_device,
  246. &scif4_device,
  247. &scif5_device,
  248. &scif6_device,
  249. &scif7_device,
  250. &scifb_device,
  251. &cmt10_device,
  252. };
  253. /* I2C */
  254. static struct resource i2c0_resources[] = {
  255. [0] = {
  256. .name = "IIC0",
  257. .start = 0xfff20000,
  258. .end = 0xfff20425 - 1,
  259. .flags = IORESOURCE_MEM,
  260. },
  261. [1] = {
  262. .start = intcs_evt2irq(0xe00),
  263. .end = intcs_evt2irq(0xe60),
  264. .flags = IORESOURCE_IRQ,
  265. },
  266. };
  267. static struct resource i2c1_resources[] = {
  268. [0] = {
  269. .name = "IIC1",
  270. .start = 0xe6c20000,
  271. .end = 0xe6c20425 - 1,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. [1] = {
  275. .start = evt2irq(0x780), /* IIC1_ALI1 */
  276. .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
  277. .flags = IORESOURCE_IRQ,
  278. },
  279. };
  280. static struct platform_device i2c0_device = {
  281. .name = "i2c-sh_mobile",
  282. .id = 0,
  283. .resource = i2c0_resources,
  284. .num_resources = ARRAY_SIZE(i2c0_resources),
  285. };
  286. static struct platform_device i2c1_device = {
  287. .name = "i2c-sh_mobile",
  288. .id = 1,
  289. .resource = i2c1_resources,
  290. .num_resources = ARRAY_SIZE(i2c1_resources),
  291. };
  292. static struct platform_device *r8a7740_late_devices[] __initdata = {
  293. &i2c0_device,
  294. &i2c1_device,
  295. };
  296. #define ICCR 0x0004
  297. #define ICSTART 0x0070
  298. #define i2c_read(reg, offset) ioread8(reg + offset)
  299. #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
  300. /*
  301. * r8a7740 chip has lasting errata on I2C I/O pad reset.
  302. * this is work-around for it.
  303. */
  304. static void r8a7740_i2c_workaround(struct platform_device *pdev)
  305. {
  306. struct resource *res;
  307. void __iomem *reg;
  308. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  309. if (unlikely(!res)) {
  310. pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
  311. return;
  312. }
  313. reg = ioremap(res->start, resource_size(res));
  314. if (unlikely(!reg)) {
  315. pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
  316. return;
  317. }
  318. i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
  319. i2c_read(reg, ICCR); /* dummy read */
  320. i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
  321. i2c_read(reg, ICSTART); /* dummy read */
  322. udelay(10);
  323. i2c_write(reg, ICCR, 0x01);
  324. i2c_write(reg, ICSTART, 0x00);
  325. udelay(10);
  326. i2c_write(reg, ICCR, 0x10);
  327. udelay(10);
  328. i2c_write(reg, ICCR, 0x00);
  329. udelay(10);
  330. i2c_write(reg, ICCR, 0x10);
  331. udelay(10);
  332. iounmap(reg);
  333. }
  334. void __init r8a7740_add_standard_devices(void)
  335. {
  336. /* I2C work-around */
  337. r8a7740_i2c_workaround(&i2c0_device);
  338. r8a7740_i2c_workaround(&i2c1_device);
  339. platform_add_devices(r8a7740_early_devices,
  340. ARRAY_SIZE(r8a7740_early_devices));
  341. platform_add_devices(r8a7740_late_devices,
  342. ARRAY_SIZE(r8a7740_late_devices));
  343. }
  344. static void __init r8a7740_earlytimer_init(void)
  345. {
  346. r8a7740_clock_init(0);
  347. shmobile_earlytimer_init();
  348. }
  349. void __init r8a7740_add_early_devices(void)
  350. {
  351. early_platform_add_devices(r8a7740_early_devices,
  352. ARRAY_SIZE(r8a7740_early_devices));
  353. /* setup early console here as well */
  354. shmobile_setup_console();
  355. /* override timer setup with soc-specific code */
  356. shmobile_timer.init = r8a7740_earlytimer_init;
  357. }