board-ap4evb.c 33 KB

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