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