1 /**************************************************************************
3 * BRIEF MODULE DESCRIPTION
4 * pci_ops for IDT EB434 board
6 * Copyright 2004 IDT Inc. (rischelp@idt.com)
7 * Copyright 2006 Felix Fietkau <nbd@openwrt.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
20 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 **************************************************************************
37 **************************************************************************
40 #include <linux/autoconf.h>
41 #include <linux/init.h>
42 #include <linux/pci.h>
43 #include <linux/types.h>
44 #include <linux/delay.h>
49 #include <asm/rc32434/rc32434.h>
50 #include <asm/rc32434/pci.h>
52 #define PCI_ACCESS_READ 0
53 #define PCI_ACCESS_WRITE 1
56 #define PCI_CFG_SET(bus,slot,func,off) \
57 (rc32434_pci->pcicfga = (0x80000000 | \
58 ((bus) << 16) | ((slot)<<11) | \
61 static inline int config_access(unsigned char access_type, struct pci_bus *bus,
62 unsigned int devfn, unsigned char where,
65 unsigned int slot = PCI_SLOT(devfn);
66 u8 func = PCI_FUNC(devfn);
69 PCI_CFG_SET(bus->number, slot, func, where);
72 if (access_type == PCI_ACCESS_WRITE)
73 rc32434_pci->pcicfgd = *data;
75 *data = rc32434_pci->pcicfgd;
84 * We can't address 8 and 16 bit words directly. Instead we have to
85 * read/write a 32bit word and mask/modify the data we actually want.
87 static int read_config_byte(struct pci_bus *bus, unsigned int devfn,
93 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
94 *val = (data >> ((where & 3) << 3)) & 0xff;
98 static int read_config_word(struct pci_bus *bus, unsigned int devfn,
104 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
105 *val = (data >> ((where & 3) << 3)) & 0xffff;
109 static int read_config_dword(struct pci_bus *bus, unsigned int devfn,
110 int where, u32 * val)
115 if (bus->number == 0 && PCI_SLOT(devfn) > 21)
119 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, val);
121 /* PCI scan: check for invalid values, device may not have
122 * finished initializing */
124 if (where == PCI_VENDOR_ID) {
125 if (ret == 0xffffffff || ret == 0x00000000 ||
126 ret == 0x0000ffff || ret == 0xffff0000) {
141 write_config_byte(struct pci_bus *bus, unsigned int devfn, int where,
146 if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
149 data = (data & ~(0xff << ((where & 3) << 3))) |
150 (val << ((where & 3) << 3));
152 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
155 return PCIBIOS_SUCCESSFUL;
160 write_config_word(struct pci_bus *bus, unsigned int devfn, int where,
165 if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
168 data = (data & ~(0xffff << ((where & 3) << 3))) |
169 (val << ((where & 3) << 3));
171 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
175 return PCIBIOS_SUCCESSFUL;
180 write_config_dword(struct pci_bus *bus, unsigned int devfn, int where,
183 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &val))
186 return PCIBIOS_SUCCESSFUL;
189 static int pci_config_read(struct pci_bus *bus, unsigned int devfn,
190 int where, int size, u32 * val)
194 return read_config_byte(bus, devfn, where, (u8 *) val);
196 return read_config_word(bus, devfn, where, (u16 *) val);
198 return read_config_dword(bus, devfn, where, val);
202 static int pci_config_write(struct pci_bus *bus, unsigned int devfn,
203 int where, int size, u32 val)
207 return write_config_byte(bus, devfn, where, (u8) val);
209 return write_config_word(bus, devfn, where, (u16) val);
211 return write_config_dword(bus, devfn, where, val);
215 struct pci_ops rc32434_pci_ops = {
216 .read = pci_config_read,
217 .write = pci_config_write,