2 * arch/arm/mach-orion/addr-map.c
4 * Address map functions for Marvell Orion System On Chip
6 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
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.
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/mbus.h>
16 #include <asm/hardware.h>
20 * The Orion has fully programable address map. There's a separate address
21 * map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIE, USB,
22 * Gigabit Ethernet, DMA/XOR engines, etc. Each interface has its own
23 * address decode windows that allow it to access any of the Orion resources.
25 * CPU address decoding --
26 * Linux assumes that it is the boot loader that already setup the access to
27 * DDR and internal registers.
28 * Setup access to PCI and PCI-E IO/MEM space is issued by core.c.
29 * Setup access to various devices located on the device bus interface (e.g.
30 * flashes, RTC, etc) should be issued by machine-setup.c according to
31 * specific board population (by using orion_setup_cpu_win()).
33 * Non-CPU Masters address decoding --
34 * Unlike the CPU, we setup the access from Orion's master interfaces to DDR
35 * banks only (the typical use case).
36 * Setup access for each master to DDR is issued by common.c.
38 * Note: although orion_setbits() and orion_clrbits() are not atomic
39 * no locking is necessary here since code in this file is only called
40 * at boot time when there is no concurrency issues.
44 * Generic Address Decode Windows bit settings
49 #define TARGET_DEV_BUS 1
50 #define ATTR_DDR_CS(n) (((n) ==0) ? 0xe : \
53 ((n) == 3) ? 0x7 : 0xf)
54 #define ATTR_PCIE_MEM 0x59
55 #define ATTR_PCIE_IO 0x51
56 #define ATTR_PCI_MEM 0x59
57 #define ATTR_PCI_IO 0x51
58 #define ATTR_DEV_CS0 0x1e
59 #define ATTR_DEV_CS1 0x1d
60 #define ATTR_DEV_CS2 0x1b
61 #define ATTR_DEV_BOOT 0xf
65 * Helpers to get DDR banks info
67 #define DDR_BASE_CS(n) ORION_DDR_REG(0x1500 + ((n) * 8))
68 #define DDR_SIZE_CS(n) ORION_DDR_REG(0x1504 + ((n) * 8))
70 #define DDR_REG_TO_SIZE(reg) (((reg) | 0xffffff) + 1)
71 #define DDR_REG_TO_BASE(reg) ((reg) & 0xff000000)
75 * CPU Address Decode Windows registers
77 #define CPU_WIN_CTRL(n) ORION_BRIDGE_REG(0x000 | ((n) << 4))
78 #define CPU_WIN_BASE(n) ORION_BRIDGE_REG(0x004 | ((n) << 4))
79 #define CPU_WIN_REMAP_LO(n) ORION_BRIDGE_REG(0x008 | ((n) << 4))
80 #define CPU_WIN_REMAP_HI(n) ORION_BRIDGE_REG(0x00c | ((n) << 4))
84 * Use this CPU address decode windows allocation
86 #define CPU_WIN_PCIE_IO 0
87 #define CPU_WIN_PCI_IO 1
88 #define CPU_WIN_PCIE_MEM 2
89 #define CPU_WIN_PCI_MEM 3
90 #define CPU_WIN_DEV_BOOT 4
91 #define CPU_WIN_DEV_CS0 5
92 #define CPU_WIN_DEV_CS1 6
93 #define CPU_WIN_DEV_CS2 7
96 * Gigabit Ethernet Address Decode Windows registers
98 #define ETH_WIN_BASE(win) ORION_ETH_REG(0x200 + ((win) * 8))
99 #define ETH_WIN_SIZE(win) ORION_ETH_REG(0x204 + ((win) * 8))
100 #define ETH_WIN_REMAP(win) ORION_ETH_REG(0x280 + ((win) * 4))
101 #define ETH_WIN_EN ORION_ETH_REG(0x290)
102 #define ETH_WIN_PROT ORION_ETH_REG(0x294)
103 #define ETH_MAX_WIN 6
104 #define ETH_MAX_REMAP_WIN 4
107 struct mbus_dram_target_info orion_mbus_dram_info
;
109 static int __init
orion_cpu_win_can_remap(u32 win
)
113 orion_pcie_id(&dev
, &rev
);
114 if ((dev
== MV88F5281_DEV_ID
&& win
< 4)
115 || (dev
== MV88F5182_DEV_ID
&& win
< 2)
116 || (dev
== MV88F5181_DEV_ID
&& win
< 2))
122 void __init
orion_setup_cpu_win(enum orion_target target
, u32 base
, u32 size
, int remap
)
128 target
= TARGET_PCIE
;
130 win
= CPU_WIN_PCIE_IO
;
135 win
= CPU_WIN_PCI_IO
;
138 target
= TARGET_PCIE
;
139 attr
= ATTR_PCIE_MEM
;
140 win
= CPU_WIN_PCIE_MEM
;
145 win
= CPU_WIN_PCI_MEM
;
148 target
= TARGET_DEV_BUS
;
149 attr
= ATTR_DEV_BOOT
;
150 win
= CPU_WIN_DEV_BOOT
;
153 target
= TARGET_DEV_BUS
;
155 win
= CPU_WIN_DEV_CS0
;
158 target
= TARGET_DEV_BUS
;
160 win
= CPU_WIN_DEV_CS1
;
163 target
= TARGET_DEV_BUS
;
165 win
= CPU_WIN_DEV_CS2
;
170 * Must be mapped by bootloader.
173 target
= attr
= win
= -1;
178 ctrl
= (((size
- 1) & 0xffff0000) | (attr
<< 8) |
179 (target
<< 4) | WIN_EN
);
181 orion_write(CPU_WIN_BASE(win
), base
);
182 orion_write(CPU_WIN_CTRL(win
), ctrl
);
184 if (orion_cpu_win_can_remap(win
)) {
186 orion_write(CPU_WIN_REMAP_LO(win
), remap
& 0xffff0000);
187 orion_write(CPU_WIN_REMAP_HI(win
), 0);
189 orion_write(CPU_WIN_REMAP_LO(win
), base
);
190 orion_write(CPU_WIN_REMAP_HI(win
), 0);
195 void __init
orion_setup_cpu_wins(void)
201 * First, disable and clear windows
203 for (i
= 0; i
< CPU_MAX_WIN
; i
++) {
204 orion_write(CPU_WIN_BASE(i
), 0);
205 orion_write(CPU_WIN_CTRL(i
), 0);
206 if (orion_cpu_win_can_remap(i
)) {
207 orion_write(CPU_WIN_REMAP_LO(i
), 0);
208 orion_write(CPU_WIN_REMAP_HI(i
), 0);
213 * Setup windows for PCI+PCIe IO+MEM space.
215 orion_setup_cpu_win(ORION_PCIE_IO
, ORION_PCIE_IO_PHYS_BASE
,
216 ORION_PCIE_IO_SIZE
, ORION_PCIE_IO_BUS_BASE
);
217 orion_setup_cpu_win(ORION_PCI_IO
, ORION_PCI_IO_PHYS_BASE
,
218 ORION_PCI_IO_SIZE
, ORION_PCI_IO_BUS_BASE
);
219 orion_setup_cpu_win(ORION_PCIE_MEM
, ORION_PCIE_MEM_PHYS_BASE
,
220 ORION_PCIE_MEM_SIZE
, -1);
221 orion_setup_cpu_win(ORION_PCI_MEM
, ORION_PCI_MEM_PHYS_BASE
,
222 ORION_PCI_MEM_SIZE
, -1);
225 * Setup MBUS dram target info.
227 orion_mbus_dram_info
.mbus_dram_target_id
= TARGET_DDR
;
229 for (i
= 0, cs
= 0; i
< 4; i
++) {
230 u32 base
= readl(DDR_BASE_CS(i
));
231 u32 size
= readl(DDR_SIZE_CS(i
));
234 * Chip select enabled?
237 struct mbus_dram_window
*w
;
239 w
= &orion_mbus_dram_info
.cs
[cs
++];
241 w
->mbus_attr
= 0xf & ~(1 << i
);
242 w
->base
= base
& 0xff000000;
243 w
->size
= (size
| 0x00ffffff) + 1;
246 orion_mbus_dram_info
.num_cs
= cs
;
249 void __init
orion_setup_eth_wins(void)
254 * First, disable and clear windows
256 for (i
= 0; i
< ETH_MAX_WIN
; i
++) {
257 orion_write(ETH_WIN_BASE(i
), 0);
258 orion_write(ETH_WIN_SIZE(i
), 0);
259 orion_setbits(ETH_WIN_EN
, 1 << i
);
260 orion_clrbits(ETH_WIN_PROT
, 0x3 << (i
* 2));
261 if (i
< ETH_MAX_REMAP_WIN
)
262 orion_write(ETH_WIN_REMAP(i
), 0);
266 * Setup windows for DDR banks.
268 for (i
= 0; i
< DDR_MAX_CS
; i
++) {
270 size
= orion_read(DDR_SIZE_CS(i
));
271 base
= orion_read(DDR_BASE_CS(i
));
272 if (size
& DDR_BANK_EN
) {
273 base
= DDR_REG_TO_BASE(base
);
274 size
= DDR_REG_TO_SIZE(size
);
275 orion_write(ETH_WIN_SIZE(i
), (size
-1) & 0xffff0000);
276 orion_write(ETH_WIN_BASE(i
), (base
& 0xffff0000) |
277 (ATTR_DDR_CS(i
) << 8) |
279 orion_clrbits(ETH_WIN_EN
, 1 << i
);
280 orion_setbits(ETH_WIN_PROT
, 0x3 << (i
* 2));