Lines Matching full:host
48 #include <linux/mmc/host.h>
60 #define SDHSTS 0x20 /* SD host status - 11 R/W */
63 #define SDHCFG 0x38 /* Host configuration - 2 R/W */
64 #define SDHBCT 0x3c /* Host byte count (debug) - 32 R/W */
66 #define SDHBLC 0x50 /* Host block count (SDIO/SDHC) - 9 R/W */
192 static void bcm2835_dumpcmd(struct bcm2835_host *host, struct mmc_command *cmd, in bcm2835_dumpcmd() argument
195 struct device *dev = &host->pdev->dev; in bcm2835_dumpcmd()
201 (cmd == host->cmd) ? '>' : ' ', in bcm2835_dumpcmd()
207 static void bcm2835_dumpregs(struct bcm2835_host *host) in bcm2835_dumpregs() argument
209 struct mmc_request *mrq = host->mrq; in bcm2835_dumpregs()
210 struct device *dev = &host->pdev->dev; in bcm2835_dumpregs()
213 bcm2835_dumpcmd(host, mrq->sbc, "sbc"); in bcm2835_dumpregs()
214 bcm2835_dumpcmd(host, mrq->cmd, "cmd"); in bcm2835_dumpregs()
221 bcm2835_dumpcmd(host, mrq->stop, "stop"); in bcm2835_dumpregs()
225 dev_dbg(dev, "SDCMD 0x%08x\n", readl(host->ioaddr + SDCMD)); in bcm2835_dumpregs()
226 dev_dbg(dev, "SDARG 0x%08x\n", readl(host->ioaddr + SDARG)); in bcm2835_dumpregs()
227 dev_dbg(dev, "SDTOUT 0x%08x\n", readl(host->ioaddr + SDTOUT)); in bcm2835_dumpregs()
228 dev_dbg(dev, "SDCDIV 0x%08x\n", readl(host->ioaddr + SDCDIV)); in bcm2835_dumpregs()
229 dev_dbg(dev, "SDRSP0 0x%08x\n", readl(host->ioaddr + SDRSP0)); in bcm2835_dumpregs()
230 dev_dbg(dev, "SDRSP1 0x%08x\n", readl(host->ioaddr + SDRSP1)); in bcm2835_dumpregs()
231 dev_dbg(dev, "SDRSP2 0x%08x\n", readl(host->ioaddr + SDRSP2)); in bcm2835_dumpregs()
232 dev_dbg(dev, "SDRSP3 0x%08x\n", readl(host->ioaddr + SDRSP3)); in bcm2835_dumpregs()
233 dev_dbg(dev, "SDHSTS 0x%08x\n", readl(host->ioaddr + SDHSTS)); in bcm2835_dumpregs()
234 dev_dbg(dev, "SDVDD 0x%08x\n", readl(host->ioaddr + SDVDD)); in bcm2835_dumpregs()
235 dev_dbg(dev, "SDEDM 0x%08x\n", readl(host->ioaddr + SDEDM)); in bcm2835_dumpregs()
236 dev_dbg(dev, "SDHCFG 0x%08x\n", readl(host->ioaddr + SDHCFG)); in bcm2835_dumpregs()
237 dev_dbg(dev, "SDHBCT 0x%08x\n", readl(host->ioaddr + SDHBCT)); in bcm2835_dumpregs()
238 dev_dbg(dev, "SDHBLC 0x%08x\n", readl(host->ioaddr + SDHBLC)); in bcm2835_dumpregs()
242 static void bcm2835_reset_internal(struct bcm2835_host *host) in bcm2835_reset_internal() argument
246 writel(SDVDD_POWER_OFF, host->ioaddr + SDVDD); in bcm2835_reset_internal()
247 writel(0, host->ioaddr + SDCMD); in bcm2835_reset_internal()
248 writel(0, host->ioaddr + SDARG); in bcm2835_reset_internal()
249 writel(0xf00000, host->ioaddr + SDTOUT); in bcm2835_reset_internal()
250 writel(0, host->ioaddr + SDCDIV); in bcm2835_reset_internal()
251 writel(0x7f8, host->ioaddr + SDHSTS); /* Write 1s to clear */ in bcm2835_reset_internal()
252 writel(0, host->ioaddr + SDHCFG); in bcm2835_reset_internal()
253 writel(0, host->ioaddr + SDHBCT); in bcm2835_reset_internal()
254 writel(0, host->ioaddr + SDHBLC); in bcm2835_reset_internal()
257 temp = readl(host->ioaddr + SDEDM); in bcm2835_reset_internal()
262 writel(temp, host->ioaddr + SDEDM); in bcm2835_reset_internal()
264 writel(SDVDD_POWER_ON, host->ioaddr + SDVDD); in bcm2835_reset_internal()
266 host->clock = 0; in bcm2835_reset_internal()
267 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_reset_internal()
268 writel(host->cdiv, host->ioaddr + SDCDIV); in bcm2835_reset_internal()
273 struct bcm2835_host *host = mmc_priv(mmc); in bcm2835_reset() local
275 if (host->dma_chan) in bcm2835_reset()
276 dmaengine_terminate_sync(host->dma_chan); in bcm2835_reset()
277 host->dma_chan = NULL; in bcm2835_reset()
278 bcm2835_reset_internal(host); in bcm2835_reset()
281 static void bcm2835_finish_command(struct bcm2835_host *host);
283 static void bcm2835_wait_transfer_complete(struct bcm2835_host *host) in bcm2835_wait_transfer_complete() argument
288 alternate_idle = (host->mrq->data->flags & MMC_DATA_READ) ? in bcm2835_wait_transfer_complete()
296 edm = readl(host->ioaddr + SDEDM); in bcm2835_wait_transfer_complete()
304 host->ioaddr + SDEDM); in bcm2835_wait_transfer_complete()
310 dev_err(&host->pdev->dev, in bcm2835_wait_transfer_complete()
313 bcm2835_dumpregs(host); in bcm2835_wait_transfer_complete()
314 host->mrq->data->error = -ETIMEDOUT; in bcm2835_wait_transfer_complete()
323 struct bcm2835_host *host = param; in bcm2835_dma_complete() local
325 schedule_work(&host->dma_work); in bcm2835_dma_complete()
328 static void bcm2835_transfer_block_pio(struct bcm2835_host *host, bool is_read) in bcm2835_transfer_block_pio() argument
333 blksize = host->data->blksz; in bcm2835_transfer_block_pio()
343 if (!sg_miter_next(&host->sg_miter)) { in bcm2835_transfer_block_pio()
344 host->data->error = -EINVAL; in bcm2835_transfer_block_pio()
348 len = min(host->sg_miter.length, blksize); in bcm2835_transfer_block_pio()
350 host->data->error = -EINVAL; in bcm2835_transfer_block_pio()
355 host->sg_miter.consumed = len; in bcm2835_transfer_block_pio()
357 buf = (u32 *)host->sg_miter.addr; in bcm2835_transfer_block_pio()
366 edm = readl(host->ioaddr + SDEDM); in bcm2835_transfer_block_pio()
374 struct device *dev = &host->pdev->dev; in bcm2835_transfer_block_pio()
384 hsts = readl(host->ioaddr + SDHSTS); in bcm2835_transfer_block_pio()
399 host->ns_per_fifo_word); in bcm2835_transfer_block_pio()
409 *(buf++) = readl(host->ioaddr + SDDATA); in bcm2835_transfer_block_pio()
411 writel(*(buf++), host->ioaddr + SDDATA); in bcm2835_transfer_block_pio()
420 sg_miter_stop(&host->sg_miter); in bcm2835_transfer_block_pio()
423 static void bcm2835_transfer_pio(struct bcm2835_host *host) in bcm2835_transfer_pio() argument
425 struct device *dev = &host->pdev->dev; in bcm2835_transfer_pio()
429 is_read = (host->data->flags & MMC_DATA_READ) != 0; in bcm2835_transfer_pio()
430 bcm2835_transfer_block_pio(host, is_read); in bcm2835_transfer_pio()
432 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_transfer_pio()
438 host->data->error = -EILSEQ; in bcm2835_transfer_pio()
443 host->data->error = -ETIMEDOUT; in bcm2835_transfer_pio()
448 void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) in bcm2835_prepare_dma() argument
454 dma_chan = host->dma_chan_rxtx; in bcm2835_prepare_dma()
470 host->drain_words = 0; in bcm2835_prepare_dma()
483 host->drain_page = sg_page(sg); in bcm2835_prepare_dma()
484 host->drain_offset = sg->offset + sg->length; in bcm2835_prepare_dma()
487 host->drain_words = len / 4; in bcm2835_prepare_dma()
493 &host->dma_cfg_rx : in bcm2835_prepare_dma()
494 &host->dma_cfg_tx); in bcm2835_prepare_dma()
510 desc->callback_param = host; in bcm2835_prepare_dma()
511 host->dma_desc = desc; in bcm2835_prepare_dma()
512 host->dma_chan = dma_chan; in bcm2835_prepare_dma()
513 host->dma_dir = dir_data; in bcm2835_prepare_dma()
516 static void bcm2835_start_dma(struct bcm2835_host *host) in bcm2835_start_dma() argument
518 dmaengine_submit(host->dma_desc); in bcm2835_start_dma()
519 dma_async_issue_pending(host->dma_chan); in bcm2835_start_dma()
522 static void bcm2835_set_transfer_irqs(struct bcm2835_host *host) in bcm2835_set_transfer_irqs() argument
527 if (host->dma_desc) { in bcm2835_set_transfer_irqs()
528 host->hcfg = (host->hcfg & ~all_irqs) | in bcm2835_set_transfer_irqs()
531 host->hcfg = (host->hcfg & ~all_irqs) | in bcm2835_set_transfer_irqs()
536 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_set_transfer_irqs()
540 void bcm2835_prepare_data(struct bcm2835_host *host, struct mmc_command *cmd) in bcm2835_prepare_data() argument
544 WARN_ON(host->data); in bcm2835_prepare_data()
546 host->data = data; in bcm2835_prepare_data()
550 host->data_complete = false; in bcm2835_prepare_data()
551 host->data->bytes_xfered = 0; in bcm2835_prepare_data()
553 if (!host->dma_desc) { in bcm2835_prepare_data()
561 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); in bcm2835_prepare_data()
562 host->blocks = data->blocks; in bcm2835_prepare_data()
565 bcm2835_set_transfer_irqs(host); in bcm2835_prepare_data()
567 writel(data->blksz, host->ioaddr + SDHBCT); in bcm2835_prepare_data()
568 writel(data->blocks, host->ioaddr + SDHBLC); in bcm2835_prepare_data()
571 static u32 bcm2835_read_wait_sdcmd(struct bcm2835_host *host, u32 max_ms) in bcm2835_read_wait_sdcmd() argument
573 struct device *dev = &host->pdev->dev; in bcm2835_read_wait_sdcmd()
577 ret = readl_poll_timeout(host->ioaddr + SDCMD, value, in bcm2835_read_wait_sdcmd()
581 ret = readl_poll_timeout(host->ioaddr + SDCMD, value, in bcm2835_read_wait_sdcmd()
590 static void bcm2835_finish_request(struct bcm2835_host *host) in bcm2835_finish_request() argument
595 cancel_delayed_work(&host->timeout_work); in bcm2835_finish_request()
597 mrq = host->mrq; in bcm2835_finish_request()
599 host->mrq = NULL; in bcm2835_finish_request()
600 host->cmd = NULL; in bcm2835_finish_request()
601 host->data = NULL; in bcm2835_finish_request()
603 host->dma_desc = NULL; in bcm2835_finish_request()
604 terminate_chan = host->dma_chan; in bcm2835_finish_request()
605 host->dma_chan = NULL; in bcm2835_finish_request()
611 dev_err(&host->pdev->dev, in bcm2835_finish_request()
615 mmc_request_done(mmc_from_priv(host), mrq); in bcm2835_finish_request()
619 bool bcm2835_send_command(struct bcm2835_host *host, struct mmc_command *cmd) in bcm2835_send_command() argument
621 struct device *dev = &host->pdev->dev; in bcm2835_send_command()
625 WARN_ON(host->cmd); in bcm2835_send_command()
627 sdcmd = bcm2835_read_wait_sdcmd(host, 100); in bcm2835_send_command()
630 bcm2835_dumpregs(host); in bcm2835_send_command()
632 bcm2835_finish_request(host); in bcm2835_send_command()
640 schedule_delayed_work(&host->timeout_work, timeout); in bcm2835_send_command()
642 host->cmd = cmd; in bcm2835_send_command()
645 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_send_command()
647 writel(sdhsts, host->ioaddr + SDHSTS); in bcm2835_send_command()
652 bcm2835_finish_request(host); in bcm2835_send_command()
656 bcm2835_prepare_data(host, cmd); in bcm2835_send_command()
658 writel(cmd->arg, host->ioaddr + SDARG); in bcm2835_send_command()
662 host->use_busy = false; in bcm2835_send_command()
670 host->use_busy = true; in bcm2835_send_command()
681 writel(sdcmd | SDCMD_NEW_FLAG, host->ioaddr + SDCMD); in bcm2835_send_command()
686 static void bcm2835_transfer_complete(struct bcm2835_host *host) in bcm2835_transfer_complete() argument
690 WARN_ON(!host->data_complete); in bcm2835_transfer_complete()
692 data = host->data; in bcm2835_transfer_complete()
693 host->data = NULL; in bcm2835_transfer_complete()
699 if (host->mrq->stop && (data->error || !host->use_sbc)) { in bcm2835_transfer_complete()
700 if (bcm2835_send_command(host, host->mrq->stop)) { in bcm2835_transfer_complete()
702 if (!host->use_busy) in bcm2835_transfer_complete()
703 bcm2835_finish_command(host); in bcm2835_transfer_complete()
706 bcm2835_wait_transfer_complete(host); in bcm2835_transfer_complete()
707 bcm2835_finish_request(host); in bcm2835_transfer_complete()
711 static void bcm2835_finish_data(struct bcm2835_host *host) in bcm2835_finish_data() argument
713 struct device *dev = &host->pdev->dev; in bcm2835_finish_data()
716 data = host->data; in bcm2835_finish_data()
718 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN); in bcm2835_finish_data()
719 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_finish_data()
723 host->data_complete = true; in bcm2835_finish_data()
725 if (host->cmd) { in bcm2835_finish_data()
731 readl(host->ioaddr + SDHSTS)); in bcm2835_finish_data()
733 bcm2835_transfer_complete(host); in bcm2835_finish_data()
737 static void bcm2835_finish_command(struct bcm2835_host *host) in bcm2835_finish_command() argument
739 struct device *dev = &host->pdev->dev; in bcm2835_finish_command()
740 struct mmc_command *cmd = host->cmd; in bcm2835_finish_command()
743 sdcmd = bcm2835_read_wait_sdcmd(host, 100); in bcm2835_finish_command()
748 bcm2835_dumpregs(host); in bcm2835_finish_command()
749 host->cmd->error = -EIO; in bcm2835_finish_command()
750 bcm2835_finish_request(host); in bcm2835_finish_command()
753 u32 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_finish_command()
756 writel(SDHSTS_ERROR_MASK, host->ioaddr + SDHSTS); in bcm2835_finish_command()
759 (host->cmd->opcode != MMC_SEND_OP_COND)) { in bcm2835_finish_command()
763 host->cmd->error = -ETIMEDOUT; in bcm2835_finish_command()
766 host->cmd->opcode); in bcm2835_finish_command()
767 bcm2835_dumpregs(host); in bcm2835_finish_command()
768 host->cmd->error = -EILSEQ; in bcm2835_finish_command()
770 edm = readl(host->ioaddr + SDEDM); in bcm2835_finish_command()
776 host->ioaddr + SDEDM); in bcm2835_finish_command()
777 bcm2835_finish_request(host); in bcm2835_finish_command()
788 readl(host->ioaddr + SDRSP0 + i * 4); in bcm2835_finish_command()
791 cmd->resp[0] = readl(host->ioaddr + SDRSP0); in bcm2835_finish_command()
795 if (cmd == host->mrq->sbc) { in bcm2835_finish_command()
797 host->cmd = NULL; in bcm2835_finish_command()
798 if (bcm2835_send_command(host, host->mrq->cmd)) { in bcm2835_finish_command()
799 if (host->data && host->dma_desc) in bcm2835_finish_command()
803 bcm2835_start_dma(host); in bcm2835_finish_command()
805 if (!host->use_busy) in bcm2835_finish_command()
806 bcm2835_finish_command(host); in bcm2835_finish_command()
808 } else if (cmd == host->mrq->stop) { in bcm2835_finish_command()
810 bcm2835_finish_request(host); in bcm2835_finish_command()
813 host->cmd = NULL; in bcm2835_finish_command()
814 if (!host->data) in bcm2835_finish_command()
815 bcm2835_finish_request(host); in bcm2835_finish_command()
816 else if (host->data_complete) in bcm2835_finish_command()
817 bcm2835_transfer_complete(host); in bcm2835_finish_command()
824 struct bcm2835_host *host = in bcm2835_timeout() local
826 struct device *dev = &host->pdev->dev; in bcm2835_timeout()
828 mutex_lock(&host->mutex); in bcm2835_timeout()
830 if (host->mrq) { in bcm2835_timeout()
832 bcm2835_dumpregs(host); in bcm2835_timeout()
834 bcm2835_reset(mmc_from_priv(host)); in bcm2835_timeout()
836 if (host->data) { in bcm2835_timeout()
837 host->data->error = -ETIMEDOUT; in bcm2835_timeout()
838 bcm2835_finish_data(host); in bcm2835_timeout()
840 if (host->cmd) in bcm2835_timeout()
841 host->cmd->error = -ETIMEDOUT; in bcm2835_timeout()
843 host->mrq->cmd->error = -ETIMEDOUT; in bcm2835_timeout()
845 bcm2835_finish_request(host); in bcm2835_timeout()
849 mutex_unlock(&host->mutex); in bcm2835_timeout()
852 static bool bcm2835_check_cmd_error(struct bcm2835_host *host, u32 intmask) in bcm2835_check_cmd_error() argument
854 struct device *dev = &host->pdev->dev; in bcm2835_check_cmd_error()
859 if (!host->cmd) in bcm2835_check_cmd_error()
864 host->cmd->error = -EILSEQ; in bcm2835_check_cmd_error()
867 if (host->mrq->data) in bcm2835_check_cmd_error()
868 host->mrq->data->error = -EILSEQ; in bcm2835_check_cmd_error()
870 host->cmd->error = -EILSEQ; in bcm2835_check_cmd_error()
872 if (host->mrq->data) in bcm2835_check_cmd_error()
873 host->mrq->data->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
875 host->cmd->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
877 host->cmd->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
879 bcm2835_dumpregs(host); in bcm2835_check_cmd_error()
883 static void bcm2835_check_data_error(struct bcm2835_host *host, u32 intmask) in bcm2835_check_data_error() argument
885 if (!host->data) in bcm2835_check_data_error()
888 host->data->error = -EILSEQ; in bcm2835_check_data_error()
890 host->data->error = -ETIMEDOUT; in bcm2835_check_data_error()
893 static void bcm2835_busy_irq(struct bcm2835_host *host) in bcm2835_busy_irq() argument
895 if (WARN_ON(!host->cmd)) { in bcm2835_busy_irq()
896 bcm2835_dumpregs(host); in bcm2835_busy_irq()
900 if (WARN_ON(!host->use_busy)) { in bcm2835_busy_irq()
901 bcm2835_dumpregs(host); in bcm2835_busy_irq()
904 host->use_busy = false; in bcm2835_busy_irq()
906 bcm2835_finish_command(host); in bcm2835_busy_irq()
909 static void bcm2835_data_irq(struct bcm2835_host *host, u32 intmask) in bcm2835_data_irq() argument
917 if (!host->data) in bcm2835_data_irq()
920 bcm2835_check_data_error(host, intmask); in bcm2835_data_irq()
921 if (host->data->error) in bcm2835_data_irq()
924 if (host->data->flags & MMC_DATA_WRITE) { in bcm2835_data_irq()
926 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN); in bcm2835_data_irq()
927 host->hcfg |= SDHCFG_BLOCK_IRPT_EN; in bcm2835_data_irq()
928 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_data_irq()
929 bcm2835_transfer_pio(host); in bcm2835_data_irq()
931 bcm2835_transfer_pio(host); in bcm2835_data_irq()
932 host->blocks--; in bcm2835_data_irq()
933 if ((host->blocks == 0) || host->data->error) in bcm2835_data_irq()
939 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN); in bcm2835_data_irq()
940 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_data_irq()
943 static void bcm2835_data_threaded_irq(struct bcm2835_host *host) in bcm2835_data_threaded_irq() argument
945 if (!host->data) in bcm2835_data_threaded_irq()
947 if ((host->blocks == 0) || host->data->error) in bcm2835_data_threaded_irq()
948 bcm2835_finish_data(host); in bcm2835_data_threaded_irq()
951 static void bcm2835_block_irq(struct bcm2835_host *host) in bcm2835_block_irq() argument
953 if (WARN_ON(!host->data)) { in bcm2835_block_irq()
954 bcm2835_dumpregs(host); in bcm2835_block_irq()
958 if (!host->dma_desc) { in bcm2835_block_irq()
959 WARN_ON(!host->blocks); in bcm2835_block_irq()
960 if (host->data->error || (--host->blocks == 0)) in bcm2835_block_irq()
961 bcm2835_finish_data(host); in bcm2835_block_irq()
963 bcm2835_transfer_pio(host); in bcm2835_block_irq()
964 } else if (host->data->flags & MMC_DATA_WRITE) { in bcm2835_block_irq()
965 bcm2835_finish_data(host); in bcm2835_block_irq()
972 struct bcm2835_host *host = dev_id; in bcm2835_irq() local
975 spin_lock(&host->lock); in bcm2835_irq()
977 intmask = readl(host->ioaddr + SDHSTS); in bcm2835_irq()
983 host->ioaddr + SDHSTS); in bcm2835_irq()
986 bcm2835_check_data_error(host, intmask); in bcm2835_irq()
987 host->irq_block = true; in bcm2835_irq()
992 if (!bcm2835_check_cmd_error(host, intmask)) { in bcm2835_irq()
993 host->irq_busy = true; in bcm2835_irq()
1005 (host->hcfg & SDHCFG_DATA_IRPT_EN)) { in bcm2835_irq()
1006 bcm2835_data_irq(host, intmask); in bcm2835_irq()
1007 host->irq_data = true; in bcm2835_irq()
1011 spin_unlock(&host->lock); in bcm2835_irq()
1018 struct bcm2835_host *host = dev_id; in bcm2835_threaded_irq() local
1022 spin_lock_irqsave(&host->lock, flags); in bcm2835_threaded_irq()
1024 block = host->irq_block; in bcm2835_threaded_irq()
1025 busy = host->irq_busy; in bcm2835_threaded_irq()
1026 data = host->irq_data; in bcm2835_threaded_irq()
1027 host->irq_block = false; in bcm2835_threaded_irq()
1028 host->irq_busy = false; in bcm2835_threaded_irq()
1029 host->irq_data = false; in bcm2835_threaded_irq()
1031 spin_unlock_irqrestore(&host->lock, flags); in bcm2835_threaded_irq()
1033 mutex_lock(&host->mutex); in bcm2835_threaded_irq()
1036 bcm2835_block_irq(host); in bcm2835_threaded_irq()
1038 bcm2835_busy_irq(host); in bcm2835_threaded_irq()
1040 bcm2835_data_threaded_irq(host); in bcm2835_threaded_irq()
1042 mutex_unlock(&host->mutex); in bcm2835_threaded_irq()
1049 struct bcm2835_host *host = in bcm2835_dma_complete_work() local
1053 mutex_lock(&host->mutex); in bcm2835_dma_complete_work()
1055 data = host->data; in bcm2835_dma_complete_work()
1057 if (host->dma_chan) { in bcm2835_dma_complete_work()
1058 dma_unmap_sg(host->dma_chan->device->dev, in bcm2835_dma_complete_work()
1060 host->dma_dir); in bcm2835_dma_complete_work()
1062 host->dma_chan = NULL; in bcm2835_dma_complete_work()
1065 if (host->drain_words) { in bcm2835_dma_complete_work()
1069 if (host->drain_offset & PAGE_MASK) { in bcm2835_dma_complete_work()
1070 host->drain_page += host->drain_offset >> PAGE_SHIFT; in bcm2835_dma_complete_work()
1071 host->drain_offset &= ~PAGE_MASK; in bcm2835_dma_complete_work()
1073 page = kmap_local_page(host->drain_page); in bcm2835_dma_complete_work()
1074 buf = page + host->drain_offset; in bcm2835_dma_complete_work()
1076 while (host->drain_words) { in bcm2835_dma_complete_work()
1077 u32 edm = readl(host->ioaddr + SDEDM); in bcm2835_dma_complete_work()
1080 *(buf++) = readl(host->ioaddr + SDDATA); in bcm2835_dma_complete_work()
1081 host->drain_words--; in bcm2835_dma_complete_work()
1087 bcm2835_finish_data(host); in bcm2835_dma_complete_work()
1089 mutex_unlock(&host->mutex); in bcm2835_dma_complete_work()
1092 static void bcm2835_set_clock(struct bcm2835_host *host, unsigned int clock) in bcm2835_set_clock() argument
1094 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_set_clock()
1122 host->cdiv = SDCDIV_MAX_CDIV; in bcm2835_set_clock()
1123 writel(host->cdiv, host->ioaddr + SDCDIV); in bcm2835_set_clock()
1127 div = host->max_clk / clock; in bcm2835_set_clock()
1130 if ((host->max_clk / div) > clock) in bcm2835_set_clock()
1137 clock = host->max_clk / (div + 2); in bcm2835_set_clock()
1142 host->ns_per_fifo_word = (1000000000 / clock) * in bcm2835_set_clock()
1145 host->cdiv = div; in bcm2835_set_clock()
1146 writel(host->cdiv, host->ioaddr + SDCDIV); in bcm2835_set_clock()
1149 writel(mmc->actual_clock / 2, host->ioaddr + SDTOUT); in bcm2835_set_clock()
1154 struct bcm2835_host *host = mmc_priv(mmc); in bcm2835_request() local
1155 struct device *dev = &host->pdev->dev; in bcm2835_request()
1179 mutex_lock(&host->mutex); in bcm2835_request()
1181 WARN_ON(host->mrq); in bcm2835_request()
1182 host->mrq = mrq; in bcm2835_request()
1184 edm = readl(host->ioaddr + SDEDM); in bcm2835_request()
1190 readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK, in bcm2835_request()
1192 bcm2835_dumpregs(host); in bcm2835_request()
1197 bcm2835_finish_request(host); in bcm2835_request()
1198 mutex_unlock(&host->mutex); in bcm2835_request()
1202 if (host->use_dma && mrq->data && (mrq->data->blocks > PIO_THRESHOLD)) in bcm2835_request()
1203 bcm2835_prepare_dma(host, mrq->data); in bcm2835_request()
1205 host->use_sbc = !!mrq->sbc && host->mrq->data && in bcm2835_request()
1206 (host->mrq->data->flags & MMC_DATA_READ); in bcm2835_request()
1207 if (host->use_sbc) { in bcm2835_request()
1208 if (bcm2835_send_command(host, mrq->sbc)) { in bcm2835_request()
1209 if (!host->use_busy) in bcm2835_request()
1210 bcm2835_finish_command(host); in bcm2835_request()
1212 } else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) { in bcm2835_request()
1213 if (host->data && host->dma_desc) { in bcm2835_request()
1215 bcm2835_start_dma(host); in bcm2835_request()
1218 if (!host->use_busy) in bcm2835_request()
1219 bcm2835_finish_command(host); in bcm2835_request()
1222 mutex_unlock(&host->mutex); in bcm2835_request()
1227 struct bcm2835_host *host = mmc_priv(mmc); in bcm2835_set_ios() local
1229 mutex_lock(&host->mutex); in bcm2835_set_ios()
1231 if (!ios->clock || ios->clock != host->clock) { in bcm2835_set_ios()
1232 bcm2835_set_clock(host, ios->clock); in bcm2835_set_ios()
1233 host->clock = ios->clock; in bcm2835_set_ios()
1237 host->hcfg &= ~SDHCFG_WIDE_EXT_BUS; in bcm2835_set_ios()
1239 host->hcfg |= SDHCFG_WIDE_EXT_BUS; in bcm2835_set_ios()
1241 host->hcfg |= SDHCFG_WIDE_INT_BUS; in bcm2835_set_ios()
1244 host->hcfg |= SDHCFG_SLOW_CARD; in bcm2835_set_ios()
1246 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_set_ios()
1248 mutex_unlock(&host->mutex); in bcm2835_set_ios()
1257 static int bcm2835_add_host(struct bcm2835_host *host) in bcm2835_add_host() argument
1259 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_add_host()
1260 struct device *dev = &host->pdev->dev; in bcm2835_add_host()
1264 if (!mmc->f_max || mmc->f_max > host->max_clk) in bcm2835_add_host()
1265 mmc->f_max = host->max_clk; in bcm2835_add_host()
1266 mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV; in bcm2835_add_host()
1273 /* host controller capabilities */ in bcm2835_add_host()
1277 spin_lock_init(&host->lock); in bcm2835_add_host()
1278 mutex_init(&host->mutex); in bcm2835_add_host()
1280 if (!host->dma_chan_rxtx) { in bcm2835_add_host()
1282 host->use_dma = false; in bcm2835_add_host()
1284 host->use_dma = true; in bcm2835_add_host()
1286 host->dma_cfg_tx.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1287 host->dma_cfg_tx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1288 host->dma_cfg_tx.direction = DMA_MEM_TO_DEV; in bcm2835_add_host()
1289 host->dma_cfg_tx.src_addr = 0; in bcm2835_add_host()
1290 host->dma_cfg_tx.dst_addr = host->phys_addr + SDDATA; in bcm2835_add_host()
1292 host->dma_cfg_rx.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1293 host->dma_cfg_rx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1294 host->dma_cfg_rx.direction = DMA_DEV_TO_MEM; in bcm2835_add_host()
1295 host->dma_cfg_rx.src_addr = host->phys_addr + SDDATA; in bcm2835_add_host()
1296 host->dma_cfg_rx.dst_addr = 0; in bcm2835_add_host()
1298 if (dmaengine_slave_config(host->dma_chan_rxtx, in bcm2835_add_host()
1299 &host->dma_cfg_tx) != 0 || in bcm2835_add_host()
1300 dmaengine_slave_config(host->dma_chan_rxtx, in bcm2835_add_host()
1301 &host->dma_cfg_rx) != 0) in bcm2835_add_host()
1302 host->use_dma = false; in bcm2835_add_host()
1314 INIT_WORK(&host->dma_work, bcm2835_dma_complete_work); in bcm2835_add_host()
1315 INIT_DELAYED_WORK(&host->timeout_work, bcm2835_timeout); in bcm2835_add_host()
1318 host->hcfg = SDHCFG_BUSY_IRPT_EN; in bcm2835_add_host()
1320 bcm2835_reset_internal(host); in bcm2835_add_host()
1322 ret = request_threaded_irq(host->irq, bcm2835_irq, in bcm2835_add_host()
1324 0, mmc_hostname(mmc), host); in bcm2835_add_host()
1326 dev_err(dev, "failed to request IRQ %d: %d\n", host->irq, ret); in bcm2835_add_host()
1332 free_irq(host->irq, host); in bcm2835_add_host()
1337 if (host->use_dma && (PIO_THRESHOLD > 0)) in bcm2835_add_host()
1340 host->use_dma ? "enabled" : "disabled", pio_limit_string); in bcm2835_add_host()
1349 struct bcm2835_host *host; in bcm2835_probe() local
1355 mmc = mmc_alloc_host(sizeof(*host), dev); in bcm2835_probe()
1360 host = mmc_priv(mmc); in bcm2835_probe()
1361 host->pdev = pdev; in bcm2835_probe()
1362 spin_lock_init(&host->lock); in bcm2835_probe()
1364 host->ioaddr = devm_platform_ioremap_resource(pdev, 0); in bcm2835_probe()
1365 if (IS_ERR(host->ioaddr)) { in bcm2835_probe()
1366 ret = PTR_ERR(host->ioaddr); in bcm2835_probe()
1380 host->phys_addr = be32_to_cpup(regaddr_p); in bcm2835_probe()
1382 host->dma_chan = NULL; in bcm2835_probe()
1383 host->dma_desc = NULL; in bcm2835_probe()
1385 host->dma_chan_rxtx = dma_request_chan(dev, "rx-tx"); in bcm2835_probe()
1386 if (IS_ERR(host->dma_chan_rxtx)) { in bcm2835_probe()
1387 ret = PTR_ERR(host->dma_chan_rxtx); in bcm2835_probe()
1388 host->dma_chan_rxtx = NULL; in bcm2835_probe()
1403 host->max_clk = clk_get_rate(clk); in bcm2835_probe()
1405 host->irq = platform_get_irq(pdev, 0); in bcm2835_probe()
1406 if (host->irq < 0) { in bcm2835_probe()
1407 ret = host->irq; in bcm2835_probe()
1415 ret = bcm2835_add_host(host); in bcm2835_probe()
1419 platform_set_drvdata(pdev, host); in bcm2835_probe()
1427 if (host->dma_chan_rxtx) in bcm2835_probe()
1428 dma_release_channel(host->dma_chan_rxtx); in bcm2835_probe()
1436 struct bcm2835_host *host = platform_get_drvdata(pdev); in bcm2835_remove() local
1437 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_remove()
1441 writel(SDVDD_POWER_OFF, host->ioaddr + SDVDD); in bcm2835_remove()
1443 free_irq(host->irq, host); in bcm2835_remove()
1445 cancel_work_sync(&host->dma_work); in bcm2835_remove()
1446 cancel_delayed_work_sync(&host->timeout_work); in bcm2835_remove()
1448 if (host->dma_chan_rxtx) in bcm2835_remove()
1449 dma_release_channel(host->dma_chan_rxtx); in bcm2835_remove()