^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2013 John Crispin <john@phrozen.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/of_platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/mach-ralink/ralink_regs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define REG_ILL_ACC_ADDR 0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define REG_ILL_ACC_TYPE 0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define ILL_INT_STATUS BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ILL_ACC_WRITE BIT(30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define ILL_ACC_LEN_M 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define ILL_ACC_OFF_M 0xf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define ILL_ACC_OFF_S 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define ILL_ACC_ID_M 0x7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define ILL_ACC_ID_S 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DRV_NAME "ill_acc"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static const char * const ill_acc_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) "cpu", "dma", "ppe", "pdma rx", "pdma tx", "pci/e", "wmac", "usb",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static irqreturn_t ill_acc_irq_handler(int irq, void *_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct device *dev = (struct device *) _priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) u32 addr = rt_memc_r32(REG_ILL_ACC_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) u32 type = rt_memc_r32(REG_ILL_ACC_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) dev_err(dev, "illegal %s access from %s - addr:0x%08x offset:%d len:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) (type & ILL_ACC_WRITE) ? ("write") : ("read"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ill_acc_ids[(type >> ILL_ACC_ID_S) & ILL_ACC_ID_M],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) addr, (type >> ILL_ACC_OFF_S) & ILL_ACC_OFF_M,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) type & ILL_ACC_LEN_M);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static int __init ill_acc_of_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /* somehow this driver breaks on RT5350 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (of_machine_is_compatible("ralink,rt5350-soc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) np = of_find_compatible_node(NULL, NULL, "ralink,rt3050-memc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) pdev = of_find_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (!pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) pr_err("%pOFn: failed to lookup pdev\n", np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) irq = irq_of_parse_and_map(np, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) dev_err(&pdev->dev, "failed to get irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) put_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (request_irq(irq, ill_acc_irq_handler, 0, "ill_acc", &pdev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) dev_err(&pdev->dev, "failed to request irq\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) put_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) rt_memc_w32(ILL_INT_STATUS, REG_ILL_ACC_TYPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) dev_info(&pdev->dev, "irq registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) arch_initcall(ill_acc_of_setup);