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 165283ecb5SPaul Mundt #undef DEBUG 175283ecb5SPaul Mundt 185283ecb5SPaul Mundt #include <linux/config.h> 195283ecb5SPaul Mundt #include <linux/types.h> 205283ecb5SPaul Mundt #include <linux/kernel.h> 215283ecb5SPaul Mundt #include <linux/init.h> 225283ecb5SPaul Mundt #include <linux/pci.h> 235283ecb5SPaul Mundt #include <linux/errno.h> 245283ecb5SPaul Mundt #include <linux/delay.h> 25*959f85f8SPaul Mundt #include "pci-sh4.h" 265283ecb5SPaul Mundt 275283ecb5SPaul Mundt /* 285283ecb5SPaul Mundt * Initialization. Try all known PCI access methods. Note that we support 295283ecb5SPaul Mundt * using both PCI BIOS and direct access: in such cases, we use I/O ports 305283ecb5SPaul Mundt * to access config space. 315283ecb5SPaul Mundt * 325283ecb5SPaul Mundt * Note that the platform specific initialization (BSC registers, and memory 33*959f85f8SPaul Mundt * space mapping) will be called via the platform defined function 34*959f85f8SPaul Mundt * pcibios_init_platform(). 355283ecb5SPaul Mundt */ 365283ecb5SPaul Mundt static int __init sh7780_pci_init(void) 375283ecb5SPaul Mundt { 38*959f85f8SPaul Mundt unsigned int id; 395283ecb5SPaul Mundt int ret; 405283ecb5SPaul Mundt 415283ecb5SPaul Mundt pr_debug("PCI: Starting intialization.\n"); 425283ecb5SPaul Mundt 43*959f85f8SPaul Mundt outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */ 44*959f85f8SPaul Mundt 45*959f85f8SPaul Mundt /* check for SH7780/SH7780R hardware */ 46*959f85f8SPaul Mundt id = pci_read_reg(SH7780_PCIVID); 47*959f85f8SPaul Mundt if ((id != ((SH7780_DEVICE_ID << 16) | SH7780_VENDOR_ID)) && 48*959f85f8SPaul Mundt (id != ((SH7781_DEVICE_ID << 16) | SH7780_VENDOR_ID))) { 49*959f85f8SPaul Mundt printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id); 50*959f85f8SPaul Mundt return -ENODEV; 51*959f85f8SPaul Mundt } 52*959f85f8SPaul Mundt 535283ecb5SPaul Mundt /* Setup the INTC */ 545283ecb5SPaul Mundt ctrl_outl(0x00200000, INTC_ICR0); /* INTC SH-4 Mode */ 555283ecb5SPaul Mundt ctrl_outl(0x00078000, INTC_INT2MSKCR); /* enable PCIINTA - PCIINTD */ 565283ecb5SPaul Mundt ctrl_outl(0x40000000, INTC_INTMSK1); /* disable IRL4-7 Interrupt */ 575283ecb5SPaul Mundt ctrl_outl(0x0000fffe, INTC_INTMSK2); /* disable IRL4-7 Interrupt */ 585283ecb5SPaul Mundt ctrl_outl(0x80000000, INTC_INTMSKCLR1); /* enable IRL0-3 Interrupt */ 595283ecb5SPaul Mundt ctrl_outl(0xfffe0000, INTC_INTMSKCLR2); /* enable IRL0-3 Interrupt */ 605283ecb5SPaul Mundt 61*959f85f8SPaul Mundt if ((ret = sh4_pci_check_direct()) != 0) 625283ecb5SPaul Mundt return ret; 635283ecb5SPaul Mundt 645283ecb5SPaul Mundt return pcibios_init_platform(); 655283ecb5SPaul Mundt } 665283ecb5SPaul Mundt core_initcall(sh7780_pci_init); 675283ecb5SPaul Mundt 68*959f85f8SPaul Mundt int __init sh7780_pcic_init(struct sh4_pci_address_map *map) 695283ecb5SPaul Mundt { 705283ecb5SPaul Mundt u32 word; 715283ecb5SPaul Mundt 725283ecb5SPaul Mundt /* 735283ecb5SPaul Mundt * This code is unused for some boards as it is done in the 745283ecb5SPaul Mundt * bootloader and doing it here means the MAC addresses loaded 755283ecb5SPaul Mundt * by the bootloader get lost. 765283ecb5SPaul Mundt */ 77*959f85f8SPaul Mundt if (!(map->flags & SH4_PCIC_NO_RESET)) { 785283ecb5SPaul Mundt /* toggle PCI reset pin */ 79*959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_PRST; 80*959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 815283ecb5SPaul Mundt /* Wait for a long time... not 1 sec. but long enough */ 825283ecb5SPaul Mundt mdelay(100); 83*959f85f8SPaul Mundt word = SH4_PCICR_PREFIX; 84*959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 855283ecb5SPaul Mundt } 865283ecb5SPaul Mundt 875283ecb5SPaul Mundt /* set the command/status bits to: 885283ecb5SPaul Mundt * Wait Cycle Control + Parity Enable + Bus Master + 895283ecb5SPaul Mundt * Mem space enable 905283ecb5SPaul Mundt */ 91*959f85f8SPaul Mundt pci_write_reg(0x00000046, SH7780_PCICMD); 925283ecb5SPaul Mundt 935283ecb5SPaul Mundt /* define this host as the host bridge */ 94*959f85f8SPaul Mundt word = PCI_BASE_CLASS_BRIDGE << 24; 95*959f85f8SPaul Mundt pci_write_reg(word, SH7780_PCIRID); 965283ecb5SPaul Mundt 975283ecb5SPaul Mundt /* Set IO and Mem windows to local address 985283ecb5SPaul Mundt * Make PCI and local address the same for easy 1 to 1 mapping 995283ecb5SPaul Mundt * Window0 = map->window0.size @ non-cached area base = SDRAM 1005283ecb5SPaul Mundt * Window1 = map->window1.size @ cached area base = SDRAM 1015283ecb5SPaul Mundt */ 1025283ecb5SPaul Mundt word = ((map->window0.size - 1) & 0x1ff00001) | 0x01; 103*959f85f8SPaul Mundt pci_write_reg(0x07f00001, SH4_PCILSR0); 1045283ecb5SPaul Mundt word = ((map->window1.size - 1) & 0x1ff00001) | 0x01; 105*959f85f8SPaul Mundt pci_write_reg(0x00000001, SH4_PCILSR1); 1065283ecb5SPaul Mundt /* Set the values on window 0 PCI config registers */ 1075283ecb5SPaul Mundt word = P2SEGADDR(map->window0.base); 108*959f85f8SPaul Mundt pci_write_reg(0xa8000000, SH4_PCILAR0); 109*959f85f8SPaul Mundt pci_write_reg(0x08000000, SH7780_PCIMBAR0); 1105283ecb5SPaul Mundt /* Set the values on window 1 PCI config registers */ 1115283ecb5SPaul Mundt word = P2SEGADDR(map->window1.base); 112*959f85f8SPaul Mundt pci_write_reg(0x00000000, SH4_PCILAR1); 113*959f85f8SPaul Mundt pci_write_reg(0x00000000, SH7780_PCIMBAR1); 1145283ecb5SPaul Mundt 1155283ecb5SPaul Mundt /* Map IO space into PCI IO window 1165283ecb5SPaul Mundt * The IO window is 64K-PCIBIOS_MIN_IO in size 1175283ecb5SPaul Mundt * IO addresses will be translated to the 1185283ecb5SPaul Mundt * PCI IO window base address 1195283ecb5SPaul Mundt */ 120*959f85f8SPaul Mundt pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n", 121*959f85f8SPaul Mundt PCIBIOS_MIN_IO, (64 << 10), 122*959f85f8SPaul Mundt SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO); 1235283ecb5SPaul Mundt 1245283ecb5SPaul Mundt /* NOTE: I'm ignoring the PCI error IRQs for now.. 1255283ecb5SPaul Mundt * TODO: add support for the internal error interrupts and 1265283ecb5SPaul Mundt * DMA interrupts... 1275283ecb5SPaul Mundt */ 1285283ecb5SPaul Mundt 1295283ecb5SPaul Mundt #ifdef CONFIG_SH_R7780RP 1305283ecb5SPaul Mundt pci_fixup_pcic(); 1315283ecb5SPaul Mundt #endif 1325283ecb5SPaul Mundt 1335283ecb5SPaul Mundt /* SH7780 init done, set central function init complete */ 1345283ecb5SPaul Mundt /* use round robin mode to stop a device starving/overruning */ 135*959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 136*959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 1375283ecb5SPaul Mundt 1385283ecb5SPaul Mundt return 1; 1395283ecb5SPaul Mundt } 140