highbank_l2_edac.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright 2011-2012 Calxeda, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/types.h>
  17. #include <linux/kernel.h>
  18. #include <linux/ctype.h>
  19. #include <linux/edac.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/of_platform.h>
  23. #include "edac_module.h"
  24. #define SR_CLR_SB_ECC_INTR 0x0
  25. #define SR_CLR_DB_ECC_INTR 0x4
  26. struct hb_l2_drvdata {
  27. void __iomem *base;
  28. int sb_irq;
  29. int db_irq;
  30. };
  31. static irqreturn_t highbank_l2_err_handler(int irq, void *dev_id)
  32. {
  33. struct edac_device_ctl_info *dci = dev_id;
  34. struct hb_l2_drvdata *drvdata = dci->pvt_info;
  35. if (irq == drvdata->sb_irq) {
  36. writel(1, drvdata->base + SR_CLR_SB_ECC_INTR);
  37. edac_device_handle_ce(dci, 0, 0, dci->ctl_name);
  38. }
  39. if (irq == drvdata->db_irq) {
  40. writel(1, drvdata->base + SR_CLR_DB_ECC_INTR);
  41. edac_device_handle_ue(dci, 0, 0, dci->ctl_name);
  42. }
  43. return IRQ_HANDLED;
  44. }
  45. static const struct of_device_id hb_l2_err_of_match[] = {
  46. { .compatible = "calxeda,hb-sregs-l2-ecc", },
  47. {},
  48. };
  49. MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
  50. static int highbank_l2_err_probe(struct platform_device *pdev)
  51. {
  52. const struct of_device_id *id;
  53. struct edac_device_ctl_info *dci;
  54. struct hb_l2_drvdata *drvdata;
  55. struct resource *r;
  56. int res = 0;
  57. dci = edac_device_alloc_ctl_info(sizeof(*drvdata), "cpu",
  58. 1, "L", 1, 2, NULL, 0, 0);
  59. if (!dci)
  60. return -ENOMEM;
  61. drvdata = dci->pvt_info;
  62. dci->dev = &pdev->dev;
  63. platform_set_drvdata(pdev, dci);
  64. if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
  65. return -ENOMEM;
  66. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  67. if (!r) {
  68. dev_err(&pdev->dev, "Unable to get mem resource\n");
  69. res = -ENODEV;
  70. goto err;
  71. }
  72. if (!devm_request_mem_region(&pdev->dev, r->start,
  73. resource_size(r), dev_name(&pdev->dev))) {
  74. dev_err(&pdev->dev, "Error while requesting mem region\n");
  75. res = -EBUSY;
  76. goto err;
  77. }
  78. drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
  79. if (!drvdata->base) {
  80. dev_err(&pdev->dev, "Unable to map regs\n");
  81. res = -ENOMEM;
  82. goto err;
  83. }
  84. id = of_match_device(hb_l2_err_of_match, &pdev->dev);
  85. dci->mod_name = pdev->dev.driver->name;
  86. dci->ctl_name = id ? id->compatible : "unknown";
  87. dci->dev_name = dev_name(&pdev->dev);
  88. if (edac_device_add_device(dci))
  89. goto err;
  90. drvdata->db_irq = platform_get_irq(pdev, 0);
  91. res = devm_request_irq(&pdev->dev, drvdata->db_irq,
  92. highbank_l2_err_handler,
  93. 0, dev_name(&pdev->dev), dci);
  94. if (res < 0)
  95. goto err2;
  96. drvdata->sb_irq = platform_get_irq(pdev, 1);
  97. res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
  98. highbank_l2_err_handler,
  99. 0, dev_name(&pdev->dev), dci);
  100. if (res < 0)
  101. goto err2;
  102. devres_close_group(&pdev->dev, NULL);
  103. return 0;
  104. err2:
  105. edac_device_del_device(&pdev->dev);
  106. err:
  107. devres_release_group(&pdev->dev, NULL);
  108. edac_device_free_ctl_info(dci);
  109. return res;
  110. }
  111. static int highbank_l2_err_remove(struct platform_device *pdev)
  112. {
  113. struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
  114. edac_device_del_device(&pdev->dev);
  115. edac_device_free_ctl_info(dci);
  116. return 0;
  117. }
  118. static struct platform_driver highbank_l2_edac_driver = {
  119. .probe = highbank_l2_err_probe,
  120. .remove = highbank_l2_err_remove,
  121. .driver = {
  122. .name = "hb_l2_edac",
  123. .of_match_table = hb_l2_err_of_match,
  124. },
  125. };
  126. module_platform_driver(highbank_l2_edac_driver);
  127. MODULE_LICENSE("GPL v2");
  128. MODULE_AUTHOR("Calxeda, Inc.");
  129. MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank L2 Cache");