pata_cs5520.c revision 8501120f1df1aa6abe38b51ab91df08ccaa1b971
1669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/*
2669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	IDE tuning and bus mastering support for the CS5510/CS5520
3669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	chipsets
4669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
5669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	The CS5510/CS5520 are slightly unusual devices. Unlike the
6669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	typical IDE controllers they do bus mastering with the drive in
7669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	PIO mode and smarter silicon.
8669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
9669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	The practical upshot of this is that we must always tune the
10669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	drive for the right PIO mode. We must also ignore all the blacklists
11669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	and the drive bus mastering DMA information. Also to confuse matters
12669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	further we can do DMA on PIO only drives.
13669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
14669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	DMA on the 5510 also requires we disable_hlt() during DMA on early
15669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	revisions.
16669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
17669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	*** This driver is strictly experimental ***
18669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
19669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	(c) Copyright Red Hat Inc 2002
20669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
21669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * This program is free software; you can redistribute it and/or modify it
22669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * under the terms of the GNU General Public License as published by the
23669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * Free Software Foundation; either version 2, or (at your option) any
24669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * later version.
25669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
26669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * This program is distributed in the hope that it will be useful, but
27669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * WITHOUT ANY WARRANTY; without even the implied warranty of
28669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * General Public License for more details.
30669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
31669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik * Documentation:
32669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Not publically available.
33669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
34669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/kernel.h>
35669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/module.h>
36669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/pci.h>
37669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/init.h>
38669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/blkdev.h>
39669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/delay.h>
40669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <scsi/scsi_host.h>
41669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#include <linux/libata.h>
42669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
43669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik#define DRV_NAME	"pata_cs5520"
448501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox#define DRV_VERSION	"0.6.3"
45669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
46669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstruct pio_clocks
47669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
48669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	int address;
49669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	int assert;
50669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	int recovery;
51669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
52669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
53669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic const struct pio_clocks cs5520_pio_clocks[]={
54669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	{3, 6, 11},
55669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	{2, 5, 6},
56669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	{1, 4, 3},
57669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	{1, 3, 2},
58669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	{1, 2, 1}
59669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
60669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
61669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/**
62669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	cs5520_set_timings	-	program PIO timings
63669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@ap: ATA port
64669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@adev: ATA device
65669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
66669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Program the PIO mode timings for the controller according to the pio
67669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	clocking table.
68669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
69669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
70669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void cs5520_set_timings(struct ata_port *ap, struct ata_device *adev, int pio)
71669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
72669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	struct pci_dev *pdev = to_pci_dev(ap->host->dev);
73669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	int slave = adev->devno;
74669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
75669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pio -= XFER_PIO_0;
76669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
77669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Channel command timing */
78669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_write_config_byte(pdev, 0x62 + ap->port_no,
79669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].recovery << 4) |
80669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].assert));
81669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* FIXME: should these use address ? */
82669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Read command timing */
83669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_write_config_byte(pdev, 0x64 +  4*ap->port_no + slave,
84669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].recovery << 4) |
85669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].assert));
86669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Write command timing */
87669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_write_config_byte(pdev, 0x66 +  4*ap->port_no + slave,
88669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].recovery << 4) |
89669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik				(cs5520_pio_clocks[pio].assert));
90669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
91669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
92669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/**
93669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	cs5520_enable_dma	-	turn on DMA bits
94669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
95669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Turn on the DMA bits for this disk. Needed because the BIOS probably
96669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	has not done the work for us. Belongs in the core SATA code.
97669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
98669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
99669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void cs5520_enable_dma(struct ata_port *ap, struct ata_device *adev)
100669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
101669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Set the DMA enable/disable flag */
102669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	u8 reg = inb(ap->ioaddr.bmdma_addr + 0x02);
103669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	reg |= 1<<(adev->devno + 5);
104669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	outb(reg, ap->ioaddr.bmdma_addr + 0x02);
105669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
106669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
107669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/**
108669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	cs5520_set_dmamode	-	program DMA timings
109669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@ap: ATA port
110669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@adev: ATA device
111669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
112669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Program the DMA mode timings for the controller according to the pio
113669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	clocking table. Note that this device sets the DMA timings to PIO
114669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	mode values. This may seem bizarre but the 5520 architecture talks
115669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	PIO mode to the disk and DMA mode to the controller so the underlying
116669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	transfers are PIO timed.
117669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
118669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
119669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void cs5520_set_dmamode(struct ata_port *ap, struct ata_device *adev)
120669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
121669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	static const int dma_xlate[3] = { XFER_PIO_0, XFER_PIO_3, XFER_PIO_4 };
122669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	cs5520_set_timings(ap, adev, dma_xlate[adev->dma_mode]);
123669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	cs5520_enable_dma(ap, adev);
124669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
125669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
126669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/**
127669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	cs5520_set_piomode	-	program PIO timings
128669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@ap: ATA port
129669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@adev: ATA device
130669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
131669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Program the PIO mode timings for the controller according to the pio
132669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	clocking table. We know pio_mode will equal dma_mode because of the
133669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	CS5520 architecture. At least once we turned DMA on and wrote a
134669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	mode setter.
135669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
136669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
137669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void cs5520_set_piomode(struct ata_port *ap, struct ata_device *adev)
138669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
139669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	cs5520_set_timings(ap, adev, adev->pio_mode);
140669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
141669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
142669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
143669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic int cs5520_pre_reset(struct ata_port *ap)
144669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
145669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	ap->cbl = ATA_CBL_PATA40;
146669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	return ata_std_prereset(ap);
147669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
148669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
149669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void cs5520_error_handler(struct ata_port *ap)
150669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
151669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	return ata_bmdma_drive_eh(ap, cs5520_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
152669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
153669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
154669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic struct scsi_host_template cs5520_sht = {
155669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.module			= THIS_MODULE,
156669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.name			= DRV_NAME,
157669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.ioctl			= ata_scsi_ioctl,
158669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.queuecommand		= ata_scsi_queuecmd,
159669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.can_queue		= ATA_DEF_QUEUE,
160669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.this_id		= ATA_SHT_THIS_ID,
161669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.sg_tablesize		= LIBATA_MAX_PRD,
162669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.max_sectors		= ATA_MAX_SECTORS,
163669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.cmd_per_lun		= ATA_SHT_CMD_PER_LUN,
164669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.emulated		= ATA_SHT_EMULATED,
165669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.use_clustering		= ATA_SHT_USE_CLUSTERING,
166669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.proc_name		= DRV_NAME,
167669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.dma_boundary		= ATA_DMA_BOUNDARY,
168669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.slave_configure	= ata_scsi_slave_config,
169afdfe899e6420eac6c5eb3bc8c89456dff38d40eTejun Heo	.slave_destroy		= ata_scsi_slave_destroy,
170669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.bios_param		= ata_std_bios_param,
1718501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	.resume			= ata_scsi_device_resume,
1728501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	.suspend		= ata_scsi_device_suspend,
173669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
174669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
175669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic struct ata_port_operations cs5520_port_ops = {
176669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.port_disable		= ata_port_disable,
177669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.set_piomode		= cs5520_set_piomode,
178669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.set_dmamode		= cs5520_set_dmamode,
179669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
180669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.tf_load		= ata_tf_load,
181669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.tf_read		= ata_tf_read,
182669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.check_status		= ata_check_status,
183669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.exec_command		= ata_exec_command,
184669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.dev_select		= ata_std_dev_select,
185669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
186669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.freeze			= ata_bmdma_freeze,
187669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.thaw			= ata_bmdma_thaw,
188669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.error_handler		= cs5520_error_handler,
189669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.post_internal_cmd	= ata_bmdma_post_internal_cmd,
190669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
191669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.bmdma_setup		= ata_bmdma_setup,
192669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.bmdma_start		= ata_bmdma_start,
193669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.bmdma_stop		= ata_bmdma_stop,
194669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.bmdma_status		= ata_bmdma_status,
195669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.qc_prep		= ata_qc_prep,
196669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.qc_issue		= ata_qc_issue_prot,
197669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.data_xfer		= ata_pio_data_xfer,
198669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
199669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.irq_handler		= ata_interrupt,
200669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.irq_clear		= ata_bmdma_irq_clear,
201669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
202669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.port_start		= ata_port_start,
203669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.port_stop		= ata_port_stop,
204669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.host_stop		= ata_host_stop,
205669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
206669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
207669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
208669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
209669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	u8 pcicfg;
210669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	static struct ata_probe_ent probe[2];
211669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	int ports = 0;
212669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
213669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* IDE port enable bits */
214669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_read_config_byte(dev, 0x60, &pcicfg);
215669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
216669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Check if the ATA ports are enabled */
217669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if ((pcicfg & 3) == 0)
218669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		return -ENODEV;
219669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
220669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if ((pcicfg & 0x40) == 0) {
221669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		printk(KERN_WARNING DRV_NAME ": DMA mode disabled. Enabling.\n");
222669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		pci_write_config_byte(dev, 0x60, pcicfg | 0x40);
223669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	}
224669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
225669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Perform set up for DMA */
226669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (pci_enable_device_bars(dev, 1<<2)) {
227669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		printk(KERN_ERR DRV_NAME ": unable to configure BAR2.\n");
228669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		return -ENODEV;
229669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	}
230669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_set_master(dev);
231669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
232669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		printk(KERN_ERR DRV_NAME ": unable to configure DMA mask.\n");
233669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		return -ENODEV;
234669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	}
235669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (pci_set_consistent_dma_mask(dev, DMA_32BIT_MASK)) {
236669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		printk(KERN_ERR DRV_NAME ": unable to configure consistent DMA mask.\n");
237669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		return -ENODEV;
238669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	}
239669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
240669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* We have to do our own plumbing as the PCI setup for this
241669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	   chipset is non-standard so we can't punt to the libata code */
242669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
243669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	INIT_LIST_HEAD(&probe[0].node);
244669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].dev = pci_dev_to_dev(dev);
245669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port_ops = &cs5520_port_ops;
246669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].sht = &cs5520_sht;
247669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].pio_mask = 0x1F;
248669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].mwdma_mask = id->driver_data;
249669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].irq = 14;
250669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].irq_flags = 0;
251669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST;
252669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].n_ports = 1;
253669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port[0].cmd_addr = 0x1F0;
254669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port[0].ctl_addr = 0x3F6;
255669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port[0].altstatus_addr = 0x3F6;
256669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[0].port[0].bmdma_addr = pci_resource_start(dev, 2);
257669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
258669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* The secondary lurks at different addresses but is otherwise
259669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	   the same beastie */
260669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
261669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1] = probe[0];
262669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	INIT_LIST_HEAD(&probe[1].node);
263669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1].irq = 15;
264669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1].port[0].cmd_addr = 0x170;
265669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1].port[0].ctl_addr = 0x376;
266669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1].port[0].altstatus_addr = 0x376;
267669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	probe[1].port[0].bmdma_addr = pci_resource_start(dev, 2) + 8;
268669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
269669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Let libata fill in the port details */
270669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	ata_std_ports(&probe[0].port[0]);
271669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	ata_std_ports(&probe[1].port[0]);
272669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
273669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	/* Now add the ports that are active */
274669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (pcicfg & 1)
275669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		ports += ata_device_add(&probe[0]);
276669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (pcicfg & 2)
277669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		ports += ata_device_add(&probe[1]);
278669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	if (ports)
279669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik		return 0;
280669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	return -ENODEV;
281669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
282669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
283669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/**
284669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	cs5520_remove_one	-	device unload
285669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	@pdev: PCI device being removed
286669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *
287669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	Handle an unplug/unload event for a PCI device. Unload the
288669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	PCI driver but do not use the default handler as we manage
289669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	resources ourself and *MUST NOT* disable the device as it has
290669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik *	other functions.
291669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik */
292669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
293669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void __devexit cs5520_remove_one(struct pci_dev *pdev)
294669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
295669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	struct device *dev = pci_dev_to_dev(pdev);
296669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	struct ata_host *host = dev_get_drvdata(dev);
297669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
298669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	ata_host_remove(host);
299669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	dev_set_drvdata(dev, NULL);
300669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
301669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
3028501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox/**
3038501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox *	cs5520_reinit_one	-	device resume
3048501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox *	@pdev: PCI device
3058501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox *
3068501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox *	Do any reconfiguration work needed by a resume from RAM. We need
3078501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox *	to restore DMA mode support on BIOSen which disabled it
3088501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox */
3098501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox
3108501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Coxstatic int cs5520_reinit_one(struct pci_dev *pdev)
3118501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox{
3128501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	u8 pcicfg;
3138501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	pci_read_config_byte(pdev, 0x60, &pcicfg);
3148501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	if ((pcicfg & 0x40) == 0)
3158501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox		pci_write_config_byte(pdev, 0x60, pcicfg | 0x40);
3168501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	return ata_pci_device_resume(pdev);
3178501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox}
318669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik/* For now keep DMA off. We can set it for all but A rev CS5510 once the
319669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik   core ATA code can handle it */
320669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
3212d2744fc8be620a2dc469cf48349e3e704119f1bJeff Garzikstatic const struct pci_device_id pata_cs5520[] = {
3222d2744fc8be620a2dc469cf48349e3e704119f1bJeff Garzik	{ PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), },
3232d2744fc8be620a2dc469cf48349e3e704119f1bJeff Garzik	{ PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), },
3242d2744fc8be620a2dc469cf48349e3e704119f1bJeff Garzik
3252d2744fc8be620a2dc469cf48349e3e704119f1bJeff Garzik	{ },
326669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
327669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
328669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic struct pci_driver cs5520_pci_driver = {
329669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.name 		= DRV_NAME,
330669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.id_table	= pata_cs5520,
331669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	.probe 		= cs5520_init_one,
3328501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	.remove		= cs5520_remove_one,
3338501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	.suspend	= ata_pci_device_suspend,
3348501120f1df1aa6abe38b51ab91df08ccaa1b971Alan Cox	.resume		= cs5520_reinit_one,
335669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik};
336669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
337669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic int __init cs5520_init(void)
338669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
339669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	return pci_register_driver(&cs5520_pci_driver);
340669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
341669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
342669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikstatic void __exit cs5520_exit(void)
343669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik{
344669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik	pci_unregister_driver(&cs5520_pci_driver);
345669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik}
346669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
347669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff GarzikMODULE_AUTHOR("Alan Cox");
348669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff GarzikMODULE_DESCRIPTION("low-level driver for Cyrix CS5510/5520");
349669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff GarzikMODULE_LICENSE("GPL");
350669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff GarzikMODULE_DEVICE_TABLE(pci, pata_cs5520);
351669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff GarzikMODULE_VERSION(DRV_VERSION);
352669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
353669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikmodule_init(cs5520_init);
354669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzikmodule_exit(cs5520_exit);
355669a5db411d85a14f86cd92bc16bf7ab5b8aa235Jeff Garzik
356