2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
6 * Copyright (C) 2013 John Crispin <john@phrozen.org>
9 #include <linux/interrupt.h>
10 #include <linux/of_platform.h>
11 #include <linux/of_irq.h>
13 #include <asm/mach-ralink/ralink_regs.h>
15 #define REG_ILL_ACC_ADDR 0x10
16 #define REG_ILL_ACC_TYPE 0x14
18 #define ILL_INT_STATUS BIT(31)
19 #define ILL_ACC_WRITE BIT(30)
20 #define ILL_ACC_LEN_M 0xff
21 #define ILL_ACC_OFF_M 0xf
22 #define ILL_ACC_OFF_S 16
23 #define ILL_ACC_ID_M 0x7
24 #define ILL_ACC_ID_S 8
26 #define DRV_NAME "ill_acc"
28 static const char * const ill_acc_ids
[] = {
29 "cpu", "dma", "ppe", "pdma rx", "pdma tx", "pci/e", "wmac", "usb",
32 static irqreturn_t
ill_acc_irq_handler(int irq
, void *_priv
)
34 struct device
*dev
= (struct device
*) _priv
;
35 u32 addr
= rt_memc_r32(REG_ILL_ACC_ADDR
);
36 u32 type
= rt_memc_r32(REG_ILL_ACC_TYPE
);
38 dev_err(dev
, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
39 (type
& ILL_ACC_WRITE
) ? ("write") : ("read"),
40 ill_acc_ids
[(type
>> ILL_ACC_ID_S
) & ILL_ACC_ID_M
],
41 addr
, (type
>> ILL_ACC_OFF_S
) & ILL_ACC_OFF_M
,
42 type
& ILL_ACC_LEN_M
);
44 rt_memc_w32(ILL_INT_STATUS
, REG_ILL_ACC_TYPE
);
49 static int __init
ill_acc_of_setup(void)
51 struct platform_device
*pdev
;
52 struct device_node
*np
;
55 /* somehow this driver breaks on RT5350 */
56 if (of_machine_is_compatible("ralink,rt5350-soc"))
59 np
= of_find_compatible_node(NULL
, NULL
, "ralink,rt3050-memc");
63 pdev
= of_find_device_by_node(np
);
65 pr_err("%s: failed to lookup pdev\n", np
->name
);
69 irq
= irq_of_parse_and_map(np
, 0);
71 dev_err(&pdev
->dev
, "failed to get irq\n");
75 if (request_irq(irq
, ill_acc_irq_handler
, 0, "ill_acc", &pdev
->dev
)) {
76 dev_err(&pdev
->dev
, "failed to request irq\n");
80 rt_memc_w32(ILL_INT_STATUS
, REG_ILL_ACC_TYPE
);
82 dev_info(&pdev
->dev
, "irq registered\n");
87 arch_initcall(ill_acc_of_setup
);