board-g4evm.c 9.6 KB

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