blob: 52d07c119a81995e9169d33a02bb911ecd48383b [file] [log] [blame]
Graeme Russ85cc39f2009-02-24 21:14:32 +11001/*
Graeme Russ45fc1d82011-04-13 19:43:26 +10002 * (C) Copyright 2008-2011
3 * Graeme Russ, <graeme.russ@gmail.com>
4 *
Graeme Russ85cc39f2009-02-24 21:14:32 +11005 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02006 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
Graeme Russ85cc39f2009-02-24 21:14:32 +11007 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
Graeme Russ85cc39f2009-02-24 21:14:32 +110027#include <common.h>
28#include <pci.h>
Graeme Russ0c5ced72010-04-24 00:05:37 +100029#include <asm/io.h>
Graeme Russ85cc39f2009-02-24 21:14:32 +110030#include <asm/pci.h>
Graeme Russ0d992d02011-08-04 22:05:09 +100031#include <asm/arch/pci.h>
32#include <asm/arch/sc520.h>
Graeme Russ85cc39f2009-02-24 21:14:32 +110033
34static struct {
35 u8 priority;
36 u16 level_reg;
37 u8 level_bit;
38} sc520_irq[] = {
Graeme Russ1d977dc2009-08-23 12:59:56 +100039 { SC520_IRQ0, 0, 0x01 },
40 { SC520_IRQ1, 0, 0x02 },
41 { SC520_IRQ2, 1, 0x02 },
42 { SC520_IRQ3, 0, 0x08 },
43 { SC520_IRQ4, 0, 0x10 },
44 { SC520_IRQ5, 0, 0x20 },
45 { SC520_IRQ6, 0, 0x40 },
46 { SC520_IRQ7, 0, 0x80 },
Graeme Russ85cc39f2009-02-24 21:14:32 +110047
Graeme Russ1d977dc2009-08-23 12:59:56 +100048 { SC520_IRQ8, 1, 0x01 },
49 { SC520_IRQ9, 1, 0x02 },
50 { SC520_IRQ10, 1, 0x04 },
51 { SC520_IRQ11, 1, 0x08 },
52 { SC520_IRQ12, 1, 0x10 },
53 { SC520_IRQ13, 1, 0x20 },
54 { SC520_IRQ14, 1, 0x40 },
55 { SC520_IRQ15, 1, 0x80 }
Graeme Russ85cc39f2009-02-24 21:14:32 +110056};
57
Graeme Russ85cc39f2009-02-24 21:14:32 +110058/* The interrupt used for PCI INTA-INTD */
59int sc520_pci_ints[15] = {
60 -1, -1, -1, -1, -1, -1, -1, -1,
61 -1, -1, -1, -1, -1, -1, -1
62};
63
64/* utility function to configure a pci interrupt */
65int pci_sc520_set_irq(int pci_pin, int irq)
66{
67 int i;
Graeme Russ0c5ced72010-04-24 00:05:37 +100068 u8 tmpb;
69 u16 tmpw;
Graeme Russ85cc39f2009-02-24 21:14:32 +110070
Graeme Russ45fc1d82011-04-13 19:43:26 +100071 debug("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
72
Graeme Russ55bed242011-11-08 02:33:14 +000073 if (irq < 0 || irq > 15)
Graeme Russ85cc39f2009-02-24 21:14:32 +110074 return -1; /* illegal irq */
Graeme Russ85cc39f2009-02-24 21:14:32 +110075
Graeme Russ55bed242011-11-08 02:33:14 +000076 if (pci_pin < 0 || pci_pin > 15)
Graeme Russ85cc39f2009-02-24 21:14:32 +110077 return -1; /* illegal pci int pin */
Graeme Russ85cc39f2009-02-24 21:14:32 +110078
79 /* first disable any non-pci interrupt source that use
80 * this level */
Graeme Russ1d977dc2009-08-23 12:59:56 +100081
82 /* PCI interrupt mapping (A through D)*/
Graeme Russ55bed242011-11-08 02:33:14 +000083 for (i = 0; i <= 3 ; i++) {
84 tmpb = readb(&sc520_mmcr->pci_int_map[i]);
85
86 if (tmpb == sc520_irq[irq].priority)
Graeme Russ0c5ced72010-04-24 00:05:37 +100087 writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]);
Graeme Russ1d977dc2009-08-23 12:59:56 +100088 }
89
90 /* GP IRQ interrupt mapping */
Graeme Russ55bed242011-11-08 02:33:14 +000091 for (i = 0; i <= 10 ; i++) {
92 tmpb = readb(&sc520_mmcr->gp_int_map[i]);
93
94 if (tmpb == sc520_irq[irq].priority)
Graeme Russ0c5ced72010-04-24 00:05:37 +100095 writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_int_map[i]);
Graeme Russ85cc39f2009-02-24 21:14:32 +110096 }
97
98 /* Set the trigger to level */
Graeme Russ0c5ced72010-04-24 00:05:37 +100099 tmpb = readb(&sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
100 tmpb |= sc520_irq[irq].level_bit;
101 writeb(tmpb, &sc520_mmcr->pic_mode[sc520_irq[irq].level_reg]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100102
103
104 if (pci_pin < 4) {
105 /* PCI INTA-INTD */
106 /* route the interrupt */
Graeme Russ55bed242011-11-08 02:33:14 +0000107 writeb(sc520_irq[irq].priority,
108 &sc520_mmcr->pci_int_map[pci_pin]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100109 } else {
110 /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
Graeme Russ55bed242011-11-08 02:33:14 +0000111 writeb(sc520_irq[irq].priority,
112 &sc520_mmcr->gp_int_map[pci_pin - 4]);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100113
114 /* also set the polarity in this case */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000115 tmpw = readw(&sc520_mmcr->intpinpol);
116 tmpw |= (1 << (pci_pin-4));
117 writew(tmpw, &sc520_mmcr->intpinpol);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100118 }
119
120 /* register the pin */
121 sc520_pci_ints[pci_pin] = irq;
122
123
124 return 0; /* OK */
125}
126
127void pci_sc520_init(struct pci_controller *hose)
128{
129 hose->first_busno = 0;
130 hose->last_busno = 0xff;
Graeme Russ6a554572010-04-24 00:05:54 +1000131 hose->region_count = pci_set_regions(hose);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100132
Graeme Russ703ede52011-11-08 02:33:22 +0000133 pci_setup_type1(hose);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100134
135 pci_register_hose(hose);
136
137 hose->last_busno = pci_hose_scan(hose);
138
139 /* enable target memory acceses on host brige */
140 pci_write_config_word(0, PCI_COMMAND,
141 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Graeme Russ85cc39f2009-02-24 21:14:32 +1100142}