2 * Ralink SoC specific prom routines
4 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/string.h>
15 #include <asm/bootinfo.h>
16 #include <asm/addrspace.h>
18 #include <asm/mach-ralink/common.h>
19 #include <asm/mach-ralink/machine.h>
20 #include <ralink_soc.h>
24 enum ramips_mach_type mach_type
;
27 static struct board_rec boards
[] __initdata
= {
30 .mach_type
= RAMIPS_MACH_RT_N15
,
32 .name
= "DIR-300-revB",
33 .mach_type
= RAMIPS_MACH_DIR_300_REVB
,
36 .mach_type
= RAMIPS_MACH_V22RW_2X2
,
39 .mach_type
= RAMIPS_MACH_WHR_G300N
,
42 .mach_type
= RAMIPS_MACH_FONERA20N
,
46 static inline void *to_ram_addr(void *addr
)
50 base
= KSEG0ADDR(RALINK_SOC_SDRAM_BASE
);
51 if (((u32
) addr
> base
) &&
52 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
55 base
= KSEG1ADDR(RALINK_SOC_SDRAM_BASE
);
56 if (((u32
) addr
> base
) &&
57 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
60 /* some U-Boot variants uses physical addresses */
61 base
= RALINK_SOC_SDRAM_BASE
;
62 if (((u32
) addr
> base
) &&
63 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
64 return (void *)KSEG0ADDR(addr
);
69 static void __init
prom_append_cmdline(const char *name
,
74 snprintf(buf
, sizeof(buf
), " %s=%s", name
, value
);
75 strlcat(arcs_cmdline
, buf
, sizeof(arcs_cmdline
));
78 #ifdef CONFIG_IMAGE_CMDLINE_HACK
79 extern char __image_cmdline
[];
81 static int __init
use_image_cmdline(void)
83 char *p
= __image_cmdline
;
95 strlcpy(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
97 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
98 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
104 static int inline use_image_cmdline(void) { return 0; }
107 static __init
void prom_init_cmdline(int argc
, char **argv
)
111 if (use_image_cmdline())
115 printk(KERN_DEBUG
"argv=%p is invalid, skipping\n",
120 for (i
= 0; i
< argc
; i
++) {
121 char *p
= to_ram_addr(argv
[i
]);
125 "argv[%d]=%p is invalid, skipping\n",
130 printk(KERN_DEBUG
"argv[%d]: %s\n", i
, p
);
131 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
132 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
136 static __init
char *prom_append_env(char **env
, const char *envname
)
138 #define PROM_MAX_ENVS 256
139 int len
= strlen(envname
);
143 printk(KERN_DEBUG
"env=%p is not in RAM, skipping\n",
148 for (i
= 0; i
< PROM_MAX_ENVS
; i
++) {
149 char *p
= to_ram_addr(env
[i
]);
154 printk(KERN_DEBUG
"env[%d]: %s\n", i
, p
);
155 if (strncmp(envname
, p
, len
) == 0 && p
[len
] == '=')
156 prom_append_cmdline(envname
, p
+ len
+ 1);
163 static __init
int ramips_board_setup(char *name
)
167 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
168 if (strcmp(name
, boards
[i
].name
) == 0) {
169 ramips_mach
= boards
[i
].mach_type
;
175 __setup("board=", ramips_board_setup
);
177 void __init
prom_init(void)
184 "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
185 (unsigned int)fw_arg0
, (unsigned int)fw_arg1
,
186 (unsigned int)fw_arg2
, (unsigned int)fw_arg3
);
189 argv
= to_ram_addr((void *)fw_arg1
);
190 prom_init_cmdline(argc
, argv
);
192 envp
= to_ram_addr((void *)fw_arg2
);
193 prom_append_env(envp
, "board");
194 prom_append_env(envp
, "ethaddr");
197 void __init
prom_free_prom_memory(void)
199 /* We do not have to prom memory to free */