1 /* 2 * This file contains work-arounds for many known SD/MMC 3 * and SDIO hardware bugs. 4 * 5 * Copyright (c) 2011 Andrei Warkentin <andreiw@motorola.com> 6 * Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com> 7 * Inspired from pci fixup code: 8 * Copyright (c) 1999 Martin Mares <mj@ucw.cz> 9 * 10 */ 11 12 #include <linux/mmc/sdio_ids.h> 13 14 #include "card.h" 15 16 static const struct mmc_fixup mmc_blk_fixups[] = { 17 #define INAND_CMD38_ARG_EXT_CSD 113 18 #define INAND_CMD38_ARG_ERASE 0x00 19 #define INAND_CMD38_ARG_TRIM 0x01 20 #define INAND_CMD38_ARG_SECERASE 0x80 21 #define INAND_CMD38_ARG_SECTRIM1 0x81 22 #define INAND_CMD38_ARG_SECTRIM2 0x88 23 /* CMD38 argument is passed through EXT_CSD[113] */ 24 MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk, 25 MMC_QUIRK_INAND_CMD38), 26 MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk, 27 MMC_QUIRK_INAND_CMD38), 28 MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk, 29 MMC_QUIRK_INAND_CMD38), 30 MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk, 31 MMC_QUIRK_INAND_CMD38), 32 MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk, 33 MMC_QUIRK_INAND_CMD38), 34 35 /* 36 * Some MMC cards experience performance degradation with CMD23 37 * instead of CMD12-bounded multiblock transfers. For now we'll 38 * black list what's bad... 39 * - Certain Toshiba cards. 40 * 41 * N.B. This doesn't affect SD cards. 42 */ 43 MMC_FIXUP("SDMB-32", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc, 44 MMC_QUIRK_BLK_NO_CMD23), 45 MMC_FIXUP("SDM032", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc, 46 MMC_QUIRK_BLK_NO_CMD23), 47 MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, 48 MMC_QUIRK_BLK_NO_CMD23), 49 MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, 50 MMC_QUIRK_BLK_NO_CMD23), 51 MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, 52 MMC_QUIRK_BLK_NO_CMD23), 53 54 /* 55 * Some MMC cards need longer data read timeout than indicated in CSD. 56 */ 57 MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc, 58 MMC_QUIRK_LONG_READ_TIME), 59 MMC_FIXUP("008GE0", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc, 60 MMC_QUIRK_LONG_READ_TIME), 61 62 /* 63 * On these Samsung MoviNAND parts, performing secure erase or 64 * secure trim can result in unrecoverable corruption due to a 65 * firmware bug. 66 */ 67 MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 68 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 69 MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 70 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 71 MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 72 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 73 MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 74 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 75 MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 76 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 77 MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 78 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 79 MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 80 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 81 MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc, 82 MMC_QUIRK_SEC_ERASE_TRIM_BROKEN), 83 84 /* 85 * On Some Kingston eMMCs, performing trim can result in 86 * unrecoverable data conrruption occasionally due to a firmware bug. 87 */ 88 MMC_FIXUP("V10008", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc, 89 MMC_QUIRK_TRIM_BROKEN), 90 MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc, 91 MMC_QUIRK_TRIM_BROKEN), 92 93 END_FIXUP 94 }; 95 96 static const struct mmc_fixup mmc_ext_csd_fixups[] = { 97 /* 98 * Certain Hynix eMMC 4.41 cards might get broken when HPI feature 99 * is used so disable the HPI feature for such buggy cards. 100 */ 101 MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_HYNIX, 102 0x014a, add_quirk, MMC_QUIRK_BROKEN_HPI, 5), 103 104 END_FIXUP 105 }; 106 107 static const struct mmc_fixup sdio_fixup_methods[] = { 108 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271, 109 add_quirk, MMC_QUIRK_NONSTD_FUNC_IF), 110 111 SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271, 112 add_quirk, MMC_QUIRK_DISABLE_CD), 113 114 SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200, 115 add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512), 116 117 SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0, 118 add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING), 119 120 END_FIXUP 121 }; 122 123 static inline void mmc_fixup_device(struct mmc_card *card, 124 const struct mmc_fixup *table) 125 { 126 const struct mmc_fixup *f; 127 u64 rev = cid_rev_card(card); 128 129 for (f = table; f->vendor_fixup; f++) { 130 if ((f->manfid == CID_MANFID_ANY || 131 f->manfid == card->cid.manfid) && 132 (f->oemid == CID_OEMID_ANY || 133 f->oemid == card->cid.oemid) && 134 (f->name == CID_NAME_ANY || 135 !strncmp(f->name, card->cid.prod_name, 136 sizeof(card->cid.prod_name))) && 137 (f->cis_vendor == card->cis.vendor || 138 f->cis_vendor == (u16) SDIO_ANY_ID) && 139 (f->cis_device == card->cis.device || 140 f->cis_device == (u16) SDIO_ANY_ID) && 141 (f->ext_csd_rev == EXT_CSD_REV_ANY || 142 f->ext_csd_rev == card->ext_csd.rev) && 143 rev >= f->rev_start && rev <= f->rev_end) { 144 dev_dbg(&card->dev, "calling %pf\n", f->vendor_fixup); 145 f->vendor_fixup(card, f->data); 146 } 147 } 148 } 149