Lines Matching +full:tf +full:- +full:a
1 // SPDX-License-Identifier: GPL-2.0-only
12 * DMA engine support based on spi-ep93xx.c by Mika Westerberg.
21 * Heavily based on the ep93xx-ide.c driver:
47 #include <linux/platform_data/dma-ep93xx.h>
50 #define DRV_NAME "ep93xx-ide"
68 * ORed to the IDECTRL register, hence giving directly the A[2:0] and
166 * of HCLK cycles to hold the data bus after a PIO write operation.
200 * Based on delay loop found in mach-pxa/mp900.c.
223 * tA = 35ns after activation of DIOR-/DIOW-. Maximum IORDY pulse in ep93xx_pata_wait_for_iordy()
227 * DIOR-/DIOW-, so we set timeout to (1250 + 35) / 25 - t2 additional in ep93xx_pata_wait_for_iordy()
230 unsigned long start = (1250 + 35) / 25 - t2; in ep93xx_pata_wait_for_iordy()
233 while (!ep93xx_pata_check_iordy(base) && counter--) in ep93xx_pata_wait_for_iordy()
235 return start - counter; in ep93xx_pata_wait_for_iordy()
256 if (t0 > t2 && t0 - t2 > t2i) in ep93xx_pata_rw_end()
257 ep93xx_pata_delay(t0 - t2); in ep93xx_pata_rw_end()
266 void __iomem *base = drv_data->ide_base; in ep93xx_pata_read()
267 const struct ata_timing *t = &drv_data->t; in ep93xx_pata_read()
268 unsigned long t0 = reg ? t->cyc8b : t->cycle; in ep93xx_pata_read()
269 unsigned long t2 = reg ? t->act8b : t->active; in ep93xx_pata_read()
270 unsigned long t2i = reg ? t->rec8b : t->recover; in ep93xx_pata_read()
272 ep93xx_pata_rw_begin(base, addr, t->setup); in ep93xx_pata_read()
276 * edge of the DIORN signal. (EP93xx UG p27-14) in ep93xx_pata_read()
278 ep93xx_pata_rw_end(base, addr, drv_data->iordy, t0, t2, t2i); in ep93xx_pata_read()
300 void __iomem *base = drv_data->ide_base; in ep93xx_pata_write()
301 const struct ata_timing *t = &drv_data->t; in ep93xx_pata_write()
302 unsigned long t0 = reg ? t->cyc8b : t->cycle; in ep93xx_pata_write()
303 unsigned long t2 = reg ? t->act8b : t->active; in ep93xx_pata_write()
304 unsigned long t2i = reg ? t->rec8b : t->recover; in ep93xx_pata_write()
306 ep93xx_pata_rw_begin(base, addr, t->setup); in ep93xx_pata_write()
309 * DIOWN is low. (EP93xx UG p27-13) in ep93xx_pata_write()
313 ep93xx_pata_rw_end(base, addr, drv_data->iordy, t0, t2, t2i); in ep93xx_pata_write()
333 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_set_piomode()
338 * slower, we will wait a bit longer in each delay. in ep93xx_pata_set_piomode()
344 ata_timing_compute(adev, adev->pio_mode, &drv_data->t, T, 0); in ep93xx_pata_set_piomode()
345 if (pair && pair->pio_mode) { in ep93xx_pata_set_piomode()
347 ata_timing_compute(pair, pair->pio_mode, &t, T, 0); in ep93xx_pata_set_piomode()
348 ata_timing_merge(&t, &drv_data->t, &drv_data->t, in ep93xx_pata_set_piomode()
351 drv_data->iordy = ata_pio_need_iordy(adev); in ep93xx_pata_set_piomode()
353 ep93xx_pata_enable_pio(drv_data->ide_base, in ep93xx_pata_set_piomode()
354 adev->pio_mode - XFER_PIO_0); in ep93xx_pata_set_piomode()
360 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_check_status()
367 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_check_altstatus()
374 const struct ata_taskfile *tf) in ep93xx_pata_tf_load() argument
376 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_tf_load()
377 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; in ep93xx_pata_tf_load()
379 if (tf->ctl != ap->last_ctl) { in ep93xx_pata_tf_load()
380 ep93xx_pata_write_reg(drv_data, tf->ctl, IDECTRL_ADDR_CTL); in ep93xx_pata_tf_load()
381 ap->last_ctl = tf->ctl; in ep93xx_pata_tf_load()
385 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { in ep93xx_pata_tf_load()
386 ep93xx_pata_write_reg(drv_data, tf->hob_feature, in ep93xx_pata_tf_load()
388 ep93xx_pata_write_reg(drv_data, tf->hob_nsect, in ep93xx_pata_tf_load()
390 ep93xx_pata_write_reg(drv_data, tf->hob_lbal, in ep93xx_pata_tf_load()
392 ep93xx_pata_write_reg(drv_data, tf->hob_lbam, in ep93xx_pata_tf_load()
394 ep93xx_pata_write_reg(drv_data, tf->hob_lbah, in ep93xx_pata_tf_load()
399 ep93xx_pata_write_reg(drv_data, tf->feature, in ep93xx_pata_tf_load()
401 ep93xx_pata_write_reg(drv_data, tf->nsect, IDECTRL_ADDR_NSECT); in ep93xx_pata_tf_load()
402 ep93xx_pata_write_reg(drv_data, tf->lbal, IDECTRL_ADDR_LBAL); in ep93xx_pata_tf_load()
403 ep93xx_pata_write_reg(drv_data, tf->lbam, IDECTRL_ADDR_LBAM); in ep93xx_pata_tf_load()
404 ep93xx_pata_write_reg(drv_data, tf->lbah, IDECTRL_ADDR_LBAH); in ep93xx_pata_tf_load()
407 if (tf->flags & ATA_TFLAG_DEVICE) in ep93xx_pata_tf_load()
408 ep93xx_pata_write_reg(drv_data, tf->device, in ep93xx_pata_tf_load()
415 static void ep93xx_pata_tf_read(struct ata_port *ap, struct ata_taskfile *tf) in ep93xx_pata_tf_read() argument
417 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_tf_read()
419 tf->command = ep93xx_pata_check_status(ap); in ep93xx_pata_tf_read()
420 tf->feature = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_FEATURE); in ep93xx_pata_tf_read()
421 tf->nsect = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_NSECT); in ep93xx_pata_tf_read()
422 tf->lbal = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_LBAL); in ep93xx_pata_tf_read()
423 tf->lbam = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_LBAM); in ep93xx_pata_tf_read()
424 tf->lbah = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_LBAH); in ep93xx_pata_tf_read()
425 tf->device = ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_DEVICE); in ep93xx_pata_tf_read()
427 if (tf->flags & ATA_TFLAG_LBA48) { in ep93xx_pata_tf_read()
428 ep93xx_pata_write_reg(drv_data, tf->ctl | ATA_HOB, in ep93xx_pata_tf_read()
430 tf->hob_feature = ep93xx_pata_read_reg(drv_data, in ep93xx_pata_tf_read()
432 tf->hob_nsect = ep93xx_pata_read_reg(drv_data, in ep93xx_pata_tf_read()
434 tf->hob_lbal = ep93xx_pata_read_reg(drv_data, in ep93xx_pata_tf_read()
436 tf->hob_lbam = ep93xx_pata_read_reg(drv_data, in ep93xx_pata_tf_read()
438 tf->hob_lbah = ep93xx_pata_read_reg(drv_data, in ep93xx_pata_tf_read()
440 ep93xx_pata_write_reg(drv_data, tf->ctl, IDECTRL_ADDR_CTL); in ep93xx_pata_tf_read()
441 ap->last_ctl = tf->ctl; in ep93xx_pata_tf_read()
447 const struct ata_taskfile *tf) in ep93xx_pata_exec_command() argument
449 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_exec_command()
451 ep93xx_pata_write_reg(drv_data, tf->command, in ep93xx_pata_exec_command()
459 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_dev_select()
472 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_set_devctl()
482 struct ata_port *ap = qc->dev->link->ap; in ep93xx_pata_data_xfer()
483 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_data_xfer()
488 while (words--) in ep93xx_pata_data_xfer()
501 buf += buflen - 1; in ep93xx_pata_data_xfer()
523 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_device_is_present()
526 ap->ops->sff_dev_select(ap, device); in ep93xx_pata_device_is_present()
551 struct ata_port *ap = link->ap; in ep93xx_pata_wait_after_reset()
552 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_wait_after_reset()
562 * -ENODEV means the odd clown forgot the D7 pulldown resistor in ep93xx_pata_wait_after_reset()
563 * and TF status is 0xff, bail out on it too. in ep93xx_pata_wait_after_reset()
575 ap->ops->sff_dev_select(ap, 1); in ep93xx_pata_wait_after_reset()
591 msleep(50); /* give drive a breather */ in ep93xx_pata_wait_after_reset()
596 if (rc != -ENODEV) in ep93xx_pata_wait_after_reset()
602 ap->ops->sff_dev_select(ap, 0); in ep93xx_pata_wait_after_reset()
604 ap->ops->sff_dev_select(ap, 1); in ep93xx_pata_wait_after_reset()
606 ap->ops->sff_dev_select(ap, 0); in ep93xx_pata_wait_after_reset()
615 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_bus_softreset()
617 ep93xx_pata_write_reg(drv_data, ap->ctl, IDECTRL_ADDR_CTL); in ep93xx_pata_bus_softreset()
619 ep93xx_pata_write_reg(drv_data, ap->ctl | ATA_SRST, IDECTRL_ADDR_CTL); in ep93xx_pata_bus_softreset()
621 ep93xx_pata_write_reg(drv_data, ap->ctl, IDECTRL_ADDR_CTL); in ep93xx_pata_bus_softreset()
622 ap->last_ctl = ap->ctl; in ep93xx_pata_bus_softreset()
624 return ep93xx_pata_wait_after_reset(&ap->link, devmask, deadline); in ep93xx_pata_bus_softreset()
629 if (drv_data->dma_rx_channel) { in ep93xx_pata_release_dma()
630 dma_release_channel(drv_data->dma_rx_channel); in ep93xx_pata_release_dma()
631 drv_data->dma_rx_channel = NULL; in ep93xx_pata_release_dma()
633 if (drv_data->dma_tx_channel) { in ep93xx_pata_release_dma()
634 dma_release_channel(drv_data->dma_tx_channel); in ep93xx_pata_release_dma()
635 drv_data->dma_tx_channel = NULL; in ep93xx_pata_release_dma()
644 chan->private = filter_param; in ep93xx_pata_dma_filter()
650 const struct platform_device *pdev = drv_data->pdev; in ep93xx_pata_dma_init()
662 drv_data->dma_rx_data.port = EP93XX_DMA_IDE; in ep93xx_pata_dma_init()
663 drv_data->dma_rx_data.direction = DMA_DEV_TO_MEM; in ep93xx_pata_dma_init()
664 drv_data->dma_rx_data.name = "ep93xx-pata-rx"; in ep93xx_pata_dma_init()
665 drv_data->dma_rx_channel = dma_request_channel(mask, in ep93xx_pata_dma_init()
666 ep93xx_pata_dma_filter, &drv_data->dma_rx_data); in ep93xx_pata_dma_init()
667 if (!drv_data->dma_rx_channel) in ep93xx_pata_dma_init()
670 drv_data->dma_tx_data.port = EP93XX_DMA_IDE; in ep93xx_pata_dma_init()
671 drv_data->dma_tx_data.direction = DMA_MEM_TO_DEV; in ep93xx_pata_dma_init()
672 drv_data->dma_tx_data.name = "ep93xx-pata-tx"; in ep93xx_pata_dma_init()
673 drv_data->dma_tx_channel = dma_request_channel(mask, in ep93xx_pata_dma_init()
674 ep93xx_pata_dma_filter, &drv_data->dma_tx_data); in ep93xx_pata_dma_init()
675 if (!drv_data->dma_tx_channel) { in ep93xx_pata_dma_init()
676 dma_release_channel(drv_data->dma_rx_channel); in ep93xx_pata_dma_init()
683 conf.src_addr = drv_data->udma_in_phys; in ep93xx_pata_dma_init()
685 if (dmaengine_slave_config(drv_data->dma_rx_channel, &conf)) { in ep93xx_pata_dma_init()
686 dev_err(&pdev->dev, "failed to configure rx dma channel\n"); in ep93xx_pata_dma_init()
694 conf.dst_addr = drv_data->udma_out_phys; in ep93xx_pata_dma_init()
696 if (dmaengine_slave_config(drv_data->dma_tx_channel, &conf)) { in ep93xx_pata_dma_init()
697 dev_err(&pdev->dev, "failed to configure tx dma channel\n"); in ep93xx_pata_dma_init()
705 struct ep93xx_pata_data *drv_data = qc->ap->host->private_data; in ep93xx_pata_dma_start()
706 void __iomem *base = drv_data->ide_base; in ep93xx_pata_dma_start()
707 struct ata_device *adev = qc->dev; in ep93xx_pata_dma_start()
708 u32 v = qc->dma_dir == DMA_TO_DEVICE ? IDEUDMAOP_RWOP : 0; in ep93xx_pata_dma_start()
709 struct dma_chan *channel = qc->dma_dir == DMA_TO_DEVICE in ep93xx_pata_dma_start()
710 ? drv_data->dma_tx_channel : drv_data->dma_rx_channel; in ep93xx_pata_dma_start()
712 txd = dmaengine_prep_slave_sg(channel, qc->sg, qc->n_elem, qc->dma_dir, in ep93xx_pata_dma_start()
715 dev_err(qc->ap->dev, "failed to prepare slave for sg dma\n"); in ep93xx_pata_dma_start()
718 txd->callback = NULL; in ep93xx_pata_dma_start()
719 txd->callback_param = NULL; in ep93xx_pata_dma_start()
722 dev_err(qc->ap->dev, "failed to submit dma transfer\n"); in ep93xx_pata_dma_start()
739 ((adev->xfer_mode - XFER_UDMA_0) << IDECFG_MODE_SHIFT), in ep93xx_pata_dma_start()
745 struct ep93xx_pata_data *drv_data = qc->ap->host->private_data; in ep93xx_pata_dma_stop()
746 void __iomem *base = drv_data->ide_base; in ep93xx_pata_dma_stop()
749 dmaengine_terminate_all(drv_data->dma_rx_channel); in ep93xx_pata_dma_stop()
750 dmaengine_terminate_all(drv_data->dma_tx_channel); in ep93xx_pata_dma_stop()
753 * To properly stop IDE-DMA, IDEUDMAOP register must to be cleared in ep93xx_pata_dma_stop()
760 ep93xx_pata_enable_pio(drv_data->ide_base, in ep93xx_pata_dma_stop()
761 qc->dev->pio_mode - XFER_PIO_0); in ep93xx_pata_dma_stop()
763 ata_sff_dma_pause(qc->ap); in ep93xx_pata_dma_stop()
768 qc->ap->ops->sff_exec_command(qc->ap, &qc->tf); in ep93xx_pata_dma_setup()
773 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_dma_status()
774 u32 val = readl(drv_data->ide_base + IDEUDMASTS); in ep93xx_pata_dma_status()
779 * DMAIDE - DMA request signal from UDMA state machine, in ep93xx_pata_dma_status()
780 * INTIDE - INT line generated by UDMA because of errors in the in ep93xx_pata_dma_status()
782 * SBUSY - UDMA state machine busy, not in idle state, in ep93xx_pata_dma_status()
783 * NDO - error for data-out not completed, in ep93xx_pata_dma_status()
784 * NDI - error for data-in not completed, in ep93xx_pata_dma_status()
785 * N4X - error for data transferred not multiplies of four in ep93xx_pata_dma_status()
786 * 32-bit words. in ep93xx_pata_dma_status()
787 * (EP93xx UG p27-17) in ep93xx_pata_dma_status()
794 if (readl(drv_data->ide_base + IDECTRL) & IDECTRL_INTRQ) in ep93xx_pata_dma_status()
807 struct ata_port *ap = al->ap; in ep93xx_pata_softreset()
808 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; in ep93xx_pata_softreset()
820 ap->ops->sff_dev_select(al->ap, 0); in ep93xx_pata_softreset()
824 /* if link is ocuppied, -ENODEV too is an error */ in ep93xx_pata_softreset()
825 if (rc && (rc != -ENODEV || sata_scr_valid(al))) { in ep93xx_pata_softreset()
831 classes[0] = ata_sff_dev_classify(&al->device[0], devmask & (1 << 0), in ep93xx_pata_softreset()
834 classes[1] = ata_sff_dev_classify(&al->device[1], in ep93xx_pata_softreset()
847 /* We only need to flush incoming data when a command was running */ in ep93xx_pata_drain_fifo()
848 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) in ep93xx_pata_drain_fifo()
851 ap = qc->ap; in ep93xx_pata_drain_fifo()
852 drv_data = ap->host->private_data; in ep93xx_pata_drain_fifo()
854 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ) in ep93xx_pata_drain_fifo()
866 struct ep93xx_pata_data *drv_data = ap->host->private_data; in ep93xx_pata_port_start()
872 drv_data->t = *ata_timing_find_mode(XFER_PIO_0); in ep93xx_pata_port_start()
931 err = -ENXIO; in ep93xx_pata_probe()
936 ide_base = devm_ioremap_resource(&pdev->dev, mem_res); in ep93xx_pata_probe()
942 drv_data = devm_kzalloc(&pdev->dev, sizeof(*drv_data), GFP_KERNEL); in ep93xx_pata_probe()
944 err = -ENXIO; in ep93xx_pata_probe()
948 drv_data->pdev = pdev; in ep93xx_pata_probe()
949 drv_data->ide_base = ide_base; in ep93xx_pata_probe()
950 drv_data->udma_in_phys = mem_res->start + IDEUDMADATAIN; in ep93xx_pata_probe()
951 drv_data->udma_out_phys = mem_res->start + IDEUDMADATAOUT; in ep93xx_pata_probe()
955 host = ata_host_alloc(&pdev->dev, 1); in ep93xx_pata_probe()
957 err = -ENXIO; in ep93xx_pata_probe()
963 host->private_data = drv_data; in ep93xx_pata_probe()
965 ap = host->ports[0]; in ep93xx_pata_probe()
966 ap->dev = &pdev->dev; in ep93xx_pata_probe()
967 ap->ops = &ep93xx_pata_port_ops; in ep93xx_pata_probe()
968 ap->flags |= ATA_FLAG_SLAVE_POSS; in ep93xx_pata_probe()
969 ap->pio_mask = ATA_PIO4; in ep93xx_pata_probe()
973 * EP931x rev.E0 - UDMA2 in ep93xx_pata_probe()
974 * EP931x rev.E1 - UDMA3 in ep93xx_pata_probe()
975 * EP931x rev.E2 - UDMA4 in ep93xx_pata_probe()
980 if (drv_data->dma_rx_channel && drv_data->dma_tx_channel) { in ep93xx_pata_probe()
984 ap->udma_mask = ATA_UDMA3; in ep93xx_pata_probe()
986 ap->udma_mask = ATA_UDMA4; in ep93xx_pata_probe()
988 ap->udma_mask = ATA_UDMA2; in ep93xx_pata_probe()
994 dev_info(&pdev->dev, "version " DRV_VERSION "\n"); in ep93xx_pata_probe()
1012 struct ep93xx_pata_data *drv_data = host->private_data; in ep93xx_pata_remove()
1016 ep93xx_pata_clear_regs(drv_data->ide_base); in ep93xx_pata_remove()
1033 MODULE_DESCRIPTION("low-level driver for cirrus ep93xx IDE controller");