xref: /openbmc/linux/drivers/mmc/core/card.h (revision a9a08845)
1 /*
2  * Private header for the mmc subsystem
3  *
4  * Copyright (C) 2016 Linaro Ltd
5  *
6  * Author: Ulf Hansson <ulf.hansson@linaro.org>
7  *
8  * License terms: GNU General Public License (GPL) version 2
9  */
10 
11 #ifndef _MMC_CORE_CARD_H
12 #define _MMC_CORE_CARD_H
13 
14 #include <linux/mmc/card.h>
15 
16 #define mmc_card_name(c)	((c)->cid.prod_name)
17 #define mmc_card_id(c)		(dev_name(&(c)->dev))
18 #define mmc_dev_to_card(d)	container_of(d, struct mmc_card, dev)
19 
20 /* Card states */
21 #define MMC_STATE_PRESENT	(1<<0)		/* present in sysfs */
22 #define MMC_STATE_READONLY	(1<<1)		/* card is read-only */
23 #define MMC_STATE_BLOCKADDR	(1<<2)		/* card uses block-addressing */
24 #define MMC_CARD_SDXC		(1<<3)		/* card is SDXC */
25 #define MMC_CARD_REMOVED	(1<<4)		/* card has been removed */
26 #define MMC_STATE_DOING_BKOPS	(1<<5)		/* card is doing BKOPS */
27 #define MMC_STATE_SUSPENDED	(1<<6)		/* card is suspended */
28 
29 #define mmc_card_present(c)	((c)->state & MMC_STATE_PRESENT)
30 #define mmc_card_readonly(c)	((c)->state & MMC_STATE_READONLY)
31 #define mmc_card_blockaddr(c)	((c)->state & MMC_STATE_BLOCKADDR)
32 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC)
33 #define mmc_card_removed(c)	((c) && ((c)->state & MMC_CARD_REMOVED))
34 #define mmc_card_doing_bkops(c)	((c)->state & MMC_STATE_DOING_BKOPS)
35 #define mmc_card_suspended(c)	((c)->state & MMC_STATE_SUSPENDED)
36 
37 #define mmc_card_set_present(c)	((c)->state |= MMC_STATE_PRESENT)
38 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
39 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR)
40 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC)
41 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED)
42 #define mmc_card_set_doing_bkops(c)	((c)->state |= MMC_STATE_DOING_BKOPS)
43 #define mmc_card_clr_doing_bkops(c)	((c)->state &= ~MMC_STATE_DOING_BKOPS)
44 #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED)
45 #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED)
46 
47 /*
48  * The world is not perfect and supplies us with broken mmc/sdio devices.
49  * For at least some of these bugs we need a work-around.
50  */
51 struct mmc_fixup {
52 	/* CID-specific fields. */
53 	const char *name;
54 
55 	/* Valid revision range */
56 	u64 rev_start, rev_end;
57 
58 	unsigned int manfid;
59 	unsigned short oemid;
60 
61 	/* SDIO-specific fields. You can use SDIO_ANY_ID here of course */
62 	u16 cis_vendor, cis_device;
63 
64 	/* for MMC cards */
65 	unsigned int ext_csd_rev;
66 
67 	void (*vendor_fixup)(struct mmc_card *card, int data);
68 	int data;
69 };
70 
71 #define CID_MANFID_ANY (-1u)
72 #define CID_OEMID_ANY ((unsigned short) -1)
73 #define CID_NAME_ANY (NULL)
74 
75 #define EXT_CSD_REV_ANY (-1u)
76 
77 #define CID_MANFID_SANDISK      0x2
78 #define CID_MANFID_ATP          0x9
79 #define CID_MANFID_TOSHIBA      0x11
80 #define CID_MANFID_MICRON       0x13
81 #define CID_MANFID_SAMSUNG      0x15
82 #define CID_MANFID_APACER       0x27
83 #define CID_MANFID_KINGSTON     0x70
84 #define CID_MANFID_HYNIX	0x90
85 
86 #define END_FIXUP { NULL }
87 
88 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end,	\
89 		   _cis_vendor, _cis_device,				\
90 		   _fixup, _data, _ext_csd_rev)				\
91 	{						\
92 		.name = (_name),			\
93 		.manfid = (_manfid),			\
94 		.oemid = (_oemid),			\
95 		.rev_start = (_rev_start),		\
96 		.rev_end = (_rev_end),			\
97 		.cis_vendor = (_cis_vendor),		\
98 		.cis_device = (_cis_device),		\
99 		.vendor_fixup = (_fixup),		\
100 		.data = (_data),			\
101 		.ext_csd_rev = (_ext_csd_rev),		\
102 	}
103 
104 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end,	\
105 		      _fixup, _data, _ext_csd_rev)			\
106 	_FIXUP_EXT(_name, _manfid,					\
107 		   _oemid, _rev_start, _rev_end,			\
108 		   SDIO_ANY_ID, SDIO_ANY_ID,				\
109 		   _fixup, _data, _ext_csd_rev)				\
110 
111 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \
112 	MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data,	\
113 		      EXT_CSD_REV_ANY)
114 
115 #define MMC_FIXUP_EXT_CSD_REV(_name, _manfid, _oemid, _fixup, _data,	\
116 			      _ext_csd_rev)				\
117 	MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data,	\
118 		      _ext_csd_rev)
119 
120 #define SDIO_FIXUP(_vendor, _device, _fixup, _data)			\
121 	_FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY,			\
122 		    CID_OEMID_ANY, 0, -1ull,				\
123 		   _vendor, _device,					\
124 		   _fixup, _data, EXT_CSD_REV_ANY)			\
125 
126 #define cid_rev(hwrev, fwrev, year, month)	\
127 	(((u64) hwrev) << 40 |			\
128 	 ((u64) fwrev) << 32 |			\
129 	 ((u64) year) << 16 |			\
130 	 ((u64) month))
131 
132 #define cid_rev_card(card)			\
133 	cid_rev(card->cid.hwrev,		\
134 		    card->cid.fwrev,		\
135 		    card->cid.year,		\
136 		    card->cid.month)
137 
138 /*
139  * Unconditionally quirk add/remove.
140  */
141 static inline void __maybe_unused add_quirk(struct mmc_card *card, int data)
142 {
143 	card->quirks |= data;
144 }
145 
146 static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data)
147 {
148 	card->quirks &= ~data;
149 }
150 
151 /*
152  * Quirk add/remove for MMC products.
153  */
154 static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data)
155 {
156 	if (mmc_card_mmc(card))
157 		card->quirks |= data;
158 }
159 
160 static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card,
161 						   int data)
162 {
163 	if (mmc_card_mmc(card))
164 		card->quirks &= ~data;
165 }
166 
167 /*
168  * Quirk add/remove for SD products.
169  */
170 static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data)
171 {
172 	if (mmc_card_sd(card))
173 		card->quirks |= data;
174 }
175 
176 static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card,
177 						   int data)
178 {
179 	if (mmc_card_sd(card))
180 		card->quirks &= ~data;
181 }
182 
183 static inline int mmc_card_lenient_fn0(const struct mmc_card *c)
184 {
185 	return c->quirks & MMC_QUIRK_LENIENT_FN0;
186 }
187 
188 static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c)
189 {
190 	return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
191 }
192 
193 static inline int mmc_card_disable_cd(const struct mmc_card *c)
194 {
195 	return c->quirks & MMC_QUIRK_DISABLE_CD;
196 }
197 
198 static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c)
199 {
200 	return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF;
201 }
202 
203 static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c)
204 {
205 	return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512;
206 }
207 
208 static inline int mmc_card_long_read_time(const struct mmc_card *c)
209 {
210 	return c->quirks & MMC_QUIRK_LONG_READ_TIME;
211 }
212 
213 static inline int mmc_card_broken_irq_polling(const struct mmc_card *c)
214 {
215 	return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING;
216 }
217 
218 static inline int mmc_card_broken_hpi(const struct mmc_card *c)
219 {
220 	return c->quirks & MMC_QUIRK_BROKEN_HPI;
221 }
222 
223 #endif
224