3 * BRIEF MODULE DESCRIPTION
4 * IT8172 system controller specific pci support.
6 * Copyright 2000 MontaVista Software Inc.
7 * Author: MontaVista Software, Inc.
8 * ppopov@mvista.com or source@mvista.com
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include <linux/types.h>
31 #include <linux/pci.h>
32 #include <linux/kernel.h>
33 #include <linux/init.h>
35 #include <asm/pci_channel.h>
36 #include <asm/it8172/it8172.h>
37 #include <asm/it8172/it8172_pci.h>
39 #define PCI_ACCESS_READ 0
40 #define PCI_ACCESS_WRITE 1
44 #define DBG(x...) printk(x)
49 static struct resource pci_mem_resource_1
;
51 static struct resource pci_io_resource
= {
58 static struct resource pci_mem_resource_0
= {
59 "ext pci memory space 0/1",
68 static struct resource pci_mem_resource_1
= {
69 "ext pci memory space 2/3",
78 extern struct pci_ops it8172_pci_ops
;
80 struct pci_channel mips_pci_channels
[] = {
81 {&it8172_pci_ops
, &pci_io_resource
, &pci_mem_resource_0
, 0x10,
83 {NULL
, NULL
, NULL
, NULL
, NULL
}
86 static int it8172_pcibios_config_access(unsigned char access_type
,
88 unsigned int devfn
, int where
,
92 * config cycles are on 4 byte boundary only
96 IT_WRITE(IT_CONFADDR
, (bus
->number
<< IT_BUSNUM_SHF
) |
97 (devfn
<< IT_FUNCNUM_SHF
) | (where
& ~0x3));
99 if (access_type
== PCI_ACCESS_WRITE
) {
100 IT_WRITE(IT_CONFDATA
, *data
);
102 IT_READ(IT_CONFDATA
, *data
);
106 * Revisit: check for master or target abort.
113 * We can't address 8 and 16 bit words directly. Instead we have to
114 * read/write a 32bit word and mask/modify the data we actually want.
116 static write_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
123 if (it8172_pcibios_config_access
124 (PCI_ACCESS_READ
, dev
, where
, &data
))
127 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
129 return PCIBIOS_SUCCESSFUL
;
134 return PCIBIOS_BAD_REGISTER_NUMBER
;
136 if (it8172_pcibios_config_access
137 (PCI_ACCESS_READ
, dev
, where
, &data
))
140 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
141 DBG("cfg read word: bus %d dev_fn %x where %x: val %x\n",
142 dev
->bus
->number
, dev
->devfn
, where
, *val
);
144 return PCIBIOS_SUCCESSFUL
;
149 return PCIBIOS_BAD_REGISTER_NUMBER
;
151 if (it8172_pcibios_config_access
152 (PCI_ACCESS_READ
, dev
, where
, &data
))
157 return PCIBIOS_SUCCESSFUL
;
162 static write_config(struct pci_bus
*bus
, unsigned int devfn
, int where
,
169 if (it8172_pcibios_config_access
170 (PCI_ACCESS_READ
, dev
, where
, &data
))
173 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
174 (val
<< ((where
& 3) << 3));
176 if (it8172_pcibios_config_access
177 (PCI_ACCESS_WRITE
, dev
, where
, &data
))
180 return PCIBIOS_SUCCESSFUL
;
184 return PCIBIOS_BAD_REGISTER_NUMBER
;
186 if (it8172_pcibios_config_access
187 (PCI_ACCESS_READ
, dev
, where
, &data
))
190 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
191 (val
<< ((where
& 3) << 3));
193 if (it8172_pcibios_config_access
194 (PCI_ACCESS_WRITE
, dev
, where
, &data
))
197 return PCIBIOS_SUCCESSFUL
;
201 return PCIBIOS_BAD_REGISTER_NUMBER
;
203 if (it8172_pcibios_config_access
204 (PCI_ACCESS_WRITE
, dev
, where
, &val
))
207 return PCIBIOS_SUCCESSFUL
;
211 struct pci_ops it8172_pci_ops
= {
213 .write
= write_config
,
216 unsigned __init
int pcibios_assign_all_busses(void)