2 * linux/include/linux/mmc/card.h
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.
8 * Card driver specific definitions.
10 #ifndef LINUX_MMC_CARD_H
11 #define LINUX_MMC_CARD_H
13 #include <linux/device.h>
14 #include <linux/mmc/core.h>
15 #include <linux/mod_devicetable.h>
30 unsigned char structure
;
31 unsigned char mmca_vsn
;
32 unsigned short cmdclass
;
33 unsigned short tacc_clks
;
36 unsigned int r2w_factor
;
38 unsigned int erase_size
; /* In sectors */
39 unsigned int read_blkbits
;
40 unsigned int write_blkbits
;
41 unsigned int capacity
;
42 unsigned int read_partial
:1,
52 u8 sec_feature_support
;
61 unsigned int part_time
; /* Units: ms */
62 unsigned int sa_timeout
; /* Units: 100ns */
63 unsigned int generic_cmd6_time
; /* Units: 10ms */
64 unsigned int power_off_longtime
; /* Units: ms */
65 u8 power_off_notification
; /* state */
66 unsigned int hs_max_dtr
;
67 unsigned int hs200_max_dtr
;
68 #define MMC_HIGH_26_MAX_DTR 26000000
69 #define MMC_HIGH_52_MAX_DTR 52000000
70 #define MMC_HIGH_DDR_MAX_DTR 52000000
71 #define MMC_HS200_MAX_DTR 200000000
73 unsigned int hc_erase_size
; /* In sectors */
74 unsigned int hc_erase_timeout
; /* In milliseconds */
75 unsigned int sec_trim_mult
; /* Secure trim multiplier */
76 unsigned int sec_erase_mult
; /* Secure erase multiplier */
77 unsigned int trim_timeout
; /* In milliseconds */
78 bool partition_setting_completed
; /* enable bit */
79 unsigned long long enhanced_area_offset
; /* Units: Byte */
80 unsigned int enhanced_area_size
; /* Units: KB */
81 unsigned int cache_size
; /* Units: KB */
82 bool hpi_en
; /* HPI enablebit */
83 bool hpi
; /* HPI support bit */
84 unsigned int hpi_cmd
; /* cmd used as HPI */
85 bool bkops
; /* background support bit */
86 bool man_bkops_en
; /* manual 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 #define MMC_FIRMWARE_LEN 8
93 u8 fwrev
[MMC_FIRMWARE_LEN
]; /* FW version */
94 u8 raw_exception_status
; /* 54 */
95 u8 raw_partition_support
; /* 160 */
96 u8 raw_rpmb_size_mult
; /* 168 */
97 u8 raw_erased_mem_count
; /* 181 */
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 */
122 unsigned int feature_support
;
123 #define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */
127 unsigned char sda_vsn
;
128 unsigned char sda_spec3
;
129 unsigned char bus_widths
;
130 #define SD_SCR_BUS_WIDTH_1 (1<<0)
131 #define SD_SCR_BUS_WIDTH_4 (1<<2)
133 #define SD_SCR_CMD20_SUPPORT (1<<0)
134 #define SD_SCR_CMD23_SUPPORT (1<<1)
138 unsigned int au
; /* In sectors */
139 unsigned int erase_timeout
; /* In milliseconds */
140 unsigned int erase_offset
; /* In milliseconds */
143 struct sd_switch_caps
{
144 unsigned int hs_max_dtr
;
145 unsigned int uhs_max_dtr
;
146 #define HIGH_SPEED_MAX_DTR 50000000
147 #define UHS_SDR104_MAX_DTR 208000000
148 #define UHS_SDR50_MAX_DTR 100000000
149 #define UHS_DDR50_MAX_DTR 50000000
150 #define UHS_SDR25_MAX_DTR UHS_DDR50_MAX_DTR
151 #define UHS_SDR12_MAX_DTR 25000000
152 unsigned int sd3_bus_mode
;
153 #define UHS_SDR12_BUS_SPEED 0
154 #define HIGH_SPEED_BUS_SPEED 1
155 #define UHS_SDR25_BUS_SPEED 1
156 #define UHS_SDR50_BUS_SPEED 2
157 #define UHS_SDR104_BUS_SPEED 3
158 #define UHS_DDR50_BUS_SPEED 4
160 #define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED)
161 #define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED)
162 #define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED)
163 #define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED)
164 #define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED)
165 #define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED)
166 unsigned int sd3_drv_type
;
167 #define SD_DRIVER_TYPE_B 0x01
168 #define SD_DRIVER_TYPE_A 0x02
169 #define SD_DRIVER_TYPE_C 0x04
170 #define SD_DRIVER_TYPE_D 0x08
171 unsigned int sd3_curr_limit
;
172 #define SD_SET_CURRENT_LIMIT_200 0
173 #define SD_SET_CURRENT_LIMIT_400 1
174 #define SD_SET_CURRENT_LIMIT_600 2
175 #define SD_SET_CURRENT_LIMIT_800 3
176 #define SD_SET_CURRENT_NO_CHANGE (-1)
178 #define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200)
179 #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400)
180 #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600)
181 #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800)
185 unsigned int sdio_vsn
;
187 unsigned int multi_block
:1,
196 unsigned short vendor
;
197 unsigned short device
;
198 unsigned short blksize
;
199 unsigned int max_dtr
;
205 struct sdio_func_tuple
;
207 #define SDIO_MAX_FUNCS 7
209 enum mmc_blk_status
{
221 /* The number of MMC physical partitions. These consist of:
222 * boot partitions (2), general purpose partitions (4) and
223 * RPMB partition (1) in MMC v4.4.
225 #define MMC_NUM_BOOT_PARTITION 2
226 #define MMC_NUM_GP_PARTITION 4
227 #define MMC_NUM_PHY_PARTITION 7
228 #define MAX_MMC_PART_NAME_LEN 20
231 * MMC Physical partitions
234 unsigned int size
; /* partition size (in bytes) */
235 unsigned int part_cfg
; /* partition type */
236 char name
[MAX_MMC_PART_NAME_LEN
];
237 bool force_ro
; /* to make boot parts RO by default */
238 unsigned int area_type
;
239 #define MMC_BLK_DATA_AREA_MAIN (1<<0)
240 #define MMC_BLK_DATA_AREA_BOOT (1<<1)
241 #define MMC_BLK_DATA_AREA_GP (1<<2)
242 #define MMC_BLK_DATA_AREA_RPMB (1<<3)
249 struct mmc_host
*host
; /* the host this device belongs to */
250 struct device dev
; /* the device */
251 u32 ocr
; /* the current OCR setting */
252 unsigned int rca
; /* relative card address of device */
253 unsigned int type
; /* card type */
254 #define MMC_TYPE_MMC 0 /* MMC card */
255 #define MMC_TYPE_SD 1 /* SD card */
256 #define MMC_TYPE_SDIO 2 /* SDIO card */
257 #define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */
258 unsigned int state
; /* (our) card state */
259 #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
260 #define MMC_STATE_READONLY (1<<1) /* card is read-only */
261 #define MMC_STATE_BLOCKADDR (1<<2) /* card uses block-addressing */
262 #define MMC_CARD_SDXC (1<<3) /* card is SDXC */
263 #define MMC_CARD_REMOVED (1<<4) /* card has been removed */
264 #define MMC_STATE_DOING_BKOPS (1<<5) /* card is doing BKOPS */
265 #define MMC_STATE_SUSPENDED (1<<6) /* card is suspended */
266 unsigned int quirks
; /* card quirks */
267 #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
268 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
270 #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
271 /* (missing CIA registers) */
272 #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4) /* SDIO card has nonstd function interfaces */
273 #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */
274 #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */
275 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */
276 #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */
278 #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */
279 #define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */
280 #define MMC_QUIRK_BROKEN_IRQ_POLLING (1<<11) /* Polling SDIO_CCCR_INTx could create a fake interrupt */
281 #define MMC_QUIRK_TRIM_BROKEN (1<<12) /* Skip trim */
284 unsigned int erase_size
; /* erase size in sectors */
285 unsigned int erase_shift
; /* if erase unit is power 2 */
286 unsigned int pref_erase
; /* in sectors */
287 unsigned int eg_boundary
; /* don't cross erase-group boundaries */
288 u8 erased_byte
; /* value of erased bytes */
290 u32 raw_cid
[4]; /* raw card CID */
291 u32 raw_csd
[4]; /* raw card CSD */
292 u32 raw_scr
[2]; /* raw card SCR */
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 */
300 unsigned int sdio_funcs
; /* number of SDIO functions */
301 struct sdio_cccr cccr
; /* common card info */
302 struct sdio_cis cis
; /* common tuple info */
303 struct sdio_func
*sdio_func
[SDIO_MAX_FUNCS
]; /* SDIO functions (devices) */
304 struct sdio_func
*sdio_single_irq
; /* SDIO function when only one IRQ active */
305 unsigned num_info
; /* number of info strings */
306 const char **info
; /* info strings */
307 struct sdio_func_tuple
*tuples
; /* unknown common tuples */
309 unsigned int sd_bus_speed
; /* Bus Speed Mode set for the card */
310 unsigned int mmc_avail_type
; /* supported device type by both host and card */
311 unsigned int drive_strength
; /* for UHS-I, HS200 or HS400 */
313 struct dentry
*debugfs_root
;
314 struct mmc_part part
[MMC_NUM_PHY_PARTITION
]; /* physical partitions */
315 unsigned int nr_parts
;
319 * This function fill contents in mmc_part.
321 static inline void mmc_part_add(struct mmc_card
*card
, unsigned int size
,
322 unsigned int part_cfg
, char *name
, int idx
, bool ro
,
325 card
->part
[card
->nr_parts
].size
= size
;
326 card
->part
[card
->nr_parts
].part_cfg
= part_cfg
;
327 sprintf(card
->part
[card
->nr_parts
].name
, name
, idx
);
328 card
->part
[card
->nr_parts
].force_ro
= ro
;
329 card
->part
[card
->nr_parts
].area_type
= area_type
;
333 static inline bool mmc_large_sector(struct mmc_card
*card
)
335 return card
->ext_csd
.data_sector_size
== 4096;
339 * The world is not perfect and supplies us with broken mmc/sdio devices.
340 * For at least some of these bugs we need a work-around.
344 /* CID-specific fields. */
347 /* Valid revision range */
348 u64 rev_start
, rev_end
;
351 unsigned short oemid
;
353 /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
354 u16 cis_vendor
, cis_device
;
356 void (*vendor_fixup
)(struct mmc_card
*card
, int data
);
360 #define CID_MANFID_ANY (-1u)
361 #define CID_OEMID_ANY ((unsigned short) -1)
362 #define CID_NAME_ANY (NULL)
364 #define END_FIXUP { NULL }
366 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \
367 _cis_vendor, _cis_device, \
371 .manfid = (_manfid), \
373 .rev_start = (_rev_start), \
374 .rev_end = (_rev_end), \
375 .cis_vendor = (_cis_vendor), \
376 .cis_device = (_cis_device), \
377 .vendor_fixup = (_fixup), \
381 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \
383 _FIXUP_EXT(_name, _manfid, \
384 _oemid, _rev_start, _rev_end, \
385 SDIO_ANY_ID, SDIO_ANY_ID, \
388 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
389 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
391 #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \
392 _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \
393 CID_OEMID_ANY, 0, -1ull, \
397 #define cid_rev(hwrev, fwrev, year, month) \
398 (((u64) hwrev) << 40 | \
399 ((u64) fwrev) << 32 | \
400 ((u64) year) << 16 | \
403 #define cid_rev_card(card) \
404 cid_rev(card->cid.hwrev, \
410 * Unconditionally quirk add/remove.
413 static inline void __maybe_unused
add_quirk(struct mmc_card
*card
, int data
)
415 card
->quirks
|= data
;
418 static inline void __maybe_unused
remove_quirk(struct mmc_card
*card
, int data
)
420 card
->quirks
&= ~data
;
423 #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
424 #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
425 #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
427 #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
428 #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
429 #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
430 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
431 #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
432 #define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS)
433 #define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED)
435 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
436 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
437 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
438 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
439 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
440 #define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS)
441 #define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS)
442 #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
443 #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
446 * Quirk add/remove for MMC products.
449 static inline void __maybe_unused
add_quirk_mmc(struct mmc_card
*card
, int data
)
451 if (mmc_card_mmc(card
))
452 card
->quirks
|= data
;
455 static inline void __maybe_unused
remove_quirk_mmc(struct mmc_card
*card
,
458 if (mmc_card_mmc(card
))
459 card
->quirks
&= ~data
;
463 * Quirk add/remove for SD products.
466 static inline void __maybe_unused
add_quirk_sd(struct mmc_card
*card
, int data
)
468 if (mmc_card_sd(card
))
469 card
->quirks
|= data
;
472 static inline void __maybe_unused
remove_quirk_sd(struct mmc_card
*card
,
475 if (mmc_card_sd(card
))
476 card
->quirks
&= ~data
;
479 static inline int mmc_card_lenient_fn0(const struct mmc_card
*c
)
481 return c
->quirks
& MMC_QUIRK_LENIENT_FN0
;
484 static inline int mmc_blksz_for_byte_mode(const struct mmc_card
*c
)
486 return c
->quirks
& MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
489 static inline int mmc_card_disable_cd(const struct mmc_card
*c
)
491 return c
->quirks
& MMC_QUIRK_DISABLE_CD
;
494 static inline int mmc_card_nonstd_func_interface(const struct mmc_card
*c
)
496 return c
->quirks
& MMC_QUIRK_NONSTD_FUNC_IF
;
499 static inline int mmc_card_broken_byte_mode_512(const struct mmc_card
*c
)
501 return c
->quirks
& MMC_QUIRK_BROKEN_BYTE_MODE_512
;
504 static inline int mmc_card_long_read_time(const struct mmc_card
*c
)
506 return c
->quirks
& MMC_QUIRK_LONG_READ_TIME
;
509 static inline int mmc_card_broken_irq_polling(const struct mmc_card
*c
)
511 return c
->quirks
& MMC_QUIRK_BROKEN_IRQ_POLLING
;
514 #define mmc_card_name(c) ((c)->cid.prod_name)
515 #define mmc_card_id(c) (dev_name(&(c)->dev))
517 #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
520 * MMC device driver (e.g., Flash card, I/O card...)
523 struct device_driver drv
;
524 int (*probe
)(struct mmc_card
*);
525 void (*remove
)(struct mmc_card
*);
526 void (*shutdown
)(struct mmc_card
*);
529 extern int mmc_register_driver(struct mmc_driver
*);
530 extern void mmc_unregister_driver(struct mmc_driver
*);
532 extern void mmc_fixup_device(struct mmc_card
*card
,
533 const struct mmc_fixup
*table
);
535 #endif /* LINUX_MMC_CARD_H */