blob: 4eb5410f842a9ea4407d885a5c9afb2124eb1c8e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Cobalt Qube/Raq PCI support
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1995, 1996, 1997, 2002, 2003 by Ralf Baechle
9 * Copyright (C) 2001, 2002, 2003 by Liam Davies (ldavies@agile.tv)
10 */
11#include <linux/types.h>
12#include <linux/pci.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15
16#include <asm/pci.h>
17#include <asm/io.h>
18#include <asm/gt64120.h>
19
Yoichi Yuasa44320f22007-05-10 20:00:55 +090020#include <cobalt.h>
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +090021#include <irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000023static void qube_raq_galileo_early_fixup(struct pci_dev *dev)
24{
25 if (dev->devfn == PCI_DEVFN(0, 0) &&
26 (dev->class >> 8) == PCI_CLASS_MEMORY_OTHER) {
27
28 dev->class = (PCI_CLASS_BRIDGE_HOST << 8) | (dev->class & 0xff);
29
30 printk(KERN_INFO "Galileo: fixed bridge class\n");
31 }
32}
33
34DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
35 qube_raq_galileo_early_fixup);
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037static void qube_raq_via_bmIDE_fixup(struct pci_dev *dev)
38{
39 unsigned short cfgword;
40 unsigned char lt;
41
42 /* Enable Bus Mastering and fast back to back. */
43 pci_read_config_word(dev, PCI_COMMAND, &cfgword);
44 cfgword |= (PCI_COMMAND_FAST_BACK | PCI_COMMAND_MASTER);
45 pci_write_config_word(dev, PCI_COMMAND, cfgword);
46
47 /* Enable both ide interfaces. ROM only enables primary one. */
48 pci_write_config_byte(dev, 0x40, 0xb);
49
50 /* Set latency timer to reasonable value. */
51 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lt);
52 if (lt < 64)
53 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
Peter Horton52378442006-01-29 21:33:48 +000054 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
57DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_1,
58 qube_raq_via_bmIDE_fixup);
59
60static void qube_raq_galileo_fixup(struct pci_dev *dev)
61{
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000062 if (dev->devfn != PCI_DEVFN(0, 0))
63 return;
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /* Fix PCI latency-timer and cache-line-size values in Galileo
66 * host bridge.
67 */
68 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
Peter Horton52378442006-01-29 21:33:48 +000069 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 /*
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000072 * The code described by the comment below has been removed
73 * as it causes bus mastering by the Ethernet controllers
74 * to break under any kind of network load. We always set
75 * the retry timeouts to their maximum.
76 *
77 * --x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--x--
78 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 * On all machines prior to Q2, we had the STOP line disconnected
80 * from Galileo to VIA on PCI. The new Galileo does not function
81 * correctly unless we have it connected.
82 *
83 * Therefore we must set the disconnect/retry cycle values to
84 * something sensible when using the new Galileo.
85 */
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000086
Auke Kok44c10132007-06-08 15:46:36 -070087 printk(KERN_INFO "Galileo: revision %u\n", dev->revision);
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000088
89#if 0
Auke Kok44c10132007-06-08 15:46:36 -070090 if (dev->revision >= 0x10) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 /* New Galileo, assumes PCI stop line to VIA is connected. */
Yoichi Yuasa56ae5832006-10-14 00:25:04 +090092 GT_WRITE(GT_PCI0_TOR_OFS, 0x4020);
Auke Kok44c10132007-06-08 15:46:36 -070093 } else if (dev->revision == 0x1 || dev->revision == 0x2)
Ralf Baechlec4ed38a2005-02-21 16:18:36 +000094#endif
95 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 signed int timeo;
97 /* XXX WE MUST DO THIS ELSE GALILEO LOCKS UP! -DaveM */
Yoichi Yuasa56ae5832006-10-14 00:25:04 +090098 timeo = GT_READ(GT_PCI0_TOR_OFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 /* Old Galileo, assumes PCI STOP line to VIA is disconnected. */
Yoichi Yuasa56ae5832006-10-14 00:25:04 +0900100 GT_WRITE(GT_PCI0_TOR_OFS,
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000101 (0xff << 16) | /* retry count */
102 (0xff << 8) | /* timeout 1 */
Yoichi Yuasa56ae5832006-10-14 00:25:04 +0900103 0xff); /* timeout 0 */
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000104
105 /* enable PCI retry exceeded interrupt */
Yoichi Yuasa56ae5832006-10-14 00:25:04 +0900106 GT_WRITE(GT_INTRMASK_OFS, GT_INTR_RETRYCTR0_MSK | GT_READ(GT_INTRMASK_OFS));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108}
109
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000110DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT64111,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 qube_raq_galileo_fixup);
112
Yoichi Yuasa3f2d5602007-05-11 21:43:09 +0900113int cobalt_board_id;
114
115static void qube_raq_via_board_id_fixup(struct pci_dev *dev)
116{
117 u8 id;
118 int retval;
119
120 retval = pci_read_config_byte(dev, VIA_COBALT_BRD_ID_REG, &id);
121 if (retval) {
122 panic("Cannot read board ID");
123 return;
124 }
125
126 cobalt_board_id = VIA_COBALT_BRD_REG_to_ID(id);
127
128 printk(KERN_INFO "Cobalt board ID: %d\n", cobalt_board_id);
129}
130
131DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0,
132 qube_raq_via_board_id_fixup);
133
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000134static char irq_tab_qube1[] __initdata = {
135 [COBALT_PCICONF_CPU] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900136 [COBALT_PCICONF_ETH0] = QUBE1_ETH0_IRQ,
137 [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000138 [COBALT_PCICONF_VIA] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900139 [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000140 [COBALT_PCICONF_ETH1] = 0
141};
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static char irq_tab_cobalt[] __initdata = {
144 [COBALT_PCICONF_CPU] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900145 [COBALT_PCICONF_ETH0] = ETH0_IRQ,
146 [COBALT_PCICONF_RAQSCSI] = SCSI_IRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 [COBALT_PCICONF_VIA] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900148 [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
149 [COBALT_PCICONF_ETH1] = ETH1_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150};
151
152static char irq_tab_raq2[] __initdata = {
153 [COBALT_PCICONF_CPU] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900154 [COBALT_PCICONF_ETH0] = ETH0_IRQ,
155 [COBALT_PCICONF_RAQSCSI] = RAQ2_SCSI_IRQ,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 [COBALT_PCICONF_VIA] = 0,
Yoichi Yuasad5ab1a62007-09-13 23:51:26 +0900157 [COBALT_PCICONF_PCISLOT] = PCISLOT_IRQ,
158 [COBALT_PCICONF_ETH1] = ETH1_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159};
160
Ralf Baechle19df0d12007-07-10 17:33:00 +0100161int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Ralf Baechlec4ed38a2005-02-21 16:18:36 +0000163 if (cobalt_board_id < COBALT_BRD_ID_QUBE2)
164 return irq_tab_qube1[slot];
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 if (cobalt_board_id == COBALT_BRD_ID_RAQ2)
167 return irq_tab_raq2[slot];
168
169 return irq_tab_cobalt[slot];
170}
171
172/* Do platform specific device initialization at pci_enable_device() time */
173int pcibios_plat_dev_init(struct pci_dev *dev)
174{
175 return 0;
176}