host.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 <dm.h>
  12. #include <dm/devres.h>
  13. #include <linux/compat.h>
  14. #include <usb.h>
  15. #include <usb/xhci.h>
  16. #include "core.h"
  17. #include "drd.h"
  18. static int __cdns3_host_init(struct cdns3 *cdns)
  19. {
  20. struct xhci_hcor *hcor;
  21. struct xhci_hccr *hccr;
  22. cdns3_drd_switch_host(cdns, 1);
  23. hccr = (struct xhci_hccr *)cdns->xhci_regs;
  24. hcor = (struct xhci_hcor *)(cdns->xhci_regs +
  25. HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
  26. return xhci_register(cdns->dev, hccr, hcor);
  27. }
  28. static void cdns3_host_exit(struct cdns3 *cdns)
  29. {
  30. xhci_deregister(cdns->dev);
  31. cdns3_drd_switch_host(cdns, 0);
  32. }
  33. int cdns3_host_init(struct cdns3 *cdns)
  34. {
  35. struct cdns3_role_driver *rdrv;
  36. rdrv = devm_kzalloc(cdns->dev, sizeof(*rdrv), GFP_KERNEL);
  37. if (!rdrv)
  38. return -ENOMEM;
  39. rdrv->start = __cdns3_host_init;
  40. rdrv->stop = cdns3_host_exit;
  41. rdrv->state = CDNS3_ROLE_STATE_INACTIVE;
  42. rdrv->name = "host";
  43. cdns->roles[USB_ROLE_HOST] = rdrv;
  44. return 0;
  45. }