setup-r8a7740.c 8.8 KB

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