blob: e0ba620d1f98227db6c6c29df901653fa8135f90 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*-----------------------------------------------------------------------------+
Josh Boyer31773492009-08-07 13:53:20 -04002| This source code is dual-licensed. You may use it under the terms of
3| the GNU General Public License version 2, or under the license below.
wdenkc6097192002-11-03 00:24:07 +00004|
5| This source code has been made available to you by IBM on an AS-IS
6| basis. Anyone receiving this source is licensed under IBM
7| copyrights to use it in any way he or she deems fit, including
8| copying it, modifying it, compiling it, and redistributing it either
9| with or without modifications. No license under IBM patents or
10| patent applications is to be implied by the copyright license.
11|
12| Any user of this software should understand that IBM cannot provide
13| technical support for this software and will not be responsible for
14| any consequences resulting from the use of this software.
15|
16| Any person who transfers this source code or any derivative work
17| must include the IBM copyright notice, this paragraph, and the
18| preceding two paragraphs in the transferred software.
19|
20| COPYRIGHT I B M CORPORATION 1995
21| LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
22+-----------------------------------------------------------------------------*/
23/*
24 * Adapted for PIP405 03.07.01
25 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
26 *
27 * TODO: Clean-up
28 */
29
30#include <common.h>
31#include <pci.h>
32#include "isa.h"
33
34#ifdef CONFIG_405GP
35#ifdef CONFIG_PCI
36
Wolfgang Denkd87080b2006-03-31 18:32:53 +020037DECLARE_GLOBAL_DATA_PTR;
wdenkc6097192002-11-03 00:24:07 +000038
39#include "piix4_pci.h"
40#include "pci_parts.h"
41
42void pci_pip405_write_regs(struct pci_controller *hose, pci_dev_t dev,
43 struct pci_config_table *entry)
44{
45 struct pci_pip405_config_entry *table;
46 int i;
47
48 table = (struct pci_pip405_config_entry*) entry->priv[0];
49
50 for (i=0; table[i].width; i++)
51 {
52#ifdef DEBUG
53 printf("Reg 0x%02X Value 0x%08lX Width %02d written\n",
54 table[i].index, table[i].val, table[i].width);
55#endif
56
57 switch(table[i].width)
58 {
59 case 1: pci_hose_write_config_byte(hose, dev, table[i].index, table[i].val); break;
60 case 2: pci_hose_write_config_word(hose, dev, table[i].index, table[i].val); break;
61 case 4: pci_hose_write_config_dword(hose, dev, table[i].index, table[i].val); break;
62 }
63 }
64}
65
66
67static void pci_pip405_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
68{
69 unsigned char int_line = 0xff;
wdenk3e386912003-04-05 00:53:31 +000070 unsigned char pin;
wdenkc6097192002-11-03 00:24:07 +000071 /*
72 * Write pci interrupt line register
73 */
74 if(PCI_DEV(dev)==0) /* Device0 = PPC405 -> skip */
75 return;
wdenk3e386912003-04-05 00:53:31 +000076 pci_hose_read_config_byte(hose, dev, PCI_INTERRUPT_PIN, &pin);
77 if ((pin == 0) || (pin > 4))
78 return;
79
80 int_line = ((PCI_DEV(dev) + (pin-1) + 10) % 4) + 28;
81 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
wdenkc6097192002-11-03 00:24:07 +000082#ifdef DEBUG
wdenk3e386912003-04-05 00:53:31 +000083 printf("Fixup IRQ: dev %d (%x) int line %d 0x%x\n",
84 PCI_DEV(dev),dev,int_line,int_line);
wdenkc6097192002-11-03 00:24:07 +000085#endif
wdenkc6097192002-11-03 00:24:07 +000086}
87
88extern void pci_405gp_init(struct pci_controller *hose);
89
90
91static struct pci_controller hose = {
92 config_table: pci_pip405_config_table,
93 fixup_irq: pci_pip405_fixup_irq,
94};
95
wdenk3e386912003-04-05 00:53:31 +000096
97static void reloc_pci_cfg_table(struct pci_config_table *table)
98{
wdenk3e386912003-04-05 00:53:31 +000099 unsigned long addr;
100
101 for (; table && table->vendor; table++) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200102 addr = (ulong) (table->config_device) + gd->reloc_off;
wdenk3e386912003-04-05 00:53:31 +0000103#ifdef DEBUG
104 printf ("device \"%d\": 0x%08lx => 0x%08lx\n",
105 table->device, (ulong) (table->config_device), addr);
106#endif
107 table->config_device =
108 (void (*)(struct pci_controller* hose, pci_dev_t dev,
109 struct pci_config_table *))addr;
110 table->priv[0]+=gd->reloc_off;
111 }
112}
113
stroesead10dd92003-02-14 11:21:23 +0000114void pci_init_board(void)
wdenkc6097192002-11-03 00:24:07 +0000115{
116 /*we want the ptrs to RAM not flash (ie don't use init list)*/
117 hose.fixup_irq = pci_pip405_fixup_irq;
118 hose.config_table = pci_pip405_config_table;
wdenk3e386912003-04-05 00:53:31 +0000119 reloc_pci_cfg_table(hose.config_table);
120#ifdef DEBUG
121 printf("Init PCI: fixup_irq=%p config_table=%p hose=%p\n",pci_pip405_fixup_irq,pci_pip405_config_table,hose);
122#endif
wdenkc6097192002-11-03 00:24:07 +0000123 pci_405gp_init(&hose);
124}
125
126#endif /* CONFIG_PCI */
127#endif /* CONFIG_405GP */