board-armadillo800eva.c 24 KB

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