board-ap4evb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  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/mfd/tmio.h>
  29. #include <linux/mmc/host.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/partitions.h>
  32. #include <linux/mtd/physmap.h>
  33. #include <linux/mmc/sh_mmcif.h>
  34. #include <linux/i2c.h>
  35. #include <linux/i2c/tsc2007.h>
  36. #include <linux/io.h>
  37. #include <linux/smsc911x.h>
  38. #include <linux/sh_intc.h>
  39. #include <linux/sh_clk.h>
  40. #include <linux/gpio.h>
  41. #include <linux/input.h>
  42. #include <linux/leds.h>
  43. #include <linux/input/sh_keysc.h>
  44. #include <linux/usb/r8a66597.h>
  45. #include <sound/sh_fsi.h>
  46. #include <video/sh_mobile_hdmi.h>
  47. #include <video/sh_mobile_lcdc.h>
  48. #include <video/sh_mipi_dsi.h>
  49. #include <mach/common.h>
  50. #include <mach/irqs.h>
  51. #include <mach/sh7372.h>
  52. #include <asm/mach-types.h>
  53. #include <asm/mach/arch.h>
  54. #include <asm/mach/map.h>
  55. #include <asm/mach/time.h>
  56. /*
  57. * Address Interface BusWidth note
  58. * ------------------------------------------------------------------
  59. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  60. * 0x0800_0000 user area -
  61. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  62. * 0x1400_0000 Ether (LAN9220) 16bit
  63. * 0x1600_0000 user area - cannot use with NAND
  64. * 0x1800_0000 user area -
  65. * 0x1A00_0000 -
  66. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  67. */
  68. /*
  69. * NOR Flash ROM
  70. *
  71. * SW1 | SW2 | SW7 | NOR Flash ROM
  72. * bit1 | bit1 bit2 | bit1 | Memory allocation
  73. * ------+------------+------+------------------
  74. * OFF | ON OFF | ON | Area 0
  75. * OFF | ON OFF | OFF | Area 4
  76. */
  77. /*
  78. * NAND Flash ROM
  79. *
  80. * SW1 | SW2 | SW7 | NAND Flash ROM
  81. * bit1 | bit1 bit2 | bit2 | Memory allocation
  82. * ------+------------+------+------------------
  83. * OFF | ON OFF | ON | FCE 0
  84. * OFF | ON OFF | OFF | FCE 1
  85. */
  86. /*
  87. * SMSC 9220
  88. *
  89. * SW1 SMSC 9220
  90. * -----------------------
  91. * ON access disable
  92. * OFF access enable
  93. */
  94. /*
  95. * LCD / IRQ / KEYSC / IrDA
  96. *
  97. * IRQ = IRQ26 (TS), IRQ27 (VIO), IRQ28 (QHD-TouchScreen)
  98. * LCD = 2nd LCDC (WVGA)
  99. *
  100. * | SW43 |
  101. * SW3 | ON | OFF |
  102. * -------------+-----------------------+---------------+
  103. * ON | KEY / IrDA | LCD |
  104. * OFF | KEY / IrDA / IRQ | IRQ |
  105. *
  106. *
  107. * QHD / WVGA display
  108. *
  109. * You can choice display type on menuconfig.
  110. * Then, check above dip-switch.
  111. */
  112. /*
  113. * USB
  114. *
  115. * J7 : 1-2 MAX3355E VBUS
  116. * 2-3 DC 5.0V
  117. *
  118. * S39: bit2: off
  119. */
  120. /*
  121. * FSI/FSMI
  122. *
  123. * SW41 : ON : SH-Mobile AP4 Audio Mode
  124. * : OFF : Bluetooth Audio Mode
  125. */
  126. /*
  127. * MMC0/SDHI1 (CN7)
  128. *
  129. * J22 : select card voltage
  130. * 1-2 pin : 1.8v
  131. * 2-3 pin : 3.3v
  132. *
  133. * SW1 | SW33
  134. * | bit1 | bit2 | bit3 | bit4
  135. * ------------+------+------+------+-------
  136. * MMC0 OFF | OFF | ON | ON | X
  137. * SDHI1 OFF | ON | X | OFF | ON
  138. *
  139. * voltage lebel
  140. * CN7 : 1.8v
  141. * CN12: 3.3v
  142. */
  143. /* MTD */
  144. static struct mtd_partition nor_flash_partitions[] = {
  145. {
  146. .name = "loader",
  147. .offset = 0x00000000,
  148. .size = 512 * 1024,
  149. },
  150. {
  151. .name = "bootenv",
  152. .offset = MTDPART_OFS_APPEND,
  153. .size = 512 * 1024,
  154. },
  155. {
  156. .name = "kernel_ro",
  157. .offset = MTDPART_OFS_APPEND,
  158. .size = 8 * 1024 * 1024,
  159. .mask_flags = MTD_WRITEABLE,
  160. },
  161. {
  162. .name = "kernel",
  163. .offset = MTDPART_OFS_APPEND,
  164. .size = 8 * 1024 * 1024,
  165. },
  166. {
  167. .name = "data",
  168. .offset = MTDPART_OFS_APPEND,
  169. .size = MTDPART_SIZ_FULL,
  170. },
  171. };
  172. static struct physmap_flash_data nor_flash_data = {
  173. .width = 2,
  174. .parts = nor_flash_partitions,
  175. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  176. };
  177. static struct resource nor_flash_resources[] = {
  178. [0] = {
  179. .start = 0x00000000,
  180. .end = 0x08000000 - 1,
  181. .flags = IORESOURCE_MEM,
  182. }
  183. };
  184. static struct platform_device nor_flash_device = {
  185. .name = "physmap-flash",
  186. .dev = {
  187. .platform_data = &nor_flash_data,
  188. },
  189. .num_resources = ARRAY_SIZE(nor_flash_resources),
  190. .resource = nor_flash_resources,
  191. };
  192. /* SMSC 9220 */
  193. static struct resource smc911x_resources[] = {
  194. {
  195. .start = 0x14000000,
  196. .end = 0x16000000 - 1,
  197. .flags = IORESOURCE_MEM,
  198. }, {
  199. .start = evt2irq(0x02c0) /* IRQ6A */,
  200. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  201. },
  202. };
  203. static struct smsc911x_platform_config smsc911x_info = {
  204. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  205. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  206. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  207. };
  208. static struct platform_device smc911x_device = {
  209. .name = "smsc911x",
  210. .id = -1,
  211. .num_resources = ARRAY_SIZE(smc911x_resources),
  212. .resource = smc911x_resources,
  213. .dev = {
  214. .platform_data = &smsc911x_info,
  215. },
  216. };
  217. /* SH_MMCIF */
  218. static struct resource sh_mmcif_resources[] = {
  219. [0] = {
  220. .name = "MMCIF",
  221. .start = 0xE6BD0000,
  222. .end = 0xE6BD00FF,
  223. .flags = IORESOURCE_MEM,
  224. },
  225. [1] = {
  226. /* MMC ERR */
  227. .start = evt2irq(0x1ac0),
  228. .flags = IORESOURCE_IRQ,
  229. },
  230. [2] = {
  231. /* MMC NOR */
  232. .start = evt2irq(0x1ae0),
  233. .flags = IORESOURCE_IRQ,
  234. },
  235. };
  236. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  237. .sup_pclk = 0,
  238. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  239. .caps = MMC_CAP_4_BIT_DATA |
  240. MMC_CAP_8_BIT_DATA |
  241. MMC_CAP_NEEDS_POLL,
  242. };
  243. static struct platform_device sh_mmcif_device = {
  244. .name = "sh_mmcif",
  245. .id = 0,
  246. .dev = {
  247. .dma_mask = NULL,
  248. .coherent_dma_mask = 0xffffffff,
  249. .platform_data = &sh_mmcif_plat,
  250. },
  251. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  252. .resource = sh_mmcif_resources,
  253. };
  254. /* SDHI0 */
  255. static struct sh_mobile_sdhi_info sdhi0_info = {
  256. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  257. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  258. };
  259. static struct resource sdhi0_resources[] = {
  260. [0] = {
  261. .name = "SDHI0",
  262. .start = 0xe6850000,
  263. .end = 0xe68501ff,
  264. .flags = IORESOURCE_MEM,
  265. },
  266. [1] = {
  267. .start = evt2irq(0x0e00) /* SDHI0 */,
  268. .flags = IORESOURCE_IRQ,
  269. },
  270. };
  271. static struct platform_device sdhi0_device = {
  272. .name = "sh_mobile_sdhi",
  273. .num_resources = ARRAY_SIZE(sdhi0_resources),
  274. .resource = sdhi0_resources,
  275. .id = 0,
  276. .dev = {
  277. .platform_data = &sdhi0_info,
  278. },
  279. };
  280. /* SDHI1 */
  281. static struct sh_mobile_sdhi_info sdhi1_info = {
  282. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  283. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  284. .tmio_ocr_mask = MMC_VDD_165_195,
  285. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  286. };
  287. static struct resource sdhi1_resources[] = {
  288. [0] = {
  289. .name = "SDHI1",
  290. .start = 0xe6860000,
  291. .end = 0xe68601ff,
  292. .flags = IORESOURCE_MEM,
  293. },
  294. [1] = {
  295. .start = evt2irq(0x0e80),
  296. .flags = IORESOURCE_IRQ,
  297. },
  298. };
  299. static struct platform_device sdhi1_device = {
  300. .name = "sh_mobile_sdhi",
  301. .num_resources = ARRAY_SIZE(sdhi1_resources),
  302. .resource = sdhi1_resources,
  303. .id = 1,
  304. .dev = {
  305. .platform_data = &sdhi1_info,
  306. },
  307. };
  308. /* USB1 */
  309. static void usb1_host_port_power(int port, int power)
  310. {
  311. if (!power) /* only power-on supported for now */
  312. return;
  313. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  314. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  315. }
  316. static struct r8a66597_platdata usb1_host_data = {
  317. .on_chip = 1,
  318. .port_power = usb1_host_port_power,
  319. };
  320. static struct resource usb1_host_resources[] = {
  321. [0] = {
  322. .name = "USBHS",
  323. .start = 0xE68B0000,
  324. .end = 0xE68B00E6 - 1,
  325. .flags = IORESOURCE_MEM,
  326. },
  327. [1] = {
  328. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  329. .flags = IORESOURCE_IRQ,
  330. },
  331. };
  332. static struct platform_device usb1_host_device = {
  333. .name = "r8a66597_hcd",
  334. .id = 1,
  335. .dev = {
  336. .dma_mask = NULL, /* not use dma */
  337. .coherent_dma_mask = 0xffffffff,
  338. .platform_data = &usb1_host_data,
  339. },
  340. .num_resources = ARRAY_SIZE(usb1_host_resources),
  341. .resource = usb1_host_resources,
  342. };
  343. const static struct fb_videomode ap4evb_lcdc_modes[] = {
  344. {
  345. #ifdef CONFIG_AP4EVB_QHD
  346. .name = "R63302(QHD)",
  347. .xres = 544,
  348. .yres = 961,
  349. .left_margin = 72,
  350. .right_margin = 600,
  351. .hsync_len = 16,
  352. .upper_margin = 8,
  353. .lower_margin = 8,
  354. .vsync_len = 2,
  355. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  356. #else
  357. .name = "WVGA Panel",
  358. .xres = 800,
  359. .yres = 480,
  360. .left_margin = 220,
  361. .right_margin = 110,
  362. .hsync_len = 70,
  363. .upper_margin = 20,
  364. .lower_margin = 5,
  365. .vsync_len = 5,
  366. .sync = 0,
  367. #endif
  368. },
  369. };
  370. static struct sh_mobile_lcdc_info lcdc_info = {
  371. .ch[0] = {
  372. .chan = LCDC_CHAN_MAINLCD,
  373. .bpp = 16,
  374. .lcd_cfg = ap4evb_lcdc_modes,
  375. .num_cfg = ARRAY_SIZE(ap4evb_lcdc_modes),
  376. }
  377. };
  378. static struct resource lcdc_resources[] = {
  379. [0] = {
  380. .name = "LCDC",
  381. .start = 0xfe940000, /* P4-only space */
  382. .end = 0xfe943fff,
  383. .flags = IORESOURCE_MEM,
  384. },
  385. [1] = {
  386. .start = intcs_evt2irq(0x580),
  387. .flags = IORESOURCE_IRQ,
  388. },
  389. };
  390. static struct platform_device lcdc_device = {
  391. .name = "sh_mobile_lcdc_fb",
  392. .num_resources = ARRAY_SIZE(lcdc_resources),
  393. .resource = lcdc_resources,
  394. .dev = {
  395. .platform_data = &lcdc_info,
  396. .coherent_dma_mask = ~0,
  397. },
  398. };
  399. /*
  400. * QHD display
  401. */
  402. #ifdef CONFIG_AP4EVB_QHD
  403. /* KEYSC (Needs SW43 set to ON) */
  404. static struct sh_keysc_info keysc_info = {
  405. .mode = SH_KEYSC_MODE_1,
  406. .scan_timing = 3,
  407. .delay = 2500,
  408. .keycodes = {
  409. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
  410. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
  411. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
  412. KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
  413. KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
  414. },
  415. };
  416. static struct resource keysc_resources[] = {
  417. [0] = {
  418. .name = "KEYSC",
  419. .start = 0xe61b0000,
  420. .end = 0xe61b0063,
  421. .flags = IORESOURCE_MEM,
  422. },
  423. [1] = {
  424. .start = evt2irq(0x0be0), /* KEYSC_KEY */
  425. .flags = IORESOURCE_IRQ,
  426. },
  427. };
  428. static struct platform_device keysc_device = {
  429. .name = "sh_keysc",
  430. .id = 0, /* "keysc0" clock */
  431. .num_resources = ARRAY_SIZE(keysc_resources),
  432. .resource = keysc_resources,
  433. .dev = {
  434. .platform_data = &keysc_info,
  435. },
  436. };
  437. /* MIPI-DSI */
  438. static struct resource mipidsi0_resources[] = {
  439. [0] = {
  440. .start = 0xffc60000,
  441. .end = 0xffc68fff,
  442. .flags = IORESOURCE_MEM,
  443. },
  444. };
  445. static struct sh_mipi_dsi_info mipidsi0_info = {
  446. .data_format = MIPI_RGB888,
  447. .lcd_chan = &lcdc_info.ch[0],
  448. };
  449. static struct platform_device mipidsi0_device = {
  450. .name = "sh-mipi-dsi",
  451. .num_resources = ARRAY_SIZE(mipidsi0_resources),
  452. .resource = mipidsi0_resources,
  453. .id = 0,
  454. .dev = {
  455. .platform_data = &mipidsi0_info,
  456. },
  457. };
  458. /* This function will disappear when we switch to (runtime) PM */
  459. static int __init ap4evb_init_display_clk(void)
  460. {
  461. struct clk *lcdc_clk;
  462. struct clk *dsitx_clk;
  463. int ret;
  464. lcdc_clk = clk_get(&lcdc_device.dev, "sh_mobile_lcdc_fb.0");
  465. if (IS_ERR(lcdc_clk))
  466. return PTR_ERR(lcdc_clk);
  467. dsitx_clk = clk_get(&mipidsi0_device.dev, "sh-mipi-dsi.0");
  468. if (IS_ERR(dsitx_clk)) {
  469. ret = PTR_ERR(dsitx_clk);
  470. goto eclkdsitxget;
  471. }
  472. ret = clk_enable(lcdc_clk);
  473. if (ret < 0)
  474. goto eclklcdcon;
  475. ret = clk_enable(dsitx_clk);
  476. if (ret < 0)
  477. goto eclkdsitxon;
  478. return 0;
  479. eclkdsitxon:
  480. clk_disable(lcdc_clk);
  481. eclklcdcon:
  482. clk_put(dsitx_clk);
  483. eclkdsitxget:
  484. clk_put(lcdc_clk);
  485. return ret;
  486. }
  487. device_initcall(ap4evb_init_display_clk);
  488. static struct platform_device *qhd_devices[] __initdata = {
  489. &mipidsi0_device,
  490. &keysc_device,
  491. };
  492. #endif /* CONFIG_AP4EVB_QHD */
  493. /* FSI */
  494. #define IRQ_FSI evt2irq(0x1840)
  495. static struct sh_fsi_platform_info fsi_info = {
  496. .porta_flags = SH_FSI_BRS_INV |
  497. SH_FSI_OUT_SLAVE_MODE |
  498. SH_FSI_IN_SLAVE_MODE |
  499. SH_FSI_OFMT(PCM) |
  500. SH_FSI_IFMT(PCM),
  501. };
  502. static struct resource fsi_resources[] = {
  503. [0] = {
  504. .name = "FSI",
  505. .start = 0xFE3C0000,
  506. .end = 0xFE3C0400 - 1,
  507. .flags = IORESOURCE_MEM,
  508. },
  509. [1] = {
  510. .start = IRQ_FSI,
  511. .flags = IORESOURCE_IRQ,
  512. },
  513. };
  514. static struct platform_device fsi_device = {
  515. .name = "sh_fsi2",
  516. .id = -1,
  517. .num_resources = ARRAY_SIZE(fsi_resources),
  518. .resource = fsi_resources,
  519. .dev = {
  520. .platform_data = &fsi_info,
  521. },
  522. };
  523. /*
  524. * If left and right margins are not multiples of 8,
  525. * LDHAJR will be adjusted accordingly by the LCDC
  526. * driver. Until we start using EDID, these values
  527. * might have to be adjusted for different monitors.
  528. */
  529. const static struct fb_videomode ap4evb_hdmi_modes[] = {
  530. {
  531. .name = "HDMI 720p",
  532. .xres = 1280,
  533. .yres = 720,
  534. .left_margin = 200,
  535. .right_margin = 88,
  536. .hsync_len = 48,
  537. .upper_margin = 20,
  538. .lower_margin = 5,
  539. .vsync_len = 5,
  540. .pixclock = 13468,
  541. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  542. }, {
  543. .name = "1280x1024",
  544. .xres = 1280,
  545. .yres = 1024,
  546. .left_margin = 144,
  547. .right_margin = 48,
  548. .hsync_len = 64,
  549. .upper_margin = 35,
  550. .lower_margin = 5,
  551. .vsync_len = 3,
  552. .pixclock = 9800,
  553. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  554. }, {
  555. .name = "HDMI 480p",
  556. .xres = 720,
  557. .yres = 480,
  558. .left_margin = 36,
  559. .right_margin = 18,
  560. .hsync_len = 68,
  561. .upper_margin = 36,
  562. .lower_margin = 3,
  563. .vsync_len = 6,
  564. .pixclock = 37037,
  565. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  566. },
  567. };
  568. static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
  569. .clock_source = LCDC_CLK_EXTERNAL,
  570. .ch[0] = {
  571. .chan = LCDC_CHAN_MAINLCD,
  572. .bpp = 16,
  573. .interface_type = RGB24,
  574. .clock_divider = 1,
  575. .flags = LCDC_FLAGS_DWPOL,
  576. .lcd_cfg = ap4evb_hdmi_modes,
  577. .num_cfg = ARRAY_SIZE(ap4evb_hdmi_modes),
  578. }
  579. };
  580. static struct resource lcdc1_resources[] = {
  581. [0] = {
  582. .name = "LCDC1",
  583. .start = 0xfe944000,
  584. .end = 0xfe947fff,
  585. .flags = IORESOURCE_MEM,
  586. },
  587. [1] = {
  588. .start = intcs_evt2irq(0x17a0),
  589. .flags = IORESOURCE_IRQ,
  590. },
  591. };
  592. static struct platform_device lcdc1_device = {
  593. .name = "sh_mobile_lcdc_fb",
  594. .num_resources = ARRAY_SIZE(lcdc1_resources),
  595. .resource = lcdc1_resources,
  596. .id = 1,
  597. .dev = {
  598. .platform_data = &sh_mobile_lcdc1_info,
  599. .coherent_dma_mask = ~0,
  600. },
  601. };
  602. static struct sh_mobile_hdmi_info hdmi_info = {
  603. .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
  604. .lcd_dev = &lcdc1_device.dev,
  605. };
  606. static struct resource hdmi_resources[] = {
  607. [0] = {
  608. .name = "HDMI",
  609. .start = 0xe6be0000,
  610. .end = 0xe6be00ff,
  611. .flags = IORESOURCE_MEM,
  612. },
  613. [1] = {
  614. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  615. .start = evt2irq(0x17e0),
  616. .flags = IORESOURCE_IRQ,
  617. },
  618. };
  619. static struct platform_device hdmi_device = {
  620. .name = "sh-mobile-hdmi",
  621. .num_resources = ARRAY_SIZE(hdmi_resources),
  622. .resource = hdmi_resources,
  623. .id = -1,
  624. .dev = {
  625. .platform_data = &hdmi_info,
  626. },
  627. };
  628. static struct gpio_led ap4evb_leds[] = {
  629. {
  630. .name = "led4",
  631. .gpio = GPIO_PORT185,
  632. .default_state = LEDS_GPIO_DEFSTATE_ON,
  633. },
  634. {
  635. .name = "led2",
  636. .gpio = GPIO_PORT186,
  637. .default_state = LEDS_GPIO_DEFSTATE_ON,
  638. },
  639. {
  640. .name = "led3",
  641. .gpio = GPIO_PORT187,
  642. .default_state = LEDS_GPIO_DEFSTATE_ON,
  643. },
  644. {
  645. .name = "led1",
  646. .gpio = GPIO_PORT188,
  647. .default_state = LEDS_GPIO_DEFSTATE_ON,
  648. }
  649. };
  650. static struct gpio_led_platform_data ap4evb_leds_pdata = {
  651. .num_leds = ARRAY_SIZE(ap4evb_leds),
  652. .leds = ap4evb_leds,
  653. };
  654. static struct platform_device leds_device = {
  655. .name = "leds-gpio",
  656. .id = 0,
  657. .dev = {
  658. .platform_data = &ap4evb_leds_pdata,
  659. },
  660. };
  661. static struct platform_device *ap4evb_devices[] __initdata = {
  662. &leds_device,
  663. &nor_flash_device,
  664. &smc911x_device,
  665. &sdhi0_device,
  666. &sdhi1_device,
  667. &usb1_host_device,
  668. &fsi_device,
  669. &sh_mmcif_device,
  670. &lcdc1_device,
  671. &lcdc_device,
  672. &hdmi_device,
  673. };
  674. static int __init hdmi_init_pm_clock(void)
  675. {
  676. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  677. int ret;
  678. long rate;
  679. if (IS_ERR(hdmi_ick)) {
  680. ret = PTR_ERR(hdmi_ick);
  681. pr_err("Cannot get HDMI ICK: %d\n", ret);
  682. goto out;
  683. }
  684. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  685. if (ret < 0) {
  686. pr_err("Cannot set PLLC2 parent: %d, %d users\n", ret, sh7372_pllc2_clk.usecount);
  687. goto out;
  688. }
  689. pr_debug("PLLC2 initial frequency %lu\n", clk_get_rate(&sh7372_pllc2_clk));
  690. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  691. if (rate < 0) {
  692. pr_err("Cannot get suitable rate: %ld\n", rate);
  693. ret = rate;
  694. goto out;
  695. }
  696. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  697. if (ret < 0) {
  698. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  699. goto out;
  700. }
  701. pr_debug("PLLC2 set frequency %lu\n", rate);
  702. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  703. if (ret < 0) {
  704. pr_err("Cannot set HDMI parent: %d\n", ret);
  705. goto out;
  706. }
  707. out:
  708. if (!IS_ERR(hdmi_ick))
  709. clk_put(hdmi_ick);
  710. return ret;
  711. }
  712. device_initcall(hdmi_init_pm_clock);
  713. #define FSIACK_DUMMY_RATE 48000
  714. static int __init fsi_init_pm_clock(void)
  715. {
  716. struct clk *fsia_ick;
  717. int ret;
  718. /*
  719. * FSIACK is connected to AK4642,
  720. * and the rate is depend on playing sound rate.
  721. * So, set dummy rate (= 48k) here
  722. */
  723. ret = clk_set_rate(&sh7372_fsiack_clk, FSIACK_DUMMY_RATE);
  724. if (ret < 0) {
  725. pr_err("Cannot set FSIACK dummy rate: %d\n", ret);
  726. return ret;
  727. }
  728. fsia_ick = clk_get(&fsi_device.dev, "icka");
  729. if (IS_ERR(fsia_ick)) {
  730. ret = PTR_ERR(fsia_ick);
  731. pr_err("Cannot get FSI ICK: %d\n", ret);
  732. return ret;
  733. }
  734. ret = clk_set_parent(fsia_ick, &sh7372_fsiack_clk);
  735. if (ret < 0) {
  736. pr_err("Cannot set FSI-A parent: %d\n", ret);
  737. goto out;
  738. }
  739. ret = clk_set_rate(fsia_ick, FSIACK_DUMMY_RATE);
  740. if (ret < 0)
  741. pr_err("Cannot set FSI-A rate: %d\n", ret);
  742. out:
  743. clk_put(fsia_ick);
  744. return ret;
  745. }
  746. device_initcall(fsi_init_pm_clock);
  747. /*
  748. * FIXME !!
  749. *
  750. * gpio_no_direction
  751. * are quick_hack.
  752. *
  753. * current gpio frame work doesn't have
  754. * the method to control only pull up/down/free.
  755. * this function should be replaced by correct gpio function
  756. */
  757. static void __init gpio_no_direction(u32 addr)
  758. {
  759. __raw_writeb(0x00, addr);
  760. }
  761. /* TouchScreen */
  762. #ifdef CONFIG_AP4EVB_QHD
  763. # define GPIO_TSC_IRQ GPIO_FN_IRQ28_123
  764. # define GPIO_TSC_PORT GPIO_PORT123
  765. #else /* WVGA */
  766. # define GPIO_TSC_IRQ GPIO_FN_IRQ7_40
  767. # define GPIO_TSC_PORT GPIO_PORT40
  768. #endif
  769. #define IRQ28 evt2irq(0x3380) /* IRQ28A */
  770. #define IRQ7 evt2irq(0x02e0) /* IRQ7A */
  771. static int ts_get_pendown_state(void)
  772. {
  773. int val;
  774. gpio_free(GPIO_TSC_IRQ);
  775. gpio_request(GPIO_TSC_PORT, NULL);
  776. gpio_direction_input(GPIO_TSC_PORT);
  777. val = gpio_get_value(GPIO_TSC_PORT);
  778. gpio_request(GPIO_TSC_IRQ, NULL);
  779. return !val;
  780. }
  781. static int ts_init(void)
  782. {
  783. gpio_request(GPIO_TSC_IRQ, NULL);
  784. return 0;
  785. }
  786. static struct tsc2007_platform_data tsc2007_info = {
  787. .model = 2007,
  788. .x_plate_ohms = 180,
  789. .get_pendown_state = ts_get_pendown_state,
  790. .init_platform_hw = ts_init,
  791. };
  792. static struct i2c_board_info tsc_device = {
  793. I2C_BOARD_INFO("tsc2007", 0x48),
  794. .type = "tsc2007",
  795. .platform_data = &tsc2007_info,
  796. /*.irq is selected on ap4evb_init */
  797. };
  798. /* I2C */
  799. static struct i2c_board_info i2c0_devices[] = {
  800. {
  801. I2C_BOARD_INFO("ak4643", 0x13),
  802. },
  803. };
  804. static struct i2c_board_info i2c1_devices[] = {
  805. {
  806. I2C_BOARD_INFO("r2025sd", 0x32),
  807. },
  808. };
  809. static struct map_desc ap4evb_io_desc[] __initdata = {
  810. /* create a 1:1 entity map for 0xe6xxxxxx
  811. * used by CPGA, INTC and PFC.
  812. */
  813. {
  814. .virtual = 0xe6000000,
  815. .pfn = __phys_to_pfn(0xe6000000),
  816. .length = 256 << 20,
  817. .type = MT_DEVICE_NONSHARED
  818. },
  819. };
  820. static void __init ap4evb_map_io(void)
  821. {
  822. iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
  823. /* setup early devices and console here as well */
  824. sh7372_add_early_devices();
  825. shmobile_setup_console();
  826. }
  827. #define GPIO_PORT9CR 0xE6051009
  828. #define GPIO_PORT10CR 0xE605100A
  829. static void __init ap4evb_init(void)
  830. {
  831. u32 srcr4;
  832. struct clk *clk;
  833. sh7372_pinmux_init();
  834. /* enable SCIFA0 */
  835. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  836. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  837. /* enable SMSC911X */
  838. gpio_request(GPIO_FN_CS5A, NULL);
  839. gpio_request(GPIO_FN_IRQ6_39, NULL);
  840. /* enable Debug switch (S6) */
  841. gpio_request(GPIO_PORT32, NULL);
  842. gpio_request(GPIO_PORT33, NULL);
  843. gpio_request(GPIO_PORT34, NULL);
  844. gpio_request(GPIO_PORT35, NULL);
  845. gpio_direction_input(GPIO_PORT32);
  846. gpio_direction_input(GPIO_PORT33);
  847. gpio_direction_input(GPIO_PORT34);
  848. gpio_direction_input(GPIO_PORT35);
  849. gpio_export(GPIO_PORT32, 0);
  850. gpio_export(GPIO_PORT33, 0);
  851. gpio_export(GPIO_PORT34, 0);
  852. gpio_export(GPIO_PORT35, 0);
  853. /* SDHI0 */
  854. gpio_request(GPIO_FN_SDHICD0, NULL);
  855. gpio_request(GPIO_FN_SDHIWP0, NULL);
  856. gpio_request(GPIO_FN_SDHICMD0, NULL);
  857. gpio_request(GPIO_FN_SDHICLK0, NULL);
  858. gpio_request(GPIO_FN_SDHID0_3, NULL);
  859. gpio_request(GPIO_FN_SDHID0_2, NULL);
  860. gpio_request(GPIO_FN_SDHID0_1, NULL);
  861. gpio_request(GPIO_FN_SDHID0_0, NULL);
  862. /* SDHI1 */
  863. gpio_request(GPIO_FN_SDHICMD1, NULL);
  864. gpio_request(GPIO_FN_SDHICLK1, NULL);
  865. gpio_request(GPIO_FN_SDHID1_3, NULL);
  866. gpio_request(GPIO_FN_SDHID1_2, NULL);
  867. gpio_request(GPIO_FN_SDHID1_1, NULL);
  868. gpio_request(GPIO_FN_SDHID1_0, NULL);
  869. /* MMCIF */
  870. gpio_request(GPIO_FN_MMCD0_0, NULL);
  871. gpio_request(GPIO_FN_MMCD0_1, NULL);
  872. gpio_request(GPIO_FN_MMCD0_2, NULL);
  873. gpio_request(GPIO_FN_MMCD0_3, NULL);
  874. gpio_request(GPIO_FN_MMCD0_4, NULL);
  875. gpio_request(GPIO_FN_MMCD0_5, NULL);
  876. gpio_request(GPIO_FN_MMCD0_6, NULL);
  877. gpio_request(GPIO_FN_MMCD0_7, NULL);
  878. gpio_request(GPIO_FN_MMCCMD0, NULL);
  879. gpio_request(GPIO_FN_MMCCLK0, NULL);
  880. /* USB enable */
  881. gpio_request(GPIO_FN_VBUS0_1, NULL);
  882. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  883. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  884. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  885. gpio_request(GPIO_FN_EXTLP_1, NULL);
  886. gpio_request(GPIO_FN_OVCN2_1, NULL);
  887. /* setup USB phy */
  888. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  889. /* enable FSI2 */
  890. gpio_request(GPIO_FN_FSIAIBT, NULL);
  891. gpio_request(GPIO_FN_FSIAILR, NULL);
  892. gpio_request(GPIO_FN_FSIAISLD, NULL);
  893. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  894. gpio_request(GPIO_PORT161, NULL);
  895. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  896. gpio_request(GPIO_PORT9, NULL);
  897. gpio_request(GPIO_PORT10, NULL);
  898. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  899. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  900. /* set SPU2 clock to 119.6 MHz */
  901. clk = clk_get(NULL, "spu_clk");
  902. if (!IS_ERR(clk)) {
  903. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  904. clk_put(clk);
  905. }
  906. /*
  907. * set irq priority, to avoid sound chopping
  908. * when NFS rootfs is used
  909. * FSI(3) > SMSC911X(2)
  910. */
  911. intc_set_priority(IRQ_FSI, 3);
  912. i2c_register_board_info(0, i2c0_devices,
  913. ARRAY_SIZE(i2c0_devices));
  914. i2c_register_board_info(1, i2c1_devices,
  915. ARRAY_SIZE(i2c1_devices));
  916. #ifdef CONFIG_AP4EVB_QHD
  917. /*
  918. * For QHD Panel (MIPI-DSI, CONFIG_AP4EVB_QHD=y) and
  919. * IRQ28 for Touch Panel, set dip switches S3, S43 as OFF, ON.
  920. */
  921. /* enable KEYSC */
  922. gpio_request(GPIO_FN_KEYOUT0, NULL);
  923. gpio_request(GPIO_FN_KEYOUT1, NULL);
  924. gpio_request(GPIO_FN_KEYOUT2, NULL);
  925. gpio_request(GPIO_FN_KEYOUT3, NULL);
  926. gpio_request(GPIO_FN_KEYOUT4, NULL);
  927. gpio_request(GPIO_FN_KEYIN0_136, NULL);
  928. gpio_request(GPIO_FN_KEYIN1_135, NULL);
  929. gpio_request(GPIO_FN_KEYIN2_134, NULL);
  930. gpio_request(GPIO_FN_KEYIN3_133, NULL);
  931. gpio_request(GPIO_FN_KEYIN4, NULL);
  932. /* enable TouchScreen */
  933. set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
  934. tsc_device.irq = IRQ28;
  935. i2c_register_board_info(1, &tsc_device, 1);
  936. /* LCDC0 */
  937. lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
  938. lcdc_info.ch[0].interface_type = RGB24;
  939. lcdc_info.ch[0].clock_divider = 1;
  940. lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
  941. lcdc_info.ch[0].lcd_size_cfg.width = 44;
  942. lcdc_info.ch[0].lcd_size_cfg.height = 79;
  943. platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
  944. #else
  945. /*
  946. * For WVGA Panel (18-bit RGB, CONFIG_AP4EVB_WVGA=y) and
  947. * IRQ7 for Touch Panel, set dip switches S3, S43 to ON, OFF.
  948. */
  949. gpio_request(GPIO_FN_LCDD17, NULL);
  950. gpio_request(GPIO_FN_LCDD16, NULL);
  951. gpio_request(GPIO_FN_LCDD15, NULL);
  952. gpio_request(GPIO_FN_LCDD14, NULL);
  953. gpio_request(GPIO_FN_LCDD13, NULL);
  954. gpio_request(GPIO_FN_LCDD12, NULL);
  955. gpio_request(GPIO_FN_LCDD11, NULL);
  956. gpio_request(GPIO_FN_LCDD10, NULL);
  957. gpio_request(GPIO_FN_LCDD9, NULL);
  958. gpio_request(GPIO_FN_LCDD8, NULL);
  959. gpio_request(GPIO_FN_LCDD7, NULL);
  960. gpio_request(GPIO_FN_LCDD6, NULL);
  961. gpio_request(GPIO_FN_LCDD5, NULL);
  962. gpio_request(GPIO_FN_LCDD4, NULL);
  963. gpio_request(GPIO_FN_LCDD3, NULL);
  964. gpio_request(GPIO_FN_LCDD2, NULL);
  965. gpio_request(GPIO_FN_LCDD1, NULL);
  966. gpio_request(GPIO_FN_LCDD0, NULL);
  967. gpio_request(GPIO_FN_LCDDISP, NULL);
  968. gpio_request(GPIO_FN_LCDDCK, NULL);
  969. gpio_request(GPIO_PORT189, NULL); /* backlight */
  970. gpio_direction_output(GPIO_PORT189, 1);
  971. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  972. gpio_direction_output(GPIO_PORT151, 1);
  973. lcdc_info.clock_source = LCDC_CLK_BUS;
  974. lcdc_info.ch[0].interface_type = RGB18;
  975. lcdc_info.ch[0].clock_divider = 2;
  976. lcdc_info.ch[0].flags = 0;
  977. lcdc_info.ch[0].lcd_size_cfg.width = 152;
  978. lcdc_info.ch[0].lcd_size_cfg.height = 91;
  979. /* enable TouchScreen */
  980. set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  981. tsc_device.irq = IRQ7;
  982. i2c_register_board_info(0, &tsc_device, 1);
  983. #endif /* CONFIG_AP4EVB_QHD */
  984. sh7372_add_standard_devices();
  985. /* HDMI */
  986. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  987. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  988. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  989. #define SRCR4 0xe61580bc
  990. srcr4 = __raw_readl(SRCR4);
  991. __raw_writel(srcr4 | (1 << 13), SRCR4);
  992. udelay(50);
  993. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  994. platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
  995. }
  996. static void __init ap4evb_timer_init(void)
  997. {
  998. sh7372_clock_init();
  999. shmobile_timer.init();
  1000. /* External clock source */
  1001. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1002. }
  1003. static struct sys_timer ap4evb_timer = {
  1004. .init = ap4evb_timer_init,
  1005. };
  1006. MACHINE_START(AP4EVB, "ap4evb")
  1007. .phys_io = 0xe6000000,
  1008. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  1009. .map_io = ap4evb_map_io,
  1010. .init_irq = sh7372_init_irq,
  1011. .init_machine = ap4evb_init,
  1012. .timer = &ap4evb_timer,
  1013. MACHINE_END