2006-08-30 06:12:40 +08:00
|
|
|
/*
|
|
|
|
* pata_atiixp.c - ATI PATA for new ATA layer
|
|
|
|
* (C) 2005 Red Hat Inc
|
|
|
|
* Alan Cox <alan@redhat.com>
|
|
|
|
*
|
|
|
|
* Based on
|
|
|
|
*
|
|
|
|
* linux/drivers/ide/pci/atiixp.c Version 0.01-bart2 Feb. 26, 2004
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 ATI Inc. <hyu@ati.com>
|
|
|
|
* Copyright (C) 2004 Bartlomiej Zolnierkiewicz
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <linux/libata.h>
|
|
|
|
|
|
|
|
#define DRV_NAME "pata_atiixp"
|
2007-08-31 16:54:06 +08:00
|
|
|
#define DRV_VERSION "0.4.6"
|
2006-08-30 06:12:40 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ATIIXP_IDE_PIO_TIMING = 0x40,
|
|
|
|
ATIIXP_IDE_MWDMA_TIMING = 0x44,
|
|
|
|
ATIIXP_IDE_PIO_CONTROL = 0x48,
|
|
|
|
ATIIXP_IDE_PIO_MODE = 0x4a,
|
|
|
|
ATIIXP_IDE_UDMA_CONTROL = 0x54,
|
|
|
|
ATIIXP_IDE_UDMA_MODE = 0x56
|
|
|
|
};
|
|
|
|
|
2007-08-06 17:36:23 +08:00
|
|
|
static int atiixp_pre_reset(struct ata_link *link, unsigned long deadline)
|
2006-08-30 06:12:40 +08:00
|
|
|
{
|
2007-08-06 17:36:23 +08:00
|
|
|
struct ata_port *ap = link->ap;
|
2007-02-01 01:10:46 +08:00
|
|
|
static const struct pci_bits atiixp_enable_bits[] = {
|
2006-08-30 06:12:40 +08:00
|
|
|
{ 0x48, 1, 0x01, 0x00 },
|
|
|
|
{ 0x48, 1, 0x08, 0x00 }
|
|
|
|
};
|
2007-03-09 03:27:31 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
2006-08-30 06:12:40 +08:00
|
|
|
|
2006-09-27 00:53:38 +08:00
|
|
|
if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
|
|
|
|
return -ENOENT;
|
|
|
|
|
2008-04-07 21:47:16 +08:00
|
|
|
return ata_sff_prereset(link, deadline);
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
|
2007-03-09 03:27:31 +08:00
|
|
|
static int atiixp_cable_detect(struct ata_port *ap)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
|
|
|
u8 udma;
|
|
|
|
|
|
|
|
/* Hack from drivers/ide/pci. Really we want to know how to do the
|
|
|
|
raw detection not play follow the bios mode guess */
|
|
|
|
pci_read_config_byte(pdev, ATIIXP_IDE_UDMA_MODE + ap->port_no, &udma);
|
|
|
|
if ((udma & 0x07) >= 0x04 || (udma & 0x70) >= 0x40)
|
|
|
|
return ATA_CBL_PATA80;
|
|
|
|
return ATA_CBL_PATA40;
|
|
|
|
}
|
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
/**
|
|
|
|
* atiixp_set_pio_timing - set initial PIO mode data
|
|
|
|
* @ap: ATA interface
|
|
|
|
* @adev: ATA device
|
|
|
|
*
|
|
|
|
* Called by both the pio and dma setup functions to set the controller
|
|
|
|
* timings for PIO transfers. We must load both the mode number and
|
|
|
|
* timing values into the controller.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void atiixp_set_pio_timing(struct ata_port *ap, struct ata_device *adev, int pio)
|
|
|
|
{
|
|
|
|
static u8 pio_timings[5] = { 0x5D, 0x47, 0x34, 0x22, 0x20 };
|
|
|
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
|
|
|
int dn = 2 * ap->port_no + adev->devno;
|
|
|
|
|
|
|
|
/* Check this is correct - the order is odd in both drivers */
|
|
|
|
int timing_shift = (16 * ap->port_no) + 8 * (adev->devno ^ 1);
|
|
|
|
u16 pio_mode_data, pio_timing_data;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_PIO_MODE, &pio_mode_data);
|
|
|
|
pio_mode_data &= ~(0x7 << (4 * dn));
|
|
|
|
pio_mode_data |= pio << (4 * dn);
|
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_PIO_MODE, pio_mode_data);
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_PIO_TIMING, &pio_timing_data);
|
2008-04-30 05:39:45 +08:00
|
|
|
pio_timing_data &= ~(0xFF << timing_shift);
|
|
|
|
pio_timing_data |= (pio_timings[pio] << timing_shift);
|
2006-08-30 06:12:40 +08:00
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_PIO_TIMING, pio_timing_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atiixp_set_piomode - set initial PIO mode data
|
|
|
|
* @ap: ATA interface
|
|
|
|
* @adev: ATA device
|
|
|
|
*
|
|
|
|
* Called to do the PIO mode setup. We use a shared helper for this
|
|
|
|
* as the DMA setup must also adjust the PIO timing information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void atiixp_set_piomode(struct ata_port *ap, struct ata_device *adev)
|
|
|
|
{
|
|
|
|
atiixp_set_pio_timing(ap, adev, adev->pio_mode - XFER_PIO_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atiixp_set_dmamode - set initial DMA mode data
|
|
|
|
* @ap: ATA interface
|
|
|
|
* @adev: ATA device
|
|
|
|
*
|
|
|
|
* Called to do the DMA mode setup. We use timing tables for most
|
|
|
|
* modes but must tune an appropriate PIO mode to match.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void atiixp_set_dmamode(struct ata_port *ap, struct ata_device *adev)
|
|
|
|
{
|
|
|
|
static u8 mwdma_timings[5] = { 0x77, 0x21, 0x20 };
|
|
|
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
|
|
|
int dma = adev->dma_mode;
|
|
|
|
int dn = 2 * ap->port_no + adev->devno;
|
|
|
|
int wanted_pio;
|
|
|
|
|
|
|
|
if (adev->dma_mode >= XFER_UDMA_0) {
|
|
|
|
u16 udma_mode_data;
|
|
|
|
|
|
|
|
dma -= XFER_UDMA_0;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_UDMA_MODE, &udma_mode_data);
|
|
|
|
udma_mode_data &= ~(0x7 << (4 * dn));
|
|
|
|
udma_mode_data |= dma << (4 * dn);
|
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_UDMA_MODE, udma_mode_data);
|
|
|
|
} else {
|
|
|
|
u16 mwdma_timing_data;
|
|
|
|
/* Check this is correct - the order is odd in both drivers */
|
|
|
|
int timing_shift = (16 * ap->port_no) + 8 * (adev->devno ^ 1);
|
|
|
|
|
|
|
|
dma -= XFER_MW_DMA_0;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_MWDMA_TIMING, &mwdma_timing_data);
|
|
|
|
mwdma_timing_data &= ~(0xFF << timing_shift);
|
|
|
|
mwdma_timing_data |= (mwdma_timings[dma] << timing_shift);
|
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_MWDMA_TIMING, mwdma_timing_data);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We must now look at the PIO mode situation. We may need to
|
|
|
|
* adjust the PIO mode to keep the timings acceptable
|
|
|
|
*/
|
|
|
|
if (adev->dma_mode >= XFER_MW_DMA_2)
|
|
|
|
wanted_pio = 4;
|
|
|
|
else if (adev->dma_mode == XFER_MW_DMA_1)
|
|
|
|
wanted_pio = 3;
|
|
|
|
else if (adev->dma_mode == XFER_MW_DMA_0)
|
|
|
|
wanted_pio = 0;
|
|
|
|
else BUG();
|
|
|
|
|
|
|
|
if (adev->pio_mode != wanted_pio)
|
|
|
|
atiixp_set_pio_timing(ap, adev, wanted_pio);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atiixp_bmdma_start - DMA start callback
|
|
|
|
* @qc: Command in progress
|
|
|
|
*
|
|
|
|
* When DMA begins we need to ensure that the UDMA control
|
|
|
|
* register for the channel is correctly set.
|
2007-09-27 06:02:52 +08:00
|
|
|
*
|
|
|
|
* Note: The host lock held by the libata layer protects
|
|
|
|
* us from two channels both trying to set DMA bits at once
|
2006-08-30 06:12:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void atiixp_bmdma_start(struct ata_queued_cmd *qc)
|
|
|
|
{
|
|
|
|
struct ata_port *ap = qc->ap;
|
|
|
|
struct ata_device *adev = qc->dev;
|
|
|
|
|
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
|
|
|
int dn = (2 * ap->port_no) + adev->devno;
|
|
|
|
u16 tmp16;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
|
2008-08-01 16:18:34 +08:00
|
|
|
if (ata_using_udma(adev))
|
2006-08-30 06:12:40 +08:00
|
|
|
tmp16 |= (1 << dn);
|
|
|
|
else
|
|
|
|
tmp16 &= ~(1 << dn);
|
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
|
|
|
|
ata_bmdma_start(qc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* atiixp_dma_stop - DMA stop callback
|
|
|
|
* @qc: Command in progress
|
|
|
|
*
|
|
|
|
* DMA has completed. Clear the UDMA flag as the next operations will
|
|
|
|
* be PIO ones not UDMA data transfer.
|
2007-09-27 06:02:52 +08:00
|
|
|
*
|
|
|
|
* Note: The host lock held by the libata layer protects
|
|
|
|
* us from two channels both trying to set DMA bits at once
|
2006-08-30 06:12:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void atiixp_bmdma_stop(struct ata_queued_cmd *qc)
|
|
|
|
{
|
|
|
|
struct ata_port *ap = qc->ap;
|
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
|
|
|
int dn = (2 * ap->port_no) + qc->dev->devno;
|
|
|
|
u16 tmp16;
|
|
|
|
|
|
|
|
pci_read_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, &tmp16);
|
|
|
|
tmp16 &= ~(1 << dn);
|
|
|
|
pci_write_config_word(pdev, ATIIXP_IDE_UDMA_CONTROL, tmp16);
|
|
|
|
ata_bmdma_stop(qc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct scsi_host_template atiixp_sht = {
|
2008-03-25 11:22:49 +08:00
|
|
|
ATA_BMDMA_SHT(DRV_NAME),
|
2008-02-21 04:09:23 +08:00
|
|
|
.sg_tablesize = LIBATA_DUMB_MAX_PRD,
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ata_port_operations atiixp_port_ops = {
|
libata: implement and use ops inheritance
libata lets low level drivers build ata_port_operations table and
register it with libata core layer. This allows low level drivers
high level of flexibility but also burdens them with lots of
boilerplate entries.
This becomes worse for drivers which support related similar
controllers which differ slightly. They share most of the operations
except for a few. However, the driver still needs to list all
operations for each variant. This results in large number of
duplicate entries, which is not only inefficient but also error-prone
as it becomes very difficult to tell what the actual differences are.
This duplicate boilerplates all over the low level drivers also make
updating the core layer exteremely difficult and error-prone. When
compounded with multi-branched development model, it ends up
accumulating inconsistencies over time. Some of those inconsistencies
cause immediate problems and fixed. Others just remain there dormant
making maintenance increasingly difficult.
To rectify the problem, this patch implements ata_port_operations
inheritance. To allow LLDs to easily re-use their own ops tables
overriding only specific methods, this patch implements poor man's
class inheritance. An ops table has ->inherits field which can be set
to any ops table as long as it doesn't create a loop. When the host
is started, the inheritance chain is followed and any operation which
isn't specified is taken from the nearest ancestor which has it
specified. This operation is called finalization and done only once
per an ops table and the LLD doesn't have to do anything special about
it other than making the ops table non-const such that libata can
update it.
libata provides four base ops tables lower drivers can inherit from -
base, sata, pmp, sff and bmdma. To avoid overriding these ops
accidentaly, these ops are declared const and LLDs should always
inherit these instead of using them directly.
After finalization, all the ops table are identical before and after
the patch except for setting .irq_handler to ata_interrupt in drivers
which didn't use to. The .irq_handler doesn't have any actual effect
and the field will soon be removed by later patch.
* sata_sx4 is still using old style EH and currently doesn't take
advantage of ops inheritance.
Signed-off-by: Tejun Heo <htejun@gmail.com>
2008-03-25 11:22:49 +08:00
|
|
|
.inherits = &ata_bmdma_port_ops,
|
2006-08-30 06:12:40 +08:00
|
|
|
|
2008-04-07 21:47:16 +08:00
|
|
|
.qc_prep = ata_sff_dumb_qc_prep,
|
2006-08-30 06:12:40 +08:00
|
|
|
.bmdma_start = atiixp_bmdma_start,
|
|
|
|
.bmdma_stop = atiixp_bmdma_stop,
|
2006-09-27 17:41:13 +08:00
|
|
|
|
libata: implement and use ops inheritance
libata lets low level drivers build ata_port_operations table and
register it with libata core layer. This allows low level drivers
high level of flexibility but also burdens them with lots of
boilerplate entries.
This becomes worse for drivers which support related similar
controllers which differ slightly. They share most of the operations
except for a few. However, the driver still needs to list all
operations for each variant. This results in large number of
duplicate entries, which is not only inefficient but also error-prone
as it becomes very difficult to tell what the actual differences are.
This duplicate boilerplates all over the low level drivers also make
updating the core layer exteremely difficult and error-prone. When
compounded with multi-branched development model, it ends up
accumulating inconsistencies over time. Some of those inconsistencies
cause immediate problems and fixed. Others just remain there dormant
making maintenance increasingly difficult.
To rectify the problem, this patch implements ata_port_operations
inheritance. To allow LLDs to easily re-use their own ops tables
overriding only specific methods, this patch implements poor man's
class inheritance. An ops table has ->inherits field which can be set
to any ops table as long as it doesn't create a loop. When the host
is started, the inheritance chain is followed and any operation which
isn't specified is taken from the nearest ancestor which has it
specified. This operation is called finalization and done only once
per an ops table and the LLD doesn't have to do anything special about
it other than making the ops table non-const such that libata can
update it.
libata provides four base ops tables lower drivers can inherit from -
base, sata, pmp, sff and bmdma. To avoid overriding these ops
accidentaly, these ops are declared const and LLDs should always
inherit these instead of using them directly.
After finalization, all the ops table are identical before and after
the patch except for setting .irq_handler to ata_interrupt in drivers
which didn't use to. The .irq_handler doesn't have any actual effect
and the field will soon be removed by later patch.
* sata_sx4 is still using old style EH and currently doesn't take
advantage of ops inheritance.
Signed-off-by: Tejun Heo <htejun@gmail.com>
2008-03-25 11:22:49 +08:00
|
|
|
.cable_detect = atiixp_cable_detect,
|
|
|
|
.set_piomode = atiixp_set_piomode,
|
|
|
|
.set_dmamode = atiixp_set_dmamode,
|
libata: make reset related methods proper port operations
Currently reset methods are not specified directly in the
ata_port_operations table. If a LLD wants to use custom reset
methods, it should construct and use a error_handler which uses those
reset methods. It's done this way for two reasons.
First, the ops table already contained too many methods and adding
four more of them would noticeably increase the amount of necessary
boilerplate code all over low level drivers.
Second, as ->error_handler uses those reset methods, it can get
confusing. ie. By overriding ->error_handler, those reset ops can be
made useless making layering a bit hazy.
Now that ops table uses inheritance, the first problem doesn't exist
anymore. The second isn't completely solved but is relieved by
providing default values - most drivers can just override what it has
implemented and don't have to concern itself about higher level
callbacks. In fact, there currently is no driver which actually
modifies error handling behavior. Drivers which override
->error_handler just wraps the standard error handler only to prepare
the controller for EH. I don't think making ops layering strict has
any noticeable benefit.
This patch makes ->prereset, ->softreset, ->hardreset, ->postreset and
their PMP counterparts propoer ops. Default ops are provided in the
base ops tables and drivers are converted to override individual reset
methods instead of creating custom error_handler.
* ata_std_error_handler() doesn't use sata_std_hardreset() if SCRs
aren't accessible. sata_promise doesn't need to use separate
error_handlers for PATA and SATA anymore.
* softreset is broken for sata_inic162x and sata_sx4. As libata now
always prefers hardreset, this doesn't really matter but the ops are
forced to NULL using ATA_OP_NULL for documentation purpose.
* pata_hpt374 needs to use different prereset for the first and second
PCI functions. This used to be done by branching from
hpt374_error_handler(). The proper way to do this is to use
separate ops and port_info tables for each function. Converted.
Signed-off-by: Tejun Heo <htejun@gmail.com>
2008-03-25 11:22:50 +08:00
|
|
|
.prereset = atiixp_pre_reset,
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
|
|
|
|
{
|
2007-05-04 18:43:58 +08:00
|
|
|
static const struct ata_port_info info = {
|
2007-05-28 18:59:48 +08:00
|
|
|
.flags = ATA_FLAG_SLAVE_POSS,
|
2006-08-30 06:12:40 +08:00
|
|
|
.pio_mask = 0x1f,
|
|
|
|
.mwdma_mask = 0x06, /* No MWDMA0 support */
|
|
|
|
.udma_mask = 0x3F,
|
|
|
|
.port_ops = &atiixp_port_ops
|
|
|
|
};
|
2007-05-04 18:43:58 +08:00
|
|
|
const struct ata_port_info *ppi[] = { &info, NULL };
|
2008-04-07 21:47:16 +08:00
|
|
|
return ata_pci_sff_init_one(dev, ppi, &atiixp_sht, NULL);
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
|
2006-09-29 08:21:59 +08:00
|
|
|
static const struct pci_device_id atiixp[] = {
|
|
|
|
{ PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP200_IDE), },
|
|
|
|
{ PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP300_IDE), },
|
|
|
|
{ PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP400_IDE), },
|
|
|
|
{ PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP600_IDE), },
|
2007-05-25 11:05:25 +08:00
|
|
|
{ PCI_VDEVICE(ATI, PCI_DEVICE_ID_ATI_IXP700_IDE), },
|
2006-09-29 08:21:59 +08:00
|
|
|
|
|
|
|
{ },
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver atiixp_pci_driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
.id_table = atiixp,
|
|
|
|
.probe = atiixp_init_one,
|
2006-11-23 00:57:36 +08:00
|
|
|
.remove = ata_pci_remove_one,
|
2007-03-02 16:31:26 +08:00
|
|
|
#ifdef CONFIG_PM
|
2006-11-23 00:57:36 +08:00
|
|
|
.resume = ata_pci_device_resume,
|
|
|
|
.suspend = ata_pci_device_suspend,
|
2007-03-02 16:31:26 +08:00
|
|
|
#endif
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init atiixp_init(void)
|
|
|
|
{
|
|
|
|
return pci_register_driver(&atiixp_pci_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit atiixp_exit(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&atiixp_pci_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Alan Cox");
|
|
|
|
MODULE_DESCRIPTION("low-level driver for ATI IXP200/300/400");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DEVICE_TABLE(pci, atiixp);
|
|
|
|
MODULE_VERSION(DRV_VERSION);
|
|
|
|
|
|
|
|
module_init(atiixp_init);
|
|
|
|
module_exit(atiixp_exit);
|