1 /*
2  * Copyright 2001 MontaVista Software Inc.
3  * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4  *
5  * arch/mips/gt64120/momenco_ocelot/pci.c
6  *     Board-specific PCI routines for gt64120 controller.
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13 #include <linux/types.h>
14 #include <linux/pci.h>
15 #include <linux/kernel.h>
16 #include <linux/version.h>
17 #include <linux/init.h>
18 #include <asm/pci.h>
19 
pci_range_ck(unsigned char bus,unsigned char dev)20 static __inline__ int pci_range_ck(unsigned char bus, unsigned char dev)
21 {
22 	/*
23 	 * We don't even pretend to handle other busses than bus 0 correctly.
24 	 * Accessing device 31 crashes the CP7000 for some reason.
25 	 */
26 	if ((bus == 0) && (dev != 31))
27 		return 0;
28 
29 	return -1;
30 }
31 
32 
gt64120_board_pcibios_fixup_bus(struct pci_bus * bus)33 void __init gt64120_board_pcibios_fixup_bus(struct pci_bus *bus)
34 {
35 	struct pci_bus *current_bus = bus;
36 	struct pci_dev *devices;
37 	struct list_head *devices_link;
38 	u16 cmd;
39 
40 	list_for_each(devices_link, &(current_bus->devices)) {
41 
42 		devices = pci_dev_b(devices_link);
43 		if (devices == NULL)
44 			continue;
45 
46 		if (PCI_SLOT(devices->devfn) == 1) {
47 			/*
48 			 * Slot 1 is primary ether port, i82559
49 			 * we double-check against that assumption
50 			 */
51 			if ((devices->vendor != 0x8086) ||
52 			    (devices->device != 0x1209) ) {
53 				panic("gt64120_board_pcibios_fixup_bus: found "
54 				      "unexpected PCI device in slot 1.");
55 			}
56 			devices->irq = 2;       /* irq_nr is 2 for INT0 */
57 		} else if (PCI_SLOT(devices->devfn) == 2) {
58 			/*
59 			 * Slot 2 is secondary ether port, i21143
60 			 * we double-check against that assumption
61 			 */
62 			if ((devices->vendor != 0x1011) ||
63 			    (devices->device != 0x19) ) {
64 				panic("gt64120_board_pcibios_fixup_bus: "
65 				      "found unexpected PCI device in slot 2.");
66 			}
67 			devices->irq = 3;       /* irq_nr is 3 for INT1 */
68 		} else if (PCI_SLOT(devices->devfn) == 4) {
69 			/* PMC Slot 1 */
70 			devices->irq = 8;       /* irq_nr is 8 for INT6 */
71 		} else if (PCI_SLOT(devices->devfn) == 5) {
72 			/* PMC Slot 1 */
73 			devices->irq = 9;       /* irq_nr is 9 for INT7 */
74 		} else {
75 			/* We don't have assign interrupts for other devices. */
76 			devices->irq = 0xff;
77 		}
78 
79 		/* Assign an interrupt number for the device */
80 		bus->ops->write_byte(devices, PCI_INTERRUPT_LINE, devices->irq);
81 
82 		/* enable master */
83 		bus->ops->read_word(devices, PCI_COMMAND, &cmd);
84 		cmd |= PCI_COMMAND_MASTER;
85 		bus->ops->write_word(devices, PCI_COMMAND, cmd);
86 	}
87 }
88