ehci-fsl.c 18 KB

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