• Home
  • Raw
  • Download

Lines Matching refs:card

78 static int mmc_decode_cid(struct mmc_card *card)  in mmc_decode_cid()  argument
80 u32 *resp = card->raw_cid; in mmc_decode_cid()
86 switch (card->csd.mmca_vsn) { in mmc_decode_cid()
89 card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); in mmc_decode_cid()
90 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
91 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
92 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
93 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
94 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
95 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
96 card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
97 card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); in mmc_decode_cid()
98 card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); in mmc_decode_cid()
99 card->cid.serial = UNSTUFF_BITS(resp, 16, 24); in mmc_decode_cid()
100 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
101 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
107 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); in mmc_decode_cid()
108 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); in mmc_decode_cid()
109 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
110 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
111 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
112 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
113 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
114 card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); in mmc_decode_cid()
115 card->cid.prv = UNSTUFF_BITS(resp, 48, 8); in mmc_decode_cid()
116 card->cid.serial = UNSTUFF_BITS(resp, 16, 32); in mmc_decode_cid()
117 card->cid.month = UNSTUFF_BITS(resp, 12, 4); in mmc_decode_cid()
118 card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; in mmc_decode_cid()
123 mmc_hostname(card->host), card->csd.mmca_vsn); in mmc_decode_cid()
130 static void mmc_set_erase_size(struct mmc_card *card) in mmc_set_erase_size() argument
132 if (card->ext_csd.erase_group_def & 1) in mmc_set_erase_size()
133 card->erase_size = card->ext_csd.hc_erase_size; in mmc_set_erase_size()
135 card->erase_size = card->csd.erase_size; in mmc_set_erase_size()
137 mmc_init_erase(card); in mmc_set_erase_size()
143 static int mmc_decode_csd(struct mmc_card *card) in mmc_decode_csd() argument
145 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
147 u32 *resp = card->raw_csd; in mmc_decode_csd()
157 mmc_hostname(card->host), csd->structure); in mmc_decode_csd()
195 static void mmc_select_card_type(struct mmc_card *card) in mmc_select_card_type() argument
197 struct mmc_host *host = card->host; in mmc_select_card_type()
198 u8 card_type = card->ext_csd.raw_card_type; in mmc_select_card_type()
252 card->ext_csd.strobe_support && in mmc_select_card_type()
256 card->ext_csd.hs_max_dtr = hs_max_dtr; in mmc_select_card_type()
257 card->ext_csd.hs200_max_dtr = hs200_max_dtr; in mmc_select_card_type()
258 card->mmc_avail_type = avail_type; in mmc_select_card_type()
261 static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd) in mmc_manage_enhanced_area() argument
268 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_manage_enhanced_area()
269 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_manage_enhanced_area()
278 if (card->ext_csd.partition_setting_completed) { in mmc_manage_enhanced_area()
287 card->ext_csd.enhanced_area_offset = in mmc_manage_enhanced_area()
292 if (mmc_card_blockaddr(card)) in mmc_manage_enhanced_area()
293 card->ext_csd.enhanced_area_offset <<= 9; in mmc_manage_enhanced_area()
297 card->ext_csd.enhanced_area_size = in mmc_manage_enhanced_area()
300 card->ext_csd.enhanced_area_size *= in mmc_manage_enhanced_area()
302 card->ext_csd.enhanced_area_size <<= 9; in mmc_manage_enhanced_area()
305 mmc_hostname(card->host)); in mmc_manage_enhanced_area()
310 static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd) in mmc_manage_gp_partitions() argument
333 if (card->ext_csd.partition_setting_completed == 0) { in mmc_manage_gp_partitions()
335 mmc_hostname(card->host)); in mmc_manage_gp_partitions()
346 mmc_part_add(card, part_size << 19, in mmc_manage_gp_partitions()
360 static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) in mmc_decode_ext_csd() argument
368 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; in mmc_decode_ext_csd()
369 if (card->csd.structure == 3) { in mmc_decode_ext_csd()
370 if (card->ext_csd.raw_ext_csd_structure > 2) { in mmc_decode_ext_csd()
372 "version %d\n", mmc_hostname(card->host), in mmc_decode_ext_csd()
373 card->ext_csd.raw_ext_csd_structure); in mmc_decode_ext_csd()
379 np = mmc_of_find_child_device(card->host, 0); in mmc_decode_ext_csd()
389 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; in mmc_decode_ext_csd()
392 mmc_fixup_device(card, mmc_ext_csd_fixups); in mmc_decode_ext_csd()
394 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; in mmc_decode_ext_csd()
395 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; in mmc_decode_ext_csd()
396 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; in mmc_decode_ext_csd()
397 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; in mmc_decode_ext_csd()
398 if (card->ext_csd.rev >= 2) { in mmc_decode_ext_csd()
399 card->ext_csd.sectors = in mmc_decode_ext_csd()
406 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) in mmc_decode_ext_csd()
407 mmc_card_set_blockaddr(card); in mmc_decode_ext_csd()
410 card->ext_csd.strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT]; in mmc_decode_ext_csd()
411 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; in mmc_decode_ext_csd()
412 mmc_select_card_type(card); in mmc_decode_ext_csd()
414 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; in mmc_decode_ext_csd()
415 card->ext_csd.raw_erase_timeout_mult = in mmc_decode_ext_csd()
417 card->ext_csd.raw_hc_erase_grp_size = in mmc_decode_ext_csd()
419 if (card->ext_csd.rev >= 3) { in mmc_decode_ext_csd()
421 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; in mmc_decode_ext_csd()
424 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; in mmc_decode_ext_csd()
426 if (card->ext_csd.part_time && in mmc_decode_ext_csd()
427 card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME) in mmc_decode_ext_csd()
428 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME; in mmc_decode_ext_csd()
432 card->ext_csd.sa_timeout = in mmc_decode_ext_csd()
434 card->ext_csd.erase_group_def = in mmc_decode_ext_csd()
436 card->ext_csd.hc_erase_timeout = 300 * in mmc_decode_ext_csd()
438 card->ext_csd.hc_erase_size = in mmc_decode_ext_csd()
441 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; in mmc_decode_ext_csd()
447 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { in mmc_decode_ext_csd()
450 mmc_part_add(card, part_size, in mmc_decode_ext_csd()
458 card->ext_csd.raw_hc_erase_gap_size = in mmc_decode_ext_csd()
460 card->ext_csd.raw_sec_trim_mult = in mmc_decode_ext_csd()
462 card->ext_csd.raw_sec_erase_mult = in mmc_decode_ext_csd()
464 card->ext_csd.raw_sec_feature_support = in mmc_decode_ext_csd()
466 card->ext_csd.raw_trim_mult = in mmc_decode_ext_csd()
468 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; in mmc_decode_ext_csd()
469 card->ext_csd.raw_driver_strength = ext_csd[EXT_CSD_DRIVER_STRENGTH]; in mmc_decode_ext_csd()
470 if (card->ext_csd.rev >= 4) { in mmc_decode_ext_csd()
473 card->ext_csd.partition_setting_completed = 1; in mmc_decode_ext_csd()
475 card->ext_csd.partition_setting_completed = 0; in mmc_decode_ext_csd()
477 mmc_manage_enhanced_area(card, ext_csd); in mmc_decode_ext_csd()
479 mmc_manage_gp_partitions(card, ext_csd); in mmc_decode_ext_csd()
481 card->ext_csd.sec_trim_mult = in mmc_decode_ext_csd()
483 card->ext_csd.sec_erase_mult = in mmc_decode_ext_csd()
485 card->ext_csd.sec_feature_support = in mmc_decode_ext_csd()
487 card->ext_csd.trim_timeout = 300 * in mmc_decode_ext_csd()
495 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; in mmc_decode_ext_csd()
496 card->ext_csd.boot_ro_lockable = true; in mmc_decode_ext_csd()
499 card->ext_csd.raw_pwr_cl_52_195 = in mmc_decode_ext_csd()
501 card->ext_csd.raw_pwr_cl_26_195 = in mmc_decode_ext_csd()
503 card->ext_csd.raw_pwr_cl_52_360 = in mmc_decode_ext_csd()
505 card->ext_csd.raw_pwr_cl_26_360 = in mmc_decode_ext_csd()
507 card->ext_csd.raw_pwr_cl_200_195 = in mmc_decode_ext_csd()
509 card->ext_csd.raw_pwr_cl_200_360 = in mmc_decode_ext_csd()
511 card->ext_csd.raw_pwr_cl_ddr_52_195 = in mmc_decode_ext_csd()
513 card->ext_csd.raw_pwr_cl_ddr_52_360 = in mmc_decode_ext_csd()
515 card->ext_csd.raw_pwr_cl_ddr_200_360 = in mmc_decode_ext_csd()
519 if (card->ext_csd.rev >= 5) { in mmc_decode_ext_csd()
521 if (card->cid.year < 2010) in mmc_decode_ext_csd()
522 card->cid.year += 16; in mmc_decode_ext_csd()
525 if (!mmc_card_broken_hpi(card) && 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()
539 if (!mmc_card_broken_hpi(card) && in mmc_decode_ext_csd()
541 card->ext_csd.hpi = 1; in mmc_decode_ext_csd()
543 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; in mmc_decode_ext_csd()
545 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; in mmc_decode_ext_csd()
550 card->ext_csd.out_of_int_time = in mmc_decode_ext_csd()
554 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; in mmc_decode_ext_csd()
555 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; in mmc_decode_ext_csd()
560 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; in mmc_decode_ext_csd()
561 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { in mmc_decode_ext_csd()
562 mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, in mmc_decode_ext_csd()
569 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; in mmc_decode_ext_csd()
571 card->erased_byte = 0xFF; in mmc_decode_ext_csd()
573 card->erased_byte = 0x0; in mmc_decode_ext_csd()
576 card->ext_csd.generic_cmd6_time = DEFAULT_CMD6_TIMEOUT_MS; in mmc_decode_ext_csd()
577 if (card->ext_csd.rev >= 6) { in mmc_decode_ext_csd()
578 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; in mmc_decode_ext_csd()
580 card->ext_csd.generic_cmd6_time = 10 * in mmc_decode_ext_csd()
582 card->ext_csd.power_off_longtime = 10 * in mmc_decode_ext_csd()
585 card->ext_csd.cache_size = in mmc_decode_ext_csd()
592 card->ext_csd.data_sector_size = 4096; in mmc_decode_ext_csd()
594 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
598 card->ext_csd.data_tag_unit_size = in mmc_decode_ext_csd()
600 (card->ext_csd.data_sector_size); in mmc_decode_ext_csd()
602 card->ext_csd.data_tag_unit_size = 0; in mmc_decode_ext_csd()
605 card->ext_csd.max_packed_writes = in mmc_decode_ext_csd()
607 card->ext_csd.max_packed_reads = in mmc_decode_ext_csd()
610 card->ext_csd.data_sector_size = 512; in mmc_decode_ext_csd()
614 if (card->ext_csd.rev >= 7) { in mmc_decode_ext_csd()
615 memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION], in mmc_decode_ext_csd()
617 card->ext_csd.ffu_capable = in mmc_decode_ext_csd()
621 card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; in mmc_decode_ext_csd()
622 card->ext_csd.device_life_time_est_typ_a = in mmc_decode_ext_csd()
624 card->ext_csd.device_life_time_est_typ_b = in mmc_decode_ext_csd()
631 static int mmc_read_ext_csd(struct mmc_card *card) in mmc_read_ext_csd() argument
636 if (!mmc_can_ext_csd(card)) in mmc_read_ext_csd()
639 err = mmc_get_ext_csd(card, &ext_csd); in mmc_read_ext_csd()
652 if (card->csd.capacity == (4096 * 512)) { in mmc_read_ext_csd()
654 mmc_hostname(card->host)); in mmc_read_ext_csd()
657 mmc_hostname(card->host)); in mmc_read_ext_csd()
664 err = mmc_decode_ext_csd(card, ext_csd); in mmc_read_ext_csd()
669 static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) in mmc_compare_ext_csds() argument
677 err = mmc_get_ext_csd(card, &bw_ext_csd); in mmc_compare_ext_csds()
682 err = !((card->ext_csd.raw_partition_support == in mmc_compare_ext_csds()
684 (card->ext_csd.raw_erased_mem_count == in mmc_compare_ext_csds()
686 (card->ext_csd.rev == in mmc_compare_ext_csds()
688 (card->ext_csd.raw_ext_csd_structure == in mmc_compare_ext_csds()
690 (card->ext_csd.raw_card_type == in mmc_compare_ext_csds()
692 (card->ext_csd.raw_s_a_timeout == in mmc_compare_ext_csds()
694 (card->ext_csd.raw_hc_erase_gap_size == in mmc_compare_ext_csds()
696 (card->ext_csd.raw_erase_timeout_mult == in mmc_compare_ext_csds()
698 (card->ext_csd.raw_hc_erase_grp_size == in mmc_compare_ext_csds()
700 (card->ext_csd.raw_sec_trim_mult == in mmc_compare_ext_csds()
702 (card->ext_csd.raw_sec_erase_mult == in mmc_compare_ext_csds()
704 (card->ext_csd.raw_sec_feature_support == in mmc_compare_ext_csds()
706 (card->ext_csd.raw_trim_mult == in mmc_compare_ext_csds()
708 (card->ext_csd.raw_sectors[0] == in mmc_compare_ext_csds()
710 (card->ext_csd.raw_sectors[1] == in mmc_compare_ext_csds()
712 (card->ext_csd.raw_sectors[2] == in mmc_compare_ext_csds()
714 (card->ext_csd.raw_sectors[3] == in mmc_compare_ext_csds()
716 (card->ext_csd.raw_pwr_cl_52_195 == in mmc_compare_ext_csds()
718 (card->ext_csd.raw_pwr_cl_26_195 == in mmc_compare_ext_csds()
720 (card->ext_csd.raw_pwr_cl_52_360 == in mmc_compare_ext_csds()
722 (card->ext_csd.raw_pwr_cl_26_360 == in mmc_compare_ext_csds()
724 (card->ext_csd.raw_pwr_cl_200_195 == in mmc_compare_ext_csds()
726 (card->ext_csd.raw_pwr_cl_200_360 == in mmc_compare_ext_csds()
728 (card->ext_csd.raw_pwr_cl_ddr_52_195 == in mmc_compare_ext_csds()
730 (card->ext_csd.raw_pwr_cl_ddr_52_360 == in mmc_compare_ext_csds()
732 (card->ext_csd.raw_pwr_cl_ddr_200_360 == in mmc_compare_ext_csds()
742 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
743 card->raw_cid[2], card->raw_cid[3]);
744 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
745 card->raw_csd[2], card->raw_csd[3]);
746 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
747 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
748 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
749 MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
750 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
751 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
752 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
753 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
754 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
755 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
756 MMC_DEV_ATTR(pre_eol_info, "%02x\n", card->ext_csd.pre_eol_info);
758 card->ext_csd.device_life_time_est_typ_a,
759 card->ext_csd.device_life_time_est_typ_b);
760 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
762 card->ext_csd.enhanced_area_offset);
763 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
764 MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
765 MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
766 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
772 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_fwrev_show() local
774 if (card->ext_csd.rev < 7) { in mmc_fwrev_show()
775 return sprintf(buf, "0x%x\n", card->cid.fwrev); in mmc_fwrev_show()
778 card->ext_csd.fwrev); in mmc_fwrev_show()
788 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_dsr_show() local
789 struct mmc_host *host = card->host; in mmc_dsr_show()
791 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
837 static int __mmc_select_powerclass(struct mmc_card *card, in __mmc_select_powerclass() argument
840 struct mmc_host *host = card->host; in __mmc_select_powerclass()
841 struct mmc_ext_csd *ext_csd = &card->ext_csd; in __mmc_select_powerclass()
891 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in __mmc_select_powerclass()
894 card->ext_csd.generic_cmd6_time); in __mmc_select_powerclass()
900 static int mmc_select_powerclass(struct mmc_card *card) in mmc_select_powerclass() argument
902 struct mmc_host *host = card->host; in mmc_select_powerclass()
907 if (!mmc_can_ext_csd(card)) in mmc_select_powerclass()
915 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; in mmc_select_powerclass()
923 err = __mmc_select_powerclass(card, ext_csd_bits); in mmc_select_powerclass()
934 static void mmc_set_bus_speed(struct mmc_card *card) in mmc_set_bus_speed() argument
938 if ((mmc_card_hs200(card) || mmc_card_hs400(card)) && in mmc_set_bus_speed()
939 max_dtr > card->ext_csd.hs200_max_dtr) in mmc_set_bus_speed()
940 max_dtr = card->ext_csd.hs200_max_dtr; in mmc_set_bus_speed()
941 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr) in mmc_set_bus_speed()
942 max_dtr = card->ext_csd.hs_max_dtr; in mmc_set_bus_speed()
943 else if (max_dtr > card->csd.max_dtr) in mmc_set_bus_speed()
944 max_dtr = card->csd.max_dtr; in mmc_set_bus_speed()
946 mmc_set_clock(card->host, max_dtr); in mmc_set_bus_speed()
954 static int mmc_select_bus_width(struct mmc_card *card) in mmc_select_bus_width() argument
964 struct mmc_host *host = card->host; in mmc_select_bus_width()
968 if (!mmc_can_ext_csd(card) || in mmc_select_bus_width()
988 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_bus_width()
991 card->ext_csd.generic_cmd6_time); in mmc_select_bus_width()
1004 err = mmc_compare_ext_csds(card, bus_width); in mmc_select_bus_width()
1006 err = mmc_bus_test(card, bus_width); in mmc_select_bus_width()
1021 static int mmc_switch_status(struct mmc_card *card) in mmc_switch_status() argument
1026 err = mmc_send_status(card, &status); in mmc_switch_status()
1030 return mmc_switch_status_error(card->host, status); in mmc_switch_status()
1036 static int mmc_select_hs(struct mmc_card *card) in mmc_select_hs() argument
1040 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs()
1042 card->ext_csd.generic_cmd6_time, in mmc_select_hs()
1045 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); in mmc_select_hs()
1046 err = mmc_switch_status(card); in mmc_select_hs()
1051 mmc_hostname(card->host), err); in mmc_select_hs()
1059 static int mmc_select_hs_ddr(struct mmc_card *card) in mmc_select_hs_ddr() argument
1061 struct mmc_host *host = card->host; in mmc_select_hs_ddr()
1065 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52)) in mmc_select_hs_ddr()
1075 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs_ddr()
1078 card->ext_csd.generic_cmd6_time); in mmc_select_hs_ddr()
1111 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) in mmc_select_hs_ddr()
1114 if (err && (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_8V)) in mmc_select_hs_ddr()
1127 static int mmc_select_hs400(struct mmc_card *card) in mmc_select_hs400() argument
1129 struct mmc_host *host = card->host; in mmc_select_hs400()
1137 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_select_hs400()
1143 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1145 card->ext_csd.generic_cmd6_time, in mmc_select_hs400()
1154 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); in mmc_select_hs400()
1157 max_dtr = card->ext_csd.hs_max_dtr; in mmc_select_hs400()
1160 err = mmc_switch_status(card); in mmc_select_hs400()
1165 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1168 card->ext_csd.generic_cmd6_time); in mmc_select_hs400()
1177 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; 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, in mmc_select_hs400()
1190 mmc_set_bus_speed(card); in mmc_select_hs400()
1192 err = mmc_switch_status(card); in mmc_select_hs400()
1199 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400()
1204 int mmc_hs200_to_hs400(struct mmc_card *card) in mmc_hs200_to_hs400() argument
1206 return mmc_select_hs400(card); in mmc_hs200_to_hs400()
1209 int mmc_hs400_to_hs200(struct mmc_card *card) in mmc_hs400_to_hs200() argument
1211 struct mmc_host *host = card->host; in mmc_hs400_to_hs200()
1217 max_dtr = card->ext_csd.hs_max_dtr; in mmc_hs400_to_hs200()
1222 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, in mmc_hs400_to_hs200()
1223 val, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1230 err = mmc_switch_status(card); in mmc_hs400_to_hs200()
1235 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, in mmc_hs400_to_hs200()
1236 EXT_CSD_BUS_WIDTH_8, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1243 err = mmc_switch_status(card); in mmc_hs400_to_hs200()
1249 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_hs400_to_hs200()
1250 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, in mmc_hs400_to_hs200()
1251 val, card->ext_csd.generic_cmd6_time, in mmc_hs400_to_hs200()
1258 err = mmc_switch_status(card); in mmc_hs400_to_hs200()
1262 mmc_set_bus_speed(card); in mmc_hs400_to_hs200()
1267 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_hs400_to_hs200()
1272 static void mmc_select_driver_type(struct mmc_card *card) in mmc_select_driver_type() argument
1276 card_drv_type = card->ext_csd.raw_driver_strength | in mmc_select_driver_type()
1279 drive_strength = mmc_select_drive_strength(card, in mmc_select_driver_type()
1280 card->ext_csd.hs200_max_dtr, in mmc_select_driver_type()
1283 card->drive_strength = drive_strength; in mmc_select_driver_type()
1286 mmc_set_driver_type(card->host, drv_type); in mmc_select_driver_type()
1289 static int mmc_select_hs400es(struct mmc_card *card) in mmc_select_hs400es() argument
1291 struct mmc_host *host = card->host; in mmc_select_hs400es()
1300 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_2V) in mmc_select_hs400es()
1303 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400_1_8V) in mmc_select_hs400es()
1310 err = mmc_select_bus_width(card); in mmc_select_hs400es()
1315 err = mmc_select_hs(card); in mmc_select_hs400es()
1319 mmc_set_clock(host, card->ext_csd.hs_max_dtr); in mmc_select_hs400es()
1321 err = mmc_switch_status(card); in mmc_select_hs400es()
1327 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400es()
1330 card->ext_csd.generic_cmd6_time); in mmc_select_hs400es()
1337 mmc_select_driver_type(card); in mmc_select_hs400es()
1341 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs400es()
1342 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400es()
1344 card->ext_csd.generic_cmd6_time, in mmc_select_hs400es()
1360 err = mmc_switch_status(card); in mmc_select_hs400es()
1367 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs400es()
1379 static int mmc_select_hs200(struct mmc_card *card) in mmc_select_hs200() argument
1381 struct mmc_host *host = card->host; in mmc_select_hs200()
1387 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) in mmc_select_hs200()
1390 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) in mmc_select_hs200()
1397 mmc_select_driver_type(card); in mmc_select_hs200()
1403 err = mmc_select_bus_width(card); in mmc_select_hs200()
1406 card->drive_strength << EXT_CSD_DRV_STR_SHIFT; in mmc_select_hs200()
1407 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs200()
1409 card->ext_csd.generic_cmd6_time, in mmc_select_hs200()
1416 err = mmc_switch_status(card); in mmc_select_hs200()
1430 pr_err("%s: %s failed, error %d\n", mmc_hostname(card->host), in mmc_select_hs200()
1439 static int mmc_select_timing(struct mmc_card *card) in mmc_select_timing() argument
1443 if (!mmc_can_ext_csd(card)) in mmc_select_timing()
1446 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400ES) in mmc_select_timing()
1447 err = mmc_select_hs400es(card); in mmc_select_timing()
1448 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) in mmc_select_timing()
1449 err = mmc_select_hs200(card); in mmc_select_timing()
1450 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS) in mmc_select_timing()
1451 err = mmc_select_hs(card); in mmc_select_timing()
1461 mmc_set_bus_speed(card); in mmc_select_timing()
1469 static int mmc_hs200_tuning(struct mmc_card *card) in mmc_hs200_tuning() argument
1471 struct mmc_host *host = card->host; in mmc_hs200_tuning()
1477 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_hs200_tuning()
1482 return mmc_execute_tuning(card); in mmc_hs200_tuning()
1494 struct mmc_card *card; in mmc_init_card() local
1545 card = oldcard; in mmc_init_card()
1550 card = mmc_alloc_card(host, &mmc_type); in mmc_init_card()
1551 if (IS_ERR(card)) { in mmc_init_card()
1552 err = PTR_ERR(card); in mmc_init_card()
1556 card->ocr = ocr; in mmc_init_card()
1557 card->type = MMC_TYPE_MMC; in mmc_init_card()
1558 card->rca = 1; in mmc_init_card()
1559 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_init_card()
1566 host->ops->init_card(host, card); in mmc_init_card()
1572 err = mmc_set_relative_addr(card); in mmc_init_card()
1583 err = mmc_send_csd(card, card->raw_csd); in mmc_init_card()
1587 err = mmc_decode_csd(card); in mmc_init_card()
1590 err = mmc_decode_cid(card); in mmc_init_card()
1599 if (card->csd.dsr_imp && host->dsr_req) in mmc_init_card()
1606 err = mmc_select_card(card); in mmc_init_card()
1613 err = mmc_read_ext_csd(card); in mmc_init_card()
1624 mmc_card_set_blockaddr(card); in mmc_init_card()
1627 mmc_set_erase_size(card); in mmc_init_card()
1634 if (card->ext_csd.partition_setting_completed || in mmc_init_card()
1635 (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { in mmc_init_card()
1636 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1638 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1650 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_init_card()
1651 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_init_card()
1653 card->ext_csd.erase_group_def = 1; in mmc_init_card()
1659 mmc_set_erase_size(card); in mmc_init_card()
1666 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { in mmc_init_card()
1667 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; in mmc_init_card()
1668 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, in mmc_init_card()
1669 card->ext_csd.part_config, in mmc_init_card()
1670 card->ext_csd.part_time); in mmc_init_card()
1678 if (card->ext_csd.rev >= 6) { in mmc_init_card()
1679 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1682 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1691 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; in mmc_init_card()
1697 err = mmc_select_timing(card); in mmc_init_card()
1701 if (mmc_card_hs200(card)) { in mmc_init_card()
1702 err = mmc_hs200_tuning(card); in mmc_init_card()
1706 err = mmc_select_hs400(card); in mmc_init_card()
1709 } else if (!mmc_card_hs400es(card)) { in mmc_init_card()
1711 err = mmc_select_bus_width(card); in mmc_init_card()
1712 if (err > 0 && mmc_card_hs(card)) { in mmc_init_card()
1713 err = mmc_select_hs_ddr(card); in mmc_init_card()
1722 mmc_select_powerclass(card); in mmc_init_card()
1727 if (card->ext_csd.hpi) { in mmc_init_card()
1728 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1730 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1735 mmc_hostname(card->host)); in mmc_init_card()
1738 card->ext_csd.hpi_en = 1; in mmc_init_card()
1745 if (!mmc_card_broken_hpi(card) && in mmc_init_card()
1746 card->ext_csd.cache_size > 0) { in mmc_init_card()
1747 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1749 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1758 mmc_hostname(card->host), err); in mmc_init_card()
1759 card->ext_csd.cache_ctrl = 0; in mmc_init_card()
1762 card->ext_csd.cache_ctrl = 1; in mmc_init_card()
1770 if (card->ext_csd.max_packed_writes >= 3 && in mmc_init_card()
1771 card->ext_csd.max_packed_reads >= 5 && in mmc_init_card()
1773 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1776 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1781 mmc_hostname(card->host)); in mmc_init_card()
1782 card->ext_csd.packed_event_en = 0; in mmc_init_card()
1785 card->ext_csd.packed_event_en = 1; in mmc_init_card()
1790 host->card = card; in mmc_init_card()
1796 mmc_remove_card(card); in mmc_init_card()
1801 static int mmc_can_sleep(struct mmc_card *card) in mmc_can_sleep() argument
1803 return (card && card->ext_csd.rev >= 3); in mmc_can_sleep()
1809 struct mmc_card *card = host->card; in mmc_sleep() local
1810 unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); in mmc_sleep()
1821 cmd.arg = card->rca << 16; in mmc_sleep()
1855 static int mmc_can_poweroff_notify(const struct mmc_card *card) in mmc_can_poweroff_notify() argument
1857 return card && in mmc_can_poweroff_notify()
1858 mmc_card_mmc(card) && in mmc_can_poweroff_notify()
1859 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); in mmc_can_poweroff_notify()
1862 static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) in mmc_poweroff_notify() argument
1864 unsigned int timeout = card->ext_csd.generic_cmd6_time; in mmc_poweroff_notify()
1869 timeout = card->ext_csd.power_off_longtime; in mmc_poweroff_notify()
1871 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_poweroff_notify()
1876 mmc_hostname(card->host), timeout); in mmc_poweroff_notify()
1879 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; in mmc_poweroff_notify()
1890 BUG_ON(!host->card); in mmc_remove()
1892 mmc_remove_card(host->card); in mmc_remove()
1893 host->card = NULL; in mmc_remove()
1901 return mmc_send_status(host->card, NULL); in mmc_alive()
1912 BUG_ON(!host->card); in mmc_detect()
1914 mmc_get_card(host->card); in mmc_detect()
1921 mmc_put_card(host->card); in mmc_detect()
1940 BUG_ON(!host->card); in _mmc_suspend()
1944 if (mmc_card_suspended(host->card)) in _mmc_suspend()
1947 if (mmc_card_doing_bkops(host->card)) { in _mmc_suspend()
1948 err = mmc_stop_bkops(host->card); in _mmc_suspend()
1953 err = mmc_flush_cache(host->card); in _mmc_suspend()
1957 if (mmc_can_poweroff_notify(host->card) && in _mmc_suspend()
1959 err = mmc_poweroff_notify(host->card, notify_type); in _mmc_suspend()
1960 else if (mmc_can_sleep(host->card)) in _mmc_suspend()
1967 mmc_card_set_suspended(host->card); in _mmc_suspend()
1983 pm_runtime_disable(&host->card->dev); in mmc_suspend()
1984 pm_runtime_set_suspended(&host->card->dev); in mmc_suspend()
1999 BUG_ON(!host->card); in _mmc_resume()
2003 if (!mmc_card_suspended(host->card)) in _mmc_resume()
2006 mmc_power_up(host, host->card->ocr); in _mmc_resume()
2007 err = mmc_init_card(host, host->card->ocr, host->card); in _mmc_resume()
2008 mmc_card_clr_suspended(host->card); in _mmc_resume()
2026 if (mmc_can_poweroff_notify(host->card) && in mmc_shutdown()
2041 pm_runtime_enable(&host->card->dev); in mmc_resume()
2078 int mmc_can_reset(struct mmc_card *card) in mmc_can_reset() argument
2082 rst_n_function = card->ext_csd.rst_n_function; in mmc_can_reset()
2091 struct mmc_card *card = host->card; in mmc_reset() local
2097 mmc_flush_cache(host->card); in mmc_reset()
2100 mmc_can_reset(card)) { in mmc_reset()
2108 mmc_power_cycle(host, card->ocr); in mmc_reset()
2110 return mmc_init_card(host, card->ocr, card); in mmc_reset()
2175 err = mmc_add_card(host->card); in mmc_attach_mmc()
2183 mmc_remove_card(host->card); in mmc_attach_mmc()
2185 host->card = NULL; in mmc_attach_mmc()