4 * ADM5120 specific PCI operations
6 * Copyright (C) ADMtek Incorporated.
7 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
8 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
9 * Copyright (C) 2007 OpenWrt.org
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
28 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/pci.h>
31 #include <linux/spinlock.h>
33 #include <asm/mach-adm5120/adm5120_defs.h>
37 #define DBG(f, ...) printk(f, ## __VA_ARGS__ )
42 #define PCI_ENABLE 0x80000000
44 static spinlock_t pci_lock = SPIN_LOCK_UNLOCKED;
46 static inline void write_cfgaddr(u32 addr)
48 *(volatile u32*)KSEG1ADDR(ADM5120_PCICFG_ADDR) = (addr | PCI_ENABLE);
51 static inline void write_cfgdata(u32 data)
53 *(volatile u32*)KSEG1ADDR(ADM5120_PCICFG_DATA) = data;
57 static inline u32 read_cfgdata(void)
59 return (*(volatile u32*)KSEG1ADDR(ADM5120_PCICFG_DATA));
62 static inline u32 mkaddr(struct pci_bus *bus, unsigned int devfn, int where)
64 return (((bus->number & 0xFF) << 16) | ((devfn & 0xFF) << 8) | \
68 static int pci_config_read(struct pci_bus *bus, unsigned int devfn, int where,
74 spin_lock_irqsave(&pci_lock, flags);
75 write_cfgaddr(mkaddr(bus,devfn,where));
76 data = read_cfgdata();
78 DBG("PCI: cfg_read %02u.%02u.%01u/%02X:%01d, cfg:0x%08X",
79 bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, data);
97 DBG(", 0x%08X returned\n", data);
98 spin_unlock_irqrestore(&pci_lock, flags);
100 return PCIBIOS_SUCCESSFUL;
103 static int pci_config_write(struct pci_bus *bus, unsigned int devfn, int where,
110 spin_lock_irqsave(&pci_lock, flags);
111 write_cfgaddr(mkaddr(bus,devfn,where));
112 data = read_cfgdata();
114 DBG("PCI: cfg_write %02u.%02u.%01u/%02X:%01d, cfg:0x%08X",
115 bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, data);
119 s = ((where & 3) << 3);
120 data &= ~(0xFF << s);
121 data |= ((val & 0xFF) << s);
124 s = ((where & 2) << 4);
125 data &= ~(0xFFFF << s);
126 data |= ((val & 0xFFFF) << s);
134 DBG(", 0x%08X written\n", data);
135 spin_unlock_irqrestore(&pci_lock, flags);
137 return PCIBIOS_SUCCESSFUL;
140 struct pci_ops adm5120_pci_ops = {
141 .read = pci_config_read,
142 .write = pci_config_write,