Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* Freescale Integrated Flash Controller
0003  *
0004  * Copyright 2011 Freescale Semiconductor, Inc
0005  *
0006  * Author: Dipen Dudhat <dipen.dudhat@freescale.com>
0007  */
0008 
0009 #ifndef __ASM_FSL_IFC_H
0010 #define __ASM_FSL_IFC_H
0011 
0012 #include <linux/compiler.h>
0013 #include <linux/types.h>
0014 #include <linux/io.h>
0015 
0016 #include <linux/of_platform.h>
0017 #include <linux/interrupt.h>
0018 
0019 /*
0020  * The actual number of banks implemented depends on the IFC version
0021  *    - IFC version 1.0 implements 4 banks.
0022  *    - IFC version 1.1 onward implements 8 banks.
0023  */
0024 #define FSL_IFC_BANK_COUNT 8
0025 
0026 #define FSL_IFC_VERSION_MASK    0x0F0F0000
0027 #define FSL_IFC_VERSION_1_0_0   0x01000000
0028 #define FSL_IFC_VERSION_1_1_0   0x01010000
0029 #define FSL_IFC_VERSION_2_0_0   0x02000000
0030 
0031 #define PGOFFSET_64K    (64*1024)
0032 #define PGOFFSET_4K (4*1024)
0033 
0034 /*
0035  * CSPR - Chip Select Property Register
0036  */
0037 #define CSPR_BA             0xFFFF0000
0038 #define CSPR_BA_SHIFT           16
0039 #define CSPR_PORT_SIZE          0x00000180
0040 #define CSPR_PORT_SIZE_SHIFT        7
0041 /* Port Size 8 bit */
0042 #define CSPR_PORT_SIZE_8        0x00000080
0043 /* Port Size 16 bit */
0044 #define CSPR_PORT_SIZE_16       0x00000100
0045 /* Port Size 32 bit */
0046 #define CSPR_PORT_SIZE_32       0x00000180
0047 /* Write Protect */
0048 #define CSPR_WP             0x00000040
0049 #define CSPR_WP_SHIFT           6
0050 /* Machine Select */
0051 #define CSPR_MSEL           0x00000006
0052 #define CSPR_MSEL_SHIFT         1
0053 /* NOR */
0054 #define CSPR_MSEL_NOR           0x00000000
0055 /* NAND */
0056 #define CSPR_MSEL_NAND          0x00000002
0057 /* GPCM */
0058 #define CSPR_MSEL_GPCM          0x00000004
0059 /* Bank Valid */
0060 #define CSPR_V              0x00000001
0061 #define CSPR_V_SHIFT            0
0062 
0063 /*
0064  * Address Mask Register
0065  */
0066 #define IFC_AMASK_MASK          0xFFFF0000
0067 #define IFC_AMASK_SHIFT         16
0068 #define IFC_AMASK(n)            (IFC_AMASK_MASK << \
0069                     (__ilog2(n) - IFC_AMASK_SHIFT))
0070 
0071 /*
0072  * Chip Select Option Register IFC_NAND Machine
0073  */
0074 /* Enable ECC Encoder */
0075 #define CSOR_NAND_ECC_ENC_EN        0x80000000
0076 #define CSOR_NAND_ECC_MODE_MASK     0x30000000
0077 /* 4 bit correction per 520 Byte sector */
0078 #define CSOR_NAND_ECC_MODE_4        0x00000000
0079 /* 8 bit correction per 528 Byte sector */
0080 #define CSOR_NAND_ECC_MODE_8        0x10000000
0081 /* Enable ECC Decoder */
0082 #define CSOR_NAND_ECC_DEC_EN        0x04000000
0083 /* Row Address Length */
0084 #define CSOR_NAND_RAL_MASK      0x01800000
0085 #define CSOR_NAND_RAL_SHIFT     20
0086 #define CSOR_NAND_RAL_1         0x00000000
0087 #define CSOR_NAND_RAL_2         0x00800000
0088 #define CSOR_NAND_RAL_3         0x01000000
0089 #define CSOR_NAND_RAL_4         0x01800000
0090 /* Page Size 512b, 2k, 4k */
0091 #define CSOR_NAND_PGS_MASK      0x00180000
0092 #define CSOR_NAND_PGS_SHIFT     16
0093 #define CSOR_NAND_PGS_512       0x00000000
0094 #define CSOR_NAND_PGS_2K        0x00080000
0095 #define CSOR_NAND_PGS_4K        0x00100000
0096 #define CSOR_NAND_PGS_8K        0x00180000
0097 /* Spare region Size */
0098 #define CSOR_NAND_SPRZ_MASK     0x0000E000
0099 #define CSOR_NAND_SPRZ_SHIFT        13
0100 #define CSOR_NAND_SPRZ_16       0x00000000
0101 #define CSOR_NAND_SPRZ_64       0x00002000
0102 #define CSOR_NAND_SPRZ_128      0x00004000
0103 #define CSOR_NAND_SPRZ_210      0x00006000
0104 #define CSOR_NAND_SPRZ_218      0x00008000
0105 #define CSOR_NAND_SPRZ_224      0x0000A000
0106 #define CSOR_NAND_SPRZ_CSOR_EXT     0x0000C000
0107 /* Pages Per Block */
0108 #define CSOR_NAND_PB_MASK       0x00000700
0109 #define CSOR_NAND_PB_SHIFT      8
0110 #define CSOR_NAND_PB(n)     ((__ilog2(n) - 5) << CSOR_NAND_PB_SHIFT)
0111 /* Time for Read Enable High to Output High Impedance */
0112 #define CSOR_NAND_TRHZ_MASK     0x0000001C
0113 #define CSOR_NAND_TRHZ_SHIFT        2
0114 #define CSOR_NAND_TRHZ_20       0x00000000
0115 #define CSOR_NAND_TRHZ_40       0x00000004
0116 #define CSOR_NAND_TRHZ_60       0x00000008
0117 #define CSOR_NAND_TRHZ_80       0x0000000C
0118 #define CSOR_NAND_TRHZ_100      0x00000010
0119 /* Buffer control disable */
0120 #define CSOR_NAND_BCTLD         0x00000001
0121 
0122 /*
0123  * Chip Select Option Register - NOR Flash Mode
0124  */
0125 /* Enable Address shift Mode */
0126 #define CSOR_NOR_ADM_SHFT_MODE_EN   0x80000000
0127 /* Page Read Enable from NOR device */
0128 #define CSOR_NOR_PGRD_EN        0x10000000
0129 /* AVD Toggle Enable during Burst Program */
0130 #define CSOR_NOR_AVD_TGL_PGM_EN     0x01000000
0131 /* Address Data Multiplexing Shift */
0132 #define CSOR_NOR_ADM_MASK       0x0003E000
0133 #define CSOR_NOR_ADM_SHIFT_SHIFT    13
0134 #define CSOR_NOR_ADM_SHIFT(n)   ((n) << CSOR_NOR_ADM_SHIFT_SHIFT)
0135 /* Type of the NOR device hooked */
0136 #define CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000
0137 #define CSOR_NOR_NOR_MODE_AVD_NOR   0x00000020
0138 /* Time for Read Enable High to Output High Impedance */
0139 #define CSOR_NOR_TRHZ_MASK      0x0000001C
0140 #define CSOR_NOR_TRHZ_SHIFT     2
0141 #define CSOR_NOR_TRHZ_20        0x00000000
0142 #define CSOR_NOR_TRHZ_40        0x00000004
0143 #define CSOR_NOR_TRHZ_60        0x00000008
0144 #define CSOR_NOR_TRHZ_80        0x0000000C
0145 #define CSOR_NOR_TRHZ_100       0x00000010
0146 /* Buffer control disable */
0147 #define CSOR_NOR_BCTLD          0x00000001
0148 
0149 /*
0150  * Chip Select Option Register - GPCM Mode
0151  */
0152 /* GPCM Mode - Normal */
0153 #define CSOR_GPCM_GPMODE_NORMAL     0x00000000
0154 /* GPCM Mode - GenericASIC */
0155 #define CSOR_GPCM_GPMODE_ASIC       0x80000000
0156 /* Parity Mode odd/even */
0157 #define CSOR_GPCM_PARITY_EVEN       0x40000000
0158 /* Parity Checking enable/disable */
0159 #define CSOR_GPCM_PAR_EN        0x20000000
0160 /* GPCM Timeout Count */
0161 #define CSOR_GPCM_GPTO_MASK     0x0F000000
0162 #define CSOR_GPCM_GPTO_SHIFT        24
0163 #define CSOR_GPCM_GPTO(n)   ((__ilog2(n) - 8) << CSOR_GPCM_GPTO_SHIFT)
0164 /* GPCM External Access Termination mode for read access */
0165 #define CSOR_GPCM_RGETA_EXT     0x00080000
0166 /* GPCM External Access Termination mode for write access */
0167 #define CSOR_GPCM_WGETA_EXT     0x00040000
0168 /* Address Data Multiplexing Shift */
0169 #define CSOR_GPCM_ADM_MASK      0x0003E000
0170 #define CSOR_GPCM_ADM_SHIFT_SHIFT   13
0171 #define CSOR_GPCM_ADM_SHIFT(n)  ((n) << CSOR_GPCM_ADM_SHIFT_SHIFT)
0172 /* Generic ASIC Parity error indication delay */
0173 #define CSOR_GPCM_GAPERRD_MASK      0x00000180
0174 #define CSOR_GPCM_GAPERRD_SHIFT     7
0175 #define CSOR_GPCM_GAPERRD(n)    (((n) - 1) << CSOR_GPCM_GAPERRD_SHIFT)
0176 /* Time for Read Enable High to Output High Impedance */
0177 #define CSOR_GPCM_TRHZ_MASK     0x0000001C
0178 #define CSOR_GPCM_TRHZ_20       0x00000000
0179 #define CSOR_GPCM_TRHZ_40       0x00000004
0180 #define CSOR_GPCM_TRHZ_60       0x00000008
0181 #define CSOR_GPCM_TRHZ_80       0x0000000C
0182 #define CSOR_GPCM_TRHZ_100      0x00000010
0183 /* Buffer control disable */
0184 #define CSOR_GPCM_BCTLD         0x00000001
0185 
0186 /*
0187  * Ready Busy Status Register (RB_STAT)
0188  */
0189 /* CSn is READY */
0190 #define IFC_RB_STAT_READY_CS0       0x80000000
0191 #define IFC_RB_STAT_READY_CS1       0x40000000
0192 #define IFC_RB_STAT_READY_CS2       0x20000000
0193 #define IFC_RB_STAT_READY_CS3       0x10000000
0194 
0195 /*
0196  * General Control Register (GCR)
0197  */
0198 #define IFC_GCR_MASK            0x8000F800
0199 /* reset all IFC hardware */
0200 #define IFC_GCR_SOFT_RST_ALL        0x80000000
0201 /* Turnaroud Time of external buffer */
0202 #define IFC_GCR_TBCTL_TRN_TIME      0x0000F800
0203 #define IFC_GCR_TBCTL_TRN_TIME_SHIFT    11
0204 
0205 /*
0206  * Common Event and Error Status Register (CM_EVTER_STAT)
0207  */
0208 /* Chip select error */
0209 #define IFC_CM_EVTER_STAT_CSER      0x80000000
0210 
0211 /*
0212  * Common Event and Error Enable Register (CM_EVTER_EN)
0213  */
0214 /* Chip select error checking enable */
0215 #define IFC_CM_EVTER_EN_CSEREN      0x80000000
0216 
0217 /*
0218  * Common Event and Error Interrupt Enable Register (CM_EVTER_INTR_EN)
0219  */
0220 /* Chip select error interrupt enable */
0221 #define IFC_CM_EVTER_INTR_EN_CSERIREN   0x80000000
0222 
0223 /*
0224  * Common Transfer Error Attribute Register-0 (CM_ERATTR0)
0225  */
0226 /* transaction type of error Read/Write */
0227 #define IFC_CM_ERATTR0_ERTYP_READ   0x80000000
0228 #define IFC_CM_ERATTR0_ERAID        0x0FF00000
0229 #define IFC_CM_ERATTR0_ERAID_SHIFT  20
0230 #define IFC_CM_ERATTR0_ESRCID       0x0000FF00
0231 #define IFC_CM_ERATTR0_ESRCID_SHIFT 8
0232 
0233 /*
0234  * Clock Control Register (CCR)
0235  */
0236 #define IFC_CCR_MASK            0x0F0F8800
0237 /* Clock division ratio */
0238 #define IFC_CCR_CLK_DIV_MASK        0x0F000000
0239 #define IFC_CCR_CLK_DIV_SHIFT       24
0240 #define IFC_CCR_CLK_DIV(n)      ((n-1) << IFC_CCR_CLK_DIV_SHIFT)
0241 /* IFC Clock Delay */
0242 #define IFC_CCR_CLK_DLY_MASK        0x000F0000
0243 #define IFC_CCR_CLK_DLY_SHIFT       16
0244 #define IFC_CCR_CLK_DLY(n)      ((n) << IFC_CCR_CLK_DLY_SHIFT)
0245 /* Invert IFC clock before sending out */
0246 #define IFC_CCR_INV_CLK_EN      0x00008000
0247 /* Fedback IFC Clock */
0248 #define IFC_CCR_FB_IFC_CLK_SEL      0x00000800
0249 
0250 /*
0251  * Clock Status Register (CSR)
0252  */
0253 /* Clk is stable */
0254 #define IFC_CSR_CLK_STAT_STABLE     0x80000000
0255 
0256 /*
0257  * IFC_NAND Machine Specific Registers
0258  */
0259 /*
0260  * NAND Configuration Register (NCFGR)
0261  */
0262 /* Auto Boot Mode */
0263 #define IFC_NAND_NCFGR_BOOT     0x80000000
0264 /* SRAM Initialization */
0265 #define IFC_NAND_NCFGR_SRAM_INIT_EN 0x20000000
0266 /* Addressing Mode-ROW0+n/COL0 */
0267 #define IFC_NAND_NCFGR_ADDR_MODE_RC0    0x00000000
0268 /* Addressing Mode-ROW0+n/COL0+n */
0269 #define IFC_NAND_NCFGR_ADDR_MODE_RC1    0x00400000
0270 /* Number of loop iterations of FIR sequences for multi page operations */
0271 #define IFC_NAND_NCFGR_NUM_LOOP_MASK    0x0000F000
0272 #define IFC_NAND_NCFGR_NUM_LOOP_SHIFT   12
0273 #define IFC_NAND_NCFGR_NUM_LOOP(n)  ((n) << IFC_NAND_NCFGR_NUM_LOOP_SHIFT)
0274 /* Number of wait cycles */
0275 #define IFC_NAND_NCFGR_NUM_WAIT_MASK    0x000000FF
0276 #define IFC_NAND_NCFGR_NUM_WAIT_SHIFT   0
0277 
0278 /*
0279  * NAND Flash Command Registers (NAND_FCR0/NAND_FCR1)
0280  */
0281 /* General purpose FCM flash command bytes CMD0-CMD7 */
0282 #define IFC_NAND_FCR0_CMD0      0xFF000000
0283 #define IFC_NAND_FCR0_CMD0_SHIFT    24
0284 #define IFC_NAND_FCR0_CMD1      0x00FF0000
0285 #define IFC_NAND_FCR0_CMD1_SHIFT    16
0286 #define IFC_NAND_FCR0_CMD2      0x0000FF00
0287 #define IFC_NAND_FCR0_CMD2_SHIFT    8
0288 #define IFC_NAND_FCR0_CMD3      0x000000FF
0289 #define IFC_NAND_FCR0_CMD3_SHIFT    0
0290 #define IFC_NAND_FCR1_CMD4      0xFF000000
0291 #define IFC_NAND_FCR1_CMD4_SHIFT    24
0292 #define IFC_NAND_FCR1_CMD5      0x00FF0000
0293 #define IFC_NAND_FCR1_CMD5_SHIFT    16
0294 #define IFC_NAND_FCR1_CMD6      0x0000FF00
0295 #define IFC_NAND_FCR1_CMD6_SHIFT    8
0296 #define IFC_NAND_FCR1_CMD7      0x000000FF
0297 #define IFC_NAND_FCR1_CMD7_SHIFT    0
0298 
0299 /*
0300  * Flash ROW and COL Address Register (ROWn, COLn)
0301  */
0302 /* Main/spare region locator */
0303 #define IFC_NAND_COL_MS         0x80000000
0304 /* Column Address */
0305 #define IFC_NAND_COL_CA_MASK        0x00000FFF
0306 
0307 /*
0308  * NAND Flash Byte Count Register (NAND_BC)
0309  */
0310 /* Byte Count for read/Write */
0311 #define IFC_NAND_BC         0x000001FF
0312 
0313 /*
0314  * NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
0315  */
0316 /* NAND Machine specific opcodes OP0-OP14*/
0317 #define IFC_NAND_FIR0_OP0       0xFC000000
0318 #define IFC_NAND_FIR0_OP0_SHIFT     26
0319 #define IFC_NAND_FIR0_OP1       0x03F00000
0320 #define IFC_NAND_FIR0_OP1_SHIFT     20
0321 #define IFC_NAND_FIR0_OP2       0x000FC000
0322 #define IFC_NAND_FIR0_OP2_SHIFT     14
0323 #define IFC_NAND_FIR0_OP3       0x00003F00
0324 #define IFC_NAND_FIR0_OP3_SHIFT     8
0325 #define IFC_NAND_FIR0_OP4       0x000000FC
0326 #define IFC_NAND_FIR0_OP4_SHIFT     2
0327 #define IFC_NAND_FIR1_OP5       0xFC000000
0328 #define IFC_NAND_FIR1_OP5_SHIFT     26
0329 #define IFC_NAND_FIR1_OP6       0x03F00000
0330 #define IFC_NAND_FIR1_OP6_SHIFT     20
0331 #define IFC_NAND_FIR1_OP7       0x000FC000
0332 #define IFC_NAND_FIR1_OP7_SHIFT     14
0333 #define IFC_NAND_FIR1_OP8       0x00003F00
0334 #define IFC_NAND_FIR1_OP8_SHIFT     8
0335 #define IFC_NAND_FIR1_OP9       0x000000FC
0336 #define IFC_NAND_FIR1_OP9_SHIFT     2
0337 #define IFC_NAND_FIR2_OP10      0xFC000000
0338 #define IFC_NAND_FIR2_OP10_SHIFT    26
0339 #define IFC_NAND_FIR2_OP11      0x03F00000
0340 #define IFC_NAND_FIR2_OP11_SHIFT    20
0341 #define IFC_NAND_FIR2_OP12      0x000FC000
0342 #define IFC_NAND_FIR2_OP12_SHIFT    14
0343 #define IFC_NAND_FIR2_OP13      0x00003F00
0344 #define IFC_NAND_FIR2_OP13_SHIFT    8
0345 #define IFC_NAND_FIR2_OP14      0x000000FC
0346 #define IFC_NAND_FIR2_OP14_SHIFT    2
0347 
0348 /*
0349  * Instruction opcodes to be programmed
0350  * in FIR registers- 6bits
0351  */
0352 enum ifc_nand_fir_opcodes {
0353     IFC_FIR_OP_NOP,
0354     IFC_FIR_OP_CA0,
0355     IFC_FIR_OP_CA1,
0356     IFC_FIR_OP_CA2,
0357     IFC_FIR_OP_CA3,
0358     IFC_FIR_OP_RA0,
0359     IFC_FIR_OP_RA1,
0360     IFC_FIR_OP_RA2,
0361     IFC_FIR_OP_RA3,
0362     IFC_FIR_OP_CMD0,
0363     IFC_FIR_OP_CMD1,
0364     IFC_FIR_OP_CMD2,
0365     IFC_FIR_OP_CMD3,
0366     IFC_FIR_OP_CMD4,
0367     IFC_FIR_OP_CMD5,
0368     IFC_FIR_OP_CMD6,
0369     IFC_FIR_OP_CMD7,
0370     IFC_FIR_OP_CW0,
0371     IFC_FIR_OP_CW1,
0372     IFC_FIR_OP_CW2,
0373     IFC_FIR_OP_CW3,
0374     IFC_FIR_OP_CW4,
0375     IFC_FIR_OP_CW5,
0376     IFC_FIR_OP_CW6,
0377     IFC_FIR_OP_CW7,
0378     IFC_FIR_OP_WBCD,
0379     IFC_FIR_OP_RBCD,
0380     IFC_FIR_OP_BTRD,
0381     IFC_FIR_OP_RDSTAT,
0382     IFC_FIR_OP_NWAIT,
0383     IFC_FIR_OP_WFR,
0384     IFC_FIR_OP_SBRD,
0385     IFC_FIR_OP_UA,
0386     IFC_FIR_OP_RB,
0387 };
0388 
0389 /*
0390  * NAND Chip Select Register (NAND_CSEL)
0391  */
0392 #define IFC_NAND_CSEL           0x0C000000
0393 #define IFC_NAND_CSEL_SHIFT     26
0394 #define IFC_NAND_CSEL_CS0       0x00000000
0395 #define IFC_NAND_CSEL_CS1       0x04000000
0396 #define IFC_NAND_CSEL_CS2       0x08000000
0397 #define IFC_NAND_CSEL_CS3       0x0C000000
0398 
0399 /*
0400  * NAND Operation Sequence Start (NANDSEQ_STRT)
0401  */
0402 /* NAND Flash Operation Start */
0403 #define IFC_NAND_SEQ_STRT_FIR_STRT  0x80000000
0404 /* Automatic Erase */
0405 #define IFC_NAND_SEQ_STRT_AUTO_ERS  0x00800000
0406 /* Automatic Program */
0407 #define IFC_NAND_SEQ_STRT_AUTO_PGM  0x00100000
0408 /* Automatic Copyback */
0409 #define IFC_NAND_SEQ_STRT_AUTO_CPB  0x00020000
0410 /* Automatic Read Operation */
0411 #define IFC_NAND_SEQ_STRT_AUTO_RD   0x00004000
0412 /* Automatic Status Read */
0413 #define IFC_NAND_SEQ_STRT_AUTO_STAT_RD  0x00000800
0414 
0415 /*
0416  * NAND Event and Error Status Register (NAND_EVTER_STAT)
0417  */
0418 /* Operation Complete */
0419 #define IFC_NAND_EVTER_STAT_OPC     0x80000000
0420 /* Flash Timeout Error */
0421 #define IFC_NAND_EVTER_STAT_FTOER   0x08000000
0422 /* Write Protect Error */
0423 #define IFC_NAND_EVTER_STAT_WPER    0x04000000
0424 /* ECC Error */
0425 #define IFC_NAND_EVTER_STAT_ECCER   0x02000000
0426 /* RCW Load Done */
0427 #define IFC_NAND_EVTER_STAT_RCW_DN  0x00008000
0428 /* Boot Loadr Done */
0429 #define IFC_NAND_EVTER_STAT_BOOT_DN 0x00004000
0430 /* Bad Block Indicator search select */
0431 #define IFC_NAND_EVTER_STAT_BBI_SRCH_SE 0x00000800
0432 
0433 /*
0434  * NAND Flash Page Read Completion Event Status Register
0435  * (PGRDCMPL_EVT_STAT)
0436  */
0437 #define PGRDCMPL_EVT_STAT_MASK      0xFFFF0000
0438 /* Small Page 0-15 Done */
0439 #define PGRDCMPL_EVT_STAT_SECTION_SP(n) (1 << (31 - (n)))
0440 /* Large Page(2K) 0-3 Done */
0441 #define PGRDCMPL_EVT_STAT_LP_2K(n)  (0xF << (28 - (n)*4))
0442 /* Large Page(4K) 0-1 Done */
0443 #define PGRDCMPL_EVT_STAT_LP_4K(n)  (0xFF << (24 - (n)*8))
0444 
0445 /*
0446  * NAND Event and Error Enable Register (NAND_EVTER_EN)
0447  */
0448 /* Operation complete event enable */
0449 #define IFC_NAND_EVTER_EN_OPC_EN    0x80000000
0450 /* Page read complete event enable */
0451 #define IFC_NAND_EVTER_EN_PGRDCMPL_EN   0x20000000
0452 /* Flash Timeout error enable */
0453 #define IFC_NAND_EVTER_EN_FTOER_EN  0x08000000
0454 /* Write Protect error enable */
0455 #define IFC_NAND_EVTER_EN_WPER_EN   0x04000000
0456 /* ECC error logging enable */
0457 #define IFC_NAND_EVTER_EN_ECCER_EN  0x02000000
0458 
0459 /*
0460  * NAND Event and Error Interrupt Enable Register (NAND_EVTER_INTR_EN)
0461  */
0462 /* Enable interrupt for operation complete */
0463 #define IFC_NAND_EVTER_INTR_OPCIR_EN        0x80000000
0464 /* Enable interrupt for Page read complete */
0465 #define IFC_NAND_EVTER_INTR_PGRDCMPLIR_EN   0x20000000
0466 /* Enable interrupt for Flash timeout error */
0467 #define IFC_NAND_EVTER_INTR_FTOERIR_EN      0x08000000
0468 /* Enable interrupt for Write protect error */
0469 #define IFC_NAND_EVTER_INTR_WPERIR_EN       0x04000000
0470 /* Enable interrupt for ECC error*/
0471 #define IFC_NAND_EVTER_INTR_ECCERIR_EN      0x02000000
0472 
0473 /*
0474  * NAND Transfer Error Attribute Register-0 (NAND_ERATTR0)
0475  */
0476 #define IFC_NAND_ERATTR0_MASK       0x0C080000
0477 /* Error on CS0-3 for NAND */
0478 #define IFC_NAND_ERATTR0_ERCS_CS0   0x00000000
0479 #define IFC_NAND_ERATTR0_ERCS_CS1   0x04000000
0480 #define IFC_NAND_ERATTR0_ERCS_CS2   0x08000000
0481 #define IFC_NAND_ERATTR0_ERCS_CS3   0x0C000000
0482 /* Transaction type of error Read/Write */
0483 #define IFC_NAND_ERATTR0_ERTTYPE_READ   0x00080000
0484 
0485 /*
0486  * NAND Flash Status Register (NAND_FSR)
0487  */
0488 /* First byte of data read from read status op */
0489 #define IFC_NAND_NFSR_RS0       0xFF000000
0490 /* Second byte of data read from read status op */
0491 #define IFC_NAND_NFSR_RS1       0x00FF0000
0492 
0493 /*
0494  * ECC Error Status Registers (ECCSTAT0-ECCSTAT3)
0495  */
0496 /* Number of ECC errors on sector n (n = 0-15) */
0497 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_MASK   0x0F000000
0498 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR0_SHIFT  24
0499 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_MASK   0x000F0000
0500 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR1_SHIFT  16
0501 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_MASK   0x00000F00
0502 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR2_SHIFT  8
0503 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_MASK   0x0000000F
0504 #define IFC_NAND_ECCSTAT0_ERRCNT_SECTOR3_SHIFT  0
0505 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_MASK   0x0F000000
0506 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR4_SHIFT  24
0507 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_MASK   0x000F0000
0508 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR5_SHIFT  16
0509 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_MASK   0x00000F00
0510 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR6_SHIFT  8
0511 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_MASK   0x0000000F
0512 #define IFC_NAND_ECCSTAT1_ERRCNT_SECTOR7_SHIFT  0
0513 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_MASK   0x0F000000
0514 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR8_SHIFT  24
0515 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_MASK   0x000F0000
0516 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR9_SHIFT  16
0517 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_MASK  0x00000F00
0518 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR10_SHIFT 8
0519 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_MASK  0x0000000F
0520 #define IFC_NAND_ECCSTAT2_ERRCNT_SECTOR11_SHIFT 0
0521 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_MASK  0x0F000000
0522 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR12_SHIFT 24
0523 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_MASK  0x000F0000
0524 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR13_SHIFT 16
0525 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_MASK  0x00000F00
0526 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR14_SHIFT 8
0527 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_MASK  0x0000000F
0528 #define IFC_NAND_ECCSTAT3_ERRCNT_SECTOR15_SHIFT 0
0529 
0530 /*
0531  * NAND Control Register (NANDCR)
0532  */
0533 #define IFC_NAND_NCR_FTOCNT_MASK    0x1E000000
0534 #define IFC_NAND_NCR_FTOCNT_SHIFT   25
0535 #define IFC_NAND_NCR_FTOCNT(n)  ((_ilog2(n) - 8)  << IFC_NAND_NCR_FTOCNT_SHIFT)
0536 
0537 /*
0538  * NAND_AUTOBOOT_TRGR
0539  */
0540 /* Trigger RCW load */
0541 #define IFC_NAND_AUTOBOOT_TRGR_RCW_LD   0x80000000
0542 /* Trigget Auto Boot */
0543 #define IFC_NAND_AUTOBOOT_TRGR_BOOT_LD  0x20000000
0544 
0545 /*
0546  * NAND_MDR
0547  */
0548 /* 1st read data byte when opcode SBRD */
0549 #define IFC_NAND_MDR_RDATA0     0xFF000000
0550 /* 2nd read data byte when opcode SBRD */
0551 #define IFC_NAND_MDR_RDATA1     0x00FF0000
0552 
0553 /*
0554  * NOR Machine Specific Registers
0555  */
0556 /*
0557  * NOR Event and Error Status Register (NOR_EVTER_STAT)
0558  */
0559 /* NOR Command Sequence Operation Complete */
0560 #define IFC_NOR_EVTER_STAT_OPC_NOR  0x80000000
0561 /* Write Protect Error */
0562 #define IFC_NOR_EVTER_STAT_WPER     0x04000000
0563 /* Command Sequence Timeout Error */
0564 #define IFC_NOR_EVTER_STAT_STOER    0x01000000
0565 
0566 /*
0567  * NOR Event and Error Enable Register (NOR_EVTER_EN)
0568  */
0569 /* NOR Command Seq complete event enable */
0570 #define IFC_NOR_EVTER_EN_OPCEN_NOR  0x80000000
0571 /* Write Protect Error Checking Enable */
0572 #define IFC_NOR_EVTER_EN_WPEREN     0x04000000
0573 /* Timeout Error Enable */
0574 #define IFC_NOR_EVTER_EN_STOEREN    0x01000000
0575 
0576 /*
0577  * NOR Event and Error Interrupt Enable Register (NOR_EVTER_INTR_EN)
0578  */
0579 /* Enable interrupt for OPC complete */
0580 #define IFC_NOR_EVTER_INTR_OPCEN_NOR    0x80000000
0581 /* Enable interrupt for write protect error */
0582 #define IFC_NOR_EVTER_INTR_WPEREN   0x04000000
0583 /* Enable interrupt for timeout error */
0584 #define IFC_NOR_EVTER_INTR_STOEREN  0x01000000
0585 
0586 /*
0587  * NOR Transfer Error Attribute Register-0 (NOR_ERATTR0)
0588  */
0589 /* Source ID for error transaction */
0590 #define IFC_NOR_ERATTR0_ERSRCID     0xFF000000
0591 /* AXI ID for error transation */
0592 #define IFC_NOR_ERATTR0_ERAID       0x000FF000
0593 /* Chip select corresponds to NOR error */
0594 #define IFC_NOR_ERATTR0_ERCS_CS0    0x00000000
0595 #define IFC_NOR_ERATTR0_ERCS_CS1    0x00000010
0596 #define IFC_NOR_ERATTR0_ERCS_CS2    0x00000020
0597 #define IFC_NOR_ERATTR0_ERCS_CS3    0x00000030
0598 /* Type of transaction read/write */
0599 #define IFC_NOR_ERATTR0_ERTYPE_READ 0x00000001
0600 
0601 /*
0602  * NOR Transfer Error Attribute Register-2 (NOR_ERATTR2)
0603  */
0604 #define IFC_NOR_ERATTR2_ER_NUM_PHASE_EXP    0x000F0000
0605 #define IFC_NOR_ERATTR2_ER_NUM_PHASE_PER    0x00000F00
0606 
0607 /*
0608  * NOR Control Register (NORCR)
0609  */
0610 #define IFC_NORCR_MASK          0x0F0F0000
0611 /* No. of Address/Data Phase */
0612 #define IFC_NORCR_NUM_PHASE_MASK    0x0F000000
0613 #define IFC_NORCR_NUM_PHASE_SHIFT   24
0614 #define IFC_NORCR_NUM_PHASE(n)  ((n-1) << IFC_NORCR_NUM_PHASE_SHIFT)
0615 /* Sequence Timeout Count */
0616 #define IFC_NORCR_STOCNT_MASK       0x000F0000
0617 #define IFC_NORCR_STOCNT_SHIFT      16
0618 #define IFC_NORCR_STOCNT(n) ((__ilog2(n) - 8) << IFC_NORCR_STOCNT_SHIFT)
0619 
0620 /*
0621  * GPCM Machine specific registers
0622  */
0623 /*
0624  * GPCM Event and Error Status Register (GPCM_EVTER_STAT)
0625  */
0626 /* Timeout error */
0627 #define IFC_GPCM_EVTER_STAT_TOER    0x04000000
0628 /* Parity error */
0629 #define IFC_GPCM_EVTER_STAT_PER     0x01000000
0630 
0631 /*
0632  * GPCM Event and Error Enable Register (GPCM_EVTER_EN)
0633  */
0634 /* Timeout error enable */
0635 #define IFC_GPCM_EVTER_EN_TOER_EN   0x04000000
0636 /* Parity error enable */
0637 #define IFC_GPCM_EVTER_EN_PER_EN    0x01000000
0638 
0639 /*
0640  * GPCM Event and Error Interrupt Enable Register (GPCM_EVTER_INTR_EN)
0641  */
0642 /* Enable Interrupt for timeout error */
0643 #define IFC_GPCM_EEIER_TOERIR_EN    0x04000000
0644 /* Enable Interrupt for Parity error */
0645 #define IFC_GPCM_EEIER_PERIR_EN     0x01000000
0646 
0647 /*
0648  * GPCM Transfer Error Attribute Register-0 (GPCM_ERATTR0)
0649  */
0650 /* Source ID for error transaction */
0651 #define IFC_GPCM_ERATTR0_ERSRCID    0xFF000000
0652 /* AXI ID for error transaction */
0653 #define IFC_GPCM_ERATTR0_ERAID      0x000FF000
0654 /* Chip select corresponds to GPCM error */
0655 #define IFC_GPCM_ERATTR0_ERCS_CS0   0x00000000
0656 #define IFC_GPCM_ERATTR0_ERCS_CS1   0x00000040
0657 #define IFC_GPCM_ERATTR0_ERCS_CS2   0x00000080
0658 #define IFC_GPCM_ERATTR0_ERCS_CS3   0x000000C0
0659 /* Type of transaction read/Write */
0660 #define IFC_GPCM_ERATTR0_ERTYPE_READ    0x00000001
0661 
0662 /*
0663  * GPCM Transfer Error Attribute Register-2 (GPCM_ERATTR2)
0664  */
0665 /* On which beat of address/data parity error is observed */
0666 #define IFC_GPCM_ERATTR2_PERR_BEAT      0x00000C00
0667 /* Parity Error on byte */
0668 #define IFC_GPCM_ERATTR2_PERR_BYTE      0x000000F0
0669 /* Parity Error reported in addr or data phase */
0670 #define IFC_GPCM_ERATTR2_PERR_DATA_PHASE    0x00000001
0671 
0672 /*
0673  * GPCM Status Register (GPCM_STAT)
0674  */
0675 #define IFC_GPCM_STAT_BSY       0x80000000  /* GPCM is busy */
0676 
0677 /*
0678  * IFC Controller NAND Machine registers
0679  */
0680 struct fsl_ifc_nand {
0681     __be32 ncfgr;
0682     u32 res1[0x4];
0683     __be32 nand_fcr0;
0684     __be32 nand_fcr1;
0685     u32 res2[0x8];
0686     __be32 row0;
0687     u32 res3;
0688     __be32 col0;
0689     u32 res4;
0690     __be32 row1;
0691     u32 res5;
0692     __be32 col1;
0693     u32 res6;
0694     __be32 row2;
0695     u32 res7;
0696     __be32 col2;
0697     u32 res8;
0698     __be32 row3;
0699     u32 res9;
0700     __be32 col3;
0701     u32 res10[0x24];
0702     __be32 nand_fbcr;
0703     u32 res11;
0704     __be32 nand_fir0;
0705     __be32 nand_fir1;
0706     __be32 nand_fir2;
0707     u32 res12[0x10];
0708     __be32 nand_csel;
0709     u32 res13;
0710     __be32 nandseq_strt;
0711     u32 res14;
0712     __be32 nand_evter_stat;
0713     u32 res15;
0714     __be32 pgrdcmpl_evt_stat;
0715     u32 res16[0x2];
0716     __be32 nand_evter_en;
0717     u32 res17[0x2];
0718     __be32 nand_evter_intr_en;
0719     __be32 nand_vol_addr_stat;
0720     u32 res18;
0721     __be32 nand_erattr0;
0722     __be32 nand_erattr1;
0723     u32 res19[0x10];
0724     __be32 nand_fsr;
0725     u32 res20;
0726     __be32 nand_eccstat[8];
0727     u32 res21[0x1c];
0728     __be32 nanndcr;
0729     u32 res22[0x2];
0730     __be32 nand_autoboot_trgr;
0731     u32 res23;
0732     __be32 nand_mdr;
0733     u32 res24[0x1C];
0734     __be32 nand_dll_lowcfg0;
0735     __be32 nand_dll_lowcfg1;
0736     u32 res25;
0737     __be32 nand_dll_lowstat;
0738     u32 res26[0x3c];
0739 };
0740 
0741 /*
0742  * IFC controller NOR Machine registers
0743  */
0744 struct fsl_ifc_nor {
0745     __be32 nor_evter_stat;
0746     u32 res1[0x2];
0747     __be32 nor_evter_en;
0748     u32 res2[0x2];
0749     __be32 nor_evter_intr_en;
0750     u32 res3[0x2];
0751     __be32 nor_erattr0;
0752     __be32 nor_erattr1;
0753     __be32 nor_erattr2;
0754     u32 res4[0x4];
0755     __be32 norcr;
0756     u32 res5[0xEF];
0757 };
0758 
0759 /*
0760  * IFC controller GPCM Machine registers
0761  */
0762 struct fsl_ifc_gpcm {
0763     __be32 gpcm_evter_stat;
0764     u32 res1[0x2];
0765     __be32 gpcm_evter_en;
0766     u32 res2[0x2];
0767     __be32 gpcm_evter_intr_en;
0768     u32 res3[0x2];
0769     __be32 gpcm_erattr0;
0770     __be32 gpcm_erattr1;
0771     __be32 gpcm_erattr2;
0772     __be32 gpcm_stat;
0773 };
0774 
0775 /*
0776  * IFC Controller Registers
0777  */
0778 struct fsl_ifc_global {
0779     __be32 ifc_rev;
0780     u32 res1[0x2];
0781     struct {
0782         __be32 cspr_ext;
0783         __be32 cspr;
0784         u32 res2;
0785     } cspr_cs[FSL_IFC_BANK_COUNT];
0786     u32 res3[0xd];
0787     struct {
0788         __be32 amask;
0789         u32 res4[0x2];
0790     } amask_cs[FSL_IFC_BANK_COUNT];
0791     u32 res5[0xc];
0792     struct {
0793         __be32 csor;
0794         __be32 csor_ext;
0795         u32 res6;
0796     } csor_cs[FSL_IFC_BANK_COUNT];
0797     u32 res7[0xc];
0798     struct {
0799         __be32 ftim[4];
0800         u32 res8[0x8];
0801     } ftim_cs[FSL_IFC_BANK_COUNT];
0802     u32 res9[0x30];
0803     __be32 rb_stat;
0804     __be32 rb_map;
0805     __be32 wb_map;
0806     __be32 ifc_gcr;
0807     u32 res10[0x2];
0808     __be32 cm_evter_stat;
0809     u32 res11[0x2];
0810     __be32 cm_evter_en;
0811     u32 res12[0x2];
0812     __be32 cm_evter_intr_en;
0813     u32 res13[0x2];
0814     __be32 cm_erattr0;
0815     __be32 cm_erattr1;
0816     u32 res14[0x2];
0817     __be32 ifc_ccr;
0818     __be32 ifc_csr;
0819     __be32 ddr_ccr_low;
0820 };
0821 
0822 
0823 struct fsl_ifc_runtime {
0824     struct fsl_ifc_nand ifc_nand;
0825     struct fsl_ifc_nor ifc_nor;
0826     struct fsl_ifc_gpcm ifc_gpcm;
0827 };
0828 
0829 extern unsigned int convert_ifc_address(phys_addr_t addr_base);
0830 extern int fsl_ifc_find(phys_addr_t addr_base);
0831 
0832 /* overview of the fsl ifc controller */
0833 
0834 struct fsl_ifc_ctrl {
0835     /* device info */
0836     struct device           *dev;
0837     struct fsl_ifc_global __iomem   *gregs;
0838     struct fsl_ifc_runtime __iomem  *rregs;
0839     int             irq;
0840     int             nand_irq;
0841     spinlock_t          lock;
0842     void                *nand;
0843     int             version;
0844     int             banks;
0845 
0846     u32 nand_stat;
0847     wait_queue_head_t nand_wait;
0848     bool little_endian;
0849 };
0850 
0851 extern struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;
0852 
0853 static inline u32 ifc_in32(void __iomem *addr)
0854 {
0855     u32 val;
0856 
0857     if (fsl_ifc_ctrl_dev->little_endian)
0858         val = ioread32(addr);
0859     else
0860         val = ioread32be(addr);
0861 
0862     return val;
0863 }
0864 
0865 static inline u16 ifc_in16(void __iomem *addr)
0866 {
0867     u16 val;
0868 
0869     if (fsl_ifc_ctrl_dev->little_endian)
0870         val = ioread16(addr);
0871     else
0872         val = ioread16be(addr);
0873 
0874     return val;
0875 }
0876 
0877 static inline u8 ifc_in8(void __iomem *addr)
0878 {
0879     return ioread8(addr);
0880 }
0881 
0882 static inline void ifc_out32(u32 val, void __iomem *addr)
0883 {
0884     if (fsl_ifc_ctrl_dev->little_endian)
0885         iowrite32(val, addr);
0886     else
0887         iowrite32be(val, addr);
0888 }
0889 
0890 static inline void ifc_out16(u16 val, void __iomem *addr)
0891 {
0892     if (fsl_ifc_ctrl_dev->little_endian)
0893         iowrite16(val, addr);
0894     else
0895         iowrite16be(val, addr);
0896 }
0897 
0898 static inline void ifc_out8(u8 val, void __iomem *addr)
0899 {
0900     iowrite8(val, addr);
0901 }
0902 
0903 #endif /* __ASM_FSL_IFC_H */