cleanup
[linux-2.4.21-pre4.git] / arch / ppc / platforms / rainier.c
1 /*
2  *
3  *
4  *    Copyright 2000-2002 MontaVista Software Inc.
5  *      Author: MontaVista Software, Inc.
6  *              akuster@mvista.com <source@mvista.com>
7  *
8  *    Module name: rainier.c
9  *
10  *    Description:
11  *      Architecture- / platform-specific boot-time initialization code for
12  *      IBM PowerPC 4xx based boards. Adapted from original
13  *      code from walnut.c
14  *
15  *      Revision:
16  *              1.0 - armin
17  *
18  *      History:
19  *              02/05/02 - initial work
20  *
21  * Please read the COPYING file for all license details.
22  */
23 #include <linux/config.h>
24 #include <linux/init.h>
25 #include <linux/smp.h>
26 #include <linux/threads.h>
27 #include <linux/param.h>
28 #include <linux/string.h>
29 #include <linux/blk.h>
30 #include <linux/pci.h>
31 #include <linux/rtc.h>
32 #include <linux/serial.h>
33 #include <asm/pc_serial.h>
34
35 #include <asm/system.h>
36 #include <asm/pci-bridge.h>
37 #include <asm/processor.h>
38 #include <asm/machdep.h>
39 #include <asm/page.h>
40 #include <asm/time.h>
41 #include <asm/io.h>
42 #include <asm/todc.h>
43 #include <platforms/ibm_ocp.h>
44
45 #undef DEBUG
46
47 #ifdef DEBUG
48 #define DBG(x...) printk(x)
49 #else
50 #define DBG(x...)
51 #endif
52
53 void *rainier_rtc_base;
54 unsigned int rainier_io_page;
55
56 void
57 *locate_rainier_io(void)
58 {
59         unsigned int temp;
60
61         temp = in_le32((void*)PPC405_PCI_CONFIG_ADDR) & PCI_CONFIG_ADDR_MASK;
62         out_le32((void*)PPC405_PCI_CONFIG_ADDR,
63                         temp | PCI_CONFIG_CYCLE_ENABLE |PCI_BASE_ADDRESS_2);
64         temp = in_le32((void*)PPC405_PCI_CONFIG_DATA);
65
66         if (temp == (PCI_BASE_ADDRESS_MEM_CARD2 | PCI_BASE_ADDRESS_MEM_PREFETCH))
67                 return PPC_405RAINIER2_IO_PAGE;
68         else
69                 return PPC_405RAINIER1_IO_PAGE;
70 }
71
72 int __init
73 ppc405_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
74 {
75         static char pci_irq_table[][4] =
76             /*
77              *      PCI IDSEL/INTPIN->INTLINE
78              *      A       B       C       D
79              */
80         {
81                 {28, 28, 28, 28},       /* IDSEL 1 - PCI slot 1 */
82                 {29, 29, 29, 29},       /* IDSEL 2 - PCI slot 2 */
83                 {30, 30, 30, 30},       /* IDSEL 3 - PCI slot 3 */
84                 {31, 31, 31, 31},       /* IDSEL 4 - PCI slot 4 */
85         };
86
87         const long min_idsel = 1, max_idsel = 4, irqs_per_slot = 4;
88         return PCI_IRQ_TABLE_LOOKUP;
89 };
90
91 void __init
92 board_setup_arch(void)
93 {
94         struct serial_struct serialreq = {0};
95
96         serialreq.iomem_base = (void*)PPC405_UART0_IO_BASE;
97         serialreq.iomem_base += rainier_io_page;
98         serialreq.baud_base = BASE_BAUD;
99         serialreq.irq = PPC405_UART0_INT;
100         serialreq.flags = STD_COM_FLAGS;
101         serialreq.io_type = SERIAL_IO_MEM;
102
103         early_serial_setup(&serialreq);
104
105         /* RTC step for the rainier */
106         rainier_rtc_base = (void *) WALNUT_RTC_VADDR;
107         TODC_INIT(TODC_TYPE_DS1743, rainier_rtc_base, rainier_rtc_base,
108                   rainier_rtc_base, 8);
109 }
110
111 void __init
112 bios_fixup(struct pci_controller *hose, struct pcil0_regs *pcip)
113 {
114         /*
115          * Expected PCI mapping:
116          *
117          *  PLB addr             PCI memory addr
118          *  ---------------------       ---------------------
119          *  0000'0000 - 7fff'ffff <---  0000'0000 - 7fff'ffff
120          *  8000'0000 - Bfff'ffff --->  8000'0000 - Bfff'ffff
121          *
122          *  PLB addr             PCI io addr
123          *  ---------------------       ---------------------
124          *  e800'0000 - e800'ffff --->  0000'0000 - 0001'0000
125          *
126          * The following code is simplified by assuming that the bootrom
127          * has been well behaved in following this mapping.
128          */
129
130 #ifdef DEBUG
131         int i;
132
133         printk("ioremap PCLIO_BASE = 0x%x\n", pcip);
134         printk("PCI bridge regs before fixup \n");
135         for (i = 0; i <= 3; i++) {
136                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
137                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
138                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
139                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
140         }
141         printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
142         printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
143         printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
144         printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
145
146 #endif
147
148         /* Disable region first */
149         out_le32((void *) &(pcip->pmm[0].ma), 0x00000000);
150         /* PLB starting addr, PCI: 0x80000000 */
151         out_le32((void *) &(pcip->pmm[0].la), 0x80000000);
152         /* PCI start addr, 0x80000000 */
153         out_le32((void *) &(pcip->pmm[0].pcila), PPC405_PCI_MEM_BASE);
154         /* 512MB range of PLB to PCI */
155         out_le32((void *) &(pcip->pmm[0].pciha), 0x00000000);
156         /* Enable no pre-fetch, enable region */
157         out_le32((void *) &(pcip->pmm[0].ma), ((0xffffffff -
158                                                 (PPC405_PCI_UPPER_MEM -
159                                                  PPC405_PCI_MEM_BASE)) | 0x01));
160
161         /*region one used bu rainier*/
162         out_le32((void *) &(pcip->pmm[1].ma), 0x00000000);
163         out_le32((void *) &(pcip->pmm[1].la), 0x80000000);
164         out_le32((void *) &(pcip->pmm[1].pcila), 0x80000000);
165         out_le32((void *) &(pcip->pmm[1].pciha), 0x00000000);
166         out_le32((void *) &(pcip->pmm[1].ma), 0xFFFF8001);
167         out_le32((void *) &(pcip->ptm1ms), 0x00000000);
168
169         /* Disable region two */
170         out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
171         out_le32((void *) &(pcip->pmm[2].la), 0x00000000);
172         out_le32((void *) &(pcip->pmm[2].pcila), 0x00000000);
173         out_le32((void *) &(pcip->pmm[2].pciha), 0x00000000);
174         out_le32((void *) &(pcip->pmm[2].ma), 0x00000000);
175         out_le32((void *) &(pcip->ptm2ms), 0x00000000);
176
177         /* end work arround */
178
179 #ifdef DEBUG
180         printk("PCI bridge regs after fixup \n");
181         for (i = 0; i <= 3; i++) {
182                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].ma)));
183                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].la)));
184                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pcila)));
185                 printk(" pmm%dma\t0x%x\n", i, in_le32(&(pcip->pmm[i].pciha)));
186         }
187         printk(" ptm1ms\t0x%x\n", in_le32(&(pcip->ptm1ms)));
188         printk(" ptm1la\t0x%x\n", in_le32(&(pcip->ptm1la)));
189         printk(" ptm2ms\t0x%x\n", in_le32(&(pcip->ptm2ms)));
190         printk(" ptm2la\t0x%x\n", in_le32(&(pcip->ptm2la)));
191
192 #endif
193 }
194
195 void __init
196 board_io_mapping(void)
197 {
198         io_block_mapping(RAINIER_IO_PAGE_INTERPOSER_PADDR,
199                          RAINIER_IO_PAGE_INTERPOSER_VADDR,PAGE_SIZE , _PAGE_IO);
200
201         io_block_mapping(RAINIER_IO_PAGE_PCI_PADDR,
202                          RAINIER_IO_PAGE_PCI_VADDR,PAGE_SIZE , _PAGE_IO);
203         
204         io_block_mapping(RAINIER_RTC_VADDR,
205                          RAINIER_RTC_PADDR, RAINIER_RTC_SIZE, _PAGE_IO);
206
207         rainier_io_page = locate_rainier_io();
208        
209         io_block_mapping(rainier_io_page ,
210                          rainier_io_page , PAGE_SIZE, _PAGE_IO);
211
212 }
213
214 void __init
215 board_setup_irq(void)
216 {
217 }
218
219 void __init
220 board_init(void)
221 {
222         ppc_md.time_init                = m48t3x_time_init;
223         ppc_md.set_rtc_time             = m48t3x_set_rtc_time;
224         ppc_md.get_rtc_time             = m48t3x_get_rtc_time;
225         ppc_md.time_init = todc_time_init;
226         ppc_md.nvram_read_val = todc_direct_read_val;
227         ppc_md.nvram_write_val = todc_direct_write_val;
228 }