0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <linux/kernel.h>
0020 #include <linux/module.h>
0021 #include <linux/pci.h>
0022 #include <linux/blkdev.h>
0023 #include <linux/delay.h>
0024 #include <scsi/scsi_host.h>
0025 #include <linux/libata.h>
0026
0027 #define DRV_NAME "ata_generic"
0028 #define DRV_VERSION "0.2.15"
0029
0030
0031
0032
0033
0034 enum {
0035 ATA_GEN_CLASS_MATCH = (1 << 0),
0036 ATA_GEN_FORCE_DMA = (1 << 1),
0037 ATA_GEN_INTEL_IDER = (1 << 2),
0038 };
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 static int generic_set_mode(struct ata_link *link, struct ata_device **unused)
0052 {
0053 struct ata_port *ap = link->ap;
0054 const struct pci_device_id *id = ap->host->private_data;
0055 int dma_enabled = 0;
0056 struct ata_device *dev;
0057
0058 if (id->driver_data & ATA_GEN_FORCE_DMA) {
0059 dma_enabled = 0xff;
0060 } else if (ap->ioaddr.bmdma_addr) {
0061
0062 dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
0063 }
0064
0065 ata_for_each_dev(dev, link, ENABLED) {
0066
0067 dev->pio_mode = XFER_PIO_0;
0068 dev->dma_mode = XFER_MW_DMA_0;
0069
0070
0071 if (dma_enabled & (1 << (5 + dev->devno))) {
0072 unsigned int xfer_mask = ata_id_xfermask(dev->id);
0073 const char *name;
0074
0075 if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
0076 name = ata_mode_string(xfer_mask);
0077 else {
0078
0079 name = "DMA";
0080 xfer_mask |= ata_xfer_mode2mask(XFER_MW_DMA_0);
0081 }
0082
0083 ata_dev_info(dev, "configured for %s\n", name);
0084
0085 dev->xfer_mode = ata_xfer_mask2mode(xfer_mask);
0086 dev->xfer_shift = ata_xfer_mode2shift(dev->xfer_mode);
0087 dev->flags &= ~ATA_DFLAG_PIO;
0088 } else {
0089 ata_dev_info(dev, "configured for PIO\n");
0090 dev->xfer_mode = XFER_PIO_0;
0091 dev->xfer_shift = ATA_SHIFT_PIO;
0092 dev->flags |= ATA_DFLAG_PIO;
0093 }
0094 }
0095 return 0;
0096 }
0097
0098 static struct scsi_host_template generic_sht = {
0099 ATA_BMDMA_SHT(DRV_NAME),
0100 };
0101
0102 static struct ata_port_operations generic_port_ops = {
0103 .inherits = &ata_bmdma_port_ops,
0104 .cable_detect = ata_cable_unknown,
0105 .set_mode = generic_set_mode,
0106 };
0107
0108 static int all_generic_ide;
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 static int is_intel_ider(struct pci_dev *dev)
0125 {
0126
0127
0128 u32 r;
0129 u16 t;
0130
0131
0132 pci_read_config_dword(dev, 0xF8, &r);
0133
0134 if (r != 0)
0135 return 0;
0136
0137
0138 pci_read_config_word(dev, 0x40, &t);
0139 if (t != 0)
0140 return 0;
0141
0142
0143
0144 pci_write_config_word(dev, 0x40, 1);
0145 pci_read_config_word(dev, 0x40, &t);
0146 if (t) {
0147 pci_write_config_word(dev, 0x40, 0);
0148 return 0;
0149 }
0150 return 1;
0151 }
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163 static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
0164 {
0165 u16 command;
0166 static const struct ata_port_info info = {
0167 .flags = ATA_FLAG_SLAVE_POSS,
0168 .pio_mask = ATA_PIO4,
0169 .mwdma_mask = ATA_MWDMA2,
0170 .udma_mask = ATA_UDMA5,
0171 .port_ops = &generic_port_ops
0172 };
0173 const struct ata_port_info *ppi[] = { &info, NULL };
0174
0175
0176 if ((id->driver_data & ATA_GEN_CLASS_MATCH) && all_generic_ide == 0)
0177 return -ENODEV;
0178
0179 if ((id->driver_data & ATA_GEN_INTEL_IDER) && !all_generic_ide)
0180 if (!is_intel_ider(dev))
0181 return -ENODEV;
0182
0183
0184 if (dev->vendor == PCI_VENDOR_ID_UMC &&
0185 dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
0186 (!(PCI_FUNC(dev->devfn) & 1)))
0187 return -ENODEV;
0188
0189 if (dev->vendor == PCI_VENDOR_ID_OPTI &&
0190 dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
0191 (!(PCI_FUNC(dev->devfn) & 1)))
0192 return -ENODEV;
0193
0194
0195
0196 pci_read_config_word(dev, PCI_COMMAND, &command);
0197 if (!(command & PCI_COMMAND_IO))
0198 return -ENODEV;
0199
0200 if (dev->vendor == PCI_VENDOR_ID_AL)
0201 ata_pci_bmdma_clear_simplex(dev);
0202
0203 if (dev->vendor == PCI_VENDOR_ID_ATI) {
0204 int rc = pcim_enable_device(dev);
0205 if (rc < 0)
0206 return rc;
0207 pcim_pin_device(dev);
0208 }
0209 return ata_pci_bmdma_init_one(dev, ppi, &generic_sht, (void *)id, 0);
0210 }
0211
0212 static struct pci_device_id ata_generic[] = {
0213 { PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
0214 { PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
0215 { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
0216 { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
0217 { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
0218 { PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
0219 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
0220 { PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
0221 { PCI_DEVICE(PCI_VENDOR_ID_CENATEK,PCI_DEVICE_ID_CENATEK_IDE),
0222 .driver_data = ATA_GEN_FORCE_DMA },
0223 #if !defined(CONFIG_PATA_TOSHIBA) && !defined(CONFIG_PATA_TOSHIBA_MODULE)
0224 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
0225 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
0226 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_3), },
0227 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_5), },
0228 #endif
0229
0230 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
0231 PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL,
0232 .driver_data = ATA_GEN_INTEL_IDER },
0233
0234 { PCI_DEVICE_CLASS(PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL),
0235 .driver_data = ATA_GEN_CLASS_MATCH },
0236 { 0, },
0237 };
0238
0239 static struct pci_driver ata_generic_pci_driver = {
0240 .name = DRV_NAME,
0241 .id_table = ata_generic,
0242 .probe = ata_generic_init_one,
0243 .remove = ata_pci_remove_one,
0244 #ifdef CONFIG_PM_SLEEP
0245 .suspend = ata_pci_device_suspend,
0246 .resume = ata_pci_device_resume,
0247 #endif
0248 };
0249
0250 module_pci_driver(ata_generic_pci_driver);
0251
0252 MODULE_AUTHOR("Alan Cox");
0253 MODULE_DESCRIPTION("low-level driver for generic ATA");
0254 MODULE_LICENSE("GPL");
0255 MODULE_DEVICE_TABLE(pci, ata_generic);
0256 MODULE_VERSION(DRV_VERSION);
0257
0258 module_param(all_generic_ide, int, 0);