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.
59 u32 *resp = card->raw_cid; in mmc_decode_cid()
65 add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); in mmc_decode_cid()
71 switch (card->csd.mmca_vsn) { in mmc_decode_cid()
72 case 0: /* MMC v1.0 - v1.2 */ in mmc_decode_cid()
74 card->cid.manfid = unstuff_bits(resp, 104, 24); in mmc_decode_cid()
75 card->cid.prod_name[0] = unstuff_bits(resp, 96, 8); in mmc_decode_cid()
76 card->cid.prod_name[1] = unstuff_bits(resp, 88, 8); in mmc_decode_cid()
77 card->cid.prod_name[2] = unstuff_bits(resp, 80, 8); in mmc_decode_cid()
78 card->cid.prod_name[3] = unstuff_bits(resp, 72, 8); in mmc_decode_cid()
79 card->cid.prod_name[4] = unstuff_bits(resp, 64, 8); in mmc_decode_cid()
80 card->cid.prod_name[5] = unstuff_bits(resp, 56, 8); in mmc_decode_cid()
81 card->cid.prod_name[6] = unstuff_bits(resp, 48, 8); in mmc_decode_cid()
82 card->cid.hwrev = unstuff_bits(resp, 44, 4); in mmc_decode_cid()
83 card->cid.fwrev = unstuff_bits(resp, 40, 4); in mmc_decode_cid()
84 card->cid.serial = unstuff_bits(resp, 16, 24); in mmc_decode_cid()
85 card->cid.month = unstuff_bits(resp, 12, 4); in mmc_decode_cid()
86 card->cid.year = unstuff_bits(resp, 8, 4) + 1997; in mmc_decode_cid()
89 case 2: /* MMC v2.0 - v2.2 */ in mmc_decode_cid()
90 case 3: /* MMC v3.1 - v3.3 */ in mmc_decode_cid()
92 card->cid.manfid = unstuff_bits(resp, 120, 8); in mmc_decode_cid()
93 card->cid.oemid = unstuff_bits(resp, 104, 16); in mmc_decode_cid()
94 card->cid.prod_name[0] = unstuff_bits(resp, 96, 8); in mmc_decode_cid()
95 card->cid.prod_name[1] = unstuff_bits(resp, 88, 8); in mmc_decode_cid()
96 card->cid.prod_name[2] = unstuff_bits(resp, 80, 8); in mmc_decode_cid()
97 card->cid.prod_name[3] = unstuff_bits(resp, 72, 8); in mmc_decode_cid()
98 card->cid.prod_name[4] = unstuff_bits(resp, 64, 8); in mmc_decode_cid()
99 card->cid.prod_name[5] = unstuff_bits(resp, 56, 8); in mmc_decode_cid()
100 card->cid.prv = unstuff_bits(resp, 48, 8); in mmc_decode_cid()
101 card->cid.serial = unstuff_bits(resp, 16, 32); in mmc_decode_cid()
102 card->cid.month = unstuff_bits(resp, 12, 4); in mmc_decode_cid()
103 card->cid.year = unstuff_bits(resp, 8, 4) + 1997; in mmc_decode_cid()
108 mmc_hostname(card->host), card->csd.mmca_vsn); in mmc_decode_cid()
109 return -EINVAL; in mmc_decode_cid()
117 if (card->ext_csd.erase_group_def & 1) in mmc_set_erase_size()
118 card->erase_size = card->ext_csd.hc_erase_size; in mmc_set_erase_size()
120 card->erase_size = card->csd.erase_size; in mmc_set_erase_size()
128 if (card->ext_csd.erase_group_def & 1) in mmc_set_wp_grp_size()
129 card->wp_grp_size = card->ext_csd.hc_erase_size * in mmc_set_wp_grp_size()
130 card->ext_csd.raw_hc_erase_gap_size; in mmc_set_wp_grp_size()
132 card->wp_grp_size = card->csd.erase_size * in mmc_set_wp_grp_size()
133 (card->csd.wp_grp_size + 1); in mmc_set_wp_grp_size()
137 * Given a 128-bit response, decode to our card CSD structure.
141 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
143 u32 *resp = card->raw_csd; in mmc_decode_csd()
150 csd->structure = unstuff_bits(resp, 126, 2); in mmc_decode_csd()
151 if (csd->structure == 0) { in mmc_decode_csd()
153 mmc_hostname(card->host), csd->structure); in mmc_decode_csd()
154 return -EINVAL; in mmc_decode_csd()
157 csd->mmca_vsn = unstuff_bits(resp, 122, 4); in mmc_decode_csd()
160 csd->taac_ns = (taac_exp[e] * taac_mant[m] + 9) / 10; in mmc_decode_csd()
161 csd->taac_clks = unstuff_bits(resp, 104, 8) * 100; in mmc_decode_csd()
165 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
166 csd->cmdclass = unstuff_bits(resp, 84, 12); in mmc_decode_csd()
170 csd->capacity = (1 + m) << (e + 2); in mmc_decode_csd()
172 csd->read_blkbits = unstuff_bits(resp, 80, 4); in mmc_decode_csd()
173 csd->read_partial = unstuff_bits(resp, 79, 1); in mmc_decode_csd()
174 csd->write_misalign = unstuff_bits(resp, 78, 1); in mmc_decode_csd()
175 csd->read_misalign = unstuff_bits(resp, 77, 1); in mmc_decode_csd()
176 csd->dsr_imp = unstuff_bits(resp, 76, 1); in mmc_decode_csd()
177 csd->r2w_factor = unstuff_bits(resp, 26, 3); in mmc_decode_csd()
178 csd->write_blkbits = unstuff_bits(resp, 22, 4); in mmc_decode_csd()
179 csd->write_partial = unstuff_bits(resp, 21, 1); in mmc_decode_csd()
181 if (csd->write_blkbits >= 9) { in mmc_decode_csd()
184 csd->erase_size = (a + 1) * (b + 1); in mmc_decode_csd()
185 csd->erase_size <<= csd->write_blkbits - 9; in mmc_decode_csd()
186 csd->wp_grp_size = unstuff_bits(resp, 32, 5); in mmc_decode_csd()
194 struct mmc_host *host = card->host; in mmc_select_card_type()
195 u8 card_type = card->ext_csd.raw_card_type; in mmc_select_card_type()
196 u32 caps = host->caps, caps2 = host->caps2; in mmc_select_card_type()
249 card->ext_csd.strobe_support && in mmc_select_card_type()
253 card->ext_csd.hs_max_dtr = hs_max_dtr; in mmc_select_card_type()
254 card->ext_csd.hs200_max_dtr = hs200_max_dtr; in mmc_select_card_type()
255 card->mmc_avail_type = avail_type; in mmc_select_card_type()
265 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_manage_enhanced_area()
266 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_manage_enhanced_area()
269 * Enhanced area feature support -- check whether the eMMC in mmc_manage_enhanced_area()
275 if (card->ext_csd.partition_setting_completed) { in mmc_manage_enhanced_area()
284 card->ext_csd.enhanced_area_offset = in mmc_manage_enhanced_area()
290 card->ext_csd.enhanced_area_offset <<= 9; in mmc_manage_enhanced_area()
294 card->ext_csd.enhanced_area_size = in mmc_manage_enhanced_area()
297 card->ext_csd.enhanced_area_size *= in mmc_manage_enhanced_area()
299 card->ext_csd.enhanced_area_size <<= 9; in mmc_manage_enhanced_area()
302 mmc_hostname(card->host)); in mmc_manage_enhanced_area()
311 card->part[card->nr_parts].size = size; in mmc_part_add()
312 card->part[card->nr_parts].part_cfg = part_cfg; in mmc_part_add()
313 sprintf(card->part[card->nr_parts].name, name, idx); in mmc_part_add()
314 card->part[card->nr_parts].force_ro = ro; in mmc_part_add()
315 card->part[card->nr_parts].area_type = area_type; in mmc_part_add()
316 card->nr_parts++; in mmc_part_add()
326 * General purpose partition feature support -- in mmc_manage_gp_partitions()
342 if (card->ext_csd.partition_setting_completed == 0) { in mmc_manage_gp_partitions()
344 mmc_hostname(card->host)); in mmc_manage_gp_partitions()
376 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; in mmc_decode_ext_csd()
377 if (card->csd.structure == 3) { in mmc_decode_ext_csd()
378 if (card->ext_csd.raw_ext_csd_structure > 2) { in mmc_decode_ext_csd()
380 "version %d\n", mmc_hostname(card->host), in mmc_decode_ext_csd()
381 card->ext_csd.raw_ext_csd_structure); in mmc_decode_ext_csd()
382 err = -EINVAL; in mmc_decode_ext_csd()
387 np = mmc_of_find_child_device(card->host, 0); in mmc_decode_ext_csd()
388 if (np && of_device_is_compatible(np, "mmc-card")) in mmc_decode_ext_csd()
389 broken_hpi = of_property_read_bool(np, "broken-hpi"); in mmc_decode_ext_csd()
395 * are authorized, see JEDEC JESD84-B50 section B.8. in mmc_decode_ext_csd()
397 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; in mmc_decode_ext_csd()
402 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; in mmc_decode_ext_csd()
403 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; in mmc_decode_ext_csd()
404 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; in mmc_decode_ext_csd()
405 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; in mmc_decode_ext_csd()
406 if (card->ext_csd.rev >= 2) { in mmc_decode_ext_csd()
407 card->ext_csd.sectors = in mmc_decode_ext_csd()
414 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) in mmc_decode_ext_csd()
418 card->ext_csd.strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT]; in mmc_decode_ext_csd()
419 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; in mmc_decode_ext_csd()
421 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; in mmc_decode_ext_csd()
422 card->ext_csd.raw_erase_timeout_mult = in mmc_decode_ext_csd()
424 card->ext_csd.raw_hc_erase_grp_size = in mmc_decode_ext_csd()
426 card->ext_csd.raw_boot_mult = in mmc_decode_ext_csd()
428 if (card->ext_csd.rev >= 3) { in mmc_decode_ext_csd()
430 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; in mmc_decode_ext_csd()
433 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; in mmc_decode_ext_csd()
437 card->ext_csd.sa_timeout = in mmc_decode_ext_csd()
439 card->ext_csd.erase_group_def = in mmc_decode_ext_csd()
441 card->ext_csd.hc_erase_timeout = 300 * in mmc_decode_ext_csd()
443 card->ext_csd.hc_erase_size = in mmc_decode_ext_csd()
446 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; in mmc_decode_ext_csd()
452 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { in mmc_decode_ext_csd()
463 card->ext_csd.raw_hc_erase_gap_size = in mmc_decode_ext_csd()
465 card->ext_csd.raw_sec_trim_mult = in mmc_decode_ext_csd()
467 card->ext_csd.raw_sec_erase_mult = in mmc_decode_ext_csd()
469 card->ext_csd.raw_sec_feature_support = in mmc_decode_ext_csd()
471 card->ext_csd.raw_trim_mult = in mmc_decode_ext_csd()
473 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; in mmc_decode_ext_csd()
474 card->ext_csd.raw_driver_strength = ext_csd[EXT_CSD_DRIVER_STRENGTH]; in mmc_decode_ext_csd()
475 if (card->ext_csd.rev >= 4) { in mmc_decode_ext_csd()
478 card->ext_csd.partition_setting_completed = 1; in mmc_decode_ext_csd()
480 card->ext_csd.partition_setting_completed = 0; in mmc_decode_ext_csd()
486 card->ext_csd.sec_trim_mult = in mmc_decode_ext_csd()
488 card->ext_csd.sec_erase_mult = in mmc_decode_ext_csd()
490 card->ext_csd.sec_feature_support = in mmc_decode_ext_csd()
492 card->ext_csd.trim_timeout = 300 * in mmc_decode_ext_csd()
500 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; in mmc_decode_ext_csd()
501 card->ext_csd.boot_ro_lockable = true; in mmc_decode_ext_csd()
504 card->ext_csd.raw_pwr_cl_52_195 = in mmc_decode_ext_csd()
506 card->ext_csd.raw_pwr_cl_26_195 = in mmc_decode_ext_csd()
508 card->ext_csd.raw_pwr_cl_52_360 = in mmc_decode_ext_csd()
510 card->ext_csd.raw_pwr_cl_26_360 = in mmc_decode_ext_csd()
512 card->ext_csd.raw_pwr_cl_200_195 = in mmc_decode_ext_csd()
514 card->ext_csd.raw_pwr_cl_200_360 = in mmc_decode_ext_csd()
516 card->ext_csd.raw_pwr_cl_ddr_52_195 = in mmc_decode_ext_csd()
518 card->ext_csd.raw_pwr_cl_ddr_52_360 = in mmc_decode_ext_csd()
520 card->ext_csd.raw_pwr_cl_ddr_200_360 = in mmc_decode_ext_csd()
524 if (card->ext_csd.rev >= 5) { in mmc_decode_ext_csd()
525 /* Adjust production date as per JEDEC JESD84-B451 */ in mmc_decode_ext_csd()
526 if (card->cid.year < 2010) in mmc_decode_ext_csd()
527 card->cid.year += 16; in mmc_decode_ext_csd()
531 card->ext_csd.bkops = 1; in mmc_decode_ext_csd()
532 card->ext_csd.man_bkops_en = in mmc_decode_ext_csd()
535 card->ext_csd.raw_bkops_status = in mmc_decode_ext_csd()
537 if (card->ext_csd.man_bkops_en) in mmc_decode_ext_csd()
539 mmc_hostname(card->host)); in mmc_decode_ext_csd()
540 card->ext_csd.auto_bkops_en = in mmc_decode_ext_csd()
543 if (card->ext_csd.auto_bkops_en) in mmc_decode_ext_csd()
545 mmc_hostname(card->host)); in mmc_decode_ext_csd()
548 /* check whether the eMMC card supports HPI */ in mmc_decode_ext_csd()
551 card->ext_csd.hpi = 1; in mmc_decode_ext_csd()
553 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; in mmc_decode_ext_csd()
555 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; in mmc_decode_ext_csd()
558 * a command interrupted by HPI in mmc_decode_ext_csd()
560 card->ext_csd.out_of_int_time = in mmc_decode_ext_csd()
564 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; in mmc_decode_ext_csd()
565 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; in mmc_decode_ext_csd()
570 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; in mmc_decode_ext_csd()
571 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { in mmc_decode_ext_csd()
579 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; in mmc_decode_ext_csd()
581 card->erased_byte = 0xFF; in mmc_decode_ext_csd()
583 card->erased_byte = 0x0; in mmc_decode_ext_csd()
586 card->ext_csd.generic_cmd6_time = DEFAULT_CMD6_TIMEOUT_MS; in mmc_decode_ext_csd()
587 if (card->ext_csd.rev >= 6) { in mmc_decode_ext_csd()
588 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; in mmc_decode_ext_csd()
590 card->ext_csd.generic_cmd6_time = 10 * in mmc_decode_ext_csd()
592 card->ext_csd.power_off_longtime = 10 * in mmc_decode_ext_csd()
595 card->ext_csd.cache_size = in mmc_decode_ext_csd()
602 card->ext_csd.data_sector_size = 4096; in mmc_decode_ext_csd()
604 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
608 card->ext_csd.data_tag_unit_size = in mmc_decode_ext_csd()
610 (card->ext_csd.data_sector_size); in mmc_decode_ext_csd()
612 card->ext_csd.data_tag_unit_size = 0; in mmc_decode_ext_csd()
615 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
623 if (!card->ext_csd.part_time) in mmc_decode_ext_csd()
624 card->ext_csd.part_time = card->ext_csd.generic_cmd6_time; in mmc_decode_ext_csd()
626 if (card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME) in mmc_decode_ext_csd()
627 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME; in mmc_decode_ext_csd()
630 if (card->ext_csd.rev >= 7) { in mmc_decode_ext_csd()
631 memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION], in mmc_decode_ext_csd()
633 card->ext_csd.ffu_capable = in mmc_decode_ext_csd()
637 card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; in mmc_decode_ext_csd()
638 card->ext_csd.device_life_time_est_typ_a = in mmc_decode_ext_csd()
640 card->ext_csd.device_life_time_est_typ_b = in mmc_decode_ext_csd()
645 if (card->ext_csd.rev >= 8) { in mmc_decode_ext_csd()
646 card->ext_csd.cmdq_support = ext_csd[EXT_CSD_CMDQ_SUPPORT] & in mmc_decode_ext_csd()
648 card->ext_csd.cmdq_depth = (ext_csd[EXT_CSD_CMDQ_DEPTH] & in mmc_decode_ext_csd()
651 if (card->ext_csd.cmdq_depth <= 2) { in mmc_decode_ext_csd()
652 card->ext_csd.cmdq_support = false; in mmc_decode_ext_csd()
653 card->ext_csd.cmdq_depth = 0; in mmc_decode_ext_csd()
655 if (card->ext_csd.cmdq_support) { in mmc_decode_ext_csd()
657 mmc_hostname(card->host), in mmc_decode_ext_csd()
658 card->ext_csd.cmdq_depth); in mmc_decode_ext_csd()
660 card->ext_csd.enhanced_rpmb_supported = in mmc_decode_ext_csd()
661 (card->ext_csd.rel_param & in mmc_decode_ext_csd()
680 if ((err != -EINVAL) in mmc_read_ext_csd()
681 && (err != -ENOSYS) in mmc_read_ext_csd()
682 && (err != -EFAULT)) in mmc_read_ext_csd()
689 if (card->csd.capacity == (4096 * 512)) { in mmc_read_ext_csd()
691 mmc_hostname(card->host)); in mmc_read_ext_csd()
694 mmc_hostname(card->host)); in mmc_read_ext_csd()
719 err = !((card->ext_csd.raw_partition_support == in mmc_compare_ext_csds()
721 (card->ext_csd.raw_erased_mem_count == in mmc_compare_ext_csds()
723 (card->ext_csd.rev == in mmc_compare_ext_csds()
725 (card->ext_csd.raw_ext_csd_structure == in mmc_compare_ext_csds()
727 (card->ext_csd.raw_card_type == in mmc_compare_ext_csds()
729 (card->ext_csd.raw_s_a_timeout == in mmc_compare_ext_csds()
731 (card->ext_csd.raw_hc_erase_gap_size == in mmc_compare_ext_csds()
733 (card->ext_csd.raw_erase_timeout_mult == in mmc_compare_ext_csds()
735 (card->ext_csd.raw_hc_erase_grp_size == in mmc_compare_ext_csds()
737 (card->ext_csd.raw_sec_trim_mult == in mmc_compare_ext_csds()
739 (card->ext_csd.raw_sec_erase_mult == in mmc_compare_ext_csds()
741 (card->ext_csd.raw_sec_feature_support == in mmc_compare_ext_csds()
743 (card->ext_csd.raw_trim_mult == in mmc_compare_ext_csds()
745 (card->ext_csd.raw_sectors[0] == in mmc_compare_ext_csds()
747 (card->ext_csd.raw_sectors[1] == in mmc_compare_ext_csds()
749 (card->ext_csd.raw_sectors[2] == in mmc_compare_ext_csds()
751 (card->ext_csd.raw_sectors[3] == in mmc_compare_ext_csds()
753 (card->ext_csd.raw_pwr_cl_52_195 == in mmc_compare_ext_csds()
755 (card->ext_csd.raw_pwr_cl_26_195 == in mmc_compare_ext_csds()
757 (card->ext_csd.raw_pwr_cl_52_360 == in mmc_compare_ext_csds()
759 (card->ext_csd.raw_pwr_cl_26_360 == in mmc_compare_ext_csds()
761 (card->ext_csd.raw_pwr_cl_200_195 == in mmc_compare_ext_csds()
763 (card->ext_csd.raw_pwr_cl_200_360 == in mmc_compare_ext_csds()
765 (card->ext_csd.raw_pwr_cl_ddr_52_195 == in mmc_compare_ext_csds()
767 (card->ext_csd.raw_pwr_cl_ddr_52_360 == in mmc_compare_ext_csds()
769 (card->ext_csd.raw_pwr_cl_ddr_200_360 == in mmc_compare_ext_csds()
773 err = -EINVAL; in mmc_compare_ext_csds()
779 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
780 card->raw_cid[2], card->raw_cid[3]);
781 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
782 card->raw_csd[2], card->raw_csd[3]);
783 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
784 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
785 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
786 MMC_DEV_ATTR(wp_grp_size, "%u\n", card->wp_grp_size << 9);
787 MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
788 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
789 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
790 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
791 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
792 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
793 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
794 MMC_DEV_ATTR(pre_eol_info, "0x%02x\n", card->ext_csd.pre_eol_info);
796 card->ext_csd.device_life_time_est_typ_a,
797 card->ext_csd.device_life_time_est_typ_b);
798 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
800 card->ext_csd.enhanced_area_offset);
801 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
802 MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
804 card->ext_csd.enhanced_rpmb_supported);
805 MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
806 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
807 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
808 MMC_DEV_ATTR(cmdq_en, "%d\n", card->ext_csd.cmdq_en);
816 if (card->ext_csd.rev < 7) in mmc_fwrev_show()
817 return sysfs_emit(buf, "0x%x\n", card->cid.fwrev); in mmc_fwrev_show()
820 card->ext_csd.fwrev); in mmc_fwrev_show()
830 struct mmc_host *host = card->host; in mmc_dsr_show()
832 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
833 return sysfs_emit(buf, "0x%x\n", host->dsr); in mmc_dsr_show()
885 struct mmc_host *host = card->host; in __mmc_select_powerclass()
886 struct mmc_ext_csd *ext_csd = &card->ext_csd; in __mmc_select_powerclass()
890 switch (1 << host->ios.vdd) { in __mmc_select_powerclass()
892 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) in __mmc_select_powerclass()
893 pwrclass_val = ext_csd->raw_pwr_cl_26_195; in __mmc_select_powerclass()
894 else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) in __mmc_select_powerclass()
896 ext_csd->raw_pwr_cl_52_195 : in __mmc_select_powerclass()
897 ext_csd->raw_pwr_cl_ddr_52_195; in __mmc_select_powerclass()
898 else if (host->ios.clock <= MMC_HS200_MAX_DTR) in __mmc_select_powerclass()
899 pwrclass_val = ext_csd->raw_pwr_cl_200_195; in __mmc_select_powerclass()
910 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) in __mmc_select_powerclass()
911 pwrclass_val = ext_csd->raw_pwr_cl_26_360; in __mmc_select_powerclass()
912 else if (host->ios.clock <= MMC_HIGH_52_MAX_DTR) in __mmc_select_powerclass()
914 ext_csd->raw_pwr_cl_52_360 : in __mmc_select_powerclass()
915 ext_csd->raw_pwr_cl_ddr_52_360; in __mmc_select_powerclass()
916 else if (host->ios.clock <= MMC_HS200_MAX_DTR) in __mmc_select_powerclass()
918 ext_csd->raw_pwr_cl_ddr_200_360 : in __mmc_select_powerclass()
919 ext_csd->raw_pwr_cl_200_360; in __mmc_select_powerclass()
924 return -EINVAL; in __mmc_select_powerclass()
939 card->ext_csd.generic_cmd6_time); in __mmc_select_powerclass()
947 struct mmc_host *host = card->host; in mmc_select_powerclass()
955 bus_width = host->ios.bus_width; in mmc_select_powerclass()
960 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; in mmc_select_powerclass()
981 unsigned int max_dtr = (unsigned int)-1; in mmc_set_bus_speed()
984 max_dtr > card->ext_csd.hs200_max_dtr) in mmc_set_bus_speed()
985 max_dtr = card->ext_csd.hs200_max_dtr; in mmc_set_bus_speed()
986 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr) in mmc_set_bus_speed()
987 max_dtr = card->ext_csd.hs_max_dtr; in mmc_set_bus_speed()
988 else if (max_dtr > card->csd.max_dtr) in mmc_set_bus_speed()
989 max_dtr = card->csd.max_dtr; in mmc_set_bus_speed()
991 mmc_set_clock(card->host, max_dtr); in mmc_set_bus_speed()
995 * Select the bus width amoung 4-bit and 8-bit(SDR).
1011 struct mmc_host *host = card->host; in mmc_select_bus_width()
1016 !(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) in mmc_select_bus_width()
1019 idx = (host->caps & MMC_CAP_8_BIT_DATA) ? 0 : 1; in mmc_select_bus_width()
1038 card->ext_csd.generic_cmd6_time); in mmc_select_bus_width()
1050 if (!(host->caps & MMC_CAP_BUS_WIDTH_TEST)) in mmc_select_bus_width()
1068 * Switch to the high-speed mode
1076 card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_HS, in mmc_select_hs()
1079 pr_warn("%s: switch to high-speed failed, err:%d\n", in mmc_select_hs()
1080 mmc_hostname(card->host), err); in mmc_select_hs()
1090 struct mmc_host *host = card->host; in mmc_select_hs_ddr()
1094 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52)) in mmc_select_hs_ddr()
1097 bus_width = host->ios.bus_width; in mmc_select_hs_ddr()
1107 card->ext_csd.generic_cmd6_time, in mmc_select_hs_ddr()
1141 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) { in mmc_select_hs_ddr()
1147 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_8V && in mmc_select_hs_ddr()
1148 host->caps & MMC_CAP_1_8V_DDR) in mmc_select_hs_ddr()
1160 struct mmc_host *host = card->host; in mmc_select_hs400()
1166 * HS400 mode requires 8-bit bus width in mmc_select_hs400()
1168 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_select_hs400()
1169 host->ios.bus_width == MMC_BUS_WIDTH_8)) in mmc_select_hs400()
1176 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1179 pr_err("%s: switch to high-speed from hs200 failed, err:%d\n", in mmc_select_hs400()
1185 if (host->ops->hs400_downgrade) in mmc_select_hs400()
1186 host->ops->hs400_downgrade(host); in mmc_select_hs400()
1192 max_dtr = card->ext_csd.hs_max_dtr; in mmc_select_hs400()
1199 if (host->ops->hs400_prepare_ddr) in mmc_select_hs400()
1200 host->ops->hs400_prepare_ddr(host); in mmc_select_hs400()
1206 card->ext_csd.generic_cmd6_time); in mmc_select_hs400()
1215 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400()
1218 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1230 if (host->ops->execute_hs400_tuning) { in mmc_select_hs400()
1232 err = host->ops->execute_hs400_tuning(host, card); in mmc_select_hs400()
1238 if (host->ops->hs400_complete) in mmc_select_hs400()
1239 host->ops->hs400_complete(host); in mmc_select_hs400()
1248 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400()
1260 struct mmc_host *host = card->host; in mmc_hs400_to_hs200()
1266 max_dtr = card->ext_csd.hs_max_dtr; in mmc_hs400_to_hs200()
1272 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1277 if (host->ops->hs400_downgrade) in mmc_hs400_to_hs200()
1278 host->ops->hs400_downgrade(host); in mmc_hs400_to_hs200()
1288 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1301 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_hs400_to_hs200()
1303 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1322 if (host->ops->prepare_hs400_tuning) in mmc_hs400_to_hs200()
1323 host->ops->prepare_hs400_tuning(host, &host->ios); in mmc_hs400_to_hs200()
1328 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_hs400_to_hs200()
1336 int fixed_drv_type = card->host->fixed_drv_type; in mmc_select_driver_type()
1338 card_drv_type = card->ext_csd.raw_driver_strength | in mmc_select_driver_type()
1346 card->ext_csd.hs200_max_dtr, in mmc_select_driver_type()
1349 card->drive_strength = drive_strength; in mmc_select_driver_type()
1352 mmc_set_driver_type(card->host, drv_type); in mmc_select_driver_type()
1357 struct mmc_host *host = card->host; in mmc_select_hs400es()
1358 int err = -EINVAL; in mmc_select_hs400es()
1361 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) in mmc_select_hs400es()
1364 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) in mmc_select_hs400es()
1375 err = err < 0 ? err : -ENOTSUPP; in mmc_select_hs400es()
1382 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1406 card->ext_csd.generic_cmd6_time); in mmc_select_hs400es()
1417 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400es()
1420 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1432 host->ios.enhanced_strobe = true; in mmc_select_hs400es()
1433 if (host->ops->hs400_enhanced_strobe) in mmc_select_hs400es()
1434 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_select_hs400es()
1443 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400es()
1451 * 1. set the desired bus width(4-bit or 8-bit, 1-bit is not supported)
1457 struct mmc_host *host = card->host; in mmc_select_hs200()
1459 int err = -EINVAL; in mmc_select_hs200()
1462 old_signal_voltage = host->ios.signal_voltage; in mmc_select_hs200()
1463 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) in mmc_select_hs200()
1466 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) in mmc_select_hs200()
1482 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs200()
1485 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs200()
1496 old_timing = host->ios.timing; in mmc_select_hs200()
1497 old_clock = host->ios.clock; in mmc_select_hs200()
1499 mmc_set_clock(card->host, card->ext_csd.hs_max_dtr); in mmc_select_hs200()
1512 if (err == -EBADMSG) { in mmc_select_hs200()
1521 err = -EIO; in mmc_select_hs200()
1523 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs200()
1539 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400ES) { in mmc_select_timing()
1544 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) { in mmc_select_timing()
1546 if (err == -EBADMSG) in mmc_select_timing()
1547 card->mmc_avail_type &= ~EXT_CSD_CARD_TYPE_HS200; in mmc_select_timing()
1552 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS) in mmc_select_timing()
1556 if (err && err != -EBADMSG) in mmc_select_timing()
1574 struct mmc_host *host = card->host; in mmc_hs200_tuning()
1580 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_hs200_tuning()
1581 host->ios.bus_width == MMC_BUS_WIDTH_8) in mmc_hs200_tuning()
1582 if (host->ops->prepare_hs400_tuning) in mmc_hs200_tuning()
1583 host->ops->prepare_hs400_tuning(host, &host->ios); in mmc_hs200_tuning()
1602 WARN_ON(!host->claimed); in mmc_init_card()
1639 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { in mmc_init_card()
1642 err = -ENOENT; in mmc_init_card()
1657 card->ocr = ocr; in mmc_init_card()
1658 card->type = MMC_TYPE_MMC; in mmc_init_card()
1659 card->rca = 1; in mmc_init_card()
1660 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_init_card()
1666 if (host->ops->init_card) in mmc_init_card()
1667 host->ops->init_card(host, card); in mmc_init_card()
1684 err = mmc_send_csd(card, card->raw_csd); in mmc_init_card()
1700 if (card->csd.dsr_imp && host->dsr_req) in mmc_init_card()
1721 * addressing. See section 8.1 JEDEC Standard JED84-A441; in mmc_init_card()
1738 if (card->ext_csd.rev >= 3) { in mmc_init_card()
1741 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1743 if (err && err != -EBADMSG) in mmc_init_card()
1752 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_init_card()
1753 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_init_card()
1755 card->ext_csd.erase_group_def = 1; in mmc_init_card()
1768 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { in mmc_init_card()
1769 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; in mmc_init_card()
1771 card->ext_csd.part_config, in mmc_init_card()
1772 card->ext_csd.part_time); in mmc_init_card()
1773 if (err && err != -EBADMSG) in mmc_init_card()
1780 if (card->ext_csd.rev >= 6) { in mmc_init_card()
1784 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1785 if (err && err != -EBADMSG) in mmc_init_card()
1789 * The err can be -EBADMSG or 0, in mmc_init_card()
1793 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; in mmc_init_card()
1798 card->erase_arg = MMC_DISCARD_ARG; in mmc_init_card()
1800 card->erase_arg = MMC_TRIM_ARG; in mmc_init_card()
1802 card->erase_arg = MMC_ERASE_ARG; in mmc_init_card()
1812 host->doing_init_tune = 1; in mmc_init_card()
1818 host->doing_init_tune = 0; in mmc_init_card()
1823 if (host->ops->execute_hs400_tuning) { in mmc_init_card()
1824 err = host->ops->execute_hs400_tuning(host, card); in mmc_init_card()
1844 * Enable HPI feature (if supported) in mmc_init_card()
1846 if (card->ext_csd.hpi) { in mmc_init_card()
1849 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1850 if (err && err != -EBADMSG) in mmc_init_card()
1853 pr_warn("%s: Enabling HPI failed\n", in mmc_init_card()
1854 mmc_hostname(card->host)); in mmc_init_card()
1855 card->ext_csd.hpi_en = 0; in mmc_init_card()
1857 card->ext_csd.hpi_en = 1; in mmc_init_card()
1868 if (card->ext_csd.cache_size > 0) { in mmc_init_card()
1871 timeout_ms = max(card->ext_csd.generic_cmd6_time, timeout_ms); in mmc_init_card()
1874 if (err && err != -EBADMSG) in mmc_init_card()
1882 mmc_hostname(card->host), err); in mmc_init_card()
1883 card->ext_csd.cache_ctrl = 0; in mmc_init_card()
1885 card->ext_csd.cache_ctrl = 1; in mmc_init_card()
1893 card->ext_csd.cmdq_en = false; in mmc_init_card()
1894 if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) { in mmc_init_card()
1896 if (err && err != -EBADMSG) in mmc_init_card()
1900 mmc_hostname(card->host)); in mmc_init_card()
1901 card->ext_csd.cmdq_support = false; in mmc_init_card()
1902 card->ext_csd.cmdq_depth = 0; in mmc_init_card()
1907 * disabled for a time, so a flag is needed to indicate to re-enable the in mmc_init_card()
1910 card->reenable_cmdq = card->ext_csd.cmdq_en; in mmc_init_card()
1912 if (host->cqe_ops && !host->cqe_enabled) { in mmc_init_card()
1913 err = host->cqe_ops->cqe_enable(host, card); in mmc_init_card()
1915 host->cqe_enabled = true; in mmc_init_card()
1917 if (card->ext_csd.cmdq_en) { in mmc_init_card()
1921 host->hsq_enabled = true; in mmc_init_card()
1928 if (host->caps2 & MMC_CAP2_AVOID_3_3V && in mmc_init_card()
1929 host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in mmc_init_card()
1932 err = -EINVAL; in mmc_init_card()
1937 host->card = card; in mmc_init_card()
1950 return card->ext_csd.rev >= 3; in mmc_can_sleep()
1957 *busy = host->ops->card_busy(host); in mmc_sleep_busy_cb()
1964 struct mmc_card *card = host->card; in mmc_sleep()
1965 unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); in mmc_sleep()
1969 /* Re-tuning can't be done once the card is deselected */ in mmc_sleep()
1977 cmd.arg = card->rca << 16; in mmc_sleep()
1991 if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp) in mmc_sleep()
1994 if (!host->ops->card_busy) { in mmc_sleep()
2010 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); in mmc_can_poweroff_notify()
2015 unsigned int timeout = card->ext_csd.generic_cmd6_time; in mmc_poweroff_notify()
2020 timeout = card->ext_csd.power_off_longtime; in mmc_poweroff_notify()
2027 mmc_hostname(card->host), timeout); in mmc_poweroff_notify()
2030 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; in mmc_poweroff_notify()
2040 mmc_remove_card(host->card); in mmc_remove()
2041 host->card = NULL; in mmc_remove()
2045 * Card detection - card is alive.
2049 return mmc_send_status(host->card, NULL); in mmc_alive()
2059 mmc_get_card(host->card, NULL); in mmc_detect()
2066 mmc_put_card(host->card, NULL); in mmc_detect()
2080 return host->card->ext_csd.cache_size > 0 && in _mmc_cache_enabled()
2081 host->card->ext_csd.cache_ctrl & 1; in _mmc_cache_enabled()
2085 * Flush the internal cache of the eMMC to non-volatile storage.
2091 if (mmc_card_broken_cache_flush(host->card) && !host->card->written_flag) in _mmc_flush_cache()
2095 err = mmc_switch(host->card, EXT_CSD_CMD_SET_NORMAL, in _mmc_flush_cache()
2101 host->card->written_flag = false; in _mmc_flush_cache()
2115 if (mmc_card_suspended(host->card)) in _mmc_suspend()
2122 if (mmc_can_poweroff_notify(host->card) && in _mmc_suspend()
2123 ((host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) || !is_suspend || in _mmc_suspend()
2124 (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND))) in _mmc_suspend()
2125 err = mmc_poweroff_notify(host->card, notify_type); in _mmc_suspend()
2126 else if (mmc_can_sleep(host->card)) in _mmc_suspend()
2133 mmc_card_set_suspended(host->card); in _mmc_suspend()
2149 pm_runtime_disable(&host->card->dev); in mmc_suspend()
2150 pm_runtime_set_suspended(&host->card->dev); in mmc_suspend()
2166 if (!mmc_card_suspended(host->card)) in _mmc_resume()
2169 mmc_power_up(host, host->card->ocr); in _mmc_resume()
2170 err = mmc_init_card(host, host->card->ocr, host->card); in _mmc_resume()
2171 mmc_card_clr_suspended(host->card); in _mmc_resume()
2189 if (mmc_can_poweroff_notify(host->card) && in mmc_shutdown()
2190 !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE)) in mmc_shutdown()
2204 pm_runtime_enable(&host->card->dev); in mmc_resume()
2215 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) in mmc_runtime_suspend()
2234 if (err && err != -ENOMEDIUM) in mmc_runtime_resume()
2245 rst_n_function = card->ext_csd.rst_n_function; in mmc_can_reset()
2253 struct mmc_card *card = host->card; in _mmc_hw_reset()
2261 if ((host->caps & MMC_CAP_HW_RESET) && host->ops->card_hw_reset && in _mmc_hw_reset()
2264 mmc_set_clock(host, host->f_init); in _mmc_hw_reset()
2265 host->ops->card_hw_reset(host); in _mmc_hw_reset()
2270 mmc_power_cycle(host, card->ocr); in _mmc_hw_reset()
2273 return mmc_init_card(host, card->ocr, card); in _mmc_hw_reset()
2298 WARN_ON(!host->claimed); in mmc_attach_mmc()
2309 if (host->ocr_avail_mmc) in mmc_attach_mmc()
2310 host->ocr_avail = host->ocr_avail_mmc; in mmc_attach_mmc()
2327 err = -EINVAL; in mmc_attach_mmc()
2339 err = mmc_add_card(host->card); in mmc_attach_mmc()
2347 mmc_remove_card(host->card); in mmc_attach_mmc()
2349 host->card = NULL; in mmc_attach_mmc()