13 #include <linux/pci.h>
18 #define AR724X_PCI_CFG_BASE 0x14000000
19 #define AR724X_PCI_CFG_SIZE 0x1000
20 #define AR724X_PCI_CTRL_BASE (AR71XX_APB_BASE + 0x000f0000)
21 #define AR724X_PCI_CTRL_SIZE 0x100
23 #define AR724X_PCI_MEM_BASE 0x10000000
24 #define AR724X_PCI_MEM_SIZE 0x08000000
26 #define AR724X_PCI_REG_RESET 0x18
27 #define AR724X_PCI_REG_INT_STATUS 0x4c
28 #define AR724X_PCI_REG_INT_MASK 0x50
30 #define AR724X_PCI_RESET_LINK_UP BIT(0)
32 #define AR724X_PCI_INT_DEV0 BIT(14)
34 #define AR724X_PCI_IRQ_COUNT 1
36 #define AR7240_BAR0_WAR_VALUE 0xffff
39 static void __iomem *ar724x_pci_devcfg_base;
40 static void __iomem *ar724x_pci_ctrl_base;
42 static u32 ar724x_pci_bar0_value;
43 static bool ar724x_pci_bar0_is_cached;
44 static bool ar724x_pci_link_up;
46 static inline bool ar724x_pci_check_link(
void)
54 static int ar724x_pci_read(
struct pci_bus *
bus,
unsigned int devfn,
int where,
61 if (!ar724x_pci_link_up)
67 base = ar724x_pci_devcfg_base;
88 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
93 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
96 ar724x_pci_bar0_is_cached) {
98 *value = ar724x_pci_bar0_value;
106 static int ar724x_pci_write(
struct pci_bus *bus,
unsigned int devfn,
int where,
114 if (!ar724x_pci_link_up)
121 if (value != 0xffffffff) {
132 ar724x_pci_bar0_is_cached =
true;
133 ar724x_pci_bar0_value =
value;
137 ar724x_pci_bar0_is_cached =
false;
141 base = ar724x_pci_devcfg_base;
148 s = ((where & 3) * 8);
149 data &= ~(0xff <<
s);
150 data |= ((value & 0xff) << s);
153 s = ((where & 2) * 8);
154 data &= ~(0xffff <<
s);
155 data |= ((value & 0xffff) << s);
161 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
169 spin_unlock_irqrestore(&ar724x_pci_lock, flags);
174 static struct pci_ops ar724x_pci_ops = {
175 .read = ar724x_pci_read,
176 .write = ar724x_pci_write,
179 static struct resource ar724x_io_resource = {
180 .name =
"PCI IO space",
186 static struct resource ar724x_mem_resource = {
187 .name =
"PCI memory space",
194 .pci_ops = &ar724x_pci_ops,
195 .io_resource = &ar724x_io_resource,
196 .mem_resource = &ar724x_mem_resource,
199 static void ar724x_pci_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
204 base = ar724x_pci_ctrl_base;
216 static void ar724x_pci_irq_unmask(
struct irq_data *
d)
221 base = ar724x_pci_ctrl_base;
233 static void ar724x_pci_irq_mask(
struct irq_data *d)
238 base = ar724x_pci_ctrl_base;
258 static struct irq_chip ar724x_pci_irq_chip = {
259 .name =
"AR724X PCI ",
260 .irq_mask = ar724x_pci_irq_mask,
261 .irq_unmask = ar724x_pci_irq_unmask,
262 .irq_mask_ack = ar724x_pci_irq_mask,
265 static void __init ar724x_pci_irq_init(
int irq)
270 base = ar724x_pci_ctrl_base;
279 irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
282 irq_set_chained_handler(irq, ar724x_pci_irq_handler);
293 if (ar724x_pci_devcfg_base ==
NULL)
298 if (ar724x_pci_ctrl_base ==
NULL)
299 goto err_unmap_devcfg;
301 ar724x_pci_link_up = ar724x_pci_check_link();
302 if (!ar724x_pci_link_up)
303 pr_warn(
"ar724x: PCIe link is down\n");
305 ar724x_pci_irq_init(irq);
311 iounmap(ar724x_pci_devcfg_base);