2 * Copyright (C) 2006 PA Semi, Inc
4 * Authors: Kip Walker, PA Semi
5 * Olof Johansson, PA Semi
7 * Maintained by: Olof Johansson <olof@lixom.net>
9 * Based on arch/powerpc/platforms/maple/pci.c
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/kernel.h>
27 #include <linux/pci.h>
29 #include <asm/pci-bridge.h>
30 #include <asm/machdep.h>
32 #include <asm/ppc-pci.h>
34 #define PA_PXP_CFA(bus, devfn, off) (((bus) << 20) | ((devfn) << 12) | (off))
36 static inline int pa_pxp_offset_valid(u8 bus
, u8 devfn
, int offset
)
38 /* Device 0 Function 0 is special: It's config space spans function 1 as
39 * well, so allow larger offset. It's really a two-function device but the
40 * second function does not probe.
42 if (bus
== 0 && devfn
== 0)
48 static void volatile __iomem
*pa_pxp_cfg_addr(struct pci_controller
*hose
,
49 u8 bus
, u8 devfn
, int offset
)
51 return hose
->cfg_data
+ PA_PXP_CFA(bus
, devfn
, offset
);
54 static inline int is_root_port(int busno
, int devfn
)
56 return ((busno
== 0) && (PCI_FUNC(devfn
) < 4) &&
57 ((PCI_SLOT(devfn
) == 16) || (PCI_SLOT(devfn
) == 17)));
60 static inline int is_5945_reg(int reg
)
62 return (((reg
>= 0x18) && (reg
< 0x34)) ||
63 ((reg
>= 0x158) && (reg
< 0x178)));
66 static int workaround_5945(struct pci_bus
*bus
, unsigned int devfn
,
67 int offset
, int len
, u32
*val
)
69 struct pci_controller
*hose
;
70 void volatile __iomem
*addr
, *dummy
;
74 if (!is_root_port(bus
->number
, devfn
) || !is_5945_reg(offset
))
77 hose
= pci_bus_to_host(bus
);
79 addr
= pa_pxp_cfg_addr(hose
, bus
->number
, devfn
, offset
& ~0x3);
82 /* Workaround bug 5945: write 0 to a dummy register before reading,
83 * and write back what we read. We must read/write the full 32-bit
84 * contents so we need to shift and mask by hand.
86 dummy
= pa_pxp_cfg_addr(hose
, bus
->number
, devfn
, 0x10);
93 *val
= (tmp
>> (8*byte
)) & 0xff;
99 *val
= (tmp
>> 16) & 0xffff;
109 static int pa_pxp_read_config(struct pci_bus
*bus
, unsigned int devfn
,
110 int offset
, int len
, u32
*val
)
112 struct pci_controller
*hose
;
113 void volatile __iomem
*addr
;
115 hose
= pci_bus_to_host(bus
);
117 return PCIBIOS_DEVICE_NOT_FOUND
;
119 if (!pa_pxp_offset_valid(bus
->number
, devfn
, offset
))
120 return PCIBIOS_BAD_REGISTER_NUMBER
;
122 if (workaround_5945(bus
, devfn
, offset
, len
, val
))
123 return PCIBIOS_SUCCESSFUL
;
125 addr
= pa_pxp_cfg_addr(hose
, bus
->number
, devfn
, offset
);
128 * Note: the caller has already checked that offset is
129 * suitably aligned and that len is 1, 2 or 4.
136 *val
= in_le16(addr
);
139 *val
= in_le32(addr
);
143 return PCIBIOS_SUCCESSFUL
;
146 static int pa_pxp_write_config(struct pci_bus
*bus
, unsigned int devfn
,
147 int offset
, int len
, u32 val
)
149 struct pci_controller
*hose
;
150 void volatile __iomem
*addr
;
152 hose
= pci_bus_to_host(bus
);
154 return PCIBIOS_DEVICE_NOT_FOUND
;
156 if (!pa_pxp_offset_valid(bus
->number
, devfn
, offset
))
157 return PCIBIOS_BAD_REGISTER_NUMBER
;
159 addr
= pa_pxp_cfg_addr(hose
, bus
->number
, devfn
, offset
);
162 * Note: the caller has already checked that offset is
163 * suitably aligned and that len is 1, 2 or 4.
176 return PCIBIOS_SUCCESSFUL
;
179 static struct pci_ops pa_pxp_ops
= {
180 .read
= pa_pxp_read_config
,
181 .write
= pa_pxp_write_config
,
184 static void __init
setup_pa_pxp(struct pci_controller
*hose
)
186 hose
->ops
= &pa_pxp_ops
;
187 hose
->cfg_data
= ioremap(0xe0000000, 0x10000000);
190 static int __init
pas_add_bridge(struct device_node
*dev
)
192 struct pci_controller
*hose
;
194 pr_debug("Adding PCI host bridge %s\n", dev
->full_name
);
196 hose
= pcibios_alloc_controller(dev
);
200 hose
->first_busno
= 0;
201 hose
->last_busno
= 0xff;
205 printk(KERN_INFO
"Found PA-PXP PCI host bridge.\n");
207 /* Interpret the "ranges" property */
208 pci_process_bridge_OF_ranges(hose
, dev
, 1);
213 void __init
pas_pci_init(void)
215 struct device_node
*np
, *root
;
217 root
= of_find_node_by_path("/");
219 printk(KERN_CRIT
"pas_pci_init: can't find root "
224 for (np
= NULL
; (np
= of_get_next_child(root
, np
)) != NULL
;)
225 if (np
->name
&& !strcmp(np
->name
, "pxp") && !pas_add_bridge(np
))
230 /* Setup the linkage between OF nodes and PHBs */
233 /* Use the common resource allocation mechanism */
237 void __iomem
*pasemi_pci_getcfgaddr(struct pci_dev
*dev
, int offset
)
239 struct pci_controller
*hose
;
241 hose
= pci_bus_to_host(dev
->bus
);
243 return (void __iomem
*)pa_pxp_cfg_addr(hose
, dev
->bus
->number
, dev
->devfn
, offset
);