670b20052a9f79e03030d959dc17b7bf26597ada
[openwrt/svn-archive/archive.git] / target / linux / ramips / patches-3.9 / 0137-MIPS-ralink-add-illegal-access-driver.patch
1 From 0402961539c5a98f3e9eac439e03f89498d110a1 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 137/164] MIPS: ralink: add illegal access driver
5
6 Signed-off-by: John Crispin <blogic@openwrt.org>
7 ---
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
12
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
17 @@ -6,7 +6,7 @@
18 # Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
19 # Copyright (C) 2013 John Crispin <blogic@openwrt.org>
20
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
23
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
27 new file mode 100644
28 index 0000000..4a3f696
29 --- /dev/null
30 +++ b/arch/mips/ralink/ill_acc.c
31 @@ -0,0 +1,87 @@
32 +/*
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.
36 + *
37 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
38 + */
39 +
40 +#include <linux/interrupt.h>
41 +#include <linux/of_platform.h>
42 +#include <linux/of_irq.h>
43 +
44 +#include <asm/mach-ralink/ralink_regs.h>
45 +
46 +#define REG_ILL_ACC_ADDR 0x10
47 +#define REG_ILL_ACC_TYPE 0x14
48 +
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
56 +
57 +#define DRV_NAME "ill_acc"
58 +
59 +static const char *ill_acc_ids[] = {
60 + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
61 +};
62 +
63 +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
64 +{
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);
68 +
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);
74 +
75 + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
76 +
77 + return IRQ_HANDLED;
78 +}
79 +
80 +static int __init ill_acc_of_setup(void)
81 +{
82 + struct platform_device *pdev;
83 + struct device_node *np;
84 + int irq;
85 +
86 + /* somehow this driver breaks on RT5350 */
87 + if (of_machine_is_compatible("ralink,rt5350-soc"))
88 + return -EINVAL;
89 +
90 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
91 + if (!np)
92 + return -EINVAL;
93 +
94 + pdev = of_find_device_by_node(np);
95 + if (!pdev) {
96 + pr_err("%s: failed to lookup pdev\n", np->name);
97 + return -EINVAL;
98 + }
99 +
100 + irq = irq_of_parse_and_map(np, 0);
101 + if (!irq) {
102 + dev_err(&pdev->dev, "failed to get irq\n");
103 + return -EINVAL;
104 + }
105 +
106 + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
107 + dev_err(&pdev->dev, "failed to request irq\n");
108 + return -EINVAL;
109 + }
110 +
111 + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
112 +
113 + dev_info(&pdev->dev, "irq registered\n");
114 +
115 + return 0;
116 +}
117 +
118 +arch_initcall(ill_acc_of_setup);
119 --
120 1.7.10.4
121