board-armadillo800eva.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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 int fsi_hdmi_set_rate(struct device *dev, int rate, int enable)
  676. {
  677. struct clk *fsib;
  678. int ret;
  679. /* it support 48KHz only */
  680. if (48000 != rate)
  681. return -EINVAL;
  682. fsib = clk_get(dev, "ickb");
  683. if (IS_ERR(fsib))
  684. return -EINVAL;
  685. if (enable) {
  686. ret = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  687. clk_enable(fsib);
  688. } else {
  689. ret = 0;
  690. clk_disable(fsib);
  691. }
  692. clk_put(fsib);
  693. return ret;
  694. }
  695. static struct sh_fsi_platform_info fsi_info = {
  696. /* FSI-WM8978 */
  697. .port_a = {
  698. },
  699. /* FSI-HDMI */
  700. .port_b = {
  701. .flags = SH_FSI_FMT_SPDIF |
  702. SH_FSI_ENABLE_STREAM_MODE,
  703. .set_rate = fsi_hdmi_set_rate,
  704. }
  705. };
  706. static struct resource fsi_resources[] = {
  707. [0] = {
  708. .name = "FSI",
  709. .start = 0xfe1f0000,
  710. .end = 0xfe1f8400 - 1,
  711. .flags = IORESOURCE_MEM,
  712. },
  713. [1] = {
  714. .start = evt2irq(0x1840),
  715. .flags = IORESOURCE_IRQ,
  716. },
  717. };
  718. static struct platform_device fsi_device = {
  719. .name = "sh_fsi2",
  720. .id = -1,
  721. .num_resources = ARRAY_SIZE(fsi_resources),
  722. .resource = fsi_resources,
  723. .dev = {
  724. .platform_data = &fsi_info,
  725. },
  726. };
  727. /* FSI-WM8978 */
  728. static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
  729. .fmt = SND_SOC_DAIFMT_I2S,
  730. .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
  731. .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
  732. .sysclk = 12288000,
  733. };
  734. static struct asoc_simple_card_info fsi_wm8978_info = {
  735. .name = "wm8978",
  736. .card = "FSI2A-WM8978",
  737. .cpu_dai = "fsia-dai",
  738. .codec = "wm8978.0-001a",
  739. .platform = "sh_fsi2",
  740. .codec_dai = "wm8978-hifi",
  741. .init = &fsi_wm8978_init_info,
  742. };
  743. static struct platform_device fsi_wm8978_device = {
  744. .name = "asoc-simple-card",
  745. .id = 0,
  746. .dev = {
  747. .platform_data = &fsi_wm8978_info,
  748. },
  749. };
  750. /* FSI-HDMI */
  751. static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
  752. .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
  753. };
  754. static struct asoc_simple_card_info fsi2_hdmi_info = {
  755. .name = "HDMI",
  756. .card = "FSI2B-HDMI",
  757. .cpu_dai = "fsib-dai",
  758. .codec = "sh-mobile-hdmi",
  759. .platform = "sh_fsi2",
  760. .codec_dai = "sh_mobile_hdmi-hifi",
  761. .init = &fsi2_hdmi_init_info,
  762. };
  763. static struct platform_device fsi_hdmi_device = {
  764. .name = "asoc-simple-card",
  765. .id = 1,
  766. .dev = {
  767. .platform_data = &fsi2_hdmi_info,
  768. },
  769. };
  770. /* I2C */
  771. static struct i2c_board_info i2c0_devices[] = {
  772. {
  773. I2C_BOARD_INFO("st1232-ts", 0x55),
  774. .irq = evt2irq(0x0340),
  775. },
  776. {
  777. I2C_BOARD_INFO("wm8978", 0x1a),
  778. },
  779. };
  780. /*
  781. * board devices
  782. */
  783. static struct platform_device *eva_devices[] __initdata = {
  784. &lcdc0_device,
  785. &gpio_keys_device,
  786. &sh_eth_device,
  787. &sdhi0_device,
  788. &sh_mmcif_device,
  789. &hdmi_device,
  790. &hdmi_lcdc_device,
  791. &camera_device,
  792. &ceu0_device,
  793. &fsi_device,
  794. &fsi_hdmi_device,
  795. &fsi_wm8978_device,
  796. };
  797. static void __init eva_clock_init(void)
  798. {
  799. struct clk *system = clk_get(NULL, "system_clk");
  800. struct clk *xtal1 = clk_get(NULL, "extal1");
  801. struct clk *usb24s = clk_get(NULL, "usb24s");
  802. struct clk *fsibck = clk_get(NULL, "fsibck");
  803. struct clk *fsib = clk_get(&fsi_device.dev, "ickb");
  804. if (IS_ERR(system) ||
  805. IS_ERR(xtal1) ||
  806. IS_ERR(usb24s) ||
  807. IS_ERR(fsibck) ||
  808. IS_ERR(fsib)) {
  809. pr_err("armadillo800eva board clock init failed\n");
  810. goto clock_error;
  811. }
  812. /* armadillo 800 eva extal1 is 24MHz */
  813. clk_set_rate(xtal1, 24000000);
  814. /* usb24s use extal1 (= system) clock (= 24MHz) */
  815. clk_set_parent(usb24s, system);
  816. /* FSIBCK is 12.288MHz, and it is parent of FSI-B */
  817. clk_set_parent(fsib, fsibck);
  818. clk_set_rate(fsibck, 12288000);
  819. clk_set_rate(fsib, 12288000);
  820. clock_error:
  821. if (!IS_ERR(system))
  822. clk_put(system);
  823. if (!IS_ERR(xtal1))
  824. clk_put(xtal1);
  825. if (!IS_ERR(usb24s))
  826. clk_put(usb24s);
  827. if (!IS_ERR(fsibck))
  828. clk_put(fsibck);
  829. if (!IS_ERR(fsib))
  830. clk_put(fsib);
  831. }
  832. /*
  833. * board init
  834. */
  835. #define GPIO_PORT7CR 0xe6050007
  836. #define GPIO_PORT8CR 0xe6050008
  837. static void __init eva_init(void)
  838. {
  839. r8a7740_pinmux_init();
  840. r8a7740_meram_workaround();
  841. /* SCIFA1 */
  842. gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
  843. gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
  844. /* LCDC0 */
  845. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  846. gpio_request(GPIO_FN_LCD0_D0, NULL);
  847. gpio_request(GPIO_FN_LCD0_D1, NULL);
  848. gpio_request(GPIO_FN_LCD0_D2, NULL);
  849. gpio_request(GPIO_FN_LCD0_D3, NULL);
  850. gpio_request(GPIO_FN_LCD0_D4, NULL);
  851. gpio_request(GPIO_FN_LCD0_D5, NULL);
  852. gpio_request(GPIO_FN_LCD0_D6, NULL);
  853. gpio_request(GPIO_FN_LCD0_D7, NULL);
  854. gpio_request(GPIO_FN_LCD0_D8, NULL);
  855. gpio_request(GPIO_FN_LCD0_D9, NULL);
  856. gpio_request(GPIO_FN_LCD0_D10, NULL);
  857. gpio_request(GPIO_FN_LCD0_D11, NULL);
  858. gpio_request(GPIO_FN_LCD0_D12, NULL);
  859. gpio_request(GPIO_FN_LCD0_D13, NULL);
  860. gpio_request(GPIO_FN_LCD0_D14, NULL);
  861. gpio_request(GPIO_FN_LCD0_D15, NULL);
  862. gpio_request(GPIO_FN_LCD0_D16, NULL);
  863. gpio_request(GPIO_FN_LCD0_D17, NULL);
  864. gpio_request(GPIO_FN_LCD0_D18_PORT40, NULL);
  865. gpio_request(GPIO_FN_LCD0_D19_PORT4, NULL);
  866. gpio_request(GPIO_FN_LCD0_D20_PORT3, NULL);
  867. gpio_request(GPIO_FN_LCD0_D21_PORT2, NULL);
  868. gpio_request(GPIO_FN_LCD0_D22_PORT0, NULL);
  869. gpio_request(GPIO_FN_LCD0_D23_PORT1, NULL);
  870. gpio_request(GPIO_FN_LCD0_DCK, NULL);
  871. gpio_request(GPIO_FN_LCD0_VSYN, NULL);
  872. gpio_request(GPIO_FN_LCD0_HSYN, NULL);
  873. gpio_request(GPIO_FN_LCD0_DISP, NULL);
  874. gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
  875. gpio_request(GPIO_PORT61, NULL); /* LCDDON */
  876. gpio_direction_output(GPIO_PORT61, 1);
  877. gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
  878. gpio_direction_output(GPIO_PORT202, 0);
  879. /* Touchscreen */
  880. gpio_request(GPIO_FN_IRQ10, NULL); /* TP_INT */
  881. gpio_request(GPIO_PORT166, NULL); /* TP_RST_B */
  882. gpio_direction_output(GPIO_PORT166, 1);
  883. /* GETHER */
  884. gpio_request(GPIO_FN_ET_CRS, NULL);
  885. gpio_request(GPIO_FN_ET_MDC, NULL);
  886. gpio_request(GPIO_FN_ET_MDIO, NULL);
  887. gpio_request(GPIO_FN_ET_TX_ER, NULL);
  888. gpio_request(GPIO_FN_ET_RX_ER, NULL);
  889. gpio_request(GPIO_FN_ET_ERXD0, NULL);
  890. gpio_request(GPIO_FN_ET_ERXD1, NULL);
  891. gpio_request(GPIO_FN_ET_ERXD2, NULL);
  892. gpio_request(GPIO_FN_ET_ERXD3, NULL);
  893. gpio_request(GPIO_FN_ET_TX_CLK, NULL);
  894. gpio_request(GPIO_FN_ET_TX_EN, NULL);
  895. gpio_request(GPIO_FN_ET_ETXD0, NULL);
  896. gpio_request(GPIO_FN_ET_ETXD1, NULL);
  897. gpio_request(GPIO_FN_ET_ETXD2, NULL);
  898. gpio_request(GPIO_FN_ET_ETXD3, NULL);
  899. gpio_request(GPIO_FN_ET_PHY_INT, NULL);
  900. gpio_request(GPIO_FN_ET_COL, NULL);
  901. gpio_request(GPIO_FN_ET_RX_DV, NULL);
  902. gpio_request(GPIO_FN_ET_RX_CLK, NULL);
  903. gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
  904. gpio_direction_output(GPIO_PORT18, 1);
  905. /* USB */
  906. gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
  907. gpio_direction_input(GPIO_PORT159);
  908. if (gpio_get_value(GPIO_PORT159)) {
  909. /* USB Host */
  910. } else {
  911. /* USB Func */
  912. gpio_request(GPIO_FN_VBUS, NULL);
  913. platform_device_register(&usbhsf_device);
  914. }
  915. /* SDHI0 */
  916. gpio_request(GPIO_FN_SDHI0_CMD, NULL);
  917. gpio_request(GPIO_FN_SDHI0_CLK, NULL);
  918. gpio_request(GPIO_FN_SDHI0_D0, NULL);
  919. gpio_request(GPIO_FN_SDHI0_D1, NULL);
  920. gpio_request(GPIO_FN_SDHI0_D2, NULL);
  921. gpio_request(GPIO_FN_SDHI0_D3, NULL);
  922. gpio_request(GPIO_FN_SDHI0_WP, NULL);
  923. gpio_request(GPIO_PORT17, NULL); /* SDHI0_18/33_B */
  924. gpio_request(GPIO_PORT74, NULL); /* SDHI0_PON */
  925. gpio_request(GPIO_PORT75, NULL); /* SDSLOT1_PON */
  926. gpio_direction_output(GPIO_PORT17, 0);
  927. gpio_direction_output(GPIO_PORT74, 1);
  928. gpio_direction_output(GPIO_PORT75, 1);
  929. /* we can use GPIO_FN_IRQ31_PORT167 here for SDHI0 CD irq */
  930. /*
  931. * MMCIF
  932. *
  933. * Here doesn't care SW1.4 status,
  934. * since CON2 is not mounted.
  935. */
  936. gpio_request(GPIO_FN_MMC1_CLK_PORT103, NULL);
  937. gpio_request(GPIO_FN_MMC1_CMD_PORT104, NULL);
  938. gpio_request(GPIO_FN_MMC1_D0_PORT149, NULL);
  939. gpio_request(GPIO_FN_MMC1_D1_PORT148, NULL);
  940. gpio_request(GPIO_FN_MMC1_D2_PORT147, NULL);
  941. gpio_request(GPIO_FN_MMC1_D3_PORT146, NULL);
  942. gpio_request(GPIO_FN_MMC1_D4_PORT145, NULL);
  943. gpio_request(GPIO_FN_MMC1_D5_PORT144, NULL);
  944. gpio_request(GPIO_FN_MMC1_D6_PORT143, NULL);
  945. gpio_request(GPIO_FN_MMC1_D7_PORT142, NULL);
  946. /* CEU0 */
  947. gpio_request(GPIO_FN_VIO0_D7, NULL);
  948. gpio_request(GPIO_FN_VIO0_D6, NULL);
  949. gpio_request(GPIO_FN_VIO0_D5, NULL);
  950. gpio_request(GPIO_FN_VIO0_D4, NULL);
  951. gpio_request(GPIO_FN_VIO0_D3, NULL);
  952. gpio_request(GPIO_FN_VIO0_D2, NULL);
  953. gpio_request(GPIO_FN_VIO0_D1, NULL);
  954. gpio_request(GPIO_FN_VIO0_D0, NULL);
  955. gpio_request(GPIO_FN_VIO0_CLK, NULL);
  956. gpio_request(GPIO_FN_VIO0_HD, NULL);
  957. gpio_request(GPIO_FN_VIO0_VD, NULL);
  958. gpio_request(GPIO_FN_VIO0_FIELD, NULL);
  959. gpio_request(GPIO_FN_VIO_CKO, NULL);
  960. /* CON1/CON15 Camera */
  961. gpio_request(GPIO_PORT173, NULL); /* STANDBY */
  962. gpio_request(GPIO_PORT172, NULL); /* RST */
  963. gpio_request(GPIO_PORT158, NULL); /* CAM_PON */
  964. gpio_direction_output(GPIO_PORT173, 0);
  965. gpio_direction_output(GPIO_PORT172, 1);
  966. gpio_direction_output(GPIO_PORT158, 0); /* see mt9t111_power() */
  967. /* FSI-WM8978 */
  968. gpio_request(GPIO_FN_FSIAIBT, NULL);
  969. gpio_request(GPIO_FN_FSIAILR, NULL);
  970. gpio_request(GPIO_FN_FSIAOMC, NULL);
  971. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  972. gpio_request(GPIO_FN_FSIAISLD_PORT5, NULL);
  973. gpio_request(GPIO_PORT7, NULL);
  974. gpio_request(GPIO_PORT8, NULL);
  975. gpio_no_direction(GPIO_PORT7CR); /* FSIAOBT needs no direction */
  976. gpio_no_direction(GPIO_PORT8CR); /* FSIAOLR needs no direction */
  977. /* FSI-HDMI */
  978. gpio_request(GPIO_FN_FSIBCK, NULL);
  979. /* HDMI */
  980. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  981. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  982. /*
  983. * CAUTION
  984. *
  985. * DBGMD/LCDC0/FSIA MUX
  986. * DBGMD_SELECT_B should be set after setting PFC Function.
  987. */
  988. gpio_request(GPIO_PORT176, NULL);
  989. gpio_direction_output(GPIO_PORT176, 1);
  990. /*
  991. * We can switch CON8/CON14 by SW1.5,
  992. * but it needs after DBGMD_SELECT_B
  993. */
  994. gpio_request(GPIO_PORT6, NULL);
  995. gpio_direction_input(GPIO_PORT6);
  996. if (gpio_get_value(GPIO_PORT6)) {
  997. /* CON14 enable */
  998. } else {
  999. /* CON8 (SDHI1) enable */
  1000. gpio_request(GPIO_FN_SDHI1_CLK, NULL);
  1001. gpio_request(GPIO_FN_SDHI1_CMD, NULL);
  1002. gpio_request(GPIO_FN_SDHI1_D0, NULL);
  1003. gpio_request(GPIO_FN_SDHI1_D1, NULL);
  1004. gpio_request(GPIO_FN_SDHI1_D2, NULL);
  1005. gpio_request(GPIO_FN_SDHI1_D3, NULL);
  1006. gpio_request(GPIO_FN_SDHI1_CD, NULL);
  1007. gpio_request(GPIO_FN_SDHI1_WP, NULL);
  1008. gpio_request(GPIO_PORT16, NULL); /* SDSLOT2_PON */
  1009. gpio_direction_output(GPIO_PORT16, 1);
  1010. platform_device_register(&sdhi1_device);
  1011. }
  1012. #ifdef CONFIG_CACHE_L2X0
  1013. /* Early BRESP enable, Shared attribute override enable, 32K*8way */
  1014. l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
  1015. #endif
  1016. i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
  1017. r8a7740_add_standard_devices();
  1018. platform_add_devices(eva_devices,
  1019. ARRAY_SIZE(eva_devices));
  1020. eva_clock_init();
  1021. }
  1022. static void __init eva_earlytimer_init(void)
  1023. {
  1024. r8a7740_clock_init(MD_CK0 | MD_CK2);
  1025. shmobile_earlytimer_init();
  1026. }
  1027. static void __init eva_add_early_devices(void)
  1028. {
  1029. r8a7740_add_early_devices();
  1030. /* override timer setup with board-specific code */
  1031. shmobile_timer.init = eva_earlytimer_init;
  1032. }
  1033. static const char *eva_boards_compat_dt[] __initdata = {
  1034. "renesas,armadillo800eva",
  1035. NULL,
  1036. };
  1037. DT_MACHINE_START(ARMADILLO800EVA_DT, "armadillo800eva")
  1038. .map_io = r8a7740_map_io,
  1039. .init_early = eva_add_early_devices,
  1040. .init_irq = r8a7740_init_irq,
  1041. .handle_irq = shmobile_handle_irq_intc,
  1042. .init_machine = eva_init,
  1043. .timer = &shmobile_timer,
  1044. .dt_compat = eva_boards_compat_dt,
  1045. MACHINE_END