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
6 these SoCs have a special irq that fires upon an illegal memmory access.
8 Signed-off-by: John Crispin <blogic@openwrt.org>
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
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
21 obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o
23 +obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o
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
30 index 0000000..4a3f696
32 +++ b/arch/mips/ralink/ill_acc.c
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.
39 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
42 +#include <linux/interrupt.h>
43 +#include <linux/of_platform.h>
44 +#include <linux/of_irq.h>
46 +#include <asm/mach-ralink/ralink_regs.h>
48 +#define REG_ILL_ACC_ADDR 0x10
49 +#define REG_ILL_ACC_TYPE 0x14
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
59 +#define DRV_NAME "ill_acc"
61 +static const char *ill_acc_ids[] = {
62 + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
65 +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
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);
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);
77 + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
82 +static int __init ill_acc_of_setup(void)
84 + struct platform_device *pdev;
85 + struct device_node *np;
88 + /* somehow this driver breaks on RT5350 */
89 + if (of_machine_is_compatible("ralink,rt5350-soc"))
92 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
96 + pdev = of_find_device_by_node(np);
98 + pr_err("%s: failed to lookup pdev\n", np->name);
102 + irq = irq_of_parse_and_map(np, 0);
104 + dev_err(&pdev->dev, "failed to get irq\n");
108 + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
109 + dev_err(&pdev->dev, "failed to request irq\n");
113 + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
115 + dev_info(&pdev->dev, "irq registered\n");
120 +arch_initcall(ill_acc_of_setup);