brute-forced more changes from MontaVista's tree. SCSI partition table read still...
[linux-2.4.git] / arch / ppc / platforms / sandpoint_pci.c
1 /*
2  * arch/ppc/platforms/sandpoint_pci.c
3  * 
4  * PCI setup routines for the Motorola SPS Sandpoint Test Platform
5  *
6  * Author: Mark A. Greer
7  *         mgreer@mvista.com
8  *
9  * Copyright 2000-2002 MontaVista Software Inc.
10  *
11  * This program is free software; you can redistribute  it and/or modify it
12  * under  the terms of  the GNU General Public License as published by the
13  * Free Software Foundation;  either version 2 of the  License, or (at your
14  * option) any later version.
15  */
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
20
21 #include <asm/byteorder.h>
22 #include <asm/io.h>
23 #include <asm/irq.h>
24 #include <asm/uaccess.h>
25 #include <asm/machdep.h>
26 #include <asm/pci-bridge.h>
27 #include <asm/mpc10x.h>
28
29 #include "sandpoint.h"
30 //#define REX_DBG_PCI 
31 /*
32  * Motorola SPS Sandpoint interrupt routing.
33  */
34 #if 0 //REX: by MUSENKI
35 static inline int
36 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
37 {
38         static char pci_irq_table[][4] =
39         /*
40          *      PCI IDSEL/INTPIN->INTLINE 
41          *         A   B   C   D
42          */
43         {
44                 { SANDPOINT_SIO_IRQ,
45                        0,  0,  0 },     /* IDSEL 11 - i8259 on Winbond */
46                 {  0,  0,  0,  0 },     /* IDSEL 12 - unused */
47 #ifdef CONFIG_SANDPOINT_X3
48                { 17, 18, 19, 20 },     /* IDSEL 13 - PCI slot 1 */
49                { 18, 19, 20, 17 },     /* IDSEL 14 - PCI slot 2 */
50                { 19, 20, 17, 18 },     /* IDSEL 15 - PCI slot 3 */
51                { 20, 17, 18, 19 },     /* IDSEL 16 - PCI slot 4 */
52 #else
53                 { 16, 19, 18, 17 },     /* IDSEL 13 - PCI slot 1 */
54                 { 17, 16, 19, 18 },     /* IDSEL 14 - PCI slot 2 */
55                 { 18, 17, 16, 19 },     /* IDSEL 15 - PCI slot 3 */
56                 { 19, 18, 17, 16 },     /* IDSEL 16 - PCI slot 4 */
57 #endif
58         };
59
60         const long min_idsel = 11, max_idsel = 16, irqs_per_slot = 4;
61         return PCI_IRQ_TABLE_LOOKUP;
62 }
63 #endif
64 #if 0           //+Bing modified 11252004
65 static inline int
66 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
67 {
68         static char pci_irq_table[][4] =
69         /*
70          *      PCI IDSEL/INTPIN->INTLINE 
71          *         A   B   C   D
72          */
73         {
74                 {   3,  0,  0,  0 },    /* IDSEL 17 - disable */
75                 {   0,  0,  0,  0 },    /* IDSEL 18 - PCI slot1*/
76                 {   2,  0,  0,  0 },    /* IDSEL 19 - LAN 83815 */
77                 {   1,  0,  4,  0 }     /* IDSEL 20 - PCI slot2 */
78         };
79
80         const long min_idsel = 17, max_idsel = 20, irqs_per_slot = 4;
81         return PCI_IRQ_TABLE_LOOKUP;
82 }
83 #else
84 static inline int
85 sandpoint_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
86 {
87         static char pci_irq_table[][4] =
88         /*
89          *      PCI IDSEL/INTPIN->INTLINE 
90          *         A   B   C   D
91          */
92         {
93                 {   0,  0,  0,  0 },    /* IDSEL 13 - mini-PCI */
94                 {   1,  -1,  2,  0 },    /* IDSEL 14 - NEC USB2.0 */
95                 {   3,  0,  0,  0 },    /* IDSEL 15 - ADM983 */
96                 {   4,  0,  0,  0 }
97         };
98
99         const long min_idsel = 13, max_idsel = 16, irqs_per_slot = 4;
100         return PCI_IRQ_TABLE_LOOKUP;
101 }
102 #endif  //+Bing modified 11252004
103
104 #if 0 //REX:
105 static void __init
106 sandpoint_setup_winbond_83553(struct pci_controller *hose)
107 {
108         int             devfn;
109
110         /*
111          * Route IDE interrupts directly to the 8259's IRQ 14 & 15.
112          * We can't route the IDE interrupt to PCI INTC# or INTD# because those
113          * woule interfere with the PMC's INTC# and INTD# lines.
114          */
115         /*
116          * Winbond Fcn 0
117          */
118         devfn = PCI_DEVFN(11,0);
119
120         early_write_config_byte(hose,
121                                 0,
122                                 devfn,
123                                 0x43, /* IDE Interrupt Routing Control */
124                                 0xef);
125         early_write_config_word(hose,
126                                 0,
127                                 devfn,
128                                 0x44, /* PCI Interrupt Routing Control */
129                                 0x0000);
130
131         /* Want ISA memory cycles to be forwarded to PCI bus */
132         early_write_config_byte(hose,
133                                 0,
134                                 devfn,
135                                 0x48, /* ISA-to-PCI Addr Decoder Control */
136                                 0xf0);
137
138         /* Enable RTC and Keyboard address locations.  */
139         early_write_config_byte(hose,
140                                 0,
141                                 devfn,
142                                 0x4d,   /* Chip Select Control Register */
143                                 0x00);
144
145         /* Enable Port 92.  */
146         early_write_config_byte(hose,
147                                 0,
148                                 devfn,
149                                 0x4e,   /* AT System Control Register */
150                                 0x06);
151         /*
152          * Winbond Fcn 1
153          */
154         devfn = PCI_DEVFN(11,1);
155
156         /* Put IDE controller into native mode. */
157         early_write_config_byte(hose,
158                                 0,
159                                 devfn,
160                                 0x09,   /* Programming interface Register */
161                                 0x8f);
162
163         /* Init IRQ routing, enable both ports, disable fast 16 */
164         early_write_config_dword(hose,
165                                 0,
166                                 devfn,
167                                 0x40,   /* IDE Control/Status Register */
168                                 0x00ff0011);
169         return;
170 }
171 #endif //82553
172
173 #ifndef CONFIG_SANDPOINT_X3
174 /* On the sandpoint X2, we must avoid sending configuration cycles to
175  * device #12 (IDSEL addr = AD12).
176  */
177 static int                     
178 sandpoint_exclude_device(u_char bus, u_char devfn)
179 {
180 #if 0
181         if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
182                 return PCIBIOS_DEVICE_NOT_FOUND;
183         else
184                 return PCIBIOS_SUCCESSFUL;
185 #endif
186 #ifdef REX_DBG_PCI
187         printk("REX_DBG_PCI: dev-fun is %X:%X.\n",PCI_SLOT(devfn), PCI_FUNC(devfn));
188 #endif  
189         if ((bus == 0) && (PCI_SLOT(devfn) == SANDPOINT_HOST_BRIDGE_IDSEL))
190         {
191                 return PCIBIOS_DEVICE_NOT_FOUND;
192         }
193         else
194         {
195                 return PCIBIOS_SUCCESSFUL;
196         }       
197
198 }
199 #endif
200
201 void __init
202 sandpoint_find_bridges(void)
203 {
204         struct pci_controller   *hose;
205
206         hose = pcibios_alloc_controller();
207
208         if (!hose)
209         {
210                 printk("pcibios_alloc_controller alloc memory fail \n");
211                 return;
212         }
213         
214         hose->first_busno = 0;
215         hose->last_busno = 0xff;
216 //REX:
217 #if 0
218         if (mpc10x_bridge_init(hose,
219                                MPC10X_MEM_MAP_B,
220                                MPC10X_MEM_MAP_B,
221                                MPC10X_MAPB_EUMB_BASE) == 0) {
222 #endif
223         if (mpc10x_bridge_init(hose,
224                                MPC10X_MEM_MAP_B,
225                                MPC10X_MEM_MAP_B,
226                                0xfc000000) == 0) {
227
228                 /* Do early winbond init, then scan PCI bus */
229                 //REX:
230                 //sandpoint_setup_winbond_83553(hose);
231 #ifndef CONFIG_SANDPOINT_X3
232                 ppc_md.pci_exclude_device = sandpoint_exclude_device;
233 #endif
234                 hose->last_busno = pciauto_bus_scan(hose, hose->first_busno);
235
236                 ppc_md.pcibios_fixup = NULL;
237                 ppc_md.pcibios_fixup_bus = NULL;
238                 ppc_md.pci_swizzle = common_swizzle;
239                 ppc_md.pci_map_irq = sandpoint_map_irq;
240         }
241         else {
242                 if (ppc_md.progress)
243                         ppc_md.progress("Bridge init failed", 0x100);
244                 printk("Host bridge init failed\n");
245         }
246
247         return;
248 }