board-ap4evb.c 32 KB

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