board-armadillo800eva.c 26 KB

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