addr-map.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * arch/arm/mach-orion5x/addr-map.c
  3. *
  4. * Address map functions for Marvell Orion 5x SoCs
  5. *
  6. * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/mbus.h>
  15. #include <asm/hardware.h>
  16. #include <asm/io.h>
  17. #include "common.h"
  18. /*
  19. * The Orion has fully programable address map. There's a separate address
  20. * map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIe, USB,
  21. * Gigabit Ethernet, DMA/XOR engines, etc. Each interface has its own
  22. * address decode windows that allow it to access any of the Orion resources.
  23. *
  24. * CPU address decoding --
  25. * Linux assumes that it is the boot loader that already setup the access to
  26. * DDR and internal registers.
  27. * Setup access to PCI and PCIe IO/MEM space is issued by this file.
  28. * Setup access to various devices located on the device bus interface (e.g.
  29. * flashes, RTC, etc) should be issued by machine-setup.c according to
  30. * specific board population (by using orion5x_setup_*_win()).
  31. *
  32. * Non-CPU Masters address decoding --
  33. * Unlike the CPU, we setup the access from Orion's master interfaces to DDR
  34. * banks only (the typical use case).
  35. * Setup access for each master to DDR is issued by platform device setup.
  36. */
  37. /*
  38. * Generic Address Decode Windows bit settings
  39. */
  40. #define TARGET_DDR 0
  41. #define TARGET_DEV_BUS 1
  42. #define TARGET_PCI 3
  43. #define TARGET_PCIE 4
  44. #define ATTR_PCIE_MEM 0x59
  45. #define ATTR_PCIE_IO 0x51
  46. #define ATTR_PCIE_WA 0x79
  47. #define ATTR_PCI_MEM 0x59
  48. #define ATTR_PCI_IO 0x51
  49. #define ATTR_DEV_CS0 0x1e
  50. #define ATTR_DEV_CS1 0x1d
  51. #define ATTR_DEV_CS2 0x1b
  52. #define ATTR_DEV_BOOT 0xf
  53. /*
  54. * Helpers to get DDR bank info
  55. */
  56. #define DDR_BASE_CS(n) ORION5X_DDR_REG(0x1500 + ((n) << 3))
  57. #define DDR_SIZE_CS(n) ORION5X_DDR_REG(0x1504 + ((n) << 3))
  58. /*
  59. * CPU Address Decode Windows registers
  60. */
  61. #define CPU_WIN_CTRL(n) ORION5X_BRIDGE_REG(0x000 | ((n) << 4))
  62. #define CPU_WIN_BASE(n) ORION5X_BRIDGE_REG(0x004 | ((n) << 4))
  63. #define CPU_WIN_REMAP_LO(n) ORION5X_BRIDGE_REG(0x008 | ((n) << 4))
  64. #define CPU_WIN_REMAP_HI(n) ORION5X_BRIDGE_REG(0x00c | ((n) << 4))
  65. struct mbus_dram_target_info orion5x_mbus_dram_info;
  66. static int __init orion5x_cpu_win_can_remap(int win)
  67. {
  68. u32 dev, rev;
  69. orion5x_pcie_id(&dev, &rev);
  70. if ((dev == MV88F5281_DEV_ID && win < 4)
  71. || (dev == MV88F5182_DEV_ID && win < 2)
  72. || (dev == MV88F5181_DEV_ID && win < 2))
  73. return 1;
  74. return 0;
  75. }
  76. static void __init setup_cpu_win(int win, u32 base, u32 size,
  77. u8 target, u8 attr, int remap)
  78. {
  79. orion5x_write(CPU_WIN_BASE(win), base & 0xffff0000);
  80. orion5x_write(CPU_WIN_CTRL(win),
  81. ((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1);
  82. if (orion5x_cpu_win_can_remap(win)) {
  83. if (remap < 0)
  84. remap = base;
  85. orion5x_write(CPU_WIN_REMAP_LO(win), remap & 0xffff0000);
  86. orion5x_write(CPU_WIN_REMAP_HI(win), 0);
  87. }
  88. }
  89. void __init orion5x_setup_cpu_mbus_bridge(void)
  90. {
  91. int i;
  92. int cs;
  93. /*
  94. * First, disable and clear windows.
  95. */
  96. for (i = 0; i < 8; i++) {
  97. orion5x_write(CPU_WIN_BASE(i), 0);
  98. orion5x_write(CPU_WIN_CTRL(i), 0);
  99. if (orion5x_cpu_win_can_remap(i)) {
  100. orion5x_write(CPU_WIN_REMAP_LO(i), 0);
  101. orion5x_write(CPU_WIN_REMAP_HI(i), 0);
  102. }
  103. }
  104. /*
  105. * Setup windows for PCI+PCIe IO+MEM space.
  106. */
  107. setup_cpu_win(0, ORION5X_PCIE_IO_PHYS_BASE, ORION5X_PCIE_IO_SIZE,
  108. TARGET_PCIE, ATTR_PCIE_IO, ORION5X_PCIE_IO_BUS_BASE);
  109. setup_cpu_win(1, ORION5X_PCI_IO_PHYS_BASE, ORION5X_PCI_IO_SIZE,
  110. TARGET_PCI, ATTR_PCI_IO, ORION5X_PCI_IO_BUS_BASE);
  111. setup_cpu_win(2, ORION5X_PCIE_MEM_PHYS_BASE, ORION5X_PCIE_MEM_SIZE,
  112. TARGET_PCIE, ATTR_PCIE_MEM, -1);
  113. setup_cpu_win(3, ORION5X_PCI_MEM_PHYS_BASE, ORION5X_PCI_MEM_SIZE,
  114. TARGET_PCI, ATTR_PCI_MEM, -1);
  115. /*
  116. * Setup MBUS dram target info.
  117. */
  118. orion5x_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  119. for (i = 0, cs = 0; i < 4; i++) {
  120. u32 base = readl(DDR_BASE_CS(i));
  121. u32 size = readl(DDR_SIZE_CS(i));
  122. /*
  123. * Chip select enabled?
  124. */
  125. if (size & 1) {
  126. struct mbus_dram_window *w;
  127. w = &orion5x_mbus_dram_info.cs[cs++];
  128. w->cs_index = i;
  129. w->mbus_attr = 0xf & ~(1 << i);
  130. w->base = base & 0xff000000;
  131. w->size = (size | 0x00ffffff) + 1;
  132. }
  133. }
  134. orion5x_mbus_dram_info.num_cs = cs;
  135. }
  136. void __init orion5x_setup_dev_boot_win(u32 base, u32 size)
  137. {
  138. setup_cpu_win(4, base, size, TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);
  139. }
  140. void __init orion5x_setup_dev0_win(u32 base, u32 size)
  141. {
  142. setup_cpu_win(5, base, size, TARGET_DEV_BUS, ATTR_DEV_CS0, -1);
  143. }
  144. void __init orion5x_setup_dev1_win(u32 base, u32 size)
  145. {
  146. setup_cpu_win(6, base, size, TARGET_DEV_BUS, ATTR_DEV_CS1, -1);
  147. }
  148. void __init orion5x_setup_dev2_win(u32 base, u32 size)
  149. {
  150. setup_cpu_win(7, base, size, TARGET_DEV_BUS, ATTR_DEV_CS2, -1);
  151. }
  152. void __init orion5x_setup_pcie_wa_win(u32 base, u32 size)
  153. {
  154. setup_cpu_win(7, base, size, TARGET_PCIE, ATTR_PCIE_WA, -1);
  155. }