diff options
Diffstat (limited to 'include/linux/mmc/card.h')
-rw-r--r-- | include/linux/mmc/card.h | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 6b7525099e56..6ad43554ac05 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h | |||
@@ -11,6 +11,7 @@ | |||
11 | #define LINUX_MMC_CARD_H | 11 | #define LINUX_MMC_CARD_H |
12 | 12 | ||
13 | #include <linux/mmc/core.h> | 13 | #include <linux/mmc/core.h> |
14 | #include <linux/mod_devicetable.h> | ||
14 | 15 | ||
15 | struct mmc_cid { | 16 | struct mmc_cid { |
16 | unsigned int manfid; | 17 | unsigned int manfid; |
@@ -29,6 +30,7 @@ struct mmc_csd { | |||
29 | unsigned short cmdclass; | 30 | unsigned short cmdclass; |
30 | unsigned short tacc_clks; | 31 | unsigned short tacc_clks; |
31 | unsigned int tacc_ns; | 32 | unsigned int tacc_ns; |
33 | unsigned int c_size; | ||
32 | unsigned int r2w_factor; | 34 | unsigned int r2w_factor; |
33 | unsigned int max_dtr; | 35 | unsigned int max_dtr; |
34 | unsigned int erase_size; /* In sectors */ | 36 | unsigned int erase_size; /* In sectors */ |
@@ -45,21 +47,47 @@ struct mmc_ext_csd { | |||
45 | u8 rev; | 47 | u8 rev; |
46 | u8 erase_group_def; | 48 | u8 erase_group_def; |
47 | u8 sec_feature_support; | 49 | u8 sec_feature_support; |
50 | u8 rel_sectors; | ||
51 | u8 rel_param; | ||
52 | u8 part_config; | ||
53 | unsigned int part_time; /* Units: ms */ | ||
48 | unsigned int sa_timeout; /* Units: 100ns */ | 54 | unsigned int sa_timeout; /* Units: 100ns */ |
49 | unsigned int hs_max_dtr; | 55 | unsigned int hs_max_dtr; |
50 | unsigned int sectors; | 56 | unsigned int sectors; |
57 | unsigned int card_type; | ||
51 | unsigned int hc_erase_size; /* In sectors */ | 58 | unsigned int hc_erase_size; /* In sectors */ |
52 | unsigned int hc_erase_timeout; /* In milliseconds */ | 59 | unsigned int hc_erase_timeout; /* In milliseconds */ |
53 | unsigned int sec_trim_mult; /* Secure trim multiplier */ | 60 | unsigned int sec_trim_mult; /* Secure trim multiplier */ |
54 | unsigned int sec_erase_mult; /* Secure erase multiplier */ | 61 | unsigned int sec_erase_mult; /* Secure erase multiplier */ |
55 | unsigned int trim_timeout; /* In milliseconds */ | 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 */ | ||
67 | u8 raw_partition_support; /* 160 */ | ||
68 | u8 raw_erased_mem_count; /* 181 */ | ||
69 | u8 raw_ext_csd_structure; /* 194 */ | ||
70 | u8 raw_card_type; /* 196 */ | ||
71 | u8 raw_s_a_timeout; /* 217 */ | ||
72 | u8 raw_hc_erase_gap_size; /* 221 */ | ||
73 | u8 raw_erase_timeout_mult; /* 223 */ | ||
74 | u8 raw_hc_erase_grp_size; /* 224 */ | ||
75 | u8 raw_sec_trim_mult; /* 229 */ | ||
76 | u8 raw_sec_erase_mult; /* 230 */ | ||
77 | u8 raw_sec_feature_support;/* 231 */ | ||
78 | u8 raw_trim_mult; /* 232 */ | ||
79 | u8 raw_sectors[4]; /* 212 - 4 bytes */ | ||
56 | }; | 80 | }; |
57 | 81 | ||
58 | struct sd_scr { | 82 | struct sd_scr { |
59 | unsigned char sda_vsn; | 83 | unsigned char sda_vsn; |
84 | unsigned char sda_spec3; | ||
60 | unsigned char bus_widths; | 85 | unsigned char bus_widths; |
61 | #define SD_SCR_BUS_WIDTH_1 (1<<0) | 86 | #define SD_SCR_BUS_WIDTH_1 (1<<0) |
62 | #define SD_SCR_BUS_WIDTH_4 (1<<2) | 87 | #define SD_SCR_BUS_WIDTH_4 (1<<2) |
88 | unsigned char cmds; | ||
89 | #define SD_SCR_CMD20_SUPPORT (1<<0) | ||
90 | #define SD_SCR_CMD23_SUPPORT (1<<1) | ||
63 | }; | 91 | }; |
64 | 92 | ||
65 | struct sd_ssr { | 93 | struct sd_ssr { |
@@ -70,6 +98,39 @@ struct sd_ssr { | |||
70 | 98 | ||
71 | struct sd_switch_caps { | 99 | struct sd_switch_caps { |
72 | unsigned int hs_max_dtr; | 100 | unsigned int hs_max_dtr; |
101 | unsigned int uhs_max_dtr; | ||
102 | #define UHS_SDR104_MAX_DTR 208000000 | ||
103 | #define UHS_SDR50_MAX_DTR 100000000 | ||
104 | #define UHS_DDR50_MAX_DTR 50000000 | ||
105 | #define UHS_SDR25_MAX_DTR UHS_DDR50_MAX_DTR | ||
106 | #define UHS_SDR12_MAX_DTR 25000000 | ||
107 | unsigned int sd3_bus_mode; | ||
108 | #define UHS_SDR12_BUS_SPEED 0 | ||
109 | #define UHS_SDR25_BUS_SPEED 1 | ||
110 | #define UHS_SDR50_BUS_SPEED 2 | ||
111 | #define UHS_SDR104_BUS_SPEED 3 | ||
112 | #define UHS_DDR50_BUS_SPEED 4 | ||
113 | |||
114 | #define SD_MODE_UHS_SDR12 (1 << UHS_SDR12_BUS_SPEED) | ||
115 | #define SD_MODE_UHS_SDR25 (1 << UHS_SDR25_BUS_SPEED) | ||
116 | #define SD_MODE_UHS_SDR50 (1 << UHS_SDR50_BUS_SPEED) | ||
117 | #define SD_MODE_UHS_SDR104 (1 << UHS_SDR104_BUS_SPEED) | ||
118 | #define SD_MODE_UHS_DDR50 (1 << UHS_DDR50_BUS_SPEED) | ||
119 | unsigned int sd3_drv_type; | ||
120 | #define SD_DRIVER_TYPE_B 0x01 | ||
121 | #define SD_DRIVER_TYPE_A 0x02 | ||
122 | #define SD_DRIVER_TYPE_C 0x04 | ||
123 | #define SD_DRIVER_TYPE_D 0x08 | ||
124 | unsigned int sd3_curr_limit; | ||
125 | #define SD_SET_CURRENT_LIMIT_200 0 | ||
126 | #define SD_SET_CURRENT_LIMIT_400 1 | ||
127 | #define SD_SET_CURRENT_LIMIT_600 2 | ||
128 | #define SD_SET_CURRENT_LIMIT_800 3 | ||
129 | |||
130 | #define SD_MAX_CURRENT_200 (1 << SD_SET_CURRENT_LIMIT_200) | ||
131 | #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400) | ||
132 | #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600) | ||
133 | #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) | ||
73 | }; | 134 | }; |
74 | 135 | ||
75 | struct sdio_cccr { | 136 | struct sdio_cccr { |
@@ -113,12 +174,20 @@ struct mmc_card { | |||
113 | #define MMC_STATE_READONLY (1<<1) /* card is read-only */ | 174 | #define MMC_STATE_READONLY (1<<1) /* card is read-only */ |
114 | #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */ | 175 | #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */ |
115 | #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */ | 176 | #define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */ |
177 | #define MMC_STATE_HIGHSPEED_DDR (1<<4) /* card is in high speed mode */ | ||
178 | #define MMC_STATE_ULTRAHIGHSPEED (1<<5) /* card is in ultra high speed mode */ | ||
179 | #define MMC_CARD_SDXC (1<<6) /* card is SDXC */ | ||
116 | unsigned int quirks; /* card quirks */ | 180 | unsigned int quirks; /* card quirks */ |
117 | #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ | 181 | #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */ |
118 | #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ | 182 | #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */ |
119 | /* for byte mode */ | 183 | /* for byte mode */ |
120 | #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ | 184 | #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ |
121 | /* (missing CIA registers) */ | 185 | /* (missing CIA registers) */ |
186 | #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3) /* clock gating the sdio bus will make card fail */ | ||
187 | #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4) /* SDIO card has nonstd function interfaces */ | ||
188 | #define MMC_QUIRK_DISABLE_CD (1<<5) /* disconnect CD/DAT[3] resistor */ | ||
189 | #define MMC_QUIRK_INAND_CMD38 (1<<6) /* iNAND devices have broken CMD38 */ | ||
190 | #define MMC_QUIRK_BLK_NO_CMD23 (1<<7) /* Avoid CMD23 for regular multiblock */ | ||
122 | 191 | ||
123 | unsigned int erase_size; /* erase size in sectors */ | 192 | unsigned int erase_size; /* erase size in sectors */ |
124 | unsigned int erase_shift; /* if erase unit is power 2 */ | 193 | unsigned int erase_shift; /* if erase unit is power 2 */ |
@@ -139,13 +208,101 @@ struct mmc_card { | |||
139 | struct sdio_cccr cccr; /* common card info */ | 208 | struct sdio_cccr cccr; /* common card info */ |
140 | struct sdio_cis cis; /* common tuple info */ | 209 | struct sdio_cis cis; /* common tuple info */ |
141 | struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */ | 210 | struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */ |
211 | struct sdio_func *sdio_single_irq; /* SDIO function when only one IRQ active */ | ||
142 | unsigned num_info; /* number of info strings */ | 212 | unsigned num_info; /* number of info strings */ |
143 | const char **info; /* info strings */ | 213 | const char **info; /* info strings */ |
144 | struct sdio_func_tuple *tuples; /* unknown common tuples */ | 214 | struct sdio_func_tuple *tuples; /* unknown common tuples */ |
145 | 215 | ||
216 | unsigned int sd_bus_speed; /* Bus Speed Mode set for the card */ | ||
217 | |||
146 | struct dentry *debugfs_root; | 218 | struct dentry *debugfs_root; |
147 | }; | 219 | }; |
148 | 220 | ||
221 | /* | ||
222 | * The world is not perfect and supplies us with broken mmc/sdio devices. | ||
223 | * For at least some of these bugs we need a work-around. | ||
224 | */ | ||
225 | |||
226 | struct mmc_fixup { | ||
227 | /* CID-specific fields. */ | ||
228 | const char *name; | ||
229 | |||
230 | /* Valid revision range */ | ||
231 | u64 rev_start, rev_end; | ||
232 | |||
233 | unsigned int manfid; | ||
234 | unsigned short oemid; | ||
235 | |||
236 | /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */ | ||
237 | u16 cis_vendor, cis_device; | ||
238 | |||
239 | void (*vendor_fixup)(struct mmc_card *card, int data); | ||
240 | int data; | ||
241 | }; | ||
242 | |||
243 | #define CID_MANFID_ANY (-1u) | ||
244 | #define CID_OEMID_ANY ((unsigned short) -1) | ||
245 | #define CID_NAME_ANY (NULL) | ||
246 | |||
247 | #define END_FIXUP { 0 } | ||
248 | |||
249 | #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \ | ||
250 | _cis_vendor, _cis_device, \ | ||
251 | _fixup, _data) \ | ||
252 | { \ | ||
253 | .name = (_name), \ | ||
254 | .manfid = (_manfid), \ | ||
255 | .oemid = (_oemid), \ | ||
256 | .rev_start = (_rev_start), \ | ||
257 | .rev_end = (_rev_end), \ | ||
258 | .cis_vendor = (_cis_vendor), \ | ||
259 | .cis_device = (_cis_device), \ | ||
260 | .vendor_fixup = (_fixup), \ | ||
261 | .data = (_data), \ | ||
262 | } | ||
263 | |||
264 | #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \ | ||
265 | _fixup, _data) \ | ||
266 | _FIXUP_EXT(_name, _manfid, \ | ||
267 | _oemid, _rev_start, _rev_end, \ | ||
268 | SDIO_ANY_ID, SDIO_ANY_ID, \ | ||
269 | _fixup, _data) \ | ||
270 | |||
271 | #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \ | ||
272 | MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data) | ||
273 | |||
274 | #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \ | ||
275 | _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \ | ||
276 | CID_OEMID_ANY, 0, -1ull, \ | ||
277 | _vendor, _device, \ | ||
278 | _fixup, _data) \ | ||
279 | |||
280 | #define cid_rev(hwrev, fwrev, year, month) \ | ||
281 | (((u64) hwrev) << 40 | \ | ||
282 | ((u64) fwrev) << 32 | \ | ||
283 | ((u64) year) << 16 | \ | ||
284 | ((u64) month)) | ||
285 | |||
286 | #define cid_rev_card(card) \ | ||
287 | cid_rev(card->cid.hwrev, \ | ||
288 | card->cid.fwrev, \ | ||
289 | card->cid.year, \ | ||
290 | card->cid.month) | ||
291 | |||
292 | /* | ||
293 | * Unconditionally quirk add/remove. | ||
294 | */ | ||
295 | |||
296 | static inline void __maybe_unused add_quirk(struct mmc_card *card, int data) | ||
297 | { | ||
298 | card->quirks |= data; | ||
299 | } | ||
300 | |||
301 | static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) | ||
302 | { | ||
303 | card->quirks &= ~data; | ||
304 | } | ||
305 | |||
149 | #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) | 306 | #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) |
150 | #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) | 307 | #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) |
151 | #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO) | 308 | #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO) |
@@ -154,11 +311,51 @@ struct mmc_card { | |||
154 | #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) | 311 | #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) |
155 | #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) | 312 | #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED) |
156 | #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) | 313 | #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) |
314 | #define mmc_card_ddr_mode(c) ((c)->state & MMC_STATE_HIGHSPEED_DDR) | ||
315 | #define mmc_sd_card_uhs(c) ((c)->state & MMC_STATE_ULTRAHIGHSPEED) | ||
316 | #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) | ||
157 | 317 | ||
158 | #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) | 318 | #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) |
159 | #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) | 319 | #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) |
160 | #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) | 320 | #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED) |
161 | #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) | 321 | #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) |
322 | #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR) | ||
323 | #define mmc_sd_card_set_uhs(c) ((c)->state |= MMC_STATE_ULTRAHIGHSPEED) | ||
324 | #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) | ||
325 | |||
326 | /* | ||
327 | * Quirk add/remove for MMC products. | ||
328 | */ | ||
329 | |||
330 | static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data) | ||
331 | { | ||
332 | if (mmc_card_mmc(card)) | ||
333 | card->quirks |= data; | ||
334 | } | ||
335 | |||
336 | static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card, | ||
337 | int data) | ||
338 | { | ||
339 | if (mmc_card_mmc(card)) | ||
340 | card->quirks &= ~data; | ||
341 | } | ||
342 | |||
343 | /* | ||
344 | * Quirk add/remove for SD products. | ||
345 | */ | ||
346 | |||
347 | static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data) | ||
348 | { | ||
349 | if (mmc_card_sd(card)) | ||
350 | card->quirks |= data; | ||
351 | } | ||
352 | |||
353 | static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card, | ||
354 | int data) | ||
355 | { | ||
356 | if (mmc_card_sd(card)) | ||
357 | card->quirks &= ~data; | ||
358 | } | ||
162 | 359 | ||
163 | static inline int mmc_card_lenient_fn0(const struct mmc_card *c) | 360 | static inline int mmc_card_lenient_fn0(const struct mmc_card *c) |
164 | { | 361 | { |
@@ -170,9 +367,21 @@ static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c) | |||
170 | return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; | 367 | return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; |
171 | } | 368 | } |
172 | 369 | ||
370 | static inline int mmc_card_disable_cd(const struct mmc_card *c) | ||
371 | { | ||
372 | return c->quirks & MMC_QUIRK_DISABLE_CD; | ||
373 | } | ||
374 | |||
375 | static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c) | ||
376 | { | ||
377 | return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; | ||
378 | } | ||
379 | |||
173 | #define mmc_card_name(c) ((c)->cid.prod_name) | 380 | #define mmc_card_name(c) ((c)->cid.prod_name) |
174 | #define mmc_card_id(c) (dev_name(&(c)->dev)) | 381 | #define mmc_card_id(c) (dev_name(&(c)->dev)) |
175 | 382 | ||
383 | #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev) | ||
384 | |||
176 | #define mmc_list_to_card(l) container_of(l, struct mmc_card, node) | 385 | #define mmc_list_to_card(l) container_of(l, struct mmc_card, node) |
177 | #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev) | 386 | #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev) |
178 | #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d) | 387 | #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d) |
@@ -191,4 +400,7 @@ struct mmc_driver { | |||
191 | extern int mmc_register_driver(struct mmc_driver *); | 400 | extern int mmc_register_driver(struct mmc_driver *); |
192 | extern void mmc_unregister_driver(struct mmc_driver *); | 401 | extern void mmc_unregister_driver(struct mmc_driver *); |
193 | 402 | ||
403 | extern void mmc_fixup_device(struct mmc_card *card, | ||
404 | const struct mmc_fixup *table); | ||
405 | |||
194 | #endif | 406 | #endif |