addr-map.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Address map functions for Marvell 370 / XP SoCs
  3. *
  4. * Copyright (C) 2012 Marvell
  5. *
  6. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/mbus.h>
  15. #include <linux/io.h>
  16. #include <linux/of.h>
  17. #include <linux/of_address.h>
  18. #include <plat/addr-map.h>
  19. /*
  20. * Generic Address Decode Windows bit settings
  21. */
  22. #define ARMADA_XP_TARGET_DEV_BUS 1
  23. #define ARMADA_XP_ATTR_DEV_BOOTROM 0x1D
  24. #define ARMADA_XP_TARGET_ETH1 3
  25. #define ARMADA_XP_TARGET_PCIE_0_2 4
  26. #define ARMADA_XP_TARGET_ETH0 7
  27. #define ARMADA_XP_TARGET_PCIE_1_3 8
  28. #define ARMADA_370_TARGET_DEV_BUS 1
  29. #define ARMADA_370_ATTR_DEV_BOOTROM 0x1D
  30. #define ARMADA_370_TARGET_PCIE_0 4
  31. #define ARMADA_370_TARGET_PCIE_1 8
  32. #define ARMADA_WINDOW_8_PLUS_OFFSET 0x90
  33. #define ARMADA_SDRAM_ADDR_DECODING_OFFSET 0x180
  34. static const struct __initdata orion_addr_map_info
  35. armada_xp_addr_map_info[] = {
  36. /*
  37. * Window for the BootROM, needed for SMP on Armada XP
  38. */
  39. { 0, 0xfff00000, SZ_1M, ARMADA_XP_TARGET_DEV_BUS,
  40. ARMADA_XP_ATTR_DEV_BOOTROM, -1 },
  41. /* End marker */
  42. { -1, 0, 0, 0, 0, 0 },
  43. };
  44. static const struct __initdata orion_addr_map_info
  45. armada_370_addr_map_info[] = {
  46. /* End marker */
  47. { -1, 0, 0, 0, 0, 0 },
  48. };
  49. static struct of_device_id of_addr_decoding_controller_table[] = {
  50. { .compatible = "marvell,armada-addr-decoding-controller" },
  51. { /* end of list */ },
  52. };
  53. static void __iomem *
  54. armada_cfg_base(const struct orion_addr_map_cfg *cfg, int win)
  55. {
  56. unsigned int offset;
  57. /* The register layout is a bit annoying and the below code
  58. * tries to cope with it.
  59. * - At offset 0x0, there are the registers for the first 8
  60. * windows, with 4 registers of 32 bits per window (ctrl,
  61. * base, remap low, remap high)
  62. * - Then at offset 0x80, there is a hole of 0x10 bytes for
  63. * the internal registers base address and internal units
  64. * sync barrier register.
  65. * - Then at offset 0x90, there the registers for 12
  66. * windows, with only 2 registers of 32 bits per window
  67. * (ctrl, base).
  68. */
  69. if (win < 8)
  70. offset = (win << 4);
  71. else
  72. offset = ARMADA_WINDOW_8_PLUS_OFFSET + ((win - 8) << 3);
  73. return cfg->bridge_virt_base + offset;
  74. }
  75. static struct __initdata orion_addr_map_cfg addr_map_cfg = {
  76. .num_wins = 20,
  77. .remappable_wins = 8,
  78. .win_cfg_base = armada_cfg_base,
  79. };
  80. static int __init armada_setup_cpu_mbus(void)
  81. {
  82. struct device_node *np;
  83. void __iomem *mbus_unit_addr_decoding_base;
  84. void __iomem *sdram_addr_decoding_base;
  85. np = of_find_matching_node(NULL, of_addr_decoding_controller_table);
  86. if (!np)
  87. return -ENODEV;
  88. mbus_unit_addr_decoding_base = of_iomap(np, 0);
  89. BUG_ON(!mbus_unit_addr_decoding_base);
  90. sdram_addr_decoding_base =
  91. mbus_unit_addr_decoding_base +
  92. ARMADA_SDRAM_ADDR_DECODING_OFFSET;
  93. addr_map_cfg.bridge_virt_base = mbus_unit_addr_decoding_base;
  94. if (of_find_compatible_node(NULL, NULL, "marvell,coherency-fabric"))
  95. addr_map_cfg.hw_io_coherency = 1;
  96. /*
  97. * Disable, clear and configure windows.
  98. */
  99. if (of_machine_is_compatible("marvell,armadaxp"))
  100. orion_config_wins(&addr_map_cfg, armada_xp_addr_map_info);
  101. else if (of_machine_is_compatible("marvell,armada370"))
  102. orion_config_wins(&addr_map_cfg, armada_370_addr_map_info);
  103. else {
  104. pr_err("Unsupported SoC\n");
  105. return -EINVAL;
  106. }
  107. /*
  108. * Setup MBUS dram target info.
  109. */
  110. orion_setup_cpu_mbus_target(&addr_map_cfg,
  111. sdram_addr_decoding_base);
  112. return 0;
  113. }
  114. /* Using a early_initcall is needed so that this initialization gets
  115. * done before the SMP initialization, which requires the BootROM to
  116. * be remapped. */
  117. early_initcall(armada_setup_cpu_mbus);