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 255283ecb5SPaul Mundt /* 265283ecb5SPaul Mundt * Initialization. Try all known PCI access methods. Note that we support 275283ecb5SPaul Mundt * using both PCI BIOS and direct access: in such cases, we use I/O ports 285283ecb5SPaul Mundt * to access config space. 295283ecb5SPaul Mundt * 305283ecb5SPaul Mundt * Note that the platform specific initialization (BSC registers, and memory 31959f85f8SPaul Mundt * space mapping) will be called via the platform defined function 32959f85f8SPaul Mundt * pcibios_init_platform(). 335283ecb5SPaul Mundt */ 34d0e3db40SMagnus Damm int __init sh7780_pci_init(struct pci_channel *chan) 355283ecb5SPaul Mundt { 36959f85f8SPaul Mundt unsigned int id; 37*4e7b7fdbSPaul Mundt const char *type = NULL; 38*4e7b7fdbSPaul Mundt int ret; 395283ecb5SPaul Mundt 40*4e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Starting intialization.\n"); 415283ecb5SPaul Mundt 42e4c6a360SMagnus Damm chan->reg_base = 0xfe040000; 43ef53fdebSMagnus Damm chan->io_base = 0xfe200000; 44e4c6a360SMagnus Damm 45*4e7b7fdbSPaul Mundt /* Enable CPU access to the PCIC registers. */ 46*4e7b7fdbSPaul Mundt __raw_writel(PCIECR_ENBL, PCIECR); 47959f85f8SPaul Mundt 48*4e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIVID); 49*4e7b7fdbSPaul Mundt if (id != SH7780_VENDOR_ID) { 50*4e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); 51959f85f8SPaul Mundt return -ENODEV; 52959f85f8SPaul Mundt } 53959f85f8SPaul Mundt 54*4e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIDID); 55*4e7b7fdbSPaul Mundt type = (id == SH7763_DEVICE_ID) ? "SH7763" : 56*4e7b7fdbSPaul Mundt (id == SH7780_DEVICE_ID) ? "SH7780" : 57*4e7b7fdbSPaul Mundt (id == SH7781_DEVICE_ID) ? "SH7781" : 58*4e7b7fdbSPaul Mundt (id == SH7785_DEVICE_ID) ? "SH7785" : 59*4e7b7fdbSPaul Mundt NULL; 60*4e7b7fdbSPaul Mundt if (unlikely(!type)) { 61*4e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Found an unsupported Renesas host " 62*4e7b7fdbSPaul Mundt "controller, device id 0x%04x.\n", id); 63*4e7b7fdbSPaul Mundt return -EINVAL; 64*4e7b7fdbSPaul Mundt } 65*4e7b7fdbSPaul Mundt 66*4e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Found a Renesas %s host " 67*4e7b7fdbSPaul Mundt "controller, revision %d.\n", type, 68*4e7b7fdbSPaul Mundt __raw_readb(chan->reg_base + SH7780_PCIRID)); 69*4e7b7fdbSPaul Mundt 70d0e3db40SMagnus Damm if ((ret = sh4_pci_check_direct(chan)) != 0) 715283ecb5SPaul Mundt return ret; 725283ecb5SPaul Mundt 735283ecb5SPaul Mundt return pcibios_init_platform(); 745283ecb5SPaul Mundt } 755283ecb5SPaul Mundt 76b8b47bfbSMagnus Damm int __init sh7780_pcic_init(struct pci_channel *chan, 77b8b47bfbSMagnus Damm struct sh4_pci_address_map *map) 785283ecb5SPaul Mundt { 795283ecb5SPaul Mundt u32 word; 805283ecb5SPaul Mundt 810bbc9bc3SPaul Mundt pci_write_reg(chan, PCI_CLASS_BRIDGE_HOST >> 8, SH7780_PCIBCC); 820bbc9bc3SPaul Mundt pci_write_reg(chan, PCI_CLASS_BRIDGE_HOST & 0xff, SH7780_PCISUB); 830bbc9bc3SPaul Mundt 845283ecb5SPaul Mundt /* set the command/status bits to: 855283ecb5SPaul Mundt * Wait Cycle Control + Parity Enable + Bus Master + 865283ecb5SPaul Mundt * Mem space enable 875283ecb5SPaul Mundt */ 88b8b47bfbSMagnus Damm pci_write_reg(chan, 0x00000046, SH7780_PCICMD); 895283ecb5SPaul Mundt 905283ecb5SPaul Mundt /* Set IO and Mem windows to local address 915283ecb5SPaul Mundt * Make PCI and local address the same for easy 1 to 1 mapping 925283ecb5SPaul Mundt */ 93b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0); 94b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1); 955283ecb5SPaul Mundt /* Set the values on window 0 PCI config registers */ 96b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.base, SH4_PCILAR0); 97b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0); 985283ecb5SPaul Mundt /* Set the values on window 1 PCI config registers */ 99b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.base, SH4_PCILAR1); 100b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1); 1015283ecb5SPaul Mundt 102b7576230SNobuhiro Iwamatsu /* Apply any last-minute PCIC fixups */ 103b8b47bfbSMagnus Damm pci_fixup_pcic(chan); 1045283ecb5SPaul Mundt 1055283ecb5SPaul Mundt /* SH7780 init done, set central function init complete */ 1065283ecb5SPaul Mundt /* use round robin mode to stop a device starving/overruning */ 107959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 108b8b47bfbSMagnus Damm pci_write_reg(chan, word, SH4_PCICR); 1095283ecb5SPaul Mundt 110d0e3db40SMagnus Damm return 0; 1115283ecb5SPaul Mundt } 112