Lines Matching full:card

20 #include <linux/mmc/card.h>
25 #include "card.h"
76 struct mmc_card *card; member
83 void mmc_decode_cid(struct mmc_card *card) in mmc_decode_cid() argument
85 u32 *resp = card->raw_cid; in mmc_decode_cid()
88 * Add the raw card ID (cid) data to the entropy pool. It doesn't in mmc_decode_cid()
91 add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); in mmc_decode_cid()
97 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); in mmc_decode_cid()
98 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); in mmc_decode_cid()
99 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
100 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
101 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
102 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
103 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
104 card->cid.hwrev = UNSTUFF_BITS(resp, 60, 4); in mmc_decode_cid()
105 card->cid.fwrev = UNSTUFF_BITS(resp, 56, 4); in mmc_decode_cid()
106 card->cid.serial = UNSTUFF_BITS(resp, 24, 32); in mmc_decode_cid()
107 card->cid.year = UNSTUFF_BITS(resp, 12, 8); in mmc_decode_cid()
108 card->cid.month = UNSTUFF_BITS(resp, 8, 4); in mmc_decode_cid()
110 card->cid.year += 2000; /* SD cards year offset */ in mmc_decode_cid()
114 * Given a 128-bit response, decode to our card CSD structure.
116 static int mmc_decode_csd(struct mmc_card *card) in mmc_decode_csd() argument
118 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
120 u32 *resp = card->raw_csd; in mmc_decode_csd()
157 mmc_card_set_readonly(card); in mmc_decode_csd()
161 * This is a block-addressed SDHC or SDXC card. Most in mmc_decode_csd()
166 mmc_card_set_blockaddr(card); in mmc_decode_csd()
179 mmc_card_set_ext_capacity(card); in mmc_decode_csd()
194 mmc_card_set_readonly(card); in mmc_decode_csd()
198 mmc_hostname(card->host), csd_struct); in mmc_decode_csd()
202 card->erase_size = csd->erase_size; in mmc_decode_csd()
208 * Given a 64-bit response, decode to our card SCR structure.
210 static int mmc_decode_scr(struct mmc_card *card) in mmc_decode_scr() argument
212 struct sd_scr *scr = &card->scr; in mmc_decode_scr()
216 resp[3] = card->raw_scr[1]; in mmc_decode_scr()
217 resp[2] = card->raw_scr[0]; in mmc_decode_scr()
222 mmc_hostname(card->host), scr_struct); in mmc_decode_scr()
238 card->erased_byte = 0xFF; in mmc_decode_scr()
240 card->erased_byte = 0x0; in mmc_decode_scr()
247 /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ in mmc_decode_scr()
250 pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); in mmc_decode_scr()
260 static int mmc_read_ssr(struct mmc_card *card) in mmc_read_ssr() argument
268 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { in mmc_read_ssr()
269 pr_warn("%s: card lacks mandatory SD Status function\n", in mmc_read_ssr()
270 mmc_hostname(card->host)); in mmc_read_ssr()
274 raw_ssr = kmalloc(sizeof(card->raw_ssr), GFP_KERNEL); in mmc_read_ssr()
278 if (mmc_app_sd_status(card, raw_ssr)) { in mmc_read_ssr()
280 mmc_hostname(card->host)); in mmc_read_ssr()
286 card->raw_ssr[i] = be32_to_cpu(raw_ssr[i]); in mmc_read_ssr()
294 au = UNSTUFF_BITS(card->raw_ssr, 428 - 384, 4); in mmc_read_ssr()
296 if (au <= 9 || card->scr.sda_spec3) { in mmc_read_ssr()
297 card->ssr.au = sd_au_size[au]; in mmc_read_ssr()
298 es = UNSTUFF_BITS(card->raw_ssr, 408 - 384, 16); in mmc_read_ssr()
299 et = UNSTUFF_BITS(card->raw_ssr, 402 - 384, 6); in mmc_read_ssr()
301 eo = UNSTUFF_BITS(card->raw_ssr, 400 - 384, 2); in mmc_read_ssr()
302 card->ssr.erase_timeout = (et * 1000) / es; in mmc_read_ssr()
303 card->ssr.erase_offset = eo * 1000; in mmc_read_ssr()
307 mmc_hostname(card->host)); in mmc_read_ssr()
314 resp[3] = card->raw_ssr[6]; in mmc_read_ssr()
316 card->erase_arg = (card->scr.sda_specx && discard_support) ? in mmc_read_ssr()
325 static int mmc_read_switch(struct mmc_card *card) in mmc_read_switch() argument
330 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_read_switch()
333 if (!(card->csd.cmdclass & CCC_SWITCH)) { in mmc_read_switch()
334 pr_warn("%s: card lacks mandatory switch function, performance might suffer\n", in mmc_read_switch()
335 mmc_hostname(card->host)); in mmc_read_switch()
344 * Find out the card's support bits with a mode 0 operation. in mmc_read_switch()
348 err = mmc_sd_switch(card, 0, 0, 0, status); in mmc_read_switch()
351 * If the host or the card can't do the switch, in mmc_read_switch()
358 mmc_hostname(card->host)); in mmc_read_switch()
365 card->sw_caps.hs_max_dtr = HIGH_SPEED_MAX_DTR; in mmc_read_switch()
367 if (card->scr.sda_spec3) { in mmc_read_switch()
368 card->sw_caps.sd3_bus_mode = status[13]; in mmc_read_switch()
369 /* Driver Strengths supported by the card */ in mmc_read_switch()
370 card->sw_caps.sd3_drv_type = status[9]; in mmc_read_switch()
371 card->sw_caps.sd3_curr_limit = status[7] | status[6] << 8; in mmc_read_switch()
381 * Test if the card supports high-speed mode and, if so, switch to it.
383 int mmc_sd_switch_hs(struct mmc_card *card) in mmc_sd_switch_hs() argument
388 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_sd_switch_hs()
391 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_switch_hs()
394 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) in mmc_sd_switch_hs()
397 if (card->sw_caps.hs_max_dtr == 0) in mmc_sd_switch_hs()
404 err = mmc_sd_switch(card, 1, 0, HIGH_SPEED_BUS_SPEED, status); in mmc_sd_switch_hs()
409 pr_warn("%s: Problem switching card into high-speed mode!\n", in mmc_sd_switch_hs()
410 mmc_hostname(card->host)); in mmc_sd_switch_hs()
422 static int sd_select_driver_type(struct mmc_card *card, u8 *status) in sd_select_driver_type() argument
427 card->drive_strength = 0; in sd_select_driver_type()
429 card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B; in sd_select_driver_type()
431 drive_strength = mmc_select_drive_strength(card, in sd_select_driver_type()
432 card->sw_caps.uhs_max_dtr, in sd_select_driver_type()
436 err = mmc_sd_switch(card, 1, 2, drive_strength, status); in sd_select_driver_type()
441 mmc_hostname(card->host)); in sd_select_driver_type()
444 card->drive_strength = drive_strength; in sd_select_driver_type()
448 mmc_set_driver_type(card->host, drv_type); in sd_select_driver_type()
453 static void sd_update_bus_speed_mode(struct mmc_card *card) in sd_update_bus_speed_mode() argument
459 if (!mmc_host_uhs(card->host)) { in sd_update_bus_speed_mode()
460 card->sd_bus_speed = 0; in sd_update_bus_speed_mode()
464 if ((card->host->caps & MMC_CAP_UHS_SDR104) && in sd_update_bus_speed_mode()
465 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) { in sd_update_bus_speed_mode()
466 card->sd_bus_speed = UHS_SDR104_BUS_SPEED; in sd_update_bus_speed_mode()
467 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) && in sd_update_bus_speed_mode()
468 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) { in sd_update_bus_speed_mode()
469 card->sd_bus_speed = UHS_DDR50_BUS_SPEED; in sd_update_bus_speed_mode()
470 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
471 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
473 card->sd_bus_speed = UHS_SDR50_BUS_SPEED; in sd_update_bus_speed_mode()
474 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
476 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) { in sd_update_bus_speed_mode()
477 card->sd_bus_speed = UHS_SDR25_BUS_SPEED; in sd_update_bus_speed_mode()
478 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
480 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
482 card->sd_bus_speed = UHS_SDR12_BUS_SPEED; in sd_update_bus_speed_mode()
486 static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status) in sd_set_bus_speed_mode() argument
491 switch (card->sd_bus_speed) { in sd_set_bus_speed_mode()
494 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sd_set_bus_speed_mode()
498 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sd_set_bus_speed_mode()
502 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sd_set_bus_speed_mode()
506 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; in sd_set_bus_speed_mode()
510 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; in sd_set_bus_speed_mode()
516 err = mmc_sd_switch(card, 1, 0, card->sd_bus_speed, status); in sd_set_bus_speed_mode()
520 if ((status[16] & 0xF) != card->sd_bus_speed) in sd_set_bus_speed_mode()
522 mmc_hostname(card->host)); in sd_set_bus_speed_mode()
524 mmc_set_timing(card->host, timing); in sd_set_bus_speed_mode()
525 mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr); in sd_set_bus_speed_mode()
556 static int sd_set_current_limit(struct mmc_card *card, u8 *status) in sd_set_current_limit() argument
567 if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) && in sd_set_current_limit()
568 (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) && in sd_set_current_limit()
569 (card->sd_bus_speed != UHS_DDR50_BUS_SPEED)) in sd_set_current_limit()
576 max_current = sd_get_host_max_current(card->host); in sd_set_current_limit()
580 * higher than the card's maximum current, the card will be using its in sd_set_current_limit()
581 * maximum current, e.g. if the card's maximum current is 300ma, and in sd_set_current_limit()
582 * when we set current limit to 200ma, the card will draw 200ma, and in sd_set_current_limit()
583 * when we set current limit to 400/600/800ma, the card will draw its in sd_set_current_limit()
587 * not supported by the card, the card can rightfully error out the in sd_set_current_limit()
589 * in a 300mA card being limited to 200mA even though the host in sd_set_current_limit()
594 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) in sd_set_current_limit()
597 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) in sd_set_current_limit()
600 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) in sd_set_current_limit()
603 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200) in sd_set_current_limit()
607 err = mmc_sd_switch(card, 1, 3, current_limit, status); in sd_set_current_limit()
613 mmc_hostname(card->host)); in sd_set_current_limit()
623 static int mmc_sd_init_uhs_card(struct mmc_card *card) in mmc_sd_init_uhs_card() argument
628 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_init_uhs_card()
636 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
640 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
644 * and card capability. in mmc_sd_init_uhs_card()
646 sd_update_bus_speed_mode(card); in mmc_sd_init_uhs_card()
648 /* Set the driver strength for the card */ in mmc_sd_init_uhs_card()
649 err = sd_select_driver_type(card, status); in mmc_sd_init_uhs_card()
653 /* Set current limit for the card */ in mmc_sd_init_uhs_card()
654 err = sd_set_current_limit(card, status); in mmc_sd_init_uhs_card()
658 /* Set bus speed mode of the card */ in mmc_sd_init_uhs_card()
659 err = sd_set_bus_speed_mode(card, status); in mmc_sd_init_uhs_card()
667 if (!mmc_host_is_spi(card->host) && in mmc_sd_init_uhs_card()
668 (card->host->ios.timing == MMC_TIMING_UHS_SDR50 || in mmc_sd_init_uhs_card()
669 card->host->ios.timing == MMC_TIMING_UHS_DDR50 || in mmc_sd_init_uhs_card()
670 card->host->ios.timing == MMC_TIMING_UHS_SDR104)) { in mmc_sd_init_uhs_card()
671 err = mmc_execute_tuning(card); in mmc_sd_init_uhs_card()
680 if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) { in mmc_sd_init_uhs_card()
682 mmc_hostname(card->host)); in mmc_sd_init_uhs_card()
693 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
694 card->raw_cid[2], card->raw_cid[3]);
695 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
696 card->raw_csd[2], card->raw_csd[3]);
697 MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
700 card->raw_ssr[0], card->raw_ssr[1], card->raw_ssr[2],
701 card->raw_ssr[3], card->raw_ssr[4], card->raw_ssr[5],
702 card->raw_ssr[6], card->raw_ssr[7], card->raw_ssr[8],
703 card->raw_ssr[9], card->raw_ssr[10], card->raw_ssr[11],
704 card->raw_ssr[12], card->raw_ssr[13], card->raw_ssr[14],
705 card->raw_ssr[15]);
706 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
707 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
708 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
709 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
710 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
711 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
712 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
713 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
714 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
715 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
716 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
722 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_dsr_show() local
723 struct mmc_host *host = card->host; in mmc_dsr_show()
725 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
733 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
734 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
735 MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
740 struct mmc_card *card = mmc_dev_to_card(dev); \
742 if (num > card->num_info) \
744 if (!card->info[num - 1][0]) \
746 return sysfs_emit(buf, "%s\n", card->info[num - 1]); \
786 struct mmc_card *card = mmc_dev_to_card(dev); in sd_std_is_visible() local
796 ) &&!mmc_card_sd_combo(card)) in sd_std_is_visible()
813 * Fetch CID from card.
838 * compliant card and we should set bit 30 in mmc_sd_get_cid()
847 * If the host supports one of UHS-I modes, request the card in mmc_sd_get_cid()
848 * to switch to 1.8V signaling level. If the card has failed in mmc_sd_get_cid()
889 int mmc_sd_get_csd(struct mmc_card *card) in mmc_sd_get_csd() argument
894 * Fetch CSD from card. in mmc_sd_get_csd()
896 err = mmc_send_csd(card, card->raw_csd); in mmc_sd_get_csd()
900 err = mmc_decode_csd(card); in mmc_sd_get_csd()
913 * E.g. because they only have micro-SD card slot. For those systems in mmc_sd_get_ro()
914 * assume that the SD card is always read-write. in mmc_sd_get_ro()
927 int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, in mmc_sd_setup_card() argument
934 * Fetch SCR from card. in mmc_sd_setup_card()
936 err = mmc_app_send_scr(card); in mmc_sd_setup_card()
940 err = mmc_decode_scr(card); in mmc_sd_setup_card()
947 err = mmc_read_ssr(card); in mmc_sd_setup_card()
952 mmc_init_erase(card); in mmc_sd_setup_card()
956 * Fetch switch information from card. Note, sd3_bus_mode can change if in mmc_sd_setup_card()
959 err = mmc_read_switch(card); in mmc_sd_setup_card()
966 * card registers because some SDHC cards are not able in mmc_sd_setup_card()
985 mmc_card_set_readonly(card); in mmc_sd_setup_card()
992 unsigned mmc_sd_get_max_clock(struct mmc_card *card) in mmc_sd_get_max_clock() argument
996 if (mmc_card_hs(card)) { in mmc_sd_get_max_clock()
997 if (max_dtr > card->sw_caps.hs_max_dtr) in mmc_sd_get_max_clock()
998 max_dtr = card->sw_caps.hs_max_dtr; in mmc_sd_get_max_clock()
999 } else if (max_dtr > card->csd.max_dtr) { in mmc_sd_get_max_clock()
1000 max_dtr = card->csd.max_dtr; in mmc_sd_get_max_clock()
1006 static bool mmc_sd_card_using_v18(struct mmc_card *card) in mmc_sd_card_using_v18() argument
1010 * 2 to 4 are zero if the card is initialized at 3.3V signal level. Thus in mmc_sd_card_using_v18()
1011 * they can be used to determine if the card has already switched to in mmc_sd_card_using_v18()
1014 return card->sw_caps.sd3_bus_mode & in mmc_sd_card_using_v18()
1018 static int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset, in sd_write_ext_reg() argument
1021 struct mmc_host *host = card->host; in sd_write_ext_reg()
1059 mmc_set_data_timeout(&data, card); in sd_write_ext_reg()
1065 * Note that, the SD card is allowed to signal busy on DAT0 up to 1s in sd_write_ext_reg()
1078 static int sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page, in sd_read_ext_reg() argument
1094 return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE, in sd_read_ext_reg()
1098 static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page, in sd_parse_ext_reg_power() argument
1109 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); in sd_parse_ext_reg_power()
1112 mmc_hostname(card->host), err); in sd_parse_ext_reg_power()
1117 card->ext_power.rev = reg_buf[0] & 0xf; in sd_parse_ext_reg_power()
1121 card->ext_power.feature_support |= SD_EXT_POWER_OFF_NOTIFY; in sd_parse_ext_reg_power()
1125 card->ext_power.feature_support |= SD_EXT_POWER_SUSTENANCE; in sd_parse_ext_reg_power()
1129 card->ext_power.feature_support |= SD_EXT_POWER_DOWN_MODE; in sd_parse_ext_reg_power()
1131 card->ext_power.fno = fno; in sd_parse_ext_reg_power()
1132 card->ext_power.page = page; in sd_parse_ext_reg_power()
1133 card->ext_power.offset = offset; in sd_parse_ext_reg_power()
1140 static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page, in sd_parse_ext_reg_perf() argument
1150 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); in sd_parse_ext_reg_perf()
1153 mmc_hostname(card->host), err); in sd_parse_ext_reg_perf()
1158 card->ext_perf.rev = reg_buf[0]; in sd_parse_ext_reg_perf()
1162 card->ext_perf.feature_support |= SD_EXT_PERF_FX_EVENT; in sd_parse_ext_reg_perf()
1164 /* Card initiated self-maintenance support at bit 0. */ in sd_parse_ext_reg_perf()
1166 card->ext_perf.feature_support |= SD_EXT_PERF_CARD_MAINT; in sd_parse_ext_reg_perf()
1170 card->ext_perf.feature_support |= SD_EXT_PERF_HOST_MAINT; in sd_parse_ext_reg_perf()
1174 card->ext_perf.feature_support |= SD_EXT_PERF_CACHE; in sd_parse_ext_reg_perf()
1178 card->ext_perf.feature_support |= SD_EXT_PERF_CMD_QUEUE; in sd_parse_ext_reg_perf()
1180 card->ext_perf.fno = fno; in sd_parse_ext_reg_perf()
1181 card->ext_perf.page = page; in sd_parse_ext_reg_perf()
1182 card->ext_perf.offset = offset; in sd_parse_ext_reg_perf()
1189 static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf, in sd_parse_ext_reg() argument
1231 return sd_parse_ext_reg_power(card, fno, page, offset); in sd_parse_ext_reg()
1235 return sd_parse_ext_reg_perf(card, fno, page, offset); in sd_parse_ext_reg()
1240 static int sd_read_ext_regs(struct mmc_card *card) in sd_read_ext_regs() argument
1246 if (mmc_host_is_spi(card->host)) in sd_read_ext_regs()
1249 if (!(card->scr.cmds & SD_SCR_CMD48_SUPPORT)) in sd_read_ext_regs()
1260 err = sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf); in sd_read_ext_regs()
1263 mmc_hostname(card->host), err); in sd_read_ext_regs()
1279 mmc_hostname(card->host)); in sd_read_ext_regs()
1289 err = sd_parse_ext_reg(card, gen_info_buf, &next_ext_addr); in sd_read_ext_regs()
1292 mmc_hostname(card->host), err); in sd_read_ext_regs()
1304 return host->card->ext_perf.feature_enabled & SD_EXT_PERF_CACHE; in sd_cache_enabled()
1309 struct mmc_card *card = host->card; in sd_flush_cache() local
1325 fno = card->ext_perf.fno; in sd_flush_cache()
1326 page = card->ext_perf.page; in sd_flush_cache()
1327 offset = card->ext_perf.offset + 261; in sd_flush_cache()
1329 err = sd_write_ext_reg(card, fno, page, offset, BIT(0)); in sd_flush_cache()
1336 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_flush_cache()
1342 * Read the Flush Cache bit. The card shall reset it, to confirm that in sd_flush_cache()
1345 err = sd_read_ext_reg(card, fno, page, offset, 1, reg_buf); in sd_flush_cache()
1359 static int sd_enable_cache(struct mmc_card *card) in sd_enable_cache() argument
1364 card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE; in sd_enable_cache()
1374 err = sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page, in sd_enable_cache()
1375 card->ext_perf.offset + 260, BIT(0)); in sd_enable_cache()
1378 mmc_hostname(card->host), err); in sd_enable_cache()
1382 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_enable_cache()
1385 card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE; in sd_enable_cache()
1393 * Handle the detection and initialisation of a card.
1395 * In the case of a resume, "oldcard" will contain the card
1401 struct mmc_card *card; in mmc_sd_init_card() local
1415 pr_debug("%s: Perhaps the card was replaced\n", in mmc_sd_init_card()
1420 card = oldcard; in mmc_sd_init_card()
1423 * Allocate card structure. in mmc_sd_init_card()
1425 card = mmc_alloc_card(host, &sd_type); in mmc_sd_init_card()
1426 if (IS_ERR(card)) in mmc_sd_init_card()
1427 return PTR_ERR(card); in mmc_sd_init_card()
1429 card->ocr = ocr; in mmc_sd_init_card()
1430 card->type = MMC_TYPE_SD; in mmc_sd_init_card()
1431 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_sd_init_card()
1438 host->ops->init_card(host, card); in mmc_sd_init_card()
1441 * For native busses: get card RCA and quit open drain mode. in mmc_sd_init_card()
1444 err = mmc_send_relative_addr(host, &card->rca); in mmc_sd_init_card()
1450 err = mmc_sd_get_csd(card); in mmc_sd_init_card()
1454 mmc_decode_cid(card); in mmc_sd_init_card()
1461 if (card->csd.dsr_imp && host->dsr_req) in mmc_sd_init_card()
1465 * Select card, as all following commands rely on that. in mmc_sd_init_card()
1468 err = mmc_select_card(card); in mmc_sd_init_card()
1473 err = mmc_sd_setup_card(host, card, oldcard != NULL); in mmc_sd_init_card()
1478 * If the card has not been power cycled, it may still be using 1.8V in mmc_sd_init_card()
1483 mmc_sd_card_using_v18(card) && in mmc_sd_init_card()
1486 mmc_sd_init_uhs_card(card)) { in mmc_sd_init_card()
1490 mmc_remove_card(card); in mmc_sd_init_card()
1498 err = mmc_sd_init_uhs_card(card); in mmc_sd_init_card()
1505 err = mmc_sd_switch_hs(card); in mmc_sd_init_card()
1507 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sd_init_card()
1514 mmc_set_clock(host, mmc_sd_get_max_clock(card)); in mmc_sd_init_card()
1520 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_sd_init_card()
1521 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); in mmc_sd_init_card()
1531 err = sd_read_ext_regs(card); in mmc_sd_init_card()
1537 if (card->ext_perf.feature_support & SD_EXT_PERF_CACHE) { in mmc_sd_init_card()
1538 err = sd_enable_cache(card); in mmc_sd_init_card()
1544 err = host->cqe_ops->cqe_enable(host, card); in mmc_sd_init_card()
1561 host->card = card; in mmc_sd_init_card()
1566 mmc_remove_card(card); in mmc_sd_init_card()
1572 * Host is being removed. Free up the current card.
1576 mmc_remove_card(host->card); in mmc_sd_remove()
1577 host->card = NULL; in mmc_sd_remove()
1581 * Card detection - card is alive.
1585 return mmc_send_status(host->card, NULL); in mmc_sd_alive()
1589 * Card detection callback from host.
1595 mmc_get_card(host->card, NULL); in mmc_sd_detect()
1598 * Just check if our card has been removed. in mmc_sd_detect()
1602 mmc_put_card(host->card, NULL); in mmc_sd_detect()
1614 static int sd_can_poweroff_notify(struct mmc_card *card) in sd_can_poweroff_notify() argument
1616 return card->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY; in sd_can_poweroff_notify()
1622 struct mmc_card *card = data->card; in sd_busy_poweroff_notify_cb() local
1630 err = sd_read_ext_reg(card, card->ext_power.fno, card->ext_power.page, in sd_busy_poweroff_notify_cb()
1631 card->ext_power.offset + 1, 1, data->reg_buf); in sd_busy_poweroff_notify_cb()
1634 mmc_hostname(card->host), err); in sd_busy_poweroff_notify_cb()
1642 static int sd_poweroff_notify(struct mmc_card *card) in sd_poweroff_notify() argument
1656 err = sd_write_ext_reg(card, card->ext_power.fno, card->ext_power.page, in sd_poweroff_notify()
1657 card->ext_power.offset + 2, BIT(0)); in sd_poweroff_notify()
1660 mmc_hostname(card->host), err); in sd_poweroff_notify()
1665 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_poweroff_notify()
1670 cb_data.card = card; in sd_poweroff_notify()
1672 err = __mmc_poll_for_busy(card->host, 0, SD_POWEROFF_NOTIFY_TIMEOUT_MS, in sd_poweroff_notify()
1682 struct mmc_card *card = host->card; in _mmc_sd_suspend() local
1687 if (mmc_card_suspended(card)) in _mmc_sd_suspend()
1690 if (sd_can_poweroff_notify(card)) in _mmc_sd_suspend()
1691 err = sd_poweroff_notify(card); in _mmc_sd_suspend()
1697 mmc_card_set_suspended(card); in _mmc_sd_suspend()
1714 pm_runtime_disable(&host->card->dev); in mmc_sd_suspend()
1715 pm_runtime_set_suspended(&host->card->dev); in mmc_sd_suspend()
1722 * This function tries to determine if the same card is still present
1731 if (!mmc_card_suspended(host->card)) in _mmc_sd_resume()
1734 mmc_power_up(host, host->card->ocr); in _mmc_sd_resume()
1735 err = mmc_sd_init_card(host, host->card->ocr, host->card); in _mmc_sd_resume()
1736 mmc_card_clr_suspended(host->card); in _mmc_sd_resume()
1748 pm_runtime_enable(&host->card->dev); in mmc_sd_resume()
1787 mmc_power_cycle(host, host->card->ocr); in mmc_sd_hw_reset()
1788 return mmc_sd_init_card(host, host->card->ocr, host->card); in mmc_sd_hw_reset()
1806 * Starting point for SD card init.
1843 * Can we support the voltage(s) of the card(s)? in mmc_attach_sd()
1851 * Detect and init the card. in mmc_attach_sd()
1858 err = mmc_add_card(host->card); in mmc_attach_sd()
1866 mmc_remove_card(host->card); in mmc_attach_sd()
1867 host->card = NULL; in mmc_attach_sd()
1872 pr_err("%s: error %d whilst initialising SD card\n", in mmc_attach_sd()