*
* ADM5120 PCI Host Controller driver
*
- * Copyright (C) ADMtek Incorporated.
- * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
- * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
* Copyright (C) 2007 OpenWrt.org
+ * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This code was based on the ADM5120 specific port of the Linux 2.6.10 kernel
+ * done by Jeroen Vreeken
+ * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * Jeroen's code was based on the Linux 2.4.xx source codes found in various
+ * tarballs released by Edimax for it's ADM5120 based devices
+ * Copyright (C) ADMtek Incorporated
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
*
*/
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/spinlock.h>
+#include <linux/io.h>
#include <linux/pci.h>
#include <linux/pci_ids.h>
#include <linux/pci_regs.h>
-#include <asm/io.h>
#include <asm/delay.h>
#include <asm/bootinfo.h>
#include <adm5120_defs.h>
#include <adm5120_info.h>
#include <adm5120_defs.h>
-#include <adm5120_irq.h>
+#include <adm5120_platform.h>
#undef DEBUG
#ifdef DEBUG
-#define DBG(f, a...) printk(KERN_DEBUG f, ## a )
+#define DBG(f, a...) printk(KERN_DEBUG f, ## a)
#else
#define DBG(f, a...) do {} while (0)
#endif
#define PCI_ENABLE 0x80000000
+/* -------------------------------------------------------------------------*/
+
+static unsigned int adm5120_pci_nr_irqs __initdata;
+static struct adm5120_pci_irq *adm5120_pci_irq_map __initdata;
+
static spinlock_t pci_lock = SPIN_LOCK_UNLOCKED;
/* -------------------------------------------------------------------------*/
spin_lock_irqsave(&pci_lock, flags);
- write_cfgaddr(mkaddr(bus,devfn,where));
+ write_cfgaddr(mkaddr(bus, devfn, where));
data = read_cfgdata();
DBG("PCI: cfg_read %02u.%02u.%01u/%02X:%01d, cfg:0x%08X",
spin_lock_irqsave(&pci_lock, flags);
- write_cfgaddr(mkaddr(bus,devfn,where));
+ write_cfgaddr(mkaddr(bus, devfn, where));
data = read_cfgdata();
DBG("PCI: cfg_write %02u.%02u.%01u/%02X:%01d, cfg:0x%08X",
/* -------------------------------------------------------------------------*/
-struct adm5120_pci_irq {
- u8 slot;
- u8 func;
- u8 pin;
- unsigned irq;
-};
-
-#define PCIIRQ(s,f,p,i) { \
- .slot = (s), \
- .func = (f), \
- .pin = (p), \
- .irq = (i) \
- }
-
-static struct adm5120_pci_irq default_pci_irqs[] __initdata = {
- PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
-};
-
-static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
- PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
- PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
- PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
-};
-
-static struct adm5120_pci_irq cas771_pci_irqs[] __initdata = {
- PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
- PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI1),
- PCIIRQ(3, 2, 3, ADM5120_IRQ_PCI2)
-};
-
-static struct adm5120_pci_irq np28g_pci_irqs[] __initdata = {
- PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
- PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI0),
- PCIIRQ(3, 1, 2, ADM5120_IRQ_PCI1),
- PCIIRQ(3, 2, 3, ADM5120_IRQ_PCI2)
-};
-
-#define GETMAP(n) do { \
- nr_irqs = ARRAY_SIZE(n ## _pci_irqs); \
- p = n ## _pci_irqs; \
- } while (0)
+void __init adm5120_pci_set_irq_map(unsigned int nr_irqs,
+ struct adm5120_pci_irq *map)
+{
+ adm5120_pci_nr_irqs = nr_irqs;
+ adm5120_pci_irq_map = map;
+}
-int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
{
- struct adm5120_pci_irq *p;
- int nr_irqs;
+ int irq = -1;
int i;
- int irq;
- irq = -1;
+ if ((!adm5120_pci_nr_irqs) || (!adm5120_pci_irq_map)) {
+ printk(KERN_ALERT "PCI: pci_irq_map is not initialized\n");
+ goto out;
+ }
+
if (slot < 1 || slot > 3) {
printk(KERN_ALERT "PCI: slot number %u is not supported\n",
slot);
goto out;
}
- GETMAP(default);
-
- switch (mips_machtype) {
- case MACH_ADM5120_RB_111:
- case MACH_ADM5120_RB_112:
- case MACH_ADM5120_RB_133:
- case MACH_ADM5120_RB_133C:
- case MACH_ADM5120_RB_153:
- GETMAP(rb1xx);
- break;
- case MACH_ADM5120_NP28G:
- GETMAP(np28g);
- break;
- case MACH_ADM5120_P335:
- case MACH_ADM5120_P334WT:
- /* using default mapping */
- break;
- case MACH_ADM5120_CAS771:
- GETMAP(cas771);
- break;
-
- case MACH_ADM5120_NP27G:
- case MACH_ADM5120_NP28GHS:
- case MACH_ADM5120_WP54AG:
- case MACH_ADM5120_WP54G:
- case MACH_ADM5120_WP54G_WRT:
- case MACH_ADM5120_WPP54AG:
- case MACH_ADM5120_WPP54G:
- default:
- printk(KERN_ALERT "PCI: irq map is unknown, using defaults.\n");
- break;
- }
-
- for (i = 0; i < nr_irqs; i++, p++) {
- if ((p->slot == slot) && (PCI_FUNC(dev->devfn) == p->func) &&
- (p->pin == pin)) {
- irq = p->irq;
+ for (i = 0; i < adm5120_pci_nr_irqs; i++) {
+ if ((adm5120_pci_irq_map[i].slot == slot)
+ && (adm5120_pci_irq_map[i].func == PCI_FUNC(dev->devfn))
+ && (adm5120_pci_irq_map[i].pin == pin)) {
+ irq = adm5120_pci_irq_map[i].irq;
break;
}
}
if (irq < 0) {
printk(KERN_ALERT "PCI: no irq found for %s pin:%u\n",
- pci_name(dev), pin);
+ pci_name((struct pci_dev *)dev), pin);
} else {
printk(KERN_INFO "PCI: mapping irq for %s pin:%u, irq:%d\n",
- pci_name(dev), pin, irq);
+ pci_name((struct pci_dev *)dev), pin, irq);
}
out: