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/mmc/core.h>
14 #include <linux/mod_devicetable.h>
28 unsigned char structure
;
29 unsigned char mmca_vsn
;
30 unsigned short cmdclass
;
31 unsigned short tacc_clks
;
34 unsigned int r2w_factor
;
36 unsigned int erase_size
; /* In sectors */
37 unsigned int read_blkbits
;
38 unsigned int write_blkbits
;
39 unsigned int capacity
;
40 unsigned int read_partial
:1,
49 u8 sec_feature_support
;
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 unsigned int hs_max_dtr
;
61 unsigned int card_type
;
62 unsigned int hc_erase_size
; /* In sectors */
63 unsigned int hc_erase_timeout
; /* In milliseconds */
64 unsigned int sec_trim_mult
; /* Secure trim multiplier */
65 unsigned int sec_erase_mult
; /* Secure erase multiplier */
66 unsigned int trim_timeout
; /* In milliseconds */
67 bool enhanced_area_en
; /* enable bit */
68 unsigned long long enhanced_area_offset
; /* Units: Byte */
69 unsigned int enhanced_area_size
; /* Units: KB */
70 unsigned int cache_size
; /* Units: KB */
71 bool hpi_en
; /* HPI enablebit */
72 bool hpi
; /* HPI support bit */
73 unsigned int hpi_cmd
; /* cmd used as HPI */
74 unsigned int data_sector_size
; /* 512 bytes or 4KB */
75 unsigned int data_tag_unit_size
; /* DATA TAG UNIT size */
76 unsigned int boot_ro_lock
; /* ro lock support */
77 bool boot_ro_lockable
;
78 u8 raw_partition_support
; /* 160 */
79 u8 raw_erased_mem_count
; /* 181 */
80 u8 raw_ext_csd_structure
; /* 194 */
81 u8 raw_card_type
; /* 196 */
82 u8 out_of_int_time
; /* 198 */
83 u8 raw_s_a_timeout
; /* 217 */
84 u8 raw_hc_erase_gap_size
; /* 221 */
85 u8 raw_erase_timeout_mult
; /* 223 */
86 u8 raw_hc_erase_grp_size
; /* 224 */
87 u8 raw_sec_trim_mult
; /* 229 */
88 u8 raw_sec_erase_mult
; /* 230 */
89 u8 raw_sec_feature_support
;/* 231 */
90 u8 raw_trim_mult
; /* 232 */
91 u8 raw_sectors
[4]; /* 212 - 4 bytes */
93 unsigned int feature_support
;
94 #define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */
98 unsigned char sda_vsn
;
99 unsigned char sda_spec3
;
100 unsigned char bus_widths
;
101 #define SD_SCR_BUS_WIDTH_1 (1<<0)
102 #define SD_SCR_BUS_WIDTH_4 (1<<2)
104 #define SD_SCR_CMD20_SUPPORT (1<<0)
105 #define SD_SCR_CMD23_SUPPORT (1<<1)
109 unsigned int au
; /* In sectors */
110 unsigned int erase_timeout
; /* In milliseconds */
111 unsigned int erase_offset
; /* In milliseconds */
114 struct sd_switch_caps
{
115 unsigned int hs_max_dtr
;
116 unsigned int uhs_max_dtr
;
117 #define HIGH_SPEED_MAX_DTR 50000000
118 #define UHS_SDR104_MAX_DTR 208000000
119 #define UHS_SDR50_MAX_DTR 100000000
120 #define UHS_DDR50_MAX_DTR 50000000
121 #define UHS_SDR25_MAX_DTR UHS_DDR50_MAX_DTR
122 #define UHS_SDR12_MAX_DTR 25000000
123 unsigned int sd3_bus_mode
;
124 #define UHS_SDR12_BUS_SPEED 0
125 #define HIGH_SPEED_BUS_SPEED 1
126 #define UHS_SDR25_BUS_SPEED 1
127 #define UHS_SDR50_BUS_SPEED 2
128 #define UHS_SDR104_BUS_SPEED 3
129 #define UHS_DDR50_BUS_SPEED 4
131 #define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED)
132 #define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED)
133 #define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED)
134 #define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED)
135 #define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED)
136 #define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED)
137 unsigned int sd3_drv_type
;
138 #define SD_DRIVER_TYPE_B 0x01
139 #define SD_DRIVER_TYPE_A 0x02
140 #define SD_DRIVER_TYPE_C 0x04
141 #define SD_DRIVER_TYPE_D 0x08
142 unsigned int sd3_curr_limit
;
143 #define SD_SET_CURRENT_LIMIT_200 0
144 #define SD_SET_CURRENT_LIMIT_400 1
145 #define SD_SET_CURRENT_LIMIT_600 2
146 #define SD_SET_CURRENT_LIMIT_800 3
148 #define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200)
149 #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400)
150 #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600)
151 #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800)
155 unsigned int sdio_vsn
;
157 unsigned int multi_block
:1,
166 unsigned short vendor
;
167 unsigned short device
;
168 unsigned short blksize
;
169 unsigned int max_dtr
;
174 struct sdio_func_tuple
;
176 #define SDIO_MAX_FUNCS 7
178 /* The number of MMC physical partitions. These consist of:
179 * boot partitions (2), general purpose partitions (4) in MMC v4.4.
181 #define MMC_NUM_BOOT_PARTITION 2
182 #define MMC_NUM_GP_PARTITION 4
183 #define MMC_NUM_PHY_PARTITION 6
184 #define MAX_MMC_PART_NAME_LEN 20
187 * MMC Physical partitions
190 unsigned int size
; /* partition size (in bytes) */
191 unsigned int part_cfg
; /* partition type */
192 char name
[MAX_MMC_PART_NAME_LEN
];
193 bool force_ro
; /* to make boot parts RO by default */
194 unsigned int area_type
;
195 #define MMC_BLK_DATA_AREA_MAIN (1<<0)
196 #define MMC_BLK_DATA_AREA_BOOT (1<<1)
197 #define MMC_BLK_DATA_AREA_GP (1<<2)
204 struct mmc_host
*host
; /* the host this device belongs to */
205 struct device dev
; /* the device */
206 unsigned int rca
; /* relative card address of device */
207 unsigned int type
; /* card type */
208 #define MMC_TYPE_MMC 0 /* MMC card */
209 #define MMC_TYPE_SD 1 /* SD card */
210 #define MMC_TYPE_SDIO 2 /* SDIO card */
211 #define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */
212 unsigned int state
; /* (our) card state */
213 #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
214 #define MMC_STATE_READONLY (1<<1) /* card is read-only */
215 #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
216 #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */
217 #define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */
218 #define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */
219 #define MMC_CARD_SDXC (1<<6) /* card is SDXC */
220 #define MMC_CARD_REMOVED (1<<7) /* card has been removed */
221 #define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */
222 #define MMC_STATE_SLEEP (1<<9) /* card is in sleep state */
223 unsigned int quirks
; /* card quirks */
224 #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
225 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
227 #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
228 /* (missing CIA registers) */
229 #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */
230 #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4) /* SDIO card has nonstd function interfaces */
231 #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */
232 #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */
233 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */
234 #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */
235 #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */
237 unsigned int poweroff_notify_state
; /* eMMC4.5 notify feature */
238 #define MMC_NO_POWER_NOTIFICATION 0
239 #define MMC_POWERED_ON 1
240 #define MMC_POWEROFF_SHORT 2
241 #define MMC_POWEROFF_LONG 3
243 unsigned int erase_size
; /* erase size in sectors */
244 unsigned int erase_shift
; /* if erase unit is power 2 */
245 unsigned int pref_erase
; /* in sectors */
246 u8 erased_byte
; /* value of erased bytes */
248 u32 raw_cid
[4]; /* raw card CID */
249 u32 raw_csd
[4]; /* raw card CSD */
250 u32 raw_scr
[2]; /* raw card SCR */
251 struct mmc_cid cid
; /* card identification */
252 struct mmc_csd csd
; /* card specific */
253 struct mmc_ext_csd ext_csd
; /* mmc v4 extended card specific */
254 struct sd_scr scr
; /* extra SD information */
255 struct sd_ssr ssr
; /* yet more SD information */
256 struct sd_switch_caps sw_caps
; /* switch (CMD6) caps */
258 unsigned int sdio_funcs
; /* number of SDIO functions */
259 struct sdio_cccr cccr
; /* common card info */
260 struct sdio_cis cis
; /* common tuple info */
261 struct sdio_func
*sdio_func
[SDIO_MAX_FUNCS
]; /* SDIO functions (devices) */
262 struct sdio_func
*sdio_single_irq
; /* SDIO function when only one IRQ active */
263 unsigned num_info
; /* number of info strings */
264 const char **info
; /* info strings */
265 struct sdio_func_tuple
*tuples
; /* unknown common tuples */
267 unsigned int sd_bus_speed
; /* Bus Speed Mode set for the card */
269 struct dentry
*debugfs_root
;
270 struct mmc_part part
[MMC_NUM_PHY_PARTITION
]; /* physical partitions */
271 unsigned int nr_parts
;
275 * This function fill contents in mmc_part.
277 static inline void mmc_part_add(struct mmc_card
*card
, unsigned int size
,
278 unsigned int part_cfg
, char *name
, int idx
, bool ro
,
281 card
->part
[card
->nr_parts
].size
= size
;
282 card
->part
[card
->nr_parts
].part_cfg
= part_cfg
;
283 sprintf(card
->part
[card
->nr_parts
].name
, name
, idx
);
284 card
->part
[card
->nr_parts
].force_ro
= ro
;
285 card
->part
[card
->nr_parts
].area_type
= area_type
;
290 * The world is not perfect and supplies us with broken mmc/sdio devices.
291 * For at least some of these bugs we need a work-around.
295 /* CID-specific fields. */
298 /* Valid revision range */
299 u64 rev_start
, rev_end
;
302 unsigned short oemid
;
304 /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
305 u16 cis_vendor
, cis_device
;
307 void (*vendor_fixup
)(struct mmc_card
*card
, int data
);
311 #define CID_MANFID_ANY (-1u)
312 #define CID_OEMID_ANY ((unsigned short) -1)
313 #define CID_NAME_ANY (NULL)
315 #define END_FIXUP { 0 }
317 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \
318 _cis_vendor, _cis_device, \
322 .manfid = (_manfid), \
324 .rev_start = (_rev_start), \
325 .rev_end = (_rev_end), \
326 .cis_vendor = (_cis_vendor), \
327 .cis_device = (_cis_device), \
328 .vendor_fixup = (_fixup), \
332 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \
334 _FIXUP_EXT(_name, _manfid, \
335 _oemid, _rev_start, _rev_end, \
336 SDIO_ANY_ID, SDIO_ANY_ID, \
339 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
340 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
342 #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \
343 _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \
344 CID_OEMID_ANY, 0, -1ull, \
348 #define cid_rev(hwrev, fwrev, year, month) \
349 (((u64) hwrev) << 40 | \
350 ((u64) fwrev) << 32 | \
351 ((u64) year) << 16 | \
354 #define cid_rev_card(card) \
355 cid_rev(card->cid.hwrev, \
361 * Unconditionally quirk add/remove.
364 static inline void __maybe_unused
add_quirk(struct mmc_card
*card
, int data
)
366 card
->quirks
|= data
;
369 static inline void __maybe_unused
remove_quirk(struct mmc_card
*card
, int data
)
371 card
->quirks
&= ~data
;
374 #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
375 #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
376 #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
378 #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
379 #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
380 #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED)
381 #define mmc_card_hs200(c) ((c)->state & MMC_STATE_HIGHSPEED_200)
382 #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
383 #define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
384 #define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
385 #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
386 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
387 #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED))
388 #define mmc_card_is_sleep(c) ((c)->state & MMC_STATE_SLEEP)
390 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
391 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
392 #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
393 #define mmc_card_set_hs200(c) ((c)->state |= MMC_STATE_HIGHSPEED_200)
394 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
395 #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
396 #define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
397 #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
398 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
399 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
400 #define mmc_card_set_sleep(c) ((c)->state |= MMC_STATE_SLEEP)
402 #define mmc_card_clr_sleep(c) ((c)->state &= ~MMC_STATE_SLEEP)
404 * Quirk add/remove for MMC products.
407 static inline void __maybe_unused
add_quirk_mmc(struct mmc_card
*card
, int data
)
409 if (mmc_card_mmc(card
))
410 card
->quirks
|= data
;
413 static inline void __maybe_unused
remove_quirk_mmc(struct mmc_card
*card
,
416 if (mmc_card_mmc(card
))
417 card
->quirks
&= ~data
;
421 * Quirk add/remove for SD products.
424 static inline void __maybe_unused
add_quirk_sd(struct mmc_card
*card
, int data
)
426 if (mmc_card_sd(card
))
427 card
->quirks
|= data
;
430 static inline void __maybe_unused
remove_quirk_sd(struct mmc_card
*card
,
433 if (mmc_card_sd(card
))
434 card
->quirks
&= ~data
;
437 static inline int mmc_card_lenient_fn0(const struct mmc_card
*c
)
439 return c
->quirks
& MMC_QUIRK_LENIENT_FN0
;
442 static inline int mmc_blksz_for_byte_mode(const struct mmc_card
*c
)
444 return c
->quirks
& MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
447 static inline int mmc_card_disable_cd(const struct mmc_card
*c
)
449 return c
->quirks
& MMC_QUIRK_DISABLE_CD
;
452 static inline int mmc_card_nonstd_func_interface(const struct mmc_card
*c
)
454 return c
->quirks
& MMC_QUIRK_NONSTD_FUNC_IF
;
457 static inline int mmc_card_broken_byte_mode_512(const struct mmc_card
*c
)
459 return c
->quirks
& MMC_QUIRK_BROKEN_BYTE_MODE_512
;
462 static inline int mmc_card_long_read_time(const struct mmc_card
*c
)
464 return c
->quirks
& MMC_QUIRK_LONG_READ_TIME
;
467 #define mmc_card_name(c) ((c)->cid.prod_name)
468 #define mmc_card_id(c) (dev_name(&(c)->dev))
470 #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
472 #define mmc_list_to_card(l) container_of(l, struct mmc_card, node)
473 #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev)
474 #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d)
477 * MMC device driver (e.g., Flash card, I/O card...)
480 struct device_driver drv
;
481 int (*probe
)(struct mmc_card
*);
482 void (*remove
)(struct mmc_card
*);
483 int (*suspend
)(struct mmc_card
*, pm_message_t
);
484 int (*resume
)(struct mmc_card
*);
487 extern int mmc_register_driver(struct mmc_driver
*);
488 extern void mmc_unregister_driver(struct mmc_driver
*);
490 extern void mmc_fixup_device(struct mmc_card
*card
,
491 const struct mmc_fixup
*table
);
493 #endif /* LINUX_MMC_CARD_H */