xref: /rk3399_rockchip-uboot/board/freescale/mpc837xerdb/pci.c (revision 326ea986ac150acdc7656d57fca647db80b50158)
15e918a98SKim Phillips /*
29993e196SKim Phillips  * Copyright (C) 2006-2009 Freescale Semiconductor, Inc.
35e918a98SKim Phillips  *
4*1a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
55e918a98SKim Phillips  */
65e918a98SKim Phillips 
75e918a98SKim Phillips #include <common.h>
85e918a98SKim Phillips #include <mpc83xx.h>
95e918a98SKim Phillips #include <pci.h>
107e915580SAnton Vorontsov #include <asm/io.h>
115e918a98SKim Phillips 
125e918a98SKim Phillips static struct pci_region pci_regions[] = {
135e918a98SKim Phillips 	{
146d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		bus_start: CONFIG_SYS_PCI_MEM_BASE,
156d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		phys_start: CONFIG_SYS_PCI_MEM_PHYS,
166d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		size: CONFIG_SYS_PCI_MEM_SIZE,
175e918a98SKim Phillips 		flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
185e918a98SKim Phillips 	},
195e918a98SKim Phillips 	{
206d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		bus_start: CONFIG_SYS_PCI_MMIO_BASE,
216d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		phys_start: CONFIG_SYS_PCI_MMIO_PHYS,
226d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		size: CONFIG_SYS_PCI_MMIO_SIZE,
235e918a98SKim Phillips 		flags: PCI_REGION_MEM
245e918a98SKim Phillips 	},
255e918a98SKim Phillips 	{
266d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		bus_start: CONFIG_SYS_PCI_IO_BASE,
276d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		phys_start: CONFIG_SYS_PCI_IO_PHYS,
286d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 		size: CONFIG_SYS_PCI_IO_SIZE,
295e918a98SKim Phillips 		flags: PCI_REGION_IO
305e918a98SKim Phillips 	}
315e918a98SKim Phillips };
325e918a98SKim Phillips 
337e915580SAnton Vorontsov static struct pci_region pcie_regions_0[] = {
347e915580SAnton Vorontsov 	{
357e915580SAnton Vorontsov 		.bus_start = CONFIG_SYS_PCIE1_MEM_BASE,
367e915580SAnton Vorontsov 		.phys_start = CONFIG_SYS_PCIE1_MEM_PHYS,
377e915580SAnton Vorontsov 		.size = CONFIG_SYS_PCIE1_MEM_SIZE,
387e915580SAnton Vorontsov 		.flags = PCI_REGION_MEM,
397e915580SAnton Vorontsov 	},
407e915580SAnton Vorontsov 	{
417e915580SAnton Vorontsov 		.bus_start = CONFIG_SYS_PCIE1_IO_BASE,
427e915580SAnton Vorontsov 		.phys_start = CONFIG_SYS_PCIE1_IO_PHYS,
437e915580SAnton Vorontsov 		.size = CONFIG_SYS_PCIE1_IO_SIZE,
447e915580SAnton Vorontsov 		.flags = PCI_REGION_IO,
457e915580SAnton Vorontsov 	},
467e915580SAnton Vorontsov };
477e915580SAnton Vorontsov 
487e915580SAnton Vorontsov static struct pci_region pcie_regions_1[] = {
497e915580SAnton Vorontsov 	{
507e915580SAnton Vorontsov 		.bus_start = CONFIG_SYS_PCIE2_MEM_BASE,
517e915580SAnton Vorontsov 		.phys_start = CONFIG_SYS_PCIE2_MEM_PHYS,
527e915580SAnton Vorontsov 		.size = CONFIG_SYS_PCIE2_MEM_SIZE,
537e915580SAnton Vorontsov 		.flags = PCI_REGION_MEM,
547e915580SAnton Vorontsov 	},
557e915580SAnton Vorontsov 	{
567e915580SAnton Vorontsov 		.bus_start = CONFIG_SYS_PCIE2_IO_BASE,
577e915580SAnton Vorontsov 		.phys_start = CONFIG_SYS_PCIE2_IO_PHYS,
587e915580SAnton Vorontsov 		.size = CONFIG_SYS_PCIE2_IO_SIZE,
597e915580SAnton Vorontsov 		.flags = PCI_REGION_IO,
607e915580SAnton Vorontsov 	},
617e915580SAnton Vorontsov };
627e915580SAnton Vorontsov 
pci_init_board(void)635e918a98SKim Phillips void pci_init_board(void)
645e918a98SKim Phillips {
656d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
667e915580SAnton Vorontsov 	volatile sysconf83xx_t *sysconf = &immr->sysconf;
675e918a98SKim Phillips 	volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
685e918a98SKim Phillips 	volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
697e915580SAnton Vorontsov 	volatile law83xx_t *pcie_law = sysconf->pcielaw;
705e918a98SKim Phillips 	struct pci_region *reg[] = { pci_regions };
717e915580SAnton Vorontsov 	struct pci_region *pcie_reg[] = { pcie_regions_0, pcie_regions_1, };
727e915580SAnton Vorontsov 	u32 spridr = in_be32(&immr->sysconf.spridr);
735e918a98SKim Phillips 
745e918a98SKim Phillips 	/* Enable all 5 PCI_CLK_OUTPUTS */
755e918a98SKim Phillips 	clk->occr |= 0xf8000000;
765e918a98SKim Phillips 	udelay(2000);
775e918a98SKim Phillips 
785e918a98SKim Phillips 	/* Configure PCI Local Access Windows */
796d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	pci_law[0].bar = CONFIG_SYS_PCI_MEM_PHYS & LAWBAR_BAR;
805e918a98SKim Phillips 	pci_law[0].ar = LBLAWAR_EN | LBLAWAR_512MB;
815e918a98SKim Phillips 
826d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	pci_law[1].bar = CONFIG_SYS_PCI_IO_PHYS & LAWBAR_BAR;
835e918a98SKim Phillips 	pci_law[1].ar = LBLAWAR_EN | LBLAWAR_1MB;
845e918a98SKim Phillips 
856aa3d3bfSPeter Tyser 	mpc83xx_pci_init(1, reg);
867e915580SAnton Vorontsov 
877e915580SAnton Vorontsov 	/* There is no PEX in MPC8379 parts. */
887e915580SAnton Vorontsov 	if (PARTID_NO_E(spridr) == SPR_8379)
897e915580SAnton Vorontsov 		return;
907e915580SAnton Vorontsov 
917e915580SAnton Vorontsov 	/* Configure the clock for PCIE controller */
927e915580SAnton Vorontsov 	clrsetbits_be32(&clk->sccr, SCCR_PCIEXP1CM | SCCR_PCIEXP2CM,
937e915580SAnton Vorontsov 				    SCCR_PCIEXP1CM_1 | SCCR_PCIEXP2CM_1);
947e915580SAnton Vorontsov 
957e915580SAnton Vorontsov 	/* Deassert the resets in the control register */
967e915580SAnton Vorontsov 	out_be32(&sysconf->pecr1, 0xE0008000);
977e915580SAnton Vorontsov 	out_be32(&sysconf->pecr2, 0xE0008000);
987e915580SAnton Vorontsov 	udelay(2000);
997e915580SAnton Vorontsov 
1007e915580SAnton Vorontsov 	/* Configure PCI Express Local Access Windows */
1017e915580SAnton Vorontsov 	out_be32(&pcie_law[0].bar, CONFIG_SYS_PCIE1_BASE & LAWBAR_BAR);
1027e915580SAnton Vorontsov 	out_be32(&pcie_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
1037e915580SAnton Vorontsov 
1047e915580SAnton Vorontsov 	out_be32(&pcie_law[1].bar, CONFIG_SYS_PCIE2_BASE & LAWBAR_BAR);
1057e915580SAnton Vorontsov 	out_be32(&pcie_law[1].ar, LBLAWAR_EN | LBLAWAR_512MB);
1067e915580SAnton Vorontsov 
1076aa3d3bfSPeter Tyser 	mpc83xx_pcie_init(2, pcie_reg);
1085e918a98SKim Phillips }
109