Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
313162d0 | 13 | #include <linux/device.h> |
aaac1b47 | 14 | #include <linux/mmc/core.h> |
32780cd1 | 15 | #include <linux/mod_devicetable.h> |
1da177e4 LT |
16 | |
17 | struct mmc_cid { | |
18 | unsigned int manfid; | |
19 | char prod_name[8]; | |
51e7e8b6 | 20 | unsigned char prv; |
1da177e4 LT |
21 | unsigned int serial; |
22 | unsigned short oemid; | |
23 | unsigned short year; | |
24 | unsigned char hwrev; | |
25 | unsigned char fwrev; | |
26 | unsigned char month; | |
27 | }; | |
28 | ||
29 | struct mmc_csd { | |
6da24b78 | 30 | unsigned char structure; |
1da177e4 LT |
31 | unsigned char mmca_vsn; |
32 | unsigned short cmdclass; | |
33 | unsigned short tacc_clks; | |
34 | unsigned int tacc_ns; | |
3a303511 | 35 | unsigned int c_size; |
37be4e78 | 36 | unsigned int r2w_factor; |
1da177e4 | 37 | unsigned int max_dtr; |
dfe86cba | 38 | unsigned int erase_size; /* In sectors */ |
1da177e4 | 39 | unsigned int read_blkbits; |
a6f6c96b | 40 | unsigned int write_blkbits; |
1da177e4 | 41 | unsigned int capacity; |
a6f6c96b RK |
42 | unsigned int read_partial:1, |
43 | read_misalign:1, | |
ce11a161 | 44 | write_partial:1, |
a6f6c96b | 45 | write_misalign:1; |
1da177e4 LT |
46 | }; |
47 | ||
bce40a36 | 48 | struct mmc_ext_csd { |
b1ebe384 | 49 | u8 rev; |
dfe86cba AH |
50 | u8 erase_group_def; |
51 | u8 sec_feature_support; | |
f4c5522b AW |
52 | u8 rel_sectors; |
53 | u8 rel_param; | |
371a689f | 54 | u8 part_config; |
881d1c25 | 55 | u8 cache_ctrl; |
b2499518 | 56 | u8 rst_n_function; |
abd9ac14 SJ |
57 | u8 max_packed_writes; |
58 | u8 max_packed_reads; | |
59 | u8 packed_event_en; | |
371a689f | 60 | unsigned int part_time; /* Units: ms */ |
b1ebe384 | 61 | unsigned int sa_timeout; /* Units: 100ns */ |
b23cf0bd | 62 | unsigned int generic_cmd6_time; /* Units: 10ms */ |
bec8726a | 63 | unsigned int power_off_longtime; /* Units: ms */ |
e6c08586 | 64 | u8 power_off_notification; /* state */ |
bce40a36 | 65 | unsigned int hs_max_dtr; |
96cf5f02 SJ |
66 | #define MMC_HIGH_26_MAX_DTR 26000000 |
67 | #define MMC_HIGH_52_MAX_DTR 52000000 | |
68 | #define MMC_HIGH_DDR_MAX_DTR 52000000 | |
69 | #define MMC_HS200_MAX_DTR 200000000 | |
85a18ad9 | 70 | unsigned int sectors; |
dfc13e84 | 71 | unsigned int card_type; |
dfe86cba AH |
72 | unsigned int hc_erase_size; /* In sectors */ |
73 | unsigned int hc_erase_timeout; /* In milliseconds */ | |
74 | unsigned int sec_trim_mult; /* Secure trim multiplier */ | |
75 | unsigned int sec_erase_mult; /* Secure erase multiplier */ | |
76 | unsigned int trim_timeout; /* In milliseconds */ | |
709de99d CD |
77 | bool enhanced_area_en; /* enable bit */ |
78 | unsigned long long enhanced_area_offset; /* Units: Byte */ | |
79 | unsigned int enhanced_area_size; /* Units: KB */ | |
881d1c25 | 80 | unsigned int cache_size; /* Units: KB */ |
eb0d8f13 JC |
81 | bool hpi_en; /* HPI enablebit */ |
82 | bool hpi; /* HPI support bit */ | |
83 | unsigned int hpi_cmd; /* cmd used as HPI */ | |
950d56ac JC |
84 | bool bkops; /* background support bit */ |
85 | bool bkops_en; /* background enable bit */ | |
4265900e SD |
86 | unsigned int data_sector_size; /* 512 bytes or 4KB */ |
87 | unsigned int data_tag_unit_size; /* DATA TAG UNIT size */ | |
add710ea JR |
88 | unsigned int boot_ro_lock; /* ro lock support */ |
89 | bool boot_ro_lockable; | |
c148e9ff | 90 | u8 raw_exception_status; /* 54 */ |
f39b2dd9 | 91 | u8 raw_partition_support; /* 160 */ |
090d25fe | 92 | u8 raw_rpmb_size_mult; /* 168 */ |
f39b2dd9 PR |
93 | u8 raw_erased_mem_count; /* 181 */ |
94 | u8 raw_ext_csd_structure; /* 194 */ | |
95 | u8 raw_card_type; /* 196 */ | |
eb0d8f13 | 96 | u8 out_of_int_time; /* 198 */ |
60443712 FS |
97 | u8 raw_pwr_cl_52_195; /* 200 */ |
98 | u8 raw_pwr_cl_26_195; /* 201 */ | |
99 | u8 raw_pwr_cl_52_360; /* 202 */ | |
100 | u8 raw_pwr_cl_26_360; /* 203 */ | |
101 | u8 raw_s_a_timeout; /* 217 */ | |
f39b2dd9 PR |
102 | u8 raw_hc_erase_gap_size; /* 221 */ |
103 | u8 raw_erase_timeout_mult; /* 223 */ | |
104 | u8 raw_hc_erase_grp_size; /* 224 */ | |
105 | u8 raw_sec_trim_mult; /* 229 */ | |
106 | u8 raw_sec_erase_mult; /* 230 */ | |
107 | u8 raw_sec_feature_support;/* 231 */ | |
108 | u8 raw_trim_mult; /* 232 */ | |
60443712 FS |
109 | u8 raw_pwr_cl_200_195; /* 236 */ |
110 | u8 raw_pwr_cl_200_360; /* 237 */ | |
111 | u8 raw_pwr_cl_ddr_52_195; /* 238 */ | |
112 | u8 raw_pwr_cl_ddr_52_360; /* 239 */ | |
950d56ac | 113 | u8 raw_bkops_status; /* 246 */ |
f39b2dd9 | 114 | u8 raw_sectors[4]; /* 212 - 4 bytes */ |
b3bf9153 KP |
115 | |
116 | unsigned int feature_support; | |
117 | #define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */ | |
bce40a36 PL |
118 | }; |
119 | ||
b57c43ad PO |
120 | struct sd_scr { |
121 | unsigned char sda_vsn; | |
013909c4 | 122 | unsigned char sda_spec3; |
b57c43ad PO |
123 | unsigned char bus_widths; |
124 | #define SD_SCR_BUS_WIDTH_1 (1<<0) | |
125 | #define SD_SCR_BUS_WIDTH_4 (1<<2) | |
f0d89972 AW |
126 | unsigned char cmds; |
127 | #define SD_SCR_CMD20_SUPPORT (1<<0) | |
128 | #define SD_SCR_CMD23_SUPPORT (1<<1) | |
b57c43ad PO |
129 | }; |
130 | ||
dfe86cba AH |
131 | struct sd_ssr { |
132 | unsigned int au; /* In sectors */ | |
133 | unsigned int erase_timeout; /* In milliseconds */ | |
134 | unsigned int erase_offset; /* In milliseconds */ | |
135 | }; | |
136 | ||
7ccd266e PO |
137 | struct sd_switch_caps { |
138 | unsigned int hs_max_dtr; | |
49c468fc | 139 | unsigned int uhs_max_dtr; |
fffe5d5a | 140 | #define HIGH_SPEED_MAX_DTR 50000000 |
49c468fc AN |
141 | #define UHS_SDR104_MAX_DTR 208000000 |
142 | #define UHS_SDR50_MAX_DTR 100000000 | |
143 | #define UHS_DDR50_MAX_DTR 50000000 | |
144 | #define UHS_SDR25_MAX_DTR UHS_DDR50_MAX_DTR | |
145 | #define UHS_SDR12_MAX_DTR 25000000 | |
013909c4 | 146 | unsigned int sd3_bus_mode; |
49c468fc | 147 | #define UHS_SDR12_BUS_SPEED 0 |
fffe5d5a | 148 | #define HIGH_SPEED_BUS_SPEED 1 |
49c468fc AN |
149 | #define UHS_SDR25_BUS_SPEED 1 |
150 | #define UHS_SDR50_BUS_SPEED 2 | |
151 | #define UHS_SDR104_BUS_SPEED 3 | |
152 | #define UHS_DDR50_BUS_SPEED 4 | |
153 | ||
fffe5d5a | 154 | #define SD_MODE_HIGH_SPEED (1 << HIGH_SPEED_BUS_SPEED) |
49c468fc AN |
155 | #define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED) |
156 | #define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED) | |
157 | #define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED) | |
158 | #define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED) | |
159 | #define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED) | |
013909c4 | 160 | unsigned int sd3_drv_type; |
d6d50a15 AN |
161 | #define SD_DRIVER_TYPE_B 0x01 |
162 | #define SD_DRIVER_TYPE_A 0x02 | |
163 | #define SD_DRIVER_TYPE_C 0x04 | |
164 | #define SD_DRIVER_TYPE_D 0x08 | |
013909c4 | 165 | unsigned int sd3_curr_limit; |
5371c927 AN |
166 | #define SD_SET_CURRENT_LIMIT_200 0 |
167 | #define SD_SET_CURRENT_LIMIT_400 1 | |
168 | #define SD_SET_CURRENT_LIMIT_600 2 | |
169 | #define SD_SET_CURRENT_LIMIT_800 3 | |
0aa67700 | 170 | #define SD_SET_CURRENT_NO_CHANGE (-1) |
5371c927 AN |
171 | |
172 | #define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200) | |
173 | #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400) | |
174 | #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600) | |
175 | #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) | |
7ccd266e PO |
176 | }; |
177 | ||
35c66c19 PO |
178 | struct sdio_cccr { |
179 | unsigned int sdio_vsn; | |
180 | unsigned int sd_vsn; | |
181 | unsigned int multi_block:1, | |
182 | low_speed:1, | |
183 | wide_bus:1, | |
184 | high_power:1, | |
006ebd5d OBC |
185 | high_speed:1, |
186 | disable_cd:1; | |
35c66c19 PO |
187 | }; |
188 | ||
1a632f8c PO |
189 | struct sdio_cis { |
190 | unsigned short vendor; | |
191 | unsigned short device; | |
192 | unsigned short blksize; | |
193 | unsigned int max_dtr; | |
194 | }; | |
195 | ||
1da177e4 | 196 | struct mmc_host; |
e29a7d73 | 197 | struct sdio_func; |
1a632f8c | 198 | struct sdio_func_tuple; |
e29a7d73 PO |
199 | |
200 | #define SDIO_MAX_FUNCS 7 | |
1da177e4 | 201 | |
2220eedf KD |
202 | enum mmc_blk_status { |
203 | MMC_BLK_SUCCESS = 0, | |
204 | MMC_BLK_PARTIAL, | |
205 | MMC_BLK_CMD_ERR, | |
206 | MMC_BLK_RETRY, | |
207 | MMC_BLK_ABORT, | |
208 | MMC_BLK_DATA_ERR, | |
209 | MMC_BLK_ECC_ERR, | |
210 | MMC_BLK_NOMEDIUM, | |
211 | MMC_BLK_NEW_REQUEST, | |
212 | }; | |
213 | ||
e0c368d5 NJ |
214 | /* The number of MMC physical partitions. These consist of: |
215 | * boot partitions (2), general purpose partitions (4) in MMC v4.4. | |
216 | */ | |
217 | #define MMC_NUM_BOOT_PARTITION 2 | |
218 | #define MMC_NUM_GP_PARTITION 4 | |
219 | #define MMC_NUM_PHY_PARTITION 6 | |
a6029e1f | 220 | #define MAX_MMC_PART_NAME_LEN 20 |
e0c368d5 NJ |
221 | |
222 | /* | |
223 | * MMC Physical partitions | |
224 | */ | |
225 | struct mmc_part { | |
226 | unsigned int size; /* partition size (in bytes) */ | |
227 | unsigned int part_cfg; /* partition type */ | |
a6029e1f | 228 | char name[MAX_MMC_PART_NAME_LEN]; |
e0c368d5 | 229 | bool force_ro; /* to make boot parts RO by default */ |
add710ea JR |
230 | unsigned int area_type; |
231 | #define MMC_BLK_DATA_AREA_MAIN (1<<0) | |
232 | #define MMC_BLK_DATA_AREA_BOOT (1<<1) | |
233 | #define MMC_BLK_DATA_AREA_GP (1<<2) | |
090d25fe | 234 | #define MMC_BLK_DATA_AREA_RPMB (1<<3) |
e0c368d5 NJ |
235 | }; |
236 | ||
1da177e4 LT |
237 | /* |
238 | * MMC device | |
239 | */ | |
240 | struct mmc_card { | |
1da177e4 LT |
241 | struct mmc_host *host; /* the host this device belongs to */ |
242 | struct device dev; /* the device */ | |
243 | unsigned int rca; /* relative card address of device */ | |
9c2c0af9 PO |
244 | unsigned int type; /* card type */ |
245 | #define MMC_TYPE_MMC 0 /* MMC card */ | |
246 | #define MMC_TYPE_SD 1 /* SD card */ | |
5c4e6f13 | 247 | #define MMC_TYPE_SDIO 2 /* SDIO card */ |
7310ece8 | 248 | #define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */ |
1da177e4 LT |
249 | unsigned int state; /* (our) card state */ |
250 | #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */ | |
bd766312 PO |
251 | #define MMC_STATE_READONLY (1<<1) /* card is read-only */ |
252 | #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */ | |
253 | #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */ | |
dfc13e84 | 254 | #define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */ |
3a303511 AN |
255 | #define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */ |
256 | #define MMC_CARD_SDXC (1<<6) /* card is SDXC */ | |
d3049504 | 257 | #define MMC_CARD_REMOVED (1<<7) /* card has been removed */ |
a4924c71 | 258 | #define MMC_STATE_HIGHSPEED_200 (1<<8) /* card is in HS200 mode */ |
950d56ac | 259 | #define MMC_STATE_DOING_BKOPS (1<<10) /* card is doing BKOPS */ |
7c979ec7 OBC |
260 | unsigned int quirks; /* card quirks */ |
261 | #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ | |
3fb7fb4a BZ |
262 | #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ |
263 | /* for byte mode */ | |
6f51be3d GI |
264 | #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ |
265 | /* (missing CIA registers) */ | |
db993500 | 266 | #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */ |
eab40687 | 267 | #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4) /* SDIO card has nonstd function interfaces */ |
2059a02d | 268 | #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */ |
6a7a6b45 | 269 | #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */ |
d0c97cfb | 270 | #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ |
9a0da648 | 271 | #define MMC_QUIRK_BROKEN_BYTE_MODE_512 (1<<8) /* Avoid sending 512 bytes in */ |
6de5fc9c | 272 | #define MMC_QUIRK_LONG_READ_TIME (1<<9) /* Data read time > CSD says */ |
3550ccdb | 273 | #define MMC_QUIRK_SEC_ERASE_TRIM_BROKEN (1<<10) /* Skip secure for erase/trim */ |
9a0da648 | 274 | /* byte mode */ |
e29a7d73 | 275 | |
dfe86cba AH |
276 | unsigned int erase_size; /* erase size in sectors */ |
277 | unsigned int erase_shift; /* if erase unit is power 2 */ | |
278 | unsigned int pref_erase; /* in sectors */ | |
279 | u8 erased_byte; /* value of erased bytes */ | |
280 | ||
1da177e4 LT |
281 | u32 raw_cid[4]; /* raw card CID */ |
282 | u32 raw_csd[4]; /* raw card CSD */ | |
b57c43ad | 283 | u32 raw_scr[2]; /* raw card SCR */ |
1da177e4 LT |
284 | struct mmc_cid cid; /* card identification */ |
285 | struct mmc_csd csd; /* card specific */ | |
bce40a36 | 286 | struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */ |
b57c43ad | 287 | struct sd_scr scr; /* extra SD information */ |
dfe86cba | 288 | struct sd_ssr ssr; /* yet more SD information */ |
7ccd266e | 289 | struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ |
e29a7d73 PO |
290 | |
291 | unsigned int sdio_funcs; /* number of SDIO functions */ | |
35c66c19 | 292 | struct sdio_cccr cccr; /* common card info */ |
1a632f8c | 293 | struct sdio_cis cis; /* common tuple info */ |
e29a7d73 | 294 | struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */ |
06e8935f | 295 | struct sdio_func *sdio_single_irq; /* SDIO function when only one IRQ active */ |
759bdc7a PO |
296 | unsigned num_info; /* number of info strings */ |
297 | const char **info; /* info strings */ | |
1a632f8c | 298 | struct sdio_func_tuple *tuples; /* unknown common tuples */ |
f4b7f927 | 299 | |
49c468fc AN |
300 | unsigned int sd_bus_speed; /* Bus Speed Mode set for the card */ |
301 | ||
f4b7f927 | 302 | struct dentry *debugfs_root; |
e0c368d5 NJ |
303 | struct mmc_part part[MMC_NUM_PHY_PARTITION]; /* physical partitions */ |
304 | unsigned int nr_parts; | |
1da177e4 LT |
305 | }; |
306 | ||
e0c368d5 NJ |
307 | /* |
308 | * This function fill contents in mmc_part. | |
309 | */ | |
310 | static inline void mmc_part_add(struct mmc_card *card, unsigned int size, | |
add710ea JR |
311 | unsigned int part_cfg, char *name, int idx, bool ro, |
312 | int area_type) | |
e0c368d5 NJ |
313 | { |
314 | card->part[card->nr_parts].size = size; | |
315 | card->part[card->nr_parts].part_cfg = part_cfg; | |
316 | sprintf(card->part[card->nr_parts].name, name, idx); | |
317 | card->part[card->nr_parts].force_ro = ro; | |
add710ea | 318 | card->part[card->nr_parts].area_type = area_type; |
e0c368d5 NJ |
319 | card->nr_parts++; |
320 | } | |
321 | ||
ce39f9d1 SJ |
322 | static inline bool mmc_large_sector(struct mmc_card *card) |
323 | { | |
324 | return card->ext_csd.data_sector_size == 4096; | |
325 | } | |
326 | ||
32780cd1 AW |
327 | /* |
328 | * The world is not perfect and supplies us with broken mmc/sdio devices. | |
329 | * For at least some of these bugs we need a work-around. | |
330 | */ | |
331 | ||
332 | struct mmc_fixup { | |
333 | /* CID-specific fields. */ | |
334 | const char *name; | |
335 | ||
336 | /* Valid revision range */ | |
337 | u64 rev_start, rev_end; | |
338 | ||
339 | unsigned int manfid; | |
340 | unsigned short oemid; | |
341 | ||
342 | /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */ | |
343 | u16 cis_vendor, cis_device; | |
344 | ||
345 | void (*vendor_fixup)(struct mmc_card *card, int data); | |
346 | int data; | |
347 | }; | |
348 | ||
853c6cac | 349 | #define CID_MANFID_ANY (-1u) |
32780cd1 AW |
350 | #define CID_OEMID_ANY ((unsigned short) -1) |
351 | #define CID_NAME_ANY (NULL) | |
352 | ||
353 | #define END_FIXUP { 0 } | |
354 | ||
355 | #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \ | |
356 | _cis_vendor, _cis_device, \ | |
357 | _fixup, _data) \ | |
358 | { \ | |
359 | .name = (_name), \ | |
360 | .manfid = (_manfid), \ | |
361 | .oemid = (_oemid), \ | |
362 | .rev_start = (_rev_start), \ | |
363 | .rev_end = (_rev_end), \ | |
364 | .cis_vendor = (_cis_vendor), \ | |
365 | .cis_device = (_cis_device), \ | |
366 | .vendor_fixup = (_fixup), \ | |
367 | .data = (_data), \ | |
368 | } | |
369 | ||
370 | #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \ | |
371 | _fixup, _data) \ | |
372 | _FIXUP_EXT(_name, _manfid, \ | |
373 | _oemid, _rev_start, _rev_end, \ | |
374 | SDIO_ANY_ID, SDIO_ANY_ID, \ | |
375 | _fixup, _data) \ | |
376 | ||
377 | #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \ | |
378 | MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data) | |
379 | ||
380 | #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \ | |
381 | _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \ | |
382 | CID_OEMID_ANY, 0, -1ull, \ | |
383 | _vendor, _device, \ | |
384 | _fixup, _data) \ | |
385 | ||
386 | #define cid_rev(hwrev, fwrev, year, month) \ | |
387 | (((u64) hwrev) << 40 | \ | |
388 | ((u64) fwrev) << 32 | \ | |
389 | ((u64) year) << 16 | \ | |
390 | ((u64) month)) | |
391 | ||
392 | #define cid_rev_card(card) \ | |
393 | cid_rev(card->cid.hwrev, \ | |
394 | card->cid.fwrev, \ | |
395 | card->cid.year, \ | |
396 | card->cid.month) | |
397 | ||
398 | /* | |
c59de928 | 399 | * Unconditionally quirk add/remove. |
32780cd1 | 400 | */ |
c59de928 | 401 | |
32780cd1 AW |
402 | static inline void __maybe_unused add_quirk(struct mmc_card *card, int data) |
403 | { | |
404 | card->quirks |= data; | |
405 | } | |
406 | ||
32780cd1 AW |
407 | static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) |
408 | { | |
409 | card->quirks &= ~data; | |
410 | } | |
57f0adc7 | 411 | |
9c2c0af9 PO |
412 | #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) |
413 | #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) | |
5c4e6f13 | 414 | #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO) |
9c2c0af9 | 415 | |
1da177e4 | 416 | #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) |
a00fc090 | 417 | #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) |
bce40a36 | 418 | #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) |
a4924c71 | 419 | #define mmc_card_hs200(c) ((c)->state & MMC_STATE_HIGHSPEED_200) |
fba68bd2 | 420 | #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) |
dfc13e84 | 421 | #define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR) |
a303c531 PR |
422 | #define mmc_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) |
423 | #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) | |
3a303511 | 424 | #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) |
d3049504 | 425 | #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) |
950d56ac | 426 | #define mmc_card_doing_bkops(c) ((c)->state & MMC_STATE_DOING_BKOPS) |
1da177e4 LT |
427 | |
428 | #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) | |
a00fc090 | 429 | #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) |
bce40a36 | 430 | #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) |
a4924c71 | 431 | #define mmc_card_set_hs200(c) ((c)->state |= MMC_STATE_HIGHSPEED_200) |
fba68bd2 | 432 | #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) |
dfc13e84 | 433 | #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR) |
a303c531 | 434 | #define mmc_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) |
3a303511 AN |
435 | #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) |
436 | #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) | |
d3049504 | 437 | #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) |
950d56ac | 438 | #define mmc_card_set_doing_bkops(c) ((c)->state |= MMC_STATE_DOING_BKOPS) |
950d56ac | 439 | #define mmc_card_clr_doing_bkops(c) ((c)->state &= ~MMC_STATE_DOING_BKOPS) |
e6c08586 | 440 | |
c59de928 AW |
441 | /* |
442 | * Quirk add/remove for MMC products. | |
443 | */ | |
444 | ||
445 | static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data) | |
446 | { | |
447 | if (mmc_card_mmc(card)) | |
448 | card->quirks |= data; | |
449 | } | |
450 | ||
451 | static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card, | |
452 | int data) | |
453 | { | |
454 | if (mmc_card_mmc(card)) | |
455 | card->quirks &= ~data; | |
456 | } | |
457 | ||
458 | /* | |
459 | * Quirk add/remove for SD products. | |
460 | */ | |
461 | ||
462 | static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data) | |
463 | { | |
464 | if (mmc_card_sd(card)) | |
465 | card->quirks |= data; | |
466 | } | |
467 | ||
468 | static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card, | |
469 | int data) | |
470 | { | |
471 | if (mmc_card_sd(card)) | |
472 | card->quirks &= ~data; | |
473 | } | |
474 | ||
7c979ec7 OBC |
475 | static inline int mmc_card_lenient_fn0(const struct mmc_card *c) |
476 | { | |
477 | return c->quirks & MMC_QUIRK_LENIENT_FN0; | |
478 | } | |
479 | ||
3fb7fb4a BZ |
480 | static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c) |
481 | { | |
482 | return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | |
483 | } | |
484 | ||
2059a02d OBC |
485 | static inline int mmc_card_disable_cd(const struct mmc_card *c) |
486 | { | |
487 | return c->quirks & MMC_QUIRK_DISABLE_CD; | |
488 | } | |
489 | ||
eab40687 OBC |
490 | static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c) |
491 | { | |
492 | return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; | |
493 | } | |
494 | ||
9a0da648 SNX |
495 | static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c) |
496 | { | |
497 | return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512; | |
498 | } | |
499 | ||
6de5fc9c SNX |
500 | static inline int mmc_card_long_read_time(const struct mmc_card *c) |
501 | { | |
502 | return c->quirks & MMC_QUIRK_LONG_READ_TIME; | |
503 | } | |
504 | ||
1da177e4 | 505 | #define mmc_card_name(c) ((c)->cid.prod_name) |
d1b26863 | 506 | #define mmc_card_id(c) (dev_name(&(c)->dev)) |
1da177e4 | 507 | |
265cdc90 | 508 | #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev) |
453722b9 | 509 | |
1da177e4 LT |
510 | #define mmc_list_to_card(l) container_of(l, struct mmc_card, node) |
511 | #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev) | |
512 | #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d) | |
513 | ||
514 | /* | |
515 | * MMC device driver (e.g., Flash card, I/O card...) | |
516 | */ | |
517 | struct mmc_driver { | |
518 | struct device_driver drv; | |
519 | int (*probe)(struct mmc_card *); | |
520 | void (*remove)(struct mmc_card *); | |
32d317c6 | 521 | int (*suspend)(struct mmc_card *); |
1da177e4 | 522 | int (*resume)(struct mmc_card *); |
76287748 | 523 | void (*shutdown)(struct mmc_card *); |
1da177e4 LT |
524 | }; |
525 | ||
526 | extern int mmc_register_driver(struct mmc_driver *); | |
527 | extern void mmc_unregister_driver(struct mmc_driver *); | |
528 | ||
32780cd1 AW |
529 | extern void mmc_fixup_device(struct mmc_card *card, |
530 | const struct mmc_fixup *table); | |
531 | ||
100e9186 | 532 | #endif /* LINUX_MMC_CARD_H */ |