ehci-uniphier.c 1.5 KB

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