133965Sjdp/* SPDX-License-Identifier: GPL-2.0-only */
289857Sobrien/*
378828Sobrien * Copyright (c) 2008 Nuovation System Designs, LLC
433965Sjdp *   Grant Erickson <gerickson@nuovations.com>
533965Sjdp *
633965Sjdp * This file defines processor mnemonics for accessing and managing
733965Sjdp * the IBM DDR1/DDR2 ECC controller found in the 405EX[r], 440SP,
833965Sjdp * 440SPe, 460EX, 460GT and 460SX.
933965Sjdp */
1033965Sjdp
1133965Sjdp#ifndef __PPC4XX_EDAC_H
1233965Sjdp#define __PPC4XX_EDAC_H
1333965Sjdp
1433965Sjdp#include <linux/types.h>
1533965Sjdp
1633965Sjdp/*
1733965Sjdp * Macro for generating register field mnemonics
1833965Sjdp */
1933965Sjdp#define PPC_REG_BITS			32
2033965Sjdp#define PPC_REG_VAL(bit, val)		((val) << ((PPC_REG_BITS - 1) - (bit)))
2133965Sjdp#define PPC_REG_DECODE(bit, val)	((val) >> ((PPC_REG_BITS - 1) - (bit)))
2233965Sjdp
2333965Sjdp/*
24107492Sobrien * IBM 4xx DDR1/DDR2 SDRAM memory controller registers (at least those
25107492Sobrien * relevant to ECC)
26107492Sobrien */
27107492Sobrien#define SDRAM_BESR			0x00	/* Error status (read/clear) */
2833965Sjdp#define SDRAM_BESRT			0x01	/* Error statuss (test/set)  */
2933965Sjdp#define SDRAM_BEARL			0x02	/* Error address low	     */
3033965Sjdp#define SDRAM_BEARH			0x03	/* Error address high	     */
3133965Sjdp#define SDRAM_WMIRQ			0x06	/* Write master (read/clear) */
3233965Sjdp#define SDRAM_WMIRQT			0x07	/* Write master (test/set)   */
3333965Sjdp#define SDRAM_MCOPT1			0x20	/* Controller options 1	     */
3433965Sjdp#define SDRAM_MBXCF_BASE		0x40	/* Bank n configuration base */
3533965Sjdp#define	SDRAM_MBXCF(n)			(SDRAM_MBXCF_BASE + (4 * (n)))
3633965Sjdp#define SDRAM_MB0CF			SDRAM_MBXCF(0)
3733965Sjdp#define SDRAM_MB1CF			SDRAM_MBXCF(1)
3833965Sjdp#define SDRAM_MB2CF			SDRAM_MBXCF(2)
3933965Sjdp#define SDRAM_MB3CF			SDRAM_MBXCF(3)
4033965Sjdp#define SDRAM_ECCCR			0x98	/* ECC error status	     */
4133965Sjdp#define SDRAM_ECCES			SDRAM_ECCCR
4233965Sjdp
4333965Sjdp/*
4433965Sjdp * PLB Master IDs
4533965Sjdp */
4633965Sjdp#define	SDRAM_PLB_M0ID_FIRST		0
4733965Sjdp#define	SDRAM_PLB_M0ID_ICU		SDRAM_PLB_M0ID_FIRST
4833965Sjdp#define	SDRAM_PLB_M0ID_PCIE0		1
4933965Sjdp#define	SDRAM_PLB_M0ID_PCIE1		2
5033965Sjdp#define	SDRAM_PLB_M0ID_DMA		3
5133965Sjdp#define	SDRAM_PLB_M0ID_DCU		4
5233965Sjdp#define	SDRAM_PLB_M0ID_OPB		5
5333965Sjdp#define	SDRAM_PLB_M0ID_MAL		6
5433965Sjdp#define	SDRAM_PLB_M0ID_SEC		7
5533965Sjdp#define	SDRAM_PLB_M0ID_AHB		8
5633965Sjdp#define SDRAM_PLB_M0ID_LAST		SDRAM_PLB_M0ID_AHB
5733965Sjdp#define SDRAM_PLB_M0ID_COUNT		(SDRAM_PLB_M0ID_LAST - \
5833965Sjdp					 SDRAM_PLB_M0ID_FIRST + 1)
5933965Sjdp
6033965Sjdp/*
6133965Sjdp * Memory Controller Bus Error Status Register
6233965Sjdp */
6333965Sjdp#define SDRAM_BESR_MASK			PPC_REG_VAL(7, 0xFF)
6433965Sjdp#define SDRAM_BESR_M0ID_MASK		PPC_REG_VAL(3, 0xF)
6533965Sjdp#define	SDRAM_BESR_M0ID_DECODE(n)	PPC_REG_DECODE(3, n)
6633965Sjdp#define SDRAM_BESR_M0ID_ICU		PPC_REG_VAL(3, SDRAM_PLB_M0ID_ICU)
6733965Sjdp#define SDRAM_BESR_M0ID_PCIE0		PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE0)
6833965Sjdp#define SDRAM_BESR_M0ID_PCIE1		PPC_REG_VAL(3, SDRAM_PLB_M0ID_PCIE1)
6933965Sjdp#define SDRAM_BESR_M0ID_DMA		PPC_REG_VAL(3, SDRAM_PLB_M0ID_DMA)
7033965Sjdp#define SDRAM_BESR_M0ID_DCU		PPC_REG_VAL(3, SDRAM_PLB_M0ID_DCU)
7133965Sjdp#define SDRAM_BESR_M0ID_OPB		PPC_REG_VAL(3, SDRAM_PLB_M0ID_OPB)
7233965Sjdp#define SDRAM_BESR_M0ID_MAL		PPC_REG_VAL(3, SDRAM_PLB_M0ID_MAL)
7333965Sjdp#define SDRAM_BESR_M0ID_SEC		PPC_REG_VAL(3, SDRAM_PLB_M0ID_SEC)
7433965Sjdp#define SDRAM_BESR_M0ID_AHB		PPC_REG_VAL(3, SDRAM_PLB_M0ID_AHB)
7533965Sjdp#define SDRAM_BESR_M0ET_MASK		PPC_REG_VAL(6, 0x7)
7633965Sjdp#define SDRAM_BESR_M0ET_NONE		PPC_REG_VAL(6, 0)
7733965Sjdp#define SDRAM_BESR_M0ET_ECC		PPC_REG_VAL(6, 1)
7833965Sjdp#define SDRAM_BESR_M0RW_MASK		PPC_REG_VAL(7, 1)
7933965Sjdp#define SDRAM_BESR_M0RW_WRITE		PPC_REG_VAL(7, 0)
8033965Sjdp#define SDRAM_BESR_M0RW_READ		PPC_REG_VAL(7, 1)
8133965Sjdp
8233965Sjdp/*
8333965Sjdp * Memory Controller PLB Write Master Interrupt Register
8433965Sjdp */
8533965Sjdp#define SDRAM_WMIRQ_MASK		PPC_REG_VAL(8, 0x1FF)
8633965Sjdp#define	SDRAM_WMIRQ_ENCODE(id)		PPC_REG_VAL((id % \
8733965Sjdp						     SDRAM_PLB_M0ID_COUNT), 1)
8833965Sjdp#define SDRAM_WMIRQ_ICU			PPC_REG_VAL(SDRAM_PLB_M0ID_ICU, 1)
8933965Sjdp#define SDRAM_WMIRQ_PCIE0		PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE0, 1)
9060484Sobrien#define SDRAM_WMIRQ_PCIE1		PPC_REG_VAL(SDRAM_PLB_M0ID_PCIE1, 1)
9160484Sobrien#define SDRAM_WMIRQ_DMA			PPC_REG_VAL(SDRAM_PLB_M0ID_DMA, 1)
9233965Sjdp#define SDRAM_WMIRQ_DCU			PPC_REG_VAL(SDRAM_PLB_M0ID_DCU, 1)
9333965Sjdp#define SDRAM_WMIRQ_OPB			PPC_REG_VAL(SDRAM_PLB_M0ID_OPB, 1)
9489857Sobrien#define SDRAM_WMIRQ_MAL			PPC_REG_VAL(SDRAM_PLB_M0ID_MAL, 1)
9533965Sjdp#define SDRAM_WMIRQ_SEC			PPC_REG_VAL(SDRAM_PLB_M0ID_SEC, 1)
9689857Sobrien#define SDRAM_WMIRQ_AHB			PPC_REG_VAL(SDRAM_PLB_M0ID_AHB, 1)
9789857Sobrien
9889857Sobrien/*
9989857Sobrien * Memory Controller Options 1 Register
10033965Sjdp */
10133965Sjdp#define SDRAM_MCOPT1_MCHK_MASK	    PPC_REG_VAL(3, 0x3)	 /* ECC mask	     */
10233965Sjdp#define SDRAM_MCOPT1_MCHK_NON	    PPC_REG_VAL(3, 0x0)	 /* No ECC gen	     */
10333965Sjdp#define SDRAM_MCOPT1_MCHK_GEN	    PPC_REG_VAL(3, 0x2)	 /* ECC gen	     */
10433965Sjdp#define SDRAM_MCOPT1_MCHK_CHK	    PPC_REG_VAL(3, 0x1)	 /* ECC gen and chk  */
10533965Sjdp#define SDRAM_MCOPT1_MCHK_CHK_REP   PPC_REG_VAL(3, 0x3)	 /* ECC gen/chk/rpt  */
10633965Sjdp#define SDRAM_MCOPT1_MCHK_DECODE(n) ((((u32)(n)) >> 28) & 0x3)
10733965Sjdp#define SDRAM_MCOPT1_RDEN_MASK	    PPC_REG_VAL(4, 0x1)	 /* Rgstrd DIMM mask */
10833965Sjdp#define SDRAM_MCOPT1_RDEN	    PPC_REG_VAL(4, 0x1)	 /* Rgstrd DIMM enbl */
10933965Sjdp#define SDRAM_MCOPT1_WDTH_MASK	    PPC_REG_VAL(7, 0x1)	 /* Width mask	     */
110#define SDRAM_MCOPT1_WDTH_32	    PPC_REG_VAL(7, 0x0)	 /* 32 bits	     */
111#define SDRAM_MCOPT1_WDTH_16	    PPC_REG_VAL(7, 0x1)	 /* 16 bits	     */
112#define SDRAM_MCOPT1_DDR_TYPE_MASK  PPC_REG_VAL(11, 0x1) /* DDR type mask    */
113#define SDRAM_MCOPT1_DDR1_TYPE	    PPC_REG_VAL(11, 0x0) /* DDR1 type	     */
114#define SDRAM_MCOPT1_DDR2_TYPE	    PPC_REG_VAL(11, 0x1) /* DDR2 type	     */
115
116/*
117 * Memory Bank 0 - n Configuration Register
118 */
119#define SDRAM_MBCF_BA_MASK		PPC_REG_VAL(12, 0x1FFF)
120#define SDRAM_MBCF_SZ_MASK		PPC_REG_VAL(19, 0xF)
121#define SDRAM_MBCF_SZ_DECODE(mbxcf)	PPC_REG_DECODE(19, mbxcf)
122#define SDRAM_MBCF_SZ_4MB		PPC_REG_VAL(19, 0x0)
123#define SDRAM_MBCF_SZ_8MB		PPC_REG_VAL(19, 0x1)
124#define SDRAM_MBCF_SZ_16MB		PPC_REG_VAL(19, 0x2)
125#define SDRAM_MBCF_SZ_32MB		PPC_REG_VAL(19, 0x3)
126#define SDRAM_MBCF_SZ_64MB		PPC_REG_VAL(19, 0x4)
127#define SDRAM_MBCF_SZ_128MB		PPC_REG_VAL(19, 0x5)
128#define SDRAM_MBCF_SZ_256MB		PPC_REG_VAL(19, 0x6)
129#define SDRAM_MBCF_SZ_512MB		PPC_REG_VAL(19, 0x7)
130#define SDRAM_MBCF_SZ_1GB		PPC_REG_VAL(19, 0x8)
131#define SDRAM_MBCF_SZ_2GB		PPC_REG_VAL(19, 0x9)
132#define SDRAM_MBCF_SZ_4GB		PPC_REG_VAL(19, 0xA)
133#define SDRAM_MBCF_SZ_8GB		PPC_REG_VAL(19, 0xB)
134#define SDRAM_MBCF_AM_MASK		PPC_REG_VAL(23, 0xF)
135#define SDRAM_MBCF_AM_MODE0		PPC_REG_VAL(23, 0x0)
136#define SDRAM_MBCF_AM_MODE1		PPC_REG_VAL(23, 0x1)
137#define SDRAM_MBCF_AM_MODE2		PPC_REG_VAL(23, 0x2)
138#define SDRAM_MBCF_AM_MODE3		PPC_REG_VAL(23, 0x3)
139#define SDRAM_MBCF_AM_MODE4		PPC_REG_VAL(23, 0x4)
140#define SDRAM_MBCF_AM_MODE5		PPC_REG_VAL(23, 0x5)
141#define SDRAM_MBCF_AM_MODE6		PPC_REG_VAL(23, 0x6)
142#define SDRAM_MBCF_AM_MODE7		PPC_REG_VAL(23, 0x7)
143#define SDRAM_MBCF_AM_MODE8		PPC_REG_VAL(23, 0x8)
144#define SDRAM_MBCF_AM_MODE9		PPC_REG_VAL(23, 0x9)
145#define SDRAM_MBCF_BE_MASK		PPC_REG_VAL(31, 0x1)
146#define SDRAM_MBCF_BE_DISABLE		PPC_REG_VAL(31, 0x0)
147#define SDRAM_MBCF_BE_ENABLE		PPC_REG_VAL(31, 0x1)
148
149/*
150 * ECC Error Status
151 */
152#define SDRAM_ECCES_MASK		PPC_REG_VAL(21, 0x3FFFFF)
153#define SDRAM_ECCES_BNCE_MASK		PPC_REG_VAL(15, 0xFFFF)
154#define SDRAM_ECCES_BNCE_ENCODE(lane)	PPC_REG_VAL(((lane) & 0xF), 1)
155#define SDRAM_ECCES_CKBER_MASK		PPC_REG_VAL(17, 0x3)
156#define SDRAM_ECCES_CKBER_NONE		PPC_REG_VAL(17, 0)
157#define SDRAM_ECCES_CKBER_16_ECC_0_3	PPC_REG_VAL(17, 2)
158#define SDRAM_ECCES_CKBER_32_ECC_0_3	PPC_REG_VAL(17, 1)
159#define SDRAM_ECCES_CKBER_32_ECC_4_8	PPC_REG_VAL(17, 2)
160#define SDRAM_ECCES_CKBER_32_ECC_0_8	PPC_REG_VAL(17, 3)
161#define SDRAM_ECCES_CE			PPC_REG_VAL(18, 1)
162#define SDRAM_ECCES_UE			PPC_REG_VAL(19, 1)
163#define SDRAM_ECCES_BKNER_MASK		PPC_REG_VAL(21, 0x3)
164#define SDRAM_ECCES_BK0ER		PPC_REG_VAL(20, 1)
165#define SDRAM_ECCES_BK1ER		PPC_REG_VAL(21, 1)
166
167#endif /* __PPC4XX_EDAC_H */
168