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