board-g4evm.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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. #include <asm/mach/time.h>
  41. /*
  42. * SDHI
  43. *
  44. * SDHI0 : card detection is possible
  45. * SDHI1 : card detection is impossible
  46. *
  47. * [G4-MAIN-BOARD]
  48. * JP74 : short # DBG_2V8A for SDHI0
  49. * JP75 : NC # DBG_3V3A for SDHI0
  50. * JP76 : NC # DBG_3V3A_SD for SDHI0
  51. * JP77 : NC # 3V3A_SDIO for SDHI1
  52. * JP78 : short # DBG_2V8A for SDHI1
  53. * JP79 : NC # DBG_3V3A for SDHI1
  54. * JP80 : NC # DBG_3V3A_SD for SDHI1
  55. *
  56. * [G4-CORE-BOARD]
  57. * S32 : all off # to dissever from G3-CORE_DBG board
  58. * S33 : all off # to dissever from G3-CORE_DBG board
  59. *
  60. * [G3-CORE_DBG-BOARD]
  61. * S1 : all off # to dissever from G3-CORE_DBG board
  62. * S3 : all off # to dissever from G3-CORE_DBG board
  63. * S4 : all off # to dissever from G3-CORE_DBG board
  64. */
  65. static struct mtd_partition nor_flash_partitions[] = {
  66. {
  67. .name = "loader",
  68. .offset = 0x00000000,
  69. .size = 512 * 1024,
  70. },
  71. {
  72. .name = "bootenv",
  73. .offset = MTDPART_OFS_APPEND,
  74. .size = 512 * 1024,
  75. },
  76. {
  77. .name = "kernel_ro",
  78. .offset = MTDPART_OFS_APPEND,
  79. .size = 8 * 1024 * 1024,
  80. .mask_flags = MTD_WRITEABLE,
  81. },
  82. {
  83. .name = "kernel",
  84. .offset = MTDPART_OFS_APPEND,
  85. .size = 8 * 1024 * 1024,
  86. },
  87. {
  88. .name = "data",
  89. .offset = MTDPART_OFS_APPEND,
  90. .size = MTDPART_SIZ_FULL,
  91. },
  92. };
  93. static struct physmap_flash_data nor_flash_data = {
  94. .width = 2,
  95. .parts = nor_flash_partitions,
  96. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  97. };
  98. static struct resource nor_flash_resources[] = {
  99. [0] = {
  100. .start = 0x00000000,
  101. .end = 0x08000000 - 1,
  102. .flags = IORESOURCE_MEM,
  103. }
  104. };
  105. static struct platform_device nor_flash_device = {
  106. .name = "physmap-flash",
  107. .dev = {
  108. .platform_data = &nor_flash_data,
  109. },
  110. .num_resources = ARRAY_SIZE(nor_flash_resources),
  111. .resource = nor_flash_resources,
  112. };
  113. /* USBHS */
  114. static void usb_host_port_power(int port, int power)
  115. {
  116. if (!power) /* only power-on supported for now */
  117. return;
  118. /* set VBOUT/PWEN and EXTLP0 in DVSTCTR */
  119. __raw_writew(__raw_readw(0xe6890008) | 0x600, 0xe6890008);
  120. }
  121. static struct r8a66597_platdata usb_host_data = {
  122. .on_chip = 1,
  123. .port_power = usb_host_port_power,
  124. };
  125. static struct resource usb_host_resources[] = {
  126. [0] = {
  127. .name = "USBHS",
  128. .start = 0xe6890000,
  129. .end = 0xe68900e5,
  130. .flags = IORESOURCE_MEM,
  131. },
  132. [1] = {
  133. .start = evt2irq(0x0a20), /* USBHS_USHI0 */
  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 = evt2irq(0x0be0), /* KEYSC_KEY */
  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 = evt2irq(0x0e00), /* SDHI0 */
  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 = evt2irq(0x0e80), /* SDHI1 */
  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 and console here as well */
  243. sh7377_add_early_devices();
  244. shmobile_setup_console();
  245. }
  246. #define GPIO_SDHID0_D0 0xe60520fc
  247. #define GPIO_SDHID0_D1 0xe60520fd
  248. #define GPIO_SDHID0_D2 0xe60520fe
  249. #define GPIO_SDHID0_D3 0xe60520ff
  250. #define GPIO_SDHICMD0 0xe6052100
  251. #define GPIO_SDHID1_D0 0xe6052103
  252. #define GPIO_SDHID1_D1 0xe6052104
  253. #define GPIO_SDHID1_D2 0xe6052105
  254. #define GPIO_SDHID1_D3 0xe6052106
  255. #define GPIO_SDHICMD1 0xe6052107
  256. /*
  257. * FIXME !!
  258. *
  259. * gpio_pull_up is quick_hack.
  260. *
  261. * current gpio frame work doesn't have
  262. * the method to control only pull up/down/free.
  263. * this function should be replaced by correct gpio function
  264. */
  265. static void __init gpio_pull_up(u32 addr)
  266. {
  267. u8 data = __raw_readb(addr);
  268. data &= 0x0F;
  269. data |= 0xC0;
  270. __raw_writeb(data, addr);
  271. }
  272. static void __init g4evm_init(void)
  273. {
  274. sh7377_pinmux_init();
  275. /* Lit DS14 LED */
  276. gpio_request(GPIO_PORT109, NULL);
  277. gpio_direction_output(GPIO_PORT109, 1);
  278. gpio_export(GPIO_PORT109, 1);
  279. /* Lit DS15 LED */
  280. gpio_request(GPIO_PORT110, NULL);
  281. gpio_direction_output(GPIO_PORT110, 1);
  282. gpio_export(GPIO_PORT110, 1);
  283. /* Lit DS16 LED */
  284. gpio_request(GPIO_PORT112, NULL);
  285. gpio_direction_output(GPIO_PORT112, 1);
  286. gpio_export(GPIO_PORT112, 1);
  287. /* Lit DS17 LED */
  288. gpio_request(GPIO_PORT113, NULL);
  289. gpio_direction_output(GPIO_PORT113, 1);
  290. gpio_export(GPIO_PORT113, 1);
  291. /* USBHS */
  292. gpio_request(GPIO_FN_VBUS_0, NULL);
  293. gpio_request(GPIO_FN_PWEN, NULL);
  294. gpio_request(GPIO_FN_OVCN, NULL);
  295. gpio_request(GPIO_FN_OVCN2, NULL);
  296. gpio_request(GPIO_FN_EXTLP, NULL);
  297. gpio_request(GPIO_FN_IDIN, NULL);
  298. /* setup USB phy */
  299. __raw_writew(0x0200, 0xe605810a); /* USBCR1 */
  300. __raw_writew(0x00e0, 0xe60581c0); /* CPFCH */
  301. __raw_writew(0x6010, 0xe60581c6); /* CGPOSR */
  302. __raw_writew(0x8a0a, 0xe605810c); /* USBCR2 */
  303. /* KEYSC @ CN31 */
  304. gpio_request(GPIO_FN_PORT60_KEYOUT5, NULL);
  305. gpio_request(GPIO_FN_PORT61_KEYOUT4, NULL);
  306. gpio_request(GPIO_FN_PORT62_KEYOUT3, NULL);
  307. gpio_request(GPIO_FN_PORT63_KEYOUT2, NULL);
  308. gpio_request(GPIO_FN_PORT64_KEYOUT1, NULL);
  309. gpio_request(GPIO_FN_PORT65_KEYOUT0, NULL);
  310. gpio_request(GPIO_FN_PORT66_KEYIN0_PU, NULL);
  311. gpio_request(GPIO_FN_PORT67_KEYIN1_PU, NULL);
  312. gpio_request(GPIO_FN_PORT68_KEYIN2_PU, NULL);
  313. gpio_request(GPIO_FN_PORT69_KEYIN3_PU, NULL);
  314. gpio_request(GPIO_FN_PORT70_KEYIN4_PU, NULL);
  315. gpio_request(GPIO_FN_PORT71_KEYIN5_PU, NULL);
  316. gpio_request(GPIO_FN_PORT72_KEYIN6_PU, NULL);
  317. /* SDHI0 */
  318. gpio_request(GPIO_FN_SDHICLK0, NULL);
  319. gpio_request(GPIO_FN_SDHICD0, NULL);
  320. gpio_request(GPIO_FN_SDHID0_0, NULL);
  321. gpio_request(GPIO_FN_SDHID0_1, NULL);
  322. gpio_request(GPIO_FN_SDHID0_2, NULL);
  323. gpio_request(GPIO_FN_SDHID0_3, NULL);
  324. gpio_request(GPIO_FN_SDHICMD0, NULL);
  325. gpio_request(GPIO_FN_SDHIWP0, NULL);
  326. gpio_pull_up(GPIO_SDHID0_D0);
  327. gpio_pull_up(GPIO_SDHID0_D1);
  328. gpio_pull_up(GPIO_SDHID0_D2);
  329. gpio_pull_up(GPIO_SDHID0_D3);
  330. gpio_pull_up(GPIO_SDHICMD0);
  331. /* SDHI1 */
  332. gpio_request(GPIO_FN_SDHICLK1, NULL);
  333. gpio_request(GPIO_FN_SDHID1_0, NULL);
  334. gpio_request(GPIO_FN_SDHID1_1, NULL);
  335. gpio_request(GPIO_FN_SDHID1_2, NULL);
  336. gpio_request(GPIO_FN_SDHID1_3, NULL);
  337. gpio_request(GPIO_FN_SDHICMD1, NULL);
  338. gpio_pull_up(GPIO_SDHID1_D0);
  339. gpio_pull_up(GPIO_SDHID1_D1);
  340. gpio_pull_up(GPIO_SDHID1_D2);
  341. gpio_pull_up(GPIO_SDHID1_D3);
  342. gpio_pull_up(GPIO_SDHICMD1);
  343. sh7377_add_standard_devices();
  344. platform_add_devices(g4evm_devices, ARRAY_SIZE(g4evm_devices));
  345. }
  346. static void __init g4evm_timer_init(void)
  347. {
  348. sh7377_clock_init();
  349. shmobile_timer.init();
  350. }
  351. static struct sys_timer g4evm_timer = {
  352. .init = g4evm_timer_init,
  353. };
  354. MACHINE_START(G4EVM, "g4evm")
  355. .phys_io = 0xe6000000,
  356. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  357. .map_io = g4evm_map_io,
  358. .init_irq = sh7377_init_irq,
  359. .init_machine = g4evm_init,
  360. .timer = &g4evm_timer,
  361. MACHINE_END