xhci-mvebu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2014 Marvell
  4. * Author: Gregory CLEMENT <gregory.clement@free-electrons.com>
  5. */
  6. #include <linux/io.h>
  7. #include <linux/mbus.h>
  8. #include <linux/of.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/phy/phy.h>
  11. #include <linux/usb.h>
  12. #include <linux/usb/hcd.h>
  13. #include "xhci-mvebu.h"
  14. #include "xhci.h"
  15. #define USB3_MAX_WINDOWS 4
  16. #define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
  17. #define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
  18. static void xhci_mvebu_mbus_config(void __iomem *base,
  19. const struct mbus_dram_target_info *dram)
  20. {
  21. int win;
  22. /* Clear all existing windows */
  23. for (win = 0; win < USB3_MAX_WINDOWS; win++) {
  24. writel(0, base + USB3_WIN_CTRL(win));
  25. writel(0, base + USB3_WIN_BASE(win));
  26. }
  27. /* Program each DRAM CS in a seperate window */
  28. for (win = 0; win < dram->num_cs; win++) {
  29. const struct mbus_dram_window *cs = dram->cs + win;
  30. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  31. (dram->mbus_dram_target_id << 4) | 1,
  32. base + USB3_WIN_CTRL(win));
  33. writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
  34. }
  35. }
  36. int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
  37. {
  38. struct device *dev = hcd->self.controller;
  39. struct platform_device *pdev = to_platform_device(dev);
  40. struct resource *res;
  41. void __iomem *base;
  42. const struct mbus_dram_target_info *dram;
  43. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  44. if (!res)
  45. return -ENODEV;
  46. /*
  47. * We don't use devm_ioremap() because this mapping should
  48. * only exists for the duration of this probe function.
  49. */
  50. base = ioremap(res->start, resource_size(res));
  51. if (!base)
  52. return -ENODEV;
  53. dram = mv_mbus_dram_info();
  54. xhci_mvebu_mbus_config(base, dram);
  55. /*
  56. * This memory area was only needed to configure the MBus
  57. * windows, and is therefore no longer useful.
  58. */
  59. iounmap(base);
  60. return 0;
  61. }
  62. int xhci_mvebu_a3700_plat_setup(struct usb_hcd *hcd)
  63. {
  64. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  65. struct device *dev = hcd->self.controller;
  66. struct phy *phy;
  67. int ret;
  68. /* Old bindings miss the PHY handle */
  69. phy = of_phy_get(dev->of_node, "usb3-phy");
  70. if (IS_ERR(phy) && PTR_ERR(phy) == -EPROBE_DEFER)
  71. return -EPROBE_DEFER;
  72. else if (IS_ERR(phy))
  73. goto phy_out;
  74. ret = phy_init(phy);
  75. if (ret)
  76. goto phy_put;
  77. ret = phy_set_mode(phy, PHY_MODE_USB_HOST_SS);
  78. if (ret)
  79. goto phy_exit;
  80. ret = phy_power_on(phy);
  81. if (ret == -EOPNOTSUPP) {
  82. /* Skip initializatin of XHCI PHY when it is unsupported by firmware */
  83. dev_warn(dev, "PHY unsupported by firmware\n");
  84. xhci->quirks |= XHCI_SKIP_PHY_INIT;
  85. }
  86. if (ret)
  87. goto phy_exit;
  88. phy_power_off(phy);
  89. phy_exit:
  90. phy_exit(phy);
  91. phy_put:
  92. of_phy_put(phy);
  93. phy_out:
  94. return 0;
  95. }
  96. int xhci_mvebu_a3700_init_quirk(struct usb_hcd *hcd)
  97. {
  98. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  99. /* Without reset on resume, the HC won't work at all */
  100. xhci->quirks |= XHCI_RESET_ON_RESUME;
  101. return 0;
  102. }