board-g4evm.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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/mfd/sh_mobile_sdhi.h>
  34. #include <linux/gpio.h>
  35. #include <mach/sh7377.h>
  36. #include <mach/common.h>
  37. #include <asm/mach-types.h>
  38. #include <asm/mach/arch.h>
  39. #include <asm/mach/map.h>
  40. /*
  41. * SDHI
  42. *
  43. * SDHI0 : card detection is possible
  44. * SDHI1 : card detection is impossible
  45. *
  46. * [G4-MAIN-BOARD]
  47. * JP74 : short # DBG_2V8A for SDHI0
  48. * JP75 : NC # DBG_3V3A for SDHI0
  49. * JP76 : NC # DBG_3V3A_SD for SDHI0
  50. * JP77 : NC # 3V3A_SDIO for SDHI1
  51. * JP78 : short # DBG_2V8A for SDHI1
  52. * JP79 : NC # DBG_3V3A for SDHI1
  53. * JP80 : NC # DBG_3V3A_SD for SDHI1
  54. *
  55. * [G4-CORE-BOARD]
  56. * S32 : all off # to dissever from G3-CORE_DBG board
  57. * S33 : all off # to dissever from G3-CORE_DBG board
  58. *
  59. * [G3-CORE_DBG-BOARD]
  60. * S1 : all off # to dissever from G3-CORE_DBG board
  61. * S3 : all off # to dissever from G3-CORE_DBG board
  62. * S4 : all off # to dissever from G3-CORE_DBG board
  63. */
  64. static struct mtd_partition nor_flash_partitions[] = {
  65. {
  66. .name = "loader",
  67. .offset = 0x00000000,
  68. .size = 512 * 1024,
  69. },
  70. {
  71. .name = "bootenv",
  72. .offset = MTDPART_OFS_APPEND,
  73. .size = 512 * 1024,
  74. },
  75. {
  76. .name = "kernel_ro",
  77. .offset = MTDPART_OFS_APPEND,
  78. .size = 8 * 1024 * 1024,
  79. .mask_flags = MTD_WRITEABLE,
  80. },
  81. {
  82. .name = "kernel",
  83. .offset = MTDPART_OFS_APPEND,
  84. .size = 8 * 1024 * 1024,
  85. },
  86. {
  87. .name = "data",
  88. .offset = MTDPART_OFS_APPEND,
  89. .size = MTDPART_SIZ_FULL,
  90. },
  91. };
  92. static struct physmap_flash_data nor_flash_data = {
  93. .width = 2,
  94. .parts = nor_flash_partitions,
  95. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  96. };
  97. static struct resource nor_flash_resources[] = {
  98. [0] = {
  99. .start = 0x00000000,
  100. .end = 0x08000000 - 1,
  101. .flags = IORESOURCE_MEM,
  102. }
  103. };
  104. static struct platform_device nor_flash_device = {
  105. .name = "physmap-flash",
  106. .dev = {
  107. .platform_data = &nor_flash_data,
  108. },
  109. .num_resources = ARRAY_SIZE(nor_flash_resources),
  110. .resource = nor_flash_resources,
  111. };
  112. /* USBHS */
  113. void usb_host_port_power(int port, int power)
  114. {
  115. if (!power) /* only power-on supported for now */
  116. return;
  117. /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
  118. __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
  119. }
  120. static struct r8a66597_platdata usb_host_data = {
  121. .on_chip = 1,
  122. .port_power = usb_host_port_power,
  123. };
  124. static struct resource usb_host_resources[] = {
  125. [0] = {
  126. .name = "USBHS",
  127. .start = 0xe6890000,
  128. .end = 0xe68900e5,
  129. .flags = IORESOURCE_MEM,
  130. },
  131. [1] = {
  132. .start = 65,
  133. .end = 65,
  134. .flags = IORESOURCE_IRQ,
  135. },
  136. };
  137. static struct platform_device usb_host_device = {
  138. .name = "r8a66597_hcd",
  139. .id = 0,
  140. .dev = {
  141. .platform_data = &usb_host_data,
  142. .dma_mask = NULL,
  143. .coherent_dma_mask = 0xffffffff,
  144. },
  145. .num_resources = ARRAY_SIZE(usb_host_resources),
  146. .resource = usb_host_resources,
  147. };
  148. /* KEYSC */
  149. static struct sh_keysc_info keysc_info = {
  150. .mode = SH_KEYSC_MODE_5,
  151. .scan_timing = 3,
  152. .delay = 100,
  153. .keycodes = {
  154. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F,
  155. KEY_G, KEY_H, KEY_I, KEY_J, KEY_K, KEY_L,
  156. KEY_M, KEY_N, KEY_U, KEY_P, KEY_Q, KEY_R,
  157. KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
  158. KEY_Y, KEY_Z, KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE,
  159. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
  160. KEY_6, KEY_7, KEY_8, KEY_9, KEY_STOP, KEY_COMPUTER,
  161. },
  162. };
  163. static struct resource keysc_resources[] = {
  164. [0] = {
  165. .name = "KEYSC",
  166. .start = 0xe61b0000,
  167. .end = 0xe61b000f,
  168. .flags = IORESOURCE_MEM,
  169. },
  170. [1] = {
  171. .start = 79,
  172. .flags = IORESOURCE_IRQ,
  173. },
  174. };
  175. static struct platform_device keysc_device = {
  176. .name = "sh_keysc",
  177. .id = 0, /* keysc0 clock */
  178. .num_resources = ARRAY_SIZE(keysc_resources),
  179. .resource = keysc_resources,
  180. .dev = {
  181. .platform_data = &keysc_info,
  182. },
  183. };
  184. /* SDHI */
  185. static struct resource sdhi0_resources[] = {
  186. [0] = {
  187. .name = "SDHI0",
  188. .start = 0xe6d50000,
  189. .end = 0xe6d501ff,
  190. .flags = IORESOURCE_MEM,
  191. },
  192. [1] = {
  193. .start = 96,
  194. .flags = IORESOURCE_IRQ,
  195. },
  196. };
  197. static struct platform_device sdhi0_device = {
  198. .name = "sh_mobile_sdhi",
  199. .num_resources = ARRAY_SIZE(sdhi0_resources),
  200. .resource = sdhi0_resources,
  201. .id = 0,
  202. };
  203. static struct resource sdhi1_resources[] = {
  204. [0] = {
  205. .name = "SDHI1",
  206. .start = 0xe6d60000,
  207. .end = 0xe6d601ff,
  208. .flags = IORESOURCE_MEM,
  209. },
  210. [1] = {
  211. .start = 100,
  212. .flags = IORESOURCE_IRQ,
  213. },
  214. };
  215. static struct platform_device sdhi1_device = {
  216. .name = "sh_mobile_sdhi",
  217. .num_resources = ARRAY_SIZE(sdhi1_resources),
  218. .resource = sdhi1_resources,
  219. .id = 1,
  220. };
  221. static struct platform_device *g4evm_devices[] __initdata = {
  222. &nor_flash_device,
  223. &usb_host_device,
  224. &keysc_device,
  225. &sdhi0_device,
  226. &sdhi1_device,
  227. };
  228. static struct map_desc g4evm_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 g4evm_map_io(void)
  240. {
  241. iotable_init(g4evm_io_desc, ARRAY_SIZE(g4evm_io_desc));
  242. /* setup early devices, clocks and console here as well */
  243. sh7377_add_early_devices();
  244. sh7367_clock_init(); /* use g3 clocks for now */
  245. shmobile_setup_console();
  246. }
  247. #define GPIO_SDHID0_D0 0xe60520fc
  248. #define GPIO_SDHID0_D1 0xe60520fd
  249. #define GPIO_SDHID0_D2 0xe60520fe
  250. #define GPIO_SDHID0_D3 0xe60520ff
  251. #define GPIO_SDHICMD0 0xe6052100
  252. #define GPIO_SDHID1_D0 0xe6052103
  253. #define GPIO_SDHID1_D1 0xe6052104
  254. #define GPIO_SDHID1_D2 0xe6052105
  255. #define GPIO_SDHID1_D3 0xe6052106
  256. #define GPIO_SDHICMD1 0xe6052107
  257. /*
  258. * FIXME !!
  259. *
  260. * gpio_pull_up is quick_hack.
  261. *
  262. * current gpio frame work doesn't have
  263. * the method to control only pull up/down/free.
  264. * this function should be replaced by correct gpio function
  265. */
  266. static void __init gpio_pull_up(u32 addr)
  267. {
  268. u8 data = __raw_readb(addr);
  269. data &= 0x0F;
  270. data |= 0xC0;
  271. __raw_writeb(data, addr);
  272. }
  273. static void __init g4evm_init(void)
  274. {
  275. sh7377_pinmux_init();
  276. /* Lit DS14 LED */
  277. gpio_request(GPIO_PORT109, NULL);
  278. gpio_direction_output(GPIO_PORT109, 1);
  279. gpio_export(GPIO_PORT109, 1);
  280. /* Lit DS15 LED */
  281. gpio_request(GPIO_PORT110, NULL);
  282. gpio_direction_output(GPIO_PORT110, 1);
  283. gpio_export(GPIO_PORT110, 1);
  284. /* Lit DS16 LED */
  285. gpio_request(GPIO_PORT112, NULL);
  286. gpio_direction_output(GPIO_PORT112, 1);
  287. gpio_export(GPIO_PORT112, 1);
  288. /* Lit DS17 LED */
  289. gpio_request(GPIO_PORT113, NULL);
  290. gpio_direction_output(GPIO_PORT113, 1);
  291. gpio_export(GPIO_PORT113, 1);
  292. /* USBHS */
  293. gpio_request(GPIO_FN_VBUS_0, NULL);
  294. gpio_request(GPIO_FN_PWEN, NULL);
  295. gpio_request(GPIO_FN_OVCN, NULL);
  296. gpio_request(GPIO_FN_OVCN2, NULL);
  297. gpio_request(GPIO_FN_EXTLP, NULL);
  298. gpio_request(GPIO_FN_IDIN, NULL);
  299. /* enable clock in SMSTPCR3 */
  300. __raw_writel(__raw_readl(0xe615013c) & ~(1 << 22), 0xe615013c);
  301. /* setup USB phy */
  302. __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
  303. __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
  304. __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
  305. __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
  306. /* KEYSC @ CN31 */
  307. gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL);
  308. gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL);
  309. gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL);
  310. gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL);
  311. gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL);
  312. gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL);
  313. gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL);
  314. gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL);
  315. gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL);
  316. gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL);
  317. gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL);
  318. gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
  319. gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
  320. /* SDHI0 */
  321. gpio_request(GPIO_FN_SDHICLK0, NULL);
  322. gpio_request(GPIO_FN_SDHICD0, NULL);
  323. gpio_request(GPIO_FN_SDHID0_0, NULL);
  324. gpio_request(GPIO_FN_SDHID0_1, NULL);
  325. gpio_request(GPIO_FN_SDHID0_2, NULL);
  326. gpio_request(GPIO_FN_SDHID0_3, NULL);
  327. gpio_request(GPIO_FN_SDHICMD0, NULL);
  328. gpio_request(GPIO_FN_SDHIWP0, NULL);
  329. gpio_pull_up(GPIO_SDHID0_D0);
  330. gpio_pull_up(GPIO_SDHID0_D1);
  331. gpio_pull_up(GPIO_SDHID0_D2);
  332. gpio_pull_up(GPIO_SDHID0_D3);
  333. gpio_pull_up(GPIO_SDHICMD0);
  334. /* SDHI1 */
  335. gpio_request(GPIO_FN_SDHICLK1, NULL);
  336. gpio_request(GPIO_FN_SDHID1_0, NULL);
  337. gpio_request(GPIO_FN_SDHID1_1, NULL);
  338. gpio_request(GPIO_FN_SDHID1_2, NULL);
  339. gpio_request(GPIO_FN_SDHID1_3, NULL);
  340. gpio_request(GPIO_FN_SDHICMD1, NULL);
  341. gpio_pull_up(GPIO_SDHID1_D0);
  342. gpio_pull_up(GPIO_SDHID1_D1);
  343. gpio_pull_up(GPIO_SDHID1_D2);
  344. gpio_pull_up(GPIO_SDHID1_D3);
  345. gpio_pull_up(GPIO_SDHICMD1);
  346. sh7377_add_standard_devices();
  347. platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
  348. }
  349. MACHINE_START(G4EVM, "g4evm")
  350. .phys_io = 0xe6000000,
  351. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  352. .map_io = g4evm_map_io,
  353. .init_irq = sh7377_init_irq,
  354. .init_machine = g4evm_init,
  355. .timer = &shmobile_timer,
  356. MACHINE_END