1*cfcc706cSMiquel Raynal /* 2*cfcc706cSMiquel Raynal * (C) Copyright 2011 NVIDIA Corporation <www.nvidia.com> 3*cfcc706cSMiquel Raynal * 4*cfcc706cSMiquel Raynal * SPDX-License-Identifier: GPL-2.0+ 5*cfcc706cSMiquel Raynal */ 6*cfcc706cSMiquel Raynal 7*cfcc706cSMiquel Raynal /* register offset */ 8*cfcc706cSMiquel Raynal #define COMMAND_0 0x00 9*cfcc706cSMiquel Raynal #define CMD_GO (1 << 31) 10*cfcc706cSMiquel Raynal #define CMD_CLE (1 << 30) 11*cfcc706cSMiquel Raynal #define CMD_ALE (1 << 29) 12*cfcc706cSMiquel Raynal #define CMD_PIO (1 << 28) 13*cfcc706cSMiquel Raynal #define CMD_TX (1 << 27) 14*cfcc706cSMiquel Raynal #define CMD_RX (1 << 26) 15*cfcc706cSMiquel Raynal #define CMD_SEC_CMD (1 << 25) 16*cfcc706cSMiquel Raynal #define CMD_AFT_DAT_MASK (1 << 24) 17*cfcc706cSMiquel Raynal #define CMD_AFT_DAT_DISABLE 0 18*cfcc706cSMiquel Raynal #define CMD_AFT_DAT_ENABLE (1 << 24) 19*cfcc706cSMiquel Raynal #define CMD_TRANS_SIZE_SHIFT 20 20*cfcc706cSMiquel Raynal #define CMD_TRANS_SIZE_PAGE 8 21*cfcc706cSMiquel Raynal #define CMD_A_VALID (1 << 19) 22*cfcc706cSMiquel Raynal #define CMD_B_VALID (1 << 18) 23*cfcc706cSMiquel Raynal #define CMD_RD_STATUS_CHK (1 << 17) 24*cfcc706cSMiquel Raynal #define CMD_R_BSY_CHK (1 << 16) 25*cfcc706cSMiquel Raynal #define CMD_CE7 (1 << 15) 26*cfcc706cSMiquel Raynal #define CMD_CE6 (1 << 14) 27*cfcc706cSMiquel Raynal #define CMD_CE5 (1 << 13) 28*cfcc706cSMiquel Raynal #define CMD_CE4 (1 << 12) 29*cfcc706cSMiquel Raynal #define CMD_CE3 (1 << 11) 30*cfcc706cSMiquel Raynal #define CMD_CE2 (1 << 10) 31*cfcc706cSMiquel Raynal #define CMD_CE1 (1 << 9) 32*cfcc706cSMiquel Raynal #define CMD_CE0 (1 << 8) 33*cfcc706cSMiquel Raynal #define CMD_CLE_BYTE_SIZE_SHIFT 4 34*cfcc706cSMiquel Raynal enum { 35*cfcc706cSMiquel Raynal CMD_CLE_BYTES1 = 0, 36*cfcc706cSMiquel Raynal CMD_CLE_BYTES2, 37*cfcc706cSMiquel Raynal CMD_CLE_BYTES3, 38*cfcc706cSMiquel Raynal CMD_CLE_BYTES4, 39*cfcc706cSMiquel Raynal }; 40*cfcc706cSMiquel Raynal #define CMD_ALE_BYTE_SIZE_SHIFT 0 41*cfcc706cSMiquel Raynal enum { 42*cfcc706cSMiquel Raynal CMD_ALE_BYTES1 = 0, 43*cfcc706cSMiquel Raynal CMD_ALE_BYTES2, 44*cfcc706cSMiquel Raynal CMD_ALE_BYTES3, 45*cfcc706cSMiquel Raynal CMD_ALE_BYTES4, 46*cfcc706cSMiquel Raynal CMD_ALE_BYTES5, 47*cfcc706cSMiquel Raynal CMD_ALE_BYTES6, 48*cfcc706cSMiquel Raynal CMD_ALE_BYTES7, 49*cfcc706cSMiquel Raynal CMD_ALE_BYTES8 50*cfcc706cSMiquel Raynal }; 51*cfcc706cSMiquel Raynal 52*cfcc706cSMiquel Raynal #define STATUS_0 0x04 53*cfcc706cSMiquel Raynal #define STATUS_RBSY0 (1 << 8) 54*cfcc706cSMiquel Raynal 55*cfcc706cSMiquel Raynal #define ISR_0 0x08 56*cfcc706cSMiquel Raynal #define ISR_IS_CMD_DONE (1 << 5) 57*cfcc706cSMiquel Raynal #define ISR_IS_ECC_ERR (1 << 4) 58*cfcc706cSMiquel Raynal 59*cfcc706cSMiquel Raynal #define IER_0 0x0C 60*cfcc706cSMiquel Raynal 61*cfcc706cSMiquel Raynal #define CFG_0 0x10 62*cfcc706cSMiquel Raynal #define CFG_HW_ECC_MASK (1 << 31) 63*cfcc706cSMiquel Raynal #define CFG_HW_ECC_DISABLE 0 64*cfcc706cSMiquel Raynal #define CFG_HW_ECC_ENABLE (1 << 31) 65*cfcc706cSMiquel Raynal #define CFG_HW_ECC_SEL_MASK (1 << 30) 66*cfcc706cSMiquel Raynal #define CFG_HW_ECC_SEL_HAMMING 0 67*cfcc706cSMiquel Raynal #define CFG_HW_ECC_SEL_RS (1 << 30) 68*cfcc706cSMiquel Raynal #define CFG_HW_ECC_CORRECTION_MASK (1 << 29) 69*cfcc706cSMiquel Raynal #define CFG_HW_ECC_CORRECTION_DISABLE 0 70*cfcc706cSMiquel Raynal #define CFG_HW_ECC_CORRECTION_ENABLE (1 << 29) 71*cfcc706cSMiquel Raynal #define CFG_PIPELINE_EN_MASK (1 << 28) 72*cfcc706cSMiquel Raynal #define CFG_PIPELINE_EN_DISABLE 0 73*cfcc706cSMiquel Raynal #define CFG_PIPELINE_EN_ENABLE (1 << 28) 74*cfcc706cSMiquel Raynal #define CFG_ECC_EN_TAG_MASK (1 << 27) 75*cfcc706cSMiquel Raynal #define CFG_ECC_EN_TAG_DISABLE 0 76*cfcc706cSMiquel Raynal #define CFG_ECC_EN_TAG_ENABLE (1 << 27) 77*cfcc706cSMiquel Raynal #define CFG_TVALUE_MASK (3 << 24) 78*cfcc706cSMiquel Raynal enum { 79*cfcc706cSMiquel Raynal CFG_TVAL4 = 0 << 24, 80*cfcc706cSMiquel Raynal CFG_TVAL6 = 1 << 24, 81*cfcc706cSMiquel Raynal CFG_TVAL8 = 2 << 24 82*cfcc706cSMiquel Raynal }; 83*cfcc706cSMiquel Raynal #define CFG_SKIP_SPARE_MASK (1 << 23) 84*cfcc706cSMiquel Raynal #define CFG_SKIP_SPARE_DISABLE 0 85*cfcc706cSMiquel Raynal #define CFG_SKIP_SPARE_ENABLE (1 << 23) 86*cfcc706cSMiquel Raynal #define CFG_COM_BSY_MASK (1 << 22) 87*cfcc706cSMiquel Raynal #define CFG_COM_BSY_DISABLE 0 88*cfcc706cSMiquel Raynal #define CFG_COM_BSY_ENABLE (1 << 22) 89*cfcc706cSMiquel Raynal #define CFG_BUS_WIDTH_MASK (1 << 21) 90*cfcc706cSMiquel Raynal #define CFG_BUS_WIDTH_8BIT 0 91*cfcc706cSMiquel Raynal #define CFG_BUS_WIDTH_16BIT (1 << 21) 92*cfcc706cSMiquel Raynal #define CFG_LPDDR1_MODE_MASK (1 << 20) 93*cfcc706cSMiquel Raynal #define CFG_LPDDR1_MODE_DISABLE 0 94*cfcc706cSMiquel Raynal #define CFG_LPDDR1_MODE_ENABLE (1 << 20) 95*cfcc706cSMiquel Raynal #define CFG_EDO_MODE_MASK (1 << 19) 96*cfcc706cSMiquel Raynal #define CFG_EDO_MODE_DISABLE 0 97*cfcc706cSMiquel Raynal #define CFG_EDO_MODE_ENABLE (1 << 19) 98*cfcc706cSMiquel Raynal #define CFG_PAGE_SIZE_SEL_MASK (7 << 16) 99*cfcc706cSMiquel Raynal enum { 100*cfcc706cSMiquel Raynal CFG_PAGE_SIZE_256 = 0 << 16, 101*cfcc706cSMiquel Raynal CFG_PAGE_SIZE_512 = 1 << 16, 102*cfcc706cSMiquel Raynal CFG_PAGE_SIZE_1024 = 2 << 16, 103*cfcc706cSMiquel Raynal CFG_PAGE_SIZE_2048 = 3 << 16, 104*cfcc706cSMiquel Raynal CFG_PAGE_SIZE_4096 = 4 << 16 105*cfcc706cSMiquel Raynal }; 106*cfcc706cSMiquel Raynal #define CFG_SKIP_SPARE_SEL_MASK (3 << 14) 107*cfcc706cSMiquel Raynal enum { 108*cfcc706cSMiquel Raynal CFG_SKIP_SPARE_SEL_4 = 0 << 14, 109*cfcc706cSMiquel Raynal CFG_SKIP_SPARE_SEL_8 = 1 << 14, 110*cfcc706cSMiquel Raynal CFG_SKIP_SPARE_SEL_12 = 2 << 14, 111*cfcc706cSMiquel Raynal CFG_SKIP_SPARE_SEL_16 = 3 << 14 112*cfcc706cSMiquel Raynal }; 113*cfcc706cSMiquel Raynal #define CFG_TAG_BYTE_SIZE_MASK 0x1FF 114*cfcc706cSMiquel Raynal 115*cfcc706cSMiquel Raynal #define TIMING_0 0x14 116*cfcc706cSMiquel Raynal #define TIMING_TRP_RESP_CNT_SHIFT 28 117*cfcc706cSMiquel Raynal #define TIMING_TRP_RESP_CNT_MASK (0xf << TIMING_TRP_RESP_CNT_SHIFT) 118*cfcc706cSMiquel Raynal #define TIMING_TWB_CNT_SHIFT 24 119*cfcc706cSMiquel Raynal #define TIMING_TWB_CNT_MASK (0xf << TIMING_TWB_CNT_SHIFT) 120*cfcc706cSMiquel Raynal #define TIMING_TCR_TAR_TRR_CNT_SHIFT 20 121*cfcc706cSMiquel Raynal #define TIMING_TCR_TAR_TRR_CNT_MASK (0xf << TIMING_TCR_TAR_TRR_CNT_SHIFT) 122*cfcc706cSMiquel Raynal #define TIMING_TWHR_CNT_SHIFT 16 123*cfcc706cSMiquel Raynal #define TIMING_TWHR_CNT_MASK (0xf << TIMING_TWHR_CNT_SHIFT) 124*cfcc706cSMiquel Raynal #define TIMING_TCS_CNT_SHIFT 14 125*cfcc706cSMiquel Raynal #define TIMING_TCS_CNT_MASK (3 << TIMING_TCS_CNT_SHIFT) 126*cfcc706cSMiquel Raynal #define TIMING_TWH_CNT_SHIFT 12 127*cfcc706cSMiquel Raynal #define TIMING_TWH_CNT_MASK (3 << TIMING_TWH_CNT_SHIFT) 128*cfcc706cSMiquel Raynal #define TIMING_TWP_CNT_SHIFT 8 129*cfcc706cSMiquel Raynal #define TIMING_TWP_CNT_MASK (0xf << TIMING_TWP_CNT_SHIFT) 130*cfcc706cSMiquel Raynal #define TIMING_TRH_CNT_SHIFT 4 131*cfcc706cSMiquel Raynal #define TIMING_TRH_CNT_MASK (3 << TIMING_TRH_CNT_SHIFT) 132*cfcc706cSMiquel Raynal #define TIMING_TRP_CNT_SHIFT 0 133*cfcc706cSMiquel Raynal #define TIMING_TRP_CNT_MASK (0xf << TIMING_TRP_CNT_SHIFT) 134*cfcc706cSMiquel Raynal 135*cfcc706cSMiquel Raynal #define RESP_0 0x18 136*cfcc706cSMiquel Raynal 137*cfcc706cSMiquel Raynal #define TIMING2_0 0x1C 138*cfcc706cSMiquel Raynal #define TIMING2_TADL_CNT_SHIFT 0 139*cfcc706cSMiquel Raynal #define TIMING2_TADL_CNT_MASK (0xf << TIMING2_TADL_CNT_SHIFT) 140*cfcc706cSMiquel Raynal 141*cfcc706cSMiquel Raynal #define CMD_REG1_0 0x20 142*cfcc706cSMiquel Raynal #define CMD_REG2_0 0x24 143*cfcc706cSMiquel Raynal #define ADDR_REG1_0 0x28 144*cfcc706cSMiquel Raynal #define ADDR_REG2_0 0x2C 145*cfcc706cSMiquel Raynal 146*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_0 0x30 147*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_GO_MASK (1 << 31) 148*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_GO_DISABLE 0 149*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_GO_ENABLE (1 << 31) 150*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_DIR_MASK (1 << 30) 151*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_DIR_READ 0 152*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_DIR_WRITE (1 << 30) 153*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_PERF_EN_MASK (1 << 29) 154*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_PERF_EN_DISABLE 0 155*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_PERF_EN_ENABLE (1 << 29) 156*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_REUSE_BUFFER_MASK (1 << 27) 157*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_REUSE_BUFFER_DISABLE 0 158*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_REUSE_BUFFER_ENABLE (1 << 27) 159*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_BURST_SIZE_SHIFT 24 160*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_BURST_SIZE_MASK (7 << DMA_MST_CTRL_BURST_SIZE_SHIFT) 161*cfcc706cSMiquel Raynal enum { 162*cfcc706cSMiquel Raynal DMA_MST_CTRL_BURST_1WORDS = 2 << DMA_MST_CTRL_BURST_SIZE_SHIFT, 163*cfcc706cSMiquel Raynal DMA_MST_CTRL_BURST_4WORDS = 3 << DMA_MST_CTRL_BURST_SIZE_SHIFT, 164*cfcc706cSMiquel Raynal DMA_MST_CTRL_BURST_8WORDS = 4 << DMA_MST_CTRL_BURST_SIZE_SHIFT, 165*cfcc706cSMiquel Raynal DMA_MST_CTRL_BURST_16WORDS = 5 << DMA_MST_CTRL_BURST_SIZE_SHIFT 166*cfcc706cSMiquel Raynal }; 167*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_IS_DMA_DONE (1 << 20) 168*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_A_MASK (1 << 2) 169*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_A_DISABLE 0 170*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_A_ENABLE (1 << 2) 171*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_B_MASK (1 << 1) 172*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_B_DISABLE 0 173*cfcc706cSMiquel Raynal #define DMA_MST_CTRL_EN_B_ENABLE (1 << 1) 174*cfcc706cSMiquel Raynal 175*cfcc706cSMiquel Raynal #define DMA_CFG_A_0 0x34 176*cfcc706cSMiquel Raynal #define DMA_CFG_B_0 0x38 177*cfcc706cSMiquel Raynal #define FIFO_CTRL_0 0x3C 178*cfcc706cSMiquel Raynal #define DATA_BLOCK_PTR_0 0x40 179*cfcc706cSMiquel Raynal #define TAG_PTR_0 0x44 180*cfcc706cSMiquel Raynal #define ECC_PTR_0 0x48 181*cfcc706cSMiquel Raynal 182*cfcc706cSMiquel Raynal #define DEC_STATUS_0 0x4C 183*cfcc706cSMiquel Raynal #define DEC_STATUS_A_ECC_FAIL (1 << 1) 184*cfcc706cSMiquel Raynal #define DEC_STATUS_B_ECC_FAIL (1 << 0) 185*cfcc706cSMiquel Raynal 186*cfcc706cSMiquel Raynal #define BCH_CONFIG_0 0xCC 187*cfcc706cSMiquel Raynal #define BCH_CONFIG_BCH_TVALUE_SHIFT 4 188*cfcc706cSMiquel Raynal #define BCH_CONFIG_BCH_TVALUE_MASK (3 << BCH_CONFIG_BCH_TVALUE_SHIFT) 189*cfcc706cSMiquel Raynal enum { 190*cfcc706cSMiquel Raynal BCH_CONFIG_BCH_TVAL4 = 0 << BCH_CONFIG_BCH_TVALUE_SHIFT, 191*cfcc706cSMiquel Raynal BCH_CONFIG_BCH_TVAL8 = 1 << BCH_CONFIG_BCH_TVALUE_SHIFT, 192*cfcc706cSMiquel Raynal BCH_CONFIG_BCH_TVAL14 = 2 << BCH_CONFIG_BCH_TVALUE_SHIFT, 193*cfcc706cSMiquel Raynal BCH_CONFIG_BCH_TVAL16 = 3 << BCH_CONFIG_BCH_TVALUE_SHIFT 194*cfcc706cSMiquel Raynal }; 195*cfcc706cSMiquel Raynal #define BCH_CONFIG_BCH_ECC_MASK (1 << 0) 196*cfcc706cSMiquel Raynal #define BCH_CONFIG_BCH_ECC_DISABLE 0 197*cfcc706cSMiquel Raynal #define BCH_CONFIG_BCH_ECC_ENABLE (1 << 0) 198*cfcc706cSMiquel Raynal 199*cfcc706cSMiquel Raynal #define BCH_DEC_RESULT_0 0xD0 200*cfcc706cSMiquel Raynal #define BCH_DEC_RESULT_CORRFAIL_ERR_MASK (1 << 8) 201*cfcc706cSMiquel Raynal #define BCH_DEC_RESULT_PAGE_COUNT_MASK 0xFF 202*cfcc706cSMiquel Raynal 203*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_BUF_0 0xD4 204*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_FAIL_SEC_FLAG_MASK 0xFF000000 205*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_CORR_SEC_FLAG_MASK 0x00FF0000 206*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_FAIL_TAG_MASK (1 << 14) 207*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_CORR_TAG_MASK (1 << 13) 208*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_MAX_CORR_CNT_MASK (0x1f << 8) 209*cfcc706cSMiquel Raynal #define BCH_DEC_STATUS_PAGE_NUMBER_MASK 0xFF 210*cfcc706cSMiquel Raynal 211*cfcc706cSMiquel Raynal #define LP_OPTIONS 0 212*cfcc706cSMiquel Raynal 213*cfcc706cSMiquel Raynal struct nand_ctlr { 214*cfcc706cSMiquel Raynal u32 command; /* offset 00h */ 215*cfcc706cSMiquel Raynal u32 status; /* offset 04h */ 216*cfcc706cSMiquel Raynal u32 isr; /* offset 08h */ 217*cfcc706cSMiquel Raynal u32 ier; /* offset 0Ch */ 218*cfcc706cSMiquel Raynal u32 config; /* offset 10h */ 219*cfcc706cSMiquel Raynal u32 timing; /* offset 14h */ 220*cfcc706cSMiquel Raynal u32 resp; /* offset 18h */ 221*cfcc706cSMiquel Raynal u32 timing2; /* offset 1Ch */ 222*cfcc706cSMiquel Raynal u32 cmd_reg1; /* offset 20h */ 223*cfcc706cSMiquel Raynal u32 cmd_reg2; /* offset 24h */ 224*cfcc706cSMiquel Raynal u32 addr_reg1; /* offset 28h */ 225*cfcc706cSMiquel Raynal u32 addr_reg2; /* offset 2Ch */ 226*cfcc706cSMiquel Raynal u32 dma_mst_ctrl; /* offset 30h */ 227*cfcc706cSMiquel Raynal u32 dma_cfg_a; /* offset 34h */ 228*cfcc706cSMiquel Raynal u32 dma_cfg_b; /* offset 38h */ 229*cfcc706cSMiquel Raynal u32 fifo_ctrl; /* offset 3Ch */ 230*cfcc706cSMiquel Raynal u32 data_block_ptr; /* offset 40h */ 231*cfcc706cSMiquel Raynal u32 tag_ptr; /* offset 44h */ 232*cfcc706cSMiquel Raynal u32 resv1; /* offset 48h */ 233*cfcc706cSMiquel Raynal u32 dec_status; /* offset 4Ch */ 234*cfcc706cSMiquel Raynal u32 hwstatus_cmd; /* offset 50h */ 235*cfcc706cSMiquel Raynal u32 hwstatus_mask; /* offset 54h */ 236*cfcc706cSMiquel Raynal u32 resv2[29]; 237*cfcc706cSMiquel Raynal u32 bch_config; /* offset CCh */ 238*cfcc706cSMiquel Raynal u32 bch_dec_result; /* offset D0h */ 239*cfcc706cSMiquel Raynal u32 bch_dec_status_buf; 240*cfcc706cSMiquel Raynal /* offset D4h */ 241*cfcc706cSMiquel Raynal }; 242