ehci-generic.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <reset.h>
  9. #include <asm/io.h>
  10. #include <dm.h>
  11. #include "ehci.h"
  12. /*
  13. * Even though here we don't explicitly use "struct ehci_ctrl"
  14. * ehci_register() expects it to be the first thing that resides in
  15. * device's private data.
  16. */
  17. struct generic_ehci {
  18. struct ehci_ctrl ctrl;
  19. };
  20. static int ehci_usb_probe(struct udevice *dev)
  21. {
  22. struct ehci_hccr *hccr;
  23. struct ehci_hcor *hcor;
  24. int i;
  25. for (i = 0; ; i++) {
  26. struct clk clk;
  27. int ret;
  28. ret = clk_get_by_index(dev, i, &clk);
  29. if (ret < 0)
  30. break;
  31. if (clk_enable(&clk))
  32. printf("failed to enable clock %d\n", i);
  33. clk_free(&clk);
  34. }
  35. for (i = 0; ; i++) {
  36. struct reset_ctl reset;
  37. int ret;
  38. ret = reset_get_by_index(dev, i, &reset);
  39. if (ret < 0)
  40. break;
  41. if (reset_deassert(&reset))
  42. printf("failed to deassert reset %d\n", i);
  43. reset_free(&reset);
  44. }
  45. hccr = map_physmem(dev_get_addr(dev), 0x100, MAP_NOCACHE);
  46. hcor = (struct ehci_hcor *)((uintptr_t)hccr +
  47. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  48. return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
  49. }
  50. static const struct udevice_id ehci_usb_ids[] = {
  51. { .compatible = "generic-ehci" },
  52. { }
  53. };
  54. U_BOOT_DRIVER(ehci_generic) = {
  55. .name = "ehci_generic",
  56. .id = UCLASS_USB,
  57. .of_match = ehci_usb_ids,
  58. .probe = ehci_usb_probe,
  59. .remove = ehci_deregister,
  60. .ops = &ehci_usb_ops,
  61. .priv_auto_alloc_size = sizeof(struct generic_ehci),
  62. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  63. };