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>
38 #include "../cell/celleb_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")
46 static inline PCI_IO_ADDR
celleb_epci_get_epci_base(
47 struct pci_controller
*hose
)
51 * Celleb epci uses cfg_addr as a base address for
52 * epci control registers.
55 return hose
->cfg_addr
;
58 static inline PCI_IO_ADDR
celleb_epci_get_epci_cfg(
59 struct pci_controller
*hose
)
63 * Celleb epci uses cfg_data as a base address for
64 * configuration area for epci devices.
67 return hose
->cfg_data
;
70 static inline void clear_and_disable_master_abort_interrupt(
71 struct pci_controller
*hose
)
73 PCI_IO_ADDR epci_base
;
75 epci_base
= celleb_epci_get_epci_base(hose
);
76 reg
= epci_base
+ PCI_COMMAND
;
77 out_be32(reg
, in_be32(reg
) | (PCI_STATUS_REC_MASTER_ABORT
<< 16));
80 static int celleb_epci_check_abort(struct pci_controller
*hose
,
84 PCI_IO_ADDR epci_base
;
88 epci_base
= celleb_epci_get_epci_base(hose
);
90 reg
= epci_base
+ PCI_COMMAND
;
93 if (val
& (PCI_STATUS_REC_MASTER_ABORT
<< 16)) {
95 (val
& 0xffff) | (PCI_STATUS_REC_MASTER_ABORT
<< 16));
97 /* clear PCI Controller error, FRE, PMFE */
98 reg
= epci_base
+ SCC_EPCI_STATUS
;
99 out_be32(reg
, SCC_EPCI_INT_PAI
);
101 reg
= epci_base
+ SCC_EPCI_VCSR
;
102 val
= in_be32(reg
) & 0xffff;
103 val
|= SCC_EPCI_VCSR_FRE
;
106 reg
= epci_base
+ SCC_EPCI_VISTAT
;
107 out_be32(reg
, SCC_EPCI_VISTAT_PMFE
);
108 return PCIBIOS_DEVICE_NOT_FOUND
;
111 return PCIBIOS_SUCCESSFUL
;
114 static PCI_IO_ADDR
celleb_epci_make_config_addr(
116 struct pci_controller
*hose
,
117 unsigned int devfn
, int where
)
121 if (bus
!= hose
->bus
)
122 addr
= celleb_epci_get_epci_cfg(hose
) +
123 (((bus
->number
& 0xff) << 16)
124 | ((devfn
& 0xff) << 8)
128 addr
= celleb_epci_get_epci_cfg(hose
) +
129 (((devfn
& 0xff) << 8) | (where
& 0xff));
131 pr_debug("EPCI: config_addr = 0x%p\n", addr
);
136 static int celleb_epci_read_config(struct pci_bus
*bus
,
137 unsigned int devfn
, int where
, int size
, u32
*val
)
139 PCI_IO_ADDR epci_base
;
141 struct device_node
*node
;
142 struct pci_controller
*hose
;
144 /* allignment check */
145 BUG_ON(where
% size
);
147 node
= (struct device_node
*)bus
->sysdata
;
148 hose
= pci_find_hose_for_OF_device(node
);
150 if (!celleb_epci_get_epci_cfg(hose
))
151 return PCIBIOS_DEVICE_NOT_FOUND
;
153 if (bus
->number
== hose
->first_busno
&& devfn
== 0) {
154 /* EPCI controller self */
156 epci_base
= celleb_epci_get_epci_base(hose
);
157 addr
= epci_base
+ where
;
164 *val
= in_be16(addr
);
167 *val
= in_be32(addr
);
170 return PCIBIOS_DEVICE_NOT_FOUND
;
175 clear_and_disable_master_abort_interrupt(hose
);
176 addr
= celleb_epci_make_config_addr(bus
, hose
, devfn
, where
);
183 *val
= in_le16(addr
);
186 *val
= in_le32(addr
);
189 return PCIBIOS_DEVICE_NOT_FOUND
;
194 "addr=0x%p, devfn=0x%x, where=0x%x, size=0x%x, val=0x%x\n",
195 addr
, devfn
, where
, size
, *val
);
197 return celleb_epci_check_abort(hose
, NULL
);
200 static int celleb_epci_write_config(struct pci_bus
*bus
,
201 unsigned int devfn
, int where
, int size
, u32 val
)
203 PCI_IO_ADDR epci_base
;
205 struct device_node
*node
;
206 struct pci_controller
*hose
;
208 /* allignment check */
209 BUG_ON(where
% size
);
211 node
= (struct device_node
*)bus
->sysdata
;
212 hose
= pci_find_hose_for_OF_device(node
);
215 if (!celleb_epci_get_epci_cfg(hose
))
216 return PCIBIOS_DEVICE_NOT_FOUND
;
218 if (bus
->number
== hose
->first_busno
&& devfn
== 0) {
219 /* EPCI controller self */
221 epci_base
= celleb_epci_get_epci_base(hose
);
222 addr
= epci_base
+ where
;
235 return PCIBIOS_DEVICE_NOT_FOUND
;
240 clear_and_disable_master_abort_interrupt(hose
);
241 addr
= celleb_epci_make_config_addr(bus
, hose
, devfn
, where
);
254 return PCIBIOS_DEVICE_NOT_FOUND
;
258 return celleb_epci_check_abort(hose
, addr
);
261 struct pci_ops celleb_epci_ops
= {
262 .read
= celleb_epci_read_config
,
263 .write
= celleb_epci_write_config
,
266 /* to be moved in FW */
267 static int __init
celleb_epci_init(struct pci_controller
*hose
)
271 PCI_IO_ADDR epci_base
;
274 epci_base
= celleb_epci_get_epci_base(hose
);
276 /* PCI core reset(Internal bus and PCI clock) */
277 reg
= epci_base
+ SCC_EPCI_CKCTRL
;
279 if (val
== 0x00030101)
282 val
&= ~(SCC_EPCI_CKCTRL_CRST0
| SCC_EPCI_CKCTRL_CRST1
);
285 /* set PCI core clock */
287 val
|= (SCC_EPCI_CKCTRL_OCLKEN
| SCC_EPCI_CKCTRL_LCLKEN
);
290 /* release PCI core reset (internal bus) */
292 val
|= SCC_EPCI_CKCTRL_CRST0
;
295 /* set PCI clock select */
296 reg
= epci_base
+ SCC_EPCI_CLKRST
;
298 val
&= ~SCC_EPCI_CLKRST_CKS_MASK
;
299 val
|= SCC_EPCI_CLKRST_CKS_2
;
303 reg
= epci_base
+ SCC_EPCI_ABTSET
;
304 out_be32(reg
, 0x0f1f001f); /* temporary value */
307 reg
= epci_base
+ SCC_EPCI_CLKRST
;
309 val
|= SCC_EPCI_CLKRST_BC
;
312 /* PCI clock enable */
314 val
|= SCC_EPCI_CLKRST_PCKEN
;
317 /* release PCI core reset (all) */
318 reg
= epci_base
+ SCC_EPCI_CKCTRL
;
320 val
|= (SCC_EPCI_CKCTRL_CRST0
| SCC_EPCI_CKCTRL_CRST1
);
323 /* set base translation registers. (already set by Beat) */
325 /* set base address masks. (already set by Beat) */
328 /* release interrupt masks and clear all interrupts */
329 reg
= epci_base
+ SCC_EPCI_INTSET
;
330 out_be32(reg
, 0x013f011f); /* all interrupts enable */
331 reg
= epci_base
+ SCC_EPCI_VIENAB
;
332 val
= SCC_EPCI_VIENAB_PMPEE
| SCC_EPCI_VIENAB_PMFEE
;
334 reg
= epci_base
+ SCC_EPCI_STATUS
;
335 out_be32(reg
, 0xffffffff);
336 reg
= epci_base
+ SCC_EPCI_VISTAT
;
337 out_be32(reg
, 0xffffffff);
339 /* disable PCI->IB address translation */
340 reg
= epci_base
+ SCC_EPCI_VCSR
;
342 val
&= ~(SCC_EPCI_VCSR_DR
| SCC_EPCI_VCSR_AT
);
345 /* set base addresses. (no need to set?) */
347 /* memory space, bus master enable */
348 reg
= epci_base
+ PCI_COMMAND
;
349 val
= PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
;
352 /* endian mode setup */
353 reg
= epci_base
+ SCC_EPCI_ECMODE
;
357 /* set control option */
358 reg
= epci_base
+ SCC_EPCI_CNTOPT
;
360 val
|= SCC_EPCI_CNTOPT_O2PMB
;
363 /* XXX: temporay: set registers for address conversion setup */
364 reg
= epci_base
+ SCC_EPCI_CNF10_REG
;
365 out_be32(reg
, 0x80000008);
366 reg
= epci_base
+ SCC_EPCI_CNF14_REG
;
367 out_be32(reg
, 0x40000008);
369 reg
= epci_base
+ SCC_EPCI_BAM0
;
370 out_be32(reg
, 0x80000000);
371 reg
= epci_base
+ SCC_EPCI_BAM1
;
372 out_be32(reg
, 0xe0000000);
374 reg
= epci_base
+ SCC_EPCI_PVBAT
;
375 out_be32(reg
, 0x80000000);
378 /* release external PCI reset */
379 reg
= epci_base
+ SCC_EPCI_CLKRST
;
381 val
|= SCC_EPCI_CLKRST_PCIRST
;
388 static int __init
celleb_setup_epci(struct device_node
*node
,
389 struct pci_controller
*hose
)
393 pr_debug("PCI: celleb_setup_epci()\n");
397 * Celleb epci uses cfg_addr and cfg_data member of
398 * pci_controller structure in irregular way.
400 * cfg_addr is used to map for control registers of
403 * cfg_data is used for configuration area of devices
404 * on Celleb epci buses.
407 if (of_address_to_resource(node
, 0, &r
))
409 hose
->cfg_addr
= ioremap(r
.start
, (r
.end
- r
.start
+ 1));
412 pr_debug("EPCI: cfg_addr map 0x%016lx->0x%016lx + 0x%016lx\n",
413 r
.start
, (unsigned long)hose
->cfg_addr
,
414 (r
.end
- r
.start
+ 1));
416 if (of_address_to_resource(node
, 2, &r
))
418 hose
->cfg_data
= ioremap(r
.start
, (r
.end
- r
.start
+ 1));
421 pr_debug("EPCI: cfg_data map 0x%016lx->0x%016lx + 0x%016lx\n",
422 r
.start
, (unsigned long)hose
->cfg_data
,
423 (r
.end
- r
.start
+ 1));
425 hose
->ops
= &celleb_epci_ops
;
426 celleb_epci_init(hose
);
432 iounmap(hose
->cfg_addr
);
435 iounmap(hose
->cfg_data
);
439 struct celleb_phb_spec celleb_epci_spec __initdata
= {
440 .setup
= celleb_setup_epci
,
441 .ops
= &spiderpci_ops
,
442 .iowa_init
= &spiderpci_iowa_init
,
443 .iowa_data
= (void *)0,