2 * Ralink RT305x 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>
14 #include <asm/bootinfo.h>
16 #include <asm/mach-ralink/common.h>
17 #include <asm/mach-ralink/machine.h>
18 #include <asm/mach-ralink/rt305x.h>
19 #include <asm/mach-ralink/rt305x_regs.h>
23 enum ramips_mach_type mach_type;
26 static int rt305x_prom_argc __initdata;
27 static char **rt305x_prom_argv __initdata;
28 static char **rt305x_prom_envp __initdata;
30 static struct board_rec boards[] __initdata = {
33 .mach_type = RAMIPS_MACH_WHR_G300N,
37 static inline void *to_ram_addr(void *addr)
41 base = KSEG0ADDR(RT305X_SDRAM_BASE);
42 if (((u32) addr > base) &&
43 ((u32) addr < (base + RT305X_MEM_SIZE_MAX)))
46 base = KSEG1ADDR(RT305X_SDRAM_BASE);
47 if (((u32) addr > base) &&
48 ((u32) addr < (base + RT305X_MEM_SIZE_MAX)))
51 /* some U-Boot variants uses physical addresses */
52 base = RT305X_SDRAM_BASE;
53 if (((u32) addr > base) &&
54 ((u32) addr < (base + RT305X_MEM_SIZE_MAX)))
55 return (void *)KSEG0ADDR(addr);
60 static __init char *rt305x_prom_getargv(const char *name)
62 int len = strlen(name);
65 if (!rt305x_prom_argv) {
66 printk(KERN_DEBUG "argv=%p is invalid, skipping\n",
71 for (i = 0; i < rt305x_prom_argc; i++) {
72 char *argv = to_ram_addr(rt305x_prom_argv[i]);
76 "argv[%d]=%p is invalid, skipping\n",
77 i, rt305x_prom_argv[i]);
81 printk(KERN_DEBUG "argv[i]: %s\n", argv);
82 if (strncmp(name, argv, len) == 0 && (argv)[len] == '=')
83 return argv + len + 1;
89 static __init char *rt305x_prom_getenv(const char *envname)
91 int len = strlen(envname);
95 env = rt305x_prom_envp;
97 printk(KERN_DEBUG "envp=%p is not in RAM, skipping\n",
102 for (p = to_ram_addr(*env); p; env++) {
103 printk(KERN_DEBUG "env: %s\n", *env);
104 if (strncmp(envname, p, len) == 0 && (p)[len] == '=')
111 static __init void find_board_byname(char *name)
115 for (i = 0; i < ARRAY_SIZE(boards); i++)
116 if (strcmp(name, boards[i].name) == 0) {
117 ramips_mach = boards[i].mach_type;
122 void __init prom_init(void)
127 "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
128 (unsigned int)fw_arg0, (unsigned int)fw_arg1,
129 (unsigned int)fw_arg2, (unsigned int)fw_arg3);
131 rt305x_prom_argc = fw_arg0;
132 rt305x_prom_argv = to_ram_addr((void *)fw_arg1);
133 rt305x_prom_envp = to_ram_addr((void *)fw_arg2);
135 p = rt305x_prom_getargv("board");
137 p = rt305x_prom_getenv("board");
139 find_board_byname(p);
142 void __init prom_free_prom_memory(void)
144 /* We do not have to prom memory to free */