Lines Matching full:host

3  *  linux/drivers/mmc/host/sdhci.c - Secure Digital Host Controller Interface driver
30 #include <linux/mmc/host.h>
40 pr_debug("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
43 pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
50 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
52 static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd);
54 void sdhci_dumpregs(struct sdhci_host *host) in sdhci_dumpregs() argument
59 sdhci_readl(host, SDHCI_DMA_ADDRESS), in sdhci_dumpregs()
60 sdhci_readw(host, SDHCI_HOST_VERSION)); in sdhci_dumpregs()
62 sdhci_readw(host, SDHCI_BLOCK_SIZE), in sdhci_dumpregs()
63 sdhci_readw(host, SDHCI_BLOCK_COUNT)); in sdhci_dumpregs()
65 sdhci_readl(host, SDHCI_ARGUMENT), in sdhci_dumpregs()
66 sdhci_readw(host, SDHCI_TRANSFER_MODE)); in sdhci_dumpregs()
67 SDHCI_DUMP("Present: 0x%08x | Host ctl: 0x%08x\n", in sdhci_dumpregs()
68 sdhci_readl(host, SDHCI_PRESENT_STATE), in sdhci_dumpregs()
69 sdhci_readb(host, SDHCI_HOST_CONTROL)); in sdhci_dumpregs()
71 sdhci_readb(host, SDHCI_POWER_CONTROL), in sdhci_dumpregs()
72 sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL)); in sdhci_dumpregs()
74 sdhci_readb(host, SDHCI_WAKE_UP_CONTROL), in sdhci_dumpregs()
75 sdhci_readw(host, SDHCI_CLOCK_CONTROL)); in sdhci_dumpregs()
77 sdhci_readb(host, SDHCI_TIMEOUT_CONTROL), in sdhci_dumpregs()
78 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_dumpregs()
80 sdhci_readl(host, SDHCI_INT_ENABLE), in sdhci_dumpregs()
81 sdhci_readl(host, SDHCI_SIGNAL_ENABLE)); in sdhci_dumpregs()
83 sdhci_readw(host, SDHCI_AUTO_CMD_STATUS), in sdhci_dumpregs()
84 sdhci_readw(host, SDHCI_SLOT_INT_STATUS)); in sdhci_dumpregs()
86 sdhci_readl(host, SDHCI_CAPABILITIES), in sdhci_dumpregs()
87 sdhci_readl(host, SDHCI_CAPABILITIES_1)); in sdhci_dumpregs()
89 sdhci_readw(host, SDHCI_COMMAND), in sdhci_dumpregs()
90 sdhci_readl(host, SDHCI_MAX_CURRENT)); in sdhci_dumpregs()
92 sdhci_readl(host, SDHCI_RESPONSE), in sdhci_dumpregs()
93 sdhci_readl(host, SDHCI_RESPONSE + 4)); in sdhci_dumpregs()
95 sdhci_readl(host, SDHCI_RESPONSE + 8), in sdhci_dumpregs()
96 sdhci_readl(host, SDHCI_RESPONSE + 12)); in sdhci_dumpregs()
97 SDHCI_DUMP("Host ctl2: 0x%08x\n", in sdhci_dumpregs()
98 sdhci_readw(host, SDHCI_HOST_CONTROL2)); in sdhci_dumpregs()
100 if (host->flags & SDHCI_USE_ADMA) { in sdhci_dumpregs()
101 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_dumpregs()
103 sdhci_readl(host, SDHCI_ADMA_ERROR), in sdhci_dumpregs()
104 sdhci_readl(host, SDHCI_ADMA_ADDRESS_HI), in sdhci_dumpregs()
105 sdhci_readl(host, SDHCI_ADMA_ADDRESS)); in sdhci_dumpregs()
108 sdhci_readl(host, SDHCI_ADMA_ERROR), in sdhci_dumpregs()
109 sdhci_readl(host, SDHCI_ADMA_ADDRESS)); in sdhci_dumpregs()
113 if (host->ops->dump_vendor_regs) in sdhci_dumpregs()
114 host->ops->dump_vendor_regs(host); in sdhci_dumpregs()
126 static void sdhci_do_enable_v4_mode(struct sdhci_host *host) in sdhci_do_enable_v4_mode() argument
130 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_do_enable_v4_mode()
135 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_do_enable_v4_mode()
139 * This can be called before sdhci_add_host() by Vendor's host controller
142 void sdhci_enable_v4_mode(struct sdhci_host *host) in sdhci_enable_v4_mode() argument
144 host->v4_mode = true; in sdhci_enable_v4_mode()
145 sdhci_do_enable_v4_mode(host); in sdhci_enable_v4_mode()
154 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) in sdhci_set_card_detection() argument
158 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || in sdhci_set_card_detection()
159 !mmc_card_is_removable(host->mmc) || mmc_can_gpio_cd(host->mmc)) in sdhci_set_card_detection()
163 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & in sdhci_set_card_detection()
166 host->ier |= present ? SDHCI_INT_CARD_REMOVE : in sdhci_set_card_detection()
169 host->ier &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); in sdhci_set_card_detection()
172 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_card_detection()
173 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_card_detection()
176 static void sdhci_enable_card_detection(struct sdhci_host *host) in sdhci_enable_card_detection() argument
178 sdhci_set_card_detection(host, true); in sdhci_enable_card_detection()
181 static void sdhci_disable_card_detection(struct sdhci_host *host) in sdhci_disable_card_detection() argument
183 sdhci_set_card_detection(host, false); in sdhci_disable_card_detection()
186 static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) in sdhci_runtime_pm_bus_on() argument
188 if (host->bus_on) in sdhci_runtime_pm_bus_on()
190 host->bus_on = true; in sdhci_runtime_pm_bus_on()
191 pm_runtime_get_noresume(mmc_dev(host->mmc)); in sdhci_runtime_pm_bus_on()
194 static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) in sdhci_runtime_pm_bus_off() argument
196 if (!host->bus_on) in sdhci_runtime_pm_bus_off()
198 host->bus_on = false; in sdhci_runtime_pm_bus_off()
199 pm_runtime_put_noidle(mmc_dev(host->mmc)); in sdhci_runtime_pm_bus_off()
202 void sdhci_reset(struct sdhci_host *host, u8 mask) in sdhci_reset() argument
206 sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); in sdhci_reset()
209 host->clock = 0; in sdhci_reset()
211 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_reset()
212 sdhci_runtime_pm_bus_off(host); in sdhci_reset()
222 if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)) in sdhci_reset()
226 mmc_hostname(host->mmc), (int)mask); in sdhci_reset()
227 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_reset()
228 sdhci_dumpregs(host); in sdhci_reset()
236 static bool sdhci_do_reset(struct sdhci_host *host, u8 mask) in sdhci_do_reset() argument
238 if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { in sdhci_do_reset()
239 struct mmc_host *mmc = host->mmc; in sdhci_do_reset()
245 host->ops->reset(host, mask); in sdhci_do_reset()
250 static void sdhci_reset_for_all(struct sdhci_host *host) in sdhci_reset_for_all() argument
252 if (sdhci_do_reset(host, SDHCI_RESET_ALL)) { in sdhci_reset_for_all()
253 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_reset_for_all()
254 if (host->ops->enable_dma) in sdhci_reset_for_all()
255 host->ops->enable_dma(host); in sdhci_reset_for_all()
258 host->preset_enabled = false; in sdhci_reset_for_all()
271 static void sdhci_reset_for_reason(struct sdhci_host *host, enum sdhci_reset_reason reason) in sdhci_reset_for_reason() argument
273 if (host->quirks2 & SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER) { in sdhci_reset_for_reason()
274 sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); in sdhci_reset_for_reason()
280 sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); in sdhci_reset_for_reason()
286 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_reset_for_reason()
287 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_reset_for_reason()
290 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_reset_for_reason()
297 static void sdhci_set_default_irqs(struct sdhci_host *host) in sdhci_set_default_irqs() argument
299 host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | in sdhci_set_default_irqs()
305 if (host->tuning_mode == SDHCI_TUNING_MODE_2 || in sdhci_set_default_irqs()
306 host->tuning_mode == SDHCI_TUNING_MODE_3) in sdhci_set_default_irqs()
307 host->ier |= SDHCI_INT_RETUNE; in sdhci_set_default_irqs()
309 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_default_irqs()
310 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_default_irqs()
313 static void sdhci_config_dma(struct sdhci_host *host) in sdhci_config_dma() argument
318 if (host->version < SDHCI_SPEC_200) in sdhci_config_dma()
321 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_config_dma()
329 if (!(host->flags & SDHCI_REQ_USE_DMA)) in sdhci_config_dma()
333 if (host->flags & SDHCI_USE_ADMA) in sdhci_config_dma()
336 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_config_dma()
342 if (host->v4_mode) { in sdhci_config_dma()
343 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
345 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
346 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_config_dma()
356 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_config_dma()
359 static void sdhci_init(struct sdhci_host *host, int soft) in sdhci_init() argument
361 struct mmc_host *mmc = host->mmc; in sdhci_init()
365 sdhci_reset_for(host, INIT); in sdhci_init()
367 sdhci_reset_for_all(host); in sdhci_init()
369 if (host->v4_mode) in sdhci_init()
370 sdhci_do_enable_v4_mode(host); in sdhci_init()
372 spin_lock_irqsave(&host->lock, flags); in sdhci_init()
373 sdhci_set_default_irqs(host); in sdhci_init()
374 spin_unlock_irqrestore(&host->lock, flags); in sdhci_init()
376 host->cqe_on = false; in sdhci_init()
380 host->clock = 0; in sdhci_init()
381 host->reinit_uhs = true; in sdhci_init()
386 static void sdhci_reinit(struct sdhci_host *host) in sdhci_reinit() argument
388 u32 cd = host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); in sdhci_reinit()
390 sdhci_init(host, 0); in sdhci_reinit()
391 sdhci_enable_card_detection(host); in sdhci_reinit()
396 * been missed while the host controller was being reset, so trigger a in sdhci_reinit()
399 if (cd != (host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT))) in sdhci_reinit()
400 mmc_detect_change(host->mmc, msecs_to_jiffies(200)); in sdhci_reinit()
403 static void __sdhci_led_activate(struct sdhci_host *host) in __sdhci_led_activate() argument
407 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_activate()
410 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
412 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
415 static void __sdhci_led_deactivate(struct sdhci_host *host) in __sdhci_led_deactivate() argument
419 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_deactivate()
422 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
424 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
431 struct sdhci_host *host = container_of(led, struct sdhci_host, led); in sdhci_led_control() local
434 spin_lock_irqsave(&host->lock, flags); in sdhci_led_control()
436 if (host->runtime_suspended) in sdhci_led_control()
440 __sdhci_led_deactivate(host); in sdhci_led_control()
442 __sdhci_led_activate(host); in sdhci_led_control()
444 spin_unlock_irqrestore(&host->lock, flags); in sdhci_led_control()
447 static int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
449 struct mmc_host *mmc = host->mmc; in sdhci_led_register()
451 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_register()
454 snprintf(host->led_name, sizeof(host->led_name), in sdhci_led_register()
457 host->led.name = host->led_name; in sdhci_led_register()
458 host->led.brightness = LED_OFF; in sdhci_led_register()
459 host->led.default_trigger = mmc_hostname(mmc); in sdhci_led_register()
460 host->led.brightness_set = sdhci_led_control; in sdhci_led_register()
462 return led_classdev_register(mmc_dev(mmc), &host->led); in sdhci_led_register()
465 static void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
467 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_unregister()
470 led_classdev_unregister(&host->led); in sdhci_led_unregister()
473 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
477 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
483 static inline int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
488 static inline void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
492 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
494 __sdhci_led_activate(host); in sdhci_led_activate()
497 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
499 __sdhci_led_deactivate(host); in sdhci_led_deactivate()
504 static void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, in sdhci_mod_timer() argument
508 mod_timer(&host->data_timer, timeout); in sdhci_mod_timer()
510 mod_timer(&host->timer, timeout); in sdhci_mod_timer()
513 static void sdhci_del_timer(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_del_timer() argument
516 del_timer(&host->data_timer); in sdhci_del_timer()
518 del_timer(&host->timer); in sdhci_del_timer()
521 static inline bool sdhci_has_requests(struct sdhci_host *host) in sdhci_has_requests() argument
523 return host->cmd || host->data_cmd; in sdhci_has_requests()
532 static void sdhci_read_block_pio(struct sdhci_host *host) in sdhci_read_block_pio() argument
540 blksize = host->data->blksz; in sdhci_read_block_pio()
544 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_read_block_pio()
546 len = min(host->sg_miter.length, blksize); in sdhci_read_block_pio()
549 host->sg_miter.consumed = len; in sdhci_read_block_pio()
551 buf = host->sg_miter.addr; in sdhci_read_block_pio()
555 scratch = sdhci_readl(host, SDHCI_BUFFER); in sdhci_read_block_pio()
568 sg_miter_stop(&host->sg_miter); in sdhci_read_block_pio()
571 static void sdhci_write_block_pio(struct sdhci_host *host) in sdhci_write_block_pio() argument
579 blksize = host->data->blksz; in sdhci_write_block_pio()
584 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_write_block_pio()
586 len = min(host->sg_miter.length, blksize); in sdhci_write_block_pio()
589 host->sg_miter.consumed = len; in sdhci_write_block_pio()
591 buf = host->sg_miter.addr; in sdhci_write_block_pio()
601 sdhci_writel(host, scratch, SDHCI_BUFFER); in sdhci_write_block_pio()
608 sg_miter_stop(&host->sg_miter); in sdhci_write_block_pio()
611 static void sdhci_transfer_pio(struct sdhci_host *host) in sdhci_transfer_pio() argument
615 if (host->blocks == 0) in sdhci_transfer_pio()
618 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
628 if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) && in sdhci_transfer_pio()
629 (host->data->blocks == 1)) in sdhci_transfer_pio()
632 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { in sdhci_transfer_pio()
633 if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY) in sdhci_transfer_pio()
636 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
637 sdhci_read_block_pio(host); in sdhci_transfer_pio()
639 sdhci_write_block_pio(host); in sdhci_transfer_pio()
641 host->blocks--; in sdhci_transfer_pio()
642 if (host->blocks == 0) in sdhci_transfer_pio()
649 static int sdhci_pre_dma_transfer(struct sdhci_host *host, in sdhci_pre_dma_transfer() argument
662 if (host->bounce_buffer) { in sdhci_pre_dma_transfer()
665 if (length > host->bounce_buffer_size) { in sdhci_pre_dma_transfer()
667 mmc_hostname(host->mmc), length, in sdhci_pre_dma_transfer()
668 host->bounce_buffer_size); in sdhci_pre_dma_transfer()
673 if (host->ops->copy_to_bounce_buffer) { in sdhci_pre_dma_transfer()
674 host->ops->copy_to_bounce_buffer(host, in sdhci_pre_dma_transfer()
678 host->bounce_buffer, length); in sdhci_pre_dma_transfer()
682 dma_sync_single_for_device(mmc_dev(host->mmc), in sdhci_pre_dma_transfer()
683 host->bounce_addr, in sdhci_pre_dma_transfer()
684 host->bounce_buffer_size, in sdhci_pre_dma_transfer()
690 sg_count = dma_map_sg(mmc_dev(host->mmc), in sdhci_pre_dma_transfer()
714 void sdhci_adma_write_desc(struct sdhci_host *host, void **desc, in sdhci_adma_write_desc() argument
724 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_write_desc()
727 *desc += host->desc_sz; in sdhci_adma_write_desc()
731 static inline void __sdhci_adma_write_desc(struct sdhci_host *host, in __sdhci_adma_write_desc() argument
735 if (host->ops->adma_write_desc) in __sdhci_adma_write_desc()
736 host->ops->adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
738 sdhci_adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
749 static void sdhci_adma_table_pre(struct sdhci_host *host, in sdhci_adma_table_pre() argument
763 host->sg_count = sg_count; in sdhci_adma_table_pre()
765 desc = host->adma_table; in sdhci_adma_table_pre()
766 align = host->align_buffer; in sdhci_adma_table_pre()
768 align_addr = host->align_addr; in sdhci_adma_table_pre()
770 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_pre()
790 __sdhci_adma_write_desc(host, &desc, align_addr, in sdhci_adma_table_pre()
808 while (len > host->max_adma) { in sdhci_adma_table_pre()
811 __sdhci_adma_write_desc(host, &desc, addr, n, ADMA2_TRAN_VALID); in sdhci_adma_table_pre()
818 __sdhci_adma_write_desc(host, &desc, addr, len, in sdhci_adma_table_pre()
825 WARN_ON((desc - host->adma_table) >= host->adma_table_sz); in sdhci_adma_table_pre()
828 if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) { in sdhci_adma_table_pre()
830 if (desc != host->adma_table) { in sdhci_adma_table_pre()
831 desc -= host->desc_sz; in sdhci_adma_table_pre()
836 __sdhci_adma_write_desc(host, &desc, 0, 0, ADMA2_NOP_END_VALID); in sdhci_adma_table_pre()
840 static void sdhci_adma_table_post(struct sdhci_host *host, in sdhci_adma_table_post() argument
852 for_each_sg(data->sg, sg, host->sg_count, i) in sdhci_adma_table_post()
859 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, in sdhci_adma_table_post()
862 align = host->align_buffer; in sdhci_adma_table_post()
864 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_post()
880 static void sdhci_set_adma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_adma_addr() argument
882 sdhci_writel(host, lower_32_bits(addr), SDHCI_ADMA_ADDRESS); in sdhci_set_adma_addr()
883 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_set_adma_addr()
884 sdhci_writel(host, upper_32_bits(addr), SDHCI_ADMA_ADDRESS_HI); in sdhci_set_adma_addr()
887 static dma_addr_t sdhci_sdma_address(struct sdhci_host *host) in sdhci_sdma_address() argument
889 if (host->bounce_buffer) in sdhci_sdma_address()
890 return host->bounce_addr; in sdhci_sdma_address()
892 return sg_dma_address(host->data->sg); in sdhci_sdma_address()
895 static void sdhci_set_sdma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_sdma_addr() argument
897 if (host->v4_mode) in sdhci_set_sdma_addr()
898 sdhci_set_adma_addr(host, addr); in sdhci_set_sdma_addr()
900 sdhci_writel(host, addr, SDHCI_DMA_ADDRESS); in sdhci_set_sdma_addr()
903 static unsigned int sdhci_target_timeout(struct sdhci_host *host, in sdhci_target_timeout() argument
914 if (host->clock && data->timeout_clks) { in sdhci_target_timeout()
919 * host->clock is in Hz. target_timeout is in us. in sdhci_target_timeout()
923 if (do_div(val, host->clock)) in sdhci_target_timeout()
932 static void sdhci_calc_sw_timeout(struct sdhci_host *host, in sdhci_calc_sw_timeout() argument
936 struct mmc_host *mmc = host->mmc; in sdhci_calc_sw_timeout()
944 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_sw_timeout()
949 freq = mmc->actual_clock ? : host->clock; in sdhci_calc_sw_timeout()
955 host->data_timeout = data->blocks * target_timeout + in sdhci_calc_sw_timeout()
958 host->data_timeout = target_timeout; in sdhci_calc_sw_timeout()
961 if (host->data_timeout) in sdhci_calc_sw_timeout()
962 host->data_timeout += MMC_CMD_TRANSFER_TIME; in sdhci_calc_sw_timeout()
965 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, in sdhci_calc_timeout() argument
975 * If the host controller provides us with an incorrect timeout in sdhci_calc_timeout()
980 if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) in sdhci_calc_timeout()
981 return host->max_timeout_count; in sdhci_calc_timeout()
985 return host->max_timeout_count; in sdhci_calc_timeout()
990 return host->max_timeout_count; in sdhci_calc_timeout()
993 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_timeout()
1001 * (2) host->timeout_clk < 2^16 in sdhci_calc_timeout()
1006 current_timeout = (1 << 13) * 1000 / host->timeout_clk; in sdhci_calc_timeout()
1010 if (count > host->max_timeout_count) { in sdhci_calc_timeout()
1011 if (!(host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT)) in sdhci_calc_timeout()
1014 count = host->max_timeout_count; in sdhci_calc_timeout()
1023 static void sdhci_set_transfer_irqs(struct sdhci_host *host) in sdhci_set_transfer_irqs() argument
1028 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_irqs()
1029 host->ier = (host->ier & ~pio_irqs) | dma_irqs; in sdhci_set_transfer_irqs()
1031 host->ier = (host->ier & ~dma_irqs) | pio_irqs; in sdhci_set_transfer_irqs()
1033 if (host->flags & (SDHCI_AUTO_CMD23 | SDHCI_AUTO_CMD12)) in sdhci_set_transfer_irqs()
1034 host->ier |= SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1036 host->ier &= ~SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1038 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_transfer_irqs()
1039 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_transfer_irqs()
1042 void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable) in sdhci_set_data_timeout_irq() argument
1045 host->ier |= SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1047 host->ier &= ~SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1048 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_data_timeout_irq()
1049 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_data_timeout_irq()
1053 void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in __sdhci_set_timeout() argument
1056 u8 count = sdhci_calc_timeout(host, cmd, &too_big); in __sdhci_set_timeout()
1059 host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT) { in __sdhci_set_timeout()
1060 sdhci_calc_sw_timeout(host, cmd); in __sdhci_set_timeout()
1061 sdhci_set_data_timeout_irq(host, false); in __sdhci_set_timeout()
1062 } else if (!(host->ier & SDHCI_INT_DATA_TIMEOUT)) { in __sdhci_set_timeout()
1063 sdhci_set_data_timeout_irq(host, true); in __sdhci_set_timeout()
1066 sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); in __sdhci_set_timeout()
1070 static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_set_timeout() argument
1072 if (host->ops->set_timeout) in sdhci_set_timeout()
1073 host->ops->set_timeout(host, cmd); in sdhci_set_timeout()
1075 __sdhci_set_timeout(host, cmd); in sdhci_set_timeout()
1078 static void sdhci_initialize_data(struct sdhci_host *host, in sdhci_initialize_data() argument
1081 WARN_ON(host->data); in sdhci_initialize_data()
1085 BUG_ON(data->blksz > host->mmc->max_blk_size); in sdhci_initialize_data()
1088 host->data = data; in sdhci_initialize_data()
1089 host->data_early = 0; in sdhci_initialize_data()
1090 host->data->bytes_xfered = 0; in sdhci_initialize_data()
1093 static inline void sdhci_set_block_info(struct sdhci_host *host, in sdhci_set_block_info() argument
1097 sdhci_writew(host, in sdhci_set_block_info()
1098 SDHCI_MAKE_BLKSZ(host->sdma_boundary, data->blksz), in sdhci_set_block_info()
1104 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_set_block_info()
1105 (host->quirks2 & SDHCI_QUIRK2_USE_32BIT_BLK_CNT)) { in sdhci_set_block_info()
1106 if (sdhci_readw(host, SDHCI_BLOCK_COUNT)) in sdhci_set_block_info()
1107 sdhci_writew(host, 0, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1108 sdhci_writew(host, data->blocks, SDHCI_32BIT_BLK_CNT); in sdhci_set_block_info()
1110 sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1114 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_prepare_data() argument
1118 sdhci_initialize_data(host, data); in sdhci_prepare_data()
1120 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_prepare_data()
1125 host->flags |= SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1136 if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1137 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) { in sdhci_prepare_data()
1147 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) in sdhci_prepare_data()
1149 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) in sdhci_prepare_data()
1158 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1163 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1170 sdhci_config_dma(host); in sdhci_prepare_data()
1172 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_prepare_data()
1173 int sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_prepare_data()
1181 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1182 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1183 sdhci_adma_table_pre(host, data, sg_cnt); in sdhci_prepare_data()
1184 sdhci_set_adma_addr(host, host->adma_addr); in sdhci_prepare_data()
1187 sdhci_set_sdma_addr(host, sdhci_sdma_address(host)); in sdhci_prepare_data()
1191 if (!(host->flags & SDHCI_REQ_USE_DMA)) { in sdhci_prepare_data()
1195 if (host->data->flags & MMC_DATA_READ) in sdhci_prepare_data()
1199 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); in sdhci_prepare_data()
1200 host->blocks = data->blocks; in sdhci_prepare_data()
1203 sdhci_set_transfer_irqs(host); in sdhci_prepare_data()
1205 sdhci_set_block_info(host, data); in sdhci_prepare_data()
1210 static int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1213 struct mmc_host *mmc = host->mmc; in sdhci_external_dma_init()
1215 host->tx_chan = dma_request_chan(mmc_dev(mmc), "tx"); in sdhci_external_dma_init()
1216 if (IS_ERR(host->tx_chan)) { in sdhci_external_dma_init()
1217 ret = PTR_ERR(host->tx_chan); in sdhci_external_dma_init()
1220 host->tx_chan = NULL; in sdhci_external_dma_init()
1224 host->rx_chan = dma_request_chan(mmc_dev(mmc), "rx"); in sdhci_external_dma_init()
1225 if (IS_ERR(host->rx_chan)) { in sdhci_external_dma_init()
1226 if (host->tx_chan) { in sdhci_external_dma_init()
1227 dma_release_channel(host->tx_chan); in sdhci_external_dma_init()
1228 host->tx_chan = NULL; in sdhci_external_dma_init()
1231 ret = PTR_ERR(host->rx_chan); in sdhci_external_dma_init()
1234 host->rx_chan = NULL; in sdhci_external_dma_init()
1240 static struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1243 return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; in sdhci_external_dma_channel()
1246 static int sdhci_external_dma_setup(struct sdhci_host *host, in sdhci_external_dma_setup() argument
1258 if (!host->mapbase) in sdhci_external_dma_setup()
1262 cfg.src_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1263 cfg.dst_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1275 chan = sdhci_external_dma_channel(host, data); in sdhci_external_dma_setup()
1281 sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_external_dma_setup()
1301 static void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1303 if (host->tx_chan) { in sdhci_external_dma_release()
1304 dma_release_channel(host->tx_chan); in sdhci_external_dma_release()
1305 host->tx_chan = NULL; in sdhci_external_dma_release()
1308 if (host->rx_chan) { in sdhci_external_dma_release()
1309 dma_release_channel(host->rx_chan); in sdhci_external_dma_release()
1310 host->rx_chan = NULL; in sdhci_external_dma_release()
1313 sdhci_switch_external_dma(host, false); in sdhci_external_dma_release()
1316 static void __sdhci_external_dma_prepare_data(struct sdhci_host *host, in __sdhci_external_dma_prepare_data() argument
1321 sdhci_initialize_data(host, data); in __sdhci_external_dma_prepare_data()
1323 host->flags |= SDHCI_REQ_USE_DMA; in __sdhci_external_dma_prepare_data()
1324 sdhci_set_transfer_irqs(host); in __sdhci_external_dma_prepare_data()
1326 sdhci_set_block_info(host, data); in __sdhci_external_dma_prepare_data()
1329 static void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1332 if (!sdhci_external_dma_setup(host, cmd)) { in sdhci_external_dma_prepare_data()
1333 __sdhci_external_dma_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1335 sdhci_external_dma_release(host); in sdhci_external_dma_prepare_data()
1337 mmc_hostname(host->mmc)); in sdhci_external_dma_prepare_data()
1338 sdhci_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1342 static void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1350 chan = sdhci_external_dma_channel(host, cmd->data); in sdhci_external_dma_pre_transfer()
1357 static inline int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1362 static inline void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1366 static inline void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1373 static inline void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1378 static inline struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1386 void sdhci_switch_external_dma(struct sdhci_host *host, bool en) in sdhci_switch_external_dma() argument
1388 host->use_external_dma = en; in sdhci_switch_external_dma()
1392 static inline bool sdhci_auto_cmd12(struct sdhci_host *host, in sdhci_auto_cmd12() argument
1395 return !mrq->sbc && (host->flags & SDHCI_AUTO_CMD12) && in sdhci_auto_cmd12()
1399 static inline bool sdhci_auto_cmd23(struct sdhci_host *host, in sdhci_auto_cmd23() argument
1402 return mrq->sbc && (host->flags & SDHCI_AUTO_CMD23); in sdhci_auto_cmd23()
1405 static inline bool sdhci_manual_cmd23(struct sdhci_host *host, in sdhci_manual_cmd23() argument
1408 return mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23); in sdhci_manual_cmd23()
1411 static inline void sdhci_auto_cmd_select(struct sdhci_host *host, in sdhci_auto_cmd_select() argument
1415 bool use_cmd12 = sdhci_auto_cmd12(host, cmd->mrq) && in sdhci_auto_cmd_select()
1417 bool use_cmd23 = sdhci_auto_cmd23(host, cmd->mrq); in sdhci_auto_cmd_select()
1426 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_auto_cmd_select()
1430 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1435 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1450 static void sdhci_set_transfer_mode(struct sdhci_host *host, in sdhci_set_transfer_mode() argument
1457 if (host->quirks2 & in sdhci_set_transfer_mode()
1461 sdhci_writew(host, 0x0, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1464 mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1465 sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | in sdhci_set_transfer_mode()
1471 WARN_ON(!host->data); in sdhci_set_transfer_mode()
1473 if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) in sdhci_set_transfer_mode()
1478 sdhci_auto_cmd_select(host, cmd, &mode); in sdhci_set_transfer_mode()
1479 if (sdhci_auto_cmd23(host, cmd->mrq)) in sdhci_set_transfer_mode()
1480 sdhci_writel(host, cmd->mrq->sbc->arg, SDHCI_ARGUMENT2); in sdhci_set_transfer_mode()
1485 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_mode()
1488 sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1491 static bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_needs_reset() argument
1493 return (!(host->flags & SDHCI_DEVICE_DEAD) && in sdhci_needs_reset()
1497 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))); in sdhci_needs_reset()
1500 static void sdhci_set_mrq_done(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_set_mrq_done() argument
1505 if (host->mrqs_done[i] == mrq) { in sdhci_set_mrq_done()
1512 if (!host->mrqs_done[i]) { in sdhci_set_mrq_done()
1513 host->mrqs_done[i] = mrq; in sdhci_set_mrq_done()
1521 static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in __sdhci_finish_mrq() argument
1523 if (host->cmd && host->cmd->mrq == mrq) in __sdhci_finish_mrq()
1524 host->cmd = NULL; in __sdhci_finish_mrq()
1526 if (host->data_cmd && host->data_cmd->mrq == mrq) in __sdhci_finish_mrq()
1527 host->data_cmd = NULL; in __sdhci_finish_mrq()
1529 if (host->deferred_cmd && host->deferred_cmd->mrq == mrq) in __sdhci_finish_mrq()
1530 host->deferred_cmd = NULL; in __sdhci_finish_mrq()
1532 if (host->data && host->data->mrq == mrq) in __sdhci_finish_mrq()
1533 host->data = NULL; in __sdhci_finish_mrq()
1535 if (sdhci_needs_reset(host, mrq)) in __sdhci_finish_mrq()
1536 host->pending_reset = true; in __sdhci_finish_mrq()
1538 sdhci_set_mrq_done(host, mrq); in __sdhci_finish_mrq()
1540 sdhci_del_timer(host, mrq); in __sdhci_finish_mrq()
1542 if (!sdhci_has_requests(host)) in __sdhci_finish_mrq()
1543 sdhci_led_deactivate(host); in __sdhci_finish_mrq()
1546 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_finish_mrq() argument
1548 __sdhci_finish_mrq(host, mrq); in sdhci_finish_mrq()
1550 queue_work(host->complete_wq, &host->complete_work); in sdhci_finish_mrq()
1553 static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout) in __sdhci_finish_data() argument
1555 struct mmc_command *data_cmd = host->data_cmd; in __sdhci_finish_data()
1556 struct mmc_data *data = host->data; in __sdhci_finish_data()
1558 host->data = NULL; in __sdhci_finish_data()
1559 host->data_cmd = NULL; in __sdhci_finish_data()
1566 if (!host->cmd || host->cmd == data_cmd) in __sdhci_finish_data()
1567 sdhci_reset_for(host, REQUEST_ERROR); in __sdhci_finish_data()
1569 sdhci_reset_for(host, REQUEST_ERROR_DATA_ONLY); in __sdhci_finish_data()
1572 if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_ADMA)) == in __sdhci_finish_data()
1574 sdhci_adma_table_post(host, data); in __sdhci_finish_data()
1594 ((!data->mrq->sbc && !sdhci_auto_cmd12(host, data->mrq)) || in __sdhci_finish_data()
1602 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1605 host->cmd = NULL; in __sdhci_finish_data()
1606 if (!sdhci_send_command(host, data->stop)) { in __sdhci_finish_data()
1613 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1615 WARN_ON(host->deferred_cmd); in __sdhci_finish_data()
1616 host->deferred_cmd = data->stop; in __sdhci_finish_data()
1621 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1625 static void sdhci_finish_data(struct sdhci_host *host) in sdhci_finish_data() argument
1627 __sdhci_finish_data(host, false); in sdhci_finish_data()
1630 static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_send_command() argument
1636 WARN_ON(host->cmd); in sdhci_send_command()
1641 if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) && in sdhci_send_command()
1654 if (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) in sdhci_send_command()
1657 host->cmd = cmd; in sdhci_send_command()
1658 host->data_timeout = 0; in sdhci_send_command()
1660 WARN_ON(host->data_cmd); in sdhci_send_command()
1661 host->data_cmd = cmd; in sdhci_send_command()
1662 sdhci_set_timeout(host, cmd); in sdhci_send_command()
1666 if (host->use_external_dma) in sdhci_send_command()
1667 sdhci_external_dma_prepare_data(host, cmd); in sdhci_send_command()
1669 sdhci_prepare_data(host, cmd); in sdhci_send_command()
1672 sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT); in sdhci_send_command()
1674 sdhci_set_transfer_mode(host, cmd); in sdhci_send_command()
1705 if (host->data_timeout) in sdhci_send_command()
1706 timeout += nsecs_to_jiffies(host->data_timeout); in sdhci_send_command()
1711 sdhci_mod_timer(host, cmd->mrq, timeout); in sdhci_send_command()
1713 if (host->use_external_dma) in sdhci_send_command()
1714 sdhci_external_dma_pre_transfer(host, cmd); in sdhci_send_command()
1716 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); in sdhci_send_command()
1721 static bool sdhci_present_error(struct sdhci_host *host, in sdhci_present_error() argument
1724 if (!present || host->flags & SDHCI_DEVICE_DEAD) { in sdhci_present_error()
1732 static bool sdhci_send_command_retry(struct sdhci_host *host, in sdhci_send_command_retry() argument
1735 __releases(host->lock) in sdhci_send_command_retry()
1736 __acquires(host->lock) in sdhci_send_command_retry()
1738 struct mmc_command *deferred_cmd = host->deferred_cmd; in sdhci_send_command_retry()
1742 while (!sdhci_send_command(host, cmd)) { in sdhci_send_command_retry()
1745 mmc_hostname(host->mmc)); in sdhci_send_command_retry()
1746 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_send_command_retry()
1747 sdhci_dumpregs(host); in sdhci_send_command_retry()
1752 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_command_retry()
1756 present = host->mmc->ops->get_cd(host->mmc); in sdhci_send_command_retry()
1758 spin_lock_irqsave(&host->lock, flags); in sdhci_send_command_retry()
1761 if (cmd == deferred_cmd && cmd != host->deferred_cmd) in sdhci_send_command_retry()
1764 if (sdhci_present_error(host, cmd, present)) in sdhci_send_command_retry()
1768 if (cmd == host->deferred_cmd) in sdhci_send_command_retry()
1769 host->deferred_cmd = NULL; in sdhci_send_command_retry()
1774 static void sdhci_read_rsp_136(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_read_rsp_136() argument
1780 cmd->resp[i] = sdhci_readl(host, reg); in sdhci_read_rsp_136()
1783 if (host->quirks2 & SDHCI_QUIRK2_RSP_136_HAS_CRC) in sdhci_read_rsp_136()
1794 static void sdhci_finish_command(struct sdhci_host *host) in sdhci_finish_command() argument
1796 struct mmc_command *cmd = host->cmd; in sdhci_finish_command()
1798 host->cmd = NULL; in sdhci_finish_command()
1802 sdhci_read_rsp_136(host, cmd); in sdhci_finish_command()
1804 cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE); in sdhci_finish_command()
1809 mmc_command_done(host->mmc, cmd->mrq); in sdhci_finish_command()
1812 * The host can send and interrupt when the busy state has in sdhci_finish_command()
1824 } else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && in sdhci_finish_command()
1825 cmd == host->data_cmd) { in sdhci_finish_command()
1833 if (!sdhci_send_command(host, cmd->mrq->cmd)) { in sdhci_finish_command()
1834 WARN_ON(host->deferred_cmd); in sdhci_finish_command()
1835 host->deferred_cmd = cmd->mrq->cmd; in sdhci_finish_command()
1840 if (host->data && host->data_early) in sdhci_finish_command()
1841 sdhci_finish_data(host); in sdhci_finish_command()
1844 __sdhci_finish_mrq(host, cmd->mrq); in sdhci_finish_command()
1848 static u16 sdhci_get_preset_value(struct sdhci_host *host) in sdhci_get_preset_value() argument
1852 switch (host->timing) { in sdhci_get_preset_value()
1855 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HIGH_SPEED); in sdhci_get_preset_value()
1858 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1861 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR25); in sdhci_get_preset_value()
1864 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR50); in sdhci_get_preset_value()
1868 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104); in sdhci_get_preset_value()
1872 preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50); in sdhci_get_preset_value()
1875 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HS400); in sdhci_get_preset_value()
1879 mmc_hostname(host->mmc)); in sdhci_get_preset_value()
1880 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1886 u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, in sdhci_calc_clk() argument
1894 if (host->version >= SDHCI_SPEC_300) { in sdhci_calc_clk()
1895 if (host->preset_enabled) { in sdhci_calc_clk()
1898 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_calc_clk()
1899 pre_val = sdhci_get_preset_value(host); in sdhci_calc_clk()
1901 if (host->clk_mul && in sdhci_calc_clk()
1905 clk_mul = host->clk_mul; in sdhci_calc_clk()
1913 * Check if the Host Controller supports Programmable Clock in sdhci_calc_clk()
1916 if (host->clk_mul) { in sdhci_calc_clk()
1918 if ((host->max_clk * host->clk_mul / div) in sdhci_calc_clk()
1922 if ((host->max_clk * host->clk_mul / div) <= clock) { in sdhci_calc_clk()
1929 clk_mul = host->clk_mul; in sdhci_calc_clk()
1940 if (!host->clk_mul || switch_base_clk) { in sdhci_calc_clk()
1942 if (host->max_clk <= clock) in sdhci_calc_clk()
1947 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1953 if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) in sdhci_calc_clk()
1954 && !div && host->max_clk <= 25000000) in sdhci_calc_clk()
1960 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1969 *actual_clock = (host->max_clk * clk_mul) / real_div; in sdhci_calc_clk()
1978 void sdhci_enable_clk(struct sdhci_host *host, u16 clk) in sdhci_enable_clk() argument
1983 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1990 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1995 mmc_hostname(host->mmc)); in sdhci_enable_clk()
1996 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_enable_clk()
1997 sdhci_dumpregs(host); in sdhci_enable_clk()
2003 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) { in sdhci_enable_clk()
2006 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2013 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2018 mmc_hostname(host->mmc)); in sdhci_enable_clk()
2019 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_enable_clk()
2020 sdhci_dumpregs(host); in sdhci_enable_clk()
2028 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2032 void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) in sdhci_set_clock() argument
2036 host->mmc->actual_clock = 0; in sdhci_set_clock()
2038 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); in sdhci_set_clock()
2043 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); in sdhci_set_clock()
2044 sdhci_enable_clk(host, clk); in sdhci_set_clock()
2048 static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_reg() argument
2051 struct mmc_host *mmc = host->mmc; in sdhci_set_power_reg()
2056 sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2058 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2061 void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_noreg() argument
2094 mmc_hostname(host->mmc), vdd); in sdhci_set_power_noreg()
2099 if (host->pwr == pwr) in sdhci_set_power_noreg()
2102 host->pwr = pwr; in sdhci_set_power_noreg()
2105 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2106 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2107 sdhci_runtime_pm_bus_off(host); in sdhci_set_power_noreg()
2113 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) in sdhci_set_power_noreg()
2114 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2121 if (host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER) in sdhci_set_power_noreg()
2122 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2126 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2128 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2129 sdhci_runtime_pm_bus_on(host); in sdhci_set_power_noreg()
2135 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) in sdhci_set_power_noreg()
2141 void sdhci_set_power(struct sdhci_host *host, unsigned char mode, in sdhci_set_power() argument
2144 if (IS_ERR(host->mmc->supply.vmmc)) in sdhci_set_power()
2145 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power()
2147 sdhci_set_power_reg(host, mode, vdd); in sdhci_set_power()
2157 void sdhci_set_power_and_bus_voltage(struct sdhci_host *host, in sdhci_set_power_and_bus_voltage() argument
2161 if (!IS_ERR(host->mmc->supply.vmmc)) { in sdhci_set_power_and_bus_voltage()
2162 struct mmc_host *mmc = host->mmc; in sdhci_set_power_and_bus_voltage()
2166 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power_and_bus_voltage()
2178 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request() local
2186 spin_lock_irqsave(&host->lock, flags); in sdhci_request()
2188 sdhci_led_activate(host); in sdhci_request()
2190 if (sdhci_present_error(host, mrq->cmd, present)) in sdhci_request()
2193 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request()
2195 if (!sdhci_send_command_retry(host, cmd, flags)) in sdhci_request()
2198 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2203 sdhci_finish_mrq(host, mrq); in sdhci_request()
2204 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2210 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request_atomic() local
2215 spin_lock_irqsave(&host->lock, flags); in sdhci_request_atomic()
2217 if (sdhci_present_error(host, mrq->cmd, true)) { in sdhci_request_atomic()
2218 sdhci_finish_mrq(host, mrq); in sdhci_request_atomic()
2222 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request_atomic()
2231 if (!sdhci_send_command(host, cmd)) in sdhci_request_atomic()
2234 sdhci_led_activate(host); in sdhci_request_atomic()
2237 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_atomic()
2242 void sdhci_set_bus_width(struct sdhci_host *host, int width) in sdhci_set_bus_width() argument
2246 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2251 if (host->mmc->caps & MMC_CAP_8_BIT_DATA) in sdhci_set_bus_width()
2258 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2262 void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing) in sdhci_set_uhs_signaling() argument
2266 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2267 /* Select Bus Speed Mode for host */ in sdhci_set_uhs_signaling()
2283 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2301 static bool sdhci_preset_needed(struct sdhci_host *host, unsigned char timing) in sdhci_preset_needed() argument
2303 return !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN) && in sdhci_preset_needed()
2307 static bool sdhci_presetable_values_change(struct sdhci_host *host, struct mmc_ios *ios) in sdhci_presetable_values_change() argument
2314 return !host->preset_enabled && in sdhci_presetable_values_change()
2315 (sdhci_preset_needed(host, ios->timing) || host->drv_type != ios->drv_type); in sdhci_presetable_values_change()
2320 struct sdhci_host *host = mmc_priv(mmc); in sdhci_set_ios() local
2321 bool reinit_uhs = host->reinit_uhs; in sdhci_set_ios()
2325 host->reinit_uhs = false; in sdhci_set_ios()
2330 if (host->flags & SDHCI_DEVICE_DEAD) { in sdhci_set_ios()
2342 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_set_ios()
2343 sdhci_reinit(host); in sdhci_set_ios()
2346 if (host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2348 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) in sdhci_set_ios()
2349 sdhci_enable_preset_value(host, false); in sdhci_set_ios()
2351 if (!ios->clock || ios->clock != host->clock) { in sdhci_set_ios()
2352 turning_on_clk = ios->clock && !host->clock; in sdhci_set_ios()
2354 host->ops->set_clock(host, ios->clock); in sdhci_set_ios()
2355 host->clock = ios->clock; in sdhci_set_ios()
2357 if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK && in sdhci_set_ios()
2358 host->clock) { in sdhci_set_ios()
2359 host->timeout_clk = mmc->actual_clock ? in sdhci_set_ios()
2361 host->clock / 1000; in sdhci_set_ios()
2363 host->ops->get_max_timeout_count ? in sdhci_set_ios()
2364 host->ops->get_max_timeout_count(host) : in sdhci_set_ios()
2366 mmc->max_busy_timeout /= host->timeout_clk; in sdhci_set_ios()
2370 if (host->ops->set_power) in sdhci_set_ios()
2371 host->ops->set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2373 sdhci_set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2375 if (host->ops->platform_send_init_74_clocks) in sdhci_set_ios()
2376 host->ops->platform_send_init_74_clocks(host, ios->power_mode); in sdhci_set_ios()
2378 host->ops->set_bus_width(host, ios->bus_width); in sdhci_set_ios()
2386 host->timing == ios->timing && in sdhci_set_ios()
2387 host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2388 !sdhci_presetable_values_change(host, ios)) in sdhci_set_ios()
2391 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2393 if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) { in sdhci_set_ios()
2408 if (host->version >= SDHCI_SPEC_300) { in sdhci_set_ios()
2413 * Enable in the Host Control 2 register is set, we in sdhci_set_ios()
2417 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2420 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2423 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2425 if (!host->preset_enabled) { in sdhci_set_ios()
2430 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2446 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2447 host->drv_type = ios->drv_type; in sdhci_set_ios()
2450 host->ops->set_uhs_signaling(host, ios->timing); in sdhci_set_ios()
2451 host->timing = ios->timing; in sdhci_set_ios()
2453 if (sdhci_preset_needed(host, ios->timing)) { in sdhci_set_ios()
2456 sdhci_enable_preset_value(host, true); in sdhci_set_ios()
2457 preset = sdhci_get_preset_value(host); in sdhci_set_ios()
2460 host->drv_type = ios->drv_type; in sdhci_set_ios()
2464 host->ops->set_clock(host, host->clock); in sdhci_set_ios()
2466 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2472 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_cd() local
2475 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_get_cd()
2490 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) in sdhci_get_cd()
2493 /* Host native card detect */ in sdhci_get_cd()
2494 return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); in sdhci_get_cd()
2499 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_cd_nogpio() local
2503 spin_lock_irqsave(&host->lock, flags); in sdhci_get_cd_nogpio()
2505 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_get_cd_nogpio()
2508 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); in sdhci_get_cd_nogpio()
2510 spin_unlock_irqrestore(&host->lock, flags); in sdhci_get_cd_nogpio()
2518 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_ro() local
2522 if (host->flags & SDHCI_DEVICE_DEAD) { in sdhci_get_ro()
2524 } else if (host->ops->get_ro) { in sdhci_get_ro()
2525 is_readonly = host->ops->get_ro(host); in sdhci_get_ro()
2531 is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE) in sdhci_get_ro()
2538 (host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT)) in sdhci_get_ro()
2547 struct sdhci_host *host = mmc_priv(mmc); in sdhci_hw_reset() local
2549 if (host->ops && host->ops->hw_reset) in sdhci_hw_reset()
2550 host->ops->hw_reset(host); in sdhci_hw_reset()
2553 static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable) in sdhci_enable_sdio_irq_nolock() argument
2555 if (!(host->flags & SDHCI_DEVICE_DEAD)) { in sdhci_enable_sdio_irq_nolock()
2557 host->ier |= SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2559 host->ier &= ~SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2561 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_enable_sdio_irq_nolock()
2562 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_enable_sdio_irq_nolock()
2568 struct sdhci_host *host = mmc_priv(mmc); in sdhci_enable_sdio_irq() local
2574 spin_lock_irqsave(&host->lock, flags); in sdhci_enable_sdio_irq()
2575 sdhci_enable_sdio_irq_nolock(host, enable); in sdhci_enable_sdio_irq()
2576 spin_unlock_irqrestore(&host->lock, flags); in sdhci_enable_sdio_irq()
2585 struct sdhci_host *host = mmc_priv(mmc); in sdhci_ack_sdio_irq() local
2588 spin_lock_irqsave(&host->lock, flags); in sdhci_ack_sdio_irq()
2589 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_ack_sdio_irq()
2590 spin_unlock_irqrestore(&host->lock, flags); in sdhci_ack_sdio_irq()
2596 struct sdhci_host *host = mmc_priv(mmc); in sdhci_start_signal_voltage_switch() local
2601 * Signal Voltage Switching is only applicable for Host Controllers in sdhci_start_signal_voltage_switch()
2604 if (host->version < SDHCI_SPEC_300) in sdhci_start_signal_voltage_switch()
2607 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2611 if (!(host->flags & SDHCI_SIGNALING_330)) in sdhci_start_signal_voltage_switch()
2613 /* Set 1.8V Signal Enable in the Host Control2 register to 0 */ in sdhci_start_signal_voltage_switch()
2615 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2629 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2638 if (!(host->flags & SDHCI_SIGNALING_180)) in sdhci_start_signal_voltage_switch()
2650 * Enable 1.8V Signal Enable in the Host Control2 in sdhci_start_signal_voltage_switch()
2654 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2657 if (host->ops->voltage_switch) in sdhci_start_signal_voltage_switch()
2658 host->ops->voltage_switch(host); in sdhci_start_signal_voltage_switch()
2661 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2670 if (!(host->flags & SDHCI_SIGNALING_120)) in sdhci_start_signal_voltage_switch()
2690 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_busy() local
2694 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); in sdhci_card_busy()
2701 struct sdhci_host *host = mmc_priv(mmc); in sdhci_prepare_hs400_tuning() local
2704 spin_lock_irqsave(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2705 host->flags |= SDHCI_HS400_TUNING; in sdhci_prepare_hs400_tuning()
2706 spin_unlock_irqrestore(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2711 void sdhci_start_tuning(struct sdhci_host *host) in sdhci_start_tuning() argument
2715 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2717 if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND) in sdhci_start_tuning()
2719 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2722 * As per the Host Controller spec v3.00, tuning command in sdhci_start_tuning()
2731 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); in sdhci_start_tuning()
2732 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); in sdhci_start_tuning()
2736 void sdhci_end_tuning(struct sdhci_host *host) in sdhci_end_tuning() argument
2738 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_end_tuning()
2739 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_end_tuning()
2743 void sdhci_reset_tuning(struct sdhci_host *host) in sdhci_reset_tuning() argument
2747 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2750 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2754 void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode) in sdhci_abort_tuning() argument
2756 sdhci_reset_tuning(host); in sdhci_abort_tuning()
2758 sdhci_reset_for(host, TUNING_ABORT); in sdhci_abort_tuning()
2760 sdhci_end_tuning(host); in sdhci_abort_tuning()
2762 mmc_send_abort_tuning(host->mmc, opcode); in sdhci_abort_tuning()
2773 void sdhci_send_tuning(struct sdhci_host *host, u32 opcode) in sdhci_send_tuning() argument
2775 struct mmc_host *mmc = host->mmc; in sdhci_send_tuning()
2779 u32 b = host->sdma_boundary; in sdhci_send_tuning()
2781 spin_lock_irqsave(&host->lock, flags); in sdhci_send_tuning()
2790 * block to the Host Controller. So we set the block size in sdhci_send_tuning()
2795 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 128), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2797 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 64), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2800 * The tuning block is sent by the card to the host controller. in sdhci_send_tuning()
2805 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); in sdhci_send_tuning()
2807 if (!sdhci_send_command_retry(host, &cmd, flags)) { in sdhci_send_tuning()
2808 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2809 host->tuning_done = 0; in sdhci_send_tuning()
2813 host->cmd = NULL; in sdhci_send_tuning()
2815 sdhci_del_timer(host, &mrq); in sdhci_send_tuning()
2817 host->tuning_done = 0; in sdhci_send_tuning()
2819 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2822 wait_event_timeout(host->buf_ready_int, (host->tuning_done == 1), in sdhci_send_tuning()
2828 int __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode) in __sdhci_execute_tuning() argument
2836 for (i = 0; i < host->tuning_loop_count; i++) { in __sdhci_execute_tuning()
2839 sdhci_send_tuning(host, opcode); in __sdhci_execute_tuning()
2841 if (!host->tuning_done) { in __sdhci_execute_tuning()
2843 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2844 sdhci_abort_tuning(host, opcode); in __sdhci_execute_tuning()
2849 if (host->tuning_delay > 0) in __sdhci_execute_tuning()
2850 mdelay(host->tuning_delay); in __sdhci_execute_tuning()
2852 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in __sdhci_execute_tuning()
2862 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2863 sdhci_reset_tuning(host); in __sdhci_execute_tuning()
2870 struct sdhci_host *host = mmc_priv(mmc); in sdhci_execute_tuning() local
2875 hs400_tuning = host->flags & SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2877 if (host->tuning_mode == SDHCI_TUNING_MODE_1) in sdhci_execute_tuning()
2878 tuning_count = host->tuning_count; in sdhci_execute_tuning()
2881 * The Host Controller needs tuning in case of SDR104 and DDR50 in sdhci_execute_tuning()
2884 * If the Host Controller supports the HS200 mode then the in sdhci_execute_tuning()
2887 switch (host->timing) { in sdhci_execute_tuning()
2907 if (host->flags & SDHCI_SDR50_NEEDS_TUNING) in sdhci_execute_tuning()
2915 if (host->ops->platform_execute_tuning) { in sdhci_execute_tuning()
2916 err = host->ops->platform_execute_tuning(host, opcode); in sdhci_execute_tuning()
2922 if (host->tuning_delay < 0) in sdhci_execute_tuning()
2923 host->tuning_delay = opcode == MMC_SEND_TUNING_BLOCK; in sdhci_execute_tuning()
2925 sdhci_start_tuning(host); in sdhci_execute_tuning()
2927 host->tuning_err = __sdhci_execute_tuning(host, opcode); in sdhci_execute_tuning()
2929 sdhci_end_tuning(host); in sdhci_execute_tuning()
2931 host->flags &= ~SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2937 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) in sdhci_enable_preset_value() argument
2939 /* Host Controller v3.00 defines preset value registers */ in sdhci_enable_preset_value()
2940 if (host->version < SDHCI_SPEC_300) in sdhci_enable_preset_value()
2947 if (host->preset_enabled != enable) { in sdhci_enable_preset_value()
2948 u16 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2955 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2958 host->flags |= SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2960 host->flags &= ~SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2962 host->preset_enabled = enable; in sdhci_enable_preset_value()
2980 struct sdhci_host *host = mmc_priv(mmc); in sdhci_pre_req() local
2989 if (host->flags & SDHCI_REQ_USE_DMA && !host->bounce_buffer) in sdhci_pre_req()
2990 sdhci_pre_dma_transfer(host, mrq->data, COOKIE_PRE_MAPPED); in sdhci_pre_req()
2993 static void sdhci_error_out_mrqs(struct sdhci_host *host, int err) in sdhci_error_out_mrqs() argument
2995 if (host->data_cmd) { in sdhci_error_out_mrqs()
2996 host->data_cmd->error = err; in sdhci_error_out_mrqs()
2997 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_error_out_mrqs()
3000 if (host->cmd) { in sdhci_error_out_mrqs()
3001 host->cmd->error = err; in sdhci_error_out_mrqs()
3002 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_error_out_mrqs()
3008 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_event() local
3013 if (host->ops->card_event) in sdhci_card_event()
3014 host->ops->card_event(host); in sdhci_card_event()
3018 spin_lock_irqsave(&host->lock, flags); in sdhci_card_event()
3021 if (sdhci_has_requests(host) && !present) { in sdhci_card_event()
3027 sdhci_reset_for(host, CARD_REMOVED); in sdhci_card_event()
3029 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_card_event()
3032 spin_unlock_irqrestore(&host->lock, flags); in sdhci_card_event()
3058 static bool sdhci_request_done(struct sdhci_host *host) in sdhci_request_done() argument
3064 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3067 mrq = host->mrqs_done[i]; in sdhci_request_done()
3073 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3081 if (sdhci_needs_reset(host, mrq)) { in sdhci_request_done()
3085 * also be in mrqs_done, otherwise host->cmd and host->data_cmd in sdhci_request_done()
3088 if (host->cmd || host->data_cmd) { in sdhci_request_done()
3089 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3094 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) in sdhci_request_done()
3096 host->ops->set_clock(host, host->clock); in sdhci_request_done()
3098 sdhci_reset_for(host, REQUEST_ERROR); in sdhci_request_done()
3100 host->pending_reset = false; in sdhci_request_done()
3108 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_request_done()
3111 if (host->use_external_dma && data && in sdhci_request_done()
3113 struct dma_chan *chan = sdhci_external_dma_channel(host, data); in sdhci_request_done()
3115 host->mrqs_done[i] = NULL; in sdhci_request_done()
3116 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3118 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3119 sdhci_set_mrq_done(host, mrq); in sdhci_request_done()
3123 if (host->bounce_buffer) { in sdhci_request_done()
3131 if (length > host->bounce_buffer_size) { in sdhci_request_done()
3133 mmc_hostname(host->mmc), in sdhci_request_done()
3134 host->bounce_buffer_size, in sdhci_request_done()
3137 length = host->bounce_buffer_size; in sdhci_request_done()
3140 mmc_dev(host->mmc), in sdhci_request_done()
3141 host->bounce_addr, in sdhci_request_done()
3142 host->bounce_buffer_size, in sdhci_request_done()
3146 host->bounce_buffer, in sdhci_request_done()
3151 mmc_dev(host->mmc), in sdhci_request_done()
3152 host->bounce_addr, in sdhci_request_done()
3153 host->bounce_buffer_size, in sdhci_request_done()
3158 dma_unmap_sg(mmc_dev(host->mmc), data->sg, in sdhci_request_done()
3166 host->mrqs_done[i] = NULL; in sdhci_request_done()
3168 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3170 if (host->ops->request_done) in sdhci_request_done()
3171 host->ops->request_done(host, mrq); in sdhci_request_done()
3173 mmc_request_done(host->mmc, mrq); in sdhci_request_done()
3180 struct sdhci_host *host = container_of(work, struct sdhci_host, in sdhci_complete_work() local
3183 while (!sdhci_request_done(host)) in sdhci_complete_work()
3189 struct sdhci_host *host; in sdhci_timeout_timer() local
3192 host = from_timer(host, t, timer); in sdhci_timeout_timer()
3194 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_timer()
3196 if (host->cmd && !sdhci_data_line_cmd(host->cmd)) { in sdhci_timeout_timer()
3198 mmc_hostname(host->mmc)); in sdhci_timeout_timer()
3199 sdhci_err_stats_inc(host, REQ_TIMEOUT); in sdhci_timeout_timer()
3200 sdhci_dumpregs(host); in sdhci_timeout_timer()
3202 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_timer()
3203 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_timer()
3206 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_timer()
3211 struct sdhci_host *host; in sdhci_timeout_data_timer() local
3214 host = from_timer(host, t, data_timer); in sdhci_timeout_data_timer()
3216 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_data_timer()
3218 if (host->data || host->data_cmd || in sdhci_timeout_data_timer()
3219 (host->cmd && sdhci_data_line_cmd(host->cmd))) { in sdhci_timeout_data_timer()
3221 mmc_hostname(host->mmc)); in sdhci_timeout_data_timer()
3222 sdhci_err_stats_inc(host, REQ_TIMEOUT); in sdhci_timeout_data_timer()
3223 sdhci_dumpregs(host); in sdhci_timeout_data_timer()
3225 if (host->data) { in sdhci_timeout_data_timer()
3226 host->data->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3227 __sdhci_finish_data(host, true); in sdhci_timeout_data_timer()
3228 queue_work(host->complete_wq, &host->complete_work); in sdhci_timeout_data_timer()
3229 } else if (host->data_cmd) { in sdhci_timeout_data_timer()
3230 host->data_cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3231 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_timeout_data_timer()
3233 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3234 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_data_timer()
3238 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_data_timer()
3247 static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p) in sdhci_cmd_irq() argument
3250 if (intmask & SDHCI_INT_AUTO_CMD_ERR && host->data_cmd) { in sdhci_cmd_irq()
3251 struct mmc_request *mrq = host->data_cmd->mrq; in sdhci_cmd_irq()
3252 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3258 if (!mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) { in sdhci_cmd_irq()
3264 if (!host->cmd) { in sdhci_cmd_irq()
3270 if (host->pending_reset) in sdhci_cmd_irq()
3273 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_cmd_irq()
3274 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_cmd_irq()
3275 sdhci_dumpregs(host); in sdhci_cmd_irq()
3282 host->cmd->error = -ETIMEDOUT; in sdhci_cmd_irq()
3283 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_cmd_irq()
3285 host->cmd->error = -EILSEQ; in sdhci_cmd_irq()
3286 if (!mmc_op_tuning(host->cmd->opcode)) in sdhci_cmd_irq()
3287 sdhci_err_stats_inc(host, CMD_CRC); in sdhci_cmd_irq()
3290 if (host->cmd->data && in sdhci_cmd_irq()
3293 host->cmd = NULL; in sdhci_cmd_irq()
3298 __sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_cmd_irq()
3304 struct mmc_request *mrq = host->cmd->mrq; in sdhci_cmd_irq()
3305 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3310 sdhci_err_stats_inc(host, AUTO_CMD); in sdhci_cmd_irq()
3312 if (sdhci_auto_cmd23(host, mrq)) { in sdhci_cmd_irq()
3314 __sdhci_finish_mrq(host, mrq); in sdhci_cmd_irq()
3320 sdhci_finish_command(host); in sdhci_cmd_irq()
3323 static void sdhci_adma_show_error(struct sdhci_host *host) in sdhci_adma_show_error() argument
3325 void *desc = host->adma_table; in sdhci_adma_show_error()
3326 dma_addr_t dma = host->adma_addr; in sdhci_adma_show_error()
3328 sdhci_dumpregs(host); in sdhci_adma_show_error()
3333 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_show_error()
3347 desc += host->desc_sz; in sdhci_adma_show_error()
3348 dma += host->desc_sz; in sdhci_adma_show_error()
3355 static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) in sdhci_data_irq() argument
3364 if (intmask & SDHCI_INT_DATA_AVAIL && !host->data) { in sdhci_data_irq()
3365 if (mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) { in sdhci_data_irq()
3366 host->tuning_done = 1; in sdhci_data_irq()
3367 wake_up(&host->buf_ready_int); in sdhci_data_irq()
3372 if (!host->data) { in sdhci_data_irq()
3373 struct mmc_command *data_cmd = host->data_cmd; in sdhci_data_irq()
3382 host->data_cmd = NULL; in sdhci_data_irq()
3384 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_data_irq()
3385 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3389 host->data_cmd = NULL; in sdhci_data_irq()
3395 if (host->cmd == data_cmd) in sdhci_data_irq()
3398 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3408 if (host->pending_reset) in sdhci_data_irq()
3412 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_data_irq()
3413 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_data_irq()
3414 sdhci_dumpregs(host); in sdhci_data_irq()
3420 host->data->error = -ETIMEDOUT; in sdhci_data_irq()
3421 sdhci_err_stats_inc(host, DAT_TIMEOUT); in sdhci_data_irq()
3423 host->data->error = -EILSEQ; in sdhci_data_irq()
3424 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_data_irq()
3425 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_data_irq()
3427 SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) in sdhci_data_irq()
3429 host->data->error = -EILSEQ; in sdhci_data_irq()
3430 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_data_irq()
3431 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_data_irq()
3433 u16 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_data_irq()
3436 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_data_irq()
3439 pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc), in sdhci_data_irq()
3441 sdhci_adma_show_error(host); in sdhci_data_irq()
3442 sdhci_err_stats_inc(host, ADMA); in sdhci_data_irq()
3443 host->data->error = -EIO; in sdhci_data_irq()
3444 if (host->ops->adma_workaround) in sdhci_data_irq()
3445 host->ops->adma_workaround(host, intmask); in sdhci_data_irq()
3448 if (host->data->error) in sdhci_data_irq()
3449 sdhci_finish_data(host); in sdhci_data_irq()
3452 sdhci_transfer_pio(host); in sdhci_data_irq()
3459 * According to the spec sdhci_readl(host, SDHCI_DMA_ADDRESS) in sdhci_data_irq()
3466 dmastart = sdhci_sdma_address(host); in sdhci_data_irq()
3467 dmanow = dmastart + host->data->bytes_xfered; in sdhci_data_irq()
3474 host->data->bytes_xfered = dmanow - dmastart; in sdhci_data_irq()
3476 &dmastart, host->data->bytes_xfered, &dmanow); in sdhci_data_irq()
3477 sdhci_set_sdma_addr(host, dmanow); in sdhci_data_irq()
3481 if (host->cmd == host->data_cmd) { in sdhci_data_irq()
3487 host->data_early = 1; in sdhci_data_irq()
3489 sdhci_finish_data(host); in sdhci_data_irq()
3495 static inline bool sdhci_defer_done(struct sdhci_host *host, in sdhci_defer_done() argument
3500 return host->pending_reset || host->always_defer_done || in sdhci_defer_done()
3501 ((host->flags & SDHCI_REQ_USE_DMA) && data && in sdhci_defer_done()
3509 struct sdhci_host *host = dev_id; in sdhci_irq() local
3514 spin_lock(&host->lock); in sdhci_irq()
3516 if (host->runtime_suspended) { in sdhci_irq()
3517 spin_unlock(&host->lock); in sdhci_irq()
3521 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3530 if (host->ops->irq) { in sdhci_irq()
3531 intmask = host->ops->irq(host, intmask); in sdhci_irq()
3539 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_irq()
3542 u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & in sdhci_irq()
3556 host->ier &= ~(SDHCI_INT_CARD_INSERT | in sdhci_irq()
3558 host->ier |= present ? SDHCI_INT_CARD_REMOVE : in sdhci_irq()
3560 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_irq()
3561 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_irq()
3563 sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3566 host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3572 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK, &intmask); in sdhci_irq()
3575 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); in sdhci_irq()
3579 mmc_hostname(host->mmc)); in sdhci_irq()
3582 mmc_retune_needed(host->mmc); in sdhci_irq()
3585 (host->ier & SDHCI_INT_CARD_INT)) { in sdhci_irq()
3586 sdhci_enable_sdio_irq_nolock(host, false); in sdhci_irq()
3587 sdio_signal_irq(host->mmc); in sdhci_irq()
3597 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_irq()
3603 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3608 struct mmc_request *mrq = host->mrqs_done[i]; in sdhci_irq()
3613 if (sdhci_defer_done(host, mrq)) { in sdhci_irq()
3617 host->mrqs_done[i] = NULL; in sdhci_irq()
3621 if (host->deferred_cmd) in sdhci_irq()
3624 spin_unlock(&host->lock); in sdhci_irq()
3631 if (host->ops->request_done) in sdhci_irq()
3632 host->ops->request_done(host, mrqs_done[i]); in sdhci_irq()
3634 mmc_request_done(host->mmc, mrqs_done[i]); in sdhci_irq()
3639 mmc_hostname(host->mmc), unexpected); in sdhci_irq()
3640 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_irq()
3641 sdhci_dumpregs(host); in sdhci_irq()
3649 struct sdhci_host *host = dev_id; in sdhci_thread_irq() local
3654 while (!sdhci_request_done(host)) in sdhci_thread_irq()
3657 spin_lock_irqsave(&host->lock, flags); in sdhci_thread_irq()
3659 isr = host->thread_isr; in sdhci_thread_irq()
3660 host->thread_isr = 0; in sdhci_thread_irq()
3662 cmd = host->deferred_cmd; in sdhci_thread_irq()
3663 if (cmd && !sdhci_send_command_retry(host, cmd, flags)) in sdhci_thread_irq()
3664 sdhci_finish_mrq(host, cmd->mrq); in sdhci_thread_irq()
3666 spin_unlock_irqrestore(&host->lock, flags); in sdhci_thread_irq()
3669 struct mmc_host *mmc = host->mmc; in sdhci_thread_irq()
3686 static bool sdhci_cd_irq_can_wakeup(struct sdhci_host *host) in sdhci_cd_irq_can_wakeup() argument
3688 return mmc_card_is_removable(host->mmc) && in sdhci_cd_irq_can_wakeup()
3689 !(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_cd_irq_can_wakeup()
3690 !mmc_can_gpio_cd(host->mmc); in sdhci_cd_irq_can_wakeup()
3696 * Table' in the SD Host Controller Standard Specification.
3701 static bool sdhci_enable_irq_wakeups(struct sdhci_host *host) in sdhci_enable_irq_wakeups() argument
3709 if (sdhci_cd_irq_can_wakeup(host)) { in sdhci_enable_irq_wakeups()
3714 if (mmc_card_wake_sdio_irq(host->mmc)) { in sdhci_enable_irq_wakeups()
3722 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3725 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3727 sdhci_writel(host, irq_val, SDHCI_INT_ENABLE); in sdhci_enable_irq_wakeups()
3729 host->irq_wake_enabled = !enable_irq_wake(host->irq); in sdhci_enable_irq_wakeups()
3731 return host->irq_wake_enabled; in sdhci_enable_irq_wakeups()
3734 static void sdhci_disable_irq_wakeups(struct sdhci_host *host) in sdhci_disable_irq_wakeups() argument
3740 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3742 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3744 disable_irq_wake(host->irq); in sdhci_disable_irq_wakeups()
3746 host->irq_wake_enabled = false; in sdhci_disable_irq_wakeups()
3749 int sdhci_suspend_host(struct sdhci_host *host) in sdhci_suspend_host() argument
3751 sdhci_disable_card_detection(host); in sdhci_suspend_host()
3753 mmc_retune_timer_stop(host->mmc); in sdhci_suspend_host()
3755 if (!device_may_wakeup(mmc_dev(host->mmc)) || in sdhci_suspend_host()
3756 !sdhci_enable_irq_wakeups(host)) { in sdhci_suspend_host()
3757 host->ier = 0; in sdhci_suspend_host()
3758 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_suspend_host()
3759 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_suspend_host()
3760 free_irq(host->irq, host); in sdhci_suspend_host()
3768 int sdhci_resume_host(struct sdhci_host *host) in sdhci_resume_host() argument
3770 struct mmc_host *mmc = host->mmc; in sdhci_resume_host()
3773 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_resume_host()
3774 if (host->ops->enable_dma) in sdhci_resume_host()
3775 host->ops->enable_dma(host); in sdhci_resume_host()
3779 (host->quirks2 & SDHCI_QUIRK2_HOST_OFF_CARD_ON)) { in sdhci_resume_host()
3780 /* Card keeps power but host controller does not */ in sdhci_resume_host()
3781 sdhci_init(host, 0); in sdhci_resume_host()
3782 host->pwr = 0; in sdhci_resume_host()
3783 host->clock = 0; in sdhci_resume_host()
3784 host->reinit_uhs = true; in sdhci_resume_host()
3787 sdhci_init(host, (mmc->pm_flags & MMC_PM_KEEP_POWER)); in sdhci_resume_host()
3790 if (host->irq_wake_enabled) { in sdhci_resume_host()
3791 sdhci_disable_irq_wakeups(host); in sdhci_resume_host()
3793 ret = request_threaded_irq(host->irq, sdhci_irq, in sdhci_resume_host()
3795 mmc_hostname(mmc), host); in sdhci_resume_host()
3800 sdhci_enable_card_detection(host); in sdhci_resume_host()
3807 int sdhci_runtime_suspend_host(struct sdhci_host *host) in sdhci_runtime_suspend_host() argument
3811 mmc_retune_timer_stop(host->mmc); in sdhci_runtime_suspend_host()
3813 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3814 host->ier &= SDHCI_INT_CARD_INT; in sdhci_runtime_suspend_host()
3815 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_runtime_suspend_host()
3816 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_runtime_suspend_host()
3817 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3819 synchronize_hardirq(host->irq); in sdhci_runtime_suspend_host()
3821 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3822 host->runtime_suspended = true; in sdhci_runtime_suspend_host()
3823 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3829 int sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset) in sdhci_runtime_resume_host() argument
3831 struct mmc_host *mmc = host->mmc; in sdhci_runtime_resume_host()
3833 int host_flags = host->flags; in sdhci_runtime_resume_host()
3836 if (host->ops->enable_dma) in sdhci_runtime_resume_host()
3837 host->ops->enable_dma(host); in sdhci_runtime_resume_host()
3840 sdhci_init(host, soft_reset); in sdhci_runtime_resume_host()
3845 host->pwr = 0; in sdhci_runtime_resume_host()
3846 host->clock = 0; in sdhci_runtime_resume_host()
3847 host->reinit_uhs = true; in sdhci_runtime_resume_host()
3852 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) { in sdhci_runtime_resume_host()
3853 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3854 sdhci_enable_preset_value(host, true); in sdhci_runtime_resume_host()
3855 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3863 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3865 host->runtime_suspended = false; in sdhci_runtime_resume_host()
3869 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_runtime_resume_host()
3872 sdhci_enable_card_detection(host); in sdhci_runtime_resume_host()
3874 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3890 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_enable() local
3894 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_enable()
3896 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3899 * Host from V4.10 supports ADMA3 DMA type. in sdhci_cqe_enable()
3903 if (host->v4_mode && (host->caps1 & SDHCI_CAN_DO_ADMA3)) in sdhci_cqe_enable()
3905 else if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_cqe_enable()
3909 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3911 sdhci_writew(host, SDHCI_MAKE_BLKSZ(host->sdma_boundary, 512), in sdhci_cqe_enable()
3915 sdhci_set_timeout(host, NULL); in sdhci_cqe_enable()
3917 host->ier = host->cqe_ier; in sdhci_cqe_enable()
3919 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_cqe_enable()
3920 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_cqe_enable()
3922 host->cqe_on = true; in sdhci_cqe_enable()
3925 mmc_hostname(mmc), host->ier, in sdhci_cqe_enable()
3926 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_enable()
3928 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_enable()
3934 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_disable() local
3937 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_disable()
3939 sdhci_set_default_irqs(host); in sdhci_cqe_disable()
3941 host->cqe_on = false; in sdhci_cqe_disable()
3944 sdhci_reset_for(host, CQE_RECOVERY); in sdhci_cqe_disable()
3947 mmc_hostname(mmc), host->ier, in sdhci_cqe_disable()
3948 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_disable()
3950 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_disable()
3954 bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error, in sdhci_cqe_irq() argument
3959 if (!host->cqe_on) in sdhci_cqe_irq()
3964 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_cqe_irq()
3965 sdhci_err_stats_inc(host, CMD_CRC); in sdhci_cqe_irq()
3968 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_cqe_irq()
3974 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_cqe_irq()
3975 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_cqe_irq()
3978 sdhci_err_stats_inc(host, DAT_TIMEOUT); in sdhci_cqe_irq()
3981 sdhci_err_stats_inc(host, ADMA); in sdhci_cqe_irq()
3986 mask = intmask & host->cqe_ier; in sdhci_cqe_irq()
3987 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
3991 mmc_hostname(host->mmc)); in sdhci_cqe_irq()
3993 intmask &= ~(host->cqe_ier | SDHCI_INT_ERROR); in sdhci_cqe_irq()
3995 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
3997 mmc_hostname(host->mmc), intmask); in sdhci_cqe_irq()
3998 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_cqe_irq()
3999 sdhci_dumpregs(host); in sdhci_cqe_irq()
4016 struct sdhci_host *host; in sdhci_alloc_host() local
4024 host = mmc_priv(mmc); in sdhci_alloc_host()
4025 host->mmc = mmc; in sdhci_alloc_host()
4026 host->mmc_host_ops = sdhci_ops; in sdhci_alloc_host()
4027 mmc->ops = &host->mmc_host_ops; in sdhci_alloc_host()
4029 host->flags = SDHCI_SIGNALING_330; in sdhci_alloc_host()
4031 host->cqe_ier = SDHCI_CQE_INT_MASK; in sdhci_alloc_host()
4032 host->cqe_err_ier = SDHCI_CQE_INT_ERR_MASK; in sdhci_alloc_host()
4034 host->tuning_delay = -1; in sdhci_alloc_host()
4035 host->tuning_loop_count = MAX_TUNING_LOOP; in sdhci_alloc_host()
4037 host->sdma_boundary = SDHCI_DEFAULT_BOUNDARY_ARG; in sdhci_alloc_host()
4044 host->adma_table_cnt = SDHCI_MAX_SEGS * 2 + 1; in sdhci_alloc_host()
4045 host->max_adma = 65536; in sdhci_alloc_host()
4047 host->max_timeout_count = 0xE; in sdhci_alloc_host()
4049 return host; in sdhci_alloc_host()
4054 static int sdhci_set_dma_mask(struct sdhci_host *host) in sdhci_set_dma_mask() argument
4056 struct mmc_host *mmc = host->mmc; in sdhci_set_dma_mask()
4060 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) in sdhci_set_dma_mask()
4061 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4064 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_set_dma_mask()
4069 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4084 void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver, in __sdhci_read_caps() argument
4091 if (host->read_caps) in __sdhci_read_caps()
4094 host->read_caps = true; in __sdhci_read_caps()
4097 host->quirks = debug_quirks; in __sdhci_read_caps()
4100 host->quirks2 = debug_quirks2; in __sdhci_read_caps()
4102 sdhci_reset_for_all(host); in __sdhci_read_caps()
4104 if (host->v4_mode) in __sdhci_read_caps()
4105 sdhci_do_enable_v4_mode(host); in __sdhci_read_caps()
4107 device_property_read_u64(mmc_dev(host->mmc), in __sdhci_read_caps()
4109 device_property_read_u64(mmc_dev(host->mmc), in __sdhci_read_caps()
4112 v = ver ? *ver : sdhci_readw(host, SDHCI_HOST_VERSION); in __sdhci_read_caps()
4113 host->version = (v & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; in __sdhci_read_caps()
4116 host->caps = *caps; in __sdhci_read_caps()
4118 host->caps = sdhci_readl(host, SDHCI_CAPABILITIES); in __sdhci_read_caps()
4119 host->caps &= ~lower_32_bits(dt_caps_mask); in __sdhci_read_caps()
4120 host->caps |= lower_32_bits(dt_caps); in __sdhci_read_caps()
4123 if (host->version < SDHCI_SPEC_300) in __sdhci_read_caps()
4127 host->caps1 = *caps1; in __sdhci_read_caps()
4129 host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); in __sdhci_read_caps()
4130 host->caps1 &= ~upper_32_bits(dt_caps_mask); in __sdhci_read_caps()
4131 host->caps1 |= upper_32_bits(dt_caps); in __sdhci_read_caps()
4136 static void sdhci_allocate_bounce_buffer(struct sdhci_host *host) in sdhci_allocate_bounce_buffer() argument
4138 struct mmc_host *mmc = host->mmc; in sdhci_allocate_bounce_buffer()
4163 host->bounce_buffer = devm_kmalloc(mmc_dev(mmc), in sdhci_allocate_bounce_buffer()
4166 if (!host->bounce_buffer) { in sdhci_allocate_bounce_buffer()
4177 host->bounce_addr = dma_map_single(mmc_dev(mmc), in sdhci_allocate_bounce_buffer()
4178 host->bounce_buffer, in sdhci_allocate_bounce_buffer()
4181 ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr); in sdhci_allocate_bounce_buffer()
4183 devm_kfree(mmc_dev(mmc), host->bounce_buffer); in sdhci_allocate_bounce_buffer()
4184 host->bounce_buffer = NULL; in sdhci_allocate_bounce_buffer()
4189 host->bounce_buffer_size = bounce_size; in sdhci_allocate_bounce_buffer()
4200 static inline bool sdhci_can_64bit_dma(struct sdhci_host *host) in sdhci_can_64bit_dma() argument
4203 * According to SD Host Controller spec v4.10, bit[27] added from in sdhci_can_64bit_dma()
4207 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) in sdhci_can_64bit_dma()
4208 return host->caps & SDHCI_CAN_64BIT_V4; in sdhci_can_64bit_dma()
4210 return host->caps & SDHCI_CAN_64BIT; in sdhci_can_64bit_dma()
4213 int sdhci_setup_host(struct sdhci_host *host) in sdhci_setup_host() argument
4223 WARN_ON(host == NULL); in sdhci_setup_host()
4224 if (host == NULL) in sdhci_setup_host()
4227 mmc = host->mmc; in sdhci_setup_host()
4231 * early before resetting the host and reading the capabilities so that in sdhci_setup_host()
4232 * the host can take the appropriate action if regulators are not in sdhci_setup_host()
4243 sdhci_readw(host, SDHCI_HOST_VERSION), in sdhci_setup_host()
4244 sdhci_readl(host, SDHCI_PRESENT_STATE)); in sdhci_setup_host()
4246 sdhci_readl(host, SDHCI_CAPABILITIES), in sdhci_setup_host()
4247 sdhci_readl(host, SDHCI_CAPABILITIES_1)); in sdhci_setup_host()
4249 sdhci_read_caps(host); in sdhci_setup_host()
4251 override_timeout_clk = host->timeout_clk; in sdhci_setup_host()
4253 if (host->version > SDHCI_SPEC_420) { in sdhci_setup_host()
4255 mmc_hostname(mmc), host->version); in sdhci_setup_host()
4258 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) in sdhci_setup_host()
4259 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4260 else if (!(host->caps & SDHCI_CAN_DO_SDMA)) in sdhci_setup_host()
4263 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4265 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && in sdhci_setup_host()
4266 (host->flags & SDHCI_USE_SDMA)) { in sdhci_setup_host()
4268 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4271 if ((host->version >= SDHCI_SPEC_200) && in sdhci_setup_host()
4272 (host->caps & SDHCI_CAN_DO_ADMA2)) in sdhci_setup_host()
4273 host->flags |= SDHCI_USE_ADMA; in sdhci_setup_host()
4275 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && in sdhci_setup_host()
4276 (host->flags & SDHCI_USE_ADMA)) { in sdhci_setup_host()
4278 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4281 if (sdhci_can_64bit_dma(host)) in sdhci_setup_host()
4282 host->flags |= SDHCI_USE_64_BIT_DMA; in sdhci_setup_host()
4284 if (host->use_external_dma) { in sdhci_setup_host()
4285 ret = sdhci_external_dma_init(host); in sdhci_setup_host()
4293 sdhci_switch_external_dma(host, false); in sdhci_setup_host()
4296 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4299 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_setup_host()
4300 if (host->ops->set_dma_mask) in sdhci_setup_host()
4301 ret = host->ops->set_dma_mask(host); in sdhci_setup_host()
4303 ret = sdhci_set_dma_mask(host); in sdhci_setup_host()
4305 if (!ret && host->ops->enable_dma) in sdhci_setup_host()
4306 ret = host->ops->enable_dma(host); in sdhci_setup_host()
4311 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4318 if ((host->flags & SDHCI_USE_64_BIT_DMA) && !host->v4_mode) in sdhci_setup_host()
4319 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4321 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4325 if (!(host->flags & SDHCI_USE_64_BIT_DMA)) in sdhci_setup_host()
4326 host->alloc_desc_sz = SDHCI_ADMA2_32_DESC_SZ; in sdhci_setup_host()
4327 else if (!host->alloc_desc_sz) in sdhci_setup_host()
4328 host->alloc_desc_sz = SDHCI_ADMA2_64_DESC_SZ(host); in sdhci_setup_host()
4330 host->desc_sz = host->alloc_desc_sz; in sdhci_setup_host()
4331 host->adma_table_sz = host->adma_table_cnt * host->desc_sz; in sdhci_setup_host()
4333 host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN; in sdhci_setup_host()
4339 host->align_buffer_sz + host->adma_table_sz, in sdhci_setup_host()
4344 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4345 } else if ((dma + host->align_buffer_sz) & in sdhci_setup_host()
4349 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4350 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4351 host->adma_table_sz, buf, dma); in sdhci_setup_host()
4353 host->align_buffer = buf; in sdhci_setup_host()
4354 host->align_addr = dma; in sdhci_setup_host()
4356 host->adma_table = buf + host->align_buffer_sz; in sdhci_setup_host()
4357 host->adma_addr = dma + host->align_buffer_sz; in sdhci_setup_host()
4366 if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) { in sdhci_setup_host()
4367 host->dma_mask = DMA_BIT_MASK(64); in sdhci_setup_host()
4368 mmc_dev(mmc)->dma_mask = &host->dma_mask; in sdhci_setup_host()
4371 if (host->version >= SDHCI_SPEC_300) in sdhci_setup_host()
4372 host->max_clk = FIELD_GET(SDHCI_CLOCK_V3_BASE_MASK, host->caps); in sdhci_setup_host()
4374 host->max_clk = FIELD_GET(SDHCI_CLOCK_BASE_MASK, host->caps); in sdhci_setup_host()
4376 host->max_clk *= 1000000; in sdhci_setup_host()
4377 if (host->max_clk == 0 || host->quirks & in sdhci_setup_host()
4379 if (!host->ops->get_max_clock) { in sdhci_setup_host()
4385 host->max_clk = host->ops->get_max_clock(host); in sdhci_setup_host()
4389 * In case of Host Controller v3.00, find out whether clock in sdhci_setup_host()
4392 host->clk_mul = FIELD_GET(SDHCI_CLOCK_MUL_MASK, host->caps1); in sdhci_setup_host()
4400 if (host->clk_mul) in sdhci_setup_host()
4401 host->clk_mul += 1; in sdhci_setup_host()
4404 * Set host parameters. in sdhci_setup_host()
4406 max_clk = host->max_clk; in sdhci_setup_host()
4408 if (host->ops->get_min_clock) in sdhci_setup_host()
4409 mmc->f_min = host->ops->get_min_clock(host); in sdhci_setup_host()
4410 else if (host->version >= SDHCI_SPEC_300) { in sdhci_setup_host()
4411 if (host->clk_mul) in sdhci_setup_host()
4412 max_clk = host->max_clk * host->clk_mul; in sdhci_setup_host()
4417 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300; in sdhci_setup_host()
4419 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; in sdhci_setup_host()
4424 if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { in sdhci_setup_host()
4425 host->timeout_clk = FIELD_GET(SDHCI_TIMEOUT_CLK_MASK, host->caps); in sdhci_setup_host()
4427 if (host->caps & SDHCI_TIMEOUT_CLK_UNIT) in sdhci_setup_host()
4428 host->timeout_clk *= 1000; in sdhci_setup_host()
4430 if (host->timeout_clk == 0) { in sdhci_setup_host()
4431 if (!host->ops->get_timeout_clock) { in sdhci_setup_host()
4438 host->timeout_clk = in sdhci_setup_host()
4439 DIV_ROUND_UP(host->ops->get_timeout_clock(host), in sdhci_setup_host()
4444 host->timeout_clk = override_timeout_clk; in sdhci_setup_host()
4446 mmc->max_busy_timeout = host->ops->get_max_timeout_count ? in sdhci_setup_host()
4447 host->ops->get_max_timeout_count(host) : 1 << 27; in sdhci_setup_host()
4448 mmc->max_busy_timeout /= host->timeout_clk; in sdhci_setup_host()
4451 if (host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT && in sdhci_setup_host()
4452 !host->ops->get_max_timeout_count) in sdhci_setup_host()
4458 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) in sdhci_setup_host()
4459 host->flags |= SDHCI_AUTO_CMD12; in sdhci_setup_host()
4465 if ((host->version >= SDHCI_SPEC_300) && in sdhci_setup_host()
4466 ((host->flags & SDHCI_USE_ADMA) || in sdhci_setup_host()
4467 !(host->flags & SDHCI_USE_SDMA) || host->v4_mode) && in sdhci_setup_host()
4468 !(host->quirks2 & SDHCI_QUIRK2_ACMD23_BROKEN)) { in sdhci_setup_host()
4469 host->flags |= SDHCI_AUTO_CMD23; in sdhci_setup_host()
4482 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) in sdhci_setup_host()
4485 if (host->quirks2 & SDHCI_QUIRK2_HOST_NO_CMD23) in sdhci_setup_host()
4488 if (host->caps & SDHCI_CAN_DO_HISPD) in sdhci_setup_host()
4491 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_setup_host()
4499 host->sdhci_core_to_disable_vqmmc = !ret; in sdhci_setup_host()
4505 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | in sdhci_setup_host()
4512 host->flags &= ~SDHCI_SIGNALING_330; in sdhci_setup_host()
4522 if (host->quirks2 & SDHCI_QUIRK2_NO_1_8_V) { in sdhci_setup_host()
4523 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4538 if (host->caps1 & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4543 if (host->caps1 & SDHCI_SUPPORT_SDR104) { in sdhci_setup_host()
4548 if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) in sdhci_setup_host()
4550 } else if (host->caps1 & SDHCI_SUPPORT_SDR50) { in sdhci_setup_host()
4554 if (host->quirks2 & SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 && in sdhci_setup_host()
4555 (host->caps1 & SDHCI_SUPPORT_HS400)) in sdhci_setup_host()
4564 if ((host->caps1 & SDHCI_SUPPORT_DDR50) && in sdhci_setup_host()
4565 !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50)) in sdhci_setup_host()
4568 /* Does the host need tuning for SDR50? */ in sdhci_setup_host()
4569 if (host->caps1 & SDHCI_USE_SDR50_TUNING) in sdhci_setup_host()
4570 host->flags |= SDHCI_SDR50_NEEDS_TUNING; in sdhci_setup_host()
4572 /* Driver Type(s) (A, C, D) supported by the host */ in sdhci_setup_host()
4573 if (host->caps1 & SDHCI_DRIVER_TYPE_A) in sdhci_setup_host()
4575 if (host->caps1 & SDHCI_DRIVER_TYPE_C) in sdhci_setup_host()
4577 if (host->caps1 & SDHCI_DRIVER_TYPE_D) in sdhci_setup_host()
4581 host->tuning_count = FIELD_GET(SDHCI_RETUNING_TIMER_COUNT_MASK, in sdhci_setup_host()
4582 host->caps1); in sdhci_setup_host()
4588 if (host->tuning_count) in sdhci_setup_host()
4589 host->tuning_count = 1 << (host->tuning_count - 1); in sdhci_setup_host()
4591 /* Re-tuning mode supported by the Host Controller */ in sdhci_setup_host()
4592 host->tuning_mode = FIELD_GET(SDHCI_RETUNING_MODE_MASK, host->caps1); in sdhci_setup_host()
4597 * According to SD Host Controller spec v3.00, if the Host System in sdhci_setup_host()
4598 * can afford more than 150mA, Host Driver should set XPC to 1. Also in sdhci_setup_host()
4603 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); in sdhci_setup_host()
4620 if (host->caps & SDHCI_CAN_VDD_330) { in sdhci_setup_host()
4627 if (host->caps & SDHCI_CAN_VDD_300) { in sdhci_setup_host()
4634 if (host->caps & SDHCI_CAN_VDD_180) { in sdhci_setup_host()
4642 /* If OCR set by host, use it instead. */ in sdhci_setup_host()
4643 if (host->ocr_mask) in sdhci_setup_host()
4644 ocr_avail = host->ocr_mask; in sdhci_setup_host()
4652 if (host->ocr_avail_sdio) in sdhci_setup_host()
4653 mmc->ocr_avail_sdio &= host->ocr_avail_sdio; in sdhci_setup_host()
4655 if (host->ocr_avail_sd) in sdhci_setup_host()
4656 mmc->ocr_avail_sd &= host->ocr_avail_sd; in sdhci_setup_host()
4660 if (host->ocr_avail_mmc) in sdhci_setup_host()
4661 mmc->ocr_avail_mmc &= host->ocr_avail_mmc; in sdhci_setup_host()
4674 host->flags |= SDHCI_SIGNALING_180; in sdhci_setup_host()
4677 host->flags |= SDHCI_SIGNALING_120; in sdhci_setup_host()
4679 spin_lock_init(&host->lock); in sdhci_setup_host()
4692 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4694 } else if (host->flags & SDHCI_USE_SDMA) { in sdhci_setup_host()
4707 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4708 if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) { in sdhci_setup_host()
4709 host->max_adma = 65532; /* 32-bit alignment */ in sdhci_setup_host()
4737 if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) { in sdhci_setup_host()
4740 mmc->max_blk_size = (host->caps & SDHCI_MAX_BLOCK_MASK) >> in sdhci_setup_host()
4754 mmc->max_blk_count = (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; in sdhci_setup_host()
4758 sdhci_allocate_bounce_buffer(host); in sdhci_setup_host()
4763 if (host->sdhci_core_to_disable_vqmmc) in sdhci_setup_host()
4766 if (host->align_buffer) in sdhci_setup_host()
4767 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4768 host->adma_table_sz, host->align_buffer, in sdhci_setup_host()
4769 host->align_addr); in sdhci_setup_host()
4770 host->adma_table = NULL; in sdhci_setup_host()
4771 host->align_buffer = NULL; in sdhci_setup_host()
4777 void sdhci_cleanup_host(struct sdhci_host *host) in sdhci_cleanup_host() argument
4779 struct mmc_host *mmc = host->mmc; in sdhci_cleanup_host()
4781 if (host->sdhci_core_to_disable_vqmmc) in sdhci_cleanup_host()
4784 if (host->align_buffer) in sdhci_cleanup_host()
4785 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_cleanup_host()
4786 host->adma_table_sz, host->align_buffer, in sdhci_cleanup_host()
4787 host->align_addr); in sdhci_cleanup_host()
4789 if (host->use_external_dma) in sdhci_cleanup_host()
4790 sdhci_external_dma_release(host); in sdhci_cleanup_host()
4792 host->adma_table = NULL; in sdhci_cleanup_host()
4793 host->align_buffer = NULL; in sdhci_cleanup_host()
4797 int __sdhci_add_host(struct sdhci_host *host) in __sdhci_add_host() argument
4800 struct mmc_host *mmc = host->mmc; in __sdhci_add_host()
4804 (host->quirks & SDHCI_QUIRK_BROKEN_CQE)) { in __sdhci_add_host()
4809 host->complete_wq = alloc_workqueue("sdhci", flags, 0); in __sdhci_add_host()
4810 if (!host->complete_wq) in __sdhci_add_host()
4813 INIT_WORK(&host->complete_work, sdhci_complete_work); in __sdhci_add_host()
4815 timer_setup(&host->timer, sdhci_timeout_timer, 0); in __sdhci_add_host()
4816 timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0); in __sdhci_add_host()
4818 init_waitqueue_head(&host->buf_ready_int); in __sdhci_add_host()
4820 sdhci_init(host, 0); in __sdhci_add_host()
4822 ret = request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq, in __sdhci_add_host()
4823 IRQF_SHARED, mmc_hostname(mmc), host); in __sdhci_add_host()
4826 mmc_hostname(mmc), host->irq, ret); in __sdhci_add_host()
4830 ret = sdhci_led_register(host); in __sdhci_add_host()
4842 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), in __sdhci_add_host()
4843 host->use_external_dma ? "External DMA" : in __sdhci_add_host()
4844 (host->flags & SDHCI_USE_ADMA) ? in __sdhci_add_host()
4845 (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" : in __sdhci_add_host()
4846 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); in __sdhci_add_host()
4848 sdhci_enable_card_detection(host); in __sdhci_add_host()
4853 sdhci_led_unregister(host); in __sdhci_add_host()
4855 sdhci_reset_for_all(host); in __sdhci_add_host()
4856 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in __sdhci_add_host()
4857 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in __sdhci_add_host()
4858 free_irq(host->irq, host); in __sdhci_add_host()
4860 destroy_workqueue(host->complete_wq); in __sdhci_add_host()
4866 int sdhci_add_host(struct sdhci_host *host) in sdhci_add_host() argument
4870 ret = sdhci_setup_host(host); in sdhci_add_host()
4874 ret = __sdhci_add_host(host); in sdhci_add_host()
4881 sdhci_cleanup_host(host); in sdhci_add_host()
4887 void sdhci_remove_host(struct sdhci_host *host, int dead) in sdhci_remove_host() argument
4889 struct mmc_host *mmc = host->mmc; in sdhci_remove_host()
4893 spin_lock_irqsave(&host->lock, flags); in sdhci_remove_host()
4895 host->flags |= SDHCI_DEVICE_DEAD; in sdhci_remove_host()
4897 if (sdhci_has_requests(host)) { in sdhci_remove_host()
4900 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_remove_host()
4903 spin_unlock_irqrestore(&host->lock, flags); in sdhci_remove_host()
4906 sdhci_disable_card_detection(host); in sdhci_remove_host()
4910 sdhci_led_unregister(host); in sdhci_remove_host()
4913 sdhci_reset_for_all(host); in sdhci_remove_host()
4915 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_remove_host()
4916 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_remove_host()
4917 free_irq(host->irq, host); in sdhci_remove_host()
4919 del_timer_sync(&host->timer); in sdhci_remove_host()
4920 del_timer_sync(&host->data_timer); in sdhci_remove_host()
4922 destroy_workqueue(host->complete_wq); in sdhci_remove_host()
4924 if (host->sdhci_core_to_disable_vqmmc) in sdhci_remove_host()
4927 if (host->align_buffer) in sdhci_remove_host()
4928 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_remove_host()
4929 host->adma_table_sz, host->align_buffer, in sdhci_remove_host()
4930 host->align_addr); in sdhci_remove_host()
4932 if (host->use_external_dma) in sdhci_remove_host()
4933 sdhci_external_dma_release(host); in sdhci_remove_host()
4935 host->adma_table = NULL; in sdhci_remove_host()
4936 host->align_buffer = NULL; in sdhci_remove_host()
4941 void sdhci_free_host(struct sdhci_host *host) in sdhci_free_host() argument
4943 mmc_free_host(host->mmc); in sdhci_free_host()
4957 ": Secure Digital Host Controller Interface driver\n"); in sdhci_drv_init()
4974 MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");