ehci-generic.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <clk.h>
  8. #include <asm/io.h>
  9. #include <dm.h>
  10. #include "ehci.h"
  11. /*
  12. * Even though here we don't explicitly use "struct ehci_ctrl"
  13. * ehci_register() expects it to be the first thing that resides in
  14. * device's private data.
  15. */
  16. struct generic_ehci {
  17. struct ehci_ctrl ctrl;
  18. };
  19. static int ehci_usb_probe(struct udevice *dev)
  20. {
  21. struct ehci_hccr *hccr;
  22. struct ehci_hcor *hcor;
  23. int i;
  24. for (i = 0; ; i++) {
  25. struct clk clk;
  26. int ret;
  27. ret = clk_get_by_index(dev, i, &clk);
  28. if (ret < 0)
  29. break;
  30. if (clk_enable(&clk))
  31. printf("failed to enable clock %d\n", i);
  32. clk_free(&clk);
  33. }
  34. hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE);
  35. hcor = (struct ehci_hcor *)((uintptr_t)hccr +
  36. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  37. return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
  38. }
  39. static int ehci_usb_remove(struct udevice *dev)
  40. {
  41. return ehci_deregister(dev);
  42. }
  43. static const struct udevice_id ehci_usb_ids[] = {
  44. { .compatible = "generic-ehci" },
  45. { }
  46. };
  47. U_BOOT_DRIVER(ehci_generic) = {
  48. .name = "ehci_generic",
  49. .id = UCLASS_USB,
  50. .of_match = ehci_usb_ids,
  51. .probe = ehci_usb_probe,
  52. .remove = ehci_usb_remove,
  53. .ops = &ehci_usb_ops,
  54. .priv_auto_alloc_size = sizeof(struct generic_ehci),
  55. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  56. };