Lines Matching +full:mmc +full:- +full:card
1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/mmc/core/core.c
5 * Copyright (C) 2003-2004 Russell King, All Rights Reserved.
7 * Copyright (C) 2005-2008 Pierre Ossman, All Rights Reserved.
24 #include <linux/fault-inject.h>
29 #include <linux/mmc/card.h>
30 #include <linux/mmc/host.h>
31 #include <linux/mmc/mmc.h>
32 #include <linux/mmc/sd.h>
33 #include <linux/mmc/slot-gpio.h>
36 #include <trace/events/mmc.h>
39 #include "card.h"
50 /* The max erase timeout, used when host->max_busy_timeout isn't specified */
85 struct mmc_command *cmd = mrq->cmd; in mmc_should_fail_request()
86 struct mmc_data *data = mrq->data; in mmc_should_fail_request()
88 -ETIMEDOUT, in mmc_should_fail_request()
89 -EILSEQ, in mmc_should_fail_request()
90 -EIO, in mmc_should_fail_request()
96 if ((cmd && cmd->error) || data->error || in mmc_should_fail_request()
97 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) in mmc_should_fail_request()
100 data->error = data_errors[get_random_u32_below(ARRAY_SIZE(data_errors))]; in mmc_should_fail_request()
101 data->bytes_xfered = get_random_u32_below(data->bytes_xfered >> 9) << 9; in mmc_should_fail_request()
115 if (mrq->cap_cmd_during_tfr && !completion_done(&mrq->cmd_completion)) in mmc_complete_cmd()
116 complete_all(&mrq->cmd_completion); in mmc_complete_cmd()
121 if (!mrq->cap_cmd_during_tfr) in mmc_command_done()
127 mmc_hostname(host), mrq->cmd->opcode); in mmc_command_done()
132 * mmc_request_done - finish processing an MMC request
133 * @host: MMC host which completed request
134 * @mrq: MMC request which request
136 * MMC drivers should call this function when they have completed
141 struct mmc_command *cmd = mrq->cmd; in mmc_request_done()
142 int err = cmd->error; in mmc_request_done()
144 /* Flag re-tuning needed on CRC errors */ in mmc_request_done()
145 if (!mmc_op_tuning(cmd->opcode) && in mmc_request_done()
146 !host->retune_crc_disable && in mmc_request_done()
147 (err == -EILSEQ || (mrq->sbc && mrq->sbc->error == -EILSEQ) || in mmc_request_done()
148 (mrq->data && mrq->data->error == -EILSEQ) || in mmc_request_done()
149 (mrq->stop && mrq->stop->error == -EILSEQ))) in mmc_request_done()
152 if (err && cmd->retries && mmc_host_is_spi(host)) { in mmc_request_done()
153 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) in mmc_request_done()
154 cmd->retries = 0; in mmc_request_done()
157 if (host->ongoing_mrq == mrq) in mmc_request_done()
158 host->ongoing_mrq = NULL; in mmc_request_done()
168 * - There was no error, OK fine then in mmc_request_done()
169 * - We are not doing some kind of retry in mmc_request_done()
170 * - The card was removed (...so just complete everything no matter in mmc_request_done()
173 if (!err || !cmd->retries || mmc_card_removed(host->card)) { in mmc_request_done()
176 if (!host->ongoing_mrq) in mmc_request_done()
177 led_trigger_event(host->led, LED_OFF); in mmc_request_done()
179 if (mrq->sbc) { in mmc_request_done()
181 mmc_hostname(host), mrq->sbc->opcode, in mmc_request_done()
182 mrq->sbc->error, in mmc_request_done()
183 mrq->sbc->resp[0], mrq->sbc->resp[1], in mmc_request_done()
184 mrq->sbc->resp[2], mrq->sbc->resp[3]); in mmc_request_done()
188 mmc_hostname(host), cmd->opcode, err, in mmc_request_done()
189 cmd->resp[0], cmd->resp[1], in mmc_request_done()
190 cmd->resp[2], cmd->resp[3]); in mmc_request_done()
192 if (mrq->data) { in mmc_request_done()
195 mrq->data->bytes_xfered, mrq->data->error); in mmc_request_done()
198 if (mrq->stop) { in mmc_request_done()
200 mmc_hostname(host), mrq->stop->opcode, in mmc_request_done()
201 mrq->stop->error, in mmc_request_done()
202 mrq->stop->resp[0], mrq->stop->resp[1], in mmc_request_done()
203 mrq->stop->resp[2], mrq->stop->resp[3]); in mmc_request_done()
207 * Request starter must handle retries - see in mmc_request_done()
210 if (mrq->done) in mmc_request_done()
211 mrq->done(mrq); in mmc_request_done()
223 mrq->cmd->error = err; in __mmc_start_request()
229 * For sdio rw commands we must wait for card busy otherwise some in __mmc_start_request()
233 if (sdio_is_io_busy(mrq->cmd->opcode, mrq->cmd->arg) && in __mmc_start_request()
234 host->ops->card_busy) { in __mmc_start_request()
237 while (host->ops->card_busy(host) && --tries) in __mmc_start_request()
241 mrq->cmd->error = -EBUSY; in __mmc_start_request()
247 if (mrq->cap_cmd_during_tfr) { in __mmc_start_request()
248 host->ongoing_mrq = mrq; in __mmc_start_request()
253 reinit_completion(&mrq->cmd_completion); in __mmc_start_request()
258 if (host->cqe_on) in __mmc_start_request()
259 host->cqe_ops->cqe_off(host); in __mmc_start_request()
261 host->ops->request(host, mrq); in __mmc_start_request()
267 if (mrq->sbc) { in mmc_mrq_pr_debug()
269 mmc_hostname(host), mrq->sbc->opcode, in mmc_mrq_pr_debug()
270 mrq->sbc->arg, mrq->sbc->flags); in mmc_mrq_pr_debug()
273 if (mrq->cmd) { in mmc_mrq_pr_debug()
276 mrq->cmd->opcode, mrq->cmd->arg, mrq->cmd->flags); in mmc_mrq_pr_debug()
279 mmc_hostname(host), mrq->tag, mrq->data->blk_addr); in mmc_mrq_pr_debug()
282 if (mrq->data) { in mmc_mrq_pr_debug()
285 mmc_hostname(host), mrq->data->blksz, in mmc_mrq_pr_debug()
286 mrq->data->blocks, mrq->data->flags, in mmc_mrq_pr_debug()
287 mrq->data->timeout_ns / 1000000, in mmc_mrq_pr_debug()
288 mrq->data->timeout_clks); in mmc_mrq_pr_debug()
291 if (mrq->stop) { in mmc_mrq_pr_debug()
293 mmc_hostname(host), mrq->stop->opcode, in mmc_mrq_pr_debug()
294 mrq->stop->arg, mrq->stop->flags); in mmc_mrq_pr_debug()
303 if (mrq->cmd) { in mmc_mrq_prep()
304 mrq->cmd->error = 0; in mmc_mrq_prep()
305 mrq->cmd->mrq = mrq; in mmc_mrq_prep()
306 mrq->cmd->data = mrq->data; in mmc_mrq_prep()
308 if (mrq->sbc) { in mmc_mrq_prep()
309 mrq->sbc->error = 0; in mmc_mrq_prep()
310 mrq->sbc->mrq = mrq; in mmc_mrq_prep()
312 if (mrq->data) { in mmc_mrq_prep()
313 if (mrq->data->blksz > host->max_blk_size || in mmc_mrq_prep()
314 mrq->data->blocks > host->max_blk_count || in mmc_mrq_prep()
315 mrq->data->blocks * mrq->data->blksz > host->max_req_size) in mmc_mrq_prep()
316 return -EINVAL; in mmc_mrq_prep()
318 for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i) in mmc_mrq_prep()
319 sz += sg->length; in mmc_mrq_prep()
320 if (sz != mrq->data->blocks * mrq->data->blksz) in mmc_mrq_prep()
321 return -EINVAL; in mmc_mrq_prep()
323 mrq->data->error = 0; in mmc_mrq_prep()
324 mrq->data->mrq = mrq; in mmc_mrq_prep()
325 if (mrq->stop) { in mmc_mrq_prep()
326 mrq->data->stop = mrq->stop; in mmc_mrq_prep()
327 mrq->stop->error = 0; in mmc_mrq_prep()
328 mrq->stop->mrq = mrq; in mmc_mrq_prep()
339 init_completion(&mrq->cmd_completion); in mmc_start_request()
343 if (mmc_card_removed(host->card)) in mmc_start_request()
344 return -ENOMEDIUM; in mmc_start_request()
348 WARN_ON(!host->claimed); in mmc_start_request()
354 led_trigger_event(host->led, LED_FULL); in mmc_start_request()
363 complete(&mrq->completion); in mmc_wait_done()
368 struct mmc_request *ongoing_mrq = READ_ONCE(host->ongoing_mrq); in mmc_wait_ongoing_tfr_cmd()
374 if (ongoing_mrq && !completion_done(&ongoing_mrq->cmd_completion)) in mmc_wait_ongoing_tfr_cmd()
375 wait_for_completion(&ongoing_mrq->cmd_completion); in mmc_wait_ongoing_tfr_cmd()
384 init_completion(&mrq->completion); in __mmc_start_req()
385 mrq->done = mmc_wait_done; in __mmc_start_req()
389 mrq->cmd->error = err; in __mmc_start_req()
391 complete(&mrq->completion); in __mmc_start_req()
402 wait_for_completion(&mrq->completion); in mmc_wait_for_req_done()
404 cmd = mrq->cmd; in mmc_wait_for_req_done()
406 if (!cmd->error || !cmd->retries || in mmc_wait_for_req_done()
407 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
413 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
414 cmd->retries--; in mmc_wait_for_req_done()
415 cmd->error = 0; in mmc_wait_for_req_done()
424 * mmc_cqe_start_req - Start a CQE request.
425 * @host: MMC host to start the request
428 * Start the request, re-tuning if needed and it is possible. Returns an error
429 * code if the request fails to start or -EBUSY if CQE is busy.
436 * CQE cannot process re-tuning commands. Caller must hold retuning in mmc_cqe_start_req()
437 * while CQE is in use. Re-tuning can happen here only when CQE has no in mmc_cqe_start_req()
438 * active requests i.e. this is the first. Note, re-tuning will call in mmc_cqe_start_req()
439 * ->cqe_off(). in mmc_cqe_start_req()
445 mrq->host = host; in mmc_cqe_start_req()
453 err = host->cqe_ops->cqe_request(host, mrq); in mmc_cqe_start_req()
462 if (mrq->cmd) { in mmc_cqe_start_req()
464 mmc_hostname(host), mrq->cmd->opcode, err); in mmc_cqe_start_req()
467 mmc_hostname(host), mrq->tag, err); in mmc_cqe_start_req()
474 * mmc_cqe_request_done - CQE has finished processing an MMC request
475 * @host: MMC host which completed request
476 * @mrq: MMC request which completed
485 /* Flag re-tuning needed on CRC errors */ in mmc_cqe_request_done()
486 if ((mrq->cmd && mrq->cmd->error == -EILSEQ) || in mmc_cqe_request_done()
487 (mrq->data && mrq->data->error == -EILSEQ)) in mmc_cqe_request_done()
492 if (mrq->cmd) { in mmc_cqe_request_done()
494 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->error); in mmc_cqe_request_done()
497 mmc_hostname(host), mrq->tag); in mmc_cqe_request_done()
500 if (mrq->data) { in mmc_cqe_request_done()
503 mrq->data->bytes_xfered, mrq->data->error); in mmc_cqe_request_done()
506 mrq->done(mrq); in mmc_cqe_request_done()
511 * mmc_cqe_post_req - CQE post process of a completed MMC request
512 * @host: MMC host
513 * @mrq: MMC request to be processed
517 if (host->cqe_ops->cqe_post_req) in mmc_cqe_post_req()
518 host->cqe_ops->cqe_post_req(host, mrq); in mmc_cqe_post_req()
526 * mmc_cqe_recovery - Recover from CQE errors.
527 * @host: MMC host to recover
547 host->cqe_ops->cqe_recovery_start(host); in mmc_cqe_recovery()
556 mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); in mmc_cqe_recovery()
566 host->cqe_ops->cqe_recovery_finish(host); in mmc_cqe_recovery()
578 * mmc_is_req_done - Determine if a 'cap_cmd_during_tfr' request is done
579 * @host: MMC host
580 * @mrq: MMC request
583 * mrq->cap_cmd_during_tfr = true. mmc_is_req_done() must be called after
591 return completion_done(&mrq->completion); in mmc_is_req_done()
596 * mmc_wait_for_req - start a request and wait for completion
597 * @host: MMC host to start command
598 * @mrq: MMC request to start
600 * Start a new MMC custom command request for a host, and wait
611 if (!mrq->cap_cmd_during_tfr) in mmc_wait_for_req()
617 * mmc_wait_for_cmd - start a command and wait for completion
618 * @host: MMC host to start command
619 * @cmd: MMC command to start
622 * Start a new MMC command for a host, and wait for the command
630 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
632 memset(cmd->resp, 0, sizeof(cmd->resp)); in mmc_wait_for_cmd()
633 cmd->retries = retries; in mmc_wait_for_cmd()
636 cmd->data = NULL; in mmc_wait_for_cmd()
640 return cmd->error; in mmc_wait_for_cmd()
646 * mmc_set_data_timeout - set the timeout for a data command
648 * @card: the MMC card associated with the data transfer
651 * correct algorithm given the card type.
653 void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) in mmc_set_data_timeout() argument
660 if (mmc_card_sdio(card)) { in mmc_set_data_timeout()
661 data->timeout_ns = 1000000000; in mmc_set_data_timeout()
662 data->timeout_clks = 0; in mmc_set_data_timeout()
669 mult = mmc_card_sd(card) ? 100 : 10; in mmc_set_data_timeout()
675 if (data->flags & MMC_DATA_WRITE) in mmc_set_data_timeout()
676 mult <<= card->csd.r2w_factor; in mmc_set_data_timeout()
678 data->timeout_ns = card->csd.taac_ns * mult; in mmc_set_data_timeout()
679 data->timeout_clks = card->csd.taac_clks * mult; in mmc_set_data_timeout()
684 if (mmc_card_sd(card)) { in mmc_set_data_timeout()
687 timeout_us = data->timeout_ns / 1000; in mmc_set_data_timeout()
688 if (card->host->ios.clock) in mmc_set_data_timeout()
689 timeout_us += data->timeout_clks * 1000 / in mmc_set_data_timeout()
690 (card->host->ios.clock / 1000); in mmc_set_data_timeout()
692 if (data->flags & MMC_DATA_WRITE) in mmc_set_data_timeout()
694 * The MMC spec "It is strongly recommended in mmc_set_data_timeout()
696 * timeout value even if the card indicates in mmc_set_data_timeout()
709 data->timeout_ns = limit_us * 1000; in mmc_set_data_timeout()
710 data->timeout_clks = 0; in mmc_set_data_timeout()
715 data->timeout_ns = limit_us * 1000; in mmc_set_data_timeout()
724 if (mmc_card_long_read_time(card) && data->flags & MMC_DATA_READ) { in mmc_set_data_timeout()
725 data->timeout_ns = 600000000; in mmc_set_data_timeout()
726 data->timeout_clks = 0; in mmc_set_data_timeout()
735 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
736 if (data->flags & MMC_DATA_WRITE) { in mmc_set_data_timeout()
737 if (data->timeout_ns < 1000000000) in mmc_set_data_timeout()
738 data->timeout_ns = 1000000000; /* 1s */ in mmc_set_data_timeout()
740 if (data->timeout_ns < 100000000) in mmc_set_data_timeout()
741 data->timeout_ns = 100000000; /* 100ms */ in mmc_set_data_timeout()
754 return host->claimer == ctx || in mmc_ctx_matches()
755 (!ctx && task && host->claimer->task == task); in mmc_ctx_matches()
762 if (!host->claimer) { in mmc_ctx_set_claimer()
764 host->claimer = ctx; in mmc_ctx_set_claimer()
766 host->claimer = &host->default_ctx; in mmc_ctx_set_claimer()
769 host->claimer->task = task; in mmc_ctx_set_claimer()
773 * __mmc_claim_host - exclusively claim a host
774 * @host: mmc host to claim
780 * dereference a non-zero value then this will return prematurely with
781 * that non-zero value without acquiring the lock. Returns zero
795 add_wait_queue(&host->wq, &wait); in __mmc_claim_host()
796 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
800 if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task)) in __mmc_claim_host()
802 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
804 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
808 host->claimed = 1; in __mmc_claim_host()
810 host->claim_cnt += 1; in __mmc_claim_host()
811 if (host->claim_cnt == 1) in __mmc_claim_host()
814 wake_up(&host->wq); in __mmc_claim_host()
815 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
816 remove_wait_queue(&host->wq, &wait); in __mmc_claim_host()
826 * mmc_release_host - release a host
827 * @host: mmc host to release
829 * Release a MMC host, allowing others to claim the host
836 WARN_ON(!host->claimed); in mmc_release_host()
838 spin_lock_irqsave(&host->lock, flags); in mmc_release_host()
839 if (--host->claim_cnt) { in mmc_release_host()
841 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
843 host->claimed = 0; in mmc_release_host()
844 host->claimer->task = NULL; in mmc_release_host()
845 host->claimer = NULL; in mmc_release_host()
846 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
847 wake_up(&host->wq); in mmc_release_host()
849 if (host->caps & MMC_CAP_SYNC_RUNTIME_PM) in mmc_release_host()
859 * card device and also claims the host.
861 void mmc_get_card(struct mmc_card *card, struct mmc_ctx *ctx) in mmc_get_card() argument
863 pm_runtime_get_sync(&card->dev); in mmc_get_card()
864 __mmc_claim_host(card->host, ctx, NULL); in mmc_get_card()
870 * pm reference for the card device.
872 void mmc_put_card(struct mmc_card *card, struct mmc_ctx *ctx) in mmc_put_card() argument
874 struct mmc_host *host = card->host; in mmc_put_card()
876 WARN_ON(ctx && host->claimer != ctx); in mmc_put_card()
879 pm_runtime_mark_last_busy(&card->dev); in mmc_put_card()
880 pm_runtime_put_autosuspend(&card->dev); in mmc_put_card()
890 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
894 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
895 ios->power_mode, ios->chip_select, ios->vdd, in mmc_set_ios()
896 1 << ios->bus_width, ios->timing); in mmc_set_ios()
898 host->ops->set_ios(host, ios); in mmc_set_ios()
906 host->ios.chip_select = mode; in mmc_set_chip_select()
916 WARN_ON(hz && hz < host->f_min); in mmc_set_clock()
918 if (hz > host->f_max) in mmc_set_clock()
919 hz = host->f_max; in mmc_set_clock()
921 host->ios.clock = hz; in mmc_set_clock()
925 int mmc_execute_tuning(struct mmc_card *card) in mmc_execute_tuning() argument
927 struct mmc_host *host = card->host; in mmc_execute_tuning()
931 if (!host->ops->execute_tuning) in mmc_execute_tuning()
934 if (host->cqe_on) in mmc_execute_tuning()
935 host->cqe_ops->cqe_off(host); in mmc_execute_tuning()
937 if (mmc_card_mmc(card)) in mmc_execute_tuning()
942 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
949 /* Only print error when we don't check for card removal */ in mmc_execute_tuning()
950 if (!host->detect_change) { in mmc_execute_tuning()
960 * Change the bus mode (open drain/push-pull) of a host.
964 host->ios.bus_mode = mode; in mmc_set_bus_mode()
973 host->ios.bus_width = width; in mmc_set_bus_width()
982 if (host->cqe_on) in mmc_set_initial_state()
983 host->cqe_ops->cqe_off(host); in mmc_set_initial_state()
988 host->ios.chip_select = MMC_CS_HIGH; in mmc_set_initial_state()
990 host->ios.chip_select = MMC_CS_DONTCARE; in mmc_set_initial_state()
991 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; in mmc_set_initial_state()
992 host->ios.bus_width = MMC_BUS_WIDTH_1; in mmc_set_initial_state()
993 host->ios.timing = MMC_TIMING_LEGACY; in mmc_set_initial_state()
994 host->ios.drv_type = 0; in mmc_set_initial_state()
995 host->ios.enhanced_strobe = false; in mmc_set_initial_state()
998 * Make sure we are in non-enhanced strobe mode before we in mmc_set_initial_state()
1001 if ((host->caps2 & MMC_CAP2_HS400_ES) && in mmc_set_initial_state()
1002 host->ops->hs400_enhanced_strobe) in mmc_set_initial_state()
1003 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_set_initial_state()
1011 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
1031 return -EINVAL; in mmc_vdd_to_ocrbitnum()
1037 vdd -= 1; in mmc_vdd_to_ocrbitnum()
1040 bit = (vdd - 2000) / 100 + 8; in mmc_vdd_to_ocrbitnum()
1047 * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
1078 mask |= 1 << vdd_max--; in mmc_vddrange_to_ocrmask()
1100 if (!host->parent || !host->parent->of_node) in mmc_of_find_child_device()
1103 for_each_child_of_node(host->parent->of_node, node) { in mmc_of_find_child_device()
1120 * Sanity check the voltages that the card claims to in mmc_select_voltage()
1125 "card claims to support voltages below defined range\n"); in mmc_select_voltage()
1129 ocr &= host->ocr_avail; in mmc_select_voltage()
1131 dev_warn(mmc_dev(host), "no support for card's volts\n"); in mmc_select_voltage()
1135 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { in mmc_select_voltage()
1136 bit = ffs(ocr) - 1; in mmc_select_voltage()
1140 bit = fls(ocr) - 1; in mmc_select_voltage()
1145 * we must shift the mask '3' with (bit - 1). in mmc_select_voltage()
1147 ocr &= 3 << (bit - 1); in mmc_select_voltage()
1148 if (bit != host->ios.vdd) in mmc_select_voltage()
1149 dev_warn(mmc_dev(host), "exceeding card's volts\n"); in mmc_select_voltage()
1158 int old_signal_voltage = host->ios.signal_voltage; in mmc_set_signal_voltage()
1160 host->ios.signal_voltage = signal_voltage; in mmc_set_signal_voltage()
1161 if (host->ops->start_signal_voltage_switch) in mmc_set_signal_voltage()
1162 err = host->ops->start_signal_voltage_switch(host, &host->ios); in mmc_set_signal_voltage()
1165 host->ios.signal_voltage = old_signal_voltage; in mmc_set_signal_voltage()
1190 clock = host->ios.clock; in mmc_host_set_uhs_voltage()
1191 host->ios.clock = 0; in mmc_host_set_uhs_voltage()
1195 return -EAGAIN; in mmc_host_set_uhs_voltage()
1199 host->ios.clock = clock; in mmc_host_set_uhs_voltage()
1214 if (!host->ops->start_signal_voltage_switch) in mmc_set_uhs_voltage()
1215 return -EPERM; in mmc_set_uhs_voltage()
1216 if (!host->ops->card_busy) in mmc_set_uhs_voltage()
1229 return -EIO; in mmc_set_uhs_voltage()
1232 * The card should drive cmd and dat[0:3] low immediately in mmc_set_uhs_voltage()
1236 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_uhs_voltage()
1237 err = -EAGAIN; in mmc_set_uhs_voltage()
1246 err = -EAGAIN; in mmc_set_uhs_voltage()
1254 * Failure to switch is indicated by the card holding in mmc_set_uhs_voltage()
1257 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_uhs_voltage()
1258 err = -EAGAIN; in mmc_set_uhs_voltage()
1263 "power cycling card\n", mmc_hostname(host)); in mmc_set_uhs_voltage()
1275 host->ios.timing = timing; in mmc_set_timing()
1284 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1288 int mmc_select_drive_strength(struct mmc_card *card, unsigned int max_dtr, in mmc_select_drive_strength() argument
1291 struct mmc_host *host = card->host; in mmc_select_drive_strength()
1296 if (!host->ops->select_drive_strength) in mmc_select_drive_strength()
1300 if (host->caps & MMC_CAP_DRIVER_TYPE_A) in mmc_select_drive_strength()
1303 if (host->caps & MMC_CAP_DRIVER_TYPE_C) in mmc_select_drive_strength()
1306 if (host->caps & MMC_CAP_DRIVER_TYPE_D) in mmc_select_drive_strength()
1315 return host->ops->select_drive_strength(card, max_dtr, in mmc_select_drive_strength()
1322 * Apply power to the MMC stack. This is a two-stage process.
1323 * First, we enable power to the card without the clock running.
1325 * enable the bus drivers and clock to the card.
1334 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1339 host->ios.vdd = fls(ocr) - 1; in mmc_power_up()
1340 host->ios.power_mode = MMC_POWER_UP; in mmc_power_up()
1350 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1354 host->ios.clock = host->f_init; in mmc_power_up()
1356 host->ios.power_mode = MMC_POWER_ON; in mmc_power_up()
1363 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1368 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1373 host->ios.clock = 0; in mmc_power_off()
1374 host->ios.vdd = 0; in mmc_power_off()
1376 host->ios.power_mode = MMC_POWER_OFF; in mmc_power_off()
1381 * Some configurations, such as the 802.11 SDIO card in the OLPC in mmc_power_off()
1382 * XO-1.5, require a short delay after poweroff before the card in mmc_power_off()
1397 * Assign a mmc bus handler to a host. Only one bus handler may control a
1402 host->bus_ops = ops; in mmc_attach_bus()
1410 host->bus_ops = NULL; in mmc_detach_bus()
1420 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL)) in _mmc_detect_change()
1421 __pm_wakeup_event(host->ws, 5000); in _mmc_detect_change()
1423 host->detect_change = 1; in _mmc_detect_change()
1424 mmc_schedule_delayed_work(&host->detect, delay); in _mmc_detect_change()
1428 * mmc_detect_change - process change of state on a MMC socket
1432 * MMC drivers should call this when they detect a card has been
1433 * inserted or removed. The MMC layer will confirm that any
1434 * present card is still functional, and initialize any newly
1443 void mmc_init_erase(struct mmc_card *card) in mmc_init_erase() argument
1447 if (is_power_of_2(card->erase_size)) in mmc_init_erase()
1448 card->erase_shift = ffs(card->erase_size) - 1; in mmc_init_erase()
1450 card->erase_shift = 0; in mmc_init_erase()
1453 * It is possible to erase an arbitrarily large area of an SD or MMC in mmc_init_erase()
1454 * card. That is not desirable because it can take a long time in mmc_init_erase()
1456 * timeout calculations become increasingly hugely over-estimated. in mmc_init_erase()
1462 * For MMC, have a stab at ai good value and for modern cards it will in mmc_init_erase()
1467 if (mmc_card_sd(card) && card->ssr.au) { in mmc_init_erase()
1468 card->pref_erase = card->ssr.au; in mmc_init_erase()
1469 card->erase_shift = ffs(card->ssr.au) - 1; in mmc_init_erase()
1470 } else if (card->erase_size) { in mmc_init_erase()
1471 sz = (card->csd.capacity << (card->csd.read_blkbits - 9)) >> 11; in mmc_init_erase()
1473 card->pref_erase = 512 * 1024 / 512; in mmc_init_erase()
1475 card->pref_erase = 1024 * 1024 / 512; in mmc_init_erase()
1477 card->pref_erase = 2 * 1024 * 1024 / 512; in mmc_init_erase()
1479 card->pref_erase = 4 * 1024 * 1024 / 512; in mmc_init_erase()
1480 if (card->pref_erase < card->erase_size) in mmc_init_erase()
1481 card->pref_erase = card->erase_size; in mmc_init_erase()
1483 sz = card->pref_erase % card->erase_size; in mmc_init_erase()
1485 card->pref_erase += card->erase_size - sz; in mmc_init_erase()
1488 card->pref_erase = 0; in mmc_init_erase()
1496 static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card, in mmc_mmc_erase_timeout() argument
1502 (arg == MMC_TRIM_ARG && card->ext_csd.rev >= 6)) { in mmc_mmc_erase_timeout()
1503 erase_timeout = card->ext_csd.trim_timeout; in mmc_mmc_erase_timeout()
1504 } else if (card->ext_csd.erase_group_def & 1) { in mmc_mmc_erase_timeout()
1507 erase_timeout = card->ext_csd.trim_timeout; in mmc_mmc_erase_timeout()
1509 erase_timeout = card->ext_csd.hc_erase_timeout; in mmc_mmc_erase_timeout()
1512 unsigned int mult = (10 << card->csd.r2w_factor); in mmc_mmc_erase_timeout()
1513 unsigned int timeout_clks = card->csd.taac_clks * mult; in mmc_mmc_erase_timeout()
1517 if (card->csd.taac_ns < 1000000) in mmc_mmc_erase_timeout()
1518 timeout_us = (card->csd.taac_ns * mult) / 1000; in mmc_mmc_erase_timeout()
1520 timeout_us = (card->csd.taac_ns / 1000) * mult; in mmc_mmc_erase_timeout()
1528 (card->host->ios.clock / 1000); in mmc_mmc_erase_timeout()
1543 erase_timeout *= card->ext_csd.sec_erase_mult; in mmc_mmc_erase_timeout()
1545 erase_timeout *= card->ext_csd.sec_trim_mult; in mmc_mmc_erase_timeout()
1554 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
1560 static unsigned int mmc_sd_erase_timeout(struct mmc_card *card, in mmc_sd_erase_timeout() argument
1572 if (card->ssr.erase_timeout) { in mmc_sd_erase_timeout()
1574 erase_timeout = card->ssr.erase_timeout * qty + in mmc_sd_erase_timeout()
1575 card->ssr.erase_offset; in mmc_sd_erase_timeout()
1591 static unsigned int mmc_erase_timeout(struct mmc_card *card, in mmc_erase_timeout() argument
1595 if (mmc_card_sd(card)) in mmc_erase_timeout()
1596 return mmc_sd_erase_timeout(card, arg, qty); in mmc_erase_timeout()
1598 return mmc_mmc_erase_timeout(card, arg, qty); in mmc_erase_timeout()
1601 static int mmc_do_erase(struct mmc_card *card, unsigned int from, in mmc_do_erase() argument
1609 mmc_retune_hold(card->host); in mmc_do_erase()
1615 * For SD, the allocation units are always a power of 2. For MMC, the in mmc_do_erase()
1627 if (card->erase_shift) in mmc_do_erase()
1628 qty += ((to >> card->erase_shift) - in mmc_do_erase()
1629 (from >> card->erase_shift)) + 1; in mmc_do_erase()
1630 else if (mmc_card_sd(card)) in mmc_do_erase()
1631 qty += to - from + 1; in mmc_do_erase()
1633 qty += ((to / card->erase_size) - in mmc_do_erase()
1634 (from / card->erase_size)) + 1; in mmc_do_erase()
1636 if (!mmc_card_blockaddr(card)) { in mmc_do_erase()
1641 if (mmc_card_sd(card)) in mmc_do_erase()
1647 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1651 err = -EIO; in mmc_do_erase()
1656 if (mmc_card_sd(card)) in mmc_do_erase()
1662 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1666 err = -EIO; in mmc_do_erase()
1673 busy_timeout = mmc_erase_timeout(card, arg, qty); in mmc_do_erase()
1674 use_r1b_resp = mmc_prepare_busy_cmd(card->host, &cmd, busy_timeout); in mmc_do_erase()
1676 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1680 err = -EIO; in mmc_do_erase()
1684 if (mmc_host_is_spi(card->host)) in mmc_do_erase()
1691 if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) in mmc_do_erase()
1695 err = mmc_poll_for_busy(card, busy_timeout, false, MMC_BUSY_ERASE); in mmc_do_erase()
1698 mmc_retune_release(card->host); in mmc_do_erase()
1702 static unsigned int mmc_align_erase_size(struct mmc_card *card, in mmc_align_erase_size() argument
1710 * When the 'card->erase_size' is power of 2, we can use round_up/down() in mmc_align_erase_size()
1713 if (is_power_of_2(card->erase_size)) { in mmc_align_erase_size()
1716 from_new = round_up(temp, card->erase_size); in mmc_align_erase_size()
1717 rem = from_new - temp; in mmc_align_erase_size()
1720 nr_new -= rem; in mmc_align_erase_size()
1724 nr_new = round_down(nr_new, card->erase_size); in mmc_align_erase_size()
1726 rem = from_new % card->erase_size; in mmc_align_erase_size()
1728 rem = card->erase_size - rem; in mmc_align_erase_size()
1731 nr_new -= rem; in mmc_align_erase_size()
1736 rem = nr_new % card->erase_size; in mmc_align_erase_size()
1738 nr_new -= rem; in mmc_align_erase_size()
1751 * mmc_erase - erase sectors.
1752 * @card: card to erase
1759 int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr, in mmc_erase() argument
1765 if (!(card->csd.cmdclass & CCC_ERASE)) in mmc_erase()
1766 return -EOPNOTSUPP; in mmc_erase()
1768 if (!card->erase_size) in mmc_erase()
1769 return -EOPNOTSUPP; in mmc_erase()
1771 if (mmc_card_sd(card) && arg != SD_ERASE_ARG && arg != SD_DISCARD_ARG) in mmc_erase()
1772 return -EOPNOTSUPP; in mmc_erase()
1774 if (mmc_card_mmc(card) && (arg & MMC_SECURE_ARGS) && in mmc_erase()
1775 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)) in mmc_erase()
1776 return -EOPNOTSUPP; in mmc_erase()
1778 if (mmc_card_mmc(card) && is_trim_arg(arg) && in mmc_erase()
1779 !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)) in mmc_erase()
1780 return -EOPNOTSUPP; in mmc_erase()
1783 if (from % card->erase_size || nr % card->erase_size) in mmc_erase()
1784 return -EINVAL; in mmc_erase()
1788 nr = mmc_align_erase_size(card, &from, &to, nr); in mmc_erase()
1794 return -EINVAL; in mmc_erase()
1797 to -= 1; in mmc_erase()
1800 * Special case where only one erase-group fits in the timeout budget: in mmc_erase()
1801 * If the region crosses an erase-group boundary on this particular in mmc_erase()
1802 * case, we will be trimming more than one erase-group which, does not in mmc_erase()
1805 * identified by the card->eg_boundary flag. in mmc_erase()
1807 rem = card->erase_size - (from % card->erase_size); in mmc_erase()
1808 if ((arg & MMC_TRIM_OR_DISCARD_ARGS) && card->eg_boundary && nr > rem) { in mmc_erase()
1809 err = mmc_do_erase(card, from, from + rem - 1, arg); in mmc_erase()
1815 return mmc_do_erase(card, from, to, arg); in mmc_erase()
1819 int mmc_can_erase(struct mmc_card *card) in mmc_can_erase() argument
1821 if (card->csd.cmdclass & CCC_ERASE && card->erase_size) in mmc_can_erase()
1827 int mmc_can_trim(struct mmc_card *card) in mmc_can_trim() argument
1829 if ((card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN) && in mmc_can_trim()
1830 (!(card->quirks & MMC_QUIRK_TRIM_BROKEN))) in mmc_can_trim()
1836 int mmc_can_discard(struct mmc_card *card) in mmc_can_discard() argument
1842 if (card->ext_csd.feature_support & MMC_DISCARD_FEATURE) in mmc_can_discard()
1848 int mmc_can_sanitize(struct mmc_card *card) in mmc_can_sanitize() argument
1850 if (!mmc_can_trim(card) && !mmc_can_erase(card)) in mmc_can_sanitize()
1852 if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE) in mmc_can_sanitize()
1857 int mmc_can_secure_erase_trim(struct mmc_card *card) in mmc_can_secure_erase_trim() argument
1859 if ((card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN) && in mmc_can_secure_erase_trim()
1860 !(card->quirks & MMC_QUIRK_SEC_ERASE_TRIM_BROKEN)) in mmc_can_secure_erase_trim()
1866 int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from, in mmc_erase_group_aligned() argument
1869 if (!card->erase_size) in mmc_erase_group_aligned()
1871 if (from % card->erase_size || nr % card->erase_size) in mmc_erase_group_aligned()
1877 static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, in mmc_do_calc_max_discard() argument
1880 struct mmc_host *host = card->host; in mmc_do_calc_max_discard()
1883 unsigned int max_busy_timeout = host->max_busy_timeout ? in mmc_do_calc_max_discard()
1884 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS; in mmc_do_calc_max_discard()
1886 if (card->erase_shift) { in mmc_do_calc_max_discard()
1887 max_qty = UINT_MAX >> card->erase_shift; in mmc_do_calc_max_discard()
1888 min_qty = card->pref_erase >> card->erase_shift; in mmc_do_calc_max_discard()
1889 } else if (mmc_card_sd(card)) { in mmc_do_calc_max_discard()
1891 min_qty = card->pref_erase; in mmc_do_calc_max_discard()
1893 max_qty = UINT_MAX / card->erase_size; in mmc_do_calc_max_discard()
1894 min_qty = card->pref_erase / card->erase_size; in mmc_do_calc_max_discard()
1898 * We should not only use 'host->max_busy_timeout' as the limitation in mmc_do_calc_max_discard()
1903 * Here we set 'card->pref_erase' as the minimal discard sectors no in mmc_do_calc_max_discard()
1904 * matter what size of 'host->max_busy_timeout', but if the in mmc_do_calc_max_discard()
1905 * 'host->max_busy_timeout' is large enough for more discard sectors, in mmc_do_calc_max_discard()
1907 * get a balance value. In cases when the 'host->max_busy_timeout' in mmc_do_calc_max_discard()
1912 for (x = 1; x && x <= max_qty && max_qty - x >= qty; x <<= 1) { in mmc_do_calc_max_discard()
1913 timeout = mmc_erase_timeout(card, arg, qty + x); in mmc_do_calc_max_discard()
1931 * an erase-group boundary even if the amount of sectors is less than in mmc_do_calc_max_discard()
1932 * one erase-group. in mmc_do_calc_max_discard()
1933 * If we can only fit one erase-group in the controller timeout budget, in mmc_do_calc_max_discard()
1934 * we have to care that erase-group boundaries are not crossed by a in mmc_do_calc_max_discard()
1937 * always touch (qty + 1) erase-groups as a simple optimization. in mmc_do_calc_max_discard()
1940 card->eg_boundary = 1; in mmc_do_calc_max_discard()
1942 qty--; in mmc_do_calc_max_discard()
1945 if (card->erase_shift) in mmc_do_calc_max_discard()
1946 max_discard = qty << card->erase_shift; in mmc_do_calc_max_discard()
1947 else if (mmc_card_sd(card)) in mmc_do_calc_max_discard()
1950 max_discard = qty * card->erase_size; in mmc_do_calc_max_discard()
1955 unsigned int mmc_calc_max_discard(struct mmc_card *card) in mmc_calc_max_discard() argument
1957 struct mmc_host *host = card->host; in mmc_calc_max_discard()
1961 * Without erase_group_def set, MMC erase timeout depends on clock in mmc_calc_max_discard()
1965 if (mmc_card_mmc(card) && !(card->ext_csd.erase_group_def & 1)) in mmc_calc_max_discard()
1966 return card->pref_erase; in mmc_calc_max_discard()
1968 max_discard = mmc_do_calc_max_discard(card, MMC_ERASE_ARG); in mmc_calc_max_discard()
1969 if (mmc_can_trim(card)) { in mmc_calc_max_discard()
1970 max_trim = mmc_do_calc_max_discard(card, MMC_TRIM_ARG); in mmc_calc_max_discard()
1973 } else if (max_discard < card->erase_size) { in mmc_calc_max_discard()
1977 mmc_hostname(host), max_discard, host->max_busy_timeout ? in mmc_calc_max_discard()
1978 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS); in mmc_calc_max_discard()
1983 bool mmc_card_is_blockaddr(struct mmc_card *card) in mmc_card_is_blockaddr() argument
1985 return card ? mmc_card_blockaddr(card) : false; in mmc_card_is_blockaddr()
1989 int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen) in mmc_set_blocklen() argument
1993 if (mmc_card_blockaddr(card) || mmc_card_ddr52(card) || in mmc_set_blocklen()
1994 mmc_card_hs400(card) || mmc_card_hs400es(card)) in mmc_set_blocklen()
2000 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2008 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->card_hw_reset) in mmc_hw_reset_for_init()
2010 host->ops->card_hw_reset(host); in mmc_hw_reset_for_init()
2014 * mmc_hw_reset - reset the card in hardware
2015 * @card: card to be reset
2017 * Hard reset the card. This function is only for upper layers, like the
2018 * block layer or card drivers. You cannot use it in host drivers (struct
2021 * Return: 0 on success, -errno on failure
2023 int mmc_hw_reset(struct mmc_card *card) in mmc_hw_reset() argument
2025 struct mmc_host *host = card->host; in mmc_hw_reset()
2028 ret = host->bus_ops->hw_reset(host); in mmc_hw_reset()
2030 pr_warn("%s: tried to HW reset card, got error %d\n", in mmc_hw_reset()
2037 int mmc_sw_reset(struct mmc_card *card) in mmc_sw_reset() argument
2039 struct mmc_host *host = card->host; in mmc_sw_reset()
2042 if (!host->bus_ops->sw_reset) in mmc_sw_reset()
2043 return -EOPNOTSUPP; in mmc_sw_reset()
2045 ret = host->bus_ops->sw_reset(host); in mmc_sw_reset()
2047 pr_warn("%s: tried to SW reset card, got error %d\n", in mmc_sw_reset()
2056 host->f_init = freq; in mmc_rescan_try_freq()
2058 pr_debug("%s: %s: trying to init card at %u Hz\n", in mmc_rescan_try_freq()
2059 mmc_hostname(host), __func__, host->f_init); in mmc_rescan_try_freq()
2061 mmc_power_up(host, host->ocr_avail); in mmc_rescan_try_freq()
2070 * sdio_reset sends CMD52 to reset card. Since we do not know in mmc_rescan_try_freq()
2071 * if the card is being re-initialized, just send it. CMD52 in mmc_rescan_try_freq()
2075 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2080 if (!(host->caps2 & MMC_CAP2_NO_SD)) { in mmc_rescan_try_freq()
2081 if (mmc_send_if_cond_pcie(host, host->ocr_avail)) in mmc_rescan_try_freq()
2087 /* Order's important: probe SDIO, then SD, then MMC */ in mmc_rescan_try_freq()
2088 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2092 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2096 if (!(host->caps2 & MMC_CAP2_NO_MMC)) in mmc_rescan_try_freq()
2102 return -EIO; in mmc_rescan_try_freq()
2109 if (!host->card || mmc_card_removed(host->card)) in _mmc_detect_card_removed()
2112 ret = host->bus_ops->alive(host); in _mmc_detect_card_removed()
2115 * Card detect status and alive check may be out of sync if card is in _mmc_detect_card_removed()
2116 * removed slowly, when card detect switch changes while card/slot in _mmc_detect_card_removed()
2117 * pads are still contacted in hardware (refer to "SD Card Mechanical in _mmc_detect_card_removed()
2118 * Addendum, Appendix C: Card Detection Switch"). So reschedule a in _mmc_detect_card_removed()
2121 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2123 pr_debug("%s: card removed too slowly\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2127 mmc_card_set_removed(host->card); in _mmc_detect_card_removed()
2128 pr_debug("%s: card remove detected\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2136 struct mmc_card *card = host->card; in mmc_detect_card_removed() local
2139 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2141 if (!card) in mmc_detect_card_removed()
2147 ret = mmc_card_removed(card); in mmc_detect_card_removed()
2149 * The card will be considered unchanged unless we have been asked to in mmc_detect_card_removed()
2150 * detect a change or host requires polling to provide card detection. in mmc_detect_card_removed()
2152 if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_detect_card_removed()
2155 host->detect_change = 0; in mmc_detect_card_removed()
2158 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2161 * rescan handle the card removal. in mmc_detect_card_removed()
2163 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2172 int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *gpt_sector) in mmc_card_alternative_gpt_sector() argument
2176 if ((!(card->host->caps2 & MMC_CAP2_ALT_GPT_TEGRA))) in mmc_card_alternative_gpt_sector()
2177 return -EOPNOTSUPP; in mmc_card_alternative_gpt_sector()
2180 if (card->ext_csd.rev < 3 || in mmc_card_alternative_gpt_sector()
2181 !mmc_card_mmc(card) || in mmc_card_alternative_gpt_sector()
2182 !mmc_card_is_blockaddr(card) || in mmc_card_alternative_gpt_sector()
2183 mmc_card_is_removable(card->host)) in mmc_card_alternative_gpt_sector()
2184 return -ENOENT; in mmc_card_alternative_gpt_sector()
2188 * main one. NVIDIA's bootloader linearizes eMMC boot0->boot1->main in mmc_card_alternative_gpt_sector()
2197 boot_sectors_num = card->ext_csd.raw_boot_mult * SZ_128K / in mmc_card_alternative_gpt_sector()
2201 *gpt_sector = card->ext_csd.sectors - boot_sectors_num - 1; in mmc_card_alternative_gpt_sector()
2213 if (host->rescan_disable) in mmc_rescan()
2216 /* If there is a non-removable card registered, only scan once */ in mmc_rescan()
2217 if (!mmc_card_is_removable(host) && host->rescan_entered) in mmc_rescan()
2219 host->rescan_entered = 1; in mmc_rescan()
2221 if (host->trigger_card_event && host->ops->card_event) { in mmc_rescan()
2223 host->ops->card_event(host); in mmc_rescan()
2225 host->trigger_card_event = false; in mmc_rescan()
2228 /* Verify a registered card to be functional, else remove it. */ in mmc_rescan()
2229 if (host->bus_ops) in mmc_rescan()
2230 host->bus_ops->detect(host); in mmc_rescan()
2232 host->detect_change = 0; in mmc_rescan()
2234 /* if there still is a card present, stop here */ in mmc_rescan()
2235 if (host->bus_ops != NULL) in mmc_rescan()
2239 if (mmc_card_is_removable(host) && host->ops->get_cd && in mmc_rescan()
2240 host->ops->get_cd(host) == 0) { in mmc_rescan()
2246 /* If an SD express card is present, then leave it as is. */ in mmc_rescan()
2254 if (freq > host->f_max) { in mmc_rescan()
2257 freq = host->f_max; in mmc_rescan()
2259 if (!mmc_rescan_try_freq(host, max(freq, host->f_min))) in mmc_rescan()
2261 if (freqs[i] <= host->f_min) in mmc_rescan()
2265 /* A non-removable card should have been detected by now. */ in mmc_rescan()
2266 if (!mmc_card_is_removable(host) && !host->bus_ops) in mmc_rescan()
2267 pr_info("%s: Failed to initialize a non-removable card", in mmc_rescan()
2272 * the card init as those are excepted. in mmc_rescan()
2274 host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0; in mmc_rescan()
2278 if (host->caps & MMC_CAP_NEEDS_POLL) in mmc_rescan()
2279 mmc_schedule_delayed_work(&host->detect, HZ); in mmc_rescan()
2284 host->f_init = max(min(freqs[0], host->f_max), host->f_min); in mmc_start_host()
2285 host->rescan_disable = 0; in mmc_start_host()
2287 if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) { in mmc_start_host()
2289 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2299 if (host->slot.cd_irq >= 0) { in __mmc_stop_host()
2301 disable_irq(host->slot.cd_irq); in __mmc_stop_host()
2304 host->rescan_disable = 1; in __mmc_stop_host()
2305 cancel_delayed_work_sync(&host->detect); in __mmc_stop_host()
2312 /* clear pm flags now and let card drivers set them as needed */ in mmc_stop_host()
2313 host->pm_flags = 0; in mmc_stop_host()
2315 if (host->bus_ops) { in mmc_stop_host()
2316 /* Calling bus_ops->remove() with a claimed host can deadlock */ in mmc_stop_host()
2317 host->bus_ops->remove(host); in mmc_stop_host()
2365 MODULE_DESCRIPTION("MMC core driver");