board-ap4evb.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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/clk.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/delay.h>
  27. #include <linux/mfd/sh_mobile_sdhi.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <linux/mtd/physmap.h>
  31. #include <linux/i2c.h>
  32. #include <linux/i2c/tsc2007.h>
  33. #include <linux/io.h>
  34. #include <linux/smsc911x.h>
  35. #include <linux/gpio.h>
  36. #include <linux/input.h>
  37. #include <linux/input/sh_keysc.h>
  38. #include <linux/usb/r8a66597.h>
  39. #include <video/sh_mobile_lcdc.h>
  40. #include <video/sh_mipi_dsi.h>
  41. #include <mach/common.h>
  42. #include <mach/irqs.h>
  43. #include <mach/sh7372.h>
  44. #include <asm/mach-types.h>
  45. #include <asm/mach/arch.h>
  46. #include <asm/mach/map.h>
  47. #include <asm/mach/time.h>
  48. /*
  49. * Address Interface BusWidth note
  50. * ------------------------------------------------------------------
  51. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  52. * 0x0800_0000 user area -
  53. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  54. * 0x1400_0000 Ether (LAN9220) 16bit
  55. * 0x1600_0000 user area - cannot use with NAND
  56. * 0x1800_0000 user area -
  57. * 0x1A00_0000 -
  58. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  59. */
  60. /*
  61. * NOR Flash ROM
  62. *
  63. * SW1 | SW2 | SW7 | NOR Flash ROM
  64. * bit1 | bit1 bit2 | bit1 | Memory allocation
  65. * ------+------------+------+------------------
  66. * OFF | ON OFF | ON | Area 0
  67. * OFF | ON OFF | OFF | Area 4
  68. */
  69. /*
  70. * NAND Flash ROM
  71. *
  72. * SW1 | SW2 | SW7 | NAND Flash ROM
  73. * bit1 | bit1 bit2 | bit2 | Memory allocation
  74. * ------+------------+------+------------------
  75. * OFF | ON OFF | ON | FCE 0
  76. * OFF | ON OFF | OFF | FCE 1
  77. */
  78. /*
  79. * SMSC 9220
  80. *
  81. * SW1 SMSC 9220
  82. * -----------------------
  83. * ON access disable
  84. * OFF access enable
  85. */
  86. /*
  87. * LCD / IRQ / KEYSC / IrDA
  88. *
  89. * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (TouchScreen)
  90. * LCD = 2nd LCDC
  91. *
  92. * | SW43 |
  93. * SW3 | ON | OFF |
  94. * -------------+-----------------------+---------------+
  95. * ON | KEY / IrDA | LCD |
  96. * OFF | KEY / IrDA / IRQ | IRQ |
  97. */
  98. /*
  99. * USB
  100. *
  101. * J7 : 1-2 MAX3355E VBUS
  102. * 2-3 DC 5.0V
  103. *
  104. * S39: bit2: off
  105. */
  106. /* MTD */
  107. static struct mtd_partition nor_flash_partitions[] = {
  108. {
  109. .name = "loader",
  110. .offset = 0x00000000,
  111. .size = 512 * 1024,
  112. },
  113. {
  114. .name = "bootenv",
  115. .offset = MTDPART_OFS_APPEND,
  116. .size = 512 * 1024,
  117. },
  118. {
  119. .name = "kernel_ro",
  120. .offset = MTDPART_OFS_APPEND,
  121. .size = 8 * 1024 * 1024,
  122. .mask_flags = MTD_WRITEABLE,
  123. },
  124. {
  125. .name = "kernel",
  126. .offset = MTDPART_OFS_APPEND,
  127. .size = 8 * 1024 * 1024,
  128. },
  129. {
  130. .name = "data",
  131. .offset = MTDPART_OFS_APPEND,
  132. .size = MTDPART_SIZ_FULL,
  133. },
  134. };
  135. static struct physmap_flash_data nor_flash_data = {
  136. .width = 2,
  137. .parts = nor_flash_partitions,
  138. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  139. };
  140. static struct resource nor_flash_resources[] = {
  141. [0] = {
  142. .start = 0x00000000,
  143. .end = 0x08000000 - 1,
  144. .flags = IORESOURCE_MEM,
  145. }
  146. };
  147. static struct platform_device nor_flash_device = {
  148. .name = "physmap-flash",
  149. .dev = {
  150. .platform_data = &nor_flash_data,
  151. },
  152. .num_resources = ARRAY_SIZE(nor_flash_resources),
  153. .resource = nor_flash_resources,
  154. };
  155. /* SMSC 9220 */
  156. static struct resource smc911x_resources[] = {
  157. {
  158. .start = 0x14000000,
  159. .end = 0x16000000 - 1,
  160. .flags = IORESOURCE_MEM,
  161. }, {
  162. .start = evt2irq(0x02c0) /* IRQ6A */,
  163. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  164. },
  165. };
  166. static struct smsc911x_platform_config smsc911x_info = {
  167. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  168. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  169. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  170. };
  171. static struct platform_device smc911x_device = {
  172. .name = "smsc911x",
  173. .id = -1,
  174. .num_resources = ARRAY_SIZE(smc911x_resources),
  175. .resource = smc911x_resources,
  176. .dev = {
  177. .platform_data = &smsc911x_info,
  178. },
  179. };
  180. /* KEYSC (Needs SW43 set to ON) */
  181. static struct sh_keysc_info keysc_info = {
  182. .mode = SH_KEYSC_MODE_1,
  183. .scan_timing = 3,
  184. .delay = 2500,
  185. .keycodes = {
  186. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
  187. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
  188. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
  189. KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
  190. KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
  191. },
  192. };
  193. static struct resource keysc_resources[] = {
  194. [0] = {
  195. .name = "KEYSC",
  196. .start = 0xe61b0000,
  197. .end = 0xe61b0063,
  198. .flags = IORESOURCE_MEM,
  199. },
  200. [1] = {
  201. .start = evt2irq(0x0be0), /* KEYSC_KEY */
  202. .flags = IORESOURCE_IRQ,
  203. },
  204. };
  205. static struct platform_device keysc_device = {
  206. .name = "sh_keysc",
  207. .id = 0, /* "keysc0" clock */
  208. .num_resources = ARRAY_SIZE(keysc_resources),
  209. .resource = keysc_resources,
  210. .dev = {
  211. .platform_data = &keysc_info,
  212. },
  213. };
  214. /* SDHI0 */
  215. static struct sh_mobile_sdhi_info sdhi0_info = {
  216. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  217. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  218. };
  219. static struct resource sdhi0_resources[] = {
  220. [0] = {
  221. .name = "SDHI0",
  222. .start = 0xe6850000,
  223. .end = 0xe68501ff,
  224. .flags = IORESOURCE_MEM,
  225. },
  226. [1] = {
  227. .start = evt2irq(0x0e00) /* SDHI0 */,
  228. .flags = IORESOURCE_IRQ,
  229. },
  230. };
  231. static struct platform_device sdhi0_device = {
  232. .name = "sh_mobile_sdhi",
  233. .num_resources = ARRAY_SIZE(sdhi0_resources),
  234. .resource = sdhi0_resources,
  235. .id = 0,
  236. .dev = {
  237. .platform_data = &sdhi0_info,
  238. },
  239. };
  240. /* USB1 */
  241. void usb1_host_port_power(int port, int power)
  242. {
  243. if (!power) /* only power-on supported for now */
  244. return;
  245. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  246. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  247. }
  248. static struct r8a66597_platdata usb1_host_data = {
  249. .on_chip = 1,
  250. .port_power = usb1_host_port_power,
  251. };
  252. static struct resource usb1_host_resources[] = {
  253. [0] = {
  254. .name = "USBHS",
  255. .start = 0xE68B0000,
  256. .end = 0xE68B00E6 - 1,
  257. .flags = IORESOURCE_MEM,
  258. },
  259. [1] = {
  260. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  261. .flags = IORESOURCE_IRQ,
  262. },
  263. };
  264. static struct platform_device usb1_host_device = {
  265. .name = "r8a66597_hcd",
  266. .id = 1,
  267. .dev = {
  268. .dma_mask = NULL, /* not use dma */
  269. .coherent_dma_mask = 0xffffffff,
  270. .platform_data = &usb1_host_data,
  271. },
  272. .num_resources = ARRAY_SIZE(usb1_host_resources),
  273. .resource = usb1_host_resources,
  274. };
  275. static struct sh_mobile_lcdc_info sh_mobile_lcdc_info = {
  276. .clock_source = LCDC_CLK_PERIPHERAL, /* One of interface clocks */
  277. .ch[0] = {
  278. .chan = LCDC_CHAN_MAINLCD,
  279. .bpp = 16,
  280. .interface_type = RGB24,
  281. .clock_divider = 1,
  282. .flags = LCDC_FLAGS_DWPOL,
  283. .lcd_cfg = {
  284. .name = "R63302(QHD)",
  285. .xres = 544,
  286. .yres = 961,
  287. .left_margin = 72,
  288. .right_margin = 600,
  289. .hsync_len = 16,
  290. .upper_margin = 8,
  291. .lower_margin = 8,
  292. .vsync_len = 2,
  293. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  294. },
  295. .lcd_size_cfg = {
  296. .width = 44,
  297. .height = 79,
  298. },
  299. }
  300. };
  301. static struct resource lcdc_resources[] = {
  302. [0] = {
  303. .name = "LCDC",
  304. .start = 0xfe940000, /* P4-only space */
  305. .end = 0xfe943fff,
  306. .flags = IORESOURCE_MEM,
  307. },
  308. [1] = {
  309. .start = intcs_evt2irq(0x580),
  310. .flags = IORESOURCE_IRQ,
  311. },
  312. };
  313. static struct platform_device lcdc_device = {
  314. .name = "sh_mobile_lcdc_fb",
  315. .num_resources = ARRAY_SIZE(lcdc_resources),
  316. .resource = lcdc_resources,
  317. .dev = {
  318. .platform_data = &sh_mobile_lcdc_info,
  319. .coherent_dma_mask = ~0,
  320. },
  321. };
  322. static struct resource mipidsi0_resources[] = {
  323. [0] = {
  324. .start = 0xffc60000,
  325. .end = 0xffc68fff,
  326. .flags = IORESOURCE_MEM,
  327. },
  328. };
  329. static struct sh_mipi_dsi_info mipidsi0_info = {
  330. .data_format = MIPI_RGB888,
  331. .lcd_chan = &sh_mobile_lcdc_info.ch[0],
  332. };
  333. static struct platform_device mipidsi0_device = {
  334. .name = "sh-mipi-dsi",
  335. .num_resources = ARRAY_SIZE(mipidsi0_resources),
  336. .resource = mipidsi0_resources,
  337. .id = 0,
  338. .dev = {
  339. .platform_data = &mipidsi0_info,
  340. },
  341. };
  342. static struct platform_device *ap4evb_devices[] __initdata = {
  343. &nor_flash_device,
  344. &smc911x_device,
  345. &keysc_device,
  346. &sdhi0_device,
  347. &usb1_host_device,
  348. &lcdc_device,
  349. &mipidsi0_device,
  350. };
  351. /* TouchScreen (Needs SW3 set to OFF) */
  352. #define IRQ28 evt2irq(0x3380) /* IRQ28A */
  353. struct tsc2007_platform_data tsc2007_info = {
  354. .model = 2007,
  355. .x_plate_ohms = 180,
  356. };
  357. /* I2C */
  358. static struct i2c_board_info i2c1_devices[] = {
  359. {
  360. I2C_BOARD_INFO("r2025sd", 0x32),
  361. },
  362. {
  363. I2C_BOARD_INFO("tsc2007", 0x48),
  364. .type = "tsc2007",
  365. .platform_data = &tsc2007_info,
  366. .irq = IRQ28,
  367. },
  368. };
  369. static struct map_desc ap4evb_io_desc[] __initdata = {
  370. /* create a 1:1 entity map for 0xe6xxxxxx
  371. * used by CPGA, INTC and PFC.
  372. */
  373. {
  374. .virtual = 0xe6000000,
  375. .pfn = __phys_to_pfn(0xe6000000),
  376. .length = 256 << 20,
  377. .type = MT_DEVICE_NONSHARED
  378. },
  379. };
  380. static void __init ap4evb_map_io(void)
  381. {
  382. iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
  383. /* setup early devices and console here as well */
  384. sh7372_add_early_devices();
  385. shmobile_setup_console();
  386. }
  387. /* This function will disappear when we switch to (runtime) PM */
  388. static int __init ap4evb_init_display_clk(void)
  389. {
  390. struct clk *lcdc_clk;
  391. struct clk *dsitx_clk;
  392. int ret;
  393. lcdc_clk = clk_get(&lcdc_device.dev, "sh_mobile_lcdc_fb.0");
  394. if (IS_ERR(lcdc_clk))
  395. return PTR_ERR(lcdc_clk);
  396. dsitx_clk = clk_get(&mipidsi0_device.dev, "sh-mipi-dsi.0");
  397. if (IS_ERR(dsitx_clk)) {
  398. ret = PTR_ERR(dsitx_clk);
  399. goto eclkdsitxget;
  400. }
  401. ret = clk_enable(lcdc_clk);
  402. if (ret < 0)
  403. goto eclklcdcon;
  404. ret = clk_enable(dsitx_clk);
  405. if (ret < 0)
  406. goto eclkdsitxon;
  407. return 0;
  408. eclkdsitxon:
  409. clk_disable(lcdc_clk);
  410. eclklcdcon:
  411. clk_put(dsitx_clk);
  412. eclkdsitxget:
  413. clk_put(lcdc_clk);
  414. return ret;
  415. }
  416. device_initcall(ap4evb_init_display_clk);
  417. static void __init ap4evb_init(void)
  418. {
  419. sh7372_pinmux_init();
  420. /* enable SCIFA0 */
  421. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  422. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  423. /* enable SMSC911X */
  424. gpio_request(GPIO_FN_CS5A, NULL);
  425. gpio_request(GPIO_FN_IRQ6_39, NULL);
  426. /* enable LED 1 - 4 */
  427. gpio_request(GPIO_PORT185, NULL);
  428. gpio_request(GPIO_PORT186, NULL);
  429. gpio_request(GPIO_PORT187, NULL);
  430. gpio_request(GPIO_PORT188, NULL);
  431. gpio_direction_output(GPIO_PORT185, 1);
  432. gpio_direction_output(GPIO_PORT186, 1);
  433. gpio_direction_output(GPIO_PORT187, 1);
  434. gpio_direction_output(GPIO_PORT188, 1);
  435. gpio_export(GPIO_PORT185, 0);
  436. gpio_export(GPIO_PORT186, 0);
  437. gpio_export(GPIO_PORT187, 0);
  438. gpio_export(GPIO_PORT188, 0);
  439. /* enable Debug switch (S6) */
  440. gpio_request(GPIO_PORT32, NULL);
  441. gpio_request(GPIO_PORT33, NULL);
  442. gpio_request(GPIO_PORT34, NULL);
  443. gpio_request(GPIO_PORT35, NULL);
  444. gpio_direction_input(GPIO_PORT32);
  445. gpio_direction_input(GPIO_PORT33);
  446. gpio_direction_input(GPIO_PORT34);
  447. gpio_direction_input(GPIO_PORT35);
  448. gpio_export(GPIO_PORT32, 0);
  449. gpio_export(GPIO_PORT33, 0);
  450. gpio_export(GPIO_PORT34, 0);
  451. gpio_export(GPIO_PORT35, 0);
  452. /* enable KEYSC */
  453. gpio_request(GPIO_FN_KEYOUT0, NULL);
  454. gpio_request(GPIO_FN_KEYOUT1, NULL);
  455. gpio_request(GPIO_FN_KEYOUT2, NULL);
  456. gpio_request(GPIO_FN_KEYOUT3, NULL);
  457. gpio_request(GPIO_FN_KEYOUT4, NULL);
  458. gpio_request(GPIO_FN_KEYIN0_136, NULL);
  459. gpio_request(GPIO_FN_KEYIN1_135, NULL);
  460. gpio_request(GPIO_FN_KEYIN2_134, NULL);
  461. gpio_request(GPIO_FN_KEYIN3_133, NULL);
  462. gpio_request(GPIO_FN_KEYIN4, NULL);
  463. /* SDHI0 */
  464. gpio_request(GPIO_FN_SDHICD0, NULL);
  465. gpio_request(GPIO_FN_SDHIWP0, NULL);
  466. gpio_request(GPIO_FN_SDHICMD0, NULL);
  467. gpio_request(GPIO_FN_SDHICLK0, NULL);
  468. gpio_request(GPIO_FN_SDHID0_3, NULL);
  469. gpio_request(GPIO_FN_SDHID0_2, NULL);
  470. gpio_request(GPIO_FN_SDHID0_1, NULL);
  471. gpio_request(GPIO_FN_SDHID0_0, NULL);
  472. /* enable TouchScreen */
  473. gpio_request(GPIO_FN_IRQ28_123, NULL);
  474. set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
  475. i2c_register_board_info(1, i2c1_devices,
  476. ARRAY_SIZE(i2c1_devices));
  477. /* USB enable */
  478. gpio_request(GPIO_FN_VBUS0_1, NULL);
  479. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  480. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  481. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  482. gpio_request(GPIO_FN_EXTLP_1, NULL);
  483. gpio_request(GPIO_FN_OVCN2_1, NULL);
  484. /* setup USB phy */
  485. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  486. sh7372_add_standard_devices();
  487. platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
  488. }
  489. static void __init ap4evb_timer_init(void)
  490. {
  491. sh7372_clock_init();
  492. shmobile_timer.init();
  493. }
  494. static struct sys_timer ap4evb_timer = {
  495. .init = ap4evb_timer_init,
  496. };
  497. MACHINE_START(AP4EVB, "ap4evb")
  498. .phys_io = 0xe6000000,
  499. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  500. .map_io = ap4evb_map_io,
  501. .init_irq = sh7372_init_irq,
  502. .init_machine = ap4evb_init,
  503. .timer = &ap4evb_timer,
  504. MACHINE_END