1 /**************************************************************************
3 * BRIEF MODULE DESCRIPTION
4 * pci_ops for IDT EB434 board
6 * Copyright 2004 IDT Inc. (rischelp@idt.com)
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 **************************************************************************
36 **************************************************************************
39 #include <linux/autoconf.h>
40 #include <linux/init.h>
41 #include <linux/pci.h>
42 #include <linux/types.h>
43 #include <linux/delay.h>
48 #include <asm/idt-boards/rc32434/rc32434.h>
49 #include <asm/idt-boards/rc32434/rc32434_pci.h>
51 #define PCI_ACCESS_READ 0
52 #define PCI_ACCESS_WRITE 1
55 #define PCI_CFG_SET(slot,func,off) \
56 (rc32434_pci->pcicfga = (0x80000000 | ((slot)<<11) | \
59 static int config_access(unsigned char access_type, struct pci_bus *bus,
60 unsigned int devfn, unsigned char where,
64 * config cycles are on 4 byte boundary only
66 unsigned int slot = PCI_SLOT(devfn);
67 u8 func = PCI_FUNC(devfn);
69 if (slot < 2 || slot > 15) {
74 PCI_CFG_SET(slot, func, where);
77 if (access_type == PCI_ACCESS_WRITE) {
79 rc32434_pci->pcicfgd = *data;
82 *data = rc32434_pci->pcicfgd;
92 * We can't address 8 and 16 bit words directly. Instead we have to
93 * read/write a 32bit word and mask/modify the data we actually want.
95 static int read_config_byte(struct pci_bus *bus, unsigned int devfn,
101 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
102 *val = (data >> ((where & 3) << 3)) & 0xff;
106 static int read_config_word(struct pci_bus *bus, unsigned int devfn,
107 int where, u16 * val)
112 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, &data);
113 *val = (data >> ((where & 3) << 3)) & 0xffff;
117 static int read_config_dword(struct pci_bus *bus, unsigned int devfn,
118 int where, u32 * val)
122 ret = config_access(PCI_ACCESS_READ, bus, devfn, where, val);
127 write_config_byte(struct pci_bus *bus, unsigned int devfn, int where,
132 if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
135 data = (data & ~(0xff << ((where & 3) << 3))) |
136 (val << ((where & 3) << 3));
138 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
141 return PCIBIOS_SUCCESSFUL;
146 write_config_word(struct pci_bus *bus, unsigned int devfn, int where,
151 if (config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
154 data = (data & ~(0xffff << ((where & 3) << 3))) |
155 (val << ((where & 3) << 3));
157 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
161 return PCIBIOS_SUCCESSFUL;
166 write_config_dword(struct pci_bus *bus, unsigned int devfn, int where,
169 if (config_access(PCI_ACCESS_WRITE, bus, devfn, where, &val))
172 return PCIBIOS_SUCCESSFUL;
175 static int pci_config_read(struct pci_bus *bus, unsigned int devfn,
176 int where, int size, u32 * val)
180 return read_config_byte(bus, devfn, where, (u8 *) val);
182 return read_config_word(bus, devfn, where, (u16 *) val);
184 return read_config_dword(bus, devfn, where, val);
188 static int pci_config_write(struct pci_bus *bus, unsigned int devfn,
189 int where, int size, u32 val)
193 return write_config_byte(bus, devfn, where, (u8) val);
195 return write_config_word(bus, devfn, where, (u16) val);
197 return write_config_dword(bus, devfn, where, val);
201 struct pci_ops rc32434_pci_ops = {
202 .read = pci_config_read,
203 .write = pci_config_write,