Path: blob/master/arch/mips/nxp/pnx8550/common/pci.c
10820 views
/*1*2* BRIEF MODULE DESCRIPTION3*4* Author: [email protected]5*6* This program is free software; you can distribute it and/or modify it7* under the terms of the GNU General Public License (Version 2) as8* published by the Free Software Foundation.9*10* This program is distributed in the hope it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* for more details.14*15* You should have received a copy of the GNU General Public License along16* with this program; if not, write to the Free Software Foundation, Inc.,17* 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.18*/19#include <linux/types.h>20#include <linux/pci.h>21#include <linux/kernel.h>22#include <linux/init.h>2324#include <pci.h>25#include <glb.h>26#include <nand.h>2728static struct resource pci_io_resource = {29.start = PNX8550_PCIIO + 0x1000, /* reserve regacy I/O space */30.end = PNX8550_PCIIO + PNX8550_PCIIO_SIZE,31.name = "pci IO space",32.flags = IORESOURCE_IO33};3435static struct resource pci_mem_resource = {36.start = PNX8550_PCIMEM,37.end = PNX8550_PCIMEM + PNX8550_PCIMEM_SIZE - 1,38.name = "pci memory space",39.flags = IORESOURCE_MEM40};4142extern struct pci_ops pnx8550_pci_ops;4344static struct pci_controller pnx8550_controller = {45.pci_ops = &pnx8550_pci_ops,46.io_map_base = PNX8550_PORT_BASE,47.io_resource = &pci_io_resource,48.mem_resource = &pci_mem_resource,49};5051/* Return the total size of DRAM-memory, (RANK0 + RANK1) */52static inline unsigned long get_system_mem_size(void)53{54/* Read IP2031_RANK0_ADDR_LO */55unsigned long dram_r0_lo = inl(PCI_BASE | 0x65010);56/* Read IP2031_RANK1_ADDR_HI */57unsigned long dram_r1_hi = inl(PCI_BASE | 0x65018);5859return dram_r1_hi - dram_r0_lo + 1;60}6162static int __init pnx8550_pci_setup(void)63{64int pci_mem_code;65int mem_size = get_system_mem_size() >> 20;6667/* Clear the Global 2 Register, PCI Inta Output Enable Registers68Bit 1:Enable DAC Powerdown69-> 0:DACs are enabled and are working normally701:DACs are powerdown71Bit 0:Enable of PCI inta output72-> 0 = Disable PCI inta output731 = Enable PCI inta output74*/75PNX8550_GLB2_ENAB_INTA_O = 0;7677/* Calc the PCI mem size code */78if (mem_size >= 128)79pci_mem_code = SIZE_128M;80else if (mem_size >= 64)81pci_mem_code = SIZE_64M;82else if (mem_size >= 32)83pci_mem_code = SIZE_32M;84else85pci_mem_code = SIZE_16M;8687/* Set PCI_XIO registers */88outl(pci_mem_resource.start, PCI_BASE | PCI_BASE1_LO);89outl(pci_mem_resource.end + 1, PCI_BASE | PCI_BASE1_HI);90outl(pci_io_resource.start, PCI_BASE | PCI_BASE2_LO);91outl(pci_io_resource.end, PCI_BASE | PCI_BASE2_HI);9293/* Send memory transaction via PCI_BASE2 */94outl(0x00000001, PCI_BASE | PCI_IO);9596/* Unlock the setup register */97outl(0xca, PCI_BASE | PCI_UNLOCKREG);9899/*100* BAR0 of PNX8550 (pci base 10) must be zero in order for ide101* to work, and in order for bus_to_baddr to work without any102* hacks.103*/104outl(0x00000000, PCI_BASE | PCI_BASE10);105106/*107*These two bars are set by default or the boot code.108* However, it's safer to set them here so we're not boot109* code dependent.110*/111outl(0x1be00000, PCI_BASE | PCI_BASE14); /* PNX MMIO */112outl(PNX8550_NAND_BASE_ADDR, PCI_BASE | PCI_BASE18); /* XIO */113114outl(PCI_EN_TA |115PCI_EN_PCI2MMI |116PCI_EN_XIO |117PCI_SETUP_BASE18_SIZE(SIZE_32M) |118PCI_SETUP_BASE18_EN |119PCI_SETUP_BASE14_EN |120PCI_SETUP_BASE10_PREF |121PCI_SETUP_BASE10_SIZE(pci_mem_code) |122PCI_SETUP_CFGMANAGE_EN |123PCI_SETUP_PCIARB_EN,124PCI_BASE |125PCI_SETUP); /* PCI_SETUP */126outl(0x00000000, PCI_BASE | PCI_CTRL); /* PCI_CONTROL */127128register_pci_controller(&pnx8550_controller);129130return 0;131}132133arch_initcall(pnx8550_pci_setup);134135136