1 From 958e444a5a7750c407ed0c90af28f74295478e99 Mon Sep 17 00:00:00 2001
2 From: Rene Bolldorf <xsecute@googlemail.com>
3 Date: Thu, 17 Nov 2011 14:25:09 +0000
4 Subject: [PATCH 17/27] MIPS: Initial PCI support for Atheros 724x SoCs.
6 [ralf@linux-mips.org: Fixed the odd formatting of all break statements.]
8 Signed-off-by: Rene Bolldorf <xsecute@googlemail.com>
9 Cc: linux-mips@linux-mips.org
10 Cc: linux-kernel@vger.kernel.org
11 Patchwork: https://patchwork.linux-mips.org/patch/3019/
12 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
14 arch/mips/include/asm/mach-ath79/pci-ath724x.h | 21 +++
15 arch/mips/pci/Makefile | 1 +
16 arch/mips/pci/pci-ath724x.c | 174 ++++++++++++++++++++++++
17 3 files changed, 196 insertions(+), 0 deletions(-)
18 create mode 100644 arch/mips/include/asm/mach-ath79/pci-ath724x.h
19 create mode 100644 arch/mips/pci/pci-ath724x.c
22 +++ b/arch/mips/include/asm/mach-ath79/pci-ath724x.h
25 + * Atheros 724x PCI support
27 + * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com>
29 + * This program is free software; you can redistribute it and/or modify it
30 + * under the terms of the GNU General Public License version 2 as published
31 + * by the Free Software Foundation.
34 +#ifndef __ASM_MACH_ATH79_PCI_ATH724X_H
35 +#define __ASM_MACH_ATH79_PCI_ATH724X_H
37 +struct ath724x_pci_data {
42 +void ath724x_pci_add_data(struct ath724x_pci_data *data, int size);
44 +#endif /* __ASM_MACH_ATH79_PCI_ATH724X_H */
45 --- a/arch/mips/pci/Makefile
46 +++ b/arch/mips/pci/Makefile
47 @@ -19,6 +19,7 @@ obj-$(CONFIG_BCM47XX) += pci-bcm47xx.o
48 obj-$(CONFIG_BCM63XX) += pci-bcm63xx.o fixup-bcm63xx.o \
50 obj-$(CONFIG_MIPS_ALCHEMY) += pci-alchemy.o
51 +obj-$(CONFIG_SOC_AR724X) += pci-ath724x.o
54 # These are still pretty much in the old state, watch, go blind.
56 +++ b/arch/mips/pci/pci-ath724x.c
59 + * Atheros 724x PCI support
61 + * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com>
63 + * This program is free software; you can redistribute it and/or modify it
64 + * under the terms of the GNU General Public License version 2 as published
65 + * by the Free Software Foundation.
68 +#include <linux/pci.h>
69 +#include <asm/mach-ath79/pci-ath724x.h>
71 +#define reg_read(_phys) (*(unsigned int *) KSEG1ADDR(_phys))
72 +#define reg_write(_phys, _val) ((*(unsigned int *) KSEG1ADDR(_phys)) = (_val))
74 +#define ATH724X_PCI_DEV_BASE 0x14000000
75 +#define ATH724X_PCI_MEM_BASE 0x10000000
76 +#define ATH724X_PCI_MEM_SIZE 0x08000000
78 +static DEFINE_SPINLOCK(ath724x_pci_lock);
79 +static struct ath724x_pci_data *pci_data;
80 +static int pci_data_size;
82 +static int ath724x_pci_read(struct pci_bus *bus, unsigned int devfn, int where,
83 + int size, uint32_t *value)
85 + unsigned long flags, addr, tval, mask;
88 + return PCIBIOS_DEVICE_NOT_FOUND;
90 + if (where & (size - 1))
91 + return PCIBIOS_BAD_REGISTER_NUMBER;
93 + spin_lock_irqsave(&ath724x_pci_lock, flags);
98 + mask = 0xff000000 >> ((where % 4) * 8);
99 + tval = reg_read(ATH724X_PCI_DEV_BASE + addr);
100 + tval = tval & ~mask;
101 + *value = (tval >> ((4 - (where % 4))*8));
105 + mask = 0xffff0000 >> ((where % 4)*8);
106 + tval = reg_read(ATH724X_PCI_DEV_BASE + addr);
107 + tval = tval & ~mask;
108 + *value = (tval >> ((4 - (where % 4))*8));
111 + *value = reg_read(ATH724X_PCI_DEV_BASE + where);
114 + spin_unlock_irqrestore(&ath724x_pci_lock, flags);
116 + return PCIBIOS_BAD_REGISTER_NUMBER;
119 + spin_unlock_irqrestore(&ath724x_pci_lock, flags);
121 + return PCIBIOS_SUCCESSFUL;
124 +static int ath724x_pci_write(struct pci_bus *bus, unsigned int devfn, int where,
125 + int size, uint32_t value)
127 + unsigned long flags, tval, addr, mask;
130 + return PCIBIOS_DEVICE_NOT_FOUND;
132 + if (where & (size - 1))
133 + return PCIBIOS_BAD_REGISTER_NUMBER;
135 + spin_lock_irqsave(&ath724x_pci_lock, flags);
139 + addr = (ATH724X_PCI_DEV_BASE + where) & ~3;
140 + mask = 0xff000000 >> ((where % 4)*8);
141 + tval = reg_read(addr);
142 + tval = tval & ~mask;
143 + tval |= (value << ((4 - (where % 4))*8)) & mask;
144 + reg_write(addr, tval);
147 + addr = (ATH724X_PCI_DEV_BASE + where) & ~3;
148 + mask = 0xffff0000 >> ((where % 4)*8);
149 + tval = reg_read(addr);
150 + tval = tval & ~mask;
151 + tval |= (value << ((4 - (where % 4))*8)) & mask;
152 + reg_write(addr, tval);
155 + reg_write((ATH724X_PCI_DEV_BASE + where), value);
158 + spin_unlock_irqrestore(&ath724x_pci_lock, flags);
160 + return PCIBIOS_BAD_REGISTER_NUMBER;
163 + spin_unlock_irqrestore(&ath724x_pci_lock, flags);
165 + return PCIBIOS_SUCCESSFUL;
168 +static struct pci_ops ath724x_pci_ops = {
169 + .read = ath724x_pci_read,
170 + .write = ath724x_pci_write,
173 +static struct resource ath724x_io_resource = {
174 + .name = "PCI IO space",
177 + .flags = IORESOURCE_IO,
180 +static struct resource ath724x_mem_resource = {
181 + .name = "PCI memory space",
182 + .start = ATH724X_PCI_MEM_BASE,
183 + .end = ATH724X_PCI_MEM_BASE + ATH724X_PCI_MEM_SIZE - 1,
184 + .flags = IORESOURCE_MEM,
187 +static struct pci_controller ath724x_pci_controller = {
188 + .pci_ops = &ath724x_pci_ops,
189 + .io_resource = &ath724x_io_resource,
190 + .mem_resource = &ath724x_mem_resource,
193 +void ath724x_pci_add_data(struct ath724x_pci_data *data, int size)
196 + pci_data_size = size;
199 +int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
201 + unsigned int devfn = dev->devfn;
204 + if (devfn > pci_data_size - 1)
207 + irq = pci_data[devfn].irq;
212 +int pcibios_plat_dev_init(struct pci_dev *dev)
214 + unsigned int devfn = dev->devfn;
216 + if (devfn > pci_data_size - 1)
217 + return PCIBIOS_DEVICE_NOT_FOUND;
219 + dev->dev.platform_data = pci_data[devfn].pdata;
221 + return PCIBIOS_SUCCESSFUL;
224 +static int __init ath724x_pcibios_init(void)
226 + register_pci_controller(&ath724x_pci_controller);
228 + return PCIBIOS_SUCCESSFUL;
231 +arch_initcall(ath724x_pcibios_init);