e9926b3b348ce5a2a924d6d7e90d005a5f72e567
[openwrt/staging/wigyori.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 #include <linux/of.h>
16 #include <linux/of_address.h>
17
18 #include <asm/setup.h>
19 #include <asm/mach-types.h>
20 #include <asm/mach/arch.h>
21 #include <mach/mcs814x.h>
22 #include <mach/cpu.h>
23 #include <asm/pgtable.h>
24 #include <asm/mach/map.h>
25
26 static struct map_desc mcs814x_io_desc[] __initdata = {
27 {
28 .virtual = MCS814X_IO_BASE,
29 .pfn = __phys_to_pfn(MCS814X_IO_START),
30 .length = MCS814X_IO_SIZE,
31 .type = MT_DEVICE
32 },
33 };
34
35 struct cpu_mode {
36 const char *name;
37 int gpio_start;
38 int gpio_end;
39 };
40
41 static const struct cpu_mode cpu_modes[] = {
42 {
43 .name = "I2S",
44 .gpio_start = 4,
45 .gpio_end = 8,
46 },
47 {
48 .name = "UART",
49 .gpio_start = 4,
50 .gpio_end = 9,
51 },
52 {
53 .name = "External MII",
54 .gpio_start = 0,
55 .gpio_end = 16,
56 },
57 {
58 .name = "Normal",
59 .gpio_start = -1,
60 .gpio_end = -1,
61 },
62 };
63
64 static void mcs814x_eth_hardware_filter_set(u8 value)
65 {
66 u32 reg;
67
68 reg = __raw_readl(_CONFADDR_DBGLED);
69 if (value)
70 reg |= 0x80;
71 else
72 reg &= ~0x80;
73 __raw_writel(reg, _CONFADDR_DBGLED);
74 }
75
76 static void mcs814x_eth_led_cfg_set(u8 cfg)
77 {
78 u32 reg;
79
80 reg = __raw_readl(_CONFADDR_SYSDBG + SYSDBG_BS2);
81 reg &= ~LED_CFG_MASK;
82 reg |= cfg;
83 __raw_writel(reg, _CONFADDR_SYSDBG + SYSDBG_BS2);
84 }
85
86 static void mcs814x_eth_buffer_shifting_set(u8 value)
87 {
88 u8 reg;
89
90 reg = __raw_readb(_CONFADDR_SYSDBG + SYSDBG_SYSCTL_MAC);
91 if (value)
92 reg |= BUF_SHIFT_BIT;
93 else
94 reg &= ~BUF_SHIFT_BIT;
95 __raw_writeb(reg, _CONFADDR_SYSDBG + SYSDBG_SYSCTL_MAC);
96 }
97
98 static struct of_device_id mcs814x_eth_ids[] __initdata = {
99 { .compatible = "moschip,nuport-mac", },
100 { /* sentinel */ },
101 };
102
103 /* Configure platform specific knobs based on ethernet device node
104 * properties */
105 static void mcs814x_eth_init(void)
106 {
107 struct device_node *np;
108 const unsigned int *intspec;
109
110 np = of_find_matching_node(NULL, mcs814x_eth_ids);
111 if (!np)
112 return;
113
114 /* hardware filter must always be enabled */
115 mcs814x_eth_hardware_filter_set(1);
116
117 intspec = of_get_property(np, "nuport-mac,buffer-shifting", NULL);
118 if (!intspec)
119 mcs814x_eth_buffer_shifting_set(0);
120 else
121 mcs814x_eth_buffer_shifting_set(1);
122
123 intspec = of_get_property(np, "nuport-mac,link-activity", NULL);
124 if (intspec)
125 mcs814x_eth_led_cfg_set(be32_to_cpup(intspec));
126 }
127
128 void __init mcs814x_init_machine(void)
129 {
130 u32 bs2, cpu_mode;
131 int gpio;
132
133 bs2 = __raw_readl(_CONFADDR_SYSDBG + SYSDBG_BS2);
134 cpu_mode = (bs2 >> CPU_MODE_SHIFT) & CPU_MODE_MASK;
135
136 pr_info("CPU mode: %s\n", cpu_modes[cpu_mode].name);
137
138 /* request the gpios since the pins are muxed for functionnality */
139 for (gpio = cpu_modes[cpu_mode].gpio_start;
140 gpio == cpu_modes[cpu_mode].gpio_end; gpio++) {
141 if (gpio != -1)
142 gpio_request(gpio, cpu_modes[cpu_mode].name);
143 }
144
145 mcs814x_eth_init();
146 }
147
148 void __init mcs814x_map_io(void)
149 {
150 iotable_init(mcs814x_io_desc, ARRAY_SIZE(mcs814x_io_desc));
151 }
152
153 void mcs814x_restart(char mode, const char *cmd)
154 {
155 __raw_writel(~(1 << 31), _CONFADDR_SYSDBG);
156 }