ohci-pxa27x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*
  2. * OHCI HCD (Host Controller Driver) for USB.
  3. *
  4. * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  5. * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
  6. * (C) Copyright 2002 Hewlett-Packard Company
  7. *
  8. * Bus Glue for pxa27x
  9. *
  10. * Written by Christopher Hoover <ch@hpl.hp.com>
  11. * Based on fragments of previous driver by Russell King et al.
  12. *
  13. * Modified for LH7A404 from ohci-sa1111.c
  14. * by Durgesh Pattamatta <pattamattad@sharpsec.com>
  15. *
  16. * Modified for pxa27x from ohci-lh7a404.c
  17. * by Nick Bane <nick@cecomputing.co.uk> 26-8-2004
  18. *
  19. * This file is licenced under the GPL.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/signal.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/clk.h>
  25. #include <linux/of_platform.h>
  26. #include <linux/of_gpio.h>
  27. #include <mach/hardware.h>
  28. #include <linux/platform_data/usb-ohci-pxa27x.h>
  29. #include <linux/platform_data/usb-pxa3xx-ulpi.h>
  30. /*
  31. * UHC: USB Host Controller (OHCI-like) register definitions
  32. */
  33. #define UHCREV (0x0000) /* UHC HCI Spec Revision */
  34. #define UHCHCON (0x0004) /* UHC Host Control Register */
  35. #define UHCCOMS (0x0008) /* UHC Command Status Register */
  36. #define UHCINTS (0x000C) /* UHC Interrupt Status Register */
  37. #define UHCINTE (0x0010) /* UHC Interrupt Enable */
  38. #define UHCINTD (0x0014) /* UHC Interrupt Disable */
  39. #define UHCHCCA (0x0018) /* UHC Host Controller Comm. Area */
  40. #define UHCPCED (0x001C) /* UHC Period Current Endpt Descr */
  41. #define UHCCHED (0x0020) /* UHC Control Head Endpt Descr */
  42. #define UHCCCED (0x0024) /* UHC Control Current Endpt Descr */
  43. #define UHCBHED (0x0028) /* UHC Bulk Head Endpt Descr */
  44. #define UHCBCED (0x002C) /* UHC Bulk Current Endpt Descr */
  45. #define UHCDHEAD (0x0030) /* UHC Done Head */
  46. #define UHCFMI (0x0034) /* UHC Frame Interval */
  47. #define UHCFMR (0x0038) /* UHC Frame Remaining */
  48. #define UHCFMN (0x003C) /* UHC Frame Number */
  49. #define UHCPERS (0x0040) /* UHC Periodic Start */
  50. #define UHCLS (0x0044) /* UHC Low Speed Threshold */
  51. #define UHCRHDA (0x0048) /* UHC Root Hub Descriptor A */
  52. #define UHCRHDA_NOCP (1 << 12) /* No over current protection */
  53. #define UHCRHDA_OCPM (1 << 11) /* Over Current Protection Mode */
  54. #define UHCRHDA_POTPGT(x) \
  55. (((x) & 0xff) << 24) /* Power On To Power Good Time */
  56. #define UHCRHDB (0x004C) /* UHC Root Hub Descriptor B */
  57. #define UHCRHS (0x0050) /* UHC Root Hub Status */
  58. #define UHCRHPS1 (0x0054) /* UHC Root Hub Port 1 Status */
  59. #define UHCRHPS2 (0x0058) /* UHC Root Hub Port 2 Status */
  60. #define UHCRHPS3 (0x005C) /* UHC Root Hub Port 3 Status */
  61. #define UHCSTAT (0x0060) /* UHC Status Register */
  62. #define UHCSTAT_UPS3 (1 << 16) /* USB Power Sense Port3 */
  63. #define UHCSTAT_SBMAI (1 << 15) /* System Bus Master Abort Interrupt*/
  64. #define UHCSTAT_SBTAI (1 << 14) /* System Bus Target Abort Interrupt*/
  65. #define UHCSTAT_UPRI (1 << 13) /* USB Port Resume Interrupt */
  66. #define UHCSTAT_UPS2 (1 << 12) /* USB Power Sense Port 2 */
  67. #define UHCSTAT_UPS1 (1 << 11) /* USB Power Sense Port 1 */
  68. #define UHCSTAT_HTA (1 << 10) /* HCI Target Abort */
  69. #define UHCSTAT_HBA (1 << 8) /* HCI Buffer Active */
  70. #define UHCSTAT_RWUE (1 << 7) /* HCI Remote Wake Up Event */
  71. #define UHCHR (0x0064) /* UHC Reset Register */
  72. #define UHCHR_SSEP3 (1 << 11) /* Sleep Standby Enable for Port3 */
  73. #define UHCHR_SSEP2 (1 << 10) /* Sleep Standby Enable for Port2 */
  74. #define UHCHR_SSEP1 (1 << 9) /* Sleep Standby Enable for Port1 */
  75. #define UHCHR_PCPL (1 << 7) /* Power control polarity low */
  76. #define UHCHR_PSPL (1 << 6) /* Power sense polarity low */
  77. #define UHCHR_SSE (1 << 5) /* Sleep Standby Enable */
  78. #define UHCHR_UIT (1 << 4) /* USB Interrupt Test */
  79. #define UHCHR_SSDC (1 << 3) /* Simulation Scale Down Clock */
  80. #define UHCHR_CGR (1 << 2) /* Clock Generation Reset */
  81. #define UHCHR_FHR (1 << 1) /* Force Host Controller Reset */
  82. #define UHCHR_FSBIR (1 << 0) /* Force System Bus Iface Reset */
  83. #define UHCHIE (0x0068) /* UHC Interrupt Enable Register*/
  84. #define UHCHIE_UPS3IE (1 << 14) /* Power Sense Port3 IntEn */
  85. #define UHCHIE_UPRIE (1 << 13) /* Port Resume IntEn */
  86. #define UHCHIE_UPS2IE (1 << 12) /* Power Sense Port2 IntEn */
  87. #define UHCHIE_UPS1IE (1 << 11) /* Power Sense Port1 IntEn */
  88. #define UHCHIE_TAIE (1 << 10) /* HCI Interface Transfer Abort
  89. Interrupt Enable*/
  90. #define UHCHIE_HBAIE (1 << 8) /* HCI Buffer Active IntEn */
  91. #define UHCHIE_RWIE (1 << 7) /* Remote Wake-up IntEn */
  92. #define UHCHIT (0x006C) /* UHC Interrupt Test register */
  93. #define PXA_UHC_MAX_PORTNUM 3
  94. struct pxa27x_ohci {
  95. /* must be 1st member here for hcd_to_ohci() to work */
  96. struct ohci_hcd ohci;
  97. struct device *dev;
  98. struct clk *clk;
  99. void __iomem *mmio_base;
  100. };
  101. #define to_pxa27x_ohci(hcd) (struct pxa27x_ohci *)hcd_to_ohci(hcd)
  102. /*
  103. PMM_NPS_MODE -- PMM Non-power switching mode
  104. Ports are powered continuously.
  105. PMM_GLOBAL_MODE -- PMM global switching mode
  106. All ports are powered at the same time.
  107. PMM_PERPORT_MODE -- PMM per port switching mode
  108. Ports are powered individually.
  109. */
  110. static int pxa27x_ohci_select_pmm(struct pxa27x_ohci *ohci, int mode)
  111. {
  112. uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA);
  113. uint32_t uhcrhdb = __raw_readl(ohci->mmio_base + UHCRHDB);
  114. switch (mode) {
  115. case PMM_NPS_MODE:
  116. uhcrhda |= RH_A_NPS;
  117. break;
  118. case PMM_GLOBAL_MODE:
  119. uhcrhda &= ~(RH_A_NPS & RH_A_PSM);
  120. break;
  121. case PMM_PERPORT_MODE:
  122. uhcrhda &= ~(RH_A_NPS);
  123. uhcrhda |= RH_A_PSM;
  124. /* Set port power control mask bits, only 3 ports. */
  125. uhcrhdb |= (0x7<<17);
  126. break;
  127. default:
  128. printk( KERN_ERR
  129. "Invalid mode %d, set to non-power switch mode.\n",
  130. mode );
  131. uhcrhda |= RH_A_NPS;
  132. }
  133. __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA);
  134. __raw_writel(uhcrhdb, ohci->mmio_base + UHCRHDB);
  135. return 0;
  136. }
  137. extern int usb_disabled(void);
  138. /*-------------------------------------------------------------------------*/
  139. static inline void pxa27x_setup_hc(struct pxa27x_ohci *ohci,
  140. struct pxaohci_platform_data *inf)
  141. {
  142. uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR);
  143. uint32_t uhcrhda = __raw_readl(ohci->mmio_base + UHCRHDA);
  144. if (inf->flags & ENABLE_PORT1)
  145. uhchr &= ~UHCHR_SSEP1;
  146. if (inf->flags & ENABLE_PORT2)
  147. uhchr &= ~UHCHR_SSEP2;
  148. if (inf->flags & ENABLE_PORT3)
  149. uhchr &= ~UHCHR_SSEP3;
  150. if (inf->flags & POWER_CONTROL_LOW)
  151. uhchr |= UHCHR_PCPL;
  152. if (inf->flags & POWER_SENSE_LOW)
  153. uhchr |= UHCHR_PSPL;
  154. if (inf->flags & NO_OC_PROTECTION)
  155. uhcrhda |= UHCRHDA_NOCP;
  156. else
  157. uhcrhda &= ~UHCRHDA_NOCP;
  158. if (inf->flags & OC_MODE_PERPORT)
  159. uhcrhda |= UHCRHDA_OCPM;
  160. else
  161. uhcrhda &= ~UHCRHDA_OCPM;
  162. if (inf->power_on_delay) {
  163. uhcrhda &= ~UHCRHDA_POTPGT(0xff);
  164. uhcrhda |= UHCRHDA_POTPGT(inf->power_on_delay / 2);
  165. }
  166. __raw_writel(uhchr, ohci->mmio_base + UHCHR);
  167. __raw_writel(uhcrhda, ohci->mmio_base + UHCRHDA);
  168. }
  169. static inline void pxa27x_reset_hc(struct pxa27x_ohci *ohci)
  170. {
  171. uint32_t uhchr = __raw_readl(ohci->mmio_base + UHCHR);
  172. __raw_writel(uhchr | UHCHR_FHR, ohci->mmio_base + UHCHR);
  173. udelay(11);
  174. __raw_writel(uhchr & ~UHCHR_FHR, ohci->mmio_base + UHCHR);
  175. }
  176. #ifdef CONFIG_PXA27x
  177. extern void pxa27x_clear_otgph(void);
  178. #else
  179. #define pxa27x_clear_otgph() do {} while (0)
  180. #endif
  181. static int pxa27x_start_hc(struct pxa27x_ohci *ohci, struct device *dev)
  182. {
  183. int retval = 0;
  184. struct pxaohci_platform_data *inf;
  185. uint32_t uhchr;
  186. inf = dev->platform_data;
  187. clk_prepare_enable(ohci->clk);
  188. pxa27x_reset_hc(ohci);
  189. uhchr = __raw_readl(ohci->mmio_base + UHCHR) | UHCHR_FSBIR;
  190. __raw_writel(uhchr, ohci->mmio_base + UHCHR);
  191. while (__raw_readl(ohci->mmio_base + UHCHR) & UHCHR_FSBIR)
  192. cpu_relax();
  193. pxa27x_setup_hc(ohci, inf);
  194. if (inf->init)
  195. retval = inf->init(dev);
  196. if (retval < 0)
  197. return retval;
  198. if (cpu_is_pxa3xx())
  199. pxa3xx_u2d_start_hc(&ohci_to_hcd(&ohci->ohci)->self);
  200. uhchr = __raw_readl(ohci->mmio_base + UHCHR) & ~UHCHR_SSE;
  201. __raw_writel(uhchr, ohci->mmio_base + UHCHR);
  202. __raw_writel(UHCHIE_UPRIE | UHCHIE_RWIE, ohci->mmio_base + UHCHIE);
  203. /* Clear any OTG Pin Hold */
  204. pxa27x_clear_otgph();
  205. return 0;
  206. }
  207. static void pxa27x_stop_hc(struct pxa27x_ohci *ohci, struct device *dev)
  208. {
  209. struct pxaohci_platform_data *inf;
  210. uint32_t uhccoms;
  211. inf = dev->platform_data;
  212. if (cpu_is_pxa3xx())
  213. pxa3xx_u2d_stop_hc(&ohci_to_hcd(&ohci->ohci)->self);
  214. if (inf->exit)
  215. inf->exit(dev);
  216. pxa27x_reset_hc(ohci);
  217. /* Host Controller Reset */
  218. uhccoms = __raw_readl(ohci->mmio_base + UHCCOMS) | 0x01;
  219. __raw_writel(uhccoms, ohci->mmio_base + UHCCOMS);
  220. udelay(10);
  221. clk_disable_unprepare(ohci->clk);
  222. }
  223. #ifdef CONFIG_OF
  224. static const struct of_device_id pxa_ohci_dt_ids[] = {
  225. { .compatible = "marvell,pxa-ohci" },
  226. { }
  227. };
  228. MODULE_DEVICE_TABLE(of, pxa_ohci_dt_ids);
  229. static u64 pxa_ohci_dma_mask = DMA_BIT_MASK(32);
  230. static int ohci_pxa_of_init(struct platform_device *pdev)
  231. {
  232. struct device_node *np = pdev->dev.of_node;
  233. struct pxaohci_platform_data *pdata;
  234. u32 tmp;
  235. if (!np)
  236. return 0;
  237. /* Right now device-tree probed devices don't get dma_mask set.
  238. * Since shared usb code relies on it, set it here for now.
  239. * Once we have dma capability bindings this can go away.
  240. */
  241. if (!pdev->dev.dma_mask)
  242. pdev->dev.dma_mask = &pxa_ohci_dma_mask;
  243. pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
  244. if (!pdata)
  245. return -ENOMEM;
  246. if (of_get_property(np, "marvell,enable-port1", NULL))
  247. pdata->flags |= ENABLE_PORT1;
  248. if (of_get_property(np, "marvell,enable-port2", NULL))
  249. pdata->flags |= ENABLE_PORT2;
  250. if (of_get_property(np, "marvell,enable-port3", NULL))
  251. pdata->flags |= ENABLE_PORT3;
  252. if (of_get_property(np, "marvell,port-sense-low", NULL))
  253. pdata->flags |= POWER_SENSE_LOW;
  254. if (of_get_property(np, "marvell,power-control-low", NULL))
  255. pdata->flags |= POWER_CONTROL_LOW;
  256. if (of_get_property(np, "marvell,no-oc-protection", NULL))
  257. pdata->flags |= NO_OC_PROTECTION;
  258. if (of_get_property(np, "marvell,oc-mode-perport", NULL))
  259. pdata->flags |= OC_MODE_PERPORT;
  260. if (!of_property_read_u32(np, "marvell,power-on-delay", &tmp))
  261. pdata->power_on_delay = tmp;
  262. if (!of_property_read_u32(np, "marvell,port-mode", &tmp))
  263. pdata->port_mode = tmp;
  264. if (!of_property_read_u32(np, "marvell,power-budget", &tmp))
  265. pdata->power_budget = tmp;
  266. pdev->dev.platform_data = pdata;
  267. return 0;
  268. }
  269. #else
  270. static int ohci_pxa_of_init(struct platform_device *pdev)
  271. {
  272. return 0;
  273. }
  274. #endif
  275. /*-------------------------------------------------------------------------*/
  276. /* configure so an HC device and id are always provided */
  277. /* always called with process context; sleeping is OK */
  278. /**
  279. * usb_hcd_pxa27x_probe - initialize pxa27x-based HCDs
  280. * Context: !in_interrupt()
  281. *
  282. * Allocates basic resources for this USB host controller, and
  283. * then invokes the start() method for the HCD associated with it
  284. * through the hotplug entry's driver_data.
  285. *
  286. */
  287. int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device *pdev)
  288. {
  289. int retval, irq;
  290. struct usb_hcd *hcd;
  291. struct pxaohci_platform_data *inf;
  292. struct pxa27x_ohci *ohci;
  293. struct resource *r;
  294. struct clk *usb_clk;
  295. retval = ohci_pxa_of_init(pdev);
  296. if (retval)
  297. return retval;
  298. inf = pdev->dev.platform_data;
  299. if (!inf)
  300. return -ENODEV;
  301. irq = platform_get_irq(pdev, 0);
  302. if (irq < 0) {
  303. pr_err("no resource of IORESOURCE_IRQ");
  304. return -ENXIO;
  305. }
  306. usb_clk = clk_get(&pdev->dev, NULL);
  307. if (IS_ERR(usb_clk))
  308. return PTR_ERR(usb_clk);
  309. hcd = usb_create_hcd (driver, &pdev->dev, "pxa27x");
  310. if (!hcd) {
  311. retval = -ENOMEM;
  312. goto err0;
  313. }
  314. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  315. if (!r) {
  316. pr_err("no resource of IORESOURCE_MEM");
  317. retval = -ENXIO;
  318. goto err1;
  319. }
  320. hcd->rsrc_start = r->start;
  321. hcd->rsrc_len = resource_size(r);
  322. if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
  323. pr_debug("request_mem_region failed");
  324. retval = -EBUSY;
  325. goto err1;
  326. }
  327. hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
  328. if (!hcd->regs) {
  329. pr_debug("ioremap failed");
  330. retval = -ENOMEM;
  331. goto err2;
  332. }
  333. /* initialize "struct pxa27x_ohci" */
  334. ohci = (struct pxa27x_ohci *)hcd_to_ohci(hcd);
  335. ohci->dev = &pdev->dev;
  336. ohci->clk = usb_clk;
  337. ohci->mmio_base = (void __iomem *)hcd->regs;
  338. if ((retval = pxa27x_start_hc(ohci, &pdev->dev)) < 0) {
  339. pr_debug("pxa27x_start_hc failed");
  340. goto err3;
  341. }
  342. /* Select Power Management Mode */
  343. pxa27x_ohci_select_pmm(ohci, inf->port_mode);
  344. if (inf->power_budget)
  345. hcd->power_budget = inf->power_budget;
  346. ohci_hcd_init(hcd_to_ohci(hcd));
  347. retval = usb_add_hcd(hcd, irq, 0);
  348. if (retval == 0)
  349. return retval;
  350. pxa27x_stop_hc(ohci, &pdev->dev);
  351. err3:
  352. iounmap(hcd->regs);
  353. err2:
  354. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  355. err1:
  356. usb_put_hcd(hcd);
  357. err0:
  358. clk_put(usb_clk);
  359. return retval;
  360. }
  361. /* may be called without controller electrically present */
  362. /* may be called with controller, bus, and devices active */
  363. /**
  364. * usb_hcd_pxa27x_remove - shutdown processing for pxa27x-based HCDs
  365. * @dev: USB Host Controller being removed
  366. * Context: !in_interrupt()
  367. *
  368. * Reverses the effect of usb_hcd_pxa27x_probe(), first invoking
  369. * the HCD's stop() method. It is always called from a thread
  370. * context, normally "rmmod", "apmd", or something similar.
  371. *
  372. */
  373. void usb_hcd_pxa27x_remove (struct usb_hcd *hcd, struct platform_device *pdev)
  374. {
  375. struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd);
  376. usb_remove_hcd(hcd);
  377. pxa27x_stop_hc(ohci, &pdev->dev);
  378. iounmap(hcd->regs);
  379. release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
  380. usb_put_hcd(hcd);
  381. clk_put(ohci->clk);
  382. }
  383. /*-------------------------------------------------------------------------*/
  384. static int
  385. ohci_pxa27x_start (struct usb_hcd *hcd)
  386. {
  387. struct ohci_hcd *ohci = hcd_to_ohci (hcd);
  388. int ret;
  389. ohci_dbg (ohci, "ohci_pxa27x_start, ohci:%p", ohci);
  390. /* The value of NDP in roothub_a is incorrect on this hardware */
  391. ohci->num_ports = 3;
  392. if ((ret = ohci_init(ohci)) < 0)
  393. return ret;
  394. if ((ret = ohci_run (ohci)) < 0) {
  395. dev_err(hcd->self.controller, "can't start %s",
  396. hcd->self.bus_name);
  397. ohci_stop (hcd);
  398. return ret;
  399. }
  400. return 0;
  401. }
  402. /*-------------------------------------------------------------------------*/
  403. static const struct hc_driver ohci_pxa27x_hc_driver = {
  404. .description = hcd_name,
  405. .product_desc = "PXA27x OHCI",
  406. .hcd_priv_size = sizeof(struct pxa27x_ohci),
  407. /*
  408. * generic hardware linkage
  409. */
  410. .irq = ohci_irq,
  411. .flags = HCD_USB11 | HCD_MEMORY,
  412. /*
  413. * basic lifecycle operations
  414. */
  415. .start = ohci_pxa27x_start,
  416. .stop = ohci_stop,
  417. .shutdown = ohci_shutdown,
  418. /*
  419. * managing i/o requests and associated device resources
  420. */
  421. .urb_enqueue = ohci_urb_enqueue,
  422. .urb_dequeue = ohci_urb_dequeue,
  423. .endpoint_disable = ohci_endpoint_disable,
  424. /*
  425. * scheduling support
  426. */
  427. .get_frame_number = ohci_get_frame,
  428. /*
  429. * root hub support
  430. */
  431. .hub_status_data = ohci_hub_status_data,
  432. .hub_control = ohci_hub_control,
  433. #ifdef CONFIG_PM
  434. .bus_suspend = ohci_bus_suspend,
  435. .bus_resume = ohci_bus_resume,
  436. #endif
  437. .start_port_reset = ohci_start_port_reset,
  438. };
  439. /*-------------------------------------------------------------------------*/
  440. static int ohci_hcd_pxa27x_drv_probe(struct platform_device *pdev)
  441. {
  442. pr_debug ("In ohci_hcd_pxa27x_drv_probe");
  443. if (usb_disabled())
  444. return -ENODEV;
  445. return usb_hcd_pxa27x_probe(&ohci_pxa27x_hc_driver, pdev);
  446. }
  447. static int ohci_hcd_pxa27x_drv_remove(struct platform_device *pdev)
  448. {
  449. struct usb_hcd *hcd = platform_get_drvdata(pdev);
  450. usb_hcd_pxa27x_remove(hcd, pdev);
  451. platform_set_drvdata(pdev, NULL);
  452. return 0;
  453. }
  454. #ifdef CONFIG_PM
  455. static int ohci_hcd_pxa27x_drv_suspend(struct device *dev)
  456. {
  457. struct usb_hcd *hcd = dev_get_drvdata(dev);
  458. struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd);
  459. if (time_before(jiffies, ohci->ohci.next_statechange))
  460. msleep(5);
  461. ohci->ohci.next_statechange = jiffies;
  462. pxa27x_stop_hc(ohci, dev);
  463. return 0;
  464. }
  465. static int ohci_hcd_pxa27x_drv_resume(struct device *dev)
  466. {
  467. struct usb_hcd *hcd = dev_get_drvdata(dev);
  468. struct pxa27x_ohci *ohci = to_pxa27x_ohci(hcd);
  469. struct pxaohci_platform_data *inf = dev->platform_data;
  470. int status;
  471. if (time_before(jiffies, ohci->ohci.next_statechange))
  472. msleep(5);
  473. ohci->ohci.next_statechange = jiffies;
  474. if ((status = pxa27x_start_hc(ohci, dev)) < 0)
  475. return status;
  476. /* Select Power Management Mode */
  477. pxa27x_ohci_select_pmm(ohci, inf->port_mode);
  478. ohci_resume(hcd, false);
  479. return 0;
  480. }
  481. static const struct dev_pm_ops ohci_hcd_pxa27x_pm_ops = {
  482. .suspend = ohci_hcd_pxa27x_drv_suspend,
  483. .resume = ohci_hcd_pxa27x_drv_resume,
  484. };
  485. #endif
  486. /* work with hotplug and coldplug */
  487. MODULE_ALIAS("platform:pxa27x-ohci");
  488. static struct platform_driver ohci_hcd_pxa27x_driver = {
  489. .probe = ohci_hcd_pxa27x_drv_probe,
  490. .remove = ohci_hcd_pxa27x_drv_remove,
  491. .shutdown = usb_hcd_platform_shutdown,
  492. .driver = {
  493. .name = "pxa27x-ohci",
  494. .owner = THIS_MODULE,
  495. .of_match_table = of_match_ptr(pxa_ohci_dt_ids),
  496. #ifdef CONFIG_PM
  497. .pm = &ohci_hcd_pxa27x_pm_ops,
  498. #endif
  499. },
  500. };