Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[pandora-kernel.git] / arch / ppc / platforms / 4xx / ep405.c
1 /*
2  * Embedded Planet 405GP board
3  * http://www.embeddedplanet.com
4  *
5  * Author: Matthew Locke <mlocke@mvista.com>
6  *
7  * 2001 (c) MontaVista, Software, Inc.  This file is licensed under
8  * the terms of the GNU General Public License version 2.  This program
9  * is licensed "as is" without any warranty of any kind, whether express
10  * or implied.
11  */
12 #include <linux/init.h>
13 #include <linux/pci.h>
14 #include <asm/system.h>
15 #include <asm/pci-bridge.h>
16 #include <asm/machdep.h>
17 #include <asm/todc.h>
18 #include <asm/ocp.h>
19 #include <asm/ibm_ocp_pci.h>
20
21 #undef DEBUG
22 #ifdef DEBUG
23 #define DBG(x...) printk(x)
24 #else
25 #define DBG(x...)
26 #endif
27
28 u8 *ep405_bcsr;
29 u8 *ep405_nvram;
30
31 static struct {
32         u8 cpld_xirq_select;
33         int pci_idsel;
34         int irq;
35 } ep405_devtable[] = {
36 #ifdef CONFIG_EP405PC
37         {0x07, 0x0E, 25},               /* EP405PC: USB */
38 #endif
39 };
40
41 int __init
42 ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
43 {
44         int i;
45
46         /* AFAICT this is only called a few times during PCI setup, so
47            performance is not critical */
48         for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
49                 if (idsel == ep405_devtable[i].pci_idsel)
50                         return ep405_devtable[i].irq;
51         }
52         return -1;
53 };
54
55 void __init
56 ep405_setup_arch(void)
57 {
58         ppc4xx_setup_arch();
59
60         ibm_ocp_set_emac(0, 0);
61
62         if (__res.bi_nvramsize == 512*1024) {
63                 /* FIXME: we should properly handle NVRTCs of different sizes */
64                 TODC_INIT(TODC_TYPE_DS1557, ep405_nvram, ep405_nvram, ep405_nvram, 8);
65         }
66 }
67
68 void __init
69 bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
70 {
71         unsigned int bar_response, bar;
72         /*
73          * Expected PCI mapping:
74          *
75          *  PLB addr             PCI memory addr
76          *  ---------------------       ---------------------
77          *  0000'0000 - 7fff'ffff <---  0000'0000 - 7fff'ffff
78          *  8000'0000 - Bfff'ffff --->  8000'0000 - Bfff'ffff
79          *
80          *  PLB addr             PCI io addr
81          *  ---------------------       ---------------------
82          *  e800'0000 - e800'ffff --->  0000'0000 - 0001'0000
83          *
84          */
85
86         /* Disable region zero first */
87         out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
88         /* PLB starting addr, PCI: 0x80000000 */
89         out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
90         /* PCI start addr, 0x80000000 */
91         out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
92         /* 512MB range of PLB to PCI */
93         out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
94         /* Enable no pre-fetch, enable region */
95         out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
96                                                 (PPC405_PCI_UPPER_MEM -
97                                                  PPC405_PCI_MEM_BASE)) | 0x01));
98
99         /* Disable region one */
100         out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
101         out_le32((void *) &(pcip->pmm[1].la), 0x00000000);
102         out_le32((void *) &(pcip->pmm[1].pcila), 0x00000000);
103         out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
104         out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
105         out_le32((void *) &(pcip->ptm1ms), 0x00000000);
106
107         /* Disable region two */
108         out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
109         out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
110         out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
111         out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
112         out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
113         out_le32((void *) &(pcip->ptm2ms), 0x00000000);
114
115         /* Configure PTM (PCI->PLB) region 1 */
116         out_le32((void *) &(pcip->ptm1la), 0x00000000); /* PLB base address */
117         /* Disable PTM region 2 */
118         out_le32((void *) &(pcip->ptm2ms), 0x00000000);
119
120         /* Zero config bars */
121         for (bar = PCI_BASE_ADDRESS_1; bar <= PCI_BASE_ADDRESS_2; bar += 4) {
122                 early_write_config_dword(hose, hose->first_busno,
123                                          PCI_FUNC(hose->first_busno), bar,
124                                          0x00000000);
125                 early_read_config_dword(hose, hose->first_busno,
126                                         PCI_FUNC(hose->first_busno), bar,
127                                         &bar_response);
128                 DBG("BUS %d, device %d, Function %d bar 0x%8.8x is 0x%8.8x\n",
129                     hose->first_busno, PCI_SLOT(hose->first_busno),
130                     PCI_FUNC(hose->first_busno), bar, bar_response);
131         }
132         /* end work arround */
133 }
134
135 void __init
136 ep405_map_io(void)
137 {
138         bd_t *bip = &__res;
139
140         ppc4xx_map_io();
141
142         ep405_bcsr = ioremap(EP405_BCSR_PADDR, EP405_BCSR_SIZE);
143
144         if (bip->bi_nvramsize > 0) {
145                 ep405_nvram = ioremap(EP405_NVRAM_PADDR, bip->bi_nvramsize);
146         }
147 }
148
149 void __init
150 ep405_init_IRQ(void)
151 {
152         int i;
153
154         ppc4xx_init_IRQ();
155
156         /* Workaround for a bug in the firmware it incorrectly sets
157            the IRQ polarities for XIRQ0 and XIRQ1 */
158         mtdcr(DCRN_UIC_PR(DCRN_UIC0_BASE), 0xffffff80); /* set the polarity */
159         mtdcr(DCRN_UIC_SR(DCRN_UIC0_BASE), 0x00000060); /* clear bogus interrupts */
160
161         /* Activate the XIRQs from the CPLD */
162         writeb(0xf0, ep405_bcsr+10);
163
164         /* Set up IRQ routing */
165         for (i = 0; i < ARRAY_SIZE(ep405_devtable); i++) {
166                 if ( (ep405_devtable[i].irq >= 25)
167                      && (ep405_devtable[i].irq) <= 31) {
168                         writeb(ep405_devtable[i].cpld_xirq_select, ep405_bcsr+5);
169                         writeb(ep405_devtable[i].irq - 25, ep405_bcsr+6);
170                 }
171         }
172 }
173
174 void __init
175 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
176               unsigned long r6, unsigned long r7)
177 {
178         ppc4xx_init(r3, r4, r5, r6, r7);
179
180         ppc_md.setup_arch = ep405_setup_arch;
181         ppc_md.setup_io_mappings = ep405_map_io;
182         ppc_md.init_IRQ = ep405_init_IRQ;
183
184         ppc_md.nvram_read_val = todc_direct_read_val;
185         ppc_md.nvram_write_val = todc_direct_write_val;
186
187         if (__res.bi_nvramsize == 512*1024) {
188                 ppc_md.time_init = todc_time_init;
189                 ppc_md.set_rtc_time = todc_set_rtc_time;
190                 ppc_md.get_rtc_time = todc_get_rtc_time;
191         } else {
192                 printk("EP405: NVRTC size is not 512k (not a DS1557).  Not sure what to do with it\n");
193         }
194 }