setup-r8a7740.c 8.8 KB

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