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 --- 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
19 obj-$(CONFIG_CLKEVT_RT3352) += cevt-rt3352.o
21 +obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o
23 obj-$(CONFIG_SOC_RT288X) += rt288x.o
24 obj-$(CONFIG_SOC_RT305X) += rt305x.o
25 obj-$(CONFIG_SOC_RT3883) += rt3883.o
27 +++ b/arch/mips/ralink/ill_acc.c
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.
34 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
37 +#include <linux/interrupt.h>
38 +#include <linux/of_platform.h>
39 +#include <linux/of_irq.h>
41 +#include <asm/mach-ralink/ralink_regs.h>
43 +#define REG_ILL_ACC_ADDR 0x10
44 +#define REG_ILL_ACC_TYPE 0x14
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
54 +#define DRV_NAME "ill_acc"
56 +static const char *ill_acc_ids[] = {
57 + "cpu", "dma", "ppe", "pdma rx","pdma tx", "pci/e", "wmac", "usb",
60 +static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
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);
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);
72 + rt_memc_w32(REG_ILL_ACC_TYPE, REG_ILL_ACC_TYPE);
77 +static int __init ill_acc_of_setup(void)
79 + struct platform_device *pdev;
80 + struct device_node *np;
83 + /* somehow this driver breaks on RT5350 */
84 + if (of_machine_is_compatible("ralink,rt5350-soc"))
87 + np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
91 + pdev = of_find_device_by_node(np);
93 + pr_err("%s: failed to lookup pdev\n", np->name);
97 + irq = irq_of_parse_and_map(np, 0);
99 + dev_err(&pdev->dev, "failed to get irq\n");
103 + if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
104 + dev_err(&pdev->dev, "failed to request irq\n");
108 + rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
110 + dev_info(&pdev->dev, "irq registered\n");
115 +arch_initcall(ill_acc_of_setup);