ehci-fsl.c 19 KB

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