Lines Matching +full:host +full:- +full:only
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.
16 #include <linux/mmc/host.h>
23 #include "host.h"
58 const u32 __mask = (__size < 32 ? 1 << __size : 0) - 1; \
59 const int __off = 3 - ((start) / 32); \
65 __res |= resp[__off-1] << ((32 - __shft) % 32); \
74 u32 *resp = card->raw_cid; in mmc_decode_cid()
80 card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); in mmc_decode_cid()
81 card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); in mmc_decode_cid()
82 card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); in mmc_decode_cid()
83 card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); in mmc_decode_cid()
84 card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); in mmc_decode_cid()
85 card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); in mmc_decode_cid()
86 card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); in mmc_decode_cid()
87 card->cid.hwrev = UNSTUFF_BITS(resp, 60, 4); in mmc_decode_cid()
88 card->cid.fwrev = UNSTUFF_BITS(resp, 56, 4); in mmc_decode_cid()
89 card->cid.serial = UNSTUFF_BITS(resp, 24, 32); in mmc_decode_cid()
90 card->cid.year = UNSTUFF_BITS(resp, 12, 8); in mmc_decode_cid()
91 card->cid.month = UNSTUFF_BITS(resp, 8, 4); in mmc_decode_cid()
93 card->cid.year += 2000; /* SD cards year offset */ in mmc_decode_cid()
97 * Given a 128-bit response, decode to our card CSD structure.
101 struct mmc_csd *csd = &card->csd; in mmc_decode_csd()
103 u32 *resp = card->raw_csd; in mmc_decode_csd()
111 csd->taac_ns = (taac_exp[e] * taac_mant[m] + 9) / 10; in mmc_decode_csd()
112 csd->taac_clks = UNSTUFF_BITS(resp, 104, 8) * 100; in mmc_decode_csd()
116 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
117 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); in mmc_decode_csd()
121 csd->capacity = (1 + m) << (e + 2); in mmc_decode_csd()
123 csd->read_blkbits = UNSTUFF_BITS(resp, 80, 4); in mmc_decode_csd()
124 csd->read_partial = UNSTUFF_BITS(resp, 79, 1); in mmc_decode_csd()
125 csd->write_misalign = UNSTUFF_BITS(resp, 78, 1); in mmc_decode_csd()
126 csd->read_misalign = UNSTUFF_BITS(resp, 77, 1); in mmc_decode_csd()
127 csd->dsr_imp = UNSTUFF_BITS(resp, 76, 1); in mmc_decode_csd()
128 csd->r2w_factor = UNSTUFF_BITS(resp, 26, 3); in mmc_decode_csd()
129 csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4); in mmc_decode_csd()
130 csd->write_partial = UNSTUFF_BITS(resp, 21, 1); in mmc_decode_csd()
133 csd->erase_size = 1; in mmc_decode_csd()
134 } else if (csd->write_blkbits >= 9) { in mmc_decode_csd()
135 csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1; in mmc_decode_csd()
136 csd->erase_size <<= csd->write_blkbits - 9; in mmc_decode_csd()
141 * This is a block-addressed SDHC or SDXC card. Most in mmc_decode_csd()
148 csd->taac_ns = 0; /* Unused */ in mmc_decode_csd()
149 csd->taac_clks = 0; /* Unused */ in mmc_decode_csd()
153 csd->max_dtr = tran_exp[e] * tran_mant[m]; in mmc_decode_csd()
154 csd->cmdclass = UNSTUFF_BITS(resp, 84, 12); in mmc_decode_csd()
155 csd->c_size = UNSTUFF_BITS(resp, 48, 22); in mmc_decode_csd()
158 if (csd->c_size >= 0xFFFF) in mmc_decode_csd()
162 csd->capacity = (1 + m) << 10; in mmc_decode_csd()
164 csd->read_blkbits = 9; in mmc_decode_csd()
165 csd->read_partial = 0; in mmc_decode_csd()
166 csd->write_misalign = 0; in mmc_decode_csd()
167 csd->read_misalign = 0; in mmc_decode_csd()
168 csd->r2w_factor = 4; /* Unused */ in mmc_decode_csd()
169 csd->write_blkbits = 9; in mmc_decode_csd()
170 csd->write_partial = 0; in mmc_decode_csd()
171 csd->erase_size = 1; in mmc_decode_csd()
175 mmc_hostname(card->host), csd_struct); in mmc_decode_csd()
176 return -EINVAL; in mmc_decode_csd()
179 card->erase_size = csd->erase_size; in mmc_decode_csd()
185 * Given a 64-bit response, decode to our card SCR structure.
189 struct sd_scr *scr = &card->scr; in mmc_decode_scr()
193 resp[3] = card->raw_scr[1]; in mmc_decode_scr()
194 resp[2] = card->raw_scr[0]; in mmc_decode_scr()
199 mmc_hostname(card->host), scr_struct); in mmc_decode_scr()
200 return -EINVAL; in mmc_decode_scr()
203 scr->sda_vsn = UNSTUFF_BITS(resp, 56, 4); in mmc_decode_scr()
204 scr->bus_widths = UNSTUFF_BITS(resp, 48, 4); in mmc_decode_scr()
205 if (scr->sda_vsn == SCR_SPEC_VER_2) in mmc_decode_scr()
207 scr->sda_spec3 = UNSTUFF_BITS(resp, 47, 1); in mmc_decode_scr()
209 if (scr->sda_spec3) { in mmc_decode_scr()
210 scr->sda_spec4 = UNSTUFF_BITS(resp, 42, 1); in mmc_decode_scr()
211 scr->sda_specx = UNSTUFF_BITS(resp, 38, 4); in mmc_decode_scr()
215 card->erased_byte = 0xFF; in mmc_decode_scr()
217 card->erased_byte = 0x0; in mmc_decode_scr()
219 if (scr->sda_spec3) in mmc_decode_scr()
220 scr->cmds = UNSTUFF_BITS(resp, 32, 2); in mmc_decode_scr()
223 if (!(scr->bus_widths & SD_SCR_BUS_WIDTH_1) || in mmc_decode_scr()
224 !(scr->bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_decode_scr()
225 pr_err("%s: invalid bus width\n", mmc_hostname(card->host)); in mmc_decode_scr()
226 return -EINVAL; in mmc_decode_scr()
243 if (!(card->csd.cmdclass & CCC_APP_SPEC)) { in mmc_read_ssr()
245 mmc_hostname(card->host)); in mmc_read_ssr()
249 raw_ssr = kmalloc(sizeof(card->raw_ssr), GFP_KERNEL); in mmc_read_ssr()
251 return -ENOMEM; in mmc_read_ssr()
255 mmc_hostname(card->host)); in mmc_read_ssr()
261 card->raw_ssr[i] = be32_to_cpu(raw_ssr[i]); in mmc_read_ssr()
266 * UNSTUFF_BITS only works with four u32s so we have to offset the in mmc_read_ssr()
269 au = UNSTUFF_BITS(card->raw_ssr, 428 - 384, 4); in mmc_read_ssr()
271 if (au <= 9 || card->scr.sda_spec3) { in mmc_read_ssr()
272 card->ssr.au = sd_au_size[au]; in mmc_read_ssr()
273 es = UNSTUFF_BITS(card->raw_ssr, 408 - 384, 16); in mmc_read_ssr()
274 et = UNSTUFF_BITS(card->raw_ssr, 402 - 384, 6); in mmc_read_ssr()
276 eo = UNSTUFF_BITS(card->raw_ssr, 400 - 384, 2); in mmc_read_ssr()
277 card->ssr.erase_timeout = (et * 1000) / es; in mmc_read_ssr()
278 card->ssr.erase_offset = eo * 1000; in mmc_read_ssr()
282 mmc_hostname(card->host)); in mmc_read_ssr()
289 resp[3] = card->raw_ssr[6]; in mmc_read_ssr()
290 discard_support = UNSTUFF_BITS(resp, 313 - 288, 1); in mmc_read_ssr()
291 card->erase_arg = (card->scr.sda_specx && discard_support) ? in mmc_read_ssr()
305 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_read_switch()
308 if (!(card->csd.cmdclass & CCC_SWITCH)) { in mmc_read_switch()
310 mmc_hostname(card->host)); in mmc_read_switch()
316 return -ENOMEM; in mmc_read_switch()
326 * If the host or the card can't do the switch, in mmc_read_switch()
329 if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) in mmc_read_switch()
333 mmc_hostname(card->host)); in mmc_read_switch()
340 card->sw_caps.hs_max_dtr = HIGH_SPEED_MAX_DTR; in mmc_read_switch()
342 if (card->scr.sda_spec3) { in mmc_read_switch()
343 card->sw_caps.sd3_bus_mode = status[13]; in mmc_read_switch()
345 card->sw_caps.sd3_drv_type = status[9]; in mmc_read_switch()
346 card->sw_caps.sd3_curr_limit = status[7] | status[6] << 8; in mmc_read_switch()
356 * Test if the card supports high-speed mode and, if so, switch to it.
363 if (card->scr.sda_vsn < SCR_SPEC_VER_1) in mmc_sd_switch_hs()
366 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_switch_hs()
369 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) in mmc_sd_switch_hs()
372 if (card->sw_caps.hs_max_dtr == 0) in mmc_sd_switch_hs()
377 return -ENOMEM; in mmc_sd_switch_hs()
384 pr_warn("%s: Problem switching card into high-speed mode!\n", in mmc_sd_switch_hs()
385 mmc_hostname(card->host)); in mmc_sd_switch_hs()
402 card->drive_strength = 0; in sd_select_driver_type()
404 card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B; in sd_select_driver_type()
407 card->sw_caps.uhs_max_dtr, in sd_select_driver_type()
416 mmc_hostname(card->host)); in sd_select_driver_type()
419 card->drive_strength = drive_strength; in sd_select_driver_type()
423 mmc_set_driver_type(card->host, drv_type); in sd_select_driver_type()
431 * If the host doesn't support any of the UHS-I modes, fallback on in sd_update_bus_speed_mode()
434 if (!mmc_host_uhs(card->host)) { in sd_update_bus_speed_mode()
435 card->sd_bus_speed = 0; in sd_update_bus_speed_mode()
439 if ((card->host->caps & MMC_CAP_UHS_SDR104) && in sd_update_bus_speed_mode()
440 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) { in sd_update_bus_speed_mode()
441 card->sd_bus_speed = UHS_SDR104_BUS_SPEED; in sd_update_bus_speed_mode()
442 } else if ((card->host->caps & MMC_CAP_UHS_DDR50) && in sd_update_bus_speed_mode()
443 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) { in sd_update_bus_speed_mode()
444 card->sd_bus_speed = UHS_DDR50_BUS_SPEED; in sd_update_bus_speed_mode()
445 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
446 MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
448 card->sd_bus_speed = UHS_SDR50_BUS_SPEED; in sd_update_bus_speed_mode()
449 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
451 (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) { in sd_update_bus_speed_mode()
452 card->sd_bus_speed = UHS_SDR25_BUS_SPEED; in sd_update_bus_speed_mode()
453 } else if ((card->host->caps & (MMC_CAP_UHS_SDR104 | in sd_update_bus_speed_mode()
455 MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode & in sd_update_bus_speed_mode()
457 card->sd_bus_speed = UHS_SDR12_BUS_SPEED; in sd_update_bus_speed_mode()
466 switch (card->sd_bus_speed) { in sd_set_bus_speed_mode()
469 card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR; in sd_set_bus_speed_mode()
473 card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR; in sd_set_bus_speed_mode()
477 card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR; in sd_set_bus_speed_mode()
481 card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR; in sd_set_bus_speed_mode()
485 card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR; in sd_set_bus_speed_mode()
491 err = mmc_sd_switch(card, 1, 0, card->sd_bus_speed, status); in sd_set_bus_speed_mode()
495 if ((status[16] & 0xF) != card->sd_bus_speed) in sd_set_bus_speed_mode()
497 mmc_hostname(card->host)); in sd_set_bus_speed_mode()
499 mmc_set_timing(card->host, timing); in sd_set_bus_speed_mode()
500 mmc_set_clock(card->host, card->sw_caps.uhs_max_dtr); in sd_set_bus_speed_mode()
506 /* Get host's max current setting at its current voltage */
507 static u32 sd_get_host_max_current(struct mmc_host *host) in sd_get_host_max_current() argument
511 voltage = 1 << host->ios.vdd; in sd_get_host_max_current()
514 max_current = host->max_current_180; in sd_get_host_max_current()
518 max_current = host->max_current_300; in sd_get_host_max_current()
522 max_current = host->max_current_330; in sd_get_host_max_current()
538 * Current limit switch is only defined for SDR50, SDR104, and DDR50 in sd_set_current_limit()
542 if ((card->sd_bus_speed != UHS_SDR50_BUS_SPEED) && in sd_set_current_limit()
543 (card->sd_bus_speed != UHS_SDR104_BUS_SPEED) && in sd_set_current_limit()
544 (card->sd_bus_speed != UHS_DDR50_BUS_SPEED)) in sd_set_current_limit()
548 * Host has different current capabilities when operating at in sd_set_current_limit()
551 max_current = sd_get_host_max_current(card->host); in sd_set_current_limit()
554 * We only check host's capability here, if we set a limit that is in sd_set_current_limit()
559 * maximum 300ma from the host. in sd_set_current_limit()
564 * in a 300mA card being limited to 200mA even though the host in sd_set_current_limit()
566 * an iMX6 host. --rmk in sd_set_current_limit()
569 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) in sd_set_current_limit()
572 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) in sd_set_current_limit()
575 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) in sd_set_current_limit()
578 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200) in sd_set_current_limit()
588 mmc_hostname(card->host)); in sd_set_current_limit()
596 * UHS-I specific initialization procedure
603 if (!(card->csd.cmdclass & CCC_SWITCH)) in mmc_sd_init_uhs_card()
608 return -ENOMEM; in mmc_sd_init_uhs_card()
610 /* Set 4-bit bus width */ in mmc_sd_init_uhs_card()
615 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); in mmc_sd_init_uhs_card()
618 * Select the bus speed mode depending on host in mmc_sd_init_uhs_card()
639 * SPI mode doesn't define CMD19 and tuning is only valid for SDR50 and in mmc_sd_init_uhs_card()
640 * SDR104 mode SD-cards. Note that tuning is mandatory for SDR104. in mmc_sd_init_uhs_card()
642 if (!mmc_host_is_spi(card->host) && in mmc_sd_init_uhs_card()
643 (card->host->ios.timing == MMC_TIMING_UHS_SDR50 || in mmc_sd_init_uhs_card()
644 card->host->ios.timing == MMC_TIMING_UHS_DDR50 || in mmc_sd_init_uhs_card()
645 card->host->ios.timing == MMC_TIMING_UHS_SDR104)) { in mmc_sd_init_uhs_card()
655 if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) { in mmc_sd_init_uhs_card()
657 mmc_hostname(card->host)); in mmc_sd_init_uhs_card()
668 MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
669 card->raw_cid[2], card->raw_cid[3]);
670 MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
671 card->raw_csd[2], card->raw_csd[3]);
672 MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
675 card->raw_ssr[0], card->raw_ssr[1], card->raw_ssr[2],
676 card->raw_ssr[3], card->raw_ssr[4], card->raw_ssr[5],
677 card->raw_ssr[6], card->raw_ssr[7], card->raw_ssr[8],
678 card->raw_ssr[9], card->raw_ssr[10], card->raw_ssr[11],
679 card->raw_ssr[12], card->raw_ssr[13], card->raw_ssr[14],
680 card->raw_ssr[15]);
681 MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
682 MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
683 MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
684 MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
685 MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
686 MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
687 MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
688 MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
689 MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
690 MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
691 MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
699 struct mmc_host *host = card->host; in mmc_dsr_show() local
701 if (card->csd.dsr_imp && host->dsr_req) in mmc_dsr_show()
702 return sprintf(buf, "0x%x\n", host->dsr); in mmc_dsr_show()
710 MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
711 MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
712 MMC_DEV_ATTR(revision, "%u.%u\n", card->major_rev, card->minor_rev);
719 if (num > card->num_info) \
720 return -ENODATA; \
721 if (!card->info[num-1][0]) \
723 return sprintf(buf, "%s\n", card->info[num-1]); \
765 /* CIS vendor and device ids, revision and info string are available only for Combo cards */ in sd_std_is_visible()
773 ) && card->type != MMC_TYPE_SD_COMBO) in sd_std_is_visible()
776 return attr->mode; in sd_std_is_visible()
792 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr) in mmc_sd_get_cid() argument
802 pr_warn("%s: Skipping voltage switch\n", mmc_hostname(host)); in mmc_sd_get_cid()
811 mmc_go_idle(host); in mmc_sd_get_cid()
817 * block-addressed SDHC cards. in mmc_sd_get_cid()
819 err = mmc_send_if_cond(host, ocr); in mmc_sd_get_cid()
824 * If the host supports one of UHS-I modes, request the card in mmc_sd_get_cid()
828 if (retries && mmc_host_uhs(host)) in mmc_sd_get_cid()
832 * If the host can supply more than 150mA at current voltage, in mmc_sd_get_cid()
835 max_current = sd_get_host_max_current(host); in mmc_sd_get_cid()
839 err = mmc_send_app_op_cond(host, ocr, rocr); in mmc_sd_get_cid()
847 if (!mmc_host_is_spi(host) && rocr && in mmc_sd_get_cid()
849 err = mmc_set_uhs_voltage(host, pocr); in mmc_sd_get_cid()
850 if (err == -EAGAIN) { in mmc_sd_get_cid()
851 retries--; in mmc_sd_get_cid()
859 err = mmc_send_cid(host, cid); in mmc_sd_get_cid()
863 int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card) in mmc_sd_get_csd() argument
870 err = mmc_send_csd(card, card->raw_csd); in mmc_sd_get_csd()
881 static int mmc_sd_get_ro(struct mmc_host *host) in mmc_sd_get_ro() argument
886 * Some systems don't feature a write-protect pin and don't need one. in mmc_sd_get_ro()
887 * E.g. because they only have micro-SD card slot. For those systems in mmc_sd_get_ro()
888 * assume that the SD card is always read-write. in mmc_sd_get_ro()
890 if (host->caps2 & MMC_CAP2_NO_WRITE_PROTECT) in mmc_sd_get_ro()
893 if (!host->ops->get_ro) in mmc_sd_get_ro()
894 return -1; in mmc_sd_get_ro()
896 ro = host->ops->get_ro(host); in mmc_sd_get_ro()
901 int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, in mmc_sd_setup_card() argument
940 * to provide valid CRCs for non-512-byte blocks. in mmc_sd_setup_card()
942 if (mmc_host_is_spi(host)) { in mmc_sd_setup_card()
943 err = mmc_spi_set_crc(host, use_spi_crc); in mmc_sd_setup_card()
949 * Check if read-only switch is active. in mmc_sd_setup_card()
952 int ro = mmc_sd_get_ro(host); in mmc_sd_setup_card()
955 pr_warn("%s: host does not support reading read-only switch, assuming write-enable\n", in mmc_sd_setup_card()
956 mmc_hostname(host)); in mmc_sd_setup_card()
967 unsigned max_dtr = (unsigned int)-1; in mmc_sd_get_max_clock()
970 if (max_dtr > card->sw_caps.hs_max_dtr) in mmc_sd_get_max_clock()
971 max_dtr = card->sw_caps.hs_max_dtr; in mmc_sd_get_max_clock()
972 } else if (max_dtr > card->csd.max_dtr) { in mmc_sd_get_max_clock()
973 max_dtr = card->csd.max_dtr; in mmc_sd_get_max_clock()
987 return card->sw_caps.sd3_bus_mode & in mmc_sd_card_using_v18()
997 static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, in mmc_sd_init_card() argument
1006 WARN_ON(!host->claimed); in mmc_sd_init_card()
1008 err = mmc_sd_get_cid(host, ocr, cid, &rocr); in mmc_sd_init_card()
1013 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) { in mmc_sd_init_card()
1015 mmc_hostname(host)); in mmc_sd_init_card()
1016 return -ENOENT; in mmc_sd_init_card()
1024 card = mmc_alloc_card(host, &sd_type); in mmc_sd_init_card()
1028 card->ocr = ocr; in mmc_sd_init_card()
1029 card->type = MMC_TYPE_SD; in mmc_sd_init_card()
1030 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); in mmc_sd_init_card()
1036 if (host->ops->init_card) in mmc_sd_init_card()
1037 host->ops->init_card(host, card); in mmc_sd_init_card()
1042 if (!mmc_host_is_spi(host)) { in mmc_sd_init_card()
1043 err = mmc_send_relative_addr(host, &card->rca); in mmc_sd_init_card()
1049 err = mmc_sd_get_csd(host, card); in mmc_sd_init_card()
1057 * handling only for cards supporting DSR and hosts requesting in mmc_sd_init_card()
1060 if (card->csd.dsr_imp && host->dsr_req) in mmc_sd_init_card()
1061 mmc_set_dsr(host); in mmc_sd_init_card()
1066 if (!mmc_host_is_spi(host)) { in mmc_sd_init_card()
1072 err = mmc_sd_setup_card(host, card, oldcard != NULL); in mmc_sd_init_card()
1078 * signaling. Detect that situation and try to initialize a UHS-I (1.8V) in mmc_sd_init_card()
1081 if (!v18_fixup_failed && !mmc_host_is_spi(host) && mmc_host_uhs(host) && in mmc_sd_init_card()
1083 host->ios.signal_voltage != MMC_SIGNAL_VOLTAGE_180) { in mmc_sd_init_card()
1085 * Re-read switch information in case it has changed since in mmc_sd_init_card()
1094 if (mmc_host_set_uhs_voltage(host) || in mmc_sd_init_card()
1097 mmc_power_cycle(host, ocr); in mmc_sd_init_card()
1106 /* Initialization sequence for UHS-I cards */ in mmc_sd_init_card()
1107 if (rocr & SD_ROCR_S18A && mmc_host_uhs(host)) { in mmc_sd_init_card()
1113 * Attempt to change to high-speed (if supported) in mmc_sd_init_card()
1117 mmc_set_timing(card->host, MMC_TIMING_SD_HS); in mmc_sd_init_card()
1124 mmc_set_clock(host, mmc_sd_get_max_clock(card)); in mmc_sd_init_card()
1129 if ((host->caps & MMC_CAP_4_BIT_DATA) && in mmc_sd_init_card()
1130 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { in mmc_sd_init_card()
1135 mmc_set_bus_width(host, MMC_BUS_WIDTH_4); in mmc_sd_init_card()
1139 if (host->cqe_ops && !host->cqe_enabled) { in mmc_sd_init_card()
1140 err = host->cqe_ops->cqe_enable(host, card); in mmc_sd_init_card()
1142 host->cqe_enabled = true; in mmc_sd_init_card()
1143 host->hsq_enabled = true; in mmc_sd_init_card()
1144 pr_info("%s: Host Software Queue enabled\n", in mmc_sd_init_card()
1145 mmc_hostname(host)); in mmc_sd_init_card()
1149 if (host->caps2 & MMC_CAP2_AVOID_3_3V && in mmc_sd_init_card()
1150 host->ios.signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in mmc_sd_init_card()
1151 pr_err("%s: Host failed to negotiate down from 3.3V\n", in mmc_sd_init_card()
1152 mmc_hostname(host)); in mmc_sd_init_card()
1153 err = -EINVAL; in mmc_sd_init_card()
1157 host->card = card; in mmc_sd_init_card()
1168 * Host is being removed. Free up the current card.
1170 static void mmc_sd_remove(struct mmc_host *host) in mmc_sd_remove() argument
1172 mmc_remove_card(host->card); in mmc_sd_remove()
1173 host->card = NULL; in mmc_sd_remove()
1177 * Card detection - card is alive.
1179 static int mmc_sd_alive(struct mmc_host *host) in mmc_sd_alive() argument
1181 return mmc_send_status(host->card, NULL); in mmc_sd_alive()
1185 * Card detection callback from host.
1187 static void mmc_sd_detect(struct mmc_host *host) in mmc_sd_detect() argument
1191 mmc_get_card(host->card, NULL); in mmc_sd_detect()
1196 err = _mmc_detect_card_removed(host); in mmc_sd_detect()
1198 mmc_put_card(host->card, NULL); in mmc_sd_detect()
1201 mmc_sd_remove(host); in mmc_sd_detect()
1203 mmc_claim_host(host); in mmc_sd_detect()
1204 mmc_detach_bus(host); in mmc_sd_detect()
1205 mmc_power_off(host); in mmc_sd_detect()
1206 mmc_release_host(host); in mmc_sd_detect()
1210 static int _mmc_sd_suspend(struct mmc_host *host) in _mmc_sd_suspend() argument
1214 mmc_claim_host(host); in _mmc_sd_suspend()
1216 if (mmc_card_suspended(host->card)) in _mmc_sd_suspend()
1219 if (!mmc_host_is_spi(host)) in _mmc_sd_suspend()
1220 err = mmc_deselect_cards(host); in _mmc_sd_suspend()
1223 mmc_power_off(host); in _mmc_sd_suspend()
1224 mmc_card_set_suspended(host->card); in _mmc_sd_suspend()
1228 mmc_release_host(host); in _mmc_sd_suspend()
1235 static int mmc_sd_suspend(struct mmc_host *host) in mmc_sd_suspend() argument
1239 err = _mmc_sd_suspend(host); in mmc_sd_suspend()
1241 pm_runtime_disable(&host->card->dev); in mmc_sd_suspend()
1242 pm_runtime_set_suspended(&host->card->dev); in mmc_sd_suspend()
1252 static int _mmc_sd_resume(struct mmc_host *host) in _mmc_sd_resume() argument
1256 mmc_claim_host(host); in _mmc_sd_resume()
1258 if (!mmc_card_suspended(host->card)) in _mmc_sd_resume()
1261 mmc_power_up(host, host->card->ocr); in _mmc_sd_resume()
1262 err = mmc_sd_init_card(host, host->card->ocr, host->card); in _mmc_sd_resume()
1263 mmc_card_clr_suspended(host->card); in _mmc_sd_resume()
1266 mmc_release_host(host); in _mmc_sd_resume()
1273 static int mmc_sd_resume(struct mmc_host *host) in mmc_sd_resume() argument
1275 pm_runtime_enable(&host->card->dev); in mmc_sd_resume()
1282 static int mmc_sd_runtime_suspend(struct mmc_host *host) in mmc_sd_runtime_suspend() argument
1286 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) in mmc_sd_runtime_suspend()
1289 err = _mmc_sd_suspend(host); in mmc_sd_runtime_suspend()
1292 mmc_hostname(host), err); in mmc_sd_runtime_suspend()
1300 static int mmc_sd_runtime_resume(struct mmc_host *host) in mmc_sd_runtime_resume() argument
1304 err = _mmc_sd_resume(host); in mmc_sd_runtime_resume()
1305 if (err && err != -ENOMEDIUM) in mmc_sd_runtime_resume()
1307 mmc_hostname(host), err); in mmc_sd_runtime_resume()
1312 static int mmc_sd_hw_reset(struct mmc_host *host) in mmc_sd_hw_reset() argument
1314 mmc_power_cycle(host, host->card->ocr); in mmc_sd_hw_reset()
1315 return mmc_sd_init_card(host, host->card->ocr, host->card); in mmc_sd_hw_reset()
1333 int mmc_attach_sd(struct mmc_host *host) in mmc_attach_sd() argument
1338 WARN_ON(!host->claimed); in mmc_attach_sd()
1340 err = mmc_send_app_op_cond(host, 0, &ocr); in mmc_attach_sd()
1344 mmc_attach_bus(host, &mmc_sd_ops); in mmc_attach_sd()
1345 if (host->ocr_avail_sd) in mmc_attach_sd()
1346 host->ocr_avail = host->ocr_avail_sd; in mmc_attach_sd()
1351 if (mmc_host_is_spi(host)) { in mmc_attach_sd()
1352 mmc_go_idle(host); in mmc_attach_sd()
1354 err = mmc_spi_read_ocr(host, 0, &ocr); in mmc_attach_sd()
1361 * these bits as being in-valid and especially also bit7. in mmc_attach_sd()
1365 rocr = mmc_select_voltage(host, ocr); in mmc_attach_sd()
1371 err = -EINVAL; in mmc_attach_sd()
1378 err = mmc_sd_init_card(host, rocr, NULL); in mmc_attach_sd()
1382 mmc_release_host(host); in mmc_attach_sd()
1383 err = mmc_add_card(host->card); in mmc_attach_sd()
1387 mmc_claim_host(host); in mmc_attach_sd()
1391 mmc_remove_card(host->card); in mmc_attach_sd()
1392 host->card = NULL; in mmc_attach_sd()
1393 mmc_claim_host(host); in mmc_attach_sd()
1395 mmc_detach_bus(host); in mmc_attach_sd()
1398 mmc_hostname(host), err); in mmc_attach_sd()