xref: /openbmc/linux/arch/sh/drivers/pci/pci-sh7780.c (revision e4c6a3604e07185046e2ce4be82a201f4447d788)
15283ecb5SPaul Mundt /*
25283ecb5SPaul Mundt  *	Low-Level PCI Support for the SH7780
35283ecb5SPaul Mundt  *
45283ecb5SPaul Mundt  *  Dustin McIntire (dustin@sensoria.com)
55283ecb5SPaul Mundt  *	Derived from arch/i386/kernel/pci-*.c which bore the message:
65283ecb5SPaul Mundt  *	(c) 1999--2000 Martin Mares <mj@ucw.cz>
75283ecb5SPaul Mundt  *
85283ecb5SPaul Mundt  *  Ported to the new API by Paul Mundt <lethal@linux-sh.org>
95283ecb5SPaul Mundt  *  With cleanup by Paul van Gool <pvangool@mimotech.com>
105283ecb5SPaul Mundt  *
115283ecb5SPaul Mundt  *  May be copied or modified under the terms of the GNU General Public
125283ecb5SPaul Mundt  *  License.  See linux/COPYING for more information.
135283ecb5SPaul Mundt  *
145283ecb5SPaul Mundt  */
155283ecb5SPaul Mundt #undef DEBUG
165283ecb5SPaul Mundt 
175283ecb5SPaul Mundt #include <linux/types.h>
185283ecb5SPaul Mundt #include <linux/kernel.h>
195283ecb5SPaul Mundt #include <linux/init.h>
205283ecb5SPaul Mundt #include <linux/pci.h>
215283ecb5SPaul Mundt #include <linux/errno.h>
225283ecb5SPaul Mundt #include <linux/delay.h>
23959f85f8SPaul Mundt #include "pci-sh4.h"
245283ecb5SPaul Mundt 
259a7ef6d5SPaul Mundt #define INTC_BASE	0xffd00000
269a7ef6d5SPaul Mundt #define INTC_ICR0	(INTC_BASE+0x0)
279a7ef6d5SPaul Mundt #define INTC_ICR1	(INTC_BASE+0x1c)
289a7ef6d5SPaul Mundt #define INTC_INTPRI	(INTC_BASE+0x10)
299a7ef6d5SPaul Mundt #define INTC_INTREQ	(INTC_BASE+0x24)
309a7ef6d5SPaul Mundt #define INTC_INTMSK0	(INTC_BASE+0x44)
319a7ef6d5SPaul Mundt #define INTC_INTMSK1	(INTC_BASE+0x48)
329a7ef6d5SPaul Mundt #define INTC_INTMSK2	(INTC_BASE+0x40080)
339a7ef6d5SPaul Mundt #define INTC_INTMSKCLR0	(INTC_BASE+0x64)
349a7ef6d5SPaul Mundt #define INTC_INTMSKCLR1	(INTC_BASE+0x68)
359a7ef6d5SPaul Mundt #define INTC_INTMSKCLR2	(INTC_BASE+0x40084)
369a7ef6d5SPaul Mundt #define INTC_INT2MSKR	(INTC_BASE+0x40038)
379a7ef6d5SPaul Mundt #define INTC_INT2MSKCR	(INTC_BASE+0x4003c)
389a7ef6d5SPaul Mundt 
395283ecb5SPaul Mundt /*
405283ecb5SPaul Mundt  * Initialization. Try all known PCI access methods. Note that we support
415283ecb5SPaul Mundt  * using both PCI BIOS and direct access: in such cases, we use I/O ports
425283ecb5SPaul Mundt  * to access config space.
435283ecb5SPaul Mundt  *
445283ecb5SPaul Mundt  * Note that the platform specific initialization (BSC registers, and memory
45959f85f8SPaul Mundt  * space mapping) will be called via the platform defined function
46959f85f8SPaul Mundt  * pcibios_init_platform().
475283ecb5SPaul Mundt  */
48d0e3db40SMagnus Damm int __init sh7780_pci_init(struct pci_channel *chan)
495283ecb5SPaul Mundt {
50959f85f8SPaul Mundt 	unsigned int id;
5132351a28SPaul Mundt 	int ret, match = 0;
525283ecb5SPaul Mundt 
535283ecb5SPaul Mundt 	pr_debug("PCI: Starting intialization.\n");
545283ecb5SPaul Mundt 
55*e4c6a360SMagnus Damm 	chan->reg_base = 0xfe040000;
56*e4c6a360SMagnus Damm 
57e036eaa6SMagnus Damm 	ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
58959f85f8SPaul Mundt 
59959f85f8SPaul Mundt 	/* check for SH7780/SH7780R hardware */
60d0e3db40SMagnus Damm 	id = pci_read_reg(chan, SH7780_PCIVID);
6132351a28SPaul Mundt 	if ((id & 0xffff) == SH7780_VENDOR_ID) {
6232351a28SPaul Mundt 		switch ((id >> 16) & 0xffff) {
637d740a06SYoshihiro Shimoda 		case SH7763_DEVICE_ID:
6432351a28SPaul Mundt 		case SH7780_DEVICE_ID:
6532351a28SPaul Mundt 		case SH7781_DEVICE_ID:
6632351a28SPaul Mundt 		case SH7785_DEVICE_ID:
6732351a28SPaul Mundt 			match = 1;
6832351a28SPaul Mundt 			break;
6932351a28SPaul Mundt 		}
7032351a28SPaul Mundt 	}
7132351a28SPaul Mundt 
7232351a28SPaul Mundt 	if (unlikely(!match)) {
73959f85f8SPaul Mundt 		printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id);
74959f85f8SPaul Mundt 		return -ENODEV;
75959f85f8SPaul Mundt 	}
76959f85f8SPaul Mundt 
775283ecb5SPaul Mundt 	/* Setup the INTC */
78b7576230SNobuhiro Iwamatsu 	if (mach_is_7780se()) {
79b7576230SNobuhiro Iwamatsu 		/* ICR0: IRL=use separately */
80b7576230SNobuhiro Iwamatsu 		ctrl_outl(0x00C00020, INTC_ICR0);
81b7576230SNobuhiro Iwamatsu 		/* ICR1: detect low level(for 2ndcut) */
82b7576230SNobuhiro Iwamatsu 		ctrl_outl(0xAAAA0000, INTC_ICR1);
83b7576230SNobuhiro Iwamatsu 		/* INTPRI: priority=3(all) */
84b7576230SNobuhiro Iwamatsu 		ctrl_outl(0x33333333, INTC_INTPRI);
85b7576230SNobuhiro Iwamatsu 	}
865283ecb5SPaul Mundt 
87d0e3db40SMagnus Damm 	if ((ret = sh4_pci_check_direct(chan)) != 0)
885283ecb5SPaul Mundt 		return ret;
895283ecb5SPaul Mundt 
905283ecb5SPaul Mundt 	return pcibios_init_platform();
915283ecb5SPaul Mundt }
925283ecb5SPaul Mundt 
93b8b47bfbSMagnus Damm int __init sh7780_pcic_init(struct pci_channel *chan,
94b8b47bfbSMagnus Damm 			    struct sh4_pci_address_map *map)
955283ecb5SPaul Mundt {
965283ecb5SPaul Mundt 	u32 word;
975283ecb5SPaul Mundt 
985283ecb5SPaul Mundt 	/*
995283ecb5SPaul Mundt 	 * This code is unused for some boards as it is done in the
1005283ecb5SPaul Mundt 	 * bootloader and doing it here means the MAC addresses loaded
1015283ecb5SPaul Mundt 	 * by the bootloader get lost.
1025283ecb5SPaul Mundt 	 */
103959f85f8SPaul Mundt 	if (!(map->flags & SH4_PCIC_NO_RESET)) {
1045283ecb5SPaul Mundt 		/* toggle PCI reset pin */
105959f85f8SPaul Mundt 		word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
106b8b47bfbSMagnus Damm 		pci_write_reg(chan, word, SH4_PCICR);
1075283ecb5SPaul Mundt 		/* Wait for a long time... not 1 sec. but long enough */
1085283ecb5SPaul Mundt 		mdelay(100);
109959f85f8SPaul Mundt 		word = SH4_PCICR_PREFIX;
110b8b47bfbSMagnus Damm 		pci_write_reg(chan, word, SH4_PCICR);
1115283ecb5SPaul Mundt 	}
1125283ecb5SPaul Mundt 
1135283ecb5SPaul Mundt 	/* set the command/status bits to:
1145283ecb5SPaul Mundt 	 * Wait Cycle Control + Parity Enable + Bus Master +
1155283ecb5SPaul Mundt 	 * Mem space enable
1165283ecb5SPaul Mundt 	 */
117b8b47bfbSMagnus Damm 	pci_write_reg(chan, 0x00000046, SH7780_PCICMD);
1185283ecb5SPaul Mundt 
1195283ecb5SPaul Mundt 	/* define this host as the host bridge */
120959f85f8SPaul Mundt 	word = PCI_BASE_CLASS_BRIDGE << 24;
121b8b47bfbSMagnus Damm 	pci_write_reg(chan, word, SH7780_PCIRID);
1225283ecb5SPaul Mundt 
1235283ecb5SPaul Mundt 	/* Set IO and Mem windows to local address
1245283ecb5SPaul Mundt 	 * Make PCI and local address the same for easy 1 to 1 mapping
1255283ecb5SPaul Mundt 	 */
126b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0);
127b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1);
1285283ecb5SPaul Mundt 	/* Set the values on window 0 PCI config registers */
129b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.base, SH4_PCILAR0);
130b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0);
1315283ecb5SPaul Mundt 	/* Set the values on window 1 PCI config registers */
132b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.base, SH4_PCILAR1);
133b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1);
1345283ecb5SPaul Mundt 
135710fa3c8SMagnus Damm 	/* Map IO space into PCI IO window:
136710fa3c8SMagnus Damm 	 * IO addresses will be translated to the PCI IO window base address
1375283ecb5SPaul Mundt 	 */
138959f85f8SPaul Mundt 	pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
139710fa3c8SMagnus Damm 		 chan->io_resource->start, chan->io_resource->end,
140710fa3c8SMagnus Damm 		 SH7780_PCI_IO_BASE + chan->io_resource->start);
1415283ecb5SPaul Mundt 
1425283ecb5SPaul Mundt 	/* NOTE: I'm ignoring the PCI error IRQs for now..
1435283ecb5SPaul Mundt 	 * TODO: add support for the internal error interrupts and
1445283ecb5SPaul Mundt 	 * DMA interrupts...
1455283ecb5SPaul Mundt 	 */
1465283ecb5SPaul Mundt 
147b7576230SNobuhiro Iwamatsu 	/* Apply any last-minute PCIC fixups */
148b8b47bfbSMagnus Damm 	pci_fixup_pcic(chan);
1495283ecb5SPaul Mundt 
1505283ecb5SPaul Mundt 	/* SH7780 init done, set central function init complete */
1515283ecb5SPaul Mundt 	/* use round robin mode to stop a device starving/overruning */
152959f85f8SPaul Mundt 	word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
153b8b47bfbSMagnus Damm 	pci_write_reg(chan, word, SH4_PCICR);
1545283ecb5SPaul Mundt 
155d0e3db40SMagnus Damm 	return 0;
1565283ecb5SPaul Mundt }
157