Lines Matching refs:host
92 static void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
107 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) in mmc_should_fail_request()
116 static inline void mmc_should_fail_request(struct mmc_host *host, in mmc_should_fail_request() argument
131 void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq) in mmc_request_done() argument
136 if (err && cmd->retries && mmc_host_is_spi(host)) { in mmc_request_done()
141 if (err && cmd->retries && !mmc_card_removed(host->card)) { in mmc_request_done()
149 mmc_should_fail_request(host, mrq); in mmc_request_done()
151 led_trigger_event(host->led, LED_OFF); in mmc_request_done()
155 mmc_hostname(host), mrq->sbc->opcode, in mmc_request_done()
162 mmc_hostname(host), cmd->opcode, err, in mmc_request_done()
168 mmc_hostname(host), in mmc_request_done()
174 mmc_hostname(host), mrq->stop->opcode, in mmc_request_done()
183 mmc_host_clk_release(host); in mmc_request_done()
189 static int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq) in mmc_start_request() argument
195 if (mmc_card_removed(host->card)) in mmc_start_request()
200 mmc_hostname(host), mrq->sbc->opcode, in mmc_start_request()
205 mmc_hostname(host), mrq->cmd->opcode, in mmc_start_request()
211 mmc_hostname(host), mrq->data->blksz, in mmc_start_request()
219 mmc_hostname(host), mrq->stop->opcode, in mmc_start_request()
223 WARN_ON(!host->claimed); in mmc_start_request()
232 BUG_ON(mrq->data->blksz > host->max_blk_size); in mmc_start_request()
233 BUG_ON(mrq->data->blocks > host->max_blk_count); in mmc_start_request()
235 host->max_req_size); in mmc_start_request()
253 mmc_host_clk_hold(host); in mmc_start_request()
254 led_trigger_event(host->led, LED_FULL); in mmc_start_request()
255 host->ops->request(host, mrq); in mmc_start_request()
284 mmc_hostname(card->host), err); in mmc_start_bkops()
295 mmc_claim_host(card->host); in mmc_start_bkops()
309 mmc_hostname(card->host), err); in mmc_start_bkops()
321 mmc_release_host(card->host); in mmc_start_bkops()
333 struct mmc_context_info *context_info = &mrq->host->context_info; in mmc_wait_data_done()
352 static int __mmc_start_data_req(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_data_req() argument
357 mrq->host = host; in __mmc_start_data_req()
359 err = mmc_start_request(host, mrq); in __mmc_start_data_req()
368 static int __mmc_start_req(struct mmc_host *host, struct mmc_request *mrq) in __mmc_start_req() argument
375 err = mmc_start_request(host, mrq); in __mmc_start_req()
395 static int mmc_wait_for_data_req_done(struct mmc_host *host, in mmc_wait_for_data_req_done() argument
400 struct mmc_context_info *context_info = &host->context_info; in mmc_wait_for_data_req_done()
417 mmc_card_removed(host->card)) { in mmc_wait_for_data_req_done()
418 err = host->areq->err_check(host->card, in mmc_wait_for_data_req_done()
419 host->areq); in mmc_wait_for_data_req_done()
423 mmc_hostname(host), in mmc_wait_for_data_req_done()
427 host->ops->request(host, mrq); in mmc_wait_for_data_req_done()
441 static void mmc_wait_for_req_done(struct mmc_host *host, in mmc_wait_for_req_done() argument
458 if (!mmc_interrupt_hpi(host->card)) { in mmc_wait_for_req_done()
460 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
465 mmc_hostname(host), __func__); in mmc_wait_for_req_done()
469 mmc_card_removed(host->card)) in mmc_wait_for_req_done()
473 mmc_hostname(host), cmd->opcode, cmd->error); in mmc_wait_for_req_done()
476 host->ops->request(host, mrq); in mmc_wait_for_req_done()
491 static void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq, in mmc_pre_req() argument
494 if (host->ops->pre_req) { in mmc_pre_req()
495 mmc_host_clk_hold(host); in mmc_pre_req()
496 host->ops->pre_req(host, mrq, is_first_req); in mmc_pre_req()
497 mmc_host_clk_release(host); in mmc_pre_req()
510 static void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq, in mmc_post_req() argument
513 if (host->ops->post_req) { in mmc_post_req()
514 mmc_host_clk_hold(host); in mmc_post_req()
515 host->ops->post_req(host, mrq, err); in mmc_post_req()
516 mmc_host_clk_release(host); in mmc_post_req()
536 struct mmc_async_req *mmc_start_req(struct mmc_host *host, in mmc_start_req() argument
541 struct mmc_async_req *data = host->areq; in mmc_start_req()
545 mmc_pre_req(host, areq->mrq, !host->areq); in mmc_start_req()
547 if (host->areq) { in mmc_start_req()
548 err = mmc_wait_for_data_req_done(host, host->areq->mrq, areq); in mmc_start_req()
561 if (host->card && mmc_card_mmc(host->card) && in mmc_start_req()
562 ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) || in mmc_start_req()
563 (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) && in mmc_start_req()
564 (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) { in mmc_start_req()
568 mmc_post_req(host, areq->mrq, -EINVAL); in mmc_start_req()
570 mmc_start_bkops(host->card, true); in mmc_start_req()
574 mmc_pre_req(host, areq->mrq, !host->areq); in mmc_start_req()
579 start_err = __mmc_start_data_req(host, areq->mrq); in mmc_start_req()
581 if (host->areq) in mmc_start_req()
582 mmc_post_req(host, host->areq->mrq, 0); in mmc_start_req()
586 mmc_post_req(host, areq->mrq, -EINVAL); in mmc_start_req()
589 host->areq = NULL; in mmc_start_req()
591 host->areq = areq; in mmc_start_req()
608 void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq) in mmc_wait_for_req() argument
610 __mmc_start_req(host, mrq); in mmc_wait_for_req()
611 mmc_wait_for_req_done(host, mrq); in mmc_wait_for_req()
631 pr_info("%s: HPI enable bit unset\n", mmc_hostname(card->host)); in mmc_interrupt_hpi()
635 mmc_claim_host(card->host); in mmc_interrupt_hpi()
638 pr_err("%s: Get card status fail\n", mmc_hostname(card->host)); in mmc_interrupt_hpi()
657 mmc_hostname(card->host), R1_CURRENT_STATE(status)); in mmc_interrupt_hpi()
677 mmc_release_host(card->host); in mmc_interrupt_hpi()
692 int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries) in mmc_wait_for_cmd() argument
696 WARN_ON(!host->claimed); in mmc_wait_for_cmd()
704 mmc_wait_for_req(host, &mrq); in mmc_wait_for_cmd()
745 mmc_claim_host(card->host); in mmc_read_bkops_status()
747 mmc_release_host(card->host); in mmc_read_bkops_status()
801 if (mmc_host_clk_rate(card->host)) in mmc_set_data_timeout()
803 (mmc_host_clk_rate(card->host) / 1000); in mmc_set_data_timeout()
848 if (mmc_host_is_spi(card->host)) { in mmc_set_data_timeout()
897 int __mmc_claim_host(struct mmc_host *host, atomic_t *abort) in __mmc_claim_host() argument
906 add_wait_queue(&host->wq, &wait); in __mmc_claim_host()
907 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
911 if (stop || !host->claimed || host->claimer == current) in __mmc_claim_host()
913 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
915 spin_lock_irqsave(&host->lock, flags); in __mmc_claim_host()
919 host->claimed = 1; in __mmc_claim_host()
920 host->claimer = current; in __mmc_claim_host()
921 host->claim_cnt += 1; in __mmc_claim_host()
922 if (host->claim_cnt == 1) in __mmc_claim_host()
925 wake_up(&host->wq); in __mmc_claim_host()
926 spin_unlock_irqrestore(&host->lock, flags); in __mmc_claim_host()
927 remove_wait_queue(&host->wq, &wait); in __mmc_claim_host()
930 pm_runtime_get_sync(mmc_dev(host)); in __mmc_claim_host()
943 void mmc_release_host(struct mmc_host *host) in mmc_release_host() argument
947 WARN_ON(!host->claimed); in mmc_release_host()
949 spin_lock_irqsave(&host->lock, flags); in mmc_release_host()
950 if (--host->claim_cnt) { in mmc_release_host()
952 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
954 host->claimed = 0; in mmc_release_host()
955 host->claimer = NULL; in mmc_release_host()
956 spin_unlock_irqrestore(&host->lock, flags); in mmc_release_host()
957 wake_up(&host->wq); in mmc_release_host()
958 pm_runtime_mark_last_busy(mmc_dev(host)); in mmc_release_host()
959 pm_runtime_put_autosuspend(mmc_dev(host)); in mmc_release_host()
971 mmc_claim_host(card->host); in mmc_get_card()
981 mmc_release_host(card->host); in mmc_put_card()
991 static inline void mmc_set_ios(struct mmc_host *host) in mmc_set_ios() argument
993 struct mmc_ios *ios = &host->ios; in mmc_set_ios()
997 mmc_hostname(host), ios->clock, ios->bus_mode, in mmc_set_ios()
1002 mmc_set_ungated(host); in mmc_set_ios()
1003 host->ops->set_ios(host, ios); in mmc_set_ios()
1009 void mmc_set_chip_select(struct mmc_host *host, int mode) in mmc_set_chip_select() argument
1011 mmc_host_clk_hold(host); in mmc_set_chip_select()
1012 host->ios.chip_select = mode; in mmc_set_chip_select()
1013 mmc_set_ios(host); in mmc_set_chip_select()
1014 mmc_host_clk_release(host); in mmc_set_chip_select()
1021 static void __mmc_set_clock(struct mmc_host *host, unsigned int hz) in __mmc_set_clock() argument
1023 WARN_ON(hz && hz < host->f_min); in __mmc_set_clock()
1025 if (hz > host->f_max) in __mmc_set_clock()
1026 hz = host->f_max; in __mmc_set_clock()
1028 host->ios.clock = hz; in __mmc_set_clock()
1029 mmc_set_ios(host); in __mmc_set_clock()
1032 void mmc_set_clock(struct mmc_host *host, unsigned int hz) in mmc_set_clock() argument
1034 mmc_host_clk_hold(host); in mmc_set_clock()
1035 __mmc_set_clock(host, hz); in mmc_set_clock()
1036 mmc_host_clk_release(host); in mmc_set_clock()
1043 void mmc_gate_clock(struct mmc_host *host) in mmc_gate_clock() argument
1047 spin_lock_irqsave(&host->clk_lock, flags); in mmc_gate_clock()
1048 host->clk_old = host->ios.clock; in mmc_gate_clock()
1049 host->ios.clock = 0; in mmc_gate_clock()
1050 host->clk_gated = true; in mmc_gate_clock()
1051 spin_unlock_irqrestore(&host->clk_lock, flags); in mmc_gate_clock()
1052 mmc_set_ios(host); in mmc_gate_clock()
1059 void mmc_ungate_clock(struct mmc_host *host) in mmc_ungate_clock() argument
1068 if (host->clk_old) { in mmc_ungate_clock()
1069 BUG_ON(host->ios.clock); in mmc_ungate_clock()
1071 __mmc_set_clock(host, host->clk_old); in mmc_ungate_clock()
1075 void mmc_set_ungated(struct mmc_host *host) in mmc_set_ungated() argument
1083 spin_lock_irqsave(&host->clk_lock, flags); in mmc_set_ungated()
1084 host->clk_gated = false; in mmc_set_ungated()
1085 spin_unlock_irqrestore(&host->clk_lock, flags); in mmc_set_ungated()
1089 void mmc_set_ungated(struct mmc_host *host) in mmc_set_ungated() argument
1096 struct mmc_host *host = card->host; in mmc_execute_tuning() local
1100 if (!host->ops->execute_tuning) in mmc_execute_tuning()
1108 mmc_host_clk_hold(host); in mmc_execute_tuning()
1109 err = host->ops->execute_tuning(host, opcode); in mmc_execute_tuning()
1110 mmc_host_clk_release(host); in mmc_execute_tuning()
1113 pr_err("%s: tuning execution failed\n", mmc_hostname(host)); in mmc_execute_tuning()
1121 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode) in mmc_set_bus_mode() argument
1123 mmc_host_clk_hold(host); in mmc_set_bus_mode()
1124 host->ios.bus_mode = mode; in mmc_set_bus_mode()
1125 mmc_set_ios(host); in mmc_set_bus_mode()
1126 mmc_host_clk_release(host); in mmc_set_bus_mode()
1132 void mmc_set_bus_width(struct mmc_host *host, unsigned int width) in mmc_set_bus_width() argument
1134 mmc_host_clk_hold(host); in mmc_set_bus_width()
1135 host->ios.bus_width = width; in mmc_set_bus_width()
1136 mmc_set_ios(host); in mmc_set_bus_width()
1137 mmc_host_clk_release(host); in mmc_set_bus_width()
1143 void mmc_set_initial_state(struct mmc_host *host) in mmc_set_initial_state() argument
1145 if (mmc_host_is_spi(host)) in mmc_set_initial_state()
1146 host->ios.chip_select = MMC_CS_HIGH; in mmc_set_initial_state()
1148 host->ios.chip_select = MMC_CS_DONTCARE; in mmc_set_initial_state()
1149 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL; in mmc_set_initial_state()
1150 host->ios.bus_width = MMC_BUS_WIDTH_1; in mmc_set_initial_state()
1151 host->ios.timing = MMC_TIMING_LEGACY; in mmc_set_initial_state()
1153 mmc_set_ios(host); in mmc_set_initial_state()
1285 struct device_node *mmc_of_find_child_device(struct mmc_host *host, in mmc_of_find_child_device() argument
1290 if (!host->parent || !host->parent->of_node) in mmc_of_find_child_device()
1293 for_each_child_of_node(host->parent->of_node, node) { in mmc_of_find_child_device()
1438 u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) in mmc_select_voltage() argument
1447 dev_warn(mmc_dev(host), in mmc_select_voltage()
1452 ocr &= host->ocr_avail; in mmc_select_voltage()
1454 dev_warn(mmc_dev(host), "no support for card's volts\n"); in mmc_select_voltage()
1458 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { in mmc_select_voltage()
1461 mmc_power_cycle(host, ocr); in mmc_select_voltage()
1465 if (bit != host->ios.vdd) in mmc_select_voltage()
1466 dev_warn(mmc_dev(host), "exceeding card's volts\n"); in mmc_select_voltage()
1472 int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) in __mmc_set_signal_voltage() argument
1475 int old_signal_voltage = host->ios.signal_voltage; in __mmc_set_signal_voltage()
1477 host->ios.signal_voltage = signal_voltage; in __mmc_set_signal_voltage()
1478 if (host->ops->start_signal_voltage_switch) { in __mmc_set_signal_voltage()
1479 mmc_host_clk_hold(host); in __mmc_set_signal_voltage()
1480 err = host->ops->start_signal_voltage_switch(host, &host->ios); in __mmc_set_signal_voltage()
1481 mmc_host_clk_release(host); in __mmc_set_signal_voltage()
1485 host->ios.signal_voltage = old_signal_voltage; in __mmc_set_signal_voltage()
1491 int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr) in mmc_set_signal_voltage() argument
1497 BUG_ON(!host); in mmc_set_signal_voltage()
1504 return __mmc_set_signal_voltage(host, signal_voltage); in mmc_set_signal_voltage()
1510 if (!host->ops->start_signal_voltage_switch) in mmc_set_signal_voltage()
1512 if (!host->ops->card_busy) in mmc_set_signal_voltage()
1514 mmc_hostname(host)); in mmc_set_signal_voltage()
1516 mmc_host_clk_hold(host); in mmc_set_signal_voltage()
1522 err = mmc_wait_for_cmd(host, &cmd, 0); in mmc_set_signal_voltage()
1526 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) { in mmc_set_signal_voltage()
1535 if (host->ops->card_busy && !host->ops->card_busy(host)) { in mmc_set_signal_voltage()
1543 clock = host->ios.clock; in mmc_set_signal_voltage()
1544 host->ios.clock = 0; in mmc_set_signal_voltage()
1545 mmc_set_ios(host); in mmc_set_signal_voltage()
1547 if (__mmc_set_signal_voltage(host, signal_voltage)) { in mmc_set_signal_voltage()
1558 host->ios.clock = clock; in mmc_set_signal_voltage()
1559 mmc_set_ios(host); in mmc_set_signal_voltage()
1568 if (host->ops->card_busy && host->ops->card_busy(host)) in mmc_set_signal_voltage()
1574 "power cycling card\n", mmc_hostname(host)); in mmc_set_signal_voltage()
1575 mmc_power_cycle(host, ocr); in mmc_set_signal_voltage()
1579 mmc_host_clk_release(host); in mmc_set_signal_voltage()
1587 void mmc_set_timing(struct mmc_host *host, unsigned int timing) in mmc_set_timing() argument
1589 mmc_host_clk_hold(host); in mmc_set_timing()
1590 host->ios.timing = timing; in mmc_set_timing()
1591 mmc_set_ios(host); in mmc_set_timing()
1592 mmc_host_clk_release(host); in mmc_set_timing()
1598 void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type) in mmc_set_driver_type() argument
1600 mmc_host_clk_hold(host); in mmc_set_driver_type()
1601 host->ios.drv_type = drv_type; in mmc_set_driver_type()
1602 mmc_set_ios(host); in mmc_set_driver_type()
1603 mmc_host_clk_release(host); in mmc_set_driver_type()
1617 void mmc_power_up(struct mmc_host *host, u32 ocr) in mmc_power_up() argument
1619 if (host->ios.power_mode == MMC_POWER_ON) in mmc_power_up()
1622 mmc_host_clk_hold(host); in mmc_power_up()
1624 mmc_pwrseq_pre_power_on(host); in mmc_power_up()
1626 host->ios.vdd = fls(ocr) - 1; in mmc_power_up()
1627 host->ios.power_mode = MMC_POWER_UP; in mmc_power_up()
1629 mmc_set_initial_state(host); in mmc_power_up()
1632 if (__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330) == 0) in mmc_power_up()
1633 dev_dbg(mmc_dev(host), "Initial signal voltage of 3.3v\n"); in mmc_power_up()
1634 else if (__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180) == 0) in mmc_power_up()
1635 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.8v\n"); in mmc_power_up()
1636 else if (__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_120) == 0) in mmc_power_up()
1637 dev_dbg(mmc_dev(host), "Initial signal voltage of 1.2v\n"); in mmc_power_up()
1645 mmc_pwrseq_post_power_on(host); in mmc_power_up()
1647 host->ios.clock = host->f_init; in mmc_power_up()
1649 host->ios.power_mode = MMC_POWER_ON; in mmc_power_up()
1650 mmc_set_ios(host); in mmc_power_up()
1658 mmc_host_clk_release(host); in mmc_power_up()
1661 void mmc_power_off(struct mmc_host *host) in mmc_power_off() argument
1663 if (host->ios.power_mode == MMC_POWER_OFF) in mmc_power_off()
1666 mmc_host_clk_hold(host); in mmc_power_off()
1668 mmc_pwrseq_power_off(host); in mmc_power_off()
1670 host->ios.clock = 0; in mmc_power_off()
1671 host->ios.vdd = 0; in mmc_power_off()
1673 host->ios.power_mode = MMC_POWER_OFF; in mmc_power_off()
1675 mmc_set_initial_state(host); in mmc_power_off()
1684 mmc_host_clk_release(host); in mmc_power_off()
1687 void mmc_power_cycle(struct mmc_host *host, u32 ocr) in mmc_power_cycle() argument
1689 mmc_power_off(host); in mmc_power_cycle()
1692 mmc_power_up(host, ocr); in mmc_power_cycle()
1698 static void __mmc_release_bus(struct mmc_host *host) in __mmc_release_bus() argument
1700 BUG_ON(!host); in __mmc_release_bus()
1701 BUG_ON(host->bus_refs); in __mmc_release_bus()
1702 BUG_ON(!host->bus_dead); in __mmc_release_bus()
1704 host->bus_ops = NULL; in __mmc_release_bus()
1710 static inline void mmc_bus_get(struct mmc_host *host) in mmc_bus_get() argument
1714 spin_lock_irqsave(&host->lock, flags); in mmc_bus_get()
1715 host->bus_refs++; in mmc_bus_get()
1716 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_get()
1723 static inline void mmc_bus_put(struct mmc_host *host) in mmc_bus_put() argument
1727 spin_lock_irqsave(&host->lock, flags); in mmc_bus_put()
1728 host->bus_refs--; in mmc_bus_put()
1729 if ((host->bus_refs == 0) && host->bus_ops) in mmc_bus_put()
1730 __mmc_release_bus(host); in mmc_bus_put()
1731 spin_unlock_irqrestore(&host->lock, flags); in mmc_bus_put()
1738 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops) in mmc_attach_bus() argument
1742 BUG_ON(!host); in mmc_attach_bus()
1745 WARN_ON(!host->claimed); in mmc_attach_bus()
1747 spin_lock_irqsave(&host->lock, flags); in mmc_attach_bus()
1749 BUG_ON(host->bus_ops); in mmc_attach_bus()
1750 BUG_ON(host->bus_refs); in mmc_attach_bus()
1752 host->bus_ops = ops; in mmc_attach_bus()
1753 host->bus_refs = 1; in mmc_attach_bus()
1754 host->bus_dead = 0; in mmc_attach_bus()
1756 spin_unlock_irqrestore(&host->lock, flags); in mmc_attach_bus()
1762 void mmc_detach_bus(struct mmc_host *host) in mmc_detach_bus() argument
1766 BUG_ON(!host); in mmc_detach_bus()
1768 WARN_ON(!host->claimed); in mmc_detach_bus()
1769 WARN_ON(!host->bus_ops); in mmc_detach_bus()
1771 spin_lock_irqsave(&host->lock, flags); in mmc_detach_bus()
1773 host->bus_dead = 1; in mmc_detach_bus()
1775 spin_unlock_irqrestore(&host->lock, flags); in mmc_detach_bus()
1777 mmc_bus_put(host); in mmc_detach_bus()
1780 static void _mmc_detect_change(struct mmc_host *host, unsigned long delay, in _mmc_detect_change() argument
1785 spin_lock_irqsave(&host->lock, flags); in _mmc_detect_change()
1786 WARN_ON(host->removed); in _mmc_detect_change()
1787 spin_unlock_irqrestore(&host->lock, flags); in _mmc_detect_change()
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()
1900 (mmc_host_clk_rate(card->host) / 1000); in mmc_mmc_erase_timeout()
1926 if (mmc_host_is_spi(card->host) && erase_timeout < 1000) in mmc_mmc_erase_timeout()
2011 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2026 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2039 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2047 if (mmc_host_is_spi(card->host)) in mmc_do_erase()
2057 err = mmc_wait_for_cmd(card->host, &cmd, 0); in mmc_do_erase()
2070 mmc_hostname(card->host), __func__); in mmc_do_erase()
2095 if (!(card->host->caps & MMC_CAP_ERASE) || in mmc_erase()
2150 if ((card->host->caps & MMC_CAP_ERASE) && in mmc_can_erase()
2210 struct mmc_host *host = card->host; in mmc_do_calc_max_discard() local
2226 if (timeout > host->max_busy_timeout) in mmc_do_calc_max_discard()
2255 struct mmc_host *host = card->host; in mmc_calc_max_discard() local
2258 if (!host->max_busy_timeout) in mmc_calc_max_discard()
2278 mmc_hostname(host), max_discard, host->max_busy_timeout); in mmc_calc_max_discard()
2293 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blocklen()
2307 return mmc_wait_for_cmd(card->host, &cmd, 5); in mmc_set_blockcount()
2311 static void mmc_hw_reset_for_init(struct mmc_host *host) in mmc_hw_reset_for_init() argument
2313 if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset) in mmc_hw_reset_for_init()
2315 mmc_host_clk_hold(host); in mmc_hw_reset_for_init()
2316 host->ops->hw_reset(host); in mmc_hw_reset_for_init()
2317 mmc_host_clk_release(host); in mmc_hw_reset_for_init()
2320 int mmc_hw_reset(struct mmc_host *host) in mmc_hw_reset() argument
2324 if (!host->card) in mmc_hw_reset()
2327 mmc_bus_get(host); in mmc_hw_reset()
2328 if (!host->bus_ops || host->bus_dead || !host->bus_ops->reset) { in mmc_hw_reset()
2329 mmc_bus_put(host); in mmc_hw_reset()
2333 ret = host->bus_ops->reset(host); in mmc_hw_reset()
2334 mmc_bus_put(host); in mmc_hw_reset()
2336 pr_warn("%s: tried to reset card\n", mmc_hostname(host)); in mmc_hw_reset()
2342 static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) in mmc_rescan_try_freq() argument
2344 host->f_init = freq; in mmc_rescan_try_freq()
2348 mmc_hostname(host), __func__, host->f_init); in mmc_rescan_try_freq()
2350 mmc_power_up(host, host->ocr_avail); in mmc_rescan_try_freq()
2356 mmc_hw_reset_for_init(host); in mmc_rescan_try_freq()
2363 sdio_reset(host); in mmc_rescan_try_freq()
2364 mmc_go_idle(host); in mmc_rescan_try_freq()
2366 mmc_send_if_cond(host, host->ocr_avail); in mmc_rescan_try_freq()
2369 if (!mmc_attach_sdio(host)) in mmc_rescan_try_freq()
2371 if (!mmc_attach_sd(host)) in mmc_rescan_try_freq()
2373 if (!mmc_attach_mmc(host)) in mmc_rescan_try_freq()
2376 mmc_power_off(host); in mmc_rescan_try_freq()
2380 int _mmc_detect_card_removed(struct mmc_host *host) in _mmc_detect_card_removed() argument
2384 if (host->caps & MMC_CAP_NONREMOVABLE) in _mmc_detect_card_removed()
2387 if (!host->card || mmc_card_removed(host->card)) in _mmc_detect_card_removed()
2390 ret = host->bus_ops->alive(host); in _mmc_detect_card_removed()
2399 if (!ret && host->ops->get_cd && !host->ops->get_cd(host)) { in _mmc_detect_card_removed()
2400 mmc_detect_change(host, msecs_to_jiffies(200)); in _mmc_detect_card_removed()
2401 pr_debug("%s: card removed too slowly\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2405 mmc_card_set_removed(host->card); in _mmc_detect_card_removed()
2406 pr_debug("%s: card remove detected\n", mmc_hostname(host)); in _mmc_detect_card_removed()
2412 int mmc_detect_card_removed(struct mmc_host *host) in mmc_detect_card_removed() argument
2414 struct mmc_card *card = host->card; in mmc_detect_card_removed()
2417 WARN_ON(!host->claimed); in mmc_detect_card_removed()
2427 if (!host->detect_change && !(host->caps & MMC_CAP_NEEDS_POLL)) in mmc_detect_card_removed()
2430 host->detect_change = 0; in mmc_detect_card_removed()
2432 ret = _mmc_detect_card_removed(host); in mmc_detect_card_removed()
2433 if (ret && (host->caps & MMC_CAP_NEEDS_POLL)) { in mmc_detect_card_removed()
2438 cancel_delayed_work(&host->detect); in mmc_detect_card_removed()
2439 _mmc_detect_change(host, 0, false); in mmc_detect_card_removed()
2449 struct mmc_host *host = in mmc_rescan() local
2453 if (host->trigger_card_event && host->ops->card_event) { in mmc_rescan()
2454 host->ops->card_event(host); in mmc_rescan()
2455 host->trigger_card_event = false; in mmc_rescan()
2458 if (host->rescan_disable) in mmc_rescan()
2462 if ((host->caps & MMC_CAP_NONREMOVABLE) && host->rescan_entered) in mmc_rescan()
2464 host->rescan_entered = 1; in mmc_rescan()
2466 mmc_bus_get(host); in mmc_rescan()
2472 if (host->bus_ops && !host->bus_dead in mmc_rescan()
2473 && !(host->caps & MMC_CAP_NONREMOVABLE)) in mmc_rescan()
2474 host->bus_ops->detect(host); in mmc_rescan()
2476 host->detect_change = 0; in mmc_rescan()
2482 mmc_bus_put(host); in mmc_rescan()
2483 mmc_bus_get(host); in mmc_rescan()
2486 if (host->bus_ops != NULL) { in mmc_rescan()
2487 mmc_bus_put(host); in mmc_rescan()
2495 mmc_bus_put(host); in mmc_rescan()
2497 if (!(host->caps & MMC_CAP_NONREMOVABLE) && host->ops->get_cd && in mmc_rescan()
2498 host->ops->get_cd(host) == 0) { in mmc_rescan()
2499 mmc_claim_host(host); in mmc_rescan()
2500 mmc_power_off(host); in mmc_rescan()
2501 mmc_release_host(host); in mmc_rescan()
2505 mmc_claim_host(host); in mmc_rescan()
2507 if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) in mmc_rescan()
2509 if (freqs[i] <= host->f_min) in mmc_rescan()
2512 mmc_release_host(host); in mmc_rescan()
2515 if (host->caps & MMC_CAP_NEEDS_POLL) in mmc_rescan()
2516 mmc_schedule_delayed_work(&host->detect, HZ); in mmc_rescan()
2519 void mmc_start_host(struct mmc_host *host) in mmc_start_host() argument
2521 host->f_init = max(freqs[0], host->f_min); in mmc_start_host()
2522 host->rescan_disable = 0; in mmc_start_host()
2523 host->ios.power_mode = MMC_POWER_UNDEFINED; in mmc_start_host()
2524 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP) in mmc_start_host()
2525 mmc_power_off(host); in mmc_start_host()
2527 mmc_power_up(host, host->ocr_avail); in mmc_start_host()
2528 mmc_gpiod_request_cd_irq(host); in mmc_start_host()
2529 _mmc_detect_change(host, 0, false); in mmc_start_host()
2532 void mmc_stop_host(struct mmc_host *host) in mmc_stop_host() argument
2536 spin_lock_irqsave(&host->lock, flags); in mmc_stop_host()
2537 host->removed = 1; in mmc_stop_host()
2538 spin_unlock_irqrestore(&host->lock, flags); in mmc_stop_host()
2540 if (host->slot.cd_irq >= 0) in mmc_stop_host()
2541 disable_irq(host->slot.cd_irq); in mmc_stop_host()
2543 host->rescan_disable = 1; in mmc_stop_host()
2544 cancel_delayed_work_sync(&host->detect); in mmc_stop_host()
2548 host->pm_flags = 0; in mmc_stop_host()
2550 mmc_bus_get(host); in mmc_stop_host()
2551 if (host->bus_ops && !host->bus_dead) { in mmc_stop_host()
2553 host->bus_ops->remove(host); in mmc_stop_host()
2554 mmc_claim_host(host); in mmc_stop_host()
2555 mmc_detach_bus(host); in mmc_stop_host()
2556 mmc_power_off(host); in mmc_stop_host()
2557 mmc_release_host(host); in mmc_stop_host()
2558 mmc_bus_put(host); in mmc_stop_host()
2561 mmc_bus_put(host); in mmc_stop_host()
2563 BUG_ON(host->card); in mmc_stop_host()
2565 mmc_power_off(host); in mmc_stop_host()
2568 int mmc_power_save_host(struct mmc_host *host) in mmc_power_save_host() argument
2573 pr_info("%s: %s: powering down\n", mmc_hostname(host), __func__); in mmc_power_save_host()
2576 mmc_bus_get(host); in mmc_power_save_host()
2578 if (!host->bus_ops || host->bus_dead) { in mmc_power_save_host()
2579 mmc_bus_put(host); in mmc_power_save_host()
2583 if (host->bus_ops->power_save) in mmc_power_save_host()
2584 ret = host->bus_ops->power_save(host); in mmc_power_save_host()
2586 mmc_bus_put(host); in mmc_power_save_host()
2588 mmc_power_off(host); in mmc_power_save_host()
2594 int mmc_power_restore_host(struct mmc_host *host) in mmc_power_restore_host() argument
2599 pr_info("%s: %s: powering up\n", mmc_hostname(host), __func__); in mmc_power_restore_host()
2602 mmc_bus_get(host); in mmc_power_restore_host()
2604 if (!host->bus_ops || host->bus_dead) { in mmc_power_restore_host()
2605 mmc_bus_put(host); in mmc_power_restore_host()
2609 mmc_power_up(host, host->card->ocr); in mmc_power_restore_host()
2610 ret = host->bus_ops->power_restore(host); in mmc_power_restore_host()
2612 mmc_bus_put(host); in mmc_power_restore_host()
2632 mmc_hostname(card->host), err); in mmc_flush_cache()
2648 struct mmc_host *host = container_of( in mmc_pm_notify() local
2657 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2658 host->rescan_disable = 1; in mmc_pm_notify()
2659 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2660 cancel_delayed_work_sync(&host->detect); in mmc_pm_notify()
2662 if (!host->bus_ops) in mmc_pm_notify()
2666 if (host->bus_ops->pre_suspend) in mmc_pm_notify()
2667 err = host->bus_ops->pre_suspend(host); in mmc_pm_notify()
2672 host->bus_ops->remove(host); in mmc_pm_notify()
2673 mmc_claim_host(host); in mmc_pm_notify()
2674 mmc_detach_bus(host); in mmc_pm_notify()
2675 mmc_power_off(host); in mmc_pm_notify()
2676 mmc_release_host(host); in mmc_pm_notify()
2677 host->pm_flags = 0; in mmc_pm_notify()
2684 spin_lock_irqsave(&host->lock, flags); in mmc_pm_notify()
2685 host->rescan_disable = 0; in mmc_pm_notify()
2686 spin_unlock_irqrestore(&host->lock, flags); in mmc_pm_notify()
2687 _mmc_detect_change(host, 0, false); in mmc_pm_notify()
2703 void mmc_init_context_info(struct mmc_host *host) in mmc_init_context_info() argument
2705 spin_lock_init(&host->context_info.lock); in mmc_init_context_info()
2706 host->context_info.is_new_req = false; in mmc_init_context_info()
2707 host->context_info.is_done_rcv = false; in mmc_init_context_info()
2708 host->context_info.is_waiting_last_req = false; in mmc_init_context_info()
2709 init_waitqueue_head(&host->context_info.wait); in mmc_init_context_info()