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 <asm/mpc85xx.h>
24 #include "edac_module.h"
25 #include "edac_core.h"
26 #include "mpc85xx_edac.h"
28 static int edac_dev_idx;
29 static int edac_pci_idx;
30 static int edac_mc_idx;
32 static u32 orig_ddr_err_disable;
33 static u32 orig_ddr_err_sbe;
39 static u32 orig_pci_err_cap_dr;
40 static u32 orig_pci_err_en;
43 static u32 orig_l2_err_disable;
46 static const char *mpc85xx_ctl_name = "MPC85xx";
48 /************************ MC SYSFS parts ***********************************/
50 static ssize_t mpc85xx_mc_inject_data_hi_show(struct mem_ctl_info *mci,
53 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
54 return sprintf(data, "0x%08x",
55 in_be32(pdata->mc_vbase +
56 MPC85XX_MC_DATA_ERR_INJECT_HI));
59 static ssize_t mpc85xx_mc_inject_data_lo_show(struct mem_ctl_info *mci,
62 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
63 return sprintf(data, "0x%08x",
64 in_be32(pdata->mc_vbase +
65 MPC85XX_MC_DATA_ERR_INJECT_LO));
68 static ssize_t mpc85xx_mc_inject_ctrl_show(struct mem_ctl_info *mci, char *data)
70 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
71 return sprintf(data, "0x%08x",
72 in_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT));
75 static ssize_t mpc85xx_mc_inject_data_hi_store(struct mem_ctl_info *mci,
76 const char *data, size_t count)
78 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
80 out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_HI,
81 simple_strtoul(data, NULL, 0));
87 static ssize_t mpc85xx_mc_inject_data_lo_store(struct mem_ctl_info *mci,
88 const char *data, size_t count)
90 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
92 out_be32(pdata->mc_vbase + MPC85XX_MC_DATA_ERR_INJECT_LO,
93 simple_strtoul(data, NULL, 0));
99 static ssize_t mpc85xx_mc_inject_ctrl_store(struct mem_ctl_info *mci,
100 const char *data, size_t count)
102 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
103 if (isdigit(*data)) {
104 out_be32(pdata->mc_vbase + MPC85XX_MC_ECC_ERR_INJECT,
105 simple_strtoul(data, NULL, 0));
111 static struct mcidev_sysfs_attribute mpc85xx_mc_sysfs_attributes[] = {
114 .name = "inject_data_hi",
115 .mode = (S_IRUGO | S_IWUSR)
117 .show = mpc85xx_mc_inject_data_hi_show,
118 .store = mpc85xx_mc_inject_data_hi_store},
121 .name = "inject_data_lo",
122 .mode = (S_IRUGO | S_IWUSR)
124 .show = mpc85xx_mc_inject_data_lo_show,
125 .store = mpc85xx_mc_inject_data_lo_store},
128 .name = "inject_ctrl",
129 .mode = (S_IRUGO | S_IWUSR)
131 .show = mpc85xx_mc_inject_ctrl_show,
132 .store = mpc85xx_mc_inject_ctrl_store},
136 .attr = {.name = NULL}
140 static void mpc85xx_set_mc_sysfs_attributes(struct mem_ctl_info *mci)
142 mci->mc_driver_sysfs_attributes = mpc85xx_mc_sysfs_attributes;
145 /**************************** PCI Err device ***************************/
148 static void mpc85xx_pci_check(struct edac_pci_ctl_info *pci)
150 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
153 err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
155 /* master aborts can happen during PCI config cycles */
156 if (!(err_detect & ~(PCI_EDE_MULTI_ERR | PCI_EDE_MST_ABRT))) {
157 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
161 printk(KERN_ERR "PCI error(s) detected\n");
162 printk(KERN_ERR "PCI/X ERR_DR register: %#08x\n", err_detect);
164 printk(KERN_ERR "PCI/X ERR_ATTRIB register: %#08x\n",
165 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ATTRIB));
166 printk(KERN_ERR "PCI/X ERR_ADDR register: %#08x\n",
167 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR));
168 printk(KERN_ERR "PCI/X ERR_EXT_ADDR register: %#08x\n",
169 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EXT_ADDR));
170 printk(KERN_ERR "PCI/X ERR_DL register: %#08x\n",
171 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DL));
172 printk(KERN_ERR "PCI/X ERR_DH register: %#08x\n",
173 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DH));
175 /* clear error bits */
176 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
178 if (err_detect & PCI_EDE_PERR_MASK)
179 edac_pci_handle_pe(pci, pci->ctl_name);
181 if ((err_detect & ~PCI_EDE_MULTI_ERR) & ~PCI_EDE_PERR_MASK)
182 edac_pci_handle_npe(pci, pci->ctl_name);
185 static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
187 struct edac_pci_ctl_info *pci = dev_id;
188 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
191 err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
196 mpc85xx_pci_check(pci);
201 static int __devinit mpc85xx_pci_err_probe(struct platform_device *pdev)
203 struct edac_pci_ctl_info *pci;
204 struct mpc85xx_pci_pdata *pdata;
208 if (!devres_open_group(&pdev->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
211 pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
215 pdata = pci->pvt_info;
216 pdata->name = "mpc85xx_pci_err";
218 platform_set_drvdata(pdev, pci);
219 pci->dev = &pdev->dev;
220 pci->mod_name = EDAC_MOD_STR;
221 pci->ctl_name = pdata->name;
222 pci->dev_name = pdev->dev.bus_id;
224 if (edac_op_state == EDAC_OPSTATE_POLL)
225 pci->edac_check = mpc85xx_pci_check;
227 pdata->edac_idx = edac_pci_idx++;
229 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
231 printk(KERN_ERR "%s: Unable to get resource for "
232 "PCI err regs\n", __func__);
236 if (!devm_request_mem_region(&pdev->dev, r->start,
237 r->end - r->start + 1, pdata->name)) {
238 printk(KERN_ERR "%s: Error while requesting mem region\n",
244 pdata->pci_vbase = devm_ioremap(&pdev->dev, r->start,
245 r->end - r->start + 1);
246 if (!pdata->pci_vbase) {
247 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
252 orig_pci_err_cap_dr =
253 in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR);
255 /* PCI master abort is expected during config cycles */
256 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR, 0x40);
258 orig_pci_err_en = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
260 /* disable master abort reporting */
261 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0x40);
263 /* clear error bits */
264 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, ~0);
266 if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
267 debugf3("%s(): failed edac_pci_add_device()\n", __func__);
271 if (edac_op_state == EDAC_OPSTATE_INT) {
272 pdata->irq = platform_get_irq(pdev, 0);
273 res = devm_request_irq(&pdev->dev, pdata->irq,
274 mpc85xx_pci_isr, IRQF_DISABLED,
275 "[EDAC] PCI err", pci);
278 "%s: Unable to requiest irq %d for "
279 "MPC85xx PCI err\n", __func__, pdata->irq);
284 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err\n",
288 devres_remove_group(&pdev->dev, mpc85xx_pci_err_probe);
289 debugf3("%s(): success\n", __func__);
290 printk(KERN_INFO EDAC_MOD_STR " PCI err registered\n");
295 edac_pci_del_device(&pdev->dev);
297 edac_pci_free_ctl_info(pci);
298 devres_release_group(&pdev->dev, mpc85xx_pci_err_probe);
302 static int mpc85xx_pci_err_remove(struct platform_device *pdev)
304 struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev);
305 struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
307 debugf0("%s()\n", __func__);
309 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR,
310 orig_pci_err_cap_dr);
312 out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, orig_pci_err_en);
314 edac_pci_del_device(pci->dev);
316 if (edac_op_state == EDAC_OPSTATE_INT)
317 irq_dispose_mapping(pdata->irq);
319 edac_pci_free_ctl_info(pci);
324 static struct platform_driver mpc85xx_pci_err_driver = {
325 .probe = mpc85xx_pci_err_probe,
326 .remove = __devexit_p(mpc85xx_pci_err_remove),
328 .name = "mpc85xx_pci_err",
332 #endif /* CONFIG_PCI */
334 /**************************** L2 Err device ***************************/
336 /************************ L2 SYSFS parts ***********************************/
338 static ssize_t mpc85xx_l2_inject_data_hi_show(struct edac_device_ctl_info
339 *edac_dev, char *data)
341 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
342 return sprintf(data, "0x%08x",
343 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI));
346 static ssize_t mpc85xx_l2_inject_data_lo_show(struct edac_device_ctl_info
347 *edac_dev, char *data)
349 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
350 return sprintf(data, "0x%08x",
351 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO));
354 static ssize_t mpc85xx_l2_inject_ctrl_show(struct edac_device_ctl_info
355 *edac_dev, char *data)
357 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
358 return sprintf(data, "0x%08x",
359 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL));
362 static ssize_t mpc85xx_l2_inject_data_hi_store(struct edac_device_ctl_info
363 *edac_dev, const char *data,
366 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
367 if (isdigit(*data)) {
368 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI,
369 simple_strtoul(data, NULL, 0));
375 static ssize_t mpc85xx_l2_inject_data_lo_store(struct edac_device_ctl_info
376 *edac_dev, const char *data,
379 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
380 if (isdigit(*data)) {
381 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO,
382 simple_strtoul(data, NULL, 0));
388 static ssize_t mpc85xx_l2_inject_ctrl_store(struct edac_device_ctl_info
389 *edac_dev, const char *data,
392 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
393 if (isdigit(*data)) {
394 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL,
395 simple_strtoul(data, NULL, 0));
401 static struct edac_dev_sysfs_attribute mpc85xx_l2_sysfs_attributes[] = {
404 .name = "inject_data_hi",
405 .mode = (S_IRUGO | S_IWUSR)
407 .show = mpc85xx_l2_inject_data_hi_show,
408 .store = mpc85xx_l2_inject_data_hi_store},
411 .name = "inject_data_lo",
412 .mode = (S_IRUGO | S_IWUSR)
414 .show = mpc85xx_l2_inject_data_lo_show,
415 .store = mpc85xx_l2_inject_data_lo_store},
418 .name = "inject_ctrl",
419 .mode = (S_IRUGO | S_IWUSR)
421 .show = mpc85xx_l2_inject_ctrl_show,
422 .store = mpc85xx_l2_inject_ctrl_store},
426 .attr = {.name = NULL}
430 static void mpc85xx_set_l2_sysfs_attributes(struct edac_device_ctl_info
433 edac_dev->sysfs_attributes = mpc85xx_l2_sysfs_attributes;
436 /***************************** L2 ops ***********************************/
438 static void mpc85xx_l2_check(struct edac_device_ctl_info *edac_dev)
440 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
443 err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
445 if (!(err_detect & L2_EDE_MASK))
448 printk(KERN_ERR "ECC Error in CPU L2 cache\n");
449 printk(KERN_ERR "L2 Error Detect Register: 0x%08x\n", err_detect);
450 printk(KERN_ERR "L2 Error Capture Data High Register: 0x%08x\n",
451 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATAHI));
452 printk(KERN_ERR "L2 Error Capture Data Lo Register: 0x%08x\n",
453 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATALO));
454 printk(KERN_ERR "L2 Error Syndrome Register: 0x%08x\n",
455 in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTECC));
456 printk(KERN_ERR "L2 Error Attributes Capture Register: 0x%08x\n",
457 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRATTR));
458 printk(KERN_ERR "L2 Error Address Capture Register: 0x%08x\n",
459 in_be32(pdata->l2_vbase + MPC85XX_L2_ERRADDR));
461 /* clear error detect register */
462 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, err_detect);
464 if (err_detect & L2_EDE_CE_MASK)
465 edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name);
467 if (err_detect & L2_EDE_UE_MASK)
468 edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
471 static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
473 struct edac_device_ctl_info *edac_dev = dev_id;
474 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
477 err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
479 if (!(err_detect & L2_EDE_MASK))
482 mpc85xx_l2_check(edac_dev);
487 static int __devinit mpc85xx_l2_err_probe(struct of_device *op,
488 const struct of_device_id *match)
490 struct edac_device_ctl_info *edac_dev;
491 struct mpc85xx_l2_pdata *pdata;
495 if (!devres_open_group(&op->dev, mpc85xx_l2_err_probe, GFP_KERNEL))
498 edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
499 "cpu", 1, "L", 1, 2, NULL, 0,
502 devres_release_group(&op->dev, mpc85xx_l2_err_probe);
506 pdata = edac_dev->pvt_info;
507 pdata->name = "mpc85xx_l2_err";
509 edac_dev->dev = &op->dev;
510 dev_set_drvdata(edac_dev->dev, edac_dev);
511 edac_dev->ctl_name = pdata->name;
512 edac_dev->dev_name = pdata->name;
514 res = of_address_to_resource(op->node, 0, &r);
516 printk(KERN_ERR "%s: Unable to get resource for "
517 "L2 err regs\n", __func__);
521 /* we only need the error registers */
524 if (!devm_request_mem_region(&op->dev, r.start,
525 r.end - r.start + 1, pdata->name)) {
526 printk(KERN_ERR "%s: Error while requesting mem region\n",
532 pdata->l2_vbase = devm_ioremap(&op->dev, r.start, r.end - r.start + 1);
533 if (!pdata->l2_vbase) {
534 printk(KERN_ERR "%s: Unable to setup L2 err regs\n", __func__);
539 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, ~0);
541 orig_l2_err_disable = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS);
543 /* clear the err_dis */
544 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, 0);
546 edac_dev->mod_name = EDAC_MOD_STR;
548 if (edac_op_state == EDAC_OPSTATE_POLL)
549 edac_dev->edac_check = mpc85xx_l2_check;
551 mpc85xx_set_l2_sysfs_attributes(edac_dev);
553 pdata->edac_idx = edac_dev_idx++;
555 if (edac_device_add_device(edac_dev) > 0) {
556 debugf3("%s(): failed edac_device_add_device()\n", __func__);
560 if (edac_op_state == EDAC_OPSTATE_INT) {
561 pdata->irq = irq_of_parse_and_map(op->node, 0);
562 res = devm_request_irq(&op->dev, pdata->irq,
563 mpc85xx_l2_isr, IRQF_DISABLED,
564 "[EDAC] L2 err", edac_dev);
567 "%s: Unable to requiest irq %d for "
568 "MPC85xx L2 err\n", __func__, pdata->irq);
569 irq_dispose_mapping(pdata->irq);
574 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for L2 Err\n",
577 edac_dev->op_state = OP_RUNNING_INTERRUPT;
579 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, L2_EIE_MASK);
582 devres_remove_group(&op->dev, mpc85xx_l2_err_probe);
584 debugf3("%s(): success\n", __func__);
585 printk(KERN_INFO EDAC_MOD_STR " L2 err registered\n");
590 edac_device_del_device(&op->dev);
592 devres_release_group(&op->dev, mpc85xx_l2_err_probe);
593 edac_device_free_ctl_info(edac_dev);
597 static int mpc85xx_l2_err_remove(struct of_device *op)
599 struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
600 struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
602 debugf0("%s()\n", __func__);
604 if (edac_op_state == EDAC_OPSTATE_INT) {
605 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, 0);
606 irq_dispose_mapping(pdata->irq);
609 out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, orig_l2_err_disable);
610 edac_device_del_device(&op->dev);
611 edac_device_free_ctl_info(edac_dev);
615 static struct of_device_id mpc85xx_l2_err_of_match[] = {
617 .compatible = "fsl,8540-l2-cache-controller",
620 .compatible = "fsl,8541-l2-cache-controller",
623 .compatible = "fsl,8544-l2-cache-controller",
626 .compatible = "fsl,8548-l2-cache-controller",
629 .compatible = "fsl,8555-l2-cache-controller",
632 .compatible = "fsl,8568-l2-cache-controller",
637 static struct of_platform_driver mpc85xx_l2_err_driver = {
638 .owner = THIS_MODULE,
639 .name = "mpc85xx_l2_err",
640 .match_table = mpc85xx_l2_err_of_match,
641 .probe = mpc85xx_l2_err_probe,
642 .remove = mpc85xx_l2_err_remove,
644 .name = "mpc85xx_l2_err",
645 .owner = THIS_MODULE,
649 /**************************** MC Err device ***************************/
651 static void mpc85xx_mc_check(struct mem_ctl_info *mci)
653 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
654 struct csrow_info *csrow;
661 err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
665 mpc85xx_mc_printk(mci, KERN_ERR, "Err Detect Register: %#8.8x\n",
668 /* no more processing if not ECC bit errors */
669 if (!(err_detect & (DDR_EDE_SBE | DDR_EDE_MBE))) {
670 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
674 syndrome = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ECC);
675 err_addr = in_be32(pdata->mc_vbase + MPC85XX_MC_CAPTURE_ADDRESS);
676 pfn = err_addr >> PAGE_SHIFT;
678 for (row_index = 0; row_index < mci->nr_csrows; row_index++) {
679 csrow = &mci->csrows[row_index];
680 if ((pfn >= csrow->first_page) && (pfn <= csrow->last_page))
684 mpc85xx_mc_printk(mci, KERN_ERR, "Capture Data High: %#8.8x\n",
685 in_be32(pdata->mc_vbase +
686 MPC85XX_MC_CAPTURE_DATA_HI));
687 mpc85xx_mc_printk(mci, KERN_ERR, "Capture Data Low: %#8.8x\n",
688 in_be32(pdata->mc_vbase +
689 MPC85XX_MC_CAPTURE_DATA_LO));
690 mpc85xx_mc_printk(mci, KERN_ERR, "syndrome: %#8.8x\n", syndrome);
691 mpc85xx_mc_printk(mci, KERN_ERR, "err addr: %#8.8x\n", err_addr);
692 mpc85xx_mc_printk(mci, KERN_ERR, "PFN: %#8.8x\n", pfn);
694 /* we are out of range */
695 if (row_index == mci->nr_csrows)
696 mpc85xx_mc_printk(mci, KERN_ERR, "PFN out of range!\n");
698 if (err_detect & DDR_EDE_SBE)
699 edac_mc_handle_ce(mci, pfn, err_addr & PAGE_MASK,
700 syndrome, row_index, 0, mci->ctl_name);
702 if (err_detect & DDR_EDE_MBE)
703 edac_mc_handle_ue(mci, pfn, err_addr & PAGE_MASK,
704 row_index, mci->ctl_name);
706 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, err_detect);
709 static irqreturn_t mpc85xx_mc_isr(int irq, void *dev_id)
711 struct mem_ctl_info *mci = dev_id;
712 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
715 err_detect = in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT);
719 mpc85xx_mc_check(mci);
724 static void __devinit mpc85xx_init_csrows(struct mem_ctl_info *mci)
726 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
727 struct csrow_info *csrow;
734 sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
736 sdtype = sdram_ctl & DSC_SDTYPE_MASK;
737 if (sdram_ctl & DSC_RD_EN) {
742 case DSC_SDTYPE_DDR2:
754 case DSC_SDTYPE_DDR2:
763 for (index = 0; index < mci->nr_csrows; index++) {
767 csrow = &mci->csrows[index];
768 cs_bnds = in_be32(pdata->mc_vbase + MPC85XX_MC_CS_BNDS_0 +
769 (index * MPC85XX_MC_CS_BNDS_OFS));
770 start = (cs_bnds & 0xfff0000) << 4;
771 end = ((cs_bnds & 0xfff) << 20);
778 continue; /* not populated */
780 csrow->first_page = start >> PAGE_SHIFT;
781 csrow->last_page = end >> PAGE_SHIFT;
782 csrow->nr_pages = csrow->last_page + 1 - csrow->first_page;
784 csrow->mtype = mtype;
785 csrow->dtype = DEV_UNKNOWN;
786 if (sdram_ctl & DSC_X32_EN)
787 csrow->dtype = DEV_X32;
788 csrow->edac_mode = EDAC_SECDED;
792 static int __devinit mpc85xx_mc_err_probe(struct of_device *op,
793 const struct of_device_id *match)
795 struct mem_ctl_info *mci;
796 struct mpc85xx_mc_pdata *pdata;
801 if (!devres_open_group(&op->dev, mpc85xx_mc_err_probe, GFP_KERNEL))
804 mci = edac_mc_alloc(sizeof(*pdata), 4, 1, edac_mc_idx);
806 devres_release_group(&op->dev, mpc85xx_mc_err_probe);
810 pdata = mci->pvt_info;
811 pdata->name = "mpc85xx_mc_err";
814 pdata->edac_idx = edac_mc_idx++;
815 dev_set_drvdata(mci->dev, mci);
816 mci->ctl_name = pdata->name;
817 mci->dev_name = pdata->name;
819 res = of_address_to_resource(op->node, 0, &r);
821 printk(KERN_ERR "%s: Unable to get resource for MC err regs\n",
826 if (!devm_request_mem_region(&op->dev, r.start,
827 r.end - r.start + 1, pdata->name)) {
828 printk(KERN_ERR "%s: Error while requesting mem region\n",
834 pdata->mc_vbase = devm_ioremap(&op->dev, r.start, r.end - r.start + 1);
835 if (!pdata->mc_vbase) {
836 printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
841 sdram_ctl = in_be32(pdata->mc_vbase + MPC85XX_MC_DDR_SDRAM_CFG);
842 if (!(sdram_ctl & DSC_ECC_EN)) {
844 printk(KERN_WARNING "%s: No ECC DIMMs discovered\n", __func__);
849 debugf3("%s(): init mci\n", __func__);
850 mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_RDDR2 |
851 MEM_FLAG_DDR | MEM_FLAG_DDR2;
852 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
853 mci->edac_cap = EDAC_FLAG_SECDED;
854 mci->mod_name = EDAC_MOD_STR;
855 mci->mod_ver = MPC85XX_REVISION;
857 if (edac_op_state == EDAC_OPSTATE_POLL)
858 mci->edac_check = mpc85xx_mc_check;
860 mci->ctl_page_to_phys = NULL;
862 mci->scrub_mode = SCRUB_SW_SRC;
864 mpc85xx_set_mc_sysfs_attributes(mci);
866 mpc85xx_init_csrows(mci);
868 #ifdef CONFIG_EDAC_DEBUG
869 edac_mc_register_mcidev_debug((struct attribute **)debug_attr);
872 /* store the original error disable bits */
873 orig_ddr_err_disable =
874 in_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE);
875 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE, 0);
877 /* clear all error bits */
878 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DETECT, ~0);
880 if (edac_mc_add_mc(mci)) {
881 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
885 if (edac_op_state == EDAC_OPSTATE_INT) {
886 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN,
887 DDR_EIE_MBEE | DDR_EIE_SBEE);
889 /* store the original error management threshold */
890 orig_ddr_err_sbe = in_be32(pdata->mc_vbase +
891 MPC85XX_MC_ERR_SBE) & 0xff0000;
893 /* set threshold to 1 error per interrupt */
894 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, 0x10000);
896 /* register interrupts */
897 pdata->irq = irq_of_parse_and_map(op->node, 0);
898 res = devm_request_irq(&op->dev, pdata->irq,
899 mpc85xx_mc_isr, IRQF_DISABLED,
900 "[EDAC] MC err", mci);
902 printk(KERN_ERR "%s: Unable to request irq %d for "
903 "MPC85xx DRAM ERR\n", __func__, pdata->irq);
904 irq_dispose_mapping(pdata->irq);
909 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC\n",
913 devres_remove_group(&op->dev, mpc85xx_mc_err_probe);
914 debugf3("%s(): success\n", __func__);
915 printk(KERN_INFO EDAC_MOD_STR " MC err registered\n");
920 edac_mc_del_mc(&op->dev);
922 devres_release_group(&op->dev, mpc85xx_mc_err_probe);
927 static int mpc85xx_mc_err_remove(struct of_device *op)
929 struct mem_ctl_info *mci = dev_get_drvdata(&op->dev);
930 struct mpc85xx_mc_pdata *pdata = mci->pvt_info;
932 debugf0("%s()\n", __func__);
934 if (edac_op_state == EDAC_OPSTATE_INT) {
935 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_INT_EN, 0);
936 irq_dispose_mapping(pdata->irq);
939 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_DISABLE,
940 orig_ddr_err_disable);
941 out_be32(pdata->mc_vbase + MPC85XX_MC_ERR_SBE, orig_ddr_err_sbe);
943 edac_mc_del_mc(&op->dev);
948 static struct of_device_id mpc85xx_mc_err_of_match[] = {
950 .compatible = "fsl,8540-memory-controller",
953 .compatible = "fsl,8541-memory-controller",
956 .compatible = "fsl,8544-memory-controller",
959 .compatible = "fsl,8548-memory-controller",
962 .compatible = "fsl,8555-memory-controller",
965 .compatible = "fsl,8568-memory-controller",
970 static struct of_platform_driver mpc85xx_mc_err_driver = {
971 .owner = THIS_MODULE,
972 .name = "mpc85xx_mc_err",
973 .match_table = mpc85xx_mc_err_of_match,
974 .probe = mpc85xx_mc_err_probe,
975 .remove = mpc85xx_mc_err_remove,
977 .name = "mpc85xx_mc_err",
978 .owner = THIS_MODULE,
982 static int __init mpc85xx_mc_init(void)
986 printk(KERN_INFO "Freescale(R) MPC85xx EDAC driver, "
987 "(C) 2006 Montavista Software\n");
989 /* make sure error reporting method is sane */
990 switch (edac_op_state) {
991 case EDAC_OPSTATE_POLL:
992 case EDAC_OPSTATE_INT:
995 edac_op_state = EDAC_OPSTATE_INT;
999 res = of_register_platform_driver(&mpc85xx_mc_err_driver);
1001 printk(KERN_WARNING EDAC_MOD_STR "MC fails to register\n");
1003 res = of_register_platform_driver(&mpc85xx_l2_err_driver);
1005 printk(KERN_WARNING EDAC_MOD_STR "L2 fails to register\n");
1008 res = platform_driver_register(&mpc85xx_pci_err_driver);
1010 printk(KERN_WARNING EDAC_MOD_STR "PCI fails to register\n");
1014 * need to clear HID1[RFXE] to disable machine check int
1015 * so we can catch it
1017 if (edac_op_state == EDAC_OPSTATE_INT) {
1018 orig_hid1 = mfspr(SPRN_HID1);
1019 mtspr(SPRN_HID1, (orig_hid1 & ~0x20000));
1025 module_init(mpc85xx_mc_init);
1027 static void __exit mpc85xx_mc_exit(void)
1029 mtspr(SPRN_HID1, orig_hid1);
1031 platform_driver_unregister(&mpc85xx_pci_err_driver);
1033 of_unregister_platform_driver(&mpc85xx_l2_err_driver);
1034 of_unregister_platform_driver(&mpc85xx_mc_err_driver);
1037 module_exit(mpc85xx_mc_exit);
1039 MODULE_LICENSE("GPL");
1040 MODULE_AUTHOR("Montavista Software, Inc.");
1041 module_param(edac_op_state, int, 0444);
1042 MODULE_PARM_DESC(edac_op_state,
1043 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");