xref: /openbmc/linux/arch/sh/drivers/pci/pci-sh7780.c (revision d0e3db40e2a1352aa2a2f425a7d4631bddc03d51)
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  */
48*d0e3db40SMagnus 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 
55e036eaa6SMagnus Damm 	ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
56959f85f8SPaul Mundt 
57959f85f8SPaul Mundt 	/* check for SH7780/SH7780R hardware */
58*d0e3db40SMagnus Damm 	id = pci_read_reg(chan, SH7780_PCIVID);
5932351a28SPaul Mundt 	if ((id & 0xffff) == SH7780_VENDOR_ID) {
6032351a28SPaul Mundt 		switch ((id >> 16) & 0xffff) {
617d740a06SYoshihiro Shimoda 		case SH7763_DEVICE_ID:
6232351a28SPaul Mundt 		case SH7780_DEVICE_ID:
6332351a28SPaul Mundt 		case SH7781_DEVICE_ID:
6432351a28SPaul Mundt 		case SH7785_DEVICE_ID:
6532351a28SPaul Mundt 			match = 1;
6632351a28SPaul Mundt 			break;
6732351a28SPaul Mundt 		}
6832351a28SPaul Mundt 	}
6932351a28SPaul Mundt 
7032351a28SPaul Mundt 	if (unlikely(!match)) {
71959f85f8SPaul Mundt 		printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id);
72959f85f8SPaul Mundt 		return -ENODEV;
73959f85f8SPaul Mundt 	}
74959f85f8SPaul Mundt 
755283ecb5SPaul Mundt 	/* Setup the INTC */
76b7576230SNobuhiro Iwamatsu 	if (mach_is_7780se()) {
77b7576230SNobuhiro Iwamatsu 		/* ICR0: IRL=use separately */
78b7576230SNobuhiro Iwamatsu 		ctrl_outl(0x00C00020, INTC_ICR0);
79b7576230SNobuhiro Iwamatsu 		/* ICR1: detect low level(for 2ndcut) */
80b7576230SNobuhiro Iwamatsu 		ctrl_outl(0xAAAA0000, INTC_ICR1);
81b7576230SNobuhiro Iwamatsu 		/* INTPRI: priority=3(all) */
82b7576230SNobuhiro Iwamatsu 		ctrl_outl(0x33333333, INTC_INTPRI);
83b7576230SNobuhiro Iwamatsu 	}
845283ecb5SPaul Mundt 
85*d0e3db40SMagnus Damm 	if ((ret = sh4_pci_check_direct(chan)) != 0)
865283ecb5SPaul Mundt 		return ret;
875283ecb5SPaul Mundt 
885283ecb5SPaul Mundt 	return pcibios_init_platform();
895283ecb5SPaul Mundt }
905283ecb5SPaul Mundt 
91b8b47bfbSMagnus Damm int __init sh7780_pcic_init(struct pci_channel *chan,
92b8b47bfbSMagnus Damm 			    struct sh4_pci_address_map *map)
935283ecb5SPaul Mundt {
945283ecb5SPaul Mundt 	u32 word;
955283ecb5SPaul Mundt 
965283ecb5SPaul Mundt 	/*
975283ecb5SPaul Mundt 	 * This code is unused for some boards as it is done in the
985283ecb5SPaul Mundt 	 * bootloader and doing it here means the MAC addresses loaded
995283ecb5SPaul Mundt 	 * by the bootloader get lost.
1005283ecb5SPaul Mundt 	 */
101959f85f8SPaul Mundt 	if (!(map->flags & SH4_PCIC_NO_RESET)) {
1025283ecb5SPaul Mundt 		/* toggle PCI reset pin */
103959f85f8SPaul Mundt 		word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
104b8b47bfbSMagnus Damm 		pci_write_reg(chan, word, SH4_PCICR);
1055283ecb5SPaul Mundt 		/* Wait for a long time... not 1 sec. but long enough */
1065283ecb5SPaul Mundt 		mdelay(100);
107959f85f8SPaul Mundt 		word = SH4_PCICR_PREFIX;
108b8b47bfbSMagnus Damm 		pci_write_reg(chan, word, SH4_PCICR);
1095283ecb5SPaul Mundt 	}
1105283ecb5SPaul Mundt 
1115283ecb5SPaul Mundt 	/* set the command/status bits to:
1125283ecb5SPaul Mundt 	 * Wait Cycle Control + Parity Enable + Bus Master +
1135283ecb5SPaul Mundt 	 * Mem space enable
1145283ecb5SPaul Mundt 	 */
115b8b47bfbSMagnus Damm 	pci_write_reg(chan, 0x00000046, SH7780_PCICMD);
1165283ecb5SPaul Mundt 
1175283ecb5SPaul Mundt 	/* define this host as the host bridge */
118959f85f8SPaul Mundt 	word = PCI_BASE_CLASS_BRIDGE << 24;
119b8b47bfbSMagnus Damm 	pci_write_reg(chan, word, SH7780_PCIRID);
1205283ecb5SPaul Mundt 
1215283ecb5SPaul Mundt 	/* Set IO and Mem windows to local address
1225283ecb5SPaul Mundt 	 * Make PCI and local address the same for easy 1 to 1 mapping
1235283ecb5SPaul Mundt 	 */
124b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0);
125b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1);
1265283ecb5SPaul Mundt 	/* Set the values on window 0 PCI config registers */
127b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.base, SH4_PCILAR0);
128b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0);
1295283ecb5SPaul Mundt 	/* Set the values on window 1 PCI config registers */
130b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.base, SH4_PCILAR1);
131b8b47bfbSMagnus Damm 	pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1);
1325283ecb5SPaul Mundt 
1335283ecb5SPaul Mundt 	/* Map IO space into PCI IO window
1345283ecb5SPaul Mundt 	 * The IO window is 64K-PCIBIOS_MIN_IO in size
1355283ecb5SPaul Mundt 	 * IO addresses will be translated to the
1365283ecb5SPaul Mundt 	 * PCI IO window base address
1375283ecb5SPaul Mundt 	 */
138959f85f8SPaul Mundt 	pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
139959f85f8SPaul Mundt 		 PCIBIOS_MIN_IO, (64 << 10),
140959f85f8SPaul Mundt 		 SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO);
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 
155*d0e3db40SMagnus Damm 	return 0;
1565283ecb5SPaul Mundt }
157