board-g4evm.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * G4EVM 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/usb/r8a66597.h>
  30. #include <linux/io.h>
  31. #include <linux/input.h>
  32. #include <linux/input/sh_keysc.h>
  33. #include <linux/gpio.h>
  34. #include <mach/sh7377.h>
  35. #include <mach/common.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. static struct mtd_partition nor_flash_partitions[] = {
  40. {
  41. .name = "loader",
  42. .offset = 0x00000000,
  43. .size = 512 * 1024,
  44. },
  45. {
  46. .name = "bootenv",
  47. .offset = MTDPART_OFS_APPEND,
  48. .size = 512 * 1024,
  49. },
  50. {
  51. .name = "kernel_ro",
  52. .offset = MTDPART_OFS_APPEND,
  53. .size = 8 * 1024 * 1024,
  54. .mask_flags = MTD_WRITEABLE,
  55. },
  56. {
  57. .name = "kernel",
  58. .offset = MTDPART_OFS_APPEND,
  59. .size = 8 * 1024 * 1024,
  60. },
  61. {
  62. .name = "data",
  63. .offset = MTDPART_OFS_APPEND,
  64. .size = MTDPART_SIZ_FULL,
  65. },
  66. };
  67. static struct physmap_flash_data nor_flash_data = {
  68. .width = 2,
  69. .parts = nor_flash_partitions,
  70. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  71. };
  72. static struct resource nor_flash_resources[] = {
  73. [0] = {
  74. .start = 0x00000000,
  75. .end = 0x08000000 - 1,
  76. .flags = IORESOURCE_MEM,
  77. }
  78. };
  79. static struct platform_device nor_flash_device = {
  80. .name = "physmap-flash",
  81. .dev = {
  82. .platform_data = &nor_flash_data,
  83. },
  84. .num_resources = ARRAY_SIZE(nor_flash_resources),
  85. .resource = nor_flash_resources,
  86. };
  87. /* USBHS */
  88. void usb_host_port_power(int port, int power)
  89. {
  90. if (!power) /* only power-on supported for now */
  91. return;
  92. /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
  93. __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
  94. }
  95. static struct r8a66597_platdata usb_host_data = {
  96. .on_chip = 1,
  97. .port_power = usb_host_port_power,
  98. };
  99. static struct resource usb_host_resources[] = {
  100. [0] = {
  101. .name = "USBHS",
  102. .start = 0xe6890000,
  103. .end = 0xe68900e5,
  104. .flags = IORESOURCE_MEM,
  105. },
  106. [1] = {
  107. .start = 65,
  108. .end = 65,
  109. .flags = IORESOURCE_IRQ,
  110. },
  111. };
  112. static struct platform_device usb_host_device = {
  113. .name = "r8a66597_hcd",
  114. .id = 0,
  115. .dev = {
  116. .platform_data = &usb_host_data,
  117. .dma_mask = NULL,
  118. .coherent_dma_mask = 0xffffffff,
  119. },
  120. .num_resources = ARRAY_SIZE(usb_host_resources),
  121. .resource = usb_host_resources,
  122. };
  123. /* KEYSC */
  124. static struct sh_keysc_info keysc_info = {
  125. .mode = SH_KEYSC_MODE_5,
  126. .scan_timing = 3,
  127. .delay = 100,
  128. .keycodes = {
  129. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F,
  130. KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L,
  131. KEY_M, KEY_N, KEY_U, KEY_P, KEY_Q, KEY_R,
  132. KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
  133. KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE,
  134. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
  135. KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
  136. },
  137. };
  138. static struct resource keysc_resources[] = {
  139. [0] = {
  140. .name = "KEYSC",
  141. .start = 0xe61b0000,
  142. .end = 0xe61b000f,
  143. .flags = IORESOURCE_MEM,
  144. },
  145. [1] = {
  146. .start = 79,
  147. .flags = IORESOURCE_IRQ,
  148. },
  149. };
  150. static struct platform_device keysc_device = {
  151. .name = "sh_keysc",
  152. .id = 0, /* keysc0 clock */
  153. .num_resources = ARRAY_SIZE(keysc_resources),
  154. .resource = keysc_resources,
  155. .dev = {
  156. .platform_data = &keysc_info,
  157. },
  158. };
  159. static struct platform_device *g4evm_devices[] __initdata = {
  160. &nor_flash_device,
  161. &usb_host_device,
  162. &keysc_device,
  163. };
  164. static struct map_desc g4evm_io_desc[] __initdata = {
  165. /* create a 1:1 entity map for 0xe6xxxxxx
  166. * used by CPGA, INTC and PFC.
  167. */
  168. {
  169. .virtual = 0xe6000000,
  170. .pfn = __phys_to_pfn(0xe6000000),
  171. .length = 256 << 20,
  172. .type = MT_DEVICE_NONSHARED
  173. },
  174. };
  175. static void __init g4evm_map_io(void)
  176. {
  177. iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc));
  178. /* setup early devices, clocks and console here as well */
  179. sh7377_add_early_devices();
  180. sh7367_clock_init(); /* use g3 clocks for now */
  181. shmobile_setup_console();
  182. }
  183. static void __init g4evm_init(void)
  184. {
  185. sh7377_pinmux_init();
  186. /* Lit DS14 LED */
  187. gpio_request(GPIO_PORT109, NULL);
  188. gpio_direction_output(GPIO_PORT109, 1);
  189. gpio_export(GPIO_PORT109, 1);
  190. /* Lit DS15 LED */
  191. gpio_request(GPIO_PORT110, NULL);
  192. gpio_direction_output(GPIO_PORT110, 1);
  193. gpio_export(GPIO_PORT110, 1);
  194. /* Lit DS16 LED */
  195. gpio_request(GPIO_PORT112, NULL);
  196. gpio_direction_output(GPIO_PORT112, 1);
  197. gpio_export(GPIO_PORT112, 1);
  198. /* Lit DS17 LED */
  199. gpio_request(GPIO_PORT113, NULL);
  200. gpio_direction_output(GPIO_PORT113, 1);
  201. gpio_export(GPIO_PORT113, 1);
  202. /* USBHS */
  203. gpio_request(GPIO_FN_VBUS_0, NULL);
  204. gpio_request(GPIO_FN_PWEN, NULL);
  205. gpio_request(GPIO_FN_OVCN, NULL);
  206. gpio_request(GPIO_FN_OVCN2, NULL);
  207. gpio_request(GPIO_FN_EXTLP, NULL);
  208. gpio_request(GPIO_FN_IDIN, NULL);
  209. /* enable clock in SMSTPCR3 */
  210. __raw_writel(__raw_readl(0xe615013c) & ~(1 << 22), 0xe615013c);
  211. /* setup USB phy */
  212. __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
  213. __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
  214. __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
  215. __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
  216. /* KEYSC @ CN31 */
  217. gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL);
  218. gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL);
  219. gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL);
  220. gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL);
  221. gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL);
  222. gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL);
  223. gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL);
  224. gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL);
  225. gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL);
  226. gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL);
  227. gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL);
  228. gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
  229. gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
  230. sh7377_add_standard_devices();
  231. platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
  232. }
  233. MACHINE_START(G4EVM, "g4evm")
  234. .phys_io = 0xe6000000,
  235. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  236. .map_io = g4evm_map_io,
  237. .init_irq = sh7377_init_irq,
  238. .init_machine = g4evm_init,
  239. .timer = &shmobile_timer,
  240. MACHINE_END