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