addr-map.c 3.7 KB

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