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