14 #include <linux/resource.h>
15 #include <linux/types.h>
17 #include <linux/bitops.h>
18 #include <linux/pci.h>
26 #define AR71XX_PCI_MEM_BASE 0x10000000
27 #define AR71XX_PCI_MEM_SIZE 0x08000000
29 #define AR71XX_PCI_WIN0_OFFS 0x10000000
30 #define AR71XX_PCI_WIN1_OFFS 0x11000000
31 #define AR71XX_PCI_WIN2_OFFS 0x12000000
32 #define AR71XX_PCI_WIN3_OFFS 0x13000000
33 #define AR71XX_PCI_WIN4_OFFS 0x14000000
34 #define AR71XX_PCI_WIN5_OFFS 0x15000000
35 #define AR71XX_PCI_WIN6_OFFS 0x16000000
36 #define AR71XX_PCI_WIN7_OFFS 0x07000000
38 #define AR71XX_PCI_CFG_BASE \
39 (AR71XX_PCI_MEM_BASE + AR71XX_PCI_WIN7_OFFS + 0x10000)
40 #define AR71XX_PCI_CFG_SIZE 0x100
42 #define AR71XX_PCI_REG_CRP_AD_CBE 0x00
43 #define AR71XX_PCI_REG_CRP_WRDATA 0x04
44 #define AR71XX_PCI_REG_CRP_RDDATA 0x08
45 #define AR71XX_PCI_REG_CFG_AD 0x0c
46 #define AR71XX_PCI_REG_CFG_CBE 0x10
47 #define AR71XX_PCI_REG_CFG_WRDATA 0x14
48 #define AR71XX_PCI_REG_CFG_RDDATA 0x18
49 #define AR71XX_PCI_REG_PCI_ERR 0x1c
50 #define AR71XX_PCI_REG_PCI_ERR_ADDR 0x20
51 #define AR71XX_PCI_REG_AHB_ERR 0x24
52 #define AR71XX_PCI_REG_AHB_ERR_ADDR 0x28
54 #define AR71XX_PCI_CRP_CMD_WRITE 0x00010000
55 #define AR71XX_PCI_CRP_CMD_READ 0x00000000
56 #define AR71XX_PCI_CFG_CMD_READ 0x0000000a
57 #define AR71XX_PCI_CFG_CMD_WRITE 0x0000000b
59 #define AR71XX_PCI_INT_CORE BIT(4)
60 #define AR71XX_PCI_INT_DEV2 BIT(2)
61 #define AR71XX_PCI_INT_DEV1 BIT(1)
62 #define AR71XX_PCI_INT_DEV0 BIT(0)
64 #define AR71XX_PCI_IRQ_COUNT 5
67 static void __iomem *ar71xx_pcicfg_base;
70 static const u8 ar71xx_pci_ble_table[4][4] = {
77 static const u32 ar71xx_pci_read_mask[8] = {
78 0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0
81 static inline u32 ar71xx_pci_get_ble(
int where,
int size,
int local)
85 t = ar71xx_pci_ble_table[size & 3][where & 3];
87 t <<= (local) ? 20 : 4;
104 (
PCI_FUNC(devfn) << 8) | (where & ~3) | 1;
110 static int ar71xx_pci_check_error(
int quiet)
122 pr_crit(
"ar71xx: %s bus error %d at addr 0x%x\n",
123 "PCI", pci_err, addr);
136 pr_crit(
"ar71xx: %s bus error %d at addr 0x%x\n",
137 "AHB", ahb_err, addr);
144 return !!(ahb_err | pci_err);
147 static inline void ar71xx_pci_local_write(
int where,
int size,
u32 value)
149 void __iomem *base = ar71xx_pcicfg_base;
152 value = value << (8 * (where & 3));
155 ad_cbe |= ar71xx_pci_get_ble(where,
size, 1);
161 static inline int ar71xx_pci_set_cfgaddr(
struct pci_bus *bus,
165 void __iomem *base = ar71xx_pcicfg_base;
168 addr = ar71xx_pci_bus_addr(bus, devfn, where);
174 return ar71xx_pci_check_error(1);
177 static int ar71xx_pci_read_config(
struct pci_bus *bus,
unsigned int devfn,
180 void __iomem *base = ar71xx_pcicfg_base;
191 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
198 spin_unlock_irqrestore(&ar71xx_pci_lock, flags);
200 *value = (data >> (8 * (where & 3))) & ar71xx_pci_read_mask[size & 7];
205 static int ar71xx_pci_write_config(
struct pci_bus *bus,
unsigned int devfn,
208 void __iomem *base = ar71xx_pcicfg_base;
213 value = value << (8 * (where & 3));
218 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
225 spin_unlock_irqrestore(&ar71xx_pci_lock,
flags);
230 static struct pci_ops ar71xx_pci_ops = {
231 .read = ar71xx_pci_read_config,
232 .write = ar71xx_pci_write_config,
235 static struct resource ar71xx_pci_io_resource = {
236 .name =
"PCI IO space",
242 static struct resource ar71xx_pci_mem_resource = {
243 .name =
"PCI memory space",
250 .pci_ops = &ar71xx_pci_ops,
251 .mem_resource = &ar71xx_pci_mem_resource,
252 .io_resource = &ar71xx_pci_io_resource,
255 static void ar71xx_pci_irq_handler(
unsigned int irq,
struct irq_desc *
desc)
279 static void ar71xx_pci_irq_unmask(
struct irq_data *
d)
292 static void ar71xx_pci_irq_mask(
struct irq_data *d)
305 static struct irq_chip ar71xx_pci_irq_chip = {
306 .name =
"AR71XX PCI",
307 .irq_mask = ar71xx_pci_irq_mask,
308 .irq_unmask = ar71xx_pci_irq_unmask,
309 .irq_mask_ack = ar71xx_pci_irq_mask,
312 static __init void ar71xx_pci_irq_init(
void)
324 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
330 static __init void ar71xx_pci_reset(
void)
357 if (ar71xx_pcicfg_base ==
NULL)
368 ar71xx_pci_check_error(1);
370 ar71xx_pci_irq_init();