ehci-uniphier.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <usb.h>
  10. #include <mach/mio-regs.h>
  11. #include <fdtdec.h>
  12. #include "ehci.h"
  13. DECLARE_GLOBAL_DATA_PTR;
  14. #define FDT gd->fdt_blob
  15. #define COMPAT "socionext,uniphier-ehci"
  16. static int get_uniphier_ehci_base(int index, struct ehci_hccr **base)
  17. {
  18. int offset;
  19. for (offset = fdt_node_offset_by_compatible(FDT, 0, COMPAT);
  20. offset >= 0;
  21. offset = fdt_node_offset_by_compatible(FDT, offset, COMPAT)) {
  22. if (index == 0) {
  23. *base = (struct ehci_hccr *)
  24. fdtdec_get_addr(FDT, offset, "reg");
  25. return 0;
  26. }
  27. index--;
  28. }
  29. return -ENODEV; /* not found */
  30. }
  31. static void uniphier_ehci_reset(int index, int on)
  32. {
  33. u32 tmp;
  34. tmp = readl(MIO_USB_RSTCTRL(index));
  35. if (on)
  36. tmp &= ~MIO_USB_RSTCTRL_XRST;
  37. else
  38. tmp |= MIO_USB_RSTCTRL_XRST;
  39. writel(tmp, MIO_USB_RSTCTRL(index));
  40. }
  41. int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
  42. struct ehci_hcor **hcor)
  43. {
  44. int ret;
  45. struct ehci_hccr *cr;
  46. struct ehci_hcor *or;
  47. uniphier_ehci_reset(index, 0);
  48. ret = get_uniphier_ehci_base(index, &cr);
  49. if (ret < 0)
  50. return ret;
  51. or = (void *)cr + HC_LENGTH(ehci_readl(&cr->cr_capbase));
  52. *hccr = cr;
  53. *hcor = or;
  54. return 0;
  55. }
  56. int ehci_hcd_stop(int index)
  57. {
  58. uniphier_ehci_reset(index, 1);
  59. return 0;
  60. }