board-armadillo800eva.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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 <mach/common.h>
  34. #include <mach/irqs.h>
  35. #include <asm/page.h>
  36. #include <asm/mach-types.h>
  37. #include <asm/mach/arch.h>
  38. #include <asm/mach/map.h>
  39. #include <asm/mach/time.h>
  40. #include <asm/hardware/cache-l2x0.h>
  41. #include <mach/r8a7740.h>
  42. #include <video/sh_mobile_lcdc.h>
  43. /*
  44. * CON1 Camera Module
  45. * CON2 Extension Bus
  46. * CON3 HDMI Output
  47. * CON4 Composite Video Output
  48. * CON5 H-UDI JTAG
  49. * CON6 ARM JTAG
  50. * CON7 SD1
  51. * CON8 SD2
  52. * CON9 RTC BackUp
  53. * CON10 Monaural Mic Input
  54. * CON11 Stereo Headphone Output
  55. * CON12 Audio Line Output(L)
  56. * CON13 Audio Line Output(R)
  57. * CON14 AWL13 Module
  58. * CON15 Extension
  59. * CON16 LCD1
  60. * CON17 LCD2
  61. * CON19 Power Input
  62. * CON20 USB1
  63. * CON21 USB2
  64. * CON22 Serial
  65. * CON23 LAN
  66. * CON24 USB3
  67. * LED1 Camera LED(Yellow)
  68. * LED2 Power LED (Green)
  69. * ED3-LED6 User LED(Yellow)
  70. * LED7 LAN link LED(Green)
  71. * LED8 LAN activity LED(Yellow)
  72. */
  73. /*
  74. * DipSwitch
  75. *
  76. * SW1
  77. *
  78. * -12345678-+---------------+----------------------------
  79. * 1 | boot | hermit
  80. * 0 | boot | OS auto boot
  81. * -12345678-+---------------+----------------------------
  82. * 00 | boot device | eMMC
  83. * 10 | boot device | SDHI0 (CON7)
  84. * 01 | boot device | -
  85. * 11 | boot device | Extension Buss (CS0)
  86. * -12345678-+---------------+----------------------------
  87. * 0 | Extension Bus | D8-D15 disable, eMMC enable
  88. * 1 | Extension Bus | D8-D15 enable, eMMC disable
  89. * -12345678-+---------------+----------------------------
  90. * 0 | SDHI1 | COM8 enable, COM14 disable
  91. * 1 | SDHI1 | COM8 enable, COM14 disable
  92. * -12345678-+---------------+----------------------------
  93. * 0 | USB0 | COM20 enable, COM24 disable
  94. * 1 | USB0 | COM20 disable, COM24 enable
  95. * -12345678-+---------------+----------------------------
  96. * 00 | JTAG | SH-X2
  97. * 10 | JTAG | ARM
  98. * 01 | JTAG | -
  99. * 11 | JTAG | Boundary Scan
  100. *-----------+---------------+----------------------------
  101. */
  102. /*
  103. * USB function
  104. *
  105. * When you use USB Function,
  106. * set SW1.6 ON, and connect cable to CN24.
  107. *
  108. * USBF needs workaround on R8A7740 chip.
  109. * These are a little bit complex.
  110. * see
  111. * usbhsf_power_ctrl()
  112. *
  113. * CAUTION
  114. *
  115. * It uses autonomy mode for USB hotplug at this point
  116. * (= usbhs_private.platform_callback.get_vbus is NULL),
  117. * since we don't know what's happen on PM control
  118. * on this workaround.
  119. */
  120. #define USBCR1 0xe605810a
  121. #define USBH 0xC6700000
  122. #define USBH_USBCTR 0x10834
  123. struct usbhsf_private {
  124. struct clk *phy;
  125. struct clk *usb24;
  126. struct clk *pci;
  127. struct clk *func;
  128. struct clk *host;
  129. void __iomem *usbh_base;
  130. struct renesas_usbhs_platform_info info;
  131. };
  132. #define usbhsf_get_priv(pdev) \
  133. container_of(renesas_usbhs_get_info(pdev), \
  134. struct usbhsf_private, info)
  135. static int usbhsf_get_id(struct platform_device *pdev)
  136. {
  137. return USBHS_GADGET;
  138. }
  139. static void usbhsf_power_ctrl(struct platform_device *pdev,
  140. void __iomem *base, int enable)
  141. {
  142. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  143. /*
  144. * Work around for USB Function.
  145. * It needs USB host clock, and settings
  146. */
  147. if (enable) {
  148. /*
  149. * enable all the related usb clocks
  150. * for usb workaround
  151. */
  152. clk_enable(priv->usb24);
  153. clk_enable(priv->pci);
  154. clk_enable(priv->host);
  155. clk_enable(priv->func);
  156. clk_enable(priv->phy);
  157. /*
  158. * set USBCR1
  159. *
  160. * Port1 is driven by USB function,
  161. * Port2 is driven by USB HOST
  162. * One HOST (Port1 or Port2 is HOST)
  163. * USB PLL input clock = 24MHz
  164. */
  165. __raw_writew(0xd750, USBCR1);
  166. mdelay(1);
  167. /*
  168. * start USB Host
  169. */
  170. __raw_writel(0x0000000c, priv->usbh_base + USBH_USBCTR);
  171. __raw_writel(0x00000008, priv->usbh_base + USBH_USBCTR);
  172. mdelay(10);
  173. /*
  174. * USB PHY Power ON
  175. */
  176. __raw_writew(0xd770, USBCR1);
  177. __raw_writew(0x4000, base + 0x102); /* USBF :: SUSPMODE */
  178. } else {
  179. __raw_writel(0x0000010f, priv->usbh_base + USBH_USBCTR);
  180. __raw_writew(0xd7c0, USBCR1); /* GPIO */
  181. clk_disable(priv->phy);
  182. clk_disable(priv->func); /* usb work around */
  183. clk_disable(priv->host); /* usb work around */
  184. clk_disable(priv->pci); /* usb work around */
  185. clk_disable(priv->usb24); /* usb work around */
  186. }
  187. }
  188. static void usbhsf_hardware_exit(struct platform_device *pdev)
  189. {
  190. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  191. if (!IS_ERR(priv->phy))
  192. clk_put(priv->phy);
  193. if (!IS_ERR(priv->usb24))
  194. clk_put(priv->usb24);
  195. if (!IS_ERR(priv->pci))
  196. clk_put(priv->pci);
  197. if (!IS_ERR(priv->host))
  198. clk_put(priv->host);
  199. if (!IS_ERR(priv->func))
  200. clk_put(priv->func);
  201. if (priv->usbh_base)
  202. iounmap(priv->usbh_base);
  203. priv->phy = NULL;
  204. priv->usb24 = NULL;
  205. priv->pci = NULL;
  206. priv->host = NULL;
  207. priv->func = NULL;
  208. priv->usbh_base = NULL;
  209. }
  210. static int usbhsf_hardware_init(struct platform_device *pdev)
  211. {
  212. struct usbhsf_private *priv = usbhsf_get_priv(pdev);
  213. priv->phy = clk_get(&pdev->dev, "phy");
  214. priv->usb24 = clk_get(&pdev->dev, "usb24");
  215. priv->pci = clk_get(&pdev->dev, "pci");
  216. priv->func = clk_get(&pdev->dev, "func");
  217. priv->host = clk_get(&pdev->dev, "host");
  218. priv->usbh_base = ioremap_nocache(USBH, 0x20000);
  219. if (IS_ERR(priv->phy) ||
  220. IS_ERR(priv->usb24) ||
  221. IS_ERR(priv->pci) ||
  222. IS_ERR(priv->host) ||
  223. IS_ERR(priv->func) ||
  224. !priv->usbh_base) {
  225. dev_err(&pdev->dev, "USB clock setting failed\n");
  226. usbhsf_hardware_exit(pdev);
  227. return -EIO;
  228. }
  229. /* usb24 use 1/1 of parent clock (= usb24s = 24MHz) */
  230. clk_set_rate(priv->usb24,
  231. clk_get_rate(clk_get_parent(priv->usb24)));
  232. return 0;
  233. }
  234. static struct usbhsf_private usbhsf_private = {
  235. .info = {
  236. .platform_callback = {
  237. .get_id = usbhsf_get_id,
  238. .hardware_init = usbhsf_hardware_init,
  239. .hardware_exit = usbhsf_hardware_exit,
  240. .power_ctrl = usbhsf_power_ctrl,
  241. },
  242. .driver_param = {
  243. .buswait_bwait = 5,
  244. .detection_delay = 5,
  245. },
  246. }
  247. };
  248. static struct resource usbhsf_resources[] = {
  249. {
  250. .name = "USBHS",
  251. .start = 0xe6890000,
  252. .end = 0xe6890104 - 1,
  253. .flags = IORESOURCE_MEM,
  254. },
  255. {
  256. .start = evt2irq(0x0A20),
  257. .flags = IORESOURCE_IRQ,
  258. },
  259. };
  260. static struct platform_device usbhsf_device = {
  261. .name = "renesas_usbhs",
  262. .dev = {
  263. .platform_data = &usbhsf_private.info,
  264. },
  265. .id = -1,
  266. .num_resources = ARRAY_SIZE(usbhsf_resources),
  267. .resource = usbhsf_resources,
  268. };
  269. /* Ether */
  270. static struct sh_eth_plat_data sh_eth_platdata = {
  271. .phy = 0x00, /* LAN8710A */
  272. .edmac_endian = EDMAC_LITTLE_ENDIAN,
  273. .register_type = SH_ETH_REG_GIGABIT,
  274. .phy_interface = PHY_INTERFACE_MODE_MII,
  275. };
  276. static struct resource sh_eth_resources[] = {
  277. {
  278. .start = 0xe9a00000,
  279. .end = 0xe9a00800 - 1,
  280. .flags = IORESOURCE_MEM,
  281. }, {
  282. .start = 0xe9a01800,
  283. .end = 0xe9a02000 - 1,
  284. .flags = IORESOURCE_MEM,
  285. }, {
  286. .start = evt2irq(0x0500),
  287. .flags = IORESOURCE_IRQ,
  288. },
  289. };
  290. static struct platform_device sh_eth_device = {
  291. .name = "sh-eth",
  292. .dev = {
  293. .platform_data = &sh_eth_platdata,
  294. },
  295. .resource = sh_eth_resources,
  296. .num_resources = ARRAY_SIZE(sh_eth_resources),
  297. };
  298. /* LCDC */
  299. static struct fb_videomode lcdc0_mode = {
  300. .name = "AMPIER/AM-800480",
  301. .xres = 800,
  302. .yres = 480,
  303. .left_margin = 88,
  304. .right_margin = 40,
  305. .hsync_len = 128,
  306. .upper_margin = 20,
  307. .lower_margin = 5,
  308. .vsync_len = 5,
  309. .sync = 0,
  310. };
  311. static struct sh_mobile_lcdc_info lcdc0_info = {
  312. .clock_source = LCDC_CLK_BUS,
  313. .ch[0] = {
  314. .chan = LCDC_CHAN_MAINLCD,
  315. .fourcc = V4L2_PIX_FMT_RGB565,
  316. .interface_type = RGB24,
  317. .clock_divider = 5,
  318. .flags = 0,
  319. .lcd_modes = &lcdc0_mode,
  320. .num_modes = 1,
  321. .panel_cfg = {
  322. .width = 111,
  323. .height = 68,
  324. },
  325. },
  326. };
  327. static struct resource lcdc0_resources[] = {
  328. [0] = {
  329. .name = "LCD0",
  330. .start = 0xfe940000,
  331. .end = 0xfe943fff,
  332. .flags = IORESOURCE_MEM,
  333. },
  334. [1] = {
  335. .start = intcs_evt2irq(0x580),
  336. .flags = IORESOURCE_IRQ,
  337. },
  338. };
  339. static struct platform_device lcdc0_device = {
  340. .name = "sh_mobile_lcdc_fb",
  341. .num_resources = ARRAY_SIZE(lcdc0_resources),
  342. .resource = lcdc0_resources,
  343. .id = 0,
  344. .dev = {
  345. .platform_data = &lcdc0_info,
  346. .coherent_dma_mask = ~0,
  347. },
  348. };
  349. /* GPIO KEY */
  350. #define GPIO_KEY(c, g, d) { .code = c, .gpio = g, .desc = d, .active_low = 1 }
  351. static struct gpio_keys_button gpio_buttons[] = {
  352. GPIO_KEY(KEY_POWER, GPIO_PORT99, "SW1"),
  353. GPIO_KEY(KEY_BACK, GPIO_PORT100, "SW2"),
  354. GPIO_KEY(KEY_MENU, GPIO_PORT97, "SW3"),
  355. GPIO_KEY(KEY_HOME, GPIO_PORT98, "SW4"),
  356. };
  357. static struct gpio_keys_platform_data gpio_key_info = {
  358. .buttons = gpio_buttons,
  359. .nbuttons = ARRAY_SIZE(gpio_buttons),
  360. };
  361. static struct platform_device gpio_keys_device = {
  362. .name = "gpio-keys",
  363. .id = -1,
  364. .dev = {
  365. .platform_data = &gpio_key_info,
  366. },
  367. };
  368. /* I2C */
  369. static struct i2c_board_info i2c0_devices[] = {
  370. {
  371. I2C_BOARD_INFO("st1232-ts", 0x55),
  372. .irq = evt2irq(0x0340),
  373. },
  374. };
  375. /*
  376. * board devices
  377. */
  378. static struct platform_device *eva_devices[] __initdata = {
  379. &lcdc0_device,
  380. &gpio_keys_device,
  381. &sh_eth_device,
  382. };
  383. static void __init eva_clock_init(void)
  384. {
  385. struct clk *system = clk_get(NULL, "system_clk");
  386. struct clk *xtal1 = clk_get(NULL, "extal1");
  387. struct clk *usb24s = clk_get(NULL, "usb24s");
  388. if (IS_ERR(system) ||
  389. IS_ERR(xtal1) ||
  390. IS_ERR(usb24s)) {
  391. pr_err("armadillo800eva board clock init failed\n");
  392. goto clock_error;
  393. }
  394. /* armadillo 800 eva extal1 is 24MHz */
  395. clk_set_rate(xtal1, 24000000);
  396. /* usb24s use extal1 (= system) clock (= 24MHz) */
  397. clk_set_parent(usb24s, system);
  398. clock_error:
  399. if (!IS_ERR(system))
  400. clk_put(system);
  401. if (!IS_ERR(xtal1))
  402. clk_put(xtal1);
  403. if (!IS_ERR(usb24s))
  404. clk_put(usb24s);
  405. }
  406. /*
  407. * board init
  408. */
  409. static void __init eva_init(void)
  410. {
  411. eva_clock_init();
  412. r8a7740_pinmux_init();
  413. /* SCIFA1 */
  414. gpio_request(GPIO_FN_SCIFA1_RXD, NULL);
  415. gpio_request(GPIO_FN_SCIFA1_TXD, NULL);
  416. /* LCDC0 */
  417. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  418. gpio_request(GPIO_FN_LCD0_D0, NULL);
  419. gpio_request(GPIO_FN_LCD0_D1, NULL);
  420. gpio_request(GPIO_FN_LCD0_D2, NULL);
  421. gpio_request(GPIO_FN_LCD0_D3, NULL);
  422. gpio_request(GPIO_FN_LCD0_D4, NULL);
  423. gpio_request(GPIO_FN_LCD0_D5, NULL);
  424. gpio_request(GPIO_FN_LCD0_D6, NULL);
  425. gpio_request(GPIO_FN_LCD0_D7, NULL);
  426. gpio_request(GPIO_FN_LCD0_D8, NULL);
  427. gpio_request(GPIO_FN_LCD0_D9, NULL);
  428. gpio_request(GPIO_FN_LCD0_D10, NULL);
  429. gpio_request(GPIO_FN_LCD0_D11, NULL);
  430. gpio_request(GPIO_FN_LCD0_D12, NULL);
  431. gpio_request(GPIO_FN_LCD0_D13, NULL);
  432. gpio_request(GPIO_FN_LCD0_D14, NULL);
  433. gpio_request(GPIO_FN_LCD0_D15, NULL);
  434. gpio_request(GPIO_FN_LCD0_D16, NULL);
  435. gpio_request(GPIO_FN_LCD0_D17, NULL);
  436. gpio_request(GPIO_FN_LCD0_D18_PORT40, NULL);
  437. gpio_request(GPIO_FN_LCD0_D19_PORT4, NULL);
  438. gpio_request(GPIO_FN_LCD0_D20_PORT3, NULL);
  439. gpio_request(GPIO_FN_LCD0_D21_PORT2, NULL);
  440. gpio_request(GPIO_FN_LCD0_D22_PORT0, NULL);
  441. gpio_request(GPIO_FN_LCD0_D23_PORT1, NULL);
  442. gpio_request(GPIO_FN_LCD0_DCK, NULL);
  443. gpio_request(GPIO_FN_LCD0_VSYN, NULL);
  444. gpio_request(GPIO_FN_LCD0_HSYN, NULL);
  445. gpio_request(GPIO_FN_LCD0_DISP, NULL);
  446. gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
  447. gpio_request(GPIO_PORT61, NULL); /* LCDDON */
  448. gpio_direction_output(GPIO_PORT61, 1);
  449. gpio_request(GPIO_PORT202, NULL); /* LCD0_LED_CONT */
  450. gpio_direction_output(GPIO_PORT202, 0);
  451. /* Touchscreen */
  452. gpio_request(GPIO_FN_IRQ10, NULL); /* TP_INT */
  453. gpio_request(GPIO_PORT166, NULL); /* TP_RST_B */
  454. gpio_direction_output(GPIO_PORT166, 1);
  455. /* GETHER */
  456. gpio_request(GPIO_FN_ET_CRS, NULL);
  457. gpio_request(GPIO_FN_ET_MDC, NULL);
  458. gpio_request(GPIO_FN_ET_MDIO, NULL);
  459. gpio_request(GPIO_FN_ET_TX_ER, NULL);
  460. gpio_request(GPIO_FN_ET_RX_ER, NULL);
  461. gpio_request(GPIO_FN_ET_ERXD0, NULL);
  462. gpio_request(GPIO_FN_ET_ERXD1, NULL);
  463. gpio_request(GPIO_FN_ET_ERXD2, NULL);
  464. gpio_request(GPIO_FN_ET_ERXD3, NULL);
  465. gpio_request(GPIO_FN_ET_TX_CLK, NULL);
  466. gpio_request(GPIO_FN_ET_TX_EN, NULL);
  467. gpio_request(GPIO_FN_ET_ETXD0, NULL);
  468. gpio_request(GPIO_FN_ET_ETXD1, NULL);
  469. gpio_request(GPIO_FN_ET_ETXD2, NULL);
  470. gpio_request(GPIO_FN_ET_ETXD3, NULL);
  471. gpio_request(GPIO_FN_ET_PHY_INT, NULL);
  472. gpio_request(GPIO_FN_ET_COL, NULL);
  473. gpio_request(GPIO_FN_ET_RX_DV, NULL);
  474. gpio_request(GPIO_FN_ET_RX_CLK, NULL);
  475. gpio_request(GPIO_PORT18, NULL); /* PHY_RST */
  476. gpio_direction_output(GPIO_PORT18, 1);
  477. /* USB */
  478. gpio_request(GPIO_PORT159, NULL); /* USB_DEVICE_MODE */
  479. gpio_direction_input(GPIO_PORT159);
  480. if (gpio_get_value(GPIO_PORT159)) {
  481. /* USB Host */
  482. } else {
  483. /* USB Func */
  484. gpio_request(GPIO_FN_VBUS, NULL);
  485. platform_device_register(&usbhsf_device);
  486. }
  487. /*
  488. * CAUTION
  489. *
  490. * DBGMD/LCDC0/FSIA MUX
  491. * DBGMD_SELECT_B should be set after setting PFC Function.
  492. */
  493. gpio_request(GPIO_PORT176, NULL);
  494. gpio_direction_output(GPIO_PORT176, 1);
  495. #ifdef CONFIG_CACHE_L2X0
  496. /* Early BRESP enable, Shared attribute override enable, 32K*8way */
  497. l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
  498. #endif
  499. i2c_register_board_info(0, i2c0_devices, ARRAY_SIZE(i2c0_devices));
  500. r8a7740_add_standard_devices();
  501. platform_add_devices(eva_devices,
  502. ARRAY_SIZE(eva_devices));
  503. }
  504. static void __init eva_earlytimer_init(void)
  505. {
  506. r8a7740_clock_init(MD_CK0 | MD_CK2);
  507. shmobile_earlytimer_init();
  508. }
  509. static void __init eva_add_early_devices(void)
  510. {
  511. r8a7740_add_early_devices();
  512. /* override timer setup with board-specific code */
  513. shmobile_timer.init = eva_earlytimer_init;
  514. }
  515. MACHINE_START(ARMADILLO800EVA, "armadillo800eva")
  516. .map_io = r8a7740_map_io,
  517. .init_early = eva_add_early_devices,
  518. .init_irq = r8a7740_init_irq,
  519. .handle_irq = shmobile_handle_irq_intc,
  520. .init_machine = eva_init,
  521. .timer = &shmobile_timer,
  522. MACHINE_END