xhci-mvebu.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "xhci-mvebu.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 platform_device *pdev)
  36. {
  37. struct resource *res;
  38. void __iomem *base;
  39. const struct mbus_dram_target_info *dram;
  40. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  41. if (!res)
  42. return -ENODEV;
  43. /*
  44. * We don't use devm_ioremap() because this mapping should
  45. * only exists for the duration of this probe function.
  46. */
  47. base = ioremap(res->start, resource_size(res));
  48. if (!base)
  49. return -ENODEV;
  50. dram = mv_mbus_dram_info();
  51. xhci_mvebu_mbus_config(base, dram);
  52. /*
  53. * This memory area was only needed to configure the MBus
  54. * windows, and is therefore no longer useful.
  55. */
  56. iounmap(base);
  57. return 0;
  58. }