}
 
 #ifdef CONFIG_PCI
+
+static int ata_resources_present(struct pci_dev *pdev, int port)
+{
+       int i;
+       
+       /* Check the PCI resources for this channel are enabled */
+       port = port * 2;
+       for (i = 0; i < 2; i ++) {
+               if (pci_resource_start(pdev, port + i) == 0 ||
+                       pci_resource_len(pdev, port + i) == 0)
+               return 0;
+       }
+       return 1;
+}
+               
 /**
  *     ata_pci_init_native_mode - Initialize native-mode driver
  *     @pdev:  pci device to be initialized
 
        probe_ent->irq = pdev->irq;
        probe_ent->irq_flags = IRQF_SHARED;
+       
+       /* Discard disabled ports. Some controllers show their
+          unused channels this way */
+       if (ata_resources_present(pdev, 0) == 0)
+               ports &= ~ATA_PORT_PRIMARY;
+       if (ata_resources_present(pdev, 1) == 0)
+               ports &= ~ATA_PORT_SECONDARY;
 
        if (ports & ATA_PORT_PRIMARY) {
                probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);