host.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Cadence USBSS DRD Driver - host side
  4. *
  5. * Copyright (C) 2018-2019 Cadence Design Systems.
  6. * Copyright (C) 2017-2018 NXP
  7. *
  8. * Authors: Peter Chen <peter.chen@nxp.com>
  9. * Pawel Laszczak <pawell@cadence.com>
  10. */
  11. #include <linux/platform_device.h>
  12. #include "core.h"
  13. #include "drd.h"
  14. static int __cdns3_host_init(struct cdns3 *cdns)
  15. {
  16. struct platform_device *xhci;
  17. int ret;
  18. cdns3_drd_switch_host(cdns, 1);
  19. xhci = platform_device_alloc("xhci-hcd", PLATFORM_DEVID_AUTO);
  20. if (!xhci) {
  21. dev_err(cdns->dev, "couldn't allocate xHCI device\n");
  22. return -ENOMEM;
  23. }
  24. xhci->dev.parent = cdns->dev;
  25. cdns->host_dev = xhci;
  26. ret = platform_device_add_resources(xhci, cdns->xhci_res,
  27. CDNS3_XHCI_RESOURCES_NUM);
  28. if (ret) {
  29. dev_err(cdns->dev, "couldn't add resources to xHCI device\n");
  30. goto err1;
  31. }
  32. ret = platform_device_add(xhci);
  33. if (ret) {
  34. dev_err(cdns->dev, "failed to register xHCI device\n");
  35. goto err1;
  36. }
  37. return 0;
  38. err1:
  39. platform_device_put(xhci);
  40. return ret;
  41. }
  42. static void cdns3_host_exit(struct cdns3 *cdns)
  43. {
  44. platform_device_unregister(cdns->host_dev);
  45. cdns->host_dev = NULL;
  46. cdns3_drd_switch_host(cdns, 0);
  47. }
  48. int cdns3_host_init(struct cdns3 *cdns)
  49. {
  50. struct cdns3_role_driver *rdrv;
  51. rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
  52. if (!rdrv)
  53. return -ENOMEM;
  54. rdrv->start = __cdns3_host_init;
  55. rdrv->stop = cdns3_host_exit;
  56. rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
  57. rdrv->name = "host";
  58. cdns->roles[USB_ROLE_HOST] = rdrv;
  59. return 0;
  60. }