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.0"
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_pre_reset - check for 40/80 pin
92 * Perform cable detection for the later UDMA133 capable
96 static int sis_133_pre_reset(struct ata_port *ap)
98 static const struct pci_bits sis_enable_bits[] = {
99 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
100 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
103 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
106 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
109 /* The top bit of this register is the cable detect bit */
110 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
111 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
112 ap->cbl = ATA_CBL_PATA40;
114 ap->cbl = ATA_CBL_PATA80;
116 return ata_std_prereset(ap);
120 * sis_error_handler - Probe specified port on PATA host controller
124 * None (inherited from caller).
127 static void sis_133_error_handler(struct ata_port *ap)
129 ata_bmdma_drive_eh(ap, sis_133_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
134 * sis_66_pre_reset - check for 40/80 pin
137 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
138 * SiS IDE controllers.
141 static int sis_66_pre_reset(struct ata_port *ap)
143 static const struct pci_bits sis_enable_bits[] = {
144 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
145 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
148 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
151 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) {
152 ata_port_disable(ap);
153 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
156 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
157 pci_read_config_byte(pdev, 0x48, &tmp);
159 if ((tmp & 0x10) && !sis_short_ata40(pdev))
160 ap->cbl = ATA_CBL_PATA40;
162 ap->cbl = ATA_CBL_PATA80;
164 return ata_std_prereset(ap);
168 * sis_66_error_handler - Probe specified port on PATA host controller
173 * None (inherited from caller).
176 static void sis_66_error_handler(struct ata_port *ap)
178 ata_bmdma_drive_eh(ap, sis_66_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
182 * sis_old_pre_reset - probe begin
185 * Set up cable type and use generic probe init
188 static int sis_old_pre_reset(struct ata_port *ap)
190 static const struct pci_bits sis_enable_bits[] = {
191 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
192 { 0x4aU, 1U, 0x04UL, 0x04UL }, /* port 1 */
195 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
197 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) {
198 ata_port_disable(ap);
199 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
202 ap->cbl = ATA_CBL_PATA40;
203 return ata_std_prereset(ap);
208 * sis_old_error_handler - Probe specified port on PATA host controller
212 * None (inherited from caller).
215 static void sis_old_error_handler(struct ata_port *ap)
217 ata_bmdma_drive_eh(ap, sis_old_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
221 * sis_set_fifo - Set RWP fifo bits for this device
225 * SIS chipsets implement prefetch/postwrite bits for each device
226 * on both channels. This functionality is not ATAPI compatible and
227 * must be configured according to the class of device present
230 static void sis_set_fifo(struct ata_port *ap, struct ata_device *adev)
232 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
236 mask <<= (2 * ap->port_no);
237 mask <<= adev->devno;
239 /* This holds various bits including the FIFO control */
240 pci_read_config_byte(pdev, 0x4B, &fifoctrl);
243 /* Enable for ATA (disk) only */
244 if (adev->class == ATA_DEV_ATA)
246 pci_write_config_byte(pdev, 0x4B, fifoctrl);
250 * sis_old_set_piomode - Initialize host controller PATA PIO timings
251 * @ap: Port whose timings we are configuring
252 * @adev: Device we are configuring for.
254 * Set PIO mode for device, in host controller PCI config space. This
255 * function handles PIO set up for all chips that are pre ATA100 and
256 * also early ATA100 devices.
259 * None (inherited from caller).
262 static void sis_old_set_piomode (struct ata_port *ap, struct ata_device *adev)
264 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
265 int port = sis_port_base(adev);
267 int speed = adev->pio_mode - XFER_PIO_0;
269 const u8 active[] = { 0x00, 0x07, 0x04, 0x03, 0x01 };
270 const u8 recovery[] = { 0x00, 0x06, 0x04, 0x03, 0x03 };
272 sis_set_fifo(ap, adev);
274 pci_read_config_byte(pdev, port, &t1);
275 pci_read_config_byte(pdev, port + 1, &t2);
277 t1 &= ~0x0F; /* Clear active/recovery timings */
281 t2 |= recovery[speed];
283 pci_write_config_byte(pdev, port, t1);
284 pci_write_config_byte(pdev, port + 1, t2);
288 * sis_100_set_pioode - Initialize host controller PATA PIO timings
289 * @ap: Port whose timings we are configuring
290 * @adev: Device we are configuring for.
292 * Set PIO mode for device, in host controller PCI config space. This
293 * function handles PIO set up for ATA100 devices and early ATA133.
296 * None (inherited from caller).
299 static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev)
301 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
302 int port = sis_port_base(adev);
303 int speed = adev->pio_mode - XFER_PIO_0;
305 const u8 actrec[] = { 0x00, 0x67, 0x44, 0x33, 0x31 };
307 sis_set_fifo(ap, adev);
309 pci_write_config_byte(pdev, port, actrec[speed]);
313 * sis_133_set_pioode - Initialize host controller PATA PIO timings
314 * @ap: Port whose timings we are configuring
315 * @adev: Device we are configuring for.
317 * Set PIO mode for device, in host controller PCI config space. This
318 * function handles PIO set up for the later ATA133 devices.
321 * None (inherited from caller).
324 static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev)
326 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
330 int speed = adev->pio_mode - XFER_PIO_0;
332 const u32 timing133[] = {
333 0x28269000, /* Recovery << 24 | Act << 16 | Ini << 12 */
339 const u32 timing100[] = {
340 0x1E1C6000, /* Recovery << 24 | Act << 16 | Ini << 12 */
347 sis_set_fifo(ap, adev);
349 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
350 pci_read_config_dword(pdev, 0x54, ®54);
351 if (reg54 & 0x40000000)
353 port += 8 * ap->port_no + 4 * adev->devno;
355 pci_read_config_dword(pdev, port, &t1);
356 t1 &= 0xC0C00FFF; /* Mask out timing */
358 if (t1 & 0x08) /* 100 or 133 ? */
359 t1 |= timing133[speed];
361 t1 |= timing100[speed];
362 pci_write_config_byte(pdev, port, t1);
366 * sis_old_set_dmamode - Initialize host controller PATA DMA timings
367 * @ap: Port whose timings we are configuring
368 * @adev: Device to program
370 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
371 * Handles pre UDMA and UDMA33 devices. Supports MWDMA as well unlike
372 * the old ide/pci driver.
375 * None (inherited from caller).
378 static void sis_old_set_dmamode (struct ata_port *ap, struct ata_device *adev)
380 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
381 int speed = adev->dma_mode - XFER_MW_DMA_0;
382 int drive_pci = sis_port_base(adev);
385 const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
386 const u16 udma_bits[] = { 0xE000, 0xC000, 0xA000 };
388 pci_read_config_word(pdev, drive_pci, &timing);
390 if (adev->dma_mode < XFER_UDMA_0) {
391 /* bits 3-0 hold recovery timing bits 8-10 active timing and
392 the higer bits are dependant on the device */
394 timing |= mwdma_bits[speed];
395 pci_write_config_word(pdev, drive_pci, timing);
397 /* Bit 15 is UDMA on/off, bit 13-14 are cycle time */
398 speed = adev->dma_mode - XFER_UDMA_0;
400 timing |= udma_bits[speed];
405 * sis_66_set_dmamode - Initialize host controller PATA DMA timings
406 * @ap: Port whose timings we are configuring
407 * @adev: Device to program
409 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
410 * Handles UDMA66 and early UDMA100 devices. Supports MWDMA as well unlike
411 * the old ide/pci driver.
414 * None (inherited from caller).
417 static void sis_66_set_dmamode (struct ata_port *ap, struct ata_device *adev)
419 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
420 int speed = adev->dma_mode - XFER_MW_DMA_0;
421 int drive_pci = sis_port_base(adev);
424 const u16 mwdma_bits[] = { 0x707, 0x202, 0x202 };
425 const u16 udma_bits[] = { 0xF000, 0xD000, 0xB000, 0xA000, 0x9000};
427 pci_read_config_word(pdev, drive_pci, &timing);
429 if (adev->dma_mode < XFER_UDMA_0) {
430 /* bits 3-0 hold recovery timing bits 8-10 active timing and
431 the higer bits are dependant on the device, bit 15 udma */
433 timing |= mwdma_bits[speed];
435 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
436 speed = adev->dma_mode - XFER_UDMA_0;
438 timing |= udma_bits[speed];
440 pci_write_config_word(pdev, drive_pci, timing);
444 * sis_100_set_dmamode - Initialize host controller PATA DMA timings
445 * @ap: Port whose timings we are configuring
446 * @adev: Device to program
448 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
449 * Handles UDMA66 and early UDMA100 devices.
452 * None (inherited from caller).
455 static void sis_100_set_dmamode (struct ata_port *ap, struct ata_device *adev)
457 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
458 int speed = adev->dma_mode - XFER_MW_DMA_0;
459 int drive_pci = sis_port_base(adev);
462 const u16 udma_bits[] = { 0x8B00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
464 pci_read_config_word(pdev, drive_pci, &timing);
466 if (adev->dma_mode < XFER_UDMA_0) {
467 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
469 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
470 speed = adev->dma_mode - XFER_UDMA_0;
472 timing |= udma_bits[speed];
474 pci_write_config_word(pdev, drive_pci, timing);
478 * sis_133_early_set_dmamode - Initialize host controller PATA DMA timings
479 * @ap: Port whose timings we are configuring
480 * @adev: Device to program
482 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
483 * Handles early SiS 961 bridges. Supports MWDMA as well unlike
484 * the old ide/pci driver.
487 * None (inherited from caller).
490 static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *adev)
492 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
493 int speed = adev->dma_mode - XFER_MW_DMA_0;
494 int drive_pci = sis_port_base(adev);
497 const u16 udma_bits[] = { 0x8F00, 0x8A00, 0x8700, 0x8500, 0x8300, 0x8200, 0x8100};
499 pci_read_config_word(pdev, drive_pci, &timing);
501 if (adev->dma_mode < XFER_UDMA_0) {
502 /* NOT SUPPORTED YET: NEED DATA SHEET. DITTO IN OLD DRIVER */
504 /* Bit 15 is UDMA on/off, bit 12-14 are cycle time */
505 speed = adev->dma_mode - XFER_UDMA_0;
507 timing |= udma_bits[speed];
509 pci_write_config_word(pdev, drive_pci, timing);
513 * sis_133_set_dmamode - Initialize host controller PATA DMA timings
514 * @ap: Port whose timings we are configuring
515 * @adev: Device to program
517 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
518 * Handles early SiS 961 bridges. Supports MWDMA as well unlike
519 * the old ide/pci driver.
522 * None (inherited from caller).
525 static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev)
527 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
528 int speed = adev->dma_mode - XFER_MW_DMA_0;
533 /* bits 4- cycle time 8 - cvs time */
534 const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 };
535 const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 };
537 /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */
538 pci_read_config_dword(pdev, 0x54, ®54);
539 if (reg54 & 0x40000000)
541 port += (8 * ap->port_no) + (4 * adev->devno);
543 pci_read_config_dword(pdev, port, &t1);
545 if (adev->dma_mode < XFER_UDMA_0) {
547 /* FIXME: need data sheet to add MWDMA here. Also lacking on
550 speed = adev->dma_mode - XFER_UDMA_0;
551 /* if & 8 no UDMA133 - need info for ... */
555 t1 |= timing_u133[speed];
557 t1 |= timing_u100[speed];
559 pci_write_config_dword(pdev, port, t1);
562 static struct scsi_host_template sis_sht = {
563 .module = THIS_MODULE,
565 .ioctl = ata_scsi_ioctl,
566 .queuecommand = ata_scsi_queuecmd,
567 .can_queue = ATA_DEF_QUEUE,
568 .this_id = ATA_SHT_THIS_ID,
569 .sg_tablesize = LIBATA_MAX_PRD,
570 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
571 .emulated = ATA_SHT_EMULATED,
572 .use_clustering = ATA_SHT_USE_CLUSTERING,
573 .proc_name = DRV_NAME,
574 .dma_boundary = ATA_DMA_BOUNDARY,
575 .slave_configure = ata_scsi_slave_config,
576 .slave_destroy = ata_scsi_slave_destroy,
577 .bios_param = ata_std_bios_param,
578 .resume = ata_scsi_device_resume,
579 .suspend = ata_scsi_device_suspend,
582 static const struct ata_port_operations sis_133_ops = {
583 .port_disable = ata_port_disable,
584 .set_piomode = sis_133_set_piomode,
585 .set_dmamode = sis_133_set_dmamode,
586 .mode_filter = ata_pci_default_filter,
588 .tf_load = ata_tf_load,
589 .tf_read = ata_tf_read,
590 .check_status = ata_check_status,
591 .exec_command = ata_exec_command,
592 .dev_select = ata_std_dev_select,
594 .freeze = ata_bmdma_freeze,
595 .thaw = ata_bmdma_thaw,
596 .error_handler = sis_133_error_handler,
597 .post_internal_cmd = ata_bmdma_post_internal_cmd,
599 .bmdma_setup = ata_bmdma_setup,
600 .bmdma_start = ata_bmdma_start,
601 .bmdma_stop = ata_bmdma_stop,
602 .bmdma_status = ata_bmdma_status,
603 .qc_prep = ata_qc_prep,
604 .qc_issue = ata_qc_issue_prot,
605 .data_xfer = ata_data_xfer,
607 .irq_handler = ata_interrupt,
608 .irq_clear = ata_bmdma_irq_clear,
609 .irq_on = ata_irq_on,
610 .irq_ack = ata_irq_ack,
612 .port_start = ata_port_start,
615 static const struct ata_port_operations sis_133_early_ops = {
616 .port_disable = ata_port_disable,
617 .set_piomode = sis_100_set_piomode,
618 .set_dmamode = sis_133_early_set_dmamode,
619 .mode_filter = ata_pci_default_filter,
621 .tf_load = ata_tf_load,
622 .tf_read = ata_tf_read,
623 .check_status = ata_check_status,
624 .exec_command = ata_exec_command,
625 .dev_select = ata_std_dev_select,
627 .freeze = ata_bmdma_freeze,
628 .thaw = ata_bmdma_thaw,
629 .error_handler = sis_66_error_handler,
630 .post_internal_cmd = ata_bmdma_post_internal_cmd,
632 .bmdma_setup = ata_bmdma_setup,
633 .bmdma_start = ata_bmdma_start,
634 .bmdma_stop = ata_bmdma_stop,
635 .bmdma_status = ata_bmdma_status,
636 .qc_prep = ata_qc_prep,
637 .qc_issue = ata_qc_issue_prot,
638 .data_xfer = ata_data_xfer,
640 .irq_handler = ata_interrupt,
641 .irq_clear = ata_bmdma_irq_clear,
642 .irq_on = ata_irq_on,
643 .irq_ack = ata_irq_ack,
645 .port_start = ata_port_start,
648 static const struct ata_port_operations sis_100_ops = {
649 .port_disable = ata_port_disable,
650 .set_piomode = sis_100_set_piomode,
651 .set_dmamode = sis_100_set_dmamode,
652 .mode_filter = ata_pci_default_filter,
654 .tf_load = ata_tf_load,
655 .tf_read = ata_tf_read,
656 .check_status = ata_check_status,
657 .exec_command = ata_exec_command,
658 .dev_select = ata_std_dev_select,
660 .freeze = ata_bmdma_freeze,
661 .thaw = ata_bmdma_thaw,
662 .error_handler = sis_66_error_handler,
663 .post_internal_cmd = ata_bmdma_post_internal_cmd,
666 .bmdma_setup = ata_bmdma_setup,
667 .bmdma_start = ata_bmdma_start,
668 .bmdma_stop = ata_bmdma_stop,
669 .bmdma_status = ata_bmdma_status,
670 .qc_prep = ata_qc_prep,
671 .qc_issue = ata_qc_issue_prot,
672 .data_xfer = ata_data_xfer,
674 .irq_handler = ata_interrupt,
675 .irq_clear = ata_bmdma_irq_clear,
676 .irq_on = ata_irq_on,
677 .irq_ack = ata_irq_ack,
679 .port_start = ata_port_start,
682 static const struct ata_port_operations sis_66_ops = {
683 .port_disable = ata_port_disable,
684 .set_piomode = sis_old_set_piomode,
685 .set_dmamode = sis_66_set_dmamode,
686 .mode_filter = ata_pci_default_filter,
688 .tf_load = ata_tf_load,
689 .tf_read = ata_tf_read,
690 .check_status = ata_check_status,
691 .exec_command = ata_exec_command,
692 .dev_select = ata_std_dev_select,
694 .freeze = ata_bmdma_freeze,
695 .thaw = ata_bmdma_thaw,
696 .error_handler = sis_66_error_handler,
697 .post_internal_cmd = ata_bmdma_post_internal_cmd,
699 .bmdma_setup = ata_bmdma_setup,
700 .bmdma_start = ata_bmdma_start,
701 .bmdma_stop = ata_bmdma_stop,
702 .bmdma_status = ata_bmdma_status,
703 .qc_prep = ata_qc_prep,
704 .qc_issue = ata_qc_issue_prot,
705 .data_xfer = ata_data_xfer,
707 .irq_handler = ata_interrupt,
708 .irq_clear = ata_bmdma_irq_clear,
709 .irq_on = ata_irq_on,
710 .irq_ack = ata_irq_ack,
712 .port_start = ata_port_start,
715 static const struct ata_port_operations sis_old_ops = {
716 .port_disable = ata_port_disable,
717 .set_piomode = sis_old_set_piomode,
718 .set_dmamode = sis_old_set_dmamode,
719 .mode_filter = ata_pci_default_filter,
721 .tf_load = ata_tf_load,
722 .tf_read = ata_tf_read,
723 .check_status = ata_check_status,
724 .exec_command = ata_exec_command,
725 .dev_select = ata_std_dev_select,
727 .freeze = ata_bmdma_freeze,
728 .thaw = ata_bmdma_thaw,
729 .error_handler = sis_old_error_handler,
730 .post_internal_cmd = ata_bmdma_post_internal_cmd,
732 .bmdma_setup = ata_bmdma_setup,
733 .bmdma_start = ata_bmdma_start,
734 .bmdma_stop = ata_bmdma_stop,
735 .bmdma_status = ata_bmdma_status,
736 .qc_prep = ata_qc_prep,
737 .qc_issue = ata_qc_issue_prot,
738 .data_xfer = ata_data_xfer,
740 .irq_handler = ata_interrupt,
741 .irq_clear = ata_bmdma_irq_clear,
742 .irq_on = ata_irq_on,
743 .irq_ack = ata_irq_ack,
745 .port_start = ata_port_start,
748 static struct ata_port_info sis_info = {
750 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
751 .pio_mask = 0x1f, /* pio0-4 */
754 .port_ops = &sis_old_ops,
756 static struct ata_port_info sis_info33 = {
758 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
759 .pio_mask = 0x1f, /* pio0-4 */
761 .udma_mask = ATA_UDMA2, /* UDMA 33 */
762 .port_ops = &sis_old_ops,
764 static struct ata_port_info sis_info66 = {
766 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
767 .pio_mask = 0x1f, /* pio0-4 */
768 .udma_mask = ATA_UDMA4, /* UDMA 66 */
769 .port_ops = &sis_66_ops,
771 static struct ata_port_info sis_info100 = {
773 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
774 .pio_mask = 0x1f, /* pio0-4 */
775 .udma_mask = ATA_UDMA5,
776 .port_ops = &sis_100_ops,
778 static struct ata_port_info sis_info100_early = {
780 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
781 .udma_mask = ATA_UDMA5,
782 .pio_mask = 0x1f, /* pio0-4 */
783 .port_ops = &sis_66_ops,
785 struct ata_port_info sis_info133 = {
787 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
788 .pio_mask = 0x1f, /* pio0-4 */
789 .udma_mask = ATA_UDMA6,
790 .port_ops = &sis_133_ops,
792 static struct ata_port_info sis_info133_early = {
794 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
795 .pio_mask = 0x1f, /* pio0-4 */
796 .udma_mask = ATA_UDMA6,
797 .port_ops = &sis_133_early_ops,
800 /* Privately shared with the SiS180 SATA driver, not for use elsewhere */
801 EXPORT_SYMBOL_GPL(sis_info133);
803 static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
808 if (sis->info == &sis_info133) {
809 pci_read_config_word(pdev, 0x50, ®w);
811 pci_write_config_word(pdev, 0x50, regw & ~0x08);
812 pci_read_config_word(pdev, 0x52, ®w);
814 pci_write_config_word(pdev, 0x52, regw & ~0x08);
818 if (sis->info == &sis_info133_early || sis->info == &sis_info100) {
820 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
821 /* Set compatibility bit */
822 pci_read_config_byte(pdev, 0x49, ®);
824 pci_write_config_byte(pdev, 0x49, reg | 0x01);
828 if (sis->info == &sis_info66 || sis->info == &sis_info100_early) {
830 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
831 /* Set compatibility bit */
832 pci_read_config_byte(pdev, 0x52, ®);
834 pci_write_config_byte(pdev, 0x52, reg | 0x04);
838 if (sis->info == &sis_info33) {
839 pci_read_config_byte(pdev, PCI_CLASS_PROG, ®);
840 if (( reg & 0x0F ) != 0x00)
841 pci_write_config_byte(pdev, PCI_CLASS_PROG, reg & 0xF0);
842 /* Fall through to ATA16 fixup below */
845 if (sis->info == &sis_info || sis->info == &sis_info33) {
846 /* force per drive recovery and active timings
847 needed on ATA_33 and below chips */
848 pci_read_config_byte(pdev, 0x52, ®);
850 pci_write_config_byte(pdev, 0x52, reg|0x08);
858 * sis_init_one - Register SiS ATA PCI device with kernel services
859 * @pdev: PCI device to register
860 * @ent: Entry in sis_pci_tbl matching with @pdev
862 * Called from kernel PCI layer. We probe for combined mode (sigh),
863 * and then hand over control to libata, for it to do the rest.
866 * Inherited from PCI layer (may sleep).
869 * Zero on success, or -ERRNO value.
872 static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
874 static int printed_version;
875 static struct ata_port_info *port_info[2];
876 struct ata_port_info *port;
877 struct pci_dev *host = NULL;
878 struct sis_chipset *chipset = NULL;
880 static struct sis_chipset sis_chipsets[] = {
882 { 0x0968, &sis_info133 },
883 { 0x0966, &sis_info133 },
884 { 0x0965, &sis_info133 },
885 { 0x0745, &sis_info100 },
886 { 0x0735, &sis_info100 },
887 { 0x0733, &sis_info100 },
888 { 0x0635, &sis_info100 },
889 { 0x0633, &sis_info100 },
891 { 0x0730, &sis_info100_early }, /* 100 with ATA 66 layout */
892 { 0x0550, &sis_info100_early }, /* 100 with ATA 66 layout */
894 { 0x0640, &sis_info66 },
895 { 0x0630, &sis_info66 },
896 { 0x0620, &sis_info66 },
897 { 0x0540, &sis_info66 },
898 { 0x0530, &sis_info66 },
900 { 0x5600, &sis_info33 },
901 { 0x5598, &sis_info33 },
902 { 0x5597, &sis_info33 },
903 { 0x5591, &sis_info33 },
904 { 0x5582, &sis_info33 },
905 { 0x5581, &sis_info33 },
907 { 0x5596, &sis_info },
908 { 0x5571, &sis_info },
909 { 0x5517, &sis_info },
910 { 0x5511, &sis_info },
914 static struct sis_chipset sis133_early = {
915 0x0, &sis_info133_early
917 static struct sis_chipset sis133 = {
920 static struct sis_chipset sis100_early = {
921 0x0, &sis_info100_early
923 static struct sis_chipset sis100 = {
927 if (!printed_version++)
928 dev_printk(KERN_DEBUG, &pdev->dev,
929 "version " DRV_VERSION "\n");
931 /* We have to find the bridge first */
933 for (chipset = &sis_chipsets[0]; chipset->device; chipset++) {
934 host = pci_get_device(PCI_VENDOR_ID_SI, chipset->device, NULL);
936 if (chipset->device == 0x630) { /* SIS630 */
938 pci_read_config_byte(host, PCI_REVISION_ID, &host_rev);
939 if (host_rev >= 0x30) /* 630 ET */
940 chipset = &sis100_early;
946 /* Look for concealed bridges */
952 /* Disable ID masking and register remapping then
953 see what the real ID is */
955 pci_read_config_dword(pdev, 0x54, &idemisc);
956 pci_write_config_dword(pdev, 0x54, idemisc & 0x7fffffff);
957 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
958 pci_write_config_dword(pdev, 0x54, idemisc);
961 case 0x5518: /* SIS 962/963 */
963 if ((idemisc & 0x40000000) == 0) {
964 pci_write_config_dword(pdev, 0x54, idemisc | 0x40000000);
965 printk(KERN_INFO "SIS5513: Switching to 5513 register mapping\n");
968 case 0x0180: /* SIS 965/965L */
971 case 0x1180: /* SIS 966/966L */
978 if (chipset == NULL) {
979 struct pci_dev *lpc_bridge;
985 /* Try the second unmasking technique */
986 pci_read_config_byte(pdev, 0x4a, &idecfg);
987 pci_write_config_byte(pdev, 0x4a, idecfg | 0x10);
988 pci_read_config_word(pdev, PCI_DEVICE_ID, &trueid);
989 pci_write_config_byte(pdev, 0x4a, idecfg);
993 lpc_bridge = pci_get_slot(pdev->bus, 0x10); /* Bus 0 Dev 2 Fn 0 */
994 if (lpc_bridge == NULL)
996 pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
997 pci_read_config_byte(pdev, 0x49, &prefctl);
998 pci_dev_put(lpc_bridge);
1000 if (sbrev == 0x10 && (prefctl & 0x80)) {
1001 chipset = &sis133_early;
1010 /* No chipset info, no support */
1011 if (chipset == NULL)
1014 port = chipset->info;
1015 port->private_data = chipset;
1017 sis_fixup(pdev, chipset);
1019 port_info[0] = port_info[1] = port;
1020 return ata_pci_init_one(pdev, port_info, 2);
1023 static const struct pci_device_id sis_pci_tbl[] = {
1024 { PCI_VDEVICE(SI, 0x5513), }, /* SiS 5513 */
1025 { PCI_VDEVICE(SI, 0x5518), }, /* SiS 5518 */
1030 static struct pci_driver sis_pci_driver = {
1032 .id_table = sis_pci_tbl,
1033 .probe = sis_init_one,
1034 .remove = ata_pci_remove_one,
1035 .suspend = ata_pci_device_suspend,
1036 .resume = ata_pci_device_resume,
1039 static int __init sis_init(void)
1041 return pci_register_driver(&sis_pci_driver);
1044 static void __exit sis_exit(void)
1046 pci_unregister_driver(&sis_pci_driver);
1049 module_init(sis_init);
1050 module_exit(sis_exit);
1052 MODULE_AUTHOR("Alan Cox");
1053 MODULE_DESCRIPTION("SCSI low-level driver for SiS ATA");
1054 MODULE_LICENSE("GPL");
1055 MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
1056 MODULE_VERSION(DRV_VERSION);