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 */ 485283ecb5SPaul Mundt static int __init sh7780_pci_init(void) 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 55959f85f8SPaul Mundt outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */ 56959f85f8SPaul Mundt 57959f85f8SPaul Mundt /* check for SH7780/SH7780R hardware */ 58959f85f8SPaul Mundt id = pci_read_reg(SH7780_PCIVID); 5932351a28SPaul Mundt if ((id & 0xffff) == SH7780_VENDOR_ID) { 6032351a28SPaul Mundt switch ((id >> 16) & 0xffff) { 6132351a28SPaul Mundt case SH7780_DEVICE_ID: 6232351a28SPaul Mundt case SH7781_DEVICE_ID: 6332351a28SPaul Mundt case SH7785_DEVICE_ID: 6432351a28SPaul Mundt match = 1; 6532351a28SPaul Mundt break; 6632351a28SPaul Mundt } 6732351a28SPaul Mundt } 6832351a28SPaul Mundt 6932351a28SPaul Mundt if (unlikely(!match)) { 70959f85f8SPaul Mundt printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id); 71959f85f8SPaul Mundt return -ENODEV; 72959f85f8SPaul Mundt } 73959f85f8SPaul Mundt 745283ecb5SPaul Mundt /* Setup the INTC */ 75*b7576230SNobuhiro Iwamatsu if (mach_is_7780se()) { 76*b7576230SNobuhiro Iwamatsu /* ICR0: IRL=use separately */ 77*b7576230SNobuhiro Iwamatsu ctrl_outl(0x00C00020, INTC_ICR0); 78*b7576230SNobuhiro Iwamatsu /* ICR1: detect low level(for 2ndcut) */ 79*b7576230SNobuhiro Iwamatsu ctrl_outl(0xAAAA0000, INTC_ICR1); 80*b7576230SNobuhiro Iwamatsu /* INTPRI: priority=3(all) */ 81*b7576230SNobuhiro Iwamatsu ctrl_outl(0x33333333, INTC_INTPRI); 82*b7576230SNobuhiro Iwamatsu } else { 83*b7576230SNobuhiro Iwamatsu /* INTC SH-4 Mode */ 84*b7576230SNobuhiro Iwamatsu ctrl_outl(0x00200000, INTC_ICR0); 85*b7576230SNobuhiro Iwamatsu /* enable PCIINTA - PCIINTD */ 86*b7576230SNobuhiro Iwamatsu ctrl_outl(0x00078000, INTC_INT2MSKCR); 87*b7576230SNobuhiro Iwamatsu /* disable IRL4-7 Interrupt */ 88*b7576230SNobuhiro Iwamatsu ctrl_outl(0x40000000, INTC_INTMSK1); 89*b7576230SNobuhiro Iwamatsu /* disable IRL4-7 Interrupt */ 90*b7576230SNobuhiro Iwamatsu ctrl_outl(0x0000fffe, INTC_INTMSK2); 91*b7576230SNobuhiro Iwamatsu /* enable IRL0-3 Interrupt */ 92*b7576230SNobuhiro Iwamatsu ctrl_outl(0x80000000, INTC_INTMSKCLR1); 93*b7576230SNobuhiro Iwamatsu /* enable IRL0-3 Interrupt */ 94*b7576230SNobuhiro Iwamatsu ctrl_outl(0xfffe0000, INTC_INTMSKCLR2); 95*b7576230SNobuhiro Iwamatsu } 965283ecb5SPaul Mundt 97959f85f8SPaul Mundt if ((ret = sh4_pci_check_direct()) != 0) 985283ecb5SPaul Mundt return ret; 995283ecb5SPaul Mundt 1005283ecb5SPaul Mundt return pcibios_init_platform(); 1015283ecb5SPaul Mundt } 1025283ecb5SPaul Mundt core_initcall(sh7780_pci_init); 1035283ecb5SPaul Mundt 104959f85f8SPaul Mundt int __init sh7780_pcic_init(struct sh4_pci_address_map *map) 1055283ecb5SPaul Mundt { 1065283ecb5SPaul Mundt u32 word; 1075283ecb5SPaul Mundt 1085283ecb5SPaul Mundt /* 1095283ecb5SPaul Mundt * This code is unused for some boards as it is done in the 1105283ecb5SPaul Mundt * bootloader and doing it here means the MAC addresses loaded 1115283ecb5SPaul Mundt * by the bootloader get lost. 1125283ecb5SPaul Mundt */ 113959f85f8SPaul Mundt if (!(map->flags & SH4_PCIC_NO_RESET)) { 1145283ecb5SPaul Mundt /* toggle PCI reset pin */ 115959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_PRST; 116959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 1175283ecb5SPaul Mundt /* Wait for a long time... not 1 sec. but long enough */ 1185283ecb5SPaul Mundt mdelay(100); 119959f85f8SPaul Mundt word = SH4_PCICR_PREFIX; 120959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 1215283ecb5SPaul Mundt } 1225283ecb5SPaul Mundt 1235283ecb5SPaul Mundt /* set the command/status bits to: 1245283ecb5SPaul Mundt * Wait Cycle Control + Parity Enable + Bus Master + 1255283ecb5SPaul Mundt * Mem space enable 1265283ecb5SPaul Mundt */ 127959f85f8SPaul Mundt pci_write_reg(0x00000046, SH7780_PCICMD); 1285283ecb5SPaul Mundt 1295283ecb5SPaul Mundt /* define this host as the host bridge */ 130959f85f8SPaul Mundt word = PCI_BASE_CLASS_BRIDGE << 24; 131959f85f8SPaul Mundt pci_write_reg(word, SH7780_PCIRID); 1325283ecb5SPaul Mundt 1335283ecb5SPaul Mundt /* Set IO and Mem windows to local address 1345283ecb5SPaul Mundt * Make PCI and local address the same for easy 1 to 1 mapping 1355283ecb5SPaul Mundt * Window0 = map->window0.size @ non-cached area base = SDRAM 1365283ecb5SPaul Mundt * Window1 = map->window1.size @ cached area base = SDRAM 1375283ecb5SPaul Mundt */ 1385283ecb5SPaul Mundt word = ((map->window0.size - 1) & 0x1ff00001) | 0x01; 139959f85f8SPaul Mundt pci_write_reg(0x07f00001, SH4_PCILSR0); 1405283ecb5SPaul Mundt word = ((map->window1.size - 1) & 0x1ff00001) | 0x01; 141959f85f8SPaul Mundt pci_write_reg(0x00000001, SH4_PCILSR1); 1425283ecb5SPaul Mundt /* Set the values on window 0 PCI config registers */ 1435283ecb5SPaul Mundt word = P2SEGADDR(map->window0.base); 144959f85f8SPaul Mundt pci_write_reg(0xa8000000, SH4_PCILAR0); 145959f85f8SPaul Mundt pci_write_reg(0x08000000, SH7780_PCIMBAR0); 1465283ecb5SPaul Mundt /* Set the values on window 1 PCI config registers */ 1475283ecb5SPaul Mundt word = P2SEGADDR(map->window1.base); 148959f85f8SPaul Mundt pci_write_reg(0x00000000, SH4_PCILAR1); 149959f85f8SPaul Mundt pci_write_reg(0x00000000, SH7780_PCIMBAR1); 1505283ecb5SPaul Mundt 1515283ecb5SPaul Mundt /* Map IO space into PCI IO window 1525283ecb5SPaul Mundt * The IO window is 64K-PCIBIOS_MIN_IO in size 1535283ecb5SPaul Mundt * IO addresses will be translated to the 1545283ecb5SPaul Mundt * PCI IO window base address 1555283ecb5SPaul Mundt */ 156959f85f8SPaul Mundt pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n", 157959f85f8SPaul Mundt PCIBIOS_MIN_IO, (64 << 10), 158959f85f8SPaul Mundt SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO); 1595283ecb5SPaul Mundt 1605283ecb5SPaul Mundt /* NOTE: I'm ignoring the PCI error IRQs for now.. 1615283ecb5SPaul Mundt * TODO: add support for the internal error interrupts and 1625283ecb5SPaul Mundt * DMA interrupts... 1635283ecb5SPaul Mundt */ 1645283ecb5SPaul Mundt 165*b7576230SNobuhiro Iwamatsu /* Apply any last-minute PCIC fixups */ 1665283ecb5SPaul Mundt pci_fixup_pcic(); 1675283ecb5SPaul Mundt 1685283ecb5SPaul Mundt /* SH7780 init done, set central function init complete */ 1695283ecb5SPaul Mundt /* use round robin mode to stop a device starving/overruning */ 170959f85f8SPaul Mundt word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 171959f85f8SPaul Mundt pci_write_reg(word, SH4_PCICR); 1725283ecb5SPaul Mundt 1735283ecb5SPaul Mundt return 1; 1745283ecb5SPaul Mundt } 175