board-ap4evb.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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. #define FSIACKCR 0xE6150018
  496. static void fsiackcr_init(struct clk *clk)
  497. {
  498. u32 status = __raw_readl(clk->enable_reg);
  499. /* use external clock */
  500. status &= ~0x000000ff;
  501. status |= 0x00000080;
  502. __raw_writel(status, clk->enable_reg);
  503. }
  504. static struct clk_ops fsiackcr_clk_ops = {
  505. .init = fsiackcr_init,
  506. };
  507. static struct clk fsiackcr_clk = {
  508. .ops = &fsiackcr_clk_ops,
  509. .enable_reg = (void __iomem *)FSIACKCR,
  510. .rate = 0, /* unknown */
  511. };
  512. static struct sh_fsi_platform_info fsi_info = {
  513. .porta_flags = SH_FSI_BRS_INV |
  514. SH_FSI_OUT_SLAVE_MODE |
  515. SH_FSI_IN_SLAVE_MODE |
  516. SH_FSI_OFMT(PCM) |
  517. SH_FSI_IFMT(PCM),
  518. };
  519. static struct resource fsi_resources[] = {
  520. [0] = {
  521. .name = "FSI",
  522. .start = 0xFE3C0000,
  523. .end = 0xFE3C0400 - 1,
  524. .flags = IORESOURCE_MEM,
  525. },
  526. [1] = {
  527. .start = IRQ_FSI,
  528. .flags = IORESOURCE_IRQ,
  529. },
  530. };
  531. static struct platform_device fsi_device = {
  532. .name = "sh_fsi2",
  533. .id = -1,
  534. .num_resources = ARRAY_SIZE(fsi_resources),
  535. .resource = fsi_resources,
  536. .dev = {
  537. .platform_data = &fsi_info,
  538. },
  539. };
  540. /*
  541. * If left and right margins are not multiples of 8,
  542. * LDHAJR will be adjusted accordingly by the LCDC
  543. * driver. Until we start using EDID, these values
  544. * might have to be adjusted for different monitors.
  545. */
  546. const static struct fb_videomode ap4evb_hdmi_modes[] = {
  547. {
  548. .name = "HDMI 720p",
  549. .xres = 1280,
  550. .yres = 720,
  551. .left_margin = 200,
  552. .right_margin = 88,
  553. .hsync_len = 48,
  554. .upper_margin = 20,
  555. .lower_margin = 5,
  556. .vsync_len = 5,
  557. .pixclock = 13468,
  558. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  559. }, {
  560. .name = "1280x1024",
  561. .xres = 1280,
  562. .yres = 1024,
  563. .left_margin = 144,
  564. .right_margin = 48,
  565. .hsync_len = 64,
  566. .upper_margin = 35,
  567. .lower_margin = 5,
  568. .vsync_len = 3,
  569. .pixclock = 9800,
  570. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  571. }, {
  572. .name = "HDMI 480p",
  573. .xres = 720,
  574. .yres = 480,
  575. .left_margin = 36,
  576. .right_margin = 18,
  577. .hsync_len = 68,
  578. .upper_margin = 36,
  579. .lower_margin = 3,
  580. .vsync_len = 6,
  581. .pixclock = 37037,
  582. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  583. },
  584. };
  585. static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
  586. .clock_source = LCDC_CLK_EXTERNAL,
  587. .ch[0] = {
  588. .chan = LCDC_CHAN_MAINLCD,
  589. .bpp = 16,
  590. .interface_type = RGB24,
  591. .clock_divider = 1,
  592. .flags = LCDC_FLAGS_DWPOL,
  593. .lcd_cfg = ap4evb_hdmi_modes,
  594. .num_cfg = ARRAY_SIZE(ap4evb_hdmi_modes),
  595. }
  596. };
  597. static struct resource lcdc1_resources[] = {
  598. [0] = {
  599. .name = "LCDC1",
  600. .start = 0xfe944000,
  601. .end = 0xfe947fff,
  602. .flags = IORESOURCE_MEM,
  603. },
  604. [1] = {
  605. .start = intcs_evt2irq(0x17a0),
  606. .flags = IORESOURCE_IRQ,
  607. },
  608. };
  609. static struct platform_device lcdc1_device = {
  610. .name = "sh_mobile_lcdc_fb",
  611. .num_resources = ARRAY_SIZE(lcdc1_resources),
  612. .resource = lcdc1_resources,
  613. .id = 1,
  614. .dev = {
  615. .platform_data = &sh_mobile_lcdc1_info,
  616. .coherent_dma_mask = ~0,
  617. },
  618. };
  619. static struct sh_mobile_hdmi_info hdmi_info = {
  620. .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
  621. .lcd_dev = &lcdc1_device.dev,
  622. };
  623. static struct resource hdmi_resources[] = {
  624. [0] = {
  625. .name = "HDMI",
  626. .start = 0xe6be0000,
  627. .end = 0xe6be00ff,
  628. .flags = IORESOURCE_MEM,
  629. },
  630. [1] = {
  631. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  632. .start = evt2irq(0x17e0),
  633. .flags = IORESOURCE_IRQ,
  634. },
  635. };
  636. static struct platform_device hdmi_device = {
  637. .name = "sh-mobile-hdmi",
  638. .num_resources = ARRAY_SIZE(hdmi_resources),
  639. .resource = hdmi_resources,
  640. .id = -1,
  641. .dev = {
  642. .platform_data = &hdmi_info,
  643. },
  644. };
  645. static struct gpio_led ap4evb_leds[] = {
  646. {
  647. .name = "led4",
  648. .gpio = GPIO_PORT185,
  649. .default_state = LEDS_GPIO_DEFSTATE_ON,
  650. },
  651. {
  652. .name = "led2",
  653. .gpio = GPIO_PORT186,
  654. .default_state = LEDS_GPIO_DEFSTATE_ON,
  655. },
  656. {
  657. .name = "led3",
  658. .gpio = GPIO_PORT187,
  659. .default_state = LEDS_GPIO_DEFSTATE_ON,
  660. },
  661. {
  662. .name = "led1",
  663. .gpio = GPIO_PORT188,
  664. .default_state = LEDS_GPIO_DEFSTATE_ON,
  665. }
  666. };
  667. static struct gpio_led_platform_data ap4evb_leds_pdata = {
  668. .num_leds = ARRAY_SIZE(ap4evb_leds),
  669. .leds = ap4evb_leds,
  670. };
  671. static struct platform_device leds_device = {
  672. .name = "leds-gpio",
  673. .id = 0,
  674. .dev = {
  675. .platform_data = &ap4evb_leds_pdata,
  676. },
  677. };
  678. static struct platform_device *ap4evb_devices[] __initdata = {
  679. &leds_device,
  680. &nor_flash_device,
  681. &smc911x_device,
  682. &sdhi0_device,
  683. &sdhi1_device,
  684. &usb1_host_device,
  685. &fsi_device,
  686. &sh_mmcif_device,
  687. &lcdc1_device,
  688. &lcdc_device,
  689. &hdmi_device,
  690. };
  691. static int __init hdmi_init_pm_clock(void)
  692. {
  693. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  694. int ret;
  695. long rate;
  696. if (IS_ERR(hdmi_ick)) {
  697. ret = PTR_ERR(hdmi_ick);
  698. pr_err("Cannot get HDMI ICK: %d\n", ret);
  699. goto out;
  700. }
  701. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  702. if (ret < 0) {
  703. pr_err("Cannot set PLLC2 parent: %d, %d users\n", ret, sh7372_pllc2_clk.usecount);
  704. goto out;
  705. }
  706. pr_debug("PLLC2 initial frequency %lu\n", clk_get_rate(&sh7372_pllc2_clk));
  707. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  708. if (rate < 0) {
  709. pr_err("Cannot get suitable rate: %ld\n", rate);
  710. ret = rate;
  711. goto out;
  712. }
  713. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  714. if (ret < 0) {
  715. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  716. goto out;
  717. }
  718. pr_debug("PLLC2 set frequency %lu\n", rate);
  719. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  720. if (ret < 0) {
  721. pr_err("Cannot set HDMI parent: %d\n", ret);
  722. goto out;
  723. }
  724. out:
  725. if (!IS_ERR(hdmi_ick))
  726. clk_put(hdmi_ick);
  727. return ret;
  728. }
  729. device_initcall(hdmi_init_pm_clock);
  730. /*
  731. * FIXME !!
  732. *
  733. * gpio_no_direction
  734. * are quick_hack.
  735. *
  736. * current gpio frame work doesn't have
  737. * the method to control only pull up/down/free.
  738. * this function should be replaced by correct gpio function
  739. */
  740. static void __init gpio_no_direction(u32 addr)
  741. {
  742. __raw_writeb(0x00, addr);
  743. }
  744. /* TouchScreen */
  745. #ifdef CONFIG_AP4EVB_QHD
  746. # define GPIO_TSC_IRQ GPIO_FN_IRQ28_123
  747. # define GPIO_TSC_PORT GPIO_PORT123
  748. #else /* WVGA */
  749. # define GPIO_TSC_IRQ GPIO_FN_IRQ7_40
  750. # define GPIO_TSC_PORT GPIO_PORT40
  751. #endif
  752. #define IRQ28 evt2irq(0x3380) /* IRQ28A */
  753. #define IRQ7 evt2irq(0x02e0) /* IRQ7A */
  754. static int ts_get_pendown_state(void)
  755. {
  756. int val;
  757. gpio_free(GPIO_TSC_IRQ);
  758. gpio_request(GPIO_TSC_PORT, NULL);
  759. gpio_direction_input(GPIO_TSC_PORT);
  760. val = gpio_get_value(GPIO_TSC_PORT);
  761. gpio_request(GPIO_TSC_IRQ, NULL);
  762. return !val;
  763. }
  764. static int ts_init(void)
  765. {
  766. gpio_request(GPIO_TSC_IRQ, NULL);
  767. return 0;
  768. }
  769. static struct tsc2007_platform_data tsc2007_info = {
  770. .model = 2007,
  771. .x_plate_ohms = 180,
  772. .get_pendown_state = ts_get_pendown_state,
  773. .init_platform_hw = ts_init,
  774. };
  775. static struct i2c_board_info tsc_device = {
  776. I2C_BOARD_INFO("tsc2007", 0x48),
  777. .type = "tsc2007",
  778. .platform_data = &tsc2007_info,
  779. /*.irq is selected on ap4evb_init */
  780. };
  781. /* I2C */
  782. static struct i2c_board_info i2c0_devices[] = {
  783. {
  784. I2C_BOARD_INFO("ak4643", 0x13),
  785. },
  786. };
  787. static struct i2c_board_info i2c1_devices[] = {
  788. {
  789. I2C_BOARD_INFO("r2025sd", 0x32),
  790. },
  791. };
  792. static struct map_desc ap4evb_io_desc[] __initdata = {
  793. /* create a 1:1 entity map for 0xe6xxxxxx
  794. * used by CPGA, INTC and PFC.
  795. */
  796. {
  797. .virtual = 0xe6000000,
  798. .pfn = __phys_to_pfn(0xe6000000),
  799. .length = 256 << 20,
  800. .type = MT_DEVICE_NONSHARED
  801. },
  802. };
  803. static void __init ap4evb_map_io(void)
  804. {
  805. iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
  806. /* setup early devices and console here as well */
  807. sh7372_add_early_devices();
  808. shmobile_setup_console();
  809. }
  810. #define GPIO_PORT9CR 0xE6051009
  811. #define GPIO_PORT10CR 0xE605100A
  812. static void __init ap4evb_init(void)
  813. {
  814. u32 srcr4;
  815. struct clk *clk;
  816. sh7372_pinmux_init();
  817. /* enable SCIFA0 */
  818. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  819. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  820. /* enable SMSC911X */
  821. gpio_request(GPIO_FN_CS5A, NULL);
  822. gpio_request(GPIO_FN_IRQ6_39, NULL);
  823. /* enable Debug switch (S6) */
  824. gpio_request(GPIO_PORT32, NULL);
  825. gpio_request(GPIO_PORT33, NULL);
  826. gpio_request(GPIO_PORT34, NULL);
  827. gpio_request(GPIO_PORT35, NULL);
  828. gpio_direction_input(GPIO_PORT32);
  829. gpio_direction_input(GPIO_PORT33);
  830. gpio_direction_input(GPIO_PORT34);
  831. gpio_direction_input(GPIO_PORT35);
  832. gpio_export(GPIO_PORT32, 0);
  833. gpio_export(GPIO_PORT33, 0);
  834. gpio_export(GPIO_PORT34, 0);
  835. gpio_export(GPIO_PORT35, 0);
  836. /* SDHI0 */
  837. gpio_request(GPIO_FN_SDHICD0, NULL);
  838. gpio_request(GPIO_FN_SDHIWP0, NULL);
  839. gpio_request(GPIO_FN_SDHICMD0, NULL);
  840. gpio_request(GPIO_FN_SDHICLK0, NULL);
  841. gpio_request(GPIO_FN_SDHID0_3, NULL);
  842. gpio_request(GPIO_FN_SDHID0_2, NULL);
  843. gpio_request(GPIO_FN_SDHID0_1, NULL);
  844. gpio_request(GPIO_FN_SDHID0_0, NULL);
  845. /* SDHI1 */
  846. gpio_request(GPIO_FN_SDHICMD1, NULL);
  847. gpio_request(GPIO_FN_SDHICLK1, NULL);
  848. gpio_request(GPIO_FN_SDHID1_3, NULL);
  849. gpio_request(GPIO_FN_SDHID1_2, NULL);
  850. gpio_request(GPIO_FN_SDHID1_1, NULL);
  851. gpio_request(GPIO_FN_SDHID1_0, NULL);
  852. /* MMCIF */
  853. gpio_request(GPIO_FN_MMCD0_0, NULL);
  854. gpio_request(GPIO_FN_MMCD0_1, NULL);
  855. gpio_request(GPIO_FN_MMCD0_2, NULL);
  856. gpio_request(GPIO_FN_MMCD0_3, NULL);
  857. gpio_request(GPIO_FN_MMCD0_4, NULL);
  858. gpio_request(GPIO_FN_MMCD0_5, NULL);
  859. gpio_request(GPIO_FN_MMCD0_6, NULL);
  860. gpio_request(GPIO_FN_MMCD0_7, NULL);
  861. gpio_request(GPIO_FN_MMCCMD0, NULL);
  862. gpio_request(GPIO_FN_MMCCLK0, NULL);
  863. /* USB enable */
  864. gpio_request(GPIO_FN_VBUS0_1, NULL);
  865. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  866. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  867. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  868. gpio_request(GPIO_FN_EXTLP_1, NULL);
  869. gpio_request(GPIO_FN_OVCN2_1, NULL);
  870. /* setup USB phy */
  871. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  872. /* enable FSI2 */
  873. gpio_request(GPIO_FN_FSIAIBT, NULL);
  874. gpio_request(GPIO_FN_FSIAILR, NULL);
  875. gpio_request(GPIO_FN_FSIAISLD, NULL);
  876. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  877. gpio_request(GPIO_PORT161, NULL);
  878. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  879. gpio_request(GPIO_PORT9, NULL);
  880. gpio_request(GPIO_PORT10, NULL);
  881. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  882. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  883. /* set SPU2 clock to 119.6 MHz */
  884. clk = clk_get(NULL, "spu_clk");
  885. if (!IS_ERR(clk)) {
  886. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  887. clk_put(clk);
  888. }
  889. /* change parent of FSI A */
  890. clk = clk_get(NULL, "fsia_clk");
  891. if (!IS_ERR(clk)) {
  892. clk_register(&fsiackcr_clk);
  893. clk_set_parent(clk, &fsiackcr_clk);
  894. clk_put(clk);
  895. }
  896. /*
  897. * set irq priority, to avoid sound chopping
  898. * when NFS rootfs is used
  899. * FSI(3) > SMSC911X(2)
  900. */
  901. intc_set_priority(IRQ_FSI, 3);
  902. i2c_register_board_info(0, i2c0_devices,
  903. ARRAY_SIZE(i2c0_devices));
  904. i2c_register_board_info(1, i2c1_devices,
  905. ARRAY_SIZE(i2c1_devices));
  906. #ifdef CONFIG_AP4EVB_QHD
  907. /*
  908. * For QHD Panel (MIPI-DSI, CONFIG_AP4EVB_QHD=y) and
  909. * IRQ28 for Touch Panel, set dip switches S3, S43 as OFF, ON.
  910. */
  911. /* enable KEYSC */
  912. gpio_request(GPIO_FN_KEYOUT0, NULL);
  913. gpio_request(GPIO_FN_KEYOUT1, NULL);
  914. gpio_request(GPIO_FN_KEYOUT2, NULL);
  915. gpio_request(GPIO_FN_KEYOUT3, NULL);
  916. gpio_request(GPIO_FN_KEYOUT4, NULL);
  917. gpio_request(GPIO_FN_KEYIN0_136, NULL);
  918. gpio_request(GPIO_FN_KEYIN1_135, NULL);
  919. gpio_request(GPIO_FN_KEYIN2_134, NULL);
  920. gpio_request(GPIO_FN_KEYIN3_133, NULL);
  921. gpio_request(GPIO_FN_KEYIN4, NULL);
  922. /* enable TouchScreen */
  923. set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
  924. tsc_device.irq = IRQ28;
  925. i2c_register_board_info(1, &tsc_device, 1);
  926. /* LCDC0 */
  927. lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
  928. lcdc_info.ch[0].interface_type = RGB24;
  929. lcdc_info.ch[0].clock_divider = 1;
  930. lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
  931. lcdc_info.ch[0].lcd_size_cfg.width = 44;
  932. lcdc_info.ch[0].lcd_size_cfg.height = 79;
  933. platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
  934. #else
  935. /*
  936. * For WVGA Panel (18-bit RGB, CONFIG_AP4EVB_WVGA=y) and
  937. * IRQ7 for Touch Panel, set dip switches S3, S43 to ON, OFF.
  938. */
  939. gpio_request(GPIO_FN_LCDD17, NULL);
  940. gpio_request(GPIO_FN_LCDD16, NULL);
  941. gpio_request(GPIO_FN_LCDD15, NULL);
  942. gpio_request(GPIO_FN_LCDD14, NULL);
  943. gpio_request(GPIO_FN_LCDD13, NULL);
  944. gpio_request(GPIO_FN_LCDD12, NULL);
  945. gpio_request(GPIO_FN_LCDD11, NULL);
  946. gpio_request(GPIO_FN_LCDD10, NULL);
  947. gpio_request(GPIO_FN_LCDD9, NULL);
  948. gpio_request(GPIO_FN_LCDD8, NULL);
  949. gpio_request(GPIO_FN_LCDD7, NULL);
  950. gpio_request(GPIO_FN_LCDD6, NULL);
  951. gpio_request(GPIO_FN_LCDD5, NULL);
  952. gpio_request(GPIO_FN_LCDD4, NULL);
  953. gpio_request(GPIO_FN_LCDD3, NULL);
  954. gpio_request(GPIO_FN_LCDD2, NULL);
  955. gpio_request(GPIO_FN_LCDD1, NULL);
  956. gpio_request(GPIO_FN_LCDD0, NULL);
  957. gpio_request(GPIO_FN_LCDDISP, NULL);
  958. gpio_request(GPIO_FN_LCDDCK, NULL);
  959. gpio_request(GPIO_PORT189, NULL); /* backlight */
  960. gpio_direction_output(GPIO_PORT189, 1);
  961. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  962. gpio_direction_output(GPIO_PORT151, 1);
  963. lcdc_info.clock_source = LCDC_CLK_BUS;
  964. lcdc_info.ch[0].interface_type = RGB18;
  965. lcdc_info.ch[0].clock_divider = 2;
  966. lcdc_info.ch[0].flags = 0;
  967. lcdc_info.ch[0].lcd_size_cfg.width = 152;
  968. lcdc_info.ch[0].lcd_size_cfg.height = 91;
  969. /* enable TouchScreen */
  970. set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  971. tsc_device.irq = IRQ7;
  972. i2c_register_board_info(0, &tsc_device, 1);
  973. #endif /* CONFIG_AP4EVB_QHD */
  974. sh7372_add_standard_devices();
  975. /* HDMI */
  976. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  977. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  978. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  979. #define SRCR4 0xe61580bc
  980. srcr4 = __raw_readl(SRCR4);
  981. __raw_writel(srcr4 | (1 << 13), SRCR4);
  982. udelay(50);
  983. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  984. platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
  985. }
  986. static void __init ap4evb_timer_init(void)
  987. {
  988. sh7372_clock_init();
  989. shmobile_timer.init();
  990. /* External clock source */
  991. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  992. }
  993. static struct sys_timer ap4evb_timer = {
  994. .init = ap4evb_timer_init,
  995. };
  996. MACHINE_START(AP4EVB, "ap4evb")
  997. .phys_io = 0xe6000000,
  998. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  999. .map_io = ap4evb_map_io,
  1000. .init_irq = sh7372_init_irq,
  1001. .init_machine = ap4evb_init,
  1002. .timer = &ap4evb_timer,
  1003. MACHINE_END