Skip to content

Commit 12401fc

Browse files
juhosgJohn Crispin
authored andcommitted
MIPS: pci-ar724x: setup command register of the PCI controller
The command register of the PCI controller is not initialized correctly by the bootloader on some boards and this leads to non working PCI bus. Add code to initialize the command register from the Linux code to avoid this. Signed-off-by: Gabor Juhos <juhosg@openwrt.org> Patchwork: http://patchwork.linux-mips.org/patch/4916/ Signed-off-by: John Crispin <blogic@openwrt.org>
1 parent 8b66d46 commit 12401fc

3 files changed

Lines changed: 74 additions & 1 deletion

File tree

‎arch/mips/ath79/pci.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,14 @@ static struct platform_device *
139139
ath79_register_pci_ar724x(int id,
140140
unsigned long cfg_base,
141141
unsigned long ctrl_base,
142+
unsigned long crp_base,
142143
unsigned long mem_base,
143144
unsigned long mem_size,
144145
unsigned long io_base,
145146
int irq)
146147
{
147148
struct platform_device *pdev;
148-
struct resource res[5];
149+
struct resource res[6];
149150

150151
memset(res, 0, sizeof(res));
151152

@@ -173,6 +174,11 @@ ath79_register_pci_ar724x(int id,
173174
res[4].start = io_base;
174175
res[4].end = io_base;
175176

177+
res[5].name = "crp_base";
178+
res[5].flags = IORESOURCE_MEM;
179+
res[5].start = crp_base;
180+
res[5].end = crp_base + AR724X_PCI_CRP_SIZE - 1;
181+
176182
pdev = platform_device_register_simple("ar724x-pci", id,
177183
res, ARRAY_SIZE(res));
178184
return pdev;
@@ -188,6 +194,7 @@ int __init ath79_register_pci(void)
188194
pdev = ath79_register_pci_ar724x(-1,
189195
AR724X_PCI_CFG_BASE,
190196
AR724X_PCI_CTRL_BASE,
197+
AR724X_PCI_CRP_BASE,
191198
AR724X_PCI_MEM_BASE,
192199
AR724X_PCI_MEM_SIZE,
193200
0,
@@ -203,6 +210,7 @@ int __init ath79_register_pci(void)
203210
pdev = ath79_register_pci_ar724x(-1,
204211
AR724X_PCI_CFG_BASE,
205212
AR724X_PCI_CTRL_BASE,
213+
AR724X_PCI_CRP_BASE,
206214
AR724X_PCI_MEM_BASE,
207215
AR724X_PCI_MEM_SIZE,
208216
0,

‎arch/mips/include/asm/mach-ath79/ar71xx_regs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767

6868
#define AR724X_PCI_CFG_BASE 0x14000000
6969
#define AR724X_PCI_CFG_SIZE 0x1000
70+
#define AR724X_PCI_CRP_BASE (AR71XX_APB_BASE + 0x000c0000)
71+
#define AR724X_PCI_CRP_SIZE 0x1000
7072
#define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000f0000)
7173
#define AR724X_PCI_CTRL_SIZE 0x100
7274

‎arch/mips/pci/pci-ar724x.c‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@
2929

3030
#define AR7240_BAR0_WAR_VALUE 0xffff
3131

32+
#define AR724X_PCI_CMD_INIT (PCI_COMMAND_MEMORY | \
33+
PCI_COMMAND_MASTER | \
34+
PCI_COMMAND_INVALIDATE | \
35+
PCI_COMMAND_PARITY | \
36+
PCI_COMMAND_SERR | \
37+
PCI_COMMAND_FAST_BACK)
38+
3239
struct ar724x_pci_controller {
3340
void __iomem *devcfg_base;
3441
void __iomem *ctrl_base;
42+
void __iomem *crp_base;
3543

3644
int irq;
3745
int irq_base;
@@ -64,6 +72,51 @@ pci_bus_to_ar724x_controller(struct pci_bus *bus)
6472
return container_of(hose, struct ar724x_pci_controller, pci_controller);
6573
}
6674

75+
static int ar724x_pci_local_write(struct ar724x_pci_controller *apc,
76+
int where, int size, u32 value)
77+
{
78+
unsigned long flags;
79+
void __iomem *base;
80+
u32 data;
81+
int s;
82+
83+
WARN_ON(where & (size - 1));
84+
85+
if (!apc->link_up)
86+
return PCIBIOS_DEVICE_NOT_FOUND;
87+
88+
base = apc->crp_base;
89+
90+
spin_lock_irqsave(&apc->lock, flags);
91+
data = __raw_readl(base + (where & ~3));
92+
93+
switch (size) {
94+
case 1:
95+
s = ((where & 3) * 8);
96+
data &= ~(0xff << s);
97+
data |= ((value & 0xff) << s);
98+
break;
99+
case 2:
100+
s = ((where & 2) * 8);
101+
data &= ~(0xffff << s);
102+
data |= ((value & 0xffff) << s);
103+
break;
104+
case 4:
105+
data = value;
106+
break;
107+
default:
108+
spin_unlock_irqrestore(&apc->lock, flags);
109+
return PCIBIOS_BAD_REGISTER_NUMBER;
110+
}
111+
112+
__raw_writel(data, base + (where & ~3));
113+
/* flush write */
114+
__raw_readl(base + (where & ~3));
115+
spin_unlock_irqrestore(&apc->lock, flags);
116+
117+
return PCIBIOS_SUCCESSFUL;
118+
}
119+
67120
static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
68121
int size, uint32_t *value)
69122
{
@@ -324,6 +377,14 @@ static int ar724x_pci_probe(struct platform_device *pdev)
324377
if (!apc->devcfg_base)
325378
return -EBUSY;
326379

380+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "crp_base");
381+
if (!res)
382+
return -EINVAL;
383+
384+
apc->crp_base = devm_request_and_ioremap(&pdev->dev, res);
385+
if (apc->crp_base == NULL)
386+
return -EBUSY;
387+
327388
apc->irq = platform_get_irq(pdev, 0);
328389
if (apc->irq < 0)
329390
return -EINVAL;
@@ -360,6 +421,8 @@ static int ar724x_pci_probe(struct platform_device *pdev)
360421

361422
ar724x_pci_irq_init(apc, id);
362423

424+
ar724x_pci_local_write(apc, PCI_COMMAND, 4, AR724X_PCI_CMD_INIT);
425+
363426
register_pci_controller(&apc->pci_controller);
364427

365428
return 0;

0 commit comments

Comments
 (0)