host.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. return -ENOMEM;
  29. }
  30. dma_set_coherent_mask(&xhci->dev, dwc->dev->coherent_dma_mask);
  31. xhci->dev.parent = dwc->dev;
  32. xhci->dev.dma_mask = dwc->dev->dma_mask;
  33. xhci->dev.dma_parms = dwc->dev->dma_parms;
  34. dwc->xhci = xhci;
  35. ret = platform_device_add_resources(xhci, dwc->xhci_resources,
  36. DWC3_XHCI_RESOURCES_NUM);
  37. if (ret) {
  38. dev_err(dwc->dev, "couldn't add resources to xHCI device\n");
  39. goto err1;
  40. }
  41. memset(&pdata, 0, sizeof(pdata));
  42. #ifdef CONFIG_DWC3_HOST_USB3_LPM_ENABLE
  43. pdata.usb3_lpm_capable = 1;
  44. #endif
  45. ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
  46. if (ret) {
  47. dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
  48. goto err1;
  49. }
  50. phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
  51. dev_name(&xhci->dev));
  52. phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
  53. dev_name(&xhci->dev));
  54. ret = platform_device_add(xhci);
  55. if (ret) {
  56. dev_err(dwc->dev, "failed to register xHCI device\n");
  57. goto err2;
  58. }
  59. return 0;
  60. err2:
  61. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  62. dev_name(&xhci->dev));
  63. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  64. dev_name(&xhci->dev));
  65. err1:
  66. platform_device_put(xhci);
  67. return ret;
  68. }
  69. void dwc3_host_exit(struct dwc3 *dwc)
  70. {
  71. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  72. dev_name(&dwc->xhci->dev));
  73. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  74. dev_name(&dwc->xhci->dev));
  75. platform_device_unregister(dwc->xhci);
  76. }