Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee13...
[pandora-kernel.git] / arch / mips / philips / pnx8550 / common / prom.c
1 /*
2  *
3  * Per Hallsmark, per.hallsmark@mvista.com
4  *
5  * Based on jmr3927/common/prom.c
6  *
7  * 2004 (c) MontaVista Software, Inc. This file is licensed under the
8  * terms of the GNU General Public License version 2. This program is
9  * licensed "as is" without any warranty of any kind, whether express
10  * or implied.
11  */
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/string.h>
16 #include <linux/serial_pnx8xxx.h>
17
18 #include <asm/bootinfo.h>
19 #include <uart.h>
20
21 /* #define DEBUG_CMDLINE */
22
23 extern int prom_argc;
24 extern char **prom_argv, **prom_envp;
25
26 typedef struct
27 {
28     char *name;
29 /*    char *val; */
30 }t_env_var;
31
32
33 char * prom_getcmdline(void)
34 {
35         return &(arcs_cmdline[0]);
36 }
37
38 void  prom_init_cmdline(void)
39 {
40         char *cp;
41         int actr;
42
43         actr = 1; /* Always ignore argv[0] */
44
45         cp = &(arcs_cmdline[0]);
46         while(actr < prom_argc) {
47                 strcpy(cp, prom_argv[actr]);
48                 cp += strlen(prom_argv[actr]);
49                 *cp++ = ' ';
50                 actr++;
51         }
52         if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
53                 --cp;
54         *cp = '\0';
55 }
56
57 char *prom_getenv(char *envname)
58 {
59         /*
60          * Return a pointer to the given environment variable.
61          * Environment variables are stored in the form of "memsize=64".
62          */
63
64         t_env_var *env = (t_env_var *)prom_envp;
65         int i;
66
67         i = strlen(envname);
68
69         while(env->name) {
70                 if(strncmp(envname, env->name, i) == 0) {
71                         return(env->name + strlen(envname) + 1);
72                 }
73                 env++;
74         }
75         return(NULL);
76 }
77
78 inline unsigned char str2hexnum(unsigned char c)
79 {
80         if(c >= '0' && c <= '9')
81                 return c - '0';
82         if(c >= 'a' && c <= 'f')
83                 return c - 'a' + 10;
84         if(c >= 'A' && c <= 'F')
85                 return c - 'A' + 10;
86         return 0; /* foo */
87 }
88
89 inline void str2eaddr(unsigned char *ea, unsigned char *str)
90 {
91         int i;
92
93         for(i = 0; i < 6; i++) {
94                 unsigned char num;
95
96                 if((*str == '.') || (*str == ':'))
97                         str++;
98                 num = str2hexnum(*str++) << 4;
99                 num |= (str2hexnum(*str++));
100                 ea[i] = num;
101         }
102 }
103
104 int get_ethernet_addr(char *ethernet_addr)
105 {
106         char *ethaddr_str;
107
108         ethaddr_str = prom_getenv("ethaddr");
109         if (!ethaddr_str) {
110                 printk("ethaddr not set in boot prom\n");
111                 return -1;
112         }
113         str2eaddr(ethernet_addr, ethaddr_str);
114         return 0;
115 }
116
117 unsigned long __init prom_free_prom_memory(void)
118 {
119         return 0;
120 }
121
122 extern int pnx8550_console_port;
123
124 /* used by prom_printf */
125 void prom_putchar(char c)
126 {
127         if (pnx8550_console_port != -1) {
128                 /* Wait until FIFO not full */
129                 while( ((ip3106_fifo(UART_BASE, pnx8550_console_port) & PNX8XXX_UART_FIFO_TXFIFO) >> 16) >= 16)
130                         ;
131                 /* Send one char */
132                 ip3106_fifo(UART_BASE, pnx8550_console_port) = c;
133         }
134 }
135
136 EXPORT_SYMBOL(prom_getcmdline);
137 EXPORT_SYMBOL(get_ethernet_addr);
138 EXPORT_SYMBOL(str2eaddr);