2 * arch/mips/pci/ops-emma2rh.c
3 * This file defines the PCI operation for EMMA2RH.
5 * Copyright (C) NEC Electronics Corporation 2004-2006
7 * This file is based on the arch/mips/pci/ops-vr41xx.c
9 * Copyright 2001 MontaVista Software Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/config.h>
27 #include <linux/pci.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
31 #include <asm/addrspace.h>
32 #include <asm/debug.h>
34 #include <asm/emma2rh/emma2rh.h>
36 #define RTABORT (0x1<<9)
37 #define RMABORT (0x1<<10)
38 #define EMMA2RH_PCI_SLOT_NUM 9 /* 0000:09.0 is final PCI device */
44 static int check_args(struct pci_bus *bus, u32 devfn, u32 * bus_num)
46 /* check if the bus is top-level */
47 if (bus->parent != NULL) {
48 *bus_num = bus->number;
49 db_assert(bus_num != 0);
55 if (PCI_SLOT(devfn) >= 10)
56 return PCIBIOS_DEVICE_NOT_FOUND;
59 if ((*bus_num >= 64) || (PCI_SLOT(devfn) >= 16))
60 return PCIBIOS_DEVICE_NOT_FOUND;
65 static inline int set_pci_configuration_address(unsigned char bus_num,
66 unsigned int devfn, int where)
70 emma2rh_out32(EMMA2RH_PCI_INT, ~RMABORT);
73 * Type 0 configuration
75 config_win0 = (1 << (22 + PCI_SLOT(devfn))) | (5 << 9);
78 * Type 1 configuration
80 config_win0 = (bus_num << 26) | (PCI_SLOT(devfn) << 22) |
83 emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, config_win0);
88 static int pci_config_read(struct pci_bus *bus, unsigned int devfn, int where,
89 int size, uint32_t * val)
92 u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
98 if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
99 return PCIBIOS_DEVICE_NOT_FOUND;
101 backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
103 if (set_pci_configuration_address(bus_num, devfn, where) < 0)
104 return PCIBIOS_DEVICE_NOT_FOUND;
107 *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
108 (where & 0xfffffffc));
112 *val = (data >> ((where & 3) << 3)) & 0xffU;
115 *val = (data >> ((where & 2) << 3)) & 0xffffU;
121 emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
122 return PCIBIOS_FUNC_NOT_SUPPORTED;
125 emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
127 if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
128 return PCIBIOS_DEVICE_NOT_FOUND;
130 return PCIBIOS_SUCCESSFUL;
133 static int pci_config_write(struct pci_bus *bus, unsigned int devfn, int where,
137 u32 base = KSEG1ADDR(EMMA2RH_PCI_CONFIG_BASE);
142 if (check_args(bus, devfn, &bus_num) == PCIBIOS_DEVICE_NOT_FOUND)
143 return PCIBIOS_DEVICE_NOT_FOUND;
145 backup_win0 = emma2rh_in32(EMMA2RH_PCI_IWIN0_CTR);
147 if (set_pci_configuration_address(bus_num, devfn, where) < 0)
148 return PCIBIOS_DEVICE_NOT_FOUND;
150 /* read modify write */
152 *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
153 (where & 0xfffffffc));
157 shift = (where & 3) << 3;
158 data &= ~(0xffU << shift);
159 data |= ((val & 0xffU) << shift);
162 shift = (where & 2) << 3;
163 data &= ~(0xffffU << shift);
164 data |= ((val & 0xffffU) << shift);
170 emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
171 return PCIBIOS_FUNC_NOT_SUPPORTED;
173 *(volatile u32 *)(base + (PCI_FUNC(devfn) << 8) +
174 (where & 0xfffffffc)) = data;
176 emma2rh_out32(EMMA2RH_PCI_IWIN0_CTR, backup_win0);
177 if (emma2rh_in32(EMMA2RH_PCI_INT) & RMABORT)
178 return PCIBIOS_DEVICE_NOT_FOUND;
180 return PCIBIOS_SUCCESSFUL;
183 struct pci_ops emma2rh_pci_ops = {
184 .read = pci_config_read,
185 .write = pci_config_write,