Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / arm / mach-orion / addr-map.c
blob4c45a0dfcffcda947b1c4a7a7207f782d0701b0b
1 /*
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 <asm/hardware.h>
16 #include "common.h"
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.
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 PCI-E IO/MEM space is issued by core.c.
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 orion_setup_cpu_win()).
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 common.c.
37 * Note: although orion_setbits() and orion_clrbits() are not atomic
38 * no locking is necessary here since code in this file is only called
39 * at boot time when there is no concurrency issues.
43 * Generic Address Decode Windows bit settings
45 #define TARGET_DDR 0
46 #define TARGET_PCI 3
47 #define TARGET_PCIE 4
48 #define TARGET_DEV_BUS 1
49 #define ATTR_DDR_CS(n) (((n) ==0) ? 0xe : \
50 ((n) == 1) ? 0xd : \
51 ((n) == 2) ? 0xb : \
52 ((n) == 3) ? 0x7 : 0xf)
53 #define ATTR_PCIE_MEM 0x59
54 #define ATTR_PCIE_IO 0x51
55 #define ATTR_PCI_MEM 0x59
56 #define ATTR_PCI_IO 0x51
57 #define ATTR_DEV_CS0 0x1e
58 #define ATTR_DEV_CS1 0x1d
59 #define ATTR_DEV_CS2 0x1b
60 #define ATTR_DEV_BOOT 0xf
61 #define WIN_EN 1
64 * Helpers to get DDR banks info
66 #define DDR_BASE_CS(n) ORION_DDR_REG(0x1500 + ((n) * 8))
67 #define DDR_SIZE_CS(n) ORION_DDR_REG(0x1504 + ((n) * 8))
68 #define DDR_MAX_CS 4
69 #define DDR_REG_TO_SIZE(reg) (((reg) | 0xffffff) + 1)
70 #define DDR_REG_TO_BASE(reg) ((reg) & 0xff000000)
71 #define DDR_BANK_EN 1
74 * CPU Address Decode Windows registers
76 #define CPU_WIN_CTRL(n) ORION_BRIDGE_REG(0x000 | ((n) << 4))
77 #define CPU_WIN_BASE(n) ORION_BRIDGE_REG(0x004 | ((n) << 4))
78 #define CPU_WIN_REMAP_LO(n) ORION_BRIDGE_REG(0x008 | ((n) << 4))
79 #define CPU_WIN_REMAP_HI(n) ORION_BRIDGE_REG(0x00c | ((n) << 4))
80 #define CPU_MAX_WIN 8
83 * Use this CPU address decode windows allocation
85 #define CPU_WIN_PCIE_IO 0
86 #define CPU_WIN_PCI_IO 1
87 #define CPU_WIN_PCIE_MEM 2
88 #define CPU_WIN_PCI_MEM 3
89 #define CPU_WIN_DEV_BOOT 4
90 #define CPU_WIN_DEV_CS0 5
91 #define CPU_WIN_DEV_CS1 6
92 #define CPU_WIN_DEV_CS2 7
95 * PCIE Address Decode Windows registers
97 #define PCIE_BAR_CTRL(n) ORION_PCIE_REG(0x1804 + ((n - 1) * 4))
98 #define PCIE_BAR_LO(n) ORION_PCIE_REG(0x0010 + ((n) * 8))
99 #define PCIE_BAR_HI(n) ORION_PCIE_REG(0x0014 + ((n) * 8))
100 <<<<<<< HEAD:arch/arm/mach-orion/addr-map.c
101 #define PCIE_WIN_CTRL(n) ORION_PCIE_REG(0x1820 + ((n) << 4))
102 #define PCIE_WIN_BASE(n) ORION_PCIE_REG(0x1824 + ((n) << 4))
103 #define PCIE_WIN_REMAP(n) ORION_PCIE_REG(0x182c + ((n) << 4))
104 =======
105 #define PCIE_WIN_CTRL(n) (((n) < 5) ? \
106 ORION_PCIE_REG(0x1820 + ((n) << 4)) : \
107 ORION_PCIE_REG(0x1880))
108 #define PCIE_WIN_BASE(n) (((n) < 5) ? \
109 ORION_PCIE_REG(0x1824 + ((n) << 4)) : \
110 ORION_PCIE_REG(0x1884))
111 #define PCIE_WIN_REMAP(n) (((n) < 5) ? \
112 ORION_PCIE_REG(0x182c + ((n) << 4)) : \
113 ORION_PCIE_REG(0x188c))
114 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/arm/mach-orion/addr-map.c
115 #define PCIE_DEFWIN_CTRL ORION_PCIE_REG(0x18b0)
116 #define PCIE_EXPROM_WIN_CTRL ORION_PCIE_REG(0x18c0)
117 #define PCIE_EXPROM_WIN_REMP ORION_PCIE_REG(0x18c4)
118 #define PCIE_MAX_BARS 3
119 <<<<<<< HEAD:arch/arm/mach-orion/addr-map.c
120 #define PCIE_MAX_WINS 5
121 =======
122 #define PCIE_MAX_WINS 6
123 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/arm/mach-orion/addr-map.c
126 * Use PCIE BAR '1' for all DDR banks
128 #define PCIE_DRAM_BAR 1
131 * PCI Address Decode Windows registers
133 #define PCI_BAR_SIZE_DDR_CS(n) (((n) == 0) ? ORION_PCI_REG(0xc08) : \
134 ((n) == 1) ? ORION_PCI_REG(0xd08) : \
135 ((n) == 2) ? ORION_PCI_REG(0xc0c) : \
136 ((n) == 3) ? ORION_PCI_REG(0xd0c) : 0)
137 #define PCI_BAR_REMAP_DDR_CS(n) (((n) ==0) ? ORION_PCI_REG(0xc48) : \
138 ((n) == 1) ? ORION_PCI_REG(0xd48) : \
139 ((n) == 2) ? ORION_PCI_REG(0xc4c) : \
140 ((n) == 3) ? ORION_PCI_REG(0xd4c) : 0)
141 #define PCI_BAR_ENABLE ORION_PCI_REG(0xc3c)
142 #define PCI_CTRL_BASE_LO(n) ORION_PCI_REG(0x1e00 | ((n) << 4))
143 #define PCI_CTRL_BASE_HI(n) ORION_PCI_REG(0x1e04 | ((n) << 4))
144 #define PCI_CTRL_SIZE(n) ORION_PCI_REG(0x1e08 | ((n) << 4))
145 #define PCI_ADDR_DECODE_CTRL ORION_PCI_REG(0xd3c)
148 * PCI configuration heleprs for BAR settings
150 #define PCI_CONF_FUNC_BAR_CS(n) ((n) >> 1)
151 #define PCI_CONF_REG_BAR_LO_CS(n) (((n) & 1) ? 0x18 : 0x10)
152 #define PCI_CONF_REG_BAR_HI_CS(n) (((n) & 1) ? 0x1c : 0x14)
155 * Gigabit Ethernet Address Decode Windows registers
157 #define ETH_WIN_BASE(win) ORION_ETH_REG(0x200 + ((win) * 8))
158 #define ETH_WIN_SIZE(win) ORION_ETH_REG(0x204 + ((win) * 8))
159 #define ETH_WIN_REMAP(win) ORION_ETH_REG(0x280 + ((win) * 4))
160 #define ETH_WIN_EN ORION_ETH_REG(0x290)
161 #define ETH_WIN_PROT ORION_ETH_REG(0x294)
162 #define ETH_MAX_WIN 6
163 #define ETH_MAX_REMAP_WIN 4
166 * USB Address Decode Windows registers
168 #define USB_WIN_CTRL(i, w) ((i == 0) ? ORION_USB0_REG(0x320 + ((w) << 4)) \
169 : ORION_USB1_REG(0x320 + ((w) << 4)))
170 #define USB_WIN_BASE(i, w) ((i == 0) ? ORION_USB0_REG(0x324 + ((w) << 4)) \
171 : ORION_USB1_REG(0x324 + ((w) << 4)))
172 #define USB_MAX_WIN 4
175 * SATA Address Decode Windows registers
177 #define SATA_WIN_CTRL(win) ORION_SATA_REG(0x30 + ((win) * 0x10))
178 #define SATA_WIN_BASE(win) ORION_SATA_REG(0x34 + ((win) * 0x10))
179 #define SATA_MAX_WIN 4
181 static int __init orion_cpu_win_can_remap(u32 win)
183 u32 dev, rev;
185 orion_pcie_id(&dev, &rev);
186 if ((dev == MV88F5281_DEV_ID && win < 4)
187 || (dev == MV88F5182_DEV_ID && win < 2)
188 || (dev == MV88F5181_DEV_ID && win < 2))
189 return 1;
191 return 0;
194 void __init orion_setup_cpu_win(enum orion_target target, u32 base, u32 size, int remap)
196 u32 win, attr, ctrl;
198 switch (target) {
199 case ORION_PCIE_IO:
200 target = TARGET_PCIE;
201 attr = ATTR_PCIE_IO;
202 win = CPU_WIN_PCIE_IO;
203 break;
204 case ORION_PCI_IO:
205 target = TARGET_PCI;
206 attr = ATTR_PCI_IO;
207 win = CPU_WIN_PCI_IO;
208 break;
209 case ORION_PCIE_MEM:
210 target = TARGET_PCIE;
211 attr = ATTR_PCIE_MEM;
212 win = CPU_WIN_PCIE_MEM;
213 break;
214 case ORION_PCI_MEM:
215 target = TARGET_PCI;
216 attr = ATTR_PCI_MEM;
217 win = CPU_WIN_PCI_MEM;
218 break;
219 case ORION_DEV_BOOT:
220 target = TARGET_DEV_BUS;
221 attr = ATTR_DEV_BOOT;
222 win = CPU_WIN_DEV_BOOT;
223 break;
224 case ORION_DEV0:
225 target = TARGET_DEV_BUS;
226 attr = ATTR_DEV_CS0;
227 win = CPU_WIN_DEV_CS0;
228 break;
229 case ORION_DEV1:
230 target = TARGET_DEV_BUS;
231 attr = ATTR_DEV_CS1;
232 win = CPU_WIN_DEV_CS1;
233 break;
234 case ORION_DEV2:
235 target = TARGET_DEV_BUS;
236 attr = ATTR_DEV_CS2;
237 win = CPU_WIN_DEV_CS2;
238 break;
239 case ORION_DDR:
240 case ORION_REGS:
242 * Must be mapped by bootloader.
244 default:
245 target = attr = win = -1;
246 BUG();
249 base &= 0xffff0000;
250 ctrl = (((size - 1) & 0xffff0000) | (attr << 8) |
251 (target << 4) | WIN_EN);
253 orion_write(CPU_WIN_BASE(win), base);
254 orion_write(CPU_WIN_CTRL(win), ctrl);
256 if (orion_cpu_win_can_remap(win)) {
257 if (remap >= 0) {
258 orion_write(CPU_WIN_REMAP_LO(win), remap & 0xffff0000);
259 orion_write(CPU_WIN_REMAP_HI(win), 0);
260 } else {
261 orion_write(CPU_WIN_REMAP_LO(win), base);
262 orion_write(CPU_WIN_REMAP_HI(win), 0);
267 void __init orion_setup_cpu_wins(void)
269 int i;
272 * First, disable and clear windows
274 for (i = 0; i < CPU_MAX_WIN; i++) {
275 orion_write(CPU_WIN_BASE(i), 0);
276 orion_write(CPU_WIN_CTRL(i), 0);
277 if (orion_cpu_win_can_remap(i)) {
278 orion_write(CPU_WIN_REMAP_LO(i), 0);
279 orion_write(CPU_WIN_REMAP_HI(i), 0);
284 * Setup windows for PCI+PCIe IO+MEM space.
286 orion_setup_cpu_win(ORION_PCIE_IO, ORION_PCIE_IO_PHYS_BASE,
287 ORION_PCIE_IO_SIZE, ORION_PCIE_IO_BUS_BASE);
288 orion_setup_cpu_win(ORION_PCI_IO, ORION_PCI_IO_PHYS_BASE,
289 ORION_PCI_IO_SIZE, ORION_PCI_IO_BUS_BASE);
290 orion_setup_cpu_win(ORION_PCIE_MEM, ORION_PCIE_MEM_PHYS_BASE,
291 ORION_PCIE_MEM_SIZE, -1);
292 orion_setup_cpu_win(ORION_PCI_MEM, ORION_PCI_MEM_PHYS_BASE,
293 ORION_PCI_MEM_SIZE, -1);
297 * Setup PCIE BARs and Address Decode Wins:
298 * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
299 * WIN[0-3] -> DRAM bank[0-3]
301 void __init orion_setup_pcie_wins(void)
303 u32 base, size, i;
306 * First, disable and clear BARs and windows
308 for (i = 1; i < PCIE_MAX_BARS; i++) {
309 orion_write(PCIE_BAR_CTRL(i), 0);
310 orion_write(PCIE_BAR_LO(i), 0);
311 orion_write(PCIE_BAR_HI(i), 0);
314 for (i = 0; i < PCIE_MAX_WINS; i++) {
315 orion_write(PCIE_WIN_CTRL(i), 0);
316 orion_write(PCIE_WIN_BASE(i), 0);
317 orion_write(PCIE_WIN_REMAP(i), 0);
321 * Setup windows for DDR banks. Count total DDR size on the fly.
323 base = DDR_REG_TO_BASE(orion_read(DDR_BASE_CS(0)));
324 size = 0;
325 for (i = 0; i < DDR_MAX_CS; i++) {
326 u32 bank_base, bank_size;
327 bank_size = orion_read(DDR_SIZE_CS(i));
328 bank_base = orion_read(DDR_BASE_CS(i));
329 if (bank_size & DDR_BANK_EN) {
330 bank_size = DDR_REG_TO_SIZE(bank_size);
331 bank_base = DDR_REG_TO_BASE(bank_base);
332 orion_write(PCIE_WIN_BASE(i), bank_base & 0xffff0000);
333 orion_write(PCIE_WIN_REMAP(i), 0);
334 orion_write(PCIE_WIN_CTRL(i),
335 ((bank_size-1) & 0xffff0000) |
336 (ATTR_DDR_CS(i) << 8) |
337 (TARGET_DDR << 4) |
338 (PCIE_DRAM_BAR << 1) | WIN_EN);
339 size += bank_size;
344 * Setup BAR[1] to all DRAM banks
346 orion_write(PCIE_BAR_LO(PCIE_DRAM_BAR), base & 0xffff0000);
347 orion_write(PCIE_BAR_HI(PCIE_DRAM_BAR), 0);
348 orion_write(PCIE_BAR_CTRL(PCIE_DRAM_BAR),
349 ((size - 1) & 0xffff0000) | WIN_EN);
352 void __init orion_setup_pci_wins(void)
354 u32 base, size, i;
357 * First, disable windows
359 orion_write(PCI_BAR_ENABLE, 0xffffffff);
362 * Setup windows for DDR banks.
364 for (i = 0; i < DDR_MAX_CS; i++) {
365 base = orion_read(DDR_BASE_CS(i));
366 size = orion_read(DDR_SIZE_CS(i));
367 if (size & DDR_BANK_EN) {
368 u32 bus, dev, func, reg, val;
369 size = DDR_REG_TO_SIZE(size);
370 base = DDR_REG_TO_BASE(base);
371 bus = orion_pci_local_bus_nr();
372 dev = orion_pci_local_dev_nr();
373 func = PCI_CONF_FUNC_BAR_CS(i);
374 reg = PCI_CONF_REG_BAR_LO_CS(i);
375 orion_pci_hw_rd_conf(bus, dev, func, reg, 4, &val);
376 orion_pci_hw_wr_conf(bus, dev, func, reg, 4,
377 (base & 0xfffff000) | (val & 0xfff));
378 reg = PCI_CONF_REG_BAR_HI_CS(i);
379 orion_pci_hw_wr_conf(bus, dev, func, reg, 4, 0);
380 orion_write(PCI_BAR_SIZE_DDR_CS(i),
381 (size - 1) & 0xfffff000);
382 orion_write(PCI_BAR_REMAP_DDR_CS(i),
383 base & 0xfffff000);
384 orion_clrbits(PCI_BAR_ENABLE, (1 << i));
389 * Disable automatic update of address remaping when writing to BARs
391 orion_setbits(PCI_ADDR_DECODE_CTRL, 1);
394 void __init orion_setup_usb_wins(void)
396 int i;
397 u32 usb_if, dev, rev;
398 u32 max_usb_if = 1;
400 orion_pcie_id(&dev, &rev);
401 if (dev == MV88F5182_DEV_ID)
402 max_usb_if = 2;
404 for (usb_if = 0; usb_if < max_usb_if; usb_if++) {
406 * First, disable and clear windows
408 for (i = 0; i < USB_MAX_WIN; i++) {
409 orion_write(USB_WIN_BASE(usb_if, i), 0);
410 orion_write(USB_WIN_CTRL(usb_if, i), 0);
414 * Setup windows for DDR banks.
416 for (i = 0; i < DDR_MAX_CS; i++) {
417 u32 base, size;
418 size = orion_read(DDR_SIZE_CS(i));
419 base = orion_read(DDR_BASE_CS(i));
420 if (size & DDR_BANK_EN) {
421 base = DDR_REG_TO_BASE(base);
422 size = DDR_REG_TO_SIZE(size);
423 orion_write(USB_WIN_CTRL(usb_if, i),
424 ((size-1) & 0xffff0000) |
425 (ATTR_DDR_CS(i) << 8) |
426 (TARGET_DDR << 4) | WIN_EN);
427 orion_write(USB_WIN_BASE(usb_if, i),
428 base & 0xffff0000);
434 void __init orion_setup_eth_wins(void)
436 int i;
439 * First, disable and clear windows
441 for (i = 0; i < ETH_MAX_WIN; i++) {
442 orion_write(ETH_WIN_BASE(i), 0);
443 orion_write(ETH_WIN_SIZE(i), 0);
444 orion_setbits(ETH_WIN_EN, 1 << i);
445 orion_clrbits(ETH_WIN_PROT, 0x3 << (i * 2));
446 if (i < ETH_MAX_REMAP_WIN)
447 orion_write(ETH_WIN_REMAP(i), 0);
451 * Setup windows for DDR banks.
453 for (i = 0; i < DDR_MAX_CS; i++) {
454 u32 base, size;
455 size = orion_read(DDR_SIZE_CS(i));
456 base = orion_read(DDR_BASE_CS(i));
457 if (size & DDR_BANK_EN) {
458 base = DDR_REG_TO_BASE(base);
459 size = DDR_REG_TO_SIZE(size);
460 orion_write(ETH_WIN_SIZE(i), (size-1) & 0xffff0000);
461 orion_write(ETH_WIN_BASE(i), (base & 0xffff0000) |
462 (ATTR_DDR_CS(i) << 8) |
463 TARGET_DDR);
464 orion_clrbits(ETH_WIN_EN, 1 << i);
465 orion_setbits(ETH_WIN_PROT, 0x3 << (i * 2));
470 void __init orion_setup_sata_wins(void)
472 int i;
475 * First, disable and clear windows
477 for (i = 0; i < SATA_MAX_WIN; i++) {
478 orion_write(SATA_WIN_BASE(i), 0);
479 orion_write(SATA_WIN_CTRL(i), 0);
483 * Setup windows for DDR banks.
485 for (i = 0; i < DDR_MAX_CS; i++) {
486 u32 base, size;
487 size = orion_read(DDR_SIZE_CS(i));
488 base = orion_read(DDR_BASE_CS(i));
489 if (size & DDR_BANK_EN) {
490 base = DDR_REG_TO_BASE(base);
491 size = DDR_REG_TO_SIZE(size);
492 orion_write(SATA_WIN_CTRL(i),
493 ((size-1) & 0xffff0000) |
494 (ATTR_DDR_CS(i) << 8) |
495 (TARGET_DDR << 4) | WIN_EN);
496 orion_write(SATA_WIN_BASE(i),
497 base & 0xffff0000);