1af873fceSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 24facdde1SUlf Hansson /* 34facdde1SUlf Hansson * Private header for the mmc subsystem 44facdde1SUlf Hansson * 54facdde1SUlf Hansson * Copyright (C) 2016 Linaro Ltd 64facdde1SUlf Hansson * 74facdde1SUlf Hansson * Author: Ulf Hansson <ulf.hansson@linaro.org> 84facdde1SUlf Hansson */ 94facdde1SUlf Hansson 104facdde1SUlf Hansson #ifndef _MMC_CORE_CARD_H 114facdde1SUlf Hansson #define _MMC_CORE_CARD_H 124facdde1SUlf Hansson 134facdde1SUlf Hansson #include <linux/mmc/card.h> 144facdde1SUlf Hansson 154facdde1SUlf Hansson #define mmc_card_name(c) ((c)->cid.prod_name) 164facdde1SUlf Hansson #define mmc_card_id(c) (dev_name(&(c)->dev)) 174facdde1SUlf Hansson #define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev) 184facdde1SUlf Hansson 194facdde1SUlf Hansson /* Card states */ 204facdde1SUlf Hansson #define MMC_STATE_PRESENT (1<<0) /* present in sysfs */ 214facdde1SUlf Hansson #define MMC_STATE_READONLY (1<<1) /* card is read-only */ 224facdde1SUlf Hansson #define MMC_STATE_BLOCKADDR (1<<2) /* card uses block-addressing */ 234facdde1SUlf Hansson #define MMC_CARD_SDXC (1<<3) /* card is SDXC */ 244facdde1SUlf Hansson #define MMC_CARD_REMOVED (1<<4) /* card has been removed */ 250c204979SUlf Hansson #define MMC_STATE_SUSPENDED (1<<5) /* card is suspended */ 264facdde1SUlf Hansson 274facdde1SUlf Hansson #define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) 284facdde1SUlf Hansson #define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) 294facdde1SUlf Hansson #define mmc_card_blockaddr(c) ((c)->state & MMC_STATE_BLOCKADDR) 304facdde1SUlf Hansson #define mmc_card_ext_capacity(c) ((c)->state & MMC_CARD_SDXC) 314facdde1SUlf Hansson #define mmc_card_removed(c) ((c) && ((c)->state & MMC_CARD_REMOVED)) 324facdde1SUlf Hansson #define mmc_card_suspended(c) ((c)->state & MMC_STATE_SUSPENDED) 334facdde1SUlf Hansson 344facdde1SUlf Hansson #define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT) 354facdde1SUlf Hansson #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY) 364facdde1SUlf Hansson #define mmc_card_set_blockaddr(c) ((c)->state |= MMC_STATE_BLOCKADDR) 374facdde1SUlf Hansson #define mmc_card_set_ext_capacity(c) ((c)->state |= MMC_CARD_SDXC) 384facdde1SUlf Hansson #define mmc_card_set_removed(c) ((c)->state |= MMC_CARD_REMOVED) 394facdde1SUlf Hansson #define mmc_card_set_suspended(c) ((c)->state |= MMC_STATE_SUSPENDED) 404facdde1SUlf Hansson #define mmc_card_clr_suspended(c) ((c)->state &= ~MMC_STATE_SUSPENDED) 414facdde1SUlf Hansson 424facdde1SUlf Hansson /* 434facdde1SUlf Hansson * The world is not perfect and supplies us with broken mmc/sdio devices. 444facdde1SUlf Hansson * For at least some of these bugs we need a work-around. 454facdde1SUlf Hansson */ 464facdde1SUlf Hansson struct mmc_fixup { 474facdde1SUlf Hansson /* CID-specific fields. */ 484facdde1SUlf Hansson const char *name; 494facdde1SUlf Hansson 504facdde1SUlf Hansson /* Valid revision range */ 514facdde1SUlf Hansson u64 rev_start, rev_end; 524facdde1SUlf Hansson 534facdde1SUlf Hansson unsigned int manfid; 544facdde1SUlf Hansson unsigned short oemid; 554facdde1SUlf Hansson 564facdde1SUlf Hansson /* SDIO-specific fields. You can use SDIO_ANY_ID here of course */ 574facdde1SUlf Hansson u16 cis_vendor, cis_device; 584facdde1SUlf Hansson 594facdde1SUlf Hansson /* for MMC cards */ 604facdde1SUlf Hansson unsigned int ext_csd_rev; 614facdde1SUlf Hansson 62b360b110SJérôme Pouiller /* Match against functions declared in device tree */ 63b360b110SJérôme Pouiller const char *of_compatible; 64b360b110SJérôme Pouiller 654facdde1SUlf Hansson void (*vendor_fixup)(struct mmc_card *card, int data); 664facdde1SUlf Hansson int data; 674facdde1SUlf Hansson }; 684facdde1SUlf Hansson 694facdde1SUlf Hansson #define CID_MANFID_ANY (-1u) 704facdde1SUlf Hansson #define CID_OEMID_ANY ((unsigned short) -1) 714facdde1SUlf Hansson #define CID_NAME_ANY (NULL) 724facdde1SUlf Hansson 734facdde1SUlf Hansson #define EXT_CSD_REV_ANY (-1u) 744facdde1SUlf Hansson 754facdde1SUlf Hansson #define CID_MANFID_SANDISK 0x2 76*07d2872bSAvri Altman #define CID_MANFID_SANDISK_SD 0x3 7791516a2aSChristoph Fritz #define CID_MANFID_ATP 0x9 784facdde1SUlf Hansson #define CID_MANFID_TOSHIBA 0x11 794facdde1SUlf Hansson #define CID_MANFID_MICRON 0x13 804facdde1SUlf Hansson #define CID_MANFID_SAMSUNG 0x15 8191516a2aSChristoph Fritz #define CID_MANFID_APACER 0x27 824facdde1SUlf Hansson #define CID_MANFID_KINGSTON 0x70 834facdde1SUlf Hansson #define CID_MANFID_HYNIX 0x90 84dbe7dc6bSDirk Behme #define CID_MANFID_NUMONYX 0xFE 854facdde1SUlf Hansson 864facdde1SUlf Hansson #define END_FIXUP { NULL } 874facdde1SUlf Hansson 884facdde1SUlf Hansson #define _FIXUP_EXT(_name, _manfid, _oemid, _rev_start, _rev_end, \ 894facdde1SUlf Hansson _cis_vendor, _cis_device, \ 904facdde1SUlf Hansson _fixup, _data, _ext_csd_rev) \ 914facdde1SUlf Hansson { \ 924facdde1SUlf Hansson .name = (_name), \ 934facdde1SUlf Hansson .manfid = (_manfid), \ 944facdde1SUlf Hansson .oemid = (_oemid), \ 954facdde1SUlf Hansson .rev_start = (_rev_start), \ 964facdde1SUlf Hansson .rev_end = (_rev_end), \ 974facdde1SUlf Hansson .cis_vendor = (_cis_vendor), \ 984facdde1SUlf Hansson .cis_device = (_cis_device), \ 994facdde1SUlf Hansson .vendor_fixup = (_fixup), \ 1004facdde1SUlf Hansson .data = (_data), \ 1014facdde1SUlf Hansson .ext_csd_rev = (_ext_csd_rev), \ 1024facdde1SUlf Hansson } 1034facdde1SUlf Hansson 1044facdde1SUlf Hansson #define MMC_FIXUP_REV(_name, _manfid, _oemid, _rev_start, _rev_end, \ 1054facdde1SUlf Hansson _fixup, _data, _ext_csd_rev) \ 1064facdde1SUlf Hansson _FIXUP_EXT(_name, _manfid, \ 1074facdde1SUlf Hansson _oemid, _rev_start, _rev_end, \ 1084facdde1SUlf Hansson SDIO_ANY_ID, SDIO_ANY_ID, \ 1094facdde1SUlf Hansson _fixup, _data, _ext_csd_rev) \ 1104facdde1SUlf Hansson 1114facdde1SUlf Hansson #define MMC_FIXUP(_name, _manfid, _oemid, _fixup, _data) \ 1124facdde1SUlf Hansson MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 1134facdde1SUlf Hansson EXT_CSD_REV_ANY) 1144facdde1SUlf Hansson 1154facdde1SUlf Hansson #define MMC_FIXUP_EXT_CSD_REV(_name, _manfid, _oemid, _fixup, _data, \ 1164facdde1SUlf Hansson _ext_csd_rev) \ 1174facdde1SUlf Hansson MMC_FIXUP_REV(_name, _manfid, _oemid, 0, -1ull, _fixup, _data, \ 1184facdde1SUlf Hansson _ext_csd_rev) 1194facdde1SUlf Hansson 1204facdde1SUlf Hansson #define SDIO_FIXUP(_vendor, _device, _fixup, _data) \ 1214facdde1SUlf Hansson _FIXUP_EXT(CID_NAME_ANY, CID_MANFID_ANY, \ 1224facdde1SUlf Hansson CID_OEMID_ANY, 0, -1ull, \ 1234facdde1SUlf Hansson _vendor, _device, \ 1244facdde1SUlf Hansson _fixup, _data, EXT_CSD_REV_ANY) \ 1254facdde1SUlf Hansson 126818cd405SH. Nikolaus Schaller #define SDIO_FIXUP_COMPATIBLE(_compatible, _fixup, _data) \ 127818cd405SH. Nikolaus Schaller { \ 128818cd405SH. Nikolaus Schaller .name = CID_NAME_ANY, \ 129818cd405SH. Nikolaus Schaller .manfid = CID_MANFID_ANY, \ 130818cd405SH. Nikolaus Schaller .oemid = CID_OEMID_ANY, \ 131818cd405SH. Nikolaus Schaller .rev_start = 0, \ 132818cd405SH. Nikolaus Schaller .rev_end = -1ull, \ 133818cd405SH. Nikolaus Schaller .cis_vendor = SDIO_ANY_ID, \ 134818cd405SH. Nikolaus Schaller .cis_device = SDIO_ANY_ID, \ 135818cd405SH. Nikolaus Schaller .vendor_fixup = (_fixup), \ 136818cd405SH. Nikolaus Schaller .data = (_data), \ 137818cd405SH. Nikolaus Schaller .ext_csd_rev = EXT_CSD_REV_ANY, \ 138818cd405SH. Nikolaus Schaller .of_compatible = _compatible, \ 139818cd405SH. Nikolaus Schaller } 140818cd405SH. Nikolaus Schaller 1414facdde1SUlf Hansson #define cid_rev(hwrev, fwrev, year, month) \ 1424facdde1SUlf Hansson (((u64) hwrev) << 40 | \ 1434facdde1SUlf Hansson ((u64) fwrev) << 32 | \ 1444facdde1SUlf Hansson ((u64) year) << 16 | \ 1454facdde1SUlf Hansson ((u64) month)) 1464facdde1SUlf Hansson 1474facdde1SUlf Hansson #define cid_rev_card(card) \ 1484facdde1SUlf Hansson cid_rev(card->cid.hwrev, \ 1494facdde1SUlf Hansson card->cid.fwrev, \ 1504facdde1SUlf Hansson card->cid.year, \ 1514facdde1SUlf Hansson card->cid.month) 1524facdde1SUlf Hansson 1534facdde1SUlf Hansson /* 1544facdde1SUlf Hansson * Unconditionally quirk add/remove. 1554facdde1SUlf Hansson */ 1564facdde1SUlf Hansson static inline void __maybe_unused add_quirk(struct mmc_card *card, int data) 1574facdde1SUlf Hansson { 1584facdde1SUlf Hansson card->quirks |= data; 1594facdde1SUlf Hansson } 1604facdde1SUlf Hansson 1614facdde1SUlf Hansson static inline void __maybe_unused remove_quirk(struct mmc_card *card, int data) 1624facdde1SUlf Hansson { 1634facdde1SUlf Hansson card->quirks &= ~data; 1644facdde1SUlf Hansson } 1654facdde1SUlf Hansson 166ebc5a1bfSharish_kandiga@mentor.com static inline void __maybe_unused add_limit_rate_quirk(struct mmc_card *card, 167ebc5a1bfSharish_kandiga@mentor.com int data) 168ebc5a1bfSharish_kandiga@mentor.com { 169ebc5a1bfSharish_kandiga@mentor.com card->quirk_max_rate = data; 170ebc5a1bfSharish_kandiga@mentor.com } 171ebc5a1bfSharish_kandiga@mentor.com 172187b1649SH. Nikolaus Schaller static inline void __maybe_unused wl1251_quirk(struct mmc_card *card, 173187b1649SH. Nikolaus Schaller int data) 174187b1649SH. Nikolaus Schaller { 175187b1649SH. Nikolaus Schaller /* 176187b1649SH. Nikolaus Schaller * We have TI wl1251 attached to this mmc. Pass this 177187b1649SH. Nikolaus Schaller * information to the SDIO core because it can't be 178187b1649SH. Nikolaus Schaller * probed by normal methods. 179187b1649SH. Nikolaus Schaller */ 180187b1649SH. Nikolaus Schaller 181187b1649SH. Nikolaus Schaller dev_info(card->host->parent, "found wl1251\n"); 182187b1649SH. Nikolaus Schaller card->quirks |= MMC_QUIRK_NONSTD_SDIO; 183187b1649SH. Nikolaus Schaller card->cccr.wide_bus = 1; 184187b1649SH. Nikolaus Schaller card->cis.vendor = 0x104c; 185187b1649SH. Nikolaus Schaller card->cis.device = 0x9066; 186187b1649SH. Nikolaus Schaller card->cis.blksize = 512; 187187b1649SH. Nikolaus Schaller card->cis.max_dtr = 24000000; 188187b1649SH. Nikolaus Schaller } 189187b1649SH. Nikolaus Schaller 1904facdde1SUlf Hansson /* 1914facdde1SUlf Hansson * Quirk add/remove for MMC products. 1924facdde1SUlf Hansson */ 1934facdde1SUlf Hansson static inline void __maybe_unused add_quirk_mmc(struct mmc_card *card, int data) 1944facdde1SUlf Hansson { 1954facdde1SUlf Hansson if (mmc_card_mmc(card)) 1964facdde1SUlf Hansson card->quirks |= data; 1974facdde1SUlf Hansson } 1984facdde1SUlf Hansson 1994facdde1SUlf Hansson static inline void __maybe_unused remove_quirk_mmc(struct mmc_card *card, 2004facdde1SUlf Hansson int data) 2014facdde1SUlf Hansson { 2024facdde1SUlf Hansson if (mmc_card_mmc(card)) 2034facdde1SUlf Hansson card->quirks &= ~data; 2044facdde1SUlf Hansson } 2054facdde1SUlf Hansson 2064facdde1SUlf Hansson /* 2074facdde1SUlf Hansson * Quirk add/remove for SD products. 2084facdde1SUlf Hansson */ 2094facdde1SUlf Hansson static inline void __maybe_unused add_quirk_sd(struct mmc_card *card, int data) 2104facdde1SUlf Hansson { 2114facdde1SUlf Hansson if (mmc_card_sd(card)) 2124facdde1SUlf Hansson card->quirks |= data; 2134facdde1SUlf Hansson } 2144facdde1SUlf Hansson 2154facdde1SUlf Hansson static inline void __maybe_unused remove_quirk_sd(struct mmc_card *card, 2164facdde1SUlf Hansson int data) 2174facdde1SUlf Hansson { 2184facdde1SUlf Hansson if (mmc_card_sd(card)) 2194facdde1SUlf Hansson card->quirks &= ~data; 2204facdde1SUlf Hansson } 2214facdde1SUlf Hansson 2224facdde1SUlf Hansson static inline int mmc_card_lenient_fn0(const struct mmc_card *c) 2234facdde1SUlf Hansson { 2244facdde1SUlf Hansson return c->quirks & MMC_QUIRK_LENIENT_FN0; 2254facdde1SUlf Hansson } 2264facdde1SUlf Hansson 2274facdde1SUlf Hansson static inline int mmc_blksz_for_byte_mode(const struct mmc_card *c) 2284facdde1SUlf Hansson { 2294facdde1SUlf Hansson return c->quirks & MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; 2304facdde1SUlf Hansson } 2314facdde1SUlf Hansson 2324facdde1SUlf Hansson static inline int mmc_card_disable_cd(const struct mmc_card *c) 2334facdde1SUlf Hansson { 2344facdde1SUlf Hansson return c->quirks & MMC_QUIRK_DISABLE_CD; 2354facdde1SUlf Hansson } 2364facdde1SUlf Hansson 2374facdde1SUlf Hansson static inline int mmc_card_nonstd_func_interface(const struct mmc_card *c) 2384facdde1SUlf Hansson { 2394facdde1SUlf Hansson return c->quirks & MMC_QUIRK_NONSTD_FUNC_IF; 2404facdde1SUlf Hansson } 2414facdde1SUlf Hansson 2424facdde1SUlf Hansson static inline int mmc_card_broken_byte_mode_512(const struct mmc_card *c) 2434facdde1SUlf Hansson { 2444facdde1SUlf Hansson return c->quirks & MMC_QUIRK_BROKEN_BYTE_MODE_512; 2454facdde1SUlf Hansson } 2464facdde1SUlf Hansson 2474facdde1SUlf Hansson static inline int mmc_card_long_read_time(const struct mmc_card *c) 2484facdde1SUlf Hansson { 2494facdde1SUlf Hansson return c->quirks & MMC_QUIRK_LONG_READ_TIME; 2504facdde1SUlf Hansson } 2514facdde1SUlf Hansson 2524facdde1SUlf Hansson static inline int mmc_card_broken_irq_polling(const struct mmc_card *c) 2534facdde1SUlf Hansson { 2544facdde1SUlf Hansson return c->quirks & MMC_QUIRK_BROKEN_IRQ_POLLING; 2554facdde1SUlf Hansson } 2564facdde1SUlf Hansson 2574facdde1SUlf Hansson static inline int mmc_card_broken_hpi(const struct mmc_card *c) 2584facdde1SUlf Hansson { 2594facdde1SUlf Hansson return c->quirks & MMC_QUIRK_BROKEN_HPI; 2604facdde1SUlf Hansson } 2614facdde1SUlf Hansson 262*07d2872bSAvri Altman static inline int mmc_card_broken_sd_discard(const struct mmc_card *c) 263*07d2872bSAvri Altman { 264*07d2872bSAvri Altman return c->quirks & MMC_QUIRK_BROKEN_SD_DISCARD; 265*07d2872bSAvri Altman } 266*07d2872bSAvri Altman 2674facdde1SUlf Hansson #endif 268