Lines Matching full:card

19 #include <linux/mmc/card.h>
23 #include "card.h"
71 static int mmc_decode_cid(struct mmc_card *card) in mmc_decode_cid() argument
73 u32 *resp = card->raw_cid; in mmc_decode_cid()
76 * Add the raw card ID (cid) data to the entropy pool. It doesn't in mmc_decode_cid()
79 add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); in mmc_decode_cid()
85 switch (card->csd.mmca_vsn) { in mmc_decode_cid()
88 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); in mmc_decode_cid()
89 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
90 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
91 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
92 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
93 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
94 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
95 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
96 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); in mmc_decode_cid()
97 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); in mmc_decode_cid()
98 card->cid.serial = UNSTUFF_BITS(resp, 16, 24); in mmc_decode_cid()
99 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
100 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
106 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); in mmc_decode_cid()
107 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); in mmc_decode_cid()
108 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
109 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
110 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
111 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
112 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
113 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
114 card->cid.prv = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
115 card->cid.serial = UNSTUFF_BITS(resp, 16, 32); in mmc_decode_cid()
116 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
117 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
121 pr_err("%s: card has unknown MMCA version %d\n", in mmc_decode_cid()
122 mmc_hostname(card->host), card->csd.mmca_vsn); in mmc_decode_cid()
129 static void mmc_set_erase_size(struct mmc_card *card) in mmc_set_erase_size() argument
131 if (card->ext_csd.erase_group_def & 1) in mmc_set_erase_size()
132 card->erase_size = card->ext_csd.hc_erase_size; in mmc_set_erase_size()
134 card->erase_size = card->csd.erase_size; in mmc_set_erase_size()
136 mmc_init_erase(card); in mmc_set_erase_size()
140 * Given a 128-bit response, decode to our card CSD structure.
142 static int mmc_decode_csd(struct mmc_card *card) in mmc_decode_csd() argument
144 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
146 u32 *resp = card->raw_csd; in mmc_decode_csd()
156 mmc_hostname(card->host), csd->structure); in mmc_decode_csd()
194 static void mmc_select_card_type(struct mmc_card *card) in mmc_select_card_type() argument
196 struct mmc_host *host = card->host; in mmc_select_card_type()
197 u8 card_type = card->ext_csd.raw_card_type; in mmc_select_card_type()
251 card->ext_csd.strobe_support && in mmc_select_card_type()
255 card->ext_csd.hs_max_dtr = hs_max_dtr; in mmc_select_card_type()
256 card->ext_csd.hs200_max_dtr = hs200_max_dtr; in mmc_select_card_type()
257 card->mmc_avail_type = avail_type; in mmc_select_card_type()
260 static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd) in mmc_manage_enhanced_area() argument
267 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_manage_enhanced_area()
268 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_manage_enhanced_area()
272 * card has the Enhanced area enabled. If so, export enhanced in mmc_manage_enhanced_area()
277 if (card->ext_csd.partition_setting_completed) { in mmc_manage_enhanced_area()
286 card->ext_csd.enhanced_area_offset = in mmc_manage_enhanced_area()
291 if (mmc_card_blockaddr(card)) in mmc_manage_enhanced_area()
292 card->ext_csd.enhanced_area_offset <<= 9; in mmc_manage_enhanced_area()
296 card->ext_csd.enhanced_area_size = in mmc_manage_enhanced_area()
299 card->ext_csd.enhanced_area_size *= in mmc_manage_enhanced_area()
301 card->ext_csd.enhanced_area_size <<= 9; in mmc_manage_enhanced_area()
304 mmc_hostname(card->host)); in mmc_manage_enhanced_area()
309 static void mmc_part_add(struct mmc_card *card, u64 size, in mmc_part_add() argument
313 card->part[card->nr_parts].size = size; in mmc_part_add()
314 card->part[card->nr_parts].part_cfg = part_cfg; in mmc_part_add()
315 sprintf(card->part[card->nr_parts].name, name, idx); in mmc_part_add()
316 card->part[card->nr_parts].force_ro = ro; in mmc_part_add()
317 card->part[card->nr_parts].area_type = area_type; in mmc_part_add()
318 card->nr_parts++; in mmc_part_add()
321 static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd) in mmc_manage_gp_partitions() argument
344 if (card->ext_csd.partition_setting_completed == 0) { in mmc_manage_gp_partitions()
346 mmc_hostname(card->host)); in mmc_manage_gp_partitions()
356 mmc_part_add(card, part_size << 19, in mmc_manage_gp_partitions()
370 static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) in mmc_decode_ext_csd() argument
378 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; in mmc_decode_ext_csd()
379 if (card->csd.structure == 3) { in mmc_decode_ext_csd()
380 if (card->ext_csd.raw_ext_csd_structure > 2) { in mmc_decode_ext_csd()
382 "version %d\n", mmc_hostname(card->host), in mmc_decode_ext_csd()
383 card->ext_csd.raw_ext_csd_structure); in mmc_decode_ext_csd()
389 np = mmc_of_find_child_device(card->host, 0); in mmc_decode_ext_csd()
390 if (np && of_device_is_compatible(np, "mmc-card")) in mmc_decode_ext_csd()
399 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; in mmc_decode_ext_csd()
402 mmc_fixup_device(card, mmc_ext_csd_fixups); in mmc_decode_ext_csd()
404 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; in mmc_decode_ext_csd()
405 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; in mmc_decode_ext_csd()
406 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; in mmc_decode_ext_csd()
407 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; in mmc_decode_ext_csd()
408 if (card->ext_csd.rev >= 2) { in mmc_decode_ext_csd()
409 card->ext_csd.sectors = in mmc_decode_ext_csd()
416 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) in mmc_decode_ext_csd()
417 mmc_card_set_blockaddr(card); in mmc_decode_ext_csd()
420 card->ext_csd.strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT]; in mmc_decode_ext_csd()
421 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; in mmc_decode_ext_csd()
422 mmc_select_card_type(card); in mmc_decode_ext_csd()
424 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; in mmc_decode_ext_csd()
425 card->ext_csd.raw_erase_timeout_mult = in mmc_decode_ext_csd()
427 card->ext_csd.raw_hc_erase_grp_size = in mmc_decode_ext_csd()
429 card->ext_csd.raw_boot_mult = in mmc_decode_ext_csd()
431 if (card->ext_csd.rev >= 3) { in mmc_decode_ext_csd()
433 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; in mmc_decode_ext_csd()
436 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; in mmc_decode_ext_csd()
440 card->ext_csd.sa_timeout = in mmc_decode_ext_csd()
442 card->ext_csd.erase_group_def = in mmc_decode_ext_csd()
444 card->ext_csd.hc_erase_timeout = 300 * in mmc_decode_ext_csd()
446 card->ext_csd.hc_erase_size = in mmc_decode_ext_csd()
449 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; in mmc_decode_ext_csd()
455 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { in mmc_decode_ext_csd()
458 mmc_part_add(card, part_size, in mmc_decode_ext_csd()
466 card->ext_csd.raw_hc_erase_gap_size = in mmc_decode_ext_csd()
468 card->ext_csd.raw_sec_trim_mult = in mmc_decode_ext_csd()
470 card->ext_csd.raw_sec_erase_mult = in mmc_decode_ext_csd()
472 card->ext_csd.raw_sec_feature_support = in mmc_decode_ext_csd()
474 card->ext_csd.raw_trim_mult = in mmc_decode_ext_csd()
476 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; in mmc_decode_ext_csd()
477 card->ext_csd.raw_driver_strength = ext_csd[EXT_CSD_DRIVER_STRENGTH]; in mmc_decode_ext_csd()
478 if (card->ext_csd.rev >= 4) { in mmc_decode_ext_csd()
481 card->ext_csd.partition_setting_completed = 1; in mmc_decode_ext_csd()
483 card->ext_csd.partition_setting_completed = 0; in mmc_decode_ext_csd()
485 mmc_manage_enhanced_area(card, ext_csd); in mmc_decode_ext_csd()
487 mmc_manage_gp_partitions(card, ext_csd); in mmc_decode_ext_csd()
489 card->ext_csd.sec_trim_mult = in mmc_decode_ext_csd()
491 card->ext_csd.sec_erase_mult = in mmc_decode_ext_csd()
493 card->ext_csd.sec_feature_support = in mmc_decode_ext_csd()
495 card->ext_csd.trim_timeout = 300 * in mmc_decode_ext_csd()
503 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; in mmc_decode_ext_csd()
504 card->ext_csd.boot_ro_lockable = true; in mmc_decode_ext_csd()
507 card->ext_csd.raw_pwr_cl_52_195 = in mmc_decode_ext_csd()
509 card->ext_csd.raw_pwr_cl_26_195 = in mmc_decode_ext_csd()
511 card->ext_csd.raw_pwr_cl_52_360 = in mmc_decode_ext_csd()
513 card->ext_csd.raw_pwr_cl_26_360 = in mmc_decode_ext_csd()
515 card->ext_csd.raw_pwr_cl_200_195 = in mmc_decode_ext_csd()
517 card->ext_csd.raw_pwr_cl_200_360 = in mmc_decode_ext_csd()
519 card->ext_csd.raw_pwr_cl_ddr_52_195 = in mmc_decode_ext_csd()
521 card->ext_csd.raw_pwr_cl_ddr_52_360 = in mmc_decode_ext_csd()
523 card->ext_csd.raw_pwr_cl_ddr_200_360 = in mmc_decode_ext_csd()
527 if (card->ext_csd.rev >= 5) { in mmc_decode_ext_csd()
529 if (card->cid.year < 2010) in mmc_decode_ext_csd()
530 card->cid.year += 16; in mmc_decode_ext_csd()
532 /* check whether the eMMC card supports BKOPS */ in mmc_decode_ext_csd()
534 card->ext_csd.bkops = 1; in mmc_decode_ext_csd()
535 card->ext_csd.man_bkops_en = in mmc_decode_ext_csd()
538 card->ext_csd.raw_bkops_status = in mmc_decode_ext_csd()
540 if (card->ext_csd.man_bkops_en) in mmc_decode_ext_csd()
542 mmc_hostname(card->host)); in mmc_decode_ext_csd()
543 card->ext_csd.auto_bkops_en = in mmc_decode_ext_csd()
546 if (card->ext_csd.auto_bkops_en) in mmc_decode_ext_csd()
548 mmc_hostname(card->host)); in mmc_decode_ext_csd()
551 /* check whether the eMMC card supports HPI */ in mmc_decode_ext_csd()
552 if (!mmc_card_broken_hpi(card) && in mmc_decode_ext_csd()
554 card->ext_csd.hpi = 1; in mmc_decode_ext_csd()
556 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; in mmc_decode_ext_csd()
558 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; in mmc_decode_ext_csd()
563 card->ext_csd.out_of_int_time = in mmc_decode_ext_csd()
567 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; in mmc_decode_ext_csd()
568 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; in mmc_decode_ext_csd()
573 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; in mmc_decode_ext_csd()
574 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { in mmc_decode_ext_csd()
575 mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, in mmc_decode_ext_csd()
582 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; in mmc_decode_ext_csd()
584 card->erased_byte = 0xFF; in mmc_decode_ext_csd()
586 card->erased_byte = 0x0; in mmc_decode_ext_csd()
589 card->ext_csd.generic_cmd6_time = DEFAULT_CMD6_TIMEOUT_MS; in mmc_decode_ext_csd()
590 if (card->ext_csd.rev >= 6) { in mmc_decode_ext_csd()
591 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; in mmc_decode_ext_csd()
593 card->ext_csd.generic_cmd6_time = 10 * in mmc_decode_ext_csd()
595 card->ext_csd.power_off_longtime = 10 * in mmc_decode_ext_csd()
598 card->ext_csd.cache_size = in mmc_decode_ext_csd()
605 card->ext_csd.data_sector_size = 4096; in mmc_decode_ext_csd()
607 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
611 card->ext_csd.data_tag_unit_size = in mmc_decode_ext_csd()
613 (card->ext_csd.data_sector_size); in mmc_decode_ext_csd()
615 card->ext_csd.data_tag_unit_size = 0; in mmc_decode_ext_csd()
618 card->ext_csd.max_packed_writes = in mmc_decode_ext_csd()
620 card->ext_csd.max_packed_reads = in mmc_decode_ext_csd()
623 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
631 if (!card->ext_csd.part_time) in mmc_decode_ext_csd()
632 card->ext_csd.part_time = card->ext_csd.generic_cmd6_time; in mmc_decode_ext_csd()
634 if (card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME) in mmc_decode_ext_csd()
635 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME; in mmc_decode_ext_csd()
638 if (card->ext_csd.rev >= 7) { in mmc_decode_ext_csd()
639 memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION], in mmc_decode_ext_csd()
641 card->ext_csd.ffu_capable = in mmc_decode_ext_csd()
645 card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; in mmc_decode_ext_csd()
646 card->ext_csd.device_life_time_est_typ_a = in mmc_decode_ext_csd()
648 card->ext_csd.device_life_time_est_typ_b = in mmc_decode_ext_csd()
653 if (card->ext_csd.rev >= 8) { in mmc_decode_ext_csd()
654 card->ext_csd.cmdq_support = ext_csd[EXT_CSD_CMDQ_SUPPORT] & in mmc_decode_ext_csd()
656 card->ext_csd.cmdq_depth = (ext_csd[EXT_CSD_CMDQ_DEPTH] & in mmc_decode_ext_csd()
659 if (card->ext_csd.cmdq_depth <= 2) { in mmc_decode_ext_csd()
660 card->ext_csd.cmdq_support = false; in mmc_decode_ext_csd()
661 card->ext_csd.cmdq_depth = 0; in mmc_decode_ext_csd()
663 if (card->ext_csd.cmdq_support) { in mmc_decode_ext_csd()
665 mmc_hostname(card->host), in mmc_decode_ext_csd()
666 card->ext_csd.cmdq_depth); in mmc_decode_ext_csd()
668 card->ext_csd.enhanced_rpmb_supported = in mmc_decode_ext_csd()
669 (card->ext_csd.rel_param & in mmc_decode_ext_csd()
676 static int mmc_read_ext_csd(struct mmc_card *card) in mmc_read_ext_csd() argument
681 if (!mmc_can_ext_csd(card)) in mmc_read_ext_csd()
684 err = mmc_get_ext_csd(card, &ext_csd); in mmc_read_ext_csd()
686 /* If the host or the card can't do the switch, in mmc_read_ext_csd()
697 if (card->csd.capacity == (4096 * 512)) { in mmc_read_ext_csd()
698 pr_err("%s: unable to read EXT_CSD on a possible high capacity card. Card will be ignored.\n", in mmc_read_ext_csd()
699 mmc_hostname(card->host)); in mmc_read_ext_csd()
702 mmc_hostname(card->host)); in mmc_read_ext_csd()
709 err = mmc_decode_ext_csd(card, ext_csd); in mmc_read_ext_csd()
714 static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) in mmc_compare_ext_csds() argument
722 err = mmc_get_ext_csd(card, &bw_ext_csd); in mmc_compare_ext_csds()
727 err = !((card->ext_csd.raw_partition_support == in mmc_compare_ext_csds()
729 (card->ext_csd.raw_erased_mem_count == in mmc_compare_ext_csds()
731 (card->ext_csd.rev == in mmc_compare_ext_csds()
733 (card->ext_csd.raw_ext_csd_structure == in mmc_compare_ext_csds()
735 (card->ext_csd.raw_card_type == in mmc_compare_ext_csds()
737 (card->ext_csd.raw_s_a_timeout == in mmc_compare_ext_csds()
739 (card->ext_csd.raw_hc_erase_gap_size == in mmc_compare_ext_csds()
741 (card->ext_csd.raw_erase_timeout_mult == in mmc_compare_ext_csds()
743 (card->ext_csd.raw_hc_erase_grp_size == in mmc_compare_ext_csds()
745 (card->ext_csd.raw_sec_trim_mult == in mmc_compare_ext_csds()
747 (card->ext_csd.raw_sec_erase_mult == in mmc_compare_ext_csds()
749 (card->ext_csd.raw_sec_feature_support == in mmc_compare_ext_csds()
751 (card->ext_csd.raw_trim_mult == in mmc_compare_ext_csds()
753 (card->ext_csd.raw_sectors[0] == in mmc_compare_ext_csds()
755 (card->ext_csd.raw_sectors[1] == in mmc_compare_ext_csds()
757 (card->ext_csd.raw_sectors[2] == in mmc_compare_ext_csds()
759 (card->ext_csd.raw_sectors[3] == in mmc_compare_ext_csds()
761 (card->ext_csd.raw_pwr_cl_52_195 == in mmc_compare_ext_csds()
763 (card->ext_csd.raw_pwr_cl_26_195 == in mmc_compare_ext_csds()
765 (card->ext_csd.raw_pwr_cl_52_360 == in mmc_compare_ext_csds()
767 (card->ext_csd.raw_pwr_cl_26_360 == in mmc_compare_ext_csds()
769 (card->ext_csd.raw_pwr_cl_200_195 == in mmc_compare_ext_csds()
771 (card->ext_csd.raw_pwr_cl_200_360 == in mmc_compare_ext_csds()
773 (card->ext_csd.raw_pwr_cl_ddr_52_195 == in mmc_compare_ext_csds()
775 (card->ext_csd.raw_pwr_cl_ddr_52_360 == in mmc_compare_ext_csds()
777 (card->ext_csd.raw_pwr_cl_ddr_200_360 == in mmc_compare_ext_csds()
787 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
788 card->raw_cid[2], card->raw_cid[3]);
789 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
790 card->raw_csd[2], card->raw_csd[3]);
791 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
792 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
793 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
794 MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
795 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
796 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
797 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
798 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
799 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
800 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
801 MMC_DEV_ATTR(pre_eol_info, "0x%02x\n", card->ext_csd.pre_eol_info);
803 card->ext_csd.device_life_time_est_typ_a,
804 card->ext_csd.device_life_time_est_typ_b);
805 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
807 card->ext_csd.enhanced_area_offset);
808 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
809 MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
811 card->ext_csd.enhanced_rpmb_supported);
812 MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
813 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
814 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
815 MMC_DEV_ATTR(cmdq_en, "%d\n", card->ext_csd.cmdq_en);
821 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_fwrev_show() local
823 if (card->ext_csd.rev < 7) in mmc_fwrev_show()
824 return sysfs_emit(buf, "0x%x\n", card->cid.fwrev); in mmc_fwrev_show()
827 card->ext_csd.fwrev); in mmc_fwrev_show()
836 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_dsr_show() local
837 struct mmc_host *host = card->host; in mmc_dsr_show()
839 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
888 static int __mmc_select_powerclass(struct mmc_card *card, in __mmc_select_powerclass() argument
891 struct mmc_host *host = card->host; in __mmc_select_powerclass()
892 struct mmc_ext_csd *ext_csd = &card->ext_csd; in __mmc_select_powerclass()
942 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in __mmc_select_powerclass()
945 card->ext_csd.generic_cmd6_time); in __mmc_select_powerclass()
951 static int mmc_select_powerclass(struct mmc_card *card) in mmc_select_powerclass() argument
953 struct mmc_host *host = card->host; in mmc_select_powerclass()
958 if (!mmc_can_ext_csd(card)) in mmc_select_powerclass()
966 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; in mmc_select_powerclass()
974 err = __mmc_select_powerclass(card, ext_csd_bits); in mmc_select_powerclass()
985 static void mmc_set_bus_speed(struct mmc_card *card) in mmc_set_bus_speed() argument
989 if ((mmc_card_hs200(card) || mmc_card_hs400(card)) && in mmc_set_bus_speed()
990 max_dtr > card->ext_csd.hs200_max_dtr) in mmc_set_bus_speed()
991 max_dtr = card->ext_csd.hs200_max_dtr; in mmc_set_bus_speed()
992 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr) in mmc_set_bus_speed()
993 max_dtr = card->ext_csd.hs_max_dtr; in mmc_set_bus_speed()
994 else if (max_dtr > card->csd.max_dtr) in mmc_set_bus_speed()
995 max_dtr = card->csd.max_dtr; in mmc_set_bus_speed()
997 mmc_set_clock(card->host, max_dtr); in mmc_set_bus_speed()
1005 static int mmc_select_bus_width(struct mmc_card *card) in mmc_select_bus_width() argument
1015 struct mmc_host *host = card->host; in mmc_select_bus_width()
1019 if (!mmc_can_ext_csd(card) || in mmc_select_bus_width()
1039 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_bus_width()
1042 card->ext_csd.generic_cmd6_time); in mmc_select_bus_width()
1055 err = mmc_compare_ext_csds(card, bus_width); in mmc_select_bus_width()
1057 err = mmc_bus_test(card, bus_width); in mmc_select_bus_width()
1074 static int mmc_select_hs(struct mmc_card *card) in mmc_select_hs() argument
1078 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs()
1080 card->ext_csd.generic_cmd6_time, MMC_TIMING_MMC_HS, in mmc_select_hs()
1084 mmc_hostname(card->host), err); in mmc_select_hs()
1092 static int mmc_select_hs_ddr(struct mmc_card *card) in mmc_select_hs_ddr() argument
1094 struct mmc_host *host = card->host; in mmc_select_hs_ddr()
1098 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52)) in mmc_select_hs_ddr()
1108 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs_ddr()
1111 card->ext_csd.generic_cmd6_time, in mmc_select_hs_ddr()
1129 * Even (e)MMC card can support 3.3v to 1.2v vccq, but not all in mmc_select_hs_ddr()
1145 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) { in mmc_select_hs_ddr()
1151 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_8V && in mmc_select_hs_ddr()
1162 static int mmc_select_hs400(struct mmc_card *card) in mmc_select_hs400() argument
1164 struct mmc_host *host = card->host; in mmc_select_hs400()
1172 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_select_hs400()
1176 /* Switch card to HS mode */ in mmc_select_hs400()
1178 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1180 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1196 max_dtr = card->ext_csd.hs_max_dtr; in mmc_select_hs400()
1199 err = mmc_switch_status(card, true); in mmc_select_hs400()
1206 /* Switch card to DDR */ in mmc_select_hs400()
1207 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1210 card->ext_csd.generic_cmd6_time); in mmc_select_hs400()
1217 /* Switch card to HS400 */ in mmc_select_hs400()
1219 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400()
1220 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1222 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400()
1232 mmc_set_bus_speed(card); in mmc_select_hs400()
1236 err = host->ops->execute_hs400_tuning(host, card); in mmc_select_hs400()
1245 err = mmc_switch_status(card, true); in mmc_select_hs400()
1252 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400()
1257 int mmc_hs200_to_hs400(struct mmc_card *card) in mmc_hs200_to_hs400() argument
1259 return mmc_select_hs400(card); in mmc_hs200_to_hs400()
1262 int mmc_hs400_to_hs200(struct mmc_card *card) in mmc_hs400_to_hs200() argument
1264 struct mmc_host *host = card->host; in mmc_hs400_to_hs200()
1270 max_dtr = card->ext_csd.hs_max_dtr; in mmc_hs400_to_hs200()
1275 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, in mmc_hs400_to_hs200()
1276 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1286 err = mmc_switch_status(card, true); in mmc_hs400_to_hs200()
1291 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, in mmc_hs400_to_hs200()
1292 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1299 err = mmc_switch_status(card, true); in mmc_hs400_to_hs200()
1305 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_hs400_to_hs200()
1306 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, in mmc_hs400_to_hs200()
1307 val, card->ext_csd.generic_cmd6_time, 0, in mmc_hs400_to_hs200()
1319 err = mmc_switch_status(card, false); in mmc_hs400_to_hs200()
1323 mmc_set_bus_speed(card); in mmc_hs400_to_hs200()
1332 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_hs400_to_hs200()
1337 static void mmc_select_driver_type(struct mmc_card *card) in mmc_select_driver_type() argument
1340 int fixed_drv_type = card->host->fixed_drv_type; in mmc_select_driver_type()
1342 card_drv_type = card->ext_csd.raw_driver_strength | in mmc_select_driver_type()
1349 drive_strength = mmc_select_drive_strength(card, in mmc_select_driver_type()
1350 card->ext_csd.hs200_max_dtr, in mmc_select_driver_type()
1353 card->drive_strength = drive_strength; in mmc_select_driver_type()
1356 mmc_set_driver_type(card->host, drv_type); in mmc_select_driver_type()
1359 static int mmc_select_hs400es(struct mmc_card *card) in mmc_select_hs400es() argument
1361 struct mmc_host *host = card->host; in mmc_select_hs400es()
1365 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) in mmc_select_hs400es()
1368 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) in mmc_select_hs400es()
1371 /* If fails try again during next card power cycle */ in mmc_select_hs400es()
1375 err = mmc_select_bus_width(card); in mmc_select_hs400es()
1383 /* Switch card to HS mode */ in mmc_select_hs400es()
1384 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400es()
1386 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1399 mmc_set_bus_speed(card); in mmc_select_hs400es()
1401 err = mmc_switch_status(card, true); in mmc_select_hs400es()
1405 /* Switch card to DDR with strobe bit */ in mmc_select_hs400es()
1407 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400es()
1410 card->ext_csd.generic_cmd6_time); in mmc_select_hs400es()
1417 mmc_select_driver_type(card); in mmc_select_hs400es()
1419 /* Switch card to HS400 */ in mmc_select_hs400es()
1421 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400es()
1422 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400es()
1424 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs400es()
1440 err = mmc_switch_status(card, true); in mmc_select_hs400es()
1447 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400es()
1459 static int mmc_select_hs200(struct mmc_card *card) in mmc_select_hs200() argument
1461 struct mmc_host *host = card->host; in mmc_select_hs200()
1467 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) in mmc_select_hs200()
1470 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) in mmc_select_hs200()
1473 /* If fails try again during next card power cycle */ in mmc_select_hs200()
1477 mmc_select_driver_type(card); in mmc_select_hs200()
1483 err = mmc_select_bus_width(card); in mmc_select_hs200()
1486 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs200()
1487 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs200()
1489 card->ext_csd.generic_cmd6_time, 0, in mmc_select_hs200()
1503 mmc_set_clock(card->host, card->ext_csd.hs_max_dtr); in mmc_select_hs200()
1510 err = mmc_switch_status(card, false); in mmc_select_hs200()
1527 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs200()
1536 static int mmc_select_timing(struct mmc_card *card) in mmc_select_timing() argument
1540 if (!mmc_can_ext_csd(card)) in mmc_select_timing()
1543 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400ES) { in mmc_select_timing()
1544 err = mmc_select_hs400es(card); in mmc_select_timing()
1548 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) { in mmc_select_timing()
1549 err = mmc_select_hs200(card); in mmc_select_timing()
1551 card->mmc_avail_type &= ~EXT_CSD_CARD_TYPE_HS200; in mmc_select_timing()
1556 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS) in mmc_select_timing()
1557 err = mmc_select_hs(card); in mmc_select_timing()
1568 mmc_set_bus_speed(card); in mmc_select_timing()
1576 static int mmc_hs200_tuning(struct mmc_card *card) in mmc_hs200_tuning() argument
1578 struct mmc_host *host = card->host; in mmc_hs200_tuning()
1584 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_hs200_tuning()
1589 return mmc_execute_tuning(card); in mmc_hs200_tuning()
1593 * Handle the detection and initialisation of a card.
1595 * In the case of a resume, "oldcard" will contain the card
1601 struct mmc_card *card; in mmc_init_card() local
1636 * Fetch CID from card. in mmc_init_card()
1644 pr_debug("%s: Perhaps the card was replaced\n", in mmc_init_card()
1650 card = oldcard; in mmc_init_card()
1653 * Allocate card structure. in mmc_init_card()
1655 card = mmc_alloc_card(host, &mmc_type); in mmc_init_card()
1656 if (IS_ERR(card)) { in mmc_init_card()
1657 err = PTR_ERR(card); in mmc_init_card()
1661 card->ocr = ocr; in mmc_init_card()
1662 card->type = MMC_TYPE_MMC; in mmc_init_card()
1663 card->rca = 1; in mmc_init_card()
1664 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_init_card()
1671 host->ops->init_card(host, card); in mmc_init_card()
1674 * For native busses: set card RCA and quit open drain mode. in mmc_init_card()
1677 err = mmc_set_relative_addr(card); in mmc_init_card()
1686 * Fetch CSD from card. in mmc_init_card()
1688 err = mmc_send_csd(card, card->raw_csd); in mmc_init_card()
1692 err = mmc_decode_csd(card); in mmc_init_card()
1695 err = mmc_decode_cid(card); in mmc_init_card()
1704 if (card->csd.dsr_imp && host->dsr_req) in mmc_init_card()
1708 * Select card, as all following commands rely on that. in mmc_init_card()
1711 err = mmc_select_card(card); in mmc_init_card()
1718 err = mmc_read_ext_csd(card); in mmc_init_card()
1729 mmc_card_set_blockaddr(card); in mmc_init_card()
1732 mmc_set_erase_size(card); in mmc_init_card()
1736 if (card->ext_csd.rev >= 3) { in mmc_init_card()
1737 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1739 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1750 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_init_card()
1751 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_init_card()
1753 card->ext_csd.erase_group_def = 1; in mmc_init_card()
1759 mmc_set_erase_size(card); in mmc_init_card()
1766 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { in mmc_init_card()
1767 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; in mmc_init_card()
1768 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, in mmc_init_card()
1769 card->ext_csd.part_config, in mmc_init_card()
1770 card->ext_csd.part_time); in mmc_init_card()
1778 if (card->ext_csd.rev >= 6) { in mmc_init_card()
1779 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1782 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1791 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; in mmc_init_card()
1795 if (mmc_can_discard(card)) in mmc_init_card()
1796 card->erase_arg = MMC_DISCARD_ARG; in mmc_init_card()
1797 else if (mmc_can_trim(card)) in mmc_init_card()
1798 card->erase_arg = MMC_TRIM_ARG; in mmc_init_card()
1800 card->erase_arg = MMC_ERASE_ARG; in mmc_init_card()
1805 err = mmc_select_timing(card); in mmc_init_card()
1809 if (mmc_card_hs200(card)) { in mmc_init_card()
1812 err = mmc_hs200_tuning(card); in mmc_init_card()
1814 err = mmc_select_hs400(card); in mmc_init_card()
1821 } else if (!mmc_card_hs400es(card)) { in mmc_init_card()
1823 err = mmc_select_bus_width(card); in mmc_init_card()
1824 if (err > 0 && mmc_card_hs(card)) { in mmc_init_card()
1825 err = mmc_select_hs_ddr(card); in mmc_init_card()
1834 mmc_select_powerclass(card); in mmc_init_card()
1839 if (card->ext_csd.hpi) { in mmc_init_card()
1840 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1842 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1847 mmc_hostname(card->host)); in mmc_init_card()
1848 card->ext_csd.hpi_en = 0; in mmc_init_card()
1850 card->ext_csd.hpi_en = 1; in mmc_init_card()
1861 if (card->ext_csd.cache_size > 0) { in mmc_init_card()
1864 timeout_ms = max(card->ext_csd.generic_cmd6_time, timeout_ms); in mmc_init_card()
1865 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1875 mmc_hostname(card->host), err); in mmc_init_card()
1876 card->ext_csd.cache_ctrl = 0; in mmc_init_card()
1878 card->ext_csd.cache_ctrl = 1; in mmc_init_card()
1886 card->ext_csd.cmdq_en = false; in mmc_init_card()
1887 if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) { in mmc_init_card()
1888 err = mmc_cmdq_enable(card); in mmc_init_card()
1893 mmc_hostname(card->host)); in mmc_init_card()
1894 card->ext_csd.cmdq_support = false; in mmc_init_card()
1895 card->ext_csd.cmdq_depth = 0; in mmc_init_card()
1903 card->reenable_cmdq = card->ext_csd.cmdq_en; in mmc_init_card()
1906 err = host->cqe_ops->cqe_enable(host, card); in mmc_init_card()
1910 if (card->ext_csd.cmdq_en) { in mmc_init_card()
1930 host->card = card; in mmc_init_card()
1936 mmc_remove_card(card); in mmc_init_card()
1941 static int mmc_can_sleep(struct mmc_card *card) in mmc_can_sleep() argument
1943 return card->ext_csd.rev >= 3; in mmc_can_sleep()
1957 struct mmc_card *card = host->card; in mmc_sleep() local
1958 unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); in mmc_sleep()
1962 /* Re-tuning can't be done once the card is deselected */ in mmc_sleep()
1970 cmd.arg = card->rca << 16; in mmc_sleep()
1979 * If the host does not wait while the card signals busy, then we can in mmc_sleep()
1999 static int mmc_can_poweroff_notify(const struct mmc_card *card) in mmc_can_poweroff_notify() argument
2001 return card && in mmc_can_poweroff_notify()
2002 mmc_card_mmc(card) && in mmc_can_poweroff_notify()
2003 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); in mmc_can_poweroff_notify()
2006 static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) in mmc_poweroff_notify() argument
2008 unsigned int timeout = card->ext_csd.generic_cmd6_time; in mmc_poweroff_notify()
2013 timeout = card->ext_csd.power_off_longtime; in mmc_poweroff_notify()
2015 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_poweroff_notify()
2020 mmc_hostname(card->host), timeout); in mmc_poweroff_notify()
2023 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; in mmc_poweroff_notify()
2029 * Host is being removed. Free up the current card.
2033 mmc_remove_card(host->card); in mmc_remove()
2034 host->card = NULL; in mmc_remove()
2038 * Card detection - card is alive.
2042 return mmc_send_status(host->card, NULL); in mmc_alive()
2046 * Card detection callback from host.
2052 mmc_get_card(host->card, NULL); in mmc_detect()
2055 * Just check if our card has been removed. in mmc_detect()
2059 mmc_put_card(host->card, NULL); in mmc_detect()
2073 return host->card->ext_csd.cache_size > 0 && in _mmc_cache_enabled()
2074 host->card->ext_csd.cache_ctrl & 1; in _mmc_cache_enabled()
2085 err = mmc_switch(host->card, EXT_CSD_CMD_SET_NORMAL, in _mmc_flush_cache()
2104 if (mmc_card_suspended(host->card)) in _mmc_suspend()
2111 if (mmc_can_poweroff_notify(host->card) && in _mmc_suspend()
2114 err = mmc_poweroff_notify(host->card, notify_type); in _mmc_suspend()
2115 else if (mmc_can_sleep(host->card)) in _mmc_suspend()
2122 mmc_card_set_suspended(host->card); in _mmc_suspend()
2138 pm_runtime_disable(&host->card->dev); in mmc_suspend()
2139 pm_runtime_set_suspended(&host->card->dev); in mmc_suspend()
2146 * This function tries to determine if the same card is still present
2155 if (!mmc_card_suspended(host->card)) in _mmc_resume()
2158 mmc_power_up(host, host->card->ocr); in _mmc_resume()
2159 err = mmc_init_card(host, host->card->ocr, host->card); in _mmc_resume()
2160 mmc_card_clr_suspended(host->card); in _mmc_resume()
2175 * In a specific case for poweroff notify, we need to resume the card in mmc_shutdown()
2178 if (mmc_can_poweroff_notify(host->card) && in mmc_shutdown()
2193 pm_runtime_enable(&host->card->dev); in mmc_resume()
2230 static int mmc_can_reset(struct mmc_card *card) in mmc_can_reset() argument
2234 rst_n_function = card->ext_csd.rst_n_function; in mmc_can_reset()
2242 struct mmc_card *card = host->card; in _mmc_hw_reset() local
2251 mmc_can_reset(card)) { in _mmc_hw_reset()
2252 /* If the card accept RST_n signal, send it. */ in _mmc_hw_reset()
2259 mmc_power_cycle(host, card->ocr); in _mmc_hw_reset()
2262 return mmc_init_card(host, card->ocr, card); in _mmc_hw_reset()
2280 * Starting point for MMC card init.
2313 * Can we support the voltage of the card? in mmc_attach_mmc()
2321 * Detect and init the card. in mmc_attach_mmc()
2328 err = mmc_add_card(host->card); in mmc_attach_mmc()
2336 mmc_remove_card(host->card); in mmc_attach_mmc()
2338 host->card = NULL; in mmc_attach_mmc()
2342 pr_err("%s: error %d whilst initialising MMC card\n", in mmc_attach_mmc()