Lines Matching full:card

20 #include <linux/mmc/card.h>
25 #include "card.h"
63 struct mmc_card *card; member
70 void mmc_decode_cid(struct mmc_card *card) in mmc_decode_cid() argument
72 u32 *resp = card->raw_cid; in mmc_decode_cid()
75 * Add the raw card ID (cid) data to the entropy pool. It doesn't in mmc_decode_cid()
78 add_device_randomness(&card->raw_cid, sizeof(card->raw_cid)); in mmc_decode_cid()
84 card->cid.manfid = unstuff_bits(resp, 120, 8); in mmc_decode_cid()
85 card->cid.oemid = unstuff_bits(resp, 104, 16); in mmc_decode_cid()
86 card->cid.prod_name[0] = unstuff_bits(resp, 96, 8); in mmc_decode_cid()
87 card->cid.prod_name[1] = unstuff_bits(resp, 88, 8); in mmc_decode_cid()
88 card->cid.prod_name[2] = unstuff_bits(resp, 80, 8); in mmc_decode_cid()
89 card->cid.prod_name[3] = unstuff_bits(resp, 72, 8); in mmc_decode_cid()
90 card->cid.prod_name[4] = unstuff_bits(resp, 64, 8); in mmc_decode_cid()
91 card->cid.hwrev = unstuff_bits(resp, 60, 4); in mmc_decode_cid()
92 card->cid.fwrev = unstuff_bits(resp, 56, 4); in mmc_decode_cid()
93 card->cid.serial = unstuff_bits(resp, 24, 32); in mmc_decode_cid()
94 card->cid.year = unstuff_bits(resp, 12, 8); in mmc_decode_cid()
95 card->cid.month = unstuff_bits(resp, 8, 4); in mmc_decode_cid()
97 card->cid.year += 2000; /* SD cards year offset */ in mmc_decode_cid()
101 * Given a 128-bit response, decode to our card CSD structure.
103 static int mmc_decode_csd(struct mmc_card *card) in mmc_decode_csd() argument
105 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
107 u32 *resp = card->raw_csd; in mmc_decode_csd()
144 mmc_card_set_readonly(card); in mmc_decode_csd()
148 * This is a block-addressed SDHC or SDXC card. Most in mmc_decode_csd()
153 mmc_card_set_blockaddr(card); in mmc_decode_csd()
166 mmc_card_set_ext_capacity(card); in mmc_decode_csd()
181 mmc_card_set_readonly(card); in mmc_decode_csd()
185 mmc_hostname(card->host), csd_struct); in mmc_decode_csd()
189 card->erase_size = csd->erase_size; in mmc_decode_csd()
195 * Given a 64-bit response, decode to our card SCR structure.
197 static int mmc_decode_scr(struct mmc_card *card) in mmc_decode_scr() argument
199 struct sd_scr *scr = &card->scr; in mmc_decode_scr()
203 resp[3] = card->raw_scr[1]; in mmc_decode_scr()
204 resp[2] = card->raw_scr[0]; in mmc_decode_scr()
209 mmc_hostname(card->host), scr_struct); in mmc_decode_scr()
225 card->erased_byte = 0xFF; in mmc_decode_scr()
227 card->erased_byte = 0x0; in mmc_decode_scr()
234 /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ in mmc_decode_scr()
237 pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); in mmc_decode_scr()
247 static int mmc_read_ssr(struct mmc_card *card) in mmc_read_ssr() argument
255 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { in mmc_read_ssr()
256 pr_warn("%s: card lacks mandatory SD Status function\n", in mmc_read_ssr()
257 mmc_hostname(card->host)); in mmc_read_ssr()
261 raw_ssr = kmalloc(sizeof(card->raw_ssr), GFP_KERNEL); in mmc_read_ssr()
265 if (mmc_app_sd_status(card, raw_ssr)) { in mmc_read_ssr()
267 mmc_hostname(card->host)); in mmc_read_ssr()
273 card->raw_ssr[i] = be32_to_cpu(raw_ssr[i]); in mmc_read_ssr()
281 au = unstuff_bits(card->raw_ssr, 428 - 384, 4); in mmc_read_ssr()
283 if (au <= 9 || card->scr.sda_spec3) { in mmc_read_ssr()
284 card->ssr.au = sd_au_size[au]; in mmc_read_ssr()
285 es = unstuff_bits(card->raw_ssr, 408 - 384, 16); in mmc_read_ssr()
286 et = unstuff_bits(card->raw_ssr, 402 - 384, 6); in mmc_read_ssr()
288 eo = unstuff_bits(card->raw_ssr, 400 - 384, 2); in mmc_read_ssr()
289 card->ssr.erase_timeout = (et * 1000) / es; in mmc_read_ssr()
290 card->ssr.erase_offset = eo * 1000; in mmc_read_ssr()
294 mmc_hostname(card->host)); in mmc_read_ssr()
301 resp[3] = card->raw_ssr[6]; in mmc_read_ssr()
303 card->erase_arg = (card->scr.sda_specx && discard_support) ? in mmc_read_ssr()
312 static int mmc_read_switch(struct mmc_card *card) in mmc_read_switch() argument
317 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_read_switch()
320 if (!(card->csd.cmdclass & CCC_SWITCH)) { in mmc_read_switch()
321 pr_warn("%s: card lacks mandatory switch function, performance might suffer\n", in mmc_read_switch()
322 mmc_hostname(card->host)); in mmc_read_switch()
331 * Find out the card's support bits with a mode 0 operation. in mmc_read_switch()
335 err = mmc_sd_switch(card, SD_SWITCH_CHECK, 0, 0, status); in mmc_read_switch()
338 * If the host or the card can't do the switch, in mmc_read_switch()
345 mmc_hostname(card->host)); in mmc_read_switch()
352 card->sw_caps.hs_max_dtr = HIGH_SPEED_MAX_DTR; in mmc_read_switch()
354 if (card->scr.sda_spec3) { in mmc_read_switch()
355 card->sw_caps.sd3_bus_mode = status[13]; in mmc_read_switch()
356 /* Driver Strengths supported by the card */ in mmc_read_switch()
357 card->sw_caps.sd3_drv_type = status[9]; in mmc_read_switch()
358 card->sw_caps.sd3_curr_limit = status[7] | status[6] << 8; in mmc_read_switch()
368 * Test if the card supports high-speed mode and, if so, switch to it.
370 int mmc_sd_switch_hs(struct mmc_card *card) in mmc_sd_switch_hs() argument
375 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_sd_switch_hs()
378 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_switch_hs()
381 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) in mmc_sd_switch_hs()
384 if (card->sw_caps.hs_max_dtr == 0) in mmc_sd_switch_hs()
391 err = mmc_sd_switch(card, SD_SWITCH_SET, 0, in mmc_sd_switch_hs()
397 pr_warn("%s: Problem switching card into high-speed mode!\n", in mmc_sd_switch_hs()
398 mmc_hostname(card->host)); in mmc_sd_switch_hs()
410 static int sd_select_driver_type(struct mmc_card *card, u8 *status) in sd_select_driver_type() argument
415 card->drive_strength = 0; in sd_select_driver_type()
417 card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B; in sd_select_driver_type()
419 drive_strength = mmc_select_drive_strength(card, in sd_select_driver_type()
420 card->sw_caps.uhs_max_dtr, in sd_select_driver_type()
424 err = mmc_sd_switch(card, SD_SWITCH_SET, 2, in sd_select_driver_type()
430 mmc_hostname(card->host)); in sd_select_driver_type()
433 card->drive_strength = drive_strength; in sd_select_driver_type()
437 mmc_set_driver_type(card->host, drv_type); in sd_select_driver_type()
442 static void sd_update_bus_speed_mode(struct mmc_card *card) in sd_update_bus_speed_mode() argument
448 if (!mmc_host_uhs(card->host)) { in sd_update_bus_speed_mode()
449 card->sd_bus_speed = 0; in sd_update_bus_speed_mode()
453 if ((card->host->caps & MMC_CAP_UHS_SDR104) && in sd_update_bus_speed_mode()
454 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) { in sd_update_bus_speed_mode()
455 card->sd_bus_speed = UHS_SDR104_BUS_SPEED; in sd_update_bus_speed_mode()
456 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) && in sd_update_bus_speed_mode()
457 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) { in sd_update_bus_speed_mode()
458 card->sd_bus_speed = UHS_DDR50_BUS_SPEED; in sd_update_bus_speed_mode()
459 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
460 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
462 card->sd_bus_speed = UHS_SDR50_BUS_SPEED; in sd_update_bus_speed_mode()
463 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
465 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) { in sd_update_bus_speed_mode()
466 card->sd_bus_speed = UHS_SDR25_BUS_SPEED; in sd_update_bus_speed_mode()
467 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
469 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
471 card->sd_bus_speed = UHS_SDR12_BUS_SPEED; in sd_update_bus_speed_mode()
475 static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status) in sd_set_bus_speed_mode() argument
480 switch (card->sd_bus_speed) { in sd_set_bus_speed_mode()
483 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sd_set_bus_speed_mode()
487 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sd_set_bus_speed_mode()
491 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sd_set_bus_speed_mode()
495 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; in sd_set_bus_speed_mode()
499 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; in sd_set_bus_speed_mode()
505 err = mmc_sd_switch(card, SD_SWITCH_SET, 0, card->sd_bus_speed, status); in sd_set_bus_speed_mode()
509 if ((status[16] & 0xF) != card->sd_bus_speed) in sd_set_bus_speed_mode()
511 mmc_hostname(card->host)); in sd_set_bus_speed_mode()
513 mmc_set_timing(card->host, timing); in sd_set_bus_speed_mode()
514 mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr); in sd_set_bus_speed_mode()
545 static int sd_set_current_limit(struct mmc_card *card, u8 *status) in sd_set_current_limit() argument
556 if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) && in sd_set_current_limit()
557 (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) && in sd_set_current_limit()
558 (card->sd_bus_speed != UHS_DDR50_BUS_SPEED)) in sd_set_current_limit()
565 max_current = sd_get_host_max_current(card->host); in sd_set_current_limit()
569 * higher than the card's maximum current, the card will be using its in sd_set_current_limit()
570 * maximum current, e.g. if the card's maximum current is 300ma, and in sd_set_current_limit()
571 * when we set current limit to 200ma, the card will draw 200ma, and in sd_set_current_limit()
572 * when we set current limit to 400/600/800ma, the card will draw its in sd_set_current_limit()
576 * not supported by the card, the card can rightfully error out the in sd_set_current_limit()
578 * in a 300mA card being limited to 200mA even though the host in sd_set_current_limit()
583 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) in sd_set_current_limit()
586 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) in sd_set_current_limit()
589 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) in sd_set_current_limit()
592 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200) in sd_set_current_limit()
596 err = mmc_sd_switch(card, SD_SWITCH_SET, 3, in sd_set_current_limit()
603 mmc_hostname(card->host)); in sd_set_current_limit()
613 static int mmc_sd_init_uhs_card(struct mmc_card *card) in mmc_sd_init_uhs_card() argument
618 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_init_uhs_card()
626 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
630 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
634 * and card capability. in mmc_sd_init_uhs_card()
636 sd_update_bus_speed_mode(card); in mmc_sd_init_uhs_card()
638 /* Set the driver strength for the card */ in mmc_sd_init_uhs_card()
639 err = sd_select_driver_type(card, status); in mmc_sd_init_uhs_card()
643 /* Set current limit for the card */ in mmc_sd_init_uhs_card()
644 err = sd_set_current_limit(card, status); in mmc_sd_init_uhs_card()
648 /* Set bus speed mode of the card */ in mmc_sd_init_uhs_card()
649 err = sd_set_bus_speed_mode(card, status); in mmc_sd_init_uhs_card()
657 if (!mmc_host_is_spi(card->host) && in mmc_sd_init_uhs_card()
658 (card->host->ios.timing == MMC_TIMING_UHS_SDR50 || in mmc_sd_init_uhs_card()
659 card->host->ios.timing == MMC_TIMING_UHS_DDR50 || in mmc_sd_init_uhs_card()
660 card->host->ios.timing == MMC_TIMING_UHS_SDR104)) { in mmc_sd_init_uhs_card()
661 err = mmc_execute_tuning(card); in mmc_sd_init_uhs_card()
670 if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) { in mmc_sd_init_uhs_card()
672 mmc_hostname(card->host)); in mmc_sd_init_uhs_card()
683 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
684 card->raw_cid[2], card->raw_cid[3]);
685 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
686 card->raw_csd[2], card->raw_csd[3]);
687 MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
690 card->raw_ssr[0], card->raw_ssr[1], card->raw_ssr[2],
691 card->raw_ssr[3], card->raw_ssr[4], card->raw_ssr[5],
692 card->raw_ssr[6], card->raw_ssr[7], card->raw_ssr[8],
693 card->raw_ssr[9], card->raw_ssr[10], card->raw_ssr[11],
694 card->raw_ssr[12], card->raw_ssr[13], card->raw_ssr[14],
695 card->raw_ssr[15]);
696 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
697 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
698 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
699 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
700 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
701 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
702 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
703 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
704 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
705 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
706 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
712 struct mmc_card *card = mmc_dev_to_card(dev); in mmc_dsr_show() local
713 struct mmc_host *host = card->host; in mmc_dsr_show()
715 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
723 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
724 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
725 MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
730 struct mmc_card *card = mmc_dev_to_card(dev); \
732 if (num > card->num_info) \
734 if (!card->info[num - 1][0]) \
736 return sysfs_emit(buf, "%s\n", card->info[num - 1]); \
776 struct mmc_card *card = mmc_dev_to_card(dev); in sd_std_is_visible() local
786 ) &&!mmc_card_sd_combo(card)) in sd_std_is_visible()
803 * Fetch CID from card.
828 * compliant card and we should set bit 30 in mmc_sd_get_cid()
837 * If the host supports one of UHS-I modes, request the card in mmc_sd_get_cid()
838 * to switch to 1.8V signaling level. If the card has failed in mmc_sd_get_cid()
879 int mmc_sd_get_csd(struct mmc_card *card) in mmc_sd_get_csd() argument
884 * Fetch CSD from card. in mmc_sd_get_csd()
886 err = mmc_send_csd(card, card->raw_csd); in mmc_sd_get_csd()
890 err = mmc_decode_csd(card); in mmc_sd_get_csd()
903 * E.g. because they only have micro-SD card slot. For those systems in mmc_sd_get_ro()
904 * assume that the SD card is always read-write. in mmc_sd_get_ro()
917 int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, in mmc_sd_setup_card() argument
924 * Fetch SCR from card. in mmc_sd_setup_card()
926 err = mmc_app_send_scr(card); in mmc_sd_setup_card()
930 err = mmc_decode_scr(card); in mmc_sd_setup_card()
937 err = mmc_read_ssr(card); in mmc_sd_setup_card()
942 mmc_init_erase(card); in mmc_sd_setup_card()
946 * Fetch switch information from card. Note, sd3_bus_mode can change if in mmc_sd_setup_card()
949 err = mmc_read_switch(card); in mmc_sd_setup_card()
956 * card registers because some SDHC cards are not able in mmc_sd_setup_card()
975 mmc_card_set_readonly(card); in mmc_sd_setup_card()
982 unsigned mmc_sd_get_max_clock(struct mmc_card *card) in mmc_sd_get_max_clock() argument
986 if (mmc_card_hs(card)) { in mmc_sd_get_max_clock()
987 if (max_dtr > card->sw_caps.hs_max_dtr) in mmc_sd_get_max_clock()
988 max_dtr = card->sw_caps.hs_max_dtr; in mmc_sd_get_max_clock()
989 } else if (max_dtr > card->csd.max_dtr) { in mmc_sd_get_max_clock()
990 max_dtr = card->csd.max_dtr; in mmc_sd_get_max_clock()
996 static bool mmc_sd_card_using_v18(struct mmc_card *card) in mmc_sd_card_using_v18() argument
1000 * 2 to 4 are zero if the card is initialized at 3.3V signal level. Thus in mmc_sd_card_using_v18()
1001 * they can be used to determine if the card has already switched to in mmc_sd_card_using_v18()
1004 return card->sw_caps.sd3_bus_mode & in mmc_sd_card_using_v18()
1008 static int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset, in sd_write_ext_reg() argument
1011 struct mmc_host *host = card->host; in sd_write_ext_reg()
1049 mmc_set_data_timeout(&data, card); in sd_write_ext_reg()
1055 * Note that, the SD card is allowed to signal busy on DAT0 up to 1s in sd_write_ext_reg()
1068 static int sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page, in sd_read_ext_reg() argument
1084 return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE, in sd_read_ext_reg()
1088 static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page, in sd_parse_ext_reg_power() argument
1099 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); in sd_parse_ext_reg_power()
1102 mmc_hostname(card->host), err); in sd_parse_ext_reg_power()
1107 card->ext_power.rev = reg_buf[0] & 0xf; in sd_parse_ext_reg_power()
1111 card->ext_power.feature_support |= SD_EXT_POWER_OFF_NOTIFY; in sd_parse_ext_reg_power()
1115 card->ext_power.feature_support |= SD_EXT_POWER_SUSTENANCE; in sd_parse_ext_reg_power()
1119 card->ext_power.feature_support |= SD_EXT_POWER_DOWN_MODE; in sd_parse_ext_reg_power()
1121 card->ext_power.fno = fno; in sd_parse_ext_reg_power()
1122 card->ext_power.page = page; in sd_parse_ext_reg_power()
1123 card->ext_power.offset = offset; in sd_parse_ext_reg_power()
1130 static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page, in sd_parse_ext_reg_perf() argument
1140 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); in sd_parse_ext_reg_perf()
1143 mmc_hostname(card->host), err); in sd_parse_ext_reg_perf()
1148 card->ext_perf.rev = reg_buf[0]; in sd_parse_ext_reg_perf()
1152 card->ext_perf.feature_support |= SD_EXT_PERF_FX_EVENT; in sd_parse_ext_reg_perf()
1154 /* Card initiated self-maintenance support at bit 0. */ in sd_parse_ext_reg_perf()
1156 card->ext_perf.feature_support |= SD_EXT_PERF_CARD_MAINT; in sd_parse_ext_reg_perf()
1160 card->ext_perf.feature_support |= SD_EXT_PERF_HOST_MAINT; in sd_parse_ext_reg_perf()
1163 if ((reg_buf[4] & BIT(0)) && !mmc_card_broken_sd_cache(card)) in sd_parse_ext_reg_perf()
1164 card->ext_perf.feature_support |= SD_EXT_PERF_CACHE; in sd_parse_ext_reg_perf()
1168 card->ext_perf.feature_support |= SD_EXT_PERF_CMD_QUEUE; in sd_parse_ext_reg_perf()
1170 card->ext_perf.fno = fno; in sd_parse_ext_reg_perf()
1171 card->ext_perf.page = page; in sd_parse_ext_reg_perf()
1172 card->ext_perf.offset = offset; in sd_parse_ext_reg_perf()
1179 static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf, in sd_parse_ext_reg() argument
1221 return sd_parse_ext_reg_power(card, fno, page, offset); in sd_parse_ext_reg()
1225 return sd_parse_ext_reg_perf(card, fno, page, offset); in sd_parse_ext_reg()
1230 static int sd_read_ext_regs(struct mmc_card *card) in sd_read_ext_regs() argument
1236 if (mmc_host_is_spi(card->host)) in sd_read_ext_regs()
1239 if (!(card->scr.cmds & SD_SCR_CMD48_SUPPORT)) in sd_read_ext_regs()
1250 err = sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf); in sd_read_ext_regs()
1253 mmc_hostname(card->host), err); in sd_read_ext_regs()
1269 * card, even if we can't support the features from the SD function in sd_read_ext_regs()
1274 mmc_hostname(card->host)); in sd_read_ext_regs()
1284 err = sd_parse_ext_reg(card, gen_info_buf, &next_ext_addr); in sd_read_ext_regs()
1287 mmc_hostname(card->host), err); in sd_read_ext_regs()
1299 return host->card->ext_perf.feature_enabled & SD_EXT_PERF_CACHE; in sd_cache_enabled()
1304 struct mmc_card *card = host->card; in sd_flush_cache() local
1320 fno = card->ext_perf.fno; in sd_flush_cache()
1321 page = card->ext_perf.page; in sd_flush_cache()
1322 offset = card->ext_perf.offset + 261; in sd_flush_cache()
1324 err = sd_write_ext_reg(card, fno, page, offset, BIT(0)); in sd_flush_cache()
1331 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_flush_cache()
1337 * Read the Flush Cache bit. The card shall reset it, to confirm that in sd_flush_cache()
1340 err = sd_read_ext_reg(card, fno, page, offset, 1, reg_buf); in sd_flush_cache()
1354 static int sd_enable_cache(struct mmc_card *card) in sd_enable_cache() argument
1359 card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE; in sd_enable_cache()
1369 err = sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page, in sd_enable_cache()
1370 card->ext_perf.offset + 260, BIT(0)); in sd_enable_cache()
1373 mmc_hostname(card->host), err); in sd_enable_cache()
1377 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_enable_cache()
1380 card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE; in sd_enable_cache()
1388 * Handle the detection and initialisation of a card.
1390 * In the case of a resume, "oldcard" will contain the card
1396 struct mmc_card *card; in mmc_sd_init_card() local
1410 pr_debug("%s: Perhaps the card was replaced\n", in mmc_sd_init_card()
1415 card = oldcard; in mmc_sd_init_card()
1418 * Allocate card structure. in mmc_sd_init_card()
1420 card = mmc_alloc_card(host, &sd_type); in mmc_sd_init_card()
1421 if (IS_ERR(card)) in mmc_sd_init_card()
1422 return PTR_ERR(card); in mmc_sd_init_card()
1424 card->ocr = ocr; in mmc_sd_init_card()
1425 card->type = MMC_TYPE_SD; in mmc_sd_init_card()
1426 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_sd_init_card()
1433 host->ops->init_card(host, card); in mmc_sd_init_card()
1436 * For native busses: get card RCA and quit open drain mode. in mmc_sd_init_card()
1439 err = mmc_send_relative_addr(host, &card->rca); in mmc_sd_init_card()
1445 err = mmc_sd_get_csd(card); in mmc_sd_init_card()
1449 mmc_decode_cid(card); in mmc_sd_init_card()
1456 if (card->csd.dsr_imp && host->dsr_req) in mmc_sd_init_card()
1460 * Select card, as all following commands rely on that. in mmc_sd_init_card()
1463 err = mmc_select_card(card); in mmc_sd_init_card()
1468 /* Apply quirks prior to card setup */ in mmc_sd_init_card()
1469 mmc_fixup_device(card, mmc_sd_fixups); in mmc_sd_init_card()
1471 err = mmc_sd_setup_card(host, card, oldcard != NULL); in mmc_sd_init_card()
1476 * If the card has not been power cycled, it may still be using 1.8V in mmc_sd_init_card()
1481 mmc_sd_card_using_v18(card) && in mmc_sd_init_card()
1484 mmc_sd_init_uhs_card(card)) { in mmc_sd_init_card()
1488 mmc_remove_card(card); in mmc_sd_init_card()
1496 err = mmc_sd_init_uhs_card(card); in mmc_sd_init_card()
1503 err = mmc_sd_switch_hs(card); in mmc_sd_init_card()
1505 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sd_init_card()
1512 mmc_set_clock(host, mmc_sd_get_max_clock(card)); in mmc_sd_init_card()
1516 err = host->ops->prepare_sd_hs_tuning(host, card); in mmc_sd_init_card()
1525 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_sd_init_card()
1526 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); in mmc_sd_init_card()
1535 err = host->ops->execute_sd_hs_tuning(host, card); in mmc_sd_init_card()
1543 err = sd_read_ext_regs(card); in mmc_sd_init_card()
1549 if (card->ext_perf.feature_support & SD_EXT_PERF_CACHE) { in mmc_sd_init_card()
1550 err = sd_enable_cache(card); in mmc_sd_init_card()
1556 err = host->cqe_ops->cqe_enable(host, card); in mmc_sd_init_card()
1573 host->card = card; in mmc_sd_init_card()
1578 mmc_remove_card(card); in mmc_sd_init_card()
1584 * Host is being removed. Free up the current card.
1588 mmc_remove_card(host->card); in mmc_sd_remove()
1589 host->card = NULL; in mmc_sd_remove()
1593 * Card detection - card is alive.
1597 return mmc_send_status(host->card, NULL); in mmc_sd_alive()
1601 * Card detection callback from host.
1607 mmc_get_card(host->card, NULL); in mmc_sd_detect()
1610 * Just check if our card has been removed. in mmc_sd_detect()
1614 mmc_put_card(host->card, NULL); in mmc_sd_detect()
1626 static int sd_can_poweroff_notify(struct mmc_card *card) in sd_can_poweroff_notify() argument
1628 return card->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY; in sd_can_poweroff_notify()
1634 struct mmc_card *card = data->card; in sd_busy_poweroff_notify_cb() local
1642 err = sd_read_ext_reg(card, card->ext_power.fno, card->ext_power.page, in sd_busy_poweroff_notify_cb()
1643 card->ext_power.offset + 1, 1, data->reg_buf); in sd_busy_poweroff_notify_cb()
1646 mmc_hostname(card->host), err); in sd_busy_poweroff_notify_cb()
1654 static int sd_poweroff_notify(struct mmc_card *card) in sd_poweroff_notify() argument
1668 err = sd_write_ext_reg(card, card->ext_power.fno, card->ext_power.page, in sd_poweroff_notify()
1669 card->ext_power.offset + 2, BIT(0)); in sd_poweroff_notify()
1672 mmc_hostname(card->host), err); in sd_poweroff_notify()
1677 err = mmc_poll_for_busy(card, SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, in sd_poweroff_notify()
1682 cb_data.card = card; in sd_poweroff_notify()
1684 err = __mmc_poll_for_busy(card->host, 0, SD_POWEROFF_NOTIFY_TIMEOUT_MS, in sd_poweroff_notify()
1694 struct mmc_card *card = host->card; in _mmc_sd_suspend() local
1699 if (mmc_card_suspended(card)) in _mmc_sd_suspend()
1702 if (sd_can_poweroff_notify(card)) in _mmc_sd_suspend()
1703 err = sd_poweroff_notify(card); in _mmc_sd_suspend()
1709 mmc_card_set_suspended(card); in _mmc_sd_suspend()
1726 pm_runtime_disable(&host->card->dev); in mmc_sd_suspend()
1727 pm_runtime_set_suspended(&host->card->dev); in mmc_sd_suspend()
1734 * This function tries to determine if the same card is still present
1743 if (!mmc_card_suspended(host->card)) in _mmc_sd_resume()
1746 mmc_power_up(host, host->card->ocr); in _mmc_sd_resume()
1747 err = mmc_sd_init_card(host, host->card->ocr, host->card); in _mmc_sd_resume()
1748 mmc_card_clr_suspended(host->card); in _mmc_sd_resume()
1760 pm_runtime_enable(&host->card->dev); in mmc_sd_resume()
1799 mmc_power_cycle(host, host->card->ocr); in mmc_sd_hw_reset()
1800 return mmc_sd_init_card(host, host->card->ocr, host->card); in mmc_sd_hw_reset()
1818 * Starting point for SD card init.
1855 * Can we support the voltage(s) of the card(s)? in mmc_attach_sd()
1863 * Detect and init the card. in mmc_attach_sd()
1870 err = mmc_add_card(host->card); in mmc_attach_sd()
1878 mmc_remove_card(host->card); in mmc_attach_sd()
1879 host->card = NULL; in mmc_attach_sd()
1884 pr_err("%s: error %d whilst initialising SD card\n", in mmc_attach_sd()