board-g4evm.c 10 KB

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