xhci-mvebu.c 1.8 KB

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