board-g3evm.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*
  2. * G3EVM board support
  3. *
  4. * Copyright (C) 2010 Magnus Damm
  5. * Copyright (C) 2008 Yoshihiro Shimoda
  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/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/delay.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/partitions.h>
  28. #include <linux/mtd/physmap.h>
  29. #include <linux/mtd/sh_flctl.h>
  30. #include <linux/usb/r8a66597.h>
  31. #include <linux/io.h>
  32. #include <linux/gpio.h>
  33. #include <linux/input.h>
  34. #include <linux/input/sh_keysc.h>
  35. #include <linux/dma-mapping.h>
  36. #include <mach/sh7367.h>
  37. #include <mach/common.h>
  38. #include <asm/mach-types.h>
  39. #include <asm/mach/arch.h>
  40. #include <asm/mach/map.h>
  41. #include <asm/mach/time.h>
  42. /*
  43. * IrDA
  44. *
  45. * S67: 5bit : ON power
  46. * : 6bit : ON remote control
  47. * OFF IrDA
  48. */
  49. static struct mtd_partition nor_flash_partitions[] = {
  50. {
  51. .name = "loader",
  52. .offset = 0x00000000,
  53. .size = 512 * 1024,
  54. },
  55. {
  56. .name = "bootenv",
  57. .offset = MTDPART_OFS_APPEND,
  58. .size = 512 * 1024,
  59. },
  60. {
  61. .name = "kernel_ro",
  62. .offset = MTDPART_OFS_APPEND,
  63. .size = 8 * 1024 * 1024,
  64. .mask_flags = MTD_WRITEABLE,
  65. },
  66. {
  67. .name = "kernel",
  68. .offset = MTDPART_OFS_APPEND,
  69. .size = 8 * 1024 * 1024,
  70. },
  71. {
  72. .name = "data",
  73. .offset = MTDPART_OFS_APPEND,
  74. .size = MTDPART_SIZ_FULL,
  75. },
  76. };
  77. static struct physmap_flash_data nor_flash_data = {
  78. .width = 2,
  79. .parts = nor_flash_partitions,
  80. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  81. };
  82. static struct resource nor_flash_resources[] = {
  83. [0] = {
  84. .start = 0x00000000,
  85. .end = 0x08000000 - 1,
  86. .flags = IORESOURCE_MEM,
  87. }
  88. };
  89. static struct platform_device nor_flash_device = {
  90. .name = "physmap-flash",
  91. .dev = {
  92. .platform_data = &nor_flash_data,
  93. },
  94. .num_resources = ARRAY_SIZE(nor_flash_resources),
  95. .resource = nor_flash_resources,
  96. };
  97. /* USBHS */
  98. static void usb_host_port_power(int port, int power)
  99. {
  100. if (!power) /* only power-on supported for now */
  101. return;
  102. /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
  103. __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
  104. }
  105. static struct r8a66597_platdata usb_host_data = {
  106. .on_chip = 1,
  107. .port_power = usb_host_port_power,
  108. };
  109. static struct resource usb_host_resources[] = {
  110. [0] = {
  111. .name = "USBHS",
  112. .start = 0xe6890000,
  113. .end = 0xe68900e5,
  114. .flags = IORESOURCE_MEM,
  115. },
  116. [1] = {
  117. .start = evt2irq(0xa20), /* USBHS_USHI0 */
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. static struct platform_device usb_host_device = {
  122. .name = "r8a66597_hcd",
  123. .id = 0,
  124. .dev = {
  125. .platform_data = &usb_host_data,
  126. .dma_mask = NULL,
  127. .coherent_dma_mask = 0xffffffff,
  128. },
  129. .num_resources = ARRAY_SIZE(usb_host_resources),
  130. .resource = usb_host_resources,
  131. };
  132. /* KEYSC */
  133. static struct sh_keysc_info keysc_info = {
  134. .mode = SH_KEYSC_MODE_5,
  135. .scan_timing = 3,
  136. .delay = 100,
  137. .keycodes = {
  138. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G,
  139. KEY_H, KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N,
  140. KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U,
  141. KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP,
  142. KEY_WAKEUP, KEY_COFFEE, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
  143. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
  144. },
  145. };
  146. static struct resource keysc_resources[] = {
  147. [0] = {
  148. .name = "KEYSC",
  149. .start = 0xe61b0000,
  150. .end = 0xe61b000f,
  151. .flags = IORESOURCE_MEM,
  152. },
  153. [1] = {
  154. .start = evt2irq(0xbe0), /* KEYSC_KEY */
  155. .flags = IORESOURCE_IRQ,
  156. },
  157. };
  158. static struct platform_device keysc_device = {
  159. .name = "sh_keysc",
  160. .num_resources = ARRAY_SIZE(keysc_resources),
  161. .resource = keysc_resources,
  162. .dev = {
  163. .platform_data = &keysc_info,
  164. },
  165. };
  166. static struct mtd_partition nand_partition_info[] = {
  167. {
  168. .name = "system",
  169. .offset = 0,
  170. .size = 64 * 1024 * 1024,
  171. },
  172. {
  173. .name = "userdata",
  174. .offset = MTDPART_OFS_APPEND,
  175. .size = 128 * 1024 * 1024,
  176. },
  177. {
  178. .name = "cache",
  179. .offset = MTDPART_OFS_APPEND,
  180. .size = 64 * 1024 * 1024,
  181. },
  182. };
  183. static struct resource nand_flash_resources[] = {
  184. [0] = {
  185. .start = 0xe6a30000,
  186. .end = 0xe6a3009b,
  187. .flags = IORESOURCE_MEM,
  188. }
  189. };
  190. static struct sh_flctl_platform_data nand_flash_data = {
  191. .parts = nand_partition_info,
  192. .nr_parts = ARRAY_SIZE(nand_partition_info),
  193. .flcmncr_val = QTSEL_E | FCKSEL_E | TYPESEL_SET | NANWF_E
  194. | SHBUSSEL | SEL_16BIT,
  195. };
  196. static struct platform_device nand_flash_device = {
  197. .name = "sh_flctl",
  198. .resource = nand_flash_resources,
  199. .num_resources = ARRAY_SIZE(nand_flash_resources),
  200. .dev = {
  201. .platform_data = &nand_flash_data,
  202. },
  203. };
  204. static struct resource irda_resources[] = {
  205. [0] = {
  206. .start = 0xE6D00000,
  207. .end = 0xE6D01FD4 - 1,
  208. .flags = IORESOURCE_MEM,
  209. },
  210. [1] = {
  211. .start = evt2irq(0x480), /* IRDA */
  212. .flags = IORESOURCE_IRQ,
  213. },
  214. };
  215. static struct platform_device irda_device = {
  216. .name = "sh_irda",
  217. .id = -1,
  218. .resource = irda_resources,
  219. .num_resources = ARRAY_SIZE(irda_resources),
  220. };
  221. static struct platform_device *g3evm_devices[] __initdata = {
  222. &nor_flash_device,
  223. &usb_host_device,
  224. &keysc_device,
  225. &nand_flash_device,
  226. &irda_device,
  227. };
  228. static struct map_desc g3evm_io_desc[] __initdata = {
  229. /* create a 1:1 entity map for 0xe6xxxxxx
  230. * used by CPGA, INTC and PFC.
  231. */
  232. {
  233. .virtual = 0xe6000000,
  234. .pfn = __phys_to_pfn(0xe6000000),
  235. .length = 256 << 20,
  236. .type = MT_DEVICE_NONSHARED
  237. },
  238. };
  239. static void __init g3evm_map_io(void)
  240. {
  241. iotable_init(g3evm_io_desc, ARRAY_SIZE(g3evm_io_desc));
  242. /* setup early devices and console here as well */
  243. sh7367_add_early_devices();
  244. shmobile_setup_console();
  245. }
  246. static void __init g3evm_init(void)
  247. {
  248. sh7367_pinmux_init();
  249. /* Lit DS4 LED */
  250. gpio_request(GPIO_PORT22, NULL);
  251. gpio_direction_output(GPIO_PORT22, 1);
  252. gpio_export(GPIO_PORT22, 0);
  253. /* Lit DS8 LED */
  254. gpio_request(GPIO_PORT23, NULL);
  255. gpio_direction_output(GPIO_PORT23, 1);
  256. gpio_export(GPIO_PORT23, 0);
  257. /* Lit DS3 LED */
  258. gpio_request(GPIO_PORT24, NULL);
  259. gpio_direction_output(GPIO_PORT24, 1);
  260. gpio_export(GPIO_PORT24, 0);
  261. /* SCIFA1 */
  262. gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
  263. gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
  264. gpio_request(GPIO_FN_SCIFA1_CTS, NULL);
  265. gpio_request(GPIO_FN_SCIFA1_RTS, NULL);
  266. /* USBHS */
  267. gpio_request(GPIO_FN_VBUS0, NULL);
  268. gpio_request(GPIO_FN_PWEN, NULL);
  269. gpio_request(GPIO_FN_OVCN, NULL);
  270. gpio_request(GPIO_FN_OVCN2, NULL);
  271. gpio_request(GPIO_FN_EXTLP, NULL);
  272. gpio_request(GPIO_FN_IDIN, NULL);
  273. /* setup USB phy */
  274. __raw_writew(0x0300, 0xe605810a); /* USBCR1 */
  275. __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
  276. __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
  277. __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
  278. /* KEYSC @ CN7 */
  279. gpio_request(GPIO_FN_PORT42_KEYOUT0, NULL);
  280. gpio_request(GPIO_FN_PORT43_KEYOUT1, NULL);
  281. gpio_request(GPIO_FN_PORT44_KEYOUT2, NULL);
  282. gpio_request(GPIO_FN_PORT45_KEYOUT3, NULL);
  283. gpio_request(GPIO_FN_PORT46_KEYOUT4, NULL);
  284. gpio_request(GPIO_FN_PORT47_KEYOUT5, NULL);
  285. gpio_request(GPIO_FN_PORT48_KEYIN0_PU, NULL);
  286. gpio_request(GPIO_FN_PORT49_KEYIN1_PU, NULL);
  287. gpio_request(GPIO_FN_PORT50_KEYIN2_PU, NULL);
  288. gpio_request(GPIO_FN_PORT55_KEYIN3_PU, NULL);
  289. gpio_request(GPIO_FN_PORT56_KEYIN4_PU, NULL);
  290. gpio_request(GPIO_FN_PORT57_KEYIN5_PU, NULL);
  291. gpio_request(GPIO_FN_PORT58_KEYIN6_PU, NULL);
  292. /* FLCTL */
  293. gpio_request(GPIO_FN_FCE0, NULL);
  294. gpio_request(GPIO_FN_D0_ED0_NAF0, NULL);
  295. gpio_request(GPIO_FN_D1_ED1_NAF1, NULL);
  296. gpio_request(GPIO_FN_D2_ED2_NAF2, NULL);
  297. gpio_request(GPIO_FN_D3_ED3_NAF3, NULL);
  298. gpio_request(GPIO_FN_D4_ED4_NAF4, NULL);
  299. gpio_request(GPIO_FN_D5_ED5_NAF5, NULL);
  300. gpio_request(GPIO_FN_D6_ED6_NAF6, NULL);
  301. gpio_request(GPIO_FN_D7_ED7_NAF7, NULL);
  302. gpio_request(GPIO_FN_D8_ED8_NAF8, NULL);
  303. gpio_request(GPIO_FN_D9_ED9_NAF9, NULL);
  304. gpio_request(GPIO_FN_D10_ED10_NAF10, NULL);
  305. gpio_request(GPIO_FN_D11_ED11_NAF11, NULL);
  306. gpio_request(GPIO_FN_D12_ED12_NAF12, NULL);
  307. gpio_request(GPIO_FN_D13_ED13_NAF13, NULL);
  308. gpio_request(GPIO_FN_D14_ED14_NAF14, NULL);
  309. gpio_request(GPIO_FN_D15_ED15_NAF15, NULL);
  310. gpio_request(GPIO_FN_WE0_XWR0_FWE, NULL);
  311. gpio_request(GPIO_FN_FRB, NULL);
  312. /* FOE, FCDE, FSC on dedicated pins */
  313. __raw_writel(__raw_readl(0xe6158048) & ~(1 << 15), 0xe6158048);
  314. /* IrDA */
  315. gpio_request(GPIO_FN_IRDA_OUT, NULL);
  316. gpio_request(GPIO_FN_IRDA_IN, NULL);
  317. gpio_request(GPIO_FN_IRDA_FIRSEL, NULL);
  318. sh7367_add_standard_devices();
  319. platform_add_devices(g3evm_devices, ARRAY_SIZE(g3evm_devices));
  320. }
  321. static void __init g3evm_timer_init(void)
  322. {
  323. sh7367_clock_init();
  324. shmobile_timer.init();
  325. }
  326. static struct sys_timer g3evm_timer = {
  327. .init = g3evm_timer_init,
  328. };
  329. MACHINE_START(G3EVM, "g3evm")
  330. .map_io = g3evm_map_io,
  331. .init_irq = sh7367_init_irq,
  332. .handle_irq = shmobile_handle_irq_intc,
  333. .init_machine = g3evm_init,
  334. .timer = &g3evm_timer,
  335. MACHINE_END