card.h 11 KB

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