mpc85xx_edac.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * Freescale MPC85xx Memory Controller kernel module
  3. *
  4. * Parts Copyrighted (c) 2013 by Freescale Semiconductor, Inc.
  5. *
  6. * Author: Dave Jiang <djiang@mvista.com>
  7. *
  8. * 2006-2007 (c) MontaVista Software, Inc. This file is licensed under
  9. * the terms of the GNU General Public License version 2. This program
  10. * is licensed "as is" without any warranty of any kind, whether express
  11. * or implied.
  12. *
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/ctype.h>
  18. #include <linux/io.h>
  19. #include <linux/mod_devicetable.h>
  20. #include <linux/edac.h>
  21. #include <linux/smp.h>
  22. #include <linux/gfp.h>
  23. #include <linux/fsl/edac.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/of_device.h>
  26. #include "edac_module.h"
  27. #include "edac_core.h"
  28. #include "mpc85xx_edac.h"
  29. #include "fsl_ddr_edac.h"
  30. static int edac_dev_idx;
  31. #ifdef CONFIG_PCI
  32. static int edac_pci_idx;
  33. #endif
  34. /*
  35. * PCI Err defines
  36. */
  37. #ifdef CONFIG_PCI
  38. static u32 orig_pci_err_cap_dr;
  39. static u32 orig_pci_err_en;
  40. #endif
  41. static u32 orig_l2_err_disable;
  42. /**************************** PCI Err device ***************************/
  43. #ifdef CONFIG_PCI
  44. static void mpc85xx_pci_check(struct edac_pci_ctl_info *pci)
  45. {
  46. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  47. u32 err_detect;
  48. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  49. /* master aborts can happen during PCI config cycles */
  50. if (!(err_detect & ~(PCI_EDE_MULTI_ERR | PCI_EDE_MST_ABRT))) {
  51. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  52. return;
  53. }
  54. pr_err("PCI error(s) detected\n");
  55. pr_err("PCI/X ERR_DR register: %#08x\n", err_detect);
  56. pr_err("PCI/X ERR_ATTRIB register: %#08x\n",
  57. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ATTRIB));
  58. pr_err("PCI/X ERR_ADDR register: %#08x\n",
  59. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR));
  60. pr_err("PCI/X ERR_EXT_ADDR register: %#08x\n",
  61. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EXT_ADDR));
  62. pr_err("PCI/X ERR_DL register: %#08x\n",
  63. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DL));
  64. pr_err("PCI/X ERR_DH register: %#08x\n",
  65. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DH));
  66. /* clear error bits */
  67. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  68. if (err_detect & PCI_EDE_PERR_MASK)
  69. edac_pci_handle_pe(pci, pci->ctl_name);
  70. if ((err_detect & ~PCI_EDE_MULTI_ERR) & ~PCI_EDE_PERR_MASK)
  71. edac_pci_handle_npe(pci, pci->ctl_name);
  72. }
  73. static void mpc85xx_pcie_check(struct edac_pci_ctl_info *pci)
  74. {
  75. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  76. u32 err_detect, err_cap_stat;
  77. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  78. err_cap_stat = in_be32(pdata->pci_vbase + MPC85XX_PCI_GAS_TIMR);
  79. pr_err("PCIe error(s) detected\n");
  80. pr_err("PCIe ERR_DR register: 0x%08x\n", err_detect);
  81. pr_err("PCIe ERR_CAP_STAT register: 0x%08x\n", err_cap_stat);
  82. pr_err("PCIe ERR_CAP_R0 register: 0x%08x\n",
  83. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R0));
  84. pr_err("PCIe ERR_CAP_R1 register: 0x%08x\n",
  85. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R1));
  86. pr_err("PCIe ERR_CAP_R2 register: 0x%08x\n",
  87. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R2));
  88. pr_err("PCIe ERR_CAP_R3 register: 0x%08x\n",
  89. in_be32(pdata->pci_vbase + MPC85XX_PCIE_ERR_CAP_R3));
  90. /* clear error bits */
  91. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, err_detect);
  92. /* reset error capture */
  93. out_be32(pdata->pci_vbase + MPC85XX_PCI_GAS_TIMR, err_cap_stat | 0x1);
  94. }
  95. static int mpc85xx_pcie_find_capability(struct device_node *np)
  96. {
  97. struct pci_controller *hose;
  98. if (!np)
  99. return -EINVAL;
  100. hose = pci_find_hose_for_OF_device(np);
  101. return early_find_capability(hose, 0, 0, PCI_CAP_ID_EXP);
  102. }
  103. static irqreturn_t mpc85xx_pci_isr(int irq, void *dev_id)
  104. {
  105. struct edac_pci_ctl_info *pci = dev_id;
  106. struct mpc85xx_pci_pdata *pdata = pci->pvt_info;
  107. u32 err_detect;
  108. err_detect = in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR);
  109. if (!err_detect)
  110. return IRQ_NONE;
  111. if (pdata->is_pcie)
  112. mpc85xx_pcie_check(pci);
  113. else
  114. mpc85xx_pci_check(pci);
  115. return IRQ_HANDLED;
  116. }
  117. static int mpc85xx_pci_err_probe(struct platform_device *op)
  118. {
  119. struct edac_pci_ctl_info *pci;
  120. struct mpc85xx_pci_pdata *pdata;
  121. struct mpc85xx_edac_pci_plat_data *plat_data;
  122. struct device_node *of_node;
  123. struct resource r;
  124. int res = 0;
  125. if (!devres_open_group(&op->dev, mpc85xx_pci_err_probe, GFP_KERNEL))
  126. return -ENOMEM;
  127. pci = edac_pci_alloc_ctl_info(sizeof(*pdata), "mpc85xx_pci_err");
  128. if (!pci)
  129. return -ENOMEM;
  130. /* make sure error reporting method is sane */
  131. switch (edac_op_state) {
  132. case EDAC_OPSTATE_POLL:
  133. case EDAC_OPSTATE_INT:
  134. break;
  135. default:
  136. edac_op_state = EDAC_OPSTATE_INT;
  137. break;
  138. }
  139. pdata = pci->pvt_info;
  140. pdata->name = "mpc85xx_pci_err";
  141. plat_data = op->dev.platform_data;
  142. if (!plat_data) {
  143. dev_err(&op->dev, "no platform data");
  144. res = -ENXIO;
  145. goto err;
  146. }
  147. of_node = plat_data->of_node;
  148. if (mpc85xx_pcie_find_capability(of_node) > 0)
  149. pdata->is_pcie = true;
  150. dev_set_drvdata(&op->dev, pci);
  151. pci->dev = &op->dev;
  152. pci->mod_name = EDAC_MOD_STR;
  153. pci->ctl_name = pdata->name;
  154. pci->dev_name = dev_name(&op->dev);
  155. if (edac_op_state == EDAC_OPSTATE_POLL) {
  156. if (pdata->is_pcie)
  157. pci->edac_check = mpc85xx_pcie_check;
  158. else
  159. pci->edac_check = mpc85xx_pci_check;
  160. }
  161. pdata->edac_idx = edac_pci_idx++;
  162. res = of_address_to_resource(of_node, 0, &r);
  163. if (res) {
  164. pr_err("%s: Unable to get resource for PCI err regs\n", __func__);
  165. goto err;
  166. }
  167. /* we only need the error registers */
  168. r.start += 0xe00;
  169. if (!devm_request_mem_region(&op->dev, r.start, resource_size(&r),
  170. pdata->name)) {
  171. pr_err("%s: Error while requesting mem region\n", __func__);
  172. res = -EBUSY;
  173. goto err;
  174. }
  175. pdata->pci_vbase = devm_ioremap(&op->dev, r.start, resource_size(&r));
  176. if (!pdata->pci_vbase) {
  177. pr_err("%s: Unable to setup PCI err regs\n", __func__);
  178. res = -ENOMEM;
  179. goto err;
  180. }
  181. if (pdata->is_pcie) {
  182. orig_pci_err_cap_dr =
  183. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR);
  184. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR, ~0);
  185. orig_pci_err_en =
  186. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
  187. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, 0);
  188. } else {
  189. orig_pci_err_cap_dr =
  190. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR);
  191. /* PCI master abort is expected during config cycles */
  192. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_CAP_DR, 0x40);
  193. orig_pci_err_en =
  194. in_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN);
  195. /* disable master abort reporting */
  196. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0x40);
  197. }
  198. /* clear error bits */
  199. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_DR, ~0);
  200. /* reset error capture */
  201. out_be32(pdata->pci_vbase + MPC85XX_PCI_GAS_TIMR, 0x1);
  202. if (edac_pci_add_device(pci, pdata->edac_idx) > 0) {
  203. edac_dbg(3, "failed edac_pci_add_device()\n");
  204. goto err;
  205. }
  206. if (edac_op_state == EDAC_OPSTATE_INT) {
  207. pdata->irq = irq_of_parse_and_map(of_node, 0);
  208. res = devm_request_irq(&op->dev, pdata->irq,
  209. mpc85xx_pci_isr,
  210. IRQF_SHARED,
  211. "[EDAC] PCI err", pci);
  212. if (res < 0) {
  213. pr_err("%s: Unable to request irq %d for MPC85xx PCI err\n",
  214. __func__, pdata->irq);
  215. irq_dispose_mapping(pdata->irq);
  216. res = -ENODEV;
  217. goto err2;
  218. }
  219. pr_info(EDAC_MOD_STR " acquired irq %d for PCI Err\n",
  220. pdata->irq);
  221. }
  222. if (pdata->is_pcie) {
  223. /*
  224. * Enable all PCIe error interrupt & error detect except invalid
  225. * PEX_CONFIG_ADDR/PEX_CONFIG_DATA access interrupt generation
  226. * enable bit and invalid PEX_CONFIG_ADDR/PEX_CONFIG_DATA access
  227. * detection enable bit. Because PCIe bus code to initialize and
  228. * configure these PCIe devices on booting will use some invalid
  229. * PEX_CONFIG_ADDR/PEX_CONFIG_DATA, edac driver prints the much
  230. * notice information. So disable this detect to fix ugly print.
  231. */
  232. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_EN, ~0
  233. & ~PEX_ERR_ICCAIE_EN_BIT);
  234. out_be32(pdata->pci_vbase + MPC85XX_PCI_ERR_ADDR, 0
  235. | PEX_ERR_ICCAD_DISR_BIT);
  236. }
  237. devres_remove_group(&op->dev, mpc85xx_pci_err_probe);
  238. edac_dbg(3, "success\n");
  239. pr_info(EDAC_MOD_STR " PCI err registered\n");
  240. return 0;
  241. err2:
  242. edac_pci_del_device(&op->dev);
  243. err:
  244. edac_pci_free_ctl_info(pci);
  245. devres_release_group(&op->dev, mpc85xx_pci_err_probe);
  246. return res;
  247. }
  248. static const struct platform_device_id mpc85xx_pci_err_match[] = {
  249. {
  250. .name = "mpc85xx-pci-edac"
  251. },
  252. {}
  253. };
  254. static struct platform_driver mpc85xx_pci_err_driver = {
  255. .probe = mpc85xx_pci_err_probe,
  256. .id_table = mpc85xx_pci_err_match,
  257. .driver = {
  258. .name = "mpc85xx_pci_err",
  259. .suppress_bind_attrs = true,
  260. },
  261. };
  262. #endif /* CONFIG_PCI */
  263. /**************************** L2 Err device ***************************/
  264. /************************ L2 SYSFS parts ***********************************/
  265. static ssize_t mpc85xx_l2_inject_data_hi_show(struct edac_device_ctl_info
  266. *edac_dev, char *data)
  267. {
  268. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  269. return sprintf(data, "0x%08x",
  270. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI));
  271. }
  272. static ssize_t mpc85xx_l2_inject_data_lo_show(struct edac_device_ctl_info
  273. *edac_dev, char *data)
  274. {
  275. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  276. return sprintf(data, "0x%08x",
  277. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO));
  278. }
  279. static ssize_t mpc85xx_l2_inject_ctrl_show(struct edac_device_ctl_info
  280. *edac_dev, char *data)
  281. {
  282. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  283. return sprintf(data, "0x%08x",
  284. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL));
  285. }
  286. static ssize_t mpc85xx_l2_inject_data_hi_store(struct edac_device_ctl_info
  287. *edac_dev, const char *data,
  288. size_t count)
  289. {
  290. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  291. if (isdigit(*data)) {
  292. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJHI,
  293. simple_strtoul(data, NULL, 0));
  294. return count;
  295. }
  296. return 0;
  297. }
  298. static ssize_t mpc85xx_l2_inject_data_lo_store(struct edac_device_ctl_info
  299. *edac_dev, const char *data,
  300. size_t count)
  301. {
  302. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  303. if (isdigit(*data)) {
  304. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJLO,
  305. simple_strtoul(data, NULL, 0));
  306. return count;
  307. }
  308. return 0;
  309. }
  310. static ssize_t mpc85xx_l2_inject_ctrl_store(struct edac_device_ctl_info
  311. *edac_dev, const char *data,
  312. size_t count)
  313. {
  314. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  315. if (isdigit(*data)) {
  316. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINJCTL,
  317. simple_strtoul(data, NULL, 0));
  318. return count;
  319. }
  320. return 0;
  321. }
  322. static struct edac_dev_sysfs_attribute mpc85xx_l2_sysfs_attributes[] = {
  323. {
  324. .attr = {
  325. .name = "inject_data_hi",
  326. .mode = (S_IRUGO | S_IWUSR)
  327. },
  328. .show = mpc85xx_l2_inject_data_hi_show,
  329. .store = mpc85xx_l2_inject_data_hi_store},
  330. {
  331. .attr = {
  332. .name = "inject_data_lo",
  333. .mode = (S_IRUGO | S_IWUSR)
  334. },
  335. .show = mpc85xx_l2_inject_data_lo_show,
  336. .store = mpc85xx_l2_inject_data_lo_store},
  337. {
  338. .attr = {
  339. .name = "inject_ctrl",
  340. .mode = (S_IRUGO | S_IWUSR)
  341. },
  342. .show = mpc85xx_l2_inject_ctrl_show,
  343. .store = mpc85xx_l2_inject_ctrl_store},
  344. /* End of list */
  345. {
  346. .attr = {.name = NULL}
  347. }
  348. };
  349. static void mpc85xx_set_l2_sysfs_attributes(struct edac_device_ctl_info
  350. *edac_dev)
  351. {
  352. edac_dev->sysfs_attributes = mpc85xx_l2_sysfs_attributes;
  353. }
  354. /***************************** L2 ops ***********************************/
  355. static void mpc85xx_l2_check(struct edac_device_ctl_info *edac_dev)
  356. {
  357. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  358. u32 err_detect;
  359. err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
  360. if (!(err_detect & L2_EDE_MASK))
  361. return;
  362. pr_err("ECC Error in CPU L2 cache\n");
  363. pr_err("L2 Error Detect Register: 0x%08x\n", err_detect);
  364. pr_err("L2 Error Capture Data High Register: 0x%08x\n",
  365. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATAHI));
  366. pr_err("L2 Error Capture Data Lo Register: 0x%08x\n",
  367. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTDATALO));
  368. pr_err("L2 Error Syndrome Register: 0x%08x\n",
  369. in_be32(pdata->l2_vbase + MPC85XX_L2_CAPTECC));
  370. pr_err("L2 Error Attributes Capture Register: 0x%08x\n",
  371. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRATTR));
  372. pr_err("L2 Error Address Capture Register: 0x%08x\n",
  373. in_be32(pdata->l2_vbase + MPC85XX_L2_ERRADDR));
  374. /* clear error detect register */
  375. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, err_detect);
  376. if (err_detect & L2_EDE_CE_MASK)
  377. edac_device_handle_ce(edac_dev, 0, 0, edac_dev->ctl_name);
  378. if (err_detect & L2_EDE_UE_MASK)
  379. edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
  380. }
  381. static irqreturn_t mpc85xx_l2_isr(int irq, void *dev_id)
  382. {
  383. struct edac_device_ctl_info *edac_dev = dev_id;
  384. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  385. u32 err_detect;
  386. err_detect = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET);
  387. if (!(err_detect & L2_EDE_MASK))
  388. return IRQ_NONE;
  389. mpc85xx_l2_check(edac_dev);
  390. return IRQ_HANDLED;
  391. }
  392. static int mpc85xx_l2_err_probe(struct platform_device *op)
  393. {
  394. struct edac_device_ctl_info *edac_dev;
  395. struct mpc85xx_l2_pdata *pdata;
  396. struct resource r;
  397. int res;
  398. if (!devres_open_group(&op->dev, mpc85xx_l2_err_probe, GFP_KERNEL))
  399. return -ENOMEM;
  400. edac_dev = edac_device_alloc_ctl_info(sizeof(*pdata),
  401. "cpu", 1, "L", 1, 2, NULL, 0,
  402. edac_dev_idx);
  403. if (!edac_dev) {
  404. devres_release_group(&op->dev, mpc85xx_l2_err_probe);
  405. return -ENOMEM;
  406. }
  407. pdata = edac_dev->pvt_info;
  408. pdata->name = "mpc85xx_l2_err";
  409. edac_dev->dev = &op->dev;
  410. dev_set_drvdata(edac_dev->dev, edac_dev);
  411. edac_dev->ctl_name = pdata->name;
  412. edac_dev->dev_name = pdata->name;
  413. res = of_address_to_resource(op->dev.of_node, 0, &r);
  414. if (res) {
  415. pr_err("%s: Unable to get resource for L2 err regs\n", __func__);
  416. goto err;
  417. }
  418. /* we only need the error registers */
  419. r.start += 0xe00;
  420. if (!devm_request_mem_region(&op->dev, r.start, resource_size(&r),
  421. pdata->name)) {
  422. pr_err("%s: Error while requesting mem region\n", __func__);
  423. res = -EBUSY;
  424. goto err;
  425. }
  426. pdata->l2_vbase = devm_ioremap(&op->dev, r.start, resource_size(&r));
  427. if (!pdata->l2_vbase) {
  428. pr_err("%s: Unable to setup L2 err regs\n", __func__);
  429. res = -ENOMEM;
  430. goto err;
  431. }
  432. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDET, ~0);
  433. orig_l2_err_disable = in_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS);
  434. /* clear the err_dis */
  435. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, 0);
  436. edac_dev->mod_name = EDAC_MOD_STR;
  437. if (edac_op_state == EDAC_OPSTATE_POLL)
  438. edac_dev->edac_check = mpc85xx_l2_check;
  439. mpc85xx_set_l2_sysfs_attributes(edac_dev);
  440. pdata->edac_idx = edac_dev_idx++;
  441. if (edac_device_add_device(edac_dev) > 0) {
  442. edac_dbg(3, "failed edac_device_add_device()\n");
  443. goto err;
  444. }
  445. if (edac_op_state == EDAC_OPSTATE_INT) {
  446. pdata->irq = irq_of_parse_and_map(op->dev.of_node, 0);
  447. res = devm_request_irq(&op->dev, pdata->irq,
  448. mpc85xx_l2_isr, IRQF_SHARED,
  449. "[EDAC] L2 err", edac_dev);
  450. if (res < 0) {
  451. pr_err("%s: Unable to request irq %d for MPC85xx L2 err\n",
  452. __func__, pdata->irq);
  453. irq_dispose_mapping(pdata->irq);
  454. res = -ENODEV;
  455. goto err2;
  456. }
  457. pr_info(EDAC_MOD_STR " acquired irq %d for L2 Err\n", pdata->irq);
  458. edac_dev->op_state = OP_RUNNING_INTERRUPT;
  459. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, L2_EIE_MASK);
  460. }
  461. devres_remove_group(&op->dev, mpc85xx_l2_err_probe);
  462. edac_dbg(3, "success\n");
  463. pr_info(EDAC_MOD_STR " L2 err registered\n");
  464. return 0;
  465. err2:
  466. edac_device_del_device(&op->dev);
  467. err:
  468. devres_release_group(&op->dev, mpc85xx_l2_err_probe);
  469. edac_device_free_ctl_info(edac_dev);
  470. return res;
  471. }
  472. static int mpc85xx_l2_err_remove(struct platform_device *op)
  473. {
  474. struct edac_device_ctl_info *edac_dev = dev_get_drvdata(&op->dev);
  475. struct mpc85xx_l2_pdata *pdata = edac_dev->pvt_info;
  476. edac_dbg(0, "\n");
  477. if (edac_op_state == EDAC_OPSTATE_INT) {
  478. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRINTEN, 0);
  479. irq_dispose_mapping(pdata->irq);
  480. }
  481. out_be32(pdata->l2_vbase + MPC85XX_L2_ERRDIS, orig_l2_err_disable);
  482. edac_device_del_device(&op->dev);
  483. edac_device_free_ctl_info(edac_dev);
  484. return 0;
  485. }
  486. static const struct of_device_id mpc85xx_l2_err_of_match[] = {
  487. /* deprecate the fsl,85.. forms in the future, 2.6.30? */
  488. { .compatible = "fsl,8540-l2-cache-controller", },
  489. { .compatible = "fsl,8541-l2-cache-controller", },
  490. { .compatible = "fsl,8544-l2-cache-controller", },
  491. { .compatible = "fsl,8548-l2-cache-controller", },
  492. { .compatible = "fsl,8555-l2-cache-controller", },
  493. { .compatible = "fsl,8568-l2-cache-controller", },
  494. { .compatible = "fsl,mpc8536-l2-cache-controller", },
  495. { .compatible = "fsl,mpc8540-l2-cache-controller", },
  496. { .compatible = "fsl,mpc8541-l2-cache-controller", },
  497. { .compatible = "fsl,mpc8544-l2-cache-controller", },
  498. { .compatible = "fsl,mpc8548-l2-cache-controller", },
  499. { .compatible = "fsl,mpc8555-l2-cache-controller", },
  500. { .compatible = "fsl,mpc8560-l2-cache-controller", },
  501. { .compatible = "fsl,mpc8568-l2-cache-controller", },
  502. { .compatible = "fsl,mpc8569-l2-cache-controller", },
  503. { .compatible = "fsl,mpc8572-l2-cache-controller", },
  504. { .compatible = "fsl,p1020-l2-cache-controller", },
  505. { .compatible = "fsl,p1021-l2-cache-controller", },
  506. { .compatible = "fsl,p2020-l2-cache-controller", },
  507. {},
  508. };
  509. MODULE_DEVICE_TABLE(of, mpc85xx_l2_err_of_match);
  510. static struct platform_driver mpc85xx_l2_err_driver = {
  511. .probe = mpc85xx_l2_err_probe,
  512. .remove = mpc85xx_l2_err_remove,
  513. .driver = {
  514. .name = "mpc85xx_l2_err",
  515. .of_match_table = mpc85xx_l2_err_of_match,
  516. },
  517. };
  518. static const struct of_device_id mpc85xx_mc_err_of_match[] = {
  519. /* deprecate the fsl,85.. forms in the future, 2.6.30? */
  520. { .compatible = "fsl,8540-memory-controller", },
  521. { .compatible = "fsl,8541-memory-controller", },
  522. { .compatible = "fsl,8544-memory-controller", },
  523. { .compatible = "fsl,8548-memory-controller", },
  524. { .compatible = "fsl,8555-memory-controller", },
  525. { .compatible = "fsl,8568-memory-controller", },
  526. { .compatible = "fsl,mpc8536-memory-controller", },
  527. { .compatible = "fsl,mpc8540-memory-controller", },
  528. { .compatible = "fsl,mpc8541-memory-controller", },
  529. { .compatible = "fsl,mpc8544-memory-controller", },
  530. { .compatible = "fsl,mpc8548-memory-controller", },
  531. { .compatible = "fsl,mpc8555-memory-controller", },
  532. { .compatible = "fsl,mpc8560-memory-controller", },
  533. { .compatible = "fsl,mpc8568-memory-controller", },
  534. { .compatible = "fsl,mpc8569-memory-controller", },
  535. { .compatible = "fsl,mpc8572-memory-controller", },
  536. { .compatible = "fsl,mpc8349-memory-controller", },
  537. { .compatible = "fsl,p1020-memory-controller", },
  538. { .compatible = "fsl,p1021-memory-controller", },
  539. { .compatible = "fsl,p2020-memory-controller", },
  540. { .compatible = "fsl,qoriq-memory-controller", },
  541. {},
  542. };
  543. MODULE_DEVICE_TABLE(of, mpc85xx_mc_err_of_match);
  544. static struct platform_driver mpc85xx_mc_err_driver = {
  545. .probe = fsl_mc_err_probe,
  546. .remove = fsl_mc_err_remove,
  547. .driver = {
  548. .name = "mpc85xx_mc_err",
  549. .of_match_table = mpc85xx_mc_err_of_match,
  550. },
  551. };
  552. static struct platform_driver * const drivers[] = {
  553. &mpc85xx_mc_err_driver,
  554. &mpc85xx_l2_err_driver,
  555. #ifdef CONFIG_PCI
  556. &mpc85xx_pci_err_driver,
  557. #endif
  558. };
  559. static int __init mpc85xx_mc_init(void)
  560. {
  561. int res = 0;
  562. u32 __maybe_unused pvr = 0;
  563. pr_info("Freescale(R) MPC85xx EDAC driver, (C) 2006 Montavista Software\n");
  564. /* make sure error reporting method is sane */
  565. switch (edac_op_state) {
  566. case EDAC_OPSTATE_POLL:
  567. case EDAC_OPSTATE_INT:
  568. break;
  569. default:
  570. edac_op_state = EDAC_OPSTATE_INT;
  571. break;
  572. }
  573. res = platform_register_drivers(drivers, ARRAY_SIZE(drivers));
  574. if (res)
  575. pr_warn(EDAC_MOD_STR "drivers fail to register\n");
  576. return 0;
  577. }
  578. module_init(mpc85xx_mc_init);
  579. static void __exit mpc85xx_mc_exit(void)
  580. {
  581. platform_unregister_drivers(drivers, ARRAY_SIZE(drivers));
  582. }
  583. module_exit(mpc85xx_mc_exit);
  584. MODULE_LICENSE("GPL");
  585. MODULE_AUTHOR("Montavista Software, Inc.");
  586. module_param(edac_op_state, int, 0444);
  587. MODULE_PARM_DESC(edac_op_state,
  588. "EDAC Error Reporting state: 0=Poll, 2=Interrupt");