1 /*
2  *
3  * BRIEF MODULE DESCRIPTION
4  *	Board specific pci fixups.
5  *
6  * Copyright 2000 MontaVista Software Inc.
7  * Author: MontaVista Software, Inc.
8  *         	ppopov@mvista.com or source@mvista.com
9  *
10  *  This program is free software; you can redistribute  it and/or modify it
11  *  under  the terms of  the GNU General  Public License as published by the
12  *  Free Software Foundation;  either version 2 of the  License, or (at your
13  *  option) any later version.
14  *
15  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
16  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
17  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
18  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
19  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
21  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
23  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  *  You should have received a copy of the  GNU General Public License along
27  *  with this program; if not, write  to the Free Software Foundation, Inc.,
28  *  675 Mass Ave, Cambridge, MA 02139, USA.
29  */
30 #include <linux/config.h>
31 
32 #ifdef CONFIG_PCI
33 
34 #include <linux/types.h>
35 #include <linux/pci.h>
36 #include <linux/kernel.h>
37 #include <linux/init.h>
38 
39 #include <asm/it8172/it8172.h>
40 #include <asm/it8172/it8172_pci.h>
41 #include <asm/it8172/it8172_int.h>
42 
pcibios_fixup_resources(struct pci_dev * dev)43 void __init pcibios_fixup_resources(struct pci_dev *dev)
44 {
45 }
46 
pcibios_fixup(void)47 void __init pcibios_fixup(void)
48 {
49 }
50 
pcibios_fixup_irqs(void)51 void __init pcibios_fixup_irqs(void)
52 {
53 	unsigned int slot, func;
54 	unsigned char pin;
55 	struct pci_dev *dev;
56         const int internal_func_irqs[7] = {
57             IT8172_AC97_IRQ,
58             IT8172_DMA_IRQ,
59             IT8172_CDMA_IRQ,
60             IT8172_USB_IRQ,
61             IT8172_BRIDGE_MASTER_IRQ,
62             IT8172_IDE_IRQ,
63             IT8172_MC68K_IRQ
64         };
65 
66 	pci_for_each_dev(dev) {
67 		if (dev->bus->number != 0) {
68 			return;
69 		}
70 
71 		pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
72 		slot = PCI_SLOT(dev->devfn);
73 		func = PCI_FUNC(dev->devfn);
74 
75 		switch (slot) {
76 			case 0x01:
77 			    /*
78 			     * Internal device 1 is actually 7 different
79 			     * internal devices on the IT8172G (a multi-
80 			     * function device).
81 			     */
82 			    if (func < 7)
83 				dev->irq = internal_func_irqs[func];
84 			    break;
85 			case 0x10:
86 				switch (pin) {
87 					case 1: /* pin A */
88 						dev->irq = IT8172_PCI_INTA_IRQ;
89 						break;
90 					case 2: /* pin B */
91 						dev->irq = IT8172_PCI_INTB_IRQ;
92 						break;
93 					case 3: /* pin C */
94 						dev->irq = IT8172_PCI_INTC_IRQ;
95 						break;
96 					case 4: /* pin D */
97 						dev->irq = IT8172_PCI_INTD_IRQ;
98 						break;
99 					default:
100 						dev->irq = 0xff;
101 						break;
102 
103 				}
104 				break;
105 			case 0x11:
106 				switch (pin) {
107 					case 1: /* pin A */
108 						dev->irq = IT8172_PCI_INTA_IRQ;
109 						break;
110 					case 2: /* pin B */
111 						dev->irq = IT8172_PCI_INTB_IRQ;
112 						break;
113 					case 3: /* pin C */
114 						dev->irq = IT8172_PCI_INTC_IRQ;
115 						break;
116 					case 4: /* pin D */
117 						dev->irq = IT8172_PCI_INTD_IRQ;
118 						break;
119 					default:
120 						dev->irq = 0xff;
121 						break;
122 
123 				}
124 				break;
125 			case 0x12:
126 				switch (pin) {
127 					case 1: /* pin A */
128 						dev->irq = IT8172_PCI_INTB_IRQ;
129 						break;
130 					case 2: /* pin B */
131 						dev->irq = IT8172_PCI_INTC_IRQ;
132 						break;
133 					case 3: /* pin C */
134 						dev->irq = IT8172_PCI_INTD_IRQ;
135 						break;
136 					case 4: /* pin D */
137 						dev->irq = IT8172_PCI_INTA_IRQ;
138 						break;
139 					default:
140 						dev->irq = 0xff;
141 						break;
142 
143 				}
144 				break;
145 			case 0x13:
146 				switch (pin) {
147 					case 1: /* pin A */
148 						dev->irq = IT8172_PCI_INTC_IRQ;
149 						break;
150 					case 2: /* pin B */
151 						dev->irq = IT8172_PCI_INTD_IRQ;
152 						break;
153 					case 3: /* pin C */
154 						dev->irq = IT8172_PCI_INTA_IRQ;
155 						break;
156 					case 4: /* pin D */
157 						dev->irq = IT8172_PCI_INTB_IRQ;
158 						break;
159 					default:
160 						dev->irq = 0xff;
161 						break;
162 
163 				}
164 				break;
165 			case 0x14:
166 				switch (pin) {
167 					case 1: /* pin A */
168 						dev->irq = IT8172_PCI_INTD_IRQ;
169 						break;
170 					case 2: /* pin B */
171 						dev->irq = IT8172_PCI_INTA_IRQ;
172 						break;
173 					case 3: /* pin C */
174 						dev->irq = IT8172_PCI_INTB_IRQ;
175 						break;
176 					case 4: /* pin D */
177 						dev->irq = IT8172_PCI_INTC_IRQ;
178 						break;
179 					default:
180 						dev->irq = 0xff;
181 						break;
182 
183 				}
184 				break;
185 			default:
186 				continue; /* do nothing */
187 		}
188 #ifdef DEBUG
189 		printk("irq fixup: slot %d, int line %d, int number %d\n",
190 			slot, pin, dev->irq);
191 #endif
192 		pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
193 	}
194 }
195 #endif
196