2 * BRIEF MODULE DESCRIPTION
3 * Alchemy/AMD Au1x00 pci support.
5 * Copyright 2001,2002,2003 MontaVista Software Inc.
6 * Author: MontaVista Software, Inc.
7 * ppopov@mvista.com or source@mvista.com
9 * Support for all devices (greater than 16) added by David Gathright.
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include <linux/config.h>
32 #include <linux/types.h>
33 #include <linux/pci.h>
34 #include <linux/kernel.h>
35 #include <linux/init.h>
37 #include <asm/au1000.h>
38 #ifdef CONFIG_MIPS_PB1000
39 #include <asm/pb1000.h>
41 #include <asm/pci_channel.h>
43 #define PCI_ACCESS_READ 0
44 #define PCI_ACCESS_WRITE 1
48 #define DBG(x...) printk(x)
54 static struct resource pci_io_resource
= {
61 static struct resource pci_mem_resource
= {
68 extern struct pci_ops au1x_pci_ops
;
70 struct pci_channel mips_pci_channels
[] = {
71 {&au1x_pci_ops
, &pci_io_resource
, &pci_mem_resource
,
72 PCI_FIRST_DEVFN
, PCI_LAST_DEVFN
},
73 {(struct pci_ops
*) NULL
, (struct resource
*) NULL
,
74 (struct resource
*) NULL
, (int) NULL
, (int) NULL
}
78 #ifdef CONFIG_MIPS_PB1000
80 * "Bus 2" is really the first and only external slot on the pb1000.
81 * We'll call that bus 0, and limit the accesses to that single
82 * external slot only. The SDRAM is already initialized in setup.c.
84 static int config_access(unsigned char access_type
, struct pci_dev
*dev
,
85 unsigned char where
, u32
* data
)
87 unsigned char bus
= dev
->bus
->number
;
88 unsigned char dev_fn
= dev
->devfn
;
91 if (((dev_fn
>> 3) != 0) || (bus
!= 0)) {
96 config
= PCI_CONFIG_BASE
| (where
& ~0x3);
98 if (access_type
== PCI_ACCESS_WRITE
) {
99 au_writel(*data
, config
);
101 *data
= au_readl(config
);
105 DBG("config_access: %d bus %d dev_fn %x at %x *data %x, conf %x\n",
106 access_type
, bus
, dev_fn
, where
, *data
, config
);
108 DBG("bridge config reg: %x (%x)\n", au_readl(PCI_BRIDGE_CONFIG
),
111 if (au_readl(PCI_BRIDGE_CONFIG
) & (1 << 16)) {
115 return PCIBIOS_SUCCESSFUL
;
121 static int config_access(unsigned char access_type
, struct pci_bus
*bus
,
122 unsigned int devfn
, unsigned char where
,
125 #ifdef CONFIG_SOC_AU1500
126 unsigned int device
= PCI_SLOT(devfn
);
127 unsigned int function
= PCI_FUNC(devfn
);
128 unsigned long config
, status
;
129 unsigned long cfg_addr
;
136 au_writel(((0x2000 << 16) |
137 (au_readl(Au1500_PCI_STATCMD
) & 0xffff)),
139 //au_writel(au_readl(Au1500_PCI_CFG) & ~PCI_ERROR, Au1500_PCI_CFG);
142 /* setup the config window */
143 if (bus
->number
== 0) {
144 cfg_addr
= (unsigned long) ioremap(Au1500_EXT_CFG
|
145 ((1 << device
) << 11),
148 cfg_addr
= (unsigned long) ioremap(Au1500_EXT_CFG_TYPE1
|
150 number
<< 16) | (device
157 panic(KERN_ERR
"PCI unable to ioremap cfg space\n");
159 /* setup the lower bits of the 36 bit address */
160 config
= cfg_addr
| (function
<< 8) | (where
& ~0x3);
163 if (access_type
== PCI_ACCESS_WRITE
) {
164 printk("cfg write: ");
166 printk("cfg read: ");
168 printk("devfn %x, device %x func %x \n", devfn
, device
, function
);
169 if (access_type
== PCI_ACCESS_WRITE
) {
170 printk("data %x\n", *data
);
174 if (access_type
== PCI_ACCESS_WRITE
) {
175 au_writel(*data
, config
);
177 *data
= au_readl(config
);
182 DBG("config_access: %d bus %d device %d at %x *data %x, conf %x\n",
183 access_type
, bus
->number
, device
, where
, *data
, config
);
186 iounmap((void *) cfg_addr
);
188 /* check master abort */
189 status
= au_readl(Au1500_PCI_STATCMD
);
191 if (access_type
== PCI_ACCESS_READ
) {
192 printk("read data: %x\n", *data
);
195 if (status
& (1 << 29)) {
198 } else if ((status
>> 28) & 0xf) {
199 printk("PCI ERR detected: status %x\n", status
);
203 return PCIBIOS_SUCCESSFUL
;
209 static int read_config_byte(struct pci_bus
*bus
, unsigned int devfn
,
215 ret
= config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
);
225 static int read_config_word(struct pci_bus
*bus
, unsigned int devfn
,
226 int where
, u16
* val
)
231 ret
= config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
);
234 *val
= data
& 0xffff;
238 static int read_config_dword(struct pci_bus
*bus
, unsigned int devfn
,
239 int where
, u32
* val
)
243 ret
= config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, val
);
248 write_config_byte(struct pci_bus
*bus
, unsigned int devfn
, int where
,
253 if (config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
256 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
257 (val
<< ((where
& 3) << 3));
259 if (config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
262 return PCIBIOS_SUCCESSFUL
;
266 write_config_word(struct pci_bus
*bus
, unsigned int devfn
, int where
,
272 return PCIBIOS_BAD_REGISTER_NUMBER
;
274 if (config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
277 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
278 (val
<< ((where
& 3) << 3));
280 if (config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
284 return PCIBIOS_SUCCESSFUL
;
288 write_config_dword(struct pci_bus
*bus
, unsigned int devfn
, int where
,
292 return PCIBIOS_BAD_REGISTER_NUMBER
;
294 if (config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &val
))
297 return PCIBIOS_SUCCESSFUL
;
300 static int config_read(struct pci_bus
*bus
, unsigned int devfn
,
301 int where
, int size
, u32
* val
)
305 return read_config_byte(bus
, devfn
, where
, (u8
*) val
);
307 return read_config_word(bus
, devfn
, where
, (u16
*) val
);
309 return read_config_dword(bus
, devfn
, where
, val
);
313 static int config_write(struct pci_bus
*bus
, unsigned int devfn
,
314 int where
, int size
, u32 val
)
318 return write_config_byte(bus
, devfn
, where
, (u8
) val
);
320 return write_config_word(bus
, devfn
, where
, (u16
) val
);
322 return write_config_dword(bus
, devfn
, where
, val
);
327 struct pci_ops au1x_pci_ops
= {