2 * pata_sis.c - SiS ATA driver
4 * (C) 2005 Red Hat <alan@redhat.com>
6 * Based upon linux/drivers/ide/pci/sis5513.c
7 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
8 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
9 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
10 * SiS Taiwan : for direct support and hardware.
11 * Daniela Engert : for initial ATA100 advices and numerous others.
12 * John Fremlin, Manfred Spraul, Dave Morgan, Peter Kjellerstedt :
13 * for checking code correctness, providing patches.
14 * Original tests and design on the SiS620 chipset.
15 * ATA100 tests and design on the SiS735 chipset.
16 * ATA16/33 support from specs
17 * ATA133 support for SiS961/962 by L.C. Chang <lcchang@sis.com.tw>
21 * Check MWDMA on drives that don't support MWDMA speed pio cycles ?
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/pci.h>
28 #include <linux/init.h>
29 #include <linux/blkdev.h>
30 #include <linux/delay.h>
31 #include <linux/device.h>
32 #include <scsi/scsi_host.h>
33 #include <linux/libata.h>
34 #include <linux/ata.h>
37 #define DRV_NAME "pata_sis"
38 #define DRV_VERSION "0.5.1"
41 u16 device; /* PCI host ID */
42 struct ata_port_info *info; /* Info block */
43 /* Probably add family, cable detect type etc here to clean
53 static const struct sis_laptop sis_laptop[] = {
54 /* devid, subvendor, subdev */
55 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
60 static int sis_short_ata40(struct pci_dev *dev)
62 const struct sis_laptop *lap = &sis_laptop[0];
65 if (lap->device == dev->device &&
66 lap->subvendor == dev->subsystem_vendor &&
67 lap->subdevice == dev->subsystem_device)
76 * sis_port_base - return PCI configuration base for dev
79 * Returns the base of the PCI configuration registers for this port
83 static int sis_port_base(struct ata_device *adev)
85 return 0x40 + (4 * adev->ap->port_no) + (2 * adev->devno);
89 * sis_133_cable_detect - check for 40/80 pin
91 * @deadline: deadline jiffies for the operation
93 * Perform cable detection for the later UDMA133 capable
97 static int sis_133_cable_detect(struct ata_port *ap)
99 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
102 /* The top bit of this register is the cable detect bit */
103 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
104 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
105 return ATA_CBL_PATA40;
106 return ATA_CBL_PATA80;
110 * sis_66_cable_detect - check for 40/80 pin
112 * @deadline: deadline jiffies for the operation
114 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
115 * SiS IDE controllers.
118 static int sis_66_cable_detect(struct ata_port *ap)
120 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
123 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
124 pci_read_config_byte(pdev, 0x48, &tmp);
126 if ((tmp & 0x10) && !sis_short_ata40(pdev))
127 return ATA_CBL_PATA40;
128 return ATA_CBL_PATA80;
133 * sis_pre_reset - probe begin
135 * @deadline: deadline jiffies for the operation
137 * Set up cable type and use generic probe init
140 static int sis_old_pre_reset(struct ata_port *ap, unsigned long deadline)
142 static const struct pci_bits sis_enable_bits[] = {
143 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
144 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
147 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
149 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
152 return ata_std_prereset(ap, deadline);
157 * sis_error_handler - Probe specified port on PATA host controller
161 * None (inherited from caller).
164 static void sis_error_handler(struct ata_port *ap)
166 ata_bmdma_drive_eh(ap, sis_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
170 * sis_set_fifo - Set RWP fifo bits for this device
174 * SIS chipsets implement prefetch/postwrite bits for each device
175 * on both channels. This functionality is not ATAPI compatible and
176 * must be configured according to the class of device present
179 static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
181 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
185 mask <<= (2 * ap->port_no);
186 mask <<= adev->devno;
188 /* This holds various bits including the FIFO control */
189 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
192 /* Enable for ATA (disk) only */
193 if (adev->class == ATA_DEV_ATA)
195 pci_write_config_byte(pdev, 0x4B, fifoctrl);
199 * sis_old_set_piomode - Initialize host controller PATA PIO timings
200 * @ap: Port whose timings we are configuring
201 * @adev: Device we are configuring for.
203 * Set PIO mode for device, in host controller PCI config space. This
204 * function handles PIO set up for all chips that are pre ATA100 and
205 * also early ATA100 devices.
208 * None (inherited from caller).
211 static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
213 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
214 int port = sis_port_base(adev);
216 int speed = adev->pio_mode - XFER_PIO_0;
218 const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
219 const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
221 sis_set_fifo(ap, adev);
223 pci_read_config_byte(pdev, port, &t1);
224 pci_read_config_byte(pdev, port + 1, &t2);
226 t1 &= ~0x0F; /* Clear active/recovery timings */
230 t2 |= recovery[speed];
232 pci_write_config_byte(pdev, port, t1);
233 pci_write_config_byte(pdev, port + 1, t2);
237 * sis_100_set_pioode - Initialize host controller PATA PIO timings
238 * @ap: Port whose timings we are configuring
239 * @adev: Device we are configuring for.
241 * Set PIO mode for device, in host controller PCI config space. This
242 * function handles PIO set up for ATA100 devices and early ATA133.
245 * None (inherited from caller).
248 static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
250 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
251 int port = sis_port_base(adev);
252 int speed = adev->pio_mode - XFER_PIO_0;
254 const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
256 sis_set_fifo(ap, adev);
258 pci_write_config_byte(pdev, port, actrec[speed]);
262 * sis_133_set_pioode - Initialize host controller PATA PIO timings
263 * @ap: Port whose timings we are configuring
264 * @adev: Device we are configuring for.
266 * Set PIO mode for device, in host controller PCI config space. This
267 * function handles PIO set up for the later ATA133 devices.
270 * None (inherited from caller).
273 static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
275 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
279 int speed = adev->pio_mode - XFER_PIO_0;
281 const u32 timing133[] = {
282 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
288 const u32 timing100[] = {
289 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
296 sis_set_fifo(ap, adev);
298 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
299 pci_read_config_dword(pdev, 0x54, ®54);
300 if (reg54 & 0x40000000)
302 port += 8 * ap->port_no + 4 * adev->devno;
304 pci_read_config_dword(pdev, port, &t1);
305 t1 &= 0xC0C00FFF; /* Mask out timing */
307 if (t1 & 0x08) /* 100 or 133 ? */
308 t1 |= timing133[speed];
310 t1 |= timing100[speed];
311 pci_write_config_byte(pdev, port, t1);
315 * sis_old_set_dmamode - Initialize host controller PATA DMA timings
316 * @ap: Port whose timings we are configuring
317 * @adev: Device to program
319 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
320 * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
321 * the old ide/pci driver.
324 * None (inherited from caller).
327 static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
329 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
330 int speed = adev->dma_mode - XFER_MW_DMA_0;
331 int drive_pci = sis_port_base(adev);
334 const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
335 const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
337 pci_read_config_word(pdev, drive_pci, &timing);
339 if (adev->dma_mode < XFER_UDMA_0) {
340 /* bits 3-0 hold recovery timing bits 8-10 active timing and
341 the higer bits are dependant on the device */
343 timing |= mwdma_bits[speed];
344 pci_write_config_word(pdev, drive_pci, timing);
346 /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
347 speed = adev->dma_mode - XFER_UDMA_0;
349 timing |= udma_bits[speed];
354 * sis_66_set_dmamode - Initialize host controller PATA DMA timings
355 * @ap: Port whose timings we are configuring
356 * @adev: Device to program
358 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
359 * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
360 * the old ide/pci driver.
363 * None (inherited from caller).
366 static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
368 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
369 int speed = adev->dma_mode - XFER_MW_DMA_0;
370 int drive_pci = sis_port_base(adev);
373 const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
374 const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000};
376 pci_read_config_word(pdev, drive_pci, &timing);
378 if (adev->dma_mode < XFER_UDMA_0) {
379 /* bits 3-0 hold recovery timing bits 8-10 active timing and
380 the higer bits are dependant on the device, bit 15 udma */
382 timing |= mwdma_bits[speed];
384 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
385 speed = adev->dma_mode - XFER_UDMA_0;
387 timing |= udma_bits[speed];
389 pci_write_config_word(pdev, drive_pci, timing);
393 * sis_100_set_dmamode - Initialize host controller PATA DMA timings
394 * @ap: Port whose timings we are configuring
395 * @adev: Device to program
397 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
398 * Handles UDMA66 and early UDMA100 devices.
401 * None (inherited from caller).
404 static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
406 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
407 int speed = adev->dma_mode - XFER_MW_DMA_0;
408 int drive_pci = sis_port_base(adev);
411 const u16 udma_bits[] = { 0x8B00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
413 pci_read_config_word(pdev, drive_pci, &timing);
415 if (adev->dma_mode < XFER_UDMA_0) {
416 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
418 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
419 speed = adev->dma_mode - XFER_UDMA_0;
421 timing |= udma_bits[speed];
423 pci_write_config_word(pdev, drive_pci, timing);
427 * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
428 * @ap: Port whose timings we are configuring
429 * @adev: Device to program
431 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
432 * Handles early SiS 961 bridges. Supports MWDMA as well unlike
433 * the old ide/pci driver.
436 * None (inherited from caller).
439 static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
441 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
442 int speed = adev->dma_mode - XFER_MW_DMA_0;
443 int drive_pci = sis_port_base(adev);
446 static const u16 udma_bits[] = { 0x8F00, 0x8A00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
448 pci_read_config_word(pdev, drive_pci, &timing);
450 if (adev->dma_mode < XFER_UDMA_0) {
451 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
453 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
454 speed = adev->dma_mode - XFER_UDMA_0;
456 timing |= udma_bits[speed];
458 pci_write_config_word(pdev, drive_pci, timing);
462 * sis_133_set_dmamode - Initialize host controller PATA DMA timings
463 * @ap: Port whose timings we are configuring
464 * @adev: Device to program
466 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
467 * Handles early SiS 961 bridges. Supports MWDMA as well unlike
468 * the old ide/pci driver.
471 * None (inherited from caller).
474 static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
476 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
477 int speed = adev->dma_mode - XFER_MW_DMA_0;
482 /* bits 4- cycle time 8 - cvs time */
483 static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
484 static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
486 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
487 pci_read_config_dword(pdev, 0x54, ®54);
488 if (reg54 & 0x40000000)
490 port += (8 * ap->port_no) + (4 * adev->devno);
492 pci_read_config_dword(pdev, port, &t1);
494 if (adev->dma_mode < XFER_UDMA_0) {
496 /* FIXME: need data sheet to add MWDMA here. Also lacking on
499 speed = adev->dma_mode - XFER_UDMA_0;
500 /* if & 8 no UDMA133 - need info for ... */
504 t1 |= timing_u133[speed];
506 t1 |= timing_u100[speed];
508 pci_write_config_dword(pdev, port, t1);
511 static struct scsi_host_template sis_sht = {
512 .module = THIS_MODULE,
514 .ioctl = ata_scsi_ioctl,
515 .queuecommand = ata_scsi_queuecmd,
516 .can_queue = ATA_DEF_QUEUE,
517 .this_id = ATA_SHT_THIS_ID,
518 .sg_tablesize = LIBATA_MAX_PRD,
519 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
520 .emulated = ATA_SHT_EMULATED,
521 .use_clustering = ATA_SHT_USE_CLUSTERING,
522 .proc_name = DRV_NAME,
523 .dma_boundary = ATA_DMA_BOUNDARY,
524 .slave_configure = ata_scsi_slave_config,
525 .slave_destroy = ata_scsi_slave_destroy,
526 .bios_param = ata_std_bios_param,
528 .resume = ata_scsi_device_resume,
529 .suspend = ata_scsi_device_suspend,
533 static 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,
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,
545 .freeze = ata_bmdma_freeze,
546 .thaw = ata_bmdma_thaw,
547 .error_handler = sis_error_handler,
548 .post_internal_cmd = ata_bmdma_post_internal_cmd,
549 .cable_detect = sis_133_cable_detect,
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,
557 .data_xfer = ata_data_xfer,
559 .irq_handler = ata_interrupt,
560 .irq_clear = ata_bmdma_irq_clear,
561 .irq_on = ata_irq_on,
562 .irq_ack = ata_irq_ack,
564 .port_start = ata_port_start,
567 static const struct ata_port_operations sis_133_early_ops = {
568 .port_disable = ata_port_disable,
569 .set_piomode = sis_100_set_piomode,
570 .set_dmamode = sis_133_early_set_dmamode,
571 .mode_filter = ata_pci_default_filter,
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,
579 .freeze = ata_bmdma_freeze,
580 .thaw = ata_bmdma_thaw,
581 .error_handler = sis_error_handler,
582 .post_internal_cmd = ata_bmdma_post_internal_cmd,
583 .cable_detect = sis_66_cable_detect,
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,
593 .irq_handler = ata_interrupt,
594 .irq_clear = ata_bmdma_irq_clear,
595 .irq_on = ata_irq_on,
596 .irq_ack = ata_irq_ack,
598 .port_start = ata_port_start,
601 static const struct ata_port_operations sis_100_ops = {
602 .port_disable = ata_port_disable,
603 .set_piomode = sis_100_set_piomode,
604 .set_dmamode = sis_100_set_dmamode,
605 .mode_filter = ata_pci_default_filter,
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,
613 .freeze = ata_bmdma_freeze,
614 .thaw = ata_bmdma_thaw,
615 .error_handler = sis_error_handler,
616 .post_internal_cmd = ata_bmdma_post_internal_cmd,
617 .cable_detect = sis_66_cable_detect,
619 .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,
625 .data_xfer = ata_data_xfer,
627 .irq_handler = ata_interrupt,
628 .irq_clear = ata_bmdma_irq_clear,
629 .irq_on = ata_irq_on,
630 .irq_ack = ata_irq_ack,
632 .port_start = ata_port_start,
635 static const struct ata_port_operations sis_66_ops = {
636 .port_disable = ata_port_disable,
637 .set_piomode = sis_old_set_piomode,
638 .set_dmamode = sis_66_set_dmamode,
639 .mode_filter = ata_pci_default_filter,
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 .cable_detect = sis_66_cable_detect,
648 .freeze = ata_bmdma_freeze,
649 .thaw = ata_bmdma_thaw,
650 .error_handler = sis_error_handler,
651 .post_internal_cmd = ata_bmdma_post_internal_cmd,
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,
659 .data_xfer = ata_data_xfer,
661 .irq_handler = ata_interrupt,
662 .irq_clear = ata_bmdma_irq_clear,
663 .irq_on = ata_irq_on,
664 .irq_ack = ata_irq_ack,
666 .port_start = ata_port_start,
669 static const struct ata_port_operations sis_old_ops = {
670 .port_disable = ata_port_disable,
671 .set_piomode = sis_old_set_piomode,
672 .set_dmamode = sis_old_set_dmamode,
673 .mode_filter = ata_pci_default_filter,
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,
681 .freeze = ata_bmdma_freeze,
682 .thaw = ata_bmdma_thaw,
683 .error_handler = sis_error_handler,
684 .post_internal_cmd = ata_bmdma_post_internal_cmd,
685 .cable_detect = ata_cable_40wire,
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,
693 .data_xfer = ata_data_xfer,
695 .irq_handler = ata_interrupt,
696 .irq_clear = ata_bmdma_irq_clear,
697 .irq_on = ata_irq_on,
698 .irq_ack = ata_irq_ack,
700 .port_start = ata_port_start,
703 static struct ata_port_info sis_info = {
705 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
706 .pio_mask = 0x1f, /* pio0-4 */
709 .port_ops = &sis_old_ops,
711 static struct ata_port_info sis_info33 = {
713 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
714 .pio_mask = 0x1f, /* pio0-4 */
716 .udma_mask = ATA_UDMA2, /* UDMA 33 */
717 .port_ops = &sis_old_ops,
719 static struct ata_port_info sis_info66 = {
721 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
722 .pio_mask = 0x1f, /* pio0-4 */
723 .udma_mask = ATA_UDMA4, /* UDMA 66 */
724 .port_ops = &sis_66_ops,
726 static struct ata_port_info sis_info100 = {
728 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
729 .pio_mask = 0x1f, /* pio0-4 */
730 .udma_mask = ATA_UDMA5,
731 .port_ops = &sis_100_ops,
733 static struct ata_port_info sis_info100_early = {
735 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
736 .udma_mask = ATA_UDMA5,
737 .pio_mask = 0x1f, /* pio0-4 */
738 .port_ops = &sis_66_ops,
740 struct ata_port_info sis_info133 = {
742 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
743 .pio_mask = 0x1f, /* pio0-4 */
744 .udma_mask = ATA_UDMA6,
745 .port_ops = &sis_133_ops,
747 static struct ata_port_info sis_info133_early = {
749 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
750 .pio_mask = 0x1f, /* pio0-4 */
751 .udma_mask = ATA_UDMA6,
752 .port_ops = &sis_133_early_ops,
755 /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
756 EXPORT_SYMBOL_GPL(sis_info133);
758 static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
763 if (sis->info == &sis_info133) {
764 pci_read_config_word(pdev, 0x50, ®w);
766 pci_write_config_word(pdev, 0x50, regw & ~0x08);
767 pci_read_config_word(pdev, 0x52, ®w);
769 pci_write_config_word(pdev, 0x52, regw & ~0x08);
773 if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
775 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
776 /* Set compatibility bit */
777 pci_read_config_byte(pdev, 0x49, ®);
779 pci_write_config_byte(pdev, 0x49, reg | 0x01);
783 if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
785 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
786 /* Set compatibility bit */
787 pci_read_config_byte(pdev, 0x52, ®);
789 pci_write_config_byte(pdev, 0x52, reg | 0x04);
793 if (sis->info == &sis_info33) {
794 pci_read_config_byte(pdev, PCI_CLASS_PROG, ®);
795 if (( reg & 0x0F ) != 0x00)
796 pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
797 /* Fall through to ATA16 fixup below */
800 if (sis->info == &sis_info || sis->info == &sis_info33) {
801 /* force per drive recovery and active timings
802 needed on ATA_33 and below chips */
803 pci_read_config_byte(pdev, 0x52, ®);
805 pci_write_config_byte(pdev, 0x52, reg|0x08);
813 * sis_init_one - Register SiS ATA PCI device with kernel services
814 * @pdev: PCI device to register
815 * @ent: Entry in sis_pci_tbl matching with @pdev
817 * Called from kernel PCI layer. We probe for combined mode (sigh),
818 * and then hand over control to libata, for it to do the rest.
821 * Inherited from PCI layer (may sleep).
824 * Zero on success, or -ERRNO value.
827 static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
829 static int printed_version;
830 static struct ata_port_info *port_info[2];
831 struct ata_port_info *port;
832 struct pci_dev *host = NULL;
833 struct sis_chipset *chipset = NULL;
834 struct sis_chipset *sets;
836 static struct sis_chipset sis_chipsets[] = {
838 { 0x0968, &sis_info133 },
839 { 0x0966, &sis_info133 },
840 { 0x0965, &sis_info133 },
841 { 0x0745, &sis_info100 },
842 { 0x0735, &sis_info100 },
843 { 0x0733, &sis_info100 },
844 { 0x0635, &sis_info100 },
845 { 0x0633, &sis_info100 },
847 { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
848 { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
850 { 0x0640, &sis_info66 },
851 { 0x0630, &sis_info66 },
852 { 0x0620, &sis_info66 },
853 { 0x0540, &sis_info66 },
854 { 0x0530, &sis_info66 },
856 { 0x5600, &sis_info33 },
857 { 0x5598, &sis_info33 },
858 { 0x5597, &sis_info33 },
859 { 0x5591, &sis_info33 },
860 { 0x5582, &sis_info33 },
861 { 0x5581, &sis_info33 },
863 { 0x5596, &sis_info },
864 { 0x5571, &sis_info },
865 { 0x5517, &sis_info },
866 { 0x5511, &sis_info },
870 static struct sis_chipset sis133_early = {
871 0x0, &sis_info133_early
873 static struct sis_chipset sis133 = {
876 static struct sis_chipset sis100_early = {
877 0x0, &sis_info100_early
879 static struct sis_chipset sis100 = {
883 if (!printed_version++)
884 dev_printk(KERN_DEBUG, &pdev->dev,
885 "version " DRV_VERSION "\n");
887 /* We have to find the bridge first */
889 for (sets = &sis_chipsets[0]; sets->device; sets++) {
890 host = pci_get_device(PCI_VENDOR_ID_SI, sets->device, NULL);
892 chipset = sets; /* Match found */
893 if (sets->device == 0x630) { /* SIS630 */
895 pci_read_config_byte(host, PCI_REVISION_ID, &host_rev);
896 if (host_rev >= 0x30) /* 630 ET */
897 chipset = &sis100_early;
903 /* Look for concealed bridges */
904 if (chipset == NULL) {
909 /* Disable ID masking and register remapping then
910 see what the real ID is */
912 pci_read_config_dword(pdev, 0x54, &idemisc);
913 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
914 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
915 pci_write_config_dword(pdev, 0x54, idemisc);
918 case 0x5518: /* SIS 962/963 */
920 if ((idemisc & 0x40000000) == 0) {
921 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
922 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
925 case 0x0180: /* SIS 965/965L */
928 case 0x1180: /* SIS 966/966L */
935 if (chipset == NULL) {
936 struct pci_dev *lpc_bridge;
942 /* Try the second unmasking technique */
943 pci_read_config_byte(pdev, 0x4a, &idecfg);
944 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
945 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
946 pci_write_config_byte(pdev, 0x4a, idecfg);
950 lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
951 if (lpc_bridge == NULL)
953 pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
954 pci_read_config_byte(pdev, 0x49, &prefctl);
955 pci_dev_put(lpc_bridge);
957 if (sbrev == 0x10 && (prefctl & 0x80)) {
958 chipset = &sis133_early;
967 /* No chipset info, no support */
971 port = chipset->info;
972 port->private_data = chipset;
974 sis_fixup(pdev, chipset);
976 port_info[0] = port_info[1] = port;
977 return ata_pci_init_one(pdev, port_info, 2);
980 static const struct pci_device_id sis_pci_tbl[] = {
981 { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
982 { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
987 static struct pci_driver sis_pci_driver = {
989 .id_table = sis_pci_tbl,
990 .probe = sis_init_one,
991 .remove = ata_pci_remove_one,
993 .suspend = ata_pci_device_suspend,
994 .resume = ata_pci_device_resume,
998 static int __init sis_init(void)
1000 return pci_register_driver(&sis_pci_driver);
1003 static void __exit sis_exit(void)
1005 pci_unregister_driver(&sis_pci_driver);
1008 module_init(sis_init);
1009 module_exit(sis_exit);
1011 MODULE_AUTHOR("Alan Cox");
1012 MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
1013 MODULE_LICENSE("GPL");
1014 MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
1015 MODULE_VERSION(DRV_VERSION);