Linux 4.6-rc6
[cris-mirror.git] / include / linux / mmc / card.h
blobeb0151bac50c1fd796f479d017bc3c3d7017c9e9
1 /*
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.
9 */
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>
17 struct mmc_cid {
18 unsigned int manfid;
19 char prod_name[8];
20 unsigned char prv;
21 unsigned int serial;
22 unsigned short oemid;
23 unsigned short year;
24 unsigned char hwrev;
25 unsigned char fwrev;
26 unsigned char month;
29 struct mmc_csd {
30 unsigned char structure;
31 unsigned char mmca_vsn;
32 unsigned short cmdclass;
33 unsigned short tacc_clks;
34 unsigned int tacc_ns;
35 unsigned int c_size;
36 unsigned int r2w_factor;
37 unsigned int max_dtr;
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,
43 read_misalign:1,
44 write_partial:1,
45 write_misalign:1,
46 dsr_imp:1;
49 struct mmc_ext_csd {
50 u8 rev;
51 u8 erase_group_def;
52 u8 sec_feature_support;
53 u8 rel_sectors;
54 u8 rel_param;
55 u8 part_config;
56 u8 cache_ctrl;
57 u8 rst_n_function;
58 u8 max_packed_writes;
59 u8 max_packed_reads;
60 u8 packed_event_en;
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
72 unsigned int sectors;
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 */
126 struct sd_scr {
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)
132 unsigned char cmds;
133 #define SD_SCR_CMD20_SUPPORT (1<<0)
134 #define SD_SCR_CMD23_SUPPORT (1<<1)
137 struct sd_ssr {
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)
184 struct sdio_cccr {
185 unsigned int sdio_vsn;
186 unsigned int sd_vsn;
187 unsigned int multi_block:1,
188 low_speed:1,
189 wide_bus:1,
190 high_power:1,
191 high_speed:1,
192 disable_cd:1;
195 struct sdio_cis {
196 unsigned short vendor;
197 unsigned short device;
198 unsigned short blksize;
199 unsigned int max_dtr;
202 struct mmc_host;
203 struct mmc_ios;
204 struct sdio_func;
205 struct sdio_func_tuple;
207 #define SDIO_MAX_FUNCS 7
209 enum mmc_blk_status {
210 MMC_BLK_SUCCESS = 0,
211 MMC_BLK_PARTIAL,
212 MMC_BLK_CMD_ERR,
213 MMC_BLK_RETRY,
214 MMC_BLK_ABORT,
215 MMC_BLK_DATA_ERR,
216 MMC_BLK_ECC_ERR,
217 MMC_BLK_NOMEDIUM,
218 MMC_BLK_NEW_REQUEST,
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
233 struct mmc_part {
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)
246 * MMC device
248 struct mmc_card {
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 */
269 /* for byte mode */
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 */
277 /* byte mode */
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,
323 int area_type)
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;
330 card->nr_parts++;
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.
343 struct mmc_fixup {
344 /* CID-specific fields. */
345 const char *name;
347 /* Valid revision range */
348 u64 rev_start, rev_end;
350 unsigned int manfid;
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);
357 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, \
368 _fixup, _data) \
370 .name = (_name), \
371 .manfid = (_manfid), \
372 .oemid = (_oemid), \
373 .rev_start = (_rev_start), \
374 .rev_end = (_rev_end), \
375 .cis_vendor = (_cis_vendor), \
376 .cis_device = (_cis_device), \
377 .vendor_fixup = (_fixup), \
378 .data = (_data), \
381 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \
382 _fixup, _data) \
383 _FIXUP_EXT(_name, _manfid, \
384 _oemid, _rev_start, _rev_end, \
385 SDIO_ANY_ID, SDIO_ANY_ID, \
386 _fixup, _data) \
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, \
394 _vendor, _device, \
395 _fixup, _data) \
397 #define cid_rev(hwrev, fwrev, year, month) \
398 (((u64) hwrev) << 40 | \
399 ((u64) fwrev) << 32 | \
400 ((u64) year) << 16 | \
401 ((u64) month))
403 #define cid_rev_card(card) \
404 cid_rev(card->cid.hwrev, \
405 card->cid.fwrev, \
406 card->cid.year, \
407 card->cid.month)
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,
456 int data)
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,
473 int data)
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...)
522 struct mmc_driver {
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 */