xref: /openbmc/linux/drivers/ata/pata_rz1000.c (revision 25df73d9)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  RZ1000/1001 driver based upon
4  *
5  *  linux/drivers/ide/pci/rz1000.c	Version 0.06	January 12, 2003
6  *  Copyright (C) 1995-1998  Linus Torvalds & author (see below)
7  *  Principal Author:  mlord@pobox.com (Mark Lord)
8  *
9  *  See linux/MAINTAINERS for address of current maintainer.
10  *
11  *  This file provides support for disabling the buggy read-ahead
12  *  mode of the RZ1000 IDE chipset, commonly used on Intel motherboards.
13  */
14 
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/pci.h>
18 #include <linux/blkdev.h>
19 #include <linux/delay.h>
20 #include <scsi/scsi_host.h>
21 #include <linux/libata.h>
22 
23 #define DRV_NAME	"pata_rz1000"
24 #define DRV_VERSION	"0.2.4"
25 
26 
27 /**
28  *	rz1000_set_mode		-	mode setting function
29  *	@link: ATA link
30  *	@unused: returned device on set_mode failure
31  *
32  *	Use a non standard set_mode function. We don't want to be tuned. We
33  *	would prefer to be BIOS generic but for the fact our hardware is
34  *	whacked out.
35  */
36 
rz1000_set_mode(struct ata_link * link,struct ata_device ** unused)37 static int rz1000_set_mode(struct ata_link *link, struct ata_device **unused)
38 {
39 	struct ata_device *dev;
40 
41 	ata_for_each_dev(dev, link, ENABLED) {
42 		/* We don't really care */
43 		dev->pio_mode = XFER_PIO_0;
44 		dev->xfer_mode = XFER_PIO_0;
45 		dev->xfer_shift = ATA_SHIFT_PIO;
46 		dev->flags |= ATA_DFLAG_PIO;
47 		ata_dev_info(dev, "configured for PIO\n");
48 	}
49 	return 0;
50 }
51 
52 
53 static const struct scsi_host_template rz1000_sht = {
54 	ATA_PIO_SHT(DRV_NAME),
55 };
56 
57 static struct ata_port_operations rz1000_port_ops = {
58 	.inherits	= &ata_sff_port_ops,
59 	.cable_detect	= ata_cable_40wire,
60 	.set_mode	= rz1000_set_mode,
61 };
62 
rz1000_fifo_disable(struct pci_dev * pdev)63 static int rz1000_fifo_disable(struct pci_dev *pdev)
64 {
65 	u16 reg;
66 	/* Be exceptionally paranoid as we must be sure to apply the fix */
67 	if (pci_read_config_word(pdev, 0x40, &reg) != 0)
68 		return -1;
69 	reg &= 0xDFFF;
70 	if (pci_write_config_word(pdev, 0x40, reg) != 0)
71 		return -1;
72 	dev_info(&pdev->dev, "disabled chipset readahead.\n");
73 	return 0;
74 }
75 
76 /**
77  *	rz1000_init_one - Register RZ1000 ATA PCI device with kernel services
78  *	@pdev: PCI device to register
79  *	@ent: Entry in rz1000_pci_tbl matching with @pdev
80  *
81  *	Configure an RZ1000 interface. This doesn't require much special
82  *	handling except that we *MUST* kill the chipset readahead or the
83  *	user may experience data corruption.
84  */
85 
rz1000_init_one(struct pci_dev * pdev,const struct pci_device_id * ent)86 static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
87 {
88 	static const struct ata_port_info info = {
89 		.flags = ATA_FLAG_SLAVE_POSS,
90 		.pio_mask = ATA_PIO4,
91 		.port_ops = &rz1000_port_ops
92 	};
93 	const struct ata_port_info *ppi[] = { &info, NULL };
94 
95 	ata_print_version_once(&pdev->dev, DRV_VERSION);
96 
97 	if (rz1000_fifo_disable(pdev) == 0)
98 		return ata_pci_sff_init_one(pdev, ppi, &rz1000_sht, NULL, 0);
99 
100 	dev_err(&pdev->dev, "failed to disable read-ahead on chipset.\n");
101 	/* Not safe to use so skip */
102 	return -ENODEV;
103 }
104 
105 #ifdef CONFIG_PM_SLEEP
rz1000_reinit_one(struct pci_dev * pdev)106 static int rz1000_reinit_one(struct pci_dev *pdev)
107 {
108 	struct ata_host *host = pci_get_drvdata(pdev);
109 	int rc;
110 
111 	rc = ata_pci_device_do_resume(pdev);
112 	if (rc)
113 		return rc;
114 
115 	/* If this fails on resume (which is a "can't happen" case), we
116 	   must stop as any progress risks data loss */
117 	if (rz1000_fifo_disable(pdev))
118 		panic("rz1000 fifo");
119 
120 	ata_host_resume(host);
121 	return 0;
122 }
123 #endif
124 
125 static const struct pci_device_id pata_rz1000[] = {
126 	{ PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), },
127 	{ PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1001), },
128 
129 	{ },
130 };
131 
132 static struct pci_driver rz1000_pci_driver = {
133 	.name 		= DRV_NAME,
134 	.id_table	= pata_rz1000,
135 	.probe 		= rz1000_init_one,
136 	.remove		= ata_pci_remove_one,
137 #ifdef CONFIG_PM_SLEEP
138 	.suspend	= ata_pci_device_suspend,
139 	.resume		= rz1000_reinit_one,
140 #endif
141 };
142 
143 module_pci_driver(rz1000_pci_driver);
144 
145 MODULE_AUTHOR("Alan Cox");
146 MODULE_DESCRIPTION("low-level driver for RZ1000 PCI ATA");
147 MODULE_LICENSE("GPL");
148 MODULE_DEVICE_TABLE(pci, pata_rz1000);
149 MODULE_VERSION(DRV_VERSION);
150