18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017-2018, Intel Corporation
48c2ecf20Sopenharmony_ci * Copyright (C) 2015 Altera Corporation
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _ALTERA_EDAC_H
88c2ecf20Sopenharmony_ci#define _ALTERA_EDAC_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/arm-smccc.h>
118c2ecf20Sopenharmony_ci#include <linux/edac.h>
128c2ecf20Sopenharmony_ci#include <linux/types.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* SDRAM Controller CtrlCfg Register */
158c2ecf20Sopenharmony_ci#define CV_CTLCFG_OFST             0x00
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* SDRAM Controller CtrlCfg Register Bit Masks */
188c2ecf20Sopenharmony_ci#define CV_CTLCFG_ECC_EN           0x400
198c2ecf20Sopenharmony_ci#define CV_CTLCFG_ECC_CORR_EN      0x800
208c2ecf20Sopenharmony_ci#define CV_CTLCFG_GEN_SB_ERR       0x2000
218c2ecf20Sopenharmony_ci#define CV_CTLCFG_GEN_DB_ERR       0x4000
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define CV_CTLCFG_ECC_AUTO_EN     (CV_CTLCFG_ECC_EN)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* SDRAM Controller Address Width Register */
268c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_OFST          0x2C
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* SDRAM Controller Address Widths Field Register */
298c2ecf20Sopenharmony_ci#define DRAMADDRW_COLBIT_MASK      0x001F
308c2ecf20Sopenharmony_ci#define DRAMADDRW_COLBIT_SHIFT     0
318c2ecf20Sopenharmony_ci#define DRAMADDRW_ROWBIT_MASK      0x03E0
328c2ecf20Sopenharmony_ci#define DRAMADDRW_ROWBIT_SHIFT     5
338c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_BANKBIT_MASK  0x1C00
348c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_BANKBIT_SHIFT 10
358c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_CSBIT_MASK    0xE000
368c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_CSBIT_SHIFT   13
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* SDRAM Controller Interface Data Width Register */
398c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH_OFST        0x30
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/* SDRAM Controller Interface Data Width Defines */
428c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH_16B_ECC     24
438c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH_32B_ECC     40
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM Status Register */
468c2ecf20Sopenharmony_ci#define CV_DRAMSTS_OFST            0x38
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM Status Register Bit Masks */
498c2ecf20Sopenharmony_ci#define CV_DRAMSTS_SBEERR          0x04
508c2ecf20Sopenharmony_ci#define CV_DRAMSTS_DBEERR          0x08
518c2ecf20Sopenharmony_ci#define CV_DRAMSTS_CORR_DROP       0x10
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM IRQ Register */
548c2ecf20Sopenharmony_ci#define CV_DRAMINTR_OFST           0x3C
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM IRQ Register Bit Masks */
578c2ecf20Sopenharmony_ci#define CV_DRAMINTR_INTREN         0x01
588c2ecf20Sopenharmony_ci#define CV_DRAMINTR_SBEMASK        0x02
598c2ecf20Sopenharmony_ci#define CV_DRAMINTR_DBEMASK        0x04
608c2ecf20Sopenharmony_ci#define CV_DRAMINTR_CORRDROPMASK   0x08
618c2ecf20Sopenharmony_ci#define CV_DRAMINTR_INTRCLR        0x10
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/* SDRAM Controller Single Bit Error Count Register */
648c2ecf20Sopenharmony_ci#define CV_SBECOUNT_OFST           0x40
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/* SDRAM Controller Double Bit Error Count Register */
678c2ecf20Sopenharmony_ci#define CV_DBECOUNT_OFST           0x44
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* SDRAM Controller ECC Error Address Register */
708c2ecf20Sopenharmony_ci#define CV_ERRADDR_OFST            0x48
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/*-----------------------------------------*/
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci/* SDRAM Controller EccCtrl Register */
758c2ecf20Sopenharmony_ci#define A10_ECCCTRL1_OFST          0x00
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* SDRAM Controller EccCtrl Register Bit Masks */
788c2ecf20Sopenharmony_ci#define A10_ECCCTRL1_ECC_EN        0x001
798c2ecf20Sopenharmony_ci#define A10_ECCCTRL1_CNT_RST       0x010
808c2ecf20Sopenharmony_ci#define A10_ECCCTRL1_AWB_CNT_RST   0x100
818c2ecf20Sopenharmony_ci#define A10_ECC_CNT_RESET_MASK     (A10_ECCCTRL1_CNT_RST | \
828c2ecf20Sopenharmony_ci				    A10_ECCCTRL1_AWB_CNT_RST)
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* SDRAM Controller Address Width Register */
858c2ecf20Sopenharmony_ci#define CV_DRAMADDRW               0xFFC2502C
868c2ecf20Sopenharmony_ci#define A10_DRAMADDRW              0xFFCFA0A8
878c2ecf20Sopenharmony_ci#define S10_DRAMADDRW              0xF80110E0
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/* SDRAM Controller Address Widths Field Register */
908c2ecf20Sopenharmony_ci#define DRAMADDRW_COLBIT_MASK      0x001F
918c2ecf20Sopenharmony_ci#define DRAMADDRW_COLBIT_SHIFT     0
928c2ecf20Sopenharmony_ci#define DRAMADDRW_ROWBIT_MASK      0x03E0
938c2ecf20Sopenharmony_ci#define DRAMADDRW_ROWBIT_SHIFT     5
948c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_BANKBIT_MASK  0x1C00
958c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_BANKBIT_SHIFT 10
968c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_CSBIT_MASK    0xE000
978c2ecf20Sopenharmony_ci#define CV_DRAMADDRW_CSBIT_SHIFT   13
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_BANKBIT_MASK  0x3C00
1008c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_BANKBIT_SHIFT 10
1018c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_GRPBIT_MASK   0xC000
1028c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_GRPBIT_SHIFT  14
1038c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_CSBIT_MASK    0x70000
1048c2ecf20Sopenharmony_ci#define A10_DRAMADDRW_CSBIT_SHIFT   16
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* SDRAM Controller Interface Data Width Register */
1078c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH             0xFFC25030
1088c2ecf20Sopenharmony_ci#define A10_DRAMIFWIDTH            0xFFCFB008
1098c2ecf20Sopenharmony_ci#define S10_DRAMIFWIDTH            0xF8011008
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci/* SDRAM Controller Interface Data Width Defines */
1128c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH_16B_ECC     24
1138c2ecf20Sopenharmony_ci#define CV_DRAMIFWIDTH_32B_ECC     40
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#define A10_DRAMIFWIDTH_16B        0x0
1168c2ecf20Sopenharmony_ci#define A10_DRAMIFWIDTH_32B        0x1
1178c2ecf20Sopenharmony_ci#define A10_DRAMIFWIDTH_64B        0x2
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM IRQ Register */
1208c2ecf20Sopenharmony_ci#define A10_ERRINTEN_OFST          0x10
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci/* SDRAM Controller DRAM IRQ Register Bit Masks */
1238c2ecf20Sopenharmony_ci#define A10_ERRINTEN_SERRINTEN     0x01
1248c2ecf20Sopenharmony_ci#define A10_ERRINTEN_DERRINTEN     0x02
1258c2ecf20Sopenharmony_ci#define A10_ECC_IRQ_EN_MASK        (A10_ERRINTEN_SERRINTEN | \
1268c2ecf20Sopenharmony_ci				    A10_ERRINTEN_DERRINTEN)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* SDRAM Interrupt Mode Register */
1298c2ecf20Sopenharmony_ci#define A10_INTMODE_OFST           0x1C
1308c2ecf20Sopenharmony_ci#define A10_INTMODE_SB_INT         1
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/* SDRAM Controller Error Status Register */
1338c2ecf20Sopenharmony_ci#define A10_INTSTAT_OFST           0x20
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* SDRAM Controller Error Status Register Bit Masks */
1368c2ecf20Sopenharmony_ci#define A10_INTSTAT_SBEERR         0x01
1378c2ecf20Sopenharmony_ci#define A10_INTSTAT_DBEERR         0x02
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/* SDRAM Controller ECC Error Address Register */
1408c2ecf20Sopenharmony_ci#define A10_DERRADDR_OFST          0x2C
1418c2ecf20Sopenharmony_ci#define A10_SERRADDR_OFST          0x30
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/* SDRAM Controller ECC Diagnostic Register */
1448c2ecf20Sopenharmony_ci#define A10_DIAGINTTEST_OFST       0x24
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define A10_DIAGINT_TSERRA_MASK    0x0001
1478c2ecf20Sopenharmony_ci#define A10_DIAGINT_TDERRA_MASK    0x0100
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define A10_SBERR_IRQ              34
1508c2ecf20Sopenharmony_ci#define A10_DBERR_IRQ              32
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* SDRAM Single Bit Error Count Compare Set Register */
1538c2ecf20Sopenharmony_ci#define A10_SERRCNTREG_OFST        0x3C
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define A10_SYMAN_INTMASK_CLR      0xFFD06098
1568c2ecf20Sopenharmony_ci#define A10_INTMASK_CLR_OFST       0x10
1578c2ecf20Sopenharmony_ci#define A10_DDR0_IRQ_MASK          BIT(17)
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistruct altr_sdram_prv_data {
1608c2ecf20Sopenharmony_ci	int ecc_ctrl_offset;
1618c2ecf20Sopenharmony_ci	int ecc_ctl_en_mask;
1628c2ecf20Sopenharmony_ci	int ecc_cecnt_offset;
1638c2ecf20Sopenharmony_ci	int ecc_uecnt_offset;
1648c2ecf20Sopenharmony_ci	int ecc_stat_offset;
1658c2ecf20Sopenharmony_ci	int ecc_stat_ce_mask;
1668c2ecf20Sopenharmony_ci	int ecc_stat_ue_mask;
1678c2ecf20Sopenharmony_ci	int ecc_saddr_offset;
1688c2ecf20Sopenharmony_ci	int ecc_daddr_offset;
1698c2ecf20Sopenharmony_ci	int ecc_irq_en_offset;
1708c2ecf20Sopenharmony_ci	int ecc_irq_en_mask;
1718c2ecf20Sopenharmony_ci	int ecc_irq_clr_offset;
1728c2ecf20Sopenharmony_ci	int ecc_irq_clr_mask;
1738c2ecf20Sopenharmony_ci	int ecc_cnt_rst_offset;
1748c2ecf20Sopenharmony_ci	int ecc_cnt_rst_mask;
1758c2ecf20Sopenharmony_ci	struct edac_dev_sysfs_attribute *eccmgr_sysfs_attr;
1768c2ecf20Sopenharmony_ci	int ecc_enable_mask;
1778c2ecf20Sopenharmony_ci	int ce_set_mask;
1788c2ecf20Sopenharmony_ci	int ue_set_mask;
1798c2ecf20Sopenharmony_ci	int ce_ue_trgr_offset;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* Altera SDRAM Memory Controller data */
1838c2ecf20Sopenharmony_cistruct altr_sdram_mc_data {
1848c2ecf20Sopenharmony_ci	struct regmap *mc_vbase;
1858c2ecf20Sopenharmony_ci	int sb_irq;
1868c2ecf20Sopenharmony_ci	int db_irq;
1878c2ecf20Sopenharmony_ci	const struct altr_sdram_prv_data *data;
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/************************** EDAC Device Defines **************************/
1918c2ecf20Sopenharmony_ci/***** General Device Trigger Defines *****/
1928c2ecf20Sopenharmony_ci#define ALTR_UE_TRIGGER_CHAR            'U'   /* Trigger for UE */
1938c2ecf20Sopenharmony_ci#define ALTR_TRIGGER_READ_WRD_CNT       32    /* Line size x 4 */
1948c2ecf20Sopenharmony_ci#define ALTR_TRIG_OCRAM_BYTE_SIZE       128   /* Line size x 4 */
1958c2ecf20Sopenharmony_ci#define ALTR_TRIG_L2C_BYTE_SIZE         4096  /* Full Page */
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/******* Cyclone5 and Arria5 Defines *******/
1988c2ecf20Sopenharmony_ci/* OCRAM ECC Management Group Defines */
1998c2ecf20Sopenharmony_ci#define ALTR_MAN_GRP_OCRAM_ECC_OFFSET   0x04
2008c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_REG_OFFSET         0x00
2018c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_EN                 BIT(0)
2028c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_INJS               BIT(1)
2038c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_INJD               BIT(2)
2048c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_SERR               BIT(3)
2058c2ecf20Sopenharmony_ci#define ALTR_OCR_ECC_DERR               BIT(4)
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci/* L2 ECC Management Group Defines */
2088c2ecf20Sopenharmony_ci#define ALTR_MAN_GRP_L2_ECC_OFFSET      0x00
2098c2ecf20Sopenharmony_ci#define ALTR_L2_ECC_REG_OFFSET          0x00
2108c2ecf20Sopenharmony_ci#define ALTR_L2_ECC_EN                  BIT(0)
2118c2ecf20Sopenharmony_ci#define ALTR_L2_ECC_INJS                BIT(1)
2128c2ecf20Sopenharmony_ci#define ALTR_L2_ECC_INJD                BIT(2)
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci/* Arria10 General ECC Block Module Defines */
2158c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_CTRL_OFST          0x08
2168c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_EN                 BIT(0)
2178c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INITA              BIT(16)
2188c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INITB              BIT(24)
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INITSTAT_OFST      0x0C
2218c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INITCOMPLETEA      BIT(0)
2228c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INITCOMPLETEB      BIT(8)
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_ERRINTEN_OFST      0x10
2258c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_ERRINTENS_OFST     0x14
2268c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_ERRINTENR_OFST     0x18
2278c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_SERRINTEN          BIT(0)
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INTMODE_OFST       0x1C
2308c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INTMODE            BIT(0)
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INTSTAT_OFST       0x20
2338c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_SERRPENA           BIT(0)
2348c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_DERRPENA           BIT(8)
2358c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_ERRPENA_MASK       (ALTR_A10_ECC_SERRPENA | \
2368c2ecf20Sopenharmony_ci					 ALTR_A10_ECC_DERRPENA)
2378c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_SERRPENB           BIT(16)
2388c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_DERRPENB           BIT(24)
2398c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_ERRPENB_MASK       (ALTR_A10_ECC_SERRPENB | \
2408c2ecf20Sopenharmony_ci					 ALTR_A10_ECC_DERRPENB)
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INTTEST_OFST       0x24
2438c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_TSERRA             BIT(0)
2448c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_TDERRA             BIT(8)
2458c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_TSERRB             BIT(16)
2468c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_TDERRB             BIT(24)
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci/* ECC Manager Defines */
2498c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTMASK_SET_OFST   0x94
2508c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTMASK_CLR_OFST   0x98
2518c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTMASK_OCRAM      BIT(1)
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTSTAT_SERR_OFST  0x9C
2548c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTSTAT_DERR_OFST  0xA0
2558c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTSTAT_L2         BIT(0)
2568c2ecf20Sopenharmony_ci#define A10_SYSMGR_ECC_INTSTAT_OCRAM      BIT(1)
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci#define A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST  0xA8
2598c2ecf20Sopenharmony_ci#define A10_SYSGMR_MPU_CLEAR_L2_ECC_SB    BIT(15)
2608c2ecf20Sopenharmony_ci#define A10_SYSGMR_MPU_CLEAR_L2_ECC_MB    BIT(31)
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* Arria 10 L2 ECC Management Group Defines */
2638c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_CTL_OFST        0x0
2648c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_EN_CTL          BIT(0)
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_STATUS          0xFFD060A4
2678c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_STAT_OFST       0xA4
2688c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_SERR_PEND       BIT(0)
2698c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_MERR_PEND       BIT(0)
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_CLR_OFST        0x4
2728c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_SERR_CLR        BIT(15)
2738c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_MERR_CLR        BIT(31)
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_INJ_OFST        ALTR_A10_L2_ECC_CTL_OFST
2768c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_CE_INJ_MASK     0x00000101
2778c2ecf20Sopenharmony_ci#define ALTR_A10_L2_ECC_UE_INJ_MASK     0x00010101
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci/* Arria 10 OCRAM ECC Management Group Defines */
2808c2ecf20Sopenharmony_ci#define ALTR_A10_OCRAM_ECC_EN_CTL       (BIT(1) | BIT(0))
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* Arria 10 Ethernet ECC Management Group Defines */
2838c2ecf20Sopenharmony_ci#define ALTR_A10_COMMON_ECC_EN_CTL      BIT(0)
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/* Arria 10 SDMMC ECC Management Group Defines */
2868c2ecf20Sopenharmony_ci#define ALTR_A10_SDMMC_IRQ_MASK         (BIT(16) | BIT(15))
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci/* A10 ECC Controller memory initialization timeout */
2898c2ecf20Sopenharmony_ci#define ALTR_A10_ECC_INIT_WATCHDOG_10US      10000
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_ci/************* Stratix10 Defines **************/
2928c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_CTRL_SDRAM_OFST      0x00
2938c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_EN                   BIT(0)
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_ERRINTEN_OFST        0x10
2968c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_ERRINTENS_OFST       0x14
2978c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_ERRINTENR_OFST       0x18
2988c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_SERRINTEN            BIT(0)
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_INTMODE_OFST         0x1C
3018c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_INTMODE              BIT(0)
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_INTSTAT_OFST         0x20
3048c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_SERRPENA             BIT(0)
3058c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_DERRPENA             BIT(8)
3068c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_ERRPENA_MASK         (ALTR_S10_ECC_SERRPENA | \
3078c2ecf20Sopenharmony_ci					   ALTR_S10_ECC_DERRPENA)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_INTTEST_OFST         0x24
3108c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_TSERRA               BIT(0)
3118c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_TDERRA               BIT(8)
3128c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_TSERRB               BIT(16)
3138c2ecf20Sopenharmony_ci#define ALTR_S10_ECC_TDERRB               BIT(24)
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci#define ALTR_S10_DERR_ADDRA_OFST          0x2C
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci/* Stratix10 ECC Manager Defines */
3188c2ecf20Sopenharmony_ci#define S10_SYSMGR_ECC_INTMASK_CLR_OFST   0x98
3198c2ecf20Sopenharmony_ci#define S10_SYSMGR_ECC_INTSTAT_DERR_OFST  0xA0
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci/* Sticky registers for Uncorrected Errors */
3228c2ecf20Sopenharmony_ci#define S10_SYSMGR_UE_VAL_OFST            0x220
3238c2ecf20Sopenharmony_ci#define S10_SYSMGR_UE_ADDR_OFST           0x224
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci#define S10_DDR0_IRQ_MASK                 BIT(16)
3268c2ecf20Sopenharmony_ci#define S10_DBE_IRQ_MASK                  0x3FFFE
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* Define ECC Block Offsets for peripherals */
3298c2ecf20Sopenharmony_ci#define ECC_BLK_ADDRESS_OFST              0x40
3308c2ecf20Sopenharmony_ci#define ECC_BLK_RDATA0_OFST               0x44
3318c2ecf20Sopenharmony_ci#define ECC_BLK_RDATA1_OFST               0x48
3328c2ecf20Sopenharmony_ci#define ECC_BLK_RDATA2_OFST               0x4C
3338c2ecf20Sopenharmony_ci#define ECC_BLK_RDATA3_OFST               0x50
3348c2ecf20Sopenharmony_ci#define ECC_BLK_WDATA0_OFST               0x54
3358c2ecf20Sopenharmony_ci#define ECC_BLK_WDATA1_OFST               0x58
3368c2ecf20Sopenharmony_ci#define ECC_BLK_WDATA2_OFST               0x5C
3378c2ecf20Sopenharmony_ci#define ECC_BLK_WDATA3_OFST               0x60
3388c2ecf20Sopenharmony_ci#define ECC_BLK_RECC0_OFST                0x64
3398c2ecf20Sopenharmony_ci#define ECC_BLK_RECC1_OFST                0x68
3408c2ecf20Sopenharmony_ci#define ECC_BLK_WECC0_OFST                0x6C
3418c2ecf20Sopenharmony_ci#define ECC_BLK_WECC1_OFST                0x70
3428c2ecf20Sopenharmony_ci#define ECC_BLK_DBYTECTRL_OFST            0x74
3438c2ecf20Sopenharmony_ci#define ECC_BLK_ACCCTRL_OFST              0x78
3448c2ecf20Sopenharmony_ci#define ECC_BLK_STARTACC_OFST             0x7C
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci#define ECC_XACT_KICK                     0x10000
3478c2ecf20Sopenharmony_ci#define ECC_WORD_WRITE                    0xFF
3488c2ecf20Sopenharmony_ci#define ECC_WRITE_DOVR                    0x101
3498c2ecf20Sopenharmony_ci#define ECC_WRITE_EDOVR                   0x103
3508c2ecf20Sopenharmony_ci#define ECC_READ_EOVR                     0x2
3518c2ecf20Sopenharmony_ci#define ECC_READ_EDOVR                    0x3
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_cistruct altr_edac_device_dev;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_cistruct edac_device_prv_data {
3568c2ecf20Sopenharmony_ci	int (*setup)(struct altr_edac_device_dev *device);
3578c2ecf20Sopenharmony_ci	int ce_clear_mask;
3588c2ecf20Sopenharmony_ci	int ue_clear_mask;
3598c2ecf20Sopenharmony_ci	int irq_status_mask;
3608c2ecf20Sopenharmony_ci	void * (*alloc_mem)(size_t size, void **other);
3618c2ecf20Sopenharmony_ci	void (*free_mem)(void *p, size_t size, void *other);
3628c2ecf20Sopenharmony_ci	int ecc_enable_mask;
3638c2ecf20Sopenharmony_ci	int ecc_en_ofst;
3648c2ecf20Sopenharmony_ci	int ce_set_mask;
3658c2ecf20Sopenharmony_ci	int ue_set_mask;
3668c2ecf20Sopenharmony_ci	int set_err_ofst;
3678c2ecf20Sopenharmony_ci	irqreturn_t (*ecc_irq_handler)(int irq, void *dev_id);
3688c2ecf20Sopenharmony_ci	int trig_alloc_sz;
3698c2ecf20Sopenharmony_ci	const struct file_operations *inject_fops;
3708c2ecf20Sopenharmony_ci	bool panic;
3718c2ecf20Sopenharmony_ci};
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistruct altr_edac_device_dev {
3748c2ecf20Sopenharmony_ci	struct list_head next;
3758c2ecf20Sopenharmony_ci	void __iomem *base;
3768c2ecf20Sopenharmony_ci	int sb_irq;
3778c2ecf20Sopenharmony_ci	int db_irq;
3788c2ecf20Sopenharmony_ci	const struct edac_device_prv_data *data;
3798c2ecf20Sopenharmony_ci	struct dentry *debugfs_dir;
3808c2ecf20Sopenharmony_ci	char *edac_dev_name;
3818c2ecf20Sopenharmony_ci	struct altr_arria10_edac *edac;
3828c2ecf20Sopenharmony_ci	struct edac_device_ctl_info *edac_dev;
3838c2ecf20Sopenharmony_ci	struct device ddev;
3848c2ecf20Sopenharmony_ci	int edac_idx;
3858c2ecf20Sopenharmony_ci};
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_cistruct altr_arria10_edac {
3888c2ecf20Sopenharmony_ci	struct device		*dev;
3898c2ecf20Sopenharmony_ci	struct regmap		*ecc_mgr_map;
3908c2ecf20Sopenharmony_ci	int sb_irq;
3918c2ecf20Sopenharmony_ci	int db_irq;
3928c2ecf20Sopenharmony_ci	struct irq_domain	*domain;
3938c2ecf20Sopenharmony_ci	struct irq_chip		irq_chip;
3948c2ecf20Sopenharmony_ci	struct list_head	a10_ecc_devices;
3958c2ecf20Sopenharmony_ci	struct notifier_block	panic_notifier;
3968c2ecf20Sopenharmony_ci};
3978c2ecf20Sopenharmony_ci
3988c2ecf20Sopenharmony_ci#endif	/* #ifndef _ALTERA_EDAC_H */
399