Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/include/linux/mmc/card.h
0004  *
0005  *  Card driver specific definitions.
0006  */
0007 #ifndef LINUX_MMC_CARD_H
0008 #define LINUX_MMC_CARD_H
0009 
0010 #include <linux/device.h>
0011 #include <linux/mod_devicetable.h>
0012 
0013 struct mmc_cid {
0014     unsigned int        manfid;
0015     char            prod_name[8];
0016     unsigned char       prv;
0017     unsigned int        serial;
0018     unsigned short      oemid;
0019     unsigned short      year;
0020     unsigned char       hwrev;
0021     unsigned char       fwrev;
0022     unsigned char       month;
0023 };
0024 
0025 struct mmc_csd {
0026     unsigned char       structure;
0027     unsigned char       mmca_vsn;
0028     unsigned short      cmdclass;
0029     unsigned short      taac_clks;
0030     unsigned int        taac_ns;
0031     unsigned int        c_size;
0032     unsigned int        r2w_factor;
0033     unsigned int        max_dtr;
0034     unsigned int        erase_size;     /* In sectors */
0035     unsigned int        read_blkbits;
0036     unsigned int        write_blkbits;
0037     unsigned int        capacity;
0038     unsigned int        read_partial:1,
0039                 read_misalign:1,
0040                 write_partial:1,
0041                 write_misalign:1,
0042                 dsr_imp:1;
0043 };
0044 
0045 struct mmc_ext_csd {
0046     u8          rev;
0047     u8          erase_group_def;
0048     u8          sec_feature_support;
0049     u8          rel_sectors;
0050     u8          rel_param;
0051     bool            enhanced_rpmb_supported;
0052     u8          part_config;
0053     u8          cache_ctrl;
0054     u8          rst_n_function;
0055     u8          max_packed_writes;
0056     u8          max_packed_reads;
0057     u8          packed_event_en;
0058     unsigned int        part_time;      /* Units: ms */
0059     unsigned int        sa_timeout;     /* Units: 100ns */
0060     unsigned int        generic_cmd6_time;  /* Units: 10ms */
0061     unsigned int            power_off_longtime;     /* Units: ms */
0062     u8          power_off_notification; /* state */
0063     unsigned int        hs_max_dtr;
0064     unsigned int        hs200_max_dtr;
0065 #define MMC_HIGH_26_MAX_DTR 26000000
0066 #define MMC_HIGH_52_MAX_DTR 52000000
0067 #define MMC_HIGH_DDR_MAX_DTR    52000000
0068 #define MMC_HS200_MAX_DTR   200000000
0069     unsigned int        sectors;
0070     unsigned int        hc_erase_size;      /* In sectors */
0071     unsigned int        hc_erase_timeout;   /* In milliseconds */
0072     unsigned int        sec_trim_mult;  /* Secure trim multiplier  */
0073     unsigned int        sec_erase_mult; /* Secure erase multiplier */
0074     unsigned int        trim_timeout;       /* In milliseconds */
0075     bool            partition_setting_completed;    /* enable bit */
0076     unsigned long long  enhanced_area_offset;   /* Units: Byte */
0077     unsigned int        enhanced_area_size; /* Units: KB */
0078     unsigned int        cache_size;     /* Units: KB */
0079     bool            hpi_en;         /* HPI enablebit */
0080     bool            hpi;            /* HPI support bit */
0081     unsigned int        hpi_cmd;        /* cmd used as HPI */
0082     bool            bkops;      /* background support bit */
0083     bool            man_bkops_en;   /* manual bkops enable bit */
0084     bool            auto_bkops_en;  /* auto bkops enable bit */
0085     unsigned int            data_sector_size;       /* 512 bytes or 4KB */
0086     unsigned int            data_tag_unit_size;     /* DATA TAG UNIT size */
0087     unsigned int        boot_ro_lock;       /* ro lock support */
0088     bool            boot_ro_lockable;
0089     bool            ffu_capable;    /* Firmware upgrade support */
0090     bool            cmdq_en;    /* Command Queue enabled */
0091     bool            cmdq_support;   /* Command Queue supported */
0092     unsigned int        cmdq_depth; /* Command Queue depth */
0093 #define MMC_FIRMWARE_LEN 8
0094     u8          fwrev[MMC_FIRMWARE_LEN];  /* FW version */
0095     u8          raw_exception_status;   /* 54 */
0096     u8          raw_partition_support;  /* 160 */
0097     u8          raw_rpmb_size_mult; /* 168 */
0098     u8          raw_erased_mem_count;   /* 181 */
0099     u8          strobe_support;     /* 184 */
0100     u8          raw_ext_csd_structure;  /* 194 */
0101     u8          raw_card_type;      /* 196 */
0102     u8          raw_driver_strength;    /* 197 */
0103     u8          out_of_int_time;    /* 198 */
0104     u8          raw_pwr_cl_52_195;  /* 200 */
0105     u8          raw_pwr_cl_26_195;  /* 201 */
0106     u8          raw_pwr_cl_52_360;  /* 202 */
0107     u8          raw_pwr_cl_26_360;  /* 203 */
0108     u8          raw_s_a_timeout;    /* 217 */
0109     u8          raw_hc_erase_gap_size;  /* 221 */
0110     u8          raw_erase_timeout_mult; /* 223 */
0111     u8          raw_hc_erase_grp_size;  /* 224 */
0112     u8          raw_boot_mult;      /* 226 */
0113     u8          raw_sec_trim_mult;  /* 229 */
0114     u8          raw_sec_erase_mult; /* 230 */
0115     u8          raw_sec_feature_support;/* 231 */
0116     u8          raw_trim_mult;      /* 232 */
0117     u8          raw_pwr_cl_200_195; /* 236 */
0118     u8          raw_pwr_cl_200_360; /* 237 */
0119     u8          raw_pwr_cl_ddr_52_195;  /* 238 */
0120     u8          raw_pwr_cl_ddr_52_360;  /* 239 */
0121     u8          raw_pwr_cl_ddr_200_360; /* 253 */
0122     u8          raw_bkops_status;   /* 246 */
0123     u8          raw_sectors[4];     /* 212 - 4 bytes */
0124     u8          pre_eol_info;       /* 267 */
0125     u8          device_life_time_est_typ_a; /* 268 */
0126     u8          device_life_time_est_typ_b; /* 269 */
0127 
0128     unsigned int            feature_support;
0129 #define MMC_DISCARD_FEATURE BIT(0)                  /* CMD38 feature */
0130 };
0131 
0132 struct sd_scr {
0133     unsigned char       sda_vsn;
0134     unsigned char       sda_spec3;
0135     unsigned char       sda_spec4;
0136     unsigned char       sda_specx;
0137     unsigned char       bus_widths;
0138 #define SD_SCR_BUS_WIDTH_1  (1<<0)
0139 #define SD_SCR_BUS_WIDTH_4  (1<<2)
0140     unsigned char       cmds;
0141 #define SD_SCR_CMD20_SUPPORT   (1<<0)
0142 #define SD_SCR_CMD23_SUPPORT   (1<<1)
0143 #define SD_SCR_CMD48_SUPPORT   (1<<2)
0144 #define SD_SCR_CMD58_SUPPORT   (1<<3)
0145 };
0146 
0147 struct sd_ssr {
0148     unsigned int        au;         /* In sectors */
0149     unsigned int        erase_timeout;      /* In milliseconds */
0150     unsigned int        erase_offset;       /* In milliseconds */
0151 };
0152 
0153 struct sd_switch_caps {
0154     unsigned int        hs_max_dtr;
0155     unsigned int        uhs_max_dtr;
0156 #define HIGH_SPEED_MAX_DTR  50000000
0157 #define UHS_SDR104_MAX_DTR  208000000
0158 #define UHS_SDR50_MAX_DTR   100000000
0159 #define UHS_DDR50_MAX_DTR   50000000
0160 #define UHS_SDR25_MAX_DTR   UHS_DDR50_MAX_DTR
0161 #define UHS_SDR12_MAX_DTR   25000000
0162 #define DEFAULT_SPEED_MAX_DTR   UHS_SDR12_MAX_DTR
0163     unsigned int        sd3_bus_mode;
0164 #define UHS_SDR12_BUS_SPEED 0
0165 #define HIGH_SPEED_BUS_SPEED    1
0166 #define UHS_SDR25_BUS_SPEED 1
0167 #define UHS_SDR50_BUS_SPEED 2
0168 #define UHS_SDR104_BUS_SPEED    3
0169 #define UHS_DDR50_BUS_SPEED 4
0170 
0171 #define SD_MODE_HIGH_SPEED  (1 << HIGH_SPEED_BUS_SPEED)
0172 #define SD_MODE_UHS_SDR12   (1 << UHS_SDR12_BUS_SPEED)
0173 #define SD_MODE_UHS_SDR25   (1 << UHS_SDR25_BUS_SPEED)
0174 #define SD_MODE_UHS_SDR50   (1 << UHS_SDR50_BUS_SPEED)
0175 #define SD_MODE_UHS_SDR104  (1 << UHS_SDR104_BUS_SPEED)
0176 #define SD_MODE_UHS_DDR50   (1 << UHS_DDR50_BUS_SPEED)
0177     unsigned int        sd3_drv_type;
0178 #define SD_DRIVER_TYPE_B    0x01
0179 #define SD_DRIVER_TYPE_A    0x02
0180 #define SD_DRIVER_TYPE_C    0x04
0181 #define SD_DRIVER_TYPE_D    0x08
0182     unsigned int        sd3_curr_limit;
0183 #define SD_SET_CURRENT_LIMIT_200    0
0184 #define SD_SET_CURRENT_LIMIT_400    1
0185 #define SD_SET_CURRENT_LIMIT_600    2
0186 #define SD_SET_CURRENT_LIMIT_800    3
0187 #define SD_SET_CURRENT_NO_CHANGE    (-1)
0188 
0189 #define SD_MAX_CURRENT_200  (1 << SD_SET_CURRENT_LIMIT_200)
0190 #define SD_MAX_CURRENT_400  (1 << SD_SET_CURRENT_LIMIT_400)
0191 #define SD_MAX_CURRENT_600  (1 << SD_SET_CURRENT_LIMIT_600)
0192 #define SD_MAX_CURRENT_800  (1 << SD_SET_CURRENT_LIMIT_800)
0193 };
0194 
0195 struct sd_ext_reg {
0196     u8          fno;
0197     u8          page;
0198     u16         offset;
0199     u8          rev;
0200     u8          feature_enabled;
0201     u8          feature_support;
0202 /* Power Management Function. */
0203 #define SD_EXT_POWER_OFF_NOTIFY (1<<0)
0204 #define SD_EXT_POWER_SUSTENANCE (1<<1)
0205 #define SD_EXT_POWER_DOWN_MODE  (1<<2)
0206 /* Performance Enhancement Function. */
0207 #define SD_EXT_PERF_FX_EVENT    (1<<0)
0208 #define SD_EXT_PERF_CARD_MAINT  (1<<1)
0209 #define SD_EXT_PERF_HOST_MAINT  (1<<2)
0210 #define SD_EXT_PERF_CACHE   (1<<3)
0211 #define SD_EXT_PERF_CMD_QUEUE   (1<<4)
0212 };
0213 
0214 struct sdio_cccr {
0215     unsigned int        sdio_vsn;
0216     unsigned int        sd_vsn;
0217     unsigned int        multi_block:1,
0218                 low_speed:1,
0219                 wide_bus:1,
0220                 high_power:1,
0221                 high_speed:1,
0222                 disable_cd:1,
0223                 enable_async_irq:1;
0224 };
0225 
0226 struct sdio_cis {
0227     unsigned short      vendor;
0228     unsigned short      device;
0229     unsigned short      blksize;
0230     unsigned int        max_dtr;
0231 };
0232 
0233 struct mmc_host;
0234 struct sdio_func;
0235 struct sdio_func_tuple;
0236 struct mmc_queue_req;
0237 
0238 #define SDIO_MAX_FUNCS      7
0239 
0240 /* The number of MMC physical partitions.  These consist of:
0241  * boot partitions (2), general purpose partitions (4) and
0242  * RPMB partition (1) in MMC v4.4.
0243  */
0244 #define MMC_NUM_BOOT_PARTITION  2
0245 #define MMC_NUM_GP_PARTITION    4
0246 #define MMC_NUM_PHY_PARTITION   7
0247 #define MAX_MMC_PART_NAME_LEN   20
0248 
0249 /*
0250  * MMC Physical partitions
0251  */
0252 struct mmc_part {
0253     u64     size;   /* partition size (in bytes) */
0254     unsigned int    part_cfg;   /* partition type */
0255     char    name[MAX_MMC_PART_NAME_LEN];
0256     bool    force_ro;   /* to make boot parts RO by default */
0257     unsigned int    area_type;
0258 #define MMC_BLK_DATA_AREA_MAIN  (1<<0)
0259 #define MMC_BLK_DATA_AREA_BOOT  (1<<1)
0260 #define MMC_BLK_DATA_AREA_GP    (1<<2)
0261 #define MMC_BLK_DATA_AREA_RPMB  (1<<3)
0262 };
0263 
0264 /*
0265  * MMC device
0266  */
0267 struct mmc_card {
0268     struct mmc_host     *host;      /* the host this device belongs to */
0269     struct device       dev;        /* the device */
0270     u32         ocr;        /* the current OCR setting */
0271     unsigned int        rca;        /* relative card address of device */
0272     unsigned int        type;       /* card type */
0273 #define MMC_TYPE_MMC        0       /* MMC card */
0274 #define MMC_TYPE_SD     1       /* SD card */
0275 #define MMC_TYPE_SDIO       2       /* SDIO card */
0276 #define MMC_TYPE_SD_COMBO   3       /* SD combo (IO+mem) card */
0277     unsigned int        state;      /* (our) card state */
0278     unsigned int        quirks;     /* card quirks */
0279     unsigned int        quirk_max_rate; /* max rate set by quirks */
0280 #define MMC_QUIRK_LENIENT_FN0   (1<<0)      /* allow SDIO FN0 writes outside of the VS CCCR range */
0281 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)    /* use func->cur_blksize */
0282                         /* for byte mode */
0283 #define MMC_QUIRK_NONSTD_SDIO   (1<<2)      /* non-standard SDIO card attached */
0284                         /* (missing CIA registers) */
0285 #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4)     /* SDIO card has nonstd function interfaces */
0286 #define MMC_QUIRK_DISABLE_CD    (1<<5)      /* disconnect CD/DAT[3] resistor */
0287 #define MMC_QUIRK_INAND_CMD38   (1<<6)      /* iNAND devices have broken CMD38 */
0288 #define MMC_QUIRK_BLK_NO_CMD23  (1<<7)      /* Avoid CMD23 for regular multiblock */
0289 #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8)   /* Avoid sending 512 bytes in */
0290                         /* byte mode */
0291 #define MMC_QUIRK_LONG_READ_TIME (1<<9)     /* Data read time > CSD says */
0292 #define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */
0293 #define MMC_QUIRK_BROKEN_IRQ_POLLING    (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */
0294 #define MMC_QUIRK_TRIM_BROKEN   (1<<12)     /* Skip trim */
0295 #define MMC_QUIRK_BROKEN_HPI    (1<<13)     /* Disable broken HPI support */
0296 
0297     bool            reenable_cmdq;  /* Re-enable Command Queue */
0298 
0299     unsigned int        erase_size; /* erase size in sectors */
0300     unsigned int        erase_shift;    /* if erase unit is power 2 */
0301     unsigned int        pref_erase; /* in sectors */
0302     unsigned int        eg_boundary;    /* don't cross erase-group boundaries */
0303     unsigned int        erase_arg;  /* erase / trim / discard */
0304     u8          erased_byte;    /* value of erased bytes */
0305 
0306     u32         raw_cid[4]; /* raw card CID */
0307     u32         raw_csd[4]; /* raw card CSD */
0308     u32         raw_scr[2]; /* raw card SCR */
0309     u32         raw_ssr[16];    /* raw card SSR */
0310     struct mmc_cid      cid;        /* card identification */
0311     struct mmc_csd      csd;        /* card specific */
0312     struct mmc_ext_csd  ext_csd;    /* mmc v4 extended card specific */
0313     struct sd_scr       scr;        /* extra SD information */
0314     struct sd_ssr       ssr;        /* yet more SD information */
0315     struct sd_switch_caps   sw_caps;    /* switch (CMD6) caps */
0316     struct sd_ext_reg   ext_power;  /* SD extension reg for PM */
0317     struct sd_ext_reg   ext_perf;   /* SD extension reg for PERF */
0318 
0319     unsigned int        sdio_funcs; /* number of SDIO functions */
0320     atomic_t        sdio_funcs_probed; /* number of probed SDIO funcs */
0321     struct sdio_cccr    cccr;       /* common card info */
0322     struct sdio_cis     cis;        /* common tuple info */
0323     struct sdio_func    *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
0324     struct sdio_func    *sdio_single_irq; /* SDIO function when only one IRQ active */
0325     u8          major_rev;  /* major revision number */
0326     u8          minor_rev;  /* minor revision number */
0327     unsigned        num_info;   /* number of info strings */
0328     const char      **info;     /* info strings */
0329     struct sdio_func_tuple  *tuples;    /* unknown common tuples */
0330 
0331     unsigned int        sd_bus_speed;   /* Bus Speed Mode set for the card */
0332     unsigned int        mmc_avail_type; /* supported device type by both host and card */
0333     unsigned int        drive_strength; /* for UHS-I, HS200 or HS400 */
0334 
0335     struct dentry       *debugfs_root;
0336     struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
0337     unsigned int    nr_parts;
0338 
0339     struct workqueue_struct *complete_wq;   /* Private workqueue */
0340 };
0341 
0342 static inline bool mmc_large_sector(struct mmc_card *card)
0343 {
0344     return card->ext_csd.data_sector_size == 4096;
0345 }
0346 
0347 static inline int mmc_card_enable_async_irq(struct mmc_card *card)
0348 {
0349     return card->cccr.enable_async_irq;
0350 }
0351 
0352 bool mmc_card_is_blockaddr(struct mmc_card *card);
0353 
0354 #define mmc_card_mmc(c)     ((c)->type == MMC_TYPE_MMC)
0355 #define mmc_card_sd(c)      ((c)->type == MMC_TYPE_SD)
0356 #define mmc_card_sdio(c)    ((c)->type == MMC_TYPE_SDIO)
0357 #define mmc_card_sd_combo(c)    ((c)->type == MMC_TYPE_SD_COMBO)
0358 
0359 #endif /* LINUX_MMC_CARD_H */