blob: 944108f6319dfa41e7fc817230a2d8a46dbd51c1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dave Liue740c462006-12-07 21:13:15 +08002/*
Kim Phillips57a2af32009-07-18 18:42:13 -05003 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Dave Liue740c462006-12-07 21:13:15 +08004 */
5
6/*
7 * PCI Configuration space access support for MPC83xx PCI Bridge
8 */
Simon Glass18afe102019-11-14 12:57:47 -07009#include <init.h>
Dave Liue740c462006-12-07 21:13:15 +080010#include <asm/mmu.h>
11#include <asm/io.h>
12#include <common.h>
Kim Phillips57a2af32009-07-18 18:42:13 -050013#include <mpc83xx.h>
Dave Liue740c462006-12-07 21:13:15 +080014#include <pci.h>
15#include <i2c.h>
Dave Liue740c462006-12-07 21:13:15 +080016#include <asm/fsl_i2c.h>
Simon Glassdbd79542020-05-10 11:40:11 -060017#include <linux/delay.h>
Kim Phillips57a2af32009-07-18 18:42:13 -050018#include "../common/pq-mds-pib.h"
Dave Liue740c462006-12-07 21:13:15 +080019
Kim Phillips57a2af32009-07-18 18:42:13 -050020static 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 Liue740c462006-12-07 21:13:15 +080040
Kim Phillips57a2af32009-07-18 18:42:13 -050041#ifdef CONFIG_MPC83XX_PCI2
42static struct pci_region pci2_regions[] = {
Dave Liue740c462006-12-07 21:13:15 +080043 {
Kim Phillips57a2af32009-07-18 18:42:13 -050044 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 Liue740c462006-12-07 21:13:15 +080048 },
Dave Liue740c462006-12-07 21:13:15 +080049 {
Kim Phillips57a2af32009-07-18 18:42:13 -050050 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 Liue740c462006-12-07 21:13:15 +080060 },
61};
Kim Phillips57a2af32009-07-18 18:42:13 -050062#endif
63
Dave Liue740c462006-12-07 21:13:15 +080064void pci_init_board(void)
65#ifdef CONFIG_PCISLAVE
66{
Kim Phillips57a2af32009-07-18 18:42:13 -050067 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 Liue740c462006-12-07 21:13:15 +080075
Kim Phillips57a2af32009-07-18 18:42:13 -050076 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
77 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
78
Peter Tysere2283322010-09-14 19:13:50 -050079 mpc83xx_pci_init(1, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -050080
Dave Liue740c462006-12-07 21:13:15 +080081 /*
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 Phillips57a2af32009-07-18 18:42:13 -050099 /* Unlock the configuration bit */
100 mpc83xx_pcislave_unlock(0);
101 printf("PCI: Agent mode enabled\n");
Dave Liue740c462006-12-07 21:13:15 +0800102}
103#else
104{
Kim Phillips57a2af32009-07-18 18:42:13 -0500105 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 Liue740c462006-12-07 21:13:15 +0800113
Kim Phillips57a2af32009-07-18 18:42:13 -0500114 /* initialize the PCA9555PW IO expander on the PIB board */
115 pib_init();
Dave Liue740c462006-12-07 21:13:15 +0800116
Wolfgang Denk291ba1b2010-10-06 09:05:45 +0200117#if defined(CONFIG_PCI_66M)
Dave Liue740c462006-12-07 21:13:15 +0800118 clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2;
119 printf("PCI clock is 66MHz\n");
Wolfgang Denk291ba1b2010-10-06 09:05:45 +0200120#elif defined(CONFIG_PCI_33M)
Dave Liue740c462006-12-07 21:13:15 +0800121 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 Phillips57a2af32009-07-18 18:42:13 -0500130 /* Configure PCI Local Access Windows */
131 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Dave Liue740c462006-12-07 21:13:15 +0800132 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M;
133
Kim Phillips57a2af32009-07-18 18:42:13 -0500134 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Dave Liue740c462006-12-07 21:13:15 +0800135 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M;
136
Dave Liue740c462006-12-07 21:13:15 +0800137 udelay(2000);
Dave Liue740c462006-12-07 21:13:15 +0800138
Kim Phillips57a2af32009-07-18 18:42:13 -0500139#ifndef CONFIG_MPC83XX_PCI2
Peter Tysere2283322010-09-14 19:13:50 -0500140 mpc83xx_pci_init(1, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -0500141#else
Peter Tysere2283322010-09-14 19:13:50 -0500142 mpc83xx_pci_init(2, reg);
Kim Phillips57a2af32009-07-18 18:42:13 -0500143#endif
Dave Liue740c462006-12-07 21:13:15 +0800144}
145#endif /* CONFIG_PCISLAVE */