host.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. pdata.usb3_lpm_capable = dwc->usb3_lpm_capable;
  43. ret = platform_device_add_data(xhci, &pdata, sizeof(pdata));
  44. if (ret) {
  45. dev_err(dwc->dev, "couldn't add platform data to xHCI device\n");
  46. goto err1;
  47. }
  48. phy_create_lookup(dwc->usb2_generic_phy, "usb2-phy",
  49. dev_name(&xhci->dev));
  50. phy_create_lookup(dwc->usb3_generic_phy, "usb3-phy",
  51. dev_name(&xhci->dev));
  52. ret = platform_device_add(xhci);
  53. if (ret) {
  54. dev_err(dwc->dev, "failed to register xHCI device\n");
  55. goto err2;
  56. }
  57. return 0;
  58. err2:
  59. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  60. dev_name(&xhci->dev));
  61. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  62. dev_name(&xhci->dev));
  63. err1:
  64. platform_device_put(xhci);
  65. return ret;
  66. }
  67. void dwc3_host_exit(struct dwc3 *dwc)
  68. {
  69. phy_remove_lookup(dwc->usb2_generic_phy, "usb2-phy",
  70. dev_name(&dwc->xhci->dev));
  71. phy_remove_lookup(dwc->usb3_generic_phy, "usb3-phy",
  72. dev_name(&dwc->xhci->dev));
  73. platform_device_unregister(dwc->xhci);
  74. }