a408e6928765c499217bbcf0d66958debd40cd63
[openwrt/svn-archive/archive.git] / target / linux / mcs814x / files-3.3 / arch / arm / mach-mcs814x / common.c
1 /*
2 * arch/arm/mach-mcs814x/common.c
3 *
4 * Core functions for Moschip MCS814x SoCs
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/gpio.h>
15
16 #include <asm/setup.h>
17 #include <asm/mach-types.h>
18 #include <asm/mach/arch.h>
19 #include <mach/hardware.h>
20 #include <mach/cpu.h>
21 #include <asm/pgtable.h>
22 #include <asm/mach/map.h>
23
24 static struct map_desc mcs814x_io_desc[] __initdata = {
25 {
26 .virtual = MCS814X_IO_BASE,
27 .pfn = __phys_to_pfn(MCS814X_IO_START),
28 .length = MCS814X_IO_SIZE,
29 .type = MT_DEVICE
30 },
31 };
32
33 #define SYSDBG_BS2 0x04
34 #define CPU_MODE_SHIFT 23
35 #define CPU_MODE_MASK 0x03
36
37 struct cpu_mode {
38 const char *name;
39 int gpio_start;
40 int gpio_end;
41 };
42
43 static const struct cpu_mode cpu_modes[] = {
44 {
45 .name = "I2S",
46 .gpio_start = 4,
47 .gpio_end = 8,
48 },
49 {
50 .name = "UART",
51 .gpio_start = 4,
52 .gpio_end = 9,
53 },
54 {
55 .name = "External MII",
56 .gpio_start = 0,
57 .gpio_end = 16,
58 },
59 {
60 .name = "Normal",
61 .gpio_start = -1,
62 .gpio_end = -1,
63 },
64 };
65
66 void __init mcs814x_init_machine(void)
67 {
68 u32 bs2, cpu_mode;
69 int gpio;
70
71 bs2 = __raw_readl(_CONFADDR_SYSDBG + SYSDBG_BS2);
72 cpu_mode = (bs2 >> CPU_MODE_SHIFT) & CPU_MODE_MASK;
73
74 pr_info("CPU mode: %s\n", cpu_modes[cpu_mode].name);
75
76 /* request the gpios since the pins are muxed for functionnality */
77 for (gpio = cpu_modes[cpu_mode].gpio_start;
78 gpio == cpu_modes[cpu_mode].gpio_end; gpio++) {
79 if (gpio != -1)
80 gpio_request(gpio, cpu_modes[cpu_mode].name);
81 }
82 }
83
84 void __init mcs814x_map_io(void)
85 {
86 iotable_init(mcs814x_io_desc, ARRAY_SIZE(mcs814x_io_desc));
87 }
88
89 void mcs814x_restart(char mode, const char *cmd)
90 {
91 __raw_writel(~(1 << 31), _CONFADDR_SYSDBG);
92 }