xref: /OK3568_Linux_fs/kernel/arch/mips/sgi-ip32/ip32-setup.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * IP32 basic setup
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is subject to the terms and conditions of the GNU General Public
5*4882a593Smuzhiyun  * License.  See the file "COPYING" in the main directory of this archive
6*4882a593Smuzhiyun  * for more details.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Copyright (C) 2000 Harald Koerfgen
9*4882a593Smuzhiyun  * Copyright (C) 2002, 2003, 2005 Ilya A. Volynets
10*4882a593Smuzhiyun  * Copyright (C) 2006 Ralf Baechle <ralf@linux-mips.org>
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun #include <linux/console.h>
13*4882a593Smuzhiyun #include <linux/init.h>
14*4882a593Smuzhiyun #include <linux/interrupt.h>
15*4882a593Smuzhiyun #include <linux/param.h>
16*4882a593Smuzhiyun #include <linux/sched.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #include <asm/bootinfo.h>
19*4882a593Smuzhiyun #include <asm/mipsregs.h>
20*4882a593Smuzhiyun #include <asm/mmu_context.h>
21*4882a593Smuzhiyun #include <asm/sgialib.h>
22*4882a593Smuzhiyun #include <asm/time.h>
23*4882a593Smuzhiyun #include <asm/traps.h>
24*4882a593Smuzhiyun #include <asm/io.h>
25*4882a593Smuzhiyun #include <asm/ip32/crime.h>
26*4882a593Smuzhiyun #include <asm/ip32/mace.h>
27*4882a593Smuzhiyun #include <asm/ip32/ip32_ints.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun extern void ip32_be_init(void);
30*4882a593Smuzhiyun extern void crime_init(void);
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifdef CONFIG_SGI_O2MACE_ETH
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * This is taken care of in here 'cause they say using Arc later on is
35*4882a593Smuzhiyun  * problematic
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun extern char o2meth_eaddr[8];
str2hexnum(unsigned char c)38*4882a593Smuzhiyun static inline unsigned char str2hexnum(unsigned char c)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	if (c >= '0' && c <= '9')
41*4882a593Smuzhiyun 		return c - '0';
42*4882a593Smuzhiyun 	if (c >= 'a' && c <= 'f')
43*4882a593Smuzhiyun 		return c - 'a' + 10;
44*4882a593Smuzhiyun 	return 0; /* foo */
45*4882a593Smuzhiyun }
46*4882a593Smuzhiyun 
str2eaddr(unsigned char * ea,unsigned char * str)47*4882a593Smuzhiyun static inline void str2eaddr(unsigned char *ea, unsigned char *str)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun 	int i;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	for (i = 0; i < 6; i++) {
52*4882a593Smuzhiyun 		unsigned char num;
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 		if(*str == ':')
55*4882a593Smuzhiyun 			str++;
56*4882a593Smuzhiyun 		num = str2hexnum(*str++) << 4;
57*4882a593Smuzhiyun 		num |= (str2hexnum(*str++));
58*4882a593Smuzhiyun 		ea[i] = num;
59*4882a593Smuzhiyun 	}
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* An arbitrary time; this can be decreased if reliability looks good */
64*4882a593Smuzhiyun #define WAIT_MS 10
65*4882a593Smuzhiyun 
plat_time_init(void)66*4882a593Smuzhiyun void __init plat_time_init(void)
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun 	printk(KERN_INFO "Calibrating system timer... ");
69*4882a593Smuzhiyun 	write_c0_count(0);
70*4882a593Smuzhiyun 	crime->timer = 0;
71*4882a593Smuzhiyun 	while (crime->timer < CRIME_MASTER_FREQ * WAIT_MS / 1000) ;
72*4882a593Smuzhiyun 	mips_hpt_frequency = read_c0_count() * 1000 / WAIT_MS;
73*4882a593Smuzhiyun 	printk("%d MHz CPU detected\n", mips_hpt_frequency * 2 / 1000000);
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun 
plat_mem_setup(void)76*4882a593Smuzhiyun void __init plat_mem_setup(void)
77*4882a593Smuzhiyun {
78*4882a593Smuzhiyun 	board_be_init = ip32_be_init;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun #ifdef CONFIG_SGI_O2MACE_ETH
81*4882a593Smuzhiyun 	{
82*4882a593Smuzhiyun 		char *mac = ArcGetEnvironmentVariable("eaddr");
83*4882a593Smuzhiyun 		str2eaddr(o2meth_eaddr, mac);
84*4882a593Smuzhiyun 	}
85*4882a593Smuzhiyun #endif
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #if defined(CONFIG_SERIAL_CORE_CONSOLE)
88*4882a593Smuzhiyun 	{
89*4882a593Smuzhiyun 		char* con = ArcGetEnvironmentVariable("console");
90*4882a593Smuzhiyun 		if (con && *con == 'd') {
91*4882a593Smuzhiyun 			static char options[8] __initdata;
92*4882a593Smuzhiyun 			char *baud = ArcGetEnvironmentVariable("dbaud");
93*4882a593Smuzhiyun 			if (baud)
94*4882a593Smuzhiyun 				strcpy(options, baud);
95*4882a593Smuzhiyun 			add_preferred_console("ttyS", *(con + 1) == '2' ? 1 : 0,
96*4882a593Smuzhiyun 					      baud ? options : NULL);
97*4882a593Smuzhiyun 		}
98*4882a593Smuzhiyun 	}
99*4882a593Smuzhiyun #endif
100*4882a593Smuzhiyun }
101