blob: b72227676f004fc1c691b32d78543a714ad83471 [file] [log] [blame]
Jeff Garzik669a5db2006-08-29 18:12:40 -04001/*
2 * pata_sis.c - SiS ATA driver
3 *
4 * (C) 2005 Red Hat <alan@redhat.com>
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +02005 * (C) 2007 Bartlomiej Zolnierkiewicz
Jeff Garzik669a5db2006-08-29 18:12:40 -04006 *
7 * Based upon linux/drivers/ide/pci/sis5513.c
8 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
9 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
10 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
11 * SiS Taiwan : for direct support and hardware.
12 * Daniela Engert : for initial ATA100 advices and numerous others.
13 * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
14 * for checking code correctness, providing patches.
15 * Original tests and design on the SiS620 chipset.
16 * ATA100 tests and design on the SiS735 chipset.
17 * ATA16/33 support from specs
18 * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
19 *
20 *
21 * TODO
22 * Check MWDMA on drives that don't support MWDMA speed pio cycles ?
23 * More Testing
24 */
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/pci.h>
29#include <linux/init.h>
30#include <linux/blkdev.h>
31#include <linux/delay.h>
32#include <linux/device.h>
33#include <scsi/scsi_host.h>
34#include <linux/libata.h>
35#include <linux/ata.h>
Alan4bb64fb2007-02-16 01:40:04 -080036#include "sis.h"
Jeff Garzik669a5db2006-08-29 18:12:40 -040037
38#define DRV_NAME "pata_sis"
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +020039#define DRV_VERSION "0.5.2"
Jeff Garzik669a5db2006-08-29 18:12:40 -040040
41struct sis_chipset {
Tejun Heo1626aeb2007-05-04 12:43:58 +020042 u16 device; /* PCI host ID */
43 const struct ata_port_info *info; /* Info block */
Jeff Garzik669a5db2006-08-29 18:12:40 -040044 /* Probably add family, cable detect type etc here to clean
45 up code later */
46};
47
Jakub W. Jozwicki J7dcbc1f2007-01-09 09:01:19 +090048struct sis_laptop {
49 u16 device;
50 u16 subvendor;
51 u16 subdevice;
52};
53
54static const struct sis_laptop sis_laptop[] = {
55 /* devid, subvendor, subdev */
56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
Alan Cox4f2d47c2007-08-22 22:56:43 +010057 { 0x5513, 0x1734, 0x105F }, /* FSC Amilo A1630 */
Jakub W. Jozwicki J7dcbc1f2007-01-09 09:01:19 +090058 /* end marker */
59 { 0, }
60};
61
62static int sis_short_ata40(struct pci_dev *dev)
63{
64 const struct sis_laptop *lap = &sis_laptop[0];
65
66 while (lap->device) {
67 if (lap->device == dev->device &&
68 lap->subvendor == dev->subsystem_vendor &&
69 lap->subdevice == dev->subsystem_device)
70 return 1;
71 lap++;
72 }
73
74 return 0;
75}
76
Jeff Garzik669a5db2006-08-29 18:12:40 -040077/**
Alan Coxdd668d12007-05-21 15:00:53 +010078 * sis_old_port_base - return PCI configuration base for dev
Jeff Garzik669a5db2006-08-29 18:12:40 -040079 * @adev: device
80 *
81 * Returns the base of the PCI configuration registers for this port
82 * number.
83 */
84
Alan Coxdd668d12007-05-21 15:00:53 +010085static int sis_old_port_base(struct ata_device *adev)
Jeff Garzik669a5db2006-08-29 18:12:40 -040086{
Tejun Heo9af5c9c2007-08-06 18:36:22 +090087 return 0x40 + (4 * adev->link->ap->port_no) + (2 * adev->devno);
Jeff Garzik669a5db2006-08-29 18:12:40 -040088}
89
90/**
Alan Cox2e413f52007-03-07 16:54:24 +000091 * sis_133_cable_detect - check for 40/80 pin
Jeff Garzik669a5db2006-08-29 18:12:40 -040092 * @ap: Port
Tejun Heod4b2bab2007-02-02 16:50:52 +090093 * @deadline: deadline jiffies for the operation
Jeff Garzik669a5db2006-08-29 18:12:40 -040094 *
95 * Perform cable detection for the later UDMA133 capable
96 * SiS chipset.
97 */
98
Alan Cox2e413f52007-03-07 16:54:24 +000099static int sis_133_cable_detect(struct ata_port *ap)
100{
101 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
102 u16 tmp;
103
104 /* The top bit of this register is the cable detect bit */
105 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
106 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
107 return ATA_CBL_PATA40;
108 return ATA_CBL_PATA80;
109}
110
111/**
112 * sis_66_cable_detect - check for 40/80 pin
113 * @ap: Port
Tejun Heod4b2bab2007-02-02 16:50:52 +0900114 * @deadline: deadline jiffies for the operation
Alan Cox2e413f52007-03-07 16:54:24 +0000115 *
116 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
117 * SiS IDE controllers.
118 */
119
120static int sis_66_cable_detect(struct ata_port *ap)
121{
122 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
123 u8 tmp;
124
125 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
126 pci_read_config_byte(pdev, 0x48, &tmp);
127 tmp >>= ap->port_no;
128 if ((tmp & 0x10) && !sis_short_ata40(pdev))
129 return ATA_CBL_PATA40;
130 return ATA_CBL_PATA80;
131}
132
133
134/**
135 * sis_pre_reset - probe begin
Tejun Heocc0680a2007-08-06 18:36:23 +0900136 * @link: ATA link
Tejun Heod4b2bab2007-02-02 16:50:52 +0900137 * @deadline: deadline jiffies for the operation
Alan Cox2e413f52007-03-07 16:54:24 +0000138 *
139 * Set up cable type and use generic probe init
140 */
141
Tejun Heocc0680a2007-08-06 18:36:23 +0900142static int sis_pre_reset(struct ata_link *link, unsigned long deadline)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400143{
144 static const struct pci_bits sis_enable_bits[] = {
145 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
146 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
147 };
Jeff Garzik85cd7252006-08-31 00:03:49 -0400148
Tejun Heocc0680a2007-08-06 18:36:23 +0900149 struct ata_port *ap = link->ap;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400150 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400151
Alan Coxc9619222006-09-26 17:53:38 +0100152 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
153 return -ENOENT;
Tejun Heod4b2bab2007-02-02 16:50:52 +0900154
Alan Cox15ce0942007-05-25 20:50:24 +0100155 /* Clear the FIFO settings. We can't enable the FIFO until
156 we know we are poking at a disk */
157 pci_write_config_byte(pdev, 0x4B, 0);
Tejun Heocc0680a2007-08-06 18:36:23 +0900158 return ata_std_prereset(link, deadline);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400159}
160
Alan Cox2e413f52007-03-07 16:54:24 +0000161
Jeff Garzik669a5db2006-08-29 18:12:40 -0400162/**
163 * sis_error_handler - Probe specified port on PATA host controller
164 * @ap: Port to probe
165 *
166 * LOCKING:
167 * None (inherited from caller).
168 */
169
Alan Cox2e413f52007-03-07 16:54:24 +0000170static void sis_error_handler(struct ata_port *ap)
Jeff Garzik669a5db2006-08-29 18:12:40 -0400171{
Alan Cox2e413f52007-03-07 16:54:24 +0000172 ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400173}
174
175/**
176 * sis_set_fifo - Set RWP fifo bits for this device
177 * @ap: Port
178 * @adev: Device
179 *
180 * SIS chipsets implement prefetch/postwrite bits for each device
181 * on both channels. This functionality is not ATAPI compatible and
182 * must be configured according to the class of device present
183 */
184
185static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
186{
187 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
188 u8 fifoctrl;
189 u8 mask = 0x11;
190
191 mask <<= (2 * ap->port_no);
192 mask <<= adev->devno;
193
194 /* This holds various bits including the FIFO control */
195 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
196 fifoctrl &= ~mask;
197
198 /* Enable for ATA (disk) only */
199 if (adev->class == ATA_DEV_ATA)
200 fifoctrl |= mask;
201 pci_write_config_byte(pdev, 0x4B, fifoctrl);
202}
203
204/**
205 * sis_old_set_piomode - Initialize host controller PATA PIO timings
206 * @ap: Port whose timings we are configuring
207 * @adev: Device we are configuring for.
208 *
209 * Set PIO mode for device, in host controller PCI config space. This
210 * function handles PIO set up for all chips that are pre ATA100 and
211 * also early ATA100 devices.
212 *
213 * LOCKING:
214 * None (inherited from caller).
215 */
216
217static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
218{
219 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Alan Coxdd668d12007-05-21 15:00:53 +0100220 int port = sis_old_port_base(adev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400221 u8 t1, t2;
222 int speed = adev->pio_mode - XFER_PIO_0;
223
224 const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
225 const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
226
227 sis_set_fifo(ap, adev);
228
229 pci_read_config_byte(pdev, port, &t1);
230 pci_read_config_byte(pdev, port + 1, &t2);
231
232 t1 &= ~0x0F; /* Clear active/recovery timings */
233 t2 &= ~0x07;
234
235 t1 |= active[speed];
236 t2 |= recovery[speed];
237
238 pci_write_config_byte(pdev, port, t1);
239 pci_write_config_byte(pdev, port + 1, t2);
240}
241
242/**
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200243 * sis_100_set_piomode - Initialize host controller PATA PIO timings
Jeff Garzik669a5db2006-08-29 18:12:40 -0400244 * @ap: Port whose timings we are configuring
245 * @adev: Device we are configuring for.
246 *
247 * Set PIO mode for device, in host controller PCI config space. This
248 * function handles PIO set up for ATA100 devices and early ATA133.
249 *
250 * LOCKING:
251 * None (inherited from caller).
252 */
253
254static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
255{
256 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
Alan Coxdd668d12007-05-21 15:00:53 +0100257 int port = sis_old_port_base(adev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400258 int speed = adev->pio_mode - XFER_PIO_0;
259
260 const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
261
262 sis_set_fifo(ap, adev);
263
264 pci_write_config_byte(pdev, port, actrec[speed]);
265}
266
267/**
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200268 * sis_133_set_piomode - Initialize host controller PATA PIO timings
Jeff Garzik669a5db2006-08-29 18:12:40 -0400269 * @ap: Port whose timings we are configuring
270 * @adev: Device we are configuring for.
271 *
272 * Set PIO mode for device, in host controller PCI config space. This
273 * function handles PIO set up for the later ATA133 devices.
274 *
275 * LOCKING:
276 * None (inherited from caller).
277 */
278
279static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
280{
281 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
282 int port = 0x40;
283 u32 t1;
284 u32 reg54;
285 int speed = adev->pio_mode - XFER_PIO_0;
286
287 const u32 timing133[] = {
288 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
289 0x0C266000,
290 0x04263000,
291 0x0C0A3000,
292 0x05093000
293 };
294 const u32 timing100[] = {
295 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
296 0x091C4000,
297 0x031C2000,
298 0x09072000,
299 0x04062000
300 };
301
302 sis_set_fifo(ap, adev);
303
304 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
305 pci_read_config_dword(pdev, 0x54, &reg54);
306 if (reg54 & 0x40000000)
307 port = 0x70;
308 port += 8 * ap->port_no + 4 * adev->devno;
309
310 pci_read_config_dword(pdev, port, &t1);
311 t1 &= 0xC0C00FFF; /* Mask out timing */
312
313 if (t1 & 0x08) /* 100 or 133 ? */
314 t1 |= timing133[speed];
315 else
316 t1 |= timing100[speed];
317 pci_write_config_byte(pdev, port, t1);
318}
319
320/**
321 * sis_old_set_dmamode - Initialize host controller PATA DMA timings
322 * @ap: Port whose timings we are configuring
323 * @adev: Device to program
324 *
325 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
326 * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
327 * the old ide/pci driver.
328 *
329 * LOCKING:
330 * None (inherited from caller).
331 */
332
333static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
334{
335 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
336 int speed = adev->dma_mode - XFER_MW_DMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100337 int drive_pci = sis_old_port_base(adev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400338 u16 timing;
339
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200340 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400341 const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
342
343 pci_read_config_word(pdev, drive_pci, &timing);
344
345 if (adev->dma_mode < XFER_UDMA_0) {
346 /* bits 3-0 hold recovery timing bits 8-10 active timing and
347 the higer bits are dependant on the device */
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200348 timing &= ~0x870F;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400349 timing |= mwdma_bits[speed];
Jeff Garzik669a5db2006-08-29 18:12:40 -0400350 } else {
351 /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
352 speed = adev->dma_mode - XFER_UDMA_0;
353 timing &= ~0x6000;
354 timing |= udma_bits[speed];
355 }
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200356 pci_write_config_word(pdev, drive_pci, timing);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400357}
358
359/**
360 * sis_66_set_dmamode - Initialize host controller PATA DMA timings
361 * @ap: Port whose timings we are configuring
362 * @adev: Device to program
363 *
364 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
365 * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
366 * the old ide/pci driver.
367 *
368 * LOCKING:
369 * None (inherited from caller).
370 */
371
372static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
373{
374 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
375 int speed = adev->dma_mode - XFER_MW_DMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100376 int drive_pci = sis_old_port_base(adev);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400377 u16 timing;
378
Tejun Heoedeb6142007-09-21 16:29:05 +0900379 /* MWDMA 0-2 and UDMA 0-5 */
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200380 const u16 mwdma_bits[] = { 0x008, 0x302, 0x301 };
Tejun Heoedeb6142007-09-21 16:29:05 +0900381 const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000, 0x8000 };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400382
383 pci_read_config_word(pdev, drive_pci, &timing);
384
385 if (adev->dma_mode < XFER_UDMA_0) {
386 /* bits 3-0 hold recovery timing bits 8-10 active timing and
387 the higer bits are dependant on the device, bit 15 udma */
Alan Coxdd668d12007-05-21 15:00:53 +0100388 timing &= ~0x870F;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400389 timing |= mwdma_bits[speed];
390 } else {
391 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
392 speed = adev->dma_mode - XFER_UDMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100393 timing &= ~0xF000;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400394 timing |= udma_bits[speed];
395 }
396 pci_write_config_word(pdev, drive_pci, timing);
397}
398
399/**
400 * sis_100_set_dmamode - Initialize host controller PATA DMA timings
401 * @ap: Port whose timings we are configuring
402 * @adev: Device to program
403 *
404 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
405 * Handles UDMA66 and early UDMA100 devices.
406 *
407 * LOCKING:
408 * None (inherited from caller).
409 */
410
411static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
412{
413 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
414 int speed = adev->dma_mode - XFER_MW_DMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100415 int drive_pci = sis_old_port_base(adev);
416 u8 timing;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400417
Alan Coxdd668d12007-05-21 15:00:53 +0100418 const u8 udma_bits[] = { 0x8B, 0x87, 0x85, 0x83, 0x82, 0x81};
Jeff Garzik669a5db2006-08-29 18:12:40 -0400419
Alan Coxdd668d12007-05-21 15:00:53 +0100420 pci_read_config_byte(pdev, drive_pci + 1, &timing);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400421
422 if (adev->dma_mode < XFER_UDMA_0) {
423 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
424 } else {
Alan Coxdd668d12007-05-21 15:00:53 +0100425 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400426 speed = adev->dma_mode - XFER_UDMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100427 timing &= ~0x8F;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400428 timing |= udma_bits[speed];
429 }
Alan Coxdd668d12007-05-21 15:00:53 +0100430 pci_write_config_byte(pdev, drive_pci + 1, timing);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400431}
432
433/**
434 * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
435 * @ap: Port whose timings we are configuring
436 * @adev: Device to program
437 *
438 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
Bartlomiej Zolnierkiewicz4761c062007-07-31 22:02:41 +0200439 * Handles early SiS 961 bridges.
Jeff Garzik669a5db2006-08-29 18:12:40 -0400440 *
441 * LOCKING:
442 * None (inherited from caller).
443 */
444
445static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
446{
447 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
448 int speed = adev->dma_mode - XFER_MW_DMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100449 int drive_pci = sis_old_port_base(adev);
450 u8 timing;
451 /* Low 4 bits are timing */
452 static const u8 udma_bits[] = { 0x8F, 0x8A, 0x87, 0x85, 0x83, 0x82, 0x81};
Jeff Garzik669a5db2006-08-29 18:12:40 -0400453
Alan Coxdd668d12007-05-21 15:00:53 +0100454 pci_read_config_byte(pdev, drive_pci + 1, &timing);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400455
456 if (adev->dma_mode < XFER_UDMA_0) {
457 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
458 } else {
Alan Coxdd668d12007-05-21 15:00:53 +0100459 /* Bit 7 is UDMA on/off, bit 0-3 are cycle time */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400460 speed = adev->dma_mode - XFER_UDMA_0;
Alan Coxdd668d12007-05-21 15:00:53 +0100461 timing &= ~0x8F;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400462 timing |= udma_bits[speed];
463 }
Alan Coxdd668d12007-05-21 15:00:53 +0100464 pci_write_config_byte(pdev, drive_pci + 1, timing);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400465}
466
467/**
468 * sis_133_set_dmamode - Initialize host controller PATA DMA timings
469 * @ap: Port whose timings we are configuring
470 * @adev: Device to program
471 *
472 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
Jeff Garzik669a5db2006-08-29 18:12:40 -0400473 *
474 * LOCKING:
475 * None (inherited from caller).
476 */
477
478static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
479{
480 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
481 int speed = adev->dma_mode - XFER_MW_DMA_0;
482 int port = 0x40;
483 u32 t1;
484 u32 reg54;
485
486 /* bits 4- cycle time 8 - cvs time */
Alan Cox2e413f52007-03-07 16:54:24 +0000487 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
488 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400489
490 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
491 pci_read_config_dword(pdev, 0x54, &reg54);
492 if (reg54 & 0x40000000)
493 port = 0x70;
494 port += (8 * ap->port_no) + (4 * adev->devno);
495
496 pci_read_config_dword(pdev, port, &t1);
497
498 if (adev->dma_mode < XFER_UDMA_0) {
499 t1 &= ~0x00000004;
500 /* FIXME: need data sheet to add MWDMA here. Also lacking on
501 ide/pci driver */
502 } else {
503 speed = adev->dma_mode - XFER_UDMA_0;
504 /* if & 8 no UDMA133 - need info for ... */
505 t1 &= ~0x00000FF0;
506 t1 |= 0x00000004;
507 if (t1 & 0x08)
508 t1 |= timing_u133[speed];
509 else
510 t1 |= timing_u100[speed];
511 }
512 pci_write_config_dword(pdev, port, t1);
513}
514
515static struct scsi_host_template sis_sht = {
516 .module = THIS_MODULE,
517 .name = DRV_NAME,
518 .ioctl = ata_scsi_ioctl,
519 .queuecommand = ata_scsi_queuecmd,
520 .can_queue = ATA_DEF_QUEUE,
521 .this_id = ATA_SHT_THIS_ID,
522 .sg_tablesize = LIBATA_MAX_PRD,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400523 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
524 .emulated = ATA_SHT_EMULATED,
525 .use_clustering = ATA_SHT_USE_CLUSTERING,
526 .proc_name = DRV_NAME,
527 .dma_boundary = ATA_DMA_BOUNDARY,
528 .slave_configure = ata_scsi_slave_config,
Tejun Heoafdfe892006-11-29 11:26:47 +0900529 .slave_destroy = ata_scsi_slave_destroy,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400530 .bios_param = ata_std_bios_param,
531};
532
533static const struct ata_port_operations sis_133_ops = {
534 .port_disable = ata_port_disable,
535 .set_piomode = sis_133_set_piomode,
536 .set_dmamode = sis_133_set_dmamode,
537 .mode_filter = ata_pci_default_filter,
538
539 .tf_load = ata_tf_load,
540 .tf_read = ata_tf_read,
541 .check_status = ata_check_status,
542 .exec_command = ata_exec_command,
543 .dev_select = ata_std_dev_select,
544
545 .freeze = ata_bmdma_freeze,
546 .thaw = ata_bmdma_thaw,
Alan Cox2e413f52007-03-07 16:54:24 +0000547 .error_handler = sis_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400548 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Cox2e413f52007-03-07 16:54:24 +0000549 .cable_detect = sis_133_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400550
551 .bmdma_setup = ata_bmdma_setup,
552 .bmdma_start = ata_bmdma_start,
553 .bmdma_stop = ata_bmdma_stop,
554 .bmdma_status = ata_bmdma_status,
555 .qc_prep = ata_qc_prep,
556 .qc_issue = ata_qc_issue_prot,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900557 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400558
Jeff Garzik669a5db2006-08-29 18:12:40 -0400559 .irq_handler = ata_interrupt,
560 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900561 .irq_on = ata_irq_on,
562 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400563
564 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400565};
566
Uwe Kozioleka3cabb22007-06-14 23:40:43 +0200567static const struct ata_port_operations sis_133_for_sata_ops = {
568 .port_disable = ata_port_disable,
569 .set_piomode = sis_133_set_piomode,
570 .set_dmamode = sis_133_set_dmamode,
571 .mode_filter = ata_pci_default_filter,
572
573 .tf_load = ata_tf_load,
574 .tf_read = ata_tf_read,
575 .check_status = ata_check_status,
576 .exec_command = ata_exec_command,
577 .dev_select = ata_std_dev_select,
578
579 .freeze = ata_bmdma_freeze,
580 .thaw = ata_bmdma_thaw,
581 .error_handler = ata_bmdma_error_handler,
582 .post_internal_cmd = ata_bmdma_post_internal_cmd,
583 .cable_detect = sis_133_cable_detect,
584
585 .bmdma_setup = ata_bmdma_setup,
586 .bmdma_start = ata_bmdma_start,
587 .bmdma_stop = ata_bmdma_stop,
588 .bmdma_status = ata_bmdma_status,
589 .qc_prep = ata_qc_prep,
590 .qc_issue = ata_qc_issue_prot,
591 .data_xfer = ata_data_xfer,
592
593 .irq_handler = ata_interrupt,
594 .irq_clear = ata_bmdma_irq_clear,
595 .irq_on = ata_irq_on,
596 .irq_ack = ata_irq_ack,
597
598 .port_start = ata_port_start,
599};
600
Jeff Garzik669a5db2006-08-29 18:12:40 -0400601static const struct ata_port_operations sis_133_early_ops = {
602 .port_disable = ata_port_disable,
603 .set_piomode = sis_100_set_piomode,
604 .set_dmamode = sis_133_early_set_dmamode,
605 .mode_filter = ata_pci_default_filter,
606
607 .tf_load = ata_tf_load,
608 .tf_read = ata_tf_read,
609 .check_status = ata_check_status,
610 .exec_command = ata_exec_command,
611 .dev_select = ata_std_dev_select,
612
613 .freeze = ata_bmdma_freeze,
614 .thaw = ata_bmdma_thaw,
Alan Cox2e413f52007-03-07 16:54:24 +0000615 .error_handler = sis_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400616 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Cox2e413f52007-03-07 16:54:24 +0000617 .cable_detect = sis_66_cable_detect,
Jeff Garzik85cd7252006-08-31 00:03:49 -0400618
Jeff Garzik669a5db2006-08-29 18:12:40 -0400619 .bmdma_setup = ata_bmdma_setup,
620 .bmdma_start = ata_bmdma_start,
621 .bmdma_stop = ata_bmdma_stop,
622 .bmdma_status = ata_bmdma_status,
623 .qc_prep = ata_qc_prep,
624 .qc_issue = ata_qc_issue_prot,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900625 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400626
Jeff Garzik669a5db2006-08-29 18:12:40 -0400627 .irq_handler = ata_interrupt,
628 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900629 .irq_on = ata_irq_on,
630 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400631
632 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400633};
634
635static const struct ata_port_operations sis_100_ops = {
636 .port_disable = ata_port_disable,
637 .set_piomode = sis_100_set_piomode,
638 .set_dmamode = sis_100_set_dmamode,
639 .mode_filter = ata_pci_default_filter,
640
641 .tf_load = ata_tf_load,
642 .tf_read = ata_tf_read,
643 .check_status = ata_check_status,
644 .exec_command = ata_exec_command,
645 .dev_select = ata_std_dev_select,
646
647 .freeze = ata_bmdma_freeze,
648 .thaw = ata_bmdma_thaw,
Alan Cox2e413f52007-03-07 16:54:24 +0000649 .error_handler = sis_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400650 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Cox2e413f52007-03-07 16:54:24 +0000651 .cable_detect = sis_66_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400652
653 .bmdma_setup = ata_bmdma_setup,
654 .bmdma_start = ata_bmdma_start,
655 .bmdma_stop = ata_bmdma_stop,
656 .bmdma_status = ata_bmdma_status,
657 .qc_prep = ata_qc_prep,
658 .qc_issue = ata_qc_issue_prot,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900659 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400660
Jeff Garzik669a5db2006-08-29 18:12:40 -0400661 .irq_handler = ata_interrupt,
662 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900663 .irq_on = ata_irq_on,
664 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400665
666 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400667};
668
669static const struct ata_port_operations sis_66_ops = {
670 .port_disable = ata_port_disable,
671 .set_piomode = sis_old_set_piomode,
672 .set_dmamode = sis_66_set_dmamode,
673 .mode_filter = ata_pci_default_filter,
674
675 .tf_load = ata_tf_load,
676 .tf_read = ata_tf_read,
677 .check_status = ata_check_status,
678 .exec_command = ata_exec_command,
679 .dev_select = ata_std_dev_select,
Alan Cox2e413f52007-03-07 16:54:24 +0000680 .cable_detect = sis_66_cable_detect,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400681
682 .freeze = ata_bmdma_freeze,
683 .thaw = ata_bmdma_thaw,
Alan Cox2e413f52007-03-07 16:54:24 +0000684 .error_handler = sis_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400685 .post_internal_cmd = ata_bmdma_post_internal_cmd,
686
687 .bmdma_setup = ata_bmdma_setup,
688 .bmdma_start = ata_bmdma_start,
689 .bmdma_stop = ata_bmdma_stop,
690 .bmdma_status = ata_bmdma_status,
691 .qc_prep = ata_qc_prep,
692 .qc_issue = ata_qc_issue_prot,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900693 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400694
Jeff Garzik669a5db2006-08-29 18:12:40 -0400695 .irq_handler = ata_interrupt,
696 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900697 .irq_on = ata_irq_on,
698 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400699
700 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400701};
702
703static const struct ata_port_operations sis_old_ops = {
704 .port_disable = ata_port_disable,
705 .set_piomode = sis_old_set_piomode,
706 .set_dmamode = sis_old_set_dmamode,
707 .mode_filter = ata_pci_default_filter,
708
709 .tf_load = ata_tf_load,
710 .tf_read = ata_tf_read,
711 .check_status = ata_check_status,
712 .exec_command = ata_exec_command,
713 .dev_select = ata_std_dev_select,
714
715 .freeze = ata_bmdma_freeze,
716 .thaw = ata_bmdma_thaw,
Alan Cox2e413f52007-03-07 16:54:24 +0000717 .error_handler = sis_error_handler,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400718 .post_internal_cmd = ata_bmdma_post_internal_cmd,
Alan Cox2e413f52007-03-07 16:54:24 +0000719 .cable_detect = ata_cable_40wire,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400720
721 .bmdma_setup = ata_bmdma_setup,
722 .bmdma_start = ata_bmdma_start,
723 .bmdma_stop = ata_bmdma_stop,
724 .bmdma_status = ata_bmdma_status,
725 .qc_prep = ata_qc_prep,
726 .qc_issue = ata_qc_issue_prot,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900727 .data_xfer = ata_data_xfer,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400728
Jeff Garzik669a5db2006-08-29 18:12:40 -0400729 .irq_handler = ata_interrupt,
730 .irq_clear = ata_bmdma_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900731 .irq_on = ata_irq_on,
732 .irq_ack = ata_irq_ack,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400733
734 .port_start = ata_port_start,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400735};
736
Tejun Heo1626aeb2007-05-04 12:43:58 +0200737static const struct ata_port_info sis_info = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400738 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400739 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400740 .pio_mask = 0x1f, /* pio0-4 */
741 .mwdma_mask = 0x07,
742 .udma_mask = 0,
743 .port_ops = &sis_old_ops,
744};
Tejun Heo1626aeb2007-05-04 12:43:58 +0200745static const struct ata_port_info sis_info33 = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400746 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400747 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400748 .pio_mask = 0x1f, /* pio0-4 */
749 .mwdma_mask = 0x07,
750 .udma_mask = ATA_UDMA2, /* UDMA 33 */
751 .port_ops = &sis_old_ops,
752};
Tejun Heo1626aeb2007-05-04 12:43:58 +0200753static const struct ata_port_info sis_info66 = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400754 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400755 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400756 .pio_mask = 0x1f, /* pio0-4 */
757 .udma_mask = ATA_UDMA4, /* UDMA 66 */
758 .port_ops = &sis_66_ops,
759};
Tejun Heo1626aeb2007-05-04 12:43:58 +0200760static const struct ata_port_info sis_info100 = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400761 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400762 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400763 .pio_mask = 0x1f, /* pio0-4 */
764 .udma_mask = ATA_UDMA5,
765 .port_ops = &sis_100_ops,
766};
Tejun Heo1626aeb2007-05-04 12:43:58 +0200767static const struct ata_port_info sis_info100_early = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400768 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400769 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400770 .udma_mask = ATA_UDMA5,
771 .pio_mask = 0x1f, /* pio0-4 */
772 .port_ops = &sis_66_ops,
773};
Uwe Kozioleka3cabb22007-06-14 23:40:43 +0200774static const struct ata_port_info sis_info133 = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400775 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400776 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400777 .pio_mask = 0x1f, /* pio0-4 */
778 .udma_mask = ATA_UDMA6,
779 .port_ops = &sis_133_ops,
780};
Uwe Kozioleka3cabb22007-06-14 23:40:43 +0200781const struct ata_port_info sis_info133_for_sata = {
782 .sht = &sis_sht,
783 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
784 .pio_mask = 0x1f, /* pio0-4 */
785 .udma_mask = ATA_UDMA6,
786 .port_ops = &sis_133_for_sata_ops,
787};
Tejun Heo1626aeb2007-05-04 12:43:58 +0200788static const struct ata_port_info sis_info133_early = {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400789 .sht = &sis_sht,
Jeff Garzik1d2808f2007-05-28 06:59:48 -0400790 .flags = ATA_FLAG_SLAVE_POSS,
Jeff Garzik669a5db2006-08-29 18:12:40 -0400791 .pio_mask = 0x1f, /* pio0-4 */
792 .udma_mask = ATA_UDMA6,
793 .port_ops = &sis_133_early_ops,
794};
795
Alan9b14dec2007-01-08 16:11:07 +0000796/* Privately shared with the SiS180 SATA driver, not for use elsewhere */
Uwe Kozioleka3cabb22007-06-14 23:40:43 +0200797EXPORT_SYMBOL_GPL(sis_info133_for_sata);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400798
799static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
800{
801 u16 regw;
802 u8 reg;
803
804 if (sis->info == &sis_info133) {
805 pci_read_config_word(pdev, 0x50, &regw);
806 if (regw & 0x08)
807 pci_write_config_word(pdev, 0x50, regw & ~0x08);
808 pci_read_config_word(pdev, 0x52, &regw);
809 if (regw & 0x08)
810 pci_write_config_word(pdev, 0x52, regw & ~0x08);
811 return;
812 }
813
814 if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
815 /* Fix up latency */
816 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
817 /* Set compatibility bit */
818 pci_read_config_byte(pdev, 0x49, &reg);
819 if (!(reg & 0x01))
820 pci_write_config_byte(pdev, 0x49, reg | 0x01);
821 return;
822 }
823
824 if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
825 /* Fix up latency */
826 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
827 /* Set compatibility bit */
828 pci_read_config_byte(pdev, 0x52, &reg);
829 if (!(reg & 0x04))
830 pci_write_config_byte(pdev, 0x52, reg | 0x04);
831 return;
832 }
833
834 if (sis->info == &sis_info33) {
835 pci_read_config_byte(pdev, PCI_CLASS_PROG, &reg);
836 if (( reg & 0x0F ) != 0x00)
837 pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
838 /* Fall through to ATA16 fixup below */
839 }
840
841 if (sis->info == &sis_info || sis->info == &sis_info33) {
842 /* force per drive recovery and active timings
843 needed on ATA_33 and below chips */
844 pci_read_config_byte(pdev, 0x52, &reg);
845 if (!(reg & 0x08))
846 pci_write_config_byte(pdev, 0x52, reg|0x08);
847 return;
848 }
849
850 BUG();
851}
852
853/**
854 * sis_init_one - Register SiS ATA PCI device with kernel services
855 * @pdev: PCI device to register
856 * @ent: Entry in sis_pci_tbl matching with @pdev
857 *
858 * Called from kernel PCI layer. We probe for combined mode (sigh),
859 * and then hand over control to libata, for it to do the rest.
860 *
861 * LOCKING:
862 * Inherited from PCI layer (may sleep).
863 *
864 * RETURNS:
865 * Zero on success, or -ERRNO value.
866 */
867
868static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
869{
870 static int printed_version;
Tejun Heo1626aeb2007-05-04 12:43:58 +0200871 struct ata_port_info port;
872 const struct ata_port_info *ppi[] = { &port, NULL };
Jeff Garzik669a5db2006-08-29 18:12:40 -0400873 struct pci_dev *host = NULL;
874 struct sis_chipset *chipset = NULL;
Alan Coxf3769e92007-04-19 11:09:52 +0100875 struct sis_chipset *sets;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400876
877 static struct sis_chipset sis_chipsets[] = {
Jeff Garzikf20b16f2006-12-11 11:14:06 -0500878
Alan Coxaf323a22006-09-12 17:15:12 +0100879 { 0x0968, &sis_info133 },
880 { 0x0966, &sis_info133 },
881 { 0x0965, &sis_info133 },
Jeff Garzik669a5db2006-08-29 18:12:40 -0400882 { 0x0745, &sis_info100 },
883 { 0x0735, &sis_info100 },
884 { 0x0733, &sis_info100 },
885 { 0x0635, &sis_info100 },
886 { 0x0633, &sis_info100 },
887
888 { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
889 { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
890
891 { 0x0640, &sis_info66 },
892 { 0x0630, &sis_info66 },
893 { 0x0620, &sis_info66 },
894 { 0x0540, &sis_info66 },
895 { 0x0530, &sis_info66 },
896
897 { 0x5600, &sis_info33 },
898 { 0x5598, &sis_info33 },
899 { 0x5597, &sis_info33 },
900 { 0x5591, &sis_info33 },
901 { 0x5582, &sis_info33 },
902 { 0x5581, &sis_info33 },
903
904 { 0x5596, &sis_info },
905 { 0x5571, &sis_info },
906 { 0x5517, &sis_info },
907 { 0x5511, &sis_info },
908
909 {0}
910 };
911 static struct sis_chipset sis133_early = {
912 0x0, &sis_info133_early
913 };
914 static struct sis_chipset sis133 = {
915 0x0, &sis_info133
916 };
917 static struct sis_chipset sis100_early = {
918 0x0, &sis_info100_early
919 };
920 static struct sis_chipset sis100 = {
921 0x0, &sis_info100
922 };
923
924 if (!printed_version++)
925 dev_printk(KERN_DEBUG, &pdev->dev,
926 "version " DRV_VERSION "\n");
927
928 /* We have to find the bridge first */
929
Alan Coxf3769e92007-04-19 11:09:52 +0100930 for (sets = &sis_chipsets[0]; sets->device; sets++) {
931 host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
Jeff Garzik669a5db2006-08-29 18:12:40 -0400932 if (host != NULL) {
Alan Coxf3769e92007-04-19 11:09:52 +0100933 chipset = sets; /* Match found */
934 if (sets->device == 0x630) { /* SIS630 */
Auke Kok44c10132007-06-08 15:46:36 -0700935 if (host->revision >= 0x30) /* 630 ET */
Jeff Garzik669a5db2006-08-29 18:12:40 -0400936 chipset = &sis100_early;
937 }
938 break;
939 }
940 }
941
942 /* Look for concealed bridges */
Alan Coxf3769e92007-04-19 11:09:52 +0100943 if (chipset == NULL) {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400944 /* Second check */
945 u32 idemisc;
946 u16 trueid;
947
948 /* Disable ID masking and register remapping then
949 see what the real ID is */
950
951 pci_read_config_dword(pdev, 0x54, &idemisc);
952 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
953 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
954 pci_write_config_dword(pdev, 0x54, idemisc);
955
956 switch(trueid) {
957 case 0x5518: /* SIS 962/963 */
958 chipset = &sis133;
959 if ((idemisc & 0x40000000) == 0) {
960 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
961 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
962 }
963 break;
964 case 0x0180: /* SIS 965/965L */
965 chipset = &sis133;
966 break;
967 case 0x1180: /* SIS 966/966L */
968 chipset = &sis133;
969 break;
970 }
971 }
972
973 /* Further check */
974 if (chipset == NULL) {
975 struct pci_dev *lpc_bridge;
976 u16 trueid;
977 u8 prefctl;
978 u8 idecfg;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400979
980 /* Try the second unmasking technique */
981 pci_read_config_byte(pdev, 0x4a, &idecfg);
982 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
983 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
984 pci_write_config_byte(pdev, 0x4a, idecfg);
985
986 switch(trueid) {
987 case 0x5517:
988 lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
989 if (lpc_bridge == NULL)
990 break;
Jeff Garzik669a5db2006-08-29 18:12:40 -0400991 pci_read_config_byte(pdev, 0x49, &prefctl);
992 pci_dev_put(lpc_bridge);
993
Auke Kok44c10132007-06-08 15:46:36 -0700994 if (lpc_bridge->revision == 0x10 && (prefctl & 0x80)) {
Jeff Garzik669a5db2006-08-29 18:12:40 -0400995 chipset = &sis133_early;
996 break;
997 }
998 chipset = &sis100;
999 break;
1000 }
1001 }
1002 pci_dev_put(host);
1003
1004 /* No chipset info, no support */
1005 if (chipset == NULL)
1006 return -ENODEV;
1007
Tejun Heo1626aeb2007-05-04 12:43:58 +02001008 port = *chipset->info;
1009 port.private_data = chipset;
Jeff Garzik669a5db2006-08-29 18:12:40 -04001010
1011 sis_fixup(pdev, chipset);
1012
Tejun Heo1626aeb2007-05-04 12:43:58 +02001013 return ata_pci_init_one(pdev, ppi);
Jeff Garzik669a5db2006-08-29 18:12:40 -04001014}
1015
1016static const struct pci_device_id sis_pci_tbl[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -04001017 { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
1018 { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
Uwe Kozioleka3cabb22007-06-14 23:40:43 +02001019 { PCI_VDEVICE(SI, 0x1180), }, /* SiS 1180 */
Jeff Garzik2d2744f2006-09-28 20:21:59 -04001020
Jeff Garzik669a5db2006-08-29 18:12:40 -04001021 { }
1022};
1023
1024static struct pci_driver sis_pci_driver = {
1025 .name = DRV_NAME,
1026 .id_table = sis_pci_tbl,
1027 .probe = sis_init_one,
1028 .remove = ata_pci_remove_one,
Tejun Heo438ac6d2007-03-02 17:31:26 +09001029#ifdef CONFIG_PM
Alan62d64ae2006-11-27 16:27:20 +00001030 .suspend = ata_pci_device_suspend,
1031 .resume = ata_pci_device_resume,
Tejun Heo438ac6d2007-03-02 17:31:26 +09001032#endif
Jeff Garzik669a5db2006-08-29 18:12:40 -04001033};
1034
1035static int __init sis_init(void)
1036{
1037 return pci_register_driver(&sis_pci_driver);
1038}
1039
1040static void __exit sis_exit(void)
1041{
1042 pci_unregister_driver(&sis_pci_driver);
1043}
1044
Jeff Garzik669a5db2006-08-29 18:12:40 -04001045module_init(sis_init);
1046module_exit(sis_exit);
1047
1048MODULE_AUTHOR("Alan Cox");
1049MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
1050MODULE_LICENSE("GPL");
1051MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
1052MODULE_VERSION(DRV_VERSION);
1053