roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 Tundra Semiconductor Corp. |
| 3 | * Alex Bounine <alexandreb@tundra.com> |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * PCI initialisation for the Tsi108 EMU board. |
| 26 | */ |
| 27 | |
| 28 | #include <config.h> |
| 29 | |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 30 | #include <common.h> |
| 31 | #include <pci.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <tsi108.h> |
Gerald Van Baren | 589c042 | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 34 | #if defined(CONFIG_OF_LIBFDT) |
| 35 | #include <libfdt.h> |
| 36 | #include <fdt_support.h> |
Wolfgang Denk | 409ecdc | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 37 | #endif |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 38 | |
| 39 | struct pci_controller local_hose; |
| 40 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 41 | void tsi108_clear_pci_error (void) |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 42 | { |
| 43 | u32 err_stat, err_addr, pci_stat; |
| 44 | |
| 45 | /* |
| 46 | * Quietly clear errors signalled as result of PCI/X configuration read |
| 47 | * requests. |
| 48 | */ |
| 49 | /* Read PB Error Log Registers */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | err_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 51 | TSI108_PB_REG_OFFSET + PB_ERRCS); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | err_addr = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 53 | TSI108_PB_REG_OFFSET + PB_AERR); |
| 54 | if (err_stat & PB_ERRCS_ES) { |
| 55 | /* Clear PCI/X bus errors if applicable */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | if ((err_addr & 0xFF000000) == CONFIG_SYS_PCI_CFG_BASE) { |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 57 | /* Clear error flag */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 59 | TSI108_PB_REG_OFFSET + PB_ERRCS) = |
| 60 | PB_ERRCS_ES; |
| 61 | |
| 62 | /* Clear read error reported in PB_ISR */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 63 | *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 64 | TSI108_PB_REG_OFFSET + PB_ISR) = |
| 65 | PB_ISR_PBS_RD_ERR; |
| 66 | |
| 67 | /* Clear errors reported by PCI CSR (Normally Master Abort) */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 68 | pci_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 69 | TSI108_PCI_REG_OFFSET + |
| 70 | PCI_CSR); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 72 | TSI108_PCI_REG_OFFSET + PCI_CSR) = |
| 73 | pci_stat; |
| 74 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 76 | TSI108_PCI_REG_OFFSET + |
| 77 | PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return; |
| 82 | } |
| 83 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 84 | unsigned int __get_pci_config_dword (u32 addr) |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 85 | { |
| 86 | unsigned int retval; |
| 87 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 88 | __asm__ __volatile__ (" lwbrx %0,0,%1\n" |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 89 | "1: eieio\n" |
| 90 | "2:\n" |
| 91 | ".section .fixup,\"ax\"\n" |
| 92 | "3: li %0,-1\n" |
| 93 | " b 2b\n" |
| 94 | ".section __ex_table,\"a\"\n" |
| 95 | " .align 2\n" |
| 96 | " .long 1b,3b\n" |
Wolfgang Denk | e2c2a95 | 2010-11-25 12:14:07 +0100 | [diff] [blame] | 97 | ".section .text.__get_pci_config_dword" |
| 98 | : "=r"(retval) : "r"(addr)); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 99 | |
| 100 | return (retval); |
| 101 | } |
| 102 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 103 | static int tsi108_read_config_dword (struct pci_controller *hose, |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 104 | pci_dev_t dev, int offset, u32 * value) |
| 105 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 106 | dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1); |
| 107 | dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc)); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 108 | *value = __get_pci_config_dword(dev); |
| 109 | if (0xFFFFFFFF == *value) |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 110 | tsi108_clear_pci_error (); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 114 | static int tsi108_write_config_dword (struct pci_controller *hose, |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 115 | pci_dev_t dev, int offset, u32 value) |
| 116 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1); |
| 118 | dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc)); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 119 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 120 | out_le32 ((volatile unsigned *)dev, value); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 125 | void pci_init_board (void) |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 126 | { |
| 127 | struct pci_controller *hose = (struct pci_controller *)&local_hose; |
| 128 | |
| 129 | hose->first_busno = 0; |
| 130 | hose->last_busno = 0xff; |
| 131 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 132 | pci_set_region (hose->regions + 0, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 133 | CONFIG_SYS_PCI_MEMORY_BUS, |
| 134 | CONFIG_SYS_PCI_MEMORY_PHYS, |
Kumar Gala | ff4e66e | 2009-02-06 09:49:31 -0600 | [diff] [blame] | 135 | CONFIG_SYS_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 136 | |
| 137 | /* PCI memory space */ |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 138 | pci_set_region (hose->regions + 1, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 139 | CONFIG_SYS_PCI_MEM_BUS, |
| 140 | CONFIG_SYS_PCI_MEM_PHYS, CONFIG_SYS_PCI_MEM_SIZE, PCI_REGION_MEM); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 141 | |
| 142 | /* PCI I/O space */ |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 143 | pci_set_region (hose->regions + 2, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 144 | CONFIG_SYS_PCI_IO_BUS, |
| 145 | CONFIG_SYS_PCI_IO_PHYS, CONFIG_SYS_PCI_IO_SIZE, PCI_REGION_IO); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 146 | |
| 147 | hose->region_count = 3; |
| 148 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 149 | pci_set_ops (hose, |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 150 | pci_hose_read_config_byte_via_dword, |
| 151 | pci_hose_read_config_word_via_dword, |
| 152 | tsi108_read_config_dword, |
| 153 | pci_hose_write_config_byte_via_dword, |
| 154 | pci_hose_write_config_word_via_dword, |
| 155 | tsi108_write_config_dword); |
| 156 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 157 | pci_register_hose (hose); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 158 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 159 | hose->last_busno = pci_hose_scan (hose); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 160 | |
roy zang | ee31121 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 161 | debug ("Done PCI initialization\n"); |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 162 | return; |
| 163 | } |
| 164 | |
Gerald Van Baren | 589c042 | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 165 | #if defined(CONFIG_OF_LIBFDT) |
| 166 | void ft_pci_setup(void *blob, bd_t *bd) |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 167 | { |
Gerald Van Baren | 589c042 | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 168 | int nodeoffset; |
| 169 | int tmp[2]; |
| 170 | const char *path; |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 171 | |
Gerald Van Baren | 589c042 | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 172 | nodeoffset = fdt_path_offset(blob, "/aliases"); |
| 173 | if (nodeoffset >= 0) { |
| 174 | path = fdt_getprop(blob, nodeoffset, "pci", NULL); |
| 175 | if (path) { |
| 176 | tmp[0] = cpu_to_be32(local_hose.first_busno); |
| 177 | tmp[1] = cpu_to_be32(local_hose.last_busno); |
| 178 | do_fixup_by_path(blob, path, "bus-range", |
| 179 | &tmp, sizeof(tmp), 1); |
| 180 | } |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 181 | } |
roy zang | 9226e7d | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 182 | } |
Gerald Van Baren | 589c042 | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 183 | #endif /* CONFIG_OF_LIBFDT */ |