ehci-fsl.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2005-2009 MontaVista Software, Inc.
  4. * Copyright 2008,2012,2015 Freescale Semiconductor, Inc.
  5. *
  6. * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided
  7. * by Hunter Wu.
  8. * Power Management support by Dave Liu <daveliu@freescale.com>,
  9. * Jerry Huang <Chang-Ming.Huang@freescale.com> and
  10. * Anton Vorontsov <avorontsov@ru.mvista.com>.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/delay.h>
  16. #include <linux/pm.h>
  17. #include <linux/err.h>
  18. #include <linux/usb.h>
  19. #include <linux/usb/ehci_def.h>
  20. #include <linux/usb/hcd.h>
  21. #include <linux/usb/otg.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/fsl_devices.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/io.h>
  26. #include "ehci.h"
  27. #include "ehci-fsl.h"
  28. #define DRIVER_DESC "Freescale EHCI Host controller driver"
  29. #define DRV_NAME "ehci-fsl"
  30. static struct hc_driver __read_mostly fsl_ehci_hc_driver;
  31. /* configure so an HC device and id are always provided */
  32. /* always called with process context; sleeping is OK */
  33. /*
  34. * fsl_ehci_drv_probe - initialize FSL-based HCDs
  35. * @pdev: USB Host Controller being probed
  36. * Context: !in_interrupt()
  37. *
  38. * Allocates basic resources for this USB host controller.
  39. *
  40. */
  41. static int fsl_ehci_drv_probe(struct platform_device *pdev)
  42. {
  43. struct fsl_usb2_platform_data *pdata;
  44. struct usb_hcd *hcd;
  45. struct resource *res;
  46. int irq;
  47. int retval;
  48. u32 tmp;
  49. pr_debug("initializing FSL-SOC USB Controller\n");
  50. /* Need platform data for setup */
  51. pdata = dev_get_platdata(&pdev->dev);
  52. if (!pdata) {
  53. dev_err(&pdev->dev,
  54. "No platform data for %s.\n", dev_name(&pdev->dev));
  55. return -ENODEV;
  56. }
  57. /*
  58. * This is a host mode driver, verify that we're supposed to be
  59. * in host mode.
  60. */
  61. if (!((pdata->operating_mode == FSL_USB2_DR_HOST) ||
  62. (pdata->operating_mode == FSL_USB2_MPH_HOST) ||
  63. (pdata->operating_mode == FSL_USB2_DR_OTG))) {
  64. dev_err(&pdev->dev,
  65. "Non Host Mode configured for %s. Wrong driver linked.\n",
  66. dev_name(&pdev->dev));
  67. return -ENODEV;
  68. }
  69. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  70. if (!res) {
  71. dev_err(&pdev->dev,
  72. "Found HC with no IRQ. Check %s setup!\n",
  73. dev_name(&pdev->dev));
  74. return -ENODEV;
  75. }
  76. irq = res->start;
  77. hcd = __usb_create_hcd(&fsl_ehci_hc_driver, pdev->dev.parent,
  78. &pdev->dev, dev_name(&pdev->dev), NULL);
  79. if (!hcd) {
  80. retval = -ENOMEM;
  81. goto err1;
  82. }
  83. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  84. hcd->regs = devm_ioremap_resource(&pdev->dev, res);
  85. if (IS_ERR(hcd->regs)) {
  86. retval = PTR_ERR(hcd->regs);
  87. goto err2;
  88. }
  89. hcd->rsrc_start = res->start;
  90. hcd->rsrc_len = resource_size(res);
  91. pdata->regs = hcd->regs;
  92. if (pdata->power_budget)
  93. hcd->power_budget = pdata->power_budget;
  94. /*
  95. * do platform specific init: check the clock, grab/config pins, etc.
  96. */
  97. if (pdata->init && pdata->init(pdev)) {
  98. retval = -ENODEV;
  99. goto err2;
  100. }
  101. /* Enable USB controller, 83xx or 8536 */
  102. if (pdata->have_sysif_regs && pdata->controller_ver < FSL_USB_VER_1_6) {
  103. tmp = ioread32be(hcd->regs + FSL_SOC_USB_CTRL);
  104. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  105. tmp |= 0x4;
  106. iowrite32be(tmp, hcd->regs + FSL_SOC_USB_CTRL);
  107. }
  108. /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */
  109. if (pdata->controller_ver == FSL_USB_VER_2_5 &&
  110. pdata->phy_mode == FSL_USB2_PHY_ULPI)
  111. iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL);
  112. /*
  113. * Enable UTMI phy and program PTS field in UTMI mode before asserting
  114. * controller reset for USB Controller version 2.5
  115. */
  116. if (pdata->has_fsl_erratum_a007792) {
  117. tmp = ioread32be(hcd->regs + FSL_SOC_USB_CTRL);
  118. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  119. tmp |= CTRL_UTMI_PHY_EN;
  120. iowrite32be(tmp, hcd->regs + FSL_SOC_USB_CTRL);
  121. writel(PORT_PTS_UTMI, hcd->regs + FSL_SOC_USB_PORTSC1);
  122. }
  123. /* Don't need to set host mode here. It will be done by tdi_reset() */
  124. retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
  125. if (retval != 0)
  126. goto err2;
  127. device_wakeup_enable(hcd->self.controller);
  128. #ifdef CONFIG_USB_OTG
  129. if (pdata->operating_mode == FSL_USB2_DR_OTG) {
  130. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  131. hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
  132. dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
  133. hcd, ehci, hcd->usb_phy);
  134. if (!IS_ERR_OR_NULL(hcd->usb_phy)) {
  135. retval = otg_set_host(hcd->usb_phy->otg,
  136. &ehci_to_hcd(ehci)->self);
  137. if (retval) {
  138. usb_put_phy(hcd->usb_phy);
  139. goto err2;
  140. }
  141. } else {
  142. dev_err(&pdev->dev, "can't find phy\n");
  143. retval = -ENODEV;
  144. goto err2;
  145. }
  146. hcd->skip_phy_initialization = 1;
  147. }
  148. #endif
  149. return retval;
  150. err2:
  151. usb_put_hcd(hcd);
  152. err1:
  153. dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
  154. if (pdata->exit)
  155. pdata->exit(pdev);
  156. return retval;
  157. }
  158. static bool usb_phy_clk_valid(struct usb_hcd *hcd)
  159. {
  160. void __iomem *non_ehci = hcd->regs;
  161. bool ret = true;
  162. if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID))
  163. ret = false;
  164. return ret;
  165. }
  166. static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
  167. enum fsl_usb2_phy_modes phy_mode,
  168. unsigned int port_offset)
  169. {
  170. u32 portsc, tmp;
  171. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  172. void __iomem *non_ehci = hcd->regs;
  173. struct device *dev = hcd->self.controller;
  174. struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
  175. if (pdata->controller_ver < 0) {
  176. dev_warn(hcd->self.controller, "Could not get controller version\n");
  177. return -ENODEV;
  178. }
  179. portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
  180. portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
  181. switch (phy_mode) {
  182. case FSL_USB2_PHY_ULPI:
  183. if (pdata->have_sysif_regs && pdata->controller_ver) {
  184. /* controller version 1.6 or above */
  185. /* turn off UTMI PHY first */
  186. tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  187. tmp &= ~(CONTROL_REGISTER_W1C_MASK | UTMI_PHY_EN);
  188. iowrite32be(tmp, non_ehci + FSL_SOC_USB_CTRL);
  189. /* then turn on ULPI and enable USB controller */
  190. tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  191. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  192. tmp |= ULPI_PHY_CLK_SEL | USB_CTRL_USB_EN;
  193. iowrite32be(tmp, non_ehci + FSL_SOC_USB_CTRL);
  194. }
  195. portsc |= PORT_PTS_ULPI;
  196. break;
  197. case FSL_USB2_PHY_SERIAL:
  198. portsc |= PORT_PTS_SERIAL;
  199. break;
  200. case FSL_USB2_PHY_UTMI_WIDE:
  201. portsc |= PORT_PTS_PTW;
  202. /* fall through */
  203. case FSL_USB2_PHY_UTMI:
  204. /* Presence of this node "has_fsl_erratum_a006918"
  205. * in device-tree is used to stop USB controller
  206. * initialization in Linux
  207. */
  208. if (pdata->has_fsl_erratum_a006918) {
  209. dev_warn(dev, "USB PHY clock invalid\n");
  210. return -EINVAL;
  211. }
  212. /* fall through */
  213. case FSL_USB2_PHY_UTMI_DUAL:
  214. /* PHY_CLK_VALID bit is de-featured from all controller
  215. * versions below 2.4 and is to be checked only for
  216. * internal UTMI phy
  217. */
  218. if (pdata->controller_ver > FSL_USB_VER_2_4 &&
  219. pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) {
  220. dev_err(dev, "USB PHY clock invalid\n");
  221. return -EINVAL;
  222. }
  223. if (pdata->have_sysif_regs && pdata->controller_ver) {
  224. /* controller version 1.6 or above */
  225. tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  226. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  227. tmp |= UTMI_PHY_EN;
  228. iowrite32be(tmp, non_ehci + FSL_SOC_USB_CTRL);
  229. mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI PHY CLK to
  230. become stable - 10ms*/
  231. }
  232. /* enable UTMI PHY */
  233. if (pdata->have_sysif_regs) {
  234. tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  235. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  236. tmp |= CTRL_UTMI_PHY_EN;
  237. iowrite32be(tmp, non_ehci + FSL_SOC_USB_CTRL);
  238. }
  239. portsc |= PORT_PTS_UTMI;
  240. break;
  241. case FSL_USB2_PHY_NONE:
  242. break;
  243. }
  244. if (pdata->have_sysif_regs &&
  245. pdata->controller_ver > FSL_USB_VER_1_6 &&
  246. !usb_phy_clk_valid(hcd)) {
  247. dev_warn(hcd->self.controller, "USB PHY clock invalid\n");
  248. return -EINVAL;
  249. }
  250. ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
  251. if (phy_mode != FSL_USB2_PHY_ULPI && pdata->have_sysif_regs) {
  252. tmp = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  253. tmp &= ~CONTROL_REGISTER_W1C_MASK;
  254. tmp |= USB_CTRL_USB_EN;
  255. iowrite32be(tmp, non_ehci + FSL_SOC_USB_CTRL);
  256. }
  257. return 0;
  258. }
  259. static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
  260. {
  261. struct usb_hcd *hcd = ehci_to_hcd(ehci);
  262. struct fsl_usb2_platform_data *pdata;
  263. void __iomem *non_ehci = hcd->regs;
  264. pdata = dev_get_platdata(hcd->self.controller);
  265. if (pdata->have_sysif_regs) {
  266. /*
  267. * Turn on cache snooping hardware, since some PowerPC platforms
  268. * wholly rely on hardware to deal with cache coherent
  269. */
  270. /* Setup Snooping for all the 4GB space */
  271. /* SNOOP1 starts from 0x0, size 2G */
  272. iowrite32be(0x0 | SNOOP_SIZE_2GB,
  273. non_ehci + FSL_SOC_USB_SNOOP1);
  274. /* SNOOP2 starts from 0x80000000, size 2G */
  275. iowrite32be(0x80000000 | SNOOP_SIZE_2GB,
  276. non_ehci + FSL_SOC_USB_SNOOP2);
  277. }
  278. /* Deal with USB erratum A-005275 */
  279. if (pdata->has_fsl_erratum_a005275 == 1)
  280. ehci->has_fsl_hs_errata = 1;
  281. if (pdata->has_fsl_erratum_a005697 == 1)
  282. ehci->has_fsl_susp_errata = 1;
  283. if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
  284. (pdata->operating_mode == FSL_USB2_DR_OTG))
  285. if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
  286. return -EINVAL;
  287. if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
  288. /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
  289. if (pdata->has_fsl_erratum_14 == 1)
  290. ehci->has_fsl_port_bug = 1;
  291. if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
  292. if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0))
  293. return -EINVAL;
  294. if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
  295. if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 1))
  296. return -EINVAL;
  297. }
  298. if (pdata->have_sysif_regs) {
  299. #ifdef CONFIG_FSL_SOC_BOOKE
  300. iowrite32be(0x00000008, non_ehci + FSL_SOC_USB_PRICTRL);
  301. iowrite32be(0x00000080, non_ehci + FSL_SOC_USB_AGECNTTHRSH);
  302. #else
  303. iowrite32be(0x0000000c, non_ehci + FSL_SOC_USB_PRICTRL);
  304. iowrite32be(0x00000040, non_ehci + FSL_SOC_USB_AGECNTTHRSH);
  305. #endif
  306. iowrite32be(0x00000001, non_ehci + FSL_SOC_USB_SICTRL);
  307. }
  308. return 0;
  309. }
  310. /* called after powerup, by probe or system-pm "wakeup" */
  311. static int ehci_fsl_reinit(struct ehci_hcd *ehci)
  312. {
  313. if (ehci_fsl_usb_setup(ehci))
  314. return -EINVAL;
  315. return 0;
  316. }
  317. /* called during probe() after chip reset completes */
  318. static int ehci_fsl_setup(struct usb_hcd *hcd)
  319. {
  320. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  321. int retval;
  322. struct fsl_usb2_platform_data *pdata;
  323. struct device *dev;
  324. dev = hcd->self.controller;
  325. pdata = dev_get_platdata(hcd->self.controller);
  326. ehci->big_endian_desc = pdata->big_endian_desc;
  327. ehci->big_endian_mmio = pdata->big_endian_mmio;
  328. /* EHCI registers start at offset 0x100 */
  329. ehci->caps = hcd->regs + 0x100;
  330. #ifdef CONFIG_PPC_83xx
  331. /*
  332. * Deal with MPC834X that need port power to be cycled after the power
  333. * fault condition is removed. Otherwise the state machine does not
  334. * reflect PORTSC[CSC] correctly.
  335. */
  336. ehci->need_oc_pp_cycle = 1;
  337. #endif
  338. hcd->has_tt = 1;
  339. retval = ehci_setup(hcd);
  340. if (retval)
  341. return retval;
  342. if (of_device_is_compatible(dev->parent->of_node,
  343. "fsl,mpc5121-usb2-dr")) {
  344. /*
  345. * set SBUSCFG:AHBBRST so that control msgs don't
  346. * fail when doing heavy PATA writes.
  347. */
  348. ehci_writel(ehci, SBUSCFG_INCR8,
  349. hcd->regs + FSL_SOC_USB_SBUSCFG);
  350. }
  351. retval = ehci_fsl_reinit(ehci);
  352. return retval;
  353. }
  354. struct ehci_fsl {
  355. struct ehci_hcd ehci;
  356. #ifdef CONFIG_PM
  357. /* Saved USB PHY settings, need to restore after deep sleep. */
  358. u32 usb_ctrl;
  359. #endif
  360. };
  361. #ifdef CONFIG_PM
  362. #ifdef CONFIG_PPC_MPC512x
  363. static int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
  364. {
  365. struct usb_hcd *hcd = dev_get_drvdata(dev);
  366. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  367. struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
  368. u32 tmp;
  369. #ifdef CONFIG_DYNAMIC_DEBUG
  370. u32 mode = ehci_readl(ehci, hcd->regs + FSL_SOC_USB_USBMODE);
  371. mode &= USBMODE_CM_MASK;
  372. tmp = ehci_readl(ehci, hcd->regs + 0x140); /* usbcmd */
  373. dev_dbg(dev, "suspend=%d already_suspended=%d "
  374. "mode=%d usbcmd %08x\n", pdata->suspended,
  375. pdata->already_suspended, mode, tmp);
  376. #endif
  377. /*
  378. * If the controller is already suspended, then this must be a
  379. * PM suspend. Remember this fact, so that we will leave the
  380. * controller suspended at PM resume time.
  381. */
  382. if (pdata->suspended) {
  383. dev_dbg(dev, "already suspended, leaving early\n");
  384. pdata->already_suspended = 1;
  385. return 0;
  386. }
  387. dev_dbg(dev, "suspending...\n");
  388. ehci->rh_state = EHCI_RH_SUSPENDED;
  389. dev->power.power_state = PMSG_SUSPEND;
  390. /* ignore non-host interrupts */
  391. clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  392. /* stop the controller */
  393. tmp = ehci_readl(ehci, &ehci->regs->command);
  394. tmp &= ~CMD_RUN;
  395. ehci_writel(ehci, tmp, &ehci->regs->command);
  396. /* save EHCI registers */
  397. pdata->pm_command = ehci_readl(ehci, &ehci->regs->command);
  398. pdata->pm_command &= ~CMD_RUN;
  399. pdata->pm_status = ehci_readl(ehci, &ehci->regs->status);
  400. pdata->pm_intr_enable = ehci_readl(ehci, &ehci->regs->intr_enable);
  401. pdata->pm_frame_index = ehci_readl(ehci, &ehci->regs->frame_index);
  402. pdata->pm_segment = ehci_readl(ehci, &ehci->regs->segment);
  403. pdata->pm_frame_list = ehci_readl(ehci, &ehci->regs->frame_list);
  404. pdata->pm_async_next = ehci_readl(ehci, &ehci->regs->async_next);
  405. pdata->pm_configured_flag =
  406. ehci_readl(ehci, &ehci->regs->configured_flag);
  407. pdata->pm_portsc = ehci_readl(ehci, &ehci->regs->port_status[0]);
  408. pdata->pm_usbgenctrl = ehci_readl(ehci,
  409. hcd->regs + FSL_SOC_USB_USBGENCTRL);
  410. /* clear the W1C bits */
  411. pdata->pm_portsc &= cpu_to_hc32(ehci, ~PORT_RWC_BITS);
  412. pdata->suspended = 1;
  413. /* clear PP to cut power to the port */
  414. tmp = ehci_readl(ehci, &ehci->regs->port_status[0]);
  415. tmp &= ~PORT_POWER;
  416. ehci_writel(ehci, tmp, &ehci->regs->port_status[0]);
  417. return 0;
  418. }
  419. static int ehci_fsl_mpc512x_drv_resume(struct device *dev)
  420. {
  421. struct usb_hcd *hcd = dev_get_drvdata(dev);
  422. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  423. struct fsl_usb2_platform_data *pdata = dev_get_platdata(dev);
  424. u32 tmp;
  425. dev_dbg(dev, "suspend=%d already_suspended=%d\n",
  426. pdata->suspended, pdata->already_suspended);
  427. /*
  428. * If the controller was already suspended at suspend time,
  429. * then don't resume it now.
  430. */
  431. if (pdata->already_suspended) {
  432. dev_dbg(dev, "already suspended, leaving early\n");
  433. pdata->already_suspended = 0;
  434. return 0;
  435. }
  436. if (!pdata->suspended) {
  437. dev_dbg(dev, "not suspended, leaving early\n");
  438. return 0;
  439. }
  440. pdata->suspended = 0;
  441. dev_dbg(dev, "resuming...\n");
  442. /* set host mode */
  443. tmp = USBMODE_CM_HOST | (pdata->es ? USBMODE_ES : 0);
  444. ehci_writel(ehci, tmp, hcd->regs + FSL_SOC_USB_USBMODE);
  445. ehci_writel(ehci, pdata->pm_usbgenctrl,
  446. hcd->regs + FSL_SOC_USB_USBGENCTRL);
  447. ehci_writel(ehci, ISIPHYCTRL_PXE | ISIPHYCTRL_PHYE,
  448. hcd->regs + FSL_SOC_USB_ISIPHYCTRL);
  449. ehci_writel(ehci, SBUSCFG_INCR8, hcd->regs + FSL_SOC_USB_SBUSCFG);
  450. /* restore EHCI registers */
  451. ehci_writel(ehci, pdata->pm_command, &ehci->regs->command);
  452. ehci_writel(ehci, pdata->pm_intr_enable, &ehci->regs->intr_enable);
  453. ehci_writel(ehci, pdata->pm_frame_index, &ehci->regs->frame_index);
  454. ehci_writel(ehci, pdata->pm_segment, &ehci->regs->segment);
  455. ehci_writel(ehci, pdata->pm_frame_list, &ehci->regs->frame_list);
  456. ehci_writel(ehci, pdata->pm_async_next, &ehci->regs->async_next);
  457. ehci_writel(ehci, pdata->pm_configured_flag,
  458. &ehci->regs->configured_flag);
  459. ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]);
  460. set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
  461. ehci->rh_state = EHCI_RH_RUNNING;
  462. dev->power.power_state = PMSG_ON;
  463. tmp = ehci_readl(ehci, &ehci->regs->command);
  464. tmp |= CMD_RUN;
  465. ehci_writel(ehci, tmp, &ehci->regs->command);
  466. usb_hcd_resume_root_hub(hcd);
  467. return 0;
  468. }
  469. #else
  470. static inline int ehci_fsl_mpc512x_drv_suspend(struct device *dev)
  471. {
  472. return 0;
  473. }
  474. static inline int ehci_fsl_mpc512x_drv_resume(struct device *dev)
  475. {
  476. return 0;
  477. }
  478. #endif /* CONFIG_PPC_MPC512x */
  479. static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
  480. {
  481. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  482. return container_of(ehci, struct ehci_fsl, ehci);
  483. }
  484. static int ehci_fsl_drv_suspend(struct device *dev)
  485. {
  486. struct usb_hcd *hcd = dev_get_drvdata(dev);
  487. struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  488. void __iomem *non_ehci = hcd->regs;
  489. if (of_device_is_compatible(dev->parent->of_node,
  490. "fsl,mpc5121-usb2-dr")) {
  491. return ehci_fsl_mpc512x_drv_suspend(dev);
  492. }
  493. ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
  494. device_may_wakeup(dev));
  495. if (!fsl_deep_sleep())
  496. return 0;
  497. ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
  498. return 0;
  499. }
  500. static int ehci_fsl_drv_resume(struct device *dev)
  501. {
  502. struct usb_hcd *hcd = dev_get_drvdata(dev);
  503. struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
  504. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  505. void __iomem *non_ehci = hcd->regs;
  506. if (of_device_is_compatible(dev->parent->of_node,
  507. "fsl,mpc5121-usb2-dr")) {
  508. return ehci_fsl_mpc512x_drv_resume(dev);
  509. }
  510. ehci_prepare_ports_for_controller_resume(ehci);
  511. if (!fsl_deep_sleep())
  512. return 0;
  513. usb_root_hub_lost_power(hcd->self.root_hub);
  514. /* Restore USB PHY settings and enable the controller. */
  515. iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
  516. ehci_reset(ehci);
  517. ehci_fsl_reinit(ehci);
  518. return 0;
  519. }
  520. static int ehci_fsl_drv_restore(struct device *dev)
  521. {
  522. struct usb_hcd *hcd = dev_get_drvdata(dev);
  523. usb_root_hub_lost_power(hcd->self.root_hub);
  524. return 0;
  525. }
  526. static const struct dev_pm_ops ehci_fsl_pm_ops = {
  527. .suspend = ehci_fsl_drv_suspend,
  528. .resume = ehci_fsl_drv_resume,
  529. .restore = ehci_fsl_drv_restore,
  530. };
  531. #define EHCI_FSL_PM_OPS (&ehci_fsl_pm_ops)
  532. #else
  533. #define EHCI_FSL_PM_OPS NULL
  534. #endif /* CONFIG_PM */
  535. #ifdef CONFIG_USB_OTG
  536. static int ehci_start_port_reset(struct usb_hcd *hcd, unsigned port)
  537. {
  538. struct ehci_hcd *ehci = hcd_to_ehci(hcd);
  539. u32 status;
  540. if (!port)
  541. return -EINVAL;
  542. port--;
  543. /* start port reset before HNP protocol time out */
  544. status = readl(&ehci->regs->port_status[port]);
  545. if (!(status & PORT_CONNECT))
  546. return -ENODEV;
  547. /* hub_wq will finish the reset later */
  548. if (ehci_is_TDI(ehci)) {
  549. writel(PORT_RESET |
  550. (status & ~(PORT_CSC | PORT_PEC | PORT_OCC)),
  551. &ehci->regs->port_status[port]);
  552. } else {
  553. writel(PORT_RESET, &ehci->regs->port_status[port]);
  554. }
  555. return 0;
  556. }
  557. #else
  558. #define ehci_start_port_reset NULL
  559. #endif /* CONFIG_USB_OTG */
  560. static const struct ehci_driver_overrides ehci_fsl_overrides __initconst = {
  561. .extra_priv_size = sizeof(struct ehci_fsl),
  562. .reset = ehci_fsl_setup,
  563. };
  564. /**
  565. * fsl_ehci_drv_remove - shutdown processing for FSL-based HCDs
  566. * @dev: USB Host Controller being removed
  567. * Context: !in_interrupt()
  568. *
  569. * Reverses the effect of usb_hcd_fsl_probe().
  570. *
  571. */
  572. static int fsl_ehci_drv_remove(struct platform_device *pdev)
  573. {
  574. struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev);
  575. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  576. if (!IS_ERR_OR_NULL(hcd->usb_phy)) {
  577. otg_set_host(hcd->usb_phy->otg, NULL);
  578. usb_put_phy(hcd->usb_phy);
  579. }
  580. usb_remove_hcd(hcd);
  581. /*
  582. * do platform specific un-initialization:
  583. * release iomux pins, disable clock, etc.
  584. */
  585. if (pdata->exit)
  586. pdata->exit(pdev);
  587. usb_put_hcd(hcd);
  588. return 0;
  589. }
  590. static struct platform_driver ehci_fsl_driver = {
  591. .probe = fsl_ehci_drv_probe,
  592. .remove = fsl_ehci_drv_remove,
  593. .shutdown = usb_hcd_platform_shutdown,
  594. .driver = {
  595. .name = "fsl-ehci",
  596. .pm = EHCI_FSL_PM_OPS,
  597. },
  598. };
  599. static int __init ehci_fsl_init(void)
  600. {
  601. if (usb_disabled())
  602. return -ENODEV;
  603. pr_info(DRV_NAME ": " DRIVER_DESC "\n");
  604. ehci_init_driver(&fsl_ehci_hc_driver, &ehci_fsl_overrides);
  605. fsl_ehci_hc_driver.product_desc =
  606. "Freescale On-Chip EHCI Host Controller";
  607. fsl_ehci_hc_driver.start_port_reset = ehci_start_port_reset;
  608. return platform_driver_register(&ehci_fsl_driver);
  609. }
  610. module_init(ehci_fsl_init);
  611. static void __exit ehci_fsl_cleanup(void)
  612. {
  613. platform_driver_unregister(&ehci_fsl_driver);
  614. }
  615. module_exit(ehci_fsl_cleanup);
  616. MODULE_DESCRIPTION(DRIVER_DESC);
  617. MODULE_LICENSE("GPL");
  618. MODULE_ALIAS("platform:" DRV_NAME);