analysisOfLiquidLevelData.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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/regulator/fixed.h>
  31. #include <linux/regulator/machine.h>
  32. #include <linux/sh_eth.h>
  33. #include <linux/videodev2.h>
  34. #include <linux/usb/renesas_usbhs.h>
  35. #include <linux/mfd/tmio.h>
  36. #include <linux/mmc/host.h>
  37. #include <linux/mmc/sh_mmcif.h>
  38. #include <linux/mmc/sh_mobile_sdhi.h>
  39. #include <linux/i2c-gpio.h>
  40. #include <mach/common.h>
  41. #include <mach/irqs.h>
  42. #include <mach/r8a7740.h>
  43. #include <media/mt9t112.h>
  44. #include <media/sh_mobile_ceu.h>
  45. #include <media/soc_camera.h>
  46. #include <asm/page.h>
  47. #include <asm/mach-types.h>
  48. #include <asm/mach/arch.h>
  49. #include <asm/mach/map.h>
  50. #include <asm/mach/time.h>
  51. #include <asm/hardware/cache-l2x0.h>
  52. #include <video/sh_mobile_lcdc.h>
  53. #include <video/sh_mobile_hdmi.h>
  54. #include <sound/sh_fsi.h>
  55. #include <sound/simple_card.h>
  56. #include "sh-gpio.h"
  57. /*
  58. * CON1 Camera Module
  59. * CON2 Extension Bus
  60. * CON3 HDMI Output
  61. * CON4 Composite Video Output
  62. * CON5 H-UDI JTAG
  63. * CON6 ARM JTAG
  64. * CON7 SD1
  65. * CON8 SD2
  66. * CON9 RTC BackUp
  67. * CON10 Monaural Mic Input
  68. * CON11 Stereo Headphone Output
  69. * CON12 Audio Line Output(L)
  70. * CON13 Audio Line Output(R)
  71. * CON14 AWL13 Module
  72. * CON15 Extension
  73. * CON16 LCD1
  74. * CON17 LCD2
  75. * CON19 Power Input
  76. * CON20 USB1
  77. * CON21 USB2
  78. * CON22 Serial
  79. * CON23 LAN
  80. * CON24 USB3
  81. * LED1 Camera LED(Yellow)
  82. * LED2 Power LED (Green)
  83. * ED3-LED6 User LED(Yellow)
  84. * LED7 LAN link LED(Green)
  85. * LED8 LAN activity LED(Yellow)
  86. */
  87. /*
  88. * DipSwitch
  89. *
  90. * SW1
  91. *
  92. * -12345678-+---------------+----------------------------
  93. * 1 | boot | hermit
  94. * 0 | boot | OS auto boot
  95. * -12345678-+---------------+----------------------------
  96. * 00 | boot device | eMMC
  97. * 10 | boot device | SDHI0 (CON7)
  98. * 01 | boot device | -
  99. * 11 | boot device | Extension Buss (CS0)
  100. * -12345678-+---------------+----------------------------
  101. * 0 | Extension Bus | D8-D15 disable, eMMC enable
  102. * 1 | Extension Bus | D8-D15 enable, eMMC disable
  103. * -12345678-+---------------+----------------------------
  104. * 0 | SDHI1 | COM8 disable, COM14 enable
  105. * 1 | SDHI1 | COM8 enable, COM14 disable
  106. * -12345678-+---------------+----------------------------
  107. * 0 | USB0 | COM20 enable, COM24 disable
  108. * 1 | USB0 | COM20 disable, COM24 enable
  109. * -12345678-+---------------+----------------------------
  110. * 00 | JTAG | SH-X2
  111. * 10 | JTAG | ARM
  112. * 01 | JTAG | -
  113. * 11 | JTAG | Boundary Scan
  114. *-----------+---------------+----------------------------
  115. */
  116. /*
  117. * FSI-WM8978
  118. *
  119. * this command is required when playback.
  120. *
  121. * # amixer set "Headphone" 50
  122. */
  123. /*
  124. * USB function
  125. *
  126. * When you use USB Function,
  127. * set SW1.6 ON, and connect cable to CN24.
  128. *
  129. * USBF needs workaround on R8A7740 chip.
  130. * These are a little bit complex.
  131. * see
  132. * usbhsf_power_ctrl()
  133. */
  134. #define IRQ7 evt2irq(0x02e0)
  135. #define USBCR1 IOMEM(0xe605810a)
  136. #define USBH 0xC6700000
  137. #define USBH_USBCTR 0x10834
  138. struct usbhsf_private {
  139. struct clk *phy;
  140. struct clk *usb24;
  141. struct clk *pci;
  142. struct clk *func;
  143. struct clk *host;
  144. void __iomem *usbh_base;
  145. struct renesas_usbhs_platform_info info;
  146. };
  147. #define usbhsf_get_priv(pdev) \
  148. container_of(renesas_usbhs_get_info(pdev), \
  149. struct usbhsf_private, info)
  150. static int usbhsf_get_id(struct platform_device *pdev)
  151. {
  152. return USBHS_GADGET;
  153. }
  154. static void usbhsf_power_ctrl(struct platform_device *pdev,
  155. void __iomem *base, int enable)
  156. {
  157. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  158. /*
  159. * Work around for USB Function.
  160. * It needs USB host clock, and settings
  161. */
  162. if (enable) {
  163. /*
  164. * enable all the related usb clocks
  165. * for usb workaround
  166. */
  167. clk_enable(priv->usb24);
  168. clk_enable(priv->pci);
  169. clk_enable(priv->host);
  170. clk_enable(priv->func);
  171. clk_enable(priv->phy);
  172. /*
  173. * set USBCR1
  174. *
  175. * Port1 is driven by USB function,
  176. * Port2 is driven by USB HOST
  177. * One HOST (Port1 or Port2 is HOST)
  178. * USB PLL input clock = 24MHz
  179. */
  180. __raw_writew(0xd750, USBCR1);
  181. mdelay(1);
  182. /*
  183. * start USB Host
  184. */
  185. __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
  186. __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
  187. mdelay(10);
  188. /*
  189. * USB PHY Power ON
  190. */
  191. __raw_writew(0xd770, USBCR1);
  192. __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
  193. } else {
  194. __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
  195. __raw_writew(0xd7c0, USBCR1); /* GPIO */
  196. clk_disable(priv->phy);
  197. clk_disable(priv->func); /* usb work around */
  198. clk_disable(priv->host); /* usb work around */
  199. clk_disable(priv->pci); /* usb work around */
  200. clk_disable(priv->usb24); /* usb work around */
  201. }
  202. }
  203. static int usbhsf_get_vbus(struct platform_device *pdev)
  204. {
  205. return gpio_get_value(GPIO_PORT209);
  206. }
  207. static irqreturn_t usbhsf_interrupt(int irq, void *data)
  208. {
  209. struct platform_device *pdev = data;
  210. renesas_usbhs_call_notify_hotplug(pdev);
  211. return IRQ_HANDLED;
  212. }
  213. static void usbhsf_hardware_exit(struct platform_device *pdev)
  214. {
  215. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  216. if (!IS_ERR(priv->phy))
  217. clk_put(priv->phy);
  218. if (!IS_ERR(priv->usb24))
  219. clk_put(priv->usb24);
  220. if (!IS_ERR(priv->pci))
  221. clk_put(priv->pci);
  222. if (!IS_ERR(priv->host))
  223. clk_put(priv->host);
  224. if (!IS_ERR(priv->func))
  225. clk_put(priv->func);
  226. if (priv->usbh_base)
  227. iounmap(priv->usbh_base);
  228. priv->phy = NULL;
  229. priv->usb24 = NULL;
  230. priv->pci = NULL;
  231. priv->host = NULL;
  232. priv->func = NULL;
  233. priv->usbh_base = NULL;
  234. free_irq(IRQ7, pdev);
  235. }
  236. static int usbhsf_hardware_init(struct platform_device *pdev)
  237. {
  238. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  239. int ret;
  240. priv->phy = clk_get(&pdev->dev, "phy");
  241. priv->usb24 = clk_get(&pdev->dev, "usb24");
  242. priv->pci = clk_get(&pdev->dev, "pci");
  243. priv->func = clk_get(&pdev->dev, "func");
  244. priv->host = clk_get(&pdev->dev, "host");
  245. priv->usbh_base = ioremap_nocache(USBH, 0x20000);
  246. if (IS_ERR(priv->phy) ||
  247. IS_ERR(priv->usb24) ||
  248. IS_ERR(priv->pci) ||
  249. IS_ERR(priv->host) ||
  250. IS_ERR(priv->func) ||
  251. !priv->usbh_base) {
  252. dev_err(&pdev->dev, "USB clock setting failed\n");
  253. usbhsf_hardware_exit(pdev);
  254. return -EIO;
  255. }
  256. ret = request_irq(IRQ7, usbhsf_interrupt, IRQF_TRIGGER_NONE,
  257. dev_name(&pdev->dev), pdev);
  258. if (ret) {
  259. dev_err(&pdev->dev, "request_irq err\n");
  260. return ret;
  261. }
  262. irq_set_irq_type(IRQ7, IRQ_TYPE_EDGE_BOTH);
  263. /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
  264. clk_set_rate(priv->usb24,
  265. clk_get_rate(clk_get_parent(priv->usb24)));
  266. return 0;
  267. }
  268. static struct usbhsf_private usbhsf_private = {
  269. .info = {
  270. .platform_callback = {
  271. .get_id = usbhsf_get_id,
  272. .get_vbus = usbhsf_get_vbus,
  273. .hardware_init = usbhsf_hardware_init,
  274. .hardware_exit = usbhsf_hardware_exit,
  275. .power_ctrl = usbhsf_power_ctrl,
  276. },
  277. .driver_param = {
  278. .buswait_bwait = 5,
  279. .detection_delay = 5,
  280. .d0_rx_id = SHDMA_SLAVE_USBHS_RX,
  281. .d1_tx_id = SHDMA_SLAVE_USBHS_TX,
  282. },
  283. }
  284. };
  285. static struct resource usbhsf_resources[] = {
  286. {
  287. .name = "USBHS",
  288. .start = 0xe6890000,
  289. .end = 0xe6890104 - 1,
  290. .flags = IORESOURCE_MEM,
  291. },
  292. {
  293. .start = evt2irq(0x0A20),
  294. .flags = IORESOURCE_IRQ,
  295. },
  296. };
  297. static struct platform_device usbhsf_device = {
  298. .name = "renesas_usbhs",
  299. .dev = {
  300. .platform_data = &usbhsf_private.info,
  301. },
  302. .id = -1,
  303. .num_resources = ARRAY_SIZE(usbhsf_resources),
  304. .resource = usbhsf_resources,
  305. };
  306. /* Ether */
  307. static struct sh_eth_plat_data sh_eth_platdata = {
  308. .phy = 0x00, /* LAN8710A */
  309. .edmac_endian = EDMAC_LITTLE_ENDIAN,
  310. .register_type = SH_ETH_REG_GIGABIT,
  311. .phy_interface = PHY_INTERFACE_MODE_MII,
  312. };
  313. static struct resource sh_eth_resources[] = {
  314. {
  315. .start = 0xe9a00000,
  316. .end = 0xe9a00800 - 1,
  317. .flags = IORESOURCE_MEM,
  318. }, {
  319. .start = 0xe9a01800,
  320. .end = 0xe9a02000 - 1,
  321. .flags = IORESOURCE_MEM,
  322. }, {
  323. .start = evt2irq(0x0500),
  324. .flags = IORESOURCE_IRQ,
  325. },
  326. };
  327. static struct platform_device sh_eth_device = {
  328. .name = "sh-eth",
  329. .id = -1,
  330. .dev = {
  331. .platform_data = &sh_eth_platdata,
  332. },
  333. .resource = sh_eth_resources,
  334. .num_resources = ARRAY_SIZE(sh_eth_resources),
  335. };
  336. /* LCDC */
  337. static struct fb_videomode lcdc0_mode = {
  338. .name = "AMPIER/AM-800480",
  339. .xres = 800,
  340. .yres = 480,
  341. .left_margin = 88,
  342. .right_margin = 40,
  343. .hsync_len = 128,
  344. .upper_margin = 20,
  345. .lower_margin = 5,
  346. .vsync_len = 5,
  347. .sync = 0,
  348. };
  349. static struct sh_mobile_lcdc_info lcdc0_info = {
  350. .clock_source = LCDC_CLK_BUS,
  351. .ch[0] = {
  352. .chan = LCDC_CHAN_MAINLCD,
  353. .fourcc = V4L2_PIX_FMT_RGB565,
  354. .interface_type = RGB24,
  355. .clock_divider = 5,
  356. .flags = 0,
  357. .lcd_modes = &lcdc0_mode,
  358. .num_modes = 1,
  359. .panel_cfg = {
  360. .width = 111,
  361. .height = 68,
  362. },
  363. },
  364. };
  365. static struct resource lcdc0_resources[] = {
  366. [0] = {
  367. .name = "LCD0",
  368. .start = 0xfe940000,
  369. .end = 0xfe943fff,
  370. .flags = IORESOURCE_MEM,
  371. },
  372. [1] = {
  373. .start = intcs_evt2irq(0x580),
  374. .flags = IORESOURCE_IRQ,
  375. },
  376. };
  377. static struct platform_device lcdc0_device = {
  378. .name = "sh_mobile_lcdc_fb",
  379. .num_resources = ARRAY_SIZE(lcdc0_resources),
  380. .resource = lcdc0_resources,
  381. .id = 0,
  382. .dev = {
  383. .platform_data = &lcdc0_info,
  384. .coherent_dma_mask = ~0,
  385. },
  386. };
  387. /*
  388. * LCDC1/HDMI
  389. */
  390. static struct sh_mobile_hdmi_info hdmi_info = {
  391. .flags = HDMI_OUTPUT_PUSH_PULL |
  392. HDMI_OUTPUT_POLARITY_HI |
  393. HDMI_32BIT_REG |
  394. HDMI_HAS_HTOP1 |
  395. HDMI_SND_SRC_SPDIF,
  396. };
  397. static struct resource hdmi_resources[] = {
  398. [0] = {
  399. .name = "HDMI",
  400. .start = 0xe6be0000,
  401. .end = 0xe6be03ff,
  402. .flags = IORESOURCE_MEM,
  403. },
  404. [1] = {
  405. .start = evt2irq(0x1700),
  406. .flags = IORESOURCE_IRQ,
  407. },
  408. [2] = {
  409. .name = "HDMI emma3pf",
  410. .start = 0xe6be4000,
  411. .end = 0xe6be43ff,
  412. .flags = IORESOURCE_MEM,
  413. },
  414. };
  415. static struct platform_device hdmi_device = {
  416. .name = "sh-mobile-hdmi",
  417. .num_resources = ARRAY_SIZE(hdmi_resources),
  418. .resource = hdmi_resources,
  419. .id = -1,
  420. .dev = {
  421. .platform_data = &hdmi_info,
  422. },
  423. };
  424. static const struct fb_videomode lcdc1_mode = {
  425. .name = "HDMI 720p",
  426. .xres = 1280,
  427. .yres = 720,
  428. .pixclock = 13468,
  429. .left_margin = 220,
  430. .right_margin = 110,
  431. .hsync_len = 40,
  432. .upper_margin = 20,
  433. .lower_margin = 5,
  434. .vsync_len = 5,
  435. .refresh = 60,
  436. .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
  437. };
  438. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  439. .clock_source = LCDC_CLK_PERIPHERAL, /* HDMI clock */
  440. .ch[0] = {
  441. .chan = LCDC_CHAN_MAINLCD,
  442. .fourcc = V4L2_PIX_FMT_RGB565,
  443. .interface_type = RGB24,
  444. .clock_divider = 1,
  445. .flags = LCDC_FLAGS_DWPOL,
  446. .lcd_modes = &lcdc1_mode,
  447. .num_modes = 1,
  448. .tx_dev = &hdmi_device,
  449. .panel_cfg = {
  450. .width = 1280,
  451. .height = 720,
  452. },
  453. },
  454. };
  455. static struct resource hdmi_lcdc_resources[] = {
  456. [0] = {
  457. .name = "LCDC1",
  458. .start = 0xfe944000,
  459. .end = 0xfe948000 - 1,
  460. .flags = IORESOURCE_MEM,
  461. },
  462. [1] = {
  463. .start = intcs_evt2irq(0x1780),
  464. .flags = IORESOURCE_IRQ,
  465. },
  466. };
  467. static struct platform_device hdmi_lcdc_device = {
  468. .name = "sh_mobile_lcdc_fb",
  469. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  470. .resource = hdmi_lcdc_resources,
  471. .id = 1,
  472. .dev = {
  473. .platform_data = &hdmi_lcdc_info,
  474. .coherent_dma_mask = ~0,
  475. },
  476. };
  477. /* GPIO KEY */
  478. #define GPIO_KEY(c, g, d, ...) \
  479. { .code = c, .gpio = g, .desc = d, .active_low = 1, __VA_ARGS__ }
  480. static struct gpio_keys_button gpio_buttons[] = {
  481. GPIO_KEY(KEY_POWER, GPIO_PORT99, "SW3", .wakeup = 1),
  482. GPIO_KEY(KEY_BACK, GPIO_PORT100, "SW4"),
  483. GPIO_KEY(KEY_MENU, GPIO_PORT97, "SW5"),
  484. GPIO_KEY(KEY_HOME, GPIO_PORT98, "SW6"),
  485. };
  486. static struct gpio_keys_platform_data gpio_key_info = {
  487. .buttons = gpio_buttons,
  488. .nbuttons = ARRAY_SIZE(gpio_buttons),
  489. };
  490. static struct platform_device gpio_keys_device = {
  491. .name = "gpio-keys",
  492. .id = -1,
  493. .dev = {
  494. .platform_data = &gpio_key_info,
  495. },
  496. };
  497. /* Fixed 3.3V regulator to be used by SDHI0, SDHI1, MMCIF */
  498. static struct regulator_consumer_supply fixed3v3_power_consumers[] =
  499. {
  500. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  501. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  502. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
  503. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
  504. REGULATOR_SUPPLY("vmmc", "sh_mmcif"),
  505. REGULATOR_SUPPLY("vqmmc", "sh_mmcif"),
  506. };
  507. /* SDHI0 */
  508. /*
  509. * FIXME
  510. *
  511. * It use polling mode here, since
  512. * CD (= Card Detect) pin is not connected to SDHI0_CD.
  513. * We can use IRQ31 as card detect irq,
  514. * but it needs chattering removal operation
  515. */
  516. #define IRQ31 evt2irq(0x33E0)
  517. static struct sh_mobile_sdhi_info sdhi0_info = {
  518. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  519. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  520. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |\
  521. MMC_CAP_NEEDS_POLL,
  522. .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  523. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  524. };
  525. static struct resource sdhi0_resources[] = {
  526. {
  527. .name = "SDHI0",
  528. .start = 0xe6850000,
  529. .end = 0xe6850100 - 1,
  530. .flags = IORESOURCE_MEM,
  531. },
  532. /*
  533. * no SH_MOBILE_SDHI_IRQ_CARD_DETECT here
  534. */
  535. {
  536. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  537. .start = evt2irq(0x0E20),
  538. .flags = IORESOURCE_IRQ,
  539. },
  540. {
  541. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  542. .start = evt2irq(0x0E40),
  543. .flags = IORESOURCE_IRQ,
  544. },
  545. };
  546. static struct platform_device sdhi0_device = {
  547. .name = "sh_mobile_sdhi",
  548. .id = 0,
  549. .dev = {
  550. .platform_data = &sdhi0_info,
  551. },
  552. .num_resources = ARRAY_SIZE(sdhi0_resources),
  553. .resource = sdhi0_resources,
  554. };
  555. /* SDHI1 */
  556. static struct sh_mobile_sdhi_info sdhi1_info = {
  557. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  558. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  559. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  560. .tmio_ocr_mask = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  561. .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
  562. };
  563. static struct resource sdhi1_resources[] = {
  564. [0] = {
  565. .name = "SDHI1",
  566. .start = 0xe6860000,
  567. .end = 0xe6860100 - 1,
  568. .flags = IORESOURCE_MEM,
  569. },
  570. [1] = {
  571. .start = evt2irq(0x0E80),
  572. .flags = IORESOURCE_IRQ,
  573. },
  574. [2] = {
  575. .start = evt2irq(0x0EA0),
  576. .flags = IORESOURCE_IRQ,
  577. },
  578. [3] = {
  579. .start = evt2irq(0x0EC0),
  580. .flags = IORESOURCE_IRQ,
  581. },
  582. };
  583. static struct platform_device sdhi1_device = {
  584. .name = "sh_mobile_sdhi",
  585. .id = 1,
  586. .dev = {
  587. .platform_data = &sdhi1_info,
  588. },
  589. .num_resources = ARRAY_SIZE(sdhi1_resources),
  590. .resource = sdhi1_resources,
  591. };
  592. /* MMCIF */
  593. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  594. .sup_pclk = 0,
  595. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  596. .caps = MMC_CAP_4_BIT_DATA |
  597. MMC_CAP_8_BIT_DATA |
  598. MMC_CAP_NONREMOVABLE,
  599. };
  600. static struct resource sh_mmcif_resources[] = {
  601. [0] = {
  602. .name = "MMCIF",
  603. .start = 0xe6bd0000,
  604. .end = 0xe6bd0100 - 1,
  605. .flags = IORESOURCE_MEM,
  606. },
  607. [1] = {
  608. /* MMC ERR */
  609. .start = evt2irq(0x1AC0),
  610. .flags = IORESOURCE_IRQ,
  611. },
  612. [2] = {
  613. /* MMC NOR */
  614. .start = evt2irq(0x1AE0),
  615. .flags = IORESOURCE_IRQ,
  616. },
  617. };
  618. static struct platform_device sh_mmcif_device = {
  619. .name = "sh_mmcif",
  620. .id = -1,
  621. .dev = {
  622. .platform_data = &sh_mmcif_plat,
  623. },
  624. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  625. .resource = sh_mmcif_resources,
  626. };
  627. /* Camera */
  628. static int mt9t111_power(struct device *dev, int mode)
  629. {
  630. struct clk *mclk = clk_get(NULL, "video1");
  631. if (IS_ERR(mclk)) {
  632. dev_err(dev, "can't get video1 clock\n");
  633. return -EINVAL;
  634. }
  635. if (mode) {
  636. /* video1 (= CON1 camera) expect 24MHz */
  637. clk_set_rate(mclk, clk_round_rate(mclk, 24000000));
  638. clk_enable(mclk);
  639. gpio_direction_output(GPIO_PORT158, 1);
  640. } else {
  641. gpio_direction_output(GPIO_PORT158, 0);
  642. clk_disable(mclk);
  643. }
  644. clk_put(mclk);
  645. return 0;
  646. }
  647. static struct i2c_board_info i2c_camera_mt9t111 = {
  648. I2C_BOARD_INFO("mt9t112", 0x3d),
  649. };
  650. static struct mt9t112_camera_info mt9t111_info = {
  651. .divider = { 16, 0, 0, 7, 0, 10, 14, 7, 7 },
  652. };
  653. static struct soc_camera_link mt9t111_link = {
  654. .i2c_adapter_id = 0,
  655. .bus_id = 0,
  656. .board_info = &i2c_camera_mt9t111,
  657. .power = mt9t111_power,
  658. .priv = &mt9t111_info,
  659. };
  660. static struct platform_device camera_device = {
  661. .name = "soc-camera-pdrv",
  662. .id = 0,
  663. .dev = {
  664. .platform_data = &mt9t111_link,
  665. },
  666. };
  667. /* CEU0 */
  668. static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
  669. .flags = SH_CEU_FLAG_LOWER_8BIT,
  670. };
  671. static struct resource ceu0_resources[] = {
  672. [0] = {
  673. .name = "CEU",
  674. .start = 0xfe910000,
  675. .end = 0xfe91009f,
  676. .flags = IORESOURCE_MEM,
  677. },
  678. [1] = {
  679. .start = intcs_evt2irq(0x0500),
  680. .flags = IORESOURCE_IRQ,
  681. },
  682. [2] = {
  683. /* place holder for contiguous memory */
  684. },
  685. };
  686. static struct platform_device ceu0_device = {
  687. .name = "sh_mobile_ceu",
  688. .id = 0,
  689. .num_resources = ARRAY_SIZE(ceu0_resources),
  690. .resource = ceu0_resources,
  691. .dev = {
  692. .platform_data = &sh_mobile_ceu0_info,
  693. .coherent_dma_mask = 0xffffffff,
  694. },
  695. };
  696. /* FSI */
  697. static struct sh_fsi_platform_info fsi_info = {
  698. /* FSI-WM8978 */
  699. .port_a = {
  700. .tx_id = SHDMA_SLAVE_FSIA_TX,
  701. },
  702. /* FSI-HDMI */
  703. .port_b = {
  704. .flags = SH_FSI_FMT_SPDIF |
  705. SH_FSI_ENABLE_STREAM_MODE |
  706. SH_FSI_CLK_CPG,
  707. .tx_id = SHDMA_SLAVE_FSIB_TX,
  708. }
  709. };
  710. static struct resource fsi_resources[] = {
  711. [0] = {
  712. .name = "FSI",
  713. .start = 0xfe1f0000,
  714. .end = 0xfe1f8400 - 1,
  715. .flags = IORESOURCE_MEM,
  716. },
  717. [1] = {
  718. .start = evt2irq(0x1840),
  719. .flags = IORESOURCE_IRQ,
  720. },
  721. };
  722. static struct platform_device fsi_device = {
  723. .name = "sh_fsi2",
  724. .id = -1,
  725. .num_resources = ARRAY_SIZE(fsi_resources),
  726. .resource = fsi_resources,
  727. .dev = {
  728. .platform_data = &fsi_info,
  729. },
  730. };
  731. /* FSI-WM8978 */
  732. static struct asoc_simple_dai_init_info fsi_wm8978_init_info = {
  733. .fmt = SND_SOC_DAIFMT_I2S,
  734. .codec_daifmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_NB_NF,
  735. .cpu_daifmt = SND_SOC_DAIFMT_CBS_CFS,
  736. .sysclk = 12288000,
  737. };
  738. static struct asoc_simple_card_info fsi_wm8978_info = {
  739. .name = "wm8978",
  740. .card = "FSI2A-WM8978",
  741. .cpu_dai = "fsia-dai",
  742. .codec = "wm8978.0-001a",
  743. .platform = "sh_fsi2",
  744. .codec_dai = "wm8978-hifi",
  745. .init = &fsi_wm8978_init_info,
  746. };
  747. static struct platform_device fsi_wm8978_device = {
  748. .name = "asoc-simple-card",
  749. .id = 0,
  750. .dev = {
  751. .platform_data = &fsi_wm8978_info,
  752. },
  753. };
  754. /* FSI-HDMI */
  755. static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
  756. .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
  757. };
  758. static struct asoc_simple_card_info fsi2_hdmi_info = {
  759. .name = "HDMI",
  760. .card = "FSI2B-HDMI",
  761. .cpu_dai = "fsib-dai",
  762. .codec = "sh-mobile-hdmi",
  763. .platform = "sh_fsi2",
  764. .codec_dai = "sh_mobile_hdmi-hifi",
  765. .init = &fsi2_hdmi_init_info,
  766. };
  767. static struct platform_device fsi_hdmi_device = {
  768. .name = "asoc-simple-card",
  769. .id = 1,
  770. .dev = {
  771. .platform_data = &fsi2_hdmi_info,
  772. },
  773. };
  774. /* RTC: RTC connects i2c-gpio. */
  775. static struct i2c_gpio_platform_data i2c_gpio_data = {
  776. .sda_pin = GPIO_PORT208,
  777. .scl_pin = GPIO_PORT91,
  778. .udelay = 5, /* 100 kHz */
  779. };
  780. static struct platform_device i2c_gpio_device = {
  781. .name = "i2c-gpio",
  782. .id = 2,
  783. .dev = {
  784. .platform_data = &i2c_gpio_data,
  785. },
  786. };
  787. /* I2C */
  788. static struct i2c_board_info i2c0_devices[] = {
  789. {
  790. I2C_BOARD_INFO("st1232-ts", 0x55),
  791. .irq = evt2irq(0x0340),
  792. },
  793. {
  794. I2C_BOARD_INFO("wm8978", 0x1a),
  795. },
  796. };
  797. static struct i2c_board_info i2c2_devices[] = {
  798. {
  799. I2C_BOARD_INFO("s35390a", 0x30),
  800. .type = "s35390a",
  801. },
  802. };
  803. /*
  804. * board devices
  805. */
  806. static struct platform_device *eva_devices[] __initdata = {
  807. &lcdc0_device,
  808. &gpio_keys_device,
  809. &sh_eth_device,
  810. &sdhi0_device,
  811. &sh_mmcif_device,
  812. &hdmi_device,
  813. &hdmi_lcdc_device,
  814. &camera_device,
  815. &ceu0_device,
  816. &fsi_device,
  817. &fsi_wm8978_device,
  818. &fsi_hdmi_device,
  819. &i2c_gpio_device,
  820. };
  821. static void __init eva_clock_init(void)
  822. {
  823. struct clk *system = clk_get(NULL, "system_clk");
  824. struct clk *xtal1 = clk_get(NULL, "extal1");
  825. struct clk *usb24s = clk_get(NULL, "usb24s");
  826. struct clk *fsibck = clk_get(NULL, "fsibck");
  827. if (IS_ERR(system) ||
  828. IS_ERR(xtal1) ||
  829. IS_ERR(usb24s) ||
  830. IS_ERR(fsibck)) {
  831. pr_err("armadillo800eva board clock init failed\n");
  832. goto clock_error;
  833. }
  834. /* armadillo 800 eva extal1 is 24MHz */
  835. clk_set_rate(xtal1, 24000000);
  836. /* usb24s use extal1 (= system) clock (= 24MHz) */
  837. clk_set_parent(usb24s, system);
  838. /* FSIBCK is 12.288MHz, and it is parent of FSI-B */
  839. clk_set_rate(fsibck, 12288000);
  840. clock_error:
  841. if (!IS_ERR(system))
  842. clk_put(system);
  843. if (!IS_ERR(xtal1))
  844. clk_put(xtal1);
  845. if (!IS_ERR(usb24s))
  846. clk_put(usb24s);
  847. if (!IS_ERR(fsibck))
  848. clk_put(fsibck);
  849. }
  850. /*
  851. * board init
  852. */
  853. #define GPIO_PORT7CR IOMEM(0xe6050007)
  854. #define GPIO_PORT8CR IOMEM(0xe6050008)
  855. static void __init eva_init(void)
  856. {
  857. struct platform_device *usb = NULL;
  858. regulator_register_always_on(0, "fixed-3.3V", fixed3v3_power_consumers,
  859. ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
  860. r8a7740_pinmux_init();
  861. r8a7740_meram_workaround();
  862. /* SCIFA1 */
  863. gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
  864. gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
  865. /* LCDC0 */
  866. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  867. gpio_request(GPIO_FN_LCD0_D0, NULL);
  868. gpio_request(GPIO_FN_LCD0_D1, NULL);
  869. gpio_request(GPIO_FN_LCD0_D2, NULL);
  870. gpio_request(GPIO_FN_LCD0_D3, NULL);