Lines Matching full:host
30 #include <linux/mmc/host.h>
42 #include "host.h"
50 /* The max erase timeout, used when host->max_busy_timeout isn't specified */
82 static void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
97 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) in mmc_should_fail_request()
106 static inline void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
119 void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_command_done() argument
127 mmc_hostname(host), mrq->cmd->opcode); in mmc_command_done()
133 * @host: MMC host which completed request
139 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_request_done() argument
146 !host->retune_crc_disable && in mmc_request_done()
150 mmc_retune_needed(host); in mmc_request_done()
152 if (err && cmd->retries && mmc_host_is_spi(host)) { in mmc_request_done()
157 if (host->ongoing_mrq == mrq) in mmc_request_done()
158 host->ongoing_mrq = NULL; in mmc_request_done()
162 trace_mmc_request_done(host, mrq); in mmc_request_done()
173 if (!err || !cmd->retries || mmc_card_removed(host->card)) { in mmc_request_done()
174 mmc_should_fail_request(host, mrq); 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()
181 mmc_hostname(host), mrq->sbc->opcode, in mmc_request_done()
188 mmc_hostname(host), cmd->opcode, err, in mmc_request_done()
194 mmc_hostname(host), in mmc_request_done()
200 mmc_hostname(host), mrq->stop->opcode, in mmc_request_done()
216 static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_request() argument
220 /* Assumes host controller has been runtime resumed by mmc_claim_host */ in __mmc_start_request()
221 err = mmc_retune(host); in __mmc_start_request()
224 mmc_request_done(host, mrq); 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()
242 mmc_request_done(host, mrq); in __mmc_start_request()
248 host->ongoing_mrq = mrq; in __mmc_start_request()
256 trace_mmc_request_start(host, mrq); 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()
264 static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq, in mmc_mrq_pr_debug() argument
269 mmc_hostname(host), mrq->sbc->opcode, in mmc_mrq_pr_debug()
275 mmc_hostname(host), cqe ? "CQE direct " : "", in mmc_mrq_pr_debug()
279 mmc_hostname(host), mrq->tag, mrq->data->blk_addr); in mmc_mrq_pr_debug()
285 mmc_hostname(host), mrq->data->blksz, in mmc_mrq_pr_debug()
293 mmc_hostname(host), mrq->stop->opcode, in mmc_mrq_pr_debug()
298 static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq) in mmc_mrq_prep() argument
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()
335 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in mmc_start_request() argument
341 mmc_retune_hold(host); in mmc_start_request()
343 if (mmc_card_removed(host->card)) in mmc_start_request()
346 mmc_mrq_pr_debug(host, mrq, false); in mmc_start_request()
348 WARN_ON(!host->claimed); in mmc_start_request()
350 err = mmc_mrq_prep(host, mrq); in mmc_start_request()
354 led_trigger_event(host->led, LED_FULL); in mmc_start_request()
355 __mmc_start_request(host, mrq); in mmc_start_request()
366 static inline void mmc_wait_ongoing_tfr_cmd(struct mmc_host *host) in mmc_wait_ongoing_tfr_cmd() argument
368 struct mmc_request *ongoing_mrq = READ_ONCE(host->ongoing_mrq); in mmc_wait_ongoing_tfr_cmd()
378 static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_req() argument
382 mmc_wait_ongoing_tfr_cmd(host); in __mmc_start_req()
387 err = mmc_start_request(host, mrq); in __mmc_start_req()
397 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req_done() argument
407 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
410 mmc_retune_recheck(host); in mmc_wait_for_req_done()
413 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
416 __mmc_start_request(host, mrq); in mmc_wait_for_req_done()
419 mmc_retune_release(host); in mmc_wait_for_req_done()
425 * @host: MMC host to start the request
431 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_start_req() argument
441 err = mmc_retune(host); in mmc_cqe_start_req()
445 mrq->host = host; in mmc_cqe_start_req()
447 mmc_mrq_pr_debug(host, mrq, true); in mmc_cqe_start_req()
449 err = mmc_mrq_prep(host, mrq); in mmc_cqe_start_req()
453 err = host->cqe_ops->cqe_request(host, mrq); in mmc_cqe_start_req()
457 trace_mmc_request_start(host, mrq); 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()
475 * @host: MMC host which completed request
481 void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_request_done() argument
483 mmc_should_fail_request(host, mrq); in mmc_cqe_request_done()
488 mmc_retune_needed(host); in mmc_cqe_request_done()
490 trace_mmc_request_done(host, mrq); 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()
502 mmc_hostname(host), in mmc_cqe_request_done()
512 * @host: MMC host
515 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_post_req() argument
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()
527 * @host: MMC host to recover
534 int mmc_cqe_recovery(struct mmc_host *host) in mmc_cqe_recovery() argument
539 mmc_retune_hold_now(host); in mmc_cqe_recovery()
545 pr_warn("%s: running CQE recovery\n", mmc_hostname(host)); in mmc_cqe_recovery()
547 host->cqe_ops->cqe_recovery_start(host); in mmc_cqe_recovery()
554 mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
556 mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); in mmc_cqe_recovery()
564 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
566 host->cqe_ops->cqe_recovery_finish(host); in mmc_cqe_recovery()
569 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
571 mmc_retune_release(host); in mmc_cqe_recovery()
579 * @host: MMC host
589 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_is_req_done() argument
597 * @host: MMC host to start command
600 * Start a new MMC custom command request for a host, and wait
607 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req() argument
609 __mmc_start_req(host, mrq); in mmc_wait_for_req()
612 mmc_wait_for_req_done(host, mrq); in mmc_wait_for_req()
618 * @host: MMC host to start command
622 * Start a new MMC command for a host, and wait for the command
626 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) in mmc_wait_for_cmd() argument
630 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
638 mmc_wait_for_req(host, &mrq); in mmc_wait_for_cmd()
688 if (card->host->ios.clock) in mmc_set_data_timeout()
690 (card->host->ios.clock / 1000); in mmc_set_data_timeout()
735 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
748 * Allow claiming an already claimed host if the context is the same or there is
751 static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx, in mmc_ctx_matches() argument
754 return host->claimer == ctx || in mmc_ctx_matches()
755 (!ctx && task && host->claimer->task == task); in mmc_ctx_matches()
758 static inline void mmc_ctx_set_claimer(struct mmc_host *host, in mmc_ctx_set_claimer() argument
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
775 * @ctx: context that claims the host or NULL in which case the default
779 * Claim a host for a set of operations. If @abort is non null and
784 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx, in __mmc_claim_host() argument
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()
809 mmc_ctx_set_claimer(host, ctx, task); 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()
819 pm_runtime_get_sync(mmc_dev(host)); 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
832 void mmc_release_host(struct mmc_host *host) in mmc_release_host() argument
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()
848 pm_runtime_mark_last_busy(mmc_dev(host)); in mmc_release_host()
849 if (host->caps & MMC_CAP_SYNC_RUNTIME_PM) in mmc_release_host()
850 pm_runtime_put_sync_suspend(mmc_dev(host)); in mmc_release_host()
852 pm_runtime_put_autosuspend(mmc_dev(host)); in mmc_release_host()
859 * card device and also claims the host.
864 __mmc_claim_host(card->host, ctx, NULL); in mmc_get_card()
869 * This is a helper function, which releases the host and drops the runtime
874 struct mmc_host *host = card->host; in mmc_put_card() local
876 WARN_ON(ctx && host->claimer != ctx); in mmc_put_card()
878 mmc_release_host(host); in mmc_put_card()
885 * Internal function that does the actual ios call to the host driver,
888 static inline void mmc_set_ios(struct mmc_host *host) in mmc_set_ios() argument
890 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
894 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
898 host->ops->set_ios(host, ios); in mmc_set_ios()
902 * Control chip select pin on a host.
904 void mmc_set_chip_select(struct mmc_host *host, int mode) in mmc_set_chip_select() argument
906 host->ios.chip_select = mode; in mmc_set_chip_select()
907 mmc_set_ios(host); in mmc_set_chip_select()
911 * Sets the host clock to the highest possible frequency that
914 void mmc_set_clock(struct mmc_host *host, unsigned int hz) in mmc_set_clock() argument
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()
922 mmc_set_ios(host); in mmc_set_clock()
927 struct mmc_host *host = card->host; in mmc_execute_tuning() local
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()
942 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
944 mmc_retune_clear(host); in mmc_execute_tuning()
945 mmc_retune_enable(host); in mmc_execute_tuning()
950 if (!host->detect_change) { in mmc_execute_tuning()
952 mmc_hostname(host), err); in mmc_execute_tuning()
953 mmc_debugfs_err_stats_inc(host, MMC_ERR_TUNING); in mmc_execute_tuning()
960 * Change the bus mode (open drain/push-pull) of a host.
962 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) in mmc_set_bus_mode() argument
964 host->ios.bus_mode = mode; in mmc_set_bus_mode()
965 mmc_set_ios(host); in mmc_set_bus_mode()
969 * Change data bus width of a host.
971 void mmc_set_bus_width(struct mmc_host *host, unsigned int width) in mmc_set_bus_width() argument
973 host->ios.bus_width = width; in mmc_set_bus_width()
974 mmc_set_ios(host); in mmc_set_bus_width()
980 void mmc_set_initial_state(struct mmc_host *host) in mmc_set_initial_state() argument
982 if (host->cqe_on) in mmc_set_initial_state()
983 host->cqe_ops->cqe_off(host); in mmc_set_initial_state()
985 mmc_retune_disable(host); in mmc_set_initial_state()
987 if (mmc_host_is_spi(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()
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()
1005 mmc_set_ios(host); in mmc_set_initial_state()
1007 mmc_crypto_set_initial_state(host); in mmc_set_initial_state()
1095 struct device_node *mmc_of_find_child_device(struct mmc_host *host, in mmc_of_find_child_device() argument
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()
1115 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) in mmc_select_voltage() argument
1124 dev_warn(mmc_dev(host), 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()
1138 mmc_power_cycle(host, ocr); 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()
1155 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) in mmc_set_signal_voltage() argument
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()
1171 void mmc_set_initial_signal_voltage(struct mmc_host *host) in mmc_set_initial_signal_voltage() argument
1174 if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) in mmc_set_initial_signal_voltage()
1175 dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); in mmc_set_initial_signal_voltage()
1176 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_set_initial_signal_voltage()
1177 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); in mmc_set_initial_signal_voltage()
1178 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) in mmc_set_initial_signal_voltage()
1179 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); in mmc_set_initial_signal_voltage()
1182 int mmc_host_set_uhs_voltage(struct mmc_host *host) in mmc_host_set_uhs_voltage() argument
1190 clock = host->ios.clock; in mmc_host_set_uhs_voltage()
1191 host->ios.clock = 0; in mmc_host_set_uhs_voltage()
1192 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1194 if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_host_set_uhs_voltage()
1199 host->ios.clock = clock; in mmc_host_set_uhs_voltage()
1200 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1205 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr) in mmc_set_uhs_voltage() argument
1214 if (!host->ops->start_signal_voltage_switch) in mmc_set_uhs_voltage()
1216 if (!host->ops->card_busy) in mmc_set_uhs_voltage()
1218 mmc_hostname(host)); in mmc_set_uhs_voltage()
1224 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_set_uhs_voltage()
1228 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) in mmc_set_uhs_voltage()
1236 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_uhs_voltage()
1241 if (mmc_host_set_uhs_voltage(host)) { in mmc_set_uhs_voltage()
1257 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_uhs_voltage()
1263 "power cycling card\n", mmc_hostname(host)); in mmc_set_uhs_voltage()
1264 mmc_power_cycle(host, ocr); in mmc_set_uhs_voltage()
1271 * Select timing parameters for host.
1273 void mmc_set_timing(struct mmc_host *host, unsigned int timing) in mmc_set_timing() argument
1275 host->ios.timing = timing; in mmc_set_timing()
1276 mmc_set_ios(host); in mmc_set_timing()
1280 * Select appropriate driver type for host.
1282 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) in mmc_set_driver_type() argument
1284 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1285 mmc_set_ios(host); in mmc_set_driver_type()
1291 struct mmc_host *host = card->host; in mmc_select_drive_strength() local
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()
1329 * If a host does all the power sequencing itself, ignore the
1332 void mmc_power_up(struct mmc_host *host, u32 ocr) in mmc_power_up() argument
1334 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1337 mmc_pwrseq_pre_power_on(host); 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()
1342 mmc_set_initial_state(host); in mmc_power_up()
1344 mmc_set_initial_signal_voltage(host); in mmc_power_up()
1350 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1352 mmc_pwrseq_post_power_on(host); 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()
1357 mmc_set_ios(host); in mmc_power_up()
1363 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1366 void mmc_power_off(struct mmc_host *host) in mmc_power_off() argument
1368 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1371 mmc_pwrseq_power_off(host); 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()
1378 mmc_set_initial_state(host); in mmc_power_off()
1388 void mmc_power_cycle(struct mmc_host *host, u32 ocr) in mmc_power_cycle() argument
1390 mmc_power_off(host); in mmc_power_cycle()
1393 mmc_power_up(host, ocr); in mmc_power_cycle()
1397 * Assign a mmc bus handler to a host. Only one bus handler may control a
1398 * host at any given time.
1400 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) in mmc_attach_bus() argument
1402 host->bus_ops = ops; in mmc_attach_bus()
1406 * Remove the current bus handler from a host.
1408 void mmc_detach_bus(struct mmc_host *host) in mmc_detach_bus() argument
1410 host->bus_ops = NULL; in mmc_detach_bus()
1413 void _mmc_detect_change(struct mmc_host *host, unsigned long delay, bool cd_irq) in _mmc_detect_change() argument
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()
1429 * @host: host which changed state.
1437 void mmc_detect_change(struct mmc_host *host, unsigned long delay) in mmc_detect_change() argument
1439 _mmc_detect_change(host, delay, true); in mmc_detect_change()
1528 (card->host->ios.clock / 1000); in mmc_mmc_erase_timeout()
1554 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
1609 mmc_retune_hold(card->host); in mmc_do_erase()
1647 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1662 err = mmc_wait_for_cmd(card->host, &cmd, 0); 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()
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()
1698 mmc_retune_release(card->host); in mmc_do_erase()
1757 * Caller must claim host before calling this function.
1880 struct mmc_host *host = card->host; in mmc_do_calc_max_discard() local
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()
1898 * We should not only use 'host->max_busy_timeout' as the limitation 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()
1957 struct mmc_host *host = card->host; in mmc_calc_max_discard() local
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()
2000 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2004 static void mmc_hw_reset_for_init(struct mmc_host *host) in mmc_hw_reset_for_init() argument
2006 mmc_pwrseq_reset(host); in mmc_hw_reset_for_init()
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()
2018 * block layer or card drivers. You cannot use it in host drivers (struct
2025 struct mmc_host *host = card->host; in mmc_hw_reset() local
2028 ret = host->bus_ops->hw_reset(host); in mmc_hw_reset()
2031 mmc_hostname(host), ret); in mmc_hw_reset()
2039 struct mmc_host *host = card->host; in mmc_sw_reset() local
2042 if (!host->bus_ops->sw_reset) in mmc_sw_reset()
2045 ret = host->bus_ops->sw_reset(host); in mmc_sw_reset()
2048 mmc_hostname(host), ret); in mmc_sw_reset()
2054 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) in mmc_rescan_try_freq() argument
2056 host->f_init = freq; 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()
2067 mmc_hw_reset_for_init(host); in mmc_rescan_try_freq()
2075 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2076 sdio_reset(host); in mmc_rescan_try_freq()
2078 mmc_go_idle(host); 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()
2083 if (mmc_card_sd_express(host)) in mmc_rescan_try_freq()
2088 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2089 if (!mmc_attach_sdio(host)) in mmc_rescan_try_freq()
2092 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2093 if (!mmc_attach_sd(host)) in mmc_rescan_try_freq()
2096 if (!(host->caps2 & MMC_CAP2_NO_MMC)) in mmc_rescan_try_freq()
2097 if (!mmc_attach_mmc(host)) in mmc_rescan_try_freq()
2101 mmc_power_off(host); in mmc_rescan_try_freq()
2105 int _mmc_detect_card_removed(struct mmc_host *host) in _mmc_detect_card_removed() argument
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()
2121 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2122 mmc_detect_change(host, msecs_to_jiffies(200)); 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()
2134 int mmc_detect_card_removed(struct mmc_host *host) in mmc_detect_card_removed() argument
2136 struct mmc_card *card = host->card; in mmc_detect_card_removed()
2139 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2144 if (!mmc_card_is_removable(host)) 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()
2157 ret = _mmc_detect_card_removed(host); in mmc_detect_card_removed()
2158 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2163 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2164 _mmc_detect_change(host, 0, false); in mmc_detect_card_removed()
2176 if ((!(card->host->caps2 & MMC_CAP2_ALT_GPT_TEGRA))) in mmc_card_alternative_gpt_sector()
2183 mmc_card_is_removable(card->host)) in mmc_card_alternative_gpt_sector()
2209 struct mmc_host *host = in mmc_rescan() local
2213 if (host->rescan_disable) 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()
2222 mmc_claim_host(host); in mmc_rescan()
2223 host->ops->card_event(host); in mmc_rescan()
2224 mmc_release_host(host); in mmc_rescan()
2225 host->trigger_card_event = false; 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()
2235 if (host->bus_ops != NULL) in mmc_rescan()
2238 mmc_claim_host(host); 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()
2241 mmc_power_off(host); in mmc_rescan()
2242 mmc_release_host(host); in mmc_rescan()
2247 if (mmc_card_sd_express(host)) { in mmc_rescan()
2248 mmc_release_host(host); 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()
2266 if (!mmc_card_is_removable(host) && !host->bus_ops) in mmc_rescan()
2268 mmc_hostname(host)); in mmc_rescan()
2274 host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0; in mmc_rescan()
2275 mmc_release_host(host); 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()
2282 void mmc_start_host(struct mmc_host *host) in mmc_start_host() argument
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()
2288 mmc_claim_host(host); in mmc_start_host()
2289 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2290 mmc_release_host(host); in mmc_start_host()
2293 mmc_gpiod_request_cd_irq(host); in mmc_start_host()
2294 _mmc_detect_change(host, 0, false); in mmc_start_host()
2297 void __mmc_stop_host(struct mmc_host *host) in __mmc_stop_host() argument
2299 if (host->slot.cd_irq >= 0) { in __mmc_stop_host()
2300 mmc_gpio_set_cd_wake(host, false); 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()
2308 void mmc_stop_host(struct mmc_host *host) in mmc_stop_host() argument
2310 __mmc_stop_host(host); 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()
2318 mmc_claim_host(host); in mmc_stop_host()
2319 mmc_detach_bus(host); in mmc_stop_host()
2320 mmc_power_off(host); in mmc_stop_host()
2321 mmc_release_host(host); in mmc_stop_host()
2325 mmc_claim_host(host); in mmc_stop_host()
2326 mmc_power_off(host); in mmc_stop_host()
2327 mmc_release_host(host); in mmc_stop_host()