2 * Ralink SoC specific prom routines
4 * Copyright (C) 2010 Joonas Lahtinen <joonas.lahtinen@gmail.com>
5 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
19 #include <asm/mach-ralink/common.h>
20 #include <asm/mach-ralink/machine.h>
21 #include <ralink_soc.h>
23 static inline void *to_ram_addr(void *addr
)
27 base
= KSEG0ADDR(RALINK_SOC_SDRAM_BASE
);
28 if (((u32
) addr
> base
) &&
29 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
32 base
= KSEG1ADDR(RALINK_SOC_SDRAM_BASE
);
33 if (((u32
) addr
> base
) &&
34 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
37 /* some U-Boot variants uses physical addresses */
38 base
= RALINK_SOC_SDRAM_BASE
;
39 if (((u32
) addr
> base
) &&
40 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
41 return (void *)KSEG0ADDR(addr
);
46 static void __init
prom_append_cmdline(const char *name
,
49 char buf
[COMMAND_LINE_SIZE
];
51 snprintf(buf
, sizeof(buf
), " %s=%s", name
, value
);
52 strlcat(arcs_cmdline
, buf
, sizeof(arcs_cmdline
));
55 #ifdef CONFIG_IMAGE_CMDLINE_HACK
56 extern char __image_cmdline
[];
58 static int __init
use_image_cmdline(void)
60 char *p
= __image_cmdline
;
72 strlcpy(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
74 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
75 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
81 static int inline use_image_cmdline(void) { return 0; }
84 static __init
void prom_init_cmdline(int argc
, char **argv
)
88 if (use_image_cmdline())
92 printk(KERN_DEBUG
"argv=%p is invalid, skipping\n",
97 for (i
= 0; i
< argc
; i
++) {
98 char *p
= to_ram_addr(argv
[i
]);
102 "argv[%d]=%p is invalid, skipping\n",
107 printk(KERN_DEBUG
"argv[%d]: %s\n", i
, p
);
108 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
109 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
113 static __init
char *prom_append_env(char **env
, const char *envname
)
115 #define PROM_MAX_ENVS 256
116 int len
= strlen(envname
);
120 printk(KERN_DEBUG
"env=%p is not in RAM, skipping\n",
125 for (i
= 0; i
< PROM_MAX_ENVS
; i
++) {
126 char *p
= to_ram_addr(env
[i
]);
131 printk(KERN_DEBUG
"env[%d]: %s\n", i
, p
);
132 if (strncmp(envname
, p
, len
) == 0 && p
[len
] == '=')
133 prom_append_cmdline(envname
, p
+ len
+ 1);
140 void __init
prom_init(void)
147 "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
148 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
149 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
152 argv
= to_ram_addr((void *)fw_arg1
);
153 prom_init_cmdline(argc
, argv
);
155 envp
= to_ram_addr((void *)fw_arg2
);
156 prom_append_env(envp
, "board");
157 prom_append_env(envp
, "ethaddr");
160 void __init
prom_free_prom_memory(void)
162 /* We do not have to prom memory to free */
This page took 0.051109 seconds and 5 git commands to generate.