Lines Matching refs:host

81 static void mmc_should_fail_request(struct mmc_host *host,  in mmc_should_fail_request()  argument
96 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) in mmc_should_fail_request()
105 static inline void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
118 void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_command_done() argument
126 mmc_hostname(host), mrq->cmd->opcode); in mmc_command_done()
138 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_request_done() argument
145 !host->retune_crc_disable && in mmc_request_done()
149 mmc_retune_needed(host); in mmc_request_done()
151 if (err && cmd->retries && mmc_host_is_spi(host)) { in mmc_request_done()
156 if (host->ongoing_mrq == mrq) in mmc_request_done()
157 host->ongoing_mrq = NULL; in mmc_request_done()
161 trace_mmc_request_done(host, mrq); in mmc_request_done()
172 if (!err || !cmd->retries || mmc_card_removed(host->card)) { in mmc_request_done()
173 mmc_should_fail_request(host, mrq); in mmc_request_done()
175 if (!host->ongoing_mrq) in mmc_request_done()
176 led_trigger_event(host->led, LED_OFF); in mmc_request_done()
180 mmc_hostname(host), mrq->sbc->opcode, in mmc_request_done()
187 mmc_hostname(host), cmd->opcode, err, in mmc_request_done()
193 mmc_hostname(host), in mmc_request_done()
199 mmc_hostname(host), mrq->stop->opcode, in mmc_request_done()
215 static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_request() argument
220 err = mmc_retune(host); in __mmc_start_request()
223 mmc_request_done(host, mrq); in __mmc_start_request()
233 host->ops->card_busy) { in __mmc_start_request()
236 while (host->ops->card_busy(host) && --tries) in __mmc_start_request()
241 mmc_request_done(host, mrq); in __mmc_start_request()
247 host->ongoing_mrq = mrq; in __mmc_start_request()
255 trace_mmc_request_start(host, mrq); in __mmc_start_request()
257 if (host->cqe_on) in __mmc_start_request()
258 host->cqe_ops->cqe_off(host); in __mmc_start_request()
260 host->ops->request(host, mrq); in __mmc_start_request()
263 static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq, in mmc_mrq_pr_debug() argument
268 mmc_hostname(host), mrq->sbc->opcode, in mmc_mrq_pr_debug()
274 mmc_hostname(host), cqe ? "CQE direct " : "", in mmc_mrq_pr_debug()
278 mmc_hostname(host), mrq->tag, mrq->data->blk_addr); in mmc_mrq_pr_debug()
284 mmc_hostname(host), mrq->data->blksz, in mmc_mrq_pr_debug()
292 mmc_hostname(host), mrq->stop->opcode, in mmc_mrq_pr_debug()
297 static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq) in mmc_mrq_prep() argument
312 if (mrq->data->blksz > host->max_blk_size || in mmc_mrq_prep()
313 mrq->data->blocks > host->max_blk_count || in mmc_mrq_prep()
314 mrq->data->blocks * mrq->data->blksz > host->max_req_size) in mmc_mrq_prep()
334 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in mmc_start_request() argument
339 mmc_send_ext_addr(host, mrq->cmd->ext_addr); in mmc_start_request()
343 mmc_retune_hold(host); in mmc_start_request()
345 if (mmc_card_removed(host->card)) in mmc_start_request()
348 mmc_mrq_pr_debug(host, mrq, false); in mmc_start_request()
350 WARN_ON(!host->claimed); in mmc_start_request()
352 err = mmc_mrq_prep(host, mrq); in mmc_start_request()
356 if (host->uhs2_sd_tran) in mmc_start_request()
357 mmc_uhs2_prepare_cmd(host, mrq); in mmc_start_request()
359 led_trigger_event(host->led, LED_FULL); in mmc_start_request()
360 __mmc_start_request(host, mrq); in mmc_start_request()
371 static inline void mmc_wait_ongoing_tfr_cmd(struct mmc_host *host) in mmc_wait_ongoing_tfr_cmd() argument
373 struct mmc_request *ongoing_mrq = READ_ONCE(host->ongoing_mrq); in mmc_wait_ongoing_tfr_cmd()
383 static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_req() argument
387 mmc_wait_ongoing_tfr_cmd(host); in __mmc_start_req()
392 err = mmc_start_request(host, mrq); in __mmc_start_req()
402 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req_done() argument
412 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
415 mmc_retune_recheck(host); in mmc_wait_for_req_done()
418 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
421 __mmc_start_request(host, mrq); in mmc_wait_for_req_done()
424 mmc_retune_release(host); in mmc_wait_for_req_done()
436 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_start_req() argument
446 err = mmc_retune(host); in mmc_cqe_start_req()
450 mrq->host = host; in mmc_cqe_start_req()
452 mmc_mrq_pr_debug(host, mrq, true); in mmc_cqe_start_req()
454 err = mmc_mrq_prep(host, mrq); in mmc_cqe_start_req()
458 if (host->uhs2_sd_tran) in mmc_cqe_start_req()
459 mmc_uhs2_prepare_cmd(host, mrq); in mmc_cqe_start_req()
461 err = host->cqe_ops->cqe_request(host, mrq); in mmc_cqe_start_req()
465 trace_mmc_request_start(host, mrq); in mmc_cqe_start_req()
472 mmc_hostname(host), mrq->cmd->opcode, err); in mmc_cqe_start_req()
475 mmc_hostname(host), mrq->tag, err); in mmc_cqe_start_req()
489 void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_request_done() argument
491 mmc_should_fail_request(host, mrq); in mmc_cqe_request_done()
496 mmc_retune_needed(host); in mmc_cqe_request_done()
498 trace_mmc_request_done(host, mrq); in mmc_cqe_request_done()
502 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->error); in mmc_cqe_request_done()
505 mmc_hostname(host), mrq->tag); in mmc_cqe_request_done()
510 mmc_hostname(host), in mmc_cqe_request_done()
523 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_post_req() argument
525 if (host->cqe_ops->cqe_post_req) in mmc_cqe_post_req()
526 host->cqe_ops->cqe_post_req(host, mrq); in mmc_cqe_post_req()
542 int mmc_cqe_recovery(struct mmc_host *host) in mmc_cqe_recovery() argument
547 mmc_retune_hold_now(host); in mmc_cqe_recovery()
553 pr_warn("%s: running CQE recovery\n", mmc_hostname(host)); in mmc_cqe_recovery()
555 host->cqe_ops->cqe_recovery_start(host); in mmc_cqe_recovery()
561 mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
563 mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); in mmc_cqe_recovery()
570 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
572 host->cqe_ops->cqe_recovery_finish(host); in mmc_cqe_recovery()
575 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); in mmc_cqe_recovery()
577 mmc_retune_release(host); in mmc_cqe_recovery()
595 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_is_req_done() argument
613 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req() argument
615 __mmc_start_req(host, mrq); in mmc_wait_for_req()
618 mmc_wait_for_req_done(host, mrq); in mmc_wait_for_req()
632 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) in mmc_wait_for_cmd() argument
636 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
644 mmc_wait_for_req(host, &mrq); in mmc_wait_for_cmd()
694 if (card->host->ios.clock) in mmc_set_data_timeout()
696 (card->host->ios.clock / 1000); in mmc_set_data_timeout()
741 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
757 static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx, in mmc_ctx_matches() argument
760 return host->claimer == ctx || in mmc_ctx_matches()
761 (!ctx && task && host->claimer->task == task); in mmc_ctx_matches()
764 static inline void mmc_ctx_set_claimer(struct mmc_host *host, in mmc_ctx_set_claimer() argument
768 if (!host->claimer) { in mmc_ctx_set_claimer()
770 host->claimer = ctx; in mmc_ctx_set_claimer()
772 host->claimer = &host->default_ctx; in mmc_ctx_set_claimer()
775 host->claimer->task = task; in mmc_ctx_set_claimer()
790 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx, in __mmc_claim_host() argument
801 add_wait_queue(&host->wq, &wait); in __mmc_claim_host()
802 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
806 if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task)) in __mmc_claim_host()
808 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
810 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
814 host->claimed = 1; in __mmc_claim_host()
815 mmc_ctx_set_claimer(host, ctx, task); in __mmc_claim_host()
816 host->claim_cnt += 1; in __mmc_claim_host()
817 if (host->claim_cnt == 1) in __mmc_claim_host()
820 wake_up(&host->wq); in __mmc_claim_host()
821 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
822 remove_wait_queue(&host->wq, &wait); in __mmc_claim_host()
825 pm_runtime_get_sync(mmc_dev(host)); in __mmc_claim_host()
838 void mmc_release_host(struct mmc_host *host) in mmc_release_host() argument
842 WARN_ON(!host->claimed); in mmc_release_host()
844 spin_lock_irqsave(&host->lock, flags); in mmc_release_host()
845 if (--host->claim_cnt) { in mmc_release_host()
847 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
849 host->claimed = 0; in mmc_release_host()
850 host->claimer->task = NULL; in mmc_release_host()
851 host->claimer = NULL; in mmc_release_host()
852 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
853 wake_up(&host->wq); in mmc_release_host()
854 pm_runtime_mark_last_busy(mmc_dev(host)); in mmc_release_host()
855 if (host->caps & MMC_CAP_SYNC_RUNTIME_PM) in mmc_release_host()
856 pm_runtime_put_sync_suspend(mmc_dev(host)); in mmc_release_host()
858 pm_runtime_put_autosuspend(mmc_dev(host)); in mmc_release_host()
870 __mmc_claim_host(card->host, ctx, NULL); in mmc_get_card()
880 struct mmc_host *host = card->host; in mmc_put_card() local
882 WARN_ON(ctx && host->claimer != ctx); in mmc_put_card()
884 mmc_release_host(host); in mmc_put_card()
893 static inline void mmc_set_ios(struct mmc_host *host) in mmc_set_ios() argument
895 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
899 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
903 host->ops->set_ios(host, ios); in mmc_set_ios()
909 void mmc_set_chip_select(struct mmc_host *host, int mode) in mmc_set_chip_select() argument
911 host->ios.chip_select = mode; in mmc_set_chip_select()
912 mmc_set_ios(host); in mmc_set_chip_select()
919 void mmc_set_clock(struct mmc_host *host, unsigned int hz) in mmc_set_clock() argument
921 WARN_ON(hz && hz < host->f_min); in mmc_set_clock()
923 if (hz > host->f_max) in mmc_set_clock()
924 hz = host->f_max; in mmc_set_clock()
926 host->ios.clock = hz; in mmc_set_clock()
927 mmc_set_ios(host); in mmc_set_clock()
932 struct mmc_host *host = card->host; in mmc_execute_tuning() local
936 if (!host->ops->execute_tuning) in mmc_execute_tuning()
939 if (host->cqe_on) in mmc_execute_tuning()
940 host->cqe_ops->cqe_off(host); in mmc_execute_tuning()
947 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
949 mmc_retune_clear(host); in mmc_execute_tuning()
950 mmc_retune_enable(host); in mmc_execute_tuning()
955 if (!host->detect_change) { in mmc_execute_tuning()
957 mmc_hostname(host), err); in mmc_execute_tuning()
958 mmc_debugfs_err_stats_inc(host, MMC_ERR_TUNING); in mmc_execute_tuning()
967 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) in mmc_set_bus_mode() argument
969 host->ios.bus_mode = mode; in mmc_set_bus_mode()
970 mmc_set_ios(host); in mmc_set_bus_mode()
976 void mmc_set_bus_width(struct mmc_host *host, unsigned int width) in mmc_set_bus_width() argument
978 host->ios.bus_width = width; in mmc_set_bus_width()
979 mmc_set_ios(host); in mmc_set_bus_width()
985 void mmc_set_initial_state(struct mmc_host *host) in mmc_set_initial_state() argument
987 if (host->cqe_on) in mmc_set_initial_state()
988 host->cqe_ops->cqe_off(host); in mmc_set_initial_state()
990 mmc_retune_disable(host); in mmc_set_initial_state()
992 if (mmc_host_is_spi(host)) in mmc_set_initial_state()
993 host->ios.chip_select = MMC_CS_HIGH; in mmc_set_initial_state()
995 host->ios.chip_select = MMC_CS_DONTCARE; in mmc_set_initial_state()
996 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; in mmc_set_initial_state()
997 host->ios.bus_width = MMC_BUS_WIDTH_1; in mmc_set_initial_state()
998 host->ios.timing = MMC_TIMING_LEGACY; in mmc_set_initial_state()
999 host->ios.drv_type = 0; in mmc_set_initial_state()
1000 host->ios.enhanced_strobe = false; in mmc_set_initial_state()
1006 if ((host->caps2 & MMC_CAP2_HS400_ES) && in mmc_set_initial_state()
1007 host->ops->hs400_enhanced_strobe) in mmc_set_initial_state()
1008 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_set_initial_state()
1010 mmc_set_ios(host); in mmc_set_initial_state()
1012 mmc_crypto_set_initial_state(host); in mmc_set_initial_state()
1100 struct device_node *mmc_of_find_child_device(struct mmc_host *host, in mmc_of_find_child_device() argument
1105 if (!host->parent || !host->parent->of_node) in mmc_of_find_child_device()
1108 for_each_child_of_node(host->parent->of_node, node) { in mmc_of_find_child_device()
1120 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) in mmc_select_voltage() argument
1129 dev_warn(mmc_dev(host), in mmc_select_voltage()
1134 ocr &= host->ocr_avail; in mmc_select_voltage()
1136 dev_warn(mmc_dev(host), "no support for card's volts\n"); in mmc_select_voltage()
1140 if (!mmc_card_uhs2(host) && host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { in mmc_select_voltage()
1143 mmc_power_cycle(host, ocr); in mmc_select_voltage()
1153 if (bit != host->ios.vdd) in mmc_select_voltage()
1154 dev_warn(mmc_dev(host), "exceeding card's volts\n"); in mmc_select_voltage()
1160 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) in mmc_set_signal_voltage() argument
1163 int old_signal_voltage = host->ios.signal_voltage; in mmc_set_signal_voltage()
1165 host->ios.signal_voltage = signal_voltage; in mmc_set_signal_voltage()
1166 if (host->ops->start_signal_voltage_switch) in mmc_set_signal_voltage()
1167 err = host->ops->start_signal_voltage_switch(host, &host->ios); in mmc_set_signal_voltage()
1170 host->ios.signal_voltage = old_signal_voltage; in mmc_set_signal_voltage()
1176 void mmc_set_initial_signal_voltage(struct mmc_host *host) in mmc_set_initial_signal_voltage() argument
1179 if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) in mmc_set_initial_signal_voltage()
1180 dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); in mmc_set_initial_signal_voltage()
1181 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_set_initial_signal_voltage()
1182 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); in mmc_set_initial_signal_voltage()
1183 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) in mmc_set_initial_signal_voltage()
1184 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); in mmc_set_initial_signal_voltage()
1187 int mmc_host_set_uhs_voltage(struct mmc_host *host) in mmc_host_set_uhs_voltage() argument
1195 clock = host->ios.clock; in mmc_host_set_uhs_voltage()
1196 host->ios.clock = 0; in mmc_host_set_uhs_voltage()
1197 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1199 if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_host_set_uhs_voltage()
1204 host->ios.clock = clock; in mmc_host_set_uhs_voltage()
1205 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1210 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr) in mmc_set_uhs_voltage() argument
1219 if (!host->ops->start_signal_voltage_switch) in mmc_set_uhs_voltage()
1221 if (!host->ops->card_busy) in mmc_set_uhs_voltage()
1223 mmc_hostname(host)); in mmc_set_uhs_voltage()
1229 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_set_uhs_voltage()
1233 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) in mmc_set_uhs_voltage()
1241 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_uhs_voltage()
1246 if (mmc_host_set_uhs_voltage(host)) { in mmc_set_uhs_voltage()
1262 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_uhs_voltage()
1268 "power cycling card\n", mmc_hostname(host)); in mmc_set_uhs_voltage()
1269 mmc_power_cycle(host, ocr); in mmc_set_uhs_voltage()
1278 void mmc_set_timing(struct mmc_host *host, unsigned int timing) in mmc_set_timing() argument
1280 host->ios.timing = timing; in mmc_set_timing()
1281 mmc_set_ios(host); in mmc_set_timing()
1287 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) in mmc_set_driver_type() argument
1289 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1290 mmc_set_ios(host); in mmc_set_driver_type()
1296 struct mmc_host *host = card->host; in mmc_select_drive_strength() local
1301 if (!host->ops->select_drive_strength) in mmc_select_drive_strength()
1305 if (host->caps & MMC_CAP_DRIVER_TYPE_A) in mmc_select_drive_strength()
1308 if (host->caps & MMC_CAP_DRIVER_TYPE_C) in mmc_select_drive_strength()
1311 if (host->caps & MMC_CAP_DRIVER_TYPE_D) in mmc_select_drive_strength()
1320 return host->ops->select_drive_strength(card, max_dtr, in mmc_select_drive_strength()
1337 void mmc_power_up(struct mmc_host *host, u32 ocr) in mmc_power_up() argument
1339 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1342 mmc_pwrseq_pre_power_on(host); in mmc_power_up()
1344 host->ios.vdd = fls(ocr) - 1; in mmc_power_up()
1345 host->ios.power_mode = MMC_POWER_UP; in mmc_power_up()
1347 mmc_set_initial_state(host); in mmc_power_up()
1349 mmc_set_initial_signal_voltage(host); in mmc_power_up()
1355 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1357 mmc_pwrseq_post_power_on(host); in mmc_power_up()
1359 host->ios.clock = host->f_init; in mmc_power_up()
1361 host->ios.power_mode = MMC_POWER_ON; in mmc_power_up()
1362 mmc_set_ios(host); in mmc_power_up()
1368 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1371 void mmc_power_off(struct mmc_host *host) in mmc_power_off() argument
1373 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1376 mmc_pwrseq_power_off(host); in mmc_power_off()
1378 host->ios.clock = 0; in mmc_power_off()
1379 host->ios.vdd = 0; in mmc_power_off()
1381 host->ios.power_mode = MMC_POWER_OFF; in mmc_power_off()
1383 mmc_set_initial_state(host); in mmc_power_off()
1393 void mmc_power_cycle(struct mmc_host *host, u32 ocr) in mmc_power_cycle() argument
1395 mmc_power_off(host); in mmc_power_cycle()
1398 mmc_power_up(host, ocr); in mmc_power_cycle()
1405 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) in mmc_attach_bus() argument
1407 host->bus_ops = ops; in mmc_attach_bus()
1413 void mmc_detach_bus(struct mmc_host *host) in mmc_detach_bus() argument
1415 host->bus_ops = NULL; in mmc_detach_bus()
1418 void _mmc_detect_change(struct mmc_host *host, unsigned long delay, bool cd_irq) in _mmc_detect_change() argument
1425 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL)) in _mmc_detect_change()
1426 __pm_wakeup_event(host->ws, 5000); in _mmc_detect_change()
1428 host->detect_change = 1; in _mmc_detect_change()
1429 mmc_schedule_delayed_work(&host->detect, delay); in _mmc_detect_change()
1442 void mmc_detect_change(struct mmc_host *host, unsigned long delay) in mmc_detect_change() argument
1444 _mmc_detect_change(host, delay, true); in mmc_detect_change()
1533 (card->host->ios.clock / 1000); in mmc_mmc_erase_timeout()
1559 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
1614 mmc_retune_hold(card->host); in mmc_do_erase()
1658 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1679 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1691 use_r1b_resp = mmc_prepare_busy_cmd(card->host, &cmd, busy_timeout); in mmc_do_erase()
1693 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1701 if (mmc_host_is_spi(card->host)) in mmc_do_erase()
1708 if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) in mmc_do_erase()
1715 mmc_retune_release(card->host); in mmc_do_erase()
1892 struct mmc_host *host = card->host; in mmc_do_calc_max_discard() local
1895 unsigned int max_busy_timeout = host->max_busy_timeout ? in mmc_do_calc_max_discard()
1896 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS; in mmc_do_calc_max_discard()
1969 struct mmc_host *host = card->host; in mmc_calc_max_discard() local
1989 mmc_hostname(host), max_discard, host->max_busy_timeout ? in mmc_calc_max_discard()
1990 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS); in mmc_calc_max_discard()
2012 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2016 static void mmc_hw_reset_for_init(struct mmc_host *host) in mmc_hw_reset_for_init() argument
2018 mmc_pwrseq_reset(host); in mmc_hw_reset_for_init()
2020 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->card_hw_reset) in mmc_hw_reset_for_init()
2022 host->ops->card_hw_reset(host); in mmc_hw_reset_for_init()
2037 struct mmc_host *host = card->host; in mmc_hw_reset() local
2040 ret = host->bus_ops->hw_reset(host); in mmc_hw_reset()
2043 mmc_hostname(host), ret); in mmc_hw_reset()
2051 struct mmc_host *host = card->host; in mmc_sw_reset() local
2054 if (!host->bus_ops->sw_reset) in mmc_sw_reset()
2057 ret = host->bus_ops->sw_reset(host); in mmc_sw_reset()
2060 mmc_hostname(host), ret); in mmc_sw_reset()
2066 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) in mmc_rescan_try_freq() argument
2068 host->f_init = freq; in mmc_rescan_try_freq()
2071 mmc_hostname(host), __func__, host->f_init); in mmc_rescan_try_freq()
2073 mmc_power_up(host, host->ocr_avail); in mmc_rescan_try_freq()
2079 mmc_hw_reset_for_init(host); in mmc_rescan_try_freq()
2087 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2088 sdio_reset(host); in mmc_rescan_try_freq()
2090 mmc_go_idle(host); in mmc_rescan_try_freq()
2092 if (!(host->caps2 & MMC_CAP2_NO_SD)) { in mmc_rescan_try_freq()
2093 if (mmc_send_if_cond_pcie(host, host->ocr_avail)) in mmc_rescan_try_freq()
2095 if (mmc_card_sd_express(host)) in mmc_rescan_try_freq()
2100 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2101 if (!mmc_attach_sdio(host)) in mmc_rescan_try_freq()
2104 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2105 if (!mmc_attach_sd(host)) in mmc_rescan_try_freq()
2108 if (!(host->caps2 & MMC_CAP2_NO_MMC)) in mmc_rescan_try_freq()
2109 if (!mmc_attach_mmc(host)) in mmc_rescan_try_freq()
2113 mmc_power_off(host); in mmc_rescan_try_freq()
2117 int _mmc_detect_card_removed(struct mmc_host *host) in _mmc_detect_card_removed() argument
2121 if (!host->card || mmc_card_removed(host->card)) in _mmc_detect_card_removed()
2124 ret = host->bus_ops->alive(host); in _mmc_detect_card_removed()
2133 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2134 mmc_detect_change(host, msecs_to_jiffies(200)); in _mmc_detect_card_removed()
2135 pr_debug("%s: card removed too slowly\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2139 mmc_card_set_removed(host->card); in _mmc_detect_card_removed()
2140 pr_debug("%s: card remove detected\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2146 int mmc_detect_card_removed(struct mmc_host *host) in mmc_detect_card_removed() argument
2148 struct mmc_card *card = host->card; in mmc_detect_card_removed()
2151 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2156 if (!mmc_card_is_removable(host)) in mmc_detect_card_removed()
2164 if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_detect_card_removed()
2167 host->detect_change = 0; in mmc_detect_card_removed()
2169 ret = _mmc_detect_card_removed(host); in mmc_detect_card_removed()
2170 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2175 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2176 _mmc_detect_change(host, 0, false); in mmc_detect_card_removed()
2188 if ((!(card->host->caps2 & MMC_CAP2_ALT_GPT_TEGRA))) in mmc_card_alternative_gpt_sector()
2195 mmc_card_is_removable(card->host)) in mmc_card_alternative_gpt_sector()
2221 struct mmc_host *host = in mmc_rescan() local
2225 if (host->rescan_disable) in mmc_rescan()
2229 if (!mmc_card_is_removable(host) && host->rescan_entered) in mmc_rescan()
2231 host->rescan_entered = 1; in mmc_rescan()
2233 if (host->trigger_card_event && host->ops->card_event) { in mmc_rescan()
2234 mmc_claim_host(host); in mmc_rescan()
2235 host->ops->card_event(host); in mmc_rescan()
2236 mmc_release_host(host); in mmc_rescan()
2237 host->trigger_card_event = false; in mmc_rescan()
2241 if (host->bus_ops) in mmc_rescan()
2242 host->bus_ops->detect(host); in mmc_rescan()
2244 host->detect_change = 0; in mmc_rescan()
2247 if (host->bus_ops != NULL) in mmc_rescan()
2250 mmc_claim_host(host); in mmc_rescan()
2251 if (mmc_card_is_removable(host) && host->ops->get_cd && in mmc_rescan()
2252 host->ops->get_cd(host) == 0) { in mmc_rescan()
2253 mmc_power_off(host); in mmc_rescan()
2254 mmc_release_host(host); in mmc_rescan()
2259 if (mmc_card_sd_express(host)) { in mmc_rescan()
2260 mmc_release_host(host); in mmc_rescan()
2271 if (!mmc_attach_sd_uhs2(host)) { in mmc_rescan()
2272 mmc_release_host(host); in mmc_rescan()
2278 if (freq > host->f_max) { in mmc_rescan()
2281 freq = host->f_max; in mmc_rescan()
2283 if (!mmc_rescan_try_freq(host, max(freq, host->f_min))) in mmc_rescan()
2285 if (freqs[i] <= host->f_min) in mmc_rescan()
2290 if (!mmc_card_is_removable(host) && !host->bus_ops) in mmc_rescan()
2292 mmc_hostname(host)); in mmc_rescan()
2298 host->err_stats[MMC_ERR_CMD_TIMEOUT] = 0; in mmc_rescan()
2299 mmc_release_host(host); in mmc_rescan()
2302 if (host->caps & MMC_CAP_NEEDS_POLL) in mmc_rescan()
2303 mmc_schedule_delayed_work(&host->detect, HZ); in mmc_rescan()
2306 void mmc_start_host(struct mmc_host *host) in mmc_start_host() argument
2308 bool power_up = !(host->caps2 & in mmc_start_host()
2311 host->f_init = max(min(freqs[0], host->f_max), host->f_min); in mmc_start_host()
2312 host->rescan_disable = 0; in mmc_start_host()
2315 mmc_claim_host(host); in mmc_start_host()
2316 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2317 mmc_release_host(host); in mmc_start_host()
2320 mmc_gpiod_request_cd_irq(host); in mmc_start_host()
2321 _mmc_detect_change(host, 0, false); in mmc_start_host()
2324 void __mmc_stop_host(struct mmc_host *host) in __mmc_stop_host() argument
2326 if (host->rescan_disable) in __mmc_stop_host()
2329 if (host->slot.cd_irq >= 0) { in __mmc_stop_host()
2330 mmc_gpio_set_cd_wake(host, false); in __mmc_stop_host()
2331 disable_irq(host->slot.cd_irq); in __mmc_stop_host()
2334 host->rescan_disable = 1; in __mmc_stop_host()
2335 cancel_delayed_work_sync(&host->detect); in __mmc_stop_host()
2338 void mmc_stop_host(struct mmc_host *host) in mmc_stop_host() argument
2340 __mmc_stop_host(host); in mmc_stop_host()
2343 host->pm_flags = 0; in mmc_stop_host()
2345 if (host->bus_ops) { in mmc_stop_host()
2347 host->bus_ops->remove(host); in mmc_stop_host()
2348 mmc_claim_host(host); in mmc_stop_host()
2349 mmc_detach_bus(host); in mmc_stop_host()
2350 mmc_power_off(host); in mmc_stop_host()
2351 mmc_release_host(host); in mmc_stop_host()
2355 mmc_claim_host(host); in mmc_stop_host()
2356 mmc_power_off(host); in mmc_stop_host()
2357 mmc_release_host(host); in mmc_stop_host()