addr-map.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * arch/arm/mach-dove/addr-map.c
  3. *
  4. * Address map functions for Marvell Dove 88AP510 SoC
  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 <asm/mach/arch.h>
  15. #include <asm/setup.h>
  16. #include "common.h"
  17. /*
  18. * Generic Address Decode Windows bit settings
  19. */
  20. #define TARGET_DDR 0x0
  21. #define TARGET_BOOTROM 0x1
  22. #define TARGET_CESA 0x3
  23. #define TARGET_PCIE0 0x4
  24. #define TARGET_PCIE1 0x8
  25. #define TARGET_SCRATCHPAD 0xd
  26. #define ATTR_CESA 0x01
  27. #define ATTR_BOOTROM 0xfd
  28. #define ATTR_DEV_SPI0_ROM 0xfe
  29. #define ATTR_DEV_SPI1_ROM 0xfb
  30. #define ATTR_PCIE_IO 0xe0
  31. #define ATTR_PCIE_MEM 0xe8
  32. #define ATTR_SCRATCHPAD 0x0
  33. /*
  34. * CPU Address Decode Windows registers
  35. */
  36. #define WIN_CTRL(n) (BRIDGE_VIRT_BASE + ((n) << 4) + 0x0)
  37. #define WIN_BASE(n) (BRIDGE_VIRT_BASE + ((n) << 4) + 0x4)
  38. #define WIN_REMAP_LO(n) (BRIDGE_VIRT_BASE + ((n) << 4) + 0x8)
  39. #define WIN_REMAP_HI(n) (BRIDGE_VIRT_BASE + ((n) << 4) + 0xc)
  40. struct mbus_dram_target_info dove_mbus_dram_info;
  41. static inline void __iomem *ddr_map_sc(int i)
  42. {
  43. return (void __iomem *)(DOVE_MC_VIRT_BASE + 0x100 + ((i) << 4));
  44. }
  45. static int cpu_win_can_remap(int win)
  46. {
  47. if (win < 4)
  48. return 1;
  49. return 0;
  50. }
  51. static void __init setup_cpu_win(int win, u32 base, u32 size,
  52. u8 target, u8 attr, int remap)
  53. {
  54. u32 ctrl;
  55. base &= 0xffff0000;
  56. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
  57. writel(base, WIN_BASE(win));
  58. writel(ctrl, WIN_CTRL(win));
  59. if (cpu_win_can_remap(win)) {
  60. if (remap < 0)
  61. remap = base;
  62. writel(remap & 0xffff0000, WIN_REMAP_LO(win));
  63. writel(0, WIN_REMAP_HI(win));
  64. }
  65. }
  66. void __init dove_setup_cpu_mbus(void)
  67. {
  68. int i;
  69. int cs;
  70. /*
  71. * First, disable and clear windows.
  72. */
  73. for (i = 0; i < 8; i++) {
  74. writel(0, WIN_BASE(i));
  75. writel(0, WIN_CTRL(i));
  76. if (cpu_win_can_remap(i)) {
  77. writel(0, WIN_REMAP_LO(i));
  78. writel(0, WIN_REMAP_HI(i));
  79. }
  80. }
  81. /*
  82. * Setup windows for PCIe IO+MEM space.
  83. */
  84. setup_cpu_win(0, DOVE_PCIE0_IO_PHYS_BASE, DOVE_PCIE0_IO_SIZE,
  85. TARGET_PCIE0, ATTR_PCIE_IO, DOVE_PCIE0_IO_BUS_BASE);
  86. setup_cpu_win(1, DOVE_PCIE1_IO_PHYS_BASE, DOVE_PCIE1_IO_SIZE,
  87. TARGET_PCIE1, ATTR_PCIE_IO, DOVE_PCIE1_IO_BUS_BASE);
  88. setup_cpu_win(2, DOVE_PCIE0_MEM_PHYS_BASE, DOVE_PCIE0_MEM_SIZE,
  89. TARGET_PCIE0, ATTR_PCIE_MEM, -1);
  90. setup_cpu_win(3, DOVE_PCIE1_MEM_PHYS_BASE, DOVE_PCIE1_MEM_SIZE,
  91. TARGET_PCIE1, ATTR_PCIE_MEM, -1);
  92. /*
  93. * Setup window for CESA engine.
  94. */
  95. setup_cpu_win(4, DOVE_CESA_PHYS_BASE, DOVE_CESA_SIZE,
  96. TARGET_CESA, ATTR_CESA, -1);
  97. /*
  98. * Setup the Window to the BootROM for Standby and Sleep Resume
  99. */
  100. setup_cpu_win(5, DOVE_BOOTROM_PHYS_BASE, DOVE_BOOTROM_SIZE,
  101. TARGET_BOOTROM, ATTR_BOOTROM, -1);
  102. /*
  103. * Setup the Window to the PMU Scratch Pad space
  104. */
  105. setup_cpu_win(6, DOVE_SCRATCHPAD_PHYS_BASE, DOVE_SCRATCHPAD_SIZE,
  106. TARGET_SCRATCHPAD, ATTR_SCRATCHPAD, -1);
  107. /*
  108. * Setup MBUS dram target info.
  109. */
  110. dove_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  111. for (i = 0, cs = 0; i < 2; i++) {
  112. u32 map = readl(ddr_map_sc(i));
  113. /*
  114. * Chip select enabled?
  115. */
  116. if (map & 1) {
  117. struct mbus_dram_window *w;
  118. w = &dove_mbus_dram_info.cs[cs++];
  119. w->cs_index = i;
  120. w->mbus_attr = 0; /* CS address decoding done inside */
  121. /* the DDR controller, no need to */
  122. /* provide attributes */
  123. w->base = map & 0xff800000;
  124. w->size = 0x100000 << (((map & 0x000f0000) >> 16) - 4);
  125. }
  126. }
  127. dove_mbus_dram_info.num_cs = cs;
  128. }