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