aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-orion/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-orion/pci.c')
-rw-r--r--arch/arm/mach-orion/pci.c343
1 files changed, 86 insertions, 257 deletions
diff --git a/arch/arm/mach-orion/pci.c b/arch/arm/mach-orion/pci.c
index cfd3d064c209..5240a245c7e4 100644
--- a/arch/arm/mach-orion/pci.c
+++ b/arch/arm/mach-orion/pci.c
@@ -14,6 +14,7 @@
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/mbus.h> 15#include <linux/mbus.h>
16#include <asm/mach/pci.h> 16#include <asm/mach/pci.h>
17#include <asm/plat-orion/pcie.h>
17#include "common.h" 18#include "common.h"
18 19
19/***************************************************************************** 20/*****************************************************************************
@@ -32,288 +33,136 @@
32/***************************************************************************** 33/*****************************************************************************
33 * PCIE controller 34 * PCIE controller
34 ****************************************************************************/ 35 ****************************************************************************/
35#define PCIE_CTRL ORION_PCIE_REG(0x1a00) 36#define PCIE_BASE ((void __iomem *)ORION_PCIE_VIRT_BASE)
36#define PCIE_STAT ORION_PCIE_REG(0x1a04)
37#define PCIE_DEV_ID ORION_PCIE_REG(0x0000)
38#define PCIE_CMD_STAT ORION_PCIE_REG(0x0004)
39#define PCIE_DEV_REV ORION_PCIE_REG(0x0008)
40#define PCIE_MASK ORION_PCIE_REG(0x1910)
41#define PCIE_CONF_ADDR ORION_PCIE_REG(0x18f8)
42#define PCIE_CONF_DATA ORION_PCIE_REG(0x18fc)
43
44/*
45 * PCIE_STAT bits
46 */
47#define PCIE_STAT_LINK_DOWN 1
48#define PCIE_STAT_BUS_OFFS 8
49#define PCIE_STAT_BUS_MASK (0xff << PCIE_STAT_BUS_OFFS)
50#define PCIE_STAT_DEV_OFFS 20
51#define PCIE_STAT_DEV_MASK (0x1f << PCIE_STAT_DEV_OFFS)
52
53/*
54 * PCIE_CONF_ADDR bits
55 */
56#define PCIE_CONF_REG(r) ((((r) & 0xf00) << 24) | ((r) & 0xfc))
57#define PCIE_CONF_FUNC(f) (((f) & 0x3) << 8)
58#define PCIE_CONF_DEV(d) (((d) & 0x1f) << 11)
59#define PCIE_CONF_BUS(b) (((b) & 0xff) << 16)
60#define PCIE_CONF_ADDR_EN (1 << 31)
61
62/*
63 * PCIE Address Decode Windows registers
64 */
65#define PCIE_BAR_CTRL(n) ORION_PCIE_REG(0x1804 + ((n - 1) * 4))
66#define PCIE_BAR_LO(n) ORION_PCIE_REG(0x0010 + ((n) * 8))
67#define PCIE_BAR_HI(n) ORION_PCIE_REG(0x0014 + ((n) * 8))
68#define PCIE_WIN_CTRL(n) (((n) < 5) ? \
69 ORION_PCIE_REG(0x1820 + ((n) << 4)) : \
70 ORION_PCIE_REG(0x1880))
71#define PCIE_WIN_BASE(n) (((n) < 5) ? \
72 ORION_PCIE_REG(0x1824 + ((n) << 4)) : \
73 ORION_PCIE_REG(0x1884))
74#define PCIE_WIN_REMAP(n) (((n) < 5) ? \
75 ORION_PCIE_REG(0x182c + ((n) << 4)) : \
76 ORION_PCIE_REG(0x188c))
77#define PCIE_MAX_BARS 3
78#define PCIE_MAX_WINS 6
79
80/*
81 * Use PCIE BAR '1' for all DDR banks
82 */
83#define PCIE_DRAM_BAR 1
84
85/*
86 * PCIE config cycles are done by programming the PCIE_CONF_ADDR register
87 * and then reading the PCIE_CONF_DATA register. Need to make sure these
88 * transactions are atomic.
89 */
90static DEFINE_SPINLOCK(orion_pcie_lock);
91 37
92void orion_pcie_id(u32 *dev, u32 *rev) 38void orion_pcie_id(u32 *dev, u32 *rev)
93{ 39{
94 *dev = orion_read(PCIE_DEV_ID) >> 16; 40 *dev = orion_pcie_dev_id(PCIE_BASE);
95 *rev = orion_read(PCIE_DEV_REV) & 0xff; 41 *rev = orion_pcie_rev(PCIE_BASE);
96}
97
98u32 orion_pcie_local_bus_nr(void)
99{
100 u32 stat = orion_read(PCIE_STAT);
101 return((stat & PCIE_STAT_BUS_MASK) >> PCIE_STAT_BUS_OFFS);
102}
103
104static u32 orion_pcie_local_dev_nr(void)
105{
106 u32 stat = orion_read(PCIE_STAT);
107 return((stat & PCIE_STAT_DEV_MASK) >> PCIE_STAT_DEV_OFFS);
108}
109
110static u32 orion_pcie_no_link(void)
111{
112 u32 stat = orion_read(PCIE_STAT);
113 return(stat & PCIE_STAT_LINK_DOWN);
114}
115
116static void orion_pcie_set_bus_nr(int nr)
117{
118 orion_clrbits(PCIE_STAT, PCIE_STAT_BUS_MASK);
119 orion_setbits(PCIE_STAT, nr << PCIE_STAT_BUS_OFFS);
120} 42}
121 43
122/* 44int orion_pcie_local_bus_nr(void)
123 * Setup PCIE BARs and Address Decode Wins:
124 * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
125 * WIN[0-3] -> DRAM bank[0-3]
126 */
127static void orion_setup_pcie_wins(struct mbus_dram_target_info *dram)
128{ 45{
129 u32 size; 46 return orion_pcie_get_local_bus_nr(PCIE_BASE);
130 int i;
131
132 /*
133 * First, disable and clear BARs and windows
134 */
135 for (i = 1; i < PCIE_MAX_BARS; i++) {
136 writel(0, PCIE_BAR_CTRL(i));
137 writel(0, PCIE_BAR_LO(i));
138 writel(0, PCIE_BAR_HI(i));
139 }
140
141 for (i = 0; i < PCIE_MAX_WINS; i++) {
142 writel(0, PCIE_WIN_CTRL(i));
143 writel(0, PCIE_WIN_BASE(i));
144 writel(0, PCIE_WIN_REMAP(i));
145 }
146
147 /*
148 * Setup windows for DDR banks. Count total DDR size on the fly.
149 */
150 size = 0;
151 for (i = 0; i < dram->num_cs; i++) {
152 struct mbus_dram_window *cs = dram->cs + i;
153
154 writel(cs->base & 0xffff0000, PCIE_WIN_BASE(i));
155 writel(0, PCIE_WIN_REMAP(i));
156 writel(((cs->size - 1) & 0xffff0000) |
157 (cs->mbus_attr << 8) |
158 (dram->mbus_dram_target_id << 4) |
159 (PCIE_DRAM_BAR << 1) | 1, PCIE_WIN_CTRL(i));
160
161 size += cs->size;
162 }
163
164 /*
165 * Setup BAR[1] to all DRAM banks
166 */
167 writel(dram->cs[0].base, PCIE_BAR_LO(PCIE_DRAM_BAR));
168 writel(0, PCIE_BAR_HI(PCIE_DRAM_BAR));
169 writel(((size - 1) & 0xffff0000) | 1, PCIE_BAR_CTRL(PCIE_DRAM_BAR));
170} 47}
171 48
172static void orion_pcie_master_slave_enable(void) 49static int pcie_valid_config(int bus, int dev)
173{
174 orion_setbits(PCIE_CMD_STAT, PCI_COMMAND_MASTER |
175 PCI_COMMAND_IO |
176 PCI_COMMAND_MEMORY);
177}
178
179static void orion_pcie_enable_interrupts(void)
180{
181 /*
182 * Enable interrupts lines
183 * INTA[24] INTB[25] INTC[26] INTD[27]
184 */
185 orion_setbits(PCIE_MASK, 0xf<<24);
186}
187
188static int orion_pcie_valid_config(u32 bus, u32 dev)
189{ 50{
190 /* 51 /*
191 * Don't go out when trying to access -- 52 * Don't go out when trying to access --
192 * 1. our own device 53 * 1. our own device / nonexisting device on local bus
193 * 2. where there's no device connected (no link) 54 * 2. where there's no device connected (no link)
194 * 3. nonexisting devices on local bus
195 */ 55 */
196 56 if (bus == 0 && dev != 1)
197 if ((orion_pcie_local_bus_nr() == bus) &&
198 (orion_pcie_local_dev_nr() == dev))
199 return 0;
200
201 if (orion_pcie_no_link())
202 return 0; 57 return 0;
203 58
204 if (bus == orion_pcie_local_bus_nr()) 59 if (!orion_pcie_link_up(PCIE_BASE))
205 if (((orion_pcie_local_dev_nr() == 0) && (dev != 1)) ||
206 ((orion_pcie_local_dev_nr() != 0) && (dev != 0)))
207 return 0; 60 return 0;
208 61
209 return 1; 62 return 1;
210} 63}
211 64
212static int orion_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, 65
213 int size, u32 *val) 66/*
67 * PCIE config cycles are done by programming the PCIE_CONF_ADDR register
68 * and then reading the PCIE_CONF_DATA register. Need to make sure these
69 * transactions are atomic.
70 */
71static DEFINE_SPINLOCK(orion_pcie_lock);
72
73static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
74 int size, u32 *val)
214{ 75{
215 unsigned long flags; 76 unsigned long flags;
216 unsigned int dev, rev, pcie_addr; 77 int ret;
217 78
218 if (orion_pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) { 79 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
219 *val = 0xffffffff; 80 *val = 0xffffffff;
220 return PCIBIOS_DEVICE_NOT_FOUND; 81 return PCIBIOS_DEVICE_NOT_FOUND;
221 } 82 }
222 83
223 spin_lock_irqsave(&orion_pcie_lock, flags); 84 spin_lock_irqsave(&orion_pcie_lock, flags);
85 ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
86 spin_unlock_irqrestore(&orion_pcie_lock, flags);
224 87
225 orion_write(PCIE_CONF_ADDR, PCIE_CONF_BUS(bus->number) | 88 return ret;
226 PCIE_CONF_DEV(PCI_SLOT(devfn)) | 89}
227 PCIE_CONF_FUNC(PCI_FUNC(devfn)) |
228 PCIE_CONF_REG(where) | PCIE_CONF_ADDR_EN);
229 90
230 orion_pcie_id(&dev, &rev); 91static int pcie_rd_conf_wa(struct pci_bus *bus, u32 devfn,
231 if (dev == MV88F5181_DEV_ID || dev == MV88F5182_DEV_ID) { 92 int where, int size, u32 *val)
232 /* extended register space */ 93{
233 pcie_addr = ORION_PCIE_WA_VIRT_BASE; 94 int ret;
234 pcie_addr |= PCIE_CONF_BUS(bus->number) |
235 PCIE_CONF_DEV(PCI_SLOT(devfn)) |
236 PCIE_CONF_FUNC(PCI_FUNC(devfn)) |
237 PCIE_CONF_REG(where);
238 *val = orion_read(pcie_addr);
239 } else
240 *val = orion_read(PCIE_CONF_DATA);
241 95
242 if (size == 1) 96 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
243 *val = (*val >> (8*(where & 0x3))) & 0xff; 97 *val = 0xffffffff;
244 else if (size == 2) 98 return PCIBIOS_DEVICE_NOT_FOUND;
245 *val = (*val >> (8*(where & 0x3))) & 0xffff; 99 }
246 100
247 spin_unlock_irqrestore(&orion_pcie_lock, flags); 101 /*
102 * We only support access to the non-extended configuration
103 * space when using the WA access method (or we would have to
104 * sacrifice 256M of CPU virtual address space.)
105 */
106 if (where >= 0x100) {
107 *val = 0xffffffff;
108 return PCIBIOS_DEVICE_NOT_FOUND;
109 }
248 110
249 return PCIBIOS_SUCCESSFUL; 111 ret = orion_pcie_rd_conf_wa((void __iomem *)ORION_PCIE_WA_VIRT_BASE,
250} 112 bus, devfn, where, size, val);
251 113
114 return ret;
115}
252 116
253static int orion_pcie_wr_conf(struct pci_bus *bus, u32 devfn, int where, 117static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
254 int size, u32 val) 118 int where, int size, u32 val)
255{ 119{
256 unsigned long flags; 120 unsigned long flags;
257 int ret; 121 int ret;
258 122
259 if (orion_pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) 123 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
260 return PCIBIOS_DEVICE_NOT_FOUND; 124 return PCIBIOS_DEVICE_NOT_FOUND;
261 125
262 spin_lock_irqsave(&orion_pcie_lock, flags); 126 spin_lock_irqsave(&orion_pcie_lock, flags);
263 127 ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
264 ret = PCIBIOS_SUCCESSFUL;
265
266 orion_write(PCIE_CONF_ADDR, PCIE_CONF_BUS(bus->number) |
267 PCIE_CONF_DEV(PCI_SLOT(devfn)) |
268 PCIE_CONF_FUNC(PCI_FUNC(devfn)) |
269 PCIE_CONF_REG(where) | PCIE_CONF_ADDR_EN);
270
271 if (size == 4) {
272 __raw_writel(val, PCIE_CONF_DATA);
273 } else if (size == 2) {
274 __raw_writew(val, PCIE_CONF_DATA + (where & 0x3));
275 } else if (size == 1) {
276 __raw_writeb(val, PCIE_CONF_DATA + (where & 0x3));
277 } else {
278 ret = PCIBIOS_BAD_REGISTER_NUMBER;
279 }
280
281 spin_unlock_irqrestore(&orion_pcie_lock, flags); 128 spin_unlock_irqrestore(&orion_pcie_lock, flags);
282 129
283 return ret; 130 return ret;
284} 131}
285 132
286struct pci_ops orion_pcie_ops = { 133struct pci_ops pcie_ops = {
287 .read = orion_pcie_rd_conf, 134 .read = pcie_rd_conf,
288 .write = orion_pcie_wr_conf, 135 .write = pcie_wr_conf,
289}; 136};
290 137
291 138
292static int orion_pcie_setup(struct pci_sys_data *sys) 139static int pcie_setup(struct pci_sys_data *sys)
293{ 140{
294 struct resource *res; 141 struct resource *res;
142 int dev;
295 143
296 /* 144 /*
297 * Point PCIe unit MBUS decode windows to DRAM space. 145 * Generic PCIe unit setup.
298 */
299 orion_setup_pcie_wins(&orion_mbus_dram_info);
300
301 /*
302 * Master + Slave enable
303 */ 146 */
304 orion_pcie_master_slave_enable(); 147 orion_pcie_setup(PCIE_BASE, &orion_mbus_dram_info);
305 148
306 /* 149 /*
307 * Enable interrupts lines A-D 150 * Check whether to apply Orion-1/Orion-NAS PCIe config
151 * read transaction workaround.
308 */ 152 */
309 orion_pcie_enable_interrupts(); 153 dev = orion_pcie_dev_id(PCIE_BASE);
154 if (dev == MV88F5181_DEV_ID || dev == MV88F5182_DEV_ID) {
155 printk(KERN_NOTICE "Applying Orion-1/Orion-NAS PCIe config "
156 "read transaction workaround\n");
157 pcie_ops.read = pcie_rd_conf_wa;
158 }
310 159
311 /* 160 /*
312 * Request resource 161 * Request resources.
313 */ 162 */
314 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL); 163 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
315 if (!res) 164 if (!res)
316 panic("orion_pci_setup unable to alloc resources"); 165 panic("pcie_setup unable to alloc resources");
317 166
318 /* 167 /*
319 * IORESOURCE_IO 168 * IORESOURCE_IO
@@ -417,19 +266,19 @@ static int orion_pcie_setup(struct pci_sys_data *sys)
417 */ 266 */
418static DEFINE_SPINLOCK(orion_pci_lock); 267static DEFINE_SPINLOCK(orion_pci_lock);
419 268
420u32 orion_pci_local_bus_nr(void) 269int orion_pci_local_bus_nr(void)
421{ 270{
422 u32 conf = orion_read(PCI_P2P_CONF); 271 u32 conf = orion_read(PCI_P2P_CONF);
423 return((conf & PCI_P2P_BUS_MASK) >> PCI_P2P_BUS_OFFS); 272 return((conf & PCI_P2P_BUS_MASK) >> PCI_P2P_BUS_OFFS);
424} 273}
425 274
426static u32 orion_pci_local_dev_nr(void) 275static int orion_pci_local_dev_nr(void)
427{ 276{
428 u32 conf = orion_read(PCI_P2P_CONF); 277 u32 conf = orion_read(PCI_P2P_CONF);
429 return((conf & PCI_P2P_DEV_MASK) >> PCI_P2P_DEV_OFFS); 278 return((conf & PCI_P2P_DEV_MASK) >> PCI_P2P_DEV_OFFS);
430} 279}
431 280
432static int orion_pci_hw_rd_conf(u32 bus, u32 dev, u32 func, 281static int orion_pci_hw_rd_conf(int bus, int dev, u32 func,
433 u32 where, u32 size, u32 *val) 282 u32 where, u32 size, u32 *val)
434{ 283{
435 unsigned long flags; 284 unsigned long flags;
@@ -451,7 +300,7 @@ static int orion_pci_hw_rd_conf(u32 bus, u32 dev, u32 func,
451 return PCIBIOS_SUCCESSFUL; 300 return PCIBIOS_SUCCESSFUL;
452} 301}
453 302
454static int orion_pci_hw_wr_conf(u32 bus, u32 dev, u32 func, 303static int orion_pci_hw_wr_conf(int bus, int dev, u32 func,
455 u32 where, u32 size, u32 val) 304 u32 where, u32 size, u32 val)
456{ 305{
457 unsigned long flags; 306 unsigned long flags;
@@ -508,7 +357,7 @@ static int orion_pci_wr_conf(struct pci_bus *bus, u32 devfn,
508 PCI_FUNC(devfn), where, size, val); 357 PCI_FUNC(devfn), where, size, val);
509} 358}
510 359
511struct pci_ops orion_pci_ops = { 360struct pci_ops pci_ops = {
512 .read = orion_pci_rd_conf, 361 .read = orion_pci_rd_conf,
513 .write = orion_pci_wr_conf, 362 .write = orion_pci_wr_conf,
514}; 363};
@@ -540,7 +389,8 @@ static void orion_pci_set_bus_nr(int nr)
540 389
541static void orion_pci_master_slave_enable(void) 390static void orion_pci_master_slave_enable(void)
542{ 391{
543 u32 bus_nr, dev_nr, func, reg, val; 392 int bus_nr, dev_nr, func, reg;
393 u32 val;
544 394
545 bus_nr = orion_pci_local_bus_nr(); 395 bus_nr = orion_pci_local_bus_nr();
546 dev_nr = orion_pci_local_dev_nr(); 396 dev_nr = orion_pci_local_dev_nr();
@@ -554,8 +404,8 @@ static void orion_pci_master_slave_enable(void)
554static void orion_setup_pci_wins(struct mbus_dram_target_info *dram) 404static void orion_setup_pci_wins(struct mbus_dram_target_info *dram)
555{ 405{
556 u32 win_enable; 406 u32 win_enable;
557 u32 bus; 407 int bus;
558 u32 dev; 408 int dev;
559 int i; 409 int i;
560 410
561 /* 411 /*
@@ -611,7 +461,7 @@ static void orion_setup_pci_wins(struct mbus_dram_target_info *dram)
611 orion_setbits(PCI_ADDR_DECODE_CTRL, 1); 461 orion_setbits(PCI_ADDR_DECODE_CTRL, 1);
612} 462}
613 463
614static int orion_pci_setup(struct pci_sys_data *sys) 464static int pci_setup(struct pci_sys_data *sys)
615{ 465{
616 struct resource *res; 466 struct resource *res;
617 467
@@ -635,7 +485,7 @@ static int orion_pci_setup(struct pci_sys_data *sys)
635 */ 485 */
636 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL); 486 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
637 if (!res) 487 if (!res)
638 panic("orion_pci_setup unable to alloc resources"); 488 panic("pci_setup unable to alloc resources");
639 489
640 /* 490 /*
641 * IORESOURCE_IO 491 * IORESOURCE_IO
@@ -674,16 +524,11 @@ int orion_pci_sys_setup(int nr, struct pci_sys_data *sys)
674 int ret = 0; 524 int ret = 0;
675 525
676 if (nr == 0) { 526 if (nr == 0) {
677 /* 527 orion_pcie_set_local_bus_nr(PCIE_BASE, sys->busnr);
678 * PCIE setup 528 ret = pcie_setup(sys);
679 */
680 orion_pcie_set_bus_nr(0);
681 ret = orion_pcie_setup(sys);
682 } else if (nr == 1) { 529 } else if (nr == 1) {
683 /* 530 orion_pci_set_bus_nr(sys->busnr);
684 * PCI setup 531 ret = pci_setup(sys);
685 */
686 ret = orion_pci_setup(sys);
687 } 532 }
688 533
689 return ret; 534 return ret;
@@ -691,31 +536,15 @@ int orion_pci_sys_setup(int nr, struct pci_sys_data *sys)
691 536
692struct pci_bus *orion_pci_sys_scan_bus(int nr, struct pci_sys_data *sys) 537struct pci_bus *orion_pci_sys_scan_bus(int nr, struct pci_sys_data *sys)
693{ 538{
694 struct pci_ops *ops;
695 struct pci_bus *bus; 539 struct pci_bus *bus;
696 540
697
698 if (nr == 0) { 541 if (nr == 0) {
699 u32 pci_bus; 542 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
700 /*
701 * PCIE scan
702 */
703 ops = &orion_pcie_ops;
704 bus = pci_scan_bus(sys->busnr, ops, sys);
705 /*
706 * Set local PCI bus number to follow PCIE bridges (if any)
707 */
708 pci_bus = bus->number + bus->subordinate - bus->secondary + 1;
709 orion_pci_set_bus_nr(pci_bus);
710 } else if (nr == 1) { 543 } else if (nr == 1) {
711 /* 544 bus = pci_scan_bus(sys->busnr, &pci_ops, sys);
712 * PCI scan
713 */
714 ops = &orion_pci_ops;
715 bus = pci_scan_bus(sys->busnr, ops, sys);
716 } else { 545 } else {
717 BUG();
718 bus = NULL; 546 bus = NULL;
547 BUG();
719 } 548 }
720 549
721 return bus; 550 return bus;