Lines Matching +full:1 +full:- +full:sdxc

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
7 * Copyright (C) 2005-2007 Pierre Ossman, All Rights Reserved.
44 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
72 u32 *resp = card->raw_cid; 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.
105 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
107 u32 *resp = card->raw_csd; in mmc_decode_csd()
115 csd->taac_ns = (taac_exp[e] * taac_mant[m] + 9) / 10; in mmc_decode_csd()
116 csd->taac_clks = unstuff_bits(resp, 104, 8) * 100; in mmc_decode_csd()
120 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
121 csd->cmdclass = unstuff_bits(resp, 84, 12); in mmc_decode_csd()
125 csd->capacity = (1 + m) << (e + 2); in mmc_decode_csd()
127 csd->read_blkbits = unstuff_bits(resp, 80, 4); in mmc_decode_csd()
128 csd->read_partial = unstuff_bits(resp, 79, 1); in mmc_decode_csd()
129 csd->write_misalign = unstuff_bits(resp, 78, 1); in mmc_decode_csd()
130 csd->read_misalign = unstuff_bits(resp, 77, 1); in mmc_decode_csd()
131 csd->dsr_imp = unstuff_bits(resp, 76, 1); in mmc_decode_csd()
132 csd->r2w_factor = unstuff_bits(resp, 26, 3); in mmc_decode_csd()
133 csd->write_blkbits = unstuff_bits(resp, 22, 4); in mmc_decode_csd()
134 csd->write_partial = unstuff_bits(resp, 21, 1); in mmc_decode_csd()
136 if (unstuff_bits(resp, 46, 1)) { in mmc_decode_csd()
137 csd->erase_size = 1; in mmc_decode_csd()
138 } else if (csd->write_blkbits >= 9) { in mmc_decode_csd()
139 csd->erase_size = unstuff_bits(resp, 39, 7) + 1; in mmc_decode_csd()
140 csd->erase_size <<= csd->write_blkbits - 9; in mmc_decode_csd()
143 if (unstuff_bits(resp, 13, 1)) in mmc_decode_csd()
146 case 1: in mmc_decode_csd()
148 * This is a block-addressed SDHC or SDXC card. Most in mmc_decode_csd()
155 csd->taac_ns = 0; /* Unused */ in mmc_decode_csd()
156 csd->taac_clks = 0; /* Unused */ in mmc_decode_csd()
160 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
161 csd->cmdclass = unstuff_bits(resp, 84, 12); in mmc_decode_csd()
162 csd->c_size = unstuff_bits(resp, 48, 22); in mmc_decode_csd()
164 /* SDXC cards have a minimum C_SIZE of 0x00FFFF */ in mmc_decode_csd()
165 if (csd->c_size >= 0xFFFF) in mmc_decode_csd()
169 csd->capacity = (1 + m) << 10; in mmc_decode_csd()
171 csd->read_blkbits = 9; in mmc_decode_csd()
172 csd->read_partial = 0; in mmc_decode_csd()
173 csd->write_misalign = 0; in mmc_decode_csd()
174 csd->read_misalign = 0; in mmc_decode_csd()
175 csd->r2w_factor = 4; /* Unused */ in mmc_decode_csd()
176 csd->write_blkbits = 9; in mmc_decode_csd()
177 csd->write_partial = 0; in mmc_decode_csd()
178 csd->erase_size = 1; in mmc_decode_csd()
180 if (unstuff_bits(resp, 13, 1)) in mmc_decode_csd()
185 mmc_hostname(card->host), csd_struct); in mmc_decode_csd()
186 return -EINVAL; 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.
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()
210 return -EINVAL; in mmc_decode_scr()
213 scr->sda_vsn = unstuff_bits(resp, 56, 4); in mmc_decode_scr()
214 scr->bus_widths = unstuff_bits(resp, 48, 4); in mmc_decode_scr()
215 if (scr->sda_vsn == SCR_SPEC_VER_2) in mmc_decode_scr()
217 scr->sda_spec3 = unstuff_bits(resp, 47, 1); in mmc_decode_scr()
219 if (scr->sda_spec3) { in mmc_decode_scr()
220 scr->sda_spec4 = unstuff_bits(resp, 42, 1); in mmc_decode_scr()
221 scr->sda_specx = unstuff_bits(resp, 38, 4); in mmc_decode_scr()
224 if (unstuff_bits(resp, 55, 1)) in mmc_decode_scr()
225 card->erased_byte = 0xFF; in mmc_decode_scr()
227 card->erased_byte = 0x0; in mmc_decode_scr()
229 if (scr->sda_spec4) in mmc_decode_scr()
230 scr->cmds = unstuff_bits(resp, 32, 4); in mmc_decode_scr()
231 else if (scr->sda_spec3) in mmc_decode_scr()
232 scr->cmds = unstuff_bits(resp, 32, 2); in mmc_decode_scr()
235 if (!(scr->bus_widths & SD_SCR_BUS_WIDTH_1) || in mmc_decode_scr()
236 !(scr->bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_decode_scr()
237 pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); in mmc_decode_scr()
238 return -EINVAL; in mmc_decode_scr()
255 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { 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()
263 return -ENOMEM; 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()
299 * starting SD5.1 discard is supported if DISCARD_SUPPORT (b313) is set in mmc_read_ssr()
301 resp[3] = card->raw_ssr[6]; in mmc_read_ssr()
302 discard_support = unstuff_bits(resp, 313 - 288, 1); in mmc_read_ssr()
303 card->erase_arg = (card->scr.sda_specx && discard_support) ? in mmc_read_ssr()
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()
322 mmc_hostname(card->host)); in mmc_read_switch()
328 return -ENOMEM; in mmc_read_switch()
341 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) 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()
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.
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()
389 return -ENOMEM; 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()
401 err = 1; in mmc_sd_switch_hs()
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()
420 card->sw_caps.uhs_max_dtr, 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()
445 * If the host doesn't support any of the UHS-I modes, fallback on in sd_update_bus_speed_mode()
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()
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()
525 voltage = 1 << host->ios.vdd; in sd_get_host_max_current()
528 max_current = host->max_current_180; in sd_get_host_max_current()
532 max_current = host->max_current_300; in sd_get_host_max_current()
536 max_current = host->max_current_330; in sd_get_host_max_current()
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()
580 * an iMX6 host. --rmk 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()
603 mmc_hostname(card->host)); in sd_set_current_limit()
611 * UHS-I specific initialization procedure
618 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_init_uhs_card()
623 return -ENOMEM; in mmc_sd_init_uhs_card()
625 /* Set 4-bit bus width */ in mmc_sd_init_uhs_card()
630 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
655 * SDR104 mode SD-cards. Note that tuning is mandatory for SDR104. 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()
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);
713 struct mmc_host *host = card->host; in mmc_dsr_show()
715 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
716 return sysfs_emit(buf, "0x%x\n", host->dsr); 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);
732 if (num > card->num_info) \
733 return -ENODATA; \
734 if (!card->info[num - 1][0]) \
736 return sysfs_emit(buf, "%s\n", card->info[num - 1]); \
740 sdio_info_attr(1);
789 return attr->mode; in sd_std_is_visible()
821 * state. We wait 1ms to give cards time to in mmc_sd_get_cid()
830 * block-addressed SDHC cards. in mmc_sd_get_cid()
837 * If the host supports one of UHS-I modes, request the card in mmc_sd_get_cid()
846 * XPC should be set to 1. in mmc_sd_get_cid()
861 * regards to this, which allows UHS-I to be supported for SDSC cards. in mmc_sd_get_cid()
866 if (err == -EAGAIN) { in mmc_sd_get_cid()
867 retries--; in mmc_sd_get_cid()
886 err = mmc_send_csd(card, card->raw_csd); in mmc_sd_get_csd()
902 * Some systems don't feature a write-protect pin and don't need one. in mmc_sd_get_ro()
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()
906 if (host->caps2 & MMC_CAP2_NO_WRITE_PROTECT) in mmc_sd_get_ro()
909 if (!host->ops->get_ro) in mmc_sd_get_ro()
910 return -1; in mmc_sd_get_ro()
912 ro = host->ops->get_ro(host); in mmc_sd_get_ro()
957 * to provide valid CRCs for non-512-byte blocks. in mmc_sd_setup_card()
966 * Check if read-only switch is active. in mmc_sd_setup_card()
972 pr_warn("%s: host does not support reading read-only switch, assuming write-enable\n", in mmc_sd_setup_card()
984 unsigned max_dtr = (unsigned int)-1; 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()
999 * According to the SD spec., the Bus Speed Mode (function group 1) bits in mmc_sd_card_using_v18()
1004 return card->sw_caps.sd3_bus_mode & in mmc_sd_card_using_v18()
1011 struct mmc_host *host = card->host; in sd_write_ext_reg()
1020 return -ENOMEM; in sd_write_ext_reg()
1029 * [26:26] MW - mask write mode (0 = disable). in sd_write_ext_reg()
1032 * [8:0] length (0 = 1 byte). in sd_write_ext_reg()
1041 data.blocks = 1; in sd_write_ext_reg()
1043 data.sg_len = 1; 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()
1080 * [8:0] length (0 = 1 byte, 1ff = 512 bytes). in sd_read_ext_reg()
1082 cmd_args = fno << 27 | page << 18 | offset << 9 | (len -1); in sd_read_ext_reg()
1084 return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE, in sd_read_ext_reg()
1096 return -ENOMEM; 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()
1110 if (reg_buf[1] & BIT(4)) in sd_parse_ext_reg_power()
1111 card->ext_power.feature_support |= SD_EXT_POWER_OFF_NOTIFY; in sd_parse_ext_reg_power()
1114 if (reg_buf[1] & BIT(5)) in sd_parse_ext_reg_power()
1115 card->ext_power.feature_support |= SD_EXT_POWER_SUSTENANCE; in sd_parse_ext_reg_power()
1118 if (reg_buf[1] & BIT(6)) 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()
1138 return -ENOMEM; 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()
1151 if (reg_buf[1] & BIT(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()
1158 /* Host initiated self-maintenance support at bit 1. */ in sd_parse_ext_reg_perf()
1159 if (reg_buf[2] & BIT(1)) in sd_parse_ext_reg_perf()
1160 card->ext_perf.feature_support |= SD_EXT_PERF_HOST_MAINT; 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()
1192 return -EFAULT; in sd_parse_ext_reg()
1204 if (num_regs != 1) in sd_parse_ext_reg()
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()
1244 return -ENOMEM; in sd_read_ext_regs()
1253 mmc_hostname(card->host), err); in sd_read_ext_regs()
1273 pr_warn("%s: non-supported SD ext reg layout\n", in sd_read_ext_regs()
1274 mmc_hostname(card->host)); 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()
1314 return -ENOMEM; in sd_flush_cache()
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()
1340 err = sd_read_ext_reg(card, fno, page, offset, 1, reg_buf); in sd_flush_cache()
1348 err = -ETIMEDOUT; in sd_flush_cache()
1359 card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE; in sd_enable_cache()
1363 return -ENOMEM; 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()
1380 card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE; in sd_enable_cache()
1402 WARN_ON(!host->claimed); in mmc_sd_init_card()
1409 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { in mmc_sd_init_card()
1412 return -ENOENT; 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()
1432 if (host->ops->init_card) in mmc_sd_init_card()
1433 host->ops->init_card(host, card); in mmc_sd_init_card()
1439 err = mmc_send_relative_addr(host, &card->rca); in mmc_sd_init_card()
1456 if (card->csd.dsr_imp && host->dsr_req) in mmc_sd_init_card()
1477 * signaling. Detect that situation and try to initialize a UHS-I (1.8V) in mmc_sd_init_card()
1482 host->ios.signal_voltage != MMC_SIGNAL_VOLTAGE_180) { in mmc_sd_init_card()
1494 /* Initialization sequence for UHS-I cards */ in mmc_sd_init_card()
1501 * Attempt to change to high-speed (if supported) in mmc_sd_init_card()
1505 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sd_init_card()
1514 if (host->ios.timing == MMC_TIMING_SD_HS && in mmc_sd_init_card()
1515 host->ops->prepare_sd_hs_tuning) { in mmc_sd_init_card()
1516 err = host->ops->prepare_sd_hs_tuning(host, card); in mmc_sd_init_card()
1524 if ((host->caps & MMC_CAP_4_BIT_DATA) && in mmc_sd_init_card()
1525 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_sd_init_card()
1533 if (host->ios.timing == MMC_TIMING_SD_HS && in mmc_sd_init_card()
1534 host->ops->execute_sd_hs_tuning) { in mmc_sd_init_card()
1535 err = host->ops->execute_sd_hs_tuning(host, card); in mmc_sd_init_card()
1549 if (card->ext_perf.feature_support & SD_EXT_PERF_CACHE) { in mmc_sd_init_card()
1555 if (host->cqe_ops && !host->cqe_enabled) { in mmc_sd_init_card()
1556 err = host->cqe_ops->cqe_enable(host, card); in mmc_sd_init_card()
1558 host->cqe_enabled = true; in mmc_sd_init_card()
1559 host->hsq_enabled = true; in mmc_sd_init_card()
1565 if (host->caps2 & MMC_CAP2_AVOID_3_3V && in mmc_sd_init_card()
1566 host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in mmc_sd_init_card()
1569 err = -EINVAL; in mmc_sd_init_card()
1573 host->card = card; in mmc_sd_init_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()
1607 mmc_get_card(host->card, NULL); in mmc_sd_detect()
1614 mmc_put_card(host->card, NULL); in mmc_sd_detect()
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()
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()
1650 *busy = !(data->reg_buf[0] & BIT(0)); in sd_busy_poweroff_notify_cb()
1662 return -ENOMEM; in sd_poweroff_notify()
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()
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()
1726 pm_runtime_disable(&host->card->dev); in mmc_sd_suspend()
1727 pm_runtime_set_suspended(&host->card->dev); in mmc_sd_suspend()
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()
1771 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) in mmc_sd_runtime_suspend()
1790 if (err && err != -ENOMEDIUM) in mmc_sd_runtime_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()
1825 WARN_ON(!host->claimed); in mmc_attach_sd()
1832 if (host->ocr_avail_sd) in mmc_attach_sd()
1833 host->ocr_avail = host->ocr_avail_sd; in mmc_attach_sd()
1848 * these bits as being in-valid and especially also bit7. in mmc_attach_sd()
1858 err = -EINVAL; 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()