linux/include/linux/mmc/card.h
<<
>>
Prefs
   1/*
   2 *  linux/include/linux/mmc/card.h
   3 *
   4 * This program is free software; you can redistribute it and/or modify
   5 * it under the terms of the GNU General Public License version 2 as
   6 * published by the Free Software Foundation.
   7 *
   8 *  Card driver specific definitions.
   9 */
  10#ifndef LINUX_MMC_CARD_H
  11#define LINUX_MMC_CARD_H
  12
  13#include <linux/device.h>
  14#include <linux/mod_devicetable.h>
  15
  16struct mmc_cid {
  17        unsigned int            manfid;
  18        char                    prod_name[8];
  19        unsigned char           prv;
  20        unsigned int            serial;
  21        unsigned short          oemid;
  22        unsigned short          year;
  23        unsigned char           hwrev;
  24        unsigned char           fwrev;
  25        unsigned char           month;
  26};
  27
  28struct mmc_csd {
  29        unsigned char           structure;
  30        unsigned char           mmca_vsn;
  31        unsigned short          cmdclass;
  32        unsigned short          taac_clks;
  33        unsigned int            taac_ns;
  34        unsigned int            c_size;
  35        unsigned int            r2w_factor;
  36        unsigned int            max_dtr;
  37        unsigned int            erase_size;             /* In sectors */
  38        unsigned int            read_blkbits;
  39        unsigned int            write_blkbits;
  40        unsigned int            capacity;
  41        unsigned int            read_partial:1,
  42                                read_misalign:1,
  43                                write_partial:1,
  44                                write_misalign:1,
  45                                dsr_imp:1;
  46};
  47
  48struct mmc_ext_csd {
  49        u8                      rev;
  50        u8                      erase_group_def;
  51        u8                      sec_feature_support;
  52        u8                      rel_sectors;
  53        u8                      rel_param;
  54        u8                      part_config;
  55        u8                      cache_ctrl;
  56        u8                      rst_n_function;
  57        u8                      max_packed_writes;
  58        u8                      max_packed_reads;
  59        u8                      packed_event_en;
  60        unsigned int            part_time;              /* Units: ms */
  61        unsigned int            sa_timeout;             /* Units: 100ns */
  62        unsigned int            generic_cmd6_time;      /* Units: 10ms */
  63        unsigned int            power_off_longtime;     /* Units: ms */
  64        u8                      power_off_notification; /* state */
  65        unsigned int            hs_max_dtr;
  66        unsigned int            hs200_max_dtr;
  67#define MMC_HIGH_26_MAX_DTR     26000000
  68#define MMC_HIGH_52_MAX_DTR     52000000
  69#define MMC_HIGH_DDR_MAX_DTR    52000000
  70#define MMC_HS200_MAX_DTR       200000000
  71        unsigned int            sectors;
  72        unsigned int            hc_erase_size;          /* In sectors */
  73        unsigned int            hc_erase_timeout;       /* In milliseconds */
  74        unsigned int            sec_trim_mult;  /* Secure trim multiplier  */
  75        unsigned int            sec_erase_mult; /* Secure erase multiplier */
  76        unsigned int            trim_timeout;           /* In milliseconds */
  77        bool                    partition_setting_completed;    /* enable bit */
  78        unsigned long long      enhanced_area_offset;   /* Units: Byte */
  79        unsigned int            enhanced_area_size;     /* Units: KB */
  80        unsigned int            cache_size;             /* Units: KB */
  81        bool                    hpi_en;                 /* HPI enablebit */
  82        bool                    hpi;                    /* HPI support bit */
  83        unsigned int            hpi_cmd;                /* cmd used as HPI */
  84        bool                    bkops;          /* background support bit */
  85        bool                    man_bkops_en;   /* manual bkops enable bit */
  86        bool                    auto_bkops_en;  /* auto bkops enable bit */
  87        unsigned int            data_sector_size;       /* 512 bytes or 4KB */
  88        unsigned int            data_tag_unit_size;     /* DATA TAG UNIT size */
  89        unsigned int            boot_ro_lock;           /* ro lock support */
  90        bool                    boot_ro_lockable;
  91        bool                    ffu_capable;    /* Firmware upgrade support */
  92        bool                    cmdq_en;        /* Command Queue enabled */
  93        bool                    cmdq_support;   /* Command Queue supported */
  94        unsigned int            cmdq_depth;     /* Command Queue depth */
  95#define MMC_FIRMWARE_LEN 8
  96        u8                      fwrev[MMC_FIRMWARE_LEN];  /* FW version */
  97        u8                      raw_exception_status;   /* 54 */
  98        u8                      raw_partition_support;  /* 160 */
  99        u8                      raw_rpmb_size_mult;     /* 168 */
 100        u8                      raw_erased_mem_count;   /* 181 */
 101        u8                      strobe_support;         /* 184 */
 102        u8                      raw_ext_csd_structure;  /* 194 */
 103        u8                      raw_card_type;          /* 196 */
 104        u8                      raw_driver_strength;    /* 197 */
 105        u8                      out_of_int_time;        /* 198 */
 106        u8                      raw_pwr_cl_52_195;      /* 200 */
 107        u8                      raw_pwr_cl_26_195;      /* 201 */
 108        u8                      raw_pwr_cl_52_360;      /* 202 */
 109        u8                      raw_pwr_cl_26_360;      /* 203 */
 110        u8                      raw_s_a_timeout;        /* 217 */
 111        u8                      raw_hc_erase_gap_size;  /* 221 */
 112        u8                      raw_erase_timeout_mult; /* 223 */
 113        u8                      raw_hc_erase_grp_size;  /* 224 */
 114        u8                      raw_sec_trim_mult;      /* 229 */
 115        u8                      raw_sec_erase_mult;     /* 230 */
 116        u8                      raw_sec_feature_support;/* 231 */
 117        u8                      raw_trim_mult;          /* 232 */
 118        u8                      raw_pwr_cl_200_195;     /* 236 */
 119        u8                      raw_pwr_cl_200_360;     /* 237 */
 120        u8                      raw_pwr_cl_ddr_52_195;  /* 238 */
 121        u8                      raw_pwr_cl_ddr_52_360;  /* 239 */
 122        u8                      raw_pwr_cl_ddr_200_360; /* 253 */
 123        u8                      raw_bkops_status;       /* 246 */
 124        u8                      raw_sectors[4];         /* 212 - 4 bytes */
 125        u8                      pre_eol_info;           /* 267 */
 126        u8                      device_life_time_est_typ_a;     /* 268 */
 127        u8                      device_life_time_est_typ_b;     /* 269 */
 128
 129        unsigned int            feature_support;
 130#define MMC_DISCARD_FEATURE     BIT(0)                  /* CMD38 feature */
 131};
 132
 133struct sd_scr {
 134        unsigned char           sda_vsn;
 135        unsigned char           sda_spec3;
 136        unsigned char           sda_spec4;
 137        unsigned char           sda_specx;
 138        unsigned char           bus_widths;
 139#define SD_SCR_BUS_WIDTH_1      (1<<0)
 140#define SD_SCR_BUS_WIDTH_4      (1<<2)
 141        unsigned char           cmds;
 142#define SD_SCR_CMD20_SUPPORT   (1<<0)
 143#define SD_SCR_CMD23_SUPPORT   (1<<1)
 144};
 145
 146struct sd_ssr {
 147        unsigned int            au;                     /* In sectors */
 148        unsigned int            erase_timeout;          /* In milliseconds */
 149        unsigned int            erase_offset;           /* In milliseconds */
 150};
 151
 152struct sd_switch_caps {
 153        unsigned int            hs_max_dtr;
 154        unsigned int            uhs_max_dtr;
 155#define HIGH_SPEED_MAX_DTR      50000000
 156#define UHS_SDR104_MAX_DTR      208000000
 157#define UHS_SDR50_MAX_DTR       100000000
 158#define UHS_DDR50_MAX_DTR       50000000
 159#define UHS_SDR25_MAX_DTR       UHS_DDR50_MAX_DTR
 160#define UHS_SDR12_MAX_DTR       25000000
 161#define DEFAULT_SPEED_MAX_DTR   UHS_SDR12_MAX_DTR
 162        unsigned int            sd3_bus_mode;
 163#define UHS_SDR12_BUS_SPEED     0
 164#define HIGH_SPEED_BUS_SPEED    1
 165#define UHS_SDR25_BUS_SPEED     1
 166#define UHS_SDR50_BUS_SPEED     2
 167#define UHS_SDR104_BUS_SPEED    3
 168#define UHS_DDR50_BUS_SPEED     4
 169
 170#define SD_MODE_HIGH_SPEED      (1 << HIGH_SPEED_BUS_SPEED)
 171#define SD_MODE_UHS_SDR12       (1 << UHS_SDR12_BUS_SPEED)
 172#define SD_MODE_UHS_SDR25       (1 << UHS_SDR25_BUS_SPEED)
 173#define SD_MODE_UHS_SDR50       (1 << UHS_SDR50_BUS_SPEED)
 174#define SD_MODE_UHS_SDR104      (1 << UHS_SDR104_BUS_SPEED)
 175#define SD_MODE_UHS_DDR50       (1 << UHS_DDR50_BUS_SPEED)
 176        unsigned int            sd3_drv_type;
 177#define SD_DRIVER_TYPE_B        0x01
 178#define SD_DRIVER_TYPE_A        0x02
 179#define SD_DRIVER_TYPE_C        0x04
 180#define SD_DRIVER_TYPE_D        0x08
 181        unsigned int            sd3_curr_limit;
 182#define SD_SET_CURRENT_LIMIT_200        0
 183#define SD_SET_CURRENT_LIMIT_400        1
 184#define SD_SET_CURRENT_LIMIT_600        2
 185#define SD_SET_CURRENT_LIMIT_800        3
 186#define SD_SET_CURRENT_NO_CHANGE        (-1)
 187
 188#define SD_MAX_CURRENT_200      (1 << SD_SET_CURRENT_LIMIT_200)
 189#define SD_MAX_CURRENT_400      (1 << SD_SET_CURRENT_LIMIT_400)
 190#define SD_MAX_CURRENT_600      (1 << SD_SET_CURRENT_LIMIT_600)
 191#define SD_MAX_CURRENT_800      (1 << SD_SET_CURRENT_LIMIT_800)
 192};
 193
 194struct sdio_cccr {
 195        unsigned int            sdio_vsn;
 196        unsigned int            sd_vsn;
 197        unsigned int            multi_block:1,
 198                                low_speed:1,
 199                                wide_bus:1,
 200                                high_power:1,
 201                                high_speed:1,
 202                                disable_cd:1;
 203};
 204
 205struct sdio_cis {
 206        unsigned short          vendor;
 207        unsigned short          device;
 208        unsigned short          blksize;
 209        unsigned int            max_dtr;
 210};
 211
 212struct mmc_host;
 213struct sdio_func;
 214struct sdio_func_tuple;
 215struct mmc_queue_req;
 216
 217#define SDIO_MAX_FUNCS          7
 218
 219/* The number of MMC physical partitions.  These consist of:
 220 * boot partitions (2), general purpose partitions (4) and
 221 * RPMB partition (1) in MMC v4.4.
 222 */
 223#define MMC_NUM_BOOT_PARTITION  2
 224#define MMC_NUM_GP_PARTITION    4
 225#define MMC_NUM_PHY_PARTITION   7
 226#define MAX_MMC_PART_NAME_LEN   20
 227
 228/*
 229 * MMC Physical partitions
 230 */
 231struct mmc_part {
 232        unsigned int    size;   /* partition size (in bytes) */
 233        unsigned int    part_cfg;       /* partition type */
 234        char    name[MAX_MMC_PART_NAME_LEN];
 235        bool    force_ro;       /* to make boot parts RO by default */
 236        unsigned int    area_type;
 237#define MMC_BLK_DATA_AREA_MAIN  (1<<0)
 238#define MMC_BLK_DATA_AREA_BOOT  (1<<1)
 239#define MMC_BLK_DATA_AREA_GP    (1<<2)
 240#define MMC_BLK_DATA_AREA_RPMB  (1<<3)
 241};
 242
 243/*
 244 * MMC device
 245 */
 246struct mmc_card {
 247        struct mmc_host         *host;          /* the host this device belongs to */
 248        struct device           dev;            /* the device */
 249        u32                     ocr;            /* the current OCR setting */
 250        unsigned int            rca;            /* relative card address of device */
 251        unsigned int            type;           /* card type */
 252#define MMC_TYPE_MMC            0               /* MMC card */
 253#define MMC_TYPE_SD             1               /* SD card */
 254#define MMC_TYPE_SDIO           2               /* SDIO card */
 255#define MMC_TYPE_SD_COMBO       3               /* SD combo (IO+mem) card */
 256        unsigned int            state;          /* (our) card state */
 257        unsigned int            quirks;         /* card quirks */
 258        unsigned int            quirk_max_rate; /* max rate set by quirks */
 259#define MMC_QUIRK_LENIENT_FN0   (1<<0)          /* allow SDIO FN0 writes outside of the VS CCCR range */
 260#define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)    /* use func->cur_blksize */
 261                                                /* for byte mode */
 262#define MMC_QUIRK_NONSTD_SDIO   (1<<2)          /* non-standard SDIO card attached */
 263                                                /* (missing CIA registers) */
 264#define MMC_QUIRK_NONSTD_FUNC_IF (1<<4)         /* SDIO card has nonstd function interfaces */
 265#define MMC_QUIRK_DISABLE_CD    (1<<5)          /* disconnect CD/DAT[3] resistor */
 266#define MMC_QUIRK_INAND_CMD38   (1<<6)          /* iNAND devices have broken CMD38 */
 267#define MMC_QUIRK_BLK_NO_CMD23  (1<<7)          /* Avoid CMD23 for regular multiblock */
 268#define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8)   /* Avoid sending 512 bytes in */
 269                                                /* byte mode */
 270#define MMC_QUIRK_LONG_READ_TIME (1<<9)         /* Data read time > CSD says */
 271#define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */
 272#define MMC_QUIRK_BROKEN_IRQ_POLLING    (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */
 273#define MMC_QUIRK_TRIM_BROKEN   (1<<12)         /* Skip trim */
 274#define MMC_QUIRK_BROKEN_HPI    (1<<13)         /* Disable broken HPI support */
 275
 276        bool                    reenable_cmdq;  /* Re-enable Command Queue */
 277
 278        unsigned int            erase_size;     /* erase size in sectors */
 279        unsigned int            erase_shift;    /* if erase unit is power 2 */
 280        unsigned int            pref_erase;     /* in sectors */
 281        unsigned int            eg_boundary;    /* don't cross erase-group boundaries */
 282        unsigned int            erase_arg;      /* erase / trim / discard */
 283        u8                      erased_byte;    /* value of erased bytes */
 284
 285        u32                     raw_cid[4];     /* raw card CID */
 286        u32                     raw_csd[4];     /* raw card CSD */
 287        u32                     raw_scr[2];     /* raw card SCR */
 288        u32                     raw_ssr[16];    /* raw card SSR */
 289        struct mmc_cid          cid;            /* card identification */
 290        struct mmc_csd          csd;            /* card specific */
 291        struct mmc_ext_csd      ext_csd;        /* mmc v4 extended card specific */
 292        struct sd_scr           scr;            /* extra SD information */
 293        struct sd_ssr           ssr;            /* yet more SD information */
 294        struct sd_switch_caps   sw_caps;        /* switch (CMD6) caps */
 295
 296        unsigned int            sdio_funcs;     /* number of SDIO functions */
 297        struct sdio_cccr        cccr;           /* common card info */
 298        struct sdio_cis         cis;            /* common tuple info */
 299        struct sdio_func        *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
 300        struct sdio_func        *sdio_single_irq; /* SDIO function when only one IRQ active */
 301        unsigned                num_info;       /* number of info strings */
 302        const char              **info;         /* info strings */
 303        struct sdio_func_tuple  *tuples;        /* unknown common tuples */
 304
 305        unsigned int            sd_bus_speed;   /* Bus Speed Mode set for the card */
 306        unsigned int            mmc_avail_type; /* supported device type by both host and card */
 307        unsigned int            drive_strength; /* for UHS-I, HS200 or HS400 */
 308
 309        struct dentry           *debugfs_root;
 310        struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */
 311        unsigned int    nr_parts;
 312
 313        unsigned int            bouncesz;       /* Bounce buffer size */
 314        struct workqueue_struct *complete_wq;   /* Private workqueue */
 315};
 316
 317static inline bool mmc_large_sector(struct mmc_card *card)
 318{
 319        return card->ext_csd.data_sector_size == 4096;
 320}
 321
 322bool mmc_card_is_blockaddr(struct mmc_card *card);
 323
 324#define mmc_card_mmc(c)         ((c)->type == MMC_TYPE_MMC)
 325#define mmc_card_sd(c)          ((c)->type == MMC_TYPE_SD)
 326#define mmc_card_sdio(c)        ((c)->type == MMC_TYPE_SDIO)
 327
 328#endif /* LINUX_MMC_CARD_H */
 329