board-ap4evb.c 25 KB

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