Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 2 | /* |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 3 | * Copyright (C) 2006-2009 Freescale Semiconductor, Inc. |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * PCI Configuration space access support for MPC83xx PCI Bridge |
| 8 | */ |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 9 | #include <init.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 10 | #include <asm/mmu.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <common.h> |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 13 | #include <mpc83xx.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 14 | #include <pci.h> |
| 15 | #include <i2c.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 16 | #include <asm/fsl_i2c.h> |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 17 | #include "../common/pq-mds-pib.h" |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 18 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 19 | static struct pci_region pci1_regions[] = { |
| 20 | { |
| 21 | bus_start: CONFIG_SYS_PCI1_MEM_BASE, |
| 22 | phys_start: CONFIG_SYS_PCI1_MEM_PHYS, |
| 23 | size: CONFIG_SYS_PCI1_MEM_SIZE, |
| 24 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
| 25 | }, |
| 26 | { |
| 27 | bus_start: CONFIG_SYS_PCI1_IO_BASE, |
| 28 | phys_start: CONFIG_SYS_PCI1_IO_PHYS, |
| 29 | size: CONFIG_SYS_PCI1_IO_SIZE, |
| 30 | flags: PCI_REGION_IO |
| 31 | }, |
| 32 | { |
| 33 | bus_start: CONFIG_SYS_PCI1_MMIO_BASE, |
| 34 | phys_start: CONFIG_SYS_PCI1_MMIO_PHYS, |
| 35 | size: CONFIG_SYS_PCI1_MMIO_SIZE, |
| 36 | flags: PCI_REGION_MEM |
| 37 | }, |
| 38 | }; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 39 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 40 | #ifdef CONFIG_MPC83XX_PCI2 |
| 41 | static struct pci_region pci2_regions[] = { |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 42 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 43 | bus_start: CONFIG_SYS_PCI2_MEM_BASE, |
| 44 | phys_start: CONFIG_SYS_PCI2_MEM_PHYS, |
| 45 | size: CONFIG_SYS_PCI2_MEM_SIZE, |
| 46 | flags: PCI_REGION_MEM | PCI_REGION_PREFETCH |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 47 | }, |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 48 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 49 | bus_start: CONFIG_SYS_PCI2_IO_BASE, |
| 50 | phys_start: CONFIG_SYS_PCI2_IO_PHYS, |
| 51 | size: CONFIG_SYS_PCI2_IO_SIZE, |
| 52 | flags: PCI_REGION_IO |
| 53 | }, |
| 54 | { |
| 55 | bus_start: CONFIG_SYS_PCI2_MMIO_BASE, |
| 56 | phys_start: CONFIG_SYS_PCI2_MMIO_PHYS, |
| 57 | size: CONFIG_SYS_PCI2_MMIO_SIZE, |
| 58 | flags: PCI_REGION_MEM |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 59 | }, |
| 60 | }; |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 61 | #endif |
| 62 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 63 | void pci_init_board(void) |
| 64 | #ifdef CONFIG_PCISLAVE |
| 65 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 66 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
| 67 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
| 68 | volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0]; |
| 69 | struct pci_region *reg[] = { pci1_regions }; |
| 70 | |
| 71 | /* Configure PCI Local Access Windows */ |
| 72 | pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR; |
| 73 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 74 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 75 | pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR; |
| 76 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M; |
| 77 | |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 78 | mpc83xx_pci_init(1, reg); |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 79 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 80 | /* |
| 81 | * Configure PCI Inbound Translation Windows |
| 82 | */ |
| 83 | pci_ctrl[0].pitar0 = 0x0; |
| 84 | pci_ctrl[0].pibar0 = 0x0; |
| 85 | pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP | |
| 86 | PIWAR_WTT_SNOOP | PIWAR_IWS_4K; |
| 87 | |
| 88 | pci_ctrl[0].pitar1 = 0x0; |
| 89 | pci_ctrl[0].pibar1 = 0x0; |
| 90 | pci_ctrl[0].piebar1 = 0x0; |
| 91 | pci_ctrl[0].piwar1 &= ~PIWAR_EN; |
| 92 | |
| 93 | pci_ctrl[0].pitar2 = 0x0; |
| 94 | pci_ctrl[0].pibar2 = 0x0; |
| 95 | pci_ctrl[0].piebar2 = 0x0; |
| 96 | pci_ctrl[0].piwar2 &= ~PIWAR_EN; |
| 97 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 98 | /* Unlock the configuration bit */ |
| 99 | mpc83xx_pcislave_unlock(0); |
| 100 | printf("PCI: Agent mode enabled\n"); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 101 | } |
| 102 | #else |
| 103 | { |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 104 | volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR; |
| 105 | volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk; |
| 106 | volatile law83xx_t *pci_law = immr->sysconf.pcilaw; |
| 107 | #ifndef CONFIG_MPC83XX_PCI2 |
| 108 | struct pci_region *reg[] = { pci1_regions }; |
| 109 | #else |
| 110 | struct pci_region *reg[] = { pci1_regions, pci2_regions }; |
| 111 | #endif |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 112 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 113 | /* initialize the PCA9555PW IO expander on the PIB board */ |
| 114 | pib_init(); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 115 | |
Wolfgang Denk | 291ba1b | 2010-10-06 09:05:45 +0200 | [diff] [blame] | 116 | #if defined(CONFIG_PCI_66M) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 117 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2; |
| 118 | printf("PCI clock is 66MHz\n"); |
Wolfgang Denk | 291ba1b | 2010-10-06 09:05:45 +0200 | [diff] [blame] | 119 | #elif defined(CONFIG_PCI_33M) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 120 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 | |
| 121 | OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR; |
| 122 | printf("PCI clock is 33MHz\n"); |
| 123 | #else |
| 124 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2; |
| 125 | printf("PCI clock is 66MHz\n"); |
| 126 | #endif |
| 127 | udelay(2000); |
| 128 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 129 | /* Configure PCI Local Access Windows */ |
| 130 | pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 131 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M; |
| 132 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 133 | pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 134 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M; |
| 135 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 136 | udelay(2000); |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 137 | |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 138 | #ifndef CONFIG_MPC83XX_PCI2 |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 139 | mpc83xx_pci_init(1, reg); |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 140 | #else |
Peter Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 141 | mpc83xx_pci_init(2, reg); |
Kim Phillips | 57a2af3 | 2009-07-18 18:42:13 -0500 | [diff] [blame] | 142 | #endif |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 143 | } |
| 144 | #endif /* CONFIG_PCISLAVE */ |