ehci-uniphier.c 1.4 KB

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