highbank_l2_edac.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_core.h"
  24. #include "edac_module.h"
  25. #define SR_CLR_SB_ECC_INTR 0x0
  26. #define SR_CLR_DB_ECC_INTR 0x4
  27. struct hb_l2_drvdata {
  28. void __iomem *base;
  29. int sb_irq;
  30. int db_irq;
  31. };
  32. static irqreturn_t highbank_l2_err_handler(int irq, void *dev_id)
  33. {
  34. struct edac_device_ctl_info *dci = dev_id;
  35. struct hb_l2_drvdata *drvdata = dci->pvt_info;
  36. if (irq == drvdata->sb_irq) {
  37. writel(1, drvdata->base + SR_CLR_SB_ECC_INTR);
  38. edac_device_handle_ce(dci, 0, 0, dci->ctl_name);
  39. }
  40. if (irq == drvdata->db_irq) {
  41. writel(1, drvdata->base + SR_CLR_DB_ECC_INTR);
  42. edac_device_handle_ue(dci, 0, 0, dci->ctl_name);
  43. }
  44. return IRQ_HANDLED;
  45. }
  46. static const struct of_device_id hb_l2_err_of_match[] = {
  47. { .compatible = "calxeda,hb-sregs-l2-ecc", },
  48. {},
  49. };
  50. MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
  51. static int highbank_l2_err_probe(struct platform_device *pdev)
  52. {
  53. const struct of_device_id *id;
  54. struct edac_device_ctl_info *dci;
  55. struct hb_l2_drvdata *drvdata;
  56. struct resource *r;
  57. int res = 0;
  58. dci = edac_device_alloc_ctl_info(sizeof(*drvdata), "cpu",
  59. 1, "L", 1, 2, NULL, 0, 0);
  60. if (!dci)
  61. return -ENOMEM;
  62. drvdata = dci->pvt_info;
  63. dci->dev = &pdev->dev;
  64. platform_set_drvdata(pdev, dci);
  65. if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
  66. return -ENOMEM;
  67. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  68. if (!r) {
  69. dev_err(&pdev->dev, "Unable to get mem resource\n");
  70. res = -ENODEV;
  71. goto err;
  72. }
  73. if (!devm_request_mem_region(&pdev->dev, r->start,
  74. resource_size(r), dev_name(&pdev->dev))) {
  75. dev_err(&pdev->dev, "Error while requesting mem region\n");
  76. res = -EBUSY;
  77. goto err;
  78. }
  79. drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
  80. if (!drvdata->base) {
  81. dev_err(&pdev->dev, "Unable to map regs\n");
  82. res = -ENOMEM;
  83. goto err;
  84. }
  85. id = of_match_device(hb_l2_err_of_match, &pdev->dev);
  86. dci->mod_name = pdev->dev.driver->name;
  87. dci->ctl_name = id ? id->compatible : "unknown";
  88. dci->dev_name = dev_name(&pdev->dev);
  89. if (edac_device_add_device(dci))
  90. goto err;
  91. drvdata->db_irq = platform_get_irq(pdev, 0);
  92. res = devm_request_irq(&pdev->dev, drvdata->db_irq,
  93. highbank_l2_err_handler,
  94. 0, dev_name(&pdev->dev), dci);
  95. if (res < 0)
  96. goto err2;
  97. drvdata->sb_irq = platform_get_irq(pdev, 1);
  98. res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
  99. highbank_l2_err_handler,
  100. 0, dev_name(&pdev->dev), dci);
  101. if (res < 0)
  102. goto err2;
  103. devres_close_group(&pdev->dev, NULL);
  104. return 0;
  105. err2:
  106. edac_device_del_device(&pdev->dev);
  107. err:
  108. devres_release_group(&pdev->dev, NULL);
  109. edac_device_free_ctl_info(dci);
  110. return res;
  111. }
  112. static int highbank_l2_err_remove(struct platform_device *pdev)
  113. {
  114. struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
  115. edac_device_del_device(&pdev->dev);
  116. edac_device_free_ctl_info(dci);
  117. return 0;
  118. }
  119. static struct platform_driver highbank_l2_edac_driver = {
  120. .probe = highbank_l2_err_probe,
  121. .remove = highbank_l2_err_remove,
  122. .driver = {
  123. .name = "hb_l2_edac",
  124. .of_match_table = hb_l2_err_of_match,
  125. },
  126. };
  127. module_platform_driver(highbank_l2_edac_driver);
  128. MODULE_LICENSE("GPL v2");
  129. MODULE_AUTHOR("Calxeda, Inc.");
  130. MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank L2 Cache");