highbank_l2_edac.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 int highbank_l2_err_probe(struct platform_device *pdev)
  47. {
  48. struct edac_device_ctl_info *dci;
  49. struct hb_l2_drvdata *drvdata;
  50. struct resource *r;
  51. int res = 0;
  52. dci = edac_device_alloc_ctl_info(sizeof(*drvdata), "cpu",
  53. 1, "L", 1, 2, NULL, 0, 0);
  54. if (!dci)
  55. return -ENOMEM;
  56. drvdata = dci->pvt_info;
  57. dci->dev = &pdev->dev;
  58. platform_set_drvdata(pdev, dci);
  59. if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
  60. return -ENOMEM;
  61. r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  62. if (!r) {
  63. dev_err(&pdev->dev, "Unable to get mem resource\n");
  64. res = -ENODEV;
  65. goto err;
  66. }
  67. if (!devm_request_mem_region(&pdev->dev, r->start,
  68. resource_size(r), dev_name(&pdev->dev))) {
  69. dev_err(&pdev->dev, "Error while requesting mem region\n");
  70. res = -EBUSY;
  71. goto err;
  72. }
  73. drvdata->base = devm_ioremap(&pdev->dev, r->start, resource_size(r));
  74. if (!drvdata->base) {
  75. dev_err(&pdev->dev, "Unable to map regs\n");
  76. res = -ENOMEM;
  77. goto err;
  78. }
  79. drvdata->db_irq = platform_get_irq(pdev, 0);
  80. res = devm_request_irq(&pdev->dev, drvdata->db_irq,
  81. highbank_l2_err_handler,
  82. 0, dev_name(&pdev->dev), dci);
  83. if (res < 0)
  84. goto err;
  85. drvdata->sb_irq = platform_get_irq(pdev, 1);
  86. res = devm_request_irq(&pdev->dev, drvdata->sb_irq,
  87. highbank_l2_err_handler,
  88. 0, dev_name(&pdev->dev), dci);
  89. if (res < 0)
  90. goto err;
  91. dci->mod_name = dev_name(&pdev->dev);
  92. dci->dev_name = dev_name(&pdev->dev);
  93. if (edac_device_add_device(dci))
  94. goto err;
  95. devres_close_group(&pdev->dev, NULL);
  96. return 0;
  97. err:
  98. devres_release_group(&pdev->dev, NULL);
  99. edac_device_free_ctl_info(dci);
  100. return res;
  101. }
  102. static int highbank_l2_err_remove(struct platform_device *pdev)
  103. {
  104. struct edac_device_ctl_info *dci = platform_get_drvdata(pdev);
  105. edac_device_del_device(&pdev->dev);
  106. edac_device_free_ctl_info(dci);
  107. return 0;
  108. }
  109. static const struct of_device_id hb_l2_err_of_match[] = {
  110. { .compatible = "calxeda,hb-sregs-l2-ecc", },
  111. {},
  112. };
  113. MODULE_DEVICE_TABLE(of, hb_l2_err_of_match);
  114. static struct platform_driver highbank_l2_edac_driver = {
  115. .probe = highbank_l2_err_probe,
  116. .remove = highbank_l2_err_remove,
  117. .driver = {
  118. .name = "hb_l2_edac",
  119. .of_match_table = hb_l2_err_of_match,
  120. },
  121. };
  122. module_platform_driver(highbank_l2_edac_driver);
  123. MODULE_LICENSE("GPL v2");
  124. MODULE_AUTHOR("Calxeda, Inc.");
  125. MODULE_DESCRIPTION("EDAC Driver for Calxeda Highbank L2 Cache");