include: replace linux/module.h with "struct module" wherever possible
[linux-2.6/next.git] / include / linux / mmc / card.h
blobb460fc2af8a1228d7f84dae2c1a2de56e181c4f5
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/mmc/core.h>
14 #include <linux/mod_devicetable.h>
16 struct mmc_cid {
17 unsigned int manfid;
18 char prod_name[8];
19 unsigned int serial;
20 unsigned short oemid;
21 unsigned short year;
22 unsigned char hwrev;
23 unsigned char fwrev;
24 unsigned char month;
27 struct mmc_csd {
28 unsigned char structure;
29 unsigned char mmca_vsn;
30 unsigned short cmdclass;
31 unsigned short tacc_clks;
32 unsigned int tacc_ns;
33 unsigned int c_size;
34 unsigned int r2w_factor;
35 unsigned int max_dtr;
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,
41 read_misalign:1,
42 write_partial:1,
43 write_misalign:1;
46 struct mmc_ext_csd {
47 u8 rev;
48 u8 erase_group_def;
49 u8 sec_feature_support;
50 u8 rel_sectors;
51 u8 rel_param;
52 u8 part_config;
53 unsigned int part_time; /* Units: ms */
54 unsigned int sa_timeout; /* Units: 100ns */
55 unsigned int hs_max_dtr;
56 unsigned int sectors;
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 */
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 */
82 struct sd_scr {
83 unsigned char sda_vsn;
84 unsigned char sda_spec3;
85 unsigned char bus_widths;
86 #define SD_SCR_BUS_WIDTH_1 (1<<0)
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)
93 struct sd_ssr {
94 unsigned int au; /* In sectors */
95 unsigned int erase_timeout; /* In milliseconds */
96 unsigned int erase_offset; /* In milliseconds */
99 struct sd_switch_caps {
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
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
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)
136 struct sdio_cccr {
137 unsigned int sdio_vsn;
138 unsigned int sd_vsn;
139 unsigned int multi_block:1,
140 low_speed:1,
141 wide_bus:1,
142 high_power:1,
143 high_speed:1,
144 disable_cd:1;
147 struct sdio_cis {
148 unsigned short vendor;
149 unsigned short device;
150 unsigned short blksize;
151 unsigned int max_dtr;
154 struct mmc_host;
155 struct sdio_func;
156 struct sdio_func_tuple;
158 #define SDIO_MAX_FUNCS 7
161 * MMC device
163 struct mmc_card {
164 struct mmc_host *host; /* the host this device belongs to */
165 struct device dev; /* the device */
166 unsigned int rca; /* relative card address of device */
167 unsigned int type; /* card type */
168 #define MMC_TYPE_MMC 0 /* MMC card */
169 #define MMC_TYPE_SD 1 /* SD card */
170 #define MMC_TYPE_SDIO 2 /* SDIO card */
171 #define MMC_TYPE_SD_COMBO 3 /* SD combo (IO+mem) card */
172 unsigned int state; /* (our) card state */
173 #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
174 #define MMC_STATE_READONLY (1<<1) /* card is read-only */
175 #define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
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 */
180 unsigned int quirks; /* card quirks */
181 #define MMC_QUIRK_LENIENT_FN0 (1<<0) /* allow SDIO FN0 writes outside of the VS CCCR range */
182 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1) /* use func->cur_blksize */
183 /* for byte mode */
184 #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
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 */
192 unsigned int erase_size; /* erase size in sectors */
193 unsigned int erase_shift; /* if erase unit is power 2 */
194 unsigned int pref_erase; /* in sectors */
195 u8 erased_byte; /* value of erased bytes */
197 u32 raw_cid[4]; /* raw card CID */
198 u32 raw_csd[4]; /* raw card CSD */
199 u32 raw_scr[2]; /* raw card SCR */
200 struct mmc_cid cid; /* card identification */
201 struct mmc_csd csd; /* card specific */
202 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
203 struct sd_scr scr; /* extra SD information */
204 struct sd_ssr ssr; /* yet more SD information */
205 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
207 unsigned int sdio_funcs; /* number of SDIO functions */
208 struct sdio_cccr cccr; /* common card info */
209 struct sdio_cis cis; /* common tuple info */
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 */
212 unsigned num_info; /* number of info strings */
213 const char **info; /* info strings */
214 struct sdio_func_tuple *tuples; /* unknown common tuples */
216 unsigned int sd_bus_speed; /* Bus Speed Mode set for the card */
218 struct dentry *debugfs_root;
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.
226 struct mmc_fixup {
227 /* CID-specific fields. */
228 const char *name;
230 /* Valid revision range */
231 u64 rev_start, rev_end;
233 unsigned int manfid;
234 unsigned short oemid;
236 /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
237 u16 cis_vendor, cis_device;
239 void (*vendor_fixup)(struct mmc_card *card, int data);
240 int data;
243 #define CID_MANFID_ANY (-1u)
244 #define CID_OEMID_ANY ((unsigned short) -1)
245 #define CID_NAME_ANY (NULL)
247 #define END_FIXUP { 0 }
249 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \
250 _cis_vendor, _cis_device, \
251 _fixup, _data) \
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), \
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) \
271 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
272 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
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) \
280 #define cid_rev(hwrev, fwrev, year, month) \
281 (((u64) hwrev) << 40 | \
282 ((u64) fwrev) << 32 | \
283 ((u64) year) << 16 | \
284 ((u64) month))
286 #define cid_rev_card(card) \
287 cid_rev(card->cid.hwrev, \
288 card->cid.fwrev, \
289 card->cid.year, \
290 card->cid.month)
293 * Unconditionally quirk add/remove.
296 static inline void __maybe_unused add_quirk(struct mmc_card *card, int data)
298 card->quirks |= data;
301 static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
303 card->quirks &= ~data;
306 #define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
307 #define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
308 #define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
310 #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
311 #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
312 #define mmc_card_highspeed(c) ((c)->state & MMC_STATE_HIGHSPEED)
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)
318 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
319 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
320 #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
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)
327 * Quirk add/remove for MMC products.
330 static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data)
332 if (mmc_card_mmc(card))
333 card->quirks |= data;
336 static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card,
337 int data)
339 if (mmc_card_mmc(card))
340 card->quirks &= ~data;
344 * Quirk add/remove for SD products.
347 static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data)
349 if (mmc_card_sd(card))
350 card->quirks |= data;
353 static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card,
354 int data)
356 if (mmc_card_sd(card))
357 card->quirks &= ~data;
360 static inline int mmc_card_lenient_fn0(const struct mmc_card *c)
362 return c->quirks & MMC_QUIRK_LENIENT_FN0;
365 static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c)
367 return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
370 static inline int mmc_card_disable_cd(const struct mmc_card *c)
372 return c->quirks & MMC_QUIRK_DISABLE_CD;
375 static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
377 return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
380 #define mmc_card_name(c) ((c)->cid.prod_name)
381 #define mmc_card_id(c) (dev_name(&(c)->dev))
383 #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
385 #define mmc_list_to_card(l) container_of(l, struct mmc_card, node)
386 #define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev)
387 #define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d)
390 * MMC device driver (e.g., Flash card, I/O card...)
392 struct mmc_driver {
393 struct device_driver drv;
394 int (*probe)(struct mmc_card *);
395 void (*remove)(struct mmc_card *);
396 int (*suspend)(struct mmc_card *, pm_message_t);
397 int (*resume)(struct mmc_card *);
400 extern int mmc_register_driver(struct mmc_driver *);
401 extern void mmc_unregister_driver(struct mmc_driver *);
403 extern void mmc_fixup_device(struct mmc_card *card,
404 const struct mmc_fixup *table);
406 #endif /* LINUX_MMC_CARD_H */