board-ap4evb.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * AP4EVB 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/i2c.h>
  30. #include <linux/i2c/tsc2007.h>
  31. #include <linux/io.h>
  32. #include <linux/smsc911x.h>
  33. #include <linux/gpio.h>
  34. #include <linux/input.h>
  35. #include <linux/input/sh_keysc.h>
  36. #include <linux/usb/r8a66597.h>
  37. #include <mach/common.h>
  38. #include <mach/sh7372.h>
  39. #include <asm/mach-types.h>
  40. #include <asm/mach/arch.h>
  41. #include <asm/mach/map.h>
  42. #include <asm/mach/time.h>
  43. /*
  44. * Address Interface BusWidth note
  45. * ------------------------------------------------------------------
  46. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  47. * 0x0800_0000 user area -
  48. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  49. * 0x1400_0000 Ether (LAN9220) 16bit
  50. * 0x1600_0000 user area - cannot use with NAND
  51. * 0x1800_0000 user area -
  52. * 0x1A00_0000 -
  53. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  54. */
  55. /*
  56. * NOR Flash ROM
  57. *
  58. * SW1 | SW2 | SW7 | NOR Flash ROM
  59. * bit1 | bit1 bit2 | bit1 | Memory allocation
  60. * ------+------------+------+------------------
  61. * OFF | ON OFF | ON | Area 0
  62. * OFF | ON OFF | OFF | Area 4
  63. */
  64. /*
  65. * NAND Flash ROM
  66. *
  67. * SW1 | SW2 | SW7 | NAND Flash ROM
  68. * bit1 | bit1 bit2 | bit2 | Memory allocation
  69. * ------+------------+------+------------------
  70. * OFF | ON OFF | ON | FCE 0
  71. * OFF | ON OFF | OFF | FCE 1
  72. */
  73. /*
  74. * SMSC 9220
  75. *
  76. * SW1 SMSC 9220
  77. * -----------------------
  78. * ON access disable
  79. * OFF access enable
  80. */
  81. /*
  82. * LCD / IRQ / KEYSC / IrDA
  83. *
  84. * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (TouchScreen)
  85. * LCD = 2nd LCDC
  86. *
  87. * | SW43 |
  88. * SW3 | ON | OFF |
  89. * -------------+-----------------------+---------------+
  90. * ON | KEY / IrDA | LCD |
  91. * OFF | KEY / IrDA / IRQ | IRQ |
  92. */
  93. /*
  94. * USB
  95. *
  96. * J7 : 1-2 MAX3355E VBUS
  97. * 2-3 DC 5.0V
  98. *
  99. * S39: bit2: off
  100. */
  101. /* MTD */
  102. static struct mtd_partition nor_flash_partitions[] = {
  103. {
  104. .name = "loader",
  105. .offset = 0x00000000,
  106. .size = 512 * 1024,
  107. },
  108. {
  109. .name = "bootenv",
  110. .offset = MTDPART_OFS_APPEND,
  111. .size = 512 * 1024,
  112. },
  113. {
  114. .name = "kernel_ro",
  115. .offset = MTDPART_OFS_APPEND,
  116. .size = 8 * 1024 * 1024,
  117. .mask_flags = MTD_WRITEABLE,
  118. },
  119. {
  120. .name = "kernel",
  121. .offset = MTDPART_OFS_APPEND,
  122. .size = 8 * 1024 * 1024,
  123. },
  124. {
  125. .name = "data",
  126. .offset = MTDPART_OFS_APPEND,
  127. .size = MTDPART_SIZ_FULL,
  128. },
  129. };
  130. static struct physmap_flash_data nor_flash_data = {
  131. .width = 2,
  132. .parts = nor_flash_partitions,
  133. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  134. };
  135. static struct resource nor_flash_resources[] = {
  136. [0] = {
  137. .start = 0x00000000,
  138. .end = 0x08000000 - 1,
  139. .flags = IORESOURCE_MEM,
  140. }
  141. };
  142. static struct platform_device nor_flash_device = {
  143. .name = "physmap-flash",
  144. .dev = {
  145. .platform_data = &nor_flash_data,
  146. },
  147. .num_resources = ARRAY_SIZE(nor_flash_resources),
  148. .resource = nor_flash_resources,
  149. };
  150. /* SMSC 9220 */
  151. static struct resource smc911x_resources[] = {
  152. {
  153. .start = 0x14000000,
  154. .end = 0x16000000 - 1,
  155. .flags = IORESOURCE_MEM,
  156. }, {
  157. .start = 6,
  158. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  159. },
  160. };
  161. static struct smsc911x_platform_config smsc911x_info = {
  162. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  163. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  164. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  165. };
  166. static struct platform_device smc911x_device = {
  167. .name = "smsc911x",
  168. .id = -1,
  169. .num_resources = ARRAY_SIZE(smc911x_resources),
  170. .resource = smc911x_resources,
  171. .dev = {
  172. .platform_data = &smsc911x_info,
  173. },
  174. };
  175. /* KEYSC (Needs SW43 set to ON) */
  176. static struct sh_keysc_info keysc_info = {
  177. .mode = SH_KEYSC_MODE_1,
  178. .scan_timing = 3,
  179. .delay = 2500,
  180. .keycodes = {
  181. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
  182. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
  183. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
  184. KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
  185. KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
  186. },
  187. };
  188. static struct resource keysc_resources[] = {
  189. [0] = {
  190. .name = "KEYSC",
  191. .start = 0xe61b0000,
  192. .end = 0xe61b0063,
  193. .flags = IORESOURCE_MEM,
  194. },
  195. [1] = {
  196. .start = 79,
  197. .flags = IORESOURCE_IRQ,
  198. },
  199. };
  200. static struct platform_device keysc_device = {
  201. .name = "sh_keysc",
  202. .id = 0, /* "keysc0" clock */
  203. .num_resources = ARRAY_SIZE(keysc_resources),
  204. .resource = keysc_resources,
  205. .dev = {
  206. .platform_data = &keysc_info,
  207. },
  208. };
  209. /* SDHI0 */
  210. static struct resource sdhi0_resources[] = {
  211. [0] = {
  212. .name = "SDHI0",
  213. .start = 0xe6850000,
  214. .end = 0xe68501ff,
  215. .flags = IORESOURCE_MEM,
  216. },
  217. [1] = {
  218. .start = 96,
  219. .flags = IORESOURCE_IRQ,
  220. },
  221. };
  222. static struct platform_device sdhi0_device = {
  223. .name = "sh_mobile_sdhi",
  224. .num_resources = ARRAY_SIZE(sdhi0_resources),
  225. .resource = sdhi0_resources,
  226. .id = 0,
  227. };
  228. /* USB1 */
  229. void usb1_host_port_power(int port, int power)
  230. {
  231. if (!power) /* only power-on supported for now */
  232. return;
  233. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  234. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  235. }
  236. static struct r8a66597_platdata usb1_host_data = {
  237. .on_chip = 1,
  238. .port_power = usb1_host_port_power,
  239. };
  240. static struct resource usb1_host_resources[] = {
  241. [0] = {
  242. .name = "USBHS",
  243. .start = 0xE68B0000,
  244. .end = 0xE68B00E6 - 1,
  245. .flags = IORESOURCE_MEM,
  246. },
  247. [1] = {
  248. .start = 215,
  249. .end = 215,
  250. .flags = IORESOURCE_IRQ,
  251. },
  252. };
  253. static struct platform_device usb1_host_device = {
  254. .name = "r8a66597_hcd",
  255. .id = 1,
  256. .dev = {
  257. .dma_mask = NULL, /* not use dma */
  258. .coherent_dma_mask = 0xffffffff,
  259. .platform_data = &usb1_host_data,
  260. },
  261. .num_resources = ARRAY_SIZE(usb1_host_resources),
  262. .resource = usb1_host_resources,
  263. };
  264. static struct platform_device *ap4evb_devices[] __initdata = {
  265. &nor_flash_device,
  266. &smc911x_device,
  267. &keysc_device,
  268. &sdhi0_device,
  269. &usb1_host_device,
  270. };
  271. /* TouchScreen (Needs SW3 set to OFF) */
  272. #define IRQ28 396
  273. struct tsc2007_platform_data tsc2007_info = {
  274. .model = 2007,
  275. .x_plate_ohms = 180,
  276. };
  277. /* I2C */
  278. static struct i2c_board_info i2c1_devices[] = {
  279. {
  280. I2C_BOARD_INFO("r2025sd", 0x32),
  281. },
  282. {
  283. I2C_BOARD_INFO("tsc2007", 0x48),
  284. .type = "tsc2007",
  285. .platform_data = &tsc2007_info,
  286. .irq = IRQ28,
  287. },
  288. };
  289. static struct map_desc ap4evb_io_desc[] __initdata = {
  290. /* create a 1:1 entity map for 0xe6xxxxxx
  291. * used by CPGA, INTC and PFC.
  292. */
  293. {
  294. .virtual = 0xe6000000,
  295. .pfn = __phys_to_pfn(0xe6000000),
  296. .length = 256 << 20,
  297. .type = MT_DEVICE_NONSHARED
  298. },
  299. };
  300. static void __init ap4evb_map_io(void)
  301. {
  302. iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
  303. /* setup early devices and console here as well */
  304. sh7372_add_early_devices();
  305. shmobile_setup_console();
  306. }
  307. static void __init ap4evb_init(void)
  308. {
  309. sh7372_pinmux_init();
  310. /* enable SCIFA0 */
  311. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  312. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  313. /* enable SMSC911X */
  314. gpio_request(GPIO_FN_CS5A, NULL);
  315. gpio_request(GPIO_FN_IRQ6_39, NULL);
  316. /* enable LED 1 - 4 */
  317. gpio_request(GPIO_PORT185, NULL);
  318. gpio_request(GPIO_PORT186, NULL);
  319. gpio_request(GPIO_PORT187, NULL);
  320. gpio_request(GPIO_PORT188, NULL);
  321. gpio_direction_output(GPIO_PORT185, 1);
  322. gpio_direction_output(GPIO_PORT186, 1);
  323. gpio_direction_output(GPIO_PORT187, 1);
  324. gpio_direction_output(GPIO_PORT188, 1);
  325. gpio_export(GPIO_PORT185, 0);
  326. gpio_export(GPIO_PORT186, 0);
  327. gpio_export(GPIO_PORT187, 0);
  328. gpio_export(GPIO_PORT188, 0);
  329. /* enable Debug switch (S6) */
  330. gpio_request(GPIO_PORT32, NULL);
  331. gpio_request(GPIO_PORT33, NULL);
  332. gpio_request(GPIO_PORT34, NULL);
  333. gpio_request(GPIO_PORT35, NULL);
  334. gpio_direction_input(GPIO_PORT32);
  335. gpio_direction_input(GPIO_PORT33);
  336. gpio_direction_input(GPIO_PORT34);
  337. gpio_direction_input(GPIO_PORT35);
  338. gpio_export(GPIO_PORT32, 0);
  339. gpio_export(GPIO_PORT33, 0);
  340. gpio_export(GPIO_PORT34, 0);
  341. gpio_export(GPIO_PORT35, 0);
  342. /* enable KEYSC */
  343. gpio_request(GPIO_FN_KEYOUT0, NULL);
  344. gpio_request(GPIO_FN_KEYOUT1, NULL);
  345. gpio_request(GPIO_FN_KEYOUT2, NULL);
  346. gpio_request(GPIO_FN_KEYOUT3, NULL);
  347. gpio_request(GPIO_FN_KEYOUT4, NULL);
  348. gpio_request(GPIO_FN_KEYIN0_136, NULL);
  349. gpio_request(GPIO_FN_KEYIN1_135, NULL);
  350. gpio_request(GPIO_FN_KEYIN2_134, NULL);
  351. gpio_request(GPIO_FN_KEYIN3_133, NULL);
  352. gpio_request(GPIO_FN_KEYIN4, NULL);
  353. /* SDHI0 */
  354. gpio_request(GPIO_FN_SDHICD0, NULL);
  355. gpio_request(GPIO_FN_SDHIWP0, NULL);
  356. gpio_request(GPIO_FN_SDHICMD0, NULL);
  357. gpio_request(GPIO_FN_SDHICLK0, NULL);
  358. gpio_request(GPIO_FN_SDHID0_3, NULL);
  359. gpio_request(GPIO_FN_SDHID0_2, NULL);
  360. gpio_request(GPIO_FN_SDHID0_1, NULL);
  361. gpio_request(GPIO_FN_SDHID0_0, NULL);
  362. /* enable TouchScreen */
  363. gpio_request(GPIO_FN_IRQ28_123, NULL);
  364. set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
  365. i2c_register_board_info(1, i2c1_devices,
  366. ARRAY_SIZE(i2c1_devices));
  367. /* USB enable */
  368. gpio_request(GPIO_FN_VBUS0_1, NULL);
  369. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  370. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  371. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  372. gpio_request(GPIO_FN_EXTLP_1, NULL);
  373. gpio_request(GPIO_FN_OVCN2_1, NULL);
  374. /* setup USB phy */
  375. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  376. sh7372_add_standard_devices();
  377. platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
  378. }
  379. static void __init ap4evb_timer_init(void)
  380. {
  381. sh7372_clock_init();
  382. shmobile_timer.init();
  383. }
  384. static struct sys_timer ap4evb_timer = {
  385. .init = ap4evb_timer_init,
  386. };
  387. MACHINE_START(AP4EVB, "ap4evb")
  388. .phys_io = 0xe6000000,
  389. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  390. .map_io = ap4evb_map_io,
  391. .init_irq = sh7372_init_irq,
  392. .init_machine = ap4evb_init,
  393. .timer = &ap4evb_timer,
  394. MACHINE_END