2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999, 2000 MIPS Technologies, Inc. All rights reserved.
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 * MIPS boards specific PCI support.
20 #include <linux/config.h>
21 #include <linux/types.h>
22 #include <linux/pci.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
26 #include <asm/mips-boards/bonito64.h>
28 #define PCI_ACCESS_READ 0
29 #define PCI_ACCESS_WRITE 1
32 * PCI configuration cycle AD bus definition
35 #define PCI_CFG_TYPE0_REG_SHF 0
36 #define PCI_CFG_TYPE0_FUNC_SHF 8
39 #define PCI_CFG_TYPE1_REG_SHF 0
40 #define PCI_CFG_TYPE1_FUNC_SHF 8
41 #define PCI_CFG_TYPE1_DEV_SHF 11
42 #define PCI_CFG_TYPE1_BUS_SHF 16
44 static int bonito64_pcibios_config_access(unsigned char access_type
,
46 unsigned int devfn
, int where
,
49 unsigned char busnum
= bus
->number
;
53 /* Algorithmics Bonito64 system controller. */
55 if ((busnum
== 0) && (PCI_SLOT(devfn
) > 21)) {
56 /* We number bus 0 devices from 0..21 */
60 #ifdef CONFIG_MIPS_BOARDS_GEN
61 if ((busnum
== 0) && (PCI_SLOT(devfn
) == 17)) {
62 /* MIPS Core boards have Bonito connected as device 17 */
67 /* Clear cause register bits */
68 BONITO_PCICMD
|= (BONITO_PCICMD_MABORT_CLR
|
69 BONITO_PCICMD_MTABORT_CLR
);
72 * Setup pattern to be used as PCI "address" for
77 pci_addr
= (u64
) 1 << (PCI_SLOT(devfn
) + 10);
80 pci_addr
= busnum
<< PCI_CFG_TYPE1_BUS_SHF
;
84 PCI_SLOT(devfn
) << PCI_CFG_TYPE1_DEV_SHF
;
87 /* Function (same for Type 0/1) */
88 pci_addr
|= PCI_FUNC(devfn
) << PCI_CFG_TYPE0_FUNC_SHF
;
90 /* Register number (same for Type 0/1) */
91 pci_addr
|= (where
& ~0x3) << PCI_CFG_TYPE0_REG_SHF
;
95 BONITO_PCIMAP_CFG
= pci_addr
>> 16;
98 BONITO_PCIMAP_CFG
= (pci_addr
>> 16) | 0x10000;
103 /* Flush Bonito register block */
104 dummy
= BONITO_PCIMAP_CFG
;
108 if (access_type
== PCI_ACCESS_WRITE
) {
109 *(volatile u32
*) (_pcictrl_bonito_pcicfg
+ (u32
)pci_addr
) = *(u32
*) data
;
112 while (BONITO_PCIMSTAT
& 0xF);
114 *(u32
*) data
= *(volatile u32
*) (_pcictrl_bonito_pcicfg
+ (u32
)pci_addr
);
117 /* Detect Master/Target abort */
118 if (BONITO_PCICMD
& (BONITO_PCICMD_MABORT_CLR
|
119 BONITO_PCICMD_MTABORT_CLR
)) {
123 BONITO_PCICMD
|= (BONITO_PCICMD_MABORT_CLR
|
124 BONITO_PCICMD_MTABORT_CLR
);
134 * We can't address 8 and 16 bit words directly. Instead we have to
135 * read/write a 32bit word and mask/modify the data we actually want.
137 static int bonito64_pcibios_read(struct pci_bus
*bus
, unsigned int devfn
,
138 int where
, int size
, u32
* val
)
142 if ((size
== 2) && (where
& 1))
143 return PCIBIOS_BAD_REGISTER_NUMBER
;
144 else if ((size
== 4) && (where
& 3))
145 return PCIBIOS_BAD_REGISTER_NUMBER
;
147 if (bonito64_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
, where
,
152 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
154 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
158 return PCIBIOS_SUCCESSFUL
;
161 static int bonito64_pcibios_write(struct pci_bus
*bus
, unsigned int devfn
,
162 int where
, int size
, u32 val
)
166 if ((size
== 2) && (where
& 1))
167 return PCIBIOS_BAD_REGISTER_NUMBER
;
168 else if ((size
== 4) && (where
& 3))
169 return PCIBIOS_BAD_REGISTER_NUMBER
;
174 if (bonito64_pcibios_config_access(PCI_ACCESS_READ
, bus
, devfn
,
179 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
180 (val
<< ((where
& 3) << 3));
182 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
183 (val
<< ((where
& 3) << 3));
186 if (bonito64_pcibios_config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
,
190 return PCIBIOS_SUCCESSFUL
;
193 struct pci_ops bonito64_pci_ops
= {
194 .read
= bonito64_pcibios_read
,
195 .write
= bonito64_pcibios_write