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
275 sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); in sdhci_reset_for_reason()
281 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_reset_for_reason()
282 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_reset_for_reason()
285 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_reset_for_reason()
292 static void sdhci_set_default_irqs(struct sdhci_host *host) in sdhci_set_default_irqs() argument
294 host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | in sdhci_set_default_irqs()
300 if (host->tuning_mode == SDHCI_TUNING_MODE_2 || in sdhci_set_default_irqs()
301 host->tuning_mode == SDHCI_TUNING_MODE_3) in sdhci_set_default_irqs()
302 host->ier |= SDHCI_INT_RETUNE; in sdhci_set_default_irqs()
304 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_default_irqs()
305 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_default_irqs()
308 static void sdhci_config_dma(struct sdhci_host *host) in sdhci_config_dma() argument
313 if (host->version < SDHCI_SPEC_200) in sdhci_config_dma()
316 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_config_dma()
324 if (!(host->flags & SDHCI_REQ_USE_DMA)) in sdhci_config_dma()
328 if (host->flags & SDHCI_USE_ADMA) in sdhci_config_dma()
331 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_config_dma()
337 if (host->v4_mode) { in sdhci_config_dma()
338 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
340 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
341 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_config_dma()
351 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_config_dma()
354 static void sdhci_init(struct sdhci_host *host, int soft) in sdhci_init() argument
356 struct mmc_host *mmc = host->mmc; in sdhci_init()
360 sdhci_reset_for(host, INIT); in sdhci_init()
362 sdhci_reset_for_all(host); in sdhci_init()
364 if (host->v4_mode) in sdhci_init()
365 sdhci_do_enable_v4_mode(host); in sdhci_init()
367 spin_lock_irqsave(&host->lock, flags); in sdhci_init()
368 sdhci_set_default_irqs(host); in sdhci_init()
369 spin_unlock_irqrestore(&host->lock, flags); in sdhci_init()
371 host->cqe_on = false; in sdhci_init()
375 host->clock = 0; in sdhci_init()
376 host->reinit_uhs = true; in sdhci_init()
381 static void sdhci_reinit(struct sdhci_host *host) in sdhci_reinit() argument
383 u32 cd = host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); in sdhci_reinit()
385 sdhci_init(host, 0); in sdhci_reinit()
386 sdhci_enable_card_detection(host); in sdhci_reinit()
391 * been missed while the host controller was being reset, so trigger a in sdhci_reinit()
394 if (cd != (host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT))) in sdhci_reinit()
395 mmc_detect_change(host->mmc, msecs_to_jiffies(200)); in sdhci_reinit()
398 static void __sdhci_led_activate(struct sdhci_host *host) in __sdhci_led_activate() argument
402 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_activate()
405 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
407 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
410 static void __sdhci_led_deactivate(struct sdhci_host *host) in __sdhci_led_deactivate() argument
414 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_deactivate()
417 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
419 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
426 struct sdhci_host *host = container_of(led, struct sdhci_host, led); in sdhci_led_control() local
429 spin_lock_irqsave(&host->lock, flags); in sdhci_led_control()
431 if (host->runtime_suspended) in sdhci_led_control()
435 __sdhci_led_deactivate(host); in sdhci_led_control()
437 __sdhci_led_activate(host); in sdhci_led_control()
439 spin_unlock_irqrestore(&host->lock, flags); in sdhci_led_control()
442 static int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
444 struct mmc_host *mmc = host->mmc; in sdhci_led_register()
446 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_register()
449 snprintf(host->led_name, sizeof(host->led_name), in sdhci_led_register()
452 host->led.name = host->led_name; in sdhci_led_register()
453 host->led.brightness = LED_OFF; in sdhci_led_register()
454 host->led.default_trigger = mmc_hostname(mmc); in sdhci_led_register()
455 host->led.brightness_set = sdhci_led_control; in sdhci_led_register()
457 return led_classdev_register(mmc_dev(mmc), &host->led); in sdhci_led_register()
460 static void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
462 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_unregister()
465 led_classdev_unregister(&host->led); in sdhci_led_unregister()
468 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
472 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
478 static inline int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
483 static inline void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
487 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
489 __sdhci_led_activate(host); in sdhci_led_activate()
492 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
494 __sdhci_led_deactivate(host); in sdhci_led_deactivate()
499 static void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, in sdhci_mod_timer() argument
503 mod_timer(&host->data_timer, timeout); in sdhci_mod_timer()
505 mod_timer(&host->timer, timeout); in sdhci_mod_timer()
508 static void sdhci_del_timer(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_del_timer() argument
511 del_timer(&host->data_timer); in sdhci_del_timer()
513 del_timer(&host->timer); in sdhci_del_timer()
516 static inline bool sdhci_has_requests(struct sdhci_host *host) in sdhci_has_requests() argument
518 return host->cmd || host->data_cmd; in sdhci_has_requests()
527 static void sdhci_read_block_pio(struct sdhci_host *host) in sdhci_read_block_pio() argument
536 blksize = host->data->blksz; in sdhci_read_block_pio()
542 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_read_block_pio()
544 len = min(host->sg_miter.length, blksize); in sdhci_read_block_pio()
547 host->sg_miter.consumed = len; in sdhci_read_block_pio()
549 buf = host->sg_miter.addr; in sdhci_read_block_pio()
553 scratch = sdhci_readl(host, SDHCI_BUFFER); in sdhci_read_block_pio()
566 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
580 blksize = host->data->blksz; in sdhci_write_block_pio()
587 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_write_block_pio()
589 len = min(host->sg_miter.length, blksize); in sdhci_write_block_pio()
592 host->sg_miter.consumed = len; in sdhci_write_block_pio()
594 buf = host->sg_miter.addr; in sdhci_write_block_pio()
604 sdhci_writel(host, scratch, SDHCI_BUFFER); in sdhci_write_block_pio()
611 sg_miter_stop(&host->sg_miter); in sdhci_write_block_pio()
616 static void sdhci_transfer_pio(struct sdhci_host *host) in sdhci_transfer_pio() argument
620 if (host->blocks == 0) in sdhci_transfer_pio()
623 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
633 if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) && in sdhci_transfer_pio()
634 (host->data->blocks == 1)) in sdhci_transfer_pio()
637 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { in sdhci_transfer_pio()
638 if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY) in sdhci_transfer_pio()
641 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
642 sdhci_read_block_pio(host); in sdhci_transfer_pio()
644 sdhci_write_block_pio(host); in sdhci_transfer_pio()
646 host->blocks--; in sdhci_transfer_pio()
647 if (host->blocks == 0) in sdhci_transfer_pio()
654 static int sdhci_pre_dma_transfer(struct sdhci_host *host, in sdhci_pre_dma_transfer() argument
667 if (host->bounce_buffer) { in sdhci_pre_dma_transfer()
670 if (length > host->bounce_buffer_size) { in sdhci_pre_dma_transfer()
672 mmc_hostname(host->mmc), length, in sdhci_pre_dma_transfer()
673 host->bounce_buffer_size); in sdhci_pre_dma_transfer()
678 if (host->ops->copy_to_bounce_buffer) { in sdhci_pre_dma_transfer()
679 host->ops->copy_to_bounce_buffer(host, in sdhci_pre_dma_transfer()
683 host->bounce_buffer, length); in sdhci_pre_dma_transfer()
687 dma_sync_single_for_device(mmc_dev(host->mmc), in sdhci_pre_dma_transfer()
688 host->bounce_addr, in sdhci_pre_dma_transfer()
689 host->bounce_buffer_size, in sdhci_pre_dma_transfer()
695 sg_count = dma_map_sg(mmc_dev(host->mmc), in sdhci_pre_dma_transfer()
721 void sdhci_adma_write_desc(struct sdhci_host *host, void **desc, in sdhci_adma_write_desc() argument
731 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_write_desc()
734 *desc += host->desc_sz; in sdhci_adma_write_desc()
738 static inline void __sdhci_adma_write_desc(struct sdhci_host *host, in __sdhci_adma_write_desc() argument
742 if (host->ops->adma_write_desc) in __sdhci_adma_write_desc()
743 host->ops->adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
745 sdhci_adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
756 static void sdhci_adma_table_pre(struct sdhci_host *host, in sdhci_adma_table_pre() argument
771 host->sg_count = sg_count; in sdhci_adma_table_pre()
773 desc = host->adma_table; in sdhci_adma_table_pre()
774 align = host->align_buffer; in sdhci_adma_table_pre()
776 align_addr = host->align_addr; in sdhci_adma_table_pre()
778 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_pre()
798 __sdhci_adma_write_desc(host, &desc, align_addr, in sdhci_adma_table_pre()
816 while (len > host->max_adma) { in sdhci_adma_table_pre()
819 __sdhci_adma_write_desc(host, &desc, addr, n, ADMA2_TRAN_VALID); in sdhci_adma_table_pre()
826 __sdhci_adma_write_desc(host, &desc, addr, len, in sdhci_adma_table_pre()
833 WARN_ON((desc - host->adma_table) >= host->adma_table_sz); in sdhci_adma_table_pre()
836 if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) { in sdhci_adma_table_pre()
838 if (desc != host->adma_table) { in sdhci_adma_table_pre()
839 desc -= host->desc_sz; in sdhci_adma_table_pre()
844 __sdhci_adma_write_desc(host, &desc, 0, 0, ADMA2_NOP_END_VALID); in sdhci_adma_table_pre()
848 static void sdhci_adma_table_post(struct sdhci_host *host, in sdhci_adma_table_post() argument
861 for_each_sg(data->sg, sg, host->sg_count, i) in sdhci_adma_table_post()
868 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, in sdhci_adma_table_post()
871 align = host->align_buffer; in sdhci_adma_table_post()
873 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_post()
889 static void sdhci_set_adma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_adma_addr() argument
891 sdhci_writel(host, lower_32_bits(addr), SDHCI_ADMA_ADDRESS); in sdhci_set_adma_addr()
892 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_set_adma_addr()
893 sdhci_writel(host, upper_32_bits(addr), SDHCI_ADMA_ADDRESS_HI); in sdhci_set_adma_addr()
896 static dma_addr_t sdhci_sdma_address(struct sdhci_host *host) in sdhci_sdma_address() argument
898 if (host->bounce_buffer) in sdhci_sdma_address()
899 return host->bounce_addr; in sdhci_sdma_address()
901 return sg_dma_address(host->data->sg); in sdhci_sdma_address()
904 static void sdhci_set_sdma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_sdma_addr() argument
906 if (host->v4_mode) in sdhci_set_sdma_addr()
907 sdhci_set_adma_addr(host, addr); in sdhci_set_sdma_addr()
909 sdhci_writel(host, addr, SDHCI_DMA_ADDRESS); in sdhci_set_sdma_addr()
912 static unsigned int sdhci_target_timeout(struct sdhci_host *host, in sdhci_target_timeout() argument
923 if (host->clock && data->timeout_clks) { in sdhci_target_timeout()
928 * host->clock is in Hz. target_timeout is in us. in sdhci_target_timeout()
932 if (do_div(val, host->clock)) in sdhci_target_timeout()
941 static void sdhci_calc_sw_timeout(struct sdhci_host *host, in sdhci_calc_sw_timeout() argument
945 struct mmc_host *mmc = host->mmc; in sdhci_calc_sw_timeout()
953 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_sw_timeout()
958 freq = mmc->actual_clock ? : host->clock; in sdhci_calc_sw_timeout()
964 host->data_timeout = data->blocks * target_timeout + in sdhci_calc_sw_timeout()
967 host->data_timeout = target_timeout; in sdhci_calc_sw_timeout()
970 if (host->data_timeout) in sdhci_calc_sw_timeout()
971 host->data_timeout += MMC_CMD_TRANSFER_TIME; in sdhci_calc_sw_timeout()
974 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, in sdhci_calc_timeout() argument
984 * If the host controller provides us with an incorrect timeout in sdhci_calc_timeout()
989 if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) in sdhci_calc_timeout()
990 return host->max_timeout_count; in sdhci_calc_timeout()
994 return host->max_timeout_count; in sdhci_calc_timeout()
999 return host->max_timeout_count; in sdhci_calc_timeout()
1002 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_timeout()
1010 * (2) host->timeout_clk < 2^16 in sdhci_calc_timeout()
1015 current_timeout = (1 << 13) * 1000 / host->timeout_clk; in sdhci_calc_timeout()
1019 if (count > host->max_timeout_count) { in sdhci_calc_timeout()
1020 if (!(host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT)) in sdhci_calc_timeout()
1023 count = host->max_timeout_count; in sdhci_calc_timeout()
1032 static void sdhci_set_transfer_irqs(struct sdhci_host *host) in sdhci_set_transfer_irqs() argument
1037 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_irqs()
1038 host->ier = (host->ier & ~pio_irqs) | dma_irqs; in sdhci_set_transfer_irqs()
1040 host->ier = (host->ier & ~dma_irqs) | pio_irqs; in sdhci_set_transfer_irqs()
1042 if (host->flags & (SDHCI_AUTO_CMD23 | SDHCI_AUTO_CMD12)) in sdhci_set_transfer_irqs()
1043 host->ier |= SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1045 host->ier &= ~SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1047 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_transfer_irqs()
1048 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_transfer_irqs()
1051 void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable) in sdhci_set_data_timeout_irq() argument
1054 host->ier |= SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1056 host->ier &= ~SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1057 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_data_timeout_irq()
1058 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_data_timeout_irq()
1062 void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in __sdhci_set_timeout() argument
1065 u8 count = sdhci_calc_timeout(host, cmd, &too_big); in __sdhci_set_timeout()
1068 host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT) { in __sdhci_set_timeout()
1069 sdhci_calc_sw_timeout(host, cmd); in __sdhci_set_timeout()
1070 sdhci_set_data_timeout_irq(host, false); in __sdhci_set_timeout()
1071 } else if (!(host->ier & SDHCI_INT_DATA_TIMEOUT)) { in __sdhci_set_timeout()
1072 sdhci_set_data_timeout_irq(host, true); in __sdhci_set_timeout()
1075 sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); in __sdhci_set_timeout()
1079 static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_set_timeout() argument
1081 if (host->ops->set_timeout) in sdhci_set_timeout()
1082 host->ops->set_timeout(host, cmd); in sdhci_set_timeout()
1084 __sdhci_set_timeout(host, cmd); in sdhci_set_timeout()
1087 static void sdhci_initialize_data(struct sdhci_host *host, in sdhci_initialize_data() argument
1090 WARN_ON(host->data); in sdhci_initialize_data()
1094 BUG_ON(data->blksz > host->mmc->max_blk_size); in sdhci_initialize_data()
1097 host->data = data; in sdhci_initialize_data()
1098 host->data_early = 0; in sdhci_initialize_data()
1099 host->data->bytes_xfered = 0; in sdhci_initialize_data()
1102 static inline void sdhci_set_block_info(struct sdhci_host *host, in sdhci_set_block_info() argument
1106 sdhci_writew(host, in sdhci_set_block_info()
1107 SDHCI_MAKE_BLKSZ(host->sdma_boundary, data->blksz), in sdhci_set_block_info()
1113 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_set_block_info()
1114 (host->quirks2 & SDHCI_QUIRK2_USE_32BIT_BLK_CNT)) { in sdhci_set_block_info()
1115 if (sdhci_readw(host, SDHCI_BLOCK_COUNT)) in sdhci_set_block_info()
1116 sdhci_writew(host, 0, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1117 sdhci_writew(host, data->blocks, SDHCI_32BIT_BLK_CNT); in sdhci_set_block_info()
1119 sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1123 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_prepare_data() argument
1127 sdhci_initialize_data(host, data); in sdhci_prepare_data()
1129 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_prepare_data()
1134 host->flags |= SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1145 if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1146 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) { in sdhci_prepare_data()
1156 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) in sdhci_prepare_data()
1158 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) in sdhci_prepare_data()
1167 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1172 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1179 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_prepare_data()
1180 int sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_prepare_data()
1188 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1189 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1190 sdhci_adma_table_pre(host, data, sg_cnt); in sdhci_prepare_data()
1191 sdhci_set_adma_addr(host, host->adma_addr); in sdhci_prepare_data()
1194 sdhci_set_sdma_addr(host, sdhci_sdma_address(host)); in sdhci_prepare_data()
1198 sdhci_config_dma(host); in sdhci_prepare_data()
1200 if (!(host->flags & SDHCI_REQ_USE_DMA)) { in sdhci_prepare_data()
1204 if (host->data->flags & MMC_DATA_READ) in sdhci_prepare_data()
1208 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); in sdhci_prepare_data()
1209 host->blocks = data->blocks; in sdhci_prepare_data()
1212 sdhci_set_transfer_irqs(host); in sdhci_prepare_data()
1214 sdhci_set_block_info(host, data); in sdhci_prepare_data()
1219 static int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1222 struct mmc_host *mmc = host->mmc; in sdhci_external_dma_init()
1224 host->tx_chan = dma_request_chan(mmc_dev(mmc), "tx"); in sdhci_external_dma_init()
1225 if (IS_ERR(host->tx_chan)) { in sdhci_external_dma_init()
1226 ret = PTR_ERR(host->tx_chan); in sdhci_external_dma_init()
1229 host->tx_chan = NULL; in sdhci_external_dma_init()
1233 host->rx_chan = dma_request_chan(mmc_dev(mmc), "rx"); in sdhci_external_dma_init()
1234 if (IS_ERR(host->rx_chan)) { in sdhci_external_dma_init()
1235 if (host->tx_chan) { in sdhci_external_dma_init()
1236 dma_release_channel(host->tx_chan); in sdhci_external_dma_init()
1237 host->tx_chan = NULL; in sdhci_external_dma_init()
1240 ret = PTR_ERR(host->rx_chan); in sdhci_external_dma_init()
1243 host->rx_chan = NULL; in sdhci_external_dma_init()
1249 static struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1252 return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; in sdhci_external_dma_channel()
1255 static int sdhci_external_dma_setup(struct sdhci_host *host, in sdhci_external_dma_setup() argument
1267 if (!host->mapbase) in sdhci_external_dma_setup()
1271 cfg.src_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1272 cfg.dst_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1284 chan = sdhci_external_dma_channel(host, data); in sdhci_external_dma_setup()
1290 sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_external_dma_setup()
1310 static void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1312 if (host->tx_chan) { in sdhci_external_dma_release()
1313 dma_release_channel(host->tx_chan); in sdhci_external_dma_release()
1314 host->tx_chan = NULL; in sdhci_external_dma_release()
1317 if (host->rx_chan) { in sdhci_external_dma_release()
1318 dma_release_channel(host->rx_chan); in sdhci_external_dma_release()
1319 host->rx_chan = NULL; in sdhci_external_dma_release()
1322 sdhci_switch_external_dma(host, false); in sdhci_external_dma_release()
1325 static void __sdhci_external_dma_prepare_data(struct sdhci_host *host, in __sdhci_external_dma_prepare_data() argument
1330 sdhci_initialize_data(host, data); in __sdhci_external_dma_prepare_data()
1332 host->flags |= SDHCI_REQ_USE_DMA; in __sdhci_external_dma_prepare_data()
1333 sdhci_set_transfer_irqs(host); in __sdhci_external_dma_prepare_data()
1335 sdhci_set_block_info(host, data); in __sdhci_external_dma_prepare_data()
1338 static void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1341 if (!sdhci_external_dma_setup(host, cmd)) { in sdhci_external_dma_prepare_data()
1342 __sdhci_external_dma_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1344 sdhci_external_dma_release(host); in sdhci_external_dma_prepare_data()
1346 mmc_hostname(host->mmc)); in sdhci_external_dma_prepare_data()
1347 sdhci_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1351 static void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1359 chan = sdhci_external_dma_channel(host, cmd->data); in sdhci_external_dma_pre_transfer()
1366 static inline int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1371 static inline void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1375 static inline void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1382 static inline void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1387 static inline struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1395 void sdhci_switch_external_dma(struct sdhci_host *host, bool en) in sdhci_switch_external_dma() argument
1397 host->use_external_dma = en; in sdhci_switch_external_dma()
1401 static inline bool sdhci_auto_cmd12(struct sdhci_host *host, in sdhci_auto_cmd12() argument
1404 return !mrq->sbc && (host->flags & SDHCI_AUTO_CMD12) && in sdhci_auto_cmd12()
1408 static inline bool sdhci_auto_cmd23(struct sdhci_host *host, in sdhci_auto_cmd23() argument
1411 return mrq->sbc && (host->flags & SDHCI_AUTO_CMD23); in sdhci_auto_cmd23()
1414 static inline bool sdhci_manual_cmd23(struct sdhci_host *host, in sdhci_manual_cmd23() argument
1417 return mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23); in sdhci_manual_cmd23()
1420 static inline void sdhci_auto_cmd_select(struct sdhci_host *host, in sdhci_auto_cmd_select() argument
1424 bool use_cmd12 = sdhci_auto_cmd12(host, cmd->mrq) && in sdhci_auto_cmd_select()
1426 bool use_cmd23 = sdhci_auto_cmd23(host, cmd->mrq); in sdhci_auto_cmd_select()
1435 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_auto_cmd_select()
1439 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1444 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1459 static void sdhci_set_transfer_mode(struct sdhci_host *host, in sdhci_set_transfer_mode() argument
1466 if (host->quirks2 & in sdhci_set_transfer_mode()
1470 sdhci_writew(host, 0x0, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1473 mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1474 sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | in sdhci_set_transfer_mode()
1480 WARN_ON(!host->data); in sdhci_set_transfer_mode()
1482 if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) in sdhci_set_transfer_mode()
1487 sdhci_auto_cmd_select(host, cmd, &mode); in sdhci_set_transfer_mode()
1488 if (sdhci_auto_cmd23(host, cmd->mrq)) in sdhci_set_transfer_mode()
1489 sdhci_writel(host, cmd->mrq->sbc->arg, SDHCI_ARGUMENT2); in sdhci_set_transfer_mode()
1494 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_mode()
1497 sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1500 static bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_needs_reset() argument
1502 return (!(host->flags & SDHCI_DEVICE_DEAD) && in sdhci_needs_reset()
1506 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))); in sdhci_needs_reset()
1509 static void sdhci_set_mrq_done(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_set_mrq_done() argument
1514 if (host->mrqs_done[i] == mrq) { in sdhci_set_mrq_done()
1521 if (!host->mrqs_done[i]) { in sdhci_set_mrq_done()
1522 host->mrqs_done[i] = mrq; in sdhci_set_mrq_done()
1530 static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in __sdhci_finish_mrq() argument
1532 if (host->cmd && host->cmd->mrq == mrq) in __sdhci_finish_mrq()
1533 host->cmd = NULL; in __sdhci_finish_mrq()
1535 if (host->data_cmd && host->data_cmd->mrq == mrq) in __sdhci_finish_mrq()
1536 host->data_cmd = NULL; in __sdhci_finish_mrq()
1538 if (host->deferred_cmd && host->deferred_cmd->mrq == mrq) in __sdhci_finish_mrq()
1539 host->deferred_cmd = NULL; in __sdhci_finish_mrq()
1541 if (host->data && host->data->mrq == mrq) in __sdhci_finish_mrq()
1542 host->data = NULL; in __sdhci_finish_mrq()
1544 if (sdhci_needs_reset(host, mrq)) in __sdhci_finish_mrq()
1545 host->pending_reset = true; in __sdhci_finish_mrq()
1547 sdhci_set_mrq_done(host, mrq); in __sdhci_finish_mrq()
1549 sdhci_del_timer(host, mrq); in __sdhci_finish_mrq()
1551 if (!sdhci_has_requests(host)) in __sdhci_finish_mrq()
1552 sdhci_led_deactivate(host); in __sdhci_finish_mrq()
1555 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_finish_mrq() argument
1557 __sdhci_finish_mrq(host, mrq); in sdhci_finish_mrq()
1559 queue_work(host->complete_wq, &host->complete_work); in sdhci_finish_mrq()
1562 static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout) in __sdhci_finish_data() argument
1564 struct mmc_command *data_cmd = host->data_cmd; in __sdhci_finish_data()
1565 struct mmc_data *data = host->data; in __sdhci_finish_data()
1567 host->data = NULL; in __sdhci_finish_data()
1568 host->data_cmd = NULL; in __sdhci_finish_data()
1575 if (!host->cmd || host->cmd == data_cmd) in __sdhci_finish_data()
1576 sdhci_reset_for(host, REQUEST_ERROR); in __sdhci_finish_data()
1578 sdhci_reset_for(host, REQUEST_ERROR_DATA_ONLY); in __sdhci_finish_data()
1581 if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_ADMA)) == in __sdhci_finish_data()
1583 sdhci_adma_table_post(host, data); in __sdhci_finish_data()
1603 ((!data->mrq->sbc && !sdhci_auto_cmd12(host, data->mrq)) || in __sdhci_finish_data()
1611 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1614 host->cmd = NULL; in __sdhci_finish_data()
1615 if (!sdhci_send_command(host, data->stop)) { in __sdhci_finish_data()
1622 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1624 WARN_ON(host->deferred_cmd); in __sdhci_finish_data()
1625 host->deferred_cmd = data->stop; in __sdhci_finish_data()
1630 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1634 static void sdhci_finish_data(struct sdhci_host *host) in sdhci_finish_data() argument
1636 __sdhci_finish_data(host, false); in sdhci_finish_data()
1639 static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_send_command() argument
1645 WARN_ON(host->cmd); in sdhci_send_command()
1650 if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) && in sdhci_send_command()
1663 if (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) in sdhci_send_command()
1666 host->cmd = cmd; in sdhci_send_command()
1667 host->data_timeout = 0; in sdhci_send_command()
1669 WARN_ON(host->data_cmd); in sdhci_send_command()
1670 host->data_cmd = cmd; in sdhci_send_command()
1671 sdhci_set_timeout(host, cmd); in sdhci_send_command()
1675 if (host->use_external_dma) in sdhci_send_command()
1676 sdhci_external_dma_prepare_data(host, cmd); in sdhci_send_command()
1678 sdhci_prepare_data(host, cmd); in sdhci_send_command()
1681 sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT); in sdhci_send_command()
1683 sdhci_set_transfer_mode(host, cmd); in sdhci_send_command()
1715 if (host->data_timeout) in sdhci_send_command()
1716 timeout += nsecs_to_jiffies(host->data_timeout); in sdhci_send_command()
1721 sdhci_mod_timer(host, cmd->mrq, timeout); in sdhci_send_command()
1723 if (host->use_external_dma) in sdhci_send_command()
1724 sdhci_external_dma_pre_transfer(host, cmd); in sdhci_send_command()
1726 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); in sdhci_send_command()
1731 static bool sdhci_present_error(struct sdhci_host *host, in sdhci_present_error() argument
1734 if (!present || host->flags & SDHCI_DEVICE_DEAD) { in sdhci_present_error()
1742 static bool sdhci_send_command_retry(struct sdhci_host *host, in sdhci_send_command_retry() argument
1745 __releases(host->lock) in sdhci_send_command_retry()
1746 __acquires(host->lock) in sdhci_send_command_retry()
1748 struct mmc_command *deferred_cmd = host->deferred_cmd; in sdhci_send_command_retry()
1752 while (!sdhci_send_command(host, cmd)) { in sdhci_send_command_retry()
1755 mmc_hostname(host->mmc)); in sdhci_send_command_retry()
1756 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_send_command_retry()
1757 sdhci_dumpregs(host); in sdhci_send_command_retry()
1762 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_command_retry()
1766 present = host->mmc->ops->get_cd(host->mmc); in sdhci_send_command_retry()
1768 spin_lock_irqsave(&host->lock, flags); in sdhci_send_command_retry()
1771 if (cmd == deferred_cmd && cmd != host->deferred_cmd) in sdhci_send_command_retry()
1774 if (sdhci_present_error(host, cmd, present)) in sdhci_send_command_retry()
1778 if (cmd == host->deferred_cmd) in sdhci_send_command_retry()
1779 host->deferred_cmd = NULL; in sdhci_send_command_retry()
1784 static void sdhci_read_rsp_136(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_read_rsp_136() argument
1790 cmd->resp[i] = sdhci_readl(host, reg); in sdhci_read_rsp_136()
1793 if (host->quirks2 & SDHCI_QUIRK2_RSP_136_HAS_CRC) in sdhci_read_rsp_136()
1804 static void sdhci_finish_command(struct sdhci_host *host) in sdhci_finish_command() argument
1806 struct mmc_command *cmd = host->cmd; in sdhci_finish_command()
1808 host->cmd = NULL; in sdhci_finish_command()
1812 sdhci_read_rsp_136(host, cmd); in sdhci_finish_command()
1814 cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE); in sdhci_finish_command()
1819 mmc_command_done(host->mmc, cmd->mrq); in sdhci_finish_command()
1822 * The host can send and interrupt when the busy state has in sdhci_finish_command()
1834 } else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && in sdhci_finish_command()
1835 cmd == host->data_cmd) { in sdhci_finish_command()
1843 if (!sdhci_send_command(host, cmd->mrq->cmd)) { in sdhci_finish_command()
1844 WARN_ON(host->deferred_cmd); in sdhci_finish_command()
1845 host->deferred_cmd = cmd->mrq->cmd; in sdhci_finish_command()
1850 if (host->data && host->data_early) in sdhci_finish_command()
1851 sdhci_finish_data(host); in sdhci_finish_command()
1854 __sdhci_finish_mrq(host, cmd->mrq); in sdhci_finish_command()
1858 static u16 sdhci_get_preset_value(struct sdhci_host *host) in sdhci_get_preset_value() argument
1862 switch (host->timing) { in sdhci_get_preset_value()
1865 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HIGH_SPEED); in sdhci_get_preset_value()
1868 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1871 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR25); in sdhci_get_preset_value()
1874 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR50); in sdhci_get_preset_value()
1878 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104); in sdhci_get_preset_value()
1882 preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50); in sdhci_get_preset_value()
1885 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HS400); in sdhci_get_preset_value()
1889 mmc_hostname(host->mmc)); in sdhci_get_preset_value()
1890 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1896 u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, in sdhci_calc_clk() argument
1904 if (host->version >= SDHCI_SPEC_300) { in sdhci_calc_clk()
1905 if (host->preset_enabled) { in sdhci_calc_clk()
1908 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_calc_clk()
1909 pre_val = sdhci_get_preset_value(host); in sdhci_calc_clk()
1911 if (host->clk_mul && in sdhci_calc_clk()
1915 clk_mul = host->clk_mul; in sdhci_calc_clk()
1923 * Check if the Host Controller supports Programmable Clock in sdhci_calc_clk()
1926 if (host->clk_mul) { in sdhci_calc_clk()
1928 if ((host->max_clk * host->clk_mul / div) in sdhci_calc_clk()
1932 if ((host->max_clk * host->clk_mul / div) <= clock) { in sdhci_calc_clk()
1939 clk_mul = host->clk_mul; in sdhci_calc_clk()
1950 if (!host->clk_mul || switch_base_clk) { in sdhci_calc_clk()
1952 if (host->max_clk <= clock) in sdhci_calc_clk()
1957 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1963 if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) in sdhci_calc_clk()
1964 && !div && host->max_clk <= 25000000) in sdhci_calc_clk()
1970 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1979 *actual_clock = (host->max_clk * clk_mul) / real_div; in sdhci_calc_clk()
1988 void sdhci_enable_clk(struct sdhci_host *host, u16 clk) in sdhci_enable_clk() argument
1993 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2000 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2005 mmc_hostname(host->mmc)); in sdhci_enable_clk()
2006 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_enable_clk()
2007 sdhci_dumpregs(host); in sdhci_enable_clk()
2013 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) { in sdhci_enable_clk()
2016 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2023 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2028 mmc_hostname(host->mmc)); in sdhci_enable_clk()
2029 sdhci_err_stats_inc(host, CTRL_TIMEOUT); in sdhci_enable_clk()
2030 sdhci_dumpregs(host); in sdhci_enable_clk()
2038 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2042 void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) in sdhci_set_clock() argument
2046 host->mmc->actual_clock = 0; in sdhci_set_clock()
2048 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); in sdhci_set_clock()
2053 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); in sdhci_set_clock()
2054 sdhci_enable_clk(host, clk); in sdhci_set_clock()
2058 static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_reg() argument
2061 struct mmc_host *mmc = host->mmc; in sdhci_set_power_reg()
2066 sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2068 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2071 void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_noreg() argument
2104 mmc_hostname(host->mmc), vdd); in sdhci_set_power_noreg()
2109 if (host->pwr == pwr) in sdhci_set_power_noreg()
2112 host->pwr = pwr; in sdhci_set_power_noreg()
2115 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2116 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2117 sdhci_runtime_pm_bus_off(host); in sdhci_set_power_noreg()
2123 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) in sdhci_set_power_noreg()
2124 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2131 if (host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER) in sdhci_set_power_noreg()
2132 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2136 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2138 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2139 sdhci_runtime_pm_bus_on(host); in sdhci_set_power_noreg()
2145 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) in sdhci_set_power_noreg()
2151 void sdhci_set_power(struct sdhci_host *host, unsigned char mode, in sdhci_set_power() argument
2154 if (IS_ERR(host->mmc->supply.vmmc)) in sdhci_set_power()
2155 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power()
2157 sdhci_set_power_reg(host, mode, vdd); in sdhci_set_power()
2167 void sdhci_set_power_and_bus_voltage(struct sdhci_host *host, in sdhci_set_power_and_bus_voltage() argument
2171 if (!IS_ERR(host->mmc->supply.vmmc)) { in sdhci_set_power_and_bus_voltage()
2172 struct mmc_host *mmc = host->mmc; in sdhci_set_power_and_bus_voltage()
2176 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power_and_bus_voltage()
2188 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request() local
2196 spin_lock_irqsave(&host->lock, flags); in sdhci_request()
2198 sdhci_led_activate(host); in sdhci_request()
2200 if (sdhci_present_error(host, mrq->cmd, present)) in sdhci_request()
2203 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request()
2205 if (!sdhci_send_command_retry(host, cmd, flags)) in sdhci_request()
2208 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2213 sdhci_finish_mrq(host, mrq); in sdhci_request()
2214 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2220 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request_atomic() local
2225 spin_lock_irqsave(&host->lock, flags); in sdhci_request_atomic()
2227 if (sdhci_present_error(host, mrq->cmd, true)) { in sdhci_request_atomic()
2228 sdhci_finish_mrq(host, mrq); in sdhci_request_atomic()
2232 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request_atomic()
2241 if (!sdhci_send_command(host, cmd)) in sdhci_request_atomic()
2244 sdhci_led_activate(host); in sdhci_request_atomic()
2247 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_atomic()
2252 void sdhci_set_bus_width(struct sdhci_host *host, int width) in sdhci_set_bus_width() argument
2256 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2261 if (host->mmc->caps & MMC_CAP_8_BIT_DATA) in sdhci_set_bus_width()
2268 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2272 void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing) in sdhci_set_uhs_signaling() argument
2276 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2277 /* Select Bus Speed Mode for host */ in sdhci_set_uhs_signaling()
2293 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2311 static bool sdhci_preset_needed(struct sdhci_host *host, unsigned char timing) in sdhci_preset_needed() argument
2313 return !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN) && in sdhci_preset_needed()
2317 static bool sdhci_presetable_values_change(struct sdhci_host *host, struct mmc_ios *ios) in sdhci_presetable_values_change() argument
2324 return !host->preset_enabled && in sdhci_presetable_values_change()
2325 (sdhci_preset_needed(host, ios->timing) || host->drv_type != ios->drv_type); in sdhci_presetable_values_change()
2330 struct sdhci_host *host = mmc_priv(mmc); in sdhci_set_ios() local
2331 bool reinit_uhs = host->reinit_uhs; in sdhci_set_ios()
2335 host->reinit_uhs = false; in sdhci_set_ios()
2340 if (host->flags & SDHCI_DEVICE_DEAD) { in sdhci_set_ios()
2352 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_set_ios()
2353 sdhci_reinit(host); in sdhci_set_ios()
2356 if (host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2358 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) in sdhci_set_ios()
2359 sdhci_enable_preset_value(host, false); in sdhci_set_ios()
2361 if (!ios->clock || ios->clock != host->clock) { in sdhci_set_ios()
2362 turning_on_clk = ios->clock && !host->clock; in sdhci_set_ios()
2364 host->ops->set_clock(host, ios->clock); in sdhci_set_ios()
2365 host->clock = ios->clock; in sdhci_set_ios()
2367 if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK && in sdhci_set_ios()
2368 host->clock) { in sdhci_set_ios()
2369 host->timeout_clk = mmc->actual_clock ? in sdhci_set_ios()
2371 host->clock / 1000; in sdhci_set_ios()
2373 host->ops->get_max_timeout_count ? in sdhci_set_ios()
2374 host->ops->get_max_timeout_count(host) : in sdhci_set_ios()
2376 mmc->max_busy_timeout /= host->timeout_clk; in sdhci_set_ios()
2380 if (host->ops->set_power) in sdhci_set_ios()
2381 host->ops->set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2383 sdhci_set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2385 if (host->ops->platform_send_init_74_clocks) in sdhci_set_ios()
2386 host->ops->platform_send_init_74_clocks(host, ios->power_mode); in sdhci_set_ios()
2388 host->ops->set_bus_width(host, ios->bus_width); in sdhci_set_ios()
2396 host->timing == ios->timing && in sdhci_set_ios()
2397 host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2398 !sdhci_presetable_values_change(host, ios)) in sdhci_set_ios()
2401 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2403 if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) { in sdhci_set_ios()
2418 if (host->version >= SDHCI_SPEC_300) { in sdhci_set_ios()
2421 if (!host->preset_enabled) { in sdhci_set_ios()
2422 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2427 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2443 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2444 host->drv_type = ios->drv_type; in sdhci_set_ios()
2448 * Enable in the Host Control 2 register is set, we in sdhci_set_ios()
2454 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2456 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2458 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2461 host->ops->set_clock(host, host->clock); in sdhci_set_ios()
2465 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2467 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2469 host->ops->set_uhs_signaling(host, ios->timing); in sdhci_set_ios()
2470 host->timing = ios->timing; in sdhci_set_ios()
2472 if (sdhci_preset_needed(host, ios->timing)) { in sdhci_set_ios()
2475 sdhci_enable_preset_value(host, true); in sdhci_set_ios()
2476 preset = sdhci_get_preset_value(host); in sdhci_set_ios()
2479 host->drv_type = ios->drv_type; in sdhci_set_ios()
2483 host->ops->set_clock(host, host->clock); in sdhci_set_ios()
2485 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2491 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_cd() local
2494 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_get_cd()
2509 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) in sdhci_get_cd()
2512 /* Host native card detect */ in sdhci_get_cd()
2513 return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); in sdhci_get_cd()
2518 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_cd_nogpio() local
2522 spin_lock_irqsave(&host->lock, flags); in sdhci_get_cd_nogpio()
2524 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_get_cd_nogpio()
2527 ret = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); in sdhci_get_cd_nogpio()
2529 spin_unlock_irqrestore(&host->lock, flags); in sdhci_get_cd_nogpio()
2535 static int sdhci_check_ro(struct sdhci_host *host) in sdhci_check_ro() argument
2540 spin_lock_irqsave(&host->lock, flags); in sdhci_check_ro()
2542 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_check_ro()
2544 else if (host->ops->get_ro) in sdhci_check_ro()
2545 is_readonly = host->ops->get_ro(host); in sdhci_check_ro()
2546 else if (mmc_can_gpio_ro(host->mmc)) in sdhci_check_ro()
2547 is_readonly = mmc_gpio_get_ro(host->mmc); in sdhci_check_ro()
2549 is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE) in sdhci_check_ro()
2552 spin_unlock_irqrestore(&host->lock, flags); in sdhci_check_ro()
2555 return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ? in sdhci_check_ro()
2563 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_ro() local
2566 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT)) in sdhci_get_ro()
2567 return sdhci_check_ro(host); in sdhci_get_ro()
2571 if (sdhci_check_ro(host)) { in sdhci_get_ro()
2582 struct sdhci_host *host = mmc_priv(mmc); in sdhci_hw_reset() local
2584 if (host->ops && host->ops->hw_reset) in sdhci_hw_reset()
2585 host->ops->hw_reset(host); in sdhci_hw_reset()
2588 static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable) in sdhci_enable_sdio_irq_nolock() argument
2590 if (!(host->flags & SDHCI_DEVICE_DEAD)) { in sdhci_enable_sdio_irq_nolock()
2592 host->ier |= SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2594 host->ier &= ~SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2596 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_enable_sdio_irq_nolock()
2597 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_enable_sdio_irq_nolock()
2603 struct sdhci_host *host = mmc_priv(mmc); in sdhci_enable_sdio_irq() local
2609 spin_lock_irqsave(&host->lock, flags); in sdhci_enable_sdio_irq()
2610 sdhci_enable_sdio_irq_nolock(host, enable); in sdhci_enable_sdio_irq()
2611 spin_unlock_irqrestore(&host->lock, flags); in sdhci_enable_sdio_irq()
2620 struct sdhci_host *host = mmc_priv(mmc); in sdhci_ack_sdio_irq() local
2623 spin_lock_irqsave(&host->lock, flags); in sdhci_ack_sdio_irq()
2624 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_ack_sdio_irq()
2625 spin_unlock_irqrestore(&host->lock, flags); in sdhci_ack_sdio_irq()
2631 struct sdhci_host *host = mmc_priv(mmc); in sdhci_start_signal_voltage_switch() local
2636 * Signal Voltage Switching is only applicable for Host Controllers in sdhci_start_signal_voltage_switch()
2639 if (host->version < SDHCI_SPEC_300) in sdhci_start_signal_voltage_switch()
2642 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2646 if (!(host->flags & SDHCI_SIGNALING_330)) in sdhci_start_signal_voltage_switch()
2648 /* Set 1.8V Signal Enable in the Host Control2 register to 0 */ in sdhci_start_signal_voltage_switch()
2650 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2664 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2673 if (!(host->flags & SDHCI_SIGNALING_180)) in sdhci_start_signal_voltage_switch()
2685 * Enable 1.8V Signal Enable in the Host Control2 in sdhci_start_signal_voltage_switch()
2689 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2692 if (host->ops->voltage_switch) in sdhci_start_signal_voltage_switch()
2693 host->ops->voltage_switch(host); in sdhci_start_signal_voltage_switch()
2696 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2705 if (!(host->flags & SDHCI_SIGNALING_120)) in sdhci_start_signal_voltage_switch()
2725 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_busy() local
2729 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); in sdhci_card_busy()
2736 struct sdhci_host *host = mmc_priv(mmc); in sdhci_prepare_hs400_tuning() local
2739 spin_lock_irqsave(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2740 host->flags |= SDHCI_HS400_TUNING; in sdhci_prepare_hs400_tuning()
2741 spin_unlock_irqrestore(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2746 void sdhci_start_tuning(struct sdhci_host *host) in sdhci_start_tuning() argument
2750 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2752 if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND) in sdhci_start_tuning()
2754 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2757 * As per the Host Controller spec v3.00, tuning command in sdhci_start_tuning()
2766 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); in sdhci_start_tuning()
2767 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); in sdhci_start_tuning()
2771 void sdhci_end_tuning(struct sdhci_host *host) in sdhci_end_tuning() argument
2773 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_end_tuning()
2774 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_end_tuning()
2778 void sdhci_reset_tuning(struct sdhci_host *host) in sdhci_reset_tuning() argument
2782 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2785 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2789 void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode) in sdhci_abort_tuning() argument
2791 sdhci_reset_tuning(host); in sdhci_abort_tuning()
2793 sdhci_reset_for(host, TUNING_ABORT); in sdhci_abort_tuning()
2795 sdhci_end_tuning(host); in sdhci_abort_tuning()
2797 mmc_send_abort_tuning(host->mmc, opcode); in sdhci_abort_tuning()
2808 void sdhci_send_tuning(struct sdhci_host *host, u32 opcode) in sdhci_send_tuning() argument
2810 struct mmc_host *mmc = host->mmc; in sdhci_send_tuning()
2814 u32 b = host->sdma_boundary; in sdhci_send_tuning()
2816 spin_lock_irqsave(&host->lock, flags); in sdhci_send_tuning()
2825 * block to the Host Controller. So we set the block size in sdhci_send_tuning()
2830 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 128), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2832 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 64), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2835 * The tuning block is sent by the card to the host controller. in sdhci_send_tuning()
2840 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); in sdhci_send_tuning()
2842 if (!sdhci_send_command_retry(host, &cmd, flags)) { in sdhci_send_tuning()
2843 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2844 host->tuning_done = 0; in sdhci_send_tuning()
2848 host->cmd = NULL; in sdhci_send_tuning()
2850 sdhci_del_timer(host, &mrq); in sdhci_send_tuning()
2852 host->tuning_done = 0; in sdhci_send_tuning()
2854 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2857 wait_event_timeout(host->buf_ready_int, (host->tuning_done == 1), in sdhci_send_tuning()
2863 static int __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode) in __sdhci_execute_tuning() argument
2871 for (i = 0; i < host->tuning_loop_count; i++) { in __sdhci_execute_tuning()
2874 sdhci_send_tuning(host, opcode); in __sdhci_execute_tuning()
2876 if (!host->tuning_done) { in __sdhci_execute_tuning()
2878 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2879 sdhci_abort_tuning(host, opcode); in __sdhci_execute_tuning()
2884 if (host->tuning_delay > 0) in __sdhci_execute_tuning()
2885 mdelay(host->tuning_delay); in __sdhci_execute_tuning()
2887 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in __sdhci_execute_tuning()
2897 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2898 sdhci_reset_tuning(host); in __sdhci_execute_tuning()
2904 struct sdhci_host *host = mmc_priv(mmc); in sdhci_execute_tuning() local
2909 hs400_tuning = host->flags & SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2911 if (host->tuning_mode == SDHCI_TUNING_MODE_1) in sdhci_execute_tuning()
2912 tuning_count = host->tuning_count; in sdhci_execute_tuning()
2915 * The Host Controller needs tuning in case of SDR104 and DDR50 in sdhci_execute_tuning()
2918 * If the Host Controller supports the HS200 mode then the in sdhci_execute_tuning()
2921 switch (host->timing) { in sdhci_execute_tuning()
2941 if (host->flags & SDHCI_SDR50_NEEDS_TUNING) in sdhci_execute_tuning()
2949 if (host->ops->platform_execute_tuning) { in sdhci_execute_tuning()
2950 err = host->ops->platform_execute_tuning(host, opcode); in sdhci_execute_tuning()
2956 if (host->tuning_delay < 0) in sdhci_execute_tuning()
2957 host->tuning_delay = opcode == MMC_SEND_TUNING_BLOCK; in sdhci_execute_tuning()
2959 sdhci_start_tuning(host); in sdhci_execute_tuning()
2961 host->tuning_err = __sdhci_execute_tuning(host, opcode); in sdhci_execute_tuning()
2963 sdhci_end_tuning(host); in sdhci_execute_tuning()
2965 host->flags &= ~SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2971 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) in sdhci_enable_preset_value() argument
2973 /* Host Controller v3.00 defines preset value registers */ in sdhci_enable_preset_value()
2974 if (host->version < SDHCI_SPEC_300) in sdhci_enable_preset_value()
2981 if (host->preset_enabled != enable) { in sdhci_enable_preset_value()
2982 u16 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2989 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2992 host->flags |= SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2994 host->flags &= ~SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2996 host->preset_enabled = enable; in sdhci_enable_preset_value()
3014 struct sdhci_host *host = mmc_priv(mmc); in sdhci_pre_req() local
3023 if (host->flags & SDHCI_REQ_USE_DMA && !host->bounce_buffer) in sdhci_pre_req()
3024 sdhci_pre_dma_transfer(host, mrq->data, COOKIE_PRE_MAPPED); in sdhci_pre_req()
3027 static void sdhci_error_out_mrqs(struct sdhci_host *host, int err) in sdhci_error_out_mrqs() argument
3029 if (host->data_cmd) { in sdhci_error_out_mrqs()
3030 host->data_cmd->error = err; in sdhci_error_out_mrqs()
3031 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_error_out_mrqs()
3034 if (host->cmd) { in sdhci_error_out_mrqs()
3035 host->cmd->error = err; in sdhci_error_out_mrqs()
3036 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_error_out_mrqs()
3042 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_event() local
3047 if (host->ops->card_event) in sdhci_card_event()
3048 host->ops->card_event(host); in sdhci_card_event()
3052 spin_lock_irqsave(&host->lock, flags); in sdhci_card_event()
3055 if (sdhci_has_requests(host) && !present) { in sdhci_card_event()
3061 sdhci_reset_for(host, CARD_REMOVED); in sdhci_card_event()
3063 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_card_event()
3066 spin_unlock_irqrestore(&host->lock, flags); in sdhci_card_event()
3092 static bool sdhci_request_done(struct sdhci_host *host) in sdhci_request_done() argument
3098 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3101 mrq = host->mrqs_done[i]; in sdhci_request_done()
3107 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3115 if (sdhci_needs_reset(host, mrq)) { in sdhci_request_done()
3119 * also be in mrqs_done, otherwise host->cmd and host->data_cmd in sdhci_request_done()
3122 if (host->cmd || host->data_cmd) { in sdhci_request_done()
3123 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3128 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) in sdhci_request_done()
3130 host->ops->set_clock(host, host->clock); in sdhci_request_done()
3132 sdhci_reset_for(host, REQUEST_ERROR); in sdhci_request_done()
3134 host->pending_reset = false; in sdhci_request_done()
3142 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_request_done()
3145 if (host->use_external_dma && data && in sdhci_request_done()
3147 struct dma_chan *chan = sdhci_external_dma_channel(host, data); in sdhci_request_done()
3149 host->mrqs_done[i] = NULL; in sdhci_request_done()
3150 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3152 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3153 sdhci_set_mrq_done(host, mrq); in sdhci_request_done()
3157 if (host->bounce_buffer) { in sdhci_request_done()
3165 if (length > host->bounce_buffer_size) { in sdhci_request_done()
3167 mmc_hostname(host->mmc), in sdhci_request_done()
3168 host->bounce_buffer_size, in sdhci_request_done()
3171 length = host->bounce_buffer_size; in sdhci_request_done()
3174 mmc_dev(host->mmc), in sdhci_request_done()
3175 host->bounce_addr, in sdhci_request_done()
3176 host->bounce_buffer_size, in sdhci_request_done()
3180 host->bounce_buffer, in sdhci_request_done()
3185 mmc_dev(host->mmc), in sdhci_request_done()
3186 host->bounce_addr, in sdhci_request_done()
3187 host->bounce_buffer_size, in sdhci_request_done()
3192 dma_unmap_sg(mmc_dev(host->mmc), data->sg, in sdhci_request_done()
3200 host->mrqs_done[i] = NULL; in sdhci_request_done()
3202 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3204 if (host->ops->request_done) in sdhci_request_done()
3205 host->ops->request_done(host, mrq); in sdhci_request_done()
3207 mmc_request_done(host->mmc, mrq); in sdhci_request_done()
3214 struct sdhci_host *host = container_of(work, struct sdhci_host, in sdhci_complete_work() local
3217 while (!sdhci_request_done(host)) in sdhci_complete_work()
3223 struct sdhci_host *host; in sdhci_timeout_timer() local
3226 host = from_timer(host, t, timer); in sdhci_timeout_timer()
3228 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_timer()
3230 if (host->cmd && !sdhci_data_line_cmd(host->cmd)) { in sdhci_timeout_timer()
3232 mmc_hostname(host->mmc)); in sdhci_timeout_timer()
3233 sdhci_err_stats_inc(host, REQ_TIMEOUT); in sdhci_timeout_timer()
3234 sdhci_dumpregs(host); in sdhci_timeout_timer()
3236 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_timer()
3237 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_timer()
3240 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_timer()
3245 struct sdhci_host *host; in sdhci_timeout_data_timer() local
3248 host = from_timer(host, t, data_timer); in sdhci_timeout_data_timer()
3250 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_data_timer()
3252 if (host->data || host->data_cmd || in sdhci_timeout_data_timer()
3253 (host->cmd && sdhci_data_line_cmd(host->cmd))) { in sdhci_timeout_data_timer()
3255 mmc_hostname(host->mmc)); in sdhci_timeout_data_timer()
3256 sdhci_err_stats_inc(host, REQ_TIMEOUT); in sdhci_timeout_data_timer()
3257 sdhci_dumpregs(host); in sdhci_timeout_data_timer()
3259 if (host->data) { in sdhci_timeout_data_timer()
3260 host->data->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3261 __sdhci_finish_data(host, true); in sdhci_timeout_data_timer()
3262 queue_work(host->complete_wq, &host->complete_work); in sdhci_timeout_data_timer()
3263 } else if (host->data_cmd) { in sdhci_timeout_data_timer()
3264 host->data_cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3265 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_timeout_data_timer()
3267 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3268 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_data_timer()
3272 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_data_timer()
3281 static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p) in sdhci_cmd_irq() argument
3284 if (intmask & SDHCI_INT_AUTO_CMD_ERR && host->data_cmd) { in sdhci_cmd_irq()
3285 struct mmc_request *mrq = host->data_cmd->mrq; in sdhci_cmd_irq()
3286 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3292 if (!mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) { in sdhci_cmd_irq()
3298 if (!host->cmd) { in sdhci_cmd_irq()
3304 if (host->pending_reset) in sdhci_cmd_irq()
3307 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_cmd_irq()
3308 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_cmd_irq()
3309 sdhci_dumpregs(host); in sdhci_cmd_irq()
3316 host->cmd->error = -ETIMEDOUT; in sdhci_cmd_irq()
3317 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_cmd_irq()
3319 host->cmd->error = -EILSEQ; in sdhci_cmd_irq()
3320 if (!mmc_op_tuning(host->cmd->opcode)) in sdhci_cmd_irq()
3321 sdhci_err_stats_inc(host, CMD_CRC); in sdhci_cmd_irq()
3324 if (host->cmd->data && in sdhci_cmd_irq()
3327 host->cmd = NULL; in sdhci_cmd_irq()
3332 __sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_cmd_irq()
3338 struct mmc_request *mrq = host->cmd->mrq; in sdhci_cmd_irq()
3339 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3344 sdhci_err_stats_inc(host, AUTO_CMD); in sdhci_cmd_irq()
3346 if (sdhci_auto_cmd23(host, mrq)) { in sdhci_cmd_irq()
3348 __sdhci_finish_mrq(host, mrq); in sdhci_cmd_irq()
3354 sdhci_finish_command(host); in sdhci_cmd_irq()
3357 static void sdhci_adma_show_error(struct sdhci_host *host) in sdhci_adma_show_error() argument
3359 void *desc = host->adma_table; in sdhci_adma_show_error()
3360 dma_addr_t dma = host->adma_addr; in sdhci_adma_show_error()
3362 sdhci_dumpregs(host); in sdhci_adma_show_error()
3367 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_show_error()
3381 desc += host->desc_sz; in sdhci_adma_show_error()
3382 dma += host->desc_sz; in sdhci_adma_show_error()
3389 static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) in sdhci_data_irq() argument
3400 if (intmask & SDHCI_INT_DATA_AVAIL && !host->data) { in sdhci_data_irq()
3401 command = SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)); in sdhci_data_irq()
3404 host->tuning_done = 1; in sdhci_data_irq()
3405 wake_up(&host->buf_ready_int); in sdhci_data_irq()
3410 if (!host->data) { in sdhci_data_irq()
3411 struct mmc_command *data_cmd = host->data_cmd; in sdhci_data_irq()
3420 host->data_cmd = NULL; in sdhci_data_irq()
3422 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_data_irq()
3423 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3427 host->data_cmd = NULL; in sdhci_data_irq()
3433 if (host->cmd == data_cmd) in sdhci_data_irq()
3436 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3446 if (host->pending_reset) in sdhci_data_irq()
3450 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_data_irq()
3451 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_data_irq()
3452 sdhci_dumpregs(host); in sdhci_data_irq()
3458 host->data->error = -ETIMEDOUT; in sdhci_data_irq()
3459 sdhci_err_stats_inc(host, DAT_TIMEOUT); in sdhci_data_irq()
3461 host->data->error = -EILSEQ; in sdhci_data_irq()
3462 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_data_irq()
3463 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_data_irq()
3465 SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) in sdhci_data_irq()
3467 host->data->error = -EILSEQ; in sdhci_data_irq()
3468 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_data_irq()
3469 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_data_irq()
3471 pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc), in sdhci_data_irq()
3473 sdhci_adma_show_error(host); in sdhci_data_irq()
3474 sdhci_err_stats_inc(host, ADMA); in sdhci_data_irq()
3475 host->data->error = -EIO; in sdhci_data_irq()
3476 if (host->ops->adma_workaround) in sdhci_data_irq()
3477 host->ops->adma_workaround(host, intmask); in sdhci_data_irq()
3480 if (host->data->error) in sdhci_data_irq()
3481 sdhci_finish_data(host); in sdhci_data_irq()
3484 sdhci_transfer_pio(host); in sdhci_data_irq()
3491 * According to the spec sdhci_readl(host, SDHCI_DMA_ADDRESS) in sdhci_data_irq()
3498 dmastart = sdhci_sdma_address(host); in sdhci_data_irq()
3499 dmanow = dmastart + host->data->bytes_xfered; in sdhci_data_irq()
3506 host->data->bytes_xfered = dmanow - dmastart; in sdhci_data_irq()
3508 &dmastart, host->data->bytes_xfered, &dmanow); in sdhci_data_irq()
3509 sdhci_set_sdma_addr(host, dmanow); in sdhci_data_irq()
3513 if (host->cmd == host->data_cmd) { in sdhci_data_irq()
3519 host->data_early = 1; in sdhci_data_irq()
3521 sdhci_finish_data(host); in sdhci_data_irq()
3527 static inline bool sdhci_defer_done(struct sdhci_host *host, in sdhci_defer_done() argument
3532 return host->pending_reset || host->always_defer_done || in sdhci_defer_done()
3533 ((host->flags & SDHCI_REQ_USE_DMA) && data && in sdhci_defer_done()
3541 struct sdhci_host *host = dev_id; in sdhci_irq() local
3546 spin_lock(&host->lock); in sdhci_irq()
3548 if (host->runtime_suspended) { in sdhci_irq()
3549 spin_unlock(&host->lock); in sdhci_irq()
3553 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3562 if (host->ops->irq) { in sdhci_irq()
3563 intmask = host->ops->irq(host, intmask); in sdhci_irq()
3571 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_irq()
3574 u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & in sdhci_irq()
3588 host->ier &= ~(SDHCI_INT_CARD_INSERT | in sdhci_irq()
3590 host->ier |= present ? SDHCI_INT_CARD_REMOVE : in sdhci_irq()
3592 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_irq()
3593 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_irq()
3595 sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3598 host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3604 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK, &intmask); in sdhci_irq()
3607 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); in sdhci_irq()
3611 mmc_hostname(host->mmc)); in sdhci_irq()
3614 mmc_retune_needed(host->mmc); in sdhci_irq()
3617 (host->ier & SDHCI_INT_CARD_INT)) { in sdhci_irq()
3618 sdhci_enable_sdio_irq_nolock(host, false); in sdhci_irq()
3619 sdio_signal_irq(host->mmc); in sdhci_irq()
3629 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_irq()
3635 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3640 struct mmc_request *mrq = host->mrqs_done[i]; in sdhci_irq()
3645 if (sdhci_defer_done(host, mrq)) { in sdhci_irq()
3649 host->mrqs_done[i] = NULL; in sdhci_irq()
3653 if (host->deferred_cmd) in sdhci_irq()
3656 spin_unlock(&host->lock); in sdhci_irq()
3663 if (host->ops->request_done) in sdhci_irq()
3664 host->ops->request_done(host, mrqs_done[i]); in sdhci_irq()
3666 mmc_request_done(host->mmc, mrqs_done[i]); in sdhci_irq()
3671 mmc_hostname(host->mmc), unexpected); in sdhci_irq()
3672 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_irq()
3673 sdhci_dumpregs(host); in sdhci_irq()
3681 struct sdhci_host *host = dev_id; in sdhci_thread_irq() local
3686 while (!sdhci_request_done(host)) in sdhci_thread_irq()
3689 spin_lock_irqsave(&host->lock, flags); in sdhci_thread_irq()
3691 isr = host->thread_isr; in sdhci_thread_irq()
3692 host->thread_isr = 0; in sdhci_thread_irq()
3694 cmd = host->deferred_cmd; in sdhci_thread_irq()
3695 if (cmd && !sdhci_send_command_retry(host, cmd, flags)) in sdhci_thread_irq()
3696 sdhci_finish_mrq(host, cmd->mrq); in sdhci_thread_irq()
3698 spin_unlock_irqrestore(&host->lock, flags); in sdhci_thread_irq()
3701 struct mmc_host *mmc = host->mmc; in sdhci_thread_irq()
3718 static bool sdhci_cd_irq_can_wakeup(struct sdhci_host *host) in sdhci_cd_irq_can_wakeup() argument
3720 return mmc_card_is_removable(host->mmc) && in sdhci_cd_irq_can_wakeup()
3721 !(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_cd_irq_can_wakeup()
3722 !mmc_can_gpio_cd(host->mmc); in sdhci_cd_irq_can_wakeup()
3728 * Table' in the SD Host Controller Standard Specification.
3733 static bool sdhci_enable_irq_wakeups(struct sdhci_host *host) in sdhci_enable_irq_wakeups() argument
3741 if (sdhci_cd_irq_can_wakeup(host)) { in sdhci_enable_irq_wakeups()
3746 if (mmc_card_wake_sdio_irq(host->mmc)) { in sdhci_enable_irq_wakeups()
3754 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3757 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3759 sdhci_writel(host, irq_val, SDHCI_INT_ENABLE); in sdhci_enable_irq_wakeups()
3761 host->irq_wake_enabled = !enable_irq_wake(host->irq); in sdhci_enable_irq_wakeups()
3763 return host->irq_wake_enabled; in sdhci_enable_irq_wakeups()
3766 static void sdhci_disable_irq_wakeups(struct sdhci_host *host) in sdhci_disable_irq_wakeups() argument
3772 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3774 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3776 disable_irq_wake(host->irq); in sdhci_disable_irq_wakeups()
3778 host->irq_wake_enabled = false; in sdhci_disable_irq_wakeups()
3781 int sdhci_suspend_host(struct sdhci_host *host) in sdhci_suspend_host() argument
3783 sdhci_disable_card_detection(host); in sdhci_suspend_host()
3785 mmc_retune_timer_stop(host->mmc); in sdhci_suspend_host()
3787 if (!device_may_wakeup(mmc_dev(host->mmc)) || in sdhci_suspend_host()
3788 !sdhci_enable_irq_wakeups(host)) { in sdhci_suspend_host()
3789 host->ier = 0; in sdhci_suspend_host()
3790 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_suspend_host()
3791 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_suspend_host()
3792 free_irq(host->irq, host); in sdhci_suspend_host()
3800 int sdhci_resume_host(struct sdhci_host *host) in sdhci_resume_host() argument
3802 struct mmc_host *mmc = host->mmc; in sdhci_resume_host()
3805 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_resume_host()
3806 if (host->ops->enable_dma) in sdhci_resume_host()
3807 host->ops->enable_dma(host); in sdhci_resume_host()
3811 (host->quirks2 & SDHCI_QUIRK2_HOST_OFF_CARD_ON)) { in sdhci_resume_host()
3812 /* Card keeps power but host controller does not */ in sdhci_resume_host()
3813 sdhci_init(host, 0); in sdhci_resume_host()
3814 host->pwr = 0; in sdhci_resume_host()
3815 host->clock = 0; in sdhci_resume_host()
3816 host->reinit_uhs = true; in sdhci_resume_host()
3819 sdhci_init(host, (mmc->pm_flags & MMC_PM_KEEP_POWER)); in sdhci_resume_host()
3822 if (host->irq_wake_enabled) { in sdhci_resume_host()
3823 sdhci_disable_irq_wakeups(host); in sdhci_resume_host()
3825 ret = request_threaded_irq(host->irq, sdhci_irq, in sdhci_resume_host()
3827 mmc_hostname(mmc), host); in sdhci_resume_host()
3832 sdhci_enable_card_detection(host); in sdhci_resume_host()
3839 int sdhci_runtime_suspend_host(struct sdhci_host *host) in sdhci_runtime_suspend_host() argument
3843 mmc_retune_timer_stop(host->mmc); in sdhci_runtime_suspend_host()
3845 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3846 host->ier &= SDHCI_INT_CARD_INT; in sdhci_runtime_suspend_host()
3847 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_runtime_suspend_host()
3848 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_runtime_suspend_host()
3849 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3851 synchronize_hardirq(host->irq); in sdhci_runtime_suspend_host()
3853 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3854 host->runtime_suspended = true; in sdhci_runtime_suspend_host()
3855 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3861 int sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset) in sdhci_runtime_resume_host() argument
3863 struct mmc_host *mmc = host->mmc; in sdhci_runtime_resume_host()
3865 int host_flags = host->flags; in sdhci_runtime_resume_host()
3868 if (host->ops->enable_dma) in sdhci_runtime_resume_host()
3869 host->ops->enable_dma(host); in sdhci_runtime_resume_host()
3872 sdhci_init(host, soft_reset); in sdhci_runtime_resume_host()
3877 host->pwr = 0; in sdhci_runtime_resume_host()
3878 host->clock = 0; in sdhci_runtime_resume_host()
3879 host->reinit_uhs = true; in sdhci_runtime_resume_host()
3884 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) { in sdhci_runtime_resume_host()
3885 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3886 sdhci_enable_preset_value(host, true); in sdhci_runtime_resume_host()
3887 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3895 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3897 host->runtime_suspended = false; in sdhci_runtime_resume_host()
3901 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_runtime_resume_host()
3904 sdhci_enable_card_detection(host); in sdhci_runtime_resume_host()
3906 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3922 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_enable() local
3926 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_enable()
3928 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3931 * Host from V4.10 supports ADMA3 DMA type. in sdhci_cqe_enable()
3935 if (host->v4_mode && (host->caps1 & SDHCI_CAN_DO_ADMA3)) in sdhci_cqe_enable()
3937 else if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_cqe_enable()
3941 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3943 sdhci_writew(host, SDHCI_MAKE_BLKSZ(host->sdma_boundary, 512), in sdhci_cqe_enable()
3947 sdhci_set_timeout(host, NULL); in sdhci_cqe_enable()
3949 host->ier = host->cqe_ier; in sdhci_cqe_enable()
3951 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_cqe_enable()
3952 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_cqe_enable()
3954 host->cqe_on = true; in sdhci_cqe_enable()
3957 mmc_hostname(mmc), host->ier, in sdhci_cqe_enable()
3958 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_enable()
3960 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_enable()
3966 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_disable() local
3969 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_disable()
3971 sdhci_set_default_irqs(host); in sdhci_cqe_disable()
3973 host->cqe_on = false; in sdhci_cqe_disable()
3976 sdhci_reset_for(host, CQE_RECOVERY); in sdhci_cqe_disable()
3979 mmc_hostname(mmc), host->ier, in sdhci_cqe_disable()
3980 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_disable()
3982 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_disable()
3986 bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error, in sdhci_cqe_irq() argument
3991 if (!host->cqe_on) in sdhci_cqe_irq()
3996 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_cqe_irq()
3997 sdhci_err_stats_inc(host, CMD_CRC); in sdhci_cqe_irq()
4000 sdhci_err_stats_inc(host, CMD_TIMEOUT); in sdhci_cqe_irq()
4006 if (!mmc_op_tuning(SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)))) in sdhci_cqe_irq()
4007 sdhci_err_stats_inc(host, DAT_CRC); in sdhci_cqe_irq()
4010 sdhci_err_stats_inc(host, DAT_TIMEOUT); in sdhci_cqe_irq()
4013 sdhci_err_stats_inc(host, ADMA); in sdhci_cqe_irq()
4018 mask = intmask & host->cqe_ier; in sdhci_cqe_irq()
4019 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
4023 mmc_hostname(host->mmc)); in sdhci_cqe_irq()
4025 intmask &= ~(host->cqe_ier | SDHCI_INT_ERROR); in sdhci_cqe_irq()
4027 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
4029 mmc_hostname(host->mmc), intmask); in sdhci_cqe_irq()
4030 sdhci_err_stats_inc(host, UNEXPECTED_IRQ); in sdhci_cqe_irq()
4031 sdhci_dumpregs(host); in sdhci_cqe_irq()
4048 struct sdhci_host *host; in sdhci_alloc_host() local
4056 host = mmc_priv(mmc); in sdhci_alloc_host()
4057 host->mmc = mmc; in sdhci_alloc_host()
4058 host->mmc_host_ops = sdhci_ops; in sdhci_alloc_host()
4059 mmc->ops = &host->mmc_host_ops; in sdhci_alloc_host()
4061 host->flags = SDHCI_SIGNALING_330; in sdhci_alloc_host()
4063 host->cqe_ier = SDHCI_CQE_INT_MASK; in sdhci_alloc_host()
4064 host->cqe_err_ier = SDHCI_CQE_INT_ERR_MASK; in sdhci_alloc_host()
4066 host->tuning_delay = -1; in sdhci_alloc_host()
4067 host->tuning_loop_count = MAX_TUNING_LOOP; in sdhci_alloc_host()
4069 host->sdma_boundary = SDHCI_DEFAULT_BOUNDARY_ARG; in sdhci_alloc_host()
4076 host->adma_table_cnt = SDHCI_MAX_SEGS * 2 + 1; in sdhci_alloc_host()
4077 host->max_adma = 65536; in sdhci_alloc_host()
4079 host->max_timeout_count = 0xE; in sdhci_alloc_host()
4081 return host; in sdhci_alloc_host()
4086 static int sdhci_set_dma_mask(struct sdhci_host *host) in sdhci_set_dma_mask() argument
4088 struct mmc_host *mmc = host->mmc; in sdhci_set_dma_mask()
4092 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) in sdhci_set_dma_mask()
4093 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4096 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_set_dma_mask()
4101 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4116 void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver, in __sdhci_read_caps() argument
4123 if (host->read_caps) in __sdhci_read_caps()
4126 host->read_caps = true; in __sdhci_read_caps()
4129 host->quirks = debug_quirks; in __sdhci_read_caps()
4132 host->quirks2 = debug_quirks2; in __sdhci_read_caps()
4134 sdhci_reset_for_all(host); in __sdhci_read_caps()
4136 if (host->v4_mode) in __sdhci_read_caps()
4137 sdhci_do_enable_v4_mode(host); in __sdhci_read_caps()
4139 device_property_read_u64(mmc_dev(host->mmc), in __sdhci_read_caps()
4141 device_property_read_u64(mmc_dev(host->mmc), in __sdhci_read_caps()
4144 v = ver ? *ver : sdhci_readw(host, SDHCI_HOST_VERSION); in __sdhci_read_caps()
4145 host->version = (v & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; in __sdhci_read_caps()
4147 if (host->quirks & SDHCI_QUIRK_MISSING_CAPS) in __sdhci_read_caps()
4151 host->caps = *caps; in __sdhci_read_caps()
4153 host->caps = sdhci_readl(host, SDHCI_CAPABILITIES); in __sdhci_read_caps()
4154 host->caps &= ~lower_32_bits(dt_caps_mask); in __sdhci_read_caps()
4155 host->caps |= lower_32_bits(dt_caps); in __sdhci_read_caps()
4158 if (host->version < SDHCI_SPEC_300) in __sdhci_read_caps()
4162 host->caps1 = *caps1; in __sdhci_read_caps()
4164 host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); in __sdhci_read_caps()
4165 host->caps1 &= ~upper_32_bits(dt_caps_mask); in __sdhci_read_caps()
4166 host->caps1 |= upper_32_bits(dt_caps); in __sdhci_read_caps()
4171 static void sdhci_allocate_bounce_buffer(struct sdhci_host *host) in sdhci_allocate_bounce_buffer() argument
4173 struct mmc_host *mmc = host->mmc; in sdhci_allocate_bounce_buffer()
4198 host->bounce_buffer = devm_kmalloc(mmc_dev(mmc), in sdhci_allocate_bounce_buffer()
4201 if (!host->bounce_buffer) { in sdhci_allocate_bounce_buffer()
4212 host->bounce_addr = dma_map_single(mmc_dev(mmc), in sdhci_allocate_bounce_buffer()
4213 host->bounce_buffer, in sdhci_allocate_bounce_buffer()
4216 ret = dma_mapping_error(mmc_dev(mmc), host->bounce_addr); in sdhci_allocate_bounce_buffer()
4218 devm_kfree(mmc_dev(mmc), host->bounce_buffer); in sdhci_allocate_bounce_buffer()
4219 host->bounce_buffer = NULL; in sdhci_allocate_bounce_buffer()
4224 host->bounce_buffer_size = bounce_size; in sdhci_allocate_bounce_buffer()
4235 static inline bool sdhci_can_64bit_dma(struct sdhci_host *host) in sdhci_can_64bit_dma() argument
4238 * According to SD Host Controller spec v4.10, bit[27] added from in sdhci_can_64bit_dma()
4242 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) in sdhci_can_64bit_dma()
4243 return host->caps & SDHCI_CAN_64BIT_V4; in sdhci_can_64bit_dma()
4245 return host->caps & SDHCI_CAN_64BIT; in sdhci_can_64bit_dma()
4248 int sdhci_setup_host(struct sdhci_host *host) in sdhci_setup_host() argument
4258 WARN_ON(host == NULL); in sdhci_setup_host()
4259 if (host == NULL) in sdhci_setup_host()
4262 mmc = host->mmc; in sdhci_setup_host()
4266 * early before resetting the host and reading the capabilities so that in sdhci_setup_host()
4267 * the host can take the appropriate action if regulators are not in sdhci_setup_host()
4278 sdhci_readw(host, SDHCI_HOST_VERSION), in sdhci_setup_host()
4279 sdhci_readl(host, SDHCI_PRESENT_STATE)); in sdhci_setup_host()
4281 sdhci_readl(host, SDHCI_CAPABILITIES), in sdhci_setup_host()
4282 sdhci_readl(host, SDHCI_CAPABILITIES_1)); in sdhci_setup_host()
4284 sdhci_read_caps(host); in sdhci_setup_host()
4286 override_timeout_clk = host->timeout_clk; in sdhci_setup_host()
4288 if (host->version > SDHCI_SPEC_420) { in sdhci_setup_host()
4290 mmc_hostname(mmc), host->version); in sdhci_setup_host()
4293 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) in sdhci_setup_host()
4294 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4295 else if (!(host->caps & SDHCI_CAN_DO_SDMA)) in sdhci_setup_host()
4298 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4300 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && in sdhci_setup_host()
4301 (host->flags & SDHCI_USE_SDMA)) { in sdhci_setup_host()
4303 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4306 if ((host->version >= SDHCI_SPEC_200) && in sdhci_setup_host()
4307 (host->caps & SDHCI_CAN_DO_ADMA2)) in sdhci_setup_host()
4308 host->flags |= SDHCI_USE_ADMA; in sdhci_setup_host()
4310 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && in sdhci_setup_host()
4311 (host->flags & SDHCI_USE_ADMA)) { in sdhci_setup_host()
4313 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4316 if (sdhci_can_64bit_dma(host)) in sdhci_setup_host()
4317 host->flags |= SDHCI_USE_64_BIT_DMA; in sdhci_setup_host()
4319 if (host->use_external_dma) { in sdhci_setup_host()
4320 ret = sdhci_external_dma_init(host); in sdhci_setup_host()
4328 sdhci_switch_external_dma(host, false); in sdhci_setup_host()
4331 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4334 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_setup_host()
4335 if (host->ops->set_dma_mask) in sdhci_setup_host()
4336 ret = host->ops->set_dma_mask(host); in sdhci_setup_host()
4338 ret = sdhci_set_dma_mask(host); in sdhci_setup_host()
4340 if (!ret && host->ops->enable_dma) in sdhci_setup_host()
4341 ret = host->ops->enable_dma(host); in sdhci_setup_host()
4346 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4353 if ((host->flags & SDHCI_USE_64_BIT_DMA) && !host->v4_mode) in sdhci_setup_host()
4354 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4356 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4360 if (!(host->flags & SDHCI_USE_64_BIT_DMA)) in sdhci_setup_host()
4361 host->alloc_desc_sz = SDHCI_ADMA2_32_DESC_SZ; in sdhci_setup_host()
4362 else if (!host->alloc_desc_sz) in sdhci_setup_host()
4363 host->alloc_desc_sz = SDHCI_ADMA2_64_DESC_SZ(host); in sdhci_setup_host()
4365 host->desc_sz = host->alloc_desc_sz; in sdhci_setup_host()
4366 host->adma_table_sz = host->adma_table_cnt * host->desc_sz; in sdhci_setup_host()
4368 host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN; in sdhci_setup_host()
4374 host->align_buffer_sz + host->adma_table_sz, in sdhci_setup_host()
4379 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4380 } else if ((dma + host->align_buffer_sz) & in sdhci_setup_host()
4384 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4385 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4386 host->adma_table_sz, buf, dma); in sdhci_setup_host()
4388 host->align_buffer = buf; in sdhci_setup_host()
4389 host->align_addr = dma; in sdhci_setup_host()
4391 host->adma_table = buf + host->align_buffer_sz; in sdhci_setup_host()
4392 host->adma_addr = dma + host->align_buffer_sz; in sdhci_setup_host()
4401 if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) { in sdhci_setup_host()
4402 host->dma_mask = DMA_BIT_MASK(64); in sdhci_setup_host()
4403 mmc_dev(mmc)->dma_mask = &host->dma_mask; in sdhci_setup_host()
4406 if (host->version >= SDHCI_SPEC_300) in sdhci_setup_host()
4407 host->max_clk = FIELD_GET(SDHCI_CLOCK_V3_BASE_MASK, host->caps); in sdhci_setup_host()
4409 host->max_clk = FIELD_GET(SDHCI_CLOCK_BASE_MASK, host->caps); in sdhci_setup_host()
4411 host->max_clk *= 1000000; in sdhci_setup_host()
4412 if (host->max_clk == 0 || host->quirks & in sdhci_setup_host()
4414 if (!host->ops->get_max_clock) { in sdhci_setup_host()
4420 host->max_clk = host->ops->get_max_clock(host); in sdhci_setup_host()
4424 * In case of Host Controller v3.00, find out whether clock in sdhci_setup_host()
4427 host->clk_mul = FIELD_GET(SDHCI_CLOCK_MUL_MASK, host->caps1); in sdhci_setup_host()
4435 if (host->clk_mul) in sdhci_setup_host()
4436 host->clk_mul += 1; in sdhci_setup_host()
4439 * Set host parameters. in sdhci_setup_host()
4441 max_clk = host->max_clk; in sdhci_setup_host()
4443 if (host->ops->get_min_clock) in sdhci_setup_host()
4444 mmc->f_min = host->ops->get_min_clock(host); in sdhci_setup_host()
4445 else if (host->version >= SDHCI_SPEC_300) { in sdhci_setup_host()
4446 if (host->clk_mul) in sdhci_setup_host()
4447 max_clk = host->max_clk * host->clk_mul; in sdhci_setup_host()
4452 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300; in sdhci_setup_host()
4454 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; in sdhci_setup_host()
4459 if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { in sdhci_setup_host()
4460 host->timeout_clk = FIELD_GET(SDHCI_TIMEOUT_CLK_MASK, host->caps); in sdhci_setup_host()
4462 if (host->caps & SDHCI_TIMEOUT_CLK_UNIT) in sdhci_setup_host()
4463 host->timeout_clk *= 1000; in sdhci_setup_host()
4465 if (host->timeout_clk == 0) { in sdhci_setup_host()
4466 if (!host->ops->get_timeout_clock) { in sdhci_setup_host()
4473 host->timeout_clk = in sdhci_setup_host()
4474 DIV_ROUND_UP(host->ops->get_timeout_clock(host), in sdhci_setup_host()
4479 host->timeout_clk = override_timeout_clk; in sdhci_setup_host()
4481 mmc->max_busy_timeout = host->ops->get_max_timeout_count ? in sdhci_setup_host()
4482 host->ops->get_max_timeout_count(host) : 1 << 27; in sdhci_setup_host()
4483 mmc->max_busy_timeout /= host->timeout_clk; in sdhci_setup_host()
4486 if (host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT && in sdhci_setup_host()
4487 !host->ops->get_max_timeout_count) in sdhci_setup_host()
4493 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) in sdhci_setup_host()
4494 host->flags |= SDHCI_AUTO_CMD12; in sdhci_setup_host()
4500 if ((host->version >= SDHCI_SPEC_300) && in sdhci_setup_host()
4501 ((host->flags & SDHCI_USE_ADMA) || in sdhci_setup_host()
4502 !(host->flags & SDHCI_USE_SDMA) || host->v4_mode) && in sdhci_setup_host()
4503 !(host->quirks2 & SDHCI_QUIRK2_ACMD23_BROKEN)) { in sdhci_setup_host()
4504 host->flags |= SDHCI_AUTO_CMD23; in sdhci_setup_host()
4517 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) in sdhci_setup_host()
4520 if (host->quirks2 & SDHCI_QUIRK2_HOST_NO_CMD23) in sdhci_setup_host()
4523 if (host->caps & SDHCI_CAN_DO_HISPD) in sdhci_setup_host()
4526 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_setup_host()
4534 host->sdhci_core_to_disable_vqmmc = !ret; in sdhci_setup_host()
4540 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | in sdhci_setup_host()
4547 host->flags &= ~SDHCI_SIGNALING_330; in sdhci_setup_host()
4557 if (host->quirks2 & SDHCI_QUIRK2_NO_1_8_V) { in sdhci_setup_host()
4558 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4573 if (host->caps1 & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4578 if (host->caps1 & SDHCI_SUPPORT_SDR104) { in sdhci_setup_host()
4583 if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) in sdhci_setup_host()
4585 } else if (host->caps1 & SDHCI_SUPPORT_SDR50) { in sdhci_setup_host()
4589 if (host->quirks2 & SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 && in sdhci_setup_host()
4590 (host->caps1 & SDHCI_SUPPORT_HS400)) in sdhci_setup_host()
4599 if ((host->caps1 & SDHCI_SUPPORT_DDR50) && in sdhci_setup_host()
4600 !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50)) in sdhci_setup_host()
4603 /* Does the host need tuning for SDR50? */ in sdhci_setup_host()
4604 if (host->caps1 & SDHCI_USE_SDR50_TUNING) in sdhci_setup_host()
4605 host->flags |= SDHCI_SDR50_NEEDS_TUNING; in sdhci_setup_host()
4607 /* Driver Type(s) (A, C, D) supported by the host */ in sdhci_setup_host()
4608 if (host->caps1 & SDHCI_DRIVER_TYPE_A) in sdhci_setup_host()
4610 if (host->caps1 & SDHCI_DRIVER_TYPE_C) in sdhci_setup_host()
4612 if (host->caps1 & SDHCI_DRIVER_TYPE_D) in sdhci_setup_host()
4616 host->tuning_count = FIELD_GET(SDHCI_RETUNING_TIMER_COUNT_MASK, in sdhci_setup_host()
4617 host->caps1); in sdhci_setup_host()
4623 if (host->tuning_count) in sdhci_setup_host()
4624 host->tuning_count = 1 << (host->tuning_count - 1); in sdhci_setup_host()
4626 /* Re-tuning mode supported by the Host Controller */ in sdhci_setup_host()
4627 host->tuning_mode = FIELD_GET(SDHCI_RETUNING_MODE_MASK, host->caps1); in sdhci_setup_host()
4632 * According to SD Host Controller spec v3.00, if the Host System in sdhci_setup_host()
4633 * can afford more than 150mA, Host Driver should set XPC to 1. Also in sdhci_setup_host()
4638 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); in sdhci_setup_host()
4655 if (host->caps & SDHCI_CAN_VDD_330) { in sdhci_setup_host()
4662 if (host->caps & SDHCI_CAN_VDD_300) { in sdhci_setup_host()
4669 if (host->caps & SDHCI_CAN_VDD_180) { in sdhci_setup_host()
4677 /* If OCR set by host, use it instead. */ in sdhci_setup_host()
4678 if (host->ocr_mask) in sdhci_setup_host()
4679 ocr_avail = host->ocr_mask; in sdhci_setup_host()
4687 if (host->ocr_avail_sdio) in sdhci_setup_host()
4688 mmc->ocr_avail_sdio &= host->ocr_avail_sdio; in sdhci_setup_host()
4690 if (host->ocr_avail_sd) in sdhci_setup_host()
4691 mmc->ocr_avail_sd &= host->ocr_avail_sd; in sdhci_setup_host()
4695 if (host->ocr_avail_mmc) in sdhci_setup_host()
4696 mmc->ocr_avail_mmc &= host->ocr_avail_mmc; in sdhci_setup_host()
4709 host->flags |= SDHCI_SIGNALING_180; in sdhci_setup_host()
4712 host->flags |= SDHCI_SIGNALING_120; in sdhci_setup_host()
4714 spin_lock_init(&host->lock); in sdhci_setup_host()
4727 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4729 } else if (host->flags & SDHCI_USE_SDMA) { in sdhci_setup_host()
4742 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4743 if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) { in sdhci_setup_host()
4744 host->max_adma = 65532; /* 32-bit alignment */ in sdhci_setup_host()
4757 if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) { in sdhci_setup_host()
4760 mmc->max_blk_size = (host->caps & SDHCI_MAX_BLOCK_MASK) >> in sdhci_setup_host()
4774 mmc->max_blk_count = (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; in sdhci_setup_host()
4778 sdhci_allocate_bounce_buffer(host); in sdhci_setup_host()
4783 if (host->sdhci_core_to_disable_vqmmc) in sdhci_setup_host()
4786 if (host->align_buffer) in sdhci_setup_host()
4787 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4788 host->adma_table_sz, host->align_buffer, in sdhci_setup_host()
4789 host->align_addr); in sdhci_setup_host()
4790 host->adma_table = NULL; in sdhci_setup_host()
4791 host->align_buffer = NULL; in sdhci_setup_host()
4797 void sdhci_cleanup_host(struct sdhci_host *host) in sdhci_cleanup_host() argument
4799 struct mmc_host *mmc = host->mmc; in sdhci_cleanup_host()
4801 if (host->sdhci_core_to_disable_vqmmc) in sdhci_cleanup_host()
4804 if (host->align_buffer) in sdhci_cleanup_host()
4805 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_cleanup_host()
4806 host->adma_table_sz, host->align_buffer, in sdhci_cleanup_host()
4807 host->align_addr); in sdhci_cleanup_host()
4809 if (host->use_external_dma) in sdhci_cleanup_host()
4810 sdhci_external_dma_release(host); in sdhci_cleanup_host()
4812 host->adma_table = NULL; in sdhci_cleanup_host()
4813 host->align_buffer = NULL; in sdhci_cleanup_host()
4817 int __sdhci_add_host(struct sdhci_host *host) in __sdhci_add_host() argument
4820 struct mmc_host *mmc = host->mmc; in __sdhci_add_host()
4824 (host->quirks & SDHCI_QUIRK_BROKEN_CQE)) { in __sdhci_add_host()
4829 host->complete_wq = alloc_workqueue("sdhci", flags, 0); in __sdhci_add_host()
4830 if (!host->complete_wq) in __sdhci_add_host()
4833 INIT_WORK(&host->complete_work, sdhci_complete_work); in __sdhci_add_host()
4835 timer_setup(&host->timer, sdhci_timeout_timer, 0); in __sdhci_add_host()
4836 timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0); in __sdhci_add_host()
4838 init_waitqueue_head(&host->buf_ready_int); in __sdhci_add_host()
4840 sdhci_init(host, 0); in __sdhci_add_host()
4842 ret = request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq, in __sdhci_add_host()
4843 IRQF_SHARED, mmc_hostname(mmc), host); in __sdhci_add_host()
4846 mmc_hostname(mmc), host->irq, ret); in __sdhci_add_host()
4850 ret = sdhci_led_register(host); in __sdhci_add_host()
4862 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), in __sdhci_add_host()
4863 host->use_external_dma ? "External DMA" : in __sdhci_add_host()
4864 (host->flags & SDHCI_USE_ADMA) ? in __sdhci_add_host()
4865 (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" : in __sdhci_add_host()
4866 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); in __sdhci_add_host()
4868 sdhci_enable_card_detection(host); in __sdhci_add_host()
4873 sdhci_led_unregister(host); in __sdhci_add_host()
4875 sdhci_reset_for_all(host); in __sdhci_add_host()
4876 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in __sdhci_add_host()
4877 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in __sdhci_add_host()
4878 free_irq(host->irq, host); in __sdhci_add_host()
4880 destroy_workqueue(host->complete_wq); in __sdhci_add_host()
4886 int sdhci_add_host(struct sdhci_host *host) in sdhci_add_host() argument
4890 ret = sdhci_setup_host(host); in sdhci_add_host()
4894 ret = __sdhci_add_host(host); in sdhci_add_host()
4901 sdhci_cleanup_host(host); in sdhci_add_host()
4907 void sdhci_remove_host(struct sdhci_host *host, int dead) in sdhci_remove_host() argument
4909 struct mmc_host *mmc = host->mmc; in sdhci_remove_host()
4913 spin_lock_irqsave(&host->lock, flags); in sdhci_remove_host()
4915 host->flags |= SDHCI_DEVICE_DEAD; in sdhci_remove_host()
4917 if (sdhci_has_requests(host)) { in sdhci_remove_host()
4920 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_remove_host()
4923 spin_unlock_irqrestore(&host->lock, flags); in sdhci_remove_host()
4926 sdhci_disable_card_detection(host); in sdhci_remove_host()
4930 sdhci_led_unregister(host); in sdhci_remove_host()
4933 sdhci_reset_for_all(host); in sdhci_remove_host()
4935 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_remove_host()
4936 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_remove_host()
4937 free_irq(host->irq, host); in sdhci_remove_host()
4939 del_timer_sync(&host->timer); in sdhci_remove_host()
4940 del_timer_sync(&host->data_timer); in sdhci_remove_host()
4942 destroy_workqueue(host->complete_wq); in sdhci_remove_host()
4944 if (host->sdhci_core_to_disable_vqmmc) in sdhci_remove_host()
4947 if (host->align_buffer) in sdhci_remove_host()
4948 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_remove_host()
4949 host->adma_table_sz, host->align_buffer, in sdhci_remove_host()
4950 host->align_addr); in sdhci_remove_host()
4952 if (host->use_external_dma) in sdhci_remove_host()
4953 sdhci_external_dma_release(host); in sdhci_remove_host()
4955 host->adma_table = NULL; in sdhci_remove_host()
4956 host->align_buffer = NULL; in sdhci_remove_host()
4961 void sdhci_free_host(struct sdhci_host *host) in sdhci_free_host() argument
4963 mmc_free_host(host->mmc); in sdhci_free_host()
4977 ": Secure Digital Host Controller Interface driver\n"); in sdhci_drv_init()
4994 MODULE_DESCRIPTION("Secure Digital Host Controller Interface core driver");