board-ap4evb.c 27 KB

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