board-ap4evb.c 25 KB

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