host.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * host.c - DesignWare USB3 DRD Controller Host Glue
  3. *
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com
  5. *
  6. * Authors: Felipe Balbi <balbi@ti.com>,
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 of
  10. * the License as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/platform_device.h>
  18. #include <linux/usb/xhci_pdriver.h>
  19. #include "core.h"
  20. int dwc3_host_init(struct dwc3 *dwc)
  21. {
  22. struct platform_device *xhci;
  23. struct usb_xhci_pdata pdata;
  24. int ret;
  25. xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
  26. if (!xhci) {
  27. dev_err(dwc->dev, "couldn't allocate xHCI device\n");
  28. ret = -ENOMEM;
  29. goto err0;
  30. }
  31. dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
  32. xhci->dev.parent = dwc->dev;
  33. xhci->dev.dma_mask = dwc->dev->dma_mask;
  34. xhci->dev.dma_parms = dwc->dev->dma_parms;
  35. dwc->xhci = xhci;
  36. ret = platform_device_add_resources(xhci, dwc->xhci_resources,
  37. DWC3_XHCI_RESOURCES_NUM);
  38. if (ret) {
  39. dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
  40. goto err1;
  41. }
  42. memset(&pdata, 0, sizeof(pdata));
  43. #ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE
  44. pdata.usb3_lpm_capable = 1;
  45. #endif
  46. ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
  47. if (ret) {
  48. dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
  49. goto err1;
  50. }
  51. ret = platform_device_add(xhci);
  52. if (ret) {
  53. dev_err(dwc->dev, "failed to register xHCI device\n");
  54. goto err1;
  55. }
  56. return 0;
  57. err1:
  58. platform_device_put(xhci);
  59. err0:
  60. return ret;
  61. }
  62. void dwc3_host_exit(struct dwc3 *dwc)
  63. {
  64. platform_device_unregister(dwc->xhci);
  65. }