• Home
  • Raw
  • Download

Lines Matching refs:host

41 	pr_debug("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
44 pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x)
51 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable);
53 static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd);
55 void sdhci_dumpregs(struct sdhci_host *host) in sdhci_dumpregs() argument
60 sdhci_readl(host, SDHCI_DMA_ADDRESS), in sdhci_dumpregs()
61 sdhci_readw(host, SDHCI_HOST_VERSION)); in sdhci_dumpregs()
63 sdhci_readw(host, SDHCI_BLOCK_SIZE), in sdhci_dumpregs()
64 sdhci_readw(host, SDHCI_BLOCK_COUNT)); in sdhci_dumpregs()
66 sdhci_readl(host, SDHCI_ARGUMENT), in sdhci_dumpregs()
67 sdhci_readw(host, SDHCI_TRANSFER_MODE)); in sdhci_dumpregs()
69 sdhci_readl(host, SDHCI_PRESENT_STATE), in sdhci_dumpregs()
70 sdhci_readb(host, SDHCI_HOST_CONTROL)); in sdhci_dumpregs()
72 sdhci_readb(host, SDHCI_POWER_CONTROL), in sdhci_dumpregs()
73 sdhci_readb(host, SDHCI_BLOCK_GAP_CONTROL)); in sdhci_dumpregs()
75 sdhci_readb(host, SDHCI_WAKE_UP_CONTROL), in sdhci_dumpregs()
76 sdhci_readw(host, SDHCI_CLOCK_CONTROL)); in sdhci_dumpregs()
78 sdhci_readb(host, SDHCI_TIMEOUT_CONTROL), in sdhci_dumpregs()
79 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_dumpregs()
81 sdhci_readl(host, SDHCI_INT_ENABLE), in sdhci_dumpregs()
82 sdhci_readl(host, SDHCI_SIGNAL_ENABLE)); in sdhci_dumpregs()
84 sdhci_readw(host, SDHCI_AUTO_CMD_STATUS), in sdhci_dumpregs()
85 sdhci_readw(host, SDHCI_SLOT_INT_STATUS)); in sdhci_dumpregs()
87 sdhci_readl(host, SDHCI_CAPABILITIES), in sdhci_dumpregs()
88 sdhci_readl(host, SDHCI_CAPABILITIES_1)); in sdhci_dumpregs()
90 sdhci_readw(host, SDHCI_COMMAND), in sdhci_dumpregs()
91 sdhci_readl(host, SDHCI_MAX_CURRENT)); in sdhci_dumpregs()
93 sdhci_readl(host, SDHCI_RESPONSE), in sdhci_dumpregs()
94 sdhci_readl(host, SDHCI_RESPONSE + 4)); in sdhci_dumpregs()
96 sdhci_readl(host, SDHCI_RESPONSE + 8), in sdhci_dumpregs()
97 sdhci_readl(host, SDHCI_RESPONSE + 12)); in sdhci_dumpregs()
99 sdhci_readw(host, SDHCI_HOST_CONTROL2)); in sdhci_dumpregs()
101 if (host->flags & SDHCI_USE_ADMA) { in sdhci_dumpregs()
102 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_dumpregs()
104 sdhci_readl(host, SDHCI_ADMA_ERROR), in sdhci_dumpregs()
105 sdhci_readl(host, SDHCI_ADMA_ADDRESS_HI), in sdhci_dumpregs()
106 sdhci_readl(host, SDHCI_ADMA_ADDRESS)); in sdhci_dumpregs()
109 sdhci_readl(host, SDHCI_ADMA_ERROR), in sdhci_dumpregs()
110 sdhci_readl(host, SDHCI_ADMA_ADDRESS)); in sdhci_dumpregs()
114 if (host->ops->dump_vendor_regs) in sdhci_dumpregs()
115 host->ops->dump_vendor_regs(host); in sdhci_dumpregs()
127 static void sdhci_do_enable_v4_mode(struct sdhci_host *host) in sdhci_do_enable_v4_mode() argument
131 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_do_enable_v4_mode()
136 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_do_enable_v4_mode()
143 void sdhci_enable_v4_mode(struct sdhci_host *host) in sdhci_enable_v4_mode() argument
145 host->v4_mode = true; in sdhci_enable_v4_mode()
146 sdhci_do_enable_v4_mode(host); in sdhci_enable_v4_mode()
155 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) in sdhci_set_card_detection() argument
159 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) || in sdhci_set_card_detection()
160 !mmc_card_is_removable(host->mmc) || mmc_can_gpio_cd(host->mmc)) in sdhci_set_card_detection()
164 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & in sdhci_set_card_detection()
167 host->ier |= present ? SDHCI_INT_CARD_REMOVE : in sdhci_set_card_detection()
170 host->ier &= ~(SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); in sdhci_set_card_detection()
173 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_card_detection()
174 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_card_detection()
177 static void sdhci_enable_card_detection(struct sdhci_host *host) in sdhci_enable_card_detection() argument
179 sdhci_set_card_detection(host, true); in sdhci_enable_card_detection()
182 static void sdhci_disable_card_detection(struct sdhci_host *host) in sdhci_disable_card_detection() argument
184 sdhci_set_card_detection(host, false); in sdhci_disable_card_detection()
187 static void sdhci_runtime_pm_bus_on(struct sdhci_host *host) in sdhci_runtime_pm_bus_on() argument
189 if (host->bus_on) in sdhci_runtime_pm_bus_on()
191 host->bus_on = true; in sdhci_runtime_pm_bus_on()
192 pm_runtime_get_noresume(host->mmc->parent); in sdhci_runtime_pm_bus_on()
195 static void sdhci_runtime_pm_bus_off(struct sdhci_host *host) in sdhci_runtime_pm_bus_off() argument
197 if (!host->bus_on) in sdhci_runtime_pm_bus_off()
199 host->bus_on = false; in sdhci_runtime_pm_bus_off()
200 pm_runtime_put_noidle(host->mmc->parent); in sdhci_runtime_pm_bus_off()
203 void sdhci_reset(struct sdhci_host *host, u8 mask) in sdhci_reset() argument
207 sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); in sdhci_reset()
210 host->clock = 0; in sdhci_reset()
212 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_reset()
213 sdhci_runtime_pm_bus_off(host); in sdhci_reset()
223 if (!(sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask)) in sdhci_reset()
227 mmc_hostname(host->mmc), (int)mask); in sdhci_reset()
228 sdhci_dumpregs(host); in sdhci_reset()
236 static void 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()
248 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_do_reset()
249 if (host->ops->enable_dma) in sdhci_do_reset()
250 host->ops->enable_dma(host); in sdhci_do_reset()
254 host->preset_enabled = false; in sdhci_do_reset()
258 static void sdhci_set_default_irqs(struct sdhci_host *host) in sdhci_set_default_irqs() argument
260 host->ier = SDHCI_INT_BUS_POWER | SDHCI_INT_DATA_END_BIT | in sdhci_set_default_irqs()
266 if (host->tuning_mode == SDHCI_TUNING_MODE_2 || in sdhci_set_default_irqs()
267 host->tuning_mode == SDHCI_TUNING_MODE_3) in sdhci_set_default_irqs()
268 host->ier |= SDHCI_INT_RETUNE; in sdhci_set_default_irqs()
270 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_default_irqs()
271 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_default_irqs()
274 static void sdhci_config_dma(struct sdhci_host *host) in sdhci_config_dma() argument
279 if (host->version < SDHCI_SPEC_200) in sdhci_config_dma()
282 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_config_dma()
290 if (!(host->flags & SDHCI_REQ_USE_DMA)) in sdhci_config_dma()
294 if (host->flags & SDHCI_USE_ADMA) in sdhci_config_dma()
297 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_config_dma()
303 if (host->v4_mode) { in sdhci_config_dma()
304 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
306 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_config_dma()
307 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_config_dma()
317 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_config_dma()
320 static void sdhci_init(struct sdhci_host *host, int soft) in sdhci_init() argument
322 struct mmc_host *mmc = host->mmc; in sdhci_init()
326 sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); in sdhci_init()
328 sdhci_do_reset(host, SDHCI_RESET_ALL); in sdhci_init()
330 if (host->v4_mode) in sdhci_init()
331 sdhci_do_enable_v4_mode(host); in sdhci_init()
333 spin_lock_irqsave(&host->lock, flags); in sdhci_init()
334 sdhci_set_default_irqs(host); in sdhci_init()
335 spin_unlock_irqrestore(&host->lock, flags); in sdhci_init()
337 host->cqe_on = false; in sdhci_init()
341 host->clock = 0; in sdhci_init()
342 host->reinit_uhs = true; in sdhci_init()
347 static void sdhci_reinit(struct sdhci_host *host) in sdhci_reinit() argument
349 u32 cd = host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT); in sdhci_reinit()
351 sdhci_init(host, 0); in sdhci_reinit()
352 sdhci_enable_card_detection(host); in sdhci_reinit()
360 if (cd != (host->ier & (SDHCI_INT_CARD_REMOVE | SDHCI_INT_CARD_INSERT))) in sdhci_reinit()
361 mmc_detect_change(host->mmc, msecs_to_jiffies(200)); in sdhci_reinit()
364 static void __sdhci_led_activate(struct sdhci_host *host) in __sdhci_led_activate() argument
368 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_activate()
371 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
373 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_activate()
376 static void __sdhci_led_deactivate(struct sdhci_host *host) in __sdhci_led_deactivate() argument
380 if (host->quirks & SDHCI_QUIRK_NO_LED) in __sdhci_led_deactivate()
383 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
385 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in __sdhci_led_deactivate()
392 struct sdhci_host *host = container_of(led, struct sdhci_host, led); in sdhci_led_control() local
395 spin_lock_irqsave(&host->lock, flags); in sdhci_led_control()
397 if (host->runtime_suspended) in sdhci_led_control()
401 __sdhci_led_deactivate(host); in sdhci_led_control()
403 __sdhci_led_activate(host); in sdhci_led_control()
405 spin_unlock_irqrestore(&host->lock, flags); in sdhci_led_control()
408 static int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
410 struct mmc_host *mmc = host->mmc; in sdhci_led_register()
412 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_register()
415 snprintf(host->led_name, sizeof(host->led_name), in sdhci_led_register()
418 host->led.name = host->led_name; in sdhci_led_register()
419 host->led.brightness = LED_OFF; in sdhci_led_register()
420 host->led.default_trigger = mmc_hostname(mmc); in sdhci_led_register()
421 host->led.brightness_set = sdhci_led_control; in sdhci_led_register()
423 return led_classdev_register(mmc_dev(mmc), &host->led); in sdhci_led_register()
426 static void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
428 if (host->quirks & SDHCI_QUIRK_NO_LED) in sdhci_led_unregister()
431 led_classdev_unregister(&host->led); in sdhci_led_unregister()
434 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
438 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
444 static inline int sdhci_led_register(struct sdhci_host *host) in sdhci_led_register() argument
449 static inline void sdhci_led_unregister(struct sdhci_host *host) in sdhci_led_unregister() argument
453 static inline void sdhci_led_activate(struct sdhci_host *host) in sdhci_led_activate() argument
455 __sdhci_led_activate(host); in sdhci_led_activate()
458 static inline void sdhci_led_deactivate(struct sdhci_host *host) in sdhci_led_deactivate() argument
460 __sdhci_led_deactivate(host); in sdhci_led_deactivate()
465 static void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, in sdhci_mod_timer() argument
469 mod_timer(&host->data_timer, timeout); in sdhci_mod_timer()
471 mod_timer(&host->timer, timeout); in sdhci_mod_timer()
474 static void sdhci_del_timer(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_del_timer() argument
477 del_timer(&host->data_timer); in sdhci_del_timer()
479 del_timer(&host->timer); in sdhci_del_timer()
482 static inline bool sdhci_has_requests(struct sdhci_host *host) in sdhci_has_requests() argument
484 return host->cmd || host->data_cmd; in sdhci_has_requests()
493 static void sdhci_read_block_pio(struct sdhci_host *host) in sdhci_read_block_pio() argument
502 blksize = host->data->blksz; in sdhci_read_block_pio()
508 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_read_block_pio()
510 len = min(host->sg_miter.length, blksize); in sdhci_read_block_pio()
513 host->sg_miter.consumed = len; in sdhci_read_block_pio()
515 buf = host->sg_miter.addr; in sdhci_read_block_pio()
519 scratch = sdhci_readl(host, SDHCI_BUFFER); in sdhci_read_block_pio()
532 sg_miter_stop(&host->sg_miter); in sdhci_read_block_pio()
537 static void sdhci_write_block_pio(struct sdhci_host *host) in sdhci_write_block_pio() argument
546 blksize = host->data->blksz; in sdhci_write_block_pio()
553 BUG_ON(!sg_miter_next(&host->sg_miter)); in sdhci_write_block_pio()
555 len = min(host->sg_miter.length, blksize); in sdhci_write_block_pio()
558 host->sg_miter.consumed = len; in sdhci_write_block_pio()
560 buf = host->sg_miter.addr; in sdhci_write_block_pio()
570 sdhci_writel(host, scratch, SDHCI_BUFFER); in sdhci_write_block_pio()
577 sg_miter_stop(&host->sg_miter); in sdhci_write_block_pio()
582 static void sdhci_transfer_pio(struct sdhci_host *host) in sdhci_transfer_pio() argument
586 if (host->blocks == 0) in sdhci_transfer_pio()
589 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
599 if ((host->quirks & SDHCI_QUIRK_BROKEN_SMALL_PIO) && in sdhci_transfer_pio()
600 (host->data->blocks == 1)) in sdhci_transfer_pio()
603 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) { in sdhci_transfer_pio()
604 if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY) in sdhci_transfer_pio()
607 if (host->data->flags & MMC_DATA_READ) in sdhci_transfer_pio()
608 sdhci_read_block_pio(host); in sdhci_transfer_pio()
610 sdhci_write_block_pio(host); in sdhci_transfer_pio()
612 host->blocks--; in sdhci_transfer_pio()
613 if (host->blocks == 0) in sdhci_transfer_pio()
620 static int sdhci_pre_dma_transfer(struct sdhci_host *host, in sdhci_pre_dma_transfer() argument
633 if (host->bounce_buffer) { in sdhci_pre_dma_transfer()
636 if (length > host->bounce_buffer_size) { in sdhci_pre_dma_transfer()
638 mmc_hostname(host->mmc), length, in sdhci_pre_dma_transfer()
639 host->bounce_buffer_size); in sdhci_pre_dma_transfer()
644 if (host->ops->copy_to_bounce_buffer) { in sdhci_pre_dma_transfer()
645 host->ops->copy_to_bounce_buffer(host, in sdhci_pre_dma_transfer()
649 host->bounce_buffer, length); in sdhci_pre_dma_transfer()
653 dma_sync_single_for_device(host->mmc->parent, in sdhci_pre_dma_transfer()
654 host->bounce_addr, in sdhci_pre_dma_transfer()
655 host->bounce_buffer_size, in sdhci_pre_dma_transfer()
661 sg_count = dma_map_sg(mmc_dev(host->mmc), in sdhci_pre_dma_transfer()
687 void sdhci_adma_write_desc(struct sdhci_host *host, void **desc, in sdhci_adma_write_desc() argument
697 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_write_desc()
700 *desc += host->desc_sz; in sdhci_adma_write_desc()
704 static inline void __sdhci_adma_write_desc(struct sdhci_host *host, in __sdhci_adma_write_desc() argument
708 if (host->ops->adma_write_desc) in __sdhci_adma_write_desc()
709 host->ops->adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
711 sdhci_adma_write_desc(host, desc, addr, len, cmd); in __sdhci_adma_write_desc()
722 static void sdhci_adma_table_pre(struct sdhci_host *host, in sdhci_adma_table_pre() argument
737 host->sg_count = sg_count; in sdhci_adma_table_pre()
739 desc = host->adma_table; in sdhci_adma_table_pre()
740 align = host->align_buffer; in sdhci_adma_table_pre()
742 align_addr = host->align_addr; in sdhci_adma_table_pre()
744 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_pre()
764 __sdhci_adma_write_desc(host, &desc, align_addr, in sdhci_adma_table_pre()
782 while (len > host->max_adma) { in sdhci_adma_table_pre()
785 __sdhci_adma_write_desc(host, &desc, addr, n, ADMA2_TRAN_VALID); in sdhci_adma_table_pre()
792 __sdhci_adma_write_desc(host, &desc, addr, len, in sdhci_adma_table_pre()
799 WARN_ON((desc - host->adma_table) >= host->adma_table_sz); in sdhci_adma_table_pre()
802 if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) { in sdhci_adma_table_pre()
804 if (desc != host->adma_table) { in sdhci_adma_table_pre()
805 desc -= host->desc_sz; in sdhci_adma_table_pre()
810 __sdhci_adma_write_desc(host, &desc, 0, 0, ADMA2_NOP_END_VALID); in sdhci_adma_table_pre()
814 static void sdhci_adma_table_post(struct sdhci_host *host, in sdhci_adma_table_post() argument
827 for_each_sg(data->sg, sg, host->sg_count, i) in sdhci_adma_table_post()
834 dma_sync_sg_for_cpu(mmc_dev(host->mmc), data->sg, in sdhci_adma_table_post()
837 align = host->align_buffer; in sdhci_adma_table_post()
839 for_each_sg(data->sg, sg, host->sg_count, i) { in sdhci_adma_table_post()
855 static void sdhci_set_adma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_adma_addr() argument
857 sdhci_writel(host, lower_32_bits(addr), SDHCI_ADMA_ADDRESS); in sdhci_set_adma_addr()
858 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_set_adma_addr()
859 sdhci_writel(host, upper_32_bits(addr), SDHCI_ADMA_ADDRESS_HI); in sdhci_set_adma_addr()
862 static dma_addr_t sdhci_sdma_address(struct sdhci_host *host) in sdhci_sdma_address() argument
864 if (host->bounce_buffer) in sdhci_sdma_address()
865 return host->bounce_addr; in sdhci_sdma_address()
867 return sg_dma_address(host->data->sg); in sdhci_sdma_address()
870 static void sdhci_set_sdma_addr(struct sdhci_host *host, dma_addr_t addr) in sdhci_set_sdma_addr() argument
872 if (host->v4_mode) in sdhci_set_sdma_addr()
873 sdhci_set_adma_addr(host, addr); in sdhci_set_sdma_addr()
875 sdhci_writel(host, addr, SDHCI_DMA_ADDRESS); in sdhci_set_sdma_addr()
878 static unsigned int sdhci_target_timeout(struct sdhci_host *host, in sdhci_target_timeout() argument
889 if (host->clock && data->timeout_clks) { in sdhci_target_timeout()
898 if (do_div(val, host->clock)) in sdhci_target_timeout()
907 static void sdhci_calc_sw_timeout(struct sdhci_host *host, in sdhci_calc_sw_timeout() argument
911 struct mmc_host *mmc = host->mmc; in sdhci_calc_sw_timeout()
919 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_sw_timeout()
924 freq = host->mmc->actual_clock ? : host->clock; in sdhci_calc_sw_timeout()
930 host->data_timeout = data->blocks * target_timeout + in sdhci_calc_sw_timeout()
933 host->data_timeout = target_timeout; in sdhci_calc_sw_timeout()
936 if (host->data_timeout) in sdhci_calc_sw_timeout()
937 host->data_timeout += MMC_CMD_TRANSFER_TIME; in sdhci_calc_sw_timeout()
940 static u8 sdhci_calc_timeout(struct sdhci_host *host, struct mmc_command *cmd, in sdhci_calc_timeout() argument
955 if (host->quirks & SDHCI_QUIRK_BROKEN_TIMEOUT_VAL) in sdhci_calc_timeout()
968 target_timeout = sdhci_target_timeout(host, cmd, data); in sdhci_calc_timeout()
981 current_timeout = (1 << 13) * 1000 / host->timeout_clk; in sdhci_calc_timeout()
990 if (!(host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT)) in sdhci_calc_timeout()
1001 static void sdhci_set_transfer_irqs(struct sdhci_host *host) in sdhci_set_transfer_irqs() argument
1006 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_irqs()
1007 host->ier = (host->ier & ~pio_irqs) | dma_irqs; in sdhci_set_transfer_irqs()
1009 host->ier = (host->ier & ~dma_irqs) | pio_irqs; in sdhci_set_transfer_irqs()
1011 if (host->flags & (SDHCI_AUTO_CMD23 | SDHCI_AUTO_CMD12)) in sdhci_set_transfer_irqs()
1012 host->ier |= SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1014 host->ier &= ~SDHCI_INT_AUTO_CMD_ERR; in sdhci_set_transfer_irqs()
1016 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_transfer_irqs()
1017 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_transfer_irqs()
1020 void sdhci_set_data_timeout_irq(struct sdhci_host *host, bool enable) in sdhci_set_data_timeout_irq() argument
1023 host->ier |= SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1025 host->ier &= ~SDHCI_INT_DATA_TIMEOUT; in sdhci_set_data_timeout_irq()
1026 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_set_data_timeout_irq()
1027 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_set_data_timeout_irq()
1031 void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in __sdhci_set_timeout() argument
1034 u8 count = sdhci_calc_timeout(host, cmd, &too_big); in __sdhci_set_timeout()
1037 host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT) { in __sdhci_set_timeout()
1038 sdhci_calc_sw_timeout(host, cmd); in __sdhci_set_timeout()
1039 sdhci_set_data_timeout_irq(host, false); in __sdhci_set_timeout()
1040 } else if (!(host->ier & SDHCI_INT_DATA_TIMEOUT)) { in __sdhci_set_timeout()
1041 sdhci_set_data_timeout_irq(host, true); in __sdhci_set_timeout()
1044 sdhci_writeb(host, count, SDHCI_TIMEOUT_CONTROL); in __sdhci_set_timeout()
1048 static void sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_set_timeout() argument
1050 if (host->ops->set_timeout) in sdhci_set_timeout()
1051 host->ops->set_timeout(host, cmd); in sdhci_set_timeout()
1053 __sdhci_set_timeout(host, cmd); in sdhci_set_timeout()
1056 static void sdhci_initialize_data(struct sdhci_host *host, in sdhci_initialize_data() argument
1059 WARN_ON(host->data); in sdhci_initialize_data()
1063 BUG_ON(data->blksz > host->mmc->max_blk_size); in sdhci_initialize_data()
1066 host->data = data; in sdhci_initialize_data()
1067 host->data_early = 0; in sdhci_initialize_data()
1068 host->data->bytes_xfered = 0; in sdhci_initialize_data()
1071 static inline void sdhci_set_block_info(struct sdhci_host *host, in sdhci_set_block_info() argument
1075 sdhci_writew(host, in sdhci_set_block_info()
1076 SDHCI_MAKE_BLKSZ(host->sdma_boundary, data->blksz), in sdhci_set_block_info()
1082 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_set_block_info()
1083 (host->quirks2 & SDHCI_QUIRK2_USE_32BIT_BLK_CNT)) { in sdhci_set_block_info()
1084 if (sdhci_readw(host, SDHCI_BLOCK_COUNT)) in sdhci_set_block_info()
1085 sdhci_writew(host, 0, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1086 sdhci_writew(host, data->blocks, SDHCI_32BIT_BLK_CNT); in sdhci_set_block_info()
1088 sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT); in sdhci_set_block_info()
1092 static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_prepare_data() argument
1096 sdhci_initialize_data(host, data); in sdhci_prepare_data()
1098 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_prepare_data()
1103 host->flags |= SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1114 if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1115 if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) { in sdhci_prepare_data()
1125 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) in sdhci_prepare_data()
1127 if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) in sdhci_prepare_data()
1136 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1141 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1148 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_prepare_data()
1149 int sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_prepare_data()
1157 host->flags &= ~SDHCI_REQ_USE_DMA; in sdhci_prepare_data()
1158 } else if (host->flags & SDHCI_USE_ADMA) { in sdhci_prepare_data()
1159 sdhci_adma_table_pre(host, data, sg_cnt); in sdhci_prepare_data()
1160 sdhci_set_adma_addr(host, host->adma_addr); in sdhci_prepare_data()
1163 sdhci_set_sdma_addr(host, sdhci_sdma_address(host)); in sdhci_prepare_data()
1167 sdhci_config_dma(host); in sdhci_prepare_data()
1169 if (!(host->flags & SDHCI_REQ_USE_DMA)) { in sdhci_prepare_data()
1173 if (host->data->flags & MMC_DATA_READ) in sdhci_prepare_data()
1177 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); in sdhci_prepare_data()
1178 host->blocks = data->blocks; in sdhci_prepare_data()
1181 sdhci_set_transfer_irqs(host); in sdhci_prepare_data()
1183 sdhci_set_block_info(host, data); in sdhci_prepare_data()
1188 static int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1191 struct mmc_host *mmc = host->mmc; in sdhci_external_dma_init()
1193 host->tx_chan = dma_request_chan(mmc->parent, "tx"); in sdhci_external_dma_init()
1194 if (IS_ERR(host->tx_chan)) { in sdhci_external_dma_init()
1195 ret = PTR_ERR(host->tx_chan); in sdhci_external_dma_init()
1198 host->tx_chan = NULL; in sdhci_external_dma_init()
1202 host->rx_chan = dma_request_chan(mmc->parent, "rx"); in sdhci_external_dma_init()
1203 if (IS_ERR(host->rx_chan)) { in sdhci_external_dma_init()
1204 if (host->tx_chan) { in sdhci_external_dma_init()
1205 dma_release_channel(host->tx_chan); in sdhci_external_dma_init()
1206 host->tx_chan = NULL; in sdhci_external_dma_init()
1209 ret = PTR_ERR(host->rx_chan); in sdhci_external_dma_init()
1212 host->rx_chan = NULL; in sdhci_external_dma_init()
1218 static struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1221 return data->flags & MMC_DATA_WRITE ? host->tx_chan : host->rx_chan; in sdhci_external_dma_channel()
1224 static int sdhci_external_dma_setup(struct sdhci_host *host, in sdhci_external_dma_setup() argument
1236 if (!host->mapbase) in sdhci_external_dma_setup()
1240 cfg.src_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1241 cfg.dst_addr = host->mapbase + SDHCI_BUFFER; in sdhci_external_dma_setup()
1253 chan = sdhci_external_dma_channel(host, data); in sdhci_external_dma_setup()
1259 sg_cnt = sdhci_pre_dma_transfer(host, data, COOKIE_MAPPED); in sdhci_external_dma_setup()
1279 static void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1281 if (host->tx_chan) { in sdhci_external_dma_release()
1282 dma_release_channel(host->tx_chan); in sdhci_external_dma_release()
1283 host->tx_chan = NULL; in sdhci_external_dma_release()
1286 if (host->rx_chan) { in sdhci_external_dma_release()
1287 dma_release_channel(host->rx_chan); in sdhci_external_dma_release()
1288 host->rx_chan = NULL; in sdhci_external_dma_release()
1291 sdhci_switch_external_dma(host, false); in sdhci_external_dma_release()
1294 static void __sdhci_external_dma_prepare_data(struct sdhci_host *host, in __sdhci_external_dma_prepare_data() argument
1299 sdhci_initialize_data(host, data); in __sdhci_external_dma_prepare_data()
1301 host->flags |= SDHCI_REQ_USE_DMA; in __sdhci_external_dma_prepare_data()
1302 sdhci_set_transfer_irqs(host); in __sdhci_external_dma_prepare_data()
1304 sdhci_set_block_info(host, data); in __sdhci_external_dma_prepare_data()
1307 static void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1310 if (!sdhci_external_dma_setup(host, cmd)) { in sdhci_external_dma_prepare_data()
1311 __sdhci_external_dma_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1313 sdhci_external_dma_release(host); in sdhci_external_dma_prepare_data()
1315 mmc_hostname(host->mmc)); in sdhci_external_dma_prepare_data()
1316 sdhci_prepare_data(host, cmd); in sdhci_external_dma_prepare_data()
1320 static void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1328 chan = sdhci_external_dma_channel(host, cmd->data); in sdhci_external_dma_pre_transfer()
1335 static inline int sdhci_external_dma_init(struct sdhci_host *host) in sdhci_external_dma_init() argument
1340 static inline void sdhci_external_dma_release(struct sdhci_host *host) in sdhci_external_dma_release() argument
1344 static inline void sdhci_external_dma_prepare_data(struct sdhci_host *host, in sdhci_external_dma_prepare_data() argument
1351 static inline void sdhci_external_dma_pre_transfer(struct sdhci_host *host, in sdhci_external_dma_pre_transfer() argument
1356 static inline struct dma_chan *sdhci_external_dma_channel(struct sdhci_host *host, in sdhci_external_dma_channel() argument
1364 void sdhci_switch_external_dma(struct sdhci_host *host, bool en) in sdhci_switch_external_dma() argument
1366 host->use_external_dma = en; in sdhci_switch_external_dma()
1370 static inline bool sdhci_auto_cmd12(struct sdhci_host *host, in sdhci_auto_cmd12() argument
1373 return !mrq->sbc && (host->flags & SDHCI_AUTO_CMD12) && in sdhci_auto_cmd12()
1377 static inline bool sdhci_auto_cmd23(struct sdhci_host *host, in sdhci_auto_cmd23() argument
1380 return mrq->sbc && (host->flags & SDHCI_AUTO_CMD23); in sdhci_auto_cmd23()
1383 static inline bool sdhci_manual_cmd23(struct sdhci_host *host, in sdhci_manual_cmd23() argument
1386 return mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23); in sdhci_manual_cmd23()
1389 static inline void sdhci_auto_cmd_select(struct sdhci_host *host, in sdhci_auto_cmd_select() argument
1393 bool use_cmd12 = sdhci_auto_cmd12(host, cmd->mrq) && in sdhci_auto_cmd_select()
1395 bool use_cmd23 = sdhci_auto_cmd23(host, cmd->mrq); in sdhci_auto_cmd_select()
1404 if (host->version >= SDHCI_SPEC_410 && host->v4_mode && in sdhci_auto_cmd_select()
1408 ctrl2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1413 sdhci_writew(host, ctrl2, SDHCI_HOST_CONTROL2); in sdhci_auto_cmd_select()
1428 static void sdhci_set_transfer_mode(struct sdhci_host *host, in sdhci_set_transfer_mode() argument
1435 if (host->quirks2 & in sdhci_set_transfer_mode()
1439 sdhci_writew(host, 0x0, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1442 mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1443 sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | in sdhci_set_transfer_mode()
1449 WARN_ON(!host->data); in sdhci_set_transfer_mode()
1451 if (!(host->quirks2 & SDHCI_QUIRK2_SUPPORT_SINGLE)) in sdhci_set_transfer_mode()
1456 sdhci_auto_cmd_select(host, cmd, &mode); in sdhci_set_transfer_mode()
1457 if (sdhci_auto_cmd23(host, cmd->mrq)) in sdhci_set_transfer_mode()
1458 sdhci_writel(host, cmd->mrq->sbc->arg, SDHCI_ARGUMENT2); in sdhci_set_transfer_mode()
1463 if (host->flags & SDHCI_REQ_USE_DMA) in sdhci_set_transfer_mode()
1466 sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); in sdhci_set_transfer_mode()
1469 static bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_needs_reset() argument
1471 return (!(host->flags & SDHCI_DEVICE_DEAD) && in sdhci_needs_reset()
1475 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))); in sdhci_needs_reset()
1478 static void sdhci_set_mrq_done(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_set_mrq_done() argument
1483 if (host->mrqs_done[i] == mrq) { in sdhci_set_mrq_done()
1490 if (!host->mrqs_done[i]) { in sdhci_set_mrq_done()
1491 host->mrqs_done[i] = mrq; in sdhci_set_mrq_done()
1499 static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in __sdhci_finish_mrq() argument
1501 if (host->cmd && host->cmd->mrq == mrq) in __sdhci_finish_mrq()
1502 host->cmd = NULL; in __sdhci_finish_mrq()
1504 if (host->data_cmd && host->data_cmd->mrq == mrq) in __sdhci_finish_mrq()
1505 host->data_cmd = NULL; in __sdhci_finish_mrq()
1507 if (host->deferred_cmd && host->deferred_cmd->mrq == mrq) in __sdhci_finish_mrq()
1508 host->deferred_cmd = NULL; in __sdhci_finish_mrq()
1510 if (host->data && host->data->mrq == mrq) in __sdhci_finish_mrq()
1511 host->data = NULL; in __sdhci_finish_mrq()
1513 if (sdhci_needs_reset(host, mrq)) in __sdhci_finish_mrq()
1514 host->pending_reset = true; in __sdhci_finish_mrq()
1516 sdhci_set_mrq_done(host, mrq); in __sdhci_finish_mrq()
1518 sdhci_del_timer(host, mrq); in __sdhci_finish_mrq()
1520 if (!sdhci_has_requests(host)) in __sdhci_finish_mrq()
1521 sdhci_led_deactivate(host); in __sdhci_finish_mrq()
1524 static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) in sdhci_finish_mrq() argument
1526 __sdhci_finish_mrq(host, mrq); in sdhci_finish_mrq()
1528 queue_work(host->complete_wq, &host->complete_work); in sdhci_finish_mrq()
1531 static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout) in __sdhci_finish_data() argument
1533 struct mmc_command *data_cmd = host->data_cmd; in __sdhci_finish_data()
1534 struct mmc_data *data = host->data; in __sdhci_finish_data()
1536 host->data = NULL; in __sdhci_finish_data()
1537 host->data_cmd = NULL; in __sdhci_finish_data()
1544 if (!host->cmd || host->cmd == data_cmd) in __sdhci_finish_data()
1545 sdhci_do_reset(host, SDHCI_RESET_CMD); in __sdhci_finish_data()
1546 sdhci_do_reset(host, SDHCI_RESET_DATA); in __sdhci_finish_data()
1549 if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_ADMA)) == in __sdhci_finish_data()
1551 sdhci_adma_table_post(host, data); in __sdhci_finish_data()
1571 ((!data->mrq->sbc && !sdhci_auto_cmd12(host, data->mrq)) || in __sdhci_finish_data()
1579 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1582 host->cmd = NULL; in __sdhci_finish_data()
1583 if (!sdhci_send_command(host, data->stop)) { in __sdhci_finish_data()
1590 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1592 WARN_ON(host->deferred_cmd); in __sdhci_finish_data()
1593 host->deferred_cmd = data->stop; in __sdhci_finish_data()
1598 __sdhci_finish_mrq(host, data->mrq); in __sdhci_finish_data()
1602 static void sdhci_finish_data(struct sdhci_host *host) in sdhci_finish_data() argument
1604 __sdhci_finish_data(host, false); in sdhci_finish_data()
1607 static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_send_command() argument
1613 WARN_ON(host->cmd); in sdhci_send_command()
1618 if ((host->quirks2 & SDHCI_QUIRK2_STOP_WITH_TC) && in sdhci_send_command()
1631 if (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) in sdhci_send_command()
1634 host->cmd = cmd; in sdhci_send_command()
1635 host->data_timeout = 0; in sdhci_send_command()
1637 WARN_ON(host->data_cmd); in sdhci_send_command()
1638 host->data_cmd = cmd; in sdhci_send_command()
1639 sdhci_set_timeout(host, cmd); in sdhci_send_command()
1643 if (host->use_external_dma) in sdhci_send_command()
1644 sdhci_external_dma_prepare_data(host, cmd); in sdhci_send_command()
1646 sdhci_prepare_data(host, cmd); in sdhci_send_command()
1649 sdhci_writel(host, cmd->arg, SDHCI_ARGUMENT); in sdhci_send_command()
1651 sdhci_set_transfer_mode(host, cmd); in sdhci_send_command()
1683 if (host->data_timeout) in sdhci_send_command()
1684 timeout += nsecs_to_jiffies(host->data_timeout); in sdhci_send_command()
1689 sdhci_mod_timer(host, cmd->mrq, timeout); in sdhci_send_command()
1691 if (host->use_external_dma) in sdhci_send_command()
1692 sdhci_external_dma_pre_transfer(host, cmd); in sdhci_send_command()
1694 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND); in sdhci_send_command()
1699 static bool sdhci_present_error(struct sdhci_host *host, in sdhci_present_error() argument
1702 if (!present || host->flags & SDHCI_DEVICE_DEAD) { in sdhci_present_error()
1710 static bool sdhci_send_command_retry(struct sdhci_host *host, in sdhci_send_command_retry() argument
1713 __releases(host->lock) in sdhci_send_command_retry()
1714 __acquires(host->lock) in sdhci_send_command_retry()
1716 struct mmc_command *deferred_cmd = host->deferred_cmd; in sdhci_send_command_retry()
1720 while (!sdhci_send_command(host, cmd)) { in sdhci_send_command_retry()
1723 mmc_hostname(host->mmc)); in sdhci_send_command_retry()
1724 sdhci_dumpregs(host); in sdhci_send_command_retry()
1729 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_command_retry()
1733 present = host->mmc->ops->get_cd(host->mmc); in sdhci_send_command_retry()
1735 spin_lock_irqsave(&host->lock, flags); in sdhci_send_command_retry()
1738 if (cmd == deferred_cmd && cmd != host->deferred_cmd) in sdhci_send_command_retry()
1741 if (sdhci_present_error(host, cmd, present)) in sdhci_send_command_retry()
1745 if (cmd == host->deferred_cmd) in sdhci_send_command_retry()
1746 host->deferred_cmd = NULL; in sdhci_send_command_retry()
1751 static void sdhci_read_rsp_136(struct sdhci_host *host, struct mmc_command *cmd) in sdhci_read_rsp_136() argument
1757 cmd->resp[i] = sdhci_readl(host, reg); in sdhci_read_rsp_136()
1760 if (host->quirks2 & SDHCI_QUIRK2_RSP_136_HAS_CRC) in sdhci_read_rsp_136()
1771 static void sdhci_finish_command(struct sdhci_host *host) in sdhci_finish_command() argument
1773 struct mmc_command *cmd = host->cmd; in sdhci_finish_command()
1775 host->cmd = NULL; in sdhci_finish_command()
1779 sdhci_read_rsp_136(host, cmd); in sdhci_finish_command()
1781 cmd->resp[0] = sdhci_readl(host, SDHCI_RESPONSE); in sdhci_finish_command()
1786 mmc_command_done(host->mmc, cmd->mrq); in sdhci_finish_command()
1801 } else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && in sdhci_finish_command()
1802 cmd == host->data_cmd) { in sdhci_finish_command()
1810 if (!sdhci_send_command(host, cmd->mrq->cmd)) { in sdhci_finish_command()
1811 WARN_ON(host->deferred_cmd); in sdhci_finish_command()
1812 host->deferred_cmd = cmd->mrq->cmd; in sdhci_finish_command()
1817 if (host->data && host->data_early) in sdhci_finish_command()
1818 sdhci_finish_data(host); in sdhci_finish_command()
1821 __sdhci_finish_mrq(host, cmd->mrq); in sdhci_finish_command()
1825 static u16 sdhci_get_preset_value(struct sdhci_host *host) in sdhci_get_preset_value() argument
1829 switch (host->timing) { in sdhci_get_preset_value()
1832 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HIGH_SPEED); in sdhci_get_preset_value()
1835 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1838 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR25); in sdhci_get_preset_value()
1841 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR50); in sdhci_get_preset_value()
1845 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104); in sdhci_get_preset_value()
1849 preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50); in sdhci_get_preset_value()
1852 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HS400); in sdhci_get_preset_value()
1856 mmc_hostname(host->mmc)); in sdhci_get_preset_value()
1857 preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR12); in sdhci_get_preset_value()
1863 u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, in sdhci_calc_clk() argument
1871 if (host->version >= SDHCI_SPEC_300) { in sdhci_calc_clk()
1872 if (host->preset_enabled) { in sdhci_calc_clk()
1875 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_calc_clk()
1876 pre_val = sdhci_get_preset_value(host); in sdhci_calc_clk()
1878 if (host->clk_mul && in sdhci_calc_clk()
1882 clk_mul = host->clk_mul; in sdhci_calc_clk()
1893 if (host->clk_mul) { in sdhci_calc_clk()
1895 if ((host->max_clk * host->clk_mul / div) in sdhci_calc_clk()
1899 if ((host->max_clk * host->clk_mul / div) <= clock) { in sdhci_calc_clk()
1906 clk_mul = host->clk_mul; in sdhci_calc_clk()
1917 if (!host->clk_mul || switch_base_clk) { in sdhci_calc_clk()
1919 if (host->max_clk <= clock) in sdhci_calc_clk()
1924 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1930 if ((host->quirks2 & SDHCI_QUIRK2_CLOCK_DIV_ZERO_BROKEN) in sdhci_calc_clk()
1931 && !div && host->max_clk <= 25000000) in sdhci_calc_clk()
1937 if ((host->max_clk / div) <= clock) in sdhci_calc_clk()
1946 *actual_clock = (host->max_clk * clk_mul) / real_div; in sdhci_calc_clk()
1955 void sdhci_enable_clk(struct sdhci_host *host, u16 clk) in sdhci_enable_clk() argument
1960 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1967 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1972 mmc_hostname(host->mmc)); in sdhci_enable_clk()
1973 sdhci_dumpregs(host); in sdhci_enable_clk()
1979 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) { in sdhci_enable_clk()
1982 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1989 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
1994 mmc_hostname(host->mmc)); in sdhci_enable_clk()
1995 sdhci_dumpregs(host); in sdhci_enable_clk()
2003 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_enable_clk()
2007 void sdhci_set_clock(struct sdhci_host *host, unsigned int clock) in sdhci_set_clock() argument
2011 host->mmc->actual_clock = 0; in sdhci_set_clock()
2013 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); in sdhci_set_clock()
2018 clk = sdhci_calc_clk(host, clock, &host->mmc->actual_clock); in sdhci_set_clock()
2019 sdhci_enable_clk(host, clk); in sdhci_set_clock()
2023 static void sdhci_set_power_reg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_reg() argument
2026 struct mmc_host *mmc = host->mmc; in sdhci_set_power_reg()
2031 sdhci_writeb(host, SDHCI_POWER_ON, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2033 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_reg()
2036 void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, in sdhci_set_power_noreg() argument
2069 mmc_hostname(host->mmc), vdd); in sdhci_set_power_noreg()
2074 if (host->pwr == pwr) in sdhci_set_power_noreg()
2077 host->pwr = pwr; in sdhci_set_power_noreg()
2080 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2081 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2082 sdhci_runtime_pm_bus_off(host); in sdhci_set_power_noreg()
2088 if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE)) in sdhci_set_power_noreg()
2089 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2096 if (host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER) in sdhci_set_power_noreg()
2097 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2101 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); in sdhci_set_power_noreg()
2103 if (host->quirks2 & SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON) in sdhci_set_power_noreg()
2104 sdhci_runtime_pm_bus_on(host); in sdhci_set_power_noreg()
2110 if (host->quirks & SDHCI_QUIRK_DELAY_AFTER_POWER) in sdhci_set_power_noreg()
2116 void sdhci_set_power(struct sdhci_host *host, unsigned char mode, in sdhci_set_power() argument
2119 if (IS_ERR(host->mmc->supply.vmmc)) in sdhci_set_power()
2120 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power()
2122 sdhci_set_power_reg(host, mode, vdd); in sdhci_set_power()
2132 void sdhci_set_power_and_bus_voltage(struct sdhci_host *host, in sdhci_set_power_and_bus_voltage() argument
2136 if (!IS_ERR(host->mmc->supply.vmmc)) { in sdhci_set_power_and_bus_voltage()
2137 struct mmc_host *mmc = host->mmc; in sdhci_set_power_and_bus_voltage()
2141 sdhci_set_power_noreg(host, mode, vdd); in sdhci_set_power_and_bus_voltage()
2153 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request() local
2161 spin_lock_irqsave(&host->lock, flags); in sdhci_request()
2163 sdhci_led_activate(host); in sdhci_request()
2165 if (sdhci_present_error(host, mrq->cmd, present)) in sdhci_request()
2168 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request()
2170 if (!sdhci_send_command_retry(host, cmd, flags)) in sdhci_request()
2173 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2178 sdhci_finish_mrq(host, mrq); in sdhci_request()
2179 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request()
2185 struct sdhci_host *host = mmc_priv(mmc); in sdhci_request_atomic() local
2190 spin_lock_irqsave(&host->lock, flags); in sdhci_request_atomic()
2192 if (sdhci_present_error(host, mrq->cmd, true)) { in sdhci_request_atomic()
2193 sdhci_finish_mrq(host, mrq); in sdhci_request_atomic()
2197 cmd = sdhci_manual_cmd23(host, mrq) ? mrq->sbc : mrq->cmd; in sdhci_request_atomic()
2206 if (!sdhci_send_command(host, cmd)) in sdhci_request_atomic()
2209 sdhci_led_activate(host); in sdhci_request_atomic()
2212 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_atomic()
2217 void sdhci_set_bus_width(struct sdhci_host *host, int width) in sdhci_set_bus_width() argument
2221 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2226 if (host->mmc->caps & MMC_CAP_8_BIT_DATA) in sdhci_set_bus_width()
2233 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_bus_width()
2237 void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing) in sdhci_set_uhs_signaling() argument
2241 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2258 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_uhs_signaling()
2276 static bool sdhci_preset_needed(struct sdhci_host *host, unsigned char timing) in sdhci_preset_needed() argument
2278 return !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN) && in sdhci_preset_needed()
2282 static bool sdhci_presetable_values_change(struct sdhci_host *host, struct mmc_ios *ios) in sdhci_presetable_values_change() argument
2289 return !host->preset_enabled && in sdhci_presetable_values_change()
2290 (sdhci_preset_needed(host, ios->timing) || host->drv_type != ios->drv_type); in sdhci_presetable_values_change()
2295 struct sdhci_host *host = mmc_priv(mmc); in sdhci_set_ios() local
2296 bool reinit_uhs = host->reinit_uhs; in sdhci_set_ios()
2300 host->reinit_uhs = false; in sdhci_set_ios()
2305 if (host->flags & SDHCI_DEVICE_DEAD) { in sdhci_set_ios()
2317 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_set_ios()
2318 sdhci_reinit(host); in sdhci_set_ios()
2321 if (host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2323 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) in sdhci_set_ios()
2324 sdhci_enable_preset_value(host, false); in sdhci_set_ios()
2326 if (!ios->clock || ios->clock != host->clock) { in sdhci_set_ios()
2327 turning_on_clk = ios->clock && !host->clock; in sdhci_set_ios()
2329 host->ops->set_clock(host, ios->clock); in sdhci_set_ios()
2330 host->clock = ios->clock; in sdhci_set_ios()
2332 if (host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK && in sdhci_set_ios()
2333 host->clock) { in sdhci_set_ios()
2334 host->timeout_clk = host->mmc->actual_clock ? in sdhci_set_ios()
2335 host->mmc->actual_clock / 1000 : in sdhci_set_ios()
2336 host->clock / 1000; in sdhci_set_ios()
2337 host->mmc->max_busy_timeout = in sdhci_set_ios()
2338 host->ops->get_max_timeout_count ? in sdhci_set_ios()
2339 host->ops->get_max_timeout_count(host) : in sdhci_set_ios()
2341 host->mmc->max_busy_timeout /= host->timeout_clk; in sdhci_set_ios()
2345 if (host->ops->set_power) in sdhci_set_ios()
2346 host->ops->set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2348 sdhci_set_power(host, ios->power_mode, ios->vdd); in sdhci_set_ios()
2350 if (host->ops->platform_send_init_74_clocks) in sdhci_set_ios()
2351 host->ops->platform_send_init_74_clocks(host, ios->power_mode); in sdhci_set_ios()
2353 host->ops->set_bus_width(host, ios->bus_width); in sdhci_set_ios()
2361 host->timing == ios->timing && in sdhci_set_ios()
2362 host->version >= SDHCI_SPEC_300 && in sdhci_set_ios()
2363 !sdhci_presetable_values_change(host, ios)) in sdhci_set_ios()
2366 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2368 if (!(host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)) { in sdhci_set_ios()
2383 if (host->version >= SDHCI_SPEC_300) { in sdhci_set_ios()
2386 if (!host->preset_enabled) { in sdhci_set_ios()
2387 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2392 ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2408 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); in sdhci_set_ios()
2409 host->drv_type = ios->drv_type; in sdhci_set_ios()
2419 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2421 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2423 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2426 host->ops->set_clock(host, host->clock); in sdhci_set_ios()
2430 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2432 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); in sdhci_set_ios()
2434 host->ops->set_uhs_signaling(host, ios->timing); in sdhci_set_ios()
2435 host->timing = ios->timing; in sdhci_set_ios()
2437 if (sdhci_preset_needed(host, ios->timing)) { in sdhci_set_ios()
2440 sdhci_enable_preset_value(host, true); in sdhci_set_ios()
2441 preset = sdhci_get_preset_value(host); in sdhci_set_ios()
2444 host->drv_type = ios->drv_type; in sdhci_set_ios()
2448 host->ops->set_clock(host, host->clock); in sdhci_set_ios()
2450 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_set_ios()
2457 if (host->quirks & SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS) in sdhci_set_ios()
2458 sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); in sdhci_set_ios()
2464 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_cd() local
2467 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_get_cd()
2471 if (!mmc_card_is_removable(host->mmc)) in sdhci_get_cd()
2482 if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) in sdhci_get_cd()
2486 return !!(sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT); in sdhci_get_cd()
2489 static int sdhci_check_ro(struct sdhci_host *host) in sdhci_check_ro() argument
2494 spin_lock_irqsave(&host->lock, flags); in sdhci_check_ro()
2496 if (host->flags & SDHCI_DEVICE_DEAD) in sdhci_check_ro()
2498 else if (host->ops->get_ro) in sdhci_check_ro()
2499 is_readonly = host->ops->get_ro(host); in sdhci_check_ro()
2500 else if (mmc_can_gpio_ro(host->mmc)) in sdhci_check_ro()
2501 is_readonly = mmc_gpio_get_ro(host->mmc); in sdhci_check_ro()
2503 is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE) in sdhci_check_ro()
2506 spin_unlock_irqrestore(&host->lock, flags); in sdhci_check_ro()
2509 return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ? in sdhci_check_ro()
2517 struct sdhci_host *host = mmc_priv(mmc); in sdhci_get_ro() local
2520 if (!(host->quirks & SDHCI_QUIRK_UNSTABLE_RO_DETECT)) in sdhci_get_ro()
2521 return sdhci_check_ro(host); in sdhci_get_ro()
2525 if (sdhci_check_ro(host)) { in sdhci_get_ro()
2536 struct sdhci_host *host = mmc_priv(mmc); in sdhci_hw_reset() local
2538 if (host->ops && host->ops->hw_reset) in sdhci_hw_reset()
2539 host->ops->hw_reset(host); in sdhci_hw_reset()
2542 static void sdhci_enable_sdio_irq_nolock(struct sdhci_host *host, int enable) in sdhci_enable_sdio_irq_nolock() argument
2544 if (!(host->flags & SDHCI_DEVICE_DEAD)) { in sdhci_enable_sdio_irq_nolock()
2546 host->ier |= SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2548 host->ier &= ~SDHCI_INT_CARD_INT; in sdhci_enable_sdio_irq_nolock()
2550 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_enable_sdio_irq_nolock()
2551 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_enable_sdio_irq_nolock()
2557 struct sdhci_host *host = mmc_priv(mmc); in sdhci_enable_sdio_irq() local
2561 pm_runtime_get_noresume(host->mmc->parent); in sdhci_enable_sdio_irq()
2563 spin_lock_irqsave(&host->lock, flags); in sdhci_enable_sdio_irq()
2564 sdhci_enable_sdio_irq_nolock(host, enable); in sdhci_enable_sdio_irq()
2565 spin_unlock_irqrestore(&host->lock, flags); in sdhci_enable_sdio_irq()
2568 pm_runtime_put_noidle(host->mmc->parent); in sdhci_enable_sdio_irq()
2574 struct sdhci_host *host = mmc_priv(mmc); in sdhci_ack_sdio_irq() local
2577 spin_lock_irqsave(&host->lock, flags); in sdhci_ack_sdio_irq()
2578 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_ack_sdio_irq()
2579 spin_unlock_irqrestore(&host->lock, flags); in sdhci_ack_sdio_irq()
2585 struct sdhci_host *host = mmc_priv(mmc); in sdhci_start_signal_voltage_switch() local
2593 if (host->version < SDHCI_SPEC_300) in sdhci_start_signal_voltage_switch()
2596 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2600 if (!(host->flags & SDHCI_SIGNALING_330)) in sdhci_start_signal_voltage_switch()
2604 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2618 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2627 if (!(host->flags & SDHCI_SIGNALING_180)) in sdhci_start_signal_voltage_switch()
2643 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2646 if (host->ops->voltage_switch) in sdhci_start_signal_voltage_switch()
2647 host->ops->voltage_switch(host); in sdhci_start_signal_voltage_switch()
2650 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_signal_voltage_switch()
2659 if (!(host->flags & SDHCI_SIGNALING_120)) in sdhci_start_signal_voltage_switch()
2679 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_busy() local
2683 present_state = sdhci_readl(host, SDHCI_PRESENT_STATE); in sdhci_card_busy()
2690 struct sdhci_host *host = mmc_priv(mmc); in sdhci_prepare_hs400_tuning() local
2693 spin_lock_irqsave(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2694 host->flags |= SDHCI_HS400_TUNING; in sdhci_prepare_hs400_tuning()
2695 spin_unlock_irqrestore(&host->lock, flags); in sdhci_prepare_hs400_tuning()
2700 void sdhci_start_tuning(struct sdhci_host *host) in sdhci_start_tuning() argument
2704 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2706 if (host->quirks2 & SDHCI_QUIRK2_TUNING_WORK_AROUND) in sdhci_start_tuning()
2708 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_start_tuning()
2720 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); in sdhci_start_tuning()
2721 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); in sdhci_start_tuning()
2725 void sdhci_end_tuning(struct sdhci_host *host) in sdhci_end_tuning() argument
2727 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_end_tuning()
2728 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_end_tuning()
2732 void sdhci_reset_tuning(struct sdhci_host *host) in sdhci_reset_tuning() argument
2736 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2739 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_reset_tuning()
2743 void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode) in sdhci_abort_tuning() argument
2745 sdhci_reset_tuning(host); in sdhci_abort_tuning()
2747 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_abort_tuning()
2748 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_abort_tuning()
2750 sdhci_end_tuning(host); in sdhci_abort_tuning()
2752 mmc_abort_tuning(host->mmc, opcode); in sdhci_abort_tuning()
2763 void sdhci_send_tuning(struct sdhci_host *host, u32 opcode) in sdhci_send_tuning() argument
2765 struct mmc_host *mmc = host->mmc; in sdhci_send_tuning()
2769 u32 b = host->sdma_boundary; in sdhci_send_tuning()
2771 spin_lock_irqsave(&host->lock, flags); in sdhci_send_tuning()
2785 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 128), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2787 sdhci_writew(host, SDHCI_MAKE_BLKSZ(b, 64), SDHCI_BLOCK_SIZE); in sdhci_send_tuning()
2795 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); in sdhci_send_tuning()
2797 if (!sdhci_send_command_retry(host, &cmd, flags)) { in sdhci_send_tuning()
2798 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2799 host->tuning_done = 0; in sdhci_send_tuning()
2803 host->cmd = NULL; in sdhci_send_tuning()
2805 sdhci_del_timer(host, &mrq); in sdhci_send_tuning()
2807 host->tuning_done = 0; in sdhci_send_tuning()
2809 spin_unlock_irqrestore(&host->lock, flags); in sdhci_send_tuning()
2812 wait_event_timeout(host->buf_ready_int, (host->tuning_done == 1), in sdhci_send_tuning()
2818 static int __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode) in __sdhci_execute_tuning() argument
2826 for (i = 0; i < host->tuning_loop_count; i++) { in __sdhci_execute_tuning()
2829 sdhci_send_tuning(host, opcode); in __sdhci_execute_tuning()
2831 if (!host->tuning_done) { in __sdhci_execute_tuning()
2833 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2834 sdhci_abort_tuning(host, opcode); in __sdhci_execute_tuning()
2839 if (host->tuning_delay > 0) in __sdhci_execute_tuning()
2840 mdelay(host->tuning_delay); in __sdhci_execute_tuning()
2842 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in __sdhci_execute_tuning()
2852 mmc_hostname(host->mmc)); in __sdhci_execute_tuning()
2853 sdhci_reset_tuning(host); in __sdhci_execute_tuning()
2859 struct sdhci_host *host = mmc_priv(mmc); in sdhci_execute_tuning() local
2864 hs400_tuning = host->flags & SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2866 if (host->tuning_mode == SDHCI_TUNING_MODE_1) in sdhci_execute_tuning()
2867 tuning_count = host->tuning_count; in sdhci_execute_tuning()
2876 switch (host->timing) { in sdhci_execute_tuning()
2896 if (host->flags & SDHCI_SDR50_NEEDS_TUNING) in sdhci_execute_tuning()
2904 if (host->ops->platform_execute_tuning) { in sdhci_execute_tuning()
2905 err = host->ops->platform_execute_tuning(host, opcode); in sdhci_execute_tuning()
2909 host->mmc->retune_period = tuning_count; in sdhci_execute_tuning()
2911 if (host->tuning_delay < 0) in sdhci_execute_tuning()
2912 host->tuning_delay = opcode == MMC_SEND_TUNING_BLOCK; in sdhci_execute_tuning()
2914 sdhci_start_tuning(host); in sdhci_execute_tuning()
2916 host->tuning_err = __sdhci_execute_tuning(host, opcode); in sdhci_execute_tuning()
2918 sdhci_end_tuning(host); in sdhci_execute_tuning()
2920 host->flags &= ~SDHCI_HS400_TUNING; in sdhci_execute_tuning()
2926 static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) in sdhci_enable_preset_value() argument
2929 if (host->version < SDHCI_SPEC_300) in sdhci_enable_preset_value()
2936 if (host->preset_enabled != enable) { in sdhci_enable_preset_value()
2937 u16 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2944 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); in sdhci_enable_preset_value()
2947 host->flags |= SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2949 host->flags &= ~SDHCI_PV_ENABLED; in sdhci_enable_preset_value()
2951 host->preset_enabled = enable; in sdhci_enable_preset_value()
2958 struct sdhci_host *host = mmc_priv(mmc); in sdhci_post_req() local
2962 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, in sdhci_post_req()
2970 struct sdhci_host *host = mmc_priv(mmc); in sdhci_pre_req() local
2979 if (host->flags & SDHCI_REQ_USE_DMA && !host->bounce_buffer) in sdhci_pre_req()
2980 sdhci_pre_dma_transfer(host, mrq->data, COOKIE_PRE_MAPPED); in sdhci_pre_req()
2983 static void sdhci_error_out_mrqs(struct sdhci_host *host, int err) in sdhci_error_out_mrqs() argument
2985 if (host->data_cmd) { in sdhci_error_out_mrqs()
2986 host->data_cmd->error = err; in sdhci_error_out_mrqs()
2987 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_error_out_mrqs()
2990 if (host->cmd) { in sdhci_error_out_mrqs()
2991 host->cmd->error = err; in sdhci_error_out_mrqs()
2992 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_error_out_mrqs()
2998 struct sdhci_host *host = mmc_priv(mmc); in sdhci_card_event() local
3003 if (host->ops->card_event) in sdhci_card_event()
3004 host->ops->card_event(host); in sdhci_card_event()
3008 spin_lock_irqsave(&host->lock, flags); in sdhci_card_event()
3011 if (sdhci_has_requests(host) && !present) { in sdhci_card_event()
3013 mmc_hostname(host->mmc)); in sdhci_card_event()
3015 mmc_hostname(host->mmc)); in sdhci_card_event()
3017 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_card_event()
3018 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_card_event()
3020 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_card_event()
3023 spin_unlock_irqrestore(&host->lock, flags); in sdhci_card_event()
3049 static bool sdhci_request_done(struct sdhci_host *host) in sdhci_request_done() argument
3055 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3058 mrq = host->mrqs_done[i]; in sdhci_request_done()
3064 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3072 if (sdhci_needs_reset(host, mrq)) { in sdhci_request_done()
3079 if (host->cmd || host->data_cmd) { in sdhci_request_done()
3080 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3085 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) in sdhci_request_done()
3087 host->ops->set_clock(host, host->clock); in sdhci_request_done()
3093 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_request_done()
3094 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_request_done()
3096 host->pending_reset = false; in sdhci_request_done()
3104 if (host->flags & SDHCI_REQ_USE_DMA) { in sdhci_request_done()
3107 if (host->use_external_dma && data && in sdhci_request_done()
3109 struct dma_chan *chan = sdhci_external_dma_channel(host, data); in sdhci_request_done()
3111 host->mrqs_done[i] = NULL; in sdhci_request_done()
3112 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3114 spin_lock_irqsave(&host->lock, flags); in sdhci_request_done()
3115 sdhci_set_mrq_done(host, mrq); in sdhci_request_done()
3119 if (host->bounce_buffer) { in sdhci_request_done()
3127 if (length > host->bounce_buffer_size) { in sdhci_request_done()
3129 mmc_hostname(host->mmc), in sdhci_request_done()
3130 host->bounce_buffer_size, in sdhci_request_done()
3133 length = host->bounce_buffer_size; in sdhci_request_done()
3136 host->mmc->parent, in sdhci_request_done()
3137 host->bounce_addr, in sdhci_request_done()
3138 host->bounce_buffer_size, in sdhci_request_done()
3142 host->bounce_buffer, in sdhci_request_done()
3147 host->mmc->parent, in sdhci_request_done()
3148 host->bounce_addr, in sdhci_request_done()
3149 host->bounce_buffer_size, in sdhci_request_done()
3154 dma_unmap_sg(mmc_dev(host->mmc), data->sg, in sdhci_request_done()
3162 host->mrqs_done[i] = NULL; in sdhci_request_done()
3164 spin_unlock_irqrestore(&host->lock, flags); in sdhci_request_done()
3166 if (host->ops->request_done) in sdhci_request_done()
3167 host->ops->request_done(host, mrq); in sdhci_request_done()
3169 mmc_request_done(host->mmc, mrq); in sdhci_request_done()
3176 struct sdhci_host *host = container_of(work, struct sdhci_host, in sdhci_complete_work() local
3179 while (!sdhci_request_done(host)) in sdhci_complete_work()
3185 struct sdhci_host *host; in sdhci_timeout_timer() local
3188 host = from_timer(host, t, timer); in sdhci_timeout_timer()
3190 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_timer()
3192 if (host->cmd && !sdhci_data_line_cmd(host->cmd)) { in sdhci_timeout_timer()
3194 mmc_hostname(host->mmc)); in sdhci_timeout_timer()
3195 sdhci_dumpregs(host); in sdhci_timeout_timer()
3197 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_timer()
3198 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_timer()
3201 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_timer()
3206 struct sdhci_host *host; in sdhci_timeout_data_timer() local
3209 host = from_timer(host, t, data_timer); in sdhci_timeout_data_timer()
3211 spin_lock_irqsave(&host->lock, flags); in sdhci_timeout_data_timer()
3213 if (host->data || host->data_cmd || in sdhci_timeout_data_timer()
3214 (host->cmd && sdhci_data_line_cmd(host->cmd))) { in sdhci_timeout_data_timer()
3216 mmc_hostname(host->mmc)); in sdhci_timeout_data_timer()
3217 sdhci_dumpregs(host); in sdhci_timeout_data_timer()
3219 if (host->data) { in sdhci_timeout_data_timer()
3220 host->data->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3221 __sdhci_finish_data(host, true); in sdhci_timeout_data_timer()
3222 queue_work(host->complete_wq, &host->complete_work); in sdhci_timeout_data_timer()
3223 } else if (host->data_cmd) { in sdhci_timeout_data_timer()
3224 host->data_cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3225 sdhci_finish_mrq(host, host->data_cmd->mrq); in sdhci_timeout_data_timer()
3227 host->cmd->error = -ETIMEDOUT; in sdhci_timeout_data_timer()
3228 sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_timeout_data_timer()
3232 spin_unlock_irqrestore(&host->lock, flags); in sdhci_timeout_data_timer()
3241 static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *intmask_p) in sdhci_cmd_irq() argument
3244 if (intmask & SDHCI_INT_AUTO_CMD_ERR && host->data_cmd) { in sdhci_cmd_irq()
3245 struct mmc_request *mrq = host->data_cmd->mrq; in sdhci_cmd_irq()
3246 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3252 if (!mrq->sbc && (host->flags & SDHCI_AUTO_CMD12)) { in sdhci_cmd_irq()
3258 if (!host->cmd) { in sdhci_cmd_irq()
3264 if (host->pending_reset) in sdhci_cmd_irq()
3267 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_cmd_irq()
3268 sdhci_dumpregs(host); in sdhci_cmd_irq()
3275 host->cmd->error = -ETIMEDOUT; in sdhci_cmd_irq()
3277 host->cmd->error = -EILSEQ; in sdhci_cmd_irq()
3280 if (host->cmd->data && in sdhci_cmd_irq()
3283 host->cmd = NULL; in sdhci_cmd_irq()
3288 __sdhci_finish_mrq(host, host->cmd->mrq); in sdhci_cmd_irq()
3294 struct mmc_request *mrq = host->cmd->mrq; in sdhci_cmd_irq()
3295 u16 auto_cmd_status = sdhci_readw(host, SDHCI_AUTO_CMD_STATUS); in sdhci_cmd_irq()
3300 if (mrq->sbc && (host->flags & SDHCI_AUTO_CMD23)) { in sdhci_cmd_irq()
3302 __sdhci_finish_mrq(host, mrq); in sdhci_cmd_irq()
3308 sdhci_finish_command(host); in sdhci_cmd_irq()
3311 static void sdhci_adma_show_error(struct sdhci_host *host) in sdhci_adma_show_error() argument
3313 void *desc = host->adma_table; in sdhci_adma_show_error()
3314 dma_addr_t dma = host->adma_addr; in sdhci_adma_show_error()
3316 sdhci_dumpregs(host); in sdhci_adma_show_error()
3321 if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_adma_show_error()
3335 desc += host->desc_sz; in sdhci_adma_show_error()
3336 dma += host->desc_sz; in sdhci_adma_show_error()
3343 static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) in sdhci_data_irq() argument
3349 command = SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)); in sdhci_data_irq()
3352 host->tuning_done = 1; in sdhci_data_irq()
3353 wake_up(&host->buf_ready_int); in sdhci_data_irq()
3358 if (!host->data) { in sdhci_data_irq()
3359 struct mmc_command *data_cmd = host->data_cmd; in sdhci_data_irq()
3368 host->data_cmd = NULL; in sdhci_data_irq()
3370 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3374 host->data_cmd = NULL; in sdhci_data_irq()
3380 if (host->cmd == data_cmd) in sdhci_data_irq()
3383 __sdhci_finish_mrq(host, data_cmd->mrq); in sdhci_data_irq()
3393 if (host->pending_reset) in sdhci_data_irq()
3397 mmc_hostname(host->mmc), (unsigned)intmask); in sdhci_data_irq()
3398 sdhci_dumpregs(host); in sdhci_data_irq()
3404 host->data->error = -ETIMEDOUT; in sdhci_data_irq()
3406 host->data->error = -EILSEQ; in sdhci_data_irq()
3408 SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND)) in sdhci_data_irq()
3410 host->data->error = -EILSEQ; in sdhci_data_irq()
3412 pr_err("%s: ADMA error: 0x%08x\n", mmc_hostname(host->mmc), in sdhci_data_irq()
3414 sdhci_adma_show_error(host); in sdhci_data_irq()
3415 host->data->error = -EIO; in sdhci_data_irq()
3416 if (host->ops->adma_workaround) in sdhci_data_irq()
3417 host->ops->adma_workaround(host, intmask); in sdhci_data_irq()
3420 if (host->data->error) in sdhci_data_irq()
3421 sdhci_finish_data(host); in sdhci_data_irq()
3424 sdhci_transfer_pio(host); in sdhci_data_irq()
3438 dmastart = sdhci_sdma_address(host); in sdhci_data_irq()
3439 dmanow = dmastart + host->data->bytes_xfered; in sdhci_data_irq()
3446 host->data->bytes_xfered = dmanow - dmastart; in sdhci_data_irq()
3448 &dmastart, host->data->bytes_xfered, &dmanow); in sdhci_data_irq()
3449 sdhci_set_sdma_addr(host, dmanow); in sdhci_data_irq()
3453 if (host->cmd == host->data_cmd) { in sdhci_data_irq()
3459 host->data_early = 1; in sdhci_data_irq()
3461 sdhci_finish_data(host); in sdhci_data_irq()
3467 static inline bool sdhci_defer_done(struct sdhci_host *host, in sdhci_defer_done() argument
3472 return host->pending_reset || host->always_defer_done || in sdhci_defer_done()
3473 ((host->flags & SDHCI_REQ_USE_DMA) && data && in sdhci_defer_done()
3481 struct sdhci_host *host = dev_id; in sdhci_irq() local
3486 spin_lock(&host->lock); in sdhci_irq()
3488 if (host->runtime_suspended) { in sdhci_irq()
3489 spin_unlock(&host->lock); in sdhci_irq()
3493 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3502 if (host->ops->irq) { in sdhci_irq()
3503 intmask = host->ops->irq(host, intmask); in sdhci_irq()
3511 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_irq()
3514 u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & in sdhci_irq()
3528 host->ier &= ~(SDHCI_INT_CARD_INSERT | in sdhci_irq()
3530 host->ier |= present ? SDHCI_INT_CARD_REMOVE : in sdhci_irq()
3532 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_irq()
3533 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_irq()
3535 sdhci_writel(host, intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3538 host->thread_isr |= intmask & (SDHCI_INT_CARD_INSERT | in sdhci_irq()
3544 sdhci_cmd_irq(host, intmask & SDHCI_INT_CMD_MASK, &intmask); in sdhci_irq()
3547 sdhci_data_irq(host, intmask & SDHCI_INT_DATA_MASK); in sdhci_irq()
3551 mmc_hostname(host->mmc)); in sdhci_irq()
3554 mmc_retune_needed(host->mmc); in sdhci_irq()
3557 (host->ier & SDHCI_INT_CARD_INT)) { in sdhci_irq()
3558 sdhci_enable_sdio_irq_nolock(host, false); in sdhci_irq()
3559 sdio_signal_irq(host->mmc); in sdhci_irq()
3569 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_irq()
3575 intmask = sdhci_readl(host, SDHCI_INT_STATUS); in sdhci_irq()
3580 struct mmc_request *mrq = host->mrqs_done[i]; in sdhci_irq()
3585 if (sdhci_defer_done(host, mrq)) { in sdhci_irq()
3589 host->mrqs_done[i] = NULL; in sdhci_irq()
3593 if (host->deferred_cmd) in sdhci_irq()
3596 spin_unlock(&host->lock); in sdhci_irq()
3603 if (host->ops->request_done) in sdhci_irq()
3604 host->ops->request_done(host, mrqs_done[i]); in sdhci_irq()
3606 mmc_request_done(host->mmc, mrqs_done[i]); in sdhci_irq()
3611 mmc_hostname(host->mmc), unexpected); in sdhci_irq()
3612 sdhci_dumpregs(host); in sdhci_irq()
3620 struct sdhci_host *host = dev_id; in sdhci_thread_irq() local
3625 while (!sdhci_request_done(host)) in sdhci_thread_irq()
3628 spin_lock_irqsave(&host->lock, flags); in sdhci_thread_irq()
3630 isr = host->thread_isr; in sdhci_thread_irq()
3631 host->thread_isr = 0; in sdhci_thread_irq()
3633 cmd = host->deferred_cmd; in sdhci_thread_irq()
3634 if (cmd && !sdhci_send_command_retry(host, cmd, flags)) in sdhci_thread_irq()
3635 sdhci_finish_mrq(host, cmd->mrq); in sdhci_thread_irq()
3637 spin_unlock_irqrestore(&host->lock, flags); in sdhci_thread_irq()
3640 struct mmc_host *mmc = host->mmc; in sdhci_thread_irq()
3657 static bool sdhci_cd_irq_can_wakeup(struct sdhci_host *host) in sdhci_cd_irq_can_wakeup() argument
3659 return mmc_card_is_removable(host->mmc) && in sdhci_cd_irq_can_wakeup()
3660 !(host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_cd_irq_can_wakeup()
3661 !mmc_can_gpio_cd(host->mmc); in sdhci_cd_irq_can_wakeup()
3672 static bool sdhci_enable_irq_wakeups(struct sdhci_host *host) in sdhci_enable_irq_wakeups() argument
3680 if (sdhci_cd_irq_can_wakeup(host)) { in sdhci_enable_irq_wakeups()
3685 if (mmc_card_wake_sdio_irq(host->mmc)) { in sdhci_enable_irq_wakeups()
3693 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3696 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_enable_irq_wakeups()
3698 sdhci_writel(host, irq_val, SDHCI_INT_ENABLE); in sdhci_enable_irq_wakeups()
3700 host->irq_wake_enabled = !enable_irq_wake(host->irq); in sdhci_enable_irq_wakeups()
3702 return host->irq_wake_enabled; in sdhci_enable_irq_wakeups()
3705 static void sdhci_disable_irq_wakeups(struct sdhci_host *host) in sdhci_disable_irq_wakeups() argument
3711 val = sdhci_readb(host, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3713 sdhci_writeb(host, val, SDHCI_WAKE_UP_CONTROL); in sdhci_disable_irq_wakeups()
3715 disable_irq_wake(host->irq); in sdhci_disable_irq_wakeups()
3717 host->irq_wake_enabled = false; in sdhci_disable_irq_wakeups()
3720 int sdhci_suspend_host(struct sdhci_host *host) in sdhci_suspend_host() argument
3722 sdhci_disable_card_detection(host); in sdhci_suspend_host()
3724 mmc_retune_timer_stop(host->mmc); in sdhci_suspend_host()
3726 if (!device_may_wakeup(mmc_dev(host->mmc)) || in sdhci_suspend_host()
3727 !sdhci_enable_irq_wakeups(host)) { in sdhci_suspend_host()
3728 host->ier = 0; in sdhci_suspend_host()
3729 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_suspend_host()
3730 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_suspend_host()
3731 free_irq(host->irq, host); in sdhci_suspend_host()
3739 int sdhci_resume_host(struct sdhci_host *host) in sdhci_resume_host() argument
3741 struct mmc_host *mmc = host->mmc; in sdhci_resume_host()
3744 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_resume_host()
3745 if (host->ops->enable_dma) in sdhci_resume_host()
3746 host->ops->enable_dma(host); in sdhci_resume_host()
3749 if ((host->mmc->pm_flags & MMC_PM_KEEP_POWER) && in sdhci_resume_host()
3750 (host->quirks2 & SDHCI_QUIRK2_HOST_OFF_CARD_ON)) { in sdhci_resume_host()
3752 sdhci_init(host, 0); in sdhci_resume_host()
3753 host->pwr = 0; in sdhci_resume_host()
3754 host->clock = 0; in sdhci_resume_host()
3755 host->reinit_uhs = true; in sdhci_resume_host()
3758 sdhci_init(host, (host->mmc->pm_flags & MMC_PM_KEEP_POWER)); in sdhci_resume_host()
3761 if (host->irq_wake_enabled) { in sdhci_resume_host()
3762 sdhci_disable_irq_wakeups(host); in sdhci_resume_host()
3764 ret = request_threaded_irq(host->irq, sdhci_irq, in sdhci_resume_host()
3766 mmc_hostname(host->mmc), host); in sdhci_resume_host()
3771 sdhci_enable_card_detection(host); in sdhci_resume_host()
3778 int sdhci_runtime_suspend_host(struct sdhci_host *host) in sdhci_runtime_suspend_host() argument
3782 mmc_retune_timer_stop(host->mmc); in sdhci_runtime_suspend_host()
3784 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3785 host->ier &= SDHCI_INT_CARD_INT; in sdhci_runtime_suspend_host()
3786 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_runtime_suspend_host()
3787 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_runtime_suspend_host()
3788 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3790 synchronize_hardirq(host->irq); in sdhci_runtime_suspend_host()
3792 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_suspend_host()
3793 host->runtime_suspended = true; in sdhci_runtime_suspend_host()
3794 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_suspend_host()
3800 int sdhci_runtime_resume_host(struct sdhci_host *host, int soft_reset) in sdhci_runtime_resume_host() argument
3802 struct mmc_host *mmc = host->mmc; in sdhci_runtime_resume_host()
3804 int host_flags = host->flags; in sdhci_runtime_resume_host()
3807 if (host->ops->enable_dma) in sdhci_runtime_resume_host()
3808 host->ops->enable_dma(host); in sdhci_runtime_resume_host()
3811 sdhci_init(host, soft_reset); in sdhci_runtime_resume_host()
3816 host->pwr = 0; in sdhci_runtime_resume_host()
3817 host->clock = 0; in sdhci_runtime_resume_host()
3818 host->reinit_uhs = true; in sdhci_runtime_resume_host()
3823 !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) { in sdhci_runtime_resume_host()
3824 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3825 sdhci_enable_preset_value(host, true); in sdhci_runtime_resume_host()
3826 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3834 spin_lock_irqsave(&host->lock, flags); in sdhci_runtime_resume_host()
3836 host->runtime_suspended = false; in sdhci_runtime_resume_host()
3840 sdhci_enable_sdio_irq_nolock(host, true); in sdhci_runtime_resume_host()
3843 sdhci_enable_card_detection(host); in sdhci_runtime_resume_host()
3845 spin_unlock_irqrestore(&host->lock, flags); in sdhci_runtime_resume_host()
3861 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_enable() local
3865 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_enable()
3867 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3874 if (host->v4_mode && (host->caps1 & SDHCI_CAN_DO_ADMA3)) in sdhci_cqe_enable()
3876 else if (host->flags & SDHCI_USE_64_BIT_DMA) in sdhci_cqe_enable()
3880 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); in sdhci_cqe_enable()
3882 sdhci_writew(host, SDHCI_MAKE_BLKSZ(host->sdma_boundary, 512), in sdhci_cqe_enable()
3886 sdhci_set_timeout(host, NULL); in sdhci_cqe_enable()
3888 host->ier = host->cqe_ier; in sdhci_cqe_enable()
3890 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_cqe_enable()
3891 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_cqe_enable()
3893 host->cqe_on = true; in sdhci_cqe_enable()
3896 mmc_hostname(mmc), host->ier, in sdhci_cqe_enable()
3897 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_enable()
3899 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_enable()
3905 struct sdhci_host *host = mmc_priv(mmc); in sdhci_cqe_disable() local
3908 spin_lock_irqsave(&host->lock, flags); in sdhci_cqe_disable()
3910 sdhci_set_default_irqs(host); in sdhci_cqe_disable()
3912 host->cqe_on = false; in sdhci_cqe_disable()
3915 sdhci_do_reset(host, SDHCI_RESET_CMD); in sdhci_cqe_disable()
3916 sdhci_do_reset(host, SDHCI_RESET_DATA); in sdhci_cqe_disable()
3920 mmc_hostname(mmc), host->ier, in sdhci_cqe_disable()
3921 sdhci_readl(host, SDHCI_INT_STATUS)); in sdhci_cqe_disable()
3923 spin_unlock_irqrestore(&host->lock, flags); in sdhci_cqe_disable()
3927 bool sdhci_cqe_irq(struct sdhci_host *host, u32 intmask, int *cmd_error, in sdhci_cqe_irq() argument
3932 if (!host->cqe_on) in sdhci_cqe_irq()
3952 mask = intmask & host->cqe_ier; in sdhci_cqe_irq()
3953 sdhci_writel(host, mask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
3957 mmc_hostname(host->mmc)); in sdhci_cqe_irq()
3959 intmask &= ~(host->cqe_ier | SDHCI_INT_ERROR); in sdhci_cqe_irq()
3961 sdhci_writel(host, intmask, SDHCI_INT_STATUS); in sdhci_cqe_irq()
3963 mmc_hostname(host->mmc), intmask); in sdhci_cqe_irq()
3964 sdhci_dumpregs(host); in sdhci_cqe_irq()
3981 struct sdhci_host *host; in sdhci_alloc_host() local
3989 host = mmc_priv(mmc); in sdhci_alloc_host()
3990 host->mmc = mmc; in sdhci_alloc_host()
3991 host->mmc_host_ops = sdhci_ops; in sdhci_alloc_host()
3992 mmc->ops = &host->mmc_host_ops; in sdhci_alloc_host()
3994 host->flags = SDHCI_SIGNALING_330; in sdhci_alloc_host()
3996 host->cqe_ier = SDHCI_CQE_INT_MASK; in sdhci_alloc_host()
3997 host->cqe_err_ier = SDHCI_CQE_INT_ERR_MASK; in sdhci_alloc_host()
3999 host->tuning_delay = -1; in sdhci_alloc_host()
4000 host->tuning_loop_count = MAX_TUNING_LOOP; in sdhci_alloc_host()
4002 host->sdma_boundary = SDHCI_DEFAULT_BOUNDARY_ARG; in sdhci_alloc_host()
4009 host->adma_table_cnt = SDHCI_MAX_SEGS * 2 + 1; in sdhci_alloc_host()
4010 host->max_adma = 65536; in sdhci_alloc_host()
4012 return host; in sdhci_alloc_host()
4017 static int sdhci_set_dma_mask(struct sdhci_host *host) in sdhci_set_dma_mask() argument
4019 struct mmc_host *mmc = host->mmc; in sdhci_set_dma_mask()
4023 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) in sdhci_set_dma_mask()
4024 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4027 if (host->flags & SDHCI_USE_64_BIT_DMA) { in sdhci_set_dma_mask()
4032 host->flags &= ~SDHCI_USE_64_BIT_DMA; in sdhci_set_dma_mask()
4047 void __sdhci_read_caps(struct sdhci_host *host, const u16 *ver, in __sdhci_read_caps() argument
4054 if (host->read_caps) in __sdhci_read_caps()
4057 host->read_caps = true; in __sdhci_read_caps()
4060 host->quirks = debug_quirks; in __sdhci_read_caps()
4063 host->quirks2 = debug_quirks2; in __sdhci_read_caps()
4065 sdhci_do_reset(host, SDHCI_RESET_ALL); in __sdhci_read_caps()
4067 if (host->v4_mode) in __sdhci_read_caps()
4068 sdhci_do_enable_v4_mode(host); in __sdhci_read_caps()
4070 device_property_read_u64_array(mmc_dev(host->mmc), in __sdhci_read_caps()
4072 device_property_read_u64_array(mmc_dev(host->mmc), in __sdhci_read_caps()
4075 v = ver ? *ver : sdhci_readw(host, SDHCI_HOST_VERSION); in __sdhci_read_caps()
4076 host->version = (v & SDHCI_SPEC_VER_MASK) >> SDHCI_SPEC_VER_SHIFT; in __sdhci_read_caps()
4078 if (host->quirks & SDHCI_QUIRK_MISSING_CAPS) in __sdhci_read_caps()
4082 host->caps = *caps; in __sdhci_read_caps()
4084 host->caps = sdhci_readl(host, SDHCI_CAPABILITIES); in __sdhci_read_caps()
4085 host->caps &= ~lower_32_bits(dt_caps_mask); in __sdhci_read_caps()
4086 host->caps |= lower_32_bits(dt_caps); in __sdhci_read_caps()
4089 if (host->version < SDHCI_SPEC_300) in __sdhci_read_caps()
4093 host->caps1 = *caps1; in __sdhci_read_caps()
4095 host->caps1 = sdhci_readl(host, SDHCI_CAPABILITIES_1); in __sdhci_read_caps()
4096 host->caps1 &= ~upper_32_bits(dt_caps_mask); in __sdhci_read_caps()
4097 host->caps1 |= upper_32_bits(dt_caps); in __sdhci_read_caps()
4102 static void sdhci_allocate_bounce_buffer(struct sdhci_host *host) in sdhci_allocate_bounce_buffer() argument
4104 struct mmc_host *mmc = host->mmc; in sdhci_allocate_bounce_buffer()
4129 host->bounce_buffer = devm_kmalloc(mmc->parent, in sdhci_allocate_bounce_buffer()
4132 if (!host->bounce_buffer) { in sdhci_allocate_bounce_buffer()
4143 host->bounce_addr = dma_map_single(mmc->parent, in sdhci_allocate_bounce_buffer()
4144 host->bounce_buffer, in sdhci_allocate_bounce_buffer()
4147 ret = dma_mapping_error(mmc->parent, host->bounce_addr); in sdhci_allocate_bounce_buffer()
4151 host->bounce_buffer_size = bounce_size; in sdhci_allocate_bounce_buffer()
4162 static inline bool sdhci_can_64bit_dma(struct sdhci_host *host) in sdhci_can_64bit_dma() argument
4169 if (host->version >= SDHCI_SPEC_410 && host->v4_mode) in sdhci_can_64bit_dma()
4170 return host->caps & SDHCI_CAN_64BIT_V4; in sdhci_can_64bit_dma()
4172 return host->caps & SDHCI_CAN_64BIT; in sdhci_can_64bit_dma()
4175 int sdhci_setup_host(struct sdhci_host *host) in sdhci_setup_host() argument
4185 WARN_ON(host == NULL); in sdhci_setup_host()
4186 if (host == NULL) in sdhci_setup_host()
4189 mmc = host->mmc; in sdhci_setup_host()
4205 sdhci_readw(host, SDHCI_HOST_VERSION), in sdhci_setup_host()
4206 sdhci_readl(host, SDHCI_PRESENT_STATE)); in sdhci_setup_host()
4208 sdhci_readl(host, SDHCI_CAPABILITIES), in sdhci_setup_host()
4209 sdhci_readl(host, SDHCI_CAPABILITIES_1)); in sdhci_setup_host()
4211 sdhci_read_caps(host); in sdhci_setup_host()
4213 override_timeout_clk = host->timeout_clk; in sdhci_setup_host()
4215 if (host->version > SDHCI_SPEC_420) { in sdhci_setup_host()
4217 mmc_hostname(mmc), host->version); in sdhci_setup_host()
4220 if (host->quirks & SDHCI_QUIRK_FORCE_DMA) in sdhci_setup_host()
4221 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4222 else if (!(host->caps & SDHCI_CAN_DO_SDMA)) in sdhci_setup_host()
4225 host->flags |= SDHCI_USE_SDMA; in sdhci_setup_host()
4227 if ((host->quirks & SDHCI_QUIRK_BROKEN_DMA) && in sdhci_setup_host()
4228 (host->flags & SDHCI_USE_SDMA)) { in sdhci_setup_host()
4230 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4233 if ((host->version >= SDHCI_SPEC_200) && in sdhci_setup_host()
4234 (host->caps & SDHCI_CAN_DO_ADMA2)) in sdhci_setup_host()
4235 host->flags |= SDHCI_USE_ADMA; in sdhci_setup_host()
4237 if ((host->quirks & SDHCI_QUIRK_BROKEN_ADMA) && in sdhci_setup_host()
4238 (host->flags & SDHCI_USE_ADMA)) { in sdhci_setup_host()
4240 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4243 if (sdhci_can_64bit_dma(host)) in sdhci_setup_host()
4244 host->flags |= SDHCI_USE_64_BIT_DMA; in sdhci_setup_host()
4246 if (host->use_external_dma) { in sdhci_setup_host()
4247 ret = sdhci_external_dma_init(host); in sdhci_setup_host()
4255 sdhci_switch_external_dma(host, false); in sdhci_setup_host()
4258 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4261 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { in sdhci_setup_host()
4262 if (host->ops->set_dma_mask) in sdhci_setup_host()
4263 ret = host->ops->set_dma_mask(host); in sdhci_setup_host()
4265 ret = sdhci_set_dma_mask(host); in sdhci_setup_host()
4267 if (!ret && host->ops->enable_dma) in sdhci_setup_host()
4268 ret = host->ops->enable_dma(host); in sdhci_setup_host()
4273 host->flags &= ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA); in sdhci_setup_host()
4280 if ((host->flags & SDHCI_USE_64_BIT_DMA) && !host->v4_mode) in sdhci_setup_host()
4281 host->flags &= ~SDHCI_USE_SDMA; in sdhci_setup_host()
4283 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4287 if (!(host->flags & SDHCI_USE_64_BIT_DMA)) in sdhci_setup_host()
4288 host->alloc_desc_sz = SDHCI_ADMA2_32_DESC_SZ; in sdhci_setup_host()
4289 else if (!host->alloc_desc_sz) in sdhci_setup_host()
4290 host->alloc_desc_sz = SDHCI_ADMA2_64_DESC_SZ(host); in sdhci_setup_host()
4292 host->desc_sz = host->alloc_desc_sz; in sdhci_setup_host()
4293 host->adma_table_sz = host->adma_table_cnt * host->desc_sz; in sdhci_setup_host()
4295 host->align_buffer_sz = SDHCI_MAX_SEGS * SDHCI_ADMA2_ALIGN; in sdhci_setup_host()
4301 host->align_buffer_sz + host->adma_table_sz, in sdhci_setup_host()
4306 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4307 } else if ((dma + host->align_buffer_sz) & in sdhci_setup_host()
4311 host->flags &= ~SDHCI_USE_ADMA; in sdhci_setup_host()
4312 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4313 host->adma_table_sz, buf, dma); in sdhci_setup_host()
4315 host->align_buffer = buf; in sdhci_setup_host()
4316 host->align_addr = dma; in sdhci_setup_host()
4318 host->adma_table = buf + host->align_buffer_sz; in sdhci_setup_host()
4319 host->adma_addr = dma + host->align_buffer_sz; in sdhci_setup_host()
4328 if (!(host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))) { in sdhci_setup_host()
4329 host->dma_mask = DMA_BIT_MASK(64); in sdhci_setup_host()
4330 mmc_dev(mmc)->dma_mask = &host->dma_mask; in sdhci_setup_host()
4333 if (host->version >= SDHCI_SPEC_300) in sdhci_setup_host()
4334 host->max_clk = FIELD_GET(SDHCI_CLOCK_V3_BASE_MASK, host->caps); in sdhci_setup_host()
4336 host->max_clk = FIELD_GET(SDHCI_CLOCK_BASE_MASK, host->caps); in sdhci_setup_host()
4338 host->max_clk *= 1000000; in sdhci_setup_host()
4339 if (host->max_clk == 0 || host->quirks & in sdhci_setup_host()
4341 if (!host->ops->get_max_clock) { in sdhci_setup_host()
4347 host->max_clk = host->ops->get_max_clock(host); in sdhci_setup_host()
4354 host->clk_mul = FIELD_GET(SDHCI_CLOCK_MUL_MASK, host->caps1); in sdhci_setup_host()
4362 if (host->clk_mul) in sdhci_setup_host()
4363 host->clk_mul += 1; in sdhci_setup_host()
4368 max_clk = host->max_clk; in sdhci_setup_host()
4370 if (host->ops->get_min_clock) in sdhci_setup_host()
4371 mmc->f_min = host->ops->get_min_clock(host); in sdhci_setup_host()
4372 else if (host->version >= SDHCI_SPEC_300) { in sdhci_setup_host()
4373 if (host->clk_mul) in sdhci_setup_host()
4374 max_clk = host->max_clk * host->clk_mul; in sdhci_setup_host()
4379 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_300; in sdhci_setup_host()
4381 mmc->f_min = host->max_clk / SDHCI_MAX_DIV_SPEC_200; in sdhci_setup_host()
4386 if (!(host->quirks & SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK)) { in sdhci_setup_host()
4387 host->timeout_clk = FIELD_GET(SDHCI_TIMEOUT_CLK_MASK, host->caps); in sdhci_setup_host()
4389 if (host->caps & SDHCI_TIMEOUT_CLK_UNIT) in sdhci_setup_host()
4390 host->timeout_clk *= 1000; in sdhci_setup_host()
4392 if (host->timeout_clk == 0) { in sdhci_setup_host()
4393 if (!host->ops->get_timeout_clock) { in sdhci_setup_host()
4400 host->timeout_clk = in sdhci_setup_host()
4401 DIV_ROUND_UP(host->ops->get_timeout_clock(host), in sdhci_setup_host()
4406 host->timeout_clk = override_timeout_clk; in sdhci_setup_host()
4408 mmc->max_busy_timeout = host->ops->get_max_timeout_count ? in sdhci_setup_host()
4409 host->ops->get_max_timeout_count(host) : 1 << 27; in sdhci_setup_host()
4410 mmc->max_busy_timeout /= host->timeout_clk; in sdhci_setup_host()
4413 if (host->quirks2 & SDHCI_QUIRK2_DISABLE_HW_TIMEOUT && in sdhci_setup_host()
4414 !host->ops->get_max_timeout_count) in sdhci_setup_host()
4420 if (host->quirks & SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12) in sdhci_setup_host()
4421 host->flags |= SDHCI_AUTO_CMD12; in sdhci_setup_host()
4427 if ((host->version >= SDHCI_SPEC_300) && in sdhci_setup_host()
4428 ((host->flags & SDHCI_USE_ADMA) || in sdhci_setup_host()
4429 !(host->flags & SDHCI_USE_SDMA) || host->v4_mode) && in sdhci_setup_host()
4430 !(host->quirks2 & SDHCI_QUIRK2_ACMD23_BROKEN)) { in sdhci_setup_host()
4431 host->flags |= SDHCI_AUTO_CMD23; in sdhci_setup_host()
4444 if (!(host->quirks & SDHCI_QUIRK_FORCE_1_BIT_DATA)) in sdhci_setup_host()
4447 if (host->quirks2 & SDHCI_QUIRK2_HOST_NO_CMD23) in sdhci_setup_host()
4450 if (host->caps & SDHCI_CAN_DO_HISPD) in sdhci_setup_host()
4453 if ((host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION) && in sdhci_setup_host()
4455 mmc_gpio_get_cd(host->mmc) < 0) in sdhci_setup_host()
4461 host->sdhci_core_to_disable_vqmmc = !ret; in sdhci_setup_host()
4467 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | in sdhci_setup_host()
4474 host->flags &= ~SDHCI_SIGNALING_330; in sdhci_setup_host()
4484 if (host->quirks2 & SDHCI_QUIRK2_NO_1_8_V) { in sdhci_setup_host()
4485 host->caps1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4500 if (host->caps1 & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 | in sdhci_setup_host()
4505 if (host->caps1 & SDHCI_SUPPORT_SDR104) { in sdhci_setup_host()
4510 if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) in sdhci_setup_host()
4512 } else if (host->caps1 & SDHCI_SUPPORT_SDR50) { in sdhci_setup_host()
4516 if (host->quirks2 & SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 && in sdhci_setup_host()
4517 (host->caps1 & SDHCI_SUPPORT_HS400)) in sdhci_setup_host()
4526 if ((host->caps1 & SDHCI_SUPPORT_DDR50) && in sdhci_setup_host()
4527 !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50)) in sdhci_setup_host()
4531 if (host->caps1 & SDHCI_USE_SDR50_TUNING) in sdhci_setup_host()
4532 host->flags |= SDHCI_SDR50_NEEDS_TUNING; in sdhci_setup_host()
4535 if (host->caps1 & SDHCI_DRIVER_TYPE_A) in sdhci_setup_host()
4537 if (host->caps1 & SDHCI_DRIVER_TYPE_C) in sdhci_setup_host()
4539 if (host->caps1 & SDHCI_DRIVER_TYPE_D) in sdhci_setup_host()
4543 host->tuning_count = FIELD_GET(SDHCI_RETUNING_TIMER_COUNT_MASK, in sdhci_setup_host()
4544 host->caps1); in sdhci_setup_host()
4550 if (host->tuning_count) in sdhci_setup_host()
4551 host->tuning_count = 1 << (host->tuning_count - 1); in sdhci_setup_host()
4554 host->tuning_mode = FIELD_GET(SDHCI_RETUNING_MODE_MASK, host->caps1); in sdhci_setup_host()
4565 max_current_caps = sdhci_readl(host, SDHCI_MAX_CURRENT); in sdhci_setup_host()
4582 if (host->caps & SDHCI_CAN_VDD_330) { in sdhci_setup_host()
4589 if (host->caps & SDHCI_CAN_VDD_300) { in sdhci_setup_host()
4596 if (host->caps & SDHCI_CAN_VDD_180) { in sdhci_setup_host()
4605 if (host->ocr_mask) in sdhci_setup_host()
4606 ocr_avail = host->ocr_mask; in sdhci_setup_host()
4614 if (host->ocr_avail_sdio) in sdhci_setup_host()
4615 mmc->ocr_avail_sdio &= host->ocr_avail_sdio; in sdhci_setup_host()
4617 if (host->ocr_avail_sd) in sdhci_setup_host()
4618 mmc->ocr_avail_sd &= host->ocr_avail_sd; in sdhci_setup_host()
4622 if (host->ocr_avail_mmc) in sdhci_setup_host()
4623 mmc->ocr_avail_mmc &= host->ocr_avail_mmc; in sdhci_setup_host()
4636 host->flags |= SDHCI_SIGNALING_180; in sdhci_setup_host()
4639 host->flags |= SDHCI_SIGNALING_120; in sdhci_setup_host()
4641 spin_lock_init(&host->lock); in sdhci_setup_host()
4654 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4656 } else if (host->flags & SDHCI_USE_SDMA) { in sdhci_setup_host()
4673 if (host->flags & SDHCI_USE_ADMA) { in sdhci_setup_host()
4674 if (host->quirks & SDHCI_QUIRK_BROKEN_ADMA_ZEROLEN_DESC) { in sdhci_setup_host()
4675 host->max_adma = 65532; /* 32-bit alignment */ in sdhci_setup_host()
4688 if (host->quirks & SDHCI_QUIRK_FORCE_BLK_SZ_2048) { in sdhci_setup_host()
4691 mmc->max_blk_size = (host->caps & SDHCI_MAX_BLOCK_MASK) >> in sdhci_setup_host()
4705 mmc->max_blk_count = (host->quirks & SDHCI_QUIRK_NO_MULTIBLOCK) ? 1 : 65535; in sdhci_setup_host()
4709 sdhci_allocate_bounce_buffer(host); in sdhci_setup_host()
4714 if (host->sdhci_core_to_disable_vqmmc) in sdhci_setup_host()
4717 if (host->align_buffer) in sdhci_setup_host()
4718 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_setup_host()
4719 host->adma_table_sz, host->align_buffer, in sdhci_setup_host()
4720 host->align_addr); in sdhci_setup_host()
4721 host->adma_table = NULL; in sdhci_setup_host()
4722 host->align_buffer = NULL; in sdhci_setup_host()
4728 void sdhci_cleanup_host(struct sdhci_host *host) in sdhci_cleanup_host() argument
4730 struct mmc_host *mmc = host->mmc; in sdhci_cleanup_host()
4732 if (host->sdhci_core_to_disable_vqmmc) in sdhci_cleanup_host()
4735 if (host->align_buffer) in sdhci_cleanup_host()
4736 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_cleanup_host()
4737 host->adma_table_sz, host->align_buffer, in sdhci_cleanup_host()
4738 host->align_addr); in sdhci_cleanup_host()
4740 if (host->use_external_dma) in sdhci_cleanup_host()
4741 sdhci_external_dma_release(host); in sdhci_cleanup_host()
4743 host->adma_table = NULL; in sdhci_cleanup_host()
4744 host->align_buffer = NULL; in sdhci_cleanup_host()
4748 int __sdhci_add_host(struct sdhci_host *host) in __sdhci_add_host() argument
4751 struct mmc_host *mmc = host->mmc; in __sdhci_add_host()
4755 (host->quirks & SDHCI_QUIRK_BROKEN_CQE)) { in __sdhci_add_host()
4760 host->complete_wq = alloc_workqueue("sdhci", flags, 0); in __sdhci_add_host()
4761 if (!host->complete_wq) in __sdhci_add_host()
4764 INIT_WORK(&host->complete_work, sdhci_complete_work); in __sdhci_add_host()
4766 timer_setup(&host->timer, sdhci_timeout_timer, 0); in __sdhci_add_host()
4767 timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0); in __sdhci_add_host()
4769 init_waitqueue_head(&host->buf_ready_int); in __sdhci_add_host()
4771 sdhci_init(host, 0); in __sdhci_add_host()
4773 ret = request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq, in __sdhci_add_host()
4774 IRQF_SHARED, mmc_hostname(mmc), host); in __sdhci_add_host()
4777 mmc_hostname(mmc), host->irq, ret); in __sdhci_add_host()
4781 ret = sdhci_led_register(host); in __sdhci_add_host()
4793 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), in __sdhci_add_host()
4794 host->use_external_dma ? "External DMA" : in __sdhci_add_host()
4795 (host->flags & SDHCI_USE_ADMA) ? in __sdhci_add_host()
4796 (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" : in __sdhci_add_host()
4797 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); in __sdhci_add_host()
4799 sdhci_enable_card_detection(host); in __sdhci_add_host()
4804 sdhci_led_unregister(host); in __sdhci_add_host()
4806 sdhci_do_reset(host, SDHCI_RESET_ALL); in __sdhci_add_host()
4807 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in __sdhci_add_host()
4808 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in __sdhci_add_host()
4809 free_irq(host->irq, host); in __sdhci_add_host()
4811 destroy_workqueue(host->complete_wq); in __sdhci_add_host()
4817 int sdhci_add_host(struct sdhci_host *host) in sdhci_add_host() argument
4821 ret = sdhci_setup_host(host); in sdhci_add_host()
4825 ret = __sdhci_add_host(host); in sdhci_add_host()
4832 sdhci_cleanup_host(host); in sdhci_add_host()
4838 void sdhci_remove_host(struct sdhci_host *host, int dead) in sdhci_remove_host() argument
4840 struct mmc_host *mmc = host->mmc; in sdhci_remove_host()
4844 spin_lock_irqsave(&host->lock, flags); in sdhci_remove_host()
4846 host->flags |= SDHCI_DEVICE_DEAD; in sdhci_remove_host()
4848 if (sdhci_has_requests(host)) { in sdhci_remove_host()
4851 sdhci_error_out_mrqs(host, -ENOMEDIUM); in sdhci_remove_host()
4854 spin_unlock_irqrestore(&host->lock, flags); in sdhci_remove_host()
4857 sdhci_disable_card_detection(host); in sdhci_remove_host()
4861 sdhci_led_unregister(host); in sdhci_remove_host()
4864 sdhci_do_reset(host, SDHCI_RESET_ALL); in sdhci_remove_host()
4866 sdhci_writel(host, 0, SDHCI_INT_ENABLE); in sdhci_remove_host()
4867 sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE); in sdhci_remove_host()
4868 free_irq(host->irq, host); in sdhci_remove_host()
4870 del_timer_sync(&host->timer); in sdhci_remove_host()
4871 del_timer_sync(&host->data_timer); in sdhci_remove_host()
4873 destroy_workqueue(host->complete_wq); in sdhci_remove_host()
4875 if (host->sdhci_core_to_disable_vqmmc) in sdhci_remove_host()
4878 if (host->align_buffer) in sdhci_remove_host()
4879 dma_free_coherent(mmc_dev(mmc), host->align_buffer_sz + in sdhci_remove_host()
4880 host->adma_table_sz, host->align_buffer, in sdhci_remove_host()
4881 host->align_addr); in sdhci_remove_host()
4883 if (host->use_external_dma) in sdhci_remove_host()
4884 sdhci_external_dma_release(host); in sdhci_remove_host()
4886 host->adma_table = NULL; in sdhci_remove_host()
4887 host->align_buffer = NULL; in sdhci_remove_host()
4892 void sdhci_free_host(struct sdhci_host *host) in sdhci_free_host() argument
4894 mmc_free_host(host->mmc); in sdhci_free_host()