Re-enable PCI subsystem :)
[openwrt/svn-archive/archive.git] / target / linux / adm5120-2.6 / files / arch / mips / pci / pci-adm5120.c
1 /*
2 * Copyright (C) ADMtek Incorporated.
3 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
4 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
5 * Copyright (C) 2007 OpenWrt.org
6 */
7
8 #include <linux/autoconf.h>
9 #include <linux/types.h>
10 #include <linux/pci.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13
14 #include <adm5120_info.h>
15 #include <adm5120_defs.h>
16
17 extern struct pci_ops adm5120_pci_ops;
18
19 #define PCI_CMM_IOACC_EN 0x1
20 #define PCI_CMM_MEMACC_EN 0x2
21 #define PCI_CMM_MASTER_EN 0x4
22 #define PCI_CMM_DEF \
23 (PCI_CMM_IOACC_EN | PCI_CMM_MEMACC_EN | PCI_CMM_MASTER_EN)
24
25 #define PCI_DEF_CACHE_LINE_SZ 4
26
27
28 struct resource pci_io_resource = {
29 .name = "ADM5120 PCI I/O",
30 .start = ADM5120_PCIIO_BASE,
31 .end = ADM5120_PCICFG_ADDR-1,
32 .flags = IORESOURCE_IO
33 };
34
35 struct resource pci_mem_resource = {
36 .name = "ADM5120 PCI MEM",
37 .start = ADM5120_PCIMEM_BASE,
38 .end = ADM5120_PCIIO_BASE-1,
39 .flags = IORESOURCE_MEM
40 };
41
42 static struct pci_controller adm5120_controller = {
43 .pci_ops = &adm5120_pci_ops,
44 .io_resource = &pci_io_resource,
45 .mem_resource = &pci_mem_resource,
46 };
47
48 int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
49 {
50 if (slot < 2 || slot > 4)
51 return -1;
52 return slot + 4;
53 }
54
55 static void adm5120_pci_fixup(struct pci_dev *dev)
56 {
57 if (dev->devfn == 0) {
58 pci_write_config_word(dev, PCI_COMMAND, PCI_CMM_DEF);
59 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
60 PCI_DEF_CACHE_LINE_SZ);
61 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
62 pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
63 }
64 }
65
66 DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, adm5120_pci_fixup);
67
68
69 int pcibios_plat_dev_init(struct pci_dev *dev)
70 {
71 return 0;
72 }
73
74 static int __init adm5120_pci_setup(void)
75 {
76 int pci_bios;
77
78 pci_bios = adm5120_has_pci();
79
80 printk("adm5120: system has %sPCI BIOS\n", pci_bios ? "" : "no ");
81 if (pci_bios == 0)
82 return 1;
83
84 /* Avoid ISA compat ranges. */
85 PCIBIOS_MIN_IO = 0x00000000;
86 PCIBIOS_MIN_MEM = 0x00000000;
87
88 /* Set I/O resource limits. */
89 ioport_resource.end = 0x1fffffff;
90 iomem_resource.end = 0xffffffff;
91
92 register_pci_controller(&adm5120_controller);
93 return 0;
94 }
95
96 arch_initcall(adm5120_pci_setup);