15283ecb5SPaul Mundt /* 25283ecb5SPaul Mundt * Low-Level PCI Support for the SH7780 35283ecb5SPaul Mundt * 4a45635dfSPaul Mundt * Copyright (C) 2005 - 2010 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> 16*aee4467bSPaul Mundt #include <linux/log2.h> 17959f85f8SPaul Mundt #include "pci-sh4.h" 18a45635dfSPaul Mundt #include <asm/mmu.h> 19a45635dfSPaul Mundt #include <asm/sizes.h> 205283ecb5SPaul Mundt 21e79066a6SPaul Mundt static struct resource sh7785_io_resource = { 22e79066a6SPaul Mundt .name = "SH7785_IO", 23a45635dfSPaul Mundt .start = 0x1000, 24a45635dfSPaul Mundt .end = SH7780_PCI_IO_SIZE - 1, 25e79066a6SPaul Mundt .flags = IORESOURCE_IO 26e79066a6SPaul Mundt }; 27e79066a6SPaul Mundt 28e79066a6SPaul Mundt static struct resource sh7785_mem_resource = { 29e79066a6SPaul Mundt .name = "SH7785_mem", 30e79066a6SPaul Mundt .start = SH7780_PCI_MEMORY_BASE, 31e79066a6SPaul Mundt .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1, 32e79066a6SPaul Mundt .flags = IORESOURCE_MEM 33e79066a6SPaul Mundt }; 34e79066a6SPaul Mundt 35e79066a6SPaul Mundt static struct pci_channel sh7780_pci_controller = { 36e79066a6SPaul Mundt .pci_ops = &sh4_pci_ops, 37e79066a6SPaul Mundt .mem_resource = &sh7785_mem_resource, 3809cfeb13SPaul Mundt .mem_offset = 0x00000000, 39e79066a6SPaul Mundt .io_resource = &sh7785_io_resource, 4009cfeb13SPaul Mundt .io_offset = 0x00000000, 415582b064SPaul Mundt .io_map_base = SH7780_PCI_IO_BASE, 42e79066a6SPaul Mundt }; 43e79066a6SPaul Mundt 44e79066a6SPaul Mundt static int __init sh7780_pci_init(void) 455283ecb5SPaul Mundt { 46e79066a6SPaul Mundt struct pci_channel *chan = &sh7780_pci_controller; 47a45635dfSPaul Mundt phys_addr_t memphys; 48a45635dfSPaul Mundt size_t memsize; 49959f85f8SPaul Mundt unsigned int id; 50a45635dfSPaul Mundt const char *type; 515283ecb5SPaul Mundt 524e7b7fdbSPaul Mundt printk(KERN_NOTICE "PCI: Starting intialization.\n"); 535283ecb5SPaul Mundt 54e4c6a360SMagnus Damm chan->reg_base = 0xfe040000; 55e4c6a360SMagnus Damm 564e7b7fdbSPaul Mundt /* Enable CPU access to the PCIC registers. */ 574e7b7fdbSPaul Mundt __raw_writel(PCIECR_ENBL, PCIECR); 58959f85f8SPaul Mundt 59a45635dfSPaul Mundt /* Reset */ 60a45635dfSPaul Mundt __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_PRST, 61a45635dfSPaul Mundt chan->reg_base + SH4_PCICR); 62a45635dfSPaul Mundt 63*aee4467bSPaul Mundt /* 64*aee4467bSPaul Mundt * Wait for it to come back up. The spec says to allow for up to 65*aee4467bSPaul Mundt * 1 second after toggling the reset pin, but in practice 100ms 66*aee4467bSPaul Mundt * is more than enough. 67*aee4467bSPaul Mundt */ 68a45635dfSPaul Mundt mdelay(100); 69a45635dfSPaul Mundt 70a45635dfSPaul Mundt id = __raw_readw(chan->reg_base + PCI_VENDOR_ID); 71a45635dfSPaul Mundt if (id != PCI_VENDOR_ID_RENESAS) { 724e7b7fdbSPaul Mundt printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id); 73959f85f8SPaul Mundt return -ENODEV; 74959f85f8SPaul Mundt } 75959f85f8SPaul Mundt 76a45635dfSPaul Mundt id = __raw_readw(chan->reg_base + PCI_DEVICE_ID); 77a45635dfSPaul Mundt type = (id == PCI_DEVICE_ID_RENESAS_SH7763) ? "SH7763" : 78a45635dfSPaul Mundt (id == PCI_DEVICE_ID_RENESAS_SH7780) ? "SH7780" : 79a45635dfSPaul Mundt (id == PCI_DEVICE_ID_RENESAS_SH7781) ? "SH7781" : 80a45635dfSPaul Mundt (id == PCI_DEVICE_ID_RENESAS_SH7785) ? "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, 90a45635dfSPaul Mundt __raw_readb(chan->reg_base + PCI_REVISION_ID)); 914e7b7fdbSPaul Mundt 92c66c1d79SPaul Mundt /* 93a45635dfSPaul Mundt * Now throw it in to register initialization mode and 94a45635dfSPaul Mundt * start the real work. 95c66c1d79SPaul Mundt */ 96a45635dfSPaul Mundt __raw_writel(SH4_PCICR_PREFIX, chan->reg_base + SH4_PCICR); 97a45635dfSPaul Mundt 98a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + PCI_BASE_ADDRESS_0); 995283ecb5SPaul Mundt 100*aee4467bSPaul Mundt memphys = __pa(memory_start); 101*aee4467bSPaul Mundt memsize = roundup_pow_of_two(memory_end - memory_start); 102*aee4467bSPaul Mundt 103*aee4467bSPaul Mundt /* 104*aee4467bSPaul Mundt * If there's more than 512MB of memory, we need to roll over to 105*aee4467bSPaul Mundt * LAR1/LSR1. 106*aee4467bSPaul Mundt */ 107*aee4467bSPaul Mundt if (memsize > SZ_512M) { 108*aee4467bSPaul Mundt __raw_writel(memphys + SZ_512M, chan->reg_base + SH4_PCILAR1); 109*aee4467bSPaul Mundt __raw_writel((((memsize - SZ_512M) - SZ_1M) & 0x1ff00000) | 1, 110*aee4467bSPaul Mundt chan->reg_base + SH4_PCILSR1); 111*aee4467bSPaul Mundt memsize = SZ_512M; 112*aee4467bSPaul Mundt } else { 113*aee4467bSPaul Mundt /* 114*aee4467bSPaul Mundt * Otherwise just zero it out and disable it. 115*aee4467bSPaul Mundt */ 116*aee4467bSPaul Mundt __raw_writel(0, chan->reg_base + SH4_PCILAR1); 117*aee4467bSPaul Mundt __raw_writel(0, chan->reg_base + SH4_PCILSR1); 118*aee4467bSPaul Mundt } 119*aee4467bSPaul Mundt 120*aee4467bSPaul Mundt /* 121*aee4467bSPaul Mundt * LAR0/LSR0 covers up to the first 512MB, which is enough to 122*aee4467bSPaul Mundt * cover all of lowmem on most platforms. 123*aee4467bSPaul Mundt */ 124a45635dfSPaul Mundt __raw_writel(memphys, chan->reg_base + SH4_PCILAR0); 125*aee4467bSPaul Mundt __raw_writel(((memsize - SZ_1M) & 0x1ff00000) | 1, 126a45635dfSPaul Mundt chan->reg_base + SH4_PCILSR0); 12762c7ae87SPaul Mundt 128a45635dfSPaul Mundt /* Clear out PCI arbiter IRQs */ 129a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH4_PCIAINT); 13062c7ae87SPaul Mundt 131a45635dfSPaul Mundt /* Unmask all of the arbiter IRQs. */ 132a45635dfSPaul Mundt __raw_writel(SH4_PCIAINT_MBKN | SH4_PCIAINT_TBTO | SH4_PCIAINT_MBTO | \ 133a45635dfSPaul Mundt SH4_PCIAINT_TABT | SH4_PCIAINT_MABT | SH4_PCIAINT_RDPE | \ 134a45635dfSPaul Mundt SH4_PCIAINT_WDPE, chan->reg_base + SH4_PCIAINTM); 13562c7ae87SPaul Mundt 136a45635dfSPaul Mundt /* Clear all error conditions */ 137a45635dfSPaul Mundt __raw_writew(PCI_STATUS_DETECTED_PARITY | \ 138a45635dfSPaul Mundt PCI_STATUS_SIG_SYSTEM_ERROR | \ 139a45635dfSPaul Mundt PCI_STATUS_REC_MASTER_ABORT | \ 140a45635dfSPaul Mundt PCI_STATUS_REC_TARGET_ABORT | \ 141a45635dfSPaul Mundt PCI_STATUS_SIG_TARGET_ABORT | \ 142a45635dfSPaul Mundt PCI_STATUS_PARITY, chan->reg_base + PCI_STATUS); 1435283ecb5SPaul Mundt 144a45635dfSPaul Mundt __raw_writew(PCI_COMMAND_SERR | PCI_COMMAND_WAIT | \ 145a45635dfSPaul Mundt PCI_COMMAND_PARITY | PCI_COMMAND_MASTER | \ 146a45635dfSPaul Mundt PCI_COMMAND_MEMORY, chan->reg_base + PCI_COMMAND); 14762c7ae87SPaul Mundt 148a45635dfSPaul Mundt /* Unmask all of the PCI IRQs */ 149a45635dfSPaul Mundt __raw_writel(SH4_PCIINTM_TTADIM | SH4_PCIINTM_TMTOIM | \ 150a45635dfSPaul Mundt SH4_PCIINTM_MDEIM | SH4_PCIINTM_APEDIM | \ 151a45635dfSPaul Mundt SH4_PCIINTM_SDIM | SH4_PCIINTM_DPEITWM | \ 152a45635dfSPaul Mundt SH4_PCIINTM_PEDITRM | SH4_PCIINTM_TADIMM | \ 153a45635dfSPaul Mundt SH4_PCIINTM_MADIMM | SH4_PCIINTM_MWPDIM | \ 154a45635dfSPaul Mundt SH4_PCIINTM_MRDPEIM, chan->reg_base + SH4_PCIINTM); 15562c7ae87SPaul Mundt 156a45635dfSPaul Mundt /* 157a45635dfSPaul Mundt * Disable the cache snoop controller for non-coherent DMA. 158a45635dfSPaul Mundt */ 159a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCICSCR0); 160a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCICSAR0); 161a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCICSCR1); 162a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCICSAR1); 16362c7ae87SPaul Mundt 164a45635dfSPaul Mundt __raw_writel(0xfd000000, chan->reg_base + SH7780_PCIMBR0); 165a45635dfSPaul Mundt __raw_writel(0x00fc0000, chan->reg_base + SH7780_PCIMBMR0); 166a45635dfSPaul Mundt 167a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCIIOBR); 168a45635dfSPaul Mundt __raw_writel(0, chan->reg_base + SH7780_PCIIOBMR); 169a45635dfSPaul Mundt 170a45635dfSPaul Mundt /* 171a45635dfSPaul Mundt * Initialization mode complete, release the control register and 172a45635dfSPaul Mundt * enable round robin mode to stop device overruns/starvation. 173a45635dfSPaul Mundt */ 174a45635dfSPaul Mundt __raw_writel(SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO, 175a45635dfSPaul Mundt chan->reg_base + SH4_PCICR); 1765283ecb5SPaul Mundt 177e79066a6SPaul Mundt register_pci_controller(chan); 178e79066a6SPaul Mundt 179d0e3db40SMagnus Damm return 0; 1805283ecb5SPaul Mundt } 181e79066a6SPaul Mundt arch_initcall(sh7780_pci_init); 182