]> Pileus Git - ~andy/linux/blob - include/linux/mmc/card.h
mmc: MMC boot partitions support.
[~andy/linux] / include / linux / mmc / card.h
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/mmc/core.h>
14 #include <linux/mod_devicetable.h>
15
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;
25 };
26
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            r2w_factor;
34         unsigned int            max_dtr;
35         unsigned int            erase_size;             /* In sectors */
36         unsigned int            read_blkbits;
37         unsigned int            write_blkbits;
38         unsigned int            capacity;
39         unsigned int            read_partial:1,
40                                 read_misalign:1,
41                                 write_partial:1,
42                                 write_misalign:1;
43 };
44
45 struct mmc_ext_csd {
46         u8                      rev;
47         u8                      erase_group_def;
48         u8                      sec_feature_support;
49         u8                      rel_sectors;
50         u8                      rel_param;
51         u8                      part_config;
52         unsigned int            part_time;              /* Units: ms */
53         unsigned int            sa_timeout;             /* Units: 100ns */
54         unsigned int            hs_max_dtr;
55         unsigned int            sectors;
56         unsigned int            card_type;
57         unsigned int            hc_erase_size;          /* In sectors */
58         unsigned int            hc_erase_timeout;       /* In milliseconds */
59         unsigned int            sec_trim_mult;  /* Secure trim multiplier  */
60         unsigned int            sec_erase_mult; /* Secure erase multiplier */
61         unsigned int            trim_timeout;           /* In milliseconds */
62         bool                    enhanced_area_en;       /* enable bit */
63         unsigned long long      enhanced_area_offset;   /* Units: Byte */
64         unsigned int            enhanced_area_size;     /* Units: KB */
65         unsigned int            boot_size;              /* in bytes */
66 };
67
68 struct sd_scr {
69         unsigned char           sda_vsn;
70         unsigned char           bus_widths;
71 #define SD_SCR_BUS_WIDTH_1      (1<<0)
72 #define SD_SCR_BUS_WIDTH_4      (1<<2)
73 };
74
75 struct sd_ssr {
76         unsigned int            au;                     /* In sectors */
77         unsigned int            erase_timeout;          /* In milliseconds */
78         unsigned int            erase_offset;           /* In milliseconds */
79 };
80
81 struct sd_switch_caps {
82         unsigned int            hs_max_dtr;
83 };
84
85 struct sdio_cccr {
86         unsigned int            sdio_vsn;
87         unsigned int            sd_vsn;
88         unsigned int            multi_block:1,
89                                 low_speed:1,
90                                 wide_bus:1,
91                                 high_power:1,
92                                 high_speed:1,
93                                 disable_cd:1;
94 };
95
96 struct sdio_cis {
97         unsigned short          vendor;
98         unsigned short          device;
99         unsigned short          blksize;
100         unsigned int            max_dtr;
101 };
102
103 struct mmc_host;
104 struct sdio_func;
105 struct sdio_func_tuple;
106
107 #define SDIO_MAX_FUNCS          7
108
109 /*
110  * MMC device
111  */
112 struct mmc_card {
113         struct mmc_host         *host;          /* the host this device belongs to */
114         struct device           dev;            /* the device */
115         unsigned int            rca;            /* relative card address of device */
116         unsigned int            type;           /* card type */
117 #define MMC_TYPE_MMC            0               /* MMC card */
118 #define MMC_TYPE_SD             1               /* SD card */
119 #define MMC_TYPE_SDIO           2               /* SDIO card */
120 #define MMC_TYPE_SD_COMBO       3               /* SD combo (IO+mem) card */
121         unsigned int            state;          /* (our) card state */
122 #define MMC_STATE_PRESENT       (1<<0)          /* present in sysfs */
123 #define MMC_STATE_READONLY      (1<<1)          /* card is read-only */
124 #define MMC_STATE_HIGHSPEED     (1<<2)          /* card is in high speed mode */
125 #define MMC_STATE_BLOCKADDR     (1<<3)          /* card uses block-addressing */
126 #define MMC_STATE_HIGHSPEED_DDR (1<<4)          /* card is in high speed mode */
127         unsigned int            quirks;         /* card quirks */
128 #define MMC_QUIRK_LENIENT_FN0   (1<<0)          /* allow SDIO FN0 writes outside of the VS CCCR range */
129 #define MMC_QUIRK_BLKSZ_FOR_BYTE_MODE (1<<1)    /* use func->cur_blksize */
130                                                 /* for byte mode */
131 #define MMC_QUIRK_NONSTD_SDIO   (1<<2)          /* non-standard SDIO card attached */
132                                                 /* (missing CIA registers) */
133 #define MMC_QUIRK_BROKEN_CLK_GATING (1<<3)      /* clock gating the sdio bus will make card fail */
134 #define MMC_QUIRK_NONSTD_FUNC_IF (1<<4)         /* SDIO card has nonstd function interfaces */
135 #define MMC_QUIRK_DISABLE_CD    (1<<5)          /* disconnect CD/DAT[3] resistor */
136
137         unsigned int            erase_size;     /* erase size in sectors */
138         unsigned int            erase_shift;    /* if erase unit is power 2 */
139         unsigned int            pref_erase;     /* in sectors */
140         u8                      erased_byte;    /* value of erased bytes */
141
142         u32                     raw_cid[4];     /* raw card CID */
143         u32                     raw_csd[4];     /* raw card CSD */
144         u32                     raw_scr[2];     /* raw card SCR */
145         struct mmc_cid          cid;            /* card identification */
146         struct mmc_csd          csd;            /* card specific */
147         struct mmc_ext_csd      ext_csd;        /* mmc v4 extended card specific */
148         struct sd_scr           scr;            /* extra SD information */
149         struct sd_ssr           ssr;            /* yet more SD information */
150         struct sd_switch_caps   sw_caps;        /* switch (CMD6) caps */
151
152         unsigned int            sdio_funcs;     /* number of SDIO functions */
153         struct sdio_cccr        cccr;           /* common card info */
154         struct sdio_cis         cis;            /* common tuple info */
155         struct sdio_func        *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
156         unsigned                num_info;       /* number of info strings */
157         const char              **info;         /* info strings */
158         struct sdio_func_tuple  *tuples;        /* unknown common tuples */
159
160         struct dentry           *debugfs_root;
161 };
162
163 /*
164  *  The world is not perfect and supplies us with broken mmc/sdio devices.
165  *  For at least some of these bugs we need a work-around.
166  */
167
168 struct mmc_fixup {
169         /* CID-specific fields. */
170         const char *name;
171
172         /* Valid revision range */
173         u64 rev_start, rev_end;
174
175         unsigned int manfid;
176         unsigned short oemid;
177
178         /* SDIO-specfic fields. You can use SDIO_ANY_ID here of course */
179         u16 cis_vendor, cis_device;
180
181         void (*vendor_fixup)(struct mmc_card *card, int data);
182         int data;
183 };
184
185 #define CID_MANFID_ANY (-1u)
186 #define CID_OEMID_ANY ((unsigned short) -1)
187 #define CID_NAME_ANY (NULL)
188
189 #define END_FIXUP { 0 }
190
191 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end,        \
192                    _cis_vendor, _cis_device,                            \
193                    _fixup, _data)                                       \
194         {                                                  \
195                 .name = (_name),                           \
196                 .manfid = (_manfid),                       \
197                 .oemid = (_oemid),                         \
198                 .rev_start = (_rev_start),                 \
199                 .rev_end = (_rev_end),                     \
200                 .cis_vendor = (_cis_vendor),               \
201                 .cis_device = (_cis_device),               \
202                 .vendor_fixup = (_fixup),                  \
203                 .data = (_data),                           \
204          }
205
206 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end,     \
207                       _fixup, _data)                                    \
208         _FIXUP_EXT(_name, _manfid,                                      \
209                    _oemid, _rev_start, _rev_end,                        \
210                    SDIO_ANY_ID, SDIO_ANY_ID,                            \
211                    _fixup, _data)                                       \
212
213 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
214         MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data)
215
216 #define SDIO_FIXUP(_vendor, _device, _fixup, _data)                     \
217         _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY,                        \
218                     CID_OEMID_ANY, 0, -1ull,                            \
219                    _vendor, _device,                                    \
220                    _fixup, _data)                                       \
221
222 #define cid_rev(hwrev, fwrev, year, month)      \
223         (((u64) hwrev) << 40 |                  \
224          ((u64) fwrev) << 32 |                  \
225          ((u64) year) << 16 |                   \
226          ((u64) month))
227
228 #define cid_rev_card(card)                \
229         cid_rev(card->cid.hwrev,          \
230                     card->cid.fwrev,      \
231                     card->cid.year,       \
232                     card->cid.month)
233
234 /*
235  * This hook just adds a quirk unconditionally.
236  */
237 static inline void __maybe_unused add_quirk(struct mmc_card *card, int data)
238 {
239         card->quirks |= data;
240 }
241
242 /*
243  * This hook just removes a quirk unconditionally.
244  */
245 static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
246 {
247         card->quirks &= ~data;
248 }
249
250 #define mmc_card_mmc(c)         ((c)->type == MMC_TYPE_MMC)
251 #define mmc_card_sd(c)          ((c)->type == MMC_TYPE_SD)
252 #define mmc_card_sdio(c)        ((c)->type == MMC_TYPE_SDIO)
253
254 #define mmc_card_present(c)     ((c)->state & MMC_STATE_PRESENT)
255 #define mmc_card_readonly(c)    ((c)->state & MMC_STATE_READONLY)
256 #define mmc_card_highspeed(c)   ((c)->state & MMC_STATE_HIGHSPEED)
257 #define mmc_card_blockaddr(c)   ((c)->state & MMC_STATE_BLOCKADDR)
258 #define mmc_card_ddr_mode(c)    ((c)->state & MMC_STATE_HIGHSPEED_DDR)
259
260 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
261 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
262 #define mmc_card_set_highspeed(c) ((c)->state |= MMC_STATE_HIGHSPEED)
263 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
264 #define mmc_card_set_ddr_mode(c) ((c)->state |= MMC_STATE_HIGHSPEED_DDR)
265
266 static inline int mmc_card_lenient_fn0(const struct mmc_card *c)
267 {
268         return c->quirks & MMC_QUIRK_LENIENT_FN0;
269 }
270
271 static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c)
272 {
273         return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
274 }
275
276 static inline int mmc_card_disable_cd(const struct mmc_card *c)
277 {
278         return c->quirks & MMC_QUIRK_DISABLE_CD;
279 }
280
281 static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
282 {
283         return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
284 }
285
286 #define mmc_card_name(c)        ((c)->cid.prod_name)
287 #define mmc_card_id(c)          (dev_name(&(c)->dev))
288
289 #define mmc_dev_to_card(d)      container_of(d, struct mmc_card, dev)
290
291 #define mmc_list_to_card(l)     container_of(l, struct mmc_card, node)
292 #define mmc_get_drvdata(c)      dev_get_drvdata(&(c)->dev)
293 #define mmc_set_drvdata(c,d)    dev_set_drvdata(&(c)->dev, d)
294
295 /*
296  * MMC device driver (e.g., Flash card, I/O card...)
297  */
298 struct mmc_driver {
299         struct device_driver drv;
300         int (*probe)(struct mmc_card *);
301         void (*remove)(struct mmc_card *);
302         int (*suspend)(struct mmc_card *, pm_message_t);
303         int (*resume)(struct mmc_card *);
304 };
305
306 extern int mmc_register_driver(struct mmc_driver *);
307 extern void mmc_unregister_driver(struct mmc_driver *);
308
309 extern void mmc_fixup_device(struct mmc_card *card,
310                              const struct mmc_fixup *table);
311
312 #endif