/* * SPDX-FileCopyrightText: 2006 Uwe Stuehler <uwe@openbsd.org> * * SPDX-License-Identifier: ISC * * SPDX-FileContributor: 2016-2024 Espressif Systems (Shanghai) CO LTD *//* ... *//* * Copyright (c) 2006 Uwe Stuehler <uwe@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *//* ... */#pragmaonce#include<stdint.h>#include<limits.h>#ifdef__cplusplusextern"C"{#endif/* MMC commands *//* response type */#defineMMC_GO_IDLE_STATE0/* R0 */#defineMMC_SEND_OP_COND1/* R3 */#defineMMC_ALL_SEND_CID2/* R2 */#defineMMC_SET_RELATIVE_ADDR3/* R1 */#defineMMC_SWITCH6/* R1B */#defineMMC_SELECT_CARD7/* R1 */#defineMMC_SEND_EXT_CSD8/* R1 */#defineMMC_SEND_CSD9/* R2 */#defineMMC_SEND_CID10/* R1 */#defineMMC_READ_DAT_UNTIL_STOP11/* R1 */#defineMMC_STOP_TRANSMISSION12/* R1B */#defineMMC_SEND_STATUS13/* R1 */#defineMMC_SET_BLOCKLEN16/* R1 */#defineMMC_READ_BLOCK_SINGLE17/* R1 */#defineMMC_READ_BLOCK_MULTIPLE18/* R1 */#defineMMC_SEND_TUNING_BLOCK19/* R1 */#defineMMC_WRITE_DAT_UNTIL_STOP20/* R1 */#defineMMC_SET_BLOCK_COUNT23/* R1 */#defineMMC_WRITE_BLOCK_SINGLE24/* R1 */#defineMMC_WRITE_BLOCK_MULTIPLE25/* R1 */#defineMMC_ERASE_GROUP_START35/* R1 */#defineMMC_ERASE_GROUP_END36/* R1 */#defineMMC_ERASE38/* R1B */#defineMMC_APP_CMD55/* R1 *//* SD commands *//* response type */#defineSD_SEND_RELATIVE_ADDR3/* R6 */#defineSD_SEND_SWITCH_FUNC6/* R1 */#defineSD_SEND_IF_COND8/* R7 */#defineSD_SWITCH_VOLTAGE11/* R1 */#defineSD_ERASE_GROUP_START32/* R1 */#defineSD_ERASE_GROUP_END33/* R1 */#defineSD_READ_OCR58/* R3 */#defineSD_CRC_ON_OFF59/* R1 *//* SD application commands *//* response type */#defineSD_APP_SET_BUS_WIDTH6/* R1 */#defineSD_APP_SD_STATUS13/* R2 */#defineSD_APP_SEND_NUM_WR_BLOCKS22/* R1 */#defineSD_APP_OP_COND41/* R3 */#defineSD_APP_SEND_SCR51/* R1 *//* SD IO commands */#defineSD_IO_SEND_OP_COND5/* R4 */#defineSD_IO_RW_DIRECT52/* R5 */#defineSD_IO_RW_EXTENDED53/* R5 *//* OCR bits */#defineMMC_OCR_MEM_READY(1<<31)/* memory power-up status bit */#defineMMC_OCR_ACCESS_MODE_MASK0x60000000/* bits 30:29 */#defineMMC_OCR_SECTOR_MODE(1<<30)#defineMMC_OCR_BYTE_MODE(1<<29)#defineMMC_OCR_3_5V_3_6V(1<<23)#defineMMC_OCR_3_4V_3_5V(1<<22)#defineMMC_OCR_3_3V_3_4V(1<<21)#defineMMC_OCR_3_2V_3_3V(1<<20)#defineMMC_OCR_3_1V_3_2V(1<<19)#defineMMC_OCR_3_0V_3_1V(1<<18)#defineMMC_OCR_2_9V_3_0V(1<<17)#defineMMC_OCR_2_8V_2_9V(1<<16)#defineMMC_OCR_2_7V_2_8V(1<<15)#defineMMC_OCR_2_6V_2_7V(1<<14)#defineMMC_OCR_2_5V_2_6V(1<<13)#defineMMC_OCR_2_4V_2_5V(1<<12)#defineMMC_OCR_2_3V_2_4V(1<<11)#defineMMC_OCR_2_2V_2_3V(1<<10)#defineMMC_OCR_2_1V_2_2V(1<<9)#defineMMC_OCR_2_0V_2_1V(1<<8)#defineMMC_OCR_1_65V_1_95V(1<<7)#defineSD_OCR_CARD_READYMMC_OCR_MEM_READY/* bit-31: power-up status */#defineSD_OCR_SDHC_CAP(1<<30)/* HCS bit */#defineSD_OCR_XPC(1<<28)/* SDXC Power Control (bit 28) */#defineSD_OCR_S18_RA(1<<24)/* S18R/A bit: 1.8V voltage support, UHS-I only */#defineSD_OCR_VOL_MASK0xFF8000/* SD OCR voltage bits 23:15 */#defineSD_OCR_3_5V_3_6VMMC_OCR_3_5V_3_6V/* bit-23 */#defineSD_OCR_3_4V_3_5VMMC_OCR_3_4V_3_5V/* bit-22 */#defineSD_OCR_3_3V_3_4VMMC_OCR_3_3V_3_4V/* ... */#defineSD_OCR_3_2V_3_3VMMC_OCR_3_2V_3_3V#defineSD_OCR_3_1V_3_2VMMC_OCR_3_1V_3_2V#defineSD_OCR_3_0V_3_1VMMC_OCR_3_0V_3_1V#defineSD_OCR_2_9V_3_0VMMC_OCR_2_9V_3_0V#defineSD_OCR_2_8V_2_9VMMC_OCR_2_8V_2_9V/* ... */#defineSD_OCR_2_7V_2_8VMMC_OCR_2_7V_2_8V/* bit-15 *//* SD mode R1 response type bits */#defineMMC_R1_READY_FOR_DATA(1<<8)/* ready for next transfer */#defineMMC_R1_APP_CMD(1<<5)/* app. commands supported */#defineMMC_R1_SWITCH_ERROR(1<<7)/* switch command did not succeed */#defineMMC_R1_CURRENT_STATE_POS(9)#defineMMC_R1_CURRENT_STATE_MASK(0x1E00)/* card current state */#defineMMC_R1_CURRENT_STATE_TRAN(4)#defineMMC_R1_CURRENT_STATE_STATUS(status)(((status)&MMC_R1_CURRENT_STATE_MASK)>>MMC_R1_CURRENT_STATE_POS)/* SPI mode R1 response type bits */#defineSD_SPI_R1_IDLE_STATE(1<<0)#defineSD_SPI_R1_ERASE_RST(1<<1)#defineSD_SPI_R1_ILLEGAL_CMD(1<<2)#defineSD_SPI_R1_CMD_CRC_ERR(1<<3)#defineSD_SPI_R1_ERASE_SEQ_ERR(1<<4)#defineSD_SPI_R1_ADDR_ERR(1<<5)#defineSD_SPI_R1_PARAM_ERR(1<<6)#defineSD_SPI_R1_NO_RESPONSE(1<<7)#defineSDIO_R1_FUNC_NUM_ERR(1<<4)/* SPI mode R2 response type bits. * The first byte is the same as for R1. * The bits below belong to the second byte. * Bits 10, 11, 12, 15 can also be reported in data error token of a read command response. *//* ... */#defineSD_SPI_R2_CARD_LOCKED(1<<8)/* Set when the card is locked by the user */#defineSD_SPI_R2_UNLOCK_FAILED(1<<9)/* Host attempts to erase a write-protected sector or makes an error during card lock/unlock operation */#defineSD_SPI_R2_ERROR(1<<10)/* A general or an unknown error occurred during the operation */#defineSD_SPI_R2_CC_ERROR(1<<11)/* Internal card controller error */#defineSD_SPI_R2_ECC_FAILED(1<<12)/* Card internal ECC was applied but failed to correct the data */#defineSD_SPI_R2_WP_VIOLATION(1<<13)/* The command tried to write a write-protected block */#defineSD_SPI_R2_ERASE_PARAM(1<<14)/* An invalid selection for erase, sectors or groups */#defineSD_SPI_R2_OUT_OF_RANGE(1<<15)/* The command argument was out of the allowed range for this card *//* 48-bit response decoding (32 bits w/o CRC) */#defineMMC_R1(resp)((resp)[0])#defineMMC_R3(resp)((resp)[0])#defineMMC_R4(resp)((resp)[0])#defineMMC_R5(resp)((resp)[0])#defineSD_R6(resp)((resp)[0])#defineMMC_R1_CURRENT_STATE(resp)(((resp)[0]>>9)&0xf)/* SPI mode response decoding */#defineSD_SPI_R1(resp)((resp)[0]&0xff)#defineSD_SPI_R2(resp)((resp)[0]&0xffff)#defineSD_SPI_R3(resp)((resp)[0])#defineSD_SPI_R7(resp)((resp)[0])/* SPI mode data response decoding */#defineSD_SPI_DATA_RSP_VALID(resp_byte)(((resp_byte)&0x11)==0x1)#defineSD_SPI_DATA_RSP(resp_byte)(((resp_byte)>>1)&0x7)#defineSD_SPI_DATA_ACCEPTED0x2#defineSD_SPI_DATA_CRC_ERROR0x5#defineSD_SPI_DATA_WR_ERROR0x6/* RCA argument and response */#defineMMC_ARG_RCA(rca)((rca)<<16)#defineSD_R6_RCA(resp)(SD_R6((resp))>>16)/* bus width argument */#defineSD_ARG_BUS_WIDTH_10#defineSD_ARG_BUS_WIDTH_42/* EXT_CSD fields */#defineEXT_CSD_SANITIZE_START165/* WO */#defineEXT_CSD_ERASED_MEM_CONT181/* RO */#defineEXT_CSD_BUS_WIDTH183/* WO */#defineEXT_CSD_HS_TIMING185/* R/W */#defineEXT_CSD_POWER_CLASS187/* R/W */#defineEXT_CSD_CMD_SET191/* R/W */#defineEXT_CSD_REV192/* RO */#defineEXT_CSD_STRUCTURE194/* RO */#defineEXT_CSD_CARD_TYPE196/* RO */#defineEXT_CSD_PWR_CL_52_195200/* RO */#defineEXT_CSD_PWR_CL_26_195201/* RO */#defineEXT_CSD_PWR_CL_52_360202/* RO */#defineEXT_CSD_PWR_CL_26_360203/* RO */#defineEXT_CSD_SEC_COUNT212/* RO */#defineEXT_CSD_SEC_FEATURE_SUPPORT231/* RO */#defineEXT_CSD_S_CMD_SET504/* RO *//* EXT_CSD field definitions */#defineEXT_CSD_REV_1_66/* Revision 1.6 (for MMC v4.5, v4.51) */#defineEXT_CSD_CMD_SET_NORMAL(1U<<0)#defineEXT_CSD_CMD_SET_SECURE(1U<<1)#defineEXT_CSD_CMD_SET_CPSECURE(1U<<2)/* EXT_CSD_HS_TIMING */#defineEXT_CSD_HS_TIMING_BC0#defineEXT_CSD_HS_TIMING_HS1#defineEXT_CSD_HS_TIMING_HS2002#defineEXT_CSD_HS_TIMING_HS4003/* EXT_CSD_BUS_WIDTH */#defineEXT_CSD_BUS_WIDTH_10#defineEXT_CSD_BUS_WIDTH_41#defineEXT_CSD_BUS_WIDTH_82#defineEXT_CSD_BUS_WIDTH_4_DDR5#defineEXT_CSD_BUS_WIDTH_8_DDR6/* EXT_CSD_CARD_TYPE *//* The only currently valid values for this field are 0x01, 0x03, 0x07, * 0x0B and 0x0F. *//* ... */#defineEXT_CSD_CARD_TYPE_F_26M(1<<0)/* SDR at "rated voltages */#defineEXT_CSD_CARD_TYPE_F_52M(1<<1)/* SDR at "rated voltages */#defineEXT_CSD_CARD_TYPE_F_52M_1_8V(1<<2)/* DDR, 1.8V or 3.3V I/O */#defineEXT_CSD_CARD_TYPE_F_52M_1_2V(1<<3)/* DDR, 1.2V I/O */#defineEXT_CSD_CARD_TYPE_26M0x01#defineEXT_CSD_CARD_TYPE_52M0x03#defineEXT_CSD_CARD_TYPE_52M_V180x07#defineEXT_CSD_CARD_TYPE_52M_V120x0b#defineEXT_CSD_CARD_TYPE_52M_V12_180x0f/* EXT_CSD_SEC_FEATURE_SUPPORT */#defineEXT_CSD_SECURE_ER_EN(uint8_t)(1<<0)#defineEXT_CSD_SEC_BD_BLK_EN(uint8_t)(1<<2)#defineEXT_CSD_SEC_GB_CL_EN(uint8_t)(1<<4)#defineEXT_CSD_SEC_SANITIZE(uint8_t)(1<<6)/* EXT_CSD MMC */#defineEXT_CSD_MMC_SIZE512/* MMC_SWITCH access mode */#defineMMC_SWITCH_MODE_CMD_SET0x00/* Change the command set */#defineMMC_SWITCH_MODE_SET_BITS0x01/* Set bits in value */#defineMMC_SWITCH_MODE_CLEAR_BITS0x02/* Clear bits in value */#defineMMC_SWITCH_MODE_WRITE_BYTE0x03/* Set target to value *//* MMC R2 response (CSD) */#defineMMC_CSD_CSDVER(resp)MMC_RSP_BITS((resp),126,2)#defineMMC_CSD_CSDVER_1_01#defineMMC_CSD_CSDVER_2_02#defineMMC_CSD_CSDVER_EXT_CSD3#defineMMC_CSD_MMCVER(resp)MMC_RSP_BITS((resp),122,4)#defineMMC_CSD_MMCVER_1_00/* MMC 1.0 - 1.2 */#defineMMC_CSD_MMCVER_1_41/* MMC 1.4 */#defineMMC_CSD_MMCVER_2_02/* MMC 2.0 - 2.2 */#defineMMC_CSD_MMCVER_3_13/* MMC 3.1 - 3.3 */#defineMMC_CSD_MMCVER_4_04/* MMC 4 */#defineMMC_CSD_READ_BL_LEN(resp)MMC_RSP_BITS((resp),80,4)#defineMMC_CSD_C_SIZE(resp)MMC_RSP_BITS((resp),62,12)#defineMMC_CSD_CAPACITY(resp)((MMC_CSD_C_SIZE((resp))+1)<<\(MMC_CSD_C_SIZE_MULT((resp))+2))...#defineMMC_CSD_C_SIZE_MULT(resp)MMC_RSP_BITS((resp),47,3)#defineMMC_CSD_WRITE_BL_PARTIAL(resp)MMC_RSP_BITS((resp),21,1)/* MMC v1 R2 response (CID) */#defineMMC_CID_MID_V1(resp)MMC_RSP_BITS((resp),104,24)#defineMMC_CID_PNM_V1_CPY(resp,pnm)\do{\(pnm)[0]=MMC_RSP_BITS((resp),96,8);\(pnm)[1]=MMC_RSP_BITS((resp),88,8);\(pnm)[2]=MMC_RSP_BITS((resp),80,8);\(pnm)[3]=MMC_RSP_BITS((resp),72,8);\(pnm)[4]=MMC_RSP_BITS((resp),64,8);\(pnm)[5]=MMC_RSP_BITS((resp),56,8);\(pnm)[6]=MMC_RSP_BITS((resp),48,8);\(pnm)[7]='\0';\}{...}while(0)...#defineMMC_CID_REV_V1(resp)MMC_RSP_BITS((resp),40,8)#defineMMC_CID_PSN_V1(resp)MMC_RSP_BITS((resp),16,24)#defineMMC_CID_MDT_V1(resp)MMC_RSP_BITS((resp),8,8)/* MMC v2 R2 response (CID) */#defineMMC_CID_MID_V2(resp)MMC_RSP_BITS((resp),120,8)#defineMMC_CID_OID_V2(resp)MMC_RSP_BITS((resp),104,16)#defineMMC_CID_PNM_V2_CPY(resp,pnm)\do{\(pnm)[0]=MMC_RSP_BITS((resp),96,8);\(pnm)[1]=MMC_RSP_BITS((resp),88,8);\(pnm)[2]=MMC_RSP_BITS((resp),80,8);\(pnm)[3]=MMC_RSP_BITS((resp),72,8);\(pnm)[4]=MMC_RSP_BITS((resp),64,8);\(pnm)[5]=MMC_RSP_BITS((resp),56,8);\(pnm)[6]='\0';\}{...}while(0)...#defineMMC_CID_PSN_V2(resp)MMC_RSP_BITS((resp),16,32)/* SD R2 response (CSD) */#defineSD_CSD_CSDVER(resp)MMC_RSP_BITS((resp),126,2)#defineSD_CSD_CSDVER_1_00#defineSD_CSD_CSDVER_2_01#defineSD_CSD_TAAC(resp)MMC_RSP_BITS((resp),112,8)#defineSD_CSD_TAAC_1_5_MSEC0x26#defineSD_CSD_NSAC(resp)MMC_RSP_BITS((resp),104,8)#defineSD_CSD_SPEED(resp)MMC_RSP_BITS((resp),96,8)#defineSD_CSD_SPEED_25_MHZ0x32#defineSD_CSD_SPEED_50_MHZ0x5a#defineSD_CSD_SPEED_100_MHZ0xb#defineSD_CSD_SPEED_200_MHZ0x2b#defineSD_CSD_CCC(resp)MMC_RSP_BITS((resp),84,12)#defineSD_CSD_CCC_BASIC(1<<0)/* basic */#defineSD_CSD_CCC_BR(1<<2)/* block read */#defineSD_CSD_CCC_BW(1<<4)/* block write */#defineSD_CSD_CCC_ERASE(1<<5)/* erase */#defineSD_CSD_CCC_WP(1<<6)/* write protection */#defineSD_CSD_CCC_LC(1<<7)/* lock card */#defineSD_CSD_CCC_AS(1<<8)/*application specific*/#defineSD_CSD_CCC_IOM(1<<9)/* I/O mode */#defineSD_CSD_CCC_SWITCH(1<<10)/* switch */#defineSD_CSD_READ_BL_LEN(resp)MMC_RSP_BITS((resp),80,4)#defineSD_CSD_READ_BL_PARTIAL(resp)MMC_RSP_BITS((resp),79,1)#defineSD_CSD_WRITE_BLK_MISALIGN(resp)MMC_RSP_BITS((resp),78,1)#defineSD_CSD_READ_BLK_MISALIGN(resp)MMC_RSP_BITS((resp),77,1)#defineSD_CSD_DSR_IMP(resp)MMC_RSP_BITS((resp),76,1)#defineSD_CSD_C_SIZE(resp)MMC_RSP_BITS((resp),62,12)#defineSD_CSD_CAPACITY(resp)((SD_CSD_C_SIZE((resp))+1)<<\(SD_CSD_C_SIZE_MULT((resp))+2))...#defineSD_CSD_V2_C_SIZE(resp)MMC_RSP_BITS((resp),48,22)#defineSD_CSD_V2_CAPACITY(resp)((SD_CSD_V2_C_SIZE((resp))+1)<<10)#defineSD_CSD_V2_BL_LEN0x9/* 512 */#defineSD_CSD_VDD_R_CURR_MIN(resp)MMC_RSP_BITS((resp),59,3)#defineSD_CSD_VDD_R_CURR_MAX(resp)MMC_RSP_BITS((resp),56,3)#defineSD_CSD_VDD_W_CURR_MIN(resp)MMC_RSP_BITS((resp),53,3)#defineSD_CSD_VDD_W_CURR_MAX(resp)MMC_RSP_BITS((resp),50,3)#defineSD_CSD_VDD_RW_CURR_100mA0x7#defineSD_CSD_VDD_RW_CURR_80mA0x6#defineSD_CSD_C_SIZE_MULT(resp)MMC_RSP_BITS((resp),47,3)#defineSD_CSD_ERASE_BLK_EN(resp)MMC_RSP_BITS((resp),46,1)#defineSD_CSD_SECTOR_SIZE(resp)MMC_RSP_BITS((resp),39,7)/* +1 */#defineSD_CSD_WP_GRP_SIZE(resp)MMC_RSP_BITS((resp),32,7)/* +1 */#defineSD_CSD_WP_GRP_ENABLE(resp)MMC_RSP_BITS((resp),31,1)#defineSD_CSD_R2W_FACTOR(resp)MMC_RSP_BITS((resp),26,3)#defineSD_CSD_WRITE_BL_LEN(resp)MMC_RSP_BITS((resp),22,4)#defineSD_CSD_RW_BL_LEN_2G0xa#defineSD_CSD_RW_BL_LEN_1G0x9#defineSD_CSD_WRITE_BL_PARTIAL(resp)MMC_RSP_BITS((resp),21,1)#defineSD_CSD_FILE_FORMAT_GRP(resp)MMC_RSP_BITS((resp),15,1)#defineSD_CSD_COPY(resp)MMC_RSP_BITS((resp),14,1)#defineSD_CSD_PERM_WRITE_PROTECT(resp)MMC_RSP_BITS((resp),13,1)#defineSD_CSD_TMP_WRITE_PROTECT(resp)MMC_RSP_BITS((resp),12,1)#defineSD_CSD_FILE_FORMAT(resp)MMC_RSP_BITS((resp),10,2)/* SD R2 response (CID) */#defineSD_CID_MID(resp)MMC_RSP_BITS((resp),120,8)#defineSD_CID_OID(resp)MMC_RSP_BITS((resp),104,16)#defineSD_CID_PNM_CPY(resp,pnm)\do{\(pnm)[0]=MMC_RSP_BITS((resp),96,8);\(pnm)[1]=MMC_RSP_BITS((resp),88,8);\(pnm)[2]=MMC_RSP_BITS((resp),80,8);\(pnm)[3]=MMC_RSP_BITS((resp),72,8);\(pnm)[4]=MMC_RSP_BITS((resp),64,8);\(pnm)[5]='\0';\}{...}while(0)...#defineSD_CID_REV(resp)MMC_RSP_BITS((resp),56,8)#defineSD_CID_PSN(resp)MMC_RSP_BITS((resp),24,32)#defineSD_CID_MDT(resp)MMC_RSP_BITS((resp),8,12)/* SCR (SD Configuration Register) */#defineSCR_STRUCTURE(scr)MMC_RSP_BITS((scr),60,4)#defineSCR_STRUCTURE_VER_1_00/* Version 1.0 */#defineSCR_SD_SPEC(scr)MMC_RSP_BITS((scr),56,4)#defineSCR_SD_SPEC_VER_1_00/* Version 1.0 and 1.01 */#defineSCR_SD_SPEC_VER_1_101/* Version 1.10 */#defineSCR_SD_SPEC_VER_22/* Version 2.00 or Version 3.0X */#defineSCR_DATA_STAT_AFTER_ERASE(scr)MMC_RSP_BITS((scr),55,1)#defineSCR_SD_SECURITY(scr)MMC_RSP_BITS((scr),52,3)#defineSCR_SD_SECURITY_NONE0/* no security */#defineSCR_SD_SECURITY_1_01/* security protocol 1.0 */#defineSCR_SD_SECURITY_1_0_22/* security protocol 1.0 */#defineSCR_SD_BUS_WIDTHS(scr)MMC_RSP_BITS((scr),48,4)#defineSCR_SD_BUS_WIDTHS_1BIT(1<<0)/* 1bit (DAT0) */#defineSCR_SD_BUS_WIDTHS_4BIT(1<<2)/* 4bit (DAT0-3) */#defineSCR_SD_SPEC3(scr)MMC_RSP_BITS((scr),47,1)#defineSCR_EX_SECURITY(scr)MMC_RSP_BITS((scr),43,4)#defineSCR_SD_SPEC4(scr)MMC_RSP_BITS((scr),42,1)#defineSCR_RESERVED(scr)MMC_RSP_BITS((scr),34,8)#defineSCR_CMD_SUPPORT_CMD23(scr)MMC_RSP_BITS((scr),33,1)#defineSCR_CMD_SUPPORT_CMD20(scr)MMC_RSP_BITS((scr),32,1)#defineSCR_RESERVED2(scr)MMC_RSP_BITS((scr),0,32)/* SSR (SD Status Register) */#defineSSR_DAT_BUS_WIDTH(ssr)MMC_RSP_BITS((ssr),510,2)#defineSSR_AU_SIZE(ssr)MMC_RSP_BITS((ssr),428,4)#defineSSR_ERASE_SIZE(ssr)MMC_RSP_BITS((ssr),408,16)#defineSSR_ERASE_TIMEOUT(ssr)MMC_RSP_BITS((ssr),402,6)#defineSSR_ERASE_OFFSET(ssr)MMC_RSP_BITS((ssr),400,2)#defineSSR_DISCARD_SUPPORT(ssr)MMC_RSP_BITS((ssr),313,1)#defineSSR_FULE_SUPPORT(ssr)MMC_RSP_BITS((ssr),312,1)/* Max supply current in SWITCH_FUNC response (in mA) */#defineSD_SFUNC_I_MAX(status)(MMC_RSP_BITS((uint32_t*)(status),496,16))/* Supported flags in SWITCH_FUNC response */#defineSD_SFUNC_SUPPORTED(status,group)\(MMC_RSP_BITS((uint32_t*)(status),400+(group-1)*16,16)).../* Selected function in SWITCH_FUNC response */#defineSD_SFUNC_SELECTED(status,group)\(MMC_RSP_BITS((uint32_t*)(status),376+(group-1)*4,4)).../* Busy flags in SWITCH_FUNC response */#defineSD_SFUNC_BUSY(status,group)\(MMC_RSP_BITS((uint32_t*)(status),272+(group-1)*16,16)).../* Version of SWITCH_FUNC response */#defineSD_SFUNC_VER(status)(MMC_RSP_BITS((uint32_t*)(status),368,8))#defineSD_SFUNC_GROUP_MAX6#defineSD_SFUNC_FUNC_MAX15#defineSD_ACCESS_MODE1/* Function group 1, Access Mode */#defineSD_COMMAND_SYSTEM2/* Function group 1, Command System */#defineSD_DRIVER_STRENGTH3/* Function group 1, Driver Strength */#defineSD_CURRENT_LIMIT4/* Function group 1, Current Limit */#defineSD_DRIVER_STRENGTH_B0/* Type B */#defineSD_DRIVER_STRENGTH_A1/* Type A */#defineSD_DRIVER_STRENGTH_C2/* Type C */#defineSD_DRIVER_STRENGTH_D3/* Type D */#defineSD_ACCESS_MODE_SDR120/* 25 MHz clock */#defineSD_ACCESS_MODE_SDR251/* 50 MHz clock */#defineSD_ACCESS_MODE_SDR502/* UHS-I, 100 MHz clock */#defineSD_ACCESS_MODE_SDR1043/* UHS-I, 208 MHz clock */#defineSD_ACCESS_MODE_DDR504/* UHS-I, 50 MHz clock, DDR */#defineSD_SSR_SIZE64/* SD status register */296 defines/** * @brief Extract up to 32 sequential bits from an array of 32-bit words * * Bits within the word are numbered in the increasing order from LSB to MSB. * * As an example, consider 2 32-bit words: * * 0x01234567 0x89abcdef * * On a little-endian system, the bytes are stored in memory as follows: * * 67 45 23 01 ef cd ab 89 * * MMC_RSP_BITS will extract bits as follows: * * start=0 len=4 -> result=0x00000007 * start=0 len=12 -> result=0x00000567 * start=28 len=8 -> result=0x000000f0 * start=59 len=5 -> result=0x00000011 * * @param src array of words to extract bits from * @param start index of the first bit to extract * @param len number of bits to extract, 1 to 32 * @return 32-bit word where requested bits start from LSB *//* ... */staticinlineuint32_tMMC_RSP_BITS(uint32_t*src,intstart,intlen){uint32_tmask=(len%32==0)?UINT_MAX:UINT_MAX>>(32-(len%32));size_tword=start/32;size_tshift=start%32;uint32_tright=src[word]>>shift;uint32_tleft=(len+shift<=32)?0:src[word+1]<<((32-shift)%32);return(left|right)&mask;}{ ... }/* SD R4 response (IO OCR) */#defineSD_IO_OCR_MEM_READY(1<<31)#defineSD_IO_OCR_NUM_FUNCTIONS(ocr)(((ocr)>>28)&0x7)#defineSD_IO_OCR_MEM_PRESENT(1<<27)#defineSD_IO_OCR_MASK0x00fffff0/* CMD52 arguments */#defineSD_ARG_CMD52_READ(0<<31)#defineSD_ARG_CMD52_WRITE(1<<31)#defineSD_ARG_CMD52_FUNC_SHIFT28#defineSD_ARG_CMD52_FUNC_MASK0x7#defineSD_ARG_CMD52_EXCHANGE(1<<27)#defineSD_ARG_CMD52_REG_SHIFT9#defineSD_ARG_CMD52_REG_MASK0x1ffff#defineSD_ARG_CMD52_DATA_SHIFT0#defineSD_ARG_CMD52_DATA_MASK0xff#defineSD_R5_DATA(resp)((resp)[0]&0xff)/* CMD53 arguments */#defineSD_ARG_CMD53_READ(0<<31)#defineSD_ARG_CMD53_WRITE(1<<31)#defineSD_ARG_CMD53_FUNC_SHIFT28#defineSD_ARG_CMD53_FUNC_MASK0x7#defineSD_ARG_CMD53_BLOCK_MODE(1<<27)#defineSD_ARG_CMD53_INCREMENT(1<<26)#defineSD_ARG_CMD53_REG_SHIFT9#defineSD_ARG_CMD53_REG_MASK0x1ffff#defineSD_ARG_CMD53_LENGTH_SHIFT0#defineSD_ARG_CMD53_LENGTH_MASK0x1ff#defineSD_ARG_CMD53_LENGTH_MAX512/* Card Common Control Registers (CCCR) */#defineSD_IO_CCCR_START0x00000#defineSD_IO_CCCR_SIZE0x100#defineSD_IO_CCCR_FN_ENABLE0x02#defineSD_IO_CCCR_FN_READY0x03#defineSD_IO_CCCR_INT_ENABLE0x04#defineSD_IO_CCCR_INT_PENDING0x05#defineSD_IO_CCCR_CTL0x06#defineCCCR_CTL_RES(1<<3)#defineSD_IO_CCCR_BUS_WIDTH0x07#defineCCCR_BUS_WIDTH_1(0<<0)#defineCCCR_BUS_WIDTH_4(2<<0)#defineCCCR_BUS_WIDTH_8(3<<0)#defineCCCR_BUS_WIDTH_ECSI(1<<5)#defineSD_IO_CCCR_CARD_CAP0x08#defineCCCR_CARD_CAP_LSCBIT(6)#defineCCCR_CARD_CAP_4BLSBIT(7)#defineSD_IO_CCCR_CISPTR0x09#defineSD_IO_CCCR_BLKSIZEL0x10#defineSD_IO_CCCR_BLKSIZEH0x11#defineSD_IO_CCCR_HIGHSPEED0x13#defineCCCR_HIGHSPEED_SUPPORTBIT(0)#defineCCCR_HIGHSPEED_ENABLEBIT(1)/* Function Basic Registers (FBR) */#defineSD_IO_FBR_START0x00100#defineSD_IO_FBR_SIZE0x00700/* Card Information Structure (CIS) */#defineSD_IO_CIS_START0x01000#defineSD_IO_CIS_SIZE0x17000/* CIS tuple codes (based on PC Card 16) */#defineCISTPL_CODE_NULL0x00#defineCISTPL_CODE_DEVICE0x01#defineCISTPL_CODE_CHKSUM0x10#defineCISTPL_CODE_VERS10x15#defineCISTPL_CODE_ALTSTR0x16#defineCISTPL_CODE_CONFIG0x1A#defineCISTPL_CODE_CFTABLE_ENTRY0x1B#defineCISTPL_CODE_MANFID0x20#defineCISTPL_CODE_FUNCID0x21#defineTPLFID_FUNCTION_SDIO0x0c#defineCISTPL_CODE_FUNCE0x22#defineCISTPL_CODE_VENDER_BEGIN0x80#defineCISTPL_CODE_VENDER_END0x8F#defineCISTPL_CODE_SDIO_STD0x91#defineCISTPL_CODE_SDIO_EXT0x92#defineCISTPL_CODE_END0xFF/* Timing */#defineSDMMC_TIMING_LEGACY0#defineSDMMC_TIMING_HIGHSPEED1#defineSDMMC_TIMING_MMC_DDR52270 defines#ifdef__cplusplus}{...}#endif
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.