Lines Matching full:host

35 #include <linux/mmc/host.h>
54 static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host, in tmio_mmc_start_dma() argument
57 if (host->dma_ops) in tmio_mmc_start_dma()
58 host->dma_ops->start(host, data); in tmio_mmc_start_dma()
61 static inline void tmio_mmc_end_dma(struct tmio_mmc_host *host) in tmio_mmc_end_dma() argument
63 if (host->dma_ops && host->dma_ops->end) in tmio_mmc_end_dma()
64 host->dma_ops->end(host); in tmio_mmc_end_dma()
67 static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable) in tmio_mmc_enable_dma() argument
69 if (host->dma_ops) in tmio_mmc_enable_dma()
70 host->dma_ops->enable(host, enable); in tmio_mmc_enable_dma()
73 static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host, in tmio_mmc_request_dma() argument
76 if (host->dma_ops) { in tmio_mmc_request_dma()
77 host->dma_ops->request(host, pdata); in tmio_mmc_request_dma()
79 host->chan_tx = NULL; in tmio_mmc_request_dma()
80 host->chan_rx = NULL; in tmio_mmc_request_dma()
84 static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host) in tmio_mmc_release_dma() argument
86 if (host->dma_ops) in tmio_mmc_release_dma()
87 host->dma_ops->release(host); in tmio_mmc_release_dma()
90 static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host) in tmio_mmc_abort_dma() argument
92 if (host->dma_ops) in tmio_mmc_abort_dma()
93 host->dma_ops->abort(host); in tmio_mmc_abort_dma()
96 static inline void tmio_mmc_dataend_dma(struct tmio_mmc_host *host) in tmio_mmc_dataend_dma() argument
98 if (host->dma_ops) in tmio_mmc_dataend_dma()
99 host->dma_ops->dataend(host); in tmio_mmc_dataend_dma()
102 void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_enable_mmc_irqs() argument
104 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ); in tmio_mmc_enable_mmc_irqs()
105 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask); in tmio_mmc_enable_mmc_irqs()
109 void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_disable_mmc_irqs() argument
111 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ); in tmio_mmc_disable_mmc_irqs()
112 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask); in tmio_mmc_disable_mmc_irqs()
116 static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i) in tmio_mmc_ack_mmc_irqs() argument
118 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, ~i); in tmio_mmc_ack_mmc_irqs()
121 static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data) in tmio_mmc_init_sg() argument
123 host->sg_len = data->sg_len; in tmio_mmc_init_sg()
124 host->sg_ptr = data->sg; in tmio_mmc_init_sg()
125 host->sg_orig = data->sg; in tmio_mmc_init_sg()
126 host->sg_off = 0; in tmio_mmc_init_sg()
129 static int tmio_mmc_next_sg(struct tmio_mmc_host *host) in tmio_mmc_next_sg() argument
131 host->sg_ptr = sg_next(host->sg_ptr); in tmio_mmc_next_sg()
132 host->sg_off = 0; in tmio_mmc_next_sg()
133 return --host->sg_len; in tmio_mmc_next_sg()
140 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_enable_sdio_irq() local
142 if (enable && !host->sdio_irq_enabled) { in tmio_mmc_enable_sdio_irq()
148 host->sdio_irq_enabled = true; in tmio_mmc_enable_sdio_irq()
149 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ; in tmio_mmc_enable_sdio_irq()
152 sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS) & ~TMIO_SDIO_MASK_ALL; in tmio_mmc_enable_sdio_irq()
153 if (host->pdata->flags & TMIO_MMC_SDIO_STATUS_SETBITS) in tmio_mmc_enable_sdio_irq()
155 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status); in tmio_mmc_enable_sdio_irq()
157 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_enable_sdio_irq()
158 } else if (!enable && host->sdio_irq_enabled) { in tmio_mmc_enable_sdio_irq()
159 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL; in tmio_mmc_enable_sdio_irq()
160 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_enable_sdio_irq()
162 host->sdio_irq_enabled = false; in tmio_mmc_enable_sdio_irq()
168 static void tmio_mmc_set_bus_width(struct tmio_mmc_host *host, in tmio_mmc_set_bus_width() argument
171 u16 reg = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT) in tmio_mmc_set_bus_width()
180 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, reg); in tmio_mmc_set_bus_width()
183 static void tmio_mmc_reset(struct tmio_mmc_host *host, bool preserve) in tmio_mmc_reset() argument
188 card_opt = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT); in tmio_mmc_reset()
189 clk_ctrl = sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL); in tmio_mmc_reset()
190 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_reset()
191 sdif_mode = sd_ctrl_read16(host, CTL_SDIF_MODE); in tmio_mmc_reset()
195 sd_ctrl_write16(host, CTL_RESET_SD, 0x0000); in tmio_mmc_reset()
197 sd_ctrl_write16(host, CTL_RESET_SD, 0x0001); in tmio_mmc_reset()
200 tmio_mmc_abort_dma(host); in tmio_mmc_reset()
202 if (host->reset) in tmio_mmc_reset()
203 host->reset(host, preserve); in tmio_mmc_reset()
205 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask_all); in tmio_mmc_reset()
206 host->sdcard_irq_mask = host->sdcard_irq_mask_all; in tmio_mmc_reset()
208 if (host->native_hotplug) in tmio_mmc_reset()
209 tmio_mmc_enable_mmc_irqs(host, in tmio_mmc_reset()
212 tmio_mmc_set_bus_width(host, host->mmc->ios.bus_width); in tmio_mmc_reset()
214 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) { in tmio_mmc_reset()
215 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask); in tmio_mmc_reset()
216 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001); in tmio_mmc_reset()
220 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, card_opt); in tmio_mmc_reset()
221 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk_ctrl); in tmio_mmc_reset()
222 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_reset()
223 sd_ctrl_write16(host, CTL_SDIF_MODE, sdif_mode); in tmio_mmc_reset()
226 if (host->mmc->card) in tmio_mmc_reset()
227 mmc_retune_needed(host->mmc); in tmio_mmc_reset()
232 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host, in tmio_mmc_reset_work() local
237 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_reset_work()
238 mrq = host->mrq; in tmio_mmc_reset_work()
243 * us, so, have to check for IS_ERR(host->mrq) in tmio_mmc_reset_work()
246 time_is_after_jiffies(host->last_req_ts + in tmio_mmc_reset_work()
248 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_reset_work()
252 dev_warn(&host->pdev->dev, in tmio_mmc_reset_work()
256 if (host->data) in tmio_mmc_reset_work()
257 host->data->error = -ETIMEDOUT; in tmio_mmc_reset_work()
258 else if (host->cmd) in tmio_mmc_reset_work()
259 host->cmd->error = -ETIMEDOUT; in tmio_mmc_reset_work()
264 host->mrq = ERR_PTR(-EBUSY); in tmio_mmc_reset_work()
265 host->cmd = NULL; in tmio_mmc_reset_work()
266 host->data = NULL; in tmio_mmc_reset_work()
268 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_reset_work()
270 tmio_mmc_reset(host, true); in tmio_mmc_reset_work()
273 host->mrq = NULL; in tmio_mmc_reset_work()
274 mmc_request_done(host->mmc, mrq); in tmio_mmc_reset_work()
291 static int tmio_mmc_start_command(struct tmio_mmc_host *host, in tmio_mmc_start_command() argument
294 struct mmc_data *data = host->data; in tmio_mmc_start_command()
310 host->cmd = cmd; in tmio_mmc_start_command()
320 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, TMIO_STOP_SEC); in tmio_mmc_start_command()
327 if ((host->pdata->flags & TMIO_MMC_HAVE_CMD12_CTRL) && in tmio_mmc_start_command()
328 (cmd->opcode == SD_IO_RW_EXTENDED || host->mrq->sbc)) in tmio_mmc_start_command()
335 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_CMD); in tmio_mmc_start_command()
338 sd_ctrl_write32_as_16_and_16(host, CTL_ARG_REG, cmd->arg); in tmio_mmc_start_command()
339 sd_ctrl_write16(host, CTL_SD_CMD, c); in tmio_mmc_start_command()
344 static void tmio_mmc_transfer_data(struct tmio_mmc_host *host, in tmio_mmc_transfer_data() argument
348 int is_read = host->data->flags & MMC_DATA_READ; in tmio_mmc_transfer_data()
354 if (host->pdata->flags & TMIO_MMC_32BIT_DATA_PORT) { in tmio_mmc_transfer_data()
359 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, buf32, in tmio_mmc_transfer_data()
362 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, buf32, in tmio_mmc_transfer_data()
373 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, &data, 1); in tmio_mmc_transfer_data()
377 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, &data, 1); in tmio_mmc_transfer_data()
384 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1); in tmio_mmc_transfer_data()
386 sd_ctrl_write16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1); in tmio_mmc_transfer_data()
402 *buf8 = sd_ctrl_read16(host, CTL_SD_DATA_PORT) & 0xff; in tmio_mmc_transfer_data()
404 sd_ctrl_write16(host, CTL_SD_DATA_PORT, *buf8); in tmio_mmc_transfer_data()
412 static void tmio_mmc_pio_irq(struct tmio_mmc_host *host) in tmio_mmc_pio_irq() argument
414 struct mmc_data *data = host->data; in tmio_mmc_pio_irq()
419 if (host->dma_on) { in tmio_mmc_pio_irq()
427 sg_virt = kmap_local_page(sg_page(host->sg_ptr)); in tmio_mmc_pio_irq()
428 buf = (unsigned short *)(sg_virt + host->sg_ptr->offset + host->sg_off); in tmio_mmc_pio_irq()
430 count = host->sg_ptr->length - host->sg_off; in tmio_mmc_pio_irq()
435 count, host->sg_off, data->flags); in tmio_mmc_pio_irq()
438 tmio_mmc_transfer_data(host, buf, count); in tmio_mmc_pio_irq()
440 host->sg_off += count; in tmio_mmc_pio_irq()
444 if (host->sg_off == host->sg_ptr->length) in tmio_mmc_pio_irq()
445 tmio_mmc_next_sg(host); in tmio_mmc_pio_irq()
448 static void tmio_mmc_check_bounce_buffer(struct tmio_mmc_host *host) in tmio_mmc_check_bounce_buffer() argument
450 if (host->sg_ptr == &host->bounce_sg) { in tmio_mmc_check_bounce_buffer()
451 void *sg_virt = kmap_local_page(sg_page(host->sg_orig)); in tmio_mmc_check_bounce_buffer()
453 memcpy(sg_virt + host->sg_orig->offset, host->bounce_buf, in tmio_mmc_check_bounce_buffer()
454 host->bounce_sg.length); in tmio_mmc_check_bounce_buffer()
459 /* needs to be called with host->lock held */
460 void tmio_mmc_do_data_irq(struct tmio_mmc_host *host) in tmio_mmc_do_data_irq() argument
462 struct mmc_data *data = host->data; in tmio_mmc_do_data_irq()
465 host->data = NULL; in tmio_mmc_do_data_irq()
468 dev_warn(&host->pdev->dev, "Spurious data end IRQ\n"); in tmio_mmc_do_data_irq()
491 if (host->dma_on) in tmio_mmc_do_data_irq()
492 tmio_mmc_check_bounce_buffer(host); in tmio_mmc_do_data_irq()
493 dev_dbg(&host->pdev->dev, "Complete Rx request %p\n", in tmio_mmc_do_data_irq()
494 host->mrq); in tmio_mmc_do_data_irq()
496 dev_dbg(&host->pdev->dev, "Complete Tx request %p\n", in tmio_mmc_do_data_irq()
497 host->mrq); in tmio_mmc_do_data_irq()
500 if (stop && !host->mrq->sbc) { in tmio_mmc_do_data_irq()
502 dev_err(&host->pdev->dev, "unsupported stop: CMD%u,0x%x. We did CMD12,0\n", in tmio_mmc_do_data_irq()
506 stop->resp[0] = sd_ctrl_read16_and_16_as_32(host, CTL_RESPONSE); in tmio_mmc_do_data_irq()
508 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0); in tmio_mmc_do_data_irq()
511 schedule_work(&host->done); in tmio_mmc_do_data_irq()
515 static void tmio_mmc_data_irq(struct tmio_mmc_host *host, unsigned int stat) in tmio_mmc_data_irq() argument
519 spin_lock(&host->lock); in tmio_mmc_data_irq()
520 data = host->data; in tmio_mmc_data_irq()
530 if (host->dma_on && (data->flags & MMC_DATA_WRITE)) { in tmio_mmc_data_irq()
531 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); in tmio_mmc_data_irq()
542 if (host->pdata->flags & TMIO_MMC_HAS_IDLE_WAIT) { in tmio_mmc_data_irq()
551 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); in tmio_mmc_data_irq()
552 tmio_mmc_dataend_dma(host); in tmio_mmc_data_irq()
554 } else if (host->dma_on && (data->flags & MMC_DATA_READ)) { in tmio_mmc_data_irq()
555 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND); in tmio_mmc_data_irq()
556 tmio_mmc_dataend_dma(host); in tmio_mmc_data_irq()
558 tmio_mmc_do_data_irq(host); in tmio_mmc_data_irq()
559 tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP); in tmio_mmc_data_irq()
562 spin_unlock(&host->lock); in tmio_mmc_data_irq()
565 static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat) in tmio_mmc_cmd_irq() argument
567 struct mmc_command *cmd = host->cmd; in tmio_mmc_cmd_irq()
570 spin_lock(&host->lock); in tmio_mmc_cmd_irq()
572 if (!host->cmd) { in tmio_mmc_cmd_irq()
583 cmd->resp[i] = sd_ctrl_read16_and_16_as_32(host, addr); in tmio_mmc_cmd_irq()
605 if (host->data && (!cmd->error || cmd->error == -EILSEQ)) { in tmio_mmc_cmd_irq()
606 if (host->data->flags & MMC_DATA_READ) { in tmio_mmc_cmd_irq()
607 if (!host->dma_on) { in tmio_mmc_cmd_irq()
608 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP); in tmio_mmc_cmd_irq()
610 tmio_mmc_disable_mmc_irqs(host, in tmio_mmc_cmd_irq()
612 queue_work(system_bh_wq, &host->dma_issue); in tmio_mmc_cmd_irq()
615 if (!host->dma_on) { in tmio_mmc_cmd_irq()
616 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_WRITEOP); in tmio_mmc_cmd_irq()
618 tmio_mmc_disable_mmc_irqs(host, in tmio_mmc_cmd_irq()
620 queue_work(system_bh_wq, &host->dma_issue); in tmio_mmc_cmd_irq()
624 schedule_work(&host->done); in tmio_mmc_cmd_irq()
628 spin_unlock(&host->lock); in tmio_mmc_cmd_irq()
631 static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host, in __tmio_mmc_card_detect_irq() argument
634 struct mmc_host *mmc = host->mmc; in __tmio_mmc_card_detect_irq()
638 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT | in __tmio_mmc_card_detect_irq()
643 mmc_detect_change(host->mmc, msecs_to_jiffies(100)); in __tmio_mmc_card_detect_irq()
650 static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host, int ireg, in __tmio_mmc_sdcard_irq() argument
655 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CMDRESPEND | in __tmio_mmc_sdcard_irq()
657 tmio_mmc_cmd_irq(host, status); in __tmio_mmc_sdcard_irq()
663 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ); in __tmio_mmc_sdcard_irq()
664 tmio_mmc_pio_irq(host); in __tmio_mmc_sdcard_irq()
670 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND); in __tmio_mmc_sdcard_irq()
671 tmio_mmc_data_irq(host, status); in __tmio_mmc_sdcard_irq()
675 if (host->dma_ops && host->dma_ops->dma_irq && host->dma_ops->dma_irq(host)) in __tmio_mmc_sdcard_irq()
681 static bool __tmio_mmc_sdio_irq(struct tmio_mmc_host *host) in __tmio_mmc_sdio_irq() argument
683 struct mmc_host *mmc = host->mmc; in __tmio_mmc_sdio_irq()
684 struct tmio_mmc_data *pdata = host->pdata; in __tmio_mmc_sdio_irq()
691 status = sd_ctrl_read16(host, CTL_SDIO_STATUS); in __tmio_mmc_sdio_irq()
692 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdio_irq_mask; in __tmio_mmc_sdio_irq()
698 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status); in __tmio_mmc_sdio_irq()
708 struct tmio_mmc_host *host = devid; in tmio_mmc_irq() local
711 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS); in tmio_mmc_irq()
712 ireg = status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask; in tmio_mmc_irq()
715 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, TMIO_MASK_IRQ); in tmio_mmc_irq()
717 if (__tmio_mmc_card_detect_irq(host, ireg, status)) in tmio_mmc_irq()
719 if (__tmio_mmc_sdcard_irq(host, ireg, status)) in tmio_mmc_irq()
722 if (__tmio_mmc_sdio_irq(host)) in tmio_mmc_irq()
729 static int tmio_mmc_start_data(struct tmio_mmc_host *host, in tmio_mmc_start_data() argument
732 struct tmio_mmc_data *pdata = host->pdata; in tmio_mmc_start_data()
738 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4 || in tmio_mmc_start_data()
739 host->mmc->ios.bus_width == MMC_BUS_WIDTH_8) { in tmio_mmc_start_data()
744 mmc_hostname(host->mmc), data->blksz); in tmio_mmc_start_data()
749 tmio_mmc_init_sg(host, data); in tmio_mmc_start_data()
750 host->data = data; in tmio_mmc_start_data()
751 host->dma_on = false; in tmio_mmc_start_data()
754 sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz); in tmio_mmc_start_data()
755 if (host->mmc->max_blk_count >= SZ_64K) in tmio_mmc_start_data()
756 sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks); in tmio_mmc_start_data()
758 sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks); in tmio_mmc_start_data()
760 tmio_mmc_start_dma(host, data); in tmio_mmc_start_data()
765 static void tmio_process_mrq(struct tmio_mmc_host *host, in tmio_process_mrq() argument
771 if (mrq->sbc && host->cmd != mrq->sbc) { in tmio_process_mrq()
776 ret = tmio_mmc_start_data(host, mrq->data); in tmio_process_mrq()
782 ret = tmio_mmc_start_command(host, cmd); in tmio_process_mrq()
786 schedule_delayed_work(&host->delayed_reset_work, in tmio_process_mrq()
791 host->mrq = NULL; in tmio_process_mrq()
793 mmc_request_done(host->mmc, mrq); in tmio_process_mrq()
799 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_request() local
802 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_request()
804 if (host->mrq) { in tmio_mmc_request()
806 if (IS_ERR(host->mrq)) { in tmio_mmc_request()
807 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_request()
814 host->last_req_ts = jiffies; in tmio_mmc_request()
816 host->mrq = mrq; in tmio_mmc_request()
818 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_request()
820 tmio_process_mrq(host, mrq); in tmio_mmc_request()
823 static void tmio_mmc_finish_request(struct tmio_mmc_host *host) in tmio_mmc_finish_request() argument
828 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_finish_request()
830 tmio_mmc_end_dma(host); in tmio_mmc_finish_request()
832 mrq = host->mrq; in tmio_mmc_finish_request()
834 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_finish_request()
839 if (host->cmd != mrq->sbc) { in tmio_mmc_finish_request()
840 host->cmd = NULL; in tmio_mmc_finish_request()
841 host->data = NULL; in tmio_mmc_finish_request()
842 host->mrq = NULL; in tmio_mmc_finish_request()
845 cancel_delayed_work(&host->delayed_reset_work); in tmio_mmc_finish_request()
847 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_finish_request()
850 tmio_mmc_ack_mmc_irqs(host, TMIO_MASK_IRQ); /* Clear all */ in tmio_mmc_finish_request()
851 tmio_mmc_abort_dma(host); in tmio_mmc_finish_request()
855 if (host->check_retune && host->check_retune(host, mrq)) in tmio_mmc_finish_request()
856 mmc_retune_needed(host->mmc); in tmio_mmc_finish_request()
859 if (host->mrq && !mrq->cmd->error) { in tmio_mmc_finish_request()
860 tmio_process_mrq(host, mrq); in tmio_mmc_finish_request()
864 if (host->fixup_request) in tmio_mmc_finish_request()
865 host->fixup_request(host, mrq); in tmio_mmc_finish_request()
867 mmc_request_done(host->mmc, mrq); in tmio_mmc_finish_request()
872 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host, in tmio_mmc_done_work() local
874 tmio_mmc_finish_request(host); in tmio_mmc_done_work()
877 static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd) in tmio_mmc_power_on() argument
879 struct mmc_host *mmc = host->mmc; 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 static unsigned int tmio_mmc_get_timeout_cycles(struct tmio_mmc_host *host) in tmio_mmc_get_timeout_cycles() argument
920 u16 val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT); in tmio_mmc_get_timeout_cycles()
926 static void tmio_mmc_max_busy_timeout(struct tmio_mmc_host *host) in tmio_mmc_max_busy_timeout() argument
928 unsigned int clk_rate = host->mmc->actual_clock ?: host->mmc->f_max; in tmio_mmc_max_busy_timeout()
930 host->mmc->max_busy_timeout = host->get_timeout_cycles(host) / in tmio_mmc_max_busy_timeout()
942 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_set_ios() local
943 struct device *dev = &host->pdev->dev; in tmio_mmc_set_ios()
946 mutex_lock(&host->ios_lock); in tmio_mmc_set_ios()
948 spin_lock_irqsave(&host->lock, flags); in tmio_mmc_set_ios()
949 if (host->mrq) { in tmio_mmc_set_ios()
950 if (IS_ERR(host->mrq)) { in tmio_mmc_set_ios()
955 host->mrq = ERR_PTR(-EINTR); in tmio_mmc_set_ios()
960 host->mrq->cmd->opcode, host->last_req_ts, in tmio_mmc_set_ios()
963 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_set_ios()
965 mutex_unlock(&host->ios_lock); in tmio_mmc_set_ios()
970 host->mrq = ERR_PTR(-EBUSY); in tmio_mmc_set_ios()
972 spin_unlock_irqrestore(&host->lock, flags); in tmio_mmc_set_ios()
976 tmio_mmc_power_off(host); in tmio_mmc_set_ios()
978 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2) in tmio_mmc_set_ios()
979 tmio_mmc_reset(host, false); in tmio_mmc_set_ios()
981 host->set_clock(host, 0); in tmio_mmc_set_ios()
984 tmio_mmc_power_on(host, ios->vdd); in tmio_mmc_set_ios()
985 host->set_clock(host, ios->clock); in tmio_mmc_set_ios()
986 tmio_mmc_set_bus_width(host, ios->bus_width); in tmio_mmc_set_ios()
989 host->set_clock(host, ios->clock); in tmio_mmc_set_ios()
990 tmio_mmc_set_bus_width(host, ios->bus_width); in tmio_mmc_set_ios()
994 if (host->pdata->flags & TMIO_MMC_USE_BUSY_TIMEOUT) in tmio_mmc_set_ios()
995 tmio_mmc_max_busy_timeout(host); in tmio_mmc_set_ios()
999 if (PTR_ERR(host->mrq) == -EINTR) in tmio_mmc_set_ios()
1000 dev_dbg(&host->pdev->dev, in tmio_mmc_set_ios()
1006 host->mrq = NULL; in tmio_mmc_set_ios()
1007 host->clk_cache = ios->clock; in tmio_mmc_set_ios()
1009 mutex_unlock(&host->ios_lock); in tmio_mmc_set_ios()
1014 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_get_ro() local
1016 return !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & in tmio_mmc_get_ro()
1022 struct tmio_mmc_host *host = mmc_priv(mmc); in tmio_mmc_get_cd() local
1024 return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) & in tmio_mmc_get_cd()
1031 struct tmio_mmc_host *host = mmc_priv(card->host); in tmio_multi_io_quirk() local
1033 if (host->multi_io_quirk) in tmio_multi_io_quirk()
1034 return host->multi_io_quirk(card, direction, blk_size); in tmio_multi_io_quirk()
1048 static int tmio_mmc_init_ocr(struct tmio_mmc_host *host) in tmio_mmc_init_ocr() argument
1050 struct tmio_mmc_data *pdata = host->pdata; in tmio_mmc_init_ocr()
1051 struct mmc_host *mmc = host->mmc; in tmio_mmc_init_ocr()
1092 struct tmio_mmc_host *host; in tmio_mmc_host_alloc() local
1105 host = mmc_priv(mmc); in tmio_mmc_host_alloc()
1106 host->ctl = ctl; in tmio_mmc_host_alloc()
1107 host->mmc = mmc; in tmio_mmc_host_alloc()
1108 host->pdev = pdev; in tmio_mmc_host_alloc()
1109 host->pdata = pdata; in tmio_mmc_host_alloc()
1110 host->ops = tmio_mmc_ops; in tmio_mmc_host_alloc()
1111 mmc->ops = &host->ops; in tmio_mmc_host_alloc()
1113 ret = mmc_of_parse(host->mmc); in tmio_mmc_host_alloc()
1115 host = ERR_PTR(ret); in tmio_mmc_host_alloc()
1121 platform_set_drvdata(pdev, host); in tmio_mmc_host_alloc()
1123 return host; in tmio_mmc_host_alloc()
1127 return host; in tmio_mmc_host_alloc()
1131 void tmio_mmc_host_free(struct tmio_mmc_host *host) in tmio_mmc_host_free() argument
1133 mmc_free_host(host->mmc); in tmio_mmc_host_free()
1145 * Check the sanity of mmc->f_min to prevent host->set_clock() from in tmio_mmc_host_probe()
1240 void tmio_mmc_host_remove(struct tmio_mmc_host *host) in tmio_mmc_host_remove() argument
1242 struct platform_device *pdev = host->pdev; in tmio_mmc_host_remove()
1243 struct mmc_host *mmc = host->mmc; in tmio_mmc_host_remove()
1247 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) in tmio_mmc_host_remove()
1248 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000); in tmio_mmc_host_remove()
1253 cancel_work_sync(&host->done); in tmio_mmc_host_remove()
1254 cancel_delayed_work_sync(&host->delayed_reset_work); in tmio_mmc_host_remove()
1255 tmio_mmc_release_dma(host); in tmio_mmc_host_remove()
1256 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); in tmio_mmc_host_remove()
1258 if (host->native_hotplug) in tmio_mmc_host_remove()
1268 static int tmio_mmc_clk_enable(struct tmio_mmc_host *host) in tmio_mmc_clk_enable() argument
1270 if (!host->clk_enable) in tmio_mmc_clk_enable()
1273 return host->clk_enable(host); in tmio_mmc_clk_enable()
1276 static void tmio_mmc_clk_disable(struct tmio_mmc_host *host) in tmio_mmc_clk_disable() argument
1278 if (host->clk_disable) in tmio_mmc_clk_disable()
1279 host->clk_disable(host); in tmio_mmc_clk_disable()
1284 struct tmio_mmc_host *host = dev_get_drvdata(dev); in tmio_mmc_host_runtime_suspend() local
1286 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all); in tmio_mmc_host_runtime_suspend()
1288 if (host->clk_cache) in tmio_mmc_host_runtime_suspend()
1289 host->set_clock(host, 0); in tmio_mmc_host_runtime_suspend()
1291 tmio_mmc_clk_disable(host); in tmio_mmc_host_runtime_suspend()
1299 struct tmio_mmc_host *host = dev_get_drvdata(dev); in tmio_mmc_host_runtime_resume() local
1301 tmio_mmc_clk_enable(host); in tmio_mmc_host_runtime_resume()
1302 tmio_mmc_reset(host, false); in tmio_mmc_host_runtime_resume()
1304 if (host->clk_cache) in tmio_mmc_host_runtime_resume()
1305 host->set_clock(host, host->clk_cache); in tmio_mmc_host_runtime_resume()
1307 tmio_mmc_enable_dma(host, true); in tmio_mmc_host_runtime_resume()