Skip to content

Commit 51414d4

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: mmc: core: Bus width testing needs to handle suspend/resume
2 parents 201f92e + f39b2dd commit 51414d4

2 files changed

Lines changed: 63 additions & 27 deletions

File tree

‎drivers/mmc/core/mmc.c‎

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
247247
return 0;
248248

249249
/* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
250+
card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
250251
if (card->csd.structure == 3) {
251-
int ext_csd_struct = ext_csd[EXT_CSD_STRUCTURE];
252-
if (ext_csd_struct > 2) {
252+
if (card->ext_csd.raw_ext_csd_structure > 2) {
253253
printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
254254
"version %d\n", mmc_hostname(card->host),
255-
ext_csd_struct);
255+
card->ext_csd.raw_ext_csd_structure);
256256
err = -EINVAL;
257257
goto out;
258258
}
@@ -266,6 +266,10 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
266266
goto out;
267267
}
268268

269+
card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0];
270+
card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1];
271+
card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2];
272+
card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3];
269273
if (card->ext_csd.rev >= 2) {
270274
card->ext_csd.sectors =
271275
ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
@@ -277,7 +281,7 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
277281
if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
278282
mmc_card_set_blockaddr(card);
279283
}
280-
284+
card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE];
281285
switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) {
282286
case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_52 |
283287
EXT_CSD_CARD_TYPE_26:
@@ -307,6 +311,11 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
307311
mmc_hostname(card->host));
308312
}
309313

314+
card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT];
315+
card->ext_csd.raw_erase_timeout_mult =
316+
ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
317+
card->ext_csd.raw_hc_erase_grp_size =
318+
ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
310319
if (card->ext_csd.rev >= 3) {
311320
u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT];
312321
card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG];
@@ -334,14 +343,24 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
334343
card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
335344
}
336345

346+
card->ext_csd.raw_hc_erase_gap_size =
347+
ext_csd[EXT_CSD_PARTITION_ATTRIBUTE];
348+
card->ext_csd.raw_sec_trim_mult =
349+
ext_csd[EXT_CSD_SEC_TRIM_MULT];
350+
card->ext_csd.raw_sec_erase_mult =
351+
ext_csd[EXT_CSD_SEC_ERASE_MULT];
352+
card->ext_csd.raw_sec_feature_support =
353+
ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
354+
card->ext_csd.raw_trim_mult =
355+
ext_csd[EXT_CSD_TRIM_MULT];
337356
if (card->ext_csd.rev >= 4) {
338357
/*
339358
* Enhanced area feature support -- check whether the eMMC
340359
* card has the Enhanced area enabled. If so, export enhanced
341360
* area offset and size to user by adding sysfs interface.
342361
*/
343362
if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
344-
(ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
363+
(ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
345364
u8 hc_erase_grp_sz =
346365
ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
347366
u8 hc_wp_grp_sz =
@@ -401,17 +420,17 @@ static inline void mmc_free_ext_csd(u8 *ext_csd)
401420
}
402421

403422

404-
static int mmc_compare_ext_csds(struct mmc_card *card, u8 *ext_csd,
405-
unsigned bus_width)
423+
static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
406424
{
407425
u8 *bw_ext_csd;
408426
int err;
409427

428+
if (bus_width == MMC_BUS_WIDTH_1)
429+
return 0;
430+
410431
err = mmc_get_ext_csd(card, &bw_ext_csd);
411-
if (err)
412-
return err;
413432

414-
if ((ext_csd == NULL || bw_ext_csd == NULL)) {
433+
if (err || bw_ext_csd == NULL) {
415434
if (bus_width != MMC_BUS_WIDTH_1)
416435
err = -EINVAL;
417436
goto out;
@@ -421,35 +440,40 @@ static int mmc_compare_ext_csds(struct mmc_card *card, u8 *ext_csd,
421440
goto out;
422441

423442
/* only compare read only fields */
424-
err = (!(ext_csd[EXT_CSD_PARTITION_SUPPORT] ==
443+
err = (!(card->ext_csd.raw_partition_support ==
425444
bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) &&
426-
(ext_csd[EXT_CSD_ERASED_MEM_CONT] ==
445+
(card->ext_csd.raw_erased_mem_count ==
427446
bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) &&
428-
(ext_csd[EXT_CSD_REV] ==
447+
(card->ext_csd.rev ==
429448
bw_ext_csd[EXT_CSD_REV]) &&
430-
(ext_csd[EXT_CSD_STRUCTURE] ==
449+
(card->ext_csd.raw_ext_csd_structure ==
431450
bw_ext_csd[EXT_CSD_STRUCTURE]) &&
432-
(ext_csd[EXT_CSD_CARD_TYPE] ==
451+
(card->ext_csd.raw_card_type ==
433452
bw_ext_csd[EXT_CSD_CARD_TYPE]) &&
434-
(ext_csd[EXT_CSD_S_A_TIMEOUT] ==
453+
(card->ext_csd.raw_s_a_timeout ==
435454
bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) &&
436-
(ext_csd[EXT_CSD_HC_WP_GRP_SIZE] ==
455+
(card->ext_csd.raw_hc_erase_gap_size ==
437456
bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) &&
438-
(ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] ==
457+
(card->ext_csd.raw_erase_timeout_mult ==
439458
bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) &&
440-
(ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] ==
459+
(card->ext_csd.raw_hc_erase_grp_size ==
441460
bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) &&
442-
(ext_csd[EXT_CSD_SEC_TRIM_MULT] ==
461+
(card->ext_csd.raw_sec_trim_mult ==
443462
bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) &&
444-
(ext_csd[EXT_CSD_SEC_ERASE_MULT] ==
463+
(card->ext_csd.raw_sec_erase_mult ==
445464
bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) &&
446-
(ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] ==
465+
(card->ext_csd.raw_sec_feature_support ==
447466
bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) &&
448-
(ext_csd[EXT_CSD_TRIM_MULT] ==
467+
(card->ext_csd.raw_trim_mult ==
449468
bw_ext_csd[EXT_CSD_TRIM_MULT]) &&
450-
memcmp(&ext_csd[EXT_CSD_SEC_CNT],
451-
&bw_ext_csd[EXT_CSD_SEC_CNT],
452-
4) != 0);
469+
(card->ext_csd.raw_sectors[0] ==
470+
bw_ext_csd[EXT_CSD_SEC_CNT + 0]) &&
471+
(card->ext_csd.raw_sectors[1] ==
472+
bw_ext_csd[EXT_CSD_SEC_CNT + 1]) &&
473+
(card->ext_csd.raw_sectors[2] ==
474+
bw_ext_csd[EXT_CSD_SEC_CNT + 2]) &&
475+
(card->ext_csd.raw_sectors[3] ==
476+
bw_ext_csd[EXT_CSD_SEC_CNT + 3]));
453477
if (err)
454478
err = -EINVAL;
455479

@@ -770,7 +794,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
770794
*/
771795
if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
772796
err = mmc_compare_ext_csds(card,
773-
ext_csd,
774797
bus_width);
775798
else
776799
err = mmc_bus_test(card, bus_width);

‎include/linux/mmc/card.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,19 @@ struct mmc_ext_csd {
6464
unsigned long long enhanced_area_offset; /* Units: Byte */
6565
unsigned int enhanced_area_size; /* Units: KB */
6666
unsigned int boot_size; /* in bytes */
67+
u8 raw_partition_support; /* 160 */
68+
u8 raw_erased_mem_count; /* 181 */
69+
u8 raw_ext_csd_structure; /* 194 */
70+
u8 raw_card_type; /* 196 */
71+
u8 raw_s_a_timeout; /* 217 */
72+
u8 raw_hc_erase_gap_size; /* 221 */
73+
u8 raw_erase_timeout_mult; /* 223 */
74+
u8 raw_hc_erase_grp_size; /* 224 */
75+
u8 raw_sec_trim_mult; /* 229 */
76+
u8 raw_sec_erase_mult; /* 230 */
77+
u8 raw_sec_feature_support;/* 231 */
78+
u8 raw_trim_mult; /* 232 */
79+
u8 raw_sectors[4]; /* 212 - 4 bytes */
6780
};
6881

6982
struct sd_scr {

0 commit comments

Comments
 (0)