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