2 * arch/ppc/syslib/ibm44x_common.c
4 * PPC44x system library
6 * Matt Porter <mporter@mvista.com>
7 * Copyright 2002-2003 MontaVista Software Inc.
9 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
10 * Copyright (c) 2003, 2004 Zultys Technologies
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.
18 #include <linux/config.h>
19 #include <linux/types.h>
20 #include <linux/serial.h>
22 #include <asm/param.h>
23 #include <asm/ibm44x.h>
25 #include <asm/machdep.h>
27 #include <asm/ppc4xx_pic.h>
29 phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size)
31 phys_addr_t page_4gb = 0;
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
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;
45 return (page_4gb | addr);
48 void __init ibm44x_calibrate_decr(unsigned int freq)
50 tb_ticks_per_jiffy = freq / HZ;
51 tb_to_us = mulhwu_scale_factor(freq, 1000000);
53 /* Set the time base to zero */
57 /* Clear any pending timer interrupts */
58 mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
60 /* Enable decrementer interrupt */
61 mtspr(SPRN_TCR, TCR_DIE);
64 extern void abort(void);
66 static void ibm44x_restart(char *cmd)
72 static void ibm44x_power_off(void)
78 static void ibm44x_halt(void)
85 * Read the 44x memory controller to get size of system memory.
87 static unsigned long __init ibm44x_find_end_of_memory(void)
97 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
100 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
103 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
106 mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
110 bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
112 if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
114 switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
116 case SDRAM_CONFIG_SIZE_8M:
117 mem_size += PPC44x_MEM_SIZE_8M;
119 case SDRAM_CONFIG_SIZE_16M:
120 mem_size += PPC44x_MEM_SIZE_16M;
122 case SDRAM_CONFIG_SIZE_32M:
123 mem_size += PPC44x_MEM_SIZE_32M;
125 case SDRAM_CONFIG_SIZE_64M:
126 mem_size += PPC44x_MEM_SIZE_64M;
128 case SDRAM_CONFIG_SIZE_128M:
129 mem_size += PPC44x_MEM_SIZE_128M;
131 case SDRAM_CONFIG_SIZE_256M:
132 mem_size += PPC44x_MEM_SIZE_256M;
134 case SDRAM_CONFIG_SIZE_512M:
135 mem_size += PPC44x_MEM_SIZE_512M;
142 static void __init ibm44x_init_irq(void)
148 for (i = 0; i < NR_IRQS; i++)
149 irq_desc[i].handler = ppc4xx_pic;
152 #ifdef CONFIG_SERIAL_TEXT_DEBUG
153 #include <linux/serialP.h>
154 #include <linux/serial_reg.h>
155 #include <asm/serial.h>
157 static struct serial_state rs_table[RS_TABLE_SIZE] = {
158 SERIAL_PORT_DFNS /* Defined in <asm/serial.h> */
161 static void ibm44x_progress(char *s, unsigned short hex)
164 volatile unsigned long com_port;
167 com_port = (unsigned long)rs_table[0].iomem_base;
168 shift = rs_table[0].iomem_reg_shift;
170 while ((c = *s++) != 0) {
171 while ((*((volatile unsigned char *)com_port +
172 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
174 *(volatile unsigned char *)com_port = c;
178 /* Send LF/CR to pretty up output */
179 while ((*((volatile unsigned char *)com_port +
180 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
182 *(volatile unsigned char *)com_port = '\r';
183 while ((*((volatile unsigned char *)com_port +
184 (UART_LSR << shift)) & UART_LSR_THRE) == 0)
186 *(volatile unsigned char *)com_port = '\n';
188 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
190 void __init ibm44x_platform_init(void)
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;
198 #ifdef CONFIG_SERIAL_TEXT_DEBUG
199 ppc_md.progress = ibm44x_progress;
200 #endif /* CONFIG_SERIAL_TEXT_DEBUG */