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