1*b28c29d0SBiju Das /* 2*b28c29d0SBiju Das * Copyright (c) 2015-2020, Renesas Electronics Corporation. All rights reserved. 3*b28c29d0SBiju Das * 4*b28c29d0SBiju Das * SPDX-License-Identifier: BSD-3-Clause 5*b28c29d0SBiju Das */ 6*b28c29d0SBiju Das 7*b28c29d0SBiju Das #ifndef EMMC_STD_H 8*b28c29d0SBiju Das #define EMMC_STD_H 9*b28c29d0SBiju Das 10*b28c29d0SBiju Das #include "emmc_hal.h" 11*b28c29d0SBiju Das 12*b28c29d0SBiju Das #ifndef FALSE 13*b28c29d0SBiju Das #define FALSE 0U 14*b28c29d0SBiju Das #endif 15*b28c29d0SBiju Das #ifndef TRUE 16*b28c29d0SBiju Das #define TRUE 1U 17*b28c29d0SBiju Das #endif 18*b28c29d0SBiju Das 19*b28c29d0SBiju Das /* 64bit registers */ 20*b28c29d0SBiju Das #define SETR_64(r, v) (*(volatile uint64_t *)(r) = (v)) 21*b28c29d0SBiju Das #define GETR_64(r) (*(volatile uint64_t *)(r)) 22*b28c29d0SBiju Das 23*b28c29d0SBiju Das /* 32bit registers */ 24*b28c29d0SBiju Das #define SETR_32(r, v) (*(volatile uint32_t *)(r) = (v)) 25*b28c29d0SBiju Das #define GETR_32(r) (*(volatile uint32_t *)(r)) 26*b28c29d0SBiju Das 27*b28c29d0SBiju Das /* 16bit registers */ 28*b28c29d0SBiju Das #define SETR_16(r, v) (*(volatile uint16_t *)(r) = (v)) 29*b28c29d0SBiju Das #define GETR_16(r) (*(volatile uint16_t *)(r)) 30*b28c29d0SBiju Das 31*b28c29d0SBiju Das /* 8bit registers */ 32*b28c29d0SBiju Das #define SETR_8(r, v) (*(volatile uint8_t *)(r) = (v)) 33*b28c29d0SBiju Das #define GETR_8(r) (*(volatile uint8_t *)(r)) 34*b28c29d0SBiju Das 35*b28c29d0SBiju Das /* CSD register Macros */ 36*b28c29d0SBiju Das #define EMMC_GET_CID(x, y) (emmc_bit_field(mmc_drv_obj.cid_data, (x), (y))) 37*b28c29d0SBiju Das 38*b28c29d0SBiju Das #define EMMC_CID_MID() (EMMC_GET_CID(127, 120)) 39*b28c29d0SBiju Das #define EMMC_CID_CBX() (EMMC_GET_CID(113, 112)) 40*b28c29d0SBiju Das #define EMMC_CID_OID() (EMMC_GET_CID(111, 104)) 41*b28c29d0SBiju Das #define EMMC_CID_PNM1() (EMMC_GET_CID(103, 88)) 42*b28c29d0SBiju Das #define EMMC_CID_PNM2() (EMMC_GET_CID(87, 56)) 43*b28c29d0SBiju Das #define EMMC_CID_PRV() (EMMC_GET_CID(55, 48)) 44*b28c29d0SBiju Das #define EMMC_CID_PSN() (EMMC_GET_CID(47, 16)) 45*b28c29d0SBiju Das #define EMMC_CID_MDT() (EMMC_GET_CID(15, 8)) 46*b28c29d0SBiju Das #define EMMC_CID_CRC() (EMMC_GET_CID(7, 1)) 47*b28c29d0SBiju Das 48*b28c29d0SBiju Das /* CSD register Macros */ 49*b28c29d0SBiju Das #define EMMC_GET_CSD(x, y) (emmc_bit_field(mmc_drv_obj.csd_data, (x), (y))) 50*b28c29d0SBiju Das 51*b28c29d0SBiju Das #define EMMC_CSD_CSD_STRUCTURE() (EMMC_GET_CSD(127, 126)) 52*b28c29d0SBiju Das #define EMMC_CSD_SPEC_VARS() (EMMC_GET_CSD(125, 122)) 53*b28c29d0SBiju Das #define EMMC_CSD_TAAC() (EMMC_GET_CSD(119, 112)) 54*b28c29d0SBiju Das #define EMMC_CSD_NSAC() (EMMC_GET_CSD(111, 104)) 55*b28c29d0SBiju Das #define EMMC_CSD_TRAN_SPEED() (EMMC_GET_CSD(103, 96)) 56*b28c29d0SBiju Das #define EMMC_CSD_CCC() (EMMC_GET_CSD(95, 84)) 57*b28c29d0SBiju Das #define EMMC_CSD_READ_BL_LEN() (EMMC_GET_CSD(83, 80)) 58*b28c29d0SBiju Das #define EMMC_CSD_READ_BL_PARTIAL() (EMMC_GET_CSD(79, 79)) 59*b28c29d0SBiju Das #define EMMC_CSD_WRITE_BLK_MISALIGN() (EMMC_GET_CSD(78, 78)) 60*b28c29d0SBiju Das #define EMMC_CSD_READ_BLK_MISALIGN() (EMMC_GET_CSD(77, 77)) 61*b28c29d0SBiju Das #define EMMC_CSD_DSR_IMP() (EMMC_GET_CSD(76, 76)) 62*b28c29d0SBiju Das #define EMMC_CSD_C_SIZE() (EMMC_GET_CSD(73, 62)) 63*b28c29d0SBiju Das #define EMMC_CSD_VDD_R_CURR_MIN() (EMMC_GET_CSD(61, 59)) 64*b28c29d0SBiju Das #define EMMC_CSD_VDD_R_CURR_MAX() (EMMC_GET_CSD(58, 56)) 65*b28c29d0SBiju Das #define EMMC_CSD_VDD_W_CURR_MIN() (EMMC_GET_CSD(55, 53)) 66*b28c29d0SBiju Das #define EMMC_CSD_VDD_W_CURR_MAX() (EMMC_GET_CSD(52, 50)) 67*b28c29d0SBiju Das #define EMMC_CSD_C_SIZE_MULT() (EMMC_GET_CSD(49, 47)) 68*b28c29d0SBiju Das #define EMMC_CSD_ERASE_GRP_SIZE() (EMMC_GET_CSD(46, 42)) 69*b28c29d0SBiju Das #define EMMC_CSD_ERASE_GRP_MULT() (EMMC_GET_CSD(41, 37)) 70*b28c29d0SBiju Das #define EMMC_CSD_WP_GRP_SIZE() (EMMC_GET_CSD(36, 32)) 71*b28c29d0SBiju Das #define EMMC_CSD_WP_GRP_ENABLE() (EMMC_GET_CSD(31, 31)) 72*b28c29d0SBiju Das #define EMMC_CSD_DEFALT_ECC() (EMMC_GET_CSD(30, 29)) 73*b28c29d0SBiju Das #define EMMC_CSD_R2W_FACTOR() (EMMC_GET_CSD(28, 26)) 74*b28c29d0SBiju Das #define EMMC_CSD_WRITE_BL_LEN() (EMMC_GET_CSD(25, 22)) 75*b28c29d0SBiju Das #define EMMC_CSD_WRITE_BL_PARTIAL() (EMMC_GET_CSD(21, 21)) 76*b28c29d0SBiju Das #define EMMC_CSD_CONTENT_PROT_APP() (EMMC_GET_CSD(16, 16)) 77*b28c29d0SBiju Das #define EMMC_CSD_FILE_FORMAT_GRP() (EMMC_GET_CSD(15, 15)) 78*b28c29d0SBiju Das #define EMMC_CSD_COPY() (EMMC_GET_CSD(14, 14)) 79*b28c29d0SBiju Das #define EMMC_CSD_PERM_WRITE_PROTECT() (EMMC_GET_CSD(13, 13)) 80*b28c29d0SBiju Das #define EMMC_CSD_TMP_WRITE_PROTECT() (EMMC_GET_CSD(12, 12)) 81*b28c29d0SBiju Das #define EMMC_CSD_FILE_FORMAT() (EMMC_GET_CSD(11, 10)) 82*b28c29d0SBiju Das #define EMMC_CSD_ECC() (EMMC_GET_CSD(9, 8)) 83*b28c29d0SBiju Das #define EMMC_CSD_CRC() (EMMC_GET_CSD(7, 1)) 84*b28c29d0SBiju Das 85*b28c29d0SBiju Das /* sector access */ 86*b28c29d0SBiju Das #define EMMC_4B_BOUNDARY_CHECK_MASK 0x00000003 87*b28c29d0SBiju Das #define EMMC_SECTOR_SIZE_SHIFT 9U /* 512 = 2^9 */ 88*b28c29d0SBiju Das #define EMMC_SECTOR_SIZE 512 89*b28c29d0SBiju Das #define EMMC_BLOCK_LENGTH 512 90*b28c29d0SBiju Das #define EMMC_BLOCK_LENGTH_DW 128 91*b28c29d0SBiju Das #define EMMC_BUF_SIZE_SHIFT 3U /* 8byte = 2^3 */ 92*b28c29d0SBiju Das 93*b28c29d0SBiju Das /* eMMC specification clock */ 94*b28c29d0SBiju Das #define EMMC_CLOCK_SPEC_400K 400000UL /* initialize clock 400KHz */ 95*b28c29d0SBiju Das #define EMMC_CLOCK_SPEC_20M 20000000UL /* normal speed 20MHz */ 96*b28c29d0SBiju Das #define EMMC_CLOCK_SPEC_26M 26000000UL /* high speed 26MHz */ 97*b28c29d0SBiju Das #define EMMC_CLOCK_SPEC_52M 52000000UL /* high speed 52MHz */ 98*b28c29d0SBiju Das #define EMMC_CLOCK_SPEC_100M 100000000UL /* high speed 100MHz */ 99*b28c29d0SBiju Das 100*b28c29d0SBiju Das /* EMMC driver error code. (extended HAL_MEMCARD_RETURN) */ 101*b28c29d0SBiju Das typedef enum { 102*b28c29d0SBiju Das EMMC_ERR = 0, /* unknown error */ 103*b28c29d0SBiju Das EMMC_SUCCESS, /* OK */ 104*b28c29d0SBiju Das EMMC_ERR_FROM_DMAC, /* DMAC allocation error */ 105*b28c29d0SBiju Das EMMC_ERR_FROM_DMAC_TRANSFER, /* DMAC transfer error */ 106*b28c29d0SBiju Das EMMC_ERR_CARD_STATUS_BIT, /* card status error */ 107*b28c29d0SBiju Das EMMC_ERR_CMD_TIMEOUT, /* command timeout error */ 108*b28c29d0SBiju Das EMMC_ERR_DATA_TIMEOUT, /* data timeout error */ 109*b28c29d0SBiju Das EMMC_ERR_CMD_CRC, /* command CRC error */ 110*b28c29d0SBiju Das EMMC_ERR_DATA_CRC, /* data CRC error */ 111*b28c29d0SBiju Das EMMC_ERR_PARAM, /* parameter error */ 112*b28c29d0SBiju Das EMMC_ERR_RESPONSE, /* response error */ 113*b28c29d0SBiju Das EMMC_ERR_RESPONSE_BUSY, /* response busy error */ 114*b28c29d0SBiju Das EMMC_ERR_TRANSFER, /* data transfer error */ 115*b28c29d0SBiju Das EMMC_ERR_READ_SECTOR, /* read sector error */ 116*b28c29d0SBiju Das EMMC_ERR_WRITE_SECTOR, /* write sector error */ 117*b28c29d0SBiju Das EMMC_ERR_STATE, /* state error */ 118*b28c29d0SBiju Das EMMC_ERR_TIMEOUT, /* timeout error */ 119*b28c29d0SBiju Das EMMC_ERR_ILLEGAL_CARD, /* illegal card */ 120*b28c29d0SBiju Das EMMC_ERR_CARD_BUSY, /* Busy state */ 121*b28c29d0SBiju Das EMMC_ERR_CARD_STATE, /* card state error */ 122*b28c29d0SBiju Das EMMC_ERR_SET_TRACE, /* trace information error */ 123*b28c29d0SBiju Das EMMC_ERR_FROM_TIMER, /* Timer error */ 124*b28c29d0SBiju Das EMMC_ERR_FORCE_TERMINATE, /* Force terminate */ 125*b28c29d0SBiju Das EMMC_ERR_CARD_POWER, /* card power fail */ 126*b28c29d0SBiju Das EMMC_ERR_ERASE_SECTOR, /* erase sector error */ 127*b28c29d0SBiju Das EMMC_ERR_INFO2 /* exec cmd error info2 */ 128*b28c29d0SBiju Das } EMMC_ERROR_CODE; 129*b28c29d0SBiju Das 130*b28c29d0SBiju Das /* Function number */ 131*b28c29d0SBiju Das #define EMMC_FUNCNO_NONE 0U 132*b28c29d0SBiju Das #define EMMC_FUNCNO_DRIVER_INIT 1U 133*b28c29d0SBiju Das #define EMMC_FUNCNO_CARD_POWER_ON 2U 134*b28c29d0SBiju Das #define EMMC_FUNCNO_MOUNT 3U 135*b28c29d0SBiju Das #define EMMC_FUNCNO_CARD_INIT 4U 136*b28c29d0SBiju Das #define EMMC_FUNCNO_HIGH_SPEED 5U 137*b28c29d0SBiju Das #define EMMC_FUNCNO_BUS_WIDTH 6U 138*b28c29d0SBiju Das #define EMMC_FUNCNO_MULTI_BOOT_SELECT_PARTITION 7U 139*b28c29d0SBiju Das #define EMMC_FUNCNO_MULTI_BOOT_READ_SECTOR 8U 140*b28c29d0SBiju Das #define EMMC_FUNCNO_TRANS_DATA_READ_SECTOR 9U 141*b28c29d0SBiju Das #define EMMC_FUNCNO_UBOOT_IMAGE_SELECT_PARTITION 10U 142*b28c29d0SBiju Das #define EMMC_FUNCNO_UBOOT_IMAGE_READ_SECTOR 11U 143*b28c29d0SBiju Das #define EMMC_FUNCNO_SET_CLOCK 12U 144*b28c29d0SBiju Das #define EMMC_FUNCNO_EXEC_CMD 13U 145*b28c29d0SBiju Das #define EMMC_FUNCNO_READ_SECTOR 14U 146*b28c29d0SBiju Das #define EMMC_FUNCNO_WRITE_SECTOR 15U 147*b28c29d0SBiju Das #define EMMC_FUNCNO_ERASE_SECTOR 16U 148*b28c29d0SBiju Das #define EMMC_FUNCNO_GET_PERTITION_ACCESS 17U 149*b28c29d0SBiju Das /* 150*b28c29d0SBiju Das * Response 151*b28c29d0SBiju Das * R1 152*b28c29d0SBiju Das * Type 'E' bit and bit14(must be 0). ignore bit22 153*b28c29d0SBiju Das */ 154*b28c29d0SBiju Das #define EMMC_R1_ERROR_MASK 0xFDBFE080U 155*b28c29d0SBiju Das /* Ignore bit23 (Not check CRC error) */ 156*b28c29d0SBiju Das #define EMMC_R1_ERROR_MASK_WITHOUT_CRC (0xFD3FE080U) 157*b28c29d0SBiju Das #define EMMC_R1_STATE_MASK 0x00001E00U /* [12:9] */ 158*b28c29d0SBiju Das #define EMMC_R1_READY 0x00000100U /* bit8 */ 159*b28c29d0SBiju Das #define EMMC_R1_STATE_SHIFT 9 160*b28c29d0SBiju Das 161*b28c29d0SBiju Das /* R4 */ 162*b28c29d0SBiju Das #define EMMC_R4_RCA_MASK 0xFFFF0000UL 163*b28c29d0SBiju Das #define EMMC_R4_STATUS 0x00008000UL 164*b28c29d0SBiju Das 165*b28c29d0SBiju Das /* CSD */ 166*b28c29d0SBiju Das #define EMMC_TRANSPEED_FREQ_UNIT_MASK 0x07 /* bit[2:0] */ 167*b28c29d0SBiju Das #define EMMC_TRANSPEED_FREQ_UNIT_SHIFT 0 168*b28c29d0SBiju Das #define EMMC_TRANSPEED_MULT_MASK 0x78 /* bit[6:3] */ 169*b28c29d0SBiju Das #define EMMC_TRANSPEED_MULT_SHIFT 3 170*b28c29d0SBiju Das 171*b28c29d0SBiju Das /* OCR */ 172*b28c29d0SBiju Das #define EMMC_HOST_OCR_VALUE 0x40FF8080 173*b28c29d0SBiju Das #define EMMC_OCR_STATUS_BIT 0x80000000L /* Card power up status bit */ 174*b28c29d0SBiju Das #define EMMC_OCR_ACCESS_MODE_MASK 0x60000000L /* bit[30:29] */ 175*b28c29d0SBiju Das #define EMMC_OCR_ACCESS_MODE_SECT 0x40000000L 176*b28c29d0SBiju Das #define EMMC_OCR_ACCESS_MODE_BYTE 0x00000000L 177*b28c29d0SBiju Das 178*b28c29d0SBiju Das /* EXT_CSD */ 179*b28c29d0SBiju Das #define EMMC_EXT_CSD_S_CMD_SET 504 180*b28c29d0SBiju Das #define EMMC_EXT_CSD_INI_TIMEOUT_AP 241 181*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_DDR_52_360 239 182*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_DDR_52_195 238 183*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_DDR_W_8_52 235 184*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_DDR_R_8_52 234 185*b28c29d0SBiju Das #define EMMC_EXT_CSD_TRIM_MULT 232 186*b28c29d0SBiju Das #define EMMC_EXT_CSD_SEC_FEATURE_SUPPORT 231 187*b28c29d0SBiju Das #define EMMC_EXT_CSD_SEC_ERASE_MULT 229 188*b28c29d0SBiju Das #define EMMC_EXT_CSD_BOOT_INFO 228 189*b28c29d0SBiju Das #define EMMC_EXT_CSD_BOOT_SIZE_MULTI 226 190*b28c29d0SBiju Das #define EMMC_EXT_CSD_ACC_SIZE 225 191*b28c29d0SBiju Das #define EMMC_EXT_CSD_HC_ERASE_GRP_SIZE 224 192*b28c29d0SBiju Das #define EMMC_EXT_CSD_ERASE_TIMEOUT_MULT 223 193*b28c29d0SBiju Das #define EMMC_EXT_CSD_PEL_WR_SEC_C 222 194*b28c29d0SBiju Das #define EMMC_EXT_CSD_HC_WP_GRP_SIZE 221 195*b28c29d0SBiju Das #define EMMC_EXT_CSD_S_C_VCC 220 196*b28c29d0SBiju Das #define EMMC_EXT_CSD_S_C_VCCQ 219 197*b28c29d0SBiju Das #define EMMC_EXT_CSD_S_A_TIMEOUT 217 198*b28c29d0SBiju Das #define EMMC_EXT_CSD_SEC_COUNT 215 199*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_W_8_52 210 200*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_R_8_52 209 201*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_W_8_26_4_52 208 202*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_R_8_26_4_52 207 203*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_W_4_26 206 204*b28c29d0SBiju Das #define EMMC_EXT_CSD_MIN_PERF_R_4_26 205 205*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_26_360 203 206*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_52_360 202 207*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_26_195 201 208*b28c29d0SBiju Das #define EMMC_EXT_CSD_PWR_CL_52_195 200 209*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE 196 210*b28c29d0SBiju Das #define EMMC_EXT_CSD_CSD_STRUCTURE 194 211*b28c29d0SBiju Das #define EMMC_EXT_CSD_EXT_CSD_REV 192 212*b28c29d0SBiju Das #define EMMC_EXT_CSD_CMD_SET 191 213*b28c29d0SBiju Das #define EMMC_EXT_CSD_CMD_SET_REV 189 214*b28c29d0SBiju Das #define EMMC_EXT_CSD_POWER_CLASS 187 215*b28c29d0SBiju Das #define EMMC_EXT_CSD_HS_TIMING 185 216*b28c29d0SBiju Das #define EMMC_EXT_CSD_BUS_WIDTH 183 217*b28c29d0SBiju Das #define EMMC_EXT_CSD_ERASED_MEM_CONT 181 218*b28c29d0SBiju Das #define EMMC_EXT_CSD_PARTITION_CONFIG 179 219*b28c29d0SBiju Das #define EMMC_EXT_CSD_BOOT_CONFIG_PROT 178 220*b28c29d0SBiju Das #define EMMC_EXT_CSD_BOOT_BUS_WIDTH 177 221*b28c29d0SBiju Das #define EMMC_EXT_CSD_ERASE_GROUP_DEF 175 222*b28c29d0SBiju Das #define EMMC_EXT_CSD_BOOT_WP 173 223*b28c29d0SBiju Das #define EMMC_EXT_CSD_USER_WP 171 224*b28c29d0SBiju Das #define EMMC_EXT_CSD_FW_CONFIG 169 225*b28c29d0SBiju Das #define EMMC_EXT_CSD_RPMB_SIZE_MULT 168 226*b28c29d0SBiju Das #define EMMC_EXT_CSD_RST_n_FUNCTION 162 227*b28c29d0SBiju Das #define EMMC_EXT_CSD_PARTITIONING_SUPPORT 160 228*b28c29d0SBiju Das #define EMMC_EXT_CSD_MAX_ENH_SIZE_MULT 159 229*b28c29d0SBiju Das #define EMMC_EXT_CSD_PARTITIONS_ATTRIBUTE 156 230*b28c29d0SBiju Das #define EMMC_EXT_CSD_PARTITION_SETTING_COMPLETED 155 231*b28c29d0SBiju Das #define EMMC_EXT_CSD_GP_SIZE_MULT 154 232*b28c29d0SBiju Das #define EMMC_EXT_CSD_ENH_SIZE_MULT 142 233*b28c29d0SBiju Das #define EMMC_EXT_CSD_ENH_START_ADDR 139 234*b28c29d0SBiju Das #define EMMC_EXT_CSD_SEC_BAD_BLK_MGMNT 134 235*b28c29d0SBiju Das 236*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE_26MHZ 0x01 237*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE_52MHZ 0x02 238*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE_DDR_52MHZ_12V 0x04 239*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE_DDR_52MHZ_18V 0x08 240*b28c29d0SBiju Das #define EMMC_EXT_CSD_CARD_TYPE_52MHZ_MASK 0x0e 241*b28c29d0SBiju Das 242*b28c29d0SBiju Das /* SWITCH (CMD6) argument */ 243*b28c29d0SBiju Das #define EXTCSD_ACCESS_BYTE (BIT25 | BIT24) 244*b28c29d0SBiju Das #define EXTCSD_SET_BITS BIT24 245*b28c29d0SBiju Das 246*b28c29d0SBiju Das #define HS_TIMING_ADD (185 << 16) /* H'b9 */ 247*b28c29d0SBiju Das #define HS_TIMING_1 (1 << 8) 248*b28c29d0SBiju Das #define HS_TIMING_HS200 (2 << 8) 249*b28c29d0SBiju Das #define HS_TIMING_HS400 (3 << 8) 250*b28c29d0SBiju Das 251*b28c29d0SBiju Das #define BUS_WIDTH_ADD (183 << 16) /* H'b7 */ 252*b28c29d0SBiju Das #define BUS_WIDTH_1 (0 << 8) 253*b28c29d0SBiju Das #define BUS_WIDTH_4 (1 << 8) 254*b28c29d0SBiju Das #define BUS_WIDTH_8 (2 << 8) 255*b28c29d0SBiju Das #define BUS_WIDTH_4DDR (5 << 8) 256*b28c29d0SBiju Das #define BUS_WIDTH_8DDR (6 << 8) 257*b28c29d0SBiju Das 258*b28c29d0SBiju Das #define EMMC_SWITCH_HS_TIMING (EXTCSD_ACCESS_BYTE | HS_TIMING_ADD |\ 259*b28c29d0SBiju Das HS_TIMING_1) /* H'03b90100 */ 260*b28c29d0SBiju Das #define EMMC_SWITCH_HS_TIMING_OFF (EXTCSD_ACCESS_BYTE |\ 261*b28c29d0SBiju Das HS_TIMING_ADD) /* H'03b90000 */ 262*b28c29d0SBiju Das 263*b28c29d0SBiju Das #define EMMC_SWITCH_BUS_WIDTH_1 (EXTCSD_ACCESS_BYTE | BUS_WIDTH_ADD |\ 264*b28c29d0SBiju Das BUS_WIDTH_1) /* H'03b70000 */ 265*b28c29d0SBiju Das #define EMMC_SWITCH_BUS_WIDTH_4 (EXTCSD_ACCESS_BYTE | BUS_WIDTH_ADD |\ 266*b28c29d0SBiju Das BUS_WIDTH_4) /* H'03b70100 */ 267*b28c29d0SBiju Das #define EMMC_SWITCH_BUS_WIDTH_8 (EXTCSD_ACCESS_BYTE | BUS_WIDTH_ADD |\ 268*b28c29d0SBiju Das BUS_WIDTH_8) /* H'03b70200 */ 269*b28c29d0SBiju Das #define EMMC_SWITCH_BUS_WIDTH_4DDR (EXTCSD_ACCESS_BYTE | BUS_WIDTH_ADD |\ 270*b28c29d0SBiju Das BUS_WIDTH_4DDR) /* H'03b70500 */ 271*b28c29d0SBiju Das #define EMMC_SWITCH_BUS_WIDTH_8DDR (EXTCSD_ACCESS_BYTE | BUS_WIDTH_ADD |\ 272*b28c29d0SBiju Das BUS_WIDTH_8DDR) /* H'03b70600 */ 273*b28c29d0SBiju Das /* Partition config = 0x00 */ 274*b28c29d0SBiju Das #define EMMC_SWITCH_PARTITION_CONFIG 0x03B30000UL 275*b28c29d0SBiju Das 276*b28c29d0SBiju Das #define TIMING_HIGH_SPEED 1UL 277*b28c29d0SBiju Das #define EMMC_BOOT_PARTITION_EN_MASK 0x38U 278*b28c29d0SBiju Das #define EMMC_BOOT_PARTITION_EN_SHIFT 3U 279*b28c29d0SBiju Das 280*b28c29d0SBiju Das /* Bus width */ 281*b28c29d0SBiju Das #define EMMC_BUSWIDTH_1BIT CE_CMD_SET_DATW_1BIT 282*b28c29d0SBiju Das #define EMMC_BUSWIDTH_4BIT CE_CMD_SET_DATW_4BIT 283*b28c29d0SBiju Das #define EMMC_BUSWIDTH_8BIT CE_CMD_SET_DATW_8BIT 284*b28c29d0SBiju Das 285*b28c29d0SBiju Das /* for st_mmc_base */ 286*b28c29d0SBiju Das #define EMMC_MAX_RESPONSE_LENGTH 17 287*b28c29d0SBiju Das #define EMMC_MAX_CID_LENGTH 16 288*b28c29d0SBiju Das #define EMMC_MAX_CSD_LENGTH 16 289*b28c29d0SBiju Das #define EMMC_MAX_EXT_CSD_LENGTH 512U 290*b28c29d0SBiju Das #define EMMC_RES_REG_ALIGNED 4U 291*b28c29d0SBiju Das #define EMMC_BUF_REG_ALIGNED 8U 292*b28c29d0SBiju Das 293*b28c29d0SBiju Das /* TAAC mask */ 294*b28c29d0SBiju Das #define TAAC_TIME_UNIT_MASK (0x07) 295*b28c29d0SBiju Das #define TAAC_MULTIPLIER_FACTOR_MASK (0x0F) 296*b28c29d0SBiju Das 297*b28c29d0SBiju Das /* Partition id */ 298*b28c29d0SBiju Das typedef enum { 299*b28c29d0SBiju Das PARTITION_ID_USER = 0x0, /* User Area */ 300*b28c29d0SBiju Das PARTITION_ID_BOOT_1 = 0x1, /* boot partition 1 */ 301*b28c29d0SBiju Das PARTITION_ID_BOOT_2 = 0x2, /* boot partition 2 */ 302*b28c29d0SBiju Das PARTITION_ID_RPMB = 0x3, /* Replay Protected Memory Block */ 303*b28c29d0SBiju Das PARTITION_ID_GP_1 = 0x4, /* General Purpose partition 1 */ 304*b28c29d0SBiju Das PARTITION_ID_GP_2 = 0x5, /* General Purpose partition 2 */ 305*b28c29d0SBiju Das PARTITION_ID_GP_3 = 0x6, /* General Purpose partition 3 */ 306*b28c29d0SBiju Das PARTITION_ID_GP_4 = 0x7, /* General Purpose partition 4 */ 307*b28c29d0SBiju Das PARTITION_ID_MASK = 0x7 /* [2:0] */ 308*b28c29d0SBiju Das } EMMC_PARTITION_ID; 309*b28c29d0SBiju Das 310*b28c29d0SBiju Das /* card state in R1 response [12:9] */ 311*b28c29d0SBiju Das typedef enum { 312*b28c29d0SBiju Das EMMC_R1_STATE_IDLE = 0, 313*b28c29d0SBiju Das EMMC_R1_STATE_READY, 314*b28c29d0SBiju Das EMMC_R1_STATE_IDENT, 315*b28c29d0SBiju Das EMMC_R1_STATE_STBY, 316*b28c29d0SBiju Das EMMC_R1_STATE_TRAN, 317*b28c29d0SBiju Das EMMC_R1_STATE_DATA, 318*b28c29d0SBiju Das EMMC_R1_STATE_RCV, 319*b28c29d0SBiju Das EMMC_R1_STATE_PRG, 320*b28c29d0SBiju Das EMMC_R1_STATE_DIS, 321*b28c29d0SBiju Das EMMC_R1_STATE_BTST, 322*b28c29d0SBiju Das EMMC_R1_STATE_SLEP 323*b28c29d0SBiju Das } EMMC_R1_STATE; 324*b28c29d0SBiju Das 325*b28c29d0SBiju Das typedef enum { 326*b28c29d0SBiju Das ESTATE_BEGIN = 0, 327*b28c29d0SBiju Das ESTATE_ISSUE_CMD, 328*b28c29d0SBiju Das ESTATE_NON_RESP_CMD, 329*b28c29d0SBiju Das ESTATE_RCV_RESP, 330*b28c29d0SBiju Das ESTATE_RCV_RESPONSE_BUSY, 331*b28c29d0SBiju Das ESTATE_CHECK_RESPONSE_COMPLETE, 332*b28c29d0SBiju Das ESTATE_DATA_TRANSFER, 333*b28c29d0SBiju Das ESTATE_DATA_TRANSFER_COMPLETE, 334*b28c29d0SBiju Das ESTATE_ACCESS_END, 335*b28c29d0SBiju Das ESTATE_TRANSFER_ERROR, 336*b28c29d0SBiju Das ESTATE_ERROR, 337*b28c29d0SBiju Das ESTATE_END 338*b28c29d0SBiju Das } EMMC_INT_STATE; 339*b28c29d0SBiju Das 340*b28c29d0SBiju Das /* eMMC boot driver error information */ 341*b28c29d0SBiju Das typedef struct { 342*b28c29d0SBiju Das uint16_t num; /* error no */ 343*b28c29d0SBiju Das uint16_t code; /* error code */ 344*b28c29d0SBiju Das 345*b28c29d0SBiju Das volatile uint32_t info1; /* SD_INFO1. (hw dependent) */ 346*b28c29d0SBiju Das volatile uint32_t info2; /* SD_INFO2. (hw dependent) */ 347*b28c29d0SBiju Das volatile uint32_t status1; /* SD_ERR_STS1. (hw dependent) */ 348*b28c29d0SBiju Das volatile uint32_t status2; /* SD_ERR_STS2. (hw dependent) */ 349*b28c29d0SBiju Das volatile uint32_t dm_info1; /* DM_CM_INFO1. (hw dependent) */ 350*b28c29d0SBiju Das volatile uint32_t dm_info2; /* DM_CM_INFO2. (hw dependent) */ 351*b28c29d0SBiju Das } st_error_info; 352*b28c29d0SBiju Das 353*b28c29d0SBiju Das /* Command information */ 354*b28c29d0SBiju Das typedef struct { 355*b28c29d0SBiju Das HAL_MEMCARD_COMMAND cmd; /* Command information */ 356*b28c29d0SBiju Das uint32_t arg; /* argument */ 357*b28c29d0SBiju Das HAL_MEMCARD_OPERATION dir; /* direction */ 358*b28c29d0SBiju Das uint32_t hw; /* SD_CMD register value. */ 359*b28c29d0SBiju Das } st_command_info; 360*b28c29d0SBiju Das 361*b28c29d0SBiju Das /* MMC driver base */ 362*b28c29d0SBiju Das typedef struct { 363*b28c29d0SBiju Das st_error_info error_info; /* error information */ 364*b28c29d0SBiju Das st_command_info cmd_info; /* command information */ 365*b28c29d0SBiju Das 366*b28c29d0SBiju Das /* for data transfer */ 367*b28c29d0SBiju Das uint32_t *buff_address_virtual; /* Dest or Src buff */ 368*b28c29d0SBiju Das uint32_t *buff_address_physical; /* Dest or Src buff */ 369*b28c29d0SBiju Das HAL_MEMCARD_DATA_WIDTH bus_width; /* bus width */ 370*b28c29d0SBiju Das 371*b28c29d0SBiju Das uint32_t trans_size; /* transfer size for this command */ 372*b28c29d0SBiju Das uint32_t remain_size; /* remain size for this command */ 373*b28c29d0SBiju Das uint32_t response_length; /* response length for this command */ 374*b28c29d0SBiju Das uint32_t sector_size; /* sector_size */ 375*b28c29d0SBiju Das 376*b28c29d0SBiju Das /* clock */ 377*b28c29d0SBiju Das uint32_t base_clock; /* MMC host controller clock */ 378*b28c29d0SBiju Das /* 379*b28c29d0SBiju Das * Max freq (Card Spec)[Hz]. It changes dynamically by CSD and 380*b28c29d0SBiju Das * EXT_CSD. 381*b28c29d0SBiju Das */ 382*b28c29d0SBiju Das uint32_t max_freq; 383*b28c29d0SBiju Das /* request freq [Hz] (400K, 26MHz, 52MHz, etc) */ 384*b28c29d0SBiju Das uint32_t request_freq; 385*b28c29d0SBiju Das /* current MMC clock[Hz] (the closest frequency supported by HW) */ 386*b28c29d0SBiju Das uint32_t current_freq; 387*b28c29d0SBiju Das 388*b28c29d0SBiju Das /* state flag */ 389*b28c29d0SBiju Das /* presence status of the memory card */ 390*b28c29d0SBiju Das HAL_MEMCARD_PRESENCE_STATUS card_present; 391*b28c29d0SBiju Das 392*b28c29d0SBiju Das uint32_t card_power_enable; 393*b28c29d0SBiju Das uint32_t clock_enable; 394*b28c29d0SBiju Das /* True : initialize complete. */ 395*b28c29d0SBiju Das uint32_t initialize; 396*b28c29d0SBiju Das /* True : sector access, FALSE : byte access */ 397*b28c29d0SBiju Das uint32_t access_mode; 398*b28c29d0SBiju Das /* True : mount complete. */ 399*b28c29d0SBiju Das uint32_t mount; 400*b28c29d0SBiju Das /* True : selected card. */ 401*b28c29d0SBiju Das uint32_t selected; 402*b28c29d0SBiju Das /* 0: DMA, 1:PIO */ 403*b28c29d0SBiju Das HAL_MEMCARD_DATA_TRANSFER_MODE transfer_mode; 404*b28c29d0SBiju Das 405*b28c29d0SBiju Das /* loaded ISSW image No. ISSW have copy image. */ 406*b28c29d0SBiju Das uint32_t image_num; 407*b28c29d0SBiju Das /* card state */ 408*b28c29d0SBiju Das EMMC_R1_STATE current_state; 409*b28c29d0SBiju Das /* True : during command processing */ 410*b28c29d0SBiju Das volatile uint32_t during_cmd_processing; 411*b28c29d0SBiju Das /* True : during transfer */ 412*b28c29d0SBiju Das volatile uint32_t during_transfer; 413*b28c29d0SBiju Das /* True : during transfer (DMA) */ 414*b28c29d0SBiju Das volatile uint32_t during_dma_transfer; 415*b28c29d0SBiju Das /* True : occurred DMAC error */ 416*b28c29d0SBiju Das volatile uint32_t dma_error_flag; 417*b28c29d0SBiju Das /* force terminate flag */ 418*b28c29d0SBiju Das volatile uint32_t force_terminate; 419*b28c29d0SBiju Das /* state machine blocking flag : True or False */ 420*b28c29d0SBiju Das volatile uint32_t state_machine_blocking; 421*b28c29d0SBiju Das /* True : get partition access processing */ 422*b28c29d0SBiju Das volatile uint32_t get_partition_access_flag; 423*b28c29d0SBiju Das 424*b28c29d0SBiju Das EMMC_PARTITION_ID boot_partition_en; /* Boot partition */ 425*b28c29d0SBiju Das EMMC_PARTITION_ID partition_access; /* Current access partition */ 426*b28c29d0SBiju Das 427*b28c29d0SBiju Das /* timeout */ 428*b28c29d0SBiju Das uint32_t hs_timing; 429*b28c29d0SBiju Das 430*b28c29d0SBiju Das /* read and write data timeout */ 431*b28c29d0SBiju Das uint32_t data_timeout; 432*b28c29d0SBiju Das 433*b28c29d0SBiju Das /* retry */ 434*b28c29d0SBiju Das uint32_t retries_after_fail; 435*b28c29d0SBiju Das 436*b28c29d0SBiju Das /* interrupt */ 437*b28c29d0SBiju Das volatile uint32_t int_event1; /* interrupt SD_INFO1 Event */ 438*b28c29d0SBiju Das volatile uint32_t int_event2; /* interrupt SD_INFO2 Event */ 439*b28c29d0SBiju Das volatile uint32_t dm_event1; /* interrupt DM_CM_INFO1 Event */ 440*b28c29d0SBiju Das volatile uint32_t dm_event2; /* interrupt DM_CM_INFO2 Event */ 441*b28c29d0SBiju Das 442*b28c29d0SBiju Das /* response */ 443*b28c29d0SBiju Das uint32_t *response; /* buffer ptr for executing command. */ 444*b28c29d0SBiju Das uint32_t r1_card_status; /* R1 response data */ 445*b28c29d0SBiju Das uint32_t r3_ocr; /* R3 response data */ 446*b28c29d0SBiju Das uint32_t r4_resp; /* R4 response data */ 447*b28c29d0SBiju Das uint32_t r5_resp; /* R5 response data */ 448*b28c29d0SBiju Das 449*b28c29d0SBiju Das /* True : clock mode is low. (MMC clock = Max26MHz) */ 450*b28c29d0SBiju Das uint32_t low_clock_mode_enable; 451*b28c29d0SBiju Das 452*b28c29d0SBiju Das uint32_t reserved2; 453*b28c29d0SBiju Das uint32_t reserved3; 454*b28c29d0SBiju Das uint32_t reserved4; 455*b28c29d0SBiju Das 456*b28c29d0SBiju Das /* CSD registers (4byte align) */ 457*b28c29d0SBiju Das uint8_t csd_data[EMMC_MAX_CSD_LENGTH] /* CSD */ 458*b28c29d0SBiju Das __attribute__ ((aligned(EMMC_RES_REG_ALIGNED))); 459*b28c29d0SBiju Das /* CID registers (4byte align) */ 460*b28c29d0SBiju Das uint8_t cid_data[EMMC_MAX_CID_LENGTH] /* CID */ 461*b28c29d0SBiju Das __attribute__ ((aligned(EMMC_RES_REG_ALIGNED))); 462*b28c29d0SBiju Das /* EXT CSD registers (8byte align) */ 463*b28c29d0SBiju Das uint8_t ext_csd_data[EMMC_MAX_EXT_CSD_LENGTH] /* EXT_CSD */ 464*b28c29d0SBiju Das __attribute__ ((aligned(EMMC_BUF_REG_ALIGNED))); 465*b28c29d0SBiju Das /* Response registers (4byte align) */ 466*b28c29d0SBiju Das uint8_t response_data[EMMC_MAX_RESPONSE_LENGTH] /* other response */ 467*b28c29d0SBiju Das __attribute__ ((aligned(EMMC_RES_REG_ALIGNED))); 468*b28c29d0SBiju Das } st_mmc_base; 469*b28c29d0SBiju Das 470*b28c29d0SBiju Das typedef int (*func) (void); 471*b28c29d0SBiju Das 472*b28c29d0SBiju Das uint32_t emmc_get_csd_time(void); 473*b28c29d0SBiju Das 474*b28c29d0SBiju Das #define MMC_DEBUG 475*b28c29d0SBiju Das #endif /* EMMC_STD_H */ 476