221
228
mmc_hostname(card->host));
232
*new_ext_csd = ext_csd;
238
* Decode extended CSD.
240
static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
228
249
/* 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];
229
251
if (card->csd.structure == 3) {
230
int ext_csd_struct = ext_csd[EXT_CSD_STRUCTURE];
231
if (ext_csd_struct > 2) {
252
if (card->ext_csd.raw_ext_csd_structure > 2) {
232
253
printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
233
254
"version %d\n", mmc_hostname(card->host),
255
card->ext_csd.raw_ext_csd_structure);
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];
248
273
if (card->ext_csd.rev >= 2) {
249
274
card->ext_csd.sectors =
250
275
ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
286
311
mmc_hostname(card->host));
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];
289
319
if (card->ext_csd.rev >= 3) {
290
320
u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT];
321
card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG];
323
/* EXT_CSD value is in units of 10ms, but we store in ms */
324
card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME];
292
326
/* Sleep / awake timeout in 100ns units */
293
327
if (sa_shift > 0 && sa_shift <= 0x17)
299
333
ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
300
334
card->ext_csd.hc_erase_size =
301
335
ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10;
337
card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C];
340
* There are two boot regions of equal size, defined in
343
card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
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];
304
356
if (card->ext_csd.rev >= 4) {
306
358
* Enhanced area feature support -- check whether the eMMC
350
402
ext_csd[EXT_CSD_TRIM_MULT];
405
if (card->ext_csd.rev >= 5)
406
card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM];
353
408
if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
354
409
card->erased_byte = 0xFF;
356
411
card->erased_byte = 0x0;
417
static inline void mmc_free_ext_csd(u8 *ext_csd)
423
static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
428
if (bus_width == MMC_BUS_WIDTH_1)
431
err = mmc_get_ext_csd(card, &bw_ext_csd);
433
if (err || bw_ext_csd == NULL) {
434
if (bus_width != MMC_BUS_WIDTH_1)
439
if (bus_width == MMC_BUS_WIDTH_1)
442
/* only compare read only fields */
443
err = (!(card->ext_csd.raw_partition_support ==
444
bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) &&
445
(card->ext_csd.raw_erased_mem_count ==
446
bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) &&
447
(card->ext_csd.rev ==
448
bw_ext_csd[EXT_CSD_REV]) &&
449
(card->ext_csd.raw_ext_csd_structure ==
450
bw_ext_csd[EXT_CSD_STRUCTURE]) &&
451
(card->ext_csd.raw_card_type ==
452
bw_ext_csd[EXT_CSD_CARD_TYPE]) &&
453
(card->ext_csd.raw_s_a_timeout ==
454
bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) &&
455
(card->ext_csd.raw_hc_erase_gap_size ==
456
bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) &&
457
(card->ext_csd.raw_erase_timeout_mult ==
458
bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) &&
459
(card->ext_csd.raw_hc_erase_grp_size ==
460
bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) &&
461
(card->ext_csd.raw_sec_trim_mult ==
462
bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) &&
463
(card->ext_csd.raw_sec_erase_mult ==
464
bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) &&
465
(card->ext_csd.raw_sec_feature_support ==
466
bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) &&
467
(card->ext_csd.raw_trim_mult ==
468
bw_ext_csd[EXT_CSD_TRIM_MULT]) &&
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]));
481
mmc_free_ext_csd(bw_ext_csd);
540
666
* If enhanced_area_en is TRUE, host needs to enable ERASE_GRP_DEF
541
* bit. This bit will be lost everytime after a reset or power off.
667
* bit. This bit will be lost every time after a reset or power off.
543
669
if (card->ext_csd.enhanced_area_en) {
544
670
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
545
EXT_CSD_ERASE_GROUP_DEF, 1);
671
EXT_CSD_ERASE_GROUP_DEF, 1, 0);
547
673
if (err && err != -EBADMSG)
697
* Ensure eMMC user default partition is enabled
699
if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) {
700
card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
701
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG,
702
card->ext_csd.part_config,
703
card->ext_csd.part_time);
704
if (err && err != -EBADMSG)
571
709
* Activate high speed (if supported)
573
711
if ((card->ext_csd.hs_max_dtr != 0) &&
574
712
(host->caps & MMC_CAP_MMC_HIGHSPEED)) {
575
713
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
576
EXT_CSD_HS_TIMING, 1);
714
EXT_CSD_HS_TIMING, 1, 0);
577
715
if (err && err != -EBADMSG)
607
745
if (mmc_card_highspeed(card)) {
608
746
if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_8V)
609
&& (host->caps & (MMC_CAP_1_8V_DDR)))
747
&& ((host->caps & (MMC_CAP_1_8V_DDR |
749
== (MMC_CAP_1_8V_DDR | MMC_CAP_UHS_DDR50)))
610
750
ddr = MMC_1_8V_DDR_MODE;
611
751
else if ((card->ext_csd.card_type & EXT_CSD_CARD_TYPE_DDR_1_2V)
612
&& (host->caps & (MMC_CAP_1_2V_DDR)))
752
&& ((host->caps & (MMC_CAP_1_2V_DDR |
754
== (MMC_CAP_1_2V_DDR | MMC_CAP_UHS_DDR50)))
613
755
ddr = MMC_1_2V_DDR_MODE;
640
782
ddr = 0; /* no DDR for 1-bit width */
641
783
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
642
784
EXT_CSD_BUS_WIDTH,
643
ext_csd_bits[idx][0]);
785
ext_csd_bits[idx][0],
645
mmc_set_bus_width_ddr(card->host,
646
bus_width, MMC_SDR_MODE);
788
mmc_set_bus_width(card->host, bus_width);
648
791
* If controller can't handle bus width test,
649
* use the highest bus width to maintain
650
* compatibility with previous MMC behavior.
792
* compare ext_csd previously read in 1 bit mode
793
* against ext_csd at new bus width
652
795
if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST))
654
err = mmc_bus_test(card, bus_width);
796
err = mmc_compare_ext_csds(card,
799
err = mmc_bus_test(card, bus_width);
668
814
1 << bus_width, ddr);
670
816
} else if (ddr) {
818
* eMMC cards can support 3.3V to 1.2V i/o (vccq)
821
* EXT_CSD_CARD_TYPE_DDR_1_8V means 3.3V or 1.8V vccq.
823
* 1.8V vccq at 3.3V core voltage (vcc) is not required
824
* in the JEDEC spec for DDR.
826
* Do not force change in vccq since we are obviously
827
* working and no change to vccq is needed.
829
* WARNING: eMMC rules are NOT the same as SD DDR
831
if (ddr == EXT_CSD_CARD_TYPE_DDR_1_2V) {
832
err = mmc_set_signal_voltage(host,
833
MMC_SIGNAL_VOLTAGE_120, 0);
671
837
mmc_card_set_ddr_mode(card);
672
mmc_set_bus_width_ddr(card->host, bus_width, ddr);
838
mmc_set_timing(card->host, MMC_TIMING_UHS_DDR50);
839
mmc_set_bus_width(card->host, bus_width);
677
844
host->card = card;
846
mmc_free_ext_csd(ext_csd);
683
851
mmc_remove_card(card);
853
mmc_free_ext_csd(ext_csd);