2 * Define the pci_ops for the Toshiba rbtx4938
3 * Copyright (C) 2000-2001 Toshiba Corporation
5 * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
6 * terms of the GNU General Public License version 2. This program is
7 * licensed "as is" without any warranty of any kind, whether express
10 * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
12 #include <linux/types.h>
13 #include <linux/pci.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
17 #include <asm/addrspace.h>
18 #include <asm/tx4938/rbtx4938.h>
20 /* initialize in setup */
21 struct resource pci_io_resource = {
22 .name = "pci IO space",
25 .flags = IORESOURCE_IO
28 /* initialize in setup */
29 struct resource pci_mem_resource = {
30 .name = "pci memory space",
33 .flags = IORESOURCE_MEM
36 struct resource tx4938_pcic1_pci_io_resource = {
40 .flags = IORESOURCE_IO
42 struct resource tx4938_pcic1_pci_mem_resource = {
46 .flags = IORESOURCE_MEM
49 static int mkaddr(int bus, int dev_fn, int where, int *flagsp)
52 /* Type 1 configuration */
53 tx4938_pcicptr->g2pcfgadrs = ((bus & 0xff) << 0x10) |
54 ((dev_fn & 0xff) << 0x08) | (where & 0xfc) | 1;
56 if (dev_fn >= PCI_DEVFN(TX4938_PCIC_MAX_DEVNU, 0))
59 /* Type 0 configuration */
60 tx4938_pcicptr->g2pcfgadrs = ((bus & 0xff) << 0x10) |
61 ((dev_fn & 0xff) << 0x08) | (where & 0xfc);
63 /* clear M_ABORT and Disable M_ABORT Int. */
64 tx4938_pcicptr->pcistatus =
65 (tx4938_pcicptr->pcistatus & 0x0000ffff) |
66 (PCI_STATUS_REC_MASTER_ABORT << 16);
67 tx4938_pcicptr->pcimask &= ~PCI_STATUS_REC_MASTER_ABORT;
72 static int check_abort(int flags)
74 int code = PCIBIOS_SUCCESSFUL;
75 /* wait write cycle completion before checking error status */
76 while (tx4938_pcicptr->pcicstatus & TX4938_PCIC_PCICSTATUS_IWB)
78 if (tx4938_pcicptr->pcistatus & (PCI_STATUS_REC_MASTER_ABORT << 16)) {
79 tx4938_pcicptr->pcistatus =
81 pcistatus & 0x0000ffff) | (PCI_STATUS_REC_MASTER_ABORT
83 tx4938_pcicptr->pcimask |= PCI_STATUS_REC_MASTER_ABORT;
84 code = PCIBIOS_DEVICE_NOT_FOUND;
89 static int tx4938_pcibios_read_config(struct pci_bus *bus, unsigned int devfn,
90 int where, int size, u32 * val)
92 int flags, retval, dev, busno, func;
94 dev = PCI_SLOT(devfn);
95 func = PCI_FUNC(devfn);
97 /* check if the bus is top-level */
98 if (bus->parent != NULL)
104 if (mkaddr(busno, devfn, where, &flags))
109 *val = *(volatile u8 *) ((ulong) & tx4938_pcicptr->g2pcfgdata |
117 *val = *(volatile u16 *) ((ulong) & tx4938_pcicptr->g2pcfgdata |
125 *val = tx4938_pcicptr->g2pcfgdata;
129 retval = check_abort(flags);
130 if (retval == PCIBIOS_DEVICE_NOT_FOUND)
136 static int tx4938_pcibios_write_config(struct pci_bus *bus, unsigned int devfn, int where,
139 int flags, dev, busno, func;
142 dev = PCI_SLOT(devfn);
143 func = PCI_FUNC(devfn);
145 /* check if the bus is top-level */
146 if (bus->parent != NULL) {
152 if (mkaddr(busno, devfn, where, &flags))
157 *(volatile u8 *) ((ulong) & tx4938_pcicptr->g2pcfgdata |
159 ((where & 3) ^ 3)) = val;
165 *(volatile u16 *) ((ulong) & tx4938_pcicptr->g2pcfgdata |
167 ((where & 0x3) ^ 0x2)) = val;
173 tx4938_pcicptr->g2pcfgdata = val;
177 return check_abort(flags);
180 struct pci_ops tx4938_pci_ops = {
181 tx4938_pcibios_read_config,
182 tx4938_pcibios_write_config
185 struct pci_controller tx4938_pci_controller[] = {
186 /* h/w only supports devices 0x00 to 0x14 */
188 .pci_ops = &tx4938_pci_ops,
189 .io_resource = &pci_io_resource,
190 .mem_resource = &pci_mem_resource,
192 /* h/w only supports devices 0x00 to 0x14 */
194 .pci_ops = &tx4938_pci_ops,
195 .io_resource = &tx4938_pcic1_pci_io_resource,
196 .mem_resource = &tx4938_pcic1_pci_mem_resource,