Lines Matching refs:host

36 #include <linux/mmc/host.h>
53 static inline void tmio_mmc_start_dma(struct tmio_mmc_host *host,
56 if (host->dma_ops)
57 host->dma_ops->start(host, data);
60 static inline void tmio_mmc_end_dma(struct tmio_mmc_host *host)
62 if (host->dma_ops && host->dma_ops->end)
63 host->dma_ops->end(host);
66 static inline void tmio_mmc_enable_dma(struct tmio_mmc_host *host, bool enable)
68 if (host->dma_ops)
69 host->dma_ops->enable(host, enable);
72 static inline void tmio_mmc_request_dma(struct tmio_mmc_host *host,
75 if (host->dma_ops) {
76 host->dma_ops->request(host, pdata);
78 host->chan_tx = NULL;
79 host->chan_rx = NULL;
83 static inline void tmio_mmc_release_dma(struct tmio_mmc_host *host)
85 if (host->dma_ops)
86 host->dma_ops->release(host);
89 static inline void tmio_mmc_abort_dma(struct tmio_mmc_host *host)
91 if (host->dma_ops)
92 host->dma_ops->abort(host);
95 static inline void tmio_mmc_dataend_dma(struct tmio_mmc_host *host)
97 if (host->dma_ops)
98 host->dma_ops->dataend(host);
101 void tmio_mmc_enable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
103 host->sdcard_irq_mask &= ~(i & TMIO_MASK_IRQ);
104 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
108 void tmio_mmc_disable_mmc_irqs(struct tmio_mmc_host *host, u32 i)
110 host->sdcard_irq_mask |= (i & TMIO_MASK_IRQ);
111 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask);
115 static void tmio_mmc_ack_mmc_irqs(struct tmio_mmc_host *host, u32 i)
117 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, ~i);
120 static void tmio_mmc_init_sg(struct tmio_mmc_host *host, struct mmc_data *data)
122 host->sg_len = data->sg_len;
123 host->sg_ptr = data->sg;
124 host->sg_orig = data->sg;
125 host->sg_off = 0;
128 static int tmio_mmc_next_sg(struct tmio_mmc_host *host)
130 host->sg_ptr = sg_next(host->sg_ptr);
131 host->sg_off = 0;
132 return --host->sg_len;
139 struct tmio_mmc_host *host = mmc_priv(mmc);
141 if (enable && !host->sdio_irq_enabled) {
147 host->sdio_irq_enabled = true;
148 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL & ~TMIO_SDIO_STAT_IOIRQ;
151 sdio_status = sd_ctrl_read16(host, CTL_SDIO_STATUS) & ~TMIO_SDIO_MASK_ALL;
152 if (host->pdata->flags & TMIO_MMC_SDIO_STATUS_SETBITS)
154 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status);
156 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
157 } else if (!enable && host->sdio_irq_enabled) {
158 host->sdio_irq_mask = TMIO_SDIO_MASK_ALL;
159 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
161 host->sdio_irq_enabled = false;
167 static void tmio_mmc_set_bus_width(struct tmio_mmc_host *host,
170 u16 reg = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT)
179 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, reg);
182 static void tmio_mmc_reset(struct tmio_mmc_host *host, bool preserve)
187 card_opt = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT);
188 clk_ctrl = sd_ctrl_read16(host, CTL_SD_CARD_CLK_CTL);
189 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2)
190 sdif_mode = sd_ctrl_read16(host, CTL_SDIF_MODE);
194 sd_ctrl_write16(host, CTL_RESET_SD, 0x0000);
196 sd_ctrl_write16(host, CTL_RESET_SD, 0x0001);
199 tmio_mmc_abort_dma(host);
201 if (host->reset)
202 host->reset(host, preserve);
204 sd_ctrl_write32_as_16_and_16(host, CTL_IRQ_MASK, host->sdcard_irq_mask_all);
205 host->sdcard_irq_mask = host->sdcard_irq_mask_all;
207 if (host->native_hotplug)
208 tmio_mmc_enable_mmc_irqs(host,
211 tmio_mmc_set_bus_width(host, host->mmc->ios.bus_width);
213 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ) {
214 sd_ctrl_write16(host, CTL_SDIO_IRQ_MASK, host->sdio_irq_mask);
215 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0001);
219 sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, card_opt);
220 sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, clk_ctrl);
221 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2)
222 sd_ctrl_write16(host, CTL_SDIF_MODE, sdif_mode);
225 if (host->mmc->card)
226 mmc_retune_needed(host->mmc);
231 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host,
236 spin_lock_irqsave(&host->lock, flags);
237 mrq = host->mrq;
242 * us, so, have to check for IS_ERR(host->mrq)
245 time_is_after_jiffies(host->last_req_ts +
247 spin_unlock_irqrestore(&host->lock, flags);
251 dev_warn(&host->pdev->dev,
255 if (host->data)
256 host->data->error = -ETIMEDOUT;
257 else if (host->cmd)
258 host->cmd->error = -ETIMEDOUT;
263 host->mrq = ERR_PTR(-EBUSY);
264 host->cmd = NULL;
265 host->data = NULL;
267 spin_unlock_irqrestore(&host->lock, flags);
269 tmio_mmc_reset(host, true);
272 host->mrq = NULL;
273 mmc_request_done(host->mmc, mrq);
290 static int tmio_mmc_start_command(struct tmio_mmc_host *host,
293 struct mmc_data *data = host->data;
309 host->cmd = cmd;
319 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, TMIO_STOP_SEC);
326 if ((host->pdata->flags & TMIO_MMC_HAVE_CMD12_CTRL) &&
327 (cmd->opcode == SD_IO_RW_EXTENDED || host->mrq->sbc))
334 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_CMD);
337 sd_ctrl_write32_as_16_and_16(host, CTL_ARG_REG, cmd->arg);
338 sd_ctrl_write16(host, CTL_SD_CMD, c);
343 static void tmio_mmc_transfer_data(struct tmio_mmc_host *host,
347 int is_read = host->data->flags & MMC_DATA_READ;
353 if (host->pdata->flags & TMIO_MMC_32BIT_DATA_PORT) {
358 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, buf32,
361 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, buf32,
372 sd_ctrl_read32_rep(host, CTL_SD_DATA_PORT, &data, 1);
376 sd_ctrl_write32_rep(host, CTL_SD_DATA_PORT, &data, 1);
383 sd_ctrl_read16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
385 sd_ctrl_write16_rep(host, CTL_SD_DATA_PORT, buf, count >> 1);
401 *buf8 = sd_ctrl_read16(host, CTL_SD_DATA_PORT) & 0xff;
403 sd_ctrl_write16(host, CTL_SD_DATA_PORT, *buf8);
411 static void tmio_mmc_pio_irq(struct tmio_mmc_host *host)
413 struct mmc_data *data = host->data;
418 if (host->dma_on) {
426 sg_virt = kmap_local_page(sg_page(host->sg_ptr));
427 buf = (unsigned short *)(sg_virt + host->sg_ptr->offset + host->sg_off);
429 count = host->sg_ptr->length - host->sg_off;
434 count, host->sg_off, data->flags);
437 tmio_mmc_transfer_data(host, buf, count);
439 host->sg_off += count;
443 if (host->sg_off == host->sg_ptr->length)
444 tmio_mmc_next_sg(host);
447 static void tmio_mmc_check_bounce_buffer(struct tmio_mmc_host *host)
449 if (host->sg_ptr == &host->bounce_sg) {
450 void *sg_virt = kmap_local_page(sg_page(host->sg_orig));
452 memcpy(sg_virt + host->sg_orig->offset, host->bounce_buf,
453 host->bounce_sg.length);
458 /* needs to be called with host->lock held */
459 void tmio_mmc_do_data_irq(struct tmio_mmc_host *host)
461 struct mmc_data *data = host->data;
464 host->data = NULL;
467 dev_warn(&host->pdev->dev, "Spurious data end IRQ\n");
490 if (host->dma_on)
491 tmio_mmc_check_bounce_buffer(host);
492 dev_dbg(&host->pdev->dev, "Complete Rx request %p\n",
493 host->mrq);
495 dev_dbg(&host->pdev->dev, "Complete Tx request %p\n",
496 host->mrq);
499 if (stop && !host->mrq->sbc) {
501 dev_err(&host->pdev->dev, "unsupported stop: CMD%u,0x%x. We did CMD12,0\n",
505 stop->resp[0] = sd_ctrl_read16_and_16_as_32(host, CTL_RESPONSE);
507 sd_ctrl_write16(host, CTL_STOP_INTERNAL_ACTION, 0);
510 schedule_work(&host->done);
514 static void tmio_mmc_data_irq(struct tmio_mmc_host *host, unsigned int stat)
518 spin_lock(&host->lock);
519 data = host->data;
529 if (host->dma_on && (data->flags & MMC_DATA_WRITE)) {
530 u32 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS);
541 if (host->pdata->flags & TMIO_MMC_HAS_IDLE_WAIT) {
550 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
551 tmio_mmc_dataend_dma(host);
553 } else if (host->dma_on && (data->flags & MMC_DATA_READ)) {
554 tmio_mmc_disable_mmc_irqs(host, TMIO_STAT_DATAEND);
555 tmio_mmc_dataend_dma(host);
557 tmio_mmc_do_data_irq(host);
558 tmio_mmc_disable_mmc_irqs(host, TMIO_MASK_READOP | TMIO_MASK_WRITEOP);
561 spin_unlock(&host->lock);
564 static void tmio_mmc_cmd_irq(struct tmio_mmc_host *host, unsigned int stat)
566 struct mmc_command *cmd = host->cmd;
569 spin_lock(&host->lock);
571 if (!host->cmd) {
582 cmd->resp[i] = sd_ctrl_read16_and_16_as_32(host, addr);
604 if (host->data && (!cmd->error || cmd->error == -EILSEQ)) {
605 if (host->data->flags & MMC_DATA_READ) {
606 if (!host->dma_on) {
607 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_READOP);
609 tmio_mmc_disable_mmc_irqs(host,
611 tasklet_schedule(&host->dma_issue);
614 if (!host->dma_on) {
615 tmio_mmc_enable_mmc_irqs(host, TMIO_MASK_WRITEOP);
617 tmio_mmc_disable_mmc_irqs(host,
619 tasklet_schedule(&host->dma_issue);
623 schedule_work(&host->done);
627 spin_unlock(&host->lock);
630 static bool __tmio_mmc_card_detect_irq(struct tmio_mmc_host *host,
633 struct mmc_host *mmc = host->mmc;
637 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CARD_INSERT |
642 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
649 static bool __tmio_mmc_sdcard_irq(struct tmio_mmc_host *host, int ireg,
654 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_CMDRESPEND |
656 tmio_mmc_cmd_irq(host, status);
662 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_RXRDY | TMIO_STAT_TXRQ);
663 tmio_mmc_pio_irq(host);
669 tmio_mmc_ack_mmc_irqs(host, TMIO_STAT_DATAEND);
670 tmio_mmc_data_irq(host, status);
674 if (host->dma_ops && host->dma_ops->dma_irq && host->dma_ops->dma_irq(host))
680 static bool __tmio_mmc_sdio_irq(struct tmio_mmc_host *host)
682 struct mmc_host *mmc = host->mmc;
683 struct tmio_mmc_data *pdata = host->pdata;
690 status = sd_ctrl_read16(host, CTL_SDIO_STATUS);
691 ireg = status & TMIO_SDIO_MASK_ALL & ~host->sdio_irq_mask;
697 sd_ctrl_write16(host, CTL_SDIO_STATUS, sdio_status);
707 struct tmio_mmc_host *host = devid;
710 status = sd_ctrl_read16_and_16_as_32(host, CTL_STATUS);
711 ireg = status & TMIO_MASK_IRQ & ~host->sdcard_irq_mask;
714 sd_ctrl_write32_as_16_and_16(host, CTL_STATUS, TMIO_MASK_IRQ);
716 if (__tmio_mmc_card_detect_irq(host, ireg, status))
718 if (__tmio_mmc_sdcard_irq(host, ireg, status))
721 if (__tmio_mmc_sdio_irq(host))
728 static int tmio_mmc_start_data(struct tmio_mmc_host *host,
731 struct tmio_mmc_data *pdata = host->pdata;
737 if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4 ||
738 host->mmc->ios.bus_width == MMC_BUS_WIDTH_8) {
743 mmc_hostname(host->mmc), data->blksz);
748 tmio_mmc_init_sg(host, data);
749 host->data = data;
750 host->dma_on = false;
753 sd_ctrl_write16(host, CTL_SD_XFER_LEN, data->blksz);
754 if (host->mmc->max_blk_count >= SZ_64K)
755 sd_ctrl_write32(host, CTL_XFER_BLK_COUNT, data->blocks);
757 sd_ctrl_write16(host, CTL_XFER_BLK_COUNT, data->blocks);
759 tmio_mmc_start_dma(host, data);
764 static void tmio_process_mrq(struct tmio_mmc_host *host,
770 if (mrq->sbc && host->cmd != mrq->sbc) {
775 ret = tmio_mmc_start_data(host, mrq->data);
781 ret = tmio_mmc_start_command(host, cmd);
785 schedule_delayed_work(&host->delayed_reset_work,
790 host->mrq = NULL;
792 mmc_request_done(host->mmc, mrq);
798 struct tmio_mmc_host *host = mmc_priv(mmc);
801 spin_lock_irqsave(&host->lock, flags);
803 if (host->mrq) {
805 if (IS_ERR(host->mrq)) {
806 spin_unlock_irqrestore(&host->lock, flags);
813 host->last_req_ts = jiffies;
815 host->mrq = mrq;
817 spin_unlock_irqrestore(&host->lock, flags);
819 tmio_process_mrq(host, mrq);
822 static void tmio_mmc_finish_request(struct tmio_mmc_host *host)
827 spin_lock_irqsave(&host->lock, flags);
829 tmio_mmc_end_dma(host);
831 mrq = host->mrq;
833 spin_unlock_irqrestore(&host->lock, flags);
838 if (host->cmd != mrq->sbc) {
839 host->cmd = NULL;
840 host->data = NULL;
841 host->mrq = NULL;
844 cancel_delayed_work(&host->delayed_reset_work);
846 spin_unlock_irqrestore(&host->lock, flags);
849 tmio_mmc_ack_mmc_irqs(host, TMIO_MASK_IRQ); /* Clear all */
850 tmio_mmc_abort_dma(host);
854 if (host->check_retune && host->check_retune(host, mrq))
855 mmc_retune_needed(host->mmc);
858 if (host->mrq && !mrq->cmd->error) {
859 tmio_process_mrq(host, mrq);
863 if (host->fixup_request)
864 host->fixup_request(host, mrq);
866 mmc_request_done(host->mmc, mrq);
871 struct tmio_mmc_host *host = container_of(work, struct tmio_mmc_host,
873 tmio_mmc_finish_request(host);
876 static void tmio_mmc_power_on(struct tmio_mmc_host *host, unsigned short vdd)
878 struct mmc_host *mmc = host->mmc;
883 if (host->set_pwr)
884 host->set_pwr(host->pdev, 1);
906 dev_dbg(&host->pdev->dev, "Regulators failed to power up: %d\n",
910 static void tmio_mmc_power_off(struct tmio_mmc_host *host)
912 struct mmc_host *mmc = host->mmc;
920 if (host->set_pwr)
921 host->set_pwr(host->pdev, 0);
924 static unsigned int tmio_mmc_get_timeout_cycles(struct tmio_mmc_host *host)
926 u16 val = sd_ctrl_read16(host, CTL_SD_MEM_CARD_OPT);
932 static void tmio_mmc_max_busy_timeout(struct tmio_mmc_host *host)
934 unsigned int clk_rate = host->mmc->actual_clock ?: host->mmc->f_max;
936 host->mmc->max_busy_timeout = host->get_timeout_cycles(host) /
948 struct tmio_mmc_host *host = mmc_priv(mmc);
949 struct device *dev = &host->pdev->dev;
952 mutex_lock(&host->ios_lock);
954 spin_lock_irqsave(&host->lock, flags);
955 if (host->mrq) {
956 if (IS_ERR(host->mrq)) {
961 host->mrq = ERR_PTR(-EINTR);
966 host->mrq->cmd->opcode, host->last_req_ts,
969 spin_unlock_irqrestore(&host->lock, flags);
971 mutex_unlock(&host->ios_lock);
976 host->mrq = ERR_PTR(-EBUSY);
978 spin_unlock_irqrestore(&host->lock, flags);
982 tmio_mmc_power_off(host);
984 if (host->pdata->flags & TMIO_MMC_MIN_RCAR2)
985 tmio_mmc_reset(host, false);
987 host->set_clock(host, 0);
990 tmio_mmc_power_on(host, ios->vdd);
991 host->set_clock(host, ios->clock);
992 tmio_mmc_set_bus_width(host, ios->bus_width);
995 host->set_clock(host, ios->clock);
996 tmio_mmc_set_bus_width(host, ios->bus_width);
1000 if (host->pdata->flags & TMIO_MMC_USE_BUSY_TIMEOUT)
1001 tmio_mmc_max_busy_timeout(host);
1005 if (PTR_ERR(host->mrq) == -EINTR)
1006 dev_dbg(&host->pdev->dev,
1012 host->mrq = NULL;
1013 host->clk_cache = ios->clock;
1015 mutex_unlock(&host->ios_lock);
1020 struct tmio_mmc_host *host = mmc_priv(mmc);
1022 return !(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) &
1028 struct tmio_mmc_host *host = mmc_priv(mmc);
1030 return !!(sd_ctrl_read16_and_16_as_32(host, CTL_STATUS) &
1037 struct tmio_mmc_host *host = mmc_priv(card->host);
1039 if (host->multi_io_quirk)
1040 return host->multi_io_quirk(card, direction, blk_size);
1054 static int tmio_mmc_init_ocr(struct tmio_mmc_host *host)
1056 struct tmio_mmc_data *pdata = host->pdata;
1057 struct mmc_host *mmc = host->mmc;
1098 struct tmio_mmc_host *host;
1111 host = mmc_priv(mmc);
1112 host->ctl = ctl;
1113 host->mmc = mmc;
1114 host->pdev = pdev;
1115 host->pdata = pdata;
1116 host->ops = tmio_mmc_ops;
1117 mmc->ops = &host->ops;
1119 ret = mmc_of_parse(host->mmc);
1121 host = ERR_PTR(ret);
1127 platform_set_drvdata(pdev, host);
1129 return host;
1133 return host;
1137 void tmio_mmc_host_free(struct tmio_mmc_host *host)
1139 mmc_free_host(host->mmc);
1151 * Check the sanity of mmc->f_min to prevent host->set_clock() from
1248 void tmio_mmc_host_remove(struct tmio_mmc_host *host)
1250 struct platform_device *pdev = host->pdev;
1251 struct mmc_host *mmc = host->mmc;
1255 if (host->pdata->flags & TMIO_MMC_SDIO_IRQ)
1256 sd_ctrl_write16(host, CTL_TRANSACTION_CTL, 0x0000);
1261 cancel_work_sync(&host->done);
1262 cancel_delayed_work_sync(&host->delayed_reset_work);
1263 tmio_mmc_release_dma(host);
1264 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all);
1266 if (host->native_hotplug)
1276 static int tmio_mmc_clk_enable(struct tmio_mmc_host *host)
1278 if (!host->clk_enable)
1281 return host->clk_enable(host);
1284 static void tmio_mmc_clk_disable(struct tmio_mmc_host *host)
1286 if (host->clk_disable)
1287 host->clk_disable(host);
1292 struct tmio_mmc_host *host = dev_get_drvdata(dev);
1294 tmio_mmc_disable_mmc_irqs(host, host->sdcard_irq_mask_all);
1296 if (host->clk_cache)
1297 host->set_clock(host, 0);
1299 tmio_mmc_clk_disable(host);
1307 struct tmio_mmc_host *host = dev_get_drvdata(dev);
1309 tmio_mmc_clk_enable(host);
1310 tmio_mmc_reset(host, false);
1312 if (host->clk_cache)
1313 host->set_clock(host, host->clk_cache);
1315 tmio_mmc_enable_dma(host, true);