Lines Matching +full:broken +full:- +full:hpi
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
6 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
54 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
55 const int __off = 3 - ((start) / 32); \
61 __res |= resp[__off-1] << ((32 - __shft) % 32); \
70 u32 *resp = card->raw_cid; in mmc_decode_cid()
76 switch (card->csd.mmca_vsn) { in mmc_decode_cid()
77 case 0: /* MMC v1.0 - v1.2 */ in mmc_decode_cid()
79 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); in mmc_decode_cid()
80 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
81 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
82 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
83 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
84 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
85 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
86 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
87 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); in mmc_decode_cid()
88 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); in mmc_decode_cid()
89 card->cid.serial = UNSTUFF_BITS(resp, 16, 24); in mmc_decode_cid()
90 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
91 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
94 case 2: /* MMC v2.0 - v2.2 */ in mmc_decode_cid()
95 case 3: /* MMC v3.1 - v3.3 */ in mmc_decode_cid()
97 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); in mmc_decode_cid()
98 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); in mmc_decode_cid()
99 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
100 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
101 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
102 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
103 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
104 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
105 card->cid.prv = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
106 card->cid.serial = UNSTUFF_BITS(resp, 16, 32); in mmc_decode_cid()
107 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
108 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
113 mmc_hostname(card->host), card->csd.mmca_vsn); in mmc_decode_cid()
114 return -EINVAL; in mmc_decode_cid()
122 if (card->ext_csd.erase_group_def & 1) in mmc_set_erase_size()
123 card->erase_size = card->ext_csd.hc_erase_size; in mmc_set_erase_size()
125 card->erase_size = card->csd.erase_size; in mmc_set_erase_size()
131 * Given a 128-bit response, decode to our card CSD structure.
135 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
137 u32 *resp = card->raw_csd; in mmc_decode_csd()
144 csd->structure = UNSTUFF_BITS(resp, 126, 2); in mmc_decode_csd()
145 if (csd->structure == 0) { in mmc_decode_csd()
147 mmc_hostname(card->host), csd->structure); in mmc_decode_csd()
148 return -EINVAL; in mmc_decode_csd()
151 csd->mmca_vsn = UNSTUFF_BITS(resp, 122, 4); in mmc_decode_csd()
154 csd->taac_ns = (taac_exp[e] * taac_mant[m] + 9) / 10; in mmc_decode_csd()
155 csd->taac_clks = UNSTUFF_BITS(resp, 104, 8) * 100; in mmc_decode_csd()
159 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
160 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); in mmc_decode_csd()
164 csd->capacity = (1 + m) << (e + 2); in mmc_decode_csd()
166 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); in mmc_decode_csd()
167 csd->read_partial = UNSTUFF_BITS(resp, 79, 1); in mmc_decode_csd()
168 csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); in mmc_decode_csd()
169 csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); in mmc_decode_csd()
170 csd->dsr_imp = UNSTUFF_BITS(resp, 76, 1); in mmc_decode_csd()
171 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); in mmc_decode_csd()
172 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); in mmc_decode_csd()
173 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); in mmc_decode_csd()
175 if (csd->write_blkbits >= 9) { in mmc_decode_csd()
178 csd->erase_size = (a + 1) * (b + 1); in mmc_decode_csd()
179 csd->erase_size <<= csd->write_blkbits - 9; in mmc_decode_csd()
187 struct mmc_host *host = card->host; in mmc_select_card_type()
188 u8 card_type = card->ext_csd.raw_card_type; in mmc_select_card_type()
189 u32 caps = host->caps, caps2 = host->caps2; in mmc_select_card_type()
242 card->ext_csd.strobe_support && in mmc_select_card_type()
246 card->ext_csd.hs_max_dtr = hs_max_dtr; in mmc_select_card_type()
247 card->ext_csd.hs200_max_dtr = hs200_max_dtr; in mmc_select_card_type()
248 card->mmc_avail_type = avail_type; in mmc_select_card_type()
258 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_manage_enhanced_area()
259 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_manage_enhanced_area()
262 * Enhanced area feature support -- check whether the eMMC in mmc_manage_enhanced_area()
268 if (card->ext_csd.partition_setting_completed) { in mmc_manage_enhanced_area()
277 card->ext_csd.enhanced_area_offset = in mmc_manage_enhanced_area()
283 card->ext_csd.enhanced_area_offset <<= 9; in mmc_manage_enhanced_area()
287 card->ext_csd.enhanced_area_size = in mmc_manage_enhanced_area()
290 card->ext_csd.enhanced_area_size *= in mmc_manage_enhanced_area()
292 card->ext_csd.enhanced_area_size <<= 9; in mmc_manage_enhanced_area()
295 mmc_hostname(card->host)); in mmc_manage_enhanced_area()
304 card->part[card->nr_parts].size = size; in mmc_part_add()
305 card->part[card->nr_parts].part_cfg = part_cfg; in mmc_part_add()
306 sprintf(card->part[card->nr_parts].name, name, idx); in mmc_part_add()
307 card->part[card->nr_parts].force_ro = ro; in mmc_part_add()
308 card->part[card->nr_parts].area_type = area_type; in mmc_part_add()
309 card->nr_parts++; in mmc_part_add()
319 * General purpose partition feature support -- in mmc_manage_gp_partitions()
335 if (card->ext_csd.partition_setting_completed == 0) { in mmc_manage_gp_partitions()
337 mmc_hostname(card->host)); in mmc_manage_gp_partitions()
369 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; in mmc_decode_ext_csd()
370 if (card->csd.structure == 3) { in mmc_decode_ext_csd()
371 if (card->ext_csd.raw_ext_csd_structure > 2) { in mmc_decode_ext_csd()
373 "version %d\n", mmc_hostname(card->host), in mmc_decode_ext_csd()
374 card->ext_csd.raw_ext_csd_structure); in mmc_decode_ext_csd()
375 err = -EINVAL; in mmc_decode_ext_csd()
380 np = mmc_of_find_child_device(card->host, 0); in mmc_decode_ext_csd()
381 if (np && of_device_is_compatible(np, "mmc-card")) in mmc_decode_ext_csd()
382 broken_hpi = of_property_read_bool(np, "broken-hpi"); in mmc_decode_ext_csd()
388 * are authorized, see JEDEC JESD84-B50 section B.8. in mmc_decode_ext_csd()
390 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; in mmc_decode_ext_csd()
395 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; in mmc_decode_ext_csd()
396 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; in mmc_decode_ext_csd()
397 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; in mmc_decode_ext_csd()
398 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; in mmc_decode_ext_csd()
399 if (card->ext_csd.rev >= 2) { in mmc_decode_ext_csd()
400 card->ext_csd.sectors = in mmc_decode_ext_csd()
407 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) in mmc_decode_ext_csd()
411 card->ext_csd.strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT]; in mmc_decode_ext_csd()
412 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; in mmc_decode_ext_csd()
415 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; in mmc_decode_ext_csd()
416 card->ext_csd.raw_erase_timeout_mult = in mmc_decode_ext_csd()
418 card->ext_csd.raw_hc_erase_grp_size = in mmc_decode_ext_csd()
420 if (card->ext_csd.rev >= 3) { in mmc_decode_ext_csd()
422 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; in mmc_decode_ext_csd()
425 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; in mmc_decode_ext_csd()
427 if (card->ext_csd.part_time && in mmc_decode_ext_csd()
428 card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME) in mmc_decode_ext_csd()
429 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME; in mmc_decode_ext_csd()
433 card->ext_csd.sa_timeout = in mmc_decode_ext_csd()
435 card->ext_csd.erase_group_def = in mmc_decode_ext_csd()
437 card->ext_csd.hc_erase_timeout = 300 * in mmc_decode_ext_csd()
439 card->ext_csd.hc_erase_size = in mmc_decode_ext_csd()
442 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; in mmc_decode_ext_csd()
448 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { in mmc_decode_ext_csd()
459 card->ext_csd.raw_hc_erase_gap_size = in mmc_decode_ext_csd()
461 card->ext_csd.raw_sec_trim_mult = in mmc_decode_ext_csd()
463 card->ext_csd.raw_sec_erase_mult = in mmc_decode_ext_csd()
465 card->ext_csd.raw_sec_feature_support = in mmc_decode_ext_csd()
467 card->ext_csd.raw_trim_mult = in mmc_decode_ext_csd()
469 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; in mmc_decode_ext_csd()
470 card->ext_csd.raw_driver_strength = ext_csd[EXT_CSD_DRIVER_STRENGTH]; in mmc_decode_ext_csd()
471 if (card->ext_csd.rev >= 4) { in mmc_decode_ext_csd()
474 card->ext_csd.partition_setting_completed = 1; in mmc_decode_ext_csd()
476 card->ext_csd.partition_setting_completed = 0; in mmc_decode_ext_csd()
482 card->ext_csd.sec_trim_mult = in mmc_decode_ext_csd()
484 card->ext_csd.sec_erase_mult = in mmc_decode_ext_csd()
486 card->ext_csd.sec_feature_support = in mmc_decode_ext_csd()
488 card->ext_csd.trim_timeout = 300 * in mmc_decode_ext_csd()
496 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; in mmc_decode_ext_csd()
497 card->ext_csd.boot_ro_lockable = true; in mmc_decode_ext_csd()
500 card->ext_csd.raw_pwr_cl_52_195 = in mmc_decode_ext_csd()
502 card->ext_csd.raw_pwr_cl_26_195 = in mmc_decode_ext_csd()
504 card->ext_csd.raw_pwr_cl_52_360 = in mmc_decode_ext_csd()
506 card->ext_csd.raw_pwr_cl_26_360 = in mmc_decode_ext_csd()
508 card->ext_csd.raw_pwr_cl_200_195 = in mmc_decode_ext_csd()
510 card->ext_csd.raw_pwr_cl_200_360 = in mmc_decode_ext_csd()
512 card->ext_csd.raw_pwr_cl_ddr_52_195 = in mmc_decode_ext_csd()
514 card->ext_csd.raw_pwr_cl_ddr_52_360 = in mmc_decode_ext_csd()
516 card->ext_csd.raw_pwr_cl_ddr_200_360 = in mmc_decode_ext_csd()
520 if (card->ext_csd.rev >= 5) { in mmc_decode_ext_csd()
521 /* Adjust production date as per JEDEC JESD84-B451 */ in mmc_decode_ext_csd()
522 if (card->cid.year < 2010) in mmc_decode_ext_csd()
523 card->cid.year += 16; in mmc_decode_ext_csd()
527 card->ext_csd.bkops = 1; in mmc_decode_ext_csd()
528 card->ext_csd.man_bkops_en = in mmc_decode_ext_csd()
531 card->ext_csd.raw_bkops_status = in mmc_decode_ext_csd()
533 if (card->ext_csd.man_bkops_en) in mmc_decode_ext_csd()
535 mmc_hostname(card->host)); in mmc_decode_ext_csd()
536 card->ext_csd.auto_bkops_en = in mmc_decode_ext_csd()
539 if (card->ext_csd.auto_bkops_en) in mmc_decode_ext_csd()
541 mmc_hostname(card->host)); in mmc_decode_ext_csd()
544 /* check whether the eMMC card supports HPI */ in mmc_decode_ext_csd()
547 card->ext_csd.hpi = 1; in mmc_decode_ext_csd()
549 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; in mmc_decode_ext_csd()
551 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; in mmc_decode_ext_csd()
554 * a command interrupted by HPI in mmc_decode_ext_csd()
556 card->ext_csd.out_of_int_time = in mmc_decode_ext_csd()
560 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; in mmc_decode_ext_csd()
561 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; in mmc_decode_ext_csd()
566 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; in mmc_decode_ext_csd()
567 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { in mmc_decode_ext_csd()
575 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; in mmc_decode_ext_csd()
577 card->erased_byte = 0xFF; in mmc_decode_ext_csd()
579 card->erased_byte = 0x0; in mmc_decode_ext_csd()
582 card->ext_csd.generic_cmd6_time = DEFAULT_CMD6_TIMEOUT_MS; in mmc_decode_ext_csd()
583 if (card->ext_csd.rev >= 6) { in mmc_decode_ext_csd()
584 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; in mmc_decode_ext_csd()
586 card->ext_csd.generic_cmd6_time = 10 * in mmc_decode_ext_csd()
588 card->ext_csd.power_off_longtime = 10 * in mmc_decode_ext_csd()
591 card->ext_csd.cache_size = in mmc_decode_ext_csd()
598 card->ext_csd.data_sector_size = 4096; in mmc_decode_ext_csd()
600 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
604 card->ext_csd.data_tag_unit_size = in mmc_decode_ext_csd()
606 (card->ext_csd.data_sector_size); in mmc_decode_ext_csd()
608 card->ext_csd.data_tag_unit_size = 0; in mmc_decode_ext_csd()
611 card->ext_csd.max_packed_writes = in mmc_decode_ext_csd()
613 card->ext_csd.max_packed_reads = in mmc_decode_ext_csd()
616 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
620 if (card->ext_csd.rev >= 7) { in mmc_decode_ext_csd()
621 memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION], in mmc_decode_ext_csd()
623 card->ext_csd.ffu_capable = in mmc_decode_ext_csd()
627 card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; in mmc_decode_ext_csd()
628 card->ext_csd.device_life_time_est_typ_a = in mmc_decode_ext_csd()
630 card->ext_csd.device_life_time_est_typ_b = in mmc_decode_ext_csd()
635 if (card->ext_csd.rev >= 8) { in mmc_decode_ext_csd()
636 card->ext_csd.cmdq_support = ext_csd[EXT_CSD_CMDQ_SUPPORT] & in mmc_decode_ext_csd()
638 card->ext_csd.cmdq_depth = (ext_csd[EXT_CSD_CMDQ_DEPTH] & in mmc_decode_ext_csd()
641 if (card->ext_csd.cmdq_depth <= 2) { in mmc_decode_ext_csd()
642 card->ext_csd.cmdq_support = false; in mmc_decode_ext_csd()
643 card->ext_csd.cmdq_depth = 0; in mmc_decode_ext_csd()
645 if (card->ext_csd.cmdq_support) { in mmc_decode_ext_csd()
647 mmc_hostname(card->host), in mmc_decode_ext_csd()
648 card->ext_csd.cmdq_depth); in mmc_decode_ext_csd()
650 card->ext_csd.enhanced_rpmb_supported = in mmc_decode_ext_csd()
651 (card->ext_csd.rel_param & in mmc_decode_ext_csd()
670 if ((err != -EINVAL) in mmc_read_ext_csd()
671 && (err != -ENOSYS) in mmc_read_ext_csd()
672 && (err != -EFAULT)) in mmc_read_ext_csd()
679 if (card->csd.capacity == (4096 * 512)) { in mmc_read_ext_csd()
681 mmc_hostname(card->host)); in mmc_read_ext_csd()
684 mmc_hostname(card->host)); in mmc_read_ext_csd()
709 err = !((card->ext_csd.raw_partition_support == in mmc_compare_ext_csds()
711 (card->ext_csd.raw_erased_mem_count == in mmc_compare_ext_csds()
713 (card->ext_csd.rev == in mmc_compare_ext_csds()
715 (card->ext_csd.raw_ext_csd_structure == in mmc_compare_ext_csds()
717 (card->ext_csd.raw_card_type == in mmc_compare_ext_csds()
719 (card->ext_csd.raw_s_a_timeout == in mmc_compare_ext_csds()
721 (card->ext_csd.raw_hc_erase_gap_size == in mmc_compare_ext_csds()
723 (card->ext_csd.raw_erase_timeout_mult == in mmc_compare_ext_csds()
725 (card->ext_csd.raw_hc_erase_grp_size == in mmc_compare_ext_csds()
727 (card->ext_csd.raw_sec_trim_mult == in mmc_compare_ext_csds()
729 (card->ext_csd.raw_sec_erase_mult == in mmc_compare_ext_csds()
731 (card->ext_csd.raw_sec_feature_support == in mmc_compare_ext_csds()
733 (card->ext_csd.raw_trim_mult == in mmc_compare_ext_csds()
735 (card->ext_csd.raw_sectors[0] == in mmc_compare_ext_csds()
737 (card->ext_csd.raw_sectors[1] == in mmc_compare_ext_csds()
739 (card->ext_csd.raw_sectors[2] == in mmc_compare_ext_csds()
741 (card->ext_csd.raw_sectors[3] == in mmc_compare_ext_csds()
743 (card->ext_csd.raw_pwr_cl_52_195 == in mmc_compare_ext_csds()
745 (card->ext_csd.raw_pwr_cl_26_195 == in mmc_compare_ext_csds()
747 (card->ext_csd.raw_pwr_cl_52_360 == in mmc_compare_ext_csds()
749 (card->ext_csd.raw_pwr_cl_26_360 == in mmc_compare_ext_csds()
751 (card->ext_csd.raw_pwr_cl_200_195 == in mmc_compare_ext_csds()
753 (card->ext_csd.raw_pwr_cl_200_360 == in mmc_compare_ext_csds()
755 (card->ext_csd.raw_pwr_cl_ddr_52_195 == in mmc_compare_ext_csds()
757 (card->ext_csd.raw_pwr_cl_ddr_52_360 == in mmc_compare_ext_csds()
759 (card->ext_csd.raw_pwr_cl_ddr_200_360 == in mmc_compare_ext_csds()
763 err = -EINVAL; in mmc_compare_ext_csds()
769 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
770 card->raw_cid[2], card->raw_cid[3]);
771 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
772 card->raw_csd[2], card->raw_csd[3]);
773 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
774 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
775 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
776 MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
777 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
778 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
779 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
780 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
781 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
782 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
783 MMC_DEV_ATTR(pre_eol_info, "0x%02x\n", card->ext_csd.pre_eol_info);
785 card->ext_csd.device_life_time_est_typ_a,
786 card->ext_csd.device_life_time_est_typ_b);
787 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
789 card->ext_csd.enhanced_area_offset);
790 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
791 MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
793 card->ext_csd.enhanced_rpmb_supported);
794 MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
795 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
796 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
797 MMC_DEV_ATTR(cmdq_en, "%d\n", card->ext_csd.cmdq_en);
805 if (card->ext_csd.rev < 7) { in mmc_fwrev_show()
806 return sprintf(buf, "0x%x\n", card->cid.fwrev); in mmc_fwrev_show()
809 card->ext_csd.fwrev); in mmc_fwrev_show()
820 struct mmc_host *host = card->host; in mmc_dsr_show()
822 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
823 return sprintf(buf, "0x%x\n", host->dsr); in mmc_dsr_show()
874 struct mmc_host *host = card->host; in __mmc_select_powerclass()
875 struct mmc_ext_csd *ext_csd = &card->ext_csd; in __mmc_select_powerclass()
879 switch (1 << host->ios.vdd) { in __mmc_select_powerclass()
881 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) in __mmc_select_powerclass()
882 pwrclass_val = ext_csd->raw_pwr_cl_26_195; in __mmc_select_powerclass()
883 else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) in __mmc_select_powerclass()
885 ext_csd->raw_pwr_cl_52_195 : in __mmc_select_powerclass()
886 ext_csd->raw_pwr_cl_ddr_52_195; in __mmc_select_powerclass()
887 else if (host->ios.clock <= MMC_HS200_MAX_DTR) in __mmc_select_powerclass()
888 pwrclass_val = ext_csd->raw_pwr_cl_200_195; in __mmc_select_powerclass()
899 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) in __mmc_select_powerclass()
900 pwrclass_val = ext_csd->raw_pwr_cl_26_360; in __mmc_select_powerclass()
901 else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) in __mmc_select_powerclass()
903 ext_csd->raw_pwr_cl_52_360 : in __mmc_select_powerclass()
904 ext_csd->raw_pwr_cl_ddr_52_360; in __mmc_select_powerclass()
905 else if (host->ios.clock <= MMC_HS200_MAX_DTR) in __mmc_select_powerclass()
907 ext_csd->raw_pwr_cl_ddr_200_360 : in __mmc_select_powerclass()
908 ext_csd->raw_pwr_cl_200_360; in __mmc_select_powerclass()
913 return -EINVAL; in __mmc_select_powerclass()
928 card->ext_csd.generic_cmd6_time); in __mmc_select_powerclass()
936 struct mmc_host *host = card->host; in mmc_select_powerclass()
944 bus_width = host->ios.bus_width; in mmc_select_powerclass()
949 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; in mmc_select_powerclass()
970 unsigned int max_dtr = (unsigned int)-1; in mmc_set_bus_speed()
973 max_dtr > card->ext_csd.hs200_max_dtr) in mmc_set_bus_speed()
974 max_dtr = card->ext_csd.hs200_max_dtr; in mmc_set_bus_speed()
975 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr) in mmc_set_bus_speed()
976 max_dtr = card->ext_csd.hs_max_dtr; in mmc_set_bus_speed()
977 else if (max_dtr > card->csd.max_dtr) in mmc_set_bus_speed()
978 max_dtr = card->csd.max_dtr; in mmc_set_bus_speed()
980 mmc_set_clock(card->host, max_dtr); in mmc_set_bus_speed()
984 * Select the bus width amoung 4-bit and 8-bit(SDR).
998 struct mmc_host *host = card->host; in mmc_select_bus_width()
1003 !(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) in mmc_select_bus_width()
1006 idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 0 : 1; in mmc_select_bus_width()
1025 card->ext_csd.generic_cmd6_time); in mmc_select_bus_width()
1037 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) in mmc_select_bus_width()
1055 * Switch to the high-speed mode
1063 card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_HS, in mmc_select_hs()
1066 pr_warn("%s: switch to high-speed failed, err:%d\n", in mmc_select_hs()
1067 mmc_hostname(card->host), err); in mmc_select_hs()
1077 struct mmc_host *host = card->host; in mmc_select_hs_ddr()
1081 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52)) in mmc_select_hs_ddr()
1084 bus_width = host->ios.bus_width; in mmc_select_hs_ddr()
1094 card->ext_csd.generic_cmd6_time, in mmc_select_hs_ddr()
1128 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) { in mmc_select_hs_ddr()
1134 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_8V && in mmc_select_hs_ddr()
1135 host->caps & MMC_CAP_1_8V_DDR) in mmc_select_hs_ddr()
1147 struct mmc_host *host = card->host; in mmc_select_hs400()
1153 * HS400 mode requires 8-bit bus width in mmc_select_hs400()
1155 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_select_hs400()
1156 host->ios.bus_width == MMC_BUS_WIDTH_8)) in mmc_select_hs400()
1163 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1166 pr_err("%s: switch to high-speed from hs200 failed, err:%d\n", in mmc_select_hs400()
1172 if (host->ops->hs400_downgrade) in mmc_select_hs400()
1173 host->ops->hs400_downgrade(host); in mmc_select_hs400()
1179 max_dtr = card->ext_csd.hs_max_dtr; in mmc_select_hs400()
1186 if (host->ops->hs400_prepare_ddr) in mmc_select_hs400()
1187 host->ops->hs400_prepare_ddr(host); in mmc_select_hs400()
1193 card->ext_csd.generic_cmd6_time); in mmc_select_hs400()
1202 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400()
1205 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1217 if (host->ops->hs400_complete) in mmc_select_hs400()
1218 host->ops->hs400_complete(host); in mmc_select_hs400()
1227 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400()
1239 struct mmc_host *host = card->host; in mmc_hs400_to_hs200()
1245 max_dtr = card->ext_csd.hs_max_dtr; in mmc_hs400_to_hs200()
1251 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1256 if (host->ops->hs400_downgrade) in mmc_hs400_to_hs200()
1257 host->ops->hs400_downgrade(host); in mmc_hs400_to_hs200()
1267 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1280 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_hs400_to_hs200()
1282 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1301 if (host->ops->prepare_hs400_tuning) in mmc_hs400_to_hs200()
1302 host->ops->prepare_hs400_tuning(host, &host->ios); in mmc_hs400_to_hs200()
1307 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_hs400_to_hs200()
1315 int fixed_drv_type = card->host->fixed_drv_type; in mmc_select_driver_type()
1317 card_drv_type = card->ext_csd.raw_driver_strength | in mmc_select_driver_type()
1325 card->ext_csd.hs200_max_dtr, in mmc_select_driver_type()
1328 card->drive_strength = drive_strength; in mmc_select_driver_type()
1331 mmc_set_driver_type(card->host, drv_type); in mmc_select_driver_type()
1336 struct mmc_host *host = card->host; in mmc_select_hs400es()
1337 int err = -EINVAL; in mmc_select_hs400es()
1340 if (!(host->caps & MMC_CAP_8_BIT_DATA)) { in mmc_select_hs400es()
1341 err = -ENOTSUPP; in mmc_select_hs400es()
1345 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) in mmc_select_hs400es()
1348 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) in mmc_select_hs400es()
1359 err = err < 0 ? err : -ENOTSUPP; in mmc_select_hs400es()
1366 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1379 mmc_set_clock(host, card->ext_csd.hs_max_dtr); in mmc_select_hs400es()
1386 card->ext_csd.generic_cmd6_time); in mmc_select_hs400es()
1397 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400es()
1400 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1412 host->ios.enhanced_strobe = true; in mmc_select_hs400es()
1413 if (host->ops->hs400_enhanced_strobe) in mmc_select_hs400es()
1414 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_select_hs400es()
1423 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400es()
1431 * 1. set the desired bus width(4-bit or 8-bit, 1-bit is not supported)
1437 struct mmc_host *host = card->host; in mmc_select_hs200()
1439 int err = -EINVAL; in mmc_select_hs200()
1442 old_signal_voltage = host->ios.signal_voltage; in mmc_select_hs200()
1443 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) in mmc_select_hs200()
1446 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) in mmc_select_hs200()
1462 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs200()
1465 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs200()
1469 old_timing = host->ios.timing; in mmc_select_hs200()
1483 if (err == -EBADMSG) in mmc_select_hs200()
1490 err = -EIO; in mmc_select_hs200()
1492 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs200()
1508 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400ES) in mmc_select_timing()
1510 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) in mmc_select_timing()
1512 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS) in mmc_select_timing()
1515 if (err && err != -EBADMSG) in mmc_select_timing()
1533 struct mmc_host *host = card->host; in mmc_hs200_tuning()
1539 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_hs200_tuning()
1540 host->ios.bus_width == MMC_BUS_WIDTH_8) in mmc_hs200_tuning()
1541 if (host->ops->prepare_hs400_tuning) in mmc_hs200_tuning()
1542 host->ops->prepare_hs400_tuning(host, &host->ios); in mmc_hs200_tuning()
1561 WARN_ON(!host->claimed); in mmc_init_card()
1598 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { in mmc_init_card()
1601 err = -ENOENT; in mmc_init_card()
1616 card->ocr = ocr; in mmc_init_card()
1617 card->type = MMC_TYPE_MMC; in mmc_init_card()
1618 card->rca = 1; in mmc_init_card()
1619 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_init_card()
1625 if (host->ops->init_card) in mmc_init_card()
1626 host->ops->init_card(host, card); in mmc_init_card()
1643 err = mmc_send_csd(card, card->raw_csd); in mmc_init_card()
1659 if (card->csd.dsr_imp && host->dsr_req) in mmc_init_card()
1680 * addressing. See section 8.1 JEDEC Standard JED84-A441; in mmc_init_card()
1691 if (card->ext_csd.rev >= 3) { in mmc_init_card()
1694 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1696 if (err && err != -EBADMSG) in mmc_init_card()
1706 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_init_card()
1707 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_init_card()
1709 card->ext_csd.erase_group_def = 1; in mmc_init_card()
1722 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { in mmc_init_card()
1723 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; in mmc_init_card()
1725 card->ext_csd.part_config, in mmc_init_card()
1726 card->ext_csd.part_time); in mmc_init_card()
1727 if (err && err != -EBADMSG) in mmc_init_card()
1734 if (card->ext_csd.rev >= 6) { in mmc_init_card()
1738 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1739 if (err && err != -EBADMSG) in mmc_init_card()
1743 * The err can be -EBADMSG or 0, in mmc_init_card()
1747 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; in mmc_init_card()
1752 card->erase_arg = MMC_DISCARD_ARG; in mmc_init_card()
1754 card->erase_arg = MMC_TRIM_ARG; in mmc_init_card()
1756 card->erase_arg = MMC_ERASE_ARG; in mmc_init_card()
1766 host->doing_init_tune = 1; in mmc_init_card()
1772 host->doing_init_tune = 0; in mmc_init_card()
1793 * Enable HPI feature (if supported) in mmc_init_card()
1795 if (card->ext_csd.hpi) { in mmc_init_card()
1798 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1799 if (err && err != -EBADMSG) in mmc_init_card()
1802 pr_warn("%s: Enabling HPI failed\n", in mmc_init_card()
1803 mmc_hostname(card->host)); in mmc_init_card()
1804 card->ext_csd.hpi_en = 0; in mmc_init_card()
1807 card->ext_csd.hpi_en = 1; in mmc_init_card()
1818 if (card->ext_csd.cache_size > 0) { in mmc_init_card()
1821 timeout_ms = max(card->ext_csd.generic_cmd6_time, timeout_ms); in mmc_init_card()
1824 if (err && err != -EBADMSG) in mmc_init_card()
1832 mmc_hostname(card->host), err); in mmc_init_card()
1833 card->ext_csd.cache_ctrl = 0; in mmc_init_card()
1836 card->ext_csd.cache_ctrl = 1; in mmc_init_card()
1844 card->ext_csd.cmdq_en = false; in mmc_init_card()
1845 if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) { in mmc_init_card()
1847 if (err && err != -EBADMSG) in mmc_init_card()
1851 mmc_hostname(card->host)); in mmc_init_card()
1852 card->ext_csd.cmdq_support = false; in mmc_init_card()
1853 card->ext_csd.cmdq_depth = 0; in mmc_init_card()
1859 * disabled for a time, so a flag is needed to indicate to re-enable the in mmc_init_card()
1862 card->reenable_cmdq = card->ext_csd.cmdq_en; in mmc_init_card()
1864 if (host->cqe_ops && !host->cqe_enabled) { in mmc_init_card()
1865 err = host->cqe_ops->cqe_enable(host, card); in mmc_init_card()
1867 host->cqe_enabled = true; in mmc_init_card()
1869 if (card->ext_csd.cmdq_en) { in mmc_init_card()
1873 host->hsq_enabled = true; in mmc_init_card()
1880 if (host->caps2 & MMC_CAP2_AVOID_3_3V && in mmc_init_card()
1881 host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in mmc_init_card()
1884 err = -EINVAL; in mmc_init_card()
1889 host->card = card; in mmc_init_card()
1902 return (card && card->ext_csd.rev >= 3); in mmc_can_sleep()
1908 struct mmc_card *card = host->card; in mmc_sleep()
1909 unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); in mmc_sleep()
1912 /* Re-tuning can't be done once the card is deselected */ in mmc_sleep()
1920 cmd.arg = card->rca << 16; in mmc_sleep()
1931 if (!(host->caps & MMC_CAP_NEED_RSP_BUSY) && host->max_busy_timeout && in mmc_sleep()
1932 (timeout_ms > host->max_busy_timeout)) { in mmc_sleep()
1949 if (!cmd.busy_timeout || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) in mmc_sleep()
1961 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); in mmc_can_poweroff_notify()
1966 unsigned int timeout = card->ext_csd.generic_cmd6_time; in mmc_poweroff_notify()
1971 timeout = card->ext_csd.power_off_longtime; in mmc_poweroff_notify()
1978 mmc_hostname(card->host), timeout); in mmc_poweroff_notify()
1981 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; in mmc_poweroff_notify()
1991 mmc_remove_card(host->card); in mmc_remove()
1992 host->card = NULL; in mmc_remove()
1996 * Card detection - card is alive.
2000 return mmc_send_status(host->card, NULL); in mmc_alive()
2010 mmc_get_card(host->card, NULL); in mmc_detect()
2017 mmc_put_card(host->card, NULL); in mmc_detect()
2037 if (mmc_card_suspended(host->card)) in _mmc_suspend()
2040 err = mmc_flush_cache(host->card); in _mmc_suspend()
2044 if (mmc_can_poweroff_notify(host->card) && in _mmc_suspend()
2045 ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend || in _mmc_suspend()
2046 (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND))) in _mmc_suspend()
2047 err = mmc_poweroff_notify(host->card, notify_type); in _mmc_suspend()
2048 else if (mmc_can_sleep(host->card)) in _mmc_suspend()
2055 mmc_card_set_suspended(host->card); in _mmc_suspend()
2071 pm_runtime_disable(&host->card->dev); in mmc_suspend()
2072 pm_runtime_set_suspended(&host->card->dev); in mmc_suspend()
2088 if (!mmc_card_suspended(host->card)) in _mmc_resume()
2091 mmc_power_up(host, host->card->ocr); in _mmc_resume()
2092 err = mmc_init_card(host, host->card->ocr, host->card); in _mmc_resume()
2093 mmc_card_clr_suspended(host->card); in _mmc_resume()
2111 if (mmc_can_poweroff_notify(host->card) && in mmc_shutdown()
2112 !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)) in mmc_shutdown()
2126 pm_runtime_enable(&host->card->dev); in mmc_resume()
2137 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) in mmc_runtime_suspend()
2156 if (err && err != -ENOMEDIUM) in mmc_runtime_resume()
2167 rst_n_function = card->ext_csd.rst_n_function; in mmc_can_reset()
2175 struct mmc_card *card = host->card; in _mmc_hw_reset()
2181 mmc_flush_cache(host->card); in _mmc_hw_reset()
2183 if ((host->caps & MMC_CAP_HW_RESET) && host->ops->hw_reset && in _mmc_hw_reset()
2186 mmc_set_clock(host, host->f_init); in _mmc_hw_reset()
2187 host->ops->hw_reset(host); in _mmc_hw_reset()
2192 mmc_power_cycle(host, card->ocr); in _mmc_hw_reset()
2195 return mmc_init_card(host, card->ocr, card); in _mmc_hw_reset()
2218 WARN_ON(!host->claimed); in mmc_attach_mmc()
2229 if (host->ocr_avail_mmc) in mmc_attach_mmc()
2230 host->ocr_avail = host->ocr_avail_mmc; in mmc_attach_mmc()
2247 err = -EINVAL; in mmc_attach_mmc()
2259 err = mmc_add_card(host->card); in mmc_attach_mmc()
2267 mmc_remove_card(host->card); in mmc_attach_mmc()
2269 host->card = NULL; in mmc_attach_mmc()