]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/x86/cpu/sc520/sc520_pci.c
x86: Code cleanup
[karo-tx-uboot.git] / arch / x86 / cpu / sc520 / sc520_pci.c
1 /*
2  * (C) Copyright 2008-2011
3  * Graeme Russ, <graeme.russ@gmail.com>
4  *
5  * (C) Copyright 2002
6  * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
7  *
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
27 #include <common.h>
28 #include <pci.h>
29 #include <asm/io.h>
30 #include <asm/pci.h>
31 #include <asm/ic/pci.h>
32 #include <asm/ic/sc520.h>
33
34 static struct {
35         u8 priority;
36         u16 level_reg;
37         u8 level_bit;
38 } sc520_irq[] = {
39         { 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 },
47
48         { 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 }
56 };
57
58 /* The interrupt used for PCI INTA-INTD  */
59 int 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 */
65 int pci_sc520_set_irq(int pci_pin, int irq)
66 {
67         int i;
68         u8 tmpb;
69         u16 tmpw;
70
71         debug("set_irq(): map INT%c to IRQ%d\n", pci_pin + 'A', irq);
72
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 */
83
84         /* PCI interrupt mapping (A through D)*/
85         for (i=0; i<=3 ;i++) {
86                 if (readb(&sc520_mmcr->pci_int_map[i]) == sc520_irq[irq].priority)
87                         writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pci_int_map[i]);
88         }
89
90         /* GP IRQ interrupt mapping */
91         for (i=0; i<=10 ;i++) {
92                 if (readb(&sc520_mmcr->gp_int_map[i]) == sc520_irq[irq].priority)
93                         writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_int_map[i]);
94         }
95
96         /* Set the trigger to level */
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]);
100
101
102         if (pci_pin < 4) {
103                 /* PCI INTA-INTD */
104                 /* route the interrupt */
105                 writeb(sc520_irq[irq].priority, &sc520_mmcr->pci_int_map[pci_pin]);
106         } else {
107                 /* GPIRQ0-GPIRQ10 used for additional PCI INTS */
108                 writeb(sc520_irq[irq].priority, &sc520_mmcr->gp_int_map[pci_pin - 4]);
109
110                 /* also set the polarity in this case */
111                 tmpw = readw(&sc520_mmcr->intpinpol);
112                 tmpw |= (1 << (pci_pin-4));
113                 writew(tmpw, &sc520_mmcr->intpinpol);
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         hose->region_count = pci_set_regions(hose);
128
129         pci_setup_type1(hose,
130                         SC520_REG_ADDR,
131                         SC520_REG_DATA);
132
133         pci_register_hose(hose);
134
135         hose->last_busno = pci_hose_scan(hose);
136
137         /* enable target memory acceses on host brige */
138         pci_write_config_word(0, PCI_COMMAND,
139                               PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
140 }