2 * arch/ppc/syslib/mpc52xx_pci.c
4 * PCI code for the Freescale MPC52xx embedded CPU.
7 * Maintainer : Sylvain Munaut <tnt@246tNt.com>
9 * Copyright (C) 2004 Sylvain Munaut <tnt@246tNt.com>
11 * This file is licensed under the terms of the GNU General Public License
12 * version 2. This program is licensed "as is" without any warranty of any
13 * kind, whether express or implied.
16 #include <linux/config.h>
20 #include <asm/mpc52xx.h>
21 #include "mpc52xx_pci.h"
23 #include <asm/delay.h>
24 #include <asm/machdep.h>
28 mpc52xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
29 int offset, int len, u32 *val)
31 struct pci_controller *hose = bus->sysdata;
34 if (ppc_md.pci_exclude_device)
35 if (ppc_md.pci_exclude_device(bus->number, devfn))
36 return PCIBIOS_DEVICE_NOT_FOUND;
38 out_be32(hose->cfg_addr,
40 ((bus->number - hose->bus_offset) << 16) |
44 value = in_le32(hose->cfg_data);
47 value >>= ((offset & 0x3) << 3);
48 value &= 0xffffffff >> (32 - (len << 3));
53 out_be32(hose->cfg_addr, 0);
55 return PCIBIOS_SUCCESSFUL;
59 mpc52xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
60 int offset, int len, u32 val)
62 struct pci_controller *hose = bus->sysdata;
65 if (ppc_md.pci_exclude_device)
66 if (ppc_md.pci_exclude_device(bus->number, devfn))
67 return PCIBIOS_DEVICE_NOT_FOUND;
69 out_be32(hose->cfg_addr,
71 ((bus->number - hose->bus_offset) << 16) |
76 value = in_le32(hose->cfg_data);
78 offset = (offset & 0x3) << 3;
79 mask = (0xffffffff >> (32 - (len << 3)));
83 val = value | ((val << offset) & mask);
86 out_le32(hose->cfg_data, val);
88 out_be32(hose->cfg_addr, 0);
90 return PCIBIOS_SUCCESSFUL;
93 static struct pci_ops mpc52xx_pci_ops = {
94 .read = mpc52xx_pci_read_config,
95 .write = mpc52xx_pci_write_config
100 mpc52xx_pci_setup(struct mpc52xx_pci __iomem *pci_regs)
103 /* Setup control regs */
104 /* Nothing to do afaik */
107 out_be32(&pci_regs->iw0btar, MPC52xx_PCI_IWBTAR_TRANSLATION(
108 MPC52xx_PCI_MEM_START + MPC52xx_PCI_MEM_OFFSET,
109 MPC52xx_PCI_MEM_START,
110 MPC52xx_PCI_MEM_SIZE ));
112 out_be32(&pci_regs->iw1btar, MPC52xx_PCI_IWBTAR_TRANSLATION(
113 MPC52xx_PCI_MMIO_START + MPC52xx_PCI_MEM_OFFSET,
114 MPC52xx_PCI_MMIO_START,
115 MPC52xx_PCI_MMIO_SIZE ));
117 out_be32(&pci_regs->iw2btar, MPC52xx_PCI_IWBTAR_TRANSLATION(
119 MPC52xx_PCI_IO_START,
120 MPC52xx_PCI_IO_SIZE ));
122 out_be32(&pci_regs->iwcr, MPC52xx_PCI_IWCR_PACK(
123 ( MPC52xx_PCI_IWCR_ENABLE | /* iw0btar */
124 MPC52xx_PCI_IWCR_READ_MULTI |
125 MPC52xx_PCI_IWCR_MEM ),
126 ( MPC52xx_PCI_IWCR_ENABLE | /* iw1btar */
127 MPC52xx_PCI_IWCR_READ |
128 MPC52xx_PCI_IWCR_MEM ),
129 ( MPC52xx_PCI_IWCR_ENABLE | /* iw2btar */
130 MPC52xx_PCI_IWCR_IO )
134 out_be32(&pci_regs->tbatr0,
135 MPC52xx_PCI_TBATR_ENABLE | MPC52xx_PCI_TARGET_IO );
136 out_be32(&pci_regs->tbatr1,
137 MPC52xx_PCI_TBATR_ENABLE | MPC52xx_PCI_TARGET_MEM );
139 out_be32(&pci_regs->tcr, MPC52xx_PCI_TCR_LD);
141 /* Reset the exteral bus ( internal PCI controller is NOT resetted ) */
142 /* Not necessary and can be a bad thing if for example the bootloader
143 is displaying a splash screen or ... Just left here for
144 documentation purpose if anyone need it */
147 tmp = in_be32(&pci_regs->gscr);
148 out_be32(&pci_regs->gscr, tmp | MPC52xx_PCI_GSCR_PR);
150 out_be32(&pci_regs->gscr, tmp);
155 mpc52xx_pci_fixup_resources(struct pci_dev *dev)
159 /* We don't rely on boot loader for PCI and resets all
161 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
162 struct resource *res = &dev->resource[i];
163 if (res->end > res->start) { /* Only valid resources */
164 res->end -= res->start;
166 res->flags |= IORESOURCE_UNSET;
170 /* The PCI Host bridge of MPC52xx has a prefetch memory resource
171 fixed to 1Gb. Doesn't fit in the resource system so we remove it */
172 if ( (dev->vendor == PCI_VENDOR_ID_MOTOROLA) &&
173 (dev->device == PCI_DEVICE_ID_MOTOROLA_MPC5200) ) {
174 struct resource *res = &dev->resource[1];
175 res->start = res->end = res->flags = 0;
180 mpc52xx_find_bridges(void)
182 struct mpc52xx_pci __iomem *pci_regs;
183 struct pci_controller *hose;
185 pci_assign_all_buses = 1;
187 pci_regs = ioremap(MPC52xx_PA(MPC52xx_PCI_OFFSET), MPC52xx_PCI_SIZE);
191 hose = pcibios_alloc_controller();
197 ppc_md.pci_swizzle = common_swizzle;
198 ppc_md.pcibios_fixup_resources = mpc52xx_pci_fixup_resources;
200 hose->first_busno = 0;
201 hose->last_busno = 0xff;
202 hose->bus_offset = 0;
203 hose->ops = &mpc52xx_pci_ops;
205 mpc52xx_pci_setup(pci_regs);
207 hose->pci_mem_offset = MPC52xx_PCI_MEM_OFFSET;
209 hose->io_base_virt = ioremap(MPC52xx_PCI_IO_BASE, MPC52xx_PCI_IO_SIZE);
210 isa_io_base = (unsigned long) hose->io_base_virt;
212 hose->cfg_addr = &pci_regs->car;
213 hose->cfg_data = hose->io_base_virt;
215 /* Setup resources */
216 pci_init_resource(&hose->mem_resources[0],
217 MPC52xx_PCI_MEM_START,
218 MPC52xx_PCI_MEM_STOP,
219 IORESOURCE_MEM|IORESOURCE_PREFETCH,
220 "PCI prefetchable memory");
222 pci_init_resource(&hose->mem_resources[1],
223 MPC52xx_PCI_MMIO_START,
224 MPC52xx_PCI_MMIO_STOP,
228 pci_init_resource(&hose->io_resource,
229 MPC52xx_PCI_IO_START,