xhci-mvebu.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2014 Marvell
  3. * Author: Gregory CLEMENT <gregory.clement@free-electrons.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * version 2 as published by the Free Software Foundation.
  8. */
  9. #include <linux/io.h>
  10. #include <linux/mbus.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/usb.h>
  14. #include <linux/usb/hcd.h>
  15. #include "xhci-mvebu.h"
  16. #define USB3_MAX_WINDOWS 4
  17. #define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
  18. #define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
  19. static void xhci_mvebu_mbus_config(void __iomem *base,
  20. const struct mbus_dram_target_info *dram)
  21. {
  22. int win;
  23. /* Clear all existing windows */
  24. for (win = 0; win < USB3_MAX_WINDOWS; win++) {
  25. writel(0, base + USB3_WIN_CTRL(win));
  26. writel(0, base + USB3_WIN_BASE(win));
  27. }
  28. /* Program each DRAM CS in a seperate window */
  29. for (win = 0; win < dram->num_cs; win++) {
  30. const struct mbus_dram_window *cs = dram->cs + win;
  31. writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
  32. (dram->mbus_dram_target_id << 4) | 1,
  33. base + USB3_WIN_CTRL(win));
  34. writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(win));
  35. }
  36. }
  37. int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
  38. {
  39. struct device *dev = hcd->self.controller;
  40. struct platform_device *pdev = to_platform_device(dev);
  41. struct resource *res;
  42. void __iomem *base;
  43. const struct mbus_dram_target_info *dram;
  44. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  45. if (!res)
  46. return -ENODEV;
  47. /*
  48. * We don't use devm_ioremap() because this mapping should
  49. * only exists for the duration of this probe function.
  50. */
  51. base = ioremap(res->start, resource_size(res));
  52. if (!base)
  53. return -ENODEV;
  54. dram = mv_mbus_dram_info();
  55. xhci_mvebu_mbus_config(base, dram);
  56. /*
  57. * This memory area was only needed to configure the MBus
  58. * windows, and is therefore no longer useful.
  59. */
  60. iounmap(base);
  61. return 0;
  62. }