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_SUSPENDED (1<<5) /* card is suspended */ 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 35 #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 36 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) 37 #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) 38 #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 39 #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) 40 #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED) 41 #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED) 42 43 /* 44 * The world is not perfect and supplies us with broken mmc/sdio devices. 45 * For at least some of these bugs we need a work-around. 46 */ 47 struct mmc_fixup { 48 /* CID-specific fields. */ 49 const char *name; 50 51 /* Valid revision range */ 52 u64 rev_start, rev_end; 53 54 unsigned int manfid; 55 unsigned short oemid; 56 57 /* SDIO-specific fields. You can use SDIO_ANY_ID here of course */ 58 u16 cis_vendor, cis_device; 59 60 /* for MMC cards */ 61 unsigned int ext_csd_rev; 62 63 void (*vendor_fixup)(struct mmc_card *card, int data); 64 int data; 65 }; 66 67 #define CID_MANFID_ANY (-1u) 68 #define CID_OEMID_ANY ((unsigned short) -1) 69 #define CID_NAME_ANY (NULL) 70 71 #define EXT_CSD_REV_ANY (-1u) 72 73 #define CID_MANFID_SANDISK 0x2 74 #define CID_MANFID_ATP 0x9 75 #define CID_MANFID_TOSHIBA 0x11 76 #define CID_MANFID_MICRON 0x13 77 #define CID_MANFID_SAMSUNG 0x15 78 #define CID_MANFID_APACER 0x27 79 #define CID_MANFID_KINGSTON 0x70 80 #define CID_MANFID_HYNIX 0x90 81 #define CID_MANFID_NUMONYX 0xFE 82 83 #define END_FIXUP { NULL } 84 85 #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \ 86 _cis_vendor, _cis_device, \ 87 _fixup, _data, _ext_csd_rev) \ 88 { \ 89 .name = (_name), \ 90 .manfid = (_manfid), \ 91 .oemid = (_oemid), \ 92 .rev_start = (_rev_start), \ 93 .rev_end = (_rev_end), \ 94 .cis_vendor = (_cis_vendor), \ 95 .cis_device = (_cis_device), \ 96 .vendor_fixup = (_fixup), \ 97 .data = (_data), \ 98 .ext_csd_rev = (_ext_csd_rev), \ 99 } 100 101 #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \ 102 _fixup, _data, _ext_csd_rev) \ 103 _FIXUP_EXT(_name, _manfid, \ 104 _oemid, _rev_start, _rev_end, \ 105 SDIO_ANY_ID, SDIO_ANY_ID, \ 106 _fixup, _data, _ext_csd_rev) \ 107 108 #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \ 109 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 110 EXT_CSD_REV_ANY) 111 112 #define MMC_FIXUP_EXT_CSD_REV(_name, _manfid, _oemid, _fixup, _data, \ 113 _ext_csd_rev) \ 114 MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 115 _ext_csd_rev) 116 117 #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \ 118 _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \ 119 CID_OEMID_ANY, 0, -1ull, \ 120 _vendor, _device, \ 121 _fixup, _data, EXT_CSD_REV_ANY) \ 122 123 #define cid_rev(hwrev, fwrev, year, month) \ 124 (((u64) hwrev) << 40 | \ 125 ((u64) fwrev) << 32 | \ 126 ((u64) year) << 16 | \ 127 ((u64) month)) 128 129 #define cid_rev_card(card) \ 130 cid_rev(card->cid.hwrev, \ 131 card->cid.fwrev, \ 132 card->cid.year, \ 133 card->cid.month) 134 135 /* 136 * Unconditionally quirk add/remove. 137 */ 138 static inline void __maybe_unused add_quirk(struct mmc_card *card, int data) 139 { 140 card->quirks |= data; 141 } 142 143 static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) 144 { 145 card->quirks &= ~data; 146 } 147 148 static inline void __maybe_unused add_limit_rate_quirk(struct mmc_card *card, 149 int data) 150 { 151 card->quirk_max_rate = data; 152 } 153 154 /* 155 * Quirk add/remove for MMC products. 156 */ 157 static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data) 158 { 159 if (mmc_card_mmc(card)) 160 card->quirks |= data; 161 } 162 163 static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card, 164 int data) 165 { 166 if (mmc_card_mmc(card)) 167 card->quirks &= ~data; 168 } 169 170 /* 171 * Quirk add/remove for SD products. 172 */ 173 static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data) 174 { 175 if (mmc_card_sd(card)) 176 card->quirks |= data; 177 } 178 179 static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card, 180 int data) 181 { 182 if (mmc_card_sd(card)) 183 card->quirks &= ~data; 184 } 185 186 static inline int mmc_card_lenient_fn0(const struct mmc_card *c) 187 { 188 return c->quirks & MMC_QUIRK_LENIENT_FN0; 189 } 190 191 static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c) 192 { 193 return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; 194 } 195 196 static inline int mmc_card_disable_cd(const struct mmc_card *c) 197 { 198 return c->quirks & MMC_QUIRK_DISABLE_CD; 199 } 200 201 static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c) 202 { 203 return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; 204 } 205 206 static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c) 207 { 208 return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512; 209 } 210 211 static inline int mmc_card_long_read_time(const struct mmc_card *c) 212 { 213 return c->quirks & MMC_QUIRK_LONG_READ_TIME; 214 } 215 216 static inline int mmc_card_broken_irq_polling(const struct mmc_card *c) 217 { 218 return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING; 219 } 220 221 static inline int mmc_card_broken_hpi(const struct mmc_card *c) 222 { 223 return c->quirks & MMC_QUIRK_BROKEN_HPI; 224 } 225 226 #endif 227