/* Previous variants of this driver used to calculate timings *forvariousvariantsofthechipandusetablesforothers. * *Notonlywasthisconfusing,butinaddition,itisn'tclear *whetherourcalculationcodewascorrect.Itdidn'tentirely *matchthedarwincodeandwhateverdocumentationIcouldfind *onthesecells * *Idecidedtoentirelyrelyonatableinsteadforthisversion *ofthedriver.Also,becauseIdon'treallycareaboutderated *modesandreallyoldHWotherthanmakingitwork,I'mnotgoing *tocalculate/snooptimingvaluesforsomethingelsethanthe *standardmodes.
*/ struct pata_macio_timing { int mode;
u32 reg1; /* Bits to set in first timing reg */
u32 reg2; /* Bits to set in second timing reg */
};
/* First clear timings */
priv->treg[adev->devno][0] = priv->treg[adev->devno][1] = 0;
/* Now get the PIO timings */
t = pata_macio_find_timing(priv, adev->pio_mode); if (t == NULL) {
dev_warn(priv->dev, "Invalid PIO timing requested: 0x%x\n",
adev->pio_mode);
t = pata_macio_find_timing(priv, XFER_PIO_0);
}
BUG_ON(t == NULL);
/* PIO timings only ever use the first treg */
priv->treg[adev->devno][0] |= t->reg1;
/* Now get DMA timings */
t = pata_macio_find_timing(priv, adev->dma_mode); if (t == NULL || (t->reg1 == 0 && t->reg2 == 0)) {
dev_dbg(priv->dev, "DMA timing not set yet, using MW_DMA_0\n");
t = pata_macio_find_timing(priv, XFER_MW_DMA_0);
}
BUG_ON(t == NULL);
/* DMA timings can use both tregs */
priv->treg[adev->devno][0] |= t->reg1;
priv->treg[adev->devno][1] |= t->reg2;
switch(priv->kind) { case controller_sh_ata6:
value = 0x0a820c97;
value2 = 0x00033031; break; case controller_un_ata6: case controller_k2_ata6:
value = 0x08618a92;
value2 = 0x00002921; break; case controller_kl_ata4:
value = 0x0008438c; break; case controller_kl_ata3:
value = 0x00084526; break; case controller_heathrow: case controller_ohare: default:
value = 0x00074526; break;
}
priv->treg[0][0] = priv->treg[1][0] = value;
priv->treg[0][1] = priv->treg[1][1] = value2;
}
if (cable && !strncmp(cable, "80-", 3)) { /* Some drives fail to detect 80c cable in PowerBook *ThesemachineuseproprietaryshortIDEcable *anyway
*/ if (!strncmp(model, "PowerBook", 9)) return ATA_CBL_PATA40_SHORT; else return ATA_CBL_PATA80;
}
}
/* G5's seem to have incorrect cable type in device-tree. *Let'sassumetheyalwayshavea80conductorcable,thisseemto *bealwaysthecaseunlesstheusermuckedaround
*/ if (of_device_is_compatible(priv->node, "K2-UATA") ||
of_device_is_compatible(priv->node, "shasta-ata")) return ATA_CBL_PATA80;
/* Anything else is 40 connectors */ return ATA_CBL_PATA40;
}
/* Make sure DMA commands updates are visible */
writel(priv->dma_table_dma, &dma_regs->cmdptr);
/* On KeyLargo 66Mhz cell, we need to add 60ns to wrDataSetup on *UDMAreads
*/ if (priv->kind == controller_kl_ata4 &&
(priv->treg[dev][0] & TR_66_UDMA_EN)) { void __iomem *rbase = ap->ioaddr.cmd_addr;
u32 reg = priv->treg[dev][0];
/* Stop the DMA engine and wait for it to full halt */
writel (((RUN|WAKE|DEAD) << 16), &dma_regs->control); while (--timeout && (readl(&dma_regs->status) & RUN))
udelay(1);
}
/* We have two things to deal with here: * *-Thedbdmawon'tstopifthecommandwasstarted *butcompletedwithanerrorwithouttransferringall *datas.Thishappenswhenbadblocksaremetduring *amulti-blocktransfer. * *-Thedbdmafifohasn'tyetfinishedflushingto *systemmemorywhenthediskinterruptoccurs.
*/
/* First check for errors */ if ((dstat & (RUN|DEAD)) != RUN)
rstat |= ATA_DMA_ERR;
/* If ACTIVE is cleared, the STOP command has been hit and *thetransferiscomplete.Ifnot,wehavetoflushthe *channel.
*/ if ((dstat & ACTIVE) == 0) return rstat;
dev_dbgdma(priv->dev, "%s: DMA still active, flushing...\n", __func__);
/* If dbdma didn't execute the STOP command yet, the *activebitisstillset.Weconsiderthatwearen't *sharinginterrupts(whichishopefullythecasewith *thosecontrollers)andsowejusttrytoflushthe *channelforpendingdatainthefifo
*/
udelay(1);
writel((FLUSH << 16) | FLUSH, &dma_regs->control); for (;;) {
udelay(1);
dstat = readl(&dma_regs->status); if ((dstat & FLUSH) == 0) break; if (++timeout > 1000) {
dev_warn(priv->dev, "timeout flushing DMA\n");
rstat |= ATA_DMA_ERR; break;
}
} return rstat;
}
/* port_start is when we allocate the DMA command list */ staticint pata_macio_port_start(struct ata_port *ap)
{ struct pata_macio_priv *priv = ap->private_data;
if (ap->ioaddr.bmdma_addr == NULL) return0;
/* Allocate space for the DBDMA commands. * *The+2is+1forthestopcommandand+1toallowfor *aligningthestartaddresstoamultipleof16bytes.
*/
priv->dma_table_cpu =
dmam_alloc_coherent(priv->dev,
(MAX_DCMDS + 2) * sizeof(struct dbdma_cmd),
&priv->dma_table_dma, GFP_KERNEL); if (priv->dma_table_cpu == NULL) {
dev_err(priv->dev, "Unable to allocate DMA command list\n");
ap->ioaddr.bmdma_addr = NULL;
ap->mwdma_mask = 0;
ap->udma_mask = 0;
} return0;
}
if (priv->kind == controller_ohare && !resume) { /* The code below is having trouble on some ohare machines *(timingrelated?).UntilIcanputmyhandononeofthese *units,Ikeeptheoldway
*/
ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, priv->node, 0, 1);
} else { int rc;
/* Reset and enable controller */
rc = ppc_md.feature_call(PMAC_FTR_IDE_RESET,
priv->node, priv->aapl_bus_id, 1);
ppc_md.feature_call(PMAC_FTR_IDE_ENABLE,
priv->node, priv->aapl_bus_id, 1);
msleep(10); /* Only bother waiting if there's a reset control */ if (rc == 0) {
ppc_md.feature_call(PMAC_FTR_IDE_RESET,
priv->node, priv->aapl_bus_id, 0);
msleep(IDE_WAKEUP_DELAY_MS);
}
}
/* If resuming a PCI device, restore the config space here */ if (priv->pdev && resume) { int rc;
pci_restore_state(priv->pdev);
rc = pcim_enable_device(priv->pdev); if (rc)
dev_err(&priv->pdev->dev, "Failed to enable device after resume (%d)\n",
rc); else
pci_set_master(priv->pdev);
}
/* On Kauai, initialize the FCR. We don't perform a reset, doesn't really *seemnecessaryandspeedsupthebootprocess
*/ if (priv->kauai_fcr)
writel(KAUAI_FCR_UATA_MAGIC |
KAUAI_FCR_UATA_RESET_N |
KAUAI_FCR_UATA_ENABLE, priv->kauai_fcr);
}
/* Hook the standard slave config to fixup some HW related alignment *restrictions
*/ staticint pata_macio_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
{ struct ata_port *ap = ata_shost_to_port(sdev->host); struct pata_macio_priv *priv = ap->private_data; struct ata_device *dev;
u16 cmd; int rc;
/* First call original */
rc = ata_scsi_sdev_configure(sdev, lim); if (rc) return rc;
/* This is lifted from sata_nv */
dev = &ap->link.device[sdev->id];
/* OHare has issues with non cache aligned DMA on some chipsets */ if (priv->kind == controller_ohare) {
lim->dma_alignment = 31;
lim->dma_pad_mask = 31;
/* Tell the world about it */
ata_dev_info(dev, "OHare alignment limits applied\n"); return0;
}
/* We only have issues with ATAPI */ if (dev->class != ATA_DEV_ATAPI) return0;
/* Shasta and K2 seem to have "issues" with reads ... */ if (priv->kind == controller_sh_ata6 || priv->kind == controller_k2_ata6) { /* Allright these are bad, apply restrictions */
lim->dma_alignment = 15;
lim->dma_pad_mask = 15;
/* We enable MWI and hack cache line size directly here, this *isspecifictothischipsetandnotnormalvalues,wehappen *tosomewhatknowwhatwearedoinghere(whichisbasically *todothesameAppledoesandpraytheydidnotgetitwrong:-)
*/
BUG_ON(!priv->pdev);
pci_write_config_byte(priv->pdev, PCI_CACHE_LINE_SIZE, 0x08);
pci_read_config_word(priv->pdev, PCI_COMMAND, &cmd);
pci_write_config_word(priv->pdev, PCI_COMMAND,
cmd | PCI_COMMAND_INVALIDATE);
/* Tell the world about it */
ata_dev_info(dev, "K2/Shasta alignment limits applied\n");
}
return0;
}
#ifdef CONFIG_PM_SLEEP staticint pata_macio_do_suspend(struct pata_macio_priv *priv, pm_message_t mesg)
{ /* First, core libata suspend to do most of the work */
ata_host_suspend(priv->host, mesg);
/* Restore to default timings */
pata_macio_default_timings(priv);
/* Mask interrupt. Not strictly necessary but old driver did
* it and I'd rather not change that here */
disable_irq(priv->irq);
/* The media bay will handle itself just fine */ if (priv->mediabay) return0;
/* Kauai has bus control FCRs directly here */ if (priv->kauai_fcr) {
u32 fcr = readl(priv->kauai_fcr);
fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE);
writel(fcr, priv->kauai_fcr);
}
/* For PCI, save state and disable DMA. No need to call *pci_set_power_state(),theHWdoesn'tdoDstatesthat *way,theplatformcodewilltakecareofsuspendingthe *ASICproperly
*/ if (priv->pdev) {
pci_save_state(priv->pdev);
pci_disable_device(priv->pdev);
}
/* Disable the bus on older machines and the cell on kauai */
ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, priv->node,
priv->aapl_bus_id, 0);
return0;
}
staticint pata_macio_do_resume(struct pata_macio_priv *priv)
{ /* Reset and re-enable the HW */
pata_macio_reset_hw(priv, 1);
/* Get Apple bus ID (for clock and ASIC control) */
bidp = of_get_property(priv->node, "AAPL,bus-id", NULL);
priv->aapl_bus_id = bidp ? *bidp : 0;
/* Fixup missing Apple bus ID in case of media-bay */ if (priv->mediabay && !bidp)
priv->aapl_bus_id = 1;
}
staticvoid pata_macio_setup_ios(struct ata_ioports *ioaddr, void __iomem * base, void __iomem * dma)
{ /* cmd_addr is the base of regs for that port */
ioaddr->cmd_addr = base;
/* taskfile registers */
ioaddr->data_addr = base + (ATA_REG_DATA << 4);
ioaddr->error_addr = base + (ATA_REG_ERR << 4);
ioaddr->feature_addr = base + (ATA_REG_FEATURE << 4);
ioaddr->nsect_addr = base + (ATA_REG_NSECT << 4);
ioaddr->lbal_addr = base + (ATA_REG_LBAL << 4);
ioaddr->lbam_addr = base + (ATA_REG_LBAM << 4);
ioaddr->lbah_addr = base + (ATA_REG_LBAH << 4);
ioaddr->device_addr = base + (ATA_REG_DEVICE << 4);
ioaddr->status_addr = base + (ATA_REG_STATUS << 4);
ioaddr->command_addr = base + (ATA_REG_CMD << 4);
ioaddr->altstatus_addr = base + 0x160;
ioaddr->ctl_addr = base + 0x160;
ioaddr->bmdma_addr = dma;
}
staticvoid pmac_macio_calc_timing_masks(struct pata_macio_priv *priv, struct ata_port_info *pinfo)
{ int i = 0;
priv->host = ata_host_alloc_pinfo(priv->dev, ppi, 1); if (priv->host == NULL) {
dev_err(priv->dev, "Failed to allocate ATA port structure\n"); return -ENOMEM;
}
/* Setup the private data in host too */
priv->host->private_data = priv;
/* Map base registers */
priv->tfregs = devm_ioremap(priv->dev, tfregs, 0x100); if (priv->tfregs == NULL) {
dev_err(priv->dev, "Failed to map ATA ports\n"); return -ENOMEM;
}
priv->host->iomap = &priv->tfregs;
/* Map DMA regs */ if (dmaregs != 0) {
dma_regs = devm_ioremap(priv->dev, dmaregs, sizeof(struct dbdma_regs)); if (dma_regs == NULL)
dev_warn(priv->dev, "Failed to map ATA DMA registers\n");
}
/* If chip has local feature control, map those regs too */ if (fcregs != 0) {
priv->kauai_fcr = devm_ioremap(priv->dev, fcregs, 4); if (priv->kauai_fcr == NULL) {
dev_err(priv->dev, "Failed to map ATA FCR register\n"); return -ENOMEM;
}
}
/* Setup port data structure */
pata_macio_setup_ios(&priv->host->ports[0]->ioaddr,
priv->tfregs, dma_regs);
priv->host->ports[0]->private_data = priv;
/* hard-reset the controller */
pata_macio_reset_hw(priv, 0);
pata_macio_apply_timings(priv->host->ports[0], 0);
/* Enable bus master if necessary */ if (priv->pdev && dma_regs)
pci_set_master(priv->pdev);
dev_info(priv->dev, "Activating pata-macio chipset %s, Apple bus ID %d\n",
macio_ata_names[priv->kind], priv->aapl_bus_id);
/* Start it up */
priv->irq = irq; return ata_host_activate(priv->host, irq, ata_bmdma_interrupt, 0,
&pata_macio_sht);
}
/* Check for broken device-trees */ if (macio_resource_count(mdev) == 0) {
dev_err(&mdev->ofdev.dev, "No addresses for controller\n"); return -ENXIO;
}
/* We cannot use a MacIO controller without its OF device node */
np = pci_device_to_OF_node(pdev); if (np == NULL) {
dev_err(&pdev->dev, "Cannot find OF device node for controller\n"); return -ENODEV;
}
/* Check that it can be enabled */ if (pcim_enable_device(pdev)) {
dev_err(&pdev->dev, "Cannot enable controller PCI device\n"); return -ENXIO;
}
/* Allocate and init private data structure */
priv = devm_kzalloc(&pdev->dev, sizeof(struct pata_macio_priv), GFP_KERNEL); if (!priv) return -ENOMEM;
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.