mpc85xx_edac.c 20 KB

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