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 int ramips_prom_argc __initdata
;
28 static char **ramips_prom_argv __initdata
;
29 static char **ramips_prom_envp __initdata
;
31 static struct board_rec boards
[] __initdata
= {
34 .mach_type
= RAMIPS_MACH_RT_N15
,
36 .name
= "DIR-300-revB",
37 .mach_type
= RAMIPS_MACH_DIR_300_REVB
,
40 .mach_type
= RAMIPS_MACH_V22RW_2X2
,
43 .mach_type
= RAMIPS_MACH_WHR_G300N
,
46 .mach_type
= RAMIPS_MACH_FONERA20N
,
50 static inline void *to_ram_addr(void *addr
)
54 base
= KSEG0ADDR(RALINK_SOC_SDRAM_BASE
);
55 if (((u32
) addr
> base
) &&
56 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
59 base
= KSEG1ADDR(RALINK_SOC_SDRAM_BASE
);
60 if (((u32
) addr
> base
) &&
61 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
64 /* some U-Boot variants uses physical addresses */
65 base
= RALINK_SOC_SDRAM_BASE
;
66 if (((u32
) addr
> base
) &&
67 ((u32
) addr
< (base
+ RALINK_SOC_MEM_SIZE_MAX
)))
68 return (void *)KSEG0ADDR(addr
);
73 static __init
char *ramips_prom_getargv(const char *name
)
75 int len
= strlen(name
);
78 if (!ramips_prom_argv
) {
79 printk(KERN_DEBUG
"argv=%p is invalid, skipping\n",
84 for (i
= 0; i
< ramips_prom_argc
; i
++) {
85 char *argv
= to_ram_addr(ramips_prom_argv
[i
]);
89 "argv[%d]=%p is invalid, skipping\n",
90 i
, ramips_prom_argv
[i
]);
94 printk(KERN_DEBUG
"argv[%d]: %s\n", i
, argv
);
95 if (strncmp(name
, argv
, len
) == 0 && (argv
)[len
] == '=')
96 return argv
+ len
+ 1;
102 static __init
char *ramips_prom_getenv(const char *envname
)
104 #define PROM_MAX_ENVS 256
105 int len
= strlen(envname
);
109 env
= ramips_prom_envp
;
111 printk(KERN_DEBUG
"envp=%p is not in RAM, skipping\n",
116 for (i
= 0; i
< PROM_MAX_ENVS
; i
++) {
117 char *p
= to_ram_addr(env
[i
]);
122 printk(KERN_DEBUG
"env[%d]: %s\n", i
, p
);
123 if (strncmp(envname
, p
, len
) == 0 && p
[len
] == '=')
131 static __init
void find_board_byname(char *name
)
135 for (i
= 0; i
< ARRAY_SIZE(boards
); i
++)
136 if (strcmp(name
, boards
[i
].name
) == 0) {
137 ramips_mach
= boards
[i
].mach_type
;
142 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
);
151 ramips_prom_argc
= fw_arg0
;
152 ramips_prom_argv
= to_ram_addr((void *)fw_arg1
);
153 ramips_prom_envp
= to_ram_addr((void *)fw_arg2
);
155 p
= ramips_prom_getargv("board");
157 p
= ramips_prom_getenv("board");
159 find_board_byname(p
);
162 void __init
prom_free_prom_memory(void)
164 /* We do not have to prom memory to free */