card.h 12 KB

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