2006-08-30 06:12:40 +08:00
|
|
|
/*
|
|
|
|
* ata_generic.c - Generic PATA/SATA controller driver.
|
|
|
|
* Copyright 2005 Red Hat Inc <alan@redhat.com>, all rights reserved.
|
|
|
|
*
|
2006-08-31 12:03:49 +08:00
|
|
|
* Elements from ide/pci/generic.c
|
2006-08-30 06:12:40 +08:00
|
|
|
* Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
|
|
|
|
* Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
|
|
|
|
*
|
|
|
|
* May be copied or modified under the terms of the GNU General Public License
|
2006-08-31 12:03:49 +08:00
|
|
|
*
|
2006-08-30 06:12:40 +08:00
|
|
|
* Driver for PCI IDE interfaces implementing the standard bus mastering
|
|
|
|
* interface functionality. This assumes the BIOS did the drive set up and
|
|
|
|
* tuning for us. By default we do not grab all IDE class devices as they
|
|
|
|
* may have other drivers or need fixups to avoid problems. Instead we keep
|
|
|
|
* a default list of stuff without documentation/driver that appears to
|
2006-08-31 12:03:49 +08:00
|
|
|
* work.
|
2006-08-30 06:12:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "ata_generic"
|
2008-01-20 00:07:58 +08:00
|
|
|
#define DRV_VERSION "0.2.15"
|
2006-08-30 06:12:40 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A generic parallel ATA driver using libata
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generic_set_mode - mode setting
|
2007-08-06 17:36:23 +08:00
|
|
|
* @link: link to set up
|
2007-01-24 19:47:07 +08:00
|
|
|
* @unused: returned device on error
|
2006-08-30 06:12:40 +08:00
|
|
|
*
|
|
|
|
* Use a non standard set_mode function. We don't want to be tuned.
|
|
|
|
* The BIOS configured everything. Our job is not to fiddle. We
|
|
|
|
* read the dma enabled bits from the PCI configuration of the device
|
2006-08-31 12:03:49 +08:00
|
|
|
* and respect them.
|
2006-08-30 06:12:40 +08:00
|
|
|
*/
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2007-08-06 17:36:23 +08:00
|
|
|
static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
|
2006-08-30 06:12:40 +08:00
|
|
|
{
|
2007-08-06 17:36:23 +08:00
|
|
|
struct ata_port *ap = link->ap;
|
2006-08-30 06:12:40 +08:00
|
|
|
int dma_enabled = 0;
|
2007-08-06 17:36:23 +08:00
|
|
|
struct ata_device *dev;
|
2008-01-20 00:07:58 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(ap->host->dev);
|
2006-08-30 06:12:40 +08:00
|
|
|
|
|
|
|
/* Bits 5 and 6 indicate if DMA is active on master/slave */
|
|
|
|
if (ap->ioaddr.bmdma_addr)
|
2007-07-03 22:11:30 +08:00
|
|
|
dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2008-01-20 00:07:58 +08:00
|
|
|
if (pdev->vendor == PCI_VENDOR_ID_CENATEK)
|
|
|
|
dma_enabled = 0xFF;
|
|
|
|
|
2007-08-06 17:36:23 +08:00
|
|
|
ata_link_for_each_dev(dev, link) {
|
2007-11-27 18:43:38 +08:00
|
|
|
if (!ata_dev_enabled(dev))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We don't really care */
|
|
|
|
dev->pio_mode = XFER_PIO_0;
|
|
|
|
dev->dma_mode = XFER_MW_DMA_0;
|
|
|
|
/* We do need the right mode information for DMA or PIO
|
|
|
|
and this comes from the current configuration flags */
|
|
|
|
if (dma_enabled & (1 << (5 + dev->devno))) {
|
2007-11-27 18:43:41 +08:00
|
|
|
unsigned int xfer_mask = ata_id_xfermask(dev->id);
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
|
|
|
|
name = ata_mode_string(xfer_mask);
|
|
|
|
else {
|
|
|
|
/* SWDMA perhaps? */
|
|
|
|
name = "DMA";
|
|
|
|
xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
|
|
|
|
name);
|
|
|
|
|
|
|
|
dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
|
|
|
|
dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
|
2007-11-27 18:43:38 +08:00
|
|
|
dev->flags &= ~ATA_DFLAG_PIO;
|
|
|
|
} else {
|
|
|
|
ata_dev_printk(dev, KERN_INFO, "configured for PIO\n");
|
|
|
|
dev->xfer_mode = XFER_PIO_0;
|
|
|
|
dev->xfer_shift = ATA_SHIFT_PIO;
|
|
|
|
dev->flags |= ATA_DFLAG_PIO;
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
}
|
2007-01-24 19:47:07 +08:00
|
|
|
return 0;
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct scsi_host_template generic_sht = {
|
2008-03-25 11:22:49 +08:00
|
|
|
ATA_BMDMA_SHT(DRV_NAME),
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ata_port_operations generic_port_ops = {
|
|
|
|
.set_mode = generic_set_mode,
|
2008-03-25 11:22:48 +08:00
|
|
|
.mode_filter = ata_pci_default_filter,
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
.tf_load = ata_tf_load,
|
|
|
|
.tf_read = ata_tf_read,
|
|
|
|
.check_status = ata_check_status,
|
|
|
|
.exec_command = ata_exec_command,
|
|
|
|
.dev_select = ata_std_dev_select,
|
|
|
|
|
|
|
|
.bmdma_setup = ata_bmdma_setup,
|
|
|
|
.bmdma_start = ata_bmdma_start,
|
|
|
|
.bmdma_stop = ata_bmdma_stop,
|
|
|
|
.bmdma_status = ata_bmdma_status,
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2007-02-01 14:06:36 +08:00
|
|
|
.data_xfer = ata_data_xfer,
|
2006-08-30 06:12:40 +08:00
|
|
|
|
|
|
|
.freeze = ata_bmdma_freeze,
|
|
|
|
.thaw = ata_bmdma_thaw,
|
2007-04-11 07:04:20 +08:00
|
|
|
.error_handler = ata_bmdma_error_handler,
|
2006-08-30 06:12:40 +08:00
|
|
|
.post_internal_cmd = ata_bmdma_post_internal_cmd,
|
2007-04-11 07:04:20 +08:00
|
|
|
.cable_detect = ata_cable_unknown,
|
2006-08-30 06:12:40 +08:00
|
|
|
|
|
|
|
.qc_prep = ata_qc_prep,
|
|
|
|
.qc_issue = ata_qc_issue_prot,
|
2006-09-27 17:41:13 +08:00
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
.irq_handler = ata_interrupt,
|
|
|
|
.irq_clear = ata_bmdma_irq_clear,
|
2007-01-26 15:27:58 +08:00
|
|
|
.irq_on = ata_irq_on,
|
2006-08-30 06:12:40 +08:00
|
|
|
|
2007-08-23 05:55:41 +08:00
|
|
|
.port_start = ata_sff_port_start,
|
2006-08-31 12:03:49 +08:00
|
|
|
};
|
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
static int all_generic_ide; /* Set to claim all devices */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ata_generic_init - attach generic IDE
|
|
|
|
* @dev: PCI device found
|
|
|
|
* @id: match entry
|
|
|
|
*
|
|
|
|
* Called each time a matching IDE interface is found. We check if the
|
2006-08-31 12:03:49 +08:00
|
|
|
* interface is one we wish to claim and if so we perform any chip
|
2006-08-30 06:12:40 +08:00
|
|
|
* specific hacks then let the ATA layer do the heavy lifting.
|
|
|
|
*/
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
|
|
|
|
{
|
|
|
|
u16 command;
|
2007-05-04 18:43:58 +08:00
|
|
|
static const struct ata_port_info info = {
|
2006-08-30 06:12:40 +08:00
|
|
|
.sht = &generic_sht,
|
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 = 0x07,
|
2007-07-10 00:16:50 +08:00
|
|
|
.udma_mask = ATA_UDMA5,
|
2006-08-30 06:12:40 +08:00
|
|
|
.port_ops = &generic_port_ops
|
|
|
|
};
|
2007-05-04 18:43:58 +08:00
|
|
|
const struct ata_port_info *ppi[] = { &info, NULL };
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
/* Don't use the generic entry unless instructed to do so */
|
|
|
|
if (id->driver_data == 1 && all_generic_ide == 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Devices that need care */
|
|
|
|
if (dev->vendor == PCI_VENDOR_ID_UMC &&
|
|
|
|
dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
|
|
|
|
(!(PCI_FUNC(dev->devfn) & 1)))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (dev->vendor == PCI_VENDOR_ID_OPTI &&
|
|
|
|
dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
|
|
|
|
(!(PCI_FUNC(dev->devfn) & 1)))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Don't re-enable devices in generic mode or we will break some
|
|
|
|
motherboards with disabled and unused IDE controllers */
|
|
|
|
pci_read_config_word(dev, PCI_COMMAND, &command);
|
|
|
|
if (!(command & PCI_COMMAND_IO))
|
|
|
|
return -ENODEV;
|
2006-08-31 12:03:49 +08:00
|
|
|
|
2006-08-30 06:12:40 +08:00
|
|
|
if (dev->vendor == PCI_VENDOR_ID_AL)
|
|
|
|
ata_pci_clear_simplex(dev);
|
|
|
|
|
2007-05-04 18:43:58 +08:00
|
|
|
return ata_pci_init_one(dev, ppi);
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_device_id ata_generic[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
|
2006-08-31 12:03:49 +08:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
|
2006-08-30 06:12:40 +08:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
|
2008-01-20 00:07:58 +08:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_CENATEK,PCI_DEVICE_ID_CENATEK_IDE), },
|
2006-08-30 06:12:40 +08:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
|
|
|
|
/* Must come last. If you add entries adjust this table appropriately */
|
|
|
|
{ PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
|
|
|
|
{ 0, },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver ata_generic_pci_driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
.id_table = ata_generic,
|
|
|
|
.probe = ata_generic_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
|
|
|
.suspend = ata_pci_device_suspend,
|
|
|
|
.resume = ata_pci_device_resume,
|
2007-03-02 16:31:26 +08:00
|
|
|
#endif
|
2006-08-30 06:12:40 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init ata_generic_init(void)
|
|
|
|
{
|
2006-10-11 05:28:12 +08:00
|
|
|
return pci_register_driver(&ata_generic_pci_driver);
|
2006-08-30 06:12:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void __exit ata_generic_exit(void)
|
|
|
|
{
|
|
|
|
pci_unregister_driver(&ata_generic_pci_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Alan Cox");
|
|
|
|
MODULE_DESCRIPTION("low-level driver for generic ATA");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DEVICE_TABLE(pci, ata_generic);
|
|
|
|
MODULE_VERSION(DRV_VERSION);
|
|
|
|
|
|
|
|
module_init(ata_generic_init);
|
|
|
|
module_exit(ata_generic_exit);
|
|
|
|
|
|
|
|
module_param(all_generic_ide, int, 0);
|