V4L/DVB (8495): usb/anysee.c: make struct anysee_usb_mutex static
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / edac / mv64x60_edac.c
blobbf071f140a054c492e16321bdf33bd2c06f6599d
1 /*
2 * Marvell MV64x60 Memory Controller kernel module for PPC platforms
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
9 * or implied.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/interrupt.h>
17 #include <linux/io.h>
18 #include <linux/edac.h>
20 #include "edac_core.h"
21 #include "edac_module.h"
22 #include "mv64x60_edac.h"
24 static const char *mv64x60_ctl_name = "MV64x60";
25 static int edac_dev_idx;
26 static int edac_pci_idx;
27 static int edac_mc_idx;
29 /*********************** PCI err device **********************************/
30 #ifdef CONFIG_PCI
31 static void mv64x60_pci_check(struct edac_pci_ctl_info *pci)
33 struct mv64x60_pci_pdata *pdata = pci->pvt_info;
34 u32 cause;
36 cause = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
37 if (!cause)
38 return;
40 printk(KERN_ERR "Error in PCI %d Interface\n", pdata->pci_hose);
41 printk(KERN_ERR "Cause register: 0x%08x\n", cause);
42 printk(KERN_ERR "Address Low: 0x%08x\n",
43 in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_LO));
44 printk(KERN_ERR "Address High: 0x%08x\n",
45 in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ADDR_HI));
46 printk(KERN_ERR "Attribute: 0x%08x\n",
47 in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_ATTR));
48 printk(KERN_ERR "Command: 0x%08x\n",
49 in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CMD));
50 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, ~cause);
52 if (cause & MV64X60_PCI_PE_MASK)
53 edac_pci_handle_pe(pci, pci->ctl_name);
55 if (!(cause & MV64X60_PCI_PE_MASK))
56 edac_pci_handle_npe(pci, pci->ctl_name);
59 static irqreturn_t mv64x60_pci_isr(int irq, void *dev_id)
61 struct edac_pci_ctl_info *pci = dev_id;
62 struct mv64x60_pci_pdata *pdata = pci->pvt_info;
63 u32 val;
65 val = in_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE);
66 if (!val)
67 return IRQ_NONE;
69 mv64x60_pci_check(pci);
71 return IRQ_HANDLED;
74 static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev)
76 struct edac_pci_ctl_info *pci;
77 struct mv64x60_pci_pdata *pdata;
78 struct resource *r;
79 int res = 0;
81 if (!devres_open_group(&pdev->dev, mv64x60_pci_err_probe, GFP_KERNEL))
82 return -ENOMEM;
84 pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mv64x60_pci_err");
85 if (!pci)
86 return -ENOMEM;
88 pdata = pci->pvt_info;
90 pdata->pci_hose = pdev->id;
91 pdata->name = "mpc85xx_pci_err";
92 pdata->irq = NO_IRQ;
93 platform_set_drvdata(pdev, pci);
94 pci->dev = &pdev->dev;
95 pci->dev_name = pdev->dev.bus_id;
96 pci->mod_name = EDAC_MOD_STR;
97 pci->ctl_name = pdata->name;
99 if (edac_op_state == EDAC_OPSTATE_POLL)
100 pci->edac_check = mv64x60_pci_check;
102 pdata->edac_idx = edac_pci_idx++;
104 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 if (!r) {
106 printk(KERN_ERR "%s: Unable to get resource for "
107 "PCI err regs\n", __func__);
108 res = -ENOENT;
109 goto err;
112 if (!devm_request_mem_region(&pdev->dev,
113 r->start,
114 r->end - r->start + 1,
115 pdata->name)) {
116 printk(KERN_ERR "%s: Error while requesting mem region\n",
117 __func__);
118 res = -EBUSY;
119 goto err;
122 pdata->pci_vbase = devm_ioremap(&pdev->dev,
123 r->start,
124 r->end - r->start + 1);
125 if (!pdata->pci_vbase) {
126 printk(KERN_ERR "%s: Unable to setup PCI err regs\n", __func__);
127 res = -ENOMEM;
128 goto err;
131 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_CAUSE, 0);
132 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK, 0);
133 out_le32(pdata->pci_vbase + MV64X60_PCI_ERROR_MASK,
134 MV64X60_PCIx_ERR_MASK_VAL);
136 if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
137 debugf3("%s(): failed edac_pci_add_device()\n", __func__);
138 goto err;
141 if (edac_op_state == EDAC_OPSTATE_INT) {
142 pdata->irq = platform_get_irq(pdev, 0);
143 res = devm_request_irq(&pdev->dev,
144 pdata->irq,
145 mv64x60_pci_isr,
146 IRQF_DISABLED,
147 "[EDAC] PCI err",
148 pci);
149 if (res < 0) {
150 printk(KERN_ERR "%s: Unable to request irq %d for "
151 "MV64x60 PCI ERR\n", __func__, pdata->irq);
152 res = -ENODEV;
153 goto err2;
155 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for PCI Err\n",
156 pdata->irq);
159 devres_remove_group(&pdev->dev, mv64x60_pci_err_probe);
161 /* get this far and it's successful */
162 debugf3("%s(): success\n", __func__);
164 return 0;
166 err2:
167 edac_pci_del_device(&pdev->dev);
168 err:
169 edac_pci_free_ctl_info(pci);
170 devres_release_group(&pdev->dev, mv64x60_pci_err_probe);
171 return res;
174 static int mv64x60_pci_err_remove(struct platform_device *pdev)
176 struct edac_pci_ctl_info *pci = platform_get_drvdata(pdev);
178 debugf0("%s()\n", __func__);
180 edac_pci_del_device(&pdev->dev);
182 edac_pci_free_ctl_info(pci);
184 return 0;
187 static struct platform_driver mv64x60_pci_err_driver = {
188 .probe = mv64x60_pci_err_probe,
189 .remove = __devexit_p(mv64x60_pci_err_remove),
190 .driver = {
191 .name = "mv64x60_pci_err",
195 #endif /* CONFIG_PCI */
197 /*********************** SRAM err device **********************************/
198 static void mv64x60_sram_check(struct edac_device_ctl_info *edac_dev)
200 struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
201 u32 cause;
203 cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
204 if (!cause)
205 return;
207 printk(KERN_ERR "Error in internal SRAM\n");
208 printk(KERN_ERR "Cause register: 0x%08x\n", cause);
209 printk(KERN_ERR "Address Low: 0x%08x\n",
210 in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_LO));
211 printk(KERN_ERR "Address High: 0x%08x\n",
212 in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_ADDR_HI));
213 printk(KERN_ERR "Data Low: 0x%08x\n",
214 in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_LO));
215 printk(KERN_ERR "Data High: 0x%08x\n",
216 in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_DATA_HI));
217 printk(KERN_ERR "Parity: 0x%08x\n",
218 in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_PARITY));
219 out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
221 edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
224 static irqreturn_t mv64x60_sram_isr(int irq, void *dev_id)
226 struct edac_device_ctl_info *edac_dev = dev_id;
227 struct mv64x60_sram_pdata *pdata = edac_dev->pvt_info;
228 u32 cause;
230 cause = in_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE);
231 if (!cause)
232 return IRQ_NONE;
234 mv64x60_sram_check(edac_dev);
236 return IRQ_HANDLED;
239 static int __devinit mv64x60_sram_err_probe(struct platform_device *pdev)
241 struct edac_device_ctl_info *edac_dev;
242 struct mv64x60_sram_pdata *pdata;
243 struct resource *r;
244 int res = 0;
246 if (!devres_open_group(&pdev->dev, mv64x60_sram_err_probe, GFP_KERNEL))
247 return -ENOMEM;
249 edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
250 "sram", 1, NULL, 0, 0, NULL, 0,
251 edac_dev_idx);
252 if (!edac_dev) {
253 devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
254 return -ENOMEM;
257 pdata = edac_dev->pvt_info;
258 pdata->name = "mv64x60_sram_err";
259 pdata->irq = NO_IRQ;
260 edac_dev->dev = &pdev->dev;
261 platform_set_drvdata(pdev, edac_dev);
262 edac_dev->dev_name = pdev->dev.bus_id;
264 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
265 if (!r) {
266 printk(KERN_ERR "%s: Unable to get resource for "
267 "SRAM err regs\n", __func__);
268 res = -ENOENT;
269 goto err;
272 if (!devm_request_mem_region(&pdev->dev,
273 r->start,
274 r->end - r->start + 1,
275 pdata->name)) {
276 printk(KERN_ERR "%s: Error while request mem region\n",
277 __func__);
278 res = -EBUSY;
279 goto err;
282 pdata->sram_vbase = devm_ioremap(&pdev->dev,
283 r->start,
284 r->end - r->start + 1);
285 if (!pdata->sram_vbase) {
286 printk(KERN_ERR "%s: Unable to setup SRAM err regs\n",
287 __func__);
288 res = -ENOMEM;
289 goto err;
292 /* setup SRAM err registers */
293 out_le32(pdata->sram_vbase + MV64X60_SRAM_ERR_CAUSE, 0);
295 edac_dev->mod_name = EDAC_MOD_STR;
296 edac_dev->ctl_name = pdata->name;
298 if (edac_op_state == EDAC_OPSTATE_POLL)
299 edac_dev->edac_check = mv64x60_sram_check;
301 pdata->edac_idx = edac_dev_idx++;
303 if (edac_device_add_device(edac_dev) > 0) {
304 debugf3("%s(): failed edac_device_add_device()\n", __func__);
305 goto err;
308 if (edac_op_state == EDAC_OPSTATE_INT) {
309 pdata->irq = platform_get_irq(pdev, 0);
310 res = devm_request_irq(&pdev->dev,
311 pdata->irq,
312 mv64x60_sram_isr,
313 IRQF_DISABLED,
314 "[EDAC] SRAM err",
315 edac_dev);
316 if (res < 0) {
317 printk(KERN_ERR
318 "%s: Unable to request irq %d for "
319 "MV64x60 SRAM ERR\n", __func__, pdata->irq);
320 res = -ENODEV;
321 goto err2;
324 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for SRAM Err\n",
325 pdata->irq);
328 devres_remove_group(&pdev->dev, mv64x60_sram_err_probe);
330 /* get this far and it's successful */
331 debugf3("%s(): success\n", __func__);
333 return 0;
335 err2:
336 edac_device_del_device(&pdev->dev);
337 err:
338 devres_release_group(&pdev->dev, mv64x60_sram_err_probe);
339 edac_device_free_ctl_info(edac_dev);
340 return res;
343 static int mv64x60_sram_err_remove(struct platform_device *pdev)
345 struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
347 debugf0("%s()\n", __func__);
349 edac_device_del_device(&pdev->dev);
350 edac_device_free_ctl_info(edac_dev);
352 return 0;
355 static struct platform_driver mv64x60_sram_err_driver = {
356 .probe = mv64x60_sram_err_probe,
357 .remove = mv64x60_sram_err_remove,
358 .driver = {
359 .name = "mv64x60_sram_err",
363 /*********************** CPU err device **********************************/
364 static void mv64x60_cpu_check(struct edac_device_ctl_info *edac_dev)
366 struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
367 u32 cause;
369 cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
370 MV64x60_CPU_CAUSE_MASK;
371 if (!cause)
372 return;
374 printk(KERN_ERR "Error on CPU interface\n");
375 printk(KERN_ERR "Cause register: 0x%08x\n", cause);
376 printk(KERN_ERR "Address Low: 0x%08x\n",
377 in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_LO));
378 printk(KERN_ERR "Address High: 0x%08x\n",
379 in_le32(pdata->cpu_vbase[0] + MV64x60_CPU_ERR_ADDR_HI));
380 printk(KERN_ERR "Data Low: 0x%08x\n",
381 in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_LO));
382 printk(KERN_ERR "Data High: 0x%08x\n",
383 in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_DATA_HI));
384 printk(KERN_ERR "Parity: 0x%08x\n",
385 in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_PARITY));
386 out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
388 edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
391 static irqreturn_t mv64x60_cpu_isr(int irq, void *dev_id)
393 struct edac_device_ctl_info *edac_dev = dev_id;
394 struct mv64x60_cpu_pdata *pdata = edac_dev->pvt_info;
395 u32 cause;
397 cause = in_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE) &
398 MV64x60_CPU_CAUSE_MASK;
399 if (!cause)
400 return IRQ_NONE;
402 mv64x60_cpu_check(edac_dev);
404 return IRQ_HANDLED;
407 static int __devinit mv64x60_cpu_err_probe(struct platform_device *pdev)
409 struct edac_device_ctl_info *edac_dev;
410 struct resource *r;
411 struct mv64x60_cpu_pdata *pdata;
412 int res = 0;
414 if (!devres_open_group(&pdev->dev, mv64x60_cpu_err_probe, GFP_KERNEL))
415 return -ENOMEM;
417 edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
418 "cpu", 1, NULL, 0, 0, NULL, 0,
419 edac_dev_idx);
420 if (!edac_dev) {
421 devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
422 return -ENOMEM;
425 pdata = edac_dev->pvt_info;
426 pdata->name = "mv64x60_cpu_err";
427 pdata->irq = NO_IRQ;
428 edac_dev->dev = &pdev->dev;
429 platform_set_drvdata(pdev, edac_dev);
430 edac_dev->dev_name = pdev->dev.bus_id;
432 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
433 if (!r) {
434 printk(KERN_ERR "%s: Unable to get resource for "
435 "CPU err regs\n", __func__);
436 res = -ENOENT;
437 goto err;
440 if (!devm_request_mem_region(&pdev->dev,
441 r->start,
442 r->end - r->start + 1,
443 pdata->name)) {
444 printk(KERN_ERR "%s: Error while requesting mem region\n",
445 __func__);
446 res = -EBUSY;
447 goto err;
450 pdata->cpu_vbase[0] = devm_ioremap(&pdev->dev,
451 r->start,
452 r->end - r->start + 1);
453 if (!pdata->cpu_vbase[0]) {
454 printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
455 res = -ENOMEM;
456 goto err;
459 r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
460 if (!r) {
461 printk(KERN_ERR "%s: Unable to get resource for "
462 "CPU err regs\n", __func__);
463 res = -ENOENT;
464 goto err;
467 if (!devm_request_mem_region(&pdev->dev,
468 r->start,
469 r->end - r->start + 1,
470 pdata->name)) {
471 printk(KERN_ERR "%s: Error while requesting mem region\n",
472 __func__);
473 res = -EBUSY;
474 goto err;
477 pdata->cpu_vbase[1] = devm_ioremap(&pdev->dev,
478 r->start,
479 r->end - r->start + 1);
480 if (!pdata->cpu_vbase[1]) {
481 printk(KERN_ERR "%s: Unable to setup CPU err regs\n", __func__);
482 res = -ENOMEM;
483 goto err;
486 /* setup CPU err registers */
487 out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_CAUSE, 0);
488 out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0);
489 out_le32(pdata->cpu_vbase[1] + MV64x60_CPU_ERR_MASK, 0x000000ff);
491 edac_dev->mod_name = EDAC_MOD_STR;
492 edac_dev->ctl_name = pdata->name;
493 if (edac_op_state == EDAC_OPSTATE_POLL)
494 edac_dev->edac_check = mv64x60_cpu_check;
496 pdata->edac_idx = edac_dev_idx++;
498 if (edac_device_add_device(edac_dev) > 0) {
499 debugf3("%s(): failed edac_device_add_device()\n", __func__);
500 goto err;
503 if (edac_op_state == EDAC_OPSTATE_INT) {
504 pdata->irq = platform_get_irq(pdev, 0);
505 res = devm_request_irq(&pdev->dev,
506 pdata->irq,
507 mv64x60_cpu_isr,
508 IRQF_DISABLED,
509 "[EDAC] CPU err",
510 edac_dev);
511 if (res < 0) {
512 printk(KERN_ERR
513 "%s: Unable to request irq %d for MV64x60 "
514 "CPU ERR\n", __func__, pdata->irq);
515 res = -ENODEV;
516 goto err2;
519 printk(KERN_INFO EDAC_MOD_STR
520 " acquired irq %d for CPU Err\n", pdata->irq);
523 devres_remove_group(&pdev->dev, mv64x60_cpu_err_probe);
525 /* get this far and it's successful */
526 debugf3("%s(): success\n", __func__);
528 return 0;
530 err2:
531 edac_device_del_device(&pdev->dev);
532 err:
533 devres_release_group(&pdev->dev, mv64x60_cpu_err_probe);
534 edac_device_free_ctl_info(edac_dev);
535 return res;
538 static int mv64x60_cpu_err_remove(struct platform_device *pdev)
540 struct edac_device_ctl_info *edac_dev = platform_get_drvdata(pdev);
542 debugf0("%s()\n", __func__);
544 edac_device_del_device(&pdev->dev);
545 edac_device_free_ctl_info(edac_dev);
546 return 0;
549 static struct platform_driver mv64x60_cpu_err_driver = {
550 .probe = mv64x60_cpu_err_probe,
551 .remove = mv64x60_cpu_err_remove,
552 .driver = {
553 .name = "mv64x60_cpu_err",
557 /*********************** DRAM err device **********************************/
559 static void mv64x60_mc_check(struct mem_ctl_info *mci)
561 struct mv64x60_mc_pdata *pdata = mci->pvt_info;
562 u32 reg;
563 u32 err_addr;
564 u32 sdram_ecc;
565 u32 comp_ecc;
566 u32 syndrome;
568 reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
569 if (!reg)
570 return;
572 err_addr = reg & ~0x3;
573 sdram_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_RCVD);
574 comp_ecc = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CALC);
575 syndrome = sdram_ecc ^ comp_ecc;
577 /* first bit clear in ECC Err Reg, 1 bit error, correctable by HW */
578 if (!(reg & 0x1))
579 edac_mc_handle_ce(mci, err_addr >> PAGE_SHIFT,
580 err_addr & PAGE_MASK, syndrome, 0, 0,
581 mci->ctl_name);
582 else /* 2 bit error, UE */
583 edac_mc_handle_ue(mci, err_addr >> PAGE_SHIFT,
584 err_addr & PAGE_MASK, 0, mci->ctl_name);
586 /* clear the error */
587 out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
590 static irqreturn_t mv64x60_mc_isr(int irq, void *dev_id)
592 struct mem_ctl_info *mci = dev_id;
593 struct mv64x60_mc_pdata *pdata = mci->pvt_info;
594 u32 reg;
596 reg = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR);
597 if (!reg)
598 return IRQ_NONE;
600 /* writing 0's to the ECC err addr in check function clears irq */
601 mv64x60_mc_check(mci);
603 return IRQ_HANDLED;
606 static void get_total_mem(struct mv64x60_mc_pdata *pdata)
608 struct device_node *np = NULL;
609 const unsigned int *reg;
611 np = of_find_node_by_type(NULL, "memory");
612 if (!np)
613 return;
615 reg = get_property(np, "reg", NULL);
617 pdata->total_mem = reg[1];
620 static void mv64x60_init_csrows(struct mem_ctl_info *mci,
621 struct mv64x60_mc_pdata *pdata)
623 struct csrow_info *csrow;
624 u32 devtype;
625 u32 ctl;
627 get_total_mem(pdata);
629 ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
631 csrow = &mci->csrows[0];
632 csrow->first_page = 0;
633 csrow->nr_pages = pdata->total_mem >> PAGE_SHIFT;
634 csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
635 csrow->grain = 8;
637 csrow->mtype = (ctl & MV64X60_SDRAM_REGISTERED) ? MEM_RDDR : MEM_DDR;
639 devtype = (ctl >> 20) & 0x3;
640 switch (devtype) {
641 case 0x0:
642 csrow->dtype = DEV_X32;
643 break;
644 case 0x2: /* could be X8 too, but no way to tell */
645 csrow->dtype = DEV_X16;
646 break;
647 case 0x3:
648 csrow->dtype = DEV_X4;
649 break;
650 default:
651 csrow->dtype = DEV_UNKNOWN;
652 break;
655 csrow->edac_mode = EDAC_SECDED;
658 static int __devinit mv64x60_mc_err_probe(struct platform_device *pdev)
660 struct mem_ctl_info *mci;
661 struct mv64x60_mc_pdata *pdata;
662 struct resource *r;
663 u32 ctl;
664 int res = 0;
666 if (!devres_open_group(&pdev->dev, mv64x60_mc_err_probe, GFP_KERNEL))
667 return -ENOMEM;
669 mci = edac_mc_alloc(sizeof(struct mv64x60_mc_pdata), 1, 1, edac_mc_idx);
670 if (!mci) {
671 printk(KERN_ERR "%s: No memory for CPU err\n", __func__);
672 devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
673 return -ENOMEM;
676 pdata = mci->pvt_info;
677 mci->dev = &pdev->dev;
678 platform_set_drvdata(pdev, mci);
679 pdata->name = "mv64x60_mc_err";
680 pdata->irq = NO_IRQ;
681 mci->dev_name = pdev->dev.bus_id;
682 pdata->edac_idx = edac_mc_idx++;
684 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
685 if (!r) {
686 printk(KERN_ERR "%s: Unable to get resource for "
687 "MC err regs\n", __func__);
688 res = -ENOENT;
689 goto err;
692 if (!devm_request_mem_region(&pdev->dev,
693 r->start,
694 r->end - r->start + 1,
695 pdata->name)) {
696 printk(KERN_ERR "%s: Error while requesting mem region\n",
697 __func__);
698 res = -EBUSY;
699 goto err;
702 pdata->mc_vbase = devm_ioremap(&pdev->dev,
703 r->start,
704 r->end - r->start + 1);
705 if (!pdata->mc_vbase) {
706 printk(KERN_ERR "%s: Unable to setup MC err regs\n", __func__);
707 res = -ENOMEM;
708 goto err;
711 ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_CONFIG);
712 if (!(ctl & MV64X60_SDRAM_ECC)) {
713 /* Non-ECC RAM? */
714 printk(KERN_WARNING "%s: No ECC DIMMs discovered\n", __func__);
715 res = -ENODEV;
716 goto err2;
719 debugf3("%s(): init mci\n", __func__);
720 mci->mtype_cap = MEM_FLAG_RDDR | MEM_FLAG_DDR;
721 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_SECDED;
722 mci->edac_cap = EDAC_FLAG_SECDED;
723 mci->mod_name = EDAC_MOD_STR;
724 mci->mod_ver = MV64x60_REVISION;
725 mci->ctl_name = mv64x60_ctl_name;
727 if (edac_op_state == EDAC_OPSTATE_POLL)
728 mci->edac_check = mv64x60_mc_check;
730 mci->ctl_page_to_phys = NULL;
732 mci->scrub_mode = SCRUB_SW_SRC;
734 mv64x60_init_csrows(mci, pdata);
736 /* setup MC registers */
737 out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ADDR, 0);
738 ctl = in_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL);
739 ctl = (ctl & 0xff00ffff) | 0x10000;
740 out_le32(pdata->mc_vbase + MV64X60_SDRAM_ERR_ECC_CNTL, ctl);
742 if (edac_mc_add_mc(mci)) {
743 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
744 goto err;
747 if (edac_op_state == EDAC_OPSTATE_INT) {
748 /* acquire interrupt that reports errors */
749 pdata->irq = platform_get_irq(pdev, 0);
750 res = devm_request_irq(&pdev->dev,
751 pdata->irq,
752 mv64x60_mc_isr,
753 IRQF_DISABLED,
754 "[EDAC] MC err",
755 mci);
756 if (res < 0) {
757 printk(KERN_ERR "%s: Unable to request irq %d for "
758 "MV64x60 DRAM ERR\n", __func__, pdata->irq);
759 res = -ENODEV;
760 goto err2;
763 printk(KERN_INFO EDAC_MOD_STR " acquired irq %d for MC Err\n",
764 pdata->irq);
767 /* get this far and it's successful */
768 debugf3("%s(): success\n", __func__);
770 return 0;
772 err2:
773 edac_mc_del_mc(&pdev->dev);
774 err:
775 devres_release_group(&pdev->dev, mv64x60_mc_err_probe);
776 edac_mc_free(mci);
777 return res;
780 static int mv64x60_mc_err_remove(struct platform_device *pdev)
782 struct mem_ctl_info *mci = platform_get_drvdata(pdev);
784 debugf0("%s()\n", __func__);
786 edac_mc_del_mc(&pdev->dev);
787 edac_mc_free(mci);
788 return 0;
791 static struct platform_driver mv64x60_mc_err_driver = {
792 .probe = mv64x60_mc_err_probe,
793 .remove = mv64x60_mc_err_remove,
794 .driver = {
795 .name = "mv64x60_mc_err",
799 static int __init mv64x60_edac_init(void)
801 int ret = 0;
803 printk(KERN_INFO "Marvell MV64x60 EDAC driver " MV64x60_REVISION "\n");
804 printk(KERN_INFO "\t(C) 2006-2007 MontaVista Software\n");
805 /* make sure error reporting method is sane */
806 switch (edac_op_state) {
807 case EDAC_OPSTATE_POLL:
808 case EDAC_OPSTATE_INT:
809 break;
810 default:
811 edac_op_state = EDAC_OPSTATE_INT;
812 break;
815 ret = platform_driver_register(&mv64x60_mc_err_driver);
816 if (ret)
817 printk(KERN_WARNING EDAC_MOD_STR "MC err failed to register\n");
819 ret = platform_driver_register(&mv64x60_cpu_err_driver);
820 if (ret)
821 printk(KERN_WARNING EDAC_MOD_STR
822 "CPU err failed to register\n");
824 ret = platform_driver_register(&mv64x60_sram_err_driver);
825 if (ret)
826 printk(KERN_WARNING EDAC_MOD_STR
827 "SRAM err failed to register\n");
829 #ifdef CONFIG_PCI
830 ret = platform_driver_register(&mv64x60_pci_err_driver);
831 if (ret)
832 printk(KERN_WARNING EDAC_MOD_STR
833 "PCI err failed to register\n");
834 #endif
836 return ret;
838 module_init(mv64x60_edac_init);
840 static void __exit mv64x60_edac_exit(void)
842 #ifdef CONFIG_PCI
843 platform_driver_unregister(&mv64x60_pci_err_driver);
844 #endif
845 platform_driver_unregister(&mv64x60_sram_err_driver);
846 platform_driver_unregister(&mv64x60_cpu_err_driver);
847 platform_driver_unregister(&mv64x60_mc_err_driver);
849 module_exit(mv64x60_edac_exit);
851 MODULE_LICENSE("GPL");
852 MODULE_AUTHOR("Montavista Software, Inc.");
853 module_param(edac_op_state, int, 0444);
854 MODULE_PARM_DESC(edac_op_state,
855 "EDAC Error Reporting state: 0=Poll, 2=Interrupt");