aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/ata_piix.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2006-08-29 18:12:40 -0400
committerJeff Garzik <jeff@garzik.org>2006-08-29 18:12:40 -0400
commit669a5db411d85a14f86cd92bc16bf7ab5b8aa235 (patch)
tree8d4f9d63e18185695a4d97e1a3fa4e18b61c7345 /drivers/ata/ata_piix.c
parentb01e86fee6c821e4e003fd4e9f65453ac478a58e (diff)
[libata] Add a bunch of PATA drivers.
The vast majority of drivers and changes are from Alan Cox. Albert Lee contributed and maintains pata_pdc2027x. Adrian Bunk, Andrew Morton, and Tejun Heo contributed various minor fixes and updates. Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/ata/ata_piix.c')
-rw-r--r--drivers/ata/ata_piix.c436
1 files changed, 326 insertions, 110 deletions
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 22b2dba90b9a..12b3a42fb356 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -93,7 +93,7 @@
93#include <linux/libata.h> 93#include <linux/libata.h>
94 94
95#define DRV_NAME "ata_piix" 95#define DRV_NAME "ata_piix"
96#define DRV_VERSION "2.00" 96#define DRV_VERSION "2.00ac6"
97 97
98enum { 98enum {
99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */ 99 PIIX_IOCFG = 0x54, /* IDE I/O configuration register */
@@ -116,15 +116,18 @@ enum {
116 PIIX_80C_SEC = (1 << 7) | (1 << 6), 116 PIIX_80C_SEC = (1 << 7) | (1 << 6),
117 117
118 /* controller IDs */ 118 /* controller IDs */
119 piix4_pata = 0, 119 piix_pata_33 = 0, /* PIIX3 or 4 at 33Mhz */
120 ich5_pata = 1, 120 ich_pata_33 = 1, /* ICH up to UDMA 33 only */
121 ich5_sata = 2, 121 ich_pata_66 = 2, /* ICH up to 66 Mhz */
122 esb_sata = 3, 122 ich_pata_100 = 3, /* ICH up to UDMA 100 */
123 ich6_sata = 4, 123 ich_pata_133 = 4, /* ICH up to UDMA 133 */
124 ich6_sata_ahci = 5, 124 ich5_sata = 5,
125 ich6m_sata_ahci = 6, 125 esb_sata = 6,
126 ich8_sata_ahci = 7, 126 ich6_sata = 7,
127 127 ich6_sata_ahci = 8,
128 ich6m_sata_ahci = 9,
129 ich8_sata_ahci = 10,
130
128 /* constants for mapping table */ 131 /* constants for mapping table */
129 P0 = 0, /* port 0 */ 132 P0 = 0, /* port 0 */
130 P1 = 1, /* port 1 */ 133 P1 = 1, /* port 1 */
@@ -152,19 +155,54 @@ struct piix_host_priv {
152static int piix_init_one (struct pci_dev *pdev, 155static int piix_init_one (struct pci_dev *pdev,
153 const struct pci_device_id *ent); 156 const struct pci_device_id *ent);
154static void piix_host_stop(struct ata_host *host); 157static void piix_host_stop(struct ata_host *host);
155static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
156static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
157static void piix_pata_error_handler(struct ata_port *ap); 158static void piix_pata_error_handler(struct ata_port *ap);
159static void ich_pata_error_handler(struct ata_port *ap);
158static void piix_sata_error_handler(struct ata_port *ap); 160static void piix_sata_error_handler(struct ata_port *ap);
161static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
162static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
163static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev);
159 164
160static unsigned int in_module_init = 1; 165static unsigned int in_module_init = 1;
161 166
162static const struct pci_device_id piix_pci_tbl[] = { 167static const struct pci_device_id piix_pci_tbl[] = {
163#ifdef ATA_ENABLE_PATA 168#ifdef ATA_ENABLE_PATA
164 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix4_pata }, 169 /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */
165 { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata }, 170 /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */
166 { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata }, 171 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
167 { 0x8086, 0x27df, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_pata }, 172 { 0x8086, 0x24db, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
173 { 0x8086, 0x25a2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
174 /* Intel PIIX4 */
175 { 0x8086, 0x7199, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
176 /* Intel PIIX4 */
177 { 0x8086, 0x7601, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
178 /* Intel PIIX */
179 { 0x8086, 0x84CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
180 /* Intel ICH (i810, i815, i840) UDMA 66*/
181 { 0x8086, 0x2411, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_66 },
182 /* Intel ICH0 : UDMA 33*/
183 { 0x8086, 0x2421, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_33 },
184 /* Intel ICH2M */
185 { 0x8086, 0x244A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
186 /* Intel ICH2 (i810E2, i845, 850, 860) UDMA 100 */
187 { 0x8086, 0x244B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
188 /* Intel ICH3M */
189 { 0x8086, 0x248A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
190 /* Intel ICH3 (E7500/1) UDMA 100 */
191 { 0x8086, 0x248B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
192 /* Intel ICH4 (i845GV, i845E, i852, i855) UDMA 100 */
193 { 0x8086, 0x24CA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
194 { 0x8086, 0x24CB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
195 /* Intel ICH5 */
196 { 0x8086, 0x24DB, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_133 },
197 /* C-ICH (i810E2) */
198 { 0x8086, 0x245B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
199 /* ESB (855GME/875P + 6300ESB) UDMA 100 */
200 { 0x8086, 0x25A2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
201 /* ICH6 (and 6) (i915) UDMA 100 */
202 { 0x8086, 0x266F, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
203 /* ICH7/7-R (i945, i975) UDMA 100*/
204 { 0x8086, 0x27DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_133 },
205 { 0x8086, 0x269E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
168#endif 206#endif
169 207
170 /* NOTE: The following PCI ids must be kept in sync with the 208 /* NOTE: The following PCI ids must be kept in sync with the
@@ -263,6 +301,39 @@ static const struct ata_port_operations piix_pata_ops = {
263 .host_stop = piix_host_stop, 301 .host_stop = piix_host_stop,
264}; 302};
265 303
304static const struct ata_port_operations ich_pata_ops = {
305 .port_disable = ata_port_disable,
306 .set_piomode = piix_set_piomode,
307 .set_dmamode = ich_set_dmamode,
308 .mode_filter = ata_pci_default_filter,
309
310 .tf_load = ata_tf_load,
311 .tf_read = ata_tf_read,
312 .check_status = ata_check_status,
313 .exec_command = ata_exec_command,
314 .dev_select = ata_std_dev_select,
315
316 .bmdma_setup = ata_bmdma_setup,
317 .bmdma_start = ata_bmdma_start,
318 .bmdma_stop = ata_bmdma_stop,
319 .bmdma_status = ata_bmdma_status,
320 .qc_prep = ata_qc_prep,
321 .qc_issue = ata_qc_issue_prot,
322 .data_xfer = ata_pio_data_xfer,
323
324 .freeze = ata_bmdma_freeze,
325 .thaw = ata_bmdma_thaw,
326 .error_handler = ich_pata_error_handler,
327 .post_internal_cmd = ata_bmdma_post_internal_cmd,
328
329 .irq_handler = ata_interrupt,
330 .irq_clear = ata_bmdma_irq_clear,
331
332 .port_start = ata_port_start,
333 .port_stop = ata_port_stop,
334 .host_stop = ata_host_stop,
335};
336
266static const struct ata_port_operations piix_sata_ops = { 337static const struct ata_port_operations piix_sata_ops = {
267 .port_disable = ata_port_disable, 338 .port_disable = ata_port_disable,
268 339
@@ -359,35 +430,56 @@ static const struct piix_map_db *piix_map_db_table[] = {
359}; 430};
360 431
361static struct ata_port_info piix_port_info[] = { 432static struct ata_port_info piix_port_info[] = {
362 /* piix4_pata */ 433 /* piix_pata_33: 0: PIIX3 or 4 at 33MHz */
363 { 434 {
364 .sht = &piix_sht, 435 .sht = &piix_sht,
365 .flags = ATA_FLAG_SLAVE_POSS, 436 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
366 .pio_mask = 0x1f, /* pio0-4 */ 437 .pio_mask = 0x1f, /* pio0-4 */
367#if 0 438 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
368 .mwdma_mask = 0x06, /* mwdma1-2 */
369#else
370 .mwdma_mask = 0x00, /* mwdma broken */
371#endif
372 .udma_mask = ATA_UDMA_MASK_40C, 439 .udma_mask = ATA_UDMA_MASK_40C,
373 .port_ops = &piix_pata_ops, 440 .port_ops = &piix_pata_ops,
374 }, 441 },
375 442
376 /* ich5_pata */ 443 /* ich_pata_33: 1 ICH0 - ICH at 33Mhz*/
444 {
445 .sht = &piix_sht,
446 .flags = ATA_FLAG_SRST | ATA_FLAG_SLAVE_POSS,
447 .pio_mask = 0x1f, /* pio 0-4 */
448 .mwdma_mask = 0x06, /* Check: maybe 0x07 */
449 .udma_mask = ATA_UDMA2, /* UDMA33 */
450 .port_ops = &ich_pata_ops,
451 },
452 /* ich_pata_66: 2 ICH controllers up to 66MHz */
377 { 453 {
378 .sht = &piix_sht, 454 .sht = &piix_sht,
379 .flags = ATA_FLAG_SLAVE_POSS | PIIX_FLAG_CHECKINTR, 455 .flags = ATA_FLAG_SRST | ATA_FLAG_SLAVE_POSS,
456 .pio_mask = 0x1f, /* pio 0-4 */
457 .mwdma_mask = 0x06, /* MWDMA0 is broken on chip */
458 .udma_mask = ATA_UDMA4,
459 .port_ops = &ich_pata_ops,
460 },
461
462 /* ich_pata_100: 3 */
463 {
464 .sht = &piix_sht,
465 .flags = ATA_FLAG_SRST | ATA_FLAG_SLAVE_POSS | PIIX_FLAG_CHECKINTR,
380 .pio_mask = 0x1f, /* pio0-4 */ 466 .pio_mask = 0x1f, /* pio0-4 */
381#if 0
382 .mwdma_mask = 0x06, /* mwdma1-2 */ 467 .mwdma_mask = 0x06, /* mwdma1-2 */
383#else 468 .udma_mask = ATA_UDMA5, /* udma0-5 */
384 .mwdma_mask = 0x00, /* mwdma broken */ 469 .port_ops = &ich_pata_ops,
385#endif
386 .udma_mask = 0x3f, /* udma0-5 */
387 .port_ops = &piix_pata_ops,
388 }, 470 },
389 471
390 /* ich5_sata */ 472 /* ich_pata_133: 4 ICH with full UDMA6 */
473 {
474 .sht = &piix_sht,
475 .flags = ATA_FLAG_SRST | ATA_FLAG_SLAVE_POSS | PIIX_FLAG_CHECKINTR,
476 .pio_mask = 0x1f, /* pio 0-4 */
477 .mwdma_mask = 0x06, /* Check: maybe 0x07 */
478 .udma_mask = ATA_UDMA6, /* UDMA133 */
479 .port_ops = &ich_pata_ops,
480 },
481
482 /* ich5_sata: 5 */
391 { 483 {
392 .sht = &piix_sht, 484 .sht = &piix_sht,
393 .flags = ATA_FLAG_SATA | PIIX_FLAG_CHECKINTR | 485 .flags = ATA_FLAG_SATA | PIIX_FLAG_CHECKINTR |
@@ -398,7 +490,7 @@ static struct ata_port_info piix_port_info[] = {
398 .port_ops = &piix_sata_ops, 490 .port_ops = &piix_sata_ops,
399 }, 491 },
400 492
401 /* i6300esb_sata */ 493 /* i6300esb_sata: 6 */
402 { 494 {
403 .sht = &piix_sht, 495 .sht = &piix_sht,
404 .flags = ATA_FLAG_SATA | 496 .flags = ATA_FLAG_SATA |
@@ -409,7 +501,7 @@ static struct ata_port_info piix_port_info[] = {
409 .port_ops = &piix_sata_ops, 501 .port_ops = &piix_sata_ops,
410 }, 502 },
411 503
412 /* ich6_sata */ 504 /* ich6_sata: 7 */
413 { 505 {
414 .sht = &piix_sht, 506 .sht = &piix_sht,
415 .flags = ATA_FLAG_SATA | 507 .flags = ATA_FLAG_SATA |
@@ -420,7 +512,7 @@ static struct ata_port_info piix_port_info[] = {
420 .port_ops = &piix_sata_ops, 512 .port_ops = &piix_sata_ops,
421 }, 513 },
422 514
423 /* ich6_sata_ahci */ 515 /* ich6_sata_ahci:8 */
424 { 516 {
425 .sht = &piix_sht, 517 .sht = &piix_sht,
426 .flags = ATA_FLAG_SATA | 518 .flags = ATA_FLAG_SATA |
@@ -432,7 +524,7 @@ static struct ata_port_info piix_port_info[] = {
432 .port_ops = &piix_sata_ops, 524 .port_ops = &piix_sata_ops,
433 }, 525 },
434 526
435 /* ich6m_sata_ahci */ 527 /* ich6m_sata_ahci: 9 */
436 { 528 {
437 .sht = &piix_sht, 529 .sht = &piix_sht,
438 .flags = ATA_FLAG_SATA | 530 .flags = ATA_FLAG_SATA |
@@ -455,6 +547,7 @@ static struct ata_port_info piix_port_info[] = {
455 .udma_mask = 0x7f, /* udma0-6 */ 547 .udma_mask = 0x7f, /* udma0-6 */
456 .port_ops = &piix_sata_ops, 548 .port_ops = &piix_sata_ops,
457 }, 549 },
550
458}; 551};
459 552
460static struct pci_bits piix_enable_bits[] = { 553static struct pci_bits piix_enable_bits[] = {
@@ -483,7 +576,8 @@ MODULE_PARM_DESC(force_pcs, "force honoring or ignoring PCS to work around "
483 * LOCKING: 576 * LOCKING:
484 * None (inherited from caller). 577 * None (inherited from caller).
485 */ 578 */
486static void piix_pata_cbl_detect(struct ata_port *ap) 579
580static void ich_pata_cbl_detect(struct ata_port *ap)
487{ 581{
488 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 582 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
489 u8 tmp, mask; 583 u8 tmp, mask;
@@ -503,14 +597,12 @@ static void piix_pata_cbl_detect(struct ata_port *ap)
503 597
504cbl40: 598cbl40:
505 ap->cbl = ATA_CBL_PATA40; 599 ap->cbl = ATA_CBL_PATA40;
506 ap->udma_mask &= ATA_UDMA_MASK_40C;
507} 600}
508 601
509/** 602/**
510 * piix_pata_prereset - prereset for PATA host controller 603 * piix_pata_prereset - prereset for PATA host controller
511 * @ap: Target port 604 * @ap: Target port
512 * 605 *
513 * Prereset including cable detection.
514 * 606 *
515 * LOCKING: 607 * LOCKING:
516 * None (inherited from caller). 608 * None (inherited from caller).
@@ -524,9 +616,7 @@ static int piix_pata_prereset(struct ata_port *ap)
524 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK; 616 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
525 return 0; 617 return 0;
526 } 618 }
527 619 ap->cbl = ATA_CBL_PATA40;
528 piix_pata_cbl_detect(ap);
529
530 return ata_std_prereset(ap); 620 return ata_std_prereset(ap);
531} 621}
532 622
@@ -536,6 +626,36 @@ static void piix_pata_error_handler(struct ata_port *ap)
536 ata_std_postreset); 626 ata_std_postreset);
537} 627}
538 628
629
630/**
631 * ich_pata_prereset - prereset for PATA host controller
632 * @ap: Target port
633 *
634 *
635 * LOCKING:
636 * None (inherited from caller).
637 */
638static int ich_pata_prereset(struct ata_port *ap)
639{
640 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
641
642 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) {
643 ata_port_printk(ap, KERN_INFO, "port disabled. ignoring.\n");
644 ap->eh_context.i.action &= ~ATA_EH_RESET_MASK;
645 return 0;
646 }
647
648 ich_pata_cbl_detect(ap);
649
650 return ata_std_prereset(ap);
651}
652
653static void ich_pata_error_handler(struct ata_port *ap)
654{
655 ata_bmdma_drive_eh(ap, ich_pata_prereset, ata_std_softreset, NULL,
656 ata_std_postreset);
657}
658
539/** 659/**
540 * piix_sata_present_mask - determine present mask for SATA host controller 660 * piix_sata_present_mask - determine present mask for SATA host controller
541 * @ap: Target port 661 * @ap: Target port
@@ -637,6 +757,13 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
637 unsigned int slave_port = 0x44; 757 unsigned int slave_port = 0x44;
638 u16 master_data; 758 u16 master_data;
639 u8 slave_data; 759 u8 slave_data;
760 u8 udma_enable;
761 int control = 0;
762
763 /*
764 * See Intel Document 298600-004 for the timing programing rules
765 * for ICH controllers.
766 */
640 767
641 static const /* ISP RTC */ 768 static const /* ISP RTC */
642 u8 timings[][2] = { { 0, 0 }, 769 u8 timings[][2] = { { 0, 0 },
@@ -645,20 +772,30 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
645 { 2, 1 }, 772 { 2, 1 },
646 { 2, 3 }, }; 773 { 2, 3 }, };
647 774
775 if (pio >= 2)
776 control |= 1; /* TIME1 enable */
777 if (ata_pio_need_iordy(adev))
778 control |= 2; /* IE enable */
779
780 /* Intel specifies that the PPE functionality is for disk only */
781 if (adev->class == ATA_DEV_ATA)
782 control |= 4; /* PPE enable */
783
648 pci_read_config_word(dev, master_port, &master_data); 784 pci_read_config_word(dev, master_port, &master_data);
649 if (is_slave) { 785 if (is_slave) {
786 /* Enable SITRE (seperate slave timing register) */
650 master_data |= 0x4000; 787 master_data |= 0x4000;
651 /* enable PPE, IE and TIME */ 788 /* enable PPE1, IE1 and TIME1 as needed */
652 master_data |= 0x0070; 789 master_data |= (control << 4);
653 pci_read_config_byte(dev, slave_port, &slave_data); 790 pci_read_config_byte(dev, slave_port, &slave_data);
654 slave_data &= (ap->port_no ? 0x0f : 0xf0); 791 slave_data &= (ap->port_no ? 0x0f : 0xf0);
655 slave_data |= 792 /* Load the timing nibble for this slave */
656 (timings[pio][0] << 2) | 793 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
657 (timings[pio][1] << (ap->port_no ? 4 : 0));
658 } else { 794 } else {
795 /* Master keeps the bits in a different format */
659 master_data &= 0xccf8; 796 master_data &= 0xccf8;
660 /* enable PPE, IE and TIME */ 797 /* Enable PPE, IE and TIME as appropriate */
661 master_data |= 0x0007; 798 master_data |= control;
662 master_data |= 799 master_data |=
663 (timings[pio][0] << 12) | 800 (timings[pio][0] << 12) |
664 (timings[pio][1] << 8); 801 (timings[pio][1] << 8);
@@ -666,13 +803,23 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
666 pci_write_config_word(dev, master_port, master_data); 803 pci_write_config_word(dev, master_port, master_data);
667 if (is_slave) 804 if (is_slave)
668 pci_write_config_byte(dev, slave_port, slave_data); 805 pci_write_config_byte(dev, slave_port, slave_data);
806
807 /* Ensure the UDMA bit is off - it will be turned back on if
808 UDMA is selected */
809
810 if (ap->udma_mask) {
811 pci_read_config_byte(dev, 0x48, &udma_enable);
812 udma_enable &= ~(1 << (2 * ap->port_no + adev->devno));
813 pci_write_config_byte(dev, 0x48, udma_enable);
814 }
669} 815}
670 816
671/** 817/**
672 * piix_set_dmamode - Initialize host controller PATA PIO timings 818 * do_pata_set_dmamode - Initialize host controller PATA PIO timings
673 * @ap: Port whose timings we are configuring 819 * @ap: Port whose timings we are configuring
674 * @adev: um 820 * @adev: Drive in question
675 * @udma: udma mode, 0 - 6 821 * @udma: udma mode, 0 - 6
822 * @is_ich: set if the chip is an ICH device
676 * 823 *
677 * Set UDMA mode for device, in host controller PCI config space. 824 * Set UDMA mode for device, in host controller PCI config space.
678 * 825 *
@@ -680,70 +827,140 @@ static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev)
680 * None (inherited from caller). 827 * None (inherited from caller).
681 */ 828 */
682 829
683static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev) 830static void do_pata_set_dmamode (struct ata_port *ap, struct ata_device *adev, int isich)
684{ 831{
685 unsigned int udma = adev->dma_mode; /* FIXME: MWDMA too */
686 struct pci_dev *dev = to_pci_dev(ap->host->dev); 832 struct pci_dev *dev = to_pci_dev(ap->host->dev);
687 u8 maslave = ap->port_no ? 0x42 : 0x40; 833 u8 master_port = ap->port_no ? 0x42 : 0x40;
688 u8 speed = udma; 834 u16 master_data;
689 unsigned int drive_dn = (ap->port_no ? 2 : 0) + adev->devno; 835 u8 speed = adev->dma_mode;
690 int a_speed = 3 << (drive_dn * 4); 836 int devid = adev->devno + 2 * ap->port_no;
691 int u_flag = 1 << drive_dn; 837 u8 udma_enable;
692 int v_flag = 0x01 << drive_dn; 838
693 int w_flag = 0x10 << drive_dn; 839 static const /* ISP RTC */
694 int u_speed = 0; 840 u8 timings[][2] = { { 0, 0 },
695 int sitre; 841 { 0, 0 },
696 u16 reg4042, reg4a; 842 { 1, 0 },
697 u8 reg48, reg54, reg55; 843 { 2, 1 },
698 844 { 2, 3 }, };
699 pci_read_config_word(dev, maslave, &reg4042); 845
700 DPRINTK("reg4042 = 0x%04x\n", reg4042); 846 pci_read_config_word(dev, master_port, &master_data);
701 sitre = (reg4042 & 0x4000) ? 1 : 0; 847 pci_read_config_byte(dev, 0x48, &udma_enable);
702 pci_read_config_byte(dev, 0x48, &reg48);
703 pci_read_config_word(dev, 0x4a, &reg4a);
704 pci_read_config_byte(dev, 0x54, &reg54);
705 pci_read_config_byte(dev, 0x55, &reg55);
706
707 switch(speed) {
708 case XFER_UDMA_4:
709 case XFER_UDMA_2: u_speed = 2 << (drive_dn * 4); break;
710 case XFER_UDMA_6:
711 case XFER_UDMA_5:
712 case XFER_UDMA_3:
713 case XFER_UDMA_1: u_speed = 1 << (drive_dn * 4); break;
714 case XFER_UDMA_0: u_speed = 0 << (drive_dn * 4); break;
715 case XFER_MW_DMA_2:
716 case XFER_MW_DMA_1: break;
717 default:
718 BUG();
719 return;
720 }
721 848
722 if (speed >= XFER_UDMA_0) { 849 if (speed >= XFER_UDMA_0) {
723 if (!(reg48 & u_flag)) 850 unsigned int udma = adev->dma_mode - XFER_UDMA_0;
724 pci_write_config_byte(dev, 0x48, reg48 | u_flag); 851 u16 udma_timing;
725 if (speed == XFER_UDMA_5) { 852 u16 ideconf;
726 pci_write_config_byte(dev, 0x55, (u8) reg55|w_flag); 853 int u_clock, u_speed;
727 } else { 854
728 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 855 /*
856 * UDMA is handled by a combination of clock switching and
857 * selection of dividers
858 *
859 * Handy rule: Odd modes are UDMATIMx 01, even are 02
860 * except UDMA0 which is 00
861 */
862 u_speed = min(2 - (udma & 1), udma);
863 if (udma == 5)
864 u_clock = 0x1000; /* 100Mhz */
865 else if (udma > 2)
866 u_clock = 1; /* 66Mhz */
867 else
868 u_clock = 0; /* 33Mhz */
869
870 udma_enable |= (1 << devid);
871
872 /* Load the CT/RP selection */
873 pci_read_config_word(dev, 0x4A, &udma_timing);
874 udma_timing &= ~(3 << (4 * devid));
875 udma_timing |= u_speed << (4 * devid);
876 pci_write_config_word(dev, 0x4A, udma_timing);
877
878 if (isich) {
879 /* Select a 33/66/100Mhz clock */
880 pci_read_config_word(dev, 0x54, &ideconf);
881 ideconf &= ~(0x1001 << devid);
882 ideconf |= u_clock << devid;
883 /* For ICH or later we should set bit 10 for better
884 performance (WR_PingPong_En) */
885 pci_write_config_word(dev, 0x54, ideconf);
729 } 886 }
730 if ((reg4a & a_speed) != u_speed)
731 pci_write_config_word(dev, 0x4a, (reg4a & ~a_speed) | u_speed);
732 if (speed > XFER_UDMA_2) {
733 if (!(reg54 & v_flag))
734 pci_write_config_byte(dev, 0x54, reg54 | v_flag);
735 } else
736 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag);
737 } else { 887 } else {
738 if (reg48 & u_flag) 888 /*
739 pci_write_config_byte(dev, 0x48, reg48 & ~u_flag); 889 * MWDMA is driven by the PIO timings. We must also enable
740 if (reg4a & a_speed) 890 * IORDY unconditionally along with TIME1. PPE has already
741 pci_write_config_word(dev, 0x4a, reg4a & ~a_speed); 891 * been set when the PIO timing was set.
742 if (reg54 & v_flag) 892 */
743 pci_write_config_byte(dev, 0x54, reg54 & ~v_flag); 893 unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
744 if (reg55 & w_flag) 894 unsigned int control;
745 pci_write_config_byte(dev, 0x55, (u8) reg55 & ~w_flag); 895 u8 slave_data;
896 const unsigned int needed_pio[3] = {
897 XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
898 };
899 int pio = needed_pio[mwdma] - XFER_PIO_0;
900
901 control = 3; /* IORDY|TIME1 */
902
903 /* If the drive MWDMA is faster than it can do PIO then
904 we must force PIO into PIO0 */
905
906 if (adev->pio_mode < needed_pio[mwdma])
907 /* Enable DMA timing only */
908 control |= 8; /* PIO cycles in PIO0 */
909
910 if (adev->devno) { /* Slave */
911 master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
912 master_data |= control << 4;
913 pci_read_config_byte(dev, 0x44, &slave_data);
914 slave_data &= (0x0F + 0xE1 * ap->port_no);
915 /* Load the matching timing */
916 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
917 pci_write_config_byte(dev, 0x44, slave_data);
918 } else { /* Master */
919 master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
920 and master timing bits */
921 master_data |= control;
922 master_data |=
923 (timings[pio][0] << 12) |
924 (timings[pio][1] << 8);
925 }
926 udma_enable &= ~(1 << devid);
927 pci_write_config_word(dev, master_port, master_data);
746 } 928 }
929 /* Don't scribble on 0x48 if the controller does not support UDMA */
930 if (ap->udma_mask)
931 pci_write_config_byte(dev, 0x48, udma_enable);
932}
933
934/**
935 * piix_set_dmamode - Initialize host controller PATA DMA timings
936 * @ap: Port whose timings we are configuring
937 * @adev: um
938 *
939 * Set MW/UDMA mode for device, in host controller PCI config space.
940 *
941 * LOCKING:
942 * None (inherited from caller).
943 */
944
945static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev)
946{
947 do_pata_set_dmamode(ap, adev, 0);
948}
949
950/**
951 * ich_set_dmamode - Initialize host controller PATA DMA timings
952 * @ap: Port whose timings we are configuring
953 * @adev: um
954 *
955 * Set MW/UDMA mode for device, in host controller PCI config space.
956 *
957 * LOCKING:
958 * None (inherited from caller).
959 */
960
961static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev)
962{
963 do_pata_set_dmamode(ap, adev, 1);
747} 964}
748 965
749#define AHCI_PCI_BAR 5 966#define AHCI_PCI_BAR 5
@@ -872,7 +1089,7 @@ static void __devinit piix_init_sata_map(struct pci_dev *pdev,
872 1089
873 case IDE: 1090 case IDE:
874 WARN_ON((i & 1) || map[i + 1] != IDE); 1091 WARN_ON((i & 1) || map[i + 1] != IDE);
875 pinfo[i / 2] = piix_port_info[ich5_pata]; 1092 pinfo[i / 2] = piix_port_info[ich_pata_100];
876 pinfo[i / 2].private_data = hpriv; 1093 pinfo[i / 2].private_data = hpriv;
877 i++; 1094 i++;
878 printk(" IDE IDE"); 1095 printk(" IDE IDE");
@@ -1007,4 +1224,3 @@ static void __exit piix_exit(void)
1007 1224
1008module_init(piix_init); 1225module_init(piix_init);
1009module_exit(piix_exit); 1226module_exit(piix_exit);
1010