2 * arch/arm/mach-mcs814x/common.c
4 * Core functions for Moschip MCS814x SoCs
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.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
14 #include <linux/gpio.h>
16 #include <linux/of_address.h>
17 #include <linux/reboot.h>
19 #include <asm/setup.h>
20 #include <asm/mach-types.h>
21 #include <asm/mach/arch.h>
22 #include <mach/mcs814x.h>
24 #include <asm/pgtable.h>
25 #include <asm/mach/map.h>
27 void __iomem *mcs814x_sysdbg_base;
29 static struct map_desc mcs814x_io_desc[] __initdata = {
31 .virtual = MCS814X_IO_BASE,
32 .pfn = __phys_to_pfn(MCS814X_IO_START),
33 .length = MCS814X_IO_SIZE,
44 static const struct cpu_mode cpu_modes[] = {
56 .name = "External MII",
67 static void mcs814x_eth_hardware_filter_set(u8 value)
71 reg = readl_relaxed(MCS814X_VIRT_BASE + MCS814X_DBGLED);
76 writel_relaxed(reg, MCS814X_VIRT_BASE + MCS814X_DBGLED);
79 static void mcs814x_eth_led_cfg_set(u8 cfg)
83 reg = readl_relaxed(mcs814x_sysdbg_base + SYSDBG_BS2);
86 writel_relaxed(reg, mcs814x_sysdbg_base + SYSDBG_BS2);
89 static void mcs814x_eth_buffer_shifting_set(u8 value)
93 reg = readb_relaxed(mcs814x_sysdbg_base + SYSDBG_SYSCTL_MAC);
97 reg &= ~BUF_SHIFT_BIT;
98 writeb_relaxed(reg, mcs814x_sysdbg_base + SYSDBG_SYSCTL_MAC);
101 static struct of_device_id mcs814x_eth_ids[] __initdata = {
102 { .compatible = "moschip,nuport-mac", },
106 /* Configure platform specific knobs based on ethernet device node
108 static void mcs814x_eth_init(void)
110 struct device_node *np;
111 const unsigned int *intspec;
113 np = of_find_matching_node(NULL, mcs814x_eth_ids);
117 /* hardware filter must always be enabled */
118 mcs814x_eth_hardware_filter_set(1);
120 intspec = of_get_property(np, "nuport-mac,buffer-shifting", NULL);
122 mcs814x_eth_buffer_shifting_set(0);
124 mcs814x_eth_buffer_shifting_set(1);
126 intspec = of_get_property(np, "nuport-mac,link-activity", NULL);
128 mcs814x_eth_led_cfg_set(be32_to_cpup(intspec));
133 void __init mcs814x_init_machine(void)
138 bs2 = readl_relaxed(mcs814x_sysdbg_base + SYSDBG_BS2);
139 cpu_mode = (bs2 >> CPU_MODE_SHIFT) & CPU_MODE_MASK;
141 pr_info("CPU mode: %s\n", cpu_modes[cpu_mode].name);
143 /* request the gpios since the pins are muxed for functionnality */
144 for (gpio = cpu_modes[cpu_mode].gpio_start;
145 gpio == cpu_modes[cpu_mode].gpio_end; gpio++) {
147 gpio_request(gpio, cpu_modes[cpu_mode].name);
153 void __init mcs814x_map_io(void)
155 iotable_init(mcs814x_io_desc, ARRAY_SIZE(mcs814x_io_desc));
157 mcs814x_sysdbg_base = ioremap(MCS814X_IO_START + MCS814X_SYSDBG,
158 MCS814X_SYSDBG_SIZE);
159 if (!mcs814x_sysdbg_base)
160 panic("unable to remap sysdbg base");
163 void mcs814x_restart(enum reboot_mode mode, const char *cmd)
165 writel_relaxed(~(1 << 31), mcs814x_sysdbg_base);