blob: 1f5f141fb7a18633b099c4ad8bb1495cbef5b824 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +10002 * arch/ppc64/kernel/pSeries_pci.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2001 Dave Engebretsen, IBM Corporation
5 * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
6 *
7 * pSeries specific routines for PCI.
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +100024#include <linux/init.h>
25#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/pci.h>
28#include <linux/string.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <asm/pci-bridge.h>
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +100031#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "pci.h"
34
John Rosedad32bb2005-06-23 17:09:54 +100035static int __initdata s7a_workaround = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#if 0
38void pcibios_name_device(struct pci_dev *dev)
39{
40 struct device_node *dn;
41
42 /*
43 * Add IBM loc code (slot) as a prefix to the device names for service
44 */
45 dn = pci_device_to_OF_node(dev);
46 if (dn) {
47 char *loc_code = get_property(dn, "ibm,loc-code", 0);
48 if (loc_code) {
49 int loc_len = strlen(loc_code);
50 if (loc_len < sizeof(dev->dev.name)) {
51 memmove(dev->dev.name+loc_len+1, dev->dev.name,
52 sizeof(dev->dev.name)-loc_len-1);
53 memcpy(dev->dev.name, loc_code, loc_len);
54 dev->dev.name[loc_len] = ' ';
55 dev->dev.name[sizeof(dev->dev.name)-1] = '\0';
56 }
57 }
58 }
59}
60DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pcibios_name_device);
61#endif
62
Arnd Bergmannc5a3c2e2005-06-23 09:43:23 +100063static void __init check_s7a(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 struct device_node *root;
66 char *model;
67
John Rosedad32bb2005-06-23 17:09:54 +100068 s7a_workaround = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 root = of_find_node_by_path("/");
70 if (root) {
71 model = get_property(root, "model", NULL);
72 if (model && !strcmp(model, "IBM,7013-S7A"))
73 s7a_workaround = 1;
74 of_node_put(root);
75 }
76}
77
John Rosedad32bb2005-06-23 17:09:54 +100078void __devinit pSeries_irq_bus_setup(struct pci_bus *bus)
79{
80 struct pci_dev *dev;
81
82 if (s7a_workaround < 0)
83 check_s7a();
84 list_for_each_entry(dev, &bus->devices, bus_list) {
85 pci_read_irq_line(dev);
86 if (s7a_workaround) {
87 if (dev->irq > 16) {
88 dev->irq -= 3;
89 pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
90 dev->irq);
91 }
92 }
93 }
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static void __init pSeries_request_regions(void)
97{
98 if (!isa_io_base)
99 return;
100
101 request_region(0x20,0x20,"pic1");
102 request_region(0xa0,0x20,"pic2");
103 request_region(0x00,0x20,"dma1");
104 request_region(0x40,0x20,"timer");
105 request_region(0x80,0x10,"dma page reg");
106 request_region(0xc0,0x20,"dma2");
107}
108
109void __init pSeries_final_fixup(void)
110{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 phbs_remap_io();
112 pSeries_request_regions();
113
114 pci_addr_cache_build();
115}
116
117/*
118 * Assume the winbond 82c105 is the IDE controller on a
119 * p610. We should probably be more careful in case
120 * someone tries to plug in a similar adapter.
121 */
122static void fixup_winbond_82c105(struct pci_dev* dev)
123{
124 int i;
125 unsigned int reg;
126
127 if (!(systemcfg->platform & PLATFORM_PSERIES))
128 return;
129
130 printk("Using INTC for W82c105 IDE controller.\n");
131 pci_read_config_dword(dev, 0x40, &reg);
132 /* Enable LEGIRQ to use INTC instead of ISA interrupts */
133 pci_write_config_dword(dev, 0x40, reg | (1<<11));
134
135 for (i = 0; i < DEVICE_COUNT_RESOURCE; ++i) {
136 /* zap the 2nd function of the winbond chip */
137 if (dev->resource[i].flags & IORESOURCE_IO
138 && dev->bus->number == 0 && dev->devfn == 0x81)
139 dev->resource[i].flags &= ~IORESOURCE_IO;
140 }
141}
142DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_82C105,
143 fixup_winbond_82c105);