xref: /OK3568_Linux_fs/kernel/drivers/ide/it821x.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2004		Red Hat
3*4882a593Smuzhiyun  * Copyright (C) 2007		Bartlomiej Zolnierkiewicz
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  May be copied or modified under the terms of the GNU General Public License
6*4882a593Smuzhiyun  *  Based in part on the ITE vendor provided SCSI driver.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *  Documentation:
9*4882a593Smuzhiyun  *	Datasheet is freely available, some other documents under NDA.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  The ITE8212 isn't exactly a standard IDE controller. It has two
12*4882a593Smuzhiyun  *  modes. In pass through mode then it is an IDE controller. In its smart
13*4882a593Smuzhiyun  *  mode its actually quite a capable hardware raid controller disguised
14*4882a593Smuzhiyun  *  as an IDE controller. Smart mode only understands DMA read/write and
15*4882a593Smuzhiyun  *  identify, none of the fancier commands apply. The IT8211 is identical
16*4882a593Smuzhiyun  *  in other respects but lacks the raid mode.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  *  Errata:
19*4882a593Smuzhiyun  *  o	Rev 0x10 also requires master/slave hold the same DMA timings and
20*4882a593Smuzhiyun  *	cannot do ATAPI MWDMA.
21*4882a593Smuzhiyun  *  o	The identify data for raid volumes lacks CHS info (technically ok)
22*4882a593Smuzhiyun  *	but also fails to set the LBA28 and other bits. We fix these in
23*4882a593Smuzhiyun  *	the IDE probe quirk code.
24*4882a593Smuzhiyun  *  o	If you write LBA48 sized I/O's (ie > 256 sector) in smart mode
25*4882a593Smuzhiyun  *	raid then the controller firmware dies
26*4882a593Smuzhiyun  *  o	Smart mode without RAID doesn't clear all the necessary identify
27*4882a593Smuzhiyun  *	bits to reduce the command set to the one used
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  *  This has a few impacts on the driver
30*4882a593Smuzhiyun  *  - In pass through mode we do all the work you would expect
31*4882a593Smuzhiyun  *  - In smart mode the clocking set up is done by the controller generally
32*4882a593Smuzhiyun  *    but we must watch the other limits and filter.
33*4882a593Smuzhiyun  *  - There are a few extra vendor commands that actually talk to the
34*4882a593Smuzhiyun  *    controller but only work PIO with no IRQ.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  *  Vendor areas of the identify block in smart mode are used for the
37*4882a593Smuzhiyun  *  timing and policy set up. Each HDD in raid mode also has a serial
38*4882a593Smuzhiyun  *  block on the disk. The hardware extra commands are get/set chip status,
39*4882a593Smuzhiyun  *  rebuild, get rebuild status.
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  *  In Linux the driver supports pass through mode as if the device was
42*4882a593Smuzhiyun  *  just another IDE controller. If the smart mode is running then
43*4882a593Smuzhiyun  *  volumes are managed by the controller firmware and each IDE "disk"
44*4882a593Smuzhiyun  *  is a raid volume. Even more cute - the controller can do automated
45*4882a593Smuzhiyun  *  hotplug and rebuild.
46*4882a593Smuzhiyun  *
47*4882a593Smuzhiyun  *  The pass through controller itself is a little demented. It has a
48*4882a593Smuzhiyun  *  flaw that it has a single set of PIO/MWDMA timings per channel so
49*4882a593Smuzhiyun  *  non UDMA devices restrict each others performance. It also has a
50*4882a593Smuzhiyun  *  single clock source per channel so mixed UDMA100/133 performance
51*4882a593Smuzhiyun  *  isn't perfect and we have to pick a clock. Thankfully none of this
52*4882a593Smuzhiyun  *  matters in smart mode. ATAPI DMA is not currently supported.
53*4882a593Smuzhiyun  *
54*4882a593Smuzhiyun  *  It seems the smart mode is a win for RAID1/RAID10 but otherwise not.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  *  TODO
57*4882a593Smuzhiyun  *	-	ATAPI UDMA is ok but not MWDMA it seems
58*4882a593Smuzhiyun  *	-	RAID configuration ioctls
59*4882a593Smuzhiyun  *	-	Move to libata once it grows up
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun #include <linux/types.h>
63*4882a593Smuzhiyun #include <linux/module.h>
64*4882a593Smuzhiyun #include <linux/slab.h>
65*4882a593Smuzhiyun #include <linux/pci.h>
66*4882a593Smuzhiyun #include <linux/ide.h>
67*4882a593Smuzhiyun #include <linux/init.h>
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #define DRV_NAME "it821x"
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun #define QUIRK_VORTEX86 1
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct it821x_dev
74*4882a593Smuzhiyun {
75*4882a593Smuzhiyun 	unsigned int smart:1,		/* Are we in smart raid mode */
76*4882a593Smuzhiyun 		timing10:1;		/* Rev 0x10 */
77*4882a593Smuzhiyun 	u8	clock_mode;		/* 0, ATA_50 or ATA_66 */
78*4882a593Smuzhiyun 	u8	want[2][2];		/* Mode/Pri log for master slave */
79*4882a593Smuzhiyun 	/* We need these for switching the clock when DMA goes on/off
80*4882a593Smuzhiyun 	   The high byte is the 66Mhz timing */
81*4882a593Smuzhiyun 	u16	pio[2];			/* Cached PIO values */
82*4882a593Smuzhiyun 	u16	mwdma[2];		/* Cached MWDMA values */
83*4882a593Smuzhiyun 	u16	udma[2];		/* Cached UDMA values (per drive) */
84*4882a593Smuzhiyun 	u16	quirks;
85*4882a593Smuzhiyun };
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #define ATA_66		0
88*4882a593Smuzhiyun #define ATA_50		1
89*4882a593Smuzhiyun #define ATA_ANY		2
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #define UDMA_OFF	0
92*4882a593Smuzhiyun #define MWDMA_OFF	0
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /*
95*4882a593Smuzhiyun  *	We allow users to force the card into non raid mode without
96*4882a593Smuzhiyun  *	flashing the alternative BIOS. This is also necessary right now
97*4882a593Smuzhiyun  *	for embedded platforms that cannot run a PC BIOS but are using this
98*4882a593Smuzhiyun  *	device.
99*4882a593Smuzhiyun  */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun static int it8212_noraid;
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /**
104*4882a593Smuzhiyun  *	it821x_program	-	program the PIO/MWDMA registers
105*4882a593Smuzhiyun  *	@drive: drive to tune
106*4882a593Smuzhiyun  *	@timing: timing info
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  *	Program the PIO/MWDMA timing for this channel according to the
109*4882a593Smuzhiyun  *	current clock.
110*4882a593Smuzhiyun  */
111*4882a593Smuzhiyun 
it821x_program(ide_drive_t * drive,u16 timing)112*4882a593Smuzhiyun static void it821x_program(ide_drive_t *drive, u16 timing)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
115*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
116*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
117*4882a593Smuzhiyun 	int channel = hwif->channel;
118*4882a593Smuzhiyun 	u8 conf;
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	/* Program PIO/MWDMA timing bits */
121*4882a593Smuzhiyun 	if(itdev->clock_mode == ATA_66)
122*4882a593Smuzhiyun 		conf = timing >> 8;
123*4882a593Smuzhiyun 	else
124*4882a593Smuzhiyun 		conf = timing & 0xFF;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x54 + 4 * channel, conf);
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun /**
130*4882a593Smuzhiyun  *	it821x_program_udma	-	program the UDMA registers
131*4882a593Smuzhiyun  *	@drive: drive to tune
132*4882a593Smuzhiyun  *	@timing: timing info
133*4882a593Smuzhiyun  *
134*4882a593Smuzhiyun  *	Program the UDMA timing for this drive according to the
135*4882a593Smuzhiyun  *	current clock.
136*4882a593Smuzhiyun  */
137*4882a593Smuzhiyun 
it821x_program_udma(ide_drive_t * drive,u16 timing)138*4882a593Smuzhiyun static void it821x_program_udma(ide_drive_t *drive, u16 timing)
139*4882a593Smuzhiyun {
140*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
141*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
142*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
143*4882a593Smuzhiyun 	int channel = hwif->channel;
144*4882a593Smuzhiyun 	u8 unit = drive->dn & 1, conf;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 	/* Program UDMA timing bits */
147*4882a593Smuzhiyun 	if(itdev->clock_mode == ATA_66)
148*4882a593Smuzhiyun 		conf = timing >> 8;
149*4882a593Smuzhiyun 	else
150*4882a593Smuzhiyun 		conf = timing & 0xFF;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 	if (itdev->timing10 == 0)
153*4882a593Smuzhiyun 		pci_write_config_byte(dev, 0x56 + 4 * channel + unit, conf);
154*4882a593Smuzhiyun 	else {
155*4882a593Smuzhiyun 		pci_write_config_byte(dev, 0x56 + 4 * channel, conf);
156*4882a593Smuzhiyun 		pci_write_config_byte(dev, 0x56 + 4 * channel + 1, conf);
157*4882a593Smuzhiyun 	}
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun  *	it821x_clock_strategy
162*4882a593Smuzhiyun  *	@drive: drive to set up
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  *	Select between the 50 and 66Mhz base clocks to get the best
165*4882a593Smuzhiyun  *	results for this interface.
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun 
it821x_clock_strategy(ide_drive_t * drive)168*4882a593Smuzhiyun static void it821x_clock_strategy(ide_drive_t *drive)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
171*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
172*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
173*4882a593Smuzhiyun 	ide_drive_t *pair = ide_get_pair_dev(drive);
174*4882a593Smuzhiyun 	int clock, altclock, sel = 0;
175*4882a593Smuzhiyun 	u8 unit = drive->dn & 1, v;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	if(itdev->want[0][0] > itdev->want[1][0]) {
178*4882a593Smuzhiyun 		clock = itdev->want[0][1];
179*4882a593Smuzhiyun 		altclock = itdev->want[1][1];
180*4882a593Smuzhiyun 	} else {
181*4882a593Smuzhiyun 		clock = itdev->want[1][1];
182*4882a593Smuzhiyun 		altclock = itdev->want[0][1];
183*4882a593Smuzhiyun 	}
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	/*
186*4882a593Smuzhiyun 	 * if both clocks can be used for the mode with the higher priority
187*4882a593Smuzhiyun 	 * use the clock needed by the mode with the lower priority
188*4882a593Smuzhiyun 	 */
189*4882a593Smuzhiyun 	if (clock == ATA_ANY)
190*4882a593Smuzhiyun 		clock = altclock;
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	/* Nobody cares - keep the same clock */
193*4882a593Smuzhiyun 	if(clock == ATA_ANY)
194*4882a593Smuzhiyun 		return;
195*4882a593Smuzhiyun 	/* No change */
196*4882a593Smuzhiyun 	if(clock == itdev->clock_mode)
197*4882a593Smuzhiyun 		return;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	/* Load this into the controller ? */
200*4882a593Smuzhiyun 	if(clock == ATA_66)
201*4882a593Smuzhiyun 		itdev->clock_mode = ATA_66;
202*4882a593Smuzhiyun 	else {
203*4882a593Smuzhiyun 		itdev->clock_mode = ATA_50;
204*4882a593Smuzhiyun 		sel = 1;
205*4882a593Smuzhiyun 	}
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	pci_read_config_byte(dev, 0x50, &v);
208*4882a593Smuzhiyun 	v &= ~(1 << (1 + hwif->channel));
209*4882a593Smuzhiyun 	v |= sel << (1 + hwif->channel);
210*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x50, v);
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun 	/*
213*4882a593Smuzhiyun 	 *	Reprogram the UDMA/PIO of the pair drive for the switch
214*4882a593Smuzhiyun 	 *	MWDMA will be dealt with by the dma switcher
215*4882a593Smuzhiyun 	 */
216*4882a593Smuzhiyun 	if(pair && itdev->udma[1-unit] != UDMA_OFF) {
217*4882a593Smuzhiyun 		it821x_program_udma(pair, itdev->udma[1-unit]);
218*4882a593Smuzhiyun 		it821x_program(pair, itdev->pio[1-unit]);
219*4882a593Smuzhiyun 	}
220*4882a593Smuzhiyun 	/*
221*4882a593Smuzhiyun 	 *	Reprogram the UDMA/PIO of our drive for the switch.
222*4882a593Smuzhiyun 	 *	MWDMA will be dealt with by the dma switcher
223*4882a593Smuzhiyun 	 */
224*4882a593Smuzhiyun 	if(itdev->udma[unit] != UDMA_OFF) {
225*4882a593Smuzhiyun 		it821x_program_udma(drive, itdev->udma[unit]);
226*4882a593Smuzhiyun 		it821x_program(drive, itdev->pio[unit]);
227*4882a593Smuzhiyun 	}
228*4882a593Smuzhiyun }
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /**
231*4882a593Smuzhiyun  *	it821x_set_pio_mode	-	set host controller for PIO mode
232*4882a593Smuzhiyun  *	@hwif: port
233*4882a593Smuzhiyun  *	@drive: drive
234*4882a593Smuzhiyun  *
235*4882a593Smuzhiyun  *	Tune the host to the desired PIO mode taking into the consideration
236*4882a593Smuzhiyun  *	the maximum PIO mode supported by the other device on the cable.
237*4882a593Smuzhiyun  */
238*4882a593Smuzhiyun 
it821x_set_pio_mode(ide_hwif_t * hwif,ide_drive_t * drive)239*4882a593Smuzhiyun static void it821x_set_pio_mode(ide_hwif_t *hwif, ide_drive_t *drive)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
242*4882a593Smuzhiyun 	ide_drive_t *pair = ide_get_pair_dev(drive);
243*4882a593Smuzhiyun 	const u8 pio = drive->pio_mode - XFER_PIO_0;
244*4882a593Smuzhiyun 	u8 unit = drive->dn & 1, set_pio = pio;
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	/* Spec says 89 ref driver uses 88 */
247*4882a593Smuzhiyun 	static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
248*4882a593Smuzhiyun 	static u8 pio_want[]    = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun 	/*
251*4882a593Smuzhiyun 	 * Compute the best PIO mode we can for a given device. We must
252*4882a593Smuzhiyun 	 * pick a speed that does not cause problems with the other device
253*4882a593Smuzhiyun 	 * on the cable.
254*4882a593Smuzhiyun 	 */
255*4882a593Smuzhiyun 	if (pair) {
256*4882a593Smuzhiyun 		u8 pair_pio = pair->pio_mode - XFER_PIO_0;
257*4882a593Smuzhiyun 		/* trim PIO to the slowest of the master/slave */
258*4882a593Smuzhiyun 		if (pair_pio < set_pio)
259*4882a593Smuzhiyun 			set_pio = pair_pio;
260*4882a593Smuzhiyun 	}
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 	/* We prefer 66Mhz clock for PIO 0-3, don't care for PIO4 */
263*4882a593Smuzhiyun 	itdev->want[unit][1] = pio_want[set_pio];
264*4882a593Smuzhiyun 	itdev->want[unit][0] = 1;	/* PIO is lowest priority */
265*4882a593Smuzhiyun 	itdev->pio[unit] = pio_timings[set_pio];
266*4882a593Smuzhiyun 	it821x_clock_strategy(drive);
267*4882a593Smuzhiyun 	it821x_program(drive, itdev->pio[unit]);
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun /**
271*4882a593Smuzhiyun  *	it821x_tune_mwdma	-	tune a channel for MWDMA
272*4882a593Smuzhiyun  *	@drive: drive to set up
273*4882a593Smuzhiyun  *	@mode_wanted: the target operating mode
274*4882a593Smuzhiyun  *
275*4882a593Smuzhiyun  *	Load the timing settings for this device mode into the
276*4882a593Smuzhiyun  *	controller when doing MWDMA in pass through mode. The caller
277*4882a593Smuzhiyun  *	must manage the whole lack of per device MWDMA/PIO timings and
278*4882a593Smuzhiyun  *	the shared MWDMA/PIO timing register.
279*4882a593Smuzhiyun  */
280*4882a593Smuzhiyun 
it821x_tune_mwdma(ide_drive_t * drive,u8 mode_wanted)281*4882a593Smuzhiyun static void it821x_tune_mwdma(ide_drive_t *drive, u8 mode_wanted)
282*4882a593Smuzhiyun {
283*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
284*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
285*4882a593Smuzhiyun 	struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
286*4882a593Smuzhiyun 	u8 unit = drive->dn & 1, channel = hwif->channel, conf;
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun 	static u16 dma[]	= { 0x8866, 0x3222, 0x3121 };
289*4882a593Smuzhiyun 	static u8 mwdma_want[]	= { ATA_ANY, ATA_66, ATA_ANY };
290*4882a593Smuzhiyun 
291*4882a593Smuzhiyun 	itdev->want[unit][1] = mwdma_want[mode_wanted];
292*4882a593Smuzhiyun 	itdev->want[unit][0] = 2;	/* MWDMA is low priority */
293*4882a593Smuzhiyun 	itdev->mwdma[unit] = dma[mode_wanted];
294*4882a593Smuzhiyun 	itdev->udma[unit] = UDMA_OFF;
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	/* UDMA bits off - Revision 0x10 do them in pairs */
297*4882a593Smuzhiyun 	pci_read_config_byte(dev, 0x50, &conf);
298*4882a593Smuzhiyun 	if (itdev->timing10)
299*4882a593Smuzhiyun 		conf |= channel ? 0x60: 0x18;
300*4882a593Smuzhiyun 	else
301*4882a593Smuzhiyun 		conf |= 1 << (3 + 2 * channel + unit);
302*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x50, conf);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	it821x_clock_strategy(drive);
305*4882a593Smuzhiyun 	/* FIXME: do we need to program this ? */
306*4882a593Smuzhiyun 	/* it821x_program(drive, itdev->mwdma[unit]); */
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun /**
310*4882a593Smuzhiyun  *	it821x_tune_udma	-	tune a channel for UDMA
311*4882a593Smuzhiyun  *	@drive: drive to set up
312*4882a593Smuzhiyun  *	@mode_wanted: the target operating mode
313*4882a593Smuzhiyun  *
314*4882a593Smuzhiyun  *	Load the timing settings for this device mode into the
315*4882a593Smuzhiyun  *	controller when doing UDMA modes in pass through.
316*4882a593Smuzhiyun  */
317*4882a593Smuzhiyun 
it821x_tune_udma(ide_drive_t * drive,u8 mode_wanted)318*4882a593Smuzhiyun static void it821x_tune_udma(ide_drive_t *drive, u8 mode_wanted)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
321*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
322*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
323*4882a593Smuzhiyun 	u8 unit = drive->dn & 1, channel = hwif->channel, conf;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	static u16 udma[]	= { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
326*4882a593Smuzhiyun 	static u8 udma_want[]	= { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun 	itdev->want[unit][1] = udma_want[mode_wanted];
329*4882a593Smuzhiyun 	itdev->want[unit][0] = 3;	/* UDMA is high priority */
330*4882a593Smuzhiyun 	itdev->mwdma[unit] = MWDMA_OFF;
331*4882a593Smuzhiyun 	itdev->udma[unit] = udma[mode_wanted];
332*4882a593Smuzhiyun 	if(mode_wanted >= 5)
333*4882a593Smuzhiyun 		itdev->udma[unit] |= 0x8080;	/* UDMA 5/6 select on */
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	/* UDMA on. Again revision 0x10 must do the pair */
336*4882a593Smuzhiyun 	pci_read_config_byte(dev, 0x50, &conf);
337*4882a593Smuzhiyun 	if (itdev->timing10)
338*4882a593Smuzhiyun 		conf &= channel ? 0x9F: 0xE7;
339*4882a593Smuzhiyun 	else
340*4882a593Smuzhiyun 		conf &= ~ (1 << (3 + 2 * channel + unit));
341*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x50, conf);
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun 	it821x_clock_strategy(drive);
344*4882a593Smuzhiyun 	it821x_program_udma(drive, itdev->udma[unit]);
345*4882a593Smuzhiyun 
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun /**
349*4882a593Smuzhiyun  *	it821x_dma_read	-	DMA hook
350*4882a593Smuzhiyun  *	@drive: drive for DMA
351*4882a593Smuzhiyun  *
352*4882a593Smuzhiyun  *	The IT821x has a single timing register for MWDMA and for PIO
353*4882a593Smuzhiyun  *	operations. As we flip back and forth we have to reload the
354*4882a593Smuzhiyun  *	clock. In addition the rev 0x10 device only works if the same
355*4882a593Smuzhiyun  *	timing value is loaded into the master and slave UDMA clock
356*4882a593Smuzhiyun  * 	so we must also reload that.
357*4882a593Smuzhiyun  *
358*4882a593Smuzhiyun  *	FIXME: we could figure out in advance if we need to do reloads
359*4882a593Smuzhiyun  */
360*4882a593Smuzhiyun 
it821x_dma_start(ide_drive_t * drive)361*4882a593Smuzhiyun static void it821x_dma_start(ide_drive_t *drive)
362*4882a593Smuzhiyun {
363*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
364*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
365*4882a593Smuzhiyun 	u8 unit = drive->dn & 1;
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	if(itdev->mwdma[unit] != MWDMA_OFF)
368*4882a593Smuzhiyun 		it821x_program(drive, itdev->mwdma[unit]);
369*4882a593Smuzhiyun 	else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
370*4882a593Smuzhiyun 		it821x_program_udma(drive, itdev->udma[unit]);
371*4882a593Smuzhiyun 	ide_dma_start(drive);
372*4882a593Smuzhiyun }
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun /**
375*4882a593Smuzhiyun  *	it821x_dma_write	-	DMA hook
376*4882a593Smuzhiyun  *	@drive: drive for DMA stop
377*4882a593Smuzhiyun  *
378*4882a593Smuzhiyun  *	The IT821x has a single timing register for MWDMA and for PIO
379*4882a593Smuzhiyun  *	operations. As we flip back and forth we have to reload the
380*4882a593Smuzhiyun  *	clock.
381*4882a593Smuzhiyun  */
382*4882a593Smuzhiyun 
it821x_dma_end(ide_drive_t * drive)383*4882a593Smuzhiyun static int it821x_dma_end(ide_drive_t *drive)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun 	ide_hwif_t *hwif = drive->hwif;
386*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(hwif);
387*4882a593Smuzhiyun 	int ret = ide_dma_end(drive);
388*4882a593Smuzhiyun 	u8 unit = drive->dn & 1;
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	if(itdev->mwdma[unit] != MWDMA_OFF)
391*4882a593Smuzhiyun 		it821x_program(drive, itdev->pio[unit]);
392*4882a593Smuzhiyun 	return ret;
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun /**
396*4882a593Smuzhiyun  *	it821x_set_dma_mode	-	set host controller for DMA mode
397*4882a593Smuzhiyun  *	@hwif: port
398*4882a593Smuzhiyun  *	@drive: drive
399*4882a593Smuzhiyun  *
400*4882a593Smuzhiyun  *	Tune the ITE chipset for the desired DMA mode.
401*4882a593Smuzhiyun  */
402*4882a593Smuzhiyun 
it821x_set_dma_mode(ide_hwif_t * hwif,ide_drive_t * drive)403*4882a593Smuzhiyun static void it821x_set_dma_mode(ide_hwif_t *hwif, ide_drive_t *drive)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun 	const u8 speed = drive->dma_mode;
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	/*
408*4882a593Smuzhiyun 	 * MWDMA tuning is really hard because our MWDMA and PIO
409*4882a593Smuzhiyun 	 * timings are kept in the same place.  We can switch in the
410*4882a593Smuzhiyun 	 * host dma on/off callbacks.
411*4882a593Smuzhiyun 	 */
412*4882a593Smuzhiyun 	if (speed >= XFER_UDMA_0 && speed <= XFER_UDMA_6)
413*4882a593Smuzhiyun 		it821x_tune_udma(drive, speed - XFER_UDMA_0);
414*4882a593Smuzhiyun 	else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
415*4882a593Smuzhiyun 		it821x_tune_mwdma(drive, speed - XFER_MW_DMA_0);
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun /**
419*4882a593Smuzhiyun  *	it821x_cable_detect	-	cable detection
420*4882a593Smuzhiyun  *	@hwif: interface to check
421*4882a593Smuzhiyun  *
422*4882a593Smuzhiyun  *	Check for the presence of an ATA66 capable cable on the
423*4882a593Smuzhiyun  *	interface. Problematic as it seems some cards don't have
424*4882a593Smuzhiyun  *	the needed logic onboard.
425*4882a593Smuzhiyun  */
426*4882a593Smuzhiyun 
it821x_cable_detect(ide_hwif_t * hwif)427*4882a593Smuzhiyun static u8 it821x_cable_detect(ide_hwif_t *hwif)
428*4882a593Smuzhiyun {
429*4882a593Smuzhiyun 	/* The reference driver also only does disk side */
430*4882a593Smuzhiyun 	return ATA_CBL_PATA80;
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun 
433*4882a593Smuzhiyun /**
434*4882a593Smuzhiyun  *	it821x_quirkproc	-	post init callback
435*4882a593Smuzhiyun  *	@drive: drive
436*4882a593Smuzhiyun  *
437*4882a593Smuzhiyun  *	This callback is run after the drive has been probed but
438*4882a593Smuzhiyun  *	before anything gets attached. It allows drivers to do any
439*4882a593Smuzhiyun  *	final tuning that is needed, or fixups to work around bugs.
440*4882a593Smuzhiyun  */
441*4882a593Smuzhiyun 
it821x_quirkproc(ide_drive_t * drive)442*4882a593Smuzhiyun static void it821x_quirkproc(ide_drive_t *drive)
443*4882a593Smuzhiyun {
444*4882a593Smuzhiyun 	struct it821x_dev *itdev = ide_get_hwifdata(drive->hwif);
445*4882a593Smuzhiyun 	u16 *id = drive->id;
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun 	if (!itdev->smart) {
448*4882a593Smuzhiyun 		/*
449*4882a593Smuzhiyun 		 *	If we are in pass through mode then not much
450*4882a593Smuzhiyun 		 *	needs to be done, but we do bother to clear the
451*4882a593Smuzhiyun 		 *	IRQ mask as we may well be in PIO (eg rev 0x10)
452*4882a593Smuzhiyun 		 *	for now and we know unmasking is safe on this chipset.
453*4882a593Smuzhiyun 		 */
454*4882a593Smuzhiyun 		drive->dev_flags |= IDE_DFLAG_UNMASK;
455*4882a593Smuzhiyun 	} else {
456*4882a593Smuzhiyun 	/*
457*4882a593Smuzhiyun 	 *	Perform fixups on smart mode. We need to "lose" some
458*4882a593Smuzhiyun 	 *	capabilities the firmware lacks but does not filter, and
459*4882a593Smuzhiyun 	 *	also patch up some capability bits that it forgets to set
460*4882a593Smuzhiyun 	 *	in RAID mode.
461*4882a593Smuzhiyun 	 */
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun 		/* Check for RAID v native */
464*4882a593Smuzhiyun 		if (strstr((char *)&id[ATA_ID_PROD],
465*4882a593Smuzhiyun 			   "Integrated Technology Express")) {
466*4882a593Smuzhiyun 			/* In raid mode the ident block is slightly buggy
467*4882a593Smuzhiyun 			   We need to set the bits so that the IDE layer knows
468*4882a593Smuzhiyun 			   LBA28. LBA48 and DMA ar valid */
469*4882a593Smuzhiyun 			id[ATA_ID_CAPABILITY]    |= (3 << 8); /* LBA28, DMA */
470*4882a593Smuzhiyun 			id[ATA_ID_COMMAND_SET_2] |= 0x0400;   /* LBA48 valid */
471*4882a593Smuzhiyun 			id[ATA_ID_CFS_ENABLE_2]  |= 0x0400;   /* LBA48 on */
472*4882a593Smuzhiyun 			/* Reporting logic */
473*4882a593Smuzhiyun 			printk(KERN_INFO "%s: IT8212 %sRAID %d volume",
474*4882a593Smuzhiyun 				drive->name, id[147] ? "Bootable " : "",
475*4882a593Smuzhiyun 				id[ATA_ID_CSFO]);
476*4882a593Smuzhiyun 			if (id[ATA_ID_CSFO] != 1)
477*4882a593Smuzhiyun 				printk(KERN_CONT "(%dK stripe)", id[146]);
478*4882a593Smuzhiyun 			printk(KERN_CONT ".\n");
479*4882a593Smuzhiyun 		} else {
480*4882a593Smuzhiyun 			/* Non RAID volume. Fixups to stop the core code
481*4882a593Smuzhiyun 			   doing unsupported things */
482*4882a593Smuzhiyun 			id[ATA_ID_FIELD_VALID]	 &= 3;
483*4882a593Smuzhiyun 			id[ATA_ID_QUEUE_DEPTH]	  = 0;
484*4882a593Smuzhiyun 			id[ATA_ID_COMMAND_SET_1]  = 0;
485*4882a593Smuzhiyun 			id[ATA_ID_COMMAND_SET_2] &= 0xC400;
486*4882a593Smuzhiyun 			id[ATA_ID_CFSSE]	 &= 0xC000;
487*4882a593Smuzhiyun 			id[ATA_ID_CFS_ENABLE_1]	  = 0;
488*4882a593Smuzhiyun 			id[ATA_ID_CFS_ENABLE_2]	 &= 0xC400;
489*4882a593Smuzhiyun 			id[ATA_ID_CSF_DEFAULT]	 &= 0xC000;
490*4882a593Smuzhiyun 			id[127]			  = 0;
491*4882a593Smuzhiyun 			id[ATA_ID_DLF]		  = 0;
492*4882a593Smuzhiyun 			id[ATA_ID_CSFO]		  = 0;
493*4882a593Smuzhiyun 			id[ATA_ID_CFA_POWER]	  = 0;
494*4882a593Smuzhiyun 			printk(KERN_INFO "%s: Performing identify fixups.\n",
495*4882a593Smuzhiyun 				drive->name);
496*4882a593Smuzhiyun 		}
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 		/*
499*4882a593Smuzhiyun 		 * Set MWDMA0 mode as enabled/support - just to tell
500*4882a593Smuzhiyun 		 * IDE core that DMA is supported (it821x hardware
501*4882a593Smuzhiyun 		 * takes care of DMA mode programming).
502*4882a593Smuzhiyun 		 */
503*4882a593Smuzhiyun 		if (ata_id_has_dma(id)) {
504*4882a593Smuzhiyun 			id[ATA_ID_MWDMA_MODES] |= 0x0101;
505*4882a593Smuzhiyun 			drive->current_speed = XFER_MW_DMA_0;
506*4882a593Smuzhiyun 		}
507*4882a593Smuzhiyun 	}
508*4882a593Smuzhiyun 
509*4882a593Smuzhiyun }
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun static const struct ide_dma_ops it821x_pass_through_dma_ops = {
512*4882a593Smuzhiyun 	.dma_host_set		= ide_dma_host_set,
513*4882a593Smuzhiyun 	.dma_setup		= ide_dma_setup,
514*4882a593Smuzhiyun 	.dma_start		= it821x_dma_start,
515*4882a593Smuzhiyun 	.dma_end		= it821x_dma_end,
516*4882a593Smuzhiyun 	.dma_test_irq		= ide_dma_test_irq,
517*4882a593Smuzhiyun 	.dma_lost_irq		= ide_dma_lost_irq,
518*4882a593Smuzhiyun 	.dma_timer_expiry	= ide_dma_sff_timer_expiry,
519*4882a593Smuzhiyun 	.dma_sff_read_status	= ide_dma_sff_read_status,
520*4882a593Smuzhiyun };
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun /**
523*4882a593Smuzhiyun  *	init_hwif_it821x	-	set up hwif structs
524*4882a593Smuzhiyun  *	@hwif: interface to set up
525*4882a593Smuzhiyun  *
526*4882a593Smuzhiyun  *	We do the basic set up of the interface structure. The IT8212
527*4882a593Smuzhiyun  *	requires several custom handlers so we override the default
528*4882a593Smuzhiyun  *	ide DMA handlers appropriately
529*4882a593Smuzhiyun  */
530*4882a593Smuzhiyun 
init_hwif_it821x(ide_hwif_t * hwif)531*4882a593Smuzhiyun static void init_hwif_it821x(ide_hwif_t *hwif)
532*4882a593Smuzhiyun {
533*4882a593Smuzhiyun 	struct pci_dev *dev = to_pci_dev(hwif->dev);
534*4882a593Smuzhiyun 	struct ide_host *host = pci_get_drvdata(dev);
535*4882a593Smuzhiyun 	struct it821x_dev *itdevs = host->host_priv;
536*4882a593Smuzhiyun 	struct it821x_dev *idev = itdevs + hwif->channel;
537*4882a593Smuzhiyun 	u8 conf;
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 	ide_set_hwifdata(hwif, idev);
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun 	pci_read_config_byte(dev, 0x50, &conf);
542*4882a593Smuzhiyun 	if (conf & 1) {
543*4882a593Smuzhiyun 		idev->smart = 1;
544*4882a593Smuzhiyun 		hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
545*4882a593Smuzhiyun 		/* Long I/O's although allowed in LBA48 space cause the
546*4882a593Smuzhiyun 		   onboard firmware to enter the twighlight zone */
547*4882a593Smuzhiyun 		hwif->rqsize = 256;
548*4882a593Smuzhiyun 	}
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun 	/* Pull the current clocks from 0x50 also */
551*4882a593Smuzhiyun 	if (conf & (1 << (1 + hwif->channel)))
552*4882a593Smuzhiyun 		idev->clock_mode = ATA_50;
553*4882a593Smuzhiyun 	else
554*4882a593Smuzhiyun 		idev->clock_mode = ATA_66;
555*4882a593Smuzhiyun 
556*4882a593Smuzhiyun 	idev->want[0][1] = ATA_ANY;
557*4882a593Smuzhiyun 	idev->want[1][1] = ATA_ANY;
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun 	/*
560*4882a593Smuzhiyun 	 *	Not in the docs but according to the reference driver
561*4882a593Smuzhiyun 	 *	this is necessary.
562*4882a593Smuzhiyun 	 */
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	if (dev->revision == 0x10) {
565*4882a593Smuzhiyun 		idev->timing10 = 1;
566*4882a593Smuzhiyun 		hwif->host_flags |= IDE_HFLAG_NO_ATAPI_DMA;
567*4882a593Smuzhiyun 		if (idev->smart == 0)
568*4882a593Smuzhiyun 			printk(KERN_WARNING DRV_NAME " %s: revision 0x10, "
569*4882a593Smuzhiyun 				"workarounds activated\n", pci_name(dev));
570*4882a593Smuzhiyun 	}
571*4882a593Smuzhiyun 
572*4882a593Smuzhiyun 	if (idev->smart == 0) {
573*4882a593Smuzhiyun 		/* MWDMA/PIO clock switching for pass through mode */
574*4882a593Smuzhiyun 		hwif->dma_ops = &it821x_pass_through_dma_ops;
575*4882a593Smuzhiyun 	} else
576*4882a593Smuzhiyun 		hwif->host_flags |= IDE_HFLAG_NO_SET_MODE;
577*4882a593Smuzhiyun 
578*4882a593Smuzhiyun 	if (hwif->dma_base == 0)
579*4882a593Smuzhiyun 		return;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	hwif->ultra_mask = ATA_UDMA6;
582*4882a593Smuzhiyun 	hwif->mwdma_mask = ATA_MWDMA2;
583*4882a593Smuzhiyun 
584*4882a593Smuzhiyun 	/* Vortex86SX quirk: prevent Ultra-DMA mode to fix BadCRC issue */
585*4882a593Smuzhiyun 	if (idev->quirks & QUIRK_VORTEX86) {
586*4882a593Smuzhiyun 		if (dev->revision == 0x11)
587*4882a593Smuzhiyun 			hwif->ultra_mask = 0;
588*4882a593Smuzhiyun 	}
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun 
it8212_disable_raid(struct pci_dev * dev)591*4882a593Smuzhiyun static void it8212_disable_raid(struct pci_dev *dev)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun 	/* Reset local CPU, and set BIOS not ready */
594*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x5E, 0x01);
595*4882a593Smuzhiyun 
596*4882a593Smuzhiyun 	/* Set to bypass mode, and reset PCI bus */
597*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x50, 0x00);
598*4882a593Smuzhiyun 	pci_write_config_word(dev, PCI_COMMAND,
599*4882a593Smuzhiyun 			      PCI_COMMAND_PARITY | PCI_COMMAND_IO |
600*4882a593Smuzhiyun 			      PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
601*4882a593Smuzhiyun 	pci_write_config_word(dev, 0x40, 0xA0F3);
602*4882a593Smuzhiyun 
603*4882a593Smuzhiyun 	pci_write_config_dword(dev,0x4C, 0x02040204);
604*4882a593Smuzhiyun 	pci_write_config_byte(dev, 0x42, 0x36);
605*4882a593Smuzhiyun 	pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
606*4882a593Smuzhiyun }
607*4882a593Smuzhiyun 
init_chipset_it821x(struct pci_dev * dev)608*4882a593Smuzhiyun static int init_chipset_it821x(struct pci_dev *dev)
609*4882a593Smuzhiyun {
610*4882a593Smuzhiyun 	u8 conf;
611*4882a593Smuzhiyun 	static char *mode[2] = { "pass through", "smart" };
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	/* Force the card into bypass mode if so requested */
614*4882a593Smuzhiyun 	if (it8212_noraid) {
615*4882a593Smuzhiyun 		printk(KERN_INFO DRV_NAME " %s: forcing bypass mode\n",
616*4882a593Smuzhiyun 			pci_name(dev));
617*4882a593Smuzhiyun 		it8212_disable_raid(dev);
618*4882a593Smuzhiyun 	}
619*4882a593Smuzhiyun 	pci_read_config_byte(dev, 0x50, &conf);
620*4882a593Smuzhiyun 	printk(KERN_INFO DRV_NAME " %s: controller in %s mode\n",
621*4882a593Smuzhiyun 		pci_name(dev), mode[conf & 1]);
622*4882a593Smuzhiyun 	return 0;
623*4882a593Smuzhiyun }
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun static const struct ide_port_ops it821x_port_ops = {
626*4882a593Smuzhiyun 	/* it821x_set_{pio,dma}_mode() are only used in pass-through mode */
627*4882a593Smuzhiyun 	.set_pio_mode		= it821x_set_pio_mode,
628*4882a593Smuzhiyun 	.set_dma_mode		= it821x_set_dma_mode,
629*4882a593Smuzhiyun 	.quirkproc		= it821x_quirkproc,
630*4882a593Smuzhiyun 	.cable_detect		= it821x_cable_detect,
631*4882a593Smuzhiyun };
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun static const struct ide_port_info it821x_chipset = {
634*4882a593Smuzhiyun 	.name		= DRV_NAME,
635*4882a593Smuzhiyun 	.init_chipset	= init_chipset_it821x,
636*4882a593Smuzhiyun 	.init_hwif	= init_hwif_it821x,
637*4882a593Smuzhiyun 	.port_ops	= &it821x_port_ops,
638*4882a593Smuzhiyun 	.pio_mask	= ATA_PIO4,
639*4882a593Smuzhiyun };
640*4882a593Smuzhiyun 
641*4882a593Smuzhiyun /**
642*4882a593Smuzhiyun  *	it821x_init_one	-	pci layer discovery entry
643*4882a593Smuzhiyun  *	@dev: PCI device
644*4882a593Smuzhiyun  *	@id: ident table entry
645*4882a593Smuzhiyun  *
646*4882a593Smuzhiyun  *	Called by the PCI code when it finds an ITE821x controller.
647*4882a593Smuzhiyun  *	We then use the IDE PCI generic helper to do most of the work.
648*4882a593Smuzhiyun  */
649*4882a593Smuzhiyun 
it821x_init_one(struct pci_dev * dev,const struct pci_device_id * id)650*4882a593Smuzhiyun static int it821x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
651*4882a593Smuzhiyun {
652*4882a593Smuzhiyun 	struct it821x_dev *itdevs;
653*4882a593Smuzhiyun 	int rc;
654*4882a593Smuzhiyun 
655*4882a593Smuzhiyun 	itdevs = kcalloc(2, sizeof(*itdevs), GFP_KERNEL);
656*4882a593Smuzhiyun 	if (itdevs == NULL) {
657*4882a593Smuzhiyun 		printk(KERN_ERR DRV_NAME " %s: out of memory\n", pci_name(dev));
658*4882a593Smuzhiyun 		return -ENOMEM;
659*4882a593Smuzhiyun 	}
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 	itdevs->quirks = id->driver_data;
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun 	rc = ide_pci_init_one(dev, &it821x_chipset, itdevs);
664*4882a593Smuzhiyun 	if (rc)
665*4882a593Smuzhiyun 		kfree(itdevs);
666*4882a593Smuzhiyun 
667*4882a593Smuzhiyun 	return rc;
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun 
it821x_remove(struct pci_dev * dev)670*4882a593Smuzhiyun static void it821x_remove(struct pci_dev *dev)
671*4882a593Smuzhiyun {
672*4882a593Smuzhiyun 	struct ide_host *host = pci_get_drvdata(dev);
673*4882a593Smuzhiyun 	struct it821x_dev *itdevs = host->host_priv;
674*4882a593Smuzhiyun 
675*4882a593Smuzhiyun 	ide_pci_remove(dev);
676*4882a593Smuzhiyun 	kfree(itdevs);
677*4882a593Smuzhiyun }
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun static const struct pci_device_id it821x_pci_tbl[] = {
680*4882a593Smuzhiyun 	{ PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8211), 0 },
681*4882a593Smuzhiyun 	{ PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8212), 0 },
682*4882a593Smuzhiyun 	{ PCI_VDEVICE(RDC, PCI_DEVICE_ID_RDC_D1010), QUIRK_VORTEX86 },
683*4882a593Smuzhiyun 	{ 0, },
684*4882a593Smuzhiyun };
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun static struct pci_driver it821x_pci_driver = {
689*4882a593Smuzhiyun 	.name		= "ITE821x IDE",
690*4882a593Smuzhiyun 	.id_table	= it821x_pci_tbl,
691*4882a593Smuzhiyun 	.probe		= it821x_init_one,
692*4882a593Smuzhiyun 	.remove		= it821x_remove,
693*4882a593Smuzhiyun 	.suspend	= ide_pci_suspend,
694*4882a593Smuzhiyun 	.resume		= ide_pci_resume,
695*4882a593Smuzhiyun };
696*4882a593Smuzhiyun 
it821x_ide_init(void)697*4882a593Smuzhiyun static int __init it821x_ide_init(void)
698*4882a593Smuzhiyun {
699*4882a593Smuzhiyun 	return ide_pci_register_driver(&it821x_pci_driver);
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun 
it821x_ide_exit(void)702*4882a593Smuzhiyun static void __exit it821x_ide_exit(void)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun 	pci_unregister_driver(&it821x_pci_driver);
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun module_init(it821x_ide_init);
708*4882a593Smuzhiyun module_exit(it821x_ide_exit);
709*4882a593Smuzhiyun 
710*4882a593Smuzhiyun module_param_named(noraid, it8212_noraid, int, S_IRUGO);
711*4882a593Smuzhiyun MODULE_PARM_DESC(noraid, "Force card into bypass mode");
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun MODULE_AUTHOR("Alan Cox");
714*4882a593Smuzhiyun MODULE_DESCRIPTION("PCI driver module for the ITE 821x");
715*4882a593Smuzhiyun MODULE_LICENSE("GPL");
716