board-ap4evb.c 27 KB

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