ill_acc.c 2.0 KB

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