Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  RZ1000/1001 driver based upon
0004  *
0005  *  linux/drivers/ide/pci/rz1000.c  Version 0.06    January 12, 2003
0006  *  Copyright (C) 1995-1998  Linus Torvalds & author (see below)
0007  *  Principal Author:  mlord@pobox.com (Mark Lord)
0008  *
0009  *  See linux/MAINTAINERS for address of current maintainer.
0010  *
0011  *  This file provides support for disabling the buggy read-ahead
0012  *  mode of the RZ1000 IDE chipset, commonly used on Intel motherboards.
0013  */
0014 
0015 #include <linux/kernel.h>
0016 #include <linux/module.h>
0017 #include <linux/pci.h>
0018 #include <linux/blkdev.h>
0019 #include <linux/delay.h>
0020 #include <scsi/scsi_host.h>
0021 #include <linux/libata.h>
0022 
0023 #define DRV_NAME    "pata_rz1000"
0024 #define DRV_VERSION "0.2.4"
0025 
0026 
0027 /**
0028  *  rz1000_set_mode     -   mode setting function
0029  *  @link: ATA link
0030  *  @unused: returned device on set_mode failure
0031  *
0032  *  Use a non standard set_mode function. We don't want to be tuned. We
0033  *  would prefer to be BIOS generic but for the fact our hardware is
0034  *  whacked out.
0035  */
0036 
0037 static int rz1000_set_mode(struct ata_link *link, struct ata_device **unused)
0038 {
0039     struct ata_device *dev;
0040 
0041     ata_for_each_dev(dev, link, ENABLED) {
0042         /* We don't really care */
0043         dev->pio_mode = XFER_PIO_0;
0044         dev->xfer_mode = XFER_PIO_0;
0045         dev->xfer_shift = ATA_SHIFT_PIO;
0046         dev->flags |= ATA_DFLAG_PIO;
0047         ata_dev_info(dev, "configured for PIO\n");
0048     }
0049     return 0;
0050 }
0051 
0052 
0053 static struct scsi_host_template rz1000_sht = {
0054     ATA_PIO_SHT(DRV_NAME),
0055 };
0056 
0057 static struct ata_port_operations rz1000_port_ops = {
0058     .inherits   = &ata_sff_port_ops,
0059     .cable_detect   = ata_cable_40wire,
0060     .set_mode   = rz1000_set_mode,
0061 };
0062 
0063 static int rz1000_fifo_disable(struct pci_dev *pdev)
0064 {
0065     u16 reg;
0066     /* Be exceptionally paranoid as we must be sure to apply the fix */
0067     if (pci_read_config_word(pdev, 0x40, &reg) != 0)
0068         return -1;
0069     reg &= 0xDFFF;
0070     if (pci_write_config_word(pdev, 0x40, reg) != 0)
0071         return -1;
0072     dev_info(&pdev->dev, "disabled chipset readahead.\n");
0073     return 0;
0074 }
0075 
0076 /**
0077  *  rz1000_init_one - Register RZ1000 ATA PCI device with kernel services
0078  *  @pdev: PCI device to register
0079  *  @ent: Entry in rz1000_pci_tbl matching with @pdev
0080  *
0081  *  Configure an RZ1000 interface. This doesn't require much special
0082  *  handling except that we *MUST* kill the chipset readahead or the
0083  *  user may experience data corruption.
0084  */
0085 
0086 static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
0087 {
0088     static const struct ata_port_info info = {
0089         .flags = ATA_FLAG_SLAVE_POSS,
0090         .pio_mask = ATA_PIO4,
0091         .port_ops = &rz1000_port_ops
0092     };
0093     const struct ata_port_info *ppi[] = { &info, NULL };
0094 
0095     ata_print_version_once(&pdev->dev, DRV_VERSION);
0096 
0097     if (rz1000_fifo_disable(pdev) == 0)
0098         return ata_pci_sff_init_one(pdev, ppi, &rz1000_sht, NULL, 0);
0099 
0100     dev_err(&pdev->dev, "failed to disable read-ahead on chipset.\n");
0101     /* Not safe to use so skip */
0102     return -ENODEV;
0103 }
0104 
0105 #ifdef CONFIG_PM_SLEEP
0106 static int rz1000_reinit_one(struct pci_dev *pdev)
0107 {
0108     struct ata_host *host = pci_get_drvdata(pdev);
0109     int rc;
0110 
0111     rc = ata_pci_device_do_resume(pdev);
0112     if (rc)
0113         return rc;
0114 
0115     /* If this fails on resume (which is a "can't happen" case), we
0116        must stop as any progress risks data loss */
0117     if (rz1000_fifo_disable(pdev))
0118         panic("rz1000 fifo");
0119 
0120     ata_host_resume(host);
0121     return 0;
0122 }
0123 #endif
0124 
0125 static const struct pci_device_id pata_rz1000[] = {
0126     { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), },
0127     { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1001), },
0128 
0129     { },
0130 };
0131 
0132 static struct pci_driver rz1000_pci_driver = {
0133     .name       = DRV_NAME,
0134     .id_table   = pata_rz1000,
0135     .probe      = rz1000_init_one,
0136     .remove     = ata_pci_remove_one,
0137 #ifdef CONFIG_PM_SLEEP
0138     .suspend    = ata_pci_device_suspend,
0139     .resume     = rz1000_reinit_one,
0140 #endif
0141 };
0142 
0143 module_pci_driver(rz1000_pci_driver);
0144 
0145 MODULE_AUTHOR("Alan Cox");
0146 MODULE_DESCRIPTION("low-level driver for RZ1000 PCI ATA");
0147 MODULE_LICENSE("GPL");
0148 MODULE_DEVICE_TABLE(pci, pata_rz1000);
0149 MODULE_VERSION(DRV_VERSION);