15283ecb5SPaul Mundt /* 25283ecb5SPaul Mundt * Low-Level PCI Support for the SH7780 35283ecb5SPaul Mundt * 462c7ae87SPaul Mundt * Copyright (C) 2005 - 2009 Paul Mundt 55283ecb5SPaul Mundt * 662c7ae87SPaul Mundt * This file is subject to the terms and conditions of the GNU General Public 762c7ae87SPaul Mundt * License. See the file "COPYING" in the main directory of this archive 862c7ae87SPaul Mundt * for more details. 95283ecb5SPaul Mundt */ 105283ecb5SPaul Mundt #include <linux/types.h> 115283ecb5SPaul Mundt #include <linux/kernel.h> 125283ecb5SPaul Mundt #include <linux/init.h> 135283ecb5SPaul Mundt #include <linux/pci.h> 145283ecb5SPaul Mundt #include <linux/errno.h> 155283ecb5SPaul Mundt #include <linux/delay.h> 16959f85f8SPaul Mundt #include "pci-sh4.h" 175283ecb5SPaul Mundt 18e79066a6SPaul Mundt extern u8 pci_cache_line_size; 19e79066a6SPaul Mundt 20e79066a6SPaul Mundt static struct resource sh7785_io_resource = { 21e79066a6SPaul Mundt .name = "SH7785_IO", 22e79066a6SPaul Mundt .start = SH7780_PCI_IO_BASE, 23e79066a6SPaul Mundt .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1, 24e79066a6SPaul Mundt .flags = IORESOURCE_IO 25e79066a6SPaul Mundt }; 26e79066a6SPaul Mundt 27e79066a6SPaul Mundt static struct resource sh7785_mem_resource = { 28e79066a6SPaul Mundt .name = "SH7785_mem", 29e79066a6SPaul Mundt .start = SH7780_PCI_MEMORY_BASE, 30e79066a6SPaul Mundt .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1, 31e79066a6SPaul Mundt .flags = IORESOURCE_MEM 32e79066a6SPaul Mundt }; 33e79066a6SPaul Mundt 34e79066a6SPaul Mundt static struct pci_channel sh7780_pci_controller = { 35e79066a6SPaul Mundt .pci_ops = &sh4_pci_ops, 36e79066a6SPaul Mundt .mem_resource = &sh7785_mem_resource, 37*09cfeb13SPaul Mundt .mem_offset = 0x00000000, 38e79066a6SPaul Mundt .io_resource = &sh7785_io_resource, 39*09cfeb13SPaul Mundt .io_offset = 0x00000000, 40e79066a6SPaul Mundt }; 41e79066a6SPaul Mundt 42e79066a6SPaul Mundt static struct sh4_pci_address_map sh7780_pci_map = { 43e79066a6SPaul Mundt .window0 = { 44e79066a6SPaul Mundt #if defined(CONFIG_32BIT) 45e79066a6SPaul Mundt .base = SH7780_32BIT_DDR_BASE_ADDR, 46e79066a6SPaul Mundt .size = 0x40000000, 47e79066a6SPaul Mundt #else 48e79066a6SPaul Mundt .base = SH7780_CS0_BASE_ADDR, 49e79066a6SPaul Mundt .size = 0x20000000, 50e79066a6SPaul Mundt #endif 51e79066a6SPaul Mundt }, 52e79066a6SPaul Mundt }; 53e79066a6SPaul Mundt 54e79066a6SPaul Mundt static int __init sh7780_pci_init(void) 555283ecb5SPaul Mundt { 56e79066a6SPaul Mundt struct pci_channel *chan = &sh7780_pci_controller; 57959f85f8SPaul Mundt unsigned int id; 584e7b7fdbSPaul Mundt const char *type = NULL; 594e7b7fdbSPaul Mundt int ret; 60e79066a6SPaul Mundt u32 word; 615283ecb5SPaul Mundt 624e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Starting intialization.\n"); 635283ecb5SPaul Mundt 64e4c6a360SMagnus Damm chan->reg_base = 0xfe040000; 65ef53fdebSMagnus Damm chan->io_base = 0xfe200000; 66e4c6a360SMagnus Damm 674e7b7fdbSPaul Mundt /* Enable CPU access to the PCIC registers. */ 684e7b7fdbSPaul Mundt __raw_writel(PCIECR_ENBL, PCIECR); 69959f85f8SPaul Mundt 704e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIVID); 714e7b7fdbSPaul Mundt if (id != SH7780_VENDOR_ID) { 724e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); 73959f85f8SPaul Mundt return -ENODEV; 74959f85f8SPaul Mundt } 75959f85f8SPaul Mundt 764e7b7fdbSPaul Mundt id = __raw_readw(chan->reg_base + SH7780_PCIDID); 774e7b7fdbSPaul Mundt type = (id == SH7763_DEVICE_ID) ? "SH7763" : 784e7b7fdbSPaul Mundt (id == SH7780_DEVICE_ID) ? "SH7780" : 794e7b7fdbSPaul Mundt (id == SH7781_DEVICE_ID) ? "SH7781" : 804e7b7fdbSPaul Mundt (id == SH7785_DEVICE_ID) ? "SH7785" : 814e7b7fdbSPaul Mundt NULL; 824e7b7fdbSPaul Mundt if (unlikely(!type)) { 834e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Found an unsupported Renesas host " 844e7b7fdbSPaul Mundt "controller, device id 0x%04x.\n", id); 854e7b7fdbSPaul Mundt return -EINVAL; 864e7b7fdbSPaul Mundt } 874e7b7fdbSPaul Mundt 884e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Found a Renesas %s host " 894e7b7fdbSPaul Mundt "controller, revision %d.\n", type, 904e7b7fdbSPaul Mundt __raw_readb(chan->reg_base + SH7780_PCIRID)); 914e7b7fdbSPaul Mundt 92d0e3db40SMagnus Damm if ((ret = sh4_pci_check_direct(chan)) != 0) 935283ecb5SPaul Mundt return ret; 945283ecb5SPaul Mundt 95c66c1d79SPaul Mundt /* 96c66c1d79SPaul Mundt * Set the class and sub-class codes. 97c66c1d79SPaul Mundt */ 98ab78cbcfSPaul Mundt __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8, 99ab78cbcfSPaul Mundt chan->reg_base + SH7780_PCIBCC); 100ab78cbcfSPaul Mundt __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff, 101ab78cbcfSPaul Mundt chan->reg_base + SH7780_PCISUB); 1020bbc9bc3SPaul Mundt 103c66c1d79SPaul Mundt pci_cache_line_size = pci_read_reg(chan, SH7780_PCICLS) / 4; 104c66c1d79SPaul Mundt 10562c7ae87SPaul Mundt /* 10662c7ae87SPaul Mundt * Set IO and Mem windows to local address 1075283ecb5SPaul Mundt * Make PCI and local address the same for easy 1 to 1 mapping 1085283ecb5SPaul Mundt */ 1094c7a47deSPaul Mundt pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0); 1105283ecb5SPaul Mundt /* Set the values on window 0 PCI config registers */ 1114c7a47deSPaul Mundt pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0); 1124c7a47deSPaul Mundt pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0); 1135283ecb5SPaul Mundt 11462c7ae87SPaul Mundt pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM); 11562c7ae87SPaul Mundt 11662c7ae87SPaul Mundt /* Set up standard PCI config registers */ 11762c7ae87SPaul Mundt __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS); 11862c7ae87SPaul Mundt __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD); 11962c7ae87SPaul Mundt __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID); 12062c7ae87SPaul Mundt __raw_writew(0x0001, chan->reg_base + SH7780_PCISID); 12162c7ae87SPaul Mundt 12262c7ae87SPaul Mundt __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF); 12362c7ae87SPaul Mundt 124b7576230SNobuhiro Iwamatsu /* Apply any last-minute PCIC fixups */ 125b8b47bfbSMagnus Damm pci_fixup_pcic(chan); 1265283ecb5SPaul Mundt 12762c7ae87SPaul Mundt pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0); 12862c7ae87SPaul Mundt pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0); 12962c7ae87SPaul Mundt 13062c7ae87SPaul Mundt #ifdef CONFIG_32BIT 13162c7ae87SPaul Mundt pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2); 13262c7ae87SPaul Mundt pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2); 13362c7ae87SPaul Mundt #endif 13462c7ae87SPaul Mundt 13562c7ae87SPaul Mundt /* Set IOBR for windows containing area specified in pci.h */ 13662c7ae87SPaul Mundt pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1), 13762c7ae87SPaul Mundt SH7780_PCIIOBR); 13862c7ae87SPaul Mundt pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)), 13962c7ae87SPaul Mundt SH7780_PCIIOBMR); 14062c7ae87SPaul Mundt 1415283ecb5SPaul Mundt /* SH7780 init done, set central function init complete */ 1425283ecb5SPaul Mundt /* use round robin mode to stop a device starving/overruning */ 143959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 144b8b47bfbSMagnus Damm pci_write_reg(chan, word, SH4_PCICR); 1455283ecb5SPaul Mundt 146f1dcab75SPaul Mundt __set_io_port_base(SH7780_PCI_IO_BASE); 147f1dcab75SPaul Mundt 148e79066a6SPaul Mundt register_pci_controller(chan); 149e79066a6SPaul Mundt 150d0e3db40SMagnus Damm return 0; 1515283ecb5SPaul Mundt } 152e79066a6SPaul Mundt arch_initcall(sh7780_pci_init); 153