addr-map.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * arch/arm/plat-orion/addr-map.c
  3. *
  4. * Address map functions for Marvell Orion based SoCs
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/mbus.h>
  14. #include <linux/io.h>
  15. #include <plat/addr-map.h>
  16. struct mbus_dram_target_info orion_mbus_dram_info;
  17. const struct mbus_dram_target_info *mv_mbus_dram_info(void)
  18. {
  19. return &orion_mbus_dram_info;
  20. }
  21. EXPORT_SYMBOL_GPL(mv_mbus_dram_info);
  22. /*
  23. * DDR target is the same on all Orion platforms.
  24. */
  25. #define TARGET_DDR 0
  26. /*
  27. * Helpers to get DDR bank info
  28. */
  29. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  30. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  31. /*
  32. * CPU Address Decode Windows registers
  33. */
  34. #define WIN_CTRL_OFF 0x0000
  35. #define WIN_BASE_OFF 0x0004
  36. #define WIN_REMAP_LO_OFF 0x0008
  37. #define WIN_REMAP_HI_OFF 0x000c
  38. #define ATTR_HW_COHERENCY (0x1 << 4)
  39. /*
  40. * Default implementation
  41. */
  42. static void __init __iomem *
  43. orion_win_cfg_base(const struct orion_addr_map_cfg *cfg, int win)
  44. {
  45. return cfg->bridge_virt_base + (win << 4);
  46. }
  47. /*
  48. * Default implementation
  49. */
  50. static int __init orion_cpu_win_can_remap(const struct orion_addr_map_cfg *cfg,
  51. const int win)
  52. {
  53. if (win < cfg->remappable_wins)
  54. return 1;
  55. return 0;
  56. }
  57. void __init orion_setup_cpu_win(const struct orion_addr_map_cfg *cfg,
  58. const int win, const u32 base,
  59. const u32 size, const u8 target,
  60. const u8 attr, const int remap)
  61. {
  62. void __iomem *addr = cfg->win_cfg_base(cfg, win);
  63. u32 ctrl, base_high, remap_addr;
  64. if (win >= cfg->num_wins) {
  65. printk(KERN_ERR "setup_cpu_win: trying to allocate window "
  66. "%d when only %d allowed\n", win, cfg->num_wins);
  67. }
  68. base_high = base & 0xffff0000;
  69. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
  70. writel(base_high, addr + WIN_BASE_OFF);
  71. writel(ctrl, addr + WIN_CTRL_OFF);
  72. if (cfg->cpu_win_can_remap(cfg, win)) {
  73. if (remap < 0)
  74. remap_addr = base;
  75. else
  76. remap_addr = remap;
  77. writel(remap_addr & 0xffff0000, addr + WIN_REMAP_LO_OFF);
  78. writel(0, addr + WIN_REMAP_HI_OFF);
  79. }
  80. }
  81. /*
  82. * Configure a number of windows.
  83. */
  84. static void __init orion_setup_cpu_wins(const struct orion_addr_map_cfg * cfg,
  85. const struct orion_addr_map_info *info)
  86. {
  87. while (info->win != -1) {
  88. orion_setup_cpu_win(cfg, info->win, info->base, info->size,
  89. info->target, info->attr, info->remap);
  90. info++;
  91. }
  92. }
  93. static void __init orion_disable_wins(const struct orion_addr_map_cfg * cfg)
  94. {
  95. void __iomem *addr;
  96. int i;
  97. for (i = 0; i < cfg->num_wins; i++) {
  98. addr = cfg->win_cfg_base(cfg, i);
  99. writel(0, addr + WIN_BASE_OFF);
  100. writel(0, addr + WIN_CTRL_OFF);
  101. if (cfg->cpu_win_can_remap(cfg, i)) {
  102. writel(0, addr + WIN_REMAP_LO_OFF);
  103. writel(0, addr + WIN_REMAP_HI_OFF);
  104. }
  105. }
  106. }
  107. /*
  108. * Disable, clear and configure windows.
  109. */
  110. void __init orion_config_wins(struct orion_addr_map_cfg * cfg,
  111. const struct orion_addr_map_info *info)
  112. {
  113. if (!cfg->cpu_win_can_remap)
  114. cfg->cpu_win_can_remap = orion_cpu_win_can_remap;
  115. if (!cfg->win_cfg_base)
  116. cfg->win_cfg_base = orion_win_cfg_base;
  117. orion_disable_wins(cfg);
  118. if (info)
  119. orion_setup_cpu_wins(cfg, info);
  120. }
  121. /*
  122. * Setup MBUS dram target info.
  123. */
  124. void __init orion_setup_cpu_mbus_target(const struct orion_addr_map_cfg *cfg,
  125. const void __iomem *ddr_window_cpu_base)
  126. {
  127. int i;
  128. int cs;
  129. orion_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  130. for (i = 0, cs = 0; i < 4; i++) {
  131. u32 base = readl(ddr_window_cpu_base + DDR_BASE_CS_OFF(i));
  132. u32 size = readl(ddr_window_cpu_base + DDR_SIZE_CS_OFF(i));
  133. /*
  134. * Chip select enabled?
  135. */
  136. if (size & 1) {
  137. struct mbus_dram_window *w;
  138. w = &orion_mbus_dram_info.cs[cs++];
  139. w->cs_index = i;
  140. w->mbus_attr = 0xf & ~(1 << i);
  141. if (cfg->hw_io_coherency)
  142. w->mbus_attr |= ATTR_HW_COHERENCY;
  143. w->base = base & 0xffff0000;
  144. w->size = (size | 0x0000ffff) + 1;
  145. }
  146. }
  147. orion_mbus_dram_info.num_cs = cs;
  148. }