5c8414a7b69506f5dd909f362dbab9bf5d870aa6
[openwrt/staging/dedeckeh.git] / target / linux / ramips / patches-3.14 / 0005-MIPS-ralink-add-illegal-access-driver.patch
1 From 60999174904c731e55992a4087999bbd4e5f2051 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 05/57] MIPS: ralink: add illegal access driver
5
6 these SoCs have a special irq that fires upon an illegal memmory access.
7
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 ---
10 arch/mips/ralink/Makefile | 2 +
11 arch/mips/ralink/ill_acc.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 89 insertions(+)
13 create mode 100644 arch/mips/ralink/ill_acc.c
14
15 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
16 index 584a8d9..fc57c16 100644
17 --- a/arch/mips/ralink/Makefile
18 +++ b/arch/mips/ralink/Makefile
19 @@ -10,6 +10,8 @@ obj-y := prom.o of.o reset.o clk.o irq.o timer.o
20
21 obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o
22
23 +obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o
24 +
25 obj-$(CONFIG_SOC_RT288X) += rt288x.o
26 obj-$(CONFIG_SOC_RT305X) += rt305x.o
27 obj-$(CONFIG_SOC_RT3883) += rt3883.o
28 diff --git a/arch/mips/ralink/ill_acc.c b/arch/mips/ralink/ill_acc.c
29 new file mode 100644
30 index 0000000..4a3f696
31 --- /dev/null
32 +++ b/arch/mips/ralink/ill_acc.c
33 @@ -0,0 +1,87 @@
34 +/*
35 + * This program is free software; you can redistribute it and/or modify it
36 + * under the terms of the GNU General Public License version 2 as published
37 + * by the Free Software Foundation.
38 + *
39 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
40 + */
41 +
42 +#include <linux/interrupt.h>
43 +#include <linux/of_platform.h>
44 +#include <linux/of_irq.h>
45 +
46 +#include <asm/mach-ralink/ralink_regs.h>
47 +
48 +#define REG_ILL_ACC_ADDR 0x10
49 +#define REG_ILL_ACC_TYPE 0x14
50 +
51 +#define ILL_INT_STATUS BIT(31)
52 +#define ILL_ACC_WRITE BIT(30)
53 +#define ILL_ACC_LEN_M 0xff
54 +#define ILL_ACC_OFF_M 0xf
55 +#define ILL_ACC_OFF_S 16
56 +#define ILL_ACC_ID_M 0x7
57 +#define ILL_ACC_ID_S 8
58 +
59 +#define DRV_NAME "ill_acc"
60 +
61 +static const char *ill_acc_ids[] = {
62 + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
63 +};
64 +
65 +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
66 +{
67 + struct device *dev = (struct device *) _priv;
68 + u32 addr = rt_memc_r32(REG_ILL_ACC_ADDR);
69 + u32 type = rt_memc_r32(REG_ILL_ACC_TYPE);
70 +
71 + dev_err(dev, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
72 + (type & ILL_ACC_WRITE) ? ("write") : ("read"),
73 + ill_acc_ids[(type >> ILL_ACC_ID_S) & ILL_ACC_ID_M],
74 + addr, (type >> ILL_ACC_OFF_S) & ILL_ACC_OFF_M,
75 + type & ILL_ACC_LEN_M);
76 +
77 + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
78 +
79 + return IRQ_HANDLED;
80 +}
81 +
82 +static int __init ill_acc_of_setup(void)
83 +{
84 + struct platform_device *pdev;
85 + struct device_node *np;
86 + int irq;
87 +
88 + /* somehow this driver breaks on RT5350 */
89 + if (of_machine_is_compatible("ralink,rt5350-soc"))
90 + return -EINVAL;
91 +
92 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
93 + if (!np)
94 + return -EINVAL;
95 +
96 + pdev = of_find_device_by_node(np);
97 + if (!pdev) {
98 + pr_err("%s: failed to lookup pdev\n", np->name);
99 + return -EINVAL;
100 + }
101 +
102 + irq = irq_of_parse_and_map(np, 0);
103 + if (!irq) {
104 + dev_err(&pdev->dev, "failed to get irq\n");
105 + return -EINVAL;
106 + }
107 +
108 + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
109 + dev_err(&pdev->dev, "failed to request irq\n");
110 + return -EINVAL;
111 + }
112 +
113 + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
114 +
115 + dev_info(&pdev->dev, "irq registered\n");
116 +
117 + return 0;
118 +}
119 +
120 +arch_initcall(ill_acc_of_setup);
121 --
122 1.7.10.4
123