2 * Support for SCC external PCI
4 * (C) Copyright 2004-2007 TOSHIBA CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <linux/kernel.h>
24 #include <linux/threads.h>
25 #include <linux/pci.h>
26 #include <linux/init.h>
27 #include <linux/pci_regs.h>
28 #include <linux/bootmem.h>
33 #include <asm/machdep.h>
34 #include <asm/pci-bridge.h>
35 #include <asm/ppc-pci.h>
39 #include "interrupt.h"
41 #define MAX_PCI_DEVICES 32
42 #define MAX_PCI_FUNCTIONS 8
44 #define iob() __asm__ __volatile__("eieio; sync":::"memory")
47 #if 0 /* test code for epci dummy read */
48 static void celleb_epci_dummy_read(struct pci_dev
*dev
)
51 struct device_node
*node
;
52 struct pci_controller
*hose
;
55 node
= (struct device_node
*)dev
->bus
->sysdata
;
56 hose
= pci_find_hose_for_OF_device(node
);
61 epci_base
= (void *)hose
->cfg_addr
;
63 val
= in_be32(epci_base
+ SCC_EPCI_WATRP
);
70 static inline void clear_and_disable_master_abort_interrupt(
71 struct pci_controller
*hose
)
74 addr
= (void *)hose
->cfg_addr
+ PCI_COMMAND
;
75 out_be32(addr
, in_be32(addr
) | (PCI_STATUS_REC_MASTER_ABORT
<< 16));
78 static int celleb_epci_check_abort(struct pci_controller
*hose
,
81 void __iomem
*reg
, *epci_base
;
85 epci_base
= (void *)hose
->cfg_addr
;
87 reg
= epci_base
+ PCI_COMMAND
;
90 if (val
& (PCI_STATUS_REC_MASTER_ABORT
<< 16)) {
92 (val
& 0xffff) | (PCI_STATUS_REC_MASTER_ABORT
<< 16));
94 /* clear PCI Controller error, FRE, PMFE */
95 reg
= epci_base
+ SCC_EPCI_STATUS
;
96 out_be32(reg
, SCC_EPCI_INT_PAI
);
98 reg
= epci_base
+ SCC_EPCI_VCSR
;
99 val
= in_be32(reg
) & 0xffff;
100 val
|= SCC_EPCI_VCSR_FRE
;
103 reg
= epci_base
+ SCC_EPCI_VISTAT
;
104 out_be32(reg
, SCC_EPCI_VISTAT_PMFE
);
105 return PCIBIOS_DEVICE_NOT_FOUND
;
108 return PCIBIOS_SUCCESSFUL
;
111 static unsigned long celleb_epci_make_config_addr(struct pci_controller
*hose
,
112 unsigned int devfn
, int where
)
115 struct pci_bus
*bus
= hose
->bus
;
118 addr
= (unsigned long)hose
->cfg_data
+
119 (((bus
->number
& 0xff) << 16)
120 | ((devfn
& 0xff) << 8)
124 addr
= (unsigned long)hose
->cfg_data
+
125 (((devfn
& 0xff) << 8) | (where
& 0xff));
127 pr_debug("EPCI: config_addr = 0x%016lx\n", addr
);
132 static int celleb_epci_read_config(struct pci_bus
*bus
,
133 unsigned int devfn
, int where
, int size
, u32
* val
)
136 struct device_node
*node
;
137 struct pci_controller
*hose
;
139 /* allignment check */
140 BUG_ON(where
% size
);
142 node
= (struct device_node
*)bus
->sysdata
;
143 hose
= pci_find_hose_for_OF_device(node
);
146 return PCIBIOS_DEVICE_NOT_FOUND
;
148 if (bus
->number
== hose
->first_busno
&& devfn
== 0) {
149 /* EPCI controller self */
151 addr
= (unsigned long)hose
->cfg_addr
+ where
;
155 *val
= in_8((u8
*)addr
);
158 *val
= in_be16((u16
*)addr
);
161 *val
= in_be32((u32
*)addr
);
164 return PCIBIOS_DEVICE_NOT_FOUND
;
169 clear_and_disable_master_abort_interrupt(hose
);
170 addr
= celleb_epci_make_config_addr(hose
, devfn
, where
);
174 *val
= in_8((u8
*)addr
);
177 *val
= in_le16((u16
*)addr
);
180 *val
= in_le32((u32
*)addr
);
183 return PCIBIOS_DEVICE_NOT_FOUND
;
188 "addr=0x%lx, devfn=0x%x, where=0x%x, size=0x%x, val=0x%x\n",
189 addr
, devfn
, where
, size
, *val
);
191 return celleb_epci_check_abort(hose
, 0);
194 static int celleb_epci_write_config(struct pci_bus
*bus
,
195 unsigned int devfn
, int where
, int size
, u32 val
)
198 struct device_node
*node
;
199 struct pci_controller
*hose
;
201 /* allignment check */
202 BUG_ON(where
% size
);
204 node
= (struct device_node
*)bus
->sysdata
;
205 hose
= pci_find_hose_for_OF_device(node
);
208 return PCIBIOS_DEVICE_NOT_FOUND
;
210 if (bus
->number
== hose
->first_busno
&& devfn
== 0) {
211 /* EPCI controller self */
213 addr
= (unsigned long)hose
->cfg_addr
+ where
;
217 out_8((u8
*)addr
, val
);
220 out_be16((u16
*)addr
, val
);
223 out_be32((u32
*)addr
, val
);
226 return PCIBIOS_DEVICE_NOT_FOUND
;
231 clear_and_disable_master_abort_interrupt(hose
);
232 addr
= celleb_epci_make_config_addr(hose
, devfn
, where
);
236 out_8((u8
*)addr
, val
);
239 out_le16((u16
*)addr
, val
);
242 out_le32((u32
*)addr
, val
);
245 return PCIBIOS_DEVICE_NOT_FOUND
;
249 return celleb_epci_check_abort(hose
, addr
);
252 struct pci_ops celleb_epci_ops
= {
253 celleb_epci_read_config
,
254 celleb_epci_write_config
,
257 /* to be moved in FW */
258 static int __devinit
celleb_epci_init(struct pci_controller
*hose
)
261 void __iomem
*reg
, *epci_base
;
264 epci_base
= (void *)hose
->cfg_addr
;
266 /* PCI core reset(Internal bus and PCI clock) */
267 reg
= epci_base
+ SCC_EPCI_CKCTRL
;
269 if (val
== 0x00030101)
272 val
&= ~(SCC_EPCI_CKCTRL_CRST0
| SCC_EPCI_CKCTRL_CRST1
);
275 /* set PCI core clock */
277 val
|= (SCC_EPCI_CKCTRL_OCLKEN
| SCC_EPCI_CKCTRL_LCLKEN
);
280 /* release PCI core reset (internal bus) */
282 val
|= SCC_EPCI_CKCTRL_CRST0
;
285 /* set PCI clock select */
286 reg
= epci_base
+ SCC_EPCI_CLKRST
;
288 val
&= ~SCC_EPCI_CLKRST_CKS_MASK
;
289 val
|= SCC_EPCI_CLKRST_CKS_2
;
293 reg
= epci_base
+ SCC_EPCI_ABTSET
;
294 out_be32(reg
, 0x0f1f001f); /* temporary value */
297 reg
= epci_base
+ SCC_EPCI_CLKRST
;
299 val
|= SCC_EPCI_CLKRST_BC
;
302 /* PCI clock enable */
304 val
|= SCC_EPCI_CLKRST_PCKEN
;
307 /* release PCI core reset (all) */
308 reg
= epci_base
+ SCC_EPCI_CKCTRL
;
310 val
|= (SCC_EPCI_CKCTRL_CRST0
| SCC_EPCI_CKCTRL_CRST1
);
313 /* set base translation registers. (already set by Beat) */
315 /* set base address masks. (already set by Beat) */
318 /* release interrupt masks and clear all interrupts */
319 reg
= epci_base
+ SCC_EPCI_INTSET
;
320 out_be32(reg
, 0x013f011f); /* all interrupts enable */
321 reg
= epci_base
+ SCC_EPCI_VIENAB
;
322 val
= SCC_EPCI_VIENAB_PMPEE
| SCC_EPCI_VIENAB_PMFEE
;
324 reg
= epci_base
+ SCC_EPCI_STATUS
;
325 out_be32(reg
, 0xffffffff);
326 reg
= epci_base
+ SCC_EPCI_VISTAT
;
327 out_be32(reg
, 0xffffffff);
329 /* disable PCI->IB address translation */
330 reg
= epci_base
+ SCC_EPCI_VCSR
;
332 val
&= ~(SCC_EPCI_VCSR_DR
| SCC_EPCI_VCSR_AT
);
335 /* set base addresses. (no need to set?) */
337 /* memory space, bus master enable */
338 reg
= epci_base
+ PCI_COMMAND
;
339 val
= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
;
342 /* endian mode setup */
343 reg
= epci_base
+ SCC_EPCI_ECMODE
;
347 /* set control option */
348 reg
= epci_base
+ SCC_EPCI_CNTOPT
;
350 val
|= SCC_EPCI_CNTOPT_O2PMB
;
353 /* XXX: temporay: set registers for address conversion setup */
354 reg
= epci_base
+ SCC_EPCI_CNF10_REG
;
355 out_be32(reg
, 0x80000008);
356 reg
= epci_base
+ SCC_EPCI_CNF14_REG
;
357 out_be32(reg
, 0x40000008);
359 reg
= epci_base
+ SCC_EPCI_BAM0
;
360 out_be32(reg
, 0x80000000);
361 reg
= epci_base
+ SCC_EPCI_BAM1
;
362 out_be32(reg
, 0xe0000000);
364 reg
= epci_base
+ SCC_EPCI_PVBAT
;
365 out_be32(reg
, 0x80000000);
368 /* release external PCI reset */
369 reg
= epci_base
+ SCC_EPCI_CLKRST
;
371 val
|= SCC_EPCI_CLKRST_PCIRST
;
378 int __devinit
celleb_setup_epci(struct device_node
*node
,
379 struct pci_controller
*hose
)
383 pr_debug("PCI: celleb_setup_epci()\n");
385 if (of_address_to_resource(node
, 0, &r
))
387 hose
->cfg_addr
= ioremap(r
.start
, (r
.end
- r
.start
+ 1));
390 pr_debug("EPCI: cfg_addr map 0x%016lx->0x%016lx + 0x%016lx\n",
391 r
.start
, (unsigned long)hose
->cfg_addr
,
392 (r
.end
- r
.start
+ 1));
394 if (of_address_to_resource(node
, 2, &r
))
396 hose
->cfg_data
= ioremap(r
.start
, (r
.end
- r
.start
+ 1));
399 pr_debug("EPCI: cfg_data map 0x%016lx->0x%016lx + 0x%016lx\n",
400 r
.start
, (unsigned long)hose
->cfg_data
,
401 (r
.end
- r
.start
+ 1));
403 celleb_epci_init(hose
);