blob: 005190ed87de64adc99261fa6a40dea26ec275dc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kumar Galac5651892006-01-12 19:51:38 -06002/*
Kim Phillips57a2af32009-07-18 18:42:13 -05003 * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
Kumar Galac5651892006-01-12 19:51:38 -06004 */
5
6#include <asm/mmu.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -07007#include <asm/io.h>
Kumar Galac5651892006-01-12 19:51:38 -06008#include <common.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -07009#include <mpc83xx.h>
Kumar Galac5651892006-01-12 19:51:38 -060010#include <pci.h>
Kumar Galac5651892006-01-12 19:51:38 -060011#include <i2c.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070012#include <asm/fsl_i2c.h>
Kumar Galac5651892006-01-12 19:51:38 -060013
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070014static struct pci_region pci1_regions[] = {
15 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020016 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
17 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
18 size: CONFIG_SYS_PCI1_MEM_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070019 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
20 },
21 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020022 bus_start: CONFIG_SYS_PCI1_IO_BASE,
23 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
24 size: CONFIG_SYS_PCI1_IO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070025 flags: PCI_REGION_IO
26 },
27 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020028 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
29 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
30 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070031 flags: PCI_REGION_MEM
Kumar Galac5651892006-01-12 19:51:38 -060032 },
Kumar Galac5651892006-01-12 19:51:38 -060033};
Kumar Galac5651892006-01-12 19:51:38 -060034
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070035#ifdef CONFIG_MPC83XX_PCI2
36static struct pci_region pci2_regions[] = {
37 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020038 bus_start: CONFIG_SYS_PCI2_MEM_BASE,
39 phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
40 size: CONFIG_SYS_PCI2_MEM_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070041 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
42 },
43 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 bus_start: CONFIG_SYS_PCI2_IO_BASE,
45 phys_start: CONFIG_SYS_PCI2_IO_PHYS,
46 size: CONFIG_SYS_PCI2_IO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070047 flags: PCI_REGION_IO
48 },
49 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050 bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
51 phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
52 size: CONFIG_SYS_PCI2_MMIO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070053 flags: PCI_REGION_MEM
54 },
Kumar Galac5651892006-01-12 19:51:38 -060055};
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070056#endif
Kumar Galac5651892006-01-12 19:51:38 -060057
Ira W. Snyder4adfd022008-08-22 11:00:15 -070058#ifndef CONFIG_PCISLAVE
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070059void pib_init(void)
Kumar Galac5651892006-01-12 19:51:38 -060060{
Ben Warrenc8135502006-09-12 10:15:53 -040061 u8 val8, orig_i2c_bus;
Kumar Galac5651892006-01-12 19:51:38 -060062 /*
63 * Assign PIB PMC slot to desired PCI bus
64 */
Ben Warrenc8135502006-09-12 10:15:53 -040065 /* Switch temporarily to I2C bus #2 */
66 orig_i2c_bus = i2c_get_bus_num();
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010067 i2c_set_bus_num(1);
Kumar Galac5651892006-01-12 19:51:38 -060068
69 val8 = 0;
70 i2c_write(0x23, 0x6, 1, &val8, 1);
71 i2c_write(0x23, 0x7, 1, &val8, 1);
72 val8 = 0xff;
73 i2c_write(0x23, 0x2, 1, &val8, 1);
74 i2c_write(0x23, 0x3, 1, &val8, 1);
75
76 val8 = 0;
77 i2c_write(0x26, 0x6, 1, &val8, 1);
78 val8 = 0x34;
79 i2c_write(0x26, 0x7, 1, &val8, 1);
Mario Six258312f2019-01-21 09:17:51 +010080#if defined(CONFIG_PCI_64BIT)
Kumar Galac5651892006-01-12 19:51:38 -060081 val8 = 0xf4; /* PMC2:PCI1/64-bit */
Mario Six258312f2019-01-21 09:17:51 +010082#elif defined(CONFIG_PCI_ALL_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -060083 val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
Mario Six258312f2019-01-21 09:17:51 +010084#elif defined(CONFIG_PCI_ONE_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -060085 val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
86#else
87 val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
88#endif
89 i2c_write(0x26, 0x2, 1, &val8, 1);
90 val8 = 0xff;
91 i2c_write(0x26, 0x3, 1, &val8, 1);
92 val8 = 0;
93 i2c_write(0x27, 0x6, 1, &val8, 1);
94 i2c_write(0x27, 0x7, 1, &val8, 1);
95 val8 = 0xff;
96 i2c_write(0x27, 0x2, 1, &val8, 1);
97 val8 = 0xef;
98 i2c_write(0x27, 0x3, 1, &val8, 1);
99 asm("eieio");
100
Mario Six258312f2019-01-21 09:17:51 +0100101#if defined(CONFIG_PCI_64BIT)
Kumar Galac5651892006-01-12 19:51:38 -0600102 printf("PCI1: 64-bit on PMC2\n");
Mario Six258312f2019-01-21 09:17:51 +0100103#elif defined(CONFIG_PCI_ALL_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -0600104 printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
Mario Six258312f2019-01-21 09:17:51 +0100105#elif defined(CONFIG_PCI_ONE_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -0600106 printf("PCI1: 32-bit on PMC1\n");
107 printf("PCI2: 32-bit on PMC2, PMC3\n");
108#else
109 printf("PCI1: 32-bit on PMC1, PMC2\n");
110 printf("PCI2: 32-bit on PMC3\n");
111#endif
Ben Warrenc8135502006-09-12 10:15:53 -0400112 /* Reset to original I2C bus */
Timur Tabiab347542006-11-03 19:15:00 -0600113 i2c_set_bus_num(orig_i2c_bus);
Kumar Galac5651892006-01-12 19:51:38 -0600114}
115
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700116void pci_init_board(void)
Kumar Galac5651892006-01-12 19:51:38 -0600117{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700119 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
120 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
121#ifndef CONFIG_MPC83XX_PCI2
122 struct pci_region *reg[] = { pci1_regions };
123#else
124 struct pci_region *reg[] = { pci1_regions, pci2_regions };
125#endif
Kumar Galac5651892006-01-12 19:51:38 -0600126
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700127 /* initialize the PCA9555PW IO expander on the PIB board */
Kumar Galac5651892006-01-12 19:51:38 -0600128 pib_init();
129
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700130 /* Enable all 8 PCI_CLK_OUTPUTS */
Kumar Galac5651892006-01-12 19:51:38 -0600131 clk->occr = 0xff000000;
132 udelay(2000);
133
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700134 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200135 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kumar Galac5651892006-01-12 19:51:38 -0600136 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
137
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kumar Gala4c7efd82006-04-20 13:45:32 -0500139 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
Kumar Galac5651892006-01-12 19:51:38 -0600140
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700141 udelay(2000);
Kumar Galac5651892006-01-12 19:51:38 -0600142
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700143#ifndef CONFIG_MPC83XX_PCI2
Peter Tysere2283322010-09-14 19:13:50 -0500144 mpc83xx_pci_init(1, reg);
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700145#else
Peter Tysere2283322010-09-14 19:13:50 -0500146 mpc83xx_pci_init(2, reg);
Kumar Galac5651892006-01-12 19:51:38 -0600147#endif
Kumar Galac5651892006-01-12 19:51:38 -0600148}
Kumar Gala4c7efd82006-04-20 13:45:32 -0500149
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700150#else
151void pci_init_board(void)
152{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200153 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700154 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
155 volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
156 struct pci_region *reg[] = { pci1_regions };
157
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700158 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200159 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700160 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
161
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700163 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
164
Peter Tysere2283322010-09-14 19:13:50 -0500165 mpc83xx_pci_init(1, reg);
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700166
167 /* Configure PCI Inbound Translation Windows (3 1MB windows) */
168 pci_ctrl->pitar0 = 0x0;
169 pci_ctrl->pibar0 = 0x0;
170 pci_ctrl->piwar0 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
171 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
172
173 pci_ctrl->pitar1 = 0x0;
174 pci_ctrl->pibar1 = 0x0;
175 pci_ctrl->piebar1 = 0x0;
176 pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
177 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
178
179 pci_ctrl->pitar2 = 0x0;
180 pci_ctrl->pibar2 = 0x0;
181 pci_ctrl->piebar2 = 0x0;
182 pci_ctrl->piwar2 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
183 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
184
185 /* Unlock the configuration bit */
186 mpc83xx_pcislave_unlock(0);
187 printf("PCI: Agent mode enabled\n");
188}
189#endif /* CONFIG_PCISLAVE */