addr-map.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * arch/arm/mach-loki/addr-map.c
  3. *
  4. * Address map functions for Marvell Loki (88RC8480) 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_PCIE0 3
  22. #define TARGET_PCIE1 4
  23. #define ATTR_DEV_BOOT 0x0f
  24. #define ATTR_DEV_CS2 0x1b
  25. #define ATTR_DEV_CS1 0x1d
  26. #define ATTR_DEV_CS0 0x1e
  27. #define ATTR_PCIE_IO 0x51
  28. #define ATTR_PCIE_MEM 0x59
  29. /*
  30. * Helpers to get DDR bank info
  31. */
  32. #define DDR_SIZE_CS(n) DDR_REG(0x1500 + ((n) << 3))
  33. #define DDR_BASE_CS(n) DDR_REG(0x1504 + ((n) << 3))
  34. /*
  35. * CPU Address Decode Windows registers
  36. */
  37. #define BRIDGE_REG(x) (BRIDGE_VIRT_BASE | (x))
  38. #define CPU_WIN_CTRL(n) BRIDGE_REG(0x000 | ((n) << 4))
  39. #define CPU_WIN_BASE(n) BRIDGE_REG(0x004 | ((n) << 4))
  40. #define CPU_WIN_REMAP_LO(n) BRIDGE_REG(0x008 | ((n) << 4))
  41. #define CPU_WIN_REMAP_HI(n) BRIDGE_REG(0x00c | ((n) << 4))
  42. struct mbus_dram_target_info loki_mbus_dram_info;
  43. static void __init setup_cpu_win(int win, u32 base, u32 size,
  44. u8 target, u8 attr, int remap)
  45. {
  46. u32 ctrl;
  47. base &= 0xffff0000;
  48. ctrl = ((size - 1) & 0xffff0000) | (attr << 8) | (1 << 5) | target;
  49. writel(base, CPU_WIN_BASE(win));
  50. writel(ctrl, CPU_WIN_CTRL(win));
  51. if (win < 2) {
  52. if (remap < 0)
  53. remap = base;
  54. writel(remap & 0xffff0000, CPU_WIN_REMAP_LO(win));
  55. writel(0, CPU_WIN_REMAP_HI(win));
  56. }
  57. }
  58. void __init loki_setup_cpu_mbus(void)
  59. {
  60. int i;
  61. int cs;
  62. /*
  63. * First, disable and clear windows.
  64. */
  65. for (i = 0; i < 8; i++) {
  66. writel(0, CPU_WIN_BASE(i));
  67. writel(0, CPU_WIN_CTRL(i));
  68. if (i < 2) {
  69. writel(0, CPU_WIN_REMAP_LO(i));
  70. writel(0, CPU_WIN_REMAP_HI(i));
  71. }
  72. }
  73. /*
  74. * Setup windows for PCIe IO+MEM space.
  75. */
  76. setup_cpu_win(2, LOKI_PCIE0_MEM_PHYS_BASE, LOKI_PCIE0_MEM_SIZE,
  77. TARGET_PCIE0, ATTR_PCIE_MEM, -1);
  78. setup_cpu_win(3, LOKI_PCIE1_MEM_PHYS_BASE, LOKI_PCIE1_MEM_SIZE,
  79. TARGET_PCIE1, ATTR_PCIE_MEM, -1);
  80. /*
  81. * Setup MBUS dram target info.
  82. */
  83. loki_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;
  84. for (i = 0, cs = 0; i < 4; i++) {
  85. u32 base = readl(DDR_BASE_CS(i));
  86. u32 size = readl(DDR_SIZE_CS(i));
  87. /*
  88. * Chip select enabled?
  89. */
  90. if (size & 1) {
  91. struct mbus_dram_window *w;
  92. w = &loki_mbus_dram_info.cs[cs++];
  93. w->cs_index = i;
  94. w->mbus_attr = 0xf & ~(1 << i);
  95. w->base = base & 0xffff0000;
  96. w->size = (size | 0x0000ffff) + 1;
  97. }
  98. }
  99. loki_mbus_dram_info.num_cs = cs;
  100. }
  101. void __init loki_setup_dev_boot_win(u32 base, u32 size)
  102. {
  103. setup_cpu_win(4, base, size, TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);
  104. }