board-ap4evb.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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. static struct sh_mobile_lcdc_info lcdc_info = {
  345. .ch[0] = {
  346. .chan = LCDC_CHAN_MAINLCD,
  347. .bpp = 16,
  348. }
  349. };
  350. static struct resource lcdc_resources[] = {
  351. [0] = {
  352. .name = "LCDC",
  353. .start = 0xfe940000, /* P4-only space */
  354. .end = 0xfe943fff,
  355. .flags = IORESOURCE_MEM,
  356. },
  357. [1] = {
  358. .start = intcs_evt2irq(0x580),
  359. .flags = IORESOURCE_IRQ,
  360. },
  361. };
  362. static struct platform_device lcdc_device = {
  363. .name = "sh_mobile_lcdc_fb",
  364. .num_resources = ARRAY_SIZE(lcdc_resources),
  365. .resource = lcdc_resources,
  366. .dev = {
  367. .platform_data = &lcdc_info,
  368. .coherent_dma_mask = ~0,
  369. },
  370. };
  371. /*
  372. * QHD display
  373. */
  374. #ifdef CONFIG_AP4EVB_QHD
  375. /* KEYSC (Needs SW43 set to ON) */
  376. static struct sh_keysc_info keysc_info = {
  377. .mode = SH_KEYSC_MODE_1,
  378. .scan_timing = 3,
  379. .delay = 2500,
  380. .keycodes = {
  381. KEY_0, KEY_1, KEY_2, KEY_3, KEY_4,
  382. KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
  383. KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
  384. KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
  385. KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
  386. },
  387. };
  388. static struct resource keysc_resources[] = {
  389. [0] = {
  390. .name = "KEYSC",
  391. .start = 0xe61b0000,
  392. .end = 0xe61b0063,
  393. .flags = IORESOURCE_MEM,
  394. },
  395. [1] = {
  396. .start = evt2irq(0x0be0), /* KEYSC_KEY */
  397. .flags = IORESOURCE_IRQ,
  398. },
  399. };
  400. static struct platform_device keysc_device = {
  401. .name = "sh_keysc",
  402. .id = 0, /* "keysc0" clock */
  403. .num_resources = ARRAY_SIZE(keysc_resources),
  404. .resource = keysc_resources,
  405. .dev = {
  406. .platform_data = &keysc_info,
  407. },
  408. };
  409. /* MIPI-DSI */
  410. static struct resource mipidsi0_resources[] = {
  411. [0] = {
  412. .start = 0xffc60000,
  413. .end = 0xffc68fff,
  414. .flags = IORESOURCE_MEM,
  415. },
  416. };
  417. static struct sh_mipi_dsi_info mipidsi0_info = {
  418. .data_format = MIPI_RGB888,
  419. .lcd_chan = &lcdc_info.ch[0],
  420. };
  421. static struct platform_device mipidsi0_device = {
  422. .name = "sh-mipi-dsi",
  423. .num_resources = ARRAY_SIZE(mipidsi0_resources),
  424. .resource = mipidsi0_resources,
  425. .id = 0,
  426. .dev = {
  427. .platform_data = &mipidsi0_info,
  428. },
  429. };
  430. /* This function will disappear when we switch to (runtime) PM */
  431. static int __init ap4evb_init_display_clk(void)
  432. {
  433. struct clk *lcdc_clk;
  434. struct clk *dsitx_clk;
  435. int ret;
  436. lcdc_clk = clk_get(&lcdc_device.dev, "sh_mobile_lcdc_fb.0");
  437. if (IS_ERR(lcdc_clk))
  438. return PTR_ERR(lcdc_clk);
  439. dsitx_clk = clk_get(&mipidsi0_device.dev, "sh-mipi-dsi.0");
  440. if (IS_ERR(dsitx_clk)) {
  441. ret = PTR_ERR(dsitx_clk);
  442. goto eclkdsitxget;
  443. }
  444. ret = clk_enable(lcdc_clk);
  445. if (ret < 0)
  446. goto eclklcdcon;
  447. ret = clk_enable(dsitx_clk);
  448. if (ret < 0)
  449. goto eclkdsitxon;
  450. return 0;
  451. eclkdsitxon:
  452. clk_disable(lcdc_clk);
  453. eclklcdcon:
  454. clk_put(dsitx_clk);
  455. eclkdsitxget:
  456. clk_put(lcdc_clk);
  457. return ret;
  458. }
  459. device_initcall(ap4evb_init_display_clk);
  460. static struct platform_device *qhd_devices[] __initdata = {
  461. &mipidsi0_device,
  462. &keysc_device,
  463. };
  464. #endif /* CONFIG_AP4EVB_QHD */
  465. /* FSI */
  466. #define IRQ_FSI evt2irq(0x1840)
  467. #define FSIACKCR 0xE6150018
  468. static void fsiackcr_init(struct clk *clk)
  469. {
  470. u32 status = __raw_readl(clk->enable_reg);
  471. /* use external clock */
  472. status &= ~0x000000ff;
  473. status |= 0x00000080;
  474. __raw_writel(status, clk->enable_reg);
  475. }
  476. static struct clk_ops fsiackcr_clk_ops = {
  477. .init = fsiackcr_init,
  478. };
  479. static struct clk fsiackcr_clk = {
  480. .ops = &fsiackcr_clk_ops,
  481. .enable_reg = (void __iomem *)FSIACKCR,
  482. .rate = 0, /* unknown */
  483. };
  484. static struct sh_fsi_platform_info fsi_info = {
  485. .porta_flags = SH_FSI_BRS_INV |
  486. SH_FSI_OUT_SLAVE_MODE |
  487. SH_FSI_IN_SLAVE_MODE |
  488. SH_FSI_OFMT(PCM) |
  489. SH_FSI_IFMT(PCM),
  490. };
  491. static struct resource fsi_resources[] = {
  492. [0] = {
  493. .name = "FSI",
  494. .start = 0xFE3C0000,
  495. .end = 0xFE3C0400 - 1,
  496. .flags = IORESOURCE_MEM,
  497. },
  498. [1] = {
  499. .start = IRQ_FSI,
  500. .flags = IORESOURCE_IRQ,
  501. },
  502. };
  503. static struct platform_device fsi_device = {
  504. .name = "sh_fsi2",
  505. .id = -1,
  506. .num_resources = ARRAY_SIZE(fsi_resources),
  507. .resource = fsi_resources,
  508. .dev = {
  509. .platform_data = &fsi_info,
  510. },
  511. };
  512. static struct sh_mobile_lcdc_info sh_mobile_lcdc1_info = {
  513. .clock_source = LCDC_CLK_EXTERNAL,
  514. .ch[0] = {
  515. .chan = LCDC_CHAN_MAINLCD,
  516. .bpp = 16,
  517. .interface_type = RGB24,
  518. .clock_divider = 1,
  519. .flags = LCDC_FLAGS_DWPOL,
  520. .lcd_cfg = {
  521. .name = "HDMI",
  522. /* So far only 720p is supported */
  523. .xres = 1280,
  524. .yres = 720,
  525. /*
  526. * If left and right margins are not multiples of 8,
  527. * LDHAJR will be adjusted accordingly by the LCDC
  528. * driver. Until we start using EDID, these values
  529. * might have to be adjusted for different monitors.
  530. */
  531. .left_margin = 200,
  532. .right_margin = 88,
  533. .hsync_len = 48,
  534. .upper_margin = 20,
  535. .lower_margin = 5,
  536. .vsync_len = 5,
  537. .pixclock = 13468,
  538. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  539. },
  540. }
  541. };
  542. static struct resource lcdc1_resources[] = {
  543. [0] = {
  544. .name = "LCDC1",
  545. .start = 0xfe944000,
  546. .end = 0xfe947fff,
  547. .flags = IORESOURCE_MEM,
  548. },
  549. [1] = {
  550. .start = intcs_evt2irq(0x17a0),
  551. .flags = IORESOURCE_IRQ,
  552. },
  553. };
  554. static struct platform_device lcdc1_device = {
  555. .name = "sh_mobile_lcdc_fb",
  556. .num_resources = ARRAY_SIZE(lcdc1_resources),
  557. .resource = lcdc1_resources,
  558. .id = 1,
  559. .dev = {
  560. .platform_data = &sh_mobile_lcdc1_info,
  561. .coherent_dma_mask = ~0,
  562. },
  563. };
  564. static struct sh_mobile_hdmi_info hdmi_info = {
  565. .lcd_chan = &sh_mobile_lcdc1_info.ch[0],
  566. .lcd_dev = &lcdc1_device.dev,
  567. };
  568. static struct resource hdmi_resources[] = {
  569. [0] = {
  570. .name = "HDMI",
  571. .start = 0xe6be0000,
  572. .end = 0xe6be00ff,
  573. .flags = IORESOURCE_MEM,
  574. },
  575. [1] = {
  576. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  577. .start = evt2irq(0x17e0),
  578. .flags = IORESOURCE_IRQ,
  579. },
  580. };
  581. static struct platform_device hdmi_device = {
  582. .name = "sh-mobile-hdmi",
  583. .num_resources = ARRAY_SIZE(hdmi_resources),
  584. .resource = hdmi_resources,
  585. .id = -1,
  586. .dev = {
  587. .platform_data = &hdmi_info,
  588. },
  589. };
  590. static struct gpio_led ap4evb_leds[] = {
  591. {
  592. .name = "led4",
  593. .gpio = GPIO_PORT185,
  594. .default_state = LEDS_GPIO_DEFSTATE_ON,
  595. },
  596. {
  597. .name = "led2",
  598. .gpio = GPIO_PORT186,
  599. .default_state = LEDS_GPIO_DEFSTATE_ON,
  600. },
  601. {
  602. .name = "led3",
  603. .gpio = GPIO_PORT187,
  604. .default_state = LEDS_GPIO_DEFSTATE_ON,
  605. },
  606. {
  607. .name = "led1",
  608. .gpio = GPIO_PORT188,
  609. .default_state = LEDS_GPIO_DEFSTATE_ON,
  610. }
  611. };
  612. static struct gpio_led_platform_data ap4evb_leds_pdata = {
  613. .num_leds = ARRAY_SIZE(ap4evb_leds),
  614. .leds = ap4evb_leds,
  615. };
  616. static struct platform_device leds_device = {
  617. .name = "leds-gpio",
  618. .id = 0,
  619. .dev = {
  620. .platform_data = &ap4evb_leds_pdata,
  621. },
  622. };
  623. static struct platform_device *ap4evb_devices[] __initdata = {
  624. &leds_device,
  625. &nor_flash_device,
  626. &smc911x_device,
  627. &sdhi0_device,
  628. &sdhi1_device,
  629. &usb1_host_device,
  630. &fsi_device,
  631. &sh_mmcif_device,
  632. &lcdc1_device,
  633. &lcdc_device,
  634. &hdmi_device,
  635. };
  636. static int __init hdmi_init_pm_clock(void)
  637. {
  638. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  639. int ret;
  640. long rate;
  641. if (IS_ERR(hdmi_ick)) {
  642. ret = PTR_ERR(hdmi_ick);
  643. pr_err("Cannot get HDMI ICK: %d\n", ret);
  644. goto out;
  645. }
  646. ret = clk_set_parent(&pllc2_clk, &dv_clki_div2_clk);
  647. if (ret < 0) {
  648. pr_err("Cannot set PLLC2 parent: %d, %d users\n", ret, pllc2_clk.usecount);
  649. goto out;
  650. }
  651. pr_debug("PLLC2 initial frequency %lu\n", clk_get_rate(&pllc2_clk));
  652. rate = clk_round_rate(&pllc2_clk, 594000000);
  653. if (rate < 0) {
  654. pr_err("Cannot get suitable rate: %ld\n", rate);
  655. ret = rate;
  656. goto out;
  657. }
  658. ret = clk_set_rate(&pllc2_clk, rate);
  659. if (ret < 0) {
  660. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  661. goto out;
  662. }
  663. pr_debug("PLLC2 set frequency %lu\n", rate);
  664. ret = clk_set_parent(hdmi_ick, &pllc2_clk);
  665. if (ret < 0) {
  666. pr_err("Cannot set HDMI parent: %d\n", ret);
  667. goto out;
  668. }
  669. out:
  670. if (!IS_ERR(hdmi_ick))
  671. clk_put(hdmi_ick);
  672. return ret;
  673. }
  674. device_initcall(hdmi_init_pm_clock);
  675. /*
  676. * FIXME !!
  677. *
  678. * gpio_no_direction
  679. * gpio_pull_up
  680. * are quick_hack.
  681. *
  682. * current gpio frame work doesn't have
  683. * the method to control only pull up/down/free.
  684. * this function should be replaced by correct gpio function
  685. */
  686. static void __init gpio_no_direction(u32 addr)
  687. {
  688. __raw_writeb(0x00, addr);
  689. }
  690. static void __init gpio_pull_up(u32 addr)
  691. {
  692. u8 data = __raw_readb(addr);
  693. data &= 0x0F;
  694. data |= 0xC0;
  695. __raw_writeb(data, addr);
  696. }
  697. /* TouchScreen */
  698. #define IRQ28 evt2irq(0x3380) /* IRQ28A */
  699. #define IRQ7 evt2irq(0x02e0) /* IRQ7A */
  700. static int ts_get_pendown_state(void)
  701. {
  702. int val1, val2;
  703. gpio_free(GPIO_FN_IRQ28_123);
  704. gpio_free(GPIO_FN_IRQ7_40);
  705. gpio_request(GPIO_PORT123, NULL);
  706. gpio_request(GPIO_PORT40, NULL);
  707. gpio_direction_input(GPIO_PORT123);
  708. gpio_direction_input(GPIO_PORT40);
  709. val1 = gpio_get_value(GPIO_PORT123);
  710. val2 = gpio_get_value(GPIO_PORT40);
  711. gpio_request(GPIO_FN_IRQ28_123, NULL); /* for QHD */
  712. gpio_request(GPIO_FN_IRQ7_40, NULL); /* for WVGA */
  713. return val1 ^ val2;
  714. }
  715. #define PORT40CR 0xE6051028
  716. #define PORT123CR 0xE605007B
  717. static int ts_init(void)
  718. {
  719. gpio_request(GPIO_FN_IRQ28_123, NULL); /* for QHD */
  720. gpio_request(GPIO_FN_IRQ7_40, NULL); /* for WVGA */
  721. gpio_pull_up(PORT40CR);
  722. gpio_pull_up(PORT123CR);
  723. return 0;
  724. }
  725. static struct tsc2007_platform_data tsc2007_info = {
  726. .model = 2007,
  727. .x_plate_ohms = 180,
  728. .get_pendown_state = ts_get_pendown_state,
  729. .init_platform_hw = ts_init,
  730. };
  731. static struct i2c_board_info tsc_device = {
  732. I2C_BOARD_INFO("tsc2007", 0x48),
  733. .type = "tsc2007",
  734. .platform_data = &tsc2007_info,
  735. /*.irq is selected on ap4evb_init */
  736. };
  737. /* I2C */
  738. static struct i2c_board_info i2c0_devices[] = {
  739. {
  740. I2C_BOARD_INFO("ak4643", 0x13),
  741. },
  742. };
  743. static struct i2c_board_info i2c1_devices[] = {
  744. {
  745. I2C_BOARD_INFO("r2025sd", 0x32),
  746. },
  747. };
  748. static struct map_desc ap4evb_io_desc[] __initdata = {
  749. /* create a 1:1 entity map for 0xe6xxxxxx
  750. * used by CPGA, INTC and PFC.
  751. */
  752. {
  753. .virtual = 0xe6000000,
  754. .pfn = __phys_to_pfn(0xe6000000),
  755. .length = 256 << 20,
  756. .type = MT_DEVICE_NONSHARED
  757. },
  758. };
  759. static void __init ap4evb_map_io(void)
  760. {
  761. iotable_init(ap4evb_io_desc, ARRAY_SIZE(ap4evb_io_desc));
  762. /* setup early devices and console here as well */
  763. sh7372_add_early_devices();
  764. shmobile_setup_console();
  765. }
  766. #define GPIO_PORT9CR 0xE6051009
  767. #define GPIO_PORT10CR 0xE605100A
  768. static void __init ap4evb_init(void)
  769. {
  770. u32 srcr4;
  771. struct clk *clk;
  772. sh7372_pinmux_init();
  773. /* enable SCIFA0 */
  774. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  775. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  776. /* enable SMSC911X */
  777. gpio_request(GPIO_FN_CS5A, NULL);
  778. gpio_request(GPIO_FN_IRQ6_39, NULL);
  779. /* enable Debug switch (S6) */
  780. gpio_request(GPIO_PORT32, NULL);
  781. gpio_request(GPIO_PORT33, NULL);
  782. gpio_request(GPIO_PORT34, NULL);
  783. gpio_request(GPIO_PORT35, NULL);
  784. gpio_direction_input(GPIO_PORT32);
  785. gpio_direction_input(GPIO_PORT33);
  786. gpio_direction_input(GPIO_PORT34);
  787. gpio_direction_input(GPIO_PORT35);
  788. gpio_export(GPIO_PORT32, 0);
  789. gpio_export(GPIO_PORT33, 0);
  790. gpio_export(GPIO_PORT34, 0);
  791. gpio_export(GPIO_PORT35, 0);
  792. /* SDHI0 */
  793. gpio_request(GPIO_FN_SDHICD0, NULL);
  794. gpio_request(GPIO_FN_SDHIWP0, NULL);
  795. gpio_request(GPIO_FN_SDHICMD0, NULL);
  796. gpio_request(GPIO_FN_SDHICLK0, NULL);
  797. gpio_request(GPIO_FN_SDHID0_3, NULL);
  798. gpio_request(GPIO_FN_SDHID0_2, NULL);
  799. gpio_request(GPIO_FN_SDHID0_1, NULL);
  800. gpio_request(GPIO_FN_SDHID0_0, NULL);
  801. /* SDHI1 */
  802. gpio_request(GPIO_FN_SDHICMD1, NULL);
  803. gpio_request(GPIO_FN_SDHICLK1, NULL);
  804. gpio_request(GPIO_FN_SDHID1_3, NULL);
  805. gpio_request(GPIO_FN_SDHID1_2, NULL);
  806. gpio_request(GPIO_FN_SDHID1_1, NULL);
  807. gpio_request(GPIO_FN_SDHID1_0, NULL);
  808. /* MMCIF */
  809. gpio_request(GPIO_FN_MMCD0_0, NULL);
  810. gpio_request(GPIO_FN_MMCD0_1, NULL);
  811. gpio_request(GPIO_FN_MMCD0_2, NULL);
  812. gpio_request(GPIO_FN_MMCD0_3, NULL);
  813. gpio_request(GPIO_FN_MMCD0_4, NULL);
  814. gpio_request(GPIO_FN_MMCD0_5, NULL);
  815. gpio_request(GPIO_FN_MMCD0_6, NULL);
  816. gpio_request(GPIO_FN_MMCD0_7, NULL);
  817. gpio_request(GPIO_FN_MMCCMD0, NULL);
  818. gpio_request(GPIO_FN_MMCCLK0, NULL);
  819. /* USB enable */
  820. gpio_request(GPIO_FN_VBUS0_1, NULL);
  821. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  822. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  823. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  824. gpio_request(GPIO_FN_EXTLP_1, NULL);
  825. gpio_request(GPIO_FN_OVCN2_1, NULL);
  826. /* setup USB phy */
  827. __raw_writew(0x8a0a, 0xE6058130); /* USBCR2 */
  828. /* enable FSI2 */
  829. gpio_request(GPIO_FN_FSIAIBT, NULL);
  830. gpio_request(GPIO_FN_FSIAILR, NULL);
  831. gpio_request(GPIO_FN_FSIAISLD, NULL);
  832. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  833. gpio_request(GPIO_PORT161, NULL);
  834. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  835. gpio_request(GPIO_PORT9, NULL);
  836. gpio_request(GPIO_PORT10, NULL);
  837. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  838. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  839. /* set SPU2 clock to 119.6 MHz */
  840. clk = clk_get(NULL, "spu_clk");
  841. if (!IS_ERR(clk)) {
  842. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  843. clk_put(clk);
  844. }
  845. /* change parent of FSI A */
  846. clk = clk_get(NULL, "fsia_clk");
  847. if (!IS_ERR(clk)) {
  848. clk_register(&fsiackcr_clk);
  849. clk_set_parent(clk, &fsiackcr_clk);
  850. clk_put(clk);
  851. }
  852. /*
  853. * set irq priority, to avoid sound chopping
  854. * when NFS rootfs is used
  855. * FSI(3) > SMSC911X(2)
  856. */
  857. intc_set_priority(IRQ_FSI, 3);
  858. i2c_register_board_info(0, i2c0_devices,
  859. ARRAY_SIZE(i2c0_devices));
  860. i2c_register_board_info(1, i2c1_devices,
  861. ARRAY_SIZE(i2c1_devices));
  862. #ifdef CONFIG_AP4EVB_QHD
  863. /*
  864. * QHD
  865. */
  866. /* enable KEYSC */
  867. gpio_request(GPIO_FN_KEYOUT0, NULL);
  868. gpio_request(GPIO_FN_KEYOUT1, NULL);
  869. gpio_request(GPIO_FN_KEYOUT2, NULL);
  870. gpio_request(GPIO_FN_KEYOUT3, NULL);
  871. gpio_request(GPIO_FN_KEYOUT4, NULL);
  872. gpio_request(GPIO_FN_KEYIN0_136, NULL);
  873. gpio_request(GPIO_FN_KEYIN1_135, NULL);
  874. gpio_request(GPIO_FN_KEYIN2_134, NULL);
  875. gpio_request(GPIO_FN_KEYIN3_133, NULL);
  876. gpio_request(GPIO_FN_KEYIN4, NULL);
  877. /* enable TouchScreen */
  878. set_irq_type(IRQ28, IRQ_TYPE_LEVEL_LOW);
  879. tsc_device.irq = IRQ28;
  880. i2c_register_board_info(1, &tsc_device, 1);
  881. /* LCDC0 */
  882. lcdc_info.clock_source = LCDC_CLK_PERIPHERAL;
  883. lcdc_info.ch[0].interface_type = RGB24;
  884. lcdc_info.ch[0].clock_divider = 1;
  885. lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
  886. lcdc_info.ch[0].lcd_cfg.name = "R63302(QHD)";
  887. lcdc_info.ch[0].lcd_cfg.xres = 544;
  888. lcdc_info.ch[0].lcd_cfg.yres = 961;
  889. lcdc_info.ch[0].lcd_cfg.left_margin = 72;
  890. lcdc_info.ch[0].lcd_cfg.right_margin = 600;
  891. lcdc_info.ch[0].lcd_cfg.hsync_len = 16;
  892. lcdc_info.ch[0].lcd_cfg.upper_margin = 8;
  893. lcdc_info.ch[0].lcd_cfg.lower_margin = 8;
  894. lcdc_info.ch[0].lcd_cfg.vsync_len = 2;
  895. lcdc_info.ch[0].lcd_cfg.sync = FB_SYNC_VERT_HIGH_ACT |
  896. FB_SYNC_HOR_HIGH_ACT;
  897. lcdc_info.ch[0].lcd_size_cfg.width = 44;
  898. lcdc_info.ch[0].lcd_size_cfg.height = 79;
  899. platform_add_devices(qhd_devices, ARRAY_SIZE(qhd_devices));
  900. #else
  901. /*
  902. * WVGA
  903. */
  904. gpio_request(GPIO_FN_LCDD17, NULL);
  905. gpio_request(GPIO_FN_LCDD16, NULL);
  906. gpio_request(GPIO_FN_LCDD15, NULL);
  907. gpio_request(GPIO_FN_LCDD14, NULL);
  908. gpio_request(GPIO_FN_LCDD13, NULL);
  909. gpio_request(GPIO_FN_LCDD12, NULL);
  910. gpio_request(GPIO_FN_LCDD11, NULL);
  911. gpio_request(GPIO_FN_LCDD10, NULL);
  912. gpio_request(GPIO_FN_LCDD9, NULL);
  913. gpio_request(GPIO_FN_LCDD8, NULL);
  914. gpio_request(GPIO_FN_LCDD7, NULL);
  915. gpio_request(GPIO_FN_LCDD6, NULL);
  916. gpio_request(GPIO_FN_LCDD5, NULL);
  917. gpio_request(GPIO_FN_LCDD4, NULL);
  918. gpio_request(GPIO_FN_LCDD3, NULL);
  919. gpio_request(GPIO_FN_LCDD2, NULL);
  920. gpio_request(GPIO_FN_LCDD1, NULL);
  921. gpio_request(GPIO_FN_LCDD0, NULL);
  922. gpio_request(GPIO_FN_LCDDISP, NULL);
  923. gpio_request(GPIO_FN_LCDDCK, NULL);
  924. gpio_request(GPIO_PORT189, NULL); /* backlight */
  925. gpio_direction_output(GPIO_PORT189, 1);
  926. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  927. gpio_direction_output(GPIO_PORT151, 1);
  928. lcdc_info.clock_source = LCDC_CLK_BUS;
  929. lcdc_info.ch[0].interface_type = RGB18;
  930. lcdc_info.ch[0].clock_divider = 2;
  931. lcdc_info.ch[0].flags = 0;
  932. lcdc_info.ch[0].lcd_cfg.name = "WVGA Panel";
  933. lcdc_info.ch[0].lcd_cfg.xres = 800;
  934. lcdc_info.ch[0].lcd_cfg.yres = 480;
  935. lcdc_info.ch[0].lcd_cfg.left_margin = 220;
  936. lcdc_info.ch[0].lcd_cfg.right_margin = 110;
  937. lcdc_info.ch[0].lcd_cfg.hsync_len = 70;
  938. lcdc_info.ch[0].lcd_cfg.upper_margin = 20;
  939. lcdc_info.ch[0].lcd_cfg.lower_margin = 5;
  940. lcdc_info.ch[0].lcd_cfg.vsync_len = 5;
  941. lcdc_info.ch[0].lcd_cfg.sync = 0;
  942. lcdc_info.ch[0].lcd_size_cfg.width = 152;
  943. lcdc_info.ch[0].lcd_size_cfg.height = 91;
  944. /* enable TouchScreen */
  945. set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  946. tsc_device.irq = IRQ7;
  947. i2c_register_board_info(0, &tsc_device, 1);
  948. #endif /* CONFIG_AP4EVB_QHD */
  949. sh7372_add_standard_devices();
  950. /* HDMI */
  951. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  952. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  953. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  954. #define SRCR4 0xe61580bc
  955. srcr4 = __raw_readl(SRCR4);
  956. __raw_writel(srcr4 | (1 << 13), SRCR4);
  957. udelay(50);
  958. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  959. platform_add_devices(ap4evb_devices, ARRAY_SIZE(ap4evb_devices));
  960. }
  961. static void __init ap4evb_timer_init(void)
  962. {
  963. sh7372_clock_init();
  964. shmobile_timer.init();
  965. /* External clock source */
  966. clk_set_rate(&dv_clki_clk, 27000000);
  967. }
  968. static struct sys_timer ap4evb_timer = {
  969. .init = ap4evb_timer_init,
  970. };
  971. MACHINE_START(AP4EVB, "ap4evb")
  972. .phys_io = 0xe6000000,
  973. .io_pg_offst = ((0xe6000000) >> 18) & 0xfffc,
  974. .map_io = ap4evb_map_io,
  975. .init_irq = sh7372_init_irq,
  976. .init_machine = ap4evb_init,
  977. .timer = &ap4evb_timer,
  978. MACHINE_END