4029c43f588aa9ae89515d62beb2507fd76ca8b9
[linux-2.6.git] / arch / ppc / syslib / ibm44x_common.c
1 /*
2  * arch/ppc/syslib/ibm44x_common.c
3  *
4  * PPC44x system library
5  *
6  * Matt Porter <mporter@kernel.crashing.org>
7  * Copyright 2002-2004 MontaVista Software Inc.
8  *
9  * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10  * Copyright (c) 2003, 2004 Zultys Technologies
11  *
12  * This program is free software; you can redistribute  it and/or modify it
13  * under  the terms of  the GNU General  Public License as published by the
14  * Free Software Foundation;  either version 2 of the  License, or (at your
15  * option) any later version.
16  *
17  */
18 #include <linux/config.h>
19 #include <linux/time.h>
20 #include <linux/types.h>
21 #include <linux/serial.h>
22
23 #include <asm/ibm44x.h>
24 #include <asm/mmu.h>
25 #include <asm/machdep.h>
26 #include <asm/time.h>
27 #include <asm/ppc4xx_pic.h>
28 #include <asm/param.h>
29
30 #include <syslib/gen550.h>
31
32 phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size)
33 {
34         phys_addr_t page_4gb = 0;
35
36         /*
37          * Trap the least significant 32-bit portions of an
38          * address in the 440's 36-bit address space.  Fix
39          * them up with the appropriate ERPN
40          */
41         if ((addr >= PPC44x_IO_LO) && (addr < PPC44x_IO_HI))
42                 page_4gb = PPC44x_IO_PAGE;
43         else if ((addr >= PPC44x_PCICFG_LO) && (addr < PPC44x_PCICFG_HI))
44                 page_4gb = PPC44x_PCICFG_PAGE;
45         else if ((addr >= PPC44x_PCIMEM_LO) && (addr < PPC44x_PCIMEM_HI))
46                 page_4gb = PPC44x_PCIMEM_PAGE;
47
48         return (page_4gb | addr);
49 };
50
51 void __init ibm44x_calibrate_decr(unsigned int freq)
52 {
53         tb_ticks_per_jiffy = freq / HZ;
54         tb_to_us = mulhwu_scale_factor(freq, 1000000);
55
56         /* Set the time base to zero */
57         mtspr(SPRN_TBWL, 0);
58         mtspr(SPRN_TBWU, 0);
59
60         /* Clear any pending timer interrupts */
61         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
62
63         /* Enable decrementer interrupt */
64         mtspr(SPRN_TCR, TCR_DIE);
65 }
66
67 extern void abort(void);
68
69 static void ibm44x_restart(char *cmd)
70 {
71         local_irq_disable();
72         abort();
73 }
74
75 static void ibm44x_power_off(void)
76 {
77         local_irq_disable();
78         for(;;);
79 }
80
81 static void ibm44x_halt(void)
82 {
83         local_irq_disable();
84         for(;;);
85 }
86
87 /*
88  * Read the 44x memory controller to get size of system memory.
89  */
90 static unsigned long __init ibm44x_find_end_of_memory(void)
91 {
92         u32 i, bank_config;
93         u32 mem_size = 0;
94
95         for (i=0; i<4; i++)
96         {
97                 switch (i)
98                 {
99                         case 0:
100                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
101                                 break;
102                         case 1:
103                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
104                                 break;
105                         case 2:
106                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
107                                 break;
108                         case 3:
109                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
110                                 break;
111                 }
112
113                 bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
114
115                 if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
116                         continue;
117                 switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
118                 {
119                         case SDRAM_CONFIG_SIZE_8M:
120                                 mem_size += PPC44x_MEM_SIZE_8M;
121                                 break;
122                         case SDRAM_CONFIG_SIZE_16M:
123                                 mem_size += PPC44x_MEM_SIZE_16M;
124                                 break;
125                         case SDRAM_CONFIG_SIZE_32M:
126                                 mem_size += PPC44x_MEM_SIZE_32M;
127                                 break;
128                         case SDRAM_CONFIG_SIZE_64M:
129                                 mem_size += PPC44x_MEM_SIZE_64M;
130                                 break;
131                         case SDRAM_CONFIG_SIZE_128M:
132                                 mem_size += PPC44x_MEM_SIZE_128M;
133                                 break;
134                         case SDRAM_CONFIG_SIZE_256M:
135                                 mem_size += PPC44x_MEM_SIZE_256M;
136                                 break;
137                         case SDRAM_CONFIG_SIZE_512M:
138                                 mem_size += PPC44x_MEM_SIZE_512M;
139                                 break;
140                 }
141         }
142         return mem_size;
143 }
144
145 static void __init ibm44x_init_irq(void)
146 {
147         int i;
148
149         ppc4xx_pic_init();
150
151         for (i = 0; i < NR_IRQS; i++)
152                 irq_desc[i].handler = ppc4xx_pic;
153 }
154
155 void __init ibm44x_platform_init(void)
156 {
157         ppc_md.init_IRQ = ibm44x_init_irq;
158         ppc_md.find_end_of_memory = ibm44x_find_end_of_memory;
159         ppc_md.restart = ibm44x_restart;
160         ppc_md.power_off = ibm44x_power_off;
161         ppc_md.halt = ibm44x_halt;
162
163 #ifdef CONFIG_SERIAL_TEXT_DEBUG
164         ppc_md.progress = gen550_progress;
165 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
166 #ifdef CONFIG_KGDB
167         ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
168 #endif
169
170         /*
171          * The Abatron BDI JTAG debugger does not tolerate others
172          * mucking with the debug registers.
173          */
174 #if !defined(CONFIG_BDI_SWITCH)
175         /* Enable internal debug mode */
176         mtspr(SPRN_DBCR0, (DBCR0_IDM));
177
178         /* Clear any residual debug events */
179         mtspr(SPRN_DBSR, 0xffffffff);
180 #endif
181 }
182