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.
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/msc01_pci.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 msc_pcibios_config_access(unsigned char access_type,
45 struct pci_bus *bus, unsigned int devfn, int where, u32 * data)
47 unsigned char busnum = bus->number;
51 if ((busnum == 0) && (PCI_SLOT(devfn) == 0))
54 /* Clear status register bits. */
55 MSC_WRITE(MSC01_PCI_INTSTAT,
56 (MSC01_PCI_INTCFG_MA_BIT | MSC01_PCI_INTCFG_TA_BIT));
60 type = 0; /* Type 0 */
62 type = 1; /* Type 1 */
64 MSC_WRITE(MSC01_PCI_CFGADDR,
65 ((busnum << MSC01_PCI_CFGADDR_BNUM_SHF) |
66 (PCI_SLOT(devfn) << MSC01_PCI_CFGADDR_DNUM_SHF)
68 MSC01_PCI_CFGADDR_FNUM_SHF) | ((where /
70 MSC01_PCI_CFGADDR_RNUM_SHF)
74 if (access_type == PCI_ACCESS_WRITE)
75 MSC_WRITE(MSC01_PCI_CFGDATA, *data);
77 MSC_READ(MSC01_PCI_CFGDATA, *data);
79 /* Detect Master/Target abort */
80 MSC_READ(MSC01_PCI_INTSTAT, intr);
81 if (intr & (MSC01_PCI_INTCFG_MA_BIT |
82 MSC01_PCI_INTCFG_TA_BIT)) {
86 MSC_READ(MSC01_PCI_INTSTAT, intr);
87 MSC_WRITE(MSC01_PCI_INTSTAT,
88 (MSC01_PCI_INTCFG_MA_BIT |
89 MSC01_PCI_INTCFG_TA_BIT));
99 * We can't address 8 and 16 bit words directly. Instead we have to
100 * read/write a 32bit word and mask/modify the data we actually want.
102 static int msc_pcibios_read(struct pci_bus *bus, unsigned int devfn,
103 int where, int size, u32 * val)
107 if ((size == 2) && (where & 1))
108 return PCIBIOS_BAD_REGISTER_NUMBER;
109 else if ((size == 4) && (where & 3))
110 return PCIBIOS_BAD_REGISTER_NUMBER;
112 if (msc_pcibios_config_access(PCI_ACCESS_READ, bus, devfn, where,
117 *val = (data >> ((where & 3) << 3)) & 0xff;
119 *val = (data >> ((where & 3) << 3)) & 0xffff;
123 return PCIBIOS_SUCCESSFUL;
126 static int msc_pcibios_write(struct pci_bus *bus, unsigned int devfn,
127 int where, int size, u32 val)
131 if ((size == 2) && (where & 1))
132 return PCIBIOS_BAD_REGISTER_NUMBER;
133 else if ((size == 4) && (where & 3))
134 return PCIBIOS_BAD_REGISTER_NUMBER;
139 if (msc_pcibios_config_access(PCI_ACCESS_READ, bus, devfn,
144 data = (data & ~(0xff << ((where & 3) << 3))) |
145 (val << ((where & 3) << 3));
147 data = (data & ~(0xffff << ((where & 3) << 3))) |
148 (val << ((where & 3) << 3));
151 if (msc_pcibios_config_access(PCI_ACCESS_WRITE, bus, devfn, where,
155 return PCIBIOS_SUCCESSFUL;
158 struct pci_ops msc_pci_ops = {
159 .read = msc_pcibios_read,
160 .write = msc_pcibios_write