Lines Matching refs:host

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
334 blksize = host->data->blksz; in bcm2835_transfer_block_pio()
346 if (!sg_miter_next(&host->sg_miter)) { in bcm2835_transfer_block_pio()
347 host->data->error = -EINVAL; in bcm2835_transfer_block_pio()
351 len = min(host->sg_miter.length, blksize); in bcm2835_transfer_block_pio()
353 host->data->error = -EINVAL; in bcm2835_transfer_block_pio()
358 host->sg_miter.consumed = len; in bcm2835_transfer_block_pio()
360 buf = (u32 *)host->sg_miter.addr; in bcm2835_transfer_block_pio()
369 edm = readl(host->ioaddr + SDEDM); in bcm2835_transfer_block_pio()
377 struct device *dev = &host->pdev->dev; in bcm2835_transfer_block_pio()
387 hsts = readl(host->ioaddr + SDHSTS); in bcm2835_transfer_block_pio()
402 host->ns_per_fifo_word); in bcm2835_transfer_block_pio()
412 *(buf++) = readl(host->ioaddr + SDDATA); in bcm2835_transfer_block_pio()
414 writel(*(buf++), host->ioaddr + SDDATA); in bcm2835_transfer_block_pio()
423 sg_miter_stop(&host->sg_miter); in bcm2835_transfer_block_pio()
428 static void bcm2835_transfer_pio(struct bcm2835_host *host) in bcm2835_transfer_pio() argument
430 struct device *dev = &host->pdev->dev; in bcm2835_transfer_pio()
434 is_read = (host->data->flags & MMC_DATA_READ) != 0; in bcm2835_transfer_pio()
435 bcm2835_transfer_block_pio(host, is_read); in bcm2835_transfer_pio()
437 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_transfer_pio()
443 host->data->error = -EILSEQ; in bcm2835_transfer_pio()
448 host->data->error = -ETIMEDOUT; in bcm2835_transfer_pio()
453 void bcm2835_prepare_dma(struct bcm2835_host *host, struct mmc_data *data) in bcm2835_prepare_dma() argument
459 dma_chan = host->dma_chan_rxtx; in bcm2835_prepare_dma()
475 host->drain_words = 0; in bcm2835_prepare_dma()
488 host->drain_page = sg_page(sg); in bcm2835_prepare_dma()
489 host->drain_offset = sg->offset + sg->length; in bcm2835_prepare_dma()
492 host->drain_words = len / 4; in bcm2835_prepare_dma()
498 &host->dma_cfg_rx : in bcm2835_prepare_dma()
499 &host->dma_cfg_tx); in bcm2835_prepare_dma()
515 desc->callback_param = host; in bcm2835_prepare_dma()
516 host->dma_desc = desc; in bcm2835_prepare_dma()
517 host->dma_chan = dma_chan; in bcm2835_prepare_dma()
518 host->dma_dir = dir_data; in bcm2835_prepare_dma()
521 static void bcm2835_start_dma(struct bcm2835_host *host) in bcm2835_start_dma() argument
523 dmaengine_submit(host->dma_desc); in bcm2835_start_dma()
524 dma_async_issue_pending(host->dma_chan); in bcm2835_start_dma()
527 static void bcm2835_set_transfer_irqs(struct bcm2835_host *host) in bcm2835_set_transfer_irqs() argument
532 if (host->dma_desc) { in bcm2835_set_transfer_irqs()
533 host->hcfg = (host->hcfg & ~all_irqs) | in bcm2835_set_transfer_irqs()
536 host->hcfg = (host->hcfg & ~all_irqs) | in bcm2835_set_transfer_irqs()
541 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_set_transfer_irqs()
545 void bcm2835_prepare_data(struct bcm2835_host *host, struct mmc_command *cmd) in bcm2835_prepare_data() argument
549 WARN_ON(host->data); in bcm2835_prepare_data()
551 host->data = data; in bcm2835_prepare_data()
555 host->data_complete = false; in bcm2835_prepare_data()
556 host->data->bytes_xfered = 0; in bcm2835_prepare_data()
558 if (!host->dma_desc) { in bcm2835_prepare_data()
566 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags); in bcm2835_prepare_data()
567 host->blocks = data->blocks; in bcm2835_prepare_data()
570 bcm2835_set_transfer_irqs(host); in bcm2835_prepare_data()
572 writel(data->blksz, host->ioaddr + SDHBCT); in bcm2835_prepare_data()
573 writel(data->blocks, host->ioaddr + SDHBLC); in bcm2835_prepare_data()
576 static u32 bcm2835_read_wait_sdcmd(struct bcm2835_host *host, u32 max_ms) in bcm2835_read_wait_sdcmd() argument
578 struct device *dev = &host->pdev->dev; in bcm2835_read_wait_sdcmd()
582 ret = readl_poll_timeout(host->ioaddr + SDCMD, value, in bcm2835_read_wait_sdcmd()
586 ret = readl_poll_timeout(host->ioaddr + SDCMD, value, in bcm2835_read_wait_sdcmd()
595 static void bcm2835_finish_request(struct bcm2835_host *host) in bcm2835_finish_request() argument
600 cancel_delayed_work(&host->timeout_work); in bcm2835_finish_request()
602 mrq = host->mrq; in bcm2835_finish_request()
604 host->mrq = NULL; in bcm2835_finish_request()
605 host->cmd = NULL; in bcm2835_finish_request()
606 host->data = NULL; in bcm2835_finish_request()
608 host->dma_desc = NULL; in bcm2835_finish_request()
609 terminate_chan = host->dma_chan; in bcm2835_finish_request()
610 host->dma_chan = NULL; in bcm2835_finish_request()
616 dev_err(&host->pdev->dev, in bcm2835_finish_request()
620 mmc_request_done(mmc_from_priv(host), mrq); in bcm2835_finish_request()
624 bool bcm2835_send_command(struct bcm2835_host *host, struct mmc_command *cmd) in bcm2835_send_command() argument
626 struct device *dev = &host->pdev->dev; in bcm2835_send_command()
630 WARN_ON(host->cmd); in bcm2835_send_command()
632 sdcmd = bcm2835_read_wait_sdcmd(host, 100); in bcm2835_send_command()
635 bcm2835_dumpregs(host); in bcm2835_send_command()
637 bcm2835_finish_request(host); in bcm2835_send_command()
645 schedule_delayed_work(&host->timeout_work, timeout); in bcm2835_send_command()
647 host->cmd = cmd; in bcm2835_send_command()
650 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_send_command()
652 writel(sdhsts, host->ioaddr + SDHSTS); in bcm2835_send_command()
657 bcm2835_finish_request(host); in bcm2835_send_command()
661 bcm2835_prepare_data(host, cmd); in bcm2835_send_command()
663 writel(cmd->arg, host->ioaddr + SDARG); in bcm2835_send_command()
667 host->use_busy = false; in bcm2835_send_command()
675 host->use_busy = true; in bcm2835_send_command()
686 writel(sdcmd | SDCMD_NEW_FLAG, host->ioaddr + SDCMD); in bcm2835_send_command()
691 static void bcm2835_transfer_complete(struct bcm2835_host *host) in bcm2835_transfer_complete() argument
695 WARN_ON(!host->data_complete); in bcm2835_transfer_complete()
697 data = host->data; in bcm2835_transfer_complete()
698 host->data = NULL; in bcm2835_transfer_complete()
704 if (host->mrq->stop && (data->error || !host->use_sbc)) { in bcm2835_transfer_complete()
705 if (bcm2835_send_command(host, host->mrq->stop)) { in bcm2835_transfer_complete()
707 if (!host->use_busy) in bcm2835_transfer_complete()
708 bcm2835_finish_command(host); in bcm2835_transfer_complete()
711 bcm2835_wait_transfer_complete(host); in bcm2835_transfer_complete()
712 bcm2835_finish_request(host); in bcm2835_transfer_complete()
716 static void bcm2835_finish_data(struct bcm2835_host *host) in bcm2835_finish_data() argument
718 struct device *dev = &host->pdev->dev; in bcm2835_finish_data()
721 data = host->data; in bcm2835_finish_data()
723 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN); in bcm2835_finish_data()
724 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_finish_data()
728 host->data_complete = true; in bcm2835_finish_data()
730 if (host->cmd) { in bcm2835_finish_data()
736 readl(host->ioaddr + SDHSTS)); in bcm2835_finish_data()
738 bcm2835_transfer_complete(host); in bcm2835_finish_data()
742 static void bcm2835_finish_command(struct bcm2835_host *host) in bcm2835_finish_command() argument
744 struct device *dev = &host->pdev->dev; in bcm2835_finish_command()
745 struct mmc_command *cmd = host->cmd; in bcm2835_finish_command()
748 sdcmd = bcm2835_read_wait_sdcmd(host, 100); in bcm2835_finish_command()
753 bcm2835_dumpregs(host); in bcm2835_finish_command()
754 host->cmd->error = -EIO; in bcm2835_finish_command()
755 bcm2835_finish_request(host); in bcm2835_finish_command()
758 u32 sdhsts = readl(host->ioaddr + SDHSTS); in bcm2835_finish_command()
761 writel(SDHSTS_ERROR_MASK, host->ioaddr + SDHSTS); in bcm2835_finish_command()
764 (host->cmd->opcode != MMC_SEND_OP_COND)) { in bcm2835_finish_command()
768 host->cmd->error = -ETIMEDOUT; in bcm2835_finish_command()
771 host->cmd->opcode); in bcm2835_finish_command()
772 bcm2835_dumpregs(host); in bcm2835_finish_command()
773 host->cmd->error = -EILSEQ; in bcm2835_finish_command()
775 edm = readl(host->ioaddr + SDEDM); in bcm2835_finish_command()
781 host->ioaddr + SDEDM); in bcm2835_finish_command()
782 bcm2835_finish_request(host); in bcm2835_finish_command()
793 readl(host->ioaddr + SDRSP0 + i * 4); in bcm2835_finish_command()
796 cmd->resp[0] = readl(host->ioaddr + SDRSP0); in bcm2835_finish_command()
800 if (cmd == host->mrq->sbc) { in bcm2835_finish_command()
802 host->cmd = NULL; in bcm2835_finish_command()
803 if (bcm2835_send_command(host, host->mrq->cmd)) { in bcm2835_finish_command()
804 if (host->data && host->dma_desc) in bcm2835_finish_command()
808 bcm2835_start_dma(host); in bcm2835_finish_command()
810 if (!host->use_busy) in bcm2835_finish_command()
811 bcm2835_finish_command(host); in bcm2835_finish_command()
813 } else if (cmd == host->mrq->stop) { in bcm2835_finish_command()
815 bcm2835_finish_request(host); in bcm2835_finish_command()
818 host->cmd = NULL; in bcm2835_finish_command()
819 if (!host->data) in bcm2835_finish_command()
820 bcm2835_finish_request(host); in bcm2835_finish_command()
821 else if (host->data_complete) in bcm2835_finish_command()
822 bcm2835_transfer_complete(host); in bcm2835_finish_command()
829 struct bcm2835_host *host = in bcm2835_timeout() local
831 struct device *dev = &host->pdev->dev; in bcm2835_timeout()
833 mutex_lock(&host->mutex); in bcm2835_timeout()
835 if (host->mrq) { in bcm2835_timeout()
837 bcm2835_dumpregs(host); in bcm2835_timeout()
839 bcm2835_reset(mmc_from_priv(host)); in bcm2835_timeout()
841 if (host->data) { in bcm2835_timeout()
842 host->data->error = -ETIMEDOUT; in bcm2835_timeout()
843 bcm2835_finish_data(host); in bcm2835_timeout()
845 if (host->cmd) in bcm2835_timeout()
846 host->cmd->error = -ETIMEDOUT; in bcm2835_timeout()
848 host->mrq->cmd->error = -ETIMEDOUT; in bcm2835_timeout()
850 bcm2835_finish_request(host); in bcm2835_timeout()
854 mutex_unlock(&host->mutex); in bcm2835_timeout()
857 static bool bcm2835_check_cmd_error(struct bcm2835_host *host, u32 intmask) in bcm2835_check_cmd_error() argument
859 struct device *dev = &host->pdev->dev; in bcm2835_check_cmd_error()
864 if (!host->cmd) in bcm2835_check_cmd_error()
869 host->cmd->error = -EILSEQ; in bcm2835_check_cmd_error()
872 if (host->mrq->data) in bcm2835_check_cmd_error()
873 host->mrq->data->error = -EILSEQ; in bcm2835_check_cmd_error()
875 host->cmd->error = -EILSEQ; in bcm2835_check_cmd_error()
877 if (host->mrq->data) in bcm2835_check_cmd_error()
878 host->mrq->data->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
880 host->cmd->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
882 host->cmd->error = -ETIMEDOUT; in bcm2835_check_cmd_error()
884 bcm2835_dumpregs(host); in bcm2835_check_cmd_error()
888 static void bcm2835_check_data_error(struct bcm2835_host *host, u32 intmask) in bcm2835_check_data_error() argument
890 if (!host->data) in bcm2835_check_data_error()
893 host->data->error = -EILSEQ; in bcm2835_check_data_error()
895 host->data->error = -ETIMEDOUT; in bcm2835_check_data_error()
898 static void bcm2835_busy_irq(struct bcm2835_host *host) in bcm2835_busy_irq() argument
900 if (WARN_ON(!host->cmd)) { in bcm2835_busy_irq()
901 bcm2835_dumpregs(host); in bcm2835_busy_irq()
905 if (WARN_ON(!host->use_busy)) { in bcm2835_busy_irq()
906 bcm2835_dumpregs(host); in bcm2835_busy_irq()
909 host->use_busy = false; in bcm2835_busy_irq()
911 bcm2835_finish_command(host); in bcm2835_busy_irq()
914 static void bcm2835_data_irq(struct bcm2835_host *host, u32 intmask) in bcm2835_data_irq() argument
922 if (!host->data) in bcm2835_data_irq()
925 bcm2835_check_data_error(host, intmask); in bcm2835_data_irq()
926 if (host->data->error) in bcm2835_data_irq()
929 if (host->data->flags & MMC_DATA_WRITE) { in bcm2835_data_irq()
931 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN); in bcm2835_data_irq()
932 host->hcfg |= SDHCFG_BLOCK_IRPT_EN; in bcm2835_data_irq()
933 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_data_irq()
934 bcm2835_transfer_pio(host); in bcm2835_data_irq()
936 bcm2835_transfer_pio(host); in bcm2835_data_irq()
937 host->blocks--; in bcm2835_data_irq()
938 if ((host->blocks == 0) || host->data->error) in bcm2835_data_irq()
944 host->hcfg &= ~(SDHCFG_DATA_IRPT_EN | SDHCFG_BLOCK_IRPT_EN); in bcm2835_data_irq()
945 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_data_irq()
948 static void bcm2835_data_threaded_irq(struct bcm2835_host *host) in bcm2835_data_threaded_irq() argument
950 if (!host->data) in bcm2835_data_threaded_irq()
952 if ((host->blocks == 0) || host->data->error) in bcm2835_data_threaded_irq()
953 bcm2835_finish_data(host); in bcm2835_data_threaded_irq()
956 static void bcm2835_block_irq(struct bcm2835_host *host) in bcm2835_block_irq() argument
958 if (WARN_ON(!host->data)) { in bcm2835_block_irq()
959 bcm2835_dumpregs(host); in bcm2835_block_irq()
963 if (!host->dma_desc) { in bcm2835_block_irq()
964 WARN_ON(!host->blocks); in bcm2835_block_irq()
965 if (host->data->error || (--host->blocks == 0)) in bcm2835_block_irq()
966 bcm2835_finish_data(host); in bcm2835_block_irq()
968 bcm2835_transfer_pio(host); in bcm2835_block_irq()
969 } else if (host->data->flags & MMC_DATA_WRITE) { in bcm2835_block_irq()
970 bcm2835_finish_data(host); in bcm2835_block_irq()
977 struct bcm2835_host *host = dev_id; in bcm2835_irq() local
980 spin_lock(&host->lock); in bcm2835_irq()
982 intmask = readl(host->ioaddr + SDHSTS); in bcm2835_irq()
988 host->ioaddr + SDHSTS); in bcm2835_irq()
991 bcm2835_check_data_error(host, intmask); in bcm2835_irq()
992 host->irq_block = true; in bcm2835_irq()
997 if (!bcm2835_check_cmd_error(host, intmask)) { in bcm2835_irq()
998 host->irq_busy = true; in bcm2835_irq()
1010 (host->hcfg & SDHCFG_DATA_IRPT_EN)) { in bcm2835_irq()
1011 bcm2835_data_irq(host, intmask); in bcm2835_irq()
1012 host->irq_data = true; in bcm2835_irq()
1016 spin_unlock(&host->lock); in bcm2835_irq()
1023 struct bcm2835_host *host = dev_id; in bcm2835_threaded_irq() local
1027 spin_lock_irqsave(&host->lock, flags); in bcm2835_threaded_irq()
1029 block = host->irq_block; in bcm2835_threaded_irq()
1030 busy = host->irq_busy; in bcm2835_threaded_irq()
1031 data = host->irq_data; in bcm2835_threaded_irq()
1032 host->irq_block = false; in bcm2835_threaded_irq()
1033 host->irq_busy = false; in bcm2835_threaded_irq()
1034 host->irq_data = false; in bcm2835_threaded_irq()
1036 spin_unlock_irqrestore(&host->lock, flags); in bcm2835_threaded_irq()
1038 mutex_lock(&host->mutex); in bcm2835_threaded_irq()
1041 bcm2835_block_irq(host); in bcm2835_threaded_irq()
1043 bcm2835_busy_irq(host); in bcm2835_threaded_irq()
1045 bcm2835_data_threaded_irq(host); in bcm2835_threaded_irq()
1047 mutex_unlock(&host->mutex); in bcm2835_threaded_irq()
1054 struct bcm2835_host *host = in bcm2835_dma_complete_work() local
1058 mutex_lock(&host->mutex); in bcm2835_dma_complete_work()
1060 data = host->data; in bcm2835_dma_complete_work()
1062 if (host->dma_chan) { in bcm2835_dma_complete_work()
1063 dma_unmap_sg(host->dma_chan->device->dev, in bcm2835_dma_complete_work()
1065 host->dma_dir); in bcm2835_dma_complete_work()
1067 host->dma_chan = NULL; in bcm2835_dma_complete_work()
1070 if (host->drain_words) { in bcm2835_dma_complete_work()
1075 if (host->drain_offset & PAGE_MASK) { in bcm2835_dma_complete_work()
1076 host->drain_page += host->drain_offset >> PAGE_SHIFT; in bcm2835_dma_complete_work()
1077 host->drain_offset &= ~PAGE_MASK; in bcm2835_dma_complete_work()
1080 page = kmap_atomic(host->drain_page); in bcm2835_dma_complete_work()
1081 buf = page + host->drain_offset; in bcm2835_dma_complete_work()
1083 while (host->drain_words) { in bcm2835_dma_complete_work()
1084 u32 edm = readl(host->ioaddr + SDEDM); in bcm2835_dma_complete_work()
1087 *(buf++) = readl(host->ioaddr + SDDATA); in bcm2835_dma_complete_work()
1088 host->drain_words--; in bcm2835_dma_complete_work()
1095 bcm2835_finish_data(host); in bcm2835_dma_complete_work()
1097 mutex_unlock(&host->mutex); in bcm2835_dma_complete_work()
1100 static void bcm2835_set_clock(struct bcm2835_host *host, unsigned int clock) in bcm2835_set_clock() argument
1102 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_set_clock()
1130 host->cdiv = SDCDIV_MAX_CDIV; in bcm2835_set_clock()
1131 writel(host->cdiv, host->ioaddr + SDCDIV); in bcm2835_set_clock()
1135 div = host->max_clk / clock; in bcm2835_set_clock()
1138 if ((host->max_clk / div) > clock) in bcm2835_set_clock()
1145 clock = host->max_clk / (div + 2); in bcm2835_set_clock()
1150 host->ns_per_fifo_word = (1000000000 / clock) * in bcm2835_set_clock()
1153 host->cdiv = div; in bcm2835_set_clock()
1154 writel(host->cdiv, host->ioaddr + SDCDIV); in bcm2835_set_clock()
1157 writel(mmc->actual_clock / 2, host->ioaddr + SDTOUT); in bcm2835_set_clock()
1162 struct bcm2835_host *host = mmc_priv(mmc); in bcm2835_request() local
1163 struct device *dev = &host->pdev->dev; in bcm2835_request()
1187 mutex_lock(&host->mutex); in bcm2835_request()
1189 WARN_ON(host->mrq); in bcm2835_request()
1190 host->mrq = mrq; in bcm2835_request()
1192 edm = readl(host->ioaddr + SDEDM); in bcm2835_request()
1198 readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK, in bcm2835_request()
1200 bcm2835_dumpregs(host); in bcm2835_request()
1205 bcm2835_finish_request(host); in bcm2835_request()
1206 mutex_unlock(&host->mutex); in bcm2835_request()
1210 if (host->use_dma && mrq->data && (mrq->data->blocks > PIO_THRESHOLD)) in bcm2835_request()
1211 bcm2835_prepare_dma(host, mrq->data); in bcm2835_request()
1213 host->use_sbc = !!mrq->sbc && host->mrq->data && in bcm2835_request()
1214 (host->mrq->data->flags & MMC_DATA_READ); in bcm2835_request()
1215 if (host->use_sbc) { in bcm2835_request()
1216 if (bcm2835_send_command(host, mrq->sbc)) { in bcm2835_request()
1217 if (!host->use_busy) in bcm2835_request()
1218 bcm2835_finish_command(host); in bcm2835_request()
1220 } else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) { in bcm2835_request()
1221 if (host->data && host->dma_desc) { in bcm2835_request()
1223 bcm2835_start_dma(host); in bcm2835_request()
1226 if (!host->use_busy) in bcm2835_request()
1227 bcm2835_finish_command(host); in bcm2835_request()
1230 mutex_unlock(&host->mutex); in bcm2835_request()
1235 struct bcm2835_host *host = mmc_priv(mmc); in bcm2835_set_ios() local
1237 mutex_lock(&host->mutex); in bcm2835_set_ios()
1239 if (!ios->clock || ios->clock != host->clock) { in bcm2835_set_ios()
1240 bcm2835_set_clock(host, ios->clock); in bcm2835_set_ios()
1241 host->clock = ios->clock; in bcm2835_set_ios()
1245 host->hcfg &= ~SDHCFG_WIDE_EXT_BUS; in bcm2835_set_ios()
1247 host->hcfg |= SDHCFG_WIDE_EXT_BUS; in bcm2835_set_ios()
1249 host->hcfg |= SDHCFG_WIDE_INT_BUS; in bcm2835_set_ios()
1252 host->hcfg |= SDHCFG_SLOW_CARD; in bcm2835_set_ios()
1254 writel(host->hcfg, host->ioaddr + SDHCFG); in bcm2835_set_ios()
1256 mutex_unlock(&host->mutex); in bcm2835_set_ios()
1265 static int bcm2835_add_host(struct bcm2835_host *host) in bcm2835_add_host() argument
1267 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_add_host()
1268 struct device *dev = &host->pdev->dev; in bcm2835_add_host()
1272 if (!mmc->f_max || mmc->f_max > host->max_clk) in bcm2835_add_host()
1273 mmc->f_max = host->max_clk; in bcm2835_add_host()
1274 mmc->f_min = host->max_clk / SDCDIV_MAX_CDIV; in bcm2835_add_host()
1285 spin_lock_init(&host->lock); in bcm2835_add_host()
1286 mutex_init(&host->mutex); in bcm2835_add_host()
1288 if (!host->dma_chan_rxtx) { in bcm2835_add_host()
1290 host->use_dma = false; in bcm2835_add_host()
1292 host->use_dma = true; in bcm2835_add_host()
1294 host->dma_cfg_tx.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1295 host->dma_cfg_tx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1296 host->dma_cfg_tx.direction = DMA_MEM_TO_DEV; in bcm2835_add_host()
1297 host->dma_cfg_tx.src_addr = 0; in bcm2835_add_host()
1298 host->dma_cfg_tx.dst_addr = host->phys_addr + SDDATA; in bcm2835_add_host()
1300 host->dma_cfg_rx.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1301 host->dma_cfg_rx.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; in bcm2835_add_host()
1302 host->dma_cfg_rx.direction = DMA_DEV_TO_MEM; in bcm2835_add_host()
1303 host->dma_cfg_rx.src_addr = host->phys_addr + SDDATA; in bcm2835_add_host()
1304 host->dma_cfg_rx.dst_addr = 0; in bcm2835_add_host()
1306 if (dmaengine_slave_config(host->dma_chan_rxtx, in bcm2835_add_host()
1307 &host->dma_cfg_tx) != 0 || in bcm2835_add_host()
1308 dmaengine_slave_config(host->dma_chan_rxtx, in bcm2835_add_host()
1309 &host->dma_cfg_rx) != 0) in bcm2835_add_host()
1310 host->use_dma = false; in bcm2835_add_host()
1322 INIT_WORK(&host->dma_work, bcm2835_dma_complete_work); in bcm2835_add_host()
1323 INIT_DELAYED_WORK(&host->timeout_work, bcm2835_timeout); in bcm2835_add_host()
1326 host->hcfg = SDHCFG_BUSY_IRPT_EN; in bcm2835_add_host()
1328 bcm2835_reset_internal(host); in bcm2835_add_host()
1330 ret = request_threaded_irq(host->irq, bcm2835_irq, in bcm2835_add_host()
1332 0, mmc_hostname(mmc), host); in bcm2835_add_host()
1334 dev_err(dev, "failed to request IRQ %d: %d\n", host->irq, ret); in bcm2835_add_host()
1340 free_irq(host->irq, host); in bcm2835_add_host()
1345 if (host->use_dma && (PIO_THRESHOLD > 0)) in bcm2835_add_host()
1348 host->use_dma ? "enabled" : "disabled", pio_limit_string); in bcm2835_add_host()
1357 struct bcm2835_host *host; in bcm2835_probe() local
1363 mmc = mmc_alloc_host(sizeof(*host), dev); in bcm2835_probe()
1368 host = mmc_priv(mmc); in bcm2835_probe()
1369 host->pdev = pdev; in bcm2835_probe()
1370 spin_lock_init(&host->lock); in bcm2835_probe()
1372 host->ioaddr = devm_platform_ioremap_resource(pdev, 0); in bcm2835_probe()
1373 if (IS_ERR(host->ioaddr)) { in bcm2835_probe()
1374 ret = PTR_ERR(host->ioaddr); in bcm2835_probe()
1388 host->phys_addr = be32_to_cpup(regaddr_p); in bcm2835_probe()
1390 host->dma_chan = NULL; in bcm2835_probe()
1391 host->dma_desc = NULL; in bcm2835_probe()
1393 host->dma_chan_rxtx = dma_request_chan(dev, "rx-tx"); in bcm2835_probe()
1394 if (IS_ERR(host->dma_chan_rxtx)) { in bcm2835_probe()
1395 ret = PTR_ERR(host->dma_chan_rxtx); in bcm2835_probe()
1396 host->dma_chan_rxtx = NULL; in bcm2835_probe()
1411 host->max_clk = clk_get_rate(clk); in bcm2835_probe()
1413 host->irq = platform_get_irq(pdev, 0); in bcm2835_probe()
1414 if (host->irq <= 0) { in bcm2835_probe()
1423 ret = bcm2835_add_host(host); in bcm2835_probe()
1427 platform_set_drvdata(pdev, host); in bcm2835_probe()
1435 if (host->dma_chan_rxtx) in bcm2835_probe()
1436 dma_release_channel(host->dma_chan_rxtx); in bcm2835_probe()
1444 struct bcm2835_host *host = platform_get_drvdata(pdev); in bcm2835_remove() local
1445 struct mmc_host *mmc = mmc_from_priv(host); in bcm2835_remove()
1449 writel(SDVDD_POWER_OFF, host->ioaddr + SDVDD); in bcm2835_remove()
1451 free_irq(host->irq, host); in bcm2835_remove()
1453 cancel_work_sync(&host->dma_work); in bcm2835_remove()
1454 cancel_delayed_work_sync(&host->timeout_work); in bcm2835_remove()
1456 if (host->dma_chan_rxtx) in bcm2835_remove()
1457 dma_release_channel(host->dma_chan_rxtx); in bcm2835_remove()