Lines Matching refs:acdev
226 static void cf_dumpregs(struct arasan_cf_dev *acdev) in cf_dumpregs() argument
228 struct device *dev = acdev->host->dev; in cf_dumpregs()
231 dev_dbg(dev, ": CFI_STS: %x", readl(acdev->vbase + CFI_STS)); in cf_dumpregs()
232 dev_dbg(dev, ": IRQ_STS: %x", readl(acdev->vbase + IRQ_STS)); in cf_dumpregs()
233 dev_dbg(dev, ": IRQ_EN: %x", readl(acdev->vbase + IRQ_EN)); in cf_dumpregs()
234 dev_dbg(dev, ": OP_MODE: %x", readl(acdev->vbase + OP_MODE)); in cf_dumpregs()
235 dev_dbg(dev, ": CLK_CFG: %x", readl(acdev->vbase + CLK_CFG)); in cf_dumpregs()
236 dev_dbg(dev, ": TM_CFG: %x", readl(acdev->vbase + TM_CFG)); in cf_dumpregs()
237 dev_dbg(dev, ": XFER_CTR: %x", readl(acdev->vbase + XFER_CTR)); in cf_dumpregs()
238 dev_dbg(dev, ": GIRQ_STS: %x", readl(acdev->vbase + GIRQ_STS)); in cf_dumpregs()
239 dev_dbg(dev, ": GIRQ_STS_EN: %x", readl(acdev->vbase + GIRQ_STS_EN)); in cf_dumpregs()
240 dev_dbg(dev, ": GIRQ_SGN_EN: %x", readl(acdev->vbase + GIRQ_SGN_EN)); in cf_dumpregs()
245 static void cf_ginterrupt_enable(struct arasan_cf_dev *acdev, bool enable) in cf_ginterrupt_enable() argument
248 writel(enable, acdev->vbase + GIRQ_STS_EN); in cf_ginterrupt_enable()
249 writel(enable, acdev->vbase + GIRQ_SGN_EN); in cf_ginterrupt_enable()
254 cf_interrupt_enable(struct arasan_cf_dev *acdev, u32 mask, bool enable) in cf_interrupt_enable() argument
256 u32 val = readl(acdev->vbase + IRQ_EN); in cf_interrupt_enable()
259 writel(mask, acdev->vbase + IRQ_STS); in cf_interrupt_enable()
260 writel(val | mask, acdev->vbase + IRQ_EN); in cf_interrupt_enable()
262 writel(val & ~mask, acdev->vbase + IRQ_EN); in cf_interrupt_enable()
265 static inline void cf_card_reset(struct arasan_cf_dev *acdev) in cf_card_reset() argument
267 u32 val = readl(acdev->vbase + OP_MODE); in cf_card_reset()
269 writel(val | CARD_RESET, acdev->vbase + OP_MODE); in cf_card_reset()
271 writel(val & ~CARD_RESET, acdev->vbase + OP_MODE); in cf_card_reset()
274 static inline void cf_ctrl_reset(struct arasan_cf_dev *acdev) in cf_ctrl_reset() argument
276 writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB, in cf_ctrl_reset()
277 acdev->vbase + OP_MODE); in cf_ctrl_reset()
278 writel(readl(acdev->vbase + OP_MODE) | CFHOST_ENB, in cf_ctrl_reset()
279 acdev->vbase + OP_MODE); in cf_ctrl_reset()
282 static void cf_card_detect(struct arasan_cf_dev *acdev, bool hotplugged) in cf_card_detect() argument
284 struct ata_port *ap = acdev->host->ports[0]; in cf_card_detect()
286 u32 val = readl(acdev->vbase + CFI_STS); in cf_card_detect()
290 if (acdev->card_present) in cf_card_detect()
292 acdev->card_present = 1; in cf_card_detect()
293 cf_card_reset(acdev); in cf_card_detect()
295 if (!acdev->card_present) in cf_card_detect()
297 acdev->card_present = 0; in cf_card_detect()
306 static int cf_init(struct arasan_cf_dev *acdev) in cf_init() argument
308 struct arasan_cf_pdata *pdata = dev_get_platdata(acdev->host->dev); in cf_init()
313 ret = clk_prepare_enable(acdev->clk); in cf_init()
315 dev_dbg(acdev->host->dev, "clock enable failed"); in cf_init()
319 ret = clk_set_rate(acdev->clk, 166000000); in cf_init()
321 dev_warn(acdev->host->dev, "clock set rate failed"); in cf_init()
322 clk_disable_unprepare(acdev->clk); in cf_init()
326 spin_lock_irqsave(&acdev->host->lock, flags); in cf_init()
333 writel(if_clk, acdev->vbase + CLK_CFG); in cf_init()
335 writel(TRUE_IDE_MODE | CFHOST_ENB, acdev->vbase + OP_MODE); in cf_init()
336 cf_interrupt_enable(acdev, CARD_DETECT_IRQ, 1); in cf_init()
337 cf_ginterrupt_enable(acdev, 1); in cf_init()
338 spin_unlock_irqrestore(&acdev->host->lock, flags); in cf_init()
343 static void cf_exit(struct arasan_cf_dev *acdev) in cf_exit() argument
347 spin_lock_irqsave(&acdev->host->lock, flags); in cf_exit()
348 cf_ginterrupt_enable(acdev, 0); in cf_exit()
349 cf_interrupt_enable(acdev, TRUE_IDE_IRQS, 0); in cf_exit()
350 cf_card_reset(acdev); in cf_exit()
351 writel(readl(acdev->vbase + OP_MODE) & ~CFHOST_ENB, in cf_exit()
352 acdev->vbase + OP_MODE); in cf_exit()
353 spin_unlock_irqrestore(&acdev->host->lock, flags); in cf_exit()
354 clk_disable_unprepare(acdev->clk); in cf_exit()
359 struct arasan_cf_dev *acdev = dev; in dma_callback() local
361 complete(&acdev->dma_completion); in dma_callback()
364 static inline void dma_complete(struct arasan_cf_dev *acdev) in dma_complete() argument
366 struct ata_queued_cmd *qc = acdev->qc; in dma_complete()
369 acdev->qc = NULL; in dma_complete()
370 ata_sff_interrupt(acdev->irq, acdev->host); in dma_complete()
372 spin_lock_irqsave(&acdev->host->lock, flags); in dma_complete()
375 spin_unlock_irqrestore(&acdev->host->lock, flags); in dma_complete()
378 static inline int wait4buf(struct arasan_cf_dev *acdev) in wait4buf() argument
380 if (!wait_for_completion_timeout(&acdev->cf_completion, TIMEOUT)) { in wait4buf()
381 u32 rw = acdev->qc->tf.flags & ATA_TFLAG_WRITE; in wait4buf()
383 dev_err(acdev->host->dev, "%s TimeOut", rw ? "write" : "read"); in wait4buf()
388 if (acdev->dma_status & ATA_DMA_ERR) in wait4buf()
395 dma_xfer(struct arasan_cf_dev *acdev, dma_addr_t src, dma_addr_t dest, u32 len) in dma_xfer() argument
398 struct dma_chan *chan = acdev->dma_chan; in dma_xfer()
405 dev_err(acdev->host->dev, "device_prep_dma_memcpy failed\n"); in dma_xfer()
410 tx->callback_param = acdev; in dma_xfer()
415 dev_err(acdev->host->dev, "dma_submit_error\n"); in dma_xfer()
422 if (!wait_for_completion_timeout(&acdev->dma_completion, TIMEOUT)) { in dma_xfer()
424 dev_err(acdev->host->dev, "wait_for_completion_timeout\n"); in dma_xfer()
431 static int sg_xfer(struct arasan_cf_dev *acdev, struct scatterlist *sg) in sg_xfer() argument
435 u32 write = acdev->qc->tf.flags & ATA_TFLAG_WRITE; in sg_xfer()
442 dest = acdev->pbase + EXT_WRITE_PORT; in sg_xfer()
445 src = acdev->pbase + EXT_READ_PORT; in sg_xfer()
457 spin_lock_irqsave(&acdev->host->lock, flags); in sg_xfer()
458 xfer_ctr = readl(acdev->vbase + XFER_CTR) & in sg_xfer()
461 acdev->vbase + XFER_CTR); in sg_xfer()
462 spin_unlock_irqrestore(&acdev->host->lock, flags); in sg_xfer()
468 ret = wait4buf(acdev); in sg_xfer()
475 ret = dma_xfer(acdev, src, dest, dma_len); in sg_xfer()
477 dev_err(acdev->host->dev, "dma failed"); in sg_xfer()
491 ret = wait4buf(acdev); in sg_xfer()
499 spin_lock_irqsave(&acdev->host->lock, flags); in sg_xfer()
500 writel(readl(acdev->vbase + XFER_CTR) & ~XFER_START, in sg_xfer()
501 acdev->vbase + XFER_CTR); in sg_xfer()
502 spin_unlock_irqrestore(&acdev->host->lock, flags); in sg_xfer()
520 struct arasan_cf_dev *acdev = container_of(work, struct arasan_cf_dev, in data_xfer() local
522 struct ata_queued_cmd *qc = acdev->qc; in data_xfer()
530 acdev->dma_chan = dma_request_chan(acdev->host->dev, "data"); in data_xfer()
531 if (IS_ERR(acdev->dma_chan)) { in data_xfer()
532 dev_err_probe(acdev->host->dev, PTR_ERR(acdev->dma_chan), in data_xfer()
534 acdev->dma_chan = NULL; in data_xfer()
539 ret = sg_xfer(acdev, sg); in data_xfer()
544 dma_release_channel(acdev->dma_chan); in data_xfer()
545 acdev->dma_chan = NULL; in data_xfer()
551 spin_lock_irqsave(&acdev->host->lock, flags); in data_xfer()
553 spin_unlock_irqrestore(&acdev->host->lock, flags); in data_xfer()
555 ata_sff_queue_delayed_work(&acdev->dwork, 1); in data_xfer()
562 cf_dumpregs(acdev); in data_xfer()
565 spin_lock_irqsave(&acdev->host->lock, flags); in data_xfer()
570 cf_ctrl_reset(acdev); in data_xfer()
571 spin_unlock_irqrestore(&acdev->host->lock, flags); in data_xfer()
573 dma_complete(acdev); in data_xfer()
578 struct arasan_cf_dev *acdev = container_of(work, struct arasan_cf_dev, in delayed_finish() local
580 struct ata_queued_cmd *qc = acdev->qc; in delayed_finish()
584 spin_lock_irqsave(&acdev->host->lock, flags); in delayed_finish()
586 spin_unlock_irqrestore(&acdev->host->lock, flags); in delayed_finish()
589 ata_sff_queue_delayed_work(&acdev->dwork, 1); in delayed_finish()
591 dma_complete(acdev); in delayed_finish()
596 struct arasan_cf_dev *acdev = ((struct ata_host *)dev)->private_data; in arasan_cf_interrupt() local
600 irqsts = readl(acdev->vbase + GIRQ_STS); in arasan_cf_interrupt()
604 spin_lock_irqsave(&acdev->host->lock, flags); in arasan_cf_interrupt()
605 irqsts = readl(acdev->vbase + IRQ_STS); in arasan_cf_interrupt()
606 writel(irqsts, acdev->vbase + IRQ_STS); /* clear irqs */ in arasan_cf_interrupt()
607 writel(GIRQ_CF, acdev->vbase + GIRQ_STS); /* clear girqs */ in arasan_cf_interrupt()
613 cf_card_detect(acdev, 1); in arasan_cf_interrupt()
614 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_interrupt()
619 acdev->dma_status = ATA_DMA_ERR; in arasan_cf_interrupt()
620 writel(readl(acdev->vbase + XFER_CTR) & ~XFER_START, in arasan_cf_interrupt()
621 acdev->vbase + XFER_CTR); in arasan_cf_interrupt()
622 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_interrupt()
623 complete(&acdev->cf_completion); in arasan_cf_interrupt()
624 dev_err(acdev->host->dev, "pio xfer err irq\n"); in arasan_cf_interrupt()
628 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_interrupt()
631 complete(&acdev->cf_completion); in arasan_cf_interrupt()
636 struct ata_queued_cmd *qc = acdev->qc; in arasan_cf_interrupt()
640 complete(&acdev->cf_completion); in arasan_cf_interrupt()
648 struct arasan_cf_dev *acdev = ap->host->private_data; in arasan_cf_freeze() local
651 writel(readl(acdev->vbase + XFER_CTR) & ~XFER_START, in arasan_cf_freeze()
652 acdev->vbase + XFER_CTR); in arasan_cf_freeze()
653 cf_ctrl_reset(acdev); in arasan_cf_freeze()
654 acdev->dma_status = ATA_DMA_ERR; in arasan_cf_freeze()
662 struct arasan_cf_dev *acdev = ap->host->private_data; in arasan_cf_error_handler() local
669 cancel_work_sync(&acdev->work); in arasan_cf_error_handler()
670 cancel_delayed_work_sync(&acdev->dwork); in arasan_cf_error_handler()
674 static void arasan_cf_dma_start(struct arasan_cf_dev *acdev) in arasan_cf_dma_start() argument
676 struct ata_queued_cmd *qc = acdev->qc; in arasan_cf_dma_start()
679 u32 xfer_ctr = readl(acdev->vbase + XFER_CTR) & ~XFER_DIR_MASK; in arasan_cf_dma_start()
683 writel(xfer_ctr, acdev->vbase + XFER_CTR); in arasan_cf_dma_start()
686 ata_sff_queue_work(&acdev->work); in arasan_cf_dma_start()
692 struct arasan_cf_dev *acdev = ap->host->private_data; in arasan_cf_qc_issue() local
710 acdev->dma_status = 0; in arasan_cf_qc_issue()
711 acdev->qc = qc; in arasan_cf_qc_issue()
713 arasan_cf_dma_start(acdev); in arasan_cf_qc_issue()
727 struct arasan_cf_dev *acdev = ap->host->private_data; in arasan_cf_set_piomode() local
738 spin_lock_irqsave(&acdev->host->lock, flags); in arasan_cf_set_piomode()
739 val = readl(acdev->vbase + OP_MODE) & in arasan_cf_set_piomode()
741 writel(val, acdev->vbase + OP_MODE); in arasan_cf_set_piomode()
742 val = readl(acdev->vbase + TM_CFG) & ~TRUEIDE_PIO_TIMING_MASK; in arasan_cf_set_piomode()
744 writel(val, acdev->vbase + TM_CFG); in arasan_cf_set_piomode()
746 cf_interrupt_enable(acdev, BUF_AVAIL_IRQ | XFER_DONE_IRQ, 0); in arasan_cf_set_piomode()
747 cf_interrupt_enable(acdev, PIO_XFER_ERR_IRQ, 1); in arasan_cf_set_piomode()
748 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_set_piomode()
753 struct arasan_cf_dev *acdev = ap->host->private_data; in arasan_cf_set_dmamode() local
757 spin_lock_irqsave(&acdev->host->lock, flags); in arasan_cf_set_dmamode()
758 opmode = readl(acdev->vbase + OP_MODE) & in arasan_cf_set_dmamode()
760 tmcfg = readl(acdev->vbase + TM_CFG); in arasan_cf_set_dmamode()
773 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_set_dmamode()
777 writel(opmode, acdev->vbase + OP_MODE); in arasan_cf_set_dmamode()
778 writel(tmcfg, acdev->vbase + TM_CFG); in arasan_cf_set_dmamode()
779 writel(DMA_XFER_MODE, acdev->vbase + XFER_CTR); in arasan_cf_set_dmamode()
781 cf_interrupt_enable(acdev, PIO_XFER_ERR_IRQ, 0); in arasan_cf_set_dmamode()
782 cf_interrupt_enable(acdev, BUF_AVAIL_IRQ | XFER_DONE_IRQ, 1); in arasan_cf_set_dmamode()
783 spin_unlock_irqrestore(&acdev->host->lock, flags); in arasan_cf_set_dmamode()
797 struct arasan_cf_dev *acdev; in arasan_cf_probe() local
816 acdev = devm_kzalloc(&pdev->dev, sizeof(*acdev), GFP_KERNEL); in arasan_cf_probe()
817 if (!acdev) in arasan_cf_probe()
831 acdev->irq = ret; in arasan_cf_probe()
839 acdev->pbase = res->start; in arasan_cf_probe()
840 acdev->vbase = devm_ioremap(&pdev->dev, res->start, in arasan_cf_probe()
842 if (!acdev->vbase) { in arasan_cf_probe()
847 acdev->clk = devm_clk_get(&pdev->dev, NULL); in arasan_cf_probe()
848 if (IS_ERR(acdev->clk)) { in arasan_cf_probe()
850 return PTR_ERR(acdev->clk); in arasan_cf_probe()
861 host->private_data = acdev; in arasan_cf_probe()
862 acdev->host = host; in arasan_cf_probe()
868 init_completion(&acdev->cf_completion); in arasan_cf_probe()
869 init_completion(&acdev->dma_completion); in arasan_cf_probe()
870 INIT_WORK(&acdev->work, data_xfer); in arasan_cf_probe()
871 INIT_DELAYED_WORK(&acdev->dwork, delayed_finish); in arasan_cf_probe()
872 dma_cap_set(DMA_MEMCPY, acdev->mask); in arasan_cf_probe()
887 ap->ioaddr.cmd_addr = acdev->vbase + ATA_DATA_PORT; in arasan_cf_probe()
888 ap->ioaddr.data_addr = acdev->vbase + ATA_DATA_PORT; in arasan_cf_probe()
889 ap->ioaddr.error_addr = acdev->vbase + ATA_ERR_FTR; in arasan_cf_probe()
890 ap->ioaddr.feature_addr = acdev->vbase + ATA_ERR_FTR; in arasan_cf_probe()
891 ap->ioaddr.nsect_addr = acdev->vbase + ATA_SC; in arasan_cf_probe()
892 ap->ioaddr.lbal_addr = acdev->vbase + ATA_SN; in arasan_cf_probe()
893 ap->ioaddr.lbam_addr = acdev->vbase + ATA_CL; in arasan_cf_probe()
894 ap->ioaddr.lbah_addr = acdev->vbase + ATA_CH; in arasan_cf_probe()
895 ap->ioaddr.device_addr = acdev->vbase + ATA_SH; in arasan_cf_probe()
896 ap->ioaddr.status_addr = acdev->vbase + ATA_STS_CMD; in arasan_cf_probe()
897 ap->ioaddr.command_addr = acdev->vbase + ATA_STS_CMD; in arasan_cf_probe()
898 ap->ioaddr.altstatus_addr = acdev->vbase + ATA_ASTS_DCTR; in arasan_cf_probe()
899 ap->ioaddr.ctl_addr = acdev->vbase + ATA_ASTS_DCTR; in arasan_cf_probe()
902 (unsigned long long) res->start, acdev->vbase); in arasan_cf_probe()
904 ret = cf_init(acdev); in arasan_cf_probe()
908 cf_card_detect(acdev, 0); in arasan_cf_probe()
910 ret = ata_host_activate(host, acdev->irq, irq_handler, 0, in arasan_cf_probe()
915 cf_exit(acdev); in arasan_cf_probe()
923 struct arasan_cf_dev *acdev = host->ports[0]->private_data; in arasan_cf_remove() local
926 cf_exit(acdev); in arasan_cf_remove()
933 struct arasan_cf_dev *acdev = host->ports[0]->private_data; in arasan_cf_suspend() local
935 if (acdev->dma_chan) in arasan_cf_suspend()
936 dmaengine_terminate_all(acdev->dma_chan); in arasan_cf_suspend()
938 cf_exit(acdev); in arasan_cf_suspend()
946 struct arasan_cf_dev *acdev = host->ports[0]->private_data; in arasan_cf_resume() local
948 cf_init(acdev); in arasan_cf_resume()