xref: /rk3399_rockchip-uboot/arch/powerpc/include/asm/fsl_pci.h (revision 79a34b71c943a80af5c6d9a2af736fbb37dcc14c)
1a47a12beSStefan Roese /*
27b4e5844SZang Roy-R61911  * Copyright 2007,2009-2012 Freescale Semiconductor, Inc.
3a47a12beSStefan Roese  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5a47a12beSStefan Roese  */
6a47a12beSStefan Roese 
7a47a12beSStefan Roese #ifndef __FSL_PCI_H_
8a47a12beSStefan Roese #define __FSL_PCI_H_
9a47a12beSStefan Roese 
10a47a12beSStefan Roese #include <asm/fsl_law.h>
11a4aafcc9SKumar Gala #include <asm/fsl_serdes.h>
12a4aafcc9SKumar Gala #include <pci.h>
13a47a12beSStefan Roese 
14b6ccd2c9SPrabhakar Kushwaha #define PEX_IP_BLK_REV_2_2	0x02080202
15b6ccd2c9SPrabhakar Kushwaha #define PEX_IP_BLK_REV_2_3	0x02080203
167b4e5844SZang Roy-R61911 #define PEX_IP_BLK_REV_3_0	0x02080300
177b4e5844SZang Roy-R61911 
187b4e5844SZang Roy-R61911 /* Freescale-specific PCI config registers */
197b4e5844SZang Roy-R61911 #define FSL_PCI_PBFR		0x44
207b4e5844SZang Roy-R61911 
217b4e5844SZang Roy-R61911 #define FSL_PCIE_CFG_RDY	0x4b0
221d0b59a9SMinghuan Lian #define FSL_PCIE_V3_CFG_RDY	0x1
237b4e5844SZang Roy-R61911 #define FSL_PROG_IF_AGENT	0x1
247b4e5844SZang Roy-R61911 
257b4e5844SZang Roy-R61911 #define PCI_LTSSM	0x404   /* PCIe Link Training, Status State Machine */
267b4e5844SZang Roy-R61911 #define  PCI_LTSSM_L0	0x16    /* L0 state */
27b6ccd2c9SPrabhakar Kushwaha 
28a47a12beSStefan Roese int fsl_setup_hose(struct pci_controller *hose, unsigned long addr);
29a47a12beSStefan Roese int fsl_is_pci_agent(struct pci_controller *hose);
30a47a12beSStefan Roese void fsl_pci_config_unlock(struct pci_controller *hose);
313a0e3c27SKumar Gala void ft_fsl_pci_setup(void *blob, const char *compat, unsigned long ctrl_addr);
32a47a12beSStefan Roese 
33a47a12beSStefan Roese /*
34a47a12beSStefan Roese  * Common PCI/PCIE Register structure for mpc85xx and mpc86xx
35a47a12beSStefan Roese  */
36a47a12beSStefan Roese 
37a47a12beSStefan Roese /*
38a47a12beSStefan Roese  * PCI Translation Registers
39a47a12beSStefan Roese  */
40a47a12beSStefan Roese typedef struct pci_outbound_window {
41a47a12beSStefan Roese 	u32	potar;		/* 0x00 - Address */
42a47a12beSStefan Roese 	u32	potear;		/* 0x04 - Address Extended */
43a47a12beSStefan Roese 	u32	powbar;		/* 0x08 - Window Base Address */
44a47a12beSStefan Roese 	u32	res1;
45a47a12beSStefan Roese 	u32	powar;		/* 0x10 - Window Attributes */
46a47a12beSStefan Roese #define POWAR_EN	0x80000000
47a47a12beSStefan Roese #define POWAR_IO_READ	0x00080000
48a47a12beSStefan Roese #define POWAR_MEM_READ	0x00040000
49a47a12beSStefan Roese #define POWAR_IO_WRITE	0x00008000
50a47a12beSStefan Roese #define POWAR_MEM_WRITE	0x00004000
51a47a12beSStefan Roese 	u32	res2[3];
52a47a12beSStefan Roese } pot_t;
53a47a12beSStefan Roese 
54a47a12beSStefan Roese typedef struct pci_inbound_window {
55a47a12beSStefan Roese 	u32	pitar;		/* 0x00 - Address */
56a47a12beSStefan Roese 	u32	res1;
57a47a12beSStefan Roese 	u32	piwbar;		/* 0x08 - Window Base Address */
58a47a12beSStefan Roese 	u32	piwbear;	/* 0x0c - Window Base Address Extended */
59a47a12beSStefan Roese 	u32	piwar;		/* 0x10 - Window Attributes */
60a47a12beSStefan Roese #define PIWAR_EN		0x80000000
61a47a12beSStefan Roese #define PIWAR_PF		0x20000000
62a47a12beSStefan Roese #define PIWAR_LOCAL		0x00f00000
63a47a12beSStefan Roese #define PIWAR_READ_SNOOP	0x00050000
64a47a12beSStefan Roese #define PIWAR_WRITE_SNOOP	0x00005000
65a47a12beSStefan Roese 	u32	res2[3];
66a47a12beSStefan Roese } pit_t;
67a47a12beSStefan Roese 
68a47a12beSStefan Roese /* PCI/PCI Express Registers */
69a47a12beSStefan Roese typedef struct ccsr_pci {
70a47a12beSStefan Roese 	u32	cfg_addr;	/* 0x000 - PCI Configuration Address Register */
71a47a12beSStefan Roese 	u32	cfg_data;	/* 0x004 - PCI Configuration Data Register */
72a47a12beSStefan Roese 	u32	int_ack;	/* 0x008 - PCI Interrupt Acknowledge Register */
73a47a12beSStefan Roese 	u32	out_comp_to;	/* 0x00C - PCI Outbound Completion Timeout Register */
74a47a12beSStefan Roese 	u32	out_conf_to;	/* 0x010 - PCI Configuration Timeout Register */
75a47a12beSStefan Roese 	u32	config;		/* 0x014 - PCIE CONFIG Register */
76b6ccd2c9SPrabhakar Kushwaha 	u32	int_status;	/* 0x018 - PCIE interrupt status register */
77b6ccd2c9SPrabhakar Kushwaha 	char	res2[4];
78a47a12beSStefan Roese 	u32	pme_msg_det;	/* 0x020 - PCIE PME & message detect register */
79a47a12beSStefan Roese 	u32	pme_msg_dis;	/* 0x024 - PCIE PME & message disable register */
80a47a12beSStefan Roese 	u32	pme_msg_int_en;	/* 0x028 - PCIE PME & message interrupt enable register */
81a47a12beSStefan Roese 	u32	pm_command;	/* 0x02c - PCIE PM Command register */
82*09bfd962STony O'Brien 	char	res3[2188];	/*     (0x8bc - 0x30 = 2188) */
83*09bfd962STony O'Brien 	u32	dbi_ro_wr_en;	/* 0x8bc - DBI read only write enable reg */
84*09bfd962STony O'Brien 	char	res4[824];	/*     (0xbf8 - 0x8c0 = 824) */
85a47a12beSStefan Roese 	u32	block_rev1;	/* 0xbf8 - PCIE Block Revision register 1 */
86a47a12beSStefan Roese 	u32	block_rev2;	/* 0xbfc - PCIE Block Revision register 2 */
87a47a12beSStefan Roese 
88a47a12beSStefan Roese 	pot_t	pot[5];		/* 0xc00 - 0xc9f Outbound ATMU's 0, 1, 2, 3, and 4 */
89b6ccd2c9SPrabhakar Kushwaha 	u32	res5[24];
90b6ccd2c9SPrabhakar Kushwaha 	pit_t	pmit;		/* 0xd00 - 0xd9c Inbound ATMU's MSI */
91b6ccd2c9SPrabhakar Kushwaha 	u32	res6[24];
92b6ccd2c9SPrabhakar Kushwaha 	pit_t	pit[4];		/* 0xd80 - 0xdff Inbound ATMU's 3, 2, 1 and 0 */
93b6ccd2c9SPrabhakar Kushwaha 
94a47a12beSStefan Roese #define PIT3 0
95a47a12beSStefan Roese #define PIT2 1
96a47a12beSStefan Roese #define PIT1 2
97a47a12beSStefan Roese 
98a47a12beSStefan Roese #if 0
99a47a12beSStefan Roese 	u32	potar0;		/* 0xc00 - PCI Outbound Transaction Address Register 0 */
100a47a12beSStefan Roese 	u32	potear0;	/* 0xc04 - PCI Outbound Translation Extended Address Register 0 */
101a47a12beSStefan Roese 	char	res5[8];
102a47a12beSStefan Roese 	u32	powar0;		/* 0xc10 - PCI Outbound Window Attributes Register 0 */
103a47a12beSStefan Roese 	char	res6[12];
104a47a12beSStefan Roese 	u32	potar1;		/* 0xc20 - PCI Outbound Transaction Address Register 1 */
105a47a12beSStefan Roese 	u32	potear1;	/* 0xc24 - PCI Outbound Translation Extended Address Register 1 */
106a47a12beSStefan Roese 	u32	powbar1;	/* 0xc28 - PCI Outbound Window Base Address Register 1 */
107a47a12beSStefan Roese 	char	res7[4];
108a47a12beSStefan Roese 	u32	powar1;		/* 0xc30 - PCI Outbound Window Attributes Register 1 */
109a47a12beSStefan Roese 	char	res8[12];
110a47a12beSStefan Roese 	u32	potar2;		/* 0xc40 - PCI Outbound Transaction Address Register 2 */
111a47a12beSStefan Roese 	u32	potear2;	/* 0xc44 - PCI Outbound Translation Extended Address Register 2 */
112a47a12beSStefan Roese 	u32	powbar2;	/* 0xc48 - PCI Outbound Window Base Address Register 2 */
113a47a12beSStefan Roese 	char	res9[4];
114a47a12beSStefan Roese 	u32	powar2;		/* 0xc50 - PCI Outbound Window Attributes Register 2 */
115a47a12beSStefan Roese 	char	res10[12];
116a47a12beSStefan Roese 	u32	potar3;		/* 0xc60 - PCI Outbound Transaction Address Register 3 */
117a47a12beSStefan Roese 	u32	potear3;	/* 0xc64 - PCI Outbound Translation Extended Address Register 3 */
118a47a12beSStefan Roese 	u32	powbar3;	/* 0xc68 - PCI Outbound Window Base Address Register 3 */
119a47a12beSStefan Roese 	char	res11[4];
120a47a12beSStefan Roese 	u32	powar3;		/* 0xc70 - PCI Outbound Window Attributes Register 3 */
121a47a12beSStefan Roese 	char	res12[12];
122a47a12beSStefan Roese 	u32	potar4;		/* 0xc80 - PCI Outbound Transaction Address Register 4 */
123a47a12beSStefan Roese 	u32	potear4;	/* 0xc84 - PCI Outbound Translation Extended Address Register 4 */
124a47a12beSStefan Roese 	u32	powbar4;	/* 0xc88 - PCI Outbound Window Base Address Register 4 */
125a47a12beSStefan Roese 	char	res13[4];
126a47a12beSStefan Roese 	u32	powar4;		/* 0xc90 - PCI Outbound Window Attributes Register 4 */
127a47a12beSStefan Roese 	char	res14[268];
128a47a12beSStefan Roese 	u32	pitar3;		/* 0xda0 - PCI Inbound Translation Address Register 3 */
129a47a12beSStefan Roese 	char	res15[4];
130a47a12beSStefan Roese 	u32	piwbar3;	/* 0xda8 - PCI Inbound Window Base Address Register 3 */
131a47a12beSStefan Roese 	u32	piwbear3;	/* 0xdac - PCI Inbound Window Base Extended Address Register 3 */
132a47a12beSStefan Roese 	u32	piwar3;		/* 0xdb0 - PCI Inbound Window Attributes Register 3 */
133a47a12beSStefan Roese 	char	res16[12];
134a47a12beSStefan Roese 	u32	pitar2;		/* 0xdc0 - PCI Inbound Translation Address Register 2 */
135a47a12beSStefan Roese 	char	res17[4];
136a47a12beSStefan Roese 	u32	piwbar2;	/* 0xdc8 - PCI Inbound Window Base Address Register 2 */
137a47a12beSStefan Roese 	u32	piwbear2;	/* 0xdcc - PCI Inbound Window Base Extended Address Register 2 */
138a47a12beSStefan Roese 	u32	piwar2;		/* 0xdd0 - PCI Inbound Window Attributes Register 2 */
139a47a12beSStefan Roese 	char	res18[12];
140a47a12beSStefan Roese 	u32	pitar1;		/* 0xde0 - PCI Inbound Translation Address Register 1 */
141a47a12beSStefan Roese 	char	res19[4];
142a47a12beSStefan Roese 	u32	piwbar1;	/* 0xde8 - PCI Inbound Window Base Address Register 1 */
143a47a12beSStefan Roese 	char	res20[4];
144a47a12beSStefan Roese 	u32	piwar1;		/* 0xdf0 - PCI Inbound Window Attributes Register 1 */
145a47a12beSStefan Roese 	char	res21[12];
146a47a12beSStefan Roese #endif
147a47a12beSStefan Roese 	u32	pedr;		/* 0xe00 - PCI Error Detect Register */
148a47a12beSStefan Roese 	u32	pecdr;		/* 0xe04 - PCI Error Capture Disable Register */
149a47a12beSStefan Roese 	u32	peer;		/* 0xe08 - PCI Error Interrupt Enable Register */
150a47a12beSStefan Roese 	u32	peattrcr;	/* 0xe0c - PCI Error Attributes Capture Register */
151a47a12beSStefan Roese 	u32	peaddrcr;	/* 0xe10 - PCI Error Address Capture Register */
152a47a12beSStefan Roese /*	u32	perr_disr	 * 0xe10 - PCIE Erorr Disable Register */
153a47a12beSStefan Roese 	u32	peextaddrcr;	/* 0xe14 - PCI	Error Extended Address Capture Register */
154a47a12beSStefan Roese 	u32	pedlcr;		/* 0xe18 - PCI Error Data Low Capture Register */
155a47a12beSStefan Roese 	u32	pedhcr;		/* 0xe1c - PCI Error Error Data High Capture Register */
156a47a12beSStefan Roese 	u32	gas_timr;	/* 0xe20 - PCI Gasket Timer Register */
157a47a12beSStefan Roese /*	u32	perr_cap_stat;	 * 0xe20 - PCIE Error Capture Status Register */
158a47a12beSStefan Roese 	char	res22[4];
159a47a12beSStefan Roese 	u32	perr_cap0;	/* 0xe28 - PCIE Error Capture Register 0 */
160a47a12beSStefan Roese 	u32	perr_cap1;	/* 0xe2c - PCIE Error Capture Register 1 */
161a47a12beSStefan Roese 	u32	perr_cap2;	/* 0xe30 - PCIE Error Capture Register 2 */
162a47a12beSStefan Roese 	u32	perr_cap3;	/* 0xe34 - PCIE Error Capture Register 3 */
163a47a12beSStefan Roese 	char	res23[200];
164a47a12beSStefan Roese 	u32	pdb_stat;	/* 0xf00 - PCIE Debug Status */
1657b4e5844SZang Roy-R61911 	char	res24[16];
1667b4e5844SZang Roy-R61911 	u32	pex_csr0;	/* 0xf14 - PEX Control/Status register 0*/
1677b4e5844SZang Roy-R61911 	u32	pex_csr1;	/* 0xf18 - PEX Control/Status register 1*/
1687b4e5844SZang Roy-R61911 	char	res25[228];
169a47a12beSStefan Roese } ccsr_fsl_pci_t;
170b6ccd2c9SPrabhakar Kushwaha #define PCIE_CONFIG_PC	0x00020000
171b6ccd2c9SPrabhakar Kushwaha #define PCIE_CONFIG_OB_CK	0x00002000
172b6ccd2c9SPrabhakar Kushwaha #define PCIE_CONFIG_SAC	0x00000010
173b6ccd2c9SPrabhakar Kushwaha #define PCIE_CONFIG_SP	0x80000002
174b6ccd2c9SPrabhakar Kushwaha #define PCIE_CONFIG_SCC	0x80000001
175a47a12beSStefan Roese 
176a47a12beSStefan Roese struct fsl_pci_info {
177a47a12beSStefan Roese 	unsigned long regs;
178a47a12beSStefan Roese 	pci_addr_t mem_bus;
179a47a12beSStefan Roese 	phys_size_t mem_phys;
180a47a12beSStefan Roese 	pci_size_t mem_size;
181a47a12beSStefan Roese 	pci_addr_t io_bus;
182a47a12beSStefan Roese 	phys_size_t io_phys;
183a47a12beSStefan Roese 	pci_size_t io_size;
184752bc335STimur Tabi 	enum law_trgt_if law;
185a47a12beSStefan Roese 	int pci_num;
186a47a12beSStefan Roese };
187a47a12beSStefan Roese 
188213ac73eSPeter Tyser void fsl_pci_init(struct pci_controller *hose, struct fsl_pci_info *pci_info);
189a47a12beSStefan Roese int fsl_pci_init_port(struct fsl_pci_info *pci_info,
190a47a12beSStefan Roese 				struct pci_controller *hose, int busno);
191a4aafcc9SKumar Gala int fsl_pcie_init_ctrl(int busno, u32 devdisr, enum srds_prtcl dev,
192a4aafcc9SKumar Gala 			struct fsl_pci_info *pci_info);
193a4aafcc9SKumar Gala int fsl_pcie_init_board(int busno);
194a47a12beSStefan Roese 
195a47a12beSStefan Roese #define SET_STD_PCI_INFO(x, num) \
196a47a12beSStefan Roese {			\
197a47a12beSStefan Roese 	x.regs = CONFIG_SYS_PCI##num##_ADDR;	\
198a47a12beSStefan Roese 	x.mem_bus = CONFIG_SYS_PCI##num##_MEM_BUS; \
199a47a12beSStefan Roese 	x.mem_phys = CONFIG_SYS_PCI##num##_MEM_PHYS; \
200a47a12beSStefan Roese 	x.mem_size = CONFIG_SYS_PCI##num##_MEM_SIZE; \
201a47a12beSStefan Roese 	x.io_bus = CONFIG_SYS_PCI##num##_IO_BUS; \
202a47a12beSStefan Roese 	x.io_phys = CONFIG_SYS_PCI##num##_IO_PHYS; \
203a47a12beSStefan Roese 	x.io_size = CONFIG_SYS_PCI##num##_IO_SIZE; \
204752bc335STimur Tabi 	x.law = LAW_TRGT_IF_PCI_##num; \
205a47a12beSStefan Roese 	x.pci_num = num; \
206a47a12beSStefan Roese }
207a47a12beSStefan Roese 
208a47a12beSStefan Roese #define SET_STD_PCIE_INFO(x, num) \
209a47a12beSStefan Roese {			\
210a47a12beSStefan Roese 	x.regs = CONFIG_SYS_PCIE##num##_ADDR;	\
211a47a12beSStefan Roese 	x.mem_bus = CONFIG_SYS_PCIE##num##_MEM_BUS; \
212a47a12beSStefan Roese 	x.mem_phys = CONFIG_SYS_PCIE##num##_MEM_PHYS; \
213a47a12beSStefan Roese 	x.mem_size = CONFIG_SYS_PCIE##num##_MEM_SIZE; \
214a47a12beSStefan Roese 	x.io_bus = CONFIG_SYS_PCIE##num##_IO_BUS; \
215a47a12beSStefan Roese 	x.io_phys = CONFIG_SYS_PCIE##num##_IO_PHYS; \
216a47a12beSStefan Roese 	x.io_size = CONFIG_SYS_PCIE##num##_IO_SIZE; \
217752bc335STimur Tabi 	x.law = LAW_TRGT_IF_PCIE_##num; \
218a47a12beSStefan Roese 	x.pci_num = num; \
219a47a12beSStefan Roese }
220a47a12beSStefan Roese 
2216525d51fSKumar Gala #define __FT_FSL_PCI_SETUP(blob, compat, num) \
2223a0e3c27SKumar Gala 	ft_fsl_pci_setup(blob, compat, CONFIG_SYS_PCI##num##_ADDR)
2236525d51fSKumar Gala 
2246525d51fSKumar Gala #define __FT_FSL_PCIE_SETUP(blob, compat, num) \
2253a0e3c27SKumar Gala 	ft_fsl_pci_setup(blob, compat, CONFIG_SYS_PCIE##num##_ADDR)
2266525d51fSKumar Gala 
2276525d51fSKumar Gala #define FT_FSL_PCI1_SETUP __FT_FSL_PCI_SETUP(blob, FSL_PCI_COMPAT, 1)
2286525d51fSKumar Gala #define FT_FSL_PCI2_SETUP __FT_FSL_PCI_SETUP(blob, FSL_PCI_COMPAT, 2)
2296525d51fSKumar Gala 
2306525d51fSKumar Gala #define FT_FSL_PCIE1_SETUP __FT_FSL_PCIE_SETUP(blob, FSL_PCIE_COMPAT, 1)
2316525d51fSKumar Gala #define FT_FSL_PCIE2_SETUP __FT_FSL_PCIE_SETUP(blob, FSL_PCIE_COMPAT, 2)
2326525d51fSKumar Gala #define FT_FSL_PCIE3_SETUP __FT_FSL_PCIE_SETUP(blob, FSL_PCIE_COMPAT, 3)
2336525d51fSKumar Gala #define FT_FSL_PCIE4_SETUP __FT_FSL_PCIE_SETUP(blob, FSL_PCIE_COMPAT, 4)
2346525d51fSKumar Gala 
235ae425c1eSMatthew McClintock #if !defined(CONFIG_PCI)
236ae425c1eSMatthew McClintock #define FT_FSL_PCI_SETUP
237ae425c1eSMatthew McClintock #elif defined(CONFIG_FSL_CORENET)
2388f29084aSKumar Gala #define FSL_PCIE_COMPAT	CONFIG_SYS_FSL_PCIE_COMPAT
2396525d51fSKumar Gala #define FT_FSL_PCI_SETUP \
2406525d51fSKumar Gala 	FT_FSL_PCIE1_SETUP; \
2416525d51fSKumar Gala 	FT_FSL_PCIE2_SETUP; \
2426525d51fSKumar Gala 	FT_FSL_PCIE3_SETUP; \
2436525d51fSKumar Gala 	FT_FSL_PCIE4_SETUP;
244a4aafcc9SKumar Gala #define FT_FSL_PCIE_SETUP FT_FSL_PCI_SETUP
2456525d51fSKumar Gala #elif defined(CONFIG_MPC85xx)
2466525d51fSKumar Gala #define FSL_PCI_COMPAT	"fsl,mpc8540-pci"
2478f29084aSKumar Gala #ifdef CONFIG_SYS_FSL_PCIE_COMPAT
2488f29084aSKumar Gala #define FSL_PCIE_COMPAT	CONFIG_SYS_FSL_PCIE_COMPAT
2498f29084aSKumar Gala #else
2506525d51fSKumar Gala #define FSL_PCIE_COMPAT	"fsl,mpc8548-pcie"
2518f29084aSKumar Gala #endif
2526525d51fSKumar Gala #define FT_FSL_PCI_SETUP \
2536525d51fSKumar Gala 	FT_FSL_PCI1_SETUP; \
2546525d51fSKumar Gala 	FT_FSL_PCI2_SETUP; \
2556525d51fSKumar Gala 	FT_FSL_PCIE1_SETUP; \
2566525d51fSKumar Gala 	FT_FSL_PCIE2_SETUP; \
2576525d51fSKumar Gala 	FT_FSL_PCIE3_SETUP;
258a4aafcc9SKumar Gala #define FT_FSL_PCIE_SETUP \
259a4aafcc9SKumar Gala 	FT_FSL_PCIE1_SETUP; \
260a4aafcc9SKumar Gala 	FT_FSL_PCIE2_SETUP; \
261a4aafcc9SKumar Gala 	FT_FSL_PCIE3_SETUP;
2626525d51fSKumar Gala #elif defined(CONFIG_MPC86xx)
2636525d51fSKumar Gala #define FSL_PCI_COMPAT	"fsl,mpc8610-pci"
2646525d51fSKumar Gala #define FSL_PCIE_COMPAT	"fsl,mpc8641-pcie"
2656525d51fSKumar Gala #define FT_FSL_PCI_SETUP \
2666525d51fSKumar Gala 	FT_FSL_PCI1_SETUP; \
2676525d51fSKumar Gala 	FT_FSL_PCIE1_SETUP; \
2686525d51fSKumar Gala 	FT_FSL_PCIE2_SETUP;
2696525d51fSKumar Gala #else
2706525d51fSKumar Gala #error FT_FSL_PCI_SETUP not defined
2716525d51fSKumar Gala #endif
2726525d51fSKumar Gala 
2736525d51fSKumar Gala 
274a47a12beSStefan Roese #endif
275