addr-map.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * arch/arm/mach-kirkwood/addr-map.c
  3. *
  4. * Address map functions for Marvell Kirkwood 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 <mach/hardware.h>
  15. #include "common.h"
  16. /*
  17. * Generic Address Decode Windows bit settings
  18. */
  19. #define TARGET_DDR 0
  20. #define TARGET_DEV_BUS 1
  21. #define TARGET_SRAM 3
  22. #define TARGET_PCIE 4
  23. #define ATTR_DEV_SPI_ROM 0x1e
  24. #define ATTR_DEV_BOOT 0x1d
  25. #define ATTR_DEV_NAND 0x2f
  26. #define ATTR_DEV_CS3 0x37
  27. #define ATTR_DEV_CS2 0x3b
  28. #define ATTR_DEV_CS1 0x3d
  29. #define ATTR_DEV_CS0 0x3e
  30. #define ATTR_PCIE_IO 0xe0
  31. #define ATTR_PCIE_MEM 0xe8
  32. #define ATTR_PCIE1_IO 0xd0
  33. #define ATTR_PCIE1_MEM 0xd8
  34. #define ATTR_SRAM 0x01
  35. /*
  36. * Helpers to get DDR bank info
  37. */
  38. #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
  39. #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
  40. /*
  41. * CPU Address Decode Windows registers
  42. */
  43. #define WIN_OFF(n) (BRIDGE_VIRT_BASE + 0x0000 + ((n) << 4))
  44. #define WIN_CTRL_OFF 0x0000
  45. #define WIN_BASE_OFF 0x0004
  46. #define WIN_REMAP_LO_OFF 0x0008
  47. #define WIN_REMAP_HI_OFF 0x000c
  48. struct mbus_dram_target_info kirkwood_mbus_dram_info;
  49. static int __init cpu_win_can_remap(int win)
  50. {
  51. if (win < 4)
  52. return 1;
  53. return 0;
  54. }
  55. static void __init setup_cpu_win(int win, u32 base, u32 size,
  56. u8 target, u8 attr, int remap)
  57. {
  58. void __iomem *addr = (void __iomem *)WIN_OFF(win);
  59. u32 ctrl;
  60. base &= 0xffff0000;
  61. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1;
  62. writel(base, addr + WIN_BASE_OFF);
  63. writel(ctrl, addr + WIN_CTRL_OFF);
  64. if (cpu_win_can_remap(win)) {
  65. if (remap < 0)
  66. remap = base;
  67. writel(remap & 0xffff0000, addr + WIN_REMAP_LO_OFF);
  68. writel(0, addr + WIN_REMAP_HI_OFF);
  69. }
  70. }
  71. void __init kirkwood_setup_cpu_mbus(void)
  72. {
  73. void __iomem *addr;
  74. int i;
  75. int cs;
  76. /*
  77. * First, disable and clear windows.
  78. */
  79. for (i = 0; i < 8; i++) {
  80. addr = (void __iomem *)WIN_OFF(i);
  81. writel(0, addr + WIN_BASE_OFF);
  82. writel(0, addr + WIN_CTRL_OFF);
  83. if (cpu_win_can_remap(i)) {
  84. writel(0, addr + WIN_REMAP_LO_OFF);
  85. writel(0, addr + WIN_REMAP_HI_OFF);
  86. }
  87. }
  88. /*
  89. * Setup windows for PCIe IO+MEM space.
  90. */
  91. setup_cpu_win(0, KIRKWOOD_PCIE_IO_PHYS_BASE, KIRKWOOD_PCIE_IO_SIZE,
  92. TARGET_PCIE, ATTR_PCIE_IO, KIRKWOOD_PCIE_IO_BUS_BASE);
  93. setup_cpu_win(1, KIRKWOOD_PCIE_MEM_PHYS_BASE, KIRKWOOD_PCIE_MEM_SIZE,
  94. TARGET_PCIE, ATTR_PCIE_MEM, KIRKWOOD_PCIE_MEM_BUS_BASE);
  95. setup_cpu_win(2, KIRKWOOD_PCIE1_IO_PHYS_BASE, KIRKWOOD_PCIE1_IO_SIZE,
  96. TARGET_PCIE, ATTR_PCIE1_IO, KIRKWOOD_PCIE1_IO_BUS_BASE);
  97. setup_cpu_win(3, KIRKWOOD_PCIE1_MEM_PHYS_BASE, KIRKWOOD_PCIE1_MEM_SIZE,
  98. TARGET_PCIE, ATTR_PCIE1_MEM, KIRKWOOD_PCIE1_MEM_BUS_BASE);
  99. /*
  100. * Setup window for NAND controller.
  101. */
  102. setup_cpu_win(4, KIRKWOOD_NAND_MEM_PHYS_BASE, KIRKWOOD_NAND_MEM_SIZE,
  103. TARGET_DEV_BUS, ATTR_DEV_NAND, -1);
  104. /*
  105. * Setup window for SRAM.
  106. */
  107. setup_cpu_win(5, KIRKWOOD_SRAM_PHYS_BASE, KIRKWOOD_SRAM_SIZE,
  108. TARGET_SRAM, ATTR_SRAM, -1);
  109. /*
  110. * Setup MBUS dram target info.
  111. */
  112. kirkwood_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  113. addr = (void __iomem *)DDR_WINDOW_CPU_BASE;
  114. for (i = 0, cs = 0; i < 4; i++) {
  115. u32 base = readl(addr + DDR_BASE_CS_OFF(i));
  116. u32 size = readl(addr + DDR_SIZE_CS_OFF(i));
  117. /*
  118. * Chip select enabled?
  119. */
  120. if (size & 1) {
  121. struct mbus_dram_window *w;
  122. w = &kirkwood_mbus_dram_info.cs[cs++];
  123. w->cs_index = i;
  124. w->mbus_attr = 0xf & ~(1 << i);
  125. w->base = base & 0xffff0000;
  126. w->size = (size | 0x0000ffff) + 1;
  127. }
  128. }
  129. kirkwood_mbus_dram_info.num_cs = cs;
  130. }