xhci-mvebu.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2014 Marvell
  4. * Author: Gregory CLEMENT <[email protected]>
  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/usb.h>
  11. #include <linux/usb/hcd.h>
  12. #include "xhci-mvebu.h"
  13. #include "xhci.h"
  14. #define USB3_MAX_WINDOWS 4
  15. #define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
  16. #define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
  17. static void xhci_mvebu_mbus_config(void __iomem *base,
  18. const struct mbus_dram_target_info *dram)
  19. {
  20. int win;
  21. /* Clear all existing windows */
  22. for (win = 0; win < USB3_MAX_WINDOWS; win++) {
  23. writel(0, base + USB3_WIN_CTRL(win));
  24. writel(0, base + USB3_WIN_BASE(win));
  25. }
  26. /* Program each DRAM CS in a seperate window */
  27. for (win = 0; win < dram->num_cs; win++) {
  28. const struct mbus_dram_window *cs = &dram->cs[win];
  29. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  30. (dram->mbus_dram_target_id << 4) | 1,
  31. base + USB3_WIN_CTRL(win));
  32. writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
  33. }
  34. }
  35. int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
  36. {
  37. struct device *dev = hcd->self.controller;
  38. struct platform_device *pdev = to_platform_device(dev);
  39. struct resource *res;
  40. void __iomem *base;
  41. const struct mbus_dram_target_info *dram;
  42. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  43. if (!res)
  44. return -ENODEV;
  45. /*
  46. * We don't use devm_ioremap() because this mapping should
  47. * only exists for the duration of this probe function.
  48. */
  49. base = ioremap(res->start, resource_size(res));
  50. if (!base)
  51. return -ENODEV;
  52. dram = mv_mbus_dram_info();
  53. xhci_mvebu_mbus_config(base, dram);
  54. /*
  55. * This memory area was only needed to configure the MBus
  56. * windows, and is therefore no longer useful.
  57. */
  58. iounmap(base);
  59. return 0;
  60. }
  61. int xhci_mvebu_a3700_init_quirk(struct usb_hcd *hcd)
  62. {
  63. struct xhci_hcd *xhci = hcd_to_xhci(hcd);
  64. /* Without reset on resume, the HC won't work at all */
  65. xhci->quirks |= XHCI_RESET_ON_RESUME;
  66. return 0;
  67. }