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