1 /***********************************************************************
2  *
3  * Copyright 2001 MontaVista Software Inc.
4  * Author: jsun@mvista.com or jsun@junsun.net
5  *
6  * arch/mips/ddb5xxx/common/prom.c
7  *     prom.c file.
8  *
9  * This program is free software; you can redistribute  it and/or modify it
10  * under  the terms of  the GNU General  Public License as published by the
11  * Free Software Foundation;  either version 2 of the  License, or (at your
12  * option) any later version.
13  *
14  ***********************************************************************
15  */
16 #include <linux/config.h>
17 #include <linux/init.h>
18 #include <linux/mm.h>
19 #include <linux/sched.h>
20 #include <linux/bootmem.h>
21 
22 #include <asm/addrspace.h>
23 #include <asm/bootinfo.h>
24 #include <asm/ddb5xxx/ddb5xxx.h>
25 #include <asm/debug.h>
26 
27 char arcs_cmdline[CL_SIZE];
28 
29 void ddb5477_runtime_detection(void);
30 
get_system_type(void)31 const char *get_system_type(void)
32 {
33 	switch (mips_machtype) {
34 	case MACH_NEC_DDB5074:		return "NEC DDB Vrc-5074";
35 	case MACH_NEC_DDB5476:		return "NEC DDB Vrc-5476";
36 	case MACH_NEC_DDB5477:		return "NEC DDB Vrc-5477";
37 	case MACH_NEC_ROCKHOPPER:	return "NEC Rockhopper";
38 	case MACH_NEC_ROCKHOPPERII:	return "NEC RockhopperII";
39 	default:			return "Unknown NEC board";
40 	}
41 }
42 
43 /* [jsun@junsun.net] PMON passes arguments in C main() style */
prom_init(int argc,const char ** arg)44 void __init prom_init(int argc, const char **arg)
45 {
46 	int i;
47 
48 	/* arg[0] is "g", the rest is boot parameters */
49 	arcs_cmdline[0] = '\0';
50 	for (i = 1; i < argc; i++) {
51 		if (strlen(arcs_cmdline) + strlen(arg[i] + 1)
52 		    >= sizeof(arcs_cmdline))
53 			break;
54 		strcat(arcs_cmdline, arg[i]);
55 		strcat(arcs_cmdline, " ");
56 	}
57 
58 	/* by default all these boards use dhcp/nfs root fs */
59 	strcat(arcs_cmdline, "ip=bootp");
60 
61 	mips_machgroup = MACH_GROUP_NEC_DDB;
62 
63 #if defined(CONFIG_DDB5074)
64 	mips_machtype = MACH_NEC_DDB5074;
65 	add_memory_region(0, DDB_SDRAM_SIZE, BOOT_MEM_RAM);
66 #elif defined(CONFIG_DDB5476)
67 	mips_machtype = MACH_NEC_DDB5476;
68 	add_memory_region(0, DDB_SDRAM_SIZE, BOOT_MEM_RAM);
69 #elif defined(CONFIG_DDB5477)
70 	ddb5477_runtime_detection();
71 	add_memory_region(0, board_ram_size, BOOT_MEM_RAM);
72 #endif
73 }
74 
prom_free_prom_memory(void)75 void __init prom_free_prom_memory(void)
76 {
77 }
78 
79 #if defined(CONFIG_DDB5477)
80 
81 #define DEFAULT_LCS1_BASE 0x19000000
82 #define TESTVAL1 'K'
83 #define TESTVAL2 'S'
84 
85 int board_ram_size;
ddb5477_runtime_detection(void)86 void ddb5477_runtime_detection(void)
87 {
88 	volatile char *test_offset;
89 	char saved_test_byte;
90 
91         /* Determine if this is a DDB5477 board, or a BSB-VR0300
92            base board.  We can tell by checking for the location of
93            the NVRAM.  It lives at the beginning of LCS1 on the DDB5477,
94            and the beginning of LCS1 on the BSB-VR0300 is flash memory.
95            The first 2K of the NVRAM are reserved, so don't we'll poke
96            around just after that.
97          */
98 
99 	/* We can only use the PCI bus to distinquish between
100 	   the Rockhopper and RockhopperII backplanes and this must
101 	   wait until ddb5477_board_init() in setup.c after the 5477
102 	   is initialized.  So, until then handle
103 	   both Rockhopper and RockhopperII backplanes as Rockhopper 1
104 	 */
105 
106         test_offset = (char *)KSEG1ADDR(DEFAULT_LCS1_BASE + 0x800);
107         saved_test_byte = *test_offset;
108 
109         *test_offset = TESTVAL1;
110         if (*test_offset != TESTVAL1) {
111                 /* We couldn't set our test value, so it must not be NVRAM,
112                    so it's a BSB_VR0300 */
113 		mips_machtype = MACH_NEC_ROCKHOPPER;
114         } else {
115                 /* We may have gotten lucky, and the TESTVAL1 was already
116                    stored at the test location, so we must check a second
117                    test value */
118                 *test_offset = TESTVAL2;
119                 if (*test_offset != TESTVAL2) {
120                         /* OK, we couldn't set this value either, so it must
121                            definately be a BSB_VR0300 */
122 			mips_machtype = MACH_NEC_ROCKHOPPER;
123                 } else {
124                         /* We could change the value twice, so it must be
125                         NVRAM, so it's a DDB_VRC5477 */
126 			mips_machtype = MACH_NEC_DDB5477;
127                 }
128         }
129         /* Restore the original byte */
130         *test_offset = saved_test_byte;
131 
132 	/* before we know a better way, we will trust PMON for getting
133 	 * RAM size
134 	 */
135 	board_ram_size = 1 << (36 - (ddb_in32(DDB_SDRAM0) & 0xf));
136 
137 	db_run(printk("DDB run-time detection : %s, %d MB RAM\n",
138 				mips_machtype == MACH_NEC_DDB5477 ?
139 				"DDB5477" : "Rockhopper",
140 				board_ram_size >> 20));
141 
142 	/* we can't handle ram size > 128 MB */
143 	db_assert(board_ram_size <= (128 << 20));
144 }
145 #endif
146