setup-r8a7740.c 7.9 KB

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