• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  This file contains work-arounds for many known SD/MMC
4  *  and SDIO hardware bugs.
5  *
6  *  Copyright (c) 2011 Andrei Warkentin <andreiw@motorola.com>
7  *  Copyright (c) 2011 Pierre Tardy <tardyp@gmail.com>
8  *  Inspired from pci fixup code:
9  *  Copyright (c) 1999 Martin Mares <mj@ucw.cz>
10  *
11  */
12 
13 #include <linux/mmc/sdio_ids.h>
14 
15 #include "card.h"
16 
17 static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
18 #define INAND_CMD38_ARG_EXT_CSD  113
19 #define INAND_CMD38_ARG_ERASE    0x00
20 #define INAND_CMD38_ARG_TRIM     0x01
21 #define INAND_CMD38_ARG_SECERASE 0x80
22 #define INAND_CMD38_ARG_SECTRIM1 0x81
23 #define INAND_CMD38_ARG_SECTRIM2 0x88
24 	/* CMD38 argument is passed through EXT_CSD[113] */
25 	MMC_FIXUP("SEM02G", CID_MANFID_SANDISK, 0x100, add_quirk,
26 		  MMC_QUIRK_INAND_CMD38),
27 	MMC_FIXUP("SEM04G", CID_MANFID_SANDISK, 0x100, add_quirk,
28 		  MMC_QUIRK_INAND_CMD38),
29 	MMC_FIXUP("SEM08G", CID_MANFID_SANDISK, 0x100, add_quirk,
30 		  MMC_QUIRK_INAND_CMD38),
31 	MMC_FIXUP("SEM16G", CID_MANFID_SANDISK, 0x100, add_quirk,
32 		  MMC_QUIRK_INAND_CMD38),
33 	MMC_FIXUP("SEM32G", CID_MANFID_SANDISK, 0x100, add_quirk,
34 		  MMC_QUIRK_INAND_CMD38),
35 
36 	/*
37 	 * Some MMC cards experience performance degradation with CMD23
38 	 * instead of CMD12-bounded multiblock transfers. For now we'll
39 	 * black list what's bad...
40 	 * - Certain Toshiba cards.
41 	 *
42 	 * N.B. This doesn't affect SD cards.
43 	 */
44 	MMC_FIXUP("SDMB-32", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc,
45 		  MMC_QUIRK_BLK_NO_CMD23),
46 	MMC_FIXUP("SDM032", CID_MANFID_SANDISK, CID_OEMID_ANY, add_quirk_mmc,
47 		  MMC_QUIRK_BLK_NO_CMD23),
48 	MMC_FIXUP("MMC08G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
49 		  MMC_QUIRK_BLK_NO_CMD23),
50 	MMC_FIXUP("MMC16G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
51 		  MMC_QUIRK_BLK_NO_CMD23),
52 	MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
53 		  MMC_QUIRK_BLK_NO_CMD23),
54 
55 	/*
56 	 * Some SD cards lockup while using CMD23 multiblock transfers.
57 	 */
58 	MMC_FIXUP("AF SD", CID_MANFID_ATP, CID_OEMID_ANY, add_quirk_sd,
59 		  MMC_QUIRK_BLK_NO_CMD23),
60 	MMC_FIXUP("APUSD", CID_MANFID_APACER, 0x5048, add_quirk_sd,
61 		  MMC_QUIRK_BLK_NO_CMD23),
62 
63 	/*
64 	 * Some MMC cards need longer data read timeout than indicated in CSD.
65 	 */
66 	MMC_FIXUP(CID_NAME_ANY, CID_MANFID_MICRON, 0x200, add_quirk_mmc,
67 		  MMC_QUIRK_LONG_READ_TIME),
68 	MMC_FIXUP("008GE0", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
69 		  MMC_QUIRK_LONG_READ_TIME),
70 
71 	/*
72 	 * On these Samsung MoviNAND parts, performing secure erase or
73 	 * secure trim can result in unrecoverable corruption due to a
74 	 * firmware bug.
75 	 */
76 	MMC_FIXUP("M8G2FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
77 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
78 	MMC_FIXUP("MAG4FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
79 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
80 	MMC_FIXUP("MBG8FA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
81 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
82 	MMC_FIXUP("MCGAFA", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
83 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
84 	MMC_FIXUP("VAL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
85 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
86 	MMC_FIXUP("VYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
87 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
88 	MMC_FIXUP("KYL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
89 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
90 	MMC_FIXUP("VZL00M", CID_MANFID_SAMSUNG, CID_OEMID_ANY, add_quirk_mmc,
91 		  MMC_QUIRK_SEC_ERASE_TRIM_BROKEN),
92 
93 	/*
94 	 *  On Some Kingston eMMCs, performing trim can result in
95 	 *  unrecoverable data conrruption occasionally due to a firmware bug.
96 	 */
97 	MMC_FIXUP("V10008", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
98 		  MMC_QUIRK_TRIM_BROKEN),
99 	MMC_FIXUP("V10016", CID_MANFID_KINGSTON, CID_OEMID_ANY, add_quirk_mmc,
100 		  MMC_QUIRK_TRIM_BROKEN),
101 
102 	/*
103 	 * Kingston EMMC04G-M627 advertises TRIM but it does not seems to
104 	 * support being used to offload WRITE_ZEROES.
105 	 */
106 	MMC_FIXUP("M62704", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
107 		  MMC_QUIRK_TRIM_BROKEN),
108 
109 	/*
110 	 * Micron MTFC4GACAJCN-1M advertises TRIM but it does not seems to
111 	 * support being used to offload WRITE_ZEROES.
112 	 */
113 	MMC_FIXUP("Q2J54A", CID_MANFID_MICRON, 0x014e, add_quirk_mmc,
114 		  MMC_QUIRK_TRIM_BROKEN),
115 
116 	/*
117 	 * Some SD cards reports discard support while they don't
118 	 */
119 	MMC_FIXUP(CID_NAME_ANY, CID_MANFID_SANDISK_SD, 0x5344, add_quirk_sd,
120 		  MMC_QUIRK_BROKEN_SD_DISCARD),
121 
122 	END_FIXUP
123 };
124 
125 static const struct mmc_fixup __maybe_unused mmc_ext_csd_fixups[] = {
126 	/*
127 	 * Certain Hynix eMMC 4.41 cards might get broken when HPI feature
128 	 * is used so disable the HPI feature for such buggy cards.
129 	 */
130 	MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_HYNIX,
131 			      0x014a, add_quirk, MMC_QUIRK_BROKEN_HPI, 5),
132 	/*
133 	 * Certain Micron (Numonyx) eMMC 4.5 cards might get broken when HPI
134 	 * feature is used so disable the HPI feature for such buggy cards.
135 	 */
136 	MMC_FIXUP_EXT_CSD_REV(CID_NAME_ANY, CID_MANFID_NUMONYX,
137 			      0x014e, add_quirk, MMC_QUIRK_BROKEN_HPI, 6),
138 
139 	END_FIXUP
140 };
141 
142 
143 static const struct mmc_fixup __maybe_unused sdio_fixup_methods[] = {
144 	SDIO_FIXUP(SDIO_VENDOR_ID_TI_WL1251, SDIO_DEVICE_ID_TI_WL1251,
145 		   add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
146 
147 	SDIO_FIXUP(SDIO_VENDOR_ID_TI_WL1251, SDIO_DEVICE_ID_TI_WL1251,
148 		   add_quirk, MMC_QUIRK_DISABLE_CD),
149 
150 	SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
151 		   add_quirk, MMC_QUIRK_NONSTD_FUNC_IF),
152 
153 	SDIO_FIXUP(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271,
154 		   add_quirk, MMC_QUIRK_DISABLE_CD),
155 
156 	SDIO_FIXUP(SDIO_VENDOR_ID_STE, SDIO_DEVICE_ID_STE_CW1200,
157 		   add_quirk, MMC_QUIRK_BROKEN_BYTE_MODE_512),
158 
159 	SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8797_F0,
160 		   add_quirk, MMC_QUIRK_BROKEN_IRQ_POLLING),
161 
162 	SDIO_FIXUP(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8887_F0,
163 		   add_limit_rate_quirk, 150000000),
164 
165 	END_FIXUP
166 };
167 
mmc_fixup_device(struct mmc_card * card,const struct mmc_fixup * table)168 static inline void mmc_fixup_device(struct mmc_card *card,
169 				    const struct mmc_fixup *table)
170 {
171 	const struct mmc_fixup *f;
172 	u64 rev = cid_rev_card(card);
173 
174 	for (f = table; f->vendor_fixup; f++) {
175 		if ((f->manfid == CID_MANFID_ANY ||
176 		     f->manfid == card->cid.manfid) &&
177 		    (f->oemid == CID_OEMID_ANY ||
178 		     f->oemid == card->cid.oemid) &&
179 		    (f->name == CID_NAME_ANY ||
180 		     !strncmp(f->name, card->cid.prod_name,
181 			      sizeof(card->cid.prod_name))) &&
182 		    (f->cis_vendor == card->cis.vendor ||
183 		     f->cis_vendor == (u16) SDIO_ANY_ID) &&
184 		    (f->cis_device == card->cis.device ||
185 		     f->cis_device == (u16) SDIO_ANY_ID) &&
186 		    (f->ext_csd_rev == EXT_CSD_REV_ANY ||
187 		     f->ext_csd_rev == card->ext_csd.rev) &&
188 		    rev >= f->rev_start && rev <= f->rev_end) {
189 			dev_dbg(&card->dev, "calling %ps\n", f->vendor_fixup);
190 			f->vendor_fixup(card, f->data);
191 		}
192 	}
193 }
194