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
;
53 unsigned int part_time
; /* Units: ms */
54 unsigned int sa_timeout
; /* Units: 100ns */
55 unsigned int hs_max_dtr
;
57 unsigned int card_type
;
58 unsigned int hc_erase_size
; /* In sectors */
59 unsigned int hc_erase_timeout
; /* In milliseconds */
60 unsigned int sec_trim_mult
; /* Secure trim multiplier */
61 unsigned int sec_erase_mult
; /* Secure erase multiplier */
62 unsigned int trim_timeout
; /* In milliseconds */
63 bool enhanced_area_en
; /* enable bit */
64 unsigned long long enhanced_area_offset
; /* Units: Byte */
65 unsigned int enhanced_area_size
; /* Units: KB */
66 unsigned int boot_size
; /* in bytes */
70 unsigned char sda_vsn
;
71 unsigned char sda_spec3
;
72 unsigned char bus_widths
;
73 #define SD_SCR_BUS_WIDTH_1 (1<<0)
74 #define SD_SCR_BUS_WIDTH_4 (1<<2)
76 #define SD_SCR_CMD20_SUPPORT (1<<0)
77 #define SD_SCR_CMD23_SUPPORT (1<<1)
81 unsigned int au
; /* In sectors */
82 unsigned int erase_timeout
; /* In milliseconds */
83 unsigned int erase_offset
; /* In milliseconds */
86 struct sd_switch_caps
{
87 unsigned int hs_max_dtr
;
88 unsigned int uhs_max_dtr
;
89 #define UHS_SDR104_MAX_DTR 208000000
90 #define UHS_SDR50_MAX_DTR 100000000
91 #define UHS_DDR50_MAX_DTR 50000000
92 #define UHS_SDR25_MAX_DTR UHS_DDR50_MAX_DTR
93 #define UHS_SDR12_MAX_DTR 25000000
94 unsigned int sd3_bus_mode
;
95 #define UHS_SDR12_BUS_SPEED 0
96 #define UHS_SDR25_BUS_SPEED 1
97 #define UHS_SDR50_BUS_SPEED 2
98 #define UHS_SDR104_BUS_SPEED 3
99 #define UHS_DDR50_BUS_SPEED 4
101 #define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED)
102 #define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED)
103 #define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED)
104 #define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED)
105 #define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED)
106 unsigned int sd3_drv_type
;
107 #define SD_DRIVER_TYPE_B 0x01
108 #define SD_DRIVER_TYPE_A 0x02
109 #define SD_DRIVER_TYPE_C 0x04
110 #define SD_DRIVER_TYPE_D 0x08
111 unsigned int sd3_curr_limit
;
112 #define SD_SET_CURRENT_LIMIT_200 0
113 #define SD_SET_CURRENT_LIMIT_400 1
114 #define SD_SET_CURRENT_LIMIT_600 2
115 #define SD_SET_CURRENT_LIMIT_800 3
117 #define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200)
118 #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400)
119 #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600)
120 #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800)
124 unsigned int sdio_vsn
;
126 unsigned int multi_block
:1,
135 unsigned short vendor
;
136 unsigned short device
;
137 unsigned short blksize
;
138 unsigned int max_dtr
;
143 struct sdio_func_tuple
;
145 #define SDIO_MAX_FUNCS 7
151 struct mmc_host
*host
; /* the host this device belongs to */
152 struct device dev
; /* the device */
153 unsigned int rca
; /* relative card address of device */
154 unsigned int type
; /* card type */
155 #define MMC_TYPE_MMC 0 /* MMC card */
156 #define MMC_TYPE_SD 1 /* SD card */
157 #define MMC_TYPE_SDIO 2 /* SDIO card */
158 #define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */
159 unsigned int state
; /* (our) card state */
160 #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
161 #define MMC_STATE_READONLY (1<<1) /* card is read-only */
162 #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
163 #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */
164 #define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */
165 #define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */
166 #define MMC_CARD_SDXC (1<<6) /* card is SDXC */
167 unsigned int quirks
; /* card quirks */
168 #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
169 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
171 #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
172 /* (missing CIA registers) */
173 #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */
174 #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4) /* SDIO card has nonstd function interfaces */
175 #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */
176 #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */
177 #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */
179 unsigned int erase_size
; /* erase size in sectors */
180 unsigned int erase_shift
; /* if erase unit is power 2 */
181 unsigned int pref_erase
; /* in sectors */
182 u8 erased_byte
; /* value of erased bytes */
184 u32 raw_cid
[4]; /* raw card CID */
185 u32 raw_csd
[4]; /* raw card CSD */
186 u32 raw_scr
[2]; /* raw card SCR */
187 struct mmc_cid cid
; /* card identification */
188 struct mmc_csd csd
; /* card specific */
189 struct mmc_ext_csd ext_csd
; /* mmc v4 extended card specific */
190 struct sd_scr scr
; /* extra SD information */
191 struct sd_ssr ssr
; /* yet more SD information */
192 struct sd_switch_caps sw_caps
; /* switch (CMD6) caps */
194 unsigned int sdio_funcs
; /* number of SDIO functions */
195 struct sdio_cccr cccr
; /* common card info */
196 struct sdio_cis cis
; /* common tuple info */
197 struct sdio_func
*sdio_func
[SDIO_MAX_FUNCS
]; /* SDIO functions (devices) */
198 struct sdio_func
*sdio_single_irq
; /* SDIO function when only one IRQ active */
199 unsigned num_info
; /* number of info strings */
200 const char **info
; /* info strings */
201 struct sdio_func_tuple
*tuples
; /* unknown common tuples */
203 unsigned int sd_bus_speed
; /* Bus Speed Mode set for the card */
205 struct dentry
*debugfs_root
;
209 * The world is not perfect and supplies us with broken mmc/sdio devices.
210 * For at least some of these bugs we need a work-around.
214 /* CID-specific fields. */
217 /* Valid revision range */
218 u64 rev_start
, rev_end
;
221 unsigned short oemid
;
223 /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
224 u16 cis_vendor
, cis_device
;
226 void (*vendor_fixup
)(struct mmc_card
*card
, int data
);
230 #define CID_MANFID_ANY (-1u)
231 #define CID_OEMID_ANY ((unsigned short) -1)
232 #define CID_NAME_ANY (NULL)
234 #define END_FIXUP { 0 }
236 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \
237 _cis_vendor, _cis_device, \
241 .manfid = (_manfid), \
243 .rev_start = (_rev_start), \
244 .rev_end = (_rev_end), \
245 .cis_vendor = (_cis_vendor), \
246 .cis_device = (_cis_device), \
247 .vendor_fixup = (_fixup), \
251 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \
253 _FIXUP_EXT(_name, _manfid, \
254 _oemid, _rev_start, _rev_end, \
255 SDIO_ANY_ID, SDIO_ANY_ID, \
258 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
259 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
261 #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \
262 _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \
263 CID_OEMID_ANY, 0, -1ull, \
267 #define cid_rev(hwrev, fwrev, year, month) \
268 (((u64) hwrev) << 40 | \
269 ((u64) fwrev) << 32 | \
270 ((u64) year) << 16 | \
273 #define cid_rev_card(card) \
274 cid_rev(card->cid.hwrev, \
280 * Unconditionally quirk add/remove.
283 static inline void __maybe_unused
add_quirk(struct mmc_card
*card
, int data
)
285 card
->quirks
|= data
;
288 static inline void __maybe_unused
remove_quirk(struct mmc_card
*card
, int data
)
290 card
->quirks
&= ~data
;
293 #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
294 #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
295 #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
297 #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
298 #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
299 #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED)
300 #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR)
301 #define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR)
302 #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED)
303 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
305 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
306 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
307 #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
308 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
309 #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
310 #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED)
311 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
314 * Quirk add/remove for MMC products.
317 static inline void __maybe_unused
add_quirk_mmc(struct mmc_card
*card
, int data
)
319 if (mmc_card_mmc(card
))
320 card
->quirks
|= data
;
323 static inline void __maybe_unused
remove_quirk_mmc(struct mmc_card
*card
,
326 if (mmc_card_mmc(card
))
327 card
->quirks
&= ~data
;
331 * Quirk add/remove for SD products.
334 static inline void __maybe_unused
add_quirk_sd(struct mmc_card
*card
, int data
)
336 if (mmc_card_sd(card
))
337 card
->quirks
|= data
;
340 static inline void __maybe_unused
remove_quirk_sd(struct mmc_card
*card
,
343 if (mmc_card_sd(card
))
344 card
->quirks
&= ~data
;
347 static inline int mmc_card_lenient_fn0(const struct mmc_card
*c
)
349 return c
->quirks
& MMC_QUIRK_LENIENT_FN0
;
352 static inline int mmc_blksz_for_byte_mode(const struct mmc_card
*c
)
354 return c
->quirks
& MMC_QUIRK_BLKSZ_FOR_BYTE_MODE
;
357 static inline int mmc_card_disable_cd(const struct mmc_card
*c
)
359 return c
->quirks
& MMC_QUIRK_DISABLE_CD
;
362 static inline int mmc_card_nonstd_func_interface(const struct mmc_card
*c
)
364 return c
->quirks
& MMC_QUIRK_NONSTD_FUNC_IF
;
367 #define mmc_card_name(c) ((c)->cid.prod_name)
368 #define mmc_card_id(c) (dev_name(&(c)->dev))
370 #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
372 #define mmc_list_to_card(l) container_of(l, struct mmc_card, node)
373 #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev)
374 #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d)
377 * MMC device driver (e.g., Flash card, I/O card...)
380 struct device_driver drv
;
381 int (*probe
)(struct mmc_card
*);
382 void (*remove
)(struct mmc_card
*);
383 int (*suspend
)(struct mmc_card
*, pm_message_t
);
384 int (*resume
)(struct mmc_card
*);
387 extern int mmc_register_driver(struct mmc_driver
*);
388 extern void mmc_unregister_driver(struct mmc_driver
*);
390 extern void mmc_fixup_device(struct mmc_card
*card
,
391 const struct mmc_fixup
*table
);