First Support on Ginger and OMAP TI
[linux-ginger.git] / arch / mips / pmc-sierra / msp71xx / msp_prom.c
blobc317a3623ce93fd88a56fada8e20f090e5e55975
1 /*
2 * BRIEF MODULE DESCRIPTION
3 * PROM library initialisation code, assuming a version of
4 * pmon is the boot code.
6 * Copyright 2000,2001 MontaVista Software Inc.
7 * Author: MontaVista Software, Inc.
8 * ppopov@mvista.com or source@mvista.com
10 * This file was derived from Carsten Langgaard's
11 * arch/mips/mips-boards/xx files.
13 * Carsten Langgaard, carstenl@mips.com
14 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA.
37 #include <linux/module.h>
38 #include <linux/kernel.h>
39 #include <linux/init.h>
40 #include <linux/string.h>
41 #include <linux/interrupt.h>
42 #include <linux/mm.h>
44 #include <asm/addrspace.h>
45 #include <asm/bootinfo.h>
46 #include <asm-generic/sections.h>
47 #include <asm/page.h>
49 #include <msp_prom.h>
50 #include <msp_regs.h>
52 /* global PROM environment variables and pointers */
53 int prom_argc;
54 char **prom_argv, **prom_envp;
55 int *prom_vec;
57 /* debug flag */
58 int init_debug = 1;
60 /* memory blocks */
61 struct prom_pmemblock mdesc[PROM_MAX_PMEMBLOCKS];
63 /* default feature sets */
64 static char msp_default_features[] =
65 #if defined(CONFIG_PMC_MSP4200_EVAL) \
66 || defined(CONFIG_PMC_MSP4200_GW)
67 "ERER";
68 #elif defined(CONFIG_PMC_MSP7120_EVAL) \
69 || defined(CONFIG_PMC_MSP7120_GW)
70 "EMEMSP";
71 #elif defined(CONFIG_PMC_MSP7120_FPGA)
72 "EMEM";
73 #endif
75 /* conversion functions */
76 static inline unsigned char str2hexnum(unsigned char c)
78 if (c >= '0' && c <= '9')
79 return c - '0';
80 if (c >= 'a' && c <= 'f')
81 return c - 'a' + 10;
82 return 0; /* foo */
85 static inline int str2eaddr(unsigned char *ea, unsigned char *str)
87 int index = 0;
88 unsigned char num = 0;
90 while (*str != '\0') {
91 if ((*str == '.') || (*str == ':')) {
92 ea[index++] = num;
93 num = 0;
94 str++;
95 } else {
96 num = num << 4;
97 num |= str2hexnum(*str++);
101 if (index == 5) {
102 ea[index++] = num;
103 return 0;
104 } else
105 return -1;
107 EXPORT_SYMBOL(str2eaddr);
109 static inline unsigned long str2hex(unsigned char *str)
111 int value = 0;
113 while (*str) {
114 value = value << 4;
115 value |= str2hexnum(*str++);
118 return value;
121 /* function to query the system information */
122 const char *get_system_type(void)
124 #if defined(CONFIG_PMC_MSP4200_EVAL)
125 return "PMC-Sierra MSP4200 Eval Board";
126 #elif defined(CONFIG_PMC_MSP4200_GW)
127 return "PMC-Sierra MSP4200 VoIP Gateway";
128 #elif defined(CONFIG_PMC_MSP7120_EVAL)
129 return "PMC-Sierra MSP7120 Eval Board";
130 #elif defined(CONFIG_PMC_MSP7120_GW)
131 return "PMC-Sierra MSP7120 Residential Gateway";
132 #elif defined(CONFIG_PMC_MSP7120_FPGA)
133 return "PMC-Sierra MSP7120 FPGA";
134 #else
135 #error "What is the type of *your* MSP?"
136 #endif
139 int get_ethernet_addr(char *ethaddr_name, char *ethernet_addr)
141 char *ethaddr_str;
143 ethaddr_str = prom_getenv(ethaddr_name);
144 if (!ethaddr_str) {
145 printk(KERN_WARNING "%s not set in boot prom\n", ethaddr_name);
146 return -1;
149 if (str2eaddr(ethernet_addr, ethaddr_str) == -1) {
150 printk(KERN_WARNING "%s badly formatted-<%s>\n",
151 ethaddr_name, ethaddr_str);
152 return -1;
155 if (init_debug > 1) {
156 int i;
157 printk(KERN_DEBUG "get_ethernet_addr: for %s ", ethaddr_name);
158 for (i = 0; i < 5; i++)
159 printk(KERN_DEBUG "%02x:",
160 (unsigned char)*(ethernet_addr+i));
161 printk(KERN_DEBUG "%02x\n", *(ethernet_addr+i));
164 return 0;
166 EXPORT_SYMBOL(get_ethernet_addr);
168 static char *get_features(void)
170 char *feature = prom_getenv(FEATURES);
172 if (feature == NULL) {
173 /* default features based on MACHINE_TYPE */
174 feature = msp_default_features;
177 return feature;
180 static char test_feature(char c)
182 char *feature = get_features();
184 while (*feature) {
185 if (*feature++ == c)
186 return *feature;
187 feature++;
190 return FEATURE_NOEXIST;
193 unsigned long get_deviceid(void)
195 char *deviceid = prom_getenv(DEVICEID);
197 if (deviceid == NULL)
198 return *DEV_ID_REG;
199 else
200 return str2hex(deviceid);
203 char identify_pci(void)
205 return test_feature(PCI_KEY);
207 EXPORT_SYMBOL(identify_pci);
209 char identify_pcimux(void)
211 return test_feature(PCIMUX_KEY);
214 char identify_sec(void)
216 return test_feature(SEC_KEY);
218 EXPORT_SYMBOL(identify_sec);
220 char identify_spad(void)
222 return test_feature(SPAD_KEY);
224 EXPORT_SYMBOL(identify_spad);
226 char identify_tdm(void)
228 return test_feature(TDM_KEY);
230 EXPORT_SYMBOL(identify_tdm);
232 char identify_zsp(void)
234 return test_feature(ZSP_KEY);
236 EXPORT_SYMBOL(identify_zsp);
238 static char identify_enetfeature(char key, unsigned long interface_num)
240 char *feature = get_features();
242 while (*feature) {
243 if (*feature++ == key && interface_num-- == 0)
244 return *feature;
245 feature++;
248 return FEATURE_NOEXIST;
251 char identify_enet(unsigned long interface_num)
253 return identify_enetfeature(ENET_KEY, interface_num);
255 EXPORT_SYMBOL(identify_enet);
257 char identify_enetTxD(unsigned long interface_num)
259 return identify_enetfeature(ENETTXD_KEY, interface_num);
261 EXPORT_SYMBOL(identify_enetTxD);
263 unsigned long identify_family(void)
265 unsigned long deviceid;
267 deviceid = get_deviceid();
269 return deviceid & CPU_DEVID_FAMILY;
271 EXPORT_SYMBOL(identify_family);
273 unsigned long identify_revision(void)
275 unsigned long deviceid;
277 deviceid = get_deviceid();
279 return deviceid & CPU_DEVID_REVISION;
281 EXPORT_SYMBOL(identify_revision);
283 /* PROM environment functions */
284 char *prom_getenv(char *env_name)
287 * Return a pointer to the given environment variable. prom_envp
288 * points to a null terminated array of pointers to variables.
289 * Environment variables are stored in the form of "memsize=64"
292 char **var = prom_envp;
293 int i = strlen(env_name);
295 while (*var) {
296 if (strncmp(env_name, *var, i) == 0) {
297 return (*var + strlen(env_name) + 1);
299 var++;
302 return NULL;
305 /* PROM commandline functions */
306 char *prom_getcmdline(void)
308 return &(arcs_cmdline[0]);
310 EXPORT_SYMBOL(prom_getcmdline);
312 void __init prom_init_cmdline(void)
314 char *cp;
315 int actr;
317 actr = 1; /* Always ignore argv[0] */
319 cp = &(arcs_cmdline[0]);
320 while (actr < prom_argc) {
321 strcpy(cp, prom_argv[actr]);
322 cp += strlen(prom_argv[actr]);
323 *cp++ = ' ';
324 actr++;
326 if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
327 --cp;
328 *cp = '\0';
331 /* memory allocation functions */
332 static int __init prom_memtype_classify(unsigned int type)
334 switch (type) {
335 case yamon_free:
336 return BOOT_MEM_RAM;
337 case yamon_prom:
338 return BOOT_MEM_ROM_DATA;
339 default:
340 return BOOT_MEM_RESERVED;
344 void __init prom_meminit(void)
346 struct prom_pmemblock *p;
348 p = prom_getmdesc();
350 while (p->size) {
351 long type;
352 unsigned long base, size;
354 type = prom_memtype_classify(p->type);
355 base = p->base;
356 size = p->size;
358 add_memory_region(base, size, type);
359 p++;
363 void __init prom_free_prom_memory(void)
365 int argc;
366 char **argv;
367 char **envp;
368 char *ptr;
369 int len = 0;
370 int i;
371 unsigned long addr;
374 * preserve environment variables and command line from pmon/bbload
375 * first preserve the command line
377 for (argc = 0; argc < prom_argc; argc++) {
378 len += sizeof(char *); /* length of pointer */
379 len += strlen(prom_argv[argc]) + 1; /* length of string */
381 len += sizeof(char *); /* plus length of null pointer */
383 argv = kmalloc(len, GFP_KERNEL);
384 ptr = (char *) &argv[prom_argc + 1]; /* strings follow array */
386 for (argc = 0; argc < prom_argc; argc++) {
387 argv[argc] = ptr;
388 strcpy(ptr, prom_argv[argc]);
389 ptr += strlen(prom_argv[argc]) + 1;
391 argv[prom_argc] = NULL; /* end array with null pointer */
392 prom_argv = argv;
394 /* next preserve the environment variables */
395 len = 0;
396 i = 0;
397 for (envp = prom_envp; *envp != NULL; envp++) {
398 i++; /* count number of environment variables */
399 len += sizeof(char *); /* length of pointer */
400 len += strlen(*envp) + 1; /* length of string */
402 len += sizeof(char *); /* plus length of null pointer */
404 envp = kmalloc(len, GFP_KERNEL);
405 ptr = (char *) &envp[i+1];
407 for (argc = 0; argc < i; argc++) {
408 envp[argc] = ptr;
409 strcpy(ptr, prom_envp[argc]);
410 ptr += strlen(prom_envp[argc]) + 1;
412 envp[i] = NULL; /* end array with null pointer */
413 prom_envp = envp;
415 for (i = 0; i < boot_mem_map.nr_map; i++) {
416 if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
417 continue;
419 addr = boot_mem_map.map[i].addr;
420 free_init_pages("prom memory",
421 addr, addr + boot_mem_map.map[i].size);
425 struct prom_pmemblock *__init prom_getmdesc(void)
427 static char memsz_env[] __initdata = "memsize";
428 static char heaptop_env[] __initdata = "heaptop";
429 char *str;
430 unsigned int memsize;
431 unsigned int heaptop;
432 int i;
434 str = prom_getenv(memsz_env);
435 if (!str) {
436 ppfinit("memsize not set in boot prom, "
437 "set to default (32Mb)\n");
438 memsize = 0x02000000;
439 } else {
440 memsize = simple_strtol(str, NULL, 0);
442 if (memsize == 0) {
443 /* if memsize is a bad size, use reasonable default */
444 memsize = 0x02000000;
447 /* convert to physical address (removing caching bits, etc) */
448 memsize = CPHYSADDR(memsize);
451 str = prom_getenv(heaptop_env);
452 if (!str) {
453 heaptop = CPHYSADDR((u32)&_text);
454 ppfinit("heaptop not set in boot prom, "
455 "set to default 0x%08x\n", heaptop);
456 } else {
457 heaptop = simple_strtol(str, NULL, 16);
458 if (heaptop == 0) {
459 /* heaptop conversion bad, might have 0xValue */
460 heaptop = simple_strtol(str, NULL, 0);
462 if (heaptop == 0) {
463 /* heaptop still bad, use reasonable default */
464 heaptop = CPHYSADDR((u32)&_text);
468 /* convert to physical address (removing caching bits, etc) */
469 heaptop = CPHYSADDR((u32)heaptop);
472 /* the base region */
473 i = 0;
474 mdesc[i].type = BOOT_MEM_RESERVED;
475 mdesc[i].base = 0x00000000;
476 mdesc[i].size = PAGE_ALIGN(0x300 + 0x80);
477 /* jtag interrupt vector + sizeof vector */
479 /* PMON data */
480 if (heaptop > mdesc[i].base + mdesc[i].size) {
481 i++; /* 1 */
482 mdesc[i].type = BOOT_MEM_ROM_DATA;
483 mdesc[i].base = mdesc[i-1].base + mdesc[i-1].size;
484 mdesc[i].size = heaptop - mdesc[i].base;
487 /* end of PMON data to start of kernel -- probably zero .. */
488 if (heaptop != CPHYSADDR((u32)_text)) {
489 i++; /* 2 */
490 mdesc[i].type = BOOT_MEM_RAM;
491 mdesc[i].base = heaptop;
492 mdesc[i].size = CPHYSADDR((u32)_text) - mdesc[i].base;
495 /* kernel proper */
496 i++; /* 3 */
497 mdesc[i].type = BOOT_MEM_RESERVED;
498 mdesc[i].base = CPHYSADDR((u32)_text);
499 mdesc[i].size = CPHYSADDR(PAGE_ALIGN((u32)_end)) - mdesc[i].base;
501 /* Remainder of RAM -- under memsize */
502 i++; /* 5 */
503 mdesc[i].type = yamon_free;
504 mdesc[i].base = mdesc[i-1].base + mdesc[i-1].size;
505 mdesc[i].size = memsize - mdesc[i].base;
507 return &mdesc[0];