blob: b7835c0fee544bb9ca18b75ea1dc29c4b226ad26 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenk9c53f402003-10-15 23:53:47 +00002/*
wdenk13eb2212004-07-09 23:27:13 +00003 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-10-15 23:53:47 +00004 * Copyright (C) 2003 Motorola Inc.
5 * Xianghua Xiao (x.xiao@motorola.com)
wdenk9c53f402003-10-15 23:53:47 +00006 */
7
8/*
9 * PCI Configuration space access support for MPC85xx PCI Bridge
10 */
11#include <common.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060012#include <asm/bitops.h>
wdenk9c53f402003-10-15 23:53:47 +000013#include <asm/cpm_85xx.h>
14#include <pci.h>
15
Hou Zhiqiang6ff48742019-04-22 21:50:34 +080016#if !defined(CONFIG_FSL_PCI_INIT) && !defined(CONFIG_DM_PCI)
wdenk13eb2212004-07-09 23:27:13 +000017
Kumar Gala3fe80872008-12-02 16:08:36 -060018#ifndef CONFIG_SYS_PCI1_MEM_BUS
19#define CONFIG_SYS_PCI1_MEM_BUS CONFIG_SYS_PCI1_MEM_BASE
20#endif
21
Kumar Gala64bb6d12008-12-02 16:08:37 -060022#ifndef CONFIG_SYS_PCI1_IO_BUS
23#define CONFIG_SYS_PCI1_IO_BUS CONFIG_SYS_PCI1_IO_BASE
24#endif
25
Kumar Gala3fe80872008-12-02 16:08:36 -060026#ifndef CONFIG_SYS_PCI2_MEM_BUS
27#define CONFIG_SYS_PCI2_MEM_BUS CONFIG_SYS_PCI2_MEM_BASE
28#endif
29
Kumar Gala64bb6d12008-12-02 16:08:37 -060030#ifndef CONFIG_SYS_PCI2_IO_BUS
31#define CONFIG_SYS_PCI2_IO_BUS CONFIG_SYS_PCI2_IO_BASE
32#endif
33
Matthew McClintockf5e4f282006-06-28 10:45:17 -050034static struct pci_controller *pci_hose;
35
wdenk492b9e72004-08-01 23:02:45 +000036void
Matthew McClintockf5e4f282006-06-28 10:45:17 -050037pci_mpc85xx_init(struct pci_controller *board_hose)
wdenk9c53f402003-10-15 23:53:47 +000038{
Matthew McClintockf5e4f282006-06-28 10:45:17 -050039 u16 reg16;
40 u32 dev;
41
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 volatile ccsr_pcix_t *pcix = (void *)(CONFIG_SYS_MPC85xx_PCIX_ADDR);
Matthew McClintock5b948822006-10-11 15:13:01 -050043#ifdef CONFIG_MPC85XX_PCI2
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 volatile ccsr_pcix_t *pcix2 = (void *)(CONFIG_SYS_MPC85xx_PCIX2_ADDR);
Matthew McClintock5b948822006-10-11 15:13:01 -050045#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Matthew McClintockf5e4f282006-06-28 10:45:17 -050047 struct pci_controller * hose;
wdenk9c53f402003-10-15 23:53:47 +000048
Matthew McClintockf5e4f282006-06-28 10:45:17 -050049 pci_hose = board_hose;
50
51 hose = &pci_hose[0];
wdenk9c53f402003-10-15 23:53:47 +000052
wdenk13eb2212004-07-09 23:27:13 +000053 hose->first_busno = 0;
54 hose->last_busno = 0xff;
wdenk9c53f402003-10-15 23:53:47 +000055
wdenk492b9e72004-08-01 23:02:45 +000056 pci_setup_indirect(hose,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 (CONFIG_SYS_IMMR+0x8000),
58 (CONFIG_SYS_IMMR+0x8004));
wdenk9c53f402003-10-15 23:53:47 +000059
Matthew McClintockf5e4f282006-06-28 10:45:17 -050060 /*
61 * Hose scan.
62 */
63 dev = PCI_BDF(hose->first_busno, 0, 0);
64 pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
65 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
66 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
67
68 /*
69 * Clear non-reserved bits in status register.
70 */
71 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
72
Peter Tyseraf7c3e32008-12-01 13:47:12 -060073 if (!(gur->pordevsr & MPC85xx_PORDEVSR_PCI1)) {
Matthew McClintockf5e4f282006-06-28 10:45:17 -050074 /* PCI-X init */
Matthew McClintock5817a862006-06-28 10:47:03 -050075 if (CONFIG_SYS_CLK_FREQ < 66000000)
76 printf("PCI-X will only work at 66 MHz\n");
77
Matthew McClintockf5e4f282006-06-28 10:45:17 -050078 reg16 = PCI_X_CMD_MAX_SPLIT | PCI_X_CMD_MAX_READ
79 | PCI_X_CMD_ERO | PCI_X_CMD_DPERR_E;
80 pci_hose_write_config_word(hose, dev, PCIX_COMMAND, reg16);
81 }
82
Kumar Gala3fe80872008-12-02 16:08:36 -060083 pcix->potar1 = (CONFIG_SYS_PCI1_MEM_BUS >> 12) & 0x000fffff;
wdenk492b9e72004-08-01 23:02:45 +000084 pcix->potear1 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085 pcix->powbar1 = (CONFIG_SYS_PCI1_MEM_PHYS >> 12) & 0x000fffff;
wdenk13eb2212004-07-09 23:27:13 +000086 pcix->powbear1 = 0x00000000;
Matthew McClintockf5e4f282006-06-28 10:45:17 -050087 pcix->powar1 = (POWAR_EN | POWAR_MEM_READ |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088 POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI1_MEM_SIZE) - 1));
wdenk9c53f402003-10-15 23:53:47 +000089
Kumar Gala64bb6d12008-12-02 16:08:37 -060090 pcix->potar2 = (CONFIG_SYS_PCI1_IO_BUS >> 12) & 0x000fffff;
wdenk492b9e72004-08-01 23:02:45 +000091 pcix->potear2 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020092 pcix->powbar2 = (CONFIG_SYS_PCI1_IO_PHYS >> 12) & 0x000fffff;
wdenk13eb2212004-07-09 23:27:13 +000093 pcix->powbear2 = 0x00000000;
Matthew McClintockf5e4f282006-06-28 10:45:17 -050094 pcix->powar2 = (POWAR_EN | POWAR_IO_READ |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020095 POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI1_IO_SIZE) - 1));
wdenk9c53f402003-10-15 23:53:47 +000096
wdenk13eb2212004-07-09 23:27:13 +000097 pcix->pitar1 = 0x00000000;
98 pcix->piwbar1 = 0x00000000;
Matthew McClintockf5e4f282006-06-28 10:45:17 -050099 pcix->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
100 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
wdenk9c53f402003-10-15 23:53:47 +0000101
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500102 pcix->powar3 = 0;
103 pcix->powar4 = 0;
104 pcix->piwar2 = 0;
105 pcix->piwar3 = 0;
wdenk0424e5d2004-10-10 20:23:57 +0000106
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500107 pci_set_region(hose->regions + 0,
Kumar Gala3fe80872008-12-02 16:08:36 -0600108 CONFIG_SYS_PCI1_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109 CONFIG_SYS_PCI1_MEM_PHYS,
110 CONFIG_SYS_PCI1_MEM_SIZE,
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500111 PCI_REGION_MEM);
Stefan Roese8c695512005-11-07 13:43:06 +0100112
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500113 pci_set_region(hose->regions + 1,
Kumar Gala64bb6d12008-12-02 16:08:37 -0600114 CONFIG_SYS_PCI1_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 CONFIG_SYS_PCI1_IO_PHYS,
116 CONFIG_SYS_PCI1_IO_SIZE,
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500117 PCI_REGION_IO);
118
119 hose->region_count = 2;
120
121 pci_register_hose(hose);
Stefan Roese8c695512005-11-07 13:43:06 +0100122
wdenk492b9e72004-08-01 23:02:45 +0000123 hose->last_busno = pci_hose_scan(hose);
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500124
125#ifdef CONFIG_MPC85XX_PCI2
126 hose = &pci_hose[1];
127
128 hose->first_busno = pci_hose[0].last_busno + 1;
129 hose->last_busno = 0xff;
130
131 pci_setup_indirect(hose,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200132 (CONFIG_SYS_IMMR+0x9000),
133 (CONFIG_SYS_IMMR+0x9004));
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500134
135 dev = PCI_BDF(hose->first_busno, 0, 0);
136 pci_hose_read_config_word (hose, dev, PCI_COMMAND, &reg16);
137 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
138 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
139
140 /*
141 * Clear non-reserved bits in status register.
142 */
143 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
144
Kumar Gala3fe80872008-12-02 16:08:36 -0600145 pcix2->potar1 = (CONFIG_SYS_PCI2_MEM_BUS >> 12) & 0x000fffff;
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500146 pcix2->potear1 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200147 pcix2->powbar1 = (CONFIG_SYS_PCI2_MEM_PHYS >> 12) & 0x000fffff;
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500148 pcix2->powbear1 = 0x00000000;
149 pcix2->powar1 = (POWAR_EN | POWAR_MEM_READ |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 POWAR_MEM_WRITE | (__ilog2(CONFIG_SYS_PCI2_MEM_SIZE) - 1));
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500151
Kumar Gala64bb6d12008-12-02 16:08:37 -0600152 pcix2->potar2 = (CONFIG_SYS_PCI2_IO_BUS >> 12) & 0x000fffff;
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500153 pcix2->potear2 = 0x00000000;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200154 pcix2->powbar2 = (CONFIG_SYS_PCI2_IO_PHYS >> 12) & 0x000fffff;
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500155 pcix2->powbear2 = 0x00000000;
156 pcix2->powar2 = (POWAR_EN | POWAR_IO_READ |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157 POWAR_IO_WRITE | (__ilog2(CONFIG_SYS_PCI2_IO_SIZE) - 1));
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500158
159 pcix2->pitar1 = 0x00000000;
160 pcix2->piwbar1 = 0x00000000;
161 pcix2->piwar1 = (PIWAR_EN | PIWAR_PF | PIWAR_LOCAL |
162 PIWAR_READ_SNOOP | PIWAR_WRITE_SNOOP | PIWAR_MEM_2G);
163
164 pcix2->powar3 = 0;
165 pcix2->powar4 = 0;
166 pcix2->piwar2 = 0;
167 pcix2->piwar3 = 0;
168
169 pci_set_region(hose->regions + 0,
Kumar Gala3fe80872008-12-02 16:08:36 -0600170 CONFIG_SYS_PCI2_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200171 CONFIG_SYS_PCI2_MEM_PHYS,
172 CONFIG_SYS_PCI2_MEM_SIZE,
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500173 PCI_REGION_MEM);
174
175 pci_set_region(hose->regions + 1,
Kumar Gala64bb6d12008-12-02 16:08:37 -0600176 CONFIG_SYS_PCI2_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200177 CONFIG_SYS_PCI2_IO_PHYS,
178 CONFIG_SYS_PCI2_IO_SIZE,
Matthew McClintockf5e4f282006-06-28 10:45:17 -0500179 PCI_REGION_IO);
180
181 hose->region_count = 2;
182
183 /*
184 * Hose scan.
185 */
186 pci_register_hose(hose);
187
188 hose->last_busno = pci_hose_scan(hose);
189#endif
wdenk9c53f402003-10-15 23:53:47 +0000190}
Kumar Gala591ac072009-09-02 09:00:50 -0500191#endif /* !CONFIG_FSL_PCI_INIT */