xref: /openbmc/linux/arch/mips/pci/pci-rc32434.c (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
173b4390fSRalf Baechle /*
273b4390fSRalf Baechle  *  BRIEF MODULE DESCRIPTION
373b4390fSRalf Baechle  *     PCI initialization for IDT EB434 board
473b4390fSRalf Baechle  *
573b4390fSRalf Baechle  *  Copyright 2004 IDT Inc. (rischelp@idt.com)
673b4390fSRalf Baechle  *
773b4390fSRalf Baechle  *  This program is free software; you can redistribute  it and/or modify it
873b4390fSRalf Baechle  *  under  the terms of  the GNU General  Public License as published by the
973b4390fSRalf Baechle  *  Free Software Foundation;  either version 2 of the  License, or (at your
1073b4390fSRalf Baechle  *  option) any later version.
1173b4390fSRalf Baechle  *
1273b4390fSRalf Baechle  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
1373b4390fSRalf Baechle  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
1473b4390fSRalf Baechle  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
1573b4390fSRalf Baechle  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
1673b4390fSRalf Baechle  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1773b4390fSRalf Baechle  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
1873b4390fSRalf Baechle  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
1973b4390fSRalf Baechle  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
2073b4390fSRalf Baechle  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2173b4390fSRalf Baechle  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2273b4390fSRalf Baechle  *
2373b4390fSRalf Baechle  *  You should have received a copy of the  GNU General Public License along
2473b4390fSRalf Baechle  *  with this program; if not, write  to the Free Software Foundation, Inc.,
2573b4390fSRalf Baechle  *  675 Mass Ave, Cambridge, MA 02139, USA.
2673b4390fSRalf Baechle  */
2773b4390fSRalf Baechle 
2873b4390fSRalf Baechle #include <linux/types.h>
2973b4390fSRalf Baechle #include <linux/pci.h>
3073b4390fSRalf Baechle #include <linux/kernel.h>
3173b4390fSRalf Baechle #include <linux/init.h>
3273b4390fSRalf Baechle 
3373b4390fSRalf Baechle #include <asm/mach-rc32434/rc32434.h>
3473b4390fSRalf Baechle #include <asm/mach-rc32434/pci.h>
3573b4390fSRalf Baechle 
3673b4390fSRalf Baechle #define PCI_ACCESS_READ	 0
3773b4390fSRalf Baechle #define PCI_ACCESS_WRITE 1
3873b4390fSRalf Baechle 
3973b4390fSRalf Baechle /* define an unsigned array for the PCI registers */
4073b4390fSRalf Baechle static unsigned int korina_cnfg_regs[25] = {
4173b4390fSRalf Baechle 	KORINA_CNFG1, KORINA_CNFG2, KORINA_CNFG3, KORINA_CNFG4,
4273b4390fSRalf Baechle 	KORINA_CNFG5, KORINA_CNFG6, KORINA_CNFG7, KORINA_CNFG8,
4373b4390fSRalf Baechle 	KORINA_CNFG9, KORINA_CNFG10, KORINA_CNFG11, KORINA_CNFG12,
4473b4390fSRalf Baechle 	KORINA_CNFG13, KORINA_CNFG14, KORINA_CNFG15, KORINA_CNFG16,
4573b4390fSRalf Baechle 	KORINA_CNFG17, KORINA_CNFG18, KORINA_CNFG19, KORINA_CNFG20,
4673b4390fSRalf Baechle 	KORINA_CNFG21, KORINA_CNFG22, KORINA_CNFG23, KORINA_CNFG24
4773b4390fSRalf Baechle };
4873b4390fSRalf Baechle static struct resource rc32434_res_pci_mem1;
4973b4390fSRalf Baechle static struct resource rc32434_res_pci_mem2;
5073b4390fSRalf Baechle 
5173b4390fSRalf Baechle static struct resource rc32434_res_pci_mem1 = {
5273b4390fSRalf Baechle 	.name = "PCI MEM1",
5373b4390fSRalf Baechle 	.start = 0x50000000,
5473b4390fSRalf Baechle 	.end = 0x5FFFFFFF,
5573b4390fSRalf Baechle 	.flags = IORESOURCE_MEM,
5673b4390fSRalf Baechle 	.sibling = NULL,
5773b4390fSRalf Baechle 	.child = &rc32434_res_pci_mem2
5873b4390fSRalf Baechle };
5973b4390fSRalf Baechle 
6073b4390fSRalf Baechle static struct resource rc32434_res_pci_mem2 = {
6173b4390fSRalf Baechle 	.name = "PCI Mem2",
6273b4390fSRalf Baechle 	.start = 0x60000000,
6373b4390fSRalf Baechle 	.end = 0x6FFFFFFF,
6473b4390fSRalf Baechle 	.flags = IORESOURCE_MEM,
6573b4390fSRalf Baechle 	.parent = &rc32434_res_pci_mem1,
6673b4390fSRalf Baechle 	.sibling = NULL,
6773b4390fSRalf Baechle 	.child = NULL
6873b4390fSRalf Baechle };
6973b4390fSRalf Baechle 
7073b4390fSRalf Baechle static struct resource rc32434_res_pci_io1 = {
7173b4390fSRalf Baechle 	.name = "PCI I/O1",
7273b4390fSRalf Baechle 	.start = 0x18800000,
7373b4390fSRalf Baechle 	.end = 0x188FFFFF,
7473b4390fSRalf Baechle 	.flags = IORESOURCE_IO,
7573b4390fSRalf Baechle };
7673b4390fSRalf Baechle 
7773b4390fSRalf Baechle extern struct pci_ops rc32434_pci_ops;
7873b4390fSRalf Baechle 
7973b4390fSRalf Baechle #define PCI_MEM1_START	PCI_ADDR_START
8073b4390fSRalf Baechle #define PCI_MEM1_END	(PCI_ADDR_START + CPUTOPCI_MEM_WIN - 1)
8173b4390fSRalf Baechle #define PCI_MEM2_START	(PCI_ADDR_START + CPUTOPCI_MEM_WIN)
8273b4390fSRalf Baechle #define PCI_MEM2_END	(PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN)  - 1)
8373b4390fSRalf Baechle #define PCI_IO1_START	(PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN))
8473b4390fSRalf Baechle #define PCI_IO1_END							\
8573b4390fSRalf Baechle 	(PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN - 1)
8673b4390fSRalf Baechle #define PCI_IO2_START							\
8773b4390fSRalf Baechle 	(PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + CPUTOPCI_IO_WIN)
8873b4390fSRalf Baechle #define PCI_IO2_END							\
8973b4390fSRalf Baechle 	(PCI_ADDR_START + (2 * CPUTOPCI_MEM_WIN) + (2 * CPUTOPCI_IO_WIN) - 1)
9073b4390fSRalf Baechle 
9173b4390fSRalf Baechle struct pci_controller rc32434_controller2;
9273b4390fSRalf Baechle 
9373b4390fSRalf Baechle struct pci_controller rc32434_controller = {
9473b4390fSRalf Baechle 	.pci_ops = &rc32434_pci_ops,
9573b4390fSRalf Baechle 	.mem_resource = &rc32434_res_pci_mem1,
9673b4390fSRalf Baechle 	.io_resource = &rc32434_res_pci_io1,
9773b4390fSRalf Baechle 	.mem_offset = 0,
9873b4390fSRalf Baechle 	.io_offset = 0,
9973b4390fSRalf Baechle 
10073b4390fSRalf Baechle };
10173b4390fSRalf Baechle 
10273b4390fSRalf Baechle #ifdef __MIPSEB__
10373b4390fSRalf Baechle #define PCI_ENDIAN_FLAG PCILBAC_sb_m
10473b4390fSRalf Baechle #else
10573b4390fSRalf Baechle #define PCI_ENDIAN_FLAG 0
10673b4390fSRalf Baechle #endif
10773b4390fSRalf Baechle 
rc32434_pcibridge_init(void)10873b4390fSRalf Baechle static int __init rc32434_pcibridge_init(void)
10973b4390fSRalf Baechle {
11073b4390fSRalf Baechle 	unsigned int pcicvalue, pcicdata = 0;
11173b4390fSRalf Baechle 	unsigned int dummyread, pcicntlval;
11273b4390fSRalf Baechle 	int loopCount;
11373b4390fSRalf Baechle 	unsigned int pci_config_addr;
11473b4390fSRalf Baechle 
11573b4390fSRalf Baechle 	pcicvalue = rc32434_pci->pcic;
11673b4390fSRalf Baechle 	pcicvalue = (pcicvalue >> PCIM_SHFT) & PCIM_BIT_LEN;
11773b4390fSRalf Baechle 	if (!((pcicvalue == PCIM_H_EA) ||
11873b4390fSRalf Baechle 	      (pcicvalue == PCIM_H_IA_FIX) ||
11973b4390fSRalf Baechle 	      (pcicvalue == PCIM_H_IA_RR))) {
1207dde29cbSJoe Perches 		pr_err("PCI init error!!!\n");
12173b4390fSRalf Baechle 		/* Not in Host Mode, return ERROR */
12273b4390fSRalf Baechle 		return -1;
12373b4390fSRalf Baechle 	}
12473b4390fSRalf Baechle 	/* Enables the Idle Grant mode, Arbiter Parking */
12573b4390fSRalf Baechle 	pcicdata |= (PCI_CTL_IGM | PCI_CTL_EAP | PCI_CTL_EN);
12673b4390fSRalf Baechle 	rc32434_pci->pcic = pcicdata;	/* Enable the PCI bus Interface */
12773b4390fSRalf Baechle 	/* Zero out the PCI status & PCI Status Mask */
12873b4390fSRalf Baechle 	for (;;) {
12973b4390fSRalf Baechle 		pcicdata = rc32434_pci->pcis;
13073b4390fSRalf Baechle 		if (!(pcicdata & PCI_STAT_RIP))
13173b4390fSRalf Baechle 			break;
13273b4390fSRalf Baechle 	}
13373b4390fSRalf Baechle 
13473b4390fSRalf Baechle 	rc32434_pci->pcis = 0;
13573b4390fSRalf Baechle 	rc32434_pci->pcism = 0xFFFFFFFF;
13673b4390fSRalf Baechle 	/* Zero out the PCI decoupled registers */
13773b4390fSRalf Baechle 	rc32434_pci->pcidac = 0;	/*
13873b4390fSRalf Baechle 					 * disable PCI decoupled accesses at
13973b4390fSRalf Baechle 					 * initialization
14073b4390fSRalf Baechle 					 */
14173b4390fSRalf Baechle 	rc32434_pci->pcidas = 0;	/* clear the status */
14273b4390fSRalf Baechle 	rc32434_pci->pcidasm = 0x0000007F;	/* Mask all the interrupts */
14373b4390fSRalf Baechle 	/* Mask PCI Messaging Interrupts */
14473b4390fSRalf Baechle 	rc32434_pci_msg->pciiic = 0;
14573b4390fSRalf Baechle 	rc32434_pci_msg->pciiim = 0xFFFFFFFF;
14673b4390fSRalf Baechle 	rc32434_pci_msg->pciioic = 0;
14773b4390fSRalf Baechle 	rc32434_pci_msg->pciioim = 0;
14873b4390fSRalf Baechle 
14973b4390fSRalf Baechle 
15073b4390fSRalf Baechle 	/* Setup PCILB0 as Memory Window */
15173b4390fSRalf Baechle 	rc32434_pci->pcilba[0].address = (unsigned int) (PCI_ADDR_START);
15273b4390fSRalf Baechle 
15373b4390fSRalf Baechle 	/* setup the PCI map address as same as the local address */
15473b4390fSRalf Baechle 
15573b4390fSRalf Baechle 	rc32434_pci->pcilba[0].mapping = (unsigned int) (PCI_ADDR_START);
15673b4390fSRalf Baechle 
15773b4390fSRalf Baechle 
15873b4390fSRalf Baechle 	/* Setup PCILBA1 as MEM */
15973b4390fSRalf Baechle 	rc32434_pci->pcilba[0].control =
16073b4390fSRalf Baechle 	    (((SIZE_256MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
16173b4390fSRalf Baechle 	dummyread = rc32434_pci->pcilba[0].control;	/* flush the CPU write Buffers */
16273b4390fSRalf Baechle 	rc32434_pci->pcilba[1].address = 0x60000000;
16373b4390fSRalf Baechle 	rc32434_pci->pcilba[1].mapping = 0x60000000;
16473b4390fSRalf Baechle 
16573b4390fSRalf Baechle 	/* setup PCILBA2 as IO Window */
16673b4390fSRalf Baechle 	rc32434_pci->pcilba[1].control =
16773b4390fSRalf Baechle 	    (((SIZE_256MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
16873b4390fSRalf Baechle 	dummyread = rc32434_pci->pcilba[1].control;	/* flush the CPU write Buffers */
16973b4390fSRalf Baechle 	rc32434_pci->pcilba[2].address = 0x18C00000;
17073b4390fSRalf Baechle 	rc32434_pci->pcilba[2].mapping = 0x18FFFFFF;
17173b4390fSRalf Baechle 
17273b4390fSRalf Baechle 	/* setup PCILBA2 as IO Window */
17373b4390fSRalf Baechle 	rc32434_pci->pcilba[2].control =
17473b4390fSRalf Baechle 	    (((SIZE_4MB & 0x1f) << PCI_LBAC_SIZE_BIT) | PCI_ENDIAN_FLAG);
17573b4390fSRalf Baechle 	dummyread = rc32434_pci->pcilba[2].control;	/* flush the CPU write Buffers */
17673b4390fSRalf Baechle 
17773b4390fSRalf Baechle 	/* Setup PCILBA3 as IO Window */
17873b4390fSRalf Baechle 	rc32434_pci->pcilba[3].address = 0x18800000;
17973b4390fSRalf Baechle 	rc32434_pci->pcilba[3].mapping = 0x18800000;
18073b4390fSRalf Baechle 	rc32434_pci->pcilba[3].control =
18173b4390fSRalf Baechle 	    ((((SIZE_1MB & 0x1ff) << PCI_LBAC_SIZE_BIT) | PCI_LBAC_MSI) |
18273b4390fSRalf Baechle 	     PCI_ENDIAN_FLAG);
18373b4390fSRalf Baechle 	dummyread = rc32434_pci->pcilba[3].control;	/* flush the CPU write Buffers */
18473b4390fSRalf Baechle 
18573b4390fSRalf Baechle 	pci_config_addr = (unsigned int) (0x80000004);
18673b4390fSRalf Baechle 	for (loopCount = 0; loopCount < 24; loopCount++) {
18773b4390fSRalf Baechle 		rc32434_pci->pcicfga = pci_config_addr;
18873b4390fSRalf Baechle 		dummyread = rc32434_pci->pcicfga;
18973b4390fSRalf Baechle 		rc32434_pci->pcicfgd = korina_cnfg_regs[loopCount];
19073b4390fSRalf Baechle 		dummyread = rc32434_pci->pcicfgd;
19173b4390fSRalf Baechle 		pci_config_addr += 4;
19273b4390fSRalf Baechle 	}
19373b4390fSRalf Baechle 	rc32434_pci->pcitc =
19473b4390fSRalf Baechle 	    (unsigned int) ((PCITC_RTIMER_VAL & 0xff) << PCI_TC_RTIMER_BIT) |
19573b4390fSRalf Baechle 	    ((PCITC_DTIMER_VAL & 0xff) << PCI_TC_DTIMER_BIT);
19673b4390fSRalf Baechle 
19773b4390fSRalf Baechle 	pcicntlval = rc32434_pci->pcic;
19873b4390fSRalf Baechle 	pcicntlval &= ~PCI_CTL_TNR;
19973b4390fSRalf Baechle 	rc32434_pci->pcic = pcicntlval;
20073b4390fSRalf Baechle 	pcicntlval = rc32434_pci->pcic;
20173b4390fSRalf Baechle 
20273b4390fSRalf Baechle 	return 0;
20373b4390fSRalf Baechle }
20473b4390fSRalf Baechle 
rc32434_pci_init(void)20573b4390fSRalf Baechle static int __init rc32434_pci_init(void)
20673b4390fSRalf Baechle {
207fb91e2cbSPhil Sutter 	void __iomem *io_map_base;
208fb91e2cbSPhil Sutter 
20973b4390fSRalf Baechle 	pr_info("PCI: Initializing PCI\n");
21073b4390fSRalf Baechle 
21173b4390fSRalf Baechle 	ioport_resource.start = rc32434_res_pci_io1.start;
21273b4390fSRalf Baechle 	ioport_resource.end = rc32434_res_pci_io1.end;
21373b4390fSRalf Baechle 
21473b4390fSRalf Baechle 	rc32434_pcibridge_init();
21573b4390fSRalf Baechle 
216fb91e2cbSPhil Sutter 	io_map_base = ioremap(rc32434_res_pci_io1.start,
217*20ef5d3aSYoichi Yuasa 			      resource_size(&rc32434_res_pci_io1));
218fb91e2cbSPhil Sutter 
219fb91e2cbSPhil Sutter 	if (!io_map_base)
220fb91e2cbSPhil Sutter 		return -ENOMEM;
221fb91e2cbSPhil Sutter 
222fb91e2cbSPhil Sutter 	rc32434_controller.io_map_base =
223fb91e2cbSPhil Sutter 		(unsigned long)io_map_base - rc32434_res_pci_io1.start;
224fb91e2cbSPhil Sutter 
22573b4390fSRalf Baechle 	register_pci_controller(&rc32434_controller);
22673b4390fSRalf Baechle 	rc32434_sync();
22773b4390fSRalf Baechle 
22873b4390fSRalf Baechle 	return 0;
22973b4390fSRalf Baechle }
23073b4390fSRalf Baechle 
23173b4390fSRalf Baechle arch_initcall(rc32434_pci_init);
232