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