roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 Tundra Semiconductor Corp. |
| 3 | * Alex Bounine <alexandreb@tundra.com> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * PCI initialisation for the Tsi108 EMU board. |
| 10 | */ |
| 11 | |
| 12 | #include <config.h> |
| 13 | |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 14 | #include <common.h> |
| 15 | #include <pci.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <tsi108.h> |
Gerald Van Baren | 84714ba | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 18 | #if defined(CONFIG_OF_LIBFDT) |
| 19 | #include <libfdt.h> |
| 20 | #include <fdt_support.h> |
Wolfgang Denk | 9225411 | 2007-11-18 16:36:27 +0100 | [diff] [blame] | 21 | #endif |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 22 | |
| 23 | struct pci_controller local_hose; |
| 24 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 25 | void tsi108_clear_pci_error (void) |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 26 | { |
| 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | err_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 35 | TSI108_PB_REG_OFFSET + PB_ERRCS); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | err_addr = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 37 | TSI108_PB_REG_OFFSET + PB_AERR); |
| 38 | if (err_stat & PB_ERRCS_ES) { |
| 39 | /* Clear PCI/X bus errors if applicable */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | if ((err_addr & 0xFF000000) == CONFIG_SYS_PCI_CFG_BASE) { |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 41 | /* Clear error flag */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 42 | *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 43 | TSI108_PB_REG_OFFSET + PB_ERRCS) = |
| 44 | PB_ERRCS_ES; |
| 45 | |
| 46 | /* Clear read error reported in PB_ISR */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | *(u32 *) (CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 48 | 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-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | pci_stat = *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 53 | TSI108_PCI_REG_OFFSET + |
| 54 | PCI_CSR); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 56 | TSI108_PCI_REG_OFFSET + PCI_CSR) = |
| 57 | pci_stat; |
| 58 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | *(volatile u32 *)(CONFIG_SYS_TSI108_CSR_BASE + |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 60 | TSI108_PCI_REG_OFFSET + |
| 61 | PCI_IRP_STAT) = PCI_IRP_STAT_P_CSR; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | return; |
| 66 | } |
| 67 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 68 | unsigned int __get_pci_config_dword (u32 addr) |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 69 | { |
| 70 | unsigned int retval; |
| 71 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 72 | __asm__ __volatile__ (" lwbrx %0,0,%1\n" |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 73 | "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 Denk | 2ef3005 | 2010-11-25 12:14:07 +0100 | [diff] [blame] | 81 | ".section .text.__get_pci_config_dword" |
| 82 | : "=r"(retval) : "r"(addr)); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 83 | |
| 84 | return (retval); |
| 85 | } |
| 86 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 87 | static int tsi108_read_config_dword (struct pci_controller *hose, |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 88 | pci_dev_t dev, int offset, u32 * value) |
| 89 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 90 | dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1); |
| 91 | dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc)); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 92 | *value = __get_pci_config_dword(dev); |
| 93 | if (0xFFFFFFFF == *value) |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 94 | tsi108_clear_pci_error (); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 98 | static int tsi108_write_config_dword (struct pci_controller *hose, |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 99 | pci_dev_t dev, int offset, u32 value) |
| 100 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 101 | dev &= (CONFIG_SYS_PCI_CFG_SIZE - 1); |
| 102 | dev |= (CONFIG_SYS_PCI_CFG_BASE | (offset & 0xfc)); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 103 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 104 | out_le32 ((volatile unsigned *)dev, value); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 105 | |
| 106 | return 0; |
| 107 | } |
| 108 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 109 | void pci_init_board (void) |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 110 | { |
| 111 | struct pci_controller *hose = (struct pci_controller *)&local_hose; |
| 112 | |
| 113 | hose->first_busno = 0; |
| 114 | hose->last_busno = 0xff; |
| 115 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 116 | pci_set_region (hose->regions + 0, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 117 | CONFIG_SYS_PCI_MEMORY_BUS, |
| 118 | CONFIG_SYS_PCI_MEMORY_PHYS, |
Kumar Gala | efa1f1d | 2009-02-06 09:49:31 -0600 | [diff] [blame] | 119 | CONFIG_SYS_PCI_MEMORY_SIZE, PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 120 | |
| 121 | /* PCI memory space */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 122 | pci_set_region (hose->regions + 1, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 123 | CONFIG_SYS_PCI_MEM_BUS, |
| 124 | CONFIG_SYS_PCI_MEM_PHYS, CONFIG_SYS_PCI_MEM_SIZE, PCI_REGION_MEM); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 125 | |
| 126 | /* PCI I/O space */ |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 127 | pci_set_region (hose->regions + 2, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 128 | CONFIG_SYS_PCI_IO_BUS, |
| 129 | CONFIG_SYS_PCI_IO_PHYS, CONFIG_SYS_PCI_IO_SIZE, PCI_REGION_IO); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 130 | |
| 131 | hose->region_count = 3; |
| 132 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 133 | pci_set_ops (hose, |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 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); |
| 140 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 141 | pci_register_hose (hose); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 142 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 143 | hose->last_busno = pci_hose_scan (hose); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 144 | |
roy zang | 92dda87 | 2006-12-01 11:47:36 +0800 | [diff] [blame] | 145 | debug ("Done PCI initialization\n"); |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | |
Gerald Van Baren | 84714ba | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 149 | #if defined(CONFIG_OF_LIBFDT) |
| 150 | void ft_pci_setup(void *blob, bd_t *bd) |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 151 | { |
Gerald Van Baren | 84714ba | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 152 | int nodeoffset; |
| 153 | int tmp[2]; |
| 154 | const char *path; |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 155 | |
Gerald Van Baren | 84714ba | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 156 | 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 zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 165 | } |
roy zang | 8bbfa85 | 2006-11-02 19:11:06 +0800 | [diff] [blame] | 166 | } |
Gerald Van Baren | 84714ba | 2008-06-03 20:24:58 -0400 | [diff] [blame] | 167 | #endif /* CONFIG_OF_LIBFDT */ |