// SPDX-License-Identifier: GPL-2.0-only /* * EP93XX PATA controller driver. * * Copyright (c) 2012, Metasoft s.c. * Rafal Prylowski <prylowski@metasoft.pl> * * Based on pata_scc.c, pata_icside.c and on earlier version of EP93XX * PATA driver by Lennert Buytenhek and Alessandro Zummo. * Read/Write timings, resource management and other improvements * from driver by Joao Ramos and Bartlomiej Zolnierkiewicz. * DMA engine support based on spi-ep93xx.c by Mika Westerberg. * * Original copyrights: * * Support for Cirrus Logic's EP93xx (EP9312, EP9315) CPUs * PATA host controller driver. * * Copyright (c) 2009, Bartlomiej Zolnierkiewicz * * Heavily based on the ep93xx-ide.c driver: * * Copyright (c) 2009, Joao Ramos <joao.ramos@inov.pt> * INESC Inovacao (INOV) * * EP93XX PATA controller driver. * Copyright (C) 2007 Lennert Buytenhek <buytenh@wantstofly.org> * * An ATA driver for the Cirrus Logic EP93xx PATA controller. * * Based on an earlier version by Alessandro Zummo, which is: * Copyright (C) 2006 Tower Technologies
*/
writel(0, base + IDECFG);
writel(0, base + IDEMDMAOP);
writel(0, base + IDEUDMAOP);
writel(0, base + IDEDATAOUT);
writel(0, base + IDEDATAIN);
writel(0, base + IDEMDMADATAOUT);
writel(0, base + IDEMDMADATAIN);
writel(0, base + IDEUDMADATAOUT);
writel(0, base + IDEUDMADATAIN);
writel(0, base + IDEUDMADEBUG);
}
/* * According to EP93xx User's Guide, WST field of IDECFG specifies number * of HCLK cycles to hold the data bus after a PIO write operation. * It should be programmed to guarantee following delays: * * PIO Mode [ns] * 0 30 * 1 20 * 2 15 * 3 10 * 4 5 * * Maximum possible value for HCLK is 100MHz.
*/ staticint ep93xx_pata_get_wst(int pio_mode)
{ int val;
if (pio_mode == 0)
val = 3; elseif (pio_mode < 3)
val = 2; else
val = 1;
return val << IDECFG_WST_SHIFT;
}
staticvoid ep93xx_pata_enable_pio(void __iomem *base, int pio_mode)
{
writel(IDECFG_IDEEN | IDECFG_PIO |
ep93xx_pata_get_wst(pio_mode) |
(pio_mode << IDECFG_MODE_SHIFT), base + IDECFG);
}
/* * Based on delay loop found in mach-pxa/mp900.c. * * Single iteration should take 5 cpu cycles. This is 25ns assuming the * fastest ep93xx cpu speed (200MHz) and is better optimized for PIO4 timings * than eg. 20ns.
*/ staticvoid ep93xx_pata_delay(unsignedlong count)
{
__asm__ volatile ( "0:\n" "mov r0, r0\n" "subs %0, %1, #1\n" "bge 0b\n"
: "=r" (count)
: "0" (count)
);
}
staticunsignedlong ep93xx_pata_wait_for_iordy(void __iomem *base, unsignedlong t2)
{ /* * According to ATA specification, IORDY pin can be first sampled * tA = 35ns after activation of DIOR-/DIOW-. Maximum IORDY pulse * width is tB = 1250ns. * * We are already t2 delay loop iterations after activation of * DIOR-/DIOW-, so we set timeout to (1250 + 35) / 25 - t2 additional * delay loop iterations.
*/ unsignedlong start = (1250 + 35) / 25 - t2; unsignedlong counter = start;
while (!ep93xx_pata_check_iordy(base) && counter--)
ep93xx_pata_delay(1); return start - counter;
}
/* common part at start of ep93xx_pata_read/write() */ staticvoid ep93xx_pata_rw_begin(void __iomem *base, unsignedlong addr, unsignedlong t1)
{
writel(IDECTRL_DIOWN | IDECTRL_DIORN | addr, base + IDECTRL);
ep93xx_pata_delay(t1);
}
/* common part at end of ep93xx_pata_read/write() */ staticvoid ep93xx_pata_rw_end(void __iomem *base, unsignedlong addr, bool iordy, unsignedlong t0, unsignedlong t2, unsignedlong t2i)
{
ep93xx_pata_delay(t2); /* lengthen t2 if needed */ if (iordy)
t2 += ep93xx_pata_wait_for_iordy(base, t2);
writel(IDECTRL_DIOWN | IDECTRL_DIORN | addr, base + IDECTRL); if (t0 > t2 && t0 - t2 > t2i)
ep93xx_pata_delay(t0 - t2); else
ep93xx_pata_delay(t2i);
}
ep93xx_pata_rw_begin(base, addr, t->setup);
writel(IDECTRL_DIOWN | addr, base + IDECTRL); /* * The IDEDATAIN register is loaded from the DD pins at the positive * edge of the DIORN signal. (EP93xx UG p27-14)
*/
ep93xx_pata_rw_end(base, addr, drv_data->iordy, t0, t2, t2i); return readl(base + IDEDATAIN);
}
ep93xx_pata_rw_begin(base, addr, t->setup); /* * Value from IDEDATAOUT register is driven onto the DD pins when * DIOWN is low. (EP93xx UG p27-13)
*/
writel(value, base + IDEDATAOUT);
writel(IDECTRL_DIORN | addr, base + IDECTRL);
ep93xx_pata_rw_end(base, addr, drv_data->iordy, t0, t2, t2i);
}
/* PIO data write */ staticvoid ep93xx_pata_write_data(struct ep93xx_pata_data *drv_data,
u16 value, unsignedlong addr)
{
ep93xx_pata_write(drv_data, value, addr, false);
}
staticvoid ep93xx_pata_set_piomode(struct ata_port *ap, struct ata_device *adev)
{ struct ep93xx_pata_data *drv_data = ap->host->private_data; struct ata_device *pair = ata_dev_pair(adev); /* * Calculate timings for the delay loop, assuming ep93xx cpu speed * is 200MHz (maximum possible for ep93xx). If actual cpu speed is * slower, we will wait a bit longer in each delay. * Additional division of cpu speed by 5, because single iteration * of our delay loop takes 5 cpu cycles (25ns).
*/ unsignedlong T = 1000000 / (200 / 5);
/* always check readiness of the master device */
rc = ata_sff_wait_ready(link, deadline); /* * -ENODEV means the odd clown forgot the D7 pulldown resistor * and TF status is 0xff, bail out on it too.
*/ if (rc) return rc;
/* * if device 1 was found in ata_devchk, wait for register * access briefly, then wait for BSY to clear.
*/ if (dev1) { int i;
ap->ops->sff_dev_select(ap, 1);
/* * Wait for register access. Some ATAPI devices fail * to set nsect/lbal after reset, so don't waste too * much time on it. We're gonna wait for !BSY anyway.
*/ for (i = 0; i < 2; i++) {
u8 nsect, lbal;
nsect = ep93xx_pata_read_reg(drv_data,
IDECTRL_ADDR_NSECT);
lbal = ep93xx_pata_read_reg(drv_data,
IDECTRL_ADDR_LBAL); if (nsect == 1 && lbal == 1) break;
msleep(50); /* give drive a breather */
}
rc = ata_sff_wait_ready(link, deadline); if (rc) { if (rc != -ENODEV) return rc;
ret = rc;
}
} /* is all this really necessary? */
ap->ops->sff_dev_select(ap, 0); if (dev1)
ap->ops->sff_dev_select(ap, 1); if (dev0)
ap->ops->sff_dev_select(ap, 0);
/* * Request two channels for IDE. Another possibility would be * to request only one channel, and reprogram it's direction at * start of new transfer.
*/
drv_data->dma_rx_channel = dma_request_chan(dev, "rx"); if (IS_ERR(drv_data->dma_rx_channel)) return dev_err_probe(dev, PTR_ERR(drv_data->dma_rx_channel), "rx DMA setup failed\n");
drv_data->dma_tx_channel = dma_request_chan(&pdev->dev, "tx"); if (IS_ERR(drv_data->dma_tx_channel)) {
ret = dev_err_probe(dev, PTR_ERR(drv_data->dma_tx_channel), "tx DMA setup failed\n"); goto fail_release_rx;
}
/* Configure receive channel direction and source address */
memset(&conf, 0, sizeof(conf));
conf.direction = DMA_DEV_TO_MEM;
conf.src_addr = drv_data->udma_in_phys;
conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
ret = dmaengine_slave_config(drv_data->dma_rx_channel, &conf); if (ret) {
dev_err_probe(dev, ret, "failed to configure rx dma channel"); goto fail_release_dma;
}
/* Configure transmit channel direction and destination address */
memset(&conf, 0, sizeof(conf));
conf.direction = DMA_MEM_TO_DEV;
conf.dst_addr = drv_data->udma_out_phys;
conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
ret = dmaengine_slave_config(drv_data->dma_tx_channel, &conf); if (ret) {
dev_err_probe(dev, ret, "failed to configure tx dma channel"); goto fail_release_dma;
}
txd = dmaengine_prep_slave_sg(channel, qc->sg, qc->n_elem, qc->dma_dir,
DMA_CTRL_ACK); if (!txd) {
dev_err(qc->ap->dev, "failed to prepare slave for sg dma\n"); return;
}
txd->callback = NULL;
txd->callback_param = NULL;
if (dmaengine_submit(txd) < 0) {
dev_err(qc->ap->dev, "failed to submit dma transfer\n"); return;
}
dma_async_issue_pending(channel);
/* * When enabling UDMA operation, IDEUDMAOP register needs to be * programmed in three step sequence: * 1) set or clear the RWOP bit, * 2) perform dummy read of the register, * 3) set the UEN bit.
*/
writel(v, base + IDEUDMAOP);
readl(base + IDEUDMAOP);
writel(v | IDEUDMAOP_UEN, base + IDEUDMAOP);
/* terminate all dma transfers, if not yet finished */
dmaengine_terminate_all(drv_data->dma_rx_channel);
dmaengine_terminate_all(drv_data->dma_tx_channel);
/* * To properly stop IDE-DMA, IDEUDMAOP register must to be cleared * and IDECTRL register must be set to default value.
*/
writel(0, base + IDEUDMAOP);
writel(readl(base + IDECTRL) | IDECTRL_DIOWN | IDECTRL_DIORN |
IDECTRL_CS0N | IDECTRL_CS1N, base + IDECTRL);
/* * UDMA Status Register bits: * * DMAIDE - DMA request signal from UDMA state machine, * INTIDE - INT line generated by UDMA because of errors in the * state machine, * SBUSY - UDMA state machine busy, not in idle state, * NDO - error for data-out not completed, * NDI - error for data-in not completed, * N4X - error for data transferred not multiplies of four * 32-bit words. * (EP93xx UG p27-17)
*/ if (val & IDEUDMASTS_NDO || val & IDEUDMASTS_NDI ||
val & IDEUDMASTS_N4X || val & IDEUDMASTS_INTIDE) return ATA_DMA_ERR;
/* read INTRQ (INT[3]) pin input state */ if (readl(drv_data->ide_base + IDECTRL) & IDECTRL_INTRQ) return ATA_DMA_INTR;
if (val & IDEUDMASTS_SBUSY || val & IDEUDMASTS_DMAIDE) return ATA_DMA_ACTIVE;
/* determine if device 0/1 are present */ if (ep93xx_pata_device_is_present(ap, 0))
devmask |= (1 << 0); if (slave_possible && ep93xx_pata_device_is_present(ap, 1))
devmask |= (1 << 1);
/* select device 0 again */
ap->ops->sff_dev_select(al->ap, 0);
/* issue bus reset */
rc = ep93xx_pata_bus_softreset(ap, devmask, deadline); /* if link is ocuppied, -ENODEV too is an error */ if (rc && (rc != -ENODEV || sata_scr_valid(al))) {
ata_link_err(al, "SRST failed (errno=%d)\n", rc); return rc;
}
/* determine by signature whether we have ATA or ATAPI devices */
classes[0] = ata_sff_dev_classify(&al->device[0], devmask & (1 << 0),
&err); if (slave_possible && err != 0x81)
classes[1] = ata_sff_dev_classify(&al->device[1],
devmask & (1 << 1), &err);
return 0;
}
/* Note: original code is ata_sff_drain_fifo */ staticvoid ep93xx_pata_drain_fifo(struct ata_queued_cmd *qc)
{ int count; struct ata_port *ap; struct ep93xx_pata_data *drv_data;
/* We only need to flush incoming data when a command was running */ if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE) return;
ap = qc->ap;
drv_data = ap->host->private_data; /* Drain up to 64K of data before we give up this recovery method */ for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ)
&& count < 65536; count += 2)
ep93xx_pata_read_reg(drv_data, IDECTRL_ADDR_DATA);
if (count)
ata_port_dbg(ap, "drained %d bytes to clear DRQ.\n", count);
/* * Set timings to safe values at startup (= number of ns from ATA * specification), we'll switch to properly calculated values later.
*/
drv_data->t = *ata_timing_find_mode(XFER_PIO_0); return 0;
}
staticconststruct scsi_host_template ep93xx_pata_sht = {
ATA_BASE_SHT(DRV_NAME), /* ep93xx dma implementation limit */
.sg_tablesize = 32, /* ep93xx dma can't transfer 65536 bytes at once */
.dma_boundary = 0x7fff,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.