libata hpt3xn: Hopefully sort out the DPLL logic versus the vendor code
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / ata / pata_rz1000.c
CommitLineData
669a5db4
JG
1/*
2 * RZ1000/1001 driver based upon
3 *
4 * linux/drivers/ide/pci/rz1000.c Version 0.06 January 12, 2003
5 * Copyright (C) 1995-1998 Linus Torvalds & author (see below)
6 * Principal Author: mlord@pobox.com (Mark Lord)
7 *
8 * See linux/MAINTAINERS for address of current maintainer.
9 *
10 * This file provides support for disabling the buggy read-ahead
11 * mode of the RZ1000 IDE chipset, commonly used on Intel motherboards.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/pci.h>
17#include <linux/init.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"
ad4a42d2 24#define DRV_VERSION "0.2.3"
669a5db4
JG
25
26
27/**
28 * rz1000_prereset - probe begin
29 * @ap: ATA port
30 *
31 * Set up cable type and use generics
32 */
33
34static int rz1000_prereset(struct ata_port *ap)
35{
36 ap->cbl = ATA_CBL_PATA40;
37 return ata_std_prereset(ap);
38}
39
40/**
41 * rz1000_error_handler - probe reset
42 * @ap: ATA port
43 *
44 * Perform the ATA standard reset sequence
45 */
46
47static void rz1000_error_handler(struct ata_port *ap)
48{
49 ata_bmdma_drive_eh(ap, rz1000_prereset, ata_std_softreset, NULL, ata_std_postreset);
50}
51
52/**
53 * rz1000_set_mode - mode setting function
54 * @ap: ATA interface
55 *
56 * Use a non standard set_mode function. We don't want to be tuned. We
57 * would prefer to be BIOS generic but for the fact our hardware is
58 * whacked out.
59 */
60
61static void rz1000_set_mode(struct ata_port *ap)
62{
63 int i;
64
65 for (i = 0; i < ATA_MAX_DEVICES; i++) {
66 struct ata_device *dev = &ap->device[i];
67 if (ata_dev_enabled(dev)) {
68 /* We don't really care */
69 dev->pio_mode = XFER_PIO_0;
70 dev->xfer_mode = XFER_PIO_0;
71 dev->xfer_shift = ATA_SHIFT_PIO;
72 dev->flags |= ATA_DFLAG_PIO;
73 }
74 }
75}
76
77
78static struct scsi_host_template rz1000_sht = {
79 .module = THIS_MODULE,
80 .name = DRV_NAME,
81 .ioctl = ata_scsi_ioctl,
82 .queuecommand = ata_scsi_queuecmd,
83 .can_queue = ATA_DEF_QUEUE,
84 .this_id = ATA_SHT_THIS_ID,
85 .sg_tablesize = LIBATA_MAX_PRD,
669a5db4
JG
86 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
87 .emulated = ATA_SHT_EMULATED,
88 .use_clustering = ATA_SHT_USE_CLUSTERING,
89 .proc_name = DRV_NAME,
90 .dma_boundary = ATA_DMA_BOUNDARY,
91 .slave_configure = ata_scsi_slave_config,
afdfe899 92 .slave_destroy = ata_scsi_slave_destroy,
669a5db4 93 .bios_param = ata_std_bios_param,
ad4a42d2
AC
94 .resume = ata_scsi_device_resume,
95 .suspend = ata_scsi_device_suspend,
669a5db4
JG
96};
97
98static struct ata_port_operations rz1000_port_ops = {
99 .set_mode = rz1000_set_mode,
100
101 .port_disable = ata_port_disable,
102 .tf_load = ata_tf_load,
103 .tf_read = ata_tf_read,
104 .check_status = ata_check_status,
105 .exec_command = ata_exec_command,
106 .dev_select = ata_std_dev_select,
107
669a5db4
JG
108 .bmdma_setup = ata_bmdma_setup,
109 .bmdma_start = ata_bmdma_start,
110 .bmdma_stop = ata_bmdma_stop,
111 .bmdma_status = ata_bmdma_status,
112
113 .qc_prep = ata_qc_prep,
114 .qc_issue = ata_qc_issue_prot,
bda30288 115
669a5db4
JG
116 .data_xfer = ata_pio_data_xfer,
117
118 .freeze = ata_bmdma_freeze,
119 .thaw = ata_bmdma_thaw,
120 .error_handler = rz1000_error_handler,
121 .post_internal_cmd = ata_bmdma_post_internal_cmd,
122
123 .irq_handler = ata_interrupt,
124 .irq_clear = ata_bmdma_irq_clear,
125
126 .port_start = ata_port_start,
127 .port_stop = ata_port_stop,
128 .host_stop = ata_host_stop
129};
130
ad4a42d2
AC
131static int rz1000_fifo_disable(struct pci_dev *pdev)
132{
133 u16 reg;
134 /* Be exceptionally paranoid as we must be sure to apply the fix */
135 if (pci_read_config_word(pdev, 0x40, &reg) != 0)
136 return -1;
137 reg &= 0xDFFF;
138 if (pci_write_config_word(pdev, 0x40, reg) != 0)
139 return -1;
140 printk(KERN_INFO DRV_NAME ": disabled chipset readahead.\n");
141 return 0;
142}
143
669a5db4
JG
144/**
145 * rz1000_init_one - Register RZ1000 ATA PCI device with kernel services
146 * @pdev: PCI device to register
147 * @ent: Entry in rz1000_pci_tbl matching with @pdev
148 *
149 * Configure an RZ1000 interface. This doesn't require much special
150 * handling except that we *MUST* kill the chipset readahead or the
151 * user may experience data corruption.
152 */
153
154static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
155{
156 static int printed_version;
157 struct ata_port_info *port_info[2];
669a5db4
JG
158 static struct ata_port_info info = {
159 .sht = &rz1000_sht,
160 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
161 .pio_mask = 0x1f,
162 .port_ops = &rz1000_port_ops
163 };
164
165 if (!printed_version++)
166 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
167
ad4a42d2
AC
168 if (rz1000_fifo_disable(pdev) == 0) {
169 port_info[0] = &info;
170 port_info[1] = &info;
171 return ata_pci_init_one(pdev, port_info, 2);
172 }
669a5db4
JG
173 printk(KERN_ERR DRV_NAME ": failed to disable read-ahead on chipset..\n");
174 /* Not safe to use so skip */
175 return -ENODEV;
176}
177
ad4a42d2
AC
178static int rz1000_reinit_one(struct pci_dev *pdev)
179{
180 /* If this fails on resume (which is a "cant happen" case), we
181 must stop as any progress risks data loss */
182 if (rz1000_fifo_disable(pdev))
183 panic("rz1000 fifo");
184 return ata_pci_device_resume(pdev);
185}
186
2d2744fc
JG
187static const struct pci_device_id pata_rz1000[] = {
188 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1000), },
189 { PCI_VDEVICE(PCTECH, PCI_DEVICE_ID_PCTECH_RZ1001), },
190
191 { },
669a5db4
JG
192};
193
194static struct pci_driver rz1000_pci_driver = {
2d2744fc 195 .name = DRV_NAME,
669a5db4
JG
196 .id_table = pata_rz1000,
197 .probe = rz1000_init_one,
ad4a42d2
AC
198 .remove = ata_pci_remove_one,
199 .suspend = ata_pci_device_suspend,
200 .resume = rz1000_reinit_one,
669a5db4
JG
201};
202
669a5db4
JG
203static int __init rz1000_init(void)
204{
205 return pci_register_driver(&rz1000_pci_driver);
206}
207
208static void __exit rz1000_exit(void)
209{
210 pci_unregister_driver(&rz1000_pci_driver);
211}
212
213MODULE_AUTHOR("Alan Cox");
214MODULE_DESCRIPTION("low-level driver for RZ1000 PCI ATA");
215MODULE_LICENSE("GPL");
216MODULE_DEVICE_TABLE(pci, pata_rz1000);
217MODULE_VERSION(DRV_VERSION);
218
219module_init(rz1000_init);
220module_exit(rz1000_exit);
221