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