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 #define MMC_CARD_SDUC (1<<6) /* card is SDUC */ 27 28 #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) 29 #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) 30 #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) 31 #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) 32 #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) 33 #define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED) 34 #define mmc_card_ult_capacity(c) ((c)->state & MMC_CARD_SDUC) 35 36 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 37 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) 38 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) 39 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 40 #define mmc_card_set_ult_capacity(c) ((c)->state |= MMC_CARD_SDUC) 41 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) 42 #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED) 43 #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED) 44 45 /* 46 * The world is not perfect and supplies us with broken mmc/sdio devices. 47 * For at least some of these bugs we need a work-around. 48 */ 49 struct mmc_fixup { 50 /* CID-specific fields. */ 51 const char *name; 52 53 /* Valid revision range */ 54 u64 rev_start, rev_end; 55 56 unsigned int manfid; 57 unsigned short oemid; 58 59 /* Manufacturing date */ 60 unsigned short year; 61 unsigned char month; 62 63 /* SDIO-specific fields. You can use SDIO_ANY_ID here of course */ 64 u16 cis_vendor, cis_device; 65 66 /* for MMC cards */ 67 unsigned int ext_csd_rev; 68 69 /* Match against functions declared in device tree */ 70 const char *of_compatible; 71 72 void (*vendor_fixup)(struct mmc_card *card, int data); 73 int data; 74 }; 75 76 #define CID_MANFID_ANY (-1u) 77 #define CID_OEMID_ANY ((unsigned short) -1) 78 #define CID_YEAR_ANY ((unsigned short) -1) 79 #define CID_MONTH_ANY ((unsigned char) -1) 80 #define CID_NAME_ANY (NULL) 81 82 #define EXT_CSD_REV_ANY (-1u) 83 84 #define CID_MANFID_SANDISK 0x2 85 #define CID_MANFID_SANDISK_SD 0x3 86 #define CID_MANFID_ATP 0x9 87 #define CID_MANFID_TOSHIBA 0x11 88 #define CID_MANFID_GIGASTONE 0x12 89 #define CID_MANFID_MICRON 0x13 90 #define CID_MANFID_SAMSUNG 0x15 91 #define CID_MANFID_APACER 0x27 92 #define CID_MANFID_KINGSTON 0x70 93 #define CID_MANFID_HYNIX 0x90 94 #define CID_MANFID_KINGSTON_SD 0x9F 95 #define CID_MANFID_NUMONYX 0xFE 96 97 #define END_FIXUP { NULL } 98 99 #define _FIXUP_EXT(_name, _manfid, _oemid, _year, _month, \ 100 _rev_start, _rev_end, \ 101 _cis_vendor, _cis_device, \ 102 _fixup, _data, _ext_csd_rev) \ 103 { \ 104 .name = (_name), \ 105 .manfid = (_manfid), \ 106 .oemid = (_oemid), \ 107 .year = (_year), \ 108 .month = (_month), \ 109 .rev_start = (_rev_start), \ 110 .rev_end = (_rev_end), \ 111 .cis_vendor = (_cis_vendor), \ 112 .cis_device = (_cis_device), \ 113 .vendor_fixup = (_fixup), \ 114 .data = (_data), \ 115 .ext_csd_rev = (_ext_csd_rev), \ 116 } 117 118 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \ 119 _fixup, _data, _ext_csd_rev) \ 120 _FIXUP_EXT(_name, _manfid, _oemid, CID_YEAR_ANY, CID_MONTH_ANY, \ 121 _rev_start, _rev_end, \ 122 SDIO_ANY_ID, SDIO_ANY_ID, \ 123 _fixup, _data, _ext_csd_rev) \ 124 125 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \ 126 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 127 EXT_CSD_REV_ANY) 128 129 #define MMC_FIXUP_EXT_CSD_REV(_name, _manfid, _oemid, _fixup, _data, \ 130 _ext_csd_rev) \ 131 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 132 _ext_csd_rev) 133 134 #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \ 135 _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, CID_OEMID_ANY, \ 136 CID_YEAR_ANY, CID_MONTH_ANY, \ 137 0, -1ull, \ 138 _vendor, _device, \ 139 _fixup, _data, EXT_CSD_REV_ANY) \ 140 141 #define SDIO_FIXUP_COMPATIBLE(_compatible, _fixup, _data) \ 142 { \ 143 .name = CID_NAME_ANY, \ 144 .manfid = CID_MANFID_ANY, \ 145 .oemid = CID_OEMID_ANY, \ 146 .rev_start = 0, \ 147 .rev_end = -1ull, \ 148 .cis_vendor = SDIO_ANY_ID, \ 149 .cis_device = SDIO_ANY_ID, \ 150 .vendor_fixup = (_fixup), \ 151 .data = (_data), \ 152 .ext_csd_rev = EXT_CSD_REV_ANY, \ 153 .of_compatible = _compatible, \ 154 } 155 156 #define cid_rev(hwrev, fwrev, year, month) \ 157 (((u64) hwrev) << 40 | \ 158 ((u64) fwrev) << 32 | \ 159 ((u64) year) << 16 | \ 160 ((u64) month)) 161 162 #define cid_rev_card(card) \ 163 cid_rev(card->cid.hwrev, \ 164 card->cid.fwrev, \ 165 card->cid.year, \ 166 card->cid.month) 167 168 /* 169 * Unconditionally quirk add/remove. 170 */ 171 static inline void __maybe_unused add_quirk(struct mmc_card *card, int data) 172 { 173 card->quirks |= data; 174 } 175 176 static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) 177 { 178 card->quirks &= ~data; 179 } 180 181 static inline void __maybe_unused add_limit_rate_quirk(struct mmc_card *card, 182 int data) 183 { 184 card->quirk_max_rate = data; 185 } 186 187 static inline void __maybe_unused wl1251_quirk(struct mmc_card *card, 188 int data) 189 { 190 /* 191 * We have TI wl1251 attached to this mmc. Pass this 192 * information to the SDIO core because it can't be 193 * probed by normal methods. 194 */ 195 196 dev_info(card->host->parent, "found wl1251\n"); 197 card->quirks |= MMC_QUIRK_NONSTD_SDIO; 198 card->cccr.wide_bus = 1; 199 card->cis.vendor = 0x104c; 200 card->cis.device = 0x9066; 201 card->cis.blksize = 512; 202 card->cis.max_dtr = 24000000; 203 } 204 205 /* 206 * Quirk add/remove for MMC products. 207 */ 208 static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data) 209 { 210 if (mmc_card_mmc(card)) 211 card->quirks |= data; 212 } 213 214 static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card, 215 int data) 216 { 217 if (mmc_card_mmc(card)) 218 card->quirks &= ~data; 219 } 220 221 /* 222 * Quirk add/remove for SD products. 223 */ 224 static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data) 225 { 226 if (mmc_card_sd(card)) 227 card->quirks |= data; 228 } 229 230 static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card, 231 int data) 232 { 233 if (mmc_card_sd(card)) 234 card->quirks &= ~data; 235 } 236 237 static inline int mmc_card_lenient_fn0(const struct mmc_card *c) 238 { 239 return c->quirks & MMC_QUIRK_LENIENT_FN0; 240 } 241 242 static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c) 243 { 244 return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; 245 } 246 247 static inline int mmc_card_disable_cd(const struct mmc_card *c) 248 { 249 return c->quirks & MMC_QUIRK_DISABLE_CD; 250 } 251 252 static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c) 253 { 254 return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; 255 } 256 257 static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c) 258 { 259 return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512; 260 } 261 262 static inline int mmc_card_long_read_time(const struct mmc_card *c) 263 { 264 return c->quirks & MMC_QUIRK_LONG_READ_TIME; 265 } 266 267 static inline int mmc_card_broken_irq_polling(const struct mmc_card *c) 268 { 269 return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING; 270 } 271 272 static inline int mmc_card_broken_hpi(const struct mmc_card *c) 273 { 274 return c->quirks & MMC_QUIRK_BROKEN_HPI; 275 } 276 277 static inline int mmc_card_broken_sd_discard(const struct mmc_card *c) 278 { 279 return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD; 280 } 281 282 static inline int mmc_card_broken_sd_cache(const struct mmc_card *c) 283 { 284 return c->quirks & MMC_QUIRK_BROKEN_SD_CACHE; 285 } 286 287 static inline int mmc_card_broken_cache_flush(const struct mmc_card *c) 288 { 289 return c->quirks & MMC_QUIRK_BROKEN_CACHE_FLUSH; 290 } 291 292 static inline int mmc_card_broken_sd_poweroff_notify(const struct mmc_card *c) 293 { 294 return c->quirks & MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY; 295 } 296 297 #endif 298