summaryrefslogtreecommitdiffstats
path: root/target/linux/ramips/files-3.7/arch/mips/ralink/common
diff options
context:
space:
mode:
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2013-04-03 09:58:44 +0000
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2013-04-03 09:58:44 +0000
commited292123bc5c9a242273ad5e9251da05fc7377c6 (patch)
tree6438279d1866fffb0c66b568f2ee3e64f2aa89b0 /target/linux/ramips/files-3.7/arch/mips/ralink/common
parentcca3ae9bc47b833ac72cf2896d1ad4bd39d1033f (diff)
[ramips] move files to files-3.7
Signed-off-by: John Crispin <blogic@openwrt.org> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@36161 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/ramips/files-3.7/arch/mips/ralink/common')
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/Makefile13
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-buttons.c57
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-leds.c54
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/gpio.c113
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/intc.c99
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/prom.c168
-rw-r--r--target/linux/ramips/files-3.7/arch/mips/ralink/common/setup.c98
7 files changed, 602 insertions, 0 deletions
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/Makefile b/target/linux/ramips/files-3.7/arch/mips/ralink/common/Makefile
new file mode 100644
index 000000000..adab85f68
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/Makefile
@@ -0,0 +1,13 @@
+#
+# Makefile for the Ralink common stuff
+#
+# Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+
+obj-y := prom.o setup.o intc.o gpio.o
+
+obj-$(CONFIG_RALINK_DEV_GPIO_BUTTONS) += dev-gpio-buttons.o
+obj-$(CONFIG_RALINK_DEV_GPIO_LEDS) += dev-gpio-leds.o
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-buttons.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-buttons.c
new file mode 100644
index 000000000..75a2a1714
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-buttons.c
@@ -0,0 +1,57 @@
+/*
+ * Ralink SoC GPIO button support
+ *
+ * Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include "linux/init.h"
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <asm/mach-ralink/dev-gpio-buttons.h>
+
+void __init ramips_register_gpio_buttons(int id,
+ unsigned poll_interval,
+ unsigned nbuttons,
+ struct gpio_keys_button *buttons)
+{
+ struct platform_device *pdev;
+ struct gpio_keys_platform_data pdata;
+ struct gpio_keys_button *p;
+ int err;
+
+ p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
+ if (!p)
+ return;
+
+ memcpy(p, buttons, nbuttons * sizeof(*p));
+
+ pdev = platform_device_alloc("gpio-keys-polled", id);
+ if (!pdev)
+ goto err_free_buttons;
+
+ memset(&pdata, 0, sizeof(pdata));
+ pdata.poll_interval = poll_interval;
+ pdata.nbuttons = nbuttons;
+ pdata.buttons = p;
+
+ err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+ if (err)
+ goto err_put_pdev;
+
+ err = platform_device_add(pdev);
+ if (err)
+ goto err_put_pdev;
+
+ return;
+
+err_put_pdev:
+ platform_device_put(pdev);
+
+err_free_buttons:
+ kfree(p);
+}
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-leds.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-leds.c
new file mode 100644
index 000000000..a45a7cb77
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/dev-gpio-leds.c
@@ -0,0 +1,54 @@
+/*
+ * Ralink SoC GPIO LED device support
+ *
+ * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <asm/mach-ralink/dev-gpio-leds.h>
+
+void __init ramips_register_gpio_leds(int id, unsigned num_leds,
+ struct gpio_led *leds)
+{
+ struct platform_device *pdev;
+ struct gpio_led_platform_data pdata;
+ struct gpio_led *p;
+ int err;
+
+ p = kmalloc(num_leds * sizeof(*p), GFP_KERNEL);
+ if (!p)
+ return;
+
+ memcpy(p, leds, num_leds * sizeof(*p));
+
+ pdev = platform_device_alloc("leds-gpio", id);
+ if (!pdev)
+ goto err_free_leds;
+
+ memset(&pdata, 0, sizeof(pdata));
+ pdata.num_leds = num_leds;
+ pdata.leds = p;
+
+ err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
+ if (err)
+ goto err_put_pdev;
+
+ err = platform_device_add(pdev);
+ if (err)
+ goto err_put_pdev;
+
+ return;
+
+err_put_pdev:
+ platform_device_put(pdev);
+
+err_free_leds:
+ kfree(p);
+}
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/gpio.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/gpio.c
new file mode 100644
index 000000000..f03d145b6
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/gpio.c
@@ -0,0 +1,113 @@
+/*
+ * Ralink SoC specific GPIO support
+ *
+ * Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+
+#include <asm/mach-ralink/ramips_gpio.h>
+
+static inline struct ramips_gpio_chip *to_ramips_gpio(struct gpio_chip *chip)
+{
+ struct ramips_gpio_chip *rg;
+
+ rg = container_of(chip, struct ramips_gpio_chip, chip);
+ return rg;
+}
+
+static inline void ramips_gpio_wr(struct ramips_gpio_chip *rg, u8 reg, u32 val)
+{
+ __raw_writel(val, rg->regs_base + rg->regs[reg]);
+}
+
+static inline u32 ramips_gpio_rr(struct ramips_gpio_chip *rg, u8 reg)
+{
+ return __raw_readl(rg->regs_base + rg->regs[reg]);
+}
+
+static int ramips_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
+{
+ struct ramips_gpio_chip *rg = to_ramips_gpio(chip);
+ unsigned long flags;
+ u32 t;
+
+ spin_lock_irqsave(&rg->lock, flags);
+ t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DIR);
+ t &= ~(1 << offset);
+ ramips_gpio_wr(rg, RAMIPS_GPIO_REG_DIR, t);
+ spin_unlock_irqrestore(&rg->lock, flags);
+
+ return 0;
+}
+
+static int ramips_gpio_direction_output(struct gpio_chip *chip,
+ unsigned offset, int value)
+{
+ struct ramips_gpio_chip *rg = to_ramips_gpio(chip);
+ unsigned long flags;
+ u32 reg;
+ u32 t;
+
+ reg = (value) ? RAMIPS_GPIO_REG_SET : RAMIPS_GPIO_REG_RESET;
+
+ spin_lock_irqsave(&rg->lock, flags);
+ ramips_gpio_wr(rg, reg, 1 << offset);
+
+ t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DIR);
+ t |= 1 << offset;
+ ramips_gpio_wr(rg, RAMIPS_GPIO_REG_DIR, t);
+ spin_unlock_irqrestore(&rg->lock, flags);
+
+ return 0;
+}
+
+static void ramips_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
+{
+ struct ramips_gpio_chip *rg = to_ramips_gpio(chip);
+ u32 reg;
+
+ reg = (value) ? RAMIPS_GPIO_REG_SET : RAMIPS_GPIO_REG_RESET;
+ ramips_gpio_wr(rg, reg, 1 << offset);
+}
+
+static int ramips_gpio_get(struct gpio_chip *chip, unsigned offset)
+{
+ struct ramips_gpio_chip *rg = to_ramips_gpio(chip);
+ u32 t;
+
+ t = ramips_gpio_rr(rg, RAMIPS_GPIO_REG_DATA);
+ return !!(t & (1 << offset));
+}
+
+static __init void ramips_gpio_chip_add(struct ramips_gpio_chip *rg)
+{
+ spin_lock_init(&rg->lock);
+
+ rg->regs_base = ioremap(rg->map_base, rg->map_size);
+
+ rg->chip.direction_input = ramips_gpio_direction_input;
+ rg->chip.direction_output = ramips_gpio_direction_output;
+ rg->chip.get = ramips_gpio_get;
+ rg->chip.set = ramips_gpio_set;
+
+ /* set polarity to low for all lines */
+ ramips_gpio_wr(rg, RAMIPS_GPIO_REG_POL, 0);
+
+ gpiochip_add(&rg->chip);
+}
+
+__init int ramips_gpio_init(struct ramips_gpio_data *data)
+{
+ int i;
+
+ for (i = 0; i < data->num_chips; i++)
+ ramips_gpio_chip_add(&data->chips[i]);
+
+ return 0;
+}
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/intc.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/intc.c
new file mode 100644
index 000000000..65e42b423
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/intc.c
@@ -0,0 +1,99 @@
+/*
+ * Ralink SoC Interrupt controller routines
+ *
+ * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/bitops.h>
+
+#include <asm/irq_cpu.h>
+#include <asm/mipsregs.h>
+
+#include <asm/mach-ralink/common.h>
+
+/* INTC register offsets */
+#define INTC_REG_STATUS0 0x00
+#define INTC_REG_STATUS1 0x04
+#define INTC_REG_TYPE 0x20
+#define INTC_REG_RAW_STATUS 0x30
+#define INTC_REG_ENABLE 0x34
+#define INTC_REG_DISABLE 0x38
+
+#define INTC_INT_GLOBAL BIT(31)
+#define INTC_IRQ_COUNT 32
+
+static unsigned int ramips_intc_irq_base;
+static void __iomem *ramips_intc_base;
+
+static inline void ramips_intc_wr(u32 val, unsigned reg)
+{
+ __raw_writel(val, ramips_intc_base + reg);
+}
+
+static inline u32 ramips_intc_rr(unsigned reg)
+{
+ return __raw_readl(ramips_intc_base + reg);
+}
+
+static void ramips_intc_irq_unmask(struct irq_data *d)
+{
+ unsigned int irq = d->irq - ramips_intc_irq_base;
+
+ ramips_intc_wr((1 << irq), INTC_REG_ENABLE);
+}
+
+static void ramips_intc_irq_mask(struct irq_data *d)
+{
+ unsigned int irq = d->irq - ramips_intc_irq_base;
+
+ ramips_intc_wr((1 << irq), INTC_REG_DISABLE);
+}
+
+static struct irq_chip ramips_intc_irq_chip = {
+ .name = "INTC",
+ .irq_unmask = ramips_intc_irq_unmask,
+ .irq_mask = ramips_intc_irq_mask,
+ .irq_mask_ack = ramips_intc_irq_mask,
+};
+
+static struct irqaction ramips_intc_irqaction = {
+ .handler = no_action,
+ .name = "cascade [INTC]",
+};
+
+void __init ramips_intc_irq_init(unsigned intc_base, unsigned irq,
+ unsigned irq_base)
+{
+ int i;
+
+ ramips_intc_base = ioremap_nocache(intc_base, PAGE_SIZE);
+ ramips_intc_irq_base = irq_base;
+
+ /* disable all interrupts */
+ ramips_intc_wr(~0, INTC_REG_DISABLE);
+
+ /* route all INTC interrupts to MIPS HW0 interrupt */
+ ramips_intc_wr(0, INTC_REG_TYPE);
+
+ for (i = ramips_intc_irq_base;
+ i < ramips_intc_irq_base + INTC_IRQ_COUNT; i++)
+ irq_set_chip_and_handler(i, &ramips_intc_irq_chip,
+ handle_level_irq);
+
+ setup_irq(irq, &ramips_intc_irqaction);
+ ramips_intc_wr(INTC_INT_GLOBAL, INTC_REG_ENABLE);
+}
+
+u32 ramips_intc_get_status(void)
+{
+ return ramips_intc_rr(INTC_REG_STATUS0);
+}
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/prom.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/prom.c
new file mode 100644
index 000000000..26169d366
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/prom.c
@@ -0,0 +1,168 @@
+/*
+ * Ralink SoC specific prom routines
+ *
+ * Copyright (C) 2010 Joonas Lahtinen <joonas.lahtinen@gmail.com>
+ * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/string.h>
+
+#include <asm/bootinfo.h>
+#include <asm/addrspace.h>
+
+#include <asm/mach-ralink/common.h>
+#include <asm/mach-ralink/machine.h>
+
+unsigned long ramips_mem_base;
+unsigned long ramips_mem_size_min;
+unsigned long ramips_mem_size_max;
+
+static inline void *to_ram_addr(void *addr)
+{
+ u32 base;
+
+ base = KSEG0ADDR(ramips_mem_base);
+ if (((u32) addr > base) &&
+ ((u32) addr < (base + ramips_mem_size_max)))
+ return addr;
+
+ base = KSEG1ADDR(ramips_mem_base);
+ if (((u32) addr > base) &&
+ ((u32) addr < (base + ramips_mem_size_max)))
+ return addr;
+
+ /* some U-Boot variants uses physical addresses */
+ base = ramips_mem_base;
+ if (((u32) addr > base) &&
+ ((u32) addr < (base + ramips_mem_size_max)))
+ return (void *)KSEG0ADDR(addr);
+
+ return NULL;
+}
+
+static char ramips_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
+static void __init prom_append_cmdline(const char *name,
+ const char *value)
+{
+ snprintf(ramips_cmdline_buf, sizeof(ramips_cmdline_buf),
+ " %s=%s", name, value);
+ strlcat(arcs_cmdline, ramips_cmdline_buf, sizeof(arcs_cmdline));
+}
+
+#ifdef CONFIG_IMAGE_CMDLINE_HACK
+extern char __image_cmdline[];
+
+static int __init use_image_cmdline(void)
+{
+ char *p = __image_cmdline;
+ int replace = 0;
+
+ if (*p == '-') {
+ replace = 1;
+ p++;
+ }
+
+ if (*p == '\0')
+ return 0;
+
+ if (replace) {
+ strlcpy(arcs_cmdline, p, sizeof(arcs_cmdline));
+ } else {
+ strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
+ strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
+ }
+
+ return 1;
+}
+#else
+static int inline use_image_cmdline(void) { return 0; }
+#endif
+
+static __init void prom_init_cmdline(int argc, char **argv)
+{
+ int i;
+
+ if (use_image_cmdline())
+ return;
+
+ if (!argv) {
+ printk(KERN_DEBUG "argv=%p is invalid, skipping\n",
+ argv);
+ return;
+ }
+
+ for (i = 0; i < argc; i++) {
+ char *p = to_ram_addr(argv[i]);
+
+ if (!p) {
+ printk(KERN_DEBUG
+ "argv[%d]=%p is invalid, skipping\n",
+ i, argv[i]);
+ continue;
+ }
+
+ printk(KERN_DEBUG "argv[%d]: %s\n", i, p);
+ strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline));
+ strlcat(arcs_cmdline, p, sizeof(arcs_cmdline));
+ }
+}
+
+static __init char *prom_append_env(char **env, const char *envname)
+{
+#define PROM_MAX_ENVS 256
+ int len = strlen(envname);
+ int i;
+
+ if (!env) {
+ printk(KERN_DEBUG "env=%p is not in RAM, skipping\n",
+ env);
+ return NULL;
+ }
+
+ for (i = 0; i < PROM_MAX_ENVS; i++) {
+ char *p = to_ram_addr(env[i]);
+
+ if (!p)
+ break;
+
+ printk(KERN_DEBUG "env[%d]: %s\n", i, p);
+ if (strncmp(envname, p, len) == 0 && p[len] == '=')
+ prom_append_cmdline(envname, p + len + 1);
+ }
+
+ return NULL;
+#undef PROM_MAX_ENVS
+}
+
+void __init prom_init(void)
+{
+ int argc;
+ char **envp;
+ char **argv;
+
+ ramips_soc_prom_init();
+
+ printk(KERN_DEBUG
+ "prom: fw_arg0=%08x, fw_arg1=%08x, fw_arg2=%08x, fw_arg3=%08x\n",
+ (unsigned int)fw_arg0, (unsigned int)fw_arg1,
+ (unsigned int)fw_arg2, (unsigned int)fw_arg3);
+
+ argc = fw_arg0;
+ argv = to_ram_addr((void *)fw_arg1);
+ prom_init_cmdline(argc, argv);
+
+ envp = to_ram_addr((void *)fw_arg2);
+ prom_append_env(envp, "board");
+ prom_append_env(envp, "ethaddr");
+}
+
+void __init prom_free_prom_memory(void)
+{
+ /* We do not have to prom memory to free */
+}
diff --git a/target/linux/ramips/files-3.7/arch/mips/ralink/common/setup.c b/target/linux/ramips/files-3.7/arch/mips/ralink/common/setup.c
new file mode 100644
index 000000000..1af855e64
--- /dev/null
+++ b/target/linux/ramips/files-3.7/arch/mips/ralink/common/setup.c
@@ -0,0 +1,98 @@
+/*
+ * Ralink SoC common setup
+ *
+ * Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
+ * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/serial_8250.h>
+
+#include <asm/bootinfo.h>
+#include <asm/addrspace.h>
+
+#include <asm/mach-ralink/common.h>
+#include <asm/mach-ralink/machine.h>
+
+unsigned char ramips_sys_type[RAMIPS_SYS_TYPE_LEN];
+unsigned long (*ramips_get_mem_size)(void);
+
+const char *get_system_type(void)
+{
+ return ramips_sys_type;
+}
+
+static void __init detect_mem_size(void)
+{
+ unsigned long size;
+
+ if (ramips_get_mem_size) {
+ size = ramips_get_mem_size();
+ } else {
+ void *base;
+
+ base = (void *) KSEG1ADDR(detect_mem_size);
+ for (size = ramips_mem_size_min; size < ramips_mem_size_max;
+ size <<= 1 ) {
+ if (!memcmp(base, base + size, 1024))
+ break;
+ }
+ }
+
+ add_memory_region(ramips_mem_base, size, BOOT_MEM_RAM);
+}
+
+void __init ramips_early_serial_setup(int line, unsigned base, unsigned freq,
+ unsigned irq)
+{
+ struct uart_port p;
+ int err;
+
+ memset(&p, 0, sizeof(p));
+ p.flags = UPF_SKIP_TEST | UPF_FIXED_TYPE;
+ p.iotype = UPIO_AU;
+ p.uartclk = freq;
+ p.regshift = 2;
+ p.type = PORT_16550A;
+
+ p.mapbase = base;
+ p.membase = ioremap_nocache(p.mapbase, PAGE_SIZE);
+ p.line = line;
+ p.irq = irq;
+
+ err = early_serial_setup(&p);
+ if (err)
+ printk(KERN_ERR "early serial%d registration failed %d\n",
+ line, err);
+}
+
+void __init plat_mem_setup(void)
+{
+ set_io_port_base(KSEG1);
+
+ detect_mem_size();
+ ramips_soc_setup();
+}
+
+__setup("board=", mips_machtype_setup);
+
+static int __init ramips_machine_setup(void)
+{
+ mips_machine_setup();
+ return 0;
+}
+
+arch_initcall(ramips_machine_setup);
+
+static void __init ramips_generic_init(void)
+{
+}
+
+MIPS_MACHINE(RAMIPS_MACH_GENERIC, "Generic", "Generic Ralink board",
+ ramips_generic_init);