vserver 1.9.3
[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@mvista.com>
7  * Copyright 2002-2003 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/types.h>
20 #include <linux/serial.h>
21
22 #include <asm/param.h>
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
29 phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size)
30 {
31         phys_addr_t page_4gb = 0;
32
33         /*
34          * Trap the least significant 32-bit portions of an
35          * address in the 440's 36-bit address space.  Fix
36          * them up with the appropriate ERPN
37          */
38         if ((addr >= PPC44x_IO_LO) && (addr < PPC44x_IO_HI))
39                 page_4gb = PPC44x_IO_PAGE;
40         else if ((addr >= PPC44x_PCICFG_LO) && (addr < PPC44x_PCICFG_HI))
41                 page_4gb = PPC44x_PCICFG_PAGE;
42         else if ((addr >= PPC44x_PCIMEM_LO) && (addr < PPC44x_PCIMEM_HI))
43                 page_4gb = PPC44x_PCIMEM_PAGE;
44
45         return (page_4gb | addr);
46 };
47
48 void __init ibm44x_calibrate_decr(unsigned int freq)
49 {
50         tb_ticks_per_jiffy = freq / HZ;
51         tb_to_us = mulhwu_scale_factor(freq, 1000000);
52
53         /* Set the time base to zero */
54         mtspr(SPRN_TBWL, 0);
55         mtspr(SPRN_TBWU, 0);
56
57         /* Clear any pending timer interrupts */
58         mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
59
60         /* Enable decrementer interrupt */
61         mtspr(SPRN_TCR, TCR_DIE);
62 }
63
64 extern void abort(void);
65
66 static void ibm44x_restart(char *cmd)
67 {
68         local_irq_disable();
69         abort();
70 }
71
72 static void ibm44x_power_off(void)
73 {
74         local_irq_disable();
75         for(;;);
76 }
77
78 static void ibm44x_halt(void)
79 {
80         local_irq_disable();
81         for(;;);
82 }
83
84 /*
85  * Read the 44x memory controller to get size of system memory.
86  */
87 static unsigned long __init ibm44x_find_end_of_memory(void)
88 {
89         u32 i, bank_config;
90         u32 mem_size = 0;
91
92         for (i=0; i<4; i++)
93         {
94                 switch (i)
95                 {
96                         case 0:
97                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
98                                 break;
99                         case 1:
100                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
101                                 break;
102                         case 2:
103                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
104                                 break;
105                         case 3:
106                                 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
107                                 break;
108                 }
109
110                 bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
111
112                 if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
113                         continue;
114                 switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
115                 {
116                         case SDRAM_CONFIG_SIZE_8M:
117                                 mem_size += PPC44x_MEM_SIZE_8M;
118                                 break;
119                         case SDRAM_CONFIG_SIZE_16M:
120                                 mem_size += PPC44x_MEM_SIZE_16M;
121                                 break;
122                         case SDRAM_CONFIG_SIZE_32M:
123                                 mem_size += PPC44x_MEM_SIZE_32M;
124                                 break;
125                         case SDRAM_CONFIG_SIZE_64M:
126                                 mem_size += PPC44x_MEM_SIZE_64M;
127                                 break;
128                         case SDRAM_CONFIG_SIZE_128M:
129                                 mem_size += PPC44x_MEM_SIZE_128M;
130                                 break;
131                         case SDRAM_CONFIG_SIZE_256M:
132                                 mem_size += PPC44x_MEM_SIZE_256M;
133                                 break;
134                         case SDRAM_CONFIG_SIZE_512M:
135                                 mem_size += PPC44x_MEM_SIZE_512M;
136                                 break;
137                 }
138         }
139         return mem_size;
140 }
141
142 static void __init ibm44x_init_irq(void)
143 {
144         int i;
145
146         ppc4xx_pic_init();
147
148         for (i = 0; i < NR_IRQS; i++)
149                 irq_desc[i].handler = ppc4xx_pic;
150 }
151
152 #ifdef CONFIG_SERIAL_TEXT_DEBUG
153 #include <linux/serialP.h>
154 #include <linux/serial_reg.h>
155 #include <asm/serial.h>
156
157 static struct serial_state rs_table[RS_TABLE_SIZE] = {
158         SERIAL_PORT_DFNS        /* Defined in <asm/serial.h> */
159 };
160
161 static void ibm44x_progress(char *s, unsigned short hex)
162 {
163         volatile char c;
164         volatile unsigned long com_port;
165         u16 shift;
166
167         com_port = (unsigned long)rs_table[0].iomem_base;
168         shift = rs_table[0].iomem_reg_shift;
169
170         while ((c = *s++) != 0) {
171                 while ((*((volatile unsigned char *)com_port +
172                                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
173                         ;
174                 *(volatile unsigned char *)com_port = c;
175
176         }
177
178         /* Send LF/CR to pretty up output */
179         while ((*((volatile unsigned char *)com_port +
180                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
181                 ;
182         *(volatile unsigned char *)com_port = '\r';
183         while ((*((volatile unsigned char *)com_port +
184                 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
185                 ;
186         *(volatile unsigned char *)com_port = '\n';
187 }
188 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
189
190 void __init ibm44x_platform_init(void)
191 {
192         ppc_md.init_IRQ = ibm44x_init_irq;
193         ppc_md.find_end_of_memory = ibm44x_find_end_of_memory;
194         ppc_md.restart = ibm44x_restart;
195         ppc_md.power_off = ibm44x_power_off;
196         ppc_md.halt = ibm44x_halt;
197
198 #ifdef CONFIG_SERIAL_TEXT_DEBUG
199         ppc_md.progress = ibm44x_progress;
200 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
201 }
202