Lines Matching refs:host

84 static void mmc_should_fail_request(struct mmc_host *host,  in mmc_should_fail_request()  argument
99 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) in mmc_should_fail_request()
108 static inline void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
121 void mmc_command_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_command_done() argument
129 mmc_hostname(host), mrq->cmd->opcode); in mmc_command_done()
141 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_request_done() argument
152 mmc_retune_needed(host); in mmc_request_done()
154 if (err && cmd->retries && mmc_host_is_spi(host)) { in mmc_request_done()
159 if (host->ongoing_mrq == mrq) in mmc_request_done()
160 host->ongoing_mrq = NULL; in mmc_request_done()
164 trace_mmc_request_done(host, mrq); in mmc_request_done()
175 if (!err || !cmd->retries || mmc_card_removed(host->card)) { in mmc_request_done()
176 mmc_should_fail_request(host, mrq); in mmc_request_done()
178 if (!host->ongoing_mrq) in mmc_request_done()
179 led_trigger_event(host->led, LED_OFF); in mmc_request_done()
183 mmc_hostname(host), mrq->sbc->opcode, in mmc_request_done()
190 mmc_hostname(host), cmd->opcode, err, in mmc_request_done()
196 mmc_hostname(host), in mmc_request_done()
202 mmc_hostname(host), mrq->stop->opcode, in mmc_request_done()
218 static void __mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_request() argument
223 err = mmc_retune(host); in __mmc_start_request()
226 mmc_request_done(host, mrq); in __mmc_start_request()
236 host->ops->card_busy) { in __mmc_start_request()
239 while (host->ops->card_busy(host) && --tries) in __mmc_start_request()
244 mmc_request_done(host, mrq); in __mmc_start_request()
250 host->ongoing_mrq = mrq; in __mmc_start_request()
258 trace_mmc_request_start(host, mrq); in __mmc_start_request()
260 if (host->cqe_on) in __mmc_start_request()
261 host->cqe_ops->cqe_off(host); in __mmc_start_request()
263 host->ops->request(host, mrq); in __mmc_start_request()
266 static void mmc_mrq_pr_debug(struct mmc_host *host, struct mmc_request *mrq, in mmc_mrq_pr_debug() argument
271 mmc_hostname(host), mrq->sbc->opcode, in mmc_mrq_pr_debug()
277 mmc_hostname(host), cqe ? "CQE direct " : "", in mmc_mrq_pr_debug()
281 mmc_hostname(host), mrq->tag, mrq->data->blk_addr); in mmc_mrq_pr_debug()
287 mmc_hostname(host), mrq->data->blksz, in mmc_mrq_pr_debug()
295 mmc_hostname(host), mrq->stop->opcode, in mmc_mrq_pr_debug()
300 static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq) in mmc_mrq_prep() argument
315 if (mrq->data->blksz > host->max_blk_size || in mmc_mrq_prep()
316 mrq->data->blocks > host->max_blk_count || in mmc_mrq_prep()
317 mrq->data->blocks * mrq->data->blksz > host->max_req_size) in mmc_mrq_prep()
337 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in mmc_start_request() argument
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 led_trigger_event(host->led, LED_FULL); in mmc_start_request()
357 __mmc_start_request(host, mrq); in mmc_start_request()
368 static inline void mmc_wait_ongoing_tfr_cmd(struct mmc_host *host) in mmc_wait_ongoing_tfr_cmd() argument
370 struct mmc_request *ongoing_mrq = READ_ONCE(host->ongoing_mrq); in mmc_wait_ongoing_tfr_cmd()
380 static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_req() argument
384 mmc_wait_ongoing_tfr_cmd(host); in __mmc_start_req()
389 err = mmc_start_request(host, mrq); in __mmc_start_req()
399 void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req_done() argument
415 if (!mmc_interrupt_hpi(host->card)) { in mmc_wait_for_req_done()
417 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
422 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
426 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
429 mmc_retune_recheck(host); in mmc_wait_for_req_done()
432 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
435 __mmc_start_request(host, mrq); in mmc_wait_for_req_done()
438 mmc_retune_release(host); in mmc_wait_for_req_done()
450 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_start_req() argument
460 err = mmc_retune(host); in mmc_cqe_start_req()
464 mrq->host = host; in mmc_cqe_start_req()
466 mmc_mrq_pr_debug(host, mrq, true); in mmc_cqe_start_req()
468 err = mmc_mrq_prep(host, mrq); in mmc_cqe_start_req()
472 err = host->cqe_ops->cqe_request(host, mrq); in mmc_cqe_start_req()
476 trace_mmc_request_start(host, mrq); in mmc_cqe_start_req()
483 mmc_hostname(host), mrq->cmd->opcode, err); in mmc_cqe_start_req()
486 mmc_hostname(host), mrq->tag, err); in mmc_cqe_start_req()
500 void mmc_cqe_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_request_done() argument
502 mmc_should_fail_request(host, mrq); in mmc_cqe_request_done()
507 mmc_retune_needed(host); in mmc_cqe_request_done()
509 trace_mmc_request_done(host, mrq); in mmc_cqe_request_done()
513 mmc_hostname(host), mrq->cmd->opcode, mrq->cmd->error); in mmc_cqe_request_done()
516 mmc_hostname(host), mrq->tag); in mmc_cqe_request_done()
521 mmc_hostname(host), in mmc_cqe_request_done()
534 void mmc_cqe_post_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_cqe_post_req() argument
536 if (host->cqe_ops->cqe_post_req) in mmc_cqe_post_req()
537 host->cqe_ops->cqe_post_req(host, mrq); in mmc_cqe_post_req()
553 int mmc_cqe_recovery(struct mmc_host *host) in mmc_cqe_recovery() argument
558 mmc_retune_hold_now(host); in mmc_cqe_recovery()
564 pr_warn("%s: running CQE recovery\n", mmc_hostname(host)); in mmc_cqe_recovery()
566 host->cqe_ops->cqe_recovery_start(host); in mmc_cqe_recovery()
573 mmc_wait_for_cmd(host, &cmd, 0); in mmc_cqe_recovery()
581 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_cqe_recovery()
583 host->cqe_ops->cqe_recovery_finish(host); in mmc_cqe_recovery()
585 mmc_retune_release(host); in mmc_cqe_recovery()
603 bool mmc_is_req_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_is_req_done() argument
621 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req() argument
623 __mmc_start_req(host, mrq); in mmc_wait_for_req()
626 mmc_wait_for_req_done(host, mrq); in mmc_wait_for_req()
640 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) in mmc_wait_for_cmd() argument
644 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
652 mmc_wait_for_req(host, &mrq); in mmc_wait_for_cmd()
702 if (card->host->ios.clock) in mmc_set_data_timeout()
704 (card->host->ios.clock / 1000); in mmc_set_data_timeout()
749 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
792 static inline bool mmc_ctx_matches(struct mmc_host *host, struct mmc_ctx *ctx, in mmc_ctx_matches() argument
795 return host->claimer == ctx || in mmc_ctx_matches()
796 (!ctx && task && host->claimer->task == task); in mmc_ctx_matches()
799 static inline void mmc_ctx_set_claimer(struct mmc_host *host, in mmc_ctx_set_claimer() argument
803 if (!host->claimer) { in mmc_ctx_set_claimer()
805 host->claimer = ctx; in mmc_ctx_set_claimer()
807 host->claimer = &host->default_ctx; in mmc_ctx_set_claimer()
810 host->claimer->task = task; in mmc_ctx_set_claimer()
825 int __mmc_claim_host(struct mmc_host *host, struct mmc_ctx *ctx, in __mmc_claim_host() argument
836 add_wait_queue(&host->wq, &wait); in __mmc_claim_host()
837 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
841 if (stop || !host->claimed || mmc_ctx_matches(host, ctx, task)) in __mmc_claim_host()
843 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
845 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
849 host->claimed = 1; in __mmc_claim_host()
850 mmc_ctx_set_claimer(host, ctx, task); in __mmc_claim_host()
851 host->claim_cnt += 1; in __mmc_claim_host()
852 if (host->claim_cnt == 1) in __mmc_claim_host()
855 wake_up(&host->wq); in __mmc_claim_host()
856 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
857 remove_wait_queue(&host->wq, &wait); in __mmc_claim_host()
860 pm_runtime_get_sync(mmc_dev(host)); in __mmc_claim_host()
873 void mmc_release_host(struct mmc_host *host) in mmc_release_host() argument
877 WARN_ON(!host->claimed); in mmc_release_host()
879 spin_lock_irqsave(&host->lock, flags); in mmc_release_host()
880 if (--host->claim_cnt) { in mmc_release_host()
882 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
884 host->claimed = 0; in mmc_release_host()
885 host->claimer->task = NULL; in mmc_release_host()
886 host->claimer = NULL; in mmc_release_host()
887 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
888 wake_up(&host->wq); in mmc_release_host()
889 pm_runtime_mark_last_busy(mmc_dev(host)); in mmc_release_host()
890 pm_runtime_put_autosuspend(mmc_dev(host)); in mmc_release_host()
902 __mmc_claim_host(card->host, ctx, NULL); in mmc_get_card()
912 struct mmc_host *host = card->host; in mmc_put_card() local
914 WARN_ON(ctx && host->claimer != ctx); in mmc_put_card()
916 mmc_release_host(host); in mmc_put_card()
926 static inline void mmc_set_ios(struct mmc_host *host) in mmc_set_ios() argument
928 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
932 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
936 host->ops->set_ios(host, ios); in mmc_set_ios()
942 void mmc_set_chip_select(struct mmc_host *host, int mode) in mmc_set_chip_select() argument
944 host->ios.chip_select = mode; in mmc_set_chip_select()
945 mmc_set_ios(host); in mmc_set_chip_select()
952 void mmc_set_clock(struct mmc_host *host, unsigned int hz) in mmc_set_clock() argument
954 WARN_ON(hz && hz < host->f_min); in mmc_set_clock()
956 if (hz > host->f_max) in mmc_set_clock()
957 hz = host->f_max; in mmc_set_clock()
959 host->ios.clock = hz; in mmc_set_clock()
960 mmc_set_ios(host); in mmc_set_clock()
965 struct mmc_host *host = card->host; in mmc_execute_tuning() local
969 if (!host->ops->execute_tuning) in mmc_execute_tuning()
972 if (host->cqe_on) in mmc_execute_tuning()
973 host->cqe_ops->cqe_off(host); in mmc_execute_tuning()
980 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
984 mmc_hostname(host), err); in mmc_execute_tuning()
986 mmc_retune_enable(host); in mmc_execute_tuning()
994 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) in mmc_set_bus_mode() argument
996 host->ios.bus_mode = mode; in mmc_set_bus_mode()
997 mmc_set_ios(host); in mmc_set_bus_mode()
1003 void mmc_set_bus_width(struct mmc_host *host, unsigned int width) in mmc_set_bus_width() argument
1005 host->ios.bus_width = width; in mmc_set_bus_width()
1006 mmc_set_ios(host); in mmc_set_bus_width()
1012 void mmc_set_initial_state(struct mmc_host *host) in mmc_set_initial_state() argument
1014 if (host->cqe_on) in mmc_set_initial_state()
1015 host->cqe_ops->cqe_off(host); in mmc_set_initial_state()
1017 mmc_retune_disable(host); in mmc_set_initial_state()
1019 if (mmc_host_is_spi(host)) in mmc_set_initial_state()
1020 host->ios.chip_select = MMC_CS_HIGH; in mmc_set_initial_state()
1022 host->ios.chip_select = MMC_CS_DONTCARE; in mmc_set_initial_state()
1023 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; in mmc_set_initial_state()
1024 host->ios.bus_width = MMC_BUS_WIDTH_1; in mmc_set_initial_state()
1025 host->ios.timing = MMC_TIMING_LEGACY; in mmc_set_initial_state()
1026 host->ios.drv_type = 0; in mmc_set_initial_state()
1027 host->ios.enhanced_strobe = false; in mmc_set_initial_state()
1033 if ((host->caps2 & MMC_CAP2_HS400_ES) && in mmc_set_initial_state()
1034 host->ops->hs400_enhanced_strobe) in mmc_set_initial_state()
1035 host->ops->hs400_enhanced_strobe(host, &host->ios); in mmc_set_initial_state()
1037 mmc_set_ios(host); in mmc_set_initial_state()
1174 struct device_node *mmc_of_find_child_device(struct mmc_host *host, in mmc_of_find_child_device() argument
1179 if (!host->parent || !host->parent->of_node) in mmc_of_find_child_device()
1182 for_each_child_of_node(host->parent->of_node, node) { in mmc_of_find_child_device()
1434 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) in mmc_select_voltage() argument
1443 dev_warn(mmc_dev(host), in mmc_select_voltage()
1448 ocr &= host->ocr_avail; in mmc_select_voltage()
1450 dev_warn(mmc_dev(host), "no support for card's volts\n"); in mmc_select_voltage()
1454 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { in mmc_select_voltage()
1457 mmc_power_cycle(host, ocr); in mmc_select_voltage()
1461 if (bit != host->ios.vdd) in mmc_select_voltage()
1462 dev_warn(mmc_dev(host), "exceeding card's volts\n"); in mmc_select_voltage()
1468 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) in mmc_set_signal_voltage() argument
1471 int old_signal_voltage = host->ios.signal_voltage; in mmc_set_signal_voltage()
1473 host->ios.signal_voltage = signal_voltage; in mmc_set_signal_voltage()
1474 if (host->ops->start_signal_voltage_switch) in mmc_set_signal_voltage()
1475 err = host->ops->start_signal_voltage_switch(host, &host->ios); in mmc_set_signal_voltage()
1478 host->ios.signal_voltage = old_signal_voltage; in mmc_set_signal_voltage()
1484 void mmc_set_initial_signal_voltage(struct mmc_host *host) in mmc_set_initial_signal_voltage() argument
1487 if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330)) in mmc_set_initial_signal_voltage()
1488 dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); in mmc_set_initial_signal_voltage()
1489 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_set_initial_signal_voltage()
1490 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); in mmc_set_initial_signal_voltage()
1491 else if (!mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120)) in mmc_set_initial_signal_voltage()
1492 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); in mmc_set_initial_signal_voltage()
1495 int mmc_host_set_uhs_voltage(struct mmc_host *host) in mmc_host_set_uhs_voltage() argument
1503 clock = host->ios.clock; in mmc_host_set_uhs_voltage()
1504 host->ios.clock = 0; in mmc_host_set_uhs_voltage()
1505 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1507 if (mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180)) in mmc_host_set_uhs_voltage()
1512 host->ios.clock = clock; in mmc_host_set_uhs_voltage()
1513 mmc_set_ios(host); in mmc_host_set_uhs_voltage()
1518 int mmc_set_uhs_voltage(struct mmc_host *host, u32 ocr) in mmc_set_uhs_voltage() argument
1527 if (!host->ops->start_signal_voltage_switch) in mmc_set_uhs_voltage()
1529 if (!host->ops->card_busy) in mmc_set_uhs_voltage()
1531 mmc_hostname(host)); in mmc_set_uhs_voltage()
1537 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_set_uhs_voltage()
1541 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) in mmc_set_uhs_voltage()
1549 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_uhs_voltage()
1554 if (mmc_host_set_uhs_voltage(host)) { in mmc_set_uhs_voltage()
1570 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_uhs_voltage()
1576 "power cycling card\n", mmc_hostname(host)); in mmc_set_uhs_voltage()
1577 mmc_power_cycle(host, ocr); in mmc_set_uhs_voltage()
1586 void mmc_set_timing(struct mmc_host *host, unsigned int timing) in mmc_set_timing() argument
1588 host->ios.timing = timing; in mmc_set_timing()
1589 mmc_set_ios(host); in mmc_set_timing()
1595 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) in mmc_set_driver_type() argument
1597 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1598 mmc_set_ios(host); in mmc_set_driver_type()
1604 struct mmc_host *host = card->host; in mmc_select_drive_strength() local
1609 if (!host->ops->select_drive_strength) in mmc_select_drive_strength()
1613 if (host->caps & MMC_CAP_DRIVER_TYPE_A) in mmc_select_drive_strength()
1616 if (host->caps & MMC_CAP_DRIVER_TYPE_C) in mmc_select_drive_strength()
1619 if (host->caps & MMC_CAP_DRIVER_TYPE_D) in mmc_select_drive_strength()
1628 return host->ops->select_drive_strength(card, max_dtr, in mmc_select_drive_strength()
1645 void mmc_power_up(struct mmc_host *host, u32 ocr) in mmc_power_up() argument
1647 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1650 mmc_pwrseq_pre_power_on(host); in mmc_power_up()
1652 host->ios.vdd = fls(ocr) - 1; in mmc_power_up()
1653 host->ios.power_mode = MMC_POWER_UP; in mmc_power_up()
1655 mmc_set_initial_state(host); in mmc_power_up()
1657 mmc_set_initial_signal_voltage(host); in mmc_power_up()
1663 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1665 mmc_pwrseq_post_power_on(host); in mmc_power_up()
1667 host->ios.clock = host->f_init; in mmc_power_up()
1669 host->ios.power_mode = MMC_POWER_ON; in mmc_power_up()
1670 mmc_set_ios(host); in mmc_power_up()
1676 mmc_delay(host->ios.power_delay_ms); in mmc_power_up()
1679 void mmc_power_off(struct mmc_host *host) in mmc_power_off() argument
1681 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1684 mmc_pwrseq_power_off(host); in mmc_power_off()
1686 host->ios.clock = 0; in mmc_power_off()
1687 host->ios.vdd = 0; in mmc_power_off()
1689 host->ios.power_mode = MMC_POWER_OFF; in mmc_power_off()
1691 mmc_set_initial_state(host); in mmc_power_off()
1701 void mmc_power_cycle(struct mmc_host *host, u32 ocr) in mmc_power_cycle() argument
1703 mmc_power_off(host); in mmc_power_cycle()
1706 mmc_power_up(host, ocr); in mmc_power_cycle()
1712 static void __mmc_release_bus(struct mmc_host *host) in __mmc_release_bus() argument
1714 WARN_ON(!host->bus_dead); in __mmc_release_bus()
1716 host->bus_ops = NULL; in __mmc_release_bus()
1722 static inline void mmc_bus_get(struct mmc_host *host) in mmc_bus_get() argument
1726 spin_lock_irqsave(&host->lock, flags); in mmc_bus_get()
1727 host->bus_refs++; in mmc_bus_get()
1728 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_get()
1735 static inline void mmc_bus_put(struct mmc_host *host) in mmc_bus_put() argument
1739 spin_lock_irqsave(&host->lock, flags); in mmc_bus_put()
1740 host->bus_refs--; in mmc_bus_put()
1741 if ((host->bus_refs == 0) && host->bus_ops) in mmc_bus_put()
1742 __mmc_release_bus(host); in mmc_bus_put()
1743 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_put()
1750 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) in mmc_attach_bus() argument
1754 WARN_ON(!host->claimed); in mmc_attach_bus()
1756 spin_lock_irqsave(&host->lock, flags); in mmc_attach_bus()
1758 WARN_ON(host->bus_ops); in mmc_attach_bus()
1759 WARN_ON(host->bus_refs); in mmc_attach_bus()
1761 host->bus_ops = ops; in mmc_attach_bus()
1762 host->bus_refs = 1; in mmc_attach_bus()
1763 host->bus_dead = 0; in mmc_attach_bus()
1765 spin_unlock_irqrestore(&host->lock, flags); in mmc_attach_bus()
1771 void mmc_detach_bus(struct mmc_host *host) in mmc_detach_bus() argument
1775 WARN_ON(!host->claimed); in mmc_detach_bus()
1776 WARN_ON(!host->bus_ops); in mmc_detach_bus()
1778 spin_lock_irqsave(&host->lock, flags); in mmc_detach_bus()
1780 host->bus_dead = 1; in mmc_detach_bus()
1782 spin_unlock_irqrestore(&host->lock, flags); in mmc_detach_bus()
1784 mmc_bus_put(host); in mmc_detach_bus()
1787 static void _mmc_detect_change(struct mmc_host *host, unsigned long delay, in _mmc_detect_change() argument
1794 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) && in _mmc_detect_change()
1795 device_can_wakeup(mmc_dev(host))) in _mmc_detect_change()
1796 pm_wakeup_event(mmc_dev(host), 5000); in _mmc_detect_change()
1798 host->detect_change = 1; in _mmc_detect_change()
1799 mmc_schedule_delayed_work(&host->detect, delay); in _mmc_detect_change()
1812 void mmc_detect_change(struct mmc_host *host, unsigned long delay) in mmc_detect_change() argument
1814 _mmc_detect_change(host, delay, true); in mmc_detect_change()
1898 (card->host->ios.clock / 1000); in mmc_mmc_erase_timeout()
1924 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
1975 mmc_retune_hold(card->host); in mmc_do_erase()
2013 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2028 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2046 if (card->host->max_busy_timeout && in mmc_do_erase()
2047 busy_timeout > card->host->max_busy_timeout) { in mmc_do_erase()
2055 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2063 if (mmc_host_is_spi(card->host)) in mmc_do_erase()
2070 if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) in mmc_do_erase()
2080 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2093 mmc_hostname(card->host), __func__); in mmc_do_erase()
2107 mmc_retune_release(card->host); in mmc_do_erase()
2174 if (!(card->host->caps & MMC_CAP_ERASE) || in mmc_erase()
2231 if ((card->host->caps & MMC_CAP_ERASE) && in mmc_can_erase()
2292 struct mmc_host *host = card->host; in mmc_do_calc_max_discard() local
2295 unsigned int max_busy_timeout = host->max_busy_timeout ? in mmc_do_calc_max_discard()
2296 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS; in mmc_do_calc_max_discard()
2369 struct mmc_host *host = card->host; in mmc_calc_max_discard() local
2389 mmc_hostname(host), max_discard, host->max_busy_timeout ? in mmc_calc_max_discard()
2390 host->max_busy_timeout : MMC_ERASE_TIMEOUT_MS); in mmc_calc_max_discard()
2412 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2426 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blockcount()
2430 static void mmc_hw_reset_for_init(struct mmc_host *host) in mmc_hw_reset_for_init() argument
2432 mmc_pwrseq_reset(host); in mmc_hw_reset_for_init()
2434 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset) in mmc_hw_reset_for_init()
2436 host->ops->hw_reset(host); in mmc_hw_reset_for_init()
2439 int mmc_hw_reset(struct mmc_host *host) in mmc_hw_reset() argument
2443 if (!host->card) in mmc_hw_reset()
2446 mmc_bus_get(host); in mmc_hw_reset()
2447 if (!host->bus_ops || host->bus_dead || !host->bus_ops->hw_reset) { in mmc_hw_reset()
2448 mmc_bus_put(host); in mmc_hw_reset()
2452 ret = host->bus_ops->hw_reset(host); in mmc_hw_reset()
2453 mmc_bus_put(host); in mmc_hw_reset()
2457 mmc_hostname(host), ret); in mmc_hw_reset()
2463 int mmc_sw_reset(struct mmc_host *host) in mmc_sw_reset() argument
2467 if (!host->card) in mmc_sw_reset()
2470 mmc_bus_get(host); in mmc_sw_reset()
2471 if (!host->bus_ops || host->bus_dead || !host->bus_ops->sw_reset) { in mmc_sw_reset()
2472 mmc_bus_put(host); in mmc_sw_reset()
2476 ret = host->bus_ops->sw_reset(host); in mmc_sw_reset()
2477 mmc_bus_put(host); in mmc_sw_reset()
2481 mmc_hostname(host), ret); in mmc_sw_reset()
2487 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) in mmc_rescan_try_freq() argument
2489 host->f_init = freq; in mmc_rescan_try_freq()
2492 mmc_hostname(host), __func__, host->f_init); in mmc_rescan_try_freq()
2494 mmc_power_up(host, host->ocr_avail); in mmc_rescan_try_freq()
2500 mmc_hw_reset_for_init(host); in mmc_rescan_try_freq()
2508 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2509 sdio_reset(host); in mmc_rescan_try_freq()
2511 mmc_go_idle(host); in mmc_rescan_try_freq()
2513 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2514 mmc_send_if_cond(host, host->ocr_avail); in mmc_rescan_try_freq()
2517 if (!(host->caps2 & MMC_CAP2_NO_SDIO)) in mmc_rescan_try_freq()
2518 if (!mmc_attach_sdio(host)) in mmc_rescan_try_freq()
2521 if (!(host->caps2 & MMC_CAP2_NO_SD)) in mmc_rescan_try_freq()
2522 if (!mmc_attach_sd(host)) in mmc_rescan_try_freq()
2525 if (!(host->caps2 & MMC_CAP2_NO_MMC)) in mmc_rescan_try_freq()
2526 if (!mmc_attach_mmc(host)) in mmc_rescan_try_freq()
2529 mmc_power_off(host); in mmc_rescan_try_freq()
2533 int _mmc_detect_card_removed(struct mmc_host *host) in _mmc_detect_card_removed() argument
2537 if (!host->card || mmc_card_removed(host->card)) in _mmc_detect_card_removed()
2540 ret = host->bus_ops->alive(host); in _mmc_detect_card_removed()
2549 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2550 mmc_detect_change(host, msecs_to_jiffies(200)); in _mmc_detect_card_removed()
2551 pr_debug("%s: card removed too slowly\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2555 mmc_card_set_removed(host->card); in _mmc_detect_card_removed()
2556 pr_debug("%s: card remove detected\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2562 int mmc_detect_card_removed(struct mmc_host *host) in mmc_detect_card_removed() argument
2564 struct mmc_card *card = host->card; in mmc_detect_card_removed()
2567 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2572 if (!mmc_card_is_removable(host)) in mmc_detect_card_removed()
2580 if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_detect_card_removed()
2583 host->detect_change = 0; in mmc_detect_card_removed()
2585 ret = _mmc_detect_card_removed(host); in mmc_detect_card_removed()
2586 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2591 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2592 _mmc_detect_change(host, 0, false); in mmc_detect_card_removed()
2602 struct mmc_host *host = in mmc_rescan() local
2606 if (host->rescan_disable) in mmc_rescan()
2610 if (!mmc_card_is_removable(host) && host->rescan_entered) in mmc_rescan()
2612 host->rescan_entered = 1; in mmc_rescan()
2614 if (host->trigger_card_event && host->ops->card_event) { in mmc_rescan()
2615 mmc_claim_host(host); in mmc_rescan()
2616 host->ops->card_event(host); in mmc_rescan()
2617 mmc_release_host(host); in mmc_rescan()
2618 host->trigger_card_event = false; in mmc_rescan()
2621 mmc_bus_get(host); in mmc_rescan()
2627 if (host->bus_ops && !host->bus_dead && mmc_card_is_removable(host)) in mmc_rescan()
2628 host->bus_ops->detect(host); in mmc_rescan()
2630 host->detect_change = 0; in mmc_rescan()
2636 mmc_bus_put(host); in mmc_rescan()
2637 mmc_bus_get(host); in mmc_rescan()
2640 if (host->bus_ops != NULL) { in mmc_rescan()
2641 mmc_bus_put(host); in mmc_rescan()
2649 mmc_bus_put(host); in mmc_rescan()
2651 mmc_claim_host(host); in mmc_rescan()
2652 if (mmc_card_is_removable(host) && host->ops->get_cd && in mmc_rescan()
2653 host->ops->get_cd(host) == 0) { in mmc_rescan()
2654 mmc_power_off(host); in mmc_rescan()
2655 mmc_release_host(host); in mmc_rescan()
2660 if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) in mmc_rescan()
2662 if (freqs[i] <= host->f_min) in mmc_rescan()
2665 mmc_release_host(host); in mmc_rescan()
2668 if (host->caps & MMC_CAP_NEEDS_POLL) in mmc_rescan()
2669 mmc_schedule_delayed_work(&host->detect, HZ); in mmc_rescan()
2672 void mmc_start_host(struct mmc_host *host) in mmc_start_host() argument
2674 host->f_init = max(freqs[0], host->f_min); in mmc_start_host()
2675 host->rescan_disable = 0; in mmc_start_host()
2676 host->ios.power_mode = MMC_POWER_UNDEFINED; in mmc_start_host()
2678 if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) { in mmc_start_host()
2679 mmc_claim_host(host); in mmc_start_host()
2680 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2681 mmc_release_host(host); in mmc_start_host()
2684 mmc_gpiod_request_cd_irq(host); in mmc_start_host()
2685 _mmc_detect_change(host, 0, false); in mmc_start_host()
2688 void mmc_stop_host(struct mmc_host *host) in mmc_stop_host() argument
2690 if (host->slot.cd_irq >= 0) { in mmc_stop_host()
2691 mmc_gpio_set_cd_wake(host, false); in mmc_stop_host()
2692 disable_irq(host->slot.cd_irq); in mmc_stop_host()
2695 host->rescan_disable = 1; in mmc_stop_host()
2696 cancel_delayed_work_sync(&host->detect); in mmc_stop_host()
2699 host->pm_flags = 0; in mmc_stop_host()
2701 mmc_bus_get(host); in mmc_stop_host()
2702 if (host->bus_ops && !host->bus_dead) { in mmc_stop_host()
2704 host->bus_ops->remove(host); in mmc_stop_host()
2705 mmc_claim_host(host); in mmc_stop_host()
2706 mmc_detach_bus(host); in mmc_stop_host()
2707 mmc_power_off(host); in mmc_stop_host()
2708 mmc_release_host(host); in mmc_stop_host()
2709 mmc_bus_put(host); in mmc_stop_host()
2712 mmc_bus_put(host); in mmc_stop_host()
2714 mmc_claim_host(host); in mmc_stop_host()
2715 mmc_power_off(host); in mmc_stop_host()
2716 mmc_release_host(host); in mmc_stop_host()
2727 struct mmc_host *host = container_of( in mmc_pm_notify() local
2736 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2737 host->rescan_disable = 1; in mmc_pm_notify()
2738 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2739 cancel_delayed_work_sync(&host->detect); in mmc_pm_notify()
2741 if (!host->bus_ops) in mmc_pm_notify()
2745 if (host->bus_ops->pre_suspend) in mmc_pm_notify()
2746 err = host->bus_ops->pre_suspend(host); in mmc_pm_notify()
2750 if (!mmc_card_is_removable(host)) { in mmc_pm_notify()
2751 dev_warn(mmc_dev(host), in mmc_pm_notify()
2759 host->bus_ops->remove(host); in mmc_pm_notify()
2760 mmc_claim_host(host); in mmc_pm_notify()
2761 mmc_detach_bus(host); in mmc_pm_notify()
2762 mmc_power_off(host); in mmc_pm_notify()
2763 mmc_release_host(host); in mmc_pm_notify()
2764 host->pm_flags = 0; in mmc_pm_notify()
2771 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2772 host->rescan_disable = 0; in mmc_pm_notify()
2773 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2774 _mmc_detect_change(host, 0, false); in mmc_pm_notify()
2781 void mmc_register_pm_notifier(struct mmc_host *host) in mmc_register_pm_notifier() argument
2783 host->pm_notify.notifier_call = mmc_pm_notify; in mmc_register_pm_notifier()
2784 register_pm_notifier(&host->pm_notify); in mmc_register_pm_notifier()
2787 void mmc_unregister_pm_notifier(struct mmc_host *host) in mmc_unregister_pm_notifier() argument
2789 unregister_pm_notifier(&host->pm_notify); in mmc_unregister_pm_notifier()