Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.git] / arch / mips / kernel / mips_machine.c
1 /*
2  *  Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
3  *
4  *  This program is free software; you can redistribute it and/or modify it
5  *  under the terms of the GNU General Public License version 2 as published
6  *  by the Free Software Foundation.
7  *
8  */
9 #include <linux/mm.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12
13 #include <asm/mips_machine.h>
14
15 static struct mips_machine *mips_machine __initdata;
16 static char *mips_machine_name = "Unknown";
17
18 #define for_each_machine(mach) \
19         for ((mach) = (struct mips_machine *)&__mips_machines_start; \
20              (mach) && \
21              (unsigned long)(mach) < (unsigned long)&__mips_machines_end; \
22              (mach)++)
23
24 __init void mips_set_machine_name(const char *name)
25 {
26         char *p;
27
28         if (name == NULL)
29                 return;
30
31         p = kstrdup(name, GFP_KERNEL);
32         if (!p)
33                 pr_err("MIPS: no memory for machine_name\n");
34
35         mips_machine_name = p;
36 }
37
38 char *mips_get_machine_name(void)
39 {
40         return mips_machine_name;
41 }
42
43 __init int mips_machtype_setup(char *id)
44 {
45         struct mips_machine *mach;
46
47         for_each_machine(mach) {
48                 if (mach->mach_id == NULL)
49                         continue;
50
51                 if (strcmp(mach->mach_id, id) == 0) {
52                         mips_machtype = mach->mach_type;
53                         return 0;
54                 }
55         }
56
57         pr_err("MIPS: no machine found for id '%s', supported machines:\n", id);
58         pr_err("%-24s %s\n", "id", "name");
59         for_each_machine(mach)
60                 pr_err("%-24s %s\n", mach->mach_id, mach->mach_name);
61
62         return 1;
63 }
64
65 __setup("machtype=", mips_machtype_setup);
66
67 __init void mips_machine_setup(void)
68 {
69         struct mips_machine *mach;
70
71         for_each_machine(mach) {
72                 if (mips_machtype == mach->mach_type) {
73                         mips_machine = mach;
74                         break;
75                 }
76         }
77
78         if (!mips_machine)
79                 return;
80
81         mips_set_machine_name(mips_machine->mach_name);
82         pr_info("MIPS: machine is %s\n", mips_machine_name);
83
84         if (mips_machine->mach_setup)
85                 mips_machine->mach_setup();
86 }