2 * (C) Copyright 2004 Tundra Semiconductor Corp.
3 * Alex Bounine <alexandreb@tundra.com>
5 * SPDX-License-Identifier: GPL-2.0+
9 * PCI initialisation for the Tsi108 EMU board.
18 #if defined(CONFIG_OF_LIBFDT)
20 #include <fdt_support.h>
23 struct pci_controller local_hose
;
25 void tsi108_clear_pci_error (void)
27 u32 err_stat
, err_addr
, pci_stat
;
30 * Quietly clear errors signalled as result of PCI/X configuration read
33 /* Read PB Error Log Registers */
34 err_stat
= *(volatile u32
*)(CONFIG_SYS_TSI108_CSR_BASE
+
35 TSI108_PB_REG_OFFSET
+ PB_ERRCS
);
36 err_addr
= *(volatile u32
*)(CONFIG_SYS_TSI108_CSR_BASE
+
37 TSI108_PB_REG_OFFSET
+ PB_AERR
);
38 if (err_stat
& PB_ERRCS_ES
) {
39 /* Clear PCI/X bus errors if applicable */
40 if ((err_addr
& 0xFF000000) == CONFIG_SYS_PCI_CFG_BASE
) {
41 /* Clear error flag */
42 *(u32
*) (CONFIG_SYS_TSI108_CSR_BASE
+
43 TSI108_PB_REG_OFFSET
+ PB_ERRCS
) =
46 /* Clear read error reported in PB_ISR */
47 *(u32
*) (CONFIG_SYS_TSI108_CSR_BASE
+
48 TSI108_PB_REG_OFFSET
+ PB_ISR
) =
51 /* Clear errors reported by PCI CSR (Normally Master Abort) */
52 pci_stat
= *(volatile u32
*)(CONFIG_SYS_TSI108_CSR_BASE
+
53 TSI108_PCI_REG_OFFSET
+
55 *(volatile u32
*)(CONFIG_SYS_TSI108_CSR_BASE
+
56 TSI108_PCI_REG_OFFSET
+ PCI_CSR
) =
59 *(volatile u32
*)(CONFIG_SYS_TSI108_CSR_BASE
+
60 TSI108_PCI_REG_OFFSET
+
61 PCI_IRP_STAT
) = PCI_IRP_STAT_P_CSR
;
68 unsigned int __get_pci_config_dword (u32 addr
)
72 __asm__
__volatile__ (" lwbrx %0,0,%1\n"
75 ".section .fixup,\"ax\"\n"
78 ".section __ex_table,\"a\"\n"
81 ".section .text.__get_pci_config_dword"
82 : "=r"(retval
) : "r"(addr
));
87 static int tsi108_read_config_dword (struct pci_controller
*hose
,
88 pci_dev_t dev
, int offset
, u32
* value
)
90 dev
&= (CONFIG_SYS_PCI_CFG_SIZE
- 1);
91 dev
|= (CONFIG_SYS_PCI_CFG_BASE
| (offset
& 0xfc));
92 *value
= __get_pci_config_dword(dev
);
93 if (0xFFFFFFFF == *value
)
94 tsi108_clear_pci_error ();
98 static int tsi108_write_config_dword (struct pci_controller
*hose
,
99 pci_dev_t dev
, int offset
, u32 value
)
101 dev
&= (CONFIG_SYS_PCI_CFG_SIZE
- 1);
102 dev
|= (CONFIG_SYS_PCI_CFG_BASE
| (offset
& 0xfc));
104 out_le32 ((volatile unsigned *)dev
, value
);
109 void pci_init_board (void)
111 struct pci_controller
*hose
= (struct pci_controller
*)&local_hose
;
113 hose
->first_busno
= 0;
114 hose
->last_busno
= 0xff;
116 pci_set_region (hose
->regions
+ 0,
117 CONFIG_SYS_PCI_MEMORY_BUS
,
118 CONFIG_SYS_PCI_MEMORY_PHYS
,
119 CONFIG_SYS_PCI_MEMORY_SIZE
, PCI_REGION_MEM
| PCI_REGION_SYS_MEMORY
);
121 /* PCI memory space */
122 pci_set_region (hose
->regions
+ 1,
123 CONFIG_SYS_PCI_MEM_BUS
,
124 CONFIG_SYS_PCI_MEM_PHYS
, CONFIG_SYS_PCI_MEM_SIZE
, PCI_REGION_MEM
);
127 pci_set_region (hose
->regions
+ 2,
128 CONFIG_SYS_PCI_IO_BUS
,
129 CONFIG_SYS_PCI_IO_PHYS
, CONFIG_SYS_PCI_IO_SIZE
, PCI_REGION_IO
);
131 hose
->region_count
= 3;
134 pci_hose_read_config_byte_via_dword
,
135 pci_hose_read_config_word_via_dword
,
136 tsi108_read_config_dword
,
137 pci_hose_write_config_byte_via_dword
,
138 pci_hose_write_config_word_via_dword
,
139 tsi108_write_config_dword
);
141 pci_register_hose (hose
);
143 hose
->last_busno
= pci_hose_scan (hose
);
145 debug ("Done PCI initialization\n");
149 #if defined(CONFIG_OF_LIBFDT)
150 void ft_pci_setup(void *blob
, bd_t
*bd
)
156 nodeoffset
= fdt_path_offset(blob
, "/aliases");
157 if (nodeoffset
>= 0) {
158 path
= fdt_getprop(blob
, nodeoffset
, "pci", NULL
);
160 tmp
[0] = cpu_to_be32(local_hose
.first_busno
);
161 tmp
[1] = cpu_to_be32(local_hose
.last_busno
);
162 do_fixup_by_path(blob
, path
, "bus-range",
163 &tmp
, sizeof(tmp
), 1);
167 #endif /* CONFIG_OF_LIBFDT */