Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* stuff specific for the sc520, but independent of implementation */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <pci.h> |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 28 | #include <asm/io.h> |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 29 | #include <asm/pci.h> |
| 30 | #include <asm/ic/sc520.h> |
| 31 | |
| 32 | static struct { |
| 33 | u8 priority; |
| 34 | u16 level_reg; |
| 35 | u8 level_bit; |
| 36 | } sc520_irq[] = { |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 37 | { SC520_IRQ0, 0, 0x01 }, |
| 38 | { SC520_IRQ1, 0, 0x02 }, |
| 39 | { SC520_IRQ2, 1, 0x02 }, |
| 40 | { SC520_IRQ3, 0, 0x08 }, |
| 41 | { SC520_IRQ4, 0, 0x10 }, |
| 42 | { SC520_IRQ5, 0, 0x20 }, |
| 43 | { SC520_IRQ6, 0, 0x40 }, |
| 44 | { SC520_IRQ7, 0, 0x80 }, |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 45 | |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 46 | { SC520_IRQ8, 1, 0x01 }, |
| 47 | { SC520_IRQ9, 1, 0x02 }, |
| 48 | { SC520_IRQ10, 1, 0x04 }, |
| 49 | { SC520_IRQ11, 1, 0x08 }, |
| 50 | { SC520_IRQ12, 1, 0x10 }, |
| 51 | { SC520_IRQ13, 1, 0x20 }, |
| 52 | { SC520_IRQ14, 1, 0x40 }, |
| 53 | { SC520_IRQ15, 1, 0x80 } |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | |
| 57 | /* The interrupt used for PCI INTA-INTD */ |
| 58 | int sc520_pci_ints[15] = { |
| 59 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 60 | -1, -1, -1, -1, -1, -1, -1 |
| 61 | }; |
| 62 | |
| 63 | /* utility function to configure a pci interrupt */ |
| 64 | int pci_sc520_set_irq(int pci_pin, int irq) |
| 65 | { |
| 66 | int i; |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 67 | u8 tmpb; |
| 68 | u16 tmpw; |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 69 | |
| 70 | # if 1 |
| 71 | printf("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq); |
| 72 | #endif |
| 73 | if (irq < 0 || irq > 15) { |
| 74 | return -1; /* illegal irq */ |
| 75 | } |
| 76 | |
| 77 | if (pci_pin < 0 || pci_pin > 15) { |
| 78 | return -1; /* illegal pci int pin */ |
| 79 | } |
| 80 | |
| 81 | /* first disable any non-pci interrupt source that use |
| 82 | * this level */ |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 83 | |
| 84 | /* PCI interrupt mapping (A through D)*/ |
| 85 | for (i=0; i<=3 ;i++) { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 86 | if (readb(&sc520_mmcr->pci_int_map[i]) == sc520_irq[irq].priority) |
| 87 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]); |
Graeme Russ | 1d977dc | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /* GP IRQ interrupt mapping */ |
| 91 | for (i=0; i<=10 ;i++) { |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 92 | if (readb(&sc520_mmcr->gp_int_map[i]) == sc520_irq[irq].priority) |
| 93 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_int_map[i]); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* Set the trigger to level */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 97 | tmpb = readb(&sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]); |
| 98 | tmpb |= sc520_irq[irq].level_bit; |
| 99 | writeb(tmpb, &sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 100 | |
| 101 | |
| 102 | if (pci_pin < 4) { |
| 103 | /* PCI INTA-INTD */ |
| 104 | /* route the interrupt */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 105 | writeb(sc520_irq[irq].priority, &sc520_mmcr->pci_int_map[pci_pin]); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 106 | } else { |
| 107 | /* GPIRQ0-GPIRQ10 used for additional PCI INTS */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 108 | writeb(sc520_irq[irq].priority, &sc520_mmcr->gp_int_map[pci_pin - 4]); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 109 | |
| 110 | /* also set the polarity in this case */ |
Graeme Russ | 0c5ced7 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 111 | tmpw = readw(&sc520_mmcr->intpinpol); |
| 112 | tmpw |= (1 << (pci_pin-4)); |
| 113 | writew(tmpw, &sc520_mmcr->intpinpol); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* register the pin */ |
| 117 | sc520_pci_ints[pci_pin] = irq; |
| 118 | |
| 119 | |
| 120 | return 0; /* OK */ |
| 121 | } |
| 122 | |
| 123 | void pci_sc520_init(struct pci_controller *hose) |
| 124 | { |
| 125 | hose->first_busno = 0; |
| 126 | hose->last_busno = 0xff; |
| 127 | |
| 128 | /* System memory space */ |
| 129 | pci_set_region(hose->regions + 0, |
| 130 | SC520_PCI_MEMORY_BUS, |
| 131 | SC520_PCI_MEMORY_PHYS, |
| 132 | SC520_PCI_MEMORY_SIZE, |
Graeme Russ | d0811ab | 2009-08-23 12:59:50 +1000 | [diff] [blame] | 133 | PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
Graeme Russ | 85cc39f | 2009-02-24 21:14:32 +1100 | [diff] [blame] | 134 | |
| 135 | /* PCI memory space */ |
| 136 | pci_set_region(hose->regions + 1, |
| 137 | SC520_PCI_MEM_BUS, |
| 138 | SC520_PCI_MEM_PHYS, |
| 139 | SC520_PCI_MEM_SIZE, |
| 140 | PCI_REGION_MEM); |
| 141 | |
| 142 | /* ISA/PCI memory space */ |
| 143 | pci_set_region(hose->regions + 2, |
| 144 | SC520_ISA_MEM_BUS, |
| 145 | SC520_ISA_MEM_PHYS, |
| 146 | SC520_ISA_MEM_SIZE, |
| 147 | PCI_REGION_MEM); |
| 148 | |
| 149 | /* PCI I/O space */ |
| 150 | pci_set_region(hose->regions + 3, |
| 151 | SC520_PCI_IO_BUS, |
| 152 | SC520_PCI_IO_PHYS, |
| 153 | SC520_PCI_IO_SIZE, |
| 154 | PCI_REGION_IO); |
| 155 | |
| 156 | /* ISA/PCI I/O space */ |
| 157 | pci_set_region(hose->regions + 4, |
| 158 | SC520_ISA_IO_BUS, |
| 159 | SC520_ISA_IO_PHYS, |
| 160 | SC520_ISA_IO_SIZE, |
| 161 | PCI_REGION_IO); |
| 162 | |
| 163 | hose->region_count = 5; |
| 164 | |
| 165 | pci_setup_type1(hose, |
| 166 | SC520_REG_ADDR, |
| 167 | SC520_REG_DATA); |
| 168 | |
| 169 | pci_register_hose(hose); |
| 170 | |
| 171 | hose->last_busno = pci_hose_scan(hose); |
| 172 | |
| 173 | /* enable target memory acceses on host brige */ |
| 174 | pci_write_config_word(0, PCI_COMMAND, |
| 175 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER); |
| 176 | |
| 177 | } |