1 From 69a5834d0a90588578df9689530fc8f3ab8ef59a Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 16 May 2013 23:28:23 +0200
4 Subject: [PATCH 53/79] MIPS: ralink: add illegal access driver
6 Signed-off-by: John Crispin <blogic@openwrt.org>
8 arch/mips/ralink/Makefile | 2 +-
9 arch/mips/ralink/ill_acc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
10 2 files changed, 88 insertions(+), 1 deletion(-)
11 create mode 100644 arch/mips/ralink/ill_acc.c
13 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
14 index 5fa6129..55a5bfc 100644
15 --- a/arch/mips/ralink/Makefile
16 +++ b/arch/mips/ralink/Makefile
18 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
19 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
21 -obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
22 +obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o ill_acc.o
24 obj-$(CONFIG_SOC_RT288X) += rt288x.o
25 obj-$(CONFIG_SOC_RT305X) += rt305x.o
26 diff --git a/arch/mips/ralink/ill_acc.c b/arch/mips/ralink/ill_acc.c
28 index 0000000..4a3f696
30 +++ b/arch/mips/ralink/ill_acc.c
33 + * This program is free software; you can redistribute it and/or modify it
34 + * under the terms of the GNU General Public License version 2 as published
35 + * by the Free Software Foundation.
37 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
40 +#include <linux/interrupt.h>
41 +#include <linux/of_platform.h>
42 +#include <linux/of_irq.h>
44 +#include <asm/mach-ralink/ralink_regs.h>
46 +#define REG_ILL_ACC_ADDR 0x10
47 +#define REG_ILL_ACC_TYPE 0x14
49 +#define ILL_INT_STATUS BIT(31)
50 +#define ILL_ACC_WRITE BIT(30)
51 +#define ILL_ACC_LEN_M 0xff
52 +#define ILL_ACC_OFF_M 0xf
53 +#define ILL_ACC_OFF_S 16
54 +#define ILL_ACC_ID_M 0x7
55 +#define ILL_ACC_ID_S 8
57 +#define DRV_NAME "ill_acc"
59 +static const char *ill_acc_ids[] = {
60 + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
63 +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
65 + struct device *dev = (struct device *) _priv;
66 + u32 addr = rt_memc_r32(REG_ILL_ACC_ADDR);
67 + u32 type = rt_memc_r32(REG_ILL_ACC_TYPE);
69 + dev_err(dev, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
70 + (type & ILL_ACC_WRITE) ? ("write") : ("read"),
71 + ill_acc_ids[(type >> ILL_ACC_ID_S) & ILL_ACC_ID_M],
72 + addr, (type >> ILL_ACC_OFF_S) & ILL_ACC_OFF_M,
73 + type & ILL_ACC_LEN_M);
75 + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
80 +static int __init ill_acc_of_setup(void)
82 + struct platform_device *pdev;
83 + struct device_node *np;
86 + /* somehow this driver breaks on RT5350 */
87 + if (of_machine_is_compatible("ralink,rt5350-soc"))
90 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
94 + pdev = of_find_device_by_node(np);
96 + pr_err("%s: failed to lookup pdev\n", np->name);
100 + irq = irq_of_parse_and_map(np, 0);
102 + dev_err(&pdev->dev, "failed to get irq\n");
106 + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
107 + dev_err(&pdev->dev, "failed to request irq\n");
111 + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
113 + dev_info(&pdev->dev, "irq registered\n");
118 +arch_initcall(ill_acc_of_setup);