setup-r8a7740.c 7.9 KB

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