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
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
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
413 if (!mmc_interrupt_hpi(host->card)) { in mmc_wait_for_req_done()
415 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
420 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
424 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
427 mmc_retune_recheck(host); in mmc_wait_for_req_done()
430 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
433 __mmc_start_request(host, mrq); in mmc_wait_for_req_done()
436 mmc_retune_release(host); in mmc_wait_for_req_done()
448 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_start_req() argument
458 err = mmc_retune(host); in mmc_cqe_start_req()
462 mrq->host = host; in mmc_cqe_start_req()
464 mmc_mrq_pr_debug(host, mrq, true); in mmc_cqe_start_req()
466 err = mmc_mrq_prep(host, mrq); in mmc_cqe_start_req()
470 err = host->cqe_ops->cqe_request(host, mrq); in mmc_cqe_start_req()
474 trace_mmc_request_start(host, mrq); in mmc_cqe_start_req()
481 mmc_hostname(host), mrq->cmd->opcode, err); in mmc_cqe_start_req()
484 mmc_hostname(host), mrq->tag, err); in mmc_cqe_start_req()
498 void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_request_done() argument
500 mmc_should_fail_request(host, mrq); in mmc_cqe_request_done()
505 mmc_retune_needed(host); in mmc_cqe_request_done()
507 trace_mmc_request_done(host, mrq); in mmc_cqe_request_done()
511 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->error); in mmc_cqe_request_done()
514 mmc_hostname(host), mrq->tag); in mmc_cqe_request_done()
519 mmc_hostname(host), in mmc_cqe_request_done()
532 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_post_req() argument
534 if (host->cqe_ops->cqe_post_req) in mmc_cqe_post_req()
535 host->cqe_ops->cqe_post_req(host, mrq); in mmc_cqe_post_req()
551 int mmc_cqe_recovery(struct mmc_host *host) in mmc_cqe_recovery() argument
556 mmc_retune_hold_now(host); in mmc_cqe_recovery()
562 pr_warn("%s: running CQE recovery\n", mmc_hostname(host)); in mmc_cqe_recovery()
564 host->cqe_ops->cqe_recovery_start(host); in mmc_cqe_recovery()
571 mmc_wait_for_cmd(host, &cmd, 0); in mmc_cqe_recovery()
579 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_cqe_recovery()
581 host->cqe_ops->cqe_recovery_finish(host); in mmc_cqe_recovery()
583 mmc_retune_release(host); in mmc_cqe_recovery()
601 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_is_req_done() argument
619 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req() argument
621 __mmc_start_req(host, mrq); in mmc_wait_for_req()
624 mmc_wait_for_req_done(host, mrq); in mmc_wait_for_req()
638 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) in mmc_wait_for_cmd() argument
642 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
650 mmc_wait_for_req(host, &mrq); in mmc_wait_for_cmd()
700 if (card->host->ios.clock) in mmc_set_data_timeout()
702 (card->host->ios.clock / 1000); in mmc_set_data_timeout()
747 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
763 static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx, in mmc_ctx_matches() argument
766 return host->claimer == ctx || in mmc_ctx_matches()
767 (!ctx && task && host->claimer->task == task); in mmc_ctx_matches()
770 static inline void mmc_ctx_set_claimer(struct mmc_host *host, in mmc_ctx_set_claimer() argument
774 if (!host->claimer) { in mmc_ctx_set_claimer()
776 host->claimer = ctx; in mmc_ctx_set_claimer()
778 host->claimer = &host->default_ctx; in mmc_ctx_set_claimer()
781 host->claimer->task = task; in mmc_ctx_set_claimer()
796 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx, in __mmc_claim_host() argument
807 add_wait_queue(&host->wq, &wait); in __mmc_claim_host()
808 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
812 if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task)) in __mmc_claim_host()
814 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
816 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
820 host->claimed = 1; in __mmc_claim_host()
821 mmc_ctx_set_claimer(host, ctx, task); in __mmc_claim_host()
822 host->claim_cnt += 1; in __mmc_claim_host()
823 if (host->claim_cnt == 1) in __mmc_claim_host()
826 wake_up(&host->wq); in __mmc_claim_host()
827 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
828 remove_wait_queue(&host->wq, &wait); in __mmc_claim_host()
831 pm_runtime_get_sync(mmc_dev(host)); in __mmc_claim_host()
844 void mmc_release_host(struct mmc_host *host) in mmc_release_host() argument
848 WARN_ON(!host->claimed); in mmc_release_host()
850 spin_lock_irqsave(&host->lock, flags); in mmc_release_host()
851 if (--host->claim_cnt) { in mmc_release_host()
853 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
855 host->claimed = 0; in mmc_release_host()
856 host->claimer->task = NULL; in mmc_release_host()
857 host->claimer = NULL; in mmc_release_host()
858 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
859 wake_up(&host->wq); in mmc_release_host()
860 pm_runtime_mark_last_busy(mmc_dev(host)); in mmc_release_host()
861 if (host->caps & MMC_CAP_SYNC_RUNTIME_PM) in mmc_release_host()
862 pm_runtime_put_sync_suspend(mmc_dev(host)); in mmc_release_host()
864 pm_runtime_put_autosuspend(mmc_dev(host)); in mmc_release_host()
876 __mmc_claim_host(card->host, ctx, NULL); in mmc_get_card()
886 struct mmc_host *host = card->host; in mmc_put_card() local
888 WARN_ON(ctx && host->claimer != ctx); in mmc_put_card()
890 mmc_release_host(host); in mmc_put_card()
900 static inline void mmc_set_ios(struct mmc_host *host) in mmc_set_ios() argument
902 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
906 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
910 host->ops->set_ios(host, ios); in mmc_set_ios()
916 void mmc_set_chip_select(struct mmc_host *host, int mode) in mmc_set_chip_select() argument
918 host->ios.chip_select = mode; in mmc_set_chip_select()
919 mmc_set_ios(host); in mmc_set_chip_select()
926 void mmc_set_clock(struct mmc_host *host, unsigned int hz) in mmc_set_clock() argument
928 WARN_ON(hz && hz < host->f_min); in mmc_set_clock()
930 if (hz > host->f_max) in mmc_set_clock()
931 hz = host->f_max; in mmc_set_clock()
933 host->ios.clock = hz; in mmc_set_clock()
934 mmc_set_ios(host); in mmc_set_clock()
939 struct mmc_host *host = card->host; in mmc_execute_tuning() local
943 if (!host->ops->execute_tuning) in mmc_execute_tuning()
946 if (host->cqe_on) in mmc_execute_tuning()
947 host->cqe_ops->cqe_off(host); in mmc_execute_tuning()
954 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
958 mmc_hostname(host), err); in mmc_execute_tuning()
960 mmc_retune_enable(host); in mmc_execute_tuning()
968 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) in mmc_set_bus_mode() argument
970 host->ios.bus_mode = mode; in mmc_set_bus_mode()
971 mmc_set_ios(host); in mmc_set_bus_mode()
977 void mmc_set_bus_width(struct mmc_host *host, unsigned int width) in mmc_set_bus_width() argument
979 host->ios.bus_width = width; in mmc_set_bus_width()
980 mmc_set_ios(host); in mmc_set_bus_width()
986 void mmc_set_initial_state(struct mmc_host *host) in mmc_set_initial_state() argument
988 if (host->cqe_on) in mmc_set_initial_state()
989 host->cqe_ops->cqe_off(host); in mmc_set_initial_state()
991 mmc_retune_disable(host); in mmc_set_initial_state()
993 if (mmc_host_is_spi(host)) in mmc_set_initial_state()
994 host->ios.chip_select = MMC_CS_HIGH; in mmc_set_initial_state()
996 host->ios.chip_select = MMC_CS_DONTCARE; in mmc_set_initial_state()
997 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; in mmc_set_initial_state()
998 host->ios.bus_width = MMC_BUS_WIDTH_1; in mmc_set_initial_state()
999 host->ios.timing = MMC_TIMING_LEGACY; in mmc_set_initial_state()
1000 host->ios.drv_type = 0; in mmc_set_initial_state()
1001 host->ios.enhanced_strobe = false; in mmc_set_initial_state()
1007 if ((host->caps2 & MMC_CAP2_HS400_ES) && in mmc_set_initial_state()
1008 host->ops->hs400_enhanced_strobe) in mmc_set_initial_state()
1009 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_set_initial_state()
1011 mmc_set_ios(host); in mmc_set_initial_state()
1099 struct device_node *mmc_of_find_child_device(struct mmc_host *host, in mmc_of_find_child_device() argument
1104 if (!host->parent || !host->parent->of_node) in mmc_of_find_child_device()
1107 for_each_child_of_node(host->parent->of_node, node) { in mmc_of_find_child_device()
1119 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) in mmc_select_voltage() argument
1128 dev_warn(mmc_dev(host), in mmc_select_voltage()
1133 ocr &= host->ocr_avail; in mmc_select_voltage()
1135 dev_warn(mmc_dev(host), "no support for card's volts\n"); in mmc_select_voltage()
1139 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { in mmc_select_voltage()
1142 mmc_power_cycle(host, ocr); in mmc_select_voltage()
1146 if (bit != host->ios.vdd) in mmc_select_voltage()
1147 dev_warn(mmc_dev(host), "exceeding card's volts\n"); in mmc_select_voltage()
1153 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) in mmc_set_signal_voltage() argument
1156 int old_signal_voltage = host->ios.signal_voltage; in mmc_set_signal_voltage()
1158 host->ios.signal_voltage = signal_voltage; in mmc_set_signal_voltage()
1159 if (host->ops->start_signal_voltage_switch) in mmc_set_signal_voltage()
1160 err = host->ops->start_signal_voltage_switch(host, &host->ios); in mmc_set_signal_voltage()
1163 host->ios.signal_voltage = old_signal_voltage; in mmc_set_signal_voltage()
1169 void mmc_set_initial_signal_voltage(struct mmc_host *host) in mmc_set_initial_signal_voltage() argument
1172 if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) in mmc_set_initial_signal_voltage()
1173 dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); in mmc_set_initial_signal_voltage()
1174 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_set_initial_signal_voltage()
1175 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); in mmc_set_initial_signal_voltage()
1176 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) in mmc_set_initial_signal_voltage()
1177 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); in mmc_set_initial_signal_voltage()
1180 int mmc_host_set_uhs_voltage(struct mmc_host *host) in mmc_host_set_uhs_voltage() argument
1188 clock = host->ios.clock; in mmc_host_set_uhs_voltage()
1189 host->ios.clock = 0; in mmc_host_set_uhs_voltage()
1190 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1192 if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_host_set_uhs_voltage()
1197 host->ios.clock = clock; in mmc_host_set_uhs_voltage()
1198 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1203 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr) in mmc_set_uhs_voltage() argument
1212 if (!host->ops->start_signal_voltage_switch) in mmc_set_uhs_voltage()
1214 if (!host->ops->card_busy) in mmc_set_uhs_voltage()
1216 mmc_hostname(host)); in mmc_set_uhs_voltage()
1222 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_set_uhs_voltage()
1226 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) in mmc_set_uhs_voltage()
1234 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_uhs_voltage()
1239 if (mmc_host_set_uhs_voltage(host)) { in mmc_set_uhs_voltage()
1255 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_uhs_voltage()
1261 "power cycling card\n", mmc_hostname(host)); in mmc_set_uhs_voltage()
1262 mmc_power_cycle(host, ocr); in mmc_set_uhs_voltage()
1271 void mmc_set_timing(struct mmc_host *host, unsigned int timing) in mmc_set_timing() argument
1273 host->ios.timing = timing; in mmc_set_timing()
1274 mmc_set_ios(host); in mmc_set_timing()
1280 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) in mmc_set_driver_type() argument
1282 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1283 mmc_set_ios(host); in mmc_set_driver_type()
1289 struct mmc_host *host = card->host; in mmc_select_drive_strength() local
1294 if (!host->ops->select_drive_strength) in mmc_select_drive_strength()
1298 if (host->caps & MMC_CAP_DRIVER_TYPE_A) in mmc_select_drive_strength()
1301 if (host->caps & MMC_CAP_DRIVER_TYPE_C) in mmc_select_drive_strength()
1304 if (host->caps & MMC_CAP_DRIVER_TYPE_D) in mmc_select_drive_strength()
1313 return host->ops->select_drive_strength(card, max_dtr, in mmc_select_drive_strength()
1330 void mmc_power_up(struct mmc_host *host, u32 ocr) in mmc_power_up() argument
1332 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1335 mmc_pwrseq_pre_power_on(host); in mmc_power_up()
1337 host->ios.vdd = fls(ocr) - 1; in mmc_power_up()
1338 host->ios.power_mode = MMC_POWER_UP; in mmc_power_up()
1340 mmc_set_initial_state(host); in mmc_power_up()
1342 mmc_set_initial_signal_voltage(host); in mmc_power_up()
1348 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1350 mmc_pwrseq_post_power_on(host); in mmc_power_up()
1352 host->ios.clock = host->f_init; in mmc_power_up()
1354 host->ios.power_mode = MMC_POWER_ON; in mmc_power_up()
1355 mmc_set_ios(host); in mmc_power_up()
1361 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1364 void mmc_power_off(struct mmc_host *host) in mmc_power_off() argument
1366 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1369 mmc_pwrseq_power_off(host); in mmc_power_off()
1371 host->ios.clock = 0; in mmc_power_off()
1372 host->ios.vdd = 0; in mmc_power_off()
1374 host->ios.power_mode = MMC_POWER_OFF; in mmc_power_off()
1376 mmc_set_initial_state(host); in mmc_power_off()
1386 void mmc_power_cycle(struct mmc_host *host, u32 ocr) in mmc_power_cycle() argument
1388 mmc_power_off(host); in mmc_power_cycle()
1391 mmc_power_up(host, ocr); in mmc_power_cycle()
1397 static void __mmc_release_bus(struct mmc_host *host) in __mmc_release_bus() argument
1399 WARN_ON(!host->bus_dead); in __mmc_release_bus()
1401 host->bus_ops = NULL; in __mmc_release_bus()
1407 static inline void mmc_bus_get(struct mmc_host *host) in mmc_bus_get() argument
1411 spin_lock_irqsave(&host->lock, flags); in mmc_bus_get()
1412 host->bus_refs++; in mmc_bus_get()
1413 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_get()
1420 static inline void mmc_bus_put(struct mmc_host *host) in mmc_bus_put() argument
1424 spin_lock_irqsave(&host->lock, flags); in mmc_bus_put()
1425 host->bus_refs--; in mmc_bus_put()
1426 if ((host->bus_refs == 0) && host->bus_ops) in mmc_bus_put()
1427 __mmc_release_bus(host); in mmc_bus_put()
1428 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_put()
1435 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) in mmc_attach_bus() argument
1439 WARN_ON(!host->claimed); in mmc_attach_bus()
1441 spin_lock_irqsave(&host->lock, flags); in mmc_attach_bus()
1443 WARN_ON(host->bus_ops); in mmc_attach_bus()
1444 WARN_ON(host->bus_refs); in mmc_attach_bus()
1446 host->bus_ops = ops; in mmc_attach_bus()
1447 host->bus_refs = 1; in mmc_attach_bus()
1448 host->bus_dead = 0; in mmc_attach_bus()
1450 spin_unlock_irqrestore(&host->lock, flags); in mmc_attach_bus()
1456 void mmc_detach_bus(struct mmc_host *host) in mmc_detach_bus() argument
1460 WARN_ON(!host->claimed); in mmc_detach_bus()
1461 WARN_ON(!host->bus_ops); in mmc_detach_bus()
1463 spin_lock_irqsave(&host->lock, flags); in mmc_detach_bus()
1465 host->bus_dead = 1; in mmc_detach_bus()
1467 spin_unlock_irqrestore(&host->lock, flags); in mmc_detach_bus()
1469 mmc_bus_put(host); in mmc_detach_bus()
1472 static void _mmc_detect_change(struct mmc_host *host, unsigned long delay, in _mmc_detect_change() argument
1479 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) && in _mmc_detect_change()
1480 device_can_wakeup(mmc_dev(host))) in _mmc_detect_change()
1481 pm_wakeup_event(mmc_dev(host), 5000); in _mmc_detect_change()
1483 host->detect_change = 1; in _mmc_detect_change()
1484 mmc_schedule_delayed_work(&host->detect, delay); in _mmc_detect_change()
1497 void mmc_detect_change(struct mmc_host *host, unsigned long delay) in mmc_detect_change() argument
1499 _mmc_detect_change(host, delay, true); in mmc_detect_change()
1583 (card->host->ios.clock / 1000); in mmc_mmc_erase_timeout()
1609 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
1666 mmc_retune_hold(card->host); in mmc_do_erase()
1704 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1719 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1737 if (card->host->max_busy_timeout && in mmc_do_erase()
1738 busy_timeout > card->host->max_busy_timeout) { in mmc_do_erase()
1746 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1754 if (mmc_host_is_spi(card->host)) in mmc_do_erase()
1761 if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) in mmc_do_erase()
1771 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
1784 mmc_hostname(card->host), __func__); in mmc_do_erase()
1798 mmc_retune_release(card->host); in mmc_do_erase()
1865 if (!(card->host->caps & MMC_CAP_ERASE) || in mmc_erase()
1922 if ((card->host->caps & MMC_CAP_ERASE) && in mmc_can_erase()
1983 struct mmc_host *host = card->host; in mmc_do_calc_max_discard() local
1986 unsigned int max_busy_timeout = host->max_busy_timeout ? in mmc_do_calc_max_discard()
1987 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS; in mmc_do_calc_max_discard()
2060 struct mmc_host *host = card->host; in mmc_calc_max_discard() local
2080 mmc_hostname(host), max_discard, host->max_busy_timeout ? in mmc_calc_max_discard()
2081 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS); in mmc_calc_max_discard()
2103 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2107 static void mmc_hw_reset_for_init(struct mmc_host *host) in mmc_hw_reset_for_init() argument
2109 mmc_pwrseq_reset(host); in mmc_hw_reset_for_init()
2111 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset) in mmc_hw_reset_for_init()
2113 host->ops->hw_reset(host); in mmc_hw_reset_for_init()
2116 int mmc_hw_reset(struct mmc_host *host) in mmc_hw_reset() argument
2120 if (!host->card) in mmc_hw_reset()
2123 mmc_bus_get(host); in mmc_hw_reset()
2124 if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { in mmc_hw_reset()
2125 mmc_bus_put(host); in mmc_hw_reset()
2129 ret = host->bus_ops->hw_reset(host); in mmc_hw_reset()
2130 mmc_bus_put(host); in mmc_hw_reset()
2134 mmc_hostname(host), ret); in mmc_hw_reset()
2140 int mmc_sw_reset(struct mmc_host *host) in mmc_sw_reset() argument
2144 if (!host->card) in mmc_sw_reset()
2147 mmc_bus_get(host); in mmc_sw_reset()
2148 if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { in mmc_sw_reset()
2149 mmc_bus_put(host); in mmc_sw_reset()
2153 ret = host->bus_ops->sw_reset(host); in mmc_sw_reset()
2154 mmc_bus_put(host); in mmc_sw_reset()
2158 mmc_hostname(host), ret); in mmc_sw_reset()
2164 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) in mmc_rescan_try_freq() argument
2166 host->f_init = freq; in mmc_rescan_try_freq()
2169 mmc_hostname(host), __func__, host->f_init); in mmc_rescan_try_freq()
2171 mmc_power_up(host, host->ocr_avail); in mmc_rescan_try_freq()
2177 mmc_hw_reset_for_init(host); in mmc_rescan_try_freq()
2185 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2186 sdio_reset(host); in mmc_rescan_try_freq()
2188 mmc_go_idle(host); in mmc_rescan_try_freq()
2190 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2191 mmc_send_if_cond(host, host->ocr_avail); in mmc_rescan_try_freq()
2194 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2195 if (!mmc_attach_sdio(host)) in mmc_rescan_try_freq()
2198 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2199 if (!mmc_attach_sd(host)) in mmc_rescan_try_freq()
2202 if (!(host->caps2 & MMC_CAP2_NO_MMC)) in mmc_rescan_try_freq()
2203 if (!mmc_attach_mmc(host)) in mmc_rescan_try_freq()
2206 mmc_power_off(host); in mmc_rescan_try_freq()
2210 int _mmc_detect_card_removed(struct mmc_host *host) in _mmc_detect_card_removed() argument
2214 if (!host->card || mmc_card_removed(host->card)) in _mmc_detect_card_removed()
2217 ret = host->bus_ops->alive(host); in _mmc_detect_card_removed()
2226 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2227 mmc_detect_change(host, msecs_to_jiffies(200)); in _mmc_detect_card_removed()
2228 pr_debug("%s: card removed too slowly\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2232 mmc_card_set_removed(host->card); in _mmc_detect_card_removed()
2233 pr_debug("%s: card remove detected\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2239 int mmc_detect_card_removed(struct mmc_host *host) in mmc_detect_card_removed() argument
2241 struct mmc_card *card = host->card; in mmc_detect_card_removed()
2244 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2249 if (!mmc_card_is_removable(host)) in mmc_detect_card_removed()
2257 if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_detect_card_removed()
2260 host->detect_change = 0; in mmc_detect_card_removed()
2262 ret = _mmc_detect_card_removed(host); in mmc_detect_card_removed()
2263 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2268 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2269 _mmc_detect_change(host, 0, false); in mmc_detect_card_removed()
2279 struct mmc_host *host = in mmc_rescan() local
2283 if (host->rescan_disable) in mmc_rescan()
2287 if (!mmc_card_is_removable(host) && host->rescan_entered) in mmc_rescan()
2289 host->rescan_entered = 1; in mmc_rescan()
2291 if (host->trigger_card_event && host->ops->card_event) { in mmc_rescan()
2292 mmc_claim_host(host); in mmc_rescan()
2293 host->ops->card_event(host); in mmc_rescan()
2294 mmc_release_host(host); in mmc_rescan()
2295 host->trigger_card_event = false; in mmc_rescan()
2298 mmc_bus_get(host); in mmc_rescan()
2304 if (host->bus_ops && !host->bus_dead && mmc_card_is_removable(host)) in mmc_rescan()
2305 host->bus_ops->detect(host); in mmc_rescan()
2307 host->detect_change = 0; in mmc_rescan()
2313 mmc_bus_put(host); in mmc_rescan()
2314 mmc_bus_get(host); in mmc_rescan()
2317 if (host->bus_ops != NULL) { in mmc_rescan()
2318 mmc_bus_put(host); in mmc_rescan()
2326 mmc_bus_put(host); in mmc_rescan()
2328 mmc_claim_host(host); in mmc_rescan()
2329 if (mmc_card_is_removable(host) && host->ops->get_cd && in mmc_rescan()
2330 host->ops->get_cd(host) == 0) { in mmc_rescan()
2331 mmc_power_off(host); in mmc_rescan()
2332 mmc_release_host(host); in mmc_rescan()
2337 if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) in mmc_rescan()
2339 if (freqs[i] <= host->f_min) in mmc_rescan()
2342 mmc_release_host(host); in mmc_rescan()
2345 if (host->caps & MMC_CAP_NEEDS_POLL) in mmc_rescan()
2346 mmc_schedule_delayed_work(&host->detect, HZ); in mmc_rescan()
2349 void mmc_start_host(struct mmc_host *host) in mmc_start_host() argument
2351 host->f_init = max(freqs[0], host->f_min); in mmc_start_host()
2352 host->rescan_disable = 0; in mmc_start_host()
2353 host->ios.power_mode = MMC_POWER_UNDEFINED; in mmc_start_host()
2355 if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) { in mmc_start_host()
2356 mmc_claim_host(host); in mmc_start_host()
2357 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2358 mmc_release_host(host); in mmc_start_host()
2361 mmc_gpiod_request_cd_irq(host); in mmc_start_host()
2362 _mmc_detect_change(host, 0, false); in mmc_start_host()
2365 void mmc_stop_host(struct mmc_host *host) in mmc_stop_host() argument
2367 if (host->slot.cd_irq >= 0) { in mmc_stop_host()
2368 mmc_gpio_set_cd_wake(host, false); in mmc_stop_host()
2369 disable_irq(host->slot.cd_irq); in mmc_stop_host()
2372 host->rescan_disable = 1; in mmc_stop_host()
2373 cancel_delayed_work_sync(&host->detect); in mmc_stop_host()
2376 host->pm_flags = 0; in mmc_stop_host()
2378 mmc_bus_get(host); in mmc_stop_host()
2379 if (host->bus_ops && !host->bus_dead) { in mmc_stop_host()
2381 host->bus_ops->remove(host); in mmc_stop_host()
2382 mmc_claim_host(host); in mmc_stop_host()
2383 mmc_detach_bus(host); in mmc_stop_host()
2384 mmc_power_off(host); in mmc_stop_host()
2385 mmc_release_host(host); in mmc_stop_host()
2386 mmc_bus_put(host); in mmc_stop_host()
2389 mmc_bus_put(host); in mmc_stop_host()
2391 mmc_claim_host(host); in mmc_stop_host()
2392 mmc_power_off(host); in mmc_stop_host()
2393 mmc_release_host(host); in mmc_stop_host()
2404 struct mmc_host *host = container_of( in mmc_pm_notify() local
2413 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2414 host->rescan_disable = 1; in mmc_pm_notify()
2415 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2416 cancel_delayed_work_sync(&host->detect); in mmc_pm_notify()
2418 if (!host->bus_ops) in mmc_pm_notify()
2422 if (host->bus_ops->pre_suspend) in mmc_pm_notify()
2423 err = host->bus_ops->pre_suspend(host); in mmc_pm_notify()
2427 if (!mmc_card_is_removable(host)) { in mmc_pm_notify()
2428 dev_warn(mmc_dev(host), in mmc_pm_notify()
2436 host->bus_ops->remove(host); in mmc_pm_notify()
2437 mmc_claim_host(host); in mmc_pm_notify()
2438 mmc_detach_bus(host); in mmc_pm_notify()
2439 mmc_power_off(host); in mmc_pm_notify()
2440 mmc_release_host(host); in mmc_pm_notify()
2441 host->pm_flags = 0; in mmc_pm_notify()
2448 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2449 host->rescan_disable = 0; in mmc_pm_notify()
2450 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2451 _mmc_detect_change(host, 0, false); in mmc_pm_notify()
2458 void mmc_register_pm_notifier(struct mmc_host *host) in mmc_register_pm_notifier() argument
2460 host->pm_notify.notifier_call = mmc_pm_notify; in mmc_register_pm_notifier()
2461 register_pm_notifier(&host->pm_notify); in mmc_register_pm_notifier()
2464 void mmc_unregister_pm_notifier(struct mmc_host *host) in mmc_unregister_pm_notifier() argument
2466 unregister_pm_notifier(&host->pm_notify); in mmc_unregister_pm_notifier()