Merge tag 'linux-kselftest-kunit-fixes-5.11-rc3' of git://git.kernel.org/pub/scm...
[linux/fpc-iii.git] / arch / mips / ralink / ill_acc.c
blobbdf53807d7c2b543cb0faa50f3f41aa565905ac6
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
4 * Copyright (C) 2013 John Crispin <john@phrozen.org>
5 */
7 #include <linux/interrupt.h>
8 #include <linux/of_platform.h>
9 #include <linux/of_irq.h>
11 #include <asm/mach-ralink/ralink_regs.h>
13 #define REG_ILL_ACC_ADDR 0x10
14 #define REG_ILL_ACC_TYPE 0x14
16 #define ILL_INT_STATUS BIT(31)
17 #define ILL_ACC_WRITE BIT(30)
18 #define ILL_ACC_LEN_M 0xff
19 #define ILL_ACC_OFF_M 0xf
20 #define ILL_ACC_OFF_S 16
21 #define ILL_ACC_ID_M 0x7
22 #define ILL_ACC_ID_S 8
24 #define DRV_NAME "ill_acc"
26 static const char * const ill_acc_ids[] = {
27 "cpu", "dma", "ppe", "pdma rx", "pdma tx", "pci/e", "wmac", "usb",
30 static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
32 struct device *dev = (struct device *) _priv;
33 u32 addr = rt_memc_r32(REG_ILL_ACC_ADDR);
34 u32 type = rt_memc_r32(REG_ILL_ACC_TYPE);
36 dev_err(dev, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
37 (type & ILL_ACC_WRITE) ? ("write") : ("read"),
38 ill_acc_ids[(type >> ILL_ACC_ID_S) & ILL_ACC_ID_M],
39 addr, (type >> ILL_ACC_OFF_S) & ILL_ACC_OFF_M,
40 type & ILL_ACC_LEN_M);
42 rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
44 return IRQ_HANDLED;
47 static int __init ill_acc_of_setup(void)
49 struct platform_device *pdev;
50 struct device_node *np;
51 int irq;
53 /* somehow this driver breaks on RT5350 */
54 if (of_machine_is_compatible("ralink,rt5350-soc"))
55 return -EINVAL;
57 np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
58 if (!np)
59 return -EINVAL;
61 pdev = of_find_device_by_node(np);
62 if (!pdev) {
63 pr_err("%pOFn: failed to lookup pdev\n", np);
64 return -EINVAL;
67 irq = irq_of_parse_and_map(np, 0);
68 if (!irq) {
69 dev_err(&pdev->dev, "failed to get irq\n");
70 put_device(&pdev->dev);
71 return -EINVAL;
74 if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
75 dev_err(&pdev->dev, "failed to request irq\n");
76 put_device(&pdev->dev);
77 return -EINVAL;
80 rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
82 dev_info(&pdev->dev, "irq registered\n");
84 return 0;
87 arch_initcall(ill_acc_of_setup);