| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 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> | 
| Vitaly Wool | 7009af8 | 2006-10-04 19:19:58 +0400 | [diff] [blame] | 16 | #include <linux/serial_pnx8xxx.h> | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 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 |  | 
| Ralf Baechle | cba2efb | 2011-06-22 10:13:17 +0100 | [diff] [blame] | 33 | char * __init prom_getcmdline(void) | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 34 | { | 
 | 35 | 	return &(arcs_cmdline[0]); | 
 | 36 | } | 
 | 37 |  | 
| Vitaly Wool | f0647a5 | 2006-12-08 11:40:35 +0300 | [diff] [blame] | 38 | void __init prom_init_cmdline(void) | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 39 | { | 
| Vitaly Wool | f0647a5 | 2006-12-08 11:40:35 +0300 | [diff] [blame] | 40 | 	int i; | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 41 |  | 
| Vitaly Wool | f0647a5 | 2006-12-08 11:40:35 +0300 | [diff] [blame] | 42 | 	arcs_cmdline[0] = '\0'; | 
 | 43 | 	for (i = 0; i < prom_argc; i++) { | 
 | 44 | 		strcat(arcs_cmdline, prom_argv[i]); | 
 | 45 | 		strcat(arcs_cmdline, " "); | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 46 | 	} | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 47 | } | 
 | 48 |  | 
 | 49 | char *prom_getenv(char *envname) | 
 | 50 | { | 
 | 51 | 	/* | 
 | 52 | 	 * Return a pointer to the given environment variable. | 
 | 53 | 	 * Environment variables are stored in the form of "memsize=64". | 
 | 54 | 	 */ | 
 | 55 |  | 
 | 56 | 	t_env_var *env = (t_env_var *)prom_envp; | 
 | 57 | 	int i; | 
 | 58 |  | 
 | 59 | 	i = strlen(envname); | 
 | 60 |  | 
 | 61 | 	while(env->name) { | 
 | 62 | 		if(strncmp(envname, env->name, i) == 0) { | 
 | 63 | 			return(env->name + strlen(envname) + 1); | 
 | 64 | 		} | 
 | 65 | 		env++; | 
 | 66 | 	} | 
 | 67 | 	return(NULL); | 
 | 68 | } | 
 | 69 |  | 
 | 70 | inline unsigned char str2hexnum(unsigned char c) | 
 | 71 | { | 
 | 72 | 	if(c >= '0' && c <= '9') | 
 | 73 | 		return c - '0'; | 
 | 74 | 	if(c >= 'a' && c <= 'f') | 
 | 75 | 		return c - 'a' + 10; | 
 | 76 | 	if(c >= 'A' && c <= 'F') | 
 | 77 | 		return c - 'A' + 10; | 
 | 78 | 	return 0; /* foo */ | 
 | 79 | } | 
 | 80 |  | 
 | 81 | inline void str2eaddr(unsigned char *ea, unsigned char *str) | 
 | 82 | { | 
 | 83 | 	int i; | 
 | 84 |  | 
 | 85 | 	for(i = 0; i < 6; i++) { | 
 | 86 | 		unsigned char num; | 
 | 87 |  | 
 | 88 | 		if((*str == '.') || (*str == ':')) | 
 | 89 | 			str++; | 
 | 90 | 		num = str2hexnum(*str++) << 4; | 
 | 91 | 		num |= (str2hexnum(*str++)); | 
 | 92 | 		ea[i] = num; | 
 | 93 | 	} | 
 | 94 | } | 
 | 95 |  | 
 | 96 | int get_ethernet_addr(char *ethernet_addr) | 
 | 97 | { | 
 | 98 |         char *ethaddr_str; | 
 | 99 |  | 
 | 100 |         ethaddr_str = prom_getenv("ethaddr"); | 
 | 101 | 	if (!ethaddr_str) { | 
 | 102 | 	        printk("ethaddr not set in boot prom\n"); | 
 | 103 | 		return -1; | 
 | 104 | 	} | 
 | 105 | 	str2eaddr(ethernet_addr, ethaddr_str); | 
 | 106 | 	return 0; | 
 | 107 | } | 
 | 108 |  | 
| Atsushi Nemoto | c44e8d5 | 2006-12-30 00:43:59 +0900 | [diff] [blame] | 109 | void __init prom_free_prom_memory(void) | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 110 | { | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 111 | } | 
 | 112 |  | 
 | 113 | extern int pnx8550_console_port; | 
 | 114 |  | 
| Ralf Baechle | 36a8853 | 2007-03-01 11:56:43 +0000 | [diff] [blame] | 115 | /* used by early printk */ | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 116 | void prom_putchar(char c) | 
 | 117 | { | 
 | 118 | 	if (pnx8550_console_port != -1) { | 
 | 119 | 		/* Wait until FIFO not full */ | 
| Vitaly Wool | 7009af8 | 2006-10-04 19:19:58 +0400 | [diff] [blame] | 120 | 		while( ((ip3106_fifo(UART_BASE, pnx8550_console_port) & PNX8XXX_UART_FIFO_TXFIFO) >> 16) >= 16) | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 121 | 			; | 
 | 122 | 		/* Send one char */ | 
 | 123 | 		ip3106_fifo(UART_BASE, pnx8550_console_port) = c; | 
 | 124 | 	} | 
 | 125 | } | 
 | 126 |  | 
| Pete Popov | bdf21b1 | 2005-07-14 17:47:57 +0000 | [diff] [blame] | 127 | EXPORT_SYMBOL(get_ethernet_addr); | 
 | 128 | EXPORT_SYMBOL(str2eaddr); |