blob: d48e1e6fe6514e254d253b50dce596accee2441b [file] [log] [blame]
roy zang8bbfa852006-11-02 19:11:06 +08001/*
2 * (C) Copyright 2004 Tundra Semiconductor Corp.
3 * Alex Bounine <alexandreb@tundra.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
roy zang8bbfa852006-11-02 19:11:06 +08006 */
7
8/*
9 * PCI initialisation for the Tsi108 EMU board.
10 */
11
12#include <config.h>
13
roy zang8bbfa852006-11-02 19:11:06 +080014#include <common.h>
15#include <pci.h>
16#include <asm/io.h>
17#include <tsi108.h>
Gerald Van Baren84714ba2008-06-03 20:24:58 -040018#if defined(CONFIG_OF_LIBFDT)
19#include <libfdt.h>
20#include <fdt_support.h>
Wolfgang Denk92254112007-11-18 16:36:27 +010021#endif
roy zang8bbfa852006-11-02 19:11:06 +080022
23struct pci_controller local_hose;
24
roy zang92dda872006-12-01 11:47:36 +080025void tsi108_clear_pci_error (void)
roy zang8bbfa852006-11-02 19:11:06 +080026{
27 u32 err_stat, err_addr, pci_stat;
28
29 /*
30 * Quietly clear errors signalled as result of PCI/X configuration read
31 * requests.
32 */
33 /* Read PB Error Log Registers */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020034 err_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080035 TSI108_PB_REG_OFFSET + PB_ERRCS);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020036 err_addr = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080037 TSI108_PB_REG_OFFSET + PB_AERR);
38 if (err_stat & PB_ERRCS_ES) {
39 /* Clear PCI/X bus errors if applicable */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020040 if ((err_addr & 0xFF000000) == CONFIG_SYS_PCI_CFG_BASE) {
roy zang8bbfa852006-11-02 19:11:06 +080041 /* Clear error flag */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080043 TSI108_PB_REG_OFFSET + PB_ERRCS) =
44 PB_ERRCS_ES;
45
46 /* Clear read error reported in PB_ISR */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047 *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080048 TSI108_PB_REG_OFFSET + PB_ISR) =
49 PB_ISR_PBS_RD_ERR;
50
51 /* Clear errors reported by PCI CSR (Normally Master Abort) */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020052 pci_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080053 TSI108_PCI_REG_OFFSET +
54 PCI_CSR);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080056 TSI108_PCI_REG_OFFSET + PCI_CSR) =
57 pci_stat;
58
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE +
roy zang8bbfa852006-11-02 19:11:06 +080060 TSI108_PCI_REG_OFFSET +
61 PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR;
62 }
63 }
64
65 return;
66}
67
roy zang92dda872006-12-01 11:47:36 +080068unsigned int __get_pci_config_dword (u32 addr)
roy zang8bbfa852006-11-02 19:11:06 +080069{
70 unsigned int retval;
71
roy zang92dda872006-12-01 11:47:36 +080072 __asm__ __volatile__ (" lwbrx %0,0,%1\n"
roy zang8bbfa852006-11-02 19:11:06 +080073 "1: eieio\n"
74 "2:\n"
75 ".section .fixup,\"ax\"\n"
76 "3: li %0,-1\n"
77 " b 2b\n"
78 ".section __ex_table,\"a\"\n"
79 " .align 2\n"
80 " .long 1b,3b\n"
Wolfgang Denk2ef30052010-11-25 12:14:07 +010081 ".section .text.__get_pci_config_dword"
82 : "=r"(retval) : "r"(addr));
roy zang8bbfa852006-11-02 19:11:06 +080083
84 return (retval);
85}
86
roy zang92dda872006-12-01 11:47:36 +080087static int tsi108_read_config_dword (struct pci_controller *hose,
roy zang8bbfa852006-11-02 19:11:06 +080088 pci_dev_t dev, int offset, u32 * value)
89{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090 dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1);
91 dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc));
roy zang8bbfa852006-11-02 19:11:06 +080092 *value = __get_pci_config_dword(dev);
93 if (0xFFFFFFFF == *value)
roy zang92dda872006-12-01 11:47:36 +080094 tsi108_clear_pci_error ();
roy zang8bbfa852006-11-02 19:11:06 +080095 return 0;
96}
97
roy zang92dda872006-12-01 11:47:36 +080098static int tsi108_write_config_dword (struct pci_controller *hose,
roy zang8bbfa852006-11-02 19:11:06 +080099 pci_dev_t dev, int offset, u32 value)
100{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200101 dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1);
102 dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc));
roy zang8bbfa852006-11-02 19:11:06 +0800103
roy zang92dda872006-12-01 11:47:36 +0800104 out_le32 ((volatile unsigned *)dev, value);
roy zang8bbfa852006-11-02 19:11:06 +0800105
106 return 0;
107}
108
roy zang92dda872006-12-01 11:47:36 +0800109void pci_init_board (void)
roy zang8bbfa852006-11-02 19:11:06 +0800110{
111 struct pci_controller *hose = (struct pci_controller *)&local_hose;
112
113 hose->first_busno = 0;
114 hose->last_busno = 0xff;
115
roy zang92dda872006-12-01 11:47:36 +0800116 pci_set_region (hose->regions + 0,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117 CONFIG_SYS_PCI_MEMORY_BUS,
118 CONFIG_SYS_PCI_MEMORY_PHYS,
Kumar Galaefa1f1d2009-02-06 09:49:31 -0600119 CONFIG_SYS_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY);
roy zang8bbfa852006-11-02 19:11:06 +0800120
121 /* PCI memory space */
roy zang92dda872006-12-01 11:47:36 +0800122 pci_set_region (hose->regions + 1,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200123 CONFIG_SYS_PCI_MEM_BUS,
124 CONFIG_SYS_PCI_MEM_PHYS, CONFIG_SYS_PCI_MEM_SIZE, PCI_REGION_MEM);
roy zang8bbfa852006-11-02 19:11:06 +0800125
126 /* PCI I/O space */
roy zang92dda872006-12-01 11:47:36 +0800127 pci_set_region (hose->regions + 2,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200128 CONFIG_SYS_PCI_IO_BUS,
129 CONFIG_SYS_PCI_IO_PHYS, CONFIG_SYS_PCI_IO_SIZE, PCI_REGION_IO);
roy zang8bbfa852006-11-02 19:11:06 +0800130
131 hose->region_count = 3;
132
roy zang92dda872006-12-01 11:47:36 +0800133 pci_set_ops (hose,
roy zang8bbfa852006-11-02 19:11:06 +0800134 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);
140
roy zang92dda872006-12-01 11:47:36 +0800141 pci_register_hose (hose);
roy zang8bbfa852006-11-02 19:11:06 +0800142
roy zang92dda872006-12-01 11:47:36 +0800143 hose->last_busno = pci_hose_scan (hose);
roy zang8bbfa852006-11-02 19:11:06 +0800144
roy zang92dda872006-12-01 11:47:36 +0800145 debug ("Done PCI initialization\n");
roy zang8bbfa852006-11-02 19:11:06 +0800146 return;
147}
148
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400149#if defined(CONFIG_OF_LIBFDT)
150void ft_pci_setup(void *blob, bd_t *bd)
roy zang8bbfa852006-11-02 19:11:06 +0800151{
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400152 int nodeoffset;
153 int tmp[2];
154 const char *path;
roy zang8bbfa852006-11-02 19:11:06 +0800155
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400156 nodeoffset = fdt_path_offset(blob, "/aliases");
157 if (nodeoffset >= 0) {
158 path = fdt_getprop(blob, nodeoffset, "pci", NULL);
159 if (path) {
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);
164 }
roy zang8bbfa852006-11-02 19:11:06 +0800165 }
roy zang8bbfa852006-11-02 19:11:06 +0800166}
Gerald Van Baren84714ba2008-06-03 20:24:58 -0400167#endif /* CONFIG_OF_LIBFDT */