Lines Matching refs:card
63 static int mmc_decode_cid(struct mmc_card *card) in mmc_decode_cid() argument
65 u32 *resp = card->raw_cid; in mmc_decode_cid()
71 switch (card->csd.mmca_vsn) { 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()
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()
115 static void mmc_set_erase_size(struct mmc_card *card) in mmc_set_erase_size() argument
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()
122 mmc_init_erase(card); in mmc_set_erase_size()
128 static int mmc_decode_csd(struct mmc_card *card) in mmc_decode_csd() argument
130 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
132 u32 *resp = card->raw_csd; in mmc_decode_csd()
142 mmc_hostname(card->host), csd->structure); in mmc_decode_csd()
183 static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) in mmc_get_ext_csd() argument
188 BUG_ON(!card); in mmc_get_ext_csd()
193 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) in mmc_get_ext_csd()
203 "receive the ext_csd.\n", mmc_hostname(card->host)); in mmc_get_ext_csd()
207 err = mmc_send_ext_csd(card, ext_csd); in mmc_get_ext_csd()
223 if (card->csd.capacity == (4096 * 512)) { in mmc_get_ext_csd()
227 mmc_hostname(card->host)); in mmc_get_ext_csd()
230 mmc_hostname(card->host)); in mmc_get_ext_csd()
239 static void mmc_select_card_type(struct mmc_card *card) in mmc_select_card_type() argument
241 struct mmc_host *host = card->host; in mmc_select_card_type()
242 u8 card_type = card->ext_csd.raw_card_type; in mmc_select_card_type()
295 card->ext_csd.hs_max_dtr = hs_max_dtr; in mmc_select_card_type()
296 card->ext_csd.hs200_max_dtr = hs200_max_dtr; in mmc_select_card_type()
297 card->mmc_avail_type = avail_type; in mmc_select_card_type()
300 static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd) in mmc_manage_enhanced_area() argument
307 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_manage_enhanced_area()
308 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_manage_enhanced_area()
317 if (card->ext_csd.partition_setting_completed) { in mmc_manage_enhanced_area()
326 card->ext_csd.enhanced_area_offset = in mmc_manage_enhanced_area()
329 if (mmc_card_blockaddr(card)) in mmc_manage_enhanced_area()
330 card->ext_csd.enhanced_area_offset <<= 9; in mmc_manage_enhanced_area()
334 card->ext_csd.enhanced_area_size = in mmc_manage_enhanced_area()
337 card->ext_csd.enhanced_area_size *= in mmc_manage_enhanced_area()
339 card->ext_csd.enhanced_area_size <<= 9; in mmc_manage_enhanced_area()
342 mmc_hostname(card->host)); in mmc_manage_enhanced_area()
347 static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd) in mmc_manage_gp_partitions() argument
370 if (card->ext_csd.partition_setting_completed == 0) { in mmc_manage_gp_partitions()
372 mmc_hostname(card->host)); in mmc_manage_gp_partitions()
383 mmc_part_add(card, part_size << 19, in mmc_manage_gp_partitions()
397 static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) in mmc_read_ext_csd() argument
402 BUG_ON(!card); in mmc_read_ext_csd()
408 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; in mmc_read_ext_csd()
409 if (card->csd.structure == 3) { in mmc_read_ext_csd()
410 if (card->ext_csd.raw_ext_csd_structure > 2) { in mmc_read_ext_csd()
412 "version %d\n", mmc_hostname(card->host), in mmc_read_ext_csd()
413 card->ext_csd.raw_ext_csd_structure); in mmc_read_ext_csd()
424 card->ext_csd.rev = ext_csd[EXT_CSD_REV]; in mmc_read_ext_csd()
426 card->ext_csd.raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; in mmc_read_ext_csd()
427 card->ext_csd.raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; in mmc_read_ext_csd()
428 card->ext_csd.raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; in mmc_read_ext_csd()
429 card->ext_csd.raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; in mmc_read_ext_csd()
430 if (card->ext_csd.rev >= 2) { in mmc_read_ext_csd()
431 card->ext_csd.sectors = in mmc_read_ext_csd()
438 if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512) in mmc_read_ext_csd()
439 mmc_card_set_blockaddr(card); in mmc_read_ext_csd()
442 card->ext_csd.raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; in mmc_read_ext_csd()
443 mmc_select_card_type(card); in mmc_read_ext_csd()
445 card->ext_csd.raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; in mmc_read_ext_csd()
446 card->ext_csd.raw_erase_timeout_mult = in mmc_read_ext_csd()
448 card->ext_csd.raw_hc_erase_grp_size = in mmc_read_ext_csd()
450 if (card->ext_csd.rev >= 3) { in mmc_read_ext_csd()
452 card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; in mmc_read_ext_csd()
455 card->ext_csd.part_time = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; in mmc_read_ext_csd()
457 if (card->ext_csd.part_time && in mmc_read_ext_csd()
458 card->ext_csd.part_time < MMC_MIN_PART_SWITCH_TIME) in mmc_read_ext_csd()
459 card->ext_csd.part_time = MMC_MIN_PART_SWITCH_TIME; in mmc_read_ext_csd()
463 card->ext_csd.sa_timeout = in mmc_read_ext_csd()
465 card->ext_csd.erase_group_def = in mmc_read_ext_csd()
467 card->ext_csd.hc_erase_timeout = 300 * in mmc_read_ext_csd()
469 card->ext_csd.hc_erase_size = in mmc_read_ext_csd()
472 card->ext_csd.rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; in mmc_read_ext_csd()
478 if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { in mmc_read_ext_csd()
481 mmc_part_add(card, part_size, in mmc_read_ext_csd()
489 card->ext_csd.raw_hc_erase_gap_size = in mmc_read_ext_csd()
491 card->ext_csd.raw_sec_trim_mult = in mmc_read_ext_csd()
493 card->ext_csd.raw_sec_erase_mult = in mmc_read_ext_csd()
495 card->ext_csd.raw_sec_feature_support = in mmc_read_ext_csd()
497 card->ext_csd.raw_trim_mult = in mmc_read_ext_csd()
499 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; in mmc_read_ext_csd()
500 if (card->ext_csd.rev >= 4) { in mmc_read_ext_csd()
503 card->ext_csd.partition_setting_completed = 1; in mmc_read_ext_csd()
505 card->ext_csd.partition_setting_completed = 0; in mmc_read_ext_csd()
507 mmc_manage_enhanced_area(card, ext_csd); in mmc_read_ext_csd()
509 mmc_manage_gp_partitions(card, ext_csd); in mmc_read_ext_csd()
511 card->ext_csd.sec_trim_mult = in mmc_read_ext_csd()
513 card->ext_csd.sec_erase_mult = in mmc_read_ext_csd()
515 card->ext_csd.sec_feature_support = in mmc_read_ext_csd()
517 card->ext_csd.trim_timeout = 300 * in mmc_read_ext_csd()
525 card->ext_csd.boot_ro_lock = ext_csd[EXT_CSD_BOOT_WP]; in mmc_read_ext_csd()
526 card->ext_csd.boot_ro_lockable = true; in mmc_read_ext_csd()
529 card->ext_csd.raw_pwr_cl_52_195 = in mmc_read_ext_csd()
531 card->ext_csd.raw_pwr_cl_26_195 = in mmc_read_ext_csd()
533 card->ext_csd.raw_pwr_cl_52_360 = in mmc_read_ext_csd()
535 card->ext_csd.raw_pwr_cl_26_360 = in mmc_read_ext_csd()
537 card->ext_csd.raw_pwr_cl_200_195 = in mmc_read_ext_csd()
539 card->ext_csd.raw_pwr_cl_200_360 = in mmc_read_ext_csd()
541 card->ext_csd.raw_pwr_cl_ddr_52_195 = in mmc_read_ext_csd()
543 card->ext_csd.raw_pwr_cl_ddr_52_360 = in mmc_read_ext_csd()
545 card->ext_csd.raw_pwr_cl_ddr_200_360 = in mmc_read_ext_csd()
549 if (card->ext_csd.rev >= 5) { in mmc_read_ext_csd()
551 if (card->cid.year < 2010) in mmc_read_ext_csd()
552 card->cid.year += 16; in mmc_read_ext_csd()
556 card->ext_csd.bkops = 1; in mmc_read_ext_csd()
557 card->ext_csd.bkops_en = ext_csd[EXT_CSD_BKOPS_EN]; in mmc_read_ext_csd()
558 card->ext_csd.raw_bkops_status = in mmc_read_ext_csd()
560 if (!card->ext_csd.bkops_en) in mmc_read_ext_csd()
562 mmc_hostname(card->host)); in mmc_read_ext_csd()
567 card->ext_csd.hpi = 1; in mmc_read_ext_csd()
569 card->ext_csd.hpi_cmd = MMC_STOP_TRANSMISSION; in mmc_read_ext_csd()
571 card->ext_csd.hpi_cmd = MMC_SEND_STATUS; in mmc_read_ext_csd()
576 card->ext_csd.out_of_int_time = in mmc_read_ext_csd()
580 card->ext_csd.rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; in mmc_read_ext_csd()
581 card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION]; in mmc_read_ext_csd()
586 card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; in mmc_read_ext_csd()
587 if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { in mmc_read_ext_csd()
588 mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, in mmc_read_ext_csd()
595 card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT]; in mmc_read_ext_csd()
597 card->erased_byte = 0xFF; in mmc_read_ext_csd()
599 card->erased_byte = 0x0; in mmc_read_ext_csd()
602 if (card->ext_csd.rev >= 6) { in mmc_read_ext_csd()
603 card->ext_csd.feature_support |= MMC_DISCARD_FEATURE; in mmc_read_ext_csd()
605 card->ext_csd.generic_cmd6_time = 10 * in mmc_read_ext_csd()
607 card->ext_csd.power_off_longtime = 10 * in mmc_read_ext_csd()
610 card->ext_csd.cache_size = in mmc_read_ext_csd()
617 card->ext_csd.data_sector_size = 4096; in mmc_read_ext_csd()
619 card->ext_csd.data_sector_size = 512; in mmc_read_ext_csd()
623 card->ext_csd.data_tag_unit_size = in mmc_read_ext_csd()
625 (card->ext_csd.data_sector_size); in mmc_read_ext_csd()
627 card->ext_csd.data_tag_unit_size = 0; in mmc_read_ext_csd()
630 card->ext_csd.max_packed_writes = in mmc_read_ext_csd()
632 card->ext_csd.max_packed_reads = in mmc_read_ext_csd()
635 card->ext_csd.data_sector_size = 512; in mmc_read_ext_csd()
639 if (card->ext_csd.rev >= 7) { in mmc_read_ext_csd()
640 card->ext_csd.pre_eol_info = ext_csd[EXT_CSD_PRE_EOL_INFO]; in mmc_read_ext_csd()
641 card->ext_csd.device_life_time_est_typ_a = in mmc_read_ext_csd()
643 card->ext_csd.device_life_time_est_typ_b = in mmc_read_ext_csd()
656 static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) in mmc_compare_ext_csds() argument
664 err = mmc_get_ext_csd(card, &bw_ext_csd); in mmc_compare_ext_csds()
672 err = !((card->ext_csd.raw_partition_support == in mmc_compare_ext_csds()
674 (card->ext_csd.raw_erased_mem_count == in mmc_compare_ext_csds()
676 (card->ext_csd.rev == in mmc_compare_ext_csds()
678 (card->ext_csd.raw_ext_csd_structure == in mmc_compare_ext_csds()
680 (card->ext_csd.raw_card_type == in mmc_compare_ext_csds()
682 (card->ext_csd.raw_s_a_timeout == in mmc_compare_ext_csds()
684 (card->ext_csd.raw_hc_erase_gap_size == in mmc_compare_ext_csds()
686 (card->ext_csd.raw_erase_timeout_mult == in mmc_compare_ext_csds()
688 (card->ext_csd.raw_hc_erase_grp_size == in mmc_compare_ext_csds()
690 (card->ext_csd.raw_sec_trim_mult == in mmc_compare_ext_csds()
692 (card->ext_csd.raw_sec_erase_mult == in mmc_compare_ext_csds()
694 (card->ext_csd.raw_sec_feature_support == in mmc_compare_ext_csds()
696 (card->ext_csd.raw_trim_mult == in mmc_compare_ext_csds()
698 (card->ext_csd.raw_sectors[0] == in mmc_compare_ext_csds()
700 (card->ext_csd.raw_sectors[1] == in mmc_compare_ext_csds()
702 (card->ext_csd.raw_sectors[2] == in mmc_compare_ext_csds()
704 (card->ext_csd.raw_sectors[3] == in mmc_compare_ext_csds()
706 (card->ext_csd.raw_pwr_cl_52_195 == in mmc_compare_ext_csds()
708 (card->ext_csd.raw_pwr_cl_26_195 == in mmc_compare_ext_csds()
710 (card->ext_csd.raw_pwr_cl_52_360 == in mmc_compare_ext_csds()
712 (card->ext_csd.raw_pwr_cl_26_360 == in mmc_compare_ext_csds()
714 (card->ext_csd.raw_pwr_cl_200_195 == in mmc_compare_ext_csds()
716 (card->ext_csd.raw_pwr_cl_200_360 == in mmc_compare_ext_csds()
718 (card->ext_csd.raw_pwr_cl_ddr_52_195 == in mmc_compare_ext_csds()
720 (card->ext_csd.raw_pwr_cl_ddr_52_360 == in mmc_compare_ext_csds()
722 (card->ext_csd.raw_pwr_cl_ddr_200_360 == in mmc_compare_ext_csds()
733 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
734 card->raw_cid[2], card->raw_cid[3]);
735 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
736 card->raw_csd[2], card->raw_csd[3]);
737 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
738 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
739 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
740 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
741 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
742 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
743 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
744 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
745 MMC_DEV_ATTR(prv, "0x%x\n", card->cid.prv);
746 MMC_DEV_ATTR(rev, "0x%x\n", card->ext_csd.rev);
747 MMC_DEV_ATTR(pre_eol_info, "%02x\n", card->ext_csd.pre_eol_info);
749 card->ext_csd.device_life_time_est_typ_a,
750 card->ext_csd.device_life_time_est_typ_b);
751 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
753 card->ext_csd.enhanced_area_offset);
754 MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
755 MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
756 MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
792 static int __mmc_select_powerclass(struct mmc_card *card, in __mmc_select_powerclass() argument
795 struct mmc_host *host = card->host; in __mmc_select_powerclass()
796 struct mmc_ext_csd *ext_csd = &card->ext_csd; in __mmc_select_powerclass()
801 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) in __mmc_select_powerclass()
854 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in __mmc_select_powerclass()
857 card->ext_csd.generic_cmd6_time); in __mmc_select_powerclass()
863 static int mmc_select_powerclass(struct mmc_card *card) in mmc_select_powerclass() argument
865 struct mmc_host *host = card->host; in mmc_select_powerclass()
870 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) in mmc_select_powerclass()
878 ddr = card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52; in mmc_select_powerclass()
886 err = __mmc_select_powerclass(card, ext_csd_bits); in mmc_select_powerclass()
897 static void mmc_set_bus_speed(struct mmc_card *card) in mmc_set_bus_speed() argument
901 if ((mmc_card_hs200(card) || mmc_card_hs400(card)) && in mmc_set_bus_speed()
902 max_dtr > card->ext_csd.hs200_max_dtr) in mmc_set_bus_speed()
903 max_dtr = card->ext_csd.hs200_max_dtr; in mmc_set_bus_speed()
904 else if (mmc_card_hs(card) && max_dtr > card->ext_csd.hs_max_dtr) in mmc_set_bus_speed()
905 max_dtr = card->ext_csd.hs_max_dtr; in mmc_set_bus_speed()
906 else if (max_dtr > card->csd.max_dtr) in mmc_set_bus_speed()
907 max_dtr = card->csd.max_dtr; in mmc_set_bus_speed()
909 mmc_set_clock(card->host, max_dtr); in mmc_set_bus_speed()
917 static int mmc_select_bus_width(struct mmc_card *card) in mmc_select_bus_width() argument
927 struct mmc_host *host = card->host; in mmc_select_bus_width()
931 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4) && in mmc_select_bus_width()
951 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_bus_width()
954 card->ext_csd.generic_cmd6_time); in mmc_select_bus_width()
967 err = mmc_compare_ext_csds(card, bus_width); in mmc_select_bus_width()
969 err = mmc_bus_test(card, bus_width); in mmc_select_bus_width()
986 static int mmc_select_hs(struct mmc_card *card) in mmc_select_hs() argument
990 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs()
992 card->ext_csd.generic_cmd6_time, in mmc_select_hs()
995 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); in mmc_select_hs()
1003 static int mmc_select_hs_ddr(struct mmc_card *card) in mmc_select_hs_ddr() argument
1005 struct mmc_host *host = card->host; in mmc_select_hs_ddr()
1009 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_52)) in mmc_select_hs_ddr()
1019 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs_ddr()
1022 card->ext_csd.generic_cmd6_time); in mmc_select_hs_ddr()
1055 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_2V) in mmc_select_hs_ddr()
1058 if (err && (card->mmc_avail_type & EXT_CSD_CARD_TYPE_DDR_1_8V)) in mmc_select_hs_ddr()
1071 static int mmc_select_hs400(struct mmc_card *card) in mmc_select_hs400() argument
1073 struct mmc_host *host = card->host; in mmc_select_hs400()
1079 if (!(card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_select_hs400()
1087 mmc_set_timing(card->host, MMC_TIMING_MMC_HS); in mmc_select_hs400()
1088 mmc_set_bus_speed(card); in mmc_select_hs400()
1090 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1092 card->ext_csd.generic_cmd6_time, in mmc_select_hs400()
1100 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1103 card->ext_csd.generic_cmd6_time); in mmc_select_hs400()
1110 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs400()
1112 card->ext_csd.generic_cmd6_time, in mmc_select_hs400()
1121 mmc_set_bus_speed(card); in mmc_select_hs400()
1133 static int mmc_select_hs200(struct mmc_card *card) in mmc_select_hs200() argument
1135 struct mmc_host *host = card->host; in mmc_select_hs200()
1138 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_2V) in mmc_select_hs200()
1141 if (err && card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200_1_8V) in mmc_select_hs200()
1152 err = mmc_select_bus_width(card); in mmc_select_hs200()
1154 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_select_hs200()
1156 card->ext_csd.generic_cmd6_time, in mmc_select_hs200()
1168 static int mmc_select_timing(struct mmc_card *card) in mmc_select_timing() argument
1172 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4 && in mmc_select_timing()
1173 card->ext_csd.hs_max_dtr == 0)) in mmc_select_timing()
1176 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) in mmc_select_timing()
1177 err = mmc_select_hs200(card); in mmc_select_timing()
1178 else if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS) in mmc_select_timing()
1179 err = mmc_select_hs(card); in mmc_select_timing()
1186 mmc_card_hs(card) ? "high-speed" : in mmc_select_timing()
1187 (mmc_card_hs200(card) ? "hs200" : ""), in mmc_select_timing()
1188 mmc_hostname(card->host)); in mmc_select_timing()
1197 mmc_set_bus_speed(card); in mmc_select_timing()
1237 static int mmc_hs200_tuning(struct mmc_card *card) in mmc_hs200_tuning() argument
1239 struct mmc_host *host = card->host; in mmc_hs200_tuning()
1245 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS400 && in mmc_hs200_tuning()
1250 return mmc_execute_tuning(card); in mmc_hs200_tuning()
1262 struct mmc_card *card; in mmc_init_card() local
1314 card = oldcard; in mmc_init_card()
1319 card = mmc_alloc_card(host, &mmc_type); in mmc_init_card()
1320 if (IS_ERR(card)) { in mmc_init_card()
1321 err = PTR_ERR(card); in mmc_init_card()
1325 card->ocr = ocr; in mmc_init_card()
1326 card->type = MMC_TYPE_MMC; in mmc_init_card()
1327 card->rca = 1; in mmc_init_card()
1328 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_init_card()
1335 err = mmc_set_relative_addr(card); in mmc_init_card()
1346 err = mmc_send_csd(card, card->raw_csd); in mmc_init_card()
1350 err = mmc_decode_csd(card); in mmc_init_card()
1353 err = mmc_decode_cid(card); in mmc_init_card()
1362 if (card->csd.dsr_imp && host->dsr_req) in mmc_init_card()
1369 err = mmc_select_card(card); in mmc_init_card()
1379 err = mmc_get_ext_csd(card, &ext_csd); in mmc_init_card()
1382 err = mmc_read_ext_csd(card, ext_csd); in mmc_init_card()
1391 if (!(mmc_card_blockaddr(card)) && (rocr & (1<<30))) in mmc_init_card()
1392 mmc_card_set_blockaddr(card); in mmc_init_card()
1395 mmc_set_erase_size(card); in mmc_init_card()
1402 if (card->ext_csd.partition_setting_completed || in mmc_init_card()
1403 (card->ext_csd.rev >= 3 && (host->caps2 & MMC_CAP2_HC_ERASE_SZ))) { in mmc_init_card()
1404 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1406 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1418 card->ext_csd.enhanced_area_offset = -EINVAL; in mmc_init_card()
1419 card->ext_csd.enhanced_area_size = -EINVAL; in mmc_init_card()
1421 card->ext_csd.erase_group_def = 1; in mmc_init_card()
1427 mmc_set_erase_size(card); in mmc_init_card()
1434 if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { in mmc_init_card()
1435 card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; in mmc_init_card()
1436 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, in mmc_init_card()
1437 card->ext_csd.part_config, in mmc_init_card()
1438 card->ext_csd.part_time); in mmc_init_card()
1446 if (card->ext_csd.rev >= 6) { in mmc_init_card()
1447 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1450 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1459 card->ext_csd.power_off_notification = EXT_CSD_POWER_ON; in mmc_init_card()
1465 err = mmc_select_timing(card); in mmc_init_card()
1469 if (mmc_card_hs200(card)) { in mmc_init_card()
1470 err = mmc_hs200_tuning(card); in mmc_init_card()
1474 err = mmc_select_hs400(card); in mmc_init_card()
1477 } else if (mmc_card_hs(card)) { in mmc_init_card()
1479 err = mmc_select_bus_width(card); in mmc_init_card()
1481 err = mmc_select_hs_ddr(card); in mmc_init_card()
1490 mmc_select_powerclass(card); in mmc_init_card()
1495 if (card->ext_csd.hpi) { in mmc_init_card()
1496 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1498 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1503 mmc_hostname(card->host)); in mmc_init_card()
1506 card->ext_csd.hpi_en = 1; in mmc_init_card()
1513 if (card->ext_csd.cache_size > 0) { in mmc_init_card()
1514 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1516 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1525 mmc_hostname(card->host), err); in mmc_init_card()
1526 card->ext_csd.cache_ctrl = 0; in mmc_init_card()
1529 card->ext_csd.cache_ctrl = 1; in mmc_init_card()
1537 if (card->ext_csd.max_packed_writes >= 3 && in mmc_init_card()
1538 card->ext_csd.max_packed_reads >= 5 && in mmc_init_card()
1540 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_init_card()
1543 card->ext_csd.generic_cmd6_time); in mmc_init_card()
1548 mmc_hostname(card->host)); in mmc_init_card()
1549 card->ext_csd.packed_event_en = 0; in mmc_init_card()
1552 card->ext_csd.packed_event_en = 1; in mmc_init_card()
1557 host->card = card; in mmc_init_card()
1564 mmc_remove_card(card); in mmc_init_card()
1571 static int mmc_can_sleep(struct mmc_card *card) in mmc_can_sleep() argument
1573 return (card && card->ext_csd.rev >= 3); in mmc_can_sleep()
1579 struct mmc_card *card = host->card; in mmc_sleep() local
1580 unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); in mmc_sleep()
1588 cmd.arg = card->rca << 16; in mmc_sleep()
1620 static int mmc_can_poweroff_notify(const struct mmc_card *card) in mmc_can_poweroff_notify() argument
1622 return card && in mmc_can_poweroff_notify()
1623 mmc_card_mmc(card) && in mmc_can_poweroff_notify()
1624 (card->ext_csd.power_off_notification == EXT_CSD_POWER_ON); in mmc_can_poweroff_notify()
1627 static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type) in mmc_poweroff_notify() argument
1629 unsigned int timeout = card->ext_csd.generic_cmd6_time; in mmc_poweroff_notify()
1634 timeout = card->ext_csd.power_off_longtime; in mmc_poweroff_notify()
1636 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, in mmc_poweroff_notify()
1641 mmc_hostname(card->host), timeout); in mmc_poweroff_notify()
1644 card->ext_csd.power_off_notification = EXT_CSD_NO_POWER_NOTIFICATION; in mmc_poweroff_notify()
1655 BUG_ON(!host->card); in mmc_remove()
1657 mmc_remove_card(host->card); in mmc_remove()
1658 host->card = NULL; in mmc_remove()
1666 return mmc_send_status(host->card, NULL); in mmc_alive()
1677 BUG_ON(!host->card); in mmc_detect()
1679 mmc_get_card(host->card); in mmc_detect()
1686 mmc_put_card(host->card); in mmc_detect()
1705 BUG_ON(!host->card); in _mmc_suspend()
1709 if (mmc_card_suspended(host->card)) in _mmc_suspend()
1712 if (mmc_card_doing_bkops(host->card)) { in _mmc_suspend()
1713 err = mmc_stop_bkops(host->card); in _mmc_suspend()
1718 err = mmc_flush_cache(host->card); in _mmc_suspend()
1722 if (mmc_can_poweroff_notify(host->card) && in _mmc_suspend()
1724 err = mmc_poweroff_notify(host->card, notify_type); in _mmc_suspend()
1725 else if (mmc_can_sleep(host->card)) in _mmc_suspend()
1732 mmc_card_set_suspended(host->card); in _mmc_suspend()
1748 pm_runtime_disable(&host->card->dev); in mmc_suspend()
1749 pm_runtime_set_suspended(&host->card->dev); in mmc_suspend()
1764 BUG_ON(!host->card); in _mmc_resume()
1768 if (!mmc_card_suspended(host->card)) in _mmc_resume()
1771 mmc_power_up(host, host->card->ocr); in _mmc_resume()
1772 err = mmc_init_card(host, host->card->ocr, host->card); in _mmc_resume()
1773 mmc_card_clr_suspended(host->card); in _mmc_resume()
1791 if (mmc_can_poweroff_notify(host->card) && in mmc_shutdown()
1810 pm_runtime_set_active(&host->card->dev); in mmc_resume()
1811 pm_runtime_mark_last_busy(&host->card->dev); in mmc_resume()
1813 pm_runtime_enable(&host->card->dev); in mmc_resume()
1859 ret = mmc_init_card(host, host->card->ocr, host->card); in mmc_power_restore()
1927 err = mmc_add_card(host->card); in mmc_attach_mmc()
1936 mmc_remove_card(host->card); in mmc_attach_mmc()
1938 host->card = NULL; in mmc_attach_mmc()