blob: 7615a1dfaa23dcf0b785391c16b936eac9c6675a [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
Simon Glass18afe102019-11-14 12:57:47 -07006#include <init.h>
Kumar Galac5651892006-01-12 19:51:38 -06007#include <asm/mmu.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -07008#include <asm/io.h>
Kumar Galac5651892006-01-12 19:51:38 -06009#include <common.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070010#include <mpc83xx.h>
Kumar Galac5651892006-01-12 19:51:38 -060011#include <pci.h>
Kumar Galac5651892006-01-12 19:51:38 -060012#include <i2c.h>
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070013#include <asm/fsl_i2c.h>
Kumar Galac5651892006-01-12 19:51:38 -060014
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070015static struct pci_region pci1_regions[] = {
16 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020017 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
18 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
19 size: CONFIG_SYS_PCI1_MEM_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070020 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
21 },
22 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023 bus_start: CONFIG_SYS_PCI1_IO_BASE,
24 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
25 size: CONFIG_SYS_PCI1_IO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070026 flags: PCI_REGION_IO
27 },
28 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
30 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
31 size: CONFIG_SYS_PCI1_MMIO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070032 flags: PCI_REGION_MEM
Kumar Galac5651892006-01-12 19:51:38 -060033 },
Kumar Galac5651892006-01-12 19:51:38 -060034};
Kumar Galac5651892006-01-12 19:51:38 -060035
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070036#ifdef CONFIG_MPC83XX_PCI2
37static struct pci_region pci2_regions[] = {
38 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039 bus_start: CONFIG_SYS_PCI2_MEM_BASE,
40 phys_start: CONFIG_SYS_PCI2_MEM_PHYS,
41 size: CONFIG_SYS_PCI2_MEM_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070042 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
43 },
44 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 bus_start: CONFIG_SYS_PCI2_IO_BASE,
46 phys_start: CONFIG_SYS_PCI2_IO_PHYS,
47 size: CONFIG_SYS_PCI2_IO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070048 flags: PCI_REGION_IO
49 },
50 {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051 bus_start: CONFIG_SYS_PCI2_MMIO_BASE,
52 phys_start: CONFIG_SYS_PCI2_MMIO_PHYS,
53 size: CONFIG_SYS_PCI2_MMIO_SIZE,
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070054 flags: PCI_REGION_MEM
55 },
Kumar Galac5651892006-01-12 19:51:38 -060056};
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070057#endif
Kumar Galac5651892006-01-12 19:51:38 -060058
Ira W. Snyder4adfd022008-08-22 11:00:15 -070059#ifndef CONFIG_PCISLAVE
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -070060void pib_init(void)
Kumar Galac5651892006-01-12 19:51:38 -060061{
Ben Warrenc8135502006-09-12 10:15:53 -040062 u8 val8, orig_i2c_bus;
Kumar Galac5651892006-01-12 19:51:38 -060063 /*
64 * Assign PIB PMC slot to desired PCI bus
65 */
Ben Warrenc8135502006-09-12 10:15:53 -040066 /* Switch temporarily to I2C bus #2 */
67 orig_i2c_bus = i2c_get_bus_num();
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +010068 i2c_set_bus_num(1);
Kumar Galac5651892006-01-12 19:51:38 -060069
70 val8 = 0;
71 i2c_write(0x23, 0x6, 1, &val8, 1);
72 i2c_write(0x23, 0x7, 1, &val8, 1);
73 val8 = 0xff;
74 i2c_write(0x23, 0x2, 1, &val8, 1);
75 i2c_write(0x23, 0x3, 1, &val8, 1);
76
77 val8 = 0;
78 i2c_write(0x26, 0x6, 1, &val8, 1);
79 val8 = 0x34;
80 i2c_write(0x26, 0x7, 1, &val8, 1);
Mario Six258312f2019-01-21 09:17:51 +010081#if defined(CONFIG_PCI_64BIT)
Kumar Galac5651892006-01-12 19:51:38 -060082 val8 = 0xf4; /* PMC2:PCI1/64-bit */
Mario Six258312f2019-01-21 09:17:51 +010083#elif defined(CONFIG_PCI_ALL_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -060084 val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
Mario Six258312f2019-01-21 09:17:51 +010085#elif defined(CONFIG_PCI_ONE_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -060086 val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
87#else
88 val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
89#endif
90 i2c_write(0x26, 0x2, 1, &val8, 1);
91 val8 = 0xff;
92 i2c_write(0x26, 0x3, 1, &val8, 1);
93 val8 = 0;
94 i2c_write(0x27, 0x6, 1, &val8, 1);
95 i2c_write(0x27, 0x7, 1, &val8, 1);
96 val8 = 0xff;
97 i2c_write(0x27, 0x2, 1, &val8, 1);
98 val8 = 0xef;
99 i2c_write(0x27, 0x3, 1, &val8, 1);
100 asm("eieio");
101
Mario Six258312f2019-01-21 09:17:51 +0100102#if defined(CONFIG_PCI_64BIT)
Kumar Galac5651892006-01-12 19:51:38 -0600103 printf("PCI1: 64-bit on PMC2\n");
Mario Six258312f2019-01-21 09:17:51 +0100104#elif defined(CONFIG_PCI_ALL_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -0600105 printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
Mario Six258312f2019-01-21 09:17:51 +0100106#elif defined(CONFIG_PCI_ONE_PCI1)
Kumar Galac5651892006-01-12 19:51:38 -0600107 printf("PCI1: 32-bit on PMC1\n");
108 printf("PCI2: 32-bit on PMC2, PMC3\n");
109#else
110 printf("PCI1: 32-bit on PMC1, PMC2\n");
111 printf("PCI2: 32-bit on PMC3\n");
112#endif
Ben Warrenc8135502006-09-12 10:15:53 -0400113 /* Reset to original I2C bus */
Timur Tabiab347542006-11-03 19:15:00 -0600114 i2c_set_bus_num(orig_i2c_bus);
Kumar Galac5651892006-01-12 19:51:38 -0600115}
116
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700117void pci_init_board(void)
Kumar Galac5651892006-01-12 19:51:38 -0600118{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700120 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
121 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
122#ifndef CONFIG_MPC83XX_PCI2
123 struct pci_region *reg[] = { pci1_regions };
124#else
125 struct pci_region *reg[] = { pci1_regions, pci2_regions };
126#endif
Kumar Galac5651892006-01-12 19:51:38 -0600127
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700128 /* initialize the PCA9555PW IO expander on the PIB board */
Kumar Galac5651892006-01-12 19:51:38 -0600129 pib_init();
130
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700131 /* Enable all 8 PCI_CLK_OUTPUTS */
Kumar Galac5651892006-01-12 19:51:38 -0600132 clk->occr = 0xff000000;
133 udelay(2000);
134
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700135 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200136 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Kumar Galac5651892006-01-12 19:51:38 -0600137 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
138
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Kumar Gala4c7efd82006-04-20 13:45:32 -0500140 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
Kumar Galac5651892006-01-12 19:51:38 -0600141
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700142 udelay(2000);
Kumar Galac5651892006-01-12 19:51:38 -0600143
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700144#ifndef CONFIG_MPC83XX_PCI2
Peter Tysere2283322010-09-14 19:13:50 -0500145 mpc83xx_pci_init(1, reg);
Ira W. Snyder0da3a3d2008-08-22 11:00:13 -0700146#else
Peter Tysere2283322010-09-14 19:13:50 -0500147 mpc83xx_pci_init(2, reg);
Kumar Galac5651892006-01-12 19:51:38 -0600148#endif
Kumar Galac5651892006-01-12 19:51:38 -0600149}
Kumar Gala4c7efd82006-04-20 13:45:32 -0500150
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700151#else
152void pci_init_board(void)
153{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700155 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
156 volatile pcictrl83xx_t *pci_ctrl = &immr->pci_ctrl[0];
157 struct pci_region *reg[] = { pci1_regions };
158
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700159 /* Configure PCI Local Access Windows */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160 pci_law[0].bar = CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700161 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
162
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200163 pci_law[1].bar = CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR;
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700164 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
165
Peter Tysere2283322010-09-14 19:13:50 -0500166 mpc83xx_pci_init(1, reg);
Ira W. Snyder4adfd022008-08-22 11:00:15 -0700167
168 /* Configure PCI Inbound Translation Windows (3 1MB windows) */
169 pci_ctrl->pitar0 = 0x0;
170 pci_ctrl->pibar0 = 0x0;
171 pci_ctrl->piwar0 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
172 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
173
174 pci_ctrl->pitar1 = 0x0;
175 pci_ctrl->pibar1 = 0x0;
176 pci_ctrl->piebar1 = 0x0;
177 pci_ctrl->piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
178 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
179
180 pci_ctrl->pitar2 = 0x0;
181 pci_ctrl->pibar2 = 0x0;
182 pci_ctrl->piebar2 = 0x0;
183 pci_ctrl->piwar2 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
184 PIWAR_WTT_SNOOP | PIWAR_IWS_1M;
185
186 /* Unlock the configuration bit */
187 mpc83xx_pcislave_unlock(0);
188 printf("PCI: Agent mode enabled\n");
189}
190#endif /* CONFIG_PCISLAVE */