addr-map.c 3.9 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. /*
  39. * Default implementation
  40. */
  41. static void __init __iomem *
  42. orion_win_cfg_base(const struct orion_addr_map_cfg *cfg, int win)
  43. {
  44. return (void __iomem *)(cfg->bridge_virt_base + (win << 4));
  45. }
  46. /*
  47. * Default implementation
  48. */
  49. static int __init orion_cpu_win_can_remap(const struct orion_addr_map_cfg *cfg,
  50. const int win)
  51. {
  52. if (win < cfg->remappable_wins)
  53. return 1;
  54. return 0;
  55. }
  56. void __init orion_setup_cpu_win(const struct orion_addr_map_cfg *cfg,
  57. const int win, const u32 base,
  58. const u32 size, const u8 target,
  59. const u8 attr, const int remap)
  60. {
  61. void __iomem *addr = cfg->win_cfg_base(cfg, win);
  62. u32 ctrl, base_high, remap_addr;
  63. if (win >= cfg->num_wins) {
  64. printk(KERN_ERR "setup_cpu_win: trying to allocate window "
  65. "%d when only %d allowed\n", win, cfg->num_wins);
  66. }
  67. base_high = base & 0xffff0000;
  68. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
  69. writel(base_high, addr + WIN_BASE_OFF);
  70. writel(ctrl, addr + WIN_CTRL_OFF);
  71. if (cfg->cpu_win_can_remap(cfg, win)) {
  72. if (remap < 0)
  73. remap_addr = base;
  74. else
  75. remap_addr = remap;
  76. writel(remap_addr & 0xffff0000, addr + WIN_REMAP_LO_OFF);
  77. writel(0, addr + WIN_REMAP_HI_OFF);
  78. }
  79. }
  80. /*
  81. * Configure a number of windows.
  82. */
  83. static void __init orion_setup_cpu_wins(const struct orion_addr_map_cfg * cfg,
  84. const struct orion_addr_map_info *info)
  85. {
  86. while (info->win != -1) {
  87. orion_setup_cpu_win(cfg, info->win, info->base, info->size,
  88. info->target, info->attr, info->remap);
  89. info++;
  90. }
  91. }
  92. static void __init orion_disable_wins(const struct orion_addr_map_cfg * cfg)
  93. {
  94. void __iomem *addr;
  95. int i;
  96. for (i = 0; i < cfg->num_wins; i++) {
  97. addr = cfg->win_cfg_base(cfg, i);
  98. writel(0, addr + WIN_BASE_OFF);
  99. writel(0, addr + WIN_CTRL_OFF);
  100. if (cfg->cpu_win_can_remap(cfg, i)) {
  101. writel(0, addr + WIN_REMAP_LO_OFF);
  102. writel(0, addr + WIN_REMAP_HI_OFF);
  103. }
  104. }
  105. }
  106. /*
  107. * Disable, clear and configure windows.
  108. */
  109. void __init orion_config_wins(struct orion_addr_map_cfg * cfg,
  110. const struct orion_addr_map_info *info)
  111. {
  112. if (!cfg->cpu_win_can_remap)
  113. cfg->cpu_win_can_remap = orion_cpu_win_can_remap;
  114. if (!cfg->win_cfg_base)
  115. cfg->win_cfg_base = orion_win_cfg_base;
  116. orion_disable_wins(cfg);
  117. if (info)
  118. orion_setup_cpu_wins(cfg, info);
  119. }
  120. /*
  121. * Setup MBUS dram target info.
  122. */
  123. void __init orion_setup_cpu_mbus_target(const struct orion_addr_map_cfg *cfg,
  124. const u32 ddr_window_cpu_base)
  125. {
  126. void __iomem *addr;
  127. int i;
  128. int cs;
  129. orion_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  130. addr = (void __iomem *)ddr_window_cpu_base;
  131. for (i = 0, cs = 0; i < 4; i++) {
  132. u32 base = readl(addr + DDR_BASE_CS_OFF(i));
  133. u32 size = readl(addr + DDR_SIZE_CS_OFF(i));
  134. /*
  135. * Chip select enabled?
  136. */
  137. if (size & 1) {
  138. struct mbus_dram_window *w;
  139. w = &orion_mbus_dram_info.cs[cs++];
  140. w->cs_index = i;
  141. w->mbus_attr = 0xf & ~(1 << i);
  142. w->base = base & 0xffff0000;
  143. w->size = (size | 0x0000ffff) + 1;
  144. }
  145. }
  146. orion_mbus_dram_info.num_cs = cs;
  147. }