ehci-fsl.c 19 KB

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