board-armadillo800eva.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  1. /*
  2. * armadillo 800 eva board support
  3. *
  4. * Copyright (C) 2012 Renesas Solutions Corp.
  5. * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  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. */
  21. #include <linux/clk.h>
  22. #include <linux/delay.h>
  23. #include <linux/err.h>
  24. #include <linux/kernel.h>
  25. #include <linux/input.h>
  26. #include <linux/irq.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/gpio.h>
  29. #include <linux/gpio_keys.h>
  30. #include <linux/sh_eth.h>
  31. #include <linux/videodev2.h>
  32. #include <linux/usb/renesas_usbhs.h>
  33. #include <linux/mfd/tmio.h>
  34. #include <linux/mmc/host.h>
  35. #include <linux/mmc/sh_mmcif.h>
  36. #include <linux/mmc/sh_mobile_sdhi.h>
  37. #include <mach/common.h>
  38. #include <mach/irqs.h>
  39. #include <mach/r8a7740.h>
  40. #include <media/mt9t112.h>
  41. #include <media/sh_mobile_ceu.h>
  42. #include <media/soc_camera.h>
  43. #include <asm/page.h>
  44. #include <asm/mach-types.h>
  45. #include <asm/mach/arch.h>
  46. #include <asm/mach/map.h>
  47. #include <asm/mach/time.h>
  48. #include <asm/hardware/cache-l2x0.h>
  49. #include <video/sh_mobile_lcdc.h>
  50. #include <video/sh_mobile_hdmi.h>
  51. #include <sound/sh_fsi.h>
  52. #include <sound/simple_card.h>
  53. /*
  54. * CON1 Camera Module
  55. * CON2 Extension Bus
  56. * CON3 HDMI Output
  57. * CON4 Composite Video Output
  58. * CON5 H-UDI JTAG
  59. * CON6 ARM JTAG
  60. * CON7 SD1
  61. * CON8 SD2
  62. * CON9 RTC BackUp
  63. * CON10 Monaural Mic Input
  64. * CON11 Stereo Headphone Output
  65. * CON12 Audio Line Output(L)
  66. * CON13 Audio Line Output(R)
  67. * CON14 AWL13 Module
  68. * CON15 Extension
  69. * CON16 LCD1
  70. * CON17 LCD2
  71. * CON19 Power Input
  72. * CON20 USB1
  73. * CON21 USB2
  74. * CON22 Serial
  75. * CON23 LAN
  76. * CON24 USB3
  77. * LED1 Camera LED(Yellow)
  78. * LED2 Power LED (Green)
  79. * ED3-LED6 User LED(Yellow)
  80. * LED7 LAN link LED(Green)
  81. * LED8 LAN activity LED(Yellow)
  82. */
  83. /*
  84. * DipSwitch
  85. *
  86. * SW1
  87. *
  88. * -12345678-+---------------+----------------------------
  89. * 1 | boot | hermit
  90. * 0 | boot | OS auto boot
  91. * -12345678-+---------------+----------------------------
  92. * 00 | boot device | eMMC
  93. * 10 | boot device | SDHI0 (CON7)
  94. * 01 | boot device | -
  95. * 11 | boot device | Extension Buss (CS0)
  96. * -12345678-+---------------+----------------------------
  97. * 0 | Extension Bus | D8-D15 disable, eMMC enable
  98. * 1 | Extension Bus | D8-D15 enable, eMMC disable
  99. * -12345678-+---------------+----------------------------
  100. * 0 | SDHI1 | COM8 disable, COM14 enable
  101. * 1 | SDHI1 | COM8 enable, COM14 disable
  102. * -12345678-+---------------+----------------------------
  103. * 0 | USB0 | COM20 enable, COM24 disable
  104. * 1 | USB0 | COM20 disable, COM24 enable
  105. * -12345678-+---------------+----------------------------
  106. * 00 | JTAG | SH-X2
  107. * 10 | JTAG | ARM
  108. * 01 | JTAG | -
  109. * 11 | JTAG | Boundary Scan
  110. *-----------+---------------+----------------------------
  111. */
  112. /*
  113. * FSI-WM8978
  114. *
  115. * this command is required when playback.
  116. *
  117. * # amixer set "Headphone" 50
  118. */
  119. /*
  120. * USB function
  121. *
  122. * When you use USB Function,
  123. * set SW1.6 ON, and connect cable to CN24.
  124. *
  125. * USBF needs workaround on R8A7740 chip.
  126. * These are a little bit complex.
  127. * see
  128. * usbhsf_power_ctrl()
  129. *
  130. * CAUTION
  131. *
  132. * It uses autonomy mode for USB hotplug at this point
  133. * (= usbhs_private.platform_callback.get_vbus is NULL),
  134. * since we don't know what's happen on PM control
  135. * on this workaround.
  136. */
  137. #define USBCR1 0xe605810a
  138. #define USBH 0xC6700000
  139. #define USBH_USBCTR 0x10834
  140. struct usbhsf_private {
  141. struct clk *phy;
  142. struct clk *usb24;
  143. struct clk *pci;
  144. struct clk *func;
  145. struct clk *host;
  146. void __iomem *usbh_base;
  147. struct renesas_usbhs_platform_info info;
  148. };
  149. #define usbhsf_get_priv(pdev) \
  150. container_of(renesas_usbhs_get_info(pdev), \
  151. struct usbhsf_private, info)
  152. static int usbhsf_get_id(struct platform_device *pdev)
  153. {
  154. return USBHS_GADGET;
  155. }
  156. static void usbhsf_power_ctrl(struct platform_device *pdev,
  157. void __iomem *base, int enable)
  158. {
  159. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  160. /*
  161. * Work around for USB Function.
  162. * It needs USB host clock, and settings
  163. */
  164. if (enable) {
  165. /*
  166. * enable all the related usb clocks
  167. * for usb workaround
  168. */
  169. clk_enable(priv->usb24);
  170. clk_enable(priv->pci);
  171. clk_enable(priv->host);
  172. clk_enable(priv->func);
  173. clk_enable(priv->phy);
  174. /*
  175. * set USBCR1
  176. *
  177. * Port1 is driven by USB function,
  178. * Port2 is driven by USB HOST
  179. * One HOST (Port1 or Port2 is HOST)
  180. * USB PLL input clock = 24MHz
  181. */
  182. __raw_writew(0xd750, USBCR1);
  183. mdelay(1);
  184. /*
  185. * start USB Host
  186. */
  187. __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
  188. __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
  189. mdelay(10);
  190. /*
  191. * USB PHY Power ON
  192. */
  193. __raw_writew(0xd770, USBCR1);
  194. __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
  195. } else {
  196. __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
  197. __raw_writew(0xd7c0, USBCR1); /* GPIO */
  198. clk_disable(priv->phy);
  199. clk_disable(priv->func); /* usb work around */
  200. clk_disable(priv->host); /* usb work around */
  201. clk_disable(priv->pci); /* usb work around */
  202. clk_disable(priv->usb24); /* usb work around */
  203. }
  204. }
  205. static void usbhsf_hardware_exit(struct platform_device *pdev)
  206. {
  207. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  208. if (!IS_ERR(priv->phy))
  209. clk_put(priv->phy);
  210. if (!IS_ERR(priv->usb24))
  211. clk_put(priv->usb24);
  212. if (!IS_ERR(priv->pci))
  213. clk_put(priv->pci);
  214. if (!IS_ERR(priv->host))
  215. clk_put(priv->host);
  216. if (!IS_ERR(priv->func))
  217. clk_put(priv->func);
  218. if (priv->usbh_base)
  219. iounmap(priv->usbh_base);
  220. priv->phy = NULL;
  221. priv->usb24 = NULL;
  222. priv->pci = NULL;
  223. priv->host = NULL;
  224. priv->func = NULL;
  225. priv->usbh_base = NULL;
  226. }
  227. static int usbhsf_hardware_init(struct platform_device *pdev)
  228. {
  229. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  230. priv->phy = clk_get(&pdev->dev, "phy");
  231. priv->usb24 = clk_get(&pdev->dev, "usb24");
  232. priv->pci = clk_get(&pdev->dev, "pci");
  233. priv->func = clk_get(&pdev->dev, "func");
  234. priv->host = clk_get(&pdev->dev, "host");
  235. priv->usbh_base = ioremap_nocache(USBH, 0x20000);
  236. if (IS_ERR(priv->phy) ||
  237. IS_ERR(priv->usb24) ||
  238. IS_ERR(priv->pci) ||
  239. IS_ERR(priv->host) ||
  240. IS_ERR(priv->func) ||
  241. !priv->usbh_base) {
  242. dev_err(&pdev->dev, "USB clock setting failed\n");
  243. usbhsf_hardware_exit(pdev);
  244. return -EIO;
  245. }
  246. /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
  247. clk_set_rate(priv->usb24,
  248. clk_get_rate(clk_get_parent(priv->usb24)));
  249. return 0;
  250. }
  251. static struct usbhsf_private usbhsf_private = {
  252. .info = {
  253. .platform_callback = {
  254. .get_id = usbhsf_get_id,
  255. .hardware_init = usbhsf_hardware_init,
  256. .hardware_exit = usbhsf_hardware_exit,
  257. .power_ctrl = usbhsf_power_ctrl,
  258. },
  259. .driver_param = {
  260. .buswait_bwait = 5,
  261. .detection_delay = 5,
  262. .d0_rx_id = SHDMA_SLAVE_USBHS_RX,
  263. .d1_tx_id = SHDMA_SLAVE_USBHS_TX,
  264. },
  265. }
  266. };
  267. static struct resource usbhsf_resources[] = {
  268. {
  269. .name = "USBHS",
  270. .start = 0xe6890000,
  271. .end = 0xe6890104 - 1,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. {
  275. .start = evt2irq(0x0A20),
  276. .flags = IORESOURCE_IRQ,
  277. },
  278. };
  279. static struct platform_device usbhsf_device = {
  280. .name = "renesas_usbhs",
  281. .dev = {
  282. .platform_data = &usbhsf_private.info,
  283. },
  284. .id = -1,
  285. .num_resources = ARRAY_SIZE(usbhsf_resources),
  286. .resource = usbhsf_resources,
  287. };
  288. /* Ether */
  289. static struct sh_eth_plat_data sh_eth_platdata = {
  290. .phy = 0x00, /* LAN8710A */
  291. .edmac_endian = EDMAC_LITTLE_ENDIAN,
  292. .register_type = SH_ETH_REG_GIGABIT,
  293. .phy_interface = PHY_INTERFACE_MODE_MII,
  294. };
  295. static struct resource sh_eth_resources[] = {
  296. {
  297. .start = 0xe9a00000,
  298. .end = 0xe9a00800 - 1,
  299. .flags = IORESOURCE_MEM,
  300. }, {
  301. .start = 0xe9a01800,
  302. .end = 0xe9a02000 - 1,
  303. .flags = IORESOURCE_MEM,
  304. }, {
  305. .start = evt2irq(0x0500),
  306. .flags = IORESOURCE_IRQ,
  307. },
  308. };
  309. static struct platform_device sh_eth_device = {
  310. .name = "sh-eth",
  311. .id = -1,
  312. .dev = {
  313. .platform_data = &sh_eth_platdata,
  314. },
  315. .resource = sh_eth_resources,
  316. .num_resources = ARRAY_SIZE(sh_eth_resources),
  317. };
  318. /* LCDC */
  319. static struct fb_videomode lcdc0_mode = {
  320. .name = "AMPIER/AM-800480",
  321. .xres = 800,
  322. .yres = 480,
  323. .left_margin = 88,
  324. .right_margin = 40,
  325. .hsync_len = 128,
  326. .upper_margin = 20,
  327. .lower_margin = 5,
  328. .vsync_len = 5,
  329. .sync = 0,
  330. };
  331. static struct sh_mobile_lcdc_info lcdc0_info = {
  332. .clock_source = LCDC_CLK_BUS,
  333. .ch[0] = {
  334. .chan = LCDC_CHAN_MAINLCD,
  335. .fourcc = V4L2_PIX_FMT_RGB565,
  336. .interface_type = RGB24,
  337. .clock_divider = 5,
  338. .flags = 0,
  339. .lcd_modes = &lcdc0_mode,
  340. .num_modes = 1,
  341. .panel_cfg = {
  342. .width = 111,
  343. .height = 68,
  344. },
  345. },
  346. };
  347. static struct resource lcdc0_resources[] = {
  348. [0] = {
  349. .name = "LCD0",
  350. .start = 0xfe940000,
  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 lcdc0_device = {
  360. .name = "sh_mobile_lcdc_fb",
  361. .num_resources = ARRAY_SIZE(lcdc0_resources),
  362. .resource = lcdc0_resources,
  363. .id = 0,
  364. .dev = {
  365. .platform_data = &lcdc0_info,
  366. .coherent_dma_mask = ~0,
  367. },
  368. };
  369. /*
  370. * LCDC1/HDMI
  371. */
  372. static struct sh_mobile_hdmi_info hdmi_info = {
  373. .flags = HDMI_OUTPUT_PUSH_PULL |
  374. HDMI_OUTPUT_POLARITY_HI |
  375. HDMI_32BIT_REG |
  376. HDMI_HAS_HTOP1 |
  377. HDMI_SND_SRC_SPDIF,
  378. };
  379. static struct resource hdmi_resources[] = {
  380. [0] = {
  381. .name = "HDMI",
  382. .start = 0xe6be0000,
  383. .end = 0xe6be03ff,
  384. .flags = IORESOURCE_MEM,
  385. },
  386. [1] = {
  387. .start = evt2irq(0x1700),
  388. .flags = IORESOURCE_IRQ,
  389. },
  390. [2] = {
  391. .name = "HDMI emma3pf",
  392. .start = 0xe6be4000,
  393. .end = 0xe6be43ff,
  394. .flags = IORESOURCE_MEM,
  395. },
  396. };
  397. static struct platform_device hdmi_device = {
  398. .name = "sh-mobile-hdmi",
  399. .num_resources = ARRAY_SIZE(hdmi_resources),
  400. .resource = hdmi_resources,
  401. .id = -1,
  402. .dev = {
  403. .platform_data = &hdmi_info,
  404. },
  405. };
  406. static const struct fb_videomode lcdc1_mode = {
  407. .name = "HDMI 720p",
  408. .xres = 1280,
  409. .yres = 720,
  410. .pixclock = 13468,
  411. .left_margin = 220,
  412. .right_margin = 110,
  413. .hsync_len = 40,
  414. .upper_margin = 20,
  415. .lower_margin = 5,
  416. .vsync_len = 5,
  417. .refresh = 60,
  418. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  419. };
  420. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  421. .clock_source = LCDC_CLK_PERIPHERAL, /* HDMI clock */
  422. .ch[0] = {
  423. .chan = LCDC_CHAN_MAINLCD,
  424. .fourcc = V4L2_PIX_FMT_RGB565,
  425. .interface_type = RGB24,
  426. .clock_divider = 1,
  427. .flags = LCDC_FLAGS_DWPOL,
  428. .lcd_modes = &lcdc1_mode,
  429. .num_modes = 1,
  430. .tx_dev = &hdmi_device,
  431. .panel_cfg = {
  432. .width = 1280,
  433. .height = 720,
  434. },
  435. },
  436. };
  437. static struct resource hdmi_lcdc_resources[] = {
  438. [0] = {
  439. .name = "LCDC1",
  440. .start = 0xfe944000,
  441. .end = 0xfe948000 - 1,
  442. .flags = IORESOURCE_MEM,
  443. },
  444. [1] = {
  445. .start = intcs_evt2irq(0x1780),
  446. .flags = IORESOURCE_IRQ,
  447. },
  448. };
  449. static struct platform_device hdmi_lcdc_device = {
  450. .name = "sh_mobile_lcdc_fb",
  451. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  452. .resource = hdmi_lcdc_resources,
  453. .id = 1,
  454. .dev = {
  455. .platform_data = &hdmi_lcdc_info,
  456. .coherent_dma_mask = ~0,
  457. },
  458. };
  459. /* GPIO KEY */
  460. #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
  461. static struct gpio_keys_button gpio_buttons[] = {
  462. GPIO_KEY(KEY_POWER, GPIO_PORT99, "SW1"),
  463. GPIO_KEY(KEY_BACK, GPIO_PORT100, "SW2"),
  464. GPIO_KEY(KEY_MENU, GPIO_PORT97, "SW3"),
  465. GPIO_KEY(KEY_HOME, GPIO_PORT98, "SW4"),
  466. };
  467. static struct gpio_keys_platform_data gpio_key_info = {
  468. .buttons = gpio_buttons,
  469. .nbuttons = ARRAY_SIZE(gpio_buttons),
  470. };
  471. static struct platform_device gpio_keys_device = {
  472. .name = "gpio-keys",
  473. .id = -1,
  474. .dev = {
  475. .platform_data = &gpio_key_info,
  476. },
  477. };
  478. /* SDHI0 */
  479. /*
  480. * FIXME
  481. *
  482. * It use polling mode here, since
  483. * CD (= Card Detect) pin is not connected to SDHI0_CD.
  484. * We can use IRQ31 as card detect irq,
  485. * but it needs chattering removal operation
  486. */
  487. #define IRQ31 evt2irq(0x33E0)
  488. static struct sh_mobile_sdhi_info sdhi0_info = {
  489. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  490. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  491. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |\
  492. MMC_CAP_NEEDS_POLL,
  493. .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  494. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  495. };
  496. static struct resource sdhi0_resources[] = {
  497. {
  498. .name = "SDHI0",
  499. .start = 0xe6850000,
  500. .end = 0xe6850100 - 1,
  501. .flags = IORESOURCE_MEM,
  502. },
  503. /*
  504. * no SH_MOBILE_SDHI_IRQ_CARD_DETECT here
  505. */
  506. {
  507. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  508. .start = evt2irq(0x0E20),
  509. .flags = IORESOURCE_IRQ,
  510. },
  511. {
  512. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  513. .start = evt2irq(0x0E40),
  514. .flags = IORESOURCE_IRQ,
  515. },
  516. };
  517. static struct platform_device sdhi0_device = {
  518. .name = "sh_mobile_sdhi",
  519. .id = 0,
  520. .dev = {
  521. .platform_data = &sdhi0_info,
  522. },
  523. .num_resources = ARRAY_SIZE(sdhi0_resources),
  524. .resource = sdhi0_resources,
  525. };
  526. /* SDHI1 */
  527. static struct sh_mobile_sdhi_info sdhi1_info = {
  528. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  529. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  530. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  531. .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  532. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  533. };
  534. static struct resource sdhi1_resources[] = {
  535. [0] = {
  536. .name = "SDHI1",
  537. .start = 0xe6860000,
  538. .end = 0xe6860100 - 1,
  539. .flags = IORESOURCE_MEM,
  540. },
  541. [1] = {
  542. .start = evt2irq(0x0E80),
  543. .flags = IORESOURCE_IRQ,
  544. },
  545. [2] = {
  546. .start = evt2irq(0x0EA0),
  547. .flags = IORESOURCE_IRQ,
  548. },
  549. [3] = {
  550. .start = evt2irq(0x0EC0),
  551. .flags = IORESOURCE_IRQ,
  552. },
  553. };
  554. static struct platform_device sdhi1_device = {
  555. .name = "sh_mobile_sdhi",
  556. .id = 1,
  557. .dev = {
  558. .platform_data = &sdhi1_info,
  559. },
  560. .num_resources = ARRAY_SIZE(sdhi1_resources),
  561. .resource = sdhi1_resources,
  562. };
  563. /* MMCIF */
  564. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  565. .sup_pclk = 0,
  566. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  567. .caps = MMC_CAP_4_BIT_DATA |
  568. MMC_CAP_8_BIT_DATA |
  569. MMC_CAP_NONREMOVABLE,
  570. };
  571. static struct resource sh_mmcif_resources[] = {
  572. [0] = {
  573. .name = "MMCIF",
  574. .start = 0xe6bd0000,
  575. .end = 0xe6bd0100 - 1,
  576. .flags = IORESOURCE_MEM,
  577. },
  578. [1] = {
  579. /* MMC ERR */
  580. .start = evt2irq(0x1AC0),
  581. .flags = IORESOURCE_IRQ,
  582. },
  583. [2] = {
  584. /* MMC NOR */
  585. .start = evt2irq(0x1AE0),
  586. .flags = IORESOURCE_IRQ,
  587. },
  588. };
  589. static struct platform_device sh_mmcif_device = {
  590. .name = "sh_mmcif",
  591. .id = -1,
  592. .dev = {
  593. .platform_data = &sh_mmcif_plat,
  594. },
  595. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  596. .resource = sh_mmcif_resources,
  597. };
  598. /* Camera */
  599. static int mt9t111_power(struct device *dev, int mode)
  600. {
  601. struct clk *mclk = clk_get(NULL, "video1");
  602. if (IS_ERR(mclk)) {
  603. dev_err(dev, "can't get video1 clock\n");
  604. return -EINVAL;
  605. }
  606. if (mode) {
  607. /* video1 (= CON1 camera) expect 24MHz */
  608. clk_set_rate(mclk, clk_round_rate(mclk, 24000000));
  609. clk_enable(mclk);
  610. gpio_direction_output(GPIO_PORT158, 1);
  611. } else {
  612. gpio_direction_output(GPIO_PORT158, 0);
  613. clk_disable(mclk);
  614. }
  615. clk_put(mclk);
  616. return 0;
  617. }
  618. static struct i2c_board_info i2c_camera_mt9t111 = {
  619. I2C_BOARD_INFO("mt9t112", 0x3d),
  620. };
  621. static struct mt9t112_camera_info mt9t111_info = {
  622. .divider = { 16, 0, 0, 7, 0, 10, 14, 7, 7 },
  623. };
  624. static struct soc_camera_link mt9t111_link = {
  625. .i2c_adapter_id = 0,
  626. .bus_id = 0,
  627. .board_info = &i2c_camera_mt9t111,
  628. .power = mt9t111_power,
  629. .priv = &mt9t111_info,
  630. };
  631. static struct platform_device camera_device = {
  632. .name = "soc-camera-pdrv",
  633. .id = 0,
  634. .dev = {
  635. .platform_data = &mt9t111_link,
  636. },
  637. };
  638. /* CEU0 */
  639. static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
  640. .flags = SH_CEU_FLAG_LOWER_8BIT,
  641. };
  642. static struct resource ceu0_resources[] = {
  643. [0] = {
  644. .name = "CEU",
  645. .start = 0xfe910000,
  646. .end = 0xfe91009f,
  647. .flags = IORESOURCE_MEM,
  648. },
  649. [1] = {
  650. .start = intcs_evt2irq(0x0500),
  651. .flags = IORESOURCE_IRQ,
  652. },
  653. [2] = {
  654. /* place holder for contiguous memory */
  655. },
  656. };
  657. static struct platform_device ceu0_device = {
  658. .name = "sh_mobile_ceu",
  659. .id = 0,
  660. .num_resources = ARRAY_SIZE(ceu0_resources),
  661. .resource = ceu0_resources,
  662. .dev = {
  663. .platform_data = &sh_mobile_ceu0_info,
  664. .coherent_dma_mask = 0xffffffff,
  665. },
  666. };
  667. /* FSI */
  668. static int fsi_hdmi_set_rate(struct device *dev, int rate, int enable)
  669. {
  670. struct clk *fsib;
  671. int ret;
  672. /* it support 48KHz only */
  673. if (48000 != rate)
  674. return -EINVAL;
  675. fsib = clk_get(dev, "ickb");
  676. if (IS_ERR(fsib))
  677. return -EINVAL;
  678. if (enable) {
  679. ret = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  680. clk_enable(fsib);
  681. } else {
  682. ret = 0;
  683. clk_disable(fsib);
  684. }
  685. clk_put(fsib);
  686. return ret;
  687. }
  688. static struct sh_fsi_platform_info fsi_info = {
  689. /* FSI-WM8978 */
  690. .port_a = {
  691. .tx_id = SHDMA_SLAVE_FSIA_TX,
  692. },
  693. /* FSI-HDMI */
  694. .port_b = {
  695. .flags = SH_FSI_FMT_SPDIF |
  696. SH_FSI_ENABLE_STREAM_MODE,
  697. .set_rate = fsi_hdmi_set_rate,
  698. .tx_id = SHDMA_SLAVE_FSIB_TX,
  699. }
  700. };
  701. static struct resource fsi_resources[] = {
  702. [0] = {
  703. .name = "FSI",
  704. .start = 0xfe1f0000,
  705. .end = 0xfe1f8400 - 1,
  706. .flags = IORESOURCE_MEM,
  707. },
  708. [1] = {
  709. .start = evt2irq(0x1840),
  710. .flags = IORESOURCE_IRQ,
  711. },
  712. };
  713. static struct platform_device fsi_device = {
  714. .name = "sh_fsi2",
  715. .id = -1,
  716. .num_resources = ARRAY_SIZE(fsi_resources),
  717. .resource = fsi_resources,
  718. .dev = {
  719. .platform_data = &fsi_info,
  720. },
  721. };
  722. /* FSI-WM8978 */
  723. static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
  724. .fmt = SND_SOC_DAIFMT_I2S,
  725. .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
  726. .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
  727. .sysclk = 12288000,
  728. };
  729. static struct asoc_simple_card_info fsi_wm8978_info = {
  730. .name = "wm8978",
  731. .card = "FSI2A-WM8978",
  732. .cpu_dai = "fsia-dai",
  733. .codec = "wm8978.0-001a",
  734. .platform = "sh_fsi2",
  735. .codec_dai = "wm8978-hifi",
  736. .init = &fsi_wm8978_init_info,
  737. };
  738. static struct platform_device fsi_wm8978_device = {
  739. .name = "asoc-simple-card",
  740. .id = 0,
  741. .dev = {
  742. .platform_data = &fsi_wm8978_info,
  743. },
  744. };
  745. /* FSI-HDMI */
  746. static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
  747. .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
  748. };
  749. static struct asoc_simple_card_info fsi2_hdmi_info = {
  750. .name = "HDMI",
  751. .card = "FSI2B-HDMI",
  752. .cpu_dai = "fsib-dai",
  753. .codec = "sh-mobile-hdmi",
  754. .platform = "sh_fsi2",
  755. .codec_dai = "sh_mobile_hdmi-hifi",
  756. .init = &fsi2_hdmi_init_info,
  757. };
  758. static struct platform_device fsi_hdmi_device = {
  759. .name = "asoc-simple-card",
  760. .id = 1,
  761. .dev = {
  762. .platform_data = &fsi2_hdmi_info,
  763. },
  764. };
  765. /* I2C */
  766. static struct i2c_board_info i2c0_devices[] = {
  767. {
  768. I2C_BOARD_INFO("st1232-ts", 0x55),
  769. .irq = evt2irq(0x0340),
  770. },
  771. {
  772. I2C_BOARD_INFO("wm8978", 0x1a),
  773. },
  774. };
  775. /*
  776. * board devices
  777. */
  778. static struct platform_device *eva_devices[] __initdata = {
  779. &lcdc0_device,
  780. &gpio_keys_device,
  781. &sh_eth_device,
  782. &sdhi0_device,
  783. &sh_mmcif_device,
  784. &hdmi_device,
  785. &hdmi_lcdc_device,
  786. &camera_device,
  787. &ceu0_device,
  788. &fsi_device,
  789. &fsi_hdmi_device,
  790. &fsi_wm8978_device,
  791. };
  792. static void __init eva_clock_init(void)
  793. {
  794. struct clk *system = clk_get(NULL, "system_clk");
  795. struct clk *xtal1 = clk_get(NULL, "extal1");
  796. struct clk *usb24s = clk_get(NULL, "usb24s");
  797. struct clk *fsibck = clk_get(NULL, "fsibck");
  798. struct clk *fsib = clk_get(&fsi_device.dev, "ickb");
  799. if (IS_ERR(system) ||
  800. IS_ERR(xtal1) ||
  801. IS_ERR(usb24s) ||
  802. IS_ERR(fsibck) ||
  803. IS_ERR(fsib)) {
  804. pr_err("armadillo800eva board clock init failed\n");
  805. goto clock_error;
  806. }
  807. /* armadillo 800 eva extal1 is 24MHz */
  808. clk_set_rate(xtal1, 24000000);
  809. /* usb24s use extal1 (= system) clock (= 24MHz) */
  810. clk_set_parent(usb24s, system);
  811. /* FSIBCK is 12.288MHz, and it is parent of FSI-B */
  812. clk_set_parent(fsib, fsibck);
  813. clk_set_rate(fsibck, 12288000);
  814. clk_set_rate(fsib, 12288000);
  815. clock_error:
  816. if (!IS_ERR(system))
  817. clk_put(system);
  818. if (!IS_ERR(xtal1))
  819. clk_put(xtal1);
  820. if (!IS_ERR(usb24s))
  821. clk_put(usb24s);
  822. if (!IS_ERR(fsibck))
  823. clk_put(fsibck);
  824. if (!IS_ERR(fsib))
  825. clk_put(fsib);
  826. }
  827. /*
  828. * board init
  829. */
  830. #define GPIO_PORT7CR 0xe6050007
  831. #define GPIO_PORT8CR 0xe6050008
  832. static void __init eva_init(void)
  833. {
  834. r8a7740_pinmux_init();
  835. r8a7740_meram_workaround();
  836. /* SCIFA1 */
  837. gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
  838. gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
  839. /* LCDC0 */
  840. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  841. gpio_request(GPIO_FN_LCD0_D0, NULL);
  842. gpio_request(GPIO_FN_LCD0_D1, NULL);
  843. gpio_request(GPIO_FN_LCD0_D2, NULL);
  844. gpio_request(GPIO_FN_LCD0_D3, NULL);
  845. gpio_request(GPIO_FN_LCD0_D4, NULL);
  846. gpio_request(GPIO_FN_LCD0_D5, NULL);
  847. gpio_request(GPIO_FN_LCD0_D6, NULL);
  848. gpio_request(GPIO_FN_LCD0_D7, NULL);
  849. gpio_request(GPIO_FN_LCD0_D8, NULL);
  850. gpio_request(GPIO_FN_LCD0_D9, NULL);
  851. gpio_request(GPIO_FN_LCD0_D10, NULL);
  852. gpio_request(GPIO_FN_LCD0_D11, NULL);
  853. gpio_request(GPIO_FN_LCD0_D12, NULL);
  854. gpio_request(GPIO_FN_LCD0_D13, NULL);
  855. gpio_request(GPIO_FN_LCD0_D14, NULL);
  856. gpio_request(GPIO_FN_LCD0_D15, NULL);
  857. gpio_request(GPIO_FN_LCD0_D16, NULL);
  858. gpio_request(GPIO_FN_LCD0_D17, NULL);
  859. gpio_request(GPIO_FN_LCD0_D18_PORT40, NULL);
  860. gpio_request(GPIO_FN_LCD0_D19_PORT4, NULL);
  861. gpio_request(GPIO_FN_LCD0_D20_PORT3, NULL);
  862. gpio_request(GPIO_FN_LCD0_D21_PORT2, NULL);
  863. gpio_request(GPIO_FN_LCD0_D22_PORT0, NULL);
  864. gpio_request(GPIO_FN_LCD0_D23_PORT1, NULL);
  865. gpio_request(GPIO_FN_LCD0_DCK, NULL);
  866. gpio_request(GPIO_FN_LCD0_VSYN, NULL);
  867. gpio_request(GPIO_FN_LCD0_HSYN, NULL);
  868. gpio_request(GPIO_FN_LCD0_DISP, NULL);
  869. gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
  870. gpio_request(GPIO_PORT61, NULL); /* LCDDON */
  871. gpio_direction_output(GPIO_PORT61, 1);
  872. gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
  873. gpio_direction_output(GPIO_PORT202, 0);
  874. /* Touchscreen */
  875. gpio_request(GPIO_FN_IRQ10, NULL); /* TP_INT */
  876. gpio_request(GPIO_PORT166, NULL); /* TP_RST_B */
  877. gpio_direction_output(GPIO_PORT166, 1);
  878. /* GETHER */
  879. gpio_request(GPIO_FN_ET_CRS, NULL);
  880. gpio_request(GPIO_FN_ET_MDC, NULL);
  881. gpio_request(GPIO_FN_ET_MDIO, NULL);
  882. gpio_request(GPIO_FN_ET_TX_ER, NULL);
  883. gpio_request(GPIO_FN_ET_RX_ER, NULL);
  884. gpio_request(GPIO_FN_ET_ERXD0, NULL);
  885. gpio_request(GPIO_FN_ET_ERXD1, NULL);
  886. gpio_request(GPIO_FN_ET_ERXD2, NULL);
  887. gpio_request(GPIO_FN_ET_ERXD3, NULL);
  888. gpio_request(GPIO_FN_ET_TX_CLK, NULL);
  889. gpio_request(GPIO_FN_ET_TX_EN, NULL);
  890. gpio_request(GPIO_FN_ET_ETXD0, NULL);
  891. gpio_request(GPIO_FN_ET_ETXD1, NULL);
  892. gpio_request(GPIO_FN_ET_ETXD2, NULL);
  893. gpio_request(GPIO_FN_ET_ETXD3, NULL);
  894. gpio_request(GPIO_FN_ET_PHY_INT, NULL);
  895. gpio_request(GPIO_FN_ET_COL, NULL);
  896. gpio_request(GPIO_FN_ET_RX_DV, NULL);
  897. gpio_request(GPIO_FN_ET_RX_CLK, NULL);
  898. gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
  899. gpio_direction_output(GPIO_PORT18, 1);
  900. /* USB */
  901. gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
  902. gpio_direction_input(GPIO_PORT159);
  903. if (gpio_get_value(GPIO_PORT159)) {
  904. /* USB Host */
  905. } else {
  906. /* USB Func */
  907. gpio_request(GPIO_FN_VBUS, NULL);
  908. platform_device_register(&usbhsf_device);
  909. }
  910. /* SDHI0 */
  911. gpio_request(GPIO_FN_SDHI0_CMD, NULL);
  912. gpio_request(GPIO_FN_SDHI0_CLK, NULL);
  913. gpio_request(GPIO_FN_SDHI0_D0, NULL);
  914. gpio_request(GPIO_FN_SDHI0_D1, NULL);
  915. gpio_request(GPIO_FN_SDHI0_D2, NULL);
  916. gpio_request(GPIO_FN_SDHI0_D3, NULL);
  917. gpio_request(GPIO_FN_SDHI0_WP, NULL);
  918. gpio_request(GPIO_PORT17, NULL); /* SDHI0_18/33_B */
  919. gpio_request(GPIO_PORT74, NULL); /* SDHI0_PON */
  920. gpio_request(GPIO_PORT75, NULL); /* SDSLOT1_PON */
  921. gpio_direction_output(GPIO_PORT17, 0);
  922. gpio_direction_output(GPIO_PORT74, 1);
  923. gpio_direction_output(GPIO_PORT75, 1);
  924. /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
  925. /*
  926. * MMCIF
  927. *
  928. * Here doesn't care SW1.4 status,
  929. * since CON2 is not mounted.
  930. */
  931. gpio_request(GPIO_FN_MMC1_CLK_PORT103, NULL);
  932. gpio_request(GPIO_FN_MMC1_CMD_PORT104, NULL);
  933. gpio_request(GPIO_FN_MMC1_D0_PORT149, NULL);
  934. gpio_request(GPIO_FN_MMC1_D1_PORT148, NULL);
  935. gpio_request(GPIO_FN_MMC1_D2_PORT147, NULL);
  936. gpio_request(GPIO_FN_MMC1_D3_PORT146, NULL);
  937. gpio_request(GPIO_FN_MMC1_D4_PORT145, NULL);
  938. gpio_request(GPIO_FN_MMC1_D5_PORT144, NULL);
  939. gpio_request(GPIO_FN_MMC1_D6_PORT143, NULL);
  940. gpio_request(GPIO_FN_MMC1_D7_PORT142, NULL);
  941. /* CEU0 */
  942. gpio_request(GPIO_FN_VIO0_D7, NULL);
  943. gpio_request(GPIO_FN_VIO0_D6, NULL);
  944. gpio_request(GPIO_FN_VIO0_D5, NULL);
  945. gpio_request(GPIO_FN_VIO0_D4, NULL);
  946. gpio_request(GPIO_FN_VIO0_D3, NULL);
  947. gpio_request(GPIO_FN_VIO0_D2, NULL);
  948. gpio_request(GPIO_FN_VIO0_D1, NULL);
  949. gpio_request(GPIO_FN_VIO0_D0, NULL);
  950. gpio_request(GPIO_FN_VIO0_CLK, NULL);
  951. gpio_request(GPIO_FN_VIO0_HD, NULL);
  952. gpio_request(GPIO_FN_VIO0_VD, NULL);
  953. gpio_request(GPIO_FN_VIO0_FIELD, NULL);
  954. gpio_request(GPIO_FN_VIO_CKO, NULL);
  955. /* CON1/CON15 Camera */
  956. gpio_request(GPIO_PORT173, NULL); /* STANDBY */
  957. gpio_request(GPIO_PORT172, NULL); /* RST */
  958. gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
  959. gpio_direction_output(GPIO_PORT173, 0);
  960. gpio_direction_output(GPIO_PORT172, 1);
  961. gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
  962. /* FSI-WM8978 */
  963. gpio_request(GPIO_FN_FSIAIBT, NULL);
  964. gpio_request(GPIO_FN_FSIAILR, NULL);
  965. gpio_request(GPIO_FN_FSIAOMC, NULL);
  966. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  967. gpio_request(GPIO_FN_FSIAISLD_PORT5, NULL);
  968. gpio_request(GPIO_PORT7, NULL);
  969. gpio_request(GPIO_PORT8, NULL);
  970. gpio_direction_none(GPIO_PORT7CR); /* FSIAOBT needs no direction */
  971. gpio_direction_none(GPIO_PORT8CR); /* FSIAOLR needs no direction */
  972. /* FSI-HDMI */
  973. gpio_request(GPIO_FN_FSIBCK, NULL);
  974. /* HDMI */
  975. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  976. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  977. /*
  978. * CAUTION
  979. *
  980. * DBGMD/LCDC0/FSIA MUX
  981. * DBGMD_SELECT_B should be set after setting PFC Function.
  982. */
  983. gpio_request(GPIO_PORT176, NULL);
  984. gpio_direction_output(GPIO_PORT176, 1);
  985. /*
  986. * We can switch CON8/CON14 by SW1.5,
  987. * but it needs after DBGMD_SELECT_B
  988. */
  989. gpio_request(GPIO_PORT6, NULL);
  990. gpio_direction_input(GPIO_PORT6);
  991. if (gpio_get_value(GPIO_PORT6)) {
  992. /* CON14 enable */
  993. } else {
  994. /* CON8 (SDHI1) enable */
  995. gpio_request(GPIO_FN_SDHI1_CLK, NULL);
  996. gpio_request(GPIO_FN_SDHI1_CMD, NULL);
  997. gpio_request(GPIO_FN_SDHI1_D0, NULL);
  998. gpio_request(GPIO_FN_SDHI1_D1, NULL);
  999. gpio_request(GPIO_FN_SDHI1_D2, NULL);
  1000. gpio_request(GPIO_FN_SDHI1_D3, NULL);
  1001. gpio_request(GPIO_FN_SDHI1_CD, NULL);
  1002. gpio_request(GPIO_FN_SDHI1_WP, NULL);
  1003. gpio_request(GPIO_PORT16, NULL); /* SDSLOT2_PON */
  1004. gpio_direction_output(GPIO_PORT16, 1);
  1005. platform_device_register(&sdhi1_device);
  1006. }
  1007. #ifdef CONFIG_CACHE_L2X0
  1008. /* Early BRESP enable, Shared attribute override enable, 32K*8way */
  1009. l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
  1010. #endif
  1011. i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
  1012. r8a7740_add_standard_devices();
  1013. platform_add_devices(eva_devices,
  1014. ARRAY_SIZE(eva_devices));
  1015. eva_clock_init();
  1016. }
  1017. static void __init eva_earlytimer_init(void)
  1018. {
  1019. r8a7740_clock_init(MD_CK0 | MD_CK2);
  1020. shmobile_earlytimer_init();
  1021. }
  1022. static void __init eva_add_early_devices(void)
  1023. {
  1024. r8a7740_add_early_devices();
  1025. /* override timer setup with board-specific code */
  1026. shmobile_timer.init = eva_earlytimer_init;
  1027. }
  1028. static const char *eva_boards_compat_dt[] __initdata = {
  1029. "renesas,armadillo800eva",
  1030. NULL,
  1031. };
  1032. DT_MACHINE_START(ARMADILLO800EVA_DT, "armadillo800eva")
  1033. .map_io = r8a7740_map_io,
  1034. .init_early = eva_add_early_devices,
  1035. .init_irq = r8a7740_init_irq,
  1036. .handle_irq = shmobile_handle_irq_intc,
  1037. .init_machine = eva_init,
  1038. .timer = &shmobile_timer,
  1039. .dt_compat = eva_boards_compat_dt,
  1040. MACHINE_END