2 * Freescale MPC85xx Memory Controller kenel module
4 * Author: Dave Jiang <djiang@mvista.com>
6 * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/slab.h>
15 #include <linux/interrupt.h>
16 #include <linux/ctype.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/edac.h>
21 #include <linux/of_platform.h>
22 #include <linux/of_device.h>
23 #include "edac_module.h"
24 #include "edac_core.h"
25 #include "mpc85xx_edac.h"
27 static int edac_dev_idx;
28 static int edac_pci_idx;
29 static int edac_mc_idx;
31 static u32 orig_ddr_err_disable;
32 static u32 orig_ddr_err_sbe;
38 static u32 orig_pci_err_cap_dr;
39 static u32 orig_pci_err_en;
42 static u32 orig_l2_err_disable;
45 /************************ MC SYSFS parts ***********************************/
47 static ssize_t mpc85xx_mc_inject_data_hi_show(struct mem_ctl_info *mci,
50 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
51 return sprintf(data, "0x%08x",
52 in_be32(pdata->mc_vbase +
53 MPC85XX_MC_DATA_ERR_INJECT_HI));
56 static ssize_t mpc85xx_mc_inject_data_lo_show(struct mem_ctl_info *mci,
59 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
60 return sprintf(data, "0x%08x",
61 in_be32(pdata->mc_vbase +
62 MPC85XX_MC_DATA_ERR_INJECT_LO));
65 static ssize_t mpc85xx_mc_inject_ctrl_show(struct mem_ctl_info *mci, char *data)
67 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
68 return sprintf(data, "0x%08x",
69 in_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT));
72 static ssize_t mpc85xx_mc_inject_data_hi_store(struct mem_ctl_info *mci,
73 const char *data, size_t count)
75 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
77 out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_HI,
78 simple_strtoul(data, NULL, 0));
84 static ssize_t mpc85xx_mc_inject_data_lo_store(struct mem_ctl_info *mci,
85 const char *data, size_t count)
87 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
89 out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_LO,
90 simple_strtoul(data, NULL, 0));
96 static ssize_t mpc85xx_mc_inject_ctrl_store(struct mem_ctl_info *mci,
97 const char *data, size_t count)
99 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
100 if (isdigit(*data)) {
101 out_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT,
102 simple_strtoul(data, NULL, 0));
108 static struct mcidev_sysfs_attribute mpc85xx_mc_sysfs_attributes[] = {
111 .name = "inject_data_hi",
112 .mode = (S_IRUGO | S_IWUSR)
114 .show = mpc85xx_mc_inject_data_hi_show,
115 .store = mpc85xx_mc_inject_data_hi_store},
118 .name = "inject_data_lo",
119 .mode = (S_IRUGO | S_IWUSR)
121 .show = mpc85xx_mc_inject_data_lo_show,
122 .store = mpc85xx_mc_inject_data_lo_store},
125 .name = "inject_ctrl",
126 .mode = (S_IRUGO | S_IWUSR)
128 .show = mpc85xx_mc_inject_ctrl_show,
129 .store = mpc85xx_mc_inject_ctrl_store},
133 .attr = {.name = NULL}
137 static void mpc85xx_set_mc_sysfs_attributes(struct mem_ctl_info *mci)
139 mci->mc_driver_sysfs_attributes = mpc85xx_mc_sysfs_attributes;
142 /**************************** PCI Err device ***************************/
145 static void mpc85xx_pci_check(struct edac_pci_ctl_info *pci)
147 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
150 err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
152 /* master aborts can happen during PCI config cycles */
153 if (!(err_detect & ~(PCI_EDE_MULTI_ERR | PCI_EDE_MST_ABRT))) {
154 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
158 printk(KERN_ERR "PCI error(s) detected\n");
159 printk(KERN_ERR "PCI/X ERR_DR register: %#08x\n", err_detect);
161 printk(KERN_ERR "PCI/X ERR_ATTRIB register: %#08x\n",
162 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ATTRIB));
163 printk(KERN_ERR "PCI/X ERR_ADDR register: %#08x\n",
164 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR));
165 printk(KERN_ERR "PCI/X ERR_EXT_ADDR register: %#08x\n",
166 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EXT_ADDR));
167 printk(KERN_ERR "PCI/X ERR_DL register: %#08x\n",
168 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DL));
169 printk(KERN_ERR "PCI/X ERR_DH register: %#08x\n",
170 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DH));
172 /* clear error bits */
173 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
175 if (err_detect & PCI_EDE_PERR_MASK)
176 edac_pci_handle_pe(pci, pci->ctl_name);
178 if ((err_detect & ~PCI_EDE_MULTI_ERR) & ~PCI_EDE_PERR_MASK)
179 edac_pci_handle_npe(pci, pci->ctl_name);
182 static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
184 struct edac_pci_ctl_info *pci = dev_id;
185 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
188 err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
193 mpc85xx_pci_check(pci);
198 static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev)
200 struct edac_pci_ctl_info *pci;
201 struct mpc85xx_pci_pdata *pdata;
205 if (!devres_open_group(&pdev->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
208 pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
212 pdata = pci->pvt_info;
213 pdata->name = "mpc85xx_pci_err";
215 platform_set_drvdata(pdev, pci);
216 pci->dev = &pdev->dev;
217 pci->mod_name = EDAC_MOD_STR;
218 pci->ctl_name = pdata->name;
219 pci->dev_name = pdev->dev.bus_id;
221 if (edac_op_state == EDAC_OPSTATE_POLL)
222 pci->edac_check = mpc85xx_pci_check;
224 pdata->edac_idx = edac_pci_idx++;
226 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
228 printk(KERN_ERR "%s: Unable to get resource for "
229 "PCI err regs\n", __func__);
233 if (!devm_request_mem_region(&pdev->dev, r->start,
234 r->end - r->start + 1, pdata->name)) {
235 printk(KERN_ERR "%s: Error while requesting mem region\n",
241 pdata->pci_vbase = devm_ioremap(&pdev->dev, r->start,
242 r->end - r->start + 1);
243 if (!pdata->pci_vbase) {
244 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
249 orig_pci_err_cap_dr =
250 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR);
252 /* PCI master abort is expected during config cycles */
253 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR, 0x40);
255 orig_pci_err_en = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
257 /* disable master abort reporting */
258 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0x40);
260 /* clear error bits */
261 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, ~0);
263 if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
264 debugf3("%s(): failed edac_pci_add_device()\n", __func__);
268 if (edac_op_state == EDAC_OPSTATE_INT) {
269 pdata->irq = platform_get_irq(pdev, 0);
270 res = devm_request_irq(&pdev->dev, pdata->irq,
271 mpc85xx_pci_isr, IRQF_DISABLED,
272 "[EDAC] PCI err", pci);
275 "%s: Unable to requiest irq %d for "
276 "MPC85xx PCI err\n", __func__, pdata->irq);
281 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err\n",
285 devres_remove_group(&pdev->dev, mpc85xx_pci_err_probe);
286 debugf3("%s(): success\n", __func__);
287 printk(KERN_INFO EDAC_MOD_STR " PCI err registered\n");
292 edac_pci_del_device(&pdev->dev);
294 edac_pci_free_ctl_info(pci);
295 devres_release_group(&pdev->dev, mpc85xx_pci_err_probe);
299 static int mpc85xx_pci_err_remove(struct platform_device *pdev)
301 struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev);
302 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
304 debugf0("%s()\n", __func__);
306 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR,
307 orig_pci_err_cap_dr);
309 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, orig_pci_err_en);
311 edac_pci_del_device(pci->dev);
313 if (edac_op_state == EDAC_OPSTATE_INT)
314 irq_dispose_mapping(pdata->irq);
316 edac_pci_free_ctl_info(pci);
321 static struct platform_driver mpc85xx_pci_err_driver = {
322 .probe = mpc85xx_pci_err_probe,
323 .remove = __devexit_p(mpc85xx_pci_err_remove),
325 .name = "mpc85xx_pci_err",
329 #endif /* CONFIG_PCI */
331 /**************************** L2 Err device ***************************/
333 /************************ L2 SYSFS parts ***********************************/
335 static ssize_t mpc85xx_l2_inject_data_hi_show(struct edac_device_ctl_info
336 *edac_dev, char *data)
338 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
339 return sprintf(data, "0x%08x",
340 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI));
343 static ssize_t mpc85xx_l2_inject_data_lo_show(struct edac_device_ctl_info
344 *edac_dev, char *data)
346 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
347 return sprintf(data, "0x%08x",
348 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO));
351 static ssize_t mpc85xx_l2_inject_ctrl_show(struct edac_device_ctl_info
352 *edac_dev, char *data)
354 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
355 return sprintf(data, "0x%08x",
356 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL));
359 static ssize_t mpc85xx_l2_inject_data_hi_store(struct edac_device_ctl_info
360 *edac_dev, const char *data,
363 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
364 if (isdigit(*data)) {
365 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI,
366 simple_strtoul(data, NULL, 0));
372 static ssize_t mpc85xx_l2_inject_data_lo_store(struct edac_device_ctl_info
373 *edac_dev, const char *data,
376 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
377 if (isdigit(*data)) {
378 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO,
379 simple_strtoul(data, NULL, 0));
385 static ssize_t mpc85xx_l2_inject_ctrl_store(struct edac_device_ctl_info
386 *edac_dev, const char *data,
389 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
390 if (isdigit(*data)) {
391 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL,
392 simple_strtoul(data, NULL, 0));
398 static struct edac_dev_sysfs_attribute mpc85xx_l2_sysfs_attributes[] = {
401 .name = "inject_data_hi",
402 .mode = (S_IRUGO | S_IWUSR)
404 .show = mpc85xx_l2_inject_data_hi_show,
405 .store = mpc85xx_l2_inject_data_hi_store},
408 .name = "inject_data_lo",
409 .mode = (S_IRUGO | S_IWUSR)
411 .show = mpc85xx_l2_inject_data_lo_show,
412 .store = mpc85xx_l2_inject_data_lo_store},
415 .name = "inject_ctrl",
416 .mode = (S_IRUGO | S_IWUSR)
418 .show = mpc85xx_l2_inject_ctrl_show,
419 .store = mpc85xx_l2_inject_ctrl_store},
423 .attr = {.name = NULL}
427 static void mpc85xx_set_l2_sysfs_attributes(struct edac_device_ctl_info
430 edac_dev->sysfs_attributes = mpc85xx_l2_sysfs_attributes;
433 /***************************** L2 ops ***********************************/
435 static void mpc85xx_l2_check(struct edac_device_ctl_info *edac_dev)
437 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
440 err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
442 if (!(err_detect & L2_EDE_MASK))
445 printk(KERN_ERR "ECC Error in CPU L2 cache\n");
446 printk(KERN_ERR "L2 Error Detect Register: 0x%08x\n", err_detect);
447 printk(KERN_ERR "L2 Error Capture Data High Register: 0x%08x\n",
448 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATAHI));
449 printk(KERN_ERR "L2 Error Capture Data Lo Register: 0x%08x\n",
450 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATALO));
451 printk(KERN_ERR "L2 Error Syndrome Register: 0x%08x\n",
452 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTECC));
453 printk(KERN_ERR "L2 Error Attributes Capture Register: 0x%08x\n",
454 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRATTR));
455 printk(KERN_ERR "L2 Error Address Capture Register: 0x%08x\n",
456 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRADDR));
458 /* clear error detect register */
459 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, err_detect);
461 if (err_detect & L2_EDE_CE_MASK)
462 edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name);
464 if (err_detect & L2_EDE_UE_MASK)
465 edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
468 static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
470 struct edac_device_ctl_info *edac_dev = dev_id;
471 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
474 err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
476 if (!(err_detect & L2_EDE_MASK))
479 mpc85xx_l2_check(edac_dev);
484 static int __devinit mpc85xx_l2_err_probe(struct of_device *op,
485 const struct of_device_id *match)
487 struct edac_device_ctl_info *edac_dev;
488 struct mpc85xx_l2_pdata *pdata;
492 if (!devres_open_group(&op->dev, mpc85xx_l2_err_probe, GFP_KERNEL))
495 edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
496 "cpu", 1, "L", 1, 2, NULL, 0,
499 devres_release_group(&op->dev, mpc85xx_l2_err_probe);
503 pdata = edac_dev->pvt_info;
504 pdata->name = "mpc85xx_l2_err";
506 edac_dev->dev = &op->dev;
507 dev_set_drvdata(edac_dev->dev, edac_dev);
508 edac_dev->ctl_name = pdata->name;
509 edac_dev->dev_name = pdata->name;
511 res = of_address_to_resource(op->node, 0, &r);
513 printk(KERN_ERR "%s: Unable to get resource for "
514 "L2 err regs\n", __func__);
518 /* we only need the error registers */
521 if (!devm_request_mem_region(&op->dev, r.start,
522 r.end - r.start + 1, pdata->name)) {
523 printk(KERN_ERR "%s: Error while requesting mem region\n",
529 pdata->l2_vbase = devm_ioremap(&op->dev, r.start, r.end - r.start + 1);
530 if (!pdata->l2_vbase) {
531 printk(KERN_ERR "%s: Unable to setup L2 err regs\n", __func__);
536 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, ~0);
538 orig_l2_err_disable = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS);
540 /* clear the err_dis */
541 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, 0);
543 edac_dev->mod_name = EDAC_MOD_STR;
545 if (edac_op_state == EDAC_OPSTATE_POLL)
546 edac_dev->edac_check = mpc85xx_l2_check;
548 mpc85xx_set_l2_sysfs_attributes(edac_dev);
550 pdata->edac_idx = edac_dev_idx++;
552 if (edac_device_add_device(edac_dev) > 0) {
553 debugf3("%s(): failed edac_device_add_device()\n", __func__);
557 if (edac_op_state == EDAC_OPSTATE_INT) {
558 pdata->irq = irq_of_parse_and_map(op->node, 0);
559 res = devm_request_irq(&op->dev, pdata->irq,
560 mpc85xx_l2_isr, IRQF_DISABLED,
561 "[EDAC] L2 err", edac_dev);
564 "%s: Unable to requiest irq %d for "
565 "MPC85xx L2 err\n", __func__, pdata->irq);
566 irq_dispose_mapping(pdata->irq);
571 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for L2 Err\n",
574 edac_dev->op_state = OP_RUNNING_INTERRUPT;
576 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, L2_EIE_MASK);
579 devres_remove_group(&op->dev, mpc85xx_l2_err_probe);
581 debugf3("%s(): success\n", __func__);
582 printk(KERN_INFO EDAC_MOD_STR " L2 err registered\n");
587 edac_device_del_device(&op->dev);
589 devres_release_group(&op->dev, mpc85xx_l2_err_probe);
590 edac_device_free_ctl_info(edac_dev);
594 static int mpc85xx_l2_err_remove(struct of_device *op)
596 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
597 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
599 debugf0("%s()\n", __func__);
601 if (edac_op_state == EDAC_OPSTATE_INT) {
602 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, 0);
603 irq_dispose_mapping(pdata->irq);
606 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, orig_l2_err_disable);
607 edac_device_del_device(&op->dev);
608 edac_device_free_ctl_info(edac_dev);
612 static struct of_device_id mpc85xx_l2_err_of_match[] = {
614 .compatible = "fsl,8540-l2-cache-controller",
617 .compatible = "fsl,8541-l2-cache-controller",
620 .compatible = "fsl,8544-l2-cache-controller",
623 .compatible = "fsl,8548-l2-cache-controller",
626 .compatible = "fsl,8555-l2-cache-controller",
629 .compatible = "fsl,8568-l2-cache-controller",
634 static struct of_platform_driver mpc85xx_l2_err_driver = {
635 .owner = THIS_MODULE,
636 .name = "mpc85xx_l2_err",
637 .match_table = mpc85xx_l2_err_of_match,
638 .probe = mpc85xx_l2_err_probe,
639 .remove = mpc85xx_l2_err_remove,
641 .name = "mpc85xx_l2_err",
642 .owner = THIS_MODULE,
646 /**************************** MC Err device ***************************/
648 static void mpc85xx_mc_check(struct mem_ctl_info *mci)
650 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
651 struct csrow_info *csrow;
658 err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
662 mpc85xx_mc_printk(mci, KERN_ERR, "Err Detect Register: %#8.8x\n",
665 /* no more processing if not ECC bit errors */
666 if (!(err_detect & (DDR_EDE_SBE | DDR_EDE_MBE))) {
667 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
671 syndrome = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ECC);
672 err_addr = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ADDRESS);
673 pfn = err_addr >> PAGE_SHIFT;
675 for (row_index = 0; row_index < mci->nr_csrows; row_index++) {
676 csrow = &mci->csrows[row_index];
677 if ((pfn >= csrow->first_page) && (pfn <= csrow->last_page))
681 mpc85xx_mc_printk(mci, KERN_ERR, "Capture Data High: %#8.8x\n",
682 in_be32(pdata->mc_vbase +
683 MPC85XX_MC_CAPTURE_DATA_HI));
684 mpc85xx_mc_printk(mci, KERN_ERR, "Capture Data Low: %#8.8x\n",
685 in_be32(pdata->mc_vbase +
686 MPC85XX_MC_CAPTURE_DATA_LO));
687 mpc85xx_mc_printk(mci, KERN_ERR, "syndrome: %#8.8x\n", syndrome);
688 mpc85xx_mc_printk(mci, KERN_ERR, "err addr: %#8.8x\n", err_addr);
689 mpc85xx_mc_printk(mci, KERN_ERR, "PFN: %#8.8x\n", pfn);
691 /* we are out of range */
692 if (row_index == mci->nr_csrows)
693 mpc85xx_mc_printk(mci, KERN_ERR, "PFN out of range!\n");
695 if (err_detect & DDR_EDE_SBE)
696 edac_mc_handle_ce(mci, pfn, err_addr & PAGE_MASK,
697 syndrome, row_index, 0, mci->ctl_name);
699 if (err_detect & DDR_EDE_MBE)
700 edac_mc_handle_ue(mci, pfn, err_addr & PAGE_MASK,
701 row_index, mci->ctl_name);
703 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
706 static irqreturn_t mpc85xx_mc_isr(int irq, void *dev_id)
708 struct mem_ctl_info *mci = dev_id;
709 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
712 err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
716 mpc85xx_mc_check(mci);
721 static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
723 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
724 struct csrow_info *csrow;
731 sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
733 sdtype = sdram_ctl & DSC_SDTYPE_MASK;
734 if (sdram_ctl & DSC_RD_EN) {
739 case DSC_SDTYPE_DDR2:
751 case DSC_SDTYPE_DDR2:
760 for (index = 0; index < mci->nr_csrows; index++) {
764 csrow = &mci->csrows[index];
765 cs_bnds = in_be32(pdata->mc_vbase + MPC85XX_MC_CS_BNDS_0 +
766 (index * MPC85XX_MC_CS_BNDS_OFS));
767 start = (cs_bnds & 0xfff0000) << 4;
768 end = ((cs_bnds & 0xfff) << 20);
775 continue; /* not populated */
777 csrow->first_page = start >> PAGE_SHIFT;
778 csrow->last_page = end >> PAGE_SHIFT;
779 csrow->nr_pages = csrow->last_page + 1 - csrow->first_page;
781 csrow->mtype = mtype;
782 csrow->dtype = DEV_UNKNOWN;
783 if (sdram_ctl & DSC_X32_EN)
784 csrow->dtype = DEV_X32;
785 csrow->edac_mode = EDAC_SECDED;
789 static int __devinit mpc85xx_mc_err_probe(struct of_device *op,
790 const struct of_device_id *match)
792 struct mem_ctl_info *mci;
793 struct mpc85xx_mc_pdata *pdata;
798 if (!devres_open_group(&op->dev, mpc85xx_mc_err_probe, GFP_KERNEL))
801 mci = edac_mc_alloc(sizeof(*pdata), 4, 1, edac_mc_idx);
803 devres_release_group(&op->dev, mpc85xx_mc_err_probe);
807 pdata = mci->pvt_info;
808 pdata->name = "mpc85xx_mc_err";
811 pdata->edac_idx = edac_mc_idx++;
812 dev_set_drvdata(mci->dev, mci);
813 mci->ctl_name = pdata->name;
814 mci->dev_name = pdata->name;
816 res = of_address_to_resource(op->node, 0, &r);
818 printk(KERN_ERR "%s: Unable to get resource for MC err regs\n",
823 if (!devm_request_mem_region(&op->dev, r.start,
824 r.end - r.start + 1, pdata->name)) {
825 printk(KERN_ERR "%s: Error while requesting mem region\n",
831 pdata->mc_vbase = devm_ioremap(&op->dev, r.start, r.end - r.start + 1);
832 if (!pdata->mc_vbase) {
833 printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
838 sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
839 if (!(sdram_ctl & DSC_ECC_EN)) {
841 printk(KERN_WARNING "%s: No ECC DIMMs discovered\n", __func__);
846 debugf3("%s(): init mci\n", __func__);
847 mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_RDDR2 |
848 MEM_FLAG_DDR | MEM_FLAG_DDR2;
849 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
850 mci->edac_cap = EDAC_FLAG_SECDED;
851 mci->mod_name = EDAC_MOD_STR;
852 mci->mod_ver = MPC85XX_REVISION;
854 if (edac_op_state == EDAC_OPSTATE_POLL)
855 mci->edac_check = mpc85xx_mc_check;
857 mci->ctl_page_to_phys = NULL;
859 mci->scrub_mode = SCRUB_SW_SRC;
861 mpc85xx_set_mc_sysfs_attributes(mci);
863 mpc85xx_init_csrows(mci);
865 #ifdef CONFIG_EDAC_DEBUG
866 edac_mc_register_mcidev_debug((struct attribute **)debug_attr);
869 /* store the original error disable bits */
870 orig_ddr_err_disable =
871 in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE);
872 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE, 0);
874 /* clear all error bits */
875 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, ~0);
877 if (edac_mc_add_mc(mci)) {
878 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
882 if (edac_op_state == EDAC_OPSTATE_INT) {
883 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN,
884 DDR_EIE_MBEE | DDR_EIE_SBEE);
886 /* store the original error management threshold */
887 orig_ddr_err_sbe = in_be32(pdata->mc_vbase +
888 MPC85XX_MC_ERR_SBE) & 0xff0000;
890 /* set threshold to 1 error per interrupt */
891 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, 0x10000);
893 /* register interrupts */
894 pdata->irq = irq_of_parse_and_map(op->node, 0);
895 res = devm_request_irq(&op->dev, pdata->irq,
896 mpc85xx_mc_isr, IRQF_DISABLED,
897 "[EDAC] MC err", mci);
899 printk(KERN_ERR "%s: Unable to request irq %d for "
900 "MPC85xx DRAM ERR\n", __func__, pdata->irq);
901 irq_dispose_mapping(pdata->irq);
906 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC\n",
910 devres_remove_group(&op->dev, mpc85xx_mc_err_probe);
911 debugf3("%s(): success\n", __func__);
912 printk(KERN_INFO EDAC_MOD_STR " MC err registered\n");
917 edac_mc_del_mc(&op->dev);
919 devres_release_group(&op->dev, mpc85xx_mc_err_probe);
924 static int mpc85xx_mc_err_remove(struct of_device *op)
926 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
927 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
929 debugf0("%s()\n", __func__);
931 if (edac_op_state == EDAC_OPSTATE_INT) {
932 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN, 0);
933 irq_dispose_mapping(pdata->irq);
936 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE,
937 orig_ddr_err_disable);
938 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, orig_ddr_err_sbe);
940 edac_mc_del_mc(&op->dev);
945 static struct of_device_id mpc85xx_mc_err_of_match[] = {
947 .compatible = "fsl,8540-memory-controller",
950 .compatible = "fsl,8541-memory-controller",
953 .compatible = "fsl,8544-memory-controller",
956 .compatible = "fsl,8548-memory-controller",
959 .compatible = "fsl,8555-memory-controller",
962 .compatible = "fsl,8568-memory-controller",
967 static struct of_platform_driver mpc85xx_mc_err_driver = {
968 .owner = THIS_MODULE,
969 .name = "mpc85xx_mc_err",
970 .match_table = mpc85xx_mc_err_of_match,
971 .probe = mpc85xx_mc_err_probe,
972 .remove = mpc85xx_mc_err_remove,
974 .name = "mpc85xx_mc_err",
975 .owner = THIS_MODULE,
979 static int __init mpc85xx_mc_init(void)
983 printk(KERN_INFO "Freescale(R) MPC85xx EDAC driver, "
984 "(C) 2006 Montavista Software\n");
986 /* make sure error reporting method is sane */
987 switch (edac_op_state) {
988 case EDAC_OPSTATE_POLL:
989 case EDAC_OPSTATE_INT:
992 edac_op_state = EDAC_OPSTATE_INT;
996 res = of_register_platform_driver(&mpc85xx_mc_err_driver);
998 printk(KERN_WARNING EDAC_MOD_STR "MC fails to register\n");
1000 res = of_register_platform_driver(&mpc85xx_l2_err_driver);
1002 printk(KERN_WARNING EDAC_MOD_STR "L2 fails to register\n");
1005 res = platform_driver_register(&mpc85xx_pci_err_driver);
1007 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n");
1011 * need to clear HID1[RFXE] to disable machine check int
1012 * so we can catch it
1014 if (edac_op_state == EDAC_OPSTATE_INT) {
1015 orig_hid1 = mfspr(SPRN_HID1);
1016 mtspr(SPRN_HID1, (orig_hid1 & ~0x20000));
1022 module_init(mpc85xx_mc_init);
1024 static void __exit mpc85xx_mc_exit(void)
1026 mtspr(SPRN_HID1, orig_hid1);
1028 platform_driver_unregister(&mpc85xx_pci_err_driver);
1030 of_unregister_platform_driver(&mpc85xx_l2_err_driver);
1031 of_unregister_platform_driver(&mpc85xx_mc_err_driver);
1034 module_exit(mpc85xx_mc_exit);
1036 MODULE_LICENSE("GPL");
1037 MODULE_AUTHOR("Montavista Software, Inc.");
1038 module_param(edac_op_state, int, 0444);
1039 MODULE_PARM_DESC(edac_op_state,
1040 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");