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 25d0e3db40SMagnus Damm int __init sh7780_pci_init(struct pci_channel *chan) 265283ecb5SPaul Mundt { 27959f85f8SPaul Mundt unsigned int id; 284e7b7fdbSPaul Mundt const char *type = NULL; 294e7b7fdbSPaul Mundt int ret; 305283ecb5SPaul Mundt 314e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Starting intialization.\n"); 325283ecb5SPaul Mundt 33e4c6a360SMagnus Damm chan->reg_base = 0xfe040000; 34ef53fdebSMagnus Damm chan->io_base = 0xfe200000; 35e4c6a360SMagnus Damm 364e7b7fdbSPaul Mundt /* Enable CPU access to the PCIC registers. */ 374e7b7fdbSPaul Mundt __raw_writel(PCIECR_ENBL, PCIECR); 38959f85f8SPaul Mundt 394e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIVID); 404e7b7fdbSPaul Mundt if (id != SH7780_VENDOR_ID) { 414e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); 42959f85f8SPaul Mundt return -ENODEV; 43959f85f8SPaul Mundt } 44959f85f8SPaul Mundt 454e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIDID); 464e7b7fdbSPaul Mundt type = (id == SH7763_DEVICE_ID) ? "SH7763" : 474e7b7fdbSPaul Mundt (id == SH7780_DEVICE_ID) ? "SH7780" : 484e7b7fdbSPaul Mundt (id == SH7781_DEVICE_ID) ? "SH7781" : 494e7b7fdbSPaul Mundt (id == SH7785_DEVICE_ID) ? "SH7785" : 504e7b7fdbSPaul Mundt NULL; 514e7b7fdbSPaul Mundt if (unlikely(!type)) { 524e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Found an unsupported Renesas host " 534e7b7fdbSPaul Mundt "controller, device id 0x%04x.\n", id); 544e7b7fdbSPaul Mundt return -EINVAL; 554e7b7fdbSPaul Mundt } 564e7b7fdbSPaul Mundt 574e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Found a Renesas %s host " 584e7b7fdbSPaul Mundt "controller, revision %d.\n", type, 594e7b7fdbSPaul Mundt __raw_readb(chan->reg_base + SH7780_PCIRID)); 604e7b7fdbSPaul Mundt 61d0e3db40SMagnus Damm if ((ret = sh4_pci_check_direct(chan)) != 0) 625283ecb5SPaul Mundt return ret; 635283ecb5SPaul Mundt 64*c66c1d79SPaul Mundt /* 65*c66c1d79SPaul Mundt * Platform specific initialization (BSC registers, and memory space 66*c66c1d79SPaul Mundt * mapping) will be called via the platform defined function 67*c66c1d79SPaul Mundt * pcibios_init_platform(). 68*c66c1d79SPaul Mundt */ 695283ecb5SPaul Mundt return pcibios_init_platform(); 705283ecb5SPaul Mundt } 715283ecb5SPaul Mundt 72*c66c1d79SPaul Mundt extern u8 pci_cache_line_size; 73*c66c1d79SPaul Mundt 74b8b47bfbSMagnus Damm int __init sh7780_pcic_init(struct pci_channel *chan, 75b8b47bfbSMagnus Damm struct sh4_pci_address_map *map) 765283ecb5SPaul Mundt { 775283ecb5SPaul Mundt u32 word; 785283ecb5SPaul Mundt 79*c66c1d79SPaul Mundt /* 80*c66c1d79SPaul Mundt * Set the class and sub-class codes. 81*c66c1d79SPaul Mundt */ 82ab78cbcfSPaul Mundt __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8, 83ab78cbcfSPaul Mundt chan->reg_base + SH7780_PCIBCC); 84ab78cbcfSPaul Mundt __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff, 85ab78cbcfSPaul Mundt chan->reg_base + SH7780_PCISUB); 860bbc9bc3SPaul Mundt 87*c66c1d79SPaul Mundt pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4; 88*c66c1d79SPaul Mundt 895283ecb5SPaul Mundt /* set the command/status bits to: 905283ecb5SPaul Mundt * Wait Cycle Control + Parity Enable + Bus Master + 915283ecb5SPaul Mundt * Mem space enable 925283ecb5SPaul Mundt */ 93b8b47bfbSMagnus Damm pci_write_reg(chan, 0x00000046, SH7780_PCICMD); 945283ecb5SPaul Mundt 955283ecb5SPaul Mundt /* Set IO and Mem windows to local address 965283ecb5SPaul Mundt * Make PCI and local address the same for easy 1 to 1 mapping 975283ecb5SPaul Mundt */ 98b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.size - 0xfffff, SH4_PCILSR0); 99b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.size - 0xfffff, SH4_PCILSR1); 1005283ecb5SPaul Mundt /* Set the values on window 0 PCI config registers */ 101b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.base, SH4_PCILAR0); 102b8b47bfbSMagnus Damm pci_write_reg(chan, map->window0.base, SH7780_PCIMBAR0); 1035283ecb5SPaul Mundt /* Set the values on window 1 PCI config registers */ 104b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.base, SH4_PCILAR1); 105b8b47bfbSMagnus Damm pci_write_reg(chan, map->window1.base, SH7780_PCIMBAR1); 1065283ecb5SPaul Mundt 107b7576230SNobuhiro Iwamatsu /* Apply any last-minute PCIC fixups */ 108b8b47bfbSMagnus Damm pci_fixup_pcic(chan); 1095283ecb5SPaul Mundt 1105283ecb5SPaul Mundt /* SH7780 init done, set central function init complete */ 1115283ecb5SPaul Mundt /* use round robin mode to stop a device starving/overruning */ 112959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 113b8b47bfbSMagnus Damm pci_write_reg(chan, word, SH4_PCICR); 1145283ecb5SPaul Mundt 115d0e3db40SMagnus Damm return 0; 1165283ecb5SPaul Mundt } 117