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