ehci-fsl.c 18 KB

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