board-ap4evb.c 25 KB

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