ehci-fsl.c 19 KB

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