Lines Matching full:host
36 #include <linux/mmc/host.h>
53 static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host, in tmio_mmc_start_dma() argument
56 if (host->dma_ops) in tmio_mmc_start_dma()
57 host->dma_ops->start(host, data); in tmio_mmc_start_dma()
60 static inline void tmio_mmc_end_dma(struct tmio_mmc_host *host) in tmio_mmc_end_dma() argument
62 if (host->dma_ops && host->dma_ops->end) in tmio_mmc_end_dma()
63 host->dma_ops->end(host); in tmio_mmc_end_dma()
66 static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable) in tmio_mmc_enable_dma() argument
68 if (host->dma_ops) in tmio_mmc_enable_dma()
69 host->dma_ops->enable(host, enable); in tmio_mmc_enable_dma()
72 static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host, in tmio_mmc_request_dma() argument
75 if (host->dma_ops) { in tmio_mmc_request_dma()
76 host->dma_ops->request(host, pdata); in tmio_mmc_request_dma()
78 host->chan_tx = NULL; in tmio_mmc_request_dma()
79 host->chan_rx = NULL; in tmio_mmc_request_dma()
83 static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host) in tmio_mmc_release_dma() argument
85 if (host->dma_ops) in tmio_mmc_release_dma()
86 host->dma_ops->release(host); in tmio_mmc_release_dma()
89 static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host) in tmio_mmc_abort_dma() argument
91 if (host->dma_ops) in tmio_mmc_abort_dma()
92 host->dma_ops->abort(host); in tmio_mmc_abort_dma()
95 static inline void tmio_mmc_dataend_dma(struct tmio_mmc_host *host) in tmio_mmc_dataend_dma() argument
97 if (host->dma_ops) in tmio_mmc_dataend_dma()
98 host->dma_ops->dataend(host); in tmio_mmc_dataend_dma()
101 void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_enable_mmc_irqs() argument
103 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ); in tmio_mmc_enable_mmc_irqs()
104 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask); in tmio_mmc_enable_mmc_irqs()
108 void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_disable_mmc_irqs() argument
110 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ); in tmio_mmc_disable_mmc_irqs()
111 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask); in tmio_mmc_disable_mmc_irqs()
115 static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_ack_mmc_irqs() argument
117 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, ~i); in tmio_mmc_ack_mmc_irqs()
120 static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data) in tmio_mmc_init_sg() argument
122 host->sg_len = data->sg_len; in tmio_mmc_init_sg()
123 host->sg_ptr = data->sg; in tmio_mmc_init_sg()
124 host->sg_orig = data->sg; in tmio_mmc_init_sg()
125 host->sg_off = 0; in tmio_mmc_init_sg()
128 static int tmio_mmc_next_sg(struct tmio_mmc_host *host) in tmio_mmc_next_sg() argument
130 host->sg_ptr = sg_next(host->sg_ptr); in tmio_mmc_next_sg()
131 host->sg_off = 0; in tmio_mmc_next_sg()
132 return --host->sg_len; in tmio_mmc_next_sg()
139 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_enable_sdio_irq() local
141 if (enable && !host->sdio_irq_enabled) { in tmio_mmc_enable_sdio_irq()
147 host->sdio_irq_enabled = true; in tmio_mmc_enable_sdio_irq()
148 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ; in tmio_mmc_enable_sdio_irq()
151 sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS) & ~TMIO_SDIO_MASK_ALL; in tmio_mmc_enable_sdio_irq()
152 if (host->pdata->flags & TMIO_MMC_SDIO_STATUS_SETBITS) in tmio_mmc_enable_sdio_irq()
154 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status); in tmio_mmc_enable_sdio_irq()
156 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_enable_sdio_irq()
157 } else if (!enable && host->sdio_irq_enabled) { in tmio_mmc_enable_sdio_irq()
158 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL; in tmio_mmc_enable_sdio_irq()
159 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_enable_sdio_irq()
161 host->sdio_irq_enabled = false; in tmio_mmc_enable_sdio_irq()
167 static void tmio_mmc_set_bus_width(struct tmio_mmc_host *host, in tmio_mmc_set_bus_width() argument
170 u16 reg = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT) in tmio_mmc_set_bus_width()
179 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, reg); in tmio_mmc_set_bus_width()
182 static void tmio_mmc_reset(struct tmio_mmc_host *host, bool preserve) in tmio_mmc_reset() argument
187 card_opt = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT); in tmio_mmc_reset()
188 clk_ctrl = sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL); in tmio_mmc_reset()
189 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_reset()
190 sdif_mode = sd_ctrl_read16(host, CTL_SDIF_MODE); in tmio_mmc_reset()
194 sd_ctrl_write16(host, CTL_RESET_SD, 0x0000); in tmio_mmc_reset()
196 sd_ctrl_write16(host, CTL_RESET_SD, 0x0001); in tmio_mmc_reset()
199 tmio_mmc_abort_dma(host); in tmio_mmc_reset()
201 if (host->reset) in tmio_mmc_reset()
202 host->reset(host, preserve); in tmio_mmc_reset()
204 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask_all); in tmio_mmc_reset()
205 host->sdcard_irq_mask = host->sdcard_irq_mask_all; in tmio_mmc_reset()
207 if (host->native_hotplug) in tmio_mmc_reset()
208 tmio_mmc_enable_mmc_irqs(host, in tmio_mmc_reset()
211 tmio_mmc_set_bus_width(host, host->mmc->ios.bus_width); in tmio_mmc_reset()
213 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) { in tmio_mmc_reset()
214 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_reset()
215 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001); in tmio_mmc_reset()
219 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, card_opt); in tmio_mmc_reset()
220 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk_ctrl); in tmio_mmc_reset()
221 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_reset()
222 sd_ctrl_write16(host, CTL_SDIF_MODE, sdif_mode); in tmio_mmc_reset()
225 if (host->mmc->card) in tmio_mmc_reset()
226 mmc_retune_needed(host->mmc); in tmio_mmc_reset()
231 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host, in tmio_mmc_reset_work() local
236 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_reset_work()
237 mrq = host->mrq; in tmio_mmc_reset_work()
242 * us, so, have to check for IS_ERR(host->mrq) in tmio_mmc_reset_work()
245 time_is_after_jiffies(host->last_req_ts + in tmio_mmc_reset_work()
247 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_reset_work()
251 dev_warn(&host->pdev->dev, in tmio_mmc_reset_work()
255 if (host->data) in tmio_mmc_reset_work()
256 host->data->error = -ETIMEDOUT; in tmio_mmc_reset_work()
257 else if (host->cmd) in tmio_mmc_reset_work()
258 host->cmd->error = -ETIMEDOUT; in tmio_mmc_reset_work()
262 host->cmd = NULL; in tmio_mmc_reset_work()
263 host->data = NULL; in tmio_mmc_reset_work()
265 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_reset_work()
267 tmio_mmc_reset(host, true); in tmio_mmc_reset_work()
270 host->mrq = NULL; in tmio_mmc_reset_work()
271 mmc_request_done(host->mmc, mrq); in tmio_mmc_reset_work()
288 static int tmio_mmc_start_command(struct tmio_mmc_host *host, in tmio_mmc_start_command() argument
291 struct mmc_data *data = host->data; in tmio_mmc_start_command()
307 host->cmd = cmd; in tmio_mmc_start_command()
317 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, TMIO_STOP_SEC); in tmio_mmc_start_command()
324 if ((host->pdata->flags & TMIO_MMC_HAVE_CMD12_CTRL) && in tmio_mmc_start_command()
325 (cmd->opcode == SD_IO_RW_EXTENDED || host->mrq->sbc)) in tmio_mmc_start_command()
332 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_CMD); in tmio_mmc_start_command()
335 sd_ctrl_write32_as_16_and_16(host, CTL_ARG_REG, cmd->arg); in tmio_mmc_start_command()
336 sd_ctrl_write16(host, CTL_SD_CMD, c); in tmio_mmc_start_command()
341 static void tmio_mmc_transfer_data(struct tmio_mmc_host *host, in tmio_mmc_transfer_data() argument
345 int is_read = host->data->flags & MMC_DATA_READ; in tmio_mmc_transfer_data()
351 if (host->pdata->flags & TMIO_MMC_32BIT_DATA_PORT) { in tmio_mmc_transfer_data()
356 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, buf32, in tmio_mmc_transfer_data()
359 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, buf32, in tmio_mmc_transfer_data()
370 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, &data, 1); in tmio_mmc_transfer_data()
374 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, &data, 1); in tmio_mmc_transfer_data()
381 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1); in tmio_mmc_transfer_data()
383 sd_ctrl_write16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1); in tmio_mmc_transfer_data()
399 *buf8 = sd_ctrl_read16(host, CTL_SD_DATA_PORT) & 0xff; in tmio_mmc_transfer_data()
401 sd_ctrl_write16(host, CTL_SD_DATA_PORT, *buf8); in tmio_mmc_transfer_data()
409 static void tmio_mmc_pio_irq(struct tmio_mmc_host *host) in tmio_mmc_pio_irq() argument
411 struct mmc_data *data = host->data; in tmio_mmc_pio_irq()
416 if (host->dma_on) { in tmio_mmc_pio_irq()
424 sg_virt = kmap_local_page(sg_page(host->sg_ptr)); in tmio_mmc_pio_irq()
425 buf = (unsigned short *)(sg_virt + host->sg_ptr->offset + host->sg_off); in tmio_mmc_pio_irq()
427 count = host->sg_ptr->length - host->sg_off; in tmio_mmc_pio_irq()
432 count, host->sg_off, data->flags); in tmio_mmc_pio_irq()
435 tmio_mmc_transfer_data(host, buf, count); in tmio_mmc_pio_irq()
437 host->sg_off += count; in tmio_mmc_pio_irq()
441 if (host->sg_off == host->sg_ptr->length) in tmio_mmc_pio_irq()
442 tmio_mmc_next_sg(host); in tmio_mmc_pio_irq()
445 static void tmio_mmc_check_bounce_buffer(struct tmio_mmc_host *host) in tmio_mmc_check_bounce_buffer() argument
447 if (host->sg_ptr == &host->bounce_sg) { in tmio_mmc_check_bounce_buffer()
448 void *sg_virt = kmap_local_page(sg_page(host->sg_orig)); in tmio_mmc_check_bounce_buffer()
450 memcpy(sg_virt + host->sg_orig->offset, host->bounce_buf, in tmio_mmc_check_bounce_buffer()
451 host->bounce_sg.length); in tmio_mmc_check_bounce_buffer()
456 /* needs to be called with host->lock held */
457 void tmio_mmc_do_data_irq(struct tmio_mmc_host *host) in tmio_mmc_do_data_irq() argument
459 struct mmc_data *data = host->data; in tmio_mmc_do_data_irq()
462 host->data = NULL; in tmio_mmc_do_data_irq()
465 dev_warn(&host->pdev->dev, "Spurious data end IRQ\n"); in tmio_mmc_do_data_irq()
488 if (host->dma_on) in tmio_mmc_do_data_irq()
489 tmio_mmc_check_bounce_buffer(host); in tmio_mmc_do_data_irq()
490 dev_dbg(&host->pdev->dev, "Complete Rx request %p\n", in tmio_mmc_do_data_irq()
491 host->mrq); in tmio_mmc_do_data_irq()
493 dev_dbg(&host->pdev->dev, "Complete Tx request %p\n", in tmio_mmc_do_data_irq()
494 host->mrq); in tmio_mmc_do_data_irq()
497 if (stop && !host->mrq->sbc) { in tmio_mmc_do_data_irq()
499 dev_err(&host->pdev->dev, "unsupported stop: CMD%u,0x%x. We did CMD12,0\n", in tmio_mmc_do_data_irq()
503 stop->resp[0] = sd_ctrl_read16_and_16_as_32(host, CTL_RESPONSE); in tmio_mmc_do_data_irq()
505 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0); in tmio_mmc_do_data_irq()
508 schedule_work(&host->done); in tmio_mmc_do_data_irq()
512 static void tmio_mmc_data_irq(struct tmio_mmc_host *host, unsigned int stat) in tmio_mmc_data_irq() argument
516 spin_lock(&host->lock); in tmio_mmc_data_irq()
517 data = host->data; in tmio_mmc_data_irq()
527 if (host->dma_on && (data->flags & MMC_DATA_WRITE)) { in tmio_mmc_data_irq()
528 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); in tmio_mmc_data_irq()
539 if (host->pdata->flags & TMIO_MMC_HAS_IDLE_WAIT) { in tmio_mmc_data_irq()
548 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); in tmio_mmc_data_irq()
549 tmio_mmc_dataend_dma(host); in tmio_mmc_data_irq()
551 } else if (host->dma_on && (data->flags & MMC_DATA_READ)) { in tmio_mmc_data_irq()
552 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); in tmio_mmc_data_irq()
553 tmio_mmc_dataend_dma(host); in tmio_mmc_data_irq()
555 tmio_mmc_do_data_irq(host); in tmio_mmc_data_irq()
556 tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP); in tmio_mmc_data_irq()
559 spin_unlock(&host->lock); in tmio_mmc_data_irq()
562 static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat) in tmio_mmc_cmd_irq() argument
564 struct mmc_command *cmd = host->cmd; in tmio_mmc_cmd_irq()
567 spin_lock(&host->lock); in tmio_mmc_cmd_irq()
569 if (!host->cmd) { in tmio_mmc_cmd_irq()
580 cmd->resp[i] = sd_ctrl_read16_and_16_as_32(host, addr); in tmio_mmc_cmd_irq()
602 if (host->data && (!cmd->error || cmd->error == -EILSEQ)) { in tmio_mmc_cmd_irq()
603 if (host->data->flags & MMC_DATA_READ) { in tmio_mmc_cmd_irq()
604 if (!host->dma_on) { in tmio_mmc_cmd_irq()
605 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP); in tmio_mmc_cmd_irq()
607 tmio_mmc_disable_mmc_irqs(host, in tmio_mmc_cmd_irq()
609 tasklet_schedule(&host->dma_issue); in tmio_mmc_cmd_irq()
612 if (!host->dma_on) { in tmio_mmc_cmd_irq()
613 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_WRITEOP); in tmio_mmc_cmd_irq()
615 tmio_mmc_disable_mmc_irqs(host, in tmio_mmc_cmd_irq()
617 tasklet_schedule(&host->dma_issue); in tmio_mmc_cmd_irq()
621 schedule_work(&host->done); in tmio_mmc_cmd_irq()
625 spin_unlock(&host->lock); in tmio_mmc_cmd_irq()
628 static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host, in __tmio_mmc_card_detect_irq() argument
631 struct mmc_host *mmc = host->mmc; in __tmio_mmc_card_detect_irq()
635 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT | in __tmio_mmc_card_detect_irq()
640 mmc_detect_change(host->mmc, msecs_to_jiffies(100)); in __tmio_mmc_card_detect_irq()
647 static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host, int ireg, in __tmio_mmc_sdcard_irq() argument
652 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CMDRESPEND | in __tmio_mmc_sdcard_irq()
654 tmio_mmc_cmd_irq(host, status); in __tmio_mmc_sdcard_irq()
660 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ); in __tmio_mmc_sdcard_irq()
661 tmio_mmc_pio_irq(host); in __tmio_mmc_sdcard_irq()
667 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND); in __tmio_mmc_sdcard_irq()
668 tmio_mmc_data_irq(host, status); in __tmio_mmc_sdcard_irq()
672 if (host->dma_ops && host->dma_ops->dma_irq && host->dma_ops->dma_irq(host)) in __tmio_mmc_sdcard_irq()
678 static bool __tmio_mmc_sdio_irq(struct tmio_mmc_host *host) in __tmio_mmc_sdio_irq() argument
680 struct mmc_host *mmc = host->mmc; in __tmio_mmc_sdio_irq()
681 struct tmio_mmc_data *pdata = host->pdata; in __tmio_mmc_sdio_irq()
688 status = sd_ctrl_read16(host, CTL_SDIO_STATUS); in __tmio_mmc_sdio_irq()
689 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdio_irq_mask; in __tmio_mmc_sdio_irq()
695 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status); in __tmio_mmc_sdio_irq()
705 struct tmio_mmc_host *host = devid; in tmio_mmc_irq() local
708 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); in tmio_mmc_irq()
709 ireg = status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask; in tmio_mmc_irq()
712 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, TMIO_MASK_IRQ); in tmio_mmc_irq()
714 if (__tmio_mmc_card_detect_irq(host, ireg, status)) in tmio_mmc_irq()
716 if (__tmio_mmc_sdcard_irq(host, ireg, status)) in tmio_mmc_irq()
719 if (__tmio_mmc_sdio_irq(host)) in tmio_mmc_irq()
726 static int tmio_mmc_start_data(struct tmio_mmc_host *host, in tmio_mmc_start_data() argument
729 struct tmio_mmc_data *pdata = host->pdata; in tmio_mmc_start_data()
735 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4 || in tmio_mmc_start_data()
736 host->mmc->ios.bus_width == MMC_BUS_WIDTH_8) { in tmio_mmc_start_data()
741 mmc_hostname(host->mmc), data->blksz); in tmio_mmc_start_data()
746 tmio_mmc_init_sg(host, data); in tmio_mmc_start_data()
747 host->data = data; in tmio_mmc_start_data()
748 host->dma_on = false; in tmio_mmc_start_data()
751 sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz); in tmio_mmc_start_data()
752 if (host->mmc->max_blk_count >= SZ_64K) in tmio_mmc_start_data()
753 sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks); in tmio_mmc_start_data()
755 sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks); in tmio_mmc_start_data()
757 tmio_mmc_start_dma(host, data); in tmio_mmc_start_data()
762 static void tmio_process_mrq(struct tmio_mmc_host *host, in tmio_process_mrq() argument
768 if (mrq->sbc && host->cmd != mrq->sbc) { in tmio_process_mrq()
773 ret = tmio_mmc_start_data(host, mrq->data); in tmio_process_mrq()
779 ret = tmio_mmc_start_command(host, cmd); in tmio_process_mrq()
783 schedule_delayed_work(&host->delayed_reset_work, in tmio_process_mrq()
788 host->mrq = NULL; in tmio_process_mrq()
790 mmc_request_done(host->mmc, mrq); in tmio_process_mrq()
796 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_request() local
799 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_request()
801 if (host->mrq) { in tmio_mmc_request()
803 if (IS_ERR(host->mrq)) { in tmio_mmc_request()
804 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_request()
811 host->last_req_ts = jiffies; in tmio_mmc_request()
813 host->mrq = mrq; in tmio_mmc_request()
815 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_request()
817 tmio_process_mrq(host, mrq); in tmio_mmc_request()
820 static void tmio_mmc_finish_request(struct tmio_mmc_host *host) in tmio_mmc_finish_request() argument
825 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_finish_request()
827 tmio_mmc_end_dma(host); in tmio_mmc_finish_request()
829 mrq = host->mrq; in tmio_mmc_finish_request()
831 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_finish_request()
836 if (host->cmd != mrq->sbc) { in tmio_mmc_finish_request()
837 host->cmd = NULL; in tmio_mmc_finish_request()
838 host->data = NULL; in tmio_mmc_finish_request()
839 host->mrq = NULL; in tmio_mmc_finish_request()
842 cancel_delayed_work(&host->delayed_reset_work); in tmio_mmc_finish_request()
844 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_finish_request()
847 tmio_mmc_ack_mmc_irqs(host, TMIO_MASK_IRQ); /* Clear all */ in tmio_mmc_finish_request()
848 tmio_mmc_abort_dma(host); in tmio_mmc_finish_request()
852 if (host->check_retune && host->check_retune(host, mrq)) in tmio_mmc_finish_request()
853 mmc_retune_needed(host->mmc); in tmio_mmc_finish_request()
856 if (host->mrq && !mrq->cmd->error) { in tmio_mmc_finish_request()
857 tmio_process_mrq(host, mrq); in tmio_mmc_finish_request()
861 if (host->fixup_request) in tmio_mmc_finish_request()
862 host->fixup_request(host, mrq); in tmio_mmc_finish_request()
864 mmc_request_done(host->mmc, mrq); in tmio_mmc_finish_request()
869 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host, in tmio_mmc_done_work() local
871 tmio_mmc_finish_request(host); in tmio_mmc_done_work()
874 static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd) in tmio_mmc_power_on() argument
876 struct mmc_host *mmc = host->mmc; in tmio_mmc_power_on()
881 if (host->set_pwr) in tmio_mmc_power_on()
882 host->set_pwr(host->pdev, 1); in tmio_mmc_power_on()
904 dev_dbg(&host->pdev->dev, "Regulators failed to power up: %d\n", in tmio_mmc_power_on()
908 static void tmio_mmc_power_off(struct tmio_mmc_host *host) in tmio_mmc_power_off() argument
910 struct mmc_host *mmc = host->mmc; in tmio_mmc_power_off()
918 if (host->set_pwr) in tmio_mmc_power_off()
919 host->set_pwr(host->pdev, 0); in tmio_mmc_power_off()
922 static unsigned int tmio_mmc_get_timeout_cycles(struct tmio_mmc_host *host) in tmio_mmc_get_timeout_cycles() argument
924 u16 val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT); in tmio_mmc_get_timeout_cycles()
930 static void tmio_mmc_max_busy_timeout(struct tmio_mmc_host *host) in tmio_mmc_max_busy_timeout() argument
932 unsigned int clk_rate = host->mmc->actual_clock ?: host->mmc->f_max; in tmio_mmc_max_busy_timeout()
934 host->mmc->max_busy_timeout = host->get_timeout_cycles(host) / in tmio_mmc_max_busy_timeout()
946 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_set_ios() local
947 struct device *dev = &host->pdev->dev; in tmio_mmc_set_ios()
950 mutex_lock(&host->ios_lock); in tmio_mmc_set_ios()
952 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_set_ios()
953 if (host->mrq) { in tmio_mmc_set_ios()
954 if (IS_ERR(host->mrq)) { in tmio_mmc_set_ios()
959 host->mrq = ERR_PTR(-EINTR); in tmio_mmc_set_ios()
964 host->mrq->cmd->opcode, host->last_req_ts, in tmio_mmc_set_ios()
967 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_set_ios()
969 mutex_unlock(&host->ios_lock); in tmio_mmc_set_ios()
973 host->mrq = ERR_PTR(-EBUSY); in tmio_mmc_set_ios()
975 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_set_ios()
979 tmio_mmc_power_off(host); in tmio_mmc_set_ios()
981 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_set_ios()
982 tmio_mmc_reset(host, false); in tmio_mmc_set_ios()
984 host->set_clock(host, 0); in tmio_mmc_set_ios()
987 tmio_mmc_power_on(host, ios->vdd); in tmio_mmc_set_ios()
988 host->set_clock(host, ios->clock); in tmio_mmc_set_ios()
989 tmio_mmc_set_bus_width(host, ios->bus_width); in tmio_mmc_set_ios()
992 host->set_clock(host, ios->clock); in tmio_mmc_set_ios()
993 tmio_mmc_set_bus_width(host, ios->bus_width); in tmio_mmc_set_ios()
997 if (host->pdata->flags & TMIO_MMC_USE_BUSY_TIMEOUT) in tmio_mmc_set_ios()
998 tmio_mmc_max_busy_timeout(host); in tmio_mmc_set_ios()
1002 if (PTR_ERR(host->mrq) == -EINTR) in tmio_mmc_set_ios()
1003 dev_dbg(&host->pdev->dev, in tmio_mmc_set_ios()
1007 host->mrq = NULL; in tmio_mmc_set_ios()
1009 host->clk_cache = ios->clock; in tmio_mmc_set_ios()
1011 mutex_unlock(&host->ios_lock); in tmio_mmc_set_ios()
1016 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_get_ro() local
1018 return !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & in tmio_mmc_get_ro()
1024 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_get_cd() local
1026 return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & in tmio_mmc_get_cd()
1033 struct tmio_mmc_host *host = mmc_priv(card->host); in tmio_multi_io_quirk() local
1035 if (host->multi_io_quirk) in tmio_multi_io_quirk()
1036 return host->multi_io_quirk(card, direction, blk_size); in tmio_multi_io_quirk()
1050 static int tmio_mmc_init_ocr(struct tmio_mmc_host *host) in tmio_mmc_init_ocr() argument
1052 struct tmio_mmc_data *pdata = host->pdata; in tmio_mmc_init_ocr()
1053 struct mmc_host *mmc = host->mmc; in tmio_mmc_init_ocr()
1094 struct tmio_mmc_host *host; in tmio_mmc_host_alloc() local
1107 host = mmc_priv(mmc); in tmio_mmc_host_alloc()
1108 host->ctl = ctl; in tmio_mmc_host_alloc()
1109 host->mmc = mmc; in tmio_mmc_host_alloc()
1110 host->pdev = pdev; in tmio_mmc_host_alloc()
1111 host->pdata = pdata; in tmio_mmc_host_alloc()
1112 host->ops = tmio_mmc_ops; in tmio_mmc_host_alloc()
1113 mmc->ops = &host->ops; in tmio_mmc_host_alloc()
1115 ret = mmc_of_parse(host->mmc); in tmio_mmc_host_alloc()
1117 host = ERR_PTR(ret); in tmio_mmc_host_alloc()
1123 platform_set_drvdata(pdev, host); in tmio_mmc_host_alloc()
1125 return host; in tmio_mmc_host_alloc()
1129 return host; in tmio_mmc_host_alloc()
1133 void tmio_mmc_host_free(struct tmio_mmc_host *host) in tmio_mmc_host_free() argument
1135 mmc_free_host(host->mmc); in tmio_mmc_host_free()
1147 * Check the sanity of mmc->f_min to prevent host->set_clock() from in tmio_mmc_host_probe()
1244 void tmio_mmc_host_remove(struct tmio_mmc_host *host) in tmio_mmc_host_remove() argument
1246 struct platform_device *pdev = host->pdev; in tmio_mmc_host_remove()
1247 struct mmc_host *mmc = host->mmc; in tmio_mmc_host_remove()
1251 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) in tmio_mmc_host_remove()
1252 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000); in tmio_mmc_host_remove()
1257 cancel_work_sync(&host->done); in tmio_mmc_host_remove()
1258 cancel_delayed_work_sync(&host->delayed_reset_work); in tmio_mmc_host_remove()
1259 tmio_mmc_release_dma(host); in tmio_mmc_host_remove()
1260 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); in tmio_mmc_host_remove()
1262 if (host->native_hotplug) in tmio_mmc_host_remove()
1272 static int tmio_mmc_clk_enable(struct tmio_mmc_host *host) in tmio_mmc_clk_enable() argument
1274 if (!host->clk_enable) in tmio_mmc_clk_enable()
1277 return host->clk_enable(host); in tmio_mmc_clk_enable()
1280 static void tmio_mmc_clk_disable(struct tmio_mmc_host *host) in tmio_mmc_clk_disable() argument
1282 if (host->clk_disable) in tmio_mmc_clk_disable()
1283 host->clk_disable(host); in tmio_mmc_clk_disable()
1288 struct tmio_mmc_host *host = dev_get_drvdata(dev); in tmio_mmc_host_runtime_suspend() local
1290 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); in tmio_mmc_host_runtime_suspend()
1292 if (host->clk_cache) in tmio_mmc_host_runtime_suspend()
1293 host->set_clock(host, 0); in tmio_mmc_host_runtime_suspend()
1295 tmio_mmc_clk_disable(host); in tmio_mmc_host_runtime_suspend()
1303 struct tmio_mmc_host *host = dev_get_drvdata(dev); in tmio_mmc_host_runtime_resume() local
1305 tmio_mmc_clk_enable(host); in tmio_mmc_host_runtime_resume()
1306 tmio_mmc_reset(host, false); in tmio_mmc_host_runtime_resume()
1308 if (host->clk_cache) in tmio_mmc_host_runtime_resume()
1309 host->set_clock(host, host->clk_cache); in tmio_mmc_host_runtime_resume()
1311 tmio_mmc_enable_dma(host, true); in tmio_mmc_host_runtime_resume()