1 From 39f3275077a5b143616fcb3e7a6457a5c42739ee Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Wed, 14 Mar 2012 10:36:04 +0100
4 Subject: [PATCH 13/47] MIPS: ath79: fix broken ar724x_pci_{read,write} functions
6 The current ar724x_pci_{read,write} functions are
7 broken. Due to that, pci_read_config_byte returns
8 with bogus values, and pci_write_config_{byte,word}
9 unconditionally clears the accessed PCI configuration
10 registers instead of changing the value of them.
12 The patch fixes the broken functions, thus the PCI
13 configuration space can be accessed correctly.
15 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
16 Cc: linux-mips@linux-mips.org
17 Patchwork: https://patchwork.linux-mips.org/patch/3493/
18 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
20 arch/mips/pci/pci-ar724x.c | 52 ++++++++++++++++++++++----------------------
21 1 files changed, 26 insertions(+), 26 deletions(-)
23 --- a/arch/mips/pci/pci-ar724x.c
24 +++ b/arch/mips/pci/pci-ar724x.c
25 @@ -22,8 +22,9 @@ static void __iomem *ar724x_pci_devcfg_b
26 static int ar724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
27 int size, uint32_t *value)
29 - unsigned long flags, addr, tval, mask;
30 + unsigned long flags;
35 return PCIBIOS_DEVICE_NOT_FOUND;
36 @@ -31,24 +32,22 @@ static int ar724x_pci_read(struct pci_bu
37 base = ar724x_pci_devcfg_base;
39 spin_lock_irqsave(&ar724x_pci_lock, flags);
40 + data = __raw_readl(base + (where & ~3));
45 - mask = 0xff000000 >> ((where % 4) * 8);
46 - tval = __raw_readl(base + addr);
47 - tval = tval & ~mask;
48 - *value = (tval >> ((4 - (where % 4))*8));
57 - mask = 0xffff0000 >> ((where % 4)*8);
58 - tval = __raw_readl(base + addr);
59 - tval = tval & ~mask;
60 - *value = (tval >> ((4 - (where % 4))*8));
66 - *value = __raw_readl(base + where);
69 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
70 @@ -57,6 +56,7 @@ static int ar724x_pci_read(struct pci_bu
73 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
76 return PCIBIOS_SUCCESSFUL;
78 @@ -64,8 +64,10 @@ static int ar724x_pci_read(struct pci_bu
79 static int ar724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
80 int size, uint32_t value)
82 - unsigned long flags, tval, addr, mask;
83 + unsigned long flags;
89 return PCIBIOS_DEVICE_NOT_FOUND;
90 @@ -73,26 +75,21 @@ static int ar724x_pci_write(struct pci_b
91 base = ar724x_pci_devcfg_base;
93 spin_lock_irqsave(&ar724x_pci_lock, flags);
94 + data = __raw_readl(base + (where & ~3));
99 - mask = 0xff000000 >> ((where % 4)*8);
100 - tval = __raw_readl(base + addr);
101 - tval = tval & ~mask;
102 - tval |= (value << ((4 - (where % 4))*8)) & mask;
103 - __raw_writel(tval, base + addr);
104 + s = ((where & 3) * 8);
105 + data &= ~(0xff << s);
106 + data |= ((value & 0xff) << s);
110 - mask = 0xffff0000 >> ((where % 4)*8);
111 - tval = __raw_readl(base + addr);
112 - tval = tval & ~mask;
113 - tval |= (value << ((4 - (where % 4))*8)) & mask;
114 - __raw_writel(tval, base + addr);
115 + s = ((where & 2) * 8);
116 + data &= ~(0xffff << s);
117 + data |= ((value & 0xffff) << s);
120 - __raw_writel(value, (base + where));
124 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
125 @@ -100,6 +97,9 @@ static int ar724x_pci_write(struct pci_b
126 return PCIBIOS_BAD_REGISTER_NUMBER;
129 + __raw_writel(data, base + (where & ~3));
131 + __raw_readl(base + (where & ~3));
132 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
134 return PCIBIOS_SUCCESSFUL;