Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 1 | /* |
| 2 | * See file CREDITS for list of people who contributed to this |
| 3 | * project. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of |
| 8 | * the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 18 | * MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <asm/mmu.h> |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 23 | #include <asm/io.h> |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 24 | #include <common.h> |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 25 | #include <mpc83xx.h> |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 26 | #include <pci.h> |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 27 | #include <i2c.h> |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 28 | #include <asm/fsl_i2c.h> |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 29 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 32 | #ifdef CONFIG_PCI |
| 33 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 34 | static struct pci_region pci1_regions[] = { |
| 35 | { |
| 36 | bus_start: CFG_PCI1_MEM_BASE, |
| 37 | phys_start: CFG_PCI1_MEM_PHYS, |
| 38 | size: CFG_PCI1_MEM_SIZE, |
| 39 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 40 | }, |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 41 | { |
| 42 | bus_start: CFG_PCI1_IO_BASE, |
| 43 | phys_start: CFG_PCI1_IO_PHYS, |
| 44 | size: CFG_PCI1_IO_SIZE, |
| 45 | flags: PCI_REGION_IO |
| 46 | }, |
| 47 | { |
| 48 | bus_start: CFG_PCI1_MMIO_BASE, |
| 49 | phys_start: CFG_PCI1_MMIO_PHYS, |
| 50 | size: CFG_PCI1_MMIO_SIZE, |
| 51 | flags: PCI_REGION_MEM |
| 52 | }, |
| 53 | }; |
| 54 | |
| 55 | #ifdef CONFIG_MPC83XX_PCI2 |
| 56 | static struct pci_region pci2_regions[] = { |
| 57 | { |
| 58 | bus_start: CFG_PCI2_MEM_BASE, |
| 59 | phys_start: CFG_PCI2_MEM_PHYS, |
| 60 | size: CFG_PCI2_MEM_SIZE, |
| 61 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 62 | }, |
| 63 | { |
| 64 | bus_start: CFG_PCI2_IO_BASE, |
| 65 | phys_start: CFG_PCI2_IO_PHYS, |
| 66 | size: CFG_PCI2_IO_SIZE, |
| 67 | flags: PCI_REGION_IO |
| 68 | }, |
| 69 | { |
| 70 | bus_start: CFG_PCI2_MMIO_BASE, |
| 71 | phys_start: CFG_PCI2_MMIO_PHYS, |
| 72 | size: CFG_PCI2_MMIO_SIZE, |
| 73 | flags: PCI_REGION_MEM |
| 74 | }, |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 75 | }; |
| 76 | #endif |
| 77 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 78 | void pib_init(void) |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 79 | { |
Ben Warren | 183da6d | 2006-09-12 10:15:53 -0400 | [diff] [blame] | 80 | u8 val8, orig_i2c_bus; |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 81 | /* |
| 82 | * Assign PIB PMC slot to desired PCI bus |
| 83 | */ |
Ben Warren | 183da6d | 2006-09-12 10:15:53 -0400 | [diff] [blame] | 84 | /* Switch temporarily to I2C bus #2 */ |
| 85 | orig_i2c_bus = i2c_get_bus_num(); |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 86 | i2c_set_bus_num(1); |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 87 | |
| 88 | val8 = 0; |
| 89 | i2c_write(0x23, 0x6, 1, &val8, 1); |
| 90 | i2c_write(0x23, 0x7, 1, &val8, 1); |
| 91 | val8 = 0xff; |
| 92 | i2c_write(0x23, 0x2, 1, &val8, 1); |
| 93 | i2c_write(0x23, 0x3, 1, &val8, 1); |
| 94 | |
| 95 | val8 = 0; |
| 96 | i2c_write(0x26, 0x6, 1, &val8, 1); |
| 97 | val8 = 0x34; |
| 98 | i2c_write(0x26, 0x7, 1, &val8, 1); |
| 99 | #if defined(PCI_64BIT) |
| 100 | val8 = 0xf4; /* PMC2:PCI1/64-bit */ |
| 101 | #elif defined(PCI_ALL_PCI1) |
| 102 | val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */ |
| 103 | #elif defined(PCI_ONE_PCI1) |
| 104 | val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */ |
| 105 | #else |
| 106 | val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */ |
| 107 | #endif |
| 108 | i2c_write(0x26, 0x2, 1, &val8, 1); |
| 109 | val8 = 0xff; |
| 110 | i2c_write(0x26, 0x3, 1, &val8, 1); |
| 111 | val8 = 0; |
| 112 | i2c_write(0x27, 0x6, 1, &val8, 1); |
| 113 | i2c_write(0x27, 0x7, 1, &val8, 1); |
| 114 | val8 = 0xff; |
| 115 | i2c_write(0x27, 0x2, 1, &val8, 1); |
| 116 | val8 = 0xef; |
| 117 | i2c_write(0x27, 0x3, 1, &val8, 1); |
| 118 | asm("eieio"); |
| 119 | |
| 120 | #if defined(PCI_64BIT) |
| 121 | printf("PCI1: 64-bit on PMC2\n"); |
| 122 | #elif defined(PCI_ALL_PCI1) |
| 123 | printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n"); |
| 124 | #elif defined(PCI_ONE_PCI1) |
| 125 | printf("PCI1: 32-bit on PMC1\n"); |
| 126 | printf("PCI2: 32-bit on PMC2, PMC3\n"); |
| 127 | #else |
| 128 | printf("PCI1: 32-bit on PMC1, PMC2\n"); |
| 129 | printf("PCI2: 32-bit on PMC3\n"); |
| 130 | #endif |
Ben Warren | 183da6d | 2006-09-12 10:15:53 -0400 | [diff] [blame] | 131 | /* Reset to original I2C bus */ |
Timur Tabi | be5e618 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 132 | i2c_set_bus_num(orig_i2c_bus); |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 133 | } |
| 134 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 135 | void pci_init_board(void) |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 136 | { |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 137 | volatile immap_t *immr = (volatile immap_t *)CFG_IMMR; |
| 138 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 139 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
| 140 | #ifndef CONFIG_MPC83XX_PCI2 |
| 141 | struct pci_region *reg[] = { pci1_regions }; |
| 142 | #else |
| 143 | struct pci_region *reg[] = { pci1_regions, pci2_regions }; |
| 144 | #endif |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 145 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 146 | /* initialize the PCA9555PW IO expander on the PIB board */ |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 147 | pib_init(); |
| 148 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 149 | /* Enable all 8 PCI_CLK_OUTPUTS */ |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 150 | clk->occr = 0xff000000; |
| 151 | udelay(2000); |
| 152 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 153 | /* Configure PCI Local Access Windows */ |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 154 | pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR; |
| 155 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G; |
| 156 | |
| 157 | pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR; |
Kumar Gala | 8fe9bf6 | 2006-04-20 13:45:32 -0500 | [diff] [blame] | 158 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M; |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 159 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 160 | udelay(2000); |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 161 | |
Ira W. Snyder | 162338e | 2008-08-22 11:00:13 -0700 | [diff] [blame^] | 162 | #ifndef CONFIG_MPC83XX_PCI2 |
| 163 | mpc83xx_pci_init(1, reg, 0); |
| 164 | #else |
| 165 | mpc83xx_pci_init(2, reg, 0); |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 166 | #endif |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 167 | } |
Kumar Gala | 8fe9bf6 | 2006-04-20 13:45:32 -0500 | [diff] [blame] | 168 | |
Kumar Gala | 86902b8 | 2006-01-12 19:51:38 -0600 | [diff] [blame] | 169 | #endif /* CONFIG_PCI */ |